@sema-agent/core 7.58.0 → 7.60.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 (519) hide show
  1. package/CHANGELOG.md +1340 -0
  2. package/README.md +6 -4
  3. package/dist/agents/agent-definition.d.ts +7 -0
  4. package/dist/agents/agent-definition.js +12 -0
  5. package/dist/agents/agent-transcript-tool.d.ts +2 -1
  6. package/dist/agents/agent-transcript-tool.js +3 -1
  7. package/dist/agents/cc-peer-directory.js +8 -8
  8. package/dist/agents/child-model-seat.d.ts +4 -2
  9. package/dist/agents/child-model-seat.js +9 -4
  10. package/dist/agents/cumulative-stats.js +0 -1
  11. package/dist/agents/inherited-tool-pool.d.ts +26 -1
  12. package/dist/agents/inherited-tool-pool.js +22 -0
  13. package/dist/agents/peer-directory.d.ts +9 -0
  14. package/dist/agents/peer-directory.js +6 -2
  15. package/dist/agents/retain-ledger.d.ts +11 -1
  16. package/dist/agents/retain-ledger.js +13 -2
  17. package/dist/agents/roster-store.d.ts +1 -1
  18. package/dist/agents/roster-store.js +3 -1
  19. package/dist/agents/send-message-tool.d.ts +8 -19
  20. package/dist/agents/send-message-tool.js +32 -50
  21. package/dist/agents/subagent.d.ts +51 -17
  22. package/dist/agents/subagent.js +150 -112
  23. package/dist/agents/tool-filter.d.ts +1 -3
  24. package/dist/agents/tool-filter.js +4 -12
  25. package/dist/bench/metrics.d.ts +3 -5
  26. package/dist/bench/metrics.js +0 -1
  27. package/dist/brain/anthropic.js +161 -45
  28. package/dist/brain/degrading.js +3 -1
  29. package/dist/brain/errors.d.ts +9 -3
  30. package/dist/brain/errors.js +7 -1
  31. package/dist/brain/failover.js +2 -1
  32. package/dist/brain/open-responses.js +3 -3
  33. package/dist/brain/openai.js +103 -53
  34. package/dist/brain/provider-dialect.d.ts +11 -0
  35. package/dist/brain/provider-dialect.js +5 -2
  36. package/dist/brain/reasoning-request.js +5 -4
  37. package/dist/brain/reasoning.d.ts +19 -0
  38. package/dist/brain/reasoning.js +17 -2
  39. package/dist/brain/request-route.d.ts +4 -1
  40. package/dist/brain/request-route.js +4 -1
  41. package/dist/brain/route-adjudicator.d.ts +84 -18
  42. package/dist/brain/route-adjudicator.js +90 -22
  43. package/dist/brain/route-conformance.js +1 -1
  44. package/dist/brain/status-sink.d.ts +7 -1
  45. package/dist/brain/status-sink.js +6 -0
  46. package/dist/brain/stream-engine.js +84 -49
  47. package/dist/brain/stream-shared.d.ts +30 -0
  48. package/dist/brain/stream-shared.js +34 -1
  49. package/dist/brain/timeout.d.ts +65 -6
  50. package/dist/brain/timeout.js +111 -11
  51. package/dist/core/a2a.d.ts +15 -5
  52. package/dist/core/a2a.js +34 -19
  53. package/dist/core/account-row.d.ts +61 -0
  54. package/dist/core/account-row.js +51 -0
  55. package/dist/core/advisor-verdict.d.ts +2 -1
  56. package/dist/core/advisor-verdict.js +1 -1
  57. package/dist/core/agent-definition.d.ts +20 -0
  58. package/dist/core/allow-entry.d.ts +20 -6
  59. package/dist/core/allow-entry.js +17 -7
  60. package/dist/core/approval-object.d.ts +29 -15
  61. package/dist/core/approval-object.js +47 -19
  62. package/dist/core/artifact-host.d.ts +0 -2
  63. package/dist/core/artifact-host.js +0 -1
  64. package/dist/core/auto-compaction.js +1 -1
  65. package/dist/core/auto-mode-defaults.d.ts +8 -0
  66. package/dist/core/auto-mode-defaults.js +1 -0
  67. package/dist/core/auto-mode-rebuild.d.ts +2 -1
  68. package/dist/core/auto-mode.d.ts +39 -4
  69. package/dist/core/auto-mode.js +63 -12
  70. package/dist/core/background-agent-store.d.ts +26 -4
  71. package/dist/core/background-agent-store.js +3 -2
  72. package/dist/core/background-shell.d.ts +12 -1
  73. package/dist/core/background-shell.js +12 -0
  74. package/dist/core/checkpoint-requirements.d.ts +13 -1
  75. package/dist/core/checkpoint-requirements.js +3 -1
  76. package/dist/core/checkpoint-store.d.ts +66 -25
  77. package/dist/core/checkpoint-store.js +22 -9
  78. package/dist/core/child-clamp-seats.d.ts +29 -0
  79. package/dist/core/child-clamp-seats.js +56 -1
  80. package/dist/core/compliance.d.ts +3 -3
  81. package/dist/core/compliance.js +1 -1
  82. package/dist/core/credential-echo.d.ts +52 -0
  83. package/dist/core/credential-echo.js +65 -0
  84. package/dist/core/credential-vocabulary.d.ts +13 -3
  85. package/dist/core/credential-vocabulary.js +12 -4
  86. package/dist/core/cross-boundary-taint.d.ts +4 -5
  87. package/dist/core/effective-path-target.d.ts +8 -2
  88. package/dist/core/effective-path-target.js +8 -3
  89. package/dist/core/engine-notice.d.ts +156 -23
  90. package/dist/core/engine-notice.js +19 -5
  91. package/dist/core/frame-settlement.d.ts +5 -0
  92. package/dist/core/frame-settlement.js +4 -0
  93. package/dist/core/gate-fold.js +8 -6
  94. package/dist/core/gate-lanes.js +47 -12
  95. package/dist/core/gate-outcome.d.ts +32 -3
  96. package/dist/core/gate-outcome.js +19 -1
  97. package/dist/core/governance-codes.d.ts +17 -1
  98. package/dist/core/governance-codes.js +25 -0
  99. package/dist/core/hands-band-screen.js +0 -1
  100. package/dist/core/hands-band.d.ts +0 -3
  101. package/dist/core/hooks.d.ts +70 -59
  102. package/dist/core/hooks.js +125 -80
  103. package/dist/core/image-admission.d.ts +106 -52
  104. package/dist/core/image-admission.js +184 -56
  105. package/dist/core/image-downsample.d.ts +36 -69
  106. package/dist/core/image-downsample.js +111 -73
  107. package/dist/core/integer-option.d.ts +21 -0
  108. package/dist/core/integer-option.js +13 -0
  109. package/dist/core/locked-config.d.ts +59 -5
  110. package/dist/core/locked-config.js +82 -50
  111. package/dist/core/mailbox-store.d.ts +45 -1
  112. package/dist/core/mailbox-store.js +53 -9
  113. package/dist/core/mcp-call-meta.d.ts +2 -2
  114. package/dist/core/mcp-call-meta.js +9 -10
  115. package/dist/core/mcp-failure.d.ts +122 -20
  116. package/dist/core/mcp-failure.js +73 -5
  117. package/dist/core/mcp-host-seat.d.ts +92 -0
  118. package/dist/core/mcp-host-seat.js +131 -0
  119. package/dist/core/mcp-probe.d.ts +7 -2
  120. package/dist/core/mcp-probe.js +7 -2
  121. package/dist/core/mcp-server-link.d.ts +22 -1
  122. package/dist/core/mcp-server-link.js +25 -1
  123. package/dist/core/mcp-server-spec.d.ts +38 -9
  124. package/dist/core/mcp-server-spec.js +55 -21
  125. package/dist/core/mcp.d.ts +27 -12
  126. package/dist/core/mcp.js +105 -76
  127. package/dist/core/memory-admission.d.ts +23 -6
  128. package/dist/core/memory-admission.js +19 -9
  129. package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
  130. package/dist/core/memory-engine/consolidation-driver.js +3 -3
  131. package/dist/core/memory-engine/consolidation.d.ts +4 -0
  132. package/dist/core/memory-engine/consolidation.js +1 -0
  133. package/dist/core/memory-engine/content-origin.d.ts +13 -0
  134. package/dist/core/memory-engine/content-origin.js +21 -3
  135. package/dist/core/memory-engine/delegation-settlement.js +5 -12
  136. package/dist/core/memory-engine/distiller.js +2 -2
  137. package/dist/core/memory-engine/dual-root.d.ts +50 -1
  138. package/dist/core/memory-engine/dual-root.js +44 -1
  139. package/dist/core/memory-engine/engine.d.ts +67 -14
  140. package/dist/core/memory-engine/engine.js +384 -212
  141. package/dist/core/memory-engine/export-bundle.d.ts +23 -0
  142. package/dist/core/memory-engine/export-bundle.js +23 -4
  143. package/dist/core/memory-engine/file-backend.d.ts +128 -55
  144. package/dist/core/memory-engine/file-backend.js +290 -117
  145. package/dist/core/memory-engine/index.d.ts +3 -2
  146. package/dist/core/memory-engine/index.js +2 -1
  147. package/dist/core/memory-engine/layout.d.ts +59 -11
  148. package/dist/core/memory-engine/layout.js +190 -40
  149. package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
  150. package/dist/core/memory-engine/memory-backend-contract.js +39 -2
  151. package/dist/core/memory-engine/scope-contract.d.ts +13 -3
  152. package/dist/core/memory-engine/scope-contract.js +2 -2
  153. package/dist/core/memory-engine/sync-client.d.ts +51 -9
  154. package/dist/core/memory-engine/sync-client.js +107 -13
  155. package/dist/core/memory-engine/sync-report.d.ts +103 -0
  156. package/dist/core/memory-engine/sync-report.js +119 -0
  157. package/dist/core/memory-engine/sync.d.ts +8 -1
  158. package/dist/core/memory-engine/types.d.ts +6 -0
  159. package/dist/core/mode-policy.d.ts +9 -1
  160. package/dist/core/mode-policy.js +11 -1
  161. package/dist/core/model-receipt.d.ts +39 -0
  162. package/dist/core/model-receipt.js +139 -0
  163. package/dist/core/mods/agent-stations.d.ts +65 -0
  164. package/dist/core/mods/agent-stations.js +105 -0
  165. package/dist/core/mods/classic-events.d.ts +5 -1
  166. package/dist/core/mods/kernel/dispatch.d.ts +5 -1
  167. package/dist/core/mods/kernel/dispatch.js +6 -5
  168. package/dist/core/mods/kernel/events.d.ts +11 -4
  169. package/dist/core/mods/kernel/events.js +11 -7
  170. package/dist/core/mods/kernel/receive.d.ts +5 -0
  171. package/dist/core/mods/kernel/receive.js +10 -0
  172. package/dist/core/mods/kernel/registration.d.ts +4 -0
  173. package/dist/core/mods/kernel/registration.js +3 -0
  174. package/dist/core/mods/lifecycle-stations.d.ts +41 -0
  175. package/dist/core/mods/lifecycle-stations.js +35 -0
  176. package/dist/core/mods/stations.d.ts +73 -60
  177. package/dist/core/mods/stations.js +64 -40
  178. package/dist/core/mods/tool-call.d.ts +10 -4
  179. package/dist/core/mods/tool-call.js +28 -12
  180. package/dist/core/mounted-mcp.d.ts +5 -0
  181. package/dist/core/mounted-mcp.js +2 -2
  182. package/dist/core/namespaced-rule-name.d.ts +7 -1
  183. package/dist/core/namespaced-rule-name.js +13 -2
  184. package/dist/core/oracle-isolation.js +1 -1
  185. package/dist/core/own-property-receipt.d.ts +3 -0
  186. package/dist/core/own-property-receipt.js +3 -0
  187. package/dist/core/parent-spec-seat.d.ts +8 -3
  188. package/dist/core/parent-spec-seat.js +2 -0
  189. package/dist/core/park-selfcheck.js +14 -8
  190. package/dist/core/peer-seat.d.ts +133 -16
  191. package/dist/core/peer-seat.js +319 -42
  192. package/dist/core/permission-rule-consent.d.ts +0 -21
  193. package/dist/core/permission-rule-consent.js +11 -6
  194. package/dist/core/permission-rule-model.d.ts +20 -2
  195. package/dist/core/permission-rule-model.js +8 -7
  196. package/dist/core/present-plan-tool.d.ts +11 -3
  197. package/dist/core/present-plan-tool.js +2 -2
  198. package/dist/core/protocol-http-auth.d.ts +14 -2
  199. package/dist/core/protocol-http-auth.js +16 -7
  200. package/dist/core/read-face-seats.d.ts +7 -5
  201. package/dist/core/read-face-seats.js +4 -1
  202. package/dist/core/redaction-marks.d.ts +4 -3
  203. package/dist/core/redaction-marks.js +2 -2
  204. package/dist/core/remote-env.d.ts +146 -98
  205. package/dist/core/remote-env.js +113 -14
  206. package/dist/core/resume-startup-cause.js +1 -0
  207. package/dist/core/retention.js +37 -12
  208. package/dist/core/retired-keys.d.ts +6 -1
  209. package/dist/core/retired-keys.js +4 -1
  210. package/dist/core/rewrite-rejudge.d.ts +13 -5
  211. package/dist/core/rewrite-rejudge.js +9 -5
  212. package/dist/core/roles.d.ts +69 -3
  213. package/dist/core/roles.js +167 -80
  214. package/dist/core/rule-owner.d.ts +3 -0
  215. package/dist/core/runner/announce-once-ledger.d.ts +5 -4
  216. package/dist/core/runner/announce-once-ledger.js +4 -2
  217. package/dist/core/runner/assemble-result.d.ts +0 -5
  218. package/dist/core/runner/assemble-result.js +0 -1
  219. package/dist/core/runner/call-hook-stations.d.ts +17 -10
  220. package/dist/core/runner/call-hook-stations.js +23 -12
  221. package/dist/core/runner/child-tree.d.ts +7 -8
  222. package/dist/core/runner/child-tree.js +6 -6
  223. package/dist/core/runner/classifier-ladder.d.ts +10 -2
  224. package/dist/core/runner/classifier-ladder.js +39 -8
  225. package/dist/core/runner/construction-doors.js +5 -0
  226. package/dist/core/runner/contracts.d.ts +82 -57
  227. package/dist/core/runner/credential-origin-seat.js +4 -3
  228. package/dist/core/runner/cross-boundary-lane.d.ts +3 -5
  229. package/dist/core/runner/cross-boundary-lane.js +11 -2
  230. package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
  231. package/dist/core/runner/cwd-alignment-probe.js +21 -0
  232. package/dist/core/runner/decide-continuation.d.ts +2 -2
  233. package/dist/core/runner/env-capability-census.d.ts +15 -20
  234. package/dist/core/runner/env-capability-census.js +25 -34
  235. package/dist/core/runner/file-history-request.d.ts +2 -2
  236. package/dist/core/runner/file-history-request.js +0 -8
  237. package/dist/core/runner/gate-exit.d.ts +87 -11
  238. package/dist/core/runner/gate-exit.js +30 -8
  239. package/dist/core/runner/git-status-frame.d.ts +5 -2
  240. package/dist/core/runner/git-status-frame.js +3 -4
  241. package/dist/core/runner/image-removed-seat.d.ts +12 -0
  242. package/dist/core/runner/image-removed-seat.js +19 -0
  243. package/dist/core/runner/image.d.ts +7 -2
  244. package/dist/core/runner/image.js +14 -8
  245. package/dist/core/runner/inline-image.d.ts +10 -8
  246. package/dist/core/runner/inline-image.js +11 -9
  247. package/dist/core/runner/memory-consolidation-driver.js +5 -5
  248. package/dist/core/runner/park-commit.d.ts +1 -1
  249. package/dist/core/runner/park-commit.js +3 -0
  250. package/dist/core/runner/permission-rule-lanes.js +1 -1
  251. package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
  252. package/dist/core/runner/prepare-ask-lane.js +2 -1
  253. package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
  254. package/dist/core/runner/prepare-boundary-parks.js +5 -5
  255. package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -5
  256. package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
  257. package/dist/core/runner/prepare-config-doors.d.ts +6 -1
  258. package/dist/core/runner/prepare-config-doors.js +16 -9
  259. package/dist/core/runner/prepare-context-lane.js +2 -0
  260. package/dist/core/runner/prepare-delegation-surface.d.ts +9 -3
  261. package/dist/core/runner/prepare-delegation-surface.js +5 -4
  262. package/dist/core/runner/prepare-file-history.d.ts +10 -12
  263. package/dist/core/runner/prepare-file-history.js +3 -12
  264. package/dist/core/runner/prepare-gate-stations.d.ts +4 -3
  265. package/dist/core/runner/prepare-gate-stations.js +4 -3
  266. package/dist/core/runner/prepare-hands-readface.d.ts +7 -1
  267. package/dist/core/runner/prepare-hands-readface.js +19 -6
  268. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -7
  269. package/dist/core/runner/prepare-inherited-gate.js +22 -31
  270. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  271. package/dist/core/runner/prepare-memory.d.ts +2 -2
  272. package/dist/core/runner/prepare-memory.js +12 -19
  273. package/dist/core/runner/prepare-park-ask.d.ts +4 -6
  274. package/dist/core/runner/prepare-park-ask.js +5 -9
  275. package/dist/core/runner/prepare-policy-chain.d.ts +8 -7
  276. package/dist/core/runner/prepare-policy-chain.js +136 -121
  277. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  278. package/dist/core/runner/prepare-project-context.js +10 -7
  279. package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -2
  280. package/dist/core/runner/prepare-prompt-inputs.js +10 -20
  281. package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
  282. package/dist/core/runner/prepare-protocol-tools.js +17 -2
  283. package/dist/core/runner/prepare-run-refs.d.ts +2 -3
  284. package/dist/core/runner/prepare-run-refs.js +4 -1
  285. package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
  286. package/dist/core/runner/prepare-suspend-saga.js +5 -7
  287. package/dist/core/runner/prepare-task.js +44 -28
  288. package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
  289. package/dist/core/runner/prepare-turn-wiring.js +7 -2
  290. package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -4
  291. package/dist/core/runner/prepare-wiring-manifest.js +34 -19
  292. package/dist/core/runner/prepare-workspace-restore.js +3 -3
  293. package/dist/core/runner/reply-pricing.d.ts +30 -0
  294. package/dist/core/runner/reply-pricing.js +19 -0
  295. package/dist/core/runner/resume-admission.js +4 -2
  296. package/dist/core/runner/resume-apply.js +6 -1
  297. package/dist/core/runner/resume-checkpoint-screen.js +4 -4
  298. package/dist/core/runner/resume-policy-outcome.js +5 -5
  299. package/dist/core/runner/retired-runner-deps.js +4 -1
  300. package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
  301. package/dist/core/runner/role-seat-defaulted.js +40 -0
  302. package/dist/core/runner/run-attachment-seats.js +3 -3
  303. package/dist/core/runner/run-brain-sinks.js +3 -0
  304. package/dist/core/runner/run-git-lane.d.ts +3 -1
  305. package/dist/core/runner/run-git-lane.js +1 -1
  306. package/dist/core/runner/run-harness-handlers.d.ts +3 -1
  307. package/dist/core/runner/run-harness-handlers.js +3 -1
  308. package/dist/core/runner/run-identity-wiring.d.ts +2 -5
  309. package/dist/core/runner/run-identity-wiring.js +6 -5
  310. package/dist/core/runner/run-leg.d.ts +2 -0
  311. package/dist/core/runner/run-leg.js +63 -56
  312. package/dist/core/runner/run-notification-lane.d.ts +3 -1
  313. package/dist/core/runner/run-notification-lane.js +16 -10
  314. package/dist/core/runner/run-settle-and-teardown.js +5 -1
  315. package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
  316. package/dist/core/runner/run-stop-and-final-verify.js +14 -6
  317. package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
  318. package/dist/core/runner/run-terminal-adoption.js +9 -3
  319. package/dist/core/runner/run-turn-boundary.js +89 -77
  320. package/dist/core/runner/runtask.d.ts +8 -5
  321. package/dist/core/runner/runtask.js +21 -13
  322. package/dist/core/runner/side-call-account.d.ts +1 -1
  323. package/dist/core/runner/side-call-account.js +3 -18
  324. package/dist/core/runner/skills-seat.js +2 -2
  325. package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
  326. package/dist/core/runner/sub-agent-deny-lists.js +20 -7
  327. package/dist/core/runner/synthetic-tools.js +2 -2
  328. package/dist/core/runner/tool-disclosure.js +0 -2
  329. package/dist/core/runner/tool-end-body.js +2 -2
  330. package/dist/core/runner/tool-face-overlay.d.ts +1 -1
  331. package/dist/core/runner/tool-face-overlay.js +26 -19
  332. package/dist/core/runner/tool-occurrence.d.ts +1 -1
  333. package/dist/core/runner/tool-occurrence.js +2 -2
  334. package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
  335. package/dist/core/runner/tool-result-media-seat.js +17 -1
  336. package/dist/core/runner/turn-attachments.d.ts +29 -27
  337. package/dist/core/runner/turn-attachments.js +27 -42
  338. package/dist/core/runner-deps.d.ts +32 -19
  339. package/dist/core/secret-env.d.ts +35 -4
  340. package/dist/core/secret-env.js +65 -3
  341. package/dist/core/sensitive-path-policy.js +3 -3
  342. package/dist/core/session-policy-store.d.ts +12 -3
  343. package/dist/core/session-policy-store.js +29 -10
  344. package/dist/core/session-store.d.ts +5 -7
  345. package/dist/core/session-store.js +50 -11
  346. package/dist/core/side-query.d.ts +11 -1
  347. package/dist/core/side-query.js +9 -0
  348. package/dist/core/skill-grant-binding.d.ts +31 -2
  349. package/dist/core/skill-grant-binding.js +31 -1
  350. package/dist/core/skill-grant.d.ts +17 -5
  351. package/dist/core/skill-grant.js +24 -6
  352. package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
  353. package/dist/core/store-contracts/checkpoint-store-contract.js +3 -2
  354. package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
  355. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  356. package/dist/core/store-contracts/tool-result-store-contract.js +37 -0
  357. package/dist/core/stub-env.d.ts +5 -5
  358. package/dist/core/stub-env.js +11 -1
  359. package/dist/core/swappable-deps.d.ts +17 -43
  360. package/dist/core/swappable-deps.js +15 -5
  361. package/dist/core/synthetic-read-verdict.d.ts +1 -1
  362. package/dist/core/synthetic-read-verdict.js +2 -1
  363. package/dist/core/task-event.d.ts +50 -10
  364. package/dist/core/task-notification.d.ts +88 -5
  365. package/dist/core/task-notification.js +146 -17
  366. package/dist/core/task-registry-agent.d.ts +18 -12
  367. package/dist/core/task-registry-agent.js +19 -6
  368. package/dist/core/task-registry-monitor.d.ts +7 -0
  369. package/dist/core/task-registry-monitor.js +28 -1
  370. package/dist/core/task-registry-shared.d.ts +43 -3
  371. package/dist/core/task-registry-shared.js +21 -7
  372. package/dist/core/task-registry-workflow.js +1 -1
  373. package/dist/core/task-registry.d.ts +50 -35
  374. package/dist/core/task-registry.js +64 -23
  375. package/dist/core/task-result.d.ts +3 -12
  376. package/dist/core/task-spec.d.ts +15 -7
  377. package/dist/core/task-stream.d.ts +1 -1
  378. package/dist/core/terminal-cause.d.ts +10 -0
  379. package/dist/core/tool-catalog-entries.js +1 -1
  380. package/dist/core/tool-check-reading.d.ts +1 -0
  381. package/dist/core/tool-check-reading.js +3 -3
  382. package/dist/core/tool-face-reader.d.ts +7 -6
  383. package/dist/core/tool-face-reader.js +4 -3
  384. package/dist/core/tool-name-aliases.d.ts +19 -0
  385. package/dist/core/tool-name-aliases.js +54 -2
  386. package/dist/core/tool-policy.d.ts +21 -4
  387. package/dist/core/tool-policy.js +1 -1
  388. package/dist/core/tool-registry.d.ts +5 -5
  389. package/dist/core/tool-registry.js +2 -2
  390. package/dist/core/tool-result-store.d.ts +88 -5
  391. package/dist/core/tool-result-store.js +51 -12
  392. package/dist/core/tool-roster.d.ts +112 -5
  393. package/dist/core/tool-roster.js +42 -1
  394. package/dist/core/tool-spec.d.ts +23 -5
  395. package/dist/core/trace.d.ts +0 -1
  396. package/dist/core/types.d.ts +5 -5
  397. package/dist/core/types.js +2 -2
  398. package/dist/core/untrusted-text.js +1 -1
  399. package/dist/core/user-attachment.d.ts +10 -5
  400. package/dist/core/user-attachment.js +15 -7
  401. package/dist/core/wiring-manifest.d.ts +6 -3
  402. package/dist/engine/compaction/compaction.js +29 -3
  403. package/dist/engine/execution-env/node-execution-env.d.ts +11 -5
  404. package/dist/engine/execution-env/node-execution-env.js +21 -13
  405. package/dist/engine/harness/agent-harness.d.ts +26 -3
  406. package/dist/engine/harness/agent-harness.js +49 -16
  407. package/dist/engine/harness/messages.d.ts +3 -1
  408. package/dist/engine/harness/messages.js +3 -2
  409. package/dist/engine/harness/types.d.ts +119 -28
  410. package/dist/engine/llm/rejected-images.d.ts +46 -0
  411. package/dist/engine/llm/rejected-images.js +54 -0
  412. package/dist/engine/llm/tool-turns.d.ts +2 -1
  413. package/dist/engine/llm/types.d.ts +18 -7
  414. package/dist/engine/loop/agent-loop.d.ts +20 -12
  415. package/dist/engine/loop/agent-loop.js +205 -36
  416. package/dist/engine/loop/types.d.ts +12 -3
  417. package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
  418. package/dist/engine/lsp/node-lsp-manager.js +32 -13
  419. package/dist/engine/session/path-to-root.d.ts +38 -0
  420. package/dist/engine/session/path-to-root.js +39 -0
  421. package/dist/engine/session/storage-base.js +4 -21
  422. package/dist/index.d.ts +35 -21
  423. package/dist/index.js +26 -17
  424. package/dist/internal/harness-types.d.ts +1 -1
  425. package/dist/internal/harness.d.ts +1 -0
  426. package/dist/internal/llm.d.ts +1 -0
  427. package/dist/orchestration/run-workflow-tool.d.ts +9 -3
  428. package/dist/orchestration/run-workflow-tool.js +59 -29
  429. package/dist/orchestration/workflow-governance.d.ts +1 -1
  430. package/dist/orchestration/workflow-governance.js +2 -1
  431. package/dist/orchestration/workflow-observe.d.ts +17 -1
  432. package/dist/orchestration/workflow-observe.js +20 -0
  433. package/dist/orchestration/workflow-types.d.ts +32 -7
  434. package/dist/orchestration/workflow.d.ts +4 -0
  435. package/dist/orchestration/workflow.js +762 -491
  436. package/dist/prompts/default.d.ts +1 -10
  437. package/dist/prompts/default.js +0 -2
  438. package/dist/shell/counting-pass.d.ts +50 -0
  439. package/dist/shell/counting-pass.js +502 -0
  440. package/dist/shell/lex.d.ts +4 -2
  441. package/dist/shell/lex.js +93 -34
  442. package/dist/shell/shell-words.d.ts +1 -1
  443. package/dist/shell/shell-words.js +7 -6
  444. package/dist/stores/file/background-agent-store.d.ts +1 -1
  445. package/dist/stores/file/background-agent-store.js +3 -1
  446. package/dist/stores/file/checkpoint-store.d.ts +127 -2
  447. package/dist/stores/file/checkpoint-store.js +19 -14
  448. package/dist/stores/file/file-history-store.d.ts +1 -1
  449. package/dist/stores/file/file-history-store.js +3 -1
  450. package/dist/stores/file/index.d.ts +4 -3
  451. package/dist/stores/file/index.js +17 -8
  452. package/dist/stores/file/mailbox-store.d.ts +1 -1
  453. package/dist/stores/file/mailbox-store.js +9 -11
  454. package/dist/stores/file/memory-store.d.ts +1 -1
  455. package/dist/stores/file/memory-store.js +3 -1
  456. package/dist/stores/file/session-policy-store.d.ts +1 -1
  457. package/dist/stores/file/session-policy-store.js +3 -1
  458. package/dist/stores/file/session-store.d.ts +1 -1
  459. package/dist/stores/file/session-store.js +3 -1
  460. package/dist/stores/file/shared-ledger.d.ts +26 -0
  461. package/dist/stores/file/shared-ledger.js +38 -9
  462. package/dist/stores/file/tool-result-store.d.ts +20 -2
  463. package/dist/stores/file/tool-result-store.js +74 -6
  464. package/dist/stores/file/usage-window-store.d.ts +1 -1
  465. package/dist/stores/file/usage-window-store.js +3 -1
  466. package/dist/stores/file/workflow-journal-store.d.ts +1 -11
  467. package/dist/stores/file/workflow-journal-store.js +3 -2
  468. package/dist/tools/fs/containment-face.d.ts +5 -0
  469. package/dist/tools/fs/encoding.d.ts +13 -4
  470. package/dist/tools/fs/encoding.js +17 -2
  471. package/dist/tools/fs/fs-bash-background-text.d.ts +7 -0
  472. package/dist/tools/fs/fs-bash-background-text.js +1 -0
  473. package/dist/tools/fs/fs-bash.d.ts +14 -4
  474. package/dist/tools/fs/fs-bash.js +29 -35
  475. package/dist/tools/fs/fs-pdf.d.ts +2 -2
  476. package/dist/tools/fs/fs-pdf.js +26 -21
  477. package/dist/tools/fs/fs-read.d.ts +5 -4
  478. package/dist/tools/fs/fs-read.js +35 -18
  479. package/dist/tools/fs/fs-search-tools.js +4 -1
  480. package/dist/tools/fs/fs-shared.d.ts +11 -13
  481. package/dist/tools/fs/fs-shared.js +11 -7
  482. package/dist/tools/fs/fs-write.js +5 -5
  483. package/dist/tools/fs/index.d.ts +14 -8
  484. package/dist/tools/fs/index.js +13 -5
  485. package/dist/tools/fs/program-read-model.d.ts +13 -0
  486. package/dist/tools/fs/program-read-model.js +15 -0
  487. package/dist/tools/fs/program-read-model.rows.js +1 -1
  488. package/dist/tools/fs/read-deny.d.ts +13 -10
  489. package/dist/tools/fs/read-deny.js +25 -5
  490. package/dist/tools/fs/read-floor.d.ts +62 -0
  491. package/dist/tools/fs/read-floor.js +58 -0
  492. package/dist/tools/fs/removal-targets.d.ts +9 -4
  493. package/dist/tools/fs/removal-targets.js +17 -9
  494. package/dist/tools/fs/search.d.ts +3 -3
  495. package/dist/tools/fs/search.js +4 -4
  496. package/dist/tools/fs/shell-read-check.d.ts +1 -1
  497. package/dist/tools/fs/shell-read-check.js +2 -1
  498. package/dist/tools/fs/shell-read-judge.d.ts +16 -8
  499. package/dist/tools/fs/shell-read-judge.js +10 -6
  500. package/dist/tools/fs/shell-read-plan.d.ts +6 -1
  501. package/dist/tools/fs/shell-read-plan.js +22 -15
  502. package/dist/tools/fs/shell-read-start.js +1 -0
  503. package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
  504. package/dist/tools/fs/shell-reentry-text.js +25 -3
  505. package/dist/tools/monitor.d.ts +9 -4
  506. package/dist/tools/monitor.js +17 -8
  507. package/dist/tools/scheduler-tools.js +42 -4
  508. package/dist/tools/web.d.ts +0 -10
  509. package/dist/tools/web.js +1 -4
  510. package/package.json +5 -2
  511. package/test/export-surface.snapshot.json +161 -21
  512. package/wire-changes/core-stores-sql@7.59.0.json +29 -0
  513. package/wire-changes/core-stores-sql@7.60.0.json +30 -0
  514. package/wire-changes/core@7.59.0.json +2459 -0
  515. package/wire-changes/core@7.60.0.json +3274 -0
  516. package/wire-changes/mods-kernel@7.59.0.json +29 -0
  517. package/wire-changes/mods-kernel@7.60.0.json +62 -0
  518. package/wire-changes/primitives@7.59.0.json +29 -0
  519. package/wire-changes/primitives@7.60.0.json +30 -0
@@ -113,6 +113,12 @@ export type BrainStatusPhase = "rate_limited" | "retrying" | "reconnecting" | "c
113
113
  * lowered output cap after the provider reported the context limit exceeded (no backoff).
114
114
  */
115
115
  export type BrainRetryErrClass = "connect_refused" | "transport" | "stall" | "rate_limit" | "server" | "http" | "output_cap";
116
+ /**
117
+ * WHOSE model call a liveness frame is about, when it is not the run's own turn — the closed set behind
118
+ * {@link BrainStatus.seat}. `classifier` = a call made for the auto-mode classifier lane (the classifier seat's model, or the
119
+ * main model standing in behind it): a side call beside the person's turn, never the turn itself.
120
+ */
121
+ export type BrainStatusSeat = "classifier";
116
122
  /** design/99 §E3/§E10 — the payload of a {@link TaskEvent} `status` event (and the brain→runner signal). */
117
123
  export interface BrainStatus {
118
124
  phase: BrainStatusPhase;
@@ -153,6 +159,23 @@ export interface BrainStatus {
153
159
  * first-byte window before headers, the armed first-token watchdog after — so a consumer can render
154
160
  * "45s of 300s". Absent on every other phase. */
155
161
  timeoutMs?: number;
162
+ /**
163
+ * On a `waiting_first_token` frame: WHICH wait it is. `response_headers` — the `fetch()` call to the
164
+ * response headers (connecting, sending the request body, and whatever the gateway does before it starts
165
+ * answering; the engine cannot see these apart, they happen inside the transport); `first_token` — the
166
+ * headers to the first content delta (a thinking delta counts). Present on every `waiting_first_token`
167
+ * frame, absent on every other phase.
168
+ */
169
+ waitSegment?: "response_headers" | "first_token";
170
+ /**
171
+ * On a retry-wait frame (`phase: "reconnecting"`, `errClass: "stall"`) for an attempt this process ended
172
+ * because the HOST WAS SUSPENDED across the wait — the machine slept, or the process was stopped — how long,
173
+ * ms: the sum of the gaps longer than five seconds between the engine's once-a-second readings of the wall
174
+ * clock, from the start of the wait the attempt was in (response headers, first token, or the silence
175
+ * between deltas). The attempt is ended at the first reading where this exceeds half of that wait's window,
176
+ * and is re-sent on a fresh connection. Absent on every other frame — a stall a deadline cut carries none.
177
+ */
178
+ sleptMs?: number;
156
179
  /** 1-based index of the attempt that just failed (the wait precedes attempt `attempt + 1`);
157
180
  * same numbering as the `brain.retry` telemetry frame. Absent on frames that are not a retry wait. */
158
181
  attempt?: number;
@@ -218,6 +241,15 @@ export interface BrainStatus {
218
241
  /** Which evidence {@link providerCondition} rests on (`unified_header` / `provider_code` / `status`). Present
219
242
  * exactly when it is. */
220
243
  providerConditionSource?: ProviderConditionSource;
244
+ /**
245
+ * WHOSE model call this frame is about ({@link BrainStatusSeat}), on every phase — a 429 backoff, a reconnect, a
246
+ * `circuit_open` fast-fail or a first-token wait all describe ONE call, and the person watching needs to know it is not their
247
+ * turn's. PRESENCE: `"classifier"` exactly on a frame about a call made for the auto-mode classifier lane
248
+ * (whichever rung's model it was asked on: the classifier seat's, or the main model standing in behind it). ABSENT =
249
+ * the run's own turn: the engine does not state a seat for the person's own model, so a consumer reads absence as "the
250
+ * main loop" — never as "unknown". Additive and optional: a consumer that never reads it renders every frame as before.
251
+ */
252
+ seat?: BrainStatusSeat;
221
253
  }
222
254
  /**
223
255
  * design/97 CORE-8 (③): one lightweight TOOL-ACTIVITY beat surfaced from a running task, for a per-agent live
@@ -597,6 +629,12 @@ export type TaskEvent = ({
597
629
  * evidence. The persisted `toolResult` row repeats the frame's mark as `details.notExecuted: true` (a live
598
630
  * leg's rows, the resumed leg's and the reconcile's appended close) — the engine's key alone: a tool's own
599
631
  * value under that name is dropped from the row.
632
+ * It is also set on a call whose gate LET IT GO and which the loop itself then refused before the body started:
633
+ * the arguments the gate cleared failed the loop's own re-validation or re-reading (a rewrite the tool's input
634
+ * check refuses, a form the tool would read as other bytes), or the run was aborted in that gap. Such a frame
635
+ * reads `gate.disposition` allowed, `isError` (with an `errorCode` when the refusal carries one), this mark — and, when the gate replaced the
636
+ * arguments, {@link rewrite} beside them. A call refused before any gate saw it (an unknown tool, arguments the
637
+ * model's own call got wrong) carries no mark: nothing there says whether the loop got that far.
600
638
  * ABSENT means only that no such evidence exists — never "it ran": a call closed with its outcome unknown
601
639
  * (a reconcile at the next process start, a call interrupted mid-execution) carries no mark, because
602
640
  * telling a consumer it did not run could invite a replay of a write that already took effect.
@@ -613,14 +651,15 @@ export type TaskEvent = ({
613
651
  /**
614
652
  * @contract tool_end.rewrite — the gate let the call go with arguments other than the ones it took: `input` is what it
615
653
  * let the call go with, `by` who replaced them. Whether the body then ran is the frame's other members' to say (`isError`
616
- * with `errorCode`, as for a tool's refusal of those arguments) — this member is never evidence that it did. Present
617
- * exactly when the gate's allow exit let the call go, the frame carries no {@link notExecuted}, and the arguments it let
618
- * the call go with differ from those it took at its entry (both as the tool reads them — the loop's argument preparation
619
- * and schema coercion are no rewrite, so the comparison is never against `tool_start.args`, which stays the model's
620
- * own). Absent on a call refused before it was let go, on a parked or answered-in-place call, and on one whose arguments
621
- * were replaced and then set back; a refusal recorded after the call was let go (the shell read admission inside the
622
- * execution) leaves it beside the `denied` record — the call was let go with them. On the frame only: the persisted
623
- * `toolResult` row does not repeat it. A resumed leg's frames do not carry it.
654
+ * with `errorCode`, as for a tool's refusal of those arguments; {@link notExecuted}) — this member is never evidence that
655
+ * it did. Present exactly when the gate's allow exit let the call go, no extension answered for the call in place of its
656
+ * body, and the arguments it let the call go with differ from those it took at its entry (both as the tool reads them —
657
+ * the loop's argument preparation and schema coercion are no rewrite, so the comparison is never against `tool_start.args`,
658
+ * which stays the model's own). Absent on a call refused before it was let go, on a parked or answered-in-place call, and
659
+ * on one whose arguments were replaced and then set back; a refusal recorded after the call was let go (the shell read
660
+ * admission inside the execution, the loop's own refusal of the arguments the gate cleared) leaves it beside that refusal
661
+ * — the call was let go with them. On the frame only: the persisted `toolResult` row does not repeat it. A resumed leg's
662
+ * frames do not carry it.
624
663
  */
625
664
  rewrite?: ToolInputRewrite;
626
665
  /** The same member as the paired `tool_start`'s: an extension's own call, and who asked for it. */
@@ -1239,8 +1278,9 @@ export type TaskEvent = ({
1239
1278
  id: string;
1240
1279
  source: "marker" | "declared";
1241
1280
  };
1242
- /** True ⇔ the paths name locations inside a remote / non-host execution env, not host paths (the reading
1243
- * `ResolvedWorkspace.remote` carries). */
1281
+ /** True ⇔ the leg's execution env does not declare its paths the host's (`capabilities.hostLocalPaths`), so the
1282
+ * paths name locations inside that env, not host paths — whatever interface drives it: a host lane driven
1283
+ * through the remote seam reads `false` (the reading `ResolvedWorkspace.remote` carries). */
1244
1284
  remote: boolean;
1245
1285
  } & TaskEventIdentity) | ({
1246
1286
  /**
@@ -518,9 +518,14 @@ export declare function terminalFrameFacets(facts: {
518
518
  /**
519
519
  * A delegated child's report as its completion frame carries it — the one value the parent's notification and the fleet
520
520
  * terminal projected from that frame both read: redacted BEFORE the cut, with the pass the task row's copy uses (a token
521
- * across the cut is never half-shown), then cut with an honest total. Absent in ⇒ absent out.
521
+ * across the cut is never half-shown), then cut with an honest total. A report longer than the frame carries is the task's
522
+ * result artifact: `persist` stores the whole redacted report and the cut line names what it answered — awaited first, so
523
+ * the frame never names a ref whose write has not landed. `ref` = the stored ref, for the task row. Absent in ⇒ absent out.
522
524
  */
523
- export declare function notifyResultField(result: string | undefined): string | undefined;
525
+ export declare function completionResultField(result: string | undefined, persist: (report: string) => Promise<import("./tool-result-store.js").TaskArtifact>): Promise<{
526
+ readonly text: string;
527
+ readonly ref?: string;
528
+ } | undefined>;
524
529
  /** The codec version this engine writes into an `engine_frame` record and the highest it reads. */
525
530
  export declare const ENGINE_FRAME_CODEC_VERSION = 1;
526
531
  /** The engine's own lanes — the only frames the durable park may encode (an `external` event never is). */
@@ -580,6 +585,63 @@ export declare function isDelegatedAgentTerminal(n: Pick<TaskNotificationPayload
580
585
  * lane-blind, the trust cut is the marking site's.
581
586
  */
582
587
  export declare function isTerminalTaskNotification(n: Pick<TaskNotificationPayload, "status">): boolean;
588
+ /**
589
+ * THE completion-sink resolution every background producer reads — a background command, a Monitor watch, a background
590
+ * agent, a workflow run: the run lane the call carries (`ToolExecuteContext.onTaskNotification`) when there is one, else
591
+ * the mount's own sink. One value per launch: the producer judges "will a completion reach the model" by it, delivers
592
+ * through it, and owes its terminal frame to it ({@link oweTerminalDelivery}) — never one sink for the judgment and
593
+ * another for the delivery.
594
+ */
595
+ export declare function resolveCompletionSink<C, M>(callSink: C | undefined, mountSink: M | undefined): C | M | undefined;
596
+ /**
597
+ * The terminal frames a run's notification lane is still OWED — the one book a one-shot submission's ending waits on.
598
+ * A loop-type background task (a background agent, a continued agent, a workflow run) whose completion sink is a run's
599
+ * lane is entered when it is admitted ({@link oweTerminalDelivery}, on the sink it will deliver through); its terminal
600
+ * frame reaching that sink discharges it — whatever the lane then does with the frame (queues it for this run, or parks
601
+ * it for the session's next run): either way nothing more for that cycle will arrive on this lane. A debt is per CYCLE:
602
+ * an agent continued while its previous cycle's frame is still on its way owes two frames, and one frame — counted once,
603
+ * by its identity (`taskNotificationDedupKey`) — settles one. A debt is booked under the task's lane key
604
+ * ({@link taskNotificationLaneKey}, the pending store's own bucket key): admission, discharge and release all name the
605
+ * task by the frame it delivers, so a frame of another lane carrying the same `task_id` settles nothing here. A background
606
+ * command or a Monitor watch never enters: its lifetime is its process's (it may never end), and a one-shot ending treats
607
+ * it by the run's teardown rules without waiting. A sink no lane bound (a host's own) owes nothing.
608
+ */
609
+ export declare class DeliveryObligations {
610
+ /** lane key → admitted cycles whose terminal frame has not reached the sink. */
611
+ private readonly owed;
612
+ /** The terminal frames already counted (their dedup keys): a repeat of one settles nothing more. */
613
+ private readonly counted;
614
+ private readonly wakers;
615
+ /** When the waiting stops whatever is still owed (monotonic) — set by the first wait, never moved. */
616
+ private waitDeadline;
617
+ owe(task: Pick<TaskNotificationPayload, "task_id" | "task_type">): void;
618
+ discharge(frame: TaskNotificationPayload): void;
619
+ /** A cycle whose terminal frame was voided before it reached the sink (a continuation dropped its deferred frame) owes
620
+ * nothing more: one debt is released, the same way its frame would have released it. */
621
+ retire(task: Pick<TaskNotificationPayload, "task_id" | "task_type">): void;
622
+ private release;
623
+ /** Wake a wait to re-check its condition (a discharge, or input the run can now drain). */
624
+ wake(): void;
625
+ /** The lane keys still owed (an internal lane's is its task id), in admission order. */
626
+ get pending(): readonly string[];
627
+ /** Resolves at the next wake, when `signal` aborts, or after `withinMs` — at once when nothing is owed, it has already
628
+ * aborted, or no time is left. */
629
+ nextDischarge(signal: AbortSignal, withinMs: number): Promise<void>;
630
+ /**
631
+ * Wait out the debt the way a one-shot ending does: wake by wake, while something is owed, `keepWaiting()` holds (no
632
+ * input is queued for the run yet, the run is not ending) and `signal` has not aborted — and never past the reference's
633
+ * print-mode ceiling, counted from this book's first wait: `mFt` (cli309.js:260064), the default of
634
+ * `CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS` (cli309.js:263180), taken as a constant. `onInput` subscribes a wake to every
635
+ * input that reaches the run's queues meanwhile (a steer, a child's message, any engine note) — the wait re-checks.
636
+ */
637
+ waitOut(signal: AbortSignal, keepWaiting: () => boolean, onInput: (wake: () => void) => () => void): Promise<void>;
638
+ }
639
+ export declare function bindDeliveryObligations(sink: object, book: DeliveryObligations): void;
640
+ /** An admitted loop-type task owes `sink` its terminal frame — named by that frame's `task_id` and `task_type` (a no-op
641
+ * for a sink no run lane bound, or none). */
642
+ export declare function oweTerminalDelivery(sink: unknown, task: Pick<TaskNotificationPayload, "task_id" | "task_type">): void;
643
+ /** A cycle whose terminal frame will never reach `sink` (it was voided) releases its debt there (no-op for an unbound sink). */
644
+ export declare function retireTerminalDelivery(sink: unknown, task: Pick<TaskNotificationPayload, "task_id" | "task_type">): void;
583
645
  export interface DrainedPendingNotifications {
584
646
  /** Payloads still held when the session's next run drained. design/373 §3.5: batch order is
585
647
  * PRIORITY-MAJOR (now < next < later; a record with no carried priority ranks AS later —
@@ -819,7 +881,7 @@ export declare function sessionBoxRecordOf(payload: TaskNotificationPayload & {
819
881
  * carrier shapes, chosen per survivor:
820
882
  * · a CLASSIC survivor (renders through the `<task-notification>` shell) is annotated IN PLACE — the
821
883
  * first surviving payload of a task that lost events gets a `[task_id]`-prefixed disclosure line
822
- * prepended to its summary (backgroundTasks 同规: the id keeps the loss addressable via TaskOutput);
884
+ * prepended to its summary (backgroundTasks 同规: the id keeps the loss addressable);
823
885
  * · an AGENT-MESSAGE survivor (design/385 §1.4 d1; renders as the `<agent-message>` carrier, its
824
886
  * `summary` wire-only) is left byte-unchanged, and the disclosure rides as a SEPARATE engine-authored
825
887
  * `event` payload inserted immediately AHEAD of it (engine speech never goes inside a peer frame;
@@ -829,9 +891,30 @@ export declare function sessionBoxRecordOf(payload: TaskNotificationPayload & {
829
891
  * whole-session line below) — consume it by iteration, never by index-pairing against `items`. The
830
892
  * zero-disclosure path returns `drained.items` itself (identity, no allocation). A task whose EVERY
831
893
  * pending item was evicted still gets one honest synthetic `event` payload saying so — a fully silent
832
- * loss is never allowed.
894
+ * loss is never allowed. `readHandleOf` = the leg's reading of a task's read handle (`Prepared.taskReadHandleOf`): that
895
+ * synthetic line names where the task's output or result is read, or that its row is no longer readable from this run.
896
+ * `tasks` = the leg's background-task table, finished rows included (`Prepared.listBackgroundTasks({ settled: true })`):
897
+ * a whole-session loss names no task, so its line carries that table instead — every task the run can still reach, live
898
+ * or finished, and where each is read — or says the run has none. A caller with neither reading claims nothing.
899
+ */
900
+ export declare function discloseDroppedPending(drained: DrainedPendingNotifications, readHandleOf?: (taskId: string) => string | undefined, tasks?: () => ReadonlyArray<BackgroundTaskTableRow>): TaskNotificationPayload[];
901
+ /** One task as the background-task table lists it: its id (TaskStop addresses it), its description, its status, and its read
902
+ * handle (`TaskRegistry.readHandleOf`) — where its output or result is read; absent = nothing to read yet. */
903
+ export interface BackgroundTaskTableRow {
904
+ id: string;
905
+ description?: string;
906
+ status: string;
907
+ read?: string;
908
+ }
909
+ /**
910
+ * THE background-task table body — every model-facing list of a run's background tasks renders through it (the
911
+ * post-compaction announce, a whole-session loss line). The per-task status phrase is the reference's attachment-renderer
912
+ * wording (cli309.js:296735) "completed in background" — completed → "completed in background" · killed → "stopped" ·
913
+ * running → "still running in background" · anything else → the raw status (CC's own fallback arm); the line mirrors CC's
914
+ * `Task "${description}" ${phrase}` with the sema task_id prefixed and the row's read handle after it. A capped list says
915
+ * how many it left out, so a short count is never passed off as the whole.
833
916
  */
834
- export declare function discloseDroppedPending(drained: DrainedPendingNotifications): TaskNotificationPayload[];
917
+ export declare function renderBackgroundTaskTable(tasks: ReadonlyArray<BackgroundTaskTableRow>): string;
835
918
  export declare class SystemInjectionQueue<TPayload = TaskNotificationPayload> {
836
919
  private readonly queues;
837
920
  private readonly dedup;
@@ -178,13 +178,27 @@ export function terminalFrameFacets(facts) {
178
178
  };
179
179
  }
180
180
  const COMPLETION_REPORT_MAX = 2_000;
181
- export function notifyResultField(result) {
181
+ function cutReportReading(artifact) {
182
+ switch (artifact.kind) {
183
+ case "stored":
184
+ return `read the full text with ReadToolResult (ref "${artifact.ref}")`;
185
+ case "unconfirmed":
186
+ return "the full text could not be stored (the write failed or went unconfirmed), so no ref can read it back — ask the agent for it via SendMessage, or read it with TaskOutput where mounted";
187
+ case "no_store":
188
+ return "the full text is not stored behind a ref (no offload store) — ask the agent for it via SendMessage, or read it with TaskOutput where mounted";
189
+ }
190
+ }
191
+ export async function completionResultField(result, persist) {
182
192
  if (!result)
183
193
  return undefined;
184
194
  const report = egressText("same-principal", result);
185
- return report.length > COMPLETION_REPORT_MAX
186
- ? `${report.slice(0, COMPLETION_REPORT_MAX)}\n[result truncated: ${report.length} chars total — ask the agent for it via SendMessage, or read it with TaskOutput where mounted]`
187
- : report;
195
+ if (report.length <= COMPLETION_REPORT_MAX)
196
+ return { text: report };
197
+ const artifact = await persist(report);
198
+ return {
199
+ text: `${report.slice(0, COMPLETION_REPORT_MAX)}\n[result truncated: ${report.length} chars total — ${cutReportReading(artifact)}]`,
200
+ ...(artifact.kind === "stored" ? { ref: artifact.ref } : {}),
201
+ };
188
202
  }
189
203
  export const ENGINE_FRAME_CODEC_VERSION = 1;
190
204
  export const ENGINE_FRAME_TASK_TYPES = Object.freeze(["background_agent", "monitor", "workflow"]);
@@ -262,6 +276,7 @@ function malformedFacet(f) {
262
276
  }
263
277
  export function engineFrameRecordOf(payload, priority, box) {
264
278
  return {
279
+ id: taskNotificationDedupKey(payload),
265
280
  content: encodeEngineFrame(payload, priority),
266
281
  sentAt: Date.now(),
267
282
  peerMeta: { fromRoot: box.sessionId, kind: "engine_frame" },
@@ -275,6 +290,89 @@ export function isDelegatedAgentTerminal(n) {
275
290
  export function isTerminalTaskNotification(n) {
276
291
  return TERMINAL_STATUSES.has(n.status);
277
292
  }
293
+ export function resolveCompletionSink(callSink, mountSink) {
294
+ return callSink ?? mountSink;
295
+ }
296
+ export class DeliveryObligations {
297
+ owed = new Map();
298
+ counted = new Set();
299
+ wakers = new Set();
300
+ waitDeadline;
301
+ owe(task) {
302
+ const lane = taskNotificationLaneKey(task);
303
+ this.owed.set(lane, (this.owed.get(lane) ?? 0) + 1);
304
+ }
305
+ discharge(frame) {
306
+ const lane = taskNotificationLaneKey(frame);
307
+ const key = taskNotificationDedupKey(frame);
308
+ if (!this.owed.has(lane) || this.counted.has(key))
309
+ return;
310
+ this.counted.add(key);
311
+ this.release(lane);
312
+ }
313
+ retire(task) {
314
+ this.release(taskNotificationLaneKey(task));
315
+ }
316
+ release(lane) {
317
+ const cycles = this.owed.get(lane);
318
+ if (cycles === undefined)
319
+ return;
320
+ if (cycles > 1)
321
+ this.owed.set(lane, cycles - 1);
322
+ else
323
+ this.owed.delete(lane);
324
+ this.wake();
325
+ }
326
+ wake() {
327
+ for (const wake of [...this.wakers])
328
+ wake();
329
+ }
330
+ get pending() {
331
+ return [...this.owed.keys()];
332
+ }
333
+ nextDischarge(signal, withinMs) {
334
+ if (this.owed.size === 0 || signal.aborted || withinMs <= 0)
335
+ return Promise.resolve();
336
+ return new Promise((resolve) => {
337
+ const timer = setTimeout(() => wake(), withinMs);
338
+ timer.unref?.();
339
+ const wake = () => {
340
+ clearTimeout(timer);
341
+ this.wakers.delete(wake);
342
+ signal.removeEventListener("abort", wake);
343
+ resolve();
344
+ };
345
+ this.wakers.add(wake);
346
+ signal.addEventListener("abort", wake, { once: true });
347
+ });
348
+ }
349
+ async waitOut(signal, keepWaiting, onInput) {
350
+ if (this.owed.size === 0)
351
+ return;
352
+ this.waitDeadline ??= performance.now() + ONE_SHOT_WAIT_CEILING_MS;
353
+ const unsubscribe = onInput(() => this.wake());
354
+ try {
355
+ while (this.owed.size > 0 && keepWaiting() && !signal.aborted && performance.now() < this.waitDeadline)
356
+ await this.nextDischarge(signal, this.waitDeadline - performance.now());
357
+ }
358
+ finally {
359
+ unsubscribe();
360
+ }
361
+ }
362
+ }
363
+ const ONE_SHOT_WAIT_CEILING_MS = 600_000;
364
+ const LANE_OBLIGATIONS = new WeakMap();
365
+ export function bindDeliveryObligations(sink, book) {
366
+ LANE_OBLIGATIONS.set(sink, book);
367
+ }
368
+ export function oweTerminalDelivery(sink, task) {
369
+ if (typeof sink === "function")
370
+ LANE_OBLIGATIONS.get(sink)?.owe(task);
371
+ }
372
+ export function retireTerminalDelivery(sink, task) {
373
+ if (typeof sink === "function")
374
+ LANE_OBLIGATIONS.get(sink)?.retire(task);
375
+ }
278
376
  export function createLiveNotificationLane(seat) {
279
377
  const handedOff = new Set();
280
378
  const enter = (admits) => (payload, priority, onDisposition) => {
@@ -514,20 +612,24 @@ export function routeOrParkNotification(store, sessionId, payload, priority, onD
514
612
  if (box !== undefined && durable) {
515
613
  store.noteDurablePark(sessionId, dedupKey);
516
614
  const record = carrier !== undefined ? sessionBoxRecordOf({ ...payload, agentMessage: carrier }, box) : engineFrameRecordOf(payload, priority, box);
517
- let appended;
518
- try {
519
- appended = Promise.resolve(box.mailbox.append(box.scope, box.handle, record));
520
- }
521
- catch (e) {
522
- appended = Promise.reject(e);
523
- }
524
- const settled = appended.then(() => onDisposition?.("parked_durably"), (e) => {
525
- store.forgetDurablePark(sessionId, dedupKey);
615
+ const ask = () => {
616
+ try {
617
+ return Promise.resolve(box.mailbox.append(box.scope, box.handle, record));
618
+ }
619
+ catch (e) {
620
+ return Promise.reject(e);
621
+ }
622
+ };
623
+ const appended = ask().catch((first) => {
526
624
  try {
527
- box.onError?.(e);
625
+ box.onError?.(first);
528
626
  }
529
627
  catch {
530
628
  }
629
+ return ask();
630
+ });
631
+ const settled = appended.then(() => onDisposition?.("parked_durably"), () => {
632
+ store.forgetDurablePark(sessionId, dedupKey);
531
633
  store.pend(sessionId, payload, priority);
532
634
  onDisposition?.("parked");
533
635
  });
@@ -544,6 +646,7 @@ export function routeOrParkNotification(store, sessionId, payload, priority, onD
544
646
  export function sessionBoxRecordOf(payload, box) {
545
647
  const peer = payload.peer;
546
648
  return {
649
+ id: taskNotificationDedupKey(payload),
547
650
  from: payload.agentMessage.from,
548
651
  content: payload.agentMessage.body,
549
652
  sentAt: Date.now(),
@@ -569,7 +672,7 @@ function evictOldest(s, match) {
569
672
  const prior = s.dropped.get(laneKey);
570
673
  s.dropped.set(laneKey, { count: (prior?.count ?? 0) + 1, taskType: victim.task_type, taskId: victim.task_id });
571
674
  }
572
- export function discloseDroppedPending(drained) {
675
+ export function discloseDroppedPending(drained, readHandleOf, tasks) {
573
676
  const hasSessionLoss = drained.droppedWholeSession !== undefined && drained.droppedWholeSession > 0;
574
677
  if (!hasSessionLoss && drained.dropped.size === 0)
575
678
  return drained.items;
@@ -579,7 +682,7 @@ export function discloseDroppedPending(drained) {
579
682
  task_id: "session",
580
683
  task_type: "background_agent",
581
684
  status: "event",
582
- summary: `${drained.droppedWholeSession} pending notification(s) for this session were dropped before this turn (the pending store evicted the whole session under its session-count cap). Which tasks they came from is no longer known.`,
685
+ summary: `${drained.droppedWholeSession} pending notification(s) for this session were dropped before this turn (the pending store evicted the whole session under its session-count cap). Which tasks they came from is no longer known.${tasks === undefined ? "" : sessionLossTableClause(tasks())}`,
583
686
  },
584
687
  ]
585
688
  : [];
@@ -621,11 +724,37 @@ export function discloseDroppedPending(drained) {
621
724
  task_id: taskId,
622
725
  task_type: dropped.taskType,
623
726
  status: "event",
624
- summary: `[${taskId}] ${dropped.count} pending notification(s) from this task were dropped (pending-queue overflow) before this turn; nothing else from it survived. TaskOutput("${taskId}") may still serve its spool.`,
727
+ summary: `[${taskId}] ${dropped.count} pending notification(s) from this task were dropped (pending-queue overflow) before this turn; nothing else from it survived.${dropped.taskType === "external" || readHandleOf === undefined ? "" : droppedReadClause(readHandleOf(taskId))}`,
625
728
  });
626
729
  }
627
730
  return [...out, ...sessionLine];
628
731
  }
732
+ function droppedReadClause(read) {
733
+ return read !== undefined ? ` Its ${read}.` : " Its row is no longer readable from this run.";
734
+ }
735
+ const BACKGROUND_TASK_TABLE_ROWS_MAX = 50;
736
+ const BACKGROUND_TASK_TABLE_DESCRIPTION_MAX = 80;
737
+ export function renderBackgroundTaskTable(tasks) {
738
+ const unlisted = tasks.length - BACKGROUND_TASK_TABLE_ROWS_MAX;
739
+ const lines = tasks.slice(0, BACKGROUND_TASK_TABLE_ROWS_MAX).map((t) => {
740
+ const phrase = t.status === "completed"
741
+ ? "completed in background"
742
+ : t.status === "killed"
743
+ ? "stopped"
744
+ : t.status === "running"
745
+ ? "still running in background"
746
+ : t.status === "parked"
747
+ ? "parked awaiting an out-of-band approval — do NOT re-issue the gated call"
748
+ : t.status;
749
+ return `- [${t.id}] Task "${(t.description ?? "background task").slice(0, BACKGROUND_TASK_TABLE_DESCRIPTION_MAX)}" ${phrase}${t.read !== undefined ? ` — ${t.read}` : ""}`;
750
+ });
751
+ return lines.join("\n") + (unlisted > 0 ? `\n(+${unlisted} more background tasks, not listed here)` : "");
752
+ }
753
+ function sessionLossTableClause(rows) {
754
+ return rows.length === 0
755
+ ? " This run has no background task left to read."
756
+ : ` This run's background tasks (read output where its row says, terminate with TaskStop):\n${renderBackgroundTaskTable(rows)}`;
757
+ }
629
758
  export class SystemInjectionQueue {
630
759
  queues = {
631
760
  now: [],
@@ -1,5 +1,5 @@
1
1
  import { type BackgroundAgentRecord, type BackgroundAgentStore } from "./background-agent-store.js";
2
- import { type StopSource, type TaskAccess, type TaskRetrievalStatus, type UnifiedTaskOutput, type UnifiedTaskResult, type BackgroundAgentTaskHandle, type DurableAgentCore, type ParkedClaimTicket, type RegisterBackgroundAgentInput } from "./task-registry-shared.js";
2
+ import { type StopSource, type TaskAccess, type TaskRetrievalStatus, type UnifiedTaskOutput, type UnifiedTaskResult, type BackgroundAgentTaskHandle, type RegisteredTaskHandle, type DurableAgentCore, type ParkedClaimTicket, type RegisterBackgroundAgentInput } from "./task-registry-shared.js";
3
3
  import { type ToolResultStore } from "./tool-result-store.js";
4
4
  import { type AgentState } from "./agent-state.js";
5
5
  import type { CheckpointSeat } from "./checkpoint-seat.js";
@@ -117,13 +117,24 @@ export declare function reapDurableAgentsLane(core: DurableAgentCore, scope: str
117
117
  skippedNoSessions: number;
118
118
  orphanPlacedReleased: number;
119
119
  }>;
120
- /** after a probe-false RELEASE the row must stop claiming a transcript:
121
- * the heartbeat's F-1 arm keeps re-driving a flush-failed lane, so a later successful flush
122
- * would otherwise persist a row whose sessionId points at the session the caller just released.
123
- * Clearing the anchor makes the eventual row honest: state/result survive, transcript does not. */
124
- export declare function releaseDurableTranscriptAnchorLane(core: DurableAgentCore, id: string): void;
120
+ /** The child session a background-agent row is anchored to right now — the session its child runs on
121
+ * or keeps (transcript / resume anchor) — or `undefined` before the bind, after the anchor's release,
122
+ * and on every other task type. The ONE reading of the anchor: the list row's `sessionId` and the
123
+ * release match below both read it here. */
124
+ export declare function childSessionAnchorOf(handle: RegisteredTaskHandle): string | undefined;
125
+ /** A successful release of the child session `sessionId` ends the row's claim on it: both copies of
126
+ * the anchor go — the handle's (the list row reads it) and the durable record's (the heartbeat's F-1
127
+ * arm keeps re-driving a flush-failed lane, so a later successful flush would otherwise persist a row
128
+ * pointing at the session the caller just released). The clear matches the PAIR (row, session): a late
129
+ * clear for a session the row no longer names leaves the current anchor alone. State/result survive,
130
+ * the transcript does not. */
131
+ export declare function releaseDurableTranscriptAnchorLane(core: DurableAgentCore, id: string, sessionId: string): void;
125
132
  /** design/151 S1a — bind the child's freshly-minted store session id onto the row (the transcript /
126
- * resume anchor; absent at register time because the child session is created after registration). */
133
+ * resume anchor; absent at register time because the child session is created after registration).
134
+ * A row already anchored to that session is left as it is (one fact, no second durable write). A row anchored to ANOTHER session
135
+ * is refused: an anchor changes only by its release ({@link releaseDurableTranscriptAnchorLane}) and a fresh bind, never by being
136
+ * written over, so the earlier session is never silently left unowned. An id that is no non-empty string is no anchor and is
137
+ * refused whatever the row holds. */
127
138
  export declare function bindBackgroundAgentSessionLane(core: DurableAgentCore, id: string, sessionId: string): void;
128
139
  /**
129
140
  * #22 — record the org-memory admission verdict THIS leg adjudicated onto the durable row, so the
@@ -556,11 +567,6 @@ agentState?: AgentState): UnifiedTaskResult;
556
567
  */
557
568
  export declare function spillClippedAgentResult(handle: BackgroundAgentTaskHandle, full: string, clipped: string, store: ToolResultStore | undefined, sessionId: string | undefined): Promise<string>;
558
569
  export declare function pollBackgroundAgentLane(handle: BackgroundAgentTaskHandle, deadline?: number, signal?: AbortSignal,
559
- /** Mirrors {@link import("./types.js").TaskSpec.oneShot} (see
560
- * {@link import("./task-registry.js").TaskToolOptions.oneShot} for the full contract): this run has
561
- * no later turn for an async background notification to land in, so the still-running body must
562
- * not teach "you will be notified when it completes". */
563
- oneShot?: boolean,
564
570
  /** design/158 S1 — the offload store a clipped result's full text spills to (see
565
571
  * {@link spillClippedAgentResult}). Absent ⇒ legal degrade, byte-identical to pre-S1 output. */
566
572
  store?: ToolResultStore,
@@ -296,6 +296,7 @@ export async function reapDurableAgentsLane(core, scope, deps, policy) {
296
296
  await deps.sessions.unpin?.(p.sessionId);
297
297
  await deps.sessions.release(p.sessionId);
298
298
  orphanPlacedReleased++;
299
+ releaseDurableTranscriptAnchorLane(core, p.handle, p.sessionId);
299
300
  }
300
301
  catch {
301
302
  }
@@ -310,16 +311,29 @@ export async function reapDurableAgentsLane(core, scope, deps, policy) {
310
311
  }
311
312
  return { rowsReaped, sessionsReleased, skippedNoSessions, orphanPlacedReleased };
312
313
  }
313
- export function releaseDurableTranscriptAnchorLane(core, id) {
314
+ export function childSessionAnchorOf(handle) {
315
+ return handle.type === "background_agent" ? handle.sessionId : undefined;
316
+ }
317
+ export function releaseDurableTranscriptAnchorLane(core, id, sessionId) {
314
318
  const handle = core.handles.get(id);
315
319
  if (!handle || handle.type !== "background_agent")
316
320
  return;
321
+ if (childSessionAnchorOf(handle) !== sessionId)
322
+ return;
323
+ delete handle.sessionId;
317
324
  durableAgentWriteLane(handle, {}, ["sessionId"]);
318
325
  }
319
326
  export function bindBackgroundAgentSessionLane(core, id, sessionId) {
327
+ if (typeof sessionId !== "string" || sessionId === "")
328
+ throw new Error(`TaskRegistry: a background-agent session anchor must be a non-empty session id (got ${typeof sessionId === "string" ? "an empty string" : `a ${sessionId === null ? "null" : typeof sessionId}`})`);
320
329
  const handle = core.handles.get(id);
321
330
  if (!handle || handle.type !== "background_agent")
322
331
  return;
332
+ const anchored = childSessionAnchorOf(handle);
333
+ if (anchored === sessionId)
334
+ return;
335
+ if (anchored !== undefined)
336
+ throw new Error(`TaskRegistry: background-agent row ${id} is anchored to a session already — release that anchor before binding another (the row keeps its anchor)`);
323
337
  handle.sessionId = sessionId;
324
338
  durableAgentWriteLane(handle, { sessionId });
325
339
  }
@@ -426,6 +440,7 @@ export function registerBackgroundAgentLane(core, input) {
426
440
  ...(input.agentType !== undefined ? { agentType: input.agentType } : {}),
427
441
  ...(input.description !== undefined ? { description: input.description } : {}),
428
442
  ...(input.model !== undefined ? { model: input.model } : {}),
443
+ ...(input.policyFloor !== undefined ? { policyFloor: input.policyFloor } : {}),
429
444
  writerId: core.writerId,
430
445
  writerEpoch: 1,
431
446
  spawnedAt: now,
@@ -1094,6 +1109,7 @@ export async function reviveBackgroundAgentLane(core, id, access, abort) {
1094
1109
  handle.resultFull = undefined;
1095
1110
  handle.spillRef = undefined;
1096
1111
  handle.spillFailed = undefined;
1112
+ handle.artifactRef = undefined;
1097
1113
  handle.error = undefined;
1098
1114
  handle.errorCode = undefined;
1099
1115
  handle.errorRetryable = undefined;
@@ -1372,7 +1388,7 @@ export async function spillClippedAgentResult(handle, full, clipped, store, sess
1372
1388
  handle.spillRef = ref;
1373
1389
  return disclose(ref);
1374
1390
  }
1375
- export async function pollBackgroundAgentLane(handle, deadline, signal, oneShot, store, sessionId, checkpointSeat) {
1391
+ export async function pollBackgroundAgentLane(handle, deadline, signal, store, sessionId, checkpointSeat) {
1376
1392
  while (handle.status === "running" && deadline !== undefined && Date.now() < deadline && !signal?.aborted) {
1377
1393
  await sleepPollStep(deadline, signal);
1378
1394
  }
@@ -1418,10 +1434,7 @@ The agent is durably suspended, waiting for an approval decision. It resumes whe
1418
1434
  : "";
1419
1435
  const stateLine = `state: ${agentStateSummary(agentState)}\n`;
1420
1436
  const body = running
1421
- ? oneShot === true
1422
- ? `status: running
1423
- ${stateLine}This is a ONE-SHOT submission — there is no later turn for a background notification to land in, so do NOT end your turn expecting one. Actively wait instead: TaskOutput({ task_id: "${handle.id}", block: true }). If it is still running after the wait, wait again (bounded) rather than ending the turn, or write out your best available answer now if you are near your own time budget.`
1424
- : `status: running
1437
+ ? `status: running
1425
1438
  ${stateLine}The agent is still working — you will be notified when it completes.`
1426
1439
  : `status: ${snap.status}
1427
1440
  ${stateLine}${snap.error ? `error: ${snap.error}${kindClause}
@@ -12,6 +12,13 @@ export declare function absorbMonitorPollLane(handle: MonitorTaskHandle, v: {
12
12
  truncated?: boolean;
13
13
  bytesDroppedBeforeCursor?: number;
14
14
  }): string[];
15
+ /** Append one poll's increment (stdout AND stderr) to the watch's output file — the bash watcher's mirror, for the
16
+ * same absorption's two consumers (the watcher tick and the stop-time drain). Never throws; a failed append is
17
+ * accounted on `spool.mirrorFailed` so the terminal frame says the file is incomplete instead of passing it off as whole. */
18
+ export declare function mirrorMonitorPollLane(handle: MonitorTaskHandle, v: {
19
+ stdout: string;
20
+ stderr: string;
21
+ }): Promise<void>;
15
22
  /** The swallow-guarded event sink, shared by the watcher's emits and the stop-time drain. */
16
23
  export declare function emitMonitorEventLane(handle: MonitorTaskHandle, n: TaskNotificationPayload): void;
17
24
  /** The monitor watcher tick loop. Same zombie-proofing discipline as {@link startBashWatcher}