UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

131 lines (130 loc) • 8.5 kB
import type { AskEffective } from "./wiring-manifest.js"; import type { PermissionMode } from "./ask-origin.js"; import { type EngineRegionMessage } from "./reminder-mint.js"; /** The auto-mode frame (title + the two paragraphs). */ export declare const AUTO_MODE_DIRECTIVE: string; /** The shell-first paragraph. The reference implementation serves it under three different headings; * the one heading this engine has a fact for is the bypass posture below. */ export declare const BASH_FIRST_DIRECTIVE: string; /** The bypass-posture frame: the reference implementation's heading over the shell-first paragraph, the * exact pair its bypass arm renders. */ export declare const BYPASS_POSTURE_DIRECTIVE: string; /** The auto-mode frame's exit: the reference exit renderer's long arm (the retired frame was not steer-only) * with no shell-first sentence (the retired frame carried none). */ export declare const AUTO_MODE_EXIT_DIRECTIVE: string; /** The bypass frame's exit: the same renderer's short arm (the retired frame was steer-only) with its * shell-first sentence (the retired frame carried the shell-first paragraph). */ export declare const BYPASS_POSTURE_EXIT_DIRECTIVE: string; /** The planning frame — the reference full reminder's opening sentence verbatim (its own "supercedes" * spelling included); the tail is adapted to the engine's exit (the plan-exit tool, a human approves). */ export declare const PLAN_MODE_DIRECTIVE: string; /** The planning frame's sparse restatement — the reference sparse shape minus the plan-file clause. */ export declare const PLAN_MODE_SPARSE_DIRECTIVE: string; /** The planning frame for a leg with NO plan-exit tool on its roster: the same opening, and the plan is the leg's * final answer (no tool is named, no approval request is promised). */ export declare const PLAN_MODE_NO_EXIT_DIRECTIVE: string; /** The no-tool planning frame's sparse restatement. */ export declare const PLAN_MODE_NO_EXIT_SPARSE_DIRECTIVE: string; /** The planning frame of a DELEGATED child — the reference's sub-agent variant: the same opening, no exit tool named, * the child answers the request it was given (its final answer goes back to the agent that delegated to it). The * reference has no sparse arm for a sub-agent, so a restatement of this row is this body. */ export declare const PLAN_MODE_CHILD_DIRECTIVE: string; /** The planning frame's exit — the reference exit renderer's text without its plan-file clause. Names no tool, so * one exit retires every planning wording. */ export declare const PLAN_MODE_EXIT_DIRECTIVE: string; /** The mode facts of one leg, both the ENGINE's own resolution — never a requested value, never spec shape. */ export interface ApprovalPostureFacts { /** The leg's EFFECTIVE permission mode (a requested mode the deployment refused has already folded back). */ mode: PermissionMode; /** The seat's own ask derivation (`askSeatEffective`, no mode) — `auto_allow` means no person answers an ask on this leg. * The LIVE `mode` is read before it: the manifest's reported word is the leg's start under its start mode, and a steer moves * the mode after it was minted. */ askEffective: AskEffective; } /** * The shape facts of one leg the planning rows word themselves by — read off what the leg IS (its minted tool roster, its * minted delegation identity), never off the requested spec. */ export interface PostureLegFacts { /** The plan-exit tool ({@link PRESENT_PLAN_TOOL_NAME}) is on this leg's roster — its wire name or an alias a call resolves. */ exitToolMounted: boolean; /** This leg runs as a delegated child (every core spawn lane, a fork included). */ isChildLeg: boolean; } /** Every fact a row's `owedBy` reads: the mode facts and the leg's shape. */ export type PostureFacts = ApprovalPostureFacts & PostureLegFacts; /** A posture family: one family stands in a context at a time per family, and its exit retires whichever of its rows stands. */ export type PostureFamily = "plan" | "auto"; /** One row of {@link POSTURE_TABLE}. */ export interface PostureRow { readonly family: PostureFamily; /** Whether the leg's mode facts call for this row. */ readonly owedBy: (facts: PostureFacts) => boolean; /** The frame that states the posture. */ readonly frame: string; /** The frame that retires it. */ readonly exit: string; /** * A restatement while the row stays owed and standing: due once `everyTurns` assistant turns have passed since * the family's last frame; the restatement is the full frame when it is the family's `1 + k·fullEvery`-th frame * since its last exit, else `sparse`. Absent ⇒ stated once and never restated while it stands. */ readonly cadence?: { readonly everyTurns: number; readonly fullEvery: number; readonly sparse: string; }; } /** * Every posture the engine states, in the order the owed row is chosen. `plan` first: it is the mode the leg * was put in, and the bypass frame's shell-first instruction would contradict it. Within it the leg's shape picks the * wording — a delegated child (the reference's sub-agent variant), else a leg with the plan-exit tool on its roster * (the planning body that names it), else the body that names no tool. Then the reference * implementation's own arm order for its one posture attachment: bypass (effective `bypassPermissions`, or — outside * `dontAsk`, whose mode refuses every ask before any seat could answer — no person answers an ask), then auto (the * classifier is armed — a requested auto mode the engine folded back is not stated, because the run is not operating * under it). */ export declare const POSTURE_TABLE: readonly PostureRow[]; /** The row the leg's facts call for, or undefined (no posture is owed). */ export declare function owedPostureRow(facts: PostureFacts): PostureRow | undefined; /** What one family's standing frame is, as the fold over the active context left it. */ export interface StandingPosture { readonly row: PostureRow; /** The family's frames since its last exit (the cadence's full/sparse count). */ readonly statements: number; /** Assistant turns since the family's last frame (the cadence's due clock). */ readonly turnsSince: number; } /** The standing families of a context, keyed by family, in the order they first stood. */ export type PostureStanding = ReadonlyMap<PostureFamily, StandingPosture>; /** * The ordered fold over the ACTIVE context's messages (the compaction boundary applied — never the raw ancestry, * which still carries what a compaction replaced): the engine's marked reminder bodies, read off ENGINE REGIONS * only (metadata, never text shape, so a caller's spliced copy — marked or not — cannot answer), per minted block; * an assistant message advances every standing family's turn clock. */ export declare function postureStandingOf(messages: readonly EngineRegionMessage[], reminderMark: string): PostureStanding; /** * The ONE composition: the frames that make the active context state exactly the posture the leg's facts call for * — the exit of every standing family the owed row does not belong to, then the owed row's frame (or its cadence's * restatement) when it is owed. Empty when the context already says it. */ export declare function composePostureFrames(facts: PostureFacts, standing: PostureStanding): string[]; /** * The run-local half of the posture: the newest posture carrier's text (the context lane's protection slot — * a clipped request keeps or reinserts the message carrying it; the carrier of an exit takes the slot, so a * retired frame is no longer protected); the owed row the last composition answered for (a boundary whose facts * still call for that row, with no cadence to keep, asks nothing of the context — absent means the last * composition read nothing or its carrier was not written, so the next boundary asks again); the frames a boundary * could not write (stated on each request's view, never persisted, until a boundary writes them); and where a * write failure is disclosed. */ export interface PostureFrameRef { protectedText?: string; composedFor?: PostureRow | null; unwritten?: string; report?: (err: Error) => void; } /** SHA-256 of a frame body — the pins' lock port, so the lock is computed the one way. */ export declare function directiveDigest(body: string): string;