@sema-agent/core 7.54.1 → 7.56.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 (621) hide show
  1. package/CHANGELOG.md +950 -0
  2. package/dist/agents/agent-transcript-tool.js +2 -1
  3. package/dist/agents/builtin-agents.d.ts +12 -14
  4. package/dist/agents/cascade.js +1 -1
  5. package/dist/agents/cc-peer-directory.d.ts +36 -0
  6. package/dist/agents/cc-peer-directory.js +139 -0
  7. package/dist/agents/cc-peer-wire.d.ts +105 -0
  8. package/dist/agents/cc-peer-wire.js +98 -0
  9. package/dist/agents/cc-uds-peer-channel.d.ts +40 -0
  10. package/dist/agents/cc-uds-peer-channel.js +457 -0
  11. package/dist/agents/child-model-seat.d.ts +0 -11
  12. package/dist/agents/child-model-seat.js +0 -3
  13. package/dist/agents/cross-session-envelope.d.ts +4 -1
  14. package/dist/agents/cross-session-envelope.js +8 -1
  15. package/dist/agents/cross-session-judge.d.ts +2 -2
  16. package/dist/agents/list-agents-tool.d.ts +3 -1
  17. package/dist/agents/list-agents-tool.js +9 -8
  18. package/dist/agents/observer.d.ts +4 -5
  19. package/dist/agents/observer.js +2 -1
  20. package/dist/agents/peer-admission.d.ts +6 -0
  21. package/dist/agents/peer-admission.js +4 -1
  22. package/dist/agents/peer-directory.d.ts +65 -13
  23. package/dist/agents/peer-directory.js +90 -25
  24. package/dist/agents/peer-notices.d.ts +1 -1
  25. package/dist/agents/peer-session-drain.d.ts +3 -1
  26. package/dist/agents/peer-session-drain.js +3 -2
  27. package/dist/agents/read-inbox-tool.js +2 -1
  28. package/dist/agents/repair-loop.js +2 -2
  29. package/dist/agents/retain-ledger.d.ts +1 -1
  30. package/dist/agents/roster-store.d.ts +1 -1
  31. package/dist/agents/send-message-tool.d.ts +10 -0
  32. package/dist/agents/send-message-tool.js +37 -8
  33. package/dist/agents/subagent.d.ts +39 -82
  34. package/dist/agents/subagent.js +109 -106
  35. package/dist/agents/tool-filter.d.ts +31 -46
  36. package/dist/agents/tool-filter.js +13 -33
  37. package/dist/agents/verify.d.ts +6 -5
  38. package/dist/agents/verify.js +3 -3
  39. package/dist/brain/anthropic.js +43 -81
  40. package/dist/brain/errors.d.ts +15 -0
  41. package/dist/brain/errors.js +10 -0
  42. package/dist/brain/media-degrade.d.ts +18 -7
  43. package/dist/brain/media-degrade.js +13 -2
  44. package/dist/brain/model-capability.d.ts +37 -0
  45. package/dist/brain/model-capability.js +34 -0
  46. package/dist/brain/model-presets.d.ts +6 -12
  47. package/dist/brain/model-presets.js +1 -6
  48. package/dist/brain/open-responses.js +27 -35
  49. package/dist/brain/openai.js +30 -98
  50. package/dist/brain/provider-dialect.d.ts +39 -3
  51. package/dist/brain/provider-dialect.js +28 -0
  52. package/dist/brain/reasoning-request.d.ts +96 -0
  53. package/dist/brain/reasoning-request.js +174 -0
  54. package/dist/brain/reasoning.d.ts +12 -12
  55. package/dist/brain/reasoning.js +4 -3
  56. package/dist/brain/request-params.d.ts +62 -9
  57. package/dist/brain/request-params.js +42 -7
  58. package/dist/brain/retry.d.ts +1 -1
  59. package/dist/brain/route-adjudicator.d.ts +15 -0
  60. package/dist/brain/route-adjudicator.js +15 -0
  61. package/dist/brain/status-sink.d.ts +20 -0
  62. package/dist/brain/status-sink.js +7 -0
  63. package/dist/brain/stream-engine.js +6 -5
  64. package/dist/brain/stream-shared.d.ts +1 -1
  65. package/dist/core/a2a.d.ts +2 -1
  66. package/dist/core/a2a.js +19 -13
  67. package/dist/core/advisor-verdict.d.ts +120 -0
  68. package/dist/core/advisor-verdict.js +92 -0
  69. package/dist/core/agent-definition.d.ts +17 -8
  70. package/dist/core/allow-entry.d.ts +69 -36
  71. package/dist/core/allow-entry.js +81 -52
  72. package/dist/core/allow-rule-shadow.d.ts +10 -3
  73. package/dist/core/approval-object.d.ts +2 -1
  74. package/dist/core/approval-object.js +6 -6
  75. package/dist/core/ask-origin.d.ts +127 -29
  76. package/dist/core/ask-origin.js +87 -25
  77. package/dist/core/ask-question.d.ts +51 -8
  78. package/dist/core/ask-question.js +12 -7
  79. package/dist/core/ask-unresolvable-notice.d.ts +8 -3
  80. package/dist/core/ask-unresolvable-notice.js +16 -2
  81. package/dist/core/auto-compaction.d.ts +11 -8
  82. package/dist/core/auto-compaction.js +4 -2
  83. package/dist/core/auto-mode-arming.d.ts +2 -2
  84. package/dist/core/auto-mode-defaults.d.ts +8 -8
  85. package/dist/core/auto-mode-prompt-assets.d.ts +3 -3
  86. package/dist/core/auto-mode-prompt.d.ts +1 -1
  87. package/dist/core/auto-mode.d.ts +17 -9
  88. package/dist/core/auto-mode.js +9 -6
  89. package/dist/core/background-agent-store.d.ts +3 -3
  90. package/dist/core/canonical-json.d.ts +1 -1
  91. package/dist/core/canonical-json.js +2 -2
  92. package/dist/core/checkpoint-generation.d.ts +53 -0
  93. package/dist/core/checkpoint-generation.js +35 -0
  94. package/dist/core/checkpoint-queries.d.ts +180 -0
  95. package/dist/core/checkpoint-queries.js +272 -0
  96. package/dist/core/checkpoint-requirements.d.ts +19 -4
  97. package/dist/core/checkpoint-requirements.js +8 -14
  98. package/dist/core/checkpoint-store.d.ts +165 -72
  99. package/dist/core/checkpoint-store.js +79 -82
  100. package/dist/core/child-clamp-seats.d.ts +6 -0
  101. package/dist/core/child-clamp-seats.js +3 -16
  102. package/dist/core/compliance.d.ts +2 -2
  103. package/dist/core/context-edit.d.ts +6 -7
  104. package/dist/core/cross-boundary-taint.d.ts +11 -4
  105. package/dist/core/cross-boundary-taint.js +3 -3
  106. package/dist/core/decision-receipt.d.ts +37 -3
  107. package/dist/core/decision-receipt.js +19 -19
  108. package/dist/core/delegation-not-started.d.ts +6 -0
  109. package/dist/core/delegation-not-started.js +17 -0
  110. package/dist/core/effective-path-target.d.ts +1 -1
  111. package/dist/core/engine-attestation.d.ts +93 -0
  112. package/dist/core/engine-attestation.js +70 -0
  113. package/dist/core/engine-capabilities.d.ts +4 -1
  114. package/dist/core/engine-capabilities.js +1 -1
  115. package/dist/core/engine-notice.d.ts +45 -12
  116. package/dist/core/exec-output-tail.d.ts +1 -1
  117. package/dist/core/file-history-retention.d.ts +1 -1
  118. package/dist/core/file-history-store.d.ts +147 -21
  119. package/dist/core/file-history-store.js +58 -32
  120. package/dist/core/gate-fold.d.ts +1 -1
  121. package/dist/core/gate-fold.js +24 -11
  122. package/dist/core/gate-lanes.js +81 -68
  123. package/dist/core/gate-outcome.d.ts +40 -6
  124. package/dist/core/gate-outcome.js +56 -0
  125. package/dist/core/governance-codes.d.ts +17 -3
  126. package/dist/core/governance-codes.js +16 -0
  127. package/dist/core/hands-band.d.ts +1 -1
  128. package/dist/core/hooks.d.ts +21 -20
  129. package/dist/core/hooks.js +3 -1
  130. package/dist/core/host-floor.d.ts +128 -0
  131. package/dist/core/host-floor.js +206 -0
  132. package/dist/core/host-target.d.ts +84 -0
  133. package/dist/core/host-target.js +92 -0
  134. package/dist/core/image-downsample.d.ts +1 -1
  135. package/dist/core/lsp-diagnostics.d.ts +4 -4
  136. package/dist/core/lsp.d.ts +3 -3
  137. package/dist/core/mailbox-store.d.ts +4 -0
  138. package/dist/core/mcp-connection-pool.d.ts +18 -2
  139. package/dist/core/mcp-connection-pool.js +53 -6
  140. package/dist/core/mcp-failure.d.ts +23 -4
  141. package/dist/core/mcp-failure.js +26 -11
  142. package/dist/core/mcp-listing-drift.d.ts +10 -0
  143. package/dist/core/mcp-listing-drift.js +6 -0
  144. package/dist/core/mcp-server-link.d.ts +173 -0
  145. package/dist/core/mcp-server-link.js +127 -0
  146. package/dist/core/mcp-server-spec.d.ts +4 -2
  147. package/dist/core/mcp-session-end.d.ts +26 -0
  148. package/dist/core/mcp-session-end.js +29 -0
  149. package/dist/core/mcp-startup-request.d.ts +17 -0
  150. package/dist/core/mcp-startup-request.js +17 -0
  151. package/dist/core/mcp.d.ts +17 -13
  152. package/dist/core/mcp.js +240 -189
  153. package/dist/core/media-byte-cap.d.ts +1 -1
  154. package/dist/core/memory-engine/delegation-settlement.js +15 -24
  155. package/dist/core/memory-engine/engine.d.ts +9 -9
  156. package/dist/core/memory-engine/engine.js +4 -4
  157. package/dist/core/memory-engine/layout.d.ts +60 -8
  158. package/dist/core/memory-engine/layout.js +65 -6
  159. package/dist/core/memory-engine/provenance-wording.d.ts +1 -1
  160. package/dist/core/memory-engine/tools.js +4 -1
  161. package/dist/core/mode-policy.d.ts +1 -1
  162. package/dist/core/model-seat.d.ts +10 -3
  163. package/dist/core/mods/classic-events.d.ts +67 -0
  164. package/dist/core/mods/classic-events.js +1 -0
  165. package/dist/core/mods/dollar.d.ts +13 -0
  166. package/dist/core/mods/extension-call.d.ts +31 -0
  167. package/dist/core/mods/extension-call.js +43 -0
  168. package/dist/core/mods/kernel/dispatch.d.ts +20 -3
  169. package/dist/core/mods/kernel/dispatch.js +140 -69
  170. package/dist/core/mods/kernel/events.d.ts +47 -11
  171. package/dist/core/mods/kernel/events.js +66 -42
  172. package/dist/core/mods/kernel/index.d.ts +4 -4
  173. package/dist/core/mods/kernel/index.js +2 -2
  174. package/dist/core/mods/kernel/receive.d.ts +39 -5
  175. package/dist/core/mods/kernel/receive.js +290 -17
  176. package/dist/core/mods/kernel/registration.d.ts +33 -2
  177. package/dist/core/mods/kernel/registration.js +6 -7
  178. package/dist/core/mods/kernel/site-rules.d.ts +44 -16
  179. package/dist/core/mods/kernel/site-rules.js +24 -42
  180. package/dist/core/mods/spec-seats.d.ts +69 -0
  181. package/dist/core/mods/spec-seats.js +114 -0
  182. package/dist/core/mods/stations.d.ts +28 -8
  183. package/dist/core/mods/stations.js +29 -13
  184. package/dist/core/mods/tool-call.d.ts +79 -0
  185. package/dist/core/mods/tool-call.js +152 -0
  186. package/dist/core/namespaced-rule-name.d.ts +44 -24
  187. package/dist/core/namespaced-rule-name.js +50 -43
  188. package/dist/core/output-style.d.ts +1 -1
  189. package/dist/core/param-rule-reach.d.ts +15 -0
  190. package/dist/core/param-rule-reach.js +30 -0
  191. package/dist/core/parent-spec-seat.d.ts +13 -1
  192. package/dist/core/parent-spec-seat.js +6 -0
  193. package/dist/core/park-selfcheck.js +1 -0
  194. package/dist/core/pause-registry.d.ts +16 -5
  195. package/dist/core/pause-registry.js +6 -2
  196. package/dist/core/peer-channel.d.ts +70 -0
  197. package/dist/core/peer-channel.js +1 -0
  198. package/dist/core/permission-rule-consent.d.ts +30 -5
  199. package/dist/core/permission-rule-consent.js +147 -50
  200. package/dist/core/permission-rule-model.d.ts +245 -65
  201. package/dist/core/permission-rule-model.js +421 -107
  202. package/dist/core/permission-rule-org.d.ts +6 -2
  203. package/dist/core/permission-rule-org.js +7 -3
  204. package/dist/core/permission-rule-provider.d.ts +6 -2
  205. package/dist/core/permission-rule-provider.js +41 -11
  206. package/dist/core/permission-rule-store.d.ts +22 -26
  207. package/dist/core/permission-rule-store.js +12 -6
  208. package/dist/core/permission-rule-sync.d.ts +11 -2
  209. package/dist/core/permission-rule-sync.js +11 -3
  210. package/dist/core/permission-rule-syntax.d.ts +5 -4
  211. package/dist/core/permission-rule-syntax.js +2 -2
  212. package/dist/core/permission-rules.d.ts +53 -15
  213. package/dist/core/permission-rules.js +125 -100
  214. package/dist/core/persisted-rule-arms.d.ts +6 -4
  215. package/dist/core/persisted-rule-arms.js +10 -12
  216. package/dist/core/present-plan-tool.js +3 -1
  217. package/dist/core/principal-name.d.ts +20 -0
  218. package/dist/core/principal-name.js +22 -0
  219. package/dist/core/prompt-section-seat.js +4 -6
  220. package/dist/core/protocol-http-auth.d.ts +26 -5
  221. package/dist/core/protocol-http-auth.js +137 -4
  222. package/dist/core/protocol-naming.d.ts +2 -2
  223. package/dist/core/read-only-shell-table.d.ts +1 -1
  224. package/dist/core/read-only-shell.d.ts +1 -1
  225. package/dist/core/retired-keys.d.ts +16 -0
  226. package/dist/core/retired-keys.js +16 -4
  227. package/dist/core/rewrite-rejudge.d.ts +60 -0
  228. package/dist/core/rewrite-rejudge.js +36 -0
  229. package/dist/core/roles.d.ts +34 -3
  230. package/dist/core/roles.js +66 -53
  231. package/dist/core/rule-lane-reads.d.ts +20 -15
  232. package/dist/core/rule-lane-reads.js +45 -17
  233. package/dist/core/rule-offer-read.d.ts +53 -0
  234. package/dist/core/rule-offer-read.js +146 -0
  235. package/dist/core/rule-owner.d.ts +46 -0
  236. package/dist/core/rule-owner.js +29 -0
  237. package/dist/core/runner/advisor-instructions.d.ts +70 -0
  238. package/dist/core/runner/advisor-instructions.js +61 -0
  239. package/dist/core/runner/advisor-tool.d.ts +33 -0
  240. package/dist/core/runner/advisor-tool.js +112 -0
  241. package/dist/core/runner/announce-once-ledger.d.ts +18 -26
  242. package/dist/core/runner/announce-once-ledger.js +19 -46
  243. package/dist/core/runner/approval-feedback.js +6 -3
  244. package/dist/core/runner/assemble-result.d.ts +2 -1
  245. package/dist/core/runner/assemble-result.js +1 -1
  246. package/dist/core/runner/call-hook-stations.d.ts +3 -2
  247. package/dist/core/runner/caller-roster.d.ts +21 -2
  248. package/dist/core/runner/caller-roster.js +38 -0
  249. package/dist/core/runner/capability-withheld-seat.d.ts +5 -0
  250. package/dist/core/runner/capability-withheld-seat.js +24 -0
  251. package/dist/core/runner/classifier-ladder.d.ts +33 -13
  252. package/dist/core/runner/classifier-ladder.js +15 -14
  253. package/dist/core/runner/compaction-restate.d.ts +10 -6
  254. package/dist/core/runner/compaction-restate.js +9 -3
  255. package/dist/core/runner/construction-doors.js +3 -0
  256. package/dist/core/runner/contracts.d.ts +40 -33
  257. package/dist/core/runner/conversation-segment.d.ts +28 -0
  258. package/dist/core/runner/conversation-segment.js +42 -0
  259. package/dist/core/runner/cross-boundary-lane.d.ts +21 -16
  260. package/dist/core/runner/cross-boundary-lane.js +58 -34
  261. package/dist/core/runner/decide-continuation.d.ts +7 -4
  262. package/dist/core/runner/decide-continuation.js +2 -2
  263. package/dist/core/runner/denial-limit-arms.d.ts +4 -4
  264. package/dist/core/runner/denial-limit-arms.js +1 -1
  265. package/dist/core/runner/derived-route-fallback.d.ts +24 -24
  266. package/dist/core/runner/derived-route-fallback.js +9 -7
  267. package/dist/core/runner/file-history-request.d.ts +18 -0
  268. package/dist/core/runner/file-history-request.js +21 -13
  269. package/dist/core/runner/file-history-restore.d.ts +45 -0
  270. package/dist/core/runner/file-history-restore.js +46 -0
  271. package/dist/core/runner/gate-exit.d.ts +9 -3
  272. package/dist/core/runner/gate-exit.js +11 -5
  273. package/dist/core/runner/image.d.ts +7 -17
  274. package/dist/core/runner/image.js +9 -60
  275. package/dist/core/runner/initial-run-state.js +1 -1
  276. package/dist/core/runner/permission-rule-lanes.d.ts +6 -6
  277. package/dist/core/runner/permission-rule-lanes.js +38 -15
  278. package/dist/core/runner/person-path-rows.d.ts +12 -9
  279. package/dist/core/runner/person-path-rows.js +19 -8
  280. package/dist/core/runner/prepare-advisor.d.ts +63 -0
  281. package/dist/core/runner/prepare-advisor.js +77 -0
  282. package/dist/core/runner/prepare-ask-lane.d.ts +2 -2
  283. package/dist/core/runner/prepare-ask-lane.js +5 -2
  284. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -6
  285. package/dist/core/runner/prepare-caps-and-workflow.js +5 -4
  286. package/dist/core/runner/prepare-config-doors.d.ts +31 -38
  287. package/dist/core/runner/prepare-config-doors.js +57 -34
  288. package/dist/core/runner/prepare-defer-classify.d.ts +4 -3
  289. package/dist/core/runner/prepare-defer-classify.js +7 -8
  290. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
  291. package/dist/core/runner/prepare-delegation-surface.js +1 -1
  292. package/dist/core/runner/prepare-file-history.d.ts +48 -8
  293. package/dist/core/runner/prepare-file-history.js +41 -73
  294. package/dist/core/runner/prepare-gate-stations.d.ts +2 -5
  295. package/dist/core/runner/prepare-gate-stations.js +12 -8
  296. package/dist/core/runner/prepare-hands-readface.d.ts +2 -8
  297. package/dist/core/runner/prepare-hands-readface.js +15 -14
  298. package/dist/core/runner/prepare-inherited-gate.d.ts +11 -7
  299. package/dist/core/runner/prepare-inherited-gate.js +8 -6
  300. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  301. package/dist/core/runner/prepare-park-ask.js +12 -12
  302. package/dist/core/runner/prepare-policy-chain.d.ts +7 -4
  303. package/dist/core/runner/prepare-policy-chain.js +68 -81
  304. package/dist/core/runner/prepare-project-context.d.ts +5 -2
  305. package/dist/core/runner/prepare-project-context.js +6 -3
  306. package/dist/core/runner/prepare-prompt-assembly.d.ts +5 -7
  307. package/dist/core/runner/prepare-prompt-assembly.js +10 -8
  308. package/dist/core/runner/prepare-prompt-inputs.d.ts +11 -9
  309. package/dist/core/runner/prepare-prompt-inputs.js +4 -6
  310. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
  311. package/dist/core/runner/prepare-protocol-tools.js +5 -4
  312. package/dist/core/runner/prepare-safety-scan.d.ts +9 -12
  313. package/dist/core/runner/prepare-safety-scan.js +8 -23
  314. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  315. package/dist/core/runner/prepare-suspend-saga.js +5 -6
  316. package/dist/core/runner/prepare-task.d.ts +1 -1
  317. package/dist/core/runner/prepare-task.js +41 -35
  318. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +7 -4
  319. package/dist/core/runner/prepare-tool-disclosure-mount.js +24 -18
  320. package/dist/core/runner/prepare-turn-wiring.d.ts +0 -4
  321. package/dist/core/runner/prepare-turn-wiring.js +2 -7
  322. package/dist/core/runner/prepare-wiring-manifest.d.ts +11 -4
  323. package/dist/core/runner/prepare-wiring-manifest.js +3 -3
  324. package/dist/core/runner/resume-admission.js +1 -1
  325. package/dist/core/runner/resume-apply.js +11 -12
  326. package/dist/core/runner/resume-checkpoint-screen.js +3 -0
  327. package/dist/core/runner/resume-claim.d.ts +4 -2
  328. package/dist/core/runner/resume-claim.js +15 -8
  329. package/dist/core/runner/resume-policy-outcome.js +1 -1
  330. package/dist/core/runner/retired-runner-deps.js +2 -1
  331. package/dist/core/runner/rewind-files.d.ts +15 -0
  332. package/dist/core/runner/rewind-files.js +132 -0
  333. package/dist/core/runner/run-attachment-seats.js +2 -2
  334. package/dist/core/runner/run-brain-sinks.d.ts +4 -1
  335. package/dist/core/runner/run-brain-sinks.js +4 -2
  336. package/dist/core/runner/run-compaction-machinery.d.ts +1 -1
  337. package/dist/core/runner/run-compaction-machinery.js +2 -12
  338. package/dist/core/runner/run-git-lane.d.ts +1 -0
  339. package/dist/core/runner/run-harness-handlers.js +14 -7
  340. package/dist/core/runner/run-leg.d.ts +1 -1
  341. package/dist/core/runner/run-leg.js +43 -18
  342. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  343. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  344. package/dist/core/runner/run-turn-boundary.d.ts +1 -0
  345. package/dist/core/runner/run-turn-boundary.js +15 -22
  346. package/dist/core/runner/runtask.d.ts +3 -0
  347. package/dist/core/runner/runtask.js +8 -9
  348. package/dist/core/runner/session-read-file-states.d.ts +15 -0
  349. package/dist/core/runner/session-read-file-states.js +28 -0
  350. package/dist/core/runner/session-rule-policy.d.ts +22 -21
  351. package/dist/core/runner/session-rule-policy.js +17 -31
  352. package/dist/core/runner/shell-env-withheld.d.ts +33 -0
  353. package/dist/core/runner/shell-env-withheld.js +51 -0
  354. package/dist/core/runner/side-call-account.d.ts +32 -8
  355. package/dist/core/runner/side-call-account.js +23 -1
  356. package/dist/core/runner/skills-seat.js +6 -2
  357. package/dist/core/runner/stream-settle-backstop.js +1 -1
  358. package/dist/core/runner/strict-output-schema.d.ts +1 -1
  359. package/dist/core/runner/sub-agent-deny-lists.js +4 -6
  360. package/dist/core/runner/synthetic-tools.d.ts +16 -13
  361. package/dist/core/runner/synthetic-tools.js +8 -3
  362. package/dist/core/runner/tool-disclosure.d.ts +10 -12
  363. package/dist/core/runner/tool-disclosure.js +3 -4
  364. package/dist/core/runner/tool-end-body.d.ts +1 -1
  365. package/dist/core/runner/tool-end-body.js +10 -9
  366. package/dist/core/runner/tool-face-overlay.d.ts +2 -1
  367. package/dist/core/runner/tool-face-overlay.js +17 -1
  368. package/dist/core/runner/tool-not-executed.d.ts +5 -0
  369. package/dist/core/runner/tool-not-executed.js +11 -0
  370. package/dist/core/runner/tool-occurrence.d.ts +8 -0
  371. package/dist/core/runner/tool-occurrence.js +7 -0
  372. package/dist/core/runner/tool-progress-lane.d.ts +2 -2
  373. package/dist/core/runner/tool-turn-repair-seat.d.ts +3 -2
  374. package/dist/core/runner/turn-attachments.d.ts +91 -80
  375. package/dist/core/runner/turn-attachments.js +62 -37
  376. package/dist/core/runner-deps.d.ts +42 -42
  377. package/dist/core/runtime-caps.d.ts +4 -4
  378. package/dist/core/safety-axis-vocab.d.ts +6 -4
  379. package/dist/core/safety-axis-vocab.js +6 -5
  380. package/dist/core/safety-merge-corpus.js +26 -2
  381. package/dist/core/same-plain-value.d.ts +40 -0
  382. package/dist/core/same-plain-value.js +49 -0
  383. package/dist/core/scheduler.d.ts +1 -1
  384. package/dist/core/secret-env.d.ts +26 -3
  385. package/dist/core/secret-env.js +44 -8
  386. package/dist/core/select-model.js +3 -3
  387. package/dist/core/sensitive-path-policy.d.ts +1 -1
  388. package/dist/core/sensitive-path-policy.js +1 -1
  389. package/dist/core/session-policy-store.d.ts +102 -35
  390. package/dist/core/session-policy-store.js +210 -48
  391. package/dist/core/session-reconcile.d.ts +2 -2
  392. package/dist/core/session-store.d.ts +106 -37
  393. package/dist/core/session-store.js +165 -91
  394. package/dist/core/session.d.ts +101 -57
  395. package/dist/core/session.js +53 -0
  396. package/dist/core/shared-memory/tools.js +3 -1
  397. package/dist/core/shared-memory/types.d.ts +1 -1
  398. package/dist/core/shell-read-silence.d.ts +11 -12
  399. package/dist/core/shell-read-silence.js +9 -5
  400. package/dist/core/shell-run-candidates.js +3 -1
  401. package/dist/core/shell-wrapper-projection.js +1 -1
  402. package/dist/core/shell-wrapper-table.d.ts +14 -7
  403. package/dist/core/shell-wrapper-table.js +5 -4
  404. package/dist/core/side-query.d.ts +10 -0
  405. package/dist/core/side-query.js +15 -1
  406. package/dist/core/skill-grant.d.ts +7 -2
  407. package/dist/core/skill-grant.js +5 -0
  408. package/dist/core/skills-directory.js +6 -2
  409. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +11 -1
  410. package/dist/core/store-contracts/checkpoint-store-contract.js +168 -3
  411. package/dist/core/store-contracts/file-history-store-contract.js +74 -4
  412. package/dist/core/store-contracts/peer-directory-contract.d.ts +7 -2
  413. package/dist/core/store-contracts/peer-directory-contract.js +14 -2
  414. package/dist/core/store-contracts/session-policy-store-contract.d.ts +7 -0
  415. package/dist/core/store-contracts/session-policy-store-contract.js +130 -0
  416. package/dist/core/store-contracts/session-repo-contract.js +176 -0
  417. package/dist/core/store-contracts/session-store-contract.d.ts +6 -8
  418. package/dist/core/store-contracts/session-store-contract.js +361 -51
  419. package/dist/core/store-contracts/workflow-journal-store-contract.js +26 -1
  420. package/dist/core/stub-env.d.ts +2 -0
  421. package/dist/core/stub-env.js +1 -0
  422. package/dist/core/surrogate-safe-slice.d.ts +3 -3
  423. package/dist/core/synthetic-read-verdict.js +3 -3
  424. package/dist/core/task-event.d.ts +42 -8
  425. package/dist/core/task-notification.d.ts +19 -15
  426. package/dist/core/task-registry-agent.d.ts +4 -4
  427. package/dist/core/task-registry-shared.d.ts +4 -4
  428. package/dist/core/task-registry-shared.js +1 -0
  429. package/dist/core/task-registry.d.ts +13 -4
  430. package/dist/core/task-registry.js +14 -2
  431. package/dist/core/task-result.d.ts +21 -3
  432. package/dist/core/task-spec.d.ts +69 -64
  433. package/dist/core/task-stream.d.ts +6 -6
  434. package/dist/core/task-tool-shape.d.ts +4 -4
  435. package/dist/core/tighten-task-spec.d.ts +1 -1
  436. package/dist/core/tighten-task-spec.js +2 -1
  437. package/dist/core/tool-catalog-entries.d.ts +36 -2
  438. package/dist/core/tool-catalog-entries.js +69 -43
  439. package/dist/core/tool-check-reading.d.ts +11 -0
  440. package/dist/core/tool-check-reading.js +11 -6
  441. package/dist/core/tool-conformance.js +1 -0
  442. package/dist/core/tool-errors.d.ts +2 -2
  443. package/dist/core/tool-face-reader.js +5 -3
  444. package/dist/core/tool-face.d.ts +21 -2
  445. package/dist/core/tool-face.js +1 -1
  446. package/dist/core/tool-model-gate.d.ts +5 -5
  447. package/dist/core/tool-name-aliases.d.ts +29 -8
  448. package/dist/core/tool-name-aliases.js +22 -4
  449. package/dist/core/tool-name-readings.d.ts +10 -43
  450. package/dist/core/tool-name-readings.js +2 -11
  451. package/dist/core/tool-policy.d.ts +85 -196
  452. package/dist/core/tool-policy.js +150 -175
  453. package/dist/core/tool-registry.d.ts +14 -7
  454. package/dist/core/tool-registry.js +17 -7
  455. package/dist/core/tool-result-store.js +5 -1
  456. package/dist/core/tool-roster.d.ts +57 -33
  457. package/dist/core/tool-roster.js +56 -68
  458. package/dist/core/tool-spec-members.js +8 -3
  459. package/dist/core/tool-spec.d.ts +53 -31
  460. package/dist/core/tools.js +51 -10
  461. package/dist/core/trace.d.ts +6 -2
  462. package/dist/core/types.d.ts +1 -1
  463. package/dist/core/untrusted-egress.d.ts +1 -1
  464. package/dist/core/untrusted-text.d.ts +1 -1
  465. package/dist/core/user-attachment.d.ts +8 -1
  466. package/dist/core/user-attachment.js +64 -4
  467. package/dist/core/warm-resume.d.ts +1 -1
  468. package/dist/core/wiring-manifest.d.ts +58 -0
  469. package/dist/core/wiring-manifest.js +14 -5
  470. package/dist/core/workflow-journal-store.d.ts +62 -0
  471. package/dist/core/workflow-journal-store.js +78 -2
  472. package/dist/core/workflow-run-store.d.ts +6 -0
  473. package/dist/core/workflow-run-store.js +2 -0
  474. package/dist/engine/compaction/compaction.d.ts +9 -9
  475. package/dist/engine/compaction/compaction.js +3 -2
  476. package/dist/engine/execution-env/node-execution-env.d.ts +26 -8
  477. package/dist/engine/execution-env/node-execution-env.js +54 -24
  478. package/dist/engine/harness/agent-harness.d.ts +39 -9
  479. package/dist/engine/harness/agent-harness.js +87 -33
  480. package/dist/engine/harness/types.d.ts +58 -9
  481. package/dist/engine/harness/types.js +12 -1
  482. package/dist/engine/llm/types.d.ts +36 -19
  483. package/dist/engine/llm/validation.d.ts +4 -1
  484. package/dist/engine/llm/validation.js +13 -1
  485. package/dist/engine/loop/agent-loop.d.ts +23 -1
  486. package/dist/engine/loop/agent-loop.js +26 -34
  487. package/dist/engine/loop/types.d.ts +31 -19
  488. package/dist/engine/lsp/node-lsp-manager.d.ts +2 -2
  489. package/dist/engine/session/memory-repo.d.ts +18 -12
  490. package/dist/engine/session/memory-repo.js +24 -9
  491. package/dist/engine/session/parent-chain-guard.d.ts +3 -2
  492. package/dist/engine/session/parent-chain-guard.js +1 -1
  493. package/dist/engine/session/repo-utils.d.ts +32 -3
  494. package/dist/engine/session/repo-utils.js +50 -5
  495. package/dist/index.d.ts +47 -23
  496. package/dist/index.js +35 -17
  497. package/dist/internal/harness-types.d.ts +1 -1
  498. package/dist/internal/harness.d.ts +3 -3
  499. package/dist/internal/harness.js +2 -2
  500. package/dist/internal/llm.d.ts +2 -2
  501. package/dist/internal/llm.js +1 -1
  502. package/dist/orchestration/goal.js +2 -2
  503. package/dist/orchestration/run-workflow-tool.d.ts +8 -6
  504. package/dist/orchestration/run-workflow-tool.js +10 -6
  505. package/dist/orchestration/workflow-size-guideline.d.ts +4 -4
  506. package/dist/orchestration/workflow-types.d.ts +18 -0
  507. package/dist/orchestration/workflow-types.js +6 -0
  508. package/dist/orchestration/workflow.d.ts +5 -13
  509. package/dist/orchestration/workflow.js +57 -49
  510. package/dist/prompt-assembly/artifact.d.ts +2 -2
  511. package/dist/prompt-assembly/artifact.js +5 -3
  512. package/dist/prompt-assembly/assemble.d.ts +3 -2
  513. package/dist/prompt-assembly/assemble.js +1 -1
  514. package/dist/prompt-assembly/catalog/schema.d.ts +43 -12
  515. package/dist/prompt-assembly/catalog/schema.js +34 -2
  516. package/dist/prompt-assembly/catalog/sections.js +0 -1
  517. package/dist/prompt-assembly/composer.d.ts +3 -1
  518. package/dist/prompt-assembly/composer.js +1 -1
  519. package/dist/prompt-assembly/event-registry.js +2 -0
  520. package/dist/prompt-assembly/overlay.js +3 -3
  521. package/dist/prompt-assembly/renderers.d.ts +1 -1
  522. package/dist/prompt-assembly/renderers.js +0 -3
  523. package/dist/prompt-assembly/role-base.d.ts +15 -0
  524. package/dist/prompt-assembly/role-base.js +9 -0
  525. package/dist/prompt-assembly/select.d.ts +39 -14
  526. package/dist/prompt-assembly/select.js +47 -16
  527. package/dist/prompt-assembly/sugar.d.ts +17 -11
  528. package/dist/prompt-assembly/sugar.js +8 -3
  529. package/dist/prompt-assembly/tool-catalog.d.ts +39 -2
  530. package/dist/prompt-assembly/tool-catalog.js +117 -4
  531. package/dist/prompt-assembly/turn-snapshot.d.ts +4 -10
  532. package/dist/prompt-assembly/turn-snapshot.js +0 -3
  533. package/dist/prompt-assembly/types.d.ts +0 -7
  534. package/dist/prompts/default.d.ts +14 -14
  535. package/dist/scenarios/full-body.d.ts +15 -15
  536. package/dist/scenarios/full-body.js +4 -3
  537. package/dist/shell/lex.js +10 -1
  538. package/dist/stores/file/adoption/adopt.d.ts +4 -3
  539. package/dist/stores/file/adoption/adopt.js +27 -33
  540. package/dist/stores/file/adoption/marker.d.ts +6 -13
  541. package/dist/stores/file/adoption/marker.js +9 -17
  542. package/dist/stores/file/checkpoint-store.d.ts +24 -0
  543. package/dist/stores/file/checkpoint-store.js +45 -7
  544. package/dist/stores/file/file-history-store.d.ts +20 -19
  545. package/dist/stores/file/file-history-store.js +157 -141
  546. package/dist/stores/file/fs-atomic.d.ts +15 -0
  547. package/dist/stores/file/fs-atomic.js +89 -14
  548. package/dist/stores/file/index.d.ts +1 -1
  549. package/dist/stores/file/index.js +2 -1
  550. package/dist/stores/file/mailbox-store.d.ts +3 -0
  551. package/dist/stores/file/mailbox-store.js +3 -1
  552. package/dist/stores/file/permission-rule-adopt.d.ts +1 -1
  553. package/dist/stores/file/permission-rule-adopt.js +18 -18
  554. package/dist/stores/file/permission-rule-store.d.ts +18 -2
  555. package/dist/stores/file/permission-rule-store.js +31 -18
  556. package/dist/stores/file/session-policy-store.d.ts +3 -3
  557. package/dist/stores/file/session-store.d.ts +54 -16
  558. package/dist/stores/file/session-store.js +114 -85
  559. package/dist/stores/file/workflow-journal-store.d.ts +10 -4
  560. package/dist/stores/file/workflow-journal-store.js +28 -13
  561. package/dist/tools/artifact/artifact-text.d.ts +1 -1
  562. package/dist/tools/artifact/artifact-tool.js +5 -3
  563. package/dist/tools/fs/bash-program-position.d.ts +19 -2
  564. package/dist/tools/fs/bash-program-position.js +56 -9
  565. package/dist/tools/fs/bash-readonly-classifier.d.ts +3 -3
  566. package/dist/tools/fs/fs-bash.d.ts +2 -2
  567. package/dist/tools/fs/fs-bash.js +8 -6
  568. package/dist/tools/fs/fs-glob.d.ts +86 -0
  569. package/dist/tools/fs/fs-glob.js +226 -0
  570. package/dist/tools/fs/fs-read.js +14 -14
  571. package/dist/tools/fs/fs-search-tools.js +7 -7
  572. package/dist/tools/fs/fs-shared.d.ts +8 -8
  573. package/dist/tools/fs/gh-rate-limit.d.ts +1 -1
  574. package/dist/tools/fs/notebook.d.ts +2 -2
  575. package/dist/tools/fs/pattern-kill-guard.d.ts +22 -0
  576. package/dist/tools/fs/pattern-kill-guard.js +397 -0
  577. package/dist/tools/fs/pdf.d.ts +9 -6
  578. package/dist/tools/fs/pdf.js +3 -3
  579. package/dist/tools/fs/program-read-model.d.ts +57 -7
  580. package/dist/tools/fs/program-read-model.js +11 -1
  581. package/dist/tools/fs/program-read-model.rows.js +78 -21
  582. package/dist/tools/fs/read-deny-home.js +3 -2
  583. package/dist/tools/fs/read-deny.d.ts +29 -7
  584. package/dist/tools/fs/read-deny.js +63 -22
  585. package/dist/tools/fs/removal-targets.d.ts +18 -8
  586. package/dist/tools/fs/removal-targets.js +47 -20
  587. package/dist/tools/fs/safety.d.ts +9 -9
  588. package/dist/tools/fs/search.d.ts +16 -6
  589. package/dist/tools/fs/search.js +20 -26
  590. package/dist/tools/fs/shell-read-argv.js +89 -12
  591. package/dist/tools/fs/shell-read-bindings.d.ts +31 -0
  592. package/dist/tools/fs/shell-read-bindings.js +41 -0
  593. package/dist/tools/fs/shell-read-check.js +12 -20
  594. package/dist/tools/fs/shell-read-environment.d.ts +5 -1
  595. package/dist/tools/fs/shell-read-environment.js +3 -2
  596. package/dist/tools/fs/shell-read-establish.d.ts +15 -0
  597. package/dist/tools/fs/shell-read-establish.js +19 -20
  598. package/dist/tools/fs/shell-read-judge.d.ts +4 -0
  599. package/dist/tools/fs/shell-read-judge.js +5 -2
  600. package/dist/tools/fs/shell-read-plan.js +24 -16
  601. package/dist/tools/fs/shell-read-start.d.ts +6 -1
  602. package/dist/tools/fs/shell-read-write-targets.d.ts +5 -1
  603. package/dist/tools/fs/shell-read-write-targets.js +2 -3
  604. package/dist/tools/fs/shell-reentry-text.d.ts +9 -0
  605. package/dist/tools/fs/shell-reentry-text.js +40 -2
  606. package/dist/tools/loop-tick.d.ts +2 -2
  607. package/dist/tools/scheduler-tools.js +5 -1
  608. package/dist/tools/task-list.d.ts +7 -7
  609. package/dist/tools/task-list.js +5 -1
  610. package/dist/tools/todo.js +65 -64
  611. package/dist/tools/web.d.ts +20 -15
  612. package/dist/tools/web.js +55 -69
  613. package/dist/tools/worktree.d.ts +3 -3
  614. package/dist/tools/worktree.js +3 -1
  615. package/package.json +1 -1
  616. package/test/export-surface.snapshot.json +5894 -5638
  617. package/wire-changes/core@7.55.0.json +3318 -0
  618. package/wire-changes/core@7.56.0.json +3891 -0
  619. package/wire-changes/mods-kernel@7.56.0.json +303 -0
  620. package/dist/core/store-contracts/session-store-incarnation-contract.d.ts +0 -39
  621. package/dist/core/store-contracts/session-store-incarnation-contract.js +0 -95
@@ -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
@@ -1,7 +1,7 @@
1
1
  import { CATCH_BUDGET_MS, createSelfBudget, POST_ABORT_GRACE_MS, RUNAWAY_AFTER_MS, unrefTimer, watchRunaway } from "./budget.js";
2
- import { expandModPattern, isModEventName, MOD_SEATS, nextToRefusal, stationOn } from "./events.js";
2
+ import { expandOnSide, failureRefuses, isModEventName, MOD_SEATS, nextToRefusal, stationOn } from "./events.js";
3
3
  import { ENGINE_ORIGIN, modsInvalid, screenModSeats, } from "./registration.js";
4
- import { answerUpward, answerViolation, detachedCopy, engineObjectsOnce, handedOn, matcherMatches, matcherViolation, methodAnswerViolation, NEXT_IN_FLIGHT, receiveAnswer, receiveEvent, receivePayload, } from "./site-rules.js";
4
+ import { answerUpward, answerViolation, detachedCopy, engineObjectsOnce, handedOn, matcherMatches, matcherViolation, methodAnswerViolation, NEXT_IN_FLIGHT, receiveAnswer, receiveEvent, receivePayload, sealedObjects, } from "./site-rules.js";
5
5
  const TIER_RANK = { prepend: 0, user: 1, append: 2, builtin: 3, core: 4 };
6
6
  const bypassed = (floors, tier) => floors.some((f) => TIER_RANK[f.from] < TIER_RANK[tier] && TIER_RANK[tier] < TIER_RANK[f.to]);
7
7
  export async function admitMods(input) {
@@ -10,7 +10,7 @@ export async function admitMods(input) {
10
10
  const mounted = [];
11
11
  const records = [];
12
12
  const describe = safeDescribe(input.describeThrown);
13
- const bus = createBus(input.side, mounted, input.bottoms, report, records, describe, input.isProxy);
13
+ const bus = createBus(input.side, mounted, input.bottoms, input.entries ?? {}, report, records, describe, input.isProxy);
14
14
  const admitted = Object.freeze({ admitted: true });
15
15
  for (const cand of screened) {
16
16
  if (input.signal?.aborted === true)
@@ -24,14 +24,10 @@ export async function admitMods(input) {
24
24
  });
25
25
  const outcome = await bus.dispatch("plugin.register", e, {
26
26
  bottom: () => admitted,
27
+ ranks: ADMISSION_RANKS,
27
28
  ...(input.signal !== undefined ? { signal: input.signal } : {}),
28
- checkAnswer: (a, judged, by) => a === admitted
29
- ? undefined
30
- : refusalOf(a) === undefined
31
- ? "takes next(e) or { refuse: <reason> }"
32
- : MOD_SEATS.indexOf(by.seat) > MOD_SEATS.findIndex((s) => s === judged["seat"])
33
- ? `a ${by.seat} registration may not refuse a ${String(judged["seat"])} registration`
34
- : undefined,
29
+ participant: (p) => MOD_SEATS.indexOf(p.seat) <= MOD_SEATS.indexOf(cand.seat),
30
+ checkAnswer: (a) => (a === admitted || refusalOf(a) !== undefined ? undefined : "takes next(e) or { refuse: <reason> }"),
35
31
  });
36
32
  if (outcome.kind === "aborted")
37
33
  throw input.signal?.reason ?? new Error("admission aborted");
@@ -59,6 +55,7 @@ export async function admitMods(input) {
59
55
  }
60
56
  return bus;
61
57
  }
58
+ const ADMISSION_RANKS = Object.freeze({ of: (a) => (refusalOf(a) !== undefined ? 1 : 0), top: 1 });
62
59
  function refusalOf(a) {
63
60
  if (typeof a !== "object" || a === null || !Object.prototype.hasOwnProperty.call(a, "refuse"))
64
61
  return undefined;
@@ -113,7 +110,7 @@ function mountOne(cand, side, describe) {
113
110
  const parsed = handlerOptions(opts);
114
111
  if (typeof parsed === "string")
115
112
  fail(`on("${String(pattern)}"): ${parsed}`);
116
- const expanded = expandModPattern(pattern);
113
+ const expanded = expandOnSide(pattern, side);
117
114
  if ("refusal" in expanded)
118
115
  return void fail(`on(): ${expanded.refusal}`);
119
116
  const outside = expanded.names.filter((n) => !cand.eventsBound.has(n));
@@ -178,16 +175,23 @@ function handlerOptions(opts) {
178
175
  }
179
176
  const HA = "skipped; what is below it ran in its place";
180
177
  const MA = "skipped; its last next() run's result stands";
181
- function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
182
- const methods = [];
178
+ function createBus(side, mounted, bottoms, entries, report, records, describe, isProxy) {
179
+ const reaches = new Map();
183
180
  for (const name of Object.keys(bottoms)) {
184
- if (!isModEventName(name) || bottoms[name] === undefined)
181
+ if (!isModEventName(name))
185
182
  continue;
183
+ const seat = bottoms[name];
186
184
  const st = stationOn(name, side);
187
- if (st?.method === undefined)
185
+ if (seat !== undefined && st?.method !== undefined)
186
+ reaches.set(name, { kind: "method", st, seat, pauses: st.method.pausesCallerBudget });
187
+ }
188
+ for (const name of Object.keys(entries)) {
189
+ if (!isModEventName(name))
188
190
  continue;
189
- const dot = name.indexOf(".");
190
- methods.push({ event: name, ns: name.slice(0, dot), method: name.slice(dot + 1), pauses: st.method.pausesCallerBudget });
191
+ const entry = entries[name];
192
+ const st = stationOn(name, side);
193
+ if (entry !== undefined && st?.call !== undefined)
194
+ reaches.set(name, { kind: "call", entry, pauses: st.call.pausesCallerBudget });
191
195
  }
192
196
  const bus = {
193
197
  records,
@@ -215,26 +219,26 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
215
219
  const inFrames = (fs, h) => fs.some((f) => f.plugin === h.reg.name && (f.kind === "dollar" || f.handler === h.index));
216
220
  const caller = frames.slice(-1);
217
221
  const above = frames.slice(0, -1);
218
- const out = [];
222
+ const all = [];
223
+ const guards = [];
219
224
  for (const h of mounted) {
220
225
  if (!h.events.has(event) || !admits(participant, h) || !matcherMatches(h.matcher, e))
221
226
  continue;
222
227
  if (inFrames(caller, h))
223
228
  continue;
224
229
  if (!inFrames(above, h))
225
- out.push({ h, reentry: false });
226
- else if (h.onCatch !== undefined && !h.observe)
227
- out.push({ h, reentry: true });
230
+ all.push({ h, reentry: false });
231
+ else if (h.observe)
232
+ continue;
233
+ else if (h.onCatch !== undefined)
234
+ all.push({ h, reentry: true });
235
+ else
236
+ guards.push(h);
228
237
  }
229
- return out;
238
+ return { all, guards };
230
239
  }
231
- async function callMethod(event, args, caller) {
232
- const seat = bottoms[event];
233
- if (seat === undefined)
234
- throw new Error(`${caller.origin.plugin}: $.${event}: no implementation on the ${side} bus`);
235
- const st = stationOn(event, side);
236
- if (st === undefined)
237
- throw new Error(`${caller.origin.plugin}: $.${event}: not raised on the ${side} bus`);
240
+ async function callMethod(event, reach, args, caller) {
241
+ const { seat, st } = reach;
238
242
  let e0 = args;
239
243
  if (seat.enter !== undefined) {
240
244
  const shaped = receivePayload(seat.enter(args), isProxy, engineObjectsOnce(args)());
@@ -249,10 +253,6 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
249
253
  signal: caller.signal,
250
254
  checkAnswer: methodAnswerViolation,
251
255
  });
252
- if (outcome.kind !== "aborted")
253
- for (const s of outcome.skipped)
254
- if (s.cause === "violation")
255
- report(new Error(`${s.registration}: $.${event}: ${s.reason} — skipped`));
256
256
  if (outcome.kind === "aborted")
257
257
  throw new Error(`${caller.origin.plugin}: $.${event}: aborted`);
258
258
  if (outcome.kind === "failed")
@@ -265,24 +265,28 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
265
265
  }
266
266
  function dollarFor(reg, frames, budget, signal, engines) {
267
267
  const origin = Object.freeze({ plugin: reg.name, tier: reg.tier });
268
- const callerFrames = Object.freeze([...frames, Object.freeze({ kind: "dollar", plugin: reg.name })]);
268
+ const caller = Object.freeze({ frames: Object.freeze([...frames, Object.freeze({ kind: "dollar", plugin: reg.name })]), origin, signal });
269
269
  const namespaces = new Map();
270
- for (const m of methods) {
271
- const ns = namespaces.get(m.ns) ?? {};
272
- namespaces.set(m.ns, ns);
273
- ns[m.method] = async (args) => {
274
- if (!reg.callsBound.has(m.event))
275
- throw new Error(`${reg.name}: $.${m.event}: not declared in uses.calls`);
270
+ for (const event of new Set([...reaches.keys(), ...reg.callsBound])) {
271
+ const dot = event.indexOf(".");
272
+ const ns = namespaces.get(event.slice(0, dot)) ?? {};
273
+ namespaces.set(event.slice(0, dot), ns);
274
+ ns[event.slice(dot + 1)] = async (args) => {
275
+ if (!reg.callsBound.has(event))
276
+ throw new Error(`${reg.name}: $.${event}: not declared in uses.calls`);
277
+ const reach = reaches.get(event);
278
+ if (reach === undefined)
279
+ throw new Error(`${reg.name}: $.${event}: not callable on the ${side} bus in this version`);
276
280
  const received = receivePayload(args === undefined ? {} : args, isProxy, engines());
277
281
  if ("refusal" in received)
278
- throw new TypeError(`${reg.name}: $.${m.event}: takes one object — ${received.refusal}`);
279
- if (m.pauses)
282
+ throw new TypeError(`${reg.name}: $.${event}: takes one object — ${received.refusal}`);
283
+ if (reach.pauses)
280
284
  budget.pause();
281
285
  try {
282
- return await callMethod(m.event, received.payload, { frames: callerFrames, origin, signal });
286
+ return reach.kind === "method" ? await callMethod(event, reach, received.payload, caller) : await reach.entry(received.payload, caller);
283
287
  }
284
288
  finally {
285
- if (m.pauses)
289
+ if (reach.pauses)
286
290
  budget.resume();
287
291
  }
288
292
  };
@@ -290,12 +294,25 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
290
294
  const out = {};
291
295
  for (const [ns, fns] of namespaces)
292
296
  out[ns] = Object.freeze(fns);
293
- return Object.freeze({ ...out, plugin: Object.freeze({ name: reg.name }) });
297
+ return Object.freeze({ ...out, plugin: Object.freeze({ ...(namespaces.get("plugin") ?? {}), name: reg.name }) });
294
298
  }
295
299
  function runDispatch(event, st, e0, options) {
296
300
  const frames = options.frames ?? [];
297
301
  const origin = options.origin ?? ENGINE_ORIGIN;
298
- const all = participants(event, e0, frames, options.participant);
302
+ const refusing = failureRefuses(st.failure);
303
+ const engineFault = (reason) => {
304
+ report(new Error(`engine: ${event}: ${reason} — the dispatch was not run`));
305
+ return Promise.resolve(Object.freeze({ kind: "failed", registration: ENGINE_ORIGIN.plugin, cause: "violation", reason: `${event}: ${reason}`, skipped: Object.freeze([]) }));
306
+ };
307
+ if (refusing && options.ranks === undefined)
308
+ return engineFault("a dispatch of an event whose failure column refuses names no answer ranks (the seat-trust law reads them)");
309
+ const { all, guards } = participants(event, e0, frames, options.participant);
310
+ const guard = refusing ? guards[0] : undefined;
311
+ if (guard !== undefined) {
312
+ const reason = "not run: the dispatch re-entered a frame it is part of, and it has no .catch to answer for it — a guard that cannot answer refuses";
313
+ report(new Error(`${guard.reg.name}: ${event}: ${reason} — failed closed: the dispatch ends here`));
314
+ return Promise.resolve(Object.freeze({ kind: "failed", registration: guard.reg.name, cause: "reentry", reason, skipped: Object.freeze([]) }));
315
+ }
299
316
  const observers = all.filter((p) => !p.reentry && p.h.observe).map((p) => p.h);
300
317
  const chain = all.filter((p) => !p.h.observe).map((p) => p.h);
301
318
  const reentered = new Set(all.filter((p) => p.reentry).map((p) => p.h));
@@ -305,6 +322,8 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
305
322
  const dispatchAc = new AbortController();
306
323
  const terminal = { kind: "terminal" };
307
324
  let settled = false;
325
+ let bottomStarted = false;
326
+ const ownMs = (ms) => (st.budgetMs === undefined ? ms : Math.min(ms, st.budgetMs));
308
327
  let graceTimer;
309
328
  let resolveOut = () => { };
310
329
  let rejectOut = () => { };
@@ -313,15 +332,16 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
313
332
  rejectOut = rej;
314
333
  });
315
334
  const signal = options.signal;
335
+ const aborted = () => (bottomStarted ? { kind: "aborted", bottomStarted: true } : { kind: "aborted" });
316
336
  const onAbort = () => {
317
337
  if (settled)
318
338
  return;
319
339
  if (st.abort === "grace") {
320
- graceTimer ??= setTimeout(() => finish({ kind: "aborted" }), POST_ABORT_GRACE_MS);
340
+ graceTimer ??= setTimeout(() => finish(aborted()), POST_ABORT_GRACE_MS);
321
341
  unrefTimer(graceTimer);
322
342
  }
323
343
  else
324
- finish({ kind: "aborted" });
344
+ finish(aborted());
325
345
  };
326
346
  function finish(o) {
327
347
  if (settled)
@@ -348,23 +368,66 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
348
368
  run.then(drop, drop);
349
369
  };
350
370
  const engines = engineObjectsOnce(e0);
371
+ const eventSealed = (() => {
372
+ let found;
373
+ return () => (found ??= sealedObjects([e0]));
374
+ })();
351
375
  const handOn = (passed) => {
352
376
  if (passed === e0)
353
377
  return { snap: e0 };
354
378
  const handed = handedOn(st.pinned, e0, passed, engines(), isProxy);
355
379
  return "violation" in handed ? handed : { snap: handed.payload };
356
380
  };
357
- const takeAnswer = (answer, s, e, h) => {
381
+ const trustFloors = new Map();
382
+ const NO_FLOOR = Object.freeze(MOD_SEATS.map(() => 0));
383
+ const seatRank = (seat) => MOD_SEATS.indexOf(seat);
384
+ const seatTrust = (taken, s, h, i, tiers) => {
385
+ const ranks = options.ranks;
386
+ if (ranks === undefined)
387
+ return undefined;
388
+ const mine = seatRank(h.reg.seat);
389
+ let rank;
390
+ try {
391
+ rank = ranks.of(taken);
392
+ }
393
+ catch {
394
+ return "returned an answer the station cannot rank";
395
+ }
396
+ const answered = s.pending === 0 && s.answers.length > 0;
397
+ let floor;
398
+ if (answered) {
399
+ const inherited = trustFloors.get(s.answers[s.answers.length - 1]) ?? NO_FLOOR;
400
+ if (rank < (inherited[mine] ?? 0))
401
+ return `answered less strictly than a more trusted seat's handler below it did — a ${h.reg.seat} answer never stands over a stricter one of a more trusted seat`;
402
+ floor = inherited;
403
+ }
404
+ else {
405
+ const unrun = chain.slice(i + 1).filter((m) => !bypassed(tiers, m.reg.tier)).map((m) => seatRank(m.reg.seat));
406
+ const trusted = unrun.length > 0 ? Math.min(...unrun) : MOD_SEATS.length;
407
+ if (trusted < mine && rank < ranks.top) {
408
+ return `answered ${s.called ? "while its next(e) still ran" : "without calling next(e)"}, with a ${MOD_SEATS[trusted]} handler below it that did not judge — a ${h.reg.seat} answer stands in place of theirs only when it refuses outright`;
409
+ }
410
+ floor = NO_FLOOR.map((_, k) => (k > trusted ? ranks.top : 0));
411
+ }
412
+ trustFloors.set(taken, floor.map((f, k) => (mine < k ? rank : f)));
413
+ return undefined;
414
+ };
415
+ const takeAnswer = (answer, s, e, h, i, tiers) => {
416
+ const handedUp = s.answers.some((a) => Object.is(a, answer));
358
417
  let taken = answer;
359
- if (!s.answers.some((a) => Object.is(a, answer))) {
360
- const received = receiveAnswer(answer, engines(), isProxy);
418
+ if (!handedUp) {
419
+ const held = { has: (v) => eventSealed().has(v) || s.sealed?.has(v) === true };
420
+ const received = receiveAnswer(answer, held, isProxy);
361
421
  if ("refusal" in received)
362
422
  return { violation: received.refusal };
363
423
  taken = received.answer;
364
424
  }
365
425
  const below = s.pending > 0 ? [...s.answers, NEXT_IN_FLIGHT] : s.answers;
366
- const why = answerViolation(taken, options.checkAnswer, e, answererOf(h), below);
367
- return why !== undefined ? { violation: why } : { answer: taken };
426
+ const why = answerViolation(taken, options.checkAnswer, e, answererOf(h), below, Object.freeze({ bottomStarted }));
427
+ if (why !== undefined)
428
+ return { violation: why };
429
+ const trust = handedUp ? undefined : seatTrust(taken, s, h, i, tiers);
430
+ return trust !== undefined ? { violation: trust } : { answer: taken };
368
431
  };
369
432
  const traceOf = (sink, index, plugin, tier, outcome, ms) => {
370
433
  sink.push(Object.freeze({ index, plugin, tier, outcome, ms }));
@@ -383,6 +446,7 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
383
446
  run.then((v) => {
384
447
  state.lastValue = { v };
385
448
  state.answers.push(v);
449
+ state.sealed = new Set([...(state.sealed ?? []), ...sealedObjects([v])]);
386
450
  stopCounting();
387
451
  }, (err) => {
388
452
  state.belowError = err;
@@ -397,8 +461,9 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
397
461
  const h = chain[i];
398
462
  if (h === undefined) {
399
463
  const t0 = Date.now();
464
+ bottomStarted = true;
400
465
  try {
401
- const v = answerUpward(await options.bottom(e, Object.freeze({ frames: fr, signal: dispatchAc.signal, origin })));
466
+ const v = answerUpward(await options.bottom(e, Object.freeze({ frames: fr, signal: dispatchAc.signal, origin })), isProxy);
402
467
  traceOf(sink, i, "core", "core", "returned", Date.now() - t0);
403
468
  return v;
404
469
  }
@@ -432,7 +497,8 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
432
497
  const name = h.reg.name;
433
498
  const ac = new AbortController();
434
499
  live.add(ac);
435
- const budget = createSelfBudget(h.reg.budgetMs, () => ac.abort(new Error(`${name} ran past its ${h.reg.budgetMs}ms budget`)));
500
+ const budgetMs = ownMs(h.reg.budgetMs);
501
+ const budget = createSelfBudget(budgetMs, () => ac.abort(new Error(`${name} ran past its ${budgetMs}ms budget`)));
436
502
  const myFrames = Object.freeze([...fr, Object.freeze({ kind: "handler", plugin: name, handler: h.index })]);
437
503
  const state = {
438
504
  pending: 0,
@@ -475,9 +541,9 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
475
541
  try {
476
542
  const raced = await Promise.race([handlerP, budget.expired]);
477
543
  if (raced === "expired" && budget.isExpired())
478
- failure = { cause: "timeout", reason: `ran past its ${h.reg.budgetMs}ms budget` };
544
+ failure = { cause: "timeout", reason: `ran past its ${budgetMs}ms budget` };
479
545
  else {
480
- const taken = takeAnswer(raced, state, e, h);
546
+ const taken = takeAnswer(raced, state, e, h, i, floors);
481
547
  if ("violation" in taken)
482
548
  failure = { cause: "violation", reason: state.violated ?? taken.violation };
483
549
  else if (state.violated !== undefined)
@@ -521,11 +587,14 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
521
587
  return caught.answer;
522
588
  }
523
589
  if (failure.cause === "threw" && state.belowError !== undefined && failure.error === state.belowError) {
590
+ if (caught !== undefined)
591
+ report(new Error(`${name}: ${event}: ${caught.problem} — what the run below threw stands`));
524
592
  traceOf(sink, i, name, h.reg.tier, "rejected", ms);
525
593
  throw failure.error;
526
594
  }
527
595
  const reason = caught !== undefined ? `${failure.reason}; ${caught.problem}` : failure.reason;
528
- if (st.failure === "refuse") {
596
+ const effectStands = st.failure === "refuse_until_run" && bottomStarted && state.last !== undefined;
597
+ if (refusing && !effectStands) {
529
598
  if (failure.cause !== "violation")
530
599
  report(new Error(`${name}: ${event}: ${reason} — failed closed: the dispatch ends here`));
531
600
  traceOf(sink, i, name, h.reg.tier, "rejected", ms);
@@ -534,8 +603,7 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
534
603
  }
535
604
  skipped.push(Object.freeze({ registration: name, cause: failure.cause, reason }));
536
605
  const effect = state.last !== undefined ? MA : HA;
537
- if (failure.cause !== "violation")
538
- report(new Error(`${name}: ${event}: ${reason} — ${effect}`));
606
+ report(new Error(`${name}: ${event}: ${reason} — ${effect}`));
539
607
  if (state.last !== undefined) {
540
608
  traceOf(sink, i, name, h.reg.tier, failure.cause === "timeout" ? "expired" : "kept", ms);
541
609
  return state.last;
@@ -549,7 +617,8 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
549
617
  return { problem: "no .catch" };
550
618
  const ac = new AbortController();
551
619
  live.add(ac);
552
- const budget = createSelfBudget(CATCH_BUDGET_MS, () => ac.abort(new Error(`${h.reg.name}: its .catch ran past its ${CATCH_BUDGET_MS}ms budget`)));
620
+ const catchMs = ownMs(CATCH_BUDGET_MS);
621
+ const budget = createSelfBudget(catchMs, () => ac.abort(new Error(`${h.reg.name}: its .catch ran past its ${catchMs}ms budget`)));
553
622
  let done = false;
554
623
  let violated;
555
624
  const replay = (passed, nextFloors) => {
@@ -570,7 +639,7 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
570
639
  return startBelow(state, budget, i, handed.snap, nextFloors, myFrames);
571
640
  };
572
641
  const message = failure.cause === "threw" ? describe(failure.error) : failure.cause === "violation" ? failure.reason : undefined;
573
- const error = Object.freeze({ kind: failure.cause, ...(message !== undefined ? { message } : {}), budget: CATCH_BUDGET_MS });
642
+ const error = Object.freeze({ kind: failure.cause, ...(message !== undefined ? { message } : {}), budget: catchMs });
574
643
  const next = makeNext({ budget, signal: ac.signal, trace: () => Object.freeze([...state.below]) }, (x) => replay(x, floors), (x, tier) => {
575
644
  const why = nextToRefusal(h.reg.tier, tier);
576
645
  return why !== undefined ? Promise.reject(new Error(`${h.reg.name}: ${why}`)) : replay(x, [...floors, { from: h.reg.tier, to: tier }]);
@@ -578,10 +647,10 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
578
647
  try {
579
648
  const raced = await Promise.race([invokeNow(() => onCatch(dollarFor(h.reg, myFrames, budget, ac.signal, engines), e, next)), budget.expired]);
580
649
  if (raced === "expired" && budget.isExpired())
581
- return { problem: `its .catch ran past its ${CATCH_BUDGET_MS}ms budget` };
650
+ return { problem: `its .catch ran past its ${catchMs}ms budget` };
582
651
  if (violated !== undefined)
583
652
  return { problem: `its .catch ${violated}` };
584
- const taken = takeAnswer(raced, state, e, h);
653
+ const taken = takeAnswer(raced, state, e, h, i, floors);
585
654
  return "violation" in taken ? { problem: `its .catch ${taken.violation}` } : { answer: taken.answer };
586
655
  }
587
656
  catch (err) {
@@ -598,7 +667,8 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
598
667
  const name = h.reg.name;
599
668
  const ac = new AbortController();
600
669
  live.add(ac);
601
- const budget = createSelfBudget(h.reg.budgetMs, () => ac.abort(new Error(`${name} ran past its ${h.reg.budgetMs}ms budget`)));
670
+ const budgetMs = ownMs(h.reg.budgetMs);
671
+ const budget = createSelfBudget(budgetMs, () => ac.abort(new Error(`${name} ran past its ${budgetMs}ms budget`)));
602
672
  const myFrames = Object.freeze([...fr, Object.freeze({ kind: "handler", plugin: name, handler: h.index })]);
603
673
  const refuse = () => Promise.reject(new Error(`${name}: an observe handler is not in the chain; next() is unavailable`));
604
674
  const next = makeNext({ budget, signal: ac.signal, trace: () => Object.freeze([]) }, refuse, refuse);
@@ -610,7 +680,7 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
610
680
  try {
611
681
  const raced = await Promise.race([invokeNow(() => h.fn(dollarFor(h.reg, myFrames, budget, ac.signal, engines), detachedCopy(e0), next)), budget.expired]);
612
682
  if (raced === "expired" && budget.isExpired())
613
- throw new Error(`ran past its ${h.reg.budgetMs}ms budget`);
683
+ throw new Error(`ran past its ${budgetMs}ms budget`);
614
684
  verdict(raced);
615
685
  }
616
686
  catch (err) {
@@ -623,9 +693,10 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
623
693
  budget.clear();
624
694
  const cac = new AbortController();
625
695
  live.add(cac);
626
- const catchBudget = createSelfBudget(CATCH_BUDGET_MS, () => cac.abort(new Error(`${name}: its .catch ran past its ${CATCH_BUDGET_MS}ms budget`)));
696
+ const catchMs = ownMs(CATCH_BUDGET_MS);
697
+ const catchBudget = createSelfBudget(catchMs, () => cac.abort(new Error(`${name}: its .catch ran past its ${catchMs}ms budget`)));
627
698
  const cnext = makeNext({ budget: catchBudget, signal: cac.signal, trace: () => Object.freeze([]) }, refuse, refuse, {
628
- error: Object.freeze({ kind: cause, ...(cause === "threw" ? { message: describe(err) } : {}), budget: CATCH_BUDGET_MS }),
699
+ error: Object.freeze({ kind: cause, ...(cause === "threw" ? { message: describe(err) } : {}), budget: catchMs }),
629
700
  called: false,
630
701
  });
631
702
  try {
@@ -662,7 +733,7 @@ function createBus(side, mounted, bottoms, report, records, describe, isProxy) {
662
733
  if (settled)
663
734
  return;
664
735
  const answer = await invoke(0, e0, [], frames, root);
665
- while (st.failure === "refuse" && pendingRuns.size > 0 && !settled)
736
+ while (refusing && pendingRuns.size > 0 && !settled)
666
737
  await Promise.allSettled([...pendingRuns]);
667
738
  finish({ kind: "answered", answer, ...(producers.has(answer) ? { answeredBy: producers.get(answer) } : {}), skipped: Object.freeze([...skipped]) });
668
739
  })().catch((err) => {
@@ -10,12 +10,19 @@
10
10
  * The kernel CONTRACT number — a monotonic integer, independent of the package version (the package is
11
11
  * cut with core every release; this number is not). It is exported for a host that loads a kernel copy
12
12
  * beside another one to compare for EQUALITY; nothing in this folder or in the engine reads it, so two
13
- * copies that differ are not detected here. It is raised when, and only when, one of four things changes:
14
- * the chain semantics (`next`, `next.to`, origin, trace, re-entry frames), the registration form (`ModRegistration`, `on`, `uses`),
15
- * the event closed set (names and their `side`), or the failure columns (failure, abort, pinned keys — which keys,
16
- * and how a pinned key is judged: by value since 2).
13
+ * copies that differ are not detected here. It is raised when, and only when, one of four things changes —
14
+ * once per release, however many of them change in it:
15
+ * the chain semantics (`next`, `next.to`, origin, trace, re-entry frames, what a `$` call reaches — a method's
16
+ * chain or a callable event's host entry — what a dispatch records of its run, how answers are received and which
17
+ * seat's answer may stand over which), the registration form (`ModRegistration`, `on`, `uses` and which names a side
18
+ * takes in it), the event closed set (names and their `side`), or the failure columns (failure, abort, pinned keys,
19
+ * an event's own budget ceiling, whether `$` may call it — which keys, and how a pinned key is judged: by value since 2).
20
+ * 3: the shell's events have stations, the event-level budget and `call` columns, a `$` call of a callable event
21
+ * reaches the host's entry, the dispatch records whether its bottom started, a re-entered guard with no `.catch`
22
+ * refuses, the one side lock over `uses` and `on`, answers received as data, the seat-trust law, `prompt.mention`
23
+ * on the engine's side, and `tool.call` with the `refuse_until_run` failure answer, callable.
17
24
  */
18
- export declare const KERNEL_CONTRACT_VERSION = 2;
25
+ export declare const KERNEL_CONTRACT_VERSION = 3;
19
26
  /** The five tiers in run order (CC names). `builtin` and `core` are the engine's own. */
20
27
  export declare const MOD_TIERS: readonly ["prepend", "user", "append", "builtin", "core"];
21
28
  export type ModTier = (typeof MOD_TIERS)[number];
@@ -29,9 +36,15 @@ export declare const MOD_EVENT_SIDES: readonly ["engine", "surface", "both"];
29
36
  export type ModEventSide = (typeof MOD_EVENT_SIDES)[number];
30
37
  /** A bus is one side. */
31
38
  export type ModBusSide = Exclude<ModEventSide, "both">;
32
- /** What a handler's failure means for the dispatch: the station's refusal (final), or skip the handler. */
33
- export declare const MOD_FAILURE_ANSWERS: readonly ["refuse", "skip"];
39
+ /**
40
+ * What a handler's failure means for the dispatch: the station's refusal (final); skip the handler; or — on an event
41
+ * whose chain bottom is an effect (a tool runs) — the refusal while the bottom has not started and, once it has, what
42
+ * the bottom did stands (the failure is reported beside the real result, which it never replaces).
43
+ */
44
+ export declare const MOD_FAILURE_ANSWERS: readonly ["refuse", "skip", "refuse_until_run"];
34
45
  export type ModFailureAnswer = (typeof MOD_FAILURE_ANSWERS)[number];
46
+ /** Whether a failure column refuses: the events a station judges on (or runs an effect behind) fail closed. */
47
+ export declare function failureRefuses(failure: ModFailureAnswer): boolean;
35
48
  /** What a cancel does to a dispatch: end it now, give it one second, or follow the calling handler. */
36
49
  export declare const MOD_ABORT_POSTURES: readonly ["immediate", "grace", "caller"];
37
50
  export type ModAbortPosture = (typeof MOD_ABORT_POSTURES)[number];
@@ -56,7 +69,12 @@ export declare const SEAT_TIER_TABLE: Readonly<{
56
69
  tiers: readonly ["user"];
57
70
  }>;
58
71
  }>;
59
- /** The station columns of an event a bus raises. `method` marks a `$` method (the event a `$` call raises). */
72
+ /**
73
+ * The station columns of an event a bus raises. `method` marks a `$` method (the event a `$` call raises; its chain
74
+ * bottom is the host's seat). `call` marks an event `$` may call: the call goes to the host's entry for the event,
75
+ * which runs whatever stands before it and raises it once at its own station. A row is a method, a callable event, or
76
+ * neither — never both.
77
+ */
60
78
  export interface ModStation {
61
79
  readonly failure: ModFailureAnswer;
62
80
  readonly abort: ModAbortPosture;
@@ -66,6 +84,12 @@ export interface ModStation {
66
84
  readonly method?: {
67
85
  readonly pausesCallerBudget: boolean;
68
86
  };
87
+ readonly call?: {
88
+ readonly pausesCallerBudget: boolean;
89
+ };
90
+ /** The event's own ceiling on a handler's time: every clock a handler runs under on this event (its body, its
91
+ * `.catch`, an observer) is the smaller of its own and this — a registration's budget never widens it. */
92
+ readonly budgetMs?: number;
69
93
  }
70
94
  /** One event: its side, and its station when a bus raises it in this version (absent ⇒ named, not raised). */
71
95
  export interface ModEventRow {
@@ -75,9 +99,10 @@ export interface ModEventRow {
75
99
  /**
76
100
  * Every event the kernel knows: the reference's closed set of 142 names (CC 2.1.296 `J3e` (cli296.js:238573) — its 33 `classic.*` names,
77
101
  * its 46 engine events and its 63 `$` methods, in its own order). The shell's names (`ui.*`, `command.*`,
78
- * `config.*`, `audio.*`, the prompt-box events and `prompt.read`) carry `side: "surface"`, so one table serves both
79
- * buses and the shell fills their stations. A row with a station is raised on its side in this version; a name with
80
- * none is named, not raised, and a registration that selects only such names is refused.
102
+ * `config.*`, `audio.*`, the prompt-box events and `prompt.read`) carry `side: "surface"`: one table serves both
103
+ * buses, and the shell's stations are its rows here, raised by the shell where their chain bottoms are. A row with a
104
+ * station is raised on its side in this version; a name with none is named, not raised, and a registration that
105
+ * selects only such names is refused.
81
106
  */
82
107
  export declare const MOD_EVENT_TABLE: Readonly<{
83
108
  "classic.PreToolUse": ModEventRow;
@@ -241,5 +266,16 @@ export declare function expandModPattern(pattern: unknown): {
241
266
  } | {
242
267
  readonly refusal: string;
243
268
  };
269
+ /**
270
+ * The names a pattern selects on a bus of `side` — the ONE side lock, read alike by `uses.events`, `uses.calls` and
271
+ * `on()`: an exact name the other side's bus reads (neither this side nor `both`) is refused (it is that bus's name, never
272
+ * usable here); a `<prefix>.*` pattern selects the names under the prefix this side reads and must select one. A name
273
+ * of this side that no station raises in this version is selected all the same (a forward declaration).
274
+ */
275
+ export declare function expandOnSide(pattern: unknown, side: ModBusSide): {
276
+ readonly names: readonly ModEventName[];
277
+ } | {
278
+ readonly refusal: string;
279
+ };
244
280
  /** A safe one-word description of a host value for a sentence (never calls the value's own toString). */
245
281
  export declare function describe(value: unknown): string;