@wrongstack/core 0.285.0 → 0.287.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 (340) hide show
  1. package/dist/autophase/phase-orchestrator.d.ts.map +1 -1
  2. package/dist/boot.d.ts.map +1 -1
  3. package/dist/coordination/agent-monitor.d.ts +29 -0
  4. package/dist/coordination/agent-monitor.d.ts.map +1 -1
  5. package/dist/coordination/autonomous-brain.d.ts +0 -2
  6. package/dist/coordination/autonomous-brain.d.ts.map +1 -1
  7. package/dist/coordination/autonomous-coordinator.d.ts +4 -0
  8. package/dist/coordination/autonomous-coordinator.d.ts.map +1 -1
  9. package/dist/coordination/brain-ledger.d.ts +142 -0
  10. package/dist/coordination/brain-ledger.d.ts.map +1 -0
  11. package/dist/coordination/brain-monitor.d.ts +46 -2
  12. package/dist/coordination/brain-monitor.d.ts.map +1 -1
  13. package/dist/coordination/brain.d.ts +43 -0
  14. package/dist/coordination/brain.d.ts.map +1 -1
  15. package/dist/coordination/delegate-tool.d.ts +8 -14
  16. package/dist/coordination/delegate-tool.d.ts.map +1 -1
  17. package/dist/coordination/director/director-btw-notes.d.ts +20 -0
  18. package/dist/coordination/director/director-btw-notes.d.ts.map +1 -0
  19. package/dist/coordination/director/director-collab.d.ts +40 -0
  20. package/dist/coordination/director/director-collab.d.ts.map +1 -0
  21. package/dist/coordination/director.d.ts +28 -9
  22. package/dist/coordination/director.d.ts.map +1 -1
  23. package/dist/coordination/fleet-manager.d.ts +21 -0
  24. package/dist/coordination/fleet-manager.d.ts.map +1 -1
  25. package/dist/coordination/fleet.d.ts +6 -7
  26. package/dist/coordination/fleet.d.ts.map +1 -1
  27. package/dist/coordination/global-mailbox.d.ts +96 -21
  28. package/dist/coordination/global-mailbox.d.ts.map +1 -1
  29. package/dist/coordination/icoordinator.d.ts +1 -3
  30. package/dist/coordination/icoordinator.d.ts.map +1 -1
  31. package/dist/coordination/index.d.ts +2 -1
  32. package/dist/coordination/index.d.ts.map +1 -1
  33. package/dist/coordination/index.js +2176 -806
  34. package/dist/coordination/index.js.map +4 -4
  35. package/dist/coordination/knowledge-graph.d.ts +13 -1
  36. package/dist/coordination/knowledge-graph.d.ts.map +1 -1
  37. package/dist/coordination/mail-tools.d.ts.map +1 -1
  38. package/dist/coordination/mailbox-actions.d.ts +12 -13
  39. package/dist/coordination/mailbox-actions.d.ts.map +1 -1
  40. package/dist/coordination/mailbox-constants.d.ts +64 -0
  41. package/dist/coordination/mailbox-constants.d.ts.map +1 -0
  42. package/dist/coordination/mailbox-events.d.ts +32 -0
  43. package/dist/coordination/mailbox-events.d.ts.map +1 -0
  44. package/dist/coordination/mailbox-message-codec.d.ts +28 -0
  45. package/dist/coordination/mailbox-message-codec.d.ts.map +1 -0
  46. package/dist/coordination/mailbox-types.d.ts +130 -5
  47. package/dist/coordination/mailbox-types.d.ts.map +1 -1
  48. package/dist/coordination/mailbox.d.ts +21 -2
  49. package/dist/coordination/mailbox.d.ts.map +1 -1
  50. package/dist/coordination/package-author-tracker.d.ts.map +1 -1
  51. package/dist/coordination/subagent-result-tool.d.ts.map +1 -1
  52. package/dist/core/agent-loop.d.ts.map +1 -1
  53. package/dist/core/agent-response.d.ts +10 -1
  54. package/dist/core/agent-response.d.ts.map +1 -1
  55. package/dist/core/agent-tools.d.ts.map +1 -1
  56. package/dist/core/agent.d.ts +8 -0
  57. package/dist/core/agent.d.ts.map +1 -1
  58. package/dist/core/context.d.ts +25 -0
  59. package/dist/core/context.d.ts.map +1 -1
  60. package/dist/core/conversation-state.d.ts +6 -0
  61. package/dist/core/conversation-state.d.ts.map +1 -1
  62. package/dist/core/fallback-model.d.ts.map +1 -1
  63. package/dist/core/mailbox-loop.d.ts +12 -5
  64. package/dist/core/mailbox-loop.d.ts.map +1 -1
  65. package/dist/core/system-prompt-builder.d.ts +14 -6
  66. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  67. package/dist/defaults/index.d.ts +0 -1
  68. package/dist/defaults/index.d.ts.map +1 -1
  69. package/dist/defaults/index.js +1690 -1998
  70. package/dist/defaults/index.js.map +4 -4
  71. package/dist/execution/auto-compaction-middleware.d.ts +8 -1
  72. package/dist/execution/auto-compaction-middleware.d.ts.map +1 -1
  73. package/dist/execution/autonomous-runner.d.ts +7 -1
  74. package/dist/execution/autonomous-runner.d.ts.map +1 -1
  75. package/dist/execution/autonomy-brain.d.ts +72 -11
  76. package/dist/execution/autonomy-brain.d.ts.map +1 -1
  77. package/dist/execution/brain-chain.d.ts +53 -0
  78. package/dist/execution/brain-chain.d.ts.map +1 -0
  79. package/dist/execution/brain-evaluation.d.ts +66 -0
  80. package/dist/execution/brain-evaluation.d.ts.map +1 -0
  81. package/dist/execution/brain-runtime.d.ts +171 -0
  82. package/dist/execution/brain-runtime.d.ts.map +1 -0
  83. package/dist/execution/compaction-core.d.ts.map +1 -1
  84. package/dist/execution/council-brain.d.ts +79 -0
  85. package/dist/execution/council-brain.d.ts.map +1 -0
  86. package/dist/execution/council-orchestrator.d.ts +32 -0
  87. package/dist/execution/council-orchestrator.d.ts.map +1 -0
  88. package/dist/execution/council-personas.d.ts +19 -0
  89. package/dist/execution/council-personas.d.ts.map +1 -0
  90. package/dist/execution/council-profiles.d.ts +34 -0
  91. package/dist/execution/council-profiles.d.ts.map +1 -0
  92. package/dist/execution/council-prompts.d.ts +21 -0
  93. package/dist/execution/council-prompts.d.ts.map +1 -0
  94. package/dist/execution/council-resolution.d.ts +57 -0
  95. package/dist/execution/council-resolution.d.ts.map +1 -0
  96. package/dist/execution/design-kit-loader.d.ts.map +1 -1
  97. package/dist/execution/enhance-recovery.d.ts +35 -0
  98. package/dist/execution/enhance-recovery.d.ts.map +1 -0
  99. package/dist/execution/error-handler.d.ts.map +1 -1
  100. package/dist/execution/eternal-autonomy.d.ts +12 -0
  101. package/dist/execution/eternal-autonomy.d.ts.map +1 -1
  102. package/dist/execution/index.d.ts +11 -1
  103. package/dist/execution/index.d.ts.map +1 -1
  104. package/dist/execution/index.js +3076 -526
  105. package/dist/execution/index.js.map +4 -4
  106. package/dist/execution/intelligent-compactor.d.ts +18 -7
  107. package/dist/execution/intelligent-compactor.d.ts.map +1 -1
  108. package/dist/execution/one-shot-llm.d.ts +52 -0
  109. package/dist/execution/one-shot-llm.d.ts.map +1 -0
  110. package/dist/execution/parallel-eternal-engine.d.ts +12 -0
  111. package/dist/execution/parallel-eternal-engine.d.ts.map +1 -1
  112. package/dist/execution/prompt-enhancer.d.ts +23 -4
  113. package/dist/execution/prompt-enhancer.d.ts.map +1 -1
  114. package/dist/execution/prompt-enhancer.js +24 -6
  115. package/dist/execution/prompt-enhancer.js.map +2 -2
  116. package/dist/execution/selective-compactor.d.ts +4 -4
  117. package/dist/execution/strategy-compactor.d.ts +7 -0
  118. package/dist/execution/strategy-compactor.d.ts.map +1 -1
  119. package/dist/execution/tool-executor.d.ts +19 -5
  120. package/dist/execution/tool-executor.d.ts.map +1 -1
  121. package/dist/hooks/registry.d.ts.map +1 -1
  122. package/dist/hooks/runner.d.ts.map +1 -1
  123. package/dist/hooks/shell-executor.d.ts.map +1 -1
  124. package/dist/hq/alerts.d.ts +5 -0
  125. package/dist/hq/alerts.d.ts.map +1 -1
  126. package/dist/hq/auth-store.d.ts +38 -10
  127. package/dist/hq/auth-store.d.ts.map +1 -1
  128. package/dist/hq/commands.d.ts +8 -4
  129. package/dist/hq/commands.d.ts.map +1 -1
  130. package/dist/hq/cost-bridge.d.ts +5 -3
  131. package/dist/hq/cost-bridge.d.ts.map +1 -1
  132. package/dist/hq/factory.d.ts +3 -0
  133. package/dist/hq/factory.d.ts.map +1 -1
  134. package/dist/hq/fleet-bridge.d.ts.map +1 -1
  135. package/dist/hq/index.d.ts +0 -1
  136. package/dist/hq/index.d.ts.map +1 -1
  137. package/dist/hq/index.js +1016 -283
  138. package/dist/hq/index.js.map +4 -4
  139. package/dist/hq/persistence.d.ts +42 -0
  140. package/dist/hq/persistence.d.ts.map +1 -1
  141. package/dist/hq/protocol/brain.d.ts +24 -0
  142. package/dist/hq/protocol/brain.d.ts.map +1 -0
  143. package/dist/hq/protocol/browser.d.ts +12 -0
  144. package/dist/hq/protocol/browser.d.ts.map +1 -0
  145. package/dist/hq/protocol/client.d.ts +69 -0
  146. package/dist/hq/protocol/client.d.ts.map +1 -0
  147. package/dist/hq/protocol/core.d.ts +130 -0
  148. package/dist/hq/protocol/core.d.ts.map +1 -0
  149. package/dist/hq/protocol/fleet.d.ts +73 -0
  150. package/dist/hq/protocol/fleet.d.ts.map +1 -0
  151. package/dist/hq/protocol/mailbox.d.ts +76 -0
  152. package/dist/hq/protocol/mailbox.d.ts.map +1 -0
  153. package/dist/hq/protocol/mcp.d.ts +51 -0
  154. package/dist/hq/protocol/mcp.d.ts.map +1 -0
  155. package/dist/hq/protocol/project.d.ts +26 -0
  156. package/dist/hq/protocol/project.d.ts.map +1 -0
  157. package/dist/hq/protocol/session.d.ts +153 -0
  158. package/dist/hq/protocol/session.d.ts.map +1 -0
  159. package/dist/hq/protocol/tool.d.ts +31 -0
  160. package/dist/hq/protocol/tool.d.ts.map +1 -0
  161. package/dist/hq/protocol.d.ts +10 -559
  162. package/dist/hq/protocol.d.ts.map +1 -1
  163. package/dist/hq/publisher.d.ts +4 -0
  164. package/dist/hq/publisher.d.ts.map +1 -1
  165. package/dist/index.d.ts +24 -8
  166. package/dist/index.d.ts.map +1 -1
  167. package/dist/index.js +7676 -3432
  168. package/dist/index.js.map +4 -4
  169. package/dist/infrastructure/index.js +13 -11
  170. package/dist/infrastructure/index.js.map +2 -2
  171. package/dist/infrastructure/token-counter.d.ts.map +1 -1
  172. package/dist/kernel/events/agent-events.d.ts +283 -0
  173. package/dist/kernel/events/agent-events.d.ts.map +1 -0
  174. package/dist/kernel/events/brain-events.d.ts +176 -0
  175. package/dist/kernel/events/brain-events.d.ts.map +1 -0
  176. package/dist/kernel/events/fleet-events.d.ts +39 -0
  177. package/dist/kernel/events/fleet-events.d.ts.map +1 -0
  178. package/dist/kernel/events/memory-events.d.ts +165 -0
  179. package/dist/kernel/events/memory-events.d.ts.map +1 -0
  180. package/dist/kernel/events/provider-events.d.ts +98 -0
  181. package/dist/kernel/events/provider-events.d.ts.map +1 -0
  182. package/dist/kernel/events/sdd-events.d.ts +118 -0
  183. package/dist/kernel/events/sdd-events.d.ts.map +1 -0
  184. package/dist/kernel/events/session-events.d.ts +227 -0
  185. package/dist/kernel/events/session-events.d.ts.map +1 -0
  186. package/dist/kernel/events/tool-events.d.ts +185 -0
  187. package/dist/kernel/events/tool-events.d.ts.map +1 -0
  188. package/dist/kernel/events/worktree-events.d.ts +58 -0
  189. package/dist/kernel/events/worktree-events.d.ts.map +1 -0
  190. package/dist/kernel/events.d.ts +12 -1282
  191. package/dist/kernel/events.d.ts.map +1 -1
  192. package/dist/kernel/index.js +22 -2
  193. package/dist/kernel/index.js.map +2 -2
  194. package/dist/kernel/run-controller.d.ts +15 -0
  195. package/dist/kernel/run-controller.d.ts.map +1 -1
  196. package/dist/mailbox-attach.d.ts.map +1 -1
  197. package/dist/models/index.js +19 -6
  198. package/dist/models/index.js.map +2 -2
  199. package/dist/models/llm-selector.d.ts +7 -0
  200. package/dist/models/llm-selector.d.ts.map +1 -1
  201. package/dist/observability/index.js +16 -15
  202. package/dist/observability/index.js.map +2 -2
  203. package/dist/plugins/auto-review-plugin.d.ts +36 -0
  204. package/dist/plugins/auto-review-plugin.d.ts.map +1 -0
  205. package/dist/plugins/chimera-plugin.d.ts +8 -0
  206. package/dist/plugins/chimera-plugin.d.ts.map +1 -1
  207. package/dist/security/index.d.ts +1 -0
  208. package/dist/security/index.d.ts.map +1 -1
  209. package/dist/security/index.js +260 -23
  210. package/dist/security/index.js.map +4 -4
  211. package/dist/security/permission-policy-schema.d.ts +77 -0
  212. package/dist/security/permission-policy-schema.d.ts.map +1 -0
  213. package/dist/security/permission-policy.d.ts +5 -0
  214. package/dist/security/permission-policy.d.ts.map +1 -1
  215. package/dist/security/secret-scrubber.d.ts.map +1 -1
  216. package/dist/security/secret-vault.d.ts +9 -0
  217. package/dist/security/secret-vault.d.ts.map +1 -1
  218. package/dist/session-registry.d.ts.map +1 -1
  219. package/dist/skills/index.js.map +2 -2
  220. package/dist/storage/config-loader.d.ts +10 -0
  221. package/dist/storage/config-loader.d.ts.map +1 -1
  222. package/dist/storage/goal-kanban.d.ts +69 -0
  223. package/dist/storage/goal-kanban.d.ts.map +1 -0
  224. package/dist/storage/goal-store.d.ts +1 -1
  225. package/dist/storage/goal-store.d.ts.map +1 -1
  226. package/dist/storage/index.d.ts +1 -1
  227. package/dist/storage/index.d.ts.map +1 -1
  228. package/dist/storage/index.js +572 -879
  229. package/dist/storage/index.js.map +4 -4
  230. package/dist/storage/memory-consolidator.d.ts +9 -1
  231. package/dist/storage/memory-consolidator.d.ts.map +1 -1
  232. package/dist/storage/plan-store.d.ts +1 -1
  233. package/dist/storage/plan-store.d.ts.map +1 -1
  234. package/dist/storage/queue-store.d.ts +4 -0
  235. package/dist/storage/queue-store.d.ts.map +1 -1
  236. package/dist/storage/session-store.d.ts +9 -0
  237. package/dist/storage/session-store.d.ts.map +1 -1
  238. package/dist/storage/task-store.d.ts +1 -1
  239. package/dist/storage/task-store.d.ts.map +1 -1
  240. package/dist/storage/todos-checkpoint.d.ts +2 -2
  241. package/dist/storage/todos-checkpoint.d.ts.map +1 -1
  242. package/dist/tools/council-tool.d.ts +25 -0
  243. package/dist/tools/council-tool.d.ts.map +1 -0
  244. package/dist/tools/index.d.ts +2 -0
  245. package/dist/tools/index.d.ts.map +1 -1
  246. package/dist/tools/index.js +1884 -12
  247. package/dist/tools/index.js.map +4 -4
  248. package/dist/tools/one-shot-llm-tool.d.ts +51 -0
  249. package/dist/tools/one-shot-llm-tool.d.ts.map +1 -0
  250. package/dist/types/config.d.ts +236 -4
  251. package/dist/types/config.d.ts.map +1 -1
  252. package/dist/types/context-window.d.ts.map +1 -1
  253. package/dist/types/council.d.ts +134 -0
  254. package/dist/types/council.d.ts.map +1 -0
  255. package/dist/types/default-config.d.ts +3 -3
  256. package/dist/types/hooks.d.ts +14 -0
  257. package/dist/types/hooks.d.ts.map +1 -1
  258. package/dist/types/index.d.ts +2 -0
  259. package/dist/types/index.d.ts.map +1 -1
  260. package/dist/types/index.js +40 -8
  261. package/dist/types/index.js.map +3 -3
  262. package/dist/types/multi-agent.d.ts +8 -0
  263. package/dist/types/multi-agent.d.ts.map +1 -1
  264. package/dist/types/observability.d.ts +5 -0
  265. package/dist/types/observability.d.ts.map +1 -1
  266. package/dist/types/one-shot-llm.d.ts +128 -0
  267. package/dist/types/one-shot-llm.d.ts.map +1 -0
  268. package/dist/types/plugin.d.ts +6 -0
  269. package/dist/types/plugin.d.ts.map +1 -1
  270. package/dist/types/provider.d.ts +17 -0
  271. package/dist/types/provider.d.ts.map +1 -1
  272. package/dist/types/system-prompt.d.ts +2 -1
  273. package/dist/types/system-prompt.d.ts.map +1 -1
  274. package/dist/types/tool-executor.d.ts +10 -0
  275. package/dist/types/tool-executor.d.ts.map +1 -1
  276. package/dist/types/tool.d.ts +7 -0
  277. package/dist/types/tool.d.ts.map +1 -1
  278. package/dist/utils/atomic-write.d.ts.map +1 -1
  279. package/dist/utils/glob-expand.d.ts.map +1 -1
  280. package/dist/utils/incoming-images.d.ts +39 -0
  281. package/dist/utils/incoming-images.d.ts.map +1 -0
  282. package/dist/utils/index.d.ts +1 -0
  283. package/dist/utils/index.d.ts.map +1 -1
  284. package/dist/utils/index.js +156 -11
  285. package/dist/utils/index.js.map +4 -4
  286. package/dist/utils/tool-wire-compact.d.ts +1 -0
  287. package/dist/utils/tool-wire-compact.d.ts.map +1 -1
  288. package/dist/utils/wstack-paths.d.ts +20 -4
  289. package/dist/utils/wstack-paths.d.ts.map +1 -1
  290. package/dist/worktree/worktree-manager.d.ts +13 -4
  291. package/dist/worktree/worktree-manager.d.ts.map +1 -1
  292. package/instructions/agents/browser.md +25 -16
  293. package/instructions/cli/next-task-predictor.md +5 -3
  294. package/instructions/coordination/subagent-baseline.md +17 -2
  295. package/instructions/leader-after-task.md +19 -8
  296. package/instructions/llm/council-judge.md +19 -0
  297. package/instructions/llm/council-voter.md +22 -0
  298. package/instructions/modes/architect.md +14 -9
  299. package/instructions/modes/audit-lite.md +9 -7
  300. package/instructions/modes/brief-system.md +12 -12
  301. package/instructions/modes/brief.md +7 -5
  302. package/instructions/modes/code-auditor.md +13 -8
  303. package/instructions/modes/code-reviewer.md +13 -8
  304. package/instructions/modes/debug-lite.md +7 -6
  305. package/instructions/modes/debugger.md +13 -9
  306. package/instructions/modes/devops.md +13 -9
  307. package/instructions/modes/plan-lite.md +7 -6
  308. package/instructions/modes/refactor-lite.md +7 -6
  309. package/instructions/modes/refactorer.md +14 -9
  310. package/instructions/modes/research-lite.md +8 -6
  311. package/instructions/modes/research-web.md +18 -55
  312. package/instructions/modes/review-lite.md +7 -6
  313. package/instructions/modes/teach-system.md +15 -15
  314. package/instructions/modes/teach.md +13 -12
  315. package/instructions/modes/test-lite.md +6 -5
  316. package/instructions/modes/tester.md +13 -9
  317. package/instructions/modes/ui-design.md +14 -8
  318. package/instructions/sections/tool/commit-hygiene.md +1 -7
  319. package/instructions/sections/tool/common-patterns.md +7 -1
  320. package/instructions/sections/tool/delegation-full.md +3 -31
  321. package/instructions/sections/tool/mailbox-compact.md +1 -1
  322. package/instructions/sections/tool/mailbox-full.md +6 -22
  323. package/instructions/system.md +294 -8
  324. package/package.json +2 -2
  325. package/skills/docker-deploy/SKILL.md +1 -1
  326. package/skills/mailbox-bridge/SKILL.md +16 -7
  327. package/skills/output-standards/SKILL.md +16 -16
  328. package/skills/wrongstack-mailbox/SKILL.md +57 -12
  329. package/dist/coordination/director-construction.d.ts +0 -90
  330. package/dist/coordination/director-construction.d.ts.map +0 -1
  331. package/dist/hq/agent-bridge.d.ts +0 -27
  332. package/dist/hq/agent-bridge.d.ts.map +0 -1
  333. package/dist/plugins/git-plugin.d.ts +0 -15
  334. package/dist/plugins/git-plugin.d.ts.map +0 -1
  335. package/dist/plugins/observability-plugin.d.ts +0 -19
  336. package/dist/plugins/observability-plugin.d.ts.map +0 -1
  337. package/dist/plugins/plan-plugin.d.ts +0 -16
  338. package/dist/plugins/plan-plugin.d.ts.map +0 -1
  339. package/dist/storage/memory-store.d.ts +0 -119
  340. package/dist/storage/memory-store.d.ts.map +0 -1
@@ -2,14 +2,17 @@
2
2
  * EventBus — observe-only typed event bus.
3
3
  * Subscribers cannot modify or cancel. Subscriber exceptions are caught.
4
4
  */
5
- import type { BrainDecision, BrainDecisionRequest } from '../coordination/brain.js';
6
- import type { Context } from '../core/context.js';
7
- import type { ContentBlock } from '../types/blocks.js';
8
- import type { MemoryClearedPayload, MemoryConsolidatedPayload, MemoryForgottenPayload, MemoryRememberedPayload } from '../types/memory.js';
9
- import type { PermissionDecision } from '../types/permission.js';
10
- import type { Usage } from '../types/provider.js';
11
- import type { RiskTier, Tool, ToolErrorCategory, ToolProgressEvent } from '../types/tool.js';
12
- import type { ToolOutputMetadata } from '../types/context-evidence.js';
5
+ import type { AgentEventMap } from './events/agent-events.js';
6
+ import type { BrainEventMap } from './events/brain-events.js';
7
+ import type { FleetEventMap } from './events/fleet-events.js';
8
+ import type { MemoryEventMap } from './events/memory-events.js';
9
+ import type { ProviderEventMap } from './events/provider-events.js';
10
+ import type { SddEventMap } from './events/sdd-events.js';
11
+ import type { SessionEventMap } from './events/session-events.js';
12
+ import type { ToolEventMap } from './events/tool-events.js';
13
+ import type { WorktreeEventMap } from './events/worktree-events.js';
14
+ /** Distress signals the BrainMonitor watches. See `coordination/brain-monitor.ts`. */
15
+ export type BrainInterventionKind = 'tool_failure_streak' | 'error_storm' | 'agent_stall' | 'file_churn';
13
16
  /**
14
17
  * Structural shape of a tracked agent as flushed by AgentStatusTracker. Kept
15
18
  * structural (not imported from the root `session-registry` module) so the
@@ -32,1280 +35,7 @@ export interface TrackedAgentSnapshot {
32
35
  partialText?: string | undefined;
33
36
  lastActivityAt: string;
34
37
  }
35
- export interface EventMap {
36
- 'brain.decision_requested': {
37
- sessionId?: string | undefined;
38
- request: BrainDecisionRequest;
39
- at: number;
40
- };
41
- 'brain.decision_answered': {
42
- sessionId?: string | undefined;
43
- request: BrainDecisionRequest;
44
- decision: BrainDecision;
45
- at: number;
46
- };
47
- 'brain.decision_ask_human': {
48
- sessionId?: string | undefined;
49
- request: BrainDecisionRequest;
50
- decision: BrainDecision;
51
- at: number;
52
- };
53
- 'brain.human_answered': {
54
- sessionId?: string | undefined;
55
- id: string;
56
- optionId?: string | undefined;
57
- deny?: boolean | undefined;
58
- text?: string | undefined;
59
- at: number;
60
- };
61
- 'brain.decision_denied': {
62
- sessionId?: string | undefined;
63
- request: BrainDecisionRequest;
64
- decision: BrainDecision;
65
- at: number;
66
- };
67
- /**
68
- * Fired by the BrainMonitor when it PROACTIVELY engaged (self-activation):
69
- * a watched signal (tool-failure streak, error storm) crossed its
70
- * threshold, the Brain was consulted, and — when the decision called for
71
- * it — a corrective steer was delivered to the working agent.
72
- */
73
- 'brain.intervention': {
74
- sessionId?: string | undefined;
75
- kind: 'tool_failure_streak' | 'error_storm';
76
- request: BrainDecisionRequest;
77
- decision: BrainDecision;
78
- /** True when a steer was actually delivered to the agent. */
79
- intervened: boolean;
80
- at: number;
81
- };
82
- 'session.started': {
83
- id: string;
84
- sessionId?: string | undefined;
85
- };
86
- 'session.ended': {
87
- id: string;
88
- sessionId?: string | undefined;
89
- usage: Usage;
90
- };
91
- 'session.damaged': {
92
- sessionId: string;
93
- detail: string;
94
- };
95
- /**
96
- * Fired by AgentStatusTracker after every flush with the full agent list
97
- * (leader + subagents). In-process consumers (e.g. the HQ session-telemetry
98
- * bridge) read this to build live snapshots without re-reading the shared
99
- * session-registry file.
100
- */
101
- 'session.agents_updated': {
102
- sessionId?: string | undefined;
103
- agents: readonly TrackedAgentSnapshot[];
104
- };
105
- /**
106
- * Fired around a single Agent.run() call. Status trackers use these to
107
- * measure active-run elapsed time instead of inferring it from iterations.
108
- */
109
- 'agent.run.started': {
110
- sessionId?: string | undefined;
111
- ctx: Context;
112
- model: string;
113
- at: string;
114
- };
115
- 'agent.run.completed': {
116
- sessionId?: string | undefined;
117
- ctx: Context;
118
- status: 'done' | 'failed' | 'max_iterations' | 'aborted';
119
- iterations: number;
120
- at: string;
121
- durationMs: number;
122
- };
123
- 'agent.run.error': {
124
- sessionId?: string | undefined;
125
- ctx: Context;
126
- err: Error;
127
- at: string;
128
- durationMs: number;
129
- };
130
- 'iteration.started': {
131
- sessionId?: string | undefined;
132
- ctx: Context;
133
- index: number;
134
- };
135
- 'iteration.completed': {
136
- sessionId?: string | undefined;
137
- ctx: Context;
138
- index: number;
139
- };
140
- /**
141
- * Fired when the agent hits its iteration limit. Listeners (CLI/TUI) can
142
- * call `grant(extra)` to allow more iterations, or `deny()` to stop.
143
- * If no listener responds within 30s the run ends with 'max_iterations'.
144
- */
145
- 'iteration.limit_reached': {
146
- sessionId?: string | undefined;
147
- currentIterations: number;
148
- currentLimit: number;
149
- grant: (extraIterations: number) => void;
150
- deny: () => void;
151
- };
152
- 'provider.response': {
153
- sessionId?: string | undefined;
154
- ctx: Context;
155
- model: string;
156
- content?: ContentBlock[] | undefined;
157
- usage: Usage;
158
- stopReason: string;
159
- };
160
- 'provider.text_delta': {
161
- sessionId?: string | undefined;
162
- ctx: Context;
163
- text: string;
164
- };
165
- 'provider.thinking_delta': {
166
- sessionId?: string | undefined;
167
- ctx: Context;
168
- text: string;
169
- };
170
- 'provider.tool_use_start': {
171
- sessionId?: string | undefined;
172
- ctx: Context;
173
- id: string;
174
- name: string;
175
- };
176
- 'provider.tool_use_stop': {
177
- sessionId?: string | undefined;
178
- ctx: Context;
179
- id: string;
180
- name: string;
181
- };
182
- /**
183
- * Fired when a single SSE event handler throws mid-stream. Best-effort: the
184
- * malformed event is skipped and the partial response built from earlier
185
- * events is preserved, so the stream is not aborted. `eventType` is the SSE
186
- * event's `type`; `msg` is the handler error message.
187
- */
188
- 'provider.stream_error': {
189
- sessionId?: string | undefined;
190
- ctx: Context;
191
- eventType: string;
192
- msg: string;
193
- };
194
- /**
195
- * Fired before each retry of a failed provider call. `attempt` is 1-based
196
- * (the first retry is attempt 1, etc.). `description` is the human-readable
197
- * one-liner from `ProviderError.describe()` — render this in the CLI/TUI
198
- * instead of grepping logger output for the raw JSON body.
199
- */
200
- 'provider.retry': {
201
- sessionId?: string | undefined;
202
- providerId: string;
203
- attempt: number;
204
- delayMs: number;
205
- status: number;
206
- description: string;
207
- };
208
- /**
209
- * Fired once when a provider call ultimately fails (retries exhausted, or
210
- * non-retryable error). Same shape as `provider.retry` minus the delay.
211
- */
212
- 'provider.error': {
213
- sessionId?: string | undefined;
214
- providerId: string;
215
- status: number;
216
- description: string;
217
- retryable: boolean;
218
- };
219
- /**
220
- * Fired by the fallback-model extension when the primary model is overloaded
221
- * (after its own retries are exhausted) and the agent switches to the next
222
- * model in the configured `fallbackModels` chain. `providerSwitched` is true
223
- * when the fallback also changed the active provider (cross-provider). UIs
224
- * render this as a notice: "⚠ opus overloaded — falling back to planner".
225
- */
226
- 'provider.fallback': {
227
- sessionId?: string | undefined;
228
- from: {
229
- providerId: string;
230
- model: string;
231
- };
232
- to: {
233
- providerId: string;
234
- model: string;
235
- };
236
- status: number;
237
- providerSwitched: boolean;
238
- contextWindowWarning?: {
239
- fromMaxContext: number;
240
- toMaxContext: number;
241
- currentTokens?: number | undefined;
242
- } | undefined;
243
- };
244
- 'tool.started': {
245
- sessionId?: string | undefined;
246
- name: string;
247
- id: string;
248
- input?: unknown | undefined;
249
- };
250
- /**
251
- * Fired when a tool call finishes successfully. Metrics collectors can count
252
- * calls and build latency histograms without parsing renderer output.
253
- */
254
- 'tool.completed': {
255
- name: string;
256
- id: string;
257
- sessionId: string;
258
- traceId?: string | undefined;
259
- agentId: string;
260
- durationMs: number;
261
- outputChars: number;
262
- };
263
- /**
264
- * Fired when a tool call throws. Does not include raw tool input/output.
265
- */
266
- 'tool.failed': {
267
- name: string;
268
- id: string;
269
- sessionId: string;
270
- traceId?: string | undefined;
271
- agentId: string;
272
- durationMs: number;
273
- category: ToolErrorCategory;
274
- retryable: boolean;
275
- detail?: string | undefined;
276
- errorCode?: string | undefined;
277
- errorSubsystem?: string | undefined;
278
- errorSeverity?: string | undefined;
279
- };
280
- /**
281
- * Fired for each ToolProgressEvent yielded by `Tool.executeStream`. UIs
282
- * subscribe to render incremental progress (streaming bash output, file
283
- * tree counts, etc.) without the tool having to know about the UI.
284
- */
285
- 'tool.progress': {
286
- sessionId?: string | undefined;
287
- name: string;
288
- id: string;
289
- event: ToolProgressEvent;
290
- };
291
- /** Cache hit on session store load — used by observability layers. */
292
- 'storage.cache_hit': {
293
- sessionId: string;
294
- store: string;
295
- filePath: string;
296
- operation: string;
297
- durationMs: number;
298
- };
299
- /**
300
- * Fired when a tool call needs confirmation
301
- * is registered on the executor. The TUI renders a confirmation dialog
302
- * from this event. Resolution is driven by calling the resolve function
303
- * passed in the payload with a decision string ('yes' | 'no' | 'always' | 'deny').
304
- */
305
- 'tool.confirm_needed': {
306
- sessionId?: string | undefined;
307
- tool: Tool;
308
- input: unknown;
309
- toolUseId: string;
310
- suggestedPattern: string;
311
- decisionSource?: PermissionDecision['source'] | undefined;
312
- riskTier?: RiskTier | undefined;
313
- resolve: (decision: 'yes' | 'no' | 'always' | 'deny') => void;
314
- };
315
- /**
316
- * Fired after the user chooses 'always' or 'deny' on a confirmation prompt.
317
- * The TUI can use this to show a brief notification that the decision was
318
- * persisted to the trust file (e.g. "✓ always allowed popo.txt" / "✗ denied popo.txt").
319
- */
320
- 'trust.persisted': {
321
- sessionId?: string | undefined;
322
- tool: string;
323
- pattern: string;
324
- decision: 'always' | 'deny';
325
- };
326
- /**
327
- * Fired when the agent loop detects that the model is repeating itself —
328
- * a tight loop that would otherwise burn iterations indefinitely. In the
329
- * default `steer-then-cut` mode the first detection injects a corrective
330
- * note into the conversation (`action: 'steer'`) and lets the run
331
- * continue; persistent repetition cuts the turn with status
332
- * `max_iterations` (`action: 'cut'`). Legacy `cut` mode hard-stops on
333
- * first detection.
334
- *
335
- * Flavours caught by the same safety valve:
336
- * - `kind: 'tool'` — the same tool(s) called with effectively the same
337
- * inputs (catches k2p7's tendency to retry identical tool calls when
338
- * a tool returns an unexpected empty result).
339
- * - `kind: 'message'` — the same assistant text repeated, with no tool
340
- * calls. K2P7 and other weak-instruction-following models can echo
341
- * their last assistant turn verbatim across many iterations in
342
- * autonomous-continue mode. The fingerprint also matches this case
343
- * so the safety valve catches it too.
344
- * - `kind: 'mixed'` — both: the response contains tool calls AND text,
345
- * and the combined fingerprint (tool names + text) repeats.
346
- *
347
- * UIs can render a warning chip. The `kind`, `action`, and `scope` fields
348
- * are additive — older subscribers that only read `tools` continue to work.
349
- */
350
- 'tool.loop_detected': {
351
- sessionId?: string | undefined;
352
- ctx: Context;
353
- /** Comma-separated tool names involved in the loop, or empty string for pure message loops. */
354
- tools: string;
355
- /** Number of repeats detected (consecutive iterations, or identical calls within the window for `scope: 'call'`). */
356
- repeatCount: number;
357
- /** 0-based iteration index where the loop was detected. */
358
- iteration: number;
359
- /**
360
- * Shape of the loop. `tool` = identical tool calls; `message` = identical
361
- * text-only response; `mixed` = both tool calls and text repeated.
362
- * Defaults to `tool` for backward compatibility with subscribers that
363
- * pre-date the field.
364
- */
365
- kind?: 'tool' | 'message' | 'mixed' | undefined;
366
- /**
367
- * What the detector did. `steer` = a corrective note was folded into the
368
- * conversation and the run continues; `cut` = the turn was ended with
369
- * status `max_iterations`. Defaults to `cut` for subscribers that
370
- * pre-date the field.
371
- */
372
- action?: 'steer' | 'cut' | undefined;
373
- /**
374
- * Which detector fired. `iteration` = consecutive effectively-identical
375
- * iterations; `call` = the same (tool name + canonicalized args) call
376
- * repeated within the sliding window, possibly interleaved with other
377
- * calls (e.g. re-reading the same file for the 4th time).
378
- */
379
- scope?: 'iteration' | 'call' | undefined;
380
- };
381
- /**
382
- * `output` is a truncated preview of the tool's serialized result text
383
- * (capped at ~400 chars by the emitter). UIs render this inline in the
384
- * tool history line without re-fetching from the session log.
385
- */
386
- 'tool.executed': {
387
- sessionId?: string | undefined;
388
- /**
389
- * The tool_use id (e.g. "toolu_…") issued by the provider for this call.
390
- * Pairs with `tool.started.id` so subscribers can correlate start/finish
391
- * even when the model fires multiple tools in parallel with identical
392
- * inputs. Optional only for legacy emit sites — new code should always
393
- * set it.
394
- */
395
- id?: string | undefined;
396
- name: string;
397
- durationMs: number;
398
- ok: boolean;
399
- input?: unknown | undefined;
400
- output?: string | undefined;
401
- /**
402
- * Full UTF-8 byte length of the serialized tool result that the model
403
- * actually sees (post-cap, post-scrub). The `output` preview is capped
404
- * at ~400 chars for transport; this number lets UIs surface what the
405
- * model is really paying tokens for. Optional only for legacy emit
406
- * sites that may not yet populate it.
407
- */
408
- outputBytes?: number | undefined;
409
- /**
410
- * Estimated token count for the full result body the model sees.
411
- * Computed from `outputBytes` with the standard ~3.5 chars/token
412
- * heuristic. Cheap to show in the TUI; not authoritative — the real
413
- * provider count lives in `provider.response.usage`. */
414
- outputTokens?: number | undefined;
415
- /**
416
- * For tools whose output has a clear "line" notion (file reads with
417
- * numbered prefixes, grep hits, bash stdout), the agent counts the
418
- * actual lines the model received and forwards it here. Undefined
419
- * for tools without a meaningful line count. */
420
- outputLines?: number | undefined;
421
- /**
422
- * Parsed context-management metadata for the result the model saw. This is
423
- * intentionally compact: file/symbol/error/path-integrity hints, not the
424
- * full output body. Compaction uses it to distinguish seen information from
425
- * information later referenced by the assistant.
426
- */
427
- metadata?: ToolOutputMetadata | undefined;
428
- };
429
- /**
430
- * Fired by the `delegate` tool right before it hands work to a subagent
431
- * and blocks on the result. Lets UIs render a "started delegating" line
432
- * immediately instead of looking idle for the (often minutes-long) life
433
- * of the subagent. Paired with `delegate.completed`.
434
- */
435
- 'delegate.started': {
436
- /** Parent/host session id for the delegation lifecycle. */
437
- sessionId?: string | undefined;
438
- /** Resolved roster role or free-form subagent name. */
439
- target: string;
440
- /** The task instruction handed to the subagent (untruncated — UIs trim). */
441
- task: string;
442
- };
443
- /**
444
- * Fired by the `delegate` tool once the subagent settles (success,
445
- * timeout, budget exhaustion, error). Carries human-friendly, untruncated
446
- * fields so UIs / the Telegram bridge can render a readable summary
447
- * instead of the JSON-stringified, ~400-char-truncated `tool.executed`
448
- * preview.
449
- */
450
- 'delegate.completed': {
451
- /** Parent/host session id for the delegation lifecycle. */
452
- sessionId?: string | undefined;
453
- /** Resolved roster role or free-form subagent name. */
454
- target: string;
455
- /** The task instruction handed to the subagent. */
456
- task: string;
457
- /** True only when the subagent finished its task cleanly. */
458
- ok: boolean;
459
- /** Task status — 'success' | 'timeout' | 'host_timeout' | 'stopped' | ... */
460
- status?: string | undefined;
461
- /** One-line human summary (from `buildDelegateSummary`), untruncated. */
462
- summary: string;
463
- durationMs: number;
464
- iterations: number;
465
- toolCalls: number;
466
- /** Estimated subagent cost in USD, from the director usage snapshot when known. */
467
- costUsd?: number | undefined;
468
- subagentId?: string | undefined;
469
- };
470
- /**
471
- * Fired when a subagent produces an assistant text block that should
472
- * appear in the main chat timeline (when agent streaming is enabled).
473
- * The payload carries the subagent's identity, the message content,
474
- * and the iteration index so UIs can render a threaded timeline.
475
- */
476
- 'agent.timeline.message': {
477
- /** Parent/host session id this subagent timeline belongs to. */
478
- sessionId?: string | undefined;
479
- /** Subagent id (e.g. "bug-hunter@abc123"). */
480
- subagentId: string;
481
- /** Human-readable name or role label. */
482
- agentName: string;
483
- /** The assistant text block content, or a tool-call summary. */
484
- content: string;
485
- /** Timeline entry kind. */
486
- kind: 'text' | 'thinking' | 'tool_use' | 'tool_result' | 'error' | 'status' | 'system';
487
- /** Iteration index within the subagent's own run. */
488
- iteration: number;
489
- /** ISO 8601 timestamp. */
490
- ts: string;
491
- /** When kind='tool_use', the tool name. */
492
- toolName?: string | undefined;
493
- /** Running cost estimate for this subagent so far. */
494
- costUsd?: number | undefined;
495
- };
496
- /**
497
- * Fired when a subagent's status changes (started, completed, failed,
498
- * timed out, stopped). UIs use this to update agent status indicators
499
- * and add status-change entries to the timeline.
500
- */
501
- 'agent.status_changed': {
502
- /** Parent/host session id this subagent status belongs to. */
503
- sessionId?: string | undefined;
504
- subagentId: string;
505
- agentName: string;
506
- status: 'spawned' | 'running' | 'completed' | 'failed' | 'timeout' | 'stopped' | 'budget_exhausted';
507
- /** ISO 8601 timestamp. */
508
- ts: string;
509
- /** Human-readable summary or error message. */
510
- summary?: string | undefined;
511
- /** Task description when available. */
512
- task?: string | undefined;
513
- };
514
- /**
515
- * Fired on every `iteration.completed`. UIs subscribe to render a live
516
- * context-window fill bar per agent (e.g. "67% ████████░░"). `load` is
517
- * clamped to 0..1 so every live surface renders at most 100%; diagnostics
518
- * can still detect over-budget states from `tokens > maxContext` or
519
- * `rawLoad`.
520
- */
521
- 'ctx.pct': {
522
- sessionId?: string | undefined;
523
- /** Fraction of maxContext currently in use, clamped to 0..1 for display. */
524
- load: number;
525
- /** Unclamped fraction when available. Can exceed 1 when over budget. */
526
- rawLoad?: number | undefined;
527
- /** Estimated total tokens (system + tools + messages). */
528
- tokens: number;
529
- /** Provider's max context window. */
530
- maxContext: number;
531
- };
532
- /** Fired when the active model's resolved context window changes. */
533
- 'ctx.max_context': {
534
- sessionId?: string | undefined;
535
- providerId: string;
536
- modelId: string;
537
- maxContext: number;
538
- };
539
- 'token.threshold': {
540
- sessionId?: string | undefined;
541
- used: number;
542
- limit: number;
543
- };
544
- /**
545
- * Fired by `DefaultTokenCounter` after each call to `account()` /
546
- * `accountWithModel()` updates its internal state. The payload carries
547
- * the live snapshot so subscribers (notably the TUI's `StatusBar`) can
548
- * re-render fresh token/cost/cache data immediately instead of waiting
549
- * for a slow polling interval. Cost fields may be zero when the model
550
- * is unknown to the ModelsRegistry — that is already signalled separately
551
- * by `token.cost_estimate_unavailable`.
552
- */
553
- 'token.accounted': {
554
- sessionId?: string | undefined;
555
- usage: Usage;
556
- cost: {
557
- input: number;
558
- output: number;
559
- total: number;
560
- };
561
- };
562
- /**
563
- * Fired when the subagent budget hits a soft limit and the coordinator
564
- * is being asked for an extension. The coordinator should call `extend()`
565
- * to grant more budget, or the promise auto-resolves to `deny` after
566
- * `timeoutMs` (default 30s), treating it as a hard stop.
567
- *
568
- * This event lets the CLI/TUI observe budget pressure in real time,
569
- * surface extension requests to users, and give the coordinator a
570
- * hook to implement custom extension policy without coupling to the
571
- * runner/budget classes.
572
- */
573
- 'budget.threshold_reached': {
574
- sessionId?: string | undefined;
575
- kind: 'iterations' | 'tool_calls' | 'tokens' | 'cost' | 'timeout' | 'idle_timeout';
576
- used: number;
577
- limit: number;
578
- /**
579
- * Call to grant more of the same budget type. `timeoutMs` extends the
580
- * wall-clock budget; the coordinator's watchdog observes the patched
581
- * limit and re-arms its timer for the new remainder.
582
- */
583
- extend: (extra: Partial<{
584
- maxIterations: number;
585
- maxToolCalls: number;
586
- maxTokens: number;
587
- maxCostUsd: number;
588
- timeoutMs: number;
589
- }>) => void;
590
- /** Call to deny the extension — subagent will stop. */
591
- deny: () => void;
592
- /** Auto-resolves to deny after timeout. */
593
- timeoutMs: number;
594
- };
595
- 'context.repaired': {
596
- sessionId?: string | undefined;
597
- ctx: Context;
598
- changed: boolean;
599
- removedToolUses: string[];
600
- removedToolResults: string[];
601
- removedMessages: number;
602
- };
603
- 'compaction.fired': {
604
- sessionId?: string | undefined;
605
- /** Threshold level that triggered compaction (warn / soft / hard). */
606
- level: 'warn' | 'soft' | 'hard';
607
- /** Tokens estimated before compaction ran. */
608
- tokens: number;
609
- /** Fraction of maxContext at the time compaction fired. */
610
- load: number;
611
- /** Provider's max context window in tokens. */
612
- maxContext: number;
613
- /** Budget snapshot used for the compaction decision. */
614
- budget?: {
615
- maxContext: number;
616
- inputTokens: number;
617
- availableInputTokens: number;
618
- remainingInputTokens: number;
619
- reservedOutputTokens: number;
620
- reservedSafetyTokens: number;
621
- load: number;
622
- overflowTokens: number;
623
- } | undefined;
624
- /** Adaptive trigger signals observed alongside token pressure. */
625
- signals?: {
626
- repeatedReadCount?: number | undefined;
627
- } | undefined;
628
- /** Full compaction report from the compactor. */
629
- report: {
630
- before: number;
631
- after: number;
632
- reductions: {
633
- phase: string;
634
- saved: number;
635
- }[];
636
- };
637
- /** Whether aggressive (summary) mode was used. */
638
- aggressive: boolean;
639
- };
640
- /**
641
- * Fired when the auto-compaction middleware's compactor.compact() call
642
- * throws. Compaction is best-effort by design so we don't crash the agent
643
- * loop, but a persistent failure (misconfigured summarizer model, network
644
- * outage) means the next iteration may hit context overflow. Observability
645
- * layers / dashboards subscribe to this to surface the silent regression.
646
- */
647
- 'compaction.failed': {
648
- sessionId?: string | undefined;
649
- err: Error;
650
- aggressive: boolean;
651
- level: 'warn' | 'soft' | 'hard';
652
- tokens: number;
653
- maxContext: number;
654
- budget?: {
655
- maxContext: number;
656
- inputTokens: number;
657
- availableInputTokens: number;
658
- remainingInputTokens: number;
659
- reservedOutputTokens: number;
660
- reservedSafetyTokens: number;
661
- load: number;
662
- overflowTokens: number;
663
- } | undefined;
664
- signals?: {
665
- repeatedReadCount?: number | undefined;
666
- } | undefined;
667
- load: number;
668
- fatal: boolean;
669
- };
670
- /**
671
- * Subagent lifecycle events. Emitted by `MultiAgentHost` so the TUI can
672
- * surface what's happening in the fleet without needing director-mode
673
- * (which renders the live FleetPanel). These complement the FleetBus
674
- * (director-only) by giving the TUI a uniform feed for both `/spawn`
675
- * and director-orchestrated work.
676
- */
677
- 'subagent.spawned': {
678
- /** Parent/host session id. Subagents remain children of this session. */
679
- sessionId?: string | undefined;
680
- subagentId: string;
681
- taskId: string;
682
- name?: string | undefined;
683
- provider?: string | undefined;
684
- model?: string | undefined;
685
- description?: string | undefined;
686
- /**
687
- * Absolute path to the per-subagent JSONL transcript on disk, when
688
- * one was created. Undefined when the subagent shares the parent
689
- * session writer (in-memory or single-file configurations).
690
- * Surfaced so the TUI (FleetPanel) and `/fleet log` can show the
691
- * user *where* to look without computing it from the run id.
692
- */
693
- transcriptPath?: string | undefined;
694
- };
695
- 'subagent.task_started': {
696
- /** Parent/host session id. */
697
- sessionId?: string | undefined;
698
- subagentId: string;
699
- taskId: string;
700
- description?: string | undefined;
701
- };
702
- /**
703
- * Fired by `MultiAgentHost` when a subagent hits a soft budget limit
704
- * and the coordinator is auto-extending. TUI renders this as a
705
- * status-line notice: "⚡ agent#name hitting kind limit (used/limit) — extending".
706
- * After the auto-extend the task either continues or the coordinator
707
- * denies the extension and the task ends with 'budget_exhausted'.
708
- */
709
- 'subagent.budget_warning': {
710
- /** Parent/host session id. */
711
- sessionId?: string | undefined;
712
- subagentId: string;
713
- kind: string;
714
- used: number;
715
- limit: number;
716
- };
717
- /**
718
- * Emitted when the coordinator/director actually GRANTS a budget
719
- * extension to a subagent (the resolution of a `budget.threshold_reached`
720
- * negotiation). Distinct from `subagent.budget_warning`, which fires when
721
- * a limit is merely *hit*. UIs use this to render a persistent "⚡ extended
722
- * ×N" badge so users can see how often an agent self-extended to stay
723
- * alive. `totalExtensions` is the cumulative count for this subagent across
724
- * all kinds; `newLimit` is the patched value for `kind`.
725
- */
726
- 'subagent.budget_extended': {
727
- /** Parent/host session id. */
728
- sessionId?: string | undefined;
729
- subagentId: string;
730
- kind: string;
731
- newLimit: number;
732
- totalExtensions: number;
733
- };
734
- /**
735
- * Per-tool-call event re-emitted from a subagent's own EventBus
736
- * onto the host EventBus, so the TUI / non-director surfaces can
737
- * render "AGENT#1 ● bash 250ms" without having to subscribe to
738
- * the director-only FleetBus. Fired AFTER the tool completes
739
- * (paired with `tool.executed`). Includes the subagent id so
740
- * multiple parallel subagents are distinguishable.
741
- */
742
- 'subagent.tool_executed': {
743
- /** Parent/host session id. */
744
- sessionId?: string | undefined;
745
- subagentId: string;
746
- taskId?: string | undefined;
747
- name: string;
748
- durationMs: number;
749
- ok: boolean;
750
- input?: unknown | undefined;
751
- outputBytes?: number | undefined;
752
- };
753
- /**
754
- * Periodic progress snapshot emitted by the subagent runner every ~25
755
- * iterations so the user can track what a subagent is doing without
756
- * looking at the FleetPanel. The leader's TUI surfaces this as a
757
- * chat history entry: "AGENT#2 💬 L25 · 47 tools · $0.023 · doing grep..."
758
- * Fired on a best-effort basis — slow subagents may skip emissions if
759
- * the 25-iteration window passes while the agent is between tool calls.
760
- */
761
- 'subagent.iteration_summary': {
762
- /** Parent/host session id. */
763
- sessionId?: string | undefined;
764
- subagentId: string;
765
- iteration: number;
766
- toolCalls: number;
767
- costUsd: number;
768
- currentTool?: string | undefined;
769
- partialText?: string | undefined;
770
- };
771
- 'subagent.task_completed': {
772
- /** Parent/host session id. */
773
- sessionId?: string | undefined;
774
- subagentId: string;
775
- taskId: string;
776
- status: 'success' | 'failed' | 'timeout' | 'stopped';
777
- iterations: number;
778
- toolCalls: number;
779
- durationMs: number;
780
- /**
781
- * Structured failure envelope when `status !== 'success'`. Carries
782
- * `kind` (one of `SubagentErrorKind`), `message`, `retryable`, and
783
- * optional `backoffMs`. UIs branch on `kind` to render the right
784
- * chip (rate_limit vs auth vs tool_failed). The type is imported
785
- * lazily as a structural object to avoid a coordination → kernel
786
- * cycle in the dependency graph.
787
- */
788
- error?: {
789
- kind: string;
790
- message: string;
791
- retryable: boolean;
792
- backoffMs?: number | undefined;
793
- cause?: {
794
- name: string | undefined;
795
- message: string;
796
- stack?: string | undefined;
797
- } | undefined;
798
- } | undefined;
799
- /** Final assistant text from the subagent's last turn. */
800
- finalText?: string | undefined;
801
- };
802
- /**
803
- * Fired after a subagent has been removed from the live coordinator and its
804
- * resources released. Surfaces must delete the agent instead of retaining a
805
- * terminal/idle card indefinitely.
806
- */
807
- 'subagent.removed': {
808
- sessionId?: string | undefined;
809
- subagentId: string;
810
- reason?: string | undefined;
811
- };
812
- /**
813
- * Fired by the delegate tool when a subagent finishes. The agent's run
814
- * loop listens for this to collect `delegateSummaries` for the RunResult,
815
- * so the CLI/TUI can render flashy completion banners.
816
- */
817
- 'subagent.done': {
818
- sessionId?: string | undefined;
819
- summary: string;
820
- ok: boolean;
821
- };
822
- /**
823
- * Fired by MultiAgentHost when a subagent's context window load changes.
824
- * The leader agent's ctx.pct is emitted directly on the host EventBus;
825
- * subagent ctx.pct events are forwarded here with subagentId attribution.
826
- * TUI uses this to render live context fill bars per agent.
827
- */
828
- 'subagent.ctx_pct': {
829
- /** Parent/host session id. */
830
- sessionId?: string | undefined;
831
- subagentId: string;
832
- /** Fraction of maxContext currently in use, clamped to 0..1 for display. */
833
- load: number;
834
- /** Unclamped fraction when available. Can exceed 1 when over budget. */
835
- rawLoad?: number | undefined;
836
- tokens: number;
837
- maxContext: number;
838
- };
839
- /**
840
- * A supervision rule detected a condition worth engaging on (starvation,
841
- * overload, backlog, stuck agent, failure streak). Fires even when the
842
- * subsequent decision is "do nothing" — the signal trail is the audit log.
843
- */
844
- 'fleet.supervisor.signal': {
845
- sessionId?: string | undefined;
846
- /** Rule kind, e.g. 'pinned_starvation' | 'overloaded_worker' | 'backlog' | 'stuck_agent' | 'failure_streak' | 'idle_with_work'. */
847
- kind: string;
848
- subagentId?: string | undefined;
849
- taskId?: string | undefined;
850
- detail: string;
851
- };
852
- /**
853
- * The supervisor consulted its decision path for a signal. `via:'rule'`
854
- * means the deterministic policy answered without an LLM; `via:'brain'`
855
- * means the tiered BrainArbiter was engaged. `outcome:'escalated'` =
856
- * unresolved ask_human, no action taken.
857
- */
858
- 'fleet.supervisor.decision': {
859
- sessionId?: string | undefined;
860
- kind: string;
861
- proposedAction: string;
862
- via: 'rule' | 'brain';
863
- outcome: 'approved' | 'denied' | 'escalated' | 'skipped';
864
- rationale?: string | undefined;
865
- };
866
- /** The supervisor executed (or failed to execute) an approved action. */
867
- 'fleet.supervisor.action': {
868
- sessionId?: string | undefined;
869
- action: 'retarget' | 'spawn_helper' | 'steer' | 'notify_leader' | 'terminate';
870
- subagentId?: string | undefined;
871
- taskId?: string | undefined;
872
- ok: boolean;
873
- detail?: string | undefined;
874
- };
875
- /** A parallel SDD run started. */
876
- 'sdd.run.started': {
877
- sessionId?: string | undefined;
878
- runId: string;
879
- graphId: string;
880
- specId?: string | undefined;
881
- total: number;
882
- /** Base branch the run's squash commits will land on (worktree runs only). */
883
- baseBranch?: string | undefined;
884
- };
885
- /** A parallel SDD run reached a terminal state. */
886
- 'sdd.run.finished': {
887
- sessionId?: string | undefined;
888
- runId: string;
889
- deadlocked: boolean;
890
- completed: number;
891
- failed: number;
892
- stopped: boolean;
893
- };
894
- /** A task began executing on a worker (carries who + which worktree). */
895
- 'sdd.task.started': {
896
- sessionId?: string | undefined;
897
- runId: string;
898
- taskId: string;
899
- subagentId: string;
900
- agentName: string;
901
- worktreeBranch?: string | undefined;
902
- };
903
- /** A task finished successfully. */
904
- 'sdd.task.completed': {
905
- sessionId?: string | undefined;
906
- runId: string;
907
- taskId: string;
908
- subagentId: string;
909
- durationMs: number;
910
- };
911
- /** A task failed terminally (retries exhausted). */
912
- 'sdd.task.failed': {
913
- sessionId?: string | undefined;
914
- runId: string;
915
- taskId: string;
916
- subagentId: string;
917
- error: string;
918
- };
919
- /** A failed task was requeued for another attempt. */
920
- 'sdd.task.retrying': {
921
- sessionId?: string | undefined;
922
- runId: string;
923
- taskId: string;
924
- attempt: number;
925
- maxRetries: number;
926
- };
927
- /** A task's worker reported success but the post-task verification gate rejected it. */
928
- 'sdd.task.verification_failed': {
929
- sessionId?: string | undefined;
930
- runId: string;
931
- taskId: string;
932
- reason: string;
933
- };
934
- /** A completed task's worktree could not be merged back into the base branch. */
935
- 'sdd.task.conflict': {
936
- sessionId?: string | undefined;
937
- runId: string;
938
- taskId: string;
939
- conflictFiles: string[];
940
- };
941
- /** A completed task's worktree was squash-merged onto the base branch (sha = the run commit). */
942
- 'sdd.task.merged': {
943
- sessionId?: string | undefined;
944
- runId: string;
945
- taskId: string;
946
- sha: string;
947
- };
948
- /** A task was split into sub-tasks (the parent becomes a completed container). */
949
- 'sdd.task.split': {
950
- sessionId?: string | undefined;
951
- runId: string;
952
- taskId: string;
953
- subtaskIds: string[];
954
- };
955
- /** The supervisor made a decision about a failing/stuck task. */
956
- 'sdd.supervisor.decision': {
957
- sessionId?: string | undefined;
958
- runId: string;
959
- taskId: string;
960
- action: 'retry' | 'reassign' | 'split' | 'fail';
961
- rationale?: string | undefined;
962
- };
963
- /** A new wave of dependency-ready tasks began. */
964
- 'sdd.wave': {
965
- sessionId?: string | undefined;
966
- runId: string;
967
- wave: number;
968
- batchSize: number;
969
- };
970
- /** No runnable tasks remain but some are still blocked — with the blocking chains. */
971
- 'sdd.deadlock': {
972
- sessionId?: string | undefined;
973
- runId: string;
974
- chains: Array<{
975
- blocked: string;
976
- blockedBy: string[];
977
- }>;
978
- };
979
- /**
980
- * Throttled full board snapshot composed by SddBoardProjector. `snapshot` is
981
- * an `SddBoardSnapshot` (sdd/board-types) — typed `unknown` here so the kernel
982
- * layer never imports from the higher `sdd/` layer (it sits below it in the
983
- * DAG); consumers cast it back. The producer (SddBoardProjector) is typed.
984
- */
985
- 'sdd.board.snapshot': {
986
- sessionId?: string | undefined;
987
- runId: string;
988
- snapshot: unknown;
989
- };
990
- 'mcp.server.connected': {
991
- name: string;
992
- toolCount: number;
993
- };
994
- 'mcp.server.reconnected': {
995
- name: string;
996
- toolCount: number;
997
- };
998
- 'mcp.server.disconnected': {
999
- name: string;
1000
- reason: string;
1001
- };
1002
- 'token.cost_estimate_unavailable': {
1003
- sessionId?: string | undefined;
1004
- model: string;
1005
- };
1006
- /** Fired by SessionWriter.writeCheckpoint() after the checkpoint event is appended to JSONL. */
1007
- 'checkpoint.written': {
1008
- sessionId?: string | undefined;
1009
- promptIndex: number;
1010
- promptPreview: string;
1011
- ts: string;
1012
- fileCount: number;
1013
- };
1014
- /**
1015
- * Fired by SessionWriter.writeInFlightMarker() — the agent loop has
1016
- * started a long-running operation. Pairs with `in_flight.ended`
1017
- * on clean shutdown. A marker with no end indicates a crash.
1018
- * (Idea #1 from IDEAS.md — Stateful Session Recovery.)
1019
- */
1020
- 'in_flight.started': {
1021
- sessionId?: string | undefined;
1022
- context: string;
1023
- ts: string;
1024
- };
1025
- /** Fired by SessionWriter.clearInFlightMarker() — operation completed cleanly. */
1026
- 'in_flight.ended': {
1027
- sessionId?: string | undefined;
1028
- reason: 'clean' | 'aborted' | 'recovered';
1029
- ts: string;
1030
- };
1031
- /**
1032
- * Fired after a session rewind completes: files are reverted and the session
1033
- * history is truncated. The TUI listens to this to update its checkpoint
1034
- * list and clear history entries that are now invalid.
1035
- */
1036
- 'session.rewound': {
1037
- sessionId?: string | undefined;
1038
- toPromptIndex: number;
1039
- revertedFiles: string[];
1040
- removedEvents: number;
1041
- };
1042
- /**
1043
- * Fired by the multi-agent coordinator on FleetBus whenever subagent
1044
- * counts change (spawn/stop/complete). The TUI subscribes to render
1045
- * live fleet counters without polling.
1046
- */
1047
- 'coordinator.stats': {
1048
- sessionId?: string | undefined;
1049
- total: number;
1050
- running: number;
1051
- idle: number;
1052
- stopped: number;
1053
- inFlight: number;
1054
- pending: number;
1055
- completed: number;
1056
- subagentStatuses: {
1057
- subagentId: string;
1058
- taskId: string;
1059
- status: string;
1060
- assigned: boolean;
1061
- }[];
1062
- };
1063
- /**
1064
- * The coordinator's max-concurrent subagent ceiling was changed at runtime
1065
- * (e.g. via `/fleet concurrency <n>`). `n` is the new ceiling. Lets the
1066
- * TUI/WebUI reflect the updated limit without polling the host.
1067
- */
1068
- 'concurrency.changed': {
1069
- sessionId?: string | undefined;
1070
- n: number;
1071
- };
1072
- /**
1073
- * Git-worktree lifecycle, emitted by WorktreeManager. AutoPhase allocates one
1074
- * worktree per phase so parallelizable phases run isolated, then merges them
1075
- * back sequentially. The WebUI/TUI subscribe to render live swim-lanes/DAG.
1076
- */
1077
- 'worktree.allocated': {
1078
- sessionId?: string | undefined;
1079
- handleId: string;
1080
- ownerId: string;
1081
- ownerLabel: string;
1082
- slug: string;
1083
- dir: string;
1084
- branch: string;
1085
- baseBranch: string;
1086
- };
1087
- 'worktree.committed': {
1088
- sessionId?: string | undefined;
1089
- handleId: string;
1090
- ownerId: string;
1091
- branch: string;
1092
- committed: boolean;
1093
- insertions: number;
1094
- deletions: number;
1095
- files: number;
1096
- sha?: string | undefined;
1097
- };
1098
- 'worktree.merged': {
1099
- sessionId?: string | undefined;
1100
- handleId: string;
1101
- ownerId: string;
1102
- branch: string;
1103
- baseBranch: string;
1104
- squash: boolean;
1105
- };
1106
- 'worktree.conflict': {
1107
- sessionId?: string | undefined;
1108
- handleId: string;
1109
- ownerId: string;
1110
- branch: string;
1111
- conflictFiles: string[];
1112
- };
1113
- 'worktree.released': {
1114
- sessionId?: string | undefined;
1115
- handleId: string;
1116
- ownerId: string;
1117
- branch: string;
1118
- kept: boolean;
1119
- };
1120
- 'worktree.failed': {
1121
- sessionId?: string | undefined;
1122
- handleId: string;
1123
- ownerId: string;
1124
- branch?: string | undefined;
1125
- error: string;
1126
- };
1127
- /**
1128
- * Auto-proceed countdown tick, emitted once per second by the REPL while
1129
- * autonomy mode `auto` is counting down to self-driving the next suggestion.
1130
- * `remaining` is the number of whole seconds left. Display-only: the TUI
1131
- * StatusBar renders it as an "auto-proceed in Ns" chip; no consumer should
1132
- * derive behavior from it (the REPL owns the actual timer).
1133
- */
1134
- 'countdown.tick': {
1135
- sessionId?: string | undefined;
1136
- remaining: number;
1137
- };
1138
- 'memory.remembered': MemoryRememberedPayload;
1139
- 'memory.forgotten': MemoryForgottenPayload;
1140
- 'memory.cleared': MemoryClearedPayload;
1141
- 'memory.consolidated': MemoryConsolidatedPayload;
1142
- /** Structured Super Memory lifecycle events. Kept structural so core never depends on the package. */
1143
- 'memory.accepted': {
1144
- memoryId: string;
1145
- sessionId?: string | undefined;
1146
- traceId?: string | undefined;
1147
- };
1148
- 'memory.candidate_created': {
1149
- candidateId: string;
1150
- sessionId?: string | undefined;
1151
- traceId?: string | undefined;
1152
- };
1153
- 'memory.candidate_rejected': {
1154
- candidateId: string;
1155
- reason: string;
1156
- sessionId?: string | undefined;
1157
- traceId?: string | undefined;
1158
- };
1159
- 'memory.updated': {
1160
- memoryId: string;
1161
- status: string;
1162
- sessionId?: string | undefined;
1163
- traceId?: string | undefined;
1164
- };
1165
- 'memory.merged': {
1166
- memoryId: string;
1167
- mergedIds: string[];
1168
- sessionId?: string | undefined;
1169
- traceId?: string | undefined;
1170
- };
1171
- 'memory.superseded': {
1172
- memoryId: string;
1173
- supersededBy: string;
1174
- sessionId?: string | undefined;
1175
- traceId?: string | undefined;
1176
- };
1177
- 'memory.contradicted': {
1178
- memoryId: string;
1179
- contradicts: string[];
1180
- sessionId?: string | undefined;
1181
- traceId?: string | undefined;
1182
- };
1183
- 'memory.staled': {
1184
- memoryId: string;
1185
- reason: string;
1186
- sessionId?: string | undefined;
1187
- traceId?: string | undefined;
1188
- };
1189
- 'memory.archived': {
1190
- memoryId: string;
1191
- reason: string;
1192
- sessionId?: string | undefined;
1193
- traceId?: string | undefined;
1194
- };
1195
- 'memory.injected': {
1196
- memoryIds: string[];
1197
- trigger: string;
1198
- sessionId?: string | undefined;
1199
- traceId?: string | undefined;
1200
- };
1201
- 'memory.verified': {
1202
- memoryId: string;
1203
- status: string;
1204
- sessionId?: string | undefined;
1205
- traceId?: string | undefined;
1206
- };
1207
- 'memory.hygiene_started': {
1208
- examined: number;
1209
- sessionId?: string | undefined;
1210
- traceId?: string | undefined;
1211
- };
1212
- 'memory.hygiene_completed': {
1213
- examined: number;
1214
- deduplicated: number;
1215
- staled: number;
1216
- archived: number;
1217
- sessionId?: string | undefined;
1218
- traceId?: string | undefined;
1219
- };
1220
- 'memory.graph_edge_added': {
1221
- edgeId: string;
1222
- from: string;
1223
- to: string;
1224
- relation: string;
1225
- sessionId?: string | undefined;
1226
- traceId?: string | undefined;
1227
- };
1228
- /**
1229
- * Fired when a store completes a read operation. Carries the session ID
1230
- * and file path so dashboards can correlate storage I/O with agent
1231
- * iterations via the session ID.
1232
- */
1233
- 'storage.read': {
1234
- sessionId: string;
1235
- /** Which store was read. */
1236
- store: 'session' | 'goal' | 'plan' | 'project' | 'todos' | 'queue' | 'tasks' | 'completed-work' | 'memory' | 'annotations' | 'audit' | 'replay' | 'config';
1237
- filePath: string;
1238
- /** Session store: load|list|summary|index_read. Goal store: load. Plan store: load. Memory store: readAll. Annotations: list. Audit: verify|load. Replay: load|lookup. Config: read_json|load_sync. Completed-work: load. */
1239
- operation: string;
1240
- outcome: 'success' | 'failure';
1241
- durationMs: number;
1242
- error?: string;
1243
- traceId?: string;
1244
- };
1245
- /**
1246
- * Fired when a store completes a write operation. Covers both individual
1247
- * event appends and batch flushes — check `eventCount` to distinguish.
1248
- */
1249
- 'storage.write': {
1250
- sessionId: string;
1251
- store: 'session' | 'goal' | 'plan' | 'project' | 'todos' | 'queue' | 'tasks' | 'completed-work' | 'memory' | 'annotations' | 'audit' | 'replay' | 'config';
1252
- filePath: string;
1253
- /** Session store: create|resume|append|flush|close|index_append|compact|checkpoint.
1254
- * Goal store: save|update|delete. Plan store: save. Project manifest: manifest_write.
1255
- * Todos: save. Queue: write|clear. Tasks: save. Memory: remember|forget|clear|consolidate.
1256
- * Annotations: add|resolve|evict. Audit: record. Replay: record|compact. Config: persist_sync.
1257
- * Completed-work: save. */
1258
- operation: string;
1259
- outcome: 'success' | 'failure';
1260
- durationMs: number;
1261
- eventCount?: number;
1262
- error?: string;
1263
- traceId?: string;
1264
- };
1265
- /**
1266
- * Fired when a store operation fails after best-effort retries.
1267
- * Use this for alert-worthy persistent failures (disk full, permissions).
1268
- */
1269
- 'storage.error': {
1270
- sessionId: string;
1271
- store: 'session' | 'goal' | 'plan' | 'project' | 'todos' | 'queue' | 'tasks' | 'completed-work' | 'memory' | 'annotations' | 'audit' | 'replay' | 'config';
1272
- filePath: string;
1273
- operation: string;
1274
- outcome?: 'failure';
1275
- error: string;
1276
- recoverable: boolean;
1277
- durationMs?: number;
1278
- traceId?: string;
1279
- };
1280
- /**
1281
- * Real-time client status event. Emitted by TUI/CLI/WebUI to report current
1282
- * session stats (tool calls, tokens, model, mode, cost). Broadcast immediately
1283
- * to all WebUI clients via setup-events.ts and written to status.json for
1284
- * external watchers.
1285
- */
1286
- 'client.status': {
1287
- /** Active session represented by this client status update. */
1288
- sessionId?: string | undefined;
1289
- clientType: string;
1290
- clientId: string;
1291
- projectHash: string;
1292
- agentCount: number;
1293
- model: string;
1294
- mode: string;
1295
- toolCalls: number;
1296
- inputTokens: number;
1297
- outputTokens: number;
1298
- cacheTokens: number;
1299
- costUsd: number;
1300
- timestamp: number;
1301
- projectSlug: string;
1302
- };
1303
- error: {
1304
- sessionId?: string | undefined;
1305
- err: Error;
1306
- phase: string;
1307
- _original?: Error | undefined;
1308
- };
38
+ export interface EventMap extends AgentEventMap, BrainEventMap, SessionEventMap, ProviderEventMap, ToolEventMap, MemoryEventMap, SddEventMap, WorktreeEventMap, FleetEventMap {
1309
39
  }
1310
40
  export type EventName = keyof EventMap;
1311
41
  export type Listener<E extends EventName> = (payload: EventMap[E]) => void;