@sema-agent/core 7.71.1 → 7.73.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 (348) hide show
  1. package/CHANGELOG.md +500 -0
  2. package/dist/agents/cross-session-ref.d.ts +2 -2
  3. package/dist/agents/cross-session-ref.js +7 -2
  4. package/dist/agents/inherited-tool-pool.d.ts +30 -2
  5. package/dist/agents/inherited-tool-pool.js +53 -7
  6. package/dist/agents/parked-resume-drive.d.ts +10 -0
  7. package/dist/agents/parked-resume-drive.js +9 -0
  8. package/dist/agents/retain-ledger.d.ts +3 -0
  9. package/dist/agents/send-message-tool.js +7 -2
  10. package/dist/agents/send-user-message-tool.d.ts +12 -0
  11. package/dist/agents/send-user-message-tool.js +67 -0
  12. package/dist/agents/subagent-steps.d.ts +9 -0
  13. package/dist/agents/subagent-steps.js +38 -0
  14. package/dist/agents/subagent.d.ts +2 -0
  15. package/dist/agents/subagent.js +47 -12
  16. package/dist/agents/verify.js +23 -7
  17. package/dist/agents/yield-adoption.js +3 -1
  18. package/dist/brain/anthropic.js +14 -9
  19. package/dist/brain/open-responses.js +4 -5
  20. package/dist/brain/openai.js +30 -23
  21. package/dist/brain/stream-engine.js +159 -151
  22. package/dist/core/a2a.d.ts +24 -3
  23. package/dist/core/a2a.js +27 -8
  24. package/dist/core/actions-digest.d.ts +43 -0
  25. package/dist/core/actions-digest.js +22 -0
  26. package/dist/core/agent-state.d.ts +28 -7
  27. package/dist/core/agent-state.js +19 -6
  28. package/dist/core/allow-entry.js +3 -3
  29. package/dist/core/approval-object.d.ts +7 -3
  30. package/dist/core/approval-object.js +30 -9
  31. package/dist/core/auto-mode.d.ts +7 -9
  32. package/dist/core/auto-mode.js +114 -8
  33. package/dist/core/checkpoint-features.d.ts +16 -5
  34. package/dist/core/checkpoint-features.js +35 -6
  35. package/dist/core/checkpoint-rekey.d.ts +1 -1
  36. package/dist/core/checkpoint-rekey.js +6 -1
  37. package/dist/core/checkpoint-requirements.d.ts +23 -3
  38. package/dist/core/checkpoint-requirements.js +5 -1
  39. package/dist/core/checkpoint-row-verdict.d.ts +1 -1
  40. package/dist/core/checkpoint-row-verdict.js +10 -4
  41. package/dist/core/checkpoint-store.d.ts +24 -2
  42. package/dist/core/checkpoint-store.js +1 -0
  43. package/dist/core/child-clamp-seats.d.ts +15 -0
  44. package/dist/core/child-clamp-seats.js +15 -0
  45. package/dist/core/delegation-frames.d.ts +1 -0
  46. package/dist/core/delegation-frames.js +1 -1
  47. package/dist/core/effective-path-target.d.ts +19 -0
  48. package/dist/core/effective-path-target.js +95 -38
  49. package/dist/core/engine-capabilities.d.ts +5 -1
  50. package/dist/core/engine-capabilities.js +1 -1
  51. package/dist/core/engine-notice.d.ts +34 -23
  52. package/dist/core/engine-version.js +1 -1
  53. package/dist/core/entries-not-applied.d.ts +19 -7
  54. package/dist/core/entries-not-applied.js +33 -1
  55. package/dist/core/file-history-store.d.ts +15 -4
  56. package/dist/core/file-history-store.js +53 -23
  57. package/dist/core/gate-fold.js +3 -1
  58. package/dist/core/governance-codes.d.ts +10 -1
  59. package/dist/core/governance-codes.js +17 -5
  60. package/dist/core/hooks.d.ts +3 -0
  61. package/dist/core/hooks.js +1 -0
  62. package/dist/core/host-instance.d.ts +23 -0
  63. package/dist/core/host-instance.js +69 -0
  64. package/dist/core/instruction-preview.d.ts +63 -0
  65. package/dist/core/instruction-preview.js +406 -0
  66. package/dist/core/judged-read.d.ts +57 -0
  67. package/dist/core/judged-read.js +1 -0
  68. package/dist/core/leg-budget.d.ts +26 -0
  69. package/dist/core/leg-budget.js +9 -0
  70. package/dist/core/leg-identity.d.ts +51 -1
  71. package/dist/core/leg-identity.js +45 -2
  72. package/dist/core/manager-launch-check.d.ts +48 -0
  73. package/dist/core/manager-launch-check.js +64 -0
  74. package/dist/core/mcp-call-meta.d.ts +2 -2
  75. package/dist/core/mcp-host-seat.d.ts +5 -0
  76. package/dist/core/mcp-host-seat.js +7 -1
  77. package/dist/core/mcp-injection-drop.d.ts +20 -10
  78. package/dist/core/mcp-injection-drop.js +9 -3
  79. package/dist/core/mcp-server-spec.d.ts +2 -1
  80. package/dist/core/mcp.js +3 -1
  81. package/dist/core/member-outcome.d.ts +3 -2
  82. package/dist/core/member-outcome.js +1 -1
  83. package/dist/core/memory-engine/deletion-record.d.ts +46 -0
  84. package/dist/core/memory-engine/deletion-record.js +96 -0
  85. package/dist/core/memory-engine/engine.js +24 -16
  86. package/dist/core/memory-engine/file-backend.js +7 -5
  87. package/dist/core/memory-engine/index.d.ts +1 -1
  88. package/dist/core/memory-engine/index.js +1 -1
  89. package/dist/core/memory-engine/layout.js +6 -4
  90. package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
  91. package/dist/core/memory-engine/projection-ledger.js +1 -1
  92. package/dist/core/memory-engine/scope-contract.d.ts +69 -11
  93. package/dist/core/memory-engine/scope-contract.js +99 -34
  94. package/dist/core/memory-engine/sync-client.js +26 -6
  95. package/dist/core/memory-engine/sync.d.ts +20 -2
  96. package/dist/core/memory-engine/sync.js +18 -17
  97. package/dist/core/mode-policy.d.ts +21 -6
  98. package/dist/core/mode-policy.js +15 -6
  99. package/dist/core/mounted-mcp.d.ts +7 -2
  100. package/dist/core/mounted-mcp.js +10 -1
  101. package/dist/core/own-property-receipt.js +11 -4
  102. package/dist/core/param-rule-reach.d.ts +8 -3
  103. package/dist/core/param-rule-reach.js +9 -1
  104. package/dist/core/parent-spec-seat.d.ts +13 -1
  105. package/dist/core/parent-spec-seat.js +18 -0
  106. package/dist/core/peer-registration.d.ts +52 -0
  107. package/dist/core/peer-registration.js +37 -0
  108. package/dist/core/peer-seat.d.ts +3 -1
  109. package/dist/core/peer-seat.js +3 -3
  110. package/dist/core/peer-task-store.d.ts +365 -0
  111. package/dist/core/peer-task-store.js +682 -0
  112. package/dist/core/permission-rule-consent.js +6 -11
  113. package/dist/core/permission-rule-model.d.ts +27 -0
  114. package/dist/core/permission-rule-model.js +34 -6
  115. package/dist/core/permission-rule-provider.d.ts +35 -33
  116. package/dist/core/permission-rule-provider.js +38 -295
  117. package/dist/core/permission-rule-store.d.ts +181 -8
  118. package/dist/core/permission-rule-store.js +420 -17
  119. package/dist/core/permission-rule-sync.js +15 -1
  120. package/dist/core/project-seat.d.ts +55 -0
  121. package/dist/core/project-seat.js +96 -0
  122. package/dist/core/protocol-http-auth.d.ts +3 -2
  123. package/dist/core/protocol-http-auth.js +26 -18
  124. package/dist/core/remote-env.d.ts +4 -4
  125. package/dist/core/retired-keys.js +1 -0
  126. package/dist/core/rule-offer-read.d.ts +1 -1
  127. package/dist/core/rule-offer-read.js +32 -4
  128. package/dist/core/run-ledger-seat.d.ts +66 -0
  129. package/dist/core/run-ledger-seat.js +70 -0
  130. package/dist/core/run-ledger.d.ts +332 -0
  131. package/dist/core/run-ledger.js +550 -0
  132. package/dist/core/runner/chain-mismatch.d.ts +32 -0
  133. package/dist/core/runner/chain-mismatch.js +29 -0
  134. package/dist/core/runner/changes-history.d.ts +1 -0
  135. package/dist/core/runner/changes-history.js +2 -2
  136. package/dist/core/runner/checkpoint-scope.d.ts +13 -3
  137. package/dist/core/runner/checkpoint-scope.js +12 -4
  138. package/dist/core/runner/construction-doors.js +6 -0
  139. package/dist/core/runner/contracts.d.ts +22 -3
  140. package/dist/core/runner/delegation-owner.d.ts +30 -0
  141. package/dist/core/runner/delegation-owner.js +20 -4
  142. package/dist/core/runner/file-history-restore.d.ts +3 -1
  143. package/dist/core/runner/file-history-restore.js +9 -6
  144. package/dist/core/runner/finish-reason-seat.js +4 -2
  145. package/dist/core/runner/leg-frame.js +3 -0
  146. package/dist/core/runner/loaded-skills.d.ts +2 -0
  147. package/dist/core/runner/loaded-skills.js +10 -0
  148. package/dist/core/runner/nested-memory-lane.d.ts +22 -5
  149. package/dist/core/runner/nested-memory-lane.js +91 -30
  150. package/dist/core/runner/person-path-rows.d.ts +23 -20
  151. package/dist/core/runner/person-path-rows.js +82 -18
  152. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
  153. package/dist/core/runner/prepare-caps-and-workflow.js +105 -90
  154. package/dist/core/runner/prepare-config-doors.d.ts +1 -0
  155. package/dist/core/runner/prepare-config-doors.js +5 -3
  156. package/dist/core/runner/prepare-context-lane.js +1 -0
  157. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  158. package/dist/core/runner/prepare-delegation-surface.js +6 -0
  159. package/dist/core/runner/prepare-execution-env.d.ts +3 -3
  160. package/dist/core/runner/prepare-file-history.js +1 -1
  161. package/dist/core/runner/prepare-hands-readface.d.ts +10 -2
  162. package/dist/core/runner/prepare-hands-readface.js +36 -22
  163. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -5
  164. package/dist/core/runner/prepare-inherited-gate.js +14 -6
  165. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -2
  166. package/dist/core/runner/prepare-memory-engine-session.js +2 -2
  167. package/dist/core/runner/prepare-memory.js +3 -15
  168. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  169. package/dist/core/runner/prepare-project-context.js +3 -7
  170. package/dist/core/runner/prepare-protocol-tools.d.ts +5 -0
  171. package/dist/core/runner/prepare-protocol-tools.js +2 -2
  172. package/dist/core/runner/prepare-run-refs.d.ts +1 -1
  173. package/dist/core/runner/prepare-run-refs.js +3 -2
  174. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
  175. package/dist/core/runner/prepare-suspend-saga.js +4 -2
  176. package/dist/core/runner/prepare-task.js +50 -37
  177. package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
  178. package/dist/core/runner/prepare-turn-wiring.js +2 -1
  179. package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -1
  180. package/dist/core/runner/prepare-wiring-manifest.js +8 -4
  181. package/dist/core/runner/read-session-changes.js +1 -1
  182. package/dist/core/runner/resume-apply.js +11 -5
  183. package/dist/core/runner/resume-checkpoint-screen.d.ts +8 -7
  184. package/dist/core/runner/resume-checkpoint-screen.js +7 -6
  185. package/dist/core/runner/resume-review-outcome.d.ts +3 -0
  186. package/dist/core/runner/resume-review-outcome.js +24 -1
  187. package/dist/core/runner/rewind-files.js +3 -2
  188. package/dist/core/runner/run-harness-handlers.js +3 -0
  189. package/dist/core/runner/run-identity-wiring.js +3 -2
  190. package/dist/core/runner/run-leg.js +9 -2
  191. package/dist/core/runner/run-notification-lane.js +20 -1
  192. package/dist/core/runner/run-settle-and-teardown.js +21 -12
  193. package/dist/core/runner/run-stop-and-final-verify.js +6 -0
  194. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  195. package/dist/core/runner/runtask.d.ts +6 -2
  196. package/dist/core/runner/runtask.js +21 -9
  197. package/dist/core/runner/shell-env-withheld.d.ts +3 -2
  198. package/dist/core/runner/shell-env-withheld.js +1 -2
  199. package/dist/core/runner/stop-tail-notice.d.ts +10 -2
  200. package/dist/core/runner/stop-tail-notice.js +9 -2
  201. package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
  202. package/dist/core/runner/stream-settle-backstop.js +1 -0
  203. package/dist/core/runner/task-start-doors.js +6 -3
  204. package/dist/core/runner/terminal-account.d.ts +10 -1
  205. package/dist/core/runner/terminal-account.js +23 -3
  206. package/dist/core/runner/tool-face-overlay.d.ts +2 -11
  207. package/dist/core/runner/tool-face-overlay.js +39 -0
  208. package/dist/core/runner/trim-stretch.js +7 -2
  209. package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
  210. package/dist/core/runner-deps.d.ts +13 -10
  211. package/dist/core/scheduler.d.ts +47 -7
  212. package/dist/core/scheduler.js +19 -7
  213. package/dist/core/secret-env.d.ts +60 -37
  214. package/dist/core/secret-env.js +45 -48
  215. package/dist/core/sensitive-path-policy.js +14 -7
  216. package/dist/core/session-checkout.d.ts +3 -0
  217. package/dist/core/session-checkout.js +1 -0
  218. package/dist/core/session-store.d.ts +12 -6
  219. package/dist/core/session-store.js +26 -6
  220. package/dist/core/session.d.ts +31 -8
  221. package/dist/core/shell-read-silence.js +1 -0
  222. package/dist/core/store-contracts/checkpoint-store-contract.js +17 -0
  223. package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
  224. package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
  225. package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
  226. package/dist/core/store-contracts/session-store-contract.js +87 -3
  227. package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
  228. package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
  229. package/dist/core/task-event.d.ts +11 -3
  230. package/dist/core/task-notification.d.ts +97 -10
  231. package/dist/core/task-notification.js +129 -5
  232. package/dist/core/task-registry-shared.d.ts +12 -1
  233. package/dist/core/task-registry-shared.js +3 -1
  234. package/dist/core/task-registry-workflow.d.ts +1 -1
  235. package/dist/core/task-registry-workflow.js +9 -1
  236. package/dist/core/task-registry.d.ts +39 -2
  237. package/dist/core/task-registry.js +76 -12
  238. package/dist/core/task-result.d.ts +13 -0
  239. package/dist/core/task-spec-members.d.ts +3 -1
  240. package/dist/core/task-spec-members.js +11 -3
  241. package/dist/core/task-spec.d.ts +57 -23
  242. package/dist/core/tool-catalog-entries.js +4 -0
  243. package/dist/core/tool-face-reader.js +1 -1
  244. package/dist/core/tool-face.d.ts +7 -0
  245. package/dist/core/tool-face.js +1 -0
  246. package/dist/core/tool-mount-facts.d.ts +5 -3
  247. package/dist/core/tool-mount-facts.js +4 -3
  248. package/dist/core/tool-mount-plan.d.ts +7 -3
  249. package/dist/core/tool-mount-plan.js +11 -5
  250. package/dist/core/tool-mount-static.d.ts +2 -2
  251. package/dist/core/tool-mount-static.js +28 -14
  252. package/dist/core/tool-registry.d.ts +33 -1
  253. package/dist/core/tool-registry.js +33 -0
  254. package/dist/core/tool-result-store.d.ts +19 -2
  255. package/dist/core/tool-result-store.js +51 -2
  256. package/dist/core/tool-roster.d.ts +16 -0
  257. package/dist/core/tool-roster.js +6 -0
  258. package/dist/core/tool-spec.d.ts +13 -4
  259. package/dist/core/tools.d.ts +6 -0
  260. package/dist/core/tools.js +1 -1
  261. package/dist/core/user-attachment.d.ts +5 -1
  262. package/dist/core/user-attachment.js +14 -7
  263. package/dist/core/wiring-manifest.d.ts +89 -29
  264. package/dist/core/wiring-manifest.js +44 -4
  265. package/dist/core/workflow-journal-store.d.ts +53 -10
  266. package/dist/core/workflow-journal-store.js +27 -4
  267. package/dist/core/workflow-run-store-contract.js +16 -0
  268. package/dist/core/workflow-run-store.d.ts +9 -7
  269. package/dist/core/workflow-run-store.js +4 -1
  270. package/dist/engine/execution-env/node-execution-env.js +3 -1
  271. package/dist/engine/harness/messages.d.ts +1 -1
  272. package/dist/engine/harness/messages.js +2 -1
  273. package/dist/engine/harness/types.d.ts +24 -1
  274. package/dist/engine/harness/types.js +10 -0
  275. package/dist/engine/llm/types.d.ts +5 -7
  276. package/dist/engine/loop/types.d.ts +2 -0
  277. package/dist/engine/lsp/node-lsp-manager.js +2 -1
  278. package/dist/engine/session/import-validate.js +6 -1
  279. package/dist/engine/session/session.d.ts +15 -2
  280. package/dist/engine/session/session.js +35 -5
  281. package/dist/index.d.ts +27 -12
  282. package/dist/index.js +20 -8
  283. package/dist/orchestration/run-workflow-tool.js +40 -32
  284. package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
  285. package/dist/orchestration/workflow-park-adoption.js +47 -12
  286. package/dist/orchestration/workflow-stop.d.ts +128 -0
  287. package/dist/orchestration/workflow-stop.js +156 -0
  288. package/dist/orchestration/workflow.d.ts +30 -6
  289. package/dist/orchestration/workflow.js +117 -54
  290. package/dist/prompts/manager-recipe.d.ts +18 -0
  291. package/dist/prompts/manager-recipe.js +24 -0
  292. package/dist/stores/file/adoption/marker.d.ts +2 -27
  293. package/dist/stores/file/adoption/marker.js +12 -0
  294. package/dist/stores/file/index.d.ts +1 -1
  295. package/dist/stores/file/index.js +1 -1
  296. package/dist/stores/file/permission-rule-store.d.ts +3 -1
  297. package/dist/stores/file/permission-rule-store.js +0 -1
  298. package/dist/stores/file/workflow-journal-store.d.ts +16 -3
  299. package/dist/stores/file/workflow-journal-store.js +93 -5
  300. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  301. package/dist/tools/artifact/artifact-tool.js +11 -6
  302. package/dist/tools/fs/file-read-check.d.ts +45 -11
  303. package/dist/tools/fs/file-read-check.js +200 -57
  304. package/dist/tools/fs/file-write-check.js +9 -3
  305. package/dist/tools/fs/index.d.ts +8 -7
  306. package/dist/tools/fs/index.js +4 -4
  307. package/dist/tools/fs/judged-reads.d.ts +51 -0
  308. package/dist/tools/fs/judged-reads.js +68 -0
  309. package/dist/tools/fs/read-deny-home.d.ts +1 -1
  310. package/dist/tools/fs/read-deny-home.js +5 -5
  311. package/dist/tools/fs/read-deny.d.ts +33 -8
  312. package/dist/tools/fs/read-deny.js +114 -25
  313. package/dist/tools/fs/safety.d.ts +12 -1
  314. package/dist/tools/fs/safety.js +16 -3
  315. package/dist/tools/fs/shell-read-check.d.ts +25 -5
  316. package/dist/tools/fs/shell-read-check.js +100 -15
  317. package/dist/tools/fs/shell-read-establish.d.ts +9 -0
  318. package/dist/tools/fs/shell-read-establish.js +34 -14
  319. package/dist/tools/fs/shell-read-judge.d.ts +13 -1
  320. package/dist/tools/fs/shell-read-judge.js +26 -7
  321. package/dist/tools/fs/shell-read-plan.d.ts +5 -0
  322. package/dist/tools/fs/shell-read-write-targets.js +17 -9
  323. package/dist/tools/scheduler-store-move.d.ts +74 -0
  324. package/dist/tools/scheduler-store-move.js +103 -0
  325. package/dist/tools/scheduler-tools.d.ts +43 -29
  326. package/dist/tools/scheduler-tools.js +161 -118
  327. package/package.json +2 -2
  328. package/test/export-surface.snapshot.json +173 -3
  329. package/wire-changes/answers/core-stores-sql@7.72.0.json +12 -0
  330. package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
  331. package/wire-changes/answers/core@7.72.0.json +84 -0
  332. package/wire-changes/answers/core@7.73.0.json +216 -0
  333. package/wire-changes/answers/mods-kernel@7.72.0.json +7 -0
  334. package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
  335. package/wire-changes/answers/primitives@7.72.0.json +6 -0
  336. package/wire-changes/answers/primitives@7.73.0.json +12 -0
  337. package/wire-changes/answers/wiki-gate@7.72.0.json +7 -0
  338. package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
  339. package/wire-changes/core-stores-sql@7.72.0.json +215 -0
  340. package/wire-changes/core-stores-sql@7.73.0.json +326 -0
  341. package/wire-changes/core@7.72.0.json +2426 -0
  342. package/wire-changes/core@7.73.0.json +6480 -0
  343. package/wire-changes/mods-kernel@7.72.0.json +147 -0
  344. package/wire-changes/mods-kernel@7.73.0.json +147 -0
  345. package/wire-changes/primitives@7.72.0.json +143 -0
  346. package/wire-changes/primitives@7.73.0.json +227 -0
  347. package/wire-changes/wiki-gate@7.72.0.json +145 -0
  348. package/wire-changes/wiki-gate@7.73.0.json +145 -0
@@ -1142,8 +1142,11 @@ export function runStreamingBrain(args) {
1142
1142
  void reader.cancel().catch(() => undefined);
1143
1143
  };
1144
1144
  let midstreamWarning;
1145
+ let activeParser;
1145
1146
  const parserOut = Object.create(out);
1146
1147
  parserOut.push = (ev) => {
1148
+ if (ev.type === "done" || ev.type === "error")
1149
+ activeParser?.sealForRetry();
1147
1150
  if (midstreamWarning !== undefined && (ev.type === "done" || ev.type === "error")) {
1148
1151
  const msg = ev.type === "done" ? ev.message : ev.error;
1149
1152
  msg.partialFinalized = true;
@@ -1164,7 +1167,7 @@ export function runStreamingBrain(args) {
1164
1167
  }
1165
1168
  out.push(ev);
1166
1169
  };
1167
- const parser = makeParser({
1170
+ const parser = (activeParser = makeParser({
1168
1171
  out: parserOut,
1169
1172
  partial,
1170
1173
  sawContentToken,
@@ -1181,175 +1184,180 @@ export function runStreamingBrain(args) {
1181
1184
  inBandEnvelope = envelope;
1182
1185
  producedBeforeFrame = firstTokenSeen;
1183
1186
  },
1184
- });
1185
- const fellBackFromStream = (failure) => {
1186
- if (keptOutput()) {
1187
- keep();
1188
- return false;
1189
- }
1190
- if (!fallBack(failure))
1191
- return false;
1192
- parser.sealForRetry();
1193
- return true;
1194
- };
1195
- const parserFailed = (e) => {
1196
- const ended = e instanceof TriedAttemptEnded ? e.ended : undefined;
1197
- const envelope = ended === undefined ? inBandEnvelope : undefined;
1198
- const kept = attemptOutput;
1199
- const failure = {
1200
- code: ended !== undefined ? extractErrorCode(ended.errorMessage) : brainErrorCodeOf(e),
1201
- status: undefined,
1202
- statement: envelope !== undefined && !producedBeforeFrame ? { envelope, inputTooLong: readMember(e, "inputTooLong") === true } : undefined,
1203
- spent: ended !== undefined
1204
- ? { usage: ended.usage, ...(ended.usageMissing === true ? { usageMissing: true } : {}) }
1205
- : kept !== undefined
1206
- ? { usage: kept.usage, ...(kept.usageMissing === true ? { usageMissing: true } : {}) }
1207
- : undefined,
1208
- };
1209
- if (fellBackFromStream(failure))
1187
+ }));
1188
+ let arm;
1189
+ let announcement;
1190
+ try {
1191
+ const fellBackFromStream = (failure) => {
1192
+ if (keptOutput()) {
1193
+ keep();
1194
+ return false;
1195
+ }
1196
+ if (!fallBack(failure))
1197
+ return false;
1210
1198
  return true;
1211
- declaredRefused = refusesDeclaredThinking(envelope);
1212
- return false;
1213
- };
1214
- const INBAND_OVERLOAD_WARNING = "API overloaded mid-response. The response above may be incomplete.";
1215
- const onLineOverloadTierA = (line) => {
1216
- try {
1217
- parser.onLine(line);
1199
+ };
1200
+ const parserFailed = (e) => {
1201
+ const ended = e instanceof TriedAttemptEnded ? e.ended : undefined;
1202
+ const envelope = ended === undefined ? inBandEnvelope : undefined;
1203
+ const kept = attemptOutput;
1204
+ const failure = {
1205
+ code: ended !== undefined ? extractErrorCode(ended.errorMessage) : brainErrorCodeOf(e),
1206
+ status: undefined,
1207
+ statement: envelope !== undefined && !producedBeforeFrame ? { envelope, inputTooLong: readMember(e, "inputTooLong") === true } : undefined,
1208
+ spent: ended !== undefined
1209
+ ? { usage: ended.usage, ...(ended.usageMissing === true ? { usageMissing: true } : {}) }
1210
+ : kept !== undefined
1211
+ ? { usage: kept.usage, ...(kept.usageMissing === true ? { usageMissing: true } : {}) }
1212
+ : undefined,
1213
+ };
1214
+ if (fellBackFromStream(failure))
1215
+ return true;
1216
+ declaredRefused = refusesDeclaredThinking(envelope);
1218
1217
  return false;
1218
+ };
1219
+ const INBAND_OVERLOAD_WARNING = "API overloaded mid-response. The response above may be incomplete.";
1220
+ const onLineOverloadTierA = (line) => {
1221
+ try {
1222
+ parser.onLine(line);
1223
+ return false;
1224
+ }
1225
+ catch (e) {
1226
+ if (brainErrorCodeOf(e) !== "server" || !parser.snapshot().hasSubstantiveText)
1227
+ throw e;
1228
+ return true;
1229
+ }
1230
+ };
1231
+ let failure;
1232
+ let fellBack = false;
1233
+ readLoop: for (;;) {
1234
+ let readRes;
1235
+ try {
1236
+ readRes = await reader.read();
1237
+ }
1238
+ catch (e) {
1239
+ if (isAbortError(e) || signal?.aborted)
1240
+ throw e;
1241
+ failure = {
1242
+ kind: "connection",
1243
+ err: new BrainError("network", `mid-stream read failed: ${remoteWords(describeNetworkError(e), req.declared)}`, undefined, { apiError: true }),
1244
+ };
1245
+ break readLoop;
1246
+ }
1247
+ const { done, value } = readRes;
1248
+ if (done)
1249
+ break;
1250
+ buffer += decoder.decode(value, { stream: true });
1251
+ let nl;
1252
+ let start = 0;
1253
+ try {
1254
+ while ((nl = buffer.indexOf("\n", start)) !== -1) {
1255
+ const line = buffer.slice(start, nl);
1256
+ start = nl + 1;
1257
+ if (onLineOverloadTierA(line)) {
1258
+ midstreamWarning = INBAND_OVERLOAD_WARNING;
1259
+ parser.finalize({ truncated: true });
1260
+ return;
1261
+ }
1262
+ }
1263
+ }
1264
+ catch (e) {
1265
+ if (!parserFailed(e))
1266
+ throw e;
1267
+ fellBack = true;
1268
+ break readLoop;
1269
+ }
1270
+ if (start > 0)
1271
+ buffer = buffer.slice(start);
1219
1272
  }
1220
- catch (e) {
1221
- if (brainErrorCodeOf(e) !== "server" || !parser.snapshot().hasSubstantiveText)
1222
- throw e;
1223
- return true;
1273
+ if (ftTimer) {
1274
+ clearTimeout(ftTimer);
1275
+ ftTimer = undefined;
1224
1276
  }
1225
- };
1226
- let failure;
1227
- let fellBack = false;
1228
- readLoop: for (;;) {
1229
- let readRes;
1230
- try {
1231
- readRes = await reader.read();
1277
+ firstTokenWait.stop();
1278
+ nextTokenWait.stop();
1279
+ if (idleTimer) {
1280
+ clearTimeout(idleTimer);
1281
+ idleTimer = undefined;
1232
1282
  }
1233
- catch (e) {
1234
- if (isAbortError(e) || signal?.aborted)
1235
- throw e;
1283
+ streamSuspend.disarm();
1284
+ if (!failure && suspendedInStream !== undefined)
1285
+ failure = suspendedInStream;
1286
+ if (!failure && firedFirstTokenDeadlineMs !== undefined) {
1236
1287
  failure = {
1237
- kind: "connection",
1238
- err: new BrainError("network", `mid-stream read failed: ${remoteWords(describeNetworkError(e), req.declared)}`, undefined, { apiError: true }),
1288
+ kind: "stalled",
1289
+ watchdog: "first-token",
1290
+ knob: "firstTokenTimeoutMs",
1291
+ timeoutMs: firedFirstTokenDeadlineMs,
1292
+ err: new BrainError("network", `first-token timeout after ${firedFirstTokenDeadlineMs}ms`, undefined, { apiError: true }),
1239
1293
  };
1240
- break readLoop;
1241
1294
  }
1242
- const { done, value } = readRes;
1243
- if (done)
1244
- break;
1245
- buffer += decoder.decode(value, { stream: true });
1246
- let nl;
1247
- let start = 0;
1248
- try {
1249
- while ((nl = buffer.indexOf("\n", start)) !== -1) {
1250
- const line = buffer.slice(start, nl);
1251
- start = nl + 1;
1252
- if (onLineOverloadTierA(line)) {
1253
- midstreamWarning = INBAND_OVERLOAD_WARNING;
1254
- parser.finalize({ truncated: true });
1255
- return;
1256
- }
1257
- }
1258
- }
1259
- catch (e) {
1260
- if (!parserFailed(e))
1261
- throw e;
1262
- fellBack = true;
1263
- break readLoop;
1264
- }
1265
- if (start > 0)
1266
- buffer = buffer.slice(start);
1267
- }
1268
- if (ftTimer) {
1269
- clearTimeout(ftTimer);
1270
- ftTimer = undefined;
1271
- }
1272
- firstTokenWait.stop();
1273
- nextTokenWait.stop();
1274
- if (idleTimer) {
1275
- clearTimeout(idleTimer);
1276
- idleTimer = undefined;
1277
- }
1278
- streamSuspend.disarm();
1279
- if (!failure && suspendedInStream !== undefined)
1280
- failure = suspendedInStream;
1281
- if (!failure && firedFirstTokenDeadlineMs !== undefined) {
1282
- failure = {
1283
- kind: "stalled",
1284
- watchdog: "first-token",
1285
- knob: "firstTokenTimeoutMs",
1286
- timeoutMs: firedFirstTokenDeadlineMs,
1287
- err: new BrainError("network", `first-token timeout after ${firedFirstTokenDeadlineMs}ms`, undefined, { apiError: true }),
1288
- };
1289
- }
1290
- if (!failure && firedIdleDeadlineMs !== undefined) {
1291
- failure = {
1292
- kind: "stalled",
1293
- watchdog: "stream idle",
1294
- knob: "idleTimeoutMs",
1295
- timeoutMs: firedIdleDeadlineMs,
1296
- err: new BrainError("network", `stream idle timeout after ${firedIdleDeadlineMs}ms`, undefined, { apiError: true }),
1297
- };
1298
- }
1299
- if (fellBack || (failure !== undefined && !parser.snapshot().terminalFrameSeen && fellBackFromStream({ code: brainErrorCodeOf(failure.err), status: undefined, statement: undefined, spent: undefined }))) {
1300
- cleanup?.();
1301
- cleanup = undefined;
1302
- continue;
1303
- }
1304
- if (!failure) {
1305
- buffer += decoder.decode();
1306
- try {
1307
- if (buffer.trim() && onLineOverloadTierA(buffer))
1308
- midstreamWarning = INBAND_OVERLOAD_WARNING;
1309
- parser.finalize(midstreamWarning !== undefined ? { truncated: true } : undefined);
1295
+ if (!failure && firedIdleDeadlineMs !== undefined) {
1296
+ failure = {
1297
+ kind: "stalled",
1298
+ watchdog: "stream idle",
1299
+ knob: "idleTimeoutMs",
1300
+ timeoutMs: firedIdleDeadlineMs,
1301
+ err: new BrainError("network", `stream idle timeout after ${firedIdleDeadlineMs}ms`, undefined, { apiError: true }),
1302
+ };
1310
1303
  }
1311
- catch (e) {
1312
- if (!parserFailed(e))
1313
- throw e;
1304
+ if (fellBack || (failure !== undefined && !parser.snapshot().terminalFrameSeen && fellBackFromStream({ code: brainErrorCodeOf(failure.err), status: undefined, statement: undefined, spent: undefined }))) {
1314
1305
  cleanup?.();
1315
1306
  cleanup = undefined;
1316
1307
  continue;
1317
1308
  }
1318
- return;
1319
- }
1320
- const snap = parser.snapshot();
1321
- const arm = streamCutOf(snap);
1322
- if (arm === "whole") {
1323
- try {
1324
- parser.finalize();
1309
+ if (!failure) {
1310
+ buffer += decoder.decode();
1311
+ try {
1312
+ if (buffer.trim() && onLineOverloadTierA(buffer))
1313
+ midstreamWarning = INBAND_OVERLOAD_WARNING;
1314
+ parser.finalize(midstreamWarning !== undefined ? { truncated: true } : undefined);
1315
+ }
1316
+ catch (e) {
1317
+ if (!parserFailed(e))
1318
+ throw e;
1319
+ cleanup?.();
1320
+ cleanup = undefined;
1321
+ continue;
1322
+ }
1323
+ return;
1325
1324
  }
1326
- catch (e) {
1327
- if (!parserFailed(e))
1328
- throw e;
1329
- cleanup?.();
1330
- cleanup = undefined;
1331
- continue;
1325
+ const snap = parser.snapshot();
1326
+ arm = streamCutOf(snap);
1327
+ if (arm === "whole") {
1328
+ try {
1329
+ parser.finalize();
1330
+ }
1331
+ catch (e) {
1332
+ if (!parserFailed(e))
1333
+ throw e;
1334
+ cleanup?.();
1335
+ cleanup = undefined;
1336
+ continue;
1337
+ }
1338
+ return;
1332
1339
  }
1333
- return;
1340
+ if (arm === "keep") {
1341
+ midstreamWarning =
1342
+ failure.kind === "stalled"
1343
+ ? "Response stalled mid-stream. The response above may be incomplete."
1344
+ : STREAM_TORN_WARNING;
1345
+ parser.finalize({ truncated: true });
1346
+ return;
1347
+ }
1348
+ if (snap.hasCompletedToolCall)
1349
+ throw failure.err;
1350
+ cleanup?.();
1351
+ cleanup = undefined;
1352
+ announcement = retryAnnouncement(failure);
1353
+ if (arm === "fail")
1354
+ throw failure.err;
1334
1355
  }
1335
- if (arm === "keep") {
1336
- midstreamWarning =
1337
- failure.kind === "stalled"
1338
- ? "Response stalled mid-stream. The response above may be incomplete."
1339
- : STREAM_TORN_WARNING;
1340
- parser.finalize({ truncated: true });
1341
- return;
1356
+ finally {
1357
+ parser.sealForRetry();
1342
1358
  }
1343
- if (snap.hasCompletedToolCall)
1344
- throw failure.err;
1345
- cleanup?.();
1346
- cleanup = undefined;
1347
- const announcement = retryAnnouncement(failure);
1348
- if (arm === "fail")
1349
- throw failure.err;
1350
1359
  if (arm === "resend_thinking") {
1351
1360
  thinkingRetries++;
1352
- parser.sealForRetry();
1353
1361
  const delayMs = 100 * thinkingRetries;
1354
1362
  await waitAnnouncingRetry(announcement, { phase: "midstream", attempt: thinkingRetries, maxRetries: THINKING_RETRY_BUDGET, delayMs });
1355
1363
  continue;
@@ -4,7 +4,9 @@ import { type PeerSeat } from "./peer-seat.js";
4
4
  import { type HostFloor } from "./host-floor.js";
5
5
  import { type A2aRevocationStopCode, type ProtocolRevocationLedger, type RevocationProbe } from "./protocol-revocation.js";
6
6
  import { type McpFailureFields } from "./mcp-failure.js";
7
- import type { A2aServerSpec } from "./types.js";
7
+ import type { A2aServerSpec, ToolExecuteContext } from "./types.js";
8
+ import { type ToolCtxEnricher } from "./tools.js";
9
+ import { type TaskRegistry } from "./task-registry.js";
8
10
  import type { AskDestination } from "./mcp-server-spec.js";
9
11
  import type { EngineNotice } from "./engine-notice.js";
10
12
  /** The hard per-skill description bound (ruled 2026-08-03: ~2KiB), counted in code points — the unit every cut in the description is made in. */
@@ -153,6 +155,22 @@ export declare const A2A_CALL_REFUSAL_CODES: Readonly<{
153
155
  readonly changeable: "a2a.call_refused_changeable";
154
156
  readonly retry_later: "a2a.call_refused_retry_later";
155
157
  }>;
158
+ /** What ONE call of a peer's tool reaches beyond the peer: the task registry the run's background rows live in, the one completion sink the
159
+ * call's ctx carries, and whether a completion would come back through it (`admitsBackgroundLaunch` — the admission every background
160
+ * producer applies, judged at the call). One source for all three: the ctx the leg's builder makes for the call. */
161
+ export interface PeerCallReach {
162
+ readonly registry: TaskRegistry;
163
+ readonly completionSink: ToolExecuteContext["onTaskNotification"];
164
+ readonly admitted: boolean;
165
+ }
166
+ /** The reach of one call, computed from the ctx the leg's per-call builder (the one every mounted tool runs with) makes for it — the
167
+ * builder's answer with the call's own identity stamped over it (`stampCallIdentity`, the stamp every `defineTool` product applies). The
168
+ * registry is the ctx's (the run's), else the engine's one. Nothing computes it at a call today: a call is sent whether or not it is
169
+ * admitted, and reading a run's seats costs a call its host objects' accessors, so the work waits for the lane that consumes it. */
170
+ export declare function peerCallReach(enrichCtx: ToolCtxEnricher, toolCallId: string, signal: AbortSignal | undefined): PeerCallReach;
171
+ /** The means a peer tool carries to compute the reach of one call (`toolCallId`, `signal`): run once, it builds the call's ctx through the leg's
172
+ * builder and reads the registry, the completion sink and the admission off it. `undefined` ⇒ the tool was minted with no builder. */
173
+ export declare function peerToolReachOf(tool: AgentTool): ((toolCallId: string, signal?: AbortSignal) => PeerCallReach) | undefined;
156
174
  /**
157
175
  * Where a call goes, per tool name, for a leg's declared peers (the preparation door's frozen snapshot, the list the leg materializes):
158
176
  * a tool under a peer's prefix answers that peer's {@link AskDestination}, read off its declaration; any other tool answers nothing. The
@@ -183,7 +201,10 @@ revocations?: ProtocolRevocationLedger & {
183
201
  * prefix) — a pure predicate that answers a boolean and does not throw — asked of each declared peer before anything is sent to it. A peer
184
202
  * it answers `false` for stays declared and is not contacted (no card request, no status row, no tool). Absent ⇒ every declared peer is
185
203
  * dialed. It has no guard against a throwing or non-boolean answer (the MCP materialization's `dialable` is host-suppliable and has one);
186
- * a form opened to a host needs that guard and a refusal code of its own. */
204
+ * a form opened to a host needs that guard and a refusal code of its own. `enrichCtx` is the leg's per-call ctx builder, which every tool the
205
+ * materialization mints (a refresh's included) carries the means to compute its calls' reach with ({@link peerToolReachOf}); absent ⇒ the
206
+ * tools carry none (the library entrance). */
187
207
  export declare function materializeLegA2aTools(revocations: RevocationProbe | undefined, specs: readonly A2aServerSpec[], principal: string | undefined, signal: AbortSignal | undefined, hostFloor: HostFloor | undefined, peerSeat: PeerSeat | undefined, onCredentialEchoed: ((peer: string, where: CredentialEchoSite) => void) | undefined, dialable?: (spec: {
188
208
  readonly name: string;
189
- }) => boolean, isolatePeers?: boolean): Promise<MaterializedA2a>;
209
+ }) => boolean, isolatePeers?: boolean, // the deployment's `RunnerDeps.a2a.isolatePeers`: an inside peer's skills keep the egress default ({@link a2aInsideRelaxed})
210
+ enrichCtx?: ToolCtxEnricher): Promise<MaterializedA2a>;
package/dist/core/a2a.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { A2A_NAMESPACE, a2aRegistrationProblems, findNamespacePrefixCollision, mintNamespacePrefix, mintNamespacedToolName } from "@sema-agent/primitives";
3
3
  import { Type } from "typebox";
4
+ import { a2aPeerRegistration, peerRegistrationDigestOf } from "./peer-registration.js";
4
5
  import { A2A_SEMA_EXTENSIONS, A2A_SEMA_REFUSAL_CODES, A2A_SEMA_SKILL_ID_KEY, A2A_STATE_TABLE, A2A_TASK_STATES, readA2APeerState } from "./a2a-task-state.js";
5
6
  import { PROTOCOL_PLAINTEXT_CREDENTIALS_CODE, assertEndpointBound, carriesDeclaredHeaders, crossesNetworkInClear, eraseSentCredentials, foreignLine, resolveProtocolHttpHeaders, underDeclaredHeaders } from "./protocol-http-auth.js";
6
7
  import { carrierEcho, echoAnnouncer, erasedEcho, nameEchoes } from "./credential-echo.js";
@@ -9,6 +10,9 @@ import { fetchFollowing, hopRefusal, HOST_FLOOR_REFUSED_CODE } from "./host-floo
9
10
  import { A2A_REVOCATION_UNREADABLE_CODE, ProtocolRevokedRefusal, REVOKED_PEER_CODES, libraryRevocationProbe } from "./protocol-revocation.js";
10
11
  import { revokedCallResult } from "./mcp-server-link.js";
11
12
  import { classifyMcpFailure, DELIVERED_BY_KIND, describeHttpTransportFailure, failureFields } from "./mcp-failure.js";
13
+ import { stampCallIdentity } from "./tools.js";
14
+ import { admitsBackgroundLaunch } from "./task-notification.js";
15
+ import { defaultTaskRegistry } from "./task-registry.js";
12
16
  import { judgeA2aEntryRegistration, judgeEntryToolAxes, refusedDeclarer, snapshotDeclaredEntry } from "./locked-config.js";
13
17
  import { INLINE_TRUNCATION_MARK_CODEPOINTS, delimitUntrusted, inlineUntrusted } from "./untrusted-text.js";
14
18
  import { renderListEntry } from "./allow-entry.js";
@@ -756,16 +760,26 @@ async function awaitTaskOutcome(t, peerLabel, skillId, firstTask, signal, declar
756
760
  observed = next;
757
761
  }
758
762
  }
759
- function buildSkillTool(spec, t, skill, lifecycle, speaks) {
763
+ export function peerCallReach(enrichCtx, toolCallId, signal) {
764
+ const ctx = stampCallIdentity(enrichCtx({ toolCallId, signal }), toolCallId, signal);
765
+ const completionSink = ctx.onTaskNotification;
766
+ return { registry: ctx.taskRegistry ?? defaultTaskRegistry, completionSink, admitted: admitsBackgroundLaunch(completionSink) };
767
+ }
768
+ const peerToolReach = new WeakMap();
769
+ export function peerToolReachOf(tool) {
770
+ return peerToolReach.get(tool);
771
+ }
772
+ function buildSkillTool(spec, t, skill, lifecycle, speaks, registration, enrichCtx) {
760
773
  const peerLabel = inlineUntrusted(spec.name, A2A_ID_MAX_CHARS);
761
774
  const name = mintNamespacedToolName(A2A_NAMESPACE, spec.name, skill.id);
762
- return {
775
+ const tool = {
763
776
  name,
764
777
  label: `${spec.name}:${skill.id}`,
765
778
  description: skillDescription(peerLabel, skill),
766
779
  parameters: a2aToolParameters(),
780
+ peerRegistration: registration,
767
781
  permissionSeat: "passthrough",
768
- execute: async (_toolCallId, params, signal) => {
782
+ execute: async (_toolCallId, params, callSignal) => {
769
783
  if (lifecycle.disposed) {
770
784
  throw new Error(`a2a: the task that mounted peer "${peerLabel}" has ended — this tool no longer sends anything to the remote agent.`);
771
785
  }
@@ -774,6 +788,7 @@ function buildSkillTool(spec, t, skill, lifecycle, speaks) {
774
788
  if (message === undefined || message.trim() === "") {
775
789
  throw new Error(`a2a: "message" is required — say what the remote agent "${peerLabel}" should do.`);
776
790
  }
791
+ const signal = callSignal;
777
792
  const taskId = asString(args["taskId"]);
778
793
  const contextId = asString(args["contextId"]);
779
794
  const result = await jsonRpc(t, "message/send", {
@@ -809,6 +824,9 @@ function buildSkillTool(spec, t, skill, lifecycle, speaks) {
809
824
  throw new Error(`a2a: peer "${peerLabel}" answered message/send with ${JSON.stringify(foreignLine(kind ?? "(no kind)", A2A_ID_MAX_CHARS))}, which is neither a message nor a task`);
810
825
  },
811
826
  };
827
+ if (enrichCtx !== undefined)
828
+ peerToolReach.set(tool, (toolCallId, signal) => peerCallReach(enrichCtx, toolCallId, signal));
829
+ return tool;
812
830
  }
813
831
  function extendedCardReasonOf(err) {
814
832
  if (err instanceof A2aNothingCarried || err instanceof PeerSeatFailure)
@@ -909,7 +927,7 @@ function declaredPeerOf(declared, index) {
909
927
  const judged = judgeEntryToolAxes(snapshot, "a2a");
910
928
  return judged.ok ? { spec: judged.entry } : { spec: snapshot, refusal: judged.error };
911
929
  }
912
- async function materializePeer(peer, principal, lifecycle, signal, floor, seat, announceEcho, revocations, isolatePeers) {
930
+ async function materializePeer(peer, principal, lifecycle, signal, floor, seat, announceEcho, revocations, isolatePeers, enrichCtx) {
913
931
  if ("refusal" in peer)
914
932
  throw peer.refusal;
915
933
  const { spec } = peer;
@@ -937,11 +955,12 @@ async function materializePeer(peer, principal, lifecycle, signal, floor, seat,
937
955
  const cardDrift = inside ? cardDriftOf(spec.allowSkills ?? [], mounted.skills.map((s) => s.id)) : undefined;
938
956
  const tools = [];
939
957
  const skillAxes = [];
958
+ const registration = peerRegistrationDigestOf("a2a", a2aPeerRegistration(spec));
940
959
  for (const skill of mounted.skills) {
941
960
  if (spec.allowSkills !== undefined && !spec.allowSkills.includes(skill.id))
942
961
  continue;
943
962
  const declared = declaredAxes?.[skill.id];
944
- const tool = buildSkillTool(spec, transport, skill, lifecycle, card.speaks);
963
+ const tool = buildSkillTool(spec, transport, skill, lifecycle, card.speaks, registration, enrichCtx);
945
964
  tools.push(tool);
946
965
  skillAxes.push(a2aAxisFor(tool.name, declared, a2aInsideRelaxed(spec, isolatePeers)));
947
966
  }
@@ -1007,7 +1026,7 @@ function asPeerWarning(spec, err) {
1007
1026
  export async function materializeA2aTools(specs, principal, signal, hostFloor, given, onCredentialEchoed, revocations) {
1008
1027
  return materializeLegA2aTools(libraryRevocationProbe(revocations, "materializeA2aTools revocations"), specs, principal, signal, hostFloor, receivePeerSeat(given, "materializeA2aTools peerSeat"), onCredentialEchoed);
1009
1028
  }
1010
- export async function materializeLegA2aTools(revocations, specs, principal, signal, hostFloor, peerSeat, onCredentialEchoed, dialable, isolatePeers = false) {
1029
+ export async function materializeLegA2aTools(revocations, specs, principal, signal, hostFloor, peerSeat, onCredentialEchoed, dialable, isolatePeers = false, enrichCtx) {
1011
1030
  const peers = specs.map((spec, index) => declaredPeerOf(spec, index));
1012
1031
  if (peers.length > 0) {
1013
1032
  const collision = findNamespacePrefixCollision(A2A_NAMESPACE, peers.map((p) => p.spec.name));
@@ -1028,7 +1047,7 @@ export async function materializeLegA2aTools(revocations, specs, principal, sign
1028
1047
  const announceEcho = echoAnnouncer(onCredentialEchoed);
1029
1048
  const dialed = peers.map((peer) => dialable === undefined || dialable(peer.spec));
1030
1049
  const undialed = new Set(peers.filter((_, i) => !dialed[i]));
1031
- const settled = await Promise.allSettled(peers.map((peer, i) => (dialed[i] ? materializePeer(peer, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers) : Promise.resolve(null))));
1050
+ const settled = await Promise.allSettled(peers.map((peer, i) => (dialed[i] ? materializePeer(peer, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers, enrichCtx) : Promise.resolve(null))));
1032
1051
  for (let i = 0; i < peers.length; i++) {
1033
1052
  const spec = peers[i].spec;
1034
1053
  const outcome = settled[i];
@@ -1070,7 +1089,7 @@ export async function materializeLegA2aTools(revocations, specs, principal, sign
1070
1089
  }
1071
1090
  const previous = statuses.find((s) => s.name === spec.name)?.toolNames ?? [];
1072
1091
  try {
1073
- const fresh = await materializePeer(target, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers);
1092
+ const fresh = await materializePeer(target, principal, lifecycle, signal, hostFloor, peerSeat, announceEcho, revocations, isolatePeers, enrichCtx);
1074
1093
  const names = fresh.tools.map((t) => t.name);
1075
1094
  results.push({
1076
1095
  peer: spec.name,
@@ -0,0 +1,43 @@
1
+ /**
2
+ * A WORKER'S ACTIONS DIGEST — what a delegated child did, counted over its whole event stream (every tool call that ended, not
3
+ * the last-steps ring a resume prompt reads): calls by tool, the shell commands it ran with the exit codes the shell reported, and
4
+ * the files it changed. The engine's own record, set beside the child's self-report on the faces a run with a member ledger reads
5
+ * (the `<actions>` section of a completion notification, the ledger row): it says what was done, never whether it was right.
6
+ *
7
+ * Types, one sentence and one shape check — no imports, so every carrier (the step recorder, the notification codec, the ledger)
8
+ * can read it without a cycle.
9
+ */
10
+ /** One file the child changed, and how many times. */
11
+ export interface ActionsDigestFile {
12
+ readonly path: string;
13
+ readonly edits: number;
14
+ }
15
+ /** See the module head. */
16
+ export interface SubagentActions {
17
+ /** Every tool call that ended, all tools. */
18
+ readonly toolCalls: number;
19
+ /** Calls by tool name, most first (ties by first use); at most {@link ACTIONS_TOOLS_CAP} names — `toolCalls` counts all. */
20
+ readonly byTool: ReadonlyArray<{
21
+ readonly tool: string;
22
+ readonly calls: number;
23
+ }>;
24
+ /** Shell commands, in order, first line each (redacted and cut as every step field is); at most {@link ACTIONS_COMMANDS_CAP}. */
25
+ readonly commands: ReadonlyArray<{
26
+ readonly command: string;
27
+ readonly exitCode?: number;
28
+ }>;
29
+ /** Commands past the listed ones — absent when every command is listed (never `0`). */
30
+ readonly commandsUnlisted?: number;
31
+ /** Files changed; empty when none — the fact a self-report of edits is read against. */
32
+ readonly filesEdited: ReadonlyArray<ActionsDigestFile>;
33
+ }
34
+ /** How many shell commands a digest lists. */
35
+ export declare const ACTIONS_COMMANDS_CAP = 20;
36
+ /** How many tool names a digest lists. */
37
+ export declare const ACTIONS_TOOLS_CAP = 16;
38
+ /** The digest as the one engine line every face reads: `tool calls 9: Read 5, Bash 3, Grep 1 · commands: \`npm test\` (exit 0) ·
39
+ * files edited: none`. */
40
+ export declare function subagentActionsLine(a: SubagentActions): string;
41
+ /** Does a value read as a {@link SubagentActions} — the check a frame that came from outside this process (a boxed frame) passes
42
+ * before it is rendered. A key this build does not read is not judged. */
43
+ export declare function isSubagentActions(v: unknown): v is SubagentActions;
@@ -0,0 +1,22 @@
1
+ export const ACTIONS_COMMANDS_CAP = 20;
2
+ export const ACTIONS_TOOLS_CAP = 16;
3
+ export function subagentActionsLine(a) {
4
+ const tools = a.byTool.length > 0 ? `: ${a.byTool.map((t) => `${t.tool} ${t.calls}`).join(", ")}` : "";
5
+ const commands = a.commands.length === 0
6
+ ? "none"
7
+ : `${a.commands.map((c) => `\`${c.command}\`${c.exitCode !== undefined ? ` (exit ${c.exitCode})` : ""}`).join(" · ")}${a.commandsUnlisted !== undefined ? ` · and ${a.commandsUnlisted} more` : ""}`;
8
+ const files = a.filesEdited.length === 0 ? "none" : a.filesEdited.map((f) => `${f.path}${f.edits > 1 ? ` (×${f.edits})` : ""}`).join(", ");
9
+ return `tool calls ${a.toolCalls}${tools} · commands: ${commands} · files edited: ${files}`;
10
+ }
11
+ const isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
12
+ export function isSubagentActions(v) {
13
+ if (v === null || typeof v !== "object" || Array.isArray(v))
14
+ return false;
15
+ const a = v;
16
+ const list = (l, item) => Array.isArray(l) && l.every((e) => e !== null && typeof e === "object" && !Array.isArray(e) && item(e));
17
+ return (isCount(a["toolCalls"]) &&
18
+ list(a["byTool"], (e) => typeof e["tool"] === "string" && isCount(e["calls"])) &&
19
+ list(a["commands"], (e) => typeof e["command"] === "string" && (e["exitCode"] === undefined || (typeof e["exitCode"] === "number" && Number.isInteger(e["exitCode"])))) &&
20
+ (a["commandsUnlisted"] === undefined || (isCount(a["commandsUnlisted"]) && a["commandsUnlisted"] > 0)) &&
21
+ list(a["filesEdited"], (e) => typeof e["path"] === "string" && isCount(e["edits"])));
22
+ }