aegiscode 3.1.8 → 3.1.10
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/README.md +23 -15
- package/dist/main.js +549 -552
- package/package.json +4 -2
- package/src/agent/Agent.ts +903 -0
- package/src/agent/SimpleAgent.ts +48 -0
- package/src/agent/index.ts +54 -0
- package/src/agent/orchestrator/AppBuilder.ts +443 -0
- package/src/agent/orchestrator/CouncilAgent.ts +310 -0
- package/src/agent/orchestrator/DiscussionRoom.ts +462 -0
- package/src/agent/orchestrator/OrchestratorAgent.ts +637 -0
- package/src/agent/orchestrator/index.ts +38 -0
- package/src/agent/orchestrator/utils.ts +397 -0
- package/src/agent/pricing.ts +115 -0
- package/src/agent/router.ts +74 -0
- package/src/agent/routerStats.ts +121 -0
- package/src/agent/types.ts +318 -0
- package/src/auth/login.ts +383 -0
- package/src/cli/config.ts +189 -0
- package/src/cli/index.ts +17 -0
- package/src/cli/middleware.ts +119 -0
- package/src/cli/types.ts +75 -0
- package/src/config/ConfigManager.ts +587 -0
- package/src/config/index.ts +7 -0
- package/src/config/types.ts +584 -0
- package/src/context/CompactionService.ts +300 -0
- package/src/context/ContextManager.ts +450 -0
- package/src/context/FileAnalyzer.ts +267 -0
- package/src/context/TokenCounter.ts +265 -0
- package/src/context/index.ts +27 -0
- package/src/context/storage/CacheStore.ts +176 -0
- package/src/context/storage/JSONLStore.ts +201 -0
- package/src/context/storage/MemoryStore.ts +205 -0
- package/src/context/storage/PersistentStore.ts +327 -0
- package/src/context/storage/index.ts +9 -0
- package/src/context/storage/pathUtils.ts +114 -0
- package/src/context/test.ts +309 -0
- package/src/context/types.ts +268 -0
- package/src/hooks/HookExecutor.ts +434 -0
- package/src/hooks/HookManager.ts +596 -0
- package/src/hooks/HookService.ts +269 -0
- package/src/hooks/Matcher.ts +157 -0
- package/src/hooks/index.ts +63 -0
- package/src/hooks/types.ts +424 -0
- package/src/main.tsx +596 -0
- package/src/mcp/HealthMonitor.ts +150 -0
- package/src/mcp/McpClient.ts +491 -0
- package/src/mcp/McpRegistry.ts +321 -0
- package/src/mcp/createMcpTool.ts +251 -0
- package/src/mcp/index.ts +15 -0
- package/src/mcp/server.ts +334 -0
- package/src/mcp/test-server.ts +88 -0
- package/src/mcp/test.ts +372 -0
- package/src/mcp/types.ts +247 -0
- package/src/memory/AgentMemoryBus.ts +432 -0
- package/src/memory/CloudSync.ts +99 -0
- package/src/memory/DriveSync.ts +106 -0
- package/src/memory/SharedMemory.ts +951 -0
- package/src/memory/index.ts +14 -0
- package/src/memory/machineFingerprint.ts +40 -0
- package/src/orchestrator/SubAgentMetadata.ts +136 -0
- package/src/prompts/builder.ts +213 -0
- package/src/prompts/default.ts +144 -0
- package/src/prompts/index.ts +16 -0
- package/src/prompts/plan.ts +64 -0
- package/src/prompts/test.ts +78 -0
- package/src/services/AnthropicChatService.ts +341 -0
- package/src/services/ChatService.ts +347 -0
- package/src/services/ClaudeCliChatService.ts +256 -0
- package/src/services/CloudSync.ts +168 -0
- package/src/services/CostLedger.ts +211 -0
- package/src/services/Heartbeat.ts +135 -0
- package/src/services/LearningCollector.ts +291 -0
- package/src/services/OllamaInstaller.ts +342 -0
- package/src/services/VersionChecker.ts +445 -0
- package/src/services/index.ts +57 -0
- package/src/services/streaming/OpenAIEventAdapter.ts +126 -0
- package/src/services/streaming/RenderingProfile.ts +90 -0
- package/src/services/streaming/StreamEventParser.ts +181 -0
- package/src/services/streaming/ThrottledRenderer.ts +139 -0
- package/src/services/streaming/TranscriptBuffer.ts +574 -0
- package/src/services/streaming/eventStatusMap.ts +52 -0
- package/src/services/streaming/index.ts +46 -0
- package/src/services/streaming/renderFormatting.ts +79 -0
- package/src/services/streaming/types.ts +234 -0
- package/src/skills/SkillLoader.ts +126 -0
- package/src/skills/SkillRegistry.ts +366 -0
- package/src/skills/index.ts +48 -0
- package/src/skills/types.ts +146 -0
- package/src/slash-commands/billing.ts +70 -0
- package/src/slash-commands/build.ts +413 -0
- package/src/slash-commands/builtinCommands.ts +2733 -0
- package/src/slash-commands/clone.ts +242 -0
- package/src/slash-commands/council.ts +125 -0
- package/src/slash-commands/custom/CustomCommandExecutor.ts +143 -0
- package/src/slash-commands/custom/CustomCommandLoader.ts +251 -0
- package/src/slash-commands/custom/CustomCommandRegistry.ts +144 -0
- package/src/slash-commands/custom/index.ts +7 -0
- package/src/slash-commands/debate.ts +254 -0
- package/src/slash-commands/gmail.ts +105 -0
- package/src/slash-commands/index.ts +388 -0
- package/src/slash-commands/mcpCommand.ts +205 -0
- package/src/slash-commands/types.ts +201 -0
- package/src/store/index.ts +76 -0
- package/src/store/selectors.ts +246 -0
- package/src/store/slices/appSlice.ts +205 -0
- package/src/store/slices/commandSlice.ts +115 -0
- package/src/store/slices/configSlice.ts +46 -0
- package/src/store/slices/focusSlice.ts +64 -0
- package/src/store/slices/index.ts +9 -0
- package/src/store/slices/sessionSlice.ts +424 -0
- package/src/store/streaming-buffer.ts +425 -0
- package/src/store/test.ts +296 -0
- package/src/store/types.ts +274 -0
- package/src/store/vanilla.ts +186 -0
- package/src/tools/builtin/bash.ts +236 -0
- package/src/tools/builtin/council.ts +105 -0
- package/src/tools/builtin/edit.ts +213 -0
- package/src/tools/builtin/glob.ts +136 -0
- package/src/tools/builtin/grep.ts +263 -0
- package/src/tools/builtin/index.ts +61 -0
- package/src/tools/builtin/memory.ts +66 -0
- package/src/tools/builtin/read.ts +168 -0
- package/src/tools/builtin/skill.ts +97 -0
- package/src/tools/builtin/snapshot.ts +40 -0
- package/src/tools/builtin/task.ts +106 -0
- package/src/tools/builtin/write.ts +134 -0
- package/src/tools/createTool.ts +221 -0
- package/src/tools/execution/ExecutionPipeline.ts +263 -0
- package/src/tools/execution/index.ts +40 -0
- package/src/tools/execution/stages/CacheStage.ts +131 -0
- package/src/tools/execution/stages/ConfirmationStage.ts +203 -0
- package/src/tools/execution/stages/DiscoveryStage.ts +46 -0
- package/src/tools/execution/stages/ExecutionStage.ts +48 -0
- package/src/tools/execution/stages/FormattingStage.ts +44 -0
- package/src/tools/execution/stages/HookStage.ts +72 -0
- package/src/tools/execution/stages/PermissionStage.ts +287 -0
- package/src/tools/execution/stages/PostHookStage.ts +71 -0
- package/src/tools/execution/stages/index.ts +12 -0
- package/src/tools/execution/test.ts +266 -0
- package/src/tools/execution/types.ts +273 -0
- package/src/tools/index.ts +81 -0
- package/src/tools/registry.ts +304 -0
- package/src/tools/schemas.ts +109 -0
- package/src/tools/test.ts +220 -0
- package/src/tools/types.ts +175 -0
- package/src/tools/validation/PermissionChecker.ts +242 -0
- package/src/tools/validation/SensitiveFileDetector.ts +210 -0
- package/src/tools/validation/index.ts +11 -0
- package/src/ui/App.tsx +166 -0
- package/src/ui/components/AegisInterface.tsx +484 -0
- package/src/ui/components/common/ChatSearch.tsx +150 -0
- package/src/ui/components/common/ErrorBoundary.tsx +82 -0
- package/src/ui/components/common/ExitMessage.tsx +120 -0
- package/src/ui/components/common/LoadingIndicator.tsx +49 -0
- package/src/ui/components/common/index.ts +6 -0
- package/src/ui/components/dialog/ConfirmationPrompt.tsx +208 -0
- package/src/ui/components/dialog/InteractiveSelector.tsx +149 -0
- package/src/ui/components/dialog/SetupWizard.tsx +297 -0
- package/src/ui/components/dialog/UpdatePrompt.tsx +155 -0
- package/src/ui/components/dialog/index.ts +8 -0
- package/src/ui/components/index.ts +28 -0
- package/src/ui/components/input/CommandSuggestions.tsx +139 -0
- package/src/ui/components/input/CustomTextInput.tsx +220 -0
- package/src/ui/components/input/InputArea.tsx +361 -0
- package/src/ui/components/input/PromptSuggestions.tsx +66 -0
- package/src/ui/components/input/index.ts +6 -0
- package/src/ui/components/layout/ChatStatusBar.tsx +90 -0
- package/src/ui/components/layout/ContextBar.tsx +79 -0
- package/src/ui/components/layout/MessageArea.tsx +96 -0
- package/src/ui/components/layout/MessageList.tsx +647 -0
- package/src/ui/components/layout/MessageSeparator.tsx +26 -0
- package/src/ui/components/layout/WelcomeMessage.tsx +93 -0
- package/src/ui/components/layout/index.ts +7 -0
- package/src/ui/components/markdown/CodeHighlighter.tsx +292 -0
- package/src/ui/components/markdown/MessageRenderer.tsx +1211 -0
- package/src/ui/components/markdown/index.ts +8 -0
- package/src/ui/components/markdown/parser.ts +336 -0
- package/src/ui/components/markdown/types.ts +66 -0
- package/src/ui/focus/FocusManager.ts +137 -0
- package/src/ui/focus/index.ts +13 -0
- package/src/ui/focus/types.ts +54 -0
- package/src/ui/focus/useFocus.ts +75 -0
- package/src/ui/hooks/index.ts +11 -0
- package/src/ui/hooks/useAgent.ts +284 -0
- package/src/ui/hooks/useCommandHistory.ts +87 -0
- package/src/ui/hooks/useCommandProcessor.ts +443 -0
- package/src/ui/hooks/useConfirmation.ts +99 -0
- package/src/ui/hooks/useCtrlCHandler.ts +100 -0
- package/src/ui/hooks/useInputBuffer.ts +122 -0
- package/src/ui/hooks/useTerminalSize.ts +68 -0
- package/src/ui/hooks/useTerminalWidth.ts +5 -0
- package/src/ui/hooks/useWindowedList.ts +118 -0
- package/src/ui/render-debugger.ts +621 -0
- package/src/ui/test.ts +189 -0
- package/src/ui/themes/ThemeManager.ts +332 -0
- package/src/ui/themes/aegisTheme.ts +87 -0
- package/src/ui/themes/darkTheme.ts +87 -0
- package/src/ui/themes/defaultTheme.ts +85 -0
- package/src/ui/themes/index.ts +10 -0
- package/src/ui/themes/lightTheme.ts +89 -0
- package/src/ui/themes/popularThemes.ts +187 -0
- package/src/ui/themes/types.ts +130 -0
- package/src/utils/clipboard.ts +48 -0
- package/src/utils/debug.ts +43 -0
- package/src/utils/environment.ts +68 -0
- package/src/utils/index.ts +10 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hooks 系统类型定义
|
|
3
|
+
*
|
|
4
|
+
* Hooks 允许用户在特定事件点注入自定义 Shell 命令,
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { PermissionMode } from '../agent/types.js';
|
|
9
|
+
|
|
10
|
+
// ========== Hook 事件类
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Hook 事件枚举
|
|
14
|
+
*
|
|
15
|
+
* 11 种事件类型,覆盖 Agent 生命周期的各个关键节点
|
|
16
|
+
*/
|
|
17
|
+
export enum HookEvent {
|
|
18
|
+
// ========== 工具执行
|
|
19
|
+
/** 工具执行前 (可阻止或修改输入) */
|
|
20
|
+
PreToolUse = 'PreToolUse',
|
|
21
|
+
/** 工具执行后 (可添加上下文或修改输出) */
|
|
22
|
+
PostToolUse = 'PostToolUse',
|
|
23
|
+
/** 工具执行失败后 */
|
|
24
|
+
PostToolUseFailure = 'PostToolUseFailure',
|
|
25
|
+
/** 权限请求时 (可自动批准/拒绝) */
|
|
26
|
+
PermissionRequest = 'PermissionRequest',
|
|
27
|
+
|
|
28
|
+
// ========== 会话生命周期
|
|
29
|
+
/** 用户提交提示词时 (可注入上下文) */
|
|
30
|
+
UserPromptSubmit = 'UserPromptSubmit',
|
|
31
|
+
/** 会话启动时 */
|
|
32
|
+
SessionStart = 'SessionStart',
|
|
33
|
+
/** 会话结束时 */
|
|
34
|
+
SessionEnd = 'SessionEnd',
|
|
35
|
+
|
|
36
|
+
// ========== 控制流
|
|
37
|
+
/** Agent 停止响应时 (可阻止停止) */
|
|
38
|
+
Stop = 'Stop',
|
|
39
|
+
/** 子 Agent (Task) 停止响应时 */
|
|
40
|
+
SubagentStop = 'SubagentStop',
|
|
41
|
+
|
|
42
|
+
// ========== 其
|
|
43
|
+
/** 通知事件 */
|
|
44
|
+
Notification = 'Notification',
|
|
45
|
+
/** 上下文压缩时 */
|
|
46
|
+
Compaction = 'Compaction',
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ========== 退出码语
|
|
50
|
+
|
|
51
|
+
export enum HookExitCode {
|
|
52
|
+
/** 成功,继续执行 */
|
|
53
|
+
SUCCESS = 0,
|
|
54
|
+
/** 非阻塞错误,记录但继续 */
|
|
55
|
+
NON_BLOCKING_ERROR = 1,
|
|
56
|
+
/** 阻塞错误,停止执行 */
|
|
57
|
+
BLOCKING_ERROR = 2,
|
|
58
|
+
/** 超时 */
|
|
59
|
+
TIMEOUT = 124,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ========== 配置类
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Hook 配置
|
|
66
|
+
*/
|
|
67
|
+
export interface HookConfig {
|
|
68
|
+
/** 是否启用 Hooks */
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
/** 默认超时(秒) */
|
|
71
|
+
defaultTimeout?: number;
|
|
72
|
+
/** 超时行为 */
|
|
73
|
+
timeoutBehavior?: 'ignore' | 'deny' | 'ask';
|
|
74
|
+
/** 失败行为 */
|
|
75
|
+
failureBehavior?: 'ignore' | 'deny' | 'ask';
|
|
76
|
+
/** 最大并发数 */
|
|
77
|
+
maxConcurrentHooks?: number;
|
|
78
|
+
|
|
79
|
+
// 各事件类型的 Hook 列
|
|
80
|
+
PreToolUse?: HookMatcher[];
|
|
81
|
+
PostToolUse?: HookMatcher[];
|
|
82
|
+
PostToolUseFailure?: HookMatcher[];
|
|
83
|
+
PermissionRequest?: HookMatcher[];
|
|
84
|
+
UserPromptSubmit?: HookMatcher[];
|
|
85
|
+
SessionStart?: HookMatcher[];
|
|
86
|
+
SessionEnd?: HookMatcher[];
|
|
87
|
+
Stop?: HookMatcher[];
|
|
88
|
+
SubagentStop?: HookMatcher[];
|
|
89
|
+
Notification?: HookMatcher[];
|
|
90
|
+
Compaction?: HookMatcher[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Hook Matcher(匹配器配置)
|
|
95
|
+
*/
|
|
96
|
+
export interface HookMatcher {
|
|
97
|
+
/** 可选名称 */
|
|
98
|
+
name?: string;
|
|
99
|
+
/** 匹配条件 */
|
|
100
|
+
matcher?: MatcherConfig;
|
|
101
|
+
/** Hook 列表 */
|
|
102
|
+
hooks: Hook[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
export interface MatcherConfig {
|
|
109
|
+
/** 工具名匹配(支持正则) */
|
|
110
|
+
tools?: string;
|
|
111
|
+
/** 文件路径匹配(glob) */
|
|
112
|
+
paths?: string;
|
|
113
|
+
/** 命令匹配(正则) */
|
|
114
|
+
commands?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Hook 类型
|
|
119
|
+
*/
|
|
120
|
+
export type Hook = CommandHook;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
export interface CommandHook {
|
|
126
|
+
type: 'command';
|
|
127
|
+
/** Shell 命令 */
|
|
128
|
+
command: string;
|
|
129
|
+
/** 超时时间(秒) */
|
|
130
|
+
timeout?: number;
|
|
131
|
+
/** 状态消息 */
|
|
132
|
+
statusMessage?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ========== 输入类
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Hook 输入基类
|
|
139
|
+
*/
|
|
140
|
+
export interface HookInputBase {
|
|
141
|
+
hook_event_name: HookEvent;
|
|
142
|
+
hook_execution_id: string;
|
|
143
|
+
timestamp: string;
|
|
144
|
+
session_id: string;
|
|
145
|
+
project_dir: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* PreToolUse 输入
|
|
150
|
+
*/
|
|
151
|
+
export interface PreToolUseInput extends HookInputBase {
|
|
152
|
+
hook_event_name: HookEvent.PreToolUse;
|
|
153
|
+
tool_name: string;
|
|
154
|
+
tool_use_id: string;
|
|
155
|
+
tool_input: Record<string, unknown>;
|
|
156
|
+
permission_mode: PermissionMode;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* PostToolUse 输入
|
|
161
|
+
*/
|
|
162
|
+
export interface PostToolUseInput extends HookInputBase {
|
|
163
|
+
hook_event_name: HookEvent.PostToolUse;
|
|
164
|
+
tool_name: string;
|
|
165
|
+
tool_use_id: string;
|
|
166
|
+
tool_input: Record<string, unknown>;
|
|
167
|
+
tool_output: unknown;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* PostToolUseFailure 输入
|
|
172
|
+
*/
|
|
173
|
+
export interface PostToolUseFailureInput extends HookInputBase {
|
|
174
|
+
hook_event_name: HookEvent.PostToolUseFailure;
|
|
175
|
+
tool_name: string;
|
|
176
|
+
tool_use_id: string;
|
|
177
|
+
tool_input: Record<string, unknown>;
|
|
178
|
+
error: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* PermissionRequest 输入
|
|
183
|
+
*/
|
|
184
|
+
export interface PermissionRequestInput extends HookInputBase {
|
|
185
|
+
hook_event_name: HookEvent.PermissionRequest;
|
|
186
|
+
tool_name: string;
|
|
187
|
+
tool_input: Record<string, unknown>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* UserPromptSubmit 输入
|
|
192
|
+
*/
|
|
193
|
+
export interface UserPromptSubmitInput extends HookInputBase {
|
|
194
|
+
hook_event_name: HookEvent.UserPromptSubmit;
|
|
195
|
+
prompt_content: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* SessionStart 输入
|
|
200
|
+
*/
|
|
201
|
+
export interface SessionStartInput extends HookInputBase {
|
|
202
|
+
hook_event_name: HookEvent.SessionStart;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* SessionEnd 输入
|
|
207
|
+
*/
|
|
208
|
+
export interface SessionEndInput extends HookInputBase {
|
|
209
|
+
hook_event_name: HookEvent.SessionEnd;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Stop 输入
|
|
214
|
+
*/
|
|
215
|
+
export interface StopInput extends HookInputBase {
|
|
216
|
+
hook_event_name: HookEvent.Stop;
|
|
217
|
+
stop_reason?: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* SubagentStop 输入
|
|
222
|
+
*/
|
|
223
|
+
export interface SubagentStopInput extends HookInputBase {
|
|
224
|
+
hook_event_name: HookEvent.SubagentStop;
|
|
225
|
+
subagent_id: string;
|
|
226
|
+
stop_reason?: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Notification 输入
|
|
231
|
+
*/
|
|
232
|
+
export interface NotificationInput extends HookInputBase {
|
|
233
|
+
hook_event_name: HookEvent.Notification;
|
|
234
|
+
message: string;
|
|
235
|
+
level: 'info' | 'warning' | 'error';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Compaction 输入
|
|
240
|
+
*/
|
|
241
|
+
export interface CompactionInput extends HookInputBase {
|
|
242
|
+
hook_event_name: HookEvent.Compaction;
|
|
243
|
+
pre_tokens: number;
|
|
244
|
+
message_count: number;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export type HookInput =
|
|
248
|
+
| PreToolUseInput
|
|
249
|
+
| PostToolUseInput
|
|
250
|
+
| PostToolUseFailureInput
|
|
251
|
+
| PermissionRequestInput
|
|
252
|
+
| UserPromptSubmitInput
|
|
253
|
+
| SessionStartInput
|
|
254
|
+
| SessionEndInput
|
|
255
|
+
| StopInput
|
|
256
|
+
| SubagentStopInput
|
|
257
|
+
| NotificationInput
|
|
258
|
+
| CompactionInput;
|
|
259
|
+
|
|
260
|
+
// ========== 输出类
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* PreToolUse 输出
|
|
264
|
+
*/
|
|
265
|
+
export interface PreToolUseOutput {
|
|
266
|
+
hookEventName?: 'PreToolUse';
|
|
267
|
+
/** 权限决策 */
|
|
268
|
+
permissionDecision?: 'allow' | 'deny' | 'ask';
|
|
269
|
+
permissionDecisionReason?: string;
|
|
270
|
+
/** 修改后的工具输入 */
|
|
271
|
+
updatedInput?: Record<string, unknown>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* PostToolUse 输出
|
|
276
|
+
*/
|
|
277
|
+
export interface PostToolUseOutput {
|
|
278
|
+
hookEventName?: 'PostToolUse';
|
|
279
|
+
/** 额外上下文 */
|
|
280
|
+
additionalContext?: string;
|
|
281
|
+
/** 修改后的输出 */
|
|
282
|
+
updatedOutput?: unknown;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* PermissionRequest 输出
|
|
287
|
+
*/
|
|
288
|
+
export interface PermissionRequestOutput {
|
|
289
|
+
/** 决策 */
|
|
290
|
+
decision?: 'approve' | 'deny' | 'ask';
|
|
291
|
+
reason?: string;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Stop 输出
|
|
296
|
+
*/
|
|
297
|
+
export interface StopOutput {
|
|
298
|
+
/** true 则阻止停止,强制继续 */
|
|
299
|
+
continue?: boolean;
|
|
300
|
+
reason?: string;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Compaction 输出
|
|
305
|
+
*/
|
|
306
|
+
export interface CompactionOutput {
|
|
307
|
+
/** true 则阻止压缩 */
|
|
308
|
+
prevent?: boolean;
|
|
309
|
+
reason?: string;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export type HookSpecificOutput =
|
|
313
|
+
| PreToolUseOutput
|
|
314
|
+
| PostToolUseOutput
|
|
315
|
+
| PermissionRequestOutput
|
|
316
|
+
| StopOutput
|
|
317
|
+
| CompactionOutput;
|
|
318
|
+
|
|
319
|
+
// ========== 执行结果类
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Hook 执行上下文
|
|
323
|
+
*/
|
|
324
|
+
export interface HookContext {
|
|
325
|
+
sessionId: string;
|
|
326
|
+
projectDir: string;
|
|
327
|
+
permissionMode: PermissionMode;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Hook 执行配置上下文
|
|
332
|
+
*/
|
|
333
|
+
export interface HookExecutionContext extends HookContext {
|
|
334
|
+
config: HookConfig;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
*
|
|
339
|
+
*/
|
|
340
|
+
export interface HookExecutionResult {
|
|
341
|
+
success: boolean;
|
|
342
|
+
exitCode: number;
|
|
343
|
+
stdout: string;
|
|
344
|
+
stderr: string;
|
|
345
|
+
duration: number;
|
|
346
|
+
output?: {
|
|
347
|
+
hookSpecificOutput?: HookSpecificOutput;
|
|
348
|
+
rawOutput?: string;
|
|
349
|
+
};
|
|
350
|
+
error?: string;
|
|
351
|
+
blocking?: boolean;
|
|
352
|
+
needsConfirmation?: boolean;
|
|
353
|
+
warning?: string;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* PreToolUse Hook 结果
|
|
358
|
+
*/
|
|
359
|
+
export interface PreToolHookResult {
|
|
360
|
+
decision: 'allow' | 'deny' | 'ask';
|
|
361
|
+
reason?: string;
|
|
362
|
+
modifiedInput?: Record<string, unknown>;
|
|
363
|
+
warning?: string;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* PostToolUse Hook 结果
|
|
368
|
+
*/
|
|
369
|
+
export interface PostToolHookResult {
|
|
370
|
+
additionalContext?: string;
|
|
371
|
+
modifiedOutput?: unknown;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* PermissionRequest Hook 结果
|
|
376
|
+
*/
|
|
377
|
+
export interface PermissionHookResult {
|
|
378
|
+
decision: 'approve' | 'deny' | 'ask';
|
|
379
|
+
reason?: string;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Stop Hook 结果
|
|
384
|
+
*/
|
|
385
|
+
export interface StopHookResult {
|
|
386
|
+
shouldContinue: boolean;
|
|
387
|
+
reason?: string;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* UserPromptSubmit Hook 结果
|
|
392
|
+
*/
|
|
393
|
+
export interface UserPromptHookResult {
|
|
394
|
+
injectedContext?: string;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Compaction Hook 结果
|
|
399
|
+
*/
|
|
400
|
+
export interface CompactionHookResult {
|
|
401
|
+
shouldPrevent: boolean;
|
|
402
|
+
reason?: string;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ========== 匹配上下
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
*
|
|
409
|
+
*/
|
|
410
|
+
export interface MatchContext {
|
|
411
|
+
toolName?: string;
|
|
412
|
+
filePath?: string;
|
|
413
|
+
command?: string;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ========== 默认配
|
|
417
|
+
|
|
418
|
+
export const DEFAULT_HOOK_CONFIG: HookConfig = {
|
|
419
|
+
enabled: true,
|
|
420
|
+
defaultTimeout: 60,
|
|
421
|
+
timeoutBehavior: 'ignore',
|
|
422
|
+
failureBehavior: 'ignore',
|
|
423
|
+
maxConcurrentHooks: 5,
|
|
424
|
+
};
|