UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

529 lines (528 loc) • 37.5 kB
import type { AgentMessage, ExecutionEnv, ReadFloor } from "../../internal/harness-types.js"; import type { TaskAccess, TaskRegistry } from "../task-registry.js"; import type { SessionMeasureSeat } from "./lifecycle-stations.js"; import type { AssistantMessage, Message, Model, Usage } from "../../internal/llm.js"; import type { CwdRef } from "../../tools/fs/fs-shared.js"; import { type PermissionResult, type ToolCallRequest } from "../tool-policy.js"; import type { ClassicEventBase, HookEnvCapabilities, HookInvocationIdentity, PermissionDeniedPayload, SubagentStartResult, UserPromptSubmitEvent } from "../hooks.js"; import type { ClassicEventMap, ClassicEventName } from "./classic-events.js"; import type { PermissionMode } from "../ask-origin.js"; import type { RunnerDeps } from "../runner-deps.js"; import type { TaskSpec } from "../task-spec.js"; import { type ModAnswerCheck, type ModAnswerRanks, type ModBus, type ModCallEntry, type ModEventName, type ModMountedHandler, type ModDispatchOutcome, type ModEventPayload, type ModRegistration } from "./kernel/index.js"; import { type SourcedOverlay } from "../../prompt-assembly/overlay.js"; import type { BandId } from "../../prompt-assembly/catalog/schema.js"; import type { ModFrame, ModParticipant } from "./kernel/dispatch.js"; import type { ModOrigin } from "./kernel/index.js"; import { type InputAuthor } from "../input-author.js"; import type { SystemInjectionPriority } from "../task-notification.js"; import { type RetiredNameView } from "../tool-name-aliases.js"; import { type EngineDollar, type ModelCompleteRequest, type ModelCompleteResult, type ModSeatView, type SessionUsage, type SessionVersion, type TurnAbortRef, type TurnAbortVerdict } from "./dollar.js"; import { type LegModSeats } from "./host.js"; export { listLegModSeats, type LegModSeats } from "./host.js"; import { type SkillScopes } from "./spec-seats.js"; import { type DelegationOwnerSeat } from "../runner/delegation-owner.js"; /** * What the engine's core answers at the bottom of every classic chain: the engine itself has nothing to add. * Frozen and empty, so it reads as "no opinion" in every classic station's answer form, and a handler that * builds on it (`{ ...(await next(e)), additionalContext }`) builds a well-formed answer. */ export declare const ENGINE_CORE_ANSWER: Readonly<Record<string, never>>; /** The classic chains' bottom. */ export declare function engineCore(): Readonly<Record<string, never>>; /** The leg's bus seat, as the stations read it. */ export type LegModBus = Pick<ModBus, "hasHandlers" | "dispatch">; /** Does a seat raise `event` — bound, and a handler hangs on it? Every station entry reads this first, synchronously. */ export declare function seatHears<B extends { readonly bus: Pick<ModBus, "hasHandlers">; }>(binding: B | undefined, event: ModEventName): binding is B; /** The `detail` member of a notice a leg raises about itself: the leg's own task id, read from its prepare's one mint ({@link legTaskIdOf}), never from the host's declaration. */ export declare function legNoticeTaskId(leg: { readonly taskId: string; }): { readonly taskId: string; }; export interface LegEvents { /** The event it opens on — present on a delegated leg. */ readonly start?: "classic.SubagentStart"; /** The event it raises when it would otherwise end. */ readonly stop: "classic.Stop" | "classic.SubagentStop"; /** The event it raises on each window of an assistant message it shows — present on a top-level leg only (a delegated leg's * stream is its parent's progress view, not a display of its own). */ readonly display?: "classic.MessageDisplay"; } /** * Both ends of a leg and its display, from the delegation fact alone (a child resumed from its checkpoint keeps it): a delegated * leg opens on `classic.SubagentStart`, ends on `classic.SubagentStop` and shows nothing of its own; any other opens on nothing, * ends on `classic.Stop` and raises `classic.MessageDisplay` over what it shows. Not the leg * kind (a resumed leg's kind reads `"resume"` whoever it runs as), and not who wrote the objective: whether an input passes * the prompt screen is the input's own fact, its author's row (`isScreened`, input-author.ts) — a delegator's words are judged * at the delegator's gate (`classic.PreToolUse` on the delegating call), an operator's resume of a child is screened. */ export declare function legEventsOf(identity: Pick<HookInvocationIdentity, "isDelegatedChild"> | undefined): LegEvents; /** * The args as a judging handler receives them: the gate pass's own immutable value ({@link ownArgs} — the value itself when * the gate already took it, which is every call the gate raises an event over), so the bytes a handler judges are the bytes * that run — an in-place edit throws instead of moving what executes, or what a handler further down judges (a rewrite is * an answer's `updatedInput`). A graph the copy refuses is handed as is (the gate refuses such args at its entry). */ export declare function judgedInputOf(args: unknown): unknown; /** One link of a leg's chain as a constraint entry names it: a registration the leg's admission mounted, with the handlers it hung. */ export interface ModChainLink { readonly registration: ModRegistration<EngineDollar>; readonly handlers: readonly ModMountedHandler[]; } /** * A bus's chain identity: the registrations its admission MOUNTED (a refused one judges nothing there), in run order, each * with the handlers it actually hung (pattern, matcher, observe, `.catch`, in hang order). Two legs that offered the same * registrations but admitted — or hung — differently are different chains: an inherited entry collapses into a child's phase * 1 only when the child mounted the very same. A handler's code is not compared (each leg's `register` builds its own * closures); what it was hung on is. Every engine admission records it once ({@link chainOfBus}). */ export declare function admittedChainOf(bus: Pick<ModBus, "records" | "mounted">, spec: Pick<TaskSpec, "mods">, deps: Pick<RunnerDeps, "mods">): readonly ModChainLink[]; /** The chain identity a bus's admission recorded, or `undefined` for a bus no engine admission mounted (its chain cannot be * read, so it is the same chain as none). */ export declare function chainOfBus(bus: object): readonly ModChainLink[] | undefined; /** Whether two chains are the same links: the same registration objects, in the same order, having hung the same handlers. */ export declare function sameModChain(a: readonly ModChainLink[], b: readonly ModChainLink[]): boolean; /** * Whether the leg's chain JUDGES a tool call: a judging handler on either event a call is judged on — `classic.PreToolUse` * (the gate's phase 1) or `tool.check` (the gate's verdict read). Such a chain is what a leg hands its children as a * screening constraint, and what a child's own gate stands in for when it mounted the same. */ export declare function chainJudges(bus: LegModBus): boolean; /** How an inherited installation's question is settled: under the context its installation froze (its approver, its durable * mandates, its classifier), never at this leg's approver — whichever event raised it (`classic.PreToolUse` at the gate's phase * 1, `tool.check` at its verdict read). An allow carrying `updatedInput` is a person's approval of an edit; an ask is one the * settlement floated (the call is marked for the park). */ export type InstallationAskSettlement = (ask: Extract<PermissionResult, { action: "ask"; }>, call: ToolCallRequest, signal: AbortSignal | undefined) => Promise<PermissionResult>; /** The question an installation's settlement floated on an EARLIER look at the call, as it stands over a later look that does not ask: a bare allow on rewritten bytes never lifts it, only that installation's approver answering over the bytes in front of it does; undefined when it marked nothing. */ export type InstallationStandingQuestion = (call: ToolCallRequest) => Extract<PermissionResult, { action: "ask"; }> | undefined; /** An inherited installation as a leg's gate raises its judging events on it (`classic.PreToolUse` at phase 1, `tool.check` at the * verdict read): the bus that mounted that chain, which of its handlers judge here, the capability face of the environment it was * installed against (the `env` of its `classic.PreToolUse` e), how its question is settled, and the question it deferred standing. */ export interface InheritedInstallation { readonly bus: LegModBus; readonly judges: (p: ModParticipant) => boolean; readonly env?: HookEnvCapabilities; readonly settle: InstallationAskSettlement; readonly standing?: InstallationStandingQuestion; } /** An inherited chain entry as its installation identity reads it (the installation is absent on a caller-policy entry). */ export interface InstallationEntry { readonly installation?: LegModBus; readonly onAsk?: unknown; readonly durableMandate?: boolean; readonly contentMandate?: boolean; readonly hookEnv?: unknown; readonly autoMode?: { readonly decider: unknown; }; } /** A leg's own installation context: its chain identity, its frozen approver, its two durable mandates, the environment its * phase 1 runs in, its classifier instance. */ export interface LegInstallation { readonly chain: readonly ModChainLink[]; readonly onAsk: unknown; readonly durableMandate: boolean; readonly contentMandate: boolean; readonly hookEnv: unknown; readonly decider: unknown; } /** * Whether an inherited entry IS a leg's installation — the ONE installation identity: the chain is read off the entry's own * installation; a caller-policy entry, or one whose bus no engine admission mounted, is no leg's installation. The rest is * the context its questions are settled in ({@link askApproverIdentity}, the two durable mandates, the environment, the classifier). */ export declare function sameInstallation(pc: InstallationEntry, leg: LegInstallation): boolean; /** * Whether a leg's own gate stands in for an inherited entry: the leg's chain judges, and the entry is the leg's installation * settled with no durable mandate — its phase 1 then judges the call with the same chain, and its questions go to the same * approver under no mandate, so the entry adds nothing on either judging event. Whether the gate raises the entry's * `classic.PreToolUse` and `tool.check` is this one test (an entry it does not hold for is judged under its own context on both: * a second judgment, never a lost one). */ export declare function standsInFor(pc: InstallationEntry, leg: Omit<LegInstallation, "durableMandate" | "contentMandate">, legChainJudges: boolean): boolean; /** * Why an inherited chain cannot be held, or `undefined`. Every entry is ONE of two kinds — a caller policy (`policy`, folded into * the leg's restriction chain) or a screening installation (`installation`, the bus an engine admission mounted: a leg's own, or * {@link admitModChain}'s, whose judging events the leg's gate raises). An entry naming both, or neither, or an installation no * engine admission mounted has no way to judge the leg's calls. Read where the chain enters a leg — before a resume's claim and * at the leg's prepare — so it is refused, never run without the judgment. */ export declare function chainEntryFault(entries: ReadonlyArray<{ readonly policy?: object; readonly installation?: object; }>): string | undefined; /** * The inherited installations a leg's gate judges its calls on after its own bus — the rule's one home, read by both judging * events (`classic.PreToolUse` at phase 1, `tool.check` at the verdict read). Every screening entry is one installation, raised * whole in the chain's order, except one the leg's own gate stands in for (`standsIn`, {@link standsInFor}). Raised whole because * a handler's answer depends on the chain it sits in (an outer handler may answer without calling `next`, or rule on what an * inner one answered), so a registration the leg also mounts in a chain of its own judges again inside the ancestor's chain (a * second judgment, never a lost one). Each carries the environment face its installation was installed against (`envOf`) and * its entry's settlement of a question (`settleOf`: an installation's `ask`, on either event, goes to the regime it froze) and the question it deferred on an earlier look (`standingOf`, left standing by a later look that does not ask). * Observe handlers never take part. A chain with a malformed entry is refused (`config.mods_invalid`, {@link chainEntryFault}). */ export declare function inheritedInstallations<E extends InstallationEntry & { readonly policy?: object; }>(entries: readonly E[], standsIn: (pc: E) => boolean, envOf: (pc: E) => HookEnvCapabilities | undefined, settleOf: (pc: E) => InstallationAskSettlement, standingOf?: (pc: E) => InstallationStandingQuestion): readonly InheritedInstallation[]; /** The members every classic `e` of a leg carries: the identity envelope, the delegated leg's `agentId`, the leg's observed mode. */ export declare function classicEventBase(identity: HookInvocationIdentity | undefined, permissionMode?: PermissionMode): ClassicEventBase; /** * Raise an observation event (a skip-on-failure event whose answer no station reads): no handler, no dispatch. * Its failures are the bus's to report; a rejected dispatch (an engine fault, never a handler's) is swallowed — * an observation must never change what it observes. The `e` is the event's own, as {@link ClassicEventMap} types it. */ export declare function observeClassic<K extends ClassicEventName>(bus: LegModBus, event: K, e: ClassicEventMap[K]["e"], signal: AbortSignal | undefined): Promise<void>; /** The frames and origin a raise runs under (an extension's `$` call's), so the caller's own handlers stay out of it. */ export interface RaisedUnder { readonly frames: readonly ModFrame[]; readonly origin: ModOrigin; } /** * Raise a classic event whose answer the station reads: `undefined` when no handler hangs on it (the station * runs as if the bus were not there), else the dispatch outcome. A rejection is an engine fault, never a * handler's (handlers fail into the outcome); a decision station fails closed on it, an observation swallows it. * The `e` is the event's own, as {@link ClassicEventMap} types it; a decision event names its answer ranks. */ export declare function dispatchClassic<K extends ClassicEventName>(bus: LegModBus, event: K, e: ClassicEventMap[K]["e"], options: { readonly signal?: AbortSignal; readonly checkAnswer?: ModAnswerCheck; readonly ranks?: ModAnswerRanks; readonly participant?: (p: ModParticipant) => boolean; readonly raisedUnder?: RaisedUnder; }): Promise<ModDispatchOutcome | undefined>; /** The answer form of a classic event whose answer is an object of optional string members (`block`, `additionalContext`, …). */ export declare function stringMembersAnswer(event: string, members: readonly string[]): (answer: unknown) => string | undefined; /** The string members of an answer the station reads (a member of any other type reads as absent — the answer check has already refused it). */ export declare function stringMembersOf<M extends string>(answer: unknown, members: readonly M[]): { [K in M]?: string; }; /** The clause a fail-closed station puts in its sentence for the handler that failed it: `crashed (extension "x" threw boom)` * — what it did, who it is and the bus's reason. */ export declare function failedHandlerClause(f: Pick<Extract<ModDispatchOutcome, { kind: "failed"; }>, "registration" | "cause" | "reason">): string; /** * The PermissionDenied station, the one body every refusal exit raises: the leg's `classic.PermissionDenied` handlers, then a host's * own raw observer (a host driving the tool gate) as one more observe handler of the event on a bus of its own, so every observer * of a deny runs under the station's columns (budget, skip on failure, grace past an abort) and none can hold the deny it reports. */ export declare function observePermissionDenied(input: { readonly legBus: LegModBus | undefined; readonly host?: { readonly observe: (payload: PermissionDeniedPayload) => void | Promise<void>; readonly onFailure: (err: Error) => void; }; readonly payload: PermissionDeniedPayload; readonly signal: AbortSignal | undefined; }): Promise<void>; /** What a prompt's screen came to, as the four entrances read it: `text` is what the entrance delivers (the prompt as it * came, or as `prompt.submit` handed it on — `rewrittenBy` then names who changed it, in the order they did); `block` the * refusal (a `prompt.submit` drop, or `classic.UserPromptSubmit`'s block); `reply` the answer an extension gave in the * model's place where the entrance takes one ({@link PROMPT_ENTRANCES}): `text` enters, its turn answered by `reply`. */ export type PromptScreen = { readonly kind: "answered"; readonly text: string; readonly rewrittenBy?: readonly string[]; readonly block?: string; readonly reply?: { readonly text: string; readonly by: string; }; readonly additionalContext?: string; } | Extract<ModDispatchOutcome, { kind: "failed"; }> | { readonly kind: "aborted"; }; /** Why a changed text may not stand, as the sentence the refused handler is told, or `undefined` when it may. */ export type TextRefusal = (text: string) => string | undefined; /** Who changed a text a chain carried, read off the chain as it runs (a station's `checkHandOn` and `checkAnswer` feed it). A * station that judges a change passes its `refuse`: a refused change is named by no one and moves nothing, so what the chain * carries is still the text the last accepted change left — the retry of a refused text (a `.catch` handing it on again) is a * change again, and is refused again. */ export interface TextChanges { /** A handler handed `text` on (down): it changed the text when that differs from what the previous hand-on (or the * original) carried. `undefined` — taken (a change or none); a sentence — the change `refuse` refused. */ handedOn(by: string, text: string, refuse?: TextRefusal): string | undefined; /** A handler answered `text` (up): it changed the text when that differs from what its `next` answered (`below`) or, when * it answered without one, from the text it was handed. `undefined` — taken; a sentence — the change `refuse` refused. */ answered(by: string, text: string, handed: string, below: string | undefined, refuse?: TextRefusal): string | undefined; /** The handlers that changed the text, in the order they did (down before up), each named once. */ rewrittenBy(): readonly string[]; } /** The one reading of who changed a text, for every station whose answer is a rewritten text (`session.receive`, * `prompt.submit`): a handler is named for the change it made — handing a different text on, or answering a different text * than the one that came up to it — never for carrying another handler's change up. */ export declare function textChanges(original: string): TextChanges; /** The stations a prompt's screen is — `prompt.submit`, and `classic.UserPromptSubmit` raised in its bottom. The one list: * the entrances raise these and nothing else on a prompt, and every reading of "is the screen heard" reads it, so a station * added here is heard by all of them. Both are the engine bus's (`MOD_EVENT_TABLE`). */ export declare const PROMPT_SCREEN_STATIONS: readonly ModEventName[]; /** The four entrances' one predicate: does the leg hear a prompt's screen — `prompt.submit`, or `classic.UserPromptSubmit` * raised in its bottom? The bus's reading of {@link promptScreenHeard}; {@link promptScreenDeclaredBy} is the registrations'. */ export declare function promptScreenHasHandlers(bus: LegModBus): boolean; /** * Whether a set of registrations declares a prompt screen: some `uses.events` pattern — an event name or a `<prefix>.*`, * expanded on the engine bus as admission expands it (`expandOnSide`) — selects `prompt.submit` or `classic.UserPromptSubmit` * ({@link PROMPT_SCREEN_STATIONS}). The reading for a host that holds registrations before any bus is admitted (an acceptance * seat that must know, before it writes a byte, whether the prompt will be screened); the bus's reading is * {@link promptScreenHasHandlers} over what the admitted registrations hung. A declaration is the upper bound on what a * registration hangs, so a registration that declares a station and hangs nothing on it is declared here and unheard there. * A pattern admission would refuse (not a name, not a list, a name no bus reads) selects nothing here — admission refuses the * registration itself, with `config.mods_invalid`. */ export declare function promptScreenDeclaredBy(registrations: readonly { readonly uses: { readonly events: readonly string[]; }; }[]): boolean; /** A screened input as the screen raises it: its author as judged, the tier a steer is taken at (its `priority`, defaulted — * what decides whether the steer entrance takes a reply), and for an extension's prompt the caller and its `$` call. */ export interface PromptScreenInput { readonly author: InputAuthor; readonly tier?: SystemInjectionPriority; readonly extension?: string; readonly raisedUnder?: RaisedUnder; /** The leg's bracket around the whole screen (`Prepared.hookScreens.prompt`): the screen is framed (`hook_progress`) for as * long as it runs. Absent where the screen has no stream to ride (a wake's message, screened before its leg exists). */ readonly whileScreened?: <T>(subject: Pick<UserPromptSubmitEvent, "source" | "inputId">, screen: () => Promise<T>) => Promise<T>; } /** * A prompt's screen at one of the four entrances (objective, live steer, a wake's message before its claim, a parked steer * redelivered): `prompt.submit` over `e` with the prompt as `text`, its bottom raising `classic.UserPromptSubmit` on the text * handed down; `undefined` (nothing raised) when neither is heard ({@link promptScreenHasHandlers}). A decision event: a * handler that throws, runs past its budget or breaks the site's contract ends the screen `failed`, and every entrance fails * closed on it; a cancelled screen ends `aborted` at once; a dispatch the engine could not run is `failed` too. What the * classic screen refused (its block, failure or cancel) is final — a `prompt.submit` handler above it does not undo it. * `input` ({@link PromptScreenInput}) rides `prompt.submit`'s `e` (both stations raised under its `$` call, when it has one). */ export declare function screenUserPrompt(bus: LegModBus, e: UserPromptSubmitEvent, signal: AbortSignal | undefined, input?: PromptScreenInput): Promise<PromptScreen | undefined>; /** * Raise `classic.SubagentStart` as a delegated leg opens on its objective (undefined when no handler hangs on it): the * context the chain answers. It never keeps the child from starting — a handler that fails is skipped and reported by * the bus (and counted on the leg's station receipt, station-receipt.ts, with the raise), a cancel ends the wait at once (the leg's own cancel then ends the child), and a dispatch the engine itself * could not run is no answer. */ export declare function openSubagent(bus: LegModBus, identity: HookInvocationIdentity, permissionMode: PermissionMode | undefined, signal: AbortSignal | undefined): Promise<SubagentStartResult | undefined>; /** The three words a `tool.check` verdict speaks. */ export declare const TOOL_CHECK_DECISIONS: readonly ["allow", "ask", "deny"]; export type ToolCheckDecision = (typeof TOOL_CHECK_DECISIONS)[number]; /** * The gate's standing verdict as the bottom of the `tool.check` chain answers it — what a handler reads from `next(e)`. * Never `deny` (a standing refusal raises nothing). On an ask: its classes, and `mandated` — true when an `allow` * answer cannot clear it at this point of the gate. `ceiling` mirrors `e.ceiling`. Read-only metadata: the gate reads * the answer's `decision` and `reason` and nothing else of it. */ export interface ToolCheckProjection { readonly decision: "allow" | "ask"; readonly reason?: string; readonly classes?: readonly string[]; readonly mandated?: boolean; readonly ceiling?: "ask"; } /** What one `tool.check` raise came to: the chain's verdict (`by` = the registration whose answer the chain returned; * absent when no handler spoke and the gate's own verdict came back up), a handler's failure, or a cancel. */ export type ToolCheckOutcome = { readonly kind: "answered"; readonly decision: ToolCheckDecision; readonly reason?: string; readonly by?: string; } | Extract<ModDispatchOutcome, { kind: "failed"; }> | { readonly kind: "aborted"; }; /** * Raise `tool.check` over the gate's standing verdict (undefined when no handler hangs on it — nothing is raised). A * refusing event: a handler that throws, runs past its budget or answers out of the site's form ends the raise * `failed`, a cancel ends it `aborted`, and the gate refuses the call on either. A dispatch the engine itself could not * run is `failed` too. `judges` = which handlers take part (absent ⇒ every handler on the bus: the leg's own raise; an * inherited installation's raise passes its {@link InheritedToolCheck.judges}). */ export declare function raiseToolCheck(bus: LegModBus, e: ModEventPayload, projection: ToolCheckProjection, signal: AbortSignal | undefined, judges?: (p: ModParticipant) => boolean): Promise<ToolCheckOutcome | undefined>; /** What a `prompt.compose` raise came to: each source class's overlays in application order, and the operator lines * for every handler whose answer was skipped. */ export interface PromptComposeOutcome { readonly deploy: readonly SourcedOverlay[]; readonly task: readonly SourcedOverlay[]; readonly warnings: readonly string[]; } /** * Raise `prompt.compose` — the collection point of the deploy and task source classes' overlays — over the leg's * bus (nothing is raised when no handler hangs on it). A collecting event: a handler's contribution is what its * answer adds after what its `next(e)` returned, and what `next(e)` returned must stand unchanged, in order, at the * head of its answer — a handler that answers without its `next(e)` (or before it returned), rewrites or removes a * lower contribution, or adds an overlay the band table does not grant its seat's class (or one that carries locked * text, or one that is not data), is skipped, and what is below it stands (runs in its place, when it never called * `next`). The engine records, at each handler's boundary, the overlays as it validated them and who contributed * each (the registration and its seat: the deployment seat is the deploy class, the task seat the task class); what * applies is that record, never the answer read again. Each class applies its contributions in chain order, so a * later registration's overlay on the same target wins. * * `lowerAdds` — the entries the classes below deploy already added (the only entries a deploy `drop` may name * besides a built-in section). */ export declare function raisePromptCompose(bus: LegModBus, e: ModEventPayload, options: { readonly lowerAdds: ReadonlyMap<string, BandId>; readonly signal?: AbortSignal; }): Promise<PromptComposeOutcome>; /** The seats behind the engine facade, bound once the leg has them. Every member is read at its call. */ export interface LegFacadeSeats { readonly exec: ModSeatView["env"]["exec"]; complete(request: ModelCompleteRequest, signal: AbortSignal): Promise<ModelCompleteResult>; readonly sessionId: string; /** The run's account of side model calls ({@link ModSeatView.book}). */ book: ModSeatView["book"]; cwd(): string; root(): string; model(): string; messages(): readonly Message[]; /** `$.session.messages({ agentId })`'s read ({@link agentRowsOf}). */ agentMessages(agentId: string): Promise<readonly AgentMessage[]>; turns(): Promise<number>; usage(): SessionUsage; version(): SessionVersion; /** `$.turn.abort`'s seat ({@link ModSeatView.turn}). */ turnAbort(turn: number, by: string): TurnAbortVerdict; now(): number; tools(): readonly string[]; agents(): readonly string[]; /** `$.tool.call`'s host entry (`createToolCallEntry`, `tool-call.ts`). */ readonly toolCall: ModCallEntry; /** `$.agent.spawn`'s host entry (`createAgentSpawnEntry`, `agent-stations.ts`). */ readonly agentSpawn: ModCallEntry; /** `$.session.append`'s host entry (`createSessionAppendEntry`, `session-append.ts`). */ readonly sessionAppend: ModCallEntry; /** `$.session.send`'s host entry (`createSessionSendEntry`, `session-send.ts`). */ readonly sessionSend: ModCallEntry; /** `$.session.compact`'s host entry (`createSessionCompactEntry`, `session-compact.ts`). */ readonly sessionCompact: ModCallEntry; /** `$.prompt.submit`'s host entry (`createPromptSubmitEntry`, `prompt-submit.ts`). */ readonly promptSubmit: ModCallEntry; } /** The leg's admitted bus, its chain identity (the one its admission recorded, {@link chainOfBus}) and the binding of the * facade its `$` reaches. `bus` is the leg bus every station raises on ({@link legBusOf}: an extension's own call's * events are raised under its frames). */ export interface LegMods { readonly bus: ModBus; /** The leg's standing chain ({@link standingBus}): the bus without the skills' registrations — what the leg hands its * descendants (its screening constraint is minted over it) and what guards each of its calls unconditionally. The bus * itself when no skill carries one. */ readonly standing: ModBus; readonly chain: readonly ModChainLink[]; /** The leg's skill scopes (`SkillSpec.mods`): the grant table opens one on each activation, the park freezes them. */ readonly skillScopes: SkillScopes; /** The leg's report sink (handler failures; a station's own disclosures). */ readonly report: (err: Error) => void; /** Bind the engine facade once the leg is prepared. Until then a `$` call throws, naming the method. */ bindFacade(seats: LegFacadeSeats): void; /** End the bus's lifetime (the leg stopped): its timers are cancelled and a `$` call made after its handler settled is * refused from here. Its owner calls it on every way out of the leg; a second call does nothing. */ end(): void; } /** * Admit the leg's bus: both seats (`RunnerDeps.mods`, `TaskSpec.mods`), screened and put to `plugin.register`. * Called once per leg, at that leg's own prepare (a delegated child and a resumed leg each admit their own; a reference-form * package's register is a replay of what its own register hung once, at its load — admitting it again replays, never reruns it); * each refused registration becomes one notice (`mods.registration_refused` for the task seat, `mods.registration_refused_deployment` * for the deployment seat). Throws `config.mods_invalid` for a * registration the kernel cannot take. */ export declare function admitLegMods(input: { /** The leg's registrations, listed once ({@link listLegModSeats}). */ readonly listed: LegModSeats; readonly deps: Pick<RunnerDeps, "onError" | "onNotice">; readonly sessionId: string; /** The skills a resumed leg's park recorded active (their scopes open from the start). */ readonly reopenedSkills?: readonly string[]; /** The leg's one view of a retired tool name: a handler's `tool` matcher written with one matches the tool the leg reads it as * (#1781, as the reference maps a hook matcher's old name). Absent ⇒ every matcher as written. */ readonly retiredNames?: RetiredNameView; }): Promise<LegMods>; /** What a leg hands {@link legFacadeSeats}: the seats it already has. */ export interface LegFacadeInput { readonly deps: Pick<RunnerDeps, "brain" | "modelFallback" | "cacheRetention" | "models" | "now">; /** Reads a mod's model request against the session's main line before it goes out (its `brain.call` row carries the reading). */ readonly observeSideRequest: import("../runner/prefix-ledger.js").RequestObserver; readonly spec: Pick<TaskSpec, "getApiKeyAndHeaders">; readonly sessionId: string; readonly model: Model; readonly executionEnv: Pick<ExecutionEnv, "exec">; /** The run's byte-floor seat: a mod's `$.process.run` is the run's own start and carries the run's base table. */ readonly readFloor: (toolCallId: string | undefined) => ReadFloor | undefined; readonly taskRoot: string; readonly cwdRef: CwdRef | undefined; /** The leg's latest model request as actually sent, recorded at the provider seam (the session's messages as the model last * saw them), whether or not a reducer left something out of it; `undefined` before the leg's first request. */ readonly lastSentRequest: () => { readonly messages: readonly Message[]; } | undefined; /** Where the leg's subagents' transcripts are read ({@link agentRowsOf}); `undefined` ⇒ there is no task list (a * session-level pass), and the read refuses saying so. */ readonly agentSessions: AgentSessionsSeat | undefined; /** The session's prompt count, read at the call (`promptCountOf` over its branch, `session-append.ts`). */ readonly turns: () => Promise<number>; /** The leg's measurement seat (`measureSession` writes it at each turn boundary). */ readonly measure: SessionMeasureSeat; /** The leg's `$.turn.abort` seat, filled by the run ({@link TurnAbortRef}). */ readonly turnAbort: TurnAbortRef; readonly activeTools: ReadonlySet<string>; readonly agentListing: { readonly entries: ReadonlyArray<{ readonly name: string; }>; } | undefined; /** The run's one account of side model calls (the same entry the classifier's side calls book on), handed the model a * `$.model.complete` call resolved to, the usage its reply reported (absent ⇒ none reported) and the reply's * diagnostics when it carried any (a degraded brain's fallback is priced by them), and the stop reason it ended on with whether its text was a * finalized partial (the same account reads whether the model answered, for the `model.fallback` notice). */ readonly book: (model: Model, reply: { readonly usage: Usage | undefined; readonly diagnostics?: AssistantMessage["diagnostics"]; readonly stopReason?: string; readonly partialFinalized?: boolean; }) => void; /** `$.tool.call`'s host entry, over the leg's harness and occurrence table. */ readonly toolCall: ModCallEntry; /** `$.agent.spawn`'s host entry, over the leg's harness and its delegation tool. */ readonly agentSpawn: ModCallEntry; /** `$.session.append`'s host entry, over the leg's admission seat and harness. */ readonly sessionAppend: ModCallEntry; /** `$.session.send`'s host entry, over the leg's `$.tool.call` entry and its SendMessage. */ readonly sessionSend: ModCallEntry; /** `$.session.compact`'s host entry, over the leg's compaction station. */ readonly sessionCompact: ModCallEntry; /** `$.prompt.submit`'s host entry, over the leg's stream's steer relay. */ readonly promptSubmit: ModCallEntry; } /** The seat a leg reads its subagents' transcripts through: its task list, only the rows its own access reaches. Each row * carries the store its child's session lives in, so no store of the leg's own is read. */ export interface AgentSessionsSeat { readonly registry: Pick<TaskRegistry, "anchoredSession">; readonly access: TaskAccess; /** The leg's own tree-owner seat: a subagent's session is read only once the one row judge holds for it (absent = the leg holds none). */ readonly owner?: DelegationOwnerSeat; /** The leg's stop: the judge's read ends with it (absent = the read is ended only by its bound). */ readonly signal?: AbortSignal; } /** The engine facade's seats over a prepared leg — each one a seat the leg already has (no new capability). */ export declare function legFacadeSeats(input: LegFacadeInput): LegFacadeSeats; /** * A chain admitted outside any leg — what a host rebuilds to re-supply an inherited screening entry on a fresh Runner * (a cross-process resume hands back `{ installation: await admitModChain(…), hookEnv, …regime }` over the same * registrations). The same admission a leg runs (both seats, `plugin.register`); no leg exists, so its `$` facade is never * bound and a `$` call throws, and its lifetime has ended from the start: a timer is refused, and so is a `$` call made after * its handler settled. Handler failures go to `onError` (absent ⇒ unreported). Its chain identity is recorded as a * leg's is ({@link chainOfBus}), so an entry carrying it is read by what it mounted. */ export declare function admitModChain(seats: { readonly deployment?: readonly ModRegistration<EngineDollar>[]; readonly task?: readonly ModRegistration<EngineDollar>[]; }, onError?: (err: Error) => void): Promise<ModBus>;