@sema-agent/core 5.19.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 (329) hide show
  1. package/CHANGELOG.md +102 -4
  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/roster-store.js +3 -0
  13. package/dist/agents/send-message-tool.d.ts +92 -0
  14. package/dist/agents/session-util.d.ts +5 -0
  15. package/dist/agents/subagent-steps.d.ts +66 -0
  16. package/dist/agents/subagent.d.ts +600 -0
  17. package/dist/agents/suspend-guard.d.ts +29 -0
  18. package/dist/agents/teacher.d.ts +75 -0
  19. package/dist/agents/team.d.ts +120 -1
  20. package/dist/agents/tool-filter.d.ts +34 -0
  21. package/dist/agents/verify.d.ts +198 -0
  22. package/dist/bench/metrics.d.ts +455 -0
  23. package/dist/brain/anthropic.d.ts +30 -0
  24. package/dist/brain/circuit-breaker.d.ts +33 -0
  25. package/dist/brain/circuit-breaker.js +14 -3
  26. package/dist/brain/context-overflow.d.ts +60 -3
  27. package/dist/brain/degrading.d.ts +67 -0
  28. package/dist/brain/errors.d.ts +42 -0
  29. package/dist/brain/failover.d.ts +15 -0
  30. package/dist/brain/media-degrade.d.ts +39 -0
  31. package/dist/brain/model-presets.d.ts +31 -0
  32. package/dist/brain/open-responses.d.ts +19 -0
  33. package/dist/brain/openai.d.ts +46 -0
  34. package/dist/brain/reasoning.d.ts +106 -1
  35. package/dist/brain/repetition.d.ts +83 -0
  36. package/dist/brain/request-params.d.ts +56 -0
  37. package/dist/brain/retry.d.ts +46 -0
  38. package/dist/brain/routing.d.ts +12 -0
  39. package/dist/brain/status-sink.d.ts +30 -1
  40. package/dist/brain/stream-engine.d.ts +147 -0
  41. package/dist/brain/stream-shared.d.ts +34 -0
  42. package/dist/brain/terminal-cause.d.ts +31 -0
  43. package/dist/brain/timeout.d.ts +108 -0
  44. package/dist/brain/timeout.js +11 -0
  45. package/dist/brain/tool-call-id.d.ts +20 -0
  46. package/dist/brain/tool-call-repair.d.ts +13 -0
  47. package/dist/config/catalog.d.ts +47 -0
  48. package/dist/config/defaults.d.ts +33 -0
  49. package/dist/core/a2a-task-state.d.ts +53 -0
  50. package/dist/core/a2a.d.ts +51 -0
  51. package/dist/core/arg-summary.d.ts +62 -0
  52. package/dist/core/ask-question.d.ts +272 -2
  53. package/dist/core/auto-compaction.d.ts +467 -0
  54. package/dist/core/auto-compaction.js +20 -6
  55. package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
  56. package/dist/core/auto-mode-prompt.d.ts +27 -0
  57. package/dist/core/auto-mode.d.ts +54 -3
  58. package/dist/core/auto-promote.d.ts +100 -0
  59. package/dist/core/background-agent-store.d.ts +293 -0
  60. package/dist/core/background-agent-store.js +5 -0
  61. package/dist/core/background-shell.d.ts +110 -0
  62. package/dist/core/cache-break-detector.d.ts +34 -0
  63. package/dist/core/canonical-json.d.ts +57 -0
  64. package/dist/core/checkpoint-store.d.ts +1574 -16
  65. package/dist/core/compliance.d.ts +30 -0
  66. package/dist/core/consolidate-scope.d.ts +75 -0
  67. package/dist/core/context-edit.d.ts +99 -0
  68. package/dist/core/context-guard.d.ts +46 -0
  69. package/dist/core/exec-gate.d.ts +44 -0
  70. package/dist/core/exec-output-tail.d.ts +61 -0
  71. package/dist/core/file-snapshot-store.d.ts +104 -0
  72. package/dist/core/fs-write-gate-policy.d.ts +36 -0
  73. package/dist/core/git-worktree-env.d.ts +31 -0
  74. package/dist/core/governance-codes.d.ts +19 -0
  75. package/dist/core/hooks.d.ts +609 -1
  76. package/dist/core/human-input-projection.d.ts +37 -0
  77. package/dist/core/human-input-projection.js +13 -0
  78. package/dist/core/image-downsample.d.ts +74 -0
  79. package/dist/core/locked-config.d.ts +37 -0
  80. package/dist/core/lsp-diagnostics.d.ts +77 -0
  81. package/dist/core/lsp-protocol.d.ts +29 -0
  82. package/dist/core/lsp-session.d.ts +60 -1
  83. package/dist/core/lsp.d.ts +150 -1
  84. package/dist/core/mailbox-store.d.ts +57 -0
  85. package/dist/core/mailbox-store.js +2 -0
  86. package/dist/core/mcp.d.ts +385 -0
  87. package/dist/core/mcp.js +58 -11
  88. package/dist/core/media-byte-cap.d.ts +21 -0
  89. package/dist/core/memory-admission.d.ts +71 -0
  90. package/dist/core/memory-engine/content-origin.d.ts +64 -0
  91. package/dist/core/memory-engine/data-plane.d.ts +43 -0
  92. package/dist/core/memory-engine/dual-root.d.ts +24 -0
  93. package/dist/core/memory-engine/engine.d.ts +230 -0
  94. package/dist/core/memory-engine/engine.js +103 -35
  95. package/dist/core/memory-engine/file-backend.d.ts +155 -0
  96. package/dist/core/memory-engine/frontmatter.d.ts +16 -0
  97. package/dist/core/memory-engine/layout.d.ts +217 -0
  98. package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
  99. package/dist/core/memory-engine/migrate.d.ts +9 -0
  100. package/dist/core/memory-engine/scan.d.ts +12 -0
  101. package/dist/core/memory-engine/scope-contract.d.ts +61 -1
  102. package/dist/core/memory-engine/sync-client.d.ts +87 -0
  103. package/dist/core/memory-engine/sync.d.ts +60 -0
  104. package/dist/core/memory-engine/tools.d.ts +41 -0
  105. package/dist/core/memory-engine/types.d.ts +188 -0
  106. package/dist/core/memory-recall.d.ts +141 -0
  107. package/dist/core/memory-vector.d.ts +20 -0
  108. package/dist/core/memory.d.ts +458 -0
  109. package/dist/core/message-utils.d.ts +6 -0
  110. package/dist/core/oracle-isolation.d.ts +69 -0
  111. package/dist/core/permission-rule-consent.d.ts +138 -0
  112. package/dist/core/permission-rule-model.d.ts +122 -0
  113. package/dist/core/permission-rule-store.d.ts +119 -3
  114. package/dist/core/permission-rules.d.ts +87 -1
  115. package/dist/core/present-plan-tool.d.ts +20 -0
  116. package/dist/core/pricing.d.ts +26 -0
  117. package/dist/core/property-harness.d.ts +86 -0
  118. package/dist/core/protocol-naming.d.ts +38 -0
  119. package/dist/core/protocol-table.d.ts +61 -0
  120. package/dist/core/push-queue.d.ts +1 -0
  121. package/dist/core/remote-env.d.ts +383 -1
  122. package/dist/core/retention-policy.d.ts +40 -0
  123. package/dist/core/retention-policy.js +21 -0
  124. package/dist/core/retention.d.ts +51 -0
  125. package/dist/core/roles.d.ts +59 -0
  126. package/dist/core/runner/active-skill-scope.d.ts +34 -0
  127. package/dist/core/runner/assemble-result.d.ts +134 -0
  128. package/dist/core/runner/compaction-call-options.d.ts +97 -1
  129. package/dist/core/runner/grounding-signal.d.ts +10 -0
  130. package/dist/core/runner/image.d.ts +17 -0
  131. package/dist/core/runner/image.js +29 -15
  132. package/dist/core/runner/memory-consolidation.d.ts +60 -0
  133. package/dist/core/runner/prepare-memory.d.ts +59 -0
  134. package/dist/core/runner/prepare-task.d.ts +1011 -2
  135. package/dist/core/runner/prepare-task.js +51 -14
  136. package/dist/core/runner/prompt-suggestions.d.ts +7 -0
  137. package/dist/core/runner/runtask.d.ts +304 -3
  138. package/dist/core/runner/runtask.js +17 -2
  139. package/dist/core/runner/session-file-state-replay.d.ts +49 -0
  140. package/dist/core/runner/session-rule-policy.d.ts +58 -0
  141. package/dist/core/runner/strict-output-schema.d.ts +18 -3
  142. package/dist/core/runner/synthetic-tools.d.ts +113 -0
  143. package/dist/core/runner/teardown-bounded.d.ts +34 -0
  144. package/dist/core/runner/tool-disclosure.d.ts +227 -0
  145. package/dist/core/runner/tool-output-projection.d.ts +6 -0
  146. package/dist/core/runner/turn-attachments.d.ts +634 -0
  147. package/dist/core/runner/usage-accounting.d.ts +32 -0
  148. package/dist/core/runtime.d.ts +9 -0
  149. package/dist/core/safe-notify.d.ts +64 -0
  150. package/dist/core/safety-axis-vocab.d.ts +23 -0
  151. package/dist/core/safety-merge-corpus.d.ts +37 -0
  152. package/dist/core/scheduler.d.ts +121 -0
  153. package/dist/core/secret-env.d.ts +32 -0
  154. package/dist/core/select-model.d.ts +15 -0
  155. package/dist/core/sensitive-path-policy.d.ts +42 -0
  156. package/dist/core/session-policy-store.d.ts +94 -0
  157. package/dist/core/session-reconcile.d.ts +80 -0
  158. package/dist/core/session-store.d.ts +85 -0
  159. package/dist/core/session.d.ts +153 -0
  160. package/dist/core/shared-memory/contract.d.ts +22 -0
  161. package/dist/core/shared-memory/normalize.d.ts +123 -2
  162. package/dist/core/shared-memory/tools.d.ts +14 -0
  163. package/dist/core/shared-memory/types.d.ts +105 -0
  164. package/dist/core/shutdown-debug.d.ts +6 -0
  165. package/dist/core/side-query.d.ts +38 -0
  166. package/dist/core/side-query.js +6 -1
  167. package/dist/core/skill-tool-specifier.d.ts +72 -0
  168. package/dist/core/skills-directory.d.ts +100 -1
  169. package/dist/core/spec-contract.d.ts +89 -0
  170. package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
  171. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
  172. package/dist/core/store-contracts/contract-harness.d.ts +20 -0
  173. package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
  174. package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
  175. package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
  176. package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
  177. package/dist/core/strategy-store.d.ts +37 -0
  178. package/dist/core/stub-env.d.ts +7 -0
  179. package/dist/core/surrogate-safe-slice.d.ts +35 -0
  180. package/dist/core/task-notification.d.ts +202 -0
  181. package/dist/core/task-outcome.d.ts +53 -0
  182. package/dist/core/task-registry-agent.d.ts +337 -1
  183. package/dist/core/task-registry-agent.js +2 -0
  184. package/dist/core/task-registry-monitor.d.ts +12 -0
  185. package/dist/core/task-registry-shared.d.ts +540 -0
  186. package/dist/core/task-registry.d.ts +343 -0
  187. package/dist/core/task-registry.js +13 -2
  188. package/dist/core/task-tool-shape.d.ts +44 -0
  189. package/dist/core/tighten-task-spec.d.ts +21 -0
  190. package/dist/core/tool-detach.d.ts +21 -0
  191. package/dist/core/tool-errors.d.ts +131 -0
  192. package/dist/core/tool-errors.js +4 -0
  193. package/dist/core/tool-name-aliases.d.ts +27 -0
  194. package/dist/core/tool-policy.d.ts +555 -0
  195. package/dist/core/tool-policy.js +3 -0
  196. package/dist/core/tool-result-budget.d.ts +32 -0
  197. package/dist/core/tool-result-store.d.ts +174 -1
  198. package/dist/core/tools.d.ts +45 -0
  199. package/dist/core/trace.d.ts +323 -0
  200. package/dist/core/types.d.ts +3859 -2
  201. package/dist/core/untrusted-egress.d.ts +8 -0
  202. package/dist/core/untrusted-text.d.ts +156 -0
  203. package/dist/core/usage-window-store.d.ts +95 -0
  204. package/dist/core/version.d.ts +1 -0
  205. package/dist/core/warm-resume.d.ts +17 -0
  206. package/dist/core/wiring-manifest.d.ts +169 -0
  207. package/dist/core/with-retry.d.ts +24 -0
  208. package/dist/core/workflow-journal-store.d.ts +160 -0
  209. package/dist/core/workflow-run-store-contract.d.ts +25 -0
  210. package/dist/core/workflow-run-store.d.ts +119 -0
  211. package/dist/core/workflow-run-store.js +2 -0
  212. package/dist/engine/compaction/compaction.d.ts +256 -1
  213. package/dist/engine/compaction/utils.d.ts +94 -0
  214. package/dist/engine/execution-env/kill-tree.d.ts +29 -0
  215. package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
  216. package/dist/engine/harness/agent-harness.d.ts +116 -0
  217. package/dist/engine/harness/agent-harness.js +3 -14
  218. package/dist/engine/harness/messages.d.ts +15 -0
  219. package/dist/engine/harness/types.d.ts +464 -2
  220. package/dist/engine/llm/diagnostics.d.ts +4 -0
  221. package/dist/engine/llm/event-stream.d.ts +3 -0
  222. package/dist/engine/llm/index.d.ts +7 -0
  223. package/dist/engine/llm/types.d.ts +500 -3
  224. package/dist/engine/llm/validation.d.ts +3 -0
  225. package/dist/engine/loop/agent-loop.d.ts +87 -2
  226. package/dist/engine/loop/runtime-deps.d.ts +7 -0
  227. package/dist/engine/loop/types.d.ts +424 -0
  228. package/dist/engine/lsp/frame-decoder.d.ts +13 -0
  229. package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
  230. package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
  231. package/dist/engine/session/import-validate.d.ts +27 -0
  232. package/dist/engine/session/log-digest.d.ts +93 -0
  233. package/dist/engine/session/memory-repo.d.ts +6 -0
  234. package/dist/engine/session/memory-storage.d.ts +2 -0
  235. package/dist/engine/session/session.d.ts +75 -0
  236. package/dist/engine/session/storage-base.d.ts +8 -0
  237. package/dist/fixtures/index.d.ts +36 -0
  238. package/dist/index.d.ts +17 -2
  239. package/dist/index.js +1 -2
  240. package/dist/internal/harness-types.d.ts +6 -0
  241. package/dist/internal/harness.d.ts +11 -0
  242. package/dist/internal/llm.d.ts +6 -0
  243. package/dist/orchestration/builtin-workflows.d.ts +53 -0
  244. package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
  245. package/dist/orchestration/goal.d.ts +57 -0
  246. package/dist/orchestration/goal.js +3 -0
  247. package/dist/orchestration/run-spec.d.ts +42 -0
  248. package/dist/orchestration/run-spec.js +4 -0
  249. package/dist/orchestration/run-workflow-tool.d.ts +169 -0
  250. package/dist/orchestration/workflow-governance.d.ts +61 -0
  251. package/dist/orchestration/workflow-meta.d.ts +28 -0
  252. package/dist/orchestration/workflow-observe.d.ts +60 -0
  253. package/dist/orchestration/workflow-primitives.d.ts +23 -1
  254. package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
  255. package/dist/orchestration/workflow-script-runner.d.ts +88 -0
  256. package/dist/orchestration/workflow-script-store.d.ts +98 -0
  257. package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
  258. package/dist/orchestration/workflow-types.d.ts +169 -2
  259. package/dist/orchestration/workflow.d.ts +358 -0
  260. package/dist/orchestration/workflow.js +13 -2
  261. package/dist/prompt-assembly/artifact-store.d.ts +33 -0
  262. package/dist/prompt-assembly/artifact.d.ts +25 -0
  263. package/dist/prompt-assembly/assemble.d.ts +20 -0
  264. package/dist/prompt-assembly/composer.d.ts +29 -0
  265. package/dist/prompt-assembly/epoch.d.ts +55 -1
  266. package/dist/prompt-assembly/event-registry.d.ts +35 -0
  267. package/dist/prompt-assembly/explain.d.ts +12 -0
  268. package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
  269. package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
  270. package/dist/prompt-assembly/types.d.ts +115 -0
  271. package/dist/prompts/coordinator.d.ts +27 -0
  272. package/dist/prompts/default.d.ts +539 -0
  273. package/dist/prompts/simple-sections.d.ts +45 -0
  274. package/dist/prompts/supervisor.d.ts +66 -0
  275. package/dist/scenarios/env.d.ts +28 -0
  276. package/dist/scenarios/full-body.d.ts +50 -0
  277. package/dist/scenarios/scenario-registry.d.ts +60 -0
  278. package/dist/scenarios/teacher-quickstart.d.ts +27 -0
  279. package/dist/server/http.d.ts +17 -0
  280. package/dist/stores/cc/lockfile.d.ts +6 -0
  281. package/dist/stores/cc/mailbox-store.d.ts +8 -0
  282. package/dist/stores/cc/roster-adapter.d.ts +4 -0
  283. package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
  284. package/dist/stores/file/background-agent-store.d.ts +24 -0
  285. package/dist/stores/file/background-agent-store.js +2 -1
  286. package/dist/stores/file/checkpoint-store.d.ts +38 -0
  287. package/dist/stores/file/file-snapshot-store.d.ts +25 -0
  288. package/dist/stores/file/fs-atomic.d.ts +155 -0
  289. package/dist/stores/file/index.d.ts +89 -0
  290. package/dist/stores/file/mailbox-store.d.ts +36 -0
  291. package/dist/stores/file/mailbox-store.js +2 -0
  292. package/dist/stores/file/memory-store.d.ts +82 -0
  293. package/dist/stores/file/permission-rule-store.d.ts +79 -0
  294. package/dist/stores/file/session-policy-store.d.ts +28 -0
  295. package/dist/stores/file/session-store.d.ts +40 -0
  296. package/dist/stores/file/shared-ledger.d.ts +83 -0
  297. package/dist/stores/file/tool-result-store.d.ts +11 -0
  298. package/dist/stores/file/usage-window-store.d.ts +18 -0
  299. package/dist/stores/file/workflow-journal-store.d.ts +100 -0
  300. package/dist/stores/file/workflow-run-store.d.ts +11 -0
  301. package/dist/stores/file/workflow-run-store.js +2 -0
  302. package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
  303. package/dist/tools/fs/encoding.d.ts +60 -0
  304. package/dist/tools/fs/fs-bash.d.ts +133 -0
  305. package/dist/tools/fs/fs-pdf.d.ts +28 -0
  306. package/dist/tools/fs/fs-search-tools.d.ts +5 -0
  307. package/dist/tools/fs/fs-shared.d.ts +360 -0
  308. package/dist/tools/fs/fs-write.d.ts +16 -0
  309. package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
  310. package/dist/tools/fs/index.d.ts +79 -0
  311. package/dist/tools/fs/notebook.d.ts +56 -0
  312. package/dist/tools/fs/pdf.d.ts +70 -0
  313. package/dist/tools/fs/pdf.js +8 -2
  314. package/dist/tools/fs/repo-map.d.ts +10 -0
  315. package/dist/tools/fs/safety.d.ts +376 -0
  316. package/dist/tools/fs/search.d.ts +131 -0
  317. package/dist/tools/loop-tick.d.ts +24 -0
  318. package/dist/tools/monitor.d.ts +55 -0
  319. package/dist/tools/scheduler-tools.d.ts +51 -0
  320. package/dist/tools/sql-adapters.d.ts +18 -0
  321. package/dist/tools/sql.d.ts +25 -0
  322. package/dist/tools/task-list.d.ts +77 -0
  323. package/dist/tools/todo.d.ts +8 -0
  324. package/dist/tools/web.d.ts +184 -0
  325. package/dist/tools/web.js +32 -5
  326. package/dist/tools/worktree.d.ts +81 -0
  327. package/package.json +2 -2
  328. package/dist/tools/gitea-issue.d.ts +0 -13
  329. package/dist/tools/gitea-issue.js +0 -75
@@ -1,34 +1,85 @@
1
+ /** A store's retention capability declaration. Absent ⇒ read fail-closed as `"none"`. */
1
2
  export type RetentionDeclaration = "managed" | "none";
3
+ /** The declaration face a storage implementation carries (structural — every store interface's
4
+ * optional `retention` field conforms). `"managed"` is a PROMISE to honor
5
+ * {@link ManagedRetentionCapability}; `"none"` is the honest default for stores that cannot delete
6
+ * on schedule (all bundled in-memory/TTL stores declare it). */
2
7
  export interface RetentionDeclaring {
3
8
  readonly retention?: RetentionDeclaration;
4
9
  }
10
+ /**
11
+ * The deployment's managed-retention policy ({@link import("./types.js").RunnerDeps.retentionPolicy}).
12
+ * Core consumes it ONLY for the startup capability validation (and exposes it to the deployment's
13
+ * scheduler); the engine never deletes data on the task path. Administrative locking rides the
14
+ * locked-config plane (key `"retentionPolicy"`), not a field here — one lock mechanism, not two.
15
+ */
5
16
  export interface RetentionPolicy {
17
+ /** Retention horizon in days. Fail-loud validated: non-finite or negative refuses the deployment
18
+ * (`config.retention_policy`); `0` is absurd-but-evaluable (delete-eligible immediately) and legal. */
6
19
  maxAgeDays: number;
7
20
  }
21
+ /**
22
+ * What a `retention: "managed"` store PROMISES (contract TYPE — core ships no implementation; the
23
+ * server half consumes this. Reference implementation of the cascade: the server's session-purge
24
+ * order contract). Every method is expected to be:
25
+ * - **tenant-domain scoped**: work is enumerated and executed per retention domain (tenant/scope),
26
+ * never as one global sweep;
27
+ * - **idempotent**: a retried invocation after a crash re-converges (already-deleted rows are
28
+ * counted, not errors);
29
+ * - **tombstoned**: deletions leave tombstones so replicas/backups converge instead of resurrecting;
30
+ * - **audited**: every destructive call returns a receipt the scheduler persists (append-only).
31
+ */
8
32
  export interface ManagedRetentionCapability {
33
+ /** Enumerate the retention domains (tenant/scope keys) this store holds data for. */
9
34
  listRetentionDomains(): Promise<readonly string[]>;
35
+ /** CAS-fenced checkpoint expiry for one domain: `pending → expired` strictly by deadline, exactly
36
+ * one winner per row across replicas, AND release the associated session pins (the reap/unpin
37
+ * split is the documented gap this contract closes). */
10
38
  expireCheckpoints(input: {
11
39
  domain: string;
12
40
  cutoffMs: number;
13
41
  }): Promise<RetentionReceipt>;
42
+ /** Lineage-aware transcript/session deletion: a session tree is deleted only when no live
43
+ * reference (fork child, background child, workflow run, pending checkpoint) still points into
44
+ * it — references are re-checked inside the deletion transaction, never assumed from a prior
45
+ * scan. */
14
46
  deleteExpiredSessions(input: {
15
47
  domain: string;
16
48
  cutoffMs: number;
17
49
  }): Promise<RetentionReceipt>;
50
+ /** Delete offloaded tool results whose owning sessions are gone (or past the horizon), skipping
51
+ * refs still reachable from live transcripts. */
18
52
  deleteOrphanToolResults(input: {
19
53
  domain: string;
20
54
  cutoffMs: number;
21
55
  }): Promise<RetentionReceipt>;
22
56
  }
57
+ /** Audit receipt of one destructive retention call (append-only material for the scheduler). */
23
58
  export interface RetentionReceipt {
24
59
  domain: string;
60
+ /** Rows destroyed by THIS call (idempotent retries count already-gone rows as 0, not errors). */
25
61
  deleted: number;
62
+ /** Rows intentionally skipped (live lineage references, legal-hold marks — hold semantics are the
63
+ * scheduler's: when a hold mark exists for a domain, the scheduler skips the domain entirely and
64
+ * records the skip; this field carries the per-row remainder). */
26
65
  skipped: number;
66
+ /** Tombstones written for the deleted rows. */
27
67
  tombstones: number;
28
68
  }
69
+ /**
70
+ * Startup validation (and per-prepare backstop): with the retention policy LOCKED and configured,
71
+ * every wired store must declare `retention: "managed"` — a locked policy over a store that cannot
72
+ * delete is refused (`config.retention_capability`), never silently accepted. Also fail-loud
73
+ * validates the policy value itself (`config.retention_policy`). Exported for deployments to call at
74
+ * their own startup; the prepare preflight re-runs it on every leg regardless.
75
+ */
29
76
  export declare function assertRetentionCapability(input: {
30
77
  policy: RetentionPolicy | undefined;
78
+ /** Whether locked-config locks the `retentionPolicy` key (locked-config.ts `LockedKey`). */
31
79
  locked: boolean;
80
+ /** The wired stores to check, each with its deployment-facing name for the refusal message.
81
+ * Accepts any store object (interfaces that predate the declaration conform structurally with
82
+ * no declaration ⇒ read fail-closed as `"none"`); the declaration read is the one narrow. */
32
83
  stores: ReadonlyArray<{
33
84
  name: string;
34
85
  store: object | undefined;
@@ -2,22 +2,76 @@ import type { ThinkingLevel } from "../internal/harness-types.js";
2
2
  import type { Model } from "../internal/llm.js";
3
3
  import type { ModelRef, ModelRole, ModelRoles } from "./types.js";
4
4
  export type { ModelRole, RoleSpec, ModelRoles } from "./types.js";
5
+ /** Resolve a string ModelRef against the catalog (a Model object passes through). */
5
6
  export declare function resolveModel(ref: ModelRef, models?: Record<string, Model>): Model;
7
+ /** 档位降档链(强→弱)。解析某档无绑定时沿链向后找第一个有绑定的档(fail-open 可用性优先;绑定缺口
8
+ * 在部署 catalog 审计面可见)。`ultra` 预留:排在 `max` 前,今天不绑,未来加档零码改。 */
6
9
  export declare const DEFAULT_TIER_ORDER: readonly string[];
10
+ /** CC 档位词 → sema 档位(内置固定,兼容层):fable/mythos→max · opus→pro · sonnet→flash · haiku→lite。 */
7
11
  export declare const CC_MODEL_TIER_ALIASES: Readonly<Record<string, string>>;
12
+ /**
13
+ * Expand a deployment's tier bindings into the model catalog: every tier name (and every CC alias whose
14
+ * tier resolves) becomes a catalog key pointing at the bound Model, so the ENTIRE resolve surface
15
+ * (`resolveModel` / roles / `@model` mentions / Agent tool `model` / workflow `agent() opts.model`)
16
+ * accepts tier vocabulary with ZERO per-callsite changes. Called ONCE at Runner construction.
17
+ *
18
+ * Rules:
19
+ * - a tier with no binding falls back DOWN {@link DEFAULT_TIER_ORDER} to the first bound tier
20
+ * (e.g. `max` unbound + `pro` bound ⇒ "max" resolves to the pro model — availability over strictness;
21
+ * the gap stays visible in the deployment's catalog audit, not silently absent);
22
+ * - an existing catalog key of the same name WINS (deployment SHADOW semantics, mirroring agents):
23
+ * a deployment that already ships a model literally named "pro" keeps it untouched;
24
+ * - a binding may itself be a catalog name or a Model object (resolved through `resolveModel`);
25
+ * an unknown binding name throws at construction (config error surfaces at boot, not first use).
26
+ */
27
+ /** [1613] the DISPLAY face of a string model ref: a CC tier ALIAS (haiku/sonnet/…) resolves to its
28
+ * sema tier name (lite/flash/…) for labels — the alias verbatim reads as a strong claim about a
29
+ * specific vendor's model while the actual routing may land anywhere ("haiku" showing over a
30
+ * DeepSeek run, clay's field report). A non-alias string is the deployment's own model key — its
31
+ * honest name — and passes through unchanged. Display only; routing (`expandTiers`) is untouched. */
8
32
  export declare function resolveModelDisplayLabel(ref: string): string;
9
33
  export declare function expandTiers(models: Record<string, Model> | undefined, tiers: Record<string, ModelRef> | undefined): Record<string, Model> | undefined;
10
34
  export interface ModelMention {
35
+ /** The matched model name — always one of `allowedNames` — or undefined if none was found. */
11
36
  model?: string;
37
+ /** The message with the matched `@model` token removed and whitespace tidied. */
12
38
  cleanedText: string;
13
39
  }
40
+ /**
41
+ * Parse a leading/inline `@model` mention out of a user message, restoring the chat "@-model" UX.
42
+ * Returns the matched model **name** (a catalog ref the caller resolves), never a Model object — and
43
+ * **only ever a name from `allowedNames`**. This is the security boundary: untrusted end-user text can
44
+ * pick *which configured model* to use, but can never inject an arbitrary `baseUrl`/`apiKey`/Model
45
+ * (see design/11). Matches the first allow-listed mention; the rest of the text is returned cleaned.
46
+ *
47
+ * Typical use: `const { model, cleanedText } = parseModelMention(userMsg, Object.keys(deps.models));`
48
+ * then `runTask({ objective: cleanedText, model })` (omit `model` to fall back to the default role).
49
+ */
14
50
  export declare function parseModelMention(text: string, allowedNames: Iterable<string>): ModelMention;
51
+ /**
52
+ * Role → 档位默认表(clay 拍 2026-07-11:「role 体系用户不感知」)。配了 `RunnerDeps.tiers` 的部署,
53
+ * 各 role 未显式配置时自动落到语义档位——用户/壳只感知档位,roles 降级为内部路由层:
54
+ * - `default` → `pro`(主力档兜底;用户/部署 roles.default / TaskSpec.model 恒可覆盖);
55
+ * - `summarize` → `flash`(压缩本该便宜;flash 未绑沿降档链到 lite);
56
+ * - `advisor` → 第一档(`ultra` 起,未绑降档到 max/pro——teacher 用最强的);
57
+ * - `verifier` → `pro`;
58
+ * - `subagent`/`team`/`synthesize` 无档位默认 = 走 FALLBACK 继承主模型(LLM 可经 model 参数自选档)。
59
+ * 未配 tiers 的部署:catalog 无 TIERS_ACTIVE 标记 → 表整体 INERT,行为与从前逐字节一致
60
+ * (即使 catalog 恰有裸模型名 `pro`/`flash` 也不入档位路由——INERT 靠配置成立,不靠键名运气)。
61
+ */
15
62
  export declare const ROLE_TIER_DEFAULTS: Readonly<Partial<Record<ModelRole, string>>>;
16
63
  export interface ResolvedRole {
17
64
  model: Model;
65
+ /** The effective thinking level: explicit `spec.thinking` wins, else the role's default. */
18
66
  thinking?: ThinkingLevel;
67
+ /** The requested role's preset system prompt, if it set one (independent of model fallback). */
19
68
  systemPrompt?: string;
20
69
  }
70
+ /**
71
+ * Resolve the model (and default thinking) for a task. Explicit `spec.model` wins; otherwise walk the
72
+ * `modelRole`'s fallback chain over the merged roles (task overrides runner) and use the first role
73
+ * that supplies a model. Throws a helpful error if nothing resolves.
74
+ */
21
75
  export declare function resolveTaskModel(spec: {
22
76
  model?: ModelRef;
23
77
  modelRole?: ModelRole;
@@ -27,6 +81,11 @@ export declare function resolveTaskModel(spec: {
27
81
  models?: Record<string, Model>;
28
82
  roles?: ModelRoles;
29
83
  }): ResolvedRole;
84
+ /**
85
+ * Resolve a role's model **only if that exact role key is configured** (no fallback chain). Used for
86
+ * the `summarize` compaction model: override only when a summarize-specific model is set, otherwise
87
+ * let the caller fall back to the main model (unchanged behavior).
88
+ */
30
89
  export declare function roleModelIfSet(role: ModelRole, spec: {
31
90
  roles?: ModelRoles;
32
91
  }, deps: {
@@ -1,6 +1,8 @@
1
1
  import type { ExecutionEnv } from "../../internal/harness-types.js";
2
2
  import type { SkillManifest, ToolEffect } from "../types.js";
3
3
  import type { ToolPolicy } from "../tool-policy.js";
4
+ /** One active skill frame: either a resolved manifest, or a fail-closed marker that the manifest for a
5
+ * loaded skill could not be resolved (→ DENY-ALL while this frame is active). */
4
6
  export type ActiveSkillFrame = {
5
7
  kind: "manifest";
6
8
  manifest: SkillManifest;
@@ -9,16 +11,48 @@ export type ActiveSkillFrame = {
9
11
  lineageId: string;
10
12
  reason: string;
11
13
  };
14
+ /**
15
+ * The per-task LIFO stack of active skill frames (design/77 §3). Owned by `prepare-task`'s closure;
16
+ * the injected `skill` tool pushes onto it on a successful load, and a deny-narrowing policy reads it
17
+ * on every tool call. A simple array is the stack — `push` on load, and the policy reads ALL frames
18
+ * currently on it (the intersection). v1 keeps lifetime heuristic (see module header).
19
+ */
12
20
  export declare class ActiveSkillScope {
13
21
  private readonly frames;
22
+ /** Push a resolved manifest frame (skill loaded successfully WITH a manifest). */
14
23
  push(frame: ActiveSkillFrame): void;
24
+ /** Pop the most-recently-pushed frame (LIFO). Returns it, or undefined when empty. v1 surfaces this
25
+ * for the "next-skill-load pops the previous sibling frame" lifetime — see prepare-task wiring. */
15
26
  pop(): ActiveSkillFrame | undefined;
27
+ /** Snapshot of the live frames (a copy — callers must not mutate the stack through it). */
16
28
  active(): readonly ActiveSkillFrame[];
17
29
  get size(): number;
18
30
  }
31
+ /**
32
+ * Build the Gate-3 deny-narrowing policy over a live {@link ActiveSkillScope} (design/77 §3). For each
33
+ * tool call, WHILE any skill frame is active:
34
+ * - DENY any tool not in the INTERSECTION of every active frame's `allowTools`.
35
+ * - For a WRITE tool with an `allowPaths` constraint on ANY active frame, DENY a write whose
36
+ * canonicalized target is outside every listed prefix (reuses {@link canonicalizeTarget}, so a
37
+ * symlink can't smuggle a write outside the allowed paths).
38
+ * - A frame whose manifest could not be resolved (`kind:"unresolved"`) → DENY-ALL (fail-closed: no
39
+ * allowlist means nothing is allowed — NOT the bare task policy).
40
+ * When NO frame is active, the policy returns `allow` for everything (it only ever subtracts), leaving
41
+ * the task policy unmodified — so a skill WITHOUT a manifest, or a task before any skill load, behaves
42
+ * exactly as before (backward-compatible).
43
+ *
44
+ * This policy must be composed via `combinePolicies(scopePolicy, taskPolicy)` so its `deny`
45
+ * short-circuits the fold and a task-policy `allow` can never widen it.
46
+ *
47
+ * `env`/`rootPath` are the SAME execution env + tracked cwd the hand tools resolve against, so
48
+ * `allowPaths` matching sees the task's real filesystem (a remote/E2B task resolves in its container).
49
+ */
19
50
  export declare function createActiveSkillScopePolicy(opts: {
20
51
  scope: ActiveSkillScope;
21
52
  env: ExecutionEnv;
22
53
  rootPath?: string;
54
+ /** Per-tool side-effect class (the SAME `toolEffects` map prepare-task builds). Lets the scope policy
55
+ * fail CLOSED on a mutating tool that `allowPaths` can NOT confine (e.g. `bash` — no parseable path):
56
+ * while an `allowPaths` constraint is active, such a tool is DENIED, never allowed to write anywhere. */
23
57
  toolEffects?: ReadonlyMap<string, ToolEffect>;
24
58
  }): ToolPolicy;
@@ -1,23 +1,36 @@
1
1
  import type { AssistantMessage } from "../../internal/llm.js";
2
2
  import type { NestedUsage, TaskResult, TaskSpec } from "../types.js";
3
+ /** Per-task usage/cost accumulator (filled across the run loop, surfaced as `TaskResult.stats`). */
3
4
  export interface Stats {
4
5
  turns: number;
5
6
  tokens: number;
7
+ /** design/97 CORE-8 (②): total tool calls executed (one per `tool_start`). Spread into `TaskResult.stats`. */
6
8
  toolCalls: number;
9
+ /** RB-457-a: prompt tokens that MISSED the cache (Anthropic-protocol `input_tokens` shape). */
7
10
  promptTokens: number;
8
11
  cachedTokens: number;
9
12
  cacheWriteTokens: number;
10
13
  cacheWriteTokensLong: number;
11
14
  outputTokens: number;
12
15
  cacheHitRate?: number;
16
+ /** RB-457-a: cache-INCLUSIVE prompt total (`promptTokens + cachedTokens + cacheWriteTokens*`) — the
17
+ * billing/window/hit-rate denominator. Required (not derived) so a new accumulation site that forgets
18
+ * it fails the type check instead of silently reporting a total short by its own leg. */
13
19
  totalInputTokens: number;
14
20
  costMicroUsd: number;
15
21
  nested?: NestedUsage;
22
+ /** Post-task memory-consolidation usage (design/41); set after the result is assembled. Kept out of
23
+ * the budget gate (`overBudget` reads `costMicroUsd`/`tokens`, never this). */
16
24
  memory?: {
17
25
  tokens: number;
18
26
  costMicroUsd: number;
19
27
  applied: number;
20
28
  };
29
+ /** design/91: human-review burden (design/89 §2.4 C2). Wall-clock approval-gate wait + count, bucketed by
30
+ * `gate.kind`, accumulated across resume legs. Set by the run loop from the per-task human-review
31
+ * accumulator (synchronous `resolveAsk` timing + durable resume latency). **NOT an LLM cost** — never
32
+ * folded into `costMicroUsd`/`costBreakdown`/the budget gate (same budget-excluded treatment as `memory`).
33
+ * Flows straight through to `TaskResult.stats.humanReview` via the public-stats spread; absent ⇒ no gate. */
21
34
  humanReview?: {
22
35
  count: number;
23
36
  totalWaitMs: number;
@@ -29,6 +42,9 @@ export interface Stats {
29
42
  toolArg?: string;
30
43
  }>;
31
44
  };
45
+ /** TB telemetry B2 (service [397]): engine-mechanism engagement counters. Set by the run loop
46
+ * only when ≥1 engaged; flows straight through to `TaskResult.stats.mechanisms` via the
47
+ * public-stats spread. */
32
48
  mechanisms?: {
33
49
  finalVerifyInjected?: true;
34
50
  finalVerifyInjections?: number;
@@ -44,42 +60,160 @@ export interface Stats {
44
60
  segment: string;
45
61
  }>;
46
62
  };
63
+ /** design/80 D-E-core (Part B): within-task compaction LLM cost (micro-USD), accumulated by
64
+ * `recordCompactionUsage` as a SEPARATE running total because that cost IS folded into `costMicroUsd`
65
+ * (so it can't be re-derived from `costMicroUsd` alone). The {@link costBreakdown.compactionMicroUsd}
66
+ * source. Run-loop internal — not a public `TaskResult.stats` field. */
47
67
  compactionMicroUsd?: number;
68
+ /**
69
+ * design/80 D-E-core (Part B): a thin FINANCE TAXONOMY of the LLM-derived costs the engine actually
70
+ * prices, decomposing the task's spend into report categories (no new persisted structure — derived from
71
+ * the cost sources that already exist). CORE = LLM-token-derived ONLY; the SERVICE adds the infra axes it
72
+ * owns (tool-call / sandbox-walltime / egress — it has the k8s cost data) and composes them with this.
73
+ * Each category is ≥ 0 and the parts reconcile to the independently-summed LLM total
74
+ * (`llmRoot + nestedSubagent + compaction` — `memory` is a separate, budget-excluded line, see its doc).
75
+ * Filled in assembleResult for `llmRoot`/`nestedSubagent`/`compaction`; the `memoryConsolidation` line is
76
+ * permanently 0 since design/157 B19 retired the runner-integrated consolidation pass (field kept — it is
77
+ * public stats contract; an engine-plane re-mount per design/138 §7 would fill it again).
78
+ */
48
79
  costBreakdown?: {
80
+ /** Root-agent LLM cost (micro-USD): `costMicroUsd` MINUS the sub-categories already folded into it
81
+ * (compaction). NOT minus nested — nested subagent cost is tracked separately and is NEVER folded into
82
+ * `costMicroUsd` (it lands only in `stats.nested`), so subtracting it would under-report the root. */
49
83
  llmRootMicroUsd: number;
84
+ /** Delegated sub-agent (nested) LLM cost (micro-USD) = `stats.nested?.costMicroUsd ?? 0`. */
50
85
  nestedSubagentMicroUsd: number;
86
+ /** Post-task memory-consolidation LLM cost (micro-USD) = `stats.memory?.costMicroUsd ?? 0`. Filled in
87
+ * runtask AFTER the (async) consolidation pass sets `stats.memory`; 0 at assembleResult time. */
51
88
  memoryConsolidationMicroUsd: number;
89
+ /** Within-task compaction LLM cost (micro-USD) = the running `compactionMicroUsd` accumulator (the
90
+ * category Framing-4 missed). This IS part of `costMicroUsd`, so it is subtracted from `llmRoot`. */
52
91
  compactionMicroUsd: number;
53
92
  };
54
93
  }
94
+ /** design/164 — the two cumulative budget ceilings a task can trip. Tokens outrank cost when both are
95
+ * over at the same boundary. */
55
96
  export type BudgetAxis = "tokens" | "cost";
97
+ /**
98
+ * The terminal-state flags the run loop hands {@link assembleResult} — the typed contract between the
99
+ * loop and result assembly (council design/34 ⑤: exported so it's grep-able and tests can construct it).
100
+ */
56
101
  export interface ResultFlags {
57
102
  threw: unknown;
103
+ /** design/99 MF-25: the EFFECTIVE (resolved) model id that served the task — echoed on `TaskResult.model`. */
58
104
  model?: string;
105
+ /** RB-368 ([2076]): some spend was accounted while the serving model had NO configured price table
106
+ * (no `RunnerDeps.pricing` entry, no `Model.cost`). The numeric total is then a fabricated
107
+ * undercount — `stats.costMicroUsd`/`costBreakdown` are OMITTED from the public result instead of
108
+ * reporting a 0 indistinguishable from "declared free". The internal accumulator (budget gate's
109
+ * coordinate) is untouched. */
59
110
  unpricedSpend?: boolean;
111
+ /** RB-430-a (design/101 §E19): prepare-time rewind disclosures to echo on `TaskResult.rewindNotes`.
112
+ * Pure pass-through — assembly neither adds nor filters (a rewind that FAILED never reaches here; it
113
+ * throws at prepare and lands in the `threw` slot as a terminal errorCode). */
60
114
  rewindNotes?: TaskResult["rewindNotes"];
115
+ /** design/174 final-round: call ids of answered-but-never-collected questions, echoed on
116
+ * `TaskResult.strandedHumanAnswers`. Pure pass-through; empty/absent ⇒ the field is omitted. The
117
+ * optional `onError` alert is NOT the disclosure — this mandatory result face is. */
61
118
  strandedHumanAnswers?: TaskResult["strandedHumanAnswers"];
119
+ /** RB-439-a: the run's remote-workspace lifecycle failures, echoed on `TaskResult.remoteEnvFailures`.
120
+ * Pure pass-through (assembly neither adds nor filters) and INDEPENDENT of the status/errorCode chain:
121
+ * a refused `suspendVM` still ends the task exactly the way it did before — this only stops the eleven
122
+ * distinct codes from arriving as one anonymous `limits.max_turns_exceeded`. Empty/absent ⇒ the field is omitted. */
62
123
  remoteEnvFailures?: TaskResult["remoteEnvFailures"];
124
+ /** ruled 2026-08-04 — the usage-governance wait hint carried by the platform terminal the run adopted
125
+ * (`undefined` for every other cause: an expiring environment has no return time to give, and a store
126
+ * failure is not a window). Passed as data rather than read back off `threw` so the seat has a typed
127
+ * producer. The assembler still gates it on the SETTLED errorCode, so a hint that arrived alongside a
128
+ * higher-ranked terminal is dropped instead of being filed under a code that does not name it —
129
+ * see `TaskResult.retryAfterMs` for the in-presence condition this preserves. */
63
130
  retryAfterMs?: number;
64
131
  abortedForTimeout: boolean;
65
132
  abortedForTurns: boolean;
133
+ /** audit A-1: the abort signal fired DURING the run (user interrupt / timeout / max-turns / budget),
134
+ * captured before the run loop's unconditional release-abort. Since the loop now exits CLEANLY on an
135
+ * abort (no synthetic stopReason:"aborted" assistant is appended), `final` is the last REAL assistant
136
+ * message — this flag is what keeps an interrupted run from being mistaken for a completed one. */
66
137
  abortedLive?: boolean;
67
138
  budgetHit?: "exceeded" | "precall";
139
+ /** design/164 — which budget ceiling the hit belongs to. Set together with {@link budgetHit} at every
140
+ * site that records one; it picks the terminal code (`limits.max_tokens_exceeded` vs
141
+ * `limits.max_cost_exceeded`), so a hit without an axis would be an unattributable terminal. */
68
142
  budgetAxis?: BudgetAxis;
69
143
  blockedReason?: string;
70
144
  conflict?: boolean;
71
145
  outputInvalid?: boolean;
146
+ /** design/72 §2.2 (B): a re-suspend was refused because the task already suspended `maxSuspends` times
147
+ * (a resume/restart loop). It aborted the run (no `threw`) but must read as `failed`/`suspend.loop`,
148
+ * NOT `suspended` — slotted ABOVE `suspendRef` and the aborted branches (this suspend never minted a
149
+ * checkpoint, so `suspendRef` is unset anyway; the ordering makes the intent explicit). */
72
150
  suspendLoop?: boolean;
151
+ /** design/45: the task deliberately suspended at a durable tool gate (capture + abort fired). When set,
152
+ * the result is `status:"suspended"` carrying this token/gate — a clean pause, NOT a failure, so it is
153
+ * slotted ABOVE the `!final`/aborted branches (slot 8.5: it beats them but yields to a real
154
+ * budget/threw failure that happened to coincide). The abort it used sets `final.stopReason="aborted"`
155
+ * but does not set `threw`, so it never reaches the `flags.threw` branch. */
73
156
  suspendRef?: {
74
157
  token: import("../checkpoint-store.js").CheckpointToken;
75
158
  gate: import("../checkpoint-store.js").CheckpointGate;
159
+ /** RB-439-b: how the paused workspace comes back (`"park_only"` = a non-suspendable target that was
160
+ * never actually paused). Echoed on `TaskResult.workspaceRestoreMode`; absent for a process-local
161
+ * suspend, which captured no remote workspace. */
76
162
  restoreMode?: "snapshot" | "park_only";
77
163
  };
164
+ /** design/76 §2.5 (dry-run / shadow) + design/80 D-B (plan-gate): the task deliberately paused at a
165
+ * REVIEW-PAUSE gate — `{kind:"needs_review"}` (a profile's dry-run interception produced a predicted
166
+ * state-diff a human/judge must REVIEW) OR `{kind:"plan_review"}` (a profile's plan-gate produced a
167
+ * proposed PLAN a human must approve/edit/reject). When set, the result is `status:"needs_review"` +
168
+ * errorCode `"review.pending"`, carrying this token/gate (keyed off ref-PRESENCE, not `gate.kind`, so it
169
+ * serves both review kinds uniformly). It is the DUAL of `suspendRef` but for DIFFERENT semantics (a human
170
+ * REVIEW, not a pre-action tool-call APPROVAL), so it has its OWN flag and its OWN assemble slot (8.6,
171
+ * between `suspendRef` 8.5 and the aborted branches 9) — **never both set at once** (the commit-side
172
+ * discriminant in prepare-task branches on `gate.kind` and sets exactly one). Disjoint from `suspendRef`
173
+ * so this branch is reachable: keying status off `suspendRef` alone (reusing it) would report `"suspended"`
174
+ * and make this dead code (v4 MAJOR-A). Like `suspendRef`, it used an abort to stop the loop (no `threw`),
175
+ * so it never hits the failure branches above. */
78
176
  reviewRef?: {
79
177
  token: import("../checkpoint-store.js").CheckpointToken;
80
178
  gate: import("../checkpoint-store.js").CheckpointGate;
179
+ /** RB-439-b: the review pause pauses the same workspace the approval pause does — same discriminant. */
81
180
  restoreMode?: "snapshot" | "park_only";
82
181
  };
83
182
  }
183
+ /**
184
+ * Extract a machine-readable code from a thrown error (e.g. `SessionError.code`, a Node error code).
185
+ * Walks the `cause` chain because the harness wraps lower-level errors (e.g. a `SessionError("conflict")`
186
+ * append failure surfaces as an `AgentHarnessError("unknown")` whose cause is the real one) — so we
187
+ * prefer the first specific code over a generic `"unknown"` wrapper.
188
+ */
84
189
  export declare function errorCodeOf(err: unknown): string | undefined;
190
+ /**
191
+ * Build the final {@link TaskResult} from the run's terminal state. **The errorCode priority chain is a
192
+ * public contract** (callers `switch` on these strings) — first match wins, in this exact order
193
+ * (council design/34 red-line #3, do not reorder):
194
+ * 1. `outputInvalid` → `"output.invalid"`
195
+ * 2. degenerate → `"output.degenerate"` + `salvagedOutput` (design/39; wins over budget/timeout)
196
+ * 3. `budgetHit` → `"limits.max_tokens_exceeded"` | `"limits.max_cost_exceeded"` (by `budgetAxis`;
197
+ * the pre-call estimate rejection and the after-spend crossing share the code — the distinction
198
+ * lives in `errorMessage`, not in a second code)
199
+ * 3.5 `suspendLoop` → `"suspend.loop"` (design/72 §2.2 B — the re-suspend cap; deterministic root
200
+ * cause, above `threw` because it owns the abort)
201
+ * 4. `threw` + walltime → `"limits.max_walltime_exceeded"`
202
+ * 5. `threw` + turns → `"limits.max_turns_exceeded"`
203
+ * 6. `threw` + conflict→ `"conflict"`
204
+ * 7. `threw` (other) → `errorCodeOf(threw)`
205
+ * 8. `blockedReason` → status `"blocked"` (no errorCode)
206
+ * 8.5 `suspendRef` → status `"suspended"` + checkpointToken/gate (design/45 B4 — a deliberate
207
+ * durable pause beats the abort it used, but yields to a real budget/threw failure above)
208
+ * 8.6 `reviewRef` → status `"needs_review"` + `"review.pending"` + checkpointToken/gate (design/76 §2.5
209
+ * — a dry-run post-prediction REVIEW pause; the DUAL of 8.5, between it and the aborts, same red-line:
210
+ * a `suspendRef` at 8.5 still wins if both were somehow set, proving slot order — but the commit-side
211
+ * discriminant guarantees only one is ever set)
212
+ * 9. `abortedLive` | stopReason aborted → `"limits.max_walltime_exceeded"` | `"limits.max_turns_exceeded"` | undefined
213
+ * (audit A-1: hoisted ABOVE no-final — the loop exits cleanly on abort, so `final` may be a
214
+ * normal message or absent; a plain user interrupt carries NO errorCode — switch on `status`)
215
+ * 10. no `final` → status `"failed"`
216
+ * 11. stopReason error → brain `[code]` prefix (or `"conflict"` from the storage-layer flag)
217
+ * 12. else → `"completed"`
218
+ */
85
219
  export declare function assembleResult(spec: TaskSpec, sessionId: string, final: AssistantMessage | undefined, stats: Stats, flags: ResultFlags): TaskResult;
@@ -4,16 +4,112 @@ import type { StaleToolResultOffloadOptions, TaskSpec } from "../types.js";
4
4
  import type { Context } from "../../internal/llm.js";
5
5
  import { type ToolResultStore } from "../tool-result-store.js";
6
6
  import type { Prepared } from "./prepare-task.js";
7
+ /**
8
+ * REF-A2 (car R11) — the maybeCompact call arguments that MUST be assembled identically on all three
9
+ * of runtask's compaction lanes (turn boundary / prompt-too-long recovery / end-of-task).
10
+ *
11
+ * Those lanes carried three hand-copied assemblies whose own comments said "must not silently
12
+ * diverge" — a discipline enforced only by human diffing. This module makes the identity structural.
13
+ * It is deliberately NARROW: only the parts that are the same invariant live here. Everything else
14
+ * the three call sites pass (model source, brain, minTokens, force, trigger, window safety, and the
15
+ * end-of-task lane's deliberate ABSENCE of `signal`) is a legitimate per-lane difference and stays at
16
+ * the call site, where its reason is written down.
17
+ *
18
+ * Every export is a free function: the turn-boundary lane assembles its call inside `makeTurnBoundary`
19
+ * (a module-level function with no `this`), so a method would not be reachable from all three sites.
20
+ * Nothing here reads or writes runner state — pure assembly over `spec` + `Prepared`.
21
+ */
22
+ /**
23
+ * Opt-in working-file attachments (LONGRUN-2 / CC 198 post-compact restore parity).
24
+ *
25
+ * Blackboard 2026-07-03 (CC parity): post-compact file re-read is DEFAULT ON (CC hard-codes it;
26
+ * LONGRUN-2 measured ≈2.3 extra read round-trips per compaction without it). `false` opts out; an
27
+ * object customizes caps. Selection set = most recently READ (CC readFileState semantics) with a
28
+ * modified-files fallback inside maybeCompact. Returns `undefined` when attachments are off or the
29
+ * task has no hands (no `readTaskFile` ⇒ nothing can be re-read).
30
+ */
7
31
  export declare function buildWorkingFileAttachments(spec: TaskSpec, prepared: Prepared): MaybeCompactOptions["workingFileAttachments"];
32
+ /**
33
+ * design/169-A — the CC-form fork seam, assembled identically on all three lanes (REF-A2): the
34
+ * summary request forks the main lane's latest real request (recorded by prepare-task's provider
35
+ * shim) instead of re-serializing the conversation into an independent full-price request.
36
+ * `maybeCompact` consults the accessor per pass and only when the summary model IS the main model;
37
+ * before the run's first main-loop call the accessor returns `undefined` and the independent form
38
+ * runs unchanged.
39
+ *
40
+ * Lossy-projection guard (SEMA-ONLY — CC has no request-layer reducers): the recorded request is a
41
+ * PROJECTION of the session, and when ANY default reducer made it lossy (guard-trim message drops,
42
+ * clearStale content blanking, the aggregate tool-result/media caps, the orphan sweep), that
43
+ * projection is missing history the summary would PERMANENTLY replace — measured live: a fork of a
44
+ * trimmed request loses the fact-survival suite's fact; a fork of a clearStale'd request summarizes
45
+ * `[tool result cleared …]` markers (独立复审 HIGH,已修). That guard lives at the RECORDING side
46
+ * (prepare-task arms `requestLossyRef` per request build; a lossy request records `undefined`), so
47
+ * every lane degrades to the independent form — which reads the FULL session — automatically.
48
+ *
49
+ * `disable` — the PTL-recovery lane's structural off-switch: the provider just rejected the very
50
+ * prefix a fork would resend, so a fork attempt there is a guaranteed wasted round-trip before the
51
+ * internal fallback. The other lanes pass `false`.
52
+ */
8
53
  export declare function forkContextOption(prepared: Prepared, disable: boolean): Pick<MaybeCompactOptions, "forkContext">;
54
+ /**
55
+ * RB-31 ([1068]) — compaction-boundary center-candidate adoption. Absent (an empty object, NOT a
56
+ * `centerAdoption: undefined` key) = restate as before; a boundary re-pin hashes the same artifact
57
+ * identity on every lane.
58
+ */
9
59
  export declare function centerAdoptionOption(prepared: Prepared): Partial<Pick<MaybeCompactOptions, "centerAdoption">>;
60
+ /** design/169-F defaults (object-present, field-absent). Named per the magic-number rule. */
10
61
  export declare const STALE_OFFLOAD_DEFAULT_KEEP_RECENT_PER_TOOL = 3;
11
62
  export declare const STALE_OFFLOAD_DEFAULT_MIN_SAVINGS_CHARS = 2000;
63
+ /** Resolved (validated, defaulted) knob — see {@link resolveStaleToolResultOffload}. */
12
64
  export interface ResolvedStaleToolResultOffload {
13
65
  keepRecentPerTool: number;
14
66
  minSavingsChars: number;
15
67
  }
68
+ /**
69
+ * design/169-F — validate + default the spec knob. Fail-loud on non-finite/negative/fractional
70
+ * values (a computed NaN silently re-defaulting is the ||0-fold this repo's engineering code bans);
71
+ * `undefined` knob ⇒ `undefined` (feature completely off).
72
+ */
16
73
  export declare function resolveStaleToolResultOffload(knob: StaleToolResultOffloadOptions | undefined): ResolvedStaleToolResultOffload | undefined;
74
+ /** The pointer that replaces a stale result's text in the request projection. PURE function of
75
+ * (toolName, ref, chars) — that determinism is the DECISION-stability guarantee: a result already
76
+ * replaced maps to the same pointer bytes on every later request (no flip-flop, no re-decision
77
+ * churn). It is NOT full prefix stability: the verbatim→pointer TRANSITION itself (a result
78
+ * crossing the staleness line as newer same-tool results arrive) rewrites that message's bytes
79
+ * once, invalidating the provider cache from that position for one request — a bounded,
80
+ * once-per-result break the `minSavingsChars` floor is there to amortize.
81
+ * Deliberately NOT `offloadPagebackHint` (the design/30 preview's hint): that hint's wording is a
82
+ * function of the LIVE reachable-tool set, and this pointer is re-derived per request — a mid-run
83
+ * ToolSearch activation would flip its bytes and break the very prefix stability this file pins.
84
+ * The reader is named by its real mounted name (独立复审 MED,已修: `read_tool_result` is a
85
+ * retired alias — a model following it burned a rejected call first). */
17
86
  export declare function buildStaleOffloadPointer(toolName: string, ref: string, chars: number): string;
18
- export declare function projectStaleToolResults(context: Context, cfg: ResolvedStaleToolResultOffload, store: ToolResultStore, sessionId: string, writtenRefs: Set<string>): Promise<Context>;
87
+ /**
88
+ * design/169-F — the request-side projection: replace STALE same-tool results with byte-stable
89
+ * pointers. "Stale" = has ≥ `keepRecentPerTool` NEWER results of the same tool name in this request
90
+ * — a monotone predicate (a result never gains "recency" back), so a replacement decision made on
91
+ * one request holds on every later one and re-derivation is deterministic: no run-scoped mutable
92
+ * decision state is needed for byte stability, only the pointer's purity (see
93
+ * {@link buildStaleOffloadPointer}) and the store's write-once `put`.
94
+ *
95
+ * The session transcript is NEVER touched — this runs on the outgoing {@link Context} only.
96
+ * Error results, image/document-bearing blocks' non-text parts, already-offloaded previews, and
97
+ * replacements that would save < `minSavingsChars` are left verbatim. The full text is persisted
98
+ * under a deterministic content-digested ref (design/30's mint helper over
99
+ * `<toolCallId>_s<sha256-12 of the text>` — write-once, so re-projection on every turn re-puts a
100
+ * no-op; the digest exists because tool-call ids carry no cross-turn uniqueness contract),
101
+ * readable back via `read_tool_result`.
102
+ */
103
+ export declare function projectStaleToolResults(context: Context, cfg: ResolvedStaleToolResultOffload, store: ToolResultStore, sessionId: string,
104
+ /** Run-scoped cache of refs already persisted by THIS run (独立复审 MED,已修): without it the
105
+ * write-once `put` is still re-issued every request — on the file backend that is a
106
+ * write-then-discard round-trip per stale result per turn. Caller owns the Set's lifetime. */
107
+ writtenRefs: Set<string>): Promise<Context>;
108
+ /**
109
+ * MF-18 修② ([496]③) — fidelity disclosure: the summary INPUT was clipped to the compaction model's
110
+ * window. Fires pre-call, so the disclosure survives a failed attempt. All three lanes emit the SAME
111
+ * frame; the end-of-task lane passes `spec.tracer ?? deps.tracer` / `spec.taskId ?? sessionId`
112
+ * explicitly because `RunState.telemetry` (which holds exactly those two resolved values) is not in
113
+ * scope inside `finish()`.
114
+ */
19
115
  export declare function emitInputTruncated(tracer: TracerHook | undefined, taskId: string): NonNullable<MaybeCompactOptions["onInputTruncated"]>;
@@ -1 +1,11 @@
1
+ /**
2
+ * Deterministic §3.C(3) process-side projection over ONE tool call's args.
3
+ *
4
+ * Shape-based, tool-name-agnostic: any tool whose args carry a string `command` field (the
5
+ * shell-tool family — "Bash" and renamed/white-labeled shells alike) is projected through the
6
+ * word-face regex; every other tool contributes nothing. Case-sensitive (the faces are lowercase
7
+ * tool/stdlib names; an uppercase variant is not these tools). A gate-blocked call still counts:
8
+ * the signal evidences the TASK CLASS (the model reaching for byte-level work), not execution
9
+ * success — and the misfire cost is bounded by the injection cap.
10
+ */
1
11
  export declare function hasVerifiableStructureSignal(args: unknown): boolean;
@@ -1,5 +1,22 @@
1
1
  import type { ImageContent } from "../../internal/llm.js";
2
2
  import type { ImageInput } from "../types.js";
3
+ /**
4
+ * Block obviously-internal hosts (loopback / private ranges / link-local incl. cloud metadata / CGNAT / IPv6
5
+ * ULA, site-local, unspecified, IPv4-mapped, NAT64). Classifies with `net.isIP` rather than a string-prefix
6
+ * regex — the old regex both UNDER-matched (IPv4-mapped `::ffff:`, NAT64, CGNAT 100.64/10, `::`) and
7
+ * OVER-matched (any DNS name starting `fc`/`fd`, e.g. `fdpartners.com`). Numeric IPv4 forms (decimal/octal/hex)
8
+ * are normalized to dotted-decimal by `URL` before this is called, so they're already covered.
9
+ * Note: this checks the LITERAL host; it does NOT resolve DNS, so a hostname resolving to a private IP is not
10
+ * caught here (documented limitation — a deployment needing that supplies its own resolve-and-pin guard).
11
+ */
3
12
  export declare function isPrivateHost(host: string): boolean;
13
+ /**
14
+ * Default SSRF guard for a remote image URL: https only, and no internal/reserved hosts (so an
15
+ * end-user-supplied `images[].url` can't make the server fetch `169.254.169.254` or a private box).
16
+ * Note: this checks the URL host literally — it does not resolve DNS, so a hostname that resolves to
17
+ * a private IP is not caught here; a deployment needing that should supply `RunnerDeps.allowImageUrl`
18
+ * (e.g. a CDN allowlist or a resolve-and-pin check). Throws on a disallowed URL.
19
+ */
4
20
  export declare function defaultImageUrlGuard(raw: string): void;
21
+ /** Resolve an {@link ImageInput} (inline base64 or a URL to fetch) into a vendored `ImageContent` block. */
5
22
  export declare function toImageContent(img: ImageInput, allowUrl?: (url: string) => boolean): Promise<ImageContent>;