@sema-agent/core 7.62.0 → 7.64.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 (320) hide show
  1. package/CHANGELOG.md +936 -0
  2. package/dist/agents/cc-peer-directory.js +1 -0
  3. package/dist/agents/cc-peer-wire.d.ts +4 -0
  4. package/dist/agents/cc-peer-wire.js +1 -0
  5. package/dist/agents/cc-uds-peer-channel.js +5 -0
  6. package/dist/agents/cross-session-judge.d.ts +3 -1
  7. package/dist/agents/cross-session-judge.js +4 -1
  8. package/dist/agents/peer-directory.d.ts +8 -0
  9. package/dist/agents/peer-directory.js +4 -0
  10. package/dist/agents/peer-held-queue.d.ts +9 -3
  11. package/dist/agents/peer-held-queue.js +12 -9
  12. package/dist/agents/peer-idle.d.ts +20 -1
  13. package/dist/agents/peer-idle.js +23 -12
  14. package/dist/agents/peer-notice-route.d.ts +16 -5
  15. package/dist/agents/peer-notice-route.js +11 -9
  16. package/dist/agents/peer-notices.d.ts +25 -8
  17. package/dist/agents/peer-notices.js +6 -1
  18. package/dist/agents/peer-session-drain.d.ts +32 -6
  19. package/dist/agents/peer-session-drain.js +100 -26
  20. package/dist/agents/send-message-tool.d.ts +7 -0
  21. package/dist/agents/send-message-tool.js +18 -6
  22. package/dist/agents/subagent-transcript-placement.d.ts +23 -0
  23. package/dist/agents/subagent-transcript-placement.js +14 -0
  24. package/dist/agents/subagent.js +102 -54
  25. package/dist/brain/route-adjudicator.js +9 -4
  26. package/dist/core/allow-entry.d.ts +4 -0
  27. package/dist/core/approval-object.js +1 -1
  28. package/dist/core/arg-summary.js +1 -1
  29. package/dist/core/ask-origin.d.ts +1 -1
  30. package/dist/core/ask-origin.js +2 -2
  31. package/dist/core/ask-question.d.ts +2 -2
  32. package/dist/core/ask-unresolvable-notice.d.ts +13 -4
  33. package/dist/core/ask-unresolvable-notice.js +10 -3
  34. package/dist/core/auto-compaction.d.ts +7 -5
  35. package/dist/core/background-agent-store.d.ts +7 -0
  36. package/dist/core/background-agent-store.js +3 -0
  37. package/dist/core/canonical-json.d.ts +23 -13
  38. package/dist/core/canonical-json.js +4 -4
  39. package/dist/core/checkpoint-queries.d.ts +50 -4
  40. package/dist/core/checkpoint-queries.js +42 -17
  41. package/dist/core/checkpoint-requirements.d.ts +3 -3
  42. package/dist/core/checkpoint-requirements.js +2 -1
  43. package/dist/core/checkpoint-row-verdict.d.ts +15 -4
  44. package/dist/core/checkpoint-row-verdict.js +22 -2
  45. package/dist/core/checkpoint-store.d.ts +28 -11
  46. package/dist/core/checkpoint-store.js +45 -4
  47. package/dist/core/compliance.d.ts +6 -2
  48. package/dist/core/compliance.js +3 -3
  49. package/dist/core/context-settings.d.ts +40 -9
  50. package/dist/core/context-settings.js +32 -10
  51. package/dist/core/engine-attestation.d.ts +27 -7
  52. package/dist/core/engine-attestation.js +5 -1
  53. package/dist/core/engine-notice.d.ts +43 -5
  54. package/dist/core/extension-requester.d.ts +9 -0
  55. package/dist/core/extension-requester.js +7 -0
  56. package/dist/core/file-history-store.d.ts +28 -0
  57. package/dist/core/file-history-store.js +48 -5
  58. package/dist/core/fs-write-gate-policy.js +1 -1
  59. package/dist/core/gate-fold.js +2 -0
  60. package/dist/core/gate-lanes.js +2 -0
  61. package/dist/core/gate-outcome.d.ts +39 -2
  62. package/dist/core/gate-outcome.js +20 -1
  63. package/dist/core/git-worktree-env.d.ts +62 -3
  64. package/dist/core/git-worktree-env.js +91 -30
  65. package/dist/core/governance-codes.d.ts +9 -3
  66. package/dist/core/governance-codes.js +17 -3
  67. package/dist/core/leg-identity.d.ts +19 -1
  68. package/dist/core/leg-identity.js +12 -0
  69. package/dist/core/mailbox-store.d.ts +39 -4
  70. package/dist/core/mailbox-store.js +14 -2
  71. package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
  72. package/dist/core/memory-engine/consolidation-driver.js +99 -98
  73. package/dist/core/memory-engine/consolidation.d.ts +74 -10
  74. package/dist/core/memory-engine/consolidation.js +183 -11
  75. package/dist/core/memory-engine/control-objects.d.ts +25 -0
  76. package/dist/core/memory-engine/control-objects.js +151 -0
  77. package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
  78. package/dist/core/memory-engine/control-plane-adoption.js +159 -0
  79. package/dist/core/memory-engine/data-plane.d.ts +8 -4
  80. package/dist/core/memory-engine/data-plane.js +11 -6
  81. package/dist/core/memory-engine/delegation-settlement.d.ts +58 -40
  82. package/dist/core/memory-engine/delegation-settlement.js +270 -85
  83. package/dist/core/memory-engine/dual-root.d.ts +12 -6
  84. package/dist/core/memory-engine/dual-root.js +11 -7
  85. package/dist/core/memory-engine/engine.d.ts +136 -58
  86. package/dist/core/memory-engine/engine.js +491 -394
  87. package/dist/core/memory-engine/entry-scan.d.ts +8 -0
  88. package/dist/core/memory-engine/entry-scan.js +3 -0
  89. package/dist/core/memory-engine/file-backend.d.ts +62 -60
  90. package/dist/core/memory-engine/file-backend.js +122 -198
  91. package/dist/core/memory-engine/index.d.ts +8 -7
  92. package/dist/core/memory-engine/index.js +7 -6
  93. package/dist/core/memory-engine/landing-admission.d.ts +5 -3
  94. package/dist/core/memory-engine/landing-admission.js +3 -3
  95. package/dist/core/memory-engine/layout.d.ts +127 -46
  96. package/dist/core/memory-engine/layout.js +264 -109
  97. package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
  98. package/dist/core/memory-engine/memory-backend-contract.js +476 -0
  99. package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
  100. package/dist/core/memory-engine/memory-deployment.js +54 -15
  101. package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
  102. package/dist/core/memory-engine/origin-clearance.js +68 -9
  103. package/dist/core/memory-engine/scope-contract.d.ts +52 -11
  104. package/dist/core/memory-engine/scope-contract.js +68 -19
  105. package/dist/core/memory-engine/session-write-home.d.ts +37 -2
  106. package/dist/core/memory-engine/session-write-home.js +38 -11
  107. package/dist/core/memory-engine/sync-client.d.ts +3 -1
  108. package/dist/core/memory-engine/sync-client.js +7 -0
  109. package/dist/core/memory-engine/sync-report.d.ts +3 -2
  110. package/dist/core/memory-engine/sync-report.js +6 -2
  111. package/dist/core/memory-engine/tools.d.ts +2 -2
  112. package/dist/core/memory-engine/tools.js +10 -10
  113. package/dist/core/memory-engine/types.d.ts +155 -19
  114. package/dist/core/memory-engine/types.js +2 -0
  115. package/dist/core/memory.js +15 -6
  116. package/dist/core/mode-policy.js +3 -3
  117. package/dist/core/mods/agent-stations.d.ts +18 -0
  118. package/dist/core/mods/agent-stations.js +8 -6
  119. package/dist/core/mods/extension-call.d.ts +4 -0
  120. package/dist/core/mods/extension-call.js +8 -0
  121. package/dist/core/mods/stations.d.ts +20 -1
  122. package/dist/core/mods/stations.js +21 -2
  123. package/dist/core/mods/tool-call.js +3 -4
  124. package/dist/core/parent-spec-seat.d.ts +2 -2
  125. package/dist/core/park-selfcheck.js +2 -2
  126. package/dist/core/pause-registry.d.ts +2 -0
  127. package/dist/core/pause-registry.js +3 -0
  128. package/dist/core/peer-channel.d.ts +5 -0
  129. package/dist/core/permission-rule-consent.d.ts +26 -8
  130. package/dist/core/permission-rule-consent.js +76 -36
  131. package/dist/core/permission-rule-store.d.ts +72 -13
  132. package/dist/core/permission-rule-store.js +29 -8
  133. package/dist/core/read-only-shell.js +3 -2
  134. package/dist/core/redaction-marks.d.ts +8 -0
  135. package/dist/core/redaction-marks.js +6 -0
  136. package/dist/core/refusal-echo.d.ts +20 -0
  137. package/dist/core/refusal-echo.js +33 -0
  138. package/dist/core/remote-env.d.ts +12 -1
  139. package/dist/core/remote-env.js +3 -0
  140. package/dist/core/retention.d.ts +180 -10
  141. package/dist/core/retention.js +45 -0
  142. package/dist/core/retired-keys.d.ts +5 -0
  143. package/dist/core/retired-keys.js +3 -0
  144. package/dist/core/rule-offer-read.d.ts +0 -4
  145. package/dist/core/rule-offer-read.js +2 -18
  146. package/dist/core/runner/child-tree.d.ts +29 -3
  147. package/dist/core/runner/child-tree.js +39 -16
  148. package/dist/core/runner/classifier-ladder.d.ts +7 -1
  149. package/dist/core/runner/classifier-ladder.js +4 -2
  150. package/dist/core/runner/compact-session.js +10 -7
  151. package/dist/core/runner/compaction-call-options.d.ts +7 -7
  152. package/dist/core/runner/compaction-call-options.js +3 -2
  153. package/dist/core/runner/contracts.d.ts +39 -11
  154. package/dist/core/runner/delegation-owner.d.ts +10 -3
  155. package/dist/core/runner/delegation-owner.js +4 -1
  156. package/dist/core/runner/gate-exit.d.ts +6 -0
  157. package/dist/core/runner/gate-exit.js +13 -4
  158. package/dist/core/runner/inherited-ask-grants.js +1 -1
  159. package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
  160. package/dist/core/runner/memory-consolidation-driver.js +12 -9
  161. package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
  162. package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
  163. package/dist/core/runner/person-path-rows.d.ts +8 -3
  164. package/dist/core/runner/person-path-rows.js +5 -1
  165. package/dist/core/runner/placement-fence.d.ts +12 -0
  166. package/dist/core/runner/placement-fence.js +20 -6
  167. package/dist/core/runner/prepare-ask-lane.js +5 -5
  168. package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
  169. package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
  170. package/dist/core/runner/prepare-config-doors.js +4 -0
  171. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  172. package/dist/core/runner/prepare-delegation-surface.js +2 -2
  173. package/dist/core/runner/prepare-execution-env.js +17 -6
  174. package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
  175. package/dist/core/runner/prepare-gate-stations.js +5 -5
  176. package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
  177. package/dist/core/runner/prepare-hands-readface.js +5 -4
  178. package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
  179. package/dist/core/runner/prepare-inherited-gate.js +12 -6
  180. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
  181. package/dist/core/runner/prepare-memory-engine-session.js +4 -4
  182. package/dist/core/runner/prepare-memory.d.ts +7 -2
  183. package/dist/core/runner/prepare-memory.js +41 -39
  184. package/dist/core/runner/prepare-park-ask.js +4 -3
  185. package/dist/core/runner/prepare-policy-chain.js +7 -7
  186. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  187. package/dist/core/runner/prepare-task.js +26 -18
  188. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  189. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  190. package/dist/core/runner/prepare-workspace-restore.js +3 -6
  191. package/dist/core/runner/resume-admission.d.ts +2 -2
  192. package/dist/core/runner/resume-admission.js +2 -23
  193. package/dist/core/runner/role-resolution-table.d.ts +98 -0
  194. package/dist/core/runner/role-resolution-table.js +62 -0
  195. package/dist/core/runner/run-compaction-machinery.js +2 -2
  196. package/dist/core/runner/run-identity-wiring.js +12 -9
  197. package/dist/core/runner/run-leg.js +9 -5
  198. package/dist/core/runner/run-notification-lane.js +22 -22
  199. package/dist/core/runner/run-recovery-lanes.js +3 -3
  200. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  201. package/dist/core/runner/run-terminal-adoption.js +1 -1
  202. package/dist/core/runner/run-turn-boundary.js +14 -15
  203. package/dist/core/runner/runtask.js +1 -1
  204. package/dist/core/runner/terminal-account.js +1 -1
  205. package/dist/core/runner/tool-occurrence.d.ts +4 -2
  206. package/dist/core/runner/tool-occurrence.js +2 -2
  207. package/dist/core/runner-deps.d.ts +7 -3
  208. package/dist/core/secret-env.d.ts +1 -1
  209. package/dist/core/secret-env.js +4 -4
  210. package/dist/core/session-checkout.d.ts +168 -0
  211. package/dist/core/session-checkout.js +579 -0
  212. package/dist/core/session-store.d.ts +12 -4
  213. package/dist/core/session-store.js +23 -3
  214. package/dist/core/session.d.ts +16 -2
  215. package/dist/core/session.js +3 -0
  216. package/dist/core/shell-read-silence.js +8 -0
  217. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
  218. package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
  219. package/dist/core/store-contracts/peer-directory-contract.js +8 -1
  220. package/dist/core/store-contracts/session-store-contract.js +39 -0
  221. package/dist/core/task-event.d.ts +30 -5
  222. package/dist/core/task-notification.d.ts +119 -32
  223. package/dist/core/task-notification.js +186 -100
  224. package/dist/core/task-registry-agent.d.ts +25 -2
  225. package/dist/core/task-registry-agent.js +56 -22
  226. package/dist/core/task-registry-shared.d.ts +33 -11
  227. package/dist/core/task-registry.d.ts +33 -9
  228. package/dist/core/task-registry.js +36 -18
  229. package/dist/core/task-spec-members.js +1 -1
  230. package/dist/core/task-spec.d.ts +27 -2
  231. package/dist/core/tool-errors.d.ts +14 -6
  232. package/dist/core/tool-errors.js +1 -1
  233. package/dist/core/tool-policy.d.ts +32 -13
  234. package/dist/core/tool-policy.js +27 -17
  235. package/dist/core/tool-result-store.d.ts +20 -0
  236. package/dist/core/tool-spec.d.ts +42 -19
  237. package/dist/core/trace.d.ts +3 -2
  238. package/dist/core/types.d.ts +1 -1
  239. package/dist/core/untrusted-egress.d.ts +15 -4
  240. package/dist/core/untrusted-egress.js +23 -22
  241. package/dist/core/workflow-journal-store.d.ts +11 -0
  242. package/dist/core/workflow-journal-store.js +7 -0
  243. package/dist/core/workflow-run-store.d.ts +9 -0
  244. package/dist/core/workflow-run-store.js +6 -0
  245. package/dist/core/workspace-snapshot.d.ts +3 -1
  246. package/dist/core/workspace-snapshot.js +1 -0
  247. package/dist/engine/compaction/compaction.d.ts +2 -1
  248. package/dist/engine/harness/types.d.ts +67 -1
  249. package/dist/engine/harness/types.js +108 -0
  250. package/dist/engine/session/import-validate.js +6 -1
  251. package/dist/engine/session/session.d.ts +30 -1
  252. package/dist/engine/session/session.js +48 -1
  253. package/dist/index.d.ts +12 -7
  254. package/dist/index.js +12 -7
  255. package/dist/internal/harness-types.d.ts +1 -1
  256. package/dist/orchestration/run-workflow-tool.d.ts +8 -1
  257. package/dist/orchestration/run-workflow-tool.js +8 -0
  258. package/dist/orchestration/workflow-types.d.ts +2 -1
  259. package/dist/orchestration/workflow.d.ts +6 -0
  260. package/dist/orchestration/workflow.js +5 -2
  261. package/dist/stores/file/checkpoint-store.d.ts +6 -0
  262. package/dist/stores/file/checkpoint-store.js +4 -1
  263. package/dist/stores/file/file-history-store.d.ts +13 -0
  264. package/dist/stores/file/file-history-store.js +75 -13
  265. package/dist/stores/file/index.d.ts +11 -1
  266. package/dist/stores/file/index.js +7 -11
  267. package/dist/stores/file/permission-rule-store.d.ts +23 -0
  268. package/dist/stores/file/permission-rule-store.js +75 -7
  269. package/dist/stores/file/session-store.js +2 -1
  270. package/dist/stores/file/tool-result-store.d.ts +14 -0
  271. package/dist/stores/file/tool-result-store.js +39 -2
  272. package/dist/stores/file/workflow-journal-store.d.ts +4 -0
  273. package/dist/stores/file/workflow-journal-store.js +17 -0
  274. package/dist/stores/file/workflow-run-store.d.ts +3 -0
  275. package/dist/stores/file/workflow-run-store.js +15 -0
  276. package/dist/tools/fs/bash-program-position.js +3 -3
  277. package/dist/tools/fs/program-read-model.d.ts +34 -10
  278. package/dist/tools/fs/program-read-model.js +37 -7
  279. package/dist/tools/fs/program-read-model.rows.js +13 -2
  280. package/dist/tools/fs/read-deny.d.ts +28 -3
  281. package/dist/tools/fs/read-deny.js +18 -2
  282. package/dist/tools/fs/removal-targets.js +3 -3
  283. package/dist/tools/fs/safety.d.ts +2 -0
  284. package/dist/tools/fs/safety.js +1 -1
  285. package/dist/tools/fs/shell-read-argv.d.ts +8 -1
  286. package/dist/tools/fs/shell-read-argv.js +34 -29
  287. package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
  288. package/dist/tools/fs/shell-read-bindings.js +5 -1
  289. package/dist/tools/fs/shell-read-brace.d.ts +18 -0
  290. package/dist/tools/fs/shell-read-brace.js +79 -0
  291. package/dist/tools/fs/shell-read-check.d.ts +8 -2
  292. package/dist/tools/fs/shell-read-check.js +16 -14
  293. package/dist/tools/fs/shell-read-establish.js +23 -16
  294. package/dist/tools/fs/shell-read-judge.d.ts +11 -0
  295. package/dist/tools/fs/shell-read-judge.js +3 -3
  296. package/dist/tools/fs/shell-read-plan.d.ts +10 -0
  297. package/dist/tools/fs/shell-read-plan.js +189 -93
  298. package/dist/tools/fs/shell-read-start.d.ts +19 -9
  299. package/dist/tools/fs/shell-read-start.js +20 -12
  300. package/dist/tools/fs/shell-read-word.d.ts +10 -0
  301. package/dist/tools/fs/shell-read-word.js +9 -5
  302. package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
  303. package/dist/tools/fs/shell-read-workdir.js +73 -12
  304. package/dist/tools/fs/shell-read-write-targets.js +13 -8
  305. package/dist/tools/worktree.d.ts +3 -2
  306. package/dist/tools/worktree.js +7 -35
  307. package/package.json +3 -2
  308. package/test/export-surface.snapshot.json +135 -11
  309. package/wire-changes/core-stores-sql@7.63.0.json +30 -0
  310. package/wire-changes/core-stores-sql@7.64.0.json +30 -0
  311. package/wire-changes/core@7.63.0.json +3523 -0
  312. package/wire-changes/core@7.64.0.json +2653 -0
  313. package/wire-changes/mods-kernel@7.63.0.json +30 -0
  314. package/wire-changes/mods-kernel@7.64.0.json +30 -0
  315. package/wire-changes/primitives@7.63.0.json +445 -0
  316. package/wire-changes/primitives@7.64.0.json +30 -0
  317. package/dist/core/credential-vocabulary.d.ts +0 -176
  318. package/dist/core/credential-vocabulary.js +0 -190
  319. package/dist/core/redaction-passes.d.ts +0 -82
  320. package/dist/core/redaction-passes.js +0 -377
@@ -1,3 +1,4 @@
1
+ import type { RefusalEcho } from "../../core/refusal-echo.js";
1
2
  import { type PathGuardFold, type PathGuardRow, type PathRowsHit, type TargetViews } from "../../core/path-guard-rows.js";
2
3
  /**
3
4
  * One deny entry: a `/`-separated run of path SEGMENTS. `*` matches any run of non-separator
@@ -167,6 +168,10 @@ export interface WriteDenyMatcher {
167
168
  }): ReadDenyHit | null;
168
169
  /** The table ONE call judges with ({@link ReadDenyMatcher.forCall}). */
169
170
  forCall?(toolCallId: string | undefined): WriteDenyMatcher;
171
+ /** Is the row a hit named (its rule text) a row that guards the READ face too — a `Read(…)` rule on the write face, whose
172
+ * paths are not written because their reads are denied — rather than a row of the write face alone? The refusal's sentence
173
+ * says which of the two refused ({@link readDenySentence}'s `readRow`). Absent ⇒ no row of this table guards reads. */
174
+ guardsReads?(pattern: string): boolean;
170
175
  }
171
176
  /** Compile the write face over the rule rows (the rows not on it are dropped here, once). */
172
177
  export declare function compileWriteDeny(rules?: readonly PathRuleDenyRow[]): WriteDenyMatcher;
@@ -288,6 +293,8 @@ export declare function sensitivePathDenyList(pattern: string | readonly string[
288
293
  export declare const SENSITIVE_PATH_DENY_SCOPE = "This list guards credential-class paths and applies regardless of the containment roots.";
289
294
  /** The write face's reach, in the same place of the sentence: a write deny row holds under every root and every mode. */
290
295
  export declare const WRITE_DENY_SCOPE = "A write deny row holds regardless of the containment roots and of the permission mode.";
296
+ /** The same place, for a write refused by a row of the READ face (a `Read(…)` rule): it holds on writes as it holds on reads. */
297
+ export declare const READ_ROW_WRITE_SCOPE = "A read deny row holds on writes too, regardless of the containment roots and of the permission mode.";
291
298
  /**
292
299
  * THE deny refusal sentence — five segments, one mint, every read face: the ACTION, the ABSOLUTE target as the
293
300
  * caller spelled it (with its canonical target in parentheses when the two differ), the DISPOSITION (a deny row is
@@ -296,9 +303,13 @@ export declare const WRITE_DENY_SCOPE = "A write deny row holds regardless of th
296
303
  * when that is the requested SPELLING rather than the target — under a symlink or case alias the two strings
297
304
  * differ, only one matches, and naming the other sends the reader chasing a path the pattern does not match.
298
305
  * A face prefixes its own `Error (<tool>): ` and may append its own closing clause; the finding itself is
299
- * never re-spelled.
306
+ * never re-spelled. One variant, by the row's family and not by the face alone: a write refused by a `Read(…)` row
307
+ * ({@link WriteDenyMatcher.guardsReads}) says the path's reads are denied, where a row of the write face alone says the
308
+ * write list.
300
309
  */
301
- export declare function readDenySentence(finding: {
310
+ export declare function readDenySentence(finding: ReadDenyFinding): string;
311
+ /** One deny finding: what the sentence of {@link readDenyRefusal} says and the list of literals it quotes are both read off it. */
312
+ export interface ReadDenyFinding {
302
313
  readonly action?: string;
303
314
  readonly target: string;
304
315
  readonly canonical?: string;
@@ -306,7 +317,21 @@ export declare function readDenySentence(finding: {
306
317
  readonly matchedView?: string;
307
318
  /** The table face that refused (default `read`): a write-face hit names the write list and its reach, and writes. */
308
319
  readonly face?: DenyFace;
309
- }): string;
320
+ /** On the write face: the row that refused is a row of the READ face too ({@link WriteDenyMatcher.guardsReads}) — a
321
+ * `Read(…)` rule, not a rule about writing. The sentence then says the path's reads are denied, which is why it is not
322
+ * written, instead of calling a read row a write deny row. */
323
+ readonly readRow?: true;
324
+ }
325
+ /**
326
+ * The deny finding minted ONCE as both of its faces: the sentence ({@link readDenySentence}) and the literals that sentence
327
+ * quotes, in the order it quotes them — the target (with its canonical target where the sentence names one), the view the
328
+ * pattern actually hit when that is a spelling other than the target, and the pattern. The list holds each literal whole; only the
329
+ * sentence elides the middle of a long one.
330
+ */
331
+ export declare function readDenyRefusal(finding: ReadDenyFinding): {
332
+ readonly sentence: string;
333
+ readonly echoed: readonly RefusalEcho[];
334
+ };
310
335
  /** The per-part budget of the deny sentence — the gate's own card-account cap, not a second number. */
311
336
  export declare const READ_DENY_SENTENCE_PART_MAX = 200;
312
337
  /** `s` verbatim when it fits `budget`, else elided in its MIDDLE ({@link elideMiddle}). */
@@ -150,12 +150,13 @@ function denyTargetViews(canonicalKey, lexicalView, opts) {
150
150
  }
151
151
  export function compileWriteDeny(rules = []) {
152
152
  const ruleRows = rules.filter((r) => r.faces.includes("write"));
153
+ const readRows = new Set(ruleRows.filter((r) => r.faces.includes("read")).map((r) => r.rule));
153
154
  const rows = ruleRows.map(ruleGuardRow);
154
155
  const matchPath = (path) => {
155
156
  const hit = denyTableHit(rows, { views: [{ path, kind: "lexical" }] });
156
157
  return hit === null ? null : { pattern: hit.pattern };
157
158
  };
158
- return { face: "write", ruleRows, matchPath, matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(rows, denyTargetViews(canonicalKey, lexicalView, opts)) };
159
+ return { face: "write", ruleRows, matchPath, matchTarget: (canonicalKey, lexicalView, opts) => denyTableHit(rows, denyTargetViews(canonicalKey, lexicalView, opts)), guardsReads: (pattern) => readRows.has(pattern) };
159
160
  }
160
161
  export function seatForCall(seat, toolCallId) {
161
162
  const forCall = seat?.forCall;
@@ -185,12 +186,27 @@ export function sensitivePathDenyList(pattern, face = "read") {
185
186
  }
186
187
  export const SENSITIVE_PATH_DENY_SCOPE = "This list guards credential-class paths and applies regardless of the containment roots.";
187
188
  export const WRITE_DENY_SCOPE = "A write deny row holds regardless of the containment roots and of the permission mode.";
189
+ export const READ_ROW_WRITE_SCOPE = "A read deny row holds on writes too, regardless of the containment roots and of the permission mode.";
188
190
  export function readDenySentence(finding) {
191
+ return readDenyRefusal(finding).sentence;
192
+ }
193
+ export function readDenyRefusal(finding) {
189
194
  const write = finding.face === "write";
190
195
  const canonicalNote = finding.canonical !== undefined && finding.canonical !== finding.target ? `(canonical target: "${fitMiddle(finding.canonical, READ_DENY_SENTENCE_PART_MAX)}") ` : "";
191
196
  const lexicalHit = finding.matchedView !== undefined && finding.matchedView !== (finding.canonical ?? finding.target);
197
+ const frame = `${finding.action ?? (write ? "writing" : "reading")} "${fitMiddle(finding.target, READ_DENY_SENTENCE_PART_MAX)}" ${canonicalNote}is refused:`;
198
+ const pattern = fitMiddle(finding.pattern, READ_DENY_SENTENCE_PART_MAX);
199
+ const echoed = Object.freeze([
200
+ Object.freeze({ kind: "path", value: finding.target, ...(finding.canonical !== undefined && finding.canonical !== finding.target ? { canonical: finding.canonical } : {}) }),
201
+ ...(lexicalHit ? [Object.freeze({ kind: "path", value: finding.matchedView })] : []),
202
+ Object.freeze({ kind: "pattern", value: finding.pattern }),
203
+ ]);
204
+ if (write && finding.readRow === true) {
205
+ 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`;
206
+ return { sentence: `${frame} ${reaches} — a path whose reads are denied is not written either. ${READ_ROW_WRITE_SCOPE}`, echoed };
207
+ }
192
208
  const judged = lexicalHit ? `the requested path's spelling ("${fitMiddle(finding.matchedView, READ_DENY_SENTENCE_PART_MAX)}") matches` : "the target matches";
193
- return `${finding.action ?? (write ? "writing" : "reading")} "${fitMiddle(finding.target, READ_DENY_SENTENCE_PART_MAX)}" ${canonicalNote}is refused: ${judged} ${sensitivePathDenyList(fitMiddle(finding.pattern, READ_DENY_SENTENCE_PART_MAX), write ? "write" : "read")}. ${write ? WRITE_DENY_SCOPE : SENSITIVE_PATH_DENY_SCOPE}`;
209
+ return { sentence: `${frame} ${judged} ${sensitivePathDenyList(pattern, write ? "write" : "read")}. ${write ? WRITE_DENY_SCOPE : SENSITIVE_PATH_DENY_SCOPE}`, echoed };
194
210
  }
195
211
  export const READ_DENY_SENTENCE_PART_MAX = PROBE_REASON_MAX;
196
212
  export function fitMiddle(s, budget) {
@@ -105,7 +105,7 @@ export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOT
105
105
  const removed = new Set(writeReadings(row, spelled).flatMap((r) => r.written.map((w) => w.at)));
106
106
  const options = new Set(args.filter((_, at) => !removed.has(at)).map((w) => w.raw));
107
107
  const forced = selectsOptions(row, spelled, received.shellChooses, TRAVERSAL, FORCED);
108
- const rm = removal.program === "rm" || !named ? { recursive: selectsOptions(row, spelled, received.shellChooses, TRAVERSAL) } : undefined;
108
+ const rm = row.key === "rm" || !named ? { recursive: selectsOptions(row, spelled, received.shellChooses, TRAVERSAL) } : undefined;
109
109
  if (forced && segment.reentry === "argv")
110
110
  out.push({ guard: "unverifiable_delete", program: removal.program, operand: segment.text.trim(), source: "stream" });
111
111
  const relocated = enclosingRelocated || readProgramPosition(segment.argv).baseMovedAt.length > 0;
@@ -181,8 +181,8 @@ const programNameUnsettled = (s) => s.verb !== undefined && s.reads.some((c) =>
181
181
  const RM_REMOVAL_ROW = programRow("rm");
182
182
  function removalProgramOf(s) {
183
183
  const basename = s.verb?.basename;
184
- const row = basename !== undefined && REMOVAL_COMMAND_SET.has(basename) ? programRow(basename) : undefined;
185
- if (row !== undefined)
184
+ const row = basename !== undefined ? programRow(basename) : undefined;
185
+ if (row !== undefined && REMOVAL_COMMAND_SET.has(row.key))
186
186
  return { program: basename, row, named: true };
187
187
  return programNameUnsettled(s) && RM_REMOVAL_ROW !== undefined ? { program: s.verb.name, row: RM_REMOVAL_ROW, named: false } : undefined;
188
188
  }
@@ -447,6 +447,8 @@ export declare function resolveKey(env: ExecutionEnv, rootCanonical: string, pat
447
447
  pattern: string;
448
448
  matchedView?: string;
449
449
  } | null;
450
+ /** The write face's {@link import("./read-deny.js").WriteDenyMatcher.guardsReads}: the row a hit named also guards reads. */
451
+ guardsReads?(pattern: string): boolean;
450
452
  }, containmentFace?: "open" | "roots"): Promise<{
451
453
  ok: true;
452
454
  key: string;
@@ -470,7 +470,7 @@ export async function resolveKey(env, rootCanonical, path, signal, baseCwd, addi
470
470
  ok: false,
471
471
  violation: {
472
472
  code: write ? "write_path_denied" : "read_path_denied",
473
- message: readDenySentence({ target: path, canonical: key, pattern: hit.pattern, ...(hit.matchedView !== undefined ? { matchedView: hit.matchedView } : {}), ...(write ? { face: "write" } : {}) }),
473
+ 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 } : {}) } : {}) }),
474
474
  target: key,
475
475
  pattern: hit.pattern,
476
476
  },
@@ -62,8 +62,15 @@ export declare function roleReads(r: Read, provenance: ReadCandidateProvenance,
62
62
  * NAME held>` + value, so the whole value is not in the text — but the text it appends IS, and an unset or empty
63
63
  * NAME makes it the whole value, so it is a candidate too. A value that is a substitution is the nested plan
64
64
  * its body already is, never a candidate of its own text (its placeholder is not a path).
65
+ *
66
+ * WHEN the shell expands the value is `expanded`: an ARGUMENT's (a program's, a launcher's or a declaration builtin's
67
+ * `NAME=value` word) is expanded with every other word of the command line, before anything of it runs — through the names
68
+ * the line holds (the table), as {@link readsOf} reads every word: `T=x; dd of="$T"` hands `dd` the value `x`. The shell's
69
+ * OWN assignments expand left to right, each after the ones before it took effect (`A=x B="$A" cmd` binds `B` to `x`) —
70
+ * what the names at the segment's start do not hold — so their value is read as written: `"shell"` (a prefix of a command,
71
+ * or a word in front of where a program would be), `"statement"` (a segment of assignments alone, which BINDS).
65
72
  */
66
- export declare function pushAssignment(reads: Bare[], w: LexedWord, provenance: ReadCandidateProvenance, bound?: boolean): void;
73
+ export declare function pushAssignment(reads: Bare[], w: LexedWord, provenance: ReadCandidateProvenance, expanded: BindingTable | "shell" | "statement"): void;
67
74
  /** Every word of a segment whose program's grammar this parser does not model, from `from` onward: option
68
75
  * payloads and path-shaped option words included, the launcher chain's own words excluded, a program declared
69
76
  * to open no path operand handing only the environment words in front of it. A program with NO row is read the
@@ -1,6 +1,6 @@
1
1
  import { literalTildeSpelling } from "../../shell/lex.js";
2
- import { expandsOf, partPattern, readOfText, rewritten } from "./shell-read-word.js";
3
- import { arithmeticSubstitutions, bindsArrayElement } from "./shell-read-bindings.js";
2
+ import { expandsOf, globMark, partPattern, readOfText, receivedWordOf, rewritten, spellingOf } from "./shell-read-word.js";
3
+ import { arithmeticSubstitutions, bindsArrayElement, judgedSpellingOf, wordValues } from "./shell-read-bindings.js";
4
4
  import { argvProgramOf, attachedOptionPayloads, isPathShapedToken } from "./bash-readonly-classifier.js";
5
5
  import { assignmentArgumentsAreNotPaths, deliversOperands, evaluatesOperands, messageWords, moduleTailOf, objectPathsOf, opensNoOperand, programRow, programTextMayOpen, programTextOpensOf, readArgs, readOptionSlot, selectsContentsTraversal, slotValueCandidates, subcommandOf, valuesAreLiteral, walksCwdWithoutOperand, wordsReadBySomeImplementations, } from "./program-read-model.js";
6
6
  import { objectPathRepositoryOf } from "./shell-read-object-path.js";
@@ -169,30 +169,35 @@ function programTextReads(r, provenance, text, language, ctx) {
169
169
  ctx.programText ??= programTextSentence(language);
170
170
  return [{ ...bare(r, provenance, text), denyOnly: true }];
171
171
  }
172
- export function pushAssignment(reads, w, provenance, bound = false) {
172
+ export function pushAssignment(reads, w, provenance, expanded) {
173
173
  const a = w.assignment;
174
- if (a === undefined || a.form === "compound" || (bound && bindsArrayElement(a)))
174
+ if (a === undefined || a.form === "compound" || (expanded === "statement" && bindsArrayElement(a)))
175
175
  return;
176
176
  const expandsTilde = a.value.expansions.some((p) => p.expansion?.kind === "tilde");
177
- const value = expandsTilde ? a.value.folded : literalTildeSpelling(a.value.folded);
178
- const settled = a.op === "=" && !expandsTilde;
179
- const named = a.value.folded === "" || (a.op === "+=" ? expandsTilde : !settled) ? undefined : value;
180
- if (a.value.folded === "" && settled)
181
- return;
182
- const v = { spelled: value, raw: a.bare ? a.value.raw : w.raw, provenance };
183
- const unsettled = provenance !== "env_assignment" ? { ...v, expands: "unresolvable" } : v.spelled.startsWith("~") && !v.spelled.includes(":") ? { ...v, expands: expandsOf(a.value) } : undefined;
184
- if (!settled && unsettled !== undefined)
185
- reads.push(unsettled);
186
- const substitutes = a.value.expansions.some((p) => p.expansion?.kind === "command" || p.expansion?.kind === "process" || p.expansion?.kind === "arithmetic");
187
- const pattern = named === undefined ? undefined : partPattern({ folded: w.folded, ...(w.judged !== undefined ? { pattern: w.judged } : {}) }, named);
188
- if (named !== undefined && !substitutes)
189
- reads.push({ spelled: named, raw: w.raw, provenance, expands: expandsOf(w), ...(pattern !== undefined ? { pattern } : {}) });
190
- if (a.value.folded.includes(":"))
191
- for (const m of a.value.folded.split(":"))
192
- if (m !== "") {
193
- const r = readOfText(m);
194
- reads.push({ spelled: r.folded, raw: r.raw, provenance, expands: r.expands, denyOnly: true });
195
- }
177
+ const held = typeof expanded === "object" && !expandsTilde ? wordValues(a.value, expanded, true) : undefined;
178
+ const texts = Array.isArray(held) ? held.map((v) => ({ value: spellingOf(v), expands: globMark(v.glob === true), pattern: judgedSpellingOf(v) })) : undefined;
179
+ for (const t of texts ?? [{ value: expandsTilde ? a.value.folded : literalTildeSpelling(a.value.folded), expands: expandsOf(w), pattern: undefined }]) {
180
+ const value = t.value;
181
+ const settled = a.op === "=" && !expandsTilde;
182
+ const named = value === "" || (a.op === "+=" ? expandsTilde : !settled) ? undefined : value;
183
+ if (value === "" && settled)
184
+ continue;
185
+ const v = { spelled: value, raw: a.bare ? a.value.raw : w.raw, provenance };
186
+ const unsettled = provenance !== "env_assignment" ? { ...v, expands: "unresolvable" } : v.spelled.startsWith("~") && !v.spelled.includes(":") ? { ...v, expands: expandsOf(a.value) } : undefined;
187
+ if (!settled && unsettled !== undefined)
188
+ reads.push(unsettled);
189
+ const substitutes = texts === undefined && a.value.expansions.some((p) => p.expansion?.kind === "command" || p.expansion?.kind === "process" || p.expansion?.kind === "arithmetic");
190
+ const pattern = named === undefined ? undefined : texts !== undefined ? t.pattern : partPattern({ folded: w.folded, ...(w.judged !== undefined ? { pattern: w.judged } : {}) }, named);
191
+ if (named !== undefined && !substitutes)
192
+ reads.push({ spelled: named, raw: w.raw, provenance, expands: t.expands, ...(pattern !== undefined ? { pattern } : {}) });
193
+ const list = texts === undefined ? a.value.folded : value;
194
+ if (list.includes(":"))
195
+ for (const m of list.split(":"))
196
+ if (m !== "") {
197
+ const r = readOfText(m);
198
+ reads.push({ spelled: r.folded, raw: r.raw, provenance, expands: r.expands, denyOnly: true });
199
+ }
200
+ }
196
201
  }
197
202
  export function unlistedWords(reads, toks, from, launcherIndices, provenance, ctx, program) {
198
203
  const argv = program !== undefined ? { program: program.basename, from: program.index } : argvProgramOf(toks.map((r) => r.word));
@@ -224,9 +229,9 @@ export function unlistedWords(reads, toks, from, launcherIndices, provenance, ct
224
229
  expanding.add(j);
225
230
  reads.push(bare(toks[j], j === argvStart ? "program_path" : provenance));
226
231
  if (j < argvStart)
227
- pushAssignment(reads, toks[j].word, "env_assignment");
232
+ pushAssignment(reads, toks[j].word, "env_assignment", ctx.table);
228
233
  else if (j > argvStart && !declaredNotPaths)
229
- pushAssignment(reads, toks[j].word, provenance);
234
+ pushAssignment(reads, toks[j].word, provenance, ctx.table);
230
235
  }
231
236
  const gathered = new RootsGathered();
232
237
  let base = new OperandBase();
@@ -257,7 +262,7 @@ export function unlistedWords(reads, toks, from, launcherIndices, provenance, ct
257
262
  continue;
258
263
  }
259
264
  reads.push(bare(r, provenance));
260
- pushAssignment(reads, r.word, "env_assignment");
265
+ pushAssignment(reads, receivedWordOf(r), "env_assignment", ctx.table);
261
266
  }
262
267
  }
263
268
  else if (!noPathOperands) {
@@ -273,7 +278,7 @@ export function unlistedWords(reads, toks, from, launcherIndices, provenance, ct
273
278
  else {
274
279
  reads.push(bare(programWord, "program_path"));
275
280
  if (!declaredNotPaths)
276
- pushAssignment(reads, programWord.word, provenance);
281
+ pushAssignment(reads, receivedWordOf(programWord), provenance, ctx.table);
277
282
  }
278
283
  }
279
284
  }
@@ -380,7 +385,7 @@ export function unlistedWords(reads, toks, from, launcherIndices, provenance, ct
380
385
  speculate(start, r.word.assignment !== undefined ? "whole" : "containment");
381
386
  const values = reads.length;
382
387
  if (!declaredNotPaths && e.slot === undefined)
383
- pushAssignment(reads, r.word, provenance);
388
+ pushAssignment(reads, receivedWordOf(r), provenance, ctx.table);
384
389
  speculate(values, "containment");
385
390
  return;
386
391
  }
@@ -517,7 +522,7 @@ function walkListed(row, argReads, first, last, expanding, reads, ctx, relocated
517
522
  if (slice[e.at].expands !== false)
518
523
  unsettledAt.push({ at: e.at, folded: t });
519
524
  if (row?.operands?.assignmentArguments !== "not-paths")
520
- pushAssignment(reads, slice[e.at].word, "operand");
525
+ pushAssignment(reads, receivedWordOf(slice[e.at]), "operand", ctx.table);
521
526
  break;
522
527
  }
523
528
  }
@@ -443,6 +443,8 @@ export declare class BindingThread {
443
443
  reaches(at: number, j?: number): boolean;
444
444
  /** Does segment `at` stand in a function body (it runs at a call, not here)? */
445
445
  inFunctionBody(at: number): boolean;
446
+ /** The innermost function body segment `at` stands in, as an id one body's segments share (`undefined`: none). */
447
+ bodyOf(at: number): number | undefined;
446
448
  /** Does segment `at` run in a subshell (a `( … )` group, a pipeline member that is not the last, a background job) or a
447
449
  * function body — whatever it changes, the shell that runs the next segment may not see? */
448
450
  runsApart(at: number): boolean;
@@ -3,6 +3,7 @@ import { shellWordsOf } from "../../shell/shell-words.js";
3
3
  import { isShellSyntaxWord, LOOP_LIST_HEADS, readProgramPosition } from "./bash-program-position.js";
4
4
  import { declaredAttributes, programRow, readArgRoles } from "./program-read-model.js";
5
5
  import { codeBodies } from "./shell-reentry-text.js";
6
+ import { braceWordListsOf } from "./shell-read-brace.js";
6
7
  import { BUILTIN_ENABLED, BUILTINS_ALL, ENABLE_BUILTIN, builtinKey, chainAvailability, enableBindings, isBuiltinKey, isDisabledValue, speaksFor } from "./shell-read-builtins.js";
7
8
  export function judgedSpellingOf(v) {
8
9
  if (v.glob !== true)
@@ -589,7 +590,7 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
589
590
  let state = "unknown";
590
591
  if (ITERATING_HEADS.has(headWord) && inAt === loopAt + 2 && argv.length > loopAt + 3) {
591
592
  const values = [];
592
- for (const w of argv.slice(loopAt + 3)) {
593
+ for (const w of new Map(braceWordListsOf(argv.slice(loopAt + 3)).flat().map((x) => [x.raw, x])).values()) {
593
594
  const v = readValue(w, false, overlay);
594
595
  if (v === "unknown") {
595
596
  values.length = 0;
@@ -992,6 +993,9 @@ export class BindingThread {
992
993
  inFunctionBody(at) {
993
994
  return this.blocks[at].body !== undefined;
994
995
  }
996
+ bodyOf(at) {
997
+ return this.blocks[at].body?.id;
998
+ }
995
999
  runsApart(at) {
996
1000
  return this.blocks[at].subshells.length > 0 || this.ownSubshell[at] === true || this.blocks[at].body !== undefined;
997
1001
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Brace expansion: the words bash makes of ONE word before any other expansion, in bash's order. A leaf (it reads the lexer
3
+ * only) so that every reader of the words a command runs with reads the same expansion — the plan's words of a simple
4
+ * command (shell-read-plan.ts, both faces) and the words a `for` list binds its variable to (shell-read-bindings.ts).
5
+ */
6
+ import { type LexedWord } from "../../shell/lex.js";
7
+ /** How many readings one segment is read in — every combination of one value for each name its words may hold several
8
+ * values of — before the reader stops claiming to know those names; and how many words one word's braces may make before
9
+ * the reader stops reading them (the word then stays the word it is). */
10
+ export declare const READINGS_MAX = 64;
11
+ /** The bash releases whose brace expansion makes different words of one text: 3.2 (macOS's `/bin/bash`) and every release
12
+ * from 4.0 on, which pads a sequence written with a leading zero and reads a sequence's step (measured on 3.2.57 and 5.3.15).
13
+ * Which one runs a command is not in the text. */
14
+ export type BashRelease = "3.2" | "4+";
15
+ /** The words a list of words makes under each bash release the text may meet ({@link braceWordsOf}): one list where every
16
+ * release makes the same words, one per release where they differ — the command is then read once per list, as a word
17
+ * whose names hold several values is (`readInSeveral`), and a `for` list binds its variable to every list's words. */
18
+ export declare function braceWordListsOf(words: readonly LexedWord[]): readonly (readonly LexedWord[])[];
@@ -0,0 +1,79 @@
1
+ import { argvOf, lexShell } from "../../shell/lex.js";
2
+ export const READINGS_MAX = 64;
3
+ const BASH_RELEASES = ["3.2", "4+"];
4
+ export function braceWordListsOf(words) {
5
+ const lists = BASH_RELEASES.map((release) => words.flatMap((w) => braceWordsOf(w, release)));
6
+ const key = (list) => list.map((w) => w.raw).join("\u0000");
7
+ return lists.filter((list, i) => lists.findIndex((other) => key(other) === key(list)) === i);
8
+ }
9
+ function braceWordsOf(word, release) {
10
+ if (!word.pieces.some((p) => p.expansion?.kind === "brace"))
11
+ return [word];
12
+ const expand = (text) => {
13
+ const w = argumentLexOf(text);
14
+ if (w === undefined || w.unresolved !== undefined)
15
+ return undefined;
16
+ const list = w.pieces.map((p) => ({ p, alternatives: p.expansion?.kind === "brace" ? braceAlternativesOf(p.expansion.body ?? "", release) : undefined })).find((x) => x.alternatives !== undefined);
17
+ if (list === undefined)
18
+ return [w];
19
+ const made = [];
20
+ const [from, to] = [list.p.span[0] - 2, list.p.span[1] - 2];
21
+ for (const alternative of list.alternatives) {
22
+ const next = `${text.slice(0, from)}${alternative}${text.slice(to)}`;
23
+ if (next === "")
24
+ continue;
25
+ const words = expand(next);
26
+ if (words === undefined)
27
+ return undefined;
28
+ made.push(...words);
29
+ if (made.length > READINGS_MAX)
30
+ return undefined;
31
+ }
32
+ return made;
33
+ };
34
+ const words = expand(word.raw);
35
+ return words === undefined || (words.length === 1 && words[0].raw === word.raw) ? [word] : words;
36
+ }
37
+ function argumentLexOf(text) {
38
+ const lexed = lexShell(`: ${text}`);
39
+ const words = "parseFailure" in lexed || lexed.segments.length !== 1 ? undefined : argvOf(lexed.segments[0]);
40
+ return words?.length === 2 && words[1].raw === text ? words[1] : undefined;
41
+ }
42
+ function braceAlternativesOf(body, release) {
43
+ const lexed = lexShell(`""${body}`);
44
+ const words = "parseFailure" in lexed || lexed.segments.length !== 1 ? undefined : argvOf(lexed.segments[0]);
45
+ if (words?.length !== 1)
46
+ return undefined;
47
+ const cuts = [];
48
+ for (const p of words[0].pieces)
49
+ if (p.quotedBy === undefined && p.literal !== undefined)
50
+ for (let i = p.literal.indexOf(","); i >= 0; i = p.literal.indexOf(",", i + 1))
51
+ cuts.push(p.span[0] - 2 + i);
52
+ if (cuts.length === 0)
53
+ return sequenceAlternativesOf(body, release);
54
+ return [...cuts, body.length].map((cut, k) => body.slice(k === 0 ? 0 : cuts[k - 1] + 1, cut));
55
+ }
56
+ function sequenceAlternativesOf(body, release) {
57
+ const m = /^([+-]?\d+|[A-Za-z])\.\.([+-]?\d+|[A-Za-z])(?:\.\.([+-]?\d+))?$/.exec(body);
58
+ if (m === null)
59
+ return undefined;
60
+ const [lhs, rhs, step] = [m[1], m[2], m[3]];
61
+ const letter = (t) => /^[A-Za-z]$/.test(t);
62
+ if (letter(lhs) !== letter(rhs))
63
+ return undefined;
64
+ if (step !== undefined && release === "3.2")
65
+ return [`\\{${body}\\}`];
66
+ const [from, to] = letter(lhs) ? [lhs.charCodeAt(0), rhs.charCodeAt(0)] : [Number(lhs), Number(rhs)];
67
+ const incr = Math.abs(step === undefined ? 1 : Number(step)) || 1;
68
+ if (![from, to, incr].every(Number.isSafeInteger) || Math.abs(to - from) / incr >= READINGS_MAX)
69
+ return undefined;
70
+ const terms = [];
71
+ for (let v = from; from <= to ? v <= to : v >= to; v += from <= to ? incr : -incr)
72
+ terms.push(v);
73
+ if (letter(lhs)) {
74
+ const chars = terms.map((c) => String.fromCharCode(c));
75
+ return chars.every(letter) ? chars : undefined;
76
+ }
77
+ const width = release === "3.2" || ![lhs, rhs].some((t) => /^-?0\d/.test(t)) ? 0 : Math.max(lhs.length, rhs.length);
78
+ return terms.map((v) => (width === 0 ? String(v) : v < 0 ? `-${String(-v).padStart(width - 1, "0")}` : String(v).padStart(width, "0")));
79
+ }
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import type { ExecutionEnv } from "../../internal/harness-types.js";
21
21
  import { violationDetails } from "./safety.js";
22
+ import type { RefusalEcho } from "../../core/refusal-echo.js";
22
23
  import { type ShellReadPlan } from "./shell-read-plan.js";
23
24
  import { type ReadLanding } from "./shell-read-identity.js";
24
25
  import { type HomeViewSource } from "./read-deny-home.js";
@@ -59,6 +60,7 @@ export interface ShellReadVouch extends ShellReadVerdictFacts {
59
60
  readonly face?: never;
60
61
  readonly sentence?: never;
61
62
  readonly details?: never;
63
+ readonly echoed?: never;
62
64
  readonly readRootCandidate?: never;
63
65
  readonly unestablished?: never;
64
66
  }
@@ -86,6 +88,9 @@ export interface ShellReadQuestion extends ShellReadVerdictFacts {
86
88
  * still carries WHAT was found on its `tool_end` — the targets outside the roots (`readonly_out_of_root`, or the file
87
89
  * tools' `path_not_in_root`), or that nothing could be established (`read_unestablished`). */
88
90
  readonly details?: ShellReadRefusalDetails;
91
+ /** `refuse` on a deny hit: the literals the refusal `sentence` quotes (target, the view that matched, pattern), minted with it
92
+ * from the one finding ({@link import("./read-deny.js").readDenyRefusal}); the gate files them on the refusal's record. */
93
+ readonly echoed?: readonly RefusalEcho[];
89
94
  /** `mandated` on an `outside_roots` finding: the directory whose grant would clear this ask. */
90
95
  readonly readRootCandidate?: ReadRootGrantCandidate;
91
96
  /** A FACT beside the disposition: some read of the command could not be established (an `unestablishable` or `declined`
@@ -212,8 +217,9 @@ export interface ShellReadStationOptions {
212
217
  * — the one trusted channel by which a refusal after the gate reaches the call's record (the tool's result is the
213
218
  * tool's own word, and a refusal must not read as a tool failure under the gate's `allowed`). Every shell tool this
214
219
  * station admits (both Bash faces, Monitor) refuses through {@link ShellReadStation.admit}, so this is the one
215
- * place to hear it. The Runner's; absent outside one. */
216
- readonly onAdmissionRefused?: (toolCallId: string) => void;
220
+ * place to hear it. A deny refusal passes the literals its sentence quotes (`echoed`, the same mint as the sentence). The
221
+ * Runner's; absent outside one. */
222
+ readonly onAdmissionRefused?: (toolCallId: string, echoed?: readonly RefusalEcho[]) => void;
217
223
  }
218
224
  /** What a consumer hands {@link judgeShellRead}: the command as written, the environment whose filesystem
219
225
  * answers where its words land (symlinks resolved, patterns expanded — a `NodeExecutionEnv` over a real
@@ -2,7 +2,7 @@ import { observeEnvironment } from "./shell-read-environment.js";
2
2
  import { errorResult } from "../../core/tools.js";
3
3
  import { BASH_READONLY_CONFINEMENT_NOTE } from "./fs-shared.js";
4
4
  import { isAbsoluteForFamily, normalizeAbsPathLexically, pathFamilyOf, violationDetails, withinAnyRoot } from "./safety.js";
5
- import { checkedReadDenyHomes, fitMiddle, READ_DENY_SENTENCE_PART_MAX, readDenySentence } from "./read-deny.js";
5
+ import { checkedReadDenyHomes, fitMiddle, READ_DENY_SENTENCE_PART_MAX, readDenyRefusal } from "./read-deny.js";
6
6
  import { NOT_AUTO_ALLOWED, declinedProgramSentence } from "./bash-program-position.js";
7
7
  import { bashClassifyDefaultAllow } from "./bash-readonly-classifier.js";
8
8
  import { planShellReads } from "./shell-read-plan.js";
@@ -12,7 +12,7 @@ import { declaredReadDenyHomes, homeViewsAt } from "./read-deny-home.js";
12
12
  import { anyOptionWord, programArgs } from "./shell-read-write-targets.js";
13
13
  import { shellReadFaceWords } from "./shell-read-face.js";
14
14
  import { passesUnasked } from "./shell-read-device.js";
15
- import { programRow, selectedOptions } from "./program-read-model.js";
15
+ import { operandWriterNames, programKeyOf, programRow, selectedOptions } from "./program-read-model.js";
16
16
  import { refusedByRemoval, SHELL_REMOVAL_COMMANDS } from "./removal-targets.js";
17
17
  import { allFindings, anyFaceGuards, decideShellRead, denyRowAtOrBelow, foldShellReadFindings, judgeEstablishedPlan, readRootGrantCandidateOf, stationGuards, writeFaceGuards, } from "./shell-read-judge.js";
18
18
  import { seatOf } from "../../core/tool-name-readings.js";
@@ -57,7 +57,7 @@ function runOrderOf(judged) {
57
57
  return { runs, plans, concurrent };
58
58
  }
59
59
  function lineOrderPlaced(runs, concurrent) {
60
- const reshapes = (s) => RESHAPES_TREE.has(s.segment.verb?.basename ?? "");
60
+ const reshapes = (s) => RESHAPES_TREE.has(programKeyOf(s.segment.verb?.basename ?? ""));
61
61
  const writes = (s) => s.findings.some((f) => f.read.candidate.face === "write");
62
62
  const stepsUp = (s) => s.findings.some((f) => f.read.candidate.spelled.split(/[\\/]/).includes(".."));
63
63
  return runs.every((later, j) => runs.every((earlier, i) => i === j || (i > j && !concurrent) || (!reshapes(earlier) && !(writes(earlier) && stepsUp(later)))));
@@ -68,7 +68,7 @@ function writesPlacedOf(judged, boundary) {
68
68
  return false;
69
69
  const { runs, plans, concurrent } = runOrderOf(judged);
70
70
  const placed = (s) => {
71
- const verb = s.segment.verb?.basename ?? "";
71
+ const verb = programKeyOf(s.segment.verb?.basename ?? "");
72
72
  if (s.segment.reentry === "shell" || s.segment.unreadProgramText !== undefined)
73
73
  return false;
74
74
  if (UNPLACED_OPTIONS[verb]?.(programArgs(s.segment).map((w) => w.spelled)) === true)
@@ -95,7 +95,7 @@ function unplacedOptionsOf(judged) {
95
95
  const nested = s.nested.map(unplacedOptionsOf).find((u) => u !== undefined);
96
96
  if (nested !== undefined)
97
97
  return nested;
98
- const verb = s.segment.verb?.basename;
98
+ const verb = s.segment.verb === undefined ? undefined : programKeyOf(s.segment.verb.basename);
99
99
  if ((verb === "cp" || verb === "mv") && anyOptionWord(programArgs(s.segment).map((w) => w.spelled)))
100
100
  return { program: verb };
101
101
  }
@@ -302,10 +302,10 @@ function refusalOf(tool, fold, boundary, paths) {
302
302
  if (fold.finding === "deny_hit" && w?.deny !== undefined) {
303
303
  const target = w.read.target ?? w.deny.matchedView;
304
304
  const write = w.deny.face === "write";
305
- const core = readDenySentence({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}) });
305
+ const { sentence: core, echoed } = readDenyRefusal({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}), ...(w.deny.readRow === true ? { readRow: true } : {}) });
306
306
  const through = deniedThrough(w.read, boundary);
307
- const sentence = `Error (${tool}): ${core} ${write ? WRITE_DENY_REFUSAL_NOTE : DENY_REFUSAL_NOTE}${through !== undefined ? ` ${DENIED_THROUGH_NOTE[through]}` : ""}`;
308
- return { sentence, ...(write ? {} : { details: violationDetails({ code: "read_path_denied", message: sentence, target, pattern: w.deny.pattern }) }) };
307
+ const sentence = `Error (${tool}): ${core} ${write ? writeDenyRefusalNote() : DENY_REFUSAL_NOTE}${through !== undefined ? ` ${DENIED_THROUGH_NOTE[through]}` : ""}`;
308
+ return { sentence, echoed, ...(write ? {} : { details: violationDetails({ code: "read_path_denied", message: sentence, target, pattern: w.deny.pattern }) }) };
309
309
  }
310
310
  const account = findingAccount(fold, boundary);
311
311
  const sentence = `Error (${tool}): ${account}. ${BASH_READONLY_CONFINEMENT_NOTE}`;
@@ -325,8 +325,10 @@ function deniedThrough(read, boundary) {
325
325
  return "home";
326
326
  return undefined;
327
327
  }
328
- const WRITE_DENY_REFUSAL_NOTE = "The boundary judges this command's write targets — its output redirections and the operands of mkdir, touch, rm, " +
329
- "rmdir, mv, cp, tee and an in-place sed — against the write deny list; a denied write is refused here rather than escalated.";
328
+ function writeDenyRefusalNote() {
329
+ const names = operandWriterNames();
330
+ return `The boundary judges this command's write targets — its output redirections and the operands of ${names.slice(0, -1).join(", ")} and ${names.at(-1)} — against the write deny list; a denied write is refused here rather than escalated.`;
331
+ }
330
332
  const DENY_REFUSAL_NOTE = "The read boundary judges the paths this command names — as written and, where a filesystem can be consulted, where " +
331
333
  "they resolve and what a pattern among them matches — and refuses a deny-listed one here rather than escalating it; " +
332
334
  "a file the command reaches without naming it is judged only where a segment deny row (built in, or the deployment's " +
@@ -343,7 +345,7 @@ function verdictOf(tool, seat, fold, judged, boundary) {
343
345
  const by = fold.finding === "unanswered" ? { environmentSilent: true } : {};
344
346
  if (disposition === "refuse") {
345
347
  const r = refusalOf(tool, fold, boundary, paths);
346
- return { disposition, finding: fold.finding, ...by, ...writes, sentence: r.sentence, ...(r.details !== undefined ? { details: r.details } : {}) };
348
+ return { disposition, finding: fold.finding, ...by, ...writes, sentence: r.sentence, ...(r.details !== undefined ? { details: r.details } : {}), ...(r.echoed !== undefined ? { echoed: r.echoed } : {}) };
347
349
  }
348
350
  const grant = fold.finding === "outside_roots" ? readRootGrantCandidateOf(judged, boundary) : undefined;
349
351
  const containment = fold.finding === "outside_roots" || fold.finding === "unestablishable" || fold.finding === "unanswered";
@@ -518,8 +520,8 @@ export function createShellReadStation(opts) {
518
520
  if (a === undefined)
519
521
  return undefined;
520
522
  admissions.delete(toolCallId);
521
- const refused = (r) => {
522
- opts.onAdmissionRefused?.(toolCallId);
523
+ const refused = (r, echoed) => {
524
+ opts.onAdmissionRefused?.(toolCallId, echoed);
523
525
  return r;
524
526
  };
525
527
  if (a.toolName !== toolName || a.command !== command) {
@@ -534,7 +536,7 @@ export function createShellReadStation(opts) {
534
536
  const fold = foldShellReadFindings(judged);
535
537
  if (fold.finding === "deny_hit") {
536
538
  const r = refusalOf(toolName, fold, a.boundary, outsidePathsOf(judged));
537
- return refused(errorResult(r.sentence, r.details));
539
+ return refused(errorResult(r.sentence, r.details), r.echoed);
538
540
  }
539
541
  const moved = changed[0];
540
542
  const identity = { finding: "identity_changed", witness: { read: moved, kind: "none", containment: "unknown" } };