@sema-agent/core 7.67.2 → 7.68.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 (505) hide show
  1. package/CHANGELOG.md +1533 -0
  2. package/README.md +18 -9
  3. package/README.zh-CN.md +16 -8
  4. package/dist/agents/agent-definition.d.ts +1 -1
  5. package/dist/agents/agent-definition.js +4 -1
  6. package/dist/agents/cascade.d.ts +2 -2
  7. package/dist/agents/cascade.js +3 -1
  8. package/dist/agents/cumulative-stats.d.ts +2 -1
  9. package/dist/agents/cumulative-stats.js +4 -1
  10. package/dist/agents/list-agents-tool.d.ts +30 -0
  11. package/dist/agents/list-agents-tool.js +45 -3
  12. package/dist/agents/peer-admission.d.ts +2 -2
  13. package/dist/agents/peer-session-drain.d.ts +2 -0
  14. package/dist/agents/peer-session-drain.js +1 -0
  15. package/dist/agents/repair-loop.js +3 -1
  16. package/dist/agents/retain-ledger.d.ts +61 -8
  17. package/dist/agents/retain-ledger.js +25 -3
  18. package/dist/agents/roster-store.d.ts +4 -2
  19. package/dist/agents/send-message-tool.d.ts +1 -1
  20. package/dist/agents/send-message-tool.js +20 -15
  21. package/dist/agents/subagent-steps.js +2 -10
  22. package/dist/agents/subagent.d.ts +3 -0
  23. package/dist/agents/subagent.js +106 -76
  24. package/dist/agents/tool-filter.d.ts +20 -11
  25. package/dist/agents/tool-filter.js +8 -4
  26. package/dist/agents/verify.d.ts +3 -1
  27. package/dist/agents/verify.js +2 -0
  28. package/dist/brain/anthropic.js +4 -4
  29. package/dist/brain/errors.d.ts +20 -0
  30. package/dist/brain/errors.js +114 -0
  31. package/dist/brain/open-responses.js +3 -1
  32. package/dist/brain/openai.js +3 -1
  33. package/dist/brain/provider-message.d.ts +5 -3
  34. package/dist/brain/provider-message.js +35 -8
  35. package/dist/brain/reasoning-request.d.ts +73 -19
  36. package/dist/brain/reasoning-request.js +164 -72
  37. package/dist/brain/reasoning-stamp.d.ts +26 -0
  38. package/dist/brain/reasoning-stamp.js +10 -0
  39. package/dist/brain/reasoning.d.ts +95 -162
  40. package/dist/brain/reasoning.js +31 -86
  41. package/dist/brain/route-adjudicator.d.ts +9 -7
  42. package/dist/brain/route-adjudicator.js +12 -10
  43. package/dist/brain/status-sink.d.ts +19 -64
  44. package/dist/brain/status-sink.js +5 -21
  45. package/dist/brain/stream-engine.d.ts +11 -2
  46. package/dist/brain/stream-engine.js +10 -0
  47. package/dist/core/a2a.d.ts +17 -5
  48. package/dist/core/a2a.js +11 -3
  49. package/dist/core/allow-entry.d.ts +35 -15
  50. package/dist/core/allow-entry.js +47 -60
  51. package/dist/core/ask-headline.d.ts +68 -0
  52. package/dist/core/ask-headline.js +23 -0
  53. package/dist/core/ask-origin.d.ts +36 -8
  54. package/dist/core/ask-origin.js +17 -10
  55. package/dist/core/ask-question.d.ts +34 -7
  56. package/dist/core/ask-question.js +10 -1
  57. package/dist/core/ask-unresolvable-notice.d.ts +7 -0
  58. package/dist/core/ask-unresolvable-notice.js +9 -3
  59. package/dist/core/auto-strip.d.ts +53 -0
  60. package/dist/core/auto-strip.js +76 -0
  61. package/dist/core/background-agent-store.d.ts +45 -5
  62. package/dist/core/background-agent-store.js +69 -15
  63. package/dist/core/background-shell.d.ts +2 -2
  64. package/dist/core/caller-text.js +2 -2
  65. package/dist/core/canonical-json.d.ts +13 -0
  66. package/dist/core/canonical-json.js +7 -0
  67. package/dist/core/checkpoint-features.d.ts +66 -20
  68. package/dist/core/checkpoint-features.js +12 -1
  69. package/dist/core/checkpoint-generation.d.ts +1 -1
  70. package/dist/core/checkpoint-queries.d.ts +1 -1
  71. package/dist/core/checkpoint-queries.js +4 -1
  72. package/dist/core/checkpoint-requirements.d.ts +25 -1
  73. package/dist/core/checkpoint-requirements.js +5 -1
  74. package/dist/core/checkpoint-row-verdict.d.ts +1 -0
  75. package/dist/core/checkpoint-row-verdict.js +4 -0
  76. package/dist/core/checkpoint-store.d.ts +66 -38
  77. package/dist/core/checkpoint-store.js +15 -6
  78. package/dist/core/child-clamp-seats.d.ts +6 -0
  79. package/dist/core/child-clamp-seats.js +1 -0
  80. package/dist/core/config-refusal-codes.d.ts +1 -1
  81. package/dist/core/config-refusal-codes.js +1 -0
  82. package/dist/core/delegation-frames.d.ts +9 -12
  83. package/dist/core/delegation-frames.js +9 -8
  84. package/dist/core/engine-capabilities.d.ts +21 -8
  85. package/dist/core/engine-capabilities.js +1 -1
  86. package/dist/core/engine-notice.d.ts +147 -34
  87. package/dist/core/engine-notice.js +27 -16
  88. package/dist/core/engine-storage-backend.d.ts +2 -1
  89. package/dist/core/env-budget.js +3 -3
  90. package/dist/core/env-knob-announce.d.ts +10 -10
  91. package/dist/core/env-knob-announce.js +3 -6
  92. package/dist/core/file-history-store.d.ts +29 -4
  93. package/dist/core/file-history-store.js +13 -0
  94. package/dist/core/frame-settlement.d.ts +2 -1
  95. package/dist/core/gate-fold.js +1 -1
  96. package/dist/core/gate-lanes.js +56 -49
  97. package/dist/core/governance-codes.d.ts +39 -3
  98. package/dist/core/governance-codes.js +61 -3
  99. package/dist/core/hooks.d.ts +29 -11
  100. package/dist/core/hooks.js +5 -2
  101. package/dist/core/human-input-projection.js +3 -3
  102. package/dist/core/input-author.d.ts +17 -3
  103. package/dist/core/input-author.js +15 -3
  104. package/dist/core/leg-identity.d.ts +10 -28
  105. package/dist/core/leg-identity.js +1 -21
  106. package/dist/core/lsp.d.ts +18 -13
  107. package/dist/core/lsp.js +30 -22
  108. package/dist/core/mailbox-store.d.ts +1 -1
  109. package/dist/core/mailbox-store.js +4 -4
  110. package/dist/core/mcp-connection-pool.d.ts +93 -4
  111. package/dist/core/mcp-connection-pool.js +104 -1
  112. package/dist/core/mcp-failure.d.ts +38 -12
  113. package/dist/core/mcp-failure.js +9 -13
  114. package/dist/core/mcp-probe.d.ts +4 -3
  115. package/dist/core/mcp-server-link.d.ts +4 -2
  116. package/dist/core/mcp-server-link.js +4 -5
  117. package/dist/core/mcp-server-spec.d.ts +3 -3
  118. package/dist/core/mcp-server-unavailable-notice.d.ts +22 -8
  119. package/dist/core/mcp-server-unavailable-notice.js +18 -4
  120. package/dist/core/mcp.d.ts +40 -6
  121. package/dist/core/mcp.js +39 -13
  122. package/dist/core/memory-engine/content-origin.js +2 -2
  123. package/dist/core/memory-engine/control-objects.d.ts +2 -4
  124. package/dist/core/memory-engine/control-objects.js +2 -10
  125. package/dist/core/memory-engine/delegation-settlement.js +6 -1
  126. package/dist/core/memory-engine/dual-root.js +3 -0
  127. package/dist/core/memory-engine/engine.d.ts +6 -4
  128. package/dist/core/memory-engine/engine.js +32 -29
  129. package/dist/core/memory-engine/file-backend.d.ts +20 -5
  130. package/dist/core/memory-engine/file-backend.js +21 -31
  131. package/dist/core/memory-engine/frontmatter.d.ts +2 -0
  132. package/dist/core/memory-engine/frontmatter.js +4 -0
  133. package/dist/core/memory-engine/layout.d.ts +114 -20
  134. package/dist/core/memory-engine/layout.js +340 -22
  135. package/dist/core/memory-engine/memory-deployment.d.ts +7 -5
  136. package/dist/core/memory-engine/mount-failed-notice.d.ts +19 -7
  137. package/dist/core/memory-engine/mount-failed-notice.js +43 -10
  138. package/dist/core/memory-engine/sync-client.js +4 -5
  139. package/dist/core/model-fallbacks.d.ts +5 -1
  140. package/dist/core/model-fallbacks.js +3 -3
  141. package/dist/core/model-receipt.d.ts +2 -1
  142. package/dist/core/model-receipt.js +12 -1
  143. package/dist/core/mods/kernel/dispatch.d.ts +2 -2
  144. package/dist/core/mods/kernel/dispatch.js +14 -6
  145. package/dist/core/mods/kernel/events.d.ts +8 -5
  146. package/dist/core/mods/kernel/events.js +2 -2
  147. package/dist/core/mods/kernel/index.d.ts +1 -1
  148. package/dist/core/mods/kernel/registration.d.ts +9 -0
  149. package/dist/core/mods/package.js +1 -1
  150. package/dist/core/mods/session-append.d.ts +4 -2
  151. package/dist/core/mods/session-append.js +3 -0
  152. package/dist/core/mods/stations.d.ts +7 -11
  153. package/dist/core/mods/stations.js +4 -7
  154. package/dist/core/mods/tool-call.d.ts +10 -8
  155. package/dist/core/mods/tool-call.js +15 -18
  156. package/dist/core/mounted-mcp.d.ts +0 -4
  157. package/dist/core/mounted-mcp.js +1 -1
  158. package/dist/core/park-noun.d.ts +24 -0
  159. package/dist/core/park-noun.js +21 -0
  160. package/dist/core/park-resumability.d.ts +60 -0
  161. package/dist/core/park-resumability.js +30 -0
  162. package/dist/core/permission-rule-provider.d.ts +24 -2
  163. package/dist/core/permission-rule-provider.js +11 -8
  164. package/dist/core/permission-rule-store.d.ts +8 -1
  165. package/dist/core/permission-rule-store.js +2 -3
  166. package/dist/core/permission-rules.d.ts +2 -1
  167. package/dist/core/permission-rules.js +8 -4
  168. package/dist/core/persisted-rule-arms.d.ts +3 -0
  169. package/dist/core/persisted-rule-arms.js +2 -1
  170. package/dist/core/present-plan-tool.d.ts +47 -3
  171. package/dist/core/present-plan-tool.js +62 -4
  172. package/dist/core/principal-name.d.ts +1 -1
  173. package/dist/core/principal-name.js +5 -5
  174. package/dist/core/process-identity.js +10 -5
  175. package/dist/core/protocol-http-auth.d.ts +30 -9
  176. package/dist/core/protocol-http-auth.js +113 -59
  177. package/dist/core/read-only-shell.js +9 -5
  178. package/dist/core/redaction-marks.d.ts +4 -26
  179. package/dist/core/redaction-marks.js +9 -21
  180. package/dist/core/remote-env.d.ts +43 -16
  181. package/dist/core/remote-env.js +1 -1
  182. package/dist/core/request-copy-projection.d.ts +1 -1
  183. package/dist/core/request-copy-projection.js +40 -50
  184. package/dist/core/resume-config-judge.js +1 -1
  185. package/dist/core/resume-startup-cause.d.ts +35 -18
  186. package/dist/core/resume-startup-cause.js +13 -10
  187. package/dist/core/retention.d.ts +167 -25
  188. package/dist/core/retention.js +100 -20
  189. package/dist/core/roles.d.ts +6 -0
  190. package/dist/core/roles.js +11 -5
  191. package/dist/core/rule-lane-reads.d.ts +3 -0
  192. package/dist/core/rule-lane-reads.js +5 -1
  193. package/dist/core/rule-store-fault.d.ts +70 -0
  194. package/dist/core/rule-store-fault.js +102 -0
  195. package/dist/core/runner/advertised-writable-dirs.js +16 -31
  196. package/dist/core/runner/announce-once-ledger.d.ts +19 -2
  197. package/dist/core/runner/announce-once-ledger.js +24 -2
  198. package/dist/core/runner/assemble-result.d.ts +6 -0
  199. package/dist/core/runner/assemble-result.js +1 -1
  200. package/dist/core/runner/auto-strip-notice.d.ts +36 -0
  201. package/dist/core/runner/auto-strip-notice.js +59 -0
  202. package/dist/core/runner/branch-window.d.ts +3 -0
  203. package/dist/core/runner/branch-window.js +37 -0
  204. package/dist/core/runner/caller-roster.d.ts +8 -3
  205. package/dist/core/runner/capability-withheld-seat.js +3 -9
  206. package/dist/core/runner/clock-and-limits.d.ts +22 -1
  207. package/dist/core/runner/clock-and-limits.js +30 -0
  208. package/dist/core/runner/contracts.d.ts +58 -35
  209. package/dist/core/runner/credential-refusal-seat.d.ts +2 -0
  210. package/dist/core/runner/credential-refusal-seat.js +47 -0
  211. package/dist/core/runner/cross-boundary-lane.js +6 -4
  212. package/dist/core/runner/decide-continuation.js +1 -1
  213. package/dist/core/runner/file-history-restore.d.ts +53 -2
  214. package/dist/core/runner/file-history-restore.js +29 -10
  215. package/dist/core/runner/forward-sink.d.ts +14 -1
  216. package/dist/core/runner/forward-sink.js +14 -12
  217. package/dist/core/runner/gate-exit.d.ts +8 -7
  218. package/dist/core/runner/gate-exit.js +13 -13
  219. package/dist/core/runner/git-status-frame.js +2 -4
  220. package/dist/core/runner/initial-run-state.js +1 -1
  221. package/dist/core/runner/main-call-account.d.ts +3 -1
  222. package/dist/core/runner/main-call-account.js +5 -3
  223. package/dist/core/runner/mcp-redial.d.ts +2 -5
  224. package/dist/core/runner/mcp-redial.js +2 -2
  225. package/dist/core/runner/nested-memory-content.d.ts +7 -1
  226. package/dist/core/runner/nested-memory-content.js +73 -13
  227. package/dist/core/runner/nested-memory-lane.d.ts +44 -19
  228. package/dist/core/runner/nested-memory-lane.js +152 -76
  229. package/dist/core/runner/park-commit.js +3 -1
  230. package/dist/core/runner/permission-rule-lanes.d.ts +8 -2
  231. package/dist/core/runner/permission-rule-lanes.js +29 -3
  232. package/dist/core/runner/person-path-rows.d.ts +3 -11
  233. package/dist/core/runner/person-path-rows.js +21 -24
  234. package/dist/core/runner/prepare-acquire-reconcile.js +3 -1
  235. package/dist/core/runner/prepare-artifact.d.ts +1 -1
  236. package/dist/core/runner/prepare-artifact.js +20 -14
  237. package/dist/core/runner/prepare-ask-lane.d.ts +9 -6
  238. package/dist/core/runner/prepare-ask-lane.js +6 -5
  239. package/dist/core/runner/prepare-boundary-parks.d.ts +7 -1
  240. package/dist/core/runner/prepare-boundary-parks.js +27 -24
  241. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -2
  242. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  243. package/dist/core/runner/prepare-config-doors.d.ts +9 -24
  244. package/dist/core/runner/prepare-config-doors.js +58 -41
  245. package/dist/core/runner/prepare-context-lane.d.ts +2 -2
  246. package/dist/core/runner/prepare-context-lane.js +3 -5
  247. package/dist/core/runner/prepare-defer-classify.d.ts +1 -1
  248. package/dist/core/runner/prepare-defer-classify.js +1 -1
  249. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
  250. package/dist/core/runner/prepare-delegation-surface.js +3 -2
  251. package/dist/core/runner/prepare-file-history.d.ts +62 -26
  252. package/dist/core/runner/prepare-file-history.js +117 -46
  253. package/dist/core/runner/prepare-gate-stations.d.ts +4 -0
  254. package/dist/core/runner/prepare-gate-stations.js +6 -5
  255. package/dist/core/runner/prepare-hands-readface.d.ts +9 -4
  256. package/dist/core/runner/prepare-hands-readface.js +8 -4
  257. package/dist/core/runner/prepare-inherited-gate.d.ts +11 -4
  258. package/dist/core/runner/prepare-inherited-gate.js +6 -6
  259. package/dist/core/runner/prepare-listings.d.ts +1 -1
  260. package/dist/core/runner/prepare-listings.js +1 -1
  261. package/dist/core/runner/prepare-memory.js +2 -2
  262. package/dist/core/runner/prepare-offload-wrappers.d.ts +1 -1
  263. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  264. package/dist/core/runner/prepare-park-ask.d.ts +10 -3
  265. package/dist/core/runner/prepare-park-ask.js +7 -9
  266. package/dist/core/runner/prepare-policy-chain.d.ts +18 -9
  267. package/dist/core/runner/prepare-policy-chain.js +18 -13
  268. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  269. package/dist/core/runner/prepare-project-context.js +5 -3
  270. package/dist/core/runner/prepare-prompt-assembly.js +2 -1
  271. package/dist/core/runner/prepare-prompt-inputs.d.ts +2 -2
  272. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  273. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -5
  274. package/dist/core/runner/prepare-protocol-tools.js +7 -7
  275. package/dist/core/runner/prepare-question-face.d.ts +4 -2
  276. package/dist/core/runner/prepare-run-refs.d.ts +7 -2
  277. package/dist/core/runner/prepare-run-refs.js +8 -7
  278. package/dist/core/runner/prepare-safety-scan.d.ts +4 -3
  279. package/dist/core/runner/prepare-suspend-saga.d.ts +3 -7
  280. package/dist/core/runner/prepare-suspend-saga.js +4 -3
  281. package/dist/core/runner/prepare-task.js +66 -53
  282. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +3 -2
  283. package/dist/core/runner/prepare-tool-disclosure-mount.js +2 -1
  284. package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
  285. package/dist/core/runner/prepare-turn-wiring.js +1 -1
  286. package/dist/core/runner/prepare-wiring-manifest.d.ts +9 -4
  287. package/dist/core/runner/prepare-wiring-manifest.js +14 -6
  288. package/dist/core/runner/prepare-workspace-restore.d.ts +4 -4
  289. package/dist/core/runner/prepare-workspace-restore.js +15 -6
  290. package/dist/core/runner/remote-env-retry.d.ts +3 -3
  291. package/dist/core/runner/restore-seat.d.ts +41 -0
  292. package/dist/core/runner/restore-seat.js +38 -0
  293. package/dist/core/runner/resume-admission.js +1 -1
  294. package/dist/core/runner/resume-apply.js +4 -3
  295. package/dist/core/runner/resume-checkpoint-screen.js +2 -1
  296. package/dist/core/runner/resume-internals-and-config.js +2 -1
  297. package/dist/core/runner/resume-preflight.js +2 -1
  298. package/dist/core/runner/rewind-files.js +22 -6
  299. package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -0
  300. package/dist/core/runner/rule-store-unreadable-notice.js +11 -0
  301. package/dist/core/runner/run-brain-sinks.d.ts +3 -6
  302. package/dist/core/runner/run-brain-sinks.js +6 -6
  303. package/dist/core/runner/run-compaction-machinery.d.ts +2 -2
  304. package/dist/core/runner/run-git-lane.d.ts +2 -0
  305. package/dist/core/runner/run-git-lane.js +2 -1
  306. package/dist/core/runner/run-harness-handlers.js +5 -4
  307. package/dist/core/runner/run-identity-wiring.js +20 -12
  308. package/dist/core/runner/run-leg.js +31 -72
  309. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  310. package/dist/core/runner/run-notification-lane.js +2 -4
  311. package/dist/core/runner/run-reasoning-seat.d.ts +5 -6
  312. package/dist/core/runner/run-reasoning-seat.js +13 -18
  313. package/dist/core/runner/run-settle-and-teardown.js +13 -9
  314. package/dist/core/runner/run-terminal-adoption.js +4 -8
  315. package/dist/core/runner/run-turn-boundary.js +6 -3
  316. package/dist/core/runner/runtask.d.ts +9 -4
  317. package/dist/core/runner/runtask.js +29 -22
  318. package/dist/core/runner/session-rule-policy.d.ts +11 -1
  319. package/dist/core/runner/shell-env-withheld.js +2 -7
  320. package/dist/core/runner/side-call-account.d.ts +5 -6
  321. package/dist/core/runner/side-call-account.js +2 -2
  322. package/dist/core/runner/stream-lifecycle-verbs.d.ts +3 -0
  323. package/dist/core/runner/stream-lifecycle-verbs.js +5 -3
  324. package/dist/core/runner/stream-settle-backstop.js +4 -6
  325. package/dist/core/runner/stream-steer-verb.d.ts +1 -1
  326. package/dist/core/runner/stream-steer-verb.js +4 -4
  327. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -3
  328. package/dist/core/runner/sub-agent-deny-lists.js +7 -4
  329. package/dist/core/runner/teardown-bounded.d.ts +7 -0
  330. package/dist/core/runner/teardown-bounded.js +7 -0
  331. package/dist/core/runner/terminal-account.js +41 -13
  332. package/dist/core/runner/terminal-projection.d.ts +1 -5
  333. package/dist/core/runner/tool-end-body.d.ts +9 -3
  334. package/dist/core/runner/tool-end-body.js +6 -3
  335. package/dist/core/runner/tool-output-projection.d.ts +13 -4
  336. package/dist/core/runner/tool-output-projection.js +10 -14
  337. package/dist/core/runner/turn-attachments.d.ts +3 -2
  338. package/dist/core/runner/turn-attachments.js +12 -5
  339. package/dist/core/runner-deps.d.ts +6 -6
  340. package/dist/core/runtime-caps.d.ts +2 -1
  341. package/dist/core/secret-env.d.ts +20 -3
  342. package/dist/core/secret-env.js +13 -15
  343. package/dist/core/session-checkout.d.ts +115 -15
  344. package/dist/core/session-checkout.js +435 -136
  345. package/dist/core/session-policy-store.js +21 -3
  346. package/dist/core/session-reconcile.js +1 -0
  347. package/dist/core/session-store.js +2 -0
  348. package/dist/core/session.d.ts +11 -1
  349. package/dist/core/shell-run-candidates.d.ts +1 -0
  350. package/dist/core/shell-run-candidates.js +1 -1
  351. package/dist/core/shutdown-debug.d.ts +6 -5
  352. package/dist/core/shutdown-debug.js +5 -1
  353. package/dist/core/skill-grant.js +4 -1
  354. package/dist/core/skills-directory.js +5 -3
  355. package/dist/core/spec-contract.d.ts +1 -1
  356. package/dist/core/store-contracts/checkpoint-store-contract.js +2 -7
  357. package/dist/core/store-contracts/file-history-store-contract.js +26 -2
  358. package/dist/core/store-contracts/session-deletion-cascade-contract.js +130 -14
  359. package/dist/core/store-contracts/task-list-store-contract.d.ts +2 -1
  360. package/dist/core/store-contracts/task-list-store-contract.js +28 -1
  361. package/dist/core/task-event.d.ts +48 -27
  362. package/dist/core/task-notification.d.ts +15 -9
  363. package/dist/core/task-notification.js +12 -0
  364. package/dist/core/task-registry-agent.d.ts +24 -22
  365. package/dist/core/task-registry-agent.js +65 -46
  366. package/dist/core/task-registry-shared.d.ts +17 -5
  367. package/dist/core/task-registry.d.ts +17 -6
  368. package/dist/core/task-registry.js +6 -1
  369. package/dist/core/task-result.d.ts +71 -25
  370. package/dist/core/task-spec-members.d.ts +0 -1
  371. package/dist/core/task-spec-members.js +1 -1
  372. package/dist/core/task-spec.d.ts +60 -52
  373. package/dist/core/task-stream.d.ts +45 -12
  374. package/dist/core/terminal-cause.d.ts +45 -8
  375. package/dist/core/terminal-cause.js +5 -0
  376. package/dist/core/tool-card-bound.d.ts +32 -0
  377. package/dist/core/tool-card-bound.js +33 -0
  378. package/dist/core/tool-catalog-entries.d.ts +9 -0
  379. package/dist/core/tool-catalog-entries.js +48 -0
  380. package/dist/core/tool-errors.d.ts +4 -3
  381. package/dist/core/tool-face.d.ts +3 -3
  382. package/dist/core/tool-mount-facts.d.ts +3 -2
  383. package/dist/core/tool-mount-facts.js +1 -1
  384. package/dist/core/tool-mount-static.js +7 -5
  385. package/dist/core/tool-policy.d.ts +21 -19
  386. package/dist/core/tool-policy.js +5 -6
  387. package/dist/core/tool-registry.d.ts +3 -1
  388. package/dist/core/tool-registry.js +15 -1
  389. package/dist/core/tool-result-store.d.ts +9 -3
  390. package/dist/core/tool-result-store.js +14 -1
  391. package/dist/core/tool-roster.d.ts +6 -0
  392. package/dist/core/tool-roster.js +18 -0
  393. package/dist/core/tool-spec.d.ts +17 -8
  394. package/dist/core/trace.d.ts +35 -31
  395. package/dist/core/types.d.ts +2 -2
  396. package/dist/core/untrusted-egress.d.ts +19 -7
  397. package/dist/core/untrusted-egress.js +26 -7
  398. package/dist/core/untrusted-text.d.ts +6 -18
  399. package/dist/core/untrusted-text.js +11 -4
  400. package/dist/core/user-attachment.d.ts +9 -6
  401. package/dist/core/user-attachment.js +12 -10
  402. package/dist/core/user-row-origin.d.ts +44 -25
  403. package/dist/core/user-row-origin.js +30 -20
  404. package/dist/core/wiring-manifest.d.ts +26 -7
  405. package/dist/core/wiring-manifest.js +14 -11
  406. package/dist/core/workspace-snapshot.d.ts +3 -1
  407. package/dist/core/workspace-snapshot.js +1 -0
  408. package/dist/engine/execution-env/node-execution-env.d.ts +23 -16
  409. package/dist/engine/execution-env/node-execution-env.js +127 -67
  410. package/dist/engine/harness/agent-harness.d.ts +4 -5
  411. package/dist/engine/harness/agent-harness.js +2 -7
  412. package/dist/engine/harness/types.d.ts +51 -19
  413. package/dist/engine/harness/types.js +28 -1
  414. package/dist/engine/llm/types.d.ts +26 -14
  415. package/dist/engine/llm/types.js +2 -2
  416. package/dist/engine/loop/agent-loop.d.ts +2 -2
  417. package/dist/engine/loop/agent-loop.js +51 -275
  418. package/dist/engine/loop/types.d.ts +0 -18
  419. package/dist/engine/session/import-validate.d.ts +3 -0
  420. package/dist/engine/session/import-validate.js +34 -2
  421. package/dist/engine/session/repo-utils.d.ts +42 -4
  422. package/dist/engine/session/repo-utils.js +33 -5
  423. package/dist/engine/session/session.d.ts +41 -14
  424. package/dist/engine/session/session.js +96 -25
  425. package/dist/index.d.ts +21 -16
  426. package/dist/index.js +16 -10
  427. package/dist/orchestration/run-spec.d.ts +1 -1
  428. package/dist/orchestration/run-workflow-tool.d.ts +12 -9
  429. package/dist/orchestration/run-workflow-tool.js +15 -19
  430. package/dist/orchestration/workflow-governance.js +13 -21
  431. package/dist/orchestration/workflow-observe.d.ts +4 -3
  432. package/dist/orchestration/workflow-primitives.d.ts +1 -1
  433. package/dist/orchestration/workflow-record-artifact.d.ts +14 -0
  434. package/dist/orchestration/workflow-record-artifact.js +32 -0
  435. package/dist/orchestration/workflow-script-store.d.ts +9 -0
  436. package/dist/orchestration/workflow-script-store.js +20 -1
  437. package/dist/orchestration/workflow-types.d.ts +33 -3
  438. package/dist/orchestration/workflow.d.ts +24 -14
  439. package/dist/orchestration/workflow.js +52 -23
  440. package/dist/prompt-assembly/artifact.js +4 -8
  441. package/dist/prompt-assembly/catalog/engine.d.ts +263 -0
  442. package/dist/prompt-assembly/catalog/engine.js +30 -0
  443. package/dist/prompt-assembly/catalog/index.d.ts +1 -1
  444. package/dist/prompt-assembly/catalog/index.js +2 -2
  445. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +1 -1
  446. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +29 -0
  447. package/dist/prompt-assembly/epoch.js +6 -8
  448. package/dist/prompt-assembly/turn-snapshot.js +8 -9
  449. package/dist/stores/file/background-agent-store.js +5 -6
  450. package/dist/stores/file/checkpoint-store.d.ts +0 -4
  451. package/dist/stores/file/checkpoint-store.js +7 -3
  452. package/dist/stores/file/file-history-store.d.ts +8 -0
  453. package/dist/stores/file/file-history-store.js +72 -0
  454. package/dist/stores/file/fs-atomic.js +17 -12
  455. package/dist/stores/file/index.js +11 -5
  456. package/dist/stores/file/mailbox-store.js +13 -4
  457. package/dist/stores/file/permission-rule-store.js +14 -13
  458. package/dist/stores/file/shared-ledger.d.ts +4 -0
  459. package/dist/stores/file/shared-ledger.js +4 -0
  460. package/dist/stores/file/task-list-store.js +12 -3
  461. package/dist/stores/file/workflow-run-store.js +1 -0
  462. package/dist/tools/fs/bash-program-position.d.ts +4 -2
  463. package/dist/tools/fs/bash-program-position.js +1 -1
  464. package/dist/tools/fs/bash-readonly-classifier.js +1 -1
  465. package/dist/tools/fs/bound-open.d.ts +97 -0
  466. package/dist/tools/fs/bound-open.js +103 -0
  467. package/dist/tools/fs/containment-face.d.ts +2 -2
  468. package/dist/tools/fs/fs-pdf.d.ts +7 -1
  469. package/dist/tools/fs/fs-pdf.js +31 -23
  470. package/dist/tools/fs/fs-read.d.ts +24 -17
  471. package/dist/tools/fs/fs-read.js +84 -53
  472. package/dist/tools/fs/fs-shared.d.ts +14 -12
  473. package/dist/tools/fs/fs-shared.js +5 -4
  474. package/dist/tools/fs/fs-write.d.ts +2 -2
  475. package/dist/tools/fs/fs-write.js +20 -12
  476. package/dist/tools/fs/index.d.ts +4 -4
  477. package/dist/tools/fs/index.js +2 -2
  478. package/dist/tools/fs/notebook.d.ts +1 -1
  479. package/dist/tools/fs/pdf.d.ts +12 -3
  480. package/dist/tools/fs/pdf.js +22 -9
  481. package/dist/tools/fs/read-deny-home.d.ts +3 -2
  482. package/dist/tools/fs/read-deny-home.js +8 -11
  483. package/dist/tools/fs/safety.d.ts +3 -2
  484. package/dist/tools/fs/shell-read-check.js +10 -9
  485. package/dist/tools/monitor.d.ts +6 -5
  486. package/dist/tools/task-list.d.ts +16 -6
  487. package/dist/tools/task-list.js +4 -0
  488. package/dist/tools/web.d.ts +9 -1
  489. package/dist/tools/web.js +8 -3
  490. package/dist/tools/worktree.d.ts +7 -5
  491. package/dist/tools/worktree.js +4 -3
  492. package/package.json +4 -3
  493. package/test/export-surface.snapshot.json +93 -7
  494. package/wire-changes/core-stores-sql@7.67.3.json +39 -0
  495. package/wire-changes/core-stores-sql@7.68.0.json +39 -0
  496. package/wire-changes/core@7.67.3.json +65 -0
  497. package/wire-changes/core@7.68.0.json +4257 -0
  498. package/wire-changes/mods-kernel@7.67.3.json +39 -0
  499. package/wire-changes/mods-kernel@7.68.0.json +129 -0
  500. package/wire-changes/primitives@7.67.3.json +39 -0
  501. package/wire-changes/primitives@7.68.0.json +253 -0
  502. package/wire-changes/wiki-gate@7.67.3.json +39 -0
  503. package/wire-changes/wiki-gate@7.68.0.json +39 -0
  504. package/dist/core/runner/credential-origin-seat.d.ts +0 -2
  505. package/dist/core/runner/credential-origin-seat.js +0 -20
@@ -0,0 +1,32 @@
1
+ import { types } from "node:util";
2
+ import { isPlainRecord, receive } from "../core/mods/kernel/receive.js";
3
+ import { isTaskArtifactRef } from "../core/tool-result-store.js";
4
+ const RECORD_ARTIFACT_RECEIPT = Object.freeze({ accessors: "refuse", depth: 1, others: "refuse", isProxy: (v) => types.isProxy(v) });
5
+ const RECORD_ARTIFACT_LINE = {
6
+ stored: (ref) => `Full record (the result and every agent's row): read it with ReadToolResult (ref "${ref}") before assuming an empty or unexpected result.`,
7
+ unconfirmed: () => "The full record (the result and every agent's row) could not be stored (the write failed or went unconfirmed), so no ref can read it back — it is not readable in this session.",
8
+ no_store: () => "The full record (the result and every agent's row) is not stored behind a ref (no offload store) — it is not readable in this session.",
9
+ };
10
+ const RECORD_UNREADABLE_LINE = "This run's record could not be read.";
11
+ function isRecordArtifactKind(word) {
12
+ return Object.hasOwn(RECORD_ARTIFACT_LINE, word);
13
+ }
14
+ function decodeRecordArtifact(raw) {
15
+ const received = receive(raw, RECORD_ARTIFACT_RECEIPT);
16
+ if (!received.ok || !isPlainRecord(received.value))
17
+ return undefined;
18
+ const { kind, ref } = received.value;
19
+ if (typeof kind !== "string" || !isRecordArtifactKind(kind))
20
+ return undefined;
21
+ if (kind === "stored")
22
+ return typeof ref === "string" && isTaskArtifactRef(ref) ? { kind, ref } : undefined;
23
+ return ref === undefined ? { kind } : undefined;
24
+ }
25
+ export function workflowRecordPickupOf(raw) {
26
+ const artifact = decodeRecordArtifact(raw);
27
+ if (artifact === undefined)
28
+ return { line: RECORD_UNREADABLE_LINE };
29
+ if (artifact.kind === "stored")
30
+ return { ref: artifact.ref, line: RECORD_ARTIFACT_LINE.stored(artifact.ref) };
31
+ return { line: RECORD_ARTIFACT_LINE[artifact.kind]() };
32
+ }
@@ -62,6 +62,15 @@ export interface WorkflowScriptStore {
62
62
  * B-4 (BREAKING): `scope` bounds the read to the CALLER's partition — a path pointing into
63
63
  * another scope's partition must be refused exactly like a path outside the store. */
64
64
  load(scriptPath: string, scope: string): Promise<string> | string;
65
+ /**
66
+ * Erase the script {@link persist} stored for `runId` in `scope`'s partition — the session-tree cascade's leg for a terminal run its
67
+ * session started ({@link import("../core/retention.js").RETENTION_CASCADE}), found through the run store's rows while they exist.
68
+ * `true` = this call removed it; `false` = there was none under that scope (another scope's script is not this call's, and an id
69
+ * {@link persist} would refuse names none). Idempotent; a store fault throws (a deletion face that cannot delete is loud). A later
70
+ * {@link load} of the path it answered fails as a missing file. The saved-name tier is not a run's and is never touched. OPTIONAL:
71
+ * absent ⇒ this store's per-run scripts outlive their runs, and the deployment owns that gap.
72
+ */
73
+ deleteRun?(runId: string, scope: string): Promise<boolean> | boolean;
65
74
  /** Resolve a SAVED workflow name to its registration (undefined = unknown name). Optional — a deployment
66
75
  * without a named registry simply omits it. RB-482 #9 (ruled 2026-08-03): ONE return form — a
67
76
  * {@link NamedWorkflowResolution} ({ script, defaultArgs? }); the legacy bare-string return is retired. A
@@ -1,4 +1,4 @@
1
- import { mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
1
+ import { mkdirSync, readFileSync, writeFileSync, existsSync, unlinkSync } from "node:fs";
2
2
  import { join, resolve, sep } from "node:path";
3
3
  import { physicalPathOfExisting } from "../core/physical-path.js";
4
4
  import { sanitizeScope } from "../stores/file/fs-atomic.js";
@@ -68,6 +68,25 @@ export function createFileWorkflowScriptStore(dir) {
68
68
  refusePhysical();
69
69
  return readFileSync(physFull, "utf-8");
70
70
  },
71
+ deleteRun(runId, scope) {
72
+ const stem = safeFileStem(runId);
73
+ if (stem === undefined)
74
+ return false;
75
+ const base = scopeDir(scope);
76
+ const physBase = physicalPathOfExisting(base);
77
+ if (!containedBy(physicalPathOfExisting(root), physBase)) {
78
+ throw new Error(`workflow script store: this scope's script partition resolves outside the store — refusing to delete through it`);
79
+ }
80
+ try {
81
+ unlinkSync(join(physBase, `${stem}.js`));
82
+ return true;
83
+ }
84
+ catch (err) {
85
+ if (err.code === "ENOENT")
86
+ return false;
87
+ throw err;
88
+ }
89
+ },
71
90
  resolveName(name) {
72
91
  if (/^wf_/i.test(name))
73
92
  return undefined;
@@ -386,6 +386,34 @@ export interface WorkflowRun {
386
386
  * this field ever being set. Absent while `status === "running"`, or on a run recorded by an older
387
387
  * engine version. */
388
388
  completionId?: string;
389
+ /**
390
+ * Where this run's FULL record (its result and every agent's row, the `ReadToolResult` page-back of the whole
391
+ * record) can be fetched — the one answer to that question. Written once, by the engine, in the run's terminal
392
+ * transition: the record is stored first, then this member is set, and it lands in the same terminal write as
393
+ * `status` (a reader that sees this engine's terminal record sees this member). Never rewritten afterwards.
394
+ *
395
+ * Three readings:
396
+ * - `stored` — the whole record was written to the run's result store (`RunWorkflowOptions.taskArtifacts`) and the
397
+ * write settled inside the terminal bound; `ref` is the key `ReadToolResult` reads it back with. It promises the
398
+ * write landed at the terminal, not that it is still readable: the record stays readable only as long as the
399
+ * deployment's result store keeps it (a store whose retention is shorter than the run record's answers a later
400
+ * read as expired);
401
+ * - `unconfirmed` — the run had a result store but this write did not settle as written (it threw, outlived the
402
+ * bound, or the record could not be rendered); no ref is announced, and a late landing is never written back;
403
+ * - `no_store` — the run was started with no result store.
404
+ *
405
+ * ABSENT on a running run, on a record an older engine wrote, on a record a deployment closed itself (an orphan
406
+ * sweep flips a `running` row), and on a terminal write that did not land — so a terminal record without it is
407
+ * NOT `no_store`. The engine only writes it; a reader decodes it through `workflowRecordPickupOf`, which also
408
+ * carries the sentence that names it to a model (a value outside these shapes reads as absent).
409
+ */
410
+ recordArtifact?: {
411
+ kind: "stored";
412
+ ref: string;
413
+ } | {
414
+ kind: "unconfirmed" | "no_store";
415
+ ref?: undefined;
416
+ };
389
417
  /** RB-243: what this run's `resumeFromRunId` actually yielded — ADDITIVE observation (same
390
418
  * contract as {@link agentFailures}: never a gate input; absent on non-resume runs, on runs recorded by
391
419
  * older engines, and on a column-mapped store that doesn't project it). Previously a resume whose journal
@@ -673,9 +701,11 @@ export declare class WorkflowAgentParkedError extends Error {
673
701
  * `unreadable` (the checkpoint store's word could not be read — the park stands). */
674
702
  export type WorkflowParkDeliveryResult = "driving" | "settled" | "kept_parked" | "already_taken" | "not_parked_here" | "unreadable";
675
703
  /** #2561 — the answer to a delivery: `live` (the run is running here and took the decisions, per-decision
676
- * `results`); `suspending` (the run has suspended on its parks and is ending — `ended` settles at its end, after
677
- * which the host resumes it with the decisions); `not_active` (no run of that id and scope is running in this
678
- * process); `not_armed` (the run holds no checkpoint store to prove a park against). */
704
+ * `results`); `suspending` (the run is ending in this process — suspended on its parks, or finishing; `ended`
705
+ * settles once its terminal row's write has settled, written or refused by the store, and the host then acts on
706
+ * the record, resuming the run with the decisions if the record says it suspended); `not_active` (this process
707
+ * has no run of that id and scope — it ended and is gone, runs in another process, or never ran here);
708
+ * `not_armed` (the run holds no checkpoint store to prove a park against). */
679
709
  export type WorkflowParkDelivery = {
680
710
  kind: "live";
681
711
  results: WorkflowParkDeliveryResult[];
@@ -6,6 +6,7 @@ import { type ParentSpecSeat } from "../core/parent-spec-seat.js";
6
6
  import type { WorkflowRunStore } from "../core/workflow-run-store.js";
7
7
  import type { WorkflowJournalStore, ResumeClaimArgs } from "../core/workflow-journal-store.js";
8
8
  import type { WorkflowRun, WorkflowEvent } from "./workflow-types.js";
9
+ import { type TaskArtifactSeat } from "../core/tool-result-store.js";
9
10
  export * from "./workflow-types.js";
10
11
  /** 198 `P0m` (pretty.js:447248) — prose state: the child's final text is the script-facing return value. */
11
12
  export declare const WORKFLOW_SUBAGENT_PROMPT = "You are a subagent spawned by a workflow orchestration script. Use the tools available to complete the task.\n\nCRITICAL: Your final text response is returned **verbatim** as a string to the calling script \u2014 it is your return value, not a message to a human.\n- Output the literal result (data, JSON, text). Do NOT output confirmations like \"Done.\" or \"Sent.\"\n- If asked for JSON, return ONLY the raw JSON \u2014 no code fences, no prose, no markdown.\n- Do NOT address a human user \u2014 there is no user on the other end. Put your answer in your final text response.\n- Do NOT delegate to further sub-agents or start nested workflows; complete the task yourself.\n- Be concise. The script will parse your output.";
@@ -153,6 +154,10 @@ export interface WorkflowInternals {
153
154
  * wrote them, so they are not asked again here; a ceiling a host writes itself is {@link RunWorkflowOptions.toolCeiling}, which is.
154
155
  * Given both, both bound every agent (these layers first) and only the host-written one is judged. */
155
156
  toolCeiling?: readonly import("../core/tool-face.js").ToolSelectorLayer[];
157
+ /** The MCP connection pool of the prepared run that launched this workflow (`ToolExecuteContext.mcpPool`), threaded into EVERY spawned
158
+ * agent (`RunInternals.mcpPool`) on both spawn legs: the agents lease from the launching session's pool and read what it remembers of
159
+ * a failed attempt, as a delegated child does. */
160
+ mcpPool?: import("../core/mcp-connection-pool.js").McpConnectionPool;
156
161
  }
157
162
  export interface WorkflowBudget {
158
163
  /** The token ceiling, or null when none was set (then `remaining()` is Infinity). */
@@ -334,6 +339,11 @@ export interface RunWorkflowOptions {
334
339
  * throw is swallowed and NEVER breaks the workflow (the run/script is the source of truth; the store is an
335
340
  * observation layer). The owner is the sole writer (rev CAS). */
336
341
  store?: WorkflowRunStore;
342
+ /** Where the run's full record (its result and every agent's row) is written at its terminal, for `ReadToolResult` to
343
+ * read back: the engine writes it before `run_end` and records the outcome on {@link WorkflowRun.recordArtifact}
344
+ * (`stored` with its ref, `unconfirmed`, or — with no seat — `no_store`). The write is bounded
345
+ * ({@link WORKFLOW_STORE_WAIT_BOUND_MS}); a run store is not needed for it. */
346
+ taskArtifacts?: TaskArtifactSeat;
337
347
  /** Tenant/grouping key for the run (default `"default"`). */
338
348
  scope?: string;
339
349
  /** design/99 MF-W: the workflow's display name + description (the run_workflow tool passes the script's
@@ -528,7 +538,7 @@ export interface RunWorkflowOptions {
528
538
  * directly-started workflow passes its own. NOT call identity. REQUIRES {@link checkpointStore} as well: a
529
539
  * durable approval whose checkpoint this workflow cannot read back is a park no resume can prove.
530
540
  */
531
- defaultDurableApproval?: TaskSpec["durableApproval"];
541
+ defaultDurableApproval?: Exclude<TaskSpec["durableApproval"], false>;
532
542
  /**
533
543
  * The HOST run's parent SPEC seat ({@link import("../core/parent-spec-seat.js").ParentSpecSeat}: principal / oneShot /
534
544
  * clientContext / the frozen question face / the fs-fence widening / envFacts / the declared persistence statement),
@@ -714,17 +724,17 @@ export declare const WORKFLOW_AGENT_MAX_RETRIES = 5;
714
724
  * degraded response (a flat sleep, NOT exponential backoff — and only on the FIRST attempt's result). */
715
725
  export declare const WORKFLOW_AGENT_THROTTLE_BACKOFF_MS = 45000;
716
726
  /**
717
- * RB-355 (2026-07-29) — the cap on how long the TERMINAL boundary waits on the resume-claim
718
- * store (the admission verdict, then the release). Both awaits sit in the run's `finally`, i.e. AFTER the
719
- * outcome is already decided: an unbounded wait there means a store implementation that hangs (a wedged
720
- * connection pool, a lost network write, a promise that simply never settles) leaves the run's `done` promise
721
- * pending FOREVER, silently discarding the guarantee `totalTimeoutMs` makes to the caller — the deadline
722
- * aborts the body, and then the cleanup hangs on the same broken store. Timing out here loses nothing that
723
- * was not already lost: a release that cannot complete leaves a claim row behind, which is precisely what the
724
- * store's TTL (invalidation layer 2) exists to reap. Scheduled on the injectable {@link WorkflowTimers} seam,
725
- * so the timer is unref'd by default and tests can drive it without waiting.
727
+ * RB-355 (2026-07-29) — the cap on a store wait the run makes inside its own control flow and has a stated answer for
728
+ * when the store does not settle. Its waits: a resume's reads of a recorded park (the checkpoint row, the origin journal),
729
+ * a park's awaited row write, and at the TERMINAL boundary the full-record write ({@link WorkflowRun.recordArtifact})
730
+ * and the resume claim (the admission verdict, then the release). An unbounded wait in any of them means a store
731
+ * implementation that hangs (a wedged connection pool, a lost network write, a promise that simply never settles) holds
732
+ * the run there FOREVER — at the terminal, the run's `done` stays pending, silently discarding the guarantee
733
+ * `totalTimeoutMs` makes to the caller. Each site's fallback is what it can answer without the store: the resume
734
+ * refuses, the park discloses, the record reads `unconfirmed`, the claim release is left to the store's TTL
735
+ * (invalidation layer 2). Scheduled on the injectable {@link WorkflowTimers} seam, so tests can drive it without waiting.
726
736
  */
727
- export declare const WORKFLOW_RESUME_CLAIM_FINALIZE_TIMEOUT_MS = 10000;
737
+ export declare const WORKFLOW_STORE_WAIT_BOUND_MS = 10000;
728
738
  /**
729
739
  * The default for {@link RunWorkflowOptions.journalAppendTimeoutMs}: how long a call waits for the journal store
730
740
  * to answer ONE append before it is refused with {@link WorkflowJournalAppendTimeoutError}.
@@ -733,9 +743,9 @@ export declare const WORKFLOW_RESUME_CLAIM_FINALIZE_TIMEOUT_MS = 10000;
733
743
  * healthy write by a wide margin: one row of at most `MAX_JOURNAL_RESULT_BYTES` to a remote, loaded database
734
744
  * is seconds, never tens of seconds — a bound near that would misread a busy store as a dead one. It also has
735
745
  * to be well inside the Workflow tool's 10-minute deadline, or the bound would add nothing there: a dead store
736
- * is named after 30 s instead of silently eating the run's whole deadline. The two terminal-boundary waits
737
- * (5 s drain, 10 s claim release) are shorter on purpose — they run after the outcome is fixed and lose
738
- * nothing by giving up; this one decides whether the script may continue.
746
+ * is named after 30 s instead of silently eating the run's whole deadline. The terminal-boundary waits
747
+ * (5 s drain, 10 s each for the record write and the claim release) are shorter on purpose — they run after the
748
+ * outcome is fixed and give up into a stated answer; this one decides whether the script may continue.
739
749
  */
740
750
  export declare const WORKFLOW_JOURNAL_APPEND_TIMEOUT_MS = 30000;
741
751
  /** F5/B4 + design/87 §4.3 — the INJECTABLE timer seam the per-agent resilience layer schedules on (the
@@ -4,6 +4,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { createHash, randomUUID } from "node:crypto";
5
5
  import { availableParallelism } from "node:os";
6
6
  import { mintCompletionId } from "../core/completion-id.js";
7
+ import { deliverEngineNotice } from "../core/engine-notice.js";
7
8
  import { applyParentSpecSeat } from "../core/parent-spec-seat.js";
8
9
  import { TERMINAL_CAUSE_IS_REPLAYABLE, isTerminalCauseKind } from "../core/terminal-cause.js";
9
10
  import { terminalProjection } from "../core/runner/terminal-projection.js";
@@ -32,6 +33,8 @@ import { WorkflowScriptError } from "./workflow-meta.js";
32
33
  import { firstByteLaneKnobMs, STALL_FIRST_BYTE_MS, STALL_FIRST_TOKEN_MS } from "../brain/timeout.js";
33
34
  import { asThrownError, isErrorLike, readMember, thrownIs, thrownName, thrownText } from "../core/thrown-value.js";
34
35
  import { bindSettledRun } from "../core/workflow-settled-run.js";
36
+ import { persistTaskArtifact } from "../core/tool-result-store.js";
37
+ import { formatWorkflowRun, WORKFLOW_RECORD_WHOLE } from "../core/task-registry-shared.js";
35
38
  export * from "./workflow-types.js";
36
39
  const MAX_TRANSCRIPT_CHARS = 4000;
37
40
  const WORKFLOW_RESULT_MAX = 4000;
@@ -383,7 +386,7 @@ function readLegApprovalWaitedMs(result, announce) {
383
386
  }
384
387
  return raw;
385
388
  }
386
- export const WORKFLOW_RESUME_CLAIM_FINALIZE_TIMEOUT_MS = 10_000;
389
+ export const WORKFLOW_STORE_WAIT_BOUND_MS = 10_000;
387
390
  export const WORKFLOW_JOURNAL_APPEND_TIMEOUT_MS = 30_000;
388
391
  const REAL_WORKFLOW_TIMERS = {
389
392
  setTimeout(fn, ms) {
@@ -395,13 +398,15 @@ const REAL_WORKFLOW_TIMERS = {
395
398
  clearTimeout(handle);
396
399
  },
397
400
  };
398
- async function finalizeWithin(timers, p, fallback) {
401
+ async function finalizeWithin(timers, p, fallback, holdsProcess = false) {
399
402
  let handle;
400
403
  try {
401
404
  return await Promise.race([
402
405
  p,
403
406
  new Promise((resolve) => {
404
- handle = timers.setTimeout(() => resolve(fallback), WORKFLOW_RESUME_CLAIM_FINALIZE_TIMEOUT_MS);
407
+ handle = timers.setTimeout(() => resolve(fallback), WORKFLOW_STORE_WAIT_BOUND_MS);
408
+ if (holdsProcess && typeof handle === "object" && handle !== null && "ref" in handle && typeof handle.ref === "function")
409
+ handle.ref();
405
410
  }),
406
411
  ]);
407
412
  }
@@ -565,6 +570,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
565
570
  const throttleBackoffMs = normalizeWorkflowTimerCap("throttleBackoffMs", opts.throttleBackoffMs) ?? WORKFLOW_AGENT_THROTTLE_BACKOFF_MS;
566
571
  const journalAppendTimeoutMs = normalizeWorkflowJournalAppendTimeoutMs(opts.journalAppendTimeoutMs);
567
572
  const timers = opts.timers ?? REAL_WORKFLOW_TIMERS;
573
+ const taskArtifacts = opts.taskArtifacts;
568
574
  const cancelController = new AbortController();
569
575
  const timeoutController = totalTimeoutMs !== undefined ? new AbortController() : undefined;
570
576
  const signalSources = [cancelController.signal];
@@ -728,6 +734,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
728
734
  const definitionSeats = (launch) => (launch.definitionToolLists !== undefined ? { definitionToolLists: launch.definitionToolLists, toolCeiling: agentCeiling ?? [] } : {});
729
735
  const spawnAttribution = {
730
736
  isDelegatedChild: true,
737
+ ...(parkLaneArmed(opts) ? { parkLaneHeld: true } : {}),
731
738
  objectiveAuthor: "workflow",
732
739
  ...(opts.questionFaceStripped === true ? { questionFaceStripped: true } : {}),
733
740
  ...(opts.interactionPosture !== undefined ? { parentInteractionPosture: opts.interactionPosture } : {}),
@@ -738,6 +745,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
738
745
  ...(opts.onForwardEvent ? { onForwardEvent: opts.onForwardEvent } : {}),
739
746
  ...(opts.inheritedGate !== undefined ? { inheritedGate: opts.inheritedGate } : {}),
740
747
  ...(agentCeiling !== undefined ? { toolCeiling: agentCeiling } : {}),
748
+ ...(internals?.mcpPool !== undefined ? { mcpPool: internals.mcpPool } : {}),
741
749
  ...((opts.rootSessionId ?? opts.originatingSessionId) !== undefined ? { rootSessionId: opts.rootSessionId ?? opts.originatingSessionId } : {}),
742
750
  ...(opts.rootSessionId !== undefined && opts.rootSessionIncarnation !== undefined ? { rootSessionIncarnation: opts.rootSessionIncarnation } : {}),
743
751
  ...(opts.rootSessionId !== undefined && opts.rootSessionScope !== undefined ? { rootSessionScope: opts.rootSessionScope } : {}),
@@ -1033,7 +1041,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1033
1041
  throw parkBindingBroken(ordinal, "the record names no token or no session for it");
1034
1042
  const read = await finalizeWithin(timers, new Promise((resolve) => resolve(seat.get(key.token))).then((cp) => ({ cp }), (err) => ({ err })), "timeout");
1035
1043
  if (read === "timeout" || "err" in read) {
1036
- throw new WorkflowParkRefusal("workflow.park_truth_unreadable", `workflow resume: ordinal ${ordinal} is recorded as PARKED and its checkpoint could not be read from the checkpoint store (${read === "timeout" ? `the read did not settle within ${WORKFLOW_RESUME_CLAIM_FINALIZE_TIMEOUT_MS}ms` : withoutToken(errText(read.err), key.token)}); the resume is refused rather than run beside a pinned child.`, { reason: "checkpoint_store_threw" });
1044
+ throw new WorkflowParkRefusal("workflow.park_truth_unreadable", `workflow resume: ordinal ${ordinal} is recorded as PARKED and its checkpoint could not be read from the checkpoint store (${read === "timeout" ? `the read did not settle within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms` : withoutToken(errText(read.err), key.token)}); the resume is refused rather than run beside a pinned child.`, { reason: "checkpoint_store_threw" });
1037
1045
  }
1038
1046
  const cp = read.cp;
1039
1047
  if (cp === null)
@@ -1055,7 +1063,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1055
1063
  .then((rows) => ({ entries: judgedJournal(key.originRunId, rows) }))
1056
1064
  .catch((err) => ({ err })), "timeout");
1057
1065
  if (loaded === "timeout" || "err" in loaded) {
1058
- emitRunLog(`resume: the journal of run "${clampRunIdText(key.originRunId)}" (the origin of the park at ordinal ${ordinal}) could not be read (${loaded === "timeout" ? `the load did not settle within ${WORKFLOW_RESUME_CLAIM_FINALIZE_TIMEOUT_MS}ms` : withoutToken(errText(loaded.err), key.token)}).`);
1066
+ emitRunLog(`resume: the journal of run "${clampRunIdText(key.originRunId)}" (the origin of the park at ordinal ${ordinal}) could not be read (${loaded === "timeout" ? `the load did not settle within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms` : withoutToken(errText(loaded.err), key.token)}).`);
1059
1067
  }
1060
1068
  else {
1061
1069
  entry = loaded.entries.filter((e) => e.parked !== undefined && callKeyOrdinal(e.callKey) === ordinal).at(-1);
@@ -1110,10 +1118,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1110
1118
  return { kind: "repark", paused };
1111
1119
  };
1112
1120
  const deliverParkDecisions = async (decisions) => {
1113
- if (parkedLeg !== undefined)
1114
- return { kind: "suspending", ended: done.then(() => undefined, () => undefined) };
1115
- if (finalized)
1116
- return { kind: "not_active" };
1121
+ const ending = () => ({ kind: "suspending", ended: done.then(() => undefined, () => undefined) });
1122
+ if (parkedLeg !== undefined || finalized)
1123
+ return ending();
1117
1124
  const seat = parkSeat;
1118
1125
  if (seat === undefined)
1119
1126
  return { kind: "not_armed" };
@@ -1161,7 +1168,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1161
1168
  results[at] = "driving";
1162
1169
  }
1163
1170
  }
1164
- return { kind: "live", results };
1171
+ return parkedLeg !== undefined || finalized ? ending() : { kind: "live", results };
1165
1172
  };
1166
1173
  const assertChildParkSeat = (s) => {
1167
1174
  const seat = s.checkpointStore;
@@ -1238,9 +1245,12 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1238
1245
  };
1239
1246
  const journalAppend = async (callKey, result, label) => {
1240
1247
  const dbg = typeof process !== "undefined" && process.env?.SEMA_DEBUG_WORKFLOW_JOURNAL === "1";
1241
- if (!journalStore) {
1248
+ const trace = (step) => {
1242
1249
  if (dbg)
1243
- console.error(`[sema:wf-journal] runId=${runId} callKey=${callKey} SKIP (no journalStore on this run)`);
1250
+ deliverEngineNotice(undefined, { code: "engine.debug_trace", message: `[sema:wf-journal] runId=${runId} callKey=${callKey} ${step}`, detail: { topic: "workflow_journal", runId, callKey } });
1251
+ };
1252
+ if (!journalStore) {
1253
+ trace("SKIP (no journalStore on this run)");
1244
1254
  return;
1245
1255
  }
1246
1256
  const stored = journalDurableResult(result);
@@ -1260,24 +1270,20 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1260
1270
  const tombstone = trackJournalWrite(() => journalStore.append(runId, scope, { callKey, result: journalOversizeTombstone(stored, bytes) }), callKey);
1261
1271
  try {
1262
1272
  await tombstone;
1263
- if (dbg)
1264
- console.error(`[sema:wf-journal] runId=${runId} callKey=${callKey} OVERSIZE-TOMBSTONE (${bytes} bytes)`);
1273
+ trace(`OVERSIZE-TOMBSTONE (${bytes} bytes)`);
1265
1274
  }
1266
1275
  catch (err) {
1267
- if (dbg)
1268
- console.error(`[sema:wf-journal] runId=${runId} callKey=${callKey} TOMBSTONE-ERROR ${thrownText(err)}`);
1276
+ trace(`TOMBSTONE-ERROR ${thrownText(err)}`);
1269
1277
  }
1270
1278
  return;
1271
1279
  }
1272
1280
  const p = trackJournalWrite(() => journalStore.append(runId, scope, { callKey, result: stored }), callKey);
1273
1281
  try {
1274
1282
  await p;
1275
- if (dbg)
1276
- console.error(`[sema:wf-journal] runId=${runId} callKey=${callKey} APPENDED (scope=${scope})`);
1283
+ trace(`APPENDED (scope=${scope})`);
1277
1284
  }
1278
1285
  catch (err) {
1279
- if (dbg)
1280
- console.error(`[sema:wf-journal] runId=${runId} callKey=${callKey} APPEND-ERROR ${thrownText(err)}`);
1286
+ trace(`APPEND-ERROR ${thrownText(err)}`);
1281
1287
  throw err;
1282
1288
  }
1283
1289
  };
@@ -1333,8 +1339,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1333
1339
  emitRunLog(`resume-journal: the PARKED leg at ordinal ${ordinal} ("${rec.label.slice(0, 80)}") could not be recorded in this run's journal (${withoutToken(errText(err), key.token)}) — ` +
1334
1340
  "the park stands: a resume of this run finds it through the run record and the checkpoint store.");
1335
1341
  }
1336
- const persisted = await finalizeWithin(timers, persist("update"), { ok: false, cause: "timeout" });
1337
- if (!persisted.ok) {
1342
+ const persisted = finalized ? undefined : await finalizeWithin(timers, persist("update"), { ok: false, cause: "timeout" });
1343
+ if (persisted !== undefined && !persisted.ok) {
1338
1344
  emitRunLog(`resume-journal: the PARKED leg at ordinal ${ordinal} ("${rec.label.slice(0, 80)}") could not be persisted on the run record (${persisted.cause}) — ` +
1339
1345
  "the park stands: a resume of this run finds it through the journal and the checkpoint store.");
1340
1346
  }
@@ -1368,6 +1374,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1368
1374
  return rec;
1369
1375
  };
1370
1376
  const settleParkedCall = async (rec, result, activityTail, agentOpts) => {
1377
+ if (finalized)
1378
+ return result;
1371
1379
  await settleAgentResult(rec, result, activityTail, agentOpts);
1372
1380
  return result;
1373
1381
  };
@@ -1478,6 +1486,25 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
1478
1486
  };
1479
1487
  return { spec: { preemptSignal: leg.signal }, internals: { reportSuspendLane: report } };
1480
1488
  };
1489
+ const settleRecordArtifact = async () => {
1490
+ if (run.recordArtifact !== undefined)
1491
+ return;
1492
+ if (taskArtifacts === undefined) {
1493
+ run.recordArtifact = { kind: "no_store" };
1494
+ return;
1495
+ }
1496
+ let written;
1497
+ try {
1498
+ written = await finalizeWithin(timers, new Promise((resolve) => resolve(persistTaskArtifact(taskArtifacts, runId, formatWorkflowRun(run, WORKFLOW_RECORD_WHOLE).content))), "timeout", true);
1499
+ if (written === "timeout") {
1500
+ emitLogLine(`record: the run's full record was not confirmed written within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms — the record reads "unconfirmed" and names no ref for it.`);
1501
+ }
1502
+ }
1503
+ catch {
1504
+ written = { kind: "unconfirmed" };
1505
+ }
1506
+ run.recordArtifact = written === "timeout" ? { kind: "unconfirmed" } : written.kind === "stored" ? { kind: "stored", ref: written.ref } : { kind: written.kind };
1507
+ };
1481
1508
  const setLegRunId = (rec, from) => {
1482
1509
  if (from.runId !== undefined && from.runId !== "")
1483
1510
  rec.taskRunId = from.runId;
@@ -2118,7 +2145,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
2118
2145
  }
2119
2146
  break;
2120
2147
  }
2121
- if (attempts > 1) {
2148
+ if (attempts > 1 && !finalized) {
2122
2149
  rec.attempts = attempts;
2123
2150
  if (lastAttemptReason !== undefined)
2124
2151
  rec.lastAttemptReason = lastAttemptReason;
@@ -2808,6 +2835,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
2808
2835
  const completedRunFailures = countAgentFailures();
2809
2836
  if (completedRunFailures > 0)
2810
2837
  run.agentFailures = completedRunFailures;
2838
+ await settleRecordArtifact();
2811
2839
  emit({ type: "run_end", runId, status: "completed", ...(completedRunFailures > 0 ? { agentFailures: completedRunFailures } : {}), ts: run.endedAt });
2812
2840
  await persist("update");
2813
2841
  return { result, runId, run };
@@ -2841,6 +2869,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
2841
2869
  const failedRunFailures = countAgentFailures();
2842
2870
  if (failedRunFailures > 0)
2843
2871
  run.agentFailures = failedRunFailures;
2872
+ await settleRecordArtifact();
2844
2873
  emit({ type: "run_end", runId, status: "failed", ...(failedRunFailures > 0 ? { agentFailures: failedRunFailures } : {}), ts: run.endedAt });
2845
2874
  await persist("update");
2846
2875
  if (err !== null && (typeof err === "object" || typeof err === "function")) {
@@ -1,4 +1,4 @@
1
- import { createHash } from "node:crypto";
1
+ import { isTextContentHash, textContentHashOf } from "../core/canonical-json.js";
2
2
  import { isBandId } from "./bands.js";
3
3
  import { SEMA_DEFAULT_CATALOG } from "./catalog/index.js";
4
4
  import { OVERLAY_OPS, PROMPT_TRAIT_BUNDLES, PROMPT_TRAITS, isPromptTraitName, isWordOf } from "./catalog/schema.js";
@@ -13,14 +13,10 @@ export const ARTIFACT_LIMITS = Object.freeze({
13
13
  maxRefChars: 500,
14
14
  maxSourceRevisionChars: 500,
15
15
  });
16
- const DIGEST_RE = /^sha256:[0-9a-f]{64}$/;
17
16
  const MESSAGE_IDS = new Set(SEMA_DEFAULT_CATALOG.messages.map((m) => m.id));
18
17
  const SECTION_IDS = new Set(SEMA_DEFAULT_CATALOG.sections.map((s) => s.id));
19
- function sha256Hex(text) {
20
- return `sha256:${createHash("sha256").update(text, "utf8").digest("hex")}`;
21
- }
22
18
  export function computeArtifactDigest(payload) {
23
- return sha256Hex(canonical(payload));
19
+ return textContentHashOf(canonical(payload));
24
20
  }
25
21
  export function requiresOf(overlays) {
26
22
  const targets = new Map();
@@ -133,7 +129,7 @@ export function verifyPromptArtifactBody(raw) {
133
129
  for (const k of Object.keys(raw))
134
130
  if (k !== "payload" && k !== "artifactDigest" && k !== "sourceRevision")
135
131
  return fail("shape", `the artifact carries ${JSON.stringify(k).slice(0, 60)}`);
136
- if (typeof raw.artifactDigest !== "string" || !DIGEST_RE.test(raw.artifactDigest))
132
+ if (!isTextContentHash(raw.artifactDigest))
137
133
  return fail("shape", "artifactDigest malformed");
138
134
  const payload = raw.payload;
139
135
  if (!isRecord(payload))
@@ -219,5 +215,5 @@ export function buildPromptArtifact(opts) {
219
215
  return "overlay" in v ? v.overlay : o;
220
216
  });
221
217
  const payload = JSON.parse(JSON.stringify({ schemaVersion: 3, requires: requiresOf(overlays), overlays, evidence: opts.evidence }));
222
- return verifyPromptArtifact({ payload, artifactDigest: sha256Hex(canonical(payload)), sourceRevision: opts.sourceRevision });
218
+ return verifyPromptArtifact({ payload, artifactDigest: textContentHashOf(canonical(payload)), sourceRevision: opts.sourceRevision });
223
219
  }