@sema-agent/core 7.67.3 → 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 (496) hide show
  1. package/CHANGELOG.md +1516 -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/open-responses.js +3 -1
  30. package/dist/brain/openai.js +3 -1
  31. package/dist/brain/reasoning-request.d.ts +73 -19
  32. package/dist/brain/reasoning-request.js +164 -72
  33. package/dist/brain/reasoning-stamp.d.ts +26 -0
  34. package/dist/brain/reasoning-stamp.js +10 -0
  35. package/dist/brain/reasoning.d.ts +95 -162
  36. package/dist/brain/reasoning.js +31 -86
  37. package/dist/brain/route-adjudicator.d.ts +9 -7
  38. package/dist/brain/route-adjudicator.js +12 -10
  39. package/dist/brain/status-sink.d.ts +19 -64
  40. package/dist/brain/status-sink.js +5 -21
  41. package/dist/brain/stream-engine.d.ts +11 -2
  42. package/dist/brain/stream-engine.js +10 -0
  43. package/dist/core/a2a.d.ts +17 -5
  44. package/dist/core/a2a.js +11 -3
  45. package/dist/core/allow-entry.d.ts +35 -15
  46. package/dist/core/allow-entry.js +47 -60
  47. package/dist/core/ask-headline.d.ts +68 -0
  48. package/dist/core/ask-headline.js +23 -0
  49. package/dist/core/ask-origin.d.ts +36 -8
  50. package/dist/core/ask-origin.js +17 -10
  51. package/dist/core/ask-question.d.ts +34 -7
  52. package/dist/core/ask-question.js +10 -1
  53. package/dist/core/ask-unresolvable-notice.d.ts +7 -0
  54. package/dist/core/ask-unresolvable-notice.js +9 -3
  55. package/dist/core/auto-strip.d.ts +53 -0
  56. package/dist/core/auto-strip.js +76 -0
  57. package/dist/core/background-agent-store.d.ts +45 -5
  58. package/dist/core/background-agent-store.js +69 -15
  59. package/dist/core/background-shell.d.ts +2 -2
  60. package/dist/core/caller-text.js +2 -2
  61. package/dist/core/canonical-json.d.ts +13 -0
  62. package/dist/core/canonical-json.js +7 -0
  63. package/dist/core/checkpoint-features.d.ts +66 -20
  64. package/dist/core/checkpoint-features.js +12 -1
  65. package/dist/core/checkpoint-generation.d.ts +1 -1
  66. package/dist/core/checkpoint-queries.d.ts +1 -1
  67. package/dist/core/checkpoint-queries.js +4 -1
  68. package/dist/core/checkpoint-requirements.d.ts +25 -1
  69. package/dist/core/checkpoint-requirements.js +5 -1
  70. package/dist/core/checkpoint-row-verdict.d.ts +1 -0
  71. package/dist/core/checkpoint-row-verdict.js +4 -0
  72. package/dist/core/checkpoint-store.d.ts +66 -38
  73. package/dist/core/checkpoint-store.js +15 -6
  74. package/dist/core/child-clamp-seats.d.ts +6 -0
  75. package/dist/core/child-clamp-seats.js +1 -0
  76. package/dist/core/config-refusal-codes.d.ts +1 -1
  77. package/dist/core/config-refusal-codes.js +1 -0
  78. package/dist/core/delegation-frames.d.ts +9 -12
  79. package/dist/core/delegation-frames.js +9 -8
  80. package/dist/core/engine-capabilities.d.ts +21 -8
  81. package/dist/core/engine-capabilities.js +1 -1
  82. package/dist/core/engine-notice.d.ts +147 -34
  83. package/dist/core/engine-notice.js +27 -16
  84. package/dist/core/engine-storage-backend.d.ts +2 -1
  85. package/dist/core/env-budget.js +3 -3
  86. package/dist/core/env-knob-announce.d.ts +10 -10
  87. package/dist/core/env-knob-announce.js +3 -6
  88. package/dist/core/file-history-store.d.ts +29 -4
  89. package/dist/core/file-history-store.js +13 -0
  90. package/dist/core/frame-settlement.d.ts +2 -1
  91. package/dist/core/gate-fold.js +1 -1
  92. package/dist/core/gate-lanes.js +56 -49
  93. package/dist/core/governance-codes.d.ts +39 -3
  94. package/dist/core/governance-codes.js +61 -3
  95. package/dist/core/hooks.d.ts +29 -11
  96. package/dist/core/hooks.js +5 -2
  97. package/dist/core/human-input-projection.js +3 -3
  98. package/dist/core/input-author.d.ts +17 -3
  99. package/dist/core/input-author.js +15 -3
  100. package/dist/core/leg-identity.d.ts +10 -28
  101. package/dist/core/leg-identity.js +1 -21
  102. package/dist/core/lsp.d.ts +18 -13
  103. package/dist/core/lsp.js +30 -22
  104. package/dist/core/mailbox-store.d.ts +1 -1
  105. package/dist/core/mailbox-store.js +4 -4
  106. package/dist/core/mcp-connection-pool.d.ts +93 -4
  107. package/dist/core/mcp-connection-pool.js +104 -1
  108. package/dist/core/mcp-failure.d.ts +38 -12
  109. package/dist/core/mcp-failure.js +9 -13
  110. package/dist/core/mcp-probe.d.ts +4 -3
  111. package/dist/core/mcp-server-link.d.ts +4 -2
  112. package/dist/core/mcp-server-link.js +4 -5
  113. package/dist/core/mcp-server-spec.d.ts +3 -3
  114. package/dist/core/mcp-server-unavailable-notice.d.ts +22 -8
  115. package/dist/core/mcp-server-unavailable-notice.js +18 -4
  116. package/dist/core/mcp.d.ts +40 -6
  117. package/dist/core/mcp.js +39 -13
  118. package/dist/core/memory-engine/content-origin.js +2 -2
  119. package/dist/core/memory-engine/control-objects.d.ts +2 -4
  120. package/dist/core/memory-engine/control-objects.js +2 -10
  121. package/dist/core/memory-engine/delegation-settlement.js +6 -1
  122. package/dist/core/memory-engine/dual-root.js +3 -0
  123. package/dist/core/memory-engine/engine.d.ts +6 -4
  124. package/dist/core/memory-engine/engine.js +32 -29
  125. package/dist/core/memory-engine/file-backend.d.ts +20 -5
  126. package/dist/core/memory-engine/file-backend.js +21 -31
  127. package/dist/core/memory-engine/frontmatter.d.ts +2 -0
  128. package/dist/core/memory-engine/frontmatter.js +4 -0
  129. package/dist/core/memory-engine/layout.d.ts +114 -20
  130. package/dist/core/memory-engine/layout.js +340 -22
  131. package/dist/core/memory-engine/memory-deployment.d.ts +7 -5
  132. package/dist/core/memory-engine/mount-failed-notice.d.ts +19 -7
  133. package/dist/core/memory-engine/mount-failed-notice.js +43 -10
  134. package/dist/core/memory-engine/sync-client.js +4 -5
  135. package/dist/core/model-fallbacks.d.ts +5 -1
  136. package/dist/core/model-fallbacks.js +3 -3
  137. package/dist/core/model-receipt.d.ts +2 -1
  138. package/dist/core/model-receipt.js +12 -1
  139. package/dist/core/mods/kernel/dispatch.d.ts +2 -2
  140. package/dist/core/mods/kernel/dispatch.js +14 -6
  141. package/dist/core/mods/kernel/events.d.ts +8 -5
  142. package/dist/core/mods/kernel/events.js +2 -2
  143. package/dist/core/mods/kernel/index.d.ts +1 -1
  144. package/dist/core/mods/kernel/registration.d.ts +9 -0
  145. package/dist/core/mods/package.js +1 -1
  146. package/dist/core/mods/session-append.d.ts +4 -2
  147. package/dist/core/mods/session-append.js +3 -0
  148. package/dist/core/mods/stations.d.ts +7 -11
  149. package/dist/core/mods/stations.js +4 -7
  150. package/dist/core/mods/tool-call.d.ts +10 -8
  151. package/dist/core/mods/tool-call.js +15 -18
  152. package/dist/core/mounted-mcp.d.ts +0 -4
  153. package/dist/core/mounted-mcp.js +1 -1
  154. package/dist/core/park-noun.d.ts +24 -0
  155. package/dist/core/park-noun.js +21 -0
  156. package/dist/core/park-resumability.d.ts +60 -0
  157. package/dist/core/park-resumability.js +30 -0
  158. package/dist/core/permission-rule-provider.d.ts +24 -2
  159. package/dist/core/permission-rule-provider.js +11 -8
  160. package/dist/core/permission-rule-store.d.ts +8 -1
  161. package/dist/core/permission-rule-store.js +2 -3
  162. package/dist/core/permission-rules.d.ts +2 -1
  163. package/dist/core/permission-rules.js +8 -4
  164. package/dist/core/persisted-rule-arms.d.ts +3 -0
  165. package/dist/core/persisted-rule-arms.js +2 -1
  166. package/dist/core/present-plan-tool.d.ts +47 -3
  167. package/dist/core/present-plan-tool.js +62 -4
  168. package/dist/core/principal-name.d.ts +1 -1
  169. package/dist/core/principal-name.js +5 -5
  170. package/dist/core/process-identity.js +10 -5
  171. package/dist/core/protocol-http-auth.d.ts +20 -14
  172. package/dist/core/protocol-http-auth.js +70 -50
  173. package/dist/core/read-only-shell.js +9 -5
  174. package/dist/core/redaction-marks.d.ts +4 -26
  175. package/dist/core/redaction-marks.js +9 -21
  176. package/dist/core/remote-env.d.ts +43 -16
  177. package/dist/core/remote-env.js +1 -1
  178. package/dist/core/request-copy-projection.d.ts +1 -1
  179. package/dist/core/request-copy-projection.js +40 -50
  180. package/dist/core/resume-config-judge.js +1 -1
  181. package/dist/core/resume-startup-cause.d.ts +35 -18
  182. package/dist/core/resume-startup-cause.js +13 -10
  183. package/dist/core/retention.d.ts +167 -25
  184. package/dist/core/retention.js +100 -20
  185. package/dist/core/roles.d.ts +6 -0
  186. package/dist/core/roles.js +11 -5
  187. package/dist/core/rule-lane-reads.d.ts +3 -0
  188. package/dist/core/rule-lane-reads.js +5 -1
  189. package/dist/core/rule-store-fault.d.ts +70 -0
  190. package/dist/core/rule-store-fault.js +102 -0
  191. package/dist/core/runner/advertised-writable-dirs.js +16 -31
  192. package/dist/core/runner/announce-once-ledger.d.ts +19 -2
  193. package/dist/core/runner/announce-once-ledger.js +24 -2
  194. package/dist/core/runner/assemble-result.d.ts +6 -0
  195. package/dist/core/runner/assemble-result.js +1 -1
  196. package/dist/core/runner/auto-strip-notice.d.ts +36 -0
  197. package/dist/core/runner/auto-strip-notice.js +59 -0
  198. package/dist/core/runner/branch-window.d.ts +3 -0
  199. package/dist/core/runner/branch-window.js +37 -0
  200. package/dist/core/runner/caller-roster.d.ts +8 -3
  201. package/dist/core/runner/capability-withheld-seat.js +3 -9
  202. package/dist/core/runner/clock-and-limits.d.ts +22 -1
  203. package/dist/core/runner/clock-and-limits.js +30 -0
  204. package/dist/core/runner/contracts.d.ts +58 -35
  205. package/dist/core/runner/credential-refusal-seat.d.ts +2 -0
  206. package/dist/core/runner/credential-refusal-seat.js +47 -0
  207. package/dist/core/runner/cross-boundary-lane.js +6 -4
  208. package/dist/core/runner/decide-continuation.js +1 -1
  209. package/dist/core/runner/file-history-restore.d.ts +53 -2
  210. package/dist/core/runner/file-history-restore.js +29 -10
  211. package/dist/core/runner/forward-sink.d.ts +14 -1
  212. package/dist/core/runner/forward-sink.js +14 -12
  213. package/dist/core/runner/gate-exit.d.ts +8 -7
  214. package/dist/core/runner/gate-exit.js +13 -13
  215. package/dist/core/runner/git-status-frame.js +2 -4
  216. package/dist/core/runner/initial-run-state.js +1 -1
  217. package/dist/core/runner/main-call-account.d.ts +3 -1
  218. package/dist/core/runner/main-call-account.js +5 -3
  219. package/dist/core/runner/mcp-redial.d.ts +2 -5
  220. package/dist/core/runner/mcp-redial.js +2 -2
  221. package/dist/core/runner/nested-memory-content.d.ts +7 -1
  222. package/dist/core/runner/nested-memory-content.js +73 -13
  223. package/dist/core/runner/nested-memory-lane.d.ts +44 -19
  224. package/dist/core/runner/nested-memory-lane.js +152 -76
  225. package/dist/core/runner/park-commit.js +3 -1
  226. package/dist/core/runner/permission-rule-lanes.d.ts +8 -2
  227. package/dist/core/runner/permission-rule-lanes.js +29 -3
  228. package/dist/core/runner/person-path-rows.d.ts +3 -11
  229. package/dist/core/runner/person-path-rows.js +21 -24
  230. package/dist/core/runner/prepare-acquire-reconcile.js +3 -1
  231. package/dist/core/runner/prepare-artifact.d.ts +1 -1
  232. package/dist/core/runner/prepare-artifact.js +20 -14
  233. package/dist/core/runner/prepare-ask-lane.d.ts +9 -6
  234. package/dist/core/runner/prepare-ask-lane.js +6 -5
  235. package/dist/core/runner/prepare-boundary-parks.d.ts +7 -1
  236. package/dist/core/runner/prepare-boundary-parks.js +27 -24
  237. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -2
  238. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  239. package/dist/core/runner/prepare-config-doors.d.ts +9 -24
  240. package/dist/core/runner/prepare-config-doors.js +58 -41
  241. package/dist/core/runner/prepare-context-lane.d.ts +2 -2
  242. package/dist/core/runner/prepare-context-lane.js +3 -5
  243. package/dist/core/runner/prepare-defer-classify.d.ts +1 -1
  244. package/dist/core/runner/prepare-defer-classify.js +1 -1
  245. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
  246. package/dist/core/runner/prepare-delegation-surface.js +3 -2
  247. package/dist/core/runner/prepare-file-history.d.ts +62 -26
  248. package/dist/core/runner/prepare-file-history.js +117 -46
  249. package/dist/core/runner/prepare-gate-stations.d.ts +4 -0
  250. package/dist/core/runner/prepare-gate-stations.js +6 -5
  251. package/dist/core/runner/prepare-hands-readface.d.ts +9 -4
  252. package/dist/core/runner/prepare-hands-readface.js +8 -4
  253. package/dist/core/runner/prepare-inherited-gate.d.ts +11 -4
  254. package/dist/core/runner/prepare-inherited-gate.js +6 -6
  255. package/dist/core/runner/prepare-listings.d.ts +1 -1
  256. package/dist/core/runner/prepare-listings.js +1 -1
  257. package/dist/core/runner/prepare-memory.js +2 -2
  258. package/dist/core/runner/prepare-offload-wrappers.d.ts +1 -1
  259. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  260. package/dist/core/runner/prepare-park-ask.d.ts +10 -3
  261. package/dist/core/runner/prepare-park-ask.js +7 -9
  262. package/dist/core/runner/prepare-policy-chain.d.ts +18 -9
  263. package/dist/core/runner/prepare-policy-chain.js +18 -13
  264. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  265. package/dist/core/runner/prepare-project-context.js +5 -3
  266. package/dist/core/runner/prepare-prompt-assembly.js +2 -1
  267. package/dist/core/runner/prepare-prompt-inputs.d.ts +2 -2
  268. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  269. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -5
  270. package/dist/core/runner/prepare-protocol-tools.js +7 -7
  271. package/dist/core/runner/prepare-question-face.d.ts +4 -2
  272. package/dist/core/runner/prepare-run-refs.d.ts +7 -2
  273. package/dist/core/runner/prepare-run-refs.js +8 -7
  274. package/dist/core/runner/prepare-safety-scan.d.ts +4 -3
  275. package/dist/core/runner/prepare-suspend-saga.d.ts +3 -7
  276. package/dist/core/runner/prepare-suspend-saga.js +4 -3
  277. package/dist/core/runner/prepare-task.js +66 -53
  278. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +3 -2
  279. package/dist/core/runner/prepare-tool-disclosure-mount.js +2 -1
  280. package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
  281. package/dist/core/runner/prepare-turn-wiring.js +1 -1
  282. package/dist/core/runner/prepare-wiring-manifest.d.ts +9 -4
  283. package/dist/core/runner/prepare-wiring-manifest.js +14 -6
  284. package/dist/core/runner/prepare-workspace-restore.d.ts +4 -4
  285. package/dist/core/runner/prepare-workspace-restore.js +15 -6
  286. package/dist/core/runner/remote-env-retry.d.ts +3 -3
  287. package/dist/core/runner/restore-seat.d.ts +41 -0
  288. package/dist/core/runner/restore-seat.js +38 -0
  289. package/dist/core/runner/resume-admission.js +1 -1
  290. package/dist/core/runner/resume-apply.js +4 -3
  291. package/dist/core/runner/resume-checkpoint-screen.js +2 -1
  292. package/dist/core/runner/resume-internals-and-config.js +2 -1
  293. package/dist/core/runner/resume-preflight.js +2 -1
  294. package/dist/core/runner/rewind-files.js +22 -6
  295. package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -0
  296. package/dist/core/runner/rule-store-unreadable-notice.js +11 -0
  297. package/dist/core/runner/run-brain-sinks.d.ts +3 -6
  298. package/dist/core/runner/run-brain-sinks.js +6 -6
  299. package/dist/core/runner/run-compaction-machinery.d.ts +2 -2
  300. package/dist/core/runner/run-git-lane.d.ts +2 -0
  301. package/dist/core/runner/run-git-lane.js +2 -1
  302. package/dist/core/runner/run-harness-handlers.js +5 -4
  303. package/dist/core/runner/run-identity-wiring.js +20 -12
  304. package/dist/core/runner/run-leg.js +31 -72
  305. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  306. package/dist/core/runner/run-notification-lane.js +2 -4
  307. package/dist/core/runner/run-reasoning-seat.d.ts +5 -6
  308. package/dist/core/runner/run-reasoning-seat.js +13 -18
  309. package/dist/core/runner/run-settle-and-teardown.js +13 -9
  310. package/dist/core/runner/run-terminal-adoption.js +4 -8
  311. package/dist/core/runner/run-turn-boundary.js +6 -3
  312. package/dist/core/runner/runtask.d.ts +9 -4
  313. package/dist/core/runner/runtask.js +29 -22
  314. package/dist/core/runner/session-rule-policy.d.ts +11 -1
  315. package/dist/core/runner/shell-env-withheld.js +2 -7
  316. package/dist/core/runner/side-call-account.d.ts +5 -6
  317. package/dist/core/runner/side-call-account.js +2 -2
  318. package/dist/core/runner/stream-lifecycle-verbs.d.ts +3 -0
  319. package/dist/core/runner/stream-lifecycle-verbs.js +5 -3
  320. package/dist/core/runner/stream-settle-backstop.js +4 -6
  321. package/dist/core/runner/stream-steer-verb.d.ts +1 -1
  322. package/dist/core/runner/stream-steer-verb.js +4 -4
  323. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -3
  324. package/dist/core/runner/sub-agent-deny-lists.js +7 -4
  325. package/dist/core/runner/teardown-bounded.d.ts +7 -0
  326. package/dist/core/runner/teardown-bounded.js +7 -0
  327. package/dist/core/runner/terminal-account.js +41 -13
  328. package/dist/core/runner/terminal-projection.d.ts +1 -5
  329. package/dist/core/runner/tool-end-body.d.ts +9 -3
  330. package/dist/core/runner/tool-end-body.js +6 -3
  331. package/dist/core/runner/tool-output-projection.d.ts +13 -4
  332. package/dist/core/runner/tool-output-projection.js +10 -14
  333. package/dist/core/runner/turn-attachments.d.ts +3 -2
  334. package/dist/core/runner/turn-attachments.js +12 -5
  335. package/dist/core/runner-deps.d.ts +6 -6
  336. package/dist/core/runtime-caps.d.ts +2 -1
  337. package/dist/core/secret-env.d.ts +20 -3
  338. package/dist/core/secret-env.js +13 -15
  339. package/dist/core/session-checkout.d.ts +115 -15
  340. package/dist/core/session-checkout.js +435 -136
  341. package/dist/core/session-policy-store.js +21 -3
  342. package/dist/core/session-reconcile.js +1 -0
  343. package/dist/core/session-store.js +2 -0
  344. package/dist/core/session.d.ts +11 -1
  345. package/dist/core/shell-run-candidates.d.ts +1 -0
  346. package/dist/core/shell-run-candidates.js +1 -1
  347. package/dist/core/shutdown-debug.d.ts +6 -5
  348. package/dist/core/shutdown-debug.js +5 -1
  349. package/dist/core/skill-grant.js +4 -1
  350. package/dist/core/skills-directory.js +5 -3
  351. package/dist/core/spec-contract.d.ts +1 -1
  352. package/dist/core/store-contracts/checkpoint-store-contract.js +2 -7
  353. package/dist/core/store-contracts/file-history-store-contract.js +26 -2
  354. package/dist/core/store-contracts/session-deletion-cascade-contract.js +130 -14
  355. package/dist/core/store-contracts/task-list-store-contract.d.ts +2 -1
  356. package/dist/core/store-contracts/task-list-store-contract.js +28 -1
  357. package/dist/core/task-event.d.ts +48 -27
  358. package/dist/core/task-notification.d.ts +15 -9
  359. package/dist/core/task-notification.js +12 -0
  360. package/dist/core/task-registry-agent.d.ts +24 -22
  361. package/dist/core/task-registry-agent.js +65 -46
  362. package/dist/core/task-registry-shared.d.ts +17 -5
  363. package/dist/core/task-registry.d.ts +17 -6
  364. package/dist/core/task-registry.js +6 -1
  365. package/dist/core/task-result.d.ts +71 -25
  366. package/dist/core/task-spec-members.d.ts +0 -1
  367. package/dist/core/task-spec-members.js +1 -1
  368. package/dist/core/task-spec.d.ts +60 -52
  369. package/dist/core/task-stream.d.ts +45 -12
  370. package/dist/core/terminal-cause.d.ts +45 -8
  371. package/dist/core/terminal-cause.js +5 -0
  372. package/dist/core/tool-card-bound.d.ts +32 -0
  373. package/dist/core/tool-card-bound.js +33 -0
  374. package/dist/core/tool-catalog-entries.d.ts +9 -0
  375. package/dist/core/tool-catalog-entries.js +48 -0
  376. package/dist/core/tool-errors.d.ts +4 -3
  377. package/dist/core/tool-face.d.ts +3 -3
  378. package/dist/core/tool-mount-facts.d.ts +3 -2
  379. package/dist/core/tool-mount-facts.js +1 -1
  380. package/dist/core/tool-mount-static.js +7 -5
  381. package/dist/core/tool-policy.d.ts +21 -19
  382. package/dist/core/tool-policy.js +5 -6
  383. package/dist/core/tool-registry.d.ts +3 -1
  384. package/dist/core/tool-registry.js +15 -1
  385. package/dist/core/tool-result-store.d.ts +9 -3
  386. package/dist/core/tool-result-store.js +14 -1
  387. package/dist/core/tool-roster.d.ts +6 -0
  388. package/dist/core/tool-roster.js +18 -0
  389. package/dist/core/tool-spec.d.ts +17 -8
  390. package/dist/core/trace.d.ts +35 -31
  391. package/dist/core/types.d.ts +2 -2
  392. package/dist/core/untrusted-egress.d.ts +10 -9
  393. package/dist/core/untrusted-egress.js +9 -9
  394. package/dist/core/untrusted-text.d.ts +0 -18
  395. package/dist/core/untrusted-text.js +7 -3
  396. package/dist/core/user-attachment.d.ts +9 -6
  397. package/dist/core/user-attachment.js +12 -10
  398. package/dist/core/user-row-origin.d.ts +44 -25
  399. package/dist/core/user-row-origin.js +30 -20
  400. package/dist/core/wiring-manifest.d.ts +26 -7
  401. package/dist/core/wiring-manifest.js +14 -11
  402. package/dist/core/workspace-snapshot.d.ts +3 -1
  403. package/dist/core/workspace-snapshot.js +1 -0
  404. package/dist/engine/execution-env/node-execution-env.d.ts +23 -16
  405. package/dist/engine/execution-env/node-execution-env.js +127 -67
  406. package/dist/engine/harness/agent-harness.d.ts +4 -5
  407. package/dist/engine/harness/agent-harness.js +2 -7
  408. package/dist/engine/harness/types.d.ts +51 -19
  409. package/dist/engine/harness/types.js +28 -1
  410. package/dist/engine/llm/types.d.ts +26 -14
  411. package/dist/engine/llm/types.js +2 -2
  412. package/dist/engine/loop/agent-loop.d.ts +2 -2
  413. package/dist/engine/loop/agent-loop.js +51 -275
  414. package/dist/engine/loop/types.d.ts +0 -18
  415. package/dist/engine/session/import-validate.d.ts +3 -0
  416. package/dist/engine/session/import-validate.js +34 -2
  417. package/dist/engine/session/repo-utils.d.ts +42 -4
  418. package/dist/engine/session/repo-utils.js +33 -5
  419. package/dist/engine/session/session.d.ts +41 -14
  420. package/dist/engine/session/session.js +96 -25
  421. package/dist/index.d.ts +21 -16
  422. package/dist/index.js +16 -10
  423. package/dist/orchestration/run-spec.d.ts +1 -1
  424. package/dist/orchestration/run-workflow-tool.d.ts +12 -9
  425. package/dist/orchestration/run-workflow-tool.js +15 -19
  426. package/dist/orchestration/workflow-governance.js +13 -21
  427. package/dist/orchestration/workflow-observe.d.ts +4 -3
  428. package/dist/orchestration/workflow-primitives.d.ts +1 -1
  429. package/dist/orchestration/workflow-record-artifact.d.ts +14 -0
  430. package/dist/orchestration/workflow-record-artifact.js +32 -0
  431. package/dist/orchestration/workflow-script-store.d.ts +9 -0
  432. package/dist/orchestration/workflow-script-store.js +20 -1
  433. package/dist/orchestration/workflow-types.d.ts +33 -3
  434. package/dist/orchestration/workflow.d.ts +24 -14
  435. package/dist/orchestration/workflow.js +52 -23
  436. package/dist/prompt-assembly/artifact.js +4 -8
  437. package/dist/prompt-assembly/catalog/engine.d.ts +263 -0
  438. package/dist/prompt-assembly/catalog/engine.js +30 -0
  439. package/dist/prompt-assembly/catalog/index.d.ts +1 -1
  440. package/dist/prompt-assembly/catalog/index.js +2 -2
  441. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +1 -1
  442. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +29 -0
  443. package/dist/prompt-assembly/epoch.js +6 -8
  444. package/dist/prompt-assembly/turn-snapshot.js +8 -9
  445. package/dist/stores/file/background-agent-store.js +5 -6
  446. package/dist/stores/file/checkpoint-store.d.ts +0 -4
  447. package/dist/stores/file/checkpoint-store.js +7 -3
  448. package/dist/stores/file/file-history-store.d.ts +8 -0
  449. package/dist/stores/file/file-history-store.js +72 -0
  450. package/dist/stores/file/fs-atomic.js +17 -12
  451. package/dist/stores/file/index.js +11 -5
  452. package/dist/stores/file/mailbox-store.js +13 -4
  453. package/dist/stores/file/permission-rule-store.js +14 -13
  454. package/dist/stores/file/shared-ledger.d.ts +4 -0
  455. package/dist/stores/file/shared-ledger.js +4 -0
  456. package/dist/stores/file/task-list-store.js +12 -3
  457. package/dist/stores/file/workflow-run-store.js +1 -0
  458. package/dist/tools/fs/bash-program-position.d.ts +4 -2
  459. package/dist/tools/fs/bash-program-position.js +1 -1
  460. package/dist/tools/fs/bash-readonly-classifier.js +1 -1
  461. package/dist/tools/fs/bound-open.d.ts +97 -0
  462. package/dist/tools/fs/bound-open.js +103 -0
  463. package/dist/tools/fs/containment-face.d.ts +2 -2
  464. package/dist/tools/fs/fs-pdf.d.ts +7 -1
  465. package/dist/tools/fs/fs-pdf.js +31 -23
  466. package/dist/tools/fs/fs-read.d.ts +24 -17
  467. package/dist/tools/fs/fs-read.js +84 -53
  468. package/dist/tools/fs/fs-shared.d.ts +14 -12
  469. package/dist/tools/fs/fs-shared.js +5 -4
  470. package/dist/tools/fs/fs-write.d.ts +2 -2
  471. package/dist/tools/fs/fs-write.js +20 -12
  472. package/dist/tools/fs/index.d.ts +4 -4
  473. package/dist/tools/fs/index.js +2 -2
  474. package/dist/tools/fs/notebook.d.ts +1 -1
  475. package/dist/tools/fs/pdf.d.ts +12 -3
  476. package/dist/tools/fs/pdf.js +22 -9
  477. package/dist/tools/fs/read-deny-home.d.ts +3 -2
  478. package/dist/tools/fs/read-deny-home.js +8 -11
  479. package/dist/tools/fs/safety.d.ts +3 -2
  480. package/dist/tools/fs/shell-read-check.js +10 -9
  481. package/dist/tools/monitor.d.ts +6 -5
  482. package/dist/tools/task-list.d.ts +16 -6
  483. package/dist/tools/task-list.js +4 -0
  484. package/dist/tools/web.d.ts +9 -1
  485. package/dist/tools/web.js +8 -3
  486. package/dist/tools/worktree.d.ts +7 -5
  487. package/dist/tools/worktree.js +4 -3
  488. package/package.json +4 -3
  489. package/test/export-surface.snapshot.json +93 -7
  490. package/wire-changes/core-stores-sql@7.68.0.json +39 -0
  491. package/wire-changes/core@7.68.0.json +4257 -0
  492. package/wire-changes/mods-kernel@7.68.0.json +129 -0
  493. package/wire-changes/primitives@7.68.0.json +253 -0
  494. package/wire-changes/wiki-gate@7.68.0.json +39 -0
  495. package/dist/core/runner/credential-origin-seat.d.ts +0 -2
  496. package/dist/core/runner/credential-origin-seat.js +0 -20
@@ -431,6 +431,20 @@ export interface UserMessage {
431
431
  attachments?: ReadonlyArray<import("../../core/attachment-source.js").BundledAttachment>;
432
432
  /** {@link RowRewrittenBy} */
433
433
  rewrittenBy?: RowRewrittenBy;
434
+ /**
435
+ * What this row is ({@link import("../../core/user-row-origin.js").UserRowOrigin}) — a person's (or a relay's) input, an attachment
436
+ * frame of one, the engine's interruption line, or any other engine note — the same word `message_committed.origin` says of it.
437
+ * Written once at the row's first commit point (`src/core/user-row-origin.ts`) and persisted with it, so a reader of the store
438
+ * alone tells a person's row from an engine's: `provenance` / `engineMinted` say how derived views present a row, never who wrote
439
+ * it (a person's live steer is an `engine-note` too). Read through `userRowSourceOf` only. Absent = a row written before the member
440
+ * existed: unknown, never read as a word. Attribution only: never sent to a provider ({@link stripEngineMetadata} strips it), never
441
+ * a decision input; the session-import door keeps a member of the closed set and drops anything else.
442
+ */
443
+ origin?: import("../../core/user-row-origin.js").UserRowOrigin;
444
+ /** On a row whose {@link UserMessage.origin} is `human_input`: the `human_input.inputId` of the one input the row is (absent on a
445
+ * resume's continuation merging parked steers, which is several). The key the frame and its row join by. Same posture as
446
+ * {@link UserMessage.origin}; anywhere else it is not read. */
447
+ inputId?: string;
434
448
  }
435
449
  /**
436
450
  * The extensions whose rewrite of this row the conversation kept (a `session.append` handler's, at the row's admission),
@@ -443,9 +457,8 @@ export type UserAttachmentKind = "text" | "notebook" | "image" | "pdf" | "direct
443
457
  /** Who held the bytes: the engine read a path in its workspace, or the host supplied text / an image. */
444
458
  export type UserAttachmentSupply = "path" | "content_text" | "content_image";
445
459
  /** What the engine delivered of the attachment's contents (the Read layer's outcome words). `attached` = the frame holds
446
- * them: a request carries them as the frame's data, or — when it already carries the same contents earlier — as the
447
- * sentence that they are not repeated beside that earlier copy, or — when its core cannot hold them — as the sentence
448
- * that they are not included. */
460
+ * them; what a request sends in their place is the capability word `user_attachments.read_state`'s statement
461
+ * (`ENGINE_CAPABILITIES`, `src/core/engine-capabilities.ts`). */
449
462
  export type UserAttachmentOutcome = "attached" | "partial" | "not_attached";
450
463
  /** The read-state entry a path attachment's delivery committed (the Read layer's observation, verbatim). */
451
464
  export interface UserAttachmentObservation {
@@ -469,7 +482,7 @@ export interface UserMessageAttachment {
469
482
  readonly inputId: string;
470
483
  /** `compaction_restore`: the engine minted this frame itself after a compaction landed, re-reading a file the
471
484
  * conversation had read (`ordinal` / `count` among the files that restore re-read); `project_instructions` / `nested_memory`:
472
- * an instruction file of the task root / of an accessed directory or a deployment's rule (among one load's). Absent: the user's. */
485
+ * an instruction file of a root's own level (the task root's, an additional directory's) / of an accessed directory or a deployment's rule (among one load's). Absent: the user's. */
473
486
  readonly origin?: "compaction_restore" | "nested_memory" | "project_instructions";
474
487
  /** 1-based position among that input's declared attachments, and how many it declared. */
475
488
  readonly ordinal: number;
@@ -777,10 +790,10 @@ export declare function flattenedUserText(content: UserMessage["content"]): stri
777
790
  export declare function changedFilesNoticesOf(m: unknown): ReadonlyArray<ChangedFilesNotice> | undefined;
778
791
  /**
779
792
  * RB-3 (stage S4 carry): strip the engine-provenance metadata fields from user messages before
780
- * serializing a Context to an external wire. The ten fields (`enginePrefixChars`/`engineSegments`/
781
- * `engineMinted`/`provenance`/`actor`/`engineNoteKey`/`attachment`/`attachments`/`runOrigin`/`changedFilesNotices`) are INTERNAL coordination
793
+ * serializing a Context to an external wire. The twelve fields (`enginePrefixChars`/`engineSegments`/
794
+ * `engineMinted`/`provenance`/`actor`/`engineNoteKey`/`attachment`/`attachments`/`runOrigin`/`changedFilesNotices`/`origin`/`inputId`) are INTERNAL coordination
782
795
  * between the engine's minting side and its consumers (permission classifier, compaction summarizer, prompt suggestions,
783
- * multiplayer attribution, attachment delivery, run attribution, the request's notice projection) — they must never reach a
796
+ * multiplayer attribution, attachment delivery, run attribution, the request's notice projection, the row's origin) — they must never reach a
784
797
  * provider payload; so is
785
798
  * {@link RowRewrittenBy}, on every role, and {@link AssistantMessage.answeredBy}. The built-in brains construct
786
799
  * their own wire shapes and are immune; a CUSTOM Brain that whole-object-serializes messages
@@ -913,17 +926,16 @@ export type AssistantMessageEvent = {
913
926
  partial: AssistantMessage;
914
927
  }
915
928
  /**
916
- * design/120 P2.0 provider contract — `toolcall_end` may trigger IN-STREAM TOOL EXECUTION
917
- * (agent-loop P2), so its emission carries real semantics, not just UI progress:
929
+ * design/120 P2.0 provider contract — `toolcall_end` says a call's input is complete, so its emission
930
+ * carries real semantics, not just UI progress (the loop forwards it to its consumers as a `message_update`;
931
+ * tools start once the stream has ended):
918
932
  * - Emit it only when the call's input is COMPLETE and parsed to a valid JSON object (`toolCall`
919
- * is executable as-is). A malformed/truncated accumulation must emit nothing (fail-closed: the
920
- * call then never executes in-stream; the brain's finalize surfaces it via its malformed path).
933
+ * is executable as-is). A malformed/truncated accumulation must emit nothing (fail-closed: no
934
+ * consumer is told a complete call exists; the brain's finalize surfaces it via its malformed path).
921
935
  * - Emit AT MOST ONCE per call, and every emitted call MUST appear — same `id`, same `arguments`
922
936
  * object identity not required but same values — in the terminal `done` message's content.
923
937
  * (One-directional: content may carry calls that never emitted `toolcall_end`, e.g. trailing
924
- * calls closed at finalize or text-repaired calls; those simply run on the post-stream batch
925
- * path.) An `error` terminal is allowed to lack the block; the loop's error-final reconciliation
926
- * merges executor-held calls back into the persisted content (design/120 §5.4).
938
+ * calls closed at finalize or text-repaired calls.) An `error` terminal is allowed to lack the block.
927
939
  */
928
940
  | {
929
941
  type: "toolcall_end";
@@ -50,7 +50,7 @@ export function renderUserAttachmentView(m, a, cap) {
50
50
  const data = blocks.map(renderContentBlock).join("\n");
51
51
  const cut = cap !== undefined && data.length > cap;
52
52
  const facts = [a.kind ?? "kind unknown", a.outcome, ...(a.truncated ? ["not the whole file"] : []), ...(cut ? [`excerpt: first ${cap} of ${data.length} characters`] : [])];
53
- const source = a.origin === "compaction_restore" ? "file re-read at summarization" : a.origin === "project_instructions" ? `instruction file of the task root${a.withdraws !== undefined ? ", withdrawn" : ""}` : a.origin === "nested_memory" ? `instruction file loaded for an accessed directory${a.withdraws !== undefined ? ", withdrawn" : ""}` : "user attachment";
53
+ const source = a.origin === "compaction_restore" ? "file re-read at summarization" : a.origin === "project_instructions" ? `instruction file of the task root or an additional working directory${a.withdraws !== undefined ? ", withdrawn" : ""}` : a.origin === "nested_memory" ? `instruction file loaded for an accessed directory${a.withdraws !== undefined ? ", withdrawn" : ""}` : "user attachment";
54
54
  const head = `${source} ${a.ordinal} of ${a.count} (${facts.join("; ")}): ${quoteDataLabel(a.label)}`;
55
55
  const body = cut ? data.slice(0, cap) : data;
56
56
  return body.length > 0 ? `${head}\n${body}` : head;
@@ -120,7 +120,7 @@ export function stripEngineMetadata(messages) {
120
120
  const { rewrittenBy: _r, answeredBy: _s, ...kept } = m;
121
121
  return kept;
122
122
  }
123
- const { enginePrefixChars: _a, engineSegments: _b, engineMinted: _c, provenance: _d, actor: _e, engineNoteKey: _f, attachment: _g, runOrigin: _h, rewrittenBy: _i, attachments: _j, changedFilesNotices: _k, ...rest } = m;
123
+ const { enginePrefixChars: _a, engineSegments: _b, engineMinted: _c, provenance: _d, actor: _e, engineNoteKey: _f, attachment: _g, runOrigin: _h, rewrittenBy: _i, attachments: _j, changedFilesNotices: _k, origin: _l, inputId: _m, ...rest } = m;
124
124
  return rest;
125
125
  });
126
126
  }
@@ -190,8 +190,8 @@ type ExecutedToolCallBatch = {
190
190
  /**
191
191
  * ONE call through the loop's per-call pipeline — announced, prepared (the gate included), executed through the execution
192
192
  * seat, finalized, closed. The sequential lane runs each call through it and adds the call's tool-result message; a host's
193
- * own call (`AgentHarness.callTool`) runs it with no model message and adds nothing. The partitioned and streaming lanes run
194
- * the same steps in two phases.
193
+ * own call (`AgentHarness.callTool`) runs it with no model message and adds nothing. The partitioned lane runs the same steps in
194
+ * two phases.
195
195
  */
196
196
  export declare function runToolCall(currentContext: AgentContext, assistantMessage: AssistantMessage | undefined, toolCall: AgentToolCall, config: AgentLoopConfig, signal: AbortSignal | undefined, emit: AgentEventSink): Promise<{
197
197
  finalized: FinalizedToolCallOutcome;
@@ -1,6 +1,5 @@
1
1
  import { findToolByName, toolNameIndex, validateToolArguments } from "../llm/index.js";
2
2
  import { truncateError } from "../../core/tool-errors.js";
3
- import { noteInterruptionMarker } from "../../core/user-row-origin.js";
4
3
  import { judgeToolNameMiss, mountedToolNames } from "../../core/tool-name-aliases.js";
5
4
  import { engineTextFor } from "../../prompt-assembly/engine-text.js";
6
5
  import { INTERRUPTED_BY_USER_FOR_TOOL_USE_MARKER, INTERRUPTED_BY_USER_MARKER, } from "../../core/session-reconcile.js";
@@ -126,7 +125,7 @@ async function settleTrailingBatchTurn(state, signal, emit, settle) {
126
125
  if (!ended && turnController.signal.aborted) {
127
126
  const cut = state.config.noteTurnCutConsumed?.(turnController);
128
127
  const pendingBeforeSettlement = state.pendingMessages;
129
- const outcome = await settleInterruptedTurn(state, tail, new StreamToolExecutor(state.context, state.config, turnController.signal, emit), batch.messages, signal, emit, cut);
128
+ const outcome = await settleInterruptedTurn(state, tail, batch.messages, signal, emit, cut);
130
129
  ended = outcome.kind === "terminal";
131
130
  if (!ended)
132
131
  state.pendingMessages.unshift(...pendingBeforeSettlement);
@@ -388,11 +387,10 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
388
387
  state.newMessages.push(message);
389
388
  }
390
389
  }
391
- let executor = new StreamToolExecutor(state.context, state.config, turnController.signal, emit);
392
390
  const retractWhenNothingInFlight = (final) => {
393
391
  if (final.stopReason === "aborted" || final.stopReason === "error")
394
392
  return;
395
- if (executor.admittedCount === 0 && final.content.every((b) => b.type !== "toolCall"))
393
+ if (final.content.every((b) => b.type !== "toolCall"))
396
394
  retractSeat();
397
395
  };
398
396
  const staticReasoningCutDowngrade = state.config.recovery?.truncatedOutput !== undefined &&
@@ -403,16 +401,10 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
403
401
  let withhold = withholdEnabled ? createPtlWithholdBuffer(emit, ptlDetect) : undefined;
404
402
  let message;
405
403
  let cutAtFinalSettle = false;
406
- try {
407
- ({ message, cutAtSettle: cutAtFinalSettle } =
408
- given !== undefined
409
- ? await deliverGivenAnswer(state.context, state.config, given, emit)
410
- : await streamAssistantResponse(state.context, state.config, turnController.signal, withhold?.sink ?? emit, streamFn, runtime, executor, staticReasoningCutDowngrade, retractWhenNothingInFlight));
411
- }
412
- finally {
413
- await executor.settle();
414
- }
415
- raiseFatalCancellation(executor);
404
+ ({ message, cutAtSettle: cutAtFinalSettle } =
405
+ given !== undefined
406
+ ? await deliverGivenAnswer(state.context, state.config, given, emit)
407
+ : await streamAssistantResponse(state.context, state.config, turnController.signal, withhold?.sink ?? emit, streamFn, runtime, staticReasoningCutDowngrade, retractWhenNothingInFlight));
416
408
  let interruptedInRecovery = false;
417
409
  let imageRetries = 0;
418
410
  const refusalChangesRequest = () => message.errorKind === IMAGE_REFUSAL_KIND
@@ -423,7 +415,6 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
423
415
  !signal?.aborted &&
424
416
  !turnController.signal.aborted &&
425
417
  isBlankFailureContent(message) &&
426
- executor.admittedCount === 0 &&
427
418
  state.context.messages[state.context.messages.length - 1] === message &&
428
419
  refusalChangesRequest()) {
429
420
  if (message.errorKind === IMAGE_REFUSAL_KIND)
@@ -436,14 +427,7 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
436
427
  }
437
428
  }
438
429
  trace?.({ kind: "continue", reason: message.errorKind === IMAGE_REFUSAL_KIND ? "image_refusal_retry" : "tool_schema_refusal_retry" });
439
- executor = new StreamToolExecutor(state.context, state.config, turnController.signal, emit);
440
- try {
441
- ({ message, cutAtSettle: cutAtFinalSettle } = await streamAssistantResponse(state.context, state.config, turnController.signal, withhold?.sink ?? emit, streamFn, runtime, executor, staticReasoningCutDowngrade, retractWhenNothingInFlight));
442
- }
443
- finally {
444
- await executor.settle();
445
- }
446
- raiseFatalCancellation(executor);
430
+ ({ message, cutAtSettle: cutAtFinalSettle } = await streamAssistantResponse(state.context, state.config, turnController.signal, withhold?.sink ?? emit, streamFn, runtime, staticReasoningCutDowngrade, retractWhenNothingInFlight));
447
431
  }
448
432
  };
449
433
  await resendWithoutRefusedParts();
@@ -456,7 +440,6 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
456
440
  !signal?.aborted &&
457
441
  detect(message) &&
458
442
  isBlankFailureContent(message) &&
459
- executor.admittedCount === 0 &&
460
443
  attempt < maxRetries) {
461
444
  attempt++;
462
445
  if (state.context.messages[state.context.messages.length - 1] === message) {
@@ -488,14 +471,7 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
488
471
  break;
489
472
  }
490
473
  trace?.({ kind: "continue", reason: "reactive_compact_retry" });
491
- executor = new StreamToolExecutor(state.context, state.config, turnController.signal, emit);
492
- try {
493
- ({ message, cutAtSettle: cutAtFinalSettle } = await streamAssistantResponse(state.context, state.config, turnController.signal, withhold?.sink ?? emit, streamFn, runtime, executor, staticReasoningCutDowngrade, retractWhenNothingInFlight));
494
- }
495
- finally {
496
- await executor.settle();
497
- }
498
- raiseFatalCancellation(executor);
474
+ ({ message, cutAtSettle: cutAtFinalSettle } = await streamAssistantResponse(state.context, state.config, turnController.signal, withhold?.sink ?? emit, streamFn, runtime, staticReasoningCutDowngrade, retractWhenNothingInFlight));
499
475
  }
500
476
  }
501
477
  }
@@ -503,8 +479,7 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
503
479
  const unrecoveredPtlFailureUnderInterrupt = ptl !== undefined &&
504
480
  message.stopReason === "error" &&
505
481
  ptlDetect(message) &&
506
- isBlankFailureContent(message) &&
507
- executor.admittedCount === 0;
482
+ isBlankFailureContent(message);
508
483
  const cutAtPtlLaneExit = turnController.signal.aborted;
509
484
  const interruptOwnsTurn = ((message.stopReason === "aborted" && cutAtFinalSettle) || (unrecoveredPtlFailureUnderInterrupt && cutAtPtlLaneExit) || interruptedInRecovery) &&
510
485
  !signal?.aborted;
@@ -523,7 +498,7 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
523
498
  state.staticReasoningCutRecoveries++;
524
499
  if (interruptOwnsTurn) {
525
500
  retractSeat();
526
- return await settleInterruptedTurn(state, message, executor, [], signal, emit, cut);
501
+ return await settleInterruptedTurn(state, message, [], signal, emit, cut);
527
502
  }
528
503
  {
529
504
  const degen = state.config.recovery?.degenerateOutput;
@@ -531,7 +506,6 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
531
506
  message.stopReason === "error" &&
532
507
  !signal?.aborted &&
533
508
  degen.detect(message) &&
534
- executor.admittedCount === 0 &&
535
509
  message.content.every((b) => b.type !== "toolCall") &&
536
510
  state.degenerateContinues < (degen.maxContinues ?? 2)) {
537
511
  retractSeat();
@@ -546,15 +520,14 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
546
520
  }
547
521
  if (message.stopReason === "error" || message.stopReason === "aborted") {
548
522
  retractSeat();
549
- const errorFinalResults = await harvestExecutorOnErrorFinal(executor, state, message, turnController.signal, emit);
550
- await endTurn(state, emit, message, errorFinalResults);
523
+ await endTurn(state, emit, message, []);
551
524
  await emit({ type: "agent_end", messages: state.newMessages });
552
525
  return { kind: "terminal", reason: "assistant_error" };
553
526
  }
554
527
  const toolResults = [];
555
528
  state.hasMoreToolCalls = false;
556
529
  if (toolCalls.length > 0) {
557
- const executedToolBatch = await executeToolCalls(state.context, message, state.config, turnController.signal, emit, executor);
530
+ const executedToolBatch = await executeToolCalls(state.context, message, state.config, turnController.signal, emit);
558
531
  toolResults.push(...executedToolBatch.messages);
559
532
  state.hasMoreToolCalls = !executedToolBatch.terminate;
560
533
  for (const result of toolResults) {
@@ -562,17 +535,11 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
562
535
  state.newMessages.push(result);
563
536
  }
564
537
  }
565
- else {
566
- for (const orphan of executor.remaining()) {
567
- executor.take(orphan.toolCall.id);
568
- await closeOrphanedStreamEntry(orphan, emit);
569
- }
570
- }
571
538
  const cutAtBatchSettle = turnController.signal.aborted;
572
539
  retractSeat();
573
540
  if (toolCalls.length > 0 && cutAtBatchSettle && !signal?.aborted) {
574
541
  const batchCut = state.config.noteTurnCutConsumed?.(turnController);
575
- return await settleInterruptedTurn(state, message, executor, toolResults, signal, emit, batchCut);
542
+ return await settleInterruptedTurn(state, message, toolResults, signal, emit, batchCut);
576
543
  }
577
544
  await endTurn(state, emit, message, toolResults);
578
545
  const nextTurnContext = {
@@ -684,9 +651,8 @@ export const TURN_INTERRUPTED_TOOL_TEXT = "[INTERRUPTED] The user interrupted th
684
651
  "had no side effects. Address the user's interjection first; re-issue the call afterwards if it is still needed.";
685
652
  export const TURN_ENDED_TOOL_TEXT = "[Tool call did not complete: the turn was ended to deliver the message that follows. Nothing refused it; re-run it if still needed.]";
686
653
  export const INTERRUPT_TURN_CUT_SETTLEMENT = Object.freeze({ neverStartedText: TURN_INTERRUPTED_TOOL_TEXT, marker: true, movesArmedCommandAside: false });
687
- async function settleInterruptedTurn(state, message, executor, committedResults, signal, emit, cut = INTERRUPT_TURN_CUT_SETTLEMENT) {
654
+ async function settleInterruptedTurn(state, message, committedResults, signal, emit, cut = INTERRUPT_TURN_CUT_SETTLEMENT) {
688
655
  const toolResults = [...committedResults];
689
- toolResults.push(...(await harvestExecutorOnErrorFinal(executor, state, message, signal, emit)));
690
656
  const turnCalls = message.content.filter((c) => c.type === "toolCall");
691
657
  const priorResults = state.context.messages.slice(state.context.messages.lastIndexOf(message) + 1).filter((m) => m.role === "toolResult");
692
658
  const answered = new Set([...priorResults, ...toolResults].map((r) => r.toolCallId));
@@ -738,9 +704,9 @@ async function settleInterruptedTurn(state, message, executor, committedResults,
738
704
  },
739
705
  ],
740
706
  provenance: "engine-note",
707
+ origin: "interruption_marker",
741
708
  timestamp: Date.now(),
742
709
  };
743
- noteInterruptionMarker(marker);
744
710
  await emit({ type: "message_start", message: marker });
745
711
  await emit({ type: "message_end", message: marker });
746
712
  state.context.messages.push(marker);
@@ -772,7 +738,7 @@ async function settleInterruptedTurn(state, message, executor, committedResults,
772
738
  state.pendingMessages = (await state.config.getSteeringMessages?.(state.hasMoreToolCalls)) || [];
773
739
  return { kind: "ran" };
774
740
  }
775
- async function streamAssistantResponse(context, config, signal, emit, streamFn, runtime, executor, staticReasoningCutDowngrade, onObtained) {
741
+ async function streamAssistantResponse(context, config, signal, emit, streamFn, runtime, staticReasoningCutDowngrade, onObtained) {
776
742
  let messages = context.messages;
777
743
  if (config.transformContext) {
778
744
  const transformed = await config.transformContext(messages, signal);
@@ -847,18 +813,12 @@ async function streamAssistantResponse(context, config, signal, emit, streamFn,
847
813
  message: { ...message },
848
814
  });
849
815
  }
850
- if (event.type === "toolcall_end" && executor) {
851
- executor.maybeAdmit(event.toolCall, partialMessage);
852
- }
853
816
  break;
854
817
  case "done":
855
818
  case "error": {
856
819
  const finalMessage = receivedFinal(await response.result());
857
820
  const cutAtSettle = signal?.aborted === true;
858
821
  onObtained?.(finalMessage);
859
- if (executor && (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted")) {
860
- mergeBackAdmittedCalls(finalMessage, executor);
861
- }
862
822
  if (addedPartial) {
863
823
  context.messages[context.messages.length - 1] = finalMessage;
864
824
  }
@@ -876,9 +836,6 @@ async function streamAssistantResponse(context, config, signal, emit, streamFn,
876
836
  const finalMessage = receivedFinal(await response.result());
877
837
  const cutAtSettle = signal?.aborted === true;
878
838
  onObtained?.(finalMessage);
879
- if (executor && (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted")) {
880
- mergeBackAdmittedCalls(finalMessage, executor);
881
- }
882
839
  if (addedPartial) {
883
840
  context.messages[context.messages.length - 1] = finalMessage;
884
841
  }
@@ -1040,12 +997,12 @@ function cutByTurnSignal(open, signal, model) {
1040
997
  result: () => final,
1041
998
  };
1042
999
  }
1043
- async function executeToolCalls(currentContext, assistantMessage, config, signal, emit, executor) {
1000
+ async function executeToolCalls(currentContext, assistantMessage, config, signal, emit) {
1044
1001
  const toolCalls = assistantMessage.content.filter((c) => c.type === "toolCall");
1045
1002
  if (config.toolExecution === "sequential") {
1046
1003
  return executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, signal, emit);
1047
1004
  }
1048
- return executeToolCallsPartitioned(currentContext, assistantMessage, toolCalls, config, signal, emit, executor);
1005
+ return executeToolCallsPartitioned(currentContext, assistantMessage, toolCalls, config, signal, emit);
1049
1006
  }
1050
1007
  async function executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, signal, emit) {
1051
1008
  const finalizedCalls = [];
@@ -1180,68 +1137,44 @@ async function runCapped(thunks, limit) {
1180
1137
  }
1181
1138
  return results;
1182
1139
  }
1183
- async function executeToolCallsPartitioned(currentContext, assistantMessage, toolCalls, config, signal, emit, executor) {
1140
+ async function executeToolCallsPartitioned(currentContext, assistantMessage, toolCalls, config, signal, emit) {
1184
1141
  const cap = resolveToolConcurrency(config.maxToolConcurrency);
1185
1142
  const allFinalized = [];
1186
1143
  const messages = [];
1187
- const remainingCalls = [];
1188
1144
  let halt;
1189
- for (const toolCall of toolCalls) {
1190
- const held = executor?.take(toolCall.id);
1191
- if (!held) {
1192
- remainingCalls.push(toolCall);
1193
- continue;
1194
- }
1195
- const finalized = await finalizeStreamEntry(currentContext, assistantMessage, held, config, signal);
1196
- await emitToolExecutionEnd(finalized, emit);
1197
- const toolResultMessage = createToolResultMessage(finalized);
1198
- await emitToolResultMessage(toolResultMessage, emit);
1199
- allFinalized.push(finalized);
1200
- messages.push(toolResultMessage);
1201
- if (held.immediate?.halt !== undefined)
1202
- halt ??= held.immediate.halt;
1203
- }
1204
- if (executor) {
1205
- for (const orphan of executor.remaining()) {
1206
- executor.take(orphan.toolCall.id);
1207
- await closeOrphanedStreamEntry(orphan, emit);
1208
- }
1209
- }
1210
- if (halt === undefined) {
1211
- const batches = partitionToolCalls(remainingCalls, currentContext.tools);
1212
- outer: for (const batch of batches) {
1213
- if (signal?.aborted)
1214
- break;
1215
- const entries = [];
1216
- for (const toolCall of batch.calls) {
1217
- await emit({
1218
- type: "tool_execution_start",
1219
- toolCallId: toolCall.id,
1220
- toolName: toolCall.name,
1221
- args: toolCall.arguments,
1222
- });
1223
- const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, config, signal);
1224
- if (preparation.kind === "immediate") {
1225
- const finalized = { toolCall, result: preparation.result, isError: preparation.isError, ...(preparation.notExecuted === true ? { notExecuted: true } : {}) };
1226
- await emitToolExecutionEnd(finalized, emit);
1227
- entries.push({ finalized, toolCall });
1228
- if (preparation.halt !== undefined) {
1229
- halt = preparation.halt;
1230
- break;
1231
- }
1232
- }
1233
- else {
1234
- entries.push({ prepared: preparation, toolCall });
1235
- }
1236
- if (signal?.aborted) {
1237
- await settleBatch(entries, true);
1238
- break outer;
1145
+ const batches = partitionToolCalls(toolCalls, currentContext.tools);
1146
+ outer: for (const batch of batches) {
1147
+ if (signal?.aborted)
1148
+ break;
1149
+ const entries = [];
1150
+ for (const toolCall of batch.calls) {
1151
+ await emit({
1152
+ type: "tool_execution_start",
1153
+ toolCallId: toolCall.id,
1154
+ toolName: toolCall.name,
1155
+ args: toolCall.arguments,
1156
+ });
1157
+ const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, config, signal);
1158
+ if (preparation.kind === "immediate") {
1159
+ const finalized = { toolCall, result: preparation.result, isError: preparation.isError, ...(preparation.notExecuted === true ? { notExecuted: true } : {}) };
1160
+ await emitToolExecutionEnd(finalized, emit);
1161
+ entries.push({ finalized, toolCall });
1162
+ if (preparation.halt !== undefined) {
1163
+ halt = preparation.halt;
1164
+ break;
1239
1165
  }
1240
1166
  }
1241
- await settleBatch(entries, batch.safe);
1242
- if (halt !== undefined)
1243
- break;
1167
+ else {
1168
+ entries.push({ prepared: preparation, toolCall });
1169
+ }
1170
+ if (signal?.aborted) {
1171
+ await settleBatch(entries, true);
1172
+ break outer;
1173
+ }
1244
1174
  }
1175
+ await settleBatch(entries, batch.safe);
1176
+ if (halt !== undefined)
1177
+ break;
1245
1178
  }
1246
1179
  if (halt !== undefined && !signal?.aborted) {
1247
1180
  const settledIds = new Set(messages.map((m) => m.toolCallId));
@@ -1290,145 +1223,6 @@ async function executeToolCallsPartitioned(currentContext, assistantMessage, too
1290
1223
  }
1291
1224
  }
1292
1225
  }
1293
- class StreamToolExecutor {
1294
- context;
1295
- config;
1296
- signal;
1297
- emit;
1298
- entries = new Map();
1299
- admittedOrder = [];
1300
- barrier = false;
1301
- inFlight = 0;
1302
- fatalCancellation;
1303
- constructor(context, config, signal, emit) {
1304
- this.context = context;
1305
- this.config = config;
1306
- this.signal = signal;
1307
- this.emit = emit;
1308
- }
1309
- get admittedCount() {
1310
- return this.admittedOrder.length;
1311
- }
1312
- admittedToolCalls() {
1313
- return this.admittedOrder.map((id) => this.entries.get(id)?.toolCall).filter((tc) => tc !== undefined);
1314
- }
1315
- maybeAdmit(toolCall, partialAssistant) {
1316
- if (this.barrier)
1317
- return;
1318
- if (this.config.streamingToolExecution !== true ||
1319
- this.config.toolExecution === "sequential" ||
1320
- this.signal?.aborted ||
1321
- partialAssistant === null ||
1322
- !isBatchSafeToolCall(findToolByName(this.context.tools, toolCall.name), toolCall) ||
1323
- this.inFlight >= resolveToolConcurrency(this.config.maxToolConcurrency) ||
1324
- this.entries.has(toolCall.id)) {
1325
- this.barrier = true;
1326
- return;
1327
- }
1328
- const entry = { toolCall, promise: Promise.resolve() };
1329
- this.entries.set(toolCall.id, entry);
1330
- this.admittedOrder.push(toolCall.id);
1331
- entry.promise = this.runOne(entry, partialAssistant);
1332
- }
1333
- async runOne(entry, partialAssistant) {
1334
- this.inFlight++;
1335
- try {
1336
- await this.emit({
1337
- type: "tool_execution_start",
1338
- toolCallId: entry.toolCall.id,
1339
- toolName: entry.toolCall.name,
1340
- args: entry.toolCall.arguments,
1341
- });
1342
- const preparation = await prepareToolCall(this.context, partialAssistant, entry.toolCall, this.config, this.signal);
1343
- if (preparation.kind === "immediate") {
1344
- entry.immediate = preparation;
1345
- if (preparation.halt !== undefined)
1346
- this.barrier = true;
1347
- return;
1348
- }
1349
- entry.prepared = preparation;
1350
- entry.executed = await executePreparedToolCall(preparation, this.signal, this.emit, this.config.executeTool, this.config.abortResultDetails, (error) => this.retainCancellation(error));
1351
- }
1352
- catch (error) {
1353
- if (isAbortSemanticsError(error))
1354
- this.retainCancellation(error);
1355
- entry.immediate = {
1356
- kind: "immediate",
1357
- result: thrownErrorToolResult(error),
1358
- isError: true,
1359
- };
1360
- }
1361
- finally {
1362
- this.inFlight--;
1363
- }
1364
- }
1365
- async settle() {
1366
- this.barrier = true;
1367
- await Promise.all([...this.entries.values()].map((e) => e.promise));
1368
- }
1369
- retainCancellation(error) {
1370
- this.fatalCancellation ??= error;
1371
- this.barrier = true;
1372
- }
1373
- takeFatalCancellation() {
1374
- const cancellation = this.fatalCancellation;
1375
- this.fatalCancellation = undefined;
1376
- return cancellation;
1377
- }
1378
- take(id) {
1379
- const entry = this.entries.get(id);
1380
- if (entry)
1381
- this.entries.delete(id);
1382
- return entry;
1383
- }
1384
- remaining() {
1385
- return this.admittedOrder
1386
- .map((id) => this.entries.get(id))
1387
- .filter((e) => e !== undefined);
1388
- }
1389
- }
1390
- async function finalizeStreamEntry(currentContext, assistantMessage, entry, config, signal) {
1391
- if (entry.prepared && entry.executed) {
1392
- return finalizeExecutedToolCall(currentContext, assistantMessage, entry.prepared, entry.executed, config, signal);
1393
- }
1394
- const immediate = entry.immediate ?? {
1395
- kind: "immediate",
1396
- result: createErrorToolResult("in-stream execution produced no outcome"),
1397
- isError: true,
1398
- };
1399
- return { toolCall: entry.toolCall, result: immediate.result, isError: immediate.isError, ...(immediate.notExecuted === true ? { notExecuted: true } : {}) };
1400
- }
1401
- async function closeOrphanedStreamEntry(entry, emit) {
1402
- await emit({
1403
- type: "tool_execution_end",
1404
- toolCallId: entry.toolCall.id,
1405
- toolName: entry.toolCall.name,
1406
- result: createErrorToolResult("in-stream result dropped: the call is missing from the final assistant content (provider contract breach)"),
1407
- isError: true,
1408
- });
1409
- }
1410
- async function harvestExecutorOnErrorFinal(executor, state, finalMessage, signal, emit) {
1411
- const held = executor.remaining();
1412
- if (held.length === 0)
1413
- return [];
1414
- const results = [];
1415
- const persistedCallIds = new Set(finalMessage.content.filter((c) => c.type === "toolCall").map((c) => c.id));
1416
- for (const entry of held) {
1417
- executor.take(entry.toolCall.id);
1418
- if (!persistedCallIds.has(entry.toolCall.id)) {
1419
- await closeOrphanedStreamEntry(entry, emit);
1420
- continue;
1421
- }
1422
- const finalized = await finalizeStreamEntry(state.context, finalMessage, entry, state.config, signal);
1423
- await emitToolExecutionEnd(finalized, emit);
1424
- const toolResultMessage = createToolResultMessage(finalized);
1425
- await emitToolResultMessage(toolResultMessage, emit);
1426
- state.context.messages.push(toolResultMessage);
1427
- state.newMessages.push(toolResultMessage);
1428
- results.push(toolResultMessage);
1429
- }
1430
- return results;
1431
- }
1432
1226
  function receivedFinal(message) {
1433
1227
  const words = readMember(message, "errorMessage");
1434
1228
  const minted = typeof words === "string" ? remoteWords(words, []) : undefined;
@@ -1450,16 +1244,6 @@ function readsTheSame(o, key, value) {
1450
1244
  return value === undefined && !(key in o);
1451
1245
  return "value" in d && d.value === value;
1452
1246
  }
1453
- function mergeBackAdmittedCalls(finalMessage, executor) {
1454
- const admitted = executor.admittedToolCalls();
1455
- if (admitted.length === 0)
1456
- return;
1457
- const present = new Set(finalMessage.content.filter((c) => c.type === "toolCall").map((c) => c.id));
1458
- const missing = admitted.filter((tc) => !present.has(tc.id));
1459
- if (missing.length === 0)
1460
- return;
1461
- finalMessage.content = [...finalMessage.content, ...missing];
1462
- }
1463
1247
  function shouldTerminateToolBatch(finalizedCalls) {
1464
1248
  return (finalizedCalls.length > 0 &&
1465
1249
  finalizedCalls.every((finalized) => finalized.result.terminate === true));
@@ -1660,7 +1444,7 @@ async function prepareToolCall(currentContext, assistantMessage, toolCall, confi
1660
1444
  });
1661
1445
  }
1662
1446
  }
1663
- async function executePreparedToolCall(prepared, signal, emit, executeTool, abortResultDetails, onLateCancellation) {
1447
+ async function executePreparedToolCall(prepared, signal, emit, executeTool, abortResultDetails) {
1664
1448
  const updateEvents = [];
1665
1449
  let acceptingUpdates = true;
1666
1450
  if (signal?.aborted) {
@@ -1687,10 +1471,7 @@ async function executePreparedToolCall(prepared, signal, emit, executeTool, abor
1687
1471
  catch (error) {
1688
1472
  delivery = Promise.reject(error);
1689
1473
  }
1690
- void delivery.catch((reason) => {
1691
- if (isAbortSemanticsError(reason))
1692
- onLateCancellation?.(reason);
1693
- });
1474
+ void delivery.catch(() => undefined);
1694
1475
  updateEvents.push(delivery);
1695
1476
  }));
1696
1477
  const startBody = () => (bodyClosed ? Promise.resolve(Object.assign(createErrorToolResult("operation not executed: the execution station had already settled this call without running its body"), { isError: true })) : ((bodyStarted = true), body()));
@@ -1769,11 +1550,6 @@ async function settleUpdateDeliveries(updateEvents) {
1769
1550
  throw failure.reason;
1770
1551
  return failure;
1771
1552
  }
1772
- function raiseFatalCancellation(executor) {
1773
- const cancellation = executor.takeFatalCancellation();
1774
- if (cancellation !== undefined)
1775
- throw cancellation;
1776
- }
1777
1553
  async function executePreparedWithDisclosure(currentContext, assistantMessage, prepared, config, signal, emit) {
1778
1554
  let executed;
1779
1555
  try {