@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
84 lines • 3.26 kB
TypeScript
import { type TruncationResult } from "./truncate.ts";
export interface OutputSnapshot {
content: string;
truncation: TruncationResult;
fullOutputPath?: string;
}
export interface FullOutput {
content: string;
/** Whether `content` omits part of the output. */
truncated: boolean;
}
/** Where an accumulator keeps the full output once it outgrows the display limits. */
export interface OutputSpill {
/** The path truncation notices show the model. */
readonly path: string;
/** Appends a chunk; a failure is latched and reported by `close`. */
write(chunk: Uint8Array | string): void;
/** Settles every write; rejects with the first write or close failure. */
close(): Promise<void>;
/** Discards the spill; a rejection leaves it in place for a retry. */
remove(): Promise<void>;
/** The whole output after `close`, cut by {@link joinHeadAndTail} past `maxBytes`. */
readFull(maxBytes: number): Promise<FullOutput>;
}
export type OutputSpillFactory = (prefix: string) => OutputSpill;
export interface OutputAccumulatorOptions {
maxLines?: number;
maxBytes?: number;
tempFilePrefix?: string;
}
/**
* The first and last bytes of an output too long to return whole, around an omission marker. Cuts at character
* boundaries: streaming decode holds back an incomplete trailing sequence, and the tail skips continuation bytes.
*/
export declare function joinHeadAndTail(head: Uint8Array, tail: Uint8Array, omittedBytes: number): string;
/**
* Incrementally tracks streaming output with bounded memory.
*
* Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded tail for display snapshots, and opens a
* spill when the full output needs to be preserved.
*/
export declare class OutputAccumulator {
private readonly maxLines;
private readonly maxBytes;
private readonly tempFilePrefix;
private readonly createSpill;
private readonly decoder;
private readonly tail;
private rawChunks;
private totalRawBytes;
private totalDecodedBytes;
private completedLines;
private totalLines;
private currentLineBytes;
private hasOpenLine;
private finished;
/** The spill that owns `fullOutputPath`, until removed. */
private spill;
/** The same spill while it still takes writes, until closed. */
private openSpill;
constructor(options: OutputAccumulatorOptions & {
spill: OutputSpillFactory;
});
append(data: Uint8Array): void;
appendText(text: string): void;
finish(): void;
snapshot(options?: {
persistIfTruncated?: boolean;
}): OutputSnapshot;
closeTempFile(): Promise<void>;
/**
* The complete output, for callers that can take more than the display snapshot. Call after
* `finish()` and `closeTempFile()`. Output longer than `maxBytes` raw bytes keeps its first and
* last `maxBytes / 2` bytes around an omission marker.
*/
readFullOutput(maxBytes: number): Promise<FullOutput>;
getLastLineBytes(): number;
removeTempFile(): Promise<void>;
private appendDecodedText;
private getSnapshotText;
private shouldUseTempFile;
private ensureTempFile;
}
//# sourceMappingURL=output-accumulator-core.d.ts.map