@@ -105,19 +105,23 @@ let isStreaming = false;
105105 /**
106106 * A tool call observed during streaming, before it lands in history.
107107 *
108- * Stores the tool name and arguments from `tool_start`, and the
109- * result text from `tool_end` (filled in when the tool finishes).
108+ * Stores the tool name and arguments from `tool_start`, progressive
109+ * text updates from `tool_delta`, and the final result from `tool_end`.
110110 */
111111 /** A pending tool call shown in the streaming tail. */
112112 export interface PendingToolCall {
113+ /** Tool call id from the assistant message. */
114+ toolCallId: string;
113115 /** Tool name. */
114116 name: string;
115117 /** Tool call arguments. */
116118 args: Record<string, unknown>;
117- /** Text result, or `null` while still running. */
118- resultText: string | null;
119+ /** Progressive text output captured so far. */
120+ resultText: string;
119121 /** Whether the tool result was an error. */
120122 isError: boolean;
123+ /** Whether the tool has finished. */
124+ done: boolean;
121125 }
122126
123127 /** Render options shared by completed and streaming assistant content. */
@@ -536,6 +540,16 @@ function renderToolBlock(lines: readonly ToolRenderLine[], theme: Theme): Node {
536540 ]);
537541 }
538542
543+/** Extract text blocks from a tool result for UI rendering. */
544+function getToolResultText(
545+ result: Extract<AgentEvent, { type: "tool_delta" | "tool_end" }>["result"],
546+): string {
547+ return result.content
548+ .filter((content): content is TextContent => content.type === "text")
549+ .map((content) => content.text)
550+ .join("\n");
551+}
552+
539553 /** Render a shell tool call with left border. */
540554 function renderShellToolCall(
541555 command: string,
@@ -629,6 +643,85 @@ export function renderToolResult(
629643 // Streaming response rendering
630644 // ---------------------------------------------------------------------------
631645
646+/** Render a pending tool call, including progressive output when available. */
647+function renderPendingToolCall(
648+ toolCall: PendingToolCall,
649+ opts: Pick<ConversationRenderOpts, "verbose" | "theme">,
650+): Node {
651+ const runningLine: ToolRenderLine = {
652+ kind: "summary",
653+ text: "Running...",
654+ };
655+
656+ if (toolCall.resultText) {
657+ if (toolCall.name === "shell") {
658+ return renderToolBlock(
659+ [
660+ ...buildShellToolLines(
661+ toolCall.args.command as string,
662+ toolCall.resultText,
663+ opts.verbose,
664+ ),
665+ ...(toolCall.done ? [] : [runningLine]),
666+ ],
667+ opts.theme,
668+ );
669+ }
670+
671+ if (toolCall.name === "edit") {
672+ return renderToolBlock(
673+ [
674+ { kind: "path", text: `~ ${String(toolCall.args.path ?? "")}` },
675+ ...previewToolRenderLines(
676+ splitToolTextLines(
677+ toolCall.resultText,
678+ toolCall.isError ? "error" : "text",
679+ ),
680+ opts.verbose,
681+ ),
682+ ...(toolCall.done ? [] : [runningLine]),
683+ ],
684+ opts.theme,
685+ );
686+ }
687+
688+ return renderToolBlock(
689+ [
690+ { kind: "toolName", text: toolCall.name },
691+ ...splitToolTextLines(
692+ toolCall.resultText,
693+ toolCall.isError ? "error" : "text",
694+ ),
695+ ...(toolCall.done ? [] : [runningLine]),
696+ ],
697+ opts.theme,
698+ );
699+ }
700+
701+ const label =
702+ toolCall.name === "shell"
703+ ? `$ ${toolCall.args.command ?? ""}`
704+ : toolCall.name === "edit"
705+ ? `~ ${toolCall.args.path ?? ""}`
706+ : toolCall.name;
707+
708+ return renderToolBlock(
709+ [
710+ {
711+ kind:
712+ toolCall.name === "shell"
713+ ? "command"
714+ : toolCall.name === "edit"
715+ ? "path"
716+ : "toolName",
717+ text: label,
718+ },
719+ ...(toolCall.done ? [] : [runningLine]),
720+ ],
721+ opts.theme,
722+ );
723+}
724+
632725 /**
633726 * Render the in-progress streaming response.
634727 *
@@ -656,28 +749,8 @@ export function renderStreamingResponse(
656749 children.push(...renderMarkdownContent(streaming.text));
657750 }
658751
659- for (const tc of streaming.pendingToolCalls) {
660- if (tc.resultText !== null) {
661- children.push(
662- renderToolResult(tc.name, tc.args, tc.resultText, tc.isError, opts),
663- );
664- } else {
665- // Tool still running — show indicator
666- const label =
667- tc.name === "shell"
668- ? `$ ${tc.args.command ?? ""}…`
669- : tc.name === "edit"
670- ? `~ ${tc.args.path ?? ""}…`
671- : `${tc.name}…`;
672- children.push(
673- HStack({ padding: { x: 1 } }, [
674- Text("│ ", { fgColor: opts.theme.toolBorder }),
675- VStack({ flex: 1 }, [
676- Text(label, { fgColor: "color06", italic: true }),
677- ]),
678- ]),
679- );
680- }
752+ for (const toolCall of streaming.pendingToolCalls) {
753+ children.push(renderPendingToolCall(toolCall, opts));
681754 }
682755
683756 if (children.length === 0) {
@@ -1439,6 +1512,7 @@ async function submitMessage(text: string, state: AppState): Promise<void> {
14391512 signal: state.abortController.signal,
14401513 onEvent: (event) => handleAgentEvent(event, state),
14411514 });
1515+ state.messages = loadMessages(state.db, state.session.id);
14421516 state.stats = computeStats(state.messages);
14431517 } finally {
14441518 state.running = false;
@@ -1475,25 +1549,38 @@ function handleAgentEvent(event: AgentEvent, state: AppState): void {
14751549 streamingText = "";
14761550 streamingThinking = "";
14771551 pendingToolCalls.push({
1552+ toolCallId: event.toolCallId,
14781553 name: event.name,
14791554 args: event.args,
1480- resultText: null,
1555+ resultText: "",
14811556 isError: false,
1557+ done: false,
14821558 });
14831559 stickToBottom = true;
14841560 cel.render();
14851561 break;
14861562
1563+ case "tool_delta": {
1564+ const pending = pendingToolCalls.find(
1565+ (toolCall) => toolCall.toolCallId === event.toolCallId,
1566+ );
1567+ if (pending) {
1568+ pending.resultText = getToolResultText(event.result);
1569+ pending.isError = event.result.isError;
1570+ }
1571+ stickToBottom = true;
1572+ cel.render();
1573+ break;
1574+ }
1575+
14871576 case "tool_end": {
14881577 const pending = pendingToolCalls.find(
1489- (tc) => tc.name === event.name && tc.resultText === null,
1578+ (toolCall) => toolCall.toolCallId === event.toolCallId,
14901579 );
14911580 if (pending) {
1492- pending.resultText = event.result.content
1493- .filter((c) => c.type === "text")
1494- .map((c) => (c as TextContent).text)
1495- .join("\n");
1581+ pending.resultText = getToolResultText(event.result);
14961582 pending.isError = event.result.isError;
1583+ pending.done = true;
14971584 }
14981585 stickToBottom = true;
14991586 cel.render();