@sema-agent/core 7.70.0 → 7.71.1

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 (439) hide show
  1. package/CHANGELOG.md +740 -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 +21 -7
  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 +69 -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 +39 -21
  344. package/dist/index.js +32 -17
  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 +173 -15
  426. package/wire-changes/core-stores-sql@7.71.0.json +40 -0
  427. package/wire-changes/core-stores-sql@7.71.1.json +40 -0
  428. package/wire-changes/core@7.71.0.json +5827 -0
  429. package/wire-changes/core@7.71.1.json +118 -0
  430. package/wire-changes/mods-kernel@7.71.0.json +52 -0
  431. package/wire-changes/mods-kernel@7.71.1.json +40 -0
  432. package/wire-changes/primitives@7.71.0.json +473 -0
  433. package/wire-changes/primitives@7.71.1.json +40 -0
  434. package/wire-changes/wiki-gate@7.71.0.json +40 -0
  435. package/wire-changes/wiki-gate@7.71.1.json +40 -0
  436. package/dist/core/frontmatter-fence.d.ts +0 -10
  437. package/dist/core/frontmatter-fence.js +0 -6
  438. package/dist/core/permission-rule-syntax.d.ts +0 -46
  439. package/dist/core/permission-rule-syntax.js +0 -52
@@ -0,0 +1,524 @@
1
+ import { createHash } from "node:crypto";
2
+ import { posix } from "node:path";
3
+ import { canonicalJsonStringify } from "./canonical-json.js";
4
+ import { BARE_INTERPRETER_NAMES, COMMAND_RULE_TOOL, foldSpacing, formatRuleText, pathWithinRoot } from "./permission-rule-model.js";
5
+ import { readShellCommand } from "./shell-run-candidates.js";
6
+ import { thrownText } from "./thrown-value.js";
7
+ import { shellWordsOf } from "../shell/shell-words.js";
8
+ import { strayMembersOf } from "./own-property-receipt.js";
9
+ export const CALL_GRANT_MATCH = "call";
10
+ const MAX_COMMAND_CHARS = 4000;
11
+ const MAX_SEGMENTS = 8;
12
+ const MAX_SCRIPT_BYTES = 1024 * 1024;
13
+ const MAX_TREE_ENTRIES = 2000;
14
+ const MAX_TREE_FILES = 300;
15
+ const MAX_TREE_BYTES = 8 * 1024 * 1024;
16
+ const INTERPRETERS = Object.freeze({
17
+ node: { inline: ["-e", "--eval", "-p", "--print"], sources: [".js", ".mjs", ".cjs", ".json", ".node"], subcommands: ["inspect"] },
18
+ python: { inline: ["-c"], sources: [".py"] },
19
+ python2: { inline: ["-c"], sources: [".py"] },
20
+ python3: { inline: ["-c"], sources: [".py"] },
21
+ ruby: { inline: ["-e"], sources: [".rb"] },
22
+ perl: { inline: ["-e", "-E"], sources: [".pl", ".pm"] },
23
+ php: { inline: ["-r"], sources: [".php"] },
24
+ });
25
+ const RUNNER_NAMES = new Set([...Object.keys(INTERPRETERS), ...BARE_INTERPRETER_NAMES].map((n) => n.toLowerCase()));
26
+ const runnerRowOf = (name) => {
27
+ const folded = name.toLowerCase();
28
+ const bare = folded.replace(/[0-9][0-9.]*[a-z]*$/, "");
29
+ return RUNNER_NAMES.has(folded) || RUNNER_NAMES.has(bare) ? bare : undefined;
30
+ };
31
+ const OTHER_BUILTINS = new Set([
32
+ "alias", "bg", "bind", "break", "builtin", "caller", "command", "compgen", "complete", "compopt", "continue", "declare", "disown", "enable",
33
+ "eval", "exec", "exit", "export", "fc", "fg", "getopts", "hash", "help", "history", "jobs", "kill", "let", "local", "logout", "mapfile",
34
+ "read", "readarray", "readonly", "return", "set", "shift", "shopt", "source", ".", "suspend", "times", "trap", "type", "typeset",
35
+ "ulimit", "umask", "unalias", "unset", "wait",
36
+ ]);
37
+ const STACK_WORDS = new Set([...shellWordsOf("stack_mover"), ...shellWordsOf("stack_editor")]);
38
+ const PRINTF_ASSIGNS = /%[-+ #'0-9.*hlLqjzt]*n/;
39
+ const PLAIN_BUILTINS = new Set(["echo", "printf", "test", "[", "true", "false", "pwd", ":"]);
40
+ const CONNECTORS = new Set(["&&", "||", ";", "|"]);
41
+ const FILE_REDIRECTIONS = new Set([">", ">>", "<", ">|", "&>", "&>>", "<>"]);
42
+ const DESCRIPTOR_REDIRECTIONS = new Set([">&", "<&"]);
43
+ const HOLE_WORD = /^[A-Za-z0-9._@%+,/][A-Za-z0-9._@%+,/-]*$/;
44
+ const sha256 = (data) => createHash("sha256").update(data).digest("hex");
45
+ export function callGrantCommandOf(binding) {
46
+ return canonicalJsonStringify(binding);
47
+ }
48
+ export function callGrantRuleTextOf(command) {
49
+ return formatRuleText(command, CALL_GRANT_MATCH, COMMAND_RULE_TOOL);
50
+ }
51
+ const no = (unbindable) => ({ unbindable });
52
+ const isAbs = (p) => p.startsWith("/");
53
+ const under = (at, word) => (isAbs(word) ? word : at === "/" ? `/${word}` : `${at}/${word}`);
54
+ const hasClimb = (word) => word.split("/").includes("..");
55
+ const inRoots = (path, roots) => roots.some((r) => pathWithinRoot(path, r));
56
+ async function canonical(seat, path, signal) {
57
+ const r = await seat.env.canonicalPath(path, signal);
58
+ if (r.ok)
59
+ return isAbs(r.value) ? { real: r.value } : no("a path resolved to no absolute path");
60
+ return r.error.code === "not_found" ? { missing: true } : no(`a path could not be resolved (${r.error.code})`);
61
+ }
62
+ async function programFileOf(seat, real, signal) {
63
+ const info = await seat.env.fileInfo(real, signal);
64
+ if (!info.ok)
65
+ return no(`a program file could not be read (${info.error.code})`);
66
+ if (info.value.kind !== "file")
67
+ return "not_executable";
68
+ if (info.value.mode === undefined)
69
+ return no("the environment does not say a program file's permission bits");
70
+ if ((info.value.mode & 0o111) === 0)
71
+ return "not_executable";
72
+ if (seat.env.fileIdentity === undefined)
73
+ return no("the environment cannot say a file's identity");
74
+ const id = await seat.env.fileIdentity(real, signal);
75
+ if (!id.ok)
76
+ return no(`a program file's identity could not be read (${id.error.code})`);
77
+ return { path: real, id: id.value, size: info.value.size, mtimeMs: info.value.mtimeMs };
78
+ }
79
+ async function programOf(seat, word, at, searchPath, signal) {
80
+ const candidates = word.includes("/") ? [under(at, word)] : searchPath.map((e) => under(e === "" ? at : under(at, e), word));
81
+ for (const c of candidates) {
82
+ const real = await canonical(seat, c, signal);
83
+ if ("unbindable" in real)
84
+ return real;
85
+ if ("missing" in real)
86
+ continue;
87
+ const file = await programFileOf(seat, real.real, signal);
88
+ if (file === "not_executable")
89
+ continue;
90
+ return file;
91
+ }
92
+ return no(`the program ${JSON.stringify(word)} resolves to no executable file`);
93
+ }
94
+ async function sourceTreeOf(seat, dir, sources, signal) {
95
+ const lines = [];
96
+ const files = [];
97
+ const stack = [dir];
98
+ let entries = 0;
99
+ while (stack.length > 0) {
100
+ const d = stack.pop();
101
+ const listed = await seat.env.listDir(d, signal);
102
+ if (!listed.ok)
103
+ return no(`the script's directory could not be listed (${listed.error.code})`);
104
+ for (const e of [...listed.value].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
105
+ if (++entries > MAX_TREE_ENTRIES)
106
+ return no(`the script's directory tree holds more than ${MAX_TREE_ENTRIES} entries`);
107
+ const rel = posix.relative(dir, e.path);
108
+ if (e.kind === "directory")
109
+ stack.push(e.path);
110
+ else if (e.kind === "symlink") {
111
+ if (seat.env.readLink === undefined)
112
+ return no("the environment cannot read a link in the script's directory tree");
113
+ const t = await seat.env.readLink(e.path, signal);
114
+ if (!t.ok)
115
+ return no(`a link in the script's directory tree could not be read (${t.error.code})`);
116
+ lines.push(`L ${rel} ${t.value}`);
117
+ if (sources.some((x) => e.name.endsWith(x)))
118
+ files.push({ rel, path: e.path });
119
+ }
120
+ else if (sources.some((x) => e.name.endsWith(x)))
121
+ files.push({ rel, path: e.path });
122
+ }
123
+ }
124
+ if (files.length > MAX_TREE_FILES)
125
+ return no(`the script's directory tree holds more than ${MAX_TREE_FILES} source files`);
126
+ let total = 0;
127
+ for (const f of files) {
128
+ const bytes = await seat.env.readBinaryFile(f.path, signal, MAX_SCRIPT_BYTES + 1);
129
+ if (!bytes.ok)
130
+ return no(`a source file beside the script could not be read (${bytes.error.code})`);
131
+ total += bytes.value.length;
132
+ if (bytes.value.length > MAX_SCRIPT_BYTES || total > MAX_TREE_BYTES)
133
+ return no("the source files beside the script are past the size bound");
134
+ lines.push(`F ${f.rel} ${sha256(bytes.value)}`);
135
+ }
136
+ return sha256(lines.sort().join("\n"));
137
+ }
138
+ const literal = (w) => w !== undefined && w.expands === false;
139
+ const GAP = /^((?:[ \t\n]|&&|\|\||;|\|)*)(?:(\d*)(&>>|&>|>>|>&|>\||<>|<&|>|<)[ \t]*)?/;
140
+ const LEADING = /^[ \t\n]*$/;
141
+ function pieceNotCarried(command, shape) {
142
+ const notSeen = "a piece this reading does not see as a run (a test, `!`, an arithmetic command, a comment)";
143
+ let at = 0;
144
+ const gap = () => {
145
+ const g = GAP.exec(command.slice(at));
146
+ at += g[0].length;
147
+ return g;
148
+ };
149
+ for (const s of shape.segments) {
150
+ let w = 0;
151
+ let t = 0;
152
+ while (w < s.argv.length || t < s.redirections.length) {
153
+ const first = at === 0;
154
+ const g = gap();
155
+ if (first && !LEADING.test(g[0]))
156
+ return "a command that does not start with its program word";
157
+ if (g[2] !== "" && g[2] !== undefined && g[1] === "")
158
+ return notSeen;
159
+ const target = g[3] !== undefined;
160
+ if (target ? t >= s.redirections.length : w >= s.argv.length)
161
+ return notSeen;
162
+ const next = target ? s.redirections[t++].target.raw : s.argv[w++].raw;
163
+ if (next === "" || !command.startsWith(next, at))
164
+ return notSeen;
165
+ at += next.length;
166
+ }
167
+ }
168
+ const tail = gap();
169
+ return tail[3] === undefined && at === command.length ? undefined : notSeen;
170
+ }
171
+ function structuralRefusal(command, shape) {
172
+ if (shape.stopped !== undefined)
173
+ return "the command could not be read whole";
174
+ if (shape.grouped)
175
+ return "a group, subshell, control structure or function definition";
176
+ if (shape.backgrounded)
177
+ return "a background job";
178
+ if (shape.strayRedirection)
179
+ return "a redirection on a piece that runs no program";
180
+ if (shape.segments.length === 0 || shape.segments.length > MAX_SEGMENTS)
181
+ return `not 1 – ${MAX_SEGMENTS} runs`;
182
+ if (shape.connectors.some((c) => !CONNECTORS.has(c)))
183
+ return "a connector other than && || ; |";
184
+ for (const s of shape.segments) {
185
+ if (s.unreadable !== undefined || s.peelUnreadable !== undefined)
186
+ return "a run whose program cannot be named";
187
+ if (s.peeled.length > 0)
188
+ return "an assignment, wrapper or launcher in front of a program";
189
+ if (s.substituted !== undefined)
190
+ return "a substitution";
191
+ if (s.argv.length === 0 || !s.argv.every(literal))
192
+ return "an expansion in a run";
193
+ if (!s.redirections.every((r) => literal(r.target)))
194
+ return "an expansion in a redirection";
195
+ }
196
+ return pieceNotCarried(command, shape);
197
+ }
198
+ async function readCall(command, seat, holes, signal) {
199
+ if (typeof command !== "string" || command.length > MAX_COMMAND_CHARS)
200
+ return no("no command text within the bound");
201
+ if (command.includes("\\"))
202
+ return no("a backslash in the command");
203
+ const folded = foldSpacing(command);
204
+ if (folded === undefined)
205
+ return no("unbalanced quoting");
206
+ const shape = readShellCommand(command);
207
+ const refusal = structuralRefusal(command, shape);
208
+ if (refusal !== undefined)
209
+ return no(refusal);
210
+ const names = seat.env.receivedEnvNames;
211
+ if (names === undefined)
212
+ return no("the environment does not say which variables its shell child receives");
213
+ if (names.includes("BASH_ENV") || names.includes("ENV"))
214
+ return no("the shell child receives BASH_ENV or ENV (a file it runs first)");
215
+ if (seat.cwd === undefined || !isAbs(seat.cwd))
216
+ return no("no working directory");
217
+ const start = await canonical(seat, seat.cwd, signal);
218
+ if (!("real" in start))
219
+ return no("the working directory could not be resolved");
220
+ const declared = seat.env.searchPath;
221
+ const searchPath = Array.isArray(declared) ? declared : undefined;
222
+ const moves = shape.segments.some((s) => s.argv[0].text === "cd");
223
+ if (moves) {
224
+ const cdPath = seat.env.cdPath;
225
+ if (!Array.isArray(cdPath) || cdPath.length > 0)
226
+ return no("a cd while CDPATH is set or unknown");
227
+ if (searchPath?.some((e) => !isAbs(e)) === true)
228
+ return no("a cd while the search path holds a relative entry");
229
+ const isCd = (k) => shape.segments[k].argv[0].text === "cd";
230
+ if (shape.connectors.some((c, k) => c !== "&&" && !(c === "|" && !isCd(k) && !isCd(k + 1))))
231
+ return no("a cd bash may skip, or that does not move every run after it");
232
+ }
233
+ let at = start.real;
234
+ const segments = [];
235
+ let candidates = [];
236
+ let scriptRun = false;
237
+ for (let i = 0; i < shape.segments.length; i++) {
238
+ const s = shape.segments[i];
239
+ const head = s.argv[0].text;
240
+ if (head === "" || head.includes("="))
241
+ return no("an assignment");
242
+ if (OTHER_BUILTINS.has(head))
243
+ return no(`the builtin ${head} is no plain builtin`);
244
+ if (head === "printf" && (s.argv[1]?.text.startsWith("-") === true || PRINTF_ASSIGNS.test(s.argv[1]?.text ?? "")))
245
+ return no("printf that sets a variable (`-v`, `%n`)");
246
+ if (STACK_WORDS.has(head))
247
+ return no(`the builtin ${head} moves through the directory stack`);
248
+ const writes = [];
249
+ for (const r of s.redirections) {
250
+ if (FILE_REDIRECTIONS.has(r.op)) {
251
+ const abs = under(at, r.target.text);
252
+ const real = await canonical(seat, abs, signal);
253
+ if ("unbindable" in real)
254
+ return real;
255
+ if ("real" in real)
256
+ writes.push(real.real);
257
+ else {
258
+ const link = await seat.env.readLink?.(abs, signal);
259
+ if (link === undefined || link.ok || link.error.code !== "not_found")
260
+ return no("a redirection target that may be a link leading nowhere");
261
+ const parent = await canonical(seat, posix.dirname(abs), signal);
262
+ if (!("real" in parent))
263
+ return no("a redirection target's directory could not be resolved");
264
+ writes.push(posix.join(parent.real, posix.basename(abs)));
265
+ }
266
+ }
267
+ else if (DESCRIPTOR_REDIRECTIONS.has(r.op)) {
268
+ if (!/^(\d+|-)$/.test(r.target.text))
269
+ return no("a descriptor redirection onto a file");
270
+ }
271
+ else
272
+ return no(`the redirection ${r.op}`);
273
+ }
274
+ if (head === "cd") {
275
+ if (s.argv.length !== 2 || s.redirections.length > 0)
276
+ return no("a cd other than one literal directory");
277
+ const target = s.argv[1].text;
278
+ if (target === "" || target.startsWith("-") || hasClimb(target))
279
+ return no("a cd other than one literal directory");
280
+ segments.push({ at, program: { builtin: "cd" }, writes });
281
+ const moved = await canonical(seat, under(at, target), signal);
282
+ if (!("real" in moved))
283
+ return no("a cd target could not be resolved");
284
+ const info = await seat.env.fileInfo(moved.real, signal);
285
+ if (!info.ok || info.value.kind !== "directory")
286
+ return no("a cd target that is no directory");
287
+ at = moved.real;
288
+ continue;
289
+ }
290
+ if (PLAIN_BUILTINS.has(head)) {
291
+ segments.push({ at, program: { builtin: head }, writes });
292
+ continue;
293
+ }
294
+ const base = posix.basename(head);
295
+ const interpreter = Object.hasOwn(INTERPRETERS, base) ? INTERPRETERS[base] : undefined;
296
+ if (interpreter === undefined && BARE_INTERPRETER_NAMES.has(base))
297
+ return no(`${base} runs another program or shell code this reading does not bind`);
298
+ if (!head.includes("/") && searchPath === undefined)
299
+ return no("the environment declares no search path for a bare program name");
300
+ const program = await programOf(seat, head, at, searchPath ?? [], signal);
301
+ if ("unbindable" in program)
302
+ return program;
303
+ const rows = [runnerRowOf(base), runnerRowOf(posix.basename(program.path))];
304
+ if (interpreter === undefined ? rows.some((r) => r !== undefined) : rows[1] !== undefined && rows[1] !== rows[0])
305
+ return no(`${base} is an interpreter, shell or launcher under another name`);
306
+ if (interpreter === undefined) {
307
+ segments.push({ at, program, writes });
308
+ continue;
309
+ }
310
+ const first = s.argv[1];
311
+ if (first === undefined)
312
+ return no("an interpreter with no code");
313
+ if (interpreter.inline.includes(first.text)) {
314
+ const code = s.argv[2];
315
+ if (code === undefined)
316
+ return no("an inline-code flag with no code");
317
+ segments.push({ at, program, inline: sha256(code.text), writes });
318
+ continue;
319
+ }
320
+ if (first.text.startsWith("-") || first.text === "")
321
+ return no("an interpreter option this reading does not bind");
322
+ if (interpreter.subcommands?.includes(first.text) === true)
323
+ return no(`the interpreter subcommand ${first.text}`);
324
+ if (hasClimb(first.text))
325
+ return no("a script path through `..`");
326
+ const scriptAbs = under(at, first.text);
327
+ const script = await canonical(seat, scriptAbs, signal);
328
+ if (!("real" in script))
329
+ return no("the script could not be resolved");
330
+ if (!inRoots(script.real, seat.roots))
331
+ return no("the script lies outside the workspace roots");
332
+ const info = await seat.env.fileInfo(script.real, signal);
333
+ if (!info.ok || info.value.kind !== "file")
334
+ return no("the script is no regular file");
335
+ const bytes = await seat.env.readBinaryFile(script.real, signal, MAX_SCRIPT_BYTES + 1);
336
+ if (!bytes.ok || bytes.value.length > MAX_SCRIPT_BYTES)
337
+ return no("the script could not be read within the bound");
338
+ const tree = await sourceTreeOf(seat, posix.dirname(script.real), interpreter.sources, signal);
339
+ if (typeof tree !== "string")
340
+ return tree;
341
+ segments.push({ at, program, script: { path: script.real, sha256: sha256(bytes.value), tree }, writes });
342
+ if (shape.segments.length === 1 && s.redirections.length === 0) {
343
+ scriptRun = true;
344
+ for (let k = 2; k < s.argv.length; k++) {
345
+ const w = s.argv[k];
346
+ if (w.raw !== w.text || !HOLE_WORD.test(w.text) || hasClimb(w.text))
347
+ continue;
348
+ const real = await canonical(seat, under(at, w.text), signal);
349
+ if ("unbindable" in real)
350
+ return real;
351
+ if (!("real" in real) || !inRoots(real.real, seat.roots))
352
+ continue;
353
+ const f = await seat.env.fileInfo(real.real, signal);
354
+ if (f.ok && f.value.kind === "file")
355
+ candidates.push({ at: k, real: real.real });
356
+ }
357
+ }
358
+ }
359
+ let chosen;
360
+ if (holes === "choose")
361
+ chosen = candidates;
362
+ else {
363
+ if (holes.length > 0 && !scriptRun)
364
+ return no("the call is not the single script run its grant masks");
365
+ chosen = [];
366
+ for (const h of holes) {
367
+ const c = candidates.find((x) => x.at === h);
368
+ if (c === undefined)
369
+ return no("a masked operand names no file inside the roots");
370
+ chosen.push(c);
371
+ }
372
+ }
373
+ const argv = shape.segments[0].argv;
374
+ const digest = chosen.length > 0 ? sha256(canonicalJsonStringify({ argv: argv.map((w, k) => (chosen.some((c) => c.at === k) ? null : w.raw)) })) : sha256(folded);
375
+ const binding = {
376
+ v: 1,
377
+ cwd: start.real,
378
+ form: chosen.length > 0 ? "argv" : "text",
379
+ digest,
380
+ segments,
381
+ holes: chosen.map((c) => ({ at: c.at, dir: posix.dirname(c.real) })),
382
+ };
383
+ return { binding, holeReals: chosen.map((c) => c.real) };
384
+ }
385
+ export async function bindCall(command, seat, signal) {
386
+ try {
387
+ const read = await readCall(command, seat, "choose", signal);
388
+ return "unbindable" in read ? read : read.binding;
389
+ }
390
+ catch (err) {
391
+ return no(`the call could not be read (${thrownText(err)})`);
392
+ }
393
+ }
394
+ export async function callGrantAdmits(binding, command, seat, signal) {
395
+ try {
396
+ const read = await readCall(command, seat, binding.holes.map((h) => h.at), signal);
397
+ if ("unbindable" in read)
398
+ return false;
399
+ const now = read.binding;
400
+ if (now.form !== binding.form || now.digest !== binding.digest || now.cwd !== binding.cwd)
401
+ return false;
402
+ if (canonicalJsonStringify(now.segments) !== canonicalJsonStringify(binding.segments))
403
+ return false;
404
+ return binding.holes.every((h, k) => pathWithinRoot(read.holeReals[k], h.dir));
405
+ }
406
+ catch {
407
+ return false;
408
+ }
409
+ }
410
+ export async function callGrantRowAdmitting(rows, call) {
411
+ const judge = call.judge;
412
+ const command = call.command;
413
+ const sessionId = call.sessionId;
414
+ if (judge === undefined || typeof command !== "string" || sessionId === undefined)
415
+ return undefined;
416
+ for (const r of rows) {
417
+ if (r.match !== CALL_GRANT_MATCH || r.behavior !== "allow" || !call.words.includes(r.tool))
418
+ continue;
419
+ if (r.scope.kind !== "session" || r.scope.sessionId !== sessionId)
420
+ continue;
421
+ const binding = readCallGrantBinding(r.command);
422
+ if (binding === undefined || callGrantRuleTextOf(r.command) !== r.rule)
423
+ continue;
424
+ if (await judge(binding, command))
425
+ return r;
426
+ }
427
+ return undefined;
428
+ }
429
+ const isText = (v) => typeof v === "string" && v.length > 0 && v.length <= 4096;
430
+ const isAbsText = (v) => isText(v) && isAbs(v);
431
+ const isDigest = (v) => typeof v === "string" && /^[0-9a-f]{64}$/.test(v);
432
+ const BINDING_WORDS = Object.freeze({ subject: "a call grant row's binding", unit: "member", moment: "when the row is read" });
433
+ const ownKeys = (v, keys) => strayMembersOf(v, BINDING_WORDS, keys) === undefined;
434
+ function isProgram(v) {
435
+ if (v === null || typeof v !== "object")
436
+ return false;
437
+ const p = v;
438
+ if ("builtin" in p)
439
+ return ownKeys(p, ["builtin"]) && (p.builtin === "cd" || PLAIN_BUILTINS.has(p.builtin));
440
+ return ownKeys(p, ["path", "id", "size", "mtimeMs"]) && isAbsText(p.path) && isText(p.id) && Number.isFinite(p.size) && Number.isFinite(p.mtimeMs);
441
+ }
442
+ function isSegment(v) {
443
+ if (v === null || typeof v !== "object")
444
+ return false;
445
+ const s = v;
446
+ if (!ownKeys(s, ["at", "program", "script", "inline", "writes"]) || !isAbsText(s.at) || !isProgram(s.program))
447
+ return false;
448
+ if (!Array.isArray(s.writes) || !s.writes.every(isAbsText))
449
+ return false;
450
+ if (s.inline !== undefined && !isDigest(s.inline))
451
+ return false;
452
+ if (s.script !== undefined) {
453
+ const sc = s.script;
454
+ if (sc === null || typeof sc !== "object" || !ownKeys(sc, ["path", "sha256", "tree"]) || !isAbsText(sc.path) || !isDigest(sc.sha256) || !isDigest(sc.tree))
455
+ return false;
456
+ }
457
+ return true;
458
+ }
459
+ export function readCallGrantBinding(command) {
460
+ if (typeof command !== "string")
461
+ return undefined;
462
+ let v;
463
+ try {
464
+ v = JSON.parse(command);
465
+ }
466
+ catch {
467
+ return undefined;
468
+ }
469
+ return isBinding(v) && callGrantCommandOf(v) === command ? v : undefined;
470
+ }
471
+ function isBinding(v) {
472
+ if (v === null || typeof v !== "object" || Array.isArray(v))
473
+ return false;
474
+ const b = v;
475
+ if (!ownKeys(b, ["v", "cwd", "form", "digest", "segments", "holes"]) || b.v !== 1 || !isAbsText(b.cwd) || (b.form !== "text" && b.form !== "argv") || !isDigest(b.digest))
476
+ return false;
477
+ if (!Array.isArray(b.segments) || b.segments.length === 0 || b.segments.length > MAX_SEGMENTS || !b.segments.every(isSegment))
478
+ return false;
479
+ if (!Array.isArray(b.holes) || !b.holes.every((h) => h !== null && typeof h === "object" && ownKeys(h, ["at", "dir"]) && Number.isSafeInteger(h.at) && h.at >= 2 && isAbsText(h.dir)))
480
+ return false;
481
+ return (b.form === "text") === (b.holes.length === 0);
482
+ }
483
+ export function callGrantRowFault(r) {
484
+ if (r.behavior !== "allow" || r.tool !== COMMAND_RULE_TOOL || r.scope?.kind !== "session")
485
+ return "metadata_mismatch";
486
+ if (readCallGrantBinding(r.command) === undefined)
487
+ return "metadata_mismatch";
488
+ return r.rule === callGrantRuleTextOf(r.command) ? undefined : "invalid_rule_text";
489
+ }
490
+ const FINGERPRINT_DIGITS = 12;
491
+ function sentenceOf(o) {
492
+ const parts = [`this command (fingerprint ${o.fingerprint}) in ${o.cwd}`, `running ${o.programs.join(", ")}`];
493
+ if (o.scripts.length > 0)
494
+ parts.push(`the script ${o.scripts.join(", ")} as it is now, with the source files in its directory`);
495
+ if (o.inlineCode.length > 0)
496
+ parts.push(`inline code ${o.inlineCode.join(", ")}`);
497
+ if (o.writes.length > 0)
498
+ parts.push(`writing ${o.writes.join(", ")}`);
499
+ if (o.operandDirs.length > 0)
500
+ parts.push(`its file operands may be any file under ${o.operandDirs.join(", ")}`);
501
+ return `${parts.join("; ")} — for the rest of this session; it is asked again if one of these changes (a file the program loads from anywhere else is not one of them)`;
502
+ }
503
+ export function offerOfBinding(b) {
504
+ const command = callGrantCommandOf(b);
505
+ const members = {
506
+ fingerprint: b.digest.slice(0, FINGERPRINT_DIGITS),
507
+ cwd: b.cwd,
508
+ programs: Object.freeze(b.segments.map((s) => ("builtin" in s.program ? s.program.builtin : s.program.path))),
509
+ scripts: Object.freeze(b.segments.flatMap((s) => (s.script !== undefined ? [s.script.path] : []))),
510
+ inlineCode: Object.freeze(b.segments.flatMap((s) => (s.inline !== undefined ? [s.inline.slice(0, FINGERPRINT_DIGITS)] : []))),
511
+ writes: Object.freeze(b.segments.flatMap((s) => s.writes)),
512
+ operandDirs: Object.freeze([...new Set(b.holes.map((h) => h.dir))]),
513
+ };
514
+ return Object.freeze({ grant: callGrantRuleTextOf(command), sentence: sentenceOf(members), ...members });
515
+ }
516
+ export function sessionCallGrantOfRow(row) {
517
+ if (row.match !== CALL_GRANT_MATCH)
518
+ return undefined;
519
+ const b = readCallGrantBinding(row.command);
520
+ if (b === undefined)
521
+ return undefined;
522
+ const offer = offerOfBinding(b);
523
+ return offer.grant === row.rule ? offer : undefined;
524
+ }
@@ -194,6 +194,9 @@ export interface OpenSessionCheckoutInput {
194
194
  readonly sessions?: Pick<SessionStore, "acquire">;
195
195
  /** The leg judges the work of the session it stands with ({@link openStandingCheckout}); read only on a stand. */
196
196
  readonly judges?: boolean;
197
+ /** Whether the leg mounts a tool that can change a file (`legMayWriteFiles`); read only by a `null` leg's {@link nullLegRootOf}. `false`:
198
+ * a leg whose session's checkout cannot be resolved runs outside it (it has nothing to record). Absent ⇒ it may write. */
199
+ readonly writes?: boolean;
197
200
  }
198
201
  export interface OpenedSessionCheckout {
199
202
  /** The leg's task root: its place in its repository's tree when that repository is isolated, else `baseRoot`. */
@@ -709,13 +709,18 @@ async function placedInSession(input, record, trees) {
709
709
  }
710
710
  async function nullLegRootOf(input, record) {
711
711
  const lead = `TaskSpec.workspace is null on a leg of session "${input.sessionId}"`;
712
- const unkeyed = "A leg that records no file history (TaskSpec.fileHistory: \"disabled\", or capture off) does not read it.";
712
+ const unkeyed = "A leg that records no file history (TaskSpec.fileHistory: \"disabled\", or capture off), or that mounts no tool that can change a file, does not need it.";
713
+ const unread = (refused, why) => {
714
+ if (input.writes !== false)
715
+ throw refused;
716
+ return { outside: { notice: `file history is not live for this leg — ${lead}, ${why}, and the leg mounts no tool that can change a file, so it runs and records no file history: no rewind restores anything it did.`, refusal: refused } };
717
+ };
713
718
  let trees;
714
719
  try {
715
720
  trees = await sessionTreesOf(input, record);
716
721
  }
717
722
  catch (err) {
718
- throw keyedRefusal(err, `${lead}, whose file history is keyed to the session's own checkout, and that checkout cannot be resolved — this leg's edits could not be recorded where the session's rewinds read them back, so the leg was not started. ${unkeyed}`);
723
+ return unread(keyedRefusal(err, `${lead}, whose file history is keyed to the session's own checkout, and that checkout cannot be resolved — this leg's edits could not be recorded where the session's rewinds read them back, so the leg was not started. ${unkeyed}`), `whose session's checkout cannot be resolved (${thrownText(err)})`);
719
724
  }
720
725
  let keyed;
721
726
  try {
@@ -724,7 +729,7 @@ async function nullLegRootOf(input, record) {
724
729
  keyed = (await rootsInSession(input.env, trees, leg)).taskRoot;
725
730
  }
726
731
  catch (err) {
727
- throw keyedRefusal(err, `${lead}: where its file history is keyed cannot be read, so the leg was not started. ${unkeyed}`);
732
+ return unread(keyedRefusal(err, `${lead}: where its file history is keyed cannot be read, so the leg was not started. ${unkeyed}`), `where its file history is keyed cannot be read (${thrownText(err)})`);
728
733
  }
729
734
  if (keyed !== undefined)
730
735
  return { root: keyed };
@@ -283,6 +283,20 @@ export declare function sessionRulesPrincipalOf(principal: unknown, verb: "getRu
283
283
  export declare function inheritedRuleKeyOf<Entry extends {
284
284
  readonly principal?: string;
285
285
  }>(entry: Entry): Entry;
286
+ /** A row's rule content: its buckets, its grammar and its operator part (the counters are the key's, not the content). */
287
+ export type SessionRuleContent = SessionPermissionRules & Pick<StoredSessionRules, "grammar" | "operatorRules">;
288
+ /**
289
+ * Two rows of ONE session-rules key as the one row that enforces both — the law the file store folds a row an earlier release filed under the
290
+ * principal `""` into the session-wide key's row by (the two keys are one key from the reading of the principal on: {@link sessionRulesPrincipalOf}),
291
+ * and the law a host's store twin carrying such rows over reads the same way. Session rules only tighten, so the join refuses whatever either row
292
+ * refuses: `toolDeny` — the entries either row holds; `toolAllow` and `allowDirs` — the entries both rows keep (a list only one row sets is
293
+ * that row's); the operator part (`operatorRules`) the same way, from each row's line (its part, else its whole buckets). Entries compare as written.
294
+ * `undefined` — the rows cannot be one row: their rule grammars differ (a row's own `grammar`, absent = 0, or its operator part's), and an
295
+ * entry's reading moves with the grammar; the file store then refuses with `SessionPolicyError("corrupt")` rather than read one row's entries
296
+ * in the other's grammar. The answer is CONTENT only (no `rev`, `gen`, `__sid` or mark: those are the store's counters for the key, which a file
297
+ * store keeps in its mark file and a twin keeps in its own column) and a new object (neither row is changed). Pure.
298
+ */
299
+ export declare function conjoinSessionRuleRows(a: StoredSessionRules, b: StoredSessionRules): SessionRuleContent | undefined;
286
300
  /**
287
301
  * The seam a deployment implements for DURABLE, cross-replica per-session rules. Unset on `RunnerDeps` ⇒ the
288
302
  * feature is OFF (no rules read, zero behavior change). Keyed on `(sessionId, principal-owner)`: core passes
@@ -1,13 +1,12 @@
1
1
  import { posix } from "node:path";
2
2
  import { isDeepStrictEqual } from "node:util";
3
3
  import { isWinFormPath } from "../tools/fs/safety.js";
4
- import { splitNamespacedName } from "@sema-agent/primitives";
4
+ import { parsePermissionRule, ruleSpellingOf, splitNamespacedName } from "@sema-agent/primitives";
5
5
  import { callerToolNameProblem, NAMESPACED_NAME_SHAPES } from "./caller-tool-name.js";
6
6
  import { compileAllowList, compiledEntryName, inertEntryPhrase, readRuleEntry, renderListEntry, rootFacingToolNames } from "./allow-entry.js";
7
7
  import { valueTypeLabel } from "./tool-name-list.js";
8
8
  import { retiredNameView } from "./tool-name-aliases.js";
9
9
  import { NAME_RULE_FACES, noticeRuleText } from "./permission-rule-model.js";
10
- import { parsePermissionRule, ruleSpellingOf } from "./permission-rule-syntax.js";
11
10
  import { namesASetOfTools } from "./namespaced-rule-name.js";
12
11
  import { entriesNotAppliedDetail } from "./entries-not-applied.js";
13
12
  import { callerKey } from "./caller-text.js";
@@ -64,6 +63,21 @@ export function inheritedRuleKeyOf(entry) {
64
63
  const { principal: _absent, ...rest } = entry;
65
64
  return rest;
66
65
  }
66
+ function conjoinBuckets(a, b) {
67
+ const both = (x, y) => (x === undefined ? y?.slice() : y === undefined ? x.slice() : x.filter((e) => y.includes(e)));
68
+ const either = (x, y) => (x === undefined && y === undefined ? undefined : [...new Set([...(x ?? []), ...(y ?? [])])]);
69
+ const out = { toolAllow: both(a.toolAllow, b.toolAllow), toolDeny: either(a.toolDeny, b.toolDeny), allowDirs: both(a.allowDirs, b.allowDirs) };
70
+ return Object.fromEntries(Object.entries(out).filter(([, v]) => v !== undefined));
71
+ }
72
+ export function conjoinSessionRuleRows(a, b) {
73
+ const grammar = a.grammar ?? 0;
74
+ if ((b.grammar ?? 0) !== grammar || [a, b].some((r) => r.operatorRules !== undefined && r.operatorRules.grammar !== grammar))
75
+ return undefined;
76
+ const bucketsOf = (r) => ({ ...(r.toolAllow !== undefined ? { toolAllow: r.toolAllow } : {}), ...(r.toolDeny !== undefined ? { toolDeny: r.toolDeny } : {}), ...(r.allowDirs !== undefined ? { allowDirs: r.allowDirs } : {}) });
77
+ const lineOf = (r) => r.operatorRules ?? bucketsOf(r);
78
+ const part = a.operatorRules === undefined && b.operatorRules === undefined ? undefined : { ...conjoinBuckets(lineOf(a), lineOf(b)), grammar };
79
+ return { ...conjoinBuckets(a, b), ...(a.grammar !== undefined || b.grammar !== undefined ? { grammar } : {}), ...(part !== undefined ? { operatorRules: part } : {}) };
80
+ }
67
81
  function lexWithin(root, p) {
68
82
  const fold = (x) => {
69
83
  let n = isWinFormPath(x) ? x.replace(/\\/g, "/") : x;