@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
@@ -1,24 +1,42 @@
1
1
  import { authSchemeCredentials, credentialHeaderValues, holdOwnCredentialValues } from "./secret-env.js";
2
- import { readMember } from "./thrown-value.js";
2
+ import { egressText } from "./untrusted-egress.js";
3
+ import { REDACTION_MARK, redactionMarkerSpans } from "./redaction-marks.js";
3
4
  import { inlineUntrusted } from "./untrusted-text.js";
4
- export function headerOwnershipCollision(t) {
5
+ export const MCP_ASSERTION_HEADER = "connector-assertion";
6
+ const PROTOCOL_OWNED_HEADERS = Object.freeze({
7
+ mcp: Object.freeze(["mcp-session-id", "mcp-protocol-version", "content-type", "accept", "last-event-id"]),
8
+ a2a: Object.freeze([]),
9
+ });
10
+ const ENGINE_OWNED_HEADERS = new Map([[MCP_ASSERTION_HEADER.toLowerCase(), MCP_ASSERTION_HEADER]]);
11
+ export function headerOwnershipCollision(t, protocol) {
5
12
  const owners = new Map();
6
- for (const name of [...Object.keys(t.headers ?? {}), ...(t.principalHeader ? [t.principalHeader] : [])]) {
7
- const prior = owners.get(name.toLowerCase());
13
+ const protocolOwned = PROTOCOL_OWNED_HEADERS[protocol];
14
+ const principalHeader = t.principalHeader ? [t.principalHeader] : [];
15
+ for (const name of [...Object.keys(t.headers ?? {}), ...principalHeader]) {
16
+ const folded = name.toLowerCase();
17
+ if (protocolOwned.includes(folded))
18
+ return { first: folded, second: name, engineOwned: true };
19
+ const engine = ENGINE_OWNED_HEADERS.get(folded);
20
+ if (engine !== undefined && principalHeader[0] === name)
21
+ return { first: engine, second: name, engineOwned: true };
22
+ const prior = owners.get(folded);
8
23
  if (prior !== undefined)
9
- return { first: prior, second: name };
10
- owners.set(name.toLowerCase(), name);
24
+ return { first: prior, second: name, engineOwned: false };
25
+ owners.set(folded, name);
11
26
  }
12
27
  return undefined;
13
28
  }
14
29
  export function resolveProtocolHttpHeaders(protocol, t, principal) {
15
30
  const principalHeader = t.principalHeader;
16
- const declared = t.headers;
17
- const own = { ...(declared !== undefined ? { headers: { ...declared } } : {}), ...(principalHeader !== undefined ? { principalHeader } : {}) };
31
+ const answered = t.headers;
32
+ const own = { ...(answered !== undefined ? { headers: { ...answered } } : {}), ...(principalHeader !== undefined ? { principalHeader } : {}) };
18
33
  holdOwnCredentialValues(credentialHeaderValues(own.headers));
19
- const collision = headerOwnershipCollision(own);
34
+ const collision = headerOwnershipCollision(own, protocol);
20
35
  if (collision !== undefined) {
21
- throw Object.assign(new Error(`${protocol}: the declaration names the header "${inlineUntrusted(collision.first, 80)}" twice ("${inlineUntrusted(collision.second, 80)}" — header names are case-insensitive); ${principalHeader !== undefined && collision.second === principalHeader ? "the principal header is the engine's to send, so remove the static entry" : "keep one spelling"} — this peer is not dialed`), { code: "config.protocol_header_collision" });
36
+ const problem = collision.engineOwned
37
+ ? `the header "${inlineUntrusted(collision.second, 80)}" is the ${PROTOCOL_OWNED_HEADERS[protocol].includes(collision.first) ? "protocol's own" : "engine's"} ${collision.first} header (header names are case-insensitive) and not ${principalHeader !== undefined && collision.second === principalHeader ? "the principal header's name" : "a header an answer may set"} — remove it`
38
+ : `the header "${inlineUntrusted(collision.first, 80)}" is named twice ("${inlineUntrusted(collision.second, 80)}" — header names are case-insensitive); ${principalHeader !== undefined && collision.second === principalHeader ? "the principal header is the engine's to send, so the answer may not set it" : "keep one spelling"}`;
39
+ throw Object.assign(new Error(`${protocol}: ${problem} — this peer is not dialed`), { code: "config.protocol_header_collision" });
22
40
  }
23
41
  if (principalHeader && principal !== undefined) {
24
42
  if (/[\r\n]/.test(principal))
@@ -32,24 +50,6 @@ export function underDeclaredHeaders(defaults, declared) {
32
50
  return { ...Object.fromEntries(Object.entries(defaults).filter(([k]) => !owned.has(k.toLowerCase()))), ...declared };
33
51
  }
34
52
  const httpTrimmed = (value) => value.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
35
- export function declaredHeaderValues(transport, principal) {
36
- const out = new Set();
37
- try {
38
- const headers = readMember(transport, "headers");
39
- if (typeof headers === "object" && headers !== null) {
40
- for (const value of Object.values(headers))
41
- if (typeof value === "string")
42
- out.add(value);
43
- }
44
- }
45
- catch {
46
- }
47
- const principalHeader = readMember(transport, "principalHeader");
48
- if (typeof principalHeader === "string" && principalHeader !== "" && principal !== undefined)
49
- out.add(principal);
50
- out.delete("");
51
- return [...out];
52
- }
53
53
  function percentEncoded(value) {
54
54
  try {
55
55
  return encodeURIComponent(value);
@@ -72,7 +72,6 @@ function requestEchoSpellings(value) {
72
72
  }
73
73
  return [...spellings];
74
74
  }
75
- const ECHO_MARKER = "[redacted]";
76
75
  const COOKIE_START = String.raw `(?<![\w-])(?<cookie>(?:[Ss][Ee][Tt]-)?[Cc][Oo][Oo][Kk][Ii][Ee])(?<quote>["']?)[ \t]*:`;
77
76
  function stringEnd(text, at) {
78
77
  for (let i = at + 1; i < text.length; i++) {
@@ -106,17 +105,7 @@ function structuredEnd(text, at) {
106
105
  return text.length;
107
106
  }
108
107
  export function scrubRequestEcho(text, declared) {
109
- const forms = new Set();
110
- for (const value of declared)
111
- for (const spelling of requestEchoSpellings(value))
112
- forms.add(spelling);
113
- forms.delete("");
114
- const members = cookieMembers(text);
115
- const removed = members.map(([, from, end]) => [from, end]);
116
- for (const hit of valueHits(text, [...forms])) {
117
- if (!members.some(([name, from]) => hit[0] >= name && hit[1] <= from))
118
- removed.push(hit);
119
- }
108
+ const removed = requestEchoRanges(text, declared);
120
109
  if (removed.length === 0)
121
110
  return text;
122
111
  removed.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
@@ -127,11 +116,51 @@ export function scrubRequestEcho(text, declared) {
127
116
  kept = Math.max(kept, end);
128
117
  continue;
129
118
  }
130
- out += text.slice(kept, start) + ECHO_MARKER;
119
+ out += text.slice(kept, start) + REDACTION_MARK;
131
120
  kept = end;
132
121
  }
133
122
  return out + text.slice(kept);
134
123
  }
124
+ function requestEchoRanges(text, declared) {
125
+ const forms = new Set();
126
+ for (const value of declared)
127
+ for (const spelling of requestEchoSpellings(value))
128
+ forms.add(spelling);
129
+ forms.delete("");
130
+ const members = cookieMembers(text);
131
+ const removed = members.map(([, from, end]) => [from, end]);
132
+ const markers = redactionMarkerSpans(text);
133
+ for (const hit of valueHits(text, [...forms])) {
134
+ if (members.some(([name, from]) => hit[0] >= name && hit[1] <= from))
135
+ continue;
136
+ if (markers.some(([from, end]) => hit[0] >= from && hit[1] <= end))
137
+ continue;
138
+ const reach = markers.filter(([from, end]) => hit[0] < end && hit[1] > from);
139
+ removed.push([Math.min(hit[0], ...reach.map(([from]) => from)), Math.max(hit[1], ...reach.map(([, end]) => end))]);
140
+ }
141
+ return removed;
142
+ }
143
+ function vocabularyValues(text) {
144
+ const report = { findings: [] };
145
+ egressText("same-principal", text, report);
146
+ return report.findings.map(({ span: [from, end] }) => {
147
+ const found = text.slice(from, end);
148
+ const rendered = egressText("same-principal", found);
149
+ let head = 0;
150
+ while (head < found.length && head < rendered.length && found[head] === rendered[head])
151
+ head++;
152
+ let tail = 0;
153
+ while (tail < found.length - head && tail < rendered.length - head && found[found.length - 1 - tail] === rendered[rendered.length - 1 - tail])
154
+ tail++;
155
+ const value = found.slice(head, found.length - tail);
156
+ return value === "" ? found : value;
157
+ });
158
+ }
159
+ export function remoteWords(text, declared) {
160
+ if (requestEchoRanges(text, declared).length === 0)
161
+ return egressText("same-principal", text);
162
+ return egressText("same-principal", scrubRequestEcho(text, [...declared, ...vocabularyValues(text)]));
163
+ }
135
164
  function cookieMembers(text) {
136
165
  const members = [];
137
166
  const pattern = new RegExp(COOKIE_START, "g");
@@ -176,5 +205,5 @@ export function assertEndpointBound(protocol, peer, endpoint, declared, headers)
176
205
  const at = new URL(endpoint).origin;
177
206
  if (origins.includes(at))
178
207
  return;
179
- throw Object.assign(new Error(`${protocol}: peer "${inlineUntrusted(peer, 80)}" advertises the endpoint origin ${inlineUntrusted(at, 120)}, outside the origins its declaration names (${origins.map((o) => inlineUntrusted(o, 120)).join(", ")}); the declared headers travel only to those — declare that origin as the peer's url (and the card's location as cardUrl) or drop the headers`), { code: "config.protocol_endpoint_unbound" });
208
+ throw Object.assign(new Error(`${protocol}: peer "${inlineUntrusted(peer, 80)}" advertises the endpoint origin ${inlineUntrusted(at, 120)}, outside the origins its declaration names (${origins.map((o) => inlineUntrusted(o, 120)).join(", ")}); the headers the peer seat answers travel only to those — declare that origin as the peer's url (and the card's location as cardUrl) or have the seat answer none for it`), { code: "config.protocol_endpoint_unbound" });
180
209
  }
@@ -60,6 +60,26 @@ export declare function findNamespacePrefixCollision(ns: ProtocolNamespace, peer
60
60
  prefix: string;
61
61
  peers: [string, string];
62
62
  } | undefined;
63
+ /**
64
+ * EVERY peer in `peers` that mints a {@link mintNamespacePrefix} an earlier peer already minted, in list order, each paired with the
65
+ * FIRST peer that holds the prefix — empty when every peer owns its own. {@link findNamespacePrefixCollision} is its first row: one
66
+ * piece of arithmetic answers both the question "is there a collision" and the question "which names, all of them".
67
+ */
68
+ export declare function findNamespacePrefixCollisions(ns: ProtocolNamespace, peers: readonly string[]): Array<{
69
+ prefix: string;
70
+ peers: [string, string];
71
+ }>;
72
+ /**
73
+ * One peer's claim ledger for tool names: the function it returns takes a REMOTE tool name, mints its wire name
74
+ * ({@link mintNamespacedToolName}) and answers `{ minted }` when the name is free, or `{ minted, heldBy }` when an earlier call
75
+ * already minted it — `heldBy` is the RAW name that took it first (it keeps the name; the ledger never re-binds). A listing's
76
+ * intake and a judge over declared names ask the same ledger; `heldBy === tool` (the same raw name again) stays distinguishable
77
+ * from two different raw names that folded together.
78
+ */
79
+ export declare function createToolNameClaims(ns: ProtocolNamespace, peer: string): (tool: string) => {
80
+ minted: string;
81
+ heldBy?: string;
82
+ };
63
83
  /**
64
84
  * The full registered name for `(peer, tool)` in `ns`. Always starts with {@link mintNamespacePrefix}'s
65
85
  * answer for the same peer (the invariant ticket #9's pins hold), and never exceeds
@@ -27,15 +27,32 @@ export function mintNamespacePrefix(ns, peer) {
27
27
  return `${ns.prefix}${settlePeerSegment(clampNameSegment(normalizeNameSegment(peer), peerBudget))}${NAME_SEP}`;
28
28
  }
29
29
  export function findNamespacePrefixCollision(ns, peers) {
30
+ return findNamespacePrefixCollisions(ns, peers)[0];
31
+ }
32
+ export function findNamespacePrefixCollisions(ns, peers) {
30
33
  const seen = new Map();
34
+ const collisions = [];
31
35
  for (const peer of peers) {
32
36
  const prefix = mintNamespacePrefix(ns, peer);
33
37
  const first = seen.get(prefix);
34
- if (first !== undefined)
35
- return { prefix, peers: [first, peer] };
38
+ if (first !== undefined) {
39
+ collisions.push({ prefix, peers: [first, peer] });
40
+ continue;
41
+ }
36
42
  seen.set(prefix, peer);
37
43
  }
38
- return undefined;
44
+ return collisions;
45
+ }
46
+ export function createToolNameClaims(ns, peer) {
47
+ const held = new Map();
48
+ return (tool) => {
49
+ const minted = mintNamespacedToolName(ns, peer, tool);
50
+ const heldBy = held.get(minted);
51
+ if (heldBy !== undefined)
52
+ return { minted, heldBy };
53
+ held.set(minted, tool);
54
+ return { minted };
55
+ };
39
56
  }
40
57
  export function mintNamespacedToolName(ns, peer, tool) {
41
58
  const prefix = mintNamespacePrefix(ns, peer);
@@ -8,6 +8,20 @@ export type ReadOnlyShellVerdict = {
8
8
  readonly readOnly: false;
9
9
  readonly reason: string;
10
10
  };
11
+ /** How a caller asks: a shape it already read, the session's working directory, the whole line's descriptor
12
+ * bindings when it judges one segment of a longer line, and the deployment's programs. */
13
+ export interface ReadOnlyShellOptions {
14
+ /** The command already read with {@link readShellCommand} (the gate reads every shell command once). */
15
+ readonly shape?: ShellCommandShape | undefined;
16
+ /** Where the session stands: a `cd` beside a `git` that lands here is no line objection. */
17
+ readonly cwd?: string | undefined;
18
+ /** The descriptor bindings of the WHOLE line, for a caller that judges one segment of it. */
19
+ readonly bound?: LineDescriptors | (() => LineDescriptors) | undefined;
20
+ /** The programs a deployment lets a face run: every program the line names (each segment's program past a `command` /
21
+ * `builtin` prefix, and the program an `xargs` segment hands its input to) must be one of them, else the
22
+ * line is not read-only for that face. It only ever narrows — a program here whose call writes is still not read-only. */
23
+ readonly readers?: ReadonlySet<string> | undefined;
24
+ }
11
25
  /** The reference implementation's question for a compound that changes directory and runs git (`cd-git-compound`). */
12
26
  export declare const CD_GIT_COMPOUND_SENTENCE = "This command changes directory before running a version-control command, which can pick up untrusted hooks or repository configuration from the target directory. Approve only if you trust it.";
13
27
  /**
@@ -17,8 +31,8 @@ export declare const CD_GIT_COMPOUND_SENTENCE = "This command changes directory
17
31
  */
18
32
  export declare function changesDirectoryBeforeGit(shape: ShellCommandShape, cwd?: string): boolean;
19
33
  /**
20
- * Read `command` as the allow layer must: read-only, or the first reason it is not. A shape already read by
21
- * the caller may be handed in (the gate reads every shell command once).
34
+ * Read `command` as every read-only consumer must: read-only, or the first reason it is not. A shape already read
35
+ * by the caller may be handed in (the gate reads every shell command once).
22
36
  *
23
37
  * @contract read_only_shell.every_segment — a command line is read-only iff the lexer reads it whole (no
24
38
  * unreadable segment, no group/subshell/control structure, no background `&`), no word anywhere carries a
@@ -30,10 +44,11 @@ export declare function changesDirectoryBeforeGit(shape: ShellCommandShape, cwd?
30
44
  * the exact forms, `echo`/`ls`/`cd`/`find`/`printf`/`history`/`arch`/`ifconfig`); else the flag-vetted
31
45
  * table with its per-row danger predicates, and the `uniq`/`jq` forms. A `cd` beside a `git` in one line
32
46
  * is never read-only (the git command's repository is then not the session's) unless the `cd` lands where the session
33
- * stands ({@link changesDirectoryBeforeGit}). Anything the reading does not positively admit is NOT read-only — the
34
- * answer is never a guess, and a `false` costs one question.
47
+ * stands ({@link changesDirectoryBeforeGit}). Given {@link ReadOnlyShellOptions.readers}, a program the line names
48
+ * outside them is an objection of its own, met where the reading meets the program. Anything the reading does not
49
+ * positively admit is NOT read-only — the answer is never a guess, and a `false` costs one question.
35
50
  */
36
- export declare function readOnlyShellVerdict(command: string, shape?: ShellCommandShape, cwd?: string, bound?: LineDescriptors | (() => LineDescriptors)): ReadOnlyShellVerdict;
51
+ export declare function readOnlyShellVerdict(command: string, opts?: ReadOnlyShellOptions): ReadOnlyShellVerdict;
37
52
  /**
38
53
  * The reader's LINE-level objection to `command` — what makes no segment of it read-only in its place, whatever the
39
54
  * segment reads on its own: the line's structure, or a `cd` beside a `git` ({@link changesDirectoryBeforeGit}). A caller
@@ -1,10 +1,12 @@
1
1
  import { posix } from "node:path";
2
2
  import { lexedWordOf, readShellCommand } from "./shell-run-candidates.js";
3
+ import { unlistedReaderSentence } from "../tools/fs/bash-readonly-classifier.js";
3
4
  import { descriptorsOfPlan, newLineDescriptors, standardDeviceUnrebound } from "../tools/fs/shell-read-device.js";
4
5
  import { planShellReads } from "../tools/fs/shell-read-plan.js";
5
6
  import { writesOnlyStandardDevices } from "../tools/fs/shell-read-write-targets.js";
6
7
  import { FIND_ACTION_PRIMARIES, FIND_NEWER_PRIMARY, FIND_VALUE_PRIMARIES, FLAG_VALUE_ACCEPTS, READ_ONLY_BARE_ONLY, READ_ONLY_BARE_PROGRAMS, READ_ONLY_COMMAND_TABLE, READ_ONLY_ENV_NAMES, READ_ONLY_EXACT_FORMS, READ_ONLY_GLOB_PROGRAMS, XARGS_READ_ONLY_TARGETS, dockerRetargetDanger, } from "./read-only-shell-table.js";
7
8
  const NOT = (reason) => ({ readOnly: false, reason });
9
+ const READ_ONLY = { readOnly: true };
8
10
  export const CD_GIT_COMPOUND_SENTENCE = "This command changes directory before running a version-control command, which can pick up untrusted hooks or repository configuration from the target directory. Approve only if you trust it.";
9
11
  export function changesDirectoryBeforeGit(shape, cwd) {
10
12
  const programs = shape.segments.map((s) => peelBuiltinPrefix(s.argv.slice(leadingAssignmentCount(s.argv)).map((w) => w.text))[0] ?? "");
@@ -20,7 +22,6 @@ export function changesDirectoryBeforeGit(shape, cwd) {
20
22
  const trim = (p) => p.replace(/\/+$/, "") || "/";
21
23
  return trim(posix.resolve(cwd, target.text)) !== trim(cwd);
22
24
  }
23
- const READ_ONLY = { readOnly: true };
24
25
  const BARE_PROGRAMS = new Set(READ_ONLY_BARE_PROGRAMS.filter((p) => !p.includes(" ")));
25
26
  const BARE_MULTIWORD = READ_ONLY_BARE_PROGRAMS.filter((p) => p.includes(" ")).map((p) => p.split(" "));
26
27
  const GLOB_PROGRAMS = new Set(READ_ONLY_GLOB_PROGRAMS);
@@ -41,7 +42,11 @@ const PRINTF_ESCAPE = new RegExp(`%[^%a-zA-Z]*${PRINTF_LENGTH}\\\\[0-7xX]`);
41
42
  const PRINTF_NUMERIC = new RegExp(`%[-+ 0#']*[0-9.*]*${PRINTF_LENGTH}[diouxXeEfFgGaAn]`);
42
43
  const JQ_DANGER_FLAG = /^['"]?-[a-zA-Z]*[fL]/;
43
44
  const JQ_DANGER_TEXT = /--from-file|--rawfile|--slurpfile|--run-tests|--library-path|\benv\b|\$ENV\b|\binclude\b|\bimport\b/;
44
- export function readOnlyShellVerdict(command, shape = readShellCommand(command), cwd, bound) {
45
+ export function readOnlyShellVerdict(command, opts = {}) {
46
+ const { cwd, bound, readers } = opts;
47
+ if (readers !== undefined && typeof readers.has !== "function")
48
+ throw new TypeError("readOnlyShellVerdict: `readers` must be a Set of program names");
49
+ const shape = opts.shape ?? readShellCommand(command);
45
50
  const line = lineStructureObjection(shape);
46
51
  if (line !== undefined)
47
52
  return NOT(line);
@@ -66,12 +71,15 @@ export function readOnlyShellVerdict(command, shape = readShellCommand(command),
66
71
  let boundOfText;
67
72
  const bindings = () => (boundOfText ??= (typeof bound === "function" ? bound() : bound) ?? lineDescriptorsOfText(command));
68
73
  for (const seg of shape.segments) {
69
- const verdict = segmentVerdict(seg, descriptors, bindings);
74
+ const verdict = segmentVerdict(seg, descriptors, bindings, readers);
70
75
  if (!verdict.readOnly)
71
76
  return verdict;
72
77
  }
73
78
  return READ_ONLY;
74
79
  }
80
+ function unlistedObjection(program, readers) {
81
+ return readers !== undefined && !readers.has(program) ? NOT(unlistedReaderSentence(program)) : undefined;
82
+ }
75
83
  const CD_GIT_REASON = "a compound that changes directory and runs git";
76
84
  function lineStructureObjection(shape) {
77
85
  if (shape.grouped)
@@ -144,16 +152,11 @@ function peelBuiltinPrefix(words) {
144
152
  return t;
145
153
  t = t.slice(r);
146
154
  }
147
- else if (t[0] === "noglob") {
148
- if (t.length <= 1)
149
- return t;
150
- t = t.slice(1);
151
- }
152
155
  else
153
156
  return t;
154
157
  }
155
158
  }
156
- function segmentVerdict(seg, line, bindings) {
159
+ function segmentVerdict(seg, line, bindings, readers) {
157
160
  for (const r of seg.redirections) {
158
161
  const target = r.target.text;
159
162
  if (!READING_REDIRECTS.has(r.op) && !standardDeviceUnrebound(target, line, []) && !(r.op === ">&" && /^\d+$/.test(target)))
@@ -174,6 +177,9 @@ function segmentVerdict(seg, line, bindings) {
174
177
  return NOT("a bare assignment runs no program");
175
178
  const words = peelBuiltinPrefix(run.map((w) => w.text));
176
179
  const program = words[0];
180
+ const unlisted = unlistedObjection(program, readers);
181
+ if (unlisted !== undefined)
182
+ return unlisted;
177
183
  if (run.some((w) => expansionKind(w) === "glob"))
178
184
  return GLOB_PROGRAMS.has(program) ? READ_ONLY : NOT(`\`${program}\` with a glob argument — the glob may name anything`);
179
185
  if (DEVICE_WRITERS.has(program) && writesOnlyStandardDevices(program, words.slice(1), bindings()))
@@ -181,7 +187,7 @@ function segmentVerdict(seg, line, bindings) {
181
187
  const structural = structuralReading(words);
182
188
  if (structural !== null)
183
189
  return structural ? READ_ONLY : NOT(`\`${program}\` with these arguments is not a read-only form`);
184
- return tableReading(words, run);
190
+ return tableReading(words, run, readers);
185
191
  }
186
192
  export function lineDescriptorsOfText(command) {
187
193
  return descriptorsOfPlan(planShellReads(command, { readers: new Set(), cwd: "/", roots: [] }));
@@ -248,7 +254,7 @@ function printfReading(words) {
248
254
  }
249
255
  return true;
250
256
  }
251
- function tableReading(words, run) {
257
+ function tableReading(words, run, readers) {
252
258
  const program = words[0];
253
259
  const hit = TABLE_ROWS.find((r) => words.length >= r.words.length && r.words.every((w, i) => words[i] === w));
254
260
  if (hit !== undefined) {
@@ -259,7 +265,8 @@ function tableReading(words, run) {
259
265
  if (a.includes("{") && (a.includes(",") || a.includes("..")))
260
266
  return NOT(`\`${program}\`: a brace pattern argument`);
261
267
  }
262
- if (!flagWalk(args, hit.row, program))
268
+ const named = [];
269
+ if (!flagWalk(args, hit.row, program, named))
263
270
  return NOT(`\`${program}\`: an option outside its read-only set (or a malformed option value)`);
264
271
  if (hit.row.wordsShape !== undefined ? !hit.row.wordsShape(args) : run.some((w) => w.raw.includes("`")))
265
272
  return NOT(`\`${program}\`: arguments outside its read-only form`);
@@ -267,6 +274,11 @@ function tableReading(words, run) {
267
274
  return NOT(`\`${program}\`: a line break inside an argument`);
268
275
  if (hit.row.dangerous?.(args) === true)
269
276
  return NOT(`\`${program}\`: an argument form upstream marks as writing, executing or resolving`);
277
+ for (const target of named) {
278
+ const unlisted = unlistedObjection(target, readers);
279
+ if (unlisted !== undefined)
280
+ return unlisted;
281
+ }
270
282
  return READ_ONLY;
271
283
  }
272
284
  if (program === "uniq" && words.slice(1).every((w, i, all) => /^-[a-zA-Z]+$/.test(w) || /^--[a-zA-Z-]+(=\S+)?$/.test(w) || (i > 0 && /^-[fsw]$/.test(all[i - 1]) && /^\d+$/.test(w))))
@@ -296,7 +308,7 @@ function jqReading(args) {
296
308
  }
297
309
  return true;
298
310
  }
299
- function flagWalk(args, row, program) {
311
+ function flagWalk(args, row, program, named) {
300
312
  let i = 0;
301
313
  while (i < args.length) {
302
314
  let word = args[i];
@@ -309,7 +321,10 @@ function flagWalk(args, row, program) {
309
321
  i++;
310
322
  word = args[i];
311
323
  }
312
- return XARGS_TARGETS.includes(word);
324
+ if (!XARGS_TARGETS.includes(word))
325
+ return false;
326
+ named.push(word);
327
+ return true;
313
328
  }
314
329
  if (word === "--") {
315
330
  if (row.respectsDoubleDash !== false)
@@ -0,0 +1,16 @@
1
+ /** The marks, by what they stand for. `whole` is the bare mark (a span removed whole — a credential value, a floor, a
2
+ * depth cut); the others name the shape that was withheld: `credentials` a URL's userinfo, `url` a whole URL, `path` an
3
+ * absolute filesystem path. A mark the engine writes is exactly one of these four. */
4
+ export declare const REDACTION_MARKS: {
5
+ readonly whole: "[redacted]";
6
+ readonly credentials: "[redacted-credentials]";
7
+ readonly url: "[redacted-url]";
8
+ readonly path: "[redacted-path]";
9
+ };
10
+ /** The bare mark — what a host compares against to tell that the engine withheld a value. */
11
+ export declare const REDACTION_MARK: "[redacted]";
12
+ /** Where the marks sit in `s`, one [start, end) span at a time, leftmost first. Lazy: a reader that stops early (a display cut stops
13
+ * at its bound) pays for the marks it looked at, not for every mark an input of a million of them holds. */
14
+ export declare function eachRedactionMarkerSpan(s: string): Generator<[number, number], void, undefined>;
15
+ /** Where the marks sit in `s`, all of them, as [start, end) spans, leftmost first. */
16
+ export declare function redactionMarkerSpans(s: string): Array<[number, number]>;
@@ -0,0 +1,16 @@
1
+ export const REDACTION_MARKS = {
2
+ whole: "[redacted]",
3
+ credentials: "[redacted-credentials]",
4
+ url: "[redacted-url]",
5
+ path: "[redacted-path]",
6
+ };
7
+ export const REDACTION_MARK = REDACTION_MARKS.whole;
8
+ const escapeLiteral = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9
+ const REDACTION_MARKER_RE = new RegExp(Object.values(REDACTION_MARKS).map(escapeLiteral).join("|"), "g");
10
+ export function* eachRedactionMarkerSpan(s) {
11
+ for (const m of s.matchAll(REDACTION_MARKER_RE))
12
+ yield [m.index, m.index + m[0].length];
13
+ }
14
+ export function redactionMarkerSpans(s) {
15
+ return [...eachRedactionMarkerSpan(s)];
16
+ }
@@ -1,3 +1,4 @@
1
+ import { REDACTION_MARK, REDACTION_MARKS, redactionMarkerSpans } from "./redaction-marks.js";
1
2
  export function summarizeRedactions(findings) {
2
3
  if (findings.length === 0)
3
4
  return "no redactions";
@@ -34,10 +35,8 @@ function passZeroMapper(batches) {
34
35
  return p;
35
36
  };
36
37
  }
37
- const PREEXISTING_MARKER_RE = /\[redacted(?:-[a-z]+)?\]/g;
38
38
  const FORMAT_CHAR_RE = /\p{Cf}/u;
39
39
  const MAX_FORMAT_SLOT_SCANS = 64;
40
- const REDACTED_WHOLE = "[redacted]";
41
40
  function finding(pass, span, family) {
42
41
  const f = { kind: pass.kind, confidence: pass.confidence, span, marker: pass.marker, source: pass.source };
43
42
  if (family !== undefined)
@@ -96,7 +95,7 @@ function soloHits(input, passes) {
96
95
  if (rescans) {
97
96
  work -= m[0].length;
98
97
  if (work < 0) {
99
- hits.push({ start: at, end: input.length, marker: pass.marker === "" ? REDACTED_WHOLE : pass.marker, pass: i, family: familyAt(), matchStart: at, matchEnd: input.length });
98
+ hits.push({ start: at, end: input.length, marker: pass.marker === "" ? REDACTION_MARK : pass.marker, pass: i, family: familyAt(), matchStart: at, matchEnd: input.length });
100
99
  break;
101
100
  }
102
101
  re.lastIndex = at + 1;
@@ -168,7 +167,7 @@ function renderRemovals(input, removals) {
168
167
  if (r.marker !== "" && (widest === undefined || r.end - r.start > widest.end - widest.start))
169
168
  widest = r;
170
169
  }
171
- const marker = widest?.marker ?? REDACTED_WHOLE;
170
+ const marker = widest?.marker ?? REDACTION_MARK;
172
171
  out += input.slice(cursor, start) + marker;
173
172
  cursor = end;
174
173
  edits.push({ at: start, removedLen: end - start, insertedLen: marker.length, inserted: marker, family: widest?.family, head: 0, tail: 0, pass: widest?.pass ?? sorted[i - 1].pass });
@@ -248,7 +247,7 @@ function replacedSpans(batches) {
248
247
  }
249
248
  export function runRedactionPasses(input, passes, report) {
250
249
  if (report !== undefined && report.preexistingMarkers === undefined) {
251
- report.preexistingMarkers = input.match(PREEXISTING_MARKER_RE)?.length ?? 0;
250
+ report.preexistingMarkers = redactionMarkerSpans(input).length;
252
251
  }
253
252
  if (!FORMAT_CHAR_RE.test(input))
254
253
  return applyPasses(input, passes, report, (pos) => pos).out;
@@ -288,7 +287,7 @@ export function runRedactionPasses(input, passes, report) {
288
287
  const { batches } = applyPasses(view, passes, report, toOriginal, true);
289
288
  const viewSpans = replacedSpans(batches);
290
289
  if (viewSpans === undefined)
291
- return REDACTED_WHOLE;
290
+ return REDACTION_MARK;
292
291
  const spans = viewSpans.map((sp) => {
293
292
  const startIdx = offsetToCharIndex.get(sp.start) ?? viewChars.length;
294
293
  const endIdx = offsetToCharIndex.get(sp.end) ?? viewChars.length;
@@ -308,7 +307,7 @@ export function runRedactionPasses(input, passes, report) {
308
307
  if (formatAtSlot[k] !== "")
309
308
  cutOffsets.push(charStartOffsets[k]);
310
309
  if (cutOffsets.length > MAX_FORMAT_SLOT_SCANS)
311
- return REDACTED_WHOLE;
310
+ return REDACTION_MARK;
312
311
  const extra = [];
313
312
  const rawSpans = replacedSpans(applyPasses(input, passes, undefined, (pos) => pos, true).batches);
314
313
  if (rawSpans !== undefined)
@@ -363,8 +362,8 @@ export function runRedactionPasses(input, passes, report) {
363
362
  result += input.slice(cursor);
364
363
  return result;
365
364
  }
366
- const BRACKET_MARKER = { "url-credentials": "[redacted-credentials]" };
367
- const bracketMarker = (kind) => BRACKET_MARKER[kind] ?? "[redacted]";
365
+ const BRACKET_MARKER = { "url-credentials": REDACTION_MARKS.credentials };
366
+ const bracketMarker = (kind) => BRACKET_MARKER[kind] ?? REDACTION_MARK;
368
367
  const capturesLabel = (re) => new RegExp(`${re.source}|`).exec("").length > 1;
369
368
  export function egressPasses(groups, replacers = {}) {
370
369
  return groups.map((rows) => {
@@ -323,7 +323,7 @@ export interface RemoteExecutionEnv extends ExecutionEnv {
323
323
  * `{isolation:true, suspendable:true}` adapter); **partial-capability** adapters (SSH/ADB: `{false, false}`
324
324
  * — a real machine/device, not snapshotable and not isolated) declare it here. **Required + explicit** so
325
325
  * the orchestrator never has to guess: there is no safe default (assuming isolation when there is none is a
326
- * security hole; assuming suspendable crashes on `suspendVM`). Use {@link isSuspendable}/{@link isIsolated}
326
+ * security hole; assuming suspendable crashes on `suspendVM`). Use {@link isSuspendable}/{@link isIsolated}/{@link processTableOf}
327
327
  * rather than the structural {@link isRemoteExecutionEnv} (method presence ≠ semantics — a stub `suspendVM`
328
328
  * that returns `"unsupported"` still satisfies the structural check). Extensible: add fields as new
329
329
  * partial-capability classes appear.
@@ -355,6 +355,29 @@ export interface RemoteExecutionEnv extends ExecutionEnv {
355
355
  * Read STRICTLY through {@link canonicalPathIsAuthoritative}, like every other capability whose
356
356
  * `true` changes what a containment leg does; a wrong-SHAPE value reads absent and is announced. */
357
357
  canonicalPathAuthoritative?: boolean;
358
+ /** True iff the commands this env runs are processes on a table that holds THIS process — the table the
359
+ * engine itself and the processes above it are on, so a kill the model writes there can reach them.
360
+ * `true` for an adapter that spawns the commands as this process's own descendants (a host lane), and
361
+ * for one whose commands run in a PID namespace that contains this process's (the host of the container
362
+ * the engine runs in); `false` only for one whose commands run where this process is not: another
363
+ * machine (SSH host, device, cloud sandbox) or a PID namespace this process is not in (a sandbox
364
+ * container, a pod). Not {@link isolation}: a non-isolated SSH host is a real machine and still another
365
+ * table. The self-preservation guard of the Bash tool asks its question exactly when this is `true`
366
+ * (and for every env that is not remote at all), and does not ask where it is `false`.
367
+ *
368
+ * What a `true` buys is the guard's question exactly as a NodeExecutionEnv gets it, limits included: on this
369
+ * process's own table, of the platform's `pgrep`, with the kill's words as written, from this process's own
370
+ * working directory. It is put as for this process's descendants, so for commands on the same table that
371
+ * are not (SSH to `localhost`) BSD's `pgrep` leaves its OWN caller's ancestors out where the real kill would
372
+ * not, and from an enclosing namespace the question sees only this process's namespace, not the ancestors
373
+ * above it.
374
+ *
375
+ * REQUIRED, with no default: either reading of an absent value is wrong somewhere (assuming `true`
376
+ * refuses an ordinary `pkill` in a sandbox because a word matched this engine here; assuming `false`
377
+ * lets a host lane's `pkill` end the session that issued it). So an absent or non-boolean value is
378
+ * announced once per run at the env's admission point and the guard refuses every pattern kill that needs the question on
379
+ * that env (`pkill -P $$` runs), naming this declaration, until the adapter states it. Read through {@link processTableOf}. */
380
+ sharesProcessTable: boolean;
358
381
  };
359
382
  /** Identity of the connected workspace (design/48 §5 gap 1). Synchronous: it is data the env already holds. */
360
383
  workspaceHandle(): WorkspaceHandle;
@@ -634,3 +657,16 @@ export declare function boundaryIsTheSandbox(env: ExecutionEnv): boolean;
634
657
  * has no case to fire on.
635
658
  */
636
659
  export declare function canonicalPathIsAuthoritative(env: ExecutionEnv): boolean;
660
+ /**
661
+ * Which process table this env's commands run on, as its adapter declares it
662
+ * ({@link RemoteExecutionEnv.capabilities}.sharesProcessTable):
663
+ * · `"this"` — a table that holds this process: a remote env that declares `true`, and every env that is not
664
+ * remote. The second is the base contract's in-process env (its commands are this process's children); an
665
+ * adapter that runs commands elsewhere without the remote seam has no block to declare in and is read the
666
+ * same way, which errs toward asking (a refusal of a kill that could not have reached this process);
667
+ * · `"other"` — a remote env that declares `false`;
668
+ * · `"undeclared"` — a remote env whose declaration is absent, not a boolean, or cannot be read (a throwing
669
+ * getter or Proxy trap). There is no default to fold it to, so the caller refuses what it cannot answer.
670
+ * Total: it never throws. It does not announce — the admission census does, once per run.
671
+ */
672
+ export declare function processTableOf(env: ExecutionEnv): "this" | "other" | "undeclared";
@@ -67,3 +67,14 @@ export function boundaryIsTheSandbox(env) {
67
67
  export function canonicalPathIsAuthoritative(env) {
68
68
  return isRemoteExecutionEnv(env) ? env.capabilities.canonicalPathAuthoritative === true : false;
69
69
  }
70
+ export function processTableOf(env) {
71
+ try {
72
+ if (!isRemoteExecutionEnv(env))
73
+ return "this";
74
+ const declared = env.capabilities.sharesProcessTable;
75
+ return declared === true ? "this" : declared === false ? "other" : "undeclared";
76
+ }
77
+ catch {
78
+ return "undeclared";
79
+ }
80
+ }
@@ -84,6 +84,28 @@ export type ReopenReasonTableCoversEveryCause = AssertAllKeysHandled<Exclude<Res
84
84
  * decision is untouched, and the retry replays it.
85
85
  */
86
86
  export declare function reopenReasonOf(cause: ResumeStartupCause | undefined): ReopenReason;
87
- /** What the result of a returned resume leg says after its checkpoint was reopened, per reason. */
88
- export declare function reopenedUnstartedSentence(reason: ReopenReason): string;
87
+ /**
88
+ * What happened to a claimed row whose approved action never started — the one closed outcome every exit of such a leg reports
89
+ * (the thrown-prepare backstop, the returned-leg settle, the post-claim abort): `reopened` under a reason (the row is pending again),
90
+ * `declined` (the store's `reopen` answered `false`: the row is no longer the resolved row this leg claimed — missing, expired, its
91
+ * decided action already disposed, or pending again — which the boolean does not say), `unknown` (the reopen threw: the write may have
92
+ * committed and only its acknowledgement been lost, so the row's state cannot be proven from here).
93
+ */
94
+ export type UnstartedRow = {
95
+ readonly kind: "reopened";
96
+ readonly reason: ReopenReason;
97
+ } | {
98
+ readonly kind: "declined";
99
+ } | {
100
+ readonly kind: "unknown";
101
+ readonly thrown: unknown;
102
+ };
103
+ /**
104
+ * THE compensation of a claimed leg whose approved action never started: the claim's reversal (`reopen`, bound to the row) asked once,
105
+ * under `reason`, and read into {@link UnstartedRow} — its answer, never a code sniffed off whatever it threw (a store's own error may
106
+ * carry any code, and a throw after a committed write is not a refusal). Every exit calls it; none re-reads the outcome another way.
107
+ */
108
+ export declare function compensateUnstarted(reopen: (reason: ReopenReason) => Promise<"reopened" | "declined">, reason: ReopenReason): Promise<UnstartedRow>;
109
+ /** The sentence for {@link UnstartedRow} — one per outcome, the same on every exit; the exit puts its own lead before it. */
110
+ export declare function unstartedRowSentence(row: UnstartedRow): string;
89
111
  export {};