UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

66 lines (65 loc) • 4.55 kB
/** * A session's write home, as {@link import("./engine.js").MemoryEngine.sessionMemoryStatus} reports it * (`SessionMemoryStatus.writeHome`): the canonical absolute directory of the write scope the session wrote under MOST * RECENTLY — `canonicalize(scopeDirFor(write scope))`, the derivation behind a leg's handle's `writableRoot`. Two sources * name a scope, each dated, and the NEWER one wins: * 1. the session's account row: every account-opening mount (a sessioned, unrestricted mount with a write face) records * its write scope there, dated by the account's (re-)open time — readable from any engine on the control plane; * 2. the entry carrying the session's newest committed lineage contribution, dated by that contribution — a session that * wrote without opening an account (provenance "off", a row written before the field) names its home this way, and so * does a leg that wrote AFTER an older account leg (an off-mode commit under another scope after a carry leg ended: * the older row must not hide the newer home). * 3. neither — ABSENT: a session that never opened an account and never committed. * A FAULTED source (a read that throws: an unreadable account ledger or lineage) answers absent and never falls through — * it may hide the newer scope, so the other source's word would be a stand-in. A SILENT source (the newest contribution's * entry is gone — deleted or a tombstone — or there is no account row) yields to the other source: a deleted note is an * ordinary state, not a fault, and the account row is the durable record of where the session writes. Older contributions * are never consulted. A registry that cannot derive a home (v1, an unfinished layout move) * answers absent before either source is read, so no read here goes through a face whose layout seat would finish the move * first and then name a post-move home. * * The reading keeps the absences apart ({@link SessionWriteHomeReading}) and the instant of the source that won, which is what * {@link chooseSessionWriteHome} needs to choose among a deployment's stores. */ import type { MemoryEntry, MemoryGovernanceDocs } from "./types.js"; /** * What one store's control plane says of a session's write home: * - `named` — the home, and `at`, the instant (ms epoch) of the source that named it (the account's (re-)open, or the * newest contribution's commit); * - `none` — neither source names a scope: a session that never opened an account here and never committed here (a * readable absence — the store holds nothing of the session's writes); * - `unreadable` — a source faulted, or the registry cannot derive a home: a newer write may be hidden, so the store * answers no home and no stand-in. */ export type SessionWriteHomeReading = { readonly state: "named"; readonly home: string; readonly at: number; } | { readonly state: "none"; } | { readonly state: "unreadable"; }; export declare function sessionWriteHomeOf(input: { memoryDir: string; controlDir: string; /** Where the session-account ledger is kept (the engine's governance store). */ docs: MemoryGovernanceDocs; sessionId: string; /** The caller's lineage read: entry id → this session's `lastAt` on it (undefined ⇔ that read faulted). */ contributions: ReadonlyMap<string, number> | undefined; /** A committed, side-effect-free entry read (the engine's audit face). */ readEntries: (ids: readonly string[]) => Promise<MemoryEntry[]>; }): Promise<SessionWriteHomeReading>; /** * The write home a session's status answers across a deployment's stores, from each store's reading * ({@link SessionWriteHomeReading}). * * @contract memory.deployment_status.write_home — a session's write home across a deployment's stores is one store's own * `writeHome`, chosen and never merged: the store whose reading names the newest home, ranked by the one law a store ranks * its own two sources by (the newer wins); absent when no store names one, absent while any store's reading is unreadable * (that store may hold the newer write, and another store's word would be a stand-in), and absent when two stores name theirs * at the same instant (there is no newer one; a store's own tie has a writer, the account); a deployment of one store * answers that store's own; a host projects the key and chooses no store itself */ export declare function chooseSessionWriteHome(readings: readonly SessionWriteHomeReading[]): string | undefined;