UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

402 lines (401 loc) • 30.7 kB
import type { RunInternals, RunnerSelfSeat } from "../core/runner/contracts.js"; import type { TaskSpec } from "../core/types.js"; import type { PeerDeclarationHold } from "../core/peer-seat.js"; import { type KeeperDeclarations } from "./agent-definition.js"; import type { BackgroundAgentRecord, BackgroundAgentSettledStatus } from "../core/background-agent-store.js"; import type { SubagentTranscriptTier } from "../core/wiring-manifest.js"; import { type ContinuationEndedBy } from "../core/delegation-frames.js"; /** * How the parent model's next SendMessage can continue a stopped background agent — the continuation ladder's own answer: * · `retained` — this engine process holds its conversation until `until` (epoch ms: the settle instant of the cycle the * answer speaks for, plus the entry's window — {@link SubagentRetainLedger.untilOf}); past it the entry is evicted. An * upper bound: the ledger's capacity, a session reap or the parent run's end can take the entry earlier; * · `durable` — its durable record revives it (no deadline this engine sets); * · `none` — SendMessage answers with a refusal (stopped by the user, nothing retained or recorded). */ export type AgentContinuation = { readonly by: "retained"; readonly until: number; } | { readonly by: "durable"; } | { readonly by: "none"; }; /** The row-side facts the durable rung admits a row on — read off the stored row by tier-3, off this process's copy of the * row's durable record by every other reader ({@link import("../core/task-registry.js").TaskRegistry.durableAgentRowFacts}). */ export type DurableRungRowFacts = Pick<BackgroundAgentRecord, "agentType" | "sessionId" | "policyFloor">; /** What the parent's face continues a child through, as the judge reads it: its SendMessage's transcript tier (`none` = the * fast lane only, no revival), or `unmounted` — the model's tool table shows no SendMessage (none mounted, the valve took it, * or a whole-tool deny hides it from the request), so nothing on it continues a child. Absent = not known (a SendMessage the * host declared itself) and never narrows. */ export type ContinuationReach = SubagentTranscriptTier | "unmounted"; /** * The durable rung's ROW-SIDE admission — the steps of SendMessage's tier-3 revival that read only the row, in its order: * a fork's row is never revived (it ran store-less, nothing resumes it); a row with no transcript anchor has nothing to * continue; a row whose birth floor cannot be read cannot hold the restrictions its child ran under on a new cycle (its * anchor rides that refusal: the ladder judges whose the row is before it answers the floor). The rung answers each * refusal with its own text; every judgment of "can the durable rung take this row" reads this one function. Facts about * the recipient (the caller's access, its mount, the box) and about the row's live state (running, parked) are the * ladder's, at send time — not here. */ export declare function durableRungAdmitsRow(row: DurableRungRowFacts): { ok: true; transcript: string; } | { ok: false; refusal: "fork"; why: string; } | { ok: false; refusal: "no_transcript"; why: string; } | { ok: false; refusal: "policy_floor_unreadable"; why: string; transcript: string; }; /** * THE continuation judge: can the parent model's next SendMessage continue this stopped background agent, and until when. * Three ordered rules over the continuation ladder's own inputs: * 1. nothing the parent model is shown continues it ⇒ `none`: a USER's stop (the ladder's one hard refusal; a parent teardown, * a reap or a host death is what the recovery lanes exist for), or a model shown no SendMessage (reach `unmounted`) — * before rule 2, whose `none` test would let `unmounted` through; * 2. the durable rung admits the row ({@link durableRungAdmitsRow}) ∧ its durable record exists ∧ the parent's * SendMessage mount can revive — its tier is not the KNOWN `none` (an unknown tier, a SendMessage the host declared * itself, does not narrow) ⇒ `durable`, whatever live entry stands in front of it; * 3. a live retain entry ({@link liveRetainEntryOf}: past-window entries are swept first; a producer that holds its own * entry reads it by identity) ⇒ `retained` until `settledAt` (the settle instant of the cycle this answer speaks for — * the entry's last settle when absent) plus the entry's window; otherwise `none`. * What it cannot foresee is answered by the ladder at send time, honestly: the caller's access, the peer admission and the * box, whether the sending run can host a background continuation at all, a session the store lost, another process. * Its readers: the terminal frames and completion notifications of every background producer, and ListAgents — * through {@link continuationClaim}, the one projection. */ export declare function agentContinuationOf(f: { status: BackgroundAgentSettledStatus; stoppedBy?: string | undefined; live: { ledger: SubagentRetainLedger; entry: SubagentRetainEntry; } | undefined; settledAt?: number | undefined; /** The row's durable record when the probe confirmed it exists (its row-side facts), else undefined. */ durableRow: DurableRungRowFacts | undefined; tier: ContinuationReach | undefined; }): AgentContinuation; /** The one projection of an {@link AgentContinuation} onto the frame and notification faces: `resumable` is whether it * continues at all, `resumableUntil` the deadline of a `retained` one (absent otherwise — not a deadline of the durable lane). */ export declare function continuationClaim(c: AgentContinuation): { resumable: boolean; resumableUntil?: number; }; /** The retain ledgers a continuation of an agent looks in: the session's (a session-scoped child outlives the run that * spawned it), the run's own, and — for a delegated child reaching a sibling — the parent run's. */ export interface RetainLedgerSeats { readonly session?: SubagentRetainLedger | undefined; readonly run?: SubagentRetainLedger | undefined; readonly sibling?: SubagentRetainLedger | undefined; } /** The live retain entry of one spawn (keyed by the spawn's tool-call id), read in the continuation ladder's order — * session, run, sibling — with the ledger that holds it. Each ledger is swept first (`now` is the reading's clock): an * entry past its window is evicted by the same reaper the ledger's timer runs, so no reader ever sees an entry in the * ledger that is no longer continuable. The first ledger that KNOWS the spawn decides, a live entry or an eviction's * tombstone alike: the ladder resumes through that ledger, so a tombstone ahead of a later ledger's entry answers "none * live" here too. The one read SendMessage's ladder, the continuation judge and the agent listing share. */ export declare function liveRetainEntryOf(seats: RetainLedgerSeats, toolUseId: string, now?: number): { ledger: SubagentRetainLedger; entry: SubagentRetainEntry; } | undefined; /** A producer's OWN retain entry, read through the shared reader by identity: held only while `ledger` still holds this * very retention under `toolUseId` (an eviction takes it out of the map; a fresh entry under the same key is another one). */ export declare function heldRetainEntry(ledger: SubagentRetainLedger | undefined, toolUseId: string, entry: SubagentRetainEntry | undefined): { ledger: SubagentRetainLedger; entry: SubagentRetainEntry; } | undefined; /** The one read of a seat's `holdDeclarations`, for every keeper outside a leg — a retained child's row (both retention registrations) and a * workflow run: the seat is judged here, once, and what it answers takes a keeper's hold over what the keeper reading reads of it * ({@link heldDeclarationsOf}). The member is required, so a typed host is stopped by the compiler; a seat built by hand without it * (untyped, cast) is refused by name whatever the keeper would hold, where the bare call was a TypeError from the middle of a run. */ export declare function holdKeeperDeclarations(runner: RunnerSelfSeat): (keeper: KeeperDeclarations) => PeerDeclarationHold; /** * design/122 D1 — one RETAINED child ledger row. `specSnapshot` is a FROZEN plain value-copy of the spawn * childSpec (r1-m5: retaining the live `ctx`/spec-builder closures would pin the parent run's whole prepare * graph — harness ref, tool wrappers — in memory for up to ttl×max); `internalsSnapshot` is the spawn-time * trusted internals copy (parentToolCallId / onForwardEvent / onSubagentSpawn — the grandchild chain stays * unbroken on resume, D2). `release` captures the DELEGATION runner (deployment-scoped, allowed) and * performs the unpin + explicit release that restores throwaway semantics. */ export interface SubagentRetainEntry { childSessionId: string; /** The spawning lane's word that the child's row owner was verified (`RunInternals.onSessionVerified`; a child with no owner to * judge: from its birth) — the lane's own fact, read through here. Until it says so `childSessionId` is not known to be this tree's * row, and the readers that can meet the entry then (`AgentTranscript`'s live lane, the release, the disposal arms) read, name, unpin * and release nothing of it; the resume face reads a settled entry only, and an entry whose lane never said so is dropped, never settled. */ rowVerified: () => boolean; /** * Dual-runner wake fix — the DELEGATION runner that OWNS the child session (its `sessions` store minted * and holds `childSessionId`, and its run face executes resumes). The Agent tool can be CALLER-mounted * with its own runner (e.g. a server's throwaway in-memory subRunner) while SendMessage/AgentTranscript * are core-mounted with the HOST runner — two DIFFERENT session stores. A resume/transcript acquire on * the host runner's (durable) store then fails `not_found` for a child that only ever lived in the spawn * runner's store ("resumable:true 停机帧 → resume.session_not_found"). Resume MUST go through this runner * when present; the mount runner is only the fallback for pre-existing rows. In-process pointer only — * retain is NOT durable, so cross-process semantics are unchanged (the ledger dies with the process → * resume.evicted, the 1.283 ruling). Lifetime: the entry's `release` closure already captures the same * runner, so this adds no new retention class. */ runner?: RunnerSelfSeat; /** The run that dispatched the child keeps a member ledger (`ToolExecuteContext.runLedgerBook` at the spawn): every cycle's * terminal frame carries the child's actions digest, a woken cycle's as the spawn cycle's. */ actionsDigest?: true; agentName?: string; /** fix-C5: PER-ENTRY retain TTL override (ms). A SESSION-scoped ledger is shared by two purposes with * different windows (failure-evidence retain = FAILED_SESSION_RETAIN_TTL_MS vs a session-scoped bg * child's opt-in retain = the run's configured ttl); the ledger-level `ttlMs` is fixed by whichever * purpose CREATED the ledger first, which silently truncated (or stretched) the other's window. * Expiry (lazy sweep + active timer) uses this when present, the ledger default otherwise. */ ttlMs?: number; specSnapshot: Readonly<TaskSpec>; /** The entry's hold on the references `specSnapshot`'s declarations name, on the seat the runner that revives it asks * (`RunnerSelfSeat.holdDeclarations`): handed to {@link SubagentRetainLedger.register}, which owns it from then on — kept while the * row is in the ledger, released the moment the row leaves it (or at once when the row is not taken). */ declarations: PeerDeclarationHold; internalsSnapshot: RunInternals; /** True while the initial run OR a resume run is in flight (resume re-entry rejects `steering.still_running`). */ running: boolean; /** True once the initial run settled at least once. */ settled: boolean; /** Last settle timestamp (epoch ms) — the retain-TTL base. */ settledAt: number; /** design/144 §1.2 (child gate) — the PARKED completion notification of this child's spawn settle: * present while a `completed` frame sits deferred behind the child's still-running background tasks * (owner key = childSessionId). `seq` is the parked frame's stop-cycle number (park does not change * cycle semantics); `cancel` unsubscribes the registry quiescence watcher and voids the frame. * RULING (recorded in design/144 §1.2): a resume/wake VOIDS the parked frame — the wake opens the * next stop cycle, whose own settle produces this child's next frame; delivering the stale parked * "completed (idle)" after the child is running again would break "one cycle, exactly one frame". * 1.284 C2 RULING (宁发勿丢): entry EVICTION (TTL / LRU / abandon / disposeAll / session reap) voids * the park PROMISE, not the frame — `flush` delivers the park-time snapshot IMMEDIATELY (summary * undecorated, honest ungated degradation) and unsubscribes the quiescence watcher; the pre-fix * leak left the watcher alive (a late quiescence poke delivered a ZOMBIE notification for an entry * long gone, and a never-settling grandchild pinned watcher + captured frame forever). */ deferredNotify?: { seq?: number; cancel: () => void; flush: () => void; }; /** The in-flight resume run's abort controller (parent-terminal cleanup aborts it — r1-M2). */ activeAbort?: AbortController; /** Unpin + explicitly release the retained session (best-effort: a release that rejects leaves the session standing and nothing retries it — a detached eviction's rejection reaches `RetainLedgerHooks.onEvictionError`; a damaged placed row is the operator's, see SessionStore.deleteUnreadable). * Answers what it decided ({@link RetainReleaseDecision}) — the one decision a departure's continuation is restated from. */ release: () => Promise<RetainReleaseDecision>; /** Called once when the entry leaves the ledger, on every path out (an eviction of any cause, an abandon), after its parked * notification was handed over: the cause, and the release decision that departure took (an abandon's: `not_released`). * Given at registration by the lane that holds the row (a synchronous child's entry carries none). */ onLeave?: (cause: RetainLeaveCause, released: Promise<RetainReleaseDecision>, entry: SubagentRetainEntry) => void; /** The continuation the host lane last heard for this entry — written where a cycle's terminal (or the restatement that follows a * landed terminal) went out while the entry was held. A departure compares against it ({@link restateOnLeave}); its emitter * sends nothing for a cycle the row has moved past (a later cycle whose terminal went out on no host lane leaves it standing). */ stated?: StatedContinuation; } /** What a retained entry's release decided: `kept_durable` — a confirmed durable row keeps the transcript (the pin came off); * `released` — the entry let its conversation go; `not_released` — nothing was let go (an abandon: a committed checkpoint owns * the session; or a row never verified as this tree's); `release_failed` — the release rejected. */ export type RetainReleaseDecision = "kept_durable" | "released" | "not_released" | "release_failed"; /** * Why an entry left the ledger. The five the ledger itself drives are the wire's {@link ContinuationEndedBy} (the lazy sweep * and the per-entry timer are two mechanisms of one cause, `ttl`); the lane's own three — `killed` (a stop evicts the entry at * the cycle's settle), `pin_failed` (the retention never held), `durable_pause` (the cycle parked: a checkpoint owns the * session) — and `row_unverified` (the row's owner was never verified, so the entry is dropped) all happen before the * cycle's terminal frame, with no stated continuation to restate, so they never reach a frame; `replaced` — a registration * under the same key took the entry's place (nothing is released) — is the ledger's own and never reaches a frame either. */ export type RetainLeaveCause = ContinuationEndedBy | "killed" | "pin_failed" | "durable_pause" | "row_unverified" | "replaced"; /** The continuation a cycle's frame stated to the host lane, as its entry keeps it ({@link SubagentRetainEntry.stated}). */ export interface StatedContinuation { /** The cycle the statement speaks for. */ readonly seq: number | undefined; /** What it stated (the judge's projection). */ readonly claim: { resumable: boolean; resumableUntil?: number; }; /** The same judgment again, now that no live entry stands: the durable half is the departure's release decision. */ judgeLeft(durableRow: DurableRungRowFacts | undefined): { resumable: boolean; resumableUntil?: number; }; /** Send the restated answer on the host lane the statement went out on (a `continuation` frame) — only while that cycle is * still the row's latest (a wake in any lane, a revival once the entry is gone included, moves the row past it). A statement * is only kept for the row's latest cycle, so an older cycle's late terminal never overwrites a newer one's. */ emit(claim: { resumable: boolean; resumableUntil?: number; }, endedBy?: ContinuationEndedBy): void; } /** * A departure's restatement: when the entry that left held a stated continuation, wait for the departure's release decision, * judge again (no live entry; the durable half is whether the release kept a durable transcript) and — when the projection * differs from what the host heard — send one `continuation` frame naming the cause. Whether that statement still speaks for the * row's latest cycle is the emitter's one check (a wake that opened a later cycle, in any lane, moves the row past it: that * cycle's own terminal then speaks). No stated continuation (the cycle's terminal has not gone out, or went out on no host lane): * nothing to compare, nothing sent — the cycle's own terminal reads the ledger as it is. Settles once the departure's statement * is settled (sent, or found unchanged, or nothing to state) — never rejects. */ export declare function restateOnLeave(entry: SubagentRetainEntry, cause: RetainLeaveCause, released: Promise<RetainReleaseDecision>, durableRow: DurableRungRowFacts | undefined): Promise<void>; /** HRD-AGO-5 — deployment-side sinks for the retain ledger's background failures. */ export interface RetainLedgerHooks { /** * A detached eviction's `release` (unpin + session release) FAILED. The row is already gone from the ledger * (containment is synchronous), so this is not recoverable state — it is the honest signal that a retained * session may still be pinned in the session store, which was previously either an `unhandledRejection` on * the host process or nothing at all. A throwing sink is swallowed (it cannot strand the reaper). */ onEvictionError?: (info: { parentToolCallId?: string; trigger: RetainLeaveCause; error: Error; }) => void; } /** * design/122 D1 — the parent-run-scoped RETAIN ledger (`TaskSpec.retainSubagentSessions`). Created by * `prepareTask` when the spec opts in, threaded to delegation tools as the TRUSTED `ctx.subagentRetain`, * and disposed by the Runner in the task's terminal `finally` (D4: abort in-flight resumes + unpin + * release every retained session — retain is NOT durable; a retained resume is reachable only while its * ledger holds the entry: the parent run's, or the parent session's for a session-scoped child). Leaks are * double-bounded by `max` + `ttlMs`. */ export declare class SubagentRetainLedger { readonly ttlMs: number; readonly max: number; private entries; /** Tombstones: ids that WERE (or would have been) retained but got evicted — their resume rejects `resume.evicted`. * fix-C2: capped FIFO (see `tombstone`) — a long-lived SESSION ledger kept producing unique failed * toolCallIds, so an uncapped set grew without bound for the session's whole life. */ private evictedIds; /** fidelity R4-1: per-entry unref'd TTL timers, armed at `markSettled` — ACTIVE expiry enforcement. * The lazy `sweepExpired` used to be the only reaper, so a ledger nobody touched again (no later * spawn/resume on it) kept its pinned sessions until process end. Cleared on evict/abandon/dispose; * the lazy sweep stays as the backstop (and the only reaper for absurd over-clamp TTLs). */ private ttlTimers; private isDisposed; private readonly hooks; private failedEvictions; private lastFailure; /** RB-463: the shared host-callback isolation scope (this ledger's own `onEvictionError` sink lives on it). * The EVICTION counters above are a different quantity and stay: they count evictions that failed, not * invocations of the sink that threw. */ private readonly notifier; constructor(config: true | { ttlMs?: number; max?: number; }, hooks?: RetainLedgerHooks); /** HRD-AGO-5 — how many DETACHED evictions failed to release their session on this ledger. Non-zero means * some retained session may still be pinned in the session store. Observable even with no sink wired. */ get evictionFailureCount(): number; /** HRD-AGO-5 — the most recent detached-eviction failure (see {@link evictionFailureCount}). */ get lastEvictionError(): Error | undefined; /** RB-463 diagnostics — how many times the deployment's `onEvictionError` SINK itself threw (distinct from * {@link evictionFailureCount}, which counts the evictions being reported). */ get evictionSinkFailureCount(): number; /** * HRD-AGO-5 — record a failure from a DETACHED call this ledger made (or that a module-level helper made on * its behalf, e.g. the session-ledger LRU disposal). Counts it, keeps the last error, and offers it to the * sink; a throwing sink is swallowed so a broken observer cannot strand the reaper. */ noteDetachedFailure(trigger: RetainLeaveCause, error: unknown, parentToolCallId?: string): void; /** * HRD-AGO-5 — the ONLY way this class issues a background eviction. `evict` removes the row + tombstones it * synchronously and only the `release` is async, so the caller never waits; but a bare `void evict(...)` made * a rejecting `release` an `unhandledRejection` on the host process (a library killing its embedder over a * best-effort cleanup) and left no trace that a session went unreleased. Every detached site routes here. */ private evictDetached; /** HRD-AGO-5 — `disposeAll` for a caller that cannot await it (the module-level session-ledger LRU). Same * contract as {@link evictDetached}: containment is synchronous, the failure is reported, never thrown. */ disposeAllDetached(cause: Parameters<SubagentRetainLedger["disposeAll"]>[0]): void; /** The one call of an entry's {@link SubagentRetainEntry.onLeave}, from every path out of the ledger (contained: a throwing * hook never strands the departure). */ private leave; /** fix-C2: hard cap on tombstones. A tombstone is only an anti-resurrection sentinel (an evicted id's * resume reads the honest `resume.evicted` instead of the generic not-retained text) — dropping the * OLDEST one merely degrades that id's error text, so FIFO eviction is a safe bound. */ private static readonly TOMBSTONES_MAX; /** fix-C2: record an eviction sentinel, FIFO-bounded (re-tombstoning an id refreshes its position). */ private tombstone; /** fix-C5: an entry's own retain window when it carries one, the ledger default otherwise. */ private effectiveTtlMs; /** The instant (epoch ms) an entry settled at `settledAt` stops being continuable: that settle plus its retain window. * The one deadline mint — the expiry fact below reads it, and a cycle's terminal frame states it for its own settle. */ untilOf(settledAt: number, e: SubagentRetainEntry): number; /** The instant (epoch ms) a settled, idle entry stops being continuable: its last settle plus its retain window. The one * expiry fact — both reapers (the lazy sweep, the per-entry timer) evict past it, and a listing states the time left * until it. While the entry runs it does not expire (its next settle moves this instant). */ continuableUntil(e: SubagentRetainEntry): number; get disposed(): boolean; get size(): number; get(parentToolCallId: string): SubagentRetainEntry | undefined; wasEvicted(parentToolCallId: string): boolean; /** LAZY TTL sweep: evict every settled idle entry whose retain TTL * elapsed (unpin + release + tombstone), so an expired session is freed at the NEXT ledger touch * (every spawn-registration and resume entry call this) rather than only when its own resume is tried. * fidelity R4-1: no longer the only reaper — `markSettled` also arms a per-entry ACTIVE timer, so * expiry fires by time even on a ledger nobody touches again. This sweep stays as the backstop. * The parent-terminal `disposeAll` stays the final backstop. `evict` removes the row + tombstones * synchronously; the release itself is fire-and-forget best-effort. */ sweepExpired(now?: number): void; /** Register a child at SPAWN (running until `markSettled`). Over `max`: the oldest settled idle entry is * evicted (unpin+release); when every slot is still running, the NEW child is NOT retained (tombstoned → * its resume rejects `resume.evicted`) and `undefined` is returned — the caller falls back to throwaway. * The entry's `declarations` hold is the ledger's from this call on: a row not taken releases it here. */ register(parentToolCallId: string, entry: Omit<SubagentRetainEntry, "running" | "settled" | "settledAt" | "activeAbort" | "deferredNotify" | "stated">): SubagentRetainEntry | undefined; /** Flip a child to settled (idle, resumable) at `settledAt` — the settle instant of the cycle that just ended, the same * instant that cycle's terminal frame states its deadline from (a lane that reads its judgment before this call hands * that instant in; absent ⇒ now). fidelity R4-1: also (re-)arms the entry's own TTL timer, so the retain window expires * by TIME, not only at the next ledger touch. */ markSettled(parentToolCallId: string, settledAt?: number): void; /** fidelity R4-1 — arm/re-arm the ACTIVE per-entry TTL reaper (unref'd: never keeps the process * alive). Idempotent with the lazy sweep: the callback re-checks the same settled/idle/elapsed * predicate, so a resume in flight (or an entry already evicted/re-settled) is left alone. The delay reads the one * expiry fact ({@link continuableUntil}), so the timer fires just past the entry's deadline wherever its settle lies. */ private armTtlTimer; private clearTtlTimer; /** 1.284 C2 — an entry leaving the ledger takes its park promise with it: deliver the parked frame * NOW (undecorated; 宁发勿丢 ruling — see the deferredNotify field doc) and unsubscribe the registry * quiescence watcher. Without this, EVERY release path (TTL timer / lazy sweep / LRU register * overflow / abandon / disposeAll / session reap) leaked the watcher: a late quiescence poke then * delivered a zombie notification for a long-gone entry, and a never-settling grandchild pinned the * watcher + captured frame forever. */ private flushDeferredNotify; /** Drop a row WITHOUT releasing (durable-pause posture: a committed checkpoint owns the session/pin — * releasing here would orphan it, mirroring the delegation tool's own no-release guard). */ abandon(parentToolCallId: string, cause: RetainLeaveCause): void; /** Evict one row: flush its parked notification (C2), abort its in-flight resume (if any), unpin + * release the session, tombstone the id; the entry's `onLeave` hears the cause and the release's decision. */ evict(parentToolCallId: string, cause: RetainLeaveCause): Promise<void>; /** design/122 D4 — parent-run terminal cleanup: abort EVERY in-flight resume + unpin + release EVERY * retained session (throwaway semantics restored; no orphan run burns tokens — same posture as * `abortBackgroundAgentsForOwner`). Idempotent; further register/resume attempts are refused. `cause` is what each entry's * `onLeave` hears: the parent run ended, the session was reaped, or the process dropped this session's ledger. */ disposeAll(cause: Extract<RetainLeaveCause, "parent_run_ended" | "session_reap" | "session_ledger_lru">): Promise<void>; } /** Look up (never create) the session-scoped retain ledger for `sessionId` — SendMessage's read side. * fix-C1: a read hit refreshes `touchedAt` (TRUE LRU) — a session kept alive ONLY by SendMessage resumes * otherwise looked stale to the cap eviction below and got its ledger disposed (aborting in-flight * resumes) while 63+ other sessions churned. */ export declare function getSessionRetainLedger(sessionId: string): SubagentRetainLedger | undefined; export declare function getOrCreateSessionRetainLedger(sessionId: string, config: { ttlMs: number; max: number; }, hooks?: RetainLedgerHooks): SubagentRetainLedger; /** Anchor ② — dispose the session's retain ledger (abort in-flight resumes, unpin + release every retained * child session) and drop it. Idempotent; wired to `TaskRegistry.onSessionReap` at retain time. Its entries leave as `session_reap`. */ export declare function releaseSessionRetainLedger(sessionId: string): Promise<void>; export declare function ensureSessionReapHook(registry: import("../core/task-registry.js").TaskRegistry): void; /** * design/122 D2 — the SINGLE resume-prompt builder: a constant TRUSTED frame core owns (operator authority + * an unpredictable correlation marker) around the operator content, which stays fenced DATA (same posture as * steer — content is never authority, and `delimitUntrusted` neutralizes fence/tag break-out sentinels). */ export declare function createResumePrompt(marker: string, content: string, origin?: "operator" | "peer"): string;