UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

57 lines (56 loc) • 3.4 kB
/** * The Runner's per-session PERMISSION-MODE seats: the mode a session's CURRENT leg runs under, as the object a * child's ceiling falls back to once the leg that spawned it has ended. A child's ceiling used to be the controller * of the leg that spawned it for the child's whole life, so a session-scoped background child kept that leg's mode * after the leg ended — the next leg of the same session, started in `plan`, did not reach it. The chain now carries * a LEG ceiling: the spawning leg's live mode while that leg runs, and the session's seat after it. Each leg binds * itself to its session's seat when its prepare commits, so the seat answers the most recently committed leg; a leg * that is still running keeps answering its own children, whatever another leg of the session commits meanwhile. */ import type { PermissionMode } from "../ask-origin.js"; import type { PermissionModeReceipt } from "../mode-policy.js"; /** A child leg whose ceiling is a leg ceiling: its receipt is read before a ceiling move and re-judged after it. */ export interface ModeCeilingHolder { receipt(): PermissionModeReceipt; /** The ceiling's source moved; `before` is this holder's receipt under the previous source. */ ceilingRebound(before: PermissionModeReceipt): void; } /** One leg's ceiling, as the chain carries it (`InheritedGate.permissionModeCeiling`). */ export interface LegModeCeiling { /** The spawning leg's live mode while it runs; the session's current leg's after it (`default` before any leg of * the session committed — no child can read it then). */ readonly current: PermissionMode; /** The same word read without starting anything (`PermissionModeController.observed` on the leg it reads). Optional on * the TYPE only: the engine's ceilings always answer it, and a reader falls to `current` when a hand-built ceiling (a * host's literal, a fixture) carries none — so the member's arrival is additive for every constructor of this shape. */ readonly observed?: PermissionMode; readonly sessionId: string; /** A child leg holds the ceiling until `signal` aborts (its own leg's end): each move of the ceiling re-judges it. */ hold(holder: ModeCeilingHolder, signal: AbortSignal): void; } /** A leg's mode seat as a ceiling reads it: the decision read and the observation read. */ type LegModeSeat = { readonly current: PermissionMode; readonly observed: PermissionMode; }; /** * The seats of one Runner, keyed by session id and held WEAKLY: a seat lives while a leg ceiling holds it, and the * next leg of the session finds the same object as long as any child still reads it. In-process only — a session * continued on another Runner instance or in another process binds that Runner's seat. */ export declare class SessionModeSeats { private readonly seats; private readonly reaper; private seatOf; /** * A leg's ceiling over its session's seat, the leg's commit (once its prepare succeeded: the leg becomes the * session's current leg) and its end (once the leg has STOPPED — its loop settled, not merely cancelled: a cancelled * leg whose tool is still pending keeps answering its own children). */ legCeiling(sessionId: string, leg: LegModeSeat): { ceiling: LegModeCeiling; commit: () => void; end: () => void; }; } export {};