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
package/src/tools/registry.ts
DELETED
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { EventEmitter } from 'events';
|
|
8
|
-
import type { Tool, FunctionDeclaration } from './types.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
export interface ToolRegisteredEvent {
|
|
14
|
-
type: 'builtin' | 'mcp';
|
|
15
|
-
tool: Tool;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export class ToolRegistry extends EventEmitter {
|
|
22
|
-
/** 内置工具 */
|
|
23
|
-
private tools = new Map<string, Tool>();
|
|
24
|
-
|
|
25
|
-
/** MCP 工具 */
|
|
26
|
-
private mcpTools = new Map<string, Tool>();
|
|
27
|
-
|
|
28
|
-
/** 分类索引 */
|
|
29
|
-
private categories = new Map<string, Set<string>>();
|
|
30
|
-
|
|
31
|
-
/** 标签索引 */
|
|
32
|
-
private tagIndex = new Map<string, Set<string>>();
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
register(tool: Tool): void {
|
|
38
|
-
if (this.tools.has(tool.name) || this.mcpTools.has(tool.name)) {
|
|
39
|
-
throw new Error(`工具 '${tool.name}' 已注册`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.tools.set(tool.name, tool);
|
|
43
|
-
this.updateIndexes(tool);
|
|
44
|
-
this.emit('toolRegistered', { type: 'builtin', tool } as ToolRegisteredEvent);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
registerMcpTool(tool: Tool): void {
|
|
51
|
-
if (this.tools.has(tool.name) || this.mcpTools.has(tool.name)) {
|
|
52
|
-
throw new Error(`工具 '${tool.name}' 已注册`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this.mcpTools.set(tool.name, tool);
|
|
56
|
-
this.updateIndexes(tool);
|
|
57
|
-
this.emit('toolRegistered', { type: 'mcp', tool } as ToolRegisteredEvent);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
*/
|
|
63
|
-
registerMcpTools(tools: Tool[]): void {
|
|
64
|
-
for (const tool of tools) {
|
|
65
|
-
this.registerMcpTool(tool);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
unregisterMcpTool(name: string): boolean {
|
|
73
|
-
const tool = this.mcpTools.get(name);
|
|
74
|
-
if (!tool) return false;
|
|
75
|
-
|
|
76
|
-
this.mcpTools.delete(name);
|
|
77
|
-
this.removeFromIndexes(tool);
|
|
78
|
-
this.emit('toolUnregistered', { type: 'mcp', tool });
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
clearMcpTools(): void {
|
|
86
|
-
for (const tool of this.mcpTools.values()) {
|
|
87
|
-
this.removeFromIndexes(tool);
|
|
88
|
-
}
|
|
89
|
-
this.mcpTools.clear();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
*/
|
|
95
|
-
registerAll(tools: Tool[]): void {
|
|
96
|
-
for (const tool of tools) {
|
|
97
|
-
this.register(tool);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
*
|
|
103
|
-
*/
|
|
104
|
-
get(name: string): Tool | undefined {
|
|
105
|
-
return this.tools.get(name) || this.mcpTools.get(name);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
|
-
has(name: string): boolean {
|
|
112
|
-
return this.tools.has(name) || this.mcpTools.has(name);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
*/
|
|
118
|
-
getAll(): Tool[] {
|
|
119
|
-
return [...this.tools.values(), ...this.mcpTools.values()];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
-
*/
|
|
125
|
-
getBuiltinTools(): Tool[] {
|
|
126
|
-
return [...this.tools.values()];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
*
|
|
131
|
-
*/
|
|
132
|
-
getMcpTools(): Tool[] {
|
|
133
|
-
return [...this.mcpTools.values()];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
*
|
|
138
|
-
*/
|
|
139
|
-
getNames(): string[] {
|
|
140
|
-
return [...this.tools.keys(), ...this.mcpTools.keys()];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
*/
|
|
146
|
-
getReadOnlyTools(): Tool[] {
|
|
147
|
-
return this.getAll().filter(tool => tool.isReadOnly);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
*
|
|
152
|
-
*/
|
|
153
|
-
getWriteTools(): Tool[] {
|
|
154
|
-
return this.getAll().filter(tool => !tool.isReadOnly);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
*
|
|
159
|
-
*/
|
|
160
|
-
getByCategory(category: string): Tool[] {
|
|
161
|
-
const names = this.categories.get(category);
|
|
162
|
-
if (!names) return [];
|
|
163
|
-
return [...names].map(name => this.tools.get(name)!).filter(Boolean);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
*
|
|
168
|
-
*/
|
|
169
|
-
getByTag(tag: string): Tool[] {
|
|
170
|
-
const names = this.tagIndex.get(tag);
|
|
171
|
-
if (!names) return [];
|
|
172
|
-
return [...names].map(name => this.tools.get(name)!).filter(Boolean);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
*
|
|
177
|
-
*/
|
|
178
|
-
getCategories(): string[] {
|
|
179
|
-
return [...this.categories.keys()];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
*
|
|
184
|
-
*/
|
|
185
|
-
getTags(): string[] {
|
|
186
|
-
return [...this.tagIndex.keys()];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
*
|
|
191
|
-
*/
|
|
192
|
-
getFunctionDeclarations(): FunctionDeclaration[] {
|
|
193
|
-
return this.getAll().map(tool => tool.getFunctionDeclaration());
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
*
|
|
198
|
-
*/
|
|
199
|
-
getFunctionDeclarationsByMode(mode?: string): FunctionDeclaration[] {
|
|
200
|
-
if (mode === 'plan') {
|
|
201
|
-
// Plan 模式只返回只读工
|
|
202
|
-
return this.getReadOnlyTools().map(t => t.getFunctionDeclaration());
|
|
203
|
-
}
|
|
204
|
-
return this.getFunctionDeclarations();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
*
|
|
209
|
-
*/
|
|
210
|
-
search(query: string): Tool[] {
|
|
211
|
-
const lowerQuery = query.toLowerCase();
|
|
212
|
-
return this.getAll().filter(tool =>
|
|
213
|
-
tool.name.toLowerCase().includes(lowerQuery) ||
|
|
214
|
-
tool.displayName.toLowerCase().includes(lowerQuery) ||
|
|
215
|
-
tool.description.short.toLowerCase().includes(lowerQuery)
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
*
|
|
221
|
-
*/
|
|
222
|
-
get size(): number {
|
|
223
|
-
return this.tools.size + this.mcpTools.size;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
*
|
|
228
|
-
*/
|
|
229
|
-
get builtinSize(): number {
|
|
230
|
-
return this.tools.size;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
*
|
|
235
|
-
*/
|
|
236
|
-
get mcpSize(): number {
|
|
237
|
-
return this.mcpTools.size;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
*
|
|
242
|
-
*/
|
|
243
|
-
clear(): void {
|
|
244
|
-
this.tools.clear();
|
|
245
|
-
this.mcpTools.clear();
|
|
246
|
-
this.categories.clear();
|
|
247
|
-
this.tagIndex.clear();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
*
|
|
252
|
-
*/
|
|
253
|
-
private updateIndexes(tool: Tool): void {
|
|
254
|
-
// 更新分类索
|
|
255
|
-
if (tool.category) {
|
|
256
|
-
if (!this.categories.has(tool.category)) {
|
|
257
|
-
this.categories.set(tool.category, new Set());
|
|
258
|
-
}
|
|
259
|
-
this.categories.get(tool.category)!.add(tool.name);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// 更新标签索
|
|
263
|
-
for (const tag of tool.tags) {
|
|
264
|
-
if (!this.tagIndex.has(tag)) {
|
|
265
|
-
this.tagIndex.set(tag, new Set());
|
|
266
|
-
}
|
|
267
|
-
this.tagIndex.get(tag)!.add(tool.name);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
*
|
|
273
|
-
*/
|
|
274
|
-
private removeFromIndexes(tool: Tool): void {
|
|
275
|
-
// 从分类索引中移
|
|
276
|
-
if (tool.category) {
|
|
277
|
-
const categorySet = this.categories.get(tool.category);
|
|
278
|
-
if (categorySet) {
|
|
279
|
-
categorySet.delete(tool.name);
|
|
280
|
-
if (categorySet.size === 0) {
|
|
281
|
-
this.categories.delete(tool.category);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// 从标签索引中移
|
|
287
|
-
for (const tag of tool.tags) {
|
|
288
|
-
const tagSet = this.tagIndex.get(tag);
|
|
289
|
-
if (tagSet) {
|
|
290
|
-
tagSet.delete(tool.name);
|
|
291
|
-
if (tagSet.size === 0) {
|
|
292
|
-
this.tagIndex.delete(tag);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
*
|
|
301
|
-
*/
|
|
302
|
-
export function createToolRegistry(): ToolRegistry {
|
|
303
|
-
return new ToolRegistry();
|
|
304
|
-
}
|
package/src/tools/schemas.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { z } from 'zod';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export const ToolSchemas = {
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
filePath: (options?: { description?: string }) =>
|
|
17
|
-
z.string()
|
|
18
|
-
.min(1, '文件路径不能为空')
|
|
19
|
-
.describe(options?.description || '文件路径'),
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
absolutePath: (options?: { description?: string }) =>
|
|
25
|
-
z.string()
|
|
26
|
-
.min(1, '路径不能为空')
|
|
27
|
-
.refine(
|
|
28
|
-
(path) => path.startsWith('/') || path.startsWith('~'),
|
|
29
|
-
'必须是绝对路径(以 / 或 ~ 开头)'
|
|
30
|
-
)
|
|
31
|
-
.describe(options?.description || '绝对路径'),
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
lineNumber: (options?: { description?: string }) =>
|
|
37
|
-
z.number()
|
|
38
|
-
.int('必须是整数')
|
|
39
|
-
.min(0, '行号不能为负')
|
|
40
|
-
.describe(options?.description || '行号(从 0 开始)'),
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
lineLimit: (options?: { description?: string; max?: number }) =>
|
|
46
|
-
z.number()
|
|
47
|
-
.int('必须是整数')
|
|
48
|
-
.min(1, '至少读取 1 行')
|
|
49
|
-
.max(options?.max || 10000, `最多读取 ${options?.max || 10000} 行`)
|
|
50
|
-
.describe(options?.description || '读取行数'),
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
encoding: () =>
|
|
56
|
-
z.enum(['utf8', 'utf-8', 'ascii', 'base64', 'binary', 'hex'])
|
|
57
|
-
.default('utf8')
|
|
58
|
-
.describe('文件编码格式'),
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Glob 模式
|
|
62
|
-
*/
|
|
63
|
-
globPattern: (options?: { description?: string }) =>
|
|
64
|
-
z.string()
|
|
65
|
-
.min(1, '模式不能为空')
|
|
66
|
-
.describe(options?.description || 'Glob 匹配模式'),
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
regexPattern: (options?: { description?: string }) =>
|
|
72
|
-
z.string()
|
|
73
|
-
.min(1, '模式不能为空')
|
|
74
|
-
.describe(options?.description || '正则表达式模式'),
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
command: (options?: { description?: string }) =>
|
|
80
|
-
z.string()
|
|
81
|
-
.min(1, '命令不能为空')
|
|
82
|
-
.describe(options?.description || 'Shell 命令'),
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
*/
|
|
87
|
-
timeout: (options?: { max?: number; default?: number }) =>
|
|
88
|
-
z.number()
|
|
89
|
-
.int()
|
|
90
|
-
.min(0)
|
|
91
|
-
.max(options?.max || 600000)
|
|
92
|
-
.default(options?.default || 30000)
|
|
93
|
-
.describe('超时时间(毫秒)'),
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
97
|
-
*/
|
|
98
|
-
booleanWithDefault: (defaultValue: boolean, description?: string) =>
|
|
99
|
-
z.boolean()
|
|
100
|
-
.default(defaultValue)
|
|
101
|
-
.describe(description || '布尔选项'),
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
*
|
|
106
|
-
*/
|
|
107
|
-
export function optional<T extends z.ZodType>(schema: T): z.ZodOptional<T> {
|
|
108
|
-
return schema.optional();
|
|
109
|
-
}
|
package/src/tools/test.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { ToolRegistry, getBuiltinTools, ToolKind, createTool } from './index.js';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
import path from 'path';
|
|
10
|
-
import fs from 'fs/promises';
|
|
11
|
-
import os from 'os';
|
|
12
|
-
|
|
13
|
-
async function testToolSystem() {
|
|
14
|
-
console.log('=== 工具系统测试 ===\n');
|
|
15
|
-
|
|
16
|
-
// 1. 创建注册表并注册内置工
|
|
17
|
-
console.log('1. 创建工具注册表并注册内置工具');
|
|
18
|
-
const registry = new ToolRegistry();
|
|
19
|
-
const builtinTools = getBuiltinTools();
|
|
20
|
-
registry.registerAll(builtinTools);
|
|
21
|
-
console.log(` 已注册 ${registry.size} 个工具: ${registry.getNames().join(', ')}`);
|
|
22
|
-
console.log(` - 内置工具: ${registry.builtinSize}`);
|
|
23
|
-
console.log(` - MCP 工具: ${registry.mcpSize}\n`);
|
|
24
|
-
|
|
25
|
-
// 2. 测试工具获
|
|
26
|
-
console.log('2. 测试工具获取');
|
|
27
|
-
const readTool = registry.get('Read');
|
|
28
|
-
console.log(` Read 工具: ${readTool ? '✅ 存在' : '❌ 不存在'}`);
|
|
29
|
-
console.log(` - 类型: ${readTool?.kind}`);
|
|
30
|
-
console.log(` - 只读: ${readTool?.isReadOnly}`);
|
|
31
|
-
console.log(` - 并发安全: ${readTool?.isConcurrencySafe}`);
|
|
32
|
-
console.log(` - 分类: ${readTool?.category}`);
|
|
33
|
-
console.log(` - 标签: ${readTool?.tags.join(', ')}\n`);
|
|
34
|
-
|
|
35
|
-
// 3. 测试只
|
|
36
|
-
console.log('3. 测试只读/写入工具过滤');
|
|
37
|
-
const readOnlyTools = registry.getReadOnlyTools();
|
|
38
|
-
const writeTools = registry.getWriteTools();
|
|
39
|
-
console.log(` 只读工具: ${readOnlyTools.map(t => t.name).join(', ')}`);
|
|
40
|
-
console.log(` 写入工具: ${writeTools.map(t => t.name).join(', ')}\n`);
|
|
41
|
-
|
|
42
|
-
// 4. 测试函数声明生
|
|
43
|
-
console.log('4. 测试函数声明生成');
|
|
44
|
-
const declarations = registry.getFunctionDeclarations();
|
|
45
|
-
for (const decl of declarations) {
|
|
46
|
-
console.log(` ${decl.name}:`);
|
|
47
|
-
console.log(` 描述: ${decl.description.slice(0, 60)}...`);
|
|
48
|
-
console.log(` 参数: ${Object.keys(decl.parameters.properties || {}).join(', ')}`);
|
|
49
|
-
}
|
|
50
|
-
console.log();
|
|
51
|
-
|
|
52
|
-
// 5. 测试 Plan 模式函数声
|
|
53
|
-
console.log('5. 测试 Plan 模式函数声明');
|
|
54
|
-
const planDeclarations = registry.getFunctionDeclarationsByMode('plan');
|
|
55
|
-
console.log(` Plan 模式工具数: ${planDeclarations.length}`);
|
|
56
|
-
console.log(` Plan 模式工具: ${planDeclarations.map(d => d.name).join(', ')}\n`);
|
|
57
|
-
|
|
58
|
-
// 6. 测试 Read 工具执
|
|
59
|
-
console.log('6. 测试 Read 工具执行');
|
|
60
|
-
if (readTool) {
|
|
61
|
-
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
62
|
-
const result = await readTool.execute({ file_path: packageJsonPath });
|
|
63
|
-
console.log(` 结果: ${result.success ? '✅ 成功' : '❌ 失败'}`);
|
|
64
|
-
console.log(` 显示内容: ${result.displayContent}`);
|
|
65
|
-
console.log(` LLM 内容长度: ${result.llmContent.length} 字符\n`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 7. 测试 Edit 工
|
|
69
|
-
console.log('7. 测试 Edit 工具');
|
|
70
|
-
const editTool = registry.get('Edit');
|
|
71
|
-
if (editTool) {
|
|
72
|
-
// 创建临时文
|
|
73
|
-
const tmpDir = os.tmpdir();
|
|
74
|
-
const testFile = path.join(tmpDir, `aegis-test-${Date.now()}.txt`);
|
|
75
|
-
await fs.writeFile(testFile, 'Hello World\nFoo Bar\n', 'utf8');
|
|
76
|
-
|
|
77
|
-
// 测试编
|
|
78
|
-
const result = await editTool.execute({
|
|
79
|
-
file_path: testFile,
|
|
80
|
-
old_string: 'World',
|
|
81
|
-
new_string: 'AEGIS',
|
|
82
|
-
});
|
|
83
|
-
console.log(` 结果: ${result.success ? '✅ 成功' : '❌ 失败'}`);
|
|
84
|
-
console.log(` 显示内容: ${result.displayContent}`);
|
|
85
|
-
|
|
86
|
-
// 验证内
|
|
87
|
-
const content = await fs.readFile(testFile, 'utf8');
|
|
88
|
-
console.log(` 验证: ${content.includes('AEGIS') ? '✅ 替换正确' : '❌ 替换失败'}`);
|
|
89
|
-
|
|
90
|
-
// 测试多重匹
|
|
91
|
-
await fs.writeFile(testFile, 'AAA BBB AAA', 'utf8');
|
|
92
|
-
const multiResult = await editTool.execute({
|
|
93
|
-
file_path: testFile,
|
|
94
|
-
old_string: 'AAA',
|
|
95
|
-
new_string: 'CCC',
|
|
96
|
-
});
|
|
97
|
-
console.log(` 多重匹配: ${multiResult.success ? '❌ 应该失败' : '✅ 正确拒绝'}`);
|
|
98
|
-
|
|
99
|
-
// 清
|
|
100
|
-
await fs.unlink(testFile);
|
|
101
|
-
console.log();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 8. 测试 Write 工
|
|
105
|
-
console.log('8. 测试 Write 工具');
|
|
106
|
-
const writeTool = registry.get('Write');
|
|
107
|
-
if (writeTool) {
|
|
108
|
-
const tmpDir = os.tmpdir();
|
|
109
|
-
const testFile = path.join(tmpDir, `aegis-write-${Date.now()}.txt`);
|
|
110
|
-
|
|
111
|
-
const result = await writeTool.execute({
|
|
112
|
-
file_path: testFile,
|
|
113
|
-
contents: 'Test content\nLine 2\n',
|
|
114
|
-
});
|
|
115
|
-
console.log(` 结果: ${result.success ? '✅ 成功' : '❌ 失败'}`);
|
|
116
|
-
console.log(` 显示内容: ${result.displayContent}`);
|
|
117
|
-
|
|
118
|
-
// 验
|
|
119
|
-
const exists = await fs.access(testFile).then(() => true).catch(() => false);
|
|
120
|
-
console.log(` 文件存在: ${exists ? '✅ 是' : '❌ 否'}`);
|
|
121
|
-
|
|
122
|
-
// 清
|
|
123
|
-
if (exists) await fs.unlink(testFile);
|
|
124
|
-
console.log();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// 9. 测试 Bash 工
|
|
128
|
-
console.log('9. 测试 Bash 工具');
|
|
129
|
-
const bashTool = registry.get('Bash');
|
|
130
|
-
if (bashTool) {
|
|
131
|
-
const result = await bashTool.execute({
|
|
132
|
-
command: 'echo "Hello from Bash"',
|
|
133
|
-
description: '测试 echo 命令',
|
|
134
|
-
});
|
|
135
|
-
console.log(` 结果: ${result.success ? '✅ 成功' : '❌ 失败'}`);
|
|
136
|
-
console.log(` 显示内容: ${result.displayContent}`);
|
|
137
|
-
console.log(` 输出: ${result.llmContent.trim()}`);
|
|
138
|
-
|
|
139
|
-
// 测试失败命
|
|
140
|
-
const failResult = await bashTool.execute({
|
|
141
|
-
command: 'exit 1',
|
|
142
|
-
});
|
|
143
|
-
console.log(` 失败命令: ${failResult.success ? '❌ 应该失败' : '✅ 正确失败'}\n`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 10. 测试 Glob 工具执
|
|
147
|
-
console.log('10. 测试 Glob 工具执行');
|
|
148
|
-
const globTool = registry.get('Glob');
|
|
149
|
-
if (globTool) {
|
|
150
|
-
const result = await globTool.execute({ pattern: '*.ts', path: path.join(process.cwd(), 'src') });
|
|
151
|
-
console.log(` 结果: ${result.success ? '✅ 成功' : '❌ 失败'}`);
|
|
152
|
-
console.log(` 显示内容: ${result.displayContent}`);
|
|
153
|
-
if (result.metadata?.count) {
|
|
154
|
-
console.log(` 找到文件数: ${result.metadata.count}\n`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// 11. 测试 Grep 工具执
|
|
159
|
-
console.log('11. 测试 Grep 工具执行');
|
|
160
|
-
const grepTool = registry.get('Grep');
|
|
161
|
-
if (grepTool) {
|
|
162
|
-
const result = await grepTool.execute({
|
|
163
|
-
pattern: 'export',
|
|
164
|
-
include: '*.ts',
|
|
165
|
-
path: path.join(process.cwd(), 'src/tools'),
|
|
166
|
-
});
|
|
167
|
-
console.log(` 结果: ${result.success ? '✅ 成功' : '❌ 失败'}`);
|
|
168
|
-
console.log(` 显示内容: ${result.displayContent}`);
|
|
169
|
-
if (result.metadata?.matches) {
|
|
170
|
-
console.log(` 匹配数: ${result.metadata.matches}\n`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// 12. 测试 MCP 工具注
|
|
175
|
-
console.log('12. 测试 MCP 工具注册');
|
|
176
|
-
const mockMcpTool = createTool({
|
|
177
|
-
name: 'MockMcpTool',
|
|
178
|
-
displayName: 'Mock MCP Tool',
|
|
179
|
-
kind: ToolKind.ReadOnly,
|
|
180
|
-
schema: z.object({ input: z.string() }),
|
|
181
|
-
description: { short: 'A mock MCP tool for testing' },
|
|
182
|
-
async execute(params) {
|
|
183
|
-
return {
|
|
184
|
-
success: true,
|
|
185
|
-
llmContent: `Mock result for: ${params.input}`,
|
|
186
|
-
displayContent: '✅ Mock MCP 工具执行成功',
|
|
187
|
-
};
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
registry.registerMcpTool(mockMcpTool);
|
|
192
|
-
console.log(` MCP 工具注册: ✅`);
|
|
193
|
-
console.log(` 总工具数: ${registry.size}`);
|
|
194
|
-
console.log(` MCP 工具数: ${registry.mcpSize}`);
|
|
195
|
-
console.log(` 获取 MCP 工具: ${registry.get('MockMcpTool') ? '✅ 存在' : '❌ 不存在'}`);
|
|
196
|
-
|
|
197
|
-
// 测试注
|
|
198
|
-
registry.unregisterMcpTool('MockMcpTool');
|
|
199
|
-
console.log(` 注销后: ${registry.get('MockMcpTool') ? '❌ 仍存在' : '✅ 已移除'}\n`);
|
|
200
|
-
|
|
201
|
-
// 13. 测试 build 方
|
|
202
|
-
console.log('13. 测试 build 方法');
|
|
203
|
-
if (readTool) {
|
|
204
|
-
const invocation = readTool.build({ file_path: '/test/path.ts' });
|
|
205
|
-
console.log(` 工具名: ${invocation.toolName}`);
|
|
206
|
-
console.log(` 参数: ${JSON.stringify(invocation.params)}\n`);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// 14. 测试参数验
|
|
210
|
-
console.log('14. 测试参数验证');
|
|
211
|
-
if (readTool) {
|
|
212
|
-
const invalidResult = await readTool.execute({ file_path: '' });
|
|
213
|
-
console.log(` 空路径测试: ${invalidResult.success ? '❌ 应该失败' : '✅ 正确失败'}`);
|
|
214
|
-
console.log(` 错误信息: ${invalidResult.displayContent}\n`);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
console.log('=== 测试完成 ===');
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
testToolSystem().catch(console.error);
|