xonecas.io
64875
Mc

mini-coder / commit a8080b6

feat: stream shell output during execution

xonecas2026-03-15 a8080b6225db77c5c04f27f576f6534b8a30f83b parent bcee265

6 files changed

TODO.md+0−1
@@ -1,6 +1,5 @@
11 # TODO
22
3-- Verbose user choice is not persisting accross sessions. Verbose mode should default to off.
43 - Gpt 5.4 shows reasoning correctly, but Gpt 5.3 codex does not. Is this a mini-coder issue?
54
65 ---
src/agent/agent.ts+7−1
@@ -63,11 +63,16 @@ export async function initAgent(opts: AgentOptions): Promise<{
6363 cwd,
6464 () => currentModel,
6565 );
66+ let verboseOutputEnabled = opts.initialVerboseOutput;
6667 const agents = loadAgents(cwd);
6768 const tools: ToolDef[] = buildToolSet({
6869 cwd,
6970 runSubagent,
70- onShellOutput: (chunk) => opts.reporter.streamChunk(chunk),
71+ onShellOutput: (chunk) => {
72+ if (!verboseOutputEnabled) return false;
73+ opts.reporter.streamChunk(chunk);
74+ return true;
75+ },
7176 availableAgents: subagentAgents(agents),
7277 });
7378
@@ -162,6 +167,7 @@ export async function initAgent(opts: AgentOptions): Promise<{
162167 },
163168 setVerboseOutput: (verbose) => {
164169 runner.verboseOutput = verbose;
170+ verboseOutputEnabled = verbose;
165171 setPreferredVerboseOutput(verbose);
166172 },
167173 get pruningMode() {
src/agent/tools.ts+2−2
@@ -27,7 +27,7 @@ function withCwdDefault(tool: ToolDef, cwd: string): ToolDef {
2727 */
2828 function withShellOutput(
2929 tool: ToolDef,
30- onOutput: (chunk: string) => void,
30+ onOutput: (chunk: string) => boolean | void,
3131 ): ToolDef {
3232 const originalExecute = tool.execute;
3333 return {
@@ -49,7 +49,7 @@ export function buildToolSet(opts: {
4949 agentName?: string,
5050 modelOverride?: string,
5151 ) => Promise<SubagentOutput>;
52- onShellOutput?: (chunk: string) => void;
52+ onShellOutput?: (chunk: string) => boolean | void;
5353 availableAgents: ReadonlyMap<string, { description: string }>;
5454 }): ToolDef[] {
5555 const { cwd, onShellOutput } = opts;
src/cli/input-loop.ts+8−1
@@ -112,7 +112,14 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
112112 command: input.command,
113113 timeout: 30_000,
114114 cwd,
115- onOutput: (chunk) => reporter.streamChunk(chunk),
115+ ...(cmdCtx.verboseOutput
116+ ? {
117+ onOutput: (chunk) => {
118+ reporter.streamChunk(chunk);
119+ return true;
120+ },
121+ }
122+ : {}),
116123 });
117124 renderToolResult("shell", result, false, {
118125 verboseOutput: cmdCtx.verboseOutput,
src/tools/shell.test.ts+13−0
@@ -46,6 +46,19 @@ describe("shellTool", () => {
4646 expect(result.stdout).toBe("ok");
4747 expect(result.streamedOutput).toBe(false);
4848 });
49+
50+ it("marks output as not streamed when output handler suppresses streaming", async () => {
51+ const onOutput = mock(() => false);
52+ const result = await shellTool.execute({
53+ command: "printf ok",
54+ timeout: 30_000,
55+ onOutput,
56+ });
57+
58+ expect(result.stdout).toBe("ok");
59+ expect(result.streamedOutput).toBe(false);
60+ expect(collectOutput(onOutput)).toBe("ok");
61+ });
4962 });
5063
5164 describe.skipIf(!process.stdin.isTTY)("shellTool raw mode", () => {
src/tools/shell.ts+3−2
@@ -21,7 +21,7 @@ const ShellSchema = z.object({
2121
2222 type ShellInput = z.infer<typeof ShellSchema> & {
2323 cwd?: string;
24- onOutput?: (chunk: string) => void;
24+ onOutput?: (chunk: string) => boolean | void;
2525 };
2626
2727 export interface ShellOutput {
@@ -122,9 +122,10 @@ export async function runShellCommand(input: ShellInput): Promise<ShellOutput> {
122122 let streamedEndsWithNewline = true;
123123 const emitOutput = (chunk: string): void => {
124124 if (!chunk || !hasOutputHandler) return;
125+ const handled = onOutput(chunk);
126+ if (handled === false) return;
125127 streamedAnyOutput = true;
126128 streamedEndsWithNewline = /[\r\n]$/.test(chunk);
127- onOutput(chunk);
128129 };
129130
130131 try {