Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions packages/opencode/src/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,25 @@ export const layer = Layer.effect(
})
const handle = yield* spawner.spawn(proc)
const collect = (stream: typeof handle.stdout) =>
Stream.runFold(
stream,
() => ({ chunks: [] as Uint8Array[], bytes: 0, truncated: false }),
(acc, chunk) => {
if (opts.maxOutputBytes === undefined) {
acc.chunks.push(chunk)
acc.bytes += chunk.length
return acc
}

const remaining = opts.maxOutputBytes - acc.bytes
if (remaining > 0) acc.chunks.push(remaining >= chunk.length ? chunk : chunk.slice(0, remaining))
acc.bytes += chunk.length
acc.truncated = acc.truncated || acc.bytes > opts.maxOutputBytes
return acc
},
).pipe(Effect.map((x) => ({ buffer: Buffer.concat(x.chunks), truncated: x.truncated })))
Effect.gen(function* () {
const chunks: Uint8Array[] = []
let bytes = 0
let truncated = false
yield* Stream.runForEach(stream, (chunk) =>
Effect.sync(() => {
if (opts.maxOutputBytes === undefined) {
chunks.push(chunk)
bytes += chunk.length
} else {
const remaining = opts.maxOutputBytes - bytes
if (remaining > 0) chunks.push(remaining >= chunk.length ? chunk : chunk.slice(0, remaining))
bytes += chunk.length
truncated = truncated || bytes > opts.maxOutputBytes
}
}),
)
return { buffer: Buffer.concat(chunks), truncated }
})
const [stdout, stderr] = yield* Effect.all([collect(handle.stdout), collect(handle.stderr)], { concurrency: 2 })
return {
exitCode: yield* handle.exitCode,
Expand Down
Loading