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