UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

70 lines (69 loc) • 5.18 kB
/** * The bindings of a run's member ledger book (`TaskSpec.runLedger`) that need the prepared leg: the holder's rows of the members the * task dispatched (read at each snapshot), and the run's own tool calls (the evidence a check may cite, heard as each one starts and * finishes). Bound once, right after prepare, by the lane that minted the book. * * A MEMBER is a background agent, workflow run or peer task whose registry row names this task as the one that dispatched it * (`parentTaskId`, written at registration by the agent tool, the workflow tool and the peer task lane alike: `isRegistryMemberKind`) * — one key for every kind, whatever owner the row registered under (a session-scoped spawn registers under the session) and whatever * else the session's reach holds (another task's spawns). How it stands is that row's: whether it runs, how it ended (the ending its * holder minted, else the one its status word names — `outcomeOfLegacyRow`, the one table), a workflow run's own members (the run's * member ledger, as the registry keeps it). * * The holder read is this process's task registry. A durable background-agent, workflow-run or peer-task store is not read: a member * whose row only such a store holds (a resume in another process) is one the holder no longer hands back — the book counts it * unreadable and the coverage is incomplete (`docs/KNOWN-LIMITS.md`, KL-4459-b). */ import { type TaskListRow } from "./task-registry.js"; import { type RunEndCause } from "./member-outcome.js"; import type { RunLedgerBook, RunLedgerRegistryRow } from "./run-ledger.js"; /** What the binding reads off the prepared leg: its task id (the book's), its run id, its registry access, its session, and its * harness's event stream. */ export interface RunLedgerLeg { readonly taskId: string; readonly runId: string; readonly registryAccess: { readonly owner: string; readonly scope: string; }; readonly sessionId: string; readonly harness: { subscribe(listener: (event: { readonly type: string; readonly toolCallId?: string; readonly result?: unknown; }) => void): () => void; }; } /** The task's member rows as its holder hands them (see the module head): every row of the reach that names the task as its * parent, read as one set (no display cap — other tasks' rows in the reach never push a member out). The reach is the leg's own, * its tree root's occupant included (`occupant`, the one its registry-facing tools act for): a worker an earlier occupant of a recycled * session id started is no member, as it is no task of that leg. */ export declare function ledgerRegistryRows(access: { readonly owner: string; readonly scope: string; }, sessionId: string, taskId: string, occupant?: string): RunLedgerRegistryRow[]; /** One member by its id — the same rule, read with no listing at all (a frame's row, however many rows the reach holds). */ export declare function ledgerMemberRow(access: { readonly owner: string; readonly scope: string; }, sessionId: string, taskId: string, memberId: string, occupant?: string): RunLedgerRegistryRow | undefined; /** One registry row as a snapshot reads it: running while its status says so; else the ending its holder minted (a background * agent's, a peer task's), else the one its status word names ({@link outcomeOfLegacyRow}) — a parked row's is `parked`. A workflow * row carries its run's own member ledger once the run settled. One cycle per row but a background agent's (a peer task's frames * count frames, not cycles). */ export declare function ledgerRegistryRowOf(r: TaskListRow, name?: string): RunLedgerRegistryRow; /** The run-end reap of the run's task-scoped background agents (the teardown's own selection: `skipSessionScoped`), run ahead of a * member ledger's last word (r3.1 R1.3: the last word is read after the reap, nothing simulated): the person's-stop mark first when * a person stopped the run's work, then the reap with what ended the run, then — when it stopped any — a bounded wait until none * of the agents this sweep selects remain running (ignoring monitors, background shells and session-scoped rows). The wait counts * the task-scoped agents currently running under this owner, so an agent started by the same owner after the stop pass can hold the * last snapshot up to the two-second bound. The teardown's own reap after it finds nothing left to take. */ export declare function reapTaskAgentsBeforeLastWord(access: { readonly owner: string; readonly scope: string; }, source: "user" | "parent", runEnd: RunEndCause | undefined): Promise<void>; /** Bind the book to the prepared leg — see the module head. The book's task is the leg's: a book minted for another task id is an * engine fault, refused here rather than read as a ledger of nobody's members. `occupant`: the occupant of the leg's tree root the * leg acts for (absent = none read: every row admits it, as on every registry face). */ export declare function bindRunLedgerBook(book: RunLedgerBook, prepared: RunLedgerLeg, occupant?: string): void;