chore(integration): snapshot local main worktree

This commit is contained in:
inman
2026-08-31 10:23:21 +08:00
parent 48a9189939
commit 33fb31fb28
116 changed files with 8108 additions and 3026 deletions

View File

@@ -1,6 +1,9 @@
import { PiProcessError } from './process-errors';
export const DEFAULT_MAX_PI_RPC_LINE_BYTES = 1024 * 1024;
// Pi caps each inline image at 4.5 MiB of base64, and one RPC record can contain
// multiple image results (for example an agent_end batch or get_entries response).
// Keep a finite transport bound while allowing normal parallel image inspection.
export const DEFAULT_MAX_PI_RPC_LINE_BYTES = 32 * 1024 * 1024;
type StrictLfJsonlFramerOptions = {
maxLineBytes?: number;
@@ -15,7 +18,8 @@ export class StrictLfJsonlFramer {
private readonly decoder = new TextDecoder('utf-8', { fatal: true });
private readonly maxLineBytes: number;
private readonly onRecord: (record: unknown) => void;
private buffered = Buffer.alloc(0);
private bufferedChunks: Buffer[] = [];
private bufferedBytes = 0;
private finished = false;
constructor(options: StrictLfJsonlFramerOptions) {
@@ -49,24 +53,27 @@ export class StrictLfJsonlFramer {
finish(): void {
if (this.finished) return;
this.finished = true;
if (this.buffered.length > 0) {
if (this.bufferedBytes > 0) {
throw protocolError('Pi RPC stdout ended with a partial line');
}
}
private append(segment: Uint8Array): void {
if (this.buffered.length + segment.byteLength > this.maxLineBytes) {
const nextBytes = this.bufferedBytes + segment.byteLength;
if (nextBytes > this.maxLineBytes) {
throw protocolError(`Pi RPC stdout line exceeded ${this.maxLineBytes} bytes`);
}
if (segment.byteLength === 0) return;
this.buffered = this.buffered.length === 0
? Buffer.from(segment)
: Buffer.concat([this.buffered, segment], this.buffered.length + segment.byteLength);
this.bufferedChunks.push(Buffer.from(segment));
this.bufferedBytes = nextBytes;
}
private emitLine(): void {
let line = this.buffered;
this.buffered = Buffer.alloc(0);
let line = this.bufferedChunks.length === 1
? this.bufferedChunks[0]
: Buffer.concat(this.bufferedChunks, this.bufferedBytes);
this.bufferedChunks = [];
this.bufferedBytes = 0;
if (line.at(-1) === 0x0d) line = line.subarray(0, -1);
if (line.length === 0) throw protocolError('Pi RPC stdout emitted a blank line');