@sema-agent/core
Version:
Stateless, task-oriented AI agent core
72 lines (71 loc) • 5.32 kB
TypeScript
/**
* The checkpoint seat's re-key law, one pure function every backend shares ({@link rekeyCheckpointRow}): a checkpoint row's key
* is its token and its identity is cells on the row, so the seat re-files a row IN PLACE — within the row's own write
* serialization, on the row as it stands there — and changes only the identity cells whose value the mapping changes. The
* row's verdict decides only whether the row is touched; its stamps follow their own judge; the write is a new generation. A
* backend keeps the commit half alone.
*
* Its run-time imports are the row judge, the stamp judge and mint, the partition record and the re-key input module — none
* of which imports a store, so `checkpoint-store.ts` reaches it without a cycle.
*/
import type { Checkpoint, StoreFidelity } from "./checkpoint-store.js";
import { type IdentityRekeyMap } from "./identity-rekey.js";
/**
* The cells of a row that carry identity — THE one list: the re-key law reads and writes exactly these paths, the census
* pin holds the list against what the real mints write (both ways), and a backend's candidate pre-screen is spelled from
* it. Two axes: a principal cell moves by the principal pair, a scope cell by the scope pair whose source it holds. The
* partition is the row's owner identity's scope — `isolationScope` when the row records one, else the row's principal — and
* is re-filed with the principal by the one identity law (`rekeyOwnerIdentity`), then recorded by the mint's own rule. A path
* segment ending in `[]` is every element of a list.
*/
export declare const CHECKPOINT_IDENTITY_MEMBERS: Readonly<{
readonly principal: readonly ["principal", "state.inheritedGate.ancestorRules[].principal"];
readonly scope: readonly ["scope", "state.legScope", "durableApproval.scope", "state.legIdentity.rootSessionScope"];
readonly partition: readonly ["isolationScope"];
}>;
/**
* The members of a row that can hold a string equal to a principal or a scope and are NOT identity cells, each with why (a
* path prefix: the member and everything under it) — the census pin's exclusion table, kept beside the list it completes so
* the reason lives in the code. A re-key leaves every one of them as it stands.
*/
export declare const CHECKPOINT_NON_IDENTITY_MEMBERS: Readonly<Record<string, string>>;
/** A row's handling by one re-key (pure; every backend writes only the commit half of it). */
export type CheckpointRekeyVerdict =
/** No cell holds a source value the mapping changes: the row is not this move's. */
{
readonly kind: "untouched";
}
/** The whole row as the write files it: its identity cells re-filed, its stamps per their judge, `rev` one above the
* `rev` of the row handed in; `partitionLeft` as `rekeyOwnerIdentity` answers it for the row's identity. */
| {
readonly kind: "rekeyed";
readonly row: Checkpoint;
readonly partitionLeft: boolean;
}
/** Selected, but this engine judges the row `lacking` (a newer engine's row): it is left as it is and counted. */
| {
readonly kind: "unrekeyable";
};
/** Is `row` this move's — does some identity cell hold a value the mapping changes (the partition's value included)? The
* selection, alone: the one question a backend may ask outside the row's write serialization (identity cells are minted once
* and only a re-key moves them), to pick the rows it then re-judges under the lock. */
export declare function checkpointRekeySelects(row: Checkpoint, map: IdentityRekeyMap): boolean;
/**
* THE law of one row ({@link CheckpointRekeyVerdict}): hand it the row AS IT STANDS within the row's own write
* serialization — `rev` comes out one above that row's, and every member the mapping does not change (the status, the
* winner, the steer queue, the execution record) as that row holds it.
* 1. selection, before any verdict: the row is this move's iff some identity cell holds a value the mapping changes — the
* partition's value (`isolationScope`, else the principal) included;
* 2. the row's verdict ({@link judgeCheckpointRow}) decides only whether it is touched: `lacking` ⇒ left as it is;
* 3. the cells are re-filed (each container on the way to a cell copied, never written into — a container the row holds at
* two places changes only at the identity path); the partition is the identity law's ({@link rekeyOwnerIdentity}: moved by
* the scope pair whose source its value is, never by the person moving) and is recorded by the mint's rule
* ({@link isolationScopeRecordOf}: only where it differs from the re-filed principal) — so a row that recorded none and
* whose principal moves without a pair for it records the partition it keeps;
* 4. the stamps follow their own judge ({@link judgeCheckpointRequirements}, asked of the row before the write): stamps that
* match are recomputed by the mint's stamp; stamps that do not are left as they are; a row below the stamped format
* (one its judge refuses as a retired seat) gains none and keeps its version — re-stamping it would make an earlier
* release's row read as this format's;
* 5. `rev` = the handed row's + 1.
*/
export declare function rekeyCheckpointRow(row: Checkpoint, map: IdentityRekeyMap, fidelity: StoreFidelity): CheckpointRekeyVerdict;