xonecas.io
64875
Mc

mini-coder / commit 3bfca32

feat: stream tool input deltas and consolidate render pipeline

- Add tool-input-delta event type and wire through stream → render
- Inline LiveReasoningBlock and StreamRenderContent into renderTurn
- Delete live-reasoning.ts, stream-render-content.ts
- Remove │ prefix from tool output, truncate long multiline inputs
- Remove dead Spinner.update() method
- Fix spinner visibility gaps during tool composition and context pruning

xonecas2026-03-22 3bfca32e6d536c8549e08beebea68b4270925052 parent 980bc9c

16 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

AGENTS.md+1−1
@@ -38,7 +38,7 @@ An augmented shell prompt coding agent — small, fast, stays out of the way.
3838 **Performance first, style second.** Instant feedback, shell-like output.
3939
4040 Focused on dev flow — minimal setup, fast to coding.
41-Output is a scrolling chronological log with strict hierarchy: actions → results → reasoning → responses. No redraws, no clearing — append-only like a terminal. Exception: `/new` clears the screen for a fresh start.
41+Output is a scrolling chronological log, append only with full streaming visibility to the user: actions → results → reasoning → responses. No redraws, no clearing — append-only like a terminal. Exception: `/new` clears the screen for a fresh start.
4242 Core features must be correct and fast before adding new ones.
4343 Community oriented — support AGENTS.md and agentskills.io specs, don't introduce new config formats.
4444
TODO.md+0−2
@@ -1,3 +1 @@
11 # mini-coder TODO
2-
3-- Expose tool input lifecycle hooks (`onInputStart`, `onInputDelta`, `onInputAvailable`) from AI SDK to the UI. Currently we only see tool results after execution. With these hooks we can show the user what the LLM is typing as tool input in real-time (e.g. stream the shell command as it's being generated, show mc-edit old/new text building up). `onInputStart`/`onInputDelta` are streaming-only (`streamText`). `onInputAvailable` fires when input is validated and ready — useful for both streamin …
src/cli/live-reasoning.test.ts+0−41
@@ -1,41 +0,0 @@
1-import { afterEach, describe, expect, test } from "bun:test";
2-import { LiveReasoningBlock } from "./live-reasoning.ts";
3-import {
4- captureStdout,
5- getCapturedStdout,
6- restoreStdout,
7- stripAnsi,
8-} from "./test-helpers.ts";
9-
10-afterEach(() => {
11- restoreStdout();
12-});
13-
14-describe("LiveReasoningBlock", () => {
15- test("streams partial reasoning immediately instead of waiting for finish", () => {
16- captureStdout();
17- const block = new LiveReasoningBlock();
18-
19- block.append("think");
20- expect(stripAnsi(getCapturedStdout())).toBe("· reasoning\n think");
21-
22- block.append("ing");
23- expect(stripAnsi(getCapturedStdout())).toBe("· reasoning\n thinking");
24-
25- block.finish();
26- expect(stripAnsi(getCapturedStdout())).toBe("· reasoning\n thinking\n");
27- });
28-
29- test("preserves blank reasoning lines and italic styling", () => {
30- captureStdout();
31- const block = new LiveReasoningBlock();
32-
33- block.append("line 1\n\nline 3");
34- block.finish();
35-
36- expect(stripAnsi(getCapturedStdout())).toBe(
37- "· reasoning\n line 1\n \n line 3\n",
38- );
39- expect(getCapturedStdout().includes("\x1b[3m")).toBe(true);
40- });
41-});
src/cli/live-reasoning.ts+0−52
@@ -1,52 +0,0 @@
1-import * as c from "yoctocolors";
2-import { G, write, writeln } from "./output.ts";
3-
4-function styleReasoningText(text: string): string {
5- return c.italic(c.dim(text));
6-}
7-
8-export class LiveReasoningBlock {
9- private blockOpen = false;
10- private lineOpen = false;
11-
12- append(delta: string): void {
13- if (!delta) return;
14- this.openBlock();
15- const lines = delta.split("\n");
16- for (const [index, line] of lines.entries()) {
17- if (line) this.writeText(line);
18- if (index < lines.length - 1) this.endLine();
19- }
20- }
21-
22- isOpen(): boolean {
23- return this.blockOpen;
24- }
25-
26- finish(): void {
27- if (!this.blockOpen) return;
28- if (this.lineOpen) writeln();
29- this.blockOpen = false;
30- this.lineOpen = false;
31- }
32-
33- private openBlock(): void {
34- if (this.blockOpen) return;
35- writeln(`${G.info} ${c.dim("reasoning")}`);
36- this.blockOpen = true;
37- }
38-
39- private writeText(text: string): void {
40- if (!this.lineOpen) {
41- write(" ");
42- this.lineOpen = true;
43- }
44- write(styleReasoningText(text));
45- }
46-
47- private endLine(): void {
48- if (!this.lineOpen) write(" ");
49- writeln();
50- this.lineOpen = false;
51- }
52-}
src/cli/spinner.ts+0−4
@@ -32,10 +32,6 @@ export class Spinner {
3232 terminal.stderrWrite("\r\x1B[2K\x1B[?25h");
3333 }
3434
35- update(label: string): void {
36- this.label = label;
37- }
38-
3935 private _tick(): void {
4036 const f = SPINNER_FRAMES[this.frame++ % SPINNER_FRAMES.length] ?? "⣾";
4137 const label = this.label ? c.dim(` ${this.label}`) : "";
src/cli/stream-render-content.ts+0−98
@@ -1,98 +0,0 @@
1-import { createHighlighter, type Highlighter } from "yoctomarkdown";
2-import { G, write, writeln } from "./output.ts";
3-import type { Spinner } from "./spinner.ts";
4-import { terminal } from "./terminal-io.ts";
5-
6-export class StreamRenderContent {
7- private inText = false;
8- private accumulatedText = "";
9- private accumulatedReasoning = "";
10- private highlighter: Highlighter | undefined;
11-
12- constructor(
13- private readonly spinner: Spinner,
14- private readonly quiet = false,
15- ) {}
16-
17- getText(): string {
18- return this.accumulatedText;
19- }
20-
21- getReasoning(): string {
22- return this.accumulatedReasoning;
23- }
24-
25- hasOpenContent(): boolean {
26- return this.inText;
27- }
28-
29- appendTextDelta(
30- delta: string | undefined,
31- renderedVisibleOutput: boolean,
32- ): void {
33- let text = delta ?? "";
34- if (!text) return;
35- if (!this.inText) {
36- text = text.trimStart();
37- if (!text) return;
38- if (!this.quiet) {
39- this.spinner.stop();
40- if (renderedVisibleOutput) writeln();
41- write(`${G.reply} `);
42- }
43- this.inText = true;
44- if (!this.quiet && terminal.isStdoutTTY)
45- this.highlighter = createHighlighter();
46- }
47- const isFirstLine = !this.accumulatedText.includes("\n");
48- this.accumulatedText += text;
49- if (this.quiet) return;
50- this.spinner.stop();
51- if (this.highlighter) {
52- let colored = this.highlighter.write(text);
53- if (colored) {
54- if (isFirstLine && colored.startsWith("\x1b[2K\r")) {
55- colored = `\x1b[2K\r${G.reply} ${colored.slice(5)}`;
56- }
57- write(colored);
58- }
59- } else {
60- write(text);
61- }
62- }
63-
64- appendReasoningDelta(delta: string | undefined): string {
65- const text = delta ?? "";
66- if (!text) return "";
67- let appended = text;
68- if (
69- this.accumulatedReasoning.endsWith("**") &&
70- text.startsWith("**") &&
71- !this.accumulatedReasoning.endsWith("\n")
72- ) {
73- appended = `\n${text}`;
74- }
75- this.accumulatedReasoning += appended;
76- return appended;
77- }
78-
79- flushOpenContent(): void {
80- if (!this.inText) return;
81- if (this.quiet) {
82- this.inText = false;
83- return;
84- }
85- if (this.highlighter) {
86- let finalColored = this.highlighter.end();
87- if (finalColored) {
88- const isFirstLine = !this.accumulatedText.includes("\n");
89- if (isFirstLine && finalColored.startsWith("\x1b[2K\r")) {
90- finalColored = `\x1b[2K\r${G.reply} ${finalColored.slice(5)}`;
91- }
92- write(finalColored);
93- }
94- }
95- writeln();
96- this.inText = false;
97- }
98-}
src/cli/stream-render.test.ts+82−0
@@ -311,6 +311,88 @@ describe("renderTurn", () => {
311311 expect(stripAnsi(getCapturedStdout())).toContain("hello");
312312 });
313313
314+ test("streams tool input deltas as composing line, then renders clean line", async () => {
315+ captureStdout();
316+
317+ await renderTurn(
318+ eventsFrom([
319+ {
320+ type: "tool-input-delta",
321+ toolName: "shell",
322+ toolCallId: "tool-stream",
323+ inputTextDelta: "echo ",
324+ },
325+ {
326+ type: "tool-input-delta",
327+ toolName: "shell",
328+ toolCallId: "tool-stream",
329+ inputTextDelta: "hello",
330+ },
331+ {
332+ type: "tool-call-start",
333+ toolName: "shell",
334+ toolCallId: "tool-stream",
335+ args: { command: "echo hello" },
336+ },
337+ {
338+ type: "tool-result",
339+ toolName: "shell",
340+ toolCallId: "tool-stream",
341+ isError: false,
342+ result: {
343+ stdout: "hello",
344+ stderr: "",
345+ exitCode: 0,
346+ success: true,
347+ timedOut: false,
348+ },
349+ },
350+ done(),
351+ ]),
352+ new Spinner(),
353+ );
354+
355+ const plain = stripAnsi(getCapturedStdout());
356+ // The composing line is overwritten by the final tool call line
357+ expect(plain).toContain("$ echo hello");
358+ // Should only show one tool call on stdout
359+ expect(countOccurrences(plain, "$ echo hello")).toBe(1);
360+ });
361+
362+ test("renders full tool-call-start when no deltas preceded it", async () => {
363+ captureStdout();
364+
365+ await renderTurn(
366+ eventsFrom([
367+ {
368+ type: "tool-call-start",
369+ toolName: "shell",
370+ toolCallId: "tool-no-delta",
371+ args: { command: "ls -la" },
372+ },
373+ {
374+ type: "tool-result",
375+ toolName: "shell",
376+ toolCallId: "tool-no-delta",
377+ isError: false,
378+ result: {
379+ stdout: "file.txt",
380+ stderr: "",
381+ exitCode: 0,
382+ success: true,
383+ timedOut: false,
384+ },
385+ },
386+ done(),
387+ ]),
388+ new Spinner(),
389+ );
390+
391+ const plain = stripAnsi(getCapturedStdout());
392+ expect(plain).toContain("ls -la");
393+ expect(plain).toContain("done exit 0");
394+ });
395+
314396 test("deduplicates repeated tool-call-start events for the same toolCallId", async () => {
315397 captureStdout();
316398
src/cli/stream-render.ts+188−37
@@ -1,21 +1,138 @@
11 import * as c from "yoctocolors";
2+import { createHighlighter, type Highlighter } from "yoctomarkdown";
3+
24 import { buildAbortMessages, isAbortError } from "../agent/agent-helpers.ts";
35 import type { CoreMessage } from "../llm-api/turn.ts";
46 import type { TurnEvent } from "../llm-api/types.ts";
5-import { LiveReasoningBlock } from "./live-reasoning.ts";
6-import { G, RenderedError, renderError, writeln } from "./output.ts";
7+
8+import { G, RenderedError, renderError, write, writeln } from "./output.ts";
79 import {
810 normalizeReasoningDelta,
911 normalizeReasoningText,
1012 } from "./reasoning.ts";
1113 import type { Spinner } from "./spinner.ts";
12-import { StreamRenderContent } from "./stream-render-content.ts";
14+import { terminal } from "./terminal-io.ts";
1315 import {
1416 buildToolCallLine,
1517 renderToolCall,
1618 renderToolResult,
1719 } from "./tool-render.ts";
1820
21+// ─── Inline reasoning rendering ──────────────────────────────────────────────
22+
23+function styleReasoning(text: string): string {
24+ return c.italic(c.dim(text));
25+}
26+
27+function writeReasoningDelta(
28+ delta: string,
29+ state: { blockOpen: boolean; lineOpen: boolean },
30+): void {
31+ if (!delta) return;
32+ if (!state.blockOpen) {
33+ writeln(`${G.info} ${c.dim("reasoning")}`);
34+ state.blockOpen = true;
35+ }
36+ const lines = delta.split("\n");
37+ for (const [i, line] of lines.entries()) {
38+ if (line) {
39+ if (!state.lineOpen) {
40+ write(" ");
41+ state.lineOpen = true;
42+ }
43+ write(styleReasoning(line));
44+ }
45+ if (i < lines.length - 1) {
46+ if (!state.lineOpen) write(" ");
47+ writeln();
48+ state.lineOpen = false;
49+ }
50+ }
51+}
52+
53+function finishReasoning(state: {
54+ blockOpen: boolean;
55+ lineOpen: boolean;
56+}): void {
57+ if (!state.blockOpen) return;
58+ if (state.lineOpen) writeln();
59+ state.blockOpen = false;
60+ state.lineOpen = false;
61+}
62+
63+// ─── Inline text streaming ───────────────────────────────────────────────────
64+
65+function appendTextDelta(
66+ delta: string | undefined,
67+ state: {
68+ inText: boolean;
69+ text: string;
70+ highlighter: Highlighter | undefined;
71+ },
72+ spinner: Spinner,
73+ quiet: boolean,
74+ renderedVisibleOutput: boolean,
75+): boolean {
76+ let chunk = delta ?? "";
77+ if (!chunk) return state.inText;
78+ if (!state.inText) {
79+ chunk = chunk.trimStart();
80+ if (!chunk) return false;
81+ if (!quiet) {
82+ spinner.stop();
83+ if (renderedVisibleOutput) writeln();
84+ write(`${G.reply} `);
85+ }
86+ state.inText = true;
87+ if (!quiet && terminal.isStdoutTTY) {
88+ state.highlighter = createHighlighter();
89+ }
90+ }
91+ const isFirstLine = !state.text.includes("\n");
92+ state.text += chunk;
93+ if (quiet) return state.inText;
94+ spinner.stop();
95+ if (state.highlighter) {
96+ let colored = state.highlighter.write(chunk);
97+ if (colored) {
98+ if (isFirstLine && colored.startsWith("\x1b[2K\r")) {
99+ colored = `\x1b[2K\r${G.reply} ${colored.slice(5)}`;
100+ }
101+ write(colored);
102+ }
103+ } else {
104+ write(chunk);
105+ }
106+ return state.inText;
107+}
108+
109+function flushText(
110+ state: {
111+ inText: boolean;
112+ text: string;
113+ highlighter: Highlighter | undefined;
114+ },
115+ quiet: boolean,
116+): void {
117+ if (!state.inText) return;
118+ if (!quiet) {
119+ if (state.highlighter) {
120+ let finalColored = state.highlighter.end();
121+ if (finalColored) {
122+ const isFirstLine = !state.text.includes("\n");
123+ if (isFirstLine && finalColored.startsWith("\x1b[2K\r")) {
124+ finalColored = `\x1b[2K\r${G.reply} ${finalColored.slice(5)}`;
125+ }
126+ write(finalColored);
127+ }
128+ }
129+ writeln();
130+ }
131+ state.inText = false;
132+}
133+
134+// ─── Main render loop ────────────────────────────────────────────────────────
135+
19136 export async function renderTurn(
20137 events: AsyncIterable<TurnEvent>,
21138 spinner: Spinner,
@@ -30,23 +147,35 @@ export async function renderTurn(
30147 const quiet = opts?.quiet ?? false;
31148 const showReasoning = !quiet && (opts?.showReasoning ?? true);
32149 const verboseOutput = opts?.verboseOutput ?? false;
33- const content = new StreamRenderContent(spinner, quiet);
34- const liveReasoning = new LiveReasoningBlock();
35150
151+ // Text state
152+ const textState = {
153+ inText: false,
154+ text: "",
155+ highlighter: undefined as Highlighter | undefined,
156+ };
157+
158+ // Reasoning state
159+ let reasoningRaw = "";
160+ let reasoningComputed = false;
161+ let reasoningText = "";
162+ const reasoningState = { blockOpen: false, lineOpen: false };
163+
164+ // Tool state
165+ const startedToolCalls = new Set<string>();
166+ const toolCallInfo = new Map<string, { toolName: string; label: string }>();
167+ let parallelCallCount = 0;
168+
169+ // Output tracking
36170 let inputTokens = 0;
37171 let outputTokens = 0;
38172 let contextTokens = 0;
39173 let newMessages: CoreMessage[] = [];
40- const startedToolCalls = new Set<string>();
41- const toolCallInfo = new Map<string, { toolName: string; label: string }>();
42- let parallelCallCount = 0;
43174 let renderedVisibleOutput = false;
44175
45- let reasoningComputed = false;
46- let reasoningText = "";
47176 const getReasoningText = (): string => {
48177 if (!reasoningComputed) {
49- reasoningText = normalizeReasoningText(content.getReasoning());
178+ reasoningText = normalizeReasoningText(reasoningRaw);
50179 reasoningComputed = true;
51180 }
52181 return reasoningText;
@@ -55,30 +184,49 @@ export async function renderTurn(
55184 for await (const event of events) {
56185 switch (event.type) {
57186 case "text-delta": {
58- liveReasoning.finish();
59- content.appendTextDelta(event.delta, renderedVisibleOutput);
60- if (content.hasOpenContent()) renderedVisibleOutput = true;
187+ finishReasoning(reasoningState);
188+ textState.inText = appendTextDelta(
189+ event.delta,
190+ textState,
191+ spinner,
192+ quiet,
193+ renderedVisibleOutput,
194+ );
195+ if (textState.inText) renderedVisibleOutput = true;
61196 break;
62197 }
198+
63199 case "reasoning-delta": {
64- content.flushOpenContent();
65- const delta = content.appendReasoningDelta(
66- normalizeReasoningDelta(event.delta),
67- );
200+ flushText(textState, quiet);
201+ let appended = normalizeReasoningDelta(event.delta);
202+ if (
203+ reasoningRaw.endsWith("**") &&
204+ appended.startsWith("**") &&
205+ !reasoningRaw.endsWith("\n")
206+ ) {
207+ appended = `\n${appended}`;
208+ }
209+ reasoningRaw += appended;
68210 reasoningComputed = false;
69- if (showReasoning && delta) {
211+ if (showReasoning && appended) {
70212 spinner.stop();
71- if (renderedVisibleOutput && !liveReasoning.isOpen()) writeln();
72- liveReasoning.append(delta);
213+ if (renderedVisibleOutput && !reasoningState.blockOpen) writeln();
214+ writeReasoningDelta(appended, reasoningState);
73215 renderedVisibleOutput = true;
74216 }
75217 break;
76218 }
77219
220+ case "tool-input-delta": {
221+ if (quiet) break;
222+ finishReasoning(reasoningState);
223+ flushText(textState, quiet);
224+ spinner.start(`composing ${event.toolName}…`);
225+ break;
226+ }
227+
78228 case "tool-call-start": {
79- if (startedToolCalls.has(event.toolCallId)) {
80- break;
81- }
229+ if (startedToolCalls.has(event.toolCallId)) break;
82230 const isConsecutiveToolCall =
83231 startedToolCalls.size > 0 && toolCallInfo.size > 0;
84232 startedToolCalls.add(event.toolCallId);
@@ -89,12 +237,14 @@ export async function renderTurn(
89237 if (toolCallInfo.size > 1) {
90238 parallelCallCount = toolCallInfo.size;
91239 }
92- liveReasoning.finish();
93- content.flushOpenContent();
240+ finishReasoning(reasoningState);
241+ flushText(textState, quiet);
94242 if (!quiet) {
95243 spinner.stop();
96- if (renderedVisibleOutput && !isConsecutiveToolCall) writeln();
97- renderToolCall(event.toolName, event.args);
244+ if (renderedVisibleOutput && !isConsecutiveToolCall) {
245+ writeln();
246+ }
247+ renderToolCall(event.toolName, event.args, { verboseOutput });
98248 renderedVisibleOutput = true;
99249 spinner.start(event.toolName);
100250 }
@@ -105,11 +255,11 @@ export async function renderTurn(
105255 startedToolCalls.delete(event.toolCallId);
106256 const callInfo = toolCallInfo.get(event.toolCallId);
107257 toolCallInfo.delete(event.toolCallId);
108- liveReasoning.finish();
258+ finishReasoning(reasoningState);
109259 if (!quiet) {
110260 spinner.stop();
111261 if (parallelCallCount > 1 && callInfo) {
112- writeln(` ${c.dim("↳")} ${callInfo.label}`);
262+ writeln(`${c.dim("↳")} ${callInfo.label}`);
113263 }
114264 if (toolCallInfo.size === 0) parallelCallCount = 0;
115265 renderToolResult(event.toolName, event.result, event.isError, {
@@ -124,8 +274,8 @@ export async function renderTurn(
124274 }
125275
126276 case "context-pruned": {
127- liveReasoning.finish();
128- content.flushOpenContent();
277+ finishReasoning(reasoningState);
278+ flushText(textState, quiet);
129279 if (!quiet) {
130280 spinner.stop();
131281 const removedKb = (event.removedBytes / 1024).toFixed(1);
@@ -133,13 +283,14 @@ export async function renderTurn(
133283 `${G.info} ${c.dim("context pruned")} ${c.dim(`–${event.removedMessageCount} messages`)} ${c.dim(`–${removedKb} KB`)}`,
134284 );
135285 renderedVisibleOutput = true;
286+ spinner.start("thinking");
136287 }
137288 break;
138289 }
139290
140291 case "turn-complete": {
141- liveReasoning.finish();
142- content.flushOpenContent();
292+ finishReasoning(reasoningState);
293+ flushText(textState, quiet);
143294 spinner.stop();
144295 if (!quiet && !renderedVisibleOutput) writeln();
145296 inputTokens = event.inputTokens;
@@ -150,8 +301,8 @@ export async function renderTurn(
150301 }
151302
152303 case "turn-error": {
153- liveReasoning.finish();
154- content.flushOpenContent();
304+ finishReasoning(reasoningState);
305+ flushText(textState, quiet);
155306 spinner.stop();
156307 inputTokens = event.inputTokens;
157308 outputTokens = event.outputTokens;
@@ -159,7 +310,7 @@ export async function renderTurn(
159310 if (isAbortError(event.error)) {
160311 newMessages = buildAbortMessages(
161312 event.partialMessages,
162- content.getText(),
313+ textState.text,
163314 );
164315 } else {
165316 renderError(event.error, "turn");
src/cli/tool-render.test.ts+56−16
@@ -5,20 +5,22 @@ import {
55 restoreStdout,
66 stripAnsi,
77 } from "./test-helpers.ts";
8-import { buildToolCallLine, renderToolResult } from "./tool-render.ts";
8+import {
9+ buildToolCallLine,
10+ renderToolCall,
11+ renderToolResult,
12+} from "./tool-render.ts";
913
1014 afterEach(() => {
1115 restoreStdout();
1216 });
1317
1418 describe("buildToolCallLine", () => {
15- test("formats shell calls with truncated command previews", () => {
16- const line = buildToolCallLine("shell", {
17- command: "echo x".repeat(30),
18- });
19+ test("formats shell calls without truncation", () => {
20+ const cmd = "echo x".repeat(30);
21+ const line = buildToolCallLine("shell", { command: cmd });
1922 expect(line).toContain("$");
20- expect(line).toContain("echo x");
21- expect(line).toContain("…");
23+ expect(line).toContain(cmd);
2224 });
2325
2426 test("formats empty shell start events as a generic shell label", () => {
@@ -57,6 +59,44 @@ describe("buildToolCallLine", () => {
5759 });
5860 });
5961
62+describe("renderToolCall", () => {
63+ test("truncates multiline shell commands when not verbose", () => {
64+ captureStdout();
65+ const lines = Array.from({ length: 10 }, (_, i) => `line ${i}`);
66+ renderToolCall("shell", { command: lines.join("\n") });
67+ const out = stripAnsi(getCapturedStdout());
68+ expect(out).toContain("line 0");
69+ expect(out).toContain("line 2");
70+ expect(out).toContain("… +5 lines");
71+ expect(out).toContain("line 8");
72+ expect(out).toContain("line 9");
73+ expect(out).not.toContain("line 5");
74+ });
75+
76+ test("shows full command when verbose", () => {
77+ captureStdout();
78+ const lines = Array.from({ length: 10 }, (_, i) => `line ${i}`);
79+ renderToolCall(
80+ "shell",
81+ { command: lines.join("\n") },
82+ { verboseOutput: true },
83+ );
84+ const out = stripAnsi(getCapturedStdout());
85+ for (let i = 0; i < 10; i++) {
86+ expect(out).toContain(`line ${i}`);
87+ }
88+ expect(out).not.toContain("… +");
89+ });
90+
91+ test("does not truncate short commands", () => {
92+ captureStdout();
93+ renderToolCall("shell", { command: "ls -la" });
94+ const out = stripAnsi(getCapturedStdout());
95+ expect(out).toContain("ls -la");
96+ expect(out).not.toContain("…");
97+ });
98+});
99+
60100 describe("renderToolResult", () => {
61101 test("shows stderr preview for failed commands", () => {
62102 captureStdout();
@@ -75,7 +115,7 @@ describe("renderToolResult", () => {
75115
76116 const plain = stripAnsi(getCapturedStdout());
77117 expect(plain).toContain("error exit 1 · stderr 1L");
78- expect(plain).toContain("│ boom");
118+ expect(plain).toContain("boom");
79119 });
80120
81121 test("shows stdout previews for successful multi-line commands", () => {
@@ -96,8 +136,8 @@ describe("renderToolResult", () => {
96136 const plain = stripAnsi(getCapturedStdout());
97137 expect(plain).toContain("done exit 0 · stdout 2L");
98138 expect(plain).toContain("stdout (2 lines)");
99- expect(plain).toContain("│ hello");
100- expect(plain).toContain("│ world");
139+ expect(plain).toContain("hello");
140+ expect(plain).toContain("world");
101141 });
102142
103143 test("truncates shell previews by keeping head and tail when verbose is off", () => {
@@ -120,11 +160,11 @@ describe("renderToolResult", () => {
120160 );
121161
122162 const plain = stripAnsi(getCapturedStdout());
123- expect(plain).toContain("│ line-1");
124- expect(plain).toContain("│ line-10");
163+ expect(plain).toContain("line-1");
164+ expect(plain).toContain("line-10");
125165 expect(plain).toContain("… +10 lines");
126- expect(plain).toContain("│ line-21");
127- expect(plain).toContain("│ line-30");
166+ expect(plain).toContain("line-21");
167+ expect(plain).toContain("line-30");
128168 });
129169
130170 test("shows full shell previews when verbose is on", () => {
@@ -148,8 +188,8 @@ describe("renderToolResult", () => {
148188 );
149189
150190 const plain = stripAnsi(getCapturedStdout());
151- expect(plain).toContain("│ line-1");
152- expect(plain).toContain("│ line-8");
191+ expect(plain).toContain("line-1");
192+ expect(plain).toContain("line-8");
153193 expect(plain).not.toContain("… +");
154194 });
155195
src/cli/tool-render.ts+27−12
@@ -1,5 +1,4 @@
11 import * as c from "yoctocolors";
2-import { truncateText } from "../internal/text.ts";
32 import { G, tildePath, writeln } from "./output.ts";
43 import { renderToolResultByName } from "./tool-result-renderers.ts";
54
@@ -76,8 +75,7 @@ function formatShellCallLine(cmd: string): string {
7675 const firstCmd = extractFirstCommand(rest);
7776 const glyph = shellCmdGlyph(firstCmd, rest);
7877 const cwdSuffix = cwd ? ` ${c.dim(`in ${cwd}`)}` : "";
79- const display = truncateText(rest, 80);
80- return `${glyph} ${display}${cwdSuffix}`;
78+ return `${glyph} ${rest}${cwdSuffix}`;
8179 }
8280
8381 export function buildToolCallLine(name: string, args: unknown): string {
@@ -101,8 +99,7 @@ export function buildToolCallLine(name: string, args: unknown): string {
10199
102100 if (name === "webSearch") {
103101 const query = typeof a.query === "string" ? a.query : "";
104- const short = query.length > 60 ? `${query.slice(0, 57)}…` : query;
105- return `${G.search} ${c.dim("search")}${short ? ` ${short}` : ""}`;
102+ return `${G.search} ${c.dim("search")}${query ? ` ${query}` : ""}`;
106103 }
107104
108105 if (name === "webContent") {
@@ -111,8 +108,7 @@ export function buildToolCallLine(name: string, args: unknown): string {
111108 urls.length === 1
112109 ? String(urls[0])
113110 : `${urls.length} url${urls.length !== 1 ? "s" : ""}`;
114- const short = label.length > 60 ? `${label.slice(0, 57)}…` : label;
115- return `${G.read} ${c.dim("fetch")} ${short}`;
111+ return `${G.read} ${c.dim("fetch")} ${label}`;
116112 }
117113
118114 if (name.startsWith("mcp_")) {
@@ -122,8 +118,27 @@ export function buildToolCallLine(name: string, args: unknown): string {
122118 return `${toolGlyph(name)} ${c.dim(name)}`;
123119 }
124120
125-export function renderToolCall(toolName: string, args: unknown): void {
126- writeln(` ${buildToolCallLine(toolName, args)}`);
121+export function renderToolCall(
122+ toolName: string,
123+ args: unknown,
124+ opts?: { verboseOutput?: boolean },
125+): void {
126+ const line = buildToolCallLine(toolName, args);
127+ if (opts?.verboseOutput) {
128+ writeln(line);
129+ return;
130+ }
131+ const lines = line.split("\n");
132+ if (lines.length <= 6) {
133+ writeln(line);
134+ return;
135+ }
136+ const head = lines.slice(0, 3);
137+ const tail = lines.slice(-2);
138+ const hidden = lines.length - head.length - tail.length;
139+ for (const l of head) writeln(l);
140+ writeln(c.dim(`… +${hidden} lines`));
141+ for (const l of tail) writeln(l);
127142 }
128143
129144 function formatErrorBadge(result: unknown): string {
@@ -146,7 +161,7 @@ export function renderToolResult(
146161 opts?: ToolResultRenderOptions,
147162 ): void {
148163 if (isError) {
149- writeln(` ${formatErrorBadge(result)}`);
164+ writeln(formatErrorBadge(result));
150165 return;
151166 }
152167
@@ -156,8 +171,8 @@ export function renderToolResult(
156171
157172 const text = JSON.stringify(result);
158173 if (opts?.verboseOutput || text.length <= 120) {
159- writeln(` ${c.dim(text)}`);
174+ writeln(c.dim(text));
160175 return;
161176 }
162- writeln(` ${c.dim(`${text.slice(0, 117)}…`)}`);
177+ writeln(c.dim(`${text.slice(0, 117)}…`));
163178 }
src/cli/tool-result-renderers.ts+26−31
@@ -14,32 +14,27 @@ type ToolResultRenderer = (
1414 function writePreviewLines(opts: {
1515 label: string;
1616 value: string;
17- lineColor: (input: string) => string;
1817 maxLines: number;
1918 }): void {
2019 if (!opts.value.trim()) return;
2120 const lines = opts.value.split("\n");
22- writeln(` ${c.dim(opts.label)} ${c.dim(`(${lines.length} lines)`)}`);
21+ if (opts.label)
22+ writeln(`${c.dim(opts.label)} ${c.dim(`(${lines.length} lines)`)}`);
23+
2324 if (!Number.isFinite(opts.maxLines) || lines.length <= opts.maxLines) {
24- for (const line of lines) {
25- writeln(` ${opts.lineColor("│")} ${line}`);
26- }
25+ for (const line of lines) writeln(line);
2726 return;
2827 }
2928
3029 const headCount = Math.max(1, Math.ceil(opts.maxLines / 2));
3130 const tailCount = Math.max(0, Math.floor(opts.maxLines / 2));
32- for (const line of lines.slice(0, headCount)) {
33- writeln(` ${opts.lineColor("│")} ${line}`);
34- }
31+ for (const line of lines.slice(0, headCount)) writeln(line);
3532 const hiddenLines = Math.max(0, lines.length - (headCount + tailCount));
3633 if (hiddenLines > 0) {
37- writeln(` ${opts.lineColor("│")} ${c.dim(`… +${hiddenLines} lines`)}`);
34+ writeln(c.dim(`… +${hiddenLines} lines`));
3835 }
3936 if (tailCount > 0) {
40- for (const line of lines.slice(-tailCount)) {
41- writeln(` ${opts.lineColor("│")} ${line}`);
42- }
37+ for (const line of lines.slice(-tailCount)) writeln(line);
4338 }
4439 }
4540
@@ -147,12 +142,11 @@ function renderShellResult(
147142 verboseOutput,
148143 });
149144
150- writeln(` ${badge} ${c.dim(parts.join(" · "))}`);
145+ writeln(`${badge} ${c.dim(parts.join(" · "))}`);
151146
152147 writePreviewLines({
153148 label: "stderr",
154149 value: displayStderr,
155- lineColor: c.red,
156150 maxLines: verboseOutput ? Number.POSITIVE_INFINITY : 10,
157151 });
158152 if (
@@ -166,7 +160,6 @@ function renderShellResult(
166160 writePreviewLines({
167161 label: "stdout",
168162 value: displayStdout,
169- lineColor: c.dim,
170163 maxLines: verboseOutput ? Number.POSITIVE_INFINITY : 20,
171164 });
172165 }
@@ -195,7 +188,7 @@ function renderSkillSummaryLine(
195188 const source = skill.source ?? "unknown";
196189 const labelPrefix = opts?.label ? `${c.dim(opts.label)} ` : "";
197190 writeln(
198- ` ${G.info} ${labelPrefix}${name} ${c.dim("·")} ${c.dim(source)}${buildSkillDescriptionPart(skill.description, opts?.verboseOutput === true)}`,
191+ `${G.info} ${labelPrefix}${name} ${c.dim("·")} ${c.dim(source)}${buildSkillDescriptionPart(skill.description, opts?.verboseOutput === true)}`,
199192 );
200193 }
201194
@@ -212,7 +205,7 @@ function renderListSkillsResult(
212205 };
213206 if (!Array.isArray(r?.skills)) return false;
214207 if (r.skills.length === 0) {
215- writeln(` ${G.info} ${c.dim("no skills")}`);
208+ writeln(`${G.info} ${c.dim("no skills")}`);
216209 return true;
217210 }
218211
@@ -224,7 +217,7 @@ function renderListSkillsResult(
224217 }
225218
226219 if (r.skills.length > maxSkills) {
227- writeln(` ${c.dim(`+${r.skills.length - maxSkills} more skills`)}`);
220+ writeln(`${c.dim(`+${r.skills.length - maxSkills} more skills`)}`);
228221 }
229222 return true;
230223 }
@@ -242,7 +235,7 @@ function renderReadSkillResult(
242235 };
243236 if (!r || typeof r !== "object") return false;
244237 if (!r.skill) {
245- writeln(` ${G.info} ${c.dim("skill")} ${c.dim("(not found)")}`);
238+ writeln(`${G.info} ${c.dim("skill")} ${c.dim("(not found)")}`);
246239 return true;
247240 }
248241 renderSkillSummaryLine(r.skill, {
@@ -261,7 +254,7 @@ function renderWebSearchResult(
261254 };
262255 if (!Array.isArray(r?.results)) return false;
263256 if (r.results.length === 0) {
264- writeln(` ${G.info} ${c.dim("no results")}`);
257+ writeln(`${G.info} ${c.dim("no results")}`);
265258 return true;
266259 }
267260
@@ -275,12 +268,12 @@ function renderWebSearchResult(
275268 typeof item.score === "number"
276269 ? c.dim(` (${item.score.toFixed(2)})`)
277270 : "";
278- writeln(` ${c.dim("•")} ${title}${score}`);
279- if (item.url) writeln(` ${c.dim(item.url)}`);
271+ writeln(`${c.dim("•")} ${title}${score}`);
272+ if (item.url) writeln(` ${c.dim(item.url)}`);
280273 }
281274
282275 if (r.results.length > maxResults) {
283- writeln(` ${c.dim(` +${r.results.length - maxResults} more`)}`);
276+ writeln(`${c.dim(`+${r.results.length - maxResults} more`)}`);
284277 }
285278 return true;
286279 }
@@ -294,7 +287,7 @@ function renderWebContentResult(
294287 };
295288 if (!Array.isArray(r?.results)) return false;
296289 if (r.results.length === 0) {
297- writeln(` ${G.info} ${c.dim("no pages")}`);
290+ writeln(`${G.info} ${c.dim("no pages")}`);
298291 return true;
299292 }
300293
@@ -304,20 +297,20 @@ function renderWebContentResult(
304297 /\s+/g,
305298 " ",
306299 );
307- writeln(` ${c.dim("•")} ${title}`);
308- if (item.url) writeln(` ${c.dim(item.url)}`);
300+ writeln(`${c.dim("•")} ${title}`);
301+ if (item.url) writeln(` ${c.dim(item.url)}`);
309302 const preview = (item.text ?? "").replace(/\s+/g, " ").trim();
310303 if (preview) {
311304 const trimmed =
312305 opts?.verboseOutput || preview.length <= 220
313306 ? preview
314307 : `${preview.slice(0, 217)}…`;
315- writeln(` ${c.dim(trimmed)}`);
308+ writeln(` ${c.dim(trimmed)}`);
316309 }
317310 }
318311
319312 if (r.results.length > maxPages) {
320- writeln(` ${c.dim(` +${r.results.length - maxPages} more`)}`);
313+ writeln(`${c.dim(`+${r.results.length - maxPages} more`)}`);
321314 }
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-execution.test.ts+6−0
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-execution.ts+13−0
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-stream-events.test.ts+29−1
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-stream-events.ts+17−1
Cut short: this commit's diff is over 1000 lines.
src/llm-api/types.ts+8−0
Cut short: this commit's diff is over 1000 lines.