@sema-agent/core 7.72.0 → 7.74.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 (375) hide show
  1. package/CHANGELOG.md +565 -0
  2. package/dist/agents/inherited-tool-pool.d.ts +26 -1
  3. package/dist/agents/inherited-tool-pool.js +46 -2
  4. package/dist/agents/list-agents-tool.js +1 -1
  5. package/dist/agents/parked-resume-drive.d.ts +10 -0
  6. package/dist/agents/parked-resume-drive.js +9 -0
  7. package/dist/agents/retain-ledger.d.ts +3 -0
  8. package/dist/agents/retain-ledger.js +3 -3
  9. package/dist/agents/send-message-tool.js +5 -4
  10. package/dist/agents/send-user-message-tool.d.ts +12 -0
  11. package/dist/agents/send-user-message-tool.js +67 -0
  12. package/dist/agents/subagent-steps.d.ts +9 -0
  13. package/dist/agents/subagent-steps.js +38 -0
  14. package/dist/agents/subagent.d.ts +2 -0
  15. package/dist/agents/subagent.js +43 -12
  16. package/dist/agents/verify.js +23 -8
  17. package/dist/agents/yield-adoption.js +3 -1
  18. package/dist/brain/anthropic.d.ts +42 -1
  19. package/dist/brain/anthropic.js +68 -13
  20. package/dist/brain/failover.d.ts +5 -0
  21. package/dist/brain/failover.js +51 -22
  22. package/dist/brain/model-lane.d.ts +12 -3
  23. package/dist/brain/model-lane.js +5 -5
  24. package/dist/brain/open-responses.js +7 -8
  25. package/dist/brain/openai.js +31 -24
  26. package/dist/brain/route-adjudicator.d.ts +33 -4
  27. package/dist/brain/route-adjudicator.js +49 -12
  28. package/dist/brain/stream-engine.js +166 -156
  29. package/dist/brain/stream-shared.d.ts +4 -3
  30. package/dist/brain/stream-shared.js +2 -2
  31. package/dist/core/actions-digest.d.ts +43 -0
  32. package/dist/core/actions-digest.js +22 -0
  33. package/dist/core/allow-entry.js +4 -4
  34. package/dist/core/ask-class.d.ts +2 -2
  35. package/dist/core/ask-headline.d.ts +1 -1
  36. package/dist/core/ask-origin.d.ts +44 -4
  37. package/dist/core/ask-origin.js +29 -10
  38. package/dist/core/auto-mode.d.ts +7 -9
  39. package/dist/core/auto-mode.js +114 -8
  40. package/dist/core/background-agent-store.d.ts +1 -0
  41. package/dist/core/background-agent-store.js +49 -8
  42. package/dist/core/checkpoint-features.d.ts +3 -2
  43. package/dist/core/checkpoint-features.js +1 -1
  44. package/dist/core/checkpoint-rekey.d.ts +1 -1
  45. package/dist/core/checkpoint-rekey.js +6 -1
  46. package/dist/core/checkpoint-requirements.d.ts +23 -3
  47. package/dist/core/checkpoint-requirements.js +5 -1
  48. package/dist/core/checkpoint-row-verdict.d.ts +1 -1
  49. package/dist/core/checkpoint-row-verdict.js +9 -3
  50. package/dist/core/checkpoint-store.d.ts +26 -2
  51. package/dist/core/checkpoint-store.js +9 -2
  52. package/dist/core/child-clamp-seats.d.ts +15 -0
  53. package/dist/core/child-clamp-seats.js +15 -0
  54. package/dist/core/config-refusal-codes.d.ts +1 -1
  55. package/dist/core/config-refusal-codes.js +1 -0
  56. package/dist/core/cron.js +9 -1
  57. package/dist/core/delegation-frames.d.ts +1 -0
  58. package/dist/core/delegation-frames.js +1 -1
  59. package/dist/core/deployment-shape.d.ts +7 -0
  60. package/dist/core/deployment-shape.js +19 -0
  61. package/dist/core/engine-capabilities.d.ts +13 -1
  62. package/dist/core/engine-capabilities.js +1 -1
  63. package/dist/core/engine-notice.d.ts +41 -28
  64. package/dist/core/engine-version.js +1 -1
  65. package/dist/core/entries-not-applied.d.ts +19 -7
  66. package/dist/core/entries-not-applied.js +33 -1
  67. package/dist/core/gate-fold.js +5 -4
  68. package/dist/core/gate-lanes.js +8 -12
  69. package/dist/core/gate-outcome.d.ts +8 -2
  70. package/dist/core/gate-outcome.js +10 -3
  71. package/dist/core/governance-codes.d.ts +14 -2
  72. package/dist/core/governance-codes.js +22 -6
  73. package/dist/core/hook-condition.d.ts +37 -0
  74. package/dist/core/hook-condition.js +567 -0
  75. package/dist/core/hooks.d.ts +5 -0
  76. package/dist/core/hooks.js +1 -0
  77. package/dist/core/host-instance.d.ts +23 -0
  78. package/dist/core/host-instance.js +69 -0
  79. package/dist/core/instruction-preview.d.ts +63 -0
  80. package/dist/core/instruction-preview.js +406 -0
  81. package/dist/core/leg-budget.d.ts +26 -0
  82. package/dist/core/leg-budget.js +9 -0
  83. package/dist/core/leg-identity.d.ts +51 -1
  84. package/dist/core/leg-identity.js +45 -2
  85. package/dist/core/manager-launch-check.d.ts +48 -0
  86. package/dist/core/manager-launch-check.js +64 -0
  87. package/dist/core/mcp-call-meta.d.ts +2 -2
  88. package/dist/core/mcp-injection-drop.d.ts +20 -10
  89. package/dist/core/mcp-injection-drop.js +9 -3
  90. package/dist/core/mcp-server-spec.d.ts +2 -1
  91. package/dist/core/member-outcome.d.ts +3 -2
  92. package/dist/core/member-outcome.js +1 -1
  93. package/dist/core/memory-engine/deletion-record.d.ts +46 -0
  94. package/dist/core/memory-engine/deletion-record.js +96 -0
  95. package/dist/core/memory-engine/engine.js +24 -16
  96. package/dist/core/memory-engine/file-backend.js +7 -5
  97. package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
  98. package/dist/core/memory-engine/projection-ledger.js +1 -1
  99. package/dist/core/memory-engine/scope-contract.d.ts +18 -13
  100. package/dist/core/memory-engine/scope-contract.js +18 -18
  101. package/dist/core/memory-engine/sync-client.js +26 -6
  102. package/dist/core/memory-engine/sync.d.ts +20 -2
  103. package/dist/core/memory-engine/sync.js +18 -17
  104. package/dist/core/mode-policy.d.ts +25 -6
  105. package/dist/core/mode-policy.js +33 -8
  106. package/dist/core/model-seat.d.ts +8 -5
  107. package/dist/core/model-shell.d.ts +129 -0
  108. package/dist/core/model-shell.js +249 -0
  109. package/dist/core/mods/kernel/digest.d.ts +4 -0
  110. package/dist/core/mods/kernel/digest.js +5 -0
  111. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  112. package/dist/core/mods/kernel/dispatch.js +15 -6
  113. package/dist/core/mods/kernel/events.d.ts +21 -5
  114. package/dist/core/mods/kernel/events.js +19 -10
  115. package/dist/core/mods/kernel/hash-mirror.d.ts +1 -0
  116. package/dist/core/mods/kernel/hash-mirror.js +55 -0
  117. package/dist/core/mods/kernel/index.d.ts +1 -0
  118. package/dist/core/mods/kernel/index.js +1 -0
  119. package/dist/core/mods/kernel/package-reader.d.ts +48 -0
  120. package/dist/core/mods/kernel/package-reader.js +149 -0
  121. package/dist/core/mods/kernel/site-rules.d.ts +4 -0
  122. package/dist/core/mods/kernel/site-rules.js +13 -0
  123. package/dist/core/mods/package.d.ts +7 -3
  124. package/dist/core/mods/package.js +47 -80
  125. package/dist/core/own-property-receipt.js +11 -4
  126. package/dist/core/parent-spec-seat.d.ts +13 -11
  127. package/dist/core/parent-spec-seat.js +13 -9
  128. package/dist/core/peer-seat.js +3 -3
  129. package/dist/core/peer-task-store.d.ts +365 -0
  130. package/dist/core/peer-task-store.js +682 -0
  131. package/dist/core/permission-rule-consent.js +6 -11
  132. package/dist/core/permission-rule-model.d.ts +27 -0
  133. package/dist/core/permission-rule-model.js +33 -5
  134. package/dist/core/permission-rule-org.js +13 -3
  135. package/dist/core/permission-rule-provider.d.ts +35 -33
  136. package/dist/core/permission-rule-provider.js +38 -295
  137. package/dist/core/permission-rule-store.d.ts +181 -8
  138. package/dist/core/permission-rule-store.js +420 -17
  139. package/dist/core/permission-rule-sync.js +15 -1
  140. package/dist/core/permission-rules.js +4 -1
  141. package/dist/core/project-seat.d.ts +55 -0
  142. package/dist/core/project-seat.js +96 -0
  143. package/dist/core/protocol-http-auth.d.ts +3 -2
  144. package/dist/core/protocol-http-auth.js +26 -18
  145. package/dist/core/remote-env.d.ts +4 -4
  146. package/dist/core/retain-seat.d.ts +42 -0
  147. package/dist/core/retain-seat.js +76 -0
  148. package/dist/core/retired-keys.js +1 -0
  149. package/dist/core/rewind-refusal-codes.d.ts +8 -0
  150. package/dist/core/rewind-refusal-codes.js +12 -0
  151. package/dist/core/roles.d.ts +2 -2
  152. package/dist/core/roles.js +15 -1
  153. package/dist/core/rule-offer-read.d.ts +1 -1
  154. package/dist/core/rule-offer-read.js +32 -4
  155. package/dist/core/rule-store-fault.d.ts +9 -7
  156. package/dist/core/rule-store-fault.js +8 -3
  157. package/dist/core/run-ledger-seat.d.ts +66 -0
  158. package/dist/core/run-ledger-seat.js +70 -0
  159. package/dist/core/run-ledger.d.ts +332 -0
  160. package/dist/core/run-ledger.js +550 -0
  161. package/dist/core/runner/checkpoint-scope.d.ts +14 -3
  162. package/dist/core/runner/checkpoint-scope.js +16 -6
  163. package/dist/core/runner/compact-session.js +1 -1
  164. package/dist/core/runner/construction-doors.js +8 -0
  165. package/dist/core/runner/contracts.d.ts +21 -5
  166. package/dist/core/runner/cross-boundary-lane.d.ts +8 -1
  167. package/dist/core/runner/cross-boundary-lane.js +4 -0
  168. package/dist/core/runner/delegation-owner.d.ts +30 -0
  169. package/dist/core/runner/delegation-owner.js +20 -4
  170. package/dist/core/runner/finish-reason-seat.js +4 -2
  171. package/dist/core/runner/gate-exit.d.ts +7 -0
  172. package/dist/core/runner/gate-exit.js +2 -1
  173. package/dist/core/runner/leg-frame.js +3 -0
  174. package/dist/core/runner/model-lane-seat.d.ts +3 -0
  175. package/dist/core/runner/model-lane-seat.js +4 -0
  176. package/dist/core/runner/nested-memory-lane.d.ts +22 -5
  177. package/dist/core/runner/nested-memory-lane.js +91 -30
  178. package/dist/core/runner/person-path-rows.d.ts +27 -16
  179. package/dist/core/runner/person-path-rows.js +93 -15
  180. package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
  181. package/dist/core/runner/prepare-config-doors.d.ts +1 -0
  182. package/dist/core/runner/prepare-config-doors.js +13 -7
  183. package/dist/core/runner/prepare-context-lane.js +1 -0
  184. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  185. package/dist/core/runner/prepare-delegation-surface.js +6 -0
  186. package/dist/core/runner/prepare-execution-env.d.ts +3 -3
  187. package/dist/core/runner/prepare-gate-stations.d.ts +6 -0
  188. package/dist/core/runner/prepare-gate-stations.js +3 -1
  189. package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
  190. package/dist/core/runner/prepare-hands-readface.js +15 -3
  191. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
  192. package/dist/core/runner/prepare-inherited-gate.js +13 -5
  193. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  194. package/dist/core/runner/prepare-run-refs.d.ts +1 -1
  195. package/dist/core/runner/prepare-run-refs.js +3 -2
  196. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
  197. package/dist/core/runner/prepare-suspend-saga.js +4 -2
  198. package/dist/core/runner/prepare-task.js +42 -30
  199. package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
  200. package/dist/core/runner/prepare-turn-wiring.js +2 -1
  201. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  202. package/dist/core/runner/prepare-wiring-manifest.js +8 -6
  203. package/dist/core/runner/resume-apply.js +11 -5
  204. package/dist/core/runner/resume-policy-outcome.js +5 -2
  205. package/dist/core/runner/resume-review-outcome.d.ts +3 -0
  206. package/dist/core/runner/resume-review-outcome.js +24 -1
  207. package/dist/core/runner/role-seat-defaulted.d.ts +3 -3
  208. package/dist/core/runner/role-seat-defaulted.js +1 -1
  209. package/dist/core/runner/rule-store-unreadable-notice.d.ts +1 -1
  210. package/dist/core/runner/rule-store-unreadable-notice.js +3 -3
  211. package/dist/core/runner/run-harness-handlers.js +4 -1
  212. package/dist/core/runner/run-identity-wiring.js +3 -2
  213. package/dist/core/runner/run-leg.js +5 -2
  214. package/dist/core/runner/run-notification-lane.js +20 -1
  215. package/dist/core/runner/run-settle-and-teardown.js +21 -12
  216. package/dist/core/runner/run-stop-and-final-verify.js +6 -0
  217. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  218. package/dist/core/runner/runtask.d.ts +6 -2
  219. package/dist/core/runner/runtask.js +21 -9
  220. package/dist/core/runner/shell-env-withheld.d.ts +6 -4
  221. package/dist/core/runner/shell-env-withheld.js +25 -3
  222. package/dist/core/runner/stop-tail-notice.d.ts +10 -2
  223. package/dist/core/runner/stop-tail-notice.js +9 -2
  224. package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
  225. package/dist/core/runner/stream-settle-backstop.js +1 -0
  226. package/dist/core/runner/sub-agent-deny-lists.js +9 -5
  227. package/dist/core/runner/task-start-doors.js +6 -3
  228. package/dist/core/runner/terminal-account.d.ts +6 -1
  229. package/dist/core/runner/terminal-account.js +16 -1
  230. package/dist/core/runner/tool-end-body.d.ts +1 -1
  231. package/dist/core/runner/tool-not-executed.d.ts +27 -8
  232. package/dist/core/runner/tool-not-executed.js +22 -11
  233. package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
  234. package/dist/core/runner/write-protection-station.d.ts +1 -1
  235. package/dist/core/runner/write-protection-station.js +1 -1
  236. package/dist/core/runner-deps.d.ts +17 -10
  237. package/dist/core/secret-env.d.ts +61 -37
  238. package/dist/core/secret-env.js +49 -49
  239. package/dist/core/session-checkout.d.ts +3 -0
  240. package/dist/core/session-checkout.js +1 -0
  241. package/dist/core/session-store.d.ts +12 -6
  242. package/dist/core/session-store.js +26 -6
  243. package/dist/core/session.d.ts +31 -8
  244. package/dist/core/shell-read-silence.d.ts +40 -2
  245. package/dist/core/shell-read-silence.js +23 -4
  246. package/dist/core/store-contracts/checkpoint-store-contract.js +10 -0
  247. package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
  248. package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
  249. package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
  250. package/dist/core/store-contracts/session-store-contract.js +87 -3
  251. package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
  252. package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
  253. package/dist/core/task-event.d.ts +14 -7
  254. package/dist/core/task-notification.d.ts +96 -10
  255. package/dist/core/task-notification.js +135 -6
  256. package/dist/core/task-registry-agent.d.ts +1 -0
  257. package/dist/core/task-registry-agent.js +1 -1
  258. package/dist/core/task-registry-shared.d.ts +12 -1
  259. package/dist/core/task-registry-shared.js +3 -1
  260. package/dist/core/task-registry-workflow.d.ts +1 -1
  261. package/dist/core/task-registry-workflow.js +9 -1
  262. package/dist/core/task-registry.d.ts +40 -2
  263. package/dist/core/task-registry.js +80 -15
  264. package/dist/core/task-result.d.ts +18 -3
  265. package/dist/core/task-spec-members.d.ts +3 -1
  266. package/dist/core/task-spec-members.js +19 -3
  267. package/dist/core/task-spec.d.ts +48 -22
  268. package/dist/core/tool-catalog-entries.js +2 -0
  269. package/dist/core/tool-gate-phase.d.ts +6 -3
  270. package/dist/core/tool-gate-phase.js +1 -0
  271. package/dist/core/tool-mount-facts.d.ts +8 -4
  272. package/dist/core/tool-mount-facts.js +7 -2
  273. package/dist/core/tool-mount-plan.d.ts +3 -1
  274. package/dist/core/tool-mount-plan.js +10 -3
  275. package/dist/core/tool-mount-static.d.ts +1 -1
  276. package/dist/core/tool-mount-static.js +4 -2
  277. package/dist/core/tool-result-store.d.ts +56 -3
  278. package/dist/core/tool-result-store.js +219 -25
  279. package/dist/core/tool-spec.d.ts +9 -2
  280. package/dist/core/trace.d.ts +3 -3
  281. package/dist/core/user-attachment.d.ts +5 -1
  282. package/dist/core/user-attachment.js +14 -7
  283. package/dist/core/wiring-manifest.d.ts +26 -20
  284. package/dist/core/wiring-manifest.js +7 -3
  285. package/dist/core/workflow-journal-store.d.ts +53 -10
  286. package/dist/core/workflow-journal-store.js +27 -4
  287. package/dist/core/workflow-run-store-contract.js +16 -0
  288. package/dist/core/workflow-run-store.d.ts +9 -7
  289. package/dist/core/workflow-run-store.js +4 -1
  290. package/dist/engine/execution-env/node-execution-env.d.ts +75 -1
  291. package/dist/engine/execution-env/node-execution-env.js +227 -13
  292. package/dist/engine/harness/types.d.ts +49 -1
  293. package/dist/engine/harness/types.js +10 -0
  294. package/dist/engine/llm/types.d.ts +13 -7
  295. package/dist/engine/llm/validation.d.ts +8 -1
  296. package/dist/engine/llm/validation.js +31 -2
  297. package/dist/engine/lsp/node-lsp-manager.js +2 -1
  298. package/dist/engine/session/import-validate.js +6 -1
  299. package/dist/engine/session/session.d.ts +15 -2
  300. package/dist/engine/session/session.js +34 -4
  301. package/dist/host-env.d.ts +10 -0
  302. package/dist/host-env.js +1 -0
  303. package/dist/index.d.ts +28 -9
  304. package/dist/index.js +22 -6
  305. package/dist/internal/harness-types.d.ts +1 -1
  306. package/dist/orchestration/goal.js +1 -1
  307. package/dist/orchestration/run-workflow-tool.js +40 -32
  308. package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
  309. package/dist/orchestration/workflow-park-adoption.js +47 -12
  310. package/dist/orchestration/workflow-primitives.js +10 -1
  311. package/dist/orchestration/workflow-script-runner.d.ts +2 -2
  312. package/dist/orchestration/workflow-stop.d.ts +128 -0
  313. package/dist/orchestration/workflow-stop.js +156 -0
  314. package/dist/orchestration/workflow.d.ts +31 -7
  315. package/dist/orchestration/workflow.js +119 -57
  316. package/dist/prompts/manager-recipe.d.ts +18 -0
  317. package/dist/prompts/manager-recipe.js +24 -0
  318. package/dist/shell/lex.d.ts +2 -2
  319. package/dist/shell/lex.js +1 -1
  320. package/dist/stores/file/permission-rule-store.d.ts +3 -1
  321. package/dist/stores/file/permission-rule-store.js +0 -1
  322. package/dist/stores/file/workflow-journal-store.d.ts +16 -3
  323. package/dist/stores/file/workflow-journal-store.js +93 -5
  324. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  325. package/dist/tools/fs/bash-model-shell.d.ts +23 -0
  326. package/dist/tools/fs/bash-model-shell.js +25 -0
  327. package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -0
  328. package/dist/tools/fs/bash-readonly-classifier.js +3 -0
  329. package/dist/tools/fs/file-write-check.js +9 -3
  330. package/dist/tools/fs/fs-bash.js +13 -11
  331. package/dist/tools/fs/index.d.ts +8 -7
  332. package/dist/tools/fs/index.js +4 -4
  333. package/dist/tools/fs/read-deny-home.d.ts +1 -1
  334. package/dist/tools/fs/read-deny-home.js +5 -5
  335. package/dist/tools/fs/read-deny.d.ts +33 -8
  336. package/dist/tools/fs/read-deny.js +114 -25
  337. package/dist/tools/fs/safety.d.ts +4 -1
  338. package/dist/tools/fs/safety.js +4 -2
  339. package/dist/tools/fs/shell-read-argv.js +1 -0
  340. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  341. package/dist/tools/fs/shell-read-check.js +134 -22
  342. package/dist/tools/fs/shell-read-establish.d.ts +9 -0
  343. package/dist/tools/fs/shell-read-establish.js +21 -11
  344. package/dist/tools/fs/shell-read-judge.d.ts +13 -1
  345. package/dist/tools/fs/shell-read-judge.js +26 -7
  346. package/dist/tools/fs/shell-read-plan.d.ts +7 -3
  347. package/dist/tools/fs/shell-read-plan.js +8 -5
  348. package/dist/tools/fs/shell-read-word.d.ts +8 -0
  349. package/dist/tools/fs/shell-read-word.js +13 -4
  350. package/dist/tools/fs/shell-read-write-targets.js +17 -9
  351. package/dist/tools/monitor.js +12 -8
  352. package/dist/tools/scheduler-tools.d.ts +1 -0
  353. package/dist/tools/scheduler-tools.js +5 -2
  354. package/package.json +3 -2
  355. package/test/export-surface.snapshot.json +192 -3
  356. package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
  357. package/wire-changes/answers/core-stores-sql@7.74.0.json +7 -0
  358. package/wire-changes/answers/core@7.73.0.json +216 -0
  359. package/wire-changes/answers/core@7.74.0.json +68 -0
  360. package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
  361. package/wire-changes/answers/mods-kernel@7.74.0.json +21 -0
  362. package/wire-changes/answers/primitives@7.73.0.json +12 -0
  363. package/wire-changes/answers/primitives@7.74.0.json +7 -0
  364. package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
  365. package/wire-changes/answers/wiki-gate@7.74.0.json +8 -0
  366. package/wire-changes/core-stores-sql@7.73.0.json +326 -0
  367. package/wire-changes/core-stores-sql@7.74.0.json +143 -0
  368. package/wire-changes/core@7.73.0.json +6480 -0
  369. package/wire-changes/core@7.74.0.json +2210 -0
  370. package/wire-changes/mods-kernel@7.73.0.json +147 -0
  371. package/wire-changes/mods-kernel@7.74.0.json +421 -0
  372. package/wire-changes/primitives@7.73.0.json +227 -0
  373. package/wire-changes/primitives@7.74.0.json +174 -0
  374. package/wire-changes/wiki-gate@7.73.0.json +145 -0
  375. package/wire-changes/wiki-gate@7.74.0.json +145 -0
@@ -150,15 +150,80 @@ function denyTargetViews(canonicalKey, lexicalView, opts) {
150
150
  views.push({ path: hop, kind: "hop" });
151
151
  return { views };
152
152
  }
153
- export function compileWriteDeny(rules = []) {
154
- const ruleRows = rules.filter((r) => r.faces.includes("write"));
155
- const readRows = new Set(ruleRows.filter((r) => r.faces.includes("read")).map((r) => r.rule));
156
- const rows = ruleRows.map(ruleGuardRow);
157
- const matchPath = (path) => {
158
- const hit = denyTableHit(rows, { views: [{ path, kind: "lexical" }] });
159
- return hit === null ? null : { pattern: hit.pattern };
153
+ export function compileWriteDeny(table) {
154
+ if (table === null || typeof table !== "object" || !Array.isArray(table.tableRows)) {
155
+ throw new TypeError("compileWriteDeny: expected a table compiled by compileReadDeny (missing tableRows) — pass the compiled table, not a separate rule list.");
156
+ }
157
+ let cachedSource;
158
+ let cached;
159
+ const projected = () => {
160
+ const source = table.tableRows;
161
+ if (!Array.isArray(source)) {
162
+ throw new TypeError("compileWriteDeny: the table carries no compiled tableRows to project.");
163
+ }
164
+ if (cached === undefined || cachedSource !== source) {
165
+ const rows = source.filter((r) => r.faces.includes("write"));
166
+ const ruleRows = [];
167
+ const writeSegments = [];
168
+ for (const r of rows) {
169
+ if ("rule" in r)
170
+ ruleRows.push(r.rule);
171
+ else if ("compiledSegment" in r)
172
+ writeSegments.push(r.compiledSegment);
173
+ }
174
+ const readRows = new Set(rows.filter((r) => r.faces.includes("read")).map((r) => r.name));
175
+ cachedSource = source;
176
+ cached = { rows, ruleRows, writeSegments, readRows };
177
+ }
178
+ return cached;
160
179
  };
161
- return { face: "write", ruleRows, matchPath, matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(rows, denyTargetViews(canonicalKey, lexicalView, opts)), guardsReads: (pattern) => readRows.has(pattern) };
180
+ projected();
181
+ return {
182
+ face: "write",
183
+ get hasRows() {
184
+ return projected().rows.length > 0;
185
+ },
186
+ get ruleRows() {
187
+ return projected().ruleRows;
188
+ },
189
+ matchPath: (path) => {
190
+ const hit = denyTableHit(projected().rows, { views: [{ path, kind: "lexical" }] });
191
+ return hit === null ? null : { pattern: hit.pattern };
192
+ },
193
+ matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(projected().rows, denyTargetViews(canonicalKey, lexicalView, opts)),
194
+ guardsReads: (pattern) => projected().readRows.has(pattern),
195
+ rowUnderRoot: (scope) => {
196
+ const { writeSegments } = projected();
197
+ if (writeSegments.length === 0 || !isAbsoluteForFamily("own", scope))
198
+ return null;
199
+ return rowNamedByRootOf(writeSegments, normalizeAbsPathLexically(scope));
200
+ },
201
+ rowAtOrBelow: (path) => {
202
+ const { writeSegments, ruleRows } = projected();
203
+ const hit = rowAtOrBelowOf(writeSegments, path);
204
+ if (hit !== null)
205
+ return { pattern: hit };
206
+ return ruleRows.length === 0 ? null : { pattern: ruleRows[0].rule };
207
+ },
208
+ get unanchoredRows() {
209
+ return projected().writeSegments.filter(unanchoredRow).map((pat) => pat.raw);
210
+ },
211
+ rowLedByName: (name) => rowLedByNameOf(projected().writeSegments, name),
212
+ };
213
+ }
214
+ function unanchoredRow(pat) {
215
+ return pat.anchors === undefined && pat.rootedOnly !== true;
216
+ }
217
+ function rowLedByNameOf(rows, name) {
218
+ const readings = foldedViewsOf([[name]]);
219
+ for (const pat of rows) {
220
+ if (!unanchoredRow(pat))
221
+ continue;
222
+ const lead = pat.segments.find((s) => !s.anything);
223
+ if (lead === undefined || readings(pat.fold).some((view) => lead.test(view[0])))
224
+ return pat.raw;
225
+ }
226
+ return null;
162
227
  }
163
228
  export function seatForCall(seat, toolCallId) {
164
229
  const forCall = seat?.forCall;
@@ -196,21 +261,34 @@ export function readDenyRefusal(finding) {
196
261
  const write = finding.face === "write";
197
262
  const canonicalNote = finding.canonical !== undefined && finding.canonical !== finding.target ? `(canonical target: "${fitMiddle(finding.canonical, READ_DENY_SENTENCE_PART_MAX)}") ` : "";
198
263
  const lexicalHit = finding.matchedView !== undefined && finding.matchedView !== (finding.canonical ?? finding.target);
199
- const under = finding.under === true && !write;
200
- const frame = `${finding.action ?? (under ? "searching below" : write ? "writing" : "reading")} "${fitMiddle(finding.target, READ_DENY_SENTENCE_PART_MAX)}" ${canonicalNote}is refused:`;
264
+ const under = finding.under === true;
265
+ const frame = `${finding.action ?? (under && !write ? "searching below" : write ? "writing" : "reading")} "${fitMiddle(finding.target, READ_DENY_SENTENCE_PART_MAX)}" ${canonicalNote}is refused:`;
201
266
  const pattern = fitMiddle(finding.pattern, READ_DENY_SENTENCE_PART_MAX);
202
267
  const echoed = Object.freeze([
203
268
  Object.freeze({ kind: "path", value: finding.target, ...(finding.canonical !== undefined && finding.canonical !== finding.target ? { canonical: finding.canonical } : {}) }),
204
269
  ...(lexicalHit ? [Object.freeze({ kind: "path", value: finding.matchedView })] : []),
205
270
  Object.freeze({ kind: "pattern", value: finding.pattern }),
206
271
  ]);
272
+ if (write && finding.lookup !== undefined) {
273
+ const row = finding.readRow === true ? `the read deny row "${pattern}"` : sensitivePathDenyList(pattern, "write");
274
+ const found = finding.lookup.found;
275
+ const held = `it holds "${fitMiddle(found, READ_DENY_SENTENCE_PART_MAX)}", a name ${row} starts with, and a recursive removal removes everything below it`;
276
+ const quoted = [echoed[0], Object.freeze({ kind: "path", value: found }), echoed.at(-1)];
277
+ return { sentence: `${frame} ${held}. ${finding.readRow === true ? READ_ROW_WRITE_SCOPE : WRITE_DENY_SCOPE}`, echoed: Object.freeze(quoted) };
278
+ }
207
279
  if (write && finding.readRow === true) {
208
- const reaches = lexicalHit ? `the path passes through "${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}", which the read deny row "${pattern}" denies reading` : `the target is a path the read deny row "${pattern}" denies reading`;
280
+ const reaches = under
281
+ ? lexicalHit
282
+ ? `the requested path's spelling ("${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}") holds a location the read deny row "${pattern}" denies reading`
283
+ : `that path holds a location the read deny row "${pattern}" denies reading`
284
+ : lexicalHit
285
+ ? `the path passes through "${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}", which the read deny row "${pattern}" denies reading`
286
+ : `the target is a path the read deny row "${pattern}" denies reading`;
209
287
  return { sentence: `${frame} ${reaches} — a path whose reads are denied is not written either. ${READ_ROW_WRITE_SCOPE}`, echoed };
210
288
  }
211
289
  if (under) {
212
290
  const holder = lexicalHit ? `the requested path's spelling ("${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}")` : "that path";
213
- return { sentence: `${frame} ${holder} holds a location on ${sensitivePathDenyList(pattern)} — locations are checked, not which files exist, so no such file need be there. ${SENSITIVE_PATH_DENY_SCOPE}`, echoed };
291
+ return { sentence: `${frame} ${holder} holds a location on ${sensitivePathDenyList(pattern, write ? "write" : "read")} — locations are checked, not which files exist, so no such file need be there. ${write ? WRITE_DENY_SCOPE : SENSITIVE_PATH_DENY_SCOPE}`, echoed };
214
292
  }
215
293
  const judged = lexicalHit ? `the requested path's spelling ("${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}") matches` : "the target matches";
216
294
  return { sentence: `${frame} ${judged} ${sensitivePathDenyList(pattern, write ? "write" : "read")}. ${write ? WRITE_DENY_SCOPE : SENSITIVE_PATH_DENY_SCOPE}`, echoed };
@@ -618,8 +696,9 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
618
696
  const ruleRows = rules.filter((r) => r.faces.includes("read"));
619
697
  const normalized = [];
620
698
  const seen = new Set();
699
+ const entryKey = (e) => `${e.caseSensitive ? "s" : "i"}:${e.pattern}`;
621
700
  const push = (e) => {
622
- const key = `${e.caseSensitive ? "s" : "i"}:${e.pattern}`;
701
+ const key = entryKey(e);
623
702
  if (seen.has(key))
624
703
  return;
625
704
  seen.add(key);
@@ -629,14 +708,16 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
629
708
  for (const row of resolveReadDenyBuiltins(builtin)) {
630
709
  const e = normalizeEntry(row.pattern, "built-in");
631
710
  push(e);
632
- if (!columns.has(e.pattern))
633
- columns.set(e.pattern, { origin: "builtin", tier: row.tier });
711
+ const k = entryKey(e);
712
+ if (!columns.has(k))
713
+ columns.set(k, { origin: "builtin", tier: row.tier });
634
714
  }
635
715
  for (const entry of additions) {
636
716
  const e = normalizeEntry(entry, layer);
637
717
  push(e);
638
- if (!columns.has(e.pattern))
639
- columns.set(e.pattern, { origin: "addition" });
718
+ const k = entryKey(e);
719
+ const prev = columns.get(k);
720
+ columns.set(k, { origin: "addition", ...(prev?.tier !== undefined ? { tier: prev.tier } : {}) });
640
721
  }
641
722
  const homeSegments = [...new Set(checkedReadDenyHomes(homes))].flatMap(homeAnchorSegments);
642
723
  const compiled = normalized.map((e) => {
@@ -664,16 +745,23 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
664
745
  return;
665
746
  const c = compiled[i];
666
747
  const rest = c.segments.slice(readDenyRunHead(run));
748
+ const key = entryKey(e);
667
749
  for (const location of new Set(checkedReadDenyHomes(locations, "readDenyHomeLinks"))) {
668
- linkedPlacements.push({ raw: e.pattern, segments: rest, fold: c.fold, anchors: homeAnchorSegments(location).map((segs) => foldSegments(c.fold, segs)), rootedOnly: true });
750
+ linkedPlacements.push({ pat: { raw: e.pattern, segments: rest, fold: c.fold, anchors: homeAnchorSegments(location).map((segs) => foldSegments(c.fold, segs)), rootedOnly: true }, key });
669
751
  }
670
752
  });
671
- const judged = linkedPlacements.length === 0 ? compiled : [...compiled, ...linkedPlacements];
672
- const segmentRows = judged.map((c) => {
673
- const col = columns.get(c.raw);
674
- return segmentGuardRow(c, { faces: ["read"], polarity: "deny", exemptible: false, fold: c.fold === "ascii" ? "ascii" : "exact", origin: col?.origin ?? "addition", ...(col?.tier !== undefined ? { tier: col.tier } : {}) });
753
+ const judgedEntries = [
754
+ ...compiled.map((pat, i) => ({ pat, key: entryKey(normalized[i]) })),
755
+ ...linkedPlacements,
756
+ ];
757
+ const judged = judgedEntries.map((x) => x.pat);
758
+ const segmentRows = judgedEntries.map(({ pat, key }) => {
759
+ const col = columns.get(key) ?? { origin: "addition" };
760
+ const faces = col.origin === "addition" ? ["read", "write"] : ["read"];
761
+ return Object.assign(segmentGuardRow(pat, { faces, polarity: "deny", exemptible: false, fold: pat.fold === "ascii" ? "ascii" : "exact", origin: col.origin, ...(col.tier !== undefined ? { tier: col.tier } : {}) }), { compiledSegment: pat });
675
762
  });
676
- const tableRows = [...segmentRows, ...ruleRows.map(ruleGuardRow)];
763
+ const allTableRows = Object.freeze([...segmentRows, ...rules.map(ruleGuardRow)]);
764
+ const readTableRows = allTableRows.filter((r) => r.faces.includes("read"));
677
765
  const rgExclusionGlobs = [];
678
766
  const rgProbeGlobs = [];
679
767
  for (const row of segmentRows) {
@@ -698,20 +786,21 @@ export function compileReadDeny(additions = [], layer = "additions", builtin, ru
698
786
  return rowNamedByRootOf(judged, normalizeAbsPathLexically(scope));
699
787
  };
700
788
  const matchPath = (path, opts) => {
701
- const hit = denyTableHit(tableRows, { views: [{ path, kind: "lexical", ...(opts?.aliasResolved === true ? { aliasResolved: true } : {}) }] });
789
+ const hit = denyTableHit(readTableRows, { views: [{ path, kind: "lexical", ...(opts?.aliasResolved === true ? { aliasResolved: true } : {}) }] });
702
790
  return hit === null ? null : { pattern: hit.pattern };
703
791
  };
704
792
  const table = {
705
793
  entries: normalized,
706
794
  ...(ruleRows.length > 0 ? { ruleRows } : {}),
707
795
  matchPath,
708
- matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(tableRows, denyTargetViews(canonicalKey, lexicalView, opts)),
796
+ matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(readTableRows, denyTargetViews(canonicalKey, lexicalView, opts)),
709
797
  rgExclusionGlobs,
710
798
  rgProbeGlobs,
711
799
  unexcludableUnder,
712
800
  rowUnderRoot,
713
801
  rowAtOrBelow,
714
802
  compiledSegments: Object.freeze([...judged]),
803
+ tableRows: allTableRows,
715
804
  };
716
805
  Object.defineProperty(table, "id", { value: `rdt-${randomUUID()}`, enumerable: false });
717
806
  return table;
@@ -1,4 +1,5 @@
1
1
  import { type DenyFace } from "./read-deny.js";
2
+ import type { RefusalEcho } from "../../core/refusal-echo.js";
2
3
  import { type HomeViewSource } from "./read-deny-home.js";
3
4
  import type { AssertAllKeysHandled } from "../../core/ask-origin.js";
4
5
  import type { ExecutionEnv } from "../../internal/harness-types.js";
@@ -110,10 +111,12 @@ export interface FsViolation {
110
111
  /** Set ONLY on `path_not_in_root` — the containment roots in effect (primary first,
111
112
  * then additionalDirectories), canonical form. */
112
113
  roots?: readonly string[];
113
- /** Set ONLY on `read_path_denied` — the deny-list pattern (verbatim entry text)
114
+ /** Set on `read_path_denied` and `write_path_denied` — the deny-list pattern (verbatim entry text)
114
115
  * the judged target matched. Absent on the refusal of a deny judgment that could not finish (a home view nobody could
115
116
  * read, read-deny-home.ts `HomeView.unread`): no row matched, so none is named and no deny card is minted. */
116
117
  pattern?: string;
118
+ /** The literals quoted by a deny refusal sentence, minted with the sentence ({@link readDenyRefusal}). */
119
+ echoed?: readonly RefusalEcho[];
117
120
  message: string;
118
121
  }
119
122
  /**
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { readDenySentence } from "./read-deny.js";
2
+ import { readDenyRefusal } from "./read-deny.js";
3
3
  import { envErrorDetail } from "./env-error-detail.js";
4
4
  import { homeViewsOf, homeViewUnreadSentence } from "./read-deny-home.js";
5
5
  import { skipsRootsContainment } from "./containment-face.js";
@@ -524,13 +524,15 @@ export async function resolveKey(env, rootCanonical, path, signal, baseCwd, addi
524
524
  }
525
525
  }
526
526
  if (hit !== null) {
527
+ const refusal = readDenyRefusal({ target: path, canonical: key, pattern: hit.pattern, ...(hit.matchedView !== undefined ? { matchedView: hit.matchedView } : {}), ...(write ? { face: "write", ...(readDeny.guardsReads?.(hit.pattern) === true ? { readRow: true } : {}) } : {}) });
527
528
  return {
528
529
  ok: false,
529
530
  violation: {
530
531
  code: write ? "write_path_denied" : "read_path_denied",
531
- message: readDenySentence({ target: path, canonical: key, pattern: hit.pattern, ...(hit.matchedView !== undefined ? { matchedView: hit.matchedView } : {}), ...(write ? { face: "write", ...(readDeny.guardsReads?.(hit.pattern) === true ? { readRow: true } : {}) } : {}) }),
532
+ message: refusal.sentence,
532
533
  target: key,
533
534
  pattern: hit.pattern,
535
+ echoed: refusal.echoed,
534
536
  },
535
537
  };
536
538
  }
@@ -139,6 +139,7 @@ export function bare(r, provenance, spelled = r.folded) {
139
139
  raw: r.raw,
140
140
  provenance,
141
141
  expands: r.expands,
142
+ ...(r.bracket === true ? { bracket: true } : {}),
142
143
  ...(pattern !== undefined ? { pattern } : {}),
143
144
  ...(whole && r.homeFloor !== undefined ? { floorSpelled: r.homeFloor } : {}),
144
145
  ...(whole && r.floorValues !== undefined ? { floors: r.floorValues } : {}),
@@ -248,6 +248,11 @@ export interface ShellReadStationOptions {
248
248
  * questions name no directory to add — a card offering one would offer what nothing grants. Absent ⇒ offered. */
249
249
  readonly offersReadRootGrant?: false;
250
250
  }
251
+ /** The bound of ONE recursive removal's subtree search ({@link applyRemovalSearch}) — its own, shorter than the gate's outer
252
+ * wait (`DEFAULT_GATE_AWAIT_TIMEOUT_MS`); and the folders it lists at most. Either reached ⇒ the search did not finish: a
253
+ * check that did not finish, asked like any other ({@link applyRemovalSearch}). */
254
+ export declare const SUBTREE_SEARCH_MS = 2000;
255
+ export declare const SUBTREE_SEARCH_DIRS = 16384;
251
256
  /** What a consumer hands {@link judgeShellRead}: the command as written, the environment whose filesystem
252
257
  * answers where its words land (symlinks resolved, patterns expanded — a `NodeExecutionEnv` over a real
253
258
  * directory is what the gate itself runs on), the boundary it is judged against, and the trust-policy seat
@@ -305,8 +310,10 @@ export interface ShellReadJudgment {
305
310
  * home and the account home the account database answers once, for this call (`readDenyHomesOf`'s homes). Every home
306
311
  * beside the declared one waits at most a short bound of its own.
307
312
  *
308
- * It carries NO deadline. Bounding an environment-facing wait and substituting a fail-closed verdict is the
309
- * gate FOLD's policy on the gate's one deadline seat; the station has never held one on either entry, and a
313
+ * It carries NO deadline but one: a recursive removal's subtree search answers under its own short bound
314
+ * ({@link SUBTREE_SEARCH_MS}), as the extra homes above do — a search that ran out is the search's own refusal, not a
315
+ * silence. Bounding the judgment's other environment-facing waits and substituting a fail-closed verdict is the
316
+ * gate FOLD's policy on the gate's one deadline seat; the station holds no other on either entry, and a
310
317
  * second default here would decide the same number twice and turn a slow-but-correct filesystem's true
311
318
  * answer into a fail-closed one unasked. A consumer wanting that posture races its own deadline and reads
312
319
  * the row the gate's fallback reads: `SHELL_READ_DECISION.unanswered[seat]`.
@@ -1,4 +1,4 @@
1
- import { observeEnvironment } from "./shell-read-environment.js";
1
+ import { isAbsence, observeEnvironment } from "./shell-read-environment.js";
2
2
  import { errorResult } from "../../core/tools.js";
3
3
  import { BASH_READONLY_CONFINEMENT_NOTE, targetUnavailableCard, targetUnavailableSentence } from "./fs-shared.js";
4
4
  import { envErrorDetail } from "./env-error-detail.js";
@@ -8,7 +8,8 @@ import { INLINE_TRUNCATION_MARK_CODEPOINTS, inlineUntrusted, PROBE_REASON_MAX }
8
8
  import { NOT_AUTO_ALLOWED, declinedProgramReason } from "./bash-program-position.js";
9
9
  import { bashClassifyDefaultAllow } from "./bash-readonly-classifier.js";
10
10
  import { planShellReads } from "./shell-read-plan.js";
11
- import { createShellReadEstablisher, establishShellReadsLexically } from "./shell-read-establish.js";
11
+ import { readStationAnswer } from "../../core/shell-read-silence.js";
12
+ import { createShellReadEstablisher, establishShellReadsLexically, writtenOnLineBefore } from "./shell-read-establish.js";
12
13
  import { readLandingsOf } from "./shell-read-identity.js";
13
14
  import { declaredReadDenyHomes, homeViewsAt } from "./read-deny-home.js";
14
15
  import { anyOptionWord, programArgs } from "./shell-read-write-targets.js";
@@ -176,11 +177,7 @@ async function writeGuardsOf(judged, boundary, env, signal) {
176
177
  const dest = await probe(parentOf(view));
177
178
  return dest === undefined || dest.ok || (dest.error.code !== "not_found" && dest.error.code !== "not_directory");
178
179
  };
179
- const changedBefore = (view, at) => {
180
- const fold = (p) => p.normalize("NFC").toLowerCase();
181
- const dir = fold(parentOf(view));
182
- return writtenBy.some((paths, i) => i !== at && (i < at || concurrent) && paths.some((w) => withinAnyRoot([fold(w)], dir) || withinAnyRoot([dir], fold(w))));
183
- };
180
+ const changedBefore = (view, at) => writtenOnLineBefore(writtenBy, at, concurrent, parentOf(view));
184
181
  const answer = async (view, key) => (await judge(view, { fs: env, ...(signal !== undefined ? { signal } : {}), ...(key ? { canonical: true } : {}) })) ?? "clear";
185
182
  const asked = [...[...asKey].map(([view, v]) => [view, v, true]), ...[...asSpelling].filter(([view]) => !landingKeys.has(view)).map(([view, v]) => [view, v, false])];
186
183
  const slotOf = (view, key) => `${key || landingKeys.has(view) ? "key" : "spelling"}\u0000${view}`;
@@ -367,8 +364,8 @@ function refusalOf(tool, fold, boundary, paths) {
367
364
  if (fold.finding === "deny_hit" && w?.deny !== undefined) {
368
365
  const target = w.read.target ?? w.deny.matchedView;
369
366
  const write = w.deny.face === "write";
370
- const under = !write && w.deny.under === true;
371
- const { sentence: core, echoed } = readDenyRefusal({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}), ...(w.deny.readRow === true ? { readRow: true } : {}), ...(under ? { under: true } : {}) });
367
+ const under = w.deny.under === true;
368
+ const { sentence: core, echoed } = readDenyRefusal({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}), ...(w.deny.readRow === true ? { readRow: true } : {}), ...(under ? { under: true } : {}), ...(w.deny.lookup !== undefined ? { lookup: w.deny.lookup, action: "removing" } : {}) });
372
369
  const through = deniedThrough(w.read, boundary);
373
370
  const sentence = `Error (${tool}): ${core} ${write ? writeDenyRefusalNote() : under ? DENY_UNDER_REFUSAL_NOTE : DENY_REFUSAL_NOTE}${through !== undefined ? ` ${DENIED_THROUGH_NOTE[through]}` : ""}`;
374
371
  return { sentence, echoed, ...(write ? {} : { details: violationDetails({ code: "read_path_denied", message: sentence, target, pattern: w.deny.pattern }) }) };
@@ -473,12 +470,119 @@ async function applyAlsoInside(judged, boundary) {
473
470
  });
474
471
  return rewrite(judged);
475
472
  }
476
- async function runShellReadStation(tool, command, declared, seat, readers, establisher, env, signal) {
477
- const plan = planShellReads(command, declarationsOf(declared, readers, env.cdPath, env.receivedEnvNames));
473
+ export const SUBTREE_SEARCH_MS = 2_000;
474
+ export const SUBTREE_SEARCH_DIRS = 16_384;
475
+ async function searchSubtree(env, root, named, signal) {
476
+ const stop = new AbortController();
477
+ const timer = setTimeout(() => stop.abort(), SUBTREE_SEARCH_MS);
478
+ const onAbort = () => stop.abort();
479
+ signal?.addEventListener("abort", onAbort, { once: true });
480
+ const ended = new Promise((resolve) => stop.signal.addEventListener("abort", () => resolve("ended"), { once: true }));
481
+ const unfinished = (why) => ({ kind: "unfinished", why: signal?.aborted === true ? "the call was cancelled" : why });
482
+ const outOfTime = `the search ran past its ${SUBTREE_SEARCH_MS / 1000} s bound`;
483
+ try {
484
+ if (signal?.aborted === true)
485
+ return unfinished("");
486
+ const top = await Promise.race([env.fileInfo(root, stop.signal), ended]);
487
+ if (top === "ended")
488
+ return unfinished(outOfTime);
489
+ if (!top.ok)
490
+ return isAbsence(top.error.code) ? { kind: "clear" } : unfinished(`it could not be inspected (${top.error.code})`);
491
+ if (top.value.kind !== "directory")
492
+ return { kind: "clear" };
493
+ const queue = [root];
494
+ for (let listed = 0; queue.length > 0; listed++) {
495
+ if (listed >= SUBTREE_SEARCH_DIRS)
496
+ return unfinished(`it holds more than ${SUBTREE_SEARCH_DIRS} folders`);
497
+ const dir = queue.shift();
498
+ const entries = await Promise.race([env.listDir(dir, stop.signal), ended]);
499
+ if (entries === "ended")
500
+ return unfinished(outOfTime);
501
+ if (!entries.ok) {
502
+ if (isAbsence(entries.error.code))
503
+ continue;
504
+ return unfinished(`"${dir}" could not be listed (${entries.error.code})`);
505
+ }
506
+ for (const entry of entries.value) {
507
+ const at = `${dir.replace(/[\\/]+$/, "")}/${entry.name}`;
508
+ const pattern = named.ledBy(entry.name);
509
+ if (pattern !== null)
510
+ return { kind: "found", pattern, at };
511
+ if (entry.kind === "directory")
512
+ queue.push(at);
513
+ }
514
+ }
515
+ return { kind: "clear" };
516
+ }
517
+ catch {
518
+ return unfinished("the environment threw");
519
+ }
520
+ finally {
521
+ clearTimeout(timer);
522
+ signal?.removeEventListener("abort", onAbort);
523
+ }
524
+ }
525
+ function removesSubtree(f) {
526
+ const r = f.read;
527
+ return r.candidate.face === "write" && r.candidate.subtree === "removed" && r.written !== undefined && r.target !== undefined && (r.established === "canonical" || r.established === "expansion") && (f.kind === "none" || f.kind === "outside_roots");
528
+ }
529
+ async function applyRemovalSearch(judged, boundary, env, signal) {
530
+ const named = boundary.writeDenyNamed;
531
+ if (named === undefined || named.rows.length === 0)
532
+ return judged;
533
+ const searched = new Map();
534
+ const answered = new Map();
535
+ for (const f of allFindings(judged)) {
536
+ if (!removesSubtree(f))
537
+ continue;
538
+ const target = f.read.target;
539
+ let search = searched.get(target);
540
+ if (search === undefined)
541
+ searched.set(target, (search = searchSubtree(env, target, named, signal)));
542
+ const found = await search;
543
+ if (found.kind === "clear")
544
+ continue;
545
+ if (found.kind === "unfinished") {
546
+ const cause = `the folders below "${target}" could not all be searched for a name the deny rows ${named.rows.map((p) => `"${p}"`).join(", ")} start with: ${found.why}`;
547
+ answered.set(f, { read: { ...f.read, cause }, kind: "unanswered", denyRowUnasked: true, containment: f.containment });
548
+ continue;
549
+ }
550
+ const readRow = boundary.writeDenyGuardsReads?.(found.pattern) === true ? { readRow: true } : {};
551
+ answered.set(f, { ...f, kind: "deny_hit", deny: { pattern: found.pattern, matchedView: normalizeAbsPathLexically(target), face: "write", under: true, lookup: { found: found.at }, ...readRow } });
552
+ }
553
+ if (answered.size === 0)
554
+ return judged;
555
+ const rewrite = (j) => ({ ...j, segments: j.segments.map((s) => ({ ...s, findings: s.findings.map((f) => answered.get(f) ?? f), nested: s.nested.map(rewrite) })) });
556
+ return rewrite(judged);
557
+ }
558
+ const holdsBracket = (c) => c.bracket === true;
559
+ const bracketCause = (spelled) => `"${spelled}" holds a bracket expression, which the shell matches by its own collation and options, so it may reach names this station does not list`;
560
+ function bracketWordsUnvouched(tool, seat, run, verdict) {
561
+ if (readStationAnswer(verdict, { toolName: tool }).kind !== "vouch")
562
+ return verdict;
563
+ const unread = new Map();
564
+ for (const f of allFindings(run.judged)) {
565
+ if (f.kind === "none" && holdsBracket(f.read.candidate))
566
+ unread.set(f, { ...f, kind: "unestablishable", read: { ...f.read, cause: bracketCause(f.read.candidate.spelled) } });
567
+ }
568
+ if (unread.size === 0)
569
+ return verdict;
570
+ const rewrite = (j) => ({ ...j, segments: j.segments.map((s) => ({ ...s, findings: s.findings.map((f) => unread.get(f) ?? f), nested: s.nested.map(rewrite) })) });
571
+ const judged = rewrite(run.judged);
572
+ const fold = foldShellReadFindings(judged);
573
+ if (fold.finding === "none")
574
+ return verdict;
575
+ const question = withReadAsk(verdictOf(tool, seat, fold, judged, run.boundary), judged);
576
+ if (question.disposition === "refuse")
577
+ return question;
578
+ const { disposition: _vouch, finding: _none, ...facts } = verdict;
579
+ return { ...facts, ...question };
580
+ }
581
+ async function runShellReadStation(tool, plan, declared, seat, establisher, env, signal) {
478
582
  const door = observeEnvironment(env);
479
583
  const established = await establisher.establish(plan, declared, signal, door);
480
584
  const boundary = { ...declared, roots: established.roots };
481
- const onPlan = await applyAlsoInside(judgePlan(plan, established, boundary), boundary);
585
+ const onPlan = await applyRemovalSearch(await applyAlsoInside(judgePlan(plan, established, boundary), boundary), boundary, env, signal);
482
586
  const judgedNow = () => {
483
587
  const unfinished = door.incomplete();
484
588
  return unfinished.length > 0 ? { ...onPlan, incomplete: unfinished } : onPlan;
@@ -503,12 +607,16 @@ async function runShellReadStation(tool, command, declared, seat, readers, estab
503
607
  export async function judgeShellRead(input) {
504
608
  assertNoRetiredShellReadBoundaryKeys(input.boundary);
505
609
  const readers = input.readers ?? new Set(bashClassifyDefaultAllow());
506
- const run = await runShellReadStation(input.tool ?? "Bash", input.command, input.boundary, commandSeatOf(input.seat), readers, createShellReadEstablisher(input.env, input.boundary.roots, { homeViews: homeViewsAt(input.env, input.readDenyHomes === undefined ? declaredReadDenyHomes(input.env) : checkedReadDenyHomes(input.readDenyHomes)) }), input.env, input.signal);
507
- const offer = normalizeReadRootCandidate(run.verdict.readRootCandidate);
610
+ const plan = planShellReads(input.command, declarationsOf(input.boundary, readers, input.env.cdPath, input.env.receivedEnvNames));
611
+ const tool = input.tool ?? "Bash";
612
+ const seat = commandSeatOf(input.seat);
613
+ const run = await runShellReadStation(tool, plan, input.boundary, seat, createShellReadEstablisher(input.env, input.boundary.roots, { homeViews: homeViewsAt(input.env, input.readDenyHomes === undefined ? declaredReadDenyHomes(input.env) : checkedReadDenyHomes(input.readDenyHomes)) }), input.env, input.signal);
614
+ const verdict = bracketWordsUnvouched(tool, seat, run, run.verdict);
615
+ const offer = normalizeReadRootCandidate(verdict.readRootCandidate);
508
616
  return {
509
617
  plan: run.plan,
510
618
  establishment: allFindings(run.judged).map((f) => f.read),
511
- verdict: run.verdict,
619
+ verdict,
512
620
  ...(offer !== undefined ? { offer } : {}),
513
621
  };
514
622
  }
@@ -567,16 +675,20 @@ export function createShellReadStation(opts) {
567
675
  return null;
568
676
  const seat = callOpts.seat ?? opts.seatOf(member);
569
677
  return (async () => {
570
- const run = await runShellReadStation(call.toolName, command, boundary, seat, readers, establisherFor(boundary.roots), opts.env, signal);
678
+ const plan = planShellReads(command, declarationsOf(boundary, readers, opts.env.cdPath, opts.env.receivedEnvNames));
679
+ const run = await runShellReadStation(call.toolName, plan, boundary, seat, establisherFor(boundary.roots), opts.env, signal);
571
680
  if (run.verdict.disposition !== "refuse" && callOpts.toolCallId !== undefined)
572
681
  remember(callOpts.toolCallId, { toolName: member, boundary: run.boundary, established: run.established, command });
573
682
  const verdict = opts.offersReadRootGrant === false ? withoutGrantOffer(run.verdict) : run.verdict;
574
- if (boundary.unreadPartitions !== true)
575
- return verdict;
576
- if (verdict.disposition !== "vouch")
577
- return { ...verdict, rowsUnread: true };
578
- const unread = unansweredOver(call.toolName, seat, "the rules this check stands on could not all be read", boundary, { rowsUnread: true });
579
- return unread.disposition === "refuse" || verdict.askRule === undefined ? unread : { ...unread, askRule: verdict.askRule, ...(verdict.askRuleOfPolicy === true ? { askRuleOfPolicy: true } : {}) };
683
+ const answered = (() => {
684
+ if (boundary.unreadPartitions !== true)
685
+ return verdict;
686
+ if (verdict.disposition !== "vouch")
687
+ return { ...verdict, rowsUnread: true };
688
+ const unread = unansweredOver(call.toolName, seat, "the rules this check stands on could not all be read", boundary, { rowsUnread: true });
689
+ return unread.disposition === "refuse" || verdict.askRule === undefined ? unread : { ...unread, askRule: verdict.askRule, ...(verdict.askRuleOfPolicy === true ? { askRuleOfPolicy: true } : {}) };
690
+ })();
691
+ return bracketWordsUnvouched(call.toolName, seat, run, answered);
580
692
  })();
581
693
  },
582
694
  unanswered(call, cause) {
@@ -92,6 +92,15 @@ export interface ShellReadEstablisher {
92
92
  readonly changed: readonly EstablishedRead[];
93
93
  }>;
94
94
  }
95
+ /**
96
+ * THE order judgment of a line's writes, one for every reader of a filesystem fact taken before the line runs (the
97
+ * establishment's {@link JudgedCandidate.onlyIf} facts, the write guards' writability): does a run BEFORE run `at` — or beside
98
+ * it, where the line runs segments at once (a pipe, a background) — write on the line of `place` (that path, a path above it
99
+ * or one below it)? A later run cannot change what run `at` meets (`cp a b && touch b`: the copy meets the tree before the
100
+ * touch). `writes[i]` is what the i-th run writes. Compared with letter case and composition folded: on a filesystem that
101
+ * ignores them (`mkdir BOX && cp x box`) two spellings are one place, and a fold that only over-matches keeps the fact unsettled.
102
+ */
103
+ export declare function writtenOnLineBefore(writes: readonly (readonly string[])[], at: number, concurrent: boolean, place: string): boolean;
95
104
  /**
96
105
  * The PURE, lexical establishment of a whole plan — what an isolated sandbox gets, and what any consumer
97
106
  * with no environment in hand (a unit pin, a lexical pre-read) can compute. Patterns and traversal roots
@@ -160,11 +160,20 @@ function lexicalReadsOf(candidate, boundary, placed) {
160
160
  }
161
161
  function writtenByText(plan, boundary) {
162
162
  const targets = new Set();
163
- const writers = new Map();
163
+ const runs = [];
164
+ const writes = [];
165
+ let concurrent = false;
164
166
  const speculativeSeen = new Set();
165
167
  let unplaced = false;
166
168
  const walk = (p) => {
167
169
  for (const s of p.segments) {
170
+ for (const n of s.nested)
171
+ walk(n);
172
+ const wrote = [];
173
+ runs.push(s);
174
+ writes.push(wrote);
175
+ if (p.shape.backgrounded || s.connector === "|")
176
+ concurrent = true;
168
177
  for (const c of s.reads) {
169
178
  if (c.speculative === undefined || c.expands !== false || c.bases === "unmodelled")
170
179
  continue;
@@ -190,16 +199,19 @@ function writtenByText(plan, boundary) {
190
199
  else {
191
200
  const t = normalizeAbsPathLexically(r.target);
192
201
  targets.add(t);
193
- writers.set(t, (writers.get(t) ?? new Set()).add(s));
202
+ wrote.push(t);
194
203
  }
195
204
  }
196
205
  }
197
- for (const n of s.nested)
198
- walk(n);
199
206
  }
200
207
  };
201
208
  walk(plan);
202
- return { targets, unplaced, writers };
209
+ return { targets, unplaced, runs, writes, concurrent };
210
+ }
211
+ export function writtenOnLineBefore(writes, at, concurrent, place) {
212
+ const fold = (p) => p.normalize("NFC").toLowerCase();
213
+ const here = fold(place);
214
+ return writes.some((paths, i) => i !== at && (i < at || concurrent) && paths.some((w) => withinAnyRoot([fold(w)], here) || withinAnyRoot([here], fold(w))));
203
215
  }
204
216
  function unfollowedBackupReads(j, boundary, cause) {
205
217
  const named = sedBackupNames(j.followed.operand.spelled, j.followed.suffix).flatMap((name) => lexicalReadsOf({ ...j.candidate, spelled: name }, boundary));
@@ -558,15 +570,13 @@ function establishLegOver(seen, readRoots) {
558
570
  for (const r of lexicalReadsOf(fact.candidate, boundary)) {
559
571
  if (r.established !== "lexical" || r.target === undefined)
560
572
  return undefined;
561
- const place = normalizeAbsPathLexically(r.target);
562
- for (const [t, by] of written.writers)
563
- if ((t === place || withinAnyRoot([place], t)) && [...by].some((s) => s !== segment))
564
- return undefined;
573
+ if (writtenOnLineBefore(written.writes, written.runs.indexOf(segment), written.concurrent, normalizeAbsPathLexically(r.target)))
574
+ return undefined;
565
575
  const at = fact.seat === "entry" ? await entryOf(r.target, signal) : await resolve(r.target, signal);
566
576
  if (at === undefined || (!at.exact && at.missing !== true))
567
577
  return undefined;
568
- const info = at.missing === true && !at.exact ? undefined : await env.fileInfo(at.value, signal);
569
- const here = info === undefined ? false : info.ok ? info.value.kind === "directory" : isAbsence(info.error.code) ? false : undefined;
578
+ const info = at.missing === true && !at.exact ? undefined : fact.seat === "entry" ? await env.fileInfo(at.value, signal) : await env.listDir(at.value, signal);
579
+ const here = info === undefined ? false : info.ok ? Array.isArray(info.value) || info.value.kind === "directory" : isAbsence(info.error.code) ? false : undefined;
570
580
  if (here === undefined || (directory !== undefined && directory !== here))
571
581
  return undefined;
572
582
  directory = here;
@@ -27,7 +27,7 @@ import type { ReadCandidate, ShellReadPlan, ShellReadSegment } from "./shell-rea
27
27
  import type { Incomplete, ObservedFilesystem } from "./shell-read-environment.js";
28
28
  import type { WriteSeat } from "./shell-read-write-targets.js";
29
29
  import { type ContainmentFace } from "./containment-face.js";
30
- import { type JudgedPathRow } from "./read-deny.js";
30
+ import { type JudgedPathRow, type ReadDenyFinding, type ReadDenyRootAnswer } from "./read-deny.js";
31
31
  import type { AssertAllKeysHandled } from "../../core/ask-origin.js";
32
32
  /** WHAT the judge found about a command — a closed set, registered in `docs/CLOSED-SETS.md`. */
33
33
  export declare const SHELL_READ_FINDINGS: readonly ["deny_hit", "outside_roots", "unestablishable", "declined", "identity_changed", "unanswered", "target_unavailable", "none"];
@@ -241,6 +241,17 @@ export interface ShellReadBoundary extends BashReadonlyRootBoundary {
241
241
  /** Does the row `writeDenyMatch` named (its rule) guard the READ face too — a `Read(…)` rule on the write face
242
242
  * ({@link import("./read-deny.js").WriteDenyMatcher.guardsReads})? Read once per hit, so the refusal says which family refused. */
243
243
  readonly writeDenyGuardsReads?: (pattern: string) => boolean;
244
+ /** The write table's rows named by or below a subtree removal/rename target (`WriteDenyMatcher.rowUnderRoot`). */
245
+ readonly writeDenyUnder?: (resolvedPath: string) => ReadDenyRootAnswer;
246
+ /** The write table's unanchored rows (`WriteDenyMatcher.unanchoredRows`, never empty here) and the first of them whose leading
247
+ * name one directory entry name matches (`WriteDenyMatcher.rowLedByName`): what the station searches a recursive removal's
248
+ * subtree for, under its own bound ({@link import("./shell-read-check.js").SUBTREE_SEARCH_MS}). PRESENT-IFF such a row. */
249
+ readonly writeDenyNamed?: {
250
+ readonly rows: readonly string[];
251
+ readonly ledBy: (entryName: string) => string | null;
252
+ };
253
+ /** The write table's rows AT or BELOW a path (`WriteDenyMatcher.rowAtOrBelow`): read by `writesPlaced` via {@link denyRowAtOrBelow}. */
254
+ readonly writeDenyAtOrBelow?: (resolvedPath: string) => string | null;
244
255
  /** The read table's rows AT or BELOW a path (`readDenySeat`'s `denyAtOrBelow`, read-deny.ts): read by the station's
245
256
  * `writesPlaced` fact only, through {@link denyRowAtOrBelow}. */
246
257
  readonly denyAtOrBelow?: (resolvedPath: string) => string | null;
@@ -355,6 +366,7 @@ export interface ReadFinding {
355
366
  readonly face?: "write";
356
367
  readonly readRow?: true;
357
368
  readonly under?: true;
369
+ readonly lookup?: ReadDenyFinding["lookup"];
358
370
  };
359
371
  /** A `deny_hit` on no row: the read's target is a process-private /proc file (`isProcSensitiveFile`, safety.ts — the set the
360
372
  * file read tools refuse), or a tree walk's root holds such files (`holdsProcSensitiveFile`); the view it was matched on. */