UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

82 lines (81 loc) • 5.34 kB
import type { ExecutionEnv, SessionTreeEntry } from "../../internal/harness-types.js"; import { type FileHistoryRestorePlan, type FileHistoryStore } from "../file-history-store.js"; import { type ChangeRow, type ChangesItem, type ChangesStoreFault } from "../session-changes.js"; /** The most ids one call of the read seat is asked: a full page's checkpoints, one more to tell whether older ones remain, and on a * later page the item its `before` names. */ export declare const CHECKPOINT_ROUND_IDS = 102; /** What the history read needs of the verb: the store, the session's history scope, its current branch's path (from its latest * compaction), the names whose texts are asked, and the reader of the newest item (the working tree's side). */ export interface HistoryReadInput { readonly store: FileHistoryStore; readonly scope: string; readonly path: readonly SessionTreeEntry[]; readonly contentOf: ReadonlySet<string>; /** The newest checkpoint against the working tree, with the `skipped` its interval counts (undefined = not known). */ readonly newest: (entryId: string, skipped: number | undefined) => Promise<ChangesItem>; } /** A history read's whole-call answer when it reads nothing. */ export type HistoryUnavailable = { readonly kind: "unavailable"; readonly reason: "no_checkpoint" | "history_unreadable" | "store_cannot_read"; readonly fault?: ChangesStoreFault; }; /** * The checkpoint list's page: the checkpoints older than `before` (all of them on the first page), newest first, at most `limit`, each * paired with the next checkpoint after it on the path — the newest with the working tree (`newest`) — and `nextBefore` when older * ones remain. A damaged checkpoint is its own item, and so is the one paired with it (`history_unreadable`); a pair with no read seat * or no exchange to read it is `store_cannot_read`. A `before` that is not a checkpoint on the path is the whole read's * `no_checkpoint`; a read seat that cannot answer at all is its `history_unreadable`. */ export declare function readCheckpointList(input: HistoryReadInput & { readonly limit: number; readonly before: string | undefined; }): Promise<{ readonly kind: "page"; readonly items: ChangesItem[]; readonly nextBefore?: string; } | HistoryUnavailable>; /** * One item of the list, by its checkpoint (`checkpoint`): the checkpoint of `entryId` on the path, paired as the list pairs it. An * entry that is not a checkpoint on the path is `no_checkpoint`. */ export declare function readCheckpointItem(input: HistoryReadInput & { readonly entryId: string; }): Promise<ChangesItem | HistoryUnavailable>; /** A row's texts, as the verb hands them. */ type RowTexts = NonNullable<ChangeRow["content"]>; /** What `since` hands of the files `contentOf` names: each one's texts decided once, while its plan holds the file's bytes * (`readCurrent`) — the bytes a rewind would leave there (the checkpoint's side) against the current ones, by the verb's one reading of * a row's texts ({@link changesContentOf}: the call's one budget, spent in the order the restore asked) — at the path a rewind at * `root` addresses each (`rewindTargetOf`, the rewind's own). The plan keeps no bytes. `undefined` when nothing is named. */ export declare function sinceTextsOf(contentOf: ReadonlySet<string>, root: string): { readonly readCurrent: (at: string, current: Uint8Array | null, target: Uint8Array | null) => void; readonly at: ReadonlyMap<string, RowTexts>; } | undefined; /** `since`: the rewind preview's plan of `entryId` at `root` (its texts decided by {@link sinceTextsOf}), read as rows; a store whose * `restore` throws is the read's `history_unreadable`, with what it threw as the fault. */ export declare function readSince(store: Pick<FileHistoryStore, "restore">, input: { readonly scope: string; readonly entryId: string; readonly env: ExecutionEnv; readonly root: string; readonly signal: AbortSignal | undefined; readonly forkedSession?: boolean; }, contentOf: ReadonlySet<string>): Promise<{ readonly kind: "rows"; readonly rows: ChangeRow[]; } | HistoryUnavailable>; /** * A checkpoint against the working tree, from the rewind preview's plan ({@link FileHistoryRestorePlan}), row by row: a file the * rewind would write is `modified` (the working tree has it) or `deleted` (it does not); one it would delete is `added`; one whose mode * alone it would change is `modified` + `modeOnly`; a file it would refuse is `uncompared` — `base_unavailable` by that class, else * `rewind_refused` with the refusal; one it would leave as it is is `uncompared` with that class; one it could not judge (`failed`), or * whose current bytes the plan could not read, is `uncompared` `unreadable`; one already as recorded is no row. A plan that found no * checkpoint is `no_checkpoint`; one that failed (or a partial one that carries an error), or that the preview refuses (a write it * cannot place beside a frozen file), is `history_unreadable` — half a plan is not an answer. */ export declare function sinceRowsOf(plan: FileHistoryRestorePlan, contentOf: ReadonlySet<string>, texts: ReadonlyMap<string, RowTexts>): { readonly kind: "rows"; readonly rows: ChangeRow[]; } | HistoryUnavailable; export {};