@sema-agent/core 7.60.0 → 7.62.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 (560) hide show
  1. package/CHANGELOG.md +917 -0
  2. package/README.md +2 -2
  3. package/dist/agents/agent-transcript-tool.d.ts +2 -2
  4. package/dist/agents/agent-transcript-tool.js +1 -1
  5. package/dist/agents/cascade.d.ts +71 -12
  6. package/dist/agents/cascade.js +61 -21
  7. package/dist/agents/composition-allowance.d.ts +53 -0
  8. package/dist/agents/composition-allowance.js +49 -0
  9. package/dist/agents/composition-placement.d.ts +29 -0
  10. package/dist/agents/composition-placement.js +24 -0
  11. package/dist/agents/cumulative-stats.d.ts +4 -0
  12. package/dist/agents/cumulative-stats.js +3 -0
  13. package/dist/agents/inherited-tool-pool.d.ts +5 -3
  14. package/dist/agents/inherited-tool-pool.js +2 -2
  15. package/dist/agents/list-agents-tool.d.ts +1 -1
  16. package/dist/agents/peer-held-queue.d.ts +27 -4
  17. package/dist/agents/peer-held-queue.js +81 -36
  18. package/dist/agents/peer-notice-route.d.ts +1 -1
  19. package/dist/agents/peer-notice-route.js +4 -3
  20. package/dist/agents/peer-notices.d.ts +4 -4
  21. package/dist/agents/peer-notices.js +8 -4
  22. package/dist/agents/peer-session-drain.d.ts +8 -1
  23. package/dist/agents/peer-session-drain.js +49 -10
  24. package/dist/agents/repair-loop.js +16 -6
  25. package/dist/agents/retain-ledger.js +3 -1
  26. package/dist/agents/roster-store.d.ts +1 -1
  27. package/dist/agents/roster-store.js +7 -4
  28. package/dist/agents/send-message-tool.d.ts +8 -10
  29. package/dist/agents/send-message-tool.js +43 -23
  30. package/dist/agents/subagent-completion-gate.d.ts +35 -0
  31. package/dist/agents/subagent-completion-gate.js +62 -0
  32. package/dist/agents/subagent-steps.d.ts +7 -6
  33. package/dist/agents/subagent.d.ts +36 -41
  34. package/dist/agents/subagent.js +245 -200
  35. package/dist/agents/suspend-guard.d.ts +47 -16
  36. package/dist/agents/suspend-guard.js +13 -4
  37. package/dist/agents/verify.d.ts +41 -14
  38. package/dist/agents/verify.js +41 -30
  39. package/dist/brain/anthropic.js +1 -0
  40. package/dist/brain/errors.d.ts +7 -1
  41. package/dist/brain/errors.js +6 -0
  42. package/dist/brain/failover.js +2 -1
  43. package/dist/brain/open-responses.js +1 -0
  44. package/dist/brain/openai.js +1 -0
  45. package/dist/brain/provider-dialect.d.ts +10 -0
  46. package/dist/brain/provider-dialect.js +13 -2
  47. package/dist/brain/stream-engine.d.ts +3 -0
  48. package/dist/brain/stream-engine.js +4 -0
  49. package/dist/core/agent-state.d.ts +1 -1
  50. package/dist/core/allow-entry.d.ts +59 -23
  51. package/dist/core/allow-entry.js +131 -38
  52. package/dist/core/ask-origin.d.ts +79 -0
  53. package/dist/core/ask-origin.js +76 -0
  54. package/dist/core/ask-question.d.ts +19 -13
  55. package/dist/core/ask-question.js +8 -2
  56. package/dist/core/auto-compaction.d.ts +2 -0
  57. package/dist/core/auto-compaction.js +2 -1
  58. package/dist/core/auto-mode.js +3 -5
  59. package/dist/core/background-agent-store.d.ts +7 -5
  60. package/dist/core/background-agent-store.js +12 -11
  61. package/dist/core/checkpoint-features.d.ts +722 -0
  62. package/dist/core/checkpoint-features.js +98 -0
  63. package/dist/core/checkpoint-requirements.d.ts +33 -5
  64. package/dist/core/checkpoint-requirements.js +18 -5
  65. package/dist/core/checkpoint-row-verdict.d.ts +99 -0
  66. package/dist/core/checkpoint-row-verdict.js +225 -0
  67. package/dist/core/checkpoint-store.d.ts +107 -738
  68. package/dist/core/checkpoint-store.js +45 -143
  69. package/dist/core/child-clamp-seats.d.ts +3 -2
  70. package/dist/core/child-clamp-seats.js +4 -3
  71. package/dist/core/closest-name.d.ts +13 -0
  72. package/dist/core/closest-name.js +35 -0
  73. package/dist/core/context-settings.js +3 -5
  74. package/dist/core/cross-boundary-taint.d.ts +1 -1
  75. package/dist/core/decision-receipt.d.ts +14 -1
  76. package/dist/core/decision-receipt.js +6 -3
  77. package/dist/core/delegation-frames.d.ts +13 -9
  78. package/dist/core/effective-path-target.js +2 -3
  79. package/dist/core/engine-attestation.d.ts +11 -1
  80. package/dist/core/engine-attestation.js +2 -0
  81. package/dist/core/engine-notice.d.ts +68 -21
  82. package/dist/core/engine-notice.js +9 -2
  83. package/dist/core/file-history-retention.d.ts +8 -0
  84. package/dist/core/file-history-retention.js +14 -11
  85. package/dist/core/file-history-store.d.ts +31 -1
  86. package/dist/core/file-history-store.js +31 -2
  87. package/dist/core/frame-settlement.d.ts +10 -0
  88. package/dist/core/frame-settlement.js +6 -1
  89. package/dist/core/fs-write-gate-policy.d.ts +3 -3
  90. package/dist/core/fs-write-gate-policy.js +8 -7
  91. package/dist/core/gate-fold.js +4 -3
  92. package/dist/core/gate-lanes.js +7 -4
  93. package/dist/core/gate-outcome.d.ts +40 -1
  94. package/dist/core/gate-outcome.js +10 -0
  95. package/dist/core/git-worktree-env.d.ts +7 -3
  96. package/dist/core/git-worktree-env.js +16 -13
  97. package/dist/core/governance-codes.d.ts +14 -4
  98. package/dist/core/governance-codes.js +19 -4
  99. package/dist/core/hooks.d.ts +25 -4
  100. package/dist/core/hooks.js +11 -4
  101. package/dist/core/host-floor.js +3 -5
  102. package/dist/core/human-input-projection.d.ts +1 -0
  103. package/dist/core/human-input-projection.js +3 -0
  104. package/dist/core/image-admission.d.ts +47 -7
  105. package/dist/core/image-admission.js +35 -4
  106. package/dist/core/input-author.d.ts +36 -0
  107. package/dist/core/input-author.js +39 -0
  108. package/dist/core/leg-identity.d.ts +62 -0
  109. package/dist/core/leg-identity.js +18 -0
  110. package/dist/core/locked-config.d.ts +4 -3
  111. package/dist/core/locked-config.js +5 -3
  112. package/dist/core/lsp.d.ts +5 -3
  113. package/dist/core/lsp.js +3 -2
  114. package/dist/core/mailbox-store.d.ts +85 -10
  115. package/dist/core/mailbox-store.js +31 -10
  116. package/dist/core/mcp-connection-pool.d.ts +6 -20
  117. package/dist/core/mcp-connection-pool.js +10 -28
  118. package/dist/core/mcp-failure.d.ts +76 -15
  119. package/dist/core/mcp-failure.js +60 -33
  120. package/dist/core/mcp-host-seat.d.ts +92 -53
  121. package/dist/core/mcp-host-seat.js +225 -46
  122. package/dist/core/mcp-probe.js +2 -2
  123. package/dist/core/mcp-server-link.d.ts +18 -6
  124. package/dist/core/mcp-server-link.js +19 -4
  125. package/dist/core/mcp-server-spec.d.ts +2 -1
  126. package/dist/core/mcp-session-end.d.ts +1 -2
  127. package/dist/core/mcp-session-end.js +1 -1
  128. package/dist/core/mcp.d.ts +6 -49
  129. package/dist/core/mcp.js +115 -111
  130. package/dist/core/media-byte-cap.d.ts +21 -46
  131. package/dist/core/media-byte-cap.js +55 -55
  132. package/dist/core/member-group.d.ts +7 -0
  133. package/dist/core/member-group.js +35 -0
  134. package/dist/core/memory-engine/consolidation-driver.d.ts +1 -1
  135. package/dist/core/memory-engine/consolidation.d.ts +1 -1
  136. package/dist/core/memory-engine/consolidation.js +7 -1
  137. package/dist/core/memory-engine/dual-root.d.ts +31 -0
  138. package/dist/core/memory-engine/dual-root.js +59 -11
  139. package/dist/core/memory-engine/engine.js +27 -24
  140. package/dist/core/memory-engine/file-backend.d.ts +13 -0
  141. package/dist/core/memory-engine/file-backend.js +35 -15
  142. package/dist/core/memory-engine/layout.d.ts +3 -0
  143. package/dist/core/memory-engine/layout.js +13 -3
  144. package/dist/core/memory-engine/memory-deployment.d.ts +110 -0
  145. package/dist/core/memory-engine/memory-deployment.js +182 -0
  146. package/dist/core/memory-engine/sync-client.d.ts +39 -18
  147. package/dist/core/memory-engine/sync-client.js +72 -14
  148. package/dist/core/memory-engine/sync-report.d.ts +7 -4
  149. package/dist/core/memory-engine/sync.d.ts +9 -1
  150. package/dist/core/memory-vector.d.ts +1 -1
  151. package/dist/core/memory.d.ts +10 -10
  152. package/dist/core/mode-policy.d.ts +8 -8
  153. package/dist/core/mode-policy.js +8 -6
  154. package/dist/core/mods/agent-stations.d.ts +39 -4
  155. package/dist/core/mods/agent-stations.js +59 -10
  156. package/dist/core/mods/classic-events.d.ts +9 -1
  157. package/dist/core/mods/dollar.d.ts +94 -1
  158. package/dist/core/mods/dollar.js +13 -1
  159. package/dist/core/mods/extension-call.d.ts +15 -1
  160. package/dist/core/mods/extension-call.js +7 -2
  161. package/dist/core/mods/kernel/dispatch.d.ts +4 -3
  162. package/dist/core/mods/kernel/dispatch.js +4 -4
  163. package/dist/core/mods/kernel/events.d.ts +14 -3
  164. package/dist/core/mods/kernel/events.js +18 -15
  165. package/dist/core/mods/kernel/registration.d.ts +3 -0
  166. package/dist/core/mods/kernel/registration.js +5 -0
  167. package/dist/core/mods/kernel/site-rules.d.ts +6 -3
  168. package/dist/core/mods/kernel/site-rules.js +10 -2
  169. package/dist/core/mods/lifecycle-stations.d.ts +36 -4
  170. package/dist/core/mods/lifecycle-stations.js +44 -9
  171. package/dist/core/mods/session-append.d.ts +118 -0
  172. package/dist/core/mods/session-append.js +318 -0
  173. package/dist/core/mods/session-compact.d.ts +48 -0
  174. package/dist/core/mods/session-compact.js +194 -0
  175. package/dist/core/mods/session-receive.d.ts +93 -0
  176. package/dist/core/mods/session-receive.js +138 -0
  177. package/dist/core/mods/session-send.d.ts +72 -0
  178. package/dist/core/mods/session-send.js +88 -0
  179. package/dist/core/mods/stations.d.ts +88 -21
  180. package/dist/core/mods/stations.js +149 -11
  181. package/dist/core/mods/tool-call.d.ts +2 -0
  182. package/dist/core/mods/tool-call.js +4 -4
  183. package/dist/core/output-style.js +3 -4
  184. package/dist/core/own-property-receipt.d.ts +68 -2
  185. package/dist/core/own-property-receipt.js +45 -2
  186. package/dist/core/park-selfcheck.js +4 -2
  187. package/dist/core/path-identity.d.ts +11 -0
  188. package/dist/core/path-identity.js +4 -0
  189. package/dist/core/path-rule-binding.d.ts +3 -1
  190. package/dist/core/path-rule-binding.js +3 -1
  191. package/dist/core/peer-seat.d.ts +3 -3
  192. package/dist/core/peer-seat.js +20 -8
  193. package/dist/core/permission-rule-consent.d.ts +21 -5
  194. package/dist/core/permission-rule-consent.js +21 -1
  195. package/dist/core/permission-rule-model.d.ts +34 -11
  196. package/dist/core/permission-rule-model.js +47 -10
  197. package/dist/core/permission-rule-org.d.ts +1 -1
  198. package/dist/core/permission-rule-provider.js +4 -1
  199. package/dist/core/permission-rules.d.ts +4 -0
  200. package/dist/core/permission-rules.js +11 -16
  201. package/dist/core/read-root-candidate.js +1 -1
  202. package/dist/core/remote-env.d.ts +74 -26
  203. package/dist/core/remote-env.js +20 -0
  204. package/dist/core/resume-startup-cause.d.ts +5 -4
  205. package/dist/core/retention-policy.d.ts +24 -23
  206. package/dist/core/retention-policy.js +36 -2
  207. package/dist/core/retention.d.ts +4 -1
  208. package/dist/core/retired-keys.d.ts +4 -4
  209. package/dist/core/row-admission.d.ts +10 -0
  210. package/dist/core/row-admission.js +5 -0
  211. package/dist/core/runner/advisor-instructions.d.ts +2 -1
  212. package/dist/core/runner/advisor-instructions.js +2 -1
  213. package/dist/core/runner/announce-once-ledger.d.ts +4 -4
  214. package/dist/core/runner/assemble-result.d.ts +13 -3
  215. package/dist/core/runner/assemble-result.js +12 -7
  216. package/dist/core/runner/caller-roster.d.ts +12 -9
  217. package/dist/core/runner/caller-roster.js +5 -2
  218. package/dist/core/runner/checkpoint-scope.d.ts +16 -1
  219. package/dist/core/runner/checkpoint-scope.js +21 -0
  220. package/dist/core/runner/compact-session.js +18 -3
  221. package/dist/core/runner/compaction-call-options.d.ts +1 -1
  222. package/dist/core/runner/compaction-restate.d.ts +2 -2
  223. package/dist/core/runner/compaction-restate.js +4 -3
  224. package/dist/core/runner/construction-doors.d.ts +2 -2
  225. package/dist/core/runner/construction-doors.js +2 -2
  226. package/dist/core/runner/contracts.d.ts +116 -34
  227. package/dist/core/runner/cross-boundary-lane.d.ts +1 -1
  228. package/dist/core/runner/decide-continuation.d.ts +4 -2
  229. package/dist/core/runner/decide-continuation.js +7 -4
  230. package/dist/core/runner/delegation-owner.d.ts +43 -0
  231. package/dist/core/runner/delegation-owner.js +59 -0
  232. package/dist/core/runner/denial-limit-arms.d.ts +15 -21
  233. package/dist/core/runner/denial-limit-arms.js +17 -10
  234. package/dist/core/runner/expire-settle.d.ts +44 -0
  235. package/dist/core/runner/expire-settle.js +55 -0
  236. package/dist/core/runner/git-status-frame.d.ts +3 -3
  237. package/dist/core/runner/git-status-frame.js +2 -1
  238. package/dist/core/runner/halt-attribution.d.ts +2 -1
  239. package/dist/core/runner/halt-attribution.js +2 -1
  240. package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
  241. package/dist/core/runner/lineage-reroot-view.js +108 -0
  242. package/dist/core/runner/local-claims.d.ts +17 -0
  243. package/dist/core/runner/local-claims.js +18 -0
  244. package/dist/core/runner/media-removed-seat.d.ts +46 -0
  245. package/dist/core/runner/media-removed-seat.js +88 -0
  246. package/dist/core/runner/park-commit.d.ts +2 -2
  247. package/dist/core/runner/permission-rule-lanes.d.ts +7 -2
  248. package/dist/core/runner/permission-rule-lanes.js +28 -9
  249. package/dist/core/runner/person-path-rows.d.ts +15 -0
  250. package/dist/core/runner/person-path-rows.js +27 -4
  251. package/dist/core/runner/placement-fence.d.ts +26 -0
  252. package/dist/core/runner/placement-fence.js +38 -0
  253. package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
  254. package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
  255. package/dist/core/runner/prepare-ask-lane.d.ts +6 -12
  256. package/dist/core/runner/prepare-ask-lane.js +4 -4
  257. package/dist/core/runner/prepare-boundary-parks.d.ts +4 -1
  258. package/dist/core/runner/prepare-boundary-parks.js +2 -2
  259. package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -0
  260. package/dist/core/runner/prepare-caps-and-workflow.js +2 -1
  261. package/dist/core/runner/prepare-config-doors.d.ts +6 -6
  262. package/dist/core/runner/prepare-config-doors.js +19 -21
  263. package/dist/core/runner/prepare-context-lane.d.ts +6 -2
  264. package/dist/core/runner/prepare-context-lane.js +13 -13
  265. package/dist/core/runner/prepare-delegation-surface.d.ts +9 -9
  266. package/dist/core/runner/prepare-delegation-surface.js +4 -5
  267. package/dist/core/runner/prepare-execution-env.d.ts +5 -2
  268. package/dist/core/runner/prepare-execution-env.js +7 -4
  269. package/dist/core/runner/prepare-gate-stations.d.ts +19 -14
  270. package/dist/core/runner/prepare-gate-stations.js +6 -4
  271. package/dist/core/runner/prepare-hands-readface.d.ts +6 -6
  272. package/dist/core/runner/prepare-hands-readface.js +32 -11
  273. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -0
  274. package/dist/core/runner/prepare-inherited-gate.js +10 -3
  275. package/dist/core/runner/prepare-lsp.d.ts +3 -0
  276. package/dist/core/runner/prepare-lsp.js +2 -2
  277. package/dist/core/runner/prepare-park-ask.d.ts +5 -2
  278. package/dist/core/runner/prepare-park-ask.js +4 -5
  279. package/dist/core/runner/prepare-policy-chain.d.ts +10 -21
  280. package/dist/core/runner/prepare-policy-chain.js +16 -25
  281. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  282. package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -4
  283. package/dist/core/runner/prepare-prompt-inputs.js +3 -2
  284. package/dist/core/runner/prepare-question-face.d.ts +6 -4
  285. package/dist/core/runner/prepare-question-face.js +2 -2
  286. package/dist/core/runner/prepare-run-refs.d.ts +3 -0
  287. package/dist/core/runner/prepare-run-refs.js +2 -2
  288. package/dist/core/runner/prepare-suspend-saga.d.ts +11 -7
  289. package/dist/core/runner/prepare-suspend-saga.js +17 -7
  290. package/dist/core/runner/prepare-task.d.ts +1 -1
  291. package/dist/core/runner/prepare-task.js +61 -30
  292. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +6 -0
  293. package/dist/core/runner/prepare-tool-disclosure-mount.js +3 -1
  294. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -0
  295. package/dist/core/runner/prepare-wiring-manifest.js +2 -1
  296. package/dist/core/runner/prepare-workspace-restore.d.ts +5 -0
  297. package/dist/core/runner/prepare-workspace-restore.js +10 -6
  298. package/dist/core/runner/read-root-grant.d.ts +1 -1
  299. package/dist/core/runner/read-root-grant.js +2 -1
  300. package/dist/core/runner/resume-admission.d.ts +8 -6
  301. package/dist/core/runner/resume-admission.js +23 -6
  302. package/dist/core/runner/resume-apply.d.ts +4 -0
  303. package/dist/core/runner/resume-apply.js +14 -5
  304. package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
  305. package/dist/core/runner/resume-checkpoint-screen.js +4 -84
  306. package/dist/core/runner/resume-claim.d.ts +8 -3
  307. package/dist/core/runner/resume-claim.js +28 -12
  308. package/dist/core/runner/resume-internals-and-config.d.ts +2 -2
  309. package/dist/core/runner/resume-internals-and-config.js +10 -1
  310. package/dist/core/runner/resume-preflight.d.ts +3 -2
  311. package/dist/core/runner/resume-preflight.js +13 -26
  312. package/dist/core/runner/retired-runner-deps.js +2 -0
  313. package/dist/core/runner/run-git-lane.d.ts +2 -0
  314. package/dist/core/runner/run-git-lane.js +6 -2
  315. package/dist/core/runner/run-harness-handlers.d.ts +2 -0
  316. package/dist/core/runner/run-harness-handlers.js +5 -4
  317. package/dist/core/runner/run-identity-wiring.d.ts +2 -2
  318. package/dist/core/runner/run-identity-wiring.js +14 -5
  319. package/dist/core/runner/run-leg.d.ts +3 -3
  320. package/dist/core/runner/run-leg.js +64 -36
  321. package/dist/core/runner/run-notification-lane.js +20 -2
  322. package/dist/core/runner/run-recovery-lanes.js +3 -2
  323. package/dist/core/runner/run-settle-and-teardown.js +12 -9
  324. package/dist/core/runner/run-stop-and-final-verify.js +2 -1
  325. package/dist/core/runner/run-telemetry-and-budget-seats.d.ts +1 -1
  326. package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
  327. package/dist/core/runner/run-terminal-adoption.js +26 -17
  328. package/dist/core/runner/run-turn-boundary.js +34 -18
  329. package/dist/core/runner/runtask.d.ts +18 -3
  330. package/dist/core/runner/runtask.js +33 -17
  331. package/dist/core/runner/session-rule-policy.d.ts +1 -1
  332. package/dist/core/runner/session-rule-policy.js +6 -1
  333. package/dist/core/runner/shell-env-withheld.d.ts +1 -1
  334. package/dist/core/runner/steering-preview.d.ts +9 -0
  335. package/dist/core/runner/steering-preview.js +5 -0
  336. package/dist/core/runner/stream-halt-verbs.d.ts +1 -14
  337. package/dist/core/runner/stream-halt-verbs.js +4 -3
  338. package/dist/core/runner/stream-reap.d.ts +7 -6
  339. package/dist/core/runner/stream-reap.js +13 -16
  340. package/dist/core/runner/stream-settle-backstop.d.ts +3 -2
  341. package/dist/core/runner/stream-settle-backstop.js +5 -3
  342. package/dist/core/runner/stream-steer-verb.d.ts +5 -2
  343. package/dist/core/runner/stream-steer-verb.js +16 -7
  344. package/dist/core/runner/terminal-account.d.ts +11 -1
  345. package/dist/core/runner/terminal-account.js +20 -0
  346. package/dist/core/runner/terminal-projection.d.ts +8 -2
  347. package/dist/core/runner/terminal-projection.js +2 -2
  348. package/dist/core/runner/tool-disclosure.d.ts +3 -0
  349. package/dist/core/runner/tool-disclosure.js +5 -2
  350. package/dist/core/runner/tool-end-body.d.ts +3 -3
  351. package/dist/core/runner/tool-end-body.js +1 -1
  352. package/dist/core/runner/tool-face-overlay.js +2 -0
  353. package/dist/core/runner/tool-output-projection.d.ts +3 -3
  354. package/dist/core/runner/tool-output-projection.js +7 -6
  355. package/dist/core/runner/tool-table-view.d.ts +56 -0
  356. package/dist/core/runner/tool-table-view.js +51 -0
  357. package/dist/core/runner/turn-attachments.d.ts +8 -2
  358. package/dist/core/runner/turn-attachments.js +2 -2
  359. package/dist/core/runner/void-verifier-pause.d.ts +33 -0
  360. package/dist/core/runner/void-verifier-pause.js +41 -0
  361. package/dist/core/runner-deps.d.ts +26 -27
  362. package/dist/core/secret-env.d.ts +19 -16
  363. package/dist/core/secret-env.js +45 -27
  364. package/dist/core/session-log-transfer.js +9 -10
  365. package/dist/core/session-policy-store.d.ts +1 -1
  366. package/dist/core/session-policy-store.js +5 -2
  367. package/dist/core/session-reconcile.d.ts +3 -2
  368. package/dist/core/session-reconcile.js +7 -4
  369. package/dist/core/session-store.d.ts +3 -1
  370. package/dist/core/session-store.js +10 -8
  371. package/dist/core/session.d.ts +16 -5
  372. package/dist/core/shell-confinement.d.ts +37 -0
  373. package/dist/core/shell-confinement.js +56 -0
  374. package/dist/core/skill-grant.js +1 -1
  375. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +8 -2
  376. package/dist/core/store-contracts/checkpoint-store-contract.js +83 -2
  377. package/dist/core/store-contracts/file-history-store-contract.d.ts +5 -2
  378. package/dist/core/store-contracts/file-history-store-contract.js +25 -1
  379. package/dist/core/store-contracts/mailbox-store-contract.d.ts +12 -5
  380. package/dist/core/store-contracts/mailbox-store-contract.js +156 -9
  381. package/dist/core/store-contracts/session-store-contract.js +22 -8
  382. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  383. package/dist/core/store-contracts/tool-result-store-contract.js +30 -0
  384. package/dist/core/task-event.d.ts +24 -9
  385. package/dist/core/task-limits.d.ts +5 -0
  386. package/dist/core/task-notification.d.ts +89 -12
  387. package/dist/core/task-notification.js +89 -14
  388. package/dist/core/task-registry-agent.d.ts +32 -50
  389. package/dist/core/task-registry-agent.js +36 -56
  390. package/dist/core/task-registry-monitor.d.ts +1 -1
  391. package/dist/core/task-registry-monitor.js +15 -60
  392. package/dist/core/task-registry-shared.d.ts +22 -112
  393. package/dist/core/task-registry-shared.js +3 -41
  394. package/dist/core/task-registry-workflow.js +5 -21
  395. package/dist/core/task-registry.d.ts +32 -62
  396. package/dist/core/task-registry.js +30 -110
  397. package/dist/core/task-result.d.ts +29 -12
  398. package/dist/core/task-spec-members.d.ts +39 -0
  399. package/dist/core/task-spec-members.js +92 -0
  400. package/dist/core/task-spec.d.ts +11 -11
  401. package/dist/core/task-tool-shape.d.ts +7 -57
  402. package/dist/core/task-tool-shape.js +7 -66
  403. package/dist/core/terminal-cause.d.ts +36 -6
  404. package/dist/core/terminal-cause.js +1 -0
  405. package/dist/core/tool-catalog-entries.js +2 -5
  406. package/dist/core/tool-check-reading.js +16 -10
  407. package/dist/core/tool-conformance.js +1 -2
  408. package/dist/core/tool-errors.d.ts +6 -3
  409. package/dist/core/tool-errors.js +2 -0
  410. package/dist/core/tool-face-reader.js +3 -2
  411. package/dist/core/tool-face.d.ts +8 -5
  412. package/dist/core/tool-face.js +1 -1
  413. package/dist/core/tool-name-aliases.d.ts +5 -29
  414. package/dist/core/tool-name-aliases.js +9 -5
  415. package/dist/core/tool-name-readings.d.ts +14 -3
  416. package/dist/core/tool-name-readings.js +2 -0
  417. package/dist/core/tool-policy.d.ts +109 -18
  418. package/dist/core/tool-policy.js +84 -14
  419. package/dist/core/tool-result-store.d.ts +23 -0
  420. package/dist/core/tool-result-store.js +3 -2
  421. package/dist/core/tool-roster.d.ts +4 -4
  422. package/dist/core/tool-spec.d.ts +23 -6
  423. package/dist/core/trace.d.ts +18 -1
  424. package/dist/core/types.d.ts +1 -1
  425. package/dist/core/types.js +1 -1
  426. package/dist/core/user-attachment.js +26 -21
  427. package/dist/core/workflow-journal-store.d.ts +1 -1
  428. package/dist/core/workflow-run-store.d.ts +2 -0
  429. package/dist/core/workflow-run-store.js +6 -5
  430. package/dist/core/workflow-settled-run.d.ts +5 -0
  431. package/dist/core/workflow-settled-run.js +7 -0
  432. package/dist/engine/execution-env/node-execution-env.d.ts +37 -9
  433. package/dist/engine/execution-env/node-execution-env.js +221 -22
  434. package/dist/engine/harness/agent-harness.d.ts +65 -18
  435. package/dist/engine/harness/agent-harness.js +90 -23
  436. package/dist/engine/harness/messages.d.ts +4 -3
  437. package/dist/engine/harness/messages.js +2 -2
  438. package/dist/engine/harness/types.d.ts +52 -7
  439. package/dist/engine/llm/media-removed.d.ts +14 -0
  440. package/dist/engine/llm/media-removed.js +9 -0
  441. package/dist/engine/llm/rejected-images.d.ts +35 -25
  442. package/dist/engine/llm/rejected-images.js +59 -10
  443. package/dist/engine/llm/types.d.ts +24 -3
  444. package/dist/engine/llm/types.js +7 -3
  445. package/dist/engine/loop/agent-loop.d.ts +6 -1
  446. package/dist/engine/loop/agent-loop.js +20 -11
  447. package/dist/engine/loop/types.d.ts +12 -3
  448. package/dist/engine/session/import-validate.js +7 -0
  449. package/dist/engine/session/parent-chain-guard.d.ts +3 -3
  450. package/dist/engine/session/parent-chain-guard.js +1 -1
  451. package/dist/engine/session/path-to-root.d.ts +18 -3
  452. package/dist/engine/session/path-to-root.js +15 -1
  453. package/dist/engine/session/repo-utils.d.ts +12 -1
  454. package/dist/engine/session/repo-utils.js +41 -0
  455. package/dist/engine/session/session.js +1 -1
  456. package/dist/engine/session/storage-base.d.ts +20 -0
  457. package/dist/engine/session/storage-base.js +28 -9
  458. package/dist/fixtures/index.d.ts +7 -5
  459. package/dist/fixtures/index.js +5 -3
  460. package/dist/index.d.ts +29 -18
  461. package/dist/index.js +19 -11
  462. package/dist/internal/harness-types.d.ts +2 -0
  463. package/dist/internal/harness.d.ts +4 -3
  464. package/dist/internal/harness.js +3 -2
  465. package/dist/internal/llm.d.ts +2 -1
  466. package/dist/internal/llm.js +1 -0
  467. package/dist/orchestration/goal.d.ts +6 -2
  468. package/dist/orchestration/goal.js +6 -3
  469. package/dist/orchestration/run-workflow-tool.d.ts +14 -17
  470. package/dist/orchestration/run-workflow-tool.js +43 -50
  471. package/dist/orchestration/workflow-types.d.ts +2 -2
  472. package/dist/orchestration/workflow.d.ts +7 -0
  473. package/dist/orchestration/workflow.js +10 -12
  474. package/dist/stores/file/background-agent-store.js +18 -15
  475. package/dist/stores/file/checkpoint-store.d.ts +2 -0
  476. package/dist/stores/file/checkpoint-store.js +13 -9
  477. package/dist/stores/file/file-history-store.js +3 -2
  478. package/dist/stores/file/fs-atomic.d.ts +0 -22
  479. package/dist/stores/file/fs-atomic.js +0 -17
  480. package/dist/stores/file/index.d.ts +7 -12
  481. package/dist/stores/file/index.js +25 -12
  482. package/dist/stores/file/ledger-tuning.d.ts +23 -0
  483. package/dist/stores/file/ledger-tuning.js +21 -0
  484. package/dist/stores/file/mailbox-store.js +42 -22
  485. package/dist/stores/file/memory-store.js +3 -2
  486. package/dist/stores/file/permission-rule-adopt.js +24 -21
  487. package/dist/stores/file/permission-rule-store.js +6 -3
  488. package/dist/stores/file/session-policy-store.js +3 -2
  489. package/dist/stores/file/session-store.d.ts +26 -7
  490. package/dist/stores/file/session-store.js +59 -35
  491. package/dist/stores/file/tool-result-store.d.ts +11 -0
  492. package/dist/stores/file/tool-result-store.js +57 -3
  493. package/dist/stores/file/usage-window-store.js +3 -2
  494. package/dist/stores/file/workflow-journal-store.d.ts +0 -2
  495. package/dist/stores/file/workflow-journal-store.js +3 -18
  496. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  497. package/dist/stores/file/workflow-run-store.js +15 -10
  498. package/dist/tools/fs/bash-program-position.d.ts +3 -2
  499. package/dist/tools/fs/bash-program-position.js +7 -7
  500. package/dist/tools/fs/dead-cwd.d.ts +5 -5
  501. package/dist/tools/fs/dead-cwd.js +4 -11
  502. package/dist/tools/fs/fs-bash-background-text.d.ts +6 -0
  503. package/dist/tools/fs/fs-bash-background-text.js +6 -0
  504. package/dist/tools/fs/fs-bash.d.ts +3 -18
  505. package/dist/tools/fs/fs-bash.js +37 -124
  506. package/dist/tools/fs/fs-pdf.js +8 -6
  507. package/dist/tools/fs/fs-read.js +2 -2
  508. package/dist/tools/fs/fs-shared.d.ts +28 -3
  509. package/dist/tools/fs/fs-shared.js +15 -0
  510. package/dist/tools/fs/index.d.ts +1 -1
  511. package/dist/tools/fs/index.js +4 -14
  512. package/dist/tools/fs/pdf.d.ts +4 -4
  513. package/dist/tools/fs/pdf.js +6 -6
  514. package/dist/tools/fs/read-deny-home.js +8 -1
  515. package/dist/tools/fs/read-deny.d.ts +26 -2
  516. package/dist/tools/fs/read-deny.js +9 -2
  517. package/dist/tools/fs/read-floor.d.ts +13 -5
  518. package/dist/tools/fs/read-floor.js +206 -2
  519. package/dist/tools/fs/removal-targets.js +2 -2
  520. package/dist/tools/fs/search.d.ts +3 -2
  521. package/dist/tools/fs/search.js +6 -6
  522. package/dist/tools/fs/shell-read-argv.d.ts +4 -2
  523. package/dist/tools/fs/shell-read-argv.js +14 -3
  524. package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
  525. package/dist/tools/fs/shell-read-bindings.js +148 -68
  526. package/dist/tools/fs/shell-read-check.js +20 -4
  527. package/dist/tools/fs/shell-read-establish.js +25 -9
  528. package/dist/tools/fs/shell-read-functions.js +2 -2
  529. package/dist/tools/fs/shell-read-identity.d.ts +3 -1
  530. package/dist/tools/fs/shell-read-identity.js +4 -2
  531. package/dist/tools/fs/shell-read-judge.d.ts +7 -1
  532. package/dist/tools/fs/shell-read-judge.js +1 -1
  533. package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
  534. package/dist/tools/fs/shell-read-object-path.js +119 -0
  535. package/dist/tools/fs/shell-read-plan.d.ts +8 -0
  536. package/dist/tools/fs/shell-read-plan.js +47 -30
  537. package/dist/tools/fs/shell-read-start.d.ts +66 -13
  538. package/dist/tools/fs/shell-read-start.js +89 -17
  539. package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
  540. package/dist/tools/fs/shell-read-workdir.js +31 -8
  541. package/dist/tools/monitor.d.ts +8 -7
  542. package/dist/tools/monitor.js +12 -10
  543. package/dist/tools/worktree.d.ts +5 -1
  544. package/dist/tools/worktree.js +20 -17
  545. package/package.json +6 -3
  546. package/test/export-surface.snapshot.json +112 -42
  547. package/wire-changes/core-stores-sql@7.61.0.json +480 -0
  548. package/wire-changes/core-stores-sql@7.62.0.json +30 -0
  549. package/wire-changes/core@7.61.0.json +4405 -0
  550. package/wire-changes/core@7.62.0.json +2181 -0
  551. package/wire-changes/mods-kernel@7.61.0.json +65 -0
  552. package/wire-changes/mods-kernel@7.62.0.json +42 -0
  553. package/wire-changes/primitives@7.61.0.json +30 -0
  554. package/wire-changes/primitives@7.62.0.json +30 -0
  555. package/dist/core/consolidate-scope.d.ts +0 -93
  556. package/dist/core/consolidate-scope.js +0 -98
  557. package/dist/core/runner/image-removed-seat.d.ts +0 -12
  558. package/dist/core/runner/image-removed-seat.js +0 -19
  559. package/dist/core/runner/memory-consolidation.d.ts +0 -109
  560. package/dist/core/runner/memory-consolidation.js +0 -251
@@ -3,9 +3,11 @@
3
3
  * event over it. Every method's bottom is a seat the engine already has; each method's limits are part of
4
4
  * its contract and are checked here (a refused input is the caller's throw, "(host check)").
5
5
  */
6
- import type { ExecutionEnv } from "../../internal/harness-types.js";
6
+ import type { AgentMessage, ExecutionEnv } from "../../internal/harness-types.js";
7
7
  import type { Context, Message, Usage } from "../../internal/llm.js";
8
+ import type { CompactOutcome } from "../task-event.js";
8
9
  import type { ModDollarBase, ModMethodBottoms } from "./kernel/index.js";
10
+ import type { ContextOccupancy } from "./lifecycle-stations.js";
9
11
  /** `$.process.run`'s default command timeout (CC). */
10
12
  export declare const PROCESS_RUN_DEFAULT_TIMEOUT_MS = 30000;
11
13
  /** `$.process.run`'s largest command timeout (CC). */
@@ -54,13 +56,30 @@ export interface ModSeatView {
54
56
  cwd(): string;
55
57
  root(): string;
56
58
  model(): string;
59
+ /** The leg's messages as the model last saw them. */
57
60
  messages(): readonly Message[];
61
+ /** A subagent's stored transcript rows, read through the leg's own task list row for it; rejects with the reason when the
62
+ * leg reaches no such row, the row has no session, or the session cannot be read. */
63
+ agentMessages(agentId: string): Promise<readonly AgentMessage[]>;
64
+ /** How many prompts the session's transcript holds from its people (`promptCountOf`, `session-append.ts`). */
65
+ turns(): Promise<number>;
66
+ usage(): SessionUsage;
67
+ version(): SessionVersion;
58
68
  };
59
69
  /** The deployment clock (`RunnerDeps.now`). */
60
70
  now(): number;
61
71
  tools(): readonly string[];
62
72
  agents(): readonly string[];
63
73
  }
74
+ /** `$.session.usage()`: the leg's latest turn-boundary measurement — the context occupancy the boundary's `context_usage`
75
+ * frame carries, absent before the leg's first boundary (a session-level pass measures none). */
76
+ export interface SessionUsage {
77
+ readonly context?: ContextOccupancy;
78
+ }
79
+ /** `$.session.version()`: the engine's package version. */
80
+ export interface SessionVersion {
81
+ readonly version: string;
82
+ }
64
83
  export interface ProcessRunResult {
65
84
  readonly stdout: string;
66
85
  readonly stderr: string;
@@ -90,7 +109,43 @@ export interface EngineDollar extends ModDollarBase {
90
109
  cwd(): Promise<string>;
91
110
  root(): Promise<string>;
92
111
  model(): Promise<string>;
112
+ /** The leg's messages as the model last saw them (the newest {@link SESSION_MESSAGES_MAX}, copies). */
93
113
  messages(): Promise<readonly Message[]>;
114
+ /** `$.session.messages({ agentId })`: a subagent's stored transcript rows (the newest {@link SESSION_MESSAGES_MAX}, copies),
115
+ * read through this leg's own task list row for that agent; rejects with the reason when this leg reaches no such row, the
116
+ * row has no session, or the session cannot be read. */
117
+ messages(args: {
118
+ readonly agentId: string;
119
+ }): Promise<readonly AgentMessage[]>;
120
+ /** `$.session.turns()`: how many prompts the session's transcript holds from its people (a steer is not one). */
121
+ turns(): Promise<number>;
122
+ /** `$.session.usage()`: the leg's latest turn-boundary measurement. */
123
+ usage(): Promise<SessionUsage>;
124
+ /** `$.session.version()`: the engine's package version. */
125
+ version(): Promise<SessionVersion>;
126
+ /** `$.session.append({ message: { role: "user", content }, agentId? })`: an extension's own note, admitted at the
127
+ * `session.append` station (`session-append.ts`). */
128
+ append(args: {
129
+ readonly message: {
130
+ readonly role: "user";
131
+ readonly content: string | readonly {
132
+ readonly type: "text";
133
+ readonly text: string;
134
+ }[];
135
+ };
136
+ readonly agentId?: string;
137
+ }): Promise<SessionAppendAnswer>;
138
+ /** `$.session.send({ to, text })`: the leg's SendMessage, run as the caller's own call and raised once at the
139
+ * `session.send` station (`session-send.ts`). */
140
+ send(args: {
141
+ readonly to: string;
142
+ readonly text: string;
143
+ }): Promise<SessionSendAnswer>;
144
+ /** `$.session.compact({ instructions? })`: a manual compaction pass at the turn boundary, in place — from a handler of
145
+ * `turn.complete` only (`session-compact.ts`). */
146
+ compact(args?: {
147
+ readonly instructions?: string;
148
+ }): Promise<SessionCompactAnswer>;
94
149
  };
95
150
  readonly clock: {
96
151
  now(): Promise<number>;
@@ -107,8 +162,26 @@ export interface EngineDollar extends ModDollarBase {
107
162
  };
108
163
  readonly agent: {
109
164
  list(): Promise<readonly string[]>;
165
+ /** `$.agent.spawn({ prompt, ... })`: the delegation tool's own pipeline as the caller's call, the subagent in the background
166
+ * (`createAgentSpawnEntry`, `agent-stations.ts`). */
167
+ spawn(args: {
168
+ readonly prompt: string;
169
+ readonly description?: string;
170
+ readonly subagentType?: string;
171
+ readonly model?: string;
172
+ readonly name?: string;
173
+ readonly cwd?: string;
174
+ }): Promise<AgentSpawnAnswer>;
110
175
  };
111
176
  }
177
+ /** What `$.agent.spawn` answers: the subagent started (`agentId`, the id its events carry; `model`, as `agent.spawn`'s bottom
178
+ * names it), none started because an extension answered the call in place of its body (`model` alone), or the refusal. */
179
+ export type AgentSpawnAnswer = {
180
+ readonly model: string;
181
+ readonly agentId?: string;
182
+ } | {
183
+ readonly deny: string;
184
+ };
112
185
  /** What `$.tool.call` answers — `tool.call`'s own forms: the frozen view of the call's result, or the refusal (returned, not thrown). */
113
186
  export type ToolCallAnswer = {
114
187
  readonly result: {
@@ -118,5 +191,25 @@ export type ToolCallAnswer = {
118
191
  } | {
119
192
  readonly deny: string;
120
193
  };
194
+ /** What `$.session.append` answers — `session.append`'s own forms: the note as kept (a frozen view), or the refusal (returned, not thrown). */
195
+ export type SessionAppendAnswer = {
196
+ readonly message: {
197
+ readonly role: "user";
198
+ readonly content: string | readonly object[];
199
+ };
200
+ } | {
201
+ readonly deny: string;
202
+ };
203
+ /** What `$.session.send` answers — `session.send`'s own forms: delivered, or not and why (returned, not thrown). */
204
+ export type SessionSendAnswer = {
205
+ readonly isDelivered: true;
206
+ } | {
207
+ readonly isDelivered: false;
208
+ readonly reason: string;
209
+ };
210
+ /** What `$.session.compact` answers: the in-place pass's outcome (a call it refuses throws, its reason on the report sink too). */
211
+ export interface SessionCompactAnswer {
212
+ readonly outcome: CompactOutcome;
213
+ }
121
214
  /** The chain bottoms of the wave-one method events over a runner's seat view. */
122
215
  export declare function engineMethodBottoms(view: ModSeatView): ModMethodBottoms;
@@ -132,6 +132,15 @@ function detachedMessage(m) {
132
132
  throw refuse("session.messages", "a session message could not be copied; the history is not handed out live");
133
133
  }
134
134
  }
135
+ function sessionMessages(view, args) {
136
+ only(args, "session.messages", ["agentId"]);
137
+ const agentId = args["agentId"];
138
+ if (agentId === undefined)
139
+ return Object.freeze(view.session.messages().slice(-SESSION_MESSAGES_MAX).map(detachedMessage));
140
+ if (typeof agentId !== "string" || agentId === "")
141
+ throw refuse("session.messages", `takes agentId, a non-empty string (got ${typeof agentId === "string" ? "an empty string" : typeof agentId})`);
142
+ return view.session.agentMessages(agentId).then((rows) => Object.freeze(rows.slice(-SESSION_MESSAGES_MAX).map(detachedMessage)));
143
+ }
135
144
  const read = (event, f) => (args) => {
136
145
  only(args, event, []);
137
146
  return f();
@@ -145,7 +154,10 @@ export function engineMethodBottoms(view) {
145
154
  "session.cwd": run(read("session.cwd", () => view.session.cwd())),
146
155
  "session.root": run(read("session.root", () => view.session.root())),
147
156
  "session.model": run(read("session.model", () => view.session.model())),
148
- "session.messages": run(read("session.messages", () => Object.freeze(view.session.messages().slice(-SESSION_MESSAGES_MAX).map(detachedMessage)))),
157
+ "session.messages": run((args) => sessionMessages(view, args)),
158
+ "session.turns": run(read("session.turns", () => view.session.turns())),
159
+ "session.usage": run(read("session.usage", () => view.session.usage())),
160
+ "session.version": run(read("session.version", () => view.session.version())),
149
161
  "clock.now": run(read("clock.now", () => view.now())),
150
162
  "clock.sleep": run((args, ctx) => sleep(args, ctx)),
151
163
  "tool.list": run(read("tool.list", () => Object.freeze([...view.tools()]))),
@@ -1,16 +1,28 @@
1
1
  import { type ModBottomContext, type ModBus } from "./kernel/index.js";
2
2
  import type { ExtensionRequester } from "../task-event.js";
3
+ /** Which `$` call made the record: the door the extension came through. */
4
+ export type ExtensionDoor = "tool.call" | "agent.spawn";
3
5
  /** One extension's call while it runs. */
4
6
  export interface ExtensionCall {
5
7
  /** The leg bus the call was made on (the one {@link legBusOf} returned). */
6
8
  readonly bus: ModBus;
7
9
  readonly toolCallId: string;
10
+ /** The door: an extension's spawn is a record made by `$.agent.spawn` — a tool an extension calls through `$.tool.call` that
11
+ * runs the delegation inside its own body hands the delegation a tool call's record, and the delegation runs as it would
12
+ * for the model. */
13
+ readonly door: ExtensionDoor;
8
14
  /** The `$` call's context: the frames its pipeline's events are raised under, and its origin. */
9
15
  readonly caller: ModBottomContext;
10
16
  /** Cleared when the call's pipeline settles — the one reading of "this call is still running". */
11
17
  readonly live: boolean;
12
18
  /** The call's end projection refused it (its latest gate record is a refusal) — written once, by the leg's tool_end station. */
13
19
  readonly denied: boolean;
20
+ /** The subagent the call started (`$.agent.spawn`): its id and the model it was let start on — written once, by the delegation
21
+ * tool where it lets the subagent run; absent ⇒ none started (the call's result is never read for it). */
22
+ readonly launched?: {
23
+ readonly agentId: string;
24
+ readonly model: string;
25
+ };
14
26
  }
15
27
  /** The running extension call this chain carries for `bus`, when it is the call `toolCallId` names (or any, unnamed). */
16
28
  export declare function extensionCallOf(bus: object, toolCallId?: string): ExtensionCall | undefined;
@@ -21,8 +33,10 @@ export declare function requesterOf(bus: object, toolCallId: string): {
21
33
  };
22
34
  /** 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
35
  export declare function noteExtensionCallDenied(bus: object, toolCallId: string): void;
36
+ /** The delegation tool says the extension's spawn it is running started its subagent (a no-op for any other call). */
37
+ export declare function noteExtensionCallLaunched(bus: object, toolCallId: string, launched: NonNullable<ExtensionCall["launched"]>): void;
24
38
  /** 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>;
39
+ export declare function runExtensionCall<T>(bus: ModBus, toolCallId: string, door: ExtensionDoor, caller: ModBottomContext, pipeline: (call: ExtensionCall) => Promise<T>): Promise<T>;
26
40
  /**
27
41
  * The leg bus every station raises on: a dispatch inside a running extension call made on it is raised under that call's
28
42
  * frames and origin (a raiser that names its own frames keeps them — they extend the call's); one raised under a call
@@ -14,8 +14,13 @@ export function noteExtensionCallDenied(bus, toolCallId) {
14
14
  if (c !== undefined && c.live && c.bus === bus && c.toolCallId === toolCallId)
15
15
  c.denied = true;
16
16
  }
17
- export async function runExtensionCall(bus, toolCallId, caller, pipeline) {
18
- const call = { bus, toolCallId, caller, live: true, denied: false };
17
+ export function noteExtensionCallLaunched(bus, toolCallId, launched) {
18
+ const c = store.getStore();
19
+ if (c !== undefined && c.live && c.bus === bus && c.toolCallId === toolCallId && c.launched === undefined)
20
+ c.launched = Object.freeze({ agentId: launched.agentId, model: launched.model });
21
+ }
22
+ export async function runExtensionCall(bus, toolCallId, door, caller, pipeline) {
23
+ const call = { bus, toolCallId, door, caller, live: true, denied: false };
19
24
  try {
20
25
  return await store.run(call, () => pipeline(call));
21
26
  }
@@ -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 ModAnswerRanks, type ModEventPayload, type ModFailureCause, type ModMatcher, type ModSkip, type ProxyProbe } from "./site-rules.js";
3
+ import { type ModAnswerCheck, type ModAnswerer, 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";
@@ -73,8 +73,9 @@ export interface ModDispatchOptions {
73
73
  /** The raiser's reading of an answer; an answer it refuses is a violation of the site. */
74
74
  readonly checkAnswer?: ModAnswerCheck;
75
75
  /** The raiser's reading of what a handler hands on (a payload other than the dispatch's own `e`, received, its pinned keys
76
- * judged); a payload it refuses is a violation of the site — the other direction of {@link checkAnswer}. */
77
- readonly checkHandOn?: (payload: ModEventPayload) => string | undefined;
76
+ * judged), with the handler that hands it on; a payload it refuses is a violation of the site — the other direction of
77
+ * {@link checkAnswer}. */
78
+ readonly checkHandOn?: (payload: ModEventPayload, by: ModAnswerer) => string | undefined;
78
79
  /** The station's ranking of its answers — named by every dispatch of an event whose failure column refuses (one that
79
80
  * names none is not run), and read by the seat-trust law. */
80
81
  readonly ranks?: ModAnswerRanks;
@@ -371,13 +371,13 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
371
371
  let found;
372
372
  return () => (found ??= sealedObjects([e0]));
373
373
  })();
374
- const handOn = (passed) => {
374
+ const handOn = (passed, h) => {
375
375
  if (passed === e0)
376
376
  return { snap: e0 };
377
377
  const handed = handedOn(st.pinned, e0, passed, engines(), isProxy);
378
378
  if ("violation" in handed)
379
379
  return handed;
380
- const why = handOnViolation(handed.payload, options.checkHandOn);
380
+ const why = handOnViolation(handed.payload, options.checkHandOn, answererOf(h));
381
381
  return why !== undefined ? { violation: why } : { snap: handed.payload };
382
382
  };
383
383
  const trustFloors = new Map();
@@ -516,7 +516,7 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
516
516
  state.violated ??= "next() already called (a handler calls next once; its first run's answer stands)";
517
517
  return Promise.reject(new Error(`${name}: next() already called`));
518
518
  }
519
- const handed = handOn(passed);
519
+ const handed = handOn(passed, h);
520
520
  if ("violation" in handed) {
521
521
  state.violated ??= handed.violation;
522
522
  return Promise.reject(new Error(`${name}: ${state.violated}`));
@@ -634,7 +634,7 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
634
634
  running.then(resume, resume);
635
635
  return running;
636
636
  }
637
- const handed = handOn(passed);
637
+ const handed = handOn(passed, h);
638
638
  if ("violation" in handed) {
639
639
  violated ??= handed.violation;
640
640
  return Promise.reject(new Error(`${h.reg.name}: ${violated}`));
@@ -30,8 +30,16 @@
30
30
  * go, before its subagent starts — every argument pinned, a refusal its only answer), `turn.complete` (a model turn ended)
31
31
  * and `session.end` (a leg ended) have stations; `tool.call`'s failure column is `refuse` — a failure once the body has
32
32
  * started withholds the result (under `refuse_until_run`, its column until 5, the result stood).
33
+ * 7: `session.receive` (a frame arriving for the model), `session.append` (a row entering the conversation), `session.send` (a
34
+ * message the leg sends) and `session.compact` (a compaction about to run) have stations; `agent.spawn` has a `call` column,
35
+ * and so do `session.append`, `session.send` and `session.compact` — a `$` call of each reaches the host's entry.
36
+ * 8: the closed set is the reference's 145 names (`session.identity`, `ui.view`, `prompt.change` named, not raised);
37
+ * `session.start` (a leg opened), `session.measure` (the leg's context occupancy moved), `turn.start` (a model turn began),
38
+ * `prompt.submit` (a person's input entering the leg — rewritable, droppable, refused on a failure), `classic.SessionStart` and
39
+ * `classic.SessionEnd` have stations, the two classic ones raised in the bottoms of `session.start` and `session.end`; the
40
+ * methods `session.turns`, `session.usage` and `session.version` have bottoms, and `session.messages` takes `{ agentId }`.
33
41
  */
34
- export declare const KERNEL_CONTRACT_VERSION = 6;
42
+ export declare const KERNEL_CONTRACT_VERSION = 8;
35
43
  /** The five tiers in run order (CC names). `builtin` and `core` are the engine's own. */
36
44
  export declare const MOD_TIERS: readonly ["prepend", "user", "append", "builtin", "core"];
37
45
  export type ModTier = (typeof MOD_TIERS)[number];
@@ -108,8 +116,8 @@ export interface ModEventRow {
108
116
  readonly station?: ModStation;
109
117
  }
110
118
  /**
111
- * 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,
112
- * its 46 engine events and its 63 `$` methods, in its own order). The shell's names (`ui.*`, `command.*`,
119
+ * Every event the kernel knows: the reference's closed set of 145 names (CC 2.1.309 `_De` (cli309.js:253322) — its 33 `classic.*` names,
120
+ * its 47 engine events and its 65 `$` methods, in its own order). The shell's names (`ui.*`, `command.*`,
113
121
  * `config.*`, `audio.*`, the prompt-box events and `prompt.read`) carry `side: "surface"`: one table serves both
114
122
  * buses, and the shell's stations are its rows here, raised by the shell where their chain bottoms are. A row with a
115
123
  * station is raised on its side in this version; a name with none is named, not raised, and a registration that
@@ -166,6 +174,7 @@ export declare const MOD_EVENT_TABLE: Readonly<{
166
174
  "prompt.fill": ModEventRow;
167
175
  "prompt.suggest": ModEventRow;
168
176
  "prompt.edit": ModEventRow;
177
+ "prompt.change": ModEventRow;
169
178
  "prompt.autocomplete": ModEventRow;
170
179
  "prompt.section": ModEventRow;
171
180
  "prompt.context": ModEventRow;
@@ -215,6 +224,7 @@ export declare const MOD_EVENT_TABLE: Readonly<{
215
224
  "session.surface": ModEventRow;
216
225
  "session.surfaces": ModEventRow;
217
226
  "session.authorize": ModEventRow;
227
+ "session.identity": ModEventRow;
218
228
  "session.usage": ModEventRow;
219
229
  "session.version": ModEventRow;
220
230
  "turn.abort": ModEventRow;
@@ -237,6 +247,7 @@ export declare const MOD_EVENT_TABLE: Readonly<{
237
247
  "ui.panes": ModEventRow;
238
248
  "ui.selection": ModEventRow;
239
249
  "ui.copy": ModEventRow;
250
+ "ui.view": ModEventRow;
240
251
  "ui.notify": ModEventRow;
241
252
  "ui.blit": ModEventRow;
242
253
  "fs.read": ModEventRow;
@@ -1,4 +1,4 @@
1
- export const KERNEL_CONTRACT_VERSION = 6;
1
+ export const KERNEL_CONTRACT_VERSION = 8;
2
2
  export const MOD_TIERS = Object.freeze(["prepend", "user", "append", "builtin", "core"]);
3
3
  export const MOD_SEATS = Object.freeze(["deployment", "task"]);
4
4
  export const MOD_EVENT_SIDES = Object.freeze(["engine", "surface", "both"]);
@@ -55,8 +55,8 @@ export const MOD_EVENT_TABLE = Object.freeze({
55
55
  "classic.Notification": engine(),
56
56
  "classic.UserPromptSubmit": engine(station("refuse", "immediate", ["source", "inputId", "actor", "prompt"])),
57
57
  "classic.UserPromptExpansion": engine(),
58
- "classic.SessionStart": engine(),
59
- "classic.SessionEnd": engine(),
58
+ "classic.SessionStart": engine(station("skip", "grace")),
59
+ "classic.SessionEnd": engine(station("skip", "grace")),
60
60
  "classic.Stop": engine(station("skip", "immediate")),
61
61
  "classic.StopFailure": engine(station("skip", "grace")),
62
62
  "classic.SubagentStart": engine(station("skip", "immediate", ["agentId", "agentType"])),
@@ -93,11 +93,12 @@ export const MOD_EVENT_TABLE = Object.freeze({
93
93
  "ui.scroll": surface(station("skip", "grace", ["component", "requestId", "by", "bodyRows", "contentRows", "origin", "pointer"], { call: true })),
94
94
  "ui.focus": surface(station("skip", "grace", ["component", "requestId", "plugin", "origin", "element"], { call: true })),
95
95
  "agent.offer": engine(station("skip", "grace", ["agent", "provider"])),
96
- "agent.spawn": engine(station("refuse_until_run", "immediate", AGENT_SPAWN_PINNED)),
97
- "prompt.submit": engine(),
96
+ "agent.spawn": engine(station("refuse_until_run", "immediate", AGENT_SPAWN_PINNED, { call: true })),
97
+ "prompt.submit": engine(station("refuse", "immediate", ["source", "inputId", "actor"])),
98
98
  "prompt.fill": surface(station("skip", "grace", ["origin", "mode"], { call: true })),
99
99
  "prompt.suggest": surface(station("skip", "grace", ["origin"], { call: true })),
100
100
  "prompt.edit": surface(station("skip", "grace", ["origin", "key"], { budgetMs: PROMPT_EDIT_BUDGET_MS })),
101
+ "prompt.change": surface(),
101
102
  "prompt.autocomplete": surface(),
102
103
  "prompt.section": engine(station("skip", "grace", ["name", "key", "mountedTools"])),
103
104
  "prompt.context": engine(),
@@ -113,17 +114,17 @@ export const MOD_EVENT_TABLE = Object.freeze({
113
114
  "telemetry.mark": engine(),
114
115
  "skill.prompt": engine(),
115
116
  "attribution.text": engine(),
116
- "session.start": engine(),
117
- "session.receive": engine(),
118
- "session.append": engine(),
119
- "session.send": engine(),
120
- "session.compact": engine(),
117
+ "session.start": engine(station("skip", "grace", ["cwd", "sessionId", "agentId"])),
118
+ "session.receive": engine(station("refuse", "immediate", ["origin", "event", "agentId"])),
119
+ "session.append": engine(station("skip", "grace", ["door", "origin", "agentId"], { call: true })),
120
+ "session.send": engine(station("refuse_until_run", "immediate", ["origin", "agentId", "to", "text"], { call: true })),
121
+ "session.compact": engine(station("refuse_until_run", "immediate", ["trigger", "agentId", "instructions"], { call: true })),
121
122
  "session.attach": engine(),
122
123
  "session.detach": engine(),
123
- "session.measure": engine(),
124
+ "session.measure": engine(station("skip", "grace", ["context", "changed", "agentId"])),
124
125
  "session.end": engine(station("skip", "grace", ["reason", "sessionId", "agentId"])),
125
126
  "plugin.register": Object.freeze({ side: "both", station: station("refuse", "immediate", ["name", "seat", "tier", "uses"]) }),
126
- "turn.start": engine(),
127
+ "turn.start": engine(station("skip", "grace", ["turn", "agentId"])),
127
128
  "turn.step": engine(),
128
129
  "turn.complete": engine(station("skip", "grace", ["answer", "agentId", "turn"])),
129
130
  "engine.create": engine(),
@@ -137,15 +138,16 @@ export const MOD_EVENT_TABLE = Object.freeze({
137
138
  "session.cwd": engine(method(true)),
138
139
  "session.root": engine(method(true)),
139
140
  "session.model": engine(method(true)),
140
- "session.turns": engine(),
141
+ "session.turns": engine(method(true)),
141
142
  "session.id": engine(method(true)),
142
143
  "session.messages": engine(method(true)),
143
144
  "session.repo": engine(),
144
145
  "session.surface": engine(),
145
146
  "session.surfaces": engine(),
146
147
  "session.authorize": engine(),
147
- "session.usage": engine(),
148
- "session.version": engine(),
148
+ "session.identity": engine(),
149
+ "session.usage": engine(method(true)),
150
+ "session.version": engine(method(true)),
149
151
  "turn.abort": engine(),
150
152
  "prompt.read": surface(method(true)),
151
153
  "flag.value": engine(),
@@ -166,6 +168,7 @@ export const MOD_EVENT_TABLE = Object.freeze({
166
168
  "ui.panes": surface(),
167
169
  "ui.selection": surface(method(true)),
168
170
  "ui.copy": surface(method(true)),
171
+ "ui.view": surface(),
169
172
  "ui.notify": surface(),
170
173
  "ui.blit": surface(),
171
174
  "fs.read": engine(),
@@ -23,6 +23,9 @@ export interface ModOrigin {
23
23
  }
24
24
  /** The engine's own origin; its `plugin` word is reserved (no registration may take it). */
25
25
  export declare const ENGINE_ORIGIN: ModOrigin;
26
+ /** The form of a registration name: 1–64 of letters, digits, `.`, `_`, `:` and `-` (`:` is the separator of the `skill:<name>` spelling a skill's registrations use). The one rule — a name reaches sentences a person or
27
+ * a model reads (`extension "<name>"`), so a name that could quote, bracket or fold a sentence is refused where it enters. */
28
+ export declare const MOD_REGISTRATION_NAME: RegExp;
26
29
  /** The extension a refusal names: the registration's own name — never the engine's origin word (a raise the engine could not run
27
30
  * names no extension), never an absent one. The one reading of "who refused" for every station that refuses a call at the hook
28
31
  * layer (`GateDisposition.extension`). Module-level: not part of the kernel's entry. */
@@ -3,6 +3,7 @@ import { resolveModBudgetMs } from "./budget.js";
3
3
  export const MODS_INVALID_CODE = "config.mods_invalid";
4
4
  export const MODS_REGISTRATION_REFUSED_CODE = "mods.registration_refused";
5
5
  export const ENGINE_ORIGIN = Object.freeze({ plugin: "engine", tier: "core" });
6
+ export const MOD_REGISTRATION_NAME = /^[A-Za-z0-9._:-]{1,64}$/;
6
7
  export function namedRegistration(registration) {
7
8
  return registration === undefined || registration === ENGINE_ORIGIN.plugin ? undefined : registration;
8
9
  }
@@ -37,8 +38,12 @@ function screenOne(item, seat, side, report) {
37
38
  if (!isRegistration(item))
38
39
  throw modsInvalid(`a ${seat} mods entry is ${describe(item)}; a registration has a name and a register function`);
39
40
  const name = item.name;
41
+ if (typeof name !== "string")
42
+ throw modsInvalid(`a ${seat} registration's name is ${describe(name)}; a registration name is a string`);
40
43
  if (name === "")
41
44
  throw modsInvalid(`a ${seat} registration has an empty name`);
45
+ if (!MOD_REGISTRATION_NAME.test(name))
46
+ throw modsInvalid(`a ${seat} registration's name (${name.length} characters) is outside the form of a registration name — 1 to 64 of letters, digits, ".", "_", ":" and "-"`);
42
47
  if (name === ENGINE_ORIGIN.plugin)
43
48
  throw modsInvalid(`a ${seat} registration is named "${name}", the engine's own origin word — choose another name`);
44
49
  const tier = tierOf(item.tier, seat, name);
@@ -74,6 +74,9 @@ export interface PinnedKeyBreak {
74
74
  * ({@link sameModValue}): the engine's own fact handed on as is, or a copy of it, is not a change.
75
75
  */
76
76
  export declare function pinnedKeyChanged(pinned: readonly string[], received: ModEventPayload, passed: ModEventPayload): PinnedKeyBreak | undefined;
77
+ /** Whether `b` is the same data as `a`, by the one comparison a pinned key is judged by ({@link sameModValue}): a copy is the
78
+ * value it copies. A pair the walk cannot finish (past the depth bound, or a read that throws) is not proven the same. */
79
+ export declare function sameModData(a: unknown, b: unknown): boolean;
77
80
  /** {@link engineObjects} of a dispatch's own event, found the first time it is asked and the same set every time after:
78
81
  * the event is frozen, so one finding serves every receipt of the dispatch. */
79
82
  export declare function engineObjectsOnce(held: ModEventPayload): () => ReadonlySet<object>;
@@ -109,9 +112,9 @@ export declare function pinnedHandOn(pinned: readonly string[], held: ModEventPa
109
112
  };
110
113
  /** Why a handler's answer breaks the site, or undefined. No answer at all is never an answer. */
111
114
  export declare function answerViolation(answer: unknown, check: ModAnswerCheck | undefined, e: ModEventPayload, by: ModAnswerer, below: readonly unknown[], run: ModDispatchRun): string | undefined;
112
- /** A station's reading of what a handler hands on: its sentence, or undefined (no check, or the payload passes). A check that
113
- * throws is a sentence too — the station could not read the payload, so it is not handed on. */
114
- export declare function handOnViolation(payload: ModEventPayload, check: ((payload: ModEventPayload) => string | undefined) | undefined): string | undefined;
115
+ /** A station's reading of what a handler hands on (and of who hands it on): its sentence, or undefined (no check, or the
116
+ * payload passes). A check that throws is a sentence too — the station could not read the payload, so it is not handed on. */
117
+ export declare function handOnViolation(payload: ModEventPayload, check: ((payload: ModEventPayload, by: ModAnswerer) => string | undefined) | undefined, by: ModAnswerer): string | undefined;
115
118
  /**
116
119
  * A `$` method's answer form: `{ value }` (the call's result) or `{ deny }` (the call throws). A `{ deny }` given after
117
120
  * the handler's `next` was answered with something that is not a deny — or while that `next` is still running — breaks
@@ -81,6 +81,14 @@ export function pinnedKeyChanged(pinned, received, passed) {
81
81
  const compared = comparePinned(pinned, received, passed);
82
82
  return "broke" in compared ? compared.broke : undefined;
83
83
  }
84
+ export function sameModData(a, b) {
85
+ try {
86
+ return sameModValue(a, b, new Map(), 1, new Map()) !== false;
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
84
92
  function comparePinned(pinned, received, passed) {
85
93
  const paired = new Map();
86
94
  const homes = new Map();
@@ -203,11 +211,11 @@ export function answerViolation(answer, check, e, by, below, run) {
203
211
  return "returned an answer the station cannot read";
204
212
  }
205
213
  }
206
- export function handOnViolation(payload, check) {
214
+ export function handOnViolation(payload, check, by) {
207
215
  if (check === undefined)
208
216
  return undefined;
209
217
  try {
210
- return check(payload);
218
+ return check(payload, by);
211
219
  }
212
220
  catch {
213
221
  return "handed on an event the station cannot read";
@@ -1,13 +1,45 @@
1
1
  /**
2
- * A leg's two lifecycle stations over its bus, both observations (an answer changes nothing, a failure skips the handler).
2
+ * A leg's lifecycle stations over its bus, all observations (an answer changes nothing, a failure skips the handler). Each
3
+ * entry reads first, synchronously, whether its event (or the classic event raised in its bottom) is heard — none ⇒ nothing
4
+ * is raised and nothing is awaited.
5
+ * `session.start`: the leg opened (prepared, before its first model request); `e = { cwd, sessionId, agentId? }`; its bottom
6
+ * raises `classic.SessionStart` with the same `e` and comes up as `{ cwd }`.
7
+ * `turn.start`: a model turn began, before its first model request; `e = { turn, agentId? }` (`turn` = 1 for the leg's first);
8
+ * the bottom comes up as `{ turn }`.
3
9
  * `turn.complete`: the turn's end records it ({@link noteCompletedTurn}); the next await point raises it once
4
10
  * ({@link raiseCompletedTurn}) — the turn boundary after it, or the leg's settle for a turn whose boundary never ran.
5
11
  * `e = { answer, reason, turn, isAborted, agentId?, usage? }`; the bottom comes up as `{ text: answer, usage? }`.
6
- * `session.end`: a leg's terminal settled; `e = { reason, sessionId, agentId? }`, `reason` the terminal status word.
12
+ * `session.measure`: a turn boundary measured the leg's context occupancy and it moved since the last measurement
13
+ * ({@link measureSession} — the one write `$.session.usage` reads); `e = { context, changed, agentId? }`; the bottom comes up as
14
+ * `{ changed }`.
15
+ * `session.end`: a leg's terminal settled; `e = { reason, sessionId, agentId? }`, `reason` the terminal status word; its bottom
16
+ * raises `classic.SessionEnd` with the same `e` and comes up as `{ sessionId }`.
7
17
  */
8
18
  import type { AssistantMessage } from "../../internal/llm.js";
19
+ import type { maybeCompact } from "../auto-compaction.js";
9
20
  import type { HookInvocationIdentity } from "../hooks.js";
10
21
  import { type LegModBus } from "./stations.js";
22
+ /** Raise `session.start` as the leg opens; `undefined` (nothing raised, nothing to await) when neither it nor
23
+ * `classic.SessionStart` is heard. */
24
+ export declare function raiseSessionStart(bus: LegModBus, identity: HookInvocationIdentity | undefined, start: {
25
+ readonly cwd: string;
26
+ readonly sessionId: string;
27
+ }, signal: AbortSignal | undefined): Promise<void> | undefined;
28
+ /** Raise `turn.start` for the turn beginning (`turn` = its number); `undefined` when no handler hangs on it. */
29
+ export declare function raiseStartedTurn(bus: LegModBus, identity: HookInvocationIdentity | undefined, turn: number, signal: AbortSignal | undefined): Promise<void> | undefined;
30
+ /** A leg's context occupancy as a turn boundary measured it: the compaction pass's own `contextUsage` — the three numbers the
31
+ * boundary's `context_usage` frame carries. */
32
+ export type ContextOccupancy = Readonly<NonNullable<Awaited<ReturnType<typeof maybeCompact>>["contextUsage"]>>;
33
+ /** What `session.measure`'s `changed` names: the units that moved (the leg measures one). */
34
+ export declare const SESSION_MEASURE_UNITS: readonly ["context"];
35
+ export type SessionMeasureUnit = (typeof SESSION_MEASURE_UNITS)[number];
36
+ /** Where a leg keeps its latest measurement: written once per boundary by {@link measureSession}, read by `$.session.usage`. */
37
+ export interface SessionMeasureSeat {
38
+ context?: ContextOccupancy;
39
+ }
40
+ /** Record a boundary's measurement on the seat (always), then raise `session.measure` when the occupancy moved since the
41
+ * last one (the first measurement moved from none); `undefined` when nothing is raised. */
42
+ export declare function measureSession(bus: LegModBus, seat: SessionMeasureSeat, measured: ContextOccupancy, identity: HookInvocationIdentity | undefined, signal: AbortSignal | undefined): Promise<void> | undefined;
11
43
  /** Why a model turn ended. */
12
44
  export type CompletedTurnReason = "answer" | "aborted" | "error";
13
45
  /** A model turn that ended, as `turn.complete` names it (raised once, then gone). */
@@ -34,8 +66,8 @@ export declare function noteCompletedTurn(bus: LegModBus, seat: CompletedTurnSea
34
66
  /** Raise `turn.complete` for each turn the seat holds, in order, each once (the seat is emptied first). An engine-side
35
67
  * rejection is swallowed: an observation never changes what it observes. */
36
68
  export declare function raiseCompletedTurn(bus: LegModBus, seat: CompletedTurnSeat, identity: HookInvocationIdentity | undefined, signal: AbortSignal | undefined): Promise<void>;
37
- /** Raise `session.end` as the leg's terminal settles (nothing when no handler hangs on it). */
69
+ /** Raise `session.end` as the leg's terminal settles; `undefined` when neither it nor `classic.SessionEnd` is heard. */
38
70
  export declare function raiseSessionEnd(bus: LegModBus, identity: HookInvocationIdentity | undefined, end: {
39
71
  readonly reason: string;
40
72
  readonly sessionId: string;
41
- }): Promise<void>;
73
+ }): Promise<void> | undefined;
@@ -1,4 +1,40 @@
1
- import { classicEventBase } from "./stations.js";
1
+ import { classicEventBase, observeClassic } from "./stations.js";
2
+ const hearsEither = (bus, typed, classic) => bus.hasHandlers(typed) || bus.hasHandlers(classic);
3
+ export function raiseSessionStart(bus, identity, start, signal) {
4
+ if (!hearsEither(bus, "session.start", "classic.SessionStart"))
5
+ return undefined;
6
+ const e = { ...classicEventBase(identity), cwd: start.cwd, sessionId: start.sessionId };
7
+ const core = Object.freeze({ cwd: start.cwd });
8
+ return observeLifecycle(bus, "session.start", e, async () => {
9
+ await observeClassic(bus, "classic.SessionStart", e, signal);
10
+ return core;
11
+ }, signal);
12
+ }
13
+ export function raiseStartedTurn(bus, identity, turn, signal) {
14
+ if (!bus.hasHandlers("turn.start"))
15
+ return undefined;
16
+ const core = Object.freeze({ turn });
17
+ return observeLifecycle(bus, "turn.start", { ...classicEventBase(identity), turn }, () => core, signal);
18
+ }
19
+ export const SESSION_MEASURE_UNITS = Object.freeze(["context"]);
20
+ export function measureSession(bus, seat, measured, identity, signal) {
21
+ const before = seat.context;
22
+ const context = Object.freeze({ usedTokens: measured.usedTokens, windowTokens: measured.windowTokens, compactAtTokens: measured.compactAtTokens });
23
+ seat.context = context;
24
+ const moved = before === undefined || before.usedTokens !== context.usedTokens || before.windowTokens !== context.windowTokens || before.compactAtTokens !== context.compactAtTokens;
25
+ if (!moved || !bus.hasHandlers("session.measure"))
26
+ return undefined;
27
+ const changed = Object.freeze(["context"]);
28
+ const core = Object.freeze({ changed });
29
+ return observeLifecycle(bus, "session.measure", { ...classicEventBase(identity), context, changed }, () => core, signal);
30
+ }
31
+ async function observeLifecycle(bus, event, e, bottom, signal) {
32
+ try {
33
+ await bus.dispatch(event, e, { bottom, ...(signal !== undefined ? { signal } : {}) });
34
+ }
35
+ catch {
36
+ }
37
+ }
2
38
  const answerOf = (message) => (message?.content ?? []).flatMap((c) => (c.type === "text" ? [c.text] : [])).join("");
3
39
  export function noteCompletedTurn(bus, seat, message, turn, aborted, usage) {
4
40
  if (!bus.hasHandlers("turn.complete"))
@@ -22,14 +58,13 @@ export async function raiseCompletedTurn(bus, seat, identity, signal) {
22
58
  }
23
59
  }
24
60
  }
25
- export async function raiseSessionEnd(bus, identity, end) {
26
- if (!bus.hasHandlers("session.end"))
27
- return;
61
+ export function raiseSessionEnd(bus, identity, end) {
62
+ if (!hearsEither(bus, "session.end", "classic.SessionEnd"))
63
+ return undefined;
28
64
  const e = { ...classicEventBase(identity), reason: end.reason, sessionId: end.sessionId };
29
65
  const core = Object.freeze({ sessionId: end.sessionId });
30
- try {
31
- await bus.dispatch("session.end", e, { bottom: () => core });
32
- }
33
- catch {
34
- }
66
+ return observeLifecycle(bus, "session.end", e, async () => {
67
+ await observeClassic(bus, "classic.SessionEnd", e, undefined);
68
+ return core;
69
+ }, undefined);
35
70
  }