UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

111 lines (110 loc) • 6.16 kB
import { type Checkpoint, type CheckpointStore, type CheckpointSummary, type ResumeOutcome } from "../checkpoint-store.js"; import type { GateOutcome } from "../gate-outcome.js"; import { type CheckpointFields } from "../pause-registry.js"; import { type ContractAssertionRunner } from "./contract-harness.js"; import { type ContractGrants } from "./grant-fixture.js"; /** Build a {@link Checkpoint} fixture: the content given, stamped by the mint's own stamp (the row format, its reader-requirement * words and digest — a row with no stated format is one the row judge refuses as a retired seat). A case that edits the row after * this reads it as the store would hand back an edited row. `createdAt` is FIXED (not wall-clock) so summary projections * are deterministic and cross-backend byte-comparable; override via `over` for ordering tests. */ export declare function createCheckpointFixture(over?: Partial<CheckpointFields>): Checkpoint; /** The canonical `policy_ask allow` outcome the contract resolves with. Declared as the NARROW * `policy_ask` arm — not the whole union — so field access and spread call sites need no * re-assertion (RB-396-d: the wide declaration forced an `as Extract<…>` + a same-value * `boundCallId` overwrite at one site — verbatim 移植残渣, both gone with this declaration). */ export declare const ALLOW: Extract<ResumeOutcome, { gate: "policy_ask"; }>; export declare const EXECUTED_ALLOW: GateOutcome; export declare const EXECUTED_ALLOW_REORDERED: GateOutcome; export declare const VETOED_BY_POLICY: GateOutcome; /** The other decider: the record a `policy_ask` allow the deployment's own POLICY decided files * (`policy_allowed`, `who.party: "policy"` with the seat that answered) — the decision's own record on the * resolved winner, and the execution record once the call ran — and the decide that carries it. A backend keeps * the record verbatim; nothing in it may be re-derived from the person's shape. */ export declare const POLICY_ALLOWED: GateOutcome; export declare const POLICY_ALLOW: Extract<ResumeOutcome, { gate: "policy_ask"; }>; /** * The full cross-backend contract for {@link CheckpointStore} — the SAME assertions for every * backend. Entries are a 1:1 port of the vitest originals (assertion semantics unchanged). */ export declare function checkpointStoreContract(make: () => CheckpointStore, runAssertion?: ContractAssertionRunner, /** `sessionHeads` = the map the binding's stores read their session heads from (their `deleteSessionCheckpoints` guard): the kit writes * the heads its delete case needs into it. Required only to judge a store that offers `deleteSessionCheckpoints`. * `composed` + `grants` = the holder binding (the C-H cells): `composed()` returns a FRESH, empty store AS THE DEPLOYMENT COMPOSES IT — * every wrapper included (a park-commit observer, a forwarding layer) — built with the judge `grants` mints its holders against * ({@link ContractGrants}). Bind the composition itself, the function the deployment's startup calls: a cell run on the bare store * cannot see a wrapper, and a wrapper is what silently drops a holder (a `put` / `setPendingSteer` / `expire` forwarded without its * last argument, a `resolve` that forwards `rev` and drops `expect.holder`). Required (both) for a store that declares `fence`. * `onOptionalMember` = told, per holder cell, whether the cell's `claimTerminal` arms ran (`verified`) or were skipped because the * composed store does not implement `claimTerminal` (`absent`), and whether the cell itself ran (`holder`: `verified`) or asserted * nothing because the binding judges no holders (`holder`: `absent` — no `fence`, no `composed`, no `grants`), and whether the * store answers the overdue face's age backstop (`listOverdue.maxAgeMs`) and the session face's run axis (`listBySession.axis`) — or * refuses a query carrying the member (`absent`: the cell judges it no further; ignoring the member is red, never `absent`). (`holders`, the set of current holders this kit took before the grant * fixture, is retired and refused by name.) */ options?: { readonly sessionHeads?: Map<string, { readonly owner: string | null; }>; readonly composed?: () => CheckpointStore; readonly grants?: ContractGrants; readonly onOptionalMember?: (report: { member: "claimTerminal" | "holder" | "listOverdue.maxAgeMs" | "listBySession.axis"; status: "verified" | "absent"; cell: string; }) => void; }): Promise<void>; /** Seed the canonical listByScope fixture into `store` and return the sorted summaries. Compare the * result against {@link EXPECTED_LISTBYSCOPE_SUMMARIES} (deep equality) to prove the backend's * summary projection matches the reference — the caller owns the comparison (harness-specific). */ export declare function checkpointListByScopeSummaries(store: CheckpointStore): Promise<CheckpointSummary[]>; /** The canonical expected summary projection (what `summarizeCheckpoint` must yield for the fixture above). */ export declare const EXPECTED_LISTBYSCOPE_SUMMARIES: ({ token: string; rowVerdict: { kind: string; }; sessionId: string; scope: string; gateKind: string; severity: number; deadline: number; createdAt: number; sourceSessionId: string; principal: string; toolCallId: string; toolName: string; toolInput: string; mandated: boolean; mandate: string; origin: string; boundGrantAbsence: string; resourceLimit?: undefined; spentMicroUsd?: undefined; } | { token: string; rowVerdict: { kind: string; }; sessionId: string; scope: string; gateKind: string; resourceLimit: { reason: string; }; spentMicroUsd: number; createdAt: number; severity?: undefined; deadline?: undefined; sourceSessionId?: undefined; principal?: undefined; toolCallId?: undefined; toolName?: undefined; toolInput?: undefined; mandated?: undefined; mandate?: undefined; origin?: undefined; boundGrantAbsence?: undefined; })[];