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.
Files changed (209) hide show
  1. package/bin/aegis.js +165 -0
  2. package/package.json +18 -86
  3. package/LICENSE +0 -21
  4. package/README.md +0 -394
  5. package/dist/main.js +0 -2171
  6. package/gui/run-gui.cjs +0 -13
  7. package/src/agent/Agent.ts +0 -903
  8. package/src/agent/SimpleAgent.ts +0 -48
  9. package/src/agent/index.ts +0 -54
  10. package/src/agent/orchestrator/AppBuilder.ts +0 -443
  11. package/src/agent/orchestrator/CouncilAgent.ts +0 -310
  12. package/src/agent/orchestrator/DiscussionRoom.ts +0 -462
  13. package/src/agent/orchestrator/OrchestratorAgent.ts +0 -637
  14. package/src/agent/orchestrator/index.ts +0 -38
  15. package/src/agent/orchestrator/utils.ts +0 -397
  16. package/src/agent/pricing.ts +0 -115
  17. package/src/agent/router.ts +0 -74
  18. package/src/agent/routerStats.ts +0 -121
  19. package/src/agent/types.ts +0 -318
  20. package/src/auth/login.ts +0 -383
  21. package/src/cli/config.ts +0 -189
  22. package/src/cli/index.ts +0 -17
  23. package/src/cli/middleware.ts +0 -119
  24. package/src/cli/types.ts +0 -75
  25. package/src/config/ConfigManager.ts +0 -587
  26. package/src/config/index.ts +0 -7
  27. package/src/config/types.ts +0 -584
  28. package/src/context/CompactionService.ts +0 -300
  29. package/src/context/ContextManager.ts +0 -450
  30. package/src/context/FileAnalyzer.ts +0 -267
  31. package/src/context/TokenCounter.ts +0 -265
  32. package/src/context/index.ts +0 -27
  33. package/src/context/storage/CacheStore.ts +0 -176
  34. package/src/context/storage/JSONLStore.ts +0 -201
  35. package/src/context/storage/MemoryStore.ts +0 -205
  36. package/src/context/storage/PersistentStore.ts +0 -327
  37. package/src/context/storage/index.ts +0 -9
  38. package/src/context/storage/pathUtils.ts +0 -114
  39. package/src/context/test.ts +0 -309
  40. package/src/context/types.ts +0 -268
  41. package/src/hooks/HookExecutor.ts +0 -434
  42. package/src/hooks/HookManager.ts +0 -596
  43. package/src/hooks/HookService.ts +0 -269
  44. package/src/hooks/Matcher.ts +0 -157
  45. package/src/hooks/index.ts +0 -63
  46. package/src/hooks/types.ts +0 -424
  47. package/src/main.tsx +0 -596
  48. package/src/mcp/HealthMonitor.ts +0 -150
  49. package/src/mcp/McpClient.ts +0 -491
  50. package/src/mcp/McpRegistry.ts +0 -321
  51. package/src/mcp/createMcpTool.ts +0 -251
  52. package/src/mcp/index.ts +0 -15
  53. package/src/mcp/server.ts +0 -334
  54. package/src/mcp/test-server.ts +0 -88
  55. package/src/mcp/test.ts +0 -372
  56. package/src/mcp/types.ts +0 -247
  57. package/src/memory/AgentMemoryBus.ts +0 -432
  58. package/src/memory/CloudSync.ts +0 -99
  59. package/src/memory/DriveSync.ts +0 -106
  60. package/src/memory/SharedMemory.ts +0 -951
  61. package/src/memory/index.ts +0 -14
  62. package/src/memory/machineFingerprint.ts +0 -40
  63. package/src/orchestrator/SubAgentMetadata.ts +0 -136
  64. package/src/prompts/builder.ts +0 -213
  65. package/src/prompts/default.ts +0 -144
  66. package/src/prompts/index.ts +0 -16
  67. package/src/prompts/plan.ts +0 -64
  68. package/src/prompts/test.ts +0 -78
  69. package/src/services/AnthropicChatService.ts +0 -341
  70. package/src/services/ChatService.ts +0 -347
  71. package/src/services/ClaudeCliChatService.ts +0 -256
  72. package/src/services/CloudSync.ts +0 -168
  73. package/src/services/CostLedger.ts +0 -211
  74. package/src/services/Heartbeat.ts +0 -135
  75. package/src/services/LearningCollector.ts +0 -291
  76. package/src/services/OllamaInstaller.ts +0 -342
  77. package/src/services/VersionChecker.ts +0 -445
  78. package/src/services/index.ts +0 -57
  79. package/src/services/streaming/OpenAIEventAdapter.ts +0 -126
  80. package/src/services/streaming/RenderingProfile.ts +0 -90
  81. package/src/services/streaming/StreamEventParser.ts +0 -181
  82. package/src/services/streaming/ThrottledRenderer.ts +0 -139
  83. package/src/services/streaming/TranscriptBuffer.ts +0 -574
  84. package/src/services/streaming/eventStatusMap.ts +0 -52
  85. package/src/services/streaming/index.ts +0 -46
  86. package/src/services/streaming/renderFormatting.ts +0 -79
  87. package/src/services/streaming/types.ts +0 -234
  88. package/src/skills/SkillLoader.ts +0 -126
  89. package/src/skills/SkillRegistry.ts +0 -366
  90. package/src/skills/index.ts +0 -48
  91. package/src/skills/types.ts +0 -146
  92. package/src/slash-commands/billing.ts +0 -70
  93. package/src/slash-commands/build.ts +0 -413
  94. package/src/slash-commands/builtinCommands.ts +0 -2733
  95. package/src/slash-commands/clone.ts +0 -242
  96. package/src/slash-commands/council.ts +0 -125
  97. package/src/slash-commands/custom/CustomCommandExecutor.ts +0 -143
  98. package/src/slash-commands/custom/CustomCommandLoader.ts +0 -251
  99. package/src/slash-commands/custom/CustomCommandRegistry.ts +0 -144
  100. package/src/slash-commands/custom/index.ts +0 -7
  101. package/src/slash-commands/debate.ts +0 -254
  102. package/src/slash-commands/gmail.ts +0 -105
  103. package/src/slash-commands/index.ts +0 -388
  104. package/src/slash-commands/mcpCommand.ts +0 -205
  105. package/src/slash-commands/types.ts +0 -201
  106. package/src/store/index.ts +0 -76
  107. package/src/store/selectors.ts +0 -246
  108. package/src/store/slices/appSlice.ts +0 -205
  109. package/src/store/slices/commandSlice.ts +0 -115
  110. package/src/store/slices/configSlice.ts +0 -46
  111. package/src/store/slices/focusSlice.ts +0 -64
  112. package/src/store/slices/index.ts +0 -9
  113. package/src/store/slices/sessionSlice.ts +0 -424
  114. package/src/store/streaming-buffer.ts +0 -425
  115. package/src/store/test.ts +0 -296
  116. package/src/store/types.ts +0 -274
  117. package/src/store/vanilla.ts +0 -186
  118. package/src/tools/builtin/bash.ts +0 -236
  119. package/src/tools/builtin/council.ts +0 -105
  120. package/src/tools/builtin/edit.ts +0 -213
  121. package/src/tools/builtin/glob.ts +0 -136
  122. package/src/tools/builtin/grep.ts +0 -263
  123. package/src/tools/builtin/index.ts +0 -61
  124. package/src/tools/builtin/memory.ts +0 -66
  125. package/src/tools/builtin/read.ts +0 -168
  126. package/src/tools/builtin/skill.ts +0 -97
  127. package/src/tools/builtin/snapshot.ts +0 -40
  128. package/src/tools/builtin/task.ts +0 -106
  129. package/src/tools/builtin/write.ts +0 -134
  130. package/src/tools/createTool.ts +0 -221
  131. package/src/tools/execution/ExecutionPipeline.ts +0 -263
  132. package/src/tools/execution/index.ts +0 -40
  133. package/src/tools/execution/stages/CacheStage.ts +0 -131
  134. package/src/tools/execution/stages/ConfirmationStage.ts +0 -203
  135. package/src/tools/execution/stages/DiscoveryStage.ts +0 -46
  136. package/src/tools/execution/stages/ExecutionStage.ts +0 -48
  137. package/src/tools/execution/stages/FormattingStage.ts +0 -44
  138. package/src/tools/execution/stages/HookStage.ts +0 -72
  139. package/src/tools/execution/stages/PermissionStage.ts +0 -287
  140. package/src/tools/execution/stages/PostHookStage.ts +0 -71
  141. package/src/tools/execution/stages/index.ts +0 -12
  142. package/src/tools/execution/test.ts +0 -266
  143. package/src/tools/execution/types.ts +0 -273
  144. package/src/tools/index.ts +0 -81
  145. package/src/tools/registry.ts +0 -304
  146. package/src/tools/schemas.ts +0 -109
  147. package/src/tools/test.ts +0 -220
  148. package/src/tools/types.ts +0 -175
  149. package/src/tools/validation/PermissionChecker.ts +0 -242
  150. package/src/tools/validation/SensitiveFileDetector.ts +0 -210
  151. package/src/tools/validation/index.ts +0 -11
  152. package/src/ui/App.tsx +0 -166
  153. package/src/ui/components/AegisInterface.tsx +0 -484
  154. package/src/ui/components/common/ChatSearch.tsx +0 -150
  155. package/src/ui/components/common/ErrorBoundary.tsx +0 -82
  156. package/src/ui/components/common/ExitMessage.tsx +0 -120
  157. package/src/ui/components/common/LoadingIndicator.tsx +0 -49
  158. package/src/ui/components/common/index.ts +0 -6
  159. package/src/ui/components/dialog/ConfirmationPrompt.tsx +0 -208
  160. package/src/ui/components/dialog/InteractiveSelector.tsx +0 -149
  161. package/src/ui/components/dialog/SetupWizard.tsx +0 -297
  162. package/src/ui/components/dialog/UpdatePrompt.tsx +0 -155
  163. package/src/ui/components/dialog/index.ts +0 -8
  164. package/src/ui/components/index.ts +0 -28
  165. package/src/ui/components/input/CommandSuggestions.tsx +0 -139
  166. package/src/ui/components/input/CustomTextInput.tsx +0 -220
  167. package/src/ui/components/input/InputArea.tsx +0 -361
  168. package/src/ui/components/input/PromptSuggestions.tsx +0 -66
  169. package/src/ui/components/input/index.ts +0 -6
  170. package/src/ui/components/layout/ChatStatusBar.tsx +0 -90
  171. package/src/ui/components/layout/ContextBar.tsx +0 -79
  172. package/src/ui/components/layout/MessageArea.tsx +0 -96
  173. package/src/ui/components/layout/MessageList.tsx +0 -647
  174. package/src/ui/components/layout/MessageSeparator.tsx +0 -26
  175. package/src/ui/components/layout/WelcomeMessage.tsx +0 -93
  176. package/src/ui/components/layout/index.ts +0 -7
  177. package/src/ui/components/markdown/CodeHighlighter.tsx +0 -292
  178. package/src/ui/components/markdown/MessageRenderer.tsx +0 -1211
  179. package/src/ui/components/markdown/index.ts +0 -8
  180. package/src/ui/components/markdown/parser.ts +0 -336
  181. package/src/ui/components/markdown/types.ts +0 -66
  182. package/src/ui/focus/FocusManager.ts +0 -137
  183. package/src/ui/focus/index.ts +0 -13
  184. package/src/ui/focus/types.ts +0 -54
  185. package/src/ui/focus/useFocus.ts +0 -75
  186. package/src/ui/hooks/index.ts +0 -11
  187. package/src/ui/hooks/useAgent.ts +0 -284
  188. package/src/ui/hooks/useCommandHistory.ts +0 -87
  189. package/src/ui/hooks/useCommandProcessor.ts +0 -443
  190. package/src/ui/hooks/useConfirmation.ts +0 -99
  191. package/src/ui/hooks/useCtrlCHandler.ts +0 -100
  192. package/src/ui/hooks/useInputBuffer.ts +0 -122
  193. package/src/ui/hooks/useTerminalSize.ts +0 -68
  194. package/src/ui/hooks/useTerminalWidth.ts +0 -5
  195. package/src/ui/hooks/useWindowedList.ts +0 -118
  196. package/src/ui/render-debugger.ts +0 -621
  197. package/src/ui/test.ts +0 -189
  198. package/src/ui/themes/ThemeManager.ts +0 -332
  199. package/src/ui/themes/aegisTheme.ts +0 -87
  200. package/src/ui/themes/darkTheme.ts +0 -87
  201. package/src/ui/themes/defaultTheme.ts +0 -85
  202. package/src/ui/themes/index.ts +0 -10
  203. package/src/ui/themes/lightTheme.ts +0 -89
  204. package/src/ui/themes/popularThemes.ts +0 -187
  205. package/src/ui/themes/types.ts +0 -130
  206. package/src/utils/clipboard.ts +0 -48
  207. package/src/utils/debug.ts +0 -43
  208. package/src/utils/environment.ts +0 -68
  209. 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,7 +0,0 @@
1
- /**
2
- *
3
- */
4
-
5
- export { CustomCommandLoader } from './CustomCommandLoader.js';
6
- export { CustomCommandExecutor } from './CustomCommandExecutor.js';
7
- export { CustomCommandRegistry } from './CustomCommandRegistry.js';
@@ -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
- };