@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
54 lines • 2.88 kB
TypeScript
import { EventLoopSlicer } from "./event-loop-slicer.ts";
import type { FileEntry } from "./session-manager.ts";
import { type SessionRecovery, type SessionRecoveryCause } from "./session-write-recovery.ts";
export declare const SESSION_READ_BUFFER_SIZE: number;
export declare function parseSessionEntryLine(line: string): FileEntry | null;
export declare class SessionLineSplitter {
private readonly decoder;
private pending;
push(chunk: Buffer): string[];
finish(): string;
}
/** Exported for testing */
export declare function loadEntriesFromFile(filePath: string, captureIdentity?: boolean): FileEntry[];
/** What `forkFrom` found in its source: the entries, whether the file had a header, and why it cannot be forked. */
export type ForkSource = {
readonly kind: "session";
readonly entries: FileEntry[];
} | {
readonly kind: "headerless";
readonly entries: FileEntry[];
} | {
readonly kind: "empty";
} | {
readonly kind: "not-a-session";
};
/**
* Read the source of a fork. A file whose line-1 header was lost but whose every other line is a session
* entry (`type`, `id`, `parentId`) is still a whole conversation, and a fork writes its own new header anyway,
* so it is forked rather than refused (omo#10375). Anything else that is not a headed session is reported as
* what it is: no parsable line at all is empty, parsable lines of another shape are not a session.
*/
export declare function readForkSource(filePath: string): ForkSource;
/**
* `loadEntriesFromFile` without holding the event loop: the same entries, read with
* asynchronous I/O and parsed in slices that yield once `slicer`'s budget is spent.
*/
export declare function loadEntriesFromFileAsync(filePath: string, slicer?: EventLoopSlicer, captureIdentity?: boolean): Promise<FileEntry[]>;
/** A torn final line was set aside, or could not be (the copy was refused) and must be set aside before the next append. */
export type FinalLineRepair = {
readonly kind: "set_aside";
readonly recovery: SessionRecovery;
} | {
readonly kind: "deferred";
};
/**
* Make this process's appends start on a new line. A final line with no newline is either a whole entry written
* without one (it parses: it is terminated and kept) or a line a crash tore part-way (it does not parse: it was
* never committed, so it is copied to `<file>.torn-<time>` and the file is cut back to its last complete line,
* senpi#3549, senpi#4295). Terminating a torn line instead would turn it into a complete, corrupt line that no reader
* can tell from real corruption. Only the final segment is read, never the whole transcript; anything but a regular
* file is left to the loader, as before.
*/
export declare function terminateFinalSessionLine(filePath: string, cause?: SessionRecoveryCause): FinalLineRepair | undefined;
//# sourceMappingURL=session-entry-file.d.ts.map