aemeathcli 1.0.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 (102) hide show
  1. package/README.md +607 -0
  2. package/dist/App-P4MYD4QY.js +2719 -0
  3. package/dist/App-P4MYD4QY.js.map +1 -0
  4. package/dist/api-key-fallback-YQQBOQIL.js +11 -0
  5. package/dist/api-key-fallback-YQQBOQIL.js.map +1 -0
  6. package/dist/chunk-4IJD72YB.js +184 -0
  7. package/dist/chunk-4IJD72YB.js.map +1 -0
  8. package/dist/chunk-6PDJ45T4.js +325 -0
  9. package/dist/chunk-6PDJ45T4.js.map +1 -0
  10. package/dist/chunk-CARHU3DO.js +562 -0
  11. package/dist/chunk-CARHU3DO.js.map +1 -0
  12. package/dist/chunk-CGEV3ARR.js +80 -0
  13. package/dist/chunk-CGEV3ARR.js.map +1 -0
  14. package/dist/chunk-CS5X3BWX.js +27 -0
  15. package/dist/chunk-CS5X3BWX.js.map +1 -0
  16. package/dist/chunk-CYQNBB25.js +44 -0
  17. package/dist/chunk-CYQNBB25.js.map +1 -0
  18. package/dist/chunk-DAHGLHNR.js +657 -0
  19. package/dist/chunk-DAHGLHNR.js.map +1 -0
  20. package/dist/chunk-H66O5Z2V.js +305 -0
  21. package/dist/chunk-H66O5Z2V.js.map +1 -0
  22. package/dist/chunk-HCIHOHLX.js +322 -0
  23. package/dist/chunk-HCIHOHLX.js.map +1 -0
  24. package/dist/chunk-HMJRPNPZ.js +1031 -0
  25. package/dist/chunk-HMJRPNPZ.js.map +1 -0
  26. package/dist/chunk-I5PZ4JTS.js +119 -0
  27. package/dist/chunk-I5PZ4JTS.js.map +1 -0
  28. package/dist/chunk-IYW62KKR.js +255 -0
  29. package/dist/chunk-IYW62KKR.js.map +1 -0
  30. package/dist/chunk-JAXXTYID.js +51 -0
  31. package/dist/chunk-JAXXTYID.js.map +1 -0
  32. package/dist/chunk-LSOYPSAT.js +183 -0
  33. package/dist/chunk-LSOYPSAT.js.map +1 -0
  34. package/dist/chunk-MFBHNWGV.js +416 -0
  35. package/dist/chunk-MFBHNWGV.js.map +1 -0
  36. package/dist/chunk-MXZSI3AY.js +311 -0
  37. package/dist/chunk-MXZSI3AY.js.map +1 -0
  38. package/dist/chunk-NBR3GHMT.js +72 -0
  39. package/dist/chunk-NBR3GHMT.js.map +1 -0
  40. package/dist/chunk-O3ZF22SW.js +246 -0
  41. package/dist/chunk-O3ZF22SW.js.map +1 -0
  42. package/dist/chunk-SUSJPZU2.js +181 -0
  43. package/dist/chunk-SUSJPZU2.js.map +1 -0
  44. package/dist/chunk-TEVZS4FA.js +310 -0
  45. package/dist/chunk-TEVZS4FA.js.map +1 -0
  46. package/dist/chunk-UY2SYSEZ.js +211 -0
  47. package/dist/chunk-UY2SYSEZ.js.map +1 -0
  48. package/dist/chunk-WAHVZH7V.js +260 -0
  49. package/dist/chunk-WAHVZH7V.js.map +1 -0
  50. package/dist/chunk-WPP3PEDE.js +234 -0
  51. package/dist/chunk-WPP3PEDE.js.map +1 -0
  52. package/dist/chunk-Y5XVD2CD.js +1610 -0
  53. package/dist/chunk-Y5XVD2CD.js.map +1 -0
  54. package/dist/chunk-YL5XFHR3.js +56 -0
  55. package/dist/chunk-YL5XFHR3.js.map +1 -0
  56. package/dist/chunk-ZGOHARPV.js +122 -0
  57. package/dist/chunk-ZGOHARPV.js.map +1 -0
  58. package/dist/claude-adapter-QMLFMSP3.js +6 -0
  59. package/dist/claude-adapter-QMLFMSP3.js.map +1 -0
  60. package/dist/claude-login-5WELXPKT.js +324 -0
  61. package/dist/claude-login-5WELXPKT.js.map +1 -0
  62. package/dist/cli.d.ts +1 -0
  63. package/dist/cli.js +703 -0
  64. package/dist/cli.js.map +1 -0
  65. package/dist/codex-login-7HHLJHBF.js +164 -0
  66. package/dist/codex-login-7HHLJHBF.js.map +1 -0
  67. package/dist/config-store-W6FBCQAQ.js +6 -0
  68. package/dist/config-store-W6FBCQAQ.js.map +1 -0
  69. package/dist/executor-6RIKIGXK.js +4 -0
  70. package/dist/executor-6RIKIGXK.js.map +1 -0
  71. package/dist/gemini-adapter-6JIHZ7WI.js +6 -0
  72. package/dist/gemini-adapter-6JIHZ7WI.js.map +1 -0
  73. package/dist/gemini-login-ZZLYC3J6.js +346 -0
  74. package/dist/gemini-login-ZZLYC3J6.js.map +1 -0
  75. package/dist/index.d.ts +2210 -0
  76. package/dist/index.js +1419 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/kimi-adapter-JN4HFFHU.js +6 -0
  79. package/dist/kimi-adapter-JN4HFFHU.js.map +1 -0
  80. package/dist/kimi-login-CZPS63NK.js +149 -0
  81. package/dist/kimi-login-CZPS63NK.js.map +1 -0
  82. package/dist/native-cli-adapters-OLW3XX57.js +6 -0
  83. package/dist/native-cli-adapters-OLW3XX57.js.map +1 -0
  84. package/dist/ollama-adapter-OJQ3FKWK.js +6 -0
  85. package/dist/ollama-adapter-OJQ3FKWK.js.map +1 -0
  86. package/dist/openai-adapter-XU46EN7B.js +6 -0
  87. package/dist/openai-adapter-XU46EN7B.js.map +1 -0
  88. package/dist/registry-4KD24ZC3.js +6 -0
  89. package/dist/registry-4KD24ZC3.js.map +1 -0
  90. package/dist/registry-H7B3AHPQ.js +5 -0
  91. package/dist/registry-H7B3AHPQ.js.map +1 -0
  92. package/dist/server-manager-PTGBHCLS.js +5 -0
  93. package/dist/server-manager-PTGBHCLS.js.map +1 -0
  94. package/dist/session-manager-ECEEACGY.js +12 -0
  95. package/dist/session-manager-ECEEACGY.js.map +1 -0
  96. package/dist/team-manager-HC4XGCFY.js +11 -0
  97. package/dist/team-manager-HC4XGCFY.js.map +1 -0
  98. package/dist/tmux-manager-GPYZ3WQH.js +6 -0
  99. package/dist/tmux-manager-GPYZ3WQH.js.map +1 -0
  100. package/dist/tools-TSMXMHIF.js +6 -0
  101. package/dist/tools-TSMXMHIF.js.map +1 -0
  102. package/package.json +89 -0
@@ -0,0 +1,2210 @@
1
+ import Database from 'better-sqlite3';
2
+ import { Socket } from 'node:net';
3
+
4
+ /**
5
+ * Model-related types per PRD sections 7.1-7.5
6
+ */
7
+ type ProviderName = "anthropic" | "openai" | "google" | "kimi" | "ollama";
8
+ type ModelRole = "planning" | "coding" | "review" | "testing" | "bugfix" | "documentation";
9
+ interface IModelInfo {
10
+ readonly id: string;
11
+ readonly name: string;
12
+ readonly provider: ProviderName;
13
+ readonly contextWindow: number;
14
+ readonly maxOutputTokens: number;
15
+ readonly inputPricePerMToken: number;
16
+ readonly outputPricePerMToken: number;
17
+ readonly supportsStreaming: boolean;
18
+ readonly supportsToolCalling: boolean;
19
+ readonly supportedRoles: readonly ModelRole[];
20
+ readonly description?: string | undefined;
21
+ }
22
+ interface IRoleConfig {
23
+ readonly primary: string;
24
+ readonly fallback: readonly string[];
25
+ }
26
+ type ModelResolutionSource = "user_override" | "role_config" | "fallback_chain" | "system_default";
27
+ interface IModelResolution {
28
+ readonly modelId: string;
29
+ readonly provider: ProviderName;
30
+ readonly source: ModelResolutionSource;
31
+ readonly role?: ModelRole | undefined;
32
+ }
33
+ interface ITokenUsage {
34
+ readonly inputTokens: number;
35
+ readonly outputTokens: number;
36
+ readonly totalTokens: number;
37
+ readonly costUsd: number;
38
+ }
39
+ declare const SUPPORTED_MODELS: Record<string, IModelInfo>;
40
+ declare const DEFAULT_MODEL_ID = "claude-sonnet-4-6";
41
+
42
+ /**
43
+ * Message types per PRD sections 7.1, 8.4
44
+ */
45
+
46
+ type MessageRole = "user" | "assistant" | "system" | "tool";
47
+ interface IChatMessage {
48
+ readonly id: string;
49
+ readonly role: MessageRole;
50
+ readonly content: string;
51
+ readonly model?: string | undefined;
52
+ readonly provider?: ProviderName | undefined;
53
+ readonly toolCalls?: readonly IToolCall[] | undefined;
54
+ readonly tokenUsage?: ITokenUsage | undefined;
55
+ readonly createdAt: Date;
56
+ }
57
+ interface IToolCall {
58
+ readonly id: string;
59
+ readonly name: string;
60
+ readonly arguments: Record<string, unknown>;
61
+ }
62
+ interface IToolResult {
63
+ readonly toolCallId: string;
64
+ readonly name: string;
65
+ readonly content: string;
66
+ readonly isError: boolean;
67
+ }
68
+ type StreamChunkType = "text" | "tool_call" | "usage" | "done" | "error";
69
+ interface IStreamChunk {
70
+ readonly type: StreamChunkType;
71
+ readonly content?: string | undefined;
72
+ readonly toolCall?: IToolCall | undefined;
73
+ readonly usage?: ITokenUsage | undefined;
74
+ readonly error?: string | undefined;
75
+ }
76
+ interface IChatRequest {
77
+ readonly model: string;
78
+ readonly messages: readonly IChatMessage[];
79
+ readonly system?: string | undefined;
80
+ readonly tools?: readonly IToolDefinition[] | undefined;
81
+ readonly maxTokens?: number | undefined;
82
+ readonly temperature?: number | undefined;
83
+ }
84
+ interface IChatResponse {
85
+ readonly id: string;
86
+ readonly model: string;
87
+ readonly provider: ProviderName;
88
+ readonly message: IChatMessage;
89
+ readonly usage: ITokenUsage;
90
+ readonly finishReason: "stop" | "tool_calls" | "max_tokens" | "error";
91
+ }
92
+ interface IToolParameter {
93
+ readonly name: string;
94
+ readonly type: string;
95
+ readonly description: string;
96
+ readonly required: boolean;
97
+ readonly default?: unknown | undefined;
98
+ readonly enum?: readonly string[] | undefined;
99
+ }
100
+ interface IToolDefinition {
101
+ readonly name: string;
102
+ readonly description: string;
103
+ readonly parameters: readonly IToolParameter[];
104
+ }
105
+ type AgentMessageType = "message" | "broadcast" | "shutdown_request" | "shutdown_response" | "plan_approval_request" | "plan_approval_response" | "task_update";
106
+ interface IAgentMessage {
107
+ readonly type: AgentMessageType;
108
+ readonly senderId: string;
109
+ readonly recipientId?: string | undefined;
110
+ readonly content: string;
111
+ readonly summary?: string | undefined;
112
+ readonly requestId?: string | undefined;
113
+ readonly approve?: boolean | undefined;
114
+ readonly timestamp: Date;
115
+ }
116
+
117
+ /**
118
+ * Tool types per PRD sections 5.1, 14.4
119
+ */
120
+
121
+ type PermissionMode = "strict" | "standard" | "permissive";
122
+ type ToolCategory = "file" | "search" | "shell" | "web" | "git" | "mcp";
123
+ interface IToolRegistration {
124
+ readonly definition: IToolDefinition;
125
+ readonly category: ToolCategory;
126
+ readonly requiresApproval: (mode: PermissionMode, args: Record<string, unknown>) => boolean;
127
+ readonly execute: (args: Record<string, unknown>) => Promise<IToolResult>;
128
+ }
129
+ interface IToolExecutionContext {
130
+ readonly workingDirectory: string;
131
+ readonly permissionMode: PermissionMode;
132
+ readonly projectRoot: string;
133
+ readonly allowedPaths: readonly string[];
134
+ readonly blockedCommands: readonly string[];
135
+ }
136
+ interface IToolRegistry {
137
+ register(tool: IToolRegistration): void;
138
+ get(name: string): IToolRegistration | undefined;
139
+ getAll(): readonly IToolRegistration[];
140
+ getDefinitions(): readonly IToolDefinition[];
141
+ execute(call: IToolCall, context: IToolExecutionContext): Promise<IToolResult>;
142
+ }
143
+
144
+ /**
145
+ * Team types per PRD section 8
146
+ */
147
+
148
+ type TaskStatus = "pending" | "in_progress" | "completed" | "blocked";
149
+ interface ITask {
150
+ readonly id: string;
151
+ subject: string;
152
+ description: string;
153
+ status: TaskStatus;
154
+ owner?: string | undefined;
155
+ model?: string | undefined;
156
+ role?: ModelRole | undefined;
157
+ blocks: string[];
158
+ blockedBy: string[];
159
+ readonly createdAt: Date;
160
+ updatedAt: Date;
161
+ }
162
+ type AgentStatus = "idle" | "active" | "error" | "shutdown";
163
+ interface IAgentConfig {
164
+ readonly name: string;
165
+ readonly agentId: string;
166
+ readonly agentType: string;
167
+ readonly model: string;
168
+ readonly provider: ProviderName;
169
+ readonly role: ModelRole;
170
+ }
171
+ interface IAgentState {
172
+ readonly config: IAgentConfig;
173
+ status: AgentStatus;
174
+ currentTaskId?: string | undefined;
175
+ paneId?: string | undefined;
176
+ }
177
+ type TeamStatus = "active" | "completed" | "error";
178
+ interface ITeamConfig {
179
+ readonly teamName: string;
180
+ readonly description?: string | undefined;
181
+ status: TeamStatus;
182
+ readonly members: readonly IAgentConfig[];
183
+ readonly createdAt: Date;
184
+ }
185
+ type IPCMethod = "agent.register" | "agent.streamChunk" | "agent.taskUpdate" | "agent.message" | "hub.taskAssign" | "hub.shutdown";
186
+ interface IIPCMessage {
187
+ readonly jsonrpc: "2.0";
188
+ readonly method: IPCMethod;
189
+ readonly params: Record<string, unknown>;
190
+ readonly id?: number | undefined;
191
+ }
192
+ type PaneLayout = "auto" | "horizontal" | "vertical" | "grid";
193
+ interface IPaneConfig {
194
+ readonly paneId: string;
195
+ readonly agentName: string;
196
+ readonly model: string;
197
+ readonly role: ModelRole;
198
+ readonly title: string;
199
+ }
200
+ interface ILayoutConfig {
201
+ readonly layout: PaneLayout;
202
+ readonly panes: readonly IPaneConfig[];
203
+ readonly maxPanes: number;
204
+ }
205
+
206
+ /**
207
+ * Configuration types per PRD section 17.3
208
+ */
209
+
210
+ interface IProviderConfig {
211
+ readonly enabled: boolean;
212
+ readonly baseUrl?: string | undefined;
213
+ }
214
+ interface IPermissionConfig {
215
+ readonly mode: PermissionMode;
216
+ readonly allowedPaths: readonly string[];
217
+ readonly blockedCommands: readonly string[];
218
+ }
219
+ type PaneBackend = "tmux" | "iterm2";
220
+ interface ISplitPanelConfig {
221
+ readonly enabled: boolean;
222
+ readonly backend: PaneBackend;
223
+ readonly defaultLayout: PaneLayout;
224
+ readonly maxPanes: number;
225
+ }
226
+ interface ICostConfig {
227
+ readonly budgetWarning: number;
228
+ readonly budgetHardStop: number;
229
+ readonly currency: string;
230
+ }
231
+ interface ITelemetryConfig {
232
+ readonly enabled: boolean;
233
+ readonly anonymized: boolean;
234
+ }
235
+ interface IOAuthProviderConfig {
236
+ readonly clientId: string;
237
+ readonly clientSecret?: string | undefined;
238
+ readonly authorizeUrl?: string | undefined;
239
+ readonly tokenUrl?: string | undefined;
240
+ readonly scope?: string | undefined;
241
+ }
242
+ interface IOAuthConfig {
243
+ readonly anthropic?: IOAuthProviderConfig | undefined;
244
+ readonly openai?: IOAuthProviderConfig | undefined;
245
+ readonly google?: IOAuthProviderConfig | undefined;
246
+ readonly kimi?: IOAuthProviderConfig | undefined;
247
+ }
248
+ interface IGlobalConfig {
249
+ readonly version: string;
250
+ readonly defaultModel: string;
251
+ readonly roles: Partial<Record<ModelRole, IRoleConfig>>;
252
+ readonly providers: Partial<Record<ProviderName, IProviderConfig>>;
253
+ readonly permissions: IPermissionConfig;
254
+ readonly splitPanel: ISplitPanelConfig;
255
+ readonly cost: ICostConfig;
256
+ readonly telemetry: ITelemetryConfig;
257
+ readonly oauth?: IOAuthConfig | undefined;
258
+ }
259
+ interface IMCPServerConfig {
260
+ readonly command: string;
261
+ readonly args: readonly string[];
262
+ readonly env?: Readonly<Record<string, string>> | undefined;
263
+ }
264
+ interface IMCPConfig {
265
+ readonly mcpServers: Readonly<Record<string, IMCPServerConfig>>;
266
+ }
267
+ interface ISkillFrontmatter {
268
+ readonly name: string;
269
+ readonly description: string;
270
+ readonly version: string;
271
+ readonly "allowed-tools"?: readonly string[] | undefined;
272
+ readonly triggers: readonly string[];
273
+ readonly "model-requirements"?: {
274
+ readonly "preferred-role"?: ModelRole | undefined;
275
+ readonly "min-context"?: number | undefined;
276
+ } | undefined;
277
+ }
278
+ interface ISkillDefinition {
279
+ readonly frontmatter: ISkillFrontmatter;
280
+ readonly body: string;
281
+ readonly filePath: string;
282
+ }
283
+ type AuthMethod = "native_login" | "api_key" | "env_variable" | "credential_helper";
284
+ interface ICredential {
285
+ readonly provider: ProviderName;
286
+ readonly method: AuthMethod;
287
+ readonly token?: string | undefined;
288
+ readonly refreshToken?: string | undefined;
289
+ readonly expiresAt?: Date | undefined;
290
+ readonly email?: string | undefined;
291
+ readonly plan?: string | undefined;
292
+ }
293
+ declare const DEFAULT_CONFIG: IGlobalConfig;
294
+
295
+ /**
296
+ * AemeathCLI Typed Error Hierarchy
297
+ * Per PRD section 15.5: Every error includes code, user message, diagnostic, recovery action
298
+ */
299
+ interface IErrorContext {
300
+ readonly code: string;
301
+ readonly userMessage: string;
302
+ readonly diagnosticMessage?: string | undefined;
303
+ readonly suggestedRecovery?: string | undefined;
304
+ }
305
+ declare abstract class AemeathError extends Error {
306
+ abstract readonly code: string;
307
+ abstract readonly userMessage: string;
308
+ diagnosticMessage?: string | undefined;
309
+ suggestedRecovery?: string | undefined;
310
+ constructor(message: string, context?: Partial<IErrorContext>);
311
+ }
312
+ declare class AuthenticationError extends AemeathError {
313
+ readonly code: "AEMEATH_PROVIDER_AUTH_001";
314
+ readonly userMessage: string;
315
+ constructor(provider: string, message?: string);
316
+ }
317
+ declare class RateLimitError extends AemeathError {
318
+ readonly code: "AEMEATH_PROVIDER_RATE_001";
319
+ readonly userMessage: string;
320
+ readonly retryAfterMs: number;
321
+ constructor(provider: string, retryAfterMs: number);
322
+ }
323
+ declare class ContextOverflowError extends AemeathError {
324
+ readonly code: "AEMEATH_PROVIDER_CTX_001";
325
+ readonly userMessage: string;
326
+ constructor(model: string, maxTokens: number, currentTokens: number);
327
+ }
328
+ declare class ModelNotFoundError extends AemeathError {
329
+ readonly code: "AEMEATH_PROVIDER_MODEL_001";
330
+ readonly userMessage: string;
331
+ constructor(model: string);
332
+ }
333
+ declare class MissingConfigError extends AemeathError {
334
+ readonly code: "AEMEATH_CONFIG_MISS_001";
335
+ readonly userMessage: string;
336
+ constructor(key: string);
337
+ }
338
+ declare class InvalidConfigError extends AemeathError {
339
+ readonly code: "AEMEATH_CONFIG_INVALID_001";
340
+ readonly userMessage: string;
341
+ constructor(key: string, reason: string);
342
+ }
343
+ declare class FileNotFoundError extends AemeathError {
344
+ readonly code: "AEMEATH_TOOL_FILE_001";
345
+ readonly userMessage: string;
346
+ constructor(filePath: string);
347
+ }
348
+ declare class PermissionDeniedError extends AemeathError {
349
+ readonly code: "AEMEATH_TOOL_PERM_001";
350
+ readonly userMessage: string;
351
+ constructor(operation: string, resource: string);
352
+ }
353
+ declare class ExecutionTimeoutError extends AemeathError {
354
+ readonly code: "AEMEATH_TOOL_TIMEOUT_001";
355
+ readonly userMessage: string;
356
+ constructor(command: string, timeoutMs: number);
357
+ }
358
+ declare class AgentSpawnError extends AemeathError {
359
+ readonly code: "AEMEATH_TEAM_SPAWN_001";
360
+ readonly userMessage: string;
361
+ constructor(agentName: string, reason: string);
362
+ }
363
+ declare class IPCError extends AemeathError {
364
+ readonly code: "AEMEATH_TEAM_IPC_001";
365
+ readonly userMessage: string;
366
+ constructor(message: string);
367
+ }
368
+ declare class ServerConnectionError extends AemeathError {
369
+ readonly code: "AEMEATH_MCP_CONN_001";
370
+ readonly userMessage: string;
371
+ constructor(serverName: string, reason: string);
372
+ }
373
+ declare class ToolCallError extends AemeathError {
374
+ readonly code: "AEMEATH_MCP_TOOL_001";
375
+ readonly userMessage: string;
376
+ constructor(toolName: string, reason: string);
377
+ }
378
+
379
+ /**
380
+ * Typed event emitter per PRD section 6.1
381
+ * Core IPC backbone for the orchestration layer.
382
+ */
383
+ type EventHandler<T = unknown> = (data: T) => void;
384
+ interface IEventMap {
385
+ "model:request": {
386
+ model: string;
387
+ role?: string;
388
+ };
389
+ "model:response": {
390
+ model: string;
391
+ tokens: number;
392
+ cost: number;
393
+ };
394
+ "model:stream:chunk": {
395
+ model: string;
396
+ content: string;
397
+ };
398
+ "model:stream:done": {
399
+ model: string;
400
+ totalTokens: number;
401
+ };
402
+ "model:error": {
403
+ model: string;
404
+ error: Error;
405
+ };
406
+ "tool:call": {
407
+ name: string;
408
+ args: Record<string, unknown>;
409
+ };
410
+ "tool:result": {
411
+ name: string;
412
+ isError: boolean;
413
+ content: string;
414
+ };
415
+ "team:created": {
416
+ teamName: string;
417
+ agentCount: number;
418
+ };
419
+ "team:deleted": {
420
+ teamName: string;
421
+ };
422
+ "agent:spawned": {
423
+ agentName: string;
424
+ model: string;
425
+ };
426
+ "agent:status": {
427
+ agentName: string;
428
+ status: string;
429
+ };
430
+ "agent:message": {
431
+ from: string;
432
+ to: string;
433
+ content: string;
434
+ };
435
+ "task:created": {
436
+ taskId: string;
437
+ subject: string;
438
+ };
439
+ "task:updated": {
440
+ taskId: string;
441
+ status: string;
442
+ };
443
+ "task:completed": {
444
+ taskId: string;
445
+ };
446
+ "cost:updated": {
447
+ total: number;
448
+ provider: string;
449
+ delta: number;
450
+ };
451
+ "cost:warning": {
452
+ current: number;
453
+ limit: number;
454
+ };
455
+ "cost:exceeded": {
456
+ current: number;
457
+ limit: number;
458
+ };
459
+ "pane:created": {
460
+ paneId: string;
461
+ agentName: string;
462
+ };
463
+ "pane:closed": {
464
+ paneId: string;
465
+ };
466
+ "skill:activated": {
467
+ skillName: string;
468
+ };
469
+ "skill:deactivated": {
470
+ skillName: string;
471
+ };
472
+ "mcp:server:started": {
473
+ serverName: string;
474
+ };
475
+ "mcp:server:stopped": {
476
+ serverName: string;
477
+ };
478
+ "mcp:server:error": {
479
+ serverName: string;
480
+ error: string;
481
+ };
482
+ "config:changed": {
483
+ key: string;
484
+ };
485
+ "auth:login": {
486
+ provider: string;
487
+ email?: string;
488
+ };
489
+ "auth:logout": {
490
+ provider: string;
491
+ };
492
+ }
493
+ type EventName = keyof IEventMap;
494
+ declare class EventBus {
495
+ private readonly listeners;
496
+ on<K extends EventName>(event: K, handler: EventHandler<IEventMap[K]>): () => void;
497
+ once<K extends EventName>(event: K, handler: EventHandler<IEventMap[K]>): () => void;
498
+ emit<K extends EventName>(event: K, data: IEventMap[K]): void;
499
+ removeAllListeners(event?: EventName): void;
500
+ listenerCount(event: EventName): number;
501
+ }
502
+ declare function getEventBus(): EventBus;
503
+
504
+ /**
505
+ * Role-based model selection per PRD section 7.2
506
+ * Resolution pipeline: user override → role config → fallback chain → system default
507
+ */
508
+
509
+ interface IModelRouterConfig {
510
+ readonly defaultModel: string;
511
+ readonly roles: Partial<Record<ModelRole, IRoleConfig>>;
512
+ readonly enabledProviders: readonly ProviderName[];
513
+ }
514
+ declare class ModelRouter {
515
+ private readonly config;
516
+ private userOverride;
517
+ constructor(config: IModelRouterConfig);
518
+ /**
519
+ * Set a temporary user override that takes highest priority.
520
+ */
521
+ setUserOverride(modelId: string | undefined): void;
522
+ /**
523
+ * Resolve the best model for a given role through the priority pipeline.
524
+ */
525
+ resolve(role?: ModelRole): IModelResolution;
526
+ /**
527
+ * Check if a model is available (provider is enabled and model is known).
528
+ */
529
+ isModelAvailable(modelId: string): boolean;
530
+ /**
531
+ * Get model info by ID. Throws if not found.
532
+ */
533
+ getModelInfo(modelId: string): IModelInfo;
534
+ /**
535
+ * Get all available models (from enabled providers).
536
+ */
537
+ getAvailableModels(): readonly IModelInfo[];
538
+ /**
539
+ * List models recommended for a specific role.
540
+ */
541
+ getModelsForRole(role: ModelRole): readonly IModelInfo[];
542
+ /**
543
+ * Validate that a model ID exists. Throws ModelNotFoundError if not.
544
+ */
545
+ private validateModel;
546
+ }
547
+ /**
548
+ * Create a ModelRouter from the global config.
549
+ */
550
+ declare function createModelRouter(config: IGlobalConfig): ModelRouter;
551
+
552
+ /**
553
+ * Context window management per PRD section 7.4
554
+ * - Token budgeting: 85% conversation, 15% buffer
555
+ * - Smart truncation: prioritize recent + system prompt
556
+ * - Compression: summarize old messages when approaching limits
557
+ * - File context tracking with LRU eviction
558
+ */
559
+
560
+ interface IFileContextEntry {
561
+ readonly filePath: string;
562
+ readonly tokenCount: number;
563
+ lastAccessedAt: number;
564
+ }
565
+ declare class ContextManager {
566
+ private readonly maxTokens;
567
+ private readonly budgetTokens;
568
+ private readonly fileContext;
569
+ private currentTokenCount;
570
+ constructor(modelInfo: IModelInfo);
571
+ /**
572
+ * Get the available token budget for new content.
573
+ */
574
+ getAvailableBudget(): number;
575
+ /**
576
+ * Get total context usage.
577
+ */
578
+ getUsage(): {
579
+ used: number;
580
+ budget: number;
581
+ max: number;
582
+ percentage: number;
583
+ };
584
+ /**
585
+ * Trim messages to fit within the context window.
586
+ * Preserves system prompt and most recent messages.
587
+ */
588
+ trimMessages(messages: readonly IChatMessage[], systemPrompt?: string): IChatMessage[];
589
+ /**
590
+ * Track a file being added to context.
591
+ */
592
+ addFileContext(filePath: string, content: string): void;
593
+ /**
594
+ * Touch a file (update last accessed time).
595
+ */
596
+ touchFile(filePath: string): void;
597
+ /**
598
+ * Remove a file from context.
599
+ */
600
+ removeFileContext(filePath: string): void;
601
+ /**
602
+ * Evict least-recently-used files to free space.
603
+ */
604
+ evictLRU(tokensNeeded: number): string[];
605
+ /**
606
+ * Get all tracked files.
607
+ */
608
+ getTrackedFiles(): readonly IFileContextEntry[];
609
+ /**
610
+ * Reset context tracking (for model switch).
611
+ */
612
+ reset(): void;
613
+ }
614
+
615
+ /**
616
+ * Real-time cost tracking per PRD section 7.5
617
+ * - Per-request cost calculation
618
+ * - Session total
619
+ * - Breakdown by provider, model, and role
620
+ * - Configurable budget alerts
621
+ */
622
+
623
+ interface ICostEntry$1 {
624
+ readonly provider: ProviderName;
625
+ readonly model: string;
626
+ readonly role?: ModelRole | undefined;
627
+ readonly usage: ITokenUsage;
628
+ readonly timestamp: Date;
629
+ }
630
+ interface ICostBreakdown {
631
+ readonly byProvider: Record<string, number>;
632
+ readonly byModel: Record<string, number>;
633
+ readonly byRole: Record<string, number>;
634
+ }
635
+ declare class CostTracker {
636
+ private readonly entries;
637
+ private readonly budgetConfig;
638
+ private warningEmitted;
639
+ constructor(budgetConfig: ICostConfig);
640
+ /**
641
+ * Record a cost entry from a model response.
642
+ */
643
+ record(provider: ProviderName, model: string, inputTokens: number, outputTokens: number, role?: ModelRole): ITokenUsage;
644
+ /**
645
+ * Get total session cost.
646
+ */
647
+ getSessionTotal(): number;
648
+ /**
649
+ * Get total token counts.
650
+ */
651
+ getSessionTokens(): {
652
+ input: number;
653
+ output: number;
654
+ total: number;
655
+ };
656
+ /**
657
+ * Get cost breakdown by provider, model, and role.
658
+ */
659
+ getBreakdown(): ICostBreakdown;
660
+ /**
661
+ * Check if budget hard stop has been exceeded.
662
+ */
663
+ isBudgetExceeded(): boolean;
664
+ /**
665
+ * Get formatted session summary.
666
+ */
667
+ getSummary(): string;
668
+ /**
669
+ * Get all cost entries (for export).
670
+ */
671
+ getEntries(): readonly ICostEntry$1[];
672
+ /**
673
+ * Reset cost tracking for a new session.
674
+ */
675
+ reset(): void;
676
+ }
677
+
678
+ /**
679
+ * Tool permission management per PRD section 14.4
680
+ * Permission modes: strict, standard, permissive
681
+ */
682
+
683
+ interface IPermissionRequest {
684
+ readonly toolName: string;
685
+ readonly category: ToolCategory;
686
+ readonly operation: string;
687
+ readonly resource?: string;
688
+ readonly command?: string;
689
+ }
690
+ interface IPermissionResult {
691
+ readonly allowed: boolean;
692
+ readonly reason?: string;
693
+ readonly requiresUserApproval: boolean;
694
+ }
695
+ declare class PermissionManager {
696
+ private mode;
697
+ private readonly allowedPaths;
698
+ private readonly blockedCommands;
699
+ private readonly approvedOperations;
700
+ constructor(mode: PermissionMode, allowedPaths: readonly string[], blockedCommands: readonly string[]);
701
+ /**
702
+ * Check if an operation is permitted.
703
+ */
704
+ check(request: IPermissionRequest): IPermissionResult;
705
+ /**
706
+ * Record that the user has approved an operation.
707
+ */
708
+ approve(request: IPermissionRequest): void;
709
+ /**
710
+ * Update permission mode.
711
+ */
712
+ setMode(mode: PermissionMode): void;
713
+ /**
714
+ * Get current mode.
715
+ */
716
+ getMode(): PermissionMode;
717
+ private checkStandardMode;
718
+ private checkStrictMode;
719
+ private isReadOperation;
720
+ private isDangerousCommand;
721
+ private getOperationKey;
722
+ }
723
+
724
+ /**
725
+ * Agent team task coordination per PRD section 8
726
+ * Manages task creation, assignment, dependency resolution, and completion tracking.
727
+ */
728
+
729
+ declare class TaskOrchestrator {
730
+ private readonly tasks;
731
+ /**
732
+ * Create a new task.
733
+ */
734
+ createTask(subject: string, description: string, options?: {
735
+ owner?: string;
736
+ model?: string;
737
+ role?: ModelRole;
738
+ blockedBy?: string[];
739
+ }): ITask;
740
+ /**
741
+ * Update task status.
742
+ */
743
+ updateStatus(taskId: string, status: TaskStatus): void;
744
+ /**
745
+ * Assign a task to an agent.
746
+ */
747
+ assignTask(taskId: string, owner: string, model?: string): void;
748
+ /**
749
+ * Get a task by ID. Throws if not found.
750
+ */
751
+ getTask(taskId: string): ITask;
752
+ /**
753
+ * Get all tasks.
754
+ */
755
+ getAllTasks(): readonly ITask[];
756
+ /**
757
+ * Get tasks by status.
758
+ */
759
+ getTasksByStatus(status: TaskStatus): readonly ITask[];
760
+ /**
761
+ * Get tasks assigned to an agent.
762
+ */
763
+ getTasksByOwner(owner: string): readonly ITask[];
764
+ /**
765
+ * Get tasks that are ready to be worked on (pending, not blocked).
766
+ */
767
+ getAvailableTasks(): readonly ITask[];
768
+ /**
769
+ * Check if all tasks are completed.
770
+ */
771
+ isAllComplete(): boolean;
772
+ /**
773
+ * Get progress summary.
774
+ */
775
+ getProgress(): {
776
+ total: number;
777
+ completed: number;
778
+ inProgress: number;
779
+ pending: number;
780
+ blocked: number;
781
+ };
782
+ /**
783
+ * Delete a task.
784
+ */
785
+ deleteTask(taskId: string): void;
786
+ /**
787
+ * When a task completes, check if any blocked tasks can now proceed.
788
+ */
789
+ private resolveBlockedTasks;
790
+ }
791
+
792
+ /**
793
+ * Unified provider interface per PRD section 7.1
794
+ * All AI providers implement IModelProvider for consistent access.
795
+ */
796
+
797
+ /**
798
+ * Unified interface for all AI model providers.
799
+ * Adapters for Claude, OpenAI, Gemini, Kimi, and Ollama all implement this.
800
+ */
801
+ interface IModelProvider {
802
+ readonly name: string;
803
+ readonly supportedModels: readonly string[];
804
+ /** Send a non-streaming chat request. */
805
+ chat(request: IChatRequest): Promise<IChatResponse>;
806
+ /** Send a streaming chat request returning an async iterable of chunks. */
807
+ stream(request: IChatRequest): AsyncIterable<IStreamChunk>;
808
+ /** Estimate token count for text using the specified model's tokenizer. */
809
+ countTokens(text: string, model: string): Promise<number>;
810
+ /** Retrieve static model metadata. */
811
+ getModelInfo(model: string): IModelInfo;
812
+ /** Dynamically fetch available model IDs from the provider API. Optional. */
813
+ listAvailableModels?(): Promise<readonly string[]>;
814
+ }
815
+ /**
816
+ * Options for constructing a provider adapter.
817
+ */
818
+ interface IProviderOptions {
819
+ readonly apiKey?: string;
820
+ readonly baseUrl?: string;
821
+ }
822
+
823
+ /**
824
+ * Provider registry per PRD section 7.1
825
+ * Central registry for provider adapters — register, resolve, list.
826
+ */
827
+
828
+ /**
829
+ * Singleton registry that maps provider names and model IDs to provider adapters.
830
+ */
831
+ declare class ProviderRegistry {
832
+ private readonly providers;
833
+ private readonly modelToProvider;
834
+ /**
835
+ * Register a provider adapter.
836
+ * Automatically indexes all supported models to this provider.
837
+ */
838
+ register(provider: IModelProvider): void;
839
+ /**
840
+ * Get a provider adapter by its name (e.g. "anthropic", "openai").
841
+ */
842
+ getByName(name: string): IModelProvider | undefined;
843
+ /**
844
+ * Get the provider adapter that supports a given model ID.
845
+ * @throws ModelNotFoundError if no provider serves this model.
846
+ */
847
+ getForModel(modelId: string): IModelProvider;
848
+ /**
849
+ * Resolve a model string to its provider.
850
+ * Supports both model IDs ("claude-sonnet-4-6") and provider-prefixed
851
+ * forms ("anthropic:claude-sonnet-4-6").
852
+ */
853
+ resolve(modelString: string): {
854
+ provider: IModelProvider;
855
+ modelId: string;
856
+ };
857
+ /**
858
+ * List all registered model IDs across all providers.
859
+ */
860
+ listModels(): readonly IModelInfo[];
861
+ /**
862
+ * List all registered provider names.
863
+ */
864
+ listProviders(): readonly string[];
865
+ /**
866
+ * Check if a model ID is supported by any registered provider.
867
+ */
868
+ hasModel(modelId: string): boolean;
869
+ /**
870
+ * Check if a provider is registered.
871
+ */
872
+ hasProvider(name: string): boolean;
873
+ /**
874
+ * List available models from all providers.
875
+ * Uses dynamic API listing where supported, falls back to static models.
876
+ */
877
+ listAllAvailableModels(): Promise<Map<string, readonly string[]>>;
878
+ }
879
+
880
+ /**
881
+ * Claude (Anthropic) adapter via Vercel AI SDK per PRD section 7.1
882
+ * Supports Claude Opus 4.6, Sonnet 4.6, Haiku 4.5
883
+ */
884
+
885
+ declare class ClaudeAdapter implements IModelProvider {
886
+ readonly name: ProviderName;
887
+ readonly supportedModels: readonly string[];
888
+ private readonly anthropic;
889
+ constructor(options?: IProviderOptions);
890
+ chat(request: IChatRequest): Promise<IChatResponse>;
891
+ stream(request: IChatRequest): AsyncIterable<IStreamChunk>;
892
+ countTokens(text: string, _model: string): Promise<number>;
893
+ getModelInfo(model: string): IModelInfo;
894
+ }
895
+
896
+ /**
897
+ * OpenAI adapter via Vercel AI SDK per PRD section 7.1
898
+ * Supports GPT-5.3 Codex, GPT-5.2, GPT-5.1 Codex series
899
+ */
900
+
901
+ declare class OpenAIAdapter implements IModelProvider {
902
+ readonly name: ProviderName;
903
+ readonly supportedModels: readonly string[];
904
+ private readonly openai;
905
+ private readonly apiKey;
906
+ private readonly baseUrl;
907
+ constructor(options?: IProviderOptions);
908
+ chat(request: IChatRequest): Promise<IChatResponse>;
909
+ stream(request: IChatRequest): AsyncIterable<IStreamChunk>;
910
+ countTokens(text: string, _model: string): Promise<number>;
911
+ getModelInfo(model: string): IModelInfo;
912
+ listAvailableModels(): Promise<readonly string[]>;
913
+ }
914
+
915
+ /**
916
+ * Gemini (Google) adapter via Vercel AI SDK per PRD section 7.1
917
+ * Supports Gemini 2.5 Pro, Gemini 2.5 Flash
918
+ */
919
+
920
+ declare class GeminiAdapter implements IModelProvider {
921
+ readonly name: ProviderName;
922
+ readonly supportedModels: readonly string[];
923
+ private readonly google;
924
+ constructor(options?: IProviderOptions);
925
+ chat(request: IChatRequest): Promise<IChatResponse>;
926
+ stream(request: IChatRequest): AsyncIterable<IStreamChunk>;
927
+ countTokens(text: string, _model: string): Promise<number>;
928
+ getModelInfo(model: string): IModelInfo;
929
+ }
930
+
931
+ /**
932
+ * Kimi (Moonshot) adapter — custom HTTP per PRD section 7.1
933
+ * Uses OpenAI-compatible API format via fetch().
934
+ * Supports Kimi Code (kimi-for-coding)
935
+ */
936
+
937
+ declare class KimiAdapter implements IModelProvider {
938
+ readonly name: ProviderName;
939
+ readonly supportedModels: readonly string[];
940
+ private readonly baseUrl;
941
+ private readonly apiKey;
942
+ constructor(options?: IProviderOptions);
943
+ chat(request: IChatRequest): Promise<IChatResponse>;
944
+ stream(request: IChatRequest): AsyncIterable<IStreamChunk>;
945
+ countTokens(text: string, _model: string): Promise<number>;
946
+ getModelInfo(model: string): IModelInfo;
947
+ listAvailableModels(): Promise<readonly string[]>;
948
+ private parseSSEStream;
949
+ }
950
+
951
+ /**
952
+ * Ollama adapter — custom HTTP for local models per PRD section 7.1
953
+ * Uses OpenAI-compatible API format at localhost:11434.
954
+ * Dynamic model listing from Ollama API.
955
+ */
956
+
957
+ declare class OllamaAdapter implements IModelProvider {
958
+ readonly name: ProviderName;
959
+ private readonly baseUrl;
960
+ private cachedModels;
961
+ constructor(options?: IProviderOptions);
962
+ get supportedModels(): readonly string[];
963
+ /**
964
+ * Refresh available models from Ollama API.
965
+ * Call once during initialization.
966
+ */
967
+ refreshModels(): Promise<readonly string[]>;
968
+ chat(request: IChatRequest): Promise<IChatResponse>;
969
+ stream(request: IChatRequest): AsyncIterable<IStreamChunk>;
970
+ countTokens(text: string, _model: string): Promise<number>;
971
+ getModelInfo(model: string): IModelInfo;
972
+ listAvailableModels(): Promise<readonly string[]>;
973
+ private parseSSEStream;
974
+ }
975
+
976
+ /**
977
+ * Native CLI-backed provider adapters.
978
+ * Uses official provider CLIs in non-interactive mode when credentials come from native login.
979
+ */
980
+
981
+ interface ICLIResult {
982
+ readonly text: string;
983
+ readonly inputTokens?: number | undefined;
984
+ readonly outputTokens?: number | undefined;
985
+ readonly finishReason?: IChatResponse["finishReason"] | undefined;
986
+ }
987
+ declare abstract class BaseNativeCLIAdapter implements IModelProvider {
988
+ abstract readonly name: ProviderName;
989
+ abstract readonly supportedModels: readonly string[];
990
+ protected abstract runCLI(model: string, prompt: string): Promise<ICLIResult>;
991
+ chat(request: IChatRequest): Promise<IChatResponse>;
992
+ stream(request: IChatRequest): AsyncIterable<IStreamChunk>;
993
+ countTokens(text: string, _model: string): Promise<number>;
994
+ getModelInfo(model: string): IModelInfo;
995
+ listAvailableModels(): Promise<readonly string[]>;
996
+ }
997
+ declare class ClaudeNativeCLIAdapter extends BaseNativeCLIAdapter {
998
+ readonly name: ProviderName;
999
+ readonly supportedModels: readonly ["claude-opus-4-6", "claude-opus-4-6-1m", "claude-sonnet-4-6", "claude-sonnet-4-6-1m", "claude-haiku-4-5"];
1000
+ protected runCLI(model: string, prompt: string): Promise<ICLIResult>;
1001
+ }
1002
+ declare class CodexNativeCLIAdapter extends BaseNativeCLIAdapter {
1003
+ readonly name: ProviderName;
1004
+ readonly supportedModels: readonly ["gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.2-codex", "gpt-5.1-codex-max", "gpt-5.2", "gpt-5.1-codex-mini"];
1005
+ protected runCLI(model: string, prompt: string): Promise<ICLIResult>;
1006
+ }
1007
+ declare class GeminiNativeCLIAdapter extends BaseNativeCLIAdapter {
1008
+ readonly name: ProviderName;
1009
+ readonly supportedModels: readonly ["gemini-3-pro-preview", "gemini-3-flash-preview", "gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.5-flash-lite"];
1010
+ protected runCLI(model: string, prompt: string): Promise<ICLIResult>;
1011
+ }
1012
+ declare class KimiNativeCLIAdapter extends BaseNativeCLIAdapter {
1013
+ readonly name: ProviderName;
1014
+ readonly supportedModels: readonly ["kimi-for-coding"];
1015
+ protected runCLI(_model: string, prompt: string): Promise<ICLIResult>;
1016
+ }
1017
+
1018
+ /**
1019
+ * Tool Registry — central registry for all built-in and MCP tools.
1020
+ * Per PRD sections 5.1, 14.4
1021
+ */
1022
+
1023
+ declare class ToolRegistry implements IToolRegistry {
1024
+ private readonly tools;
1025
+ private readonly categoryIndex;
1026
+ register(tool: IToolRegistration): void;
1027
+ get(name: string): IToolRegistration | undefined;
1028
+ getAll(): readonly IToolRegistration[];
1029
+ getDefinitions(): readonly IToolDefinition[];
1030
+ getByCategory(category: ToolCategory): readonly IToolRegistration[];
1031
+ execute(call: IToolCall, context: IToolExecutionContext): Promise<IToolResult>;
1032
+ }
1033
+
1034
+ /**
1035
+ * Tools barrel export and default registry factory.
1036
+ * Per PRD section 5.1
1037
+ */
1038
+
1039
+ declare function createDefaultRegistry(context: IToolExecutionContext): ToolRegistry;
1040
+
1041
+ /**
1042
+ * Credential storage per PRD section 13.6
1043
+ * Primary: OS keychain via node-keytar
1044
+ * Fallback: AES-256-GCM encrypted file
1045
+ */
1046
+
1047
+ declare class CredentialStore {
1048
+ private keytarAvailable;
1049
+ /**
1050
+ * Store a credential for a provider.
1051
+ */
1052
+ set(provider: ProviderName, credential: ICredential): Promise<void>;
1053
+ /**
1054
+ * Get a credential for a provider.
1055
+ */
1056
+ get(provider: ProviderName): Promise<ICredential | undefined>;
1057
+ /**
1058
+ * Delete a credential for a provider.
1059
+ */
1060
+ delete(provider: ProviderName): Promise<void>;
1061
+ /**
1062
+ * Check if a credential exists for a provider.
1063
+ */
1064
+ has(provider: ProviderName): Promise<boolean>;
1065
+ private getEncryptionKey;
1066
+ private storeEncrypted;
1067
+ private loadEncrypted;
1068
+ private deleteEncrypted;
1069
+ private encryptFile;
1070
+ private decryptFile;
1071
+ private isKeytarAvailable;
1072
+ private getKeytar;
1073
+ }
1074
+
1075
+ /**
1076
+ * Multi-provider session lifecycle per PRD section 13.5
1077
+ * Resolution priority: native login (CLI delegation) > API key > env variable > credential helper
1078
+ *
1079
+ * Credentials are obtained by delegating to official CLI tools:
1080
+ * - Claude Code CLI → macOS Keychain
1081
+ * - Codex CLI → ~/.codex/auth.json
1082
+ * - Gemini CLI → ~/.gemini/oauth_creds.json
1083
+ * - Kimi CLI → ~/.kimi/credentials/kimi-code.json
1084
+ */
1085
+
1086
+ declare class SessionManager {
1087
+ private readonly credentialStore;
1088
+ private readonly apiKeyFallback;
1089
+ constructor(store?: CredentialStore);
1090
+ /**
1091
+ * Get the best available credential for a provider.
1092
+ * Follows resolution priority from PRD section 13.5.
1093
+ */
1094
+ getActiveCredential(provider: ProviderName): Promise<ICredential>;
1095
+ /**
1096
+ * Check if a provider has any available credential.
1097
+ */
1098
+ isAuthenticated(provider: ProviderName): Promise<boolean>;
1099
+ /**
1100
+ * Get status info for a provider.
1101
+ */
1102
+ getStatus(provider: ProviderName): Promise<{
1103
+ loggedIn: boolean;
1104
+ method?: AuthMethod | undefined;
1105
+ email?: string | undefined;
1106
+ plan?: string | undefined;
1107
+ }>;
1108
+ /**
1109
+ * Get the API key or token string for a provider.
1110
+ */
1111
+ getToken(provider: ProviderName): Promise<string>;
1112
+ /**
1113
+ * Re-read tokens from the official CLI's cached storage.
1114
+ * This is the "refresh" mechanism — instead of doing HTTP refresh ourselves,
1115
+ * we re-read from the CLI tool's cache which may have been refreshed by the CLI.
1116
+ */
1117
+ private refreshFromCliCache;
1118
+ private loadLoginModule;
1119
+ private isExpired;
1120
+ private getFromEnvironment;
1121
+ }
1122
+
1123
+ /**
1124
+ * SQLite database store — PRD section 17.1
1125
+ * Uses better-sqlite3 with WAL mode for concurrent reads.
1126
+ * Runs migrations on startup. Provides raw query interface.
1127
+ */
1128
+
1129
+ declare class SqliteStore {
1130
+ private db;
1131
+ private closed;
1132
+ get database(): Database.Database;
1133
+ open(dbPath?: string): void;
1134
+ private runMigrations;
1135
+ prepare(sql: string): Database.Statement;
1136
+ run(sql: string, ...params: readonly unknown[]): Database.RunResult;
1137
+ get<T>(sql: string, ...params: readonly unknown[]): T | undefined;
1138
+ all<T>(sql: string, ...params: readonly unknown[]): T[];
1139
+ transaction<T>(fn: () => T): T;
1140
+ close(): void;
1141
+ private registerCleanupHandlers;
1142
+ }
1143
+
1144
+ /**
1145
+ * Configuration store — PRD sections 17.2, 17.3
1146
+ * Loads/saves global and project config with Zod validation.
1147
+ * Merges project config over global config.
1148
+ * Watches for config file changes.
1149
+ */
1150
+
1151
+ type ConfigChangeCallback = (config: IGlobalConfig) => void;
1152
+ declare class ConfigStore {
1153
+ private globalConfig;
1154
+ private projectConfig;
1155
+ private mergedConfig;
1156
+ private watchers;
1157
+ private changeCallbacks;
1158
+ get config(): IGlobalConfig;
1159
+ loadGlobal(configPath?: string): IGlobalConfig;
1160
+ loadProject(projectRoot: string): IGlobalConfig;
1161
+ saveGlobal(config?: IGlobalConfig, configPath?: string): void;
1162
+ saveProject(projectRoot: string, config: Partial<IGlobalConfig>): void;
1163
+ watchGlobal(configPath?: string): void;
1164
+ watchProject(projectRoot: string): void;
1165
+ onChange(callback: ConfigChangeCallback): void;
1166
+ stopWatching(): void;
1167
+ private watchConfigFile;
1168
+ private rebuildMergedConfig;
1169
+ private applyDefaults;
1170
+ }
1171
+
1172
+ /**
1173
+ * Conversation store types — database row types and public interfaces.
1174
+ * Extracted to keep conversation-store.ts under 400 lines.
1175
+ */
1176
+
1177
+ interface IConversation {
1178
+ readonly id: string;
1179
+ readonly projectRoot: string;
1180
+ readonly defaultModel: string | null;
1181
+ readonly createdAt: string;
1182
+ readonly updatedAt: string;
1183
+ readonly metadata: Record<string, unknown>;
1184
+ }
1185
+ interface IMessage {
1186
+ readonly id: number;
1187
+ readonly conversationId: string;
1188
+ readonly role: MessageRole;
1189
+ readonly model: string | null;
1190
+ readonly provider: ProviderName | null;
1191
+ readonly content: string;
1192
+ readonly toolCalls: unknown[] | null;
1193
+ readonly tokenUsage: IStoredTokenUsage | null;
1194
+ readonly createdAt: string;
1195
+ }
1196
+ interface IStoredTokenUsage {
1197
+ readonly input: number;
1198
+ readonly output: number;
1199
+ readonly cost: number;
1200
+ }
1201
+ interface IFileContext {
1202
+ readonly id: number;
1203
+ readonly conversationId: string;
1204
+ readonly filePath: string;
1205
+ readonly contentHash: string | null;
1206
+ readonly tokenCount: number | null;
1207
+ readonly addedAt: string;
1208
+ }
1209
+ interface ICostEntry {
1210
+ readonly id: number;
1211
+ readonly conversationId: string;
1212
+ readonly provider: string;
1213
+ readonly model: string;
1214
+ readonly role: string | null;
1215
+ readonly inputTokens: number | null;
1216
+ readonly outputTokens: number | null;
1217
+ readonly costUsd: number | null;
1218
+ readonly createdAt: string;
1219
+ }
1220
+ interface IPaginationOptions {
1221
+ readonly limit: number;
1222
+ readonly offset: number;
1223
+ }
1224
+ interface IAddMessageParams {
1225
+ readonly conversationId: string;
1226
+ readonly role: MessageRole;
1227
+ readonly content: string;
1228
+ readonly model?: string;
1229
+ readonly provider?: ProviderName;
1230
+ readonly toolCalls?: unknown[];
1231
+ readonly tokenUsage?: IStoredTokenUsage;
1232
+ }
1233
+ interface IAddCostParams {
1234
+ readonly conversationId: string;
1235
+ readonly provider: string;
1236
+ readonly model: string;
1237
+ readonly role?: string;
1238
+ readonly inputTokens?: number;
1239
+ readonly outputTokens?: number;
1240
+ readonly costUsd?: number;
1241
+ }
1242
+ interface IAddFileContextParams {
1243
+ readonly conversationId: string;
1244
+ readonly filePath: string;
1245
+ readonly contentHash?: string;
1246
+ readonly tokenCount?: number;
1247
+ }
1248
+
1249
+ /**
1250
+ * Conversation store — PRD section 17.1
1251
+ * CRUD for conversations, messages, file context, and cost tracking.
1252
+ * All queries use parameterized prepared statements.
1253
+ */
1254
+
1255
+ declare class ConversationStore {
1256
+ private readonly store;
1257
+ constructor(store: SqliteStore);
1258
+ createConversation(projectRoot: string, defaultModel?: string, metadata?: Record<string, unknown>): IConversation;
1259
+ getConversation(id: string): IConversation | undefined;
1260
+ listConversations(projectRoot?: string): IConversation[];
1261
+ deleteConversation(id: string): void;
1262
+ addMessage(params: IAddMessageParams): IMessage;
1263
+ getMessages(conversationId: string, pagination?: IPaginationOptions): IMessage[];
1264
+ getMessageCount(conversationId: string): number;
1265
+ addFileContext(params: IAddFileContextParams): IFileContext;
1266
+ getFileContext(conversationId: string): IFileContext[];
1267
+ removeFileContext(conversationId: string, filePath: string): void;
1268
+ addCost(params: IAddCostParams): ICostEntry;
1269
+ getConversationCost(conversationId: string): number;
1270
+ getCostBreakdown(conversationId: string): ICostEntry[];
1271
+ private mapConversationRow;
1272
+ private mapMessageRow;
1273
+ private mapFileContextRow;
1274
+ private mapCostRow;
1275
+ }
1276
+
1277
+ /**
1278
+ * Inter-agent message routing per PRD section 8.4
1279
+ * Supports: DM, broadcast, shutdown, plan approval, task updates.
1280
+ * Message queue for busy agents with automatic drain on idle transition.
1281
+ */
1282
+
1283
+ /** Handler function invoked when an agent receives a message. */
1284
+ type MessageHandler$1 = (message: IAgentMessage) => void;
1285
+ /**
1286
+ * Optional transport layer for remote message delivery (e.g., IPC hub).
1287
+ * Implement this interface to bridge the message bus to Unix domain sockets.
1288
+ */
1289
+ interface IMessageTransport {
1290
+ send(agentId: string, message: IAgentMessage): Promise<boolean>;
1291
+ onReceive(handler: (message: IAgentMessage) => void): () => void;
1292
+ }
1293
+ /** Options for constructing a MessageBus. */
1294
+ interface IMessageBusOptions {
1295
+ readonly transport?: IMessageTransport;
1296
+ }
1297
+ declare class MessageBus {
1298
+ private readonly handlers;
1299
+ private readonly queues;
1300
+ private readonly statuses;
1301
+ private readonly transport;
1302
+ private readonly transportUnsubscribe;
1303
+ private destroyed;
1304
+ constructor(options?: IMessageBusOptions);
1305
+ /** Register an agent as available for message delivery. */
1306
+ registerAgent(agentId: string): void;
1307
+ /** Remove an agent from the bus. Pending messages are discarded. */
1308
+ unregisterAgent(agentId: string): void;
1309
+ /** Subscribe to messages delivered to an agent. Returns unsubscribe function. */
1310
+ subscribe(agentId: string, handler: MessageHandler$1): () => void;
1311
+ /** Route a message to its recipient(s). Returns true if delivered or queued. */
1312
+ send(message: IAgentMessage): boolean;
1313
+ /** Create a well-formed message and send it. Returns the created message. */
1314
+ createAndSend(type: AgentMessageType, senderId: string, recipientId: string | undefined, content: string, extra?: {
1315
+ summary?: string;
1316
+ requestId?: string;
1317
+ approve?: boolean;
1318
+ }): IAgentMessage;
1319
+ /** Update an agent's status. Drains the queue when transitioning to idle. */
1320
+ setAgentStatus(agentId: string, status: AgentStatus): void;
1321
+ /** Get the number of queued messages for an agent. */
1322
+ getQueueSize(agentId: string): number;
1323
+ /** Get all registered agent IDs. */
1324
+ getRegisteredAgents(): readonly string[];
1325
+ /** Tear down the message bus and release resources. */
1326
+ destroy(): void;
1327
+ private broadcastToAll;
1328
+ private deliverToAgent;
1329
+ private invokeHandlers;
1330
+ private enqueue;
1331
+ private drainQueue;
1332
+ private routeIncoming;
1333
+ }
1334
+
1335
+ /**
1336
+ * File-based task persistence per PRD section 20.2
1337
+ * Atomic writes for crash recovery: write to temp file, then rename.
1338
+ * Store at getTasksDir()/teamName/taskId.json
1339
+ */
1340
+
1341
+ declare class TaskStore {
1342
+ private readonly storeDir;
1343
+ constructor(teamName: string);
1344
+ /** Persist a task to disk with atomic write (temp + rename). */
1345
+ save(task: ITask): void;
1346
+ /** Load a single task by ID. Throws if not found. */
1347
+ load(taskId: string): ITask;
1348
+ /** Load all tasks for this team, sorted by creation time. */
1349
+ loadAll(): ITask[];
1350
+ /** Remove a task file from disk. Returns true if deleted. */
1351
+ remove(taskId: string): boolean;
1352
+ /** Check whether a task file exists on disk. */
1353
+ exists(taskId: string): boolean;
1354
+ /** Absolute path to this team's task store directory. */
1355
+ getStorePath(): string;
1356
+ private getTaskFilePath;
1357
+ /** Remove orphaned .tmp files left from interrupted writes. */
1358
+ private cleanupTempFiles;
1359
+ private static serialize;
1360
+ private static deserialize;
1361
+ }
1362
+
1363
+ /**
1364
+ * Plan approval workflow per PRD section 8.2 step 5
1365
+ * Agent submits plan → Leader reviews → Approve or reject.
1366
+ * Uses message bus for transport; includes configurable timeout.
1367
+ */
1368
+
1369
+ /** Result of a plan approval request. */
1370
+ interface IPlanApprovalResult {
1371
+ readonly approved: boolean;
1372
+ readonly feedback?: string | undefined;
1373
+ readonly requestId: string;
1374
+ readonly respondedBy: string;
1375
+ readonly respondedAt: Date;
1376
+ }
1377
+ /** A pending plan awaiting leader review (for listing). */
1378
+ interface IPendingPlan {
1379
+ readonly requestId: string;
1380
+ readonly agentId: string;
1381
+ readonly plan: string;
1382
+ readonly submittedAt: Date;
1383
+ }
1384
+ /** Options for the PlanApproval workflow. */
1385
+ interface IPlanApprovalOptions {
1386
+ readonly leaderId?: string;
1387
+ readonly timeoutMs?: number;
1388
+ }
1389
+ declare class PlanApproval {
1390
+ private readonly messageBus;
1391
+ private readonly leaderId;
1392
+ private readonly timeoutMs;
1393
+ private readonly pending;
1394
+ private destroyed;
1395
+ constructor(messageBus: MessageBus, options?: IPlanApprovalOptions);
1396
+ /**
1397
+ * Submit a plan for approval. Returns a promise that resolves
1398
+ * when the leader approves or rejects, or rejects on timeout.
1399
+ */
1400
+ submitPlan(agentId: string, plan: string): Promise<IPlanApprovalResult>;
1401
+ /** Leader approves a pending plan. Returns false if no matching request. */
1402
+ approvePlan(requestId: string, responderId: string): boolean;
1403
+ /** Leader rejects a pending plan with feedback. */
1404
+ rejectPlan(requestId: string, responderId: string, feedback: string): boolean;
1405
+ /**
1406
+ * Handle an incoming plan_approval_response message.
1407
+ * Call this from a message bus subscription to close the request loop.
1408
+ */
1409
+ handleResponse(message: IAgentMessage): void;
1410
+ /** Cancel a pending plan request. */
1411
+ cancelPlan(requestId: string): boolean;
1412
+ /** Get all pending plan requests (for leader UI). */
1413
+ getPendingPlans(): readonly IPendingPlan[];
1414
+ /** Get the count of pending plans. */
1415
+ getPendingCount(): number;
1416
+ /** Tear down: cancel all pending plans and release resources. */
1417
+ destroy(): void;
1418
+ }
1419
+
1420
+ /**
1421
+ * Team creation and lifecycle management per PRD section 8.2
1422
+ * Orchestrates agents, tasks, messaging, and plan approval for a team.
1423
+ */
1424
+
1425
+ /** Agent definition used when creating a team. */
1426
+ interface IAgentDefinition {
1427
+ readonly name: string;
1428
+ readonly agentType: string;
1429
+ readonly model: string;
1430
+ readonly provider: ProviderName;
1431
+ readonly role: ModelRole;
1432
+ }
1433
+ /** Options for createTeam(). */
1434
+ interface ITeamCreateOptions {
1435
+ readonly description?: string;
1436
+ readonly agents: readonly IAgentDefinition[];
1437
+ readonly sessionId?: string;
1438
+ readonly cliEntryPoint?: string;
1439
+ }
1440
+ declare class TeamManager {
1441
+ private readonly activeTeams;
1442
+ /** Create a new team: config, directories, and agent process handles. */
1443
+ createTeam(name: string, options: ITeamCreateOptions): Promise<ITeamConfig>;
1444
+ /** Start all agent processes for a team. */
1445
+ startAgents(teamName: string): Promise<void>;
1446
+ /** Gracefully shutdown and remove a team. */
1447
+ deleteTeam(name: string): Promise<void>;
1448
+ /** List all teams from disk (active and inactive). */
1449
+ listTeams(): ITeamConfig[];
1450
+ /** Load a team config from disk. Throws if not found. */
1451
+ getTeam(name: string): ITeamConfig;
1452
+ /** Get the runtime state of a specific agent within an active team. */
1453
+ getAgentState(teamName: string, agentName: string): IAgentState | undefined;
1454
+ /** Get all agent states for an active team. */
1455
+ getAgentStates(teamName: string): readonly IAgentState[];
1456
+ /** Get the message bus for an active team. */
1457
+ getMessageBus(teamName: string): MessageBus | undefined;
1458
+ /** Get the task store for an active team. */
1459
+ getTaskStore(teamName: string): TaskStore | undefined;
1460
+ /** Get the plan approval handler for an active team. */
1461
+ getPlanApproval(teamName: string): PlanApproval | undefined;
1462
+ /** Register a callback for IPC messages from all agents in a team. Returns cleanup function. */
1463
+ onAgentMessages(teamName: string, callback: (agentName: string, method: string, params: Record<string, unknown>) => void): () => void;
1464
+ /** Assign a task to a specific agent via IPC. */
1465
+ assignTask(teamName: string, agentName: string, taskId: string, subject: string, description: string): void;
1466
+ /** Check whether a team is currently active in memory. */
1467
+ isTeamActive(name: string): boolean;
1468
+ /** Shut down all active teams. Call during application cleanup. */
1469
+ shutdownAll(): Promise<void>;
1470
+ private getActiveTeam;
1471
+ private saveTeamConfig;
1472
+ private loadTeamConfig;
1473
+ private shutdownAgents;
1474
+ }
1475
+
1476
+ /**
1477
+ * Agent subprocess management per PRD sections 8.1, 9.4
1478
+ * Each agent runs as a separate Node.js process (fork of aemeathcli).
1479
+ * Parent–child IPC uses JSON-RPC 2.0 protocol (IIPCMessage).
1480
+ */
1481
+
1482
+ /** Configuration for spawning an agent process. */
1483
+ interface IAgentProcessOptions {
1484
+ readonly teamName: string;
1485
+ readonly sessionId: string;
1486
+ readonly cliEntryPoint?: string | undefined;
1487
+ readonly env?: Readonly<Record<string, string>>;
1488
+ readonly shutdownTimeoutMs?: number;
1489
+ readonly registrationTimeoutMs?: number;
1490
+ }
1491
+ /** Callback for IPC messages received from the child process. */
1492
+ type AgentMessageCallback = (method: string, params: Record<string, unknown>) => void;
1493
+ declare class AgentProcess {
1494
+ private readonly config;
1495
+ private readonly teamName;
1496
+ private readonly sessionId;
1497
+ private readonly cliEntryPoint;
1498
+ private readonly customEnv;
1499
+ private readonly shutdownTimeoutMs;
1500
+ private readonly registrationTimeoutMs;
1501
+ private readonly messageCallbacks;
1502
+ private child;
1503
+ private status;
1504
+ private currentTaskId;
1505
+ private nextMessageId;
1506
+ constructor(config: IAgentConfig, options: IAgentProcessOptions);
1507
+ /** Spawn the child process. Throws AgentSpawnError on failure. */
1508
+ start(): Promise<void>;
1509
+ /** Gracefully stop the agent. Falls back to SIGTERM after timeout. */
1510
+ stop(): Promise<void>;
1511
+ /** Kill and restart the agent process. */
1512
+ restart(): Promise<void>;
1513
+ /** Send a JSON-RPC 2.0 message to the child process. Returns message ID. */
1514
+ sendIPC(method: IPCMethod, params: Record<string, unknown>): number;
1515
+ /** Assign a task to this agent via IPC. */
1516
+ assignTask(taskId: string, subject: string, description: string): number;
1517
+ /** Register a callback for IPC messages from the child process. */
1518
+ onMessage(callback: AgentMessageCallback): () => void;
1519
+ /** Get the current agent state snapshot. */
1520
+ getState(): IAgentState;
1521
+ /** Get the current status. */
1522
+ getStatus(): AgentStatus;
1523
+ /** Get the child process PID, or undefined if not running. */
1524
+ getPid(): number | undefined;
1525
+ /** Check if the child process is alive. */
1526
+ isAlive(): boolean;
1527
+ private setupChildListeners;
1528
+ private handleChildMessage;
1529
+ /** Wait for the child to send agent.register. Rejects on timeout or early exit. */
1530
+ private waitForRegistration;
1531
+ private setStatus;
1532
+ private notifyCallbacks;
1533
+ private cleanup;
1534
+ }
1535
+
1536
+ /**
1537
+ * Layout engine for split-panel auto-layout computation per PRD section 9.2.
1538
+ * Computes pane positions based on agent count and terminal dimensions.
1539
+ */
1540
+
1541
+ interface IPaneGeometry {
1542
+ readonly paneId: string;
1543
+ readonly row: number;
1544
+ readonly col: number;
1545
+ readonly widthPercent: number;
1546
+ readonly heightPercent: number;
1547
+ readonly splitDirection: "horizontal" | "vertical" | "none";
1548
+ }
1549
+ interface IComputedLayout {
1550
+ readonly panes: readonly IPaneGeometry[];
1551
+ readonly rows: number;
1552
+ readonly cols: number;
1553
+ readonly terminalWidth: number;
1554
+ readonly terminalHeight: number;
1555
+ }
1556
+ interface ITerminalSize {
1557
+ readonly columns: number;
1558
+ readonly rows: number;
1559
+ }
1560
+ declare class LayoutEngine {
1561
+ private readonly terminalSize;
1562
+ constructor(terminalSize?: Partial<ITerminalSize>);
1563
+ /**
1564
+ * Compute the full layout for a set of pane configs.
1565
+ */
1566
+ computeLayout(config: ILayoutConfig): IComputedLayout;
1567
+ /**
1568
+ * Determine the best auto-layout for a given pane count (PRD section 9.2).
1569
+ */
1570
+ resolveAutoLayout(paneCount: number): Exclude<PaneLayout, "auto">;
1571
+ /**
1572
+ * Get the maximum number of panes the terminal can support.
1573
+ */
1574
+ getMaxPanes(): number;
1575
+ /**
1576
+ * Check if the terminal is large enough for the requested pane count.
1577
+ */
1578
+ canFitPanes(paneCount: number): boolean;
1579
+ /**
1580
+ * Get the grid dimensions for a given pane count and layout type.
1581
+ */
1582
+ private getGridDimensions;
1583
+ /**
1584
+ * Compute grid rows and columns for a given pane count.
1585
+ * PRD section 9.2:
1586
+ * 2 agents → horizontal split (50/50) → 1x2
1587
+ * 3 agents → 1 top + 2 bottom → 2 rows
1588
+ * 4 agents → 2x2 grid
1589
+ * 5+ agents → leader top + grid bottom
1590
+ */
1591
+ private computeGridSize;
1592
+ /**
1593
+ * Compute per-pane geometries based on layout type.
1594
+ */
1595
+ private computeGeometries;
1596
+ /**
1597
+ * Horizontal split: all panes side by side.
1598
+ */
1599
+ private computeHorizontalLayout;
1600
+ /**
1601
+ * Vertical split: all panes stacked.
1602
+ */
1603
+ private computeVerticalLayout;
1604
+ /**
1605
+ * Grid layout per PRD section 9.2 rules:
1606
+ * 3 agents → leader spans top, 2 on bottom
1607
+ * 4 agents → 2x2 even grid
1608
+ * 5+ agents → leader spans top, rest in grid below
1609
+ */
1610
+ private computeGridLayout;
1611
+ /**
1612
+ * Determine split direction based on position in grid.
1613
+ */
1614
+ private determineSplitDirection;
1615
+ /**
1616
+ * Detect terminal width from environment.
1617
+ */
1618
+ private detectTerminalWidth;
1619
+ /**
1620
+ * Detect terminal height from environment.
1621
+ */
1622
+ private detectTerminalHeight;
1623
+ }
1624
+
1625
+ /**
1626
+ * TmuxManager — Programmatic tmux control per PRD section 9.2.
1627
+ * Creates sessions, splits panes, sends commands, manages lifecycle.
1628
+ */
1629
+
1630
+ interface ITmuxPaneInfo {
1631
+ readonly paneId: string;
1632
+ readonly tmuxPaneId: string;
1633
+ readonly agentName: string;
1634
+ readonly title: string;
1635
+ }
1636
+ interface ITmuxManagerOptions {
1637
+ readonly sessionPrefix?: string;
1638
+ }
1639
+ declare class TmuxManager {
1640
+ private readonly sessionPrefix;
1641
+ private readonly layoutEngine;
1642
+ private readonly panes;
1643
+ private sessionName;
1644
+ private disposed;
1645
+ constructor(options?: ITmuxManagerOptions);
1646
+ /**
1647
+ * Check if tmux is available on this system.
1648
+ */
1649
+ isAvailable(): Promise<boolean>;
1650
+ /**
1651
+ * Create a new tmux session for a team.
1652
+ */
1653
+ createSession(teamName: string): Promise<string>;
1654
+ /**
1655
+ * Create split panes based on a layout configuration.
1656
+ */
1657
+ createPanes(layoutConfig: ILayoutConfig): Promise<IComputedLayout>;
1658
+ /**
1659
+ * Send a command string to a specific pane.
1660
+ */
1661
+ sendCommand(paneId: string, command: string): Promise<void>;
1662
+ /**
1663
+ * Resize a pane by tmux pane target.
1664
+ */
1665
+ resizePane(paneId: string, dimensions: {
1666
+ width?: number;
1667
+ height?: number;
1668
+ }): Promise<void>;
1669
+ /**
1670
+ * Set the title for a tmux pane.
1671
+ */
1672
+ private setPaneTitle;
1673
+ /**
1674
+ * Kill a specific pane.
1675
+ */
1676
+ killPane(paneId: string): Promise<void>;
1677
+ /**
1678
+ * Attach to the tmux session (gives control to the user).
1679
+ */
1680
+ attachSession(): Promise<void>;
1681
+ /**
1682
+ * Check if the session still exists.
1683
+ */
1684
+ isSessionAlive(): Promise<boolean>;
1685
+ /**
1686
+ * Destroy the entire tmux session and all panes.
1687
+ */
1688
+ destroy(): Promise<void>;
1689
+ /**
1690
+ * Get the current session name.
1691
+ */
1692
+ getSessionName(): string | undefined;
1693
+ /**
1694
+ * Get all tracked pane info.
1695
+ */
1696
+ getPanes(): ReadonlyMap<string, ITmuxPaneInfo>;
1697
+ private splitPane;
1698
+ private getFirstPaneId;
1699
+ private equalizeLayout;
1700
+ private killSessionSilent;
1701
+ private assertNotDisposed;
1702
+ private assertSession;
1703
+ }
1704
+
1705
+ /**
1706
+ * iTerm2Manager — macOS iTerm2 Python API bridge per PRD section 9.3.
1707
+ * Splits sessions into panes, sets profiles, sends commands.
1708
+ * Graceful fallback if iTerm2 is not available.
1709
+ */
1710
+
1711
+ interface IITerm2PaneInfo {
1712
+ readonly paneId: string;
1713
+ readonly sessionId: string;
1714
+ readonly agentName: string;
1715
+ readonly title: string;
1716
+ }
1717
+ declare class ITerm2Manager {
1718
+ private readonly panes;
1719
+ private disposed;
1720
+ /**
1721
+ * Check if currently running inside iTerm2 on macOS.
1722
+ */
1723
+ isAvailable(): boolean;
1724
+ /**
1725
+ * Check if the iTerm2 Python API is accessible.
1726
+ */
1727
+ isPythonAPIAvailable(): Promise<boolean>;
1728
+ /**
1729
+ * Create panes in the current iTerm2 window based on layout config.
1730
+ */
1731
+ createPanes(layoutConfig: ILayoutConfig): Promise<void>;
1732
+ /**
1733
+ * Send a command to a specific pane via iTerm2 Python API.
1734
+ */
1735
+ sendCommand(paneId: string, command: string): Promise<void>;
1736
+ /**
1737
+ * Set the profile (colors) for a pane based on agent role.
1738
+ */
1739
+ setProfile(paneId: string, role: string): Promise<void>;
1740
+ /**
1741
+ * Destroy all managed iTerm2 panes.
1742
+ */
1743
+ destroy(): Promise<void>;
1744
+ /**
1745
+ * Get all tracked pane info.
1746
+ */
1747
+ getPanes(): ReadonlyMap<string, IITerm2PaneInfo>;
1748
+ /**
1749
+ * Register a pane that was created externally.
1750
+ */
1751
+ registerPane(info: IITerm2PaneInfo): void;
1752
+ private buildCreatePanesScript;
1753
+ private buildSplitCommands;
1754
+ private shouldSplitVertically;
1755
+ private buildSendCommandScript;
1756
+ private buildSetProfileScript;
1757
+ private buildCloseSessionScript;
1758
+ private executePythonScript;
1759
+ private assertNotDisposed;
1760
+ }
1761
+
1762
+ /**
1763
+ * IPCHub — Unix domain socket server for inter-agent communication.
1764
+ * JSON-RPC 2.0 protocol with HMAC authentication per PRD section 9.4 & 14.5.
1765
+ */
1766
+
1767
+ type MethodHandler = (clientId: string, params: Record<string, unknown>, id: number | undefined, socket: Socket) => Promise<unknown>;
1768
+ declare class IPCHub {
1769
+ private readonly sessionId;
1770
+ private readonly hmacSecret;
1771
+ private readonly socketPath;
1772
+ private readonly clients;
1773
+ private readonly handlers;
1774
+ private server;
1775
+ private disposed;
1776
+ constructor(sessionId: string);
1777
+ getHmacSecret(): string;
1778
+ getSocketPath(): string;
1779
+ getClientCount(): number;
1780
+ getConnectedAgentIds(): readonly string[];
1781
+ /** Start the Unix domain socket server. */
1782
+ start(): Promise<void>;
1783
+ /** Send a message to a specific registered client. */
1784
+ sendToClient(agentId: string, message: IIPCMessage): void;
1785
+ /** Broadcast a message to all connected clients. */
1786
+ broadcast(message: IIPCMessage, excludeId?: string): void;
1787
+ /** Register a custom method handler. */
1788
+ onMethod(method: string, handler: MethodHandler): void;
1789
+ /** Compute HMAC-SHA256 for a message. */
1790
+ computeHmac(message: IIPCMessage): string;
1791
+ /** Register a connected socket as a client (also called by agent.register). */
1792
+ registerClientSocket(agentId: string, agentName: string, socket: Socket): void;
1793
+ /** Gracefully shut down the hub and all connections. */
1794
+ destroy(): Promise<void>;
1795
+ private handleConnection;
1796
+ private processRaw;
1797
+ private registerDefaultHandlers;
1798
+ private verifyHmac;
1799
+ private isAuthEnvelope;
1800
+ private write;
1801
+ private sendResult;
1802
+ private sendError;
1803
+ private removeStaleSocket;
1804
+ private setupProcessCleanup;
1805
+ private assertAlive;
1806
+ }
1807
+
1808
+ /**
1809
+ * PaneProcess — IPC client connecting to the IPCHub from an agent process.
1810
+ * JSON-RPC 2.0 with HMAC auth, reconnection, and heartbeat per PRD 9.4 & 20.2.
1811
+ */
1812
+
1813
+ interface IPaneProcessOptions {
1814
+ readonly agentId: string;
1815
+ readonly agentName: string;
1816
+ readonly socketPath: string;
1817
+ readonly hmacSecret: string;
1818
+ readonly heartbeatIntervalMs?: number;
1819
+ readonly reconnectMaxRetries?: number;
1820
+ }
1821
+ type MessageHandler = (message: IIPCMessage) => void;
1822
+ declare class PaneProcess {
1823
+ private readonly agentId;
1824
+ private readonly agentName;
1825
+ private readonly socketPath;
1826
+ private readonly hmacSecret;
1827
+ private readonly heartbeatMs;
1828
+ private readonly maxRetries;
1829
+ private readonly msgHandlers;
1830
+ private readonly pending;
1831
+ private socket;
1832
+ private heartbeatTimer;
1833
+ private nextId;
1834
+ private connected;
1835
+ private disposed;
1836
+ constructor(options: IPaneProcessOptions);
1837
+ /** Connect to the IPC hub and register this agent. */
1838
+ connect(): Promise<void>;
1839
+ /** Send a JSON-RPC 2.0 request and wait for response. */
1840
+ request(method: IPCMethod, params: Record<string, unknown>): Promise<unknown>;
1841
+ /** Send a notification (no response expected). */
1842
+ notify(method: IPCMethod, params: Record<string, unknown>): void;
1843
+ /** Convenience: send a stream chunk. */
1844
+ sendStreamChunk(content: string, model: string, taskId?: string): void;
1845
+ /** Convenience: send a task status update. */
1846
+ sendTaskUpdate(taskId: string, status: string): void;
1847
+ /** Convenience: send a message to another agent via the hub. */
1848
+ sendMessage(to: string, content: string): Promise<unknown>;
1849
+ /** Register a handler for incoming messages of a specific method. */
1850
+ onMessage(method: string, handler: MessageHandler): () => void;
1851
+ isConnected(): boolean;
1852
+ /** Gracefully disconnect from the hub. */
1853
+ disconnect(): Promise<void>;
1854
+ private establish;
1855
+ private connectSocket;
1856
+ private attemptReconnect;
1857
+ private register;
1858
+ private handleIncoming;
1859
+ private resolveResponse;
1860
+ private dispatch;
1861
+ private startHeartbeat;
1862
+ private stopHeartbeat;
1863
+ private sendAuthenticated;
1864
+ private isResponse;
1865
+ private isMessage;
1866
+ private rejectAll;
1867
+ private assertAlive;
1868
+ private assertConnected;
1869
+ }
1870
+
1871
+ /**
1872
+ * SkillLoader — Parses YAML frontmatter + Markdown body from SKILL.md files.
1873
+ * Per PRD section 10.2-10.3: YAML skill file format with Zod validation.
1874
+ */
1875
+
1876
+ declare class SkillLoader {
1877
+ /**
1878
+ * Parse a single SKILL.md file into an ISkillDefinition.
1879
+ * Returns null if the file is malformed or invalid.
1880
+ */
1881
+ loadSkillFile(filePath: string): Promise<ISkillDefinition | null>;
1882
+ /**
1883
+ * Parse raw SKILL.md content string into an ISkillDefinition.
1884
+ */
1885
+ parseSkillContent(raw: string, filePath: string): ISkillDefinition | null;
1886
+ /**
1887
+ * Extract only name and description for progressive loading (~100 tokens).
1888
+ */
1889
+ loadSkillSummary(filePath: string): Promise<{
1890
+ name: string;
1891
+ description: string;
1892
+ } | null>;
1893
+ /**
1894
+ * Split raw content into YAML frontmatter and Markdown body.
1895
+ * Frontmatter is delimited by `---` at the start and a subsequent `---`.
1896
+ */
1897
+ private extractFrontmatter;
1898
+ }
1899
+
1900
+ /**
1901
+ * SkillRegistry — Discovers, indexes, and resolves skill definitions.
1902
+ * Resolution priority: project > user > built-in (PRD section 10.4).
1903
+ * Progressive loading: only name + description loaded initially (~100 tokens each).
1904
+ */
1905
+
1906
+ type SkillSource = "project" | "user" | "built-in";
1907
+ interface ISkillSummary {
1908
+ readonly name: string;
1909
+ readonly description: string;
1910
+ readonly version: string;
1911
+ readonly source: SkillSource;
1912
+ readonly dirPath: string;
1913
+ }
1914
+ declare class SkillRegistry {
1915
+ private readonly loader;
1916
+ private readonly skills;
1917
+ private readonly triggerIndex;
1918
+ private initialized;
1919
+ constructor(loader?: SkillLoader);
1920
+ /**
1921
+ * Initialize the registry by scanning all skill directories.
1922
+ * Loads in priority order so higher-priority sources override lower ones.
1923
+ */
1924
+ initialize(projectRoot?: string): Promise<void>;
1925
+ /**
1926
+ * Get a full skill definition by name. Loads content on demand.
1927
+ */
1928
+ getByName(name: string): Promise<ISkillDefinition | null>;
1929
+ /**
1930
+ * Find a skill by trigger string (e.g. "$review" or "review").
1931
+ */
1932
+ getByTrigger(trigger: string): Promise<ISkillDefinition | null>;
1933
+ /**
1934
+ * Resolve a trigger string to a skill name without loading the full definition.
1935
+ */
1936
+ resolveTriger(trigger: string): string | undefined;
1937
+ /**
1938
+ * List all registered skill summaries.
1939
+ */
1940
+ listAll(): readonly ISkillSummary[];
1941
+ /**
1942
+ * Check if a skill exists by name.
1943
+ */
1944
+ has(name: string): boolean;
1945
+ /**
1946
+ * Get the count of registered skills.
1947
+ */
1948
+ get size(): number;
1949
+ /**
1950
+ * Reset the registry for re-initialization.
1951
+ */
1952
+ reset(): void;
1953
+ /**
1954
+ * Scan a directory for skill subdirectories containing SKILL.md.
1955
+ */
1956
+ private scanDirectory;
1957
+ /**
1958
+ * Register a single skill from its SKILL.md file path.
1959
+ */
1960
+ private registerSkillFromFile;
1961
+ /**
1962
+ * Index all triggers for a skill definition.
1963
+ */
1964
+ private registerTriggers;
1965
+ /**
1966
+ * Remove all trigger mappings associated with a skill name.
1967
+ */
1968
+ private removeTriggers;
1969
+ /**
1970
+ * Resolve the built-in skills directory relative to this module.
1971
+ */
1972
+ private getBuiltInSkillsDir;
1973
+ }
1974
+
1975
+ /**
1976
+ * SkillExecutor — Manages skill activation, context injection, and tool restriction.
1977
+ * Per PRD section 10.3: Load full SKILL.md content into context on activation,
1978
+ * restrict tools, and unload on deactivation.
1979
+ */
1980
+
1981
+ interface IActiveSkill {
1982
+ readonly definition: ISkillDefinition;
1983
+ readonly activatedAt: Date;
1984
+ readonly previousAllowedTools: readonly string[] | null;
1985
+ }
1986
+ interface ISkillActivationResult {
1987
+ readonly success: boolean;
1988
+ readonly skill?: ISkillDefinition;
1989
+ readonly errorMessage?: string;
1990
+ readonly warnings?: readonly string[];
1991
+ }
1992
+ interface IModelCapabilities {
1993
+ readonly contextWindow: number;
1994
+ readonly currentRole?: ModelRole;
1995
+ }
1996
+ declare class SkillExecutor {
1997
+ private readonly registry;
1998
+ private activeSkill;
1999
+ private baseAllowedTools;
2000
+ constructor(registry: SkillRegistry);
2001
+ /**
2002
+ * Activate a skill by name.
2003
+ */
2004
+ activateByName(name: string, modelCapabilities?: IModelCapabilities): Promise<ISkillActivationResult>;
2005
+ /**
2006
+ * Activate a skill by trigger string (e.g. "$review" or "review").
2007
+ */
2008
+ activateByTrigger(trigger: string, modelCapabilities?: IModelCapabilities): Promise<ISkillActivationResult>;
2009
+ /**
2010
+ * Deactivate the currently active skill, restoring previous tool set.
2011
+ */
2012
+ deactivate(): void;
2013
+ /**
2014
+ * Get the currently active skill, or null if none.
2015
+ */
2016
+ getActiveSkill(): IActiveSkill | null;
2017
+ /**
2018
+ * Check if any skill is currently active.
2019
+ */
2020
+ isActive(): boolean;
2021
+ /**
2022
+ * Get the active skill's body content for context injection.
2023
+ * Returns null if no skill is active.
2024
+ */
2025
+ getActiveSkillContent(): string | null;
2026
+ /**
2027
+ * Get the name of the currently active skill, or null.
2028
+ */
2029
+ getActiveSkillName(): string | null;
2030
+ /**
2031
+ * Get the allowed tool list under the current state.
2032
+ * When a skill is active with allowed-tools, only those tools are permitted.
2033
+ * Returns null when no restrictions are in effect.
2034
+ */
2035
+ getAllowedTools(): readonly string[] | null;
2036
+ /**
2037
+ * Check if a specific tool is allowed under the current skill restrictions.
2038
+ */
2039
+ isToolAllowed(toolName: string): boolean;
2040
+ /**
2041
+ * Set the base allowed tools (used when no skill is active).
2042
+ */
2043
+ setBaseAllowedTools(tools: readonly string[] | null): void;
2044
+ /**
2045
+ * Validate model requirements for a skill definition.
2046
+ * Returns compatibility status and any warnings.
2047
+ */
2048
+ checkModelRequirements(definition: ISkillDefinition, capabilities: IModelCapabilities): {
2049
+ compatible: boolean;
2050
+ warnings: readonly string[];
2051
+ };
2052
+ /**
2053
+ * Core activation logic. Deactivates any current skill first.
2054
+ */
2055
+ private activate;
2056
+ }
2057
+
2058
+ /**
2059
+ * MCP client per PRD section 11.1
2060
+ * Wraps @modelcontextprotocol/sdk Client with typed, transport-agnostic interface.
2061
+ * Supports stdio (local servers) and Streamable HTTP (remote servers).
2062
+ */
2063
+ interface IMCPToolSchema {
2064
+ readonly name: string;
2065
+ readonly description: string;
2066
+ readonly inputSchema: Readonly<Record<string, unknown>>;
2067
+ }
2068
+ interface IMCPCallResult {
2069
+ readonly content: string;
2070
+ readonly isError: boolean;
2071
+ }
2072
+ interface IMCPResource {
2073
+ readonly uri: string;
2074
+ readonly name: string;
2075
+ readonly description: string;
2076
+ readonly mimeType: string;
2077
+ }
2078
+ interface IStdioTransportConfig {
2079
+ readonly type: "stdio";
2080
+ readonly command: string;
2081
+ readonly args: readonly string[];
2082
+ readonly env?: Readonly<Record<string, string>>;
2083
+ }
2084
+ interface IHttpTransportConfig {
2085
+ readonly type: "streamable-http";
2086
+ readonly url: string;
2087
+ }
2088
+ type MCPTransportConfig = IStdioTransportConfig | IHttpTransportConfig;
2089
+ interface IMCPClientOptions {
2090
+ readonly serverName: string;
2091
+ readonly transport: MCPTransportConfig;
2092
+ readonly connectionTimeoutMs?: number;
2093
+ }
2094
+ declare class MCPClient {
2095
+ private client;
2096
+ private connected;
2097
+ private readonly serverName;
2098
+ private readonly transportConfig;
2099
+ private readonly connectionTimeoutMs;
2100
+ constructor(options: IMCPClientOptions);
2101
+ get isConnected(): boolean;
2102
+ get name(): string;
2103
+ /** Establish connection to the MCP server. */
2104
+ connect(): Promise<void>;
2105
+ /** Gracefully close the MCP connection. */
2106
+ disconnect(): Promise<void>;
2107
+ /** Disconnect then reconnect to the server. */
2108
+ reconnect(): Promise<void>;
2109
+ /** List all tools exposed by this MCP server. */
2110
+ listTools(): Promise<readonly IMCPToolSchema[]>;
2111
+ /** Call a tool on this MCP server with the given arguments. */
2112
+ callTool(toolName: string, args: Record<string, unknown>): Promise<IMCPCallResult>;
2113
+ /** List resources exposed by this MCP server. */
2114
+ listResources(): Promise<readonly IMCPResource[]>;
2115
+ /** Read a specific resource by URI. */
2116
+ readResource(uri: string): Promise<string>;
2117
+ private connectWithTimeout;
2118
+ private requireConnected;
2119
+ }
2120
+
2121
+ /**
2122
+ * MCP server lifecycle manager per PRD section 11.1
2123
+ * Manages multiple MCP server connections: start, stop, health-check, restart, rate-limit.
2124
+ */
2125
+
2126
+ type ServerStatus = "stopped" | "connecting" | "connected" | "error";
2127
+ interface IRateLimitConfig {
2128
+ readonly maxCallsPerMinute: number;
2129
+ }
2130
+ interface IServerManagerOptions {
2131
+ readonly connectionTimeoutMs?: number;
2132
+ readonly healthCheckIntervalMs?: number;
2133
+ readonly maxConsecutiveFailures?: number;
2134
+ readonly defaultRateLimit?: IRateLimitConfig | undefined;
2135
+ readonly rateLimits?: Readonly<Record<string, IRateLimitConfig>> | undefined;
2136
+ }
2137
+ declare class MCPServerManager {
2138
+ private readonly servers;
2139
+ private readonly options;
2140
+ private healthCheckTimer;
2141
+ constructor(options?: IServerManagerOptions);
2142
+ /** Start all servers defined in the MCP config. */
2143
+ startAll(config: IMCPConfig): Promise<void>;
2144
+ /** Start a single MCP server by name and config. */
2145
+ startServer(name: string, serverConfig: IMCPServerConfig): Promise<void>;
2146
+ /** Stop a single server by name. */
2147
+ stopServer(name: string): Promise<void>;
2148
+ /** Stop all managed servers and clean up. */
2149
+ stopAll(): Promise<void>;
2150
+ /** Get a connected client by server name. */
2151
+ getClient(name: string): MCPClient | undefined;
2152
+ /** Get all connected server names. */
2153
+ getConnectedServers(): readonly string[];
2154
+ /** Get the status of a server. */
2155
+ getServerStatus(name: string): ServerStatus | undefined;
2156
+ /** List tools from a specific server (with rate-limit check). */
2157
+ listServerTools(name: string): Promise<readonly IMCPToolSchema[]>;
2158
+ /** Check rate limit before allowing a call to the given server. Throws on exceeded. */
2159
+ checkRateLimitFor(name: string): void;
2160
+ /** Record a tool call for rate-limiting purposes. */
2161
+ recordCall(name: string): void;
2162
+ private startHealthChecks;
2163
+ private stopHealthChecks;
2164
+ private runHealthChecks;
2165
+ private restartServer;
2166
+ private checkRateLimit;
2167
+ private getMaxCallsPerMinute;
2168
+ private requireServer;
2169
+ }
2170
+
2171
+ /**
2172
+ * MCP tool bridge per PRD section 11.3
2173
+ * Converts MCP tool schemas to AemeathCLI IToolDefinition format and back.
2174
+ * Registers MCP tools into the unified tool registry with lazy loading.
2175
+ * Tool namespacing: mcp__{serverName}__{toolName}
2176
+ */
2177
+
2178
+ declare class MCPToolBridge {
2179
+ private readonly serverManager;
2180
+ private readonly toolCache;
2181
+ constructor(serverManager: MCPServerManager);
2182
+ /**
2183
+ * Discover tools from all connected MCP servers and register them.
2184
+ * Uses lazy loading: definitions are fetched and cached on first request.
2185
+ */
2186
+ registerAll(registry: IToolRegistry): Promise<number>;
2187
+ /**
2188
+ * Register tools from a single MCP server.
2189
+ * Fetches tool schemas and caches definitions.
2190
+ */
2191
+ registerServerTools(serverName: string, registry: IToolRegistry): Promise<number>;
2192
+ /**
2193
+ * Lazy-load tool definitions for a server.
2194
+ * Returns cached definitions if already loaded.
2195
+ */
2196
+ loadToolDefinitions(serverName: string): Promise<readonly IToolDefinition[]>;
2197
+ /**
2198
+ * Execute an MCP tool call: validate, convert, call, return result.
2199
+ */
2200
+ executeTool(call: IToolCall): Promise<IToolResult>;
2201
+ /** Invalidate cached tool definitions for a server (e.g. after config reload). */
2202
+ invalidateCache(serverName?: string): void;
2203
+ /** Check whether a tool name is an MCP-namespaced tool. */
2204
+ isMCPTool(toolName: string): boolean;
2205
+ /** Get all cached tool definitions across all servers. */
2206
+ getAllDefinitions(): readonly IToolDefinition[];
2207
+ private createRegistration;
2208
+ }
2209
+
2210
+ export { AemeathError, type AgentMessageType, AgentProcess, AgentSpawnError, AuthenticationError, ClaudeAdapter, ClaudeNativeCLIAdapter, CodexNativeCLIAdapter, ConfigStore, ContextManager, ContextOverflowError, ConversationStore, CostTracker, CredentialStore, DEFAULT_CONFIG, DEFAULT_MODEL_ID, ExecutionTimeoutError, FileNotFoundError, GeminiAdapter, GeminiNativeCLIAdapter, type IAgentConfig, type IAgentMessage, type IAgentState, type IChatMessage, type IChatRequest, type IChatResponse, type ICredential, type IGlobalConfig, type ILayoutConfig, type IMCPConfig, type IModelInfo, type IModelProvider, type IModelResolution, IPCError, IPCHub, type IPaneConfig, type IProviderOptions, type IRoleConfig, type ISkillDefinition, type IStreamChunk, type ITask, type ITeamConfig, ITerm2Manager, type ITokenUsage, type IToolCall, type IToolDefinition, type IToolExecutionContext, type IToolParameter, type IToolRegistration, type IToolRegistry, type IToolResult, InvalidConfigError, KimiAdapter, KimiNativeCLIAdapter, LayoutEngine, MCPClient, MCPServerManager, MCPToolBridge, MessageBus, type MessageRole, MissingConfigError, ModelNotFoundError, type ModelRole, ModelRouter, OllamaAdapter, OpenAIAdapter, type PaneLayout, PaneProcess, PermissionDeniedError, PermissionManager, type PermissionMode, PlanApproval, type ProviderName, ProviderRegistry, RateLimitError, SUPPORTED_MODELS, ServerConnectionError, SessionManager, SkillExecutor, SkillLoader, SkillRegistry, SqliteStore, TaskOrchestrator, type TaskStatus, TaskStore, TeamManager, TmuxManager, ToolCallError, type ToolCategory, ToolRegistry, createDefaultRegistry, createModelRouter, getEventBus };