@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
@@ -6,6 +6,7 @@ import { resolveCheckpointStore } from "./checkpoint-store.js";
6
6
  import { isLiveQuestionFace } from "./ask-question.js";
7
7
  import { AUTO_MODE_DENY_SOURCES, isAutoModeDenySource } from "./runtime-caps.js";
8
8
  import { describeRejectedValue } from "./tool-search-setting.js";
9
+ import { RUN_ORIGINS } from "./run-origin.js";
9
10
  export const APPROVAL_REACH = Object.freeze(["none"]);
10
11
  const APPROVAL_REACH_SET = new Set(APPROVAL_REACH);
11
12
  export function isApprovalReach(v) {
@@ -161,8 +162,8 @@ function readSessionRulesFact(fact) {
161
162
  return { childrenReadLive: fact };
162
163
  }
163
164
  export function deriveWiringManifest(facts) {
164
- if (facts.half === "static" && facts.leg !== undefined) {
165
- throw new Error("a static wiring manifest has no leg — leg identity is an effective-half fact");
165
+ if (facts.half === "static" && (facts.leg !== undefined || facts.runOrigin !== undefined)) {
166
+ throw new Error("a static wiring manifest has no leg — leg identity (its kind and its run origin) is an effective-half fact");
166
167
  }
167
168
  if (facts.half === "effective" && facts.leg === undefined) {
168
169
  throw new Error("an effective wiring manifest requires its leg kind");
@@ -179,7 +180,7 @@ export function deriveWiringManifest(facts) {
179
180
  : "absent";
180
181
  const manifest = {
181
182
  schemaVersion: 1,
182
- ...(facts.leg !== undefined ? { leg: { kind: facts.leg } } : {}),
183
+ ...(facts.leg !== undefined ? { leg: { kind: facts.leg, ...(facts.runOrigin !== undefined ? { runOrigin: readWordFact(facts.runOrigin, RUN_ORIGINS, "run origin") } : {}) } } : {}),
183
184
  ask: {
184
185
  form: facts.askForm,
185
186
  ...(facts.askProvenance !== undefined ? { provenance: facts.askProvenance } : {}),
@@ -0,0 +1,44 @@
1
+ /**
2
+ * WHERE A LEG STANDS, as one value: the ONE projection of it ({@link workspaceSnapshotOf}) and the ONE seat
3
+ * that announces it on the `workspace_changed` frame ({@link createWorkspaceFrameSeat}).
4
+ *
5
+ * The seat sends the leg-start snapshot when the leg binds its sink, and afterwards a frame only when the snapshot's digest
6
+ * differs from the last frame it sent — the digest is the snapshot's canonical JSON, so every member the projection carries
7
+ * takes part in the comparison with no second list to keep in step. The fixed members (root, project, remote) are leg
8
+ * facts handed in at prepare; the two live ones are read off the leg's own seats at each observation (the tracked cwd, the
9
+ * active EnterWorktree switch), never copied.
10
+ */
11
+ import type { ActiveWorktreeSession } from "../internal/harness-types.js";
12
+ import type { SessionProject } from "./memory-engine/scope-contract.js";
13
+ import type { TaskEvent, TaskEventIdentity } from "./task-event.js";
14
+ /** The frame's value — derived from the `workspace_changed` arm of the event union (one source; never a hand-copied shape). */
15
+ export type WorkspaceSnapshot = Omit<Extract<TaskEvent, {
16
+ type: "workspace_changed";
17
+ }>, "type" | keyof TaskEventIdentity>;
18
+ /** What a leg's snapshot is projected from. */
19
+ export interface WorkspaceFacts {
20
+ /** The leg's task root as its root receiving point settled it (`resolveTaskRootCanonical`). */
21
+ readonly root: string;
22
+ /** The leg's tracked logical cwd — present only where a real shell is mounted; absent ⇒ the cwd is `root`. */
23
+ readonly cwdRef?: {
24
+ readonly current: string;
25
+ };
26
+ /** The leg's EnterWorktree seat — present only where the worktree tools are mounted. */
27
+ readonly worktreeSessionRef?: {
28
+ readonly current?: ActiveWorktreeSession;
29
+ };
30
+ /** The leg's project verdict (`resolveSessionProject`); absent ⇒ the leg has no project identity. */
31
+ readonly project?: SessionProject;
32
+ /** The leg's one remoteness reading (the restore phase's, the same value `ResolvedWorkspace.remote` carries). */
33
+ readonly remote: boolean;
34
+ }
35
+ /** The ONE mint of the `workspace_changed` value. */
36
+ export declare function workspaceSnapshotOf(facts: WorkspaceFacts): WorkspaceSnapshot;
37
+ /** The leg's frame seat (held on `Prepared`): the run binds its sink once, and observes after every tool that may have moved the leg. */
38
+ export interface WorkspaceFrameSeat {
39
+ /** Bind this leg's frame sink and send the leg-start snapshot through it. The first binding wins; a later one is ignored. */
40
+ subscribe(push: (snapshot: WorkspaceSnapshot) => void): void;
41
+ /** Re-project, and send iff the snapshot differs from the last one sent. Nothing is sent before the sink is bound. */
42
+ observe(): void;
43
+ }
44
+ export declare function createWorkspaceFrameSeat(facts: WorkspaceFacts): WorkspaceFrameSeat;
@@ -0,0 +1,34 @@
1
+ import { canonicalJsonStringify } from "./canonical-json.js";
2
+ export function workspaceSnapshotOf(facts) {
3
+ const active = facts.worktreeSessionRef?.current;
4
+ return {
5
+ cwd: facts.cwdRef?.current ?? facts.root,
6
+ root: facts.root,
7
+ ...(active !== undefined ? { entered: { dir: active.worktreeDir, ...(active.entered === true ? { byPath: true } : {}) } } : {}),
8
+ ...(facts.project !== undefined ? { project: { id: facts.project.id, source: facts.project.source } } : {}),
9
+ remote: facts.remote,
10
+ };
11
+ }
12
+ export function createWorkspaceFrameSeat(facts) {
13
+ let push;
14
+ let lastSent;
15
+ const send = () => {
16
+ if (push === undefined)
17
+ return;
18
+ const snapshot = workspaceSnapshotOf(facts);
19
+ const digest = canonicalJsonStringify(snapshot);
20
+ if (digest === lastSent)
21
+ return;
22
+ lastSent = digest;
23
+ push(snapshot);
24
+ };
25
+ return {
26
+ subscribe(sink) {
27
+ if (push !== undefined)
28
+ return;
29
+ push = sink;
30
+ send();
31
+ },
32
+ observe: send,
33
+ };
34
+ }
@@ -1,6 +1,7 @@
1
1
  import type { ExecutionEnv } from "../internal/harness-types.js";
2
2
  import type { ObservedFilesystem } from "../tools/fs/shell-read-environment.js";
3
3
  import type { PermissionResult } from "./tool-policy.js";
4
+ import { type GuardHitVia } from "./path-guard-rows.js";
4
5
  import { type ToolCallLike } from "./tool-registry.js";
5
6
  /**
6
7
  * How one table row matches the judged path:
@@ -106,7 +107,7 @@ export type WriteProtectionVerdict = {
106
107
  } | {
107
108
  readonly kind: "hit";
108
109
  readonly hit: WriteProtectedHit;
109
- readonly via: "spelling" | "chain" | "target";
110
+ readonly via: GuardHitVia;
110
111
  } | {
111
112
  readonly kind: "unresolvable";
112
113
  readonly cause: string;
@@ -206,6 +207,27 @@ export interface WriteProtectionCompileOptions {
206
207
  * cannot answer path questions), and its consumer announces once per leg rather than once per write.
207
208
  */
208
209
  readonly onViewAbsent?: (absence: WriteProtectionViewAbsence) => void;
210
+ /**
211
+ * The leg's CURRENT write location when it is a managed worktree — read once per judgment; `undefined` while the leg writes
212
+ * a directory that is not one. Each entry is one spelling of that tree: its `root` (`<base>/.sema/worktrees/<slug>`) and the
213
+ * `base` checkout it was minted under; `kind: "canonical"` is the tree's canonical identity, `kind: "spelled"` the spelling
214
+ * the leg's cwd and spellings carry it under (the task root as given, which may reach it through an alias).
215
+ *
216
+ * THE CURRENT-TREE READING (the reference implementation's `.claude/worktrees` exemption, narrowed to the one tree this leg
217
+ * writes): every view of a target that lies inside the tree is judged as the SAME relative path in `base` — only the managed
218
+ * prefix is removed, so the base checkout's own ancestry is judged as ever, a tree's own `.sema/settings.json` or `.git` is
219
+ * judged as the base checkout's, and an ordinary file of the tree meets no `.sema` row. A view outside the tree (a sibling
220
+ * tree, any other path) is judged as it stands. Narrow by construction, because this reading exempts: containment is
221
+ * byte-exact (no case fold), the canonical view is compared with the canonical identity alone, and a remainder that carries a
222
+ * `.` or `..` segment is judged as it stands (where it lands is not decided here).
223
+ */
224
+ readonly checkoutOf?: () => ReadonlyArray<ManagedCheckoutView> | undefined;
225
+ }
226
+ /** One spelling of the leg's current managed tree ({@link WriteProtectionCompileOptions.checkoutOf}). */
227
+ export interface ManagedCheckoutView {
228
+ readonly root: string;
229
+ readonly base: string;
230
+ readonly kind: "canonical" | "spelled";
209
231
  }
210
232
  /**
211
233
  * Compile the write-protection judge for a deployment configuration. Returns `undefined` when the
@@ -223,6 +245,12 @@ export declare function compileWriteProtection(entries?: readonly WriteProtected
223
245
  * ask carries that table's class) or a deployment's guarded write row (`ToolPolicy.writeGuardRows`: the target is not
224
246
  * placed). */
225
247
  export type WriteTargetCoverage = "protected" | "guarded";
248
+ /** One file of the engine's own the table does not demote: its declared spelling and the canonical key the run admitted it
249
+ * under (the session plan file, `TaskSpec.planFile`, as the advertised-writable seat holds it). ENGINE-INTERNAL. */
250
+ export interface ExemptFile {
251
+ readonly spelled: string;
252
+ readonly key: string;
253
+ }
226
254
  /** The leg's write judgment, compiled once ({@link compileLegWriteJudgment}). ENGINE-INTERNAL (not re-exported from
227
255
  * `src/index.ts`). */
228
256
  export interface LegWriteJudgment {
@@ -236,6 +264,7 @@ export interface LegWriteJudgment {
236
264
  readonly fs: ObservedFilesystem;
237
265
  readonly signal?: AbortSignal;
238
266
  readonly canonical?: true;
267
+ readonly spellingOnly?: true;
239
268
  }) => Promise<WriteTargetCoverage | undefined>) | undefined;
240
269
  }
241
270
  /**
@@ -246,6 +275,7 @@ export interface LegWriteJudgment {
246
275
  */
247
276
  export declare function compileLegWriteJudgment(entries: readonly WriteProtectedEntry[], opts: Omit<WriteProtectionCompileOptions, "dataRoot"> & {
248
277
  readonly exemptRoots: readonly string[];
278
+ readonly exemptFiles?: readonly ExemptFile[];
249
279
  readonly guardRows?: import("./tool-policy.js").ToolPolicy["writeGuardRows"];
250
280
  }): LegWriteJudgment;
251
281
  /**
@@ -254,8 +284,11 @@ export declare function compileLegWriteJudgment(entries: readonly WriteProtected
254
284
  * · `hit` ⇒ `ask` (`safety`; no `requiresRealApproval` — one explicit look, clearable by an approver, a
255
285
  * blanket `onAsk:"allow"`, the classifier or a matching persisted rule). The matched row NAME goes on the
256
286
  * message (table names are deployment-validated vocabulary); the model-authored target path deliberately
257
- * does not — `message` is the classifier's `askMessage`, and the approval card already shows the args. The
258
- * spelling form's sentence is the historical one byte for byte; the target form says the target RESOLVED.
287
+ * does not — `message` is the classifier's `askMessage`, and the approval card already shows the args. ONE
288
+ * sentence for every view: the row first, then — when the reading that met it is not the spelling — the one reach
289
+ * clause every guard's sentence uses ({@link guardHitReachClause}); a hit through the real target and a hit through a
290
+ * hop of the link chain are one fact to the classifier and the approver, so they read one sentence. The spelling
291
+ * view's sentence is the historical one byte for byte.
259
292
  * · `unresolvable` ⇒ `deny` (`safety`; reason word `target_unresolved` on the sentence): where the write lands could not be
260
293
  * determined, so this table cannot say it is not a protected path — refused in every permission mode (a refusal, not a
261
294
  * question a mode releases), the reference's write check form ("where it leads on disk could not be determined").
@@ -270,6 +303,13 @@ export declare function writeProtectionTightenDecision(toolName: string, verdict
270
303
  * it took no part.
271
304
  */
272
305
  export declare function writeProtectionMandated(verdict: WriteProtectionVerdict): boolean;
306
+ /**
307
+ * WHICH of the two table classes a verdict's hit is — the one reading of `via` as the class fact, beside the mandate predicate:
308
+ * `spelling` ⇒ the path as written names the row (`write_protection`); `target` / `chain` ⇒ the row is met only where the path
309
+ * resolves on disk (`write_protection_on_disk`) — the judge reads the spelling first and answers there on a hit, so a resolved
310
+ * reading is the answer only for a spelling that names no row. `undefined` for a verdict that is not a hit.
311
+ */
312
+ export declare function writeProtectionReachOf(verdict: WriteProtectionVerdict): "spelling" | "on_disk" | undefined;
273
313
  /**
274
314
  * The ENGINE-FILLED gate input (`ToolGateInput.writeProtectionCheck`). Returns `null` SYNCHRONOUSLY when the
275
315
  * call is not this layer's business — not a covered write, or no resolvable target string — and otherwise
@@ -1,5 +1,5 @@
1
- import { anchorSpelling, canonicalizeTarget, isAbsoluteForFamily, isWinFormPath, writeTargetPath, isUncPath, pathFamilyOf } from "../tools/fs/safety.js";
2
- import { judgePathRows } from "./path-guard-rows.js";
1
+ import { anchorSpelling, canonicalizeTarget, isAbsoluteForFamily, isWinFormPath, normalizeAbsPathLexically, writeTargetPath, isUncPath, pathFamilyOf } from "../tools/fs/safety.js";
2
+ import { checkoutReadingOf, guardHitReachClause, guardHitVia, judgePathRows } from "./path-guard-rows.js";
3
3
  import { protectivePathTargetOf } from "./tool-registry.js";
4
4
  import { pathTargetBaseOf } from "./effective-path-target.js";
5
5
  import { canonicalDataRootKeys, dataRootSpellings, relativeUnderRoot } from "./sensitive-path-policy.js";
@@ -207,6 +207,22 @@ export function spelledExemptionOf(dataRootPaths) {
207
207
  return (spelling) => relativeUnderDataRoot(spelling, roots);
208
208
  }
209
209
  export const WRITE_PROTECTION_TARGET_VIEWS = Object.freeze(["spelling-only", "target"]);
210
+ function judgedInCheckout(path, checkout, kind) {
211
+ const reading = checkoutReadingOf(kind);
212
+ for (const c of checkout ?? []) {
213
+ if (reading === "canonical-only" && c.kind !== "canonical")
214
+ continue;
215
+ const rel = relativeUnderRoot(path, c.root);
216
+ if (rel === null)
217
+ continue;
218
+ if (rel.split("/").some((s) => s === "." || s === ".."))
219
+ return path;
220
+ if (rel === "")
221
+ return c.base;
222
+ return c.base.endsWith("/") ? `${c.base}${rel}` : `${c.base}/${rel}`;
223
+ }
224
+ return path;
225
+ }
210
226
  export function compileWriteProtection(entries, opts) {
211
227
  const rows = resolveWriteProtectedTable(entries);
212
228
  if (rows.length === 0)
@@ -223,6 +239,10 @@ export function compileLegWriteJudgment(entries, opts) {
223
239
  judgeWriteTarget: rows.length === 0 && guardRows === undefined
224
240
  ? undefined
225
241
  : async (target, judgeOpts) => {
242
+ if (judgeOpts.spellingOnly === true) {
243
+ const spelled = await compiled.judgment(target, {}, undefined);
244
+ return spelled !== undefined && spelled.unreadable === undefined && TABLE_ROWS.has(spelled.row) ? "protected" : undefined;
245
+ }
226
246
  const hit = await compiled.judgment(target, { ...(judgeOpts.signal !== undefined ? { signal: judgeOpts.signal } : {}), ...(judgeOpts.canonical === true ? { canonical: true } : {}) }, judgeOpts.fs, guardRows);
227
247
  return hit === undefined ? undefined : hit.unreadable === undefined && TABLE_ROWS.has(hit.row) ? "protected" : "guarded";
228
248
  },
@@ -234,6 +254,8 @@ function heldRows(cause) {
234
254
  }
235
255
  function compileWriteJudgment(rows, origin, opts) {
236
256
  const dataRootPaths = opts.exemptRoots;
257
+ const exemptFileKeys = (opts.exemptFiles ?? []).map((f) => f.key);
258
+ const exemptFileSpellings = new Set((opts.exemptFiles ?? []).flatMap((f) => [normalizeAbsPathLexically(f.spelled), normalizeAbsPathLexically(f.key)]));
237
259
  const spelledRemainder = spelledExemptionOf(dataRootPaths);
238
260
  const readingMemo = new Map();
239
261
  const readingsOf = (spelling) => {
@@ -275,9 +297,10 @@ function compileWriteJudgment(rows, origin, opts) {
275
297
  return readingsOf(view.path).some((segs) => roots.some((root) => atConfigRoot(segs, root.map(foldWriteProtectSegment), tail))) ? REACHED : NOT_REACHED;
276
298
  }, { below: opts?.agentConfigDir ?? "" }));
277
299
  const tableAt = (canonicalRoots) => (configTails.length === 0 ? tableRows : [...tableRows, ...configRowsAt(canonicalRoots)]);
278
- const spelledView = (spelled, kind) => {
279
- const remainder = spelledRemainder(spelled);
280
- return { path: spelled, kind, ...(remainder !== null ? { exemptRemainder: remainder } : {}) };
300
+ const spelledView = (spelled, kind, checkout) => {
301
+ const judgedPath = judgedInCheckout(spelled, checkout, kind);
302
+ const remainder = spelledRemainder(judgedPath);
303
+ return { path: judgedPath, kind, ...(remainder !== null ? { exemptRemainder: remainder } : {}) };
281
304
  };
282
305
  const anchoredSpelling = (path, cwd) => {
283
306
  const base = typeof cwd === "string" && cwd.length > 0 ? cwd : undefined;
@@ -307,9 +330,11 @@ function compileWriteJudgment(rows, origin, opts) {
307
330
  })();
308
331
  const givenKey = ctx.canonical === true && env !== undefined;
309
332
  const base = ctx.base ?? ctx.cwd ?? rootPath;
310
- const lexical = givenKey ? undefined : spelledView(anchoredSpelling(path, ctx.base ?? ctx.cwd), "lexical");
333
+ const checkout = opts.checkoutOf?.();
334
+ const lexical = givenKey ? undefined : spelledView(anchoredSpelling(path, ctx.base ?? ctx.cwd), "lexical", checkout);
311
335
  const bySpelling = lexical === undefined ? undefined : judgePathRows([...tableAt([]), ...extra], { views: [lexical] }, "tighten");
312
- if (bySpelling !== undefined && bySpelling.unreadable === undefined && TABLE_ROWS.has(bySpelling.row))
336
+ const namesExemptFile = lexical !== undefined && env !== undefined && exemptFileSpellings.has(normalizeAbsPathLexically(lexical.path));
337
+ if (bySpelling !== undefined && bySpelling.unreadable === undefined && TABLE_ROWS.has(bySpelling.row) && !namesExemptFile)
313
338
  return bySpelling;
314
339
  if (env === undefined)
315
340
  return bySpelling;
@@ -338,11 +363,13 @@ function compileWriteJudgment(rows, origin, opts) {
338
363
  const canonicalRoots = canonKey === undefined || configTails.length === 0 || opts?.agentConfigDir === undefined ? [] : (await canonicalDataRootKeys(env, [opts.agentConfigDir], ctx.signal, rootLookupFailed)).map(agentConfigDirSegments);
339
364
  const table = [...tableAt(canonicalRoots), ...extra];
340
365
  const aliased = canonAliased ? { aliasResolved: true } : {};
341
- const views = [...(lexical !== undefined ? [{ ...lexical, ...aliased }] : []), ...(canonKey !== undefined ? [{ path: canonKey, kind: "canonical", ...aliased }] : [])];
366
+ const views = [...(lexical !== undefined ? [{ ...lexical, ...aliased }] : []), ...(canonKey !== undefined ? [{ path: judgedInCheckout(canonKey, checkout, "canonical"), kind: "canonical", ...aliased }] : [])];
342
367
  const identity = {};
343
368
  const identityRemainder = () => (identity.asked ??= (async () => {
344
369
  if (canonKey === undefined)
345
370
  return undefined;
371
+ if (exemptFileKeys.includes(canonKey))
372
+ return "";
346
373
  for (const rootKey of await canonicalDataRootKeys(env, dataRootPaths, ctx.signal, rootLookupFailed)) {
347
374
  const relative = relativeUnderRoot(canonKey, rootKey);
348
375
  if (relative !== null)
@@ -377,7 +404,7 @@ function compileWriteJudgment(rows, origin, opts) {
377
404
  targetUnread ??= chain.value.cause;
378
405
  }
379
406
  for (const hop of chainHopsOrNone(chain.value))
380
- views.push(spelledView(hop, "hop"));
407
+ views.push(spelledView(hop, "hop", checkout));
381
408
  }
382
409
  return judged();
383
410
  };
@@ -385,7 +412,7 @@ function compileWriteJudgment(rows, origin, opts) {
385
412
  rows,
386
413
  targetView: opts?.env === undefined ? "spelling-only" : "target",
387
414
  matchPath(path, cwd) {
388
- const hit = judgePathRows(tableAt([]), { views: [spelledView(anchoredSpelling(path, cwd), "lexical")] }, "tighten");
415
+ const hit = judgePathRows(tableAt([]), { views: [spelledView(anchoredSpelling(path, cwd), "lexical", opts.checkoutOf?.())] }, "tighten");
389
416
  return hit === undefined ? null : { name: hit.row.name, kind: hit.row.kind };
390
417
  },
391
418
  async judge(path, ctx = {}) {
@@ -417,7 +444,7 @@ function atConfigRoot(segs, root, tail) {
417
444
  return segs.length >= root.length + tail.length && root.every((a, i) => segs[i] === a) && tail.every((t, i) => segs[root.length + i] === t);
418
445
  }
419
446
  function verdictOf(hit) {
420
- return { kind: "hit", hit: { name: hit.row.name, kind: hit.row.kind }, via: hit.viewKind === "canonical" ? "target" : hit.viewKind === "hop" ? "chain" : "spelling" };
447
+ return { kind: "hit", hit: { name: hit.row.name, kind: hit.row.kind }, via: guardHitVia(hit.viewKind) };
421
448
  }
422
449
  export function writeProtectionTightenDecision(toolName, verdict) {
423
450
  if (verdict.kind === "clear")
@@ -429,19 +456,19 @@ export function writeProtectionTightenDecision(toolName, verdict) {
429
456
  decisionReason: "safety",
430
457
  };
431
458
  }
459
+ const reach = guardHitReachClause(verdict.via);
432
460
  return {
433
461
  action: "ask",
434
- message: verdict.via === "target"
435
- ? `tool "${toolName}" writes to a write-protected path — its real target resolves onto table entry "${verdict.hit.name}" — explicit approval required`
436
- : verdict.via === "chain"
437
- ? `tool "${toolName}" writes to a write-protected path — its symlink chain passes through table entry "${verdict.hit.name}" — explicit approval required`
438
- : `tool "${toolName}" writes to a write-protected path (table entry "${verdict.hit.name}") — explicit approval required`,
462
+ message: `tool "${toolName}" writes to a write-protected path (table entry "${verdict.hit.name}")${reach !== undefined ? ` — ${reach}` : ""} — explicit approval required`,
439
463
  decisionReason: "safety",
440
464
  };
441
465
  }
442
466
  export function writeProtectionMandated(verdict) {
443
467
  return verdict.kind === "hit";
444
468
  }
469
+ export function writeProtectionReachOf(verdict) {
470
+ return verdict.kind !== "hit" ? undefined : verdict.via === "spelling" ? "spelling" : "on_disk";
471
+ }
445
472
  export function createWriteProtectionCheck(entries, opts) {
446
473
  const matcher = compileWriteProtection(entries, opts);
447
474
  return matcher === undefined ? undefined : writeProtectionMountOver(matcher, opts?.rootPath);
@@ -583,10 +583,36 @@ function createSummarizationOptions(model, maxTokens, apiKey, headers, signal, t
583
583
  return options;
584
584
  }
585
585
  async function completeSummarization(model, context, options, streamFn, runtime) {
586
- if (streamFn) {
587
- return (await streamFn(model, context, options)).result();
586
+ const call = async () => streamFn ? (await streamFn(model, context, options)).result() : await resolveAgentCoreCompleteFn(runtime)(model, context, options);
587
+ const signal = options.signal;
588
+ if (signal === undefined)
589
+ return await call();
590
+ if (signal.aborted)
591
+ return summaryCallAborted(model);
592
+ let release = () => undefined;
593
+ const cut = new Promise((resolve) => {
594
+ const onAbort = () => resolve(summaryCallAborted(model));
595
+ signal.addEventListener("abort", onAbort, { once: true });
596
+ release = () => signal.removeEventListener("abort", onAbort);
597
+ });
598
+ try {
599
+ return await Promise.race([cut, call()]);
600
+ }
601
+ finally {
602
+ release();
588
603
  }
589
- return await resolveAgentCoreCompleteFn(runtime)(model, context, options);
604
+ }
605
+ function summaryCallAborted(model) {
606
+ return {
607
+ role: "assistant",
608
+ content: [],
609
+ api: model.api,
610
+ provider: model.provider,
611
+ model: model.id,
612
+ usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
613
+ stopReason: "aborted",
614
+ timestamp: Date.now(),
615
+ };
590
616
  }
591
617
  const SUMMARY_REASONING_FLOOR = 2048;
592
618
  const SUMMARY_MAX_ESCALATIONS = 2;
@@ -93,8 +93,8 @@ export declare class NodeExecutionEnv implements ExecutionEnv, BackgroundShellCa
93
93
  get withheldEnv(): readonly SecretEnvFinding[];
94
94
  /** The environment the next shell child would receive, for a READ (the scrub seat is the reader's collector or a
95
95
  * no-op: a read announces nothing). `undefined` when no child would be spawned at all — the policy is refused against
96
- * the own credentials declared since construction, and every spawn throws that reason — so a reader sees "the child
97
- * gets none", never a throw. */
96
+ * the own credentials declared since construction, or `shellEnv` is no grant, and every spawn throws that reason — so
97
+ * a reader sees "the child gets none", never a throw. Composed once: the refusal is the composition's own. */
98
98
  private childEnvForRead;
99
99
  private shellPath?;
100
100
  private shellEnv?;
@@ -118,7 +118,8 @@ export declare class NodeExecutionEnv implements ExecutionEnv, BackgroundShellCa
118
118
  shellEnv?: NodeJS.ProcessEnv;
119
119
  /** VENDORED EDIT (D1, security): how much of `process.env` the shell child inherits. Default `"scrub"` =
120
120
  * fail-closed (drop secret-pattern keys, keep PATH/build/locale). `"all"` = full inherit (trusted env);
121
- * `string[]` = strict allowlist. `shellEnv`/per-exec `env` always pass through. Any other value — an unknown
121
+ * `string[]` = strict allowlist. `shellEnv`/per-exec `env` always pass through (`hostChildEnv`'s grants: one that is
122
+ * not a map of variable names to strings throws here and at the spawn). Any other value — an unknown
122
123
  * word, a non-string, a list entry that is not a variable name — throws here (`inheritEnvPolicyProblem`'s
123
124
  * reason), the same judgment the oracle gate's `inheritEnv` meets. Whatever the policy, the deployment's own
124
125
  * credentials (`declareWithheldEnv`: by name, and by a value equal to a declared or engine-held credential value)
@@ -3,20 +3,22 @@ import { randomUUID } from "node:crypto";
3
3
  import { closeSync, constants, createReadStream, mkdtempSync, openSync, readSync, rmSync, statSync, truncateSync, unlinkSync } from "node:fs";
4
4
  import { access, appendFile, lstat, mkdir, mkdtemp, open, readdir, readFile, readlink, rename, rm, stat, unlink, writeFile, } from "node:fs/promises";
5
5
  import { tmpdir } from "node:os";
6
- import { isAbsolute, join, resolve } from "node:path";
6
+ import { dirname, isAbsolute, join, sep } from "node:path";
7
7
  import { createInterface } from "node:readline";
8
8
  import { ExecutionError, err, FileError, ok, toError, } from "../harness/types.js";
9
9
  import { killProcessTree, shutdownDebug } from "./kill-tree.js";
10
- import { __resetSecretEnvScrubNoticeAnnouncement, announceSecretEnvScrub, inheritEnvPolicyProblem, inheritedHostEnv } from "../../core/secret-env.js";
10
+ import { __resetSecretEnvScrubNoticeAnnouncement, announceSecretEnvScrub, hostChildEnv, hostChildEnvProblem, inheritedHostEnv } from "../../core/secret-env.js";
11
11
  import { physicalPathOfAsync } from "../../core/physical-path.js";
12
12
  import { posixModeBitsMeaningful } from "../../core/posix-mode-face.js";
13
- import { walkSymlinkChain } from "./symlink-chain.js";
13
+ import { anchorAtLinkDir, walkSymlinkChain } from "./symlink-chain.js";
14
14
  import { RollingTailBuffer, markTruncated, newStreamCursorState, sliceStreamIncrement, } from "../../core/exec-output-tail.js";
15
15
  import { BackgroundShellError } from "../../core/background-shell.js";
16
16
  import { SchedulerError } from "../../core/scheduler.js";
17
17
  const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
18
18
  function resolvePath(cwd, path) {
19
- return isAbsolute(path) ? path : resolve(cwd, path);
19
+ if (isAbsolute(path))
20
+ return path;
21
+ return anchorAtLinkDir(isAbsolute(cwd) ? cwd : anchorAtLinkDir(process.cwd(), cwd, sep), path, sep);
20
22
  }
21
23
  export function resolveExecTimeoutMs(timeoutSeconds) {
22
24
  if (typeof timeoutSeconds !== "number" ||
@@ -246,9 +248,7 @@ export function __resetSecretScrubAnnouncement() {
246
248
  __resetSecretEnvScrubNoticeAnnouncement();
247
249
  }
248
250
  function getShellEnv(inheritEnv, baseEnv, extraEnv, onScrub, onNotice) {
249
- const scrubbed = [];
250
- const inherited = inheritedHostEnv(inheritEnv, scrubbed);
251
- const findings = scrubbed.filter((f) => baseEnv?.[f.key] === undefined && extraEnv?.[f.key] === undefined);
251
+ const { env, withheld: findings } = hostChildEnv(inheritEnv, baseEnv, extraEnv);
252
252
  if (findings.length > 0) {
253
253
  if (typeof onScrub === "function") {
254
254
  try {
@@ -273,11 +273,7 @@ function getShellEnv(inheritEnv, baseEnv, extraEnv, onScrub, onNotice) {
273
273
  announceSecretEnvScrub(onNotice, findings);
274
274
  }
275
275
  }
276
- return {
277
- ...inherited,
278
- ...baseEnv,
279
- ...extraEnv,
280
- };
276
+ return env;
281
277
  }
282
278
  const EXIT_SETTLE_DRAIN_MS = 500;
283
279
  const EXEC_SPOOL_PUMP_MS = 200;
@@ -331,9 +327,12 @@ export class NodeExecutionEnv {
331
327
  return withheld;
332
328
  }
333
329
  childEnvForRead(collect = () => { }) {
334
- if (inheritEnvPolicyProblem(this.inheritEnv) !== undefined)
330
+ try {
331
+ return getShellEnv(this.inheritEnv, this.shellEnv, undefined, collect);
332
+ }
333
+ catch {
335
334
  return undefined;
336
- return getShellEnv(this.inheritEnv, this.shellEnv, undefined, collect);
335
+ }
337
336
  }
338
337
  shellPath;
339
338
  shellEnv;
@@ -351,7 +350,7 @@ export class NodeExecutionEnv {
351
350
  this.cwd = options.cwd;
352
351
  this.shellPath = options.shellPath;
353
352
  this.shellEnv = options.shellEnv;
354
- const inheritEnvProblem = inheritEnvPolicyProblem(options.inheritEnv);
353
+ const inheritEnvProblem = hostChildEnvProblem(options.inheritEnv, options.shellEnv);
355
354
  if (inheritEnvProblem !== undefined)
356
355
  throw new Error(`NodeExecutionEnv: ${inheritEnvProblem}`);
357
356
  this.inheritEnv = Array.isArray(options.inheritEnv) ? [...options.inheritEnv] : (options.inheritEnv ?? "scrub");
@@ -396,7 +395,9 @@ export class NodeExecutionEnv {
396
395
  return ok(resolvePath(this.cwd, path));
397
396
  }
398
397
  async joinPath(parts) {
399
- return ok(join(...parts));
398
+ const leading = sep === "\\" ? /^[\\/]+/ : /^\/+/;
399
+ const named = parts.map((part, i) => (i === 0 ? part : part.replace(leading, ""))).filter((part) => part !== "");
400
+ return ok(named.length === 0 ? "." : named.reduce((at, part) => anchorAtLinkDir(at, part, sep)));
400
401
  }
401
402
  async exec(command, options) {
402
403
  if (options?.abortSignal?.aborted) {
@@ -831,7 +832,7 @@ export class NodeExecutionEnv {
831
832
  return aborted;
832
833
  }
833
834
  try {
834
- await mkdir(resolve(resolved, ".."), { recursive: true });
835
+ await mkdir(dirname(resolved), { recursive: true });
835
836
  }
836
837
  catch (error) {
837
838
  return err(toFileError(error, resolved));
@@ -854,8 +855,8 @@ export class NodeExecutionEnv {
854
855
  let hop;
855
856
  try {
856
857
  const link = await readlink(resolved);
857
- const parentReal = await physicalPathOfAsync(resolve(resolved, "..")).catch(() => resolve(resolved, ".."));
858
- hop = isAbsolute(link) ? link : resolve(parentReal, link);
858
+ const parentReal = await physicalPathOfAsync(dirname(resolved)).catch(() => dirname(resolved));
859
+ hop = isAbsolute(link) ? link : anchorAtLinkDir(parentReal, link, sep);
859
860
  }
860
861
  catch {
861
862
  hop = undefined;
@@ -956,7 +957,7 @@ export class NodeExecutionEnv {
956
957
  return aborted;
957
958
  }
958
959
  try {
959
- await mkdir(resolve(resolved, ".."), { recursive: true });
960
+ await mkdir(dirname(resolved), { recursive: true });
960
961
  }
961
962
  catch (error) {
962
963
  return err(toFileError(error, resolved));
@@ -979,7 +980,7 @@ export class NodeExecutionEnv {
979
980
  async appendFile(path, content) {
980
981
  const resolved = resolvePath(this.cwd, path);
981
982
  try {
982
- await mkdir(resolve(resolved, ".."), { recursive: true });
983
+ await mkdir(dirname(resolved), { recursive: true });
983
984
  await appendFile(resolved, content);
984
985
  return ok(undefined);
985
986
  }
@@ -1036,7 +1037,7 @@ export class NodeExecutionEnv {
1036
1037
  if (loopAbort) {
1037
1038
  return loopAbort;
1038
1039
  }
1039
- const entryPath = resolve(resolved, entry.name);
1040
+ const entryPath = anchorAtLinkDir(resolved, entry.name, sep);
1040
1041
  try {
1041
1042
  const info = fileInfoFromStats(entryPath, await lstat(entryPath));
1042
1043
  if (info.ok) {
@@ -1152,7 +1153,7 @@ export class NodeExecutionEnv {
1152
1153
  const loopAbort = abortResult(abortSignal, resolved);
1153
1154
  if (loopAbort)
1154
1155
  return loopAbort;
1155
- const info = fileInfoFromStats(resolve(resolved, entry.name), await lstat(join(listed, entry.name)));
1156
+ const info = fileInfoFromStats(anchorAtLinkDir(resolved, entry.name, sep), await lstat(anchorAtLinkDir(listed, entry.name, sep)));
1156
1157
  if (info.ok)
1157
1158
  infos.push(info.value);
1158
1159
  }
@@ -1,10 +1,12 @@
1
1
  import { type FileError, type Result, type SymlinkChain } from "../harness/types.js";
2
2
  /**
3
- * Anchor a RELATIVE symlink target at its link's own directory, UNFOLDED, with exactly one separator between the two.
4
- * A root directory (`/`, `C:\`, `\\host\share\`) already ends in its own separator, and a second one mints a spelling
5
- * (`//private/tmp`) that no guarded row matches; `path.resolve`/`join` would fix the separator and fold `..`, which
6
- * this walk may not do. `separator` is the one the caller's `dirname` writes (a pure function of its inputs); a
7
- * backslash terminates only where it IS a separator — on a POSIX tree `/a/b\` is an ordinary name.
3
+ * Anchor a RELATIVE spelling at a directory, UNFOLDED, with exactly one separator between the two — the one anchor of
4
+ * this environment: a symlink target at its link's own directory (the walk below), a path at the environment's `cwd`
5
+ * and a name under the directory that holds it (`NodeExecutionEnv`'s every member). A root directory (`/`, `C:\`,
6
+ * `\\host\share\`) already ends in its own separator, and a second one mints a spelling (`//private/tmp`) that no
7
+ * guarded row matches; `path.resolve`/`join` would fix the separator and fold `..`, which no reader of a path may do —
8
+ * a `..` is the filesystem's to resolve. `separator` is the one the caller's `dirname` writes (a pure function of its
9
+ * inputs); a backslash terminates only where it IS a separator — on a POSIX tree `/a/b\` is an ordinary name.
8
10
  */
9
11
  export declare function anchorAtLinkDir(linkDir: string, target: string, separator: string): string;
10
12
  /** The walk's bound (the reference CLI's own); the terminal canonicalizer refuses at 16, so this only bounds what is REPORTED. */