@sema-agent/core 7.57.0 → 7.59.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 (399) hide show
  1. package/CHANGELOG.md +1161 -0
  2. package/README.md +6 -4
  3. package/dist/agents/cc-peer-directory.js +8 -8
  4. package/dist/agents/child-model-seat.d.ts +4 -2
  5. package/dist/agents/child-model-seat.js +5 -3
  6. package/dist/agents/peer-directory.d.ts +9 -0
  7. package/dist/agents/peer-directory.js +6 -2
  8. package/dist/agents/send-message-tool.js +21 -12
  9. package/dist/agents/subagent-steps.js +2 -4
  10. package/dist/agents/subagent.js +33 -34
  11. package/dist/brain/anthropic.js +161 -45
  12. package/dist/brain/errors.d.ts +9 -3
  13. package/dist/brain/errors.js +7 -1
  14. package/dist/brain/failover.js +2 -1
  15. package/dist/brain/open-responses.js +3 -3
  16. package/dist/brain/openai.js +103 -53
  17. package/dist/brain/provider-dialect.d.ts +11 -0
  18. package/dist/brain/provider-dialect.js +5 -2
  19. package/dist/brain/reasoning-request.js +5 -4
  20. package/dist/brain/reasoning.d.ts +19 -0
  21. package/dist/brain/reasoning.js +17 -2
  22. package/dist/brain/request-route.d.ts +4 -1
  23. package/dist/brain/request-route.js +4 -1
  24. package/dist/brain/route-adjudicator.d.ts +84 -18
  25. package/dist/brain/route-adjudicator.js +89 -22
  26. package/dist/brain/route-conformance.js +1 -1
  27. package/dist/brain/stream-engine.js +84 -49
  28. package/dist/brain/stream-shared.d.ts +30 -0
  29. package/dist/brain/stream-shared.js +34 -1
  30. package/dist/brain/timeout.d.ts +62 -5
  31. package/dist/brain/timeout.js +93 -6
  32. package/dist/core/a2a.d.ts +2 -1
  33. package/dist/core/a2a.js +23 -10
  34. package/dist/core/account-row.d.ts +61 -0
  35. package/dist/core/account-row.js +51 -0
  36. package/dist/core/advisor-verdict.d.ts +2 -1
  37. package/dist/core/advisor-verdict.js +1 -1
  38. package/dist/core/allow-entry.d.ts +20 -7
  39. package/dist/core/allow-entry.js +18 -9
  40. package/dist/core/approval-object.d.ts +29 -15
  41. package/dist/core/approval-object.js +47 -19
  42. package/dist/core/ask-origin.d.ts +21 -2
  43. package/dist/core/ask-origin.js +5 -1
  44. package/dist/core/auto-compaction.d.ts +4 -0
  45. package/dist/core/auto-compaction.js +2 -2
  46. package/dist/core/auto-mode-directive.d.ts +29 -5
  47. package/dist/core/auto-mode-directive.js +38 -8
  48. package/dist/core/background-agent-store.d.ts +16 -3
  49. package/dist/core/checkpoint-requirements.d.ts +19 -1
  50. package/dist/core/checkpoint-requirements.js +5 -1
  51. package/dist/core/checkpoint-store.d.ts +85 -23
  52. package/dist/core/checkpoint-store.js +31 -9
  53. package/dist/core/child-clamp-seats.d.ts +29 -0
  54. package/dist/core/child-clamp-seats.js +56 -1
  55. package/dist/core/compliance.d.ts +2 -2
  56. package/dist/core/compliance.js +1 -1
  57. package/dist/core/effective-path-target.d.ts +8 -2
  58. package/dist/core/effective-path-target.js +8 -3
  59. package/dist/core/engine-notice.d.ts +99 -9
  60. package/dist/core/engine-notice.js +19 -5
  61. package/dist/core/fs-write-gate-policy.d.ts +4 -2
  62. package/dist/core/fs-write-gate-policy.js +7 -3
  63. package/dist/core/gate-fold.js +7 -4
  64. package/dist/core/gate-lanes.js +19 -6
  65. package/dist/core/gate-outcome.d.ts +32 -3
  66. package/dist/core/gate-outcome.js +19 -1
  67. package/dist/core/git-worktree-env.d.ts +53 -11
  68. package/dist/core/git-worktree-env.js +96 -12
  69. package/dist/core/governance-codes.d.ts +9 -1
  70. package/dist/core/governance-codes.js +13 -0
  71. package/dist/core/hooks.d.ts +35 -4
  72. package/dist/core/hooks.js +17 -11
  73. package/dist/core/human-input-projection.d.ts +1 -0
  74. package/dist/core/human-input-projection.js +3 -0
  75. package/dist/core/image-admission.d.ts +6 -5
  76. package/dist/core/image-admission.js +18 -14
  77. package/dist/core/locked-config.d.ts +20 -3
  78. package/dist/core/locked-config.js +40 -3
  79. package/dist/core/mailbox-store.d.ts +45 -1
  80. package/dist/core/mailbox-store.js +53 -9
  81. package/dist/core/mcp-call-meta.d.ts +66 -0
  82. package/dist/core/mcp-call-meta.js +103 -0
  83. package/dist/core/mcp-connection-pool.d.ts +3 -1
  84. package/dist/core/mcp-connection-pool.js +3 -1
  85. package/dist/core/mcp-failure.d.ts +117 -15
  86. package/dist/core/mcp-failure.js +71 -3
  87. package/dist/core/mcp-probe.d.ts +4 -0
  88. package/dist/core/mcp-probe.js +1 -1
  89. package/dist/core/mcp-server-link.d.ts +27 -3
  90. package/dist/core/mcp-server-link.js +25 -1
  91. package/dist/core/mcp-server-spec.d.ts +46 -18
  92. package/dist/core/mcp-server-spec.js +1 -18
  93. package/dist/core/mcp.d.ts +16 -20
  94. package/dist/core/mcp.js +112 -55
  95. package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
  96. package/dist/core/memory-engine/consolidation-driver.js +3 -3
  97. package/dist/core/memory-engine/consolidation.d.ts +4 -0
  98. package/dist/core/memory-engine/consolidation.js +1 -0
  99. package/dist/core/memory-engine/delegation-settlement.js +5 -12
  100. package/dist/core/memory-engine/distiller.js +2 -2
  101. package/dist/core/memory-engine/dual-root.d.ts +50 -1
  102. package/dist/core/memory-engine/dual-root.js +44 -1
  103. package/dist/core/memory-engine/engine.d.ts +67 -14
  104. package/dist/core/memory-engine/engine.js +384 -212
  105. package/dist/core/memory-engine/export-bundle.d.ts +23 -0
  106. package/dist/core/memory-engine/export-bundle.js +23 -4
  107. package/dist/core/memory-engine/file-backend.d.ts +128 -55
  108. package/dist/core/memory-engine/file-backend.js +290 -117
  109. package/dist/core/memory-engine/index.d.ts +1 -1
  110. package/dist/core/memory-engine/layout.d.ts +59 -11
  111. package/dist/core/memory-engine/layout.js +190 -40
  112. package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
  113. package/dist/core/memory-engine/memory-backend-contract.js +39 -2
  114. package/dist/core/memory-engine/scope-contract.d.ts +45 -4
  115. package/dist/core/memory-engine/scope-contract.js +80 -11
  116. package/dist/core/memory-engine/sync-client.d.ts +9 -1
  117. package/dist/core/memory-engine/sync-client.js +31 -8
  118. package/dist/core/memory-engine/sync.d.ts +5 -0
  119. package/dist/core/memory-engine/types.d.ts +6 -0
  120. package/dist/core/mode-policy.d.ts +8 -5
  121. package/dist/core/mode-policy.js +5 -4
  122. package/dist/core/mods/classic-events.d.ts +5 -1
  123. package/dist/core/mods/host.js +1 -1
  124. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  125. package/dist/core/mods/kernel/dispatch.js +12 -9
  126. package/dist/core/mods/kernel/events.d.ts +6 -1
  127. package/dist/core/mods/kernel/events.js +2 -2
  128. package/dist/core/mods/kernel/registration.d.ts +9 -1
  129. package/dist/core/mods/kernel/registration.js +3 -0
  130. package/dist/core/mods/kernel/site-rules.d.ts +3 -0
  131. package/dist/core/mods/kernel/site-rules.js +10 -0
  132. package/dist/core/mods/package.d.ts +23 -0
  133. package/dist/core/mods/package.js +118 -0
  134. package/dist/core/mods/stations.d.ts +33 -12
  135. package/dist/core/mods/stations.js +45 -11
  136. package/dist/core/mods/tool-call.d.ts +5 -1
  137. package/dist/core/mods/tool-call.js +13 -4
  138. package/dist/core/parent-spec-seat.d.ts +8 -3
  139. package/dist/core/parent-spec-seat.js +2 -0
  140. package/dist/core/park-selfcheck.js +6 -0
  141. package/dist/core/path-guard-rows.d.ts +20 -0
  142. package/dist/core/path-guard-rows.js +11 -0
  143. package/dist/core/peer-seat.d.ts +248 -0
  144. package/dist/core/peer-seat.js +439 -0
  145. package/dist/core/permission-rule-consent.js +10 -4
  146. package/dist/core/permission-rule-model.d.ts +16 -0
  147. package/dist/core/permission-rule-model.js +1 -1
  148. package/dist/core/present-plan-tool.d.ts +20 -3
  149. package/dist/core/present-plan-tool.js +48 -4
  150. package/dist/core/protocol-http-auth.d.ts +40 -29
  151. package/dist/core/protocol-http-auth.js +30 -32
  152. package/dist/core/redaction-marks.d.ts +16 -0
  153. package/dist/core/redaction-marks.js +16 -0
  154. package/dist/core/redaction-passes.js +8 -9
  155. package/dist/core/resume-startup-cause.js +1 -0
  156. package/dist/core/retention.d.ts +41 -15
  157. package/dist/core/retention.js +59 -12
  158. package/dist/core/rewrite-rejudge.d.ts +38 -0
  159. package/dist/core/rewrite-rejudge.js +42 -2
  160. package/dist/core/roles.d.ts +34 -2
  161. package/dist/core/roles.js +43 -4
  162. package/dist/core/run-origin.d.ts +40 -0
  163. package/dist/core/run-origin.js +37 -0
  164. package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
  165. package/dist/core/runner/advertised-writable-dirs.js +126 -0
  166. package/dist/core/runner/announce-once-ledger.d.ts +5 -4
  167. package/dist/core/runner/announce-once-ledger.js +4 -2
  168. package/dist/core/runner/call-hook-stations.js +2 -2
  169. package/dist/core/runner/compaction-restate.d.ts +15 -6
  170. package/dist/core/runner/compaction-restate.js +28 -2
  171. package/dist/core/runner/contracts.d.ts +33 -21
  172. package/dist/core/runner/credential-origin-seat.js +4 -3
  173. package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
  174. package/dist/core/runner/cwd-alignment-probe.js +21 -0
  175. package/dist/core/runner/decide-continuation.d.ts +2 -2
  176. package/dist/core/runner/gate-exit.d.ts +30 -8
  177. package/dist/core/runner/gate-exit.js +15 -8
  178. package/dist/core/runner/image-removed-seat.d.ts +12 -0
  179. package/dist/core/runner/image-removed-seat.js +19 -0
  180. package/dist/core/runner/inline-image.js +1 -1
  181. package/dist/core/runner/memory-consolidation-driver.js +3 -3
  182. package/dist/core/runner/park-commit.d.ts +1 -1
  183. package/dist/core/runner/park-commit.js +3 -0
  184. package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
  185. package/dist/core/runner/prepare-ask-lane.js +2 -1
  186. package/dist/core/runner/prepare-boundary-parks.js +2 -2
  187. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
  188. package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
  189. package/dist/core/runner/prepare-config-doors.d.ts +8 -5
  190. package/dist/core/runner/prepare-config-doors.js +14 -10
  191. package/dist/core/runner/prepare-context-lane.js +2 -0
  192. package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
  193. package/dist/core/runner/prepare-delegation-surface.js +16 -18
  194. package/dist/core/runner/prepare-gate-stations.js +1 -1
  195. package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
  196. package/dist/core/runner/prepare-hands-readface.js +9 -1
  197. package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
  198. package/dist/core/runner/prepare-inherited-gate.js +14 -27
  199. package/dist/core/runner/prepare-memory.d.ts +3 -0
  200. package/dist/core/runner/prepare-memory.js +26 -37
  201. package/dist/core/runner/prepare-park-ask.d.ts +1 -1
  202. package/dist/core/runner/prepare-park-ask.js +2 -1
  203. package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
  204. package/dist/core/runner/prepare-policy-chain.js +18 -15
  205. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  206. package/dist/core/runner/prepare-project-context.js +2 -2
  207. package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
  208. package/dist/core/runner/prepare-prompt-inputs.js +8 -19
  209. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
  210. package/dist/core/runner/prepare-protocol-tools.js +11 -3
  211. package/dist/core/runner/prepare-run-refs.d.ts +2 -3
  212. package/dist/core/runner/prepare-run-refs.js +4 -1
  213. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  214. package/dist/core/runner/prepare-suspend-saga.js +2 -1
  215. package/dist/core/runner/prepare-task.js +28 -13
  216. package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
  217. package/dist/core/runner/prepare-wiring-manifest.js +4 -3
  218. package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
  219. package/dist/core/runner/prepare-workspace-restore.js +4 -4
  220. package/dist/core/runner/reply-pricing.d.ts +30 -0
  221. package/dist/core/runner/reply-pricing.js +19 -0
  222. package/dist/core/runner/resume-admission.js +5 -3
  223. package/dist/core/runner/resume-apply.js +6 -1
  224. package/dist/core/runner/resume-checkpoint-screen.js +2 -0
  225. package/dist/core/runner/resume-policy-outcome.js +5 -5
  226. package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
  227. package/dist/core/runner/role-seat-defaulted.js +40 -0
  228. package/dist/core/runner/run-brain-sinks.js +2 -0
  229. package/dist/core/runner/run-harness-handlers.d.ts +3 -4
  230. package/dist/core/runner/run-harness-handlers.js +1 -8
  231. package/dist/core/runner/run-identity-wiring.d.ts +2 -5
  232. package/dist/core/runner/run-identity-wiring.js +6 -4
  233. package/dist/core/runner/run-leg.d.ts +2 -0
  234. package/dist/core/runner/run-leg.js +42 -29
  235. package/dist/core/runner/run-notification-lane.js +3 -0
  236. package/dist/core/runner/run-stop-and-final-verify.js +2 -2
  237. package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
  238. package/dist/core/runner/run-terminal-adoption.js +9 -3
  239. package/dist/core/runner/run-turn-boundary.js +77 -70
  240. package/dist/core/runner/runtask.d.ts +1 -1
  241. package/dist/core/runner/runtask.js +2 -2
  242. package/dist/core/runner/side-call-account.d.ts +1 -1
  243. package/dist/core/runner/side-call-account.js +3 -18
  244. package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
  245. package/dist/core/runner/sub-agent-deny-lists.js +10 -0
  246. package/dist/core/runner/terminal-account.js +3 -3
  247. package/dist/core/runner/tool-end-body.js +2 -1
  248. package/dist/core/runner/tool-occurrence.d.ts +5 -2
  249. package/dist/core/runner/tool-occurrence.js +4 -3
  250. package/dist/core/runner/turn-attachments.d.ts +26 -22
  251. package/dist/core/runner/turn-attachments.js +24 -26
  252. package/dist/core/runner/write-protection-station.d.ts +8 -2
  253. package/dist/core/runner/write-protection-station.js +2 -0
  254. package/dist/core/runner-deps.d.ts +3 -3
  255. package/dist/core/secret-env.d.ts +32 -2
  256. package/dist/core/secret-env.js +65 -3
  257. package/dist/core/sensitive-path-policy.js +9 -10
  258. package/dist/core/session-log-transfer.d.ts +24 -0
  259. package/dist/core/session-log-transfer.js +166 -0
  260. package/dist/core/session-policy-store.d.ts +3 -1
  261. package/dist/core/session-policy-store.js +13 -9
  262. package/dist/core/session-store.d.ts +86 -24
  263. package/dist/core/session-store.js +162 -24
  264. package/dist/core/session.d.ts +92 -1
  265. package/dist/core/shell-read-silence.js +1 -0
  266. package/dist/core/side-query.d.ts +11 -1
  267. package/dist/core/side-query.js +9 -0
  268. package/dist/core/skill-grant-binding.d.ts +31 -2
  269. package/dist/core/skill-grant-binding.js +31 -1
  270. package/dist/core/skill-grant.d.ts +8 -5
  271. package/dist/core/skill-grant.js +6 -6
  272. package/dist/core/steer-replay.d.ts +4 -2
  273. package/dist/core/steer-replay.js +2 -1
  274. package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
  275. package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
  276. package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
  277. package/dist/core/store-contracts/session-repo-contract.js +112 -5
  278. package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
  279. package/dist/core/store-contracts/session-store-contract.js +236 -2
  280. package/dist/core/synthetic-read-verdict.js +2 -1
  281. package/dist/core/task-event.d.ts +92 -8
  282. package/dist/core/task-notification.js +16 -10
  283. package/dist/core/task-registry-agent.js +1 -0
  284. package/dist/core/task-registry-shared.d.ts +7 -1
  285. package/dist/core/task-spec.d.ts +49 -1
  286. package/dist/core/task-stream.d.ts +2 -1
  287. package/dist/core/terminal-cause.d.ts +11 -1
  288. package/dist/core/tool-catalog-entries.js +1 -0
  289. package/dist/core/tool-check-reading.d.ts +1 -0
  290. package/dist/core/tool-check-reading.js +3 -3
  291. package/dist/core/tool-policy.d.ts +16 -0
  292. package/dist/core/tool-result-store.d.ts +17 -10
  293. package/dist/core/tool-result-store.js +3 -1
  294. package/dist/core/tool-roster.d.ts +112 -5
  295. package/dist/core/tool-roster.js +42 -1
  296. package/dist/core/tool-spec.d.ts +3 -1
  297. package/dist/core/types.d.ts +3 -3
  298. package/dist/core/types.js +1 -1
  299. package/dist/core/untrusted-egress.d.ts +0 -2
  300. package/dist/core/untrusted-egress.js +10 -14
  301. package/dist/core/user-attachment.js +1 -1
  302. package/dist/core/wiring-manifest.d.ts +18 -6
  303. package/dist/core/wiring-manifest.js +4 -3
  304. package/dist/core/workspace-snapshot.d.ts +44 -0
  305. package/dist/core/workspace-snapshot.js +34 -0
  306. package/dist/core/write-protect.d.ts +43 -3
  307. package/dist/core/write-protect.js +43 -16
  308. package/dist/engine/compaction/compaction.js +29 -3
  309. package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
  310. package/dist/engine/execution-env/node-execution-env.js +24 -23
  311. package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
  312. package/dist/engine/harness/agent-harness.d.ts +30 -2
  313. package/dist/engine/harness/agent-harness.js +43 -12
  314. package/dist/engine/harness/messages.d.ts +3 -1
  315. package/dist/engine/harness/messages.js +3 -2
  316. package/dist/engine/harness/types.d.ts +56 -7
  317. package/dist/engine/harness/types.js +5 -1
  318. package/dist/engine/llm/rejected-images.d.ts +46 -0
  319. package/dist/engine/llm/rejected-images.js +54 -0
  320. package/dist/engine/llm/tool-turns.d.ts +2 -1
  321. package/dist/engine/llm/types.d.ts +30 -10
  322. package/dist/engine/llm/types.js +1 -1
  323. package/dist/engine/loop/agent-loop.d.ts +8 -0
  324. package/dist/engine/loop/agent-loop.js +52 -15
  325. package/dist/engine/loop/types.d.ts +3 -1
  326. package/dist/engine/session/import-validate.js +3 -0
  327. package/dist/engine/session/memory-repo.d.ts +17 -9
  328. package/dist/engine/session/memory-repo.js +44 -34
  329. package/dist/engine/session/path-to-root.d.ts +38 -0
  330. package/dist/engine/session/path-to-root.js +39 -0
  331. package/dist/engine/session/repo-utils.d.ts +22 -4
  332. package/dist/engine/session/repo-utils.js +49 -1
  333. package/dist/engine/session/storage-base.d.ts +10 -1
  334. package/dist/engine/session/storage-base.js +11 -22
  335. package/dist/index.d.ts +29 -16
  336. package/dist/index.js +21 -11
  337. package/dist/internal/harness-types.d.ts +2 -2
  338. package/dist/internal/harness.d.ts +3 -2
  339. package/dist/internal/harness.js +2 -2
  340. package/dist/internal/llm.d.ts +1 -0
  341. package/dist/orchestration/workflow-observe.d.ts +17 -1
  342. package/dist/orchestration/workflow-observe.js +20 -0
  343. package/dist/orchestration/workflow-types.d.ts +32 -7
  344. package/dist/orchestration/workflow.js +739 -489
  345. package/dist/shell/counting-pass.d.ts +50 -0
  346. package/dist/shell/counting-pass.js +502 -0
  347. package/dist/shell/lex.d.ts +4 -2
  348. package/dist/shell/lex.js +93 -34
  349. package/dist/shell/shell-words.d.ts +1 -1
  350. package/dist/shell/shell-words.js +7 -6
  351. package/dist/stores/file/index.d.ts +4 -1
  352. package/dist/stores/file/index.js +4 -1
  353. package/dist/stores/file/mailbox-store.js +6 -10
  354. package/dist/stores/file/session-store.d.ts +15 -8
  355. package/dist/stores/file/session-store.js +28 -13
  356. package/dist/tools/fs/fs-bash.d.ts +6 -0
  357. package/dist/tools/fs/fs-bash.js +6 -3
  358. package/dist/tools/fs/fs-write.d.ts +6 -3
  359. package/dist/tools/fs/fs-write.js +8 -7
  360. package/dist/tools/fs/index.d.ts +3 -0
  361. package/dist/tools/fs/index.js +7 -3
  362. package/dist/tools/fs/program-read-model.d.ts +13 -0
  363. package/dist/tools/fs/program-read-model.js +15 -0
  364. package/dist/tools/fs/program-read-model.rows.js +1 -1
  365. package/dist/tools/fs/read-deny.d.ts +13 -10
  366. package/dist/tools/fs/read-deny.js +25 -5
  367. package/dist/tools/fs/read-floor.d.ts +19 -0
  368. package/dist/tools/fs/read-floor.js +23 -0
  369. package/dist/tools/fs/safety.js +40 -8
  370. package/dist/tools/fs/search.js +6 -24
  371. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  372. package/dist/tools/fs/shell-read-check.js +61 -16
  373. package/dist/tools/fs/shell-read-establish.js +2 -1
  374. package/dist/tools/fs/shell-read-identity.js +1 -1
  375. package/dist/tools/fs/shell-read-judge.d.ts +26 -9
  376. package/dist/tools/fs/shell-read-judge.js +10 -6
  377. package/dist/tools/fs/shell-read-plan.d.ts +6 -1
  378. package/dist/tools/fs/shell-read-plan.js +22 -15
  379. package/dist/tools/fs/shell-read-start.js +1 -0
  380. package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
  381. package/dist/tools/fs/shell-reentry-text.js +25 -3
  382. package/dist/tools/monitor.d.ts +4 -0
  383. package/dist/tools/monitor.js +2 -0
  384. package/dist/tools/worktree.d.ts +42 -15
  385. package/dist/tools/worktree.js +60 -32
  386. package/package.json +5 -2
  387. package/test/export-surface.snapshot.json +149 -1
  388. package/wire-changes/core-stores-sql@7.58.0.json +29 -0
  389. package/wire-changes/core-stores-sql@7.59.0.json +29 -0
  390. package/wire-changes/core@7.58.0.json +2188 -0
  391. package/wire-changes/core@7.59.0.json +2459 -0
  392. package/wire-changes/mods-kernel@7.58.0.json +81 -0
  393. package/wire-changes/mods-kernel@7.59.0.json +29 -0
  394. package/wire-changes/primitives@7.58.0.json +29 -0
  395. package/wire-changes/primitives@7.59.0.json +29 -0
  396. package/dist/primitives/credential-ref.d.ts +0 -89
  397. package/dist/primitives/credential-ref.js +0 -125
  398. package/dist/primitives/index.d.ts +0 -2
  399. package/dist/primitives/index.js +0 -1
@@ -14,8 +14,11 @@ import { type CwdRef } from "./fs-shared.js";
14
14
  * Absent hook ⇒ byte-identical behavior.
15
15
  */
16
16
  export type { BeforeWriteRequest, BeforeWriteResult, BeforeWriteHook, TrackEditRequest, TrackEditResult, TrackFileEditHook } from "../../core/types.js";
17
- export declare function createEditFileTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: string, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool;
18
- export declare function createWriteFileTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: string, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool;
17
+ /** A write tool's primary containment root: fixed, or a getter over the leg's live write location (read once per call, so an
18
+ * EnterWorktree switch moves where the next write may land). Canonical in both forms. */
19
+ export type WriteRootSeat = string | (() => string);
20
+ export declare function createEditFileTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: WriteRootSeat, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool;
21
+ export declare function createWriteFileTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: WriteRootSeat, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool;
19
22
  /**
20
23
  * design v1.163 — NotebookEdit: replace/insert/delete a single cell in a .ipynb. CC-parity tool over the SAME hand-band
21
24
  * safety skeleton as Edit/Write (resolveKey containment → requireRead read-before-edit → checkStale content-hash
@@ -23,4 +26,4 @@ export declare function createWriteFileTool(env: ExecutionEnv, state: ReadFileSt
23
26
  * .ipynb as the cell projection but records read state (hash/totalLines) in the RAW notebook-text
24
27
  * coordinate — that raw-coordinate read record is what this tool's freshness check depends on.
25
28
  */
26
- export declare function createNotebookEditTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: string, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool;
29
+ export declare function createNotebookEditTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: WriteRootSeat, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool;
@@ -89,6 +89,7 @@ async function gateToolWrite(hook, tool, path, key, content) {
89
89
  return `Error (${tool}): write rejected by the write gate (${res.code}): ${clipHookText(res.reason)}`;
90
90
  return undefined;
91
91
  }
92
+ const rootOf = (seat) => (typeof seat === "function" ? seat() : seat);
92
93
  export function createEditFileTool(env, state, rootCanonical, cwdRef, additionalRoots, beforeWrite, trackEdit, onEdited, writeFace, writeDeny) {
93
94
  return defineTool({
94
95
  name: "Edit",
@@ -114,7 +115,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
114
115
  const path = fileArgPath(args);
115
116
  if (path === undefined)
116
117
  return { ok: true };
117
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
118
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
118
119
  if (!r.ok)
119
120
  return { ok: true };
120
121
  if (a.old_string === a.new_string)
@@ -152,7 +153,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
152
153
  const path = fileArgPath(args);
153
154
  if (path === undefined)
154
155
  return errorResult(`Error (Edit): file_path is required.`);
155
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
156
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
156
157
  if (!r.ok)
157
158
  return errorResult(violationText("Edit", r.violation), violationDetails(r.violation));
158
159
  if (!batch && a.old_string === a.new_string) {
@@ -190,7 +191,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
190
191
  details: { type: "create", filePath: path, content: created },
191
192
  };
192
193
  }
193
- return errorResult(`Error (Edit): ${await enoentMessage(env, r.key, cwdRef?.current ?? rootCanonical, ctx.signal)}`);
194
+ return errorResult(`Error (Edit): ${await enoentMessage(env, r.key, cwdRef?.current ?? rootOf(rootCanonical), ctx.signal)}`);
194
195
  }
195
196
  const editInfo = await env.fileInfo(r.key, ctx.signal);
196
197
  if (editInfo.ok && editInfo.value.size > MAX_EDIT_BYTES) {
@@ -346,7 +347,7 @@ export function createWriteFileTool(env, state, rootCanonical, cwdRef, additiona
346
347
  return { ok: true };
347
348
  if (ipynbRedirect("Write", path))
348
349
  return { ok: true };
349
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
350
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
350
351
  if (!r.ok)
351
352
  return { ok: true };
352
353
  const exists = await env.exists(r.key, ctx.signal);
@@ -365,7 +366,7 @@ export function createWriteFileTool(env, state, rootCanonical, cwdRef, additiona
365
366
  const ipynb = ipynbRedirect("Write", path);
366
367
  if (ipynb)
367
368
  return errorResult(ipynb);
368
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
369
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
369
370
  if (!r.ok)
370
371
  return errorResult(violationText("Write", r.violation), violationDetails(r.violation));
371
372
  const exists = await env.exists(r.key, ctx.signal);
@@ -462,7 +463,7 @@ export function createNotebookEditTool(env, state, rootCanonical, cwdRef, additi
462
463
  return { ok: false, code: "invalid", message: NOTEBOOK_CELL_TYPE_REQUIRED_MESSAGE };
463
464
  if (mode !== "insert" && !a.cell_id)
464
465
  return { ok: false, code: "invalid", message: NOTEBOOK_CELL_ID_REQUIRED_MESSAGE };
465
- const r = await resolveKey(env, rootCanonical, a.notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
466
+ const r = await resolveKey(env, rootOf(rootCanonical), a.notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
466
467
  if (!r.ok)
467
468
  return { ok: true };
468
469
  const notRead = requireRead(state, r.key);
@@ -482,7 +483,7 @@ export function createNotebookEditTool(env, state, rootCanonical, cwdRef, additi
482
483
  return errorResult(NOTEBOOK_CELL_TYPE_REQUIRED_MESSAGE);
483
484
  if (mode !== "insert" && !cell_id)
484
485
  return errorResult(NOTEBOOK_CELL_ID_REQUIRED_MESSAGE);
485
- const r = await resolveKey(env, rootCanonical, notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
486
+ const r = await resolveKey(env, rootOf(rootCanonical), notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
486
487
  if (!r.ok)
487
488
  return errorResult(violationText("NotebookEdit", r.violation), violationDetails(r.violation));
488
489
  const notRead = requireRead(state, r.key);
@@ -26,6 +26,9 @@ export interface HandsToolkitOptions {
26
26
  * `bash_readonly` IS constrained by them (that face refuses a read outside the roots), so widening
27
27
  * here widens what the read-only band may read. */
28
28
  additionalRoots?: readonly string[];
29
+ /** The WRITE tools' primary root (edit_file / write_file / notebook_edit), read per call: the leg's write location, which
30
+ * moves with an EnterWorktree switch while the read tools keep `rootCanonical`. Absent ⇒ `rootCanonical` (one root). */
31
+ writeRoot?: () => string;
29
32
  /** The read-boundary whitelist: extra allowed containment roots for the READ faces only —
30
33
  * read_file/grep/glob/repo_map and `bash_readonly` admit them; edit_file/write_file/notebook_edit
31
34
  * and the full `bash`'s disclosure roots deliberately do NOT (widening reads must never silently
@@ -17,6 +17,7 @@ export { BASH_CLASSIFY_EXTRA_ALLOW, bashClassifyDefaultAllow } from "./bash-read
17
17
  import { checkedReadDenyHomes, compileReadDeny, compileWriteDeny, readDenyBuiltinConfigOf, readDenyRowAnchor } from "./read-deny.js";
18
18
  import { withGateTimeout } from "../../core/gate-bounded-await.js";
19
19
  import { carriedReadFaceOf, carryHomeViews, homeViewsAt, placeReadDenyAtHome, placementViewsOf, readDenyPlacedLater, sayPlacementLost } from "./read-deny-home.js";
20
+ import { readFloorSeat } from "./read-floor.js";
20
21
  import { deploymentFaceClampNotice, resolveContainmentFace } from "./containment-face.js";
21
22
  export * from "./containment-face.js";
22
23
  import {} from "./fs-shared.js";
@@ -43,6 +44,7 @@ export function createHandsToolkit(env, readFileState, rootCanonical, opts = {})
43
44
  ? undefined
44
45
  : (canonicalKey, c) => readAdmission?.(c.toolCallId, canonicalKey) === true || (bgOutput?.(canonicalKey, c) ?? false);
45
46
  const { readDeny, writeDeny, afterPlacement } = carriedFace !== undefined ? { readDeny: carriedFace.readDeny, writeDeny: carriedFace.writeDeny, afterPlacement: (tool) => tool } : bandOwnTables(env, opts);
47
+ const readFloor = readFloorSeat(readDeny);
46
48
  const readFace = resolveContainmentFace({
47
49
  kind: "read",
48
50
  depsFace: opts.readFace,
@@ -81,16 +83,17 @@ export function createHandsToolkit(env, readFileState, rootCanonical, opts = {})
81
83
  afterPlacement(createReadFileTool(env, readFileState, rootCanonical, readCwd, readFaceRoots, opts.readImageDownsampler, opts.pdfModelCapabilities, bgOutputReadExemption, readDeny, readFace, opts.reminderMark, opts.reminderDisclosureCounts, reader)),
82
84
  ];
83
85
  if (handsWriteHalfMounts({ readOnly })) {
84
- tools.push(createEditFileTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createWriteFileTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createNotebookEditTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
86
+ tools.push(createEditFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createWriteFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createNotebookEditTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
85
87
  }
86
88
  tools.push(afterPlacement(createGrepTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)), afterPlacement(createGlobTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)), afterPlacement(createRepoMapTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)));
87
89
  if (includeShell) {
88
- tools.push(readOnly
90
+ tools.push(afterPlacement(readOnly
89
91
  ? createBashReadonlyTool(env, rootCanonical, new Set(bashReadonlyAllow ?? BASH_READONLY_DEFAULT_ALLOW), {
90
92
  ...(opts.bashDefaultTimeoutMs !== undefined ? { bashDefaultTimeoutMs: opts.bashDefaultTimeoutMs } : {}),
91
93
  ...(opts.bashMaxTimeoutMs !== undefined ? { bashMaxTimeoutMs: opts.bashMaxTimeoutMs } : {}),
92
94
  ...(opts.onNotice !== undefined ? { onNotice: opts.onNotice } : {}),
93
95
  ...(opts.shellReadAdmission !== undefined ? { shellReadAdmission: opts.shellReadAdmission } : {}),
96
+ ...(readFloor !== undefined ? { readFloor } : {}),
94
97
  ...(opts.onToolProgress !== undefined ? { onToolProgress: opts.onToolProgress } : {}),
95
98
  })
96
99
  : createBashTool(env, rootCanonical, commitCoAuthor, cwdRef, {
@@ -107,12 +110,13 @@ export function createHandsToolkit(env, readFileState, rootCanonical, opts = {})
107
110
  ...(opts.oneShot !== undefined ? { oneShot: opts.oneShot } : {}),
108
111
  ...(additionalRoots !== undefined ? { additionalRoots } : {}),
109
112
  ...(opts.shellReadAdmission !== undefined ? { shellReadAdmission: opts.shellReadAdmission } : {}),
113
+ ...(readFloor !== undefined ? { readFloor } : {}),
110
114
  ...(opts.bashDefaultTimeoutMs !== undefined ? { bashDefaultTimeoutMs: opts.bashDefaultTimeoutMs } : {}),
111
115
  ...(opts.bashMaxTimeoutMs !== undefined ? { bashMaxTimeoutMs: opts.bashMaxTimeoutMs } : {}),
112
116
  ...(opts.onNotice !== undefined ? { onNotice: opts.onNotice } : {}),
113
117
  ...(opts.monitorToolActive !== undefined ? { monitorToolActive: opts.monitorToolActive } : {}),
114
118
  ...(opts.reminderMark !== undefined ? { reminderMark: opts.reminderMark } : {}),
115
- }));
119
+ })));
116
120
  if (!readOnly && mountBackgroundTaskTools && hasBackgroundShell(env)) {
117
121
  const sessionAxis = opts.sessionId !== undefined ? { sessionId: opts.sessionId } : {};
118
122
  tools.push(opts.taskRegistry
@@ -422,6 +422,9 @@ export interface ProgramRow {
422
422
  readonly movesBase?: "stack";
423
423
  /** A shell block word at the program position: it names no command of its own. */
424
424
  readonly syntax?: "block";
425
+ /** What it writes to its standard output, read off its operands ({@link printedText}): `words` = its operands joined
426
+ * by a space (`echo`), `format` = its one operand as a format (`printf`). */
427
+ readonly prints?: "words" | "format";
425
428
  /** Git-style subcommands: the word after the program's own options names one, and the words after it are read by
426
429
  * ITS grammar, operands and traversal ({@link subcommandOf}). */
427
430
  readonly subcommands?: Readonly<Record<string, Subcommand>>;
@@ -875,6 +878,16 @@ export declare function readProgramTextLanguage(row: ProgramRow | undefined): st
875
878
  /** The program text of an invocation of a row whose first positional is program text, under EACH implementation's
876
879
  * grammar (no text says which one runs, so a reader combines the readings). */
877
880
  export declare function programTextReadings(row: ProgramRow, args: readonly string[]): ProgramTextReading[];
881
+ /**
882
+ * The text a printer row ({@link ProgramRow.prints}) writes to its standard output, read off its argv (the program word
883
+ * excluded; `undefined` = a word whose value the command does not spell). `undefined` wherever the words do not spell the
884
+ * text: such a word, an option the row does not explain, an escape the program may interpret (a backslash: `echo -e`, an
885
+ * `echo` that reads escapes by default, every `printf` format), a format with a directive (`%`), a format behind an
886
+ * option (`printf -v NAME` writes a variable, not the output), or a row that prints nothing it is handed. What the printer
887
+ * is where the command runs (a function or an alias of its name, a trap around it)
888
+ * is not read here: the one reader of this text uses it to refuse, never to clear (`ShellReadSegment.printed`).
889
+ */
890
+ export declare function printedText(row: ProgramRow | undefined, args: readonly (string | undefined)[]): string | undefined;
878
891
  /**
879
892
  * The subcommand an argv (the program word excluded) names, and the row it is read by: the first word past the
880
893
  * program's own options, which are read EXACTLY by the row's grammar — an option the row does not declare may take the
@@ -1331,6 +1331,21 @@ function programTextUnder(g, args) {
1331
1331
  const script = supplied ? scripts.join("\n") : firstOperand;
1332
1332
  return script === undefined ? "none" : { text: script };
1333
1333
  }
1334
+ export function printedText(row, args) {
1335
+ const words = args.filter((a) => a !== undefined);
1336
+ if (row?.prints === undefined || words.length !== args.length)
1337
+ return undefined;
1338
+ const events = readArgRoles(row, words);
1339
+ const from = events.find((e) => e.kind === "operand" || e.kind === "dash-word-operand")?.at ?? words.length;
1340
+ if (events.some((e) => e.at < from && e.kind === "option" && e.reading === "speculative"))
1341
+ return undefined;
1342
+ const printed = words.slice(from);
1343
+ if (printed.some((w) => w.includes("\\")))
1344
+ return undefined;
1345
+ if (row.prints === "words")
1346
+ return printed.join(" ");
1347
+ return from === 0 && printed.length === 1 && !printed[0].includes("%") ? printed[0] : undefined;
1348
+ }
1334
1349
  function exactSpec(g, tok) {
1335
1350
  if (tok.startsWith("--"))
1336
1351
  return tok.includes("=") ? undefined : g.long[tok.slice(2)];
@@ -585,7 +585,7 @@ const git = {
585
585
  const noPath = (key, rest, extra = {}) => ({ key, grammars: [], operands: { rest }, witness: BINARY, ...extra });
586
586
  const BUILTIN_ONLY = { declared: "a shell builtin with no binary of its own on every host: its words are read by the shell" };
587
587
  const noPathRows = [
588
- noPath("pwd", LABEL, { builtin: "inert" }), noPath("echo", LABEL, { builtin: "inert", grammars: [grammar(switches("neE"), {}, { afterFirstOperand: "operands" })] }), noPath("printf", LABEL, { grammars: [grammar({ v: val(BINDS_NAME) })] }), noPath("whoami", LABEL), noPath("uname", LABEL),
588
+ noPath("pwd", LABEL, { builtin: "inert" }), noPath("echo", LABEL, { builtin: "inert", grammars: [grammar(switches("neE"), {}, { afterFirstOperand: "operands" })], prints: "words" }), noPath("printf", LABEL, { grammars: [grammar({ v: val(BINDS_NAME) })], prints: "format" }), noPath("whoami", LABEL), noPath("uname", LABEL),
589
589
  noPath("which", LABEL), noPath("basename", LABEL), noPath("dirname", LABEL),
590
590
  { key: "tr", grammars: [], operands: { rest: LABEL, stdinBelow: "always" }, witness: BINARY },
591
591
  noPath("cal", COUNT), noPath("uptime", LABEL), noPath("id", LABEL), noPath("groups", LABEL), noPath("nproc", LABEL), noPath("locale", LABEL),
@@ -12,9 +12,10 @@ import { type PathGuardFold, type PathGuardRow, type PathRowsHit, type TargetVie
12
12
  * absolute path (a path that is not absolute is not placed, and the row does not judge it).
13
13
  * String shorthand ≡ `{ pattern }`. Matching is ASCII-case-insensitive by default (a case-insensitive
14
14
  * filesystem serves `.SSH` and `.ssh` as the same directory); `caseSensitive: true` opts a single
15
- * entry out. Unicode normalization (NFC/NFD) and volume-level case semantics are NOT modeled (v1
16
- * residual, shared with the write guard; the canonical view — realpath returns the on-disk spelling —
17
- * covers half of it).
15
+ * entry out. Names are compared in canonical composition (NFC) whatever the case setting — `ü` as one code point and `u` plus a
16
+ * combining diaeresis are one name, as on a filesystem that compares names by canonical equivalence; a compatibility form
17
+ * (a ligature) is another name. Volume-level case semantics are NOT modeled (v1 residual, shared with the write guard; the
18
+ * canonical view — realpath returns the on-disk spelling — covers half of it).
18
19
  */
19
20
  export type ReadDenyEntry = string | {
20
21
  pattern: string;
@@ -422,11 +423,13 @@ export declare const READ_FACE_DEFAULT_DENY_ENTRIES: readonly ReadDenyEntry[];
422
423
  * themselves, `ß` stays `ß`). Both sides of a comparison go through it.
423
424
  */
424
425
  export declare function ignoreCaseFold(s: string): string;
425
- /** How a compiled pattern compares: `none` byte for byte; `ascii` and `unicode` through the fold of that name, both sides —
426
- * the pattern's side at compile, the segments' side by whoever tests (once per path: {@link segmentReadingsOf}). */
426
+ /** How a compiled pattern compares, both sides composed ({@link composed}), then: `none` byte for byte; `ascii` and `unicode`
427
+ * through the case fold of that name — the pattern's side at compile, the segments' side by whoever tests (once per path:
428
+ * {@link segmentReadingsOf}). */
427
429
  export type SegmentFold = "none" | "ascii" | "unicode";
428
430
  /** The function that folds a string as each fold folds — the one place that says which function that is (the pattern at compile,
429
- * a path's segments in the readings, an anchor's segments all read it, at the time they fold). */
431
+ * a path's segments in the readings, an anchor's segments all read it, at the time they fold): composition first, in every
432
+ * fold, then the fold's own case mapping. */
430
433
  export declare const SEGMENT_FOLDS: Record<SegmentFold, (s: string) => string>;
431
434
  /** One compiled segment of a pattern: `*` stands for any run of characters but a separator, every other character for itself. */
432
435
  export interface SegmentMatcher {
@@ -454,11 +457,11 @@ export interface CompiledSegmentPattern {
454
457
  unplacedHome?: true;
455
458
  }
456
459
  /**
457
- * Compile one segment-glob pattern (shared engine). `fold`:
458
- * · "none" — byte-exact segments;
460
+ * Compile one segment-glob pattern (shared engine). `fold` (every fold first composes the name, {@link composed}):
461
+ * · "none" — exact segments, case included;
459
462
  * · "ascii" — ASCII-case-insensitive (deny-set contract);
460
- * · "unicode" — the fold a RegExp `i` flag applies, {@link ignoreCaseFold} (the write guard's historical host-keyed
461
- * behavior — kept for it answer for answer; NOT used by the deny set).
463
+ * · "unicode" — the fold a RegExp `i` flag applies, {@link ignoreCaseFold}, over the composed name (the write guard's
464
+ * historical host-keyed case behavior; NOT used by the deny set).
462
465
  * The pattern is folded here, once; the segments a row is tested on are folded by whoever tests, once per path
463
466
  * ({@link segmentReadingsOf}) — never once per row per test.
464
467
  * Returns null when the pattern reduces to zero segments — the CALLER owns its loud path (the two
@@ -337,16 +337,35 @@ export function ignoreCaseFold(s) {
337
337
  }
338
338
  return out;
339
339
  }
340
- export const SEGMENT_FOLDS = { none: (s) => s, ascii: asciiLower, unicode: ignoreCaseFold };
340
+ function composed(s) {
341
+ return /[^\x00-\x7f]/.test(s) ? s.normalize("NFC") : s;
342
+ }
343
+ export const SEGMENT_FOLDS = {
344
+ none: composed,
345
+ ascii: (s) => asciiLower(composed(s)),
346
+ unicode: (s) => ignoreCaseFold(composed(s)),
347
+ };
341
348
  function foldSegments(fold, segs) {
342
349
  return segs.map((s) => SEGMENT_FOLDS[fold](s));
343
350
  }
351
+ const SPELLED_FOLDS = { none: (s) => s, ascii: asciiLower, unicode: ignoreCaseFold };
352
+ function readingsOfViews(fold, views) {
353
+ const out = [];
354
+ for (const segs of views) {
355
+ const twin = foldSegments(fold, segs);
356
+ out.push(twin);
357
+ const spelled = segs.map((s) => SPELLED_FOLDS[fold](s));
358
+ if (spelled.some((s, i) => s !== twin[i]))
359
+ out.push(spelled);
360
+ }
361
+ return out;
362
+ }
344
363
  function foldedViewsOf(views) {
345
364
  const memo = new Map();
346
365
  return (fold) => {
347
366
  let folded = memo.get(fold);
348
367
  if (folded === undefined)
349
- memo.set(fold, (folded = fold === "none" ? views : views.map((segs) => foldSegments(fold, segs))));
368
+ memo.set(fold, (folded = readingsOfViews(fold, views)));
350
369
  return folded;
351
370
  };
352
371
  }
@@ -376,12 +395,13 @@ function segmentReadingsOf(path, aliasResolved) {
376
395
  const known = SEGMENT_READINGS.get(key);
377
396
  if (known !== undefined)
378
397
  return known;
379
- const views = segmentViewsOf(path, aliasResolved ? { aliasResolved } : undefined);
398
+ const spelledViews = segmentViewsOf(path, aliasResolved ? { aliasResolved } : undefined);
399
+ const views = readingsOfViews("none", spelledViews);
380
400
  let folded;
381
401
  const readings = {
382
402
  views,
383
- lowered: views.map((v) => foldSegments("ascii", v)),
384
- folded: () => (folded ??= views.map((v) => foldSegments("unicode", v))),
403
+ lowered: readingsOfViews("ascii", spelledViews),
404
+ folded: () => (folded ??= readingsOfViews("unicode", spelledViews)),
385
405
  rooted: isAbsoluteForFamily("own", path),
386
406
  };
387
407
  if (SEGMENT_READINGS.size >= 512)
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The byte floor's one adapter: the read-deny table a call judges with, as the {@link ReadFloor} its command
3
+ * start carries to the environment the command runs in.
4
+ *
5
+ * One table, two readers. The shell read station judges what a command NAMES (its operands, its expansions, a
6
+ * recursive read's root — never the tree below a root, the zero-friction reading); the environment judges what a process
7
+ * OPENS. Both read the same rows through the same judgment: this module derives nothing — the rows are the ones the
8
+ * engine's refusals cite (`readDenySeat`) and the judgment is the table's own `matchPath`, read off the table the call
9
+ * is pinned to (`seatForCall`). A floor never loosens the station: what the station refuses never starts.
10
+ */
11
+ import type { ReadFloor } from "../../internal/harness-types.js";
12
+ import { type ReadDenyMatcher } from "./read-deny.js";
13
+ /** The floor ONE call's command start carries, read off the table that call judges with — `undefined` when the table
14
+ * holds no row (an empty table keeps nothing, and the start then carries no floor: the options are the ones a start
15
+ * took before the floor existed). */
16
+ export type ReadFloorSeat = (toolCallId: string | undefined) => ReadFloor | undefined;
17
+ /** The seat over a face's deny table (the run's, or a library-direct band's own); `undefined` for no table. Built once per
18
+ * mount; each call reads its own pinned table through it. */
19
+ export declare function readFloorSeat(table: ReadDenyMatcher | undefined): ReadFloorSeat | undefined;
@@ -0,0 +1,23 @@
1
+ import { readDenySeat, seatForCall } from "./read-deny.js";
2
+ import { isAbsoluteForFamily } from "./safety.js";
3
+ export function readFloorSeat(table) {
4
+ if (table === undefined)
5
+ return undefined;
6
+ return (toolCallId) => readFloorOf(seatForCall(table, toolCallId));
7
+ }
8
+ function readFloorOf(table) {
9
+ const rows = Object.freeze([...readDenySeat(table).denyEntries]);
10
+ if (rows.length === 0)
11
+ return undefined;
12
+ const denies = (absolutePath) => {
13
+ if (typeof absolutePath !== "string" || !isAbsoluteForFamily("own", absolutePath))
14
+ return rows[0];
15
+ try {
16
+ return table.matchPath(absolutePath)?.pattern ?? null;
17
+ }
18
+ catch {
19
+ return rows[0];
20
+ }
21
+ };
22
+ return Object.freeze({ rows, denies });
23
+ }
@@ -444,7 +444,7 @@ function within(rootCanonical, p) {
444
444
  }
445
445
  export async function resolveKey(env, rootCanonical, path, signal, baseCwd, additionalRoots, exactFileReadExemption, readDeny, containmentFace) {
446
446
  const views = await readPath(env, path, baseCwd ?? rootCanonical, { root: rootCanonical, ...(baseCwd !== undefined ? { cwd: baseCwd } : {}) }, { intent: "resolve", views: readDeny !== undefined ? "chain" : "canonical" }, signal);
447
- const canon = views.canonical ?? (await canonicalizeTarget(env, path, signal, pathFamilyOf({ root: rootCanonical }), baseCwd));
447
+ const canon = views.canonical ?? { ok: false, message: `cannot resolve path "${clipSpelling(path)}": ${views.lexical?.kind === "unreadable" ? views.lexical.reason : "the environment was not asked where it lands"}; refused.` };
448
448
  if (!canon.ok)
449
449
  return { ok: false, violation: { code: "invalid", message: canon.message } };
450
450
  const key = canon.key;
@@ -545,6 +545,10 @@ async function probeRealTarget(env, path, target, family, signal) {
545
545
  if (!newPath.ok) {
546
546
  return { ok: false, message: newPath.message, unresolvedSymlink: true };
547
547
  }
548
+ if ("reprobe" in newPath) {
549
+ abs = newPath.reprobe;
550
+ continue;
551
+ }
548
552
  return { ok: true, key: newPath.key };
549
553
  }
550
554
  const canon = await env.canonicalPath(abs, signal);
@@ -559,6 +563,10 @@ async function probeRealTarget(env, path, target, family, signal) {
559
563
  if (!viaAncestors.ok) {
560
564
  return { ok: false, message: viaAncestors.message, unresolvedSymlink: true };
561
565
  }
566
+ if ("reprobe" in viaAncestors) {
567
+ abs = viaAncestors.reprobe;
568
+ continue;
569
+ }
562
570
  return { ok: true, key: viaAncestors.key };
563
571
  }
564
572
  if (!env.readLink) {
@@ -584,7 +592,7 @@ async function probeRealTarget(env, path, target, family, signal) {
584
592
  }
585
593
  abs = reabs.value;
586
594
  }
587
- return { ok: false, message: `symlink chain for "${path}" exceeded the hop cap; target unresolved`, unresolvedSymlink: true };
595
+ return { ok: false, message: `resolving "${path}" exceeded the hop cap (links followed, or a \`..\` back into an existing directory re-probed); target unresolved`, unresolvedSymlink: true };
588
596
  }
589
597
  function parentDir(abs) {
590
598
  const i = lastSepIndex(abs);
@@ -623,15 +631,39 @@ async function canonicalizeNewPath(env, abs, family, signal, opts) {
623
631
  if (!canon.ok) {
624
632
  return { ok: false, message: `cannot canonicalize existing ancestor "${candidate}": ${canon.error.message}` };
625
633
  }
626
- const tailSegments = tail.reverse();
627
- const canonSep = nativeSepOf(canon.value);
628
- if (tailSegments.length === 0)
629
- return { ok: true, key: canon.value };
630
- return { ok: true, key: [canon.value.replace(family === "win" ? /[\\/]+$/ : /\/+$/, ""), ...tailSegments].join(canonSep) };
634
+ return { ok: true, ...rejoinMissingTail(canon.value, tail.reverse(), family) };
631
635
  }
632
636
  tail.push(parts.pop());
633
637
  }
634
- return { ok: true, key: abs };
638
+ const share = family === "win" && isUncSpelling(abs) ? tail.pop() : undefined;
639
+ return { ok: true, ...rejoinMissingTail(`${[...parts, ...(share !== undefined ? [share] : [])].join(sep)}${sep}`, tail.reverse(), family) };
640
+ }
641
+ function rejoinMissingTail(canonical, tail, family) {
642
+ const trimmed = (at) => at.replace(family === "win" ? /[\\/]+$/ : /\/+$/, "");
643
+ let at = canonical;
644
+ const names = [];
645
+ for (let i = 0; i < tail.length; i++) {
646
+ const seg = tail[i];
647
+ if (seg === "" || seg === ".")
648
+ continue;
649
+ if (seg !== "..")
650
+ names.push(seg);
651
+ else if (names.length > 1)
652
+ names.pop();
653
+ else {
654
+ if (names.length === 1)
655
+ names.pop();
656
+ else {
657
+ const up = normalizeAbsPathLexically(`${at}/..`);
658
+ if (up !== normalizeAbsPathLexically(at))
659
+ at = up;
660
+ }
661
+ const rest = tail.slice(i + 1);
662
+ if (rest.some((s) => s !== "" && s !== "."))
663
+ return { reprobe: [trimmed(at), ...rest].join(nativeSepOf(at)) };
664
+ }
665
+ }
666
+ return { key: names.length === 0 ? at : [trimmed(at), ...names].join(nativeSepOf(at)) };
635
667
  }
636
668
  export function violationText(toolName, v) {
637
669
  return `Error (${toolName}): ${v.message}`;
@@ -40,25 +40,6 @@ const TYPE_GLOBS = {
40
40
  css: "*.{css,scss,less}",
41
41
  };
42
42
  const basename = (p) => p.slice(Math.max(p.lastIndexOf("/"), p.lastIndexOf("\\")) + 1);
43
- function collapseDotSegments(p) {
44
- const win = isWinFormPath(p);
45
- const lead = (win ? /^[\\/]*/ : /^\/*/).exec(p)?.[0] ?? "";
46
- const sep = win ? "\\" : "/";
47
- const parts = p.slice(lead.length).split(win ? /[\\/]+/ : /\/+/);
48
- const floor = !win ? 0 : lead.length >= 2 ? 2 : /^[A-Za-z]:$/.test(parts[0] ?? "") ? 1 : 0;
49
- const kept = [];
50
- for (const part of parts) {
51
- if (part === "" || part === ".")
52
- continue;
53
- if (part === "..") {
54
- if (kept.length > floor)
55
- kept.pop();
56
- continue;
57
- }
58
- kept.push(part);
59
- }
60
- return kept.length === 0 ? "" : lead + kept.join(sep);
61
- }
62
43
  const NO_MATCHES = "No matches.";
63
44
  const GREP_LINE_CLIP = 500;
64
45
  function clipLine(line) {
@@ -813,18 +794,19 @@ export async function jsGrepDetailed(env, root, p, signal, guards, deny, denyOut
813
794
  const mode = p.output_mode ?? "files_with_matches";
814
795
  const rel = (abs) => (abs.startsWith(rootPrefix) ? abs.slice(rootPrefix.length) : abs);
815
796
  const startWin = isWinFormPath(start);
816
- const startNorm = collapseDotSegments(start);
817
- const targetSpell = p.path ? p.path.replace(startWin ? /[\\/]+$/ : /\/+$/, "") : "";
797
+ const trailingSeparators = startWin ? /[\\/]+$/ : /\/+$/;
798
+ const anchor = start.replace(trailingSeparators, "");
799
+ const targetSpell = p.path ? p.path.replace(trailingSeparators, "") : "";
818
800
  const isBoundary = (c) => c === "/" || (startWin && c === "\\");
819
801
  const relOut = (abs) => {
820
802
  if (!p.path) {
821
803
  const r = rel(abs);
822
804
  return r === abs ? r : `./${r}`;
823
805
  }
824
- if (abs === startNorm || abs === start)
806
+ if (abs === start || abs === anchor)
825
807
  return targetSpell;
826
- if (abs.startsWith(startNorm) && isBoundary(abs[startNorm.length]))
827
- return targetSpell + abs.slice(startNorm.length);
808
+ if (abs.startsWith(anchor) && isBoundary(abs[anchor.length]))
809
+ return targetSpell + abs.slice(anchor.length);
828
810
  return rel(abs);
829
811
  };
830
812
  if (p.glob) {
@@ -105,8 +105,15 @@ export interface ShellReadVerdictFacts {
105
105
  readonly writesPlaced?: true;
106
106
  /** A FACT beside the disposition: a write target this command names lands on the write-protection table — judged by
107
107
  * the table's own judge, as a write tool's target is — so the command's ask carries that table's class, whichever
108
- * mode reads it. Absent ⇒ no target the station established is covered (or no judge is mounted). */
108
+ * mode reads it. Absent ⇒ no target the station established is covered (or no judge is mounted). Said of a target whose
109
+ * TEXT names the row (the table's spelling view of one of its spellings); a covered target whose text names none is the
110
+ * member below — one target, one of the two. */
109
111
  readonly writeProtected?: true;
112
+ /** A FACT beside the disposition: a write target this command names meets the write-protection table only where it resolves
113
+ * on disk (its real target, a link on the way) — none of the target's spellings names a row — so the command's ask carries
114
+ * that reading's class, which the auto-mode classifier does not answer. Beside `writeProtected` when another target's text
115
+ * names a row. Absent ⇒ no such target (or no judge is mounted). */
116
+ readonly writeProtectedOnDisk?: true;
110
117
  /** A FACT beside the disposition: a target this command's program WRITES was placed and the environment could not say
111
118
  * where it leads ({@link EstablishedRead.unresolved}) — the reading's `target_unresolved` fact, the same one a write
112
119
  * tool's unresolved target states, so the command's ask carries that class (no automatic lane answers it; the shell face
@@ -254,7 +261,7 @@ export interface ShellReadJudgment {
254
261
  * holding a command, an environment and a boundary gets the decision the gate would reach for them.
255
262
  *
256
263
  * An ENVIRONMENT question, not a text question: a symlink that leaves the roots, a pattern that expands
257
- * onto a deny row, a traversal root that cannot be enumerated are answered by `env`, not guessed from the
264
+ * onto a deny row, a traversal root that lands elsewhere than it is spelled are answered by `env`, not guessed from the
258
265
  * spelling. {@link judgeShellReadLexically} is the no-environment reading and not a substitute — it is
259
266
  * LAXER where only a filesystem sees the escape (an in-root symlink pointing out vouches) and answers a
260
267
  * pattern on its spelling alone, so the two diverge in both directions.