@sema-agent/core
Version:
Stateless, task-oriented AI agent core
998 lines • 75.9 kB
TypeScript
import type { McpDroppedTool } from "../mcp.js";
import { type McpUnavailableEntry } from "../mcp-failure.js";
import type { McpInstructionsEntry } from "../prompt-section-seat.js";
import type { TaskSpec } from "../types.js";
import { type AttachmentSource } from "../attachment-source.js";
import type { ChangedFilesNotice } from "../../internal/llm.js";
import { type BackgroundTaskTableRow } from "../task-notification.js";
import { type SkillListingEntry, type SkillsBlockRender } from "./synthetic-tools.js";
import { type ResolvedSkillListingBudget } from "../skill-listing-budget.js";
import { type EngineText } from "../../prompt-assembly/engine-text.js";
import { type SilentStretch, type SilentTurnReminderArm } from "./boundary-reminders.js";
/**
* Turn-boundary attachment seam: the PURE producer layer (CC `getContextAttachments`
* parity). This module is the single home of the CC-parity cadence judgment; the words of every frame whose kind a task
* can turn off are catalog messages (`prompt-assembly/catalog/events.ts`), read through the run's engine text reading
* (`AttachmentInputs.engineText`, the renderers' `say`); it holds NO harness handle, does NO I/O, and never injects anything itself — the
* run loop (runtask onTurnBoundary) is the ONLY steerer. That split exists so every trigger window is
* offline-testable and the injection gate/ordering stays at the one arbitration point the engine already has.
*
* F3 (wrapper semantics): a {@link TurnAttachment} carries the BODY ONLY — no `<system-reminder>` shell.
* The steerer wraps each body exactly once at a single call site, so double-wrap/no-wrap can't drift
* per-producer.
*/
/** Cadence constants for the todo reminder. */
export declare const TODO_REMINDER_CONFIG: {
readonly TURNS_SINCE_WRITE: 10;
readonly TURNS_BETWEEN_REMINDERS: 10;
};
/** Tool-search reminder cadence defaults.
* `EVERY_N_TURNS` gates BOTH windows (since-last-ToolSearch and since-last-reminder);
* `MAX_NAMES` bounds how many undiscovered names the body enumerates before the `(+N more)` tail. */
export declare const TOOL_SEARCH_REMINDER_CONFIG: {
readonly EVERY_N_TURNS: 15;
readonly MAX_NAMES: 10;
};
/**
* The `total_tokens_reminder` mode set.
* Each arm names what the rendered number IS, per CC's own schema prose:
* - `off` — the lane is silent. Kept as a member rather than folded into the opt-in flag because it
* is the DEPLOYMENT-RESOLVED kill switch (CC resolves the mode from env
* `CLAUDE_CODE_TOTAL_TOKENS_REMINDER` → settings → gate; sema keeps env resolution at the shell and
* carries only the resolved mode — the {@link AttachmentInputs.config.todoReminderMode} contract
* verbatim, where "wired on" and "silenced by policy" are also two independent bits).
* - `infinite` — the literal text `Infinite`.
* - `fixed` — the constant {@link TOTAL_TOKENS_FIXED_ARM_VALUE}. Together with `infinite` these are
* CC's two CONSTANT arms: they consume no measurement at all, which is exactly why they exist
* (they are the controls the countdown arms are measured against).
* - `countdown` — the live remaining budget, raw.
* - `padded-countdown` — the same, smoothed by a monotone floor so the number never jumps back.
*/
export declare const TOTAL_TOKENS_REMINDER_MODES: readonly ["off", "infinite", "fixed", "countdown", "padded-countdown"];
/**
* The closed set is spelled TWICE (the public `TaskSpec.attachments.
* totalTokensReminderMode` literal union and this array), and only the TaskSpec→array direction had
* a compile chain (runtask's AttachmentInputs assignment). The config door widens this array to
* `readonly string[]` before `includes`, so a member added HERE and never to the public union used
* to compile clean, pass the door, and render — while the public type declared it illegal. Both
* directions now refuse at compile time (the governance-codes `satisfies` lockstep form):
* - array ⊆ TaskSpec — the `satisfies` on the declaration above;
* - TaskSpec ⊆ array — the conditional below collapses the exported type to `never` (the default-
* mode constant two lines down errors immediately) when the public union grows an unlisted member.
*/
type TaskSpecTotalTokensReminderMode = NonNullable<NonNullable<TaskSpec["attachments"]>["totalTokensReminderMode"]>;
export type TotalTokensReminderMode = [TaskSpecTotalTokensReminderMode] extends [(typeof TOTAL_TOKENS_REMINDER_MODES)[number]] ? (typeof TOTAL_TOKENS_REMINDER_MODES)[number] : never;
/** The default mode. The 2026-07-30 registration of this lane rested on the premise that it is OFF by default;
* the reference flipped that default, which is the fact that reopened the ruling. Applies only ONCE the deployment has
* opted the lane in. */
export declare const TOTAL_TOKENS_REMINDER_DEFAULT_MODE: TotalTokensReminderMode;
/** CC's `fixed` arm constant (bundle `A9o`). A fixed anchor is the POINT of that arm (the
* number is meant not to move), so it is copied as the constant it is rather than re-pointed at a
* declared ceiling — a deployment that wants its own number picks a countdown arm instead. */
export declare const TOTAL_TOKENS_FIXED_ARM_VALUE = 5000000;
/** F5: per-boundary stat scan upper bound — at most this many most-recently-read files are stat'ed. */
export declare const CHANGED_FILES_MAX = 20;
/**
* F5 (记档 known limitation): `ReadEntry.lastReadAt` is wall-clock (Date.now) while `FileInfo.mtimeMs`
* is the fs clock — a cross-clock comparison (CC getChangedFiles is the same shape: its readFileState
* timestamp is also wall-clock). The 2s epsilon absorbs ordinary skew/mtime granularity; git-checkout /
* formatter storms remain a documented false-positive source (hash-confirm 抗假阳 = v2).
*/
export declare const CHANGED_FILES_MTIME_EPS_MS = 2000;
/** Per-boundary byte cap over the bundle's CLIPPABLE frames (weak-model context economics). Intact-class
* frames ride outside it — see {@link ATTACHMENT_DELIVERY_CLASS}. */
export declare const ATTACHMENT_BYTE_CAP: number;
/** How the bundle cap treats a source — see {@link ATTACHMENT_DELIVERY_CLASS}. */
export type AttachmentDeliveryClass = {
readonly class: "clippable";
} | {
readonly class: "intact";
/** The producer's own byte bound for the frame it renders from these inputs — the promise the lane
* relies on instead of clipping. A closed form of bounded quantities (a resolved budget, a list cap,
* a per-item cap, a constant), never of unbounded remote text. */
readonly bound: (inp: AttachmentInputs) => number;
};
/** The `workflow_continuation` frame's ceiling — its registry row's `maxBytes`; its producer, `workflowContinuationFrameBody`, renders within it. */
export declare const WORKFLOW_CONTINUATION_MAX_BYTES: number;
/**
* @contract attachments.delivery_class — every attachment source is one of two classes, and its event registry row
* (`dedupe`) is the one place that says which; the class answers whether the bundle cap may clip it — every source's
* consumption is recorded on the carrying message's receipt (`FrameReceipt`), never at collection. An INTACT source
* (`replace-by-key`) states a kept fact (an announced set, a drained pending list, a once digest, an announced value), so
* a clipped frame could never be recorded; the lane never clips or drops it, and the producer bounds it (`bound`: its
* input-dependent bound, else its row's `maxBytes`). A CLIPPABLE source (`repeat`) is said again at the next quiet
* boundary when it did not ride, so the bundle cap ({@link ATTACHMENT_BYTE_CAP}) may clip or drop it. Derived at load,
* total over the source union: a source with no row, or an intact one with no bound, refuses the module.
*/
export declare const ATTACHMENT_DELIVERY_CLASS: Readonly<Record<AttachmentSource, AttachmentDeliveryClass>>;
/** Whether the bundle cap must leave this source whole ({@link ATTACHMENT_DELIVERY_CLASS}). */
export declare function isIntactSource(source: AttachmentSource): boolean;
/** G1 续批 — one agent type on the delegation tool's roster (ToolSpec.agentListing, filled by
* createSubagentTool: defined agents + the built-in fork when offered). */
export interface AgentListingEntry {
name: string;
description: string;
/** Pre-rendered tool-boundary note for the `(Tools: …)` line tail (CC `gHm`/220 `WW_` @465651-465663:
* "All tools" / "All tools except X, Y" / an explicit list / "None"). Computed by the producer
* (createSubagentTool → {@link import("../../agents/subagent.js").agentToolsNote}).
*
* Omitting it no longer drops the tail. 220's `fvd` (@465664-465668) interpolates
* `WW_(def)` UNCONDITIONALLY and `WW_` is total — its no-allow/no-deny arm returns the literal
* "All tools" — so every roster line in 220 carries the boundary. sema's optional field only ever
* meant "a hand-built entry did not precompute one"; that entry's real boundary IS the full offered
* pool, so the `core/event.agent-listing.all-tools` message is substituted and the tail is now always present. Reading a line
* with no tail as "unknown boundary" was never available to the model anyway — it read as "this type
* has no tools", the one thing that is never true. */
tools?: string;
}
/** G1 通告层: a background task visible to THIS run, snapshotted at the boundary by the
* runtask-side getter (registry ground truth — the producer never touches the registry itself). */
/** A row of the background-task table ({@link BackgroundTaskTableRow}). */
export type BackgroundTaskSnapshot = BackgroundTaskTableRow;
export declare function attachmentEnvelopeTags(source: AttachmentSource): string[];
/** One due reminder. `body` is the inner text — the steerer adds the `<system-reminder>` wrapper (F3). */
export interface TurnAttachment {
source: AttachmentSource;
body: string;
/** The producer's record step for THIS frame (a window's stamp, the surfaced marks, the latch), handed over instead of
* run: the caller runs it on the receipt of the message carrying the frame (`FrameReceipt`). A frame the lane cap
* drops is not returned, so its step never runs and the frame is due again; a clipped frame keeps it. */
commit?: () => void;
/** The bound, in characters, of this frame's `steering_injected` echo when the shared display budget would cut it
* mid-row: a frame whose body is a list of rows its renderer already bounds states the bound of that list (here, the
* lane cap it rides under) so the echo is the list the model received, not the first row or two of it. Absent = the
* shared budget ({@link import("./steering-preview.js").STEERING_PREVIEW_BUDGET}). */
echoBound?: number;
/** changed_files only: the files the body lists, in order — each the (path, modification time) the model is told
* about ({@link changedFilesNoticeIn} records them on the carrying message). */
noticed?: ReadonlyArray<{
readonly path: string;
readonly mtimeMs: number;
}>;
}
/** H4 — the thin projection of a todo list kept run-local (NEVER the wire-capped `tool_end.structured` card).
* Pure CONTENT memory: the write-window anchor lives on {@link AttachmentState.todoLastWriteTurn}
* (task #51 F3 — the window resets on tool-call INITIATION, which may precede/outlive any ingest). */
export interface ListProjection {
/** ≤{@link PROJECTION_ITEMS_MAX} items, content clipped to {@link PROJECTION_CONTENT_MAX} chars. */
items: Array<{
content: string;
status: string;
}>;
}
/**
* Run-local mutable producer state, owned by the run loop (one per run, torn down with it). Mutated by
* {@link reduceToolEnd} (ingest) and {@link collectDueAttachments} (window bookkeeping on fire) — both
* synchronous and deterministic, so the state stays offline-testable despite the mutation.
*/
export interface AttachmentState {
/** TodoWrite family snapshot; undefined = TodoWrite never used this run (CC still reminds: the
* gentle "hasn't been used recently" nudge with no list section). */
todo?: ListProjection;
/** Task family (TaskCreate/TaskUpdate/TaskGet/TaskList) — keyed by task id so per-task updates from a
* PARALLEL tool batch commute (F10: distinct ids reduce to the same map in either completion order). */
taskItems?: Map<string, {
content: string;
status: string;
}>;
/** Cadence-clock value AT the last task WRITE anchor block, INCLUSIVE (task #51 F1 block units — see
* {@link advanceCadenceClock}). 口径①: the reference's counter resets ONLY on a
* TaskCreate/TaskUpdate tool_use (`a.name === bD || a.name === hF`) — a TaskGet/TaskList READ is NOT
* engagement and leaves the 10-unit window running. F3: stamped on tool-call INITIATION (the tool_use
* block existing in the transcript IS CC's anchor — qFm never checks execution outcome, so a failed or
* policy-blocked write still resets the window), via {@link stampWriteAnchor} from the message walk. */
taskLastWriteTurn?: number;
/** TodoWrite counterpart of {@link taskLastWriteTurn} (same block coordinate, same initiation-anchor
* semantics — CC BFm :480217-480219 matches the TodoWrite tool_use block by name only). */
todoLastWriteTurn?: number;
lastTodoReminderTurn: number;
lastTaskReminderTurn: number;
/** Cadence-clock value at the last `ToolSearch` tool_use block (the reference
* finds it by BACKWARD transcript scan: `turnsSinceLastToolSearch`). Same INITIATION-anchor semantics
* as {@link taskLastWriteTurn} — the block existing in the transcript is the anchor, no outcome check.
* `undefined` = never used this leg, which is the state the reminder exists for (220's scan returns the
* full transcript length there). */
toolSearchLastUseTurn?: number;
/** Cadence-clock value at the last tool_search_usage_reminder emitted (the reference's
* `turnsSinceLastReminder`, found by scanning back for the attachment entry itself). */
lastToolSearchReminderTurn: number;
/** G1 backgroundTasks (CC /compact parity): SET by the run loop when a compaction LANDS,
* CONSUMED at the next boundary the collector actually runs (a steered-away boundary carries it
* forward untouched — the collector is never called there). One-shot: post-compact announce once,
* never per-boundary nagging. A cap-starved bundle loses this one snapshot (documented trade-off,
* same class as the truncated changed_files batch): the next compaction re-arms it. */
postCompactPending: boolean;
/** G1 续批 agent_listing (CC `agent_listing_delta`): name → description of the agent types already
* ANNOUNCED this leg. `undefined` = the initial full-roster announcement is still pending (CC
* isInitial). Advanced ONLY by {@link commitAgentListing} (run-loop-owned: first-frame delivery and
* intact cap survival at a boundary — MED-3①). A durable-resume leg is SEEDED by the run loop from
* the checkpoint's `announcedListings.agents` name-set when present ([c209-C] Q5 — the boundary
* producer then diffs the CURRENT roster against the seed, so cross-leg roster drift IS
* delta-announced now that the listing frame is the ONLY roster source); an old checkpoint without
* the field falls back to the MED-3② transcript probe (seeded as the current entries when a listing
* reminder is found — drift undetectable there, conservative full re-announce when not found). */
announcedAgentTypes?: Map<string, string>;
/** [c209-C] skills_listing counterpart of {@link announcedAgentTypes}: name → description of the
* skills already ANNOUNCED this leg. `undefined` = the initial full `<skills>` block is still
* pending. Advanced ONLY by {@link commitSkillsListing} (same first-frame / intact-cap-survival
* discipline); resume seeding mirrors the agent arm (checkpoint name-set → drift diff; MED-3②
* transcript probe fallback). No CC anchor for a skills delta exists (209 ships only the initial
* full listing) — the delta arm is a mechanism-family derivation from `agent_listing_delta`,
* registered in cc-divergences. */
announcedSkills?: Map<string, string>;
/** [c209-C] R2 C7 — the model-catalog names last ANNOUNCED to the model (the initial frame's
* "Models available for the 'model' parameter:" tail, Q4). `undefined` = never announced /
* unknowable (old checkpoint, transcript-probe seed) — the delta arm then stays silent on models
* (conservative, pre-C7 behavior). Advanced by {@link commitAgentListing} when the committed
* frame carried a catalog; a durable-resume leg is seeded from the checkpoint's
* `announcedListings.models` so a catalog change across a suspend IS re-announced (the drift
* line rides the first boundary's agent_listing frame). */
announcedModels?: readonly string[];
/**
* The `padded-countdown` arm's SMOOTHING FLOOR: the highest usage figure this run has
* already published against. CC's `cumulativeUsed` (bundle: `Math.max(storedFloor, rolledOver +
* used − anchor)`, stored back) exists so the countdown never RUNS BACKWARDS when the live usage
* coordinate drops under it — a model that watched its budget shrink and then saw it grow again
* learns the number is noise.
*
* Two of CC's three maps are structurally degenerate here and that is a mapping, not a loss:
* - the per-agent KEY — CC's tracker is session-scoped and keyed by `agentId ?? "main"` because one
* CC session hosts the main agent and its subagents; a sema {@link AttachmentState} is already
* per-RUN, and a delegated child is its own run with its own state, so this scalar IS that slot.
* - the ANCHOR (`reanchorTaskBudget`, re-armed on every regular user prompt so a new user task
* counts down from the full budget again) — a sema LEG is one task epoch, so the anchor is fixed
* at 0 for the leg's whole life and the epoch reset is the next `runTask` invocation — a
* durable-resume leg INCLUDED (it re-enters through `runTask`, rebuilds this state, re-derives
* its slice window and restarts the spend coordinate, so its countdown re-anchors to the new
* leg's real remaining — the CC re-anchor arm, not a floor violation; the floor deliberately
* does NOT ride the checkpoint, since a carried floor against a fresh slice window would freeze
* the readout at "0 tokens left" over an allowance the run genuinely holds). Same lifecycle
* reasoning applies to every per-leg counter here.
* - the ROLLOVER (`rollOverContext`, which adds each compacted-away context back so the count keeps
* advancing) is likewise not owed: sema feeds a CUMULATIVE spend coordinate (`stats.tokens`),
* which a compaction never rewinds, where CC feeds the live context size.
* `undefined` = the padded arm has not rendered yet (an OFF lane, or a raw-countdown one, never
* allocates it).
*/
totalTokensFloor?: number;
}
/**
* A1-R — the date_change lane's OWN state, deliberately NOT an
* {@link AttachmentState} member: allocating that for a date-only run would activate the cadence
* content scan + projection reducers on every non-opted run (the reopen's exact finding). Two
* fields, zero reducers. `announcedDate` starts at the session anchor's announced date; the RUN LOOP
* commits it (the producer below is pure) on the carrying message's receipt — the date block rides ABOVE
* the 8KB bundle cap as a fixed ~140-byte item, so no clipping face exists (contrast tools_delta's
* drain-on-intact, which lives inside the capped bundle).
*/
export interface DateChangeState {
announcedDate: string;
}
/**
* `workflow_size_guideline_change` (the third above-cap fixed-frame lane) has NO state interface and
* no producer here on purpose: its copy is the Workflow tool's own
* `workflowSizeGuidelineChangeNotice`, and rendering it from this module would put an
* orchestration dependency on the pure attachment producer layer. Its one-field run-local state and
* its baseline/live comparison live at the single steerer instead (runtask.ts, next to the
* date_change lane it is structurally identical to). The kind is listed in
* {@link AttachmentSource} because the steer wrapper, the byte accounting and the
* `steering_injected` echo are all keyed on that wordlist.
*/
export declare function createAttachmentState(): AttachmentState;
export declare function reduceToolEnd(state: AttachmentState, details: unknown): void;
/** task #51 F2/F3 — which reminder window a tool_use block resets. Resolved by the run loop (alias-aware:
* ToolSpec.aliases over the mounted roster; retired-name normalization is gone); the producers
* here never inspect tool names themselves.
* Adds `tool_search`: not a write, but the same INITIATION-anchor mechanism (a `ToolSearch`
* tool_use block resets that lane's "haven't used it recently" window), so it rides the same walk
* instead of duplicating the message scan. */
export type WriteFamily = "todo" | "task" | "tool_search";
/**
* task #51 F3 (发起锚) — reset a write window at the cadence-clock value of the write tool_use block
* (INCLUSIVE of that block). CC's qFm/BFm anchor is the tool_use block's presence in the transcript
* (:480217-480219/:480253-480254) with NO execution-outcome check — a failed, policy-blocked, or
* suspended call still resets the 10-unit window. Callers: {@link advanceCadenceClock}'s message walk
* (the transcript-anchor moment) and the durable-resume gated-write replay (leg-local clock).
*/
export declare function stampWriteAnchor(state: AttachmentState, family: WriteFamily, clock: number): void;
/**
* 口径④ cadence clock, task #51 F1 (verified against observed CC behavior) — CC's cadence unit is the
* per-content-block assistant TRANSCRIPT ENTRY, not the physical turn. The reference mints ONE
* `{type:"assistant"}` entry PER content block: the streaming layer at `content_block_stop`
* (pretty.js:593011-593038 — `content: pnn([Pr],…)` single-block array, `rn.push` per block) and the
* `tgf` normalizer (:597284 — `content.map` → one single-block entry each). The reminder counters
* BFm/qFm (:480210-480226/:480246-480262) then tick `r++`/`o++` once per non-`_or` entry, and `_or`
* (:599513-599517) applied to a single-block entry degenerates to "is this block thinking/
* redacted_thinking" — so the 10/10 windows consume ONE unit per NON-THINKING CONTENT BLOCK. A
* `[text, tool_use]` turn costs 2 units, a parallel-k tool batch costs k(+lead) — live probe
* (bench/probes/task51-cadence-live, real reference client + stub API): `[text, tool_use]×N` fires the
* task_reminder at request #7, block-exact, where a turn-level clock predicts #11-12.
*
* Applied by the run loop once per completed assistant MESSAGE; returns the advanced clock. CC edge
* semantics kept verbatim: non-array content → `_or` false → counted as ONE entry; an empty array is
* vacuously all-thinking (`.every`) → 0. sema folds `redacted_thinking` into `{type:"thinking",
* redacted:true}` (brain/anthropic.ts B2) so matching "thinking" covers both; the literal
* "redacted_thinking" arm serves CC-shape inputs. `stats.turns` is untouched — it has unrelated
* consumers (limits/budget/telemetry) whose physical-turn semantics must not drift.
*
* F3 write anchors ride the SAME walk: a toolCall block whose name resolves (alias-aware, F2) to a
* write family stamps that window at the block's inclusive clock value — CC-exact: same-message
* leading text blocks sit BEFORE the anchor (they consumed budget but are not part of the
* since-write distance), later sibling blocks count toward it; the LAST write block wins, matching
* qFm's tail-first scan.
*/
export declare function advanceCadenceClock(state: AttachmentState, clock: number, content: unknown, writeFamilyOf: (toolName: string) => WriteFamily | undefined): number;
/**
* task #51 F4 (压缩交互) — rebase every reminder window to the CURRENT cadence clock
* when a compaction LANDS. CC's windows are recomputed per request by BACKWARD TRANSCRIPT SCAN
* (BFm/qFm): compaction removes the write tool_use anchors and the reminder attachment entries, so
* both counters find nothing (t=-1/n=-1) and only count post-compaction entries — the windows
* effectively RESET, needing another 10 non-thinking entries before the next fire. sema's stateful
* windows would otherwise survive compaction and fire at the first post-compact boundary where CC
* stays silent. Setting all four fields to `clock` makes each window measure distance from the
* compaction point — arithmetic-identical to CC's anchor loss. (If a messagesToKeep-style preserved
* segment is ever implemented, a recent anchor inside the kept tail would survive in CC — refine
* this to check the preserved segment then; recorded caveat.)
*/
export declare function rebaseCadenceWindows(state: AttachmentState, clock: number): void;
export interface AttachmentInputs {
/** COMPLETED assistant turns at this boundary (`stats.turns`). */
turn: number;
/** 口径④/F1 — the BLOCK-level cadence clock at this boundary: total NON-THINKING content blocks
* across all completed assistant messages ({@link advanceCadenceClock}, CC per-block transcript
* entries :593011/:597284 ticked by BFm/qFm :480210-480226/:480246-480262). This is the todo/task
* reminder-cadence clock — thinking blocks never consume 10/10 budget (`_or` :599513), and a
* multi-block turn consumes one unit PER block, so the windows run 2-3× faster than physical
* turns on real transcripts (text+tool_use is the norm). Write anchors ({@link stampWriteAnchor})
* are stamped in this SAME coordinate. Omitted ⇒ falls back to `turn` (correct only for the
* degenerate one-non-thinking-block-per-turn transcript). */
cadenceTurn?: number;
/** Whether TodoWrite is mounted (CC gate: no tool ⇒ no reminder, ever). */
todoMounted: boolean;
/** Whether the task-family tools are mounted. Both mounted ⇒ task_reminder wins (CC isTodoV2 branch). */
taskListMounted: boolean;
/**
* The output-style frame's body, rendered once at prepare from `TaskSpec.outputStyle` (output-style.ts);
* present ⇒ the frame is due at this boundary. The reference implementation's producer has no window: it
* attaches at every attachment cycle while a non-default style is active, so the run loop passes it at every owed
* boundary whose request does not already carry it (a leg's head) and this producer holds no state for it.
*/
outputStyle?: string;
/** SR-3 budget_usd lane: the run's cost progress against its $ ceiling, in USD. Only passed
* when `config.budgetUsd` opted in AND the task actually carries a ceiling (CC gate
* `e === void 0 → []` — no `maxBudgetUsd`, no lane). CC computes `used = sy()` (session-cumulative
* totalCostUSD) and `remaining = total − used`, both raw JS numbers; sema feeds the SAME coordinate
* its budget gate enforces (`stats.costMicroUsd`/`maxCostMicroUsd`, ÷1e6 → USD) so the model-visible
* numbers can never disagree with the `limits.max_cost_exceeded` verdict. */
budgetUsd?: {
used: number;
total: number;
};
/** The TOKEN twin of {@link budgetUsd}, fed
* from the same place for the same reason: `used` is the run's cumulative token spend
* (`stats.tokens`) and `total` is the ceiling the budget gate enforces against it
* (`rs.budget.maxTokensWindow` = min(`limits.maxTokens`, the cross-slice allocation's remainder)),
* so a model-visible countdown can never disagree with an eventual `limits.max_tokens_exceeded`.
* Core neither estimates nor discovers this pair: no ceiling declared ⇒ absent ⇒ the countdown arms
* are silent (CC's own `maxBudgetUsd === void 0 → []` posture on the sibling lane).
*
* COORDINATE NOTE (candidate divergence registration): CC's two countdown arms read two DIFFERENT
* sources — `countdown` the live remaining context window, `padded-countdown` a synthetic task
* budget (its default 15_000_000 is far larger than any real window). sema carries ONE pair, the
* enforced spend coordinate, and lets the mode pick the arithmetic over it: publishing a context
* window would mean publishing a figure core cannot make true (BYOM — the window, the tokenizer and
* the accounting belong to the deployment's model), while the enforced ceiling is the one token
* number core owns end to end. */
totalTokens?: {
used: number;
total: number;
};
/** The current stretch of silence, read off the rows the next request is built from ({@link readSilentStretch}), with the
* time on the rows' clock — passed only when the silent reminder's arm is on. */
silentTurn?: {
readonly stretch: SilentStretch;
readonly now: number;
};
/** The time since the session's clock started (ms) — passed only when the elapsed-time reminder is on. */
elapsedMs?: number;
config: {
todoReminder: boolean;
/** 口径③ — CC `r2o()` kill-switch parity (pretty.js:479167-479171; consumed by both producers at
* :480232/:480268 as `if (r2o() === "off") return []`). CC resolves the mode from env
* `CLAUDE_CODE_TODO_REMINDER_MODE` (highest precedence) else the `tengu_soft_slate_nudge` gate;
* `"off"` silences BOTH the todo and task reminder lanes even when otherwise wired on, any other
* value (or absence) = CC `"baseline"` (on). sema keeps env resolution at the deployment shell
* and carries only the resolved mode here — core reads no env. */
todoReminderMode?: "baseline" | "off";
/** Tool_search_usage_reminder lane (opt-in, default OFF). */
toolSearchReminder?: boolean;
changedFiles: boolean;
/** SR-3: budget_usd progressive reminder lane (opt-in, default OFF like every 133 member). CC fires
* it on EVERY attachment cycle while `maxBudgetUsd` is set; there is NO threshold ladder and no
* throttle window (QFm/`_Fy` are unconditional) — the "progression" is the numbers advancing with
* spend. sema mirrors that: one line per collected clean boundary, no window state here; the turn
* boundary collects the whole bundle only where the turn's own work owes the next request (a
* boundary steer must never EXTEND a finished run — the loop's continuation fact, `continues`).
*
* Attribution CORRECTED (the previous note claimed "gated `d = !t.agentId` :479177 —
* subagents never see it", which reads 220 wrong). In 220 the `!agentId` flag gates only the
* MAIN-AGENT-EXCLUSIVE producer group (`_` @607478-607522: ide_selection / output_style /
* diagnostics / memory_update / token_usage / output_token_usage). `budget_usd` sits in the SHARED
* group `g` (@607474) and its ONLY door is `maxBudgetUsd === undefined → []` — so a 220 SUBAGENT
* whose own options carry a ceiling DOES see the readout. Core follows 220. There is no
* agent-identity door in this collector to remove — the lane's reachability is entirely
* "does this task's spec carry a ceiling and opt in", which is true for a child exactly when the
* deployment gave it both. Capability位 (what the delegation lane does NOT do): `buildChildSpec`
* (agents/subagent.ts) propagates neither `maxCostUsd` nor `attachments`, so a child spawned by the
* delegation tool inherits no ceiling and no opt-in and is silent by construction; a child spawned
* through a workflow governance baseline (`WorkflowGovernanceBaseline.base`, which explicitly
* snapshots `maxCostUsd` and every other governance field) reaches the lane. */
budgetUsd?: boolean;
/**
* `total_tokens_reminder`: registered in the SHARED producer group beside `budget_usd`, so a subagent carrying its own
* ceiling sees it too. DEFAULT ON, matching the reference's own default;
* explicit `false` opts out. Before the
* flip an un-opted deployment rendered no reminder frame at all. The countdown arms still need a
* declared ceiling, so a task without one is silent either way. (Scoped deliberately to this lane:
* registering
* `<total_tokens>` in ENGINE_ENVELOPES changed the SANITIZE/DISCLOSURE faces for every
* deployment, opted or not — untrusted text carrying that spelling is now defused on the fenced
* lanes and envelope-shaped external data trips the disclosure tail. That is the
* defensive direction and unconditional by design: the envelope family must be un-forgeable
* whether or not anyone renders the real frame.)
*
* WHY IT EXISTS NOW. The 2026-07-30 registration refused it as a product-face question and rested
* on "OFF by default even in 220". 245 flips exactly that premise — its settings schema reads
* "Defaults to padded-countdown", i.e. upstream now publishes a token countdown to the model by
* default. The BYOM honesty objection is answered by SHAPE rather than by dropping it: core
* estimates nothing. The numbers are the ones the engine already enforces against
* ({@link AttachmentInputs.totalTokens}), the ceiling is the deployment's own declared
* `limits.maxTokens`, and with no ceiling declared the countdown arms simply never fire.
*
* AND WHY IT IS NOW ON BY DEFAULT: the same 245 fact that
* justified BUILDING it is a statement about its DEFAULT, so shipping it opt-in left the engine
* one ruling short of the anchor. Both halves of "is this safe on by default" hold here — the
* readout cannot be wrong (it reads the enforced coordinate, never an estimate), and it cannot
* appear where nobody asked for a ceiling (no ceiling ⇒ no numbers ⇒ silence). The `budget_usd`
* twin stays opt-in: CC has no default-on posture for it, and inventing one would be the
* unanchored move.
*
* The arm is chosen by {@link totalTokensReminderMode} (default {@link
* TOTAL_TOKENS_REMINDER_DEFAULT_MODE}); `off` there silences the lane without un-wiring it.
*/
totalTokensReminder?: boolean;
/** The RESOLVED mode (see {@link TOTAL_TOKENS_REMINDER_MODES}). CC resolves it from env /
* settings / a server gate; sema keeps env resolution at the deployment shell and carries only the
* resolved value, exactly like {@link todoReminderMode}. Absent ⇒ {@link
* TOTAL_TOKENS_REMINDER_DEFAULT_MODE}. A value outside the closed set is refused at the config
* door (`config.attachment_invalid`), never folded to the default. */
totalTokensReminderMode?: TotalTokensReminderMode;
/** The silent-turn reminder's arm, as prepare resolved it (`Prepared.runTimeReminders.lane`, boundary-reminders.ts): the
* model's traits, the task's switch, a top-level leg. Absent or `off` ⇒ silent. */
silentTurnReminder?: SilentTurnReminderArm;
/** The elapsed-time reminder, as prepare resolved it (same lane). */
elapsedTimeReminder?: boolean;
/** G1: post-compact background-task announce (opt-in, default OFF like the 133 members). */
backgroundTasks?: boolean;
/** G1: deferred-tool materialization announce (setTools delta → boundary notice). */
toolsDelta?: boolean;
/** G1 续批: agent-type roster announce (CC `agent_listing_delta`). [c209-C]: listing-family
* member — default ON at the TaskSpec layer (the frame is the ONLY roster source since the
* roster left the tool description), unlike the rest of the 133 family. */
agentListing?: boolean;
/** [c209-C]: skills listing announce (initial `<skills>` block + drift deltas). Listing-family
* member — default ON at the TaskSpec layer, same rationale as `agentListing`. */
skillsListing?: boolean;
/** G1 续批: MCP server-instruction delta announce (CC `mcp_instructions_delta`). */
mcpInstructions?: boolean;
};
/** Deferred tools whose schemas the model has NOT loaded yet (declared but not
* activated), sorted, snapshotted by the run loop.
* Only passed
* when `config.toolSearchReminder` is opted in AND the task actually has deferred tools — an empty
* or absent list silences the lane permanently. */
undiscoveredTools?: readonly string[];
/** Is the direct-call lane mounted on this run's placeholders (`Prepared.deferDirectCall`,
* i.e. `TaskSpec.deferSelfResolve` not disabled)? Selects which closing sentence the
* tool_search_usage_reminder body carries; absent ⇒ the default direct-lane posture, matching the
* spec field's own default. Meaningless unless `config.toolSearchReminder` is on. */
deferDirectCall?: boolean;
/** Boundary-time scan result (already stat'ed + EPS-filtered by the prepare-task closure). Only
* passed when `changedFiles` is opted in — OFF must mean zero stat calls upstream. */
changedFiles?: ReadonlyArray<{
path: string;
mtimeMs: number;
}>;
/** G1 backgroundTasks: the leg's live background tasks, every one (`Prepared.listBackgroundTasks`); the renderer caps the list.
* Only fetched when opted in AND `state.postCompactPending` — OFF means zero registry reads. */
backgroundTasks?: ReadonlyArray<BackgroundTaskSnapshot>;
/** G1 toolsDelta: deferred tools MATERIALIZED since the last announcement (prepare-task's
* rematerialize diff — already newly-added-only, resume-seeded actives never appear here). The
* CALLER owns consumption: drain its pending list only when the returned capped bundle actually
* retained the `tools_delta` block (cap starvation must not lose the announcement forever). */
newTools?: readonly string[];
/** `true` when the run materializes statically (activation never swaps the tools
* block): the tools_delta wording must then not claim "full schemas are loaded". Rides beside
* `newTools` because it qualifies the same frame. */
newToolsStaticFace?: boolean;
/** The subset of `newTools` that the static face could not carry in result text and
* that materialized into the tools block instead. See {@link renderToolsDelta}. */
newToolsSwappedUnderStatic?: readonly string[];
/** The same fact for the READDED arm. See {@link renderToolsDelta}. */
readdedToolsSwappedUnderStatic?: readonly string[];
/** The MCP-driven arms of the SAME tools_delta frame (removed / readded).
* Same pre-diffed input + CALLER-owned intact-survival consumption discipline as `newTools`; only
* passed when `config.toolsDelta` is opted in. See {@link McpToolsDeltaFacts} for reachability. */
mcpToolsDelta?: McpToolsDeltaFacts;
/** G1 续批 agent_listing: the boundary-time roster snapshot of the mounted delegation tool
* (prepare-time static in practice; the producer's delta path serves dynamic-registration
* deployments and tests). Only passed when `config.agentListing` opted in. */
agentListing?: ReadonlyArray<AgentListingEntry>;
/** The delegation tool's mounted name — interpolated into the roster headers ("…for the
* Agent tool:"); byte-identical to CC under the default name "Agent". */
agentToolName?: string;
/** [c209-C] Q4 — model catalog names for the agent_listing INITIAL frame's trailing
* "Models available for the 'model' parameter:" line (no CC anchor — CC's model face is a static
* tier enum; sema's catalog is deployment-dynamic, so the names ride the same frame the roster
* does instead of the tool description's cached prefix). [c209-C] R2 C7: a delta frame re-carries
* the full line ONLY on catalog drift against the KNOWN announced catalog
* ({@link AttachmentState.announcedModels}, checkpoint-seeded across legs); otherwise the
* execute-time unknown-model error text remains the fallback disclosure (design/C §2.2). */
agentModels?: readonly string[];
/** [c209-C] skills_listing: the boundary-time skills snapshot (prepare-time static in practice —
* the delta path serves dynamic-installation deployments and tests, same posture as
* `agentListing`). Only passed when `config.skillsListing` is on. */
skillsListing?: ReadonlyArray<SkillListingEntry>;
/** The listing family's budget, resolved once at the config door: `agent_listing` and `skills_listing`
* are each folded into it (each frame measured against the whole number, not a share). Absent ⇒ the
* seat reader's no-knob answer. */
listingBudget?: ResolvedSkillListingBudget;
/** G1 续批 mcp_instructions: pending deltas snapshotted from `MaterializedMcp.instructionsDelta`.
* CALLER-owned consumption on intact cap survival (same `newTools` discipline). */
mcpInstructions?: {
added: ReadonlyArray<McpInstructionsEntry>;
removed: readonly string[];
};
/** The run's engine text reading (its locale's): the frame's catalog lines render through it, and the caller's
* intact-survival check renders through the same one. The Runner's boundary always hands it; absent ⇒ canonical. */
engineText?: EngineText;
/** [cc216] mcp_dropped_tools: intake-dropped MCP tools snapshotted from
* `MaterializedMcp.droppedTools` (rides the `mcpInstructions` opt-in — same MCP announce lane).
* CALLER-owned consumption on intact cap survival (same `newTools` discipline). Tool names are
* pre-neutralized at the mcp.ts producer; reasons are core-authored. */
mcpDroppedTools?: ReadonlyArray<McpDroppedTool>;
}
/**
* Compute every reminder due at this clean turn boundary. Pure decision + render — no I/O, and no record:
* what a delivered frame records (a reminder window's stamp, the surfaced marks, the post-compaction latch) is
* the frame's own {@link TurnAttachment.commit}, decided HERE beside the render (so the two cannot drift) and
* run by the caller on the receipt of the message that carries it. Two writes are not records of delivery and
* stay here: the padded countdown's floor (a fact about the measured usage) and the latch an EMPTY registry
* consumes (nothing is rendered, so nothing is owed).
*
* Returns attachments in EVIDENCE-STRENGTH order (todo/task → tool_search_usage_reminder →
* output_style → silent_turn_reminder → elapsed_time_reminder → budget_usd → total_tokens_reminder → background_tasks → tools_delta → agent_listing →
* skills_listing → mcp_instructions → mcp_dropped_tools → changed_files), which is also the §R3
* MED-6 truncation order read backwards: under the 8KB cap changed_files is sacrificed first, the
* todo/task list last. The G1/续批 members are registry/engine ground truth (strong), but the
* todo/task lane keeps priority: it carries the run's own work-tracking state, which the model can
* least afford to lose.
*/
export declare function collectDueAttachments(state: AttachmentState, inp: AttachmentInputs): readonly TurnAttachment[];
/**
* The changed_files frame for one scan's result — the ONE collector, shared by the turn boundary's bundle and a leg's first
* request: every file the scan found changed and not read again, or `undefined` when there is none. Whether the model was
* already told is not this collector's question: it is asked of the request's own view, which carries each listed
* (path, modification time) once (`request-copy-projection.ts`, over the record {@link changedFilesNoticeIn} writes). So a
* notice the request lost — the byte cap starved it, a trim or a summary took it — is minted again by the next scan, and
* the record step is nothing.
*/
export declare function collectChangedFilesAttachment(changed: ReadonlyArray<{
path: string;
mtimeMs: number;
}>, say?: EngineText): TurnAttachment | undefined;
/**
* The same frame for a leg's first request, under the bundle's own lane cap ({@link ATTACHMENT_BYTE_CAP}, the one cut
* {@link capAttachments} makes): the list is unbounded where the boundary clips it, so a frame the first request carries is clipped
* by the same function, alone — it is the one clippable frame a first request owes.
*/
export declare function collectChangedFilesFirstRequestFrame(changed: ReadonlyArray<{
path: string;
mtimeMs: number;
}>, say?: EngineText): TurnAttachment | undefined;
/**
* The record of a changed_files block as it stands in `text` — the message that carries it (its `changedFilesNotices`):
* `block` is the frame's minted bytes, found at their first occurrence; each listed file is found
* at its own list line in them, in order, and a file whose line the byte cap cut (with every one after it) is not listed.
* `undefined` when the block is not in `text` or lists no whole line — the request then carries it as written.
*/
export declare function changedFilesNoticeIn(text: string, block: string, frame: TurnAttachment): ChangedFilesNotice | undefined;
/**
* The `tool_search_usage_reminder` renderer text, with the two
* interpolations resolved: the name list (+ `(+N more)` tail when the census exceeds
* {@link TOOL_SEARCH_REMINDER_CONFIG}.MAX_NAMES) and the ToolSearch tool's mounted name — sema mounts
* the same name. The quoted `select:<name>[,<name>...]` form is also sema's real ToolSearch contract
* (tool-disclosure.ts's `select:` prefix parser), so the copy stays true rather than merely quoted.
*
* ONE sema amendment, the same one DD-5 already applied to the sibling ToolSearch description: the
* closing sentence is POSTURE-AWARE rather than an absolute failure promise. With the
* direct-call lane mounted — the default (`TaskSpec.deferSelfResolve` not disabled) — a call on a
* still-deferred tool whose arguments match the real schema EXECUTES and activates it, so "calling a
* tool before its schema is loaded will fail" is false for that posture. This face must not assert an
* execution gate the engine does not implement; the steer stays pessimistic on purpose (activate
* rather than guess — inventing arguments for an unseen schema is the real failure) but is phrased as
* the reason it is true. The `deferSelfResolve: false` posture keeps the absolute wording, which is
* exactly true for it.
*/
export declare function renderToolSearchUsageReminder(undiscovered: readonly string[], directCallEnabled?: boolean, say?: EngineText): string;
/**
* SR-3 — the reference's `budget_usd` template (cli296.js:250449: "USD budget: $"):
* `USD budget: $${used}/$${total}; $${remaining} remaining`
* `remaining = total − used` is computed producer-side in CC (QFm :480427 `n = e - t`) and re-derived
* here from the two inputs — one fewer number to drift. CC interpolates RAW JS numbers (sy() is a
* float accumulator; no rounding anywhere in QFm or the renderer), kept verbatim: sema's inputs come
* from integer micro-USD ÷ 1e6, so they render with ≤6 decimals by construction.
*/
/** A1 — the date-change reminder (`core/event.date-change`), in `say`'s reading. */
export declare function renderDateChange(newDate: string, say: EngineText): string;
/**
* A1-R — the date_change producer (CC attachments.ts:1400-1443 parity): the system-prefix
* date is FROZEN for the session segment (upstream: "cached for the duration of the conversation" — re-rendering
* the prefix at midnight costs ~920K effective tokens per overnight session, upstream's own comment);
* when the boundary-time LOCAL date walks away from the last announced one, the model is told at the
* TAIL instead. String INEQUALITY (backward NTP jumps announce too). PURE — the caller commits
* `state.announcedDate = today` when the carrying message's receipt settles (see {@link DateChangeState}).
*/
export declare function collectDateChange(state: DateChangeState, today: string, say: EngineText): TurnAttachment | undefined;
/** The silent-turn reminder's one sentence. */
export declare function renderSilentTurnReminder(say: EngineText): string;
/** The elapsed-time reminder for a duration: whole minutes and the seconds past them in two digits ({@link elapsedTimeSlots}). */
export declare function renderElapsedTime(ms: number, say: EngineText): string;
export declare function renderBudgetUsd(used: number, total: number, say?: EngineText): string;
/**
* The whole body is the one-line envelope (cli296.js:188983): "<total_tokens>N tokens left</total_tokens>",
* where N is the arm's own substitution — the literal
* `Infinite`, the {@link TOTAL_TOKENS_FIXED_ARM_VALUE} constant, or the remaining count clamped at
* zero (CC's `Math.max(0, …)`: an over-spent run reads `0 tokens left`, never a negative number).
*
* `remaining` is ignored by the two constant arms — the caller passes whatever it has (the producer
* passes 0), matching CC, whose own producer computes `0` for them.
*
* The `<total_tokens>` tag is an ENGINE-MINTED authority envelope: it is registered in the
* `ENGINE_ENVELOPES` census (untrusted-text.ts) and is in the fenced family, so the same spelling
* arriving inside untrusted content is defused rather than read as this readout. Its own body needs no
* escaping in return — every byte here is engine copy or a finite number.
*/
export declare function renderTotalTokensReminder(mode: TotalTokensReminderMode, remaining: number, say?: EngineText): string;
/**
* SR-7 — the `orphaned_background_tasks` frame (`core/event.orphaned-background-tasks*`, the reference's "The container
* was restarted" notice): the aggregated orphaned-background-task notice a restarted/resumed leg injects ONCE (CC's own
* `<system-reminder>` wrapper is added by the caller — sema's single-wrap-point discipline, F3). Line shape CC-exact:
* `- ${description || "(no description)"} (task ${id})` — `||` kept (an EMPTY description also reads
* "(no description)", CC-same). Consumed by the runtask durable-resume path, NOT a boundary producer:
* the trigger is the resume itself (CC gate `CLAUDE_CODE_RESUME_INTERRUPTED_TURN`, :707384), not a
* cadence window.
*/
export declare function renderOrphanedBackgroundTasks(tasks: ReadonlyArray<{
id: string;
description?: string;
}>, say: EngineText): string;
/**
* Per-frame list cap for the `deferred_tools_delta` arms.
* Lists longer than this collapse to a grouped one-liner + "…and N more".
*/
export declare const TOOLS_DELTA_LIST_MAX = 30;
/** The MCP-driven arms of the deferred-tools announce. All fields are pre-diffed by the
* producer (prepare-task's `rematerialize` seam / the materialize-time failed-server projection) and
* are CALLER-drained on intact cap survival, exactly like {@link AttachmentInputs.newTools}. */
export interface McpToolsDeltaFacts {
/** Previously-announced deferred tools that LEFT the harness roster (their server withdrew them —
* reached through RefreshMcpTools's prefix re-splice). */
removed?: readonly string[];
/** Previously-announced-then-withdrawn deferred tools that came BACK. */
readded?: readonly string[];
}
/**
* The `mcp_unavailable` frame — the declared MCP servers that did not connect for this message, each the once-per-session ledger's
* pair (`name` and the REMOTE `error` text, neutralized and bounded at intake). A server whose failure record carries `authorization`
* is told in the needs-authorization arm ahead ({@link needsAuthorizationArm}), every other in the reference's failed-servers arm
* "configured but failed to connect", its duration clause the truth of each server: one whose failure the session's pool remembers
* (`remembered`) is unavailable (cli321.js:289065) "for this session" — it is dialed again only when its declaration changes or the
* host has it reconnected (mcp-connection-pool.ts `attempt`); any other is unavailable "for now" and tried again by the next message.
* A server line is `name: "<error>"`, or `name <error>` — `name (class)` — when the entry's `error` is its class line (`classLine`: a multi-tenant
* deployment's model reads no remote words of a failed dial).
*/
export declare function renderMcpUnavailable(entries: ReadonlyArray<McpUnavailableEntry>, say?: EngineText): string | undefined;
/** Whether the `mcp_unavailable` lane is on for a task's attachments config — the one reading, asked by the config door (so a switch
* nobody can read refuses the task before any resource is acquired) and by the leg's first request: absent is the registry's
* default, a boolean is itself (an explicit `true` is not vetoed by a registry flip), anything else is refused by name
* (`config.invalid_argument`, `detail.field`), never read as either state. */
export declare function mcpUnavailableOn(cfg: TaskSpec["attachments"] | null): boolean;
/** The boolean switches of the attachments config whose absence is their kind's registry default — one reading for each, asked
* by the config door and by the lane: absent is the registry's default, a boolean is itself, anything else is refused by name. */
export declare function attachmentSwitchOn(cfg: TaskSpec["attachments"] | null, key: "mcpUnavailable" | "silentTurnReminder" | "elapsedTimeReminder", kind: AttachmentSource): boolean;
/** The `mcp_unavailable` frame a leg's first request owes — a fresh leg's first message or a resumed leg's continuation, the one
* request every leg makes — or undefined (the lane is off, or nothing is pending). `entries` is what the frame names; the
* carrying message's receipt settles exactly those. */
export declare function owedMcpUnavailable(prepared: {
readonly mcpUnavailable?: {
pending: McpUnavailableEntry[];
};
readonly engineText: EngineText;
}, cfg: TaskSpec["attachments"] | null): {
body: string;
entries: McpUnavailableEntry[];
} | undefined;
/**
* G1 — deferred-tool materialization announce (boundary notice). The reference's template (cli296.js:128211): "The following deferred tools are now available via", in full:
* "The following deferred
* tools are now available via ${ToolSearch}. Their schemas are NOT loaded — calling them directly
* will fail with InputValidationError. Use ${ToolSearch} with query \"select:<name>[,...]\" to load
* tool schemas before calling them:" — but CC announces DISCOVERABLE tools (schemas still deferred),
* while sema announces MATERIALIZED tools (tool_search already ran setTools; schemas ARE live), so
* the middle clause is inverted to match sema's actual contract. Same CC shape: lead sentence +
* name list.
*
* CC 2.1.220 (`deferred_tools_delta`, cli250.js:45890-45918) carries SIX arms; sema
* shipped only the `added` one. The arms below are the ones whose STATE IS REACHABLE in this engine
* (data-side audit):
* - `readded` / `removed`: reachable via RefreshMcpTools — the refresh splices a
* server's whole `mcp__<server>__` prefix domain out of the live tool array and pushes the fresh
* listing back, so a withdrawn tool genuinely leaves (and a re-advertised one genuinely returns)
* the roster mid-task. CC's trailing "Load via ToolSearch as before" / "Do not search for them —
* ToolSearch will return no match" clauses are kept, because sema mounts the SAME ToolSearch name.
* The reference's `failed` and `needs-auth` arms are their own frame here ({@link renderMcpUnavailable}): they must reach the leg's first request.
* DELIBERATELY ABSENT (state unreachable — announcing it would be a §25 honesty breach):
* - `pending`: `materializeMcpTools` is fully AWAITED inside prepareTask (one
* `Promise.allSettled` over every server) before the run loop's first turn, so "still connecting"
* does not exist at any turn boundary — `McpServerStatus.status` is `connected | failed` only.
* Returns `undefined` when every arm is empty (CC `i.length === 0 → []`).
*/
export declare function renderToolsDelta(input: {
added?: readonly string[];
staticFace?: boolean;
/** The subset of `added` that the STATIC face could not carry and that therefore
* materialized into the tools block instead (a declaration too large to inline in result text,
* or one that does not serialize; see the per-tool exemption in prepare-task). Empty/absent on
* every ordinary static run, which keeps the common frame byte-identical; when it is non-empty
* the static wording below would otherwise assert compact placeholders for a name the model can
* see carries a full schema. Meaningless unless `staticFace` is true. */
swappedUnderStatic?: readonly string[];
/** The same exemption fact for the READDED arm (a name announced earlier, withdrawn, and now back).
* The exemption is sticky within a leg, so a tool that was ever exempt is remounted with its full
* declaration on readdition — and the readded wording, like the added wording, would otherwise
* assert compact placeholders the model can see are not there. */
readdedSwappedUnderStatic?: readonly string[];
} & McpToolsDeltaFacts, say?: EngineText): string | undefined;
/** The initial-roster header (`core/event.agent-listing`) with the tool name interpolated — read through one reading for
* the renderer AND the run loop's resume transcript probe (MED-3②: "was the listing ever delivered?"). */
export declare function agentListingInitialHeader(toolName: string, say?: EngineText): string;
/** The roster-drift header (`core/event.agent-listing.added`) — same one-reading rationale as {@link agentListingInitialHeader}.
* The interpolated tool name is neutralized on both headers: a caller renames the delegation tool, so
* the name is deployment text arriving on the marked-reminder lane like every other field here. */
export declare function agentListingDeltaHeader(toolName: string, say?: EngineText): string;
/** The removal-frame header of the agent-type roster (`core/event.agent-listing.removed`; renderer + replay parser). */
export declare function agentListingRemovedHeader(say?: EngineText): string;
/** The agent listing's three headers under one reading (the transcript replay reads them under every reading, `listing-replay.ts`). */
export declare function agentListingHeaders(toolName: string, say?: EngineText): {
readonly initial: string;
readonly delta: string;
readonly removed: string;
};
/**
* G1 续批 — agent-type roster announce (`agent_listing_delta`, cli296.js:250594),
* headers with the tool name interpolated — byte-identical to the reference under the default "Agent").
* First call (no announced map) = CC `isInitial`: full roster under "Available agent types…", plus the
* concurrency note when more than one type is offered. Later
* calls announce only drift: adds under "New agent types are now available…", removals under "The
* following agent types are no longer available:" + `- <name>` lines, followed by the
* ambient-context message. Name-keyed like CC: a description
* change on an existing name is not re-announced. Every line carries a `(Tools: …)` tail (
* 220 `fvd`/`WW_` @465651-465668 — the model needs each type's tool boundary to pick a type;
* PARITY-SPOT-AGENT-TYPES F3), defaulted to the all-tools message when the entry precomputed none.
*
* ShowConcurrencyNote, honest attribution: `entries.length > 1` is a sema APPROXIMATION, not
* CC semantics. 220's real predicate (@607882) is `Aa() !== "pro" && Cq() === "default"` — subscription
* tier is not "pro" AND the output style is the default one. The tier axis does not exist in core (BYOM has no
* subscription plane) and the style axis is only a declared seat (`TaskSpec.outputStyle`), so the predicate is
* untranslatable as a whole, and
* 220's intent — "show the parallel-launch hint to users who have not already been told it elsewhere" —
* has no sema carrier either. The roster-size proxy is kept because it is the one honest thing core can
* say: a single-type roster cannot be launched concurrently with a different type, so the note would be
* noise. RESIDUAL (divergences candidate): under a >1 roster sema shows the note where 220 would hide it
* for a pro/non-default-style user.
*
* Added/removed ordering: adds are sorted by `localeCompare` and removals by the default
* `sort()`, exactly as 220 does at @607873 (`c.sort((p,f) => p.agentType.localeCompare(f.agentType)), u.sort()`).
* This is not cosmetic here: the announced-set advance ({@link commitAgentListing}) is gated on the
* rendered block surviving the capped bundle BYTE-IDENTICAL against a re-render, so a deployment that
* merely reorders its declarations between two boundaries used to mint a different byte string for the
* same content. Sorting makes the frame a function of the SET, which is what that predicate assumes.
* SCOPED to the DRIFT arms (recorded residual): 220's `c.sort` also covers the isInitial roster, but
* sema's initial order is CURATED and load-bearing — general-purpose first (the type that is always
* pickable), the deployment's definitions in declared order, `fork` last — and that curation carries
* information an alphabetical sort would destroy. The initial frame renders one array once, so it has
* no re-render byte-identity exposure of its own.
*
* PURE — never mutates `state`. The announced-set advance is CALLER-owned via
* {@link commitAgentListing}, committed on the carrying message's receipt (`FrameReceipt`).
*
* The roster is folded into the listing budget by the one folding engine ({@link foldListingWithin}),
* the skills block's sibling: every type stays listed, the last-declared ones lose their detail first,
* and the frame's size is this producer's own promise ({@link ATTACHMENT_DELIVERY_CLASS}). The report
* (`nameOnly` / `dropped`) covers the roster on an initial frame and the added set on a drift frame.
*/
export declare function renderAgentListingFrame(state: AttachmentState, entries: ReadonlyArray<AgentListingEntry>, toolName: string, models?: readonly string[], budget?: ResolvedSkillListingBudget, say?: EngineText): AgentListingFrameRender | undefined;
/** The text-only face of {@link renderAgentListingFrame} — what the delivery lanes render. */
export declare function renderAgentListingDelta(state: AttachmentState, entries: ReadonlyArray<AgentListingEntry>, toolName: string, models?: readonly string[], budget?: ResolvedSkillListingBudget, say?: EngineText): string | undefined;
/** What one {@link renderAgentListingFrame} call produced: the frame, the report, and how many types it set out to list. */
export interface AgentListingFrameRender {
text: string;
nameOnly: readonly string[];
dropped: readonly string[];
/** The denominator for the disclosure: the whole roster on an initial frame, the added set on a drift frame. */
listed: number;
}
/** The carrier prefix of the model-catalog line (`core/event.agent-listing.models` and its space) — one reading for the
* renderer and the replay parser (`listing-replay.ts`). */
export declare function modelsPrefix(say: EngineText): string;
/**
* MED-3① commit half of {@link renderAgentListingDelta}: mark the CURRENT roster as announced. The run
* loop calls this on the receipt of the message that carried the frame; an undelivered frame leaves the
* announced map untouched so the next boundary re-announces. Snapshotting `entries` wholesale is
* equivalent to add/remove bookkeeping (the diff is name-keyed; descriptions are never re-diffed).
*/
export declare function commitAgentListing(state: AttachmentState, entries: ReadonlyArray<AgentListingEntry>, models?: readonly string[]): void;
/** [c209-C] The skills listing's three headers (`core/event.skills-listing`, `….added`, `….removed`) as the run's reading
* says them — one reading for the renderer AND the run loop's resume transcript probe (MED-3② skills arm). The drift
* headers mirror the agent arm's (no CC anchor for a skills delta — mechanism-family derivation, registered in
* cc-divergences). */
export declare function skillsListingHeaders(say?: EngineText): {
readonly initial: string;
readonly delta: string;
readonly removed: string;
};
/** What one {@link renderSkillsListingFrame} call produced: the render's own report, plus the
* denominator it is against. */
export interface SkillsListingFrameRender extends SkillsBlockRender {
/** How many skills this frame set out to list — the whole roster on an initial frame, the ADDED set
* on a drift frame. The disclosure's denominator, read off the frame that was actually delivered
* rather than re-derived from the roster. */
readonly listed: number;
}
/**
* [c209-C] skills_listing producer — the skills counterpart of {@link renderAgentListingDelta}, with
* the degradation report the disclosure lane announces. First call (no announced map) = the full
* `<skills>` disclosure block VERBATIM (the exact bytes that used to sit in the stable system prompt
* now ride the reminder lane, as a
* first-user-turn reminder ~5.9KB, report §5.1). Later calls announce only drift, name-keyed like the
* agent arm: adds under the delta header ({@link skillsListingHeaders}) with the SAME `- name: description` line
* shape the block uses, removals under the removed header + `- <name>` lines,
* followed by the ambient-context message (agent-removal-arm parity). A description
* change on an existing name is not re-announced (name-keyed, agent-arm parity).
*
* ONE RULER FOR EVERY FRAME: the drift frame is measured against the SAME resolved budget as the
* initial block, arms and joiners included, and its ADD arm degrades through the same three tiers
* ({@link renderSkillLinesWithin}). The frame is an intact-class attachment — the lane never clips
* it — so this measurement is its whole bound. The split: the ambient tail and the removal
* arm's one-line floor are reserved first (both constants), the ADD arm degrades into what is left,
* and the removal arm spends whatever the add arm did not — so the frame's size is the resolved budget
* or, when even the two floors do not fit it, a small constant, never a function of the roster.
*
* The report covers the ADD arm only: `nameOnly` / `dropped` name skills this frame listed without a
* description or could not list at all. A departed name that did not fit is not a listed skill.
*
* MED-3① discipline: PURE — the announced-set advance is CALLER-owned via {@link commitSkillsListing},
* committed on the carrying message's receipt. The commit records
* EVERY entry, including one this frame dropped: the alternative is a frame re-rendering the same
* un-listable tail at every boundary, which is the replay this budget exists to end. The `Skill` tool
* serves a dropped skill, and `skills.listing_truncated` tells the deployment it happened.
*/
export declare function renderSkillsListingFrame(state: AttachmentState, entries: ReadonlyArray<SkillListingEntry>, budget?: ResolvedSkillListingBudget, say?: EngineText): SkillsListingFrameRender | undefined;
/** The text-only face of {@link renderSkillsListingFrame} — what the delivery lanes render, and what
* the intact-survival predicate re-renders to compare. */
export declare function renderSkillsListingDelta(state: AttachmentState, entries: ReadonlyArray<SkillListingEntry>, budget?: ResolvedSkillListingBudget, say?: EngineText): string | undefined;
/** [c209-C] commit half of {@link renderSkillsListingDelta} — same MED-3① contract as
* {@link commitAgentListing}: called by the run loop on the receipt of the message that carried the
* frame; an undelivered frame leaves the announced map untouched so the next boundary re-announces. */
export declare function commitSkillsListing(state: AttachmentState, entries: ReadonlyArray<SkillListingEntry>): void;
/**
* Per-server bound (in CODE POINTS, matching every other clipper in `untrusted-text.ts`) on
* ONE MCP server's `instructions` text. The text is SERVER-controlled and UNBOUNDED on the wire, and
* neither lane it rides has a cap above this one: the stable system-prompt lane has none, and the
* `mcp_instructions` attachment is intact-class (the bundle cap never clips it), so this bound IS the
* producer's promise — without it a single server could pin an arbitrarily large blob into the cached
* prompt prefix or into one boundary frame. The number is the reference's own, the same as the tool-description cap in
* `mcp.ts` ((cli309.js:274179) "MCP server instructions from 2,048 to 4,096 characters").
*/
export declare const MCP_INSTRUCTIONS_MAX_CHARS = 4096;
/**
* The ONE way MCP server-provided instruction text becomes model-facing, used by BOTH the
* stable system-prompt lane (prepare-task's `# MCP Server Instructions` block) and
* the boundary delta lane ({@link renderMcpInstructionsDelta}).
*
* The bug this closes: the same server-authored string was carried with TWO DIFFERENT trust postures
* — fenced on the delta lane, RAW-INTERPOLATED (no fence, no bound) into the stable prompt. A single
* source makes the divergence unrepresentable.
*
* Truncation is DISCLOSED (§25 honesty): the fence clips silently with an ellipsis, which reads to the
* model as the server's own text. The trailing note lives OUTSIDE the fence, on a trusted line, so the
* model can tell "the server said less" from "we cut it".
*
* The clip verdict comes FROM the fence (`delimitUntrustedWithClip`), never from a length test
* re-derived here. The earlier shape did re-derive it — a local `sanitizeUntrustedText` pre-pass with
* the DEFAULT (reminder-only) tag set, measured against the cap — and that mirror silently stopped
* matching once the fence widened its neutralization to the whole authority-envelope family: each
* widened-family tag occurrence adds an entity the pre-count never saw, so a server could land its text
* in the `(cap − N, cap]` window and get the body clipped with the honesty note withheld, N being its
* own choice of tag count. One measurement, taken where the cut happens, is the only shape that cannot
* drift.
*/
export declare function fenceMcpServerInstructions(server: string, text: string, say?: EngineText): string;
/**
* The ONE renderer of an MCP instructions entry, read by both lanes. A server's text rides the fence above;
* a host's replacement is host text and takes the reference's per-server block, `## <server>` then the
* text (cli296.js B[17396126,17396429), `Yqe`), unfenced. Both are bounded by the same per-entry cap and
* disclose the same cut, so the frame's size bound holds for the entry that actually rides.
*/
export declare function renderMcpInstructionsEntry(entry: McpInstructionsEntry, say?: EngineText): string;
/**
* G1 续批 — MCP server-instruction delta (the reference header, cli296.js:250602: "The following MCP servers have provided instructions").
* Deliberate deviations from the reference (recorded):
* - added instruction text is UNTRUSTED server-controlled text → each block rides inside a
* `delimitUntrusted` fence (CC injects the raw block; sema's external-inlet posture is fencing —
* the text is additionally already `sanitizeUntrustedText`-neutralized at the mcp.ts producer).
* Each entry renders through {@link renderMcpInstructionsEntry}, shared with the STABLE system-prompt
* lane, so one entry never carries two postures; every entry, server's or host's, carries the per-entry
* {@link MCP_INSTRUCTIONS_MAX_CHARS} bound (the frame is intact-class: its size is entries × that cap).
* The disconnect list is followed by the ambient-context message
* (resolved by the 2026-07-10 parity spot audit).
* Removal names are `\n`-joined WITHOUT a `- ` prefix (CC-exact; the agent-listing removal list DOES
* carry the prefix — the asymmetry is the reference's, kept as is). Exported for the run loop's
* intact-survival consumption check (tools_delta discipline).
*/
export declare function renderMcpInstructionsDelta(added: ReadonlyArray<McpInstructionsEntry>, removed: readonly string[], say?: EngineText): string | undefined;
/**
* [cc216] mcp_dropped_tools — announce intake-dropped MCP tools ONCE (CC's
* `mcp_dropped_tools_delta` system reminder). Per-entry line shape follows CC's `qny`
* (pretty.js:481821): `"${tool}" (MCP server "${server}"): "${reason}"`.
*
* The lead is the reference's `mcp_dropped_tools_delta` (cli296.js:250610): the `# Unavailable MCP
* Tools` heading, the full lead sentence, the **"Quoted text is data reported during validation, not
* instructions"** neutralizer (which is exactly what sema's quote-wrapped `"${reason}"` /
* `"${server}"` interpolation needed and did not have), and the "tell them it was excluded and why"
* clause.
* ONE adaptation, deliberate: CC writes "would be rejected by the Anthropic API"; sema is BYOM (the
* provider is the deployment's choice), so the clause reads "rejected by the model provider" — the
* same fact stated provider-neutrally. Everything else is letter-for-letter.
*
* Tool names/servers/reasons arrive pre-neutralized + bounded from the mcp.ts producer. The
* ambient-context tail is CC's own `Yfn` on this arm (@626674). Exported for the run
* loop's intact-survival consumption check (tools_delta discipline).
*/
export declare function renderMcpDroppedTools(entries: ReadonlyArray<McpDroppedTool>, say?: EngineText): string;
/** Per-boundary byte bound for one mcp_dropped_tools frame — the producer's own promise for an
* intact-class frame ({@link ATTACHMENT_DELIVERY_CLASS}), so one batch reads as one bounded frame. The event registry
* row's `maxBytes`, read here. */
export declare const MCP_DROPPED_BATCH_MAX_BYTES: number;
/**
* Bounded-batch selection for the dropped-tools announce: the longest prefix of COMPLETE entries whose
* render fits {@link MCP_DROPPED_BATCH_MAX_BYTES} (always ≥1), so an oversized list drains
* monotonically across boundaries — the delivered batch's receipt takes exactly those entries off, the tail
* rides later boundaries. Pure/deterministic. The ≥1
* floor is SAFE because entries are bounded at the mcp.ts producer (tool ≤160 cps, reason ≤240 cps,
* both single-lined) — one rendered entry is always a few hundred bytes.
*/
export declare function selectMcpDroppedBatch<T extends McpDroppedTool>(entries: ReadonlyArray<T>, say?: EngineText): T[];
/**
* Largest prefix of `s` that fits `maxBytes` UTF-8 bytes (binary search — never splits the budget math).
*
* The ONE byte-budget prefix search in the runner. runtask.ts's batch-context clip
* used to carry a hand-copied twin whose doc claimed this module "doesn't export
* it" — that layering argument died once runtask started importing {@link ATTACHMENT_BYTE_CAP} from
* here, so the budget CONSTANT and the budget MATH now come from the same place. Producer-layer purity
* is unchanged: this is a pure function of (string, number).
*/
export declare function clipToBytes(s: string, maxBytes: number): string;
export {};