@sema-agent/core
Version:
Stateless, task-oriented AI agent core
164 lines (163 loc) • 18.2 kB
TypeScript
/**
* The checkpoint row's own answer to "does anything IN THIS ROW keep this engine from resuming it": every refusal of the
* resume ladder that the row and this engine decide alone — no deployment fact, no resume input, no decision — judged by
* one pure, total function ({@link judgeCheckpointRow}). Two readers ask it and no other site decides those refusals:
* - the resume ladder, at its first statement after the row is read `pending` (resume-admission): a non-`ok` verdict is
* thrown there, before the claim (the row stays `pending` and byte-identical);
* - the listing projection (`summarizeCheckpoint`, checkpoint-store.ts), which carries it as `CheckpointSummary.rowVerdict`,
* so a row this engine will refuse is listed as such instead of as an approvable card.
*
* ONE ANSWER, TWO FACES: the verdict's `sentence` is a fixed engine sentence chosen by the refusal's code and arm
* ({@link ROW_REFUSAL_SENTENCES}), never built from the row; the resume error's `message` is that sentence followed by the
* row's own diagnostic (member paths, a refused value), and its `detail` is the refusal's. So a listing carries no row
* content and the refusal a person gets on approving starts with the very sentence the listing showed.
*
* WHAT `ok` SAYS: nothing in the row keeps this engine from resuming it — not that the resume will run. The refusals a
* deployment fact, a resume input or the decision itself decides (no env factory for a remote workspace, organization
* governance unwired, an aborted signal, the re-supplied parent constraints, a decision that does not bind the parked call)
* are still told at the resume.
*
* ORDER (one law: the specific before the general): a newer row is refused as newer before any segment of it is read (the
* version ceiling, then a reader word this worker lacks); then a pending row that records its action's outcome; then a row below
* the format, as a retired seat (the floor: no arm reads such a row); then a row whose members do not read as every reader reads them — its
* pause, its state, its stamps (a row with no segment for the arms below to read is damaged, whatever its version; the one table
* of those shapes is the listing faces' too); then the seats and the axis a release retired (each names what
* to do about it); then the reader-requirement list and the row digest — a row changed in storage (`requirements_damaged`), else an
* earlier release's intact row (`reading_changed`), told
* only when nothing more specific is; then the recorded mode words, the sections by their shapes, the
* frozen chain's tool names, the recorded run origin, and the parent-constraint record's own integrity. The first refusal
* is the verdict.
*
* TOTAL: a row the judge cannot read (a member that throws when read) is `damaged` (`requirements_damaged`); the resume
* error's `detail.thrownName` names what was thrown, so an engine defect and a damaged row are told apart. A row whose member does
* not read as the member-shape table says (`rowMemberProblem`, checkpoint-queries.ts: the gate, the pending action, the state,
* `createdAt`, `deadline`) is the same word with nothing thrown: its refusal names the member in the table's words.
*
* The row-seat readers the judge asks and other readers share live here too — the retired seats' refusals and the recorded
* mode seed (prepare reads the seed; the parked-steer queue's read asks the retired steer seat's refusal).
*/
import { CheckpointError } from "./checkpoint-features.js";
import type { Checkpoint, CheckpointRowVerdict, CheckpointState } from "./checkpoint-store.js";
import type { PermissionMode, ShellGateDoctrine } from "./types.js";
/**
* The refusal of a frozen inherited chain recorded under an earlier release's projection meaning — an intact row
* (`reading_changed`), told apart from a chain that does not match its digest (a damaged row). Both resume readers that
* compare a chain with its recorded digest raise it: the row judge, over the row's own chain (its reading puts the fixed
* sentence in front), and the checkpoint screen, over a re-supplied chain that matches the row under that earlier meaning —
* this construction, whose message is the arm's fixed sentence, then the diagnostic (the row judge's form).
*/
export declare function earlierChainMeaningRefusal(): CheckpointError;
/** The `reading_changed` refusal a resume reader raises outside the row judge, in the row judge's form (the arm's fixed sentence,
* then `diagnostic`): the earlier chain meaning above, and a chain an earlier release recorded without layer kinds that this
* runner cannot rebuild (`constraint-layers.ts` — the row judge reads no deployment, so that arm is decided where the chain is). */
export declare function readingChangedRefusal(diagnostic: string): CheckpointError;
/**
* The fixed sentence of each row refusal, keyed by its code and arm (`code|reason`), or — for a recorded word the resume
* refuses through prepare's refusal channel (`checkpoint.config_refused`) — by prepare's own code (`detail.code`). Engine
* text only: no sentence names a value, a path or a word the row holds.
*
* A SENTENCE NAMES NO OTHER RELEASE'S WORKER (#4769, #5181): a refusal another release can still read (`terminal: false`) gives the
* way out that works on every deployment (expire the checkpoint and run the work again) and stops there. A worker of the release that
* parked the row exists only where a rolling upgrade still runs one — a single-root deployment upgraded in place has none — and the
* judge reads no deployment, so a sentence that sends its reader to that worker sends a single-user host nowhere. The one machine fact
* stays `terminal`; the road for an operator who does keep such a worker is in the release notes and the integration guide.
* `version_newer` runs the other way (resume on a worker at or above the release; the way back is an upgrade) and keeps its form.
*
* ONE VERB FOR THE ONE ACTION. What a host does with a pending row it cannot resume is `expire` (the store has no other verb that
* retires a row), and every sentence below that gives a way out names it so — never "cancel". A refusal no release resumes (`terminal: true`)
* whose cause no input of a new run reproduces ends "Expire it, then start the task again."; the sentences of the order above keep their
* own tails ("Expire it and run the work again." and the like). One terminal arm says something before that way out: a pending row that
* records what became of its action (`execution_recorded`) may have had that action run already, so it says to check that first.
*
* "RUN THE WORK AGAIN" HOLDS ONLY WHERE RUNNING AGAIN DOES NOT WRITE THE SAME ROW. For every sentence below but one, the cause is
* something no input of a new run reproduces (a seat, an axis or a word a release retired, a damaged section). `config.tool_face_control`
* has a second cause: a host's own `ToolPolicy.projection` that spells a tool with a rule suffix (`Read(*)`) reaches the row through
* the parent chain (`prepare-inherited-gate.ts`), so THIS release writes the row it then refuses, and running the work again under the
* same policy parks the same refused row. That sentence therefore names what changes the cause (a policy that names each tool by its
* bare name).
*/
export declare const ROW_REFUSAL_SENTENCES: Readonly<{
readonly "checkpoint.unsupported_version|version_newer": "This engine cannot resume this checkpoint: it was parked by a newer engine release, whose row this release cannot read. The checkpoint stays pending; resume it on a worker at or above the release that parked it.";
readonly "checkpoint.unsupported_version|seat_retired": "This engine cannot resume this checkpoint: it carries a seat an earlier engine release wrote and this release retired. The checkpoint stays pending and nothing was consumed. Expire it and run the work again.";
readonly "checkpoint.unsupported_version|leg_not_resumable": "This engine cannot resume this checkpoint: it was parked by a synchronous child leg, and nobody resumes such a leg's parks — its result has no road back to the run that spawned it. Nothing was consumed; expire it, and run the work again: have a person who is present approve it live, or delegate it as a background agent whose approvals can wait.";
readonly "checkpoint.unsupported_version|reading_changed": "This engine cannot resume this checkpoint: it was parked by an earlier engine release, and this release reads part of the row differently — a member the decision binds, or the constraints the work inherited — so the row would not mean here what it meant to that release. The row is intact and stays pending; nothing was consumed. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|requirements_damaged": "This engine cannot resume this checkpoint: its content does not read the way it was recorded when it was parked — it was changed or lost in storage. The checkpoint stays pending and nothing was consumed. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|execution_recorded": "This engine cannot resume this checkpoint: it reads pending, yet it records what became of the action it was decided for — the decision was lost in storage after the action was taken up, so the action may already have run, or been refused. The checkpoint stays pending. Check what the row records (`executionOutcome`) and whether the action already took effect — running it again may repeat it. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|real_approval_damaged": "This engine cannot resume this checkpoint: its real-approval mark is missing or malformed (a corruption or downgrade guard). The checkpoint stays pending. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|read_face_damaged": "This engine cannot resume this checkpoint: its read-face section is missing or malformed (a corruption or downgrade guard). The checkpoint stays pending. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|write_face_damaged": "This engine cannot resume this checkpoint: its write-face section is malformed (a corruption guard). The checkpoint stays pending. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|skill_grants_damaged": "This engine cannot resume this checkpoint: its skill-grant section does not read as grant rows under this engine — damaged, or written by an earlier release whose entries this release reads differently. The checkpoint stays pending. Expire it and run the work again.";
readonly "checkpoint.invalid_outcome|skill_scopes_damaged": "This engine cannot resume this checkpoint: its skill-scope section does not read as a list of named skills (a damaged section). The checkpoint stays pending. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|hands_coordinates_damaged": "This engine cannot resume this checkpoint: one of its recorded workspace coordinates is not an absolute path (a corruption guard). The checkpoint stays pending. Expire it, then start the task again.";
readonly "checkpoint.invalid_outcome|constraint_chain_missing": "This engine cannot resume this checkpoint: it requires parent constraints but does not carry both their frozen chain and its digest (a corruption or downgrade guard). The checkpoint stays pending. Expire it, then start the task again.";
readonly "checkpoint.walltime_axis_retired|": "This engine cannot resume this checkpoint: its budget carries a wall-clock allocation, an axis this engine retired, so resuming here would run the work with that ceiling unenforced. The checkpoint stays pending. Expire it and start a fresh task bounded by tokens or budget.";
readonly "resume.parent_constraint_mismatch|constraint_chain_damaged": "This engine cannot resume this checkpoint: its own recorded constraint chain does not match the digest it records (a corrupt or inconsistently minted row). The checkpoint stays pending. Expire it, then start the task again.";
readonly "config.permission_mode_invalid": "This engine cannot resume this checkpoint: a permission mode it records is not one this engine reads (or not one a plan can return to). The checkpoint stays pending. Expire it and run the work again.";
readonly "config.run_origin_invalid": "This engine cannot resume this checkpoint: the run origin it records is not a word this engine knows. The checkpoint stays pending. Expire it and run the work again.";
readonly "config.tool_face_control": "This engine cannot resume this checkpoint: its frozen inherited constraint chain records a tool name in a spelling this engine does not replay. The checkpoint stays pending. Expire it and run the work again under a policy that names each tool by its bare name.";
}>;
type RowRefusalKey = keyof typeof ROW_REFUSAL_SENTENCES;
/**
* Whether NO engine release resumes the row — the verdict's `terminal`, present on every refusal: `true` = no engine release resumes
* it (the card is the host's to expire); `false` = this release cannot read it, another can (a newer one, or an earlier one — the one
* that parked it, if it still runs). Every refusal here is final on THIS engine (the judge is pure over the row's bytes): that fact is the
* verdict's `kind` not being `ok`, never this mark. Read off each arm's cause, one row per key ({@link ROW_REFUSAL_SENTENCES} says no worker
* of another release, so this mark is the one place the fact is written): an arm whose row another release reads is `false`, one no
* release reads is `true`. Typed over every key, so a new refusal is a compile error here until it is placed.
*/
export declare const ROW_REFUSAL_TERMINAL: {
readonly [K in RowRefusalKey]: boolean;
};
/**
* The verdict of a row nothing could read — one the judge threw on, or one the listing projection could not project: `damaged` /
* `requirements_damaged` under the fixed sentence. The total judge answers it, and the projection answers it for a row the judge
* called `ok` but a summary cannot be made of, so a listing never presents a row it cannot read as an approvable card.
*/
export declare const UNREADABLE_ROW_VERDICT: CheckpointRowVerdict;
/**
* The ONE refusal of the RETIRED pre-queue single steer seat (`state.pendingSteer`, written before the queue existed): the
* seat has no `inputId`, `seq` or actor, so folding it in would mint a synthetic identity nothing else can name. The refusal is
* `checkpoint.unsupported_version` with `reason: "seat_retired"` — terminal for the row's bytes; the host decides the parked
* instruction on its own surface and parks it again through `setPendingSteer` if it still applies. The row's judge
* ({@link judgeCheckpointRow}) and the queue's read (`readPendingSteerQueue`, checkpoint-store.ts) ask it. Returns the
* refusal, `undefined` for none.
*/
export declare function retiredSteerSeatRefusal(state: object): CheckpointError | undefined;
/**
* The ONE refusal of a retired mode seed — one of the row's own refusals ({@link judgeCheckpointRow}, read PRE-CAS on every
* resume kind and by every listing): a row whose `inheritedGate` still carries a retired member is refused as the engine refuses
* every retired row seat ({@link retiredSteerSeatRefusal}) — `checkpoint.unsupported_version` with `reason: "seat_retired"` —
* terminal for the row's bytes on this engine, and nothing consumed: the row stays byte-identical and `pending`. No engine
* reads the retired keys into a mode any more; an engine at 7.38.x or earlier still does, so the row can be resumed there once
* (its next suspend writes `permissionMode`), or expired (`CheckpointStore.expire`). Returns the refusal, `undefined` for none.
*/
export declare function retiredModeSeedRefusal(state: Pick<CheckpointState, "inheritedGate">): CheckpointError | undefined;
/**
* The mode seed a row records (the 7.34.0 shape), read at prepare after the row's judge ({@link retiredModeSeedRefusal} among its refusals) has screened the row:
* `permissionMode` must be a member of the closed set and `prePlanMode` a mode a plan can return to (else
* `config.permission_mode_invalid`, the row cannot be resumed under a word this engine does not know); the shell floor is
* `"always"` or absent. Nothing here migrates or guesses.
*/
export declare function recordedModeSeed(gate: Pick<NonNullable<CheckpointState["inheritedGate"]>, "permissionMode" | "prePlanMode" | "shellGate"> | undefined): {
permissionMode?: PermissionMode;
prePlanMode?: PermissionMode;
shellGate?: ShellGateDoctrine;
};
/**
* The row's verdict for THIS engine: `ok`, `lacking` (a newer engine can resume it: `checkpoint.unsupported_version` /
* `version_newer`, `requires` the reader words it lacks when its requirement list named them), or `damaged` (this engine
* does not resume these bytes). Pure (reads no clock, no random, no deployment) and total; the verdict is frozen. A store's
* listing carries it as `CheckpointSummary.rowVerdict`; a whole-row reader (`listBySession`, an operator queue) asks it here.
*/
export declare function judgeCheckpointRow(cp: Checkpoint): CheckpointRowVerdict;
/** The refusal the resume throws for a row whose verdict is not `ok` — the verdict's code, its sentence then the row's
* diagnostic as the message, the refusal's own detail — or `undefined` for an `ok` row. Always judged now, never memoized. */
export declare function checkpointRowRefusal(cp: Checkpoint): CheckpointError | undefined;
/** {@link checkpointRowRefusal} as the resume reads it: the refusal and whether it is the verdict's chain arm — an intact chain an
* earlier release digested under its own projection meaning (`reading_changed`), which the resume throws at its chain rung, after
* the decision's bindings, rather than at admission. The arm that refused says so; the refusal object never does. */
export declare function checkpointRowResumeRefusal(cp: Checkpoint): {
readonly refusal: CheckpointError;
readonly chainArm: boolean;
} | undefined;
export {};