@sema-agent/core
Version:
Stateless, task-oriented AI agent core
49 lines (48 loc) • 3.7 kB
TypeScript
import { type ProjectionLedgerRow } from "./layout.js";
import type { MemoryEntry, MemoryEntryHeader } from "./types.js";
/** What one mount did with the recorded seats of the scopes it mounted. */
export interface ProjectionRetirement {
/** Rows this mount is done with: each leaves the ledger by its identity. */
readonly judged: ProjectionLedgerRow[];
/** Files left as found because their content changed after the engine placed it, the entry's id still on them (a change the store has not taken). */
readonly changed: ProjectionLedgerRow[];
/** Files left as found because another note now stands at the seat — one with no id or with another entry's id — and nothing of the placed copy is left in it. */
readonly replaced: ProjectionLedgerRow[];
/** Files that were to be removed and were not: their rows stay for the next mount. */
readonly failed: Array<{
readonly row: ProjectionLedgerRow;
readonly why: string;
}>;
}
/**
* Judge every row of a mounted scope whose seat this mount projects no entry onto. `homes` maps each mounted scope to its home
* directory; `entries` are the entries this mount read (the projection pass writes each one's seat but a repo-ingested one's)
* and `headers` the store's listing they were read from — a seat the listing names but the entry read did not answer (an entry
* removed between the two reads) is not retired on this mount. `beforeRemove` is the caller's store-boundary check, run before a
* seat is moved (it throws to refuse, and the refusal is the caller's). A seat is removed by moving it aside and judging the
* moved bytes again: bytes a writer put there meanwhile go back without replacing anything.
*/
export declare function retireGoneProjections(rows: readonly ProjectionLedgerRow[], mount: {
readonly homes: ReadonlyMap<string, string>;
readonly entries: readonly Pick<MemoryEntry, "id" | "scope" | "slug" | "frontmatter">[];
readonly headers: readonly Pick<MemoryEntryHeader, "id" | "scope" | "slug">[];
readonly beforeRemove: (path: string) => void;
readonly now: () => number;
}): ProjectionRetirement;
/** What a mount says about the files it left: one line per file, by scope — the seat only, never content. The announcement
* renderer keeps an item to the inline label bound (160 characters), so the quoted seat is held to its room and what a person
* acts on comes before a cause (a seat name cut past that bound would take the rest of the line with it). Three arms, each
* saying what is true of it: a copy changed here (not saved back if deleted, else delete the file), something else standing at the
* seat (nothing is asked of the person), a copy that could not be removed. */
export declare function retirementNotices(r: ProjectionRetirement): Map<string | undefined, string[]>;
/** The one wording of a ledger fault: unreadable at a mount (nothing removed — the notice is said before the record is written, so
* it claims no rebuild), replaced by a harvest (said only once a write replaced it), or not written. The cause comes last (see
* {@link retirementNotices}). */
export declare function ledgerFaultNotice(fault: "read" | "rebuilt" | "write", why?: string): string;
/** The harvest half: the rows for the candidate seats (under `scope`'s `home`) whose file now holds exactly the content the store
* took — it parses to the candidate's `id` with its `rev`. A candidate whose file reads otherwise is not recorded. */
export declare function projectionsHeldAt(candidates: Iterable<{
readonly path: string;
readonly id: string;
readonly rev: string;
}>, scope: string, home: string): ProjectionLedgerRow[];