@sema-agent/core 5.20.0 → 5.21.1

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 (313) hide show
  1. package/CHANGELOG.md +19 -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-search-tools.js +0 -1
  292. package/dist/tools/fs/fs-shared.d.ts +360 -0
  293. package/dist/tools/fs/fs-write.d.ts +16 -0
  294. package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
  295. package/dist/tools/fs/index.d.ts +79 -0
  296. package/dist/tools/fs/notebook.d.ts +56 -0
  297. package/dist/tools/fs/pdf.d.ts +70 -0
  298. package/dist/tools/fs/pdf.js +8 -2
  299. package/dist/tools/fs/repo-map.d.ts +10 -0
  300. package/dist/tools/fs/safety.d.ts +376 -0
  301. package/dist/tools/fs/search.d.ts +131 -0
  302. package/dist/tools/loop-tick.d.ts +24 -0
  303. package/dist/tools/monitor.d.ts +55 -0
  304. package/dist/tools/scheduler-tools.d.ts +51 -0
  305. package/dist/tools/sql-adapters.d.ts +18 -0
  306. package/dist/tools/sql.d.ts +25 -0
  307. package/dist/tools/task-list.d.ts +77 -0
  308. package/dist/tools/todo.d.ts +8 -0
  309. package/dist/tools/web.d.ts +184 -0
  310. package/dist/tools/worktree.d.ts +81 -0
  311. package/package.json +2 -2
  312. package/dist/tools/gitea-issue.d.ts +0 -13
  313. package/dist/tools/gitea-issue.js +0 -75
@@ -1,79 +1,281 @@
1
+ /** design/135 G2: `"event"` is the ONE non-terminal member — a Monitor batch notification (new stdout
2
+ * lines from a still-running watch). Everything else is a terminal completion notification. */
1
3
  export type TaskNotificationStatus = "completed" | "failed" | "killed" | "cancelled" | "event";
2
4
  export type SystemInjectionPriority = "now" | "next" | "later";
3
5
  export interface TaskNotificationPayload {
4
6
  task_id: string;
7
+ /** design/144 §2: `"external"` is CORE-MINTED ONLY — `TaskStream.notify()` casts it onto every
8
+ * externally injected event, and the input type ({@link ExternalNotificationInput}) deliberately has
9
+ * no `task_type` field, so an outside producer can never wear an internal lane's type (a forged
10
+ * "background_bash completed" impersonating a real child). */
5
11
  task_type: "background_bash" | "workflow" | "background_agent" | "monitor" | "external";
6
12
  toolUseId?: string;
7
13
  status: TaskNotificationStatus;
14
+ /** design/135 G2 (Monitor): the batched stdout lines of ONE `status:"event"` notification (lines that
15
+ * arrived within the same batch window). `result` carries the same text joined/clipped for the model;
16
+ * this structured mirror is for SDK/UI consumers. */
8
17
  lines?: string[];
18
+ /** Per-task monotonically increasing counter. Load-bearing for dedup — {@link taskNotificationDedupKey}
19
+ * folds it in, so successive notifications of the same task_id+status don't collapse into one queue
20
+ * entry. Its SEMANTICS are per-task_type (design/144 §1.1):
21
+ * - `monitor`: the `status:"event"` BATCH counter (design/135 G2) — one per stdout batch window;
22
+ * terminal notifications omit it (one per status, as before).
23
+ * - `background_agent`: the STOP-CYCLE number. First settle (spawn stop) = 1; every successful
24
+ * SendMessage/resume wake bumps it, so the resumed run's settle notifies with 2, 3, … — the
25
+ * stop→wake→stop second-cycle frame is no longer swallowed by the `task_id:status` dedup key.
26
+ * The cycle number rides whenever it is KNOWABLE, from either carrier: the retain ledger's
27
+ * `cycleSeq`, or — on a tier-3 cross-process revival / a parked resume, which deliberately carry
28
+ * no retain entry — the durable row's own `seq`. ABSENT only when neither exists (retain OFF on a
29
+ * store-less spawn, an expired ledger with no durable row, the fork lane): the cycle count is not
30
+ * knowable there, and an honest downgrade to the old single-cycle key beats a forged period
31
+ * number. So `seq` present does NOT imply a retain entry exists.
32
+ * - `external`: caller-supplied verbatim ({@link ExternalNotificationInput.seq}) — the injector's
33
+ * own dedup discriminator across same-task_id+status events.
34
+ * Consumers (server inbox fold / shell render) key `taskId:status[:seq]` — a frame WITHOUT seq keeps
35
+ * the old two-part key (single-cycle semantics), by contract. */
9
36
  seq?: number;
37
+ /** design/144 §2 (external lane only): WHO sent this event — a deployment-provided attribution label
38
+ * (e.g. a webhook origin). UNTRUSTED: rendered into the `<task-notification … from="…">` header via
39
+ * `inlineUntrusted` + attribute-escaping, never as authority. Absent on every internal lane. */
10
40
  source?: string;
41
+ /** design/134 §3.3: only on `status:"killed"` — who stopped it. MIRROR of task-registry `StopSource`
42
+ * (the single source; inlined here to avoid an import cycle — task-registry imports this module;
43
+ * third mirror: types.ts `BackgroundChildEvent.stoppedBy` — keep all three in sync). OPEN ENUM:
44
+ * consumers must tolerate unknown values (a future "timeout" etc. is not breaking) and fall back
45
+ * to default copy. */
11
46
  stoppedBy?: "user" | "parent" | "system" | (string & {});
12
47
  summary: string;
48
+ /** RB-386① ([2090]) — the failure reason DIGEST on a `status:"failed"` terminal notification
49
+ * (background_agent lanes): the same bounded text the settle stored as the registry row's `error`
50
+ * (the completed frame carries the full `result`; the failed frame used to carry NOTHING machine-
51
+ * readable — consumers had to parse the summary prose, which pre-fix didn't even include the
52
+ * reason). UNTRUSTED (child/provider-influenceable text) — render-fence before display. Absent on
53
+ * every non-failed frame and on pre-RB-386 producers. */
13
54
  error?: string;
55
+ /** RB-386① — the machine-readable failure code beside {@link error}, when one is known: the child's
56
+ * `TaskResult.errorCode` taxonomy (brain `[code]` prefixes via extractErrorCode, `limit.*`,
57
+ * `budget.*`, …). Engine-minted, never model text. Absent when the failure carried no code. */
14
58
  errorCode?: string;
59
+ /** Structured exit code of a background command's terminal notification (bash lane): the process
60
+ * exited on its own with this code. Lets consumers branch on success/failure without parsing the
61
+ * summary wording. Absent when the process never exited by itself (killed / spawn-failed lanes). */
15
62
  exitCode?: number;
16
63
  result?: string;
64
+ /** Present (`true`) only on a `status:"killed"` notification that carries a `result` slice: the text
65
+ * was produced BEFORE the stop won the status race, so it is the child's partial work — the same
66
+ * semantics as the poll face's `partial_result` flag (one meaning across both surfaces). Absent on
67
+ * every other notification (a completed result is never flagged). */
17
68
  partial?: boolean;
18
69
  output_file?: string;
19
70
  usage?: unknown;
71
+ /** [1409] CC `<diagnostics>` parity: ENGINE-MINTED teaching text for the "result is empty/unexpected —
72
+ * now what" moment (per-agent read route / journal coordinate / resume command). Producers must mint it
73
+ * from engine values only (ids, store locators) — never from model-influenceable text. */
20
74
  diagnostics?: string;
75
+ /** The child run's SESSION id, when known. A shell keys its fleet/footer rows by its own
76
+ * local ids; the a* task_id alone can be unmappable on its side — sessionId is the stable cross-system
77
+ * anchor (the same handle TaskResult.sessionId / fleet rows carry). Optional: bash lane has none. */
21
78
  sessionId?: string;
79
+ /** Residual lane A — the child's last ≤10 completed tool steps, so the parent can write a precise resume
80
+ * prompt for a killed/stopped child without reading the transcript. Rendered as a compact block.
81
+ * Background-agent lane only; bounded upstream. */
22
82
  recentSteps?: import("../agents/subagent-steps.js").SubagentStep[];
83
+ /** Residual lane D (core half) — files the child mutated with edit counts. Background-agent lane only. */
23
84
  editedFiles?: import("../agents/subagent-steps.js").SubagentEditedFile[];
85
+ /** Residual lane E — `true` when the child can be revived via SendMessage (retained + not user-stopped).
86
+ * Lets the parent decide continue-vs-restart without trial-and-error. Background-agent lane only. */
24
87
  resumable?: boolean;
88
+ /** P1-3(黑板 [1920]/[1921]/[1924]/[1925], cli/server 商定项) — a cross-channel correlation key for
89
+ * ONE completion event. The same task's completion fans out across several independent read faces
90
+ * today (this live notification frame, a durable inbox entry, and the `TaskOutput` poll projection)
91
+ * — a consumer previously had to reconstruct "are these the same completion?" from weaker signals
92
+ * (task_id + status + timing). Minted ONCE per completion, fill-once (first writer wins), on the
93
+ * same task-registry handle/record every read face serves from — see
94
+ * {@link "./task-registry.js".UnifiedTaskOutput.completionId} for the shared contract (open-shape
95
+ * `string`, absent until terminal settle, absent on a pre-P1-3 core build). Deliberately ABSENT on
96
+ * the `"external"` lane (`TaskStream.notify()`) — that lane has its own caller-supplied `seq`
97
+ * correlation key ([1837]/[1925] cross-repo confirmed posture) and no registry-side settle point to
98
+ * mint this from; core-minting one there would create two competing correlation keys on the same
99
+ * frame. */
25
100
  completionId?: string;
101
+ /** design/176 — the peer-message marker + hop-chain carrier, present ONLY on payloads minted by
102
+ * the SendMessage delivery legs (the engine's single peer-carrier producer). Three uses: it
103
+ * carries the forwarding chain (engine-read side channel — never rendered to the model face),
104
+ * it marks the payload as peer-class for the consumption-boundary chain recording, and it keys
105
+ * the discipline-block pairing. Deliberately NOT on {@link ExternalNotificationInput}: an
106
+ * outside caller can neither mint a chain nor wear the peer class. */
26
107
  peer?: {
27
108
  hopChain: string[];
28
109
  };
29
110
  }
111
+ /**
112
+ * design/144 §2 — the caller-facing input of `TaskStream.notify()`: a STRUCTURED external event to inject
113
+ * into the running task's notification lane (same delivery machinery as background_bash/monitor/agent
114
+ * completions: SystemInjectionQueue dedup → steer/followUp/idle-park three-state delivery).
115
+ *
116
+ * Deliberately a SUBSET of {@link TaskNotificationPayload}: NO `task_type` (core mints `"external"` — a
117
+ * caller can never impersonate an internal lane) and none of the internal-lane fields (lines/stoppedBy/
118
+ * usage/…). Every field is treated as UNTRUSTED data on the model face (the XML renderer sanitizes) —
119
+ * transport, inbound authn, and idle-session durable park are the DEPLOYMENT half (design/43: no
120
+ * daemon/webhook semantics in core; core only takes "a structured event that already reached this
121
+ * process" into THIS run's injection queue).
122
+ */
30
123
  export interface ExternalNotificationInput {
124
+ /** The caller's correlation id for the event source (free-form; part of the dedup key). */
31
125
  task_id: string;
32
126
  status: TaskNotificationStatus;
33
127
  summary: string;
34
128
  result?: string;
129
+ /** Caller-side dedup discriminator: successive events of the same task_id+status need distinct `seq`s
130
+ * or the queue's dedup key swallows the repeats (same contract as every internal lane). */
35
131
  seq?: number;
132
+ /** Attribution label rendered into the `from="…"` header (untrusted; sanitized). */
36
133
  source?: string;
37
134
  }
38
135
  export interface SystemInjection<TPayload = unknown> {
39
136
  kind: "task_notification";
137
+ /** design/116 §7, re-anchored 2026-08-05 (CC 2.1.221): EVERY priority delivers at the NEXT turn
138
+ * boundary via harness.steer(), mid-work included — CC's queued task-notification inputs are
139
+ * unconditionally deliverable at the boundary, and the old later→followUp mapping (deliver only
140
+ * when the agent would otherwise stop) starved busy models of the very completion they were told
141
+ * not to poll for. Delivery is ARRIVAL order (consecutive frames batch); `priority` affects only the park/uplink
142
+ * path. A delivery that races the agent going idle parks on PendingSessionNotifications for the
143
+ * session's next run. `drain()` serves that parked lane. */
40
144
  priority: SystemInjectionPriority;
41
145
  dedupKey: string;
42
146
  payload: TPayload;
147
+ /** S2b codex R2-F2' — resolved with the ACTUAL injection outcome by the runner's subscribe
148
+ * listener: "queued" once the boundary steer accepted, "parked" when the idle tail-race (or the
149
+ * engine-note backlog cap) rejected and the payload was pended per session. Absent =
150
+ * fire-and-forget producer (no receipt to honor). */
43
151
  onDisposition?: (d: "queued" | "parked") => void;
44
152
  }
45
153
  export declare function taskNotificationDedupKey(n: Pick<TaskNotificationPayload, "task_id" | "task_type" | "status" | "seq">): string;
154
+ /**
155
+ * RB-142 — the lane-scoped identity of a task, extracted from {@link taskNotificationDedupKey} so every
156
+ * place that treats "same task" as one bucket applies the SAME lane rule.
157
+ *
158
+ * The dedup key had the lane segment from the start; three other sites did not — the pending store's
159
+ * per-task quota, its eviction victim predicate, and its drop ledger key were all the bare `task_id`.
160
+ * The lane segment exists because `task_id` is caller-supplied free-form on the external lane, so an
161
+ * external injector that picks a real child's id landed in the child's quota, evicted the child's frames,
162
+ * and merged into one ledger row carrying ONE `taskType` — the exact impersonation direction this
163
+ * module's header says cannot happen. One rule, one helper, one place to change it.
164
+ */
46
165
  export declare function taskNotificationLaneKey(n: Pick<TaskNotificationPayload, "task_id" | "task_type">): string;
166
+ /** Attribute-context escape for the external `from="…"` header: the value already went through
167
+ * `inlineUntrusted` (one-line, capped, sanitized), but a `"` would still close the attribute — escape
168
+ * the XML structural chars so the header can never be broken out of. Exported for the design/171
169
+ * human-input projection, which renders the same kind of untrusted attribution label — one escape
170
+ * implementation, never a per-renderer copy. */
47
171
  export declare function attrEscape(value: string): string;
172
+ /** Max rendered length of an untrusted attribution label (the external `from="…"` header and the
173
+ * design/171 speaker envelope share it — same concern: a display label, not a payload). */
48
174
  export declare const EXTERNAL_SOURCE_MAX = 120;
49
175
  export declare function renderTaskNotificationXml(n: TaskNotificationPayload): string;
176
+ /**
177
+ * The BETWEEN-TURNS pending lane. A task notification born while NO turn is
178
+ * live (the run's notification lane is torn down, or the harness rejected the injection because the agent
179
+ * was already idle) used to be silently unreachable: the Monitor main use-case (long-watch events between
180
+ * turns) and the stoppedBy notifications (a killed-evicted child whose registry row is already gone)
181
+ * both land exactly in that window. This store parks them PER SESSION; the session's next run drains it at
182
+ * start and rides the payloads down the SAME notification lane (steer at the next turn boundary), so
183
+ * in-turn and between-turn events keep one shape.
184
+ *
185
+ * Bounds (1.254 F4 家族纪律): per-task cap + per-session cap + session-count cap, oldest dropped first —
186
+ * preferring NON-terminal victims (an exit/killed terminal is the single most load-bearing notification of
187
+ * a watch and dies only when nothing else can) — and every drop is counted per task and DISCLOSED on
188
+ * delivery ({@link discloseDroppedPending}), never silent.
189
+ *
190
+ * Dedup (design/144 X4): `pend` drops a payload whose {@link taskNotificationDedupKey} is already parked
191
+ * for the session — the ended-run park leg honors the same key contract as the live queue's enqueue
192
+ * (before this, a repeat external notify() after the run ended would deliver DUPLICATE frames on the next
193
+ * run's drain, violating the notify contract). HONEST WINDOW LIMIT: the dedup set lives and dies with one
194
+ * session's parked batch — it does NOT span the live queue (a key delivered live and then pended after
195
+ * teardown is a fresh domain) and it resets at `drain` (a repeat arriving after the next run drained is
196
+ * deliverable again — same posture as the queue, whose drain also releases keys). A bound-evicted victim
197
+ * releases its key (mirror of SystemInjectionQueue cap eviction), so the set is bounded by the item caps.
198
+ *
199
+ * NOT checkpointed (durable-resume ruling, recorded): the registry itself (`defaultTaskRegistry`) is
200
+ * process-local — a cross-process durable resume cannot reconnect a monitor's watcher/process anyway, so a
201
+ * pending queue that outlives the process would advertise events for handles that no longer exist. Same-
202
+ * process resume legs share this store via the Runner and drain normally.
203
+ */
50
204
  export declare const MAX_PENDING_EVENTS_PER_TASK = 50;
51
205
  export declare const MAX_PENDING_EVENTS_PER_SESSION = 200;
52
206
  export declare const MAX_PENDING_SESSIONS = 100;
207
+ /**
208
+ * RB-375 A2 (ruled 2026-08-03) — is this frame the TERMINAL of a delegated background agent?
209
+ *
210
+ * It is the one notification class whose audience is the whole DELEGATION TREE rather than the
211
+ * session that produced it: the frame answers "the work you delegated is over", and the party that
212
+ * asked for the work is the conversation at the root of the tree, not necessarily the run that
213
+ * happened to issue the spawn call. Every other class (a shell completion, a Monitor batch, a
214
+ * SendMessage delivery, an external `notify()` event) is addressed to THIS session and stays there.
215
+ *
216
+ * Reuses {@link TERMINAL_STATUSES} — the same terminal-vs-event rule the pending store's eviction
217
+ * preference applies, so "terminal" can never mean two things in this module.
218
+ */
53
219
  export declare function isDelegatedAgentTerminal(n: Pick<TaskNotificationPayload, "task_type" | "status">): boolean;
54
220
  export interface DrainedPendingNotifications {
221
+ /** Chronological (pend order) payloads still held when the session's next run drained. */
55
222
  items: TaskNotificationPayload[];
223
+ /** task_id → notifications evicted by the bounds while pending (never delivered). `taskType` remembers
224
+ * the victim's lane so a survivors-none disclosure can still render an honest synthetic payload. */
225
+ /** RB-142: keyed by {@link taskNotificationLaneKey}, NOT the bare `task_id` — the external lane's ids are
226
+ * caller-supplied, so one bare-id row could cover two lanes and name only one of their types. `taskId`
227
+ * carries the victim's real id back out (the lane key is process-internal and must never be rendered). */
56
228
  dropped: Map<string, {
57
229
  count: number;
58
230
  taskType: TaskNotificationPayload["task_type"];
59
231
  taskId: string;
60
232
  }>;
233
+ /**
234
+ * RB-114 (2026-07-25, defect probe): notifications lost when this whole SESSION was evicted by the
235
+ * session-count cap, kept OUT of `dropped`. RB-91 folded them in under a `"(evicted-session)"` string
236
+ * key, which put a session-level fact into a per-task ledger and broke twice for it: the key could
237
+ * collide with a real, free-form external `task_id` (merging two unrelated counts and mislabelling the
238
+ * lane — design/144 X1 already ruled that the external lane needs its own key space), and the
239
+ * survivors-none renderer told the model to call `TaskOutput("(evicted-session)")`, an instruction with
240
+ * nothing behind it. The count is a session fact; it now has a session field.
241
+ */
61
242
  droppedWholeSession?: number;
62
243
  }
63
244
  export declare class PendingSessionNotifications {
64
245
  private readonly sessions;
246
+ /** Whole sessions evicted by {@link MAX_PENDING_SESSIONS} (their pendings were never delivered). */
65
247
  droppedSessions: number;
248
+ /**
249
+ * RB-91 (2026-07-25, red probe): a TOMBSTONE per whole-session eviction, so that session's next drain
250
+ * can still say what it lost. The two item-level caps disclose their drops per task (they mutate a
251
+ * surviving session's `dropped` map), but the session-count cap deleted the whole record and only
252
+ * bumped a global, unattributed counter — from the evicted session's point of view its next drain
253
+ * returned `undefined`, which is exactly what "nothing ever happened" looks like. The class contract
254
+ * says every drop is disclosed on delivery and never silent; this arm was the exception.
255
+ * Bounded like the sessions map itself (a tombstone is two numbers and a lane tag).
256
+ */
66
257
  private readonly evictedSessions;
258
+ /** RB-143: whole-session losses whose tombstone was itself evicted — the count survives, the attribution
259
+ * does not. Surfaced on the next session-level disclosure so it is never simply forgotten. */
67
260
  private unattributedDrops;
68
261
  pend(sessionId: string, n: TaskNotificationPayload): void;
262
+ /** Remove and return the session's pendings (one-shot — the next run consumes them exactly once). */
69
263
  drain(sessionId: string): DrainedPendingNotifications | undefined;
70
264
  get size(): number;
71
265
  }
266
+ /**
267
+ * Delivery-side overflow disclosure: fold the per-task drop counts into the drained payloads. The first
268
+ * surviving payload of a task that lost events gets a `[task_id]`-prefixed disclosure line prepended to its
269
+ * summary (backgroundTasks 同规: the id keeps the loss addressable via TaskOutput). A task whose EVERY
270
+ * pending item was evicted still gets one honest synthetic `event` payload saying so — a fully silent loss
271
+ * is never allowed.
272
+ */
72
273
  export declare function discloseDroppedPending(drained: DrainedPendingNotifications): TaskNotificationPayload[];
73
274
  export declare class SystemInjectionQueue<TPayload = TaskNotificationPayload> {
74
275
  private readonly queues;
75
276
  private readonly dedup;
76
277
  private readonly listeners;
278
+ /** F4 observability: how many queued items were evicted by the retention cap (never delivered). */
77
279
  droppedOldest: number;
78
280
  enqueue(item: SystemInjection<TPayload>): boolean;
79
281
  drain(priority?: SystemInjectionPriority): Array<SystemInjection<TPayload>>;
@@ -1,26 +1,79 @@
1
+ /**
2
+ * design/73 §1 v1 — **TaskOutcome 反馈账本(薄 seam)**。core 的唯一职责 = 在有客观 oracle 的终态发射
3
+ * 一条结构化事实;聚合(keyed by `(taskSignature, model)`)、路由/预算策略、bandit 全在 service 侧
4
+ * ledger(§7.2)。seam 形态照 `RunnerDeps.tracer` / `RunnerDeps.onError` 先例:fire-and-forget、
5
+ * swallow-guarded(throwing sink 绝不影响 run)。
6
+ *
7
+ * 🔴 红线(design/73 §1.2/§4 + makereal-corpus §4 交叉验证裁决,逐条钉死):
8
+ * ① **只发 mechanical tier** — `verificationKind` 被类型钉成字面量 `"mechanical"`,且
9
+ * {@link emitTaskOutcome} 对运行时混入的非 mechanical 值 FAIL-CLOSED 丢弃。llm_assisted /
10
+ * self-report(reviewer 判定、supervisor approval、模型自报)绝不进 v1 —— 那是 service 侧
11
+ * 仪表盘 metadata,绝不等权驱动变更(绝不自评闭环)。
12
+ * ② **必须带 `oracleHadRedRun`** — "同一个机械 oracle 曾观察到 RED" 是最强 grounded 信号
13
+ * (防 vacuous oracle:一个从来没红过的 oracle 证明不了任何东西)。
14
+ * ③ **单发射点** — `runGoal` 终态一次(goal 模式的 `doneCheck` = 天然机械 oracle)+ 有真 oracle 的
15
+ * harness/service 显式调 {@link emitTaskOutcome}。替掉散落 console.log 的污染源(console 刮出来的
16
+ * 数字 = 内存叙事,零 durable 产物)。
17
+ * ④ **core 只发事实** — 本模块无任何聚合/持久化/策略;n=1-per-signature 阶段消费侧只准做只读
18
+ * ledger/仪表盘,自动策略变更 flag-off(§7.4 回测门)。
19
+ */
1
20
  import type { RunnerDeps } from "./types.js";
21
+ /**
22
+ * One mechanical-tier outcome fact for a finished task/goal run. Real-data shape reference: the nightly
23
+ * matrix ledger (60-row summary.jsonl) — `oracle` stays free-form on purpose (each harness has its own
24
+ * mechanical fields: behaviorPass/typesClean/…) with `green` as the single required derived bit.
25
+ */
2
26
  export interface TaskOutcome {
27
+ /** Aggregation key — stable across runs of the "same task" (service aggregates by `(taskSignature, model)`). */
3
28
  taskSignature: string;
29
+ /** This run's identity (the taskId of the final task leg, or the goal's sessionId). */
4
30
  runId: string;
31
+ /** Effective model id that served the run (resolved `Model.id`), when known. */
5
32
  model?: string;
33
+ /** 🔴 Red line ①: core emits ONLY the mechanical tier. Literal type — no other value exists in v1. */
6
34
  verificationKind: "mechanical";
35
+ /** Terminal status of the run (e.g. a `GoalStatus` or `TaskStatus` — "achieved"/"completed"/"failed"/…). */
7
36
  status: string;
37
+ /** Machine-readable failure code when the terminal status carried one. */
8
38
  errorCode?: string;
39
+ /**
40
+ * The mechanical oracle's result — free-form per harness (pass/fail counts, typesClean, exit codes, …)
41
+ * but ALWAYS with the derived `green` bit: did the objective oracle pass at the end?
42
+ */
9
43
  oracle: {
10
44
  green: boolean;
11
45
  [k: string]: unknown;
12
46
  };
47
+ /**
48
+ * 🔴 Red line ②: did the SAME mechanical oracle observe a RED (failing) state during this run — the
49
+ * strongest grounded signal (an oracle that never ran red proves nothing about its own substance).
50
+ * In `runGoal` this is derived: any `doneCheck` verdict with `done:false` before the terminal state.
51
+ */
13
52
  oracleHadRedRun: boolean;
53
+ /** Raw inputs a service-side signature derivation can use (§7.3) — optional in v1. */
14
54
  signatureInputs?: {
15
55
  toolset?: string[];
16
56
  objectiveHash?: string;
17
57
  targetLang?: string;
18
58
  moduleCount?: number;
19
59
  };
60
+ /** Total tokens spent (own + nested). */
20
61
  tokens?: number;
62
+ /** Total cost in integer micro-USD (own + nested). */
21
63
  costMicroUsd?: number;
64
+ /** Total model turns (own + nested). */
22
65
  turns?: number;
66
+ /** Wall-clock duration of the whole run, ms. */
23
67
  wallMs?: number;
68
+ /** Harness-specific extras (cacheHitRate, compactions, chaos lane, …). Facts only — never judgments. */
24
69
  extra?: Record<string, unknown>;
25
70
  }
71
+ /**
72
+ * Fire the deployment's `onTaskOutcome` sink with one outcome fact — the SINGLE emission chokepoint
73
+ * (red line ③). Fire-and-forget + swallow-guarded (tracer/onError posture): a throwing sink never
74
+ * affects the caller. FAIL-CLOSED on tier: anything not `verificationKind:"mechanical"` (runtime cast
75
+ * around the literal type) is dropped, never forwarded (red line ①). Exported for harnesses/services
76
+ * that have a REAL mechanical oracle outside goal mode; plain `runTask` never auto-emits (no objective
77
+ * oracle → nothing to ground a fact in — we do not guess).
78
+ */
26
79
  export declare function emitTaskOutcome(deps: Pick<RunnerDeps, "onTaskOutcome">, outcome: TaskOutcome): void;