Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/server/scripts/dev-replay-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export const SCENARIOS = [
name: "Command output",
file: "./dev-replay/command_output_transcript.ndjson",
},
{
id: "inline-command",
name: "Inline command",
file: "./dev-replay/inline_command_transcript.ndjson",
},
// scripts/metrics/web/client-metrics.ts: a heavy timeline that seeds fast, and a turn that streams for minutes.
{ id: "bench-heavy", name: "Heavy turn", file: "./dev-replay/bench_heavy_transcript.ndjson" },
{ id: "bench-stream", name: "Long stream", file: "./dev-replay/bench_stream_transcript.ndjson" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"type":"transcript_start","provider":"acpRegistry","protocol":"acp.ndjson-jsonrpc","version":"1","scenario":"dev_replay_inline_command"}
{"type":"expect_outbound","frame":{"kind":"request","method":"session/prompt","params":"<any>"}}
{"type":"emit_inbound","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"dev-replay-session","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"Run this command in your project:\n\n```sh\ninline_run_count=$(( ${inline_run_count:-0} + 1 )); printf 'inline command run %s\\n' \"$inline_run_count\"\n```\n"}}}}}
{"type":"emit_inbound","frame":{"kind":"response","method":"session/prompt","result":{"stopReason":"end_turn"}}}
3 changes: 2 additions & 1 deletion apps/server/src/terminal/Manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3495,7 +3495,8 @@ it.layer(
const { manager, ptyAdapter } = yield* createManager(5, {
shellResolver: () => shell,
}).pipe(Effect.provide(layerWithHostPlatform(platform)));
yield* manager.open(openInput());
const opened = yield* manager.open(openInput());
expect.soft(opened.shell, `${platform} ${shell}`).toBe(shell);
expect.soft(ptyAdapter.spawnInputs[0]?.args, `${platform} ${shell}`).toEqual(args);
}
}),
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/terminal/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ function snapshot(
status: session.status,
pid: session.pid,
supportsConditionalWrites: true,
shell: session.shell,
...snapshotHistory(session, supportsSnapshotSequenceState),
exitCode: session.exitCode,
exitSignal: session.exitSignal,
Expand All @@ -465,6 +466,7 @@ function summary(session: TerminalSessionState): TerminalSummary {
exitCode: session.exitCode,
exitSignal: session.exitSignal,
hasRunningSubprocess: session.hasRunningSubprocess,
shell: session.shell,
label: terminalWireLabel(session),
updatedAt: session.updatedAt,
};
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ function useChatMarkdownState(
skills = EMPTY_MARKDOWN_SKILLS,
onUseArtifactTemplate,
onRunShellCommand,
streamingId,
imageBaseDir,
workspaceMutationId,
onImageExpand,
Expand Down Expand Up @@ -1142,6 +1143,7 @@ function useChatMarkdownState(
onTaskListChange,
onUseArtifactTemplate,
onRunShellCommand,
streamingId,
openChangeRequestLink,
startDeferredLinkOpen,
openIssueLink,
Expand Down Expand Up @@ -1886,6 +1888,8 @@ const CHAT_MARKDOWN_COMPONENTS = {
isStreaming,
onRunShellCommand,
previewMarkdownFences,
threadRef,
streamingId,
} = use(ChatMarkdownRendererContext);
const text = use(ChatMarkdownTextContext);
const codeBlock = extractCodeBlock(children);
Expand Down Expand Up @@ -1952,6 +1956,9 @@ const CHAT_MARKDOWN_COMPONENTS = {
language={language}
fenceTitle={fenceTitle}
theme={resolvedTheme}
threadRef={threadRef}
messageId={streamingId}
blockOffset={node?.position?.start.offset}
onRunShellCommand={
onRunShellCommand && !isStreaming && isClosedCodeFence(node, text, codeBlock.code)
? onRunShellCommand
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/components/PersistentThreadTerminals.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isInlineTerminalId } from "../lib/inlineTerminal";
import {
AuthTerminalOperateScope,
type EnvironmentId,
Expand Down Expand Up @@ -92,8 +93,11 @@ export const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerm
panelSurfaces.flatMap((surface) => (surface.kind === "terminal" ? surface.terminalIds : [])),
);
const drawerTerminalSessions =
knownTerminalSessions?.filter((session) => !panelTerminalIds.has(session.target.terminalId)) ??
[];
knownTerminalSessions?.filter(
(session) =>
!panelTerminalIds.has(session.target.terminalId) &&
!isInlineTerminalId(session.target.terminalId),
) ?? [];
const terminalLabelsById = new Map<string, string>();
for (const session of drawerTerminalSessions) {
terminalLabelsById.set(
Expand Down
12 changes: 7 additions & 5 deletions apps/web/src/components/ThreadStatusIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
} from "react";
import { cn } from "../lib/utils";
import { Button } from "./ui/button";
import { isInlineTerminalId } from "../lib/inlineTerminal";
import { revealThreadTerminal } from "../lib/revealThreadTerminal";

import { useEnvironmentQuery } from "../state/query";
Expand Down Expand Up @@ -946,14 +947,15 @@ export function ThreadTerminalStatusButton({
}) {
const gt = useGT();
const messages = useMessages();
const terminalId = terminalIds[0];
const drawerTerminalIds = terminalIds.filter((id) => !isInlineTerminalId(id));
const terminalId = drawerTerminalIds[0];
if (terminalId === undefined) return null;
const status = terminalStatusFromRunningIds(terminalIds, messages);
const status = terminalStatusFromRunningIds(drawerTerminalIds, messages);
const label = gt`${plural(
{ count: terminalIds.length },
{ count: drawerTerminalIds.length },
{
one: part`${{ count: terminalIds.length }} terminal process running. Open terminal`,
other: part`${{ count: terminalIds.length }} terminal processes running. Open terminal`,
one: part`${{ count: drawerTerminalIds.length }} terminal process running. Open terminal`,
other: part`${{ count: drawerTerminalIds.length }} terminal processes running. Open terminal`,
},
)}`;
return (
Expand Down
16 changes: 11 additions & 5 deletions apps/web/src/components/ThreadTerminalDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import { useEnvironmentScope } from "../state/session";
import { openTerminalLinkInPreview } from "./preview/openTerminalLinkInPreview";
import { useOpenInSystemBrowser } from "../browser/useOpenInSystemBrowser";
import { terminalInputWriter } from "./terminal/terminalInputWriter";
import { createInlineTerminalDisplay, isInlineTerminalId } from "../lib/inlineTerminal";
import { useAtomCommand } from "../state/use-atom-command";
import { preventTerminalCloseShortcut } from "../lib/terminalCloseShortcut";
import { observeResize } from "../lib/observeResize";
Expand Down Expand Up @@ -168,11 +169,12 @@ function writeSystemMessage(
export function writeTerminalOutputUpdate(
terminal: Pick<GhosttyTerminalSurface, "resetAndWrite" | "write">,
update: TerminalOutputUpdate,
display?: ReturnType<typeof createInlineTerminalDisplay>,
): void {
if (update.type === "reset") {
terminal.resetAndWrite(update.data);
terminal.resetAndWrite(display ? display(update.data, true) : update.data);
} else if (update.type === "append") {
terminal.write(update.data);
terminal.write(display ? display(update.data, false) : update.data);
}
}

Expand All @@ -195,14 +197,15 @@ export function synchronizeTerminalOutput(
>,
session: Pick<TerminalSessionState, "output" | "version">,
cursor: TerminalOutputCursor,
display?: ReturnType<typeof createInlineTerminalDisplay>,
): TerminalOutputCursor {
if (session.version === 0) return cursor;
const update = readTerminalOutputUpdate(session.output, cursor);
if (update.type === "none") return update.cursor;
const cells = terminal.getSelectionCellCount();
const compared = cells <= MAX_COMPARED_SELECTION_CELLS;
const selection = cells > 0 && compared ? terminal.getSelection() : "";
writeTerminalOutputUpdate(terminal, update);
writeTerminalOutputUpdate(terminal, update, display);
if (!compared || (cells > 0 && terminal.getSelection() !== selection)) {
terminal.clearSelection({ source: "output" });
}
Expand All @@ -215,11 +218,12 @@ export function synchronizeTerminalSession(
previous: Pick<TerminalSessionState, "output" | "version" | "error">,
session: Pick<TerminalSessionState, "output" | "version" | "error">,
cursor: TerminalOutputCursor,
display?: ReturnType<typeof createInlineTerminalDisplay>,
): TerminalOutputCursor {
const nextCursor =
session.version === previous.version && session.output === previous.output
? cursor
: synchronizeTerminalOutput(terminal, session, cursor);
: synchronizeTerminalOutput(terminal, session, cursor, display);
// An attach failure can change only the error, keeping the last buffer.
if (
session.error !== null &&
Expand Down Expand Up @@ -802,13 +806,14 @@ function TerminalSessionViewport({
void terminal.setFont(terminalFontOptions(currentFont.family, currentFont.size));
}
const latestSession = readTerminalSession();
const display = isInlineTerminalId(terminalId) ? createInlineTerminalDisplay() : undefined;
terminal.setSharedGrid(latestSession.grid);
const initialOutput = readTerminalOutputUpdate(
latestSession.output,
INITIAL_TERMINAL_OUTPUT_CURSOR,
);
if (initialOutput.type === "reset" && initialOutput.data.length > 0) {
writeTerminalOutputUpdate(terminal, initialOutput);
writeTerminalOutputUpdate(terminal, initialOutput, display);
}
outputCursorRef.current = initialOutput.cursor;
if (latestSession.error !== null) writeSystemMessage(terminal, latestSession.error);
Expand All @@ -835,6 +840,7 @@ function TerminalSessionViewport({
previous,
session,
outputCursorRef.current,
display,
);
}),
);
Expand Down
Loading
Loading