@defai.digital/ax-cli 2.7.0 → 2.8.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/.ax-cli/checkpoints/2025-11-20/checkpoint-2dd84869-e62d-46c8-9885-7e45f37f36e2.json +69 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-484dc350-353f-4808-9ed1-ebb3cefdab37.json +24 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-74a18b87-6172-4215-962b-44bb9f46a662.json +69 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-870a5fb9-6e82-4ff2-8ec8-af4c251cc514.json +44 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-93946601-0e83-456c-ba47-def9713124dd.json +24 -0
- package/.ax-cli/checkpoints/metadata.json +62 -0
- package/README.md +2 -2
- package/dist/agent/context-manager.d.ts +2 -2
- package/dist/agent/context-manager.js +28 -15
- package/dist/agent/context-manager.js.map +1 -1
- package/dist/agent/dependency-resolver.d.ts +83 -0
- package/dist/agent/dependency-resolver.js +302 -0
- package/dist/agent/dependency-resolver.js.map +1 -0
- package/dist/agent/llm-agent.d.ts +63 -0
- package/dist/agent/llm-agent.js +250 -0
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/agent/specialized/analysis-agent.d.ts +11 -0
- package/dist/agent/specialized/analysis-agent.js +33 -0
- package/dist/agent/specialized/analysis-agent.js.map +1 -0
- package/dist/agent/specialized/debug-agent.d.ts +11 -0
- package/dist/agent/specialized/debug-agent.js +33 -0
- package/dist/agent/specialized/debug-agent.js.map +1 -0
- package/dist/agent/specialized/documentation-agent.d.ts +11 -0
- package/dist/agent/specialized/documentation-agent.js +33 -0
- package/dist/agent/specialized/documentation-agent.js.map +1 -0
- package/dist/agent/specialized/index.d.ts +11 -0
- package/dist/agent/specialized/index.js +12 -0
- package/dist/agent/specialized/index.js.map +1 -0
- package/dist/agent/specialized/performance-agent.d.ts +11 -0
- package/dist/agent/specialized/performance-agent.js +33 -0
- package/dist/agent/specialized/performance-agent.js.map +1 -0
- package/dist/agent/specialized/refactoring-agent.d.ts +11 -0
- package/dist/agent/specialized/refactoring-agent.js +33 -0
- package/dist/agent/specialized/refactoring-agent.js.map +1 -0
- package/dist/agent/specialized/testing-agent.d.ts +11 -0
- package/dist/agent/specialized/testing-agent.js +33 -0
- package/dist/agent/specialized/testing-agent.js.map +1 -0
- package/dist/agent/subagent-orchestrator.d.ts +124 -0
- package/dist/agent/subagent-orchestrator.js +345 -0
- package/dist/agent/subagent-orchestrator.js.map +1 -0
- package/dist/agent/subagent-types.d.ts +262 -0
- package/dist/agent/subagent-types.js +152 -0
- package/dist/agent/subagent-types.js.map +1 -0
- package/dist/agent/subagent.d.ts +88 -0
- package/dist/agent/subagent.js +402 -0
- package/dist/agent/subagent.js.map +1 -0
- package/dist/checkpoint/index.d.ts +9 -0
- package/dist/checkpoint/index.js +11 -0
- package/dist/checkpoint/index.js.map +1 -0
- package/dist/checkpoint/manager.d.ts +99 -0
- package/dist/checkpoint/manager.js +281 -0
- package/dist/checkpoint/manager.js.map +1 -0
- package/dist/checkpoint/storage.d.ts +31 -0
- package/dist/checkpoint/storage.js +265 -0
- package/dist/checkpoint/storage.js.map +1 -0
- package/dist/checkpoint/types.d.ts +111 -0
- package/dist/checkpoint/types.js +17 -0
- package/dist/checkpoint/types.js.map +1 -0
- package/dist/commands/rewind.d.ts +19 -0
- package/dist/commands/rewind.js +221 -0
- package/dist/commands/rewind.js.map +1 -0
- package/dist/hooks/use-input-handler.js +24 -0
- package/dist/hooks/use-input-handler.js.map +1 -1
- package/dist/llm/client.js +2 -1
- package/dist/llm/client.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -0
- package/dist/mcp/client.js +27 -12
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/transports.d.ts +0 -1
- package/dist/mcp/transports.js +10 -7
- package/dist/mcp/transports.js.map +1 -1
- package/dist/schemas/api-schemas.js +4 -0
- package/dist/schemas/api-schemas.js.map +1 -1
- package/dist/tools/bash.js +26 -1
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/search.js +21 -9
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/text-editor.d.ts +16 -0
- package/dist/tools/text-editor.js +33 -0
- package/dist/tools/text-editor.js.map +1 -1
- package/dist/ui/components/chat-interface.js +3 -2
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/subagent-monitor.d.ts +29 -0
- package/dist/ui/components/subagent-monitor.js +150 -0
- package/dist/ui/components/subagent-monitor.js.map +1 -0
- package/dist/utils/history-manager.d.ts +1 -0
- package/dist/utils/history-manager.js +40 -5
- package/dist/utils/history-manager.js.map +1 -1
- package/dist/utils/json-utils.d.ts +7 -0
- package/dist/utils/json-utils.js +70 -2
- package/dist/utils/json-utils.js.map +1 -1
- package/dist/utils/settings-manager.js +12 -10
- package/dist/utils/settings-manager.js.map +1 -1
- package/dist/utils/text-utils.js +3 -3
- package/dist/utils/text-utils.js.map +1 -1
- package/dist/utils/token-counter.d.ts +5 -0
- package/dist/utils/token-counter.js +18 -3
- package/dist/utils/token-counter.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subagent Base Class
|
|
3
|
+
*
|
|
4
|
+
* Base class for all specialized subagents. Subagents are lightweight AI agents
|
|
5
|
+
* that focus on specific tasks (testing, documentation, refactoring, etc.) with
|
|
6
|
+
* limited tool access and shallow conversation history.
|
|
7
|
+
*/
|
|
8
|
+
import { EventEmitter } from 'events';
|
|
9
|
+
import { LLMClient } from '../llm/client.js';
|
|
10
|
+
import { SubagentRole, SubagentState } from './subagent-types.js';
|
|
11
|
+
// Import tools
|
|
12
|
+
import { BashTool } from '../tools/bash.js';
|
|
13
|
+
import { TextEditorTool } from '../tools/text-editor.js';
|
|
14
|
+
import { SearchTool } from '../tools/search.js';
|
|
15
|
+
/**
|
|
16
|
+
* Base Subagent class
|
|
17
|
+
*/
|
|
18
|
+
export class Subagent extends EventEmitter {
|
|
19
|
+
id;
|
|
20
|
+
role;
|
|
21
|
+
config;
|
|
22
|
+
llmClient;
|
|
23
|
+
chatHistory;
|
|
24
|
+
messages;
|
|
25
|
+
tools;
|
|
26
|
+
isActive;
|
|
27
|
+
currentTaskId;
|
|
28
|
+
status;
|
|
29
|
+
constructor(role, configOverrides) {
|
|
30
|
+
super();
|
|
31
|
+
this.id = `${role}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
32
|
+
this.role = role;
|
|
33
|
+
// Merge with default config for this role
|
|
34
|
+
const defaultConfig = this.getDefaultConfig(role);
|
|
35
|
+
this.config = { ...defaultConfig, ...configOverrides, role };
|
|
36
|
+
this.chatHistory = [];
|
|
37
|
+
this.messages = [];
|
|
38
|
+
this.tools = new Map();
|
|
39
|
+
this.isActive = false;
|
|
40
|
+
this.currentTaskId = null;
|
|
41
|
+
// Initialize status
|
|
42
|
+
this.status = {
|
|
43
|
+
id: this.id,
|
|
44
|
+
taskId: '',
|
|
45
|
+
role: this.role,
|
|
46
|
+
state: SubagentState.PENDING,
|
|
47
|
+
progress: 0,
|
|
48
|
+
startTime: new Date(),
|
|
49
|
+
};
|
|
50
|
+
// Initialize LLM client with same settings as main agent
|
|
51
|
+
this.llmClient = new LLMClient(process.env.YOUR_API_KEY || '', process.env.GROK_MODEL || 'glm-4.6', process.env.GROK_BASE_URL);
|
|
52
|
+
// Initialize allowed tools
|
|
53
|
+
this.initializeTools();
|
|
54
|
+
// Set system prompt
|
|
55
|
+
this.messages.push({
|
|
56
|
+
role: 'system',
|
|
57
|
+
content: this.buildSystemPrompt(),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get default configuration for a role
|
|
62
|
+
*/
|
|
63
|
+
getDefaultConfig(role) {
|
|
64
|
+
// Default tools and settings based on role
|
|
65
|
+
const roleDefaults = {
|
|
66
|
+
[SubagentRole.GENERAL]: {
|
|
67
|
+
allowedTools: ['bash', 'text_editor', 'search'],
|
|
68
|
+
maxToolRounds: 30,
|
|
69
|
+
contextDepth: 20,
|
|
70
|
+
priority: 1,
|
|
71
|
+
},
|
|
72
|
+
[SubagentRole.TESTING]: {
|
|
73
|
+
allowedTools: ['bash', 'text_editor', 'search'],
|
|
74
|
+
maxToolRounds: 20,
|
|
75
|
+
contextDepth: 10,
|
|
76
|
+
priority: 2,
|
|
77
|
+
},
|
|
78
|
+
[SubagentRole.DOCUMENTATION]: {
|
|
79
|
+
allowedTools: ['text_editor', 'search'],
|
|
80
|
+
maxToolRounds: 15,
|
|
81
|
+
contextDepth: 20,
|
|
82
|
+
priority: 1,
|
|
83
|
+
},
|
|
84
|
+
[SubagentRole.REFACTORING]: {
|
|
85
|
+
allowedTools: ['bash', 'text_editor', 'search'],
|
|
86
|
+
maxToolRounds: 25,
|
|
87
|
+
contextDepth: 20,
|
|
88
|
+
priority: 2,
|
|
89
|
+
},
|
|
90
|
+
[SubagentRole.ANALYSIS]: {
|
|
91
|
+
allowedTools: ['bash', 'text_editor', 'search'],
|
|
92
|
+
maxToolRounds: 15,
|
|
93
|
+
contextDepth: 15,
|
|
94
|
+
priority: 3,
|
|
95
|
+
},
|
|
96
|
+
[SubagentRole.DEBUG]: {
|
|
97
|
+
allowedTools: ['bash', 'text_editor', 'search'],
|
|
98
|
+
maxToolRounds: 30,
|
|
99
|
+
contextDepth: 15,
|
|
100
|
+
priority: 3,
|
|
101
|
+
},
|
|
102
|
+
[SubagentRole.PERFORMANCE]: {
|
|
103
|
+
allowedTools: ['bash', 'search'],
|
|
104
|
+
maxToolRounds: 25,
|
|
105
|
+
contextDepth: 10,
|
|
106
|
+
priority: 2,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
role,
|
|
111
|
+
allowedTools: [],
|
|
112
|
+
maxToolRounds: 20,
|
|
113
|
+
contextDepth: 10,
|
|
114
|
+
priority: 1,
|
|
115
|
+
...roleDefaults[role],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Initialize tools based on allowed tools in config
|
|
120
|
+
*/
|
|
121
|
+
initializeTools() {
|
|
122
|
+
const allowedTools = this.config.allowedTools;
|
|
123
|
+
if (allowedTools.includes('bash')) {
|
|
124
|
+
this.tools.set('bash', new BashTool());
|
|
125
|
+
}
|
|
126
|
+
if (allowedTools.includes('text_editor')) {
|
|
127
|
+
// TextEditorTool doesn't need parameters
|
|
128
|
+
this.tools.set('text_editor', new TextEditorTool());
|
|
129
|
+
}
|
|
130
|
+
if (allowedTools.includes('search')) {
|
|
131
|
+
this.tools.set('search', new SearchTool());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Build system prompt for this subagent role
|
|
136
|
+
* Override in specialized subagent classes
|
|
137
|
+
*/
|
|
138
|
+
buildSystemPrompt() {
|
|
139
|
+
return this.config.customSystemPrompt || `You are a specialized ${this.role} agent.`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Execute a task
|
|
143
|
+
*/
|
|
144
|
+
async executeTask(task) {
|
|
145
|
+
this.isActive = true;
|
|
146
|
+
this.currentTaskId = task.id;
|
|
147
|
+
const startTime = Date.now();
|
|
148
|
+
// Update status
|
|
149
|
+
this.status = {
|
|
150
|
+
id: this.id,
|
|
151
|
+
taskId: task.id,
|
|
152
|
+
role: this.role,
|
|
153
|
+
state: SubagentState.RUNNING,
|
|
154
|
+
progress: 0,
|
|
155
|
+
startTime: new Date(),
|
|
156
|
+
toolsUsed: [],
|
|
157
|
+
toolRoundsUsed: 0,
|
|
158
|
+
};
|
|
159
|
+
const result = {
|
|
160
|
+
id: this.id,
|
|
161
|
+
taskId: task.id,
|
|
162
|
+
role: this.role,
|
|
163
|
+
success: false,
|
|
164
|
+
output: '',
|
|
165
|
+
executionTime: 0,
|
|
166
|
+
status: this.status,
|
|
167
|
+
filesModified: [],
|
|
168
|
+
filesCreated: [],
|
|
169
|
+
toolCalls: [],
|
|
170
|
+
};
|
|
171
|
+
try {
|
|
172
|
+
// Emit both 'start' and 'task-started' for compatibility
|
|
173
|
+
this.emit('start', { taskId: task.id, role: this.role });
|
|
174
|
+
this.emit('task-started', { taskId: task.id, role: this.role });
|
|
175
|
+
// Add task context to messages
|
|
176
|
+
const contextPrompt = this.buildContextPrompt(task);
|
|
177
|
+
this.messages.push({
|
|
178
|
+
role: 'user',
|
|
179
|
+
content: contextPrompt,
|
|
180
|
+
});
|
|
181
|
+
// Add to chat history
|
|
182
|
+
this.chatHistory.push({
|
|
183
|
+
type: 'user',
|
|
184
|
+
content: contextPrompt,
|
|
185
|
+
timestamp: new Date(),
|
|
186
|
+
});
|
|
187
|
+
// Execute with tool rounds limit
|
|
188
|
+
let toolRounds = 0;
|
|
189
|
+
let isComplete = false;
|
|
190
|
+
while (toolRounds < this.config.maxToolRounds && !isComplete) {
|
|
191
|
+
const response = await this.llmClient.chat(this.messages, this.getToolDefinitions(), { stream: false });
|
|
192
|
+
if (!response.choices || response.choices.length === 0) {
|
|
193
|
+
throw new Error('No response from LLM');
|
|
194
|
+
}
|
|
195
|
+
const choice = response.choices[0];
|
|
196
|
+
const message = choice.message;
|
|
197
|
+
// Handle content
|
|
198
|
+
if (message.content) {
|
|
199
|
+
this.chatHistory.push({
|
|
200
|
+
type: 'assistant',
|
|
201
|
+
content: message.content,
|
|
202
|
+
timestamp: new Date(),
|
|
203
|
+
});
|
|
204
|
+
result.output = message.content;
|
|
205
|
+
this.emit('progress', {
|
|
206
|
+
taskId: task.id,
|
|
207
|
+
content: message.content,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// Handle tool calls
|
|
211
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
212
|
+
this.messages.push({
|
|
213
|
+
role: 'assistant',
|
|
214
|
+
content: message.content || '',
|
|
215
|
+
tool_calls: message.tool_calls,
|
|
216
|
+
});
|
|
217
|
+
for (const toolCall of message.tool_calls) {
|
|
218
|
+
const toolResult = await this.executeToolCall(toolCall);
|
|
219
|
+
// Track tool usage in status
|
|
220
|
+
if (!this.status.toolsUsed.includes(toolCall.function.name)) {
|
|
221
|
+
this.status.toolsUsed.push(toolCall.function.name);
|
|
222
|
+
}
|
|
223
|
+
// Track tool calls
|
|
224
|
+
if (!result.toolCalls) {
|
|
225
|
+
result.toolCalls = [];
|
|
226
|
+
}
|
|
227
|
+
result.toolCalls.push(toolCall);
|
|
228
|
+
// Track files created/modified
|
|
229
|
+
if (toolCall.function.name === 'text_editor' && toolResult.success) {
|
|
230
|
+
const args = JSON.parse(toolCall.function.arguments);
|
|
231
|
+
if (args.path) {
|
|
232
|
+
if (args.command === 'create') {
|
|
233
|
+
if (!result.filesCreated.includes(args.path)) {
|
|
234
|
+
result.filesCreated.push(args.path);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
if (!result.filesModified.includes(args.path)) {
|
|
239
|
+
result.filesModified.push(args.path);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// Add tool result to messages
|
|
245
|
+
this.messages.push({
|
|
246
|
+
role: 'tool',
|
|
247
|
+
tool_call_id: toolCall.id,
|
|
248
|
+
content: toolResult.output || toolResult.error || '',
|
|
249
|
+
});
|
|
250
|
+
this.chatHistory.push({
|
|
251
|
+
type: 'tool_result',
|
|
252
|
+
content: toolResult.output || toolResult.error || '',
|
|
253
|
+
timestamp: new Date(),
|
|
254
|
+
toolCall: toolCall,
|
|
255
|
+
toolResult: toolResult,
|
|
256
|
+
});
|
|
257
|
+
this.emit('tool-executed', {
|
|
258
|
+
taskId: task.id,
|
|
259
|
+
toolName: toolCall.function.name,
|
|
260
|
+
result: toolResult,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
toolRounds++;
|
|
264
|
+
this.status.toolRoundsUsed = toolRounds;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
// No more tool calls, task complete
|
|
268
|
+
isComplete = true;
|
|
269
|
+
}
|
|
270
|
+
// Check timeout
|
|
271
|
+
const elapsed = Date.now() - startTime;
|
|
272
|
+
if (this.config.timeout && elapsed > this.config.timeout) {
|
|
273
|
+
throw new Error(`Task timeout after ${elapsed}ms`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
result.success = true;
|
|
277
|
+
result.executionTime = Date.now() - startTime;
|
|
278
|
+
this.status.state = SubagentState.COMPLETED;
|
|
279
|
+
this.status.endTime = new Date();
|
|
280
|
+
this.status.progress = 100;
|
|
281
|
+
result.status = { ...this.status };
|
|
282
|
+
this.emit('task-completed', { taskId: task.id, result });
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
result.success = false;
|
|
286
|
+
result.error = error.message;
|
|
287
|
+
result.executionTime = Date.now() - startTime;
|
|
288
|
+
this.status.state = SubagentState.FAILED;
|
|
289
|
+
this.status.endTime = new Date();
|
|
290
|
+
this.status.error = error.message;
|
|
291
|
+
result.status = { ...this.status };
|
|
292
|
+
this.emit('task-failed', { taskId: task.id, error: error.message });
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
this.isActive = false;
|
|
296
|
+
this.currentTaskId = null;
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Build context prompt from task
|
|
302
|
+
*/
|
|
303
|
+
buildContextPrompt(task) {
|
|
304
|
+
let prompt = `Task: ${task.description}\n\n`;
|
|
305
|
+
if (task.context) {
|
|
306
|
+
prompt += `Context:\n`;
|
|
307
|
+
if (task.context.metadata?.workingDirectory) {
|
|
308
|
+
prompt += `- Working Directory: ${task.context.metadata.workingDirectory}\n`;
|
|
309
|
+
}
|
|
310
|
+
if (task.context.conversationHistory && task.context.conversationHistory.length > 0) {
|
|
311
|
+
prompt += `\nRecent conversation:\n`;
|
|
312
|
+
task.context.conversationHistory.slice(-5).forEach((entry) => {
|
|
313
|
+
prompt += `${entry.type}: ${entry.content.substring(0, 200)}\n`;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return prompt;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Execute a tool call
|
|
321
|
+
*/
|
|
322
|
+
async executeToolCall(toolCall) {
|
|
323
|
+
const toolName = toolCall.function.name;
|
|
324
|
+
const tool = this.tools.get(toolName);
|
|
325
|
+
if (!tool) {
|
|
326
|
+
return {
|
|
327
|
+
success: false,
|
|
328
|
+
error: `Tool '${toolName}' not available for ${this.role} agent`,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
const args = JSON.parse(toolCall.function.arguments);
|
|
333
|
+
const result = await tool.execute(args);
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
return {
|
|
338
|
+
success: false,
|
|
339
|
+
error: `Tool execution error: ${error.message}`,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Get tool definitions for LLM
|
|
345
|
+
*/
|
|
346
|
+
getToolDefinitions() {
|
|
347
|
+
const definitions = [];
|
|
348
|
+
for (const [, tool] of this.tools) {
|
|
349
|
+
if (typeof tool.getToolDefinition === 'function') {
|
|
350
|
+
definitions.push(tool.getToolDefinition());
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return definitions;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get current status
|
|
357
|
+
*/
|
|
358
|
+
getStatus() {
|
|
359
|
+
return { ...this.status };
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Abort execution
|
|
363
|
+
*/
|
|
364
|
+
abort() {
|
|
365
|
+
this.isActive = false;
|
|
366
|
+
this.status.state = SubagentState.CANCELLED;
|
|
367
|
+
this.status.endTime = new Date();
|
|
368
|
+
this.emit('cancel', { role: this.role });
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Terminate subagent
|
|
372
|
+
*/
|
|
373
|
+
async terminate() {
|
|
374
|
+
this.isActive = false;
|
|
375
|
+
this.currentTaskId = null;
|
|
376
|
+
this.removeAllListeners();
|
|
377
|
+
this.emit('terminated', { role: this.role });
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Get chat history (for debugging/monitoring)
|
|
381
|
+
*/
|
|
382
|
+
getChatHistory() {
|
|
383
|
+
return [...this.chatHistory];
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Get logs (alias for getChatHistory for test compatibility)
|
|
387
|
+
*/
|
|
388
|
+
getLogs() {
|
|
389
|
+
return [...this.chatHistory];
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Receive a message from parent/orchestrator
|
|
393
|
+
*/
|
|
394
|
+
async receiveMessage(message) {
|
|
395
|
+
this.emit('message', message);
|
|
396
|
+
// Handle cancellation messages
|
|
397
|
+
if (message.type === 'cancellation') {
|
|
398
|
+
this.abort();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=subagent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent.js","sourceRoot":"","sources":["../../src/agent/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAS7C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAElE,eAAe;AACf,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,YAAY;IACxB,EAAE,CAAS;IACX,IAAI,CAAe;IACnB,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,SAAS,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc,CAAC,OAMpB;QACC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE9B,+BAA+B;QAC/B,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YACpC,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkpoint System
|
|
3
|
+
*
|
|
4
|
+
* Exports all checkpoint-related functionality
|
|
5
|
+
*/
|
|
6
|
+
export type { Checkpoint, CheckpointConfig, CheckpointFilter, CheckpointInfo, CheckpointMetadata, CheckpointOptions, CheckpointRestoreResult, CheckpointStats, CheckpointIndex, FileSnapshot, } from './types.js';
|
|
7
|
+
export { DEFAULT_CHECKPOINT_CONFIG } from './types.js';
|
|
8
|
+
export { CheckpointStorage, calculateHash, verifyFileSnapshot } from './storage.js';
|
|
9
|
+
export { CheckpointManager, getCheckpointManager, resetCheckpointManager } from './manager.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkpoint System
|
|
3
|
+
*
|
|
4
|
+
* Exports all checkpoint-related functionality
|
|
5
|
+
*/
|
|
6
|
+
export { DEFAULT_CHECKPOINT_CONFIG } from './types.js';
|
|
7
|
+
// Storage
|
|
8
|
+
export { CheckpointStorage, calculateHash, verifyFileSnapshot } from './storage.js';
|
|
9
|
+
// Manager
|
|
10
|
+
export { CheckpointManager, getCheckpointManager, resetCheckpointManager } from './manager.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/checkpoint/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgBH,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,UAAU;AACV,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEpF,UAAU;AACV,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkpoint Manager
|
|
3
|
+
*
|
|
4
|
+
* High-level API for checkpoint operations:
|
|
5
|
+
* - Creating checkpoints
|
|
6
|
+
* - Listing checkpoints
|
|
7
|
+
* - Restoring checkpoints
|
|
8
|
+
* - Pruning old checkpoints
|
|
9
|
+
* - Automatic checkpoint scheduling
|
|
10
|
+
*/
|
|
11
|
+
import type { Checkpoint, CheckpointConfig, CheckpointInfo, CheckpointOptions, CheckpointRestoreResult, CheckpointStats, CheckpointFilter } from './types.js';
|
|
12
|
+
import type { ChatEntry } from '../agent/llm-agent.js';
|
|
13
|
+
export declare class CheckpointManager {
|
|
14
|
+
private storage;
|
|
15
|
+
private config;
|
|
16
|
+
constructor(config?: Partial<CheckpointConfig>, baseDir?: string);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new checkpoint
|
|
20
|
+
*/
|
|
21
|
+
createCheckpoint(options: CheckpointOptions): Promise<Checkpoint>;
|
|
22
|
+
/**
|
|
23
|
+
* Restore a checkpoint
|
|
24
|
+
*/
|
|
25
|
+
restoreCheckpoint(checkpointId: string): Promise<CheckpointRestoreResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Apply a checkpoint (restore files and return conversation state)
|
|
28
|
+
* Alias for restoreCheckpoint for backward compatibility
|
|
29
|
+
*/
|
|
30
|
+
applyCheckpoint(checkpointId: string): Promise<CheckpointRestoreResult>;
|
|
31
|
+
/**
|
|
32
|
+
* List checkpoints with optional filtering
|
|
33
|
+
*/
|
|
34
|
+
listCheckpoints(filter?: CheckpointFilter): Promise<CheckpointInfo[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Get checkpoint by ID
|
|
37
|
+
*/
|
|
38
|
+
getCheckpoint(checkpointId: string): Promise<Checkpoint | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Get checkpoint info
|
|
41
|
+
*/
|
|
42
|
+
getCheckpointInfo(checkpointId: string): Promise<CheckpointInfo | null>;
|
|
43
|
+
/**
|
|
44
|
+
* Delete a checkpoint
|
|
45
|
+
*/
|
|
46
|
+
deleteCheckpoint(checkpointId: string): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Get checkpoint statistics
|
|
49
|
+
*/
|
|
50
|
+
getStats(): Promise<CheckpointStats>;
|
|
51
|
+
/**
|
|
52
|
+
* Prune old checkpoints based on config
|
|
53
|
+
*/
|
|
54
|
+
pruneOldCheckpoints(): Promise<number>;
|
|
55
|
+
/**
|
|
56
|
+
* Compress old checkpoints based on config
|
|
57
|
+
*/
|
|
58
|
+
compressOldCheckpoints(): Promise<number>;
|
|
59
|
+
/**
|
|
60
|
+
* Run maintenance (pruning, compression, limit enforcement)
|
|
61
|
+
*/
|
|
62
|
+
runMaintenance(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Enforce maximum number of checkpoints
|
|
65
|
+
*/
|
|
66
|
+
private enforceCheckpointLimit;
|
|
67
|
+
/**
|
|
68
|
+
* Enforce storage size limit (in MB)
|
|
69
|
+
*/
|
|
70
|
+
private enforceStorageLimit;
|
|
71
|
+
/**
|
|
72
|
+
* Get conversation state from a checkpoint
|
|
73
|
+
*/
|
|
74
|
+
getConversationState(checkpointId: string): Promise<ChatEntry[] | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Check if checkpoint should be created before an operation
|
|
77
|
+
*/
|
|
78
|
+
shouldCreateCheckpoint(operation: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Update configuration
|
|
81
|
+
*/
|
|
82
|
+
updateConfig(config: Partial<CheckpointConfig>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Get current configuration
|
|
85
|
+
*/
|
|
86
|
+
getConfig(): CheckpointConfig;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the singleton checkpoint manager instance
|
|
90
|
+
*/
|
|
91
|
+
export declare function getCheckpointManager(config?: Partial<CheckpointConfig>, baseDir?: string): CheckpointManager;
|
|
92
|
+
/**
|
|
93
|
+
* Initialize a new checkpoint manager instance (creates new singleton)
|
|
94
|
+
*/
|
|
95
|
+
export declare function initCheckpointManager(config?: Partial<CheckpointConfig>, baseDir?: string): CheckpointManager;
|
|
96
|
+
/**
|
|
97
|
+
* Reset the singleton instance (for testing)
|
|
98
|
+
*/
|
|
99
|
+
export declare function resetCheckpointManager(): void;
|