@sema-agent/core 7.67.3 → 7.68.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (501) hide show
  1. package/CHANGELOG.md +1537 -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 +45 -2
  69. package/dist/core/checkpoint-requirements.js +16 -6
  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 +18 -0
  388. package/dist/core/tool-roster.js +30 -1
  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-stores-sql@7.68.1.json +39 -0
  492. package/wire-changes/core@7.68.0.json +4257 -0
  493. package/wire-changes/core@7.68.1.json +95 -0
  494. package/wire-changes/mods-kernel@7.68.0.json +129 -0
  495. package/wire-changes/mods-kernel@7.68.1.json +39 -0
  496. package/wire-changes/primitives@7.68.0.json +253 -0
  497. package/wire-changes/primitives@7.68.1.json +39 -0
  498. package/wire-changes/wiki-gate@7.68.0.json +39 -0
  499. package/wire-changes/wiki-gate@7.68.1.json +39 -0
  500. package/dist/core/runner/credential-origin-seat.d.ts +0 -2
  501. package/dist/core/runner/credential-origin-seat.js +0 -20
@@ -1,6 +1,6 @@
1
1
  import { uuidv7 } from "../../internal/harness.js";
2
- import { createSafeNotifier, observeThenableRejection } from "../safe-notify.js";
3
- import { forwardSafely } from "./forward-sink.js";
2
+ import { observeThenableRejection } from "../safe-notify.js";
3
+ import { forwardSafely, hostSinkNotifier } from "./forward-sink.js";
4
4
  import { createSnapshotFrameSeat } from "../snapshot-frame-seat.js";
5
5
  import { emitsChildRowFrames, taskStartedFrame } from "../delegation-frames.js";
6
6
  import { recordFrameReceipt, toolResultReceiptKey } from "../frame-settlement.js";
@@ -9,7 +9,9 @@ import { discloseDroppedPending, renderTaskNotificationXml, sessionAddressOf, ta
9
9
  import { buildAppliedHumanInputEvent } from "../human-input-projection.js";
10
10
  import { announceAcceptance, nextHumanInputSeq } from "./steer-admission.js";
11
11
  import { deliverDelegationLifecycle, deliverEngineNotice, parentLegIds, parkedInputIdsOf, undrainedUserInputNotices } from "../types.js";
12
- import { droppedInputsDisclosure } from "../input-author.js";
12
+ import { droppedInputsDisclosure, droppedInputsNotice } from "../input-author.js";
13
+ import { legNoticeTaskId } from "../mods/stations.js";
14
+ import { announceDigest, withAnnounceDigests } from "./announce-once-ledger.js";
13
15
  import { inputSourceOf } from "../steer-replay.js";
14
16
  import { mintCallerStopGate } from "./caller-stop-gate.js";
15
17
  export function runIdentityWiring(input) {
@@ -24,9 +26,7 @@ export function runIdentityWiring(input) {
24
26
  const parentToolCallId = internals?.parentToolCallId;
25
27
  const ident = () => parentToolCallId !== undefined ? { eventId: uuidv7(), parentToolCallId, sourceTaskId: runSourceTaskId } : { eventId: uuidv7() };
26
28
  notificationLane.ident = ident;
27
- const internalsNotifier = createSafeNotifier({
28
- onError: (f) => console.warn(`[sema-core] ${f.site}: run-internals sink threw (contained; further failures counted, not re-disclosed): ${f.error.message}`),
29
- });
29
+ const internalsNotifier = hostSinkNotifier(runner.deps.onNotice, "run_internals");
30
30
  const legAt = Object.freeze({ taskId: prepared.taskId, sessionId: prepared.sessionId });
31
31
  const offerLegFrame = (frame) => {
32
32
  Object.freeze(frame);
@@ -40,15 +40,13 @@ export function runIdentityWiring(input) {
40
40
  prepared.toolRosterDeltas.subscribe((delta) => queue.push({ type: "tool_roster_delta", delta, ...ident() }));
41
41
  prepared.toolDisclosure?.subscribe((snapshot) => queue.push({ type: "tool_disclosure", ...snapshot, ...ident() }));
42
42
  prepared.workspaceFrame.subscribe((snapshot) => offerLegFrame({ type: "workspace_changed", ...snapshot, ...ident() }));
43
- const delegationLifecycleNotifier = createSafeNotifier({
44
- onError: (f) => console.warn(`[sema-core] ${f.site}: delegation-lifecycle observer threw (contained; further failures counted, not re-disclosed): ${f.error.message}`),
45
- });
43
+ const delegationLifecycleNotifier = hostSinkNotifier(runner.deps.onNotice, "delegation_lifecycle");
46
44
  const emitDelegationLifecycle = (event) => {
47
45
  if (!prepared.hookIdentity.isDelegatedChild)
48
46
  return;
49
47
  if (runner.deps.onDelegationLifecycle === undefined)
50
48
  return;
51
- deliverDelegationLifecycle(runner.deps.onDelegationLifecycle, event, delegationLifecycleNotifier, "runtask.onDelegationLifecycle");
49
+ deliverDelegationLifecycle(runner.deps.onDelegationLifecycle, event, delegationLifecycleNotifier, "runtask.onDelegationLifecycle", runner.deps.onNotice);
52
50
  };
53
51
  if (emitsChildRowFrames(prepared.hookIdentity) && prepared.hookIdentity.legKind !== "resume") {
54
52
  const started = taskStartedFrame({ taskId: runSourceTaskId, sessionId: prepared.sessionId, model: prepared.model.id, identity: prepared.hookIdentity }, internals, ident());
@@ -87,7 +85,17 @@ export function runIdentityWiring(input) {
87
85
  deliverEngineNotice(runner.deps.onNotice, notice);
88
86
  }
89
87
  };
90
- prepared.harness.onUndrainedOtherInputs = (authors) => runner.deps.onError?.(droppedInputsDisclosure(authors), { phase: "degraded", sessionId: prepared.sessionId, classification: "undelivered-input-dropped" });
88
+ prepared.harness.onUndrainedOtherInputs = (authors) => {
89
+ runner.deps.onError?.(droppedInputsDisclosure(authors), { phase: "degraded", sessionId: prepared.sessionId, classification: "undelivered-input-dropped" });
90
+ const notice = droppedInputsNotice(authors, { ...prepared.legNotice.route.address, ...legNoticeTaskId(prepared), runId: prepared.runId });
91
+ const digest = announceDigest(notice.code, prepared.sessionId);
92
+ const record = prepared.announcedListingsRef;
93
+ if (record.advisories?.includes(digest) === true)
94
+ return;
95
+ deliverEngineNotice(runner.deps.onNotice, notice, prepared.legNotice.admission);
96
+ record.advisories = withAnnounceDigests(record.advisories, [digest]);
97
+ prepared.frameReceipts.listingSnapshotOwed = true;
98
+ };
91
99
  prepared.harness.onEngineNoteConsumed = (p) => {
92
100
  const payload = p;
93
101
  const peer = payload?.peer;
@@ -152,6 +160,6 @@ export function runIdentityWiring(input) {
152
160
  }
153
161
  const loopLatch = { ended: false, userInterrupted: false, userHalted: false, callerStop: mintCallerStopGate(spec.signal) };
154
162
  onReady({ harness: prepared.harness, abortController: prepared.abortController, loop: loopLatch, reminderMark: prepared.reminderMark, sessionId: prepared.sessionId, runId: prepared.runId, hookIdentity: prepared.hookIdentity, modBus: prepared.modBus, permissionMode: prepared.permissionMode });
155
- const stats = { turns: 0, tokens: 0, toolCalls: 0, promptTokens: 0, totalInputTokens: 0, cachedTokens: 0, cacheWriteTokens: 0, cacheWriteTokensLong: 0, outputTokens: 0, costMicroUsd: 0 };
163
+ const stats = { turns: 0, tokens: 0, toolCalls: 0, promptTokens: 0, totalInputTokens: 0, cachedTokens: 0, cacheWriteTokens: 0, cacheWriteTokensLong: 0, outputTokens: 0, costMicroUsd: 0, apiDurationMs: 0 };
156
164
  return { runSourceTaskId, parentToolCallId, ident, emitDelegationLifecycle, loopLatch, stats, internalsNotifier, offerLegFrame, undrainedUserAtEnd: { get current() { return undrainedUserAtEnd; } }, userInputLostAtEnd: { get current() { return userInputLostAtEnd; } } };
157
165
  }
@@ -6,7 +6,7 @@ import { CheckpointError, planReviewRequesterOf, readPendingSteerQueue, realAppr
6
6
  import { normalizePersistedRuleHit } from "../rule-lane-reads.js";
7
7
  import { decidersNote, SETTLEMENT_NOBODY_JUDGED } from "../gate-outcome.js";
8
8
  import { formatHookFeedback } from "../hooks.js";
9
- import { classicEventBase, failedHandlerClause, legEventsOf, legNoticeTaskId, openSubagent, screenUserPrompt, seatHears } from "../mods/stations.js";
9
+ import { classicEventBase, failedHandlerClause, legEventsOf, legNoticeTaskId, observePermissionDenied, openSubagent, screenUserPrompt, seatHears } from "../mods/stations.js";
10
10
  import { raiseSessionEnd, raiseSessionStart } from "../mods/lifecycle-stations.js";
11
11
  import { offeredAgentListing } from "../mods/agent-stations.js";
12
12
  import { appendAdmittedRow } from "../row-admission.js";
@@ -45,7 +45,7 @@ import { approvalWordsOf, owedApprovalWords, withApprovalWords } from "./approva
45
45
  import { chainCannotJudge } from "./call-hook-stations.js";
46
46
  import { settleExecutionRecord } from "./execution-record.js";
47
47
  import { holdPrompt } from "./prompt-block.js";
48
- import { frozenInputSnapshot } from "./gate-exit.js";
48
+ import { frozenInputSnapshot, permissionDeniedOf } from "./gate-exit.js";
49
49
  import { withGateTimeout } from "../gate-bounded-await.js";
50
50
  import { readStationAnswer } from "../shell-read-silence.js";
51
51
  import { resolveGitLegDelivery, wrapGitFrame } from "./git-leg-delivery.js";
@@ -55,6 +55,7 @@ import { isBareHumanRefusal, maybeHumanRejectionHalt } from "./prepare-gate-stat
55
55
  import { nextHumanInputSeq } from "./steer-admission.js";
56
56
  import { usableInputId } from "../user-row-origin.js";
57
57
  import { settleTeardownLeg } from "./teardown-bounded.js";
58
+ import { runAbortedError } from "../terminal-cause.js";
58
59
  import { announceToolCall, emitSettled, toolResultMsg } from "./tool-end-body.js";
59
60
  import { rowDetailsOf, withRowNotExecuted } from "./tool-not-executed.js";
60
61
  import { announceListingTruncation } from "../skill-listing-budget.js";
@@ -81,11 +82,8 @@ export async function runLeg(input) {
81
82
  const starting = raiseSessionStart(prepared.modBus, prepared.hookIdentity, { cwd: prepared.cwdRef?.current ?? prepared.taskRootPath, sessionId: prepared.sessionId }, prepared.abortController.signal);
82
83
  if (starting !== undefined)
83
84
  await starting;
84
- if (prepared.abortController.signal.aborted) {
85
- const e = new Error("run aborted");
86
- e.name = "AbortError";
87
- throw e;
88
- }
85
+ if (prepared.abortController.signal.aborted)
86
+ throw runAbortedError();
89
87
  if (resume) {
90
88
  const walltimeExhaustedResume = effectiveTimeoutMs !== undefined && effectiveTimeoutMs <= 0;
91
89
  const approvalWords = approvalWordsOf(resume.outcome);
@@ -728,13 +726,12 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
728
726
  const occurrences = prepared.toolOccurrences;
729
727
  const callStart = { toolCallId: pendingAction.toolCallId, spelledName, wireName: pendingAction.toolName, ...pendingLabel, args: resolvedArgs, ...(resume.cp.checkpointId !== undefined ? { resumesCheckpoint: resume.cp.checkpointId } : {}) };
730
728
  announceToolCall(occurrences, callStart, { push: emit });
731
- occurrences.gateRound(pendingAction.toolCallId, decidedGate, frozenInputSnapshot(resolvedArgs));
729
+ const decidedInput = frozenInputSnapshot(resolvedArgs);
730
+ occurrences.gateRound(pendingAction.toolCallId, decidedGate, decidedInput);
732
731
  let notExecuted = false;
733
732
  const resultRow = (text, isError) => withRowNotExecuted(toolResultMsg(pendingAction.toolCallId, pendingAction.toolName, text, isError), notExecuted);
734
- const settleEnd = async (isError, result, refusedBy, neverRan, facts) => {
735
- if (refusedBy !== undefined)
736
- occurrences.refuse(pendingAction.toolCallId, refusedBy, facts);
737
- const settled = emitSettled(occurrences, callStart, { result, isError, ...(neverRan ? { notExecuted: true } : {}) }, { push: emit, structured: prepared.structuredProjector, mediaBudgetBase64Chars: runner.deps.mediaBudgetBase64Chars });
733
+ const settleEnd = async (isError, result, neverRan) => {
734
+ const settled = emitSettled(occurrences, callStart, { result, isError, ...(neverRan ? { notExecuted: true } : {}) }, { push: emit, structured: prepared.structuredProjector, mediaBudgetBase64Chars: runner.deps.mediaBudgetBase64Chars, reviewRequest: prepared.reviewRequestRef });
738
735
  notExecuted = settled.notExecuted === true;
739
736
  const gate = settled.gate ?? decidedGate;
740
737
  const word = await resume.recordExecutionOutcome(gate);
@@ -743,14 +740,17 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
743
740
  const settleUnreadable = async (error, which) => {
744
741
  const marks = egressValue("same-principal", thrownMarksOf(error));
745
742
  const text = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: the tool could not read ${which} — its argument preparation failed (${egressThrownText("same-principal", error)}). This approval is spent — the call has to be re-issued.`, prepared.reminderMark);
746
- await settleEnd(true, { content: text, ...(marks !== undefined ? { details: marks } : {}) }, undefined, true);
743
+ await settleEnd(true, { content: text, ...(marks !== undefined ? { details: marks } : {}) }, true);
747
744
  emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(text, true)), "toolResult", pendingAction.toolCallId);
748
745
  };
749
- const vetoApproval = async (miss) => {
750
- const text = formatHookFeedback(miss.message, prepared.reminderMark);
751
- await settleEnd(true, { content: text, ...(miss.code !== undefined ? { details: { code: miss.code } } : {}) }, "policy");
746
+ const refuseCall = async (sentence, by, card = {}) => {
747
+ const gate = by === undefined ? decidedGate : occurrences.refuse(pendingAction.toolCallId, by.layer, by.facts);
748
+ await observePermissionDenied({ legBus: prepared.modBus, payload: permissionDeniedOf({ toolName: pendingAction.toolName, finalInput: decidedInput, toolCallId: pendingAction.toolCallId, reason: sentence, gate, identity: prepared.hookIdentity, permissionMode: prepared.permissionMode.observed }), signal: prepared.abortController.signal });
749
+ const text = formatHookFeedback(sentence, prepared.reminderMark);
750
+ await settleEnd(true, { content: text, ...card });
752
751
  emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(text, true)), "toolResult", pendingAction.toolCallId);
753
752
  };
753
+ const vetoApproval = (miss) => refuseCall(miss.message, { layer: "policy" }, miss.code !== undefined ? { details: { code: miss.code } } : {});
754
754
  if (outcome.decision === "deny") {
755
755
  const settlementKind = outcome.gateOutcome?.settlement?.kind;
756
756
  const reason = settlementKind === "policy_refused"
@@ -760,9 +760,7 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
760
760
  ? delimitUntrusted("reviewer note", outcome.reason, REVIEWER_NOTE_MAX_BODY)
761
761
  : `No one answered the approval request for the pending tool call "${pendingAction.toolName}" — the approval window elapsed with no answer, so it was not executed.`
762
762
  : humanRefusalSentence("tool use", outcome.reason, prepared.hookIdentity.isDelegatedChild);
763
- await settleEnd(true, { content: formatHookFeedback(reason, prepared.reminderMark) });
764
- const eid = await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(formatHookFeedback(reason, prepared.reminderMark), true));
765
- emitCommitted(eid, "toolResult", pendingAction.toolCallId);
763
+ await refuseCall(reason);
766
764
  const parkedFallback = pendingAction.denialLimitFallback;
767
765
  if (parkedFallback !== undefined && settlementKind !== undefined && SETTLEMENT_NOBODY_JUDGED[settlementKind]) {
768
766
  prepared.stopForDenialLimit({ toolName: pendingAction.toolName, toolCallId: pendingAction.toolCallId, fallback: parkedFallback, settlement: settlementKind });
@@ -777,23 +775,15 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
777
775
  if (decided.unread !== undefined)
778
776
  return settleUnreadable(decided.unread.error, humanRewrite !== undefined ? "the arguments the decision edited it to" : "its arguments");
779
777
  const screened = await prepared.approvedCallScreen?.({ toolCallId: pendingAction.toolCallId, toolName: pendingAction.toolName, args: structuredClone(resolvedArgs), answered });
780
- if (screened !== undefined && "refused" in screened) {
781
- const hookDenial = formatHookFeedback(screened.refused, prepared.reminderMark);
782
- await settleEnd(true, { content: hookDenial }, "hook", undefined, screened.extension !== undefined ? { extension: screened.extension } : undefined);
783
- emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(hookDenial, true)), "toolResult", pendingAction.toolCallId);
784
- return;
785
- }
778
+ if (screened !== undefined && "refused" in screened)
779
+ return refuseCall(screened.refused, { layer: "hook", facts: screened.extension !== undefined ? { extension: screened.extension } : undefined });
786
780
  const executedArgs = resolvedArgs;
787
781
  const unseen = !licenseCovers(pendingAction.boundInputHash, pendingAction.toolName, executedArgs);
788
782
  let beltReading;
789
783
  const beltReq = () => ({ toolName: pendingAction.toolName, args: executedArgs, toolCallId: pendingAction.toolCallId, ...callFactsSeat({ face: beltFace(), budget: beltBudget, cwd: prepared.cwdRef?.current, root: prepared.handsRoot, advertisedWritableDirs: prepared.advertisedWritableDirs, exemptRoots: prepared.exemptRoots }), ...(beltReading !== undefined ? { targetReading: beltReading } : {}), ...requestGrantBinding((call, args) => skillGrantBindingMembers(call, args, prepared.skillSpecs, SKILL_TOOL_NAME), pendingAction, executedArgs) });
790
784
  const unjudgeable = unseen ? chainCannotJudge(resume.cp.state.inheritedGate) : undefined;
791
- if (unjudgeable !== undefined) {
792
- const chainDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: its input changed after the approval and the inherited ancestor chain cannot judge the changed input (${unjudgeable}). This approval is spent — the call has to be re-issued.`, prepared.reminderMark);
793
- await settleEnd(true, { content: chainDenial }, "policy");
794
- emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(chainDenial, true)), "toolResult", pendingAction.toolCallId);
795
- return;
796
- }
785
+ if (unjudgeable !== undefined)
786
+ return refuseCall(`The approved tool call "${pendingAction.toolName}" was not executed: its input changed after the approval and the inherited ancestor chain cannot judge the changed input (${unjudgeable}). This approval is spent — the call has to be re-issued.`, { layer: "policy" });
797
787
  const beltBudget = {
798
788
  resourceRemainingMicroUsd: remainingBudgetMicroUsd(prepared.resourceLedger),
799
789
  resourceSpentMicroUsd: prepared.resourceLedger?.spentMicroUsd ?? 0,
@@ -823,21 +813,14 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
823
813
  : personUnanswered
824
814
  ? " (the call as it would run raises a question that requires a person's approval, and no person answered that question for this call; send the call again to have it asked)"
825
815
  : " (the policy rewrote these bytes to a value that was not approved)";
826
- const editedDenial = formatHookFeedback(`The approver EDITED this call's input; the edited call is refused by the deployment's tool policy and was not executed${why}.`, prepared.reminderMark);
827
816
  const outlet = rechecked.action !== "deny" && !personUnanswered && rewrite?.unread === undefined && rewrite !== undefined ? { details: { editRewritten: { acceptableForm: rewrite.args } } } : denialCard(rechecked);
828
- await settleEnd(true, { content: editedDenial, ...outlet }, "policy");
829
- emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(editedDenial, true)), "toolResult", pendingAction.toolCallId);
830
- return;
817
+ return refuseCall(`The approver EDITED this call's input; the edited call is refused by the deployment's tool policy and was not executed${why}.`, { layer: "policy" }, outlet);
831
818
  }
832
819
  }
833
820
  const gateRealApproval = resume.cp.gate.kind === "irreversible_ask" ? resume.cp.gate.realApproval : undefined;
834
821
  const gateOrgGoverned = realApprovalOrgFact(gateRealApproval) !== undefined;
835
822
  if (gateOrgGoverned && prepared.permissionRuleOrg === undefined) {
836
- const unwiredDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: its approval was minted under organization governance (${gateRealApproval.origin}), and this worker has no org adjudication wiring — a governed approval may only be redeemed where governance can be enforced. This approval is spent; re-issue the call on an org-wired worker.`, prepared.reminderMark);
837
- await settleEnd(true, { content: unwiredDenial }, "org");
838
- const eid = await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(unwiredDenial, true));
839
- emitCommitted(eid, "toolResult", pendingAction.toolCallId);
840
- return;
823
+ return refuseCall(`The approved tool call "${pendingAction.toolName}" was not executed: its approval was minted under organization governance (${gateRealApproval.origin}), and this worker has no org adjudication wiring — a governed approval may only be redeemed where governance can be enforced. This approval is spent; re-issue the call on an org-wired worker.`, { layer: "org" });
841
824
  }
842
825
  if (prepared.permissionRuleOrg !== undefined) {
843
826
  const orgVerdict = prepared.permissionRuleOrg
@@ -867,30 +850,18 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
867
850
  const orgDisclosures = org.status === "unavailable" && org.disclosures.length > 0
868
851
  ? ` Governance disclosures: ${inlineUntrusted(org.disclosures.join("; "), ORG_DISCLOSURE_MAX_CHARS)}.`
869
852
  : "";
870
- const orgDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: ${blocked}.${orgDisclosures} This approval is spent — the call has to be re-issued and ${unanswered ? "decided by a person" : "approved again once organization policy permits it"}.`, prepared.reminderMark);
871
- await settleEnd(true, { content: orgDenial }, "org");
872
- const eid = await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(orgDenial, true));
873
- emitCommitted(eid, "toolResult", pendingAction.toolCallId);
874
- return;
853
+ return refuseCall(`The approved tool call "${pendingAction.toolName}" was not executed: ${blocked}.${orgDisclosures} This approval is spent — the call has to be re-issued and ${unanswered ? "decided by a person" : "approved again once organization policy permits it"}.`, { layer: "org" });
875
854
  }
876
855
  }
877
856
  if (prepared.denyNarrowingPolicy) {
878
857
  const narrowed = refuseOutOfContractDecision(await beltCheck((signal) => prepared.denyNarrowingPolicy.check(beltReq(), signal), "the narrowing rules re-checking a resumed call"));
879
858
  if (narrowed.action === "deny") {
880
- const narrowedDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" is now denied by ${ruleSourcePhrase("narrowing")} and was not executed${narrowed.message ? `: ${narrowed.message}` : ""}.`, prepared.reminderMark);
881
- await settleEnd(true, { content: narrowedDenial, ...denialCard(narrowed) }, "policy");
882
- const eid = await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(narrowedDenial, true));
883
- emitCommitted(eid, "toolResult", pendingAction.toolCallId);
884
- return;
859
+ return refuseCall(`The approved tool call "${pendingAction.toolName}" is now denied by ${ruleSourcePhrase("narrowing")} and was not executed${narrowed.message ? `: ${narrowed.message}` : ""}.`, { layer: "policy" }, denialCard(narrowed));
885
860
  }
886
861
  }
887
862
  const skillRefusal = skillRowRefusal(prepared.skillGrants, beltReq());
888
- if (skillRefusal !== undefined) {
889
- const skillDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: ${skillRefusal.message}. This approval is spent — the call has to be re-issued.`, prepared.reminderMark);
890
- await settleEnd(true, { content: skillDenial }, "policy");
891
- emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(skillDenial, true)), "toolResult", pendingAction.toolCallId);
892
- return;
893
- }
863
+ if (skillRefusal !== undefined)
864
+ return refuseCall(`The approved tool call "${pendingAction.toolName}" was not executed: ${skillRefusal.message}. This approval is spent — the call has to be re-issued.`, { layer: "policy" });
894
865
  if (prepared.persistedRuleLane !== undefined) {
895
866
  const unreadable = { unreadable: true };
896
867
  let laneWaitCancelled = false;
@@ -909,11 +880,7 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
909
880
  : tightened.tightened === "deny"
910
881
  ? `a standing deny rule of yours (${disclosedRuleSet(read.hit?.rules ?? [])}) now refuses it`
911
882
  : `it could not be read against your standing deny/ask rules (${read.reason})`;
912
- const ruleDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: ${why}. This approval is spent — the call has to be re-issued and approved again.`, prepared.reminderMark);
913
- await settleEnd(true, { content: ruleDenial, ...denialCard(tightened.decision) }, "persisted_rule");
914
- const eid = await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(ruleDenial, true));
915
- emitCommitted(eid, "toolResult", pendingAction.toolCallId);
916
- return;
883
+ return refuseCall(`The approved tool call "${pendingAction.toolName}" was not executed: ${why}. This approval is spent — the call has to be re-issued and approved again.`, { layer: "persisted_rule" }, denialCard(tightened.decision));
917
884
  }
918
885
  }
919
886
  if (prepared.shellReadCheck !== undefined) {
@@ -932,11 +899,7 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
932
899
  }
933
900
  const reading = readStationAnswer(verdict, { toolName: pendingAction.toolName, toolCallId: pendingAction.toolCallId });
934
901
  if (reading.kind === "refuse" || reading.kind === "silence" || (unseen && reading.kind !== "vouch")) {
935
- const readDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: ${reading.verdict.sentence ?? "the read boundary does not vouch for what it reads on this leg"} This approval is spent — the call has to be re-issued and approved again.`, prepared.reminderMark);
936
- await settleEnd(true, { content: readDenial, ...(reading.verdict.details !== undefined ? { details: reading.verdict.details } : {}) }, "read_boundary", undefined, reading.verdict.echoed !== undefined ? { echoed: reading.verdict.echoed } : undefined);
937
- const eid = await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(readDenial, true));
938
- emitCommitted(eid, "toolResult", pendingAction.toolCallId);
939
- return;
902
+ return refuseCall(`The approved tool call "${pendingAction.toolName}" was not executed: ${reading.verdict.sentence ?? "the read boundary does not vouch for what it reads on this leg"} This approval is spent — the call has to be re-issued and approved again.`, { layer: "read_boundary", facts: reading.verdict.echoed !== undefined ? { echoed: reading.verdict.echoed } : undefined }, reading.verdict.details !== undefined ? { details: reading.verdict.details } : {});
940
903
  }
941
904
  reading.verdict.admit?.();
942
905
  }
@@ -952,12 +915,8 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
952
915
  tool = mounted().tool;
953
916
  const waited = prepared.crossBoundary?.storeWaits() ?? 0;
954
917
  const crossBoundaryRefusal = await prepared.crossBoundary?.check?.exit({ toolName: pendingAction.toolName, args: executedArgs, toolCallId: pendingAction.toolCallId }, answered);
955
- if (crossBoundaryRefusal !== undefined) {
956
- const text = formatHookFeedback(crossBoundaryRefusal.message, prepared.reminderMark);
957
- await settleEnd(true, { content: text }, "policy");
958
- emitCommitted(await appendAdmittedRow(prepared.admitRows, prepared.session, resultRow(text, true)), "toolResult", pendingAction.toolCallId);
959
- return;
960
- }
918
+ if (crossBoundaryRefusal !== undefined)
919
+ return refuseCall(crossBoundaryRefusal.message, { layer: "policy" });
961
920
  if ((prepared.crossBoundary?.storeWaits() ?? 0) === waited)
962
921
  break;
963
922
  }
@@ -5,6 +5,7 @@ import { DeliveryObligations, type NotificationInjectionOutcome, type PendingSes
5
5
  import type { RunnerDeps, TaskEvent, TaskSpec } from "../types.js";
6
6
  import type { SessionReadFileStates } from "./session-read-file-states.js";
7
7
  import type { SessionModeSeats } from "./session-mode-seats.js";
8
+ import type { SessionMcpPools } from "../mcp-connection-pool.js";
8
9
  import type { NotificationLaneBindings, Prepared, PrepareTaskFn, ResumeRun, RunInternals, RunnerDepsSeat, RunnerSelfSeat, TaskIdRef } from "./contracts.js";
9
10
  export interface RunNotificationLaneInput<R> {
10
11
  /** borrowed-readonly — the task spec: prepare's input, and the isolation scope the peer scope is minted from. */
@@ -36,6 +37,8 @@ export interface RunNotificationLaneInput<R> {
36
37
  sessionReadStates: SessionReadFileStates;
37
38
  /** borrowed-mutable — the Runner's per-session permission-mode seats, ALWAYS this Runner's (a caller-supplied one is overridden). */
38
39
  sessionModeSeats: SessionModeSeats;
40
+ /** borrowed-mutable — the per-session MCP pools of this Runner's session store, ALWAYS (as the two above). */
41
+ sessionMcpPools: SessionMcpPools;
39
42
  /** borrowed-mutable — the Runner's per-session parked-notification store: the torn-down lane and the escalation pend here. */
40
43
  pendingSessionNotifications: PendingSessionNotifications;
41
44
  /** borrowed-readonly — the orchestrator's entry (a lane may not name the orchestrator; the driver hands it in), as the ONE
@@ -1,4 +1,3 @@
1
- import { recordedSyncChildBlock } from "../leg-identity.js";
2
1
  import { createPeerInboundChainRef, createPeerSelfRef } from "../../agents/peer-admission.js";
3
2
  import { boundInputHashOf } from "../canonical-json.js";
4
3
  import { readPendingSteerQueue } from "../checkpoint-store.js";
@@ -15,14 +14,13 @@ export function runNotificationLane(input) {
15
14
  return obligations.run(() => runNotificationLaneAs(input, obligations));
16
15
  }
17
16
  async function runNotificationLaneAs(input, obligations) {
18
- const { spec, queue, resume, internals, taskIdRef, holdSessionLock, legWrites, promptSubmitRef, runner, self, sessions, sessionReadStates, sessionModeSeats, pendingSessionNotifications, prepareTask, next } = input;
17
+ const { spec, queue, resume, internals, taskIdRef, holdSessionLock, legWrites, promptSubmitRef, runner, self, sessions, sessionReadStates, sessionModeSeats, sessionMcpPools, pendingSessionNotifications, prepareTask, next } = input;
19
18
  const prepareResume = resume
20
19
  ? {
21
20
  leafId: resume.cp.leafId,
22
21
  ...(resume.cp.heldRows !== undefined ? { heldRows: [...resume.cp.heldRows] } : {}),
23
22
  suspendedBatch: new Set(resume.cp.pendingAction.kind === "tool_approval" ? resume.cp.pendingAction.batchToolCallIds : []),
24
23
  seed: resume.cp.state,
25
- ...((recorded) => (recorded !== undefined ? { syncChildBlockOfRow: recorded } : {}))(recordedSyncChildBlock(resume.cp)),
26
24
  outcome: resume.outcome,
27
25
  ...((opening) => (opening !== undefined ? { opening } : {}))(resume.outcome.gate === "wake" ? wakeOpening(readPendingSteerQueue(resume.cp.state), resume.wakeMessage) : undefined),
28
26
  ...(resume.legMods !== undefined ? { legMods: resume.legMods } : {}),
@@ -151,7 +149,7 @@ async function runNotificationLaneAs(input, obligations) {
151
149
  peerInboundChainRef,
152
150
  detachHub,
153
151
  sessionReadStates,
154
- sessionModeSeats,
152
+ sessionModeSeats, sessionMcpPools,
155
153
  onTaskNotification: laneSink,
156
154
  }, self, taskIdRef, holdSessionLock, legWrites, (destination, delivery) => pendingSessionNotifications.discardsStaleNotice(destination, delivery), promptSubmitRef);
157
155
  try {
@@ -2,10 +2,9 @@
2
2
  * The run body's REASONING seat (R5), verbatim from `Runner.runLocked`: the leg-entry resolution of
3
3
  * the requested reasoning intensity against the model's real capability, the ONE publisher that writes both faces
4
4
  * (the `reasoning.resolved` trace frame and the `TaskResult.effectiveReasoning` seat on the backstop carrier), and
5
- * the wire-facts consumer that lets the leg's FIRST committed request correct the cap-blind mint (once; foreign
6
- * reports are contained at their call sites, not here).
5
+ * the reader that lets the leg's first request with a terminal message correct the entry value (once).
7
6
  */
8
- import { type ReasoningWireFacts, type ResolvedReasoning } from "../../brain/reasoning.js";
7
+ import type { ResolvedReasoning } from "../../brain/reasoning.js";
9
8
  import type { Prepared, RunState, TaskIdRef } from "./contracts.js";
10
9
  export interface RunReasoningSeatInput {
11
10
  /** borrowed-readonly — the leg's prepared seat: the requested thinking level and the model. */
@@ -16,10 +15,10 @@ export interface RunReasoningSeatInput {
16
15
  taskIdRef: TaskIdRef | undefined;
17
16
  }
18
17
  export interface RunReasoningSeatResult {
19
- /** The CONSUMPTION half of {@link ReasoningWireFacts} — installed as the third brain ALS sink. */
20
- observeReasoningWireFacts: (facts: ReasoningWireFacts) => void;
18
+ /** Read one `message_end` message of the leg's harness — the git lane's subscription hands every one here. */
19
+ observeReasoningMessage: (message: unknown) => void;
21
20
  /** The leg's resolution as a READ FACE over this lane's own `let` (the leg-entry mint, then at most one
22
- * first-committed-request correction): the settle lane's result assembly reads it for `effectiveReasoning`. */
21
+ * first-request correction): the settle lane's result assembly reads it for `effectiveReasoning`. */
23
22
  reasoningResolution: {
24
23
  readonly current: ResolvedReasoning | undefined;
25
24
  };
@@ -1,8 +1,10 @@
1
- import { resolveReasoning } from "../../brain/reasoning.js";
1
+ import { resolutionOf, resolveReasoning } from "../../brain/reasoning-request.js";
2
+ import { reasoningStampOf } from "../../brain/reasoning-stamp.js";
2
3
  import { emitTrace } from "../trace.js";
4
+ import { isDeepStrictEqual } from "node:util";
3
5
  export function runReasoningSeat(input) {
4
6
  const { prepared, rs, taskIdRef } = input;
5
- let reasoningResolution = prepared.thinking && prepared.thinking !== "off" ? resolveReasoning(prepared.thinking, prepared.model) : undefined;
7
+ let reasoningResolution = prepared.thinking !== undefined ? resolveReasoning(prepared.thinking, prepared.model) : undefined;
6
8
  const publishReasoningResolution = (r) => {
7
9
  reasoningResolution = r;
8
10
  if (taskIdRef)
@@ -24,25 +26,18 @@ export function runReasoningSeat(input) {
24
26
  };
25
27
  if (reasoningResolution !== undefined)
26
28
  publishReasoningResolution(reasoningResolution);
27
- let reasoningFactsConsumed = false;
28
- const observeReasoningWireFacts = (facts) => {
29
- if (reasoningFactsConsumed)
29
+ let corrected = false;
30
+ const observeReasoningMessage = (message) => {
31
+ if (corrected || reasoningResolution === undefined)
30
32
  return;
31
- reasoningFactsConsumed = true;
32
- if (prepared.thinking === undefined || prepared.thinking === "off")
33
+ const stamp = reasoningStampOf(message);
34
+ if (stamp === undefined || stamp.model !== prepared.model)
33
35
  return;
34
- const next = resolveReasoning(prepared.thinking, prepared.model, facts);
35
- const current = reasoningResolution;
36
- if (current !== undefined &&
37
- current.effective === next.effective &&
38
- current.graded === next.graded &&
39
- current.clamped === next.clamped &&
40
- current.format === next.format &&
41
- current.endpoint === next.endpoint &&
42
- current.dropped === next.dropped) {
36
+ corrected = true;
37
+ const next = resolutionOf(stamp.level, stamp.carried, prepared.model.api ?? "unknown");
38
+ if (isDeepStrictEqual(next, reasoningResolution))
43
39
  return;
44
- }
45
40
  publishReasoningResolution(next);
46
41
  };
47
- return { observeReasoningWireFacts, reasoningResolution: { get current() { return reasoningResolution; } } };
42
+ return { observeReasoningMessage, reasoningResolution: { get current() { return reasoningResolution; } } };
48
43
  }
@@ -17,11 +17,11 @@ import { deliverEngineNotice, parentLegIds, settleOwedUserInput } from "../types
17
17
  import { assembleResult } from "./assemble-result.js";
18
18
  import { discloseUnconsumedEndings } from "./halt-attribution.js";
19
19
  import { forwardSafely } from "./forward-sink.js";
20
- import { TIMER_LATENESS_REPORT_MS } from "./clock-and-limits.js";
20
+ import { completedPastLimitNotice, limitCrossedOf, TIMER_LATENESS_REPORT_MS } from "./clock-and-limits.js";
21
21
  import { resumeDecisionWasNegative } from "./decide-continuation.js";
22
22
  import { drainForwardedFramesBeforeDone, forwardsSubagentEvents } from "./prepare-run-refs.js";
23
23
  import { generatePromptSuggestions } from "./prompt-suggestions.js";
24
- import { TeardownLegTimeoutError, raceTeardownLeg, settleTeardownLeg, teardownLegBudget } from "./teardown-bounded.js";
24
+ import { raceTeardownLegOr, settleTeardownLeg, teardownLegBudget } from "./teardown-bounded.js";
25
25
  import { owedDateAnchor } from "./conversation-segment.js";
26
26
  import { autoRunConsolidationFromRecommendation, autoRunOnRecommendationEffective, scopeHasUnconsumedRecommendation } from "./memory-consolidation-driver.js";
27
27
  import { amendTerminal, terminalProjection } from "./terminal-projection.js";
@@ -107,6 +107,7 @@ export async function runSettleAndTeardown(input) {
107
107
  intake: taskIdRef?.intake,
108
108
  ...(displayed !== undefined ? { displayed } : {}),
109
109
  strandedHumanAnswers,
110
+ refusedAsks: prepared.refusedAsks,
110
111
  remoteEnvFailures: prepared.remoteEnvFailures,
111
112
  effectiveReadFace: prepared.effectiveReadFace,
112
113
  effectiveWriteFace: prepared.effectiveWriteFace,
@@ -120,6 +121,7 @@ export async function runSettleAndTeardown(input) {
120
121
  abortedForTurns: rs.limits.turnsExceeded,
121
122
  abortedLive,
122
123
  answerSettled,
124
+ limitCrossed: limitCrossedOf({ limits: rs.limits, budget: rs.budget, stats, walltimeLimitMs: spec.limits?.maxWalltimeMs, walltimeTimerFired: timeout.fired, elapsedMs: Math.ceil(performance.now() - rs.telemetry.taskStartMonotonic) }),
123
125
  budgetHit: rs.limits.budgetHit,
124
126
  budgetAxis: rs.limits.budgetAxis,
125
127
  blockedReason: prepared.blockedRef.reason,
@@ -144,6 +146,8 @@ export async function runSettleAndTeardown(input) {
144
146
  },
145
147
  });
146
148
  }
149
+ if (result.limitCrossed !== undefined)
150
+ deliverEngineNotice(runner.deps.onNotice, completedPastLimitNotice(result.limitCrossed, { sessionId: prepared.sessionId, runId: rs.telemetry.runId, ...legNoticeTaskId(prepared) }));
147
151
  discloseUnconsumedEndings({ accepted: loopLatch.userHalted, consumption: prepared.harness.haltConsumption(), onNotice: runner.deps.onNotice, sessionId: prepared.sessionId, runId: rs.telemetry.runId, taskId: prepared.taskId });
148
152
  let rowReturned = false;
149
153
  if (resume !== undefined &&
@@ -154,7 +158,7 @@ export async function runSettleAndTeardown(input) {
154
158
  const reopenReason = reopenReasonOf(resumeStartupCauseOf(result.terminal.kind === "failed" ? result.terminal.code : undefined));
155
159
  const row = await compensateUnstarted(resume.reopenUnstarted, reopenReason, resume.claimedRowPending);
156
160
  rowReturned = row.kind === "reopened";
157
- amendTerminal(result, rowReturned ? "resume.reopened_unstarted" : "resume.reopen_failed_unstarted", row.kind, (m) => `${m ?? "the resume leg did not complete"} — ${unstartedRowSentence(row)}`);
161
+ amendTerminal(result, rowReturned ? "resume.reopened_unstarted" : "resume.reopen_failed_unstarted", row.kind, (m) => `${m ?? "the resume leg did not complete"} — ${unstartedRowSentence(row, resume.cp)}`);
158
162
  }
159
163
  settleOwedUserInput(owedUserInput, rowReturned, { taskId: prepared.taskId, sessionId: prepared.sessionId, runId: prepared.runId, parent: parentLegIds(internals) }, runner.deps.onNotice);
160
164
  prepared.sealReadStateSeat?.(ownCommittedTailRef.current);
@@ -231,7 +235,11 @@ export async function runSettleAndTeardown(input) {
231
235
  const mes = prepared.memoryEngineSession;
232
236
  await settleTeardownLeg(() => mes.harvest(), "memoryEngineSession.harvest (settle leg)", (e) => runner.deps.onError?.(e, { phase: "config", sessionId: prepared.sessionId }));
233
237
  const scope = mes.handle.writeScope;
234
- if (scope !== null && autoRunOnRecommendationEffective(runner.deps) && (await scopeHasUnconsumedRecommendation(mes.engine, scope))) {
238
+ const gateOwed = scope !== null && autoRunOnRecommendationEffective(runner.deps) && (await raceTeardownLegOr(() => scopeHasUnconsumedRecommendation(mes.engine, scope), "memory consolidation gate read (settle leg)", (timeout) => {
239
+ runner.deps.onError?.(timeout, { phase: "config", sessionId: prepared.sessionId });
240
+ return false;
241
+ }));
242
+ if (scope !== null && gateOwed) {
235
243
  const compliance = { postureOf: runner.deps.compliancePostureResolver, scopeContract: mes.scopeContract, denies: spec.complianceAdditionalDenies };
236
244
  void autoRunConsolidationFromRecommendation({ deps: runner.deps, engine: mes.engine, scope, sessionId: prepared.sessionId, writeJudge: prepared.consolidationWriteJudge, compliance, onNotice: runner.deps.onNotice, onError: runner.deps.onError });
237
245
  }
@@ -351,11 +359,7 @@ async function yieldParkedLegBackground(prepared, runner) {
351
359
  `${report.notYieldable.map((u) => `${u.id} (${u.reason})`).join(", ")} — they were not parked and do not continue with it.`);
352
360
  }
353
361
  const budgetMs = teardownLegBudget();
354
- const drained = await raceTeardownLeg(() => report.drained(), "parked leg's background agents").catch((e) => {
355
- if (e instanceof TeardownLegTimeoutError)
356
- return undefined;
357
- throw e;
358
- });
362
+ const drained = await raceTeardownLegOr(() => report.drained(), "parked leg's background agents", () => undefined);
359
363
  if (drained !== undefined) {
360
364
  if (drained.unpersisted.length > 0)
361
365
  disclose(`the rows of ${drained.unpersisted.length} background agent(s) this parked leg yielded were not written (${drained.unpersisted.join(", ")}): the store refused the write; it is retried, and until it lands those rows read their previous state.`);
@@ -15,6 +15,7 @@ import { emitSettled, reconciledEnd } from "./tool-end-body.js";
15
15
  import { isApprovalWordsFrame } from "./approval-feedback.js";
16
16
  import { asThrownError } from "../thrown-value.js";
17
17
  import { modelLaneBrainOf } from "./model-lane-seat.js";
18
+ import { raceTeardownLeg } from "./teardown-bounded.js";
18
19
  export async function runTerminalAdoption(input) {
19
20
  const { spec, queue, prepared, rs, stats, ident, emitCommitted, startedToolCallIds, toolLabels, timeout, compactionBrain, compactionBreaker, windowSafetyOptions, undrainedUserAtEnd, userInputLostAtEnd, final, abortedLive, userInterruptedLive, callerStop, runner, sessions, next } = input;
20
21
  let { threw } = input;
@@ -47,7 +48,7 @@ export async function runTerminalAdoption(input) {
47
48
  const report = await reconcileInterruptedSession(prepared.session, prepared.toolEffects, undefined, startedToolCallIds, prepared.admitRows);
48
49
  orphansClosed = report.recovered.length;
49
50
  for (const orphan of report.recovered) {
50
- emitSettled(prepared.toolOccurrences, { toolCallId: orphan.toolCallId, spelledName: orphan.toolName, ...(toolLabels.has(orphan.toolName) ? { label: toolLabels.get(orphan.toolName) } : {}), args: orphan.args }, reconciledEnd(orphan), { push: (f) => queue.push({ ...f, ...ident() }), structured: prepared.structuredProjector, mediaBudgetBase64Chars: runner.deps.mediaBudgetBase64Chars });
51
+ emitSettled(prepared.toolOccurrences, { toolCallId: orphan.toolCallId, spelledName: orphan.toolName, ...(toolLabels.has(orphan.toolName) ? { label: toolLabels.get(orphan.toolName) } : {}), args: orphan.args }, reconciledEnd(orphan), { push: (f) => queue.push({ ...f, ...ident() }), structured: prepared.structuredProjector, mediaBudgetBase64Chars: runner.deps.mediaBudgetBase64Chars, reviewRequest: prepared.reviewRequestRef });
51
52
  emitCommitted(orphan.entryId, "toolResult", orphan.toolCallId);
52
53
  }
53
54
  reconcileComplete = true;
@@ -107,7 +108,7 @@ export async function runTerminalAdoption(input) {
107
108
  ];
108
109
  for (const { input, live, approval } of owed) {
109
110
  try {
110
- if (!(await store.setPendingSteer(parkToken, parkScope, input)))
111
+ if (!(await raceTeardownLeg(() => store.setPendingSteer(parkToken, parkScope, input), "checkpointStore.setPendingSteer (parked-input migration leg)")))
111
112
  break;
112
113
  if (live !== undefined)
113
114
  carried.push(live);
@@ -219,12 +220,7 @@ async function finish(spec, prepared, opts, runner, sessions) {
219
220
  }
220
221
  }
221
222
  }
222
- try {
223
- await sessions.touch(prepared.sessionId);
224
- }
225
- catch (err) {
226
- runner.deps.onError?.(err, { phase: "config", sessionId: prepared.sessionId });
227
- }
223
+ await raceTeardownLeg(() => sessions.touch(prepared.sessionId), "sessions.touch (settle leg)").catch((err) => runner.deps.onError?.(err, { phase: "config", sessionId: prepared.sessionId }));
228
224
  try {
229
225
  await prepared.mcp.dispose();
230
226
  }
@@ -146,6 +146,8 @@ export function createTurnBoundary(input) {
146
146
  return undefined;
147
147
  }
148
148
  const axisCrossed = taskAxisCrossed(rs.limits, walltimeMonotonicDeadline);
149
+ if (rs.limits.walltimeCrossedMs === undefined && walltimeMonotonicDeadline !== undefined && performance.now() >= walltimeMonotonicDeadline)
150
+ rs.limits.walltimeCrossedMs = Math.ceil(performance.now() - rs.telemetry.taskStartMonotonic);
149
151
  const taskAxisHit = axisCrossed && legOwesTurn();
150
152
  if (axisCrossed)
151
153
  legContinues = false;
@@ -223,14 +225,15 @@ export function createTurnBoundary(input) {
223
225
  };
224
226
  }
225
227
  }
226
- if (prepared.reviewRequestRef.pending !== undefined) {
227
- const { reason, requestedByCallId } = prepared.reviewRequestRef.pending;
228
+ const pendingReview = prepared.reviewRequestRef.pending;
229
+ if (pendingReview !== undefined) {
228
230
  prepared.reviewRequestRef.pending = undefined;
231
+ prepared.reviewRequestRef.later = undefined;
229
232
  const honorable = prepared.suspendForReview !== undefined &&
230
233
  !prepared.abortController.signal.aborted &&
231
234
  prepared.pausedRef.current === undefined;
232
235
  if (honorable && prepared.suspendForReview) {
233
- await prepared.suspendForReview(reason, requestedByCallId);
236
+ await prepared.suspendForReview(pendingReview);
234
237
  legContinues &&= !prepared.abortController.signal.aborted && prepared.pausedRef.current === undefined;
235
238
  return undefined;
236
239
  }
@@ -4,6 +4,7 @@ import { type TaskOutcome } from "../task-outcome.js";
4
4
  import { type SwappableDeps } from "../swappable-deps.js";
5
5
  import { type SideQuerySpec, type SideQueryResult } from "../side-query.js";
6
6
  import type { SessionStore } from "../session.js";
7
+ import { type ForgetMcpFailureRequest, type ForgetMcpFailureResult } from "../mcp-connection-pool.js";
7
8
  import { type SessionAddress, type SessionCompletionLane, type TaskNotificationSink } from "../task-notification.js";
8
9
  import type { AgentDefinition, EngineNotice, ModelRef, ModelRoles, RunnerDeps, TaskEvent, TaskResult, TaskSpec, TaskStream } from "../types.js";
9
10
  import { type ContextSettings, type ContextWindowOverlay } from "../context-settings.js";
@@ -32,6 +33,8 @@ export declare class Runner implements RunnerSelfSeat {
32
33
  * evicted) falls back to the transcript-replay rung. See {@link SessionReadFileStates}. */
33
34
  private readonly sessionReadStates;
34
35
  private readonly sessionModeSeats;
36
+ /** The MCP pools of the sessions of {@link sessions} — the STORE's (shared by every Runner over it): one pool per session, remembering a failed connection attempt ({@link sessionMcpPoolsOf}). */
37
+ private readonly sessionMcpPools;
35
38
  /** task notifications born BETWEEN turns (run torn down / harness already idle), parked
36
39
  * per session and drained into the session's next run at its first boundary. Runner-lived (outlives any
37
40
  * single run, like the registry handles that produce into it); bounded + drop-disclosing, see
@@ -153,6 +156,8 @@ export declare class Runner implements RunnerSelfSeat {
153
156
  rewindFiles(request: RewindFilesRequest): Promise<RewindFilesResult>;
154
157
  /** The out-of-run manual compaction, no run and no user turn — the contract is {@link compactIdleSession}'s (the one pass every lane runs; refused while a leg of this Runner holds or awaits the session's lock, or a write issued to it has not settled, and while the session is parked at a pending checkpoint). */
155
158
  compactSession(request: CompactSessionRequest): Promise<CompactSessionResult>;
159
+ /** The out-of-run recovery of an MCP server: the session forgets its failed connection attempt at `server`, so its next message dials it (nothing is dialed now; no lock, no session entry — {@link forgetSessionMcpFailure}). In a live run, `TaskStream.reconnectMcpServer` dials now. */
160
+ forgetMcpFailure(request: ForgetMcpFailureRequest): ForgetMcpFailureResult;
156
161
  /** Run a task and stream live events; await `.result()` for the final TaskResult. `resume` (internal)
157
162
  * drives a durable resume through the same loop instead of a fresh objective prompt.
158
163
  * `internals` (internal) is a TRUSTED run-scoped channel for live per-task state the
@@ -218,10 +223,10 @@ export declare class Runner implements RunnerSelfSeat {
218
223
  * `already_resolved` (lost the CAS — idempotent no-op), `walltime_axis_retired` (pre-CAS: the
219
224
  * persisted ledger carries the retired wall-clock budget axis — a worker of the previous release can
220
225
  * still finish it), `resume_aborted` (the caller's signal was already aborted at entry, or aborted
221
- * during the resume — pre-CAS/edit-re-adjudication legs leave the checkpoint pending and resumable,
222
- * the post-claim leg leaves it consumed; the message says which), `reopen_failed` (an aborted resume
223
- * needed to reopen the checkpoint and the store refused, or the reopen failed in flight — the message
224
- * distinguishes terminally-consumed from state-unprovable), `config_refused` (pre-CAS: the re-supplied
226
+ * during the resume — before the claim the checkpoint stays pending; after it, `detail.unstartedRow: "reopened"` says the claim was
227
+ * reversed (pending again), and without it the code does not say which state the row is in — read it), `reopen_failed` (an aborted
228
+ * resume could not prove its claim reversed — `detail.unstartedRow` is `"declined"` (the store refused: read the row) or `"unknown"`
229
+ * (the reopen failed in flight: state unprovable)), `config_refused` (pre-CAS: the re-supplied
225
230
  * config or a mode the row recorded is one prepare would refuse — `detail.code` is prepare's own code,
226
231
  * `detail.field` says whether the config or the row carries it; the checkpoint stays pending and
227
232
  * unchanged). Each code's full contract is on {@link CheckpointError.code}.