@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
@@ -1,7 +1,7 @@
1
1
  import { DENIED_BY_MAY_ECHO, modeReleaseOf, readDenyTableOf, screenGateOutcome, SETTLEMENT_IS_REFUSAL } from "../gate-outcome.js";
2
2
  import { traceHookCrash } from "../gate-crash-trace.js";
3
3
  import { thrownText } from "../thrown-value.js";
4
- import { ASK_CLASSES, askFaceOf, classifyAsk, headlessApprovalRemedy, NOBODY_CAN_APPROVE, unresolvedAskDenialMessage, unresolvedAskQuestionOf } from "../ask-origin.js";
4
+ import { ASK_CLASSES, askFaceOf, classifyAsk, headlessApprovalRemedy, withParkRemedy, NOBODY_CAN_APPROVE, unresolvedAskDenialMessage } from "../ask-origin.js";
5
5
  import { NOT_RESUMABLE_CARRY_ON, notResumableWayOut } from "../park-resumability.js";
6
6
  import { wireOf } from "../tool-name-readings.js";
7
7
  import { isProtectedWrite } from "../tool-registry.js";
@@ -12,7 +12,7 @@ import { argsAsTheToolReads } from "../effective-path-target.js";
12
12
  import { rewriteRecordOf } from "../rewrite-rejudge.js";
13
13
  import { askUnresolvableRemedySeat } from "../ask-unresolvable-notice.js";
14
14
  import { foreignLine } from "../protocol-http-auth.js";
15
- import { CONTENT_ASK_NOT_SHOWN, contentAskNotShownMessage } from "../ask-question.js";
15
+ import { isSuspendLaneReason } from "../suspend-lane-reasons.js";
16
16
  import { unavailableLandingOf } from "../unavailable-landing.js";
17
17
  import { notRecordedMark } from "../redaction-marks.js";
18
18
  import { formatHookFeedback } from "../reminder-mint.js";
@@ -273,6 +273,7 @@ function memberAt(value, path) {
273
273
  return at;
274
274
  }
275
275
  const PARK_FAILURE_CAUSE_MAX = 600;
276
+ const suspendLaneReasonOf = (v) => (isSuspendLaneReason(v) ? v : undefined);
276
277
  function withParkFailureCause(reason, park, nobodyJudged) {
277
278
  if (park === undefined)
278
279
  return reason;
@@ -291,15 +292,10 @@ function wayOnOf(row) {
291
292
  return undefined;
292
293
  return row.nobodyRemedy !== undefined ? row.nobodyRemedy() : row.wayOut !== undefined ? NOBODY_CAN_APPROVE : undefined;
293
294
  }
294
- function parkFailedBase(text, toolName, cause, park) {
295
- if (park === undefined)
296
- return text;
297
- if (park.kind === "no_target" && text.startsWith(CONTENT_ASK_NOT_SHOWN))
298
- return `${contentAskNotShownMessage(true)}${text.slice(CONTENT_ASK_NOT_SHOWN.length)}`;
299
- if (cause !== "no_approver_wired" && cause !== "approver_unavailable")
295
+ export function parkFailedBase(text, minted, park) {
296
+ if (park === undefined || minted === undefined || !text.startsWith(minted.text))
300
297
  return text;
301
- const question = unresolvedAskQuestionOf(cause, toolName, text);
302
- return question === undefined ? text : unresolvedAskDenialMessage(cause, toolName, question, true);
298
+ return `${unresolvedAskDenialMessage(minted.cause, minted.question, true)}${text.slice(minted.text.length)}`;
303
299
  }
304
300
  export function takeInheritedScreen(pass, read) {
305
301
  if (read?.floated !== undefined)
@@ -400,17 +396,19 @@ export async function exitGate(pass) {
400
396
  const nobodyMayAnswer = input.askSeatForm !== undefined && input.askSeatForm !== "callback" && !parkCanWait && pass.askClassification?.classes.has("content_question") !== true;
401
397
  const remedyOf = (approverSeat) => headlessApprovalRemedy({ mode: input.permissionMode?.(), classification: foldCause !== undefined ? ancestorUnresolvedClassification(pass.req) : pass.askClassification, approverSeat, coveredWrite: isProtectedWrite(pass.req), ...(pass.shellUnplacedOptions !== undefined ? { unplacedOptions: pass.shellUnplacedOptions } : {}), ...(wayOut !== undefined ? { notResumableWayOut: wayOut } : {}) });
402
398
  const headless = bindingRefusal !== undefined || remedySeat === undefined ? undefined : remedyOf(remedySeat);
403
- const remedy = headless?.sentence;
404
- const parkNote = pass.parkFailed !== undefined ? { kind: "failed", cause: pass.parkFailed } : unresolvable !== undefined && pass.parkTargetGap !== undefined ? { kind: "no_target", gap: pass.parkTargetGap } : undefined;
399
+ const parkNote = pass.parkFailed !== undefined ? ((r) => ({ kind: "failed", cause: pass.parkFailed, ...(r !== undefined ? { reason: r } : {}) }))(suspendLaneReasonOf(pass.parkFailedReason)) : unresolvable !== undefined && pass.parkTargetGap !== undefined ? { kind: "no_target", gap: pass.parkTargetGap } : undefined;
400
+ const parkFailedSaid = parkNote?.kind === "failed" && headless !== undefined ? foreignLine(parkNote.cause, PARK_FAILURE_CAUSE_MAX) : "";
401
+ const hostWay = headless !== undefined && parkFailedSaid !== "" ? withParkRemedy(headless, parkFailedSaid) : headless;
402
+ const remedy = hostWay?.sentence;
405
403
  const question = pass.askClassification?.classes.has("content_question") === true;
406
404
  const modelWayOut = wayOnOf({ nobodyJudged: unresolvable !== undefined, question, unbindable: bindingRefusal !== undefined, legHoldsNoPark: !floated && parkNote?.kind === "no_target", seatReAsked: input.askSeatForm === undefined || input.askSeatForm === "callback" || input.askSeatForm === "policy_callback", nobodyMayAnswer, nobodyRemedy: remedy !== undefined ? () => remedyOf("nobody").sentence : undefined, wayOut });
407
- const base = parkFailedBase(decisionText(pass.decision) ?? `tool "${toolName}" denied by policy`, toolName, unresolvable, parkNote);
405
+ const base = parkFailedBase(decisionText(pass.decision) ?? `tool "${toolName}" denied by policy`, attestationOf(pass.decision, { toolCallId, toolName })?.unanswered, parkNote);
408
406
  const tail = question ? "" : remedy !== undefined || (modelWayOut !== undefined && wayOut === undefined) ? ` — ${modelWayOut ?? remedy}` : unresolvable !== undefined && wayOut !== undefined && bindingRefusal === undefined ? (modelWayOut !== undefined ? `. To go on: ${modelWayOut}.` : `. To go on: ${wayOut}. ${NOT_RESUMABLE_CARRY_ON}`) : "";
409
407
  const denyReason = withParkFailureCause(`${tail.startsWith(".") ? base.replace(/\.$/, "") : base}${tail}`, parkNote, unresolvable !== undefined && !question);
410
408
  if (unresolvable !== undefined) {
411
409
  const cause = unresolvable;
412
410
  const noticeRemedy = bindingRefusal ?? remedy;
413
- pass.notifier.notify(() => input.onAskUnresolvable?.({ toolName, toolCallId, cause, parkLaneExisted: pass.suspendAsk !== undefined, ...(parkNote?.kind === "no_target" ? { parkTargetGap: parkNote.gap } : {}), ...(noticeRemedy !== undefined ? { remedy: noticeRemedy } : {}), ...(modelWayOut !== undefined ? { modelRemedy: modelWayOut } : {}), ...(headless !== undefined ? { remedies: headless.remedies } : {}), ...(wayOut !== undefined && input.notResumable !== undefined ? { notResumableWayOut: wayOut, notResumableSource: input.notResumable.source } : {}), ...(question ? { question: true } : {}), ...(bindingRefusal !== undefined ? { unbindable: true } : {}) }), "toolGate.onAskUnresolvable");
411
+ pass.notifier.notify(() => input.onAskUnresolvable?.({ toolName, toolCallId, cause, parkLaneExisted: pass.suspendAsk !== undefined, ...(parkNote?.kind === "no_target" ? { parkTargetGap: parkNote.gap } : {}), ...(parkFailedSaid !== "" ? { parkFailed: parkFailedSaid, ...(parkNote?.kind === "failed" && parkNote.reason !== undefined ? { parkFailedReason: parkNote.reason } : {}) } : {}), ...(noticeRemedy !== undefined ? { remedy: noticeRemedy } : {}), ...(modelWayOut !== undefined ? { modelRemedy: modelWayOut } : {}), ...(hostWay !== undefined ? { remedies: hostWay.remedies } : {}), ...(wayOut !== undefined && input.notResumable !== undefined ? { notResumableWayOut: wayOut, notResumableSource: input.notResumable.source } : {}), ...(question ? { question: true } : {}), ...(bindingRefusal !== undefined ? { unbindable: true } : {}) }), "toolGate.onAskUnresolvable");
414
412
  }
415
413
  const finalInput = frozenInputSnapshot(pass.currentInput);
416
414
  await notifyPermissionDenied(permissionDeniedOf({ toolName, finalInput, toolCallId, reason: denyReason, gate, identity: input.identity }));
@@ -1,4 +1,4 @@
1
- import { isFrontmatterFence } from "../frontmatter-fence.js";
1
+ import { isFrontmatterFence } from "@sema-agent/primitives";
2
2
  import { sliceHeadSafe } from "../surrogate-safe-slice.js";
3
3
  import { compileGlobToken } from "../../tools/fs/search.js";
4
4
  export const INSTRUCTION_FILE_MIN_CHARS = 40_000;
@@ -3,7 +3,7 @@ import type { ModelFileReader } from "../../tools/fs/fs-read.js";
3
3
  import { type ReadFileState } from "../../tools/fs/safety.js";
4
4
  import type { SyntheticServedReadJudge } from "../synthetic-read-verdict.js";
5
5
  import type { ToolCallFace } from "../tool-policy.js";
6
- import { type InstructionLayer, type MintedAttachmentFrame } from "../user-attachment.js";
6
+ import { type FrameFileTools, type InstructionLayer, type MintedAttachmentFrame } from "../user-attachment.js";
7
7
  import type { ReminderDisclosureCounts } from "../reminder-disclosure.js";
8
8
  import type { TaskSpec } from "../task-spec.js";
9
9
  import type { EngineNotice, RunnerDeps, TaskEvent, TaskEventIdentity } from "../types.js";
@@ -43,6 +43,11 @@ export declare const INSTRUCTIONS_WITHHELD = "instructions.withheld";
43
43
  * no file of the run's (a label for a name, or a run with no files), so it has nowhere to resolve. */
44
44
  export declare const INSTRUCTIONS_WITHHELD_REASONS: readonly ["rule_denied", "outside_roots", "approval_required", "admission_unknown", "target_moved", "outside_its_root", "too_many_texts", "unanchored"];
45
45
  export type InstructionsWithheldReason = (typeof INSTRUCTIONS_WITHHELD_REASONS)[number];
46
+ /** The notice a member the family names was loaded under though it really lies, links followed, outside its root and the task root
47
+ * (a link to a shared file): read as before — the reference reads it too — and said once per session per (path, target), with no
48
+ * contents. A found file outside them is not loaded ({@link INSTRUCTIONS_WITHHELD} `outside_its_root`); one the read roots or a rule
49
+ * refuses is withheld whatever the name. */
50
+ export declare const INSTRUCTIONS_OUTSIDE_ROOT = "instructions.outside_root";
46
51
  /** The notice a run prepared with no instruction family declared is the first, for its notice receiver, to say. */
47
52
  export declare const INSTRUCTIONS_FAMILY_UNDECLARED = "instructions.family_undeclared";
48
53
  /** The operator's sentence for that absence: what no run reads, and the one thing that makes them read it. */
@@ -122,7 +127,7 @@ export declare function instructionFamilyOf(spec: Pick<TaskSpec, "instructionFam
122
127
  export declare function screenNestedMemory(spec: Pick<TaskSpec, "instructionFamily"> | unknown, projectMemory: TaskSpec["projectMemory"] | unknown): ScreenedNestedMemory | undefined;
123
128
  /** What the lane reads with: the hands' environment and reader, the run's served-read judge (every ask held: nobody asked
124
129
  * for this file, so it is shown only where the model's own `Read` of it would be served with nobody asked) and the face
125
- * the run's roster gives `Read` (read at each judgment; none ⇒ the model could not read the file itself), the live read
130
+ * the run's roster gives `Read` (read at each judgment; none ⇒ the probe carries no face — never a reason to withhold), the live read
126
131
  * state, the canonical task root and the additional working directories the request declared (each its declared spelling
127
132
  * and the one canonical form the hands resolved it to, in declaration order; read as roots only under the declaration's
128
133
  * opt-in); the prepared leg (read at each load) for the model and the records. A leg with no hands seats the lane without
@@ -146,6 +151,9 @@ interface LaneSeatCommon {
146
151
  readonly counts: ReminderDisclosureCounts | undefined;
147
152
  readonly deps: Pick<RunnerDeps, "onNotice" | "onError">;
148
153
  readonly leg: () => Pick<Prepared, "harness" | "session" | "sessionId" | "runId" | "announcedListingsRef" | "frameReceipts" | "hookIdentity"> | undefined;
154
+ /** The file tools the run's roster mounts, read at each mint — what a frame's sentence (a cut file's way to the rest) may send the
155
+ * model to; absent outside a Runner: every one taken as mounted. */
156
+ readonly fileTools?: () => FrameFileTools;
149
157
  }
150
158
  /** An additional working directory as the request declared it (`TaskSpec.additionalDirectories`, the spelling) and as the
151
159
  * hands resolved it (the canonical form the file tools' fence holds). */
@@ -28,6 +28,7 @@ export const NESTED_MEMORY_STAT_BATCH = 8;
28
28
  export const NESTED_MEMORY_PROBE_FACE = "nested-memory";
29
29
  export const INSTRUCTIONS_WITHHELD = "instructions.withheld";
30
30
  export const INSTRUCTIONS_WITHHELD_REASONS = Object.freeze(["rule_denied", "outside_roots", "approval_required", "admission_unknown", "target_moved", "outside_its_root", "too_many_texts", "unanchored"]);
31
+ export const INSTRUCTIONS_OUTSIDE_ROOT = "instructions.outside_root";
31
32
  export const INSTRUCTIONS_FAMILY_UNDECLARED = "instructions.family_undeclared";
32
33
  export function instructionsFamilyUndeclaredNotice(sessionId) {
33
34
  return {
@@ -341,6 +342,26 @@ export function createNestedMemoryLane(seat) {
341
342
  const rel = relOf(key);
342
343
  return at === "any" && rel !== undefined && rel !== "" && levelsOf(rel).some((level) => memberAt(rel, level, declaredNamesOf(0), declaredRulesOf(0)) !== undefined);
343
344
  };
345
+ const tellLoadedOutside = (path, target) => {
346
+ const leg = seat.leg();
347
+ if (leg === undefined)
348
+ return;
349
+ const d = announceDigest(INSTRUCTIONS_OUTSIDE_ROOT, JSON.stringify([path, target]));
350
+ if ((leg.announcedListingsRef.advisories ?? []).includes(d))
351
+ return;
352
+ leg.announcedListingsRef.advisories = withAnnounceDigests(leg.announcedListingsRef.advisories, [d]);
353
+ leg.frameReceipts.listingSnapshotOwed = true;
354
+ if (agentIdOf(leg.hookIdentity) !== undefined)
355
+ return;
356
+ const r = rootLevelOf(path);
357
+ const what = r === 0 ? "An instruction file of the task root" : r > 0 ? "An instruction file of an additional working directory" : "An instruction file of a directory the model accessed";
358
+ const from = r > 0 ? "that directory and the task root" : "the task root";
359
+ deliverEngineNotice(seat.deps.onNotice, {
360
+ code: INSTRUCTIONS_OUTSIDE_ROOT,
361
+ message: `${what} was loaded from outside ${from}: ${path} leads to ${target}. If that is not meant, replace it with a file inside ${from}, or turn the project's instruction files off for the request.`,
362
+ detail: { path, target, sessionId: leg.sessionId, runId: leg.runId },
363
+ });
364
+ };
344
365
  const levelItems = (r, level) => {
345
366
  const items = [];
346
367
  const add = (i) => {
@@ -597,15 +618,11 @@ export function createNestedMemoryLane(seat) {
597
618
  visited.add(key);
598
619
  return includesAt(includesBy.get(key) ?? [], item, key);
599
620
  }
600
- const face = hands.readFace();
601
- if (face === undefined) {
602
- withheld(item, "admission_unknown");
603
- return [];
604
- }
605
621
  p.count++;
622
+ const face = hands.readFace();
606
623
  const held = await hands.reader.openBound(key, seat.signal);
607
624
  try {
608
- const verdict = await hands.judge({ file_path: item.path, face }, NESTED_MEMORY_PROBE_FACE, { deadlineAt });
625
+ const verdict = await hands.judge({ file_path: item.path, ...(face !== undefined ? { face } : {}) }, NESTED_MEMORY_PROBE_FACE, { deadlineAt });
609
626
  if (verdict.verdict !== "no_objection") {
610
627
  withheld(item, verdict.verdict === "deny" ? "rule_denied" : verdict.verdict === "ask" ? "approval_required" : "admission_unknown");
611
628
  return [];
@@ -660,6 +677,7 @@ export function createNestedMemoryLane(seat) {
660
677
  const recorded = { hash, totalLines, truncated: !whole, ...(whole ? { view: { start: 1, end: totalLines } } : { isPartialView: true }) };
661
678
  inFlight.add(key);
662
679
  const layer = layerOf(item.level);
680
+ const outsideItsRoots = !foundByLane(item) && !insideItsRoots(item.root, key);
663
681
  const read = {
664
682
  supply: "path",
665
683
  owner: item.owner ?? "repository",
@@ -674,6 +692,8 @@ export function createNestedMemoryLane(seat) {
674
692
  seen?.set(key, entryId(landed));
675
693
  inFlight.delete(key);
676
694
  echo.fn?.(key, layer, false);
695
+ if (outsideItsRoots)
696
+ tellLoadedOutside(item.path, key);
677
697
  },
678
698
  };
679
699
  reads.push({ read, item, key });
@@ -817,7 +837,8 @@ export function createNestedMemoryLane(seat) {
817
837
  const model = leg.harness.getModel();
818
838
  const budget = NESTED_MEMORY_FRAME_BUDGET_FILES * instructionFileCap(model.contextWindow, model.charsPerToken ?? 4);
819
839
  const taken = [...reads];
820
- const disclosure = { reader: hands?.reader, mark: seat.mark, counts: seat.counts };
840
+ const fileTools = seat.fileTools?.();
841
+ const disclosure = { reader: hands?.reader, mark: seat.mark, counts: seat.counts, ...(fileTools !== undefined ? { fileTools } : {}) };
821
842
  let minted = mintInstructionFrames(taken.map((r) => r.read), disclosure);
822
843
  const sizeOf = (frames) => frames.reduce((n, f) => n + f.seed.content.reduce((m, b) => m + (b.type === "text" ? b.text.length : 0), 0), 0);
823
844
  while (taken.length > 1 && sizeOf(minted.frames) > budget) {
@@ -952,7 +973,7 @@ const WITHHELD_WAY_OUT = {
952
973
  rule_denied: "Remove the read rule that refuses it (a built-in credential row can be removed only by the deployment), or move the file to a path no rule refuses.",
953
974
  outside_roots: "Point the link back inside those directories or make it a real file there, or add the directory it leads to among the session's additional directories.",
954
975
  approval_required: "Remove the ask rule or policy (yours, the deployment's or the organization's) that makes reading it ask; an allow rule does not override an ask.",
955
- admission_unknown: "Check that the run has the Read tool and, for a `~/` include, that the deployment declares a home directory; a check that could not answer is retried the next time instruction files are loaded.",
976
+ admission_unknown: "A check that could not answer is retried the next time instruction files are loaded; for a `~/` include, the deployment must declare a home directory.",
956
977
  target_moved: "Nothing to change: it is checked again the next time instruction files are loaded.",
957
978
  outside_its_root: "A file the lane found outside that root and the task root is loaded only when this project approves instruction files outside it (an approval applies from the next run); otherwise put the file inside one of them or point the link at one — adding directories or rules does not change this.",
958
979
  too_many_texts: "Merge the texts, or leave out the ones not needed, so that what matters is among the first.",
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A resume's money-ceiling door: the run's OWN money ceiling over the model it runs on that the ceiling cannot count — the refusal the
3
+ * start's doors give ({@link unpricedModelRefusal}), asked of the config a resume is handed, so `Runner.judgeResumeConfig` and the
4
+ * resume's pre-claim ladder say what prepare would say after the claim (the row staying pending).
5
+ *
6
+ * The model is read the way prepare reads it (`resolveRunModel` over the role maps' receipts: `deps` with the deployment's, `taskRoles`
7
+ * the task's). `priorLedger` is the resumed row's ledger (what its chain has left of a total); none ⇒ the config's own ceiling.
8
+ * A model that does not resolve — or a price table that cannot be read — is prepare's refusal to give, after the claim and in its own
9
+ * words, not this door's: nothing is asked of it here.
10
+ */
11
+ import type { ResourceLedger } from "../checkpoint-store.js";
12
+ import type { RunnerDeps, TaskSpec } from "../types.js";
13
+ export declare function refuseUncountedOwnModel(config: Pick<TaskSpec, "limits" | "resourceSuspend" | "model" | "modelRole" | "roles" | "thinking">, deps: RunnerDeps, taskRoles: TaskSpec["roles"], priorLedger: ResourceLedger | undefined): void;
@@ -0,0 +1,17 @@
1
+ import { resolveRunModel } from "./seat-model-doors.js";
2
+ import { ownMoneyCeiling, unpricedModelRefusal } from "./side-call-account.js";
3
+ export function refuseUncountedOwnModel(config, deps, taskRoles, priorLedger) {
4
+ const held = ownMoneyCeiling(config, priorLedger);
5
+ if (held === undefined)
6
+ return;
7
+ let refusal;
8
+ try {
9
+ const resolved = resolveRunModel(taskRoles !== undefined ? { ...config, roles: taskRoles } : config, deps);
10
+ refusal = unpricedModelRefusal(held, resolved.model, deps.pricing, resolved.modelInput);
11
+ }
12
+ catch {
13
+ return;
14
+ }
15
+ if (refusal !== undefined)
16
+ throw refusal;
17
+ }
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import type { Checkpoint, CheckpointGate, CheckpointToken } from "../checkpoint-store.js";
10
10
  import type { WorkspaceHandle } from "../remote-env.js";
11
- import type { Prepared } from "./contracts.js";
11
+ import type { ParkWrites, Prepared } from "./contracts.js";
12
12
  /** Default resource-checkpoint retention (30 days, the spec's
13
13
  * `RESOURCE_SUSPEND_TTL_SEC`). Stamped onto the checkpoint `deadline` so the durable reaper can GC an
14
14
  * ORPHANED resource suspend; a legitimate auto-resume fires long before this. Override via
@@ -127,4 +127,6 @@ export declare function heldCallResultOf(refs: Pick<Prepared, "pausedRef">, tool
127
127
  export declare function publishCommittedSuspend(refs: Pick<Prepared, "pausedRef">, token: CheckpointToken, gate: CheckpointGate, scope: string, remoteHandle: WorkspaceHandle | undefined,
128
128
  /** The COMMITTED row — passed whole, not as pre-extracted members, so no call site can hand this seam an id or a fact
129
129
  * the committed row does not actually carry. */
130
- row: Pick<Checkpoint, "checkpointId" | "pendingAction" | "state">): void;
130
+ row: Pick<Checkpoint, "checkpointId" | "pendingAction" | "state">,
131
+ /** What the saga's committed answer says the put carried — passed as the saga answered it (see {@link CommittedPause.writes}). */
132
+ writes: ParkWrites): void;
@@ -32,7 +32,7 @@ export function heldCallResultOf(refs, toolCallId) {
32
32
  const text = card.kind === "card" && card.card === "question" ? HELD_CALL_TEXT.question : HELD_CALL_TEXT.approval;
33
33
  return { content: [{ type: "text", text }], details: { code: "gate.parked", gatedCallId: toolCallId } };
34
34
  }
35
- export function publishCommittedSuspend(refs, token, gate, scope, remoteHandle, row) {
35
+ export function publishCommittedSuspend(refs, token, gate, scope, remoteHandle, row, writes) {
36
36
  const { pendingAction } = row;
37
37
  const pause = {
38
38
  cause: {
@@ -45,6 +45,7 @@ export function publishCommittedSuspend(refs, token, gate, scope, remoteHandle,
45
45
  },
46
46
  scope,
47
47
  ...(pendingAction.kind === "tool_approval" ? { gatedCallId: pendingAction.toolCallId } : {}),
48
+ writes,
48
49
  };
49
50
  refs.pausedRef.current = pause;
50
51
  }
@@ -34,6 +34,7 @@ import { type EffectivePermissionRules, type PermissionRuleStoreProvider, type P
34
34
  import { type AutoStripReason } from "../auto-strip.js";
35
35
  import { type MountedPeersSeat } from "../a2a-bound-grant.js";
36
36
  import { type PersistedRuleBuckets } from "../persisted-rule-buckets.js";
37
+ import { type CallGrantBinding } from "../session-call-grant.js";
37
38
  /**
38
39
  * The evidence an INHERITED-lane ask carries.
39
40
  *
@@ -196,6 +197,9 @@ export declare function createPermissionRuleLanes(cfg: {
196
197
  * (its scope covers this leg) and whose text reads as an allow rule (one that does not grants nothing in any mode). Absent ⇒
197
198
  * nobody is told (a judgment that is not the gate's: the consolidation judge, a synthetic read, a resumed call's belt). */
198
199
  onAutoStripped?: (rule: PersistedRule, reason: AutoStripReason, req: ToolCallRequest) => void;
200
+ /** The session call grants' one judgment, over the run's execution environment: does a stored binding admit this shell
201
+ * command now ({@link callGrantAdmits})? Absent ⇒ no call grant row admits anything (the leg has no environment to read). */
202
+ callGrantAdmits?: (binding: CallGrantBinding, command: string, signal?: AbortSignal) => Promise<boolean>;
199
203
  }): PermissionRuleLanes;
200
204
  /** The surviving-ask facts the rule-offer factory reads (see {@link createRuleOffersOf}): the
201
205
  * synchronous mint sites spread the surviving decision, which carries them; the park leg threads
@@ -18,6 +18,7 @@ import { strongestAnswer } from "../persisted-rule-arms.js";
18
18
  import { ORG_ADJUDICATION_TIMEOUT_MS } from "../permission-rule-org.js";
19
19
  import { insidePeerOfferOf } from "../a2a-bound-grant.js";
20
20
  import { refuseUnreadAncestorBuckets } from "../persisted-rule-buckets.js";
21
+ import { callGrantRowAdmitting } from "../session-call-grant.js";
21
22
  const NO_LEADS = new Map();
22
23
  export function inheritedAskRuleEvidence(provider) {
23
24
  const org = provider?.partitions.org === true ? "not_adjudicated" : "not_wired";
@@ -173,6 +174,11 @@ export function createPermissionRuleLanes(cfg) {
173
174
  const stands = answer !== undefined && (("behavior" in answer && answer.behavior === "deny") || "unreadable" in answer);
174
175
  if ((view.unreadable !== undefined || unread.length > 0) && !stands)
175
176
  return storeUnreadable(unread, answer !== undefined && "behavior" in answer && answer.behavior === "ask" ? answer : undefined);
177
+ if (answer === undefined || "segmentCoverage" in answer) {
178
+ const granted = await callGrantOf(stripped, req, judged);
179
+ if (granted !== undefined)
180
+ return persistedRuleAnswerOf({ behavior: "allow", rules: [granted] });
181
+ }
176
182
  if (answer === undefined || !("behavior" in answer) || answer.behavior !== "allow")
177
183
  return answer;
178
184
  const bound = table.flatMap((r) => {
@@ -192,6 +198,7 @@ export function createPermissionRuleLanes(cfg) {
192
198
  return { unreadable: true, reason: why };
193
199
  }
194
200
  };
201
+ const callGrantOf = (rows, req, judged) => callGrantRowAdmitting(rows, { words: judged.flatMap(([n, g, grants]) => (grants && g === "command" ? [n] : [])), sessionId: cfg.sessionId, command: req.args?.command, judge: cfg.callGrantAdmits });
195
202
  const unjudgedRowAnswer = (row, refusal, tool) => {
196
203
  const why = `the stored ${row.behavior} rule ${escapeForDisclosure(row.rule)} is no rule this engine reads (${refusal})`;
197
204
  cfg.onDisclosure(`the persisted rule lane could not judge a ${tool} call against the rows it read — ${why}`);
@@ -5,7 +5,7 @@ import { readPrincipal } from "../principal-name.js";
5
5
  import { ORG_ADJUDICATION_TIMEOUT_MS, orgResolutionHeld, orgRowsStandOverFace } from "../permission-rule-org.js";
6
6
  import { canonicalize } from "../canonical-json.js";
7
7
  import { PATH_RULE_FACES, READ_RULE_TOOL, eligiblePersisted, noticeRuleText, ruleToolGrammarOf } from "../permission-rule-model.js";
8
- import { indexOfUnescaped } from "../permission-rule-syntax.js";
8
+ import { indexOfUnescaped } from "@sema-agent/primitives";
9
9
  import { ROSTERLESS_RETIRED_VIEW, ruleListUnderView } from "../tool-name-aliases.js";
10
10
  import { bindPathRules, persistedRowAnchors, projectScopeIdentity } from "../path-rule-binding.js";
11
11
  import { DEFAULT_GATE_AWAIT_TIMEOUT_MS, gateWaitFailureOf, withGateTimeout } from "../gate-bounded-await.js";
@@ -21,9 +21,15 @@ export declare function mintPlacementFence(row: WorkspaceHandle | undefined, han
21
21
  * device its fence names is refused before anything reports the workspace or runs on it. A leg that restored a
22
22
  * checkpointed workspace (its restore took the receipt already, against the restored handle) is refused
23
23
  * `resume.env_failed` here too — its env may have moved after the restore (re-initialization reconnecting elsewhere) —
24
- * any other leg `config.placement_not_honored`.
24
+ * any other leg `config.placement_not_honored`. `restoredRow` is that leg's row's workspace (absent on every other leg): a
25
+ * refusal whose one reading of the env's device {@link devicesDisprove} the row's is marked `envDisowned` (the env is not the
26
+ * row's workspace, so the leg's exit destroys it at once).
25
27
  */
26
- export declare function settleOwnTarget(env: ExecutionEnv | undefined, fence: PlacementTarget | undefined, restoredCheckpoint: boolean): PlacementTarget | undefined;
28
+ export declare function settleOwnTarget(env: ExecutionEnv | undefined, fence: PlacementTarget | undefined, restoredRow: Pick<WorkspaceHandle, "deviceId"> | undefined): PlacementTarget | undefined;
29
+ /** Whether a device receipt disproves that a resume leg's env stands at its row's workspace: the row and the env each name a
30
+ * device and they differ (an absent one, or the waking leg's, proves nothing). The one reading of both receipts a resume leg
31
+ * meets — the restore's identity check before anything is connected, and the settle point after. */
32
+ export declare function devicesDisprove(rowDevice: string | undefined, envDevice: string | undefined): boolean;
27
33
  /** The codes a device move is refused with: a fresh fenced leg, and a leg that restores or resumes a checkpointed workspace. */
28
34
  export type DeviceMoveRefusalCode = "config.placement_not_honored" | "resume.env_failed";
29
35
  /**
@@ -20,12 +20,17 @@ function handedFence(value) {
20
20
  }
21
21
  return Object.freeze(deviceId !== undefined ? { provider, deviceId } : { provider });
22
22
  }
23
- export function settleOwnTarget(env, fence, restoredCheckpoint) {
23
+ export function settleOwnTarget(env, fence, restoredRow) {
24
24
  const own = reportedPlacementTarget(env);
25
- if (!placementHonored(fence, own))
26
- throw deviceMoveRefusal(restoredCheckpoint ? "resume.env_failed" : "config.placement_not_honored", fence?.deviceId, own?.deviceId);
25
+ if (!placementHonored(fence, own)) {
26
+ const refusal = deviceMoveRefusal(restoredRow !== undefined ? "resume.env_failed" : "config.placement_not_honored", fence?.deviceId, own?.deviceId);
27
+ throw restoredRow !== undefined && devicesDisprove(restoredRow.deviceId, own?.deviceId) ? Object.assign(refusal, { envDisowned: true }) : refusal;
28
+ }
27
29
  return own;
28
30
  }
31
+ export function devicesDisprove(rowDevice, envDevice) {
32
+ return rowDevice !== undefined && envDevice !== undefined && rowDevice !== envDevice;
33
+ }
29
34
  export function deviceMoveRefusal(code, fenceDevice, reportedDevice) {
30
35
  const fenced = fenceDevice !== undefined ? `device "${renderDeviceId(fenceDevice)}"` : "no device";
31
36
  const reports = reportedDevice !== undefined ? `device "${renderDeviceId(reportedDevice)}"` : "no device";
@@ -19,11 +19,12 @@ export declare function policyCheckAbortedDeny(): PermissionResult;
19
19
  /** The deny of a judgment that FAILED (threw or rejected) while `signal` bounded its wait: the aborted deny when the signal had
20
20
  * already ended the wait (a cancellation — not reported), else the policy's own throw — its sentence and one line of what it
21
21
  * threw — reported once through {@link reportPolicyThrow}. A seat that raced the judgment against its signal has told the two
22
- * apart already and passes no signal. */
22
+ * apart already and passes no signal. `said`: the model's sentence of a seat whose failure was no throw (a target reading that moved
23
+ * the call it was handed), which says what failed in its own words; absent, the sentence is the policy's throw. */
23
24
  export declare function failedJudgmentDeny(err: unknown, signal: AbortSignal | undefined, report: (err: Error) => void, seat: string, call: {
24
25
  readonly toolName: string;
25
26
  readonly toolCallId: string;
26
- }): PermissionResult;
27
+ }, said?: string): PermissionResult;
27
28
  /** Hand the deployment, through `report` (the seat's hook-failure lane), the failure of the policy that threw while `seat`
28
29
  * judged `call`. A rejection that arrives with the judgment's `signal` already aborted is the task ending mid-judgment — a
29
30
  * cancellation, not a policy defect — and is not reported (the deny it produced stands either way). A report lane that
@@ -10,11 +10,11 @@ export function policyThrowLine(err) {
10
10
  export function policyCheckAbortedDeny() {
11
11
  return { action: "deny", message: "policy check aborted (task timed out or cancelled)" };
12
12
  }
13
- export function failedJudgmentDeny(err, signal, report, seat, call) {
13
+ export function failedJudgmentDeny(err, signal, report, seat, call, said) {
14
14
  if (signal?.aborted === true)
15
15
  return policyCheckAbortedDeny();
16
16
  reportPolicyThrow(report, seat, call, err);
17
- return { action: "deny", message: `policy check threw — the tool policy chain failed while judging this call (not a timeout or cancellation), so it was denied fail-closed: ${policyThrowLine(err)}` };
17
+ return { action: "deny", message: said ?? `policy check threw — the tool policy chain failed while judging this call (not a timeout or cancellation), so it was denied fail-closed: ${policyThrowLine(err)}` };
18
18
  }
19
19
  export function reportPolicyThrow(report, seat, call, err, signal) {
20
20
  if (signal?.aborted === true)
@@ -13,10 +13,11 @@
13
13
  * audit B-17: release deletes the history on the default store), so a throw here never strands a
14
14
  * cached view and never hands out a half-acquired resource.
15
15
  *
16
- * Throws pass through unchanged: `delegation.owner_mismatch` (the resolved row does not record the tree owner the acquire named — its
17
- * cached view dropped first), `resume.session_not_found` (requireExisting fail-loud mapping),
16
+ * Throws pass through unchanged: `delegation.owner_mismatch` (a leg holding a seat resolved a row that is not its tree's — its cached view
17
+ * dropped first), the session store's fault of that judgement (`config.invalid_session_store` / `storage`), `resume.session_not_found` (requireExisting fail-loud mapping),
18
18
  * the `resume_at.*` target-validation refusals (`judgeRewindTarget`, then the landing's: the window, `refuseOpenToolCallAt`), `corrupt_session`
19
- * for a log that does not hold together (the path reads after the branch), and — after the
19
+ * for a log that does not hold together (the path reads after the branch), `holder.superseded` (a write the store refused for the
20
+ * leg's grant: never re-woken — a superseded leg stops), and — after the
20
21
  * bounded re-wake budget — the session conflict itself. A throw after a `resumeAt` branch landed first writes that branch
21
22
  * back (`settleBranchWriteBack`); on success the branch is handed over with the session.
22
23
  */
@@ -25,9 +26,10 @@ import type { AcquiredSession, SessionStore } from "../session.js";
25
26
  import { type RecoveredOrphan } from "../session-reconcile.js";
26
27
  import type { TaskSpec, ToolEffect } from "../types.js";
27
28
  import type { PrepareResume } from "./contracts.js";
28
- import { type ResumeAtBranch } from "./branch-writeback.js";
29
+ import { type ResumeAtBranch, type WriteRefusal } from "./branch-writeback.js";
29
30
  import { type LegWrites } from "./session-write-ledger.js";
30
31
  import { replayLossLeg } from "./lineage-reroot-view.js";
32
+ import type { RewindOutcome } from "./rewind-outcome.js";
31
33
  export interface PrepareAcquireReconcileInput {
32
34
  /** borrowed-mutable (service port) — the deployment's session store. This phase's verbs on it are
33
35
  * the acquire/forget half of the session resource protocol: `acquire` per attempt, `forget` to
@@ -50,10 +52,12 @@ export interface PrepareAcquireReconcileInput {
50
52
  * partition. Never combined with `requireExistingSession` semantics: the require-existing form
51
53
  * re-opens and placement is first-write immutable, so it rides only the create-capable arm. */
52
54
  placement?: import("../session.js").SessionPlacement;
53
- /** borrowed-readonly — the tree owner this leg's create-capable acquire names (`name`, read before this phase from the spawner's seat; absent = none), on the create-capable
54
- * arm only; the row it resolves is read back against it ({@link readBackDelegatedRow}: under the leg's stop, worded by who named the id). */
55
- owner?: import("./delegation-owner.js").DelegatedRowOwner;
56
- /** borrowed-readonly — told that the acquired row may be named, right after its owner read back as {@link owner} (or no owner to judge); again, same id, on a lost-CAS re-acquire. */
55
+ /** borrowed-readonly — what this leg's row is judged by (read before this phase from the spawner's seat; absent = the leg holds no seat:
56
+ * its row is not judged). Its owner, when a name, is named on the create-capable acquire; the row every attempt resolves — either form —
57
+ * is judged before anything is written to it ({@link judgeLegRow}: under the leg's stop). */
58
+ judged?: import("./delegation-owner.js").JudgedLeg;
59
+ /** borrowed-readonly — told once that the acquired row may be named: the row of the attempt the phase ends on, when that attempt's
60
+ * judgement held (or the leg holds no seat) — never an attempt a lost CAS re-woke from. */
57
61
  verified?: (sessionId: string) => void;
58
62
  /** borrowed-readonly — the durable-park TOPOLOGY gap sentence for this
59
63
  * deployment (`durableParkGapFor`), or `undefined` when the topology is whole / does not apply.
@@ -65,8 +69,15 @@ export interface PrepareAcquireReconcileInput {
65
69
  report?: (err: Error, sessionId: string) => void;
66
70
  /** borrowed-mutable (the Runner's) — this leg's view of the session write ledger, every storage write issued through it ({@link writesThroughLeg}); absent for a standalone prepare. */
67
71
  legWrites?: LegWrites;
72
+ /** borrowed-readonly — the grant holder this leg's session writes carry ({@link stampHolder}, installed nearest the storage, with or
73
+ * without a ledger): the run's `RunInternals.holder` on a leg the host started; absent on a leg an engine lane started, and when the
74
+ * run carries none. */
75
+ holder?: string;
68
76
  /** borrowed-readonly — where the leg says what the log's replay dropped, and re-rooted a branch at it ({@link replayLossLeg}): absent ⇒ nothing said and no re-root (a break is refused). */
69
77
  replayLossNotice?: Parameters<typeof replayLossLeg>[0];
78
+ /** borrowed-mutable — the leg's record of where its request left the conversation's leaf ({@link RewindOutcome.branch}): the
79
+ * `resumeAt` branch states it moved once its leaf write lands, and the branch it hands on carries the record to its write-back. */
80
+ rewindOutcome?: Pick<RewindOutcome, "branch">;
70
81
  }
71
82
  /** The phase's outputs (four-class form). All six are fresh bindings —
72
83
  * the driver destructures them into consts, so a consumer moved ahead of this call is a lexical
@@ -79,12 +90,10 @@ export interface PrepareAcquireReconcileResult {
79
90
  * always wraps storage in the concrete built-in — the epoch pin needs its
80
91
  * append/getPromptEpoch). Aliases `acquired.session`'s storage through the proxy. */
81
92
  session: StoredSession;
82
- /** owned cell — flipped to `hit: true` by the conflict-detecting proxy installed inside `session`
83
- * whenever a RUN-time write loses the optimistic lock (identity is contract: the proxy closes
84
- * over this exact object; the run loop reads it into `errorCode="conflict"`). */
85
- conflictRef: {
86
- hit: boolean;
87
- };
93
+ /** owned cell — the leg's write-boundary latch ({@link WriteRefusal}), set by the proxy installed inside `session` whenever a
94
+ * RUN-time write is refused with `conflict` or `holder.superseded` (identity is contract: the proxy closes over this exact
95
+ * object; the run loop reads its word into `errorCode`). */
96
+ writeRefusal: WriteRefusal;
88
97
  /** owned — scan-1/A5: what the wake/crash reconcile closed, handed to the run loop so it can mint
89
98
  * the matching stream frames (see `Prepared.wakeRecovered`). Written by the acquire attempt that
90
99
  * SUCCEEDS (a conflict-losing attempt re-wakes and re-derives the whole set from the fresh
@@ -4,24 +4,26 @@ import { readMember } from "../thrown-value.js";
4
4
  import { refuseOpenToolCallAt } from "./continues-from.js";
5
5
  import { beforeTakes, judgeRewindTarget } from "./rewind-target.js";
6
6
  import { reconcileInterruptedSession } from "../session-reconcile.js";
7
- import { detectConflicts, settleBranchWriteBack } from "./branch-writeback.js";
7
+ import { detectConflicts, settleBranchWriteBack, writeRefusalLatch } from "./branch-writeback.js";
8
8
  import { settleTeardownLeg } from "./teardown-bounded.js";
9
- import { writesThroughLeg } from "./session-write-ledger.js";
9
+ import { stampHolder, writesThroughLeg } from "./session-write-ledger.js";
10
10
  import { replayLossLeg } from "./lineage-reroot-view.js";
11
11
  import { atLanding, refuseBranchOutsideWindow } from "./branch-window.js";
12
- import { createForm, readBackDelegatedRow } from "./delegation-owner.js";
12
+ import { createForm, judgeLegRow } from "./delegation-owner.js";
13
13
  const RECONCILE_MAX_RETRIES = 3;
14
14
  export async function prepareAcquireReconcile(input) {
15
15
  const { sessions, spec, resume, wakeEffects } = input;
16
16
  let acquired;
17
17
  let session;
18
- let conflictRef;
18
+ let writeRefusal;
19
19
  let wakeRecovered = [];
20
20
  let branch;
21
+ let rebranched = false;
21
22
  const lossLeg = input.replayLossNotice !== undefined ? replayLossLeg(input.replayLossNotice) : undefined;
23
+ const namedOwner = input.judged?.owner ?? undefined;
22
24
  for (let attempt = 0;; attempt++) {
23
25
  try {
24
- acquired = await sessions.acquire(spec.sessionId, spec.requireExistingSession ? { requireExisting: true } : createForm({ ...(input.placement !== undefined ? { placement: input.placement } : {}), ...(input.owner !== undefined ? { owner: input.owner.name } : {}) }));
26
+ acquired = await sessions.acquire(spec.sessionId, spec.requireExistingSession ? { requireExisting: true } : createForm({ ...(input.placement !== undefined ? { placement: input.placement } : {}), ...(namedOwner !== undefined ? { owner: namedOwner } : {}) }));
25
27
  }
26
28
  catch (err) {
27
29
  if (spec.requireExistingSession && err?.code === "not_found") {
@@ -32,17 +34,19 @@ export async function prepareAcquireReconcile(input) {
32
34
  }
33
35
  throw err;
34
36
  }
35
- if (input.owner !== undefined && !spec.requireExistingSession)
36
- await readBackDelegatedRow(sessions, acquired, input.owner, (e, id) => input.report?.(e, id));
37
- input.verified?.(acquired.sessionId);
38
- conflictRef = { hit: false };
37
+ if (input.judged !== undefined)
38
+ await judgeLegRow(sessions, acquired, { ...input.judged, minted: input.judged.minted && !spec.requireExistingSession }, (e, id) => input.report?.(e, id));
39
+ writeRefusal = writeRefusalLatch();
39
40
  const own = { ids: undefined };
40
- const legStorage = input.legWrites !== undefined ? writesThroughLeg(acquired.session.getStorage(), input.legWrites, acquired.sessionId) : acquired.session.getStorage();
41
- session = new StoredSession(detectConflicts(lossLeg !== undefined ? lossLeg.view(legStorage, acquired.sessionId) : legStorage, conflictRef, own));
41
+ const stamped = input.holder !== undefined ? stampHolder(acquired.session.getStorage(), input.holder) : acquired.session.getStorage();
42
+ const legStorage = input.legWrites !== undefined ? writesThroughLeg(stamped, input.legWrites, acquired.sessionId) : stamped;
43
+ session = new StoredSession(detectConflicts(lossLeg !== undefined ? lossLeg.view(legStorage, acquired.sessionId) : legStorage, writeRefusal, own));
42
44
  try {
43
45
  input.legWrites?.startAt(await session.getLeafId());
44
- if (!spec.sessionId)
46
+ if (!spec.sessionId) {
47
+ input.verified?.(acquired.sessionId);
45
48
  break;
49
+ }
46
50
  if (resume) {
47
51
  await session.getStorage().setLeafId(resume.leafId).catch((cut) => {
48
52
  throw readMember(cut, "code") === "not_found" ? new SessionError("corrupt_session", `session "${spec.sessionId}" no longer holds the entry its checkpoint was cut at ("${resume.leafId}")`, cut, "cut_point_missing") : cut;
@@ -56,11 +60,22 @@ export async function prepareAcquireReconcile(input) {
56
60
  const leafSet = await refuseBranchOutsideWindow(raw, landing, spec.resumeAt, acquired.sessionId, "resumeAt", start.id, beforeTakes(target.entry));
57
61
  if (leafSet !== null)
58
62
  await refuseOpenToolCallAt(session, leafSet, spec.resumeAt, "resumeAt");
59
- await storage.setLeafId(leafSet);
63
+ const outcome = input.rewindOutcome;
64
+ try {
65
+ await storage.setLeafId(leafSet);
66
+ }
67
+ catch (err) {
68
+ if (outcome !== undefined && !isSessionConflict(err))
69
+ outcome.branch = undefined;
70
+ throw err;
71
+ }
72
+ if (outcome !== undefined && leafSet !== leafBefore)
73
+ outcome.branch = "left_moved";
60
74
  own.ids = new Set();
61
- branch = { storage, leafBefore, leafSet, own };
75
+ branch = { storage, leafBefore, leafSet, own, ...(outcome !== undefined && !rebranched ? { outcome } : {}) };
62
76
  }
63
77
  wakeRecovered = (await reconcileInterruptedSession(session, wakeEffects, resume?.suspendedBatch)).recovered;
78
+ input.verified?.(acquired.sessionId);
64
79
  break;
65
80
  }
66
81
  catch (err) {
@@ -69,10 +84,13 @@ export async function prepareAcquireReconcile(input) {
69
84
  const forget = sessions.forget.bind(sessions), id = acquired.sessionId;
70
85
  await settleTeardownLeg(() => Promise.resolve(forget(id)).catch(() => undefined), "forget (acquire-reconcile re-wake leg)", (e) => input.report?.(e, id));
71
86
  }
87
+ if (branch !== undefined)
88
+ rebranched = true;
72
89
  branch = undefined;
73
90
  lossLeg?.discard();
74
91
  continue;
75
92
  }
93
+ input.verified?.(acquired.sessionId);
76
94
  if (branch !== undefined)
77
95
  await settleBranchWriteBack(branch, acquired.sessionId, "resumeAt branch write-back (acquire-reconcile failure leg)", (e) => input.report?.(e, acquired.sessionId));
78
96
  await settleTeardownLeg(() => Promise.resolve(sessions.forget ? sessions.forget(acquired.sessionId) : undefined).catch(() => undefined), "forget (acquire-reconcile failure leg)", (e) => input.report?.(e, acquired.sessionId));
@@ -80,5 +98,5 @@ export async function prepareAcquireReconcile(input) {
80
98
  }
81
99
  }
82
100
  lossLeg?.settle();
83
- return { acquired, session, conflictRef, wakeRecovered, branch };
101
+ return { acquired, session, writeRefusal, wakeRecovered, branch };
84
102
  }