UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

96 lines (95 loc) • 6.12 kB
/** * The Runner's per-session PROMPT seats: what the reference keeps about a session's prompt in its process state, in this * process — the session clock the elapsed-time reminder reads, and the session's shell-first judgment the Bash card is chosen by. * * One seat per session tree (the root's address key, `rootSessionAddressKeyOf`: its scope, id and occupant), so a child leg * reads its root's facts, as the reference's process-wide state is read by its subagents. In-process only, as the reference * keeps it: a session continued on another Runner instance or in another process starts with no facts (the elapsed clock then * starts at its first reading). Bounded by {@link MAX_SESSIONS} sessions, least recently used out first (a dropped session reads as * one with no facts). A CACHE, never an authority — nothing here is persisted. */ import type { PermissionMode } from "../ask-origin.js"; import type { PromptTraitName } from "../../prompt-assembly/catalog/schema.js"; import type { ToolCardFacts } from "../../prompt-assembly/tool-catalog.js"; import type { TaskSpec } from "../types.js"; import { type LegOpening, type RunTimeReminderLane } from "./boundary-reminders.js"; /** * What a leg's prepare takes from its session tree's prompt seat: the card facts its tool cards are mounted with (the session's * shell-first judgment, {@link shellFirstSessionOf}), and the run-time reminders' lane (the run's traits read once, the task's * switches, a top-level leg) with the leg's handle on the tree's elapsed clock. `key` is the tree's address key; undefined (an * address that names nobody) ⇒ the leg keeps facts of its own. `seats` absent (a standalone prepare) ⇒ the same. */ export declare function preparePromptSeats(input: { readonly seats: SessionPromptSeats | undefined; readonly key: string | undefined; readonly traits: ReadonlySet<PromptTraitName>; readonly childLeg: boolean; readonly attachments: TaskSpec["attachments"]; /** The mode the leg runs under (the controller's effective word). */ readonly mode: PermissionMode; /** In a plan: the mode it was entered from, as that mode runs (`PermissionModeController.prePlanModeObserved`). */ readonly prePlanMode: PermissionMode | undefined; readonly now: () => number; }): { readonly cardFacts: ToolCardFacts; readonly runTimeReminders: { readonly lane: RunTimeReminderLane; readonly elapsedClock: ElapsedTimeClock; readonly opening: { current?: LegOpening; }; }; }; /** What one session tree's prompt holds in this process. */ export interface SessionPromptFacts { /** The session clock: when (on the run's clock, `Prepared.now`) the person last gave the session an input its elapsed-time * reminder counts from. Absent = no clock (none started yet, or the reminder was off when the person last spoke). */ elapsedSince?: number; /** The session's shell-first judgment ({@link shellFirstSessionOf}), made once — by the first leg of the tree this process * prepares — and read by every later leg of it, its children included. Absent = not judged yet in this process. */ shellFirst?: boolean; } /** * Whether the session is a shell-first one (the `shellFirstSession` prompt fact), judged once per session tree as the reference * judges it once per session (`bashFirstDescriptionTrimmed ??=`): the mode the judging leg runs under (a plan: the mode it was * entered from as that mode runs, `prePlanMode`) is auto or bypassPermissions, and its model holds a shell-first trait. A later leg — a mode * switched mid-session, another model, a delegated child — reads the judgment; it never judges again (the card, and the prompt * prefix it sits in, stays put). */ export declare function shellFirstSessionOf(facts: SessionPromptFacts, leg: { readonly mode: PermissionMode; readonly prePlanMode: PermissionMode | undefined; readonly traits: ReadonlySet<PromptTraitName>; }): boolean; /** One Runner's session trees' prompt facts, keyed as the fast-mode seat keys its facts. */ export declare class SessionPromptSeats { #private; /** The session tree's facts, made on the first ask (a least-recently-used touch on every ask). */ of(key: string): SessionPromptFacts; } /** A leg's handle on its session tree's elapsed-time clock ({@link SessionPromptFacts.elapsedSince}). */ export interface ElapsedTimeClock { /** The leg's objective is the person's own (its author counts as the operator's): its commit will move the clock. An objective * another author wrote — a recipe's own continuation, a delegator's — is never admitted, nor is a steer that lands mid-run (the * reference restarts its clock at a new prompt only, `VOi` in its `processUserInput`; a mid-turn input is an attachment there). */ admit(inputId: string): void; /** A person's-input row was committed (`origin: "human_input"`, its `inputId`): an admitted input {@link restart}s the clock. */ committed(inputId: string | undefined): void; /** The person's words reached the session (an admitted input's commit; a resume's continuation carrying a parked steer or the * wake message, which are the operator's): the clock starts again from now when the reminder is on, and is cleared when it is * off. A child leg's inputs do not move it. */ restart(): void; /** The time since the clock started, in ms; a session with no clock starts one now (the first reading is 0). */ elapsedMs(): number; } /** * The leg's elapsed-time clock over its tree's facts. `facts` is the tree's ({@link SessionPromptSeats.of}) — or the leg's own * when its root's address names nobody, shared with no one; `root` is whether the leg is its tree's root leg (only a root leg's * person inputs restart the clock); `on` is whether the leg's elapsed-time reminder is on. */ export declare function elapsedTimeClockOf(input: { readonly facts: SessionPromptFacts; readonly root: boolean; readonly on: boolean; readonly now: () => number; }): ElapsedTimeClock;