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,300 +0,0 @@
1
- /**
2
- *
3
- *
4
- *
5
- */
6
-
7
- import { nanoid } from 'nanoid';
8
- import type { Message } from '../agent/types.js';
9
- import type { CompactionOptions, CompactionResult, FileContent } from './types.js';
10
- import { TokenCounter } from './TokenCounter.js';
11
- import { FileAnalyzer } from './FileAnalyzer.js';
12
- import { onCompaction } from '../hooks/index.js';
13
-
14
- export class CompactionService {
15
- /** 压缩阈值百分比(80%) */
16
- private static readonly THRESHOLD_PERCENT = 0.8;
17
- /** 保留比例(20%) */
18
- private static readonly RETAIN_PERCENT = 0.2;
19
- /** 降级时保留比例(30%) */
20
- private static readonly FALLBACK_RETAIN_PERCENT = 0.3;
21
-
22
- /**
23
- *
24
- */
25
- static shouldCompact(
26
- messages: Message[],
27
- modelName: string,
28
- maxContextTokens: number
29
- ): boolean {
30
- return TokenCounter.shouldCompact(
31
- messages,
32
- modelName,
33
- maxContextTokens,
34
- this.THRESHOLD_PERCENT
35
- );
36
- }
37
-
38
- /**
39
- *
40
- */
41
- static async compact(
42
- messages: Message[],
43
- options: CompactionOptions
44
- ): Promise<CompactionResult> {
45
- const preTokens = options.actualPreTokens
46
- ?? TokenCounter.countTokens(messages, options.modelName);
47
-
48
- // 执行 Compaction Hook - 检查是否应该阻止压
49
- const shouldPrevent = await onCompaction(
50
- preTokens,
51
- messages.length,
52
- options.sessionId || 'unknown',
53
- options.projectDir || process.cwd()
54
- );
55
-
56
- if (shouldPrevent) {
57
- console.log('[CompactionService] 压缩被 Hook 阻止');
58
- return {
59
- success: false,
60
- summary: '',
61
- preTokens,
62
- postTokens: preTokens,
63
- filesIncluded: [],
64
- compactedMessages: messages,
65
- error: 'Compaction prevented by hook',
66
- };
67
- }
68
-
69
- try {
70
- console.log('[CompactionService] 开始压缩,消息数:', messages.length);
71
-
72
- // 1. 分析并读取重点文
73
- const fileRefs = FileAnalyzer.analyzeFiles(messages);
74
- const filePaths = fileRefs.map(f => f.path);
75
- const fileContents = await FileAnalyzer.readFilesContent(filePaths);
76
-
77
- // 2. 调用 LLM 生成总
78
- const summary = await this.generateSummary(messages, fileContents, options);
79
-
80
- // 3. 计算保留范围并过滤孤儿 tool 消
81
- const retainCount = Math.ceil(messages.length * this.RETAIN_PERCENT);
82
- const candidateMessages = messages.slice(-retainCount);
83
- const retainedMessages = this.filterOrphanToolMessages(candidateMessages);
84
-
85
- // 4. 创建压缩消
86
- const summaryMessage = this.createSummaryMessage(nanoid(), summary);
87
- const compactedMessages = [summaryMessage, ...retainedMessages];
88
-
89
- const postTokens = TokenCounter.countTokens(compactedMessages, options.modelName);
90
-
91
- console.log(`[CompactionService] Token 变化: ${preTokens} → ${postTokens}`);
92
-
93
- return {
94
- success: true,
95
- summary,
96
- preTokens,
97
- postTokens,
98
- filesIncluded: filePaths,
99
- compactedMessages,
100
- };
101
- } catch (error) {
102
- // 降级策略:简单截
103
- return this.fallbackCompact(messages, options, preTokens, error);
104
- }
105
- }
106
-
107
- /**
108
- *
109
- */
110
- private static async generateSummary(
111
- messages: Message[],
112
- fileContents: FileContent[],
113
- options: CompactionOptions
114
- ): Promise<string> {
115
- const prompt = this.buildCompactionPrompt(messages, fileContents);
116
-
117
- // 如果提供了 chatService,使用它来生成总
118
- if (options.chatService && typeof (options.chatService as any).chat === 'function') {
119
- try {
120
- const response = await (options.chatService as any).chat([
121
- { role: 'system', content: 'You are a helpful assistant that creates concise summaries.' },
122
- { role: 'user', content: prompt },
123
- ]);
124
- return response.content || this.createFallbackSummary(messages);
125
- } catch (error) {
126
- console.warn('[CompactionService] LLM 调用失败,使用回退总结', error);
127
- return this.createFallbackSummary(messages);
128
- }
129
- }
130
-
131
- // 没有 chatService,使用简单的摘
132
- return this.createFallbackSummary(messages);
133
- }
134
-
135
- /**
136
- *
137
- */
138
- private static buildCompactionPrompt(
139
- messages: Message[],
140
- fileContents: FileContent[]
141
- ): string {
142
- // 格式化消息历
143
- const messagesText = messages.map((msg, i) => {
144
- const role = msg.role || 'unknown';
145
- const content = typeof msg.content === 'string'
146
- ? msg.content
147
- : JSON.stringify(msg.content);
148
-
149
- // 截断过长消
150
- const maxLength = 5000;
151
- const truncated = content.length > maxLength
152
- ? content.substring(0, maxLength) + '...'
153
- : content;
154
-
155
- return `[${i + 1}] ${role}: ${truncated}`;
156
- }).join('\n\n');
157
-
158
- // 格式化文件内
159
- const filesText = fileContents.map(file =>
160
- `### ${file.path}\n\`\`\`\n${file.content}\n\`\`\``
161
- ).join('\n\n');
162
-
163
- return `Your task is to create a detailed summary of the conversation so far. This summary will be used as context for continuing the conversation, so it's important to preserve key information.
164
-
165
- ## Conversation History
166
- ${messagesText}
167
-
168
- ${fileContents.length > 0 ? `## Important Files\n\n${filesText}` : ''}
169
-
170
- Please provide your summary following this structure:
171
-
172
- 1. **Primary Request and Intent** - What is the user trying to accomplish?
173
- 2. **Key Technical Concepts** - Important technical details, patterns, or decisions
174
- 3. **Files and Code Sections** - Key files mentioned or modified
175
- 4. **Errors and Fixes** - Any issues encountered and how they were resolved
176
- 5. **Problem Solving** - Approach taken to solve problems
177
- 6. **All User Messages** - Brief summary of what the user asked
178
- 7. **Pending Tasks** - Any incomplete work or next steps
179
- 8. **Current Work** - What was being worked on most recently
180
- 9. **Optional Next Step** - Suggested next action
181
-
182
- Keep the summary concise but comprehensive. Focus on information that would be needed to continue the work.`;
183
- }
184
-
185
- /**
186
- *
187
- */
188
- private static createFallbackSummary(messages: Message[]): string {
189
- const userMessages = messages.filter(m => m.role === 'user');
190
- const assistantMessages = messages.filter(m => m.role === 'assistant');
191
- const toolCalls = messages.filter(m => m.role === 'tool' || (m.tool_calls && m.tool_calls.length > 0));
192
-
193
- const userSummary = userMessages.slice(-5).map(m => {
194
- const content = typeof m.content === 'string' ? m.content : JSON.stringify(m.content);
195
- return `- ${content.substring(0, 200)}${content.length > 200 ? '...' : ''}`;
196
- }).join('\n');
197
-
198
- return `## Conversation Summary (Auto-generated)
199
-
200
- ### Statistics
201
- - Total messages: ${messages.length}
202
- - User messages: ${userMessages.length}
203
- - Assistant messages: ${assistantMessages.length}
204
- - Tool interactions: ${toolCalls.length}
205
-
206
- ### Recent User Requests
207
- ${userSummary || '(No user messages)'}
208
-
209
- ### Note
210
- This is an automatically generated summary. Some context may have been lost.
211
- The conversation can continue normally.`;
212
- }
213
-
214
- /**
215
- *
216
- */
217
- private static filterOrphanToolMessages(messages: Message[]): Message[] {
218
- // 收集保留消息中所有 tool_call
219
- const availableToolCallIds = new Set<string>();
220
- for (const msg of messages) {
221
- if (msg.role === 'assistant' && msg.tool_calls) {
222
- for (const tc of msg.tool_calls) {
223
- if (tc.id) {
224
- availableToolCallIds.add(tc.id);
225
- }
226
- }
227
- }
228
- }
229
-
230
- // 过滤孤儿 tool 消
231
- return messages.filter(msg => {
232
- if (msg.role === 'tool' && msg.tool_call_id) {
233
- return availableToolCallIds.has(msg.tool_call_id);
234
- }
235
- return true;
236
- });
237
- }
238
-
239
- /**
240
- *
241
- */
242
- private static createSummaryMessage(id: string, summary: string): Message {
243
- return {
244
- role: 'user',
245
- content: `[Previous conversation summary]\n\n${summary}\n\n[End of summary - conversation continues below]`,
246
- };
247
- }
248
-
249
- /**
250
- *
251
- */
252
- private static fallbackCompact(
253
- messages: Message[],
254
- options: CompactionOptions,
255
- preTokens: number,
256
- error: unknown
257
- ): CompactionResult {
258
- console.warn('[CompactionService] 使用降级策略', error);
259
-
260
- // 保留 30% 的最近消
261
- const retainCount = Math.ceil(messages.length * this.FALLBACK_RETAIN_PERCENT);
262
- const candidateMessages = messages.slice(-retainCount);
263
- const retainedMessages = this.filterOrphanToolMessages(candidateMessages);
264
-
265
- const errorMsg = error instanceof Error ? error.message : String(error);
266
- const summaryMessage = this.createSummaryMessage(
267
- nanoid(),
268
- `[Automatic compaction failed; using fallback]
269
-
270
- An error occurred during compaction. Retained the latest ${retainCount} messages (~30%).
271
-
272
- Error: ${errorMsg}
273
-
274
- The conversation can continue, but consider retrying compaction later with /compact.`
275
- );
276
-
277
- const compactedMessages = [summaryMessage, ...retainedMessages];
278
- const postTokens = TokenCounter.countTokens(compactedMessages, options.modelName);
279
-
280
- return {
281
- success: false,
282
- summary: typeof summaryMessage.content === 'string' ? summaryMessage.content : '',
283
- preTokens,
284
- postTokens,
285
- filesIncluded: [],
286
- compactedMessages,
287
- error: errorMsg,
288
- };
289
- }
290
-
291
- /**
292
- *
293
- */
294
- static async forceCompact(
295
- messages: Message[],
296
- options: Omit<CompactionOptions, 'trigger'>
297
- ): Promise<CompactionResult> {
298
- return this.compact(messages, { ...options, trigger: 'auto' });
299
- }
300
- }