@sema-agent/core
Version:
Stateless, task-oriented AI agent core
431 lines (430 loc) • 36.2 kB
TypeScript
/**
* The permission MODE's two derivations, beside the arbitration that reads it (`ask-origin.ts`):
*
* - {@link modePolicyOf} — what a mode INSTALLS on the leg: the plan pair and the mode's own write gate (the
* reference implementation's per-mode defaults: `plan` keeps every tool mounted and ASKS at the call for a write
* and for a tool it did not define that is not read-only, `acceptEdits` writes inside the root without asking,
* `default` / `auto` / `dontAsk` ask on every covered write — auto's classifier and dontAsk's refusal then act on
* that ask — and `bypassPermissions` installs no gate). One writer of the mode (the caller, the steer verb, the
* model's `EnterPlanMode`), one interpreter (this engine): a library embedder's `plan` is not a word a serving
* layer has to translate first.
* - {@link PermissionModeController} — the one RESOLUTION of a leg's effective mode, read live by every mode
* consumer (the gate's arbitration, the mode gate policy, the manifest, the children's ceiling): the
* requested word, clamped under the parent's live ceiling, folded back to `default` where the deployment
* denies it or the arming face is absent. A steer rewrites the requested word; nothing caches the answer.
*/
import type { AgentTool, ExecutionEnv } from "../internal/harness-types.js";
import type { ContainmentFace } from "../tools/fs/containment-face.js";
import { type PermissionResult, type ToolCallRequest, type ToolPolicy } from "./tool-policy.js";
import { type ToolRoster } from "./tool-roster.js";
import { type PermissionMode } from "./ask-origin.js";
import type { RuntimeCaps } from "./runtime-caps.js";
import type { AutoModeArmFact } from "./wiring-manifest.js";
import type { RunnerDeps } from "./runner-deps.js";
import { type StartedShell } from "../shell/lex.js";
import { type ConfigRefusalInput } from "./config-refusal-input.js";
import type { TaskSpec } from "./task-spec.js";
/** WHY an effective mode is not the requested one: the deployment's deny bit (`RuntimeCaps.bypassPermissions` /
* `RuntimeCaps.autoMode`), a requested `auto` with no classifier face wired, or a child's declaration folded under
* its parent's ceiling. */
export declare const PERMISSION_MODE_FOLD_REASONS: readonly ["operator_deny", "face_absent", "inherited_ceiling"];
export type PermissionModeFoldReason = (typeof PERMISSION_MODE_FOLD_REASONS)[number];
/** The mode's seats on a leg. `writeGate`: `none` — no mode write gate; `ask` — every covered write asks;
* `accept_root` — writes inside the leg's write roots (the task root and every additional working directory) are allowed,
* writes outside them ask; `plan` — every write {@link planRefusesWrite} names is the mode's OWN question (the plan
* sentence, `decisionReason: "mode"`: a person may say yes, no rule and no automatic lane answers it). `fileCommands`: the
* shell commands whose ordinary question the mode answers itself ({@link modeAcceptsFileCommand}) — the reference
* implementation's `acceptEdits` set ("auto-approve file edits and common file commands"); empty for every other mode.
* `writeFace`: the write face the mode states where no seat declared one (the mode row of {@link import("../tools/fs/containment-face.js").resolveContainmentFace}) —
* `bypassPermissions` writes outside the write roots (`open`); every other mode states nothing and the default fence stands.
* `unstated`: the mode's answer for a call to a tool that states no permission of its own (permission seat `passthrough`)
* when no answer covers the fold's allow ({@link asksUnstated}) — `ask` (the arbitration then answers it as any ask: dontAsk refuses it, auto's
* classifier may answer it), or `none` (the call runs; `bypassPermissions`, which installs no gate and asks nothing it would
* release). */
export interface ModePolicy {
readonly enablePlanMode: boolean;
readonly writeGate: "none" | "ask" | "accept_root" | "plan";
readonly fileCommands: readonly string[];
readonly writeFace: ContainmentFace | undefined;
readonly unstated: "ask" | "none";
}
/** The `acceptEdits` file commands: a closed set. */
export declare const ACCEPT_EDITS_FILE_COMMANDS: readonly ["mkdir", "touch", "rm", "rmdir", "mv", "cp", "sed"];
/** The mode → seats table, total over {@link PermissionMode}. */
export declare function modePolicyOf(mode: PermissionMode): ModePolicy;
/** The spec with the mode's own seats applied: `plan` mounts the plan pair (every other tool stays, the mode gate asks at
* the call). The one place a mode becomes a spec seat — the leg's prepare and the static plan read both go through it, so a
* deployment's static answer for a mode is the answer the leg mounts. */
export declare function withModeSeats<S extends {
readonly enablePlanMode?: boolean;
}>(spec: S, mode: PermissionMode): S;
/**
* Is this call a shell command the mode's {@link ModePolicy.fileCommands} cover — every segment a SIMPLE command
* whose command word is, as written, one of them? The reference implementation's reading (it compares the first
* word of each command against its list): no redirection, no pipe or background, no substitution, no leading
* assignment, no wrapper in front, a literal unquoted command word — `/bin/rm` and `"rm"` are not `rm`. The answer
* is only ever a license for the mode to answer the call's ORDINARY question: the gate's arbitration reads it beside
* the class set and the read station's `writesPlaced` fact (every write target established inside the write roots, no
* removal of a root, every program in the text), so a deny rule, an ask rule, the delete guard, a read-boundary finding
* or a write the station could not place still stands. A `run_in_background` call is not accepted (as a `&` is not).
*/
export declare function modeAcceptsFileCommand(mode: PermissionMode, toolName: string, args: unknown): boolean;
/** {@link modeAcceptsFileCommand} of a call whose text `shell` runs (the gate's mode point: the call's started shell). */
export declare function modeAcceptsFileCommandIn(shell: StartedShell, mode: PermissionMode, toolName: string, args: unknown): boolean;
/** What the mode gate policy resolves paths against. `acceptDirs` = the leg's WRITE ROOTS (the task root plus every additional
* working directory), the set `acceptEdits` allows writes inside — absent ⇒ the root alone; `roster` = the leg's live tool roster
* (who defined the called tool and its effect) and `readOnlyDeclared` = whether the mounted tool of that name declares itself
* read-only, both read per call by {@link planRefusesWrite}. What the gate never asks about is not a seat here: it is the run's
* advertised writable seat (scratchpad, memory root, session plan file), stamped on every request as
* `advertisedWritableRoots` — the fence's own admission, so the gate holds no second copy of it. */
export interface ModeGateSeats {
env: ExecutionEnv;
rootPath: string;
/** A getter is read per call: the leg's live write roots (canonical identities), which move with its write location (an
* EnterWorktree switch). */
acceptDirs?: readonly string[] | (() => readonly string[]);
roster?: {
readonly current: ToolRoster | undefined;
};
readOnlyDeclared?: (toolName: string) => boolean;
}
/** Does the LAST mounted instance of this name (the one a call dispatches to) declare itself read-only — an MCP server's
* `readOnlyHint` ({@link AgentTool.mcpReadOnlyHint})? The mode gate's `readOnlyDeclared` seat over the leg's live tools. */
export declare function mountedToolDeclaresReadOnly(tools: readonly AgentTool[], toolName: string): boolean;
/** The ONE rule of the unstated question, read at the fold's last station and at the approved-edit round: an allow on a tool
* that states no permission of its own, under a mode whose `unstated` answer is `ask`, that no answer covers — no engine
* record of a settled wait licensing the bytes that run (`runs`; {@link answeredFor}). A layer's allow says nothing here
* whatever words it carries; who else may clear the question is the allow layer's business (its members, a hook's own `allow`
* among them), not this rule's. A call to an A2A peer registered inside the trust boundary (`insidePeer`, the gate's
* `a2aInsidePeer` record) is asked under EVERY mode: the relaxation changes who may clear its question (`a2a_inside`), never
* whether there is one — so `bypassPermissions` releases it on the call's record, as it released the marked call before. */
export declare function asksUnstated(d: PermissionResult, call: {
toolCallId: string;
toolName: string;
}, runs: unknown, seat: "passthrough" | undefined, mode: PermissionMode | undefined, insidePeer: boolean): boolean;
/** The unstated question's sentence (the reference implementation's passthrough sentence, without its product name). */
export declare const unstatedAskMessage: (toolName: string) => string;
/** One call's permission seat: `passthrough` (an allow no answer covers meets the mode's unstated answer) and the question
* put when it does — absent ⇒ {@link unstatedAskMessage}. */
export interface PermissionSeatReading {
readonly seat: "passthrough";
readonly question?: string;
/** This call must be put to a person, under every mode — the per-call form of a server's
* {@link import("../engine/loop/types.js").AgentTool.mcpRequiresUserInteraction} declaration (the `Skill` tool's reading for a
* skill the host declared an approved proposal, `SkillSpec.createdBy`). The gate reads the two as one fact. */
readonly requiresUserInteraction?: true;
}
/** The gate's permission-seat inputs (a member group of `ToolGateInput`), read through {@link permissionSeatAt}. */
export interface PermissionSeatInputs {
/** The called tool's permission seat ({@link import("./tool-spec.js").ToolSpec.permissionSeat}): `"passthrough"` ⇒ an allow no answer covers
* meets the mode's answer for an unstated call ({@link ModePolicy.unstated}). Absent ⇒ the tool answers for itself. */
permissionSeat?: "passthrough";
/** The question that static seat puts (the mounted tool's own sentence, {@link mountedToolPermissionQuestion}); absent ⇒
* {@link unstatedAskMessage}. */
permissionQuestion?: string;
/** The seat read off THIS call's arguments, for a tool whose seat depends on them (the Runner wires it for the `Skill`
* tool: a skill that declares a list asks `Execute skill: <name>`). Present ⇒ it is the reading. */
permissionSeatOf?: (args: unknown) => PermissionSeatReading | undefined;
}
/**
* The ONE reading of a call's permission seat, taken on the arguments the gate is judging (the policy's rewrite and the
* hook's included): the per-call reader where the tool's seat depends on its arguments, else the mounted tool's static
* seat. Read at the fold's last station and at the approved-edit round, on that round's edited bytes.
*/
export declare function permissionSeatAt(input: PermissionSeatInputs, args: unknown): PermissionSeatReading | undefined;
/** A call's seat inputs as the gate reads them: a tool's own seat (its static word, its question, its per-call reader) speaks for a
* call the model made; the engine's continuation of a parked workflow run (`continuationCall`) continues a run whose launch already
* passed the gate, so it is judged without that seat — every other input of the group (skill rows, entry lists) stands. */
export declare function seatInputsOfCall<T extends PermissionSeatInputs>(inputs: T, continuationCall: boolean): T | Omit<T, "permissionSeat" | "permissionQuestion" | "permissionSeatOf">;
/**
* The interaction tighten on an APPROVED EDIT's bytes: where the edited bytes' seat reading declares that the call must be put to a
* person and the card those bytes put is not the card of the bytes the approver answered over carrying that declaration (`answered`
* — none, or another card), a surviving allow becomes that card (`safety`). An edit onto such a call is put to a person; an edit that
* keeps the card a person answered is not asked again. Anything else is `decision` as given.
*/
export declare function editInteractionTighten<D extends PermissionResult>(decision: D, input: PermissionSeatInputs, editArgs: unknown, answered: {
readonly bytes: unknown;
} | undefined, toolName: string): D | Extract<PermissionResult, {
action: "ask";
}>;
/** The PERMISSION SEAT of the LAST mounted instance of this name (the one a call dispatches to) — `passthrough` when the
* instance states no permission of its own ({@link AgentTool.permissionSeat}), else `undefined` (the engine's stations and
* the deployment's declarations answer for it). Read per call off the leg's live mount array, so a refresh is seen. */
export declare function mountedToolPermissionSeat(tools: readonly AgentTool[], toolName: string): "passthrough" | undefined;
/** The question the LAST mounted instance of this name puts through its `passthrough` seat ({@link AgentTool.permissionQuestion}),
* as the instance carries it (the gate's entry judges it, {@link readPermissionQuestion}); `undefined` ⇒ the generic sentence. */
export declare function mountedToolPermissionQuestion(tools: readonly AgentTool[], toolName: string): string | undefined;
/** The gate's entry reading of a seat's question ({@link PermissionSeatInputs.permissionQuestion}): a string with a visible
* character, or absent; anything else is refused loudly (`config.invalid_argument`, the input named, the value never echoed) —
* the reading the gate's other caller sentence, `suspendTargetGap`, gets. */
export declare function readPermissionQuestion(value: unknown): string | undefined;
/** Does the LAST mounted instance of this name (the one a call dispatches to) carry its server's declaration that a call must be put to a
* person ({@link AgentTool.mcpRequiresUserInteraction})? Read per call off the leg's live mount array, so a refresh is seen. The gate's
* seat for the `requires_user_interaction` class. */
export declare function mountedToolRequiresUserInteraction(tools: readonly AgentTool[], toolName: string): boolean;
/**
* Is this call a WRITE the `plan` mode asks about? Two faces, one question — does the call write by its declaration:
* · a covered path write (the catalog's protective floor: a file-write tool, or a same-name tool wearing its slot), and
* · a call to a tool the engine does not define (a caller's, an MCP server's, an A2A peer's) that is not read-only — the
* reference implementation's plan arm for a tool it did not write (`!isReadOnly` ⇒ the mode). Read-only is the tool's
* effect on the leg's roster being `read`, or — only where that effect is the fail-closed default (nobody declared one)
* — the mounted tool's own read-only declaration (`readOnlyDeclared`: an MCP server's `readOnlyHint`, which the
* reference reads for this question). A declared effect (the tool's own, or the deployment's `toolAxes`) always
* outranks the server's claim; the effect is the repeat-safety axis a server's self-claim never lowers.
* The engine's own tools answer through their own seats: a child a delegation spawns inherits `plan` as its ceiling, and
* the shell station and the tool marks raise their own questions, which reach a person under `plan` as under `default`.
* A name the roster does not carry dispatches nowhere and is not judged here.
*/
export declare function planRefusesWrite(req: ToolCallRequest, roster: ToolRoster | undefined, readOnlyDeclared?: (toolName: string) => boolean): boolean;
/**
* Does a question of the MODE reach a call of this tool — its unstated question (the tool declares the `passthrough` seat
* and the mode asks one, {@link asksUnstated}) or its write gate (a covered path write; under `plan`, every write
* {@link planRefusesWrite} names)? Read on the tool's face as the roster mints it — its declarations, never a call's
* arguments — by the load-time ungated-write warning, which names a caller's write-capable tool no question of the mode reaches.
*/
export declare function modeQuestionReaches(mode: PermissionMode, roster: ToolRoster, toolName: string, seat: "passthrough" | undefined): boolean;
/** The acceptEdits mode's own write gate over `seats`: an in-root write it answers allow, everything else it asks. One
* constructor for the mode's gate below and for the manager station's question "would acceptEdits admit this path?"
* (`manager-seat.ts`), so the two cannot answer differently. */
export declare function acceptEditsWriteGate(seats: Pick<ModeGateSeats, "env" | "rootPath" | "acceptDirs">): ToolPolicy;
/**
* The mode's WRITE GATE as one live policy layer: every call reads the mode ref and dispatches to the gate the
* table names for it, so a steer changes the next call's gate without re-composing the chain. The three gates are
* built once (their root / exemption screens run at construction). The plan gate is the ask gate with the plan
* sentence in place of the ordinary write question: the same structural exemptions (the scratchpad, the advertised
* writable roots — the reference exempts its scratchpad and agent-memory files under plan too) admit a write, everything
* else the mode names asks.
*/
export declare function createModeGatePolicy(modeRef: {
readonly current: PermissionMode;
}, seats: ModeGateSeats): ToolPolicy;
/**
* The mode a resumed leg REQUESTS. Without a mode the approval names: the re-passed spec's word, else the word the checkpoint row
* recorded — except where the resume approves or edits a pause whose approval requests the plan exit (`approvalRequestsPlanExit`, the
* one answer the pause's faces echo: a `plan_review` over a row recorded in `plan`): the plan exits to the resume's word, else to the
* word the leg had before it (`prePlanMode`, the reference implementation's ExitPlanMode: `prePlanMode ?? "default"`; absent ⇒ the
* leg's own default). A re-passed `plan` does not keep an approved plan open.
* The mode the person's approval names (`outcome.permissionMode`, the one the decided row records), on whatever row it decides: a
* tightening of that mode holds unconditionally; a widening holds only where the ceiling it is folded under is known — the parent's
* mode with the deployment's cap (the leg's ceilings fold it after). A leg with a parent whose mode this resume was not handed
* (`parentModeUnknown`) has no known ceiling: the widening is withheld and the leg requests the mode it would without it.
*/
export declare function modeRequestAfterResume(seat: PermissionMode | undefined, recorded: {
readonly permissionMode?: PermissionMode;
readonly prePlanMode?: PermissionMode;
}, outcome: {
readonly gate: string;
readonly decision?: string;
readonly permissionMode?: PermissionMode;
} | undefined, parentModeUnknown?: true): PermissionMode | undefined;
/** The mode an approval named that {@link modeRequestAfterResume} withholds (a widening with no known ceiling), else `undefined` —
* the one fact a leg says when it does not take the mode a person approved. */
export declare function withheldApprovalMode(seat: PermissionMode | undefined, recorded: {
readonly permissionMode?: PermissionMode;
readonly prePlanMode?: PermissionMode;
}, outcome: {
readonly gate: string;
readonly decision?: string;
readonly permissionMode?: PermissionMode;
} | undefined, parentModeUnknown?: true): PermissionMode | undefined;
/**
* The permission MODE's door — two refusals in the pre-first-await stretch, each by name and never a fold back to
* absence (a mode a caller believes it declared must not silently run as another): a `permissionMode` outside
* the closed set (`config.permission_mode_invalid`); a `shellGate` value other than the floor word `"always"`
* (`config.shell_gate_value_retired` — `"off"` / `"classify"` were a doctrine the mode arbitration replaced). A RETIRED
* mode key (`autoModeRequested` / `approverPosture` — one key now) is refused by the spec's one read (`readCallerSpec`,
* `config.spec_retired_key`), before this door. The value it screened is the value it RETURNS — the mode seat reads this
* snapshot, never the spec again. The ONE function both entrances call: prepare (the run's read of its spec, before the
* config doors rebind it, in its pre-first-await stretch) and the resume ladder's admission rung (the re-supplied
* config's read, before the claim) — a resume prepare would refuse is refused before it consumes the row.
*/
export declare function refusePermissionModeDoors(spec: Pick<TaskSpec, "permissionMode" | "shellGate">): PermissionMode | undefined;
/** The resume's ONE refusal channel for a door prepare would refuse at: enters `screen` (prepare's own function, which throws prepare's sentence and code)
* with `input` as every prepare entrance does ({@link enterConfigDoor}), and leaves a refusal of one of {@link CHECKPOINT_CONFIG_REFUSAL_CODES} as
* `checkpoint.config_refused` — the sentence, prepare's code as `detail.code`, the input the engine recorded for it as `detail.field` (the nearest entrance's
* word: a door inside `screen` entered with its own word keeps it), and prepare's own arm as `detail.reason` when its error names one; that error is recorded
* with the same word, so `configRefusalInputOf` answers the object `resume()` / `resumeStream()` reject with as it answers its `detail.field`. Anything
* else leaves as it was thrown. What the door returns is returned. */
export declare function asResumeConfigRefusal<T>(input: ConfigRefusalInput, screen: () => T): T;
/** The three-member answer every mode question gets — the manifest member, the steer verb's return value and the
* fold notice's detail share it. `requested` is absent when the caller declared nothing (a root inherits `default`,
* a child inherits its parent). */
export interface PermissionModeReceipt {
readonly requested?: PermissionMode;
readonly effective: PermissionMode;
readonly foldedBy?: PermissionModeFoldReason;
}
/** The deployment's facts a declared mode arms against: the controller binds them once the caps resolved; a host states them
* to read what a word would arm as on its deployment ({@link foldPermissionMode}). */
export interface PermissionModeArmingFacts {
/** The deny bits for this principal (`false` = denied; absent = not denied — absence is never a denial), and the settings
* plane that turned auto mode off when the resolver named one. */
readonly caps: Pick<RuntimeCaps, "bypassPermissions" | "autoMode" | "autoModeDenySource"> | undefined;
/** An auto-mode classifier face is wired: the leg's deployment face (`RunnerDeps.autoMode`), or the one its ancestor armed from. */
readonly autoFacePresent: boolean;
/** The deny bit was coined by a resolver fault (a throw, or a result the value screen refused), not stated: the same fold,
* named `resolver_fault` on the arming fact. */
readonly capsFaulted?: boolean;
}
/** The words a leg may START from when it declares none: the two whose mode seats are the same (`modePolicyOf`), so the plan
* pair and the write gate a leg mounts never depend on whether its start arms. */
export type PermissionModeStartWord = Extract<PermissionMode, "default" | "auto">;
export declare const PERMISSION_MODE_START_WORDS: readonly PermissionModeStartWord[];
/** What a requested word arms as ({@link foldPermissionMode}). */
export interface PermissionModeFoldInput {
/** The word asked for — the caller's, a steer's, or the one a checkpoint row recorded; absent = none. */
readonly requested?: PermissionMode;
/** The parent's mode a child's declaration is clamped under; absent for a root leg. */
readonly ceiling?: PermissionMode;
/** The word a leg that starts fresh as a root starts from when it requests nothing (`RunnerDeps.permissionModeWhenUnset`);
* absent = `default`. Not given for a resume or a delegated leg. */
readonly whenUnset?: PermissionModeStartWord;
/** The deployment's arming facts; absent = not known yet (nothing folds against them, and no arming fact is answered). */
readonly arming?: PermissionModeArmingFacts;
}
/** The fold's answer. */
export interface PermissionModeFold {
/** The three-member answer (the manifest member, the steer's return value, the fold notice's detail). */
readonly receipt: PermissionModeReceipt;
/** The word the fold folded — present exactly when `receipt.foldedBy` is: what a fold notice names. */
readonly folded?: PermissionMode;
/** The leg's declaration: the requested word under the ceiling, or a root's start word — `default` when the start word is one
* the arming facts fold. What a checkpoint records and what the leg's plan seat reads. */
readonly declared: PermissionMode;
/** Auto mode's arming fact for the declared word (present when `arming` was given): `armed` exactly when `receipt.effective` is
* `auto`; otherwise the first arm that failed — `no_intent` (the word is not `auto`), `no_face`, `denied` (with the plane when
* the resolver named one), `resolver_fault`. */
readonly autoMode?: AutoModeArmFact;
}
/**
* What a requested permission mode ARMS AS — the one fold every leg's mode seat answers with ({@link PermissionModeController}
* calls it on every read), exported so a host can state what a word would arm as on its deployment without a copy of the rule:
* 1. the declaration: the requested word clamped under the ceiling (a child's), or — a leg that requested nothing and has no
* ceiling — the start word (`whenUnset`, given only for a leg that starts fresh as a root; else `default`);
* 2. the arming fold: `bypassPermissions` the deployment denies, and `auto` with no classifier face or under the deny bit, run
* `default` (`foldedBy` `operator_deny` / `face_absent`); a clamp the ceiling forced is `inherited_ceiling`.
* A root's start word is nobody's request: a start word the arming facts fold runs `default` with no `foldedBy` — nothing is
* announced for a word nobody asked for — and the leg declares `default`. A word somebody asked for (the caller, a steer, the
* word a checkpoint recorded because the leg ran under it) folds as it always does, announced.
* A static answer: an arming that fails at run time (the classifier's leg cannot be built) is not foreseen here.
* A `requested`, `ceiling` or `whenUnset` outside its set is refused (`config.permission_mode_invalid`, `detail.field` names which).
*/
export declare function foldPermissionMode(input: PermissionModeFoldInput): PermissionModeFold;
/** `RunnerDeps.permissionModeWhenUnset` read: absent, or a start word — anything else is refused by name, never read as `default`. */
export declare function screenPermissionModeWhenUnset(word: unknown): PermissionModeStartWord | undefined;
/** The arming facts the controller folds a declared mode against, bound once the deployment's caps resolved. */
export interface PermissionModeArming extends PermissionModeArmingFacts {
/** Arm the classifier for a leg whose effective mode became `auto` after prepare (a steer, a parent's live ceiling);
* idempotent. A failed arming leaves no classifier: a steer is rolled back and rejects with the failure; an arming a
* read started (no caller awaits it) reports it through {@link onArmFault}. */
readonly armAuto?: () => Promise<void> | void;
/** Where an arming a read of {@link PermissionModeController.current} started reports its failure. Observe-only: a throw
* or a rejection from it is contained. */
readonly onArmFault?: (error: unknown) => void;
}
/**
* The auto-mode classifier FACE a leg arms from — ONE reading for the arming fact ({@link PermissionModeArming.autoFacePresent}),
* the arming itself and the face this leg hands its children: the leg's own deployment face (`RunnerDeps.autoMode`), else
* the face its ancestor armed from, riding the trusted chain (`InheritedGate.autoModeFace`). A delegated child whose own
* runner wires no face is classified from its ancestor's deployment face — each of a subagent's actions goes through the
* same decision order as the parent's — on the child's own transcript and model; the child's own face wins where it has one.
*/
export declare function autoModeFaceOf(deps: Pick<RunnerDeps, "autoMode">, inherited: InheritedAutoModeFace | undefined): RunnerDeps["autoMode"];
/** The chain's carriage of that face (`InheritedGate` extends it). */
export interface InheritedAutoModeFace {
/** The auto-mode face the spawning leg armed from — opaque half, never serialized; present only when that leg's deps (or its own
* chain) carried one. A child whose runner wires no face of its own arms its classifier from it ({@link autoModeFaceOf}). */
autoModeFace?: RunnerDeps["autoMode"];
}
/** A live ceiling: the parent leg's own controller (`current` tracks the parent's steers), or a recorded word. A ceiling
* that can start something on a read (a controller, the engine's leg ceiling) also answers `observed` — the same word,
* read without starting anything; one without it is read through `current` on an observation too. */
export type PermissionModeCeiling = {
readonly current: PermissionMode;
readonly observed?: PermissionMode;
} | PermissionMode;
/**
* The one resolution of a leg's effective mode. `current` is derived on every read from three inputs —
* the requested word (the spec's, or the newest steer's whose arming has not failed), the ceiling (a parent's live controller, or the
* word a checkpoint recorded) and the arming facts — so a parent's steer reaches a running child on the
* child's next read with no forwarding, and nothing holds a stale answer.
*/
export declare class PermissionModeController {
private readonly requestedBySpec;
private readonly ceiling;
/** The steers that still count, oldest first: each is pending (its arming running) or took effect. A steer whose
* arming fails leaves the list; one that takes effect drops the older ones (a newer steer that took effect outranks
* them whatever they do next). */
private readonly steers;
private arming;
private readonly onFold;
private readonly whenUnset;
private prePlan;
/** `onFold` hears every fold with the word the fold FOLDED — what a fold notice names: the leg's own request for the
* ceiling fold (the word the parent's mode outranks); for the deployment's folds the declared word (the request after
* the ceiling, or — a leg that requested nothing — the word it inherited). `whenUnset`: the start word of a leg that
* starts fresh as a root ({@link foldPermissionMode}); its constructor's caller gives it to no other leg. */
constructor(requestedBySpec: PermissionMode | undefined, ceiling: PermissionModeCeiling | undefined, opts?: {
onFold?: (receipt: PermissionModeReceipt, folded: PermissionMode) => void;
prePlanMode?: PermissionMode;
whenUnset?: PermissionModeStartWord;
});
/** The declared word the leg had when a steer (or the model's `EnterPlanMode`) last moved it into `plan`, while it is
* there; a leg that started in plan has none, and a steer out of plan clears it. A checkpoint row records it. */
get prePlanMode(): PermissionMode | undefined;
/** {@link prePlanMode} as it runs: the word (already declared under the ceiling it was entered under) folded against the
* deployment's arming facts as {@link observed} folds the leg's own (an `auto` with no classifier face, or under the deny bit,
* runs `default`). An observation: read through the ceilings' `observed`, it starts no arming. Absent when the leg is not in a
* plan entered from another mode. */
get prePlanModeObserved(): PermissionMode | undefined;
/** The word the caller asked for right now: the newest steer that still counts, else the spec's. */
get requested(): PermissionMode | undefined;
private ceilingNow;
/** The leg's declaration ({@link PermissionModeFold.declared}) — what a checkpoint records. */
get declared(): PermissionMode;
/** Auto mode's arming fact as the fold answers it now — read once the arming facts are bound (the manifest's `autoMode`
* member); an observation, so it starts no arming. */
autoModeArmFact(): AutoModeArmFact;
private armedForAuto;
/** Contains the fault observer: its synchronous throw and its rejection both stop here. */
private readonly faultSeat;
/** The effective mode: declared, then folded against the arming facts. A read that finds the leg in `auto` with its
* classifier not yet armed (a parent's steer reached this child through the live ceiling) starts the arming — idempotent,
* not awaited: the call that observed the transition may still meet the person, the next one meets the classifier. A
* failure goes to {@link PermissionModeArming.onArmFault}; the leg then has no classifier, so its asks go on to the
* approval seat as under `default`. */
get current(): PermissionMode;
/** The effective mode read to REPORT it (a hook context), not to decide with it: the word {@link current} answers,
* reached through the ceilings' own `observed`, so neither this leg nor an ancestor starts its classifier's arming.
* A decision read is what starts it; an observation that did would arm a leg earlier than its own gate, and so move
* who answers the leg's next ask. */
get observed(): PermissionMode;
/** The effective mode this leg would run under were `word` asked for now — the same fold ({@link foldPermissionMode}) over the
* same ceiling (observed) and arming facts, with `word` as the request; an observation: nothing is steered, armed or announced. */
armsAs(word: PermissionMode): PermissionMode;
/** The three-member answer as it stands right now. */
receipt(): PermissionModeReceipt;
private receiptOf;
/** The fold over the leg's three inputs as they stand — one read for the receipt, the declaration and the arming fact. */
private answerOf;
/** Hand a fold to the observer with the word it folded (an answer without a fold says nothing). */
private announce;
/** The construction-time announcement: a fold the leg STARTS with (a ceiling fold, before any arming is bound). */
announceStart(): PermissionModeReceipt;
/** The ceiling's source moved to another leg (the parent session's next leg); `before` is this leg's receipt under the
* previous one. A ceiling fold the move produced — or changed — is announced, as the construction-time fold is. */
ceilingRebound(before: PermissionModeReceipt): void;
/** Bind the deployment's arming facts (once, after the caps resolved); announces a fold-back if one results, then lets
* those waiting for the mode to settle ({@link whenArmed}) go. */
bindArming(arming: PermissionModeArming): PermissionModeReceipt;
private readonly awaitingArming;
/** Run `then` once the arming facts are bound — from then on {@link observed} is the mode the leg runs under; before, a word the
* arming folds back (`auto` with no classifier, a relaxed mode the deployment denies) reads as itself. Now, when they already are.
* A throw from `then` is contained (a notice seat is host code). */
whenArmed(then: () => void): void;
/** A steer: the requested word changes; the arming fold is re-judged; a leg that became `auto` arms its classifier.
* When that arming fails the steer rejects with the failure, stops counting (the requested word is again the newest
* steer's that still counts, else the spec's — a failed arming never undoes another steer, and never leaves the leg
* in `auto` on its own word), and the arming may start again on the leg's next move into `auto`. */
steer(mode: PermissionMode): Promise<PermissionModeReceipt>;
}