UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

80 lines (79 loc) • 7.96 kB
import type { MaybeCompactOptions } from "../auto-compaction.js"; import { type PostureFacts } from "../auto-mode-directive.js"; import type { Prepared } from "./contracts.js"; import { type InstructionEcho } from "./nested-memory-lane.js"; /** * The facts the posture composition reads, as the leg IS now: the live effective mode and ask answer, the plan-exit * tool's presence on the minted roster, the minted delegation identity, and the session plan file the run admitted. The one place a leg's facts are assembled — * the leg's first turn, a resumed continuation, a continuing boundary and a landed compaction all ask through it. */ export declare function postureFactsOf(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs">): PostureFacts; /** * The posture question, asked of the ACTIVE context: the frames the leg's mode facts owe now (exits of retired * families, the owed frame or its cadence's restatement — `composePostureFrames`), minted as one carrier text — * one marked reminder per frame — that takes the context lane's protection slot. `undefined` when the context * already states the posture. * * `"on_change"` (a continuing turn boundary): asks nothing of the context when the facts still call for the row the * last composition answered for and that row keeps no cadence — the context only changes posture through this * function's own carriers and a landed compaction (which asks with `"always"`). A context that cannot be read * answers "nothing standing": the owed frame is restated rather than withheld. */ export declare function owedPostureText(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs" | "session" | "reminderMark" | "postureFrameRef" | "engineText">, ask: "always" | "on_change"): Promise<string | undefined>; /** The posture's COMPACTION arm: after a landed compaction the runner asks the posture question of the compacted * context and appends what it owes as one engine-minted message, before any reader of the new baseline (the next * model request included). A leg that owes no posture registers nothing: a compaction only REMOVES frames, and a * retired frame that survives it in the kept tail is answered by the next composition (the next continuing * boundary, or the next leg's first turn). */ export declare function postureRestateOption(prepared: Prepared): Pick<MaybeCompactOptions, "postureRestate">; /** * The posture's MID-RUN write (a turn boundary, a landed compaction): what the active context owes is appended to * the transcript as one engine-minted message, awaited — the next request's context is rebuilt from the session after * the boundary, so the frames reach that very request, ahead of every queued steer. Two cases do not write, and take * one path — the frames ride each request's view (never persisted) and the composition stays dirty, so the next * boundary that can write does: a boundary that HOLDS engine injections (a person's bare rejection halted the batch — * nothing the engine says may enter the transcript ahead of that person's next words), and a failed append (the rule * of every engine frame written at a boundary, the git frame's re-assert and the compaction itself: the run continues * and the failure is reported, `onError` phase `degraded`). Never throws. */ export declare function appendOwedPosture(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs" | "session" | "admitRows" | "reminderMark" | "postureFrameRef" | "batchHaltRef" | "frameReceipts" | "engineText">, ask: "always" | "on_change"): Promise<void>; /** The declared output style's frame as one engine-marked reminder — the one spelling every site that states it directly * (a resumed leg's continuation, a boundary a queued input continues) mints. */ export declare function mintOutputStyleReminder(prepared: Pick<Prepared, "outputStyleFrame" | "reminderMark">): string | undefined; /** Is a frame of this source already on its way to the next request (a pending receipt)? The one reading, for every * collector that could state it again: the boundary bundle, the direct-write style lane and the posture writer. */ export declare function frameCarried(ledger: Prepared["frameReceipts"], source: Prepared["frameReceipts"]["pending"][number]["source"]): boolean; /** * Settle the receipts a landed message carries, in receipt order. A step that must read the session first (a changed-files notice's * announcement) returns a promise: the steps behind it wait for it, and the one promise is handed back to the `message_end` handler * (the harness awaits its listeners), so every announcement lands before the next listener reads the event. `undefined` when every * step was synchronous. */ export declare function settleFrameReceipts(settled: ReadonlyArray<Prepared["frameReceipts"]["pending"][number]>, entryId: string): Promise<void> | undefined; /** * The turn boundary's direct writes, for a boundary a request can follow: the owed posture, and the output style when * the turn's tool results do not go back as the next request (`turnOwesRequest` false) and queued input already * guarantees the next one (`pendingInjectionCount`, both lanes: what can continue a run), unless that request already * carries it ({@link frameCarried}). Both frames keep the posture's halt rule. The guarantee is read synchronously, at * the call, before any await — a boundary with nothing queued returns the posture's own promise. */ export declare function appendBoundaryFrames(prepared: Pick<Prepared, "approvalPosture" | "toolRoster" | "hookIdentity" | "advertisedWritableDirs" | "session" | "admitRows" | "reminderMark" | "postureFrameRef" | "batchHaltRef" | "outputStyleFrame" | "harness" | "frameReceipts" | "engineText">, turnOwesRequest: boolean): Promise<void>; /** * The session plan file's post-compaction reference (the reference's `plan_file_reference`, CC 2.1.309 `Tmr` (cli309.js:265943)): a compaction * summarizes away the turns that wrote the plan, so a leg whose run admitted a plan file that holds a plan is told where * it is and what it says, in any mode — the reference's own sentences, the plan fenced as the untrusted model text it is. * Read through the seat's one reader; an absent or blank file says nothing (there is no plan to refer to), and an * unreadable one is not guessed at. One engine-minted message, appended like the posture's; a failed append is reported * and never fails the landed compaction. */ export declare function planFileRestateOption(prepared: Prepared): Pick<MaybeCompactOptions, "planFileRestate">; /** The instruction files' compaction arm (`restateInstructionFiles`): a leg with the instruction-file lane writes what the * compacted context owes — the task root's members first — before any reader of the new baseline. It keeps the posture's * halt rule (a person's bare rejection halted the batch: nothing the engine says enters the transcript ahead of that * person's next words; the next load owes the files again). */ export declare function instructionsRestateOption(prepared: Prepared, echo: InstructionEcho): Pick<MaybeCompactOptions, "instructionsRestate">; /** Every post-compaction restatement the three compaction routes register, at one spread site, and the frames those * restatements post again (`restatedFrames`: the floor the trigger's "window below overhead" judgment reads beside the * prefix — the request core's engine frames, the one set the guard trim holds); `echo` is the run's echo of a restated * instruction frame. */ export declare function compactionRestateOptions(prepared: Prepared, echo: InstructionEcho): Pick<MaybeCompactOptions, "gitRestate" | "instructionsRestate" | "postureRestate" | "planFileRestate" | "advisorRestate" | "languageRestate" | "sandboxFrameRestate" | "restatedFrames">;