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,71 +0,0 @@
1
- /**
2
- * Post Hook Stage - PostToolUse Hooks 执行阶段
3
- *
4
- */
5
-
6
- import type { PipelineStage, ToolExecution } from '../types.js';
7
- import { onPostToolUse, onPostToolUseFailure } from '../../../hooks/index.js';
8
-
9
- export class PostHookStage implements PipelineStage {
10
- readonly name = 'postHook';
11
-
12
- async process(execution: ToolExecution): Promise<void> {
13
- const result = execution.getResult();
14
- if (!result) {
15
- return;
16
- }
17
-
18
- const tool = execution._internal.tool;
19
- if (!tool) {
20
- return;
21
- }
22
-
23
- // 复用 PreToolUse 阶段生成
24
- const toolUseId = execution._internal.hookToolUseId || `tool_post_${Date.now()}`;
25
- const sessionId = execution.context.sessionId || 'unknown';
26
- const projectDir = execution.context.workspaceRoot || process.cwd();
27
- const permissionMode = execution.context.permissionMode;
28
-
29
- // 根据执行成
30
- if (result.success) {
31
- // 执
32
- const hookResult = await onPostToolUse(
33
- tool.name,
34
- toolUseId,
35
- execution.params as Record<string, unknown>,
36
- result,
37
- sessionId,
38
- projectDir,
39
- permissionMode
40
- );
41
-
42
- // 处理 Hook 结果:添加额外上下
43
- if (hookResult.additionalContext) {
44
- // 将 Hook 注入的上下文追加
45
- const currentResult = execution.getResult();
46
- if (currentResult) {
47
- currentResult.llmContent += `\n\n[Hook Context]\n${hookResult.additionalContext}`;
48
- }
49
- }
50
-
51
- // 处理 Hook 结果:修改输
52
- if (hookResult.modifiedOutput !== undefined) {
53
- const currentResult = execution.getResult();
54
- if (currentResult) {
55
- currentResult.llmContent = String(hookResult.modifiedOutput);
56
- }
57
- }
58
- } else {
59
- // 执
60
- await onPostToolUseFailure(
61
- tool.name,
62
- toolUseId,
63
- execution.params as Record<string, unknown>,
64
- result.error?.message || 'Unknown error',
65
- sessionId,
66
- projectDir,
67
- permissionMode
68
- );
69
- }
70
- }
71
- }
@@ -1,12 +0,0 @@
1
- /**
2
- *
3
- */
4
-
5
- export { DiscoveryStage } from './DiscoveryStage.js';
6
- export { CacheStage } from './CacheStage.js';
7
- export { PermissionStage } from './PermissionStage.js';
8
- export { HookStage } from './HookStage.js';
9
- export { ConfirmationStage } from './ConfirmationStage.js';
10
- export { ExecutionStage } from './ExecutionStage.js';
11
- export { PostHookStage } from './PostHookStage.js';
12
- export { FormattingStage } from './FormattingStage.js';
@@ -1,266 +0,0 @@
1
- /**
2
- *
3
- *
4
- *
5
- */
6
-
7
- import { ExecutionPipeline, PermissionMode, type PipelineExecutionContext } from './index.js';
8
- import { ToolRegistry, createToolRegistry, getBuiltinTools } from '../index.js';
9
- import { PermissionChecker } from '../validation/PermissionChecker.js';
10
- import { SensitiveFileDetector, SensitivityLevel } from '../validation/SensitiveFileDetector.js';
11
- import * as fs from 'fs/promises';
12
- import * as path from 'path';
13
- import * as os from 'os';
14
-
15
- // ========== 测试辅
16
-
17
- let testDir: string;
18
-
19
- async function setup() {
20
- testDir = path.join(os.tmpdir(), `pipeline-test-${Date.now()}`);
21
- await fs.mkdir(testDir, { recursive: true });
22
-
23
- // 创建测试文
24
- await fs.writeFile(path.join(testDir, 'test.txt'), 'Hello, World!');
25
- await fs.writeFile(path.join(testDir, 'config.json'), '{"key": "value"}');
26
- }
27
-
28
- async function cleanup() {
29
- try {
30
- await fs.rm(testDir, { recursive: true, force: true });
31
- } catch {
32
- // Ignore cleanup errors
33
- }
34
- }
35
-
36
- function createTestContext(mode: PermissionMode = PermissionMode.DEFAULT): PipelineExecutionContext {
37
- return {
38
- sessionId: 'test-session',
39
- workspaceRoot: testDir,
40
- permissionMode: mode,
41
- };
42
- }
43
-
44
- // ========== 测
45
-
46
- async function testPermissionChecker() {
47
- console.log('\n1. 测试 PermissionChecker');
48
-
49
- const checker = new PermissionChecker({
50
- allow: ['Bash(npm:*)'],
51
- deny: ['Bash(rm -rf:*)'],
52
- });
53
-
54
- // 测试 allow 规
55
- const allowResult = checker.check({
56
- toolName: 'Bash',
57
- params: { command: 'npm test' },
58
- });
59
- console.log(` npm test: ${allowResult.result} (expected: allow)`);
60
-
61
- // 测试 deny 规
62
- const denyResult = checker.check({
63
- toolName: 'Bash',
64
- params: { command: 'rm -rf /' },
65
- });
66
- console.log(` rm -rf: ${denyResult.result} (expected: deny)`);
67
-
68
- // 测试默
69
- const askResult = checker.check({
70
- toolName: 'Write',
71
- params: { file_path: '/tmp/test.txt' },
72
- });
73
- console.log(` Write: ${askResult.result} (expected: ask)`);
74
- }
75
-
76
- async function testSensitiveFileDetector() {
77
- console.log('\n2. 测试 SensitiveFileDetector');
78
-
79
- // 高敏
80
- const envResult = SensitiveFileDetector.check('.env');
81
- console.log(` .env: ${envResult.level} (expected: high)`);
82
-
83
- // 中敏
84
- const logResult = SensitiveFileDetector.check('app.log');
85
- console.log(` app.log: ${logResult.level} (expected: medium)`);
86
-
87
- // 低敏
88
- const configResult = SensitiveFileDetector.check('config.json');
89
- console.log(` config.json: ${configResult.level} (expected: low)`);
90
-
91
- // 非敏
92
- const normalResult = SensitiveFileDetector.check('main.ts');
93
- console.log(` main.ts: sensitive=${normalResult.sensitive} (expected: false)`);
94
-
95
- // 危险路
96
- const dangerous = SensitiveFileDetector.isDangerousPath('/etc/passwd');
97
- console.log(` /etc/passwd: dangerous=${dangerous} (expected: true)`);
98
- }
99
-
100
- async function testPipelineReadOnly() {
101
- console.log('\n3. 测试只读工具执行');
102
-
103
- const registry = createToolRegistry();
104
- const builtinTools = getBuiltinTools();
105
- for (const tool of builtinTools) {
106
- registry.register(tool);
107
- }
108
-
109
- const pipeline = new ExecutionPipeline(registry);
110
- const context = createTestContext();
111
-
112
- // 测试 Read 工
113
- const testFile = path.join(testDir, 'test.txt');
114
- const readResult = await pipeline.execute('Read', { file_path: testFile }, context);
115
- console.log(` Read: success=${readResult.success}, content includes 'Hello'=${readResult.llmContent.includes('Hello')}`);
116
-
117
- // 测试 Glob 工
118
- const globResult = await pipeline.execute('Glob', { pattern: '*.txt', path: testDir }, context);
119
- console.log(` Glob: success=${globResult.success}, found files=${globResult.llmContent.includes('test.txt')}`);
120
- }
121
-
122
- async function testPermissionModes() {
123
- console.log('\n4. 测试权限模式');
124
-
125
- const registry = createToolRegistry();
126
- const builtinTools = getBuiltinTools();
127
- for (const tool of builtinTools) {
128
- registry.register(tool);
129
- }
130
-
131
- const pipeline = new ExecutionPipeline(registry);
132
- const testFile = path.join(testDir, 'write-test.txt');
133
-
134
- // PLAN 模式:Write 应该被拒
135
- const planContext = createTestContext(PermissionMode.PLAN);
136
- const planResult = await pipeline.execute(
137
- 'Write',
138
- { file_path: testFile, contents: 'test' },
139
- planContext
140
- );
141
- console.log(` PLAN + Write: success=${planResult.success} (expected: false)`);
142
-
143
- // YOLO 模式:Write 应该自动批
144
- const yoloContext = createTestContext(PermissionMode.YOLO);
145
- const yoloResult = await pipeline.execute(
146
- 'Write',
147
- { file_path: testFile, contents: 'YOLO test' },
148
- yoloContext
149
- );
150
- console.log(` YOLO + Write: success=${yoloResult.success} (expected: true)`);
151
-
152
- // 验证文件内
153
- const content = await fs.readFile(testFile, 'utf8');
154
- console.log(` File content correct: ${content === 'YOLO test'}`);
155
- }
156
-
157
- async function testPipelineStages() {
158
- console.log('\n5. 测试管道阶段事件');
159
-
160
- const registry = createToolRegistry();
161
- const builtinTools = getBuiltinTools();
162
- for (const tool of builtinTools) {
163
- registry.register(tool);
164
- }
165
-
166
- const pipeline = new ExecutionPipeline(registry);
167
- const context = createTestContext(PermissionMode.YOLO);
168
-
169
- const stagesExecuted = pipeline.getStageNames();
170
-
171
- const testFile = path.join(testDir, 'test.txt');
172
- await pipeline.execute('Read', { file_path: testFile }, context);
173
-
174
- console.log(` Stages: ${stagesExecuted.join(' → ')}`);
175
- console.log(` All ${stagesExecuted.length} stages executed: ${stagesExecuted.length === 8}`);
176
- }
177
-
178
- async function testExecutionHistory() {
179
- console.log('\n6. 测试执行历史');
180
-
181
- const registry = createToolRegistry();
182
- const builtinTools = getBuiltinTools();
183
- for (const tool of builtinTools) {
184
- registry.register(tool);
185
- }
186
-
187
- const pipeline = new ExecutionPipeline(registry);
188
- const context = createTestContext(PermissionMode.YOLO);
189
-
190
- // 执行几个操
191
- const testFile = path.join(testDir, 'test.txt');
192
- await pipeline.execute('Read', { file_path: testFile }, context);
193
- await pipeline.execute('Glob', { pattern: '*', path: testDir }, context);
194
-
195
- const history = pipeline.getHistory();
196
- console.log(` History entries: ${history.length} (expected: 2)`);
197
- console.log(` First entry tool: ${history[0]?.toolName} (expected: Read)`);
198
- }
199
-
200
- async function testSessionApprovals() {
201
- console.log('\n7. 测试会话批准');
202
-
203
- const registry = createToolRegistry();
204
- const builtinTools = getBuiltinTools();
205
- for (const tool of builtinTools) {
206
- registry.register(tool);
207
- }
208
-
209
- const pipeline = new ExecutionPipeline(registry);
210
-
211
- // 手动添加会话批
212
- pipeline.addSessionApproval('Write(/tmp/approved.txt)');
213
-
214
- console.log(` Has approval: ${pipeline.hasSessionApproval('Write(/tmp/approved.txt)')} (expected: true)`);
215
- console.log(` No approval: ${pipeline.hasSessionApproval('Write(/tmp/other.txt)')} (expected: false)`);
216
-
217
- // 清
218
- pipeline.clearSessionApprovals();
219
- console.log(` After clear: ${pipeline.hasSessionApproval('Write(/tmp/approved.txt)')} (expected: false)`);
220
- }
221
-
222
- async function testBashTool() {
223
- console.log('\n8. 测试 Bash 工具');
224
-
225
- const registry = createToolRegistry();
226
- const builtinTools = getBuiltinTools();
227
- for (const tool of builtinTools) {
228
- registry.register(tool);
229
- }
230
-
231
- const pipeline = new ExecutionPipeline(registry);
232
- const context = createTestContext(PermissionMode.YOLO);
233
-
234
- // 简单命
235
- const echoResult = await pipeline.execute(
236
- 'Bash',
237
- { command: 'echo "Pipeline Test"' },
238
- context
239
- );
240
- console.log(` echo: success=${echoResult.success}, output includes 'Pipeline Test'=${echoResult.llmContent.includes('Pipeline Test')}`);
241
- }
242
-
243
- // ========== 主函
244
-
245
- async function main() {
246
- console.log('=== 执行管道测试 ===');
247
-
248
- try {
249
- await setup();
250
-
251
- await testPermissionChecker();
252
- await testSensitiveFileDetector();
253
- await testPipelineReadOnly();
254
- await testPermissionModes();
255
- await testPipelineStages();
256
- await testExecutionHistory();
257
- await testSessionApprovals();
258
- await testBashTool();
259
-
260
- console.log('\n=== 测试完成 ===');
261
- } finally {
262
- await cleanup();
263
- }
264
- }
265
-
266
- main().catch(console.error);
@@ -1,273 +0,0 @@
1
- /**
2
- *
3
- */
4
-
5
- import type { Tool, ToolResult, ToolInvocation } from '../types.js';
6
-
7
- // ========== 权限模
8
-
9
- /**
10
- *
11
- */
12
- export enum PermissionMode {
13
- /** 默认模式:写操作需确认 */
14
- DEFAULT = 'default',
15
- /** 自动批准编辑 */
16
- AUTO_EDIT = 'autoEdit',
17
- /** 自动批准所有 */
18
- YOLO = 'yolo',
19
- /** 只读调研模式 */
20
- PLAN = 'plan',
21
- }
22
-
23
- // ========== 权限检
24
-
25
- /**
26
- *
27
- */
28
- export enum PermissionResult {
29
- ALLOW = 'allow',
30
- ASK = 'ask',
31
- DENY = 'deny',
32
- }
33
-
34
- /**
35
- *
36
- */
37
- export interface PermissionCheckResult {
38
- result: PermissionResult;
39
- matchedRule?: string;
40
- reason?: string;
41
- }
42
-
43
- /**
44
- *
45
- */
46
- export interface PermissionConfig {
47
- allow: string[];
48
- deny: string[];
49
- ask: string[];
50
- }
51
-
52
- /**
53
- *
54
- */
55
- export interface ToolInvocationDescriptor {
56
- toolName: string;
57
- params: Record<string, unknown>;
58
- affectedPaths?: string[];
59
- tool?: Tool;
60
- }
61
-
62
- // ========== 确认机
63
-
64
- /**
65
- *
66
- */
67
- export interface ConfirmationDetails {
68
- title: string;
69
- message: string;
70
- details?: string;
71
- risks?: string[];
72
- affectedFiles?: string[];
73
- }
74
-
75
- /**
76
- *
77
- */
78
- export interface ConfirmationResponse {
79
- approved: boolean;
80
- reason?: string;
81
- scope?: 'once' | 'session';
82
- }
83
-
84
- /**
85
- *
86
- */
87
- export interface ConfirmationHandler {
88
- requestConfirmation(details: ConfirmationDetails): Promise<ConfirmationResponse>;
89
- }
90
-
91
- // ========== 执行上下
92
-
93
- /**
94
- *
95
- */
96
- export interface PipelineExecutionContext {
97
- sessionId: string;
98
- workspaceRoot: string;
99
- permissionMode: PermissionMode;
100
- signal?: AbortSignal;
101
- onProgress?: (progress: ToolProgress) => void;
102
- confirmationHandler?: ConfirmationHandler;
103
- messageId?: string;
104
- /** Per-model setting: false skips confirmation prompts entirely. Defaults to true. */
105
- requireConfirmation?: boolean;
106
- }
107
-
108
- /**
109
- *
110
- */
111
- export interface ToolProgress {
112
- stage: string;
113
- message: string;
114
- percent?: number;
115
- }
116
-
117
- // ========== 工具执
118
-
119
- /**
120
- *
121
- */
122
- export interface ToolExecutionInternal {
123
- tool?: Tool;
124
- invocation?: ToolInvocation;
125
- needsConfirmation?: boolean;
126
- confirmationReason?: string;
127
- permissionSignature?: string;
128
- hookToolUseId?: string;
129
- /**
130
- * Set when the command pilots another terminal session (tmux send-keys,
131
- * screen -X stuff, etc.) — a vector for a model to mutate shared state
132
- * (config.json, files) by typing into a second instance's stdin as if it
133
- * were a real user, bypassing both per-model requireConfirmation and any
134
- * session "always allow" approval. When true, ConfirmationStage must show
135
- * the prompt regardless of either.
136
- */
137
- forceConfirmation?: boolean;
138
-
139
- /** Cache key set by CacheStage — ExecutionStage uses it to store results */
140
- cacheKey?: string;
141
- }
142
-
143
- /**
144
- *
145
- */
146
- export class ToolExecution {
147
- private result?: ToolResult;
148
- private aborted = false;
149
- private abortReason?: string;
150
-
151
- readonly _internal: ToolExecutionInternal = {};
152
-
153
- constructor(
154
- public readonly toolName: string,
155
- public params: Record<string, unknown>,
156
- public readonly context: PipelineExecutionContext
157
- ) {}
158
-
159
- /**
160
- *
161
- */
162
- abort(reason: string): void {
163
- this.aborted = true;
164
- this.abortReason = reason;
165
- }
166
-
167
- /**
168
- *
169
- */
170
- isAborted(): boolean {
171
- return this.aborted;
172
- }
173
-
174
- /**
175
- *
176
- */
177
- getAbortReason(): string | undefined {
178
- return this.abortReason;
179
- }
180
-
181
- /**
182
- *
183
- */
184
- setResult(result: ToolResult): void {
185
- this.result = result;
186
- }
187
-
188
- /**
189
- *
190
- */
191
- getResult(): ToolResult | undefined {
192
- return this.result;
193
- }
194
- }
195
-
196
- // ========== 管道阶
197
-
198
- /**
199
- *
200
- */
201
- export interface PipelineStage {
202
- readonly name: string;
203
- process(execution: ToolExecution): Promise<void>;
204
- }
205
-
206
- // ========== 管道配
207
-
208
- /**
209
- *
210
- */
211
- export interface ExecutionPipelineConfig {
212
- permissions?: PermissionConfig;
213
- defaultMode?: PermissionMode;
214
- /** Per-model allowed tools — overrides global whitelist for the current model */
215
- allowedTools?: string[];
216
- /** Per-model disallowed tools — overrides global blacklist for the current model */
217
- disallowedTools?: string[];
218
- }
219
-
220
- // ========== 执行历
221
-
222
- /**
223
- *
224
- */
225
- export interface ExecutionHistoryEntry {
226
- toolName: string;
227
- params: Record<string, unknown>;
228
- result: ToolResult;
229
- timestamp: number;
230
- duration: number;
231
- permissionMode: PermissionMode;
232
- stages: string[];
233
- }
234
-
235
- // ========== Hook 相
236
-
237
- /**
238
- * Pre-Tool Hook 结果
239
- */
240
- export interface PreToolHookResult {
241
- decision: 'allow' | 'ask' | 'deny';
242
- modifiedInput?: Record<string, unknown>;
243
- reason?: string;
244
- warning?: string;
245
- }
246
-
247
- /**
248
- * Post-Tool Hook 参数
249
- */
250
- export interface PostToolHookParams {
251
- toolName: string;
252
- params: Record<string, unknown>;
253
- result?: ToolResult;
254
- context: PipelineExecutionContext;
255
- }
256
-
257
- // ========== 管道事
258
-
259
- /**
260
- *
261
- */
262
- export interface StageStartEvent {
263
- stage: string;
264
- execution: ToolExecution;
265
- }
266
-
267
- /**
268
- *
269
- */
270
- export interface StageCompleteEvent {
271
- stage: string;
272
- execution: ToolExecution;
273
- }
@@ -1,81 +0,0 @@
1
- /**
2
- *
3
- */
4
-
5
- // 类
6
- export {
7
- ToolKind,
8
- ToolErrorType,
9
- } from './types.js';
10
-
11
- export type {
12
- Tool,
13
- ToolResult,
14
- ToolError,
15
- ToolDescription,
16
- ToolExample,
17
- ExecutionContext,
18
- FunctionDeclaration,
19
- ToolInvocation,
20
- } from './types.js';
21
-
22
- // 工厂函
23
- export { createTool } from './createTool.js';
24
- export type { ToolConfig } from './createTool.js';
25
-
26
- // Schema
27
- export { ToolSchemas, optional } from './schemas.js';
28
-
29
- // 注册
30
- export { ToolRegistry, createToolRegistry } from './registry.js';
31
-
32
- // 注册表事
33
- export type { ToolRegisteredEvent } from './registry.js';
34
-
35
- // 内置工
36
- export {
37
- readTool,
38
- editTool,
39
- writeTool,
40
- grepTool,
41
- bashTool,
42
- getBuiltinTools,
43
- } from './builtin/index.js';
44
-
45
- // 执行管
46
- export {
47
- ExecutionPipeline,
48
- PermissionMode,
49
- PermissionResult,
50
- ToolExecution,
51
- } from './execution/index.js';
52
-
53
- export type {
54
- ExecutionPipelineEvents,
55
- PipelineStage,
56
- PipelineExecutionContext,
57
- ExecutionPipelineConfig,
58
- ExecutionHistoryEntry,
59
- PermissionCheckResult,
60
- PermissionConfig,
61
- ToolInvocationDescriptor,
62
- ConfirmationDetails,
63
- ConfirmationResponse,
64
- ConfirmationHandler,
65
- ToolProgress,
66
- PreToolHookResult,
67
- PostToolHookParams,
68
- } from './execution/index.js';
69
-
70
- // 验
71
- export {
72
- PermissionChecker,
73
- DEFAULT_PERMISSION_CONFIG,
74
- SensitiveFileDetector,
75
- SensitivityLevel,
76
- } from './validation/index.js';
77
-
78
- export type {
79
- SensitivityResult,
80
- SensitivityResultWithPath,
81
- } from './validation/index.js';