@sema-agent/core
Version:
Stateless, task-oriented AI agent core
171 lines (170 loc) • 15.7 kB
TypeScript
/**
* The parent SPEC seat a run hands its children — the projection of the fields of the parent's own REBOUND spec
* that inherit copy-at-spawn (identity, process facts, deployment facts, the frozen question face) onto ONE value
* both delegation lanes copy onto a child spec: `ToolExecuteContext.parentSpecSeat` on the Task lane,
* `RunWorkflowToolDeps.parentSpecSeat` → `RunWorkflowOptions.parentSpecSeat` on the workflow lane. Minted once per
* prepare (the inherited-gate phase); applied by ONE function ({@link applyParentSpecSeat}) so the two lanes
* cannot drift on which fields travel or on the priority between a child's own value and the parent's.
*
* The checkpoint seat (`./checkpoint-seat.ts`) is the same shape for one field; this seat carries the rest.
*/
import type { OnQuestion } from "./ask-question.js";
import type { ModRegistration } from "./mods/kernel/index.js";
import type { EngineDollar } from "./mods/dollar.js";
import { type TaskSandboxSettings } from "./command-sandbox.js";
import type { ToolExecuteContext } from "./tool-spec.js";
import type { FastModeLeg } from "./runner/fast-mode-seat.js";
import type { TaskSpec } from "./types.js";
import { type ProjectSeat } from "./project-seat.js";
/** The fields of a spec the seat carries — one `Pick`, shared by the mint's input and the apply's target. */
export type ParentSpecSeatFields = Pick<TaskSpec, "principal" | "isolationScope" | "oneShot" | "clientContext" | "onQuestion" | "mods" | "additionalDirectories" | "additionalReadDirectories" | "envFacts" | "sandbox" | "memoryPersistenceCapable" | "classifyAllShell" | "memory" | "compaction" | "skillListingBudgetFraction" | "skillListingMaxDescChars" | "fileHistory" | "projectMemory" | "promptForm" | "promptBinding" | "promptLocale" | "advisorModel" | "attachments" | "language" | "instructionFamily" | "fastMode" | "project">;
/**
* The seat a run hands its children. Every member is the parent's own value, frozen at mint (arrays copied and
* frozen; the facts object copied). Members present iff the parent carries them — an absent member is "nothing to
* inherit", never a value.
* · `principal` — the end-user identity (design/62: inherits verbatim, a worker cannot delegate under another).
* · `isolationScope` — the parent's working-state partition, the same shape and law as `principal`: a child works
* inside the scope its parent works in, so its rows, offloads and parked approvals land in the parent's bucket.
* · `oneShot` — the process fact ("no later turn"): only `true` travels; it is a REMOVAL (see the apply law).
* · `clientContext` — the user's TZ/email facts (the child's environment block localizes the same way).
* · `onQuestion` — the parent's FROZEN question face (`spec.onQuestion ?? deps.onQuestion`, the value the parent's
* own AskUserQuestion resolves at): the child's question tool MOUNTS on it, so without it the child has no tool.
* · `mods` — the parent's TASK seat of the mods bus (`spec.mods`, the request-level registrations a host mounts from
* the user's settings). A deployment's `RunnerDeps.mods` already serve every leg; the task seat did not, so a
* `classic.Stop` handler a user wired ran for the leader and never for its teammates (CC runs one chain for the
* session and its subagents, the event carrying `agentId`). A child dispatches the travelled registrations as its
* own task seat (its events carry the child's identity); an ancestor's chain still rides the constraint fold, and
* collapses into the child's own phase 1 when the installation is the same. Same law as `onQuestion`: a child's
* own value wins, the seat fills an unset one.
* · `additionalDirectories` / `additionalReadDirectories` — the fs-fence widening (deployment property).
* · `envFacts` — the sandbox facts (profile / egress / scratchpad).
* · `sandbox` — the command sandbox requirement, as the parent's own prepare judged it: a FLOOR, merged with the child's own
* requirement toward the stricter side, member by member (`mergeChildSandbox`) — never the fill law, so a child cannot
* author a looser sandbox than its parent runs under, and may author a stricter one.
* · `memoryPersistenceCapable` — the deployment's DECLARED persistence statement: `false` is a REMOVAL (floor),
* `true` a default a child's own declaration may narrow.
* · `classifyAllShell` — the request's "no shell allow entry clears a call in `auto`" declaration: only `true` travels and
* it is a REMOVAL (the child's shell allow entries stand down in `auto` as the parent's did; a child's own `false` cannot
* lift it).
* · `memory` — the request-level "memory is off" FACT, `{ enabled: false }` and nothing else of the declaration (the clamp
* table's `memory.enabled` row; present only when the parent stated `enabled: false`): a REMOVAL (floor) that
* REWRITES the one member on the child's own memory declaration — its scopes and knobs are the child's.
* · `compaction` — the request's CONTEXT-MANAGEMENT settings (autoCompact / manualCompact / withinTask / reserve / keepRecent /
* instructions / attachWorkingFiles / staleToolResultOffload). One set of settings for the
* whole delegation tree, measured per leg against the leg's OWN window: the numbers are repaired against the
* child's model by the same sanitizer every leg runs (`sanitizeCompactionSettings`), so a parent's 128k-tuned
* reserve does not have to be re-tuned to be legal on a 6k child. A seat's `false` is NOT a removal — the
* reference implementation shares one settings object down the tree rather than flooring children, and a
* child that authors its own settings wins the whole object (an ORDINARY seat member).
* · `skillListingBudgetFraction` / `skillListingMaxDescChars` — the listing-budget knobs, the same shape for the
* same reason: a fraction the parent tuned is a fraction OF EACH LEG'S OWN window, so it travels as a number
* and every leg multiplies it by its own.
* · `fileHistory` — the request's file-history off switch (`"disabled"`, its only word), for the edits its delegates
* make on its behalf too. An ORDINARY member (fill law); with one word no child can author it back on.
* · `projectMemory` — the request's off switch for the deployment's project context (`"disabled"`, its only word): the
* delegates that work for it read no project context either. An ORDINARY member (fill law), the `fileHistory` shape.
* · `promptForm` — the host form of the system prompt (`"minimal"`, its only word: the core-behavior band is out). A
* host's product choice for the whole delegation tree, so every engine-built child (both delegation lanes and the
* observer sidecar) composes the same set of sections. An ORDINARY member (fill law).
* · `promptBinding` — the binding (a deployment's scenario name), a prompt selector value. A child composes its
* parent's center artifact, so its overlays' `when.binding` reads the same binding. An ORDINARY member (fill law).
* · `promptLocale` — the rendering of the catalog text (`"zh-Hans"`, its only word), a prompt selector value: the delegates
* that work for a run read the engine's text in the run's locale. An ORDINARY member (fill law); not a floor, so no
* clamp row.
* · `advisorModel` — the person's advisor setting: every engine-built child judges it against its OWN model (an advisor
* weaker than the child's model does not attach there). An ORDINARY member (fill law); the observer sidecar takes it and
* excludes the tool by name.
* · `attachments` — the request's attachment-lane declaration, WHOLE (which frames ride the legs' requests and which are
* switched off): one declaration for the delegation tree, so a lane the parent turned on or off is on or off for the
* delegates that work for it. An ORDINARY member (fill law): a child that authors `attachments` at all keeps exactly what it
* authored, never half to the parent.
* · `language` — the person's reply language. It reaches every engine-built child; a named teammate states it to its model
* and an ordinary delegated child does not (the leg's own judgment, `language-frame.ts`). An ORDINARY member (fill law).
* · `instructionFamily` — the instruction-file family the deployment declared: the delegates read the same names in the
* directories they access. Its own member, not a lane of `attachments`, so a child that authors `attachments` still
* inherits it. An ORDINARY member (fill law): a child that declares a family keeps exactly that one.
* · `fastMode` — the person's fast-mode request: the delegates that work for a run ask for fast speed as the run does (the
* reference copies its parent's `fastMode` into a subagent when it spawns it: (cli321.js:292312) "fastMode:r.options.fastMode"), each served only where its own model's entry declares it, and a child
* leg reads its tree's cooldown (`fast-mode-seat.ts`). It is what the minting leg asks for WHEN a child is started — the leg's
* word as the stream verb (`TaskStream.setFastMode`) last set it ({@link bindParentSpecSeatFastMode}), the spec's word before a
* leg is bound — so a toggle reaches every child started after it. Not a clamp: either word travels as written. An ORDINARY
* member (fill law): a child's own word stands.
* · `project` — the parent leg's project SEAT: its verdict's id with the texts that belong to it (`SessionProjectVerdict.seat`; a
* parent judged by its marker alone hands `{ id }`), bound once after `resolveSessionProject` ({@link bindParentSpecSeatProject}).
* Every spawner hands it on `RunInternals.parentProject` as the child's DEFAULT (its id used only when the child declares no
* `project` and its own workspace has no marker; its texts only when the child's verdict is its id) — and a waker hands its own
* to the agent it wakes. Deliberately NOT copied onto `TaskSpec.project` by {@link applyParentSpecSeat}: a declaration is compared
* with the child's marker, and a child's own workspace marker must beat the inherited default rather than mismatch against it.
*/
export interface ParentSpecSeat {
readonly principal?: string;
readonly isolationScope?: string;
readonly oneShot?: true;
readonly clientContext?: TaskSpec["clientContext"];
readonly onQuestion?: OnQuestion;
readonly mods?: readonly ModRegistration<EngineDollar>[];
readonly additionalDirectories?: readonly string[];
readonly additionalReadDirectories?: readonly string[];
readonly envFacts?: TaskSpec["envFacts"];
readonly sandbox?: TaskSandboxSettings;
readonly memoryPersistenceCapable?: boolean;
readonly classifyAllShell?: true;
readonly memory?: {
readonly enabled: false;
};
readonly compaction?: TaskSpec["compaction"];
readonly skillListingBudgetFraction?: number;
readonly skillListingMaxDescChars?: number;
readonly fileHistory?: "disabled";
readonly projectMemory?: "disabled";
readonly promptForm?: "minimal";
readonly promptBinding?: string;
readonly promptLocale?: TaskSpec["promptLocale"];
readonly advisorModel?: TaskSpec["advisorModel"];
readonly attachments?: TaskSpec["attachments"];
readonly language?: string;
readonly instructionFamily?: TaskSpec["instructionFamily"];
readonly fastMode?: boolean;
readonly project?: ProjectSeat;
}
/** Refuse (by name, `config.deps_retired_key`) a seat that still carries a retired member. Read at every door a seat enters
* by hand: the ctx reader, the apply, and the send lane's waker clamps. */
export declare function assertParentSpecSeatCurrent(seat: object | undefined): void;
/** Bind the seat a leg minted to that leg's fast mode: from now on the seat's `fastMode` is what the leg asks for at the moment it
* is read — a child started after a toggle is filled with the toggled word. Once per seat, by the leg that minted it. */
export declare function bindParentSpecSeatFastMode(seat: ParentSpecSeat, leg: Pick<FastModeLeg, "requested">): void;
/** Bind the seat a leg minted to that leg's resolved project seat (`sessionProject.seat`): from now on the seat's `project` is the
* leg's (`undefined` when the leg has no verdict). Bound once per seat, after `resolveSessionProject` runs, so mount validation still
* runs before the marker walk. */
export declare function bindParentSpecSeatProject(seat: ParentSpecSeat, project: ProjectSeat | undefined): void;
/** Mint the seat off the parent's REBOUND spec and its frozen question face (spec over deps — the caller resolves it once,
* the same value the parent's own question routing reads). Absent fields stay absent; `oneShot` only when `true`. `fastMode` is
* read when it is read: the bound leg's ask ({@link bindParentSpecSeatFastMode}) — `undefined` while the leg asks for nothing and
* its spec said no word —, the spec's word before a leg is bound. */
export declare function parentSpecSeatOf(spec: Omit<ParentSpecSeatFields, "onQuestion">, frozenOnQuestion: OnQuestion | undefined): ParentSpecSeat;
/**
* Apply the seat to a child spec — ONE law for every member, both lanes:
* a value the child spec already carries WINS; the seat FILLS an unset one; the four REMOVAL values
* (`oneShot: true`, `memoryPersistenceCapable: false`, `classifyAllShell: true`, `memory: { enabled: false }`) land
* UNCONDITIONALLY.
* "Already carries" is the child's own authorship — a deployment baseline, a trusted script, an agent definition's
* fold (the Task lane folds the definition's `memoryPersistenceCapable` before applying; the workflow lane applies at
* the launch site AFTER the agentType fold) — so a definition may narrow a parent `true` to `false`, a baseline-pinned
* principal stands, and nothing a child can author lifts a removal. Arrays and the facts object are copied per child
* (a retained child's frozen snapshot must not alias the parent's seat). Returns a NEW object; `child` is not mutated.
* No seat (a tool running outside a Runner task) ⇒ the child spec is returned as is.
*/
export declare function applyParentSpecSeat<S extends ParentSpecSeatFields>(child: S, seat: ParentSpecSeat | undefined): S;
/** The ctx keys that restate a seat member as THIS run's own fact (tools read them for scope / receipts / clamps). `isolationScope` is the
* ctx's RESOLVED one (`isolationScopeOf` of the run's spec — its member, else its principal), so it is compared with the seat's resolution. */
declare const SEAT_FACTS_ON_CTX: readonly ["principal", "isolationScope", "oneShot", "onQuestion", "memoryPersistenceCapable"];
/**
* The seat a delegation boundary reads off a trusted ctx — ONE reader for both delegation tools. A Runner-filled ctx
* always carries the seat beside the run's own facts, and the two agree by construction (one mint). A HAND-BUILT ctx
* (a caller invoking a delegation tool's `execute` directly) that carries any of those facts WITHOUT the seat, or with
* a seat that disagrees with them, is REFUSED (`config.parent_spec_seat_missing`): spawning a principal-less child from a
* principal-bearing caller would offload into the shared namespace and re-key its journal — a silent tenant narrowing,
* never a fallback. A ctx with neither (a tool running outside a Runner task) hands down no seat.
*/
export declare function parentSpecSeatOfCtx(ctx: Pick<ToolExecuteContext, "parentSpecSeat" | (typeof SEAT_FACTS_ON_CTX)[number]>): ParentSpecSeat | undefined;
export {};