xonecas.io
64875
Mc

mini-coder / commit ac0f2c7

refactor: remove streamed shell output rendering path

Remove the LiveOutputBlock streaming infrastructure:
- Delete live-output.ts
- Remove onOutput callback from shell tool input/execution
- Remove streamedOutput field from ShellOutput
- Remove streamChunk from CliReporter and Reporter interface
- Remove onShellOutput wiring from agent/tools/input-loop
- Remove onOutput from TOOL_RUNTIME_INPUT_KEYS filter
- Update all affected tests

Shell output is now rendered exclusively via the post-hoc preview
path (writePreviewLines), simplifying the codebase. Logs remain
available for debugging.

xonecas2026-03-16 ac0f2c7a5288ac3cef33b3e147fb75685d50fa75 parent 5624c3a

17 files changed

TODO.md+2−2
@@ -2,8 +2,7 @@
22
33 ## Bugs:
44
5-- Chat completions endpoint models sometimes print empty assistant messages.
6-- Are we doing any buffering when rendering assistant responses? It feels slower to render. The library we use is very fast and can render well, maybe it's something from before we adopted it?
5+- models sometimes print empty assistant messages. Or excessive leading whitespace. Seems like something is wrong.
76
87 ---
98
@@ -20,6 +19,7 @@ We could look into coloring the most used shell commands.
2019 - Ensure we have a good styled output that is clear to the user, refactor as needed.
2120 - Ensure we have propper hierchy in output, and the different types of output are clearly distinguishable for the user, using styles and whitespace.
2221 - Ensure proper spinner functionality, that follow up messages don't rended inline and that is doesn't break anything.
22+- Ensure conversation log is logical, and that user, assistant, assistant reasoning, and tools and tool calls and responses are clearly labelled and associated for readability
2323
2424 ---
2525
src/agent/agent.test.ts+0−1
@@ -121,7 +121,6 @@ describe("sanitizeModelAuthoredMessages", () => {
121121 input: {
122122 path: "TODO.md",
123123 cwd: "/tmp/project",
124- onOutput: "ignore",
125124 },
126125 },
127126 ],
src/agent/agent.ts+0−7
@@ -63,16 +63,10 @@ export async function initAgent(opts: AgentOptions): Promise<{
6363 cwd,
6464 () => currentModel,
6565 );
66- let verboseOutputEnabled = opts.initialVerboseOutput;
6766 const agents = loadAgents(cwd);
6867 const tools: ToolDef[] = buildToolSet({
6968 cwd,
7069 runSubagent,
71- onShellOutput: (chunk) => {
72- if (!verboseOutputEnabled) return false;
73- opts.reporter.streamChunk(chunk);
74- return true;
75- },
7670 availableAgents: subagentAgents(agents),
7771 });
7872
@@ -167,7 +161,6 @@ export async function initAgent(opts: AgentOptions): Promise<{
167161 },
168162 setVerboseOutput: (verbose) => {
169163 runner.verboseOutput = verbose;
170- verboseOutputEnabled = verbose;
171164 setPreferredVerboseOutput(verbose);
172165 },
173166 get pruningMode() {
src/agent/reporter.ts+1−3
@@ -28,9 +28,7 @@ export interface AgentReporter {
2828 info(msg: string): void;
2929 error(msg: string | Error, hint?: string): void;
3030 warn(msg: string): void;
31- writeText(text: string): void; // For raw text like passthrough shell output
32- /** Write a raw output chunk without adding a newline (e.g. streaming shell output). */
33- streamChunk(text: string): void;
31+ writeText(text: string): void;
3432
3533 startSpinner(label?: string): void;
3634 stopSpinner(): void;
src/agent/tools.ts+5−30
@@ -22,26 +22,6 @@ function withCwdDefault(tool: ToolDef, cwd: string): ToolDef {
2222 };
2323 }
2424
25-/**
26- * Inject an onOutput streaming callback into the shell tool's input.
27- */
28-function withShellOutput(
29- tool: ToolDef,
30- onOutput: (chunk: string) => boolean | undefined,
31-): ToolDef {
32- const originalExecute = tool.execute;
33- return {
34- ...tool,
35- execute: async (input: unknown) => {
36- const patched = {
37- ...(typeof input === "object" && input !== null ? input : {}),
38- onOutput,
39- } as Record<string, unknown>;
40- return originalExecute(patched);
41- },
42- };
43-}
44-
4525 export function buildToolSet(opts: {
4626 cwd: string;
4727 runSubagent: (
@@ -49,19 +29,14 @@ export function buildToolSet(opts: {
4929 agentName?: string,
5030 modelOverride?: string,
5131 ) => Promise<SubagentOutput>;
52- onShellOutput?: (chunk: string) => boolean | undefined;
5332 availableAgents: ReadonlyMap<string, { description: string }>;
5433 }): ToolDef[] {
55- const { cwd, onShellOutput } = opts;
34+ const { cwd } = opts;
5635
57- const shell = (
58- onShellOutput
59- ? withShellOutput(
60- withCwdDefault(shellTool as ToolDef, cwd),
61- onShellOutput,
62- )
63- : withCwdDefault(shellTool as ToolDef, cwd)
64- ) as ToolDef<{ cwd?: string; command: string }, ShellOutput>;
36+ const shell = withCwdDefault(shellTool as ToolDef, cwd) as ToolDef<
37+ { cwd?: string; command: string },
38+ ShellOutput
39+ >;
6540
6641 const tools: ToolDef[] = [
6742 shell as ToolDef,
src/cli/headless-reporter.ts+0−1
@@ -20,7 +20,6 @@ export class HeadlessReporter implements AgentReporter {
2020 error(_msg: string | Error, _hint?: string): void {}
2121 warn(_msg: string): void {}
2222 writeText(_text: string): void {}
23- streamChunk(_text: string): void {}
2423
2524 startSpinner(_label?: string): void {}
2625 stopSpinner(): void {}
src/cli/input-loop.ts+0−8
@@ -112,14 +112,6 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
112112 command: input.command,
113113 timeout: 30_000,
114114 cwd,
115- ...(cmdCtx.verboseOutput
116- ? {
117- onOutput: (chunk) => {
118- reporter.streamChunk(chunk);
119- return true;
120- },
121- }
122- : {}),
123115 });
124116 renderToolResult("shell", result, false, {
125117 verboseOutput: cmdCtx.verboseOutput,
src/cli/live-output.ts+0−54
@@ -1,54 +0,0 @@
1-import * as c from "yoctocolors";
2-import { terminal } from "./terminal-io.ts";
3-
4-const LIVE_OUTPUT_PREFIX = ` ${c.dim("│")} `;
5-
6-function write(text: string): void {
7- terminal.stdoutWrite(text);
8-}
9-
10-function writeln(text = ""): void {
11- terminal.stdoutWrite(`${text}\n`);
12-}
13-
14-export class LiveOutputBlock {
15- private pending = "";
16- private lineOpen = false;
17-
18- append(chunk: string): void {
19- if (!chunk) return;
20- this.pending += chunk.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
21- this.flushCompleteLines();
22- }
23-
24- finish(): void {
25- if (this.pending.length > 0) {
26- this.openLine();
27- write(this.pending);
28- this.pending = "";
29- }
30- if (this.lineOpen) {
31- writeln();
32- this.lineOpen = false;
33- }
34- }
35-
36- private flushCompleteLines(): void {
37- let boundary = this.pending.indexOf("\n");
38- while (boundary !== -1) {
39- const line = this.pending.slice(0, boundary);
40- this.openLine();
41- write(line);
42- writeln();
43- this.lineOpen = false;
44- this.pending = this.pending.slice(boundary + 1);
45- boundary = this.pending.indexOf("\n");
46- }
47- }
48-
49- private openLine(): void {
50- if (this.lineOpen) return;
51- write(LIVE_OUTPUT_PREFIX);
52- this.lineOpen = true;
53- }
54-}
src/cli/output.test.ts+1−24
@@ -1,5 +1,5 @@
11 import { afterEach, describe, expect, test } from "bun:test";
2-import { CliReporter, renderBanner, renderUserMessage } from "./output.ts";
2+import { renderBanner, renderUserMessage } from "./output.ts";
33 import { terminal } from "./terminal-io.ts";
44
55 let stdout = "";
@@ -48,26 +48,3 @@ describe("renderBanner", () => {
4848 expect(stripAnsi(stdout)).toContain("zen/gpt-5.4 · ~/src/mini-coder");
4949 });
5050 });
51-
52-describe("CliReporter live output", () => {
53- test("groups streamed chunks into an indented output block", () => {
54- captureStdout();
55- const reporter = new CliReporter();
56-
57- reporter.streamChunk("hello");
58- reporter.streamChunk("\nworld\n");
59- reporter.info("done");
60-
61- expect(stripAnsi(stdout)).toBe(" │ hello\n │ world\n· done\n");
62- });
63-
64- test("flushes an unterminated streamed line before the next log line", () => {
65- captureStdout();
66- const reporter = new CliReporter();
67-
68- reporter.streamChunk("partial line");
69- reporter.warn("next");
70-
71- expect(stripAnsi(stdout)).toBe(" │ partial line\n! next\n");
72- });
73-});
src/cli/output.ts+5−23
@@ -12,7 +12,6 @@ import { loadAgents } from "./agents.ts";
1212 import { loadCustomCommands } from "./custom-commands.ts";
1313 import { logError } from "./error-log.ts";
1414 import { parseAppError } from "./error-parse.ts";
15-import { LiveOutputBlock } from "./live-output.ts";
1615 import { loadSkillsIndex } from "./skills.ts";
1716 import { Spinner } from "./spinner.ts";
1817 import { renderStatusBar } from "./status-bar.ts";
@@ -163,24 +162,14 @@ export function renderBanner(model: string, cwd: string): void {
163162
164163 export class CliReporter implements AgentReporter {
165164 private spinner = new Spinner();
166- private liveOutput = new LiveOutputBlock();
167-
168- private haltSpinner(): void {
169- this.spinner.stop();
170- }
171-
172- private haltSpinnerAndFlushLiveOutput(): void {
173- this.spinner.stop();
174- this.liveOutput.finish();
175- }
176165
177166 info(msg: string): void {
178- this.haltSpinnerAndFlushLiveOutput();
167+ this.spinner.stop();
179168 writeln(`${G.info} ${c.dim(msg)}`);
180169 }
181170
182171 error(msg: string | Error, hint?: string): void {
183- this.haltSpinnerAndFlushLiveOutput();
172+ this.spinner.stop();
184173 if (typeof msg === "string") {
185174 renderError(msg, hint);
186175 } else {
@@ -189,38 +178,31 @@ export class CliReporter implements AgentReporter {
189178 }
190179
191180 warn(msg: string): void {
192- this.haltSpinnerAndFlushLiveOutput();
181+ this.spinner.stop();
193182 writeln(`${G.warn} ${msg}`);
194183 }
195184
196185 writeText(text: string): void {
197- this.haltSpinnerAndFlushLiveOutput();
186+ this.spinner.stop();
198187 writeln(text);
199188 }
200189
201- streamChunk(text: string): void {
202- this.haltSpinner();
203- this.liveOutput.append(text);
204- }
205-
206190 startSpinner(label?: string): void {
207191 this.spinner.start(label);
208192 }
209193
210194 stopSpinner(): void {
211- this.haltSpinner();
195+ this.spinner.stop();
212196 }
213197
214198 async renderTurn(
215199 events: AsyncIterable<TurnEvent>,
216200 opts?: { showReasoning?: boolean; verboseOutput?: boolean },
217201 ): Promise<TurnResult> {
218- this.liveOutput.finish();
219202 return renderTurn(events, this.spinner, opts);
220203 }
221204
222205 renderStatusBar(data: StatusBarData): void {
223- this.liveOutput.finish();
224206 renderStatusBar(data);
225207 }
226208
src/cli/stream-render.test.ts+0−1
@@ -295,7 +295,6 @@ describe("renderTurn", () => {
295295 exitCode: 0,
296296 success: true,
297297 timedOut: false,
298- streamedOutput: false,
299298 },
300299 },
301300 { type: "reasoning-delta", delta: "done" },
src/cli/tool-render.test.ts+3−29
@@ -54,7 +54,7 @@ describe("buildToolCallLine", () => {
5454 });
5555
5656 describe("renderToolResult", () => {
57- test("does not duplicate streamed shell output previews", () => {
57+ test("shows stderr preview for failed commands", () => {
5858 captureStdout();
5959
6060 renderToolResult(
@@ -65,39 +65,16 @@ describe("renderToolResult", () => {
6565 exitCode: 1,
6666 success: false,
6767 timedOut: false,
68- streamedOutput: true,
6968 },
7069 false,
7170 );
7271
7372 const plain = stripAnsi(stdout);
7473 expect(plain).toContain("error exit 1 · stderr 1L");
75- expect(plain).not.toContain("stderr (1 lines)");
76- expect(plain).not.toContain("│ boom");
74+ expect(plain).toContain("│ boom");
7775 });
7876
79- test("does not repeat successful single-line stdout when it was streamed live", () => {
80- captureStdout();
81-
82- renderToolResult(
83- "shell",
84- {
85- stdout: "done",
86- stderr: "",
87- exitCode: 0,
88- success: true,
89- timedOut: false,
90- streamedOutput: true,
91- },
92- false,
93- );
94-
95- const plain = stripAnsi(stdout);
96- expect(plain).toContain("done exit 0");
97- expect(plain).not.toContain("out: done");
98- });
99-
100- test("shows stdout previews for non-streamed successful multi-line commands", () => {
77+ test("shows stdout previews for successful multi-line commands", () => {
10178 captureStdout();
10279
10380 renderToolResult(
@@ -108,7 +85,6 @@ describe("renderToolResult", () => {
10885 exitCode: 0,
10986 success: true,
11087 timedOut: false,
111- streamedOutput: false,
11288 },
11389 false,
11490 );
@@ -135,7 +111,6 @@ describe("renderToolResult", () => {
135111 exitCode: 0,
136112 success: true,
137113 timedOut: false,
138- streamedOutput: false,
139114 },
140115 false,
141116 );
@@ -163,7 +138,6 @@ describe("renderToolResult", () => {
163138 exitCode: 0,
164139 success: true,
165140 timedOut: false,
166- streamedOutput: false,
167141 },
168142 false,
169143 { verboseOutput: true },
src/cli/tool-result-renderers.ts+0−17
@@ -72,19 +72,9 @@ function buildShellSummaryParts(opts: {
7272 stdoutLines: number;
7373 stderrLines: number;
7474 stdoutSingleLine: string | null;
75- streamedOutput: boolean;
7675 verboseOutput: boolean;
7776 }): string[] {
7877 const parts = [`exit ${opts.exitCode}`];
79- if (opts.streamedOutput) {
80- if (opts.stdoutLines === 0 && opts.stderrLines === 0) {
81- parts.push("no output");
82- }
83- if (opts.stderrLines > 0) {
84- parts.push(`stderr ${opts.stderrLines}L`);
85- }
86- return parts;
87- }
8878
8979 if (
9080 opts.stderrLines === 0 &&
@@ -130,13 +120,11 @@ function renderShellResult(
130120 exitCode: number;
131121 success: boolean;
132122 timedOut: boolean;
133- streamedOutput?: boolean;
134123 };
135124 if (!r || typeof r.stdout !== "string" || typeof r.stderr !== "string") {
136125 return false;
137126 }
138127
139- const streamedOutput = r.streamedOutput === true;
140128 const verboseOutput = opts?.verboseOutput === true;
141129 const stdoutLines = countShellLines(r.stdout);
142130 const stderrLines = countShellLines(r.stderr);
@@ -151,16 +139,11 @@ function renderShellResult(
151139 stdoutLines,
152140 stderrLines,
153141 stdoutSingleLine,
154- streamedOutput,
155142 verboseOutput,
156143 });
157144
158145 writeln(` ${badge} ${c.dim(parts.join(" · "))}`);
159146
160- if (streamedOutput) {
161- return true;
162- }
163-
164147 writePreviewLines({
165148 label: "stderr",
166149 value: r.stderr,
src/llm-api/history/shared.ts+1−1
@@ -54,7 +54,7 @@ function hasObjectToolCallInput(
5454 );
5555 }
5656
57-const TOOL_RUNTIME_INPUT_KEYS = new Set(["cwd", "onOutput"]);
57+const TOOL_RUNTIME_INPUT_KEYS = new Set(["cwd"]);
5858
5959 export function stripToolRuntimeInputFields(
6060 messages: CoreMessage[],
src/llm-api/turn.test.ts+0−1
@@ -103,7 +103,6 @@ describe("stripToolRuntimeInputFields", () => {
103103 path: "TODO.md",
104104 line: 1,
105105 cwd: "/tmp/project",
106- onOutput: "ignore-me-too",
107106 },
108107 },
109108 ],
src/tools/shell.test.ts+7−45
@@ -1,63 +1,25 @@
1-import { describe, expect, it, mock } from "bun:test";
1+import { describe, expect, it } from "bun:test";
22 import { shellTool } from "./shell.ts";
33
4-function collectOutput(mockFn: ReturnType<typeof mock>): string {
5- return mockFn.mock.calls.map((call) => String(call[0] ?? "")).join("");
6-}
7-
8-async function expectStreamedOutput(command: string, expectedOutput: string) {
9- const onOutput = mock(() => true);
10- const result = await shellTool.execute({
11- command,
12- timeout: 30_000,
13- onOutput,
14- });
15-
16- expect(result.stdout).toBe(expectedOutput.trimEnd());
17- expect(result.streamedOutput).toBe(true);
18- expect(collectOutput(onOutput)).toBe(expectedOutput);
19-}
20-
214 describe("shellTool", () => {
22- it("appends a newline to streamed output when the command does not print one", async () => {
23- await expectStreamedOutput("printf ok", "ok\n");
24- });
25-
26- it("does not duplicate a trailing newline in streamed output", async () => {
27- await expectStreamedOutput("printf 'ok\\n'", "ok\n");
28- });
29-
30- it("injects mc-edit into shell commands", async () => {
31- const result = await shellTool.execute({
32- command: "mc-edit --help >/dev/null",
33- timeout: 30_000,
34- });
35-
36- expect(result.success).toBe(true);
37- expect(result.exitCode).toBe(0);
38- });
39-
40- it("marks output as not streamed when no onOutput handler is provided", async () => {
5+ it("captures stdout", async () => {
416 const result = await shellTool.execute({
427 command: "printf ok",
438 timeout: 30_000,
449 });
4510
4611 expect(result.stdout).toBe("ok");
47- expect(result.streamedOutput).toBe(false);
12+ expect(result.success).toBe(true);
4813 });
4914
50- it("marks output as not streamed when output handler suppresses streaming", async () => {
51- const onOutput = mock(() => false);
15+ it("injects mc-edit into shell commands", async () => {
5216 const result = await shellTool.execute({
53- command: "printf ok",
17+ command: "mc-edit --help >/dev/null",
5418 timeout: 30_000,
55- onOutput,
5619 });
5720
58- expect(result.stdout).toBe("ok");
59- expect(result.streamedOutput).toBe(false);
60- expect(collectOutput(onOutput)).toBe("ok");
21+ expect(result.success).toBe(true);
22+ expect(result.exitCode).toBe(0);
6123 });
6224 });
6325
src/tools/shell.ts+2−22
@@ -21,7 +21,6 @@ const ShellSchema = z.object({
2121
2222 type ShellInput = z.infer<typeof ShellSchema> & {
2323 cwd?: string;
24- onOutput?: (chunk: string) => boolean | undefined;
2524 };
2625
2726 export interface ShellOutput {
@@ -30,7 +29,6 @@ export interface ShellOutput {
3029 exitCode: number;
3130 success: boolean;
3231 timedOut: boolean;
33- streamedOutput: boolean;
3432 }
3533
3634 const MAX_OUTPUT_BYTES = 10_000; // 10KB per stream
@@ -79,14 +77,12 @@ export async function runShellCommand(input: ShellInput): Promise<ShellOutput> {
7977
8078 async function collectStream(
8179 stream: ReadableStream<Uint8Array>,
82- onChunk?: (text: string) => void,
8380 ): Promise<string> {
8481 const reader = stream.getReader();
8582 readers.push(reader);
8683 const chunks: Uint8Array[] = [];
8784 let totalBytes = 0;
8885 let truncated = false;
89- const decoder = new TextDecoder();
9086
9187 while (true) {
9288 try {
@@ -94,7 +90,6 @@ export async function runShellCommand(input: ShellInput): Promise<ShellOutput> {
9490 if (done) break;
9591 if (!value) continue;
9692
97- onChunk?.(decoder.decode(value, { stream: true }));
9893 if (totalBytes + value.length > MAX_OUTPUT_BYTES) {
9994 chunks.push(value.slice(0, MAX_OUTPUT_BYTES - totalBytes));
10095 truncated = true;
@@ -116,26 +111,12 @@ export async function runShellCommand(input: ShellInput): Promise<ShellOutput> {
116111 let stdout = "";
117112 let stderr = "";
118113 let exitCode = 1;
119- const onOutput = input.onOutput;
120- const hasOutputHandler = typeof onOutput === "function";
121- let streamedAnyOutput = false;
122- let streamedEndsWithNewline = true;
123- const emitOutput = (chunk: string): void => {
124- if (!chunk || !hasOutputHandler) return;
125- const handled = onOutput(chunk);
126- if (handled === false) return;
127- streamedAnyOutput = true;
128- streamedEndsWithNewline = /[\r\n]$/.test(chunk);
129- };
130114
131115 try {
132116 [stdout, stderr] = await Promise.all([
133- collectStream(proc.stdout, hasOutputHandler ? emitOutput : undefined),
134- collectStream(proc.stderr, hasOutputHandler ? emitOutput : undefined),
117+ collectStream(proc.stdout),
118+ collectStream(proc.stderr),
135119 ]);
136- if (streamedAnyOutput && !streamedEndsWithNewline) {
137- emitOutput("\n");
138- }
139120 exitCode = await proc.exited;
140121 } finally {
141122 clearTimeout(timer);
@@ -155,7 +136,6 @@ export async function runShellCommand(input: ShellInput): Promise<ShellOutput> {
155136 exitCode,
156137 success: exitCode === 0,
157138 timedOut,
158- streamedOutput: streamedAnyOutput,
159139 };
160140 }