@sema-agent/core 5.20.0 → 5.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/agents/agent-definition.d.ts +7 -0
  3. package/dist/agents/agent-transcript-tool.d.ts +30 -0
  4. package/dist/agents/builtin-agents.d.ts +60 -0
  5. package/dist/agents/cascade.d.ts +107 -0
  6. package/dist/agents/cumulative-stats.d.ts +56 -0
  7. package/dist/agents/observer.d.ts +162 -0
  8. package/dist/agents/peer-admission.d.ts +95 -0
  9. package/dist/agents/repair-loop.d.ts +226 -0
  10. package/dist/agents/retain-ledger.d.ts +141 -0
  11. package/dist/agents/roster-store.d.ts +105 -0
  12. package/dist/agents/send-message-tool.d.ts +92 -0
  13. package/dist/agents/session-util.d.ts +5 -0
  14. package/dist/agents/subagent-steps.d.ts +66 -0
  15. package/dist/agents/subagent.d.ts +600 -0
  16. package/dist/agents/suspend-guard.d.ts +29 -0
  17. package/dist/agents/teacher.d.ts +75 -0
  18. package/dist/agents/team.d.ts +120 -1
  19. package/dist/agents/tool-filter.d.ts +34 -0
  20. package/dist/agents/verify.d.ts +198 -0
  21. package/dist/bench/metrics.d.ts +455 -0
  22. package/dist/brain/anthropic.d.ts +30 -0
  23. package/dist/brain/circuit-breaker.d.ts +33 -0
  24. package/dist/brain/context-overflow.d.ts +60 -3
  25. package/dist/brain/degrading.d.ts +67 -0
  26. package/dist/brain/errors.d.ts +42 -0
  27. package/dist/brain/failover.d.ts +15 -0
  28. package/dist/brain/media-degrade.d.ts +39 -0
  29. package/dist/brain/model-presets.d.ts +31 -0
  30. package/dist/brain/open-responses.d.ts +19 -0
  31. package/dist/brain/openai.d.ts +46 -0
  32. package/dist/brain/reasoning.d.ts +106 -1
  33. package/dist/brain/repetition.d.ts +83 -0
  34. package/dist/brain/request-params.d.ts +56 -0
  35. package/dist/brain/retry.d.ts +46 -0
  36. package/dist/brain/routing.d.ts +12 -0
  37. package/dist/brain/status-sink.d.ts +30 -1
  38. package/dist/brain/stream-engine.d.ts +147 -0
  39. package/dist/brain/stream-shared.d.ts +34 -0
  40. package/dist/brain/terminal-cause.d.ts +31 -0
  41. package/dist/brain/timeout.d.ts +107 -0
  42. package/dist/brain/tool-call-id.d.ts +20 -0
  43. package/dist/brain/tool-call-repair.d.ts +13 -0
  44. package/dist/config/catalog.d.ts +47 -0
  45. package/dist/config/defaults.d.ts +33 -0
  46. package/dist/core/a2a-task-state.d.ts +53 -0
  47. package/dist/core/a2a.d.ts +51 -0
  48. package/dist/core/arg-summary.d.ts +62 -0
  49. package/dist/core/ask-question.d.ts +272 -2
  50. package/dist/core/auto-compaction.d.ts +467 -0
  51. package/dist/core/auto-compaction.js +20 -6
  52. package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
  53. package/dist/core/auto-mode-prompt.d.ts +27 -0
  54. package/dist/core/auto-mode.d.ts +54 -3
  55. package/dist/core/auto-promote.d.ts +100 -0
  56. package/dist/core/background-agent-store.d.ts +292 -0
  57. package/dist/core/background-shell.d.ts +110 -0
  58. package/dist/core/cache-break-detector.d.ts +34 -0
  59. package/dist/core/canonical-json.d.ts +57 -0
  60. package/dist/core/checkpoint-store.d.ts +1574 -16
  61. package/dist/core/compliance.d.ts +30 -0
  62. package/dist/core/consolidate-scope.d.ts +75 -0
  63. package/dist/core/context-edit.d.ts +99 -0
  64. package/dist/core/context-guard.d.ts +46 -0
  65. package/dist/core/exec-gate.d.ts +44 -0
  66. package/dist/core/exec-output-tail.d.ts +61 -0
  67. package/dist/core/file-snapshot-store.d.ts +104 -0
  68. package/dist/core/fs-write-gate-policy.d.ts +36 -0
  69. package/dist/core/git-worktree-env.d.ts +31 -0
  70. package/dist/core/governance-codes.d.ts +19 -0
  71. package/dist/core/hooks.d.ts +608 -1
  72. package/dist/core/human-input-projection.d.ts +37 -0
  73. package/dist/core/human-input-projection.js +13 -0
  74. package/dist/core/image-downsample.d.ts +74 -0
  75. package/dist/core/locked-config.d.ts +37 -0
  76. package/dist/core/lsp-diagnostics.d.ts +77 -0
  77. package/dist/core/lsp-protocol.d.ts +29 -0
  78. package/dist/core/lsp-session.d.ts +60 -1
  79. package/dist/core/lsp.d.ts +150 -1
  80. package/dist/core/mailbox-store.d.ts +57 -0
  81. package/dist/core/mcp.d.ts +381 -0
  82. package/dist/core/media-byte-cap.d.ts +21 -0
  83. package/dist/core/memory-admission.d.ts +71 -0
  84. package/dist/core/memory-engine/content-origin.d.ts +64 -0
  85. package/dist/core/memory-engine/data-plane.d.ts +43 -0
  86. package/dist/core/memory-engine/dual-root.d.ts +24 -0
  87. package/dist/core/memory-engine/engine.d.ts +230 -0
  88. package/dist/core/memory-engine/engine.js +103 -35
  89. package/dist/core/memory-engine/file-backend.d.ts +155 -0
  90. package/dist/core/memory-engine/frontmatter.d.ts +16 -0
  91. package/dist/core/memory-engine/layout.d.ts +217 -0
  92. package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
  93. package/dist/core/memory-engine/migrate.d.ts +9 -0
  94. package/dist/core/memory-engine/scan.d.ts +12 -0
  95. package/dist/core/memory-engine/scope-contract.d.ts +61 -1
  96. package/dist/core/memory-engine/sync-client.d.ts +87 -0
  97. package/dist/core/memory-engine/sync.d.ts +60 -0
  98. package/dist/core/memory-engine/tools.d.ts +41 -0
  99. package/dist/core/memory-engine/types.d.ts +188 -0
  100. package/dist/core/memory-recall.d.ts +141 -0
  101. package/dist/core/memory-vector.d.ts +20 -0
  102. package/dist/core/memory.d.ts +458 -0
  103. package/dist/core/message-utils.d.ts +6 -0
  104. package/dist/core/oracle-isolation.d.ts +69 -0
  105. package/dist/core/permission-rule-consent.d.ts +138 -0
  106. package/dist/core/permission-rule-model.d.ts +122 -0
  107. package/dist/core/permission-rule-store.d.ts +119 -3
  108. package/dist/core/permission-rules.d.ts +87 -1
  109. package/dist/core/present-plan-tool.d.ts +20 -0
  110. package/dist/core/pricing.d.ts +26 -0
  111. package/dist/core/property-harness.d.ts +86 -0
  112. package/dist/core/protocol-naming.d.ts +38 -0
  113. package/dist/core/protocol-table.d.ts +61 -0
  114. package/dist/core/push-queue.d.ts +1 -0
  115. package/dist/core/remote-env.d.ts +383 -1
  116. package/dist/core/retention-policy.d.ts +33 -0
  117. package/dist/core/retention.d.ts +51 -0
  118. package/dist/core/roles.d.ts +59 -0
  119. package/dist/core/runner/active-skill-scope.d.ts +34 -0
  120. package/dist/core/runner/assemble-result.d.ts +134 -0
  121. package/dist/core/runner/compaction-call-options.d.ts +97 -1
  122. package/dist/core/runner/grounding-signal.d.ts +10 -0
  123. package/dist/core/runner/image.d.ts +17 -0
  124. package/dist/core/runner/image.js +29 -15
  125. package/dist/core/runner/memory-consolidation.d.ts +60 -0
  126. package/dist/core/runner/prepare-memory.d.ts +59 -0
  127. package/dist/core/runner/prepare-task.d.ts +1011 -2
  128. package/dist/core/runner/prepare-task.js +12 -11
  129. package/dist/core/runner/prompt-suggestions.d.ts +7 -0
  130. package/dist/core/runner/runtask.d.ts +304 -3
  131. package/dist/core/runner/session-file-state-replay.d.ts +49 -0
  132. package/dist/core/runner/session-rule-policy.d.ts +58 -0
  133. package/dist/core/runner/strict-output-schema.d.ts +18 -3
  134. package/dist/core/runner/synthetic-tools.d.ts +113 -0
  135. package/dist/core/runner/teardown-bounded.d.ts +34 -0
  136. package/dist/core/runner/tool-disclosure.d.ts +227 -0
  137. package/dist/core/runner/tool-output-projection.d.ts +6 -0
  138. package/dist/core/runner/turn-attachments.d.ts +634 -0
  139. package/dist/core/runner/usage-accounting.d.ts +32 -0
  140. package/dist/core/runtime.d.ts +9 -0
  141. package/dist/core/safe-notify.d.ts +64 -0
  142. package/dist/core/safety-axis-vocab.d.ts +23 -0
  143. package/dist/core/safety-merge-corpus.d.ts +37 -0
  144. package/dist/core/scheduler.d.ts +121 -0
  145. package/dist/core/secret-env.d.ts +32 -0
  146. package/dist/core/select-model.d.ts +15 -0
  147. package/dist/core/sensitive-path-policy.d.ts +42 -0
  148. package/dist/core/session-policy-store.d.ts +94 -0
  149. package/dist/core/session-reconcile.d.ts +80 -0
  150. package/dist/core/session-store.d.ts +85 -0
  151. package/dist/core/session.d.ts +153 -0
  152. package/dist/core/shared-memory/contract.d.ts +22 -0
  153. package/dist/core/shared-memory/normalize.d.ts +123 -2
  154. package/dist/core/shared-memory/tools.d.ts +14 -0
  155. package/dist/core/shared-memory/types.d.ts +105 -0
  156. package/dist/core/shutdown-debug.d.ts +6 -0
  157. package/dist/core/side-query.d.ts +38 -0
  158. package/dist/core/side-query.js +6 -1
  159. package/dist/core/skill-tool-specifier.d.ts +72 -0
  160. package/dist/core/skills-directory.d.ts +100 -1
  161. package/dist/core/spec-contract.d.ts +89 -0
  162. package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
  163. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
  164. package/dist/core/store-contracts/contract-harness.d.ts +20 -0
  165. package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
  166. package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
  167. package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
  168. package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
  169. package/dist/core/strategy-store.d.ts +37 -0
  170. package/dist/core/stub-env.d.ts +7 -0
  171. package/dist/core/surrogate-safe-slice.d.ts +35 -0
  172. package/dist/core/task-notification.d.ts +202 -0
  173. package/dist/core/task-outcome.d.ts +53 -0
  174. package/dist/core/task-registry-agent.d.ts +337 -1
  175. package/dist/core/task-registry-monitor.d.ts +12 -0
  176. package/dist/core/task-registry-shared.d.ts +540 -0
  177. package/dist/core/task-registry.d.ts +343 -0
  178. package/dist/core/task-registry.js +13 -2
  179. package/dist/core/task-tool-shape.d.ts +44 -0
  180. package/dist/core/tighten-task-spec.d.ts +21 -0
  181. package/dist/core/tool-detach.d.ts +21 -0
  182. package/dist/core/tool-errors.d.ts +131 -0
  183. package/dist/core/tool-errors.js +4 -0
  184. package/dist/core/tool-name-aliases.d.ts +27 -0
  185. package/dist/core/tool-policy.d.ts +555 -0
  186. package/dist/core/tool-result-budget.d.ts +32 -0
  187. package/dist/core/tool-result-store.d.ts +174 -1
  188. package/dist/core/tools.d.ts +45 -0
  189. package/dist/core/trace.d.ts +323 -0
  190. package/dist/core/types.d.ts +3859 -2
  191. package/dist/core/untrusted-egress.d.ts +8 -0
  192. package/dist/core/untrusted-text.d.ts +156 -0
  193. package/dist/core/usage-window-store.d.ts +95 -0
  194. package/dist/core/version.d.ts +1 -0
  195. package/dist/core/warm-resume.d.ts +17 -0
  196. package/dist/core/wiring-manifest.d.ts +169 -0
  197. package/dist/core/with-retry.d.ts +24 -0
  198. package/dist/core/workflow-journal-store.d.ts +160 -0
  199. package/dist/core/workflow-run-store-contract.d.ts +25 -0
  200. package/dist/core/workflow-run-store.d.ts +119 -0
  201. package/dist/engine/compaction/compaction.d.ts +256 -1
  202. package/dist/engine/compaction/utils.d.ts +94 -0
  203. package/dist/engine/execution-env/kill-tree.d.ts +29 -0
  204. package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
  205. package/dist/engine/harness/agent-harness.d.ts +116 -0
  206. package/dist/engine/harness/agent-harness.js +3 -14
  207. package/dist/engine/harness/messages.d.ts +15 -0
  208. package/dist/engine/harness/types.d.ts +464 -2
  209. package/dist/engine/llm/diagnostics.d.ts +4 -0
  210. package/dist/engine/llm/event-stream.d.ts +3 -0
  211. package/dist/engine/llm/index.d.ts +7 -0
  212. package/dist/engine/llm/types.d.ts +500 -3
  213. package/dist/engine/llm/validation.d.ts +3 -0
  214. package/dist/engine/loop/agent-loop.d.ts +87 -2
  215. package/dist/engine/loop/runtime-deps.d.ts +7 -0
  216. package/dist/engine/loop/types.d.ts +424 -0
  217. package/dist/engine/lsp/frame-decoder.d.ts +13 -0
  218. package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
  219. package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
  220. package/dist/engine/session/import-validate.d.ts +27 -0
  221. package/dist/engine/session/log-digest.d.ts +93 -0
  222. package/dist/engine/session/memory-repo.d.ts +6 -0
  223. package/dist/engine/session/memory-storage.d.ts +2 -0
  224. package/dist/engine/session/session.d.ts +75 -0
  225. package/dist/engine/session/storage-base.d.ts +8 -0
  226. package/dist/fixtures/index.d.ts +36 -0
  227. package/dist/index.d.ts +16 -1
  228. package/dist/index.js +0 -1
  229. package/dist/internal/harness-types.d.ts +6 -0
  230. package/dist/internal/harness.d.ts +11 -0
  231. package/dist/internal/llm.d.ts +6 -0
  232. package/dist/orchestration/builtin-workflows.d.ts +53 -0
  233. package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
  234. package/dist/orchestration/goal.d.ts +57 -0
  235. package/dist/orchestration/goal.js +3 -0
  236. package/dist/orchestration/run-spec.d.ts +42 -0
  237. package/dist/orchestration/run-workflow-tool.d.ts +169 -0
  238. package/dist/orchestration/workflow-governance.d.ts +61 -0
  239. package/dist/orchestration/workflow-meta.d.ts +28 -0
  240. package/dist/orchestration/workflow-observe.d.ts +60 -0
  241. package/dist/orchestration/workflow-primitives.d.ts +23 -1
  242. package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
  243. package/dist/orchestration/workflow-script-runner.d.ts +88 -0
  244. package/dist/orchestration/workflow-script-store.d.ts +98 -0
  245. package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
  246. package/dist/orchestration/workflow-types.d.ts +169 -2
  247. package/dist/orchestration/workflow.d.ts +358 -0
  248. package/dist/prompt-assembly/artifact-store.d.ts +33 -0
  249. package/dist/prompt-assembly/artifact.d.ts +25 -0
  250. package/dist/prompt-assembly/assemble.d.ts +20 -0
  251. package/dist/prompt-assembly/composer.d.ts +29 -0
  252. package/dist/prompt-assembly/epoch.d.ts +55 -1
  253. package/dist/prompt-assembly/event-registry.d.ts +35 -0
  254. package/dist/prompt-assembly/explain.d.ts +12 -0
  255. package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
  256. package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
  257. package/dist/prompt-assembly/types.d.ts +115 -0
  258. package/dist/prompts/coordinator.d.ts +27 -0
  259. package/dist/prompts/default.d.ts +539 -0
  260. package/dist/prompts/simple-sections.d.ts +45 -0
  261. package/dist/prompts/supervisor.d.ts +66 -0
  262. package/dist/scenarios/env.d.ts +28 -0
  263. package/dist/scenarios/full-body.d.ts +50 -0
  264. package/dist/scenarios/scenario-registry.d.ts +60 -0
  265. package/dist/scenarios/teacher-quickstart.d.ts +27 -0
  266. package/dist/server/http.d.ts +17 -0
  267. package/dist/stores/cc/lockfile.d.ts +6 -0
  268. package/dist/stores/cc/mailbox-store.d.ts +8 -0
  269. package/dist/stores/cc/roster-adapter.d.ts +4 -0
  270. package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
  271. package/dist/stores/file/background-agent-store.d.ts +24 -0
  272. package/dist/stores/file/checkpoint-store.d.ts +38 -0
  273. package/dist/stores/file/file-snapshot-store.d.ts +25 -0
  274. package/dist/stores/file/fs-atomic.d.ts +155 -0
  275. package/dist/stores/file/index.d.ts +89 -0
  276. package/dist/stores/file/mailbox-store.d.ts +36 -0
  277. package/dist/stores/file/memory-store.d.ts +82 -0
  278. package/dist/stores/file/permission-rule-store.d.ts +79 -0
  279. package/dist/stores/file/session-policy-store.d.ts +28 -0
  280. package/dist/stores/file/session-store.d.ts +40 -0
  281. package/dist/stores/file/shared-ledger.d.ts +83 -0
  282. package/dist/stores/file/tool-result-store.d.ts +11 -0
  283. package/dist/stores/file/usage-window-store.d.ts +18 -0
  284. package/dist/stores/file/workflow-journal-store.d.ts +100 -0
  285. package/dist/stores/file/workflow-run-store.d.ts +11 -0
  286. package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
  287. package/dist/tools/fs/encoding.d.ts +60 -0
  288. package/dist/tools/fs/fs-bash.d.ts +133 -0
  289. package/dist/tools/fs/fs-pdf.d.ts +28 -0
  290. package/dist/tools/fs/fs-search-tools.d.ts +5 -0
  291. package/dist/tools/fs/fs-shared.d.ts +360 -0
  292. package/dist/tools/fs/fs-write.d.ts +16 -0
  293. package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
  294. package/dist/tools/fs/index.d.ts +79 -0
  295. package/dist/tools/fs/notebook.d.ts +56 -0
  296. package/dist/tools/fs/pdf.d.ts +70 -0
  297. package/dist/tools/fs/pdf.js +8 -2
  298. package/dist/tools/fs/repo-map.d.ts +10 -0
  299. package/dist/tools/fs/safety.d.ts +376 -0
  300. package/dist/tools/fs/search.d.ts +131 -0
  301. package/dist/tools/loop-tick.d.ts +24 -0
  302. package/dist/tools/monitor.d.ts +55 -0
  303. package/dist/tools/scheduler-tools.d.ts +51 -0
  304. package/dist/tools/sql-adapters.d.ts +18 -0
  305. package/dist/tools/sql.d.ts +25 -0
  306. package/dist/tools/task-list.d.ts +77 -0
  307. package/dist/tools/todo.d.ts +8 -0
  308. package/dist/tools/web.d.ts +184 -0
  309. package/dist/tools/worktree.d.ts +81 -0
  310. package/package.json +2 -2
  311. package/dist/tools/gitea-issue.d.ts +0 -13
  312. package/dist/tools/gitea-issue.js +0 -75
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.21.0 — 2026-08-09
4
+
5
+ ### BREAKING
6
+
7
+ - **`createGiteaIssueTool` / `GiteaIssueToolOptions` removed** (historical deletion). A single-vendor
8
+ HTTP integration from this repo's own early self-hosted era — the engine is the wrong layer for it.
9
+ A deployment that wants issue-filing mounts its own ToolSpec (~30 lines against its forge's API) or
10
+ an MCP server; nothing else in the engine referenced it.
11
+
3
12
  ## 5.20.0 — 2026-08-08
4
13
 
5
14
  ### BREAKING
@@ -1,2 +1,9 @@
1
1
  import type { AgentDefinition } from "../core/types.js";
2
+ /**
3
+ * Validate + freeze a declarative sub-agent definition (design/38 1B). A thin, fail-fast factory: it
4
+ * checks the only hard requirement (a non-empty `name`) and returns a shallow-frozen copy so a stored
5
+ * definition can't be mutated out from under the registry. Registry-level checks (name uniqueness,
6
+ * collision with reserved/tool names, model-ref resolution) happen when the set is handed to
7
+ * {@link createSubagentTool}, where the tool name + model catalog are available.
8
+ */
2
9
  export declare function defineAgent(def: AgentDefinition): AgentDefinition;
@@ -1,15 +1,45 @@
1
1
  import { Type } from "typebox";
2
2
  import type { Runner } from "../core/runner/runtask.js";
3
+ /** Model-facing name of the child-transcript read tool (residual lane C). */
3
4
  export declare const AGENT_TRANSCRIPT_TOOL_NAME = "AgentTranscript";
4
5
  export interface AgentTranscriptToolOptions {
6
+ /** Runner whose `sessions` store holds the child's persisted history. */
5
7
  runner: Runner;
8
+ /** The unified registry the background Agent lane registered its a* handles in (scopes reads to lineage). */
6
9
  registry: import("../core/task-registry.js").TaskRegistry;
10
+ /** design/151 S1b: the durable ledger — when the live row/retain entry is gone (restart, terminal GC,
11
+ * retain off), the row's `sessionId` still anchors the PRESERVED transcript session (the S1b
12
+ * lifecycle flip skipped its release). Reads go through `runner.sessions` — a split-store child
13
+ * (caller-mounted Agent tool with its own runner) is honestly unreadable here after a restart. */
7
14
  agentStore?: import("../core/background-agent-store.js").BackgroundAgentStore;
15
+ /** Access identity (mirrors SendMessage/TaskOutput — the mount fills these). */
8
16
  owner?: string;
9
17
  scope?: string;
10
18
  sessionId?: string;
19
+ /**
20
+ * RB-409 seat, wired by RB-448 — the mount's per-call ctx builder, forwarded to {@link defineTool}
21
+ * (see {@link import("../core/tools.js").ToolCtxEnricher}). This tool is a `defineTool` PRODUCT, so
22
+ * without it the body sees exactly `{toolCallId, signal}` and `ctx.subagentRetain` below is always
23
+ * undefined — the run-scoped retain ledger has NO other channel (its own doc calls itself "threaded
24
+ * to delegation tools as the TRUSTED ctx.subagentRetain"), so the ordinary retained child this tool
25
+ * advertises reading was structurally unreachable and every such call fell through to the durable
26
+ * lane and then to "not retained". Same seat, same builder and same rationale as the SendMessage
27
+ * twin (RB-409 fixed it there and left this sibling — extracted from the same source file in
28
+ * design/157 A7 — behind). Absent ⇒ unchanged behavior: the `opts` axes alone supply the identity.
29
+ */
11
30
  enrichCtx?: import("../core/tools.js").ToolCtxEnricher;
12
31
  }
32
+ /**
33
+ * Residual observability (lane C) — build the MODEL-VISIBLE **AgentTranscript** tool: read the last N tool steps of a
34
+ * previously spawned background agent ON DEMAND (a PULL face — it does NOT inflate the parent's context
35
+ * the way an injected residual would). `id` is the a* task_id the Agent tool returned. This is the
36
+ * complement to the stop-time residual (which the notification already carries): use it to look deeper
37
+ * into a child's tail when the residual isn't enough.
38
+ *
39
+ * Safety: reads are bounded to the parent's OWN lineage — the same non-leaking registry access scope as
40
+ * SendMessage/TaskOutput (an unknown or out-of-scope id reads identically to "not found"). Only a
41
+ * RETAINED child's session survives to be read; a throwaway child returns an honest "not retained".
42
+ */
13
43
  export declare function createAgentTranscriptTool(opts: AgentTranscriptToolOptions): import("../internal/harness-types.js").AgentTool<Type.TObject<{
14
44
  id: Type.TString;
15
45
  lastN: Type.TOptional<Type.TInteger>;
@@ -1,8 +1,68 @@
1
1
  import type { AgentDefinition } from "../core/types.js";
2
+ /**
3
+ * F1 (design/135 批次3 / PARITY-SPOT-AGENT-TYPES-2026-07-10) — the CC 2.1.198 BUILT-IN `Explore` and
4
+ * `Plan` agent types, ported to sema's AgentDefinition roster shape.
5
+ *
6
+ * 198 锚 (亲核 2026-07-10, drift 调研: 198→204→206 逐字零漂移):
7
+ * - Explore definition `qme` — pretty.js:409186-409198 (`agentType:"Explore"`, whenToUse=nbm,
8
+ * whenToUseLean=rbm, `disallowedTools:[is,NR,s0,xa,Ic,FR]` = Agent/Artifact/ExitPlanMode/Edit/Write/
9
+ * NotebookEdit, `model:"inherit"`, `omitClaudeMd:!0`, getSystemPrompt=tbm).
10
+ * - Explore whenToUse `nbm` / whenToUseLean `rbm` — pretty.js:409173-409174 (verbatim below).
11
+ * - Explore system prompt `tbm()` — pretty.js:409122-409160 (verbatim below, unix+Glob/Grep arm).
12
+ * - Plan definition `Xor` — pretty.js:486943-486953 (`agentType:"Plan"`, single whenToUse, same six
13
+ * disallowedTools, `tools: qme.tools` = undefined, `model:"inherit"`, `omitClaudeMd:!0`).
14
+ * - Plan system prompt `kBm()` — pretty.js:486874-486930 (verbatim below, unix arm).
15
+ * - Registry `HCe` — pretty.js:487221-487240: Explore+Plan ship behind `iAt()` (487127-487131:
16
+ * env kill-switch `CLAUDE_CODE_DISABLE_EXPLORE_PLAN_AGENTS` + `tengu_slate_ibis` gate DEFAULT ON)
17
+ * ⇒ GA default-on in 198 (and byte-stable through 204/206 — CC-DRIFT-198-206-AGENT-TYPES 锚 1-7).
18
+ * SDK entrypoints ship them too (only `claude-code-guide` is non-SDK); the SDK-form opt-out is
19
+ * `CLAUDE_AGENT_SDK_DISABLE_BUILTIN_AGENTS` (487221) → sema's deployment-config analog is
20
+ * `SubagentToolOptions.builtinAgents: false` (config-driven, not env-driven).
21
+ *
22
+ * sema adaptations (deliberate, each recorded):
23
+ * - De-branding (prompt-sovereignty / SUBAGENT_PROMPT precedent): CC's persona first sentences name the
24
+ * product ("… for Claude Code, Anthropic's official CLI for Claude." / "… for Claude Code.") — sema
25
+ * stays provider-neutral, the brand clause is dropped; every other byte is CC-verbatim.
26
+ * - Platform arm: CC's `tbm`/`kBm` interpolate per-platform tool guidance (unix Bash vs PowerShell) and
27
+ * a bash-only search mode (`ww()`). sema children run in a POSIX ExecutionEnv with first-party
28
+ * Glob/Grep/Read/Bash under CC-identical names — the unix + Glob/Grep arm is baked verbatim
29
+ * (Mu="Glob" :149761, Jc="Grep" :224202, Ls="Read", Lo="Bash").
30
+ * - `model:"inherit"` — sema shape: `model` omitted on an AgentDefinition = inherit the caller's current
31
+ * model (identical semantics). CC's Explore firstParty opus UPGRADE (`GAe`, 409162-409171: built-in
32
+ * Explore may upshift to opus on first-party subscriptions) is a CC-subscription ladder concern —
33
+ * NOT ported (sema is provider-neutral; inherit is the base arm both sides share).
34
+ * - `omitClaudeMd:!0` (422063: drops the CLAUDE.md user-context layer for these types) — NOT ported this
35
+ * round: sema's project-context layer is assembled in prepare-task (design/113 C4), a concurrent-batch
36
+ * conflict domain at port time. Recorded as the F7 residual; the deployment `loadProjectMemory` seam
37
+ * already receives `isSubagent`/`agentName` and can trim today.
38
+ * - `disallowedTools` → `denyTools` (sema name), with the DELEGATION-tool entry tracking the deployment's
39
+ * actual tool name (default "Agent" = CC-verbatim). "Artifact"/"ExitPlanMode" have first-party sema
40
+ * referents only partially (present_plan canonicalizes to ExitPlanMode; Artifact has none) — a deny of
41
+ * an unmounted name is a documented no-op (tool-filter), kept for CC listing-tail byte parity.
42
+ */
43
+ /** CC 198 `nbm` (pretty.js:409173) — Explore `whenToUse`, verbatim. */
2
44
  export declare const EXPLORE_WHEN_TO_USE = "Fast read-only search agent for locating code. Use it to find files by pattern (eg. \"src/components/**/*.tsx\"), grep for symbols or keywords (eg. \"API endpoints\"), or answer \"where is X defined / which files reference Y.\" Do NOT use it for code review, design-doc auditing, cross-file consistency checks, or open-ended analysis \u2014 it reads excerpts rather than whole files and will miss content past its read window. When calling, specify search breadth: \"quick\" for a single targeted lookup, \"medium\" for moderate exploration, or \"very thorough\" to search across multiple locations and naming conventions.";
45
+ /** CC 198 `rbm` (pretty.js:409174) — Explore `whenToUseLean`, verbatim. */
3
46
  export declare const EXPLORE_WHEN_TO_USE_LEAN = "Read-only search agent for broad fan-out searches \u2014 when answering means sweeping many files, directories, or naming conventions and you only need the conclusion, not the file dumps. It reads excerpts rather than whole files, so it locates code; it doesn't review or audit it. Specify search breadth: \"medium\" for moderate exploration, \"very thorough\" for multiple locations and naming conventions.";
47
+ /** CC 198 Plan `whenToUse` (pretty.js:486945), verbatim (Plan has no lean variant in 198). */
4
48
  export declare const PLAN_WHEN_TO_USE = "Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs.";
49
+ /** CC 198 `tbm()` (pretty.js:409122-409160) — Explore persona, unix+Glob/Grep arm, first sentence de-branded. */
5
50
  export declare const EXPLORE_SYSTEM_PROMPT = "You are a file search specialist. You excel at thoroughly navigating and exploring codebases.\n\n=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===\nThis is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from:\n- Creating new files (no Write, touch, or file creation of any kind)\n- Modifying existing files (no Edit operations)\n- Deleting files (no rm or deletion)\n- Moving or copying files (no mv or cp)\n- Creating temporary files anywhere, including /tmp\n- Using redirect operators (>, >>, |) or heredocs to write to files\n- Running ANY commands that change system state\n\nYour role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools - attempting to edit files will fail.\n\nYour strengths:\n- Rapidly finding files using glob patterns\n- Searching code and text with powerful regex patterns\n- Reading and analyzing file contents\n\nGuidelines:\n- Use Glob for broad file pattern matching\n- Use Grep for searching file contents with regex\n- Use Read when you know the specific file path you need to read\n- Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)\n- NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification\n- Adapt your search approach based on the thoroughness level specified by the caller\n- Communicate your final report directly as a regular message - do NOT attempt to create files\n\nNOTE: You are meant to be a fast agent that returns output as quickly as possible. In order to achieve this you must:\n- Make efficient use of the tools that you have at your disposal: be smart about how you search for files and implementations\n- Wherever possible you should try to spawn multiple parallel tool calls for grepping and reading files\n\nComplete the user's search request efficiently and report your findings clearly.";
51
+ /** CC 198 `kBm()` (pretty.js:486874-486930) — Plan persona, unix arm, first sentence de-branded. */
6
52
  export declare const PLAN_SYSTEM_PROMPT = "You are a software architect and planning specialist. Your role is to explore the codebase and design implementation plans.\n\n=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===\nThis is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:\n- Creating new files (no Write, touch, or file creation of any kind)\n- Modifying existing files (no Edit operations)\n- Deleting files (no rm or deletion)\n- Moving or copying files (no mv or cp)\n- Creating temporary files anywhere, including /tmp\n- Using redirect operators (>, >>, |) or heredocs to write to files\n- Running ANY commands that change system state\n\nYour role is EXCLUSIVELY to explore the codebase and design implementation plans. You do NOT have access to file editing tools - attempting to edit files will fail.\n\nYou will be provided with a set of requirements and optionally a perspective on how to approach the design process.\n\n## Your Process\n\n1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.\n\n2. **Explore Thoroughly**:\n - Read any files provided to you in the initial prompt\n - Find existing patterns and conventions using Glob, Grep, and Read\n - Understand the current architecture\n - Identify similar features as reference\n - Trace through relevant code paths\n - Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)\n - NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification\n\n3. **Design Solution**:\n - Create implementation approach based on your assigned perspective\n - Consider trade-offs and architectural decisions\n - Follow existing patterns where appropriate\n\n4. **Detail the Plan**:\n - Provide step-by-step implementation strategy\n - Identify dependencies and sequencing\n - Anticipate potential challenges\n\n## Required Output\n\nEnd your response with:\n\n### Critical Files for Implementation\nList 3-5 files most critical for implementing this plan:\n- path/to/file1.ts\n- path/to/file2.ts\n- path/to/file3.ts\n\nREMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write, edit, or modify any files. You do NOT have access to file editing tools.";
53
+ /**
54
+ * CC 198 `disallowedTools:[is,NR,s0,xa,Ic,FR]` (pretty.js:409189 Explore / :486948 Plan) — the six-tool
55
+ * deny set shared by both read-only built-ins, constants resolved 亲核: is="Agent"(147382),
56
+ * NR="Artifact"(143265), s0="ExitPlanMode"(149770), xa="Edit"(143358), Ic="Write"(143375),
57
+ * NotebookEdit FR(143373). The delegation-tool entry is parameterized on the deployment's actual tool
58
+ * name (default = "Agent", CC-verbatim).
59
+ */
7
60
  export declare const BUILTIN_READONLY_DENY_TOOLS: (delegationToolName?: string) => string[];
61
+ /**
62
+ * Build the built-in agent definitions offered by {@link import("./subagent.js").createSubagentTool}
63
+ * (CC `HCe` registry analog, SDK arm: Explore + Plan; general-purpose is sema's OMITTED-`subagent_type`
64
+ * fallback and fork lives in the `subagent_type` value domain — neither needs a definition here).
65
+ * A deployment definition of the same name SHADOWS a built-in (fork-shadowing precedent), and
66
+ * `builtinAgents: false` removes them wholesale (CC `CLAUDE_AGENT_SDK_DISABLE_BUILTIN_AGENTS` form).
67
+ */
8
68
  export declare function builtinAgentDefinitions(delegationToolName?: string): AgentDefinition[];
@@ -1,24 +1,98 @@
1
1
  import type { Runner } from "../core/runner/runtask.js";
2
2
  import type { ModelRef, TaskResult, TaskSpec } from "../core/types.js";
3
+ /**
4
+ * Quality-gate cascade (design/27). Run the SAME task across a ladder of models (cheapest → strongest);
5
+ * after each rung a caller-supplied **decidable gate** judges "good enough" — pass = keep it, fail =
6
+ * escalate to the next rung. Classic FrugalGPT cascade, as a thin function over `runner.runTask`
7
+ * (no Runner-core changes).
8
+ *
9
+ * APPLICABILITY: cascade only helps when the gate is **decidable** (a schema check, a verifier model, a
10
+ * concrete assertion). Open-ended "completeness" tasks (find every bug, writing quality) have no oracle —
11
+ * the gate keeps passing the first plausible cheap answer and escalation idles. Those want breadth /
12
+ * adversarial debate (a `team`), not a depth ladder.
13
+ *
14
+ * Cost note (design/27 §2): each rung is an independent COLD `runTask` — every escalation repays the
15
+ * full input cost. Cascade wins when (a) the cheap rung usually passes and (b) the prompt isn't so large
16
+ * that the restart tax dominates. It is NOT always cheaper than running the strongest model directly.
17
+ *
18
+ * Boundary vs teacher mode: teacher injects advice and continues the SAME session (recovery); cascade
19
+ * does independent re-runs on a model ladder (breadth). Orthogonal, not merged.
20
+ */
21
+ /** A gate's verdict: a bare boolean, or `{ pass, diagnostics }` to attach reasoning to `attempts[]`. */
3
22
  export type GateVerdict = boolean | {
4
23
  pass: boolean;
5
24
  diagnostics?: string;
6
25
  };
7
26
  export interface CascadeRung {
27
+ /** The model this rung runs on. */
8
28
  model: ModelRef;
29
+ /** Optional per-rung overrides (default: inherit the task's). */
9
30
  overrides?: Partial<Pick<TaskSpec, "limits" | "systemPrompt">>;
10
31
  }
11
32
  export interface CascadeConfig {
33
+ /** RB-473 — disclosure channel for CONTAINED host-callback failures in this scope (the RB-463
34
+ * isolation primitive's bounded first-failure per site). Absent ⇒ failures are counted only. */
12
35
  onNotifyError?: (failure: import("../core/safe-notify.js").SafeNotifyFailure) => void;
36
+ /** Model ladder, cheapest → strongest. ≥1 rung; the last rung is the fallback (returned even if it doesn't pass). */
13
37
  ladder: CascadeRung[];
38
+ /**
39
+ * Quality gate: given a rung's result, return whether it is good enough (true/`{pass:true}` = keep,
40
+ * false = escalate). Default: `status === "completed"` — and, if `spec.outputSchema` is set, also
41
+ * requires a valid `structuredOutput` (so a schema auto-gives "only keep a rung that actually produced
42
+ * valid structured output"; a prose-only completion escalates). The gate can be a pure check (structured
43
+ * output / fields), a verifier model, semantic agreement, etc. **A throw is treated as "did not pass"**
44
+ * (fail-open to escalate) and recorded as `attempts[].gateError` — so a broken gate can't strand the run,
45
+ * but a verifier-gate's own failure is still visible. The gate must be decidable (see APPLICABILITY).
46
+ *
47
+ * HRD-AGO-10 — a positive verdict is CONJOINED with the rung's status: it counts as a pass only when
48
+ * `result.status === "completed"`, unless {@link CascadeConfig.acceptPartial} is set. A status-blind gate
49
+ * ("the text is non-empty", "the JSON parses") could otherwise keep a blocked/failed/timeout rung, which made
50
+ * `cascadeOutcome: "passed"` disagree with the `status` the same object carries. A verdict rejected on those
51
+ * grounds is recorded as `passed: false` + {@link CascadeAttempt.statusRejected}, and the cascade escalates.
52
+ *
53
+ * @warning unredacted — the gate receives the UNREDACTED `TaskResult` (model output, structured output,
54
+ * stats); this is prose advisory, not an enforced boundary (design/54 §3.5, [46] DESIGN1). If your gate
55
+ * forwards output to an external service, ensure it has no sensitive data or sanitize first.
56
+ */
14
57
  gate?: (result: TaskResult, rung: {
15
58
  index: number;
16
59
  model: ModelRef;
17
60
  }) => GateVerdict | Promise<GateVerdict>;
61
+ /**
62
+ * HRD-AGO-10 — the explicit opt-out from the require-completed conjunction above. Two states, no middle:
63
+ * - **omitted / `false` (default)** — a {@link gate} pass counts only on a `completed` rung. Unfinished work
64
+ * is escalated, so `cascadeOutcome: "passed"` always implies the returned rung actually finished.
65
+ * - **`true`** — the gate's verdict alone decides, so a deliberately partial answer can be kept (a blocked
66
+ * rung whose partial output IS the deliverable, a timeout whose streamed prefix is good enough). The
67
+ * returned `status` still reports the truth — this only says the gate is allowed to accept it.
68
+ *
69
+ * Ignored by the default gate, which requires `completed` in either case.
70
+ */
18
71
  acceptPartial?: boolean;
72
+ /** Max escalations (rungs run ≤ maxEscalations + 1). Default = `ladder.length - 1` (the whole ladder). */
19
73
  maxEscalations?: number;
74
+ /** Stop escalating once cumulative cost reaches this; return the current best. Optional. */
20
75
  costCeilingMicroUsd?: number;
76
+ /**
77
+ * Overall wall-clock ceiling for the whole cascade (per-rung time is `spec.limits.timeout`). Optional.
78
+ *
79
+ * HRD-AGO-7 — this is a REAL deadline over the run, not just a gate on starting the next rung: each rung is
80
+ * dispatched with an `AbortSignal` that fires at `start + totalTimeoutMs` (combined with the caller's own
81
+ * `spec.signal` when there is one), so a rung already in flight when the budget runs out is ABORTED. What
82
+ * "aborted" buys is bounded by the workload's cooperation with cancellation — the brain request is cancelled
83
+ * and a tool that honors its `ToolExecuteContext.signal` stops at once, but a tool that ignores its signal
84
+ * still runs to its own completion (the run then assembles as failed the moment it returns). Cleanup on a
85
+ * cut: the rung's result is NOT gated (truncated work must never pass), its session IS released (nothing
86
+ * pins it — a durable pause is handled earlier and returns instead), the attempt is recorded with
87
+ * `timedOut: true`, and the ladder stops (`cascadeOutcome: "exhausted"`) rather than escalating past a
88
+ * deadline that has already passed.
89
+ *
90
+ * A budget already spent AT ENTRY (`0`, negative, or a caller that measured elapsed time itself) dispatches
91
+ * NOTHING and returns the cascade's own terminal: `status: "failed"`, `errorCode:
92
+ * "cascade.budget_exhausted"`, empty `attempts`, `finalRung: -1`.
93
+ */
21
94
  totalTimeoutMs?: number;
95
+ /** Per-rung callback (observability). */
22
96
  onRung?: (info: {
23
97
  index: number;
24
98
  model: ModelRef;
@@ -30,20 +104,53 @@ export interface CascadeAttempt {
30
104
  index: number;
31
105
  model: ModelRef;
32
106
  passed: boolean;
107
+ /** This rung's OWN+nested spend. ABSENT when the rung ran unpriced (RB-368 knownness, codex batch-4
108
+ * F4) — a fabricated 0 here both misreported the attempt and let escalation ride under a finite
109
+ * ceiling the engine could not actually enforce. */
33
110
  costMicroUsd?: number;
34
111
  status: TaskResult["status"];
112
+ /** The rung's own failure code (e.g. "auth") if its `runTask` failed — distinct from "gate rejected it". */
35
113
  errorCode?: string;
114
+ /** Set when the gate THREW (vs returned false) — surfaces a broken verifier-gate (expired key, etc.). */
36
115
  gateError?: string;
116
+ /** HRD-AGO-7: this rung was CUT IN FLIGHT by {@link CascadeConfig.totalTimeoutMs}. Its result is truncated
117
+ * work, so it was never handed to the gate (`passed` is always false) and the ladder stopped here. */
37
118
  timedOut?: true;
119
+ /** HRD-AGO-7: the CALLER's own `spec.signal` aborted during this rung (distinct from the cascade deadline).
120
+ * Same handling — no gate, no escalation onto an already-aborted signal. */
38
121
  cancelled?: true;
122
+ /** HRD-AGO-10: the gate returned a PASS but the rung had not `completed`, so the verdict did not count
123
+ * (`passed: false`, escalate). Set only in the default require-completed mode — never with
124
+ * {@link CascadeConfig.acceptPartial}. */
39
125
  statusRejected?: true;
126
+ /** Optional reasoning the gate attached to its verdict. */
40
127
  diagnostics?: string;
41
128
  }
42
129
  export interface CascadeRunResult extends TaskResult {
130
+ /**
131
+ * The cascade's conclusion, **distinct from the inherited `status`**: `"passed"` = some rung passed the
132
+ * gate; `"exhausted"` = ladder/guards ran out with no rung passing (the last rung's result is returned,
133
+ * and its `status` may still be "completed" — judge the cascade by `cascadeOutcome`, not `status`).
134
+ */
43
135
  cascadeOutcome: "passed" | "exhausted";
136
+ /** F4: present when a finite `costCeilingMicroUsd` was configured but some rung's spend was unpriced —
137
+ * the ceiling could not be enforced over unknown cost, so the ladder STOPPED escalating (fail-closed)
138
+ * instead of riding an unbindable budget. Judge spend by the absent cost fields, not by 0. */
44
139
  costCeilingUnenforceable?: true;
140
+ /** True if the returned result came from a rung after the first (i.e. an escalation happened). */
45
141
  escalated: boolean;
142
+ /** Which rung (0-based) produced the returned result — or `-1` when NO rung was dispatched (an already
143
+ * spent {@link CascadeConfig.totalTimeoutMs}); `attempts` is then empty and the result is the cascade's
144
+ * own synthetic `cascade.budget_exhausted` terminal, not a rung's. */
46
145
  finalRung: number;
146
+ /** Per-rung audit detail (cost, pass/fail, why). Each attempt's `costMicroUsd` includes that rung's nested
147
+ * (delegated) cost; the top-level `stats.costMicroUsd` is the sum of the rungs' OWN cost (nested totals live
148
+ * in `stats.nested.costMicroUsd`), so it is NOT the plain sum of `attempts[].costMicroUsd`. */
47
149
  attempts: CascadeAttempt[];
48
150
  }
151
+ /**
152
+ * Side-effect note: `runCascade` runs the task up to N times. If your tools have non-idempotent effects
153
+ * (`effect: "write"`), those execute once PER rung — ensure idempotency, or gate before the side effect
154
+ * (e.g. a structured-output gate). `TaskSpec` never guaranteed idempotency; cascade makes it explicit.
155
+ */
49
156
  export declare function runCascade(runner: Runner, spec: TaskSpec, config: CascadeConfig): Promise<CascadeRunResult>;
@@ -1,29 +1,85 @@
1
1
  import type { TaskResult } from "../core/types.js";
2
+ /**
3
+ * Shared CUMULATIVE-STATS constructor for the multi-leg agent compositions (cascade rungs, repair-loop
4
+ * attempts, teacher student attempts). All three run `runner.runTask` MORE THAN ONCE and must report the
5
+ * OPERATION's totals, not the last leg's.
6
+ *
7
+ * The invariant this exists to hold in ONE place: **every field the accumulator tracks is OVERRIDDEN over
8
+ * the base stats**. A field left un-overridden silently leaks the LAST leg's value dressed up as a
9
+ * cumulative total (the cascade R1-m5 / R3 trap; repair-loop shipped exactly that hole on `humanReview`).
10
+ * Three independent copies of this literal is how that hole survived in one copy while the other two were
11
+ * fixed — hence one constructor, three call sites.
12
+ *
13
+ * OWN and NESTED stay DISJOINT (the cascade R-5 / teacher A-7 convention): a consumer adds
14
+ * `stats.X + stats.nested.X` for the true total; nested cost is never folded into `costMicroUsd`.
15
+ */
16
+ /** Cumulative delegated-subagent (nested) totals, summed across every leg. */
2
17
  export interface CumulativeNestedTotals {
3
18
  tokens: number;
4
19
  turns: number;
5
20
  tasks: number;
6
21
  costMicroUsd: number;
7
22
  }
23
+ /**
24
+ * Cumulative human-review (design/91 C2 axis) burden, summed across every leg. `gates` is the ordered
25
+ * concatenation of each leg's gate entries — the element shape is the canonical one published on
26
+ * {@link TaskResult}, so a leg's entry passes through with `toolName`/`toolArg` intact.
27
+ */
8
28
  export interface CumulativeHumanReviewTotals {
9
29
  count: number;
10
30
  totalWaitMs: number;
11
31
  gates: NonNullable<TaskResult["stats"]["humanReview"]>["gates"];
12
32
  }
33
+ /**
34
+ * The running totals a multi-leg composition accumulates. Every field is REQUIRED: an optional field here
35
+ * would re-open the exact "forgot to override one" hole this module exists to close — a caller that has
36
+ * nothing to report passes zeros.
37
+ */
13
38
  export interface CumulativeStatsAccumulator {
14
39
  tokens: number;
15
40
  turns: number;
16
41
  promptTokens: number;
42
+ /** RB-457-a: the cache-INCLUSIVE input total — its own leg, no longer derivable from `promptTokens` (the
43
+ * cache-MISS sum). Also the cache-hit-rate denominator. */
17
44
  totalInputTokens: number;
18
45
  cachedTokens: number;
19
46
  outputTokens: number;
20
47
  cacheWriteTokens: number;
21
48
  cacheWriteTokensLong: number;
49
+ /**
50
+ * Cumulative own LLM cost (micro-USD) EXACTLY as the caller wants it published. Callers differ on the
51
+ * zero case on purpose and this constructor does not adjudicate: cascade/repair-loop publish a plain `0`
52
+ * (a run happened, it cost nothing measurable), teacher collapses `0` to `undefined` (the RB-368
53
+ * "unpriced spend is absent, not free" posture). Unifying the two is a BEHAVIOR change, not a refactor.
54
+ *
55
+ * Ignored entirely when {@link anyLegUnpriced} is set — see there.
56
+ */
22
57
  costMicroUsd: number | undefined;
58
+ /**
59
+ * TRUE when ANY contributing leg published no `costMicroUsd`, i.e. it ran on a model with neither a
60
+ * `RunnerDeps.pricing` entry nor a `Model.cost` declaration (`stats.costMicroUsd` is contractually
61
+ * ABSENT there — types.ts / RB-368 [2076]).
62
+ *
63
+ * Accumulating such a leg as `?? 0` publishes a total that is not one: the operation's real cost is
64
+ * unknown, and reporting the priced legs' partial sum makes "no price table" indistinguishable from
65
+ * "declared free" — the exact conflation the single-leg face refuses. So the knownness travels with the
66
+ * money: when this is set, `costMicroUsd` AND `costBreakdown` are both omitted from the cumulative
67
+ * stats, matching what a single unpriced `runTask` already reports. Token/turn totals are unaffected
68
+ * (they are knowable regardless of pricing).
69
+ */
23
70
  anyLegUnpriced: boolean;
71
+ /** Cumulative root-agent LLM cost for the `costBreakdown` taxonomy. */
24
72
  llmRootMicroUsd: number;
73
+ /** Cumulative within-task compaction LLM cost for the `costBreakdown` taxonomy. */
25
74
  compactionMicroUsd: number;
26
75
  nested: CumulativeNestedTotals;
27
76
  humanReview: CumulativeHumanReviewTotals;
28
77
  }
78
+ /**
79
+ * Build the cumulative stats over a base (the FINAL leg's stats — it carries the non-accumulated fields
80
+ * such as `model`) with every accumulated field overridden.
81
+ *
82
+ * `cacheHitRate` is RE-DERIVED from the cumulative cached/total-input totals rather than spread from the
83
+ * base: a ratio is not additive, so the last leg's rate is never the operation's rate.
84
+ */
29
85
  export declare function buildCumulativeStats(base: TaskResult["stats"], acc: CumulativeStatsAccumulator): TaskResult["stats"];