centaurus-cli 2.9.1 → 2.9.2
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/dist/cli-adapter.d.ts +70 -0
- package/dist/cli-adapter.d.ts.map +1 -1
- package/dist/cli-adapter.js +349 -156
- package/dist/cli-adapter.js.map +1 -1
- package/dist/config/mcp-config-manager.d.ts +21 -0
- package/dist/config/mcp-config-manager.d.ts.map +1 -1
- package/dist/config/mcp-config-manager.js +184 -1
- package/dist/config/mcp-config-manager.js.map +1 -1
- package/dist/config/models.d.ts +1 -0
- package/dist/config/models.d.ts.map +1 -1
- package/dist/config/models.js +7 -2
- package/dist/config/models.js.map +1 -1
- package/dist/config/slash-commands.d.ts.map +1 -1
- package/dist/config/slash-commands.js +4 -3
- package/dist/config/slash-commands.js.map +1 -1
- package/dist/index.js +60 -11
- package/dist/index.js.map +1 -1
- package/dist/mcp/mcp-command-handler.d.ts +34 -3
- package/dist/mcp/mcp-command-handler.d.ts.map +1 -1
- package/dist/mcp/mcp-command-handler.js +171 -83
- package/dist/mcp/mcp-command-handler.js.map +1 -1
- package/dist/mcp/mcp-server-manager.d.ts.map +1 -1
- package/dist/mcp/mcp-server-manager.js +9 -23
- package/dist/mcp/mcp-server-manager.js.map +1 -1
- package/dist/mcp/mcp-tool-wrapper.d.ts.map +1 -1
- package/dist/mcp/mcp-tool-wrapper.js +42 -5
- package/dist/mcp/mcp-tool-wrapper.js.map +1 -1
- package/dist/services/api-client.d.ts +9 -0
- package/dist/services/api-client.d.ts.map +1 -1
- package/dist/services/api-client.js +25 -0
- package/dist/services/api-client.js.map +1 -1
- package/dist/services/input-detection-agent.d.ts +40 -0
- package/dist/services/input-detection-agent.d.ts.map +1 -0
- package/dist/services/input-detection-agent.js +213 -0
- package/dist/services/input-detection-agent.js.map +1 -0
- package/dist/services/input-requirement-detector.d.ts +28 -0
- package/dist/services/input-requirement-detector.d.ts.map +1 -0
- package/dist/services/input-requirement-detector.js +203 -0
- package/dist/services/input-requirement-detector.js.map +1 -0
- package/dist/services/monitored-shell-manager.d.ts +120 -0
- package/dist/services/monitored-shell-manager.d.ts.map +1 -0
- package/dist/services/monitored-shell-manager.js +239 -0
- package/dist/services/monitored-shell-manager.js.map +1 -0
- package/dist/services/shell-input-agent.d.ts +89 -0
- package/dist/services/shell-input-agent.d.ts.map +1 -0
- package/dist/services/shell-input-agent.js +361 -0
- package/dist/services/shell-input-agent.js.map +1 -0
- package/dist/services/sub-agent-manager.d.ts +139 -0
- package/dist/services/sub-agent-manager.d.ts.map +1 -0
- package/dist/services/sub-agent-manager.js +517 -0
- package/dist/services/sub-agent-manager.js.map +1 -0
- package/dist/tools/background-command.d.ts.map +1 -1
- package/dist/tools/background-command.js +33 -13
- package/dist/tools/background-command.js.map +1 -1
- package/dist/tools/command.d.ts.map +1 -1
- package/dist/tools/command.js +64 -1
- package/dist/tools/command.js.map +1 -1
- package/dist/tools/file-ops.d.ts.map +1 -1
- package/dist/tools/file-ops.js +33 -19
- package/dist/tools/file-ops.js.map +1 -1
- package/dist/tools/get-diff.js +1 -1
- package/dist/tools/get-diff.js.map +1 -1
- package/dist/tools/grep-search.d.ts.map +1 -1
- package/dist/tools/grep-search.js +41 -15
- package/dist/tools/grep-search.js.map +1 -1
- package/dist/tools/plan-mode.js +3 -3
- package/dist/tools/plan-mode.js.map +1 -1
- package/dist/tools/registry.js +1 -1
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/sub-agent.d.ts +9 -0
- package/dist/tools/sub-agent.d.ts.map +1 -0
- package/dist/tools/sub-agent.js +232 -0
- package/dist/tools/sub-agent.js.map +1 -0
- package/dist/tools/task-complete.d.ts.map +1 -1
- package/dist/tools/task-complete.js +14 -26
- package/dist/tools/task-complete.js.map +1 -1
- package/dist/ui/components/App.d.ts +43 -0
- package/dist/ui/components/App.d.ts.map +1 -1
- package/dist/ui/components/App.js +560 -94
- package/dist/ui/components/App.js.map +1 -1
- package/dist/ui/components/CircularSelectInput.d.ts +24 -0
- package/dist/ui/components/CircularSelectInput.d.ts.map +1 -0
- package/dist/ui/components/CircularSelectInput.js +71 -0
- package/dist/ui/components/CircularSelectInput.js.map +1 -0
- package/dist/ui/components/ErrorBoundary.d.ts +3 -2
- package/dist/ui/components/ErrorBoundary.d.ts.map +1 -1
- package/dist/ui/components/ErrorBoundary.js +29 -1
- package/dist/ui/components/ErrorBoundary.js.map +1 -1
- package/dist/ui/components/InputBox.d.ts +2 -0
- package/dist/ui/components/InputBox.d.ts.map +1 -1
- package/dist/ui/components/InputBox.js +23 -3
- package/dist/ui/components/InputBox.js.map +1 -1
- package/dist/ui/components/InteractiveShell.d.ts +6 -0
- package/dist/ui/components/InteractiveShell.d.ts.map +1 -1
- package/dist/ui/components/InteractiveShell.js +57 -6
- package/dist/ui/components/InteractiveShell.js.map +1 -1
- package/dist/ui/components/MCPAddScreen.d.ts +13 -0
- package/dist/ui/components/MCPAddScreen.d.ts.map +1 -0
- package/dist/ui/components/MCPAddScreen.js +54 -0
- package/dist/ui/components/MCPAddScreen.js.map +1 -0
- package/dist/ui/components/MCPListScreen.d.ts +17 -0
- package/dist/ui/components/MCPListScreen.d.ts.map +1 -0
- package/dist/ui/components/MCPListScreen.js +50 -0
- package/dist/ui/components/MCPListScreen.js.map +1 -0
- package/dist/ui/components/MCPServerListScreen.d.ts +16 -0
- package/dist/ui/components/MCPServerListScreen.d.ts.map +1 -0
- package/dist/ui/components/MCPServerListScreen.js +59 -0
- package/dist/ui/components/MCPServerListScreen.js.map +1 -0
- package/dist/ui/components/MonitorModeAIPanel.d.ts +23 -0
- package/dist/ui/components/MonitorModeAIPanel.d.ts.map +1 -0
- package/dist/ui/components/MonitorModeAIPanel.js +69 -0
- package/dist/ui/components/MonitorModeAIPanel.js.map +1 -0
- package/dist/ui/components/MultiLineInput.d.ts +13 -0
- package/dist/ui/components/MultiLineInput.d.ts.map +1 -0
- package/dist/ui/components/MultiLineInput.js +223 -0
- package/dist/ui/components/MultiLineInput.js.map +1 -0
- package/dist/ui/components/StatusBar.d.ts +2 -0
- package/dist/ui/components/StatusBar.d.ts.map +1 -1
- package/dist/ui/components/StatusBar.js +33 -2
- package/dist/ui/components/StatusBar.js.map +1 -1
- package/dist/ui/components/ToolExecutionMessage.d.ts.map +1 -1
- package/dist/ui/components/ToolExecutionMessage.js +226 -12
- package/dist/ui/components/ToolExecutionMessage.js.map +1 -1
- package/dist/ui/components/VersionUpdatePrompt.d.ts.map +1 -1
- package/dist/ui/components/VersionUpdatePrompt.js +3 -2
- package/dist/ui/components/VersionUpdatePrompt.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-Agent Manager Service
|
|
3
|
+
*
|
|
4
|
+
* Manages the lifecycle of background sub-agents that can be spawned
|
|
5
|
+
* by the main agent to handle delegated tasks.
|
|
6
|
+
*/
|
|
7
|
+
import { randomUUID } from 'crypto';
|
|
8
|
+
import { aiServiceClient } from './ai-service-client.js';
|
|
9
|
+
import { apiClient } from './api-client.js';
|
|
10
|
+
import { sessionQuotaManager } from './session-quota-manager.js';
|
|
11
|
+
import { logError } from '../utils/logger.js';
|
|
12
|
+
import { quickLog } from '../utils/conversation-logger.js';
|
|
13
|
+
import { ContextManager } from '../context/context-manager.js';
|
|
14
|
+
// ==================== Constants ====================
|
|
15
|
+
const MAX_CONCURRENT_SUBAGENTS = 5;
|
|
16
|
+
const SUBAGENT_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
|
|
17
|
+
const MAX_TURNS_PER_SUBAGENT = 50;
|
|
18
|
+
// Model selection based on complexity
|
|
19
|
+
const SIMPLE_MODEL = 'gemini-3-flash-preview';
|
|
20
|
+
const COMPLEX_MODEL = 'gemini-3-pro-preview';
|
|
21
|
+
const COMPLEXITY_THRESHOLD = 5;
|
|
22
|
+
// ==================== Sub-Agent System Prompt ====================
|
|
23
|
+
const SUBAGENT_SYSTEM_PROMPT = `You are a sub-agent spawned by a main AI agent to complete a specific task.
|
|
24
|
+
|
|
25
|
+
IMPORTANT RULES:
|
|
26
|
+
1. You have full access to file system tools (read, write, edit, list, grep, find)
|
|
27
|
+
2. You have access to command execution tools
|
|
28
|
+
3. Focus ONLY on the task assigned to you
|
|
29
|
+
4. Always provide reason_text for every tool call to explain what you're doing
|
|
30
|
+
5. Call task_complete when you've finished the assigned task
|
|
31
|
+
6. Be efficient - don't explore unnecessarily, stick to the task
|
|
32
|
+
7. If you encounter errors, try to resolve them or report clearly what went wrong
|
|
33
|
+
|
|
34
|
+
CONTEXT FROM MAIN AGENT:
|
|
35
|
+
Working Directory: {WORKING_DIRECTORY}
|
|
36
|
+
|
|
37
|
+
{CONTEXT}
|
|
38
|
+
|
|
39
|
+
YOUR TASK:
|
|
40
|
+
{PROMPT}
|
|
41
|
+
|
|
42
|
+
Complete this task efficiently and call task_complete when done.`;
|
|
43
|
+
// ==================== SubAgentManager Class ====================
|
|
44
|
+
class SubAgentManagerClass {
|
|
45
|
+
subAgents = new Map();
|
|
46
|
+
toolRegistry;
|
|
47
|
+
onSubAgentCountChange;
|
|
48
|
+
onToolExecutionUpdate;
|
|
49
|
+
/**
|
|
50
|
+
* Initialize the manager with a tool registry
|
|
51
|
+
*/
|
|
52
|
+
initialize(toolRegistry) {
|
|
53
|
+
this.toolRegistry = toolRegistry;
|
|
54
|
+
quickLog(`[${new Date().toISOString()}] [SubAgentManager] Initialized with tool registry\n`);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Set callback for sub-agent count changes
|
|
58
|
+
*/
|
|
59
|
+
setOnSubAgentCountChange(callback) {
|
|
60
|
+
this.onSubAgentCountChange = callback;
|
|
61
|
+
quickLog(`[${new Date().toISOString()}] [SubAgentManager] setOnSubAgentCountChange callback registered\n`);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set callback for tool execution updates (for logging)
|
|
65
|
+
*/
|
|
66
|
+
setOnToolExecutionUpdate(callback) {
|
|
67
|
+
this.onToolExecutionUpdate = callback;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Notify listeners about sub-agent count change
|
|
71
|
+
*/
|
|
72
|
+
notifyCountChange() {
|
|
73
|
+
const runningAgents = this.getRunningSubAgents();
|
|
74
|
+
const runningCount = runningAgents.length;
|
|
75
|
+
const details = runningAgents.map(a => `${a.id}:${a.status}`).join(', ');
|
|
76
|
+
quickLog(`[${new Date().toISOString()}] [SubAgentManager] notifyCountChange called, runningCount=${runningCount}, agents=[${details}]\n`);
|
|
77
|
+
if (this.onSubAgentCountChange) {
|
|
78
|
+
this.onSubAgentCountChange(runningCount);
|
|
79
|
+
// quickLog(`Callback invoked`) // Removed redundant log or kept if preferred
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Select model based on complexity
|
|
84
|
+
*/
|
|
85
|
+
selectModel(complexity) {
|
|
86
|
+
return complexity <= COMPLEXITY_THRESHOLD ? SIMPLE_MODEL : COMPLEX_MODEL;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Generate system prompt for sub-agent
|
|
90
|
+
*/
|
|
91
|
+
generateSystemPrompt(config) {
|
|
92
|
+
return SUBAGENT_SYSTEM_PROMPT
|
|
93
|
+
.replace('{WORKING_DIRECTORY}', config.workingDirectory)
|
|
94
|
+
.replace('{CONTEXT}', config.context || 'No additional context provided.')
|
|
95
|
+
.replace('{PROMPT}', config.prompt);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Spawn a new sub-agent
|
|
99
|
+
*/
|
|
100
|
+
async spawnSubAgent(config) {
|
|
101
|
+
// Check concurrent limit
|
|
102
|
+
if (this.getRunningSubAgents().length >= MAX_CONCURRENT_SUBAGENTS) {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
error: `Maximum ${MAX_CONCURRENT_SUBAGENTS} concurrent sub-agents allowed. Wait for existing sub-agents to complete.`
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Check if tool registry is initialized
|
|
109
|
+
if (!this.toolRegistry) {
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
error: 'SubAgentManager not initialized. Tool registry is missing.'
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Check authentication
|
|
116
|
+
if (!apiClient.isAuthenticated()) {
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
error: 'Authentication required for sub-agents.'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// Check session quota
|
|
123
|
+
if (!sessionQuotaManager.canSendMessage()) {
|
|
124
|
+
return {
|
|
125
|
+
success: false,
|
|
126
|
+
error: 'Session quota exhausted. Cannot spawn sub-agent.'
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// Create sub-agent
|
|
130
|
+
const agentId = `subagent-${randomUUID().substring(0, 8)}`;
|
|
131
|
+
const model = this.selectModel(config.complexity);
|
|
132
|
+
const subAgent = {
|
|
133
|
+
id: agentId,
|
|
134
|
+
status: 'pending',
|
|
135
|
+
prompt: config.prompt,
|
|
136
|
+
context: config.context,
|
|
137
|
+
workingDirectory: config.workingDirectory,
|
|
138
|
+
complexity: config.complexity,
|
|
139
|
+
model,
|
|
140
|
+
startTime: new Date(),
|
|
141
|
+
conversationHistory: [],
|
|
142
|
+
turnCount: 0,
|
|
143
|
+
fileOperations: [],
|
|
144
|
+
toolHistory: [],
|
|
145
|
+
isRead: false,
|
|
146
|
+
abortController: new AbortController(),
|
|
147
|
+
};
|
|
148
|
+
this.subAgents.set(agentId, subAgent);
|
|
149
|
+
quickLog(`[${new Date().toISOString()}] [SubAgentManager] Sub-agent ${agentId} added to map, calling notifyCountChange\\n`);
|
|
150
|
+
this.notifyCountChange();
|
|
151
|
+
// Start the sub-agent loop in background (don't await)
|
|
152
|
+
this.runSubAgentLoop(agentId, config).catch(error => {
|
|
153
|
+
logError(`Sub-agent ${agentId} failed:`, error);
|
|
154
|
+
const agent = this.subAgents.get(agentId);
|
|
155
|
+
if (agent && agent.status === 'running') {
|
|
156
|
+
agent.status = 'failed';
|
|
157
|
+
agent.error = error.message || String(error);
|
|
158
|
+
agent.endTime = new Date();
|
|
159
|
+
this.notifyCountChange();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return { success: true, agentId };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Run the sub-agent's agent loop
|
|
166
|
+
*/
|
|
167
|
+
async runSubAgentLoop(agentId, config) {
|
|
168
|
+
const subAgent = this.subAgents.get(agentId);
|
|
169
|
+
if (!subAgent) {
|
|
170
|
+
throw new Error(`Sub-agent ${agentId} not found`);
|
|
171
|
+
}
|
|
172
|
+
subAgent.status = 'running';
|
|
173
|
+
this.notifyCountChange();
|
|
174
|
+
// Set up timeout
|
|
175
|
+
const timeoutId = setTimeout(() => {
|
|
176
|
+
const agent = this.subAgents.get(agentId);
|
|
177
|
+
if (agent && agent.status === 'running') {
|
|
178
|
+
agent.status = 'failed';
|
|
179
|
+
agent.error = 'Sub-agent timed out after 10 minutes';
|
|
180
|
+
agent.endTime = new Date();
|
|
181
|
+
agent.abortController?.abort();
|
|
182
|
+
this.notifyCountChange();
|
|
183
|
+
}
|
|
184
|
+
}, SUBAGENT_TIMEOUT_MS);
|
|
185
|
+
try {
|
|
186
|
+
// Initialize conversation with system prompt (as user message since backend injects system)
|
|
187
|
+
const systemPrompt = this.generateSystemPrompt(config);
|
|
188
|
+
subAgent.conversationHistory.push({
|
|
189
|
+
role: 'user',
|
|
190
|
+
content: systemPrompt,
|
|
191
|
+
});
|
|
192
|
+
const tools = this.toolRegistry.getSchemas();
|
|
193
|
+
// Build execution context
|
|
194
|
+
// Create a dedicated ContextManager for this sub-agent
|
|
195
|
+
const contextManager = new ContextManager(config.workingDirectory, process.platform);
|
|
196
|
+
const context = {
|
|
197
|
+
cwd: config.workingDirectory,
|
|
198
|
+
contextManager: contextManager,
|
|
199
|
+
requireApproval: async () => true, // Auto-approve for sub-agents (autonomous)
|
|
200
|
+
onStreamingOutput: () => { }, // No streaming output for sub-agents (yet)
|
|
201
|
+
};
|
|
202
|
+
// Agent loop
|
|
203
|
+
while (subAgent.turnCount < MAX_TURNS_PER_SUBAGENT && subAgent.status === 'running') {
|
|
204
|
+
subAgent.turnCount++;
|
|
205
|
+
// Check quota
|
|
206
|
+
sessionQuotaManager.incrementMessageCount();
|
|
207
|
+
if (!sessionQuotaManager.canSendMessage()) {
|
|
208
|
+
subAgent.status = 'failed';
|
|
209
|
+
subAgent.error = 'Session quota exhausted during sub-agent execution';
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
let assistantMessage = '';
|
|
213
|
+
let toolCalls = [];
|
|
214
|
+
// Stream AI response
|
|
215
|
+
try {
|
|
216
|
+
for await (const chunk of aiServiceClient.streamChat(subAgent.model, subAgent.conversationHistory, tools, { cwd: config.workingDirectory, platform: process.platform, shell: process.env.SHELL || 'cmd.exe', os: 'windows', homeDir: process.env.USERPROFILE || '' }, undefined, undefined, subAgent.abortController?.signal)) {
|
|
217
|
+
if (chunk.type === 'error') {
|
|
218
|
+
throw new Error(chunk.message);
|
|
219
|
+
}
|
|
220
|
+
if (chunk.type === 'text') {
|
|
221
|
+
assistantMessage += chunk.content;
|
|
222
|
+
}
|
|
223
|
+
if (chunk.type === 'tool_call') {
|
|
224
|
+
const toolCall = chunk.toolCall;
|
|
225
|
+
// Parse string arguments if needed
|
|
226
|
+
if (toolCall.arguments && typeof toolCall.arguments === 'string') {
|
|
227
|
+
try {
|
|
228
|
+
toolCall.arguments = JSON.parse(toolCall.arguments);
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
// Ignore parsing error
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
toolCalls.push(toolCall);
|
|
235
|
+
}
|
|
236
|
+
if (chunk.type === 'done') {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
if (error.name === 'AbortError') {
|
|
243
|
+
// Sub-agent was terminated
|
|
244
|
+
subAgent.status = 'terminated';
|
|
245
|
+
subAgent.endTime = new Date();
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
// Add assistant message to history
|
|
251
|
+
if (toolCalls.length > 0 || assistantMessage) {
|
|
252
|
+
const assistantMsg = {
|
|
253
|
+
role: 'assistant',
|
|
254
|
+
content: assistantMessage,
|
|
255
|
+
};
|
|
256
|
+
if (toolCalls.length > 0) {
|
|
257
|
+
assistantMsg.tool_calls = toolCalls;
|
|
258
|
+
}
|
|
259
|
+
subAgent.conversationHistory.push(assistantMsg);
|
|
260
|
+
}
|
|
261
|
+
// Execute tool calls
|
|
262
|
+
if (toolCalls.length === 0) {
|
|
263
|
+
// No tool calls and no task_complete - something went wrong
|
|
264
|
+
subAgent.status = 'completed';
|
|
265
|
+
subAgent.result = assistantMessage || 'Sub-agent completed without explicit task_complete';
|
|
266
|
+
subAgent.endTime = new Date();
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
for (const toolCall of toolCalls) {
|
|
270
|
+
// Check for task_complete
|
|
271
|
+
if (toolCall.name === 'task_complete') {
|
|
272
|
+
subAgent.status = 'completed';
|
|
273
|
+
subAgent.result = assistantMessage || 'Task completed successfully';
|
|
274
|
+
subAgent.endTime = new Date();
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
// Track the tool execution
|
|
278
|
+
const reasonText = toolCall.arguments?.reason_text;
|
|
279
|
+
const toolExecution = {
|
|
280
|
+
toolName: toolCall.name,
|
|
281
|
+
arguments: toolCall.arguments,
|
|
282
|
+
reasonText,
|
|
283
|
+
result: '',
|
|
284
|
+
success: false,
|
|
285
|
+
timestamp: new Date(),
|
|
286
|
+
};
|
|
287
|
+
try {
|
|
288
|
+
quickLog(`[SubAgent ${subAgent.id}] Executing tool: ${toolCall.name}`);
|
|
289
|
+
// Execute the tool
|
|
290
|
+
const result = await this.toolRegistry.execute(toolCall.name, toolCall.arguments, context);
|
|
291
|
+
quickLog(`[SubAgent ${subAgent.id}] Tool ${toolCall.name} execution result: ${JSON.stringify(result)}`);
|
|
292
|
+
toolExecution.success = result.success;
|
|
293
|
+
toolExecution.result = result.result;
|
|
294
|
+
// Track file operations
|
|
295
|
+
this.trackFileOperation(subAgent, toolCall, result);
|
|
296
|
+
// Add tool result to history
|
|
297
|
+
subAgent.conversationHistory.push({
|
|
298
|
+
role: 'tool',
|
|
299
|
+
tool_call_id: toolCall.id,
|
|
300
|
+
content: result.success ? result.result : `Error: ${result.error}`,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
toolExecution.success = false;
|
|
305
|
+
toolExecution.result = `Error: ${error.message}`;
|
|
306
|
+
subAgent.conversationHistory.push({
|
|
307
|
+
role: 'tool',
|
|
308
|
+
tool_call_id: toolCall.id,
|
|
309
|
+
content: `Error: ${error.message}`,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
subAgent.toolHistory.push(toolExecution);
|
|
313
|
+
}
|
|
314
|
+
// Check if task was completed
|
|
315
|
+
if (subAgent.status === 'completed') {
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// Check if we hit max turns
|
|
320
|
+
if (subAgent.turnCount >= MAX_TURNS_PER_SUBAGENT && subAgent.status === 'running') {
|
|
321
|
+
subAgent.status = 'failed';
|
|
322
|
+
subAgent.error = `Sub-agent exceeded maximum ${MAX_TURNS_PER_SUBAGENT} turns`;
|
|
323
|
+
subAgent.endTime = new Date();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
finally {
|
|
327
|
+
clearTimeout(timeoutId);
|
|
328
|
+
this.notifyCountChange();
|
|
329
|
+
}
|
|
330
|
+
quickLog(`[${new Date().toISOString()}] [SubAgent] ${agentId} finished with status: ${subAgent.status}\n`);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Track file operations made by sub-agent
|
|
334
|
+
*/
|
|
335
|
+
trackFileOperation(subAgent, toolCall, result) {
|
|
336
|
+
const { name, arguments: args } = toolCall;
|
|
337
|
+
if (name === 'write_to_file') {
|
|
338
|
+
subAgent.fileOperations.push({
|
|
339
|
+
type: 'create',
|
|
340
|
+
path: args.TargetFile || args.target_path || args.file_path || 'unknown_file',
|
|
341
|
+
newContent: args.content,
|
|
342
|
+
reasonText: args.reason_text,
|
|
343
|
+
timestamp: new Date(),
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else if (name === 'edit_file' || name === 'multi_edit_file') {
|
|
347
|
+
subAgent.fileOperations.push({
|
|
348
|
+
type: 'edit',
|
|
349
|
+
path: args.file_path || args.target_path || 'unknown_file',
|
|
350
|
+
diff: result.success ? result.result : undefined,
|
|
351
|
+
reasonText: args.reason_text,
|
|
352
|
+
timestamp: new Date(),
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
// Note: We could also track delete operations if there was a delete_file tool
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Get a sub-agent by ID
|
|
359
|
+
*/
|
|
360
|
+
getSubAgent(agentId) {
|
|
361
|
+
return this.subAgents.get(agentId);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Get all sub-agents
|
|
365
|
+
*/
|
|
366
|
+
getAllSubAgents() {
|
|
367
|
+
return Array.from(this.subAgents.values());
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get running sub-agents
|
|
371
|
+
*/
|
|
372
|
+
getRunningSubAgents() {
|
|
373
|
+
return this.getAllSubAgents().filter(a => a.status === 'running' || a.status === 'pending');
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Get completed but unread sub-agents
|
|
377
|
+
*/
|
|
378
|
+
getCompletedUnreadSubAgents() {
|
|
379
|
+
return this.getAllSubAgents().filter(a => (a.status === 'completed' || a.status === 'failed' || a.status === 'terminated') &&
|
|
380
|
+
!a.isRead);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Terminate a sub-agent
|
|
384
|
+
*/
|
|
385
|
+
terminateSubAgent(agentId) {
|
|
386
|
+
const subAgent = this.subAgents.get(agentId);
|
|
387
|
+
if (!subAgent) {
|
|
388
|
+
return { success: false, error: `Sub-agent ${agentId} not found` };
|
|
389
|
+
}
|
|
390
|
+
if (subAgent.status !== 'running' && subAgent.status !== 'pending') {
|
|
391
|
+
return { success: false, error: `Sub-agent ${agentId} is not running (status: ${subAgent.status})` };
|
|
392
|
+
}
|
|
393
|
+
subAgent.abortController?.abort();
|
|
394
|
+
subAgent.status = 'terminated';
|
|
395
|
+
subAgent.endTime = new Date();
|
|
396
|
+
this.notifyCountChange();
|
|
397
|
+
return { success: true };
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Get formatted diff output for a sub-agent
|
|
401
|
+
*/
|
|
402
|
+
getSubAgentDiff(agentId) {
|
|
403
|
+
const subAgent = this.subAgents.get(agentId);
|
|
404
|
+
if (!subAgent) {
|
|
405
|
+
return `Sub-agent ${agentId} not found`;
|
|
406
|
+
}
|
|
407
|
+
const lines = [];
|
|
408
|
+
lines.push(`## Sub-Agent Results: ${agentId}`);
|
|
409
|
+
lines.push(`**Status:** ${subAgent.status}`);
|
|
410
|
+
lines.push(`**Model:** ${subAgent.model}`);
|
|
411
|
+
lines.push(`**Duration:** ${this.formatDuration(subAgent.startTime, subAgent.endTime)}`);
|
|
412
|
+
lines.push(`**Turns:** ${subAgent.turnCount}`);
|
|
413
|
+
lines.push('');
|
|
414
|
+
if (subAgent.result) {
|
|
415
|
+
lines.push(`**Result:** ${subAgent.result}`);
|
|
416
|
+
lines.push('');
|
|
417
|
+
}
|
|
418
|
+
if (subAgent.error) {
|
|
419
|
+
lines.push(`**Error:** ${subAgent.error}`);
|
|
420
|
+
lines.push('');
|
|
421
|
+
}
|
|
422
|
+
// File operations
|
|
423
|
+
if (subAgent.fileOperations.length > 0) {
|
|
424
|
+
lines.push('### File Operations');
|
|
425
|
+
lines.push('');
|
|
426
|
+
for (const op of subAgent.fileOperations) {
|
|
427
|
+
const typeIcon = op.type === 'create' ? '📝' : op.type === 'edit' ? '✏️' : '🗑️';
|
|
428
|
+
lines.push(`${typeIcon} **${op.type.toUpperCase()}**: \`${op.path}\``);
|
|
429
|
+
if (op.reasonText) {
|
|
430
|
+
lines.push(` *Reason:* ${op.reasonText}`);
|
|
431
|
+
}
|
|
432
|
+
if (op.diff) {
|
|
433
|
+
lines.push('```diff');
|
|
434
|
+
lines.push(op.diff);
|
|
435
|
+
lines.push('```');
|
|
436
|
+
}
|
|
437
|
+
else if (op.newContent && op.type === 'create') {
|
|
438
|
+
// For new files, show a summary
|
|
439
|
+
const lineCount = op.newContent.split('\n').length;
|
|
440
|
+
lines.push(` *Created file with ${lineCount} lines*`);
|
|
441
|
+
}
|
|
442
|
+
lines.push('');
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
// Tool execution history (summarized)
|
|
446
|
+
if (subAgent.toolHistory.length > 0) {
|
|
447
|
+
lines.push('### Tool Execution Summary');
|
|
448
|
+
lines.push('');
|
|
449
|
+
const toolCounts = new Map();
|
|
450
|
+
for (const exec of subAgent.toolHistory) {
|
|
451
|
+
toolCounts.set(exec.toolName, (toolCounts.get(exec.toolName) || 0) + 1);
|
|
452
|
+
}
|
|
453
|
+
for (const [tool, count] of toolCounts) {
|
|
454
|
+
lines.push(`- ${tool}: ${count} call(s)`);
|
|
455
|
+
}
|
|
456
|
+
lines.push('');
|
|
457
|
+
}
|
|
458
|
+
const markdownReport = lines.join('\n');
|
|
459
|
+
// Create structured data for UI
|
|
460
|
+
const structuredData = {
|
|
461
|
+
agentId: subAgent.id,
|
|
462
|
+
status: subAgent.status,
|
|
463
|
+
model: subAgent.model,
|
|
464
|
+
duration: this.formatDuration(subAgent.startTime, subAgent.endTime),
|
|
465
|
+
turnCount: subAgent.turnCount,
|
|
466
|
+
fileOperations: subAgent.fileOperations.map(op => ({
|
|
467
|
+
type: op.type,
|
|
468
|
+
path: op.path
|
|
469
|
+
})),
|
|
470
|
+
result: subAgent.result,
|
|
471
|
+
error: subAgent.error
|
|
472
|
+
};
|
|
473
|
+
// Return JSON string containing both checkable text (for AI) and structured data (for UI)
|
|
474
|
+
// Wrapped in a format that looks like text but can be parsed as JSON if needed by UI
|
|
475
|
+
// Actually, let's just return a JSON object string. The AI can read JSON.
|
|
476
|
+
return JSON.stringify({
|
|
477
|
+
report: markdownReport,
|
|
478
|
+
data: structuredData
|
|
479
|
+
}, null, 2);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Mark sub-agent results as read
|
|
483
|
+
*/
|
|
484
|
+
markSubAgentRead(agentId) {
|
|
485
|
+
const subAgent = this.subAgents.get(agentId);
|
|
486
|
+
if (subAgent) {
|
|
487
|
+
subAgent.isRead = true;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Format duration between two dates
|
|
492
|
+
*/
|
|
493
|
+
formatDuration(start, end) {
|
|
494
|
+
const endTime = end || new Date();
|
|
495
|
+
const durationMs = endTime.getTime() - start.getTime();
|
|
496
|
+
const seconds = Math.floor(durationMs / 1000);
|
|
497
|
+
const minutes = Math.floor(seconds / 60);
|
|
498
|
+
if (minutes > 0) {
|
|
499
|
+
return `${minutes}m ${seconds % 60}s`;
|
|
500
|
+
}
|
|
501
|
+
return `${seconds}s`;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Clean up old completed sub-agents (call periodically)
|
|
505
|
+
*/
|
|
506
|
+
cleanup() {
|
|
507
|
+
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);
|
|
508
|
+
for (const [id, agent] of this.subAgents) {
|
|
509
|
+
if (agent.endTime && agent.endTime < oneHourAgo && agent.isRead) {
|
|
510
|
+
this.subAgents.delete(id);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
// Export singleton
|
|
516
|
+
export const SubAgentManager = new SubAgentManagerClass();
|
|
517
|
+
//# sourceMappingURL=sub-agent-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-agent-manager.js","sourceRoot":"","sources":["../../src/services/sub-agent-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAAqC,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAc,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AA4D/D,sDAAsD;AAEtD,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AACzD,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC,sCAAsC;AACtC,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAC9C,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAC7C,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B,oEAAoE;AAEpE,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;iEAmBkC,CAAC;AAElE,kEAAkE;AAElE,MAAM,oBAAoB;IACd,SAAS,GAA0B,IAAI,GAAG,EAAE,CAAC;IAC7C,YAAY,CAAgB;IAC5B,qBAAqB,CAA2B;IAChD,qBAAqB,CAAyB;IAEtD;;OAEG;IACH,UAAU,CAAC,YAA0B;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,QAAQ,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,W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U,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC9D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC9B,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAED,mBAAmB;AACnB,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,oBAAoB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-command.d.ts","sourceRoot":"","sources":["../../src/tools/background-command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,eAAO,MAAM,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"background-command.d.ts","sourceRoot":"","sources":["../../src/tools/background-command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,eAAO,MAAM,qBAAqB,EAAE,IAwLnC,CAAC"}
|
|
@@ -17,15 +17,17 @@ USE CASES:
|
|
|
17
17
|
- Running long-running processes (builds, tests, watchers)
|
|
18
18
|
- Running multiple commands concurrently
|
|
19
19
|
|
|
20
|
-
ACTIONS:
|
|
21
|
-
1. "start" - Start a new background command. Returns a task_id immediately.
|
|
22
|
-
2. "status" - Check the status and output of a background task. Use this to monitor progress.
|
|
23
|
-
3. "kill" - Terminate a running background task.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
20
|
+
ACTIONS:
|
|
21
|
+
1. "start" - Start a new background command. Returns a task_id immediately.
|
|
22
|
+
2. "status" - Check the status and output of a background task. Use this to monitor progress.
|
|
23
|
+
3. "kill" - Terminate a running background task.
|
|
24
|
+
4. "wait" - Pause execution for a specified duration. Use this instead of repeatedly checking status.
|
|
25
|
+
|
|
26
|
+
IMPORTANT:
|
|
27
|
+
- After starting a task, you can continue with other work while it runs.
|
|
28
|
+
- Use "status" periodically to check on long-running tasks.
|
|
29
|
+
- Use "wait" to pause before checking status again (e.g., wait 30 seconds for a build to complete).
|
|
30
|
+
- Always clean up tasks with "kill" when they're no longer needed.
|
|
29
31
|
- The task_id returned from "start" must be saved to use with "status" or "kill".`,
|
|
30
32
|
parameters: {
|
|
31
33
|
type: 'object',
|
|
@@ -36,8 +38,8 @@ IMPORTANT:
|
|
|
36
38
|
},
|
|
37
39
|
action: {
|
|
38
40
|
type: 'string',
|
|
39
|
-
enum: ['start', 'status', 'kill'],
|
|
40
|
-
description: 'The action to perform: "start" to run a new command, "status" to check a task, "kill" to terminate a task.',
|
|
41
|
+
enum: ['start', 'status', 'kill', 'wait'],
|
|
42
|
+
description: 'The action to perform: "start" to run a new command, "status" to check a task, "kill" to terminate a task, "wait" to pause execution.',
|
|
41
43
|
},
|
|
42
44
|
command: {
|
|
43
45
|
type: 'string',
|
|
@@ -55,12 +57,16 @@ IMPORTANT:
|
|
|
55
57
|
type: 'integer',
|
|
56
58
|
description: 'Number of lines of output to return (from the end). Default: 50. Only used with "status" action.',
|
|
57
59
|
},
|
|
60
|
+
wait_seconds: {
|
|
61
|
+
type: 'integer',
|
|
62
|
+
description: 'Number of seconds to wait. REQUIRED when action is "wait". Use this to pause before checking task status again.',
|
|
63
|
+
},
|
|
58
64
|
},
|
|
59
65
|
required: ['reason_text', 'action'],
|
|
60
66
|
},
|
|
61
67
|
},
|
|
62
68
|
async execute(args, context) {
|
|
63
|
-
const { action, command, cwd, task_id, output_lines = 50 } = args;
|
|
69
|
+
const { action, command, cwd, task_id, output_lines = 50, wait_seconds } = args;
|
|
64
70
|
switch (action) {
|
|
65
71
|
case 'start': {
|
|
66
72
|
// Validate required parameters for start
|
|
@@ -154,8 +160,22 @@ ${outputToShow || '(no output yet)'}
|
|
|
154
160
|
throw new Error(`Failed to kill task "${task_id}". The task may have already completed.`);
|
|
155
161
|
}
|
|
156
162
|
}
|
|
163
|
+
case 'wait': {
|
|
164
|
+
// Validate required parameters for wait
|
|
165
|
+
if (!wait_seconds) {
|
|
166
|
+
throw new Error('Missing required parameter "wait_seconds" for action "wait"');
|
|
167
|
+
}
|
|
168
|
+
if (wait_seconds < 1 || wait_seconds > 300) {
|
|
169
|
+
throw new Error('wait_seconds must be between 1 and 300 (5 minutes)');
|
|
170
|
+
}
|
|
171
|
+
// Create a promise that resolves after the specified duration
|
|
172
|
+
await new Promise(resolve => setTimeout(resolve, wait_seconds * 1000));
|
|
173
|
+
return `Waited for ${wait_seconds} second${wait_seconds !== 1 ? 's' : ''}.
|
|
174
|
+
|
|
175
|
+
⏱️ The execution has been paused for the requested duration. You can now continue with the next action.`;
|
|
176
|
+
}
|
|
157
177
|
default:
|
|
158
|
-
throw new Error(`Unknown action "${action}". Valid actions are: "start", "status", "kill".`);
|
|
178
|
+
throw new Error(`Unknown action "${action}". Valid actions are: "start", "status", "kill", "wait".`);
|
|
159
179
|
}
|
|
160
180
|
},
|
|
161
181
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-command.js","sourceRoot":"","sources":["../../src/tools/background-command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,MAAM,CAAC,MAAM,qBAAqB,GAAS;IACvC,MAAM,EAAE;QACJ,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE
|
|
1
|
+
{"version":3,"file":"background-command.js","sourceRoot":"","sources":["../../src/tools/background-command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,MAAM,CAAC,MAAM,qBAAqB,GAAS;IACvC,MAAM,EAAE;QACJ,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE;;;;;;;;;;;;;;;;;;kFAkB6D;QAC1E,UAAU,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACR,WAAW,EAAE;oBACT,IA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C,IAAI,CAAC,SAAS,EAAE,CAAC;oBAClB,OAAO,SAAS,OAAO,mEAAmE,CAAC;gBAC/F,CAAC;gBAED,MAAM,OAAO,GAAG,qBAAqB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBAC1D,IAAI,OAAO,EAAE,CAAC;oBACV,OAAO,oBAAoB,OAAO;;eAEvC,IAAI,CAAC,OAAO;iCACM,CAAC;gBAClB,CAAC;qBAAM,CAAC;oBACJ,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,yCAAyC,CAAC,CAAC;gBAC9F,CAAC;YACL,CAAC;YAED,KAAK,MAAM,CAAC,CAAC,CAAC;gBACV,wCAAwC;gBACxC,IAAI,CAAC,YAAY,EAAE,CAAC;oBAChB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;gBACnF,CAAC;gBAED,IAAI,YAAY,GAAG,CAAC,IAAI,YAAY,GAAG,GAAG,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;gBAC1E,CAAC;gBAED,8DAA8D;gBAC9D,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC;gBAEvE,OAAO,cAAc,YAAY,UAAU,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;;wGAEgB,CAAC;YAC7F,CAAC;YAED;gBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,0DAA0D,CAAC,CAAC;QAC7G,CAAC;IACL,CAAC;CACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/tools/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/tools/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAwClC,eAAO,MAAM,cAAc,EAAE,IAga5B,CAAC"}
|