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,251 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CustomCommandLoader - 自定义命令加载器
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* - 解析 YAML Frontmatter
|
|
6
|
-
* - 提取命令内容
|
|
7
|
-
* - 支持多目录扫描
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import * as os from 'os';
|
|
13
|
-
import type {
|
|
14
|
-
CustomCommand,
|
|
15
|
-
CustomCommandConfig,
|
|
16
|
-
CustomCommandSource,
|
|
17
|
-
CustomCommandSourceDir,
|
|
18
|
-
CustomCommandDiscoveryResult,
|
|
19
|
-
} from '../types.js';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
interface CommandDirectory {
|
|
25
|
-
path: string;
|
|
26
|
-
source: CustomCommandSource;
|
|
27
|
-
sourceDir: CustomCommandSourceDir;
|
|
28
|
-
priority: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
export class CustomCommandLoader {
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
async discover(workspaceRoot: string): Promise<CustomCommandDiscoveryResult> {
|
|
39
|
-
const commands: CustomCommand[] = [];
|
|
40
|
-
const warnings: string[] = [];
|
|
41
|
-
const scannedDirs: string[] = [];
|
|
42
|
-
|
|
43
|
-
// 定义扫描目录(按优先级排序,后面的覆盖前面
|
|
44
|
-
const directories: CommandDirectory[] = [
|
|
45
|
-
// 用户级命令(最低优先
|
|
46
|
-
{
|
|
47
|
-
path: path.join(os.homedir(), '.aegis', 'commands'),
|
|
48
|
-
source: 'user',
|
|
49
|
-
sourceDir: 'aegis',
|
|
50
|
-
priority: 1,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
path: path.join(os.homedir(), '.claude', 'commands'),
|
|
54
|
-
source: 'user',
|
|
55
|
-
sourceDir: 'claude',
|
|
56
|
-
priority: 2,
|
|
57
|
-
},
|
|
58
|
-
// 项目级命令(最高优先
|
|
59
|
-
{
|
|
60
|
-
path: path.join(workspaceRoot, '.aegis', 'commands'),
|
|
61
|
-
source: 'project',
|
|
62
|
-
sourceDir: 'aegis',
|
|
63
|
-
priority: 3,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
path: path.join(workspaceRoot, '.claude', 'commands'),
|
|
67
|
-
source: 'project',
|
|
68
|
-
sourceDir: 'claude',
|
|
69
|
-
priority: 4,
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
// 扫描每个目
|
|
74
|
-
for (const dir of directories) {
|
|
75
|
-
if (!fs.existsSync(dir.path)) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
scannedDirs.push(dir.path);
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
const discovered = await this.scanDirectory(dir.path, dir.source, dir.sourceDir);
|
|
83
|
-
commands.push(...discovered.commands);
|
|
84
|
-
warnings.push(...discovered.warnings);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
warnings.push(`扫描目录失败 ${dir.path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return { commands, warnings, scannedDirs };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
private async scanDirectory(
|
|
97
|
-
dirPath: string,
|
|
98
|
-
source: CustomCommandSource,
|
|
99
|
-
sourceDir: CustomCommandSourceDir,
|
|
100
|
-
namespace?: string
|
|
101
|
-
): Promise<{ commands: CustomCommand[]; warnings: string[] }> {
|
|
102
|
-
const commands: CustomCommand[] = [];
|
|
103
|
-
const warnings: string[] = [];
|
|
104
|
-
|
|
105
|
-
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
106
|
-
|
|
107
|
-
for (const entry of entries) {
|
|
108
|
-
const fullPath = path.join(dirPath, entry.name);
|
|
109
|
-
|
|
110
|
-
if (entry.isDirectory()) {
|
|
111
|
-
// 递归扫描子目录(创建命名空
|
|
112
|
-
const subNamespace = namespace ? `${namespace}/${entry.name}` : entry.name;
|
|
113
|
-
const subResult = await this.scanDirectory(fullPath, source, sourceDir, subNamespace);
|
|
114
|
-
commands.push(...subResult.commands);
|
|
115
|
-
warnings.push(...subResult.warnings);
|
|
116
|
-
} else if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
117
|
-
// 加载 Markdown 命令文
|
|
118
|
-
try {
|
|
119
|
-
const command = await this.loadCommandFile(fullPath, source, sourceDir, namespace);
|
|
120
|
-
if (command) {
|
|
121
|
-
commands.push(command);
|
|
122
|
-
}
|
|
123
|
-
} catch (error) {
|
|
124
|
-
warnings.push(`加载命令失败 ${fullPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { commands, warnings };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
*/
|
|
135
|
-
private async loadCommandFile(
|
|
136
|
-
filePath: string,
|
|
137
|
-
source: CustomCommandSource,
|
|
138
|
-
sourceDir: CustomCommandSourceDir,
|
|
139
|
-
namespace?: string
|
|
140
|
-
): Promise<CustomCommand | null> {
|
|
141
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
142
|
-
const { config, body } = this.parseFrontmatter(content);
|
|
143
|
-
|
|
144
|
-
// 从文件名提取命令
|
|
145
|
-
const fileName = path.basename(filePath, '.md');
|
|
146
|
-
const name = fileName.toLowerCase();
|
|
147
|
-
|
|
148
|
-
// 跳过空内
|
|
149
|
-
if (!body.trim()) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
name,
|
|
155
|
-
namespace,
|
|
156
|
-
config,
|
|
157
|
-
content: body,
|
|
158
|
-
path: filePath,
|
|
159
|
-
source,
|
|
160
|
-
sourceDir,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
*
|
|
166
|
-
*/
|
|
167
|
-
private parseFrontmatter(content: string): { config: CustomCommandConfig; body: string } {
|
|
168
|
-
const frontmatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
|
|
169
|
-
const match = content.match(frontmatterRegex);
|
|
170
|
-
|
|
171
|
-
if (!match) {
|
|
172
|
-
return { config: {}, body: content };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const [, frontmatter, body] = match;
|
|
176
|
-
const config = this.parseYamlSimple(frontmatter);
|
|
177
|
-
|
|
178
|
-
return { config, body };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
*
|
|
183
|
-
*/
|
|
184
|
-
private parseYamlSimple(yaml: string): CustomCommandConfig {
|
|
185
|
-
const config: CustomCommandConfig = {};
|
|
186
|
-
const lines = yaml.split('\n');
|
|
187
|
-
|
|
188
|
-
let currentKey: string | null = null;
|
|
189
|
-
let arrayBuffer: string[] = [];
|
|
190
|
-
let inArray = false;
|
|
191
|
-
|
|
192
|
-
for (const line of lines) {
|
|
193
|
-
const trimmed = line.trim();
|
|
194
|
-
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
195
|
-
|
|
196
|
-
// 数组
|
|
197
|
-
if (trimmed.startsWith('- ')) {
|
|
198
|
-
if (inArray && currentKey) {
|
|
199
|
-
arrayBuffer.push(trimmed.slice(2).trim());
|
|
200
|
-
}
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// 保存之前的数
|
|
205
|
-
if (inArray && currentKey && arrayBuffer.length > 0) {
|
|
206
|
-
(config as any)[this.toCamelCase(currentKey)] = arrayBuffer;
|
|
207
|
-
arrayBuffer = [];
|
|
208
|
-
inArray = false;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// 键值
|
|
212
|
-
const colonIndex = trimmed.indexOf(':');
|
|
213
|
-
if (colonIndex !== -1) {
|
|
214
|
-
const key = trimmed.slice(0, colonIndex).trim();
|
|
215
|
-
const value = trimmed.slice(colonIndex + 1).trim();
|
|
216
|
-
|
|
217
|
-
currentKey = key;
|
|
218
|
-
|
|
219
|
-
if (value === '') {
|
|
220
|
-
// 可能是数组开
|
|
221
|
-
inArray = true;
|
|
222
|
-
arrayBuffer = [];
|
|
223
|
-
} else {
|
|
224
|
-
// 普通
|
|
225
|
-
const camelKey = this.toCamelCase(key);
|
|
226
|
-
if (value === 'true') {
|
|
227
|
-
(config as any)[camelKey] = true;
|
|
228
|
-
} else if (value === 'false') {
|
|
229
|
-
(config as any)[camelKey] = false;
|
|
230
|
-
} else {
|
|
231
|
-
(config as any)[camelKey] = value;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// 处理最后的数
|
|
238
|
-
if (inArray && currentKey && arrayBuffer.length > 0) {
|
|
239
|
-
(config as any)[this.toCamelCase(currentKey)] = arrayBuffer;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return config;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
*
|
|
247
|
-
*/
|
|
248
|
-
private toCamelCase(str: string): string {
|
|
249
|
-
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
250
|
-
}
|
|
251
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CustomCommandRegistry - 自定义命令注册中心
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
CustomCommand,
|
|
9
|
-
CustomCommandExecutionContext,
|
|
10
|
-
CustomCommandDiscoveryResult,
|
|
11
|
-
} from '../types.js';
|
|
12
|
-
import { CustomCommandLoader } from './CustomCommandLoader.js';
|
|
13
|
-
import { CustomCommandExecutor } from './CustomCommandExecutor.js';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
export class CustomCommandRegistry {
|
|
19
|
-
private static instance: CustomCommandRegistry;
|
|
20
|
-
|
|
21
|
-
private commands: Map<string, CustomCommand> = new Map();
|
|
22
|
-
private loader = new CustomCommandLoader();
|
|
23
|
-
private executor = new CustomCommandExecutor();
|
|
24
|
-
private initialized = false;
|
|
25
|
-
|
|
26
|
-
private constructor() {}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
static getInstance(): CustomCommandRegistry {
|
|
32
|
-
if (!CustomCommandRegistry.instance) {
|
|
33
|
-
CustomCommandRegistry.instance = new CustomCommandRegistry();
|
|
34
|
-
}
|
|
35
|
-
return CustomCommandRegistry.instance;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
async initialize(workspaceRoot: string): Promise<CustomCommandDiscoveryResult> {
|
|
42
|
-
const result = await this.loader.discover(workspaceRoot);
|
|
43
|
-
|
|
44
|
-
// 清空现有命
|
|
45
|
-
this.commands.clear();
|
|
46
|
-
|
|
47
|
-
// 按顺序注册(后面的覆盖前面的同名命
|
|
48
|
-
for (const cmd of result.commands) {
|
|
49
|
-
const key = this.getCommandKey(cmd.name, cmd.namespace);
|
|
50
|
-
this.commands.set(key, cmd);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.initialized = true;
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
isInitialized(): boolean {
|
|
61
|
-
return this.initialized;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
getCommand(name: string, namespace?: string): CustomCommand | undefined {
|
|
68
|
-
// 先尝试带命名空
|
|
69
|
-
if (namespace) {
|
|
70
|
-
const key = this.getCommandKey(name, namespace);
|
|
71
|
-
const cmd = this.commands.get(key);
|
|
72
|
-
if (cmd) return cmd;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 再尝试不带命名空
|
|
76
|
-
return this.commands.get(name);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
*
|
|
81
|
-
*/
|
|
82
|
-
getAllCommands(): CustomCommand[] {
|
|
83
|
-
return Array.from(this.commands.values());
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* - 有 description
|
|
91
|
-
* - 没有设置 disableModelInvocation: true
|
|
92
|
-
*/
|
|
93
|
-
getModelInvocableCommands(): CustomCommand[] {
|
|
94
|
-
return this.getAllCommands().filter(
|
|
95
|
-
(cmd) => cmd.config.description && !cmd.config.disableModelInvocation
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
*/
|
|
102
|
-
async executeCommand(
|
|
103
|
-
name: string,
|
|
104
|
-
context: CustomCommandExecutionContext,
|
|
105
|
-
namespace?: string
|
|
106
|
-
): Promise<string | null> {
|
|
107
|
-
const cmd = this.getCommand(name, namespace);
|
|
108
|
-
if (!cmd) return null;
|
|
109
|
-
|
|
110
|
-
return this.executor.execute(cmd, context);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*/
|
|
119
|
-
getCommandLabel(cmd: CustomCommand): string {
|
|
120
|
-
const base = cmd.source === 'project' ? 'project' : 'user';
|
|
121
|
-
return cmd.namespace ? `(${base}:${cmd.namespace})` : `(${base})`;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
private getCommandKey(name: string, namespace?: string): string {
|
|
128
|
-
return namespace ? `${namespace}/${name}` : name;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
*
|
|
133
|
-
*/
|
|
134
|
-
async reload(workspaceRoot: string): Promise<CustomCommandDiscoveryResult> {
|
|
135
|
-
return this.initialize(workspaceRoot);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
get size(): number {
|
|
142
|
-
return this.commands.size;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* /debate — Multi-model debate & discussion command
|
|
3
|
-
*
|
|
4
|
-
* Launches a structured debate/discussion between multiple configured models.
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* /debate "React vs SolidJS" --models gpt-4o,deepseek --rounds 3
|
|
8
|
-
* /debate "Ska vi använda microservices?" (auto-picks all available models)
|
|
9
|
-
* /debate "What's the best testing strategy?" --format qa --models gpt-4o,claude-sonnet-4
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { SlashCommand, SlashCommandResult, SlashCommandContext } from './types.js';
|
|
13
|
-
import type { AgentConfig } from '../agent/types.js';
|
|
14
|
-
import { DiscussionRoom, type DiscussionFormat, type DebateModelConfig } from '../agent/orchestrator/DiscussionRoom.js';
|
|
15
|
-
import type { DiscussionResult } from '../agent/orchestrator/DiscussionRoom.js';
|
|
16
|
-
import { configManager } from '../config/index.js';
|
|
17
|
-
import type { ModelConfig } from '../config/types.js';
|
|
18
|
-
|
|
19
|
-
// ── Helpers ───────────────────────────────────────────────────────────────────────
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Resolve model configs from arguments, falling back to all configured models.
|
|
23
|
-
*/
|
|
24
|
-
function resolveModels(modelArg: string | undefined): { models: DebateModelConfig[]; errors: string[] } {
|
|
25
|
-
const cfg = configManager.getConfig();
|
|
26
|
-
const allModels: ModelConfig[] = cfg.models || [];
|
|
27
|
-
const errors: string[] = [];
|
|
28
|
-
|
|
29
|
-
if (modelArg) {
|
|
30
|
-
// Specific models requested: comma-separated IDs
|
|
31
|
-
const ids = modelArg.split(',').map(s => s.trim().toLowerCase());
|
|
32
|
-
const selected: DebateModelConfig[] = [];
|
|
33
|
-
|
|
34
|
-
for (const id of ids) {
|
|
35
|
-
const found = allModels.find(m =>
|
|
36
|
-
m.id?.toLowerCase() === id ||
|
|
37
|
-
m.model?.toLowerCase() === id ||
|
|
38
|
-
m.name?.toLowerCase() === id
|
|
39
|
-
);
|
|
40
|
-
if (found) {
|
|
41
|
-
selected.push(modelConfigToDebateModel(found));
|
|
42
|
-
} else {
|
|
43
|
-
errors.push(`Model "${id}" not found in config. Use /model list to see available models.`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return { models: selected, errors };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// No specific models: use all non-Anthropic models (Anthropic often rate-limited for multi-call)
|
|
51
|
-
// Filter to models that have apiKey configured
|
|
52
|
-
const configured = allModels.filter(m => m.apiKey && m.apiKey.length > 0);
|
|
53
|
-
|
|
54
|
-
if (configured.length === 0) {
|
|
55
|
-
return { models: [], errors: ['No configured models found. Add models with /model add or check your config.'] };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Take up to 4 models to avoid excessive API cost
|
|
59
|
-
const selected = configured.slice(0, 4).map(modelConfigToDebateModel);
|
|
60
|
-
return { models: selected, errors: [] };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function modelConfigToDebateModel(mc: ModelConfig): DebateModelConfig {
|
|
64
|
-
return {
|
|
65
|
-
name: mc.name || mc.id || mc.model || 'Unknown',
|
|
66
|
-
config: {
|
|
67
|
-
apiKey: mc.apiKey || '',
|
|
68
|
-
baseURL: mc.baseURL,
|
|
69
|
-
model: mc.model,
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function parseArgs(args: string): {
|
|
75
|
-
topic: string;
|
|
76
|
-
models?: string;
|
|
77
|
-
rounds: number;
|
|
78
|
-
format: DiscussionFormat;
|
|
79
|
-
} {
|
|
80
|
-
const trimmed = args.trim();
|
|
81
|
-
let topic = trimmed;
|
|
82
|
-
let modelsArg: string | undefined;
|
|
83
|
-
let rounds = 2;
|
|
84
|
-
let format: DiscussionFormat = 'debate';
|
|
85
|
-
|
|
86
|
-
// Parse --models flag
|
|
87
|
-
const modelsMatch = trimmed.match(/--models\s+(\S+)/);
|
|
88
|
-
if (modelsMatch) {
|
|
89
|
-
modelsArg = modelsMatch[1];
|
|
90
|
-
topic = topic.replace(/--models\s+\S+/g, '').trim();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Parse --rounds flag
|
|
94
|
-
const roundsMatch = trimmed.match(/--rounds\s+(\d+)/);
|
|
95
|
-
if (roundsMatch) {
|
|
96
|
-
rounds = parseInt(roundsMatch[1], 10);
|
|
97
|
-
if (rounds < 1) rounds = 1;
|
|
98
|
-
if (rounds > 5) rounds = 5;
|
|
99
|
-
topic = topic.replace(/--rounds\s+\d+/g, '').trim();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Parse --format flag
|
|
103
|
-
const formatMatch = trimmed.match(/--format\s+(\w+)/);
|
|
104
|
-
if (formatMatch) {
|
|
105
|
-
const valid: DiscussionFormat[] = ['debate', 'discussion', 'qa', 'panel'];
|
|
106
|
-
const f = formatMatch[1].toLowerCase() as DiscussionFormat;
|
|
107
|
-
if (valid.includes(f)) {
|
|
108
|
-
format = f;
|
|
109
|
-
}
|
|
110
|
-
topic = topic.replace(/--format\s+\w+/g, '').trim();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Strip quotes around topic
|
|
114
|
-
topic = topic.replace(/^["']|["']$/g, '').trim();
|
|
115
|
-
|
|
116
|
-
if (!topic) {
|
|
117
|
-
throw new Error('Usage: /debate <topic> [--models id1,id2] [--rounds N] [--format debate|discussion|qa|panel]');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return { topic, models: modelsArg, rounds, format };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// ── Command ───────────────────────────────────────────────────────────────────────
|
|
124
|
-
|
|
125
|
-
export const debateCommand: SlashCommand = {
|
|
126
|
-
name: 'debate',
|
|
127
|
-
aliases: ['db'],
|
|
128
|
-
description: 'Multi-model debate — pítch models against each other on a topic',
|
|
129
|
-
category: 'general',
|
|
130
|
-
usage: '/debate <topic> [--models id1,id2] [--rounds N] [--format debate|discussion|qa|panel]',
|
|
131
|
-
examples: [
|
|
132
|
-
'/debate React vs SolidJS --models gpt-4o,deepseek-chat',
|
|
133
|
-
'/debate "Should we use microservices?" --rounds 3',
|
|
134
|
-
'/debate "What is the best testing strategy?" --format qa',
|
|
135
|
-
'/debate "Future of AI coding assistants" --format panel --models gpt-4o,claude-sonnet-4,gemini-2.5-pro',
|
|
136
|
-
],
|
|
137
|
-
fullDescription: `Run a structured debate or discussion between multiple AI models.
|
|
138
|
-
|
|
139
|
-
Each model takes turns responding, seeing all previous responses.
|
|
140
|
-
Results are streamed in real-time via the chat interface.
|
|
141
|
-
|
|
142
|
-
Formats:
|
|
143
|
-
debate — Models argue opposing positions (default)
|
|
144
|
-
discussion — Collaborative exploration of a topic
|
|
145
|
-
qa — Models answer a question from their perspective
|
|
146
|
-
panel — Expert panel discussion with moderator-style prompts
|
|
147
|
-
|
|
148
|
-
Flags:
|
|
149
|
-
--models Comma-separated model IDs (default: all configured models, max 4)
|
|
150
|
-
--rounds Number of rounds (1-5, default 2)
|
|
151
|
-
--format Debate format (debate, discussion, qa, panel)`,
|
|
152
|
-
async handler(args: string, context: SlashCommandContext): Promise<SlashCommandResult> {
|
|
153
|
-
try {
|
|
154
|
-
const parsed = parseArgs(args);
|
|
155
|
-
const resolved = resolveModels(parsed.models);
|
|
156
|
-
|
|
157
|
-
if (resolved.models.length === 0) {
|
|
158
|
-
const error = resolved.errors.join('\n') || 'No models could be resolved.';
|
|
159
|
-
return { success: false, type: 'error', content: error };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (resolved.errors.length > 0) {
|
|
163
|
-
// Non-fatal: some models not found, but we have some
|
|
164
|
-
if (context.onContentDelta) {
|
|
165
|
-
context.onContentDelta(`*Note: ${resolved.errors.join('; ')}*\n\n`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Build the discussion room
|
|
170
|
-
const room = new DiscussionRoom({
|
|
171
|
-
topic: parsed.topic,
|
|
172
|
-
models: resolved.models,
|
|
173
|
-
rounds: parsed.rounds,
|
|
174
|
-
format: parsed.format,
|
|
175
|
-
maxTokensPerResponse: 600,
|
|
176
|
-
timeout: 120000,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
// Stream start notification
|
|
180
|
-
const formatIcons: Record<string, string> = {
|
|
181
|
-
debate: '⚖️',
|
|
182
|
-
discussion: '💬',
|
|
183
|
-
qa: '❓',
|
|
184
|
-
panel: '🎙️',
|
|
185
|
-
};
|
|
186
|
-
const icon = formatIcons[parsed.format] || '💬';
|
|
187
|
-
const modelNames = resolved.models.map(m => m.name).join(', ');
|
|
188
|
-
|
|
189
|
-
if (context.onContentDelta) {
|
|
190
|
-
context.onContentDelta(`## ${icon} ${parsed.format.charAt(0).toUpperCase() + parsed.format.slice(1)}: ${parsed.topic}\n\n`);
|
|
191
|
-
context.onContentDelta(`*Models: ${modelNames} · ${parsed.rounds} rounds*\n\n`);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Stream rounds in real-time via event system
|
|
195
|
-
let streamingRound = false;
|
|
196
|
-
|
|
197
|
-
room.on('round:start', (ev) => {
|
|
198
|
-
streamingRound = true;
|
|
199
|
-
if (context.onContentDelta) {
|
|
200
|
-
context.onContentDelta(`### Round ${ev.round}\n\n`);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
room.on('model:start', (ev) => {
|
|
205
|
-
if (context.onContentDelta) {
|
|
206
|
-
const model = resolved.models.find(m => m.name === ev.model);
|
|
207
|
-
const color = model?.color || '';
|
|
208
|
-
context.onContentDelta(`**${color}${ev.model}${color ? '\x1b[0m' : ''}** thinking...\n\n`);
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
room.on('model:complete', (ev) => {
|
|
213
|
-
if (context.onContentDelta) {
|
|
214
|
-
const model = resolved.models.find(m => m.name === ev.model);
|
|
215
|
-
const color = model?.color || '';
|
|
216
|
-
context.onContentDelta(`**${color}${ev.model}${color ? '\x1b[0m' : ''}** · ${ev.metadata?.durationMs ? `_(${(ev.metadata.durationMs as number / 1000).toFixed(1)}s)_` : ''}\n\n`);
|
|
217
|
-
context.onContentDelta(`${ev.content}\n\n`);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
room.on('model:error', (ev) => {
|
|
222
|
-
if (context.onContentDelta) {
|
|
223
|
-
context.onContentDelta(`**${ev.model}** ⚠️ *Failed: ${ev.content}*\n\n`);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
room.on('summary:ready', (ev) => {
|
|
228
|
-
if (context.onContentDelta) {
|
|
229
|
-
context.onContentDelta(`---\n\n### Summary\n\n${ev.content}\n\n`);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
room.on('discussion:complete', (ev) => {
|
|
234
|
-
const meta = ev.metadata as unknown as DiscussionResult['metadata'];
|
|
235
|
-
if (context.onContentDelta) {
|
|
236
|
-
context.onContentDelta(`*${meta.modelsUsed} models · ${meta.totalRounds} rounds · ${(meta.totalDurationMs / 1000).toFixed(1)}s · ${meta.totalTokens.toLocaleString()} tokens*\n`);
|
|
237
|
-
context.onContentDelta(`\n✅ **Debate complete!**\n`);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// Run the debate (events fire during execution via handlers above)
|
|
242
|
-
await room.run();
|
|
243
|
-
|
|
244
|
-
return { success: true, type: 'silent' };
|
|
245
|
-
} catch (error) {
|
|
246
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
247
|
-
return {
|
|
248
|
-
success: false,
|
|
249
|
-
type: 'error',
|
|
250
|
-
error: errMsg,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
};
|