@@ -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 }