@sema-agent/core 7.70.0 → 7.71.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 (434) hide show
  1. package/CHANGELOG.md +728 -0
  2. package/dist/agents/agent-transcript-tool.js +43 -19
  3. package/dist/agents/inherited-tool-pool.d.ts +5 -1
  4. package/dist/agents/inherited-tool-pool.js +6 -0
  5. package/dist/agents/retain-ledger.js +2 -0
  6. package/dist/agents/send-message-tool.d.ts +12 -1
  7. package/dist/agents/send-message-tool.js +47 -9
  8. package/dist/agents/subagent.js +31 -10
  9. package/dist/agents/tool-filter.js +1 -2
  10. package/dist/agents/verify.js +13 -2
  11. package/dist/agents/yield-adoption.js +11 -1
  12. package/dist/brain/claude-model-id.d.ts +11 -0
  13. package/dist/brain/claude-model-id.js +3 -1
  14. package/dist/config/catalog.js +10 -1
  15. package/dist/config/defaults.d.ts +3 -0
  16. package/dist/config/defaults.js +1 -0
  17. package/dist/core/allow-entry.js +1 -2
  18. package/dist/core/ask-origin.d.ts +55 -21
  19. package/dist/core/ask-origin.js +19 -11
  20. package/dist/core/ask-question.d.ts +4 -7
  21. package/dist/core/ask-question.js +2 -4
  22. package/dist/core/ask-unresolvable-notice.d.ts +17 -3
  23. package/dist/core/ask-unresolvable-notice.js +18 -4
  24. package/dist/core/attachment-source.d.ts +1 -1
  25. package/dist/core/attachment-source.js +2 -0
  26. package/dist/core/auto-compaction.d.ts +14 -4
  27. package/dist/core/auto-compaction.js +3 -2
  28. package/dist/core/auto-strip.js +2 -0
  29. package/dist/core/caller-text.d.ts +2 -33
  30. package/dist/core/caller-text.js +2 -23
  31. package/dist/core/caller-tool-name.js +1 -2
  32. package/dist/core/canonical-json.d.ts +9 -0
  33. package/dist/core/canonical-json.js +6 -0
  34. package/dist/core/checkpoint-features.d.ts +43 -80
  35. package/dist/core/checkpoint-features.js +10 -20
  36. package/dist/core/checkpoint-generation.d.ts +89 -19
  37. package/dist/core/checkpoint-generation.js +89 -14
  38. package/dist/core/checkpoint-queries.d.ts +95 -15
  39. package/dist/core/checkpoint-queries.js +108 -7
  40. package/dist/core/checkpoint-rekey.d.ts +2 -1
  41. package/dist/core/checkpoint-rekey.js +2 -2
  42. package/dist/core/checkpoint-requirements.d.ts +7 -6
  43. package/dist/core/checkpoint-requirements.js +2 -5
  44. package/dist/core/checkpoint-row-verdict.d.ts +3 -4
  45. package/dist/core/checkpoint-row-verdict.js +20 -41
  46. package/dist/core/checkpoint-store.d.ts +65 -41
  47. package/dist/core/checkpoint-store.js +28 -14
  48. package/dist/core/command-sandbox.d.ts +5 -3
  49. package/dist/core/command-sandbox.js +17 -9
  50. package/dist/core/config-refusal-codes.d.ts +1 -1
  51. package/dist/core/config-refusal-codes.js +1 -0
  52. package/dist/core/declaration-words.d.ts +2 -1
  53. package/dist/core/declaration-words.js +13 -2
  54. package/dist/core/effective-path-target.d.ts +23 -0
  55. package/dist/core/effective-path-target.js +15 -1
  56. package/dist/core/engine-attestation.d.ts +5 -1
  57. package/dist/core/engine-attestation.js +1 -0
  58. package/dist/core/engine-capabilities.d.ts +14 -9
  59. package/dist/core/engine-capabilities.js +1 -1
  60. package/dist/core/engine-notice.d.ts +62 -32
  61. package/dist/core/engine-version.js +1 -1
  62. package/dist/core/entries-not-applied.d.ts +1 -1
  63. package/dist/core/entries-not-applied.js +1 -0
  64. package/dist/core/file-history-store.d.ts +95 -11
  65. package/dist/core/file-history-store.js +117 -19
  66. package/dist/core/gate-fold.js +13 -7
  67. package/dist/core/gate-lanes.js +9 -9
  68. package/dist/core/governance-codes.d.ts +56 -7
  69. package/dist/core/governance-codes.js +105 -7
  70. package/dist/core/grant-holder.d.ts +53 -0
  71. package/dist/core/grant-holder.js +80 -0
  72. package/dist/core/hooks.d.ts +7 -3
  73. package/dist/core/hooks.js +2 -2
  74. package/dist/core/locked-config.d.ts +7 -1
  75. package/dist/core/locked-config.js +9 -2
  76. package/dist/core/mcp-call-meta.d.ts +52 -7
  77. package/dist/core/mcp-call-meta.js +21 -2
  78. package/dist/core/mcp-host-read.d.ts +1 -1
  79. package/dist/core/mcp-server-spec.d.ts +18 -0
  80. package/dist/core/mcp-server-spec.js +1 -0
  81. package/dist/core/mcp.js +2 -2
  82. package/dist/core/member-outcome.d.ts +22 -1
  83. package/dist/core/member-outcome.js +18 -6
  84. package/dist/core/memory-engine/delegation-settlement.js +5 -5
  85. package/dist/core/memory-engine/engine.js +19 -19
  86. package/dist/core/memory-engine/file-backend.d.ts +7 -2
  87. package/dist/core/memory-engine/file-backend.js +14 -12
  88. package/dist/core/memory-engine/frontmatter.js +1 -1
  89. package/dist/core/memory-engine/index.d.ts +1 -0
  90. package/dist/core/memory-engine/index.js +1 -0
  91. package/dist/core/memory-engine/layout.d.ts +34 -9
  92. package/dist/core/memory-engine/layout.js +36 -19
  93. package/dist/core/memory-engine/memory-deployment.js +8 -8
  94. package/dist/core/memory-engine/mount-failed-notice.d.ts +8 -5
  95. package/dist/core/memory-engine/mount-failed-notice.js +5 -2
  96. package/dist/core/mode-policy.d.ts +5 -0
  97. package/dist/core/mode-policy.js +6 -0
  98. package/dist/core/mods/host.d.ts +2 -1
  99. package/dist/core/mods/host.js +7 -6
  100. package/dist/core/mods/kernel/index.d.ts +1 -1
  101. package/dist/core/mods/kernel/index.js +1 -1
  102. package/dist/core/mods/kernel/registration.d.ts +5 -2
  103. package/dist/core/mods/kernel/registration.js +19 -3
  104. package/dist/core/mods/package.d.ts +12 -1
  105. package/dist/core/mods/package.js +36 -9
  106. package/dist/core/mods/stations.d.ts +7 -1
  107. package/dist/core/mods/stations.js +17 -3
  108. package/dist/core/mods/teammate-stations.d.ts +4 -1
  109. package/dist/core/mods/teammate-stations.js +1 -1
  110. package/dist/core/native-signal.d.ts +13 -0
  111. package/dist/core/native-signal.js +18 -0
  112. package/dist/core/park-resumability.d.ts +16 -14
  113. package/dist/core/park-resumability.js +9 -4
  114. package/dist/core/path-rule-binding.js +1 -1
  115. package/dist/core/permission-rule-model.d.ts +11 -5
  116. package/dist/core/permission-rule-model.js +5 -3
  117. package/dist/core/permission-rule-org.js +1 -1
  118. package/dist/core/permission-rule-provider.d.ts +5 -1
  119. package/dist/core/permission-rule-provider.js +6 -1
  120. package/dist/core/permission-rule-session.d.ts +35 -5
  121. package/dist/core/permission-rule-session.js +32 -1
  122. package/dist/core/permission-rule-store.d.ts +5 -1
  123. package/dist/core/permission-rule-store.js +28 -5
  124. package/dist/core/permission-rules.d.ts +2 -2
  125. package/dist/core/permission-rules.js +2 -3
  126. package/dist/core/principal-name.d.ts +12 -0
  127. package/dist/core/principal-name.js +6 -2
  128. package/dist/core/read-root-grant-screen.d.ts +7 -6
  129. package/dist/core/read-root-grant-screen.js +7 -8
  130. package/dist/core/remote-env.d.ts +42 -8
  131. package/dist/core/resume-config-judge.js +1 -1
  132. package/dist/core/resume-startup-cause.d.ts +19 -4
  133. package/dist/core/resume-startup-cause.js +25 -6
  134. package/dist/core/rewind-conversation.d.ts +4 -0
  135. package/dist/core/rewrite-rejudge.d.ts +9 -1
  136. package/dist/core/rewrite-rejudge.js +11 -1
  137. package/dist/core/rule-offer-read.js +3 -2
  138. package/dist/core/runner/assemble-result.d.ts +21 -11
  139. package/dist/core/runner/assemble-result.js +24 -4
  140. package/dist/core/runner/boundary-reminders.d.ts +104 -0
  141. package/dist/core/runner/boundary-reminders.js +108 -0
  142. package/dist/core/runner/branch-writeback.d.ts +21 -7
  143. package/dist/core/runner/branch-writeback.js +44 -6
  144. package/dist/core/runner/command-sandbox-frame.js +2 -1
  145. package/dist/core/runner/compact-session.js +11 -4
  146. package/dist/core/runner/constraint-layers.d.ts +24 -5
  147. package/dist/core/runner/constraint-layers.js +21 -2
  148. package/dist/core/runner/continuation-gate.js +3 -1
  149. package/dist/core/runner/contracts.d.ts +83 -13
  150. package/dist/core/runner/cross-boundary-lane.js +2 -1
  151. package/dist/core/runner/delegation-owner.d.ts +246 -45
  152. package/dist/core/runner/delegation-owner.js +237 -63
  153. package/dist/core/runner/expire-settle.d.ts +17 -0
  154. package/dist/core/runner/expire-settle.js +8 -2
  155. package/dist/core/runner/file-history-request.d.ts +4 -3
  156. package/dist/core/runner/file-history-request.js +4 -1
  157. package/dist/core/runner/file-history-restore.d.ts +11 -3
  158. package/dist/core/runner/file-history-restore.js +11 -3
  159. package/dist/core/runner/gate-exit.d.ts +22 -1
  160. package/dist/core/runner/gate-exit.js +12 -14
  161. package/dist/core/runner/nested-memory-content.js +1 -1
  162. package/dist/core/runner/nested-memory-lane.d.ts +10 -2
  163. package/dist/core/runner/nested-memory-lane.js +29 -8
  164. package/dist/core/runner/own-model-money-door.d.ts +13 -0
  165. package/dist/core/runner/own-model-money-door.js +17 -0
  166. package/dist/core/runner/park-commit.d.ts +4 -2
  167. package/dist/core/runner/park-commit.js +2 -1
  168. package/dist/core/runner/permission-rule-lanes.d.ts +4 -0
  169. package/dist/core/runner/permission-rule-lanes.js +7 -0
  170. package/dist/core/runner/person-path-rows.js +1 -1
  171. package/dist/core/runner/placement-fence.d.ts +8 -2
  172. package/dist/core/runner/placement-fence.js +8 -3
  173. package/dist/core/runner/policy-throw.d.ts +3 -2
  174. package/dist/core/runner/policy-throw.js +2 -2
  175. package/dist/core/runner/prepare-acquire-reconcile.d.ts +23 -14
  176. package/dist/core/runner/prepare-acquire-reconcile.js +33 -15
  177. package/dist/core/runner/prepare-artifact.d.ts +14 -1
  178. package/dist/core/runner/prepare-artifact.js +7 -2
  179. package/dist/core/runner/prepare-ask-lane.d.ts +8 -0
  180. package/dist/core/runner/prepare-ask-lane.js +14 -5
  181. package/dist/core/runner/prepare-boundary-parks.js +5 -4
  182. package/dist/core/runner/prepare-config-doors.d.ts +9 -4
  183. package/dist/core/runner/prepare-config-doors.js +25 -8
  184. package/dist/core/runner/prepare-defer-classify.d.ts +8 -4
  185. package/dist/core/runner/prepare-defer-classify.js +6 -6
  186. package/dist/core/runner/prepare-execution-env.d.ts +4 -1
  187. package/dist/core/runner/prepare-execution-env.js +8 -3
  188. package/dist/core/runner/prepare-file-history.d.ts +26 -0
  189. package/dist/core/runner/prepare-file-history.js +15 -1
  190. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -3
  191. package/dist/core/runner/prepare-inherited-gate.js +9 -2
  192. package/dist/core/runner/prepare-leg-adoption.d.ts +2 -2
  193. package/dist/core/runner/prepare-park-ask.js +8 -5
  194. package/dist/core/runner/prepare-policy-chain.d.ts +5 -0
  195. package/dist/core/runner/prepare-policy-chain.js +18 -7
  196. package/dist/core/runner/prepare-prompt-assembly.d.ts +3 -0
  197. package/dist/core/runner/prepare-prompt-assembly.js +4 -3
  198. package/dist/core/runner/prepare-suspend-saga.d.ts +4 -1
  199. package/dist/core/runner/prepare-suspend-saga.js +19 -5
  200. package/dist/core/runner/prepare-task.d.ts +2 -5
  201. package/dist/core/runner/prepare-task.js +71 -26
  202. package/dist/core/runner/prepare-turn-wiring.js +7 -5
  203. package/dist/core/runner/prepare-workspace-restore.js +59 -28
  204. package/dist/core/runner/read-root-grant.d.ts +1 -0
  205. package/dist/core/runner/read-root-grant.js +1 -2
  206. package/dist/core/runner/resume-admission.d.ts +3 -0
  207. package/dist/core/runner/resume-admission.js +6 -4
  208. package/dist/core/runner/resume-apply.js +7 -5
  209. package/dist/core/runner/resume-claim.d.ts +2 -2
  210. package/dist/core/runner/resume-claim.js +4 -4
  211. package/dist/core/runner/resume-policy-outcome.d.ts +1 -1
  212. package/dist/core/runner/resume-policy-outcome.js +6 -4
  213. package/dist/core/runner/resume-preflight.d.ts +3 -0
  214. package/dist/core/runner/resume-preflight.js +10 -3
  215. package/dist/core/runner/rewind-conversation.js +11 -4
  216. package/dist/core/runner/rewind-files.js +29 -14
  217. package/dist/core/runner/rewind-outcome.d.ts +27 -0
  218. package/dist/core/runner/rewind-outcome.js +14 -0
  219. package/dist/core/runner/run-attachment-seats.js +2 -1
  220. package/dist/core/runner/run-clock-and-content.js +2 -0
  221. package/dist/core/runner/run-identity-wiring.js +2 -0
  222. package/dist/core/runner/run-leg.js +11 -1
  223. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  224. package/dist/core/runner/run-notification-lane.js +2 -2
  225. package/dist/core/runner/run-settle-and-teardown.d.ts +4 -2
  226. package/dist/core/runner/run-settle-and-teardown.js +52 -40
  227. package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
  228. package/dist/core/runner/run-stop-and-final-verify.js +5 -4
  229. package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
  230. package/dist/core/runner/run-terminal-adoption.js +3 -3
  231. package/dist/core/runner/run-turn-boundary.js +7 -0
  232. package/dist/core/runner/runtask.d.ts +7 -4
  233. package/dist/core/runner/runtask.js +18 -9
  234. package/dist/core/runner/session-call-grant-station.d.ts +64 -0
  235. package/dist/core/runner/session-call-grant-station.js +119 -0
  236. package/dist/core/runner/session-file-state-replay.js +2 -2
  237. package/dist/core/runner/session-prompt-seats.d.ts +95 -0
  238. package/dist/core/runner/session-prompt-seats.js +62 -0
  239. package/dist/core/runner/session-rule-policy.js +1 -1
  240. package/dist/core/runner/session-write-ledger.d.ts +8 -0
  241. package/dist/core/runner/session-write-ledger.js +16 -0
  242. package/dist/core/runner/side-call-account.js +5 -1
  243. package/dist/core/runner/stop-tail-notice.d.ts +7 -0
  244. package/dist/core/runner/stop-tail-notice.js +23 -8
  245. package/dist/core/runner/stream-reap.js +4 -2
  246. package/dist/core/runner/stream-settle-backstop.d.ts +1 -1
  247. package/dist/core/runner/stream-settle-backstop.js +17 -18
  248. package/dist/core/runner/terminal-account.js +17 -8
  249. package/dist/core/runner/terminal-projection.d.ts +3 -2
  250. package/dist/core/runner/terminal-projection.js +1 -1
  251. package/dist/core/runner/tool-turn-repair-seat.d.ts +2 -2
  252. package/dist/core/runner/tool-turn-repair-seat.js +12 -7
  253. package/dist/core/runner/turn-attachments.d.ts +22 -1
  254. package/dist/core/runner/turn-attachments.js +20 -3
  255. package/dist/core/runner-deps.d.ts +6 -2
  256. package/dist/core/secret-env.d.ts +26 -6
  257. package/dist/core/secret-env.js +6 -6
  258. package/dist/core/session-call-grant-screen.d.ts +58 -0
  259. package/dist/core/session-call-grant-screen.js +18 -0
  260. package/dist/core/session-call-grant.d.ts +93 -0
  261. package/dist/core/session-call-grant.js +524 -0
  262. package/dist/core/session-checkout.d.ts +3 -0
  263. package/dist/core/session-checkout.js +8 -3
  264. package/dist/core/session-policy-store.d.ts +14 -0
  265. package/dist/core/session-policy-store.js +16 -2
  266. package/dist/core/session-store.d.ts +18 -1
  267. package/dist/core/session-store.js +20 -4
  268. package/dist/core/session.d.ts +36 -4
  269. package/dist/core/shared-artifact-reads.d.ts +93 -0
  270. package/dist/core/shared-artifact-reads.js +94 -0
  271. package/dist/core/skill-grant.js +1 -1
  272. package/dist/core/skills-directory.d.ts +9 -45
  273. package/dist/core/skills-directory.js +9 -722
  274. package/dist/core/spend-account.js +3 -0
  275. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +22 -4
  276. package/dist/core/store-contracts/checkpoint-store-contract.js +363 -29
  277. package/dist/core/store-contracts/file-history-store-contract.d.ts +11 -3
  278. package/dist/core/store-contracts/file-history-store-contract.js +62 -2
  279. package/dist/core/store-contracts/grant-fixture.d.ts +52 -0
  280. package/dist/core/store-contracts/grant-fixture.js +84 -0
  281. package/dist/core/store-contracts/session-repo-contract.js +18 -0
  282. package/dist/core/store-contracts/session-store-contract.d.ts +15 -1
  283. package/dist/core/store-contracts/session-store-contract.js +211 -2
  284. package/dist/core/store-contracts/workflow-journal-store-contract.js +47 -8
  285. package/dist/core/suspend-lane-reasons.d.ts +13 -0
  286. package/dist/core/suspend-lane-reasons.js +5 -0
  287. package/dist/core/synthetic-read-verdict.d.ts +5 -3
  288. package/dist/core/synthetic-read-verdict.js +1 -1
  289. package/dist/core/task-limits.d.ts +15 -0
  290. package/dist/core/task-notification.d.ts +33 -7
  291. package/dist/core/task-notification.js +34 -9
  292. package/dist/core/task-registry-agent.d.ts +1 -1
  293. package/dist/core/task-registry-agent.js +18 -7
  294. package/dist/core/task-registry-shared.d.ts +29 -4
  295. package/dist/core/task-registry-shared.js +7 -0
  296. package/dist/core/task-registry.d.ts +21 -1
  297. package/dist/core/task-registry.js +36 -9
  298. package/dist/core/task-result.d.ts +55 -1
  299. package/dist/core/task-spec.d.ts +17 -3
  300. package/dist/core/terminal-cause.d.ts +68 -5
  301. package/dist/core/tool-catalog-entries.js +1 -1
  302. package/dist/core/tool-check-reading.js +2 -1
  303. package/dist/core/tool-errors.js +1 -0
  304. package/dist/core/tool-list-grammar.d.ts +0 -47
  305. package/dist/core/tool-list-grammar.js +1 -75
  306. package/dist/core/tool-model-gate.d.ts +7 -11
  307. package/dist/core/tool-model-gate.js +5 -8
  308. package/dist/core/tool-name-aliases.js +2 -3
  309. package/dist/core/tool-name-readings.d.ts +4 -0
  310. package/dist/core/tool-name-readings.js +1 -0
  311. package/dist/core/tool-policy.d.ts +46 -4
  312. package/dist/core/tool-policy.js +47 -18
  313. package/dist/core/tool-result-store.d.ts +0 -24
  314. package/dist/core/tool-result-store.js +1 -36
  315. package/dist/core/tool-spec.d.ts +8 -4
  316. package/dist/core/untrusted-egress.js +2 -2
  317. package/dist/core/untrusted-text.d.ts +8 -0
  318. package/dist/core/untrusted-text.js +14 -0
  319. package/dist/core/user-attachment.d.ts +16 -1
  320. package/dist/core/user-attachment.js +42 -18
  321. package/dist/core/wiring-manifest.d.ts +4 -9
  322. package/dist/core/wiring-manifest.js +1 -1
  323. package/dist/core/workflow-journal-store.d.ts +55 -8
  324. package/dist/core/workflow-journal-store.js +34 -10
  325. package/dist/core/workflow-run-store-contract.js +56 -1
  326. package/dist/core/workflow-run-store.d.ts +43 -19
  327. package/dist/core/workflow-run-store.js +17 -2
  328. package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
  329. package/dist/engine/execution-env/node-execution-env.js +4 -0
  330. package/dist/engine/harness/agent-harness.d.ts +10 -5
  331. package/dist/engine/harness/agent-harness.js +12 -4
  332. package/dist/engine/harness/types.d.ts +18 -0
  333. package/dist/engine/llm/tool-turns.d.ts +1 -1
  334. package/dist/engine/llm/types.d.ts +5 -4
  335. package/dist/engine/session/memory-repo.d.ts +15 -3
  336. package/dist/engine/session/memory-repo.js +21 -3
  337. package/dist/engine/session/memory-storage.d.ts +5 -0
  338. package/dist/engine/session/memory-storage.js +8 -3
  339. package/dist/engine/session/repo-utils.d.ts +9 -0
  340. package/dist/engine/session/repo-utils.js +14 -0
  341. package/dist/engine/session/storage-base.d.ts +20 -7
  342. package/dist/engine/session/storage-base.js +13 -1
  343. package/dist/index.d.ts +37 -19
  344. package/dist/index.js +30 -15
  345. package/dist/internal/harness.d.ts +1 -1
  346. package/dist/internal/harness.js +1 -1
  347. package/dist/orchestration/run-workflow-tool.d.ts +13 -1
  348. package/dist/orchestration/run-workflow-tool.js +101 -32
  349. package/dist/orchestration/workflow-park-adoption.d.ts +309 -92
  350. package/dist/orchestration/workflow-park-adoption.js +588 -323
  351. package/dist/orchestration/workflow-tree-id.d.ts +66 -0
  352. package/dist/orchestration/workflow-tree-id.js +66 -0
  353. package/dist/orchestration/workflow-types.d.ts +90 -11
  354. package/dist/orchestration/workflow-types.js +10 -1
  355. package/dist/orchestration/workflow.d.ts +30 -4
  356. package/dist/orchestration/workflow.js +424 -114
  357. package/dist/prompt-assembly/catalog/constitution.js +5 -1
  358. package/dist/prompt-assembly/catalog/core-behavior.d.ts +3 -4
  359. package/dist/prompt-assembly/catalog/core-behavior.js +61 -22
  360. package/dist/prompt-assembly/catalog/environment.js +2 -2
  361. package/dist/prompt-assembly/catalog/events.d.ts +16 -0
  362. package/dist/prompt-assembly/catalog/events.js +2 -0
  363. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +72 -44
  364. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +2 -2
  365. package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +2 -0
  366. package/dist/prompt-assembly/catalog/schema.d.ts +5 -1
  367. package/dist/prompt-assembly/catalog/schema.js +2 -0
  368. package/dist/prompt-assembly/catalog/sections.js +3 -14
  369. package/dist/prompt-assembly/event-registry.js +2 -0
  370. package/dist/prompt-assembly/select.js +1 -0
  371. package/dist/prompt-assembly/tool-catalog.d.ts +10 -7
  372. package/dist/prompt-assembly/tool-catalog.js +21 -7
  373. package/dist/prompt-assembly/types.d.ts +3 -0
  374. package/dist/prompts/default.d.ts +4 -1
  375. package/dist/prompts/default.js +6 -0
  376. package/dist/stores/file/checkpoint-store.d.ts +11 -10
  377. package/dist/stores/file/checkpoint-store.js +36 -10
  378. package/dist/stores/file/file-history-store.d.ts +6 -0
  379. package/dist/stores/file/file-history-store.js +21 -4
  380. package/dist/stores/file/fs-atomic.d.ts +1 -1
  381. package/dist/stores/file/index.d.ts +14 -4
  382. package/dist/stores/file/index.js +21 -5
  383. package/dist/stores/file/process-anchor.d.ts +9 -1
  384. package/dist/stores/file/session-policy-store.js +2 -17
  385. package/dist/stores/file/session-store.d.ts +27 -0
  386. package/dist/stores/file/session-store.js +81 -9
  387. package/dist/stores/file/workflow-journal-store.d.ts +14 -4
  388. package/dist/stores/file/workflow-journal-store.js +32 -24
  389. package/dist/stores/file/workflow-run-store.d.ts +15 -4
  390. package/dist/stores/file/workflow-run-store.js +76 -0
  391. package/dist/tools/artifact/artifact-tool.d.ts +10 -3
  392. package/dist/tools/artifact/artifact-tool.js +16 -1
  393. package/dist/tools/fs/bash-program-position.d.ts +10 -4
  394. package/dist/tools/fs/bash-program-position.js +11 -8
  395. package/dist/tools/fs/bash-readonly-classifier.d.ts +3 -1
  396. package/dist/tools/fs/bash-readonly-classifier.js +9 -2
  397. package/dist/tools/fs/find-actions.d.ts +30 -16
  398. package/dist/tools/fs/find-actions.js +272 -19
  399. package/dist/tools/fs/fs-bash.js +8 -5
  400. package/dist/tools/fs/fs-shared.d.ts +0 -29
  401. package/dist/tools/fs/fs-shared.js +0 -5
  402. package/dist/tools/fs/fs-write.js +2 -1
  403. package/dist/tools/fs/read-deny.d.ts +6 -1
  404. package/dist/tools/fs/read-deny.js +6 -1
  405. package/dist/tools/fs/read-floor.d.ts +6 -0
  406. package/dist/tools/fs/read-floor.js +5 -1
  407. package/dist/tools/fs/removal-actions.d.ts +43 -0
  408. package/dist/tools/fs/removal-actions.js +25 -0
  409. package/dist/tools/fs/removal-targets.d.ts +2 -21
  410. package/dist/tools/fs/removal-targets.js +2 -3
  411. package/dist/tools/fs/safety.d.ts +37 -1
  412. package/dist/tools/fs/safety.js +52 -0
  413. package/dist/tools/fs/shell-climb.d.ts +46 -0
  414. package/dist/tools/fs/shell-climb.js +79 -0
  415. package/dist/tools/fs/shell-read-check.js +47 -19
  416. package/dist/tools/fs/shell-read-establish.js +36 -22
  417. package/dist/tools/fs/shell-read-judge.d.ts +10 -2
  418. package/dist/tools/fs/shell-read-judge.js +4 -4
  419. package/dist/tools/fs/shell-read-plan.d.ts +3 -0
  420. package/dist/tools/fs/shell-read-plan.js +1 -1
  421. package/dist/tools/fs/shell-read-workdir.js +3 -2
  422. package/dist/tools/fs/shell-read-write-targets.d.ts +4 -3
  423. package/dist/tools/fs/shell-read-write-targets.js +3 -0
  424. package/package.json +2 -2
  425. package/test/export-surface.snapshot.json +169 -15
  426. package/wire-changes/core-stores-sql@7.71.0.json +40 -0
  427. package/wire-changes/core@7.71.0.json +5827 -0
  428. package/wire-changes/mods-kernel@7.71.0.json +52 -0
  429. package/wire-changes/primitives@7.71.0.json +473 -0
  430. package/wire-changes/wiki-gate@7.71.0.json +40 -0
  431. package/dist/core/frontmatter-fence.d.ts +0 -10
  432. package/dist/core/frontmatter-fence.js +0 -6
  433. package/dist/core/permission-rule-syntax.d.ts +0 -46
  434. package/dist/core/permission-rule-syntax.js +0 -52
@@ -0,0 +1,119 @@
1
+ import { deliverEngineNotice } from "../types.js";
2
+ import { legNoticeTaskId } from "../mods/stations.js";
3
+ import { resolveOwnerStore } from "../permission-rule-provider.js";
4
+ import { landRuleAdd, writerOf } from "../permission-rule-store.js";
5
+ import { cardRuleFormOf, COMMAND_RULE_TOOL } from "../permission-rule-model.js";
6
+ import { wireOf } from "../tool-name-readings.js";
7
+ import { thrownText } from "../thrown-value.js";
8
+ import { DEFAULT_GATE_AWAIT_TIMEOUT_MS } from "../gate-bounded-await.js";
9
+ import { bindCall, CALL_GRANT_MATCH, callGrantCommandOf, callGrantRuleTextOf, offerOfBinding } from "../session-call-grant.js";
10
+ export function createCallGrantDoorOf(offersOf) {
11
+ return (call, args, ask) => {
12
+ if (ask === undefined || ask.classes?.some((c) => c === "sandbox_override" || c === "a2a_inside") === true)
13
+ return false;
14
+ if (cardRuleFormOf(wireOf("offer.callGrantTool", call), call) !== "command")
15
+ return false;
16
+ const offered = offersOf(call, args, ask);
17
+ return Object.keys(offered).length > 0 && (offered.ruleOffersAbsence === undefined || offered.ruleOffersAbsence === "lane_cannot_speak");
18
+ };
19
+ }
20
+ const WHY = {
21
+ not_a_string: "the grant is not a string",
22
+ no_offer: "this approval card offered no session grant",
23
+ mismatch: "the grant is not the one the card offered (it must be sent back exactly as offered)",
24
+ edited: "the approval changed the call's input, and the grant names the call the card showed",
25
+ };
26
+ function announceRejected(at, reason, why, offered, requested) {
27
+ deliverEngineNotice(at.onNotice, {
28
+ code: "approval.session_call_grant_rejected",
29
+ message: `the approval for "${at.toolName}" asked to allow this call for the rest of the session, and nothing was kept: ${why}. The approval's own verdict is unchanged.`,
30
+ detail: { reason, ...(offered !== undefined ? { offered } : {}), ...(requested !== undefined ? { requested } : {}), toolName: at.toolName, toolCallId: at.toolCallId, checkpointId: at.checkpointId, sessionId: at.sessionId, runId: at.runId, ...legNoticeTaskId(at) },
31
+ });
32
+ }
33
+ export function settleUnofferedSessionCallGrant(screen, at) {
34
+ if (screen === undefined)
35
+ return undefined;
36
+ const reason = screen.verdict === "rejected" ? screen.reason : "no_offer";
37
+ announceRejected(at, reason, WHY[reason], undefined, screen.verdict === "rejected" ? screen.requested : screen.grant.slice(0, 200));
38
+ return undefined;
39
+ }
40
+ export function sessionCallGrantStation(cfg) {
41
+ const bounded = (signal) => AbortSignal.any([...(signal !== undefined ? [signal] : []), AbortSignal.timeout(DEFAULT_GATE_AWAIT_TIMEOUT_MS)]);
42
+ const write = async (binding, toolCallId, signal) => {
43
+ const owner = cfg.sessionRowOwner();
44
+ if (owner === undefined)
45
+ return { landed: false, reason: "the run no longer keeps session rules (the rule store's writer is not this engine's)" };
46
+ let writer;
47
+ let store;
48
+ try {
49
+ store = resolveOwnerStore({ provider: cfg.provider, owner });
50
+ writer = writerOf(store);
51
+ }
52
+ catch (err) {
53
+ return { landed: false, reason: `the rule store could not be resolved (${thrownText(err)})` };
54
+ }
55
+ if (writer === undefined)
56
+ return { landed: false, reason: "the resolved permission-rule store has no write face" };
57
+ if (signal.aborted)
58
+ return { landed: false, reason: "the call ended before the session row was written" };
59
+ const command = callGrantCommandOf(binding);
60
+ try {
61
+ const dot = await writer.nextDot();
62
+ const landing = await landRuleAdd({
63
+ store,
64
+ writer,
65
+ delta: {
66
+ kind: "redemption-add",
67
+ behavior: "allow",
68
+ rule: callGrantRuleTextOf(command),
69
+ scope: { kind: "session", sessionId: cfg.sessionId },
70
+ tool: COMMAND_RULE_TOOL,
71
+ match: CALL_GRANT_MATCH,
72
+ command,
73
+ add: { dot, origin: "user", createdAt: new Date(cfg.now?.() ?? Date.now()).toISOString() },
74
+ redemption: { recordId: `card:${toolCallId}`, ...(owner.kind === "principal" ? { principal: owner.principal } : { owner }) },
75
+ },
76
+ });
77
+ return landing.landed ? { landed: true } : { landed: false, reason: landing.committed === "unknown" ? `${landing.reason} — if it landed, the call stays allowed for the session` : landing.reason };
78
+ }
79
+ catch (err) {
80
+ return { landed: false, reason: `the session row could not be written (${thrownText(err)}) — if it landed, the call stays allowed for the session` };
81
+ }
82
+ };
83
+ return {
84
+ mint: async (command, signal) => {
85
+ if (cfg.provider.revokeSessionRule === undefined || cfg.sessionRowOwner() === undefined)
86
+ return undefined;
87
+ const binding = await bindCall(command, cfg.seat(), bounded(signal)).catch(() => undefined);
88
+ if (binding === undefined || "unbindable" in binding)
89
+ return undefined;
90
+ return { offer: offerOfBinding(binding), binding };
91
+ },
92
+ settle: (screen, minted, at) => {
93
+ if (screen === undefined)
94
+ return undefined;
95
+ const ids = { toolName: at.toolName, toolCallId: at.toolCallId, checkpointId: at.checkpointId, sessionId: at.sessionId, runId: at.runId, ...legNoticeTaskId(at) };
96
+ const offered = minted?.offer.grant;
97
+ if (screen.verdict === "rejected") {
98
+ announceRejected(at, screen.reason, WHY[screen.reason], offered, screen.requested);
99
+ return undefined;
100
+ }
101
+ if (minted === undefined || minted.offer.grant !== screen.grant) {
102
+ announceRejected(at, "no_offer", WHY.no_offer, offered);
103
+ return undefined;
104
+ }
105
+ const signal = bounded(at.signal);
106
+ return write(minted.binding, at.toolCallId, signal).then((written) => {
107
+ if (!written.landed) {
108
+ announceRejected(at, "not_written", `the session row was not written (${written.reason})`, offered);
109
+ return;
110
+ }
111
+ deliverEngineNotice(at.onNotice, {
112
+ code: "approval.session_call_granted",
113
+ message: `the approval for "${at.toolName}" allows this call for the rest of this session: ${minted.offer.sentence}.`,
114
+ detail: { rule: minted.offer.grant, cwd: minted.offer.cwd, programs: [...minted.offer.programs], ...ids },
115
+ });
116
+ });
117
+ },
118
+ };
119
+ }
@@ -1,8 +1,8 @@
1
1
  import { userAttachmentOf } from "../../internal/llm.js";
2
2
  import { isAbsoluteForFamily, pathFamilyOf, sha256 } from "../../tools/fs/safety.js";
3
- import { applyRecordedEdit, entriesCarriedAcrossLegs } from "../../tools/fs/fs-shared.js";
3
+ import { entriesCarriedAcrossLegs } from "../../tools/fs/fs-shared.js";
4
4
  import { normalizeFileText } from "../../tools/fs/encoding.js";
5
- import { offloadedDetailOf } from "../tool-result-store.js";
5
+ import { applyRecordedEdit, offloadedDetailOf } from "@sema-agent/primitives";
6
6
  import { attachmentTransmissionId, isInstructionLaneEntry } from "../user-attachment.js";
7
7
  import { fileArgPath } from "../tool-registry.js";
8
8
  import { leadingSystemReminderOpen } from "../reminder-mint.js";
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The Runner's per-session PROMPT seats: what the reference keeps about a session's prompt in its process state, in this
3
+ * process — the session clock the elapsed-time reminder reads, and the session's shell-first judgment the Bash card is chosen by.
4
+ *
5
+ * One seat per session tree (the root's address key, `rootSessionAddressKeyOf`: its scope, id and occupant), so a child leg
6
+ * reads its root's facts, as the reference's process-wide state is read by its subagents. In-process only, as the reference
7
+ * keeps it: a session continued on another Runner instance or in another process starts with no facts (the elapsed clock then
8
+ * starts at its first reading). Bounded by {@link MAX_SESSIONS} sessions, least recently used out first (a dropped session reads as
9
+ * one with no facts). A CACHE, never an authority — nothing here is persisted.
10
+ */
11
+ import type { PermissionMode } from "../ask-origin.js";
12
+ import type { PromptTraitName } from "../../prompt-assembly/catalog/schema.js";
13
+ import type { ToolCardFacts } from "../../prompt-assembly/tool-catalog.js";
14
+ import type { TaskSpec } from "../types.js";
15
+ import { type LegOpening, type RunTimeReminderLane } from "./boundary-reminders.js";
16
+ /**
17
+ * What a leg's prepare takes from its session tree's prompt seat: the card facts its tool cards are mounted with (the session's
18
+ * shell-first judgment, {@link shellFirstSessionOf}), and the run-time reminders' lane (the run's traits read once, the task's
19
+ * switches, a top-level leg) with the leg's handle on the tree's elapsed clock. `key` is the tree's address key; undefined (an
20
+ * address that names nobody) ⇒ the leg keeps facts of its own. `seats` absent (a standalone prepare) ⇒ the same.
21
+ */
22
+ export declare function preparePromptSeats(input: {
23
+ readonly seats: SessionPromptSeats | undefined;
24
+ readonly key: string | undefined;
25
+ readonly traits: ReadonlySet<PromptTraitName>;
26
+ readonly childLeg: boolean;
27
+ readonly attachments: TaskSpec["attachments"];
28
+ /** The mode the leg runs under (the controller's effective word). */
29
+ readonly mode: PermissionMode;
30
+ /** In a plan: the mode it was entered from, as that mode runs (`PermissionModeController.prePlanModeObserved`). */
31
+ readonly prePlanMode: PermissionMode | undefined;
32
+ readonly now: () => number;
33
+ }): {
34
+ readonly cardFacts: ToolCardFacts;
35
+ readonly runTimeReminders: {
36
+ readonly lane: RunTimeReminderLane;
37
+ readonly elapsedClock: ElapsedTimeClock;
38
+ readonly opening: {
39
+ current?: LegOpening;
40
+ };
41
+ };
42
+ };
43
+ /** What one session tree's prompt holds in this process. */
44
+ export interface SessionPromptFacts {
45
+ /** The session clock: when (on the run's clock, `Prepared.now`) the person last gave the session an input its elapsed-time
46
+ * reminder counts from. Absent = no clock (none started yet, or the reminder was off when the person last spoke). */
47
+ elapsedSince?: number;
48
+ /** The session's shell-first judgment ({@link shellFirstSessionOf}), made once — by the first leg of the tree this process
49
+ * prepares — and read by every later leg of it, its children included. Absent = not judged yet in this process. */
50
+ shellFirst?: boolean;
51
+ }
52
+ /**
53
+ * Whether the session is a shell-first one (the `shellFirstSession` prompt fact), judged once per session tree as the reference
54
+ * judges it once per session (`bashFirstDescriptionTrimmed ??=`): the mode the judging leg runs under (a plan: the mode it was
55
+ * entered from as that mode runs, `prePlanMode`) is auto or bypassPermissions, and its model holds a shell-first trait. A later leg — a mode
56
+ * switched mid-session, another model, a delegated child — reads the judgment; it never judges again (the card, and the prompt
57
+ * prefix it sits in, stays put).
58
+ */
59
+ export declare function shellFirstSessionOf(facts: SessionPromptFacts, leg: {
60
+ readonly mode: PermissionMode;
61
+ readonly prePlanMode: PermissionMode | undefined;
62
+ readonly traits: ReadonlySet<PromptTraitName>;
63
+ }): boolean;
64
+ /** One Runner's session trees' prompt facts, keyed as the fast-mode seat keys its facts. */
65
+ export declare class SessionPromptSeats {
66
+ #private;
67
+ /** The session tree's facts, made on the first ask (a least-recently-used touch on every ask). */
68
+ of(key: string): SessionPromptFacts;
69
+ }
70
+ /** A leg's handle on its session tree's elapsed-time clock ({@link SessionPromptFacts.elapsedSince}). */
71
+ export interface ElapsedTimeClock {
72
+ /** The leg's objective is the person's own (its author counts as the operator's): its commit will move the clock. An objective
73
+ * another author wrote — a recipe's own continuation, a delegator's — is never admitted, nor is a steer that lands mid-run (the
74
+ * reference restarts its clock at a new prompt only, `VOi` in its `processUserInput`; a mid-turn input is an attachment there). */
75
+ admit(inputId: string): void;
76
+ /** A person's-input row was committed (`origin: "human_input"`, its `inputId`): an admitted input {@link restart}s the clock. */
77
+ committed(inputId: string | undefined): void;
78
+ /** The person's words reached the session (an admitted input's commit; a resume's continuation carrying a parked steer or the
79
+ * wake message, which are the operator's): the clock starts again from now when the reminder is on, and is cleared when it is
80
+ * off. A child leg's inputs do not move it. */
81
+ restart(): void;
82
+ /** The time since the clock started, in ms; a session with no clock starts one now (the first reading is 0). */
83
+ elapsedMs(): number;
84
+ }
85
+ /**
86
+ * The leg's elapsed-time clock over its tree's facts. `facts` is the tree's ({@link SessionPromptSeats.of}) — or the leg's own
87
+ * when its root's address names nobody, shared with no one; `root` is whether the leg is its tree's root leg (only a root leg's
88
+ * person inputs restart the clock); `on` is whether the leg's elapsed-time reminder is on.
89
+ */
90
+ export declare function elapsedTimeClockOf(input: {
91
+ readonly facts: SessionPromptFacts;
92
+ readonly root: boolean;
93
+ readonly on: boolean;
94
+ readonly now: () => number;
95
+ }): ElapsedTimeClock;
@@ -0,0 +1,62 @@
1
+ import { traitsHold } from "../../prompt-assembly/select.js";
2
+ import { runTimeReminderLane } from "./boundary-reminders.js";
3
+ import { attachmentSwitchOn } from "./turn-attachments.js";
4
+ export function preparePromptSeats(input) {
5
+ const { key, traits, childLeg, attachments, mode, prePlanMode, now } = input;
6
+ const facts = key !== undefined ? (input.seats ?? new SessionPromptSeats()).of(key) : {};
7
+ const lane = runTimeReminderLane({
8
+ traits,
9
+ childLeg,
10
+ switches: { silentTurn: attachmentSwitchOn(attachments, "silentTurnReminder", "silent_turn_reminder"), elapsedTime: attachmentSwitchOn(attachments, "elapsedTimeReminder", "elapsed_time_reminder") },
11
+ });
12
+ return Object.freeze({
13
+ cardFacts: Object.freeze({ shellFirstSession: shellFirstSessionOf(facts, { mode, prePlanMode, traits }) }),
14
+ runTimeReminders: Object.freeze({ lane, elapsedClock: elapsedTimeClockOf({ facts, root: !childLeg, on: lane.elapsedTime, now }), opening: {} }),
15
+ });
16
+ }
17
+ const MAX_SESSIONS = 4096;
18
+ const SHELL_FIRST_TRAITS = Object.freeze([{ allOf: ["thrifty_sonic"] }, { allOf: ["fable_5_1_prompt_bundle"] }, { allOf: ["opus_5_5_prompt_bundle"] }]);
19
+ const SHELL_FIRST_MODES = new Set(["auto", "bypassPermissions"]);
20
+ export function shellFirstSessionOf(facts, leg) {
21
+ facts.shellFirst ??= SHELL_FIRST_MODES.has(leg.mode === "plan" ? leg.prePlanMode : leg.mode) && SHELL_FIRST_TRAITS.some((c) => traitsHold(c, leg.traits));
22
+ return facts.shellFirst;
23
+ }
24
+ export class SessionPromptSeats {
25
+ #facts = new Map();
26
+ of(key) {
27
+ const held = this.#facts.get(key) ?? {};
28
+ this.#facts.delete(key);
29
+ this.#facts.set(key, held);
30
+ if (this.#facts.size > MAX_SESSIONS) {
31
+ const oldest = this.#facts.keys().next().value;
32
+ if (oldest !== undefined)
33
+ this.#facts.delete(oldest);
34
+ }
35
+ return held;
36
+ }
37
+ }
38
+ export function elapsedTimeClockOf(input) {
39
+ const { facts, root, on, now } = input;
40
+ const admitted = new Set();
41
+ const restart = () => {
42
+ if (!root)
43
+ return;
44
+ if (on)
45
+ facts.elapsedSince = now();
46
+ else
47
+ delete facts.elapsedSince;
48
+ };
49
+ return {
50
+ admit: (inputId) => void admitted.add(inputId),
51
+ committed: (inputId) => {
52
+ if (inputId !== undefined && admitted.delete(inputId))
53
+ restart();
54
+ },
55
+ restart,
56
+ elapsedMs: () => {
57
+ const at = now();
58
+ facts.elapsedSince ??= at;
59
+ return Math.max(0, at - facts.elapsedSince);
60
+ },
61
+ };
62
+ }
@@ -1,7 +1,7 @@
1
1
  import { canonicalizeTarget, isWinFormPath, pathFamilyOf, writeTargetPath } from "../../tools/fs/safety.js";
2
2
  import { REFUSES_NO_WHOLE_TOOL, TOOL_TABLE_VIEW_READ } from "../tool-policy.js";
3
3
  import { NO_RETIRED_READING, ruleListUnderView } from "../tool-name-aliases.js";
4
- import { ruleSpellingOf } from "../permission-rule-syntax.js";
4
+ import { ruleSpellingOf } from "@sema-agent/primitives";
5
5
  import { SESSION_RULES_GRAMMAR, compileSessionRuleBucket, continuesLineage, earlierGrammarAnnouncer, earlierGrammarEntries, earlierGrammarNotices, earlierGrammarRefusalClause, readSessionRulesShape, unreadableDenyEntries } from "../session-policy-store.js";
6
6
  import { compiledEntryName, judgeAllowEntries, uncoveredCommandSegment, wholeToolEntryOf } from "../allow-entry.js";
7
7
  import { inlineUntrusted } from "../untrusted-text.js";
@@ -25,6 +25,14 @@ export declare class SessionWriteLedger {
25
25
  */
26
26
  drained(sessionId: string, ms: number): Promise<boolean>;
27
27
  }
28
+ /**
29
+ * THE stamp of a writer's grant holder on its session writes: the two write members are called with the holder added to their options
30
+ * (`SessionWriteOptions.holder`), every other member is the storage's own. The options handed on are a plain object built here, the
31
+ * caller's `expectedLeafId` read once into it — never the caller's object, so nothing the caller passed runs code between the store's
32
+ * judgement and its write. Per writer and non-mutating (a Proxy). A run's leg and the out-of-run session verbs install it the same
33
+ * way, only when they carry a holder; a leg an engine lane started carries none to stamp.
34
+ */
35
+ export declare function stampHolder(storage: SessionStorage, holder: string): SessionStorage;
28
36
  /**
29
37
  * The acquired storage as a leg writes it: the two write members go through `leg.issue` (named by the entry type, `leaf` for a
30
38
  * leaf move, with the leaf the session is on once it lands — `leafIdAfterEntry` of the entry, the target of a leaf move — and the
@@ -101,6 +101,22 @@ export class SessionWriteLedger {
101
101
  wake();
102
102
  }
103
103
  }
104
+ export function stampHolder(storage, holder) {
105
+ const stamped = (opts) => {
106
+ const expected = opts?.expectedLeafId;
107
+ return expected !== undefined ? { expectedLeafId: expected, holder } : { holder };
108
+ };
109
+ return new Proxy(storage, {
110
+ get(target, prop, receiver) {
111
+ if (prop === "appendEntry")
112
+ return (entry, opts) => target.appendEntry(entry, stamped(opts));
113
+ if (prop === "setLeafId")
114
+ return (leafId, opts) => target.setLeafId(leafId, stamped(opts));
115
+ const value = Reflect.get(target, prop, receiver);
116
+ return typeof value === "function" ? value.bind(target) : value;
117
+ },
118
+ });
119
+ }
104
120
  export function writesThroughLeg(storage, leg, sessionId) {
105
121
  return new Proxy(storage, {
106
122
  get(target, prop, receiver) {
@@ -76,11 +76,15 @@ export function costFigureOf(telemetry, costMicroUsd) {
76
76
  export function recordSideCallUsage(stats, usage, lane, call) {
77
77
  if (usage === undefined || call.usageMissing === true)
78
78
  stats.usageMissing = true;
79
+ const { account } = call;
79
80
  if (usage === undefined) {
81
+ const { modelId, price, priced, tableExists } = priceReply({}, call.model, account.pricing(), true);
82
+ if (!priced)
83
+ noteUnpricedSpend(account.telemetry, unpricedCallCause(modelId, tableExists, lane));
84
+ account.noteUnevaluablePriceTable(price);
80
85
  bookCacheOperands(stats, lane, undefined, true, 0);
81
86
  return;
82
87
  }
83
- const { account } = call;
84
88
  const { modelId, served, price, priced, tableExists, totalInputTokens, uncachedInputTokens, costMicroUsd } = priceReply(usage, call.model, account.pricing(), call.usageMissing === true);
85
89
  if (!priced)
86
90
  noteUnpricedSpend(account.telemetry, unpricedCallCause(modelId, tableExists, lane));
@@ -38,3 +38,10 @@ export declare function stopTailWaitedFor(owed: Pick<DeliveryObligations, "pendi
38
38
  }, registry?: Pick<TaskRegistry, "runEndReading">): readonly StopTailWaitedTask[];
39
39
  /** `task.interrupt_unconsumed`, for a stop that landed after the answer settled. `origin` names the axis that stopped the run. */
40
40
  export declare function interruptUnconsumedNotice(waitedFor: readonly StopTailWaitedTask[], origin: string, ids: Record<string, string>): EngineNotice;
41
+ /**
42
+ * `task.wait_ceiling_reached`, for a one-shot ending whose wait reached its ceiling (`limits.oneShotWaitCeilingMs`, `ceilingMs` the
43
+ * value it waited under) with background tasks it started still owed: no stop arrived — the wait gave up. `waitedFor` is the same
44
+ * reading the stop's notice carries ({@link stopTailWaitedFor}), taken before the run-end sweep; never empty (the ceiling only stops a
45
+ * wait with something still owed).
46
+ */
47
+ export declare function waitCeilingReachedNotice(waitedFor: readonly StopTailWaitedTask[], ceilingMs: number, ids: Record<string, string>): EngineNotice;
@@ -15,21 +15,36 @@ function named(t) {
15
15
  const what = `${t.taskType !== undefined ? (TYPE_WORD[t.taskType] ?? t.taskType) : "task"} ${t.taskId}`;
16
16
  return t.description !== undefined ? `${what} "${t.description}"` : what;
17
17
  }
18
- export function interruptUnconsumedNotice(waitedFor, origin, ids) {
19
- const tail = "the answer stands as the result, the run ends completed, and no interruption marker or limit code records the stop.";
20
- if (waitedFor.length === 0) {
21
- return { code: "task.interrupt_unconsumed", message: `a stop arrived after the run had already given its answer: nothing was cut or stopped by it — ${tail}`, detail: { ...ids, origin, waitedFor: [] } };
22
- }
18
+ function fatesSaid(waitedFor) {
23
19
  const parts = [
24
20
  ["stopped with the run", waitedFor.filter((t) => t.stopped === true)],
25
21
  ["no longer waited for, left to their own lifetime", waitedFor.filter((t) => t.stopped === false)],
26
22
  ["not found at the run's end", waitedFor.filter((t) => t.stopped === undefined)],
27
23
  ];
28
- const said = parts.filter(([, ts]) => ts.length > 0).map(([what, ts]) => `${what}: ${ts.map(named).join(", ")}`);
24
+ return parts
25
+ .filter(([, ts]) => ts.length > 0)
26
+ .map(([what, ts]) => `${what}: ${ts.map(named).join(", ")}`)
27
+ .join("; ");
28
+ }
29
+ const counted = (n) => `${n} background task${n === 1 ? "" : "s"}`;
30
+ export function interruptUnconsumedNotice(waitedFor, origin, ids) {
31
+ const tail = "the answer stands as the result, the run ends completed, and no interruption marker or limit code records the stop.";
32
+ if (waitedFor.length === 0) {
33
+ return { code: "task.interrupt_unconsumed", message: `a stop arrived after the run had already given its answer: nothing was cut or stopped by it — ${tail}`, detail: { ...ids, origin, waitedFor: [] } };
34
+ }
29
35
  return {
30
36
  code: "task.interrupt_unconsumed",
31
- message: `a stop arrived after the run had already given its answer, while it was still waiting for ${waitedFor.length} background task${waitedFor.length === 1 ? "" : "s"} it started; ` +
32
- `the stop ended that wait (${said.join("; ")}) — the result carries nothing from them, ${tail}`,
37
+ message: `a stop arrived after the run had already given its answer, while it was still waiting for ${counted(waitedFor.length)} it started; ` +
38
+ `the stop ended that wait (${fatesSaid(waitedFor)}) — the result carries nothing from them, ${tail}`,
33
39
  detail: { ...ids, origin, waitedFor: waitedFor.map((t) => ({ ...t })) },
34
40
  };
35
41
  }
42
+ export function waitCeilingReachedNotice(waitedFor, ceilingMs, ids) {
43
+ return {
44
+ code: "task.wait_ceiling_reached",
45
+ message: `the run gave its answer and waited ${ceilingMs} ms (its one-shot wait ceiling) for ${counted(waitedFor.length)} it started, then stopped waiting ` +
46
+ `(${fatesSaid(waitedFor)}) — the answer stands as the result and carries nothing from them. ` +
47
+ `The host can raise this wait's ceiling, or lift it so the wait lasts as long as the run's time limit allows.`,
48
+ detail: { ...ids, ceilingMs, waitedFor: waitedFor.map((t) => ({ ...t })) },
49
+ };
50
+ }
@@ -1,4 +1,4 @@
1
- import { runExpiredDuty, settleLostRow } from "./expire-settle.js";
1
+ import { expireCarrying, runExpiredDuty, settleLostRow } from "./expire-settle.js";
2
2
  export function streamReap(input) {
3
3
  const { live, runner, locallyClaimedTokens, parentConstraintRegistry, suspendedEnvReaps } = input;
4
4
  const reapSuspended = async () => {
@@ -14,7 +14,7 @@ export function streamReap(input) {
14
14
  };
15
15
  let won;
16
16
  try {
17
- won = await rh.store.expire(rh.token, rh.scope);
17
+ won = await expireCarrying(rh.store, rh.token, rh.scope, rh.holder);
18
18
  }
19
19
  catch (err) {
20
20
  reportErr(err);
@@ -32,6 +32,8 @@ export function streamReap(input) {
32
32
  const settledAway = seen === "resolved" || seen === "absent";
33
33
  if (settledAway && !claimed && !locallyClaimedTokens.held(rh.token))
34
34
  suspendedEnvReaps.delete(rh.token);
35
+ if (seen === "pending" && rh.holder !== undefined && !claimed)
36
+ reportErr(new Error("suspended stream destroy: the checkpoint was not expired — the run's grant is no longer current (another leg holds the run, or the run has ended) or a resume moved the row; the paused workspace and the pending row are left to the current holder or the deployment's own cancel and reaper"));
35
37
  };
36
38
  return { reapSuspended };
37
39
  }
@@ -11,7 +11,7 @@ export interface StreamSettleBackstopInput {
11
11
  resume: ResumeRun | undefined;
12
12
  /** borrowed-mutable — the stream's event queue: the backstop pushes the `done` frame and closes it. */
13
13
  queue: PushQueue<TaskEvent>;
14
- /** borrowed-mutable — the run body's backstop carrier (effective ids + post-prepare observations); the owed delegation terminal is cleared here once delivered. */
14
+ /** borrowed-mutable — the run body's backstop carrier (effective ids + post-prepare observations); the owed delegation terminal is cleared here once delivered, and the env a refused resume leg handed over (`legEnvForRow`) taken. */
15
15
  taskIdRef: TaskIdRef;
16
16
  /** borrowed-readonly — the invocation's frozen tracer (one sink for the start↔end pair). */
17
17
  entryTracer: {
@@ -1,5 +1,5 @@
1
1
  import { thrownFailureOf } from "./terminal-account.js";
2
- import { compensateUnstarted, reopenReasonOf, resumeAgainMayCure, unstartedFailureOf, unstartedRowSentence } from "../resume-startup-cause.js";
2
+ import { compensateUnstarted, reopenReasonOf, resumeAgainMayCure, rowKeepsWhatItsRetryNeeds, unstartedFailureOf, unstartedRowSentence } from "../resume-startup-cause.js";
3
3
  import { resumeDecisionWasNegative } from "./decide-continuation.js";
4
4
  import { drainForwardedFramesBeforeDone, forwardsSubagentEvents } from "./prepare-run-refs.js";
5
5
  import { hasDestroy } from "../remote-env.js";
@@ -8,6 +8,8 @@ import { settleTeardownLeg } from "./teardown-bounded.js";
8
8
  import { emitTrace } from "../trace.js";
9
9
  import { deliverDelegationLifecycle } from "../types.js";
10
10
  import { unsettledLegContinuesFrom } from "./continues-from.js";
11
+ import { resultPostureSeats } from "./assemble-result.js";
12
+ import { withRewindOutcome } from "./rewind-outcome.js";
11
13
  import { asThrownError, readMember, thrownText } from "../thrown-value.js";
12
14
  export function streamSettleBackstop(input) {
13
15
  const { spec, resume, queue, taskIdRef, entryTracer, runStartedAt, live, runner, sessions, locallyClaimedTokens, parentConstraintRegistry, suspendedEnvReaps } = input;
@@ -16,21 +18,16 @@ export function streamSettleBackstop(input) {
16
18
  const failure = unstartedFailureOf(code, detail, sessions);
17
19
  const reopenReason = reopenReasonOf(failure.cause);
18
20
  const reopenable = resume !== undefined && live.resultValue === undefined && resume.pendingActionStarted !== true && !(resumeDecisionWasNegative(resume) && resume.decisionDelivered === true);
19
- let reopenCommitted = false;
20
- let reopenStateUnknown = false;
21
21
  let unstartedRow;
22
22
  if (reopenable && resume !== undefined) {
23
23
  const row = await compensateUnstarted(resume.reopenUnstarted, reopenReason, resume.claimedRowPending);
24
24
  unstartedRow = row.kind;
25
25
  if (row.kind === "reopened") {
26
- reopenCommitted = true;
27
26
  message = `${message} — ${unstartedRowSentence(row, resume.cp, failure)}`;
28
27
  }
29
28
  else {
30
- parentConstraintRegistry.delete(resume.cp.token);
31
29
  const original = asThrownError(err);
32
- reopenStateUnknown = row.kind === "unknown";
33
- err = Object.assign(new Error(`${original.message} — ${unstartedRowSentence(row, resume.cp)}`, { cause: original }), { code: "checkpoint.reopen_failed" });
30
+ err = Object.assign(new Error(`${original.message} — ${unstartedRowSentence(row, resume.cp, failure)}`, { cause: original }), { code: "checkpoint.reopen_failed" });
34
31
  const replacement = thrownFailureOf(err, thrownText(err));
35
32
  code = replacement.code;
36
33
  message = replacement.message;
@@ -39,16 +36,17 @@ export function streamSettleBackstop(input) {
39
36
  }
40
37
  if (resume && live.resultValue === undefined)
41
38
  locallyClaimedTokens.close(resume.cp.token);
42
- if (resume && !reopenCommitted && live.resultValue === undefined) {
39
+ const legEnv = taskIdRef.legEnvForRow;
40
+ taskIdRef.legEnvForRow = undefined;
41
+ if (resume && !rowKeepsWhatItsRetryNeeds(unstartedRow) && live.resultValue === undefined) {
43
42
  parentConstraintRegistry.delete(resume.cp.token);
44
43
  await settleTeardownLeg(() => sessions.unpin?.(resume.cp.sessionId), "sessions.unpin (resume-failure leg)", (e) => runner.deps.onError?.(e, { phase: "config", sessionId: resume.cp.sessionId }));
45
- if (!reopenStateUnknown) {
46
- const failedReap = suspendedEnvReaps.get(resume.cp.token);
47
- suspendedEnvReaps.delete(resume.cp.token);
48
- if (failedReap?.env !== undefined && hasDestroy(failedReap.env)) {
49
- const failedEnv = failedReap.env;
50
- await settleTeardownLeg(() => failedEnv.destroy(), "terminal resume-failure env destroy", (e) => runner.deps.onError?.(e, { phase: "config", sessionId: resume.cp.sessionId }));
51
- }
44
+ const failedReap = suspendedEnvReaps.get(resume.cp.token);
45
+ suspendedEnvReaps.delete(resume.cp.token);
46
+ for (const env of new Set([failedReap?.env, legEnv])) {
47
+ if (env === undefined || !hasDestroy(env))
48
+ continue;
49
+ await settleTeardownLeg(() => env.destroy(), "terminal resume-failure env destroy", (e) => runner.deps.onError?.(e, { phase: "config", sessionId: resume.cp.sessionId }));
52
50
  }
53
51
  }
54
52
  if (live.resultValue !== undefined) {
@@ -71,11 +69,11 @@ export function streamSettleBackstop(input) {
71
69
  }
72
70
  return undefined;
73
71
  })();
74
- live.resultValue = {
72
+ live.resultValue = withRewindOutcome({
75
73
  taskId: taskIdRef.current ?? "unknown",
76
74
  sessionId: taskIdRef.rowVerified === false ? "" : taskIdRef.sessionId ?? "unknown",
77
75
  ...(taskIdRef.runId !== undefined ? { runId: taskIdRef.runId } : {}),
78
- terminal: { kind: "failed", ...(code !== undefined ? { code } : {}), message, ...(detail !== undefined ? { detail } : {}), ...(unstartedRow !== undefined ? { unstartedRow } : {}), ...(unstartedRow === "reopened" ? { resumeAgainMayCure: resumeAgainMayCure(failure.cause) } : {}) },
76
+ terminal: { kind: "failed", ...(code !== undefined ? { code } : {}), message, ...(detail !== undefined ? { detail } : {}), ...(unstartedRow !== undefined ? { unstartedRow } : {}), ...(unstartedRow === "reopened" && resumeAgainMayCure(failure.cause) !== undefined ? { resumeAgainMayCure: resumeAgainMayCure(failure.cause) } : {}) },
79
77
  result: "", resultEntryIds: [],
80
78
  ...(taskIdRef.intake !== undefined ? { intake: taskIdRef.intake } : {}),
81
79
  ...(taskIdRef.writesAtClose !== undefined ? { continuesFrom: unsettledLegContinuesFrom(taskIdRef.writesAtClose) } : {}),
@@ -87,6 +85,7 @@ export function streamSettleBackstop(input) {
87
85
  return observed !== undefined && observed.length > 0 ? { editedFiles: observed } : {};
88
86
  })(),
89
87
  ...(taskIdRef.readFloorUnkept?.current === true ? { readDenyFloor: { kept: false } } : {}),
88
+ ...resultPostureSeats(taskIdRef.posture),
90
89
  ...(() => {
91
90
  const hinted = readMember(err, "retryAfterMs");
92
91
  return code === "memory.admission_required" && typeof hinted === "number" && Number.isFinite(hinted) && hinted > 0
@@ -94,7 +93,7 @@ export function streamSettleBackstop(input) {
94
93
  : {};
95
94
  })(),
96
95
  stats: { turns: 0, tokens: 0, toolCalls: 0, cachedTokens: 0, costMicroUsd: 0, usageMissing: true },
97
- };
96
+ }, taskIdRef.rewind);
98
97
  emitTrace(entryTracer.tracer, () => ({
99
98
  kind: "task.end",
100
99
  version: 1,
@@ -157,7 +157,7 @@ function pairedNameOf(value, keys, read) {
157
157
  }
158
158
  return named;
159
159
  }
160
- function recordOf(value, depth, budget, reserved) {
160
+ function recordOf(value, depth, budget, reserved, cutKeys) {
161
161
  let keys;
162
162
  try {
163
163
  keys = Object.keys(value).filter((k) => k !== reserved);
@@ -165,8 +165,10 @@ function recordOf(value, depth, budget, reserved) {
165
165
  catch {
166
166
  return undefined;
167
167
  }
168
+ const nameable = (key) => isProviderEchoShape(key) && !carriesCredential(key);
168
169
  if (keys.length > CODED_DETAIL_ENTRIES) {
169
170
  budget.cuts++;
171
+ cutKeys?.push(...keys.filter(nameable));
170
172
  return undefined;
171
173
  }
172
174
  if ((keys.length > 0 && keys.every((k) => INDEX_KEY_RE.test(k))) || !charge(budget, 0))
@@ -175,10 +177,12 @@ function recordOf(value, depth, budget, reserved) {
175
177
  const paired = pairedNameOf(value, keys, nameMembers);
176
178
  const out = {};
177
179
  for (const key of keys) {
178
- if (!isProviderEchoShape(key) || carriesCredential(key))
180
+ if (!nameable(key))
179
181
  continue;
182
+ const cutsBefore = budget.cuts;
180
183
  if (budget.chars + key.length > CODED_DETAIL_CHARS) {
181
184
  budget.cuts++;
185
+ cutKeys?.push(key);
182
186
  continue;
183
187
  }
184
188
  const charsBefore = budget.chars;
@@ -189,6 +193,8 @@ function recordOf(value, depth, budget, reserved) {
189
193
  budget.chars = charsBefore;
190
194
  else
191
195
  Object.defineProperty(out, key, { value: admitted, enumerable: true, writable: true, configurable: true });
196
+ if (budget.cuts > cutsBefore)
197
+ cutKeys?.push(key);
192
198
  }
193
199
  return Object.keys(out).length > 0 ? out : undefined;
194
200
  }
@@ -196,20 +202,23 @@ const INPUT_MEMBER = "input";
196
202
  function detailRecordOf(detail, reserved) {
197
203
  try {
198
204
  if (detail === null || typeof detail !== "object" || Array.isArray(detail) || ArrayBuffer.isView(detail))
199
- return undefined;
205
+ return { detail: undefined, omitted: [] };
200
206
  }
201
207
  catch {
202
- return undefined;
208
+ return { detail: undefined, omitted: [] };
203
209
  }
204
- return recordOf(detail, 0, { values: 0, chars: 0, cuts: 0 }, reserved);
210
+ const omitted = [];
211
+ return { detail: recordOf(detail, 0, { values: 0, chars: 0, cuts: 0 }, reserved, omitted), omitted };
205
212
  }
206
213
  function codedFailureDetailOf(code, link) {
207
214
  const family = isConfigRefusalCode(code);
208
215
  const input = family ? configInputOfRefusal(link) : undefined;
209
- const detail = detailRecordOf(readMember(link, "detail"), family ? INPUT_MEMBER : undefined);
216
+ const { detail, omitted: cutNames } = detailRecordOf(readMember(link, "detail"), family ? INPUT_MEMBER : undefined);
217
+ const omitted = cutNames.slice(0, CODED_DETAIL_ENTRIES);
218
+ const cut = omitted.length > 0 ? { omitted, ...(cutNames.length > omitted.length ? { omittedMore: cutNames.length - omitted.length } : {}) } : {};
210
219
  if (input === undefined)
211
- return detail === undefined ? undefined : { kind: "coded", detail };
212
- return { kind: "coded", detail: { [INPUT_MEMBER]: input, ...detail } };
220
+ return detail === undefined && omitted.length === 0 ? undefined : { kind: "coded", detail: detail ?? {}, ...cut };
221
+ return { kind: "coded", detail: { [INPUT_MEMBER]: input, ...detail }, ...cut };
213
222
  }
214
223
  export function errorCodeOf(err) {
215
224
  return codedLinkOf(err)?.code;
@@ -20,6 +20,7 @@ export declare function terminalProjection(terminal: TerminalCause): {
20
20
  * be reopened) amends the CAUSE — the one record there is. The code fills only an empty seat (the leg's
21
21
  * own terminal code, when it had one, still names the ending); the message is extended, not replaced;
22
22
  * the row's outcome is stated on its own member (`unstartedRow`), whatever the code says, and — on a row that is pending again — whether
23
- * the same decision resumed again can succeed (`resumeAgainMayCure`, the failure's cause read by the one table).
23
+ * the same decision resumed again can succeed (`resumeAgainMayCure`, the failure's cause read by the one table; absent when the table
24
+ * has no answer: the row is not this run's).
24
25
  */
25
- export declare function amendTerminal(result: TaskResult, code: string, unstartedRow: UnstartedRowOutcome, message: (prior: string | undefined) => string, resumeAgainMayCure: boolean): void;
26
+ export declare function amendTerminal(result: TaskResult, code: string, unstartedRow: UnstartedRowOutcome, message: (prior: string | undefined) => string, resumeAgainMayCure: boolean | undefined): void;
@@ -24,5 +24,5 @@ export function amendTerminal(result, code, unstartedRow, message, resumeAgainMa
24
24
  const t = result.terminal;
25
25
  if (t.kind !== "failed")
26
26
  return;
27
- result.terminal = { ...t, code: t.code ?? code, message: message(t.message), unstartedRow, ...(unstartedRow === "reopened" ? { resumeAgainMayCure } : {}) };
27
+ result.terminal = { ...t, code: t.code ?? code, message: message(t.message), unstartedRow, ...(unstartedRow === "reopened" && resumeAgainMayCure !== undefined ? { resumeAgainMayCure } : {}) };
28
28
  }