@sema-agent/core 7.56.0 → 7.58.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 (319) hide show
  1. package/CHANGELOG.md +926 -0
  2. package/LICENSE +1 -1
  3. package/dist/agents/org-delivery-gate.js +3 -4
  4. package/dist/agents/peer-held-queue.d.ts +69 -49
  5. package/dist/agents/peer-held-queue.js +255 -106
  6. package/dist/agents/peer-session-drain.js +63 -43
  7. package/dist/agents/send-message-tool.js +3 -2
  8. package/dist/agents/subagent-steps.js +2 -4
  9. package/dist/agents/subagent.js +8 -8
  10. package/dist/brain/anthropic.js +16 -8
  11. package/dist/brain/open-responses.js +10 -8
  12. package/dist/brain/openai.js +11 -9
  13. package/dist/brain/provider-dialect.d.ts +3 -2
  14. package/dist/brain/provider-dialect.js +2 -2
  15. package/dist/brain/request-params.d.ts +6 -0
  16. package/dist/brain/request-params.js +14 -1
  17. package/dist/brain/route-adjudicator.js +2 -1
  18. package/dist/brain/stream-engine.d.ts +9 -0
  19. package/dist/brain/stream-engine.js +24 -10
  20. package/dist/brain/stream-shared.d.ts +5 -4
  21. package/dist/brain/stream-shared.js +4 -4
  22. package/dist/core/a2a.d.ts +2 -1
  23. package/dist/core/a2a.js +23 -10
  24. package/dist/core/allow-entry.d.ts +5 -11
  25. package/dist/core/allow-entry.js +19 -26
  26. package/dist/core/approval-object.d.ts +21 -5
  27. package/dist/core/approval-object.js +44 -17
  28. package/dist/core/ask-origin.d.ts +23 -4
  29. package/dist/core/ask-origin.js +5 -1
  30. package/dist/core/auto-compaction.d.ts +75 -6
  31. package/dist/core/auto-compaction.js +43 -27
  32. package/dist/core/auto-mode-directive.d.ts +29 -5
  33. package/dist/core/auto-mode-directive.js +38 -8
  34. package/dist/core/background-agent-store.d.ts +6 -2
  35. package/dist/core/background-agent-store.js +1 -1
  36. package/dist/core/checkpoint-requirements.d.ts +13 -1
  37. package/dist/core/checkpoint-requirements.js +4 -0
  38. package/dist/core/checkpoint-store.d.ts +44 -40
  39. package/dist/core/checkpoint-store.js +32 -14
  40. package/dist/core/cross-boundary-taint.js +4 -2
  41. package/dist/core/engine-notice.d.ts +4 -3
  42. package/dist/core/engine-notice.js +6 -0
  43. package/dist/core/file-history-store.d.ts +14 -8
  44. package/dist/core/file-history-store.js +14 -4
  45. package/dist/core/fs-write-gate-policy.d.ts +4 -2
  46. package/dist/core/fs-write-gate-policy.js +7 -3
  47. package/dist/core/gate-fold.js +6 -3
  48. package/dist/core/gate-lanes.js +13 -5
  49. package/dist/core/git-worktree-env.d.ts +53 -11
  50. package/dist/core/git-worktree-env.js +96 -12
  51. package/dist/core/hooks.d.ts +6 -3
  52. package/dist/core/hooks.js +12 -5
  53. package/dist/core/human-input-projection.d.ts +1 -0
  54. package/dist/core/human-input-projection.js +3 -0
  55. package/dist/core/locked-config.d.ts +15 -1
  56. package/dist/core/locked-config.js +38 -2
  57. package/dist/core/mailbox-store.d.ts +62 -1
  58. package/dist/core/mailbox-store.js +59 -0
  59. package/dist/core/mcp-call-meta.d.ts +66 -0
  60. package/dist/core/mcp-call-meta.js +103 -0
  61. package/dist/core/mcp-connection-pool.d.ts +3 -1
  62. package/dist/core/mcp-connection-pool.js +3 -1
  63. package/dist/core/mcp-failure.d.ts +7 -1
  64. package/dist/core/mcp-failure.js +10 -0
  65. package/dist/core/mcp-name-judge.d.ts +46 -0
  66. package/dist/core/mcp-name-judge.js +61 -0
  67. package/dist/core/mcp-probe.d.ts +5 -1
  68. package/dist/core/mcp-probe.js +3 -6
  69. package/dist/core/mcp-server-link.d.ts +5 -2
  70. package/dist/core/mcp-server-spec.d.ts +46 -18
  71. package/dist/core/mcp-server-spec.js +1 -18
  72. package/dist/core/mcp.d.ts +6 -14
  73. package/dist/core/mcp.js +85 -65
  74. package/dist/core/memory-engine/consolidation-driver.js +4 -3
  75. package/dist/core/memory-engine/distiller.js +26 -17
  76. package/dist/core/memory-engine/layout.js +5 -2
  77. package/dist/core/memory-engine/scope-contract.d.ts +45 -4
  78. package/dist/core/memory-engine/scope-contract.js +80 -11
  79. package/dist/core/mode-policy.d.ts +8 -5
  80. package/dist/core/mode-policy.js +5 -4
  81. package/dist/core/mods/host.js +1 -1
  82. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  83. package/dist/core/mods/kernel/dispatch.js +10 -8
  84. package/dist/core/mods/kernel/events.d.ts +5 -1
  85. package/dist/core/mods/kernel/events.js +1 -1
  86. package/dist/core/mods/kernel/registration.d.ts +5 -1
  87. package/dist/core/mods/kernel/site-rules.d.ts +3 -0
  88. package/dist/core/mods/kernel/site-rules.js +10 -0
  89. package/dist/core/mods/package.d.ts +23 -0
  90. package/dist/core/mods/package.js +118 -0
  91. package/dist/core/mods/stations.d.ts +2 -2
  92. package/dist/core/mods/stations.js +1 -1
  93. package/dist/core/mods/tool-call.d.ts +5 -1
  94. package/dist/core/mods/tool-call.js +12 -3
  95. package/dist/core/park-selfcheck.js +2 -0
  96. package/dist/core/path-guard-rows.d.ts +20 -0
  97. package/dist/core/path-guard-rows.js +11 -0
  98. package/dist/core/peer-seat.d.ts +186 -0
  99. package/dist/core/peer-seat.js +307 -0
  100. package/dist/core/permission-rule-consent.d.ts +5 -3
  101. package/dist/core/permission-rule-consent.js +20 -15
  102. package/dist/core/permission-rule-model.d.ts +43 -2
  103. package/dist/core/permission-rule-model.js +52 -8
  104. package/dist/core/permission-rule-org.js +1 -1
  105. package/dist/core/present-plan-tool.d.ts +10 -1
  106. package/dist/core/present-plan-tool.js +46 -2
  107. package/dist/core/protocol-http-auth.d.ts +56 -31
  108. package/dist/core/protocol-http-auth.js +71 -42
  109. package/dist/core/protocol-naming.d.ts +20 -0
  110. package/dist/core/protocol-naming.js +20 -3
  111. package/dist/core/read-only-shell.d.ts +20 -5
  112. package/dist/core/read-only-shell.js +29 -14
  113. package/dist/core/redaction-marks.d.ts +16 -0
  114. package/dist/core/redaction-marks.js +16 -0
  115. package/dist/core/redaction-passes.js +8 -9
  116. package/dist/core/remote-env.d.ts +37 -1
  117. package/dist/core/remote-env.js +11 -0
  118. package/dist/core/resume-startup-cause.d.ts +24 -2
  119. package/dist/core/resume-startup-cause.js +20 -1
  120. package/dist/core/retention.d.ts +41 -15
  121. package/dist/core/retention.js +59 -12
  122. package/dist/core/rewrite-rejudge.d.ts +37 -0
  123. package/dist/core/rewrite-rejudge.js +40 -0
  124. package/dist/core/roles.js +50 -7
  125. package/dist/core/run-origin.d.ts +40 -0
  126. package/dist/core/run-origin.js +37 -0
  127. package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
  128. package/dist/core/runner/advertised-writable-dirs.js +126 -0
  129. package/dist/core/runner/compact-session.d.ts +10 -0
  130. package/dist/core/runner/compact-session.js +202 -0
  131. package/dist/core/runner/compaction-call-options.d.ts +2 -2
  132. package/dist/core/runner/compaction-restate.d.ts +15 -6
  133. package/dist/core/runner/compaction-restate.js +28 -2
  134. package/dist/core/runner/compaction-seams.d.ts +21 -1
  135. package/dist/core/runner/compaction-seams.js +11 -8
  136. package/dist/core/runner/contracts.d.ts +36 -21
  137. package/dist/core/runner/derived-route-fallback.d.ts +13 -0
  138. package/dist/core/runner/derived-route-fallback.js +6 -0
  139. package/dist/core/runner/env-capability-census.d.ts +3 -2
  140. package/dist/core/runner/env-capability-census.js +9 -3
  141. package/dist/core/runner/gate-exit.d.ts +18 -4
  142. package/dist/core/runner/gate-exit.js +5 -1
  143. package/dist/core/runner/permission-rule-lanes.d.ts +7 -7
  144. package/dist/core/runner/permission-rule-lanes.js +17 -11
  145. package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
  146. package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
  147. package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
  148. package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
  149. package/dist/core/runner/prepare-config-doors.d.ts +14 -5
  150. package/dist/core/runner/prepare-config-doors.js +16 -13
  151. package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
  152. package/dist/core/runner/prepare-delegation-surface.js +15 -18
  153. package/dist/core/runner/prepare-gate-stations.js +1 -1
  154. package/dist/core/runner/prepare-hands-readface.d.ts +10 -4
  155. package/dist/core/runner/prepare-hands-readface.js +6 -1
  156. package/dist/core/runner/prepare-memory.d.ts +3 -0
  157. package/dist/core/runner/prepare-memory.js +19 -23
  158. package/dist/core/runner/prepare-park-ask.d.ts +2 -0
  159. package/dist/core/runner/prepare-park-ask.js +2 -2
  160. package/dist/core/runner/prepare-policy-chain.d.ts +4 -4
  161. package/dist/core/runner/prepare-policy-chain.js +4 -6
  162. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
  163. package/dist/core/runner/prepare-protocol-tools.js +3 -3
  164. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  165. package/dist/core/runner/prepare-suspend-saga.js +2 -1
  166. package/dist/core/runner/prepare-task.d.ts +4 -1
  167. package/dist/core/runner/prepare-task.js +46 -37
  168. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +13 -0
  169. package/dist/core/runner/prepare-tool-disclosure-mount.js +13 -7
  170. package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
  171. package/dist/core/runner/prepare-wiring-manifest.js +2 -2
  172. package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
  173. package/dist/core/runner/prepare-workspace-restore.js +4 -4
  174. package/dist/core/runner/resume-admission.js +1 -1
  175. package/dist/core/runner/resume-checkpoint-screen.js +2 -0
  176. package/dist/core/runner/rewind-files.d.ts +2 -5
  177. package/dist/core/runner/rewind-files.js +9 -51
  178. package/dist/core/runner/run-harness-handlers.d.ts +3 -4
  179. package/dist/core/runner/run-harness-handlers.js +1 -8
  180. package/dist/core/runner/run-identity-wiring.js +1 -0
  181. package/dist/core/runner/run-leg.js +15 -22
  182. package/dist/core/runner/run-notification-lane.d.ts +2 -0
  183. package/dist/core/runner/run-notification-lane.js +5 -2
  184. package/dist/core/runner/run-recovery-lanes.js +3 -4
  185. package/dist/core/runner/run-settle-and-teardown.js +5 -11
  186. package/dist/core/runner/run-terminal-adoption.js +3 -4
  187. package/dist/core/runner/run-turn-boundary.js +3 -5
  188. package/dist/core/runner/runtask.d.ts +8 -1
  189. package/dist/core/runner/runtask.js +28 -34
  190. package/dist/core/runner/send-message-continuation.js +1 -1
  191. package/dist/core/runner/session-verb-doors.d.ts +28 -0
  192. package/dist/core/runner/session-verb-doors.js +48 -0
  193. package/dist/core/runner/session-write-ledger.d.ts +30 -0
  194. package/dist/core/runner/session-write-ledger.js +101 -0
  195. package/dist/core/runner/stream-settle-backstop.js +11 -14
  196. package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
  197. package/dist/core/runner/sub-agent-deny-lists.js +21 -10
  198. package/dist/core/runner/teardown-bounded.d.ts +1 -0
  199. package/dist/core/runner/teardown-bounded.js +1 -0
  200. package/dist/core/runner/terminal-account.js +3 -3
  201. package/dist/core/runner/tool-end-body.js +1 -0
  202. package/dist/core/runner/tool-occurrence.d.ts +4 -1
  203. package/dist/core/runner/tool-occurrence.js +2 -1
  204. package/dist/core/runner/write-protection-station.d.ts +8 -2
  205. package/dist/core/runner/write-protection-station.js +2 -0
  206. package/dist/core/runner-deps.d.ts +4 -4
  207. package/dist/core/secret-env.d.ts +4 -0
  208. package/dist/core/secret-env.js +3 -0
  209. package/dist/core/sensitive-path-policy.js +6 -7
  210. package/dist/core/session-log-transfer.d.ts +24 -0
  211. package/dist/core/session-log-transfer.js +166 -0
  212. package/dist/core/session-policy-store.d.ts +7 -2
  213. package/dist/core/session-policy-store.js +1 -1
  214. package/dist/core/session-store.d.ts +84 -19
  215. package/dist/core/session-store.js +162 -24
  216. package/dist/core/session.d.ts +92 -1
  217. package/dist/core/shell-read-silence.js +1 -0
  218. package/dist/core/shell-wrapper-projection.d.ts +1 -1
  219. package/dist/core/steer-replay.d.ts +4 -2
  220. package/dist/core/steer-replay.js +2 -1
  221. package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
  222. package/dist/core/store-contracts/checkpoint-store-contract.js +19 -1
  223. package/dist/core/store-contracts/file-history-store-contract.js +9 -0
  224. package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
  225. package/dist/core/store-contracts/session-repo-contract.js +112 -5
  226. package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
  227. package/dist/core/store-contracts/session-store-contract.js +236 -2
  228. package/dist/core/task-event.d.ts +68 -8
  229. package/dist/core/task-registry-agent.d.ts +8 -4
  230. package/dist/core/task-registry-agent.js +14 -8
  231. package/dist/core/task-registry-shared.d.ts +36 -6
  232. package/dist/core/task-registry-shared.js +11 -0
  233. package/dist/core/task-registry.d.ts +1 -1
  234. package/dist/core/task-registry.js +1 -1
  235. package/dist/core/task-spec.d.ts +37 -0
  236. package/dist/core/task-stream.d.ts +2 -1
  237. package/dist/core/terminal-cause.d.ts +1 -1
  238. package/dist/core/tool-catalog-entries.d.ts +6 -0
  239. package/dist/core/tool-catalog-entries.js +2 -0
  240. package/dist/core/tool-name-aliases.d.ts +32 -2
  241. package/dist/core/tool-name-aliases.js +23 -0
  242. package/dist/core/tool-name-readings.d.ts +4 -0
  243. package/dist/core/tool-name-readings.js +1 -0
  244. package/dist/core/tool-policy.d.ts +10 -6
  245. package/dist/core/tool-policy.js +4 -7
  246. package/dist/core/tool-result-store.d.ts +17 -10
  247. package/dist/core/tool-result-store.js +3 -1
  248. package/dist/core/trace.d.ts +4 -1
  249. package/dist/core/trace.js +2 -1
  250. package/dist/core/types.d.ts +1 -1
  251. package/dist/core/untrusted-egress.d.ts +18 -0
  252. package/dist/core/untrusted-egress.js +82 -12
  253. package/dist/core/wiring-manifest.d.ts +12 -3
  254. package/dist/core/wiring-manifest.js +4 -3
  255. package/dist/core/workspace-snapshot.d.ts +44 -0
  256. package/dist/core/workspace-snapshot.js +34 -0
  257. package/dist/core/write-protect.d.ts +43 -3
  258. package/dist/core/write-protect.js +43 -16
  259. package/dist/engine/execution-env/node-execution-env.js +15 -11
  260. package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
  261. package/dist/engine/harness/agent-harness.d.ts +12 -5
  262. package/dist/engine/harness/agent-harness.js +13 -2
  263. package/dist/engine/harness/types.d.ts +48 -7
  264. package/dist/engine/harness/types.js +5 -1
  265. package/dist/engine/llm/types.d.ts +12 -3
  266. package/dist/engine/llm/types.js +1 -1
  267. package/dist/engine/loop/agent-loop.d.ts +1 -4
  268. package/dist/engine/loop/agent-loop.js +26 -4
  269. package/dist/engine/session/import-validate.js +3 -0
  270. package/dist/engine/session/memory-repo.d.ts +17 -9
  271. package/dist/engine/session/memory-repo.js +44 -34
  272. package/dist/engine/session/repo-utils.d.ts +22 -4
  273. package/dist/engine/session/repo-utils.js +49 -1
  274. package/dist/engine/session/storage-base.d.ts +10 -1
  275. package/dist/engine/session/storage-base.js +7 -1
  276. package/dist/index.d.ts +23 -11
  277. package/dist/index.js +15 -6
  278. package/dist/internal/harness-types.d.ts +1 -1
  279. package/dist/internal/harness.d.ts +4 -3
  280. package/dist/internal/harness.js +3 -2
  281. package/dist/stores/file/checkpoint-store.d.ts +0 -4
  282. package/dist/stores/file/checkpoint-store.js +0 -1
  283. package/dist/stores/file/file-history-store.js +12 -4
  284. package/dist/stores/file/index.d.ts +4 -1
  285. package/dist/stores/file/index.js +4 -1
  286. package/dist/stores/file/mailbox-store.d.ts +2 -1
  287. package/dist/stores/file/mailbox-store.js +26 -1
  288. package/dist/stores/file/session-store.d.ts +15 -8
  289. package/dist/stores/file/session-store.js +28 -13
  290. package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
  291. package/dist/tools/fs/bash-readonly-classifier.js +5 -10
  292. package/dist/tools/fs/fs-bash.js +10 -3
  293. package/dist/tools/fs/fs-write.d.ts +6 -3
  294. package/dist/tools/fs/fs-write.js +8 -7
  295. package/dist/tools/fs/index.d.ts +3 -0
  296. package/dist/tools/fs/index.js +1 -1
  297. package/dist/tools/fs/pattern-kill-guard.d.ts +3 -2
  298. package/dist/tools/fs/pattern-kill-guard.js +68 -36
  299. package/dist/tools/fs/safety.js +40 -8
  300. package/dist/tools/fs/search.js +6 -24
  301. package/dist/tools/fs/shell-read-check.d.ts +18 -1
  302. package/dist/tools/fs/shell-read-check.js +66 -16
  303. package/dist/tools/fs/shell-read-establish.js +2 -1
  304. package/dist/tools/fs/shell-read-identity.d.ts +12 -9
  305. package/dist/tools/fs/shell-read-identity.js +10 -5
  306. package/dist/tools/fs/shell-read-judge.d.ts +10 -1
  307. package/dist/tools/web.js +9 -7
  308. package/dist/tools/worktree.d.ts +42 -15
  309. package/dist/tools/worktree.js +60 -32
  310. package/package.json +4 -2
  311. package/test/export-surface.snapshot.json +141 -3
  312. package/wire-changes/core-stores-sql@7.57.0.json +29 -0
  313. package/wire-changes/core-stores-sql@7.58.0.json +29 -0
  314. package/wire-changes/core@7.57.0.json +1487 -0
  315. package/wire-changes/core@7.58.0.json +2188 -0
  316. package/wire-changes/mods-kernel@7.57.0.json +29 -0
  317. package/wire-changes/mods-kernel@7.58.0.json +81 -0
  318. package/wire-changes/primitives@7.57.0.json +245 -0
  319. package/wire-changes/primitives@7.58.0.json +29 -0
@@ -89,6 +89,7 @@ async function gateToolWrite(hook, tool, path, key, content) {
89
89
  return `Error (${tool}): write rejected by the write gate (${res.code}): ${clipHookText(res.reason)}`;
90
90
  return undefined;
91
91
  }
92
+ const rootOf = (seat) => (typeof seat === "function" ? seat() : seat);
92
93
  export function createEditFileTool(env, state, rootCanonical, cwdRef, additionalRoots, beforeWrite, trackEdit, onEdited, writeFace, writeDeny) {
93
94
  return defineTool({
94
95
  name: "Edit",
@@ -114,7 +115,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
114
115
  const path = fileArgPath(args);
115
116
  if (path === undefined)
116
117
  return { ok: true };
117
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
118
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
118
119
  if (!r.ok)
119
120
  return { ok: true };
120
121
  if (a.old_string === a.new_string)
@@ -152,7 +153,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
152
153
  const path = fileArgPath(args);
153
154
  if (path === undefined)
154
155
  return errorResult(`Error (Edit): file_path is required.`);
155
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
156
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
156
157
  if (!r.ok)
157
158
  return errorResult(violationText("Edit", r.violation), violationDetails(r.violation));
158
159
  if (!batch && a.old_string === a.new_string) {
@@ -190,7 +191,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
190
191
  details: { type: "create", filePath: path, content: created },
191
192
  };
192
193
  }
193
- return errorResult(`Error (Edit): ${await enoentMessage(env, r.key, cwdRef?.current ?? rootCanonical, ctx.signal)}`);
194
+ return errorResult(`Error (Edit): ${await enoentMessage(env, r.key, cwdRef?.current ?? rootOf(rootCanonical), ctx.signal)}`);
194
195
  }
195
196
  const editInfo = await env.fileInfo(r.key, ctx.signal);
196
197
  if (editInfo.ok && editInfo.value.size > MAX_EDIT_BYTES) {
@@ -346,7 +347,7 @@ export function createWriteFileTool(env, state, rootCanonical, cwdRef, additiona
346
347
  return { ok: true };
347
348
  if (ipynbRedirect("Write", path))
348
349
  return { ok: true };
349
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
350
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
350
351
  if (!r.ok)
351
352
  return { ok: true };
352
353
  const exists = await env.exists(r.key, ctx.signal);
@@ -365,7 +366,7 @@ export function createWriteFileTool(env, state, rootCanonical, cwdRef, additiona
365
366
  const ipynb = ipynbRedirect("Write", path);
366
367
  if (ipynb)
367
368
  return errorResult(ipynb);
368
- const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
369
+ const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
369
370
  if (!r.ok)
370
371
  return errorResult(violationText("Write", r.violation), violationDetails(r.violation));
371
372
  const exists = await env.exists(r.key, ctx.signal);
@@ -462,7 +463,7 @@ export function createNotebookEditTool(env, state, rootCanonical, cwdRef, additi
462
463
  return { ok: false, code: "invalid", message: NOTEBOOK_CELL_TYPE_REQUIRED_MESSAGE };
463
464
  if (mode !== "insert" && !a.cell_id)
464
465
  return { ok: false, code: "invalid", message: NOTEBOOK_CELL_ID_REQUIRED_MESSAGE };
465
- const r = await resolveKey(env, rootCanonical, a.notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
466
+ const r = await resolveKey(env, rootOf(rootCanonical), a.notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
466
467
  if (!r.ok)
467
468
  return { ok: true };
468
469
  const notRead = requireRead(state, r.key);
@@ -482,7 +483,7 @@ export function createNotebookEditTool(env, state, rootCanonical, cwdRef, additi
482
483
  return errorResult(NOTEBOOK_CELL_TYPE_REQUIRED_MESSAGE);
483
484
  if (mode !== "insert" && !cell_id)
484
485
  return errorResult(NOTEBOOK_CELL_ID_REQUIRED_MESSAGE);
485
- const r = await resolveKey(env, rootCanonical, notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
486
+ const r = await resolveKey(env, rootOf(rootCanonical), notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
486
487
  if (!r.ok)
487
488
  return errorResult(violationText("NotebookEdit", r.violation), violationDetails(r.violation));
488
489
  const notRead = requireRead(state, r.key);
@@ -26,6 +26,9 @@ export interface HandsToolkitOptions {
26
26
  * `bash_readonly` IS constrained by them (that face refuses a read outside the roots), so widening
27
27
  * here widens what the read-only band may read. */
28
28
  additionalRoots?: readonly string[];
29
+ /** The WRITE tools' primary root (edit_file / write_file / notebook_edit), read per call: the leg's write location, which
30
+ * moves with an EnterWorktree switch while the read tools keep `rootCanonical`. Absent ⇒ `rootCanonical` (one root). */
31
+ writeRoot?: () => string;
29
32
  /** The read-boundary whitelist: extra allowed containment roots for the READ faces only —
30
33
  * read_file/grep/glob/repo_map and `bash_readonly` admit them; edit_file/write_file/notebook_edit
31
34
  * and the full `bash`'s disclosure roots deliberately do NOT (widening reads must never silently
@@ -81,7 +81,7 @@ export function createHandsToolkit(env, readFileState, rootCanonical, opts = {})
81
81
  afterPlacement(createReadFileTool(env, readFileState, rootCanonical, readCwd, readFaceRoots, opts.readImageDownsampler, opts.pdfModelCapabilities, bgOutputReadExemption, readDeny, readFace, opts.reminderMark, opts.reminderDisclosureCounts, reader)),
82
82
  ];
83
83
  if (handsWriteHalfMounts({ readOnly })) {
84
- tools.push(createEditFileTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createWriteFileTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createNotebookEditTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
84
+ tools.push(createEditFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createWriteFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createNotebookEditTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
85
85
  }
86
86
  tools.push(afterPlacement(createGrepTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)), afterPlacement(createGlobTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)), afterPlacement(createRepoMapTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)));
87
87
  if (includeShell) {
@@ -12,8 +12,9 @@ export interface PatternKillReading {
12
12
  export declare function patternKillReadings(command: string, cwd: string): PatternKillReading[];
13
13
  /**
14
14
  * The refusal for a command whose pattern-kill would select this agent's own process or one above it — or undefined (run it).
15
- * `cwd`: where the command stands, for the plan's read of its words (nothing is read from disk). Remote environments and
16
- * Windows are not asked: their process table is not this one.
15
+ * `cwd`: where the command stands, for the plan's read of its words (nothing is read from disk). Where the question is put is
16
+ * the env's own declaration ({@link processTableOf}): this process's table is asked, another table is not, and an env that does
17
+ * not say is refused. Windows is not asked: this process's table is not read there.
17
18
  */
18
19
  export declare function patternKillRefusal(command: string, env: ExecutionEnv, cwd: string, signal?: AbortSignal): Promise<{
19
20
  content: string;
@@ -1,15 +1,18 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { errorResult } from "../../core/tools.js";
4
- import { isRemoteExecutionEnv } from "../../core/remote-env.js";
4
+ import { processTableOf } from "../../core/remote-env.js";
5
5
  import { inheritedHostEnv } from "../../core/secret-env.js";
6
6
  import { inlineUntrusted } from "../../core/untrusted-text.js";
7
7
  import { planShellReads } from "./shell-read-plan.js";
8
8
  import { programArgs } from "./shell-read-write-targets.js";
9
9
  const PROBE_TIMEOUT_MS = 5_000;
10
10
  const ANCESTOR_HOPS_MAX = 128;
11
- const SHELL_PID_WORD = /^\$(?:\$|\{\$\}|BASHPID|\{BASHPID\})$/;
11
+ const SHELL_PID_SPELLING = String.raw `\$(?:\$|\{\$\})`;
12
+ const SHELL_PID_WORD = new RegExp(`^${SHELL_PID_SPELLING}$`);
13
+ const SHELL_PID_EXPANSION = new RegExp(SHELL_PID_SPELLING, "g");
12
14
  const NAME_SELECTION_KEEPS_ANCESTORS = process.platform === "linux" ? [] : ["-a"];
15
+ const OPTIONS_END_AT_FIRST_OPERAND = process.platform !== "linux";
13
16
  const SIGNAL_ONLY_FIRST_ARGUMENT = process.platform !== "linux";
14
17
  const HANDLER_SELECTS_BY_SIGNAL = process.platform === "linux";
15
18
  const LONG_OPTIONS = new Map([
@@ -54,21 +57,28 @@ const isSignalWord = (w) => {
54
57
  const m = SIGNAL_WORD.exec(w);
55
58
  return m !== null && (m[1] === undefined || SIGNAL_NAMES.has(m[1].toUpperCase()));
56
59
  };
57
- function selectorWords(allWords, killer) {
60
+ function readSelection(allWords, killer) {
58
61
  const signalAt = killer !== "pkill" ? -1 : SIGNAL_ONLY_FIRST_ARGUMENT ? (isSignalWord(allWords[0] ?? "") ? 0 : -1) : allWords.findIndex(isSignalWord);
59
62
  const signalWord = signalAt < 0 ? undefined : allWords[signalAt].slice(1);
60
63
  const words = signalAt < 0 ? allWords : allWords.filter((_, i) => i !== signalAt);
61
64
  const out = [];
65
+ const parentLists = [];
62
66
  let ended = false;
63
67
  let requireHandler = false;
68
+ let negated = false;
64
69
  let signalOption;
65
70
  let valueOf;
71
+ const valueGiven = (key, value) => {
72
+ if (key === "P")
73
+ parentLists.push(value.split(","));
74
+ };
66
75
  for (const w of words) {
67
76
  if (valueOf !== undefined) {
68
- if (valueOf === "ask")
77
+ if (valueOf.fate === "ask")
69
78
  out.push(w);
70
- else if (valueOf === "signal")
79
+ else if (valueOf.fate === "signal")
71
80
  signalOption = w;
81
+ valueGiven(valueOf.key, w);
72
82
  valueOf = undefined;
73
83
  continue;
74
84
  }
@@ -82,60 +92,75 @@ function selectorWords(allWords, killer) {
82
92
  if (key !== undefined && (takesValueKey(key) || longValue === undefined)) {
83
93
  if (key === "H")
84
94
  requireHandler = true;
95
+ if (key === "v")
96
+ negated = true;
85
97
  const fate = fateOfKey(key);
86
98
  if (fate === "ask")
87
99
  out.push(w);
88
100
  if (takesValueKey(key) && longValue === undefined)
89
- valueOf = fate;
90
- else if (fate === "signal" && longValue !== undefined)
91
- signalOption = longValue;
101
+ valueOf = { fate, key };
102
+ else if (longValue !== undefined) {
103
+ if (fate === "signal")
104
+ signalOption = longValue;
105
+ valueGiven(key, longValue);
106
+ }
92
107
  continue;
93
108
  }
94
109
  const letters = bundledLetters(w);
95
110
  if (letters === undefined) {
96
111
  out.push(w);
112
+ if (OPTIONS_END_AT_FIRST_OPERAND && (w === "-" || !w.startsWith("-")))
113
+ ended = true;
97
114
  continue;
98
115
  }
99
116
  if (letters.includes("H"))
100
117
  requireHandler = true;
118
+ if (letters.includes("v"))
119
+ negated = true;
101
120
  const last = letters[letters.length - 1];
102
121
  const fate = fateOfKey(last);
103
122
  const kept = letters.filter((ch) => fateOfKey(ch) === "ask").join("");
104
123
  const attached = VALUED_LETTERS.has(last) ? w.slice(1 + letters.length) : "";
105
124
  if (kept !== "")
106
125
  out.push(`-${kept}${fate === "ask" ? attached : ""}`);
107
- if (VALUED_LETTERS.has(last) && attached === "")
108
- valueOf = fate;
126
+ if (VALUED_LETTERS.has(last)) {
127
+ if (attached === "")
128
+ valueOf = { fate, key: last };
129
+ else
130
+ valueGiven(last, attached);
131
+ }
109
132
  }
110
133
  const signal = signalOption ?? signalWord;
111
- return HANDLER_SELECTS_BY_SIGNAL && requireHandler && signal !== undefined ? ["--signal", signal, ...out] : out;
134
+ return { words: HANDLER_SELECTS_BY_SIGNAL && requireHandler && signal !== undefined ? ["--signal", signal, ...out] : out, parentLists, negated };
112
135
  }
113
- const negatesSelection = (words) => words.some((w) => w === "--inverse" || (bundledLetters(w)?.includes("v") ?? false));
114
- function selectsOnlyShellChildren(words) {
115
- return words.some((w, i) => {
116
- if (w === "-P" || w === "--parent")
117
- return SHELL_PID_WORD.test(words[i + 1] ?? "");
118
- const attached = /^(?:-P|--parent=)(.+)$/.exec(w);
119
- return attached !== null && SHELL_PID_WORD.test(attached[1]);
120
- });
136
+ const LAST_PARENT_LIST_WINS = process.platform === "linux";
137
+ function boundedToShellChildren(read, unread) {
138
+ if (unread !== undefined)
139
+ return false;
140
+ const standing = LAST_PARENT_LIST_WINS ? read.parentLists.slice(-1) : read.parentLists;
141
+ return standing.length > 0 && standing.every((list) => list.every((pid) => SHELL_PID_WORD.test(pid)));
121
142
  }
122
143
  const literalName = (name) => name.replace(/[\\.[\]{}()*+?^$|]/g, "\\$&");
123
144
  function wordsOf(segment) {
124
145
  const args = programArgs(segment);
125
- const rewritten = args.find((a) => a.rewritten === true);
126
- const computed = segment.reentry === "argv" ? "its arguments arrive on a stream" : rewritten === undefined ? undefined : `\`${inlineUntrusted(rewritten.raw, 60)}\` is expanded by the shell when the command runs`;
127
- return { words: args.map((a) => a.spelled), ...(computed !== undefined ? { computed } : {}) };
146
+ const expands = (a) => `\`${inlineUntrusted(a.raw, 60)}\` is expanded by the shell when the command runs`;
147
+ const stream = segment.reentry === "argv" ? "its arguments arrive on a stream" : undefined;
148
+ const opaque = args.find((a) => a.rewritten === true && /[$`*?[~{\\]/.test(a.raw.replace(SHELL_PID_EXPANSION, "0")));
149
+ const first = args.find((a) => a.rewritten === true);
150
+ const unread = stream ?? (opaque === undefined ? undefined : expands(opaque));
151
+ const computed = unread ?? (first === undefined ? undefined : expands(first));
152
+ return { words: args.map((a) => a.spelled), ...(computed !== undefined ? { computed } : {}), ...(unread !== undefined ? { unread } : {}) };
128
153
  }
129
154
  const shown = (segment) => inlineUntrusted(segment.text, 200);
130
155
  function readPkill(segment) {
131
- const { words, computed } = wordsOf(segment);
132
- if (selectsOnlyShellChildren(words)) {
133
- return negatesSelection(words) ? { text: shown(segment), probes: [], computed: "`-v` negates the selection, so `-P` of the shell's pid no longer limits it to the shell's children" } : undefined;
156
+ const { words, computed, unread } = wordsOf(segment);
157
+ const read = readSelection(words, "pkill");
158
+ if (boundedToShellChildren(read, unread)) {
159
+ return read.negated ? { text: shown(segment), probes: [], computed: "the selection is negated (`-v` / `--inverse`), so `-P` of the shell's pid no longer limits it to the shell's children" } : undefined;
134
160
  }
135
161
  if (computed !== undefined)
136
162
  return { text: shown(segment), probes: [], computed };
137
- const selectors = selectorWords(words, "pkill");
138
- return selectors.length === 0 ? undefined : { text: shown(segment), probes: [selectors] };
163
+ return read.words.length === 0 ? undefined : { text: shown(segment), probes: [read.words] };
139
164
  }
140
165
  const OPT_FLAG = { does: "flag" };
141
166
  const OPT_FILTER = { does: "filter" };
@@ -157,7 +182,6 @@ const KILLALL_OPTIONS = new Map([
157
182
  ["-v", OPT_FLAG], ["--verbose", OPT_FLAG], ["-V", OPT_FLAG], ["--version", OPT_FLAG], ["-w", OPT_FLAG], ["--wait", OPT_FLAG], ["-d", OPT_FLAG], ["-z", OPT_FLAG], ["--help", OPT_FLAG],
158
183
  ]);
159
184
  const takesValue = (opt) => opt !== undefined && (opt.does === "select" || opt.does === "context" || opt.does === "filter" || opt.does === "valued");
160
- const OPTIONS_END_AT_FIRST_NAME = process.platform !== "linux";
161
185
  const KILLALL_VALUED_LETTERS = new Set([...KILLALL_OPTIONS].filter(([spelling, opt]) => !spelling.startsWith("--") && takesValue(opt)).map(([spelling]) => spelling.slice(1)));
162
186
  function optionsOf(w) {
163
187
  if (w.startsWith("--")) {
@@ -185,7 +209,7 @@ function readKillallWords(words) {
185
209
  }
186
210
  if (!w.startsWith("-") || w === "-") {
187
211
  names.push(w);
188
- if (OPTIONS_END_AT_FIRST_NAME) {
212
+ if (OPTIONS_END_AT_FIRST_OPERAND) {
189
213
  names.push(...words.slice(i + 1));
190
214
  break;
191
215
  }
@@ -238,7 +262,7 @@ function readSelector(segment) {
238
262
  const names = read.words.filter((w, i) => !w.startsWith("-") && read.words[i - 1] !== "-o");
239
263
  return { text: shown(segment), probes: names.map((n) => [...NAME_SELECTION_KEEPS_ANCESTORS, "-x", literalName(n)]) };
240
264
  }
241
- return { text: shown(segment), probes: [selectorWords(read.words, "pgrep")] };
265
+ return { text: shown(segment), probes: [readSelection(read.words, "pgrep").words] };
242
266
  }
243
267
  const SELECTORS = new Set(["pgrep", "pidof"]);
244
268
  const EVERY_PROCESS_PID = /^-0*1$/;
@@ -358,12 +382,8 @@ const SENTENCE = {
358
382
  computed: (f) => `Error (Bash): refusing to run \`${f.text}\` — which processes it selects is decided when the command runs (${f.why}), so it cannot first be checked against this agent's own process and the processes above it. Write the pattern into the command as a literal, ${WAY_OUT}.`,
359
383
  unavailable: (f) => `Error (Bash): refusing to run \`${f.text}\` — the check that its selection holds neither this agent's own process nor a process above it could not run (${f.why}). Stop the process by its PID, or target your own children with \`pkill -P $$ ...\`.`,
360
384
  };
361
- export async function patternKillRefusal(command, env, cwd, signal) {
362
- if (process.platform === "win32" || isRemoteExecutionEnv(env))
363
- return undefined;
364
- const readings = patternKillReadings(command, cwd);
365
- if (readings.length === 0)
366
- return undefined;
385
+ const UNDECLARED_TABLE = "the execution environment does not declare whether its commands run on this agent's process table — `capabilities.sharesProcessTable` is missing or not a boolean";
386
+ async function findingsOnThisTable(readings, signal) {
367
387
  const found = [];
368
388
  const asked = await Promise.all(readings.map(async (r) => ({ r, answers: await Promise.all(r.probes.map((p) => selected(p, signal))) })));
369
389
  let ancestry;
@@ -389,6 +409,18 @@ export async function patternKillRefusal(command, env, cwd, signal) {
389
409
  found.push({ kind: "hit", text: r.text, pid, own: pid === process.pid });
390
410
  }
391
411
  }
412
+ return found;
413
+ }
414
+ export async function patternKillRefusal(command, env, cwd, signal) {
415
+ if (process.platform === "win32")
416
+ return undefined;
417
+ const readings = patternKillReadings(command, cwd).filter((r) => r.probes.length > 0 || r.computed !== undefined || r.everyProcess === true);
418
+ if (readings.length === 0)
419
+ return undefined;
420
+ const table = processTableOf(env);
421
+ if (table === "other")
422
+ return undefined;
423
+ const found = table === "this" ? await findingsOnThisTable(readings, signal) : [{ kind: "unavailable", text: readings[0].text, why: UNDECLARED_TABLE }];
392
424
  const f = found.find((x) => x.kind === "hit") ?? found.find((x) => x.kind === "computed") ?? found[0];
393
425
  if (f === undefined || signal?.aborted === true)
394
426
  return undefined;
@@ -444,7 +444,7 @@ function within(rootCanonical, p) {
444
444
  }
445
445
  export async function resolveKey(env, rootCanonical, path, signal, baseCwd, additionalRoots, exactFileReadExemption, readDeny, containmentFace) {
446
446
  const views = await readPath(env, path, baseCwd ?? rootCanonical, { root: rootCanonical, ...(baseCwd !== undefined ? { cwd: baseCwd } : {}) }, { intent: "resolve", views: readDeny !== undefined ? "chain" : "canonical" }, signal);
447
- const canon = views.canonical ?? (await canonicalizeTarget(env, path, signal, pathFamilyOf({ root: rootCanonical }), baseCwd));
447
+ const canon = views.canonical ?? { ok: false, message: `cannot resolve path "${clipSpelling(path)}": ${views.lexical?.kind === "unreadable" ? views.lexical.reason : "the environment was not asked where it lands"}; refused.` };
448
448
  if (!canon.ok)
449
449
  return { ok: false, violation: { code: "invalid", message: canon.message } };
450
450
  const key = canon.key;
@@ -545,6 +545,10 @@ async function probeRealTarget(env, path, target, family, signal) {
545
545
  if (!newPath.ok) {
546
546
  return { ok: false, message: newPath.message, unresolvedSymlink: true };
547
547
  }
548
+ if ("reprobe" in newPath) {
549
+ abs = newPath.reprobe;
550
+ continue;
551
+ }
548
552
  return { ok: true, key: newPath.key };
549
553
  }
550
554
  const canon = await env.canonicalPath(abs, signal);
@@ -559,6 +563,10 @@ async function probeRealTarget(env, path, target, family, signal) {
559
563
  if (!viaAncestors.ok) {
560
564
  return { ok: false, message: viaAncestors.message, unresolvedSymlink: true };
561
565
  }
566
+ if ("reprobe" in viaAncestors) {
567
+ abs = viaAncestors.reprobe;
568
+ continue;
569
+ }
562
570
  return { ok: true, key: viaAncestors.key };
563
571
  }
564
572
  if (!env.readLink) {
@@ -584,7 +592,7 @@ async function probeRealTarget(env, path, target, family, signal) {
584
592
  }
585
593
  abs = reabs.value;
586
594
  }
587
- return { ok: false, message: `symlink chain for "${path}" exceeded the hop cap; target unresolved`, unresolvedSymlink: true };
595
+ return { ok: false, message: `resolving "${path}" exceeded the hop cap (links followed, or a \`..\` back into an existing directory re-probed); target unresolved`, unresolvedSymlink: true };
588
596
  }
589
597
  function parentDir(abs) {
590
598
  const i = lastSepIndex(abs);
@@ -623,15 +631,39 @@ async function canonicalizeNewPath(env, abs, family, signal, opts) {
623
631
  if (!canon.ok) {
624
632
  return { ok: false, message: `cannot canonicalize existing ancestor "${candidate}": ${canon.error.message}` };
625
633
  }
626
- const tailSegments = tail.reverse();
627
- const canonSep = nativeSepOf(canon.value);
628
- if (tailSegments.length === 0)
629
- return { ok: true, key: canon.value };
630
- return { ok: true, key: [canon.value.replace(family === "win" ? /[\\/]+$/ : /\/+$/, ""), ...tailSegments].join(canonSep) };
634
+ return { ok: true, ...rejoinMissingTail(canon.value, tail.reverse(), family) };
631
635
  }
632
636
  tail.push(parts.pop());
633
637
  }
634
- return { ok: true, key: abs };
638
+ const share = family === "win" && isUncSpelling(abs) ? tail.pop() : undefined;
639
+ return { ok: true, ...rejoinMissingTail(`${[...parts, ...(share !== undefined ? [share] : [])].join(sep)}${sep}`, tail.reverse(), family) };
640
+ }
641
+ function rejoinMissingTail(canonical, tail, family) {
642
+ const trimmed = (at) => at.replace(family === "win" ? /[\\/]+$/ : /\/+$/, "");
643
+ let at = canonical;
644
+ const names = [];
645
+ for (let i = 0; i < tail.length; i++) {
646
+ const seg = tail[i];
647
+ if (seg === "" || seg === ".")
648
+ continue;
649
+ if (seg !== "..")
650
+ names.push(seg);
651
+ else if (names.length > 1)
652
+ names.pop();
653
+ else {
654
+ if (names.length === 1)
655
+ names.pop();
656
+ else {
657
+ const up = normalizeAbsPathLexically(`${at}/..`);
658
+ if (up !== normalizeAbsPathLexically(at))
659
+ at = up;
660
+ }
661
+ const rest = tail.slice(i + 1);
662
+ if (rest.some((s) => s !== "" && s !== "."))
663
+ return { reprobe: [trimmed(at), ...rest].join(nativeSepOf(at)) };
664
+ }
665
+ }
666
+ return { key: names.length === 0 ? at : [trimmed(at), ...names].join(nativeSepOf(at)) };
635
667
  }
636
668
  export function violationText(toolName, v) {
637
669
  return `Error (${toolName}): ${v.message}`;
@@ -40,25 +40,6 @@ const TYPE_GLOBS = {
40
40
  css: "*.{css,scss,less}",
41
41
  };
42
42
  const basename = (p) => p.slice(Math.max(p.lastIndexOf("/"), p.lastIndexOf("\\")) + 1);
43
- function collapseDotSegments(p) {
44
- const win = isWinFormPath(p);
45
- const lead = (win ? /^[\\/]*/ : /^\/*/).exec(p)?.[0] ?? "";
46
- const sep = win ? "\\" : "/";
47
- const parts = p.slice(lead.length).split(win ? /[\\/]+/ : /\/+/);
48
- const floor = !win ? 0 : lead.length >= 2 ? 2 : /^[A-Za-z]:$/.test(parts[0] ?? "") ? 1 : 0;
49
- const kept = [];
50
- for (const part of parts) {
51
- if (part === "" || part === ".")
52
- continue;
53
- if (part === "..") {
54
- if (kept.length > floor)
55
- kept.pop();
56
- continue;
57
- }
58
- kept.push(part);
59
- }
60
- return kept.length === 0 ? "" : lead + kept.join(sep);
61
- }
62
43
  const NO_MATCHES = "No matches.";
63
44
  const GREP_LINE_CLIP = 500;
64
45
  function clipLine(line) {
@@ -813,18 +794,19 @@ export async function jsGrepDetailed(env, root, p, signal, guards, deny, denyOut
813
794
  const mode = p.output_mode ?? "files_with_matches";
814
795
  const rel = (abs) => (abs.startsWith(rootPrefix) ? abs.slice(rootPrefix.length) : abs);
815
796
  const startWin = isWinFormPath(start);
816
- const startNorm = collapseDotSegments(start);
817
- const targetSpell = p.path ? p.path.replace(startWin ? /[\\/]+$/ : /\/+$/, "") : "";
797
+ const trailingSeparators = startWin ? /[\\/]+$/ : /\/+$/;
798
+ const anchor = start.replace(trailingSeparators, "");
799
+ const targetSpell = p.path ? p.path.replace(trailingSeparators, "") : "";
818
800
  const isBoundary = (c) => c === "/" || (startWin && c === "\\");
819
801
  const relOut = (abs) => {
820
802
  if (!p.path) {
821
803
  const r = rel(abs);
822
804
  return r === abs ? r : `./${r}`;
823
805
  }
824
- if (abs === startNorm || abs === start)
806
+ if (abs === start || abs === anchor)
825
807
  return targetSpell;
826
- if (abs.startsWith(startNorm) && isBoundary(abs[startNorm.length]))
827
- return targetSpell + abs.slice(startNorm.length);
808
+ if (abs.startsWith(anchor) && isBoundary(abs[anchor.length]))
809
+ return targetSpell + abs.slice(anchor.length);
828
810
  return rel(abs);
829
811
  };
830
812
  if (p.glob) {
@@ -20,6 +20,7 @@
20
20
  import type { ExecutionEnv } from "../../internal/harness-types.js";
21
21
  import { violationDetails } from "./safety.js";
22
22
  import { type ShellReadPlan } from "./shell-read-plan.js";
23
+ import { type ReadLanding } from "./shell-read-identity.js";
23
24
  import { type HomeViewSource } from "./read-deny-home.js";
24
25
  import { type EstablishedRead, type ShellReadBoundary, type ShellReadDisposition, type ShellReadFinding, type ShellReadSeat } from "./shell-read-judge.js";
25
26
  import type { ReadRootGrantCandidate } from "../../core/tool-spec.js";
@@ -104,8 +105,15 @@ export interface ShellReadVerdictFacts {
104
105
  readonly writesPlaced?: true;
105
106
  /** A FACT beside the disposition: a write target this command names lands on the write-protection table — judged by
106
107
  * the table's own judge, as a write tool's target is — so the command's ask carries that table's class, whichever
107
- * mode reads it. Absent ⇒ no target the station established is covered (or no judge is mounted). */
108
+ * mode reads it. Absent ⇒ no target the station established is covered (or no judge is mounted). Said of a target whose
109
+ * TEXT names the row (the table's spelling view of one of its spellings); a covered target whose text names none is the
110
+ * member below — one target, one of the two. */
108
111
  readonly writeProtected?: true;
112
+ /** A FACT beside the disposition: a write target this command names meets the write-protection table only where it resolves
113
+ * on disk (its real target, a link on the way) — none of the target's spellings names a row — so the command's ask carries
114
+ * that reading's class, which the auto-mode classifier does not answer. Beside `writeProtected` when another target's text
115
+ * names a row. Absent ⇒ no such target (or no judge is mounted). */
116
+ readonly writeProtectedOnDisk?: true;
109
117
  /** A FACT beside the disposition: a target this command's program WRITES was placed and the environment could not say
110
118
  * where it leads ({@link EstablishedRead.unresolved}) — the reading's `target_unresolved` fact, the same one a write
111
119
  * tool's unresolved target states, so the command's ask carries that class (no automatic lane answers it; the shell face
@@ -169,9 +177,18 @@ export type ShellReadAdmission = (toolName: string, toolCallId: string | undefin
169
177
  isError: true;
170
178
  details?: unknown;
171
179
  } | undefined>;
180
+ /** Where the station's last non-refused judgment of a call found its reads land (`readLandingsOf`): the judgment its
181
+ * admission holds for the call id — the one the spawn re-establishes — read without consuming it. `undefined` ⇒ the
182
+ * station holds none (a refused judgment records nothing). Its readers take it right where the latest judgment is a
183
+ * non-refused one of the bytes they hold: the park when the filed bytes are the judged ones, the resumed leg's execution
184
+ * station after its belt. A judgment that settles after a newer one replaced it is what the spawn would re-establish too:
185
+ * the spawn then refuses bytes the entry does not describe, and a row bound to it vetoes the resume wherever the two
186
+ * commands' reads differ (fail-closed either way). */
187
+ export type ShellReadLandings = (toolCallId: string) => readonly ReadLanding[] | undefined;
172
188
  export interface ShellReadStation {
173
189
  readonly check: ShellReadCheck;
174
190
  readonly admit: ShellReadAdmission;
191
+ readonly landings: ShellReadLandings;
175
192
  }
176
193
  export interface ShellReadStationOptions {
177
194
  readonly env: ExecutionEnv;