@sema-agent/core
Version:
Stateless, task-oriented AI agent core
71 lines (70 loc) • 6.76 kB
TypeScript
/**
* The resume's CONFIG JUDGE — the rungs of the resume ladder that refuse a re-supplied config (or the deployment's deps, or a recorded
* name list) the way prepare would refuse it after the claim, and the one question that asks them all before anything is written.
*
* Every refusal here leaves by the resume's ONE refusal channel (`asResumeConfigRefusal`: `checkpoint.config_refused`, the sentence prepare
* gives, prepare's code as `detail.code`, the input that carries it as `detail.field`, the arm as `detail.reason`). The ladder (admission,
* checkpoint screen, internals-and-config) calls these functions at the stations it always entered them at, so the order of its refusals is
* unchanged; {@link resumeConfigVerdictOf} runs the same functions in the same relative order over the same inputs, answers the first
* `checkpoint.config_refused` as a value, and writes nothing — `Runner.judgeResumeConfig` is its public seat. One set of rungs, one order:
* a host that asks first and writes after cannot be told something the claim path would not say.
*
* What it answers is the CONFIG question only. The row's own refusals (its version, its requirements, its recorded words) are the row's
* verdict (`checkpointRowRefusal`), which the ladder reads before these rungs; a refusal that is not a config refusal (an outcome the gate
* does not take, a principal that contradicts the row, a lost claim) is not this judge's to give.
*/
import { type Checkpoint, type CheckpointStore } from "./checkpoint-store.js";
import type { CheckpointConfigRefusalCode, CheckpointErrorReason } from "./checkpoint-features.js";
import { type ConfigRefusalInput } from "./config-refusal-input.js";
import type { SessionStore } from "./session.js";
import type { RunnerDeps } from "./types.js";
import type { ResumeTaskConfig, RunInternals } from "./runner/contracts.js";
/** What a host asks before it writes: the pending row, the config the resume would be handed, the trusted internals it would be handed. */
export interface ResumeConfigQuestion {
/** The pending row the resume would redeem (the host's own read of the token). The rungs that compare the config with the row read it: the names the row recorded, the isolation scope it was parked in. Required: a question without the row would pass those rungs unasked. */
readonly row: Checkpoint;
/** The `taskConfig` the resume would be handed, as the host would hand it. */
readonly taskConfig: ResumeTaskConfig;
/** The trusted `internals` the resume would be handed (its `holder`, `toolCeiling`, `ownToolLists`, inherited parent constraints), when it would be handed any. */
readonly internals?: RunInternals;
}
/**
* The answer: the config would not be refused, or the refusal the resume would give — `code`, `field` and `reason` are the resume's
* `checkpoint.config_refused` `detail.code`, `detail.field` and `detail.reason`, `message` its sentence (prepare's own).
*/
export type ResumeConfigVerdict = {
readonly ok: true;
} | {
readonly ok: false;
readonly code: CheckpointConfigRefusalCode;
readonly field: ConfigRefusalInput;
readonly reason?: CheckpointErrorReason;
readonly message: string;
};
/** Rung 1 — the caller's config is a record, read ONCE into the snapshot every later rung and the resumed leg read (own data; the skills' lists detached). Refuses by the resume's one channel. */
export declare function readResumeConfig(taskConfig: ResumeTaskConfig): ResumeTaskConfig;
/** The trusted internals bag as the ladder reads it after the seat door's one read of it (`readLegInternals`): the composition leg copied by its one reading, the one member the ladder validates by its members. What every later rung and the resumed leg read, and what a host's question is judged over. */
export declare function snapshotResumeInternals(internals: RunInternals | undefined): RunInternals | undefined;
/** Rung 2 — the checkpoint store this resume redeems against (`undefined` for the `"disabled"` spelling); a seat the engine cannot accept leaves by the one channel, at the seat that named it. */
export declare function resolveResumeStore(config: ResumeTaskConfig, deps: RunnerDeps): CheckpointStore | undefined;
/** Rung 4 — the tool names a resume is bound by: the row's recorded ceiling and own lists (each when the leg runs under it, i.e. the internals supply no live one), then the roster the resume hands. */
export declare function refuseRecordedAndMountedToolNames(cp: Checkpoint, internals: RunInternals | undefined, tools: unknown): void;
/** Rung 5 — a retired member of an inherited constraint this resume is handed refuses by the same channel as the caller policies' same word, so the row stays pending. */
export declare function refuseRetiredInheritedConstraints(internals: RunInternals | undefined): void;
/** Rung 6 — the checkpoint scopes the config declares must follow the isolation scope the leg will run in. Asked only where the config names none and the row records one: the leg then inherits the row's, and that pair exists only after the inheritance (a config that names its own was judged by its door). `row` / `supplied` are the two values the caller already read (`|| undefined`). */
export declare function refuseScopesOffInheritedIsolationScope(row: string | undefined, supplied: string | undefined, config: Pick<ResumeTaskConfig, "durableApproval" | "resourceSuspend">): void;
/**
* Would a resume with this config be refused at the config rungs, before the claim? Runs {@link readResumeConfig}, {@link resolveResumeStore},
* `refuseResumeDoors`, {@link refuseRecordedAndMountedToolNames}, {@link refuseRetiredInheritedConstraints} and
* {@link refuseScopesOffInheritedIsolationScope} in the order the ladder reaches them, over the deps and the session store the Runner holds; the first
* `checkpoint.config_refused` is the answer. Pure: it reads the question's values and the seats' declarations and calls no store, no sink and no
* factory; the row stays as it is. A throw that is none of the channel's refusals leaves as it was thrown, exactly as the resume leaves it.
* The config bag is read once, and the internals are read through the seat door's one read of the bag (`readLegInternals`, then
* {@link snapshotResumeInternals}), as a resume reads them: a bag whose read throws is refused by the door's own sentence
* (`config.invalid_argument`) before any rung, as the resume refuses it; a bag that answers differently the next time it is read (an
* accessor) is a bag this verdict cannot vouch for.
*/
export declare function resumeConfigVerdictOf(question: ResumeConfigQuestion, seats: {
readonly deps: RunnerDeps;
readonly sessions: SessionStore;
}): ResumeConfigVerdict;