cliskill 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.
- package/LICENSE +21 -0
- package/README.md +470 -0
- package/dist/bootstrap/cli.d.ts +21 -0
- package/dist/bootstrap/cli.js +9 -0
- package/dist/bootstrap/cli.js.map +1 -0
- package/dist/chunk-AJENHWD3.js +103 -0
- package/dist/chunk-AJENHWD3.js.map +1 -0
- package/dist/chunk-ULZHJVWD.js +9945 -0
- package/dist/chunk-ULZHJVWD.js.map +1 -0
- package/dist/index.d.ts +2018 -0
- package/dist/index.js +1658 -0
- package/dist/index.js.map +1 -0
- package/dist/paths-OODUHG6V.js +39 -0
- package/dist/paths-OODUHG6V.js.map +1 -0
- package/package.json +86 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2018 @@
|
|
|
1
|
+
export { runCli } from './bootstrap/cli.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema for a single provider configuration.
|
|
7
|
+
* Supports any AI model provider with arbitrary base URLs.
|
|
8
|
+
*/
|
|
9
|
+
declare const providerSchema: z.ZodObject<{
|
|
10
|
+
/** Unique name for this provider profile */
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
/** Base URL for the API endpoint */
|
|
13
|
+
baseUrl: z.ZodString;
|
|
14
|
+
/** API key (can also be set via environment variable) */
|
|
15
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
16
|
+
/** Default model to use */
|
|
17
|
+
model: z.ZodString;
|
|
18
|
+
/** API format: "openai-compatible" | "messages-compatible" | "glm-compatible" | "custom" */
|
|
19
|
+
format: z.ZodEnum<["openai-compatible", "messages-compatible", "glm-compatible", "custom"]>;
|
|
20
|
+
/** Custom headers to send with each request */
|
|
21
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
22
|
+
/** Request timeout in milliseconds */
|
|
23
|
+
timeout: z.ZodDefault<z.ZodNumber>;
|
|
24
|
+
/** Maximum tokens in response — 65536 allows large file writes without truncation */
|
|
25
|
+
maxTokens: z.ZodDefault<z.ZodNumber>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
name: string;
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
model: string;
|
|
30
|
+
format: "custom" | "openai-compatible" | "messages-compatible" | "glm-compatible";
|
|
31
|
+
timeout: number;
|
|
32
|
+
maxTokens: number;
|
|
33
|
+
apiKey?: string | undefined;
|
|
34
|
+
headers?: Record<string, string> | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
name: string;
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
model: string;
|
|
39
|
+
format: "custom" | "openai-compatible" | "messages-compatible" | "glm-compatible";
|
|
40
|
+
apiKey?: string | undefined;
|
|
41
|
+
headers?: Record<string, string> | undefined;
|
|
42
|
+
timeout?: number | undefined;
|
|
43
|
+
maxTokens?: number | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
type ProviderConfig = z.infer<typeof providerSchema>;
|
|
46
|
+
/**
|
|
47
|
+
* Schema for the main application configuration.
|
|
48
|
+
*/
|
|
49
|
+
declare const appConfigSchema: z.ZodObject<{
|
|
50
|
+
/** Default provider name to use */
|
|
51
|
+
defaultProvider: z.ZodOptional<z.ZodString>;
|
|
52
|
+
/** Provider configurations */
|
|
53
|
+
providers: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
54
|
+
/** Unique name for this provider profile */
|
|
55
|
+
name: z.ZodString;
|
|
56
|
+
/** Base URL for the API endpoint */
|
|
57
|
+
baseUrl: z.ZodString;
|
|
58
|
+
/** API key (can also be set via environment variable) */
|
|
59
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
60
|
+
/** Default model to use */
|
|
61
|
+
model: z.ZodString;
|
|
62
|
+
/** API format: "openai-compatible" | "messages-compatible" | "glm-compatible" | "custom" */
|
|
63
|
+
format: z.ZodEnum<["openai-compatible", "messages-compatible", "glm-compatible", "custom"]>;
|
|
64
|
+
/** Custom headers to send with each request */
|
|
65
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
66
|
+
/** Request timeout in milliseconds */
|
|
67
|
+
timeout: z.ZodDefault<z.ZodNumber>;
|
|
68
|
+
/** Maximum tokens in response — 65536 allows large file writes without truncation */
|
|
69
|
+
maxTokens: z.ZodDefault<z.ZodNumber>;
|
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
|
71
|
+
name: string;
|
|
72
|
+
baseUrl: string;
|
|
73
|
+
model: string;
|
|
74
|
+
format: "custom" | "openai-compatible" | "messages-compatible" | "glm-compatible";
|
|
75
|
+
timeout: number;
|
|
76
|
+
maxTokens: number;
|
|
77
|
+
apiKey?: string | undefined;
|
|
78
|
+
headers?: Record<string, string> | undefined;
|
|
79
|
+
}, {
|
|
80
|
+
name: string;
|
|
81
|
+
baseUrl: string;
|
|
82
|
+
model: string;
|
|
83
|
+
format: "custom" | "openai-compatible" | "messages-compatible" | "glm-compatible";
|
|
84
|
+
apiKey?: string | undefined;
|
|
85
|
+
headers?: Record<string, string> | undefined;
|
|
86
|
+
timeout?: number | undefined;
|
|
87
|
+
maxTokens?: number | undefined;
|
|
88
|
+
}>, "many">>;
|
|
89
|
+
/** Permission mode: "ask" | "auto-accept" | "plan" */
|
|
90
|
+
permissionMode: z.ZodDefault<z.ZodEnum<["ask", "auto-accept", "plan"]>>;
|
|
91
|
+
/** Enable verbose logging */
|
|
92
|
+
verbose: z.ZodDefault<z.ZodBoolean>;
|
|
93
|
+
/** Maximum context tokens before compaction */
|
|
94
|
+
maxContextTokens: z.ZodDefault<z.ZodNumber>;
|
|
95
|
+
/** Custom system prompt additions */
|
|
96
|
+
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
97
|
+
/** Auto mode — automatic tool approval without subscription gates */
|
|
98
|
+
autoMode: z.ZodDefault<z.ZodObject<{
|
|
99
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
100
|
+
trustLevel: z.ZodDefault<z.ZodEnum<["full-auto", "safe-auto", "ask"]>>;
|
|
101
|
+
autoApprovedTools: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
102
|
+
autoApprovedCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
103
|
+
maxAutoActions: z.ZodDefault<z.ZodNumber>;
|
|
104
|
+
requireConfirmationFor: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
105
|
+
}, "strip", z.ZodTypeAny, {
|
|
106
|
+
enabled: boolean;
|
|
107
|
+
trustLevel: "ask" | "full-auto" | "safe-auto";
|
|
108
|
+
autoApprovedTools: string[];
|
|
109
|
+
autoApprovedCommands: string[];
|
|
110
|
+
maxAutoActions: number;
|
|
111
|
+
requireConfirmationFor: string[];
|
|
112
|
+
}, {
|
|
113
|
+
enabled?: boolean | undefined;
|
|
114
|
+
trustLevel?: "ask" | "full-auto" | "safe-auto" | undefined;
|
|
115
|
+
autoApprovedTools?: string[] | undefined;
|
|
116
|
+
autoApprovedCommands?: string[] | undefined;
|
|
117
|
+
maxAutoActions?: number | undefined;
|
|
118
|
+
requireConfirmationFor?: string[] | undefined;
|
|
119
|
+
}>>;
|
|
120
|
+
/** Fast mode — response speed optimizations without upsell */
|
|
121
|
+
fastMode: z.ZodDefault<z.ZodObject<{
|
|
122
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
123
|
+
reducedPrompts: z.ZodDefault<z.ZodBoolean>;
|
|
124
|
+
skipOptionalChecks: z.ZodDefault<z.ZodBoolean>;
|
|
125
|
+
preloadTools: z.ZodDefault<z.ZodBoolean>;
|
|
126
|
+
streamingOptimizations: z.ZodDefault<z.ZodBoolean>;
|
|
127
|
+
}, "strip", z.ZodTypeAny, {
|
|
128
|
+
enabled: boolean;
|
|
129
|
+
reducedPrompts: boolean;
|
|
130
|
+
skipOptionalChecks: boolean;
|
|
131
|
+
preloadTools: boolean;
|
|
132
|
+
streamingOptimizations: boolean;
|
|
133
|
+
}, {
|
|
134
|
+
enabled?: boolean | undefined;
|
|
135
|
+
reducedPrompts?: boolean | undefined;
|
|
136
|
+
skipOptionalChecks?: boolean | undefined;
|
|
137
|
+
preloadTools?: boolean | undefined;
|
|
138
|
+
streamingOptimizations?: boolean | undefined;
|
|
139
|
+
}>>;
|
|
140
|
+
/** Model access — unrestricted model selection */
|
|
141
|
+
models: z.ZodDefault<z.ZodObject<{
|
|
142
|
+
aliases: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
143
|
+
alias: z.ZodString;
|
|
144
|
+
model: z.ZodString;
|
|
145
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
146
|
+
}, "strip", z.ZodTypeAny, {
|
|
147
|
+
model: string;
|
|
148
|
+
alias: string;
|
|
149
|
+
provider?: string | undefined;
|
|
150
|
+
}, {
|
|
151
|
+
model: string;
|
|
152
|
+
alias: string;
|
|
153
|
+
provider?: string | undefined;
|
|
154
|
+
}>, "many">>;
|
|
155
|
+
defaultModel: z.ZodDefault<z.ZodString>;
|
|
156
|
+
fallbackModel: z.ZodDefault<z.ZodString>;
|
|
157
|
+
maxContextTokens: z.ZodDefault<z.ZodNumber>;
|
|
158
|
+
}, "strip", z.ZodTypeAny, {
|
|
159
|
+
maxContextTokens: number;
|
|
160
|
+
aliases: {
|
|
161
|
+
model: string;
|
|
162
|
+
alias: string;
|
|
163
|
+
provider?: string | undefined;
|
|
164
|
+
}[];
|
|
165
|
+
defaultModel: string;
|
|
166
|
+
fallbackModel: string;
|
|
167
|
+
}, {
|
|
168
|
+
maxContextTokens?: number | undefined;
|
|
169
|
+
aliases?: {
|
|
170
|
+
model: string;
|
|
171
|
+
alias: string;
|
|
172
|
+
provider?: string | undefined;
|
|
173
|
+
}[] | undefined;
|
|
174
|
+
defaultModel?: string | undefined;
|
|
175
|
+
fallbackModel?: string | undefined;
|
|
176
|
+
}>>;
|
|
177
|
+
/** Remote SSH session configuration */
|
|
178
|
+
remote: z.ZodDefault<z.ZodObject<{
|
|
179
|
+
defaultHost: z.ZodOptional<z.ZodString>;
|
|
180
|
+
defaultPort: z.ZodDefault<z.ZodNumber>;
|
|
181
|
+
defaultUsername: z.ZodOptional<z.ZodString>;
|
|
182
|
+
privateKeyPath: z.ZodOptional<z.ZodString>;
|
|
183
|
+
keepAlive: z.ZodDefault<z.ZodBoolean>;
|
|
184
|
+
connectionTimeout: z.ZodDefault<z.ZodNumber>;
|
|
185
|
+
}, "strip", z.ZodTypeAny, {
|
|
186
|
+
defaultPort: number;
|
|
187
|
+
keepAlive: boolean;
|
|
188
|
+
connectionTimeout: number;
|
|
189
|
+
defaultHost?: string | undefined;
|
|
190
|
+
defaultUsername?: string | undefined;
|
|
191
|
+
privateKeyPath?: string | undefined;
|
|
192
|
+
}, {
|
|
193
|
+
defaultHost?: string | undefined;
|
|
194
|
+
defaultPort?: number | undefined;
|
|
195
|
+
defaultUsername?: string | undefined;
|
|
196
|
+
privateKeyPath?: string | undefined;
|
|
197
|
+
keepAlive?: boolean | undefined;
|
|
198
|
+
connectionTimeout?: number | undefined;
|
|
199
|
+
}>>;
|
|
200
|
+
/** Context window — no subscription limits */
|
|
201
|
+
contextWindow: z.ZodDefault<z.ZodObject<{
|
|
202
|
+
maxTokens: z.ZodDefault<z.ZodNumber>;
|
|
203
|
+
compactionThreshold: z.ZodDefault<z.ZodNumber>;
|
|
204
|
+
warningThreshold: z.ZodDefault<z.ZodNumber>;
|
|
205
|
+
strategy: z.ZodDefault<z.ZodEnum<["sliding", "compaction", "hybrid"]>>;
|
|
206
|
+
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
maxTokens: number;
|
|
208
|
+
compactionThreshold: number;
|
|
209
|
+
warningThreshold: number;
|
|
210
|
+
strategy: "sliding" | "compaction" | "hybrid";
|
|
211
|
+
}, {
|
|
212
|
+
maxTokens?: number | undefined;
|
|
213
|
+
compactionThreshold?: number | undefined;
|
|
214
|
+
warningThreshold?: number | undefined;
|
|
215
|
+
strategy?: "sliding" | "compaction" | "hybrid" | undefined;
|
|
216
|
+
}>>;
|
|
217
|
+
/** Theme configuration for terminal output */
|
|
218
|
+
theme: z.ZodDefault<z.ZodObject<{
|
|
219
|
+
name: z.ZodDefault<z.ZodEnum<["dark", "light", "light-daltonized", "dark-daltonized", "light-ansi", "dark-ansi", "auto"]>>;
|
|
220
|
+
}, "strip", z.ZodTypeAny, {
|
|
221
|
+
name: "dark" | "light" | "light-daltonized" | "dark-daltonized" | "light-ansi" | "dark-ansi" | "auto";
|
|
222
|
+
}, {
|
|
223
|
+
name?: "dark" | "light" | "light-daltonized" | "dark-daltonized" | "light-ansi" | "dark-ansi" | "auto" | undefined;
|
|
224
|
+
}>>;
|
|
225
|
+
/** Housekeeping — background maintenance tasks */
|
|
226
|
+
housekeeping: z.ZodDefault<z.ZodObject<{
|
|
227
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
228
|
+
cleanupInterval: z.ZodDefault<z.ZodNumber>;
|
|
229
|
+
maxHistoryAge: z.ZodDefault<z.ZodNumber>;
|
|
230
|
+
maxMemorySize: z.ZodDefault<z.ZodNumber>;
|
|
231
|
+
idleThreshold: z.ZodDefault<z.ZodNumber>;
|
|
232
|
+
}, "strip", z.ZodTypeAny, {
|
|
233
|
+
enabled: boolean;
|
|
234
|
+
cleanupInterval: number;
|
|
235
|
+
maxHistoryAge: number;
|
|
236
|
+
maxMemorySize: number;
|
|
237
|
+
idleThreshold: number;
|
|
238
|
+
}, {
|
|
239
|
+
enabled?: boolean | undefined;
|
|
240
|
+
cleanupInterval?: number | undefined;
|
|
241
|
+
maxHistoryAge?: number | undefined;
|
|
242
|
+
maxMemorySize?: number | undefined;
|
|
243
|
+
idleThreshold?: number | undefined;
|
|
244
|
+
}>>;
|
|
245
|
+
}, "strip", z.ZodTypeAny, {
|
|
246
|
+
providers: {
|
|
247
|
+
name: string;
|
|
248
|
+
baseUrl: string;
|
|
249
|
+
model: string;
|
|
250
|
+
format: "custom" | "openai-compatible" | "messages-compatible" | "glm-compatible";
|
|
251
|
+
timeout: number;
|
|
252
|
+
maxTokens: number;
|
|
253
|
+
apiKey?: string | undefined;
|
|
254
|
+
headers?: Record<string, string> | undefined;
|
|
255
|
+
}[];
|
|
256
|
+
permissionMode: "ask" | "auto-accept" | "plan";
|
|
257
|
+
verbose: boolean;
|
|
258
|
+
maxContextTokens: number;
|
|
259
|
+
autoMode: {
|
|
260
|
+
enabled: boolean;
|
|
261
|
+
trustLevel: "ask" | "full-auto" | "safe-auto";
|
|
262
|
+
autoApprovedTools: string[];
|
|
263
|
+
autoApprovedCommands: string[];
|
|
264
|
+
maxAutoActions: number;
|
|
265
|
+
requireConfirmationFor: string[];
|
|
266
|
+
};
|
|
267
|
+
fastMode: {
|
|
268
|
+
enabled: boolean;
|
|
269
|
+
reducedPrompts: boolean;
|
|
270
|
+
skipOptionalChecks: boolean;
|
|
271
|
+
preloadTools: boolean;
|
|
272
|
+
streamingOptimizations: boolean;
|
|
273
|
+
};
|
|
274
|
+
models: {
|
|
275
|
+
maxContextTokens: number;
|
|
276
|
+
aliases: {
|
|
277
|
+
model: string;
|
|
278
|
+
alias: string;
|
|
279
|
+
provider?: string | undefined;
|
|
280
|
+
}[];
|
|
281
|
+
defaultModel: string;
|
|
282
|
+
fallbackModel: string;
|
|
283
|
+
};
|
|
284
|
+
remote: {
|
|
285
|
+
defaultPort: number;
|
|
286
|
+
keepAlive: boolean;
|
|
287
|
+
connectionTimeout: number;
|
|
288
|
+
defaultHost?: string | undefined;
|
|
289
|
+
defaultUsername?: string | undefined;
|
|
290
|
+
privateKeyPath?: string | undefined;
|
|
291
|
+
};
|
|
292
|
+
contextWindow: {
|
|
293
|
+
maxTokens: number;
|
|
294
|
+
compactionThreshold: number;
|
|
295
|
+
warningThreshold: number;
|
|
296
|
+
strategy: "sliding" | "compaction" | "hybrid";
|
|
297
|
+
};
|
|
298
|
+
theme: {
|
|
299
|
+
name: "dark" | "light" | "light-daltonized" | "dark-daltonized" | "light-ansi" | "dark-ansi" | "auto";
|
|
300
|
+
};
|
|
301
|
+
housekeeping: {
|
|
302
|
+
enabled: boolean;
|
|
303
|
+
cleanupInterval: number;
|
|
304
|
+
maxHistoryAge: number;
|
|
305
|
+
maxMemorySize: number;
|
|
306
|
+
idleThreshold: number;
|
|
307
|
+
};
|
|
308
|
+
defaultProvider?: string | undefined;
|
|
309
|
+
systemPrompt?: string | undefined;
|
|
310
|
+
}, {
|
|
311
|
+
defaultProvider?: string | undefined;
|
|
312
|
+
providers?: {
|
|
313
|
+
name: string;
|
|
314
|
+
baseUrl: string;
|
|
315
|
+
model: string;
|
|
316
|
+
format: "custom" | "openai-compatible" | "messages-compatible" | "glm-compatible";
|
|
317
|
+
apiKey?: string | undefined;
|
|
318
|
+
headers?: Record<string, string> | undefined;
|
|
319
|
+
timeout?: number | undefined;
|
|
320
|
+
maxTokens?: number | undefined;
|
|
321
|
+
}[] | undefined;
|
|
322
|
+
permissionMode?: "ask" | "auto-accept" | "plan" | undefined;
|
|
323
|
+
verbose?: boolean | undefined;
|
|
324
|
+
maxContextTokens?: number | undefined;
|
|
325
|
+
systemPrompt?: string | undefined;
|
|
326
|
+
autoMode?: {
|
|
327
|
+
enabled?: boolean | undefined;
|
|
328
|
+
trustLevel?: "ask" | "full-auto" | "safe-auto" | undefined;
|
|
329
|
+
autoApprovedTools?: string[] | undefined;
|
|
330
|
+
autoApprovedCommands?: string[] | undefined;
|
|
331
|
+
maxAutoActions?: number | undefined;
|
|
332
|
+
requireConfirmationFor?: string[] | undefined;
|
|
333
|
+
} | undefined;
|
|
334
|
+
fastMode?: {
|
|
335
|
+
enabled?: boolean | undefined;
|
|
336
|
+
reducedPrompts?: boolean | undefined;
|
|
337
|
+
skipOptionalChecks?: boolean | undefined;
|
|
338
|
+
preloadTools?: boolean | undefined;
|
|
339
|
+
streamingOptimizations?: boolean | undefined;
|
|
340
|
+
} | undefined;
|
|
341
|
+
models?: {
|
|
342
|
+
maxContextTokens?: number | undefined;
|
|
343
|
+
aliases?: {
|
|
344
|
+
model: string;
|
|
345
|
+
alias: string;
|
|
346
|
+
provider?: string | undefined;
|
|
347
|
+
}[] | undefined;
|
|
348
|
+
defaultModel?: string | undefined;
|
|
349
|
+
fallbackModel?: string | undefined;
|
|
350
|
+
} | undefined;
|
|
351
|
+
remote?: {
|
|
352
|
+
defaultHost?: string | undefined;
|
|
353
|
+
defaultPort?: number | undefined;
|
|
354
|
+
defaultUsername?: string | undefined;
|
|
355
|
+
privateKeyPath?: string | undefined;
|
|
356
|
+
keepAlive?: boolean | undefined;
|
|
357
|
+
connectionTimeout?: number | undefined;
|
|
358
|
+
} | undefined;
|
|
359
|
+
contextWindow?: {
|
|
360
|
+
maxTokens?: number | undefined;
|
|
361
|
+
compactionThreshold?: number | undefined;
|
|
362
|
+
warningThreshold?: number | undefined;
|
|
363
|
+
strategy?: "sliding" | "compaction" | "hybrid" | undefined;
|
|
364
|
+
} | undefined;
|
|
365
|
+
theme?: {
|
|
366
|
+
name?: "dark" | "light" | "light-daltonized" | "dark-daltonized" | "light-ansi" | "dark-ansi" | "auto" | undefined;
|
|
367
|
+
} | undefined;
|
|
368
|
+
housekeeping?: {
|
|
369
|
+
enabled?: boolean | undefined;
|
|
370
|
+
cleanupInterval?: number | undefined;
|
|
371
|
+
maxHistoryAge?: number | undefined;
|
|
372
|
+
maxMemorySize?: number | undefined;
|
|
373
|
+
idleThreshold?: number | undefined;
|
|
374
|
+
} | undefined;
|
|
375
|
+
}>;
|
|
376
|
+
type AppConfig = z.infer<typeof appConfigSchema>;
|
|
377
|
+
|
|
378
|
+
type Role = 'system' | 'user' | 'assistant';
|
|
379
|
+
type TextBlock = {
|
|
380
|
+
type: 'text';
|
|
381
|
+
text: string;
|
|
382
|
+
};
|
|
383
|
+
type ToolUseBlock = {
|
|
384
|
+
type: 'tool_use';
|
|
385
|
+
id: string;
|
|
386
|
+
name: string;
|
|
387
|
+
input: Record<string, unknown>;
|
|
388
|
+
};
|
|
389
|
+
type ToolResultBlock = {
|
|
390
|
+
type: 'tool_result';
|
|
391
|
+
toolUseId: string;
|
|
392
|
+
content: string;
|
|
393
|
+
isError?: boolean;
|
|
394
|
+
};
|
|
395
|
+
type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock;
|
|
396
|
+
interface Message {
|
|
397
|
+
role: Role;
|
|
398
|
+
content: ContentBlock[];
|
|
399
|
+
}
|
|
400
|
+
interface ToolDefinition {
|
|
401
|
+
name: string;
|
|
402
|
+
description: string;
|
|
403
|
+
inputSchema: Record<string, unknown>;
|
|
404
|
+
}
|
|
405
|
+
type StreamEvent = {
|
|
406
|
+
type: 'text_delta';
|
|
407
|
+
text: string;
|
|
408
|
+
} | {
|
|
409
|
+
type: 'tool_use_start';
|
|
410
|
+
id: string;
|
|
411
|
+
name: string;
|
|
412
|
+
} | {
|
|
413
|
+
type: 'tool_use_delta';
|
|
414
|
+
id: string;
|
|
415
|
+
inputDelta: string;
|
|
416
|
+
} | {
|
|
417
|
+
type: 'tool_use_end';
|
|
418
|
+
id: string;
|
|
419
|
+
name: string;
|
|
420
|
+
input: Record<string, unknown>;
|
|
421
|
+
} | {
|
|
422
|
+
type: 'message_start';
|
|
423
|
+
model: string;
|
|
424
|
+
} | {
|
|
425
|
+
type: 'message_end';
|
|
426
|
+
stopReason: 'end_turn' | 'tool_use' | 'max_tokens';
|
|
427
|
+
usage: UsageStats;
|
|
428
|
+
};
|
|
429
|
+
interface UsageStats {
|
|
430
|
+
inputTokens: number;
|
|
431
|
+
outputTokens: number;
|
|
432
|
+
cacheReadTokens?: number;
|
|
433
|
+
cacheWriteTokens?: number;
|
|
434
|
+
}
|
|
435
|
+
interface CompletionRequest {
|
|
436
|
+
messages: Message[];
|
|
437
|
+
tools?: ToolDefinition[];
|
|
438
|
+
systemPrompt?: string;
|
|
439
|
+
maxTokens?: number;
|
|
440
|
+
temperature?: number;
|
|
441
|
+
stopSequences?: string[];
|
|
442
|
+
stream?: boolean;
|
|
443
|
+
/** External abort signal — linked with per-request timeout via AbortSignal.any() */
|
|
444
|
+
signal?: AbortSignal;
|
|
445
|
+
}
|
|
446
|
+
interface CompletionResult {
|
|
447
|
+
message: Message;
|
|
448
|
+
stopReason: 'end_turn' | 'tool_use' | 'max_tokens';
|
|
449
|
+
usage: UsageStats;
|
|
450
|
+
model: string;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
interface ProviderAdapter {
|
|
454
|
+
readonly name: string;
|
|
455
|
+
readonly config: ProviderConfig;
|
|
456
|
+
complete(request: CompletionRequest): Promise<CompletionResult>;
|
|
457
|
+
stream(request: CompletionRequest): AsyncGenerator<StreamEvent>;
|
|
458
|
+
validate(): Promise<{
|
|
459
|
+
ok: boolean;
|
|
460
|
+
error?: string;
|
|
461
|
+
}>;
|
|
462
|
+
estimateTokens(messages: {
|
|
463
|
+
content: string;
|
|
464
|
+
}[]): number;
|
|
465
|
+
dispose(): void;
|
|
466
|
+
}
|
|
467
|
+
declare abstract class BaseAdapter implements ProviderAdapter {
|
|
468
|
+
abstract readonly name: string;
|
|
469
|
+
abstract readonly config: ProviderConfig;
|
|
470
|
+
abstract complete(request: CompletionRequest): Promise<CompletionResult>;
|
|
471
|
+
abstract stream(request: CompletionRequest): AsyncGenerator<StreamEvent>;
|
|
472
|
+
abstract validate(): Promise<{
|
|
473
|
+
ok: boolean;
|
|
474
|
+
error?: string;
|
|
475
|
+
}>;
|
|
476
|
+
abstract dispose(): void;
|
|
477
|
+
private readonly rateLimitHandler;
|
|
478
|
+
estimateTokens(messages: {
|
|
479
|
+
content: string;
|
|
480
|
+
}[]): number;
|
|
481
|
+
protected buildUrl(path: string): string;
|
|
482
|
+
protected buildHeaders(): Record<string, string>;
|
|
483
|
+
/**
|
|
484
|
+
* Build an AbortSignal that combines the per-request timeout with an
|
|
485
|
+
* optional external signal (e.g. from a parent agent or user cancel).
|
|
486
|
+
* Uses AbortSignal.any() so EITHER source triggers abort.
|
|
487
|
+
*/
|
|
488
|
+
protected buildSignal(external?: AbortSignal): AbortSignal;
|
|
489
|
+
/**
|
|
490
|
+
* Fetch with automatic retry for rate-limit (429), server errors (5xx),
|
|
491
|
+
* and network failures (TypeError: fetch failed).
|
|
492
|
+
* `optionsFactory` is called per-attempt to create fresh AbortSignal timeouts.
|
|
493
|
+
*/
|
|
494
|
+
protected fetchWithRetry(url: string, optionsFactory: () => RequestInit): Promise<Response>;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** Events emitted by the agent loop */
|
|
498
|
+
type LoopEvent = {
|
|
499
|
+
type: 'assistant_text';
|
|
500
|
+
text: string;
|
|
501
|
+
} | {
|
|
502
|
+
type: 'tool_start';
|
|
503
|
+
toolName: string;
|
|
504
|
+
toolId: string;
|
|
505
|
+
} | {
|
|
506
|
+
type: 'tool_result';
|
|
507
|
+
toolName: string;
|
|
508
|
+
toolId: string;
|
|
509
|
+
result: string;
|
|
510
|
+
isError: boolean;
|
|
511
|
+
} | {
|
|
512
|
+
type: 'turn_complete';
|
|
513
|
+
turnNumber: number;
|
|
514
|
+
stopReason: string;
|
|
515
|
+
} | {
|
|
516
|
+
type: 'usage_update';
|
|
517
|
+
inputTokens: number;
|
|
518
|
+
outputTokens: number;
|
|
519
|
+
} | {
|
|
520
|
+
type: 'loop_complete';
|
|
521
|
+
totalTurns: number;
|
|
522
|
+
usage: UsageStats;
|
|
523
|
+
messages: Message[];
|
|
524
|
+
} | {
|
|
525
|
+
type: 'context_compacted';
|
|
526
|
+
summary: string;
|
|
527
|
+
removedCount: number;
|
|
528
|
+
} | {
|
|
529
|
+
type: 'error';
|
|
530
|
+
error: Error;
|
|
531
|
+
};
|
|
532
|
+
/** Context passed to tools during execution */
|
|
533
|
+
interface ToolExecutionContext {
|
|
534
|
+
/** Working directory for the tool */
|
|
535
|
+
cwd: string;
|
|
536
|
+
/** Abort signal for cancellation */
|
|
537
|
+
abortSignal: AbortSignal;
|
|
538
|
+
/** Permission checker — returns true if operation is allowed */
|
|
539
|
+
checkPermission: (operation: string, details?: string) => Promise<boolean>;
|
|
540
|
+
/** Session identifier for per-session state isolation */
|
|
541
|
+
sessionId?: string;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** Risk level of a tool operation */
|
|
545
|
+
type RiskLevel = 'readonly' | 'safe' | 'destructive' | 'critical';
|
|
546
|
+
/** Definition of a tool that can be used by the AI */
|
|
547
|
+
interface ToolContract {
|
|
548
|
+
/** Unique name of the tool */
|
|
549
|
+
name: string;
|
|
550
|
+
/** Description shown to the AI model */
|
|
551
|
+
description: string;
|
|
552
|
+
/** Zod schema for input validation */
|
|
553
|
+
inputSchema: z.ZodType;
|
|
554
|
+
/** Risk level — determines permission requirements */
|
|
555
|
+
riskLevel: RiskLevel;
|
|
556
|
+
/** Whether this tool can run concurrently with other tools */
|
|
557
|
+
concurrencySafe: boolean;
|
|
558
|
+
/** Whether this tool only reads data (no side effects) */
|
|
559
|
+
readOnly: boolean;
|
|
560
|
+
/**
|
|
561
|
+
* Execute the tool with validated input.
|
|
562
|
+
* Returns a string result to be sent back to the model.
|
|
563
|
+
*/
|
|
564
|
+
execute(input: z.infer<this['inputSchema']>, context: ToolExecutionContext): Promise<string>;
|
|
565
|
+
/**
|
|
566
|
+
* Generate the tool definition for the AI model's tool list.
|
|
567
|
+
*/
|
|
568
|
+
toToolDefinition(): {
|
|
569
|
+
name: string;
|
|
570
|
+
description: string;
|
|
571
|
+
inputSchema: Record<string, unknown>;
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Base class for tools with common functionality.
|
|
576
|
+
*/
|
|
577
|
+
declare abstract class BaseTool<T extends z.ZodType> implements ToolContract {
|
|
578
|
+
abstract name: string;
|
|
579
|
+
abstract description: string;
|
|
580
|
+
abstract inputSchema: T;
|
|
581
|
+
abstract riskLevel: RiskLevel;
|
|
582
|
+
abstract concurrencySafe: boolean;
|
|
583
|
+
abstract readOnly: boolean;
|
|
584
|
+
abstract execute(input: z.infer<T>, context: ToolExecutionContext): Promise<string>;
|
|
585
|
+
toToolDefinition(): {
|
|
586
|
+
name: string;
|
|
587
|
+
description: string;
|
|
588
|
+
inputSchema: Record<string, unknown>;
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Registry of available tools.
|
|
594
|
+
* Manages tool registration and provides tool definitions for AI requests.
|
|
595
|
+
*/
|
|
596
|
+
declare class ToolRegistry {
|
|
597
|
+
private tools;
|
|
598
|
+
/** Register a tool */
|
|
599
|
+
register(tool: ToolContract): void;
|
|
600
|
+
/** Get a tool by name */
|
|
601
|
+
get(name: string): ToolContract | undefined;
|
|
602
|
+
/** Get all registered tools */
|
|
603
|
+
getAll(): ToolContract[];
|
|
604
|
+
/** Get tool definitions for AI model requests */
|
|
605
|
+
getToolDefinitions(): ToolDefinition[];
|
|
606
|
+
/** Check if a tool exists */
|
|
607
|
+
has(name: string): boolean;
|
|
608
|
+
/** Unregister a tool */
|
|
609
|
+
unregister(name: string): void;
|
|
610
|
+
/** Clear all tools */
|
|
611
|
+
clear(): void;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
declare class AdapterRegistry {
|
|
615
|
+
private adapters;
|
|
616
|
+
register(config: ProviderConfig): ProviderAdapter;
|
|
617
|
+
get(name: string): ProviderAdapter | undefined;
|
|
618
|
+
getAll(): ProviderAdapter[];
|
|
619
|
+
unregister(name: string): void;
|
|
620
|
+
disposeAll(): void;
|
|
621
|
+
private createAdapter;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** Alias mapping for model names */
|
|
625
|
+
interface ModelAlias {
|
|
626
|
+
alias: string;
|
|
627
|
+
model: string;
|
|
628
|
+
provider?: string;
|
|
629
|
+
}
|
|
630
|
+
/** Configuration for unrestricted model access */
|
|
631
|
+
interface ModelAccessConfig {
|
|
632
|
+
aliases: ModelAlias[];
|
|
633
|
+
defaultModel: string;
|
|
634
|
+
fallbackModel: string;
|
|
635
|
+
maxContextTokens: number;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Manages model name resolution with alias support.
|
|
639
|
+
* No subscription restrictions — all models available to everyone.
|
|
640
|
+
*/
|
|
641
|
+
declare class ModelAccessManager {
|
|
642
|
+
private config;
|
|
643
|
+
private aliasMap;
|
|
644
|
+
constructor(config: ModelAccessConfig);
|
|
645
|
+
/** Resolve a model name or alias to the actual model identifier */
|
|
646
|
+
resolveModelName(nameOrAlias: string): string;
|
|
647
|
+
/** Get the provider for a model alias, if specified */
|
|
648
|
+
getProviderForAlias(nameOrAlias: string): string | undefined;
|
|
649
|
+
/** Get the effective model to use (with fallback) */
|
|
650
|
+
getEffectiveModel(requestedModel?: string): string;
|
|
651
|
+
/** Get fallback model when primary is unavailable */
|
|
652
|
+
getFallbackModel(): string;
|
|
653
|
+
/** Get max context tokens (no subscription limits) */
|
|
654
|
+
getMaxContextTokens(): number;
|
|
655
|
+
/** List all available aliases */
|
|
656
|
+
listAliases(): ModelAlias[];
|
|
657
|
+
/** Add or update an alias at runtime */
|
|
658
|
+
setAlias(alias: ModelAlias): void;
|
|
659
|
+
/** Remove an alias */
|
|
660
|
+
removeAlias(aliasName: string): boolean;
|
|
661
|
+
/** Check if a name is a known alias */
|
|
662
|
+
isAlias(name: string): boolean;
|
|
663
|
+
/** Get current config */
|
|
664
|
+
getConfig(): Readonly<ModelAccessConfig>;
|
|
665
|
+
/** Update configuration */
|
|
666
|
+
updateConfig(partial: Partial<ModelAccessConfig>): void;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** Task categories for model selection heuristics */
|
|
670
|
+
type TaskCategory = 'reasoning' | 'code' | 'fast' | 'creative' | 'analysis' | 'default';
|
|
671
|
+
interface ModelRouterConfig {
|
|
672
|
+
/** Default model/alias to use when no specific model is requested */
|
|
673
|
+
defaultModel: string;
|
|
674
|
+
/** Model preferences per task category */
|
|
675
|
+
preferences: Partial<Record<TaskCategory, string>>;
|
|
676
|
+
}
|
|
677
|
+
declare class ModelRouter {
|
|
678
|
+
private registry;
|
|
679
|
+
private modelAccess;
|
|
680
|
+
private config;
|
|
681
|
+
constructor(registry: AdapterRegistry, modelAccess: ModelAccessManager, config?: Partial<ModelRouterConfig>);
|
|
682
|
+
/** Resolve a model name or alias to a concrete adapter */
|
|
683
|
+
resolve(modelOrAlias?: string): ProviderAdapter | null;
|
|
684
|
+
/** Auto-select the best adapter based on a task description */
|
|
685
|
+
autoSelect(taskDescription: string): ProviderAdapter | null;
|
|
686
|
+
/** Classify a task description into a task category */
|
|
687
|
+
classifyTask(text: string): TaskCategory;
|
|
688
|
+
/** Get model capabilities category from model name */
|
|
689
|
+
getModelCategory(modelName: string): TaskCategory;
|
|
690
|
+
/** List all available models across all adapters */
|
|
691
|
+
listAvailableModels(): Array<{
|
|
692
|
+
provider: string;
|
|
693
|
+
model: string;
|
|
694
|
+
category: TaskCategory;
|
|
695
|
+
}>;
|
|
696
|
+
/** Get the effective model name for a given alias or name */
|
|
697
|
+
getEffectiveModel(requestedModel?: string): string;
|
|
698
|
+
private findAdapterForModel;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/** Trust level for auto mode */
|
|
702
|
+
type TrustLevel = 'full-auto' | 'safe-auto' | 'ask';
|
|
703
|
+
/** Configuration for auto mode behavior */
|
|
704
|
+
interface AutoModeConfig {
|
|
705
|
+
enabled: boolean;
|
|
706
|
+
trustLevel: TrustLevel;
|
|
707
|
+
autoApprovedTools: string[];
|
|
708
|
+
autoApprovedCommands: string[];
|
|
709
|
+
maxAutoActions: number;
|
|
710
|
+
requireConfirmationFor: string[];
|
|
711
|
+
}
|
|
712
|
+
/** Result of an auto-approval check */
|
|
713
|
+
interface AutoApprovalResult {
|
|
714
|
+
approved: boolean;
|
|
715
|
+
reason: string;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Manages automatic approval of tool executions based on trust level,
|
|
719
|
+
* whitelists, and blacklists. No subscription checks — fully free.
|
|
720
|
+
*/
|
|
721
|
+
declare class AutoModeManager {
|
|
722
|
+
private config;
|
|
723
|
+
private actionCount;
|
|
724
|
+
constructor(config: AutoModeConfig);
|
|
725
|
+
/** Check if a tool execution should be auto-approved */
|
|
726
|
+
shouldAutoApprove(toolName: string, riskLevel: RiskLevel, content?: string): AutoApprovalResult;
|
|
727
|
+
/** Get current auto action count */
|
|
728
|
+
getActionCount(): number;
|
|
729
|
+
/** Reset action counter */
|
|
730
|
+
resetActionCount(): void;
|
|
731
|
+
/** Update configuration at runtime */
|
|
732
|
+
updateConfig(partial: Partial<AutoModeConfig>): void;
|
|
733
|
+
/** Get current config */
|
|
734
|
+
getConfig(): Readonly<AutoModeConfig>;
|
|
735
|
+
/** Check if auto mode is effectively active */
|
|
736
|
+
isActive(): boolean;
|
|
737
|
+
private isBlacklisted;
|
|
738
|
+
private isToolWhitelisted;
|
|
739
|
+
private isRiskApproved;
|
|
740
|
+
private isCommandSafe;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/** Configuration for fast mode optimizations */
|
|
744
|
+
interface FastModeConfig {
|
|
745
|
+
enabled: boolean;
|
|
746
|
+
reducedPrompts: boolean;
|
|
747
|
+
skipOptionalChecks: boolean;
|
|
748
|
+
preloadTools: boolean;
|
|
749
|
+
streamingOptimizations: boolean;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Manages fast mode optimizations for quicker agent responses.
|
|
753
|
+
* No upsell messages — simply works when enabled.
|
|
754
|
+
*/
|
|
755
|
+
declare class FastModeManager {
|
|
756
|
+
private config;
|
|
757
|
+
constructor(config: FastModeConfig);
|
|
758
|
+
/** Check if fast mode is active */
|
|
759
|
+
isActive(): boolean;
|
|
760
|
+
/** Get the system prompt modifier based on fast mode settings */
|
|
761
|
+
getSystemPromptModifier(): string;
|
|
762
|
+
/** Check if optional checks should be skipped */
|
|
763
|
+
shouldSkipOptionalChecks(): boolean;
|
|
764
|
+
/** Check if tools should be preloaded */
|
|
765
|
+
shouldPreloadTools(): boolean;
|
|
766
|
+
/** Check if streaming optimizations are enabled */
|
|
767
|
+
hasStreamingOptimizations(): boolean;
|
|
768
|
+
/** Get streaming batch size (smaller = more responsive, larger = faster throughput) */
|
|
769
|
+
getStreamingBatchSize(): number;
|
|
770
|
+
/** Get tool execution concurrency limit */
|
|
771
|
+
getToolConcurrency(): number;
|
|
772
|
+
/** Get the delay between turns (ms). Always 0 — no artificial delays. */
|
|
773
|
+
getInterTurnDelay(): number;
|
|
774
|
+
/** Get current config */
|
|
775
|
+
getConfig(): Readonly<FastModeConfig>;
|
|
776
|
+
/** Update configuration at runtime */
|
|
777
|
+
updateConfig(partial: Partial<FastModeConfig>): void;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/** Role definition for a plan mode agent */
|
|
781
|
+
interface PlanAgentRole {
|
|
782
|
+
name: string;
|
|
783
|
+
description: string;
|
|
784
|
+
systemPromptSuffix: string;
|
|
785
|
+
allowedTools: string[];
|
|
786
|
+
maxSteps: number;
|
|
787
|
+
}
|
|
788
|
+
/** Configuration for plan mode */
|
|
789
|
+
interface PlanModeConfig {
|
|
790
|
+
enabled: boolean;
|
|
791
|
+
maxParallelAgents: number;
|
|
792
|
+
agentRoles: PlanAgentRole[];
|
|
793
|
+
planningStrategy: 'sequential' | 'parallel' | 'adaptive';
|
|
794
|
+
maxStepsPerAgent: number;
|
|
795
|
+
contextSharing: boolean;
|
|
796
|
+
}
|
|
797
|
+
/** Single step in a plan */
|
|
798
|
+
interface PlanStep {
|
|
799
|
+
id: string;
|
|
800
|
+
description: string;
|
|
801
|
+
assignedAgent: string;
|
|
802
|
+
status: 'pending' | 'in-progress' | 'completed' | 'failed';
|
|
803
|
+
result?: string;
|
|
804
|
+
dependencies: string[];
|
|
805
|
+
}
|
|
806
|
+
/** A plan with steps and metadata */
|
|
807
|
+
interface Plan {
|
|
808
|
+
id: string;
|
|
809
|
+
goal: string;
|
|
810
|
+
steps: PlanStep[];
|
|
811
|
+
status: 'planning' | 'executing' | 'completed' | 'failed';
|
|
812
|
+
createdAt: Date;
|
|
813
|
+
completedAt?: Date;
|
|
814
|
+
}
|
|
815
|
+
/** Statistics for plan execution */
|
|
816
|
+
interface PlanStats {
|
|
817
|
+
totalSteps: number;
|
|
818
|
+
completedSteps: number;
|
|
819
|
+
failedSteps: number;
|
|
820
|
+
totalDuration: number;
|
|
821
|
+
agentStats: Record<string, {
|
|
822
|
+
steps: number;
|
|
823
|
+
success: number;
|
|
824
|
+
failed: number;
|
|
825
|
+
}>;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Manages plan mode lifecycle: creation, configuration, state.
|
|
829
|
+
* Does NOT execute plans — that is PlanExecutor's job.
|
|
830
|
+
*/
|
|
831
|
+
declare class PlanModeManager {
|
|
832
|
+
private config;
|
|
833
|
+
private activePlan;
|
|
834
|
+
constructor(config?: Partial<PlanModeConfig>);
|
|
835
|
+
/** Current configuration */
|
|
836
|
+
getConfig(): PlanModeConfig;
|
|
837
|
+
/** Update configuration */
|
|
838
|
+
updateConfig(partial: Partial<PlanModeConfig>): void;
|
|
839
|
+
/** Whether plan mode is enabled */
|
|
840
|
+
isEnabled(): boolean;
|
|
841
|
+
/** Enable plan mode */
|
|
842
|
+
enable(): void;
|
|
843
|
+
/** Disable plan mode */
|
|
844
|
+
disable(): void;
|
|
845
|
+
/** Get the active plan */
|
|
846
|
+
getActivePlan(): Plan | null;
|
|
847
|
+
/** Create a new plan from a goal */
|
|
848
|
+
createPlan(goal: string, steps: Omit<PlanStep, 'status'>[]): Plan;
|
|
849
|
+
/** Mark plan as executing */
|
|
850
|
+
startExecution(plan: Plan): void;
|
|
851
|
+
/** Mark plan as completed */
|
|
852
|
+
completePlan(plan: Plan): void;
|
|
853
|
+
/** Mark plan as failed */
|
|
854
|
+
failPlan(plan: Plan): void;
|
|
855
|
+
/** Get a role by name */
|
|
856
|
+
getRole(name: string): PlanAgentRole | undefined;
|
|
857
|
+
/** Get all roles */
|
|
858
|
+
getRoles(): PlanAgentRole[];
|
|
859
|
+
/** Compute statistics for a plan */
|
|
860
|
+
computeStats(plan: Plan): PlanStats;
|
|
861
|
+
/** Format a plan as a human-readable string */
|
|
862
|
+
formatPlan(plan: Plan): string;
|
|
863
|
+
/** Format execution stats as a human-readable report */
|
|
864
|
+
formatStats(stats: PlanStats): string;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
interface ContextWindowConfig {
|
|
868
|
+
maxTokens: number;
|
|
869
|
+
compactionThreshold: number;
|
|
870
|
+
warningThreshold: number;
|
|
871
|
+
strategy: 'sliding' | 'compaction' | 'hybrid';
|
|
872
|
+
}
|
|
873
|
+
interface ContextUsage {
|
|
874
|
+
usedTokens: number;
|
|
875
|
+
maxTokens: number;
|
|
876
|
+
remainingTokens: number;
|
|
877
|
+
usagePercent: number;
|
|
878
|
+
needsWarning: boolean;
|
|
879
|
+
needsCompaction: boolean;
|
|
880
|
+
}
|
|
881
|
+
declare class ContextWindowManager {
|
|
882
|
+
private readonly config;
|
|
883
|
+
constructor(config?: Partial<ContextWindowConfig>);
|
|
884
|
+
getCurrentUsage(messages: Message[], systemPrompt?: string): ContextUsage;
|
|
885
|
+
needsCompaction(messages: Message[], systemPrompt?: string): boolean;
|
|
886
|
+
estimateTokens(content: string): number;
|
|
887
|
+
getMaxTokens(): number;
|
|
888
|
+
getConfig(): Readonly<ContextWindowConfig>;
|
|
889
|
+
getCompactionThreshold(): number;
|
|
890
|
+
getWarningThreshold(): number;
|
|
891
|
+
getStrategy(): ContextWindowConfig['strategy'];
|
|
892
|
+
calculateMessagesTokens(messages: Message[]): number;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
interface QueryEngineConfig {
|
|
896
|
+
maxTurns: number;
|
|
897
|
+
maxTokens: number;
|
|
898
|
+
compactionThreshold: number;
|
|
899
|
+
systemPrompt?: string;
|
|
900
|
+
verbose?: boolean;
|
|
901
|
+
/** Permission checker forwarded from parent context (e.g. agent-tool) */
|
|
902
|
+
checkPermission?: (operation: string, details?: string) => Promise<boolean>;
|
|
903
|
+
/** External abort signal — linked to adapter requests via AbortSignal.any() */
|
|
904
|
+
signal?: AbortSignal;
|
|
905
|
+
}
|
|
906
|
+
interface QueryResult {
|
|
907
|
+
messages: Message[];
|
|
908
|
+
totalTokens: {
|
|
909
|
+
input: number;
|
|
910
|
+
output: number;
|
|
911
|
+
};
|
|
912
|
+
totalCost: number;
|
|
913
|
+
duration: number;
|
|
914
|
+
turns: number;
|
|
915
|
+
compacted: boolean;
|
|
916
|
+
}
|
|
917
|
+
type QueryEvent = {
|
|
918
|
+
type: 'text_delta';
|
|
919
|
+
text: string;
|
|
920
|
+
} | {
|
|
921
|
+
type: 'tool_use';
|
|
922
|
+
name: string;
|
|
923
|
+
input: unknown;
|
|
924
|
+
} | {
|
|
925
|
+
type: 'tool_result';
|
|
926
|
+
name: string;
|
|
927
|
+
output: string;
|
|
928
|
+
isError?: boolean;
|
|
929
|
+
} | {
|
|
930
|
+
type: 'compaction';
|
|
931
|
+
summary: string;
|
|
932
|
+
removedCount: number;
|
|
933
|
+
} | {
|
|
934
|
+
type: 'cost_update';
|
|
935
|
+
cost: number;
|
|
936
|
+
tokens: {
|
|
937
|
+
input: number;
|
|
938
|
+
output: number;
|
|
939
|
+
};
|
|
940
|
+
} | {
|
|
941
|
+
type: 'turn_start';
|
|
942
|
+
turn: number;
|
|
943
|
+
} | {
|
|
944
|
+
type: 'turn_end';
|
|
945
|
+
turn: number;
|
|
946
|
+
} | {
|
|
947
|
+
type: 'complete';
|
|
948
|
+
result: QueryResult;
|
|
949
|
+
} | {
|
|
950
|
+
type: 'error';
|
|
951
|
+
error: Error;
|
|
952
|
+
};
|
|
953
|
+
declare class QueryEngine {
|
|
954
|
+
private config;
|
|
955
|
+
private adapter;
|
|
956
|
+
private tools;
|
|
957
|
+
private executor;
|
|
958
|
+
private compactor;
|
|
959
|
+
private costTracker;
|
|
960
|
+
private abortController;
|
|
961
|
+
constructor(config: Partial<QueryEngineConfig>, adapter: ProviderAdapter, tools: ToolRegistry);
|
|
962
|
+
run(prompt: string): AsyncGenerator<QueryEvent>;
|
|
963
|
+
abort(): void;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
interface LoopDeps {
|
|
967
|
+
adapter: ProviderAdapter;
|
|
968
|
+
toolRegistry: ToolRegistry;
|
|
969
|
+
config: AppConfig;
|
|
970
|
+
systemPrompt: string;
|
|
971
|
+
cwd: string;
|
|
972
|
+
abortSignal: AbortSignal;
|
|
973
|
+
/** Permission callback — returns true if operation is allowed */
|
|
974
|
+
onPermissionRequest: (operation: string, details?: string) => Promise<boolean>;
|
|
975
|
+
/** Auto mode manager (optional — created from config if not provided) */
|
|
976
|
+
autoModeManager?: AutoModeManager;
|
|
977
|
+
/** Fast mode manager (optional — created from config if not provided) */
|
|
978
|
+
fastModeManager?: FastModeManager;
|
|
979
|
+
/** Plan mode manager (optional — enables multi-agent plan execution) */
|
|
980
|
+
planModeManager?: PlanModeManager;
|
|
981
|
+
/** Context window manager (optional — created from config if not provided) */
|
|
982
|
+
contextWindowManager?: ContextWindowManager;
|
|
983
|
+
/** Session history — messages from previous turns in this conversation */
|
|
984
|
+
sessionHistory?: Message[];
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Run the autonomous agent loop.
|
|
988
|
+
* Yields LoopEvents as the agent processes the user's input,
|
|
989
|
+
* calls tools, and generates responses.
|
|
990
|
+
*
|
|
991
|
+
* If `deps.sessionHistory` is provided, the loop continues an existing
|
|
992
|
+
* conversation — the history is prepended so the model sees the full context.
|
|
993
|
+
*/
|
|
994
|
+
declare function runAgentLoop(userMessage: string, deps: LoopDeps): AsyncGenerator<LoopEvent>;
|
|
995
|
+
/**
|
|
996
|
+
* Create a default tool registry with built-in tools.
|
|
997
|
+
* When a ModelRouter is provided, the AgentTool is also registered
|
|
998
|
+
* with full model routing capabilities.
|
|
999
|
+
*/
|
|
1000
|
+
declare function createDefaultToolRegistry(modelRouter?: ModelRouter): ToolRegistry;
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Adapter for chat/completions-compatible APIs.
|
|
1004
|
+
* Works with any provider implementing the /chat/completions endpoint.
|
|
1005
|
+
*/
|
|
1006
|
+
declare class GenericCompatAdapter extends BaseAdapter {
|
|
1007
|
+
readonly config: ProviderConfig;
|
|
1008
|
+
readonly name: string;
|
|
1009
|
+
constructor(config: ProviderConfig, name?: string);
|
|
1010
|
+
complete(request: CompletionRequest): Promise<CompletionResult>;
|
|
1011
|
+
stream(request: CompletionRequest): AsyncGenerator<StreamEvent>;
|
|
1012
|
+
validate(): Promise<{
|
|
1013
|
+
ok: boolean;
|
|
1014
|
+
error?: string;
|
|
1015
|
+
}>;
|
|
1016
|
+
dispose(): void;
|
|
1017
|
+
private buildRequestBody;
|
|
1018
|
+
private mapMessage;
|
|
1019
|
+
private mapTool;
|
|
1020
|
+
private mapResponse;
|
|
1021
|
+
private parseSSEStream;
|
|
1022
|
+
/** Track active tool calls: index → { id, name, args } for emitting tool_use_end */
|
|
1023
|
+
private activeToolCalls;
|
|
1024
|
+
private processChunk;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
declare const enterPlanInputSchema: z.ZodObject<{
|
|
1028
|
+
plan_prompt: z.ZodString;
|
|
1029
|
+
agents: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
1030
|
+
strategy: z.ZodOptional<z.ZodDefault<z.ZodEnum<["sequential", "parallel", "adaptive"]>>>;
|
|
1031
|
+
}, "strip", z.ZodTypeAny, {
|
|
1032
|
+
plan_prompt: string;
|
|
1033
|
+
strategy?: "sequential" | "parallel" | "adaptive" | undefined;
|
|
1034
|
+
agents?: number | undefined;
|
|
1035
|
+
}, {
|
|
1036
|
+
plan_prompt: string;
|
|
1037
|
+
strategy?: "sequential" | "parallel" | "adaptive" | undefined;
|
|
1038
|
+
agents?: number | undefined;
|
|
1039
|
+
}>;
|
|
1040
|
+
type EnterPlanInput = z.infer<typeof enterPlanInputSchema>;
|
|
1041
|
+
declare class EnterPlanModeTool extends BaseTool<typeof enterPlanInputSchema> {
|
|
1042
|
+
name: string;
|
|
1043
|
+
description: string;
|
|
1044
|
+
inputSchema: z.ZodObject<{
|
|
1045
|
+
plan_prompt: z.ZodString;
|
|
1046
|
+
agents: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
1047
|
+
strategy: z.ZodOptional<z.ZodDefault<z.ZodEnum<["sequential", "parallel", "adaptive"]>>>;
|
|
1048
|
+
}, "strip", z.ZodTypeAny, {
|
|
1049
|
+
plan_prompt: string;
|
|
1050
|
+
strategy?: "sequential" | "parallel" | "adaptive" | undefined;
|
|
1051
|
+
agents?: number | undefined;
|
|
1052
|
+
}, {
|
|
1053
|
+
plan_prompt: string;
|
|
1054
|
+
strategy?: "sequential" | "parallel" | "adaptive" | undefined;
|
|
1055
|
+
agents?: number | undefined;
|
|
1056
|
+
}>;
|
|
1057
|
+
riskLevel: "safe";
|
|
1058
|
+
concurrencySafe: boolean;
|
|
1059
|
+
readOnly: boolean;
|
|
1060
|
+
execute(input: EnterPlanInput, context: ToolExecutionContext): Promise<string>;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
declare const exitPlanInputSchema: z.ZodObject<{
|
|
1064
|
+
plan: z.ZodString;
|
|
1065
|
+
confirmed: z.ZodBoolean;
|
|
1066
|
+
}, "strip", z.ZodTypeAny, {
|
|
1067
|
+
plan: string;
|
|
1068
|
+
confirmed: boolean;
|
|
1069
|
+
}, {
|
|
1070
|
+
plan: string;
|
|
1071
|
+
confirmed: boolean;
|
|
1072
|
+
}>;
|
|
1073
|
+
type ExitPlanInput = z.infer<typeof exitPlanInputSchema>;
|
|
1074
|
+
declare class ExitPlanModeTool extends BaseTool<typeof exitPlanInputSchema> {
|
|
1075
|
+
name: string;
|
|
1076
|
+
description: string;
|
|
1077
|
+
inputSchema: z.ZodObject<{
|
|
1078
|
+
plan: z.ZodString;
|
|
1079
|
+
confirmed: z.ZodBoolean;
|
|
1080
|
+
}, "strip", z.ZodTypeAny, {
|
|
1081
|
+
plan: string;
|
|
1082
|
+
confirmed: boolean;
|
|
1083
|
+
}, {
|
|
1084
|
+
plan: string;
|
|
1085
|
+
confirmed: boolean;
|
|
1086
|
+
}>;
|
|
1087
|
+
riskLevel: "safe";
|
|
1088
|
+
concurrencySafe: boolean;
|
|
1089
|
+
readOnly: boolean;
|
|
1090
|
+
execute(input: ExitPlanInput, context: ToolExecutionContext): Promise<string>;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
declare const webSearchInputSchema: z.ZodObject<{
|
|
1094
|
+
query: z.ZodString;
|
|
1095
|
+
max_results: z.ZodDefault<z.ZodNumber>;
|
|
1096
|
+
search_engine: z.ZodDefault<z.ZodEnum<["duckduckgo", "google"]>>;
|
|
1097
|
+
}, "strip", z.ZodTypeAny, {
|
|
1098
|
+
max_results: number;
|
|
1099
|
+
query: string;
|
|
1100
|
+
search_engine: "duckduckgo" | "google";
|
|
1101
|
+
}, {
|
|
1102
|
+
query: string;
|
|
1103
|
+
max_results?: number | undefined;
|
|
1104
|
+
search_engine?: "duckduckgo" | "google" | undefined;
|
|
1105
|
+
}>;
|
|
1106
|
+
type WebSearchInput = z.infer<typeof webSearchInputSchema>;
|
|
1107
|
+
declare class WebSearchTool extends BaseTool<typeof webSearchInputSchema> {
|
|
1108
|
+
name: string;
|
|
1109
|
+
description: string;
|
|
1110
|
+
inputSchema: z.ZodObject<{
|
|
1111
|
+
query: z.ZodString;
|
|
1112
|
+
max_results: z.ZodDefault<z.ZodNumber>;
|
|
1113
|
+
search_engine: z.ZodDefault<z.ZodEnum<["duckduckgo", "google"]>>;
|
|
1114
|
+
}, "strip", z.ZodTypeAny, {
|
|
1115
|
+
max_results: number;
|
|
1116
|
+
query: string;
|
|
1117
|
+
search_engine: "duckduckgo" | "google";
|
|
1118
|
+
}, {
|
|
1119
|
+
query: string;
|
|
1120
|
+
max_results?: number | undefined;
|
|
1121
|
+
search_engine?: "duckduckgo" | "google" | undefined;
|
|
1122
|
+
}>;
|
|
1123
|
+
riskLevel: "safe";
|
|
1124
|
+
concurrencySafe: boolean;
|
|
1125
|
+
readOnly: boolean;
|
|
1126
|
+
execute(input: WebSearchInput, _context: ToolExecutionContext): Promise<string>;
|
|
1127
|
+
private fallbackLiteSearch;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
declare const lspInputSchema: z.ZodObject<{
|
|
1131
|
+
operation: z.ZodEnum<["go_to_definition", "find_references", "hover", "document_symbols", "workspace_symbols"]>;
|
|
1132
|
+
file_path: z.ZodString;
|
|
1133
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
1134
|
+
character: z.ZodOptional<z.ZodNumber>;
|
|
1135
|
+
query: z.ZodOptional<z.ZodString>;
|
|
1136
|
+
}, "strip", z.ZodTypeAny, {
|
|
1137
|
+
operation: "go_to_definition" | "find_references" | "hover" | "document_symbols" | "workspace_symbols";
|
|
1138
|
+
file_path: string;
|
|
1139
|
+
query?: string | undefined;
|
|
1140
|
+
line?: number | undefined;
|
|
1141
|
+
character?: number | undefined;
|
|
1142
|
+
}, {
|
|
1143
|
+
operation: "go_to_definition" | "find_references" | "hover" | "document_symbols" | "workspace_symbols";
|
|
1144
|
+
file_path: string;
|
|
1145
|
+
query?: string | undefined;
|
|
1146
|
+
line?: number | undefined;
|
|
1147
|
+
character?: number | undefined;
|
|
1148
|
+
}>;
|
|
1149
|
+
type LspInput = z.infer<typeof lspInputSchema>;
|
|
1150
|
+
declare class LspTool extends BaseTool<typeof lspInputSchema> {
|
|
1151
|
+
name: string;
|
|
1152
|
+
description: string;
|
|
1153
|
+
inputSchema: z.ZodObject<{
|
|
1154
|
+
operation: z.ZodEnum<["go_to_definition", "find_references", "hover", "document_symbols", "workspace_symbols"]>;
|
|
1155
|
+
file_path: z.ZodString;
|
|
1156
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
1157
|
+
character: z.ZodOptional<z.ZodNumber>;
|
|
1158
|
+
query: z.ZodOptional<z.ZodString>;
|
|
1159
|
+
}, "strip", z.ZodTypeAny, {
|
|
1160
|
+
operation: "go_to_definition" | "find_references" | "hover" | "document_symbols" | "workspace_symbols";
|
|
1161
|
+
file_path: string;
|
|
1162
|
+
query?: string | undefined;
|
|
1163
|
+
line?: number | undefined;
|
|
1164
|
+
character?: number | undefined;
|
|
1165
|
+
}, {
|
|
1166
|
+
operation: "go_to_definition" | "find_references" | "hover" | "document_symbols" | "workspace_symbols";
|
|
1167
|
+
file_path: string;
|
|
1168
|
+
query?: string | undefined;
|
|
1169
|
+
line?: number | undefined;
|
|
1170
|
+
character?: number | undefined;
|
|
1171
|
+
}>;
|
|
1172
|
+
riskLevel: "readonly";
|
|
1173
|
+
concurrencySafe: boolean;
|
|
1174
|
+
readOnly: boolean;
|
|
1175
|
+
execute(input: LspInput, context: ToolExecutionContext): Promise<string>;
|
|
1176
|
+
private goToDefinition;
|
|
1177
|
+
private findReferences;
|
|
1178
|
+
private hover;
|
|
1179
|
+
private documentSymbols;
|
|
1180
|
+
private workspaceSymbols;
|
|
1181
|
+
private extractNameAtPosition;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
declare const agentInputSchema: z.ZodObject<{
|
|
1185
|
+
task: z.ZodString;
|
|
1186
|
+
working_directory: z.ZodOptional<z.ZodString>;
|
|
1187
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1188
|
+
max_turns: z.ZodDefault<z.ZodNumber>;
|
|
1189
|
+
model: z.ZodOptional<z.ZodString>;
|
|
1190
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
1191
|
+
}, "strip", z.ZodTypeAny, {
|
|
1192
|
+
task: string;
|
|
1193
|
+
max_turns: number;
|
|
1194
|
+
model?: string | undefined;
|
|
1195
|
+
timeout?: number | undefined;
|
|
1196
|
+
working_directory?: string | undefined;
|
|
1197
|
+
tools?: string[] | undefined;
|
|
1198
|
+
}, {
|
|
1199
|
+
task: string;
|
|
1200
|
+
model?: string | undefined;
|
|
1201
|
+
timeout?: number | undefined;
|
|
1202
|
+
working_directory?: string | undefined;
|
|
1203
|
+
tools?: string[] | undefined;
|
|
1204
|
+
max_turns?: number | undefined;
|
|
1205
|
+
}>;
|
|
1206
|
+
type AgentInput = z.infer<typeof agentInputSchema>;
|
|
1207
|
+
/** Router factory type — injected at registration time */
|
|
1208
|
+
type ModelRouterFactory = () => ModelRouter;
|
|
1209
|
+
/** Registry factory type — provides the parent registry for tool filtering */
|
|
1210
|
+
type RegistryFactory = () => ToolRegistry;
|
|
1211
|
+
declare class AgentTool extends BaseTool<typeof agentInputSchema> {
|
|
1212
|
+
name: string;
|
|
1213
|
+
description: string;
|
|
1214
|
+
inputSchema: z.ZodObject<{
|
|
1215
|
+
task: z.ZodString;
|
|
1216
|
+
working_directory: z.ZodOptional<z.ZodString>;
|
|
1217
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1218
|
+
max_turns: z.ZodDefault<z.ZodNumber>;
|
|
1219
|
+
model: z.ZodOptional<z.ZodString>;
|
|
1220
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
1221
|
+
}, "strip", z.ZodTypeAny, {
|
|
1222
|
+
task: string;
|
|
1223
|
+
max_turns: number;
|
|
1224
|
+
model?: string | undefined;
|
|
1225
|
+
timeout?: number | undefined;
|
|
1226
|
+
working_directory?: string | undefined;
|
|
1227
|
+
tools?: string[] | undefined;
|
|
1228
|
+
}, {
|
|
1229
|
+
task: string;
|
|
1230
|
+
model?: string | undefined;
|
|
1231
|
+
timeout?: number | undefined;
|
|
1232
|
+
working_directory?: string | undefined;
|
|
1233
|
+
tools?: string[] | undefined;
|
|
1234
|
+
max_turns?: number | undefined;
|
|
1235
|
+
}>;
|
|
1236
|
+
riskLevel: "destructive";
|
|
1237
|
+
concurrencySafe: boolean;
|
|
1238
|
+
readOnly: boolean;
|
|
1239
|
+
private modelRouterFactory;
|
|
1240
|
+
private registryFactory;
|
|
1241
|
+
constructor(modelRouterFactory: ModelRouterFactory, registryFactory: RegistryFactory);
|
|
1242
|
+
execute(input: AgentInput, context: ToolExecutionContext): Promise<string>;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
/** A memory entry stored in the memory system */
|
|
1246
|
+
interface MemoryEntry {
|
|
1247
|
+
/** Unique ID */
|
|
1248
|
+
id: string;
|
|
1249
|
+
/** Topic/category */
|
|
1250
|
+
topic: string;
|
|
1251
|
+
/** Memory content */
|
|
1252
|
+
content: string;
|
|
1253
|
+
/** When this memory was created */
|
|
1254
|
+
createdAt: number;
|
|
1255
|
+
/** When this memory was last accessed */
|
|
1256
|
+
lastAccessedAt: number;
|
|
1257
|
+
/** Relevance score (0-1) for ranking */
|
|
1258
|
+
relevance?: number;
|
|
1259
|
+
}
|
|
1260
|
+
/** Configuration for the memory system */
|
|
1261
|
+
interface MemoryConfig {
|
|
1262
|
+
/** Directory to store memory files */
|
|
1263
|
+
memoryDir: string;
|
|
1264
|
+
/** Maximum size of MEMORY.md entrypoint in characters */
|
|
1265
|
+
maxEntrypointSize: number;
|
|
1266
|
+
/** Maximum number of topic files */
|
|
1267
|
+
maxTopicFiles: number;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* File-based memory store.
|
|
1272
|
+
* Stores memories in a directory structure:
|
|
1273
|
+
* .cliskill/memory/
|
|
1274
|
+
* MEMORY.md — entrypoint (summary)
|
|
1275
|
+
* topics/
|
|
1276
|
+
* project.md — topic-specific memories
|
|
1277
|
+
* preferences.md
|
|
1278
|
+
* ...
|
|
1279
|
+
*/
|
|
1280
|
+
declare class MemoryStore {
|
|
1281
|
+
private config;
|
|
1282
|
+
private rootDir;
|
|
1283
|
+
private cache;
|
|
1284
|
+
private loaded;
|
|
1285
|
+
constructor(projectRoot: string, config?: Partial<MemoryConfig>);
|
|
1286
|
+
/**
|
|
1287
|
+
* Initialize the memory directory structure.
|
|
1288
|
+
*/
|
|
1289
|
+
init(): Promise<void>;
|
|
1290
|
+
/**
|
|
1291
|
+
* Load all memories from disk into cache.
|
|
1292
|
+
*/
|
|
1293
|
+
load(): Promise<void>;
|
|
1294
|
+
/**
|
|
1295
|
+
* Get a memory by topic.
|
|
1296
|
+
*/
|
|
1297
|
+
get(topic: string): MemoryEntry | undefined;
|
|
1298
|
+
/**
|
|
1299
|
+
* Get all memories.
|
|
1300
|
+
*/
|
|
1301
|
+
getAll(): MemoryEntry[];
|
|
1302
|
+
/**
|
|
1303
|
+
* Save a memory entry to disk.
|
|
1304
|
+
*/
|
|
1305
|
+
set(topic: string, content: string): Promise<void>;
|
|
1306
|
+
/**
|
|
1307
|
+
* Delete a memory by topic.
|
|
1308
|
+
*/
|
|
1309
|
+
delete(topic: string): Promise<boolean>;
|
|
1310
|
+
/**
|
|
1311
|
+
* Search memories by keyword.
|
|
1312
|
+
*/
|
|
1313
|
+
search(query: string): MemoryEntry[];
|
|
1314
|
+
/**
|
|
1315
|
+
* Get the entrypoint (MEMORY.md) content.
|
|
1316
|
+
*/
|
|
1317
|
+
getEntrypoint(): Promise<string>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Update the entrypoint (MEMORY.md) content.
|
|
1320
|
+
*/
|
|
1321
|
+
setEntrypoint(content: string): Promise<void>;
|
|
1322
|
+
/**
|
|
1323
|
+
* Build a context string from relevant memories for inclusion in system prompt.
|
|
1324
|
+
*/
|
|
1325
|
+
buildContext(query?: string, maxTokens?: number): Promise<string>;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
interface EnhancedMemoryEntry {
|
|
1329
|
+
topic: string;
|
|
1330
|
+
content: string;
|
|
1331
|
+
timestamp: number;
|
|
1332
|
+
relevanceScore?: number;
|
|
1333
|
+
accessCount: number;
|
|
1334
|
+
lastAccessed: number;
|
|
1335
|
+
tags: string[];
|
|
1336
|
+
source: 'user' | 'agent' | 'auto';
|
|
1337
|
+
}
|
|
1338
|
+
interface MemorySearchResult {
|
|
1339
|
+
entry: EnhancedMemoryEntry;
|
|
1340
|
+
score: number;
|
|
1341
|
+
matchedTerms: string[];
|
|
1342
|
+
}
|
|
1343
|
+
interface EnhancedMemoryConfig {
|
|
1344
|
+
maxEntriesPerTopic: number;
|
|
1345
|
+
maxTotalSize: number;
|
|
1346
|
+
autoExtract: boolean;
|
|
1347
|
+
relevanceDecayDays: number;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
declare class EnhancedMemoryStore {
|
|
1351
|
+
private config;
|
|
1352
|
+
private baseDir;
|
|
1353
|
+
private entries;
|
|
1354
|
+
private loaded;
|
|
1355
|
+
constructor(baseDir: string, config?: Partial<EnhancedMemoryConfig>);
|
|
1356
|
+
init(): Promise<void>;
|
|
1357
|
+
load(): Promise<void>;
|
|
1358
|
+
addMemory(topic: string, content: string, tags?: string[], source?: EnhancedMemoryEntry['source']): Promise<void>;
|
|
1359
|
+
search(query: string, limit?: number): Promise<MemorySearchResult[]>;
|
|
1360
|
+
extractMemories(text: string): Promise<string[]>;
|
|
1361
|
+
getStats(): {
|
|
1362
|
+
totalEntries: number;
|
|
1363
|
+
totalSize: number;
|
|
1364
|
+
topics: string[];
|
|
1365
|
+
};
|
|
1366
|
+
prune(): Promise<number>;
|
|
1367
|
+
private getAllEntries;
|
|
1368
|
+
private persist;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/** A skill definition loaded from a .md file or registered programmatically */
|
|
1372
|
+
interface SkillDefinition {
|
|
1373
|
+
/** Unique name */
|
|
1374
|
+
name: string;
|
|
1375
|
+
/** Human-readable description */
|
|
1376
|
+
description: string;
|
|
1377
|
+
/** Aliases for invocation */
|
|
1378
|
+
aliases?: string[];
|
|
1379
|
+
/** The prompt template to inject when skill is activated */
|
|
1380
|
+
prompt: string;
|
|
1381
|
+
/** List of tools this skill is allowed to use (empty = all) */
|
|
1382
|
+
allowedTools?: string[];
|
|
1383
|
+
/** Whether this skill is built-in or user-defined */
|
|
1384
|
+
builtin: boolean;
|
|
1385
|
+
/** Source file path (for user-defined skills) */
|
|
1386
|
+
sourcePath?: string;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* Registry of available skills.
|
|
1391
|
+
* Manages skill registration, lookup, and loading from disk.
|
|
1392
|
+
*/
|
|
1393
|
+
declare class SkillRegistry {
|
|
1394
|
+
private skills;
|
|
1395
|
+
private aliasIndex;
|
|
1396
|
+
/** Register a skill */
|
|
1397
|
+
register(skill: SkillDefinition): void;
|
|
1398
|
+
/** Get a skill by name or alias */
|
|
1399
|
+
get(nameOrAlias: string): SkillDefinition | undefined;
|
|
1400
|
+
/** Get all registered skills */
|
|
1401
|
+
getAll(): SkillDefinition[];
|
|
1402
|
+
/** Check if a skill exists */
|
|
1403
|
+
has(name: string): boolean;
|
|
1404
|
+
/** Unregister a skill */
|
|
1405
|
+
unregister(name: string): void;
|
|
1406
|
+
/**
|
|
1407
|
+
* Load skills from a directory.
|
|
1408
|
+
* Returns the number of skills loaded.
|
|
1409
|
+
*/
|
|
1410
|
+
loadFromDir(dir: string): Promise<number>;
|
|
1411
|
+
/**
|
|
1412
|
+
* Load skills from standard locations:
|
|
1413
|
+
* 1. ~/.cliskill/skills/ (global user skills)
|
|
1414
|
+
* 2. .cliskill/skills/ (project skills)
|
|
1415
|
+
*/
|
|
1416
|
+
loadStandardSkills(projectRoot: string): Promise<number>;
|
|
1417
|
+
/**
|
|
1418
|
+
* Get skill prompt for injection into system prompt.
|
|
1419
|
+
*/
|
|
1420
|
+
getSkillPrompt(nameOrAlias: string): string | undefined;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
/** Permission mode for the session */
|
|
1424
|
+
type PermissionMode = 'ask' | 'auto-accept' | 'plan';
|
|
1425
|
+
/** A rule that allows or denies an operation */
|
|
1426
|
+
interface PermissionRule {
|
|
1427
|
+
/** Tool name pattern (e.g., "bash", "file_*") */
|
|
1428
|
+
tool: string;
|
|
1429
|
+
/** Content pattern (e.g., "git *", "rm *") */
|
|
1430
|
+
contentPattern?: string;
|
|
1431
|
+
/** Whether this rule allows or denies */
|
|
1432
|
+
allow: boolean;
|
|
1433
|
+
}
|
|
1434
|
+
/** Result of a permission check */
|
|
1435
|
+
interface PermissionResult {
|
|
1436
|
+
allowed: boolean;
|
|
1437
|
+
reason?: string;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Permission manager that evaluates tool execution requests
|
|
1441
|
+
* against configured rules and the current permission mode.
|
|
1442
|
+
*/
|
|
1443
|
+
declare class PermissionManager {
|
|
1444
|
+
private mode;
|
|
1445
|
+
private rules;
|
|
1446
|
+
private sessionDecisions;
|
|
1447
|
+
constructor(mode: PermissionMode, rules?: PermissionRule[]);
|
|
1448
|
+
/**
|
|
1449
|
+
* Check if a tool operation is allowed.
|
|
1450
|
+
*/
|
|
1451
|
+
check(toolName: string, riskLevel: RiskLevel, content?: string): PermissionResult;
|
|
1452
|
+
/**
|
|
1453
|
+
* Record a user decision for the session.
|
|
1454
|
+
*/
|
|
1455
|
+
recordDecision(toolName: string, content: string, allowed: boolean): void;
|
|
1456
|
+
/**
|
|
1457
|
+
* Add a permission rule.
|
|
1458
|
+
*/
|
|
1459
|
+
addRule(rule: PermissionRule): void;
|
|
1460
|
+
/**
|
|
1461
|
+
* Set the permission mode.
|
|
1462
|
+
*/
|
|
1463
|
+
setMode(mode: PermissionMode): void;
|
|
1464
|
+
/**
|
|
1465
|
+
* Get the current permission mode.
|
|
1466
|
+
*/
|
|
1467
|
+
getMode(): PermissionMode;
|
|
1468
|
+
private matchTool;
|
|
1469
|
+
private matchContent;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* Simple command inspector for shell commands.
|
|
1474
|
+
* Analyzes commands for potential security risks without full AST parsing.
|
|
1475
|
+
*/
|
|
1476
|
+
/** Risk classification of a shell command */
|
|
1477
|
+
type CommandRisk = 'safe' | 'moderate' | 'dangerous';
|
|
1478
|
+
/** Result of command analysis */
|
|
1479
|
+
interface CommandAnalysis$1 {
|
|
1480
|
+
risk: CommandRisk;
|
|
1481
|
+
reason: string;
|
|
1482
|
+
/** The base command (first word) */
|
|
1483
|
+
baseCommand: string;
|
|
1484
|
+
/** Whether the command modifies the filesystem */
|
|
1485
|
+
modifiesFiles: boolean;
|
|
1486
|
+
/** Whether the command accesses the network */
|
|
1487
|
+
accessesNetwork: boolean;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Analyze a shell command for security risks.
|
|
1491
|
+
*/
|
|
1492
|
+
declare function inspectCommand(command: string): CommandAnalysis$1;
|
|
1493
|
+
|
|
1494
|
+
interface ModelUsage {
|
|
1495
|
+
model: string;
|
|
1496
|
+
inputTokens: number;
|
|
1497
|
+
outputTokens: number;
|
|
1498
|
+
cacheReadTokens: number;
|
|
1499
|
+
cacheCreationTokens: number;
|
|
1500
|
+
totalRequests: number;
|
|
1501
|
+
}
|
|
1502
|
+
interface CostEntry {
|
|
1503
|
+
timestamp: number;
|
|
1504
|
+
model: string;
|
|
1505
|
+
inputTokens: number;
|
|
1506
|
+
outputTokens: number;
|
|
1507
|
+
cacheReadTokens: number;
|
|
1508
|
+
cacheCreationTokens: number;
|
|
1509
|
+
cost: number;
|
|
1510
|
+
}
|
|
1511
|
+
interface CostConfig {
|
|
1512
|
+
prices: Record<string, {
|
|
1513
|
+
input: number;
|
|
1514
|
+
output: number;
|
|
1515
|
+
cacheRead: number;
|
|
1516
|
+
cacheWrite: number;
|
|
1517
|
+
}>;
|
|
1518
|
+
budgetLimit?: number;
|
|
1519
|
+
}
|
|
1520
|
+
declare class CostTracker {
|
|
1521
|
+
private entries;
|
|
1522
|
+
private config;
|
|
1523
|
+
private sessionStart;
|
|
1524
|
+
constructor(config?: Partial<CostConfig>);
|
|
1525
|
+
/** Record token usage for a model */
|
|
1526
|
+
recordUsage(model: string, usage: Omit<ModelUsage, 'model' | 'totalRequests'>): CostEntry;
|
|
1527
|
+
/** Get total session cost in USD */
|
|
1528
|
+
getSessionTotal(): number;
|
|
1529
|
+
/** Get aggregated usage by model */
|
|
1530
|
+
getSessionUsage(): ModelUsage[];
|
|
1531
|
+
/** Get all recorded entries */
|
|
1532
|
+
getEntries(): CostEntry[];
|
|
1533
|
+
/** Format cost as USD string */
|
|
1534
|
+
formatCost(usd: number): string;
|
|
1535
|
+
/** Format duration from ms to human-readable */
|
|
1536
|
+
formatDuration(ms: number): string;
|
|
1537
|
+
/** Check if budget limit is exceeded */
|
|
1538
|
+
checkBudget(): {
|
|
1539
|
+
exceeded: boolean;
|
|
1540
|
+
used: number;
|
|
1541
|
+
limit?: number;
|
|
1542
|
+
percent?: number;
|
|
1543
|
+
};
|
|
1544
|
+
/** Get session duration in ms */
|
|
1545
|
+
getSessionDuration(): number;
|
|
1546
|
+
/** Reset for new session */
|
|
1547
|
+
reset(): void;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
interface TokenBudgetAnalysis {
|
|
1551
|
+
usedTokens: number;
|
|
1552
|
+
maxTokens: number;
|
|
1553
|
+
remainingTokens: number;
|
|
1554
|
+
usagePercent: number;
|
|
1555
|
+
needsCompaction: boolean;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Estimate the number of tokens in a text string.
|
|
1559
|
+
* Uses heuristic: ~4 chars per token for English, ~2.5 for other languages.
|
|
1560
|
+
*/
|
|
1561
|
+
declare function estimateTokens(text: string): number;
|
|
1562
|
+
/**
|
|
1563
|
+
* Estimate total tokens for an array of messages.
|
|
1564
|
+
* Adds overhead per message (~4 tokens).
|
|
1565
|
+
*/
|
|
1566
|
+
declare function estimateMessagesTokens(messages: Array<{
|
|
1567
|
+
role: string;
|
|
1568
|
+
content: unknown;
|
|
1569
|
+
}>): number;
|
|
1570
|
+
/**
|
|
1571
|
+
* Analyze token budget for the current context.
|
|
1572
|
+
* Returns usage stats and whether compaction is needed.
|
|
1573
|
+
*/
|
|
1574
|
+
declare function analyzeTokenBudget(context: {
|
|
1575
|
+
messages: unknown[];
|
|
1576
|
+
systemPrompt?: string;
|
|
1577
|
+
maxTokens: number;
|
|
1578
|
+
}): TokenBudgetAnalysis;
|
|
1579
|
+
|
|
1580
|
+
interface HistoryEntry {
|
|
1581
|
+
content: string;
|
|
1582
|
+
timestamp: number;
|
|
1583
|
+
type: 'user' | 'paste';
|
|
1584
|
+
}
|
|
1585
|
+
interface HistoryConfig {
|
|
1586
|
+
maxEntries: number;
|
|
1587
|
+
filePath: string;
|
|
1588
|
+
}
|
|
1589
|
+
declare class HistoryManager {
|
|
1590
|
+
private entries;
|
|
1591
|
+
private config;
|
|
1592
|
+
private cursorIndex;
|
|
1593
|
+
constructor(config?: Partial<HistoryConfig>);
|
|
1594
|
+
addEntry(content: string, type?: 'user' | 'paste'): void;
|
|
1595
|
+
getEntries(): HistoryEntry[];
|
|
1596
|
+
search(query: string): HistoryEntry[];
|
|
1597
|
+
getRecent(count: number): HistoryEntry[];
|
|
1598
|
+
clear(): void;
|
|
1599
|
+
navigateUp(): string | null;
|
|
1600
|
+
navigateDown(): string | null;
|
|
1601
|
+
save(): Promise<void>;
|
|
1602
|
+
load(): Promise<void>;
|
|
1603
|
+
private resolvePath;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
/**
|
|
1607
|
+
* Streaming Tool Executor — executes tools concurrently based on safety classification.
|
|
1608
|
+
* Adapted from Claude's StreamingToolExecutor.ts.
|
|
1609
|
+
*
|
|
1610
|
+
* - Concurrency-safe tools (readOnly) can run in parallel with each other
|
|
1611
|
+
* - Non-safe tools (bash, file_write, etc.) must run exclusively
|
|
1612
|
+
* - If a Bash tool errors, sibling tools are cancelled
|
|
1613
|
+
* - Results are collected in the order tools were queued
|
|
1614
|
+
*/
|
|
1615
|
+
|
|
1616
|
+
interface ToolCallRequest {
|
|
1617
|
+
id: string;
|
|
1618
|
+
name: string;
|
|
1619
|
+
input: Record<string, unknown>;
|
|
1620
|
+
concurrencySafe: boolean;
|
|
1621
|
+
}
|
|
1622
|
+
interface ToolCallResult {
|
|
1623
|
+
id: string;
|
|
1624
|
+
output: string;
|
|
1625
|
+
isError: boolean;
|
|
1626
|
+
duration: number;
|
|
1627
|
+
}
|
|
1628
|
+
interface ExecutorConfig {
|
|
1629
|
+
abortOnError?: boolean;
|
|
1630
|
+
}
|
|
1631
|
+
interface ExecutorResult {
|
|
1632
|
+
toolResult: ToolResultBlock;
|
|
1633
|
+
event: Extract<LoopEvent, {
|
|
1634
|
+
type: 'tool_result';
|
|
1635
|
+
}>;
|
|
1636
|
+
}
|
|
1637
|
+
type ToolExecutionFn = (toolCall: {
|
|
1638
|
+
id: string;
|
|
1639
|
+
name: string;
|
|
1640
|
+
input: Record<string, unknown>;
|
|
1641
|
+
}, toolRegistry: ToolRegistry, toolContext: ToolExecutionContext, autoMode: AutoModeManager, onPermissionRequest: (operation: string, details?: string) => Promise<boolean>) => Promise<ExecutorResult>;
|
|
1642
|
+
/**
|
|
1643
|
+
* Executes tools with concurrency control.
|
|
1644
|
+
*
|
|
1645
|
+
* Two usage patterns:
|
|
1646
|
+
* 1. **Streaming (loop.ts)**: Create with full constructor, addTool(), getRemainingResults()
|
|
1647
|
+
* 2. **Batch (query-engine.ts)**: Create with (tools, config), call executeTools()
|
|
1648
|
+
*/
|
|
1649
|
+
declare class StreamingToolExecutor {
|
|
1650
|
+
private tools;
|
|
1651
|
+
private hasBashError;
|
|
1652
|
+
private bashErrorDescription;
|
|
1653
|
+
private siblingAbortController;
|
|
1654
|
+
private discarded;
|
|
1655
|
+
private readonly toolRegistry;
|
|
1656
|
+
private readonly executorConfig;
|
|
1657
|
+
private readonly toolContext?;
|
|
1658
|
+
private readonly autoMode?;
|
|
1659
|
+
private readonly onPermissionRequest?;
|
|
1660
|
+
private readonly executeFn?;
|
|
1661
|
+
/**
|
|
1662
|
+
* Constructor supports two patterns:
|
|
1663
|
+
* 1. Batch mode: new StreamingToolExecutor(tools, config?)
|
|
1664
|
+
* 2. Streaming mode: new StreamingToolExecutor(tools, context, autoMode, permFn, execFn)
|
|
1665
|
+
*/
|
|
1666
|
+
constructor(tools: ToolRegistry, configOrContext?: ExecutorConfig | ToolExecutionContext, autoMode?: AutoModeManager, onPermissionRequest?: (operation: string, details?: string) => Promise<boolean>, executeFn?: ToolExecutionFn);
|
|
1667
|
+
/** Discard all pending/in-progress tools */
|
|
1668
|
+
discard(): void;
|
|
1669
|
+
/** Add a tool to the execution queue. Starts immediately if conditions allow. */
|
|
1670
|
+
addTool(toolCall: {
|
|
1671
|
+
id: string;
|
|
1672
|
+
name: string;
|
|
1673
|
+
input: Record<string, unknown>;
|
|
1674
|
+
}): void;
|
|
1675
|
+
/** Get completed results in queue order (non-blocking) */
|
|
1676
|
+
getCompletedResults(): Generator<ExecutorResult, void>;
|
|
1677
|
+
/** Wait for all remaining tools and yield results as they complete */
|
|
1678
|
+
getRemainingResults(): AsyncGenerator<ExecutorResult, void>;
|
|
1679
|
+
/** Execute a batch of tool calls and return all results */
|
|
1680
|
+
executeTools(requests: ToolCallRequest[], context: ToolExecutionContext): Promise<ToolCallResult[]>;
|
|
1681
|
+
/** Cancel all running tools (backward-compatible alias for discard()) */
|
|
1682
|
+
cancelAll(): void;
|
|
1683
|
+
/** Get count of currently executing tools */
|
|
1684
|
+
getActiveCount(): number;
|
|
1685
|
+
private reset;
|
|
1686
|
+
private canExecuteTool;
|
|
1687
|
+
private processQueue;
|
|
1688
|
+
private executeTool;
|
|
1689
|
+
private createSyntheticError;
|
|
1690
|
+
private hasCompletedResults;
|
|
1691
|
+
private hasExecutingTools;
|
|
1692
|
+
private hasUnfinishedTools;
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
interface CompactionConfig {
|
|
1696
|
+
maxTokens: number;
|
|
1697
|
+
compactionThreshold: number;
|
|
1698
|
+
keepRecentMessages: number;
|
|
1699
|
+
}
|
|
1700
|
+
interface CompactionResult {
|
|
1701
|
+
originalTokenCount: number;
|
|
1702
|
+
compactedTokenCount: number;
|
|
1703
|
+
summary: string;
|
|
1704
|
+
removedMessages: number;
|
|
1705
|
+
keptMessages: number;
|
|
1706
|
+
}
|
|
1707
|
+
interface MessageForCompaction {
|
|
1708
|
+
role: 'user' | 'assistant';
|
|
1709
|
+
content: string;
|
|
1710
|
+
timestamp?: number;
|
|
1711
|
+
}
|
|
1712
|
+
declare class ContextCompactor {
|
|
1713
|
+
private config;
|
|
1714
|
+
private adapter;
|
|
1715
|
+
constructor(config: CompactionConfig, adapter?: ProviderAdapter | null);
|
|
1716
|
+
shouldCompact(messages: MessageForCompaction[]): boolean;
|
|
1717
|
+
compact(messages: MessageForCompaction[], systemPrompt?: string): Promise<CompactionResult>;
|
|
1718
|
+
private generateSummary;
|
|
1719
|
+
private truncateMessages;
|
|
1720
|
+
private estimateMessagesTokens;
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
type HookEvent = 'pre_tool_use' | 'post_tool_use' | 'pre_query' | 'post_query' | 'on_error' | 'on_stop';
|
|
1724
|
+
interface HookCondition {
|
|
1725
|
+
tool_name?: string;
|
|
1726
|
+
pattern?: string;
|
|
1727
|
+
}
|
|
1728
|
+
interface HookDefinition {
|
|
1729
|
+
id: string;
|
|
1730
|
+
event: HookEvent;
|
|
1731
|
+
type: 'command' | 'function';
|
|
1732
|
+
command?: string;
|
|
1733
|
+
handler?: string;
|
|
1734
|
+
condition?: HookCondition;
|
|
1735
|
+
timeout: number;
|
|
1736
|
+
enabled: boolean;
|
|
1737
|
+
}
|
|
1738
|
+
interface HookResult {
|
|
1739
|
+
hookId: string;
|
|
1740
|
+
success: boolean;
|
|
1741
|
+
output?: string;
|
|
1742
|
+
error?: string;
|
|
1743
|
+
duration: number;
|
|
1744
|
+
}
|
|
1745
|
+
interface HookContext {
|
|
1746
|
+
event: HookEvent;
|
|
1747
|
+
toolName?: string;
|
|
1748
|
+
toolInput?: unknown;
|
|
1749
|
+
toolOutput?: string;
|
|
1750
|
+
error?: Error;
|
|
1751
|
+
workingDirectory: string;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
declare class HookRegistry {
|
|
1755
|
+
private hooks;
|
|
1756
|
+
register(hook: HookDefinition): void;
|
|
1757
|
+
unregister(id: string): void;
|
|
1758
|
+
getHooksForEvent(event: HookEvent): HookDefinition[];
|
|
1759
|
+
getAll(): HookDefinition[];
|
|
1760
|
+
loadFromConfig(config: unknown): void;
|
|
1761
|
+
clear(): void;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
declare class HookExecutor {
|
|
1765
|
+
private registry;
|
|
1766
|
+
constructor(registry: HookRegistry);
|
|
1767
|
+
executeHooks(event: HookContext['event'], context: HookContext): Promise<HookResult[]>;
|
|
1768
|
+
private matchesCondition;
|
|
1769
|
+
private executeOne;
|
|
1770
|
+
private executeCommand;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
interface ParsedCommand {
|
|
1774
|
+
command: string;
|
|
1775
|
+
args: string[];
|
|
1776
|
+
operators: string[];
|
|
1777
|
+
subCommands: ParsedCommand[];
|
|
1778
|
+
redirections: Redirection[];
|
|
1779
|
+
envVars: Record<string, string>;
|
|
1780
|
+
isBackground: boolean;
|
|
1781
|
+
isSubshell: boolean;
|
|
1782
|
+
}
|
|
1783
|
+
interface Redirection {
|
|
1784
|
+
type: '>' | '>>' | '<' | '2>' | '2>>' | '&>' | '|';
|
|
1785
|
+
target: string;
|
|
1786
|
+
}
|
|
1787
|
+
interface CommandAnalysis {
|
|
1788
|
+
commands: string[];
|
|
1789
|
+
isPipe: boolean;
|
|
1790
|
+
isChained: boolean;
|
|
1791
|
+
hasRedirection: boolean;
|
|
1792
|
+
hasSubshell: boolean;
|
|
1793
|
+
isBackground: boolean;
|
|
1794
|
+
envVarCount: number;
|
|
1795
|
+
estimatedRisk: 'safe' | 'moderate' | 'dangerous';
|
|
1796
|
+
}
|
|
1797
|
+
declare function parseCommand(input: string): ParsedCommand;
|
|
1798
|
+
declare function analyzeCommand(input: string): CommandAnalysis;
|
|
1799
|
+
|
|
1800
|
+
interface MCPServerConfig {
|
|
1801
|
+
name: string;
|
|
1802
|
+
command: string;
|
|
1803
|
+
args: string[];
|
|
1804
|
+
env?: Record<string, string>;
|
|
1805
|
+
transport: 'stdio';
|
|
1806
|
+
}
|
|
1807
|
+
interface MCPTool {
|
|
1808
|
+
name: string;
|
|
1809
|
+
description: string;
|
|
1810
|
+
inputSchema: Record<string, unknown>;
|
|
1811
|
+
}
|
|
1812
|
+
interface MCPResource {
|
|
1813
|
+
uri: string;
|
|
1814
|
+
name: string;
|
|
1815
|
+
description?: string;
|
|
1816
|
+
mimeType?: string;
|
|
1817
|
+
}
|
|
1818
|
+
interface MCPPrompt {
|
|
1819
|
+
name: string;
|
|
1820
|
+
description?: string;
|
|
1821
|
+
arguments?: Array<{
|
|
1822
|
+
name: string;
|
|
1823
|
+
description?: string;
|
|
1824
|
+
required?: boolean;
|
|
1825
|
+
}>;
|
|
1826
|
+
}
|
|
1827
|
+
interface JSONRPCRequest {
|
|
1828
|
+
jsonrpc: '2.0';
|
|
1829
|
+
id: number;
|
|
1830
|
+
method: string;
|
|
1831
|
+
params?: Record<string, unknown>;
|
|
1832
|
+
}
|
|
1833
|
+
interface JSONRPCResponse {
|
|
1834
|
+
jsonrpc: '2.0';
|
|
1835
|
+
id: number;
|
|
1836
|
+
result?: unknown;
|
|
1837
|
+
error?: {
|
|
1838
|
+
code: number;
|
|
1839
|
+
message: string;
|
|
1840
|
+
data?: unknown;
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
declare class MCPClient {
|
|
1845
|
+
private config;
|
|
1846
|
+
private process;
|
|
1847
|
+
private rl;
|
|
1848
|
+
private connected;
|
|
1849
|
+
private nextId;
|
|
1850
|
+
private pendingRequests;
|
|
1851
|
+
private buffer;
|
|
1852
|
+
constructor(config: MCPServerConfig);
|
|
1853
|
+
connect(): Promise<void>;
|
|
1854
|
+
disconnect(): Promise<void>;
|
|
1855
|
+
listTools(): Promise<MCPTool[]>;
|
|
1856
|
+
callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
1857
|
+
listResources(): Promise<MCPResource[]>;
|
|
1858
|
+
readResource(uri: string): Promise<unknown>;
|
|
1859
|
+
listPrompts(): Promise<MCPPrompt[]>;
|
|
1860
|
+
isConnected(): boolean;
|
|
1861
|
+
private sendRequest;
|
|
1862
|
+
private sendNotification;
|
|
1863
|
+
private handleLine;
|
|
1864
|
+
private cleanup;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
declare class MCPConnectionManager {
|
|
1868
|
+
private clients;
|
|
1869
|
+
addServer(config: MCPServerConfig): Promise<void>;
|
|
1870
|
+
removeServer(name: string): Promise<void>;
|
|
1871
|
+
getConnectedServers(): string[];
|
|
1872
|
+
getAllTools(): Promise<MCPTool[]>;
|
|
1873
|
+
callTool(serverName: string, toolName: string, args: Record<string, unknown>): Promise<unknown>;
|
|
1874
|
+
getToolsForServer(serverName: string): Promise<MCPTool[]>;
|
|
1875
|
+
disconnectAll(): Promise<void>;
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
type TaskStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
1879
|
+
interface TaskDefinition {
|
|
1880
|
+
id: string;
|
|
1881
|
+
name: string;
|
|
1882
|
+
description: string;
|
|
1883
|
+
type: 'agent' | 'shell' | 'custom';
|
|
1884
|
+
status: TaskStatus;
|
|
1885
|
+
createdAt: number;
|
|
1886
|
+
startedAt?: number;
|
|
1887
|
+
completedAt?: number;
|
|
1888
|
+
error?: string;
|
|
1889
|
+
result?: string;
|
|
1890
|
+
progress?: number;
|
|
1891
|
+
}
|
|
1892
|
+
interface TaskEvents {
|
|
1893
|
+
onProgress: (taskId: string, progress: number, message?: string) => void;
|
|
1894
|
+
onComplete: (taskId: string, result: string) => void;
|
|
1895
|
+
onError: (taskId: string, error: string) => void;
|
|
1896
|
+
onStatusChange: (taskId: string, status: TaskStatus) => void;
|
|
1897
|
+
}
|
|
1898
|
+
type TaskEventName = keyof TaskEvents;
|
|
1899
|
+
type TaskEventHandler<E extends TaskEventName> = TaskEvents[E];
|
|
1900
|
+
|
|
1901
|
+
declare class TaskManager {
|
|
1902
|
+
private tasks;
|
|
1903
|
+
private listeners;
|
|
1904
|
+
private idCounter;
|
|
1905
|
+
createTask(definition: Omit<TaskDefinition, 'id' | 'status' | 'createdAt'>): string;
|
|
1906
|
+
cancelTask(id: string): void;
|
|
1907
|
+
getTask(id: string): TaskDefinition | undefined;
|
|
1908
|
+
listTasks(filter?: {
|
|
1909
|
+
status?: TaskStatus;
|
|
1910
|
+
}): TaskDefinition[];
|
|
1911
|
+
getActiveCount(): number;
|
|
1912
|
+
removeTask(id: string): void;
|
|
1913
|
+
clearCompleted(): void;
|
|
1914
|
+
on<E extends TaskEventName>(event: E, handler: TaskEventHandler<E>): void;
|
|
1915
|
+
off<E extends TaskEventName>(event: E, handler: TaskEventHandler<E>): void;
|
|
1916
|
+
/** @internal Update task status */
|
|
1917
|
+
updateStatus(id: string, status: TaskStatus): void;
|
|
1918
|
+
/** @internal Update task progress */
|
|
1919
|
+
updateProgress(id: string, progress: number, message?: string): void;
|
|
1920
|
+
/** @internal Set task result */
|
|
1921
|
+
setResult(id: string, result: string): void;
|
|
1922
|
+
/** @internal Set task error */
|
|
1923
|
+
setError(id: string, error: string): void;
|
|
1924
|
+
private emit;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
declare function executeAgentTask(taskId: string, manager: TaskManager, adapter: ProviderAdapter, tools: ToolRegistry, prompt: string, signal?: AbortSignal): Promise<void>;
|
|
1928
|
+
declare function executeShellTask(taskId: string, manager: TaskManager, command: string, cwd: string, signal?: AbortSignal): Promise<void>;
|
|
1929
|
+
|
|
1930
|
+
type AgentRole = 'coordinator' | 'worker' | 'reviewer';
|
|
1931
|
+
interface AgentConfig {
|
|
1932
|
+
id: string;
|
|
1933
|
+
name: string;
|
|
1934
|
+
role: AgentRole;
|
|
1935
|
+
model?: string;
|
|
1936
|
+
tools?: string[];
|
|
1937
|
+
maxTurns?: number;
|
|
1938
|
+
systemPrompt?: string;
|
|
1939
|
+
}
|
|
1940
|
+
interface SwarmMessage {
|
|
1941
|
+
from: string;
|
|
1942
|
+
to: string | '*';
|
|
1943
|
+
type: 'task' | 'result' | 'query' | 'response' | 'shutdown';
|
|
1944
|
+
content: string;
|
|
1945
|
+
timestamp: number;
|
|
1946
|
+
}
|
|
1947
|
+
interface SwarmResult {
|
|
1948
|
+
agentId: string;
|
|
1949
|
+
agentName: string;
|
|
1950
|
+
task: string;
|
|
1951
|
+
result: string;
|
|
1952
|
+
success: boolean;
|
|
1953
|
+
duration: number;
|
|
1954
|
+
turns: number;
|
|
1955
|
+
}
|
|
1956
|
+
interface SubTask {
|
|
1957
|
+
id: string;
|
|
1958
|
+
description: string;
|
|
1959
|
+
assignedTo?: string;
|
|
1960
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
1961
|
+
result?: string;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
declare class SwarmCoordinator {
|
|
1965
|
+
private adapter;
|
|
1966
|
+
private tools;
|
|
1967
|
+
private agents;
|
|
1968
|
+
private mailbox;
|
|
1969
|
+
private abortController;
|
|
1970
|
+
constructor(adapter: ProviderAdapter, tools: ToolRegistry);
|
|
1971
|
+
addAgent(config: AgentConfig): void;
|
|
1972
|
+
removeAgent(id: string): void;
|
|
1973
|
+
getAgents(): AgentConfig[];
|
|
1974
|
+
sendMessage(message: SwarmMessage): Promise<void>;
|
|
1975
|
+
executeSwarm(task: string): Promise<SwarmResult[]>;
|
|
1976
|
+
shutdown(): void;
|
|
1977
|
+
private findAgentByRole;
|
|
1978
|
+
private findAgentsByRole;
|
|
1979
|
+
private decomposeTask;
|
|
1980
|
+
private fallbackDecompose;
|
|
1981
|
+
private assignSubtasks;
|
|
1982
|
+
private executeParallel;
|
|
1983
|
+
private reviewResults;
|
|
1984
|
+
private createEngine;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
interface ChatMessage {
|
|
1988
|
+
id: string;
|
|
1989
|
+
role: 'user' | 'assistant' | 'tool' | 'error';
|
|
1990
|
+
content: string;
|
|
1991
|
+
toolName?: string;
|
|
1992
|
+
isError?: boolean;
|
|
1993
|
+
}
|
|
1994
|
+
interface StatusBarProps {
|
|
1995
|
+
model: string;
|
|
1996
|
+
inputTokens: number;
|
|
1997
|
+
outputTokens: number;
|
|
1998
|
+
sessionStart: number;
|
|
1999
|
+
toolCount: number;
|
|
2000
|
+
}
|
|
2001
|
+
type LoopEventHandler = (event: LoopEvent) => void;
|
|
2002
|
+
interface InkAppProps {
|
|
2003
|
+
model: string;
|
|
2004
|
+
toolCount: number;
|
|
2005
|
+
onSubmit: (message: string, onEvent: LoopEventHandler) => Promise<void>;
|
|
2006
|
+
}
|
|
2007
|
+
declare const StatusBar: React.NamedExoticComponent<StatusBarProps>;
|
|
2008
|
+
declare const Spinner: React.NamedExoticComponent<{
|
|
2009
|
+
label: string;
|
|
2010
|
+
}>;
|
|
2011
|
+
declare function InkApp({ model, toolCount, onSubmit }: InkAppProps): React.ReactElement;
|
|
2012
|
+
declare function renderInkApp(props: InkAppProps): void;
|
|
2013
|
+
declare function formatAnsiMessage(message: ChatMessage): string;
|
|
2014
|
+
declare function MessageList({ messages }: {
|
|
2015
|
+
messages: ChatMessage[];
|
|
2016
|
+
}): React.ReactElement;
|
|
2017
|
+
|
|
2018
|
+
export { AdapterRegistry, type AgentConfig, type AgentRole, AgentTool, type AppConfig, type ChatMessage, type CommandAnalysis, type CompactionConfig, type CompactionResult, type CompletionRequest, type CompletionResult, ContextCompactor, type CostConfig, type CostEntry, CostTracker, type EnhancedMemoryConfig, type EnhancedMemoryEntry, EnhancedMemoryStore, EnterPlanModeTool, type ExecutorConfig, ExitPlanModeTool, GenericCompatAdapter, type HistoryConfig, type HistoryEntry, HistoryManager, type HookCondition, type HookContext, type HookDefinition, type HookEvent, HookExecutor, HookRegistry, type HookResult, InkApp, type InkAppProps, type JSONRPCRequest, type JSONRPCResponse, type LoopEventHandler, LspTool, MCPClient, MCPConnectionManager, type MCPPrompt, type MCPResource, type MCPServerConfig, type MCPTool, type MemoryEntry, type MemorySearchResult, MemoryStore, type Message, type MessageForCompaction, MessageList, type ModelRouterFactory, type ModelUsage, type ParsedCommand, PermissionManager, type ProviderAdapter, type ProviderConfig, QueryEngine, type QueryEngineConfig, type QueryEvent, type QueryResult, type Redirection, type RegistryFactory, type SkillDefinition, SkillRegistry, Spinner, StatusBar, type StatusBarProps, type StreamEvent, StreamingToolExecutor, type SubTask, SwarmCoordinator, type SwarmMessage, type SwarmResult, type TaskDefinition, type TaskEventHandler, type TaskEventName, type TaskEvents, TaskManager, type TaskStatus, type TokenBudgetAnalysis, type ToolCallRequest, type ToolCallResult, type ToolContract, ToolRegistry, WebSearchTool, analyzeCommand, analyzeTokenBudget, createDefaultToolRegistry, estimateMessagesTokens, estimateTokens, executeAgentTask, executeShellTask, formatAnsiMessage, inspectCommand, parseCommand, renderInkApp, runAgentLoop };
|