@sema-agent/core 7.57.0 → 7.59.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 (399) hide show
  1. package/CHANGELOG.md +1161 -0
  2. package/README.md +6 -4
  3. package/dist/agents/cc-peer-directory.js +8 -8
  4. package/dist/agents/child-model-seat.d.ts +4 -2
  5. package/dist/agents/child-model-seat.js +5 -3
  6. package/dist/agents/peer-directory.d.ts +9 -0
  7. package/dist/agents/peer-directory.js +6 -2
  8. package/dist/agents/send-message-tool.js +21 -12
  9. package/dist/agents/subagent-steps.js +2 -4
  10. package/dist/agents/subagent.js +33 -34
  11. package/dist/brain/anthropic.js +161 -45
  12. package/dist/brain/errors.d.ts +9 -3
  13. package/dist/brain/errors.js +7 -1
  14. package/dist/brain/failover.js +2 -1
  15. package/dist/brain/open-responses.js +3 -3
  16. package/dist/brain/openai.js +103 -53
  17. package/dist/brain/provider-dialect.d.ts +11 -0
  18. package/dist/brain/provider-dialect.js +5 -2
  19. package/dist/brain/reasoning-request.js +5 -4
  20. package/dist/brain/reasoning.d.ts +19 -0
  21. package/dist/brain/reasoning.js +17 -2
  22. package/dist/brain/request-route.d.ts +4 -1
  23. package/dist/brain/request-route.js +4 -1
  24. package/dist/brain/route-adjudicator.d.ts +84 -18
  25. package/dist/brain/route-adjudicator.js +89 -22
  26. package/dist/brain/route-conformance.js +1 -1
  27. package/dist/brain/stream-engine.js +84 -49
  28. package/dist/brain/stream-shared.d.ts +30 -0
  29. package/dist/brain/stream-shared.js +34 -1
  30. package/dist/brain/timeout.d.ts +62 -5
  31. package/dist/brain/timeout.js +93 -6
  32. package/dist/core/a2a.d.ts +2 -1
  33. package/dist/core/a2a.js +23 -10
  34. package/dist/core/account-row.d.ts +61 -0
  35. package/dist/core/account-row.js +51 -0
  36. package/dist/core/advisor-verdict.d.ts +2 -1
  37. package/dist/core/advisor-verdict.js +1 -1
  38. package/dist/core/allow-entry.d.ts +20 -7
  39. package/dist/core/allow-entry.js +18 -9
  40. package/dist/core/approval-object.d.ts +29 -15
  41. package/dist/core/approval-object.js +47 -19
  42. package/dist/core/ask-origin.d.ts +21 -2
  43. package/dist/core/ask-origin.js +5 -1
  44. package/dist/core/auto-compaction.d.ts +4 -0
  45. package/dist/core/auto-compaction.js +2 -2
  46. package/dist/core/auto-mode-directive.d.ts +29 -5
  47. package/dist/core/auto-mode-directive.js +38 -8
  48. package/dist/core/background-agent-store.d.ts +16 -3
  49. package/dist/core/checkpoint-requirements.d.ts +19 -1
  50. package/dist/core/checkpoint-requirements.js +5 -1
  51. package/dist/core/checkpoint-store.d.ts +85 -23
  52. package/dist/core/checkpoint-store.js +31 -9
  53. package/dist/core/child-clamp-seats.d.ts +29 -0
  54. package/dist/core/child-clamp-seats.js +56 -1
  55. package/dist/core/compliance.d.ts +2 -2
  56. package/dist/core/compliance.js +1 -1
  57. package/dist/core/effective-path-target.d.ts +8 -2
  58. package/dist/core/effective-path-target.js +8 -3
  59. package/dist/core/engine-notice.d.ts +99 -9
  60. package/dist/core/engine-notice.js +19 -5
  61. package/dist/core/fs-write-gate-policy.d.ts +4 -2
  62. package/dist/core/fs-write-gate-policy.js +7 -3
  63. package/dist/core/gate-fold.js +7 -4
  64. package/dist/core/gate-lanes.js +19 -6
  65. package/dist/core/gate-outcome.d.ts +32 -3
  66. package/dist/core/gate-outcome.js +19 -1
  67. package/dist/core/git-worktree-env.d.ts +53 -11
  68. package/dist/core/git-worktree-env.js +96 -12
  69. package/dist/core/governance-codes.d.ts +9 -1
  70. package/dist/core/governance-codes.js +13 -0
  71. package/dist/core/hooks.d.ts +35 -4
  72. package/dist/core/hooks.js +17 -11
  73. package/dist/core/human-input-projection.d.ts +1 -0
  74. package/dist/core/human-input-projection.js +3 -0
  75. package/dist/core/image-admission.d.ts +6 -5
  76. package/dist/core/image-admission.js +18 -14
  77. package/dist/core/locked-config.d.ts +20 -3
  78. package/dist/core/locked-config.js +40 -3
  79. package/dist/core/mailbox-store.d.ts +45 -1
  80. package/dist/core/mailbox-store.js +53 -9
  81. package/dist/core/mcp-call-meta.d.ts +66 -0
  82. package/dist/core/mcp-call-meta.js +103 -0
  83. package/dist/core/mcp-connection-pool.d.ts +3 -1
  84. package/dist/core/mcp-connection-pool.js +3 -1
  85. package/dist/core/mcp-failure.d.ts +117 -15
  86. package/dist/core/mcp-failure.js +71 -3
  87. package/dist/core/mcp-probe.d.ts +4 -0
  88. package/dist/core/mcp-probe.js +1 -1
  89. package/dist/core/mcp-server-link.d.ts +27 -3
  90. package/dist/core/mcp-server-link.js +25 -1
  91. package/dist/core/mcp-server-spec.d.ts +46 -18
  92. package/dist/core/mcp-server-spec.js +1 -18
  93. package/dist/core/mcp.d.ts +16 -20
  94. package/dist/core/mcp.js +112 -55
  95. package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
  96. package/dist/core/memory-engine/consolidation-driver.js +3 -3
  97. package/dist/core/memory-engine/consolidation.d.ts +4 -0
  98. package/dist/core/memory-engine/consolidation.js +1 -0
  99. package/dist/core/memory-engine/delegation-settlement.js +5 -12
  100. package/dist/core/memory-engine/distiller.js +2 -2
  101. package/dist/core/memory-engine/dual-root.d.ts +50 -1
  102. package/dist/core/memory-engine/dual-root.js +44 -1
  103. package/dist/core/memory-engine/engine.d.ts +67 -14
  104. package/dist/core/memory-engine/engine.js +384 -212
  105. package/dist/core/memory-engine/export-bundle.d.ts +23 -0
  106. package/dist/core/memory-engine/export-bundle.js +23 -4
  107. package/dist/core/memory-engine/file-backend.d.ts +128 -55
  108. package/dist/core/memory-engine/file-backend.js +290 -117
  109. package/dist/core/memory-engine/index.d.ts +1 -1
  110. package/dist/core/memory-engine/layout.d.ts +59 -11
  111. package/dist/core/memory-engine/layout.js +190 -40
  112. package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
  113. package/dist/core/memory-engine/memory-backend-contract.js +39 -2
  114. package/dist/core/memory-engine/scope-contract.d.ts +45 -4
  115. package/dist/core/memory-engine/scope-contract.js +80 -11
  116. package/dist/core/memory-engine/sync-client.d.ts +9 -1
  117. package/dist/core/memory-engine/sync-client.js +31 -8
  118. package/dist/core/memory-engine/sync.d.ts +5 -0
  119. package/dist/core/memory-engine/types.d.ts +6 -0
  120. package/dist/core/mode-policy.d.ts +8 -5
  121. package/dist/core/mode-policy.js +5 -4
  122. package/dist/core/mods/classic-events.d.ts +5 -1
  123. package/dist/core/mods/host.js +1 -1
  124. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  125. package/dist/core/mods/kernel/dispatch.js +12 -9
  126. package/dist/core/mods/kernel/events.d.ts +6 -1
  127. package/dist/core/mods/kernel/events.js +2 -2
  128. package/dist/core/mods/kernel/registration.d.ts +9 -1
  129. package/dist/core/mods/kernel/registration.js +3 -0
  130. package/dist/core/mods/kernel/site-rules.d.ts +3 -0
  131. package/dist/core/mods/kernel/site-rules.js +10 -0
  132. package/dist/core/mods/package.d.ts +23 -0
  133. package/dist/core/mods/package.js +118 -0
  134. package/dist/core/mods/stations.d.ts +33 -12
  135. package/dist/core/mods/stations.js +45 -11
  136. package/dist/core/mods/tool-call.d.ts +5 -1
  137. package/dist/core/mods/tool-call.js +13 -4
  138. package/dist/core/parent-spec-seat.d.ts +8 -3
  139. package/dist/core/parent-spec-seat.js +2 -0
  140. package/dist/core/park-selfcheck.js +6 -0
  141. package/dist/core/path-guard-rows.d.ts +20 -0
  142. package/dist/core/path-guard-rows.js +11 -0
  143. package/dist/core/peer-seat.d.ts +248 -0
  144. package/dist/core/peer-seat.js +439 -0
  145. package/dist/core/permission-rule-consent.js +10 -4
  146. package/dist/core/permission-rule-model.d.ts +16 -0
  147. package/dist/core/permission-rule-model.js +1 -1
  148. package/dist/core/present-plan-tool.d.ts +20 -3
  149. package/dist/core/present-plan-tool.js +48 -4
  150. package/dist/core/protocol-http-auth.d.ts +40 -29
  151. package/dist/core/protocol-http-auth.js +30 -32
  152. package/dist/core/redaction-marks.d.ts +16 -0
  153. package/dist/core/redaction-marks.js +16 -0
  154. package/dist/core/redaction-passes.js +8 -9
  155. package/dist/core/resume-startup-cause.js +1 -0
  156. package/dist/core/retention.d.ts +41 -15
  157. package/dist/core/retention.js +59 -12
  158. package/dist/core/rewrite-rejudge.d.ts +38 -0
  159. package/dist/core/rewrite-rejudge.js +42 -2
  160. package/dist/core/roles.d.ts +34 -2
  161. package/dist/core/roles.js +43 -4
  162. package/dist/core/run-origin.d.ts +40 -0
  163. package/dist/core/run-origin.js +37 -0
  164. package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
  165. package/dist/core/runner/advertised-writable-dirs.js +126 -0
  166. package/dist/core/runner/announce-once-ledger.d.ts +5 -4
  167. package/dist/core/runner/announce-once-ledger.js +4 -2
  168. package/dist/core/runner/call-hook-stations.js +2 -2
  169. package/dist/core/runner/compaction-restate.d.ts +15 -6
  170. package/dist/core/runner/compaction-restate.js +28 -2
  171. package/dist/core/runner/contracts.d.ts +33 -21
  172. package/dist/core/runner/credential-origin-seat.js +4 -3
  173. package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
  174. package/dist/core/runner/cwd-alignment-probe.js +21 -0
  175. package/dist/core/runner/decide-continuation.d.ts +2 -2
  176. package/dist/core/runner/gate-exit.d.ts +30 -8
  177. package/dist/core/runner/gate-exit.js +15 -8
  178. package/dist/core/runner/image-removed-seat.d.ts +12 -0
  179. package/dist/core/runner/image-removed-seat.js +19 -0
  180. package/dist/core/runner/inline-image.js +1 -1
  181. package/dist/core/runner/memory-consolidation-driver.js +3 -3
  182. package/dist/core/runner/park-commit.d.ts +1 -1
  183. package/dist/core/runner/park-commit.js +3 -0
  184. package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
  185. package/dist/core/runner/prepare-ask-lane.js +2 -1
  186. package/dist/core/runner/prepare-boundary-parks.js +2 -2
  187. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
  188. package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
  189. package/dist/core/runner/prepare-config-doors.d.ts +8 -5
  190. package/dist/core/runner/prepare-config-doors.js +14 -10
  191. package/dist/core/runner/prepare-context-lane.js +2 -0
  192. package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
  193. package/dist/core/runner/prepare-delegation-surface.js +16 -18
  194. package/dist/core/runner/prepare-gate-stations.js +1 -1
  195. package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
  196. package/dist/core/runner/prepare-hands-readface.js +9 -1
  197. package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
  198. package/dist/core/runner/prepare-inherited-gate.js +14 -27
  199. package/dist/core/runner/prepare-memory.d.ts +3 -0
  200. package/dist/core/runner/prepare-memory.js +26 -37
  201. package/dist/core/runner/prepare-park-ask.d.ts +1 -1
  202. package/dist/core/runner/prepare-park-ask.js +2 -1
  203. package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
  204. package/dist/core/runner/prepare-policy-chain.js +18 -15
  205. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  206. package/dist/core/runner/prepare-project-context.js +2 -2
  207. package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
  208. package/dist/core/runner/prepare-prompt-inputs.js +8 -19
  209. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
  210. package/dist/core/runner/prepare-protocol-tools.js +11 -3
  211. package/dist/core/runner/prepare-run-refs.d.ts +2 -3
  212. package/dist/core/runner/prepare-run-refs.js +4 -1
  213. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  214. package/dist/core/runner/prepare-suspend-saga.js +2 -1
  215. package/dist/core/runner/prepare-task.js +28 -13
  216. package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
  217. package/dist/core/runner/prepare-wiring-manifest.js +4 -3
  218. package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
  219. package/dist/core/runner/prepare-workspace-restore.js +4 -4
  220. package/dist/core/runner/reply-pricing.d.ts +30 -0
  221. package/dist/core/runner/reply-pricing.js +19 -0
  222. package/dist/core/runner/resume-admission.js +5 -3
  223. package/dist/core/runner/resume-apply.js +6 -1
  224. package/dist/core/runner/resume-checkpoint-screen.js +2 -0
  225. package/dist/core/runner/resume-policy-outcome.js +5 -5
  226. package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
  227. package/dist/core/runner/role-seat-defaulted.js +40 -0
  228. package/dist/core/runner/run-brain-sinks.js +2 -0
  229. package/dist/core/runner/run-harness-handlers.d.ts +3 -4
  230. package/dist/core/runner/run-harness-handlers.js +1 -8
  231. package/dist/core/runner/run-identity-wiring.d.ts +2 -5
  232. package/dist/core/runner/run-identity-wiring.js +6 -4
  233. package/dist/core/runner/run-leg.d.ts +2 -0
  234. package/dist/core/runner/run-leg.js +42 -29
  235. package/dist/core/runner/run-notification-lane.js +3 -0
  236. package/dist/core/runner/run-stop-and-final-verify.js +2 -2
  237. package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
  238. package/dist/core/runner/run-terminal-adoption.js +9 -3
  239. package/dist/core/runner/run-turn-boundary.js +77 -70
  240. package/dist/core/runner/runtask.d.ts +1 -1
  241. package/dist/core/runner/runtask.js +2 -2
  242. package/dist/core/runner/side-call-account.d.ts +1 -1
  243. package/dist/core/runner/side-call-account.js +3 -18
  244. package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
  245. package/dist/core/runner/sub-agent-deny-lists.js +10 -0
  246. package/dist/core/runner/terminal-account.js +3 -3
  247. package/dist/core/runner/tool-end-body.js +2 -1
  248. package/dist/core/runner/tool-occurrence.d.ts +5 -2
  249. package/dist/core/runner/tool-occurrence.js +4 -3
  250. package/dist/core/runner/turn-attachments.d.ts +26 -22
  251. package/dist/core/runner/turn-attachments.js +24 -26
  252. package/dist/core/runner/write-protection-station.d.ts +8 -2
  253. package/dist/core/runner/write-protection-station.js +2 -0
  254. package/dist/core/runner-deps.d.ts +3 -3
  255. package/dist/core/secret-env.d.ts +32 -2
  256. package/dist/core/secret-env.js +65 -3
  257. package/dist/core/sensitive-path-policy.js +9 -10
  258. package/dist/core/session-log-transfer.d.ts +24 -0
  259. package/dist/core/session-log-transfer.js +166 -0
  260. package/dist/core/session-policy-store.d.ts +3 -1
  261. package/dist/core/session-policy-store.js +13 -9
  262. package/dist/core/session-store.d.ts +86 -24
  263. package/dist/core/session-store.js +162 -24
  264. package/dist/core/session.d.ts +92 -1
  265. package/dist/core/shell-read-silence.js +1 -0
  266. package/dist/core/side-query.d.ts +11 -1
  267. package/dist/core/side-query.js +9 -0
  268. package/dist/core/skill-grant-binding.d.ts +31 -2
  269. package/dist/core/skill-grant-binding.js +31 -1
  270. package/dist/core/skill-grant.d.ts +8 -5
  271. package/dist/core/skill-grant.js +6 -6
  272. package/dist/core/steer-replay.d.ts +4 -2
  273. package/dist/core/steer-replay.js +2 -1
  274. package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
  275. package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
  276. package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
  277. package/dist/core/store-contracts/session-repo-contract.js +112 -5
  278. package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
  279. package/dist/core/store-contracts/session-store-contract.js +236 -2
  280. package/dist/core/synthetic-read-verdict.js +2 -1
  281. package/dist/core/task-event.d.ts +92 -8
  282. package/dist/core/task-notification.js +16 -10
  283. package/dist/core/task-registry-agent.js +1 -0
  284. package/dist/core/task-registry-shared.d.ts +7 -1
  285. package/dist/core/task-spec.d.ts +49 -1
  286. package/dist/core/task-stream.d.ts +2 -1
  287. package/dist/core/terminal-cause.d.ts +11 -1
  288. package/dist/core/tool-catalog-entries.js +1 -0
  289. package/dist/core/tool-check-reading.d.ts +1 -0
  290. package/dist/core/tool-check-reading.js +3 -3
  291. package/dist/core/tool-policy.d.ts +16 -0
  292. package/dist/core/tool-result-store.d.ts +17 -10
  293. package/dist/core/tool-result-store.js +3 -1
  294. package/dist/core/tool-roster.d.ts +112 -5
  295. package/dist/core/tool-roster.js +42 -1
  296. package/dist/core/tool-spec.d.ts +3 -1
  297. package/dist/core/types.d.ts +3 -3
  298. package/dist/core/types.js +1 -1
  299. package/dist/core/untrusted-egress.d.ts +0 -2
  300. package/dist/core/untrusted-egress.js +10 -14
  301. package/dist/core/user-attachment.js +1 -1
  302. package/dist/core/wiring-manifest.d.ts +18 -6
  303. package/dist/core/wiring-manifest.js +4 -3
  304. package/dist/core/workspace-snapshot.d.ts +44 -0
  305. package/dist/core/workspace-snapshot.js +34 -0
  306. package/dist/core/write-protect.d.ts +43 -3
  307. package/dist/core/write-protect.js +43 -16
  308. package/dist/engine/compaction/compaction.js +29 -3
  309. package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
  310. package/dist/engine/execution-env/node-execution-env.js +24 -23
  311. package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
  312. package/dist/engine/harness/agent-harness.d.ts +30 -2
  313. package/dist/engine/harness/agent-harness.js +43 -12
  314. package/dist/engine/harness/messages.d.ts +3 -1
  315. package/dist/engine/harness/messages.js +3 -2
  316. package/dist/engine/harness/types.d.ts +56 -7
  317. package/dist/engine/harness/types.js +5 -1
  318. package/dist/engine/llm/rejected-images.d.ts +46 -0
  319. package/dist/engine/llm/rejected-images.js +54 -0
  320. package/dist/engine/llm/tool-turns.d.ts +2 -1
  321. package/dist/engine/llm/types.d.ts +30 -10
  322. package/dist/engine/llm/types.js +1 -1
  323. package/dist/engine/loop/agent-loop.d.ts +8 -0
  324. package/dist/engine/loop/agent-loop.js +52 -15
  325. package/dist/engine/loop/types.d.ts +3 -1
  326. package/dist/engine/session/import-validate.js +3 -0
  327. package/dist/engine/session/memory-repo.d.ts +17 -9
  328. package/dist/engine/session/memory-repo.js +44 -34
  329. package/dist/engine/session/path-to-root.d.ts +38 -0
  330. package/dist/engine/session/path-to-root.js +39 -0
  331. package/dist/engine/session/repo-utils.d.ts +22 -4
  332. package/dist/engine/session/repo-utils.js +49 -1
  333. package/dist/engine/session/storage-base.d.ts +10 -1
  334. package/dist/engine/session/storage-base.js +11 -22
  335. package/dist/index.d.ts +29 -16
  336. package/dist/index.js +21 -11
  337. package/dist/internal/harness-types.d.ts +2 -2
  338. package/dist/internal/harness.d.ts +3 -2
  339. package/dist/internal/harness.js +2 -2
  340. package/dist/internal/llm.d.ts +1 -0
  341. package/dist/orchestration/workflow-observe.d.ts +17 -1
  342. package/dist/orchestration/workflow-observe.js +20 -0
  343. package/dist/orchestration/workflow-types.d.ts +32 -7
  344. package/dist/orchestration/workflow.js +739 -489
  345. package/dist/shell/counting-pass.d.ts +50 -0
  346. package/dist/shell/counting-pass.js +502 -0
  347. package/dist/shell/lex.d.ts +4 -2
  348. package/dist/shell/lex.js +93 -34
  349. package/dist/shell/shell-words.d.ts +1 -1
  350. package/dist/shell/shell-words.js +7 -6
  351. package/dist/stores/file/index.d.ts +4 -1
  352. package/dist/stores/file/index.js +4 -1
  353. package/dist/stores/file/mailbox-store.js +6 -10
  354. package/dist/stores/file/session-store.d.ts +15 -8
  355. package/dist/stores/file/session-store.js +28 -13
  356. package/dist/tools/fs/fs-bash.d.ts +6 -0
  357. package/dist/tools/fs/fs-bash.js +6 -3
  358. package/dist/tools/fs/fs-write.d.ts +6 -3
  359. package/dist/tools/fs/fs-write.js +8 -7
  360. package/dist/tools/fs/index.d.ts +3 -0
  361. package/dist/tools/fs/index.js +7 -3
  362. package/dist/tools/fs/program-read-model.d.ts +13 -0
  363. package/dist/tools/fs/program-read-model.js +15 -0
  364. package/dist/tools/fs/program-read-model.rows.js +1 -1
  365. package/dist/tools/fs/read-deny.d.ts +13 -10
  366. package/dist/tools/fs/read-deny.js +25 -5
  367. package/dist/tools/fs/read-floor.d.ts +19 -0
  368. package/dist/tools/fs/read-floor.js +23 -0
  369. package/dist/tools/fs/safety.js +40 -8
  370. package/dist/tools/fs/search.js +6 -24
  371. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  372. package/dist/tools/fs/shell-read-check.js +61 -16
  373. package/dist/tools/fs/shell-read-establish.js +2 -1
  374. package/dist/tools/fs/shell-read-identity.js +1 -1
  375. package/dist/tools/fs/shell-read-judge.d.ts +26 -9
  376. package/dist/tools/fs/shell-read-judge.js +10 -6
  377. package/dist/tools/fs/shell-read-plan.d.ts +6 -1
  378. package/dist/tools/fs/shell-read-plan.js +22 -15
  379. package/dist/tools/fs/shell-read-start.js +1 -0
  380. package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
  381. package/dist/tools/fs/shell-reentry-text.js +25 -3
  382. package/dist/tools/monitor.d.ts +4 -0
  383. package/dist/tools/monitor.js +2 -0
  384. package/dist/tools/worktree.d.ts +42 -15
  385. package/dist/tools/worktree.js +60 -32
  386. package/package.json +5 -2
  387. package/test/export-surface.snapshot.json +149 -1
  388. package/wire-changes/core-stores-sql@7.58.0.json +29 -0
  389. package/wire-changes/core-stores-sql@7.59.0.json +29 -0
  390. package/wire-changes/core@7.58.0.json +2188 -0
  391. package/wire-changes/core@7.59.0.json +2459 -0
  392. package/wire-changes/mods-kernel@7.58.0.json +81 -0
  393. package/wire-changes/mods-kernel@7.59.0.json +29 -0
  394. package/wire-changes/primitives@7.58.0.json +29 -0
  395. package/wire-changes/primitives@7.59.0.json +29 -0
  396. package/dist/primitives/credential-ref.d.ts +0 -89
  397. package/dist/primitives/credential-ref.js +0 -125
  398. package/dist/primitives/index.d.ts +0 -2
  399. package/dist/primitives/index.js +0 -1
@@ -2,7 +2,7 @@ import type { PeerInboundChainRef } from "../../agents/peer-admission.js";
2
2
  import { type SafeNotifier } from "../safe-notify.js";
3
3
  import { type NotificationInjectionOutcome, type PendingSessionNotifications, type SystemInjectionPriority, type TaskNotificationPayload } from "../task-notification.js";
4
4
  import type { PushQueue } from "../push-queue.js";
5
- import type { TaskEvent, TaskSpec } from "../types.js";
5
+ import type { HeldUserInputs, TaskEvent, TaskSpec } from "../types.js";
6
6
  import type { Stats } from "./assemble-result.js";
7
7
  import { type CallerStopGate } from "./caller-stop-gate.js";
8
8
  import type { CaptureOptOutRef, LiveHandle, ManualCompactRef, McpRedialRef, NotificationLaneBindings, NotifyRef, Prepared, RunInternals, RunnerDepsSeat, TaskIdRef } from "./contracts.js";
@@ -73,10 +73,7 @@ export interface RunIdentityWiringResult {
73
73
  /** The held agent_end account, a READ FACE over this lane's own `let` (the undrained-inputs sink writes it
74
74
  * when the run committed a durable park); the terminal-adoption lane settles it minus what the park carried. */
75
75
  undrainedUserAtEnd: {
76
- readonly current: {
77
- steer: number;
78
- followUp: number;
79
- } | undefined;
76
+ readonly current: HeldUserInputs | undefined;
80
77
  };
81
78
  /** The run's ONE isolation scope for the {@link RunInternals} observation sinks: minted here because
82
79
  * the manifest sink below is the run's first call into one, and handed on to the harness-handlers lane
@@ -6,7 +6,7 @@ import { recordFrameReceipt, toolResultReceiptKey } from "../frame-settlement.js
6
6
  import { discloseDroppedPending, renderTaskNotificationXml, taskNotificationDedupKey } from "../task-notification.js";
7
7
  import { buildAppliedHumanInputEvent } from "../human-input-projection.js";
8
8
  import { announceAcceptance, nextHumanInputSeq } from "./steer-admission.js";
9
- import { deliverDelegationLifecycle, deliverEngineNotice, parentLegIds, undrainedUserInputNotices } from "../types.js";
9
+ import { deliverDelegationLifecycle, deliverEngineNotice, parentLegIds, parkedInputIdsOf, undrainedUserInputNotices } from "../types.js";
10
10
  import { mintCallerStopGate } from "./caller-stop-gate.js";
11
11
  export function runIdentityWiring(input) {
12
12
  const { spec, queue, prepared, internals, taskIdRef, onReady, manualCompactRef, notifyRef, captureOptOutRef, mcpRedialRef, injectTaskNotification, deliveredAtTurnOpen, peerInboundChainRef, notificationLane, pendingSessionNotifications, runner } = input;
@@ -28,6 +28,7 @@ export function runIdentityWiring(input) {
28
28
  internalsNotifier.notify(() => observeThenableRejection(internals?.onWiringManifest?.(wiringManifest), internalsNotifier, "runtask.onWiringManifest"), "runtask.onWiringManifest");
29
29
  prepared.toolRosterDeltas.subscribe((delta) => queue.push({ type: "tool_roster_delta", delta, ...ident() }));
30
30
  prepared.toolDisclosure?.subscribe((snapshot) => queue.push({ type: "tool_disclosure", ...snapshot, ...ident() }));
31
+ prepared.workspaceFrame.subscribe((snapshot) => queue.push({ type: "workspace_changed", ...snapshot, ...ident() }));
31
32
  const delegationLifecycleNotifier = createSafeNotifier({
32
33
  onError: (f) => console.warn(`[sema-core] ${f.site}: delegation-lifecycle observer threw (contained; further failures counted, not re-disclosed): ${f.error.message}`),
33
34
  });
@@ -63,13 +64,14 @@ export function runIdentityWiring(input) {
63
64
  prepared.harness.engineInjectionsHeld = () => prepared.batchHaltRef.current !== undefined;
64
65
  let undrainedUserAtEnd;
65
66
  let userInputLostAtEnd = false;
66
- prepared.harness.onUndrainedUserInputs = (counts) => {
67
+ prepared.harness.onUndrainedUserInputs = (counts, parkRecords) => {
67
68
  userInputLostAtEnd = counts.steer + counts.followUp > 0;
69
+ const inputIds = parkRecords !== undefined ? parkedInputIdsOf(parkRecords) : undefined;
68
70
  if (prepared.pausedRef.current !== undefined || prepared.undeliveredContinuationRef.current.parkedSteers.length > 0) {
69
- undrainedUserAtEnd = counts;
71
+ undrainedUserAtEnd = { steer: counts.steer, followUp: counts.followUp, ...(inputIds !== undefined ? { inputIds } : {}) };
70
72
  return;
71
73
  }
72
- for (const notice of undrainedUserInputNotices(counts, spec.taskId ?? prepared.sessionId, prepared.sessionId, prepared.runId, parentLegIds(internals))) {
74
+ for (const notice of undrainedUserInputNotices({ ...counts, ...(inputIds !== undefined ? { inputIds } : {}) }, spec.taskId ?? prepared.sessionId, prepared.sessionId, prepared.runId, parentLegIds(internals))) {
73
75
  deliverEngineNotice(runner.deps.onNotice, notice);
74
76
  }
75
77
  };
@@ -40,6 +40,8 @@ export interface RunLegInput<R> {
40
40
  rs: RunState;
41
41
  /** borrowed-readonly — the API-boundary attribution snapshot of the objective's actor (the objective leg's speaker envelope). */
42
42
  entryActor: ActorAssertion | undefined;
43
+ /** borrowed-readonly — `RunInternals.operatorObjective`: this delegated leg's objective carries a person's words. */
44
+ operatorObjective: boolean;
43
45
  /** borrowed-readonly — the effective walltime window (undefined = unbounded): `<= 0` refuses the first turn. */
44
46
  effectiveTimeoutMs: number | undefined;
45
47
  /** borrowed-mutable — the hard walltime timer: claimed (`fired`) and cleared by the exhausted arms and the finally. */
@@ -5,14 +5,15 @@ import { CheckpointError, readPendingSteerQueue, realApprovalOrgFact, remainingB
5
5
  import { normalizePersistedRuleHit } from "../rule-lane-reads.js";
6
6
  import { decidersNote, SETTLEMENT_NOBODY_JUDGED } from "../gate-outcome.js";
7
7
  import { formatHookFeedback } from "../hooks.js";
8
- import { classicEventBase, failedHandlerClause, screenUserPrompt } from "../mods/stations.js";
8
+ import { classicEventBase, failedHandlerClause, legEventsOf, openSubagent, screenUserPrompt } from "../mods/stations.js";
9
9
  import { buildAppliedHumanInputEvent, buildHumanInputEvent, projectHumanInput } from "../human-input-projection.js";
10
10
  import { humanInputAttachmentsOf, readObjectiveAttachments, userAttachmentDeclarations } from "../user-attachment.js";
11
11
  import { readToolCallArguments, uuidv7 } from "../../internal/harness.js";
12
12
  import { ORG_ADJUDICATION_TIMEOUT_MS, settleOrgVerdictWithin } from "../permission-rule-org.js";
13
13
  import { applyPersistedTightening, disclosedRuleSet } from "../persisted-rule-arms.js";
14
14
  import { argsReadBy, stampArgsReading } from "../effective-path-target.js";
15
- import { skillRowRefusal } from "../skill-grant.js";
15
+ import { skillGrantBindingMembers, skillRowRefusal } from "../skill-grant.js";
16
+ import { requestGrantBinding } from "../skill-grant-binding.js";
16
17
  import { judgeApprovalObject } from "../approval-object.js";
17
18
  import { SKILL_TOOL_NAME } from "./synthetic-tools.js";
18
19
  import { computeCostMicroUsd } from "../pricing.js";
@@ -53,12 +54,13 @@ import { thrownMarksOf } from "../thrown-value.js";
53
54
  import { egressThrownText, egressValue } from "../untrusted-egress.js";
54
55
  import { ruleSourcePhrase } from "../rule-denial-sentence.js";
55
56
  export async function runLeg(input) {
56
- const { spec, queue, prepared, resume, rs, entryActor, effectiveTimeoutMs, timeout, pushContent, ident, emitCommitted, writeFamilyOf, startedToolCallIds, announceWorkspaceMove, withBrainSinks, flushGitMirror, loopLatch, notificationLane, unsubscribeTaskNotifications, unsubGitRetry, unsubBoundary, unsub, runner, next } = input;
57
+ const { spec, queue, prepared, resume, rs, entryActor, operatorObjective, effectiveTimeoutMs, timeout, pushContent, ident, emitCommitted, writeFamilyOf, startedToolCallIds, announceWorkspaceMove, withBrainSinks, flushGitMirror, loopLatch, notificationLane, unsubscribeTaskNotifications, unsubGitRetry, unsubBoundary, unsub, runner, next } = input;
57
58
  let final;
58
59
  let threw;
59
60
  let abortedLive = false;
60
61
  let userInterruptedLive = false;
61
62
  let strandedHumanAnswers = [];
63
+ const legRunOrigin = prepared.wiringManifest.leg?.runOrigin;
62
64
  try {
63
65
  if (prepared.abortController.signal.aborted) {
64
66
  const e = new Error("run aborted");
@@ -224,6 +226,7 @@ export async function runLeg(input) {
224
226
  ...(steer.actor !== undefined ? { actor: steer.actor } : {}),
225
227
  ...(steer.actor?.issuer !== undefined ? { issuer: steer.actor.issuer } : {}),
226
228
  ...(spec.principal !== undefined ? { principal: spec.principal } : {}),
229
+ ...(steer.runOrigin !== undefined ? { runOrigin: steer.runOrigin } : {}),
227
230
  }),
228
231
  ...ident(),
229
232
  });
@@ -244,7 +247,7 @@ export async function runLeg(input) {
244
247
  if (steer.trusted)
245
248
  engineSegments.push({ start, end: continuation.length });
246
249
  appliedEvents.push(() => ({
247
- ...buildAppliedHumanInputEvent({ carrier: source, source, sessionSeq: nextHumanInputSeq(prepared.harness), inputId: steer.inputId, actor: steer.actor, principal: spec.principal }),
250
+ ...buildAppliedHumanInputEvent({ carrier: source, source, sessionSeq: nextHumanInputSeq(prepared.harness), inputId: steer.inputId, actor: steer.actor, principal: spec.principal, runOrigin: steer.runOrigin }),
248
251
  ...ident(),
249
252
  }));
250
253
  }
@@ -303,28 +306,36 @@ export async function runLeg(input) {
303
306
  const projectedObjective = projectHumanInput({ text: spec.objective, actor: objectiveActor, source: "objective" });
304
307
  let effectiveObjective = projectedObjective;
305
308
  let promptBlocked = false;
306
- const screen = await screenUserPrompt(prepared.modBus, {
307
- ...classicEventBase(prepared.hookIdentity, prepared.permissionMode.observed),
308
- prompt: spec.objective,
309
- source: "objective",
310
- ...(objectiveActor !== undefined ? { actor: snapshotActorAssertion(objectiveActor) } : {}),
311
- ...(prepared.userAttachments !== undefined ? { userAttachments: userAttachmentDeclarations(prepared.userAttachments) } : {}),
312
- }, prepared.abortController.signal);
313
- if (screen?.kind === "aborted") {
314
- holdPrompt(prepared.blockedRef, prepared.reminderMark, "cancelled", `the task was cancelled while the deployment's userPromptSubmit hook was still screening this prompt; ` +
315
- `the prompt was NOT submitted (fail-closed)`);
316
- promptBlocked = true;
317
- }
318
- else if (screen?.kind === "failed") {
319
- holdPrompt(prepared.blockedRef, prepared.reminderMark, screen.cause === "timeout" ? "timeout" : "crashed", `the deployment's userPromptSubmit hook ${failedHandlerClause(screen)} while screening this prompt; the prompt was NOT submitted (fail-closed)`);
320
- promptBlocked = true;
321
- }
322
- else if (screen?.block) {
323
- holdPrompt(prepared.blockedRef, prepared.reminderMark, "block", screen.block);
324
- promptBlocked = true;
309
+ const objectiveEvents = legEventsOf(prepared.hookIdentity, operatorObjective);
310
+ if (objectiveEvents.screen !== undefined) {
311
+ const screen = await screenUserPrompt(prepared.modBus, {
312
+ ...classicEventBase(prepared.hookIdentity, prepared.permissionMode.observed),
313
+ prompt: spec.objective,
314
+ source: "objective",
315
+ ...(objectiveActor !== undefined ? { actor: snapshotActorAssertion(objectiveActor) } : {}),
316
+ ...(prepared.userAttachments !== undefined ? { userAttachments: userAttachmentDeclarations(prepared.userAttachments) } : {}),
317
+ }, prepared.abortController.signal);
318
+ if (screen?.kind === "aborted") {
319
+ holdPrompt(prepared.blockedRef, prepared.reminderMark, "cancelled", `the task was cancelled while the deployment's userPromptSubmit hook was still screening this prompt; ` +
320
+ `the prompt was NOT submitted (fail-closed)`);
321
+ promptBlocked = true;
322
+ }
323
+ else if (screen?.kind === "failed") {
324
+ holdPrompt(prepared.blockedRef, prepared.reminderMark, screen.cause === "timeout" ? "timeout" : "crashed", `the deployment's userPromptSubmit hook ${failedHandlerClause(screen)} while screening this prompt; the prompt was NOT submitted (fail-closed)`);
325
+ promptBlocked = true;
326
+ }
327
+ else if (screen?.block) {
328
+ holdPrompt(prepared.blockedRef, prepared.reminderMark, "block", screen.block);
329
+ promptBlocked = true;
330
+ }
331
+ else if (screen?.additionalContext) {
332
+ effectiveObjective = `${formatHookFeedback(screen.additionalContext, prepared.reminderMark)}\n\n${projectedObjective}`;
333
+ }
325
334
  }
326
- else if (screen?.additionalContext) {
327
- effectiveObjective = `${formatHookFeedback(screen.additionalContext, prepared.reminderMark)}\n\n${projectedObjective}`;
335
+ if (objectiveEvents.start !== undefined && !promptBlocked) {
336
+ const start = await openSubagent(prepared.modBus, prepared.hookIdentity, prepared.permissionMode.observed, prepared.abortController.signal);
337
+ if (start?.additionalContext)
338
+ effectiveObjective = `${formatHookFeedback(start.additionalContext, prepared.reminderMark)}\n\n${effectiveObjective}`;
328
339
  }
329
340
  const objectiveInputId = uuidv7();
330
341
  const { frames: attachmentFrames, chars: attachmentChars } = await readObjectiveAttachments(prepared, objectiveInputId, promptBlocked, { overlay: () => legContextOverlayOption(prepared, runner).contextOverlay, objectiveChars: effectiveObjective.length });
@@ -493,6 +504,7 @@ export async function runLeg(input) {
493
504
  ...(objectiveActor?.issuer !== undefined ? { issuer: objectiveActor.issuer } : {}),
494
505
  ...(spec.principal !== undefined ? { principal: spec.principal } : {}),
495
506
  ...(attachmentFrames.length > 0 ? { attachments: humanInputAttachmentsOf(attachmentFrames) } : {}),
507
+ ...(legRunOrigin !== undefined ? { runOrigin: legRunOrigin } : {}),
496
508
  }),
497
509
  ...ident(),
498
510
  });
@@ -501,6 +513,7 @@ export async function runLeg(input) {
501
513
  ...(enginePrefixChars > 0 ? { enginePrefixChars } : {}),
502
514
  ...(attachmentFrames.length > 0 ? { trailing: attachmentFrames.map((f) => f.seed) } : {}),
503
515
  ...(objectiveActor !== undefined ? { actor: objectiveActor } : {}),
516
+ ...(legRunOrigin !== undefined ? { runOrigin: legRunOrigin } : {}),
504
517
  }));
505
518
  await flushGitMirror();
506
519
  if (prepared.gitStatusRef.announced?.pending === true)
@@ -596,9 +609,9 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
596
609
  occurrences.gateRound(pendingAction.toolCallId, decidedGate, frozenInputSnapshot(resolvedArgs));
597
610
  let notExecuted = false;
598
611
  const resultRow = (text, isError) => withRowNotExecuted(toolResultMsg(pendingAction.toolCallId, pendingAction.toolName, text, isError), notExecuted);
599
- const settleEnd = async (isError, result, refusedBy, neverRan) => {
612
+ const settleEnd = async (isError, result, refusedBy, neverRan, extension) => {
600
613
  if (refusedBy !== undefined)
601
- occurrences.refuse(pendingAction.toolCallId, refusedBy);
614
+ occurrences.refuse(pendingAction.toolCallId, refusedBy, extension);
602
615
  const settled = emitSettled(occurrences, callStart, { result, isError, ...(neverRan ? { notExecuted: true } : {}) }, { push: emit, structured: prepared.structuredProjector, mediaByteCapBytes: runner.deps.mediaByteCapBytes });
603
616
  notExecuted = settled.notExecuted === true;
604
617
  const gate = settled.gate ?? decidedGate;
@@ -644,7 +657,7 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
644
657
  const screened = await prepared.approvedCallScreen?.({ toolCallId: pendingAction.toolCallId, toolName: pendingAction.toolName, args: structuredClone(resolvedArgs), decidedBy: outcome.hostDecision.decidedBy });
645
658
  if (screened !== undefined && "refused" in screened) {
646
659
  const hookDenial = formatHookFeedback(screened.refused, prepared.reminderMark);
647
- await settleEnd(true, { content: hookDenial }, "hook");
660
+ await settleEnd(true, { content: hookDenial }, "hook", undefined, screened.extension);
648
661
  emitCommitted(await prepared.session.appendMessage(resultRow(hookDenial, true)), "toolResult", pendingAction.toolCallId);
649
662
  return;
650
663
  }
@@ -659,7 +672,7 @@ async function resolvePendingCall(runner, prepared, resume, emit, emitCommitted,
659
672
  const executedArgs = rescreened !== undefined ? rescreened.args : resolvedArgs;
660
673
  const unseen = !licenseCovers(pendingAction.boundInputHash, executedArgs);
661
674
  let beltReading;
662
- const beltReq = () => ({ toolName: pendingAction.toolName, args: executedArgs, toolCallId: pendingAction.toolCallId, ...callFaceSeat(beltFace()), budget: beltBudget, ...(prepared.cwdRef !== undefined ? { cwd: prepared.cwdRef.current } : {}), ...(prepared.handsRoot !== undefined ? { root: prepared.handsRoot } : {}), ...advertisedWritableRootsSeat(prepared.advertisedWritableDirs), ...exemptRootsSeat(prepared.exemptRoots), ...(beltReading !== undefined ? { targetReading: beltReading } : {}) });
675
+ const beltReq = () => ({ toolName: pendingAction.toolName, args: executedArgs, toolCallId: pendingAction.toolCallId, ...callFaceSeat(beltFace()), budget: beltBudget, ...(prepared.cwdRef !== undefined ? { cwd: prepared.cwdRef.current } : {}), ...(prepared.handsRoot !== undefined ? { root: prepared.handsRoot } : {}), ...advertisedWritableRootsSeat(prepared.advertisedWritableDirs), ...exemptRootsSeat(prepared.exemptRoots), ...(beltReading !== undefined ? { targetReading: beltReading } : {}), ...requestGrantBinding((call, args) => skillGrantBindingMembers(call, args, prepared.skillSpecs, SKILL_TOOL_NAME), pendingAction, executedArgs) });
663
676
  const unjudgeable = unseen ? chainCannotJudge(resume.cp.state.inheritedGate) : undefined;
664
677
  if (unjudgeable !== undefined) {
665
678
  const chainDenial = formatHookFeedback(`The approved tool call "${pendingAction.toolName}" was not executed: its input changed after the approval and the inherited ancestor chain cannot judge the changed input (${unjudgeable}). This approval is spent — the call has to be re-issued.`, prepared.reminderMark);
@@ -1,5 +1,7 @@
1
1
  import { createPeerInboundChainRef, createPeerSelfRef } from "../../agents/peer-admission.js";
2
2
  import { boundInputHashOf } from "../canonical-json.js";
3
+ import { readPendingSteerQueue } from "../checkpoint-store.js";
4
+ import { wakeOpening } from "../run-origin.js";
3
5
  import { createLiveNotificationLane, DurableAppendObligations, injectionLaneOf, isDelegatedAgentTerminal, isTerminalTaskNotification, renderTaskNotificationXml, routeOrParkNotification, SystemInjectionQueue, taskNotificationDedupKey } from "../task-notification.js";
4
6
  import { ToolDetachHub } from "../tool-detach.js";
5
7
  import { pendingContentAskCallId } from "./decide-continuation.js";
@@ -15,6 +17,7 @@ async function runNotificationLaneAs(input, obligations) {
15
17
  suspendedBatch: new Set(resume.cp.pendingAction.kind === "tool_approval" ? resume.cp.pendingAction.batchToolCallIds : []),
16
18
  seed: resume.cp.state,
17
19
  outcome: resume.outcome,
20
+ ...((opening) => (opening !== undefined ? { opening } : {}))(resume.outcome.gate === "wake" ? wakeOpening(readPendingSteerQueue(resume.cp.state), resume.wakeMessage) : undefined),
18
21
  ...(resume.legMods !== undefined ? { legMods: resume.legMods } : {}),
19
22
  priorSuspendCount: resume.cp.suspendCount,
20
23
  priorLedger: resume.cp.resourceLedger,
@@ -1,11 +1,11 @@
1
1
  import { openSystemReminder } from "../reminder-mint.js";
2
2
  import { formatHookFeedback } from "../hooks.js";
3
- import { classicEventBase, dispatchClassic, stopEventOf, stringMembersAnswer, stringMembersOf } from "../mods/stations.js";
3
+ import { classicEventBase, dispatchClassic, legEventsOf, stringMembersAnswer, stringMembersOf } from "../mods/stations.js";
4
4
  import { asThrownError } from "../thrown-value.js";
5
5
  const STOP_HOOK_BLOCK_CAP = 8;
6
6
  export function runStopAndFinalVerify(input) {
7
7
  const { spec, prepared, queue, rs, stats, ident, walltimeMonotonicDeadline, runner } = input;
8
- const stopEvent = stopEventOf(prepared.hookIdentity);
8
+ const stopEvent = legEventsOf(prepared.hookIdentity).stop;
9
9
  const stopArmed = prepared.modBus.hasHandlers(stopEvent);
10
10
  const finalVerificationOn = spec.finalVerification === true;
11
11
  const finalVerifyBudgetFill = () => {
@@ -19,7 +19,7 @@ import type { Model } from "../../internal/llm.js";
19
19
  import { type MaybeCompactOptions } from "../auto-compaction.js";
20
20
  import type { SessionStore } from "../session.js";
21
21
  import type { PushQueue } from "../push-queue.js";
22
- import type { Brain, OwedUserInputAccount, TaskEvent, TaskSpec } from "../types.js";
22
+ import { type Brain, type HeldUserInputs, type OwedUserInputAccount, type TaskEvent, type TaskSpec } from "../types.js";
23
23
  import { type Stats } from "./assemble-result.js";
24
24
  import type { EndOfTaskCompaction, Prepared, RunnerDepsSeat, RunState } from "./contracts.js";
25
25
  import type { CallerStopGate } from "./caller-stop-gate.js";
@@ -61,10 +61,7 @@ export interface RunTerminalAdoptionInput<R> {
61
61
  windowSafetyOptions: (mainModel: Model) => Pick<MaybeCompactOptions, "fallbackBudget" | "onWindowSafety">;
62
62
  /** borrowed-readonly — the held agent_end account, as the read face on the identity lane's Result. */
63
63
  undrainedUserAtEnd: {
64
- readonly current: {
65
- steer: number;
66
- followUp: number;
67
- } | undefined;
64
+ readonly current: HeldUserInputs | undefined;
68
65
  };
69
66
  /** borrowed-readonly — did the run end with a person's steer / follow-up still pending (the identity lane's read face)? Folded
70
67
  * into the answer-settled verdict this lane evaluates once. */
@@ -2,6 +2,7 @@ import { compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTR
2
2
  import { eventDefaultOn } from "../../prompt-assembly/event-registry.js";
3
3
  import { appendInterruptionMarker, reconcileInterruptedSession } from "../session-reconcile.js";
4
4
  import { emitTrace } from "../trace.js";
5
+ import { parkedInputIdsOf } from "../types.js";
5
6
  import { answerSettled } from "./assemble-result.js";
6
7
  import { errorCodeOf } from "./terminal-account.js";
7
8
  import { awaitChargeWithSlowDisclosure, discloseUnevaluableWindow } from "./clock-and-limits.js";
@@ -79,6 +80,7 @@ export async function runTerminalAdoption(input) {
79
80
  }
80
81
  let migratedParked = { steer: 0, followUp: 0 };
81
82
  let carriedContinuation = 0;
83
+ const carriedContinuationInputIds = [];
82
84
  let carriedApproval = 0;
83
85
  let approvalRefusal;
84
86
  if (committedPause !== undefined && runner.deps.checkpointStore !== undefined) {
@@ -101,8 +103,11 @@ export async function runTerminalAdoption(input) {
101
103
  carried.push(live);
102
104
  else if (approval)
103
105
  carriedApproval += 1;
104
- else
106
+ else {
105
107
  carriedContinuation += 1;
108
+ if (typeof input.inputId === "string")
109
+ carriedContinuationInputIds.push(input.inputId);
110
+ }
106
111
  }
107
112
  catch (parkErr) {
108
113
  runner.deps.onError?.(asThrownError(parkErr), {
@@ -118,9 +123,10 @@ export async function runTerminalAdoption(input) {
118
123
  break;
119
124
  }
120
125
  }
121
- migratedParked = prepared.harness.dropParkedUserInputs(carried);
126
+ const dropped = prepared.harness.dropParkedUserInputs(carried);
127
+ migratedParked = { steer: dropped.steer, followUp: dropped.followUp, inputIds: parkedInputIdsOf(dropped.records) };
122
128
  }
123
- const owedUserInput = { held: undrainedUserAtEnd.current, migrated: migratedParked, continuation: { frames: prepared.undeliveredContinuationRef.current.parkedSteers.filter((f) => !isApprovalWordsFrame(f)), carried: carriedContinuation, approval: { owed: prepared.undeliveredContinuationRef.current.parkedSteers.filter(isApprovalWordsFrame).length, carried: carriedApproval, ...(approvalRefusal !== undefined ? { refusal: approvalRefusal } : {}) } } };
129
+ const owedUserInput = { held: undrainedUserAtEnd.current, migrated: migratedParked, continuation: { frames: prepared.undeliveredContinuationRef.current.parkedSteers.filter((f) => !isApprovalWordsFrame(f)), carried: carriedContinuation, carriedInputIds: carriedContinuationInputIds, approval: { owed: prepared.undeliveredContinuationRef.current.parkedSteers.filter(isApprovalWordsFrame).length, carried: carriedApproval, ...(approvalRefusal !== undefined ? { refusal: approvalRefusal } : {}) } } };
124
130
  if (rs.attach.attachState?.postCompactPending === true && (rs.attach.attachmentsCfg?.backgroundTasks ?? eventDefaultOn("background_tasks")) === true) {
125
131
  emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.announce_dropped", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
126
132
  }
@@ -4,7 +4,7 @@ import { eventDefaultOn } from "../../prompt-assembly/event-registry.js";
4
4
  import { compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTRUCTIONS, isCompactionManualCancel, manualCompactOutcomeOf, maybeCompact, mintCompactedEvent, nextTrimForceBackoff, recordCompactionAndCheckRapidRefill } from "../auto-compaction.js";
5
5
  import { emitTrace } from "../trace.js";
6
6
  import { redactThenCut } from "../../agents/subagent-steps.js";
7
- import { ATTACHMENT_BYTE_CAP, CHANGED_FILES_MAX, TOTAL_TOKENS_REMINDER_DEFAULT_MODE, attachmentEnvelopeTags, clipToBytes, collectDateChange, collectDueAttachments, collectInstructionsChange, commitAgentListing, commitInstructionsChange, commitSkillsListing, isIntactSource, rebaseCadenceWindows, renderAgentListingFrame, renderMcpDroppedTools, renderMcpInstructionsDelta, selectMcpDroppedBatch, renderSkillsListingFrame, renderToolsDelta } from "./turn-attachments.js";
7
+ import { ATTACHMENT_BYTE_CAP, CHANGED_FILES_MAX, TOTAL_TOKENS_REMINDER_DEFAULT_MODE, attachmentEnvelopeTags, clipToBytes, collectDateChange, collectDueAttachments, collectInstructionsChange, commitAgentListing, commitInstructionsChange, commitSkillsListing, isIntactSource, rebaseCadenceWindows, renderAgentListingFrame, renderMcpInstructionsDelta, selectMcpDroppedBatch, renderSkillsListingFrame } from "./turn-attachments.js";
8
8
  import { announceListingTruncation } from "../skill-listing-budget.js";
9
9
  import { buildWorkingFileAttachments, centerAdoptionOption, contextInstructionFilesOption, emitInputTruncated, forkContextOption, legCompactionSettings, legContextOverlayOption } from "./compaction-call-options.js";
10
10
  import { classicEventBase, dispatchClassic, stringMembersAnswer, stringMembersOf } from "../mods/stations.js";
@@ -20,6 +20,13 @@ import { contextUsageSections } from "../../prompt-assembly/section-usage.js";
20
20
  import { asThrownError } from "../thrown-value.js";
21
21
  const BATCH_CONTEXT_MIN_KEEP_BYTES = 160;
22
22
  const BATCH_TRUNCATION_MARKER = "\n…[truncated]";
23
+ function consumeDelivered(pending, delivered) {
24
+ for (const d of delivered) {
25
+ const at = pending.indexOf(d);
26
+ if (at !== -1)
27
+ pending.splice(at, 1);
28
+ }
29
+ }
23
30
  export function createTurnBoundary(input) {
24
31
  const { prepared, stats, rs, deps } = input;
25
32
  const { spec, queue, loopLatch: { callerStop }, manualCompactRef, todoToolMounted, taskToolsMounted, walltimeMonotonicDeadline, timeout, ident, postToolBatchArmed, batchArgs, compactionBrain, withinTaskCompaction, compactionBreaker, windowSafetyOptions, rapidRefill, drainManualCompact, runnerHooks, runner } = deps;
@@ -152,7 +159,8 @@ export function createTurnBoundary(input) {
152
159
  turnOwesRequest &&
153
160
  prepared.batchHaltRef.current === undefined &&
154
161
  !boundarySteered &&
155
- !prepared.abortController.signal.aborted) {
162
+ !prepared.abortController.signal.aborted &&
163
+ !frameCarried(prepared.frameReceipts, "limit_approach")) {
156
164
  const thresholds = approachCfg?.at ?? LIMIT_APPROACH_DEFAULT_THRESHOLDS;
157
165
  const ratios = [];
158
166
  if (rs.budget.maxTokensWindow !== undefined && rs.budget.maxTokensWindow > 0) {
@@ -177,22 +185,31 @@ export function createTurnBoundary(input) {
177
185
  tightest = r;
178
186
  const index = rs.counters.approachNoticesSent;
179
187
  if (tightest !== undefined && tightest.ratio >= thresholds[index]) {
180
- rs.counters.approachNoticesSent += 1;
181
188
  const percent = Math.min(100, Math.round(tightest.ratio * 100));
182
189
  const body = limitApproachFrames(index === 0 ? 0 : 1, tightest.axis, percent, prepared.reminderMark);
183
- void prepared.harness.steer(body, { engineMinted: true }).catch(() => undefined);
184
- queue.push({ type: "steering_injected", source: "limit_approach", preview: body.slice(0, 220), ...ident() });
190
+ const preview = body.slice(0, 220);
191
+ prepared.frameReceipts.pending.push({
192
+ source: "limit_approach",
193
+ text: body,
194
+ commit: () => {
195
+ rs.counters.approachNoticesSent += 1;
196
+ queue.push({ type: "steering_injected", source: "limit_approach", preview, ...ident() });
197
+ },
198
+ });
199
+ void prepared.harness.steer(body, { engineMinted: true }).catch(() => {
200
+ prepared.frameReceipts.pending = prepared.frameReceipts.pending.filter((r) => r.text !== body);
201
+ });
185
202
  boundarySteered = true;
186
203
  }
187
204
  }
188
205
  if (prepared.reviewRequestRef.pending !== undefined) {
189
- const { reason } = prepared.reviewRequestRef.pending;
206
+ const { reason, requestedByCallId } = prepared.reviewRequestRef.pending;
190
207
  prepared.reviewRequestRef.pending = undefined;
191
208
  const honorable = prepared.suspendForReview !== undefined &&
192
209
  !prepared.abortController.signal.aborted &&
193
210
  prepared.pausedRef.current === undefined;
194
211
  if (honorable && prepared.suspendForReview) {
195
- await prepared.suspendForReview(reason);
212
+ await prepared.suspendForReview(reason, requestedByCallId);
196
213
  legContinues = !prepared.abortController.signal.aborted && prepared.pausedRef.current === undefined;
197
214
  return undefined;
198
215
  }
@@ -215,7 +232,9 @@ export function createTurnBoundary(input) {
215
232
  }
216
233
  let boundaryAttachmentBytes = 0;
217
234
  let attachmentsPayload;
218
- const receiptCommits = [];
235
+ const recordSteps = new Map();
236
+ const bundleReceipts = [];
237
+ const carried = (source) => frameCarried(prepared.frameReceipts, source);
219
238
  if ((rs.attach.dateState !== undefined ||
220
239
  rs.attach.instrState !== undefined ||
221
240
  rs.attach.sizeGuidelineState !== undefined ||
@@ -229,7 +248,7 @@ export function createTurnBoundary(input) {
229
248
  const due = [];
230
249
  if (rs.attach.attachState !== undefined) {
231
250
  const attachState = rs.attach.attachState;
232
- const changedFilesOn = Boolean(rs.attach.attachmentsCfg?.changedFiles);
251
+ const changedFilesOn = Boolean(rs.attach.attachmentsCfg?.changedFiles) && !carried("changed_files");
233
252
  let changed;
234
253
  if (changedFilesOn && prepared.detectExternalChanges !== undefined) {
235
254
  const maxFiles = typeof rs.attach.attachmentsCfg?.changedFiles === "object"
@@ -246,10 +265,9 @@ export function createTurnBoundary(input) {
246
265
  rs.attach.attachState.surfacedMtime.delete(p);
247
266
  changed = scan.changed;
248
267
  }
249
- const backgroundTasksOn = (rs.attach.attachmentsCfg?.backgroundTasks ?? eventDefaultOn("background_tasks")) === true;
268
+ const backgroundTasksOn = (rs.attach.attachmentsCfg?.backgroundTasks ?? eventDefaultOn("background_tasks")) === true && !carried("background_tasks");
250
269
  const bgTasks = backgroundTasksOn && rs.attach.attachState.postCompactPending ? prepared.listBackgroundTasks() : undefined;
251
- const toolsDeltaOn = rs.attach.attachmentsCfg?.toolsDelta === true;
252
- let announcedOnceDirty = false;
270
+ const toolsDeltaOn = rs.attach.attachmentsCfg?.toolsDelta === true && !carried("tools_delta");
253
271
  const tdRef = toolsDeltaOn ? prepared.toolsDeltaRef : undefined;
254
272
  const pendingTools = tdRef !== undefined && tdRef.pending.length > 0 ? [...tdRef.pending] : undefined;
255
273
  const pendingRemovedTools = tdRef !== undefined && tdRef.pendingRemoved.length > 0 ? [...tdRef.pendingRemoved] : undefined;
@@ -264,7 +282,7 @@ export function createTurnBoundary(input) {
264
282
  const mcpDelta = prepared.mcp.instructionsDelta;
265
283
  const mcpAdds = mcpInstructionsOn && mcpDelta.pendingAdds.length > 0 ? [...mcpDelta.pendingAdds] : undefined;
266
284
  const mcpRemovals = mcpInstructionsOn && mcpDelta.pendingRemovals.length > 0 ? [...mcpDelta.pendingRemovals] : undefined;
267
- const mcpDropped = mcpInstructionsOn && prepared.mcp.droppedTools.length > 0 ? selectMcpDroppedBatch(prepared.mcp.droppedTools) : undefined;
285
+ const mcpDropped = mcpInstructionsOn && !carried("mcp_dropped_tools") && prepared.mcp.droppedTools.length > 0 ? selectMcpDroppedBatch(prepared.mcp.droppedTools) : undefined;
268
286
  const budgetUsdOn = rs.attach.attachmentsCfg?.budgetUsd === true && rs.budget.maxCostMicroUsd !== undefined;
269
287
  const totalTokensDeclared = rs.attach.attachmentsCfg?.totalTokensReminder;
270
288
  const totalTokensMode = rs.attach.attachmentsCfg?.totalTokensReminderMode ?? TOTAL_TOKENS_REMINDER_DEFAULT_MODE;
@@ -273,7 +291,7 @@ export function createTurnBoundary(input) {
273
291
  totalTokensMode !== "fixed" &&
274
292
  totalTokensMode !== "infinite";
275
293
  const totalTokensOn = totalTokensDeclared === true || totalTokensArmedByDefault;
276
- const toolSearchReminderOn = rs.attach.attachmentsCfg?.toolSearchReminder === true && prepared.deferredToolNames !== undefined;
294
+ const toolSearchReminderOn = rs.attach.attachmentsCfg?.toolSearchReminder === true && prepared.deferredToolNames !== undefined && !carried("tool_search_usage_reminder");
277
295
  const undiscoveredTools = toolSearchReminderOn
278
296
  ? [...prepared.deferredToolNames].filter((n) => !prepared.activeTools.has(n)).sort()
279
297
  : undefined;
@@ -286,7 +304,7 @@ export function createTurnBoundary(input) {
286
304
  todoMounted: todoToolMounted,
287
305
  taskListMounted: taskToolsMounted,
288
306
  config: {
289
- todoReminder: rs.attach.attachmentsCfg?.todoReminder === true,
307
+ todoReminder: rs.attach.attachmentsCfg?.todoReminder === true && !carried("todo_reminder") && !carried("task_reminder"),
290
308
  ...(rs.attach.attachmentsCfg?.todoReminderMode !== undefined ? { todoReminderMode: rs.attach.attachmentsCfg.todoReminderMode } : {}),
291
309
  toolSearchReminder: toolSearchReminderOn,
292
310
  changedFiles: changedFilesOn,
@@ -336,27 +354,16 @@ export function createTurnBoundary(input) {
336
354
  : {}),
337
355
  ...(mcpDropped !== undefined ? { mcpDroppedTools: mcpDropped } : {}),
338
356
  }));
339
- if (pendingTools !== undefined || mcpToolsDelta !== undefined) {
340
- const exact = renderToolsDelta({
341
- ...(pendingTools !== undefined ? { added: pendingTools } : {}),
342
- ...(prepared.toolMaterializeStatic ? { staticFace: true } : {}),
343
- ...(prepared.toolMaterializeStatic && pendingTools !== undefined
344
- ? { swappedUnderStatic: pendingTools.filter((n) => prepared.staticFaceFor?.(n) !== true) }
345
- : {}),
346
- ...(prepared.toolMaterializeStatic && pendingReaddedTools !== undefined
347
- ? { readdedSwappedUnderStatic: pendingReaddedTools.filter((n) => prepared.staticFaceFor?.(n) !== true) }
348
- : {}),
349
- ...(mcpToolsDelta ?? {}),
350
- });
351
- if (exact !== undefined && due.some((a) => a.source === "tools_delta" && a.body === exact)) {
352
- const ref = prepared.toolsDeltaRef;
357
+ if ((pendingTools !== undefined || mcpToolsDelta !== undefined) && due.some((a) => a.source === "tools_delta")) {
358
+ const ref = prepared.toolsDeltaRef;
359
+ recordSteps.set("tools_delta", () => {
353
360
  if (pendingTools !== undefined)
354
- ref.pending.splice(0, pendingTools.length);
361
+ consumeDelivered(ref.pending, pendingTools);
355
362
  if (pendingRemovedTools !== undefined)
356
- ref.pendingRemoved.splice(0, pendingRemovedTools.length);
363
+ consumeDelivered(ref.pendingRemoved, pendingRemovedTools);
357
364
  if (pendingReaddedTools !== undefined)
358
- ref.pendingReadded.splice(0, pendingReaddedTools.length);
359
- }
365
+ consumeDelivered(ref.pendingReadded, pendingReaddedTools);
366
+ });
360
367
  }
361
368
  if ((mcpAdds !== undefined || mcpRemovals !== undefined) &&
362
369
  due.some((a) => a.source === "mcp_instructions" && a.body === renderMcpInstructionsDelta(mcpAdds ?? [], mcpRemovals ?? []))) {
@@ -365,64 +372,57 @@ export function createTurnBoundary(input) {
365
372
  if (mcpRemovals !== undefined)
366
373
  mcpDelta.pendingRemovals.splice(0, mcpRemovals.length);
367
374
  }
368
- if (mcpDropped !== undefined &&
369
- due.some((a) => a.source === "mcp_dropped_tools" && a.body === renderMcpDroppedTools(mcpDropped))) {
370
- prepared.mcp.droppedTools.splice(0, mcpDropped.length);
371
- if (!noNextRequest()) {
375
+ if (mcpDropped !== undefined && due.some((a) => a.source === "mcp_dropped_tools")) {
376
+ recordSteps.set("mcp_dropped_tools", () => {
377
+ consumeDelivered(prepared.mcp.droppedTools, mcpDropped);
372
378
  prepared.announcedListingsRef.advisories = withAnnounceDigests(prepared.announcedListingsRef.advisories, mcpDropped.map(droppedToolDigest));
373
- announcedOnceDirty = true;
374
- }
379
+ prepared.frameReceipts.listingSnapshotOwed = true;
380
+ });
375
381
  }
376
382
  if (agentListingDue && due.some((a) => a.source === "agent_listing")) {
377
383
  const listing = prepared.agentListing;
378
384
  const frame = renderAgentListingFrame(attachState, listing.entries, listing.toolName, listing.models, listing.budget);
379
- receiptCommits.push({
380
- source: "agent_listing",
381
- commit: () => {
382
- commitAgentListing(attachState, listing.entries, listing.models);
383
- prepared.announcedListingsRef.agents = listing.entries.map((e) => e.name);
384
- if (listing.models !== undefined)
385
- prepared.announcedListingsRef.models = [...listing.models];
386
- prepared.frameReceipts.listingSnapshotOwed = true;
387
- announceListingTruncation(deps.runner.deps.onNotice, { listing: "agents", total: frame.listed, nameOnly: frame.nameOnly, dropped: frame.dropped, budget: listing.budget, sessionId: prepared.sessionId });
388
- },
385
+ recordSteps.set("agent_listing", () => {
386
+ commitAgentListing(attachState, listing.entries, listing.models);
387
+ prepared.announcedListingsRef.agents = listing.entries.map((e) => e.name);
388
+ if (listing.models !== undefined)
389
+ prepared.announcedListingsRef.models = [...listing.models];
390
+ prepared.frameReceipts.listingSnapshotOwed = true;
391
+ announceListingTruncation(deps.runner.deps.onNotice, { listing: "agents", total: frame.listed, nameOnly: frame.nameOnly, dropped: frame.dropped, budget: listing.budget, sessionId: prepared.sessionId });
389
392
  });
390
393
  }
391
394
  if (skillsListingDue && due.some((a) => a.source === "skills_listing")) {
392
395
  const listing = prepared.skillsListing;
393
396
  const frame = renderSkillsListingFrame(attachState, listing.entries, listing.budget);
394
- receiptCommits.push({
395
- source: "skills_listing",
396
- commit: () => {
397
- commitSkillsListing(attachState, listing.entries);
398
- prepared.announcedListingsRef.skills = listing.entries.map((e) => e.name);
399
- prepared.frameReceipts.listingSnapshotOwed = true;
400
- announceListingTruncation(deps.runner.deps.onNotice, { listing: "skills", total: frame.listed, nameOnly: frame.nameOnly, dropped: frame.dropped, budget: listing.budget, sessionId: prepared.sessionId });
401
- },
397
+ recordSteps.set("skills_listing", () => {
398
+ commitSkillsListing(attachState, listing.entries);
399
+ prepared.announcedListingsRef.skills = listing.entries.map((e) => e.name);
400
+ prepared.frameReceipts.listingSnapshotOwed = true;
401
+ announceListingTruncation(deps.runner.deps.onNotice, { listing: "skills", total: frame.listed, nameOnly: frame.nameOnly, dropped: frame.dropped, budget: listing.budget, sessionId: prepared.sessionId });
402
402
  });
403
403
  }
404
- if (announcedOnceDirty)
405
- prepared.frameReceipts.listingSnapshotOwed = true;
406
404
  }
407
405
  if (rs.attach.dateState !== undefined && !frameCarried(prepared.frameReceipts, "date_change")) {
408
406
  const today = prepared.dateChange.today();
409
407
  const cand = collectDateChange(rs.attach.dateState, today);
410
408
  if (cand !== undefined) {
411
409
  due.unshift(cand);
412
- receiptCommits.push({ source: "date_change", commit: () => void (rs.attach.dateState.announcedDate = today) });
410
+ recordSteps.set("date_change", () => void (rs.attach.dateState.announcedDate = today));
413
411
  }
414
412
  }
415
- if (rs.attach.sizeGuidelineState !== undefined) {
416
- const guideline = rs.attach.sizeGuidelineState.current();
417
- if (guideline !== rs.attach.sizeGuidelineState.announcedGuideline) {
413
+ if (rs.attach.sizeGuidelineState !== undefined && !carried("workflow_size_guideline_change")) {
414
+ const sizeState = rs.attach.sizeGuidelineState;
415
+ const guideline = sizeState.current();
416
+ if (guideline !== sizeState.announcedGuideline) {
418
417
  due.splice(due.length > 0 && due[0].source === "date_change" ? 1 : 0, 0, {
419
418
  source: "workflow_size_guideline_change",
420
419
  body: workflowSizeGuidelineChangeNotice(guideline),
421
420
  });
422
- rs.attach.sizeGuidelineState.announcedGuideline = guideline;
421
+ recordSteps.set("workflow_size_guideline_change", () => void (sizeState.announcedGuideline = guideline));
423
422
  }
424
423
  }
425
- if (rs.attach.instrState !== undefined && rs.attach.instrProbe !== undefined) {
424
+ if (rs.attach.instrState !== undefined && rs.attach.instrProbe !== undefined && !carried("instructions_change")) {
425
+ const instrState = rs.attach.instrState;
426
426
  let probed = null;
427
427
  try {
428
428
  const PROBE_CEILING_MS = 2_000;
@@ -436,10 +436,10 @@ export function createTurnBoundary(input) {
436
436
  catch {
437
437
  probed = null;
438
438
  }
439
- const cand = collectInstructionsChange(rs.attach.instrState, probed);
439
+ const cand = collectInstructionsChange(instrState, probed);
440
440
  if (cand !== undefined) {
441
441
  due.splice(due.length > 0 && due[0].source === "date_change" ? 1 : 0, 0, cand.attachment);
442
- commitInstructionsChange(rs.attach.instrState, cand.announced);
442
+ recordSteps.set("instructions_change", () => commitInstructionsChange(instrState, cand.announced));
443
443
  }
444
444
  }
445
445
  if (due.length > 0) {
@@ -447,9 +447,16 @@ export function createTurnBoundary(input) {
447
447
  for (const a of due)
448
448
  if (!isIntactSource(a.source))
449
449
  boundaryAttachmentBytes += Buffer.byteLength(a.body, "utf8");
450
- rs.attach.attachmentsInjected += due.length;
451
450
  for (const a of due) {
452
- queue.push({ type: "steering_injected", source: a.source, preview: redactThenCut(a.body, 220), ...ident() });
451
+ const record = a.commit ?? recordSteps.get(a.source);
452
+ bundleReceipts.push({
453
+ source: a.source,
454
+ commit: () => {
455
+ queue.push({ type: "steering_injected", source: a.source, preview: redactThenCut(a.body, 220), ...ident() });
456
+ rs.attach.attachmentsInjected += 1;
457
+ record?.();
458
+ },
459
+ });
453
460
  }
454
461
  }
455
462
  }
@@ -485,7 +492,7 @@ export function createTurnBoundary(input) {
485
492
  }
486
493
  if ((attachmentsPayload !== undefined || batchContextBlock !== undefined) && prepared.batchHaltRef.current === undefined) {
487
494
  const payload = attachmentsPayload !== undefined && batchContextBlock !== undefined ? `${attachmentsPayload}\n${batchContextBlock}` : (attachmentsPayload ?? batchContextBlock);
488
- for (const c of receiptCommits)
495
+ for (const c of bundleReceipts)
489
496
  prepared.frameReceipts.pending.push({ source: c.source, text: payload, commit: c.commit });
490
497
  void prepared.harness.steer(payload, { engineMinted: true }).catch(() => {
491
498
  prepared.frameReceipts.pending = prepared.frameReceipts.pending.filter((r) => r.text !== payload);