@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,4 +1,5 @@
1
1
  import type { GovernanceRetryClass } from "./governance-codes.js";
2
+ import type { RewindMoved } from "./terminal-cause.js";
2
3
  import { type FileHistoryRetentionPolicy } from "./file-history-retention.js";
3
4
  import type { ExecutionEnv, SessionRowExpectation } from "../internal/harness-types.js";
4
5
  /** rel path of `child` under `root` in "/" form (win root) / verbatim form (posix root); null when not under.
@@ -41,12 +42,16 @@ export type FileHistoryTrackKeyResolution = {
41
42
  * does not keep them, or it was imported: a place never crosses the export door), so where it belongs cannot be
42
43
  * told; a host that knows where such versions were recorded names it on the rewind (`unplacedHistoryRecordedUnder`). The row's
43
44
  * sentence says the way out as a fact about the host, never as that input's name: a host whose own wire takes the directory under
44
- * another key renders its way out from this `class`.
45
+ * another key renders its way out from this `class`;
46
+ * · `changed_since_plan` — the restore was about to write or delete a file its plan did not see that way (the file's
47
+ * bytes or absence, or the version to restore, differ from what the plan read just before; or the plan did not plan to
48
+ * move it): another writer changed it between the two ({@link planFileHistoryRestore}). What is there now stays; a rewind
49
+ * planned again restores it as it then stands.
45
50
  * Damage to the store's own records (a missing version record, a missing or corrupt blob) is not a refusal
46
51
  * in any backend: it is a `failed` row. A consumer reads the class as an OPEN set (a later release may add a word)
47
52
  * and branches on it, never on the reason text.
48
53
  */
49
- export declare const FILE_HISTORY_REFUSAL_CLASSES: readonly ["link_safety", "base_unavailable", "key_unresolvable", "recorded_elsewhere", "place_unrecorded"];
54
+ export declare const FILE_HISTORY_REFUSAL_CLASSES: readonly ["link_safety", "base_unavailable", "key_unresolvable", "recorded_elsewhere", "place_unrecorded", "changed_since_plan"];
50
55
  export type FileHistoryRefusalClass = (typeof FILE_HISTORY_REFUSAL_CLASSES)[number];
51
56
  /**
52
57
  * Why a rewind LEFT a tracked file as it is without counting it refused or failed — the `class` of a {@link FileHistoryLeftAsIsFile}
@@ -271,7 +276,39 @@ export declare function resolveTrackKey(root: string, key: string, minted?: File
271
276
  /** The file-history failure codes, spelled once: {@link FileHistoryError}'s `code` is derived from this tuple (each
272
277
  * word is documented there). A host that recognizes a code in failure text, or keeps a code in a store, reads this
273
278
  * value rather than keeping its own list. */
274
- export declare const FILE_HISTORY_ERROR_CODES: readonly ["track_failed", "snapshot_failed", "restore_failed", "adopt_failed", "not_found", "aborted", "unsupported_format", "conflict"];
279
+ export declare const FILE_HISTORY_ERROR_CODES: readonly ["track_failed", "snapshot_failed", "restore_failed", "adopt_failed", "not_found", "aborted", "unsupported_format", "conflict", "too_large"];
280
+ /** Where a {@link FileHistorySizeLimit} comes from: `"store_option"` = the store was configured with it (the bundled stores'
281
+ * `maxBlobBytes`); `"backend"` = the storage medium's own bound, which the store read from it (a database's packet limit). A
282
+ * CLOSED SET with one home, registered in `docs/CLOSED-SETS.md`. */
283
+ export declare const FILE_HISTORY_LIMIT_SOURCES: readonly ["store_option", "backend"];
284
+ export type FileHistoryLimitSource = (typeof FILE_HISTORY_LIMIT_SOURCES)[number];
285
+ /** The bound a `too_large` refusal names: the most bytes ONE stored copy of a file may hold (a copy of exactly this many is stored),
286
+ * and where the bound comes from. */
287
+ export interface FileHistorySizeLimit {
288
+ readonly bytes: number;
289
+ readonly source: FileHistoryLimitSource;
290
+ }
291
+ /**
292
+ * THE `too_large` refusal — the one mint every store answers it with (a backend of another kind included): `code` `too_large`,
293
+ * `permanence` `terminal` (the same bytes never fit under the same bound), `limit` the bound and its source, and a sentence naming
294
+ * what was refused, its size and the bound — no stored content. `size` is the refused copy's byte length.
295
+ */
296
+ export declare function fileHistoryTooLarge(input: {
297
+ readonly what: string;
298
+ readonly size: number;
299
+ readonly limit: FileHistorySizeLimit;
300
+ }): FileHistoryError;
301
+ /** A bundled store's `maxBlobBytes` option, read once at construction: absent = no bound; else a safe integer, 0 or more — any other
302
+ * value is refused there (`config.invalid_argument`), never read as "no bound". */
303
+ export declare function readMaxBlobBytes(owner: string, value: unknown): number | undefined;
304
+ /** A bundled store's judgment of one copy it is about to store under its `maxBlobBytes`: `undefined` = it fits (a copy of exactly
305
+ * the bound fits), else the {@link fileHistoryTooLarge} refusal. Measured in bytes, never characters. */
306
+ export declare function blobOverStoreLimit(bytes: Uint8Array, maxBlobBytes: number | undefined, what: string): FileHistoryError | undefined;
307
+ /** A refusal as a verb's failed answer (`undefined` stays `undefined`). */
308
+ export declare function overLimit(error: FileHistoryError | undefined): {
309
+ readonly ok: false;
310
+ readonly error: FileHistoryError;
311
+ } | undefined;
275
312
  export interface FileHistoryError {
276
313
  /** `not_found` = no boundary for that (scope, entryId) — an absence, never a fault (a boundary that is there
277
314
  * but cannot be read is the verb's `*_failed` with the fault); `aborted` = the signal fired (or the
@@ -294,10 +331,15 @@ export interface FileHistoryError {
294
331
  * be judged, a fault in staging or publishing a good graph (the disk refusing it) — and `exportHistory`
295
332
  * answers it for a history it cannot read whole. `unsupported_format` is the import DOOR's refusal and
296
333
  * nothing else: a foreign-epoch or wrong-version envelope, or an envelope whose content the closed sets
297
- * (or the backend's own record-naming rules) cannot hold, refused before any blob is fetched; the rest
298
- * name the verb that failed. */
334
+ * (or the backend's own record-naming rules) cannot hold, refused before any blob is fetched; `too_large` = one copy of a file
335
+ * the verb would store (a first touch's pristine bytes, a boundary's capture, an imported or exchanged blob) is over the store's
336
+ * bound — the call commits nothing (no record, no boundary, no imported graph; a copy an earlier file of the same call already
337
+ * wrote is not referenced by anything this call commits, as after any failed attempt), `limit` says the bound and where it comes from, `permanence` is `terminal`
338
+ * ({@link fileHistoryTooLarge}, the one mint); the rest name the verb that failed. */
299
339
  code: (typeof FILE_HISTORY_ERROR_CODES)[number];
300
340
  message: string;
341
+ /** On `too_large`, and only there: the bound the copy is over ({@link FileHistorySizeLimit}). */
342
+ limit?: FileHistorySizeLimit;
301
343
  /** The backend's judgment of a FAULT — it could not do what it was asked — as a {@link GovernanceRetryClass}
302
344
  * word (the words are defined there, once). Stated whenever the backend knows: from a caught error's code,
303
345
  * or from a state it found itself (a damaged record is `terminal`). Absent when it does not know, and on an
@@ -462,6 +504,14 @@ export interface FileHistoryRestoreOptions {
462
504
  */
463
505
  unplacedHistoryRecordedUnder?: string;
464
506
  }
507
+ /** The word a host writes for `unplacedHistoryRecordedUnder` (on `TaskSpec` and `Runner.rewindFiles`, never on a store's own `restore`)
508
+ * when the directory this session's older versions were recorded under is this rewind's own root — the root the engine joins the
509
+ * session's keys on (a session that works in a tree of its own: that tree), which a host does not have to know or spell: the host
510
+ * states the fact, the engine supplies the path. */
511
+ export declare const UNPLACED_AT_REWIND_ROOT = "rewind_root";
512
+ /** The restore's options as the store is handed them at `root` (the rewind's own root, the one its keys are joined on): the word
513
+ * {@link UNPLACED_AT_REWIND_ROOT} read as that root; any other value as it is. Every seat that hands options to a store asks this. */
514
+ export declare function restoreOptionsAt(options: FileHistoryRestoreOptions | undefined, root: string): FileHistoryRestoreOptions | undefined;
465
515
  export interface FileHistoryDiffStats {
466
516
  filesChanged: string[];
467
517
  insertions: number;
@@ -496,7 +546,8 @@ export interface RewindFilesRequest {
496
546
  dryRun?: boolean;
497
547
  /** Caller cancel for the restore. */
498
548
  signal?: AbortSignal;
499
- /** {@link FileHistoryRestoreOptions.unplacedHistoryRecordedUnder}, for this rewind (preview and restore alike). */
549
+ /** {@link FileHistoryRestoreOptions.unplacedHistoryRecordedUnder}, for this rewind (preview and restore alike) — or the word
550
+ * `"rewind_root"`: this rewind's own root, which the engine supplies (as `TaskSpec.unplacedHistoryRecordedUnder` reads it). */
500
551
  unplacedHistoryRecordedUnder?: string;
501
552
  /** The occupant the caller read the session as: `{ row: { owner, incarnation } }` (a `SessionHead` serves as `row`) — the
502
553
  * session under `sessionId` must still be that row (`sessionRowMatches` on the acquired session), or nothing is rewound and
@@ -510,6 +561,10 @@ export interface RewindFilesRequest {
510
561
  * env that stands elsewhere ⇒ `config.cwd_not_honored`. Absent ⇒ the factory attaches to the workspace it holds for the
511
562
  * session (and refuses, its own refusal passed through, when it holds none). */
512
563
  cwd?: string;
564
+ /** `CompactSessionRequest.holder`'s member on the file rewind (its request door answers a bad value `rewind.invalid_spec`). This verb writes no session entry, so the holder fences its session side only: the
565
+ * files themselves move through the history store on the execution environment, which no session fence reaches — the host's own
566
+ * grant (its run row) guards that part. */
567
+ holder?: string;
513
568
  }
514
569
  /** `Runner.rewindFiles`' answer. A refusal is a thrown `Error` carrying a `code`. */
515
570
  export type RewindFilesResult =
@@ -1213,12 +1268,12 @@ export type FileRestoreApplyOutcome =
1213
1268
  /** A refusal this half decides: about the object at the path (its kind, a guarded write's precondition, the recorded
1214
1269
  * place having moved or become a link, a file the rewind holds because a frozen row names it — `link_safety`), or about where
1215
1270
  * the version belongs (`recorded_elsewhere`, with
1216
- * `recordedUnder`; `place_unrecorded`). `action` = what converging would have done. A backend copies all of it into the
1217
- * ledger row. */
1271
+ * `recordedUnder`; `place_unrecorded`), or about the file having changed since the restore's plan read it
1272
+ * (`changed_since_plan`). `action` = what converging would have done. A backend copies all of it into the ledger row. */
1218
1273
  | {
1219
1274
  outcome: "refused";
1220
1275
  reason: string;
1221
- class: "link_safety" | "recorded_elsewhere" | "place_unrecorded";
1276
+ class: "link_safety" | "recorded_elsewhere" | "place_unrecorded" | "changed_since_plan";
1222
1277
  recordedUnder?: string;
1223
1278
  action?: "write" | "delete";
1224
1279
  }
@@ -1268,6 +1323,10 @@ export type FileRestoreApplyOutcome =
1268
1323
  * · HOLD — once the preflight has read where the file really lies, the rewind's env view is asked whether it holds that file (a
1269
1324
  * frozen row's file, {@link RestoreHolds}); a held file is refused `link_safety` with the view's sentence, before any write,
1270
1325
  * delete or change of mode. An env that is not the engine's view holds nothing.
1326
+ * · AS PLANNED — once the file's current bytes are read, the view is told what this half found there and would converge it to
1327
+ * ({@link notePlannedState}): a planning view records it; the view of the restore that carries the plan out answers a refusal
1328
+ * (`changed_since_plan`) when the plan read the same file otherwise, or never reached it — before any write, delete or change
1329
+ * of mode. A file already converged needs none and is `identical`, whatever the plan read.
1271
1330
  *
1272
1331
  * THE WRITE uses `env.writeFileGuarded` when the env has it — one atomic verify-and-write whose
1273
1332
  * expectation names the addressed path and forbids following a leaf link, so the window between
@@ -1340,6 +1399,10 @@ export interface InMemoryFileHistoryStoreOptions {
1340
1399
  /** The clock the store ages unreferenced blobs by (milliseconds; {@link FILE_HISTORY_UNREFERENCED_BLOB_GRACE_MS}). Omitted ⇒
1341
1400
  * `Date.now`; a value that is not a function is refused here. */
1342
1401
  now?: () => number;
1402
+ /** The most bytes one stored copy of a file may hold ({@link readMaxBlobBytes}): a copy over it is refused `too_large`
1403
+ * ({@link blobOverStoreLimit}) at every verb that would store it — `trackEdit`, `snapshot`, `importHistory`, `blobExchange.put` —
1404
+ * with nothing of the call committed. Omitted ⇒ no bound. */
1405
+ maxBlobBytes?: number;
1343
1406
  }
1344
1407
  export declare class InMemoryFileHistoryStore implements FileHistoryStore {
1345
1408
  private readonly scopes;
@@ -1358,6 +1421,8 @@ export declare class InMemoryFileHistoryStore implements FileHistoryStore {
1358
1421
  * settle: `deleteBySession` refuses while a scope has one, an import still fetching its blobs included. */
1359
1422
  private readonly writers;
1360
1423
  constructor(options?: InMemoryFileHistoryStoreOptions);
1424
+ /** {@link InMemoryFileHistoryStoreOptions.maxBlobBytes}, as read at construction. */
1425
+ private readonly maxBlobBytes;
1361
1426
  /** The bundled exchange ({@link FileHistoryBlobExchange}) over this store's own blobs. A `put` (re)starts the blob's age. */
1362
1427
  readonly blobExchange: FileHistoryBlobExchange;
1363
1428
  /** Keep a captured or imported blob (dedup by address): its age starts at its first write. */
@@ -1437,7 +1502,20 @@ interface RestoreSeen {
1437
1502
  readonly mutations: readonly EnvMutation[];
1438
1503
  readonly held: readonly HeldMutation[];
1439
1504
  readonly told: ReadonlyMap<string, string>;
1505
+ /** On a WITNESSING view: how many mutations (a write, a delete, a change of mode, a directory made) the restore asked of the env,
1506
+ * and how many of them answered done — whatever their path. A held mutation, and one the view refused itself, was never asked.
1507
+ * Zero on a planning view, which asks the env for none. */
1508
+ readonly asked: {
1509
+ readonly issued: number;
1510
+ readonly done: number;
1511
+ };
1512
+ /** On a PLANNING view: what the shared restore half found at each path it read and would converge it to ({@link notePlannedState}),
1513
+ * the first state per path — the plan a restore is then held to. */
1514
+ readonly states: ReadonlyMap<string, string>;
1440
1515
  }
1516
+ /** Whether a witnessed restore moved the working tree ({@link RewindMoved}), read off its view's {@link RestoreSeen.asked}: one done
1517
+ * ⇒ `"some"`; asked and none done ⇒ `"unknown"` (a failed write may have written part); none asked ⇒ `"none"`. */
1518
+ export declare function restoreMovedOf(seen: Pick<RestoreSeen, "asked">): RewindMoved;
1441
1519
  /**
1442
1520
  * The files a restore must not move under ANY key: the file of every frozen row it lists ({@link fileHistoryEntryFrozen} — the
1443
1521
  * row's recorded place joined with its key's last segment, the store's own composition), keyed by its spelling folded the way the
@@ -1452,8 +1530,9 @@ export type RestoreHolds = ReadonlyMap<string, {
1452
1530
  readonly frozenKeys: readonly string[];
1453
1531
  }>;
1454
1532
  /** A view of `env` that performs every call and records the mutations a restore made through it; it holds the files `holds` names
1455
- * (a plan's, {@link FileHistoryRestorePlan.holds}), so the restore performs what its plan planned. */
1456
- export declare function witnessEnvOf(env: ExecutionEnv, holds?: RestoreHolds): {
1533
+ * (a plan's, {@link FileHistoryRestorePlan.holds}) and refuses a file the plan read otherwise (`planned`, its
1534
+ * {@link FileHistoryRestorePlan.states}), so the restore performs what its plan planned. */
1535
+ export declare function witnessEnvOf(env: ExecutionEnv, holds?: RestoreHolds, planned?: ReadonlyMap<string, string>): {
1457
1536
  env: ExecutionEnv;
1458
1537
  } & RestoreSeen;
1459
1538
  /** A restore as the engine answers it: its rows, each stating `outsideRoot`. */
@@ -1495,6 +1574,10 @@ export interface FileHistoryRestorePlan {
1495
1574
  /** The files the restore holds ({@link RestoreHolds}: its frozen rows' files) — what the plan held, and what the restore that
1496
1575
  * carries it out holds ({@link witnessEnvOf}). Empty when the restore lists no frozen row. */
1497
1576
  readonly holds: RestoreHolds;
1577
+ /** What the plan read at each path it reached and would converge it to ({@link RestoreSeen.states}) — what the restore that carries it
1578
+ * out holds every write, delete and change of mode to ({@link witnessEnvOf}): a file found otherwise, or never reached by the plan, is
1579
+ * refused `changed_since_plan`. */
1580
+ readonly states: ReadonlyMap<string, string>;
1498
1581
  /** The keys of the restore's frozen rows (sorted) when the plan also asked a mutation whose real path the shared restore half did
1499
1582
  * not read (the store converged a file another way, or through an env it wrapped): which file such a write lands on cannot be
1500
1583
  * told, so it cannot be held — a seat refuses the whole restore before any file moves. Absent otherwise. */
@@ -1546,6 +1629,7 @@ export declare function planFileHistoryRestore(store: Pick<FileHistoryStore, "re
1546
1629
  env: ExecutionEnv;
1547
1630
  root: string;
1548
1631
  signal?: AbortSignal;
1632
+ /** The rewind's options as the request states them: the word {@link UNPLACED_AT_REWIND_ROOT} is read as `root` here ({@link restoreOptionsAt}). */
1549
1633
  options?: FileHistoryRestoreOptions;
1550
1634
  /** Called once for each planned write (with the bytes it would write) or delete (`target` null) whose current file the arithmetic
1551
1635
  * read (`current` null: none there), in the order the restore asked them, while the plan holds those bytes — it keeps none after. */
@@ -46,7 +46,7 @@ function lastSegmentOf(absPath) {
46
46
  const cut = (isWinFormPath(absPath) ? normSlash(absPath) : absPath).replace(/\/+$/, "");
47
47
  return cut.slice(cut.lastIndexOf("/") + 1);
48
48
  }
49
- export const FILE_HISTORY_REFUSAL_CLASSES = Object.freeze(["link_safety", "base_unavailable", "key_unresolvable", "recorded_elsewhere", "place_unrecorded"]);
49
+ export const FILE_HISTORY_REFUSAL_CLASSES = Object.freeze(["link_safety", "base_unavailable", "key_unresolvable", "recorded_elsewhere", "place_unrecorded", "changed_since_plan"]);
50
50
  export const FILE_HISTORY_LEFT_AS_IS_CLASSES = Object.freeze(["frozen_history", "recorded_outside_root"]);
51
51
  export function fileHistoryEntryTravels(key) {
52
52
  return key.kind === "root-relative";
@@ -129,7 +129,32 @@ export function resolveTrackKey(root, key, minted) {
129
129
  return { ok: false, reason: `unsafe recorded key escapes root: ${key}`, class: "key_unresolvable" };
130
130
  return { ok: true, abs: joinUnder(root, keyN) };
131
131
  }
132
- export const FILE_HISTORY_ERROR_CODES = Object.freeze(["track_failed", "snapshot_failed", "restore_failed", "adopt_failed", "not_found", "aborted", "unsupported_format", "conflict"]);
132
+ export const FILE_HISTORY_ERROR_CODES = Object.freeze(["track_failed", "snapshot_failed", "restore_failed", "adopt_failed", "not_found", "aborted", "unsupported_format", "conflict", "too_large"]);
133
+ export const FILE_HISTORY_LIMIT_SOURCES = Object.freeze(["store_option", "backend"]);
134
+ export function fileHistoryTooLarge(input) {
135
+ const { what, size, limit } = input;
136
+ return {
137
+ code: "too_large",
138
+ message: `${what} is ${size} bytes, over the file history's limit of ${limit.bytes} bytes for one stored copy (${limit.source === "store_option" ? "the store's maxBlobBytes" : "the storage backend's own bound"}) — the call committed nothing`,
139
+ permanence: "terminal",
140
+ limit: Object.freeze({ bytes: limit.bytes, source: limit.source }),
141
+ };
142
+ }
143
+ export function readMaxBlobBytes(owner, value) {
144
+ if (value === undefined)
145
+ return undefined;
146
+ if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0)
147
+ return value;
148
+ throw Object.assign(new TypeError(`${owner} options.maxBlobBytes must be a whole number of bytes, 0 or more (got ${value === null ? "null" : typeof value === "number" ? String(value) : typeof value})`), { code: "config.invalid_argument" });
149
+ }
150
+ export function blobOverStoreLimit(bytes, maxBlobBytes, what) {
151
+ if (maxBlobBytes === undefined || bytes.byteLength <= maxBlobBytes)
152
+ return undefined;
153
+ return fileHistoryTooLarge({ what, size: bytes.byteLength, limit: { bytes: maxBlobBytes, source: "store_option" } });
154
+ }
155
+ export function overLimit(error) {
156
+ return error === undefined ? undefined : { ok: false, error };
157
+ }
133
158
  const CAUGHT_CODE_RETRY_CLASS = new Map([
134
159
  ...["EACCES", "EPERM", "EROFS", "ENAMETOOLONG", "EFBIG", "ENOTDIR", "EISDIR"].map((c) => [c, "terminal"]),
135
160
  ...["EAGAIN", "EWOULDBLOCK", "EBUSY", "EINTR", "ETIMEDOUT", "EMFILE", "ENFILE"].map((c) => [c, "transient"]),
@@ -150,6 +175,10 @@ export class FileHistoryStoreError extends Error {
150
175
  this.permanence = failure.permanence;
151
176
  }
152
177
  }
178
+ export const UNPLACED_AT_REWIND_ROOT = "rewind_root";
179
+ export function restoreOptionsAt(options, root) {
180
+ return options?.unplacedHistoryRecordedUnder === UNPLACED_AT_REWIND_ROOT ? { ...options, unplacedHistoryRecordedUnder: root } : options;
181
+ }
153
182
  export const FILE_HISTORY_DIFF_LINE_BUDGET = 2000;
154
183
  export function bytesAreBinary(bytes) {
155
184
  return bytes.includes(0);
@@ -525,20 +554,25 @@ export async function applyFileRestoreViaEnv(env, absPath, target, opts) {
525
554
  const refuseHeld = (action, reason) => ({ outcome: "refused", reason, class: "link_safety", action });
526
555
  const cur = await env.readBinaryFile(absPath, signal);
527
556
  const curAbsent = !cur.ok && isAbsence(cur.error.code);
557
+ const curHash = cur.ok ? createHash("sha256").update(cur.value).digest("hex") : undefined;
558
+ const unplanned = notePlannedState(env, absPath, `${curHash !== undefined ? `bytes:${curHash} mode:${guard.currentMode ?? "unread"}` : curAbsent ? "absent" : `unread:${cur.ok ? "" : cur.error.code}`} ->${"absent" in target ? "absent" : `bytes:${target.hash}`}`);
559
+ const refuseUnplanned = (action) => ({ outcome: "refused", reason: CHANGED_SINCE_PLAN_REASON, class: "changed_since_plan", action });
528
560
  if ("absent" in target) {
529
561
  if (curAbsent)
530
562
  return { outcome: "identical" };
531
563
  if (hold !== undefined)
532
564
  return refuseHeld("delete", hold());
565
+ if (unplanned)
566
+ return refuseUnplanned("delete");
533
567
  const rm = await env.remove(absPath, { force: true, ...(signal !== undefined ? { abortSignal: signal } : {}) });
534
568
  if (!rm.ok)
535
569
  return { outcome: "failed", reason: `remove: ${rm.error.code}` };
536
570
  return { outcome: "applied" };
537
571
  }
538
- if (cur.ok && createHash("sha256").update(cur.value).digest("hex") === target.hash) {
539
- const modeOnly = await applyRecordedMode(env, absPath, opts, guard.currentMode, hold !== undefined);
572
+ if (curHash !== undefined && curHash === target.hash) {
573
+ const modeOnly = await applyRecordedMode(env, absPath, opts, guard.currentMode, hold !== undefined || unplanned);
540
574
  if (modeOnly === "held")
541
- return refuseHeld("write", hold());
575
+ return hold !== undefined ? refuseHeld("write", hold()) : refuseUnplanned("write");
542
576
  if (modeOnly === "unchanged")
543
577
  return { outcome: "identical" };
544
578
  if (modeOnly === "applied")
@@ -549,9 +583,11 @@ export async function applyFileRestoreViaEnv(env, absPath, target, opts) {
549
583
  }
550
584
  if (hold !== undefined)
551
585
  return refuseHeld("write", hold());
586
+ if (unplanned)
587
+ return refuseUnplanned("write");
552
588
  const w = await writeRestoredBytes(env, absPath, target.bytes, signal);
553
589
  if (!w.ok)
554
- return w.refused ? { outcome: "refused", reason: `write: ${w.code}`, class: "link_safety", action: "write" } : { outcome: "failed", reason: `write: ${w.code}` };
590
+ return w.refused ? { outcome: "refused", reason: `write: ${w.code} — the path stopped being what the check read just before the write (the file, or a directory above it, became a link or another object), so nothing was written; ${LINK_SAFETY_WAY_ON.changed}`, class: "link_safety", action: "write" } : { outcome: "failed", reason: `write: ${w.code}` };
555
591
  const modeAfter = await applyRecordedMode(env, absPath, opts, undefined);
556
592
  return { outcome: "applied", ...(modeAfter === "unpreserved" || modeAfter === "applied_unpreserved" ? { modeNotPreserved: true } : {}) };
557
593
  }
@@ -563,8 +599,8 @@ async function restorePreflight(env, absPath, target, opts) {
563
599
  const info = await env.fileInfo(absPath, opts.signal);
564
600
  if (info.ok && info.value.kind !== "file") {
565
601
  return refuse("link_safety", info.value.kind === "symlink"
566
- ? "restore target is a SYMLINK — the recorded bytes belong to the file that was edited, not to whatever the link now points at"
567
- : `restore target is a ${info.value.kind}, not a regular file — the recorded bytes are not this object's`);
602
+ ? `restore target is a SYMLINK — the recorded bytes belong to the file that was edited, not to whatever the link now points at; ${LINK_SAFETY_WAY_ON.leaf}`
603
+ : `restore target is a ${info.value.kind}, not a regular file — the recorded bytes are not this object's; ${LINK_SAFETY_WAY_ON.leaf}`);
568
604
  }
569
605
  const currentMode = info.ok ? info.value.mode : undefined;
570
606
  const recorded = await recordedPlaceOf(env, absPath, opts);
@@ -575,10 +611,10 @@ async function restorePreflight(env, absPath, target, opts) {
575
611
  if (now === recorded)
576
612
  return { currentMode, place: now };
577
613
  if (now === undefined)
578
- return refuse("link_safety", "where this file would land cannot be read (its directory's real path did not resolve) — it was not written");
614
+ return refuse("link_safety", `where this file would land cannot be read (its directory's real path did not resolve) — it was not written; ${LINK_SAFETY_WAY_ON.unread}`);
579
615
  const stands = await placeAsItStands(env, recorded, opts.signal);
580
616
  if (stands === undefined) {
581
- return refuse("link_safety", `the directory this version was recorded under (${recorded}) no longer resolves to itself — it was moved or is reached through a link now — so it was not written`);
617
+ return refuse("link_safety", `the directory this version was recorded under (${recorded}) no longer resolves to itself — it was moved or is reached through a link now — so it was not written; ${LINK_SAFETY_WAY_ON.place}`);
582
618
  }
583
619
  if (stands === now)
584
620
  return { currentMode, place: now };
@@ -596,6 +632,12 @@ async function restorePreflight(env, absPath, target, opts) {
596
632
  }
597
633
  return refuse("recorded_elsewhere", `not restored: this version belongs to ${joinUnder(stands, lastSegmentOf(absPath))}, where it was recorded — a file is restored only there; rewind from ${oldRootOf(stands, relUnder(opts.root, absPath) ?? "")} to restore it`, stands);
598
634
  }
635
+ const LINK_SAFETY_WAY_ON = {
636
+ leaf: "to restore it, put a regular file back at this path in place of the link or other object (or remove it), then rewind again — or restore the file by hand",
637
+ place: "to restore it, put that directory back where it was as a real directory (not a link to one), then rewind again — or restore the file by hand",
638
+ unread: "to restore it, check that its directory still exists and can be reached, then rewind again — or restore the file by hand",
639
+ changed: "to restore it, put the file and the directories above it back as they were (a regular file, no link in place of any of them), then rewind again — or restore the file by hand",
640
+ };
599
641
  async function recordedPlaceOf(env, absPath, opts) {
600
642
  const ident = opts.parentIdent;
601
643
  if (ident !== undefined && isPlace(ident))
@@ -659,7 +701,7 @@ async function applyRecordedMode(env, absPath, opts, currentMode, held = false)
659
701
  return "held";
660
702
  return (await setMode(want & 0o7777)) ? "applied" : "unpreserved";
661
703
  }
662
- const IN_MEMORY_FILE_HISTORY_STORE_OPTION_KEYS = optionKeys()({ retention: 0, now: 0 });
704
+ const IN_MEMORY_FILE_HISTORY_STORE_OPTION_KEYS = optionKeys()({ retention: 0, now: 0, maxBlobBytes: 0 });
663
705
  export class InMemoryFileHistoryStore {
664
706
  scopes = new Map();
665
707
  boundaryKeep;
@@ -675,10 +717,12 @@ export class InMemoryFileHistoryStore {
675
717
  throw Object.assign(new TypeError(`InMemoryFileHistoryStore options.now must be a function answering milliseconds (got ${opts.now === null ? "null" : typeof opts.now})`), { code: "config.invalid_argument" });
676
718
  }
677
719
  this.now = opts.now ?? Date.now;
720
+ this.maxBlobBytes = readMaxBlobBytes("InMemoryFileHistoryStore", opts.maxBlobBytes);
678
721
  }
722
+ maxBlobBytes;
679
723
  blobExchange = {
680
724
  put: async (hash, bytes) => {
681
- const refused = blobPutRefusal(hash, bytes);
725
+ const refused = blobPutRefusal(hash, bytes) ?? overLimit(blobOverStoreLimit(bytes, this.maxBlobBytes, `the blob put under ${hash}`));
682
726
  if (refused !== undefined)
683
727
  return refused;
684
728
  if (!this.blobs.has(hash))
@@ -801,6 +845,9 @@ export class InMemoryFileHistoryStore {
801
845
  return { ok: true, minted: true };
802
846
  }
803
847
  if (cap.state === "file") {
848
+ const over = overLimit(blobOverStoreLimit(cap.bytes, this.maxBlobBytes, `the first-touch copy of ${absPath}`));
849
+ if (over !== undefined)
850
+ return over;
804
851
  this.leaseBlob(cap.hash);
805
852
  try {
806
853
  this.holdBlob(cap.hash, cap.bytes);
@@ -927,6 +974,11 @@ export class InMemoryFileHistoryStore {
927
974
  staged.set(key, { kind: "unchanged", version: last.version });
928
975
  continue;
929
976
  }
977
+ const over = overLimit(blobOverStoreLimit(cap.bytes, this.maxBlobBytes, `the boundary's copy of ${resolved.abs}`));
978
+ if (over !== undefined) {
979
+ sc.spentAttempts.add(entryId);
980
+ return over;
981
+ }
930
982
  if (!stagedBlobHashes.has(cap.hash)) {
931
983
  stagedBlobHashes.add(cap.hash);
932
984
  this.leaseBlob(cap.hash);
@@ -1255,6 +1307,9 @@ export class InMemoryFileHistoryStore {
1255
1307
  if (createHash("sha256").update(bytes).digest("hex") !== hash) {
1256
1308
  return { ok: false, error: { code: "adopt_failed", message: `source blob ${hash} fails content-address integrity — refused, nothing published` } };
1257
1309
  }
1310
+ const over = overLimit(blobOverStoreLimit(bytes, this.maxBlobBytes, `source blob ${hash}`));
1311
+ if (over !== undefined)
1312
+ return over;
1258
1313
  staged.set(hash, bytes);
1259
1314
  }
1260
1315
  const live = this.scopes.get(scope);
@@ -1284,6 +1339,9 @@ export class InMemoryFileHistoryStore {
1284
1339
  }
1285
1340
  }
1286
1341
  }
1342
+ export function restoreMovedOf(seen) {
1343
+ return seen.asked.done > 0 ? "some" : seen.asked.issued > 0 ? "unknown" : "none";
1344
+ }
1287
1345
  function foldedFile(p) {
1288
1346
  return foldedSpelling(isWinFormPath(p) ? normSlash(p) : p);
1289
1347
  }
@@ -1315,14 +1373,40 @@ function noteRealPath(env, at, real) {
1315
1373
  const hold = Reflect.apply(seat, undefined, [at, real]);
1316
1374
  return typeof hold === "function" ? hold : undefined;
1317
1375
  }
1376
+ const PLANNED_STATE_SEAT = Symbol("file-history restore: the state a plan read");
1377
+ function notePlannedState(env, at, state) {
1378
+ const seat = Reflect.get(env, PLANNED_STATE_SEAT);
1379
+ return typeof seat === "function" && Reflect.apply(seat, undefined, [at, state]) === true;
1380
+ }
1381
+ const CHANGED_SINCE_PLAN_REASON = "not restored: this file is not as the rewind's plan read it a moment before (another writer changed or removed it in between, or the version to restore is another), so it was neither written nor deleted — what is there now stays; rewind again (a preview first) to restore it as it now stands";
1318
1382
  const PLAN_READS = new Set(["absolutePath", "joinPath", "readTextFile", "readTextLines", "readBinaryFile", "fileInfo", "listDir", "canonicalPath", "readLink", "canonicalChain", "fileIdentity", "openBound", "exists"]);
1319
1383
  const PLAN_MUTATIONS = { writeFile: "write", writeFileGuarded: "write", writeFileExclusive: "write", appendFile: "write", remove: "delete", setFileMode: "mode", createDir: "none" };
1320
- function envViewOf(env, perform, holds) {
1384
+ function envViewOf(env, perform, holds, planned) {
1321
1385
  const mutations = [];
1322
1386
  const held = [];
1323
1387
  const reals = new Map();
1388
+ const asked = { issued: 0, done: 0 };
1389
+ const states = new Map();
1390
+ const occurrences = new Map();
1324
1391
  const view = new Proxy(env, {
1325
1392
  get(target, prop, receiver) {
1393
+ if (prop === PLANNED_STATE_SEAT) {
1394
+ return (at, state) => {
1395
+ const n = occurrences.get(at) ?? 0;
1396
+ occurrences.set(at, n + 1);
1397
+ const slot = `${at}\u0000${n}`;
1398
+ if (!perform) {
1399
+ states.set(slot, state);
1400
+ return false;
1401
+ }
1402
+ if (planned === undefined)
1403
+ return false;
1404
+ const real = reals.get(at);
1405
+ if (real !== undefined && mutations.some((m) => m.real !== undefined && foldedFile(m.real) === foldedFile(real)))
1406
+ return false;
1407
+ return planned.get(slot) !== state;
1408
+ };
1409
+ }
1326
1410
  if (prop === REAL_PATH_SEAT) {
1327
1411
  return (at, real) => {
1328
1412
  const hold = holds?.get(foldedFile(real));
@@ -1357,22 +1441,34 @@ function envViewOf(env, perform, holds) {
1357
1441
  if (kind !== "none" && holds !== undefined && holds.size > 0 && typeof at === "string" && !reals.has(at)) {
1358
1442
  return Promise.resolve({ ok: false, error: { code: "precondition_failed", message: `a rewind that holds files a frozen history names performs no write it cannot place, and this one (${at}) did not state where it lands` } });
1359
1443
  }
1444
+ asked.issued++;
1360
1445
  return Promise.resolve(fn.apply(target, args)).then((r) => {
1361
- if (r !== null && typeof r === "object" && r.ok === true)
1446
+ if (r !== null && typeof r === "object" && r.ok === true) {
1447
+ asked.done++;
1362
1448
  note();
1449
+ }
1450
+ else if (prop === "writeFileGuarded" && readMember(readMember(r, "error"), "code") === "precondition_failed") {
1451
+ asked.issued--;
1452
+ }
1363
1453
  return r;
1364
1454
  });
1365
1455
  };
1366
1456
  }
1367
- if (perform || PLAN_READS.has(prop))
1457
+ if (PLAN_READS.has(prop))
1368
1458
  return fn.bind(target);
1459
+ if (perform) {
1460
+ return (...args) => {
1461
+ asked.issued++;
1462
+ return fn.apply(target, args);
1463
+ };
1464
+ }
1369
1465
  return () => Promise.resolve({ ok: false, error: { code: "unsupported", message: `a planned restore reached ${prop}, which a plan does not perform` } });
1370
1466
  },
1371
1467
  });
1372
- return { env: view, mutations, held, told: reals };
1468
+ return { env: view, mutations, held, told: reals, asked, states };
1373
1469
  }
1374
- export function witnessEnvOf(env, holds) {
1375
- return envViewOf(env, true, holds);
1470
+ export function witnessEnvOf(env, holds, planned) {
1471
+ return envViewOf(env, true, holds, planned);
1376
1472
  }
1377
1473
  function oldRootOf(place, key) {
1378
1474
  const dirs = relativeInEveryFamily(key) ? key.split("/").length - 1 : 0;
@@ -1471,9 +1567,10 @@ export function withRewindFiles(storeAnswer, seen, root) {
1471
1567
  return { ...ledger, ...(leftAsIs !== undefined ? { leftAsIs } : {}), files };
1472
1568
  }
1473
1569
  export async function planFileHistoryRestore(store, input) {
1570
+ const options = restoreOptionsAt(input.options, input.root);
1474
1571
  const pass = async (holds) => {
1475
1572
  const planning = envViewOf(input.env, false, holds);
1476
- const restored = await store.restore(input.scope, input.entryId, planning.env, input.root, input.signal, input.options);
1573
+ const restored = await store.restore(input.scope, input.entryId, planning.env, input.root, input.signal, options);
1477
1574
  return { planning, stored: restored, answered: withRewindFiles(restored, planning, input.root) };
1478
1575
  };
1479
1576
  const first = await pass(undefined);
@@ -1515,6 +1612,7 @@ export async function planFileHistoryRestore(store, input) {
1515
1612
  restore: answered,
1516
1613
  diffStats: { filesChanged: answered.filesChanged, insertions, deletions, files: answered.files, refused: answered.refused, failed: answered.failed, ...(answered.leftAsIs !== undefined && answered.leftAsIs.length > 0 ? { leftAsIs: answered.leftAsIs } : {}) },
1517
1614
  holds,
1615
+ states: planning.states,
1518
1616
  ...(unread ? { unheld: [...new Set([...holds.values()].flatMap((h) => h.frozenKeys))].sort() } : {}),
1519
1617
  changes,
1520
1618
  };
@@ -1,4 +1,4 @@
1
- import { inlineUntrusted, PROBE_REASON_MAX } from "./untrusted-text.js";
1
+ import { inlineUntrusted, inlineUntrustedAtWord, PROBE_REASON_MAX } from "./untrusted-text.js";
2
2
  import { markTightenMessage } from "./safety-axis-vocab.js";
3
3
  import { normalizeProbeCause } from "./checkpoint-features.js";
4
4
  import { normalizeReadRootCandidate } from "./read-root-candidate.js";
@@ -10,7 +10,7 @@ import { createGateDeadline, awaitWriteProtectionJudgment, gateWaitFailureOf, wi
10
10
  import { shellReadFaceWords } from "../tools/fs/shell-read-face.js";
11
11
  import { failedJudgmentDeny } from "./runner/policy-throw.js";
12
12
  import { thrownText } from "./thrown-value.js";
13
- import { argsAsTheToolReads } from "./effective-path-target.js";
13
+ import { argsAsTheToolReads, movedCallReading, stampedCallOf } from "./effective-path-target.js";
14
14
  import { foldHookAsk, refuseOutOfContractDecision } from "./tool-policy.js";
15
15
  import { sandboxOverrideMessage, withChainAskReasons, withProbeMandate } from "./ask-origin.js";
16
16
  import { applyUnansweredSilence, readStationAnswer, silencedBy } from "./shell-read-silence.js";
@@ -23,14 +23,20 @@ export async function runGateFold(pass) {
23
23
  pass.req = Object.freeze({ toolName, args: pass.currentInput, toolCallId, ...(pass.req.face !== undefined ? { face: pass.req.face } : {}) });
24
24
  let unread;
25
25
  try {
26
- const stamped = input.stampCallTarget?.(pass.req, callSignal ?? input.abortSignal);
27
- if (stamped !== undefined)
28
- pass.req = Object.freeze(await stamped);
26
+ const given = pass.req;
27
+ const stamped = input.stampCallTarget?.(given, callSignal ?? input.abortSignal);
28
+ if (stamped !== undefined) {
29
+ const read = stampedCallOf(given, await stamped);
30
+ if (read.moved === undefined)
31
+ pass.req = Object.freeze(read.req);
32
+ else
33
+ unread = movedCallReading(read.moved);
34
+ }
29
35
  }
30
36
  catch (error) {
31
37
  unread = { error };
32
38
  }
33
- pass.decision = unread !== undefined ? failedJudgmentDeny(unread.error, callSignal ?? input.abortSignal, (e) => traceHookCrash(input, e, notifier), "the call's target reading", { toolName, toolCallId }) : adjudicate ? refuseOutOfContractDecision(await (callSignal !== undefined ? adjudicate(pass.req, callSignal) : adjudicate(pass.req)), { call: pass.req }) : { action: "allow" };
39
+ pass.decision = unread !== undefined ? failedJudgmentDeny(unread.error, callSignal ?? input.abortSignal, (e) => traceHookCrash(input, e, notifier), "the call's target reading", { toolName, toolCallId }, unread.said) : adjudicate ? refuseOutOfContractDecision(await (callSignal !== undefined ? adjudicate(pass.req, callSignal) : adjudicate(pass.req)), { call: pass.req }) : { action: "allow" };
34
40
  {
35
41
  const read = ledger.fromDecision(pass.decision);
36
42
  pass.decision = read.decision;
@@ -225,7 +231,7 @@ function applyShellReadVerdict(pass, answer, toolName, shellGated) {
225
231
  }
226
232
  function applyStationDisposition(pass, reading, toolName, shellGated) {
227
233
  const verdict = reading.verdict;
228
- const account = verdict.sentence !== undefined && verdict.sentence.trim().length > 0 ? inlineUntrusted(verdict.sentence, PROBE_REASON_MAX) : undefined;
234
+ const account = verdict.sentence !== undefined && verdict.sentence.trim().length > 0 ? inlineUntrustedAtWord(verdict.sentence, PROBE_REASON_MAX) : undefined;
229
235
  if (verdict.writesPlaced === true)
230
236
  pass.shellWritesPlaced = true;
231
237
  if (verdict.writeProtected === true)
@@ -1,13 +1,13 @@
1
1
  import { argsAsTheToolReads, withArgsReading } from "./effective-path-target.js";
2
2
  import { boundListGrantOf, boundStoredGrantOf, standsOnWholePeerRow, unboundGrantOf } from "./a2a-bound-grant.js";
3
- import { attest, attestationOf, bindableArgsOf, decisionText, foldHookAsk, refusalOf, refuseOutOfContractDecision } from "./tool-policy.js";
4
- import { APPROVER_AUTHOR, extensionAuthors, noteRewrite, outletAsk, POLICY_AUTHOR, readRejudge, rewriteChasedSentence, screenRewrite } from "./rewrite-rejudge.js";
3
+ import { attest, attestationOf, bindableArgsOf, decisionText, foldHookAsk, receivedResolution, refusalOf, refuseOutOfContractDecision } from "./tool-policy.js";
4
+ import { answerAsShown, APPROVER_AUTHOR, extensionAuthors, shownDigestOf, noteRewrite, outletAsk, POLICY_AUTHOR, readRejudge, rewriteChasedSentence, screenRewrite } from "./rewrite-rejudge.js";
5
5
  import { allowMayClearOn, arbitrateByMode, boundGrantMayClear, askClassMembersOf, askReasonsOf, classifyAsk, joinAskReasons, decisionAskClassesOf, dontAskRefusalMessage, fileCommandOptionsSentence, persistedRuleMandateOf, safetyAxisOf, stampAskOrigin, withChainAskReasons, withFoldedOf } from "./ask-origin.js";
6
6
  import { classifierParseFailureDenyMessage, classifierSaidOf, classifierSaidTail, denialLimitFallbackAsk, rungDidNotRule, unarmedWindow, verdictSpendRefusal } from "./auto-mode.js";
7
7
  import { classifierNoRulingArm, settleNoRulingAsk } from "./classifier-unavailable-arm.js";
8
8
  import { SETTLEMENT_NOBODY_JUDGED } from "./gate-outcome.js";
9
9
  import { inlineUntrusted } from "./untrusted-text.js";
10
- import { ASK_USER_QUESTION_TOOL_NAME, CONTENT_ASK_NOT_SHOWN, isEngineQuestionFace, questionToolAsk } from "./ask-question.js";
10
+ import { ASK_USER_QUESTION_TOOL_NAME, contentAskNotShownMessage, isEngineQuestionFace, questionToolAsk } from "./ask-question.js";
11
11
  import { routesContent } from "./tool-catalog-entries.js";
12
12
  import { applyPersistedTightening, disclosedRuleSet } from "./persisted-rule-arms.js";
13
13
  import { skillAllowDecision, skillRowRefusal } from "./skill-grant.js";
@@ -77,7 +77,7 @@ export async function runGateLanes(pass) {
77
77
  return undefined;
78
78
  const suspended = await parkWith(suspendAsk, [req, args, safety, liveFaceUnavailable, realApprovalOf(d, org), d.allowRuleShadowed, d.decisionReason, d.probeReason, d.probeCause, d.segmentCoverage, d.matchedAskRule, d.probeMandated], carryOf(d, req));
79
79
  if (suspended && "parkFailed" in suspended)
80
- pass.parkFailed = suspended.parkFailed;
80
+ (pass.parkFailed = suspended.parkFailed), (pass.parkFailedReason = suspended.parkFailedReason);
81
81
  return suspended && !("parkFailed" in suspended) ? { suspend: suspended, preToolContext: pass.preToolContext } : undefined;
82
82
  };
83
83
  const landingOf = (req) => {
@@ -93,7 +93,7 @@ export async function runGateLanes(pass) {
93
93
  if (ask.origin === undefined)
94
94
  throw new Error(`the content ask for "${toolName}" reached its refusal without an origin word`);
95
95
  ledger.set({ settlement: { kind: input.resolveContentAsk !== undefined ? "approver_unavailable" : "no_approver", who: { party: "none" }, when: Date.now() }, origin: ask.origin });
96
- return { action: "deny", message: input.notResumable !== undefined ? questionNotShownOnLeg(input.notResumable, input.resolveContentAsk !== undefined) : CONTENT_ASK_NOT_SHOWN };
96
+ return { action: "deny", message: input.notResumable !== undefined ? questionNotShownOnLeg(input.notResumable, input.resolveContentAsk !== undefined) : contentAskNotShownMessage(pass.parkFailed === undefined && pass.parkTargetGap !== undefined) };
97
97
  };
98
98
  const markedUnresolvable = () => (markedThisRound ??= input.isMarkedUnresolvable?.(input.event.toolCallId) === true);
99
99
  const mandateMarksNow = () => ({
@@ -550,11 +550,11 @@ export async function runGateLanes(pass) {
550
550
  let askBeforeResolve = pass.decision;
551
551
  const delivery = deliveredCall(pass.req);
552
552
  const resolveOnce = (d) => (callSignal !== undefined ? resolveAsk(d, delivery, callSignal) : resolveAsk(d, delivery));
553
- let resolved = await resolveOnce(askBeforeResolve);
553
+ let resolved = answerAsShown(shownDigestOf(delivery), receivedResolution(await resolveOnce(askBeforeResolve), toolName), delivery);
554
554
  const refallback = settleNoRulingAsk({ ask: askBeforeResolve, mintedHere: noRulingMinted, resolved: { action: resolved.action, settlement: attestationOf(resolved, pass.req)?.settlement }, tracker: input.autoMode?.denialTracking });
555
555
  if (refallback !== undefined && askBeforeResolve.action === "ask") {
556
556
  askBeforeResolve = fallbackAskOf(askBeforeResolve, refallback, toolName);
557
- resolved = await resolveOnce(askBeforeResolve);
557
+ resolved = answerAsShown(shownDigestOf(delivery), receivedResolution(await resolveOnce(askBeforeResolve), toolName), delivery);
558
558
  }
559
559
  resolved = ledger.fromResolved(resolved, askBeforeResolve, pass.req);
560
560
  if (resolved.action === "deny")
@@ -844,7 +844,7 @@ export async function runGateLanes(pass) {
844
844
  break;
845
845
  }
846
846
  const editDelivery = deliveredCall(editAskReq);
847
- const rr = ledger.fromResolved(await (callSignal !== undefined ? resolveAsk(editAskDecision, editDelivery, callSignal) : resolveAsk(editAskDecision, editDelivery)), editAskDecision, editAskReq);
847
+ const rr = ledger.fromResolved(answerAsShown(shownDigestOf(editDelivery), receivedResolution(await (callSignal !== undefined ? resolveAsk(editAskDecision, editDelivery, callSignal) : resolveAsk(editAskDecision, editDelivery)), toolName), editDelivery), editAskDecision, editAskReq);
848
848
  if (rr.action !== "allow") {
849
849
  refusedAtResolution(rr);
850
850
  if (rewrittenEdit)
@@ -895,7 +895,7 @@ export async function runGateLanes(pass) {
895
895
  }
896
896
  if (unanswered !== undefined && unanswered.deny === undefined && editDenied === undefined) {
897
897
  const marked = deliveredCall(unanswered.req);
898
- refusedAtResolution(ledger.fromResolved(await (callSignal !== undefined ? resolveAsk(unanswered.ask, marked, callSignal) : resolveAsk(unanswered.ask, marked)), unanswered.ask, unanswered.req));
898
+ refusedAtResolution(ledger.fromResolved(answerAsShown(shownDigestOf(marked), receivedResolution(await (callSignal !== undefined ? resolveAsk(unanswered.ask, marked, callSignal) : resolveAsk(unanswered.ask, marked)), toolName), marked), unanswered.ask, unanswered.req));
899
899
  }
900
900
  pass.decision = editDenied !== undefined ? refusalOf(editDenied, editArgs) : { ...pass.decision, updatedInput: editArgs };
901
901
  }