@sema-agent/core
Version:
Stateless, task-oriented AI agent core
104 lines (103 loc) • 8.39 kB
TypeScript
/**
* The person-facing half of a memory mount that failed open (`memory.mount_failed`, audience `user`). The memory phase's
* fail-open arm runs the task without its memory when the mount does not complete; the operator hears it on `onError` and the
* result's `effectiveMemoryScopes` reads `memoryless` / `mount-failed`, and this notice is what the session's user hears.
*
* Minted by the memory phase under the guard that mints that observation — so the notice and the observation are one fact, and
* a throw after the session assembled (the run then proceeds WITH its memory) says nothing. Dedup unit: the consumer's key
* `(code, detail.sessionId)`, once per session; the phase mints once per prepared leg whose mount failed.
*
* `scopes` is what the task asked to mount — every read scope and the write scope when it is a further one (the whole span failed, not
* one scope's mount), `cause` the closed set below, and `outsideReason` exactly when `cause` is `memory.target_outside_store` (which case
* of it the refusal named) — never the thrown text and never a path (a store-form refusal's `detail.path` stays on the operator's lane).
*
* The same causes, and the same words, say why a capture opt-out could not be recorded (`memory.capture_optout_unpersisted`): its cause
* set is this one plus the record store's own failure, and the retry word each cause carries is derived here, once.
*/
import type { EngineNotice } from "../types.js";
import { type StoreFormRefusalCode, type StoreFormRefusalReading, type TargetOutsideStoreReason } from "./layout.js";
/** Why the store did not mount: the store-form refusal's own code when the mount was refused for the store's physical form,
* {@link ROOT_ANCHOR_DAMAGED} when it was refused because its root anchor cannot be trusted (one re-anchor restores it), else
* `"unclassified"`. */
export type MemoryMountFailedCause = StoreFormRefusalCode | "memory.root_anchor_damaged" | "unclassified";
/** The code whose cases the person hears apart — the one reading of the family that carries a case word. */
type OutsideCode = Extract<StoreFormRefusalReading, {
readonly outsideReason: TargetOutsideStoreReason;
}>["code"];
/** What a mount failure reports: its cause, and — exactly when the cause is the code with cases — which case the refusal named. */
export type MemoryMountFailedReading = {
readonly cause: Exclude<MemoryMountFailedCause, OutsideCode>;
} | {
readonly cause: OutsideCode;
readonly outsideReason: TargetOutsideStoreReason;
};
/** What a mount failure reports, read once from the thrown value through the family's one reader ({@link storeFormRefusalReadingOf})
* and the root anchor's ({@link isRootAnchorRefusal}); anything neither names is `"unclassified"`. */
export declare function memoryMountFailedReadingOf(thrown: unknown): MemoryMountFailedReading;
export declare function memoryMountFailedNotice(input: {
sessionId: string;
scopes: readonly string[];
} & MemoryMountFailedReading): EngineNotice;
/** What a retry of the refused request can expect. `until_fixed`: until someone changes something, the same request fails the same way —
* said only when the engine can tell. `transient`: the same request may succeed — said whenever the engine cannot tell it will fail
* ("may", not "will"). */
export type CaptureOptOutUnpersistedRetry = "transient" | "until_fixed";
/** Why a capture opt-out could not be recorded (`memory.capture_optout_unpersisted`'s `detail.cause` — this table's keys), and the retry word
* each cause carries, derived here and nowhere else (a consumer that only asks "retry or not" reads `detail.retry` and keeps no table).
* `record_unpersisted`: the record store did not durably land the record (or the in-flight guard before it failed); every other cause is
* why the memory phase failed before the record was made — a mount failure's cause ({@link MemoryMountFailedCause}), read by its one
* reader. The store-form family is `until_fixed` — the layout the engine was handed is not the one it needs, and the same request is
* refused until it is — and so is `memory.root_anchor_damaged` (refused at every open until the store is re-anchored); `record_unpersisted` and `unclassified` are `transient` — a record store briefly unavailable heals, a read-only
* volume does not, and the engine cannot tell which. `satisfies` over the mount causes and the record's own: a cause added to the mount
* failures without its word here is a tsc error. */
export declare const CAPTURE_OPTOUT_UNPERSISTED_RETRY: Readonly<{
readonly record_unpersisted: "transient";
readonly "memory.target_outside_store": "until_fixed";
readonly "memory.scope_home_not_directory": "until_fixed";
readonly "memory.control_plane_links_unsupported": "until_fixed";
readonly "memory.control_plane_strays": "until_fixed";
readonly "memory.store_root_sensitive": "until_fixed";
readonly "memory.control_plane_split": "until_fixed";
readonly "memory.store_absent": "until_fixed";
readonly "memory.root_anchor_damaged": "until_fixed";
readonly unclassified: "transient";
}>;
export type CaptureOptOutUnpersistedCause = keyof typeof CAPTURE_OPTOUT_UNPERSISTED_RETRY;
/** Why one opt-out could not be recorded: the record store's own failure, or a mount failure's reading (its case too, for the code with cases). */
export type CaptureOptOutUnpersistedReading = {
readonly cause: "record_unpersisted";
} | MemoryMountFailedReading;
/** Why a mark answered `"unpersisted"`, read off the store it was made in: that store expected at `controlDir` and absent
* ({@link storeAbsence}) ⇒ {@link STORE_ABSENT}; else the record store did not land the record. Both ingresses' marks read it. */
export declare function captureMarkUnpersistedReadingOf(controlDir: string): CaptureOptOutUnpersistedReading;
/** The two clauses every receipt of a refused opt-out says — why the record did not land, and what a retry can expect (the cause's
* retry word, then how it is restored) — written once for the notice and for the error the run or the verb is refused with. A reading
* whose cause is not one of {@link CAPTURE_OPTOUT_UNPERSISTED_RETRY}'s keys (an untyped caller's `{ sessionId, ingress }` without one),
* or that names the code with cases without one of its cases, is a `TypeError`: why the opt-out was not recorded is never said as
* `undefined`, nor its retry word guessed. */
export declare function captureOptOutUnpersistedWords(reading: CaptureOptOutUnpersistedReading): {
readonly why: string;
readonly retry: string;
};
/** The `detail` members a refused opt-out carries beside its session — the notice's and the error's alike: the cause, the retry word derived
* from it, and exactly for `memory.target_outside_store` which case. */
export declare function captureOptOutUnpersistedDetail(reading: CaptureOptOutUnpersistedReading): {
cause: CaptureOptOutUnpersistedCause;
retry: CaptureOptOutUnpersistedRetry;
outsideReason?: TargetOutsideStoreReason;
};
/**
* design/383 §2.8 — the opt-out that could NOT be honored (`memory.capture_optout_unpersisted`, audience `user`; dedup unit: once per
* ATTEMPT — nothing latches between attempts: `deliverEngineNotice` does not dedup and a mark answering `"unpersisted"` is not recorded
* in-process). Minted ONLY beside the typed throw carrying the same code, never beside a success. The declaration ingress refuses the
* RUN — a declared opt-out, or a spawning session's floor, whose record was not made: its mark answered `"unpersisted"`, or the memory
* phase failed before the mark; the host FLIP VERB's throw rejects only the verb promise, so the run continues with capture still ON.
* The message is written per ingress for that reason ("nothing was captured" is false on the flip arm, where the run goes on capturing),
* and `ingress` rides `detail` so a consumer branches without parsing prose; without it the text says only what is true on both faces.
* Why it was not recorded and what a retry can expect ride `detail` too ({@link captureOptOutUnpersistedDetail}) and are said in words.
*/
export declare function memoryCaptureOptOutUnpersistedNotice(input: {
sessionId: string;
ingress?: "declaration" | "flip-verb";
} & CaptureOptOutUnpersistedReading): EngineNotice;
export {};