@sema-agent/core 7.55.0 → 7.57.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 (502) hide show
  1. package/CHANGELOG.md +1054 -0
  2. package/LICENSE +1 -1
  3. package/dist/agents/cascade.js +1 -1
  4. package/dist/agents/cc-peer-directory.js +1 -0
  5. package/dist/agents/child-model-seat.d.ts +0 -11
  6. package/dist/agents/child-model-seat.js +0 -3
  7. package/dist/agents/list-agents-tool.d.ts +3 -1
  8. package/dist/agents/list-agents-tool.js +7 -7
  9. package/dist/agents/org-delivery-gate.js +3 -4
  10. package/dist/agents/peer-directory.d.ts +22 -4
  11. package/dist/agents/peer-directory.js +24 -2
  12. package/dist/agents/peer-held-queue.d.ts +69 -49
  13. package/dist/agents/peer-held-queue.js +255 -106
  14. package/dist/agents/peer-session-drain.js +65 -45
  15. package/dist/agents/repair-loop.js +2 -2
  16. package/dist/agents/send-message-tool.js +7 -6
  17. package/dist/agents/subagent.d.ts +6 -4
  18. package/dist/agents/subagent.js +72 -68
  19. package/dist/agents/tool-filter.d.ts +7 -5
  20. package/dist/agents/tool-filter.js +12 -9
  21. package/dist/agents/verify.d.ts +3 -2
  22. package/dist/agents/verify.js +3 -3
  23. package/dist/brain/anthropic.js +45 -80
  24. package/dist/brain/media-degrade.d.ts +18 -7
  25. package/dist/brain/media-degrade.js +13 -2
  26. package/dist/brain/model-capability.d.ts +37 -0
  27. package/dist/brain/model-capability.js +34 -0
  28. package/dist/brain/model-presets.d.ts +2 -8
  29. package/dist/brain/model-presets.js +1 -6
  30. package/dist/brain/open-responses.js +23 -34
  31. package/dist/brain/openai.js +25 -96
  32. package/dist/brain/provider-dialect.d.ts +3 -2
  33. package/dist/brain/provider-dialect.js +2 -2
  34. package/dist/brain/reasoning-request.d.ts +96 -0
  35. package/dist/brain/reasoning-request.js +174 -0
  36. package/dist/brain/reasoning.d.ts +11 -11
  37. package/dist/brain/reasoning.js +4 -3
  38. package/dist/brain/request-params.d.ts +13 -4
  39. package/dist/brain/request-params.js +21 -5
  40. package/dist/brain/status-sink.d.ts +20 -0
  41. package/dist/brain/status-sink.js +7 -0
  42. package/dist/brain/stream-engine.d.ts +9 -0
  43. package/dist/brain/stream-engine.js +24 -10
  44. package/dist/brain/stream-shared.d.ts +5 -4
  45. package/dist/brain/stream-shared.js +4 -4
  46. package/dist/core/a2a.d.ts +2 -1
  47. package/dist/core/a2a.js +19 -13
  48. package/dist/core/agent-definition.d.ts +10 -0
  49. package/dist/core/allow-entry.d.ts +23 -23
  50. package/dist/core/allow-entry.js +42 -46
  51. package/dist/core/allow-rule-shadow.d.ts +3 -3
  52. package/dist/core/approval-object.d.ts +21 -5
  53. package/dist/core/approval-object.js +44 -17
  54. package/dist/core/ask-origin.d.ts +66 -20
  55. package/dist/core/ask-origin.js +63 -23
  56. package/dist/core/ask-question.d.ts +51 -8
  57. package/dist/core/ask-question.js +3 -4
  58. package/dist/core/ask-unresolvable-notice.d.ts +8 -3
  59. package/dist/core/ask-unresolvable-notice.js +16 -2
  60. package/dist/core/auto-compaction.d.ts +71 -6
  61. package/dist/core/auto-compaction.js +42 -26
  62. package/dist/core/background-agent-store.d.ts +6 -2
  63. package/dist/core/background-agent-store.js +1 -1
  64. package/dist/core/checkpoint-generation.d.ts +53 -0
  65. package/dist/core/checkpoint-generation.js +35 -0
  66. package/dist/core/checkpoint-queries.d.ts +180 -0
  67. package/dist/core/checkpoint-queries.js +272 -0
  68. package/dist/core/checkpoint-requirements.d.ts +19 -1
  69. package/dist/core/checkpoint-requirements.js +6 -0
  70. package/dist/core/checkpoint-store.d.ts +105 -53
  71. package/dist/core/checkpoint-store.js +43 -20
  72. package/dist/core/cross-boundary-taint.d.ts +6 -5
  73. package/dist/core/cross-boundary-taint.js +5 -5
  74. package/dist/core/decision-receipt.d.ts +37 -3
  75. package/dist/core/decision-receipt.js +17 -17
  76. package/dist/core/delegation-not-started.d.ts +6 -0
  77. package/dist/core/delegation-not-started.js +17 -0
  78. package/dist/core/engine-attestation.d.ts +93 -0
  79. package/dist/core/engine-attestation.js +70 -0
  80. package/dist/core/engine-capabilities.d.ts +4 -1
  81. package/dist/core/engine-capabilities.js +1 -1
  82. package/dist/core/engine-notice.d.ts +32 -12
  83. package/dist/core/engine-notice.js +6 -0
  84. package/dist/core/file-history-store.d.ts +104 -22
  85. package/dist/core/file-history-store.js +37 -19
  86. package/dist/core/gate-fold.d.ts +1 -1
  87. package/dist/core/gate-fold.js +22 -10
  88. package/dist/core/gate-lanes.js +73 -65
  89. package/dist/core/gate-outcome.d.ts +26 -5
  90. package/dist/core/gate-outcome.js +26 -0
  91. package/dist/core/governance-codes.d.ts +5 -1
  92. package/dist/core/governance-codes.js +6 -0
  93. package/dist/core/hooks.d.ts +19 -18
  94. package/dist/core/hooks.js +3 -1
  95. package/dist/core/host-floor.d.ts +128 -0
  96. package/dist/core/host-floor.js +206 -0
  97. package/dist/core/host-target.d.ts +38 -3
  98. package/dist/core/host-target.js +38 -5
  99. package/dist/core/mailbox-store.d.ts +62 -1
  100. package/dist/core/mailbox-store.js +59 -0
  101. package/dist/core/mcp-name-judge.d.ts +46 -0
  102. package/dist/core/mcp-name-judge.js +61 -0
  103. package/dist/core/mcp-probe.d.ts +1 -1
  104. package/dist/core/mcp-probe.js +2 -5
  105. package/dist/core/mcp.d.ts +5 -1
  106. package/dist/core/mcp.js +70 -64
  107. package/dist/core/memory-engine/consolidation-driver.js +4 -3
  108. package/dist/core/memory-engine/delegation-settlement.js +15 -24
  109. package/dist/core/memory-engine/distiller.js +26 -17
  110. package/dist/core/memory-engine/engine.js +4 -4
  111. package/dist/core/memory-engine/layout.d.ts +60 -8
  112. package/dist/core/memory-engine/layout.js +70 -8
  113. package/dist/core/model-seat.d.ts +10 -3
  114. package/dist/core/mods/classic-events.d.ts +67 -0
  115. package/dist/core/mods/classic-events.js +1 -0
  116. package/dist/core/mods/dollar.d.ts +13 -0
  117. package/dist/core/mods/extension-call.d.ts +31 -0
  118. package/dist/core/mods/extension-call.js +43 -0
  119. package/dist/core/mods/kernel/dispatch.d.ts +20 -3
  120. package/dist/core/mods/kernel/dispatch.js +140 -69
  121. package/dist/core/mods/kernel/events.d.ts +47 -11
  122. package/dist/core/mods/kernel/events.js +66 -42
  123. package/dist/core/mods/kernel/index.d.ts +4 -4
  124. package/dist/core/mods/kernel/index.js +2 -2
  125. package/dist/core/mods/kernel/receive.d.ts +39 -5
  126. package/dist/core/mods/kernel/receive.js +290 -17
  127. package/dist/core/mods/kernel/registration.d.ts +33 -2
  128. package/dist/core/mods/kernel/registration.js +6 -7
  129. package/dist/core/mods/kernel/site-rules.d.ts +44 -16
  130. package/dist/core/mods/kernel/site-rules.js +24 -42
  131. package/dist/core/mods/spec-seats.d.ts +69 -0
  132. package/dist/core/mods/spec-seats.js +114 -0
  133. package/dist/core/mods/stations.d.ts +28 -8
  134. package/dist/core/mods/stations.js +29 -13
  135. package/dist/core/mods/tool-call.d.ts +79 -0
  136. package/dist/core/mods/tool-call.js +152 -0
  137. package/dist/core/namespaced-rule-name.d.ts +32 -38
  138. package/dist/core/namespaced-rule-name.js +29 -36
  139. package/dist/core/parent-spec-seat.d.ts +6 -1
  140. package/dist/core/parent-spec-seat.js +2 -0
  141. package/dist/core/park-selfcheck.js +3 -0
  142. package/dist/core/permission-rule-consent.d.ts +24 -3
  143. package/dist/core/permission-rule-consent.js +136 -41
  144. package/dist/core/permission-rule-model.d.ts +57 -5
  145. package/dist/core/permission-rule-model.js +90 -31
  146. package/dist/core/permission-rule-org.d.ts +6 -2
  147. package/dist/core/permission-rule-org.js +8 -4
  148. package/dist/core/permission-rule-provider.d.ts +5 -2
  149. package/dist/core/permission-rule-provider.js +41 -11
  150. package/dist/core/permission-rule-store.d.ts +3 -2
  151. package/dist/core/permission-rule-store.js +11 -2
  152. package/dist/core/permission-rule-sync.js +3 -2
  153. package/dist/core/permission-rule-syntax.d.ts +5 -4
  154. package/dist/core/permission-rule-syntax.js +2 -2
  155. package/dist/core/permission-rules.d.ts +4 -4
  156. package/dist/core/permission-rules.js +11 -20
  157. package/dist/core/persisted-rule-arms.d.ts +2 -2
  158. package/dist/core/persisted-rule-arms.js +10 -12
  159. package/dist/core/principal-name.d.ts +20 -0
  160. package/dist/core/principal-name.js +22 -0
  161. package/dist/core/prompt-section-seat.js +4 -6
  162. package/dist/core/protocol-http-auth.d.ts +40 -5
  163. package/dist/core/protocol-http-auth.js +168 -4
  164. package/dist/core/protocol-naming.d.ts +20 -0
  165. package/dist/core/protocol-naming.js +20 -3
  166. package/dist/core/read-only-shell.d.ts +20 -5
  167. package/dist/core/read-only-shell.js +29 -14
  168. package/dist/core/remote-env.d.ts +37 -1
  169. package/dist/core/remote-env.js +11 -0
  170. package/dist/core/resume-startup-cause.d.ts +24 -2
  171. package/dist/core/resume-startup-cause.js +20 -1
  172. package/dist/core/retired-keys.d.ts +16 -0
  173. package/dist/core/retired-keys.js +16 -4
  174. package/dist/core/rewrite-rejudge.d.ts +60 -0
  175. package/dist/core/rewrite-rejudge.js +36 -0
  176. package/dist/core/roles.d.ts +28 -1
  177. package/dist/core/roles.js +81 -26
  178. package/dist/core/rule-lane-reads.d.ts +20 -15
  179. package/dist/core/rule-lane-reads.js +45 -17
  180. package/dist/core/rule-owner.d.ts +3 -3
  181. package/dist/core/rule-owner.js +3 -2
  182. package/dist/core/runner/announce-once-ledger.d.ts +14 -0
  183. package/dist/core/runner/announce-once-ledger.js +5 -0
  184. package/dist/core/runner/assemble-result.d.ts +1 -0
  185. package/dist/core/runner/assemble-result.js +1 -1
  186. package/dist/core/runner/call-hook-stations.d.ts +3 -2
  187. package/dist/core/runner/caller-roster.d.ts +16 -4
  188. package/dist/core/runner/caller-roster.js +33 -6
  189. package/dist/core/runner/capability-withheld-seat.d.ts +5 -0
  190. package/dist/core/runner/capability-withheld-seat.js +24 -0
  191. package/dist/core/runner/classifier-ladder.d.ts +7 -9
  192. package/dist/core/runner/classifier-ladder.js +3 -3
  193. package/dist/core/runner/compact-session.d.ts +10 -0
  194. package/dist/core/runner/compact-session.js +202 -0
  195. package/dist/core/runner/compaction-call-options.d.ts +2 -2
  196. package/dist/core/runner/compaction-seams.d.ts +21 -1
  197. package/dist/core/runner/compaction-seams.js +11 -8
  198. package/dist/core/runner/construction-doors.js +3 -0
  199. package/dist/core/runner/contracts.d.ts +50 -40
  200. package/dist/core/runner/cross-boundary-lane.d.ts +17 -13
  201. package/dist/core/runner/cross-boundary-lane.js +40 -27
  202. package/dist/core/runner/denial-limit-arms.d.ts +2 -2
  203. package/dist/core/runner/denial-limit-arms.js +1 -1
  204. package/dist/core/runner/derived-route-fallback.d.ts +13 -0
  205. package/dist/core/runner/derived-route-fallback.js +6 -0
  206. package/dist/core/runner/env-capability-census.d.ts +3 -2
  207. package/dist/core/runner/env-capability-census.js +9 -3
  208. package/dist/core/runner/file-history-request.d.ts +18 -0
  209. package/dist/core/runner/file-history-request.js +21 -13
  210. package/dist/core/runner/file-history-restore.d.ts +45 -0
  211. package/dist/core/runner/file-history-restore.js +46 -0
  212. package/dist/core/runner/gate-exit.d.ts +3 -3
  213. package/dist/core/runner/gate-exit.js +4 -3
  214. package/dist/core/runner/image.d.ts +7 -17
  215. package/dist/core/runner/image.js +9 -60
  216. package/dist/core/runner/permission-rule-lanes.d.ts +11 -11
  217. package/dist/core/runner/permission-rule-lanes.js +39 -17
  218. package/dist/core/runner/person-path-rows.d.ts +12 -9
  219. package/dist/core/runner/person-path-rows.js +18 -7
  220. package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
  221. package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
  222. package/dist/core/runner/prepare-ask-lane.d.ts +2 -2
  223. package/dist/core/runner/prepare-ask-lane.js +5 -2
  224. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -6
  225. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  226. package/dist/core/runner/prepare-config-doors.d.ts +35 -38
  227. package/dist/core/runner/prepare-config-doors.js +46 -28
  228. package/dist/core/runner/prepare-defer-classify.d.ts +4 -3
  229. package/dist/core/runner/prepare-defer-classify.js +7 -8
  230. package/dist/core/runner/prepare-file-history.d.ts +48 -8
  231. package/dist/core/runner/prepare-file-history.js +7 -39
  232. package/dist/core/runner/prepare-gate-stations.d.ts +1 -1
  233. package/dist/core/runner/prepare-gate-stations.js +10 -1
  234. package/dist/core/runner/prepare-hands-readface.d.ts +5 -9
  235. package/dist/core/runner/prepare-hands-readface.js +17 -14
  236. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
  237. package/dist/core/runner/prepare-inherited-gate.js +5 -3
  238. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  239. package/dist/core/runner/prepare-park-ask.d.ts +2 -0
  240. package/dist/core/runner/prepare-park-ask.js +7 -7
  241. package/dist/core/runner/prepare-policy-chain.d.ts +6 -3
  242. package/dist/core/runner/prepare-policy-chain.js +67 -76
  243. package/dist/core/runner/prepare-prompt-assembly.d.ts +5 -7
  244. package/dist/core/runner/prepare-prompt-assembly.js +10 -8
  245. package/dist/core/runner/prepare-prompt-inputs.d.ts +11 -9
  246. package/dist/core/runner/prepare-prompt-inputs.js +3 -5
  247. package/dist/core/runner/prepare-protocol-tools.d.ts +2 -0
  248. package/dist/core/runner/prepare-protocol-tools.js +3 -3
  249. package/dist/core/runner/prepare-safety-scan.d.ts +1 -1
  250. package/dist/core/runner/prepare-safety-scan.js +0 -17
  251. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  252. package/dist/core/runner/prepare-suspend-saga.js +5 -6
  253. package/dist/core/runner/prepare-task.d.ts +5 -2
  254. package/dist/core/runner/prepare-task.js +48 -43
  255. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +20 -4
  256. package/dist/core/runner/prepare-tool-disclosure-mount.js +33 -23
  257. package/dist/core/runner/prepare-turn-wiring.d.ts +0 -4
  258. package/dist/core/runner/prepare-turn-wiring.js +2 -7
  259. package/dist/core/runner/prepare-wiring-manifest.d.ts +6 -2
  260. package/dist/core/runner/prepare-wiring-manifest.js +3 -3
  261. package/dist/core/runner/resume-admission.js +1 -1
  262. package/dist/core/runner/resume-apply.js +11 -12
  263. package/dist/core/runner/resume-checkpoint-screen.js +3 -0
  264. package/dist/core/runner/resume-claim.d.ts +4 -2
  265. package/dist/core/runner/resume-claim.js +15 -8
  266. package/dist/core/runner/retired-runner-deps.js +1 -0
  267. package/dist/core/runner/rewind-files.d.ts +12 -0
  268. package/dist/core/runner/rewind-files.js +90 -0
  269. package/dist/core/runner/run-attachment-seats.js +2 -1
  270. package/dist/core/runner/run-brain-sinks.d.ts +4 -1
  271. package/dist/core/runner/run-brain-sinks.js +4 -2
  272. package/dist/core/runner/run-harness-handlers.js +12 -4
  273. package/dist/core/runner/run-leg.d.ts +1 -1
  274. package/dist/core/runner/run-leg.js +40 -39
  275. package/dist/core/runner/run-notification-lane.d.ts +2 -0
  276. package/dist/core/runner/run-notification-lane.js +2 -2
  277. package/dist/core/runner/run-recovery-lanes.js +3 -4
  278. package/dist/core/runner/run-settle-and-teardown.js +7 -12
  279. package/dist/core/runner/run-terminal-adoption.js +3 -4
  280. package/dist/core/runner/run-turn-boundary.js +4 -15
  281. package/dist/core/runner/runtask.d.ts +10 -0
  282. package/dist/core/runner/runtask.js +35 -42
  283. package/dist/core/runner/send-message-continuation.js +1 -1
  284. package/dist/core/runner/session-read-file-states.d.ts +15 -0
  285. package/dist/core/runner/session-read-file-states.js +28 -0
  286. package/dist/core/runner/session-rule-policy.js +4 -3
  287. package/dist/core/runner/session-verb-doors.d.ts +28 -0
  288. package/dist/core/runner/session-verb-doors.js +48 -0
  289. package/dist/core/runner/session-write-ledger.d.ts +30 -0
  290. package/dist/core/runner/session-write-ledger.js +101 -0
  291. package/dist/core/runner/shell-env-withheld.d.ts +33 -0
  292. package/dist/core/runner/shell-env-withheld.js +51 -0
  293. package/dist/core/runner/skills-seat.js +6 -2
  294. package/dist/core/runner/stream-settle-backstop.js +12 -15
  295. package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
  296. package/dist/core/runner/sub-agent-deny-lists.js +25 -17
  297. package/dist/core/runner/synthetic-tools.d.ts +6 -0
  298. package/dist/core/runner/synthetic-tools.js +4 -1
  299. package/dist/core/runner/teardown-bounded.d.ts +1 -0
  300. package/dist/core/runner/teardown-bounded.js +1 -0
  301. package/dist/core/runner/tool-disclosure.d.ts +10 -12
  302. package/dist/core/runner/tool-disclosure.js +1 -3
  303. package/dist/core/runner/tool-end-body.d.ts +1 -1
  304. package/dist/core/runner/tool-end-body.js +10 -9
  305. package/dist/core/runner/tool-not-executed.d.ts +5 -0
  306. package/dist/core/runner/tool-not-executed.js +11 -0
  307. package/dist/core/runner/tool-occurrence.d.ts +8 -0
  308. package/dist/core/runner/tool-occurrence.js +7 -0
  309. package/dist/core/runner/turn-attachments.d.ts +33 -15
  310. package/dist/core/runner/turn-attachments.js +62 -37
  311. package/dist/core/runner-deps.d.ts +7 -7
  312. package/dist/core/safety-axis-vocab.d.ts +6 -4
  313. package/dist/core/safety-axis-vocab.js +6 -5
  314. package/dist/core/safety-merge-corpus.js +11 -3
  315. package/dist/core/secret-env.d.ts +30 -3
  316. package/dist/core/secret-env.js +47 -8
  317. package/dist/core/select-model.js +3 -3
  318. package/dist/core/session-policy-store.d.ts +32 -15
  319. package/dist/core/session-policy-store.js +156 -36
  320. package/dist/core/session-store.d.ts +29 -10
  321. package/dist/core/session-store.js +51 -19
  322. package/dist/core/session.d.ts +82 -16
  323. package/dist/core/session.js +53 -0
  324. package/dist/core/shell-read-silence.d.ts +11 -12
  325. package/dist/core/shell-read-silence.js +9 -5
  326. package/dist/core/shell-run-candidates.js +3 -1
  327. package/dist/core/shell-wrapper-projection.d.ts +1 -1
  328. package/dist/core/shell-wrapper-projection.js +1 -1
  329. package/dist/core/shell-wrapper-table.d.ts +14 -7
  330. package/dist/core/shell-wrapper-table.js +5 -4
  331. package/dist/core/side-query.js +10 -1
  332. package/dist/core/skill-grant.d.ts +7 -2
  333. package/dist/core/skill-grant.js +5 -0
  334. package/dist/core/skills-directory.js +6 -2
  335. package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
  336. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +11 -1
  337. package/dist/core/store-contracts/checkpoint-store-contract.js +141 -2
  338. package/dist/core/store-contracts/file-history-store-contract.js +40 -1
  339. package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
  340. package/dist/core/store-contracts/peer-directory-contract.d.ts +7 -2
  341. package/dist/core/store-contracts/peer-directory-contract.js +14 -2
  342. package/dist/core/store-contracts/session-repo-contract.js +51 -0
  343. package/dist/core/store-contracts/session-store-contract.d.ts +2 -1
  344. package/dist/core/store-contracts/session-store-contract.js +150 -14
  345. package/dist/core/stub-env.d.ts +2 -0
  346. package/dist/core/stub-env.js +1 -0
  347. package/dist/core/synthetic-read-verdict.js +3 -3
  348. package/dist/core/task-event.d.ts +32 -4
  349. package/dist/core/task-notification.d.ts +16 -12
  350. package/dist/core/task-registry-agent.d.ts +8 -4
  351. package/dist/core/task-registry-agent.js +14 -8
  352. package/dist/core/task-registry-shared.d.ts +35 -6
  353. package/dist/core/task-registry-shared.js +11 -0
  354. package/dist/core/task-registry.d.ts +10 -1
  355. package/dist/core/task-registry.js +12 -2
  356. package/dist/core/task-result.d.ts +18 -0
  357. package/dist/core/task-spec.d.ts +18 -13
  358. package/dist/core/tighten-task-spec.js +2 -1
  359. package/dist/core/tool-catalog-entries.d.ts +23 -0
  360. package/dist/core/tool-catalog-entries.js +14 -2
  361. package/dist/core/tool-check-reading.d.ts +11 -0
  362. package/dist/core/tool-check-reading.js +11 -6
  363. package/dist/core/tool-model-gate.d.ts +2 -2
  364. package/dist/core/tool-name-aliases.d.ts +48 -18
  365. package/dist/core/tool-name-aliases.js +36 -19
  366. package/dist/core/tool-name-readings.d.ts +6 -32
  367. package/dist/core/tool-name-readings.js +2 -9
  368. package/dist/core/tool-policy.d.ts +78 -204
  369. package/dist/core/tool-policy.js +152 -204
  370. package/dist/core/tool-result-store.js +3 -0
  371. package/dist/core/tool-roster.d.ts +14 -19
  372. package/dist/core/tool-roster.js +11 -44
  373. package/dist/core/tool-spec-members.js +7 -2
  374. package/dist/core/tool-spec.d.ts +19 -11
  375. package/dist/core/tools.js +49 -9
  376. package/dist/core/trace.d.ts +6 -3
  377. package/dist/core/trace.js +2 -1
  378. package/dist/core/types.d.ts +1 -1
  379. package/dist/core/untrusted-egress.d.ts +20 -0
  380. package/dist/core/untrusted-egress.js +77 -3
  381. package/dist/core/user-attachment.d.ts +8 -1
  382. package/dist/core/user-attachment.js +64 -4
  383. package/dist/core/wiring-manifest.d.ts +9 -0
  384. package/dist/core/wiring-manifest.js +1 -0
  385. package/dist/core/workflow-journal-store.js +1 -1
  386. package/dist/engine/compaction/compaction.js +3 -2
  387. package/dist/engine/execution-env/node-execution-env.d.ts +7 -3
  388. package/dist/engine/execution-env/node-execution-env.js +11 -2
  389. package/dist/engine/harness/agent-harness.d.ts +32 -6
  390. package/dist/engine/harness/agent-harness.js +65 -9
  391. package/dist/engine/harness/types.d.ts +29 -2
  392. package/dist/engine/llm/types.d.ts +28 -11
  393. package/dist/engine/loop/agent-loop.d.ts +23 -4
  394. package/dist/engine/loop/agent-loop.js +42 -30
  395. package/dist/engine/loop/types.d.ts +16 -6
  396. package/dist/engine/session/memory-repo.d.ts +9 -2
  397. package/dist/engine/session/memory-repo.js +11 -1
  398. package/dist/engine/session/repo-utils.d.ts +6 -5
  399. package/dist/engine/session/repo-utils.js +14 -6
  400. package/dist/index.d.ts +34 -17
  401. package/dist/index.js +22 -11
  402. package/dist/internal/harness-types.d.ts +1 -1
  403. package/dist/internal/harness.d.ts +2 -1
  404. package/dist/internal/harness.js +1 -0
  405. package/dist/internal/llm.d.ts +1 -1
  406. package/dist/orchestration/run-workflow-tool.d.ts +6 -4
  407. package/dist/orchestration/run-workflow-tool.js +5 -3
  408. package/dist/orchestration/workflow.d.ts +3 -0
  409. package/dist/orchestration/workflow.js +36 -18
  410. package/dist/primitives/credential-ref.d.ts +89 -0
  411. package/dist/primitives/credential-ref.js +125 -0
  412. package/dist/primitives/index.d.ts +2 -0
  413. package/dist/primitives/index.js +1 -0
  414. package/dist/prompt-assembly/artifact.d.ts +2 -2
  415. package/dist/prompt-assembly/artifact.js +5 -3
  416. package/dist/prompt-assembly/assemble.d.ts +3 -2
  417. package/dist/prompt-assembly/assemble.js +1 -1
  418. package/dist/prompt-assembly/catalog/schema.d.ts +43 -12
  419. package/dist/prompt-assembly/catalog/schema.js +34 -2
  420. package/dist/prompt-assembly/catalog/sections.js +0 -1
  421. package/dist/prompt-assembly/composer.d.ts +3 -1
  422. package/dist/prompt-assembly/composer.js +1 -1
  423. package/dist/prompt-assembly/event-registry.js +1 -0
  424. package/dist/prompt-assembly/overlay.js +3 -3
  425. package/dist/prompt-assembly/renderers.d.ts +1 -1
  426. package/dist/prompt-assembly/renderers.js +0 -3
  427. package/dist/prompt-assembly/role-base.d.ts +15 -0
  428. package/dist/prompt-assembly/role-base.js +9 -0
  429. package/dist/prompt-assembly/select.d.ts +39 -14
  430. package/dist/prompt-assembly/select.js +47 -16
  431. package/dist/prompt-assembly/sugar.d.ts +17 -11
  432. package/dist/prompt-assembly/sugar.js +8 -3
  433. package/dist/prompt-assembly/tool-catalog.d.ts +37 -3
  434. package/dist/prompt-assembly/tool-catalog.js +114 -4
  435. package/dist/prompt-assembly/turn-snapshot.d.ts +4 -10
  436. package/dist/prompt-assembly/turn-snapshot.js +0 -3
  437. package/dist/prompt-assembly/types.d.ts +0 -7
  438. package/dist/scenarios/full-body.d.ts +11 -11
  439. package/dist/scenarios/full-body.js +4 -3
  440. package/dist/shell/lex.js +10 -1
  441. package/dist/stores/file/adoption/adopt.js +4 -3
  442. package/dist/stores/file/adoption/marker.js +3 -2
  443. package/dist/stores/file/checkpoint-store.d.ts +21 -4
  444. package/dist/stores/file/checkpoint-store.js +38 -7
  445. package/dist/stores/file/file-history-store.js +18 -11
  446. package/dist/stores/file/index.js +2 -1
  447. package/dist/stores/file/mailbox-store.d.ts +2 -1
  448. package/dist/stores/file/mailbox-store.js +26 -1
  449. package/dist/stores/file/permission-rule-adopt.js +4 -3
  450. package/dist/stores/file/permission-rule-store.js +11 -5
  451. package/dist/stores/file/session-store.d.ts +29 -6
  452. package/dist/stores/file/session-store.js +42 -50
  453. package/dist/tools/artifact/artifact-tool.js +3 -2
  454. package/dist/tools/fs/bash-program-position.d.ts +19 -2
  455. package/dist/tools/fs/bash-program-position.js +56 -9
  456. package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
  457. package/dist/tools/fs/bash-readonly-classifier.js +5 -10
  458. package/dist/tools/fs/fs-bash.js +15 -8
  459. package/dist/tools/fs/fs-glob.d.ts +86 -0
  460. package/dist/tools/fs/fs-glob.js +226 -0
  461. package/dist/tools/fs/fs-read.js +14 -14
  462. package/dist/tools/fs/fs-search-tools.js +7 -7
  463. package/dist/tools/fs/pattern-kill-guard.d.ts +23 -0
  464. package/dist/tools/fs/pattern-kill-guard.js +429 -0
  465. package/dist/tools/fs/pdf.d.ts +9 -6
  466. package/dist/tools/fs/pdf.js +3 -3
  467. package/dist/tools/fs/program-read-model.d.ts +57 -7
  468. package/dist/tools/fs/program-read-model.js +11 -1
  469. package/dist/tools/fs/program-read-model.rows.js +78 -21
  470. package/dist/tools/fs/read-deny-home.js +3 -2
  471. package/dist/tools/fs/removal-targets.d.ts +17 -7
  472. package/dist/tools/fs/removal-targets.js +47 -20
  473. package/dist/tools/fs/search.d.ts +10 -0
  474. package/dist/tools/fs/search.js +20 -26
  475. package/dist/tools/fs/shell-read-argv.js +89 -12
  476. package/dist/tools/fs/shell-read-bindings.d.ts +31 -0
  477. package/dist/tools/fs/shell-read-bindings.js +41 -0
  478. package/dist/tools/fs/shell-read-check.d.ts +10 -0
  479. package/dist/tools/fs/shell-read-check.js +13 -20
  480. package/dist/tools/fs/shell-read-environment.d.ts +5 -1
  481. package/dist/tools/fs/shell-read-environment.js +3 -2
  482. package/dist/tools/fs/shell-read-establish.d.ts +15 -0
  483. package/dist/tools/fs/shell-read-establish.js +19 -20
  484. package/dist/tools/fs/shell-read-identity.d.ts +12 -9
  485. package/dist/tools/fs/shell-read-identity.js +9 -4
  486. package/dist/tools/fs/shell-read-plan.js +24 -16
  487. package/dist/tools/fs/shell-read-start.d.ts +6 -1
  488. package/dist/tools/fs/shell-read-write-targets.d.ts +5 -1
  489. package/dist/tools/fs/shell-read-write-targets.js +2 -3
  490. package/dist/tools/fs/shell-reentry-text.d.ts +9 -0
  491. package/dist/tools/fs/shell-reentry-text.js +40 -2
  492. package/dist/tools/todo.js +63 -63
  493. package/dist/tools/web.d.ts +19 -14
  494. package/dist/tools/web.js +46 -61
  495. package/package.json +1 -1
  496. package/test/export-surface.snapshot.json +221 -7
  497. package/wire-changes/core-stores-sql@7.57.0.json +29 -0
  498. package/wire-changes/core@7.56.0.json +3891 -0
  499. package/wire-changes/core@7.57.0.json +1487 -0
  500. package/wire-changes/mods-kernel@7.56.0.json +303 -0
  501. package/wire-changes/mods-kernel@7.57.0.json +29 -0
  502. package/wire-changes/primitives@7.57.0.json +245 -0
@@ -513,13 +513,21 @@ export interface QuarantineOutcome {
513
513
  * without native bindings. What this buys is the leaf variant, which is the cheap one; the ancestor
514
514
  * variant stays open and is recorded with the rest of the family rather than papered over.
515
515
  *
516
- * Throws like `writeFileSync`, including ELOOP when the final component IS a symlink. A HARD link is the
517
- * same tamper by other means — the file's bytes live under a second name, possibly outside the store, and
518
- * an in-place write would change them there too — so an opened file with more than one name is refused
519
- * the same way, before anything is truncated (the check reads the opened descriptor: no window). The
520
- * write itself goes through `writeFileSync` on the open descriptor, which writes every byte or throws —
521
- * a bare `writeSync` may short-write, and reporting a truncated restore as contained (after the
522
- * truncation already destroyed the destination) is the failure this guard exists to prevent.
516
+ * Throws like `writeFileSync`, including ELOOP when the final component IS a symlink, and EACCES for a
517
+ * file whose own bits refuse the write. A write changes only the NAME it writes. A file with one name is
518
+ * rewritten in place (its inode and mode stay). A HARD link is the same tamper as a symlink by other
519
+ * means — the file's bytes live under a second name, possibly outside the store, and an in-place write
520
+ * would change them there too — so a file the open finds with more names is never written in place.
521
+ * One such name is the engine's own: a staging name a no-replace restore stopped between its `link` and
522
+ * its `unlink` left beside the file; it is removed first ({@link dropStagingSecondNames}), the interrupted
523
+ * restore's last step. A file that still has another name gets a new file under THIS name, written the
524
+ * way the store commits a file ({@link atomicWriteFileSync}: an exclusive no-follow sibling, 0o600,
525
+ * renamed over this name); the other names keep their file, its bytes and its mode. Residual: a path
526
+ * replaced by another file between the open and that rename is replaced again (the window every
527
+ * rename-based store write has). The in-place write goes through `writeFileSync` on the open descriptor,
528
+ * which writes every byte or throws — a bare `writeSync` may short-write, and reporting a truncated
529
+ * restore as contained (after the truncation already destroyed the destination) is the failure this
530
+ * guard exists to prevent.
523
531
  */
524
532
  export declare function writeFileNoFollow(path: string, content: string): void;
525
533
  /** {@link writeFileNoFollow}'s NO-REPLACE twin: write `content` only if nothing is at `path`. `"written"`
@@ -529,6 +537,48 @@ export declare function writeFileNoFollow(path: string, content: string): void;
529
537
  * it refuses a symlink at the final component on its own (POSIX `EEXIST` on a link, dangling or not),
530
538
  * so the twin's no-follow property is kept without a second check. */
531
539
  export declare function writeFileNoReplace(path: string, content: string): "written" | "kept";
540
+ /** THE minter of every staging name the engine puts beside a plane file while it is displaced:
541
+ * `<owner>.staging-<ms>-<pid>-<seq>`. One grammar for every site, so one recognizer
542
+ * ({@link stagingNamePattern}) knows the names the engine can have left beside a seat. */
543
+ export declare function mintStagingName(owner: string, now: () => number): string;
544
+ /** The grammar {@link mintStagingName} and {@link claimStaging} write, as a recognizer — of ONE owner's
545
+ * generations when `owner` is given; otherwise of every staging name an engine has minted beside a seat,
546
+ * for the two owners it mints them for: an instruction hold (`hold-<ms>-<12 hex>`) and a crash-residue
547
+ * capture (`<ms>-residue-<entry id>.md`), whose `<ms>-residue-<id>.md.staging` of 7.55.0 and earlier is
548
+ * included (a name already on disk does not lose its owner with an upgrade). A prefix or a bare
549
+ * `.staging-` suffix would adopt any name a writer chose on the strength of its spelling. Minted and
550
+ * recognised side by side so the two cannot drift. */
551
+ export declare function stagingNamePattern(owner?: string): RegExp;
552
+ /** Take exclusive hold of a staged name by an atomic same-directory rename to a name minted HERE: the
553
+ * staged name lives in a WRITABLE directory, so a plain read-then-unlink could delete a replacement that
554
+ * landed between the two while reporting success over the earlier bytes. After the claim, what the rename
555
+ * moved is what every later read and unlink addresses. Returns the claim when it took, the original when
556
+ * the directory refused it (a hardening, not a precondition — a caller that removes on the strength of
557
+ * the claim checks which one it got). Residual: a writer enumerating the directory can still replace the
558
+ * CLAIM name before it is read — nothing Node's `fs` closes that, and the window is narrower than the one
559
+ * it replaces. */
560
+ export declare function claimStaging(stagingPath: string): string;
561
+ /** Whether `path` names the file `ref` describes: a regular file on the same device with the same inode,
562
+ * read without following a link at `path`. */
563
+ export declare function isSameFile(path: string, ref: {
564
+ readonly dev: number;
565
+ readonly ino: number;
566
+ }): boolean;
567
+ /**
568
+ * Remove every staging name an engine minted ({@link stagingNamePattern}) beside `seat` that is another
569
+ * name of the file `opened` describes — the un-dropped half of a no-replace restore stopped between its
570
+ * `link` and its `unlink`. Called by a write about to replace that file's bytes: removing the name loses
571
+ * nothing the write itself does not overwrite, and touches only names in the engine's staging grammar (a name
572
+ * is read as the engine's own by its spelling and by being the same file, so a hard link someone made and
573
+ * spelled that way goes too; every other hard-link copy, snapshot name and planted link stays, with its file).
574
+ * Not claimed first: a claim is a `rename`, which replaces whatever already stands at the claim name.
575
+ * Residual: a file put at that minted name between the check and the removal is removed — only a writer of
576
+ * this directory can put it there, and it can remove the name itself. Answers how many names went.
577
+ */
578
+ export declare function dropStagingSecondNames(seat: string, opened: {
579
+ readonly dev: number;
580
+ readonly ino: number;
581
+ }): number;
532
582
  /**
533
583
  * The ONE way a committed baseline goes back after {@link quarantineAndTombstone} emptied its seat —
534
584
  * the inverse half of that function, beside it so the removal word and its readers stay in one module.
@@ -1272,7 +1322,9 @@ export declare function writeAllSync(fd: number, data: string): void;
1272
1322
  * is not fsync'd (stores/file/fs-atomic.ts has the dir-fsync variant for stores that need it), so
1273
1323
  * a crash in that window can resurface the old content. Sidecars tolerate that (they are rebuilt
1274
1324
  * or re-derived); do not route data that can't through here. Throws on failure (fail-closed: a
1275
- * sidecar that cannot be written must not be silently skipped). */
1325
+ * sidecar that cannot be written must not be silently skipped). The tmp file is created EXCLUSIVELY and
1326
+ * no-follow: a name already standing there (a link or a file somebody placed) is an `EEXIST` refusal,
1327
+ * never a file this write truncates or writes through. */
1276
1328
  export declare function atomicWriteFileSync(path: string, data: string): void;
1277
1329
  /** Content-gated {@link atomicWriteFileSync} for a DERIVED/control-plane file: a byte-identical
1278
1330
  * rewrite (the common case on a repeat mount over an unchanged store) is skipped entirely, so the
@@ -6,6 +6,7 @@ import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
6
6
  import { MEMORY_ORIGIN_CAUSES } from "./types.js";
7
7
  import { physicalPathOf, physicalPathOfExisting, priorCallerCasedPathOf } from "../physical-path.js";
8
8
  import { thrownLabel, thrownText } from "../thrown-value.js";
9
+ import { egressText } from "../untrusted-egress.js";
9
10
  const SCOPES_FILE = "scopes.json";
10
11
  export const CURSORS_FILE = "cursors.json";
11
12
  export const CONTROL_PLANE_DIR = ".engine";
@@ -1137,16 +1138,20 @@ export const QUARANTINE_DIR = "quarantine";
1137
1138
  const DELETED_TOMBSTONE = "---\ndeleted: true\n---\n";
1138
1139
  export function writeFileNoFollow(path, content) {
1139
1140
  const fd = openSync(path, O_WRONLY | O_CREAT | O_NOFOLLOW, 0o644);
1141
+ let names;
1140
1142
  try {
1141
- const links = fstatSync(fd).nlink;
1142
- if (links > 1)
1143
- throw Object.assign(new Error(`${path} has ${links} names (a hard link) — a write through one name changes the file under the others; not written`), { path });
1144
- ftruncateSync(fd, 0);
1145
- writeFileSync(fd, content, "utf8");
1143
+ const opened = fstatSync(fd);
1144
+ names = opened.nlink > 1 && dropStagingSecondNames(path, opened) > 0 ? fstatSync(fd).nlink : opened.nlink;
1145
+ if (names <= 1) {
1146
+ ftruncateSync(fd, 0);
1147
+ writeFileSync(fd, content, "utf8");
1148
+ }
1146
1149
  }
1147
1150
  finally {
1148
1151
  closeSync(fd);
1149
1152
  }
1153
+ if (names > 1)
1154
+ atomicWriteFileSync(path, content);
1150
1155
  }
1151
1156
  export function writeFileNoReplace(path, content) {
1152
1157
  let fd;
@@ -1166,6 +1171,61 @@ export function writeFileNoReplace(path, content) {
1166
1171
  }
1167
1172
  return "written";
1168
1173
  }
1174
+ let stagingSeq = 0;
1175
+ export function mintStagingName(owner, now) {
1176
+ stagingSeq += 1;
1177
+ return `${owner}.staging-${now()}-${process.pid}-${stagingSeq}`;
1178
+ }
1179
+ export function stagingNamePattern(owner) {
1180
+ const head = owner === undefined
1181
+ ? String.raw `(?:hold-\d+-[0-9a-f]{12}\.staging-\d+-\d+-\d+|\d+-residue-[^/]+\.md\.staging(?:-\d+-\d+-\d+)?)`
1182
+ : String.raw `${owner.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\.staging-\d+-\d+-\d+`;
1183
+ return new RegExp(String.raw `^${head}(?:\.claim-\d+-\d+)*$`);
1184
+ }
1185
+ export function claimStaging(stagingPath) {
1186
+ stagingSeq += 1;
1187
+ const claimed = `${stagingPath}.claim-${process.pid}-${stagingSeq}`;
1188
+ try {
1189
+ renameSync(stagingPath, claimed);
1190
+ return claimed;
1191
+ }
1192
+ catch {
1193
+ return stagingPath;
1194
+ }
1195
+ }
1196
+ export function isSameFile(path, ref) {
1197
+ try {
1198
+ const st = lstatSync(path);
1199
+ return st.isFile() && st.dev === ref.dev && st.ino === ref.ino;
1200
+ }
1201
+ catch {
1202
+ return false;
1203
+ }
1204
+ }
1205
+ export function dropStagingSecondNames(seat, opened) {
1206
+ const dir = dirname(seat);
1207
+ let names;
1208
+ try {
1209
+ names = readdirSync(dir);
1210
+ }
1211
+ catch {
1212
+ return 0;
1213
+ }
1214
+ const minted = stagingNamePattern();
1215
+ let dropped = 0;
1216
+ for (const name of names) {
1217
+ const at = join(dir, name);
1218
+ if (name === basename(seat) || !minted.test(name) || !isSameFile(at, opened))
1219
+ continue;
1220
+ try {
1221
+ unlinkSync(at);
1222
+ dropped += 1;
1223
+ }
1224
+ catch {
1225
+ }
1226
+ }
1227
+ return dropped;
1228
+ }
1169
1229
  function readForVerification(path, maxBytes) {
1170
1230
  let fd;
1171
1231
  try {
@@ -1408,6 +1468,7 @@ function readSidecarJson(controlDir, fileName) {
1408
1468
  }
1409
1469
  return undefined;
1410
1470
  }
1471
+ const mintedItems = (items) => items.map((item) => egressText("same-principal", item));
1411
1472
  function coerceAnnouncements(raw) {
1412
1473
  const rec = { folded: 0, queue: [] };
1413
1474
  if (!raw || typeof raw !== "object" || Array.isArray(raw))
@@ -1429,7 +1490,7 @@ function coerceAnnouncements(raw) {
1429
1490
  at: a.at,
1430
1491
  ...(typeof a.sessionId === "string" ? { sessionId: a.sessionId } : {}),
1431
1492
  ...(typeof a.reportId === "string" ? { reportId: a.reportId } : {}),
1432
- items: a.items,
1493
+ items: mintedItems(a.items),
1433
1494
  });
1434
1495
  }
1435
1496
  }
@@ -1437,7 +1498,8 @@ function coerceAnnouncements(raw) {
1437
1498
  return rec;
1438
1499
  }
1439
1500
  export function enqueueMemoryAnnouncement(controlDir, ann, opts) {
1440
- const family = opts?.supersedesPrefix;
1501
+ ann = { ...ann, items: mintedItems(ann.items) };
1502
+ const family = opts?.supersedesPrefix === undefined ? undefined : egressText("same-principal", opts.supersedesPrefix);
1441
1503
  if (ann.items.length === 0 && family === undefined)
1442
1504
  return;
1443
1505
  lockedJournaledUpdate(controlDir, ANNOUNCEMENTS_FILE, (current) => {
@@ -2628,7 +2690,7 @@ export function writeAllSync(fd, data) {
2628
2690
  export function atomicWriteFileSync(path, data) {
2629
2691
  ensureDirExists(dirname(path));
2630
2692
  const tmp = join(dirname(path), `.tmp-${process.pid}-${Math.random().toString(36).slice(2, 10)}`);
2631
- const fd = openSync(tmp, "w", 0o600);
2693
+ const fd = openSync(tmp, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, 0o600);
2632
2694
  try {
2633
2695
  writeAllSync(fd, data);
2634
2696
  fsyncSync(fd);
@@ -49,9 +49,16 @@ export type RoleSpec = ModelRef | {
49
49
  select?: import("./select-model.js").ModelCriteria;
50
50
  thinking?: ThinkingLevel;
51
51
  /**
52
- * Optional preset system prompt for this role (e.g. {@link CODE_AGENT_PROMPT} for a dev role).
53
- * Used only when the task does not supply its own `TaskSpec.systemPrompt`. Lets coding roles run
54
- * a coding prompt while other roles keep the neutral default — without touching the global default.
52
+ * The role's preset role base, by WORD: which catalog role base (`core/role.base` variant) tasks of this role
53
+ * are assembled for — `"code"` for a coding role — and their host role. Same closed set and door as
54
+ * `TaskSpec.promptRole` (`HOST_ROLES`; outside it ⇒ `config.prompt_selector_invalid`, naming `roles.<role>.promptRole`).
55
+ * The preset applies only when the task names no role base of its own (neither `promptRole` nor `systemPrompt`):
56
+ * the first source that names one — task, then this preset, then an engine spawner's child persona — decides it.
57
+ */
58
+ promptRole?: import("../prompt-assembly/catalog/schema.js").HostRole;
59
+ /**
60
+ * The role's preset role base, by TEXT (it replaces the base `promptRole` selects; the role is `promptRole`, else
61
+ * `general`). Same precedence as `promptRole`: used only when the task names no role base of its own.
55
62
  */
56
63
  systemPrompt?: string;
57
64
  };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The one typing of the engine's classic stations: each `classic.*` event a station raises, paired with its `e` and its
3
+ * answer form. Every raise site constructs its `e` against it (`dispatchClassic` / `observeClassic`), and the engine's
4
+ * registration form types a handler by it. Its keys are the event table's `classic.*` rows that carry a station — the key
5
+ * set is held to that table.
6
+ */
7
+ import type { PermissionDeniedPayload, PostCompactEvent, PostToolBatchEvent, PostToolBatchResult, PostToolUseEvent, PostToolUseFailureEvent, PostToolUseFailureResult, PostToolUseResult, PreCompactEvent, PreCompactResult, PreToolUseEvent, PreToolUseResult, StopEvent, StopFailureEvent, StopHookResult, UserPromptSubmitEvent, UserPromptSubmitResult } from "../hooks.js";
8
+ import type { MappedOn, ModRegistration } from "./kernel/index.js";
9
+ import type { EngineDollar } from "./dollar.js";
10
+ /** The answer of an event whose station reads none (an observation event): a chain handler passes `next(e)`'s on. */
11
+ export type ObservedAnswer = Readonly<Record<string, never>>;
12
+ /** Each `classic.*` event a station raises, with its `e` and its answer form. */
13
+ export type ClassicEventMap = {
14
+ readonly "classic.PreToolUse": {
15
+ readonly e: PreToolUseEvent;
16
+ readonly answer: PreToolUseResult | null | false;
17
+ };
18
+ readonly "classic.PostToolUse": {
19
+ readonly e: PostToolUseEvent;
20
+ readonly answer: PostToolUseResult;
21
+ };
22
+ readonly "classic.PostToolUseFailure": {
23
+ readonly e: PostToolUseFailureEvent;
24
+ readonly answer: PostToolUseFailureResult;
25
+ };
26
+ readonly "classic.PostToolBatch": {
27
+ readonly e: PostToolBatchEvent;
28
+ readonly answer: PostToolBatchResult;
29
+ };
30
+ readonly "classic.UserPromptSubmit": {
31
+ readonly e: UserPromptSubmitEvent;
32
+ readonly answer: UserPromptSubmitResult;
33
+ };
34
+ readonly "classic.Stop": {
35
+ readonly e: StopEvent;
36
+ readonly answer: StopHookResult;
37
+ };
38
+ readonly "classic.SubagentStop": {
39
+ readonly e: StopEvent;
40
+ readonly answer: StopHookResult;
41
+ };
42
+ readonly "classic.StopFailure": {
43
+ readonly e: StopFailureEvent;
44
+ readonly answer: ObservedAnswer;
45
+ };
46
+ readonly "classic.PreCompact": {
47
+ readonly e: PreCompactEvent;
48
+ readonly answer: PreCompactResult;
49
+ };
50
+ readonly "classic.PostCompact": {
51
+ readonly e: PostCompactEvent;
52
+ readonly answer: ObservedAnswer;
53
+ };
54
+ readonly "classic.PermissionDenied": {
55
+ readonly e: PermissionDeniedPayload;
56
+ readonly answer: ObservedAnswer;
57
+ };
58
+ };
59
+ /** A `classic.*` event a station raises. */
60
+ export type ClassicEventName = keyof ClassicEventMap;
61
+ /**
62
+ * A registration on the engine's bus (`RunnerDeps.mods`, `TaskSpec.mods`): the kernel's registration form whose `on`
63
+ * types a handler of a `classic.*` event by {@link ClassicEventMap} — its `e`, its `next`, its answer.
64
+ */
65
+ export interface EngineModRegistration extends Omit<ModRegistration<EngineDollar>, "register"> {
66
+ register(on: MappedOn<EngineDollar, ClassicEventMap>, options: unknown): void;
67
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -100,10 +100,23 @@ export interface EngineDollar extends ModDollarBase {
100
100
  };
101
101
  readonly tool: {
102
102
  list(): Promise<readonly string[]>;
103
+ /** `$.tool.call({ tool, ...input })`: the run's own pipeline for one call of a mounted tool (`tool-call.ts`). */
104
+ call(args: {
105
+ readonly tool: string;
106
+ } & Readonly<Record<string, unknown>>): Promise<ToolCallAnswer>;
103
107
  };
104
108
  readonly agent: {
105
109
  list(): Promise<readonly string[]>;
106
110
  };
107
111
  }
112
+ /** What `$.tool.call` answers — `tool.call`'s own forms: the frozen view of the call's result, or the refusal (returned, not thrown). */
113
+ export type ToolCallAnswer = {
114
+ readonly result: {
115
+ readonly content: readonly object[];
116
+ readonly isError: boolean;
117
+ };
118
+ } | {
119
+ readonly deny: string;
120
+ };
108
121
  /** The chain bottoms of the wave-one method events over a runner's seat view. */
109
122
  export declare function engineMethodBottoms(view: ModSeatView): ModMethodBottoms;
@@ -0,0 +1,31 @@
1
+ import { type ModBottomContext, type ModBus } from "./kernel/index.js";
2
+ import type { ExtensionRequester } from "../task-event.js";
3
+ /** One extension's call while it runs. */
4
+ export interface ExtensionCall {
5
+ /** The leg bus the call was made on (the one {@link legBusOf} returned). */
6
+ readonly bus: ModBus;
7
+ readonly toolCallId: string;
8
+ /** The `$` call's context: the frames its pipeline's events are raised under, and its origin. */
9
+ readonly caller: ModBottomContext;
10
+ /** Cleared when the call's pipeline settles — the one reading of "this call is still running". */
11
+ readonly live: boolean;
12
+ /** The call's end projection refused it (its latest gate record is a refusal) — written once, by the leg's tool_end station. */
13
+ readonly denied: boolean;
14
+ }
15
+ /** The running extension call this chain carries for `bus`, when it is the call `toolCallId` names (or any, unnamed). */
16
+ export declare function extensionCallOf(bus: object, toolCallId?: string): ExtensionCall | undefined;
17
+ /** Who asked for the call `toolCallId` names, when it is the running extension call: the one projection every carrier of
18
+ * `requestedBy` reads (the occurrence the frames are projected from, the approval card). */
19
+ export declare function requesterOf(bus: object, toolCallId: string): {
20
+ readonly requestedBy?: ExtensionRequester;
21
+ };
22
+ /** The leg's tool_end station says the call it is closing was refused (a no-op for any call that is not the running extension call). */
23
+ export declare function noteExtensionCallDenied(bus: object, toolCallId: string): void;
24
+ /** Run an extension's call: `pipeline` runs with the call's record in scope; the record stops being live when it settles. */
25
+ export declare function runExtensionCall<T>(bus: ModBus, toolCallId: string, caller: ModBottomContext, pipeline: (call: ExtensionCall) => Promise<T>): Promise<T>;
26
+ /**
27
+ * The leg bus every station raises on: a dispatch inside a running extension call made on it is raised under that call's
28
+ * frames and origin (a raiser that names its own frames keeps them — they extend the call's); one raised under a call
29
+ * that has settled is refused, `failed` by the engine and said once on `report`; any other dispatch is the bus's own.
30
+ */
31
+ export declare function legBusOf(bus: ModBus, report: (err: Error) => void): ModBus;
@@ -0,0 +1,43 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { ENGINE_ORIGIN } from "./kernel/index.js";
3
+ const store = new AsyncLocalStorage();
4
+ export function extensionCallOf(bus, toolCallId) {
5
+ const c = store.getStore();
6
+ return c !== undefined && c.live && c.bus === bus && (toolCallId === undefined || c.toolCallId === toolCallId) ? c : undefined;
7
+ }
8
+ export function requesterOf(bus, toolCallId) {
9
+ const c = extensionCallOf(bus, toolCallId);
10
+ return c !== undefined ? { requestedBy: Object.freeze({ kind: "extension", name: c.caller.origin.plugin }) } : {};
11
+ }
12
+ export function noteExtensionCallDenied(bus, toolCallId) {
13
+ const c = store.getStore();
14
+ if (c !== undefined && c.live && c.bus === bus && c.toolCallId === toolCallId)
15
+ c.denied = true;
16
+ }
17
+ export async function runExtensionCall(bus, toolCallId, caller, pipeline) {
18
+ const call = { bus, toolCallId, caller, live: true, denied: false };
19
+ try {
20
+ return await store.run(call, () => pipeline(call));
21
+ }
22
+ finally {
23
+ call.live = false;
24
+ }
25
+ }
26
+ export function legBusOf(bus, report) {
27
+ const leg = {
28
+ records: bus.records,
29
+ mounted: () => bus.mounted(),
30
+ hasHandlers: (event, participant) => bus.hasHandlers(event, participant),
31
+ dispatch: (event, e, options) => {
32
+ const c = store.getStore();
33
+ if (c === undefined || c.bus !== leg || options.frames !== undefined)
34
+ return bus.dispatch(event, e, options);
35
+ if (c.live)
36
+ return bus.dispatch(event, e, { ...options, frames: c.caller.frames, origin: c.caller.origin });
37
+ const reason = `${event}: raised under extension "${c.caller.origin.plugin}"'s call ${c.toolCallId}, which has ended — an event is not raised under a call that is over`;
38
+ report(new Error(`engine: ${reason} — the dispatch was not run`));
39
+ return Promise.resolve(Object.freeze({ kind: "failed", registration: ENGINE_ORIGIN.plugin, cause: "violation", reason, skipped: Object.freeze([]) }));
40
+ },
41
+ };
42
+ return leg;
43
+ }
@@ -1,6 +1,6 @@
1
1
  import { type ModBusSide, type ModEventName, type ModSeat } from "./events.js";
2
2
  import { type ModAdmissionRecord, type ModDollarBase, type ModOrigin, type ModSeats } from "./registration.js";
3
- import { type ModAnswerCheck, type ModEventPayload, type ModFailureCause, type ModMatcher, type ModSkip, type ProxyProbe } from "./site-rules.js";
3
+ import { type ModAnswerCheck, type ModAnswerRanks, type ModEventPayload, type ModFailureCause, type ModMatcher, type ModSkip, type ProxyProbe } from "./site-rules.js";
4
4
  /** A frame on the dispatch stack: a registration's own `$` call, or one of its handlers running. */
5
5
  export type ModFrame = {
6
6
  readonly kind: "dollar";
@@ -28,6 +28,13 @@ export interface ModMethodSeat {
28
28
  readonly enter?: (args: ModEventPayload) => ModEventPayload;
29
29
  }
30
30
  export type ModMethodBottoms = Partial<Record<ModEventName, ModMethodSeat>>;
31
+ /**
32
+ * A callable event's host entry: what a `$` call of the event reaches. It runs whatever stands before the event and
33
+ * raises the event once at its own station, under `ctx.frames` and `ctx.origin` (so the caller's own handlers stay out
34
+ * of that raise); its answer is the call's answer (a `{ deny }` is returned, not thrown) and its throw the caller's.
35
+ */
36
+ export type ModCallEntry = (args: ModEventPayload, ctx: ModBottomContext) => unknown;
37
+ export type ModCallEntries = Partial<Record<ModEventName, ModCallEntry>>;
31
38
  export type ModDispatchOutcome = {
32
39
  readonly kind: "answered";
33
40
  readonly answer: unknown;
@@ -39,8 +46,12 @@ export type ModDispatchOutcome = {
39
46
  readonly cause: ModFailureCause;
40
47
  readonly reason: string;
41
48
  readonly skipped: readonly ModSkip[];
42
- } | {
49
+ }
50
+ /** `bottomStarted`: the chain's bottom had started when the dispatch was cancelled — on an effect event, what it did is
51
+ * not known from here. */
52
+ | {
43
53
  readonly kind: "aborted";
54
+ readonly bottomStarted?: true;
44
55
  };
45
56
  /** What a participant filter sees of one mounted handler: its registration, that registration's seat, and whether it only observes. */
46
57
  export interface ModParticipant {
@@ -57,6 +68,9 @@ export interface ModDispatchOptions {
57
68
  readonly origin?: ModOrigin;
58
69
  /** The raiser's reading of an answer; an answer it refuses is a violation of the site. */
59
70
  readonly checkAnswer?: ModAnswerCheck;
71
+ /** The station's ranking of its answers — named by every dispatch of an event whose failure column refuses (one that
72
+ * names none is not run), and read by the seat-trust law. */
73
+ readonly ranks?: ModAnswerRanks;
60
74
  /** Which mounted handlers take part (absent ⇒ every handler on the event). A handler it leaves out neither runs nor observes. */
61
75
  readonly participant?: (p: ModParticipant) => boolean;
62
76
  }
@@ -76,12 +90,15 @@ export interface ModBus {
76
90
  mounted(): readonly ModMountedHandler[];
77
91
  /** Whether any mounted handler hangs on `event` (among those `participant` admits) — no handler, no dispatch (the station skips the call). */
78
92
  hasHandlers(event: ModEventName, participant?: (p: ModParticipant) => boolean): boolean;
79
- dispatch(event: ModEventName, e: ModEventPayload, options: ModDispatchOptions): Promise<ModDispatchOutcome>;
93
+ /** Raise `event` with the raiser's `e` (an object the bus receives whole, an event map's `e` as it is). */
94
+ dispatch(event: ModEventName, e: object, options: ModDispatchOptions): Promise<ModDispatchOutcome>;
80
95
  }
81
96
  export interface ModBusInput<D extends ModDollarBase = ModDollarBase> {
82
97
  readonly side: ModBusSide;
83
98
  readonly seats: ModSeats<D>;
84
99
  readonly bottoms: ModMethodBottoms;
100
+ /** The host's entries of the callable events its bus raises (absent ⇒ none: a `$` call of such an event throws). */
101
+ readonly entries?: ModCallEntries;
85
102
  /** Where handler failures go (the host's error channel). Never throws back into the bus. */
86
103
  readonly report: (err: Error, classification?: "observational-hook-verdict-ignored") => void;
87
104
  /** The host's one rule for turning a THROWN value into text (a handler, a `.catch` or a `register` may throw