aegiscode 3.1.10 → 3.4.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/bin/aegis.js +165 -0
- package/package.json +18 -86
- package/LICENSE +0 -21
- package/README.md +0 -394
- package/dist/main.js +0 -2171
- package/gui/run-gui.cjs +0 -13
- package/src/agent/Agent.ts +0 -903
- package/src/agent/SimpleAgent.ts +0 -48
- package/src/agent/index.ts +0 -54
- package/src/agent/orchestrator/AppBuilder.ts +0 -443
- package/src/agent/orchestrator/CouncilAgent.ts +0 -310
- package/src/agent/orchestrator/DiscussionRoom.ts +0 -462
- package/src/agent/orchestrator/OrchestratorAgent.ts +0 -637
- package/src/agent/orchestrator/index.ts +0 -38
- package/src/agent/orchestrator/utils.ts +0 -397
- package/src/agent/pricing.ts +0 -115
- package/src/agent/router.ts +0 -74
- package/src/agent/routerStats.ts +0 -121
- package/src/agent/types.ts +0 -318
- package/src/auth/login.ts +0 -383
- package/src/cli/config.ts +0 -189
- package/src/cli/index.ts +0 -17
- package/src/cli/middleware.ts +0 -119
- package/src/cli/types.ts +0 -75
- package/src/config/ConfigManager.ts +0 -587
- package/src/config/index.ts +0 -7
- package/src/config/types.ts +0 -584
- package/src/context/CompactionService.ts +0 -300
- package/src/context/ContextManager.ts +0 -450
- package/src/context/FileAnalyzer.ts +0 -267
- package/src/context/TokenCounter.ts +0 -265
- package/src/context/index.ts +0 -27
- package/src/context/storage/CacheStore.ts +0 -176
- package/src/context/storage/JSONLStore.ts +0 -201
- package/src/context/storage/MemoryStore.ts +0 -205
- package/src/context/storage/PersistentStore.ts +0 -327
- package/src/context/storage/index.ts +0 -9
- package/src/context/storage/pathUtils.ts +0 -114
- package/src/context/test.ts +0 -309
- package/src/context/types.ts +0 -268
- package/src/hooks/HookExecutor.ts +0 -434
- package/src/hooks/HookManager.ts +0 -596
- package/src/hooks/HookService.ts +0 -269
- package/src/hooks/Matcher.ts +0 -157
- package/src/hooks/index.ts +0 -63
- package/src/hooks/types.ts +0 -424
- package/src/main.tsx +0 -596
- package/src/mcp/HealthMonitor.ts +0 -150
- package/src/mcp/McpClient.ts +0 -491
- package/src/mcp/McpRegistry.ts +0 -321
- package/src/mcp/createMcpTool.ts +0 -251
- package/src/mcp/index.ts +0 -15
- package/src/mcp/server.ts +0 -334
- package/src/mcp/test-server.ts +0 -88
- package/src/mcp/test.ts +0 -372
- package/src/mcp/types.ts +0 -247
- package/src/memory/AgentMemoryBus.ts +0 -432
- package/src/memory/CloudSync.ts +0 -99
- package/src/memory/DriveSync.ts +0 -106
- package/src/memory/SharedMemory.ts +0 -951
- package/src/memory/index.ts +0 -14
- package/src/memory/machineFingerprint.ts +0 -40
- package/src/orchestrator/SubAgentMetadata.ts +0 -136
- package/src/prompts/builder.ts +0 -213
- package/src/prompts/default.ts +0 -144
- package/src/prompts/index.ts +0 -16
- package/src/prompts/plan.ts +0 -64
- package/src/prompts/test.ts +0 -78
- package/src/services/AnthropicChatService.ts +0 -341
- package/src/services/ChatService.ts +0 -347
- package/src/services/ClaudeCliChatService.ts +0 -256
- package/src/services/CloudSync.ts +0 -168
- package/src/services/CostLedger.ts +0 -211
- package/src/services/Heartbeat.ts +0 -135
- package/src/services/LearningCollector.ts +0 -291
- package/src/services/OllamaInstaller.ts +0 -342
- package/src/services/VersionChecker.ts +0 -445
- package/src/services/index.ts +0 -57
- package/src/services/streaming/OpenAIEventAdapter.ts +0 -126
- package/src/services/streaming/RenderingProfile.ts +0 -90
- package/src/services/streaming/StreamEventParser.ts +0 -181
- package/src/services/streaming/ThrottledRenderer.ts +0 -139
- package/src/services/streaming/TranscriptBuffer.ts +0 -574
- package/src/services/streaming/eventStatusMap.ts +0 -52
- package/src/services/streaming/index.ts +0 -46
- package/src/services/streaming/renderFormatting.ts +0 -79
- package/src/services/streaming/types.ts +0 -234
- package/src/skills/SkillLoader.ts +0 -126
- package/src/skills/SkillRegistry.ts +0 -366
- package/src/skills/index.ts +0 -48
- package/src/skills/types.ts +0 -146
- package/src/slash-commands/billing.ts +0 -70
- package/src/slash-commands/build.ts +0 -413
- package/src/slash-commands/builtinCommands.ts +0 -2733
- package/src/slash-commands/clone.ts +0 -242
- package/src/slash-commands/council.ts +0 -125
- package/src/slash-commands/custom/CustomCommandExecutor.ts +0 -143
- package/src/slash-commands/custom/CustomCommandLoader.ts +0 -251
- package/src/slash-commands/custom/CustomCommandRegistry.ts +0 -144
- package/src/slash-commands/custom/index.ts +0 -7
- package/src/slash-commands/debate.ts +0 -254
- package/src/slash-commands/gmail.ts +0 -105
- package/src/slash-commands/index.ts +0 -388
- package/src/slash-commands/mcpCommand.ts +0 -205
- package/src/slash-commands/types.ts +0 -201
- package/src/store/index.ts +0 -76
- package/src/store/selectors.ts +0 -246
- package/src/store/slices/appSlice.ts +0 -205
- package/src/store/slices/commandSlice.ts +0 -115
- package/src/store/slices/configSlice.ts +0 -46
- package/src/store/slices/focusSlice.ts +0 -64
- package/src/store/slices/index.ts +0 -9
- package/src/store/slices/sessionSlice.ts +0 -424
- package/src/store/streaming-buffer.ts +0 -425
- package/src/store/test.ts +0 -296
- package/src/store/types.ts +0 -274
- package/src/store/vanilla.ts +0 -186
- package/src/tools/builtin/bash.ts +0 -236
- package/src/tools/builtin/council.ts +0 -105
- package/src/tools/builtin/edit.ts +0 -213
- package/src/tools/builtin/glob.ts +0 -136
- package/src/tools/builtin/grep.ts +0 -263
- package/src/tools/builtin/index.ts +0 -61
- package/src/tools/builtin/memory.ts +0 -66
- package/src/tools/builtin/read.ts +0 -168
- package/src/tools/builtin/skill.ts +0 -97
- package/src/tools/builtin/snapshot.ts +0 -40
- package/src/tools/builtin/task.ts +0 -106
- package/src/tools/builtin/write.ts +0 -134
- package/src/tools/createTool.ts +0 -221
- package/src/tools/execution/ExecutionPipeline.ts +0 -263
- package/src/tools/execution/index.ts +0 -40
- package/src/tools/execution/stages/CacheStage.ts +0 -131
- package/src/tools/execution/stages/ConfirmationStage.ts +0 -203
- package/src/tools/execution/stages/DiscoveryStage.ts +0 -46
- package/src/tools/execution/stages/ExecutionStage.ts +0 -48
- package/src/tools/execution/stages/FormattingStage.ts +0 -44
- package/src/tools/execution/stages/HookStage.ts +0 -72
- package/src/tools/execution/stages/PermissionStage.ts +0 -287
- package/src/tools/execution/stages/PostHookStage.ts +0 -71
- package/src/tools/execution/stages/index.ts +0 -12
- package/src/tools/execution/test.ts +0 -266
- package/src/tools/execution/types.ts +0 -273
- package/src/tools/index.ts +0 -81
- package/src/tools/registry.ts +0 -304
- package/src/tools/schemas.ts +0 -109
- package/src/tools/test.ts +0 -220
- package/src/tools/types.ts +0 -175
- package/src/tools/validation/PermissionChecker.ts +0 -242
- package/src/tools/validation/SensitiveFileDetector.ts +0 -210
- package/src/tools/validation/index.ts +0 -11
- package/src/ui/App.tsx +0 -166
- package/src/ui/components/AegisInterface.tsx +0 -484
- package/src/ui/components/common/ChatSearch.tsx +0 -150
- package/src/ui/components/common/ErrorBoundary.tsx +0 -82
- package/src/ui/components/common/ExitMessage.tsx +0 -120
- package/src/ui/components/common/LoadingIndicator.tsx +0 -49
- package/src/ui/components/common/index.ts +0 -6
- package/src/ui/components/dialog/ConfirmationPrompt.tsx +0 -208
- package/src/ui/components/dialog/InteractiveSelector.tsx +0 -149
- package/src/ui/components/dialog/SetupWizard.tsx +0 -297
- package/src/ui/components/dialog/UpdatePrompt.tsx +0 -155
- package/src/ui/components/dialog/index.ts +0 -8
- package/src/ui/components/index.ts +0 -28
- package/src/ui/components/input/CommandSuggestions.tsx +0 -139
- package/src/ui/components/input/CustomTextInput.tsx +0 -220
- package/src/ui/components/input/InputArea.tsx +0 -361
- package/src/ui/components/input/PromptSuggestions.tsx +0 -66
- package/src/ui/components/input/index.ts +0 -6
- package/src/ui/components/layout/ChatStatusBar.tsx +0 -90
- package/src/ui/components/layout/ContextBar.tsx +0 -79
- package/src/ui/components/layout/MessageArea.tsx +0 -96
- package/src/ui/components/layout/MessageList.tsx +0 -647
- package/src/ui/components/layout/MessageSeparator.tsx +0 -26
- package/src/ui/components/layout/WelcomeMessage.tsx +0 -93
- package/src/ui/components/layout/index.ts +0 -7
- package/src/ui/components/markdown/CodeHighlighter.tsx +0 -292
- package/src/ui/components/markdown/MessageRenderer.tsx +0 -1211
- package/src/ui/components/markdown/index.ts +0 -8
- package/src/ui/components/markdown/parser.ts +0 -336
- package/src/ui/components/markdown/types.ts +0 -66
- package/src/ui/focus/FocusManager.ts +0 -137
- package/src/ui/focus/index.ts +0 -13
- package/src/ui/focus/types.ts +0 -54
- package/src/ui/focus/useFocus.ts +0 -75
- package/src/ui/hooks/index.ts +0 -11
- package/src/ui/hooks/useAgent.ts +0 -284
- package/src/ui/hooks/useCommandHistory.ts +0 -87
- package/src/ui/hooks/useCommandProcessor.ts +0 -443
- package/src/ui/hooks/useConfirmation.ts +0 -99
- package/src/ui/hooks/useCtrlCHandler.ts +0 -100
- package/src/ui/hooks/useInputBuffer.ts +0 -122
- package/src/ui/hooks/useTerminalSize.ts +0 -68
- package/src/ui/hooks/useTerminalWidth.ts +0 -5
- package/src/ui/hooks/useWindowedList.ts +0 -118
- package/src/ui/render-debugger.ts +0 -621
- package/src/ui/test.ts +0 -189
- package/src/ui/themes/ThemeManager.ts +0 -332
- package/src/ui/themes/aegisTheme.ts +0 -87
- package/src/ui/themes/darkTheme.ts +0 -87
- package/src/ui/themes/defaultTheme.ts +0 -85
- package/src/ui/themes/index.ts +0 -10
- package/src/ui/themes/lightTheme.ts +0 -89
- package/src/ui/themes/popularThemes.ts +0 -187
- package/src/ui/themes/types.ts +0 -130
- package/src/utils/clipboard.ts +0 -48
- package/src/utils/debug.ts +0 -43
- package/src/utils/environment.ts +0 -68
- package/src/utils/index.ts +0 -10
|
@@ -1,637 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OrchestratorAgent — Multi-agent orchestration coordinator
|
|
3
|
-
*
|
|
4
|
-
* Capabilities:
|
|
5
|
-
* - Delegates tasks to specialized sub-agents
|
|
6
|
-
* - Runs agents in parallel for independent tasks
|
|
7
|
-
* - Fuses results from multiple agents
|
|
8
|
-
* - Routes follow-up tasks based on context
|
|
9
|
-
* - Sub-agents can use real tools (Read, Edit, Write, Bash, Grep, Glob)
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { randomUUID } from 'node:crypto';
|
|
13
|
-
import type { AgentConfig, Message, ToolCall, ToolDefinition } from '../types.js';
|
|
14
|
-
import { createChatService } from '../../services/ChatService.js';
|
|
15
|
-
import { sharedMemory } from '../../memory/SharedMemory.js';
|
|
16
|
-
import { agentMemoryBus } from '../../memory/AgentMemoryBus.js';
|
|
17
|
-
import { agentDebug } from '../../utils/debug.js';
|
|
18
|
-
import { configManager } from '../../config/ConfigManager.js';
|
|
19
|
-
import { SubAgentMetadataStore } from '../../orchestrator/SubAgentMetadata.js';
|
|
20
|
-
import {
|
|
21
|
-
createToolRegistry,
|
|
22
|
-
getBuiltinTools,
|
|
23
|
-
ExecutionPipeline,
|
|
24
|
-
PermissionMode,
|
|
25
|
-
type ToolRegistry,
|
|
26
|
-
type PipelineExecutionContext,
|
|
27
|
-
type ConfirmationHandler,
|
|
28
|
-
} from '../../tools/index.js';
|
|
29
|
-
|
|
30
|
-
// ========== Types ==========
|
|
31
|
-
|
|
32
|
-
export interface SubAgentConfig {
|
|
33
|
-
name: string;
|
|
34
|
-
role: string;
|
|
35
|
-
systemPrompt: string;
|
|
36
|
-
config: AgentConfig;
|
|
37
|
-
tools?: string[]; // tool names this agent can use
|
|
38
|
-
permissionMode?: PermissionMode; // defaults to user's configured mode
|
|
39
|
-
confirmationHandler?: ConfirmationHandler; // for interactive tool approval
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface TaskDelegation {
|
|
43
|
-
agentName: string;
|
|
44
|
-
task: string;
|
|
45
|
-
context?: {
|
|
46
|
-
messages?: Message[];
|
|
47
|
-
files?: string[];
|
|
48
|
-
previousResults?: string;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface AgentResponse {
|
|
53
|
-
agentName: string;
|
|
54
|
-
content: string;
|
|
55
|
-
toolCalls?: ToolCall[];
|
|
56
|
-
metadata?: {
|
|
57
|
-
tokensUsed?: number;
|
|
58
|
-
durationMs?: number;
|
|
59
|
-
toolCallsCount?: number;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface OrchestrationResult {
|
|
64
|
-
success: boolean;
|
|
65
|
-
responses: AgentResponse[];
|
|
66
|
-
summary: string;
|
|
67
|
-
metadata: {
|
|
68
|
-
agentsUsed: number;
|
|
69
|
-
totalTokens?: number;
|
|
70
|
-
totalDurationMs: number;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const subAgentMetadataStore = new SubAgentMetadataStore();
|
|
75
|
-
|
|
76
|
-
// ========== Tool-Enabled Sub-Agent Runner ==========
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* SubAgentRunner — runs one sub-agent with optional tool execution.
|
|
80
|
-
*
|
|
81
|
-
* Previously this was a pure LLM chat. Now it:
|
|
82
|
-
* 1. Registers its allowed tools
|
|
83
|
-
* 2. Passes tool definitions to the LLM
|
|
84
|
-
* 3. Executes tool calls inline (like Agent.ts)
|
|
85
|
-
* 4. Returns the final content + metadata
|
|
86
|
-
*/
|
|
87
|
-
class SubAgentRunner {
|
|
88
|
-
private chatService: ReturnType<typeof createChatService>;
|
|
89
|
-
private config: SubAgentConfig;
|
|
90
|
-
private toolRegistry?: ToolRegistry;
|
|
91
|
-
private executionPipeline?: ExecutionPipeline;
|
|
92
|
-
private currentSessionId: string = 'default';
|
|
93
|
-
|
|
94
|
-
constructor(config: SubAgentConfig) {
|
|
95
|
-
this.config = config;
|
|
96
|
-
this.chatService = createChatService(config.config);
|
|
97
|
-
|
|
98
|
-
// Set up tool registry if this agent has tool access
|
|
99
|
-
if (config.tools && config.tools.length > 0) {
|
|
100
|
-
const registry = createToolRegistry();
|
|
101
|
-
const builtins = getBuiltinTools();
|
|
102
|
-
for (const tool of builtins) {
|
|
103
|
-
if (config.tools.includes(tool.name)) {
|
|
104
|
-
registry.register(tool);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
this.toolRegistry = registry;
|
|
108
|
-
// Use configured permission mode, or read from user's settings (default: ask for confirm)
|
|
109
|
-
const mode = config.permissionMode || resolvePermissionMode();
|
|
110
|
-
this.executionPipeline = new ExecutionPipeline(registry, {
|
|
111
|
-
defaultMode: mode,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async run(
|
|
117
|
-
task: string,
|
|
118
|
-
context?: TaskDelegation['context'],
|
|
119
|
-
sessionId?: string,
|
|
120
|
-
): Promise<AgentResponse> {
|
|
121
|
-
const startTime = Date.now();
|
|
122
|
-
const sid = sessionId || 'default';
|
|
123
|
-
this.currentSessionId = sid;
|
|
124
|
-
|
|
125
|
-
const spawnId = randomUUID();
|
|
126
|
-
await subAgentMetadataStore.spawn({
|
|
127
|
-
spawnId,
|
|
128
|
-
agentName: this.config.name,
|
|
129
|
-
role: this.config.role,
|
|
130
|
-
task,
|
|
131
|
-
sessionId: sid,
|
|
132
|
-
agentType: 'subagent',
|
|
133
|
-
}).catch(() => {});
|
|
134
|
-
|
|
135
|
-
// ── Inject cross-session persistent memory ──
|
|
136
|
-
const memCtx = await sharedMemory.buildContext(task, 3, sid);
|
|
137
|
-
|
|
138
|
-
// ── Inject shared agent memory bus context (inter-agent communication) ──
|
|
139
|
-
const agentContext = await agentMemoryBus.getContextForAgent(
|
|
140
|
-
this.config.name,
|
|
141
|
-
sid,
|
|
142
|
-
8,
|
|
143
|
-
600,
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
let systemPrompt = this.config.systemPrompt;
|
|
147
|
-
if (memCtx) {
|
|
148
|
-
systemPrompt += '\n\n' + memCtx;
|
|
149
|
-
}
|
|
150
|
-
if (agentContext) {
|
|
151
|
-
systemPrompt += '\n\n' + agentContext;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const messages: Message[] = [
|
|
155
|
-
{ role: 'system', content: systemPrompt },
|
|
156
|
-
...(context?.messages || []),
|
|
157
|
-
];
|
|
158
|
-
|
|
159
|
-
messages.push({
|
|
160
|
-
role: 'user',
|
|
161
|
-
content: context?.previousResults
|
|
162
|
-
? `Previous results:\n${context.previousResults}\n\n---\n\n${task}`
|
|
163
|
-
: task,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// ── Build tool definitions for LLM ──
|
|
167
|
-
const tools: ToolDefinition[] | undefined = this.toolRegistry
|
|
168
|
-
? this.toolRegistry.getFunctionDeclarationsByMode().map(fn => ({
|
|
169
|
-
type: 'function' as const,
|
|
170
|
-
function: {
|
|
171
|
-
name: fn.name,
|
|
172
|
-
description: fn.description,
|
|
173
|
-
parameters: fn.parameters as ToolDefinition['function']['parameters'],
|
|
174
|
-
},
|
|
175
|
-
}))
|
|
176
|
-
: undefined;
|
|
177
|
-
|
|
178
|
-
// ── Execute LLM loop (max 1 turn with tools) ──
|
|
179
|
-
let totalToolCalls = 0;
|
|
180
|
-
try {
|
|
181
|
-
const result = await this.chatService.chat(messages, tools);
|
|
182
|
-
|
|
183
|
-
// If no tool calls — just return content
|
|
184
|
-
if (!result.toolCalls || result.toolCalls.length === 0) {
|
|
185
|
-
await this.publishResult(task, result.content, result.usage?.totalTokens, startTime);
|
|
186
|
-
const durationMs = Date.now() - startTime;
|
|
187
|
-
await subAgentMetadataStore.finish(spawnId, 'success', {
|
|
188
|
-
durationMs,
|
|
189
|
-
tokensUsed: result.usage?.totalTokens,
|
|
190
|
-
toolCallsCount: 0,
|
|
191
|
-
}).catch(() => {});
|
|
192
|
-
return {
|
|
193
|
-
agentName: this.config.name,
|
|
194
|
-
content: result.content,
|
|
195
|
-
metadata: {
|
|
196
|
-
tokensUsed: result.usage?.totalTokens,
|
|
197
|
-
durationMs,
|
|
198
|
-
},
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Execute tool calls and get final content from LLM
|
|
203
|
-
const finalContent = await this.executeToolCallsAndRespond(
|
|
204
|
-
result.toolCalls,
|
|
205
|
-
messages,
|
|
206
|
-
tools,
|
|
207
|
-
sid,
|
|
208
|
-
);
|
|
209
|
-
totalToolCalls = result.toolCalls.length;
|
|
210
|
-
|
|
211
|
-
await this.publishResult(task, finalContent, result.usage?.totalTokens, startTime);
|
|
212
|
-
const durationMs = Date.now() - startTime;
|
|
213
|
-
await subAgentMetadataStore.finish(spawnId, 'success', {
|
|
214
|
-
durationMs,
|
|
215
|
-
tokensUsed: result.usage?.totalTokens,
|
|
216
|
-
toolCallsCount: totalToolCalls,
|
|
217
|
-
}).catch(() => {});
|
|
218
|
-
return {
|
|
219
|
-
agentName: this.config.name,
|
|
220
|
-
content: finalContent,
|
|
221
|
-
toolCalls: result.toolCalls,
|
|
222
|
-
metadata: {
|
|
223
|
-
tokensUsed: result.usage?.totalTokens,
|
|
224
|
-
durationMs,
|
|
225
|
-
toolCallsCount: totalToolCalls,
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
} catch (error) {
|
|
229
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
230
|
-
agentDebug.error(`[${this.config.name}] LLM call failed: ${errMsg}`);
|
|
231
|
-
|
|
232
|
-
agentMemoryBus.publish({
|
|
233
|
-
channel: 'error',
|
|
234
|
-
sourceAgent: this.config.name,
|
|
235
|
-
sessionId: sid,
|
|
236
|
-
content: `LLM call failed: ${errMsg}`,
|
|
237
|
-
importance: 0.9,
|
|
238
|
-
tags: ['error', 'llm-failure'],
|
|
239
|
-
}).catch(() => {});
|
|
240
|
-
|
|
241
|
-
const durationMs = Date.now() - startTime;
|
|
242
|
-
await subAgentMetadataStore.finish(spawnId, 'error', {
|
|
243
|
-
durationMs,
|
|
244
|
-
error: errMsg,
|
|
245
|
-
}).catch(() => {});
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
agentName: this.config.name,
|
|
249
|
-
content: `[Error: ${errMsg}]`,
|
|
250
|
-
metadata: {
|
|
251
|
-
durationMs,
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Execute tool calls, feed results back to LLM, return final response.
|
|
259
|
-
*/
|
|
260
|
-
private async executeToolCallsAndRespond(
|
|
261
|
-
toolCalls: ToolCall[],
|
|
262
|
-
messages: Message[],
|
|
263
|
-
tools: ToolDefinition[] | undefined,
|
|
264
|
-
sessionId: string,
|
|
265
|
-
): Promise<string> {
|
|
266
|
-
if (!this.executionPipeline) {
|
|
267
|
-
return toolCalls.map(tc => `[tool call: ${tc.function.name}]`).join('\n');
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Add assistant message with tool calls
|
|
271
|
-
messages.push({
|
|
272
|
-
role: 'assistant',
|
|
273
|
-
content: '',
|
|
274
|
-
tool_calls: toolCalls,
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// Execute each tool call
|
|
278
|
-
for (const tc of toolCalls) {
|
|
279
|
-
if (tc.type !== 'function') continue;
|
|
280
|
-
|
|
281
|
-
let params: Record<string, unknown>;
|
|
282
|
-
try {
|
|
283
|
-
params = JSON.parse(tc.function.arguments);
|
|
284
|
-
} catch {
|
|
285
|
-
messages.push({
|
|
286
|
-
role: 'tool',
|
|
287
|
-
tool_call_id: tc.id,
|
|
288
|
-
name: tc.function.name,
|
|
289
|
-
content: `Error: Invalid JSON arguments: ${tc.function.arguments}`,
|
|
290
|
-
});
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const pipelineContext: PipelineExecutionContext = {
|
|
295
|
-
sessionId,
|
|
296
|
-
workspaceRoot: process.cwd(),
|
|
297
|
-
permissionMode: this.config.permissionMode || resolvePermissionMode(),
|
|
298
|
-
messageId: tc.id,
|
|
299
|
-
confirmationHandler: this.config.confirmationHandler,
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
const execResult = await this.executionPipeline.execute(
|
|
303
|
-
tc.function.name,
|
|
304
|
-
params,
|
|
305
|
-
pipelineContext,
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
messages.push({
|
|
309
|
-
role: 'tool',
|
|
310
|
-
tool_call_id: tc.id,
|
|
311
|
-
name: tc.function.name,
|
|
312
|
-
content: execResult.llmContent || execResult.displayContent || '',
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Get final response from LLM after tool execution
|
|
317
|
-
try {
|
|
318
|
-
const final = await this.chatService.chat(messages, tools);
|
|
319
|
-
return final.content || '';
|
|
320
|
-
} catch {
|
|
321
|
-
return toolCalls.map(tc => `[${tc.function.name}: executed]`).join('\n');
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Publish result to shared memory bus.
|
|
327
|
-
*/
|
|
328
|
-
private async publishResult(
|
|
329
|
-
task: string,
|
|
330
|
-
content: string,
|
|
331
|
-
tokensUsed: number | undefined,
|
|
332
|
-
startTime: number,
|
|
333
|
-
): Promise<void> {
|
|
334
|
-
const channel = this.inferChannel(task, content);
|
|
335
|
-
agentMemoryBus.publish({
|
|
336
|
-
channel,
|
|
337
|
-
sourceAgent: this.config.name,
|
|
338
|
-
sessionId: this.currentSessionId,
|
|
339
|
-
content: content.slice(0, 500),
|
|
340
|
-
importance: content.length > 100 ? 0.7 : 0.4,
|
|
341
|
-
tags: [this.config.role],
|
|
342
|
-
metadata: { tokensUsed, taskLength: task.length },
|
|
343
|
-
}).catch(() => {});
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
private inferChannel(task: string, content: string): import('../../memory/AgentMemoryBus.js').AgentChannel {
|
|
347
|
-
const lowerTask = task.toLowerCase();
|
|
348
|
-
const lowerContent = content.toLowerCase();
|
|
349
|
-
|
|
350
|
-
if (lowerContent.startsWith('[error:')) return 'error';
|
|
351
|
-
if (lowerTask.includes('review') || lowerTask.includes('audit')) return 'decision';
|
|
352
|
-
if (lowerTask.includes('suggest') || lowerTask.includes('recommend')) return 'suggestion';
|
|
353
|
-
if (lowerContent.includes('conclusion') || lowerContent.includes('decided') || lowerContent.includes('recommend'))
|
|
354
|
-
return 'decision';
|
|
355
|
-
if (lowerContent.includes('fact') || lowerContent.includes('found') || lowerContent.includes('discovered'))
|
|
356
|
-
return 'fact';
|
|
357
|
-
if (lowerContent.includes('question') || content.endsWith('?')) return 'question';
|
|
358
|
-
|
|
359
|
-
return 'intermediate';
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// ========== Orchestrator ==========
|
|
364
|
-
|
|
365
|
-
export class OrchestratorAgent {
|
|
366
|
-
private agents: Map<string, SubAgentRunner> = new Map();
|
|
367
|
-
private agentConfigs: Map<string, SubAgentConfig> = new Map();
|
|
368
|
-
private name: string;
|
|
369
|
-
private systemPrompt: string;
|
|
370
|
-
|
|
371
|
-
constructor(name: string, systemPrompt: string) {
|
|
372
|
-
this.name = name;
|
|
373
|
-
this.systemPrompt = systemPrompt;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
registerAgent(config: SubAgentConfig): void {
|
|
377
|
-
if (this.agents.has(config.name)) {
|
|
378
|
-
agentDebug.warn(`Orchestrator: Agent "${config.name}" already registered, overwriting`);
|
|
379
|
-
}
|
|
380
|
-
this.agents.set(config.name, new SubAgentRunner(config));
|
|
381
|
-
this.agentConfigs.set(config.name, config);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
unregisterAgent(name: string): void {
|
|
385
|
-
this.agents.delete(name);
|
|
386
|
-
this.agentConfigs.delete(name);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
getRegisteredAgents(): string[] {
|
|
390
|
-
return Array.from(this.agentConfigs.keys());
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
getAgentConfig(name: string): SubAgentConfig | undefined {
|
|
394
|
-
return this.agentConfigs.get(name);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
async delegate(
|
|
398
|
-
agentName: string,
|
|
399
|
-
task: string,
|
|
400
|
-
context?: TaskDelegation['context'],
|
|
401
|
-
sessionId?: string,
|
|
402
|
-
): Promise<AgentResponse> {
|
|
403
|
-
const runner = this.agents.get(agentName);
|
|
404
|
-
if (!runner) {
|
|
405
|
-
throw new Error(`Orchestrator: Agent "${agentName}" not found. Registered: [${this.getRegisteredAgents().join(', ')}]`);
|
|
406
|
-
}
|
|
407
|
-
return runner.run(task, context, sessionId);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
setSessionId(sessionId: string): void {
|
|
411
|
-
this.name = this.name;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Run multiple tasks in parallel with configurable concurrency.
|
|
416
|
-
* Default concurrency = number of tasks (full parallelism).
|
|
417
|
-
*/
|
|
418
|
-
async delegateParallel(
|
|
419
|
-
delegations: TaskDelegation[],
|
|
420
|
-
concurrency: number = delegations.length,
|
|
421
|
-
sessionId?: string,
|
|
422
|
-
): Promise<AgentResponse[]> {
|
|
423
|
-
if (concurrency <= 0) concurrency = delegations.length;
|
|
424
|
-
|
|
425
|
-
const results: AgentResponse[] = [];
|
|
426
|
-
for (let i = 0; i < delegations.length; i += concurrency) {
|
|
427
|
-
const batch = delegations.slice(i, i + concurrency);
|
|
428
|
-
const batchResults = await Promise.allSettled(
|
|
429
|
-
batch.map(d => this.delegate(d.agentName, d.task, d.context, sessionId))
|
|
430
|
-
);
|
|
431
|
-
for (let j = 0; j < batchResults.length; j++) {
|
|
432
|
-
const r = batchResults[j];
|
|
433
|
-
if (r.status === 'fulfilled') {
|
|
434
|
-
results.push(r.value);
|
|
435
|
-
} else {
|
|
436
|
-
const reason = r.reason instanceof Error ? r.reason.message : String(r.reason);
|
|
437
|
-
agentDebug.error(`[${batch[j].agentName}] delegateParallel unhandled: ${reason}`);
|
|
438
|
-
results.push({
|
|
439
|
-
agentName: batch[j].agentName,
|
|
440
|
-
content: `[Fatal: ${reason}]`,
|
|
441
|
-
metadata: { durationMs: 0 },
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return results;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
async delegateChain(tasks: TaskDelegation[]): Promise<AgentResponse[]> {
|
|
450
|
-
const results: AgentResponse[] = [];
|
|
451
|
-
let previousResults = '';
|
|
452
|
-
|
|
453
|
-
for (const task of tasks) {
|
|
454
|
-
const result = await this.delegate(task.agentName, task.task, {
|
|
455
|
-
...task.context,
|
|
456
|
-
previousResults: previousResults || undefined,
|
|
457
|
-
});
|
|
458
|
-
results.push(result);
|
|
459
|
-
if (result.content) {
|
|
460
|
-
previousResults += `\n[${result.agentName}]:\n${result.content}\n`;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
return results;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Full orchestration: split a complex task into sub-tasks,
|
|
469
|
-
* run them in parallel, then synthesize results.
|
|
470
|
-
*/
|
|
471
|
-
async orchestrate(
|
|
472
|
-
complexTask: string,
|
|
473
|
-
subTasks: Record<string, string>,
|
|
474
|
-
synthesiserName?: string,
|
|
475
|
-
sessionId?: string,
|
|
476
|
-
): Promise<OrchestrationResult> {
|
|
477
|
-
const startTime = Date.now();
|
|
478
|
-
const sid = sessionId || `orchestrate-${Date.now()}`;
|
|
479
|
-
const delegations: TaskDelegation[] = Object.entries(subTasks).map(
|
|
480
|
-
([agentName, task]) => ({
|
|
481
|
-
agentName,
|
|
482
|
-
task: `Task: ${complexTask}\n\nYour assignment:\n${task}`,
|
|
483
|
-
})
|
|
484
|
-
);
|
|
485
|
-
|
|
486
|
-
// Phase 1: Run all sub-agents fully in parallel
|
|
487
|
-
const responses = await this.delegateParallel(delegations, delegations.length, sid);
|
|
488
|
-
|
|
489
|
-
// Phase 2: Synthesize
|
|
490
|
-
const MAX_RESPONSE_CHARS = 2000;
|
|
491
|
-
const synthesiser = synthesiserName || this.getRegisteredAgents()[0];
|
|
492
|
-
const synthesisPrompt = responses
|
|
493
|
-
.map(r => {
|
|
494
|
-
const body = r.content || '(no response)';
|
|
495
|
-
const truncated = body.length > MAX_RESPONSE_CHARS
|
|
496
|
-
? body.slice(0, MAX_RESPONSE_CHARS) + '\n...(truncated)'
|
|
497
|
-
: body;
|
|
498
|
-
return `[${r.agentName}]:\n${truncated}`;
|
|
499
|
-
})
|
|
500
|
-
.join('\n\n---\n\n');
|
|
501
|
-
|
|
502
|
-
let summary = '';
|
|
503
|
-
if (synthesiser && responses.length > 1) {
|
|
504
|
-
try {
|
|
505
|
-
const synthesis = await this.delegate(
|
|
506
|
-
synthesiser,
|
|
507
|
-
`You are a senior technical lead synthesizing analysis from multiple specialist agents.\n\nTask: ${complexTask}\n\nAgent analyses:\n\n${synthesisPrompt}\n\n---\n\nProvide a concise, actionable summary: key findings, recommended approach, and top 3 action items.`,
|
|
508
|
-
undefined,
|
|
509
|
-
sid,
|
|
510
|
-
);
|
|
511
|
-
summary = synthesis.content;
|
|
512
|
-
} catch {
|
|
513
|
-
summary = responses.map(r => `**${r.agentName}**: ${(r.content || '').slice(0, 300)}`).join('\n\n');
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
summary = responses[0]?.content || '';
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
agentMemoryBus.publish({
|
|
520
|
-
channel: 'decision',
|
|
521
|
-
sourceAgent: 'orchestrator',
|
|
522
|
-
sessionId: sid,
|
|
523
|
-
content: `[Orchestration Summary] ${summary.slice(0, 500)}`,
|
|
524
|
-
importance: 0.85,
|
|
525
|
-
tags: ['orchestration', 'summary'],
|
|
526
|
-
metadata: {
|
|
527
|
-
agentsUsed: responses.length,
|
|
528
|
-
totalDurationMs: Date.now() - startTime,
|
|
529
|
-
},
|
|
530
|
-
}).catch(() => {});
|
|
531
|
-
|
|
532
|
-
const totalTokens = responses.reduce(
|
|
533
|
-
(sum, r) => sum + (r.metadata?.tokensUsed || 0),
|
|
534
|
-
0
|
|
535
|
-
);
|
|
536
|
-
|
|
537
|
-
return {
|
|
538
|
-
success: responses.some(r => r.content.length > 0),
|
|
539
|
-
responses,
|
|
540
|
-
summary,
|
|
541
|
-
metadata: {
|
|
542
|
-
agentsUsed: responses.length,
|
|
543
|
-
totalTokens,
|
|
544
|
-
totalDurationMs: Date.now() - startTime,
|
|
545
|
-
},
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// ========== Factory ==========
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* Resolve the user's configured permission mode, falling back to DEFAULT (ask for confirmation).
|
|
554
|
-
*/
|
|
555
|
-
function resolvePermissionMode(): PermissionMode {
|
|
556
|
-
try {
|
|
557
|
-
const mode = configManager.getDefaultPermissionMode();
|
|
558
|
-
switch (mode) {
|
|
559
|
-
case 'autoEdit': return PermissionMode.AUTO_EDIT;
|
|
560
|
-
case 'yolo': return PermissionMode.YOLO;
|
|
561
|
-
case 'plan': return PermissionMode.PLAN;
|
|
562
|
-
default: return PermissionMode.DEFAULT;
|
|
563
|
-
}
|
|
564
|
-
} catch {
|
|
565
|
-
return PermissionMode.DEFAULT;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
export function createDefaultOrchestrator(
|
|
570
|
-
config: AgentConfig
|
|
571
|
-
): OrchestratorAgent {
|
|
572
|
-
const agentConfig = { ...config, timeout: 180000 };
|
|
573
|
-
|
|
574
|
-
const orchestrator = new OrchestratorAgent(
|
|
575
|
-
'AEGIS-Orchestrator',
|
|
576
|
-
'You are AEGIS Orchestrator, coordinating multiple specialist agents. Route tasks optimally.'
|
|
577
|
-
);
|
|
578
|
-
|
|
579
|
-
orchestrator.registerAgent({
|
|
580
|
-
name: 'architect',
|
|
581
|
-
role: 'System Architect',
|
|
582
|
-
systemPrompt: `You are a System Architect. Analyze code structure, dependencies, and design patterns.
|
|
583
|
-
Provide architectural recommendations with specific file paths and refactoring steps.
|
|
584
|
-
Focus on: module boundaries, data flow, API design, scalability. Be concise.
|
|
585
|
-
|
|
586
|
-
You can use Read, Grep, and Glob to explore the codebase.`,
|
|
587
|
-
config: agentConfig,
|
|
588
|
-
tools: ['Read', 'Grep', 'Glob'],
|
|
589
|
-
});
|
|
590
|
-
|
|
591
|
-
orchestrator.registerAgent({
|
|
592
|
-
name: 'implementer',
|
|
593
|
-
role: 'Implementation Engineer',
|
|
594
|
-
systemPrompt: `You are an Implementation Engineer. Write clean, production-ready code.
|
|
595
|
-
Follow existing code patterns. Provide complete code blocks with file paths.
|
|
596
|
-
Focus on: correctness, error handling, TypeScript types, edge cases. Be concise.
|
|
597
|
-
|
|
598
|
-
You can use Read, Grep, Edit, and Write to modify the codebase.`,
|
|
599
|
-
config: agentConfig,
|
|
600
|
-
tools: ['Read', 'Edit', 'Write', 'Grep', 'Glob'],
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
orchestrator.registerAgent({
|
|
604
|
-
name: 'reviewer',
|
|
605
|
-
role: 'Code Reviewer',
|
|
606
|
-
systemPrompt: `You are a Code Reviewer. Review code for bugs, security issues, and style.
|
|
607
|
-
Be critical but constructive. Prioritize correctness and security over style.
|
|
608
|
-
Focus on: logic errors, type safety, error handling, performance, security. Be concise.
|
|
609
|
-
|
|
610
|
-
You can use Read, Grep, and Glob to examine the codebase.`,
|
|
611
|
-
config: agentConfig,
|
|
612
|
-
tools: ['Read', 'Grep', 'Glob'],
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
orchestrator.registerAgent({
|
|
616
|
-
name: 'debugger',
|
|
617
|
-
role: 'Debugging Specialist',
|
|
618
|
-
systemPrompt: `You are a Debugging Specialist. Diagnose errors systematically.
|
|
619
|
-
Formulate hypotheses, test each one, and reason about root causes.
|
|
620
|
-
Focus on: stack traces, error messages, unexpected behavior, reproduction steps. Be concise.
|
|
621
|
-
|
|
622
|
-
You can use Read, Grep, Glob, and Bash to investigate and test hypotheses.`,
|
|
623
|
-
config: agentConfig,
|
|
624
|
-
tools: ['Read', 'Grep', 'Glob', 'Bash'],
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
orchestrator.registerAgent({
|
|
628
|
-
name: 'synthesizer',
|
|
629
|
-
role: 'Technical Lead Synthesizer',
|
|
630
|
-
systemPrompt: `You are a senior technical lead. Given analysis from multiple specialist agents, synthesize their findings into a clear, actionable summary.
|
|
631
|
-
Structure your response as: key findings, recommended approach, top action items.
|
|
632
|
-
Be direct, concrete, and avoid repeating everything the agents said.`,
|
|
633
|
-
config: agentConfig,
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
return orchestrator;
|
|
637
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orchestrator — Multi-agent orchestration system
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { OrchestratorAgent, createDefaultOrchestrator } from './OrchestratorAgent.js';
|
|
6
|
-
export { CouncilAgent } from './CouncilAgent.js';
|
|
7
|
-
export { DiscussionRoom } from './DiscussionRoom.js';
|
|
8
|
-
|
|
9
|
-
export { AppBuilder, runApp, getApp, getRegisteredApps, createBuiltinApps } from './AppBuilder.js';
|
|
10
|
-
export type { AppDefinition, AppRunOptions, AppRunResult } from './AppBuilder.js';
|
|
11
|
-
|
|
12
|
-
export { resolveModelConfig, requireModelConfig, createSubAgentToolkit, createSubAgentChatService, buildSourceContext } from './utils.js';
|
|
13
|
-
export type { ResolvedModelConfig, SubAgentOptions } from './utils.js';
|
|
14
|
-
|
|
15
|
-
export type {
|
|
16
|
-
SubAgentConfig,
|
|
17
|
-
TaskDelegation,
|
|
18
|
-
AgentResponse,
|
|
19
|
-
OrchestrationResult,
|
|
20
|
-
} from './OrchestratorAgent.js';
|
|
21
|
-
|
|
22
|
-
export type {
|
|
23
|
-
DeliberationConfig,
|
|
24
|
-
DeliberationResult,
|
|
25
|
-
VoteResult,
|
|
26
|
-
VoteValue,
|
|
27
|
-
} from './CouncilAgent.js';
|
|
28
|
-
|
|
29
|
-
export type {
|
|
30
|
-
DiscussionConfig,
|
|
31
|
-
DiscussionResult,
|
|
32
|
-
DiscussionFormat,
|
|
33
|
-
DebateRound,
|
|
34
|
-
DebateModelConfig,
|
|
35
|
-
DiscussionEvent,
|
|
36
|
-
DiscussionEventType,
|
|
37
|
-
DiscussionEventHandler,
|
|
38
|
-
} from './DiscussionRoom.js';
|