@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
@@ -104,12 +104,13 @@ function unplacedOptionsOf(judged) {
104
104
  async function writeGuardsOf(judged, boundary, env, signal) {
105
105
  const judge = boundary.writeTargetJudge;
106
106
  if (judge === undefined)
107
- return { unplaced: false, writeProtected: false };
107
+ return { unplaced: false, writeProtected: false, writeProtectedOnDisk: false };
108
108
  const { runs, concurrent } = runOrderOf(judged);
109
109
  const asKey = new Map();
110
110
  const asSpelling = new Map();
111
111
  const landingKeys = new Set();
112
112
  const writtenBy = runs.map(() => []);
113
+ const targets = [];
113
114
  const add = (into, view, child, at) => {
114
115
  if (!isAbsoluteForFamily(pathFamilyOf({ root: view }), view))
115
116
  return;
@@ -126,10 +127,16 @@ async function writeGuardsOf(judged, boundary, env, signal) {
126
127
  add(key ? asKey : asSpelling, f.read.target, child, at);
127
128
  if (key && written.seat === "landing")
128
129
  landingKeys.add(f.read.target);
129
- if (written.seat === "landing")
130
- for (const spelling of f.read.spellings)
130
+ const views = [[f.read.target, key]];
131
+ if (written.seat === "landing") {
132
+ for (const spelling of f.read.spellings) {
131
133
  add(asSpelling, spelling, child, at);
134
+ views.push([spelling, false]);
135
+ }
136
+ }
132
137
  writtenBy[at].push(f.read.target, ...f.read.spellings);
138
+ const derived = f.read.derivedSpellings ?? [];
139
+ targets.push({ views, text: f.read.established === "expansion" ? (f.read.origin !== undefined ? [f.read.origin] : []) : f.read.spellings.filter((s) => !derived.includes(s)) });
133
140
  }
134
141
  });
135
142
  const probes = new Map();
@@ -160,20 +167,52 @@ async function writeGuardsOf(judged, boundary, env, signal) {
160
167
  };
161
168
  const answer = async (view, key) => (await judge(view, { fs: env, ...(signal !== undefined ? { signal } : {}), ...(key ? { canonical: true } : {}) })) ?? "clear";
162
169
  const asked = [...[...asKey].map(([view, v]) => [view, v, true]), ...[...asSpelling].filter(([view]) => !landingKeys.has(view)).map(([view, v]) => [view, v, false])];
170
+ const slotOf = (view, key) => `${key || landingKeys.has(view) ? "key" : "spelling"}\u0000${view}`;
171
+ const askable = new Map(asked.map(([view, v, key]) => [slotOf(view, key), { view, v, key }]));
172
+ const answers = new Map();
173
+ const answerAt = async (view, key) => {
174
+ const slot = slotOf(view, key);
175
+ const known = answers.get(slot);
176
+ if (known !== undefined)
177
+ return known;
178
+ const a = askable.get(slot);
179
+ const found = a === undefined || (!(await writable(a.view, a.v)) && !changedBefore(a.view, a.v.at)) ? "clear" : await answer(a.view, a.key);
180
+ answers.set(slot, found);
181
+ return found;
182
+ };
183
+ const textNamesRow = async (text) => {
184
+ for (const spelling of text) {
185
+ if (!isAbsoluteForFamily(pathFamilyOf({ root: spelling }), spelling))
186
+ continue;
187
+ if ((await judge(spelling, { fs: env, spellingOnly: true })) === "protected")
188
+ return true;
189
+ }
190
+ return false;
191
+ };
163
192
  let unplaced = false;
164
193
  let writeProtected = false;
165
- for (const [view, v, key] of asked) {
166
- if (!(await writable(view, v)) && !changedBefore(view, v.at))
167
- continue;
168
- const found = await answer(view, key);
169
- if (found === "protected")
170
- writeProtected = true;
171
- if (found !== "clear")
172
- unplaced = true;
173
- if (writeProtected)
194
+ let writeProtectedOnDisk = false;
195
+ for (const target of targets) {
196
+ let covered = false;
197
+ for (const [view, key] of target.views) {
198
+ const found = await answerAt(view, key);
199
+ if (found !== "clear")
200
+ unplaced = true;
201
+ if (found === "protected") {
202
+ covered = true;
203
+ break;
204
+ }
205
+ }
206
+ if (covered) {
207
+ if (await textNamesRow(target.text))
208
+ writeProtected = true;
209
+ else
210
+ writeProtectedOnDisk = true;
211
+ }
212
+ if (writeProtected && writeProtectedOnDisk)
174
213
  break;
175
214
  }
176
- return { unplaced, writeProtected };
215
+ return { unplaced, writeProtected, writeProtectedOnDisk };
177
216
  }
178
217
  export function readStationMemberOf(call, members) {
179
218
  return seatOf("fold.readStation", members, call);
@@ -311,7 +350,7 @@ function judgePlan(plan, established, boundary) {
311
350
  return judgeEstablishedPlan(plan, established.reads, boundary, (n) => {
312
351
  const nested = established.nested.get(n);
313
352
  return nested === undefined ? { plan: n, segments: [], guards: stationGuards(boundary), writeGuards: writeFaceGuards(boundary) } : judgePlan(n, nested, boundary);
314
- });
353
+ }, (n) => judgePlan(n, establishShellReadsLexically(n, boundary), boundary));
315
354
  }
316
355
  async function applyAlsoInside(judged, boundary) {
317
356
  const alsoInside = boundary.alsoInside;
@@ -336,6 +375,7 @@ async function applyAlsoInside(judged, boundary) {
336
375
  segment: s.segment,
337
376
  findings: s.findings.map((f) => (outsideRead(f) && rescued.has(f.read.target) ? { ...f, kind: "none", containment: "inside" } : f)),
338
377
  nested: s.nested.map(rewrite),
378
+ printed: s.printed,
339
379
  })),
340
380
  });
341
381
  return rewrite(judged);
@@ -352,13 +392,18 @@ async function runShellReadStation(tool, command, declared, seat, readers, estab
352
392
  };
353
393
  let judged = judgedNow();
354
394
  let judgedVerdict = verdictOf(tool, seat, foldShellReadFindings(judged), judged, boundary);
355
- const guarded = judgedVerdict.disposition === "refuse" ? { unplaced: false, writeProtected: false } : await writeGuardsOf(judged, boundary, door.fs, signal);
395
+ const guarded = judgedVerdict.disposition === "refuse" ? { unplaced: false, writeProtected: false, writeProtectedOnDisk: false } : await writeGuardsOf(judged, boundary, door.fs, signal);
356
396
  judged = judgedNow();
357
397
  judgedVerdict = verdictOf(tool, seat, foldShellReadFindings(judged), judged, boundary);
358
398
  const unplaced = unplacedOptionsOf(judged);
359
399
  const placed = judgedVerdict.finding !== "unanswered" && writesPlacedOf(judged, boundary);
360
400
  const unresolved = judgedVerdict.disposition !== "refuse" && runOrderOf(judged).runs.some((s) => s.findings.some((f) => f.read.written !== undefined && f.read.unresolved === true));
361
- const facts = { ...judgedVerdict, ...(guarded.writeProtected ? { writeProtected: true } : {}), ...(unresolved ? { targetUnresolved: true } : {}) };
401
+ const facts = {
402
+ ...judgedVerdict,
403
+ ...(guarded.writeProtected ? { writeProtected: true } : {}),
404
+ ...(guarded.writeProtectedOnDisk ? { writeProtectedOnDisk: true } : {}),
405
+ ...(unresolved ? { targetUnresolved: true } : {}),
406
+ };
362
407
  const verdict = placed && !guarded.unplaced ? { ...facts, writesPlaced: true } : unplaced !== undefined ? { ...facts, unplacedOptions: unplaced } : facts;
363
408
  return { plan, established, judged, boundary, verdict };
364
409
  }
@@ -444,8 +444,9 @@ function establishLegOver(seen, readRoots) {
444
444
  continue;
445
445
  }
446
446
  const spellings = at.spelled !== undefined ? [at.folded, at.spelled] : [at.folded];
447
+ const derived = name !== operand.spelled ? { derivedSpellings: spellings } : {};
447
448
  for (const seat of j.seats ?? ["landing"])
448
- out.push(writtenAt(await canonicalReadOf(j.candidate, at.spelled ?? at.folded, spellings, "canonical", undefined, undefined, signal, seat), j, seat));
449
+ out.push(writtenAt({ ...(await canonicalReadOf(j.candidate, at.spelled ?? at.folded, spellings, "canonical", undefined, undefined, signal, seat)), ...derived }, j, seat));
449
450
  }
450
451
  }
451
452
  return out;
@@ -55,7 +55,7 @@ export async function withHomeViews(door, placed, established, signal) {
55
55
  const home = landed ? await views.of(r.target, r.node === "file" ? { leaf: "file" } : undefined) : {};
56
56
  if (home.unread !== undefined && !unread.includes(home.unread))
57
57
  unread.push(home.unread);
58
- out.push(home.view === undefined || r.spellings.includes(home.view) ? r : { ...r, spellings: [...r.spellings, home.view] });
58
+ out.push(home.view === undefined || r.spellings.includes(home.view) ? r : { ...r, spellings: [...r.spellings, home.view], derivedSpellings: [...(r.derivedSpellings ?? []), home.view] });
59
59
  }
60
60
  reads.set(segment, out);
61
61
  }
@@ -218,16 +218,20 @@ export interface ShellReadBoundary extends BashReadonlyRootBoundary {
218
218
  * `"guarded"`: a deployment row covers it — the target is not placed; `undefined`: nothing covers it. Read by the
219
219
  * station's write facts only. A judgment that throws fails the station's answer (the caller's fail-closed arm). Every lookup
220
220
  * it makes goes through `fs` — the command's door — and through no environment of its own: the station's one decision about
221
- * what a silence means reads the answers the judgment got as well as the ones it did not. */
221
+ * what a silence means reads the answers the judgment got as well as the ones it did not. `spellingOnly` ⇔ judge the path as
222
+ * written and nothing else — the table's spelling view, no lookup, no deployment row: `"protected"` when the text itself names
223
+ * a row of the table (what the station tells a written target's two readings apart by,
224
+ * {@link import("./shell-read-check.js").ShellReadVerdict.writeProtectedOnDisk}). */
222
225
  readonly writeTargetJudge?: (target: string, opts: {
223
226
  readonly fs: ObservedFilesystem;
224
227
  readonly signal?: AbortSignal;
225
228
  readonly canonical?: true;
229
+ readonly spellingOnly?: true;
226
230
  }) => Promise<"protected" | "guarded" | undefined>;
227
231
  }
228
232
  /** How far one candidate got before it was judged. `lexical` = the folded spelling is the judged target
229
233
  * (an isolated sandbox, or a resolver that declares no authority and did not answer); `canonical` = the
230
- * environment resolved it; `expansion` = one path a pattern expanded to or a traversal enumerated;
234
+ * environment resolved it; `expansion` = one path a pattern expanded to (a traversal root is never listed below);
231
235
  * `unestablishable` = the floor could not say where it lands (`cause` says why). */
232
236
  export type ReadEstablishment = "lexical" | "canonical" | "expansion" | "unestablishable";
233
237
  export interface EstablishedRead {
@@ -239,6 +243,11 @@ export interface EstablishedRead {
239
243
  /** Every spelling the deny judge sees BESIDE the target: the folded spelling, the kernel spelling of a
240
244
  * `..` operand, the pattern an expansion came from, the placeholder-carrying fold of a substitution. */
241
245
  readonly spellings: readonly string[];
246
+ /** The members of {@link spellings} a reading of the FILESYSTEM produced rather than the command's text — the home's view of
247
+ * a landed target (read-deny-home.ts), added so the deny judge places a home-anchored row wherever the target really is; the
248
+ * name of a GNU sed `--follow-symlinks` backup when the operand's links supplied it. Every other spelling is the command's
249
+ * own text (folded, or as the kernel walks it). Absent ⇒ none. */
250
+ readonly derivedSpellings?: readonly string[];
242
251
  /** The pattern or traversal root an `expansion` came from, as folded. */
243
252
  readonly origin?: string;
244
253
  /** What the environment said the target IS, where a read asked — only a traversal root asks (it lists the root
@@ -284,11 +293,14 @@ export interface ReadFinding {
284
293
  * @contract shell.read_boundary.friction_floor — what this judge answers is a question about TEXT and the
285
294
  * FILESYSTEM the command will run in: which files the words of a command may name, resolved against the
286
295
  * declared roots, the declared home and the observed working directory, and — where the environment can
287
- * answer — where those spellings really land (symlinks resolved, patterns expanded, traversal roots
288
- * enumerated, each within a bound). It is not a question about what the process will open. A deployment's
289
- * containment for what a shell may reach is the `ExecutionEnv` the command runs in (a sandbox, a
290
- * container, a remote adapter); everything here is the friction floor under that containment. Under an
291
- * isolated sandbox the floor is lexical (the sandbox is the boundary and its filesystem is not this
296
+ * answer — where those spellings really land (symlinks resolved, patterns expanded within a bound). A
297
+ * recursive read's root is one of those words: it is judged by what the command NAMES (the root itself and the
298
+ * placed rows the root contains), never by a tree walked below it. It is not a question about what the
299
+ * process will open. A deployment's containment for what a shell may reach is the `ExecutionEnv` the
300
+ * command runs in (a sandbox, a container, a remote adapter); everything here is the friction floor under
301
+ * that containment, and the read-deny table this station judges with travels to that environment on every
302
+ * command start as `readFloor` (an environment that confines processes keeps it or refuses the start). Under
303
+ * an isolated sandbox the floor is lexical (the sandbox is the boundary and its filesystem is not this
292
304
  * process's to resolve). A deny-listed read is REFUSED on every seat; an out-of-root read asks where a
293
305
  * person can be asked and is refused where none can; a read the floor cannot establish (an expansion it
294
306
  * cannot finish, a spelling the shell rewrites, a working directory it cannot place) is asked or refused
@@ -321,6 +333,10 @@ export interface JudgedSegment {
321
333
  readonly segment: ShellReadSegment;
322
334
  readonly findings: readonly ReadFinding[];
323
335
  readonly nested: readonly JudgedPlan[];
336
+ /** What a literal printer says the segment's shell is fed ({@link ShellReadSegment.printed}), judged on its spelling alone
337
+ * (no environment is asked about a text that may not run): the fold reads its deny hits and nothing else; no other reader
338
+ * of a judged plan reads it. */
339
+ readonly printed: readonly JudgedPlan[];
324
340
  }
325
341
  export interface JudgedPlan {
326
342
  readonly plan: ShellReadPlan;
@@ -384,11 +400,12 @@ export interface ShellReadFold {
384
400
  * only RAISE that: the nested text's deny-relation answers count — a deny hit (a refusal is a refusal whatever
385
401
  * runs it) and a root that may hold a row no home places — its containment and its other silence do not (an inner
386
402
  * `cat inside.txt` vouches nothing about the outer text). A substitution body (`$(…)`, a backtick, `<(…)`) is nested
387
- * WITHOUT re-entry and folds in full.
403
+ * WITHOUT re-entry and folds in full. What a literal printer says the shell is fed ({@link JudgedSegment.printed}) is a
404
+ * text that may not run at all: its deny HITS count, and nothing else it finds or fails to find does.
388
405
  */
389
406
  export declare function foldShellReadFindings(judged: JudgedPlan): ShellReadFold;
390
407
  /** Judge every established read of a plan, in place. `establish` runs per segment so a caller can bound it. */
391
- export declare function judgeEstablishedPlan(plan: ShellReadPlan, established: ReadonlyMap<ShellReadSegment, readonly EstablishedRead[]>, boundary: ShellReadBoundary, nestedOf: (plan: ShellReadPlan) => JudgedPlan): JudgedPlan;
408
+ export declare function judgeEstablishedPlan(plan: ShellReadPlan, established: ReadonlyMap<ShellReadSegment, readonly EstablishedRead[]>, boundary: ShellReadBoundary, nestedOf: (plan: ShellReadPlan) => JudgedPlan, printedOf: (plan: ShellReadPlan) => JudgedPlan): JudgedPlan;
392
409
  /** Every finding of a judged plan, flattened (segments and nested plans alike). */
393
410
  export declare function allFindings(judged: JudgedPlan): ReadFinding[];
394
411
  /** One lexical step up, family-aware. A family ROOT is its own parent — the fixpoint the climb below ends
@@ -146,12 +146,13 @@ export function foldShellReadFindings(judged) {
146
146
  if (rank > 0 || (rank === 0 && next.witness?.read.candidate.face === "write" && best.witness?.read.candidate.face !== "write"))
147
147
  best = next;
148
148
  };
149
- const walk = (j, denyOnly) => {
149
+ const walk = (j, reading) => {
150
+ const denyOnly = reading !== "full";
150
151
  if (j.plan.unreadable !== undefined && !denyOnly)
151
152
  raise({ finding: "unestablishable" });
152
153
  for (const s of j.segments) {
153
154
  for (const f of s.findings) {
154
- if (denyOnly && f.kind !== "deny_hit" && f.kind !== "unanswered")
155
+ if (denyOnly && f.kind !== "deny_hit" && (reading === "deny-hit" || f.kind !== "unanswered"))
155
156
  continue;
156
157
  if (f.kind !== "none")
157
158
  raise({ finding: f.kind, witness: f });
@@ -169,12 +170,13 @@ export function foldShellReadFindings(judged) {
169
170
  if (move !== undefined && (typeof move.target === "string" || move.target.expands !== false))
170
171
  raise({ finding: "unestablishable", declined: s.segment });
171
172
  }
172
- const nestedDenyOnly = denyOnly || s.segment.reentry === "shell";
173
173
  for (const n of s.nested)
174
- walk(n, nestedDenyOnly);
174
+ walk(n, reading === "full" && s.segment.reentry !== "shell" ? "full" : reading === "deny-hit" ? "deny-hit" : "deny-relation");
175
+ for (const n of s.printed)
176
+ walk(n, "deny-hit");
175
177
  }
176
178
  };
177
- walk(judged, false);
179
+ walk(judged, "full");
178
180
  const unfinished = judged.incomplete?.[0];
179
181
  if (unfinished !== undefined && (judged.guards || judged.writeGuards) && SHELL_READ_FINDING_RANK.unanswered > SHELL_READ_FINDING_RANK[best.finding]) {
180
182
  unestablished = true;
@@ -182,13 +184,14 @@ export function foldShellReadFindings(judged) {
182
184
  }
183
185
  return { ...best, ...(unestablished ? { unestablished: true } : {}), ...(unplacedRead ? { unplacedRead: true } : {}), ...(unestablished && reentered.length > 0 ? { reentered } : {}) };
184
186
  }
185
- export function judgeEstablishedPlan(plan, established, boundary, nestedOf) {
187
+ export function judgeEstablishedPlan(plan, established, boundary, nestedOf, printedOf) {
186
188
  return {
187
189
  plan,
188
190
  segments: plan.segments.map((segment) => ({
189
191
  segment,
190
192
  findings: (established.get(segment) ?? []).map((r) => judgeRead(r, boundary)),
191
193
  nested: segment.nested.map(nestedOf),
194
+ printed: (segment.printed ?? []).map(printedOf),
192
195
  })),
193
196
  guards: stationGuards(boundary),
194
197
  writeGuards: writeFaceGuards(boundary),
@@ -273,6 +276,7 @@ export function rejudge(judged, boundary) {
273
276
  segment: s.segment,
274
277
  findings: s.findings.map((f) => judgeRead(f.read, boundary)),
275
278
  nested: s.nested.map((n) => rejudge(n, boundary)),
279
+ printed: s.printed.map((n) => rejudge(n, boundary)),
276
280
  })),
277
281
  guards: stationGuards(boundary),
278
282
  writeGuards: writeFaceGuards(boundary),
@@ -22,7 +22,8 @@
22
22
  * · an INTERPRETER's inline program is a shape fact (`reentry:"interpreter"`), never parsed, never a finding;
23
23
  * · `<` targets are read candidates, `>`-family targets are write targets (tagged, not read), here-documents
24
24
  * and here-strings are data (an UNQUOTED here-document body's substitutions are nested plans) — except to a shell
25
- * whose argv names no script: what arrives on its standard input is its script, a nested plan where the text spells it;
25
+ * whose argv names no script: what arrives on its standard input is its script, a nested plan where the text spells it,
26
+ * a `printed` plan where a literal printer producing it does (`printed`: never what runs — only its deny hits count);
26
27
  * · `$(…)`, backticks and `<(…)` bodies are nested plans; a word carrying one cannot be resolved from the text;
27
28
  * · the working-directory thread (`shell-read-workdir.ts`) moves the base the LATER segments resolve against, as a
28
29
  * candidate SET (`&&` proves a move, nothing else does), and gives `PWD` / `OLDPWD` their values; a loop body with
@@ -136,6 +137,10 @@ export interface ShellReadSegment {
136
137
  readonly bases: readonly string[] | "unmodelled";
137
138
  /** Substitution bodies, unquoted here-document substitutions, and re-entered shell text, each its own plan. */
138
139
  readonly nested: readonly ShellReadPlan[];
140
+ /** Texts a literal printer's words say this segment's shell is fed (a pipe's producer, the body of a `<(…)` script file or
141
+ * of a `< <(…)` input), each its own plan — never a text known to run, so no reader of what runs (`nested`) reads them: the
142
+ * read station judges them on their spelling, and only a deny hit among them counts (it refuses the call). */
143
+ readonly printed?: readonly ShellReadPlan[];
139
144
  readonly reach: SegmentReach;
140
145
  /** The names a change that can reach this segment touched (`BindingTable.rebound`): any other name still holds what the
141
146
  * shell provides here. `all`: any name may have changed. */
@@ -8,7 +8,7 @@ import { POLL_LOOP_MAX_BEATS, attachedOptionPayloads, resolveOperandLexically, i
8
8
  import { BLOCK_WORD_NAMES, commandLineOf, commandLineOptionSpellings, declaredAttributes, isDeclarationBuiltin, isInertBuiltin, launcherOptionPathRole, launcherOptionStep, readOptionRole, programLanguageOf, programTextOpensOf, selectedOptions, movesBaseByStack, opensNoOperand, programDelivery, programRow, readArgRoles, runsShellText, } from "./program-read-model.js";
9
9
  import { shellWordsOf } from "../../shell/shell-words.js";
10
10
  import { isAbsoluteForFamily } from "./safety.js";
11
- import { codeBodies, launchedInput, reentersShell, reentryText, scriptFileAt, stdinTextsOf } from "./shell-reentry-text.js";
11
+ import { codeBodies, launchedInput, pipedTextOf, printedByProcess, reentersShell, reentryText, scriptFileAt, stdinTextsOf } from "./shell-reentry-text.js";
12
12
  import { heldAt, plannedOnce, rebasePlan, startedAt, stdinFeeds } from "./shell-read-start.js";
13
13
  import { markStandardDevices } from "./shell-read-device.js";
14
14
  export const READ_CANDIDATE_PROVENANCES = Object.freeze([
@@ -68,7 +68,7 @@ function planText(command, decl, depth, start, from) {
68
68
  const empty = lexed.segments.map((segment, si) => segmentIsEmpty(segment, projected[si]));
69
69
  const facts = projected.map(() => undefined);
70
70
  const tables = projected.map(() => undefined);
71
- const fedAt = stdinFeeds(lexed.segments, start?.stdin ?? [], (si) => [{ from: `${lexed.segments[si - 1].text.trim()} |` }]);
71
+ const fedAt = stdinFeeds(lexed.segments, start?.stdin ?? [], (si) => [pipedTextOf(lexed.segments[si - 1])]);
72
72
  const inheritedFns = new Set([...(start?.exportedFunctions ?? [])].flatMap(([name, body]) => (body === "unread" ? [name] : [])));
73
73
  const factsAt = (si, table) => {
74
74
  tables[si] ??= table;
@@ -202,6 +202,7 @@ function planText(command, decl, depth, start, from) {
202
202
  const moved = readProgramPosition(f.argv).launcherMovesBase;
203
203
  const programPlaced = moved ? placedAt("unmodelled", bases !== "unmodelled" ? bases : floor) : withBases;
204
204
  const programRead = (c) => (c.provenance === "stdin_redirect" ? withBases(c) : programPlaced(c));
205
+ const placeNested = (n) => (f.elsewhere?.has(n) === true ? n : rebasePlan(n, decl.cwd, moved && f.shellSide?.has(n) !== true ? "unmodelled" : bases, bases === "unmodelled" ? floor : bases));
205
206
  segments.push({
206
207
  text: f.text,
207
208
  connector: f.connector,
@@ -216,7 +217,8 @@ function planText(command, decl, depth, start, from) {
216
217
  redirects: f.redirects.map((r) => ({ op: r.op, direction: r.direction, ...(r.fd !== undefined ? { fd: r.fd } : {}), ...(r.target !== undefined ? { target: withBases(r.target) } : {}) })),
217
218
  ...(move !== undefined ? { baseMove: { target: typeof move.target === "string" ? move.target : withBases(move.target) } } : {}),
218
219
  bases,
219
- nested: f.nested.map((n) => (f.elsewhere?.has(n) === true ? n : rebasePlan(n, decl.cwd, moved && f.shellSide?.has(n) !== true ? "unmodelled" : bases, bases === "unmodelled" ? floor : bases))),
220
+ nested: f.nested.map(placeNested),
221
+ ...(f.printed.length > 0 ? { printed: f.printed.map(placeNested) } : {}),
220
222
  reach: reaches[si] ?? { andJoined: false, orBroken: false, moveProvable: false },
221
223
  rebound: tables[si]?.rebound ?? "all",
222
224
  });
@@ -310,6 +312,7 @@ function readingFacts(segment, p, decl, reading, nestedPlan, fed, inheritedFns =
310
312
  }
311
313
  function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheritedFns = new Set()) {
312
314
  const nested = [];
315
+ const printed = [];
313
316
  const elsewhere = new Set();
314
317
  const ctx = { table, reentered: [], programTextSeen: false };
315
318
  const enclosedToo = (e) => [e, ...(e.inner ?? []).flatMap(enclosedToo)];
@@ -356,6 +359,7 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
356
359
  argv: p.argv,
357
360
  redirects,
358
361
  nested,
362
+ printed,
359
363
  };
360
364
  const done = (f) => {
361
365
  const reentered = [...new Set(ctx.reentered)];
@@ -488,8 +492,10 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
488
492
  const reenterShell = (verb, argvs) => {
489
493
  const stdin = stdinTextsOf(segment, fed);
490
494
  const scripts = new Map();
491
- const script = (text, at) => { if (text !== undefined)
492
- scripts.set(JSON.stringify([text, at]), { ...at, text }); };
495
+ const prints = new Map();
496
+ const into = (to) => (text, at) => { if (text !== undefined)
497
+ to.set(JSON.stringify([text, at]), { ...at, text }); };
498
+ const script = into(scripts), print = into(prints);
493
499
  for (const { shell, texts: t, args: a, as } of argvs) {
494
500
  const user = as !== undefined ? { as } : {};
495
501
  const argvText = [reentryText(shell, t), reentryText(shell, a)];
@@ -497,20 +503,21 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
497
503
  script(text, { ...user, ...(stdin.length > 0 ? { stdin } : {}) });
498
504
  if (argvText.every((text) => text === undefined))
499
505
  for (const s of stdin)
500
- if (s.literal !== undefined)
501
- script(reentryText(shell, t, s.literal), user);
506
+ void (s.literal !== undefined && script(reentryText(shell, t, s.literal), user), s.printed !== undefined && print(reentryText(shell, t, s.printed), user));
502
507
  }
503
- for (const { text, ...at } of scripts.values()) {
504
- const plan = nestedPlan(text, "now", at);
505
- nested.push(plan);
506
- if (at.as?.login === true)
507
- elsewhere.add(plan);
508
- }
509
- for (const { shell, args: a, words } of argvs) {
508
+ for (const { shell, args: a, words, as } of argvs) {
510
509
  const at = shell === "source" || shell === "." ? a.findIndex((w) => !w.startsWith("-") || w === "-") : scriptFileAt(shell, a);
511
510
  const file = at === undefined ? undefined : words[at];
512
511
  if (file !== undefined)
513
- reads.push(bare(file, "operand"));
512
+ void (reads.push(bare(file, "operand")), print(printedByProcess(file.word), as !== undefined ? { as } : {}));
513
+ }
514
+ for (const [to, plans] of [[scripts, nested], [prints, printed]]) {
515
+ for (const { text, ...at } of to.values()) {
516
+ const plan = nestedPlan(text, "now", at);
517
+ plans.push(plan);
518
+ if (at.as?.login === true)
519
+ elsewhere.add(plan);
520
+ }
514
521
  }
515
522
  return done({ empty: false, launcherChain, verb, reentry: "shell", declines, reads, moveProvable: false, ...(loopHead !== undefined ? { loopHead } : {}), ...(stdin.length > 0 ? { stdin } : {}), ...(shift !== undefined ? { shift } : {}) });
516
523
  };
@@ -94,6 +94,7 @@ export function rebasePlan(plan, from, to, floor) {
94
94
  ...(s.baseMove !== undefined ? { baseMove: { target: typeof s.baseMove.target === "string" ? s.baseMove.target : moveCandidate(s.baseMove.target) } } : {}),
95
95
  bases: s.bases === "unmodelled" || to === "unmodelled" ? "unmodelled" : [...new Set(s.bases.flatMap(moveBase))],
96
96
  nested: s.nested.map((n) => rebasePlan(n, from, to, floor)),
97
+ ...(s.printed !== undefined ? { printed: s.printed.map((n) => rebasePlan(n, from, to, floor)) } : {}),
97
98
  })),
98
99
  };
99
100
  }
@@ -136,11 +136,25 @@ export declare function spellLaunched(argv: readonly LexedWord[], args: readonly
136
136
  export declare function scriptFileAt(basename: string, args: readonly string[]): number | undefined;
137
137
  /** One text that may arrive on a segment's standard input: `from` = its source as written (a here-document's body,
138
138
  * `<<<WORD`, `<FILE`, `<&N`, the segment the pipe comes from); `literal` = the text, where the command spells it — a
139
- * here-document or here-string written in the command; never a pipe's text, which a program PRODUCES. */
139
+ * here-document or here-string written in the command; never a pipe's text, which a program PRODUCES. `printed` = the
140
+ * text a literal printer producing it spells ({@link printedBy}: the pipe's producer, the body of a `< <(…)`) — what the
141
+ * printer's words say it prints, never what the shell is known to receive: read only for what it refuses. */
140
142
  export interface StdinText {
141
143
  readonly from: string;
142
144
  readonly literal?: string;
145
+ readonly printed?: string;
143
146
  }
147
+ /** The text a producer's words say it prints ({@link printedText}): one simple command — no redirection, here-document or
148
+ * group — whose program word and every argument are literal, run by a printer row. `undefined` for any other producer. The
149
+ * reading is no claim about the stream (a function, an alias or a trap of the printer's name, a second writer on it are not
150
+ * read): its one reader refuses by it and never clears by it (`ShellReadSegment.printed`). */
151
+ export declare function printedBy(segment: LexedSegment): string | undefined;
152
+ /** What a pipe hands the segment after it: the producing segment as written, and the text it spells where it is a literal
153
+ * printer ({@link printedBy}). */
154
+ export declare function pipedTextOf(producer: LexedSegment): StdinText;
155
+ /** The text a word that is one process substitution prints, where its body is one literal printer ({@link printedBy}):
156
+ * `<(printf 'X')` — a script file a shell is handed, or the file its standard input is redirected from. */
157
+ export declare function printedByProcess(word: LexedWord): string | undefined;
144
158
  /** What may arrive on a segment's standard input: each here-document (its descriptor is not read: every one counts) —
145
159
  * its body, literal when quoted or when nothing in it expands — each here-string (literal when its word is), `<` file
146
160
  * or `<&` descriptor written to no other descriptor, and what it inherits (`fed`: the pipe it is reached through, the
@@ -1,6 +1,6 @@
1
- import { literalHeredocBody, literalTextOf } from "../../shell/lex.js";
1
+ import { lexShell, literalHeredocBody, literalTextOf } from "../../shell/lex.js";
2
2
  import { programBasename, readProgramPosition } from "./bash-program-position.js";
3
- import { implementationRejects, implementationsOf, programRow, readArgRoles, selectedOptions, selectedSpellings, targetUserOf } from "./program-read-model.js";
3
+ import { implementationRejects, implementationsOf, printedText, programRow, readArgRoles, selectedOptions, selectedSpellings, targetUserOf } from "./program-read-model.js";
4
4
  import { namesStandardInput } from "./safety.js";
5
5
  export function codeBodies(basename, args) {
6
6
  const row = programRow(basename);
@@ -240,6 +240,27 @@ function scriptSourceOf(row, args) {
240
240
  return { stdin: true };
241
241
  return { file: first.at, stdin: options.some((e) => e.kind === "option" && e.reading === "speculative") };
242
242
  }
243
+ export function printedBy(segment) {
244
+ if (segment.tokens.some((t) => t.kind !== "word"))
245
+ return undefined;
246
+ const argv = segment.tokens.filter((t) => t.kind === "word");
247
+ const pos = readProgramPosition(argv);
248
+ const program = pos.program;
249
+ if (program === undefined || pos.refusal !== undefined || pos.launchers.length > 0 || literalTextOf(argv[program.index].pieces) === undefined)
250
+ return undefined;
251
+ return printedText(programRow(program.basename), argv.slice(program.index + 1).map((w) => literalTextOf(w.pieces)));
252
+ }
253
+ export function pipedTextOf(producer) {
254
+ const printed = printedBy(producer);
255
+ return { from: `${producer.text.trim()} |`, ...(printed !== undefined ? { printed } : {}) };
256
+ }
257
+ export function printedByProcess(word) {
258
+ const e = word.pieces.length === 1 ? word.pieces[0].expansion : undefined;
259
+ if (e?.kind !== "process" || e.body === undefined || !word.raw.startsWith("<("))
260
+ return undefined;
261
+ const lexed = lexShell(e.body);
262
+ return "parseFailure" in lexed || lexed.segments.length !== 1 ? undefined : printedBy(lexed.segments[0]);
263
+ }
243
264
  export function stdinTextsOf(segment, fed) {
244
265
  const out = [];
245
266
  let replacesPipe = false;
@@ -250,7 +271,8 @@ export function stdinTextsOf(segment, fed) {
250
271
  }
251
272
  else if (t.kind === "redirect" && (t.fd ?? 0) === 0 && (t.op === "<<<" || t.op === "<" || t.op === "<>" || (t.op === "<&" && t.dup !== "-"))) {
252
273
  const literal = t.op === "<<<" && t.target !== undefined ? literalTextOf(t.target.pieces) : undefined;
253
- out.push({ from: `${t.op}${t.target?.raw ?? t.dup ?? ""}`, ...(literal !== undefined ? { literal } : {}) });
274
+ const printed = t.op === "<" && t.target !== undefined ? printedByProcess(t.target) : undefined;
275
+ out.push({ from: `${t.op}${t.target?.raw ?? t.dup ?? ""}`, ...(literal !== undefined ? { literal } : {}), ...(printed !== undefined ? { printed } : {}) });
254
276
  replacesPipe = true;
255
277
  }
256
278
  }
@@ -43,6 +43,7 @@ import { type MonitorTimers, type TaskRegistry } from "../core/task-registry.js"
43
43
  import type { TaskNotificationPayload } from "../core/task-notification.js";
44
44
  import type { ToolResultStore } from "../core/tool-result-store.js";
45
45
  import type { ShellReadAdmission } from "./fs/shell-read-check.js";
46
+ import type { ReadFloorSeat } from "./fs/read-floor.js";
46
47
  export interface MonitorToolOptions {
47
48
  registry: TaskRegistry;
48
49
  /** Fallbacks when the runtime ctx carries no identity (direct mounts) — same posture as createBashTool. */
@@ -73,6 +74,9 @@ export interface MonitorToolOptions {
73
74
  * spawns a shell command too, so what it runs is what the station judged, re-established before the watch
74
75
  * spawns. Absent ⇒ no station judged this mount; nothing is re-established. */
75
76
  shellReadAdmission?: ShellReadAdmission;
77
+ /** The byte floor's seat (read-floor.ts) — the SAME table the shell faces carry: the watched command's start hands it to
78
+ * the environment. Absent ⇒ the start carries no floor. */
79
+ readFloor?: ReadFloorSeat;
76
80
  /** RB-465-b (HRD-PTL-3 残件): spec-level retain (`TaskSpec.retainBackgroundProcesses`) — the task lane of
77
81
  * THE retain predicate (`retainsBackgroundProcesses`), OR-composed with the env capability. Read twice,
78
82
  * by the same predicate: the persistent-watch receipt's wording, and the row's `retained` mark at
@@ -79,9 +79,11 @@ export function createMonitorTool(env, opts) {
79
79
  }
80
80
  if (ctx.signal?.aborted === true)
81
81
  return errorResult("Error (Monitor): the call was cancelled before the watch started.");
82
+ const readFloor = opts.readFloor?.(ctx.toolCallId);
82
83
  const spawn = await env.spawnBackground(command, {
83
84
  ...(opts.cwdRef !== undefined ? { cwd: opts.cwdRef.current } : {}),
84
85
  ...(spawnTimeoutSec !== undefined ? { timeout: spawnTimeoutSec } : {}),
86
+ ...(readFloor !== undefined ? { readFloor } : {}),
85
87
  });
86
88
  if (!spawn.ok)
87
89
  return errorResult(`Error (Monitor): ${spawn.error.message}`);
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * 审计深挖 G4 — the `EnterWorktree` / `ExitWorktree` tool pair: SESSION-level git-worktree
3
- * isolation. EnterWorktree creates a managed worktree under `.sema-worktrees/`
4
- * (the same {@link WORKTREE_PARENT} the subagent `isolation:"worktree"` lane uses) and REALLY switches
5
- * the task's working directory into it; ExitWorktree returns to the original directory and cleans up.
3
+ * isolation. EnterWorktree creates a managed worktree under `.sema/worktrees/`
4
+ * (the same {@link WORKTREE_PARENT} the subagent `isolation:"worktree"` lane uses, through the one mint `addWorktree`) and
5
+ * REALLY switches the task's working directory and write access into it; ExitWorktree returns to the original directory and
6
+ * cleans up.
6
7
  *
7
8
  * Semantics:
8
9
  * ① worktrees live in a managed parent dir inside the repo (CC: `.claude/worktrees/`; sema:
9
- * `.sema-worktrees/`) — never scattered;
10
+ * `.sema/worktrees/<name>`, on the new branch `sema/<name>`) — never scattered;
10
11
  * ② baseRef is two-state: `"head"` = the current local HEAD (unpushed commits present), `"fresh"` =
11
12
  * the default branch tip (CC: `origin/<default-branch>` for a clean tree);
12
13
  * ③ a second CREATING EnterWorktree (`name`) while one is active is REFUSED ("Already in a worktree
@@ -23,18 +24,16 @@
23
24
  * hands band shares one {@link CwdRef} (`handsCwdRef` in prepare-task): Bash runs every command in
24
25
  * `cwdRef.current` (and `cd` moves it), Read/Edit/Write resolve relative paths against it, Monitor
25
26
  * spawns there. EnterWorktree therefore performs a REAL switch by assigning `cwdRef.current`; the
26
- * Runner's per-tool cwd read reports it as `workspace_changed`, same as an observed `cd`. Path
27
- * containment is untouched: the worktree lives UNDER the task root, so resolveKey's canonical-within
28
- * check still holds for every subsequent fs op.
27
+ * Runner's per-tool cwd read reports it as `workspace_changed`, same as an observed `cd`.
29
28
  *
30
- * ⚠️ Containment ruling (deliberate): entering a worktree is a **cwd switch, NOT a
31
- * sandbox**. resolveKey's containment anchor stays the ORIGINAL task root — it is deliberately NOT
32
- * re-anchored/tightened to the worktree dir, so `../../` from inside the worktree can still reach the
33
- * rest of the repository (which is WITHIN the task root and was reachable before Enter too), while
34
- * anything outside the task root stays fenced exactly as before. This matches the reference's semantics
35
- * (CC worktrees live beside the repo with no containment tightening either); tightening here would buy
36
- * no security (Bash/`cd` already roam the root) and would break legitimate repo-relative access. The
37
- * tool description + Enter reply state this honestly so the model never assumes isolation.
29
+ * WRITE ROOT = WRITE LOCATION (the reference implementation's permission-root relocation: entering a worktree "moves the
30
+ * session's working directory and write access there", and after a further switch the previously visited tree is no longer
31
+ * writable). The leg's write root is read live through {@link currentCheckoutOf} — the active worktree while one is tracked,
32
+ * the task root otherwise — by every write-root reader (the structured write tools, the shell's write targets, the
33
+ * accept-edits mode gate), so the base checkout and every other managed worktree are outside the write roots while a tree is
34
+ * active and judged by the existing out-of-root semantics. The READ roots do not move (the worktree lives under the task
35
+ * root). It is still not a sandbox: an arbitrary program run in the shell writes wherever the process can; the tool
36
+ * description and the replies say both halves.
38
37
  *
39
38
  * Security posture: both tools only ever run `git` against the task root / managed worktree (no
40
39
  * arbitrary command surface), but they create/delete on-disk state ⇒ effect:"write" (plan mode gates
@@ -47,6 +46,7 @@
47
46
  * Enter→suspend→resume→Exit behaves exactly like an unsuspended session.
48
47
  */
49
48
  import type { ActiveWorktreeSession, AgentTool, ExecutionEnv } from "../internal/harness-types.js";
49
+ import type { ManagedCheckoutView } from "../core/write-protect.js";
50
50
  import type { CwdRef } from "./fs/index.js";
51
51
  /** the ACTIVE worktree session, ALL-SERIALIZABLE (plain strings, no closures):
52
52
  * prepare-task owns the ref, stamps `current` into `CheckpointState.activeWorktree` at a durable
@@ -73,6 +73,33 @@ export interface WorktreeSessionRef {
73
73
  * for the CAS-reject-vs-serialize trade-off). */
74
74
  entering?: boolean;
75
75
  }
76
+ /**
77
+ * THE write location of a leg — its one reader: the active worktree while one is tracked, the task root otherwise. Every
78
+ * write-root reader reads this (the structured write tools, the shell's write targets, the accept-edits mode gate), so
79
+ * "where may this leg write" has one answer that moves with EnterWorktree / ExitWorktree.
80
+ *
81
+ * The answer is a CANONICAL directory (the write roots compare canonical keys). A tree this engine minted is spelled under
82
+ * the task root's own spelling (`<root>/.sema/worktrees/<slug>`), and its three managed levels are refused at mint when any
83
+ * is a symlink — so its canonical form IS the task root's canonical form plus the same tail; a tree entered by `path` is
84
+ * already spelled as git reports it (the physical path). A recorded spelling under neither stands as recorded: a write root
85
+ * that matches no key refuses, never admits.
86
+ */
87
+ export declare function currentCheckoutOf(session: WorktreeSessionRef | undefined, taskRoot: {
88
+ readonly spelled: string;
89
+ readonly canonical: string;
90
+ }): string;
91
+ /** A leg's write-location seat (the EnterWorktree session; empty until the worktree mount seeds it) and its readers, minted
92
+ * before any write-root reader: `writeLocation` ({@link currentCheckoutOf} over the seat) and `checkout` — the write location
93
+ * when it is a managed tree (a switch, or a task root that IS one): its canonical identity and the spelling the leg's paths
94
+ * carry it under, for the write-protection judge's current-tree reading (`WriteProtectionCompileOptions.checkoutOf`). */
95
+ export declare function writeLocationOf(taskRoot: {
96
+ readonly spelled: string;
97
+ readonly canonical: string;
98
+ }): {
99
+ readonly seat: WorktreeSessionRef;
100
+ readonly writeLocation: () => string;
101
+ readonly checkout: () => ReadonlyArray<ManagedCheckoutView> | undefined;
102
+ };
76
103
  export interface WorktreeToolsOptions {
77
104
  /** The task root (the repo root the managed worktrees nest under; `git` runs `-C` here). */
78
105
  repoRoot: string;