@sema-agent/core 7.60.0 → 7.62.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 (560) hide show
  1. package/CHANGELOG.md +917 -0
  2. package/README.md +2 -2
  3. package/dist/agents/agent-transcript-tool.d.ts +2 -2
  4. package/dist/agents/agent-transcript-tool.js +1 -1
  5. package/dist/agents/cascade.d.ts +71 -12
  6. package/dist/agents/cascade.js +61 -21
  7. package/dist/agents/composition-allowance.d.ts +53 -0
  8. package/dist/agents/composition-allowance.js +49 -0
  9. package/dist/agents/composition-placement.d.ts +29 -0
  10. package/dist/agents/composition-placement.js +24 -0
  11. package/dist/agents/cumulative-stats.d.ts +4 -0
  12. package/dist/agents/cumulative-stats.js +3 -0
  13. package/dist/agents/inherited-tool-pool.d.ts +5 -3
  14. package/dist/agents/inherited-tool-pool.js +2 -2
  15. package/dist/agents/list-agents-tool.d.ts +1 -1
  16. package/dist/agents/peer-held-queue.d.ts +27 -4
  17. package/dist/agents/peer-held-queue.js +81 -36
  18. package/dist/agents/peer-notice-route.d.ts +1 -1
  19. package/dist/agents/peer-notice-route.js +4 -3
  20. package/dist/agents/peer-notices.d.ts +4 -4
  21. package/dist/agents/peer-notices.js +8 -4
  22. package/dist/agents/peer-session-drain.d.ts +8 -1
  23. package/dist/agents/peer-session-drain.js +49 -10
  24. package/dist/agents/repair-loop.js +16 -6
  25. package/dist/agents/retain-ledger.js +3 -1
  26. package/dist/agents/roster-store.d.ts +1 -1
  27. package/dist/agents/roster-store.js +7 -4
  28. package/dist/agents/send-message-tool.d.ts +8 -10
  29. package/dist/agents/send-message-tool.js +43 -23
  30. package/dist/agents/subagent-completion-gate.d.ts +35 -0
  31. package/dist/agents/subagent-completion-gate.js +62 -0
  32. package/dist/agents/subagent-steps.d.ts +7 -6
  33. package/dist/agents/subagent.d.ts +36 -41
  34. package/dist/agents/subagent.js +245 -200
  35. package/dist/agents/suspend-guard.d.ts +47 -16
  36. package/dist/agents/suspend-guard.js +13 -4
  37. package/dist/agents/verify.d.ts +41 -14
  38. package/dist/agents/verify.js +41 -30
  39. package/dist/brain/anthropic.js +1 -0
  40. package/dist/brain/errors.d.ts +7 -1
  41. package/dist/brain/errors.js +6 -0
  42. package/dist/brain/failover.js +2 -1
  43. package/dist/brain/open-responses.js +1 -0
  44. package/dist/brain/openai.js +1 -0
  45. package/dist/brain/provider-dialect.d.ts +10 -0
  46. package/dist/brain/provider-dialect.js +13 -2
  47. package/dist/brain/stream-engine.d.ts +3 -0
  48. package/dist/brain/stream-engine.js +4 -0
  49. package/dist/core/agent-state.d.ts +1 -1
  50. package/dist/core/allow-entry.d.ts +59 -23
  51. package/dist/core/allow-entry.js +131 -38
  52. package/dist/core/ask-origin.d.ts +79 -0
  53. package/dist/core/ask-origin.js +76 -0
  54. package/dist/core/ask-question.d.ts +19 -13
  55. package/dist/core/ask-question.js +8 -2
  56. package/dist/core/auto-compaction.d.ts +2 -0
  57. package/dist/core/auto-compaction.js +2 -1
  58. package/dist/core/auto-mode.js +3 -5
  59. package/dist/core/background-agent-store.d.ts +7 -5
  60. package/dist/core/background-agent-store.js +12 -11
  61. package/dist/core/checkpoint-features.d.ts +722 -0
  62. package/dist/core/checkpoint-features.js +98 -0
  63. package/dist/core/checkpoint-requirements.d.ts +33 -5
  64. package/dist/core/checkpoint-requirements.js +18 -5
  65. package/dist/core/checkpoint-row-verdict.d.ts +99 -0
  66. package/dist/core/checkpoint-row-verdict.js +225 -0
  67. package/dist/core/checkpoint-store.d.ts +107 -738
  68. package/dist/core/checkpoint-store.js +45 -143
  69. package/dist/core/child-clamp-seats.d.ts +3 -2
  70. package/dist/core/child-clamp-seats.js +4 -3
  71. package/dist/core/closest-name.d.ts +13 -0
  72. package/dist/core/closest-name.js +35 -0
  73. package/dist/core/context-settings.js +3 -5
  74. package/dist/core/cross-boundary-taint.d.ts +1 -1
  75. package/dist/core/decision-receipt.d.ts +14 -1
  76. package/dist/core/decision-receipt.js +6 -3
  77. package/dist/core/delegation-frames.d.ts +13 -9
  78. package/dist/core/effective-path-target.js +2 -3
  79. package/dist/core/engine-attestation.d.ts +11 -1
  80. package/dist/core/engine-attestation.js +2 -0
  81. package/dist/core/engine-notice.d.ts +68 -21
  82. package/dist/core/engine-notice.js +9 -2
  83. package/dist/core/file-history-retention.d.ts +8 -0
  84. package/dist/core/file-history-retention.js +14 -11
  85. package/dist/core/file-history-store.d.ts +31 -1
  86. package/dist/core/file-history-store.js +31 -2
  87. package/dist/core/frame-settlement.d.ts +10 -0
  88. package/dist/core/frame-settlement.js +6 -1
  89. package/dist/core/fs-write-gate-policy.d.ts +3 -3
  90. package/dist/core/fs-write-gate-policy.js +8 -7
  91. package/dist/core/gate-fold.js +4 -3
  92. package/dist/core/gate-lanes.js +7 -4
  93. package/dist/core/gate-outcome.d.ts +40 -1
  94. package/dist/core/gate-outcome.js +10 -0
  95. package/dist/core/git-worktree-env.d.ts +7 -3
  96. package/dist/core/git-worktree-env.js +16 -13
  97. package/dist/core/governance-codes.d.ts +14 -4
  98. package/dist/core/governance-codes.js +19 -4
  99. package/dist/core/hooks.d.ts +25 -4
  100. package/dist/core/hooks.js +11 -4
  101. package/dist/core/host-floor.js +3 -5
  102. package/dist/core/human-input-projection.d.ts +1 -0
  103. package/dist/core/human-input-projection.js +3 -0
  104. package/dist/core/image-admission.d.ts +47 -7
  105. package/dist/core/image-admission.js +35 -4
  106. package/dist/core/input-author.d.ts +36 -0
  107. package/dist/core/input-author.js +39 -0
  108. package/dist/core/leg-identity.d.ts +62 -0
  109. package/dist/core/leg-identity.js +18 -0
  110. package/dist/core/locked-config.d.ts +4 -3
  111. package/dist/core/locked-config.js +5 -3
  112. package/dist/core/lsp.d.ts +5 -3
  113. package/dist/core/lsp.js +3 -2
  114. package/dist/core/mailbox-store.d.ts +85 -10
  115. package/dist/core/mailbox-store.js +31 -10
  116. package/dist/core/mcp-connection-pool.d.ts +6 -20
  117. package/dist/core/mcp-connection-pool.js +10 -28
  118. package/dist/core/mcp-failure.d.ts +76 -15
  119. package/dist/core/mcp-failure.js +60 -33
  120. package/dist/core/mcp-host-seat.d.ts +92 -53
  121. package/dist/core/mcp-host-seat.js +225 -46
  122. package/dist/core/mcp-probe.js +2 -2
  123. package/dist/core/mcp-server-link.d.ts +18 -6
  124. package/dist/core/mcp-server-link.js +19 -4
  125. package/dist/core/mcp-server-spec.d.ts +2 -1
  126. package/dist/core/mcp-session-end.d.ts +1 -2
  127. package/dist/core/mcp-session-end.js +1 -1
  128. package/dist/core/mcp.d.ts +6 -49
  129. package/dist/core/mcp.js +115 -111
  130. package/dist/core/media-byte-cap.d.ts +21 -46
  131. package/dist/core/media-byte-cap.js +55 -55
  132. package/dist/core/member-group.d.ts +7 -0
  133. package/dist/core/member-group.js +35 -0
  134. package/dist/core/memory-engine/consolidation-driver.d.ts +1 -1
  135. package/dist/core/memory-engine/consolidation.d.ts +1 -1
  136. package/dist/core/memory-engine/consolidation.js +7 -1
  137. package/dist/core/memory-engine/dual-root.d.ts +31 -0
  138. package/dist/core/memory-engine/dual-root.js +59 -11
  139. package/dist/core/memory-engine/engine.js +27 -24
  140. package/dist/core/memory-engine/file-backend.d.ts +13 -0
  141. package/dist/core/memory-engine/file-backend.js +35 -15
  142. package/dist/core/memory-engine/layout.d.ts +3 -0
  143. package/dist/core/memory-engine/layout.js +13 -3
  144. package/dist/core/memory-engine/memory-deployment.d.ts +110 -0
  145. package/dist/core/memory-engine/memory-deployment.js +182 -0
  146. package/dist/core/memory-engine/sync-client.d.ts +39 -18
  147. package/dist/core/memory-engine/sync-client.js +72 -14
  148. package/dist/core/memory-engine/sync-report.d.ts +7 -4
  149. package/dist/core/memory-engine/sync.d.ts +9 -1
  150. package/dist/core/memory-vector.d.ts +1 -1
  151. package/dist/core/memory.d.ts +10 -10
  152. package/dist/core/mode-policy.d.ts +8 -8
  153. package/dist/core/mode-policy.js +8 -6
  154. package/dist/core/mods/agent-stations.d.ts +39 -4
  155. package/dist/core/mods/agent-stations.js +59 -10
  156. package/dist/core/mods/classic-events.d.ts +9 -1
  157. package/dist/core/mods/dollar.d.ts +94 -1
  158. package/dist/core/mods/dollar.js +13 -1
  159. package/dist/core/mods/extension-call.d.ts +15 -1
  160. package/dist/core/mods/extension-call.js +7 -2
  161. package/dist/core/mods/kernel/dispatch.d.ts +4 -3
  162. package/dist/core/mods/kernel/dispatch.js +4 -4
  163. package/dist/core/mods/kernel/events.d.ts +14 -3
  164. package/dist/core/mods/kernel/events.js +18 -15
  165. package/dist/core/mods/kernel/registration.d.ts +3 -0
  166. package/dist/core/mods/kernel/registration.js +5 -0
  167. package/dist/core/mods/kernel/site-rules.d.ts +6 -3
  168. package/dist/core/mods/kernel/site-rules.js +10 -2
  169. package/dist/core/mods/lifecycle-stations.d.ts +36 -4
  170. package/dist/core/mods/lifecycle-stations.js +44 -9
  171. package/dist/core/mods/session-append.d.ts +118 -0
  172. package/dist/core/mods/session-append.js +318 -0
  173. package/dist/core/mods/session-compact.d.ts +48 -0
  174. package/dist/core/mods/session-compact.js +194 -0
  175. package/dist/core/mods/session-receive.d.ts +93 -0
  176. package/dist/core/mods/session-receive.js +138 -0
  177. package/dist/core/mods/session-send.d.ts +72 -0
  178. package/dist/core/mods/session-send.js +88 -0
  179. package/dist/core/mods/stations.d.ts +88 -21
  180. package/dist/core/mods/stations.js +149 -11
  181. package/dist/core/mods/tool-call.d.ts +2 -0
  182. package/dist/core/mods/tool-call.js +4 -4
  183. package/dist/core/output-style.js +3 -4
  184. package/dist/core/own-property-receipt.d.ts +68 -2
  185. package/dist/core/own-property-receipt.js +45 -2
  186. package/dist/core/park-selfcheck.js +4 -2
  187. package/dist/core/path-identity.d.ts +11 -0
  188. package/dist/core/path-identity.js +4 -0
  189. package/dist/core/path-rule-binding.d.ts +3 -1
  190. package/dist/core/path-rule-binding.js +3 -1
  191. package/dist/core/peer-seat.d.ts +3 -3
  192. package/dist/core/peer-seat.js +20 -8
  193. package/dist/core/permission-rule-consent.d.ts +21 -5
  194. package/dist/core/permission-rule-consent.js +21 -1
  195. package/dist/core/permission-rule-model.d.ts +34 -11
  196. package/dist/core/permission-rule-model.js +47 -10
  197. package/dist/core/permission-rule-org.d.ts +1 -1
  198. package/dist/core/permission-rule-provider.js +4 -1
  199. package/dist/core/permission-rules.d.ts +4 -0
  200. package/dist/core/permission-rules.js +11 -16
  201. package/dist/core/read-root-candidate.js +1 -1
  202. package/dist/core/remote-env.d.ts +74 -26
  203. package/dist/core/remote-env.js +20 -0
  204. package/dist/core/resume-startup-cause.d.ts +5 -4
  205. package/dist/core/retention-policy.d.ts +24 -23
  206. package/dist/core/retention-policy.js +36 -2
  207. package/dist/core/retention.d.ts +4 -1
  208. package/dist/core/retired-keys.d.ts +4 -4
  209. package/dist/core/row-admission.d.ts +10 -0
  210. package/dist/core/row-admission.js +5 -0
  211. package/dist/core/runner/advisor-instructions.d.ts +2 -1
  212. package/dist/core/runner/advisor-instructions.js +2 -1
  213. package/dist/core/runner/announce-once-ledger.d.ts +4 -4
  214. package/dist/core/runner/assemble-result.d.ts +13 -3
  215. package/dist/core/runner/assemble-result.js +12 -7
  216. package/dist/core/runner/caller-roster.d.ts +12 -9
  217. package/dist/core/runner/caller-roster.js +5 -2
  218. package/dist/core/runner/checkpoint-scope.d.ts +16 -1
  219. package/dist/core/runner/checkpoint-scope.js +21 -0
  220. package/dist/core/runner/compact-session.js +18 -3
  221. package/dist/core/runner/compaction-call-options.d.ts +1 -1
  222. package/dist/core/runner/compaction-restate.d.ts +2 -2
  223. package/dist/core/runner/compaction-restate.js +4 -3
  224. package/dist/core/runner/construction-doors.d.ts +2 -2
  225. package/dist/core/runner/construction-doors.js +2 -2
  226. package/dist/core/runner/contracts.d.ts +116 -34
  227. package/dist/core/runner/cross-boundary-lane.d.ts +1 -1
  228. package/dist/core/runner/decide-continuation.d.ts +4 -2
  229. package/dist/core/runner/decide-continuation.js +7 -4
  230. package/dist/core/runner/delegation-owner.d.ts +43 -0
  231. package/dist/core/runner/delegation-owner.js +59 -0
  232. package/dist/core/runner/denial-limit-arms.d.ts +15 -21
  233. package/dist/core/runner/denial-limit-arms.js +17 -10
  234. package/dist/core/runner/expire-settle.d.ts +44 -0
  235. package/dist/core/runner/expire-settle.js +55 -0
  236. package/dist/core/runner/git-status-frame.d.ts +3 -3
  237. package/dist/core/runner/git-status-frame.js +2 -1
  238. package/dist/core/runner/halt-attribution.d.ts +2 -1
  239. package/dist/core/runner/halt-attribution.js +2 -1
  240. package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
  241. package/dist/core/runner/lineage-reroot-view.js +108 -0
  242. package/dist/core/runner/local-claims.d.ts +17 -0
  243. package/dist/core/runner/local-claims.js +18 -0
  244. package/dist/core/runner/media-removed-seat.d.ts +46 -0
  245. package/dist/core/runner/media-removed-seat.js +88 -0
  246. package/dist/core/runner/park-commit.d.ts +2 -2
  247. package/dist/core/runner/permission-rule-lanes.d.ts +7 -2
  248. package/dist/core/runner/permission-rule-lanes.js +28 -9
  249. package/dist/core/runner/person-path-rows.d.ts +15 -0
  250. package/dist/core/runner/person-path-rows.js +27 -4
  251. package/dist/core/runner/placement-fence.d.ts +26 -0
  252. package/dist/core/runner/placement-fence.js +38 -0
  253. package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
  254. package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
  255. package/dist/core/runner/prepare-ask-lane.d.ts +6 -12
  256. package/dist/core/runner/prepare-ask-lane.js +4 -4
  257. package/dist/core/runner/prepare-boundary-parks.d.ts +4 -1
  258. package/dist/core/runner/prepare-boundary-parks.js +2 -2
  259. package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -0
  260. package/dist/core/runner/prepare-caps-and-workflow.js +2 -1
  261. package/dist/core/runner/prepare-config-doors.d.ts +6 -6
  262. package/dist/core/runner/prepare-config-doors.js +19 -21
  263. package/dist/core/runner/prepare-context-lane.d.ts +6 -2
  264. package/dist/core/runner/prepare-context-lane.js +13 -13
  265. package/dist/core/runner/prepare-delegation-surface.d.ts +9 -9
  266. package/dist/core/runner/prepare-delegation-surface.js +4 -5
  267. package/dist/core/runner/prepare-execution-env.d.ts +5 -2
  268. package/dist/core/runner/prepare-execution-env.js +7 -4
  269. package/dist/core/runner/prepare-gate-stations.d.ts +19 -14
  270. package/dist/core/runner/prepare-gate-stations.js +6 -4
  271. package/dist/core/runner/prepare-hands-readface.d.ts +6 -6
  272. package/dist/core/runner/prepare-hands-readface.js +32 -11
  273. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -0
  274. package/dist/core/runner/prepare-inherited-gate.js +10 -3
  275. package/dist/core/runner/prepare-lsp.d.ts +3 -0
  276. package/dist/core/runner/prepare-lsp.js +2 -2
  277. package/dist/core/runner/prepare-park-ask.d.ts +5 -2
  278. package/dist/core/runner/prepare-park-ask.js +4 -5
  279. package/dist/core/runner/prepare-policy-chain.d.ts +10 -21
  280. package/dist/core/runner/prepare-policy-chain.js +16 -25
  281. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  282. package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -4
  283. package/dist/core/runner/prepare-prompt-inputs.js +3 -2
  284. package/dist/core/runner/prepare-question-face.d.ts +6 -4
  285. package/dist/core/runner/prepare-question-face.js +2 -2
  286. package/dist/core/runner/prepare-run-refs.d.ts +3 -0
  287. package/dist/core/runner/prepare-run-refs.js +2 -2
  288. package/dist/core/runner/prepare-suspend-saga.d.ts +11 -7
  289. package/dist/core/runner/prepare-suspend-saga.js +17 -7
  290. package/dist/core/runner/prepare-task.d.ts +1 -1
  291. package/dist/core/runner/prepare-task.js +61 -30
  292. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +6 -0
  293. package/dist/core/runner/prepare-tool-disclosure-mount.js +3 -1
  294. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -0
  295. package/dist/core/runner/prepare-wiring-manifest.js +2 -1
  296. package/dist/core/runner/prepare-workspace-restore.d.ts +5 -0
  297. package/dist/core/runner/prepare-workspace-restore.js +10 -6
  298. package/dist/core/runner/read-root-grant.d.ts +1 -1
  299. package/dist/core/runner/read-root-grant.js +2 -1
  300. package/dist/core/runner/resume-admission.d.ts +8 -6
  301. package/dist/core/runner/resume-admission.js +23 -6
  302. package/dist/core/runner/resume-apply.d.ts +4 -0
  303. package/dist/core/runner/resume-apply.js +14 -5
  304. package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
  305. package/dist/core/runner/resume-checkpoint-screen.js +4 -84
  306. package/dist/core/runner/resume-claim.d.ts +8 -3
  307. package/dist/core/runner/resume-claim.js +28 -12
  308. package/dist/core/runner/resume-internals-and-config.d.ts +2 -2
  309. package/dist/core/runner/resume-internals-and-config.js +10 -1
  310. package/dist/core/runner/resume-preflight.d.ts +3 -2
  311. package/dist/core/runner/resume-preflight.js +13 -26
  312. package/dist/core/runner/retired-runner-deps.js +2 -0
  313. package/dist/core/runner/run-git-lane.d.ts +2 -0
  314. package/dist/core/runner/run-git-lane.js +6 -2
  315. package/dist/core/runner/run-harness-handlers.d.ts +2 -0
  316. package/dist/core/runner/run-harness-handlers.js +5 -4
  317. package/dist/core/runner/run-identity-wiring.d.ts +2 -2
  318. package/dist/core/runner/run-identity-wiring.js +14 -5
  319. package/dist/core/runner/run-leg.d.ts +3 -3
  320. package/dist/core/runner/run-leg.js +64 -36
  321. package/dist/core/runner/run-notification-lane.js +20 -2
  322. package/dist/core/runner/run-recovery-lanes.js +3 -2
  323. package/dist/core/runner/run-settle-and-teardown.js +12 -9
  324. package/dist/core/runner/run-stop-and-final-verify.js +2 -1
  325. package/dist/core/runner/run-telemetry-and-budget-seats.d.ts +1 -1
  326. package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
  327. package/dist/core/runner/run-terminal-adoption.js +26 -17
  328. package/dist/core/runner/run-turn-boundary.js +34 -18
  329. package/dist/core/runner/runtask.d.ts +18 -3
  330. package/dist/core/runner/runtask.js +33 -17
  331. package/dist/core/runner/session-rule-policy.d.ts +1 -1
  332. package/dist/core/runner/session-rule-policy.js +6 -1
  333. package/dist/core/runner/shell-env-withheld.d.ts +1 -1
  334. package/dist/core/runner/steering-preview.d.ts +9 -0
  335. package/dist/core/runner/steering-preview.js +5 -0
  336. package/dist/core/runner/stream-halt-verbs.d.ts +1 -14
  337. package/dist/core/runner/stream-halt-verbs.js +4 -3
  338. package/dist/core/runner/stream-reap.d.ts +7 -6
  339. package/dist/core/runner/stream-reap.js +13 -16
  340. package/dist/core/runner/stream-settle-backstop.d.ts +3 -2
  341. package/dist/core/runner/stream-settle-backstop.js +5 -3
  342. package/dist/core/runner/stream-steer-verb.d.ts +5 -2
  343. package/dist/core/runner/stream-steer-verb.js +16 -7
  344. package/dist/core/runner/terminal-account.d.ts +11 -1
  345. package/dist/core/runner/terminal-account.js +20 -0
  346. package/dist/core/runner/terminal-projection.d.ts +8 -2
  347. package/dist/core/runner/terminal-projection.js +2 -2
  348. package/dist/core/runner/tool-disclosure.d.ts +3 -0
  349. package/dist/core/runner/tool-disclosure.js +5 -2
  350. package/dist/core/runner/tool-end-body.d.ts +3 -3
  351. package/dist/core/runner/tool-end-body.js +1 -1
  352. package/dist/core/runner/tool-face-overlay.js +2 -0
  353. package/dist/core/runner/tool-output-projection.d.ts +3 -3
  354. package/dist/core/runner/tool-output-projection.js +7 -6
  355. package/dist/core/runner/tool-table-view.d.ts +56 -0
  356. package/dist/core/runner/tool-table-view.js +51 -0
  357. package/dist/core/runner/turn-attachments.d.ts +8 -2
  358. package/dist/core/runner/turn-attachments.js +2 -2
  359. package/dist/core/runner/void-verifier-pause.d.ts +33 -0
  360. package/dist/core/runner/void-verifier-pause.js +41 -0
  361. package/dist/core/runner-deps.d.ts +26 -27
  362. package/dist/core/secret-env.d.ts +19 -16
  363. package/dist/core/secret-env.js +45 -27
  364. package/dist/core/session-log-transfer.js +9 -10
  365. package/dist/core/session-policy-store.d.ts +1 -1
  366. package/dist/core/session-policy-store.js +5 -2
  367. package/dist/core/session-reconcile.d.ts +3 -2
  368. package/dist/core/session-reconcile.js +7 -4
  369. package/dist/core/session-store.d.ts +3 -1
  370. package/dist/core/session-store.js +10 -8
  371. package/dist/core/session.d.ts +16 -5
  372. package/dist/core/shell-confinement.d.ts +37 -0
  373. package/dist/core/shell-confinement.js +56 -0
  374. package/dist/core/skill-grant.js +1 -1
  375. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +8 -2
  376. package/dist/core/store-contracts/checkpoint-store-contract.js +83 -2
  377. package/dist/core/store-contracts/file-history-store-contract.d.ts +5 -2
  378. package/dist/core/store-contracts/file-history-store-contract.js +25 -1
  379. package/dist/core/store-contracts/mailbox-store-contract.d.ts +12 -5
  380. package/dist/core/store-contracts/mailbox-store-contract.js +156 -9
  381. package/dist/core/store-contracts/session-store-contract.js +22 -8
  382. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  383. package/dist/core/store-contracts/tool-result-store-contract.js +30 -0
  384. package/dist/core/task-event.d.ts +24 -9
  385. package/dist/core/task-limits.d.ts +5 -0
  386. package/dist/core/task-notification.d.ts +89 -12
  387. package/dist/core/task-notification.js +89 -14
  388. package/dist/core/task-registry-agent.d.ts +32 -50
  389. package/dist/core/task-registry-agent.js +36 -56
  390. package/dist/core/task-registry-monitor.d.ts +1 -1
  391. package/dist/core/task-registry-monitor.js +15 -60
  392. package/dist/core/task-registry-shared.d.ts +22 -112
  393. package/dist/core/task-registry-shared.js +3 -41
  394. package/dist/core/task-registry-workflow.js +5 -21
  395. package/dist/core/task-registry.d.ts +32 -62
  396. package/dist/core/task-registry.js +30 -110
  397. package/dist/core/task-result.d.ts +29 -12
  398. package/dist/core/task-spec-members.d.ts +39 -0
  399. package/dist/core/task-spec-members.js +92 -0
  400. package/dist/core/task-spec.d.ts +11 -11
  401. package/dist/core/task-tool-shape.d.ts +7 -57
  402. package/dist/core/task-tool-shape.js +7 -66
  403. package/dist/core/terminal-cause.d.ts +36 -6
  404. package/dist/core/terminal-cause.js +1 -0
  405. package/dist/core/tool-catalog-entries.js +2 -5
  406. package/dist/core/tool-check-reading.js +16 -10
  407. package/dist/core/tool-conformance.js +1 -2
  408. package/dist/core/tool-errors.d.ts +6 -3
  409. package/dist/core/tool-errors.js +2 -0
  410. package/dist/core/tool-face-reader.js +3 -2
  411. package/dist/core/tool-face.d.ts +8 -5
  412. package/dist/core/tool-face.js +1 -1
  413. package/dist/core/tool-name-aliases.d.ts +5 -29
  414. package/dist/core/tool-name-aliases.js +9 -5
  415. package/dist/core/tool-name-readings.d.ts +14 -3
  416. package/dist/core/tool-name-readings.js +2 -0
  417. package/dist/core/tool-policy.d.ts +109 -18
  418. package/dist/core/tool-policy.js +84 -14
  419. package/dist/core/tool-result-store.d.ts +23 -0
  420. package/dist/core/tool-result-store.js +3 -2
  421. package/dist/core/tool-roster.d.ts +4 -4
  422. package/dist/core/tool-spec.d.ts +23 -6
  423. package/dist/core/trace.d.ts +18 -1
  424. package/dist/core/types.d.ts +1 -1
  425. package/dist/core/types.js +1 -1
  426. package/dist/core/user-attachment.js +26 -21
  427. package/dist/core/workflow-journal-store.d.ts +1 -1
  428. package/dist/core/workflow-run-store.d.ts +2 -0
  429. package/dist/core/workflow-run-store.js +6 -5
  430. package/dist/core/workflow-settled-run.d.ts +5 -0
  431. package/dist/core/workflow-settled-run.js +7 -0
  432. package/dist/engine/execution-env/node-execution-env.d.ts +37 -9
  433. package/dist/engine/execution-env/node-execution-env.js +221 -22
  434. package/dist/engine/harness/agent-harness.d.ts +65 -18
  435. package/dist/engine/harness/agent-harness.js +90 -23
  436. package/dist/engine/harness/messages.d.ts +4 -3
  437. package/dist/engine/harness/messages.js +2 -2
  438. package/dist/engine/harness/types.d.ts +52 -7
  439. package/dist/engine/llm/media-removed.d.ts +14 -0
  440. package/dist/engine/llm/media-removed.js +9 -0
  441. package/dist/engine/llm/rejected-images.d.ts +35 -25
  442. package/dist/engine/llm/rejected-images.js +59 -10
  443. package/dist/engine/llm/types.d.ts +24 -3
  444. package/dist/engine/llm/types.js +7 -3
  445. package/dist/engine/loop/agent-loop.d.ts +6 -1
  446. package/dist/engine/loop/agent-loop.js +20 -11
  447. package/dist/engine/loop/types.d.ts +12 -3
  448. package/dist/engine/session/import-validate.js +7 -0
  449. package/dist/engine/session/parent-chain-guard.d.ts +3 -3
  450. package/dist/engine/session/parent-chain-guard.js +1 -1
  451. package/dist/engine/session/path-to-root.d.ts +18 -3
  452. package/dist/engine/session/path-to-root.js +15 -1
  453. package/dist/engine/session/repo-utils.d.ts +12 -1
  454. package/dist/engine/session/repo-utils.js +41 -0
  455. package/dist/engine/session/session.js +1 -1
  456. package/dist/engine/session/storage-base.d.ts +20 -0
  457. package/dist/engine/session/storage-base.js +28 -9
  458. package/dist/fixtures/index.d.ts +7 -5
  459. package/dist/fixtures/index.js +5 -3
  460. package/dist/index.d.ts +29 -18
  461. package/dist/index.js +19 -11
  462. package/dist/internal/harness-types.d.ts +2 -0
  463. package/dist/internal/harness.d.ts +4 -3
  464. package/dist/internal/harness.js +3 -2
  465. package/dist/internal/llm.d.ts +2 -1
  466. package/dist/internal/llm.js +1 -0
  467. package/dist/orchestration/goal.d.ts +6 -2
  468. package/dist/orchestration/goal.js +6 -3
  469. package/dist/orchestration/run-workflow-tool.d.ts +14 -17
  470. package/dist/orchestration/run-workflow-tool.js +43 -50
  471. package/dist/orchestration/workflow-types.d.ts +2 -2
  472. package/dist/orchestration/workflow.d.ts +7 -0
  473. package/dist/orchestration/workflow.js +10 -12
  474. package/dist/stores/file/background-agent-store.js +18 -15
  475. package/dist/stores/file/checkpoint-store.d.ts +2 -0
  476. package/dist/stores/file/checkpoint-store.js +13 -9
  477. package/dist/stores/file/file-history-store.js +3 -2
  478. package/dist/stores/file/fs-atomic.d.ts +0 -22
  479. package/dist/stores/file/fs-atomic.js +0 -17
  480. package/dist/stores/file/index.d.ts +7 -12
  481. package/dist/stores/file/index.js +25 -12
  482. package/dist/stores/file/ledger-tuning.d.ts +23 -0
  483. package/dist/stores/file/ledger-tuning.js +21 -0
  484. package/dist/stores/file/mailbox-store.js +42 -22
  485. package/dist/stores/file/memory-store.js +3 -2
  486. package/dist/stores/file/permission-rule-adopt.js +24 -21
  487. package/dist/stores/file/permission-rule-store.js +6 -3
  488. package/dist/stores/file/session-policy-store.js +3 -2
  489. package/dist/stores/file/session-store.d.ts +26 -7
  490. package/dist/stores/file/session-store.js +59 -35
  491. package/dist/stores/file/tool-result-store.d.ts +11 -0
  492. package/dist/stores/file/tool-result-store.js +57 -3
  493. package/dist/stores/file/usage-window-store.js +3 -2
  494. package/dist/stores/file/workflow-journal-store.d.ts +0 -2
  495. package/dist/stores/file/workflow-journal-store.js +3 -18
  496. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  497. package/dist/stores/file/workflow-run-store.js +15 -10
  498. package/dist/tools/fs/bash-program-position.d.ts +3 -2
  499. package/dist/tools/fs/bash-program-position.js +7 -7
  500. package/dist/tools/fs/dead-cwd.d.ts +5 -5
  501. package/dist/tools/fs/dead-cwd.js +4 -11
  502. package/dist/tools/fs/fs-bash-background-text.d.ts +6 -0
  503. package/dist/tools/fs/fs-bash-background-text.js +6 -0
  504. package/dist/tools/fs/fs-bash.d.ts +3 -18
  505. package/dist/tools/fs/fs-bash.js +37 -124
  506. package/dist/tools/fs/fs-pdf.js +8 -6
  507. package/dist/tools/fs/fs-read.js +2 -2
  508. package/dist/tools/fs/fs-shared.d.ts +28 -3
  509. package/dist/tools/fs/fs-shared.js +15 -0
  510. package/dist/tools/fs/index.d.ts +1 -1
  511. package/dist/tools/fs/index.js +4 -14
  512. package/dist/tools/fs/pdf.d.ts +4 -4
  513. package/dist/tools/fs/pdf.js +6 -6
  514. package/dist/tools/fs/read-deny-home.js +8 -1
  515. package/dist/tools/fs/read-deny.d.ts +26 -2
  516. package/dist/tools/fs/read-deny.js +9 -2
  517. package/dist/tools/fs/read-floor.d.ts +13 -5
  518. package/dist/tools/fs/read-floor.js +206 -2
  519. package/dist/tools/fs/removal-targets.js +2 -2
  520. package/dist/tools/fs/search.d.ts +3 -2
  521. package/dist/tools/fs/search.js +6 -6
  522. package/dist/tools/fs/shell-read-argv.d.ts +4 -2
  523. package/dist/tools/fs/shell-read-argv.js +14 -3
  524. package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
  525. package/dist/tools/fs/shell-read-bindings.js +148 -68
  526. package/dist/tools/fs/shell-read-check.js +20 -4
  527. package/dist/tools/fs/shell-read-establish.js +25 -9
  528. package/dist/tools/fs/shell-read-functions.js +2 -2
  529. package/dist/tools/fs/shell-read-identity.d.ts +3 -1
  530. package/dist/tools/fs/shell-read-identity.js +4 -2
  531. package/dist/tools/fs/shell-read-judge.d.ts +7 -1
  532. package/dist/tools/fs/shell-read-judge.js +1 -1
  533. package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
  534. package/dist/tools/fs/shell-read-object-path.js +119 -0
  535. package/dist/tools/fs/shell-read-plan.d.ts +8 -0
  536. package/dist/tools/fs/shell-read-plan.js +47 -30
  537. package/dist/tools/fs/shell-read-start.d.ts +66 -13
  538. package/dist/tools/fs/shell-read-start.js +89 -17
  539. package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
  540. package/dist/tools/fs/shell-read-workdir.js +31 -8
  541. package/dist/tools/monitor.d.ts +8 -7
  542. package/dist/tools/monitor.js +12 -10
  543. package/dist/tools/worktree.d.ts +5 -1
  544. package/dist/tools/worktree.js +20 -17
  545. package/package.json +6 -3
  546. package/test/export-surface.snapshot.json +112 -42
  547. package/wire-changes/core-stores-sql@7.61.0.json +480 -0
  548. package/wire-changes/core-stores-sql@7.62.0.json +30 -0
  549. package/wire-changes/core@7.61.0.json +4405 -0
  550. package/wire-changes/core@7.62.0.json +2181 -0
  551. package/wire-changes/mods-kernel@7.61.0.json +65 -0
  552. package/wire-changes/mods-kernel@7.62.0.json +42 -0
  553. package/wire-changes/primitives@7.61.0.json +30 -0
  554. package/wire-changes/primitives@7.62.0.json +30 -0
  555. package/dist/core/consolidate-scope.d.ts +0 -93
  556. package/dist/core/consolidate-scope.js +0 -98
  557. package/dist/core/runner/image-removed-seat.d.ts +0 -12
  558. package/dist/core/runner/image-removed-seat.js +0 -19
  559. package/dist/core/runner/memory-consolidation.d.ts +0 -109
  560. package/dist/core/runner/memory-consolidation.js +0 -251
@@ -3,8 +3,7 @@ import { MCP_NAMESPACE } from "./protocol-table.js";
3
3
  import { catalogRuleFaceOf, isShellFaceToolName, pathTargetOf } from "./tool-registry.js";
4
4
  import { HOST_UNREADABLE_SENTENCE, callHostTargetOf } from "./host-target.js";
5
5
  import { indexOfUnescaped, lastIndexOfUnescaped, parsePermissionRule, ruleSpellingOf } from "./permission-rule-syntax.js";
6
- import { callPathFaceOf, canonicalNameValue, COMMAND_RULE_TOOL, domainRuleAdmits, isUsablePathBase, laneToolNamesOf, mountedOnlyArgumentOf, mountedValueArmOf, NAME_RULE_FACES, nameRuleReach, nameRuleSubjectOf, nameValueAbsentReason, nameValuesUnreadReason, parseRuleText, PATH_RULE_BASE_LABEL, PATH_RULE_FACES, programRunReachOf, ruleBasesNeeded, ruleLaneOf, ruleShapeOf, shellRuleParamOf, ruleContentOf } from "./permission-rule-model.js";
7
- import { pathFamilyOf } from "../tools/fs/safety.js";
6
+ import { callPathFaceOf, canonicalNameValue, COMMAND_RULE_TOOL, domainRuleAdmits, ruleWordsOf, mountedOnlyArgumentOf, mountedValueArmOf, NAME_RULE_FACES, nameRuleReach, nameRuleSubjectOf, nameValueAbsentReason, nameValuesUnreadReason, parseRuleText, PATH_RULE_BASE_LABEL, PATH_RULE_FACES, programRunReachOf, ruleLaneOf, unusableDeclaredBase, ruleShapeOf, shellRuleParamOf, ruleContentOf } from "./permission-rule-model.js";
8
7
  import { callTargetReadingOf, callTargetViewsOf } from "./effective-path-target.js";
9
8
  import { DEFAULT_MAX_SCALAR_VALUE_CHARS, paramRuleReaches } from "./param-rule-reach.js";
10
9
  import { bindPathRules, judgeRuleRows, policyAnchors, rowsWhereTheyLead } from "./path-rule-binding.js";
@@ -209,11 +208,9 @@ function compile(rules, caps, primaryFieldGeneric, ruleFaces, pathBases = {}) {
209
208
  bad(text, "invalid.command_rule", `${parsedPath.reject.code}: ${parsedPath.reject.message}`);
210
209
  continue;
211
210
  }
212
- for (const base of ruleBasesNeeded(parsedPath.rule)) {
213
- const declared = base === "cwd" ? (pathBases.cwd ?? pathBases.root) : pathBases[base];
214
- if (declared !== undefined && !isUsablePathBase(declared, pathFamilyOf(pathBases))) {
215
- bad(text, "unsupported.path_base", `"${text}" is relative to ${PATH_RULE_BASE_LABEL[base]}, and the one this policy declares for it is not an absolute path of its tree's family — the rule could not be judged on any call`, { name: `pathBases.${base === "cwd" && pathBases.cwd === undefined ? "root" : base}` });
216
- }
211
+ const unusable = unusableDeclaredBase(parsedPath.rule, pathBases);
212
+ if (unusable !== undefined) {
213
+ bad(text, "unsupported.path_base", `"${text}" is relative to ${PATH_RULE_BASE_LABEL[unusable.base]}, and the one this policy declares for it is not an absolute path of its tree's family — the rule could not be judged on any call`, { name: `pathBases.${unusable.key}` });
217
214
  }
218
215
  if (issues.length > 0 && issues[issues.length - 1].rule === text && issues[issues.length - 1].code === "unsupported.path_base")
219
216
  continue;
@@ -332,6 +329,8 @@ export function createPermissionRulePolicy(rules, opts) {
332
329
  const heldFor = (table, req) => heldValues("policy.permissionRules", table, req);
333
330
  const coveringHit = (lane, req) => lane.length === 0 ? undefined : heldFor({ get: (name) => lane.find((r) => ruleNameCovers(r.ruleName, name)) }, req)[0];
334
331
  const hasCovering = namespacedCovering.deny.length > 0 || namespacedCovering.ask.length > 0;
332
+ const wholeToolDeny = (req) => entryFor(req)?.bare.deny ?? (hasCovering ? coveringHit(namespacedCovering.deny, req) : undefined);
333
+ const deniesWhole = namespacedCovering.deny.length > 0 || [...byTool.values()].some((e) => e.bare.deny !== undefined);
335
334
  const faceRules = {
336
335
  deny: [...byTool.values()].flatMap((e) => e.content.deny.filter((r) => r.faces !== undefined)),
337
336
  ask: [...byTool.values()].flatMap((e) => e.content.ask.filter((r) => r.faces !== undefined)),
@@ -462,20 +461,16 @@ export function createPermissionRulePolicy(rules, opts) {
462
461
  };
463
462
  return {
464
463
  nameSets: [nameSets],
464
+ ...(deniesWhole ? { wholeToolRefusals: () => Promise.resolve((tool) => wholeToolDeny(tool) !== undefined) } : {}),
465
465
  ...(pathSpecs.length > 0 ? { pathRules: (anchors) => boundAt(policyAnchors(pathBases, anchors)).rows } : {}),
466
466
  check(req) {
467
467
  const entry = entryFor(req);
468
468
  const covering = hasCovering;
469
- if (entry?.bare.deny) {
470
- return { action: "deny", message: ruleDenial(req, entry.bare.deny.ruleText, entry.bare.deny.source) };
471
- }
472
- if (covering) {
473
- const coveringDeny = coveringHit(namespacedCovering.deny, req);
474
- if (coveringDeny)
475
- return { action: "deny", message: ruleDenial(req, coveringDeny.ruleText, coveringDeny.source) };
476
- }
469
+ const whole = wholeToolDeny(req);
470
+ if (whole !== undefined)
471
+ return { action: "deny", message: ruleDenial(req, whole.ruleText, whole.source) };
477
472
  const callFace = faceRules.deny.length > 0 || faceRules.ask.length > 0 ? callPathFaceOf(req) : undefined;
478
- const shellCall = hasCommandRules && laneToolNamesOf(req).includes(COMMAND_RULE_TOOL);
473
+ const shellCall = hasCommandRules && ruleWordsOf(req, "deny").includes(COMMAND_RULE_TOOL);
479
474
  const denyLane = contentLaneOf("deny", entry, shellCall, callFace);
480
475
  const contentDeny = denyLane.length > 0 ? contentHit(denyLane, req) : undefined;
481
476
  if (contentDeny !== undefined && contentDeny.unreadable === undefined) {
@@ -1,4 +1,4 @@
1
- import { isPlainRecord, safeDataValue } from "./checkpoint-store.js";
1
+ import { isPlainRecord, safeDataValue } from "./checkpoint-features.js";
2
2
  import { validatePath } from "./effective-path-target.js";
3
3
  export { READ_ROOT_CANDIDATE_DIR_MAX } from "./effective-path-target.js";
4
4
  export function normalizeReadRootCandidate(value) {
@@ -77,11 +77,38 @@ export declare const WORKSPACE_HANDLE_MEMBERS: ReadonlyArray<keyof WorkspaceHand
77
77
  * structured-clone step to fail on an exotic value. Each member is read the way the engine's own handle comparison reads it.
78
78
  *
79
79
  * ONE copy per live handle: a second call for the same object answers the copy the first call made (the members are read
80
- * once), so every place the engine hands a checkpointed handle to the outside — the resume preflight's facts, the env
81
- * factory's {@link ExecutionEnvFactoryContext.resumeWorkspace}, the restore's {@link VmLifecycleOptions.priorHandle} —
82
- * delivers the same object, not three renderings of one fact.
80
+ * once), so every place the engine hands a checkpointed handle to the outside — the resume preflight's facts and the
81
+ * restore's {@link VmLifecycleOptions.priorHandle} — delivers the same object, not two renderings of one fact; the env
82
+ * factory's {@link ExecutionEnvFactoryContext.placementTarget} is the row's target ({@link placementTargetOf}).
83
83
  */
84
84
  export declare function frozenHandleCopy(handle: WorkspaceHandle): Readonly<WorkspaceHandle>;
85
+ /**
86
+ * Which target a leg's environment is on: the backend (`provider`) and, when the target states one, the physical device
87
+ * (`deviceId`) — the two members of a {@link WorkspaceHandle} that NAME a target, and nothing that reconnects to or restores
88
+ * one (a sandbox id, a reconnect token, a snapshot id). The value of {@link ExecutionEnvFactoryContext.placementTarget}.
89
+ */
90
+ export type PlacementTarget = Readonly<{
91
+ provider: string;
92
+ deviceId?: string;
93
+ }>;
94
+ /** The target `handle` names NOW: its `provider` and `deviceId` read as strings at this call (never through
95
+ * {@link frozenHandleCopy}'s per-object copy — an env may answer one handle object and update it in place, and a receipt
96
+ * must see what the env reports at the moment it is read), frozen; `undefined` when it names no provider (an empty
97
+ * string names none). */
98
+ export declare function placementTargetOf(handle: WorkspaceHandle): PlacementTarget | undefined;
99
+ /**
100
+ * The target an environment reports for itself, read ONCE per leg — at the point the leg's workspace settles: its
101
+ * `workspaceHandle()`'s {@link placementTargetOf}. `undefined` when there is nothing to read: the environment is not a
102
+ * remote one, or its handle cannot answer yet (a lazy-connect adapter before its first connection throws). That leg has
103
+ * no target of its own, so what it spawns carries no fence.
104
+ */
105
+ export declare function reportedPlacementTarget(env: ExecutionEnv | undefined): PlacementTarget | undefined;
106
+ /**
107
+ * The ONE receipt every fenced leg is checked with: the target its environment reported honors `fence` when the fence names
108
+ * no device, or the report names that same device. A report that could not be read (`undefined`) names none, so it honors
109
+ * no device. `provider` is no part of it: only a durable resume leg also requires the checkpointed backend.
110
+ */
111
+ export declare function placementHonored(fence: PlacementTarget | undefined, report: PlacementTarget | undefined): boolean;
85
112
  /**
86
113
  * A reference to a secret injected at {@link RemoteExecutionEnv.connect}/{@link RemoteExecutionEnv.postResumeInit}
87
114
  * time (design/48 §5 gap 7) — never baked into the image. The control plane resolves {@link ref} to a value out of
@@ -132,8 +159,9 @@ export interface VmLifecycleOptions {
132
159
  * as the legacy current-config behavior).
133
160
  *
134
161
  * A frozen copy holding exactly the declared members ({@link WORKSPACE_HANDLE_MEMBERS}) the checkpoint row carries
135
- * as strings — the SAME object the env factory's {@link ExecutionEnvFactoryContext.resumeWorkspace} was, for the
136
- * same row — not the stored row's own object: writing to it throws, and a decoration on the stored handle is absent.
162
+ * as strings ({@link frozenHandleCopy}: the SAME object the resume preflight's facts carry, for the same row) — not
163
+ * the stored row's own object: writing to it throws, and a decoration on the stored handle is absent. The restore
164
+ * facts live here only; the env factory was told the row's target alone ({@link ExecutionEnvFactoryContext.placementTarget}).
137
165
  */
138
166
  priorHandle?: Readonly<WorkspaceHandle>;
139
167
  }
@@ -321,7 +349,14 @@ export declare class RemoteExecutionError extends Error {
321
349
  * idempotency; the adapter MUST NOT blind-retry.
322
350
  */
323
351
  export interface RemoteExecutionEnv extends ExecutionEnv {
324
- /** Identity of the connected workspace (design/48 §5 gap 1). Synchronous: it is data the env already holds. */
352
+ /**
353
+ * Identity of the connected workspace (design/48 §5 gap 1). Synchronous: it is data the env already holds.
354
+ *
355
+ * The engine reads it once per leg, when the leg's workspace settles, to learn which target the leg is on
356
+ * ({@link reportedPlacementTarget}) — the fence every agent the leg spawns or wakes is minted under. A target-bound
357
+ * adapter (one whose handle states `deviceId`) answers it from construction on, before any connection; an adapter
358
+ * that cannot answer yet (it throws) gives its leg no target, and that leg's agents carry no fence.
359
+ */
325
360
  workspaceHandle(): WorkspaceHandle;
326
361
  /** Provision/attach the remote workspace and inject secrets. Returns the resulting {@link WorkspaceHandle}. */
327
362
  connect(config?: RemoteConnectConfig): Promise<{
@@ -449,7 +484,11 @@ export interface ExecutionEnvFactoryContext {
449
484
  * factory MUST refuse loudly too (loud-bad-value posture), never default around.
450
485
  */
451
486
  placementRootSessionId: string;
452
- /** Caller-supplied task id, when set on the `TaskSpec`. */
487
+ /**
488
+ * Caller-supplied task id: present only on a leg whose caller set `TaskSpec.taskId`. A child spec the engine builds (a
489
+ * delegated agent of any kind, a revival) never carries one — such a leg's task id IS its session id — so a factory
490
+ * MUST NOT identify a descendant by this key; the tree is {@link placementRootSessionId}, the leg {@link sessionId}.
491
+ */
453
492
  taskId?: string;
454
493
  /**
455
494
  * design/97 CORE-6 — per-task ISOLATION request threaded from the workflow's `ctx.agent({ isolation })` via
@@ -477,28 +516,37 @@ export interface ExecutionEnvFactoryContext {
477
516
  */
478
517
  parentCwd?: string;
479
518
  /**
480
- * design/380 O1 delivery fence — the workspace a DURABLE RESUME leg is rebuilding: a frozen copy of the
481
- * {@link WorkspaceHandle} the checkpoint row recorded at suspend, holding exactly the members a handle declares
482
- * ({@link WORKSPACE_HANDLE_MEMBERS}) that the row carries as strings. Present ONLY on that leg — the key is
483
- * absent (not an `undefined` value) on every fresh run, and on a resume whose row recorded no workspace
484
- * handle. Mutating the copy reaches nothing the engine reads.
519
+ * The placement FENCE — this context's one answer to "on which target must THIS leg's env be minted". Every leg
520
+ * learns its own target once, when its workspace settles (what its env reports, {@link reportedPlacementTarget});
521
+ * that one value is the fence of every leg it hands work to:
522
+ * · an agent it spawns (a delegated child of any kind, a workflow agent) or wakes (a retained or revived agent: the
523
+ * WAKING leg's target, never one remembered from the spawn);
524
+ * · a later leg of the same piece of work — a cascade rung after the first, a verification gate's verifier and fix
525
+ * legs — carries the FIRST leg's target;
526
+ * · a durable resume leg carries its checkpoint row's target, member by member over the one its waking leg hands it
527
+ * (a member the row states wins; a row recorded without `deviceId` takes the waking leg's).
528
+ * The key is ABSENT (not an `undefined` value) on a top-level first leg its host gave no fence
529
+ * (`RunInternals.placementTarget`), and on a leg whose spawning leg has no target of its own (its env is not remote,
530
+ * or could not answer `workspaceHandle()` when its workspace settled). A frozen value; mutating it reaches nothing.
485
531
  *
486
- * A factory bound to a target (the device lane) **MUST** mint the env on the device
487
- * `resumeWorkspace.deviceId` names and, when it cannot (offline, busy, the placement moved to another
488
- * device), **THROW** a typed refusal. It **MUST NOT** connect some other device and leave the engine to
489
- * notice, and it **MUST NOT** look the current binding up afresh from {@link placementRootSessionId} for
490
- * this leg. A row recorded without `deviceId` (a non-device lane, or a row older than the field) states no
491
- * device to honor; the factory then follows its ordinary routing.
532
+ * A factory bound to a target (the device lane) **MUST** mint the env on the device `placementTarget.deviceId` names
533
+ * and, when it cannot (offline, busy, the placement moved to another device), **THROW** a typed refusal. It **MUST
534
+ * NOT** connect some other device and leave the engine to notice, and it **MUST NOT** choose the target by the
535
+ * current binding of {@link placementRootSessionId}: it may read that binding only to find that it differs from the
536
+ * fence, and then refuse. A fence without `deviceId` states no device to honor; the factory then follows its
537
+ * ordinary routing.
492
538
  *
493
- * The minted env's `workspaceHandle()` **MUST** report the device its connection actually reached; it is
494
- * never copied from `resumeWorkspace`. The engine's comparison of that report against the row (`provider`
495
- * equal; `deviceId` equal whenever the row carries one) stays as the receipt check and TRUSTS the report: a
496
- * factory that connected elsewhere and reports so is refused (`resume.env_failed`), only after the wrong
497
- * connection was made, but one that echoes the fence while connecting elsewhere defeats its own protection
498
- * and passes. The fence moves no refusal earlier than it was: it runs after the claim, so what a deployment
499
- * can still catch BEFORE the claim is `RunnerDeps.resumePreflight` alone.
539
+ * The minted env's `workspaceHandle()` **MUST** report the device its connection actually reached; it is never
540
+ * copied from the fence. The engine checks every fenced leg with one receipt ({@link placementHonored}: the report
541
+ * names the fence's `deviceId` whenever the fence carries one, and a report that cannot be read names none): a leg
542
+ * restoring a checkpointed workspace that fails it is refused `resume.env_failed` (that restore also requires the
543
+ * checkpointed `provider`), any other leg `config.placement_not_honored`, before it runs. The receipt TRUSTS the report: a factory that connected elsewhere and
544
+ * reports so is refused, only after the wrong connection was made, but one that echoes the fence while connecting
545
+ * elsewhere defeats its own protection and passes. On a resume leg the fence moves no refusal earlier than it was:
546
+ * it runs after the claim, so what a deployment can still catch BEFORE the claim is `RunnerDeps.resumePreflight`
547
+ * alone.
500
548
  */
501
- resumeWorkspace?: Readonly<WorkspaceHandle>;
549
+ placementTarget?: PlacementTarget;
502
550
  }
503
551
  /**
504
552
  * A **trusted control-plane** factory that mints a per-task {@link ExecutionEnv} (design/48 §5 answers core
@@ -18,6 +18,26 @@ export function frozenHandleCopy(handle) {
18
18
  FROZEN_COPY_OF.set(handle, frozen);
19
19
  return frozen;
20
20
  }
21
+ export function placementTargetOf(handle) {
22
+ const provider = handle.provider;
23
+ const deviceId = handle.deviceId;
24
+ if (typeof provider !== "string" || provider === "")
25
+ return undefined;
26
+ return Object.freeze(typeof deviceId === "string" ? { provider, deviceId } : { provider });
27
+ }
28
+ export function reportedPlacementTarget(env) {
29
+ if (env === undefined || env === null || !isRemoteExecutionEnv(env))
30
+ return undefined;
31
+ try {
32
+ return placementTargetOf(env.workspaceHandle());
33
+ }
34
+ catch {
35
+ return undefined;
36
+ }
37
+ }
38
+ export function placementHonored(fence, report) {
39
+ return fence?.deviceId === undefined || report?.deviceId === fence.deviceId;
40
+ }
21
41
  export const RETRYABLE_REMOTE_ERROR_CODES = [
22
42
  "auth_transient",
23
43
  "connect_failed",
@@ -9,10 +9,11 @@
9
9
  * · `environment` — the leg's infrastructure failed (the workspace restore, an abort): the decision is
10
10
  * untouched, and a retry replays it;
11
11
  * · `session_gone` — the resumed agent's transcript session is missing;
12
- * · `transcript_corrupt` — the resumed agent's transcript session is THERE but cannot be read as a session: its log
13
- * has no header its store wrote (`corrupt_session`), or its entry tree is structurally unusable — a leaf or parent
14
- * entry that is not in the log (`invalid_session`). Distinct from `session_gone`: the bytes exist, so deleting or
15
- * restoring the transcript is the remedy, not re-creating a session;
12
+ * · `transcript_corrupt` — the resumed agent's transcript session is THERE but cannot be read as a session
13
+ * (`corrupt_session`): its log has no header its store wrote, or its entry tree does not hold together — a leaf,
14
+ * a parent or the entry its checkpoint was cut at that is not in the log, a parent chain that loops. A store outside
15
+ * this package that answers the same fact `invalid_session` reads the same way. Distinct from `session_gone`: the
16
+ * bytes exist, so deleting or restoring the transcript is the remedy, not re-creating a session;
16
17
  * · `tool_unavailable` — the approved tool is not available to the resumed leg (gone, replaced by a
17
18
  * different contract, or an inherited tool the drive cannot hand over): this approval cannot run, and a
18
19
  * fresh decision resolves it;
@@ -1,26 +1,3 @@
1
- /**
2
- * knob-hygiene #98 — one validator for every RETENTION policy a bundled store accepts.
3
- *
4
- * These knobs share a property nothing else in the engine does: they are the only numbers whose job is
5
- * to DELETE, so an unevaluable one is not merely ignored, it decides. The shapes actually reachable:
6
- *
7
- * - `keep` is consumed as `rows.slice(Math.max(0, keep))` / `i >= keep`. `Math.max(0, NaN)` is `NaN`
8
- * and `slice(NaN)` means `slice(0)` — so a policy whose `keep` arrived as NaN (the ordinary
9
- * `Number(cfg.keep)` on a missing or misspelled field) deleted EVERY terminal row instead of
10
- * keeping N of them. A negative `keep` reaches the same place by a different route.
11
- * - `maxAgeMs` on the roster feeds `now - createdAt <= maxAgeMs`, which is false for NaN — so every
12
- * row reads as expired, the next write persists the survivors, and the whole roster is gone. A
13
- * roster row is a durable ADDRESS; losing one turns a live agent unreachable.
14
- * - the remaining `*MaxAgeMs` arms fail the other way (NaN comparisons are false ⇒ nothing is
15
- * reaped), which is safe but equally silent: retention that quietly stopped running is how a disk
16
- * fills up. They are validated for the same reason — an operator deserves the same answer either way.
17
- *
18
- * Fail-loud rather than fall back to a default: a retention policy is the deployment saying what it
19
- * wants kept, and quietly substituting a different policy is exactly the class of silence this sweep
20
- * exists to remove. Every store passes its options through here BEFORE touching a row, so no
21
- * implementation can drift from another (the RB-74 / RB-87 / RB-111 history in the store family is
22
- * three consecutive "fixed one of the two implementations" misses).
23
- */
24
1
  export interface RetentionPolicyKnobs {
25
2
  /** Age bound in ms. */
26
3
  maxAgeMs?: number;
@@ -40,6 +17,30 @@ export interface RetentionPolicyKnobs {
40
17
  * {@link assertRetentionPolicy}'s "0 or more" wording without telling an operator something false.
41
18
  */
42
19
  export declare function refuseRetentionPolicy(label: string, knob: string, value: unknown, requirement: string): never;
20
+ /**
21
+ * The cutoff an age sweep removes entries before — `now - maxAgeMs` — or `undefined` when no age bound was stated
22
+ * (nothing is aged out). A bound that cannot be evaluated is refused, as {@link assertRetentionPolicy} refuses it, and
23
+ * so is a `now` that is not a finite number: either would decide what to delete instead of bounding it. The bound is
24
+ * read once, and the value judged is the value the cutoff is computed from.
25
+ */
26
+ export declare function ageCutoff(label: string, now: number, opts: {
27
+ maxAgeMs?: number;
28
+ } | undefined): number | undefined;
29
+ /** The family's coded refusal of a retention bag's stray key ({@link receiveMembers}'s one sentence, under the family's code):
30
+ * a misspelled bound (`maxAge` for `maxAgeMs`) reads as "no bound" — nothing is deleted and nothing is said, the silence a
31
+ * retention seam exists to remove. */
32
+ export declare function retentionKnobRefusal(message: string): Error;
33
+ /**
34
+ * The one reading a seam takes of a caller's retention bag: the bag is received by the receipt law with the seam's
35
+ * knobs as the members it takes ({@link receiveMembers}: a plain object, each member read once off its own descriptor,
36
+ * a member it does not take refused by name in the family's code), each knob on the copy is judged by
37
+ * {@link assertRetentionPolicy}, and the frozen copy is handed back — the value a seam judges is the value it then
38
+ * deletes by, and nothing is read from the caller's bag again. A Proxy, an object of another prototype (a bound it
39
+ * would inherit is never read) and a getter that throws are the receipt's refusals (`config.invalid_argument`).
40
+ * Absent bag ⇒ an empty policy (nothing is applied). `beside` names members of the same bag that are not knobs and that
41
+ * the seam reads itself (the joint reap's `now`): taken by the same receipt, handed back on the copy, never judged here.
42
+ */
43
+ export declare function receiveRetentionPolicy<P extends RetentionPolicyKnobs>(label: string, opts: P | undefined, accepts: readonly (keyof RetentionPolicyKnobs)[], beside?: readonly Exclude<keyof P, keyof RetentionPolicyKnobs | number | symbol>[]): Readonly<Partial<P>>;
43
44
  /**
44
45
  * Refuse a malformed retention policy at the door. `undefined` on any field keeps its documented
45
46
  * meaning — that arm is simply not applied — so a deployment that sets nothing is untouched.
@@ -1,3 +1,6 @@
1
+ import { receiveMembers } from "./own-property-receipt.js";
2
+ const AGE_KNOBS = ["maxAgeMs", "staleRunningMaxAgeMs"];
3
+ const COUNT_KNOBS = ["keep", "maxEntries"];
1
4
  export function refuseRetentionPolicy(label, knob, value, requirement) {
2
5
  const e = new Error(`${label}: ${knob} must be ${requirement} (got ${typeof value === "string" ? JSON.stringify(value) : String(value)}) — a retention bound that cannot be evaluated silently decides what to delete instead of bounding it`);
3
6
  e.code = "config.retention_policy_invalid";
@@ -6,16 +9,47 @@ export function refuseRetentionPolicy(label, knob, value, requirement) {
6
9
  function invalidPolicy(label, knob, value, requirement) {
7
10
  refuseRetentionPolicy(label, knob, value, requirement);
8
11
  }
12
+ export function ageCutoff(label, now, opts) {
13
+ const { maxAgeMs } = receiveRetentionPolicy(label, opts, ["maxAgeMs"]);
14
+ if (typeof now !== "number" || !Number.isFinite(now))
15
+ refuseRetentionPolicy(label, "now", now, "a finite number of milliseconds");
16
+ return maxAgeMs === undefined ? undefined : now - maxAgeMs;
17
+ }
18
+ export function retentionKnobRefusal(message) {
19
+ const e = new Error(message);
20
+ e.code = "config.retention_policy_invalid";
21
+ return e;
22
+ }
23
+ export function receiveRetentionPolicy(label, opts, accepts, beside = []) {
24
+ if (opts === undefined)
25
+ return Object.freeze({});
26
+ if (typeof opts !== "object" || opts === null)
27
+ refuseRetentionPolicy(label, "opts", opts, "an object of retention knobs or absent");
28
+ const got = receiveMembers(opts, { subject: `${label} policy`, unit: "retention knob", moment: "before anything is judged or deleted" }, [...accepts, ...beside], retentionKnobRefusal);
29
+ const held = {};
30
+ for (const knob of accepts) {
31
+ const v = got[knob];
32
+ if (v !== undefined)
33
+ held[knob] = v;
34
+ }
35
+ assertRetentionPolicy(label, held);
36
+ for (const name of beside) {
37
+ const v = got[name];
38
+ if (v !== undefined)
39
+ held[name] = v;
40
+ }
41
+ return Object.freeze(held);
42
+ }
9
43
  export function assertRetentionPolicy(label, opts) {
10
44
  if (opts === undefined)
11
45
  return;
12
- for (const knob of ["maxAgeMs", "staleRunningMaxAgeMs"]) {
46
+ for (const knob of AGE_KNOBS) {
13
47
  const v = opts[knob];
14
48
  if (v !== undefined && (!Number.isFinite(v) || v < 0)) {
15
49
  invalidPolicy(label, knob, v, "a finite, non-negative number of milliseconds");
16
50
  }
17
51
  }
18
- for (const knob of ["keep", "maxEntries"]) {
52
+ for (const knob of COUNT_KNOBS) {
19
53
  const v = opts[knob];
20
54
  if (v !== undefined && (!Number.isInteger(v) || v < 0)) {
21
55
  invalidPolicy(label, knob, v, "a whole number of rows, 0 or more");
@@ -42,7 +42,10 @@ export interface RetentionPolicy {
42
42
  * WRITES the row, not to the receipt: an implementation records it in the same transaction as the
43
43
  * deletion (recording after the delete would leave an unwitnessed delete on a crash), and it is
44
44
  * the only side that knows its own op, sweep round, and policy generation. The receipt below is
45
- * therefore the CALL's three counts, deliberately not an audit row.
45
+ * therefore the CALL's three counts, deliberately not an audit row. Where the deletion and the
46
+ * sweep's context live on two sides — a SQL backend writes the deletion, the deployment holds the op —
47
+ * the deployment writes the audit row through the backend's `audit` transaction hook, inside the
48
+ * deleting transaction, from the receipt it is handed there.
46
49
  */
47
50
  export interface ManagedRetentionCapability {
48
51
  /** Enumerate the retention domains (tenant/scope keys) this store holds data for. */
@@ -32,15 +32,15 @@ export declare function retiredKeyRefusal(hit: {
32
32
  * tables (this one and `runner/retired-runner-deps.ts`). The record's callbacks never run, so a deny one carried would pass
33
33
  * unseen — the key is refused by name instead. */
34
34
  export declare const RETIRED_HOOKS_REPLACEMENT = "the callback seats are `mods` registrations now \u2014 register the extension on `RunnerDeps.mods` (a deployment's) or `TaskSpec.mods` (a task's), hung on the `classic.*` events (`classic.PreToolUse`, `classic.PostToolUse`, `classic.PostToolBatch`, `classic.UserPromptSubmit`, `classic.Stop`, `classic.SubagentStop`, \u2026); a callback that denied is a handler answering `{ action: \"deny\", message }`";
35
- /** The RETIRED `TaskSpec` keys, each with the sentence that names its replacement — the table the spec door reads
36
- * ({@link assertNoRetiredKeys} with owner `TaskSpec`). A caller still writing one of these is refused by name
35
+ /** The RETIRED `TaskSpec` keys, each with the sentence that names its replacement — the table the spec's one read judges
36
+ * (`readCallerSpec`, over the values it took: {@link retiredKeyOf}, owner `TaskSpec`). A caller still writing one of these is refused by name
37
37
  * (`config.spec_retired_key`), never read as absence: a mode a caller believes it declared must not silently run
38
38
  * as another. Each retired row has ONE reader: a row inside a seat that is read once by its own reader lives in that
39
- * seat's table ({@link RETIRED_SKILLS_SEAT_KEYS}), so the spec door never reads into the seat a second time. */
39
+ * seat's table ({@link RETIRED_SKILLS_SEAT_KEYS}), so the spec's read never reads into the seat a second time. */
40
40
  export declare const RETIRED_TASK_SPEC_KEYS: Readonly<Record<string, string>>;
41
41
  /** The RETIRED `TaskSpec.skills` rows — the table the skills seat's one reader (`readSkillsSeat`) judges over its one read of
42
42
  * the seat, owner `TaskSpec` (same code, same `TaskSpec.skills[].…` sentence). Kept out of {@link RETIRED_TASK_SPEC_KEYS}:
43
- * the spec door reading these rows would read the caller's `skills` before the seat's reader does. */
43
+ * the spec's read judging these rows would read into the caller's `skills` entries before the seat's reader does. */
44
44
  export declare const RETIRED_SKILLS_SEAT_KEYS: Readonly<Record<string, string>>;
45
45
  /** The RETIRED `ToolSpec` members — a spec still carrying one is refused by name (`config.deps_retired_key`) where the
46
46
  * factory reads the spec, never dropped unseen: a description the author wrote for one prompt shape would silently
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A direct writer's commit point: a conversation row the leg adds itself (a reconcile's result, a restated frame, a resumed
3
+ * call's settled result) passes the leg's one admission seat first — `session.append` (`mods/session-append.ts`), the seat
4
+ * the harness calls at its own commit points — and then the store keeps it. The seat may rewrite the row in place; what is
5
+ * stored, and what the caller reads off the row after, is the row as admitted. Absent seat ⇒ the row as made.
6
+ */
7
+ import type { AgentMessage, RowAdmission } from "../internal/harness-types.js";
8
+ export declare function appendAdmittedRow(admit: RowAdmission | undefined, session: {
9
+ appendMessage(message: AgentMessage): Promise<string>;
10
+ }, row: AgentMessage): Promise<string>;
@@ -0,0 +1,5 @@
1
+ export async function appendAdmittedRow(admit, session, row) {
2
+ if (admit !== undefined)
3
+ await admit([row]);
4
+ return session.appendMessage(row);
5
+ }
@@ -4,7 +4,7 @@
4
4
  * the `advisor_tool` attachment kind: it rides a fresh leg's first request, and a compaction inside a leg that mounts the
5
5
  * tool restates the full text right after it lands. Model lane only: no `steering_injected` echo.
6
6
  */
7
- import type { AnnouncedAdvisorState, AnnouncedListingSnapshotInput } from "../../internal/harness.js";
7
+ import type { AnnouncedAdvisorState, AnnouncedListingSnapshotInput, RowAdmission } from "../../internal/harness.js";
8
8
  import type { PostureFrameRef } from "../auto-mode-directive.js";
9
9
  import type { StoredSession } from "../session.js";
10
10
  import type { FrameReceiptLedger } from "./contracts.js";
@@ -63,6 +63,7 @@ export declare function appendAdvisorRestate(prepared: {
63
63
  readonly advisorInstruction?: AdvisorInstructionSeat;
64
64
  readonly reminderMark: string;
65
65
  readonly session: Pick<StoredSession, "appendMessage">;
66
+ readonly admitRows: RowAdmission;
66
67
  readonly batchHaltRef: {
67
68
  readonly current?: unknown;
68
69
  };
@@ -1,3 +1,4 @@
1
+ import { appendAdmittedRow } from "../row-admission.js";
1
2
  import { mintSystemReminder } from "../reminder-mint.js";
2
3
  import { thrownText } from "../thrown-value.js";
3
4
  export const ADVISOR_TOOL_INSTRUCTIONS = `# Advisor Tool
@@ -49,7 +50,7 @@ export async function appendAdvisorRestate(prepared) {
49
50
  return;
50
51
  const text = mintSystemReminder(ADVISOR_TOOL_INSTRUCTIONS, prepared.reminderMark);
51
52
  try {
52
- await prepared.session.appendMessage({ role: "user", content: [{ type: "text", text }], timestamp: Date.now(), engineMinted: true });
53
+ await appendAdmittedRow(prepared.admitRows, prepared.session, { role: "user", content: [{ type: "text", text }], timestamp: Date.now(), engineMinted: true });
53
54
  }
54
55
  catch (err) {
55
56
  try {
@@ -3,10 +3,10 @@ import type { AnnounceOnceSink } from "./contracts.js";
3
3
  import type { McpDroppedTool, McpServerStatus } from "../mcp.js";
4
4
  import type { McpUnavailableEntry } from "../mcp-failure.js";
5
5
  import type { RunnerDeps } from "../types.js";
6
- /** Upper bound on the advisory-digest arm kept in the record (oldest dropped past it). A digest is
7
- * 64 hex chars; a session accumulates a handful of distinct advisories, never hundreds — the bound
8
- * keeps a pathological deployment (a warning whose text embeds a per-run value) from growing the
9
- * snapshot without limit while still holding every realistic set. */
6
+ /** Upper bound on the advisory-digest arm kept in the record (oldest dropped past it). A digest is 64 hex chars; the arm
7
+ * holds a session's distinct advisories (a handful) and the digest of every media block the request budget cut and told
8
+ * (`media-removed-seat.ts` — a session with many images can pass the bound): past it the oldest go, whichever face wrote
9
+ * them, and their fact is said again by a later run, never lost. The bound keeps the snapshot finite. */
10
10
  export declare const ANNOUNCE_ONCE_MAX_DIGESTS = 200;
11
11
  /** Stable digest of one announcement: `sha256(lane \n text)` as hex. Opaque on the wire; only ever
12
12
  * compared for equality. */
@@ -1,8 +1,8 @@
1
1
  import type { AssistantMessage } from "../../internal/llm.js";
2
2
  import type { HumanReviewGateRow } from "../task-result.js";
3
- import type { NestedUsage, PausedCause, TaskResult, TaskSpec, TerminalCause } from "../types.js";
3
+ import type { NestedUsage, PausedCause, TaskResult, TerminalCause } from "../types.js";
4
4
  import type { TerminalBlockedDetail } from "../terminal-cause.js";
5
- import type { HaltConsumption } from "../../internal/harness.js";
5
+ import type { HaltConsumption, LoopTerminalReason } from "../../internal/harness.js";
6
6
  /** Per-task usage/cost accumulator (filled across the run loop, surfaced as `TaskResult.stats`). */
7
7
  export interface Stats {
8
8
  turns: number;
@@ -166,6 +166,9 @@ export interface ResultFlags {
166
166
  * read-posture seats above: present iff prepare completed (the memory-less states are their own
167
167
  * values — absence means only "prepare never ran to completion"). */
168
168
  effectiveMemoryScopes?: TaskResult["effectiveMemoryScopes"];
169
+ /** The leg's frozen placement fixed point, echoed on `TaskResult.placementRoot`. Pure pass-through on every terminal (the
170
+ * same law as the observation seats above); absent ⇒ the key is omitted. */
171
+ placementRoot?: TaskResult["placementRoot"];
169
172
  /** The leg's effective reasoning resolution, echoed on `TaskResult.effectiveReasoning`.
170
173
  * Pure pass-through on every terminal (same law as the read-posture seats): the SAME object the
171
174
  * `reasoning.resolved` trace frame carried (runtask resolves once per leg — two faces, one mint);
@@ -203,6 +206,8 @@ export interface ResultFlags {
203
206
  * the loop folded it into a text-only failure message, so the typed code rides this flag. */
204
207
  gitCoreOverBudget?: boolean;
205
208
  outputInvalid?: boolean;
209
+ /** The word the loop's last exit named (`Prepared.loopTerminalRef`), read through `loopExitFailureOf`; absent = the loop never exited. */
210
+ loopTerminal?: LoopTerminalReason;
206
211
  /** A re-suspend was refused because the task already suspended `maxSuspends` times
207
212
  * (a resume/restart loop). It aborted the run (no `threw`) but must read as `failed`/`suspend.loop`,
208
213
  * NOT `suspended` — slotted ABOVE `suspendRef` and the aborted branches (this suspend never minted a
@@ -307,6 +312,11 @@ export declare function terminalCauseOf(final: AssistantMessage | undefined, sta
307
312
  * the pass-through seat; an accepted-but-unconsumed halt never reaches this slot)
308
313
  * 10. no `final` → status `"failed"`
309
314
  * 11. stopReason error → brain `[code]` prefix (or `"conflict"` from the storage-layer flag)
315
+ * 11.5 the loop exited on a spent recovery budget (`loopTerminal`, read through `loopExitFailureOf`) →
316
+ * `"model.malformed_tool_use_exhausted"` | `"model.truncated_output_exhausted"` (status `"failed"`)
310
317
  * 12. else → `"completed"`
311
318
  */
312
- export declare function assembleResult(spec: TaskSpec, sessionId: string, final: AssistantMessage | undefined, stats: Stats, flags: ResultFlags): TaskResult;
319
+ export declare function assembleResult(leg: {
320
+ readonly taskId: string;
321
+ readonly sessionId: string;
322
+ }, final: AssistantMessage | undefined, stats: Stats, flags: ResultFlags): TaskResult;
@@ -1,6 +1,6 @@
1
1
  import { isDegenerateCutMessage } from "../../brain/terminal-cause.js";
2
2
  import { extractErrorCode, isProviderEchoShape, refusedTheRequest, stripErrorCodePrefix } from "../../brain/errors.js";
3
- import { completedTerminalOf, modelOutputInvalidOfMessage, providerVerdictOf, requestRouteOfMessage, thrownFailureOf } from "./terminal-account.js";
3
+ import { completedTerminalOf, loopExitFailureOf, modelOutputInvalidOfMessage, providerVerdictOf, refusedPartOf, requestRouteOfMessage, thrownFailureOf } from "./terminal-account.js";
4
4
  import { terminalProjection } from "./terminal-projection.js";
5
5
  import { haltConsumed } from "./halt-attribution.js";
6
6
  import { providerReportedModel } from "../message-utils.js";
@@ -50,7 +50,9 @@ export function terminalCauseOf(final, stats, flags) {
50
50
  !flags.abortedLive &&
51
51
  flags.abortedForTimeout !== true &&
52
52
  flags.abortedForTurns !== true;
53
- const isDegenerate = final?.stopReason === "error" && isDegenerateCutMessage(final);
53
+ const errorKind = readMember(final, "errorKind");
54
+ const isDegenerate = final?.stopReason === "error" && isDegenerateCutMessage({ errorKind: errorKind });
55
+ const loopExit = loopExitFailureOf(flags.loopTerminal);
54
56
  if (flags.outputInvalid) {
55
57
  terminal = { kind: "failed", code: "output.invalid", message: "model did not produce a valid structured output within the retry limit" };
56
58
  }
@@ -97,7 +99,7 @@ export function terminalCauseOf(final, stats, flags) {
97
99
  const code = flags.abortedForTimeout ? "limits.max_walltime_exceeded" : flags.abortedForTurns ? "limits.max_turns_exceeded" : undefined;
98
100
  terminal = { kind: "failed", ...(code !== undefined ? { code } : {}), message: final?.errorMessage ?? (flags.abortedForTurns ? "max turns exceeded" : "run aborted") };
99
101
  }
100
- else if (haltConsumed(flags.haltConsumption) && (!final || haltOwnsAbortedFinal)) {
102
+ else if ((haltConsumed(flags.haltConsumption) && (!final || haltOwnsAbortedFinal)) || (flags.haltedOnUserRejection === true && !final)) {
101
103
  terminal = { kind: "completed" };
102
104
  }
103
105
  else if (!final) {
@@ -137,20 +139,23 @@ export function terminalCauseOf(final, stats, flags) {
137
139
  let detail;
138
140
  if (messageNamed && apiError && typeof apiStatus === "number" && refusedTheRequest(apiStatus)) {
139
141
  const route = requestRouteOfMessage(final);
140
- detail = { kind: "provider_rejected", status: apiStatus, ...(typeof apiCode === "string" && isProviderEchoShape(apiCode) ? { code: apiCode } : {}), ...providerVerdictOf(final), ...(route !== undefined ? { route } : {}) };
142
+ detail = { kind: "provider_rejected", status: apiStatus, ...(typeof apiCode === "string" && isProviderEchoShape(apiCode) ? { code: apiCode } : {}), ...providerVerdictOf(final), ...(route !== undefined ? { route } : {}), ...refusedPartOf(errorKind, readMember(final, "refusedTool")) };
141
143
  }
142
144
  else if (messageNamed && outputInvalid !== undefined) {
143
145
  detail = { kind: "model_output_invalid", ...outputInvalid };
144
146
  }
145
147
  terminal = { kind: "failed", code, message, ...(detail !== undefined ? { detail } : {}) };
146
148
  }
149
+ else if (loopExit !== undefined) {
150
+ terminal = { kind: "failed", code: loopExit.code, message: loopExit.message };
151
+ }
147
152
  else {
148
153
  terminal = completedTerminalOf(final);
149
154
  }
150
155
  return { terminal, apiFailure };
151
156
  }
152
- export function assembleResult(spec, sessionId, final, stats, flags) {
153
- const taskId = spec.taskId ?? sessionId;
157
+ export function assembleResult(leg, final, stats, flags) {
158
+ const { taskId, sessionId } = leg;
154
159
  const text = final ? assistantText(final) : "";
155
160
  const responseModel = final === undefined ? undefined : providerReportedModel(final);
156
161
  if (!flags.unpricedSpend) {
@@ -177,5 +182,5 @@ export function assembleResult(spec, sessionId, final, stats, flags) {
177
182
  if (flags.unpricedSpend)
178
183
  delete publicStats.costMicroUsd;
179
184
  const stampHaltedByUser = haltConsumed(flags.haltConsumption);
180
- return { taskId, ...(flags.runId !== undefined ? { runId: flags.runId } : {}), sessionId, terminal, ...(flags.model !== undefined ? { model: flags.model } : {}), ...(responseModel !== undefined ? { responseModel } : {}), result: result.trim(), ...(flags.answerEntryIds !== undefined ? { resultEntryIds: [...flags.answerEntryIds] } : {}), salvagedOutput, ...(apiFailure !== undefined ? { apiFailure } : {}), ...(retryAfterMs !== undefined ? { retryAfterMs } : {}), ...(flags.rewindNotes !== undefined && flags.rewindNotes.length > 0 ? { rewindNotes: flags.rewindNotes } : {}), ...(flags.editedFiles !== undefined && flags.editedFiles.length > 0 ? { editedFiles: flags.editedFiles } : {}), ...(flags.haltedOnUserRejection === true ? { haltedOnUserRejection: true } : {}), ...(stampHaltedByUser ? { haltedByUser: true } : {}), ...(flags.remoteEnvFailures !== undefined && flags.remoteEnvFailures.length > 0 ? { remoteEnvFailures: [...flags.remoteEnvFailures] } : {}), ...(flags.strandedHumanAnswers !== undefined && flags.strandedHumanAnswers.length > 0 ? { strandedHumanAnswers: flags.strandedHumanAnswers } : {}), ...(flags.effectiveReadFace !== undefined ? { effectiveReadFace: flags.effectiveReadFace } : {}), ...(flags.effectiveWriteFace !== undefined ? { effectiveWriteFace: flags.effectiveWriteFace } : {}), ...(flags.effectiveReadDenyPatterns !== undefined && flags.effectiveReadDenyPatterns.length > 0 ? { effectiveReadDenyPatterns: flags.effectiveReadDenyPatterns } : {}), ...(flags.effectiveMemoryScopes !== undefined ? { effectiveMemoryScopes: flags.effectiveMemoryScopes } : {}), ...(flags.effectiveReasoning !== undefined ? { effectiveReasoning: flags.effectiveReasoning } : {}), ...(flags.compaction !== undefined ? { compaction: flags.compaction } : {}), stats: publicStats };
185
+ return { taskId, ...(flags.runId !== undefined ? { runId: flags.runId } : {}), sessionId, terminal, ...(flags.model !== undefined ? { model: flags.model } : {}), ...(responseModel !== undefined ? { responseModel } : {}), result: result.trim(), ...(flags.answerEntryIds !== undefined ? { resultEntryIds: [...flags.answerEntryIds] } : {}), salvagedOutput, ...(apiFailure !== undefined ? { apiFailure } : {}), ...(retryAfterMs !== undefined ? { retryAfterMs } : {}), ...(flags.rewindNotes !== undefined && flags.rewindNotes.length > 0 ? { rewindNotes: flags.rewindNotes } : {}), ...(flags.editedFiles !== undefined && flags.editedFiles.length > 0 ? { editedFiles: flags.editedFiles } : {}), ...(flags.haltedOnUserRejection === true ? { haltedOnUserRejection: true } : {}), ...(stampHaltedByUser ? { haltedByUser: true } : {}), ...(flags.remoteEnvFailures !== undefined && flags.remoteEnvFailures.length > 0 ? { remoteEnvFailures: [...flags.remoteEnvFailures] } : {}), ...(flags.strandedHumanAnswers !== undefined && flags.strandedHumanAnswers.length > 0 ? { strandedHumanAnswers: flags.strandedHumanAnswers } : {}), ...(flags.effectiveReadFace !== undefined ? { effectiveReadFace: flags.effectiveReadFace } : {}), ...(flags.effectiveWriteFace !== undefined ? { effectiveWriteFace: flags.effectiveWriteFace } : {}), ...(flags.effectiveReadDenyPatterns !== undefined && flags.effectiveReadDenyPatterns.length > 0 ? { effectiveReadDenyPatterns: flags.effectiveReadDenyPatterns } : {}), ...(flags.effectiveMemoryScopes !== undefined ? { effectiveMemoryScopes: flags.effectiveMemoryScopes } : {}), ...(flags.placementRoot !== undefined ? { placementRoot: flags.placementRoot } : {}), ...(flags.effectiveReasoning !== undefined ? { effectiveReasoning: flags.effectiveReasoning } : {}), ...(flags.compaction !== undefined ? { compaction: flags.compaction } : {}), stats: publicStats };
181
186
  }