@sema-agent/core
Version:
Stateless, task-oriented AI agent core
98 lines (97 loc) • 6.07 kB
TypeScript
/**
* The `form` of a `corrupt_session` — which way a stored session log is damaged, as a closed word, with the one sentence that says what a
* person can do about each. `SessionError("corrupt_session")` carries it (`SessionError.detail.form`); a failed terminal states it as
* `terminal.detail.detail.form`. A consumer branches on the word and shows {@link corruptSessionWayOutSentence} for it over the store the
* session is in, never parses the error's own sentence.
*
* Every `corrupt_session` this package mints names one of these. Absence reads as "not stated": a record an older worker wrote, or a store
* outside this package that mints the code without a form — never a form inferred from the sentence.
*
* · `no_header` — the log has no header its store wrote (no first meta record), so nothing in it reads as a session;
* · `bad_cell` — a cell of the header this build cannot read (the owner, the occupant token, the placement) holds a value that is not a
* legal one (this package mints it for the owner and placement cells; a store outside it states it for any header cell);
* · `bad_entry` — an entry of the log cannot be read as an entry (the file store skips such a line and counts it, so a store that refuses a log
* over an unreadable entry is its mint; the head reads, the open is refused);
* · `leaf_missing` — the log's leaf names an entry the log does not hold;
* · `floor_missing` — a bounded window names a floor entry the loaded part of the log does not hold;
* · `parent_missing` — an entry names a parent the log does not hold (a break in the chain);
* · `parent_loop` — the parent links loop back on themselves;
* · `kept_start_missing` — a compaction names a first-kept entry that is not on its branch;
* · `cut_point_missing` — a parked checkpoint was cut at an entry the log no longer holds.
*/
import type { AssertAllKeysHandled } from "./ask-origin.js";
export declare const CORRUPT_SESSION_FORMS: readonly ["no_header", "bad_cell", "bad_entry", "leaf_missing", "floor_missing", "parent_missing", "parent_loop", "kept_start_missing", "cut_point_missing"];
export type CorruptSessionForm = (typeof CORRUPT_SESSION_FORMS)[number];
/** Membership test for {@link CorruptSessionForm}. */
export declare function isCorruptSessionForm(v: unknown): v is CorruptSessionForm;
/** The member a `corrupt_session` carries: `SessionError.detail`, the seat a failed terminal's `coded` account reads. */
export interface CorruptSessionDetail {
readonly form: CorruptSessionForm;
}
/**
* What a person can do with a damaged session short of deleting it:
* · `continue` — the session reads as it stands: a new task on it goes on from its leaf (what is damaged is a parked record, not the log);
* · `rewind` — resume at, or fork from, an entry the damage does not touch (an entry whose path to the root holds together), when there is one.
*/
export declare const CORRUPT_SESSION_WAYS: readonly ["continue", "rewind"];
export type CorruptSessionWay = (typeof CORRUPT_SESSION_WAYS)[number];
/**
* The engine's two doors that remove a session row, judged on its head and never on its log:
* · `owner` — the owner's delete (`SessionStore.delete`): a row whose head reads, guarded by its owner;
* · `operator` — the deployment operator's (`SessionStore.deleteUnreadable`): a row whose head read itself is refused.
* A store offers each or not; which it offers is read off the store (a function member, or none), never declared beside it.
*/
export declare const CORRUPT_SESSION_DELETE_DOORS: readonly ["owner", "operator"];
export type CorruptSessionDeleteDoor = (typeof CORRUPT_SESSION_DELETE_DOORS)[number];
/** One form's exit: the ways that keep the session (empty = removing the row is the only exit) and the doors that remove such a row
* (empty = removing it is not its way out). Its sentence is {@link corruptSessionWayOutSentence}'s, which reads the store's doors. */
export interface CorruptSessionWayOut {
readonly ways: readonly CorruptSessionWay[];
readonly deleteBy: readonly CorruptSessionDeleteDoor[];
}
/** The way out of each form — with {@link corruptSessionWayOutSentence} the one place it is defined; the integration guide renders both. */
export declare const CORRUPT_SESSION_WAYS_OUT: Readonly<{
no_header: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
bad_cell: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
bad_entry: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
leaf_missing: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
floor_missing: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
parent_missing: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
parent_loop: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
kept_start_missing: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
cut_point_missing: {
ways: readonly ("continue" | "rewind")[];
deleteBy: readonly ("owner" | "operator")[];
};
}>;
export type WaysOutTableCoversEveryForm = AssertAllKeysHandled<Exclude<CorruptSessionForm, keyof typeof CORRUPT_SESSION_WAYS_OUT>>;
/**
* The sentence a consumer shows for `form` over `store` (the session store the damaged row is in): the form's way out, its delete
* clause naming only a door the store offers — a door it does not offer is said as such (no door of the engine removes the row; clear
* it in the store), never offered as an exit.
*/
export declare function corruptSessionWayOutSentence(form: CorruptSessionForm, store: object): string;