@sema-agent/core 7.67.2 → 7.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (505) hide show
  1. package/CHANGELOG.md +1533 -0
  2. package/README.md +18 -9
  3. package/README.zh-CN.md +16 -8
  4. package/dist/agents/agent-definition.d.ts +1 -1
  5. package/dist/agents/agent-definition.js +4 -1
  6. package/dist/agents/cascade.d.ts +2 -2
  7. package/dist/agents/cascade.js +3 -1
  8. package/dist/agents/cumulative-stats.d.ts +2 -1
  9. package/dist/agents/cumulative-stats.js +4 -1
  10. package/dist/agents/list-agents-tool.d.ts +30 -0
  11. package/dist/agents/list-agents-tool.js +45 -3
  12. package/dist/agents/peer-admission.d.ts +2 -2
  13. package/dist/agents/peer-session-drain.d.ts +2 -0
  14. package/dist/agents/peer-session-drain.js +1 -0
  15. package/dist/agents/repair-loop.js +3 -1
  16. package/dist/agents/retain-ledger.d.ts +61 -8
  17. package/dist/agents/retain-ledger.js +25 -3
  18. package/dist/agents/roster-store.d.ts +4 -2
  19. package/dist/agents/send-message-tool.d.ts +1 -1
  20. package/dist/agents/send-message-tool.js +20 -15
  21. package/dist/agents/subagent-steps.js +2 -10
  22. package/dist/agents/subagent.d.ts +3 -0
  23. package/dist/agents/subagent.js +106 -76
  24. package/dist/agents/tool-filter.d.ts +20 -11
  25. package/dist/agents/tool-filter.js +8 -4
  26. package/dist/agents/verify.d.ts +3 -1
  27. package/dist/agents/verify.js +2 -0
  28. package/dist/brain/anthropic.js +4 -4
  29. package/dist/brain/errors.d.ts +20 -0
  30. package/dist/brain/errors.js +114 -0
  31. package/dist/brain/open-responses.js +3 -1
  32. package/dist/brain/openai.js +3 -1
  33. package/dist/brain/provider-message.d.ts +5 -3
  34. package/dist/brain/provider-message.js +35 -8
  35. package/dist/brain/reasoning-request.d.ts +73 -19
  36. package/dist/brain/reasoning-request.js +164 -72
  37. package/dist/brain/reasoning-stamp.d.ts +26 -0
  38. package/dist/brain/reasoning-stamp.js +10 -0
  39. package/dist/brain/reasoning.d.ts +95 -162
  40. package/dist/brain/reasoning.js +31 -86
  41. package/dist/brain/route-adjudicator.d.ts +9 -7
  42. package/dist/brain/route-adjudicator.js +12 -10
  43. package/dist/brain/status-sink.d.ts +19 -64
  44. package/dist/brain/status-sink.js +5 -21
  45. package/dist/brain/stream-engine.d.ts +11 -2
  46. package/dist/brain/stream-engine.js +10 -0
  47. package/dist/core/a2a.d.ts +17 -5
  48. package/dist/core/a2a.js +11 -3
  49. package/dist/core/allow-entry.d.ts +35 -15
  50. package/dist/core/allow-entry.js +47 -60
  51. package/dist/core/ask-headline.d.ts +68 -0
  52. package/dist/core/ask-headline.js +23 -0
  53. package/dist/core/ask-origin.d.ts +36 -8
  54. package/dist/core/ask-origin.js +17 -10
  55. package/dist/core/ask-question.d.ts +34 -7
  56. package/dist/core/ask-question.js +10 -1
  57. package/dist/core/ask-unresolvable-notice.d.ts +7 -0
  58. package/dist/core/ask-unresolvable-notice.js +9 -3
  59. package/dist/core/auto-strip.d.ts +53 -0
  60. package/dist/core/auto-strip.js +76 -0
  61. package/dist/core/background-agent-store.d.ts +45 -5
  62. package/dist/core/background-agent-store.js +69 -15
  63. package/dist/core/background-shell.d.ts +2 -2
  64. package/dist/core/caller-text.js +2 -2
  65. package/dist/core/canonical-json.d.ts +13 -0
  66. package/dist/core/canonical-json.js +7 -0
  67. package/dist/core/checkpoint-features.d.ts +66 -20
  68. package/dist/core/checkpoint-features.js +12 -1
  69. package/dist/core/checkpoint-generation.d.ts +1 -1
  70. package/dist/core/checkpoint-queries.d.ts +1 -1
  71. package/dist/core/checkpoint-queries.js +4 -1
  72. package/dist/core/checkpoint-requirements.d.ts +25 -1
  73. package/dist/core/checkpoint-requirements.js +5 -1
  74. package/dist/core/checkpoint-row-verdict.d.ts +1 -0
  75. package/dist/core/checkpoint-row-verdict.js +4 -0
  76. package/dist/core/checkpoint-store.d.ts +66 -38
  77. package/dist/core/checkpoint-store.js +15 -6
  78. package/dist/core/child-clamp-seats.d.ts +6 -0
  79. package/dist/core/child-clamp-seats.js +1 -0
  80. package/dist/core/config-refusal-codes.d.ts +1 -1
  81. package/dist/core/config-refusal-codes.js +1 -0
  82. package/dist/core/delegation-frames.d.ts +9 -12
  83. package/dist/core/delegation-frames.js +9 -8
  84. package/dist/core/engine-capabilities.d.ts +21 -8
  85. package/dist/core/engine-capabilities.js +1 -1
  86. package/dist/core/engine-notice.d.ts +147 -34
  87. package/dist/core/engine-notice.js +27 -16
  88. package/dist/core/engine-storage-backend.d.ts +2 -1
  89. package/dist/core/env-budget.js +3 -3
  90. package/dist/core/env-knob-announce.d.ts +10 -10
  91. package/dist/core/env-knob-announce.js +3 -6
  92. package/dist/core/file-history-store.d.ts +29 -4
  93. package/dist/core/file-history-store.js +13 -0
  94. package/dist/core/frame-settlement.d.ts +2 -1
  95. package/dist/core/gate-fold.js +1 -1
  96. package/dist/core/gate-lanes.js +56 -49
  97. package/dist/core/governance-codes.d.ts +39 -3
  98. package/dist/core/governance-codes.js +61 -3
  99. package/dist/core/hooks.d.ts +29 -11
  100. package/dist/core/hooks.js +5 -2
  101. package/dist/core/human-input-projection.js +3 -3
  102. package/dist/core/input-author.d.ts +17 -3
  103. package/dist/core/input-author.js +15 -3
  104. package/dist/core/leg-identity.d.ts +10 -28
  105. package/dist/core/leg-identity.js +1 -21
  106. package/dist/core/lsp.d.ts +18 -13
  107. package/dist/core/lsp.js +30 -22
  108. package/dist/core/mailbox-store.d.ts +1 -1
  109. package/dist/core/mailbox-store.js +4 -4
  110. package/dist/core/mcp-connection-pool.d.ts +93 -4
  111. package/dist/core/mcp-connection-pool.js +104 -1
  112. package/dist/core/mcp-failure.d.ts +38 -12
  113. package/dist/core/mcp-failure.js +9 -13
  114. package/dist/core/mcp-probe.d.ts +4 -3
  115. package/dist/core/mcp-server-link.d.ts +4 -2
  116. package/dist/core/mcp-server-link.js +4 -5
  117. package/dist/core/mcp-server-spec.d.ts +3 -3
  118. package/dist/core/mcp-server-unavailable-notice.d.ts +22 -8
  119. package/dist/core/mcp-server-unavailable-notice.js +18 -4
  120. package/dist/core/mcp.d.ts +40 -6
  121. package/dist/core/mcp.js +39 -13
  122. package/dist/core/memory-engine/content-origin.js +2 -2
  123. package/dist/core/memory-engine/control-objects.d.ts +2 -4
  124. package/dist/core/memory-engine/control-objects.js +2 -10
  125. package/dist/core/memory-engine/delegation-settlement.js +6 -1
  126. package/dist/core/memory-engine/dual-root.js +3 -0
  127. package/dist/core/memory-engine/engine.d.ts +6 -4
  128. package/dist/core/memory-engine/engine.js +32 -29
  129. package/dist/core/memory-engine/file-backend.d.ts +20 -5
  130. package/dist/core/memory-engine/file-backend.js +21 -31
  131. package/dist/core/memory-engine/frontmatter.d.ts +2 -0
  132. package/dist/core/memory-engine/frontmatter.js +4 -0
  133. package/dist/core/memory-engine/layout.d.ts +114 -20
  134. package/dist/core/memory-engine/layout.js +340 -22
  135. package/dist/core/memory-engine/memory-deployment.d.ts +7 -5
  136. package/dist/core/memory-engine/mount-failed-notice.d.ts +19 -7
  137. package/dist/core/memory-engine/mount-failed-notice.js +43 -10
  138. package/dist/core/memory-engine/sync-client.js +4 -5
  139. package/dist/core/model-fallbacks.d.ts +5 -1
  140. package/dist/core/model-fallbacks.js +3 -3
  141. package/dist/core/model-receipt.d.ts +2 -1
  142. package/dist/core/model-receipt.js +12 -1
  143. package/dist/core/mods/kernel/dispatch.d.ts +2 -2
  144. package/dist/core/mods/kernel/dispatch.js +14 -6
  145. package/dist/core/mods/kernel/events.d.ts +8 -5
  146. package/dist/core/mods/kernel/events.js +2 -2
  147. package/dist/core/mods/kernel/index.d.ts +1 -1
  148. package/dist/core/mods/kernel/registration.d.ts +9 -0
  149. package/dist/core/mods/package.js +1 -1
  150. package/dist/core/mods/session-append.d.ts +4 -2
  151. package/dist/core/mods/session-append.js +3 -0
  152. package/dist/core/mods/stations.d.ts +7 -11
  153. package/dist/core/mods/stations.js +4 -7
  154. package/dist/core/mods/tool-call.d.ts +10 -8
  155. package/dist/core/mods/tool-call.js +15 -18
  156. package/dist/core/mounted-mcp.d.ts +0 -4
  157. package/dist/core/mounted-mcp.js +1 -1
  158. package/dist/core/park-noun.d.ts +24 -0
  159. package/dist/core/park-noun.js +21 -0
  160. package/dist/core/park-resumability.d.ts +60 -0
  161. package/dist/core/park-resumability.js +30 -0
  162. package/dist/core/permission-rule-provider.d.ts +24 -2
  163. package/dist/core/permission-rule-provider.js +11 -8
  164. package/dist/core/permission-rule-store.d.ts +8 -1
  165. package/dist/core/permission-rule-store.js +2 -3
  166. package/dist/core/permission-rules.d.ts +2 -1
  167. package/dist/core/permission-rules.js +8 -4
  168. package/dist/core/persisted-rule-arms.d.ts +3 -0
  169. package/dist/core/persisted-rule-arms.js +2 -1
  170. package/dist/core/present-plan-tool.d.ts +47 -3
  171. package/dist/core/present-plan-tool.js +62 -4
  172. package/dist/core/principal-name.d.ts +1 -1
  173. package/dist/core/principal-name.js +5 -5
  174. package/dist/core/process-identity.js +10 -5
  175. package/dist/core/protocol-http-auth.d.ts +30 -9
  176. package/dist/core/protocol-http-auth.js +113 -59
  177. package/dist/core/read-only-shell.js +9 -5
  178. package/dist/core/redaction-marks.d.ts +4 -26
  179. package/dist/core/redaction-marks.js +9 -21
  180. package/dist/core/remote-env.d.ts +43 -16
  181. package/dist/core/remote-env.js +1 -1
  182. package/dist/core/request-copy-projection.d.ts +1 -1
  183. package/dist/core/request-copy-projection.js +40 -50
  184. package/dist/core/resume-config-judge.js +1 -1
  185. package/dist/core/resume-startup-cause.d.ts +35 -18
  186. package/dist/core/resume-startup-cause.js +13 -10
  187. package/dist/core/retention.d.ts +167 -25
  188. package/dist/core/retention.js +100 -20
  189. package/dist/core/roles.d.ts +6 -0
  190. package/dist/core/roles.js +11 -5
  191. package/dist/core/rule-lane-reads.d.ts +3 -0
  192. package/dist/core/rule-lane-reads.js +5 -1
  193. package/dist/core/rule-store-fault.d.ts +70 -0
  194. package/dist/core/rule-store-fault.js +102 -0
  195. package/dist/core/runner/advertised-writable-dirs.js +16 -31
  196. package/dist/core/runner/announce-once-ledger.d.ts +19 -2
  197. package/dist/core/runner/announce-once-ledger.js +24 -2
  198. package/dist/core/runner/assemble-result.d.ts +6 -0
  199. package/dist/core/runner/assemble-result.js +1 -1
  200. package/dist/core/runner/auto-strip-notice.d.ts +36 -0
  201. package/dist/core/runner/auto-strip-notice.js +59 -0
  202. package/dist/core/runner/branch-window.d.ts +3 -0
  203. package/dist/core/runner/branch-window.js +37 -0
  204. package/dist/core/runner/caller-roster.d.ts +8 -3
  205. package/dist/core/runner/capability-withheld-seat.js +3 -9
  206. package/dist/core/runner/clock-and-limits.d.ts +22 -1
  207. package/dist/core/runner/clock-and-limits.js +30 -0
  208. package/dist/core/runner/contracts.d.ts +58 -35
  209. package/dist/core/runner/credential-refusal-seat.d.ts +2 -0
  210. package/dist/core/runner/credential-refusal-seat.js +47 -0
  211. package/dist/core/runner/cross-boundary-lane.js +6 -4
  212. package/dist/core/runner/decide-continuation.js +1 -1
  213. package/dist/core/runner/file-history-restore.d.ts +53 -2
  214. package/dist/core/runner/file-history-restore.js +29 -10
  215. package/dist/core/runner/forward-sink.d.ts +14 -1
  216. package/dist/core/runner/forward-sink.js +14 -12
  217. package/dist/core/runner/gate-exit.d.ts +8 -7
  218. package/dist/core/runner/gate-exit.js +13 -13
  219. package/dist/core/runner/git-status-frame.js +2 -4
  220. package/dist/core/runner/initial-run-state.js +1 -1
  221. package/dist/core/runner/main-call-account.d.ts +3 -1
  222. package/dist/core/runner/main-call-account.js +5 -3
  223. package/dist/core/runner/mcp-redial.d.ts +2 -5
  224. package/dist/core/runner/mcp-redial.js +2 -2
  225. package/dist/core/runner/nested-memory-content.d.ts +7 -1
  226. package/dist/core/runner/nested-memory-content.js +73 -13
  227. package/dist/core/runner/nested-memory-lane.d.ts +44 -19
  228. package/dist/core/runner/nested-memory-lane.js +152 -76
  229. package/dist/core/runner/park-commit.js +3 -1
  230. package/dist/core/runner/permission-rule-lanes.d.ts +8 -2
  231. package/dist/core/runner/permission-rule-lanes.js +29 -3
  232. package/dist/core/runner/person-path-rows.d.ts +3 -11
  233. package/dist/core/runner/person-path-rows.js +21 -24
  234. package/dist/core/runner/prepare-acquire-reconcile.js +3 -1
  235. package/dist/core/runner/prepare-artifact.d.ts +1 -1
  236. package/dist/core/runner/prepare-artifact.js +20 -14
  237. package/dist/core/runner/prepare-ask-lane.d.ts +9 -6
  238. package/dist/core/runner/prepare-ask-lane.js +6 -5
  239. package/dist/core/runner/prepare-boundary-parks.d.ts +7 -1
  240. package/dist/core/runner/prepare-boundary-parks.js +27 -24
  241. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -2
  242. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  243. package/dist/core/runner/prepare-config-doors.d.ts +9 -24
  244. package/dist/core/runner/prepare-config-doors.js +58 -41
  245. package/dist/core/runner/prepare-context-lane.d.ts +2 -2
  246. package/dist/core/runner/prepare-context-lane.js +3 -5
  247. package/dist/core/runner/prepare-defer-classify.d.ts +1 -1
  248. package/dist/core/runner/prepare-defer-classify.js +1 -1
  249. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
  250. package/dist/core/runner/prepare-delegation-surface.js +3 -2
  251. package/dist/core/runner/prepare-file-history.d.ts +62 -26
  252. package/dist/core/runner/prepare-file-history.js +117 -46
  253. package/dist/core/runner/prepare-gate-stations.d.ts +4 -0
  254. package/dist/core/runner/prepare-gate-stations.js +6 -5
  255. package/dist/core/runner/prepare-hands-readface.d.ts +9 -4
  256. package/dist/core/runner/prepare-hands-readface.js +8 -4
  257. package/dist/core/runner/prepare-inherited-gate.d.ts +11 -4
  258. package/dist/core/runner/prepare-inherited-gate.js +6 -6
  259. package/dist/core/runner/prepare-listings.d.ts +1 -1
  260. package/dist/core/runner/prepare-listings.js +1 -1
  261. package/dist/core/runner/prepare-memory.js +2 -2
  262. package/dist/core/runner/prepare-offload-wrappers.d.ts +1 -1
  263. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  264. package/dist/core/runner/prepare-park-ask.d.ts +10 -3
  265. package/dist/core/runner/prepare-park-ask.js +7 -9
  266. package/dist/core/runner/prepare-policy-chain.d.ts +18 -9
  267. package/dist/core/runner/prepare-policy-chain.js +18 -13
  268. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  269. package/dist/core/runner/prepare-project-context.js +5 -3
  270. package/dist/core/runner/prepare-prompt-assembly.js +2 -1
  271. package/dist/core/runner/prepare-prompt-inputs.d.ts +2 -2
  272. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  273. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -5
  274. package/dist/core/runner/prepare-protocol-tools.js +7 -7
  275. package/dist/core/runner/prepare-question-face.d.ts +4 -2
  276. package/dist/core/runner/prepare-run-refs.d.ts +7 -2
  277. package/dist/core/runner/prepare-run-refs.js +8 -7
  278. package/dist/core/runner/prepare-safety-scan.d.ts +4 -3
  279. package/dist/core/runner/prepare-suspend-saga.d.ts +3 -7
  280. package/dist/core/runner/prepare-suspend-saga.js +4 -3
  281. package/dist/core/runner/prepare-task.js +66 -53
  282. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +3 -2
  283. package/dist/core/runner/prepare-tool-disclosure-mount.js +2 -1
  284. package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
  285. package/dist/core/runner/prepare-turn-wiring.js +1 -1
  286. package/dist/core/runner/prepare-wiring-manifest.d.ts +9 -4
  287. package/dist/core/runner/prepare-wiring-manifest.js +14 -6
  288. package/dist/core/runner/prepare-workspace-restore.d.ts +4 -4
  289. package/dist/core/runner/prepare-workspace-restore.js +15 -6
  290. package/dist/core/runner/remote-env-retry.d.ts +3 -3
  291. package/dist/core/runner/restore-seat.d.ts +41 -0
  292. package/dist/core/runner/restore-seat.js +38 -0
  293. package/dist/core/runner/resume-admission.js +1 -1
  294. package/dist/core/runner/resume-apply.js +4 -3
  295. package/dist/core/runner/resume-checkpoint-screen.js +2 -1
  296. package/dist/core/runner/resume-internals-and-config.js +2 -1
  297. package/dist/core/runner/resume-preflight.js +2 -1
  298. package/dist/core/runner/rewind-files.js +22 -6
  299. package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -0
  300. package/dist/core/runner/rule-store-unreadable-notice.js +11 -0
  301. package/dist/core/runner/run-brain-sinks.d.ts +3 -6
  302. package/dist/core/runner/run-brain-sinks.js +6 -6
  303. package/dist/core/runner/run-compaction-machinery.d.ts +2 -2
  304. package/dist/core/runner/run-git-lane.d.ts +2 -0
  305. package/dist/core/runner/run-git-lane.js +2 -1
  306. package/dist/core/runner/run-harness-handlers.js +5 -4
  307. package/dist/core/runner/run-identity-wiring.js +20 -12
  308. package/dist/core/runner/run-leg.js +31 -72
  309. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  310. package/dist/core/runner/run-notification-lane.js +2 -4
  311. package/dist/core/runner/run-reasoning-seat.d.ts +5 -6
  312. package/dist/core/runner/run-reasoning-seat.js +13 -18
  313. package/dist/core/runner/run-settle-and-teardown.js +13 -9
  314. package/dist/core/runner/run-terminal-adoption.js +4 -8
  315. package/dist/core/runner/run-turn-boundary.js +6 -3
  316. package/dist/core/runner/runtask.d.ts +9 -4
  317. package/dist/core/runner/runtask.js +29 -22
  318. package/dist/core/runner/session-rule-policy.d.ts +11 -1
  319. package/dist/core/runner/shell-env-withheld.js +2 -7
  320. package/dist/core/runner/side-call-account.d.ts +5 -6
  321. package/dist/core/runner/side-call-account.js +2 -2
  322. package/dist/core/runner/stream-lifecycle-verbs.d.ts +3 -0
  323. package/dist/core/runner/stream-lifecycle-verbs.js +5 -3
  324. package/dist/core/runner/stream-settle-backstop.js +4 -6
  325. package/dist/core/runner/stream-steer-verb.d.ts +1 -1
  326. package/dist/core/runner/stream-steer-verb.js +4 -4
  327. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -3
  328. package/dist/core/runner/sub-agent-deny-lists.js +7 -4
  329. package/dist/core/runner/teardown-bounded.d.ts +7 -0
  330. package/dist/core/runner/teardown-bounded.js +7 -0
  331. package/dist/core/runner/terminal-account.js +41 -13
  332. package/dist/core/runner/terminal-projection.d.ts +1 -5
  333. package/dist/core/runner/tool-end-body.d.ts +9 -3
  334. package/dist/core/runner/tool-end-body.js +6 -3
  335. package/dist/core/runner/tool-output-projection.d.ts +13 -4
  336. package/dist/core/runner/tool-output-projection.js +10 -14
  337. package/dist/core/runner/turn-attachments.d.ts +3 -2
  338. package/dist/core/runner/turn-attachments.js +12 -5
  339. package/dist/core/runner-deps.d.ts +6 -6
  340. package/dist/core/runtime-caps.d.ts +2 -1
  341. package/dist/core/secret-env.d.ts +20 -3
  342. package/dist/core/secret-env.js +13 -15
  343. package/dist/core/session-checkout.d.ts +115 -15
  344. package/dist/core/session-checkout.js +435 -136
  345. package/dist/core/session-policy-store.js +21 -3
  346. package/dist/core/session-reconcile.js +1 -0
  347. package/dist/core/session-store.js +2 -0
  348. package/dist/core/session.d.ts +11 -1
  349. package/dist/core/shell-run-candidates.d.ts +1 -0
  350. package/dist/core/shell-run-candidates.js +1 -1
  351. package/dist/core/shutdown-debug.d.ts +6 -5
  352. package/dist/core/shutdown-debug.js +5 -1
  353. package/dist/core/skill-grant.js +4 -1
  354. package/dist/core/skills-directory.js +5 -3
  355. package/dist/core/spec-contract.d.ts +1 -1
  356. package/dist/core/store-contracts/checkpoint-store-contract.js +2 -7
  357. package/dist/core/store-contracts/file-history-store-contract.js +26 -2
  358. package/dist/core/store-contracts/session-deletion-cascade-contract.js +130 -14
  359. package/dist/core/store-contracts/task-list-store-contract.d.ts +2 -1
  360. package/dist/core/store-contracts/task-list-store-contract.js +28 -1
  361. package/dist/core/task-event.d.ts +48 -27
  362. package/dist/core/task-notification.d.ts +15 -9
  363. package/dist/core/task-notification.js +12 -0
  364. package/dist/core/task-registry-agent.d.ts +24 -22
  365. package/dist/core/task-registry-agent.js +65 -46
  366. package/dist/core/task-registry-shared.d.ts +17 -5
  367. package/dist/core/task-registry.d.ts +17 -6
  368. package/dist/core/task-registry.js +6 -1
  369. package/dist/core/task-result.d.ts +71 -25
  370. package/dist/core/task-spec-members.d.ts +0 -1
  371. package/dist/core/task-spec-members.js +1 -1
  372. package/dist/core/task-spec.d.ts +60 -52
  373. package/dist/core/task-stream.d.ts +45 -12
  374. package/dist/core/terminal-cause.d.ts +45 -8
  375. package/dist/core/terminal-cause.js +5 -0
  376. package/dist/core/tool-card-bound.d.ts +32 -0
  377. package/dist/core/tool-card-bound.js +33 -0
  378. package/dist/core/tool-catalog-entries.d.ts +9 -0
  379. package/dist/core/tool-catalog-entries.js +48 -0
  380. package/dist/core/tool-errors.d.ts +4 -3
  381. package/dist/core/tool-face.d.ts +3 -3
  382. package/dist/core/tool-mount-facts.d.ts +3 -2
  383. package/dist/core/tool-mount-facts.js +1 -1
  384. package/dist/core/tool-mount-static.js +7 -5
  385. package/dist/core/tool-policy.d.ts +21 -19
  386. package/dist/core/tool-policy.js +5 -6
  387. package/dist/core/tool-registry.d.ts +3 -1
  388. package/dist/core/tool-registry.js +15 -1
  389. package/dist/core/tool-result-store.d.ts +9 -3
  390. package/dist/core/tool-result-store.js +14 -1
  391. package/dist/core/tool-roster.d.ts +6 -0
  392. package/dist/core/tool-roster.js +18 -0
  393. package/dist/core/tool-spec.d.ts +17 -8
  394. package/dist/core/trace.d.ts +35 -31
  395. package/dist/core/types.d.ts +2 -2
  396. package/dist/core/untrusted-egress.d.ts +19 -7
  397. package/dist/core/untrusted-egress.js +26 -7
  398. package/dist/core/untrusted-text.d.ts +6 -18
  399. package/dist/core/untrusted-text.js +11 -4
  400. package/dist/core/user-attachment.d.ts +9 -6
  401. package/dist/core/user-attachment.js +12 -10
  402. package/dist/core/user-row-origin.d.ts +44 -25
  403. package/dist/core/user-row-origin.js +30 -20
  404. package/dist/core/wiring-manifest.d.ts +26 -7
  405. package/dist/core/wiring-manifest.js +14 -11
  406. package/dist/core/workspace-snapshot.d.ts +3 -1
  407. package/dist/core/workspace-snapshot.js +1 -0
  408. package/dist/engine/execution-env/node-execution-env.d.ts +23 -16
  409. package/dist/engine/execution-env/node-execution-env.js +127 -67
  410. package/dist/engine/harness/agent-harness.d.ts +4 -5
  411. package/dist/engine/harness/agent-harness.js +2 -7
  412. package/dist/engine/harness/types.d.ts +51 -19
  413. package/dist/engine/harness/types.js +28 -1
  414. package/dist/engine/llm/types.d.ts +26 -14
  415. package/dist/engine/llm/types.js +2 -2
  416. package/dist/engine/loop/agent-loop.d.ts +2 -2
  417. package/dist/engine/loop/agent-loop.js +51 -275
  418. package/dist/engine/loop/types.d.ts +0 -18
  419. package/dist/engine/session/import-validate.d.ts +3 -0
  420. package/dist/engine/session/import-validate.js +34 -2
  421. package/dist/engine/session/repo-utils.d.ts +42 -4
  422. package/dist/engine/session/repo-utils.js +33 -5
  423. package/dist/engine/session/session.d.ts +41 -14
  424. package/dist/engine/session/session.js +96 -25
  425. package/dist/index.d.ts +21 -16
  426. package/dist/index.js +16 -10
  427. package/dist/orchestration/run-spec.d.ts +1 -1
  428. package/dist/orchestration/run-workflow-tool.d.ts +12 -9
  429. package/dist/orchestration/run-workflow-tool.js +15 -19
  430. package/dist/orchestration/workflow-governance.js +13 -21
  431. package/dist/orchestration/workflow-observe.d.ts +4 -3
  432. package/dist/orchestration/workflow-primitives.d.ts +1 -1
  433. package/dist/orchestration/workflow-record-artifact.d.ts +14 -0
  434. package/dist/orchestration/workflow-record-artifact.js +32 -0
  435. package/dist/orchestration/workflow-script-store.d.ts +9 -0
  436. package/dist/orchestration/workflow-script-store.js +20 -1
  437. package/dist/orchestration/workflow-types.d.ts +33 -3
  438. package/dist/orchestration/workflow.d.ts +24 -14
  439. package/dist/orchestration/workflow.js +52 -23
  440. package/dist/prompt-assembly/artifact.js +4 -8
  441. package/dist/prompt-assembly/catalog/engine.d.ts +263 -0
  442. package/dist/prompt-assembly/catalog/engine.js +30 -0
  443. package/dist/prompt-assembly/catalog/index.d.ts +1 -1
  444. package/dist/prompt-assembly/catalog/index.js +2 -2
  445. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +1 -1
  446. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +29 -0
  447. package/dist/prompt-assembly/epoch.js +6 -8
  448. package/dist/prompt-assembly/turn-snapshot.js +8 -9
  449. package/dist/stores/file/background-agent-store.js +5 -6
  450. package/dist/stores/file/checkpoint-store.d.ts +0 -4
  451. package/dist/stores/file/checkpoint-store.js +7 -3
  452. package/dist/stores/file/file-history-store.d.ts +8 -0
  453. package/dist/stores/file/file-history-store.js +72 -0
  454. package/dist/stores/file/fs-atomic.js +17 -12
  455. package/dist/stores/file/index.js +11 -5
  456. package/dist/stores/file/mailbox-store.js +13 -4
  457. package/dist/stores/file/permission-rule-store.js +14 -13
  458. package/dist/stores/file/shared-ledger.d.ts +4 -0
  459. package/dist/stores/file/shared-ledger.js +4 -0
  460. package/dist/stores/file/task-list-store.js +12 -3
  461. package/dist/stores/file/workflow-run-store.js +1 -0
  462. package/dist/tools/fs/bash-program-position.d.ts +4 -2
  463. package/dist/tools/fs/bash-program-position.js +1 -1
  464. package/dist/tools/fs/bash-readonly-classifier.js +1 -1
  465. package/dist/tools/fs/bound-open.d.ts +97 -0
  466. package/dist/tools/fs/bound-open.js +103 -0
  467. package/dist/tools/fs/containment-face.d.ts +2 -2
  468. package/dist/tools/fs/fs-pdf.d.ts +7 -1
  469. package/dist/tools/fs/fs-pdf.js +31 -23
  470. package/dist/tools/fs/fs-read.d.ts +24 -17
  471. package/dist/tools/fs/fs-read.js +84 -53
  472. package/dist/tools/fs/fs-shared.d.ts +14 -12
  473. package/dist/tools/fs/fs-shared.js +5 -4
  474. package/dist/tools/fs/fs-write.d.ts +2 -2
  475. package/dist/tools/fs/fs-write.js +20 -12
  476. package/dist/tools/fs/index.d.ts +4 -4
  477. package/dist/tools/fs/index.js +2 -2
  478. package/dist/tools/fs/notebook.d.ts +1 -1
  479. package/dist/tools/fs/pdf.d.ts +12 -3
  480. package/dist/tools/fs/pdf.js +22 -9
  481. package/dist/tools/fs/read-deny-home.d.ts +3 -2
  482. package/dist/tools/fs/read-deny-home.js +8 -11
  483. package/dist/tools/fs/safety.d.ts +3 -2
  484. package/dist/tools/fs/shell-read-check.js +10 -9
  485. package/dist/tools/monitor.d.ts +6 -5
  486. package/dist/tools/task-list.d.ts +16 -6
  487. package/dist/tools/task-list.js +4 -0
  488. package/dist/tools/web.d.ts +9 -1
  489. package/dist/tools/web.js +8 -3
  490. package/dist/tools/worktree.d.ts +7 -5
  491. package/dist/tools/worktree.js +4 -3
  492. package/package.json +4 -3
  493. package/test/export-surface.snapshot.json +93 -7
  494. package/wire-changes/core-stores-sql@7.67.3.json +39 -0
  495. package/wire-changes/core-stores-sql@7.68.0.json +39 -0
  496. package/wire-changes/core@7.67.3.json +65 -0
  497. package/wire-changes/core@7.68.0.json +4257 -0
  498. package/wire-changes/mods-kernel@7.67.3.json +39 -0
  499. package/wire-changes/mods-kernel@7.68.0.json +129 -0
  500. package/wire-changes/primitives@7.67.3.json +39 -0
  501. package/wire-changes/primitives@7.68.0.json +253 -0
  502. package/wire-changes/wiki-gate@7.67.3.json +39 -0
  503. package/wire-changes/wiki-gate@7.68.0.json +39 -0
  504. package/dist/core/runner/credential-origin-seat.d.ts +0 -2
  505. package/dist/core/runner/credential-origin-seat.js +0 -20
@@ -28,6 +28,7 @@ import type { MaterializedMcp } from "../mcp.js";
28
28
  import type { SessionStore } from "../session.js";
29
29
  import { type ToolResultStore } from "../tool-result-store.js";
30
30
  import { type OnAsk, type ToolPolicy } from "../tool-policy.js";
31
+ import { type ApprovalParkNotResumable } from "../park-resumability.js";
31
32
  import type { RunnerDeps, RuntimeCaps, TaskSpec, ToolEffect, ToolExecuteContext } from "../types.js";
32
33
  import { type LegWriteGuard, type LegWriteProtection } from "./write-protection-station.js";
33
34
  import { type UsageWindow } from "../usage-window-store.js";
@@ -36,12 +37,13 @@ import type { ToolMountPlan } from "../tool-mount-plan.js";
36
37
  import { type AutoModeArmFact, type SuspendLaneReason, type WiringManifest, type WiringManifestMcpEntry } from "../wiring-manifest.js";
37
38
  import { type PermissionModeController } from "../mode-policy.js";
38
39
  import type { AnnounceOnceSink, Prepared, PrepareResume, RunInternals, UsageGovernance } from "./contracts.js";
40
+ import type { RosterSpec } from "./caller-roster.js";
39
41
  export interface PrepareWiringManifestInput {
40
42
  /** borrowed-readonly — the REBOUND spec. Read: `onQuestion` (the question seam), `handsReadOnly` / `tools` (the ungated scan),
41
43
  * `resourceSuspend` (the task-axis lane), `durableApproval` / `principal` (the synthesis and the notice), `interactiveTools` /
42
44
  * `mcp` / `checkpointStore` (manifest cells and the notice's cause), `enablePlanMode` (the gate-machinery predicate's
43
45
  * plan-mode term), `writeProtectedAdditions` (the request's rows of the write-protection table). Never mutated. */
44
- spec: Pick<TaskSpec, "onQuestion" | "handsReadOnly" | "tools" | "resourceSuspend" | "preemptSignal" | "durableApproval" | "principal" | "interactiveTools" | "mcp" | "checkpointStore" | "enablePlanMode" | "peerPresence" | "writeProtectedAdditions">;
46
+ spec: Pick<RosterSpec, "durableApproval"> & Pick<TaskSpec, "onQuestion" | "handsReadOnly" | "tools" | "resourceSuspend" | "preemptSignal" | "principal" | "interactiveTools" | "mcp" | "checkpointStore" | "enablePlanMode" | "peerPresence" | "writeProtectedAdditions">;
45
47
  /** borrowed-readonly — the deployment seats, whole: `onError` (the warning), `executionEnv`
46
48
  * (the hook-env predicate), `checkpointStore` (durable infra), the manifest's dozen wiring facts (`backgroundAgentStore`,
47
49
  * `permissionRuleStore`, `permissionRuleSyncWired`, `onBackgroundChildEvent`, `lockedConfig`, `compliancePostureResolver`,
@@ -184,8 +186,8 @@ export interface PrepareWiringManifestInput {
184
186
  delegation: {
185
187
  isDelegatedChild: boolean;
186
188
  };
187
- /** borrowed-readonly — the driver's one leg fact (`approvalParkNotResumableOf`): the synthesis reads it. */ approvalParkNotResumable: boolean;
188
- /** borrowed-readonly — the driver's refusal fact (the entitlement ∧ a store ∧ `approvalParkNotResumable`): the notice's `leg_not_resumable`. */ forcedGateNotResumable: boolean;
189
+ /** borrowed-readonly — the driver's one leg fact (`approvalParkNotResumableOf`): the synthesis, the park lane's atom and the suspend gap read it. */ approvalParkNotResumable: ApprovalParkNotResumable | undefined;
190
+ /** borrowed-readonly — the driver's refusal fact (the entitlement ∧ `approvalParkNotResumable`, its source word; the store is not a term): the notice's `leg_not_resumable`. */ forcedGateNotResumable: ApprovalParkNotResumable | false | undefined;
189
191
  }
190
192
  export interface PrepareWiringManifestResult {
191
193
  /** owned — the run's own approver seat (spec over deps), read by the gate-fold station. */
@@ -215,7 +217,7 @@ export interface PrepareWiringManifestResult {
215
217
  /** owned — whether the suspend saga must be armed for a PLATFORM cause. */
216
218
  platformSuspendArmed: boolean;
217
219
  /** owned — the effective durable-approval opt-in: the caller's, or the scope synthesized for a forced durable gate. */
218
- durableApproval: TaskSpec["durableApproval"];
220
+ durableApproval: import("../task-spec.js").DurableApprovalOptIn | undefined;
219
221
  /** owned — this leg's EFFECTIVE wiring manifest (`Prepared.wiringManifest`). */
220
222
  wiringManifest: WiringManifest;
221
223
  /** owned — the leg's write judgment: its gate input (`mount.check`, absent when the table was emptied — no tighten
@@ -264,6 +266,9 @@ export interface SuspendInfraGap {
264
266
  */
265
267
  export declare function durableSuspendInfraGaps(facts: {
266
268
  readonly storeWired: boolean;
269
+ /** The leg's one fact says its LANE holds no park of it (source `lane`): no suspend of it is resumed by anyone. The host's word
270
+ * (source `host`) is not a gap here — it speaks for the decision parks only. */
271
+ readonly laneHoldsNoPark: boolean;
267
272
  readonly volatileToolResults: boolean;
268
273
  readonly envGap: {
269
274
  readonly code: Extract<SuspendLaneReason, `env_${string}`>;
@@ -8,6 +8,7 @@ import { toolFieldsOfServer } from "../mounted-mcp.js";
8
8
  import { suspendTargetGapRowOf } from "../remote-env.js";
9
9
  import { isVolatileOffloadStore } from "../tool-result-store.js";
10
10
  import { durableMandateSourceOf, effectiveDurableApprovalOf, isAnsweringSeat } from "../tool-policy.js";
11
+ import { notResumableClause, notResumableWayOut } from "../park-resumability.js";
11
12
  import { deliverEngineNotice } from "../types.js";
12
13
  import { inlineUntrusted } from "../untrusted-text.js";
13
14
  import { mountWriteProtection } from "./write-protection-station.js";
@@ -112,24 +113,27 @@ function liveChainSeatClause(form) {
112
113
  }
113
114
  }
114
115
  }
115
- const LEG_NOT_RESUMABLE_SENTENCE = "Durable approval gate mandated but unavailable: the runtime entitlement forceDurableGate is in force for this principal, but this delegated leg cannot be resumed — its parent forwarded it no durable approval (a synchronous or fork child, or a background child whose lane cannot park) — so no ask of it can be parked for a durable answer, and none is answered in its place: every permission ask is refused without asking anyone and AskUserQuestion is refused (not shown). NO durable approval record is written. Ask from the parent leg itself, delegate the work as a background agent on a lane that can park, or withdraw the entitlement.";
116
+ function legNotResumableSentence(source) {
117
+ return `Durable approval gate mandated but unavailable: the runtime entitlement forceDurableGate is in force for this principal, but this leg cannot be resumed — ${notResumableClause(source)} — so no ask of it can be parked for a durable answer, and none is answered in its place: every permission ask is refused without asking anyone and AskUserQuestion is refused (not shown). NO durable approval record is written. To go on: ${notResumableWayOut(source, true)}; or withdraw the entitlement.`;
118
+ }
116
119
  function announceDurableGateUnavailable(args) {
117
120
  if (args.mandate === undefined || (args.storeWired && !args.notResumable))
118
121
  return;
119
122
  const source = args.mandate;
120
- const cause = args.storeWired ? "leg_not_resumable" : args.taskStoreDisabled ? "task_store_disabled" : "no_deployment_store";
123
+ const notResumable = args.notResumable !== false ? args.notResumable : undefined;
124
+ const cause = notResumable !== undefined ? "leg_not_resumable" : args.taskStoreDisabled ? "task_store_disabled" : "no_deployment_store";
121
125
  const inheritedContentMandate = (args.parentConstraints ?? []).some((pc) => pc.contentMandate === true);
122
- const answersLive = cause !== "leg_not_resumable";
126
+ const answersLive = notResumable === undefined;
123
127
  const liveQuestionFace = args.liveQuestionFace && !inheritedContentMandate && answersLive;
124
128
  deliverEngineNotice(args.onNotice, {
125
129
  code: "config.durable_gate_unavailable",
126
- message: !answersLive ? LEG_NOT_RESUMABLE_SENTENCE :
130
+ message: notResumable !== undefined ? legNotResumableSentence(notResumable) :
127
131
  `Durable approval gate mandated but unavailable: ${source === "force_durable_gate" ? "the runtime entitlement forceDurableGate is in force for this principal" : "this task opted into durable approval (durableApproval) with no live approver seat"}, ` +
128
- `but ${cause === "task_store_disabled" ? 'this task disabled the checkpoint store (checkpointStore: "disabled")' : "this deployment wired no checkpoint store"}, ` +
132
+ `but ${cause === "task_store_disabled" ? 'this task runs with the checkpoint store switched off (checkpointStore: "disabled" — set by the host on the task, or by the engine on a fork child and every leg under it, since nothing resumes a fork)' : "this deployment wired no checkpoint store"}, ` +
129
133
  `so no interactive ask of this task can be parked for a durable answer. Asks resolve on the live chain instead ` +
130
134
  `(${liveChainSeatClause(args.seatForm)}; ` +
131
135
  `${liveQuestionFace ? "a live question face answers AskUserQuestion in-stream" : args.liveQuestionFace ? "AskUserQuestion is withheld from the live face by an inherited durable mandate and refused" : "AskUserQuestion has no live face and is refused"}) ` +
132
- `and NO durable approval record is written. ${cause === "task_store_disabled" ? "Run this task with its store" : "Wire a checkpoint store on this deployment"}, or ${source === "force_durable_gate" ? "withdraw the entitlement for principals served here" : args.declaredNone ? 'run the task where a person can be asked (without approvalReach: "none"), or drop durableApproval' : "give the task a live approver seat (or drop durableApproval)"}.`,
136
+ `and NO durable approval record is written. ${cause === "task_store_disabled" ? 'Run the task with its store (a fork child cannot have one: delegate work that must wait for a person without subagent_type "fork")' : "Wire a checkpoint store on this deployment"}, or ${source === "force_durable_gate" ? "withdraw the entitlement for principals served here" : args.declaredNone ? 'run the task where a person can be asked (without approvalReach: "none"), or drop durableApproval' : "give the task a live approver seat (or drop durableApproval)"}.`,
133
137
  detail: {
134
138
  sessionId: args.sessionId,
135
139
  runId: args.runId,
@@ -145,6 +149,8 @@ export function durableSuspendInfraGaps(facts) {
145
149
  const gaps = [];
146
150
  if (!facts.storeWired)
147
151
  gaps.push({ code: "no_checkpoint_store", why: "no CheckpointStore is wired" });
152
+ if (facts.laneHoldsNoPark)
153
+ gaps.push({ code: "leg_not_resumable", why: notResumableClause("lane") });
148
154
  if (facts.volatileToolResults)
149
155
  gaps.push({ code: "volatile_tool_results", why: "tool-result offload uses the in-memory store (a resume needs durable results)" });
150
156
  if (facts.envGap !== undefined)
@@ -203,6 +209,7 @@ export function prepareWiringManifest(input) {
203
209
  const suspendTargetGap = suspendTargetGapRow?.clause;
204
210
  const suspendInfraGaps = durableSuspendInfraGaps({
205
211
  storeWired: resolveCheckpointStore(spec, deps) !== undefined,
212
+ laneHoldsNoPark: approvalParkNotResumable === "lane",
206
213
  volatileToolResults: offloadStore !== undefined && isVolatileOffloadStore(offloadStore),
207
214
  envGap: suspendTargetGapRow,
208
215
  });
@@ -239,6 +246,7 @@ export function prepareWiringManifest(input) {
239
246
  elicitSeamWired: resolveElicitSeam(deps),
240
247
  elicitServersOptedIn: countElicitOptIns(spec),
241
248
  parkCapable: checkpointStore !== undefined,
249
+ parkLegNotResumable: approvalParkNotResumable !== undefined,
242
250
  parkDurableApprovalOptIn: spec.durableApproval !== undefined,
243
251
  parkForceDurableGate: runtimeCaps?.forceDurableGate === true && durableApproval !== undefined,
244
252
  parkSafetyVocabularyArmed: irreversibleTools.size > 0 || egressTools.size > 0 || shellReadStationArmed,
@@ -5,7 +5,7 @@ import type { PrepareResume, RunInternals } from "./contracts.js";
5
5
  export { remoteEnvFailureNote, restoreWorkspaceWithRetry } from "./remote-env-retry.js";
6
6
  export interface PrepareWorkspaceRestoreInput {
7
7
  /** borrowed-readonly (the ownership-ref PROTOCOL stays with the driver — D-8 案①): the env this
8
- * task owns, when the factory minted one. This phase reads and drives it (`resumeVM`,
8
+ * task owns, when the factory minted one. This phase reads and drives it (`connect` / `resumeVM`,
9
9
  * `postResumeInit`, `canonicalPath`) but NEVER rebinds or destroys it — the detach guard and the
10
10
  * prepare-throw catch are the exception-path owners, both in the driver, and their reference
11
11
  * must stay authoritative (a phase-local rebind could never reach them). */
@@ -14,9 +14,9 @@ export interface PrepareWorkspaceRestoreInput {
14
14
  * object (相 API 规则件 R-4: receiver preserved for `deps.onError?.()`; a new deps read must
15
15
  * widen this Pick). `executionEnv` feeds only the observation sink's remote predicate. */
16
16
  deps: Pick<RunnerDeps, "onError" | "executionEnv">;
17
- /** borrowed-readonly — `signal` only: the caller's cancel signal, composed into the restore's
18
- * abortSignal so a cancel DURING the restore short-circuits it (the live listener is attached
19
- * only after the harness exists). */
17
+ /** borrowed-readonly — `signal` only: the caller's cancel signal, composed into the restore seat's
18
+ * signal so a cancel DURING the establishment call short-circuits it and stops the leg (the live
19
+ * listener is attached only after the harness exists). */
20
20
  spec: Pick<TaskSpec, "signal">;
21
21
  /** borrowed-readonly — the trusted spawn-side seats the observation sink reads: the sink itself
22
22
  * and the isolation REQUEST (by this point past the driver's fail-closed enforcement, so
@@ -1,4 +1,5 @@
1
1
  import { declaredSuspend, frozenHandleCopy, isRemoteExecutionEnv, missingRestoreSurface, pathsAreHostLocal, placementHonored, placementTargetOf } from "../remote-env.js";
2
+ import { connectAtRestoreSeat, establishAtRestoreSeat } from "./restore-seat.js";
2
3
  import { deviceMoveRefusal, settleOwnTarget } from "./placement-fence.js";
3
4
  import { remoteEnvFailureNote, restoreWorkspaceWithRetry } from "./remote-env-retry.js";
4
5
  import { rebaseWorkspacePathAcross } from "./workspace-path.js";
@@ -9,6 +10,10 @@ export async function prepareWorkspaceRestore(input) {
9
10
  let taskRootPath = input.taskRootInitial;
10
11
  let restoredRootRebase;
11
12
  const rebaseRestoredPath = (p) => restoredRootRebase === undefined ? p : rebaseWorkspacePathAcross(p, restoredRootRebase.from, restoredRootRebase.to);
13
+ const restoreSignal = spec.signal ? AbortSignal.any([abortController.signal, spec.signal]) : abortController.signal;
14
+ if (resume?.workspaceHandle === undefined && ownedEnv !== undefined && isRemoteExecutionEnv(ownedEnv)) {
15
+ await connectAtRestoreSeat(ownedEnv, restoreSignal);
16
+ }
12
17
  if (resume?.workspaceHandle !== undefined) {
13
18
  const failResume = (message, cause, note) => {
14
19
  const e = new Error(message, cause ? { cause } : undefined);
@@ -37,19 +42,23 @@ export async function prepareWorkspaceRestore(input) {
37
42
  if (handle.mountPath && handle.mountPath !== taskRootPath) {
38
43
  taskRootPath = handle.mountPath;
39
44
  }
45
+ await connectAtRestoreSeat(ownedEnv, restoreSignal);
40
46
  }
41
47
  else {
42
- const restoreSignal = spec.signal
43
- ? AbortSignal.any([abortController.signal, spec.signal])
44
- : abortController.signal;
45
48
  const missingHere = missingRestoreSurface(ownedEnv);
46
49
  if (missingHere.length > 0) {
47
50
  failResume(`the resumed execution env cannot restore a workspace snapshot: its adapter does not implement ${missingHere.join(" or ")}. The checkpoint holds snapshot "${handle.snapshotId}" — wire an adapter that implements the full RemoteExecutionEnv restore surface and re-resume.`);
48
51
  }
49
52
  refuseIdentityMismatch(ownedEnv.workspaceHandle());
50
- const { outcome: restored, attempts: restoreAttempts } = await restoreWorkspaceWithRetry(ownedEnv, handle.snapshotId, {
51
- abortSignal: restoreSignal,
52
- priorHandle: frozenHandleCopy(handle),
53
+ const snapshotId = handle.snapshotId;
54
+ let restoreAttempts = 0;
55
+ const restored = await establishAtRestoreSeat("resumeVM", restoreSignal, async () => {
56
+ const settled = await restoreWorkspaceWithRetry(ownedEnv, snapshotId, {
57
+ abortSignal: restoreSignal,
58
+ priorHandle: frozenHandleCopy(handle),
59
+ });
60
+ restoreAttempts = settled.attempts;
61
+ return settled.outcome;
53
62
  });
54
63
  if (!restored.ok) {
55
64
  failResume(`resumeVM failed after ${restoreAttempts} attempt(s) (${restored.error.code}): ${envErrorDetail(restored.error.message)}`, restored.error, remoteEnvFailureNote("resumeVM", restored.error, restoreAttempts));
@@ -1,9 +1,9 @@
1
1
  import type { RemoteExecutionEnv, RemoteExecutionError, SnapshotId, VmLifecycleOptions } from "../remote-env.js";
2
2
  import type { RemoteEnvFailureNote } from "../types.js";
3
3
  /**
4
- * Project one failed remote lifecycle call onto the caller-facing note. ONE builder for all
5
- * three ops so the `retryable` classification can never drift between the lane that reports a `suspendVM`
6
- * refusal and the lane that reports a failed restore.
4
+ * Project one failed remote lifecycle call onto the caller-facing note. ONE builder for all three ops so `retryable`
5
+ * never drifts between the `suspendVM` lane and the restore lane — and it reads the table the restore seat reads to
6
+ * decide whether a run starts, so a note never says `retryable` of a code the seat refused standing.
7
7
  */
8
8
  export declare function remoteEnvFailureNote(op: RemoteEnvFailureNote["op"], error: RemoteExecutionError, attempts: number): RemoteEnvFailureNote;
9
9
  /**
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The leg's RESTORE SEAT reading — the one place a leg's own remote environment answers whether the run may start.
3
+ * The workspace-restore phase establishes the env its factory minted for the leg once, before anything else reads it
4
+ * (`resumeVM` on a leg that restores a snapshot, `connect` on every other leg), and hands the call to
5
+ * {@link establishAtRestoreSeat}, which reads the answer in three steps: the run's own cancel stops the leg with the
6
+ * cancelled run's terminal; `ok` answers back; a failure is read through `RETRYABLE_REMOTE_ERROR_CODES` — the run starts
7
+ * past a code the table holds, `unknown` and an `aborted` the run did not cause, and any other code is the environment's
8
+ * standing refusal, which ends the leg here with that code. Machinery the phase reaches DOWN for; it imports no runner module.
9
+ */
10
+ import { RemoteExecutionError } from "../remote-env.js";
11
+ import type { RemoteExecutionEnv, WorkspaceHandle } from "../remote-env.js";
12
+ /** What an establishment call answers (`connect` and `resumeVM` share the shape). */
13
+ export type EstablishAnswer = {
14
+ ok: true;
15
+ value: WorkspaceHandle;
16
+ } | {
17
+ ok: false;
18
+ error: RemoteExecutionError;
19
+ };
20
+ /**
21
+ * THE restore seat's reading of one establishment call, in three steps:
22
+ * ① the run's own cancel — read before the call (a cancelled run establishes nothing) and again once it settled — stops
23
+ * the leg with the run's one cancellation value, the terminal every cancelled run reports;
24
+ * ② `ok` answers back;
25
+ * ③ a failure is read through `RETRYABLE_REMOTE_ERROR_CODES`: a code it holds, `unknown` (it names no fact of the
26
+ * environment, and neither does a code the answer leaves empty or blank) or `aborted` (a cancel the run's own did not
27
+ * cause — ① read that one) answers back to the verb's own
28
+ * reading; any other code is this environment's standing refusal — starting the run past it would only retry it at the
29
+ * first operation — and fails the leg here: the thrown value states no code of its own, so the terminal reads the
30
+ * adapter's through the cause, and it carries no failure note (the terminal IS the code).
31
+ * A call that throws is not read here: the throw passes through as it is (the `connect` arm reads its own throw below).
32
+ */
33
+ export declare function establishAtRestoreSeat<A extends EstablishAnswer>(verb: "connect" | "resumeVM", signal: AbortSignal, call: () => Promise<A>): Promise<A>;
34
+ /**
35
+ * `connect` at the restore seat: called once and never retried — an answer the seat starts the run past is retried by
36
+ * the run's first operation anyway. An answer outside the contract — a throw (an adapter without the method, or one
37
+ * that broke the never-throw contract), or a value that is neither `{ ok: true }` nor `{ ok: false, error }` with a
38
+ * string `error.code` — is no code at all: `unknown`. Every answer short of the seat's two stops starts the run; the
39
+ * handle it answers is not read (the settle point reads the env's own `workspaceHandle()`).
40
+ */
41
+ export declare function connectAtRestoreSeat(env: RemoteExecutionEnv, signal: AbortSignal): Promise<void>;
@@ -0,0 +1,38 @@
1
+ import { isRetryableRemoteErrorCode, RemoteExecutionError } from "../remote-env.js";
2
+ import { runAbortedError } from "../terminal-cause.js";
3
+ import { readMember, thrownText } from "../thrown-value.js";
4
+ import { envErrorDetail } from "../../tools/fs/env-error-detail.js";
5
+ export async function establishAtRestoreSeat(verb, signal, call) {
6
+ if (signal.aborted)
7
+ throw runAbortedError();
8
+ const answer = await call();
9
+ if (signal.aborted)
10
+ throw runAbortedError();
11
+ const settled = answer;
12
+ if (!settled.ok) {
13
+ const { code, message } = settled.error;
14
+ const named = typeof code === "string" && code.trim() !== "";
15
+ if (named && !isRetryableRemoteErrorCode(code) && code !== "unknown" && code !== "aborted") {
16
+ throw new Error(`${verb} refused (${code}): ${envErrorDetail(message)}`, { cause: settled.error });
17
+ }
18
+ }
19
+ return answer;
20
+ }
21
+ export async function connectAtRestoreSeat(env, signal) {
22
+ await establishAtRestoreSeat("connect", signal, async () => {
23
+ try {
24
+ const answer = await env.connect({ abortSignal: signal });
25
+ return isContractAnswer(answer) ? answer : unclassified("answered outside its contract");
26
+ }
27
+ catch (thrown) {
28
+ return unclassified(`threw: ${thrownText(thrown)}`);
29
+ }
30
+ });
31
+ }
32
+ function isContractAnswer(answer) {
33
+ const ok = readMember(answer, "ok");
34
+ return ok === true || (ok === false && typeof readMember(readMember(answer, "error"), "code") === "string");
35
+ }
36
+ function unclassified(what) {
37
+ return { ok: false, error: new RemoteExecutionError("unknown", `the restore seat's connect call ${what}`) };
38
+ }
@@ -58,7 +58,7 @@ export async function resumeAdmission(input) {
58
58
  const outcomeGate = outcome.gate;
59
59
  const resumeSignal = config.signal;
60
60
  let suppliedMessage;
61
- config = refuseResumeDoors(config, runner.deps, sessions, internals?.holder);
61
+ config = refuseResumeDoors(config, runner.deps, sessions, internals);
62
62
  const parkedSteers = readPendingSteerQueue(cp.state);
63
63
  if (outcomeGate === "wake") {
64
64
  suppliedMessage = outcome.message;
@@ -1,5 +1,6 @@
1
1
  import { snapshotActorAssertion } from "../../internal/llm.js";
2
2
  import { CheckpointError, remainingBudgetMicroUsd } from "../checkpoint-store.js";
3
+ import { resumeCancelledSentence } from "../park-noun.js";
3
4
  import { chainPolicyOnLeg, chainTopAnchors } from "./child-tree.js";
4
5
  import { mintHookInvocationIdentity } from "../hooks.js";
5
6
  import { admitLegMods, classicEventBase, failedHandlerClause, promptScreenHasHandlers, screenUserPrompt } from "../mods/stations.js";
@@ -65,7 +66,7 @@ async function applyRungs(input, admitted) {
65
66
  ...(screenedMessage.actor !== undefined ? { actor: snapshotActorAssertion(screenedMessage.actor) } : {}),
66
67
  }, resumeSignal);
67
68
  if (screen?.kind === "aborted") {
68
- throw new CheckpointError("checkpoint.resume_aborted", "the resume was aborted while the deployment's userPromptSubmit hook was still screening this wake message — the checkpoint stays pending and is resumable with a live signal");
69
+ throw new CheckpointError("checkpoint.resume_aborted", resumeCancelledSentence("while this deployment's hook was still checking the wake message", cp));
69
70
  }
70
71
  if (screen?.kind === "failed") {
71
72
  throw new CheckpointError("steering.blocked_by_hook", `the deployment's userPromptSubmit hook ${failedHandlerClause(screen)} while screening this wake message; the resume was refused (fail-closed) and the checkpoint stays pending`);
@@ -89,10 +90,10 @@ async function applyRungs(input, admitted) {
89
90
  if (editSignal === undefined)
90
91
  return p;
91
92
  if (editSignal.aborted) {
92
- throw new CheckpointError("checkpoint.resume_aborted", "the resume was aborted while re-adjudicating the call before the claim — the checkpoint stays pending and is resumable with a live signal");
93
+ throw new CheckpointError("checkpoint.resume_aborted", resumeCancelledSentence("while the call was being checked again", cp));
93
94
  }
94
95
  return new Promise((resolve, reject) => {
95
- const onAbort = () => reject(new CheckpointError("checkpoint.resume_aborted", "the resume was aborted while re-adjudicating the call before the claim — the checkpoint stays pending and is resumable with a live signal"));
96
+ const onAbort = () => reject(new CheckpointError("checkpoint.resume_aborted", resumeCancelledSentence("while the call was being checked again", cp)));
96
97
  editSignal.addEventListener("abort", onAbort, { once: true });
97
98
  p.then((v) => { editSignal.removeEventListener("abort", onAbort); resolve(v); }, (e) => { editSignal.removeEventListener("abort", onAbort); reject(e); });
98
99
  });
@@ -1,4 +1,5 @@
1
1
  import { CheckpointError, realApprovalOrgFact } from "../checkpoint-store.js";
2
+ import { resumeCancelledSentence } from "../park-noun.js";
2
3
  import { constraintChainDigest, constraintChainEntryOfSuppliedLayer } from "../tool-policy.js";
3
4
  import { chainInstallationGaps, chainInstallationRefusal } from "./child-tree.js";
4
5
  import { chainEntryFault } from "../mods/stations.js";
@@ -10,7 +11,7 @@ export function resumeCheckpointScreen(input) {
10
11
  throw new CheckpointError("checkpoint.unsupported_version", `this checkpoint's approval was minted under organization governance (org ${String(realApprovalOrgFact(preCasGateBit))}, routed as ${String(preCasGateBit?.origin)}) and this worker has no org adjudication wiring (its permission-rule store carries no org partition) — a governed approval may only be redeemed where governance can be enforced; the checkpoint stays pending, resume it on an org-wired worker`, { reason: "governed_unwired" });
11
12
  }
12
13
  if (resumeSignal?.aborted === true && cp.status === "pending") {
13
- throw new CheckpointError("checkpoint.resume_aborted", "the resume was handed an ALREADY-ABORTED signal — refusing to consume the approval on a leg that cannot run it (the checkpoint stays pending and is resumable with a live signal)");
14
+ throw new CheckpointError("checkpoint.resume_aborted", resumeCancelledSentence("before it began (the signal it was handed was already cancelled, so it took nothing)", cp));
14
15
  }
15
16
  if (cp.state.workspaceHandle !== undefined && runner.deps.executionEnvFactory === undefined) {
16
17
  throw new CheckpointError("checkpoint.unsupported_version", "checkpoint has a remote workspaceHandle but no RunnerDeps.executionEnvFactory is wired to rebuild the env", { reason: "env_factory_missing" });
@@ -1,4 +1,5 @@
1
1
  import { CheckpointError, readPendingSteerQueue } from "../checkpoint-store.js";
2
+ import { resumeCancelledSentence } from "../park-noun.js";
2
3
  import { GLOBAL_USAGE_KEY, resolveUsageWindows, usageRetryAfterMs } from "../usage-window-store.js";
3
4
  import { compositionLegRecord, placementValueOrAbsent, sameCompositionLeg } from "./checkpoint-scope.js";
4
5
  import { raceSettlementAgainstSignal } from "./abort-race.js";
@@ -68,7 +69,7 @@ export function resumeInternalsAndConfig(input) {
68
69
  const read = usageWindowStore.read(ledgerKey, preCasWindows, Date.now());
69
70
  const raced = resumeSignal === undefined ? undefined : await raceSettlementAgainstSignal(read, resumeSignal);
70
71
  if (raced?.tag === "aborted") {
71
- throw new CheckpointError("checkpoint.resume_aborted", "the resume was aborted while it read the deployment's usage window before the claim — the checkpoint stays pending and is resumable with a live signal");
72
+ throw new CheckpointError("checkpoint.resume_aborted", resumeCancelledSentence("while this deployment's usage limits were being read", cp));
72
73
  }
73
74
  if (raced?.tag === "threw")
74
75
  throw raced.error;
@@ -1,4 +1,5 @@
1
1
  import { CheckpointError } from "../checkpoint-store.js";
2
+ import { resumeCancelledSentence } from "../park-noun.js";
2
3
  import { MAX_TIMER_MS } from "../mods/kernel/index.js";
3
4
  import { frozenHandleCopy } from "../remote-env.js";
4
5
  import { inlineUntrusted } from "../untrusted-text.js";
@@ -72,7 +73,7 @@ export async function resumePreflight(input) {
72
73
  const seat = await boundedPreflight(preflightTimeoutMs, resumeSignal, (sig) => preflight(info, sig));
73
74
  if (seat.expired) {
74
75
  if (seat.cause === "aborted")
75
- throw new CheckpointError("checkpoint.resume_aborted", "the resume was aborted while the deployment's resumePreflight was still screening it — the checkpoint stays pending and is resumable with a live signal");
76
+ throw new CheckpointError("checkpoint.resume_aborted", resumeCancelledSentence("while this deployment's resume check was still running", cp));
76
77
  throw new CheckpointError("resume.preflight_rejected", `the deployment's resumePreflight did not answer within its ${preflightTimeoutMs}ms deadline while screening this resume — refused fail-closed (retry-later arm)${refusalTail}`);
77
78
  }
78
79
  verdict = seat.value;
@@ -1,11 +1,14 @@
1
1
  import { hasDestroy } from "../remote-env.js";
2
2
  import { resolveDeploymentFileHistory, storeUnconfiguredRefusal } from "./file-history-request.js";
3
3
  import { prepareExecutionEnv } from "./prepare-execution-env.js";
4
- import { noBoundaryRefusal, settleFileHistoryRestore } from "./file-history-restore.js";
5
- import { adoptForkedFileHistory, resolveFileHistoryCoordinates } from "./prepare-file-history.js";
4
+ import { noBoundaryRefusal, refuseRestoreOnForkWithOwnTree, refuseTargetOutsideOwnLog, settleFileHistoryRestore } from "./file-history-restore.js";
5
+ import { adoptForkedFileHistory, resolveFileHistoryCoordinates, unaddressedRewindRefusal } from "./prepare-file-history.js";
6
+ import { fileHistoryScopeOf } from "../../engine/session/repo-utils.js";
6
7
  import { createRollbackStack } from "./rollback-stack.js";
7
8
  import { acquireExistingSession, claimIdleSession, readOccupantExpectation, readPlainRequest, shownValue } from "./session-verb-doors.js";
8
9
  import { settleTeardownLeg } from "./teardown-bounded.js";
10
+ import { forkHasOwnTree, recordedRootOf, sessionRootOf } from "../session-checkout.js";
11
+ import { canonicalOrSelf } from "./child-tree.js";
9
12
  const REQUEST_KEYS = new Set(["sessionId", "to", "dryRun", "signal", "expect"]);
10
13
  export async function rewindSessionFiles(seats, request) {
11
14
  const req = screenRewindFilesRequest(request);
@@ -46,19 +49,32 @@ export async function rewindSessionFiles(seats, request) {
46
49
  release();
47
50
  }
48
51
  }
49
- async function rewindOnEnv(req, env, handsEnabled, taskRoot, ctx) {
52
+ async function rewindOnEnv(req, env, handsEnabled, baseRoot, ctx) {
50
53
  if (!handsEnabled)
51
54
  throw filesEnvUnsupportedRefusal(req.sessionId, req.to);
52
- const { historyRoot, historyScope } = await resolveFileHistoryCoordinates(true, env, taskRoot, undefined, req.sessionId);
55
+ await refuseTargetOutsideOwnLog(ctx.session, req.sessionId, req.to, req.dryRun ? "preview" : "restore");
56
+ let row;
57
+ try {
58
+ row = await ctx.session.getMetadata();
59
+ }
60
+ catch {
61
+ throw unaddressedRewindRefusal(req.sessionId, req.to);
62
+ }
63
+ const ownScope = fileHistoryScopeOf(req.sessionId, row.incarnation);
64
+ const at = { env, session: ctx.session, sessionId: req.sessionId, baseRoot };
65
+ const sessionRoot = await sessionRootOf(at, `Runner.rewindFiles: where session "${req.sessionId}"'s files stand cannot be resolved from its checkout (TaskSpec.workspace), so nothing was rewound to entry "${req.to}" — a rewind is never applied to the base checkout in place of the session's own tree; a session that works in its own tree is rewound while that checkout stands (before releaseSessionCheckout, its tree on disk).`);
66
+ refuseRestoreOnForkWithOwnTree(await forkHasOwnTree(ctx.session, req.sessionId, row.forkedFrom), req.sessionId, req.to, req.dryRun ? "preview" : "restore");
67
+ const { historyRoot, historyScope } = await resolveFileHistoryCoordinates(env, sessionRoot, undefined, ownScope);
68
+ const roots = { own: () => Promise.resolve(historyRoot), source: async (origin) => { const r = await recordedRootOf(at, origin); return r === undefined ? undefined : canonicalOrSelf(env, r); } };
53
69
  if (ctx.captureStore !== undefined)
54
- await adoptForkedFileHistory(ctx.captureStore, ctx.session, req.sessionId, ctx.seats.deps.onError);
70
+ await adoptForkedFileHistory(ctx.captureStore, { origin: row.forkedFrom, originIncarnation: row.forkedFromIncarnation }, req.sessionId, ownScope, ctx.seats.deps.onError, roots);
55
71
  if (req.dryRun) {
56
72
  if (!(await ctx.store.canRestore(historyScope, req.to)))
57
73
  throw noBoundaryRefusal(req.to, req.sessionId, true);
58
74
  const preview = ctx.store.diffStats === undefined ? null : await ctx.store.diffStats(historyScope, req.to, env, historyRoot);
59
75
  return { dryRun: true, preview: preview ?? null };
60
76
  }
61
- const restore = await settleFileHistoryRestore({ store: ctx.store, sessionId: req.sessionId, target: req.to, before: false, env, root: historyRoot, signal: req.signal, readStates: ctx.seats.readStates });
77
+ const restore = await settleFileHistoryRestore({ store: ctx.store, sessionId: req.sessionId, scope: historyScope, target: req.to, before: false, env, root: historyRoot, signal: req.signal, readStates: ctx.seats.readStates });
62
78
  return { dryRun: false, restore };
63
79
  }
64
80
  function screenRewindFilesRequest(request) {
@@ -0,0 +1,8 @@
1
+ import { type RuleStoreFault } from "../rule-store-fault.js";
2
+ import type { RunnerDeps } from "../runner-deps.js";
3
+ import { type AnnounceOnceLedger } from "./announce-once-ledger.js";
4
+ /** The reader's `onUnread` seat over a run's notice sink and the session's announced record. */
5
+ export declare function ruleStoreUnreadableNotice(onNotice: RunnerDeps["onNotice"], ids: {
6
+ readonly sessionId: string;
7
+ readonly runId: string;
8
+ }, record: Pick<AnnounceOnceLedger, "oncePerSession">): (at: "prepare" | "call", faults: readonly RuleStoreFault[]) => void;
@@ -0,0 +1,11 @@
1
+ import { deliverEngineNotice } from "../engine-notice.js";
2
+ import { ruleStoreFaultsKey, ruleStoreUnreadableNoticeSentence } from "../rule-store-fault.js";
3
+ import { announceDigest } from "./announce-once-ledger.js";
4
+ const RULE_STORE_UNAVAILABLE = "permission.rule_store_unavailable";
5
+ export function ruleStoreUnreadableNotice(onNotice, ids, record) {
6
+ return (at, faults) => record.oncePerSession(announceDigest(RULE_STORE_UNAVAILABLE, ruleStoreFaultsKey(faults)), () => deliverEngineNotice(onNotice, {
7
+ code: RULE_STORE_UNAVAILABLE,
8
+ message: ruleStoreUnreadableNoticeSentence(at, faults),
9
+ detail: { at, sessionId: ids.sessionId, runId: ids.runId, faults: faults.map((f) => ({ sources: [...f.sources], reason: f.reason })) },
10
+ }));
11
+ }
@@ -1,4 +1,3 @@
1
- import type { ReasoningWireFacts } from "../../brain/reasoning.js";
2
1
  import { type ExtraBodyDroppedSeatInput } from "./extra-body-dropped-seat.js";
3
2
  import type { RunState } from "./contracts.js";
4
3
  import type { LegFrameOffer } from "./leg-frame.js";
@@ -14,15 +13,13 @@ export interface RunBrainSinksInput {
14
13
  parentToolCallId?: string;
15
14
  sourceTaskId?: string;
16
15
  };
17
- /** borrowed-readonly — the reasoning lane's wire-facts consumer, the third sink the composition installs. */
18
- observeReasoningWireFacts: (facts: ReasoningWireFacts) => void;
19
- /** borrowed-readonly — the notice sink and the leg's ids; the fourth and fifth sinks' announcers are minted from them. */
16
+ /** borrowed-readonly — the notice sink and the leg's ids; the third and fourth sinks' announcers are minted from them. */
20
17
  notice: ExtraBodyDroppedSeatInput;
21
- /** borrowed-mutable — the session's announced record: the sixth sink's announcer says a withheld capability once per session. */
18
+ /** borrowed-mutable — the session's announced record: the fifth sink's announcer says a withheld capability once per session. */
22
19
  announced: CapabilityWithheldRecord;
23
20
  }
24
21
  export interface RunBrainSinksResult {
25
- /** Compose the three brain ALS sinks around a brain-driving call. */
22
+ /** Compose the two brain ALS sinks around a brain-driving call. */
26
23
  withBrainSinks: <T>(fn: () => Promise<T>) => Promise<T>;
27
24
  /** Compose the three leg-wide request sinks (the extraBody strip, the credential-origin refusal, the withheld capability) around the whole leg. */
28
25
  withLegRequestSinks: <T>(fn: () => Promise<T>) => Promise<T>;
@@ -1,12 +1,12 @@
1
- import { runWithBrainTelemetry, runWithReasoningWireFacts, runWithStatusSink } from "../../brain/status-sink.js";
1
+ import { runWithBrainTelemetry, runWithStatusSink } from "../../brain/status-sink.js";
2
2
  import { createExtraBodyDroppedScope } from "./extra-body-dropped-seat.js";
3
- import { createCredentialOriginRefusalScope } from "./credential-origin-seat.js";
3
+ import { createCredentialRefusalScope } from "./credential-refusal-seat.js";
4
4
  import { emitTrace } from "../trace.js";
5
5
  import { admittedProviderMessage } from "../../brain/provider-message.js";
6
6
  import { readMember } from "../thrown-value.js";
7
7
  import { createCapabilityWithheldScope } from "./capability-withheld-seat.js";
8
8
  export function runBrainSinks(input) {
9
- const { offerLegFrame, rs, ident, observeReasoningWireFacts, notice, announced } = input;
9
+ const { offerLegFrame, rs, ident, notice, announced } = input;
10
10
  const statusEmit = (s) => {
11
11
  const providerMessage = admittedProviderMessage(readMember(s, "providerMessage"));
12
12
  const frame = {
@@ -61,10 +61,10 @@ export function runBrainSinks(input) {
61
61
  ? { kind: "brain.echo_dropped", version: 1, taskId: rs.telemetry.taskId, field: t.field, ts: Date.now() }
62
62
  : { kind: "vision.placeholder", version: 1, taskId: rs.telemetry.taskId, count: t.count, ts: Date.now() });
63
63
  };
64
- const withBrainSinks = (fn) => runWithStatusSink(statusEmit, () => runWithBrainTelemetry(telemetryEmit, () => runWithReasoningWireFacts(observeReasoningWireFacts, fn)));
64
+ const withBrainSinks = (fn) => runWithStatusSink(statusEmit, () => runWithBrainTelemetry(telemetryEmit, fn));
65
65
  const withExtraBodyDropped = createExtraBodyDroppedScope(notice);
66
- const withCredentialOriginRefusals = createCredentialOriginRefusalScope(notice);
66
+ const withCredentialRefusals = createCredentialRefusalScope(notice);
67
67
  const withCapabilityWithheld = createCapabilityWithheldScope(notice, announced);
68
- const withLegRequestSinks = (fn) => withExtraBodyDropped(() => withCredentialOriginRefusals(() => withCapabilityWithheld(fn)));
68
+ const withLegRequestSinks = (fn) => withExtraBodyDropped(() => withCredentialRefusals(() => withCapabilityWithheld(fn)));
69
69
  return { withBrainSinks, withLegRequestSinks };
70
70
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The run body's COMPACTION MACHINERY (R9), verbatim from `Runner.runLocked`: the accounted
3
- * compaction brain (every summary call re-priced onto `stats` like a main-loop call, behind no-op status and
4
- * reasoning-wire-facts sinks), the within-task compaction switch, the shared consecutive-failure breaker, and the
3
+ * compaction brain (every summary call re-priced onto `stats` like a main-loop call, behind a no-op status
4
+ * sink), the within-task compaction switch, the shared consecutive-failure breaker, and the
5
5
  * window-safety option builder every in-run maybeCompact lane spreads (the fallback-budget gate + the disclosure bridge).
6
6
  */
7
7
  import type { Model } from "../../internal/llm.js";
@@ -37,6 +37,8 @@ export interface RunGitLaneInput {
37
37
  onMessageEnd: (event: Extract<AgentHarnessEvent, {
38
38
  type: "message_end";
39
39
  }>) => Promise<void> | undefined;
40
+ /** borrowed-readonly — the reasoning seat's reader: every `message_end` message goes to it first (it reads, never awaits). */
41
+ observeReasoningMessage: (message: unknown) => void;
40
42
  /** borrowed-readonly — the harness-handlers lane's tool_execution_start closure. */
41
43
  onToolStart: (event: Extract<AgentHarnessEvent, {
42
44
  type: "tool_execution_start";
@@ -3,7 +3,7 @@ import { wrapGitFrame } from "./git-leg-delivery.js";
3
3
  import { appendAdmittedRow } from "../row-admission.js";
4
4
  import { thrownText } from "../thrown-value.js";
5
5
  export function runGitLane(input) {
6
- const { prepared, queue, rs, ident, onMessageStart, onMessageUpdate, onMessageEnd, onToolStart, onToolEnd, onTurnEnd, onTurnStart, onTurnBoundary, runner } = input;
6
+ const { prepared, queue, rs, ident, onMessageStart, onMessageUpdate, onMessageEnd, observeReasoningMessage, onToolStart, onToolEnd, onTurnEnd, onTurnStart, onTurnBoundary, runner } = input;
7
7
  prepared.gitStatusRef.reassert = async () => {
8
8
  const ref = prepared.gitStatusRef;
9
9
  const frame = ref.frame;
@@ -90,6 +90,7 @@ export function runGitLane(input) {
90
90
  onMessageUpdate(event);
91
91
  break;
92
92
  case "message_end":
93
+ observeReasoningMessage(event.message);
93
94
  return onMessageEnd(event);
94
95
  case "tool_execution_start":
95
96
  onToolStart(event);
@@ -33,7 +33,7 @@ export function createHarnessHandlers(input) {
33
33
  const finishReasonSeat = createFinishReasonSeat(deps.runnerHooks.onNotice, { sessionId: prepared.sessionId, runId: prepared.runId });
34
34
  const withheldShellEnvSeat = createWithheldShellEnvSeat(prepared, deps.runnerHooks.onNotice);
35
35
  const { spec, queue, internals, ident, pushContent, display, emitCommitted, startedToolCallIds, toolStartAt, toolProgress, writeFamilyOf, toolLabels, postToolBatchArmed, batchArgs, internalsNotifier, mediaBudgetBase64Chars } = deps;
36
- const frames = { push: (f) => pushContent({ ...f, ...ident() }), structured: prepared.structuredProjector, mediaBudgetBase64Chars };
36
+ const frames = { push: (f) => pushContent({ ...f, ...ident() }), structured: prepared.structuredProjector, mediaBudgetBase64Chars, reviewRequest: prepared.reviewRequestRef };
37
37
  const startOf = (e) => {
38
38
  const label = toolLabels.get(e.toolName);
39
39
  return { toolCallId: e.toolCallId, spelledName: e.toolName, wireName: rosterToolName(prepared.toolRosterDeltas.current, e.toolName), ...(label !== undefined ? { label } : {}), args: e.args, ...requesterOf(prepared.modBus, e.toolCallId) };
@@ -113,7 +113,7 @@ export function createHarnessHandlers(input) {
113
113
  if (answerBills !== undefined)
114
114
  rs.degrade.fallbackSeat.observe("main", requestedModel, answerBills.reading);
115
115
  if (answeredWithoutModel(m)) {
116
- rs.turn.turnUsage ??= { inputTokens: 0, totalInputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, costMicroUsd: 0 };
116
+ rs.turn.turnUsage ??= { inputTokens: 0, totalInputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, costMicroUsd: 0, apiDurationMs: 0 };
117
117
  }
118
118
  else if (m.role === "assistant" && "usage" in m && m.usage) {
119
119
  if (m.usageMissing) {
@@ -123,10 +123,10 @@ export function createHarnessHandlers(input) {
123
123
  bookLeftHops(rs, stats, answerBills?.reading);
124
124
  const u = m.usage;
125
125
  const answerUsageMissing = m.usageMissing === true;
126
- const { turnTotal, turnUncached, turnCostMicroUsd, priced: answerPriced } = bookMainCall(rs, stats, answerBills?.reading.served ?? requestedModel, u, answerUsageMissing);
127
126
  const callEndAt = Date.now();
128
127
  const callIssuedAt = prepared.callIssuedAtRef.current;
129
128
  prepared.callIssuedAtRef.current = undefined;
129
+ const { turnTotal, turnUncached, turnCostMicroUsd, priced: answerPriced } = bookMainCall(rs, stats, answerBills?.reading.served ?? requestedModel, u, answerUsageMissing, callIssuedAt !== undefined ? callEndAt - callIssuedAt : 0);
130
130
  emitTrace(rs.telemetry.tracer, () => ({
131
131
  kind: "brain.call",
132
132
  version: 1,
@@ -317,7 +317,7 @@ export function createHarnessHandlers(input) {
317
317
  prepared.workCutRef.abortedBeforeTurnEnd = true;
318
318
  const stopExtra = rs.turn.turnStopReason !== undefined ? { stopReason: rs.turn.turnStopReason } : {};
319
319
  const servedExtra = rs.turn.turnResponseModel !== undefined ? { responseModel: rs.turn.turnResponseModel } : {};
320
- const usage = rs.turn.turnUsage ?? { inputTokens: 0, totalInputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, costMicroUsd: 0 };
320
+ const usage = rs.turn.turnUsage ?? { inputTokens: 0, totalInputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, costMicroUsd: 0, apiDurationMs: 0 };
321
321
  const turnUsageUnknown = rs.turn.turnUsage === undefined || rs.turn.turnUsageMissing;
322
322
  if (turnUsageUnknown)
323
323
  stats.usageMissing = true;
@@ -356,6 +356,7 @@ export function createHarnessHandlers(input) {
356
356
  toolProgress.clear();
357
357
  if (rs.limits.effectiveMaxTurns !== undefined && rs.limits.effectiveMaxTurns > 0 && stats.turns >= rs.limits.effectiveMaxTurns) {
358
358
  rs.limits.turnsExceeded = true;
359
+ rs.limits.budgetOverAtTurnCap = rs.budget.overBudget();
359
360
  if (prepared.suspendForResource === undefined) {
360
361
  void prepared.harness.abort();
361
362
  prepared.abortController.abort();