@sema-agent/core 7.58.0 → 7.60.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 (519) hide show
  1. package/CHANGELOG.md +1340 -0
  2. package/README.md +6 -4
  3. package/dist/agents/agent-definition.d.ts +7 -0
  4. package/dist/agents/agent-definition.js +12 -0
  5. package/dist/agents/agent-transcript-tool.d.ts +2 -1
  6. package/dist/agents/agent-transcript-tool.js +3 -1
  7. package/dist/agents/cc-peer-directory.js +8 -8
  8. package/dist/agents/child-model-seat.d.ts +4 -2
  9. package/dist/agents/child-model-seat.js +9 -4
  10. package/dist/agents/cumulative-stats.js +0 -1
  11. package/dist/agents/inherited-tool-pool.d.ts +26 -1
  12. package/dist/agents/inherited-tool-pool.js +22 -0
  13. package/dist/agents/peer-directory.d.ts +9 -0
  14. package/dist/agents/peer-directory.js +6 -2
  15. package/dist/agents/retain-ledger.d.ts +11 -1
  16. package/dist/agents/retain-ledger.js +13 -2
  17. package/dist/agents/roster-store.d.ts +1 -1
  18. package/dist/agents/roster-store.js +3 -1
  19. package/dist/agents/send-message-tool.d.ts +8 -19
  20. package/dist/agents/send-message-tool.js +32 -50
  21. package/dist/agents/subagent.d.ts +51 -17
  22. package/dist/agents/subagent.js +150 -112
  23. package/dist/agents/tool-filter.d.ts +1 -3
  24. package/dist/agents/tool-filter.js +4 -12
  25. package/dist/bench/metrics.d.ts +3 -5
  26. package/dist/bench/metrics.js +0 -1
  27. package/dist/brain/anthropic.js +161 -45
  28. package/dist/brain/degrading.js +3 -1
  29. package/dist/brain/errors.d.ts +9 -3
  30. package/dist/brain/errors.js +7 -1
  31. package/dist/brain/failover.js +2 -1
  32. package/dist/brain/open-responses.js +3 -3
  33. package/dist/brain/openai.js +103 -53
  34. package/dist/brain/provider-dialect.d.ts +11 -0
  35. package/dist/brain/provider-dialect.js +5 -2
  36. package/dist/brain/reasoning-request.js +5 -4
  37. package/dist/brain/reasoning.d.ts +19 -0
  38. package/dist/brain/reasoning.js +17 -2
  39. package/dist/brain/request-route.d.ts +4 -1
  40. package/dist/brain/request-route.js +4 -1
  41. package/dist/brain/route-adjudicator.d.ts +84 -18
  42. package/dist/brain/route-adjudicator.js +90 -22
  43. package/dist/brain/route-conformance.js +1 -1
  44. package/dist/brain/status-sink.d.ts +7 -1
  45. package/dist/brain/status-sink.js +6 -0
  46. package/dist/brain/stream-engine.js +84 -49
  47. package/dist/brain/stream-shared.d.ts +30 -0
  48. package/dist/brain/stream-shared.js +34 -1
  49. package/dist/brain/timeout.d.ts +65 -6
  50. package/dist/brain/timeout.js +111 -11
  51. package/dist/core/a2a.d.ts +15 -5
  52. package/dist/core/a2a.js +34 -19
  53. package/dist/core/account-row.d.ts +61 -0
  54. package/dist/core/account-row.js +51 -0
  55. package/dist/core/advisor-verdict.d.ts +2 -1
  56. package/dist/core/advisor-verdict.js +1 -1
  57. package/dist/core/agent-definition.d.ts +20 -0
  58. package/dist/core/allow-entry.d.ts +20 -6
  59. package/dist/core/allow-entry.js +17 -7
  60. package/dist/core/approval-object.d.ts +29 -15
  61. package/dist/core/approval-object.js +47 -19
  62. package/dist/core/artifact-host.d.ts +0 -2
  63. package/dist/core/artifact-host.js +0 -1
  64. package/dist/core/auto-compaction.js +1 -1
  65. package/dist/core/auto-mode-defaults.d.ts +8 -0
  66. package/dist/core/auto-mode-defaults.js +1 -0
  67. package/dist/core/auto-mode-rebuild.d.ts +2 -1
  68. package/dist/core/auto-mode.d.ts +39 -4
  69. package/dist/core/auto-mode.js +63 -12
  70. package/dist/core/background-agent-store.d.ts +26 -4
  71. package/dist/core/background-agent-store.js +3 -2
  72. package/dist/core/background-shell.d.ts +12 -1
  73. package/dist/core/background-shell.js +12 -0
  74. package/dist/core/checkpoint-requirements.d.ts +13 -1
  75. package/dist/core/checkpoint-requirements.js +3 -1
  76. package/dist/core/checkpoint-store.d.ts +66 -25
  77. package/dist/core/checkpoint-store.js +22 -9
  78. package/dist/core/child-clamp-seats.d.ts +29 -0
  79. package/dist/core/child-clamp-seats.js +56 -1
  80. package/dist/core/compliance.d.ts +3 -3
  81. package/dist/core/compliance.js +1 -1
  82. package/dist/core/credential-echo.d.ts +52 -0
  83. package/dist/core/credential-echo.js +65 -0
  84. package/dist/core/credential-vocabulary.d.ts +13 -3
  85. package/dist/core/credential-vocabulary.js +12 -4
  86. package/dist/core/cross-boundary-taint.d.ts +4 -5
  87. package/dist/core/effective-path-target.d.ts +8 -2
  88. package/dist/core/effective-path-target.js +8 -3
  89. package/dist/core/engine-notice.d.ts +156 -23
  90. package/dist/core/engine-notice.js +19 -5
  91. package/dist/core/frame-settlement.d.ts +5 -0
  92. package/dist/core/frame-settlement.js +4 -0
  93. package/dist/core/gate-fold.js +8 -6
  94. package/dist/core/gate-lanes.js +47 -12
  95. package/dist/core/gate-outcome.d.ts +32 -3
  96. package/dist/core/gate-outcome.js +19 -1
  97. package/dist/core/governance-codes.d.ts +17 -1
  98. package/dist/core/governance-codes.js +25 -0
  99. package/dist/core/hands-band-screen.js +0 -1
  100. package/dist/core/hands-band.d.ts +0 -3
  101. package/dist/core/hooks.d.ts +70 -59
  102. package/dist/core/hooks.js +125 -80
  103. package/dist/core/image-admission.d.ts +106 -52
  104. package/dist/core/image-admission.js +184 -56
  105. package/dist/core/image-downsample.d.ts +36 -69
  106. package/dist/core/image-downsample.js +111 -73
  107. package/dist/core/integer-option.d.ts +21 -0
  108. package/dist/core/integer-option.js +13 -0
  109. package/dist/core/locked-config.d.ts +59 -5
  110. package/dist/core/locked-config.js +82 -50
  111. package/dist/core/mailbox-store.d.ts +45 -1
  112. package/dist/core/mailbox-store.js +53 -9
  113. package/dist/core/mcp-call-meta.d.ts +2 -2
  114. package/dist/core/mcp-call-meta.js +9 -10
  115. package/dist/core/mcp-failure.d.ts +122 -20
  116. package/dist/core/mcp-failure.js +73 -5
  117. package/dist/core/mcp-host-seat.d.ts +92 -0
  118. package/dist/core/mcp-host-seat.js +131 -0
  119. package/dist/core/mcp-probe.d.ts +7 -2
  120. package/dist/core/mcp-probe.js +7 -2
  121. package/dist/core/mcp-server-link.d.ts +22 -1
  122. package/dist/core/mcp-server-link.js +25 -1
  123. package/dist/core/mcp-server-spec.d.ts +38 -9
  124. package/dist/core/mcp-server-spec.js +55 -21
  125. package/dist/core/mcp.d.ts +27 -12
  126. package/dist/core/mcp.js +105 -76
  127. package/dist/core/memory-admission.d.ts +23 -6
  128. package/dist/core/memory-admission.js +19 -9
  129. package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
  130. package/dist/core/memory-engine/consolidation-driver.js +3 -3
  131. package/dist/core/memory-engine/consolidation.d.ts +4 -0
  132. package/dist/core/memory-engine/consolidation.js +1 -0
  133. package/dist/core/memory-engine/content-origin.d.ts +13 -0
  134. package/dist/core/memory-engine/content-origin.js +21 -3
  135. package/dist/core/memory-engine/delegation-settlement.js +5 -12
  136. package/dist/core/memory-engine/distiller.js +2 -2
  137. package/dist/core/memory-engine/dual-root.d.ts +50 -1
  138. package/dist/core/memory-engine/dual-root.js +44 -1
  139. package/dist/core/memory-engine/engine.d.ts +67 -14
  140. package/dist/core/memory-engine/engine.js +384 -212
  141. package/dist/core/memory-engine/export-bundle.d.ts +23 -0
  142. package/dist/core/memory-engine/export-bundle.js +23 -4
  143. package/dist/core/memory-engine/file-backend.d.ts +128 -55
  144. package/dist/core/memory-engine/file-backend.js +290 -117
  145. package/dist/core/memory-engine/index.d.ts +3 -2
  146. package/dist/core/memory-engine/index.js +2 -1
  147. package/dist/core/memory-engine/layout.d.ts +59 -11
  148. package/dist/core/memory-engine/layout.js +190 -40
  149. package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
  150. package/dist/core/memory-engine/memory-backend-contract.js +39 -2
  151. package/dist/core/memory-engine/scope-contract.d.ts +13 -3
  152. package/dist/core/memory-engine/scope-contract.js +2 -2
  153. package/dist/core/memory-engine/sync-client.d.ts +51 -9
  154. package/dist/core/memory-engine/sync-client.js +107 -13
  155. package/dist/core/memory-engine/sync-report.d.ts +103 -0
  156. package/dist/core/memory-engine/sync-report.js +119 -0
  157. package/dist/core/memory-engine/sync.d.ts +8 -1
  158. package/dist/core/memory-engine/types.d.ts +6 -0
  159. package/dist/core/mode-policy.d.ts +9 -1
  160. package/dist/core/mode-policy.js +11 -1
  161. package/dist/core/model-receipt.d.ts +39 -0
  162. package/dist/core/model-receipt.js +139 -0
  163. package/dist/core/mods/agent-stations.d.ts +65 -0
  164. package/dist/core/mods/agent-stations.js +105 -0
  165. package/dist/core/mods/classic-events.d.ts +5 -1
  166. package/dist/core/mods/kernel/dispatch.d.ts +5 -1
  167. package/dist/core/mods/kernel/dispatch.js +6 -5
  168. package/dist/core/mods/kernel/events.d.ts +11 -4
  169. package/dist/core/mods/kernel/events.js +11 -7
  170. package/dist/core/mods/kernel/receive.d.ts +5 -0
  171. package/dist/core/mods/kernel/receive.js +10 -0
  172. package/dist/core/mods/kernel/registration.d.ts +4 -0
  173. package/dist/core/mods/kernel/registration.js +3 -0
  174. package/dist/core/mods/lifecycle-stations.d.ts +41 -0
  175. package/dist/core/mods/lifecycle-stations.js +35 -0
  176. package/dist/core/mods/stations.d.ts +73 -60
  177. package/dist/core/mods/stations.js +64 -40
  178. package/dist/core/mods/tool-call.d.ts +10 -4
  179. package/dist/core/mods/tool-call.js +28 -12
  180. package/dist/core/mounted-mcp.d.ts +5 -0
  181. package/dist/core/mounted-mcp.js +2 -2
  182. package/dist/core/namespaced-rule-name.d.ts +7 -1
  183. package/dist/core/namespaced-rule-name.js +13 -2
  184. package/dist/core/oracle-isolation.js +1 -1
  185. package/dist/core/own-property-receipt.d.ts +3 -0
  186. package/dist/core/own-property-receipt.js +3 -0
  187. package/dist/core/parent-spec-seat.d.ts +8 -3
  188. package/dist/core/parent-spec-seat.js +2 -0
  189. package/dist/core/park-selfcheck.js +14 -8
  190. package/dist/core/peer-seat.d.ts +133 -16
  191. package/dist/core/peer-seat.js +319 -42
  192. package/dist/core/permission-rule-consent.d.ts +0 -21
  193. package/dist/core/permission-rule-consent.js +11 -6
  194. package/dist/core/permission-rule-model.d.ts +20 -2
  195. package/dist/core/permission-rule-model.js +8 -7
  196. package/dist/core/present-plan-tool.d.ts +11 -3
  197. package/dist/core/present-plan-tool.js +2 -2
  198. package/dist/core/protocol-http-auth.d.ts +14 -2
  199. package/dist/core/protocol-http-auth.js +16 -7
  200. package/dist/core/read-face-seats.d.ts +7 -5
  201. package/dist/core/read-face-seats.js +4 -1
  202. package/dist/core/redaction-marks.d.ts +4 -3
  203. package/dist/core/redaction-marks.js +2 -2
  204. package/dist/core/remote-env.d.ts +146 -98
  205. package/dist/core/remote-env.js +113 -14
  206. package/dist/core/resume-startup-cause.js +1 -0
  207. package/dist/core/retention.js +37 -12
  208. package/dist/core/retired-keys.d.ts +6 -1
  209. package/dist/core/retired-keys.js +4 -1
  210. package/dist/core/rewrite-rejudge.d.ts +13 -5
  211. package/dist/core/rewrite-rejudge.js +9 -5
  212. package/dist/core/roles.d.ts +69 -3
  213. package/dist/core/roles.js +167 -80
  214. package/dist/core/rule-owner.d.ts +3 -0
  215. package/dist/core/runner/announce-once-ledger.d.ts +5 -4
  216. package/dist/core/runner/announce-once-ledger.js +4 -2
  217. package/dist/core/runner/assemble-result.d.ts +0 -5
  218. package/dist/core/runner/assemble-result.js +0 -1
  219. package/dist/core/runner/call-hook-stations.d.ts +17 -10
  220. package/dist/core/runner/call-hook-stations.js +23 -12
  221. package/dist/core/runner/child-tree.d.ts +7 -8
  222. package/dist/core/runner/child-tree.js +6 -6
  223. package/dist/core/runner/classifier-ladder.d.ts +10 -2
  224. package/dist/core/runner/classifier-ladder.js +39 -8
  225. package/dist/core/runner/construction-doors.js +5 -0
  226. package/dist/core/runner/contracts.d.ts +82 -57
  227. package/dist/core/runner/credential-origin-seat.js +4 -3
  228. package/dist/core/runner/cross-boundary-lane.d.ts +3 -5
  229. package/dist/core/runner/cross-boundary-lane.js +11 -2
  230. package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
  231. package/dist/core/runner/cwd-alignment-probe.js +21 -0
  232. package/dist/core/runner/decide-continuation.d.ts +2 -2
  233. package/dist/core/runner/env-capability-census.d.ts +15 -20
  234. package/dist/core/runner/env-capability-census.js +25 -34
  235. package/dist/core/runner/file-history-request.d.ts +2 -2
  236. package/dist/core/runner/file-history-request.js +0 -8
  237. package/dist/core/runner/gate-exit.d.ts +87 -11
  238. package/dist/core/runner/gate-exit.js +30 -8
  239. package/dist/core/runner/git-status-frame.d.ts +5 -2
  240. package/dist/core/runner/git-status-frame.js +3 -4
  241. package/dist/core/runner/image-removed-seat.d.ts +12 -0
  242. package/dist/core/runner/image-removed-seat.js +19 -0
  243. package/dist/core/runner/image.d.ts +7 -2
  244. package/dist/core/runner/image.js +14 -8
  245. package/dist/core/runner/inline-image.d.ts +10 -8
  246. package/dist/core/runner/inline-image.js +11 -9
  247. package/dist/core/runner/memory-consolidation-driver.js +5 -5
  248. package/dist/core/runner/park-commit.d.ts +1 -1
  249. package/dist/core/runner/park-commit.js +3 -0
  250. package/dist/core/runner/permission-rule-lanes.js +1 -1
  251. package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
  252. package/dist/core/runner/prepare-ask-lane.js +2 -1
  253. package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
  254. package/dist/core/runner/prepare-boundary-parks.js +5 -5
  255. package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -5
  256. package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
  257. package/dist/core/runner/prepare-config-doors.d.ts +6 -1
  258. package/dist/core/runner/prepare-config-doors.js +16 -9
  259. package/dist/core/runner/prepare-context-lane.js +2 -0
  260. package/dist/core/runner/prepare-delegation-surface.d.ts +9 -3
  261. package/dist/core/runner/prepare-delegation-surface.js +5 -4
  262. package/dist/core/runner/prepare-file-history.d.ts +10 -12
  263. package/dist/core/runner/prepare-file-history.js +3 -12
  264. package/dist/core/runner/prepare-gate-stations.d.ts +4 -3
  265. package/dist/core/runner/prepare-gate-stations.js +4 -3
  266. package/dist/core/runner/prepare-hands-readface.d.ts +7 -1
  267. package/dist/core/runner/prepare-hands-readface.js +19 -6
  268. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -7
  269. package/dist/core/runner/prepare-inherited-gate.js +22 -31
  270. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  271. package/dist/core/runner/prepare-memory.d.ts +2 -2
  272. package/dist/core/runner/prepare-memory.js +12 -19
  273. package/dist/core/runner/prepare-park-ask.d.ts +4 -6
  274. package/dist/core/runner/prepare-park-ask.js +5 -9
  275. package/dist/core/runner/prepare-policy-chain.d.ts +8 -7
  276. package/dist/core/runner/prepare-policy-chain.js +136 -121
  277. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  278. package/dist/core/runner/prepare-project-context.js +10 -7
  279. package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -2
  280. package/dist/core/runner/prepare-prompt-inputs.js +10 -20
  281. package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
  282. package/dist/core/runner/prepare-protocol-tools.js +17 -2
  283. package/dist/core/runner/prepare-run-refs.d.ts +2 -3
  284. package/dist/core/runner/prepare-run-refs.js +4 -1
  285. package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
  286. package/dist/core/runner/prepare-suspend-saga.js +5 -7
  287. package/dist/core/runner/prepare-task.js +44 -28
  288. package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
  289. package/dist/core/runner/prepare-turn-wiring.js +7 -2
  290. package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -4
  291. package/dist/core/runner/prepare-wiring-manifest.js +34 -19
  292. package/dist/core/runner/prepare-workspace-restore.js +3 -3
  293. package/dist/core/runner/reply-pricing.d.ts +30 -0
  294. package/dist/core/runner/reply-pricing.js +19 -0
  295. package/dist/core/runner/resume-admission.js +4 -2
  296. package/dist/core/runner/resume-apply.js +6 -1
  297. package/dist/core/runner/resume-checkpoint-screen.js +4 -4
  298. package/dist/core/runner/resume-policy-outcome.js +5 -5
  299. package/dist/core/runner/retired-runner-deps.js +4 -1
  300. package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
  301. package/dist/core/runner/role-seat-defaulted.js +40 -0
  302. package/dist/core/runner/run-attachment-seats.js +3 -3
  303. package/dist/core/runner/run-brain-sinks.js +3 -0
  304. package/dist/core/runner/run-git-lane.d.ts +3 -1
  305. package/dist/core/runner/run-git-lane.js +1 -1
  306. package/dist/core/runner/run-harness-handlers.d.ts +3 -1
  307. package/dist/core/runner/run-harness-handlers.js +3 -1
  308. package/dist/core/runner/run-identity-wiring.d.ts +2 -5
  309. package/dist/core/runner/run-identity-wiring.js +6 -5
  310. package/dist/core/runner/run-leg.d.ts +2 -0
  311. package/dist/core/runner/run-leg.js +63 -56
  312. package/dist/core/runner/run-notification-lane.d.ts +3 -1
  313. package/dist/core/runner/run-notification-lane.js +16 -10
  314. package/dist/core/runner/run-settle-and-teardown.js +5 -1
  315. package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
  316. package/dist/core/runner/run-stop-and-final-verify.js +14 -6
  317. package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
  318. package/dist/core/runner/run-terminal-adoption.js +9 -3
  319. package/dist/core/runner/run-turn-boundary.js +89 -77
  320. package/dist/core/runner/runtask.d.ts +8 -5
  321. package/dist/core/runner/runtask.js +21 -13
  322. package/dist/core/runner/side-call-account.d.ts +1 -1
  323. package/dist/core/runner/side-call-account.js +3 -18
  324. package/dist/core/runner/skills-seat.js +2 -2
  325. package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
  326. package/dist/core/runner/sub-agent-deny-lists.js +20 -7
  327. package/dist/core/runner/synthetic-tools.js +2 -2
  328. package/dist/core/runner/tool-disclosure.js +0 -2
  329. package/dist/core/runner/tool-end-body.js +2 -2
  330. package/dist/core/runner/tool-face-overlay.d.ts +1 -1
  331. package/dist/core/runner/tool-face-overlay.js +26 -19
  332. package/dist/core/runner/tool-occurrence.d.ts +1 -1
  333. package/dist/core/runner/tool-occurrence.js +2 -2
  334. package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
  335. package/dist/core/runner/tool-result-media-seat.js +17 -1
  336. package/dist/core/runner/turn-attachments.d.ts +29 -27
  337. package/dist/core/runner/turn-attachments.js +27 -42
  338. package/dist/core/runner-deps.d.ts +32 -19
  339. package/dist/core/secret-env.d.ts +35 -4
  340. package/dist/core/secret-env.js +65 -3
  341. package/dist/core/sensitive-path-policy.js +3 -3
  342. package/dist/core/session-policy-store.d.ts +12 -3
  343. package/dist/core/session-policy-store.js +29 -10
  344. package/dist/core/session-store.d.ts +5 -7
  345. package/dist/core/session-store.js +50 -11
  346. package/dist/core/side-query.d.ts +11 -1
  347. package/dist/core/side-query.js +9 -0
  348. package/dist/core/skill-grant-binding.d.ts +31 -2
  349. package/dist/core/skill-grant-binding.js +31 -1
  350. package/dist/core/skill-grant.d.ts +17 -5
  351. package/dist/core/skill-grant.js +24 -6
  352. package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
  353. package/dist/core/store-contracts/checkpoint-store-contract.js +3 -2
  354. package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
  355. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  356. package/dist/core/store-contracts/tool-result-store-contract.js +37 -0
  357. package/dist/core/stub-env.d.ts +5 -5
  358. package/dist/core/stub-env.js +11 -1
  359. package/dist/core/swappable-deps.d.ts +17 -43
  360. package/dist/core/swappable-deps.js +15 -5
  361. package/dist/core/synthetic-read-verdict.d.ts +1 -1
  362. package/dist/core/synthetic-read-verdict.js +2 -1
  363. package/dist/core/task-event.d.ts +50 -10
  364. package/dist/core/task-notification.d.ts +88 -5
  365. package/dist/core/task-notification.js +146 -17
  366. package/dist/core/task-registry-agent.d.ts +18 -12
  367. package/dist/core/task-registry-agent.js +19 -6
  368. package/dist/core/task-registry-monitor.d.ts +7 -0
  369. package/dist/core/task-registry-monitor.js +28 -1
  370. package/dist/core/task-registry-shared.d.ts +43 -3
  371. package/dist/core/task-registry-shared.js +21 -7
  372. package/dist/core/task-registry-workflow.js +1 -1
  373. package/dist/core/task-registry.d.ts +50 -35
  374. package/dist/core/task-registry.js +64 -23
  375. package/dist/core/task-result.d.ts +3 -12
  376. package/dist/core/task-spec.d.ts +15 -7
  377. package/dist/core/task-stream.d.ts +1 -1
  378. package/dist/core/terminal-cause.d.ts +10 -0
  379. package/dist/core/tool-catalog-entries.js +1 -1
  380. package/dist/core/tool-check-reading.d.ts +1 -0
  381. package/dist/core/tool-check-reading.js +3 -3
  382. package/dist/core/tool-face-reader.d.ts +7 -6
  383. package/dist/core/tool-face-reader.js +4 -3
  384. package/dist/core/tool-name-aliases.d.ts +19 -0
  385. package/dist/core/tool-name-aliases.js +54 -2
  386. package/dist/core/tool-policy.d.ts +21 -4
  387. package/dist/core/tool-policy.js +1 -1
  388. package/dist/core/tool-registry.d.ts +5 -5
  389. package/dist/core/tool-registry.js +2 -2
  390. package/dist/core/tool-result-store.d.ts +88 -5
  391. package/dist/core/tool-result-store.js +51 -12
  392. package/dist/core/tool-roster.d.ts +112 -5
  393. package/dist/core/tool-roster.js +42 -1
  394. package/dist/core/tool-spec.d.ts +23 -5
  395. package/dist/core/trace.d.ts +0 -1
  396. package/dist/core/types.d.ts +5 -5
  397. package/dist/core/types.js +2 -2
  398. package/dist/core/untrusted-text.js +1 -1
  399. package/dist/core/user-attachment.d.ts +10 -5
  400. package/dist/core/user-attachment.js +15 -7
  401. package/dist/core/wiring-manifest.d.ts +6 -3
  402. package/dist/engine/compaction/compaction.js +29 -3
  403. package/dist/engine/execution-env/node-execution-env.d.ts +11 -5
  404. package/dist/engine/execution-env/node-execution-env.js +21 -13
  405. package/dist/engine/harness/agent-harness.d.ts +26 -3
  406. package/dist/engine/harness/agent-harness.js +49 -16
  407. package/dist/engine/harness/messages.d.ts +3 -1
  408. package/dist/engine/harness/messages.js +3 -2
  409. package/dist/engine/harness/types.d.ts +119 -28
  410. package/dist/engine/llm/rejected-images.d.ts +46 -0
  411. package/dist/engine/llm/rejected-images.js +54 -0
  412. package/dist/engine/llm/tool-turns.d.ts +2 -1
  413. package/dist/engine/llm/types.d.ts +18 -7
  414. package/dist/engine/loop/agent-loop.d.ts +20 -12
  415. package/dist/engine/loop/agent-loop.js +205 -36
  416. package/dist/engine/loop/types.d.ts +12 -3
  417. package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
  418. package/dist/engine/lsp/node-lsp-manager.js +32 -13
  419. package/dist/engine/session/path-to-root.d.ts +38 -0
  420. package/dist/engine/session/path-to-root.js +39 -0
  421. package/dist/engine/session/storage-base.js +4 -21
  422. package/dist/index.d.ts +35 -21
  423. package/dist/index.js +26 -17
  424. package/dist/internal/harness-types.d.ts +1 -1
  425. package/dist/internal/harness.d.ts +1 -0
  426. package/dist/internal/llm.d.ts +1 -0
  427. package/dist/orchestration/run-workflow-tool.d.ts +9 -3
  428. package/dist/orchestration/run-workflow-tool.js +59 -29
  429. package/dist/orchestration/workflow-governance.d.ts +1 -1
  430. package/dist/orchestration/workflow-governance.js +2 -1
  431. package/dist/orchestration/workflow-observe.d.ts +17 -1
  432. package/dist/orchestration/workflow-observe.js +20 -0
  433. package/dist/orchestration/workflow-types.d.ts +32 -7
  434. package/dist/orchestration/workflow.d.ts +4 -0
  435. package/dist/orchestration/workflow.js +762 -491
  436. package/dist/prompts/default.d.ts +1 -10
  437. package/dist/prompts/default.js +0 -2
  438. package/dist/shell/counting-pass.d.ts +50 -0
  439. package/dist/shell/counting-pass.js +502 -0
  440. package/dist/shell/lex.d.ts +4 -2
  441. package/dist/shell/lex.js +93 -34
  442. package/dist/shell/shell-words.d.ts +1 -1
  443. package/dist/shell/shell-words.js +7 -6
  444. package/dist/stores/file/background-agent-store.d.ts +1 -1
  445. package/dist/stores/file/background-agent-store.js +3 -1
  446. package/dist/stores/file/checkpoint-store.d.ts +127 -2
  447. package/dist/stores/file/checkpoint-store.js +19 -14
  448. package/dist/stores/file/file-history-store.d.ts +1 -1
  449. package/dist/stores/file/file-history-store.js +3 -1
  450. package/dist/stores/file/index.d.ts +4 -3
  451. package/dist/stores/file/index.js +17 -8
  452. package/dist/stores/file/mailbox-store.d.ts +1 -1
  453. package/dist/stores/file/mailbox-store.js +9 -11
  454. package/dist/stores/file/memory-store.d.ts +1 -1
  455. package/dist/stores/file/memory-store.js +3 -1
  456. package/dist/stores/file/session-policy-store.d.ts +1 -1
  457. package/dist/stores/file/session-policy-store.js +3 -1
  458. package/dist/stores/file/session-store.d.ts +1 -1
  459. package/dist/stores/file/session-store.js +3 -1
  460. package/dist/stores/file/shared-ledger.d.ts +26 -0
  461. package/dist/stores/file/shared-ledger.js +38 -9
  462. package/dist/stores/file/tool-result-store.d.ts +20 -2
  463. package/dist/stores/file/tool-result-store.js +74 -6
  464. package/dist/stores/file/usage-window-store.d.ts +1 -1
  465. package/dist/stores/file/usage-window-store.js +3 -1
  466. package/dist/stores/file/workflow-journal-store.d.ts +1 -11
  467. package/dist/stores/file/workflow-journal-store.js +3 -2
  468. package/dist/tools/fs/containment-face.d.ts +5 -0
  469. package/dist/tools/fs/encoding.d.ts +13 -4
  470. package/dist/tools/fs/encoding.js +17 -2
  471. package/dist/tools/fs/fs-bash-background-text.d.ts +7 -0
  472. package/dist/tools/fs/fs-bash-background-text.js +1 -0
  473. package/dist/tools/fs/fs-bash.d.ts +14 -4
  474. package/dist/tools/fs/fs-bash.js +29 -35
  475. package/dist/tools/fs/fs-pdf.d.ts +2 -2
  476. package/dist/tools/fs/fs-pdf.js +26 -21
  477. package/dist/tools/fs/fs-read.d.ts +5 -4
  478. package/dist/tools/fs/fs-read.js +35 -18
  479. package/dist/tools/fs/fs-search-tools.js +4 -1
  480. package/dist/tools/fs/fs-shared.d.ts +11 -13
  481. package/dist/tools/fs/fs-shared.js +11 -7
  482. package/dist/tools/fs/fs-write.js +5 -5
  483. package/dist/tools/fs/index.d.ts +14 -8
  484. package/dist/tools/fs/index.js +13 -5
  485. package/dist/tools/fs/program-read-model.d.ts +13 -0
  486. package/dist/tools/fs/program-read-model.js +15 -0
  487. package/dist/tools/fs/program-read-model.rows.js +1 -1
  488. package/dist/tools/fs/read-deny.d.ts +13 -10
  489. package/dist/tools/fs/read-deny.js +25 -5
  490. package/dist/tools/fs/read-floor.d.ts +62 -0
  491. package/dist/tools/fs/read-floor.js +58 -0
  492. package/dist/tools/fs/removal-targets.d.ts +9 -4
  493. package/dist/tools/fs/removal-targets.js +17 -9
  494. package/dist/tools/fs/search.d.ts +3 -3
  495. package/dist/tools/fs/search.js +4 -4
  496. package/dist/tools/fs/shell-read-check.d.ts +1 -1
  497. package/dist/tools/fs/shell-read-check.js +2 -1
  498. package/dist/tools/fs/shell-read-judge.d.ts +16 -8
  499. package/dist/tools/fs/shell-read-judge.js +10 -6
  500. package/dist/tools/fs/shell-read-plan.d.ts +6 -1
  501. package/dist/tools/fs/shell-read-plan.js +22 -15
  502. package/dist/tools/fs/shell-read-start.js +1 -0
  503. package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
  504. package/dist/tools/fs/shell-reentry-text.js +25 -3
  505. package/dist/tools/monitor.d.ts +9 -4
  506. package/dist/tools/monitor.js +17 -8
  507. package/dist/tools/scheduler-tools.js +42 -4
  508. package/dist/tools/web.d.ts +0 -10
  509. package/dist/tools/web.js +1 -4
  510. package/package.json +5 -2
  511. package/test/export-surface.snapshot.json +161 -21
  512. package/wire-changes/core-stores-sql@7.59.0.json +29 -0
  513. package/wire-changes/core-stores-sql@7.60.0.json +30 -0
  514. package/wire-changes/core@7.59.0.json +2459 -0
  515. package/wire-changes/core@7.60.0.json +3274 -0
  516. package/wire-changes/mods-kernel@7.59.0.json +29 -0
  517. package/wire-changes/mods-kernel@7.60.0.json +62 -0
  518. package/wire-changes/primitives@7.59.0.json +29 -0
  519. package/wire-changes/primitives@7.60.0.json +30 -0
@@ -6,12 +6,13 @@ import { canAccessAgentRecord, } from "./background-agent-store.js";
6
6
  import { delimitUntrusted } from "./untrusted-text.js";
7
7
  import { createSafeNotifier } from "./safe-notify.js";
8
8
  import { stripCwdSentinel } from "../tools/fs/fs-shared.js";
9
+ import { persistTaskArtifact, taskArtifactOriginOf } from "./tool-result-store.js";
9
10
  import { registerMonitorLane, pollMonitorLane, stopMonitorLane } from "./task-registry-monitor.js";
10
11
  import { registerWorkflowLane, pollWorkflowLane, stopWorkflowLane } from "./task-registry-workflow.js";
11
- import { mintCompletionId, canAccessWorkflowRun, formatWorkflowRun, clipTaskOutput, assertOwnership, sleepPollStep, statusFromBackground, rollSpoolText, accountDroppedBytes, renderSpoolBody, stdoutHeadingOf, REPLAY_FACE, SPOOL_REPLAY, INCREMENT_REPLAY, spoolDropNote, droppedGapNote, alreadyTerminalStopNote, terminalTaskSummary, TASK_OUTPUT_MAX_CHARS, MONITOR_BATCH_WINDOW_MS, MONITOR_DEFAULT_TIMEOUT_MS, MONITOR_MAX_TIMEOUT_MS, MONITOR_MAX_BATCHES_PER_MINUTE, canAccess, DURABLE_AGENT_HANDLE_RE, } from "./task-registry-shared.js";
12
+ import { mintCompletionId, taskReadHandleText, canAccessWorkflowRun, formatWorkflowRun, clipTaskOutput, assertOwnership, sleepPollStep, statusFromBackground, rollSpoolText, accountDroppedBytes, renderSpoolBody, stdoutHeadingOf, REPLAY_FACE, SPOOL_REPLAY, INCREMENT_REPLAY, spoolDropNote, droppedGapNote, alreadyTerminalStopNote, terminalTaskSummary, TASK_OUTPUT_MAX_CHARS, MONITOR_BATCH_WINDOW_MS, MONITOR_DEFAULT_TIMEOUT_MS, MONITOR_MAX_TIMEOUT_MS, MONITOR_MAX_BATCHES_PER_MINUTE, canAccess, DURABLE_AGENT_HANDLE_RE, } from "./task-registry-shared.js";
12
13
  export { normalizeAgentName, DURABLE_AGENT_HEARTBEAT_MS, DURABLE_AGENT_HANDLE_RE, BG_AGENT_REAP_STOP_ERROR, engineAgentName, chosenAgentName } from "./task-registry-shared.js";
13
14
  import { TASK_OUTPUT_TOOL_NAME, TASK_STOP_TOOL_NAME, TASK_OUTPUT_MISSING_ID_MESSAGE, TASK_STOP_MISSING_ID_MESSAGE, TASK_STOP_PARAMS, resolveTaskIdArg, REGISTRY_TASK_TOOL_CAPS, composeTaskOutputDescription, composeTaskOutputParams, composeTaskStopDescription, } from "./task-tool-shape.js";
14
- import { durableAgentArmedLane, durableAgentRowProbeLane, beginDurableClaimLane, endDurableClaimLane, reapDurableAgentsLane, noteBackgroundAgentActivityLane, reapStaleSessionBackgroundAgentsLane, releaseDurableTranscriptAnchorLane, bindBackgroundAgentSessionLane, registerBackgroundAgentLane, recordBackgroundAgentOrgAdmissionLane, parkBackgroundAgentLane, reconcileParkedAgentsLane, claimParkedAgentLane, rollbackParkedClaimLane, consumeParkedFlipLane, finalizeParkedResumeLane, settleBackgroundAgentLane, abortBackgroundAgentsForOwnerLane, serveDurableAgentRowLane, resolveBackgroundAgentByNameLane, backgroundAgentCycleSeqLane, activeDelegationHandlesLane, markRetainedContinuationLane, reviveBackgroundAgentLane, settleRevivedAgentLane, unmarkRetainedContinuationLane, attachAgentNotifyLane, deliverToRunningAgentLane, runningBackgroundAgentLabelsLane, runningAgentFooterLane, notFoundRunningAgentsTail, pollBackgroundAgentLane, stopBackgroundAgentLane, } from "./task-registry-agent.js";
15
+ import { durableAgentArmedLane, durableAgentRowProbeLane, beginDurableClaimLane, endDurableClaimLane, reapDurableAgentsLane, noteBackgroundAgentActivityLane, reapStaleSessionBackgroundAgentsLane, releaseDurableTranscriptAnchorLane, bindBackgroundAgentSessionLane, childSessionAnchorOf, registerBackgroundAgentLane, recordBackgroundAgentOrgAdmissionLane, parkBackgroundAgentLane, reconcileParkedAgentsLane, claimParkedAgentLane, rollbackParkedClaimLane, consumeParkedFlipLane, finalizeParkedResumeLane, settleBackgroundAgentLane, abortBackgroundAgentsForOwnerLane, serveDurableAgentRowLane, resolveBackgroundAgentByNameLane, backgroundAgentCycleSeqLane, activeDelegationHandlesLane, markRetainedContinuationLane, reviveBackgroundAgentLane, settleRevivedAgentLane, unmarkRetainedContinuationLane, attachAgentNotifyLane, deliverToRunningAgentLane, runningBackgroundAgentLabelsLane, runningAgentFooterLane, notFoundRunningAgentsTail, pollBackgroundAgentLane, stopBackgroundAgentLane, } from "./task-registry-agent.js";
15
16
  import { mountRuleFace, toolFace } from "./tool-catalog-entries.js";
16
17
  import { thrownText } from "./thrown-value.js";
17
18
  import { agentStateSourceOfHandle, agentStateSourceOfRecord, agentStateSummary, readAgentState } from "./agent-state.js";
@@ -81,10 +82,29 @@ async function drainBashTailBestEffort(handle) {
81
82
  catch {
82
83
  }
83
84
  }
84
- function bashMirrorGapNote(handle) {
85
- return handle.outputFile !== undefined && handle.spool?.mirrorFailed === true
86
- ? " [!] The output file is INCOMPLETE (one or more writes to it failed) — trust the result text / TaskOutput over the file."
87
- : "";
85
+ function commandRecordSink(rowOf, record, guarded, sink) {
86
+ return (n) => {
87
+ const row = rowOf(n.task_id);
88
+ if ((row?.type !== "background_bash" && row?.type !== "monitor") || n.status === "event")
89
+ return sink(n);
90
+ const gap = row.outputFile === undefined ? "missing" : row.spool?.mirrorFailed === true ? "incomplete" : undefined;
91
+ if (gap === undefined)
92
+ return sink(n);
93
+ const retained = row.spool !== undefined && row.spool.stdout.length + row.spool.stderr.length > 0 ? row.spool : undefined;
94
+ if (row.taskArtifacts === undefined || retained === undefined)
95
+ return sink(gap === "incomplete" ? { ...n, summary: n.summary + commandRecordGapNote(row, gap, undefined) } : n);
96
+ const body = renderSpoolBody(retained, { running: false, handleStatus: row.status, shape: (text) => text, rolledExtraClause: "", drainNote: "" });
97
+ void persistTaskArtifact(row.taskArtifacts, row.id, body).then((artifact) => {
98
+ const ref = artifact.kind === "stored" ? artifact.ref : undefined;
99
+ if (ref !== undefined)
100
+ record(row.id, ref);
101
+ guarded(() => sink(ref === undefined && gap === "missing" ? n : { ...n, summary: n.summary + commandRecordGapNote(row, gap, ref) }));
102
+ });
103
+ };
104
+ }
105
+ function commandRecordGapNote(row, gap, ref) {
106
+ const head = gap === "incomplete" ? ` [!] Its output file ${row.outputFile} is incomplete (an append failed) — do not read it as the whole output` : " [!] No output file holds its output (the file could not be created)";
107
+ return ref === undefined ? `${head}.` : `${head}; what the engine retained (its head and tail, any gap stated) is stored: read it with ReadToolResult (ref "${ref}").`;
88
108
  }
89
109
  function explicitStopBashTerminalNote(handle, alreadyGone) {
90
110
  const resultText = handle.spool !== undefined ? bashTerminalResult(handle.spool) : "";
@@ -98,7 +118,7 @@ function explicitStopBashTerminalNote(handle, alreadyGone) {
98
118
  ...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
99
119
  status: "killed",
100
120
  ...(handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
101
- summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "killed")} — ${detail}${bashMirrorGapNote(handle)}${handle.spool !== undefined ? droppedGapNote(handle.spool) : ""}`,
121
+ summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "killed")} — ${detail}${handle.spool !== undefined ? droppedGapNote(handle.spool) : ""}`,
102
122
  ...(resultText.length > 0 ? { result: resultText, partial: true } : {}),
103
123
  ...(handle.completionId !== undefined ? { completionId: handle.completionId } : {}),
104
124
  });
@@ -146,8 +166,8 @@ export class TaskRegistry {
146
166
  async reapDurableAgents(scope, deps, policy) {
147
167
  return reapDurableAgentsLane(this.core, scope, deps, policy);
148
168
  }
149
- releaseDurableTranscriptAnchor(id) {
150
- return releaseDurableTranscriptAnchorLane(this.core, id);
169
+ releaseDurableTranscriptAnchor(id, sessionId) {
170
+ return releaseDurableTranscriptAnchorLane(this.core, id, sessionId);
151
171
  }
152
172
  bindBackgroundAgentSession(id, sessionId) {
153
173
  return bindBackgroundAgentSessionLane(this.core, id, sessionId);
@@ -247,8 +267,8 @@ export class TaskRegistry {
247
267
  runningBackgroundAgentLabels(access) {
248
268
  return runningBackgroundAgentLabelsLane(this.core, access);
249
269
  }
250
- async pollBackgroundAgent(handle, deadline, signal, oneShot, toolResultStore, sessionId, checkpointSeat) {
251
- return pollBackgroundAgentLane(handle, deadline, signal, oneShot, toolResultStore, sessionId, checkpointSeat);
270
+ async pollBackgroundAgent(handle, deadline, signal, toolResultStore, sessionId, checkpointSeat) {
271
+ return pollBackgroundAgentLane(handle, deadline, signal, toolResultStore, sessionId, checkpointSeat);
252
272
  }
253
273
  async stopBackgroundAgent(handle) {
254
274
  return stopBackgroundAgentLane(this.core, handle);
@@ -273,6 +293,7 @@ export class TaskRegistry {
273
293
  if (this.handles.has(id))
274
294
  throw new Error(`TaskRegistry: task id already registered: ${id}`);
275
295
  const now = input.now ?? Date.now();
296
+ const onTerminal = input.onTerminal !== undefined ? this.commandRecordSink(input.onTerminal) : undefined;
276
297
  this.handles.set(id, {
277
298
  id,
278
299
  type: "background_bash",
@@ -286,18 +307,22 @@ export class TaskRegistry {
286
307
  updatedAt: now,
287
308
  env: input.env,
288
309
  shellId: input.shellId,
289
- ...(input.onTerminal !== undefined ? { onTerminal: input.onTerminal } : {}),
310
+ ...(onTerminal !== undefined ? { onTerminal } : {}),
290
311
  ...(input.outputFile !== undefined ? { outputFile: input.outputFile } : {}),
312
+ ...(input.taskArtifacts !== undefined ? { taskArtifacts: input.taskArtifacts } : {}),
291
313
  ...(retainsBackgroundProcesses({ env: envDeclaresRetain(input.env), task: input.retainBackgroundProcesses === true }) ? { retained: true } : {}),
292
314
  ...(input.retainBackgroundProcesses !== undefined ? { retainStatedAtLaunch: true } : {}),
293
315
  });
294
- if (input.onTerminal)
295
- this.startBashWatcher(id, input.onTerminal);
316
+ if (onTerminal)
317
+ this.startBashWatcher(id, onTerminal);
296
318
  return id;
297
319
  }
320
+ commandRecordSink(sink) {
321
+ return commandRecordSink((id) => this.handles.get(id), (id, ref) => this.recordArtifactRef(id, ref, 0), (send) => this.notifier.notify(send, "taskRegistry.commandRecordSink"), sink);
322
+ }
298
323
  isBackgroundOutputFile(canonicalPath, access, env) {
299
324
  for (const handle of this.handles.values()) {
300
- if (handle.type !== "background_bash" || handle.outputFile === undefined)
325
+ if ((handle.type !== "background_bash" && handle.type !== "monitor") || handle.outputFile === undefined)
301
326
  continue;
302
327
  if (handle.env !== env)
303
328
  continue;
@@ -399,6 +424,22 @@ export class TaskRegistry {
399
424
  getCompletionId(id) {
400
425
  return this.handles.get(id)?.completionId;
401
426
  }
427
+ recordArtifactRef(id, ref, cycle) {
428
+ const h = this.handles.get(id);
429
+ if (h === undefined)
430
+ return;
431
+ if ((h.type === "background_agent" ? (h.reviveCycle ?? 0) : 0) !== cycle)
432
+ return;
433
+ h.artifactRef = ref;
434
+ }
435
+ artifactBoundaryLegs(ref, access, tree) {
436
+ const id = taskArtifactOriginOf(ref);
437
+ return id === undefined ? { legs: [] } : this.boundaryLegsOf(id, access, "output", tree);
438
+ }
439
+ readHandleOf(id, access) {
440
+ const h = this.handles.get(id);
441
+ return h !== undefined && canAccess(h, access) ? taskReadHandleText(h) : undefined;
442
+ }
402
443
  markStopSourceForOwner(access, source, opts) {
403
444
  let marked = 0;
404
445
  for (const handle of this.handles.values()) {
@@ -470,7 +511,7 @@ export class TaskRegistry {
470
511
  ...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
471
512
  status: "killed",
472
513
  stoppedBy: handle.stoppedBy,
473
- summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "killed")} — killed before completion (${clause(handle.stoppedBy)})${killFailed ? ` — kill attempt reported ${kill.ok ? "" : kill.error.code}: the process may still be terminating; the environment teardown retries` : ""}${bashMirrorGapNote(handle)}`,
514
+ summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "killed")} — killed before completion (${clause(handle.stoppedBy)})${killFailed ? ` — kill attempt reported ${kill.ok ? "" : kill.error.code}: the process may still be terminating; the environment teardown retries` : ""}`,
474
515
  ...(resultText.length > 0 ? { result: resultText, partial: true } : {}),
475
516
  ...(handle.completionId !== undefined ? { completionId: handle.completionId } : {}),
476
517
  }));
@@ -765,7 +806,7 @@ export class TaskRegistry {
765
806
  ...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
766
807
  ...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
767
808
  status: "failed",
768
- summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "failed")} — lost its background process (${r.error.message}); no further output will arrive.${bashMirrorGapNote(handle)}`,
809
+ summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "failed")} — lost its background process (${r.error.message}); no further output will arrive.`,
769
810
  ...(lostResult.length > 0 ? { result: lostResult } : {}),
770
811
  ...(handle.completionId !== undefined ? { completionId: handle.completionId } : {}),
771
812
  }));
@@ -813,7 +854,6 @@ export class TaskRegistry {
813
854
  ? `${terminalTaskSummary("bash", desc, "killed")} — timed out after ${r.value.timeoutSec}s (its own background time budget); the process was killed`
814
855
  : `${terminalTaskSummary("bash", desc, "killed")} — timed out (its own background time budget); the process was killed`
815
856
  : `${terminalTaskSummary("bash", desc, handle.status === "completed" ? "completed" : handle.status === "killed" ? "killed" : "failed")} — ${r.value.status}`) +
816
- bashMirrorGapNote(handle) +
817
857
  droppedGapNote(spool),
818
858
  ...(resultText.length > 0 ? { result: resultText } : {}),
819
859
  ...(handle.status === "killed" && resultText.length > 0 ? { partial: true } : {}),
@@ -837,7 +877,7 @@ export class TaskRegistry {
837
877
  ...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
838
878
  ...(handle.outputFile !== undefined ? { output_file: handle.outputFile } : {}),
839
879
  status: "failed",
840
- summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "failed")} — lost its background process (poll failed: ${thrownText(e)}); no further output will arrive.${bashMirrorGapNote(handle)}`,
880
+ summary: `${terminalTaskSummary("bash", (handle.description ?? "background command").slice(0, 200), "failed")} — lost its background process (poll failed: ${thrownText(e)}); no further output will arrive.`,
841
881
  ...(crashedResult.length > 0 ? { result: crashedResult } : {}),
842
882
  ...(handle.completionId !== undefined ? { completionId: handle.completionId } : {}),
843
883
  }));
@@ -859,7 +899,7 @@ export class TaskRegistry {
859
899
  return out;
860
900
  }
861
901
  registerMonitor(input) {
862
- return registerMonitorLane(this.core, input);
902
+ return registerMonitorLane(this.core, input.onEvent !== undefined ? { ...input, onEvent: this.commandRecordSink(input.onEvent) } : input);
863
903
  }
864
904
  registerWorkflow(input) {
865
905
  return registerWorkflowLane(this.core, input);
@@ -883,7 +923,7 @@ export class TaskRegistry {
883
923
  if (handle.type === "background_bash")
884
924
  return this.pollBackgroundBash(handle, taskId, access, opts.filter, deadline, opts.signal);
885
925
  if (handle.type === "background_agent")
886
- return this.pollBackgroundAgent(handle, deadline, opts.signal, opts.oneShot, opts.toolResultStore, access.sessionId, opts.checkpointSeat);
926
+ return this.pollBackgroundAgent(handle, deadline, opts.signal, opts.toolResultStore, access.sessionId, opts.checkpointSeat);
887
927
  if (handle.type === "monitor")
888
928
  return this.pollMonitor(handle, opts.filter, deadline, opts.signal);
889
929
  return this.pollWorkflow(handle, access, deadline, opts.signal);
@@ -1031,6 +1071,7 @@ The durable record is still marked running (last update ${new Date(row.updatedAt
1031
1071
  for (const h of this.handles.values()) {
1032
1072
  if (!canAccess(h, access))
1033
1073
  continue;
1074
+ const childSession = childSessionAnchorOf(h);
1034
1075
  out.push({
1035
1076
  task_id: h.id,
1036
1077
  type: h.type,
@@ -1039,6 +1080,7 @@ The durable record is still marked running (last update ${new Date(row.updatedAt
1039
1080
  ...((h.type === "background_bash" || h.type === "monitor") && shellRowRetained(h) ? { retained: true } : {}),
1040
1081
  ...(h.description !== undefined ? { description: h.description } : {}),
1041
1082
  ...(h.toolUseId !== undefined ? { toolUseId: h.toolUseId } : {}),
1083
+ ...(childSession !== undefined ? { sessionId: childSession } : {}),
1042
1084
  createdAt: h.createdAt,
1043
1085
  updatedAt: h.updatedAt,
1044
1086
  });
@@ -1277,7 +1319,7 @@ The durable record is still marked running (last update ${new Date(row.updatedAt
1277
1319
  const retrieval_status = r.error.code === "timeout" ? "timeout" : "not_ready";
1278
1320
  return {
1279
1321
  content: `Error (TaskStop): ${r.error.message} — the kill did not land; the process may still be running.` +
1280
- (restored ? " Its watcher keeps running: TaskOutput still works and the completion notification will still fire." : " TaskOutput still reflects its live status."),
1322
+ (restored ? " Its watcher keeps running: its output file keeps filling and the completion notification will still fire." : " It has no watcher, so no completion notification will follow."),
1281
1323
  details: { task_id: handle.id, type: "background_bash", status: handle.status, retrieval_status, error: r.error.code },
1282
1324
  isError: true,
1283
1325
  };
@@ -1354,7 +1396,6 @@ export function createTaskOutputTool(opts) {
1354
1396
  block: args.block !== false,
1355
1397
  timeoutMs: effectiveTimeoutMs,
1356
1398
  signal: ctx.signal,
1357
- oneShot: opts.oneShot,
1358
1399
  toolResultStore: opts.toolResultStore,
1359
1400
  checkpointSeat: opts.checkpointSeat,
1360
1401
  });
@@ -419,7 +419,7 @@ export interface TaskResult {
419
419
  * of silence. Present only when at least one applies (absent = nothing to disclose), so a consumer that
420
420
  * ignores the field is unchanged. A rewind that could NOT be delivered as asked is NOT a note — it is a
421
421
  * terminal failure (`rewind_snapshot.unresolvable` / `rewind.store_unconfigured` /
422
- * `rewind.restore_failed` / `rewind.invalid_spec` / `rewind.rewind_files_retired` /
422
+ * `rewind.restore_failed` / `rewind.invalid_spec` /
423
423
  * `rewind.conflicting_targets` / `rewind.child_scope_unsupported` / `rewind.capture_disabled`).
424
424
  *
425
425
  * - `conversation_only` — {@link TaskSpec.resumeAt} branched the transcript WITHOUT
@@ -776,11 +776,8 @@ export interface TaskResult {
776
776
  * mechanism engaged this leg; absent = none did (byte-compatible).
777
777
  */
778
778
  mechanisms?: {
779
- /** design/132: the natural-end final-verification reminder was injected this run. */
780
- finalVerifyInjected?: true;
781
- /** oracle-grounding gate (opus LOW 复审, additive): HOW MANY final-verification injections
782
- * fired this run — 1 = the R9 one-shot only, 2 = R9 + the grounding re-entry (hard cap).
783
- * Present iff `finalVerifyInjected` is (the boolean stays for compatibility, RL-1336-finalverify-bool). */
779
+ /** design/132: HOW MANY natural-end final-verification injections fired this run — 1 = the R9 one-shot
780
+ * only, 2 = R9 + the oracle-grounding re-entry (hard cap). Present iff at least one fired. */
784
781
  finalVerifyInjections?: number;
785
782
  /** design/133: number of attachment blocks injected this run — turn-boundary bundles
786
783
  * (todo/task reminders, changed-files notes, plan-mode re-reminders, listing drift frames;
@@ -874,8 +871,6 @@ export interface TaskResult {
874
871
  * subagent cost (it lands in `nested`, see assemble-result.ts), so `nestedSubagentMicroUsd` sits
875
872
  * OUTSIDE the costMicroUsd identity, not inside it (measured correction: the previous wording
876
873
  * `llmRoot + nested + compaction === costMicroUsd` only held when nested was 0).
877
- * (`memoryConsolidationMicroUsd` is a separate, budget-excluded line, permanently 0 since the
878
- * runner-integrated consolidation pass was retired — design/157 B19 — and NOT part of any identity).
879
874
  * Present whenever stats are assembled, EXCEPT when `costMicroUsd` is absent for unpriced spend
880
875
  * (RB-368) — the taxonomy would partition a fabricated total, so it is omitted together with it.
881
876
  */
@@ -889,10 +884,6 @@ export interface TaskResult {
889
884
  llmRootMicroUsd: number;
890
885
  /** Delegated sub-agent (nested) LLM cost (micro-USD) = `nested?.costMicroUsd ?? 0`. */
891
886
  nestedSubagentMicroUsd: number;
892
- /** Post-task memory-consolidation LLM cost (micro-USD). Permanently 0 since design/157 B19 retired
893
- * the runner-integrated consolidation pass (kept: public stats contract; an engine-plane re-mount —
894
- * design/138 §7 — would fill it). A separate, budget-excluded line. */
895
- memoryConsolidationMicroUsd: number;
896
887
  /** design/100 §E12 — prompt-suggestion pass LLM cost (micro-USD) = `suggestions?.costMicroUsd ?? 0`; filled
897
888
  * asynchronously after the (post-completion) pass (0 until then). A separate, budget-excluded line. */
898
889
  suggestionsMicroUsd?: number;
@@ -441,11 +441,8 @@ export interface TaskSpec {
441
441
  *
442
442
  * There is NO capture request anymore: first-touch tracking is ON whenever a `RunnerDeps.fileHistoryStore`
443
443
  * is wired, `RunnerDeps.fileHistoryCapture` is not `"off"`, and no {@link fileHistory} off switch is set (per-edited-file backups are near-zero cost — no tree walk,
444
- * no size gate), which is what retired the old `rewindFiles` capture request. The retired
445
- * `rewindFiles` spelling is handled at prepare: its capture sense (true, no `resumeAt`) is a
446
- * tolerated no-op with a deprecation disclosure (the intent is structurally satisfied); its restore
447
- * sense (true, with `resumeAt`) is a typed retirement rejection naming THIS field — the restore
448
- * semantics genuinely changed (whole-tree ⇒ tracked set), so that migration must be explicit.
444
+ * no size gate). The retired `rewindFiles` key is refused by name at prepare (`config.spec_retired_key`) in
445
+ * both of its old senses; the restore sense is THIS field.
449
446
  */
450
447
  restoreFiles?: boolean;
451
448
  /**
@@ -820,7 +817,7 @@ export interface TaskSpec {
820
817
  * their own fake self-check; prompt discipline alone (1.242) had a low landing rate. Opt-in
821
818
  * because the evidence is from UNATTENDED long-task legs; consumers default it OFF and expose an
822
819
  * explicit opt-in (ruled 2026-08-04). Interactive deployments choose per scenario. Read-only /
823
- * Q&A runs never trigger it. Telemetry: `stats.mechanisms.finalVerifyInjected`.
820
+ * Q&A runs never trigger it. Telemetry: `stats.mechanisms.finalVerifyInjections`.
824
821
  */
825
822
  finalVerification?: boolean;
826
823
  /**
@@ -1076,6 +1073,17 @@ export interface TaskSpec {
1076
1073
  * Persists on the checkpoint's data half (`CheckpointState.inheritedGate.permissionMode`), re-judged on every leg.
1077
1074
  */
1078
1075
  permissionMode?: PermissionMode;
1076
+ /**
1077
+ * In `auto` mode, let no shell allow entry clear a call — the classifier judges it (the reference's
1078
+ * `autoMode.classifyAllShell`). `true` ⇒ while the mode is `auto` (read per call), the whole shell tool, a name that reaches
1079
+ * it and every `Bash(…)` rule whatever it names stand down — in stored rules, a skill's `allowed-tools`, {@link allowedTools}
1080
+ * and the deployment's list alike. Absent / `false` ⇒ only the entries that hand over arbitrary code stand down. Narrows only;
1081
+ * outside `auto`, and for deny / ask rules, a hook's allow, non-shell entries and a read-only command, nothing changes. Which settings planes may set it is the host's
1082
+ * reading (the reference: user, flag and managed settings, never a repository's own); the host sends its allow lists
1083
+ * unchanged beside it. Tighten-only: `tightenTaskSpec` keeps a baseline's `true`, an engine-built child inherits it. A
1084
+ * present non-boolean refuses the run (`config.invalid_argument`).
1085
+ */
1086
+ classifyAllShell?: boolean;
1079
1087
  /** Task-scoped MCP servers, materialized into tools then disposed. */
1080
1088
  mcp?: McpServerSpec[];
1081
1089
  /** Task-scoped A2A peers (remote agents), whose advertised skills mount as `a2a__<peer>__<skill>`
@@ -1115,7 +1123,7 @@ export interface TaskSpec {
1115
1123
  * deployment's {@link import("./runner-deps.js").RunnerDeps.allowedTools}, under the same predicate: deny and ask rules
1116
1124
  * still win, and a question no allow rule clears (a mandated, governance, hook or plan question) is still put to a person,
1117
1125
  * with the entry disclosed on the card. In `auto` mode an entry that hands over arbitrary code (the whole shell, an
1118
- * interpreter or launcher prefix) is left to the classifier.
1126
+ * interpreter or launcher prefix) is left to the classifier — every shell entry, under {@link classifyAllShell}.
1119
1127
  *
1120
1128
  * Lives for this run — the steers it takes in included; a delegated child holds the entries until it ends; a resumed leg
1121
1129
  * holds them only when its spec supplies them again (they are not written into a checkpoint). An entry this grammar
@@ -270,7 +270,7 @@ export interface TaskStream extends AsyncIterable<TaskEvent> {
270
270
  * `memory.capture_optout_unavailable` (this run mounted no memory session — nothing to opt out
271
271
  * of), `memory.capture_optout_sweep_failed` (the record STANDS but the §2.3 boundary sweep could
272
272
  * not contain named residue paths — a repeat call is the retry lane),
273
- * `config.memory_capture_unsupported` (remote/per-run deployment shape with no
273
+ * `config.memory_capture_unsupported` (an execution env whose paths are not the host's, with no
274
274
  * {@link RunnerDeps.memoryCaptureRecordStore} — the record would not survive to a resume
275
275
  * replica), `steering.invalid_content` (a non-string `options.reason`), plus the steer-family
276
276
  * `steering.not_running` once the task has finished. Resolves `{ outcome }`: `"created"` = this
@@ -141,6 +141,16 @@ export type TerminalCause = {
141
141
  * Absent on pre-identity checkpoints.
142
142
  */
143
143
  checkpointId?: string;
144
+ /**
145
+ * The id of the tool call that asked for this plan_review pause — the call that PRESENTED the plan (the
146
+ * `ExitPlanMode` call for the first-party plan tool), so a card can join the pause to that call by id instead of
147
+ * by adjacency. PRESENT only on a `plan_review` pause whose requester carried a call id; ABSENT on every other
148
+ * pause and on a plan_review pause whose requester had none (a row a deployment minted itself, a revive context). It
149
+ * is provenance, not a binding: the pause gates no call, so no `tool_approval` field rides beside it, and the
150
+ * resume never reads it. Echo of the committed row's {@link import("./checkpoint-store.js").PendingAction}
151
+ * `plan_review.requestedByCallId` — one write, at the park mint.
152
+ */
153
+ requestedByCallId?: string;
144
154
  /**
145
155
  * HOW the paused task's remote workspace will come back, present whenever the pause captured a
146
156
  * remote workspace. The two modes bill and behave very differently:
@@ -134,7 +134,7 @@ export const TOOL_CATALOG_ENTRIES = [
134
134
  { id: "report-findings", name: "ReportFindings", source: "builtin", definedIn: "src/core/runner/synthetic-tools.ts", mountedBy: ["always"], cards: ["report-findings"], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.report_findings@1"), ruleFace: { params: ["level"] } } },
135
135
  { id: "structured-output", name: OUTPUT_TOOL_NAME, protocol: ["structured"], source: "synthetic", definedIn: "src/core/runner/synthetic-tools.ts", mountedBy: ["optional"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.structured_output@1") } },
136
136
  { id: "skill", name: "Skill", source: "builtin", definedIn: "src/core/runner/synthetic-tools.ts", mountedBy: ["optional"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.skill@1"), renderHints: { approvalCard: "skill" }, ruleFace: { params: ["skill", "args"] } } },
137
- { id: "read-tool-result", name: "ReadToolResult", source: "builtin", definedIn: "src/core/tool-result-store.ts", mountedBy: ["optional"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.read_tool_result@1"), budgetExempt: true, ruleFace: { params: ["ref", "offset", "limit"] } } },
137
+ { id: "read-tool-result", name: "ReadToolResult", source: "builtin", definedIn: "src/core/tool-result-store.ts", mountedBy: ["optional"], cards: [], face: { family: "scaffold", boundaryLegs: "per_call", effect: "read", contract: c("core.read_tool_result@1"), budgetExempt: true, ruleFace: { params: ["ref", "offset", "limit"] } } },
138
138
  { id: "tool-search", name: "ToolSearch", source: "builtin", definedIn: "src/core/runner/tool-disclosure.ts", mountedBy: ["optional"], cards: ["tool-search"], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.tool_search@1"), ruleFace: { params: ["query", "max_results"] } } },
139
139
  { id: "advisor", name: "advisor", source: "builtin", definedIn: "src/core/runner/advisor-tool.ts", mountedBy: ["optional"], cards: ["advisor"], face: { family: "scaffold", boundaryLegs: [], effect: "read", contentOrigin: "local", contract: c("core.advisor@1"), offload: false, budgetExempt: true, ruleFace: { params: [] } } },
140
140
  { id: "ask-user-question", name: "AskUserQuestion", source: "builtin", definedIn: "src/core/ask-question.ts", mountedBy: ["optional"], cards: ["ask-question"], face: { family: "other", boundaryLegs: [], effect: "read", contract: c("core.ask_user_question@1"), renderHints: { approvalCard: "question" }, ruleFace: { params: [] } } },
@@ -20,6 +20,7 @@ export type ToolCheckReading = {
20
20
  } | {
21
21
  readonly kind: "denied";
22
22
  readonly deny: PermissionResult;
23
+ readonly by?: string;
23
24
  } | {
24
25
  readonly kind: "asked";
25
26
  readonly ask: Extract<PermissionResult, {
@@ -5,17 +5,17 @@ import { failedHandlerClause } from "./mods/stations.js";
5
5
  const STANDS = Object.freeze({ kind: "stands" });
6
6
  function readToolCheck(heard, standing, call, mayClear) {
7
7
  const { toolName } = call;
8
- const refused = (message) => ({ kind: "denied", deny: refusalOf({ action: "deny", message, decisionReason: "hook" }, call.judged) });
8
+ const refused = (message, by) => ({ kind: "denied", deny: refusalOf({ action: "deny", message, decisionReason: "hook" }, call.judged), ...(by !== undefined ? { by } : {}) });
9
9
  if (heard.kind === "aborted")
10
10
  return refused(`the task was cancelled while a tool.check handler was still checking this call to "${toolName}"; the call was NOT executed (fail-closed)`);
11
11
  if (heard.kind === "failed")
12
- return refused(`a tool.check handler ${failedHandlerClause(heard)} while checking this call to "${toolName}"; the call was NOT executed (fail-closed)`);
12
+ return refused(`a tool.check handler ${failedHandlerClause(heard)} while checking this call to "${toolName}"; the call was NOT executed (fail-closed)`, heard.registration);
13
13
  if (heard.by === undefined && heard.decision === standing.action)
14
14
  return STANDS;
15
15
  const { who, why } = speakerOf(heard);
16
16
  const rewritten = call.rewrite !== undefined ? { updatedInput: call.rewrite } : {};
17
17
  if (heard.decision === "deny")
18
- return refused(`tool "${toolName}" denied by ${who}${why}`);
18
+ return refused(`tool "${toolName}" denied by ${who}${why}`, heard.by);
19
19
  if (heard.decision === "ask") {
20
20
  return standing.action === "ask"
21
21
  ? { kind: "asked", ask: { ...standing, decisionReason: "hook", ...(heard.reason !== undefined ? { message: heard.reason } : {}) }, minted: false }
@@ -9,15 +9,16 @@
9
9
  * the prepare path, and the public surface is tiered by where a symbol is declared (`readToolAxes` is `advanced` for the same reason).
10
10
  */
11
11
  import { type McpServerSpec } from "./mcp-server-spec.js";
12
+ /** Every member name a face declaration has, at any depth — the words a `toolFaces` refusal's member path spells (derived from the tables above). */
13
+ export declare const TOOL_FACE_WORDS: ReadonlySet<string>;
12
14
  /**
13
15
  * {@link readToolFaces}'s answer. `ok: true` hands back a copy of the faces that the reader itself built, plain data and none of the caller's own
14
16
  * objects; `faces` is absent when nothing is declared (no key at all, or an empty record). `ok: false` carries one sentence (its detail cut at
15
- * 240 characters) naming the tool and the member that did not fit. What it may quote of the declaration is its structure and nothing of its content:
16
- * a tool or member name (quoted, a tool name cut at 80 characters), the word a closed table refuses, a key or a list entry over its bound (its
17
- * first 40 characters), a key a pattern parameter names, a count and its bound. It never quotes display text (`userFacingName`, `activity`) or
18
- * the entries of a list that fits. These are the mount's judge's own sentences, the ones it announces at the listing, so the reader and the mount
19
- * tell one operator one thing; `readToolAxes` refuses in the same sentence shape and names no word because an axis word is never a name the
20
- * operator needs echoed to find the fault.
17
+ * 240 characters) pointing at the tool and the member that did not fit. It says the face's own member names, the closed words a member takes,
18
+ * kinds, counts and bounds; it never says the declaration's content — a tool name, an unknown member's name, a word a closed table refuses, a
19
+ * parameter name, a list entry, display text: each is shown in the one caller's-text shape (`callerText`: the redaction mark and its length).
20
+ * These are the mount's judge's own sentences, the ones it announces at the listing, so the reader and the mount tell one operator one thing;
21
+ * `readToolAxes` refuses in the same sentence shape.
21
22
  */
22
23
  export type ToolFacesRead = {
23
24
  ok: true;
@@ -1,4 +1,4 @@
1
- import { dataKind, perToolEmptyName, perToolEntryRefusal, quotedName, receivePerToolDeclaration } from "./mcp-server-spec.js";
1
+ import { callerText, dataKind, perToolEmptyName, perToolEntryRefusal, receivePerToolDeclaration } from "./mcp-server-spec.js";
2
2
  import { isPlainRecord } from "./mods/kernel/receive.js";
3
3
  import { faceProblem } from "./runner/tool-face-overlay.js";
4
4
  import { inlineUntrusted } from "./untrusted-text.js";
@@ -9,6 +9,7 @@ const HOST_TARGET_KINDS = { param: "string" };
9
9
  const HOST_TARGET_REQUIRED = ["param"];
10
10
  const RENDER_HINT_KINDS = { userFacingName: "string", activity: "string", summaryParams: "list", resultCards: "list", approvalCard: "string" };
11
11
  const RULE_FACE_KINDS = { primaryParams: "list", params: "list", nameValues: "list" };
12
+ export const TOOL_FACE_WORDS = new Set([TOOL_FACE_MEMBERS, PATH_TARGET_KINDS, HOST_TARGET_KINDS, RENDER_HINT_KINDS, RULE_FACE_KINDS].flatMap((table) => Object.keys(table)));
12
13
  function kindProblem(label, value, kind) {
13
14
  if (value === undefined)
14
15
  return undefined;
@@ -20,7 +21,7 @@ function membersOf(raw, label, names) {
20
21
  if (!isPlainRecord(raw))
21
22
  return `${label} is ${dataKind(raw)}, not an object`;
22
23
  const unknown = Object.keys(raw).find((member) => !names.includes(member));
23
- return unknown === undefined ? raw : `${label} has the unknown member ${quotedName(unknown)} (the members are ${names.join(", ")})`;
24
+ return unknown === undefined ? raw : `${label} has an unknown member ${callerText(unknown)} (the members are ${names.join(", ")})`;
24
25
  }
25
26
  function ownMember(record, name) {
26
27
  return Object.hasOwn(record, name) ? record[name] : undefined;
@@ -74,7 +75,7 @@ function readOneToolFace(raw) {
74
75
  export function readToolFaces(declared) {
75
76
  if (declared === undefined)
76
77
  return { ok: true };
77
- const received = receivePerToolDeclaration(declared, "toolFaces", "tool");
78
+ const received = receivePerToolDeclaration(declared, "toolFaces", "tool", TOOL_FACE_WORDS);
78
79
  if (!received.ok)
79
80
  return { ok: false, problem: received.problem };
80
81
  const entries = [];
@@ -65,6 +65,7 @@ export type RuleToolNameVerdict = {
65
65
  readonly kind: "unmintable_segment";
66
66
  readonly guidance: string;
67
67
  readonly currentName?: string;
68
+ readonly ambiguous?: true;
68
69
  };
69
70
  /**
70
71
  * A name in ANY protocol namespace split into its owning namespace, its peer segment and its optional tool segment —
@@ -80,6 +81,23 @@ export declare function splitNamespacedName(name: string): {
80
81
  readonly peer: string;
81
82
  readonly tool?: string;
82
83
  } | undefined;
84
+ /** One way a rule name can be read as a protocol name: the peer's MINTED segment and, when the reading names a tool, its segment. */
85
+ export interface PeerReading {
86
+ readonly ns: ProtocolNamespace;
87
+ readonly peer: string;
88
+ readonly tool?: string;
89
+ }
90
+ /**
91
+ * Every way an MCP rule name can denote a peer, when it can be read more than one way — the readings the reference's lookup takes
92
+ * of a name whose server segment may itself carry the separator: a cut at EACH `__` of the body (server = what precedes the cut,
93
+ * tool = what follows) and the whole body as a server (`mcp__a__b` is tool `b` of server `a`, and server `a__b`). The reference
94
+ * spells a server `a__b` as is; the mint folds a run of `_` and drops a trailing one ({@link mintNamespacePrefix}), so a server
95
+ * segment is read through the mint — the peer a reading names is the one the mint would spell it as. `[]` for a name with no
96
+ * second reading: no separator in the body (the one reading is {@link splitNamespacedName}'s), a glob, an empty segment on either
97
+ * side of a cut, or a namespace the reference has no spelling for (only MCP's server names reach a rule from another product).
98
+ * The first reading is the first separator's — the one `splitNamespacedName` gives.
99
+ */
100
+ export declare function peerReadingsOf(name: string): readonly PeerReading[];
83
101
  /**
84
102
  * Does a list of this behavior read a `*` in a tool name as a glob over the WHOLE name — anywhere in it, the lone `*` (every tool)
85
103
  * included? A list that RESTRICTS (`deny`, `ask`) does: it reaches every tool any of whose names the glob matches (the reference's
@@ -117,6 +135,7 @@ export type ToolNameFault = {
117
135
  readonly verdict: Exclude<RuleToolNameVerdict["kind"], "current">;
118
136
  readonly guidance?: string;
119
137
  readonly currentName?: string;
138
+ readonly ambiguous?: true;
120
139
  } | {
121
140
  readonly reason: "near_miss";
122
141
  readonly currentName: string;
@@ -1,4 +1,4 @@
1
- import { carriesNamespaceSeparator, protocolOf } from "./protocol-table.js";
1
+ import { carriesNamespaceSeparator, MCP_NAMESPACE, protocolOf } from "./protocol-table.js";
2
2
  import { mintNamespacePrefix } from "./protocol-naming.js";
3
3
  import { catalogToolNames } from "./tool-registry.js";
4
4
  export const RETIRED_TOOL_NAMES = new Map([
@@ -54,6 +54,28 @@ export function splitNamespacedName(name) {
54
54
  const [peer = "", ...rest] = name.slice(ns.prefix.length).split(NAMESPACE_SEPARATOR);
55
55
  return rest.length > 0 ? { ns, peer, tool: rest.join(NAMESPACE_SEPARATOR) } : { ns, peer };
56
56
  }
57
+ export function peerReadingsOf(name) {
58
+ if (name.includes("*"))
59
+ return [];
60
+ const ns = protocolOf(name);
61
+ if (ns === undefined || ns.id !== MCP_NAMESPACE.id)
62
+ return [];
63
+ const body = name.slice(ns.prefix.length);
64
+ if (body === "" || body.startsWith(NAMESPACE_SEPARATOR))
65
+ return [];
66
+ const mintedPeer = (server) => mintNamespacePrefix(ns, server).slice(ns.prefix.length, -NAMESPACE_SEPARATOR.length);
67
+ const readings = [];
68
+ for (let at = body.indexOf(NAMESPACE_SEPARATOR); at !== -1; at = body.indexOf(NAMESPACE_SEPARATOR, at + 1)) {
69
+ const tool = body.slice(at + NAMESPACE_SEPARATOR.length);
70
+ if (tool !== "")
71
+ readings.push({ ns, peer: mintedPeer(body.slice(0, at)), tool });
72
+ }
73
+ if (readings.length === 0)
74
+ return [];
75
+ if (!body.endsWith(NAMESPACE_SEPARATOR))
76
+ readings.push({ ns, peer: mintedPeer(body) });
77
+ return readings.filter((r, i) => readings.findIndex((o) => o.peer === r.peer && o.tool === r.tool) === i);
78
+ }
57
79
  export function readsNameGlob(behavior) {
58
80
  return behavior === "deny" || behavior === "ask";
59
81
  }
@@ -86,6 +108,25 @@ function unmintableSegmentOf(split, behavior) {
86
108
  currentName: `${ns.prefix}${minted}${tool !== undefined ? `${NAMESPACE_SEPARATOR}${tool}` : ""}`,
87
109
  };
88
110
  }
111
+ function ambiguousServerSpellingOf(name, roster) {
112
+ const readings = peerReadingsOf(name);
113
+ if (readings.length === 0)
114
+ return undefined;
115
+ for (const carried of roster) {
116
+ const split = splitNamespacedName(carried);
117
+ if (split === undefined || split.tool === undefined)
118
+ continue;
119
+ if (!readings.some((r) => r.ns.id === split.ns.id && r.peer === split.peer && (r.tool === undefined || r.tool === split.tool)))
120
+ continue;
121
+ return {
122
+ kind: "unmintable_segment",
123
+ ambiguous: true,
124
+ guidance: "the name reads as more than one MCP server's. To allow it, use the tool's full name.",
125
+ currentName: carried,
126
+ };
127
+ }
128
+ return undefined;
129
+ }
89
130
  export function judgeRuleToolName(name, roster, behavior) {
90
131
  if (roster.has(name))
91
132
  return CURRENT;
@@ -94,6 +135,11 @@ export function judgeRuleToolName(name, roster, behavior) {
94
135
  const currentName = /^renamed "([^"]+)"/.exec(guidance)?.[1];
95
136
  return currentName !== undefined ? { kind: "retired", guidance, currentName } : { kind: "retired", guidance };
96
137
  }
138
+ if (behavior === "allow") {
139
+ const ambiguous = ambiguousServerSpellingOf(name, roster);
140
+ if (ambiguous !== undefined)
141
+ return ambiguous;
142
+ }
97
143
  const split = splitNamespacedName(name);
98
144
  if (split === undefined)
99
145
  return carriesNamespaceSeparator(name) && !(readsNameGlob(behavior) && name.includes("*")) ? UNPREFIXED : CURRENT;
@@ -116,7 +162,13 @@ export function toolNameFaultOf(name, roster, behavior) {
116
162
  if (verdict.kind === "unprefixed_namespace")
117
163
  return { reason: "tool_name", verdict: verdict.kind };
118
164
  if (verdict.kind !== "current") {
119
- return { reason: "tool_name", verdict: verdict.kind, guidance: verdict.guidance, ...(verdict.currentName !== undefined ? { currentName: verdict.currentName } : {}) };
165
+ return {
166
+ reason: "tool_name",
167
+ verdict: verdict.kind,
168
+ guidance: verdict.guidance,
169
+ ...(verdict.currentName !== undefined ? { currentName: verdict.currentName } : {}),
170
+ ...(verdict.kind === "unmintable_segment" && verdict.ambiguous === true ? { ambiguous: true } : {}),
171
+ };
120
172
  }
121
173
  const mounted = nearMissSpellingOf(name, roster);
122
174
  return mounted === undefined ? undefined : { reason: "near_miss", currentName: mounted };