aegiscode 3.1.10 → 3.2.0
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-cli-linux-x64 +0 -0
- package/bin/cli.js +68 -0
- package/package.json +11 -48
- package/scripts/download-binary.mjs +155 -0
- 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/types.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// ========== 工具类型枚
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
export enum ToolKind {
|
|
12
|
-
/** 只读操作,无副作用 */
|
|
13
|
-
ReadOnly = 'readonly',
|
|
14
|
-
/** 文件写入操作 */
|
|
15
|
-
Write = 'write',
|
|
16
|
-
/** 命令执行,可能有副作用 */
|
|
17
|
-
Execute = 'execute',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ========== 工具描
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
export interface ToolExample {
|
|
26
|
-
description: string;
|
|
27
|
-
params: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
export interface ToolDescription {
|
|
34
|
-
/** 简短描述(一行) */
|
|
35
|
-
short: string;
|
|
36
|
-
/** 详细说明 */
|
|
37
|
-
long?: string;
|
|
38
|
-
/** 使用注意事项 */
|
|
39
|
-
usageNotes?: string[];
|
|
40
|
-
/** 使用示例 */
|
|
41
|
-
examples?: ToolExample[];
|
|
42
|
-
/** 重要提示 */
|
|
43
|
-
important?: string[];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ========== 工具错
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
*/
|
|
51
|
-
export enum ToolErrorType {
|
|
52
|
-
/** 参数验证错误 */
|
|
53
|
-
VALIDATION_ERROR = 'validation_error',
|
|
54
|
-
/** 执行错误 */
|
|
55
|
-
EXECUTION_ERROR = 'execution_error',
|
|
56
|
-
/** 权限错误 */
|
|
57
|
-
PERMISSION_ERROR = 'permission_error',
|
|
58
|
-
/** 超时错误 */
|
|
59
|
-
TIMEOUT_ERROR = 'timeout_error',
|
|
60
|
-
/** 未知错误 */
|
|
61
|
-
UNKNOWN_ERROR = 'unknown_error',
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
export interface ToolError {
|
|
68
|
-
type: ToolErrorType;
|
|
69
|
-
message: string;
|
|
70
|
-
details?: unknown;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ========== 工具结
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
export interface ToolResult {
|
|
79
|
-
/** 执行是否成功 */
|
|
80
|
-
success: boolean;
|
|
81
|
-
/** 传递给 LLM 的内容(可能很长) */
|
|
82
|
-
llmContent: string;
|
|
83
|
-
/** 显示给用户的内容(简洁摘要) */
|
|
84
|
-
displayContent: string;
|
|
85
|
-
/** 错误信息 */
|
|
86
|
-
error?: ToolError;
|
|
87
|
-
/** 额外元数据 */
|
|
88
|
-
metadata?: Record<string, unknown>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// ========== 执行上下
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
export interface ExecutionContext {
|
|
97
|
-
/** 会话 ID */
|
|
98
|
-
sessionId?: string;
|
|
99
|
-
/** 中断信号 */
|
|
100
|
-
signal?: AbortSignal;
|
|
101
|
-
/** 工作目录 */
|
|
102
|
-
cwd?: string;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ========== 函数声
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* LLM 函数声明(OpenAI 格式)
|
|
109
|
-
*/
|
|
110
|
-
export interface FunctionDeclaration {
|
|
111
|
-
name: string;
|
|
112
|
-
description: string;
|
|
113
|
-
parameters: {
|
|
114
|
-
type: 'object';
|
|
115
|
-
properties: Record<string, unknown>;
|
|
116
|
-
required?: string[];
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ========== 工具调
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
-
*/
|
|
125
|
-
export interface ToolInvocation<TParams = unknown> {
|
|
126
|
-
/** 工具名称 */
|
|
127
|
-
toolName: string;
|
|
128
|
-
/** 参数 */
|
|
129
|
-
params: TParams;
|
|
130
|
-
/** 调用 ID */
|
|
131
|
-
callId?: string;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ========== 工具接
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
*
|
|
138
|
-
*/
|
|
139
|
-
export interface Tool<TParams = unknown> {
|
|
140
|
-
/** 工具唯一名称 */
|
|
141
|
-
readonly name: string;
|
|
142
|
-
/** 显示名称 */
|
|
143
|
-
readonly displayName: string;
|
|
144
|
-
/** 工具类型 */
|
|
145
|
-
readonly kind: ToolKind;
|
|
146
|
-
/** 是否只读 */
|
|
147
|
-
readonly isReadOnly: boolean;
|
|
148
|
-
/** 是否并发安全 */
|
|
149
|
-
readonly isConcurrencySafe: boolean;
|
|
150
|
-
/** 是否启用结构化输出 */
|
|
151
|
-
readonly strict: boolean;
|
|
152
|
-
/** 工具描述 */
|
|
153
|
-
readonly description: ToolDescription;
|
|
154
|
-
/** 版本 */
|
|
155
|
-
readonly version: string;
|
|
156
|
-
/** 分类 */
|
|
157
|
-
readonly category?: string;
|
|
158
|
-
/** 标签 */
|
|
159
|
-
readonly tags: string[];
|
|
160
|
-
|
|
161
|
-
/** 生成 LLM 函数声明 */
|
|
162
|
-
getFunctionDeclaration(): FunctionDeclaration;
|
|
163
|
-
|
|
164
|
-
/** 构建执行实例 */
|
|
165
|
-
build(params: TParams): ToolInvocation<TParams>;
|
|
166
|
-
|
|
167
|
-
/** 执行工具 */
|
|
168
|
-
execute(params: TParams, context?: ExecutionContext): Promise<ToolResult>;
|
|
169
|
-
|
|
170
|
-
/** 提取签名内容(用于权限规则) */
|
|
171
|
-
extractSignatureContent?: (params: unknown) => string;
|
|
172
|
-
|
|
173
|
-
/** 抽象权限规则(用于权限匹配) */
|
|
174
|
-
abstractPermissionRule?: (params: unknown) => string;
|
|
175
|
-
}
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { minimatch } from 'minimatch';
|
|
7
|
-
import {
|
|
8
|
-
PermissionResult,
|
|
9
|
-
type PermissionCheckResult,
|
|
10
|
-
type PermissionConfig,
|
|
11
|
-
type ToolInvocationDescriptor,
|
|
12
|
-
} from '../execution/types.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export const DEFAULT_PERMISSION_CONFIG: PermissionConfig = {
|
|
18
|
-
allow: [
|
|
19
|
-
// 只读工具默认允
|
|
20
|
-
'Read(**/*)',
|
|
21
|
-
'Glob(**/*)',
|
|
22
|
-
'Grep(**/*)',
|
|
23
|
-
],
|
|
24
|
-
deny: [
|
|
25
|
-
// 危险命令默认拒
|
|
26
|
-
'Bash(rm -rf:*)',
|
|
27
|
-
'Bash(sudo:*)',
|
|
28
|
-
'Write(/etc/*)',
|
|
29
|
-
'Write(/usr/*)',
|
|
30
|
-
'Write(/System/*)',
|
|
31
|
-
],
|
|
32
|
-
ask: [],
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
export class PermissionChecker {
|
|
39
|
-
private config: PermissionConfig;
|
|
40
|
-
|
|
41
|
-
constructor(config?: Partial<PermissionConfig>) {
|
|
42
|
-
this.config = {
|
|
43
|
-
allow: [...DEFAULT_PERMISSION_CONFIG.allow, ...(config?.allow || [])],
|
|
44
|
-
deny: [...DEFAULT_PERMISSION_CONFIG.deny, ...(config?.deny || [])],
|
|
45
|
-
ask: [...DEFAULT_PERMISSION_CONFIG.ask, ...(config?.ask || [])],
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
check(descriptor: ToolInvocationDescriptor): PermissionCheckResult {
|
|
53
|
-
const signature = PermissionChecker.buildSignature(descriptor);
|
|
54
|
-
|
|
55
|
-
// 1. 检查 deny 规则(优先级最
|
|
56
|
-
for (const rule of this.config.deny) {
|
|
57
|
-
if (this.matchesRule(signature, rule, descriptor)) {
|
|
58
|
-
return {
|
|
59
|
-
result: PermissionResult.DENY,
|
|
60
|
-
matchedRule: rule,
|
|
61
|
-
reason: `Not executed: rule "${rule}" excludes this action. Choose a different approach.`,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 2. 检查 allow 规
|
|
67
|
-
for (const rule of this.config.allow) {
|
|
68
|
-
if (this.matchesRule(signature, rule, descriptor)) {
|
|
69
|
-
return {
|
|
70
|
-
result: PermissionResult.ALLOW,
|
|
71
|
-
matchedRule: rule,
|
|
72
|
-
reason: `Allowed by rule: ${rule}`,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 3. 检查 ask 规
|
|
78
|
-
for (const rule of this.config.ask) {
|
|
79
|
-
if (this.matchesRule(signature, rule, descriptor)) {
|
|
80
|
-
return {
|
|
81
|
-
result: PermissionResult.ASK,
|
|
82
|
-
matchedRule: rule,
|
|
83
|
-
reason: `Requires confirmation by rule: ${rule}`,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// 4. 默
|
|
89
|
-
return {
|
|
90
|
-
result: PermissionResult.ASK,
|
|
91
|
-
matchedRule: 'default',
|
|
92
|
-
reason: 'No matching rule, requires confirmation',
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
*
|
|
98
|
-
*/
|
|
99
|
-
static buildSignature(descriptor: ToolInvocationDescriptor): string {
|
|
100
|
-
const { toolName, params, tool } = descriptor;
|
|
101
|
-
|
|
102
|
-
// 使用工具的 extractSignatureContent 方法(如果存
|
|
103
|
-
if (tool?.extractSignatureContent) {
|
|
104
|
-
const content = tool.extractSignatureContent(params);
|
|
105
|
-
return `${toolName}(${content})`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// 如果没有工具对象,尝试从常见参数提取签名内
|
|
109
|
-
const signatureContent = PermissionChecker.extractDefaultSignatureContent(toolName, params);
|
|
110
|
-
if (signatureContent) {
|
|
111
|
-
return `${toolName}(${signatureContent})`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// 默认:只返回工具
|
|
115
|
-
return toolName;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
*
|
|
120
|
-
*/
|
|
121
|
-
private static extractDefaultSignatureContent(
|
|
122
|
-
toolName: string,
|
|
123
|
-
params: Record<string, unknown>
|
|
124
|
-
): string | null {
|
|
125
|
-
switch (toolName) {
|
|
126
|
-
case 'Bash':
|
|
127
|
-
if (typeof params.command === 'string') {
|
|
128
|
-
return params.command;
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
case 'Read':
|
|
132
|
-
case 'Write':
|
|
133
|
-
case 'Edit':
|
|
134
|
-
if (typeof params.file_path === 'string') {
|
|
135
|
-
return params.file_path;
|
|
136
|
-
}
|
|
137
|
-
break;
|
|
138
|
-
case 'Glob':
|
|
139
|
-
if (typeof params.pattern === 'string') {
|
|
140
|
-
return params.pattern;
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
case 'Grep':
|
|
144
|
-
if (typeof params.pattern === 'string') {
|
|
145
|
-
return params.pattern;
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
*
|
|
154
|
-
*/
|
|
155
|
-
private matchesRule(
|
|
156
|
-
signature: string,
|
|
157
|
-
rule: string,
|
|
158
|
-
descriptor: ToolInvocationDescriptor
|
|
159
|
-
): boolean {
|
|
160
|
-
// 1. 精确匹配工具
|
|
161
|
-
if (rule === descriptor.toolName) {
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// 2. 解析规
|
|
166
|
-
const match = rule.match(/^(\w+)(?:\((.+)\))?$/);
|
|
167
|
-
if (!match) {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const [, ruleTool, rulePattern] = match;
|
|
172
|
-
|
|
173
|
-
// 工具名不匹
|
|
174
|
-
if (ruleTool !== descriptor.toolName) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// 没有参数模式,匹配所有该工具的调
|
|
179
|
-
if (!rulePattern) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// 3. 提取签名内
|
|
184
|
-
const signatureContent = this.extractSignatureContent(signature);
|
|
185
|
-
|
|
186
|
-
// 4. 匹配模
|
|
187
|
-
return this.matchPattern(signatureContent, rulePattern);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
*
|
|
192
|
-
*/
|
|
193
|
-
private extractSignatureContent(signature: string): string {
|
|
194
|
-
const match = signature.match(/^\w+\((.+)\)$/);
|
|
195
|
-
return match ? match[1] : '';
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
*
|
|
200
|
-
*/
|
|
201
|
-
private matchPattern(content: string, pattern: string): boolean {
|
|
202
|
-
// 1. 前缀通配符 (npm:*
|
|
203
|
-
if (pattern.endsWith(':*')) {
|
|
204
|
-
const prefix = pattern.slice(0, -2);
|
|
205
|
-
return content.startsWith(prefix);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 2. Glob 模
|
|
209
|
-
if (pattern.includes('*') || pattern.includes('?')) {
|
|
210
|
-
return minimatch(content, pattern, { dot: true });
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// 3. 精确匹
|
|
214
|
-
return content === pattern;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
*
|
|
219
|
-
*/
|
|
220
|
-
addRule(type: 'allow' | 'deny' | 'ask', rule: string): void {
|
|
221
|
-
this.config[type].push(rule);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
*
|
|
226
|
-
*/
|
|
227
|
-
removeRule(type: 'allow' | 'deny' | 'ask', rule: string): boolean {
|
|
228
|
-
const index = this.config[type].indexOf(rule);
|
|
229
|
-
if (index !== -1) {
|
|
230
|
-
this.config[type].splice(index, 1);
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
*
|
|
238
|
-
*/
|
|
239
|
-
getConfig(): PermissionConfig {
|
|
240
|
-
return { ...this.config };
|
|
241
|
-
}
|
|
242
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// ========== 敏感级
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
export enum SensitivityLevel {
|
|
12
|
-
/** 低敏感:配置文件 */
|
|
13
|
-
LOW = 'low',
|
|
14
|
-
/** 中敏感:数据库、日志 */
|
|
15
|
-
MEDIUM = 'medium',
|
|
16
|
-
/** 高敏感:密钥、凭证 */
|
|
17
|
-
HIGH = 'high',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ========== 检测结
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
export interface SensitivityResult {
|
|
26
|
-
sensitive: boolean;
|
|
27
|
-
level?: SensitivityLevel;
|
|
28
|
-
reason?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
export interface SensitivityResultWithPath {
|
|
35
|
-
path: string;
|
|
36
|
-
result: SensitivityResult;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// ========== 敏感规
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
interface SensitiveRule {
|
|
45
|
-
pattern: RegExp;
|
|
46
|
-
level: SensitivityLevel;
|
|
47
|
-
reason: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ========== 检测
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
export class SensitiveFileDetector {
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
private static readonly SENSITIVE_PATTERNS: SensitiveRule[] = [
|
|
60
|
-
// ========== 高敏
|
|
61
|
-
// 环境变
|
|
62
|
-
{ pattern: /\.env$/, level: SensitivityLevel.HIGH, reason: '环境变量文件可能包含密钥' },
|
|
63
|
-
{ pattern: /\.env\.(local|development|production|test)$/, level: SensitivityLevel.HIGH, reason: '环境变量文件可能包含密钥' },
|
|
64
|
-
|
|
65
|
-
// 凭证文
|
|
66
|
-
{ pattern: /credentials?\.json$/, level: SensitivityLevel.HIGH, reason: '凭证文件' },
|
|
67
|
-
{ pattern: /secrets?\.json$/, level: SensitivityLevel.HIGH, reason: '密钥文件' },
|
|
68
|
-
{ pattern: /\.credentials$/, level: SensitivityLevel.HIGH, reason: '凭证文件' },
|
|
69
|
-
|
|
70
|
-
// 密钥文
|
|
71
|
-
{ pattern: /\.pem$/, level: SensitivityLevel.HIGH, reason: '私钥/证书文件' },
|
|
72
|
-
{ pattern: /\.key$/, level: SensitivityLevel.HIGH, reason: '密钥文件' },
|
|
73
|
-
{ pattern: /\.p12$/, level: SensitivityLevel.HIGH, reason: 'PKCS12 证书文件' },
|
|
74
|
-
{ pattern: /\.pfx$/, level: SensitivityLevel.HIGH, reason: 'PFX 证书文件' },
|
|
75
|
-
|
|
76
|
-
// SSH 密
|
|
77
|
-
{ pattern: /id_rsa/, level: SensitivityLevel.HIGH, reason: 'SSH RSA 私钥' },
|
|
78
|
-
{ pattern: /id_ed25519/, level: SensitivityLevel.HIGH, reason: 'SSH Ed25519 私钥' },
|
|
79
|
-
{ pattern: /id_ecdsa/, level: SensitivityLevel.HIGH, reason: 'SSH ECDSA 私钥' },
|
|
80
|
-
{ pattern: /id_dsa/, level: SensitivityLevel.HIGH, reason: 'SSH DSA 私钥' },
|
|
81
|
-
|
|
82
|
-
// AWS
|
|
83
|
-
{ pattern: /\.aws\/credentials$/, level: SensitivityLevel.HIGH, reason: 'AWS 凭证文件' },
|
|
84
|
-
|
|
85
|
-
// 其
|
|
86
|
-
{ pattern: /\.htpasswd$/, level: SensitivityLevel.HIGH, reason: 'HTTP 密码文件' },
|
|
87
|
-
{ pattern: /\.netrc$/, level: SensitivityLevel.HIGH, reason: '网络凭证文件' },
|
|
88
|
-
|
|
89
|
-
// ========== 中敏
|
|
90
|
-
// 数据
|
|
91
|
-
{ pattern: /\.sqlite3?$/, level: SensitivityLevel.MEDIUM, reason: 'SQLite 数据库文件' },
|
|
92
|
-
{ pattern: /\.db$/, level: SensitivityLevel.MEDIUM, reason: '数据库文件' },
|
|
93
|
-
|
|
94
|
-
// 日
|
|
95
|
-
{ pattern: /\.log$/, level: SensitivityLevel.MEDIUM, reason: '日志文件可能包含敏感信息' },
|
|
96
|
-
|
|
97
|
-
// 历史记
|
|
98
|
-
{ pattern: /\.bash_history$/, level: SensitivityLevel.MEDIUM, reason: 'Bash 历史记录' },
|
|
99
|
-
{ pattern: /\.zsh_history$/, level: SensitivityLevel.MEDIUM, reason: 'Zsh 历史记录' },
|
|
100
|
-
|
|
101
|
-
// 其他配
|
|
102
|
-
{ pattern: /\.npmrc$/, level: SensitivityLevel.MEDIUM, reason: 'npm 配置可能包含 token' },
|
|
103
|
-
{ pattern: /\.pypirc$/, level: SensitivityLevel.MEDIUM, reason: 'PyPI 配置可能包含 token' },
|
|
104
|
-
|
|
105
|
-
// ========== 低敏
|
|
106
|
-
// 配置文
|
|
107
|
-
{ pattern: /config\.json$/, level: SensitivityLevel.LOW, reason: '配置文件' },
|
|
108
|
-
{ pattern: /settings\.json$/, level: SensitivityLevel.LOW, reason: '设置文件' },
|
|
109
|
-
{ pattern: /\.gitconfig$/, level: SensitivityLevel.LOW, reason: 'Git 配置文件' },
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
*
|
|
114
|
-
*/
|
|
115
|
-
private static readonly DANGEROUS_PATHS: RegExp[] = [
|
|
116
|
-
/^\/etc\//,
|
|
117
|
-
/^\/usr\//,
|
|
118
|
-
/^\/System\//,
|
|
119
|
-
/^\/var\//,
|
|
120
|
-
/^\/root\//,
|
|
121
|
-
/^C:\\Windows\\/i,
|
|
122
|
-
/^C:\\Program Files/i,
|
|
123
|
-
];
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
*
|
|
127
|
-
*/
|
|
128
|
-
static check(filePath: string): SensitivityResult {
|
|
129
|
-
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
130
|
-
|
|
131
|
-
for (const rule of this.SENSITIVE_PATTERNS) {
|
|
132
|
-
if (rule.pattern.test(normalizedPath)) {
|
|
133
|
-
return {
|
|
134
|
-
sensitive: true,
|
|
135
|
-
level: rule.level,
|
|
136
|
-
reason: rule.reason,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return { sensitive: false };
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
*
|
|
146
|
-
*/
|
|
147
|
-
static isDangerousPath(filePath: string): boolean {
|
|
148
|
-
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
149
|
-
return this.DANGEROUS_PATHS.some(pattern => pattern.test(normalizedPath));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
*
|
|
154
|
-
*/
|
|
155
|
-
static checkMultiple(filePaths: string[]): SensitivityResultWithPath[] {
|
|
156
|
-
return filePaths.map(path => ({
|
|
157
|
-
path,
|
|
158
|
-
result: this.check(path),
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
*
|
|
164
|
-
*/
|
|
165
|
-
static filterSensitive(
|
|
166
|
-
filePaths: string[],
|
|
167
|
-
minLevel: SensitivityLevel = SensitivityLevel.LOW
|
|
168
|
-
): SensitivityResultWithPath[] {
|
|
169
|
-
const levelOrder = {
|
|
170
|
-
[SensitivityLevel.LOW]: 0,
|
|
171
|
-
[SensitivityLevel.MEDIUM]: 1,
|
|
172
|
-
[SensitivityLevel.HIGH]: 2,
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
return this.checkMultiple(filePaths).filter(
|
|
176
|
-
item =>
|
|
177
|
-
item.result.sensitive &&
|
|
178
|
-
item.result.level &&
|
|
179
|
-
levelOrder[item.result.level] >= levelOrder[minLevel]
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
*
|
|
185
|
-
*/
|
|
186
|
-
static getLevelDescription(level: SensitivityLevel): string {
|
|
187
|
-
switch (level) {
|
|
188
|
-
case SensitivityLevel.LOW:
|
|
189
|
-
return '低敏感';
|
|
190
|
-
case SensitivityLevel.MEDIUM:
|
|
191
|
-
return '中敏感';
|
|
192
|
-
case SensitivityLevel.HIGH:
|
|
193
|
-
return '高敏感';
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
*
|
|
199
|
-
*/
|
|
200
|
-
static getLevelAction(level: SensitivityLevel): string {
|
|
201
|
-
switch (level) {
|
|
202
|
-
case SensitivityLevel.LOW:
|
|
203
|
-
return '正常流程处理';
|
|
204
|
-
case SensitivityLevel.MEDIUM:
|
|
205
|
-
return '需要用户确认';
|
|
206
|
-
case SensitivityLevel.HIGH:
|
|
207
|
-
return '默认拒绝访问';
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { PermissionChecker, DEFAULT_PERMISSION_CONFIG } from './PermissionChecker.js';
|
|
6
|
-
export {
|
|
7
|
-
SensitiveFileDetector,
|
|
8
|
-
SensitivityLevel,
|
|
9
|
-
type SensitivityResult,
|
|
10
|
-
type SensitivityResultWithPath,
|
|
11
|
-
} from './SensitiveFileDetector.js';
|