Merge pull request #11913 from Kilo-Org/understood-meerkat

fix(cli): retain shell output for fast-exiting commands
This commit is contained in:
Marius
2026-07-03 15:13:08 +02:00
committed by GitHub
4 changed files with 51 additions and 4 deletions
+8 -2
View File
@@ -1,4 +1,4 @@
import { Effect, Stream } from "effect"
import { Effect, Fiber, Stream } from "effect" // kilocode_change - Fiber
import os from "os"
import { createWriteStream } from "node:fs"
import * as Tool from "./tool"
@@ -548,7 +548,7 @@ export const ShellTool = Tool.define(
yield* Effect.addFinalizer(closeSink)
const handle = yield* spawner.spawn(cmd(input.shell, input.command, input.cwd, input.env))
yield* Effect.forkScoped(
const reader = yield* Effect.forkScoped( // kilocode_change - keep the fiber so trailing output can be drained
Stream.runForEach(Stream.decodeText(handle.all), (chunk) => {
const size = Buffer.byteLength(chunk, "utf-8")
list.push({ text: chunk, size })
@@ -621,6 +621,12 @@ export const ShellTool = Tool.define(
yield* handle.kill({ forceKillAfter: "3 seconds" }).pipe(Effect.orDie)
}
// kilocode_change start - closing the scope interrupts the reader fiber, which can drop
// buffered output that arrived just before the process exited. Wait for the stream to
// finish (it ends once stdio closes) so fast commands do not lose their final chunks.
yield* Fiber.await(reader).pipe(Effect.timeout("3 seconds"), Effect.ignore)
// kilocode_change end
return exit.kind === "exit" ? exit.code : null
}),
).pipe(Effect.orDie)