@sema-agent/core
Version:
Stateless, task-oriented AI agent core
47 lines (46 loc) • 3.62 kB
TypeScript
/**
* The write gate, asked at the apply for every entry file a plan writes or removes: the backend's FINAL spelling of each (as its
* `admit`), or the one the apply knows for a backend that cannot admit. Kept beside the engine rather than in it; everything about
* how a refusal is shaped lives here — including what it says was written, which only the apply knows ({@link refusalNamingWritten}).
*/
import { ConsolidationRefusedError, type ConsolidationDirectedPatch, type ConsolidationWriteGate } from "./consolidation.js";
import type { AdmitLandings, PatchLanding } from "./landing-admission.js";
import type { MemoryBackend, MemoryEntry } from "./types.js";
/** The refusal of a verb that may apply a plan and was handed no write gate — thrown before the verb claims or changes anything. */
export declare const CONSOLIDATION_WRITE_GATE_REQUIRED_CODE = "config.memory_consolidation_write_gate";
/** A verb that may apply a plan carries the write gate; absent, it refuses before it claims or changes anything (a host that holds
* no rules passes a gate that resolves, and so says it). */
export declare function requireWriteGate(gate: unknown, verb: string): asserts gate is ConsolidationWriteGate;
/**
* Where a plan's pending directed patches write or remove files, as the store holds the entries now: an update's target and, when
* it moves the entry, the file it leaves; the file a delete removes. An id the store no longer holds is no write of a delete.
*/
export declare function directedLandings(directed: readonly ConsolidationDirectedPatch[], getByIds: (ids: readonly string[]) => Promise<MemoryEntry[]>): Promise<PatchLanding[]>;
/** What of a plan the store already holds: products it carries (the ids are the plan's own, minted at the freeze, so the store
* holding one means the plan wrote it) and directed patches whose planned state stands. */
export interface PlanWritten {
readonly products: readonly PatchLanding[];
readonly directed: readonly string[];
}
/**
* {@link PlanWritten} for `plan`, read through `committed` once `backend` has replayed every commit it holds (a locked entry that
* writes nothing runs its recovery first) — what an earlier pass, which a crash or a failure cut short before its book was written,
* or this pass before a refusal, put in the store. Undefined when the store could not be read (a refusal then says so).
*/
export declare function planWritten(plan: {
readonly products: readonly {
readonly id: string;
}[];
readonly directed: readonly ConsolidationDirectedPatch[];
}, backend: Pick<MemoryBackend, "applyPatches">, committed: Pick<MemoryBackend, "getByIds">): Promise<PlanWritten | undefined>;
/**
* The write gate's refusal at the apply, completed with what the plan has written: the gate knows why it refused; the apply knows
* that nothing further is written and what the store already holds of the plan (`written`; undefined = could not be read).
*/
export declare function refusalNamingWritten(err: ConsolidationRefusedError, written: PlanWritten | undefined): ConsolidationRefusedError;
/**
* The write gate as one apply's `admit`: every landing (`<slug>.md` in its scope's library directory) is put to the gate, all of
* them before any is written; the first refusal rejects with the gate's own error. A landing admitted once in the apply is not
* asked again (the apply asks its directed targets up front, and the backend names them again when it plans their batch).
*/
export declare function admitLandingsThrough(gate: ConsolidationWriteGate, homeOf: (scope: string) => string): AdmitLandings;