Multi-agent audit + aggressive cleanup across server/web/coder/booterm, delivered behind a DEFER discipline so none of the in-flight files were touched. Removes dead code/deps/columns, dedups server + coder helpers, and splits the oversized modules (tools.ts, opencode-server.ts, sentinel-summaries, turn.ts, TerminalPane.tsx) behind stable contracts. Adds 78 parity/unit tests (server 587, coder 323); fixes two latent bugs (ChatPane queue keys, FileViewerOverlay blank-line parity). Intended tag: v2.7.12-audit-cleanup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { Readable, Writable } from 'node:stream';
|
|
import type { ChildProcess } from 'node:child_process';
|
|
import { ndJsonStream } from '@agentclientprotocol/sdk';
|
|
|
|
function nodeReadableToWeb(nodeStream: NodeJS.ReadableStream): ReadableStream<Uint8Array> {
|
|
return new ReadableStream<Uint8Array>({
|
|
start(controller) {
|
|
nodeStream.on('data', (chunk: Buffer) => controller.enqueue(new Uint8Array(chunk)));
|
|
nodeStream.on('end', () => controller.close());
|
|
nodeStream.on('error', (err) => controller.error(err));
|
|
},
|
|
cancel() {
|
|
if ('destroy' in nodeStream && typeof (nodeStream as Readable).destroy === 'function') {
|
|
(nodeStream as Readable).destroy();
|
|
}
|
|
},
|
|
});
|
|
}
|
|
|
|
function nodeWritableToWeb(nodeStream: NodeJS.WritableStream): WritableStream<Uint8Array> {
|
|
return new WritableStream<Uint8Array>({
|
|
write(chunk) {
|
|
return new Promise<void>((resolve, reject) => {
|
|
const ok = (nodeStream as Writable).write(chunk, (err) => {
|
|
if (err) reject(err);
|
|
});
|
|
if (ok) resolve();
|
|
else (nodeStream as Writable).once('drain', resolve);
|
|
});
|
|
},
|
|
close() {
|
|
return new Promise<void>((resolve) => {
|
|
(nodeStream as Writable).end(resolve);
|
|
});
|
|
},
|
|
abort() {
|
|
(nodeStream as Writable).destroy();
|
|
},
|
|
});
|
|
}
|
|
|
|
export function createAcpNdJsonStream(child: ChildProcess) {
|
|
return ndJsonStream(nodeWritableToWeb(child.stdin!), nodeReadableToWeb(child.stdout!));
|
|
}
|