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,584 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* - config.json: 基础配置(API、模型、UI)
|
|
6
|
+
* - settings.json: 行为配置(权限、Hooks、环境变量)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
|
|
11
|
+
// ========== 枚举定
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* LLM API 提供商类型
|
|
15
|
+
*/
|
|
16
|
+
export type ProviderType = 'openai-compatible' | 'anthropic';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export enum PermissionMode {
|
|
22
|
+
DEFAULT = 'default', // 只读自动,写入需确
|
|
23
|
+
AUTO_EDIT = 'autoEdit', // 只读+写入自动,执行需确
|
|
24
|
+
YOLO = 'yolo', // 完全自动(危
|
|
25
|
+
PLAN = 'plan', // 只读自动,其他拦
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ========== Zod Schemas ==========
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export const ModelConfigSchema = z.object({
|
|
36
|
+
id: z.string().optional(), // nanoid 自动生
|
|
37
|
+
name: z.string().optional(), // 显示名
|
|
38
|
+
provider: z.enum(['openai-compatible', 'anthropic']).optional(),
|
|
39
|
+
apiKey: z.string().optional(),
|
|
40
|
+
baseURL: z.string().optional(),
|
|
41
|
+
model: z.string().optional(),
|
|
42
|
+
temperature: z.number().min(0).max(2).optional(),
|
|
43
|
+
maxContextTokens: z.number().optional(),
|
|
44
|
+
topP: z.number().optional(),
|
|
45
|
+
topK: z.number().optional(),
|
|
46
|
+
|
|
47
|
+
// 模型级工具过滤:只在当前模型生效
|
|
48
|
+
allowedTools: z.array(z.string()).optional(),
|
|
49
|
+
disallowedTools: z.array(z.string()).optional(),
|
|
50
|
+
|
|
51
|
+
// 是否需要确认提示(默认 true,保持原有行为)
|
|
52
|
+
requireConfirmation: z.boolean().optional(),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
export const PRESET_THEME_IDS = ['default', 'light', 'dark', 'ocean', 'forest', 'sunset'] as const;
|
|
59
|
+
export type PresetThemeId = typeof PRESET_THEME_IDS[number];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* UI 配置 Schema
|
|
63
|
+
*/
|
|
64
|
+
export const UIConfigSchema = z.object({
|
|
65
|
+
// 支持所有预设主题,也支持自定义主题名
|
|
66
|
+
theme: z.string().optional(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Auto-router Schema — per-tier model id overrides for simple/medium/complex tasks
|
|
71
|
+
*/
|
|
72
|
+
export const AutoRouterConfigSchema = z.object({
|
|
73
|
+
enabled: z.boolean().optional(),
|
|
74
|
+
tiers: z.object({
|
|
75
|
+
simple: z.string().optional(),
|
|
76
|
+
medium: z.string().optional(),
|
|
77
|
+
complex: z.string().optional(),
|
|
78
|
+
}).optional(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Extended-thinking Schema — budget tier sent as `thinking.budget_tokens` to
|
|
83
|
+
* Anthropic models that support it. 'off' omits the thinking param entirely.
|
|
84
|
+
*/
|
|
85
|
+
export const ThinkingConfigSchema = z.object({
|
|
86
|
+
budget: z.enum(['off', 'low', 'medium', 'high', 'max']).optional(),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
*/
|
|
92
|
+
export const PermissionConfigSchema = z.object({
|
|
93
|
+
allow: z.array(z.string()).default([]),
|
|
94
|
+
deny: z.array(z.string()).default([]),
|
|
95
|
+
ask: z.array(z.string()).default([]),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* MCP 服务器配置 Schema
|
|
100
|
+
*/
|
|
101
|
+
export const McpServerConfigSchema = z.object({
|
|
102
|
+
type: z.enum(['stdio', 'sse', 'http']),
|
|
103
|
+
|
|
104
|
+
// stdio 配
|
|
105
|
+
command: z.string().optional(),
|
|
106
|
+
args: z.array(z.string()).optional(),
|
|
107
|
+
env: z.record(z.string()).optional(),
|
|
108
|
+
cwd: z.string().optional(),
|
|
109
|
+
|
|
110
|
+
// sse/http 配置
|
|
111
|
+
url: z.string().optional(),
|
|
112
|
+
headers: z.record(z.string()).optional(),
|
|
113
|
+
|
|
114
|
+
// 其他配
|
|
115
|
+
enabled: z.boolean().optional(),
|
|
116
|
+
timeout: z.number().optional(),
|
|
117
|
+
description: z.string().optional(),
|
|
118
|
+
|
|
119
|
+
// 健康检查配
|
|
120
|
+
healthCheck: z.object({
|
|
121
|
+
enabled: z.boolean(),
|
|
122
|
+
intervalMs: z.number(),
|
|
123
|
+
timeoutMs: z.number(),
|
|
124
|
+
maxFailures: z.number(),
|
|
125
|
+
}).optional(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Hook 配置 Schema
|
|
130
|
+
*
|
|
131
|
+
*
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
export const HookConfigSchema = z.object({
|
|
135
|
+
enabled: z.boolean().optional(),
|
|
136
|
+
defaultTimeout: z.number().optional(),
|
|
137
|
+
timeoutBehavior: z.enum(['ignore', 'deny', 'ask']).optional(),
|
|
138
|
+
failureBehavior: z.enum(['ignore', 'deny', 'ask']).optional(),
|
|
139
|
+
maxConcurrentHooks: z.number().optional(),
|
|
140
|
+
// 各事件类型的 Hook 列表(使用 passthrough 接受完整结
|
|
141
|
+
PreToolUse: z.array(z.any()).optional(),
|
|
142
|
+
PostToolUse: z.array(z.any()).optional(),
|
|
143
|
+
PostToolUseFailure: z.array(z.any()).optional(),
|
|
144
|
+
PermissionRequest: z.array(z.any()).optional(),
|
|
145
|
+
UserPromptSubmit: z.array(z.any()).optional(),
|
|
146
|
+
SessionStart: z.array(z.any()).optional(),
|
|
147
|
+
SessionEnd: z.array(z.any()).optional(),
|
|
148
|
+
Stop: z.array(z.any()).optional(),
|
|
149
|
+
SubagentStop: z.array(z.any()).optional(),
|
|
150
|
+
Notification: z.array(z.any()).optional(),
|
|
151
|
+
Compaction: z.array(z.any()).optional(),
|
|
152
|
+
}).optional();
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
*
|
|
156
|
+
*/
|
|
157
|
+
export const ConfigSchema = z.object({
|
|
158
|
+
//
|
|
159
|
+
default: ModelConfigSchema.optional(),
|
|
160
|
+
|
|
161
|
+
//
|
|
162
|
+
models: z.array(ModelConfigSchema).optional(),
|
|
163
|
+
currentModelId: z.string().optional(),
|
|
164
|
+
|
|
165
|
+
// UI
|
|
166
|
+
ui: UIConfigSchema.optional(),
|
|
167
|
+
theme: z.string().optional(),
|
|
168
|
+
|
|
169
|
+
//
|
|
170
|
+
permissions: PermissionConfigSchema.optional(),
|
|
171
|
+
|
|
172
|
+
//
|
|
173
|
+
defaultPermissionMode: z.enum(['default', 'autoEdit', 'yolo', 'plan']).optional(),
|
|
174
|
+
|
|
175
|
+
//
|
|
176
|
+
toolWhitelist: z.array(z.string()).optional(),
|
|
177
|
+
|
|
178
|
+
//
|
|
179
|
+
toolBlacklist: z.array(z.string()).optional(),
|
|
180
|
+
|
|
181
|
+
// MCP
|
|
182
|
+
mcpServers: z.record(McpServerConfigSchema).optional(),
|
|
183
|
+
|
|
184
|
+
// MCP
|
|
185
|
+
mcpEnabled: z.boolean().optional(),
|
|
186
|
+
|
|
187
|
+
// Hooks
|
|
188
|
+
hooks: HookConfigSchema,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
*
|
|
193
|
+
*
|
|
194
|
+
*/
|
|
195
|
+
export const ClawdConfigSchema = z.object({
|
|
196
|
+
// ===== 基础配
|
|
197
|
+
|
|
198
|
+
// 默认模型配置(向后兼
|
|
199
|
+
default: ModelConfigSchema.optional(),
|
|
200
|
+
|
|
201
|
+
// 多模型配
|
|
202
|
+
currentModelId: z.string().optional(),
|
|
203
|
+
models: z.array(ModelConfigSchema).optional(),
|
|
204
|
+
|
|
205
|
+
// 全局参
|
|
206
|
+
temperature: z.number().min(0).max(2).optional(),
|
|
207
|
+
maxContextTokens: z.number().optional(),
|
|
208
|
+
maxOutputTokens: z.number().optional(),
|
|
209
|
+
stream: z.boolean().optional(),
|
|
210
|
+
timeout: z.number().optional(),
|
|
211
|
+
|
|
212
|
+
// UI
|
|
213
|
+
ui: UIConfigSchema.optional(),
|
|
214
|
+
theme: z.string().optional(),
|
|
215
|
+
language: z.string().optional(),
|
|
216
|
+
|
|
217
|
+
// 调
|
|
218
|
+
debug: z.union([z.string(), z.boolean()]).optional(),
|
|
219
|
+
|
|
220
|
+
// MCP
|
|
221
|
+
mcpEnabled: z.boolean().optional(),
|
|
222
|
+
mcpServers: z.record(McpServerConfigSchema).optional(),
|
|
223
|
+
|
|
224
|
+
// 自动路由:按任务复杂度自动选择模型
|
|
225
|
+
autoRouter: AutoRouterConfigSchema.optional(),
|
|
226
|
+
|
|
227
|
+
// 扩展思考:发送给支持的模型的 thinking budget
|
|
228
|
+
thinking: ThinkingConfigSchema.optional(),
|
|
229
|
+
|
|
230
|
+
// ===== 行为配
|
|
231
|
+
|
|
232
|
+
// 权
|
|
233
|
+
permissions: PermissionConfigSchema.optional(),
|
|
234
|
+
defaultPermissionMode: z.enum(['default', 'autoEdit', 'yolo', 'plan']).optional(),
|
|
235
|
+
|
|
236
|
+
// 工具过
|
|
237
|
+
toolWhitelist: z.array(z.string()).optional(),
|
|
238
|
+
toolBlacklist: z.array(z.string()).optional(),
|
|
239
|
+
|
|
240
|
+
// Hooks
|
|
241
|
+
hooks: HookConfigSchema,
|
|
242
|
+
|
|
243
|
+
// 环境变
|
|
244
|
+
env: z.record(z.string()).optional(),
|
|
245
|
+
|
|
246
|
+
// 其
|
|
247
|
+
maxTurns: z.number().optional(),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
*
|
|
252
|
+
*
|
|
253
|
+
*/
|
|
254
|
+
export const RuntimeConfigSchema = ClawdConfigSchema.extend({
|
|
255
|
+
// 系统提
|
|
256
|
+
systemPrompt: z.string().optional(),
|
|
257
|
+
appendSystemPrompt: z.string().optional(),
|
|
258
|
+
|
|
259
|
+
// 会话管
|
|
260
|
+
initialMessage: z.string().optional(),
|
|
261
|
+
resumeSessionId: z.string().optional(),
|
|
262
|
+
forkSession: z.boolean().optional(),
|
|
263
|
+
|
|
264
|
+
// 工具过滤(CLI 临
|
|
265
|
+
allowedTools: z.array(z.string()).optional(),
|
|
266
|
+
disallowedTools: z.array(z.string()).optional(),
|
|
267
|
+
|
|
268
|
+
// MCP(CLI 临
|
|
269
|
+
mcpConfigPaths: z.array(z.string()).optional(),
|
|
270
|
+
strictMcpConfig: z.boolean().optional(),
|
|
271
|
+
|
|
272
|
+
// 其
|
|
273
|
+
fallbackModel: z.string().optional(),
|
|
274
|
+
addDirs: z.array(z.string()).optional(),
|
|
275
|
+
outputFormat: z.enum(['text', 'json', 'stream-json']).optional(),
|
|
276
|
+
print: z.boolean().optional(),
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// ========== 类型导
|
|
280
|
+
|
|
281
|
+
export type ModelConfig = z.infer<typeof ModelConfigSchema>;
|
|
282
|
+
export type UIConfig = z.infer<typeof UIConfigSchema>;
|
|
283
|
+
export type AutoRouterConfig = z.infer<typeof AutoRouterConfigSchema>;
|
|
284
|
+
export type ThinkingConfig = z.infer<typeof ThinkingConfigSchema>;
|
|
285
|
+
export type PermissionConfig = z.infer<typeof PermissionConfigSchema>;
|
|
286
|
+
export type McpServerConfig = z.infer<typeof McpServerConfigSchema>;
|
|
287
|
+
export type HookConfig = z.infer<typeof HookConfigSchema>;
|
|
288
|
+
export type ClawdConfig = z.infer<typeof ClawdConfigSchema>;
|
|
289
|
+
export type RuntimeConfig = z.infer<typeof RuntimeConfigSchema>;
|
|
290
|
+
|
|
291
|
+
// 向后兼
|
|
292
|
+
export type Config = ClawdConfig;
|
|
293
|
+
|
|
294
|
+
// ========== 字段路由
|
|
295
|
+
|
|
296
|
+
export type MergeStrategy = 'replace' | 'append-dedupe' | 'deep-merge';
|
|
297
|
+
export type ConfigTarget = 'config' | 'settings';
|
|
298
|
+
export type ConfigScope = 'local' | 'project' | 'global';
|
|
299
|
+
|
|
300
|
+
export interface FieldRouting {
|
|
301
|
+
target: ConfigTarget;
|
|
302
|
+
defaultScope: ConfigScope;
|
|
303
|
+
mergeStrategy: MergeStrategy;
|
|
304
|
+
persistable: boolean;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
*
|
|
309
|
+
*/
|
|
310
|
+
export const FIELD_ROUTING_TABLE: Record<string, FieldRouting> = {
|
|
311
|
+
// config.json 字
|
|
312
|
+
models: { target: 'config', defaultScope: 'global', mergeStrategy: 'replace', persistable: true },
|
|
313
|
+
currentModelId: { target: 'config', defaultScope: 'global', mergeStrategy: 'replace', persistable: true },
|
|
314
|
+
theme: { target: 'config', defaultScope: 'global', mergeStrategy: 'replace', persistable: true },
|
|
315
|
+
language: { target: 'config', defaultScope: 'global', mergeStrategy: 'replace', persistable: true },
|
|
316
|
+
mcpServers: { target: 'config', defaultScope: 'global', mergeStrategy: 'deep-merge', persistable: true },
|
|
317
|
+
mcpEnabled: { target: 'config', defaultScope: 'global', mergeStrategy: 'replace', persistable: true },
|
|
318
|
+
autoRouter: { target: 'config', defaultScope: 'global', mergeStrategy: 'deep-merge', persistable: true },
|
|
319
|
+
thinking: { target: 'config', defaultScope: 'global', mergeStrategy: 'deep-merge', persistable: true },
|
|
320
|
+
|
|
321
|
+
// settings.json 字
|
|
322
|
+
permissions: { target: 'settings', defaultScope: 'local', mergeStrategy: 'replace', persistable: true },
|
|
323
|
+
defaultPermissionMode: { target: 'settings', defaultScope: 'local', mergeStrategy: 'replace', persistable: true },
|
|
324
|
+
hooks: { target: 'settings', defaultScope: 'local', mergeStrategy: 'deep-merge', persistable: true },
|
|
325
|
+
env: { target: 'settings', defaultScope: 'local', mergeStrategy: 'deep-merge', persistable: true },
|
|
326
|
+
|
|
327
|
+
// 非持久化字段(CLI 临时参
|
|
328
|
+
systemPrompt: { target: 'settings', defaultScope: 'local', mergeStrategy: 'replace', persistable: false },
|
|
329
|
+
appendSystemPrompt: { target: 'settings', defaultScope: 'local', mergeStrategy: 'replace', persistable: false },
|
|
330
|
+
initialMessage: { target: 'settings', defaultScope: 'local', mergeStrategy: 'replace', persistable: false },
|
|
331
|
+
resumeSessionId: { target: 'settings', defaultScope: 'local', mergeStrategy: 'replace', persistable: false },
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// ========== 默认配
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
*
|
|
338
|
+
*/
|
|
339
|
+
export const DEFAULT_PERMISSIONS: PermissionConfig = {
|
|
340
|
+
allow: [
|
|
341
|
+
// 安全的系统信息命
|
|
342
|
+
'Bash(pwd)',
|
|
343
|
+
'Bash(whoami)',
|
|
344
|
+
'Bash(hostname)',
|
|
345
|
+
'Bash(uname *)',
|
|
346
|
+
'Bash(date)',
|
|
347
|
+
'Bash(echo *)',
|
|
348
|
+
// 目录列
|
|
349
|
+
'Bash(ls *)',
|
|
350
|
+
'Bash(tree *)',
|
|
351
|
+
// Git 只读命
|
|
352
|
+
'Bash(git status)',
|
|
353
|
+
'Bash(git log *)',
|
|
354
|
+
'Bash(git diff *)',
|
|
355
|
+
'Bash(git branch *)',
|
|
356
|
+
// 包管理器只读命
|
|
357
|
+
'Bash(npm list *)',
|
|
358
|
+
'Bash(npm view *)',
|
|
359
|
+
'Bash(bun *)',
|
|
360
|
+
],
|
|
361
|
+
ask: [
|
|
362
|
+
// 高风险命令(需要确
|
|
363
|
+
'Bash(curl *)',
|
|
364
|
+
'Bash(wget *)',
|
|
365
|
+
'Bash(rm -rf *)',
|
|
366
|
+
'Bash(rm -r *)',
|
|
367
|
+
],
|
|
368
|
+
deny: [
|
|
369
|
+
// 敏感文
|
|
370
|
+
'Read(./.env)',
|
|
371
|
+
'Read(./.env.*)',
|
|
372
|
+
// 危险命
|
|
373
|
+
'Bash(rm -rf /)',
|
|
374
|
+
'Bash(sudo *)',
|
|
375
|
+
'Bash(chmod 777 *)',
|
|
376
|
+
// Shell 嵌
|
|
377
|
+
'Bash(bash *)',
|
|
378
|
+
'Bash(sh *)',
|
|
379
|
+
'Bash(eval *)',
|
|
380
|
+
],
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
*
|
|
385
|
+
*/
|
|
386
|
+
export const DEFAULT_MODELS = [
|
|
387
|
+
{
|
|
388
|
+
id: 'claude-fable-5',
|
|
389
|
+
name: 'Claude Fable 5',
|
|
390
|
+
provider: 'anthropic' as const,
|
|
391
|
+
model: 'claude-fable-5',
|
|
392
|
+
baseURL: 'https://api.anthropic.com/v1',
|
|
393
|
+
apiKey: '',
|
|
394
|
+
allowedTools: ['Read', 'Grep', 'Glob', 'Edit', 'Write', 'Bash'],
|
|
395
|
+
requireConfirmation: false,
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
id: 'claude-sonnet-4',
|
|
399
|
+
name: 'Claude Sonnet 4.6',
|
|
400
|
+
provider: 'anthropic' as const,
|
|
401
|
+
model: 'claude-sonnet-4-6',
|
|
402
|
+
baseURL: 'https://api.anthropic.com/v1',
|
|
403
|
+
apiKey: '',
|
|
404
|
+
allowedTools: ['Read', 'Grep', 'Glob', 'Edit', 'Write', 'Bash'],
|
|
405
|
+
requireConfirmation: false,
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: 'claude-opus-4',
|
|
409
|
+
name: 'Claude Opus 4.8',
|
|
410
|
+
provider: 'anthropic' as const,
|
|
411
|
+
model: 'claude-opus-4-8',
|
|
412
|
+
baseURL: 'https://api.anthropic.com/v1',
|
|
413
|
+
apiKey: '',
|
|
414
|
+
allowedTools: ['Read', 'Grep', 'Glob', 'Edit', 'Write', 'Bash'],
|
|
415
|
+
requireConfirmation: false,
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
id: 'claude-haiku-4',
|
|
419
|
+
name: 'Claude Haiku 4.5',
|
|
420
|
+
provider: 'anthropic' as const,
|
|
421
|
+
model: 'claude-haiku-4-5-20251001',
|
|
422
|
+
baseURL: 'https://api.anthropic.com/v1',
|
|
423
|
+
apiKey: '',
|
|
424
|
+
allowedTools: ['Read', 'Grep', 'Glob', 'Edit', 'Write', 'Bash'],
|
|
425
|
+
requireConfirmation: false,
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
id: 'deepseek-chat',
|
|
429
|
+
name: 'DeepSeek Chat',
|
|
430
|
+
provider: 'openai-compatible' as const,
|
|
431
|
+
model: 'deepseek-chat',
|
|
432
|
+
baseURL: 'https://api.deepseek.com/v1',
|
|
433
|
+
apiKey: '',
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
id: 'deepseek-reasoner',
|
|
437
|
+
name: 'DeepSeek Reasoner',
|
|
438
|
+
provider: 'openai-compatible' as const,
|
|
439
|
+
model: 'deepseek-reasoner',
|
|
440
|
+
baseURL: 'https://api.deepseek.com/v1',
|
|
441
|
+
apiKey: '',
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
id: 'groq-llama',
|
|
445
|
+
name: 'Groq Llama 3.3 70B',
|
|
446
|
+
provider: 'openai-compatible' as const,
|
|
447
|
+
model: 'llama-3.3-70b-versatile',
|
|
448
|
+
baseURL: 'https://api.groq.com/openai/v1',
|
|
449
|
+
apiKey: '',
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
id: 'groq-deepseek',
|
|
453
|
+
name: 'Groq QwQ-32B',
|
|
454
|
+
provider: 'openai-compatible' as const,
|
|
455
|
+
model: 'qwen-qwq-32b',
|
|
456
|
+
baseURL: 'https://api.groq.com/openai/v1',
|
|
457
|
+
apiKey: '',
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
id: 'openai-gpt-5.5',
|
|
461
|
+
name: 'GPT-5.5',
|
|
462
|
+
provider: 'openai-compatible' as const,
|
|
463
|
+
model: 'gpt-5.5',
|
|
464
|
+
baseURL: 'https://api.openai.com/v1',
|
|
465
|
+
apiKey: '',
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
id: 'chatgpt',
|
|
469
|
+
name: 'ChatGPT',
|
|
470
|
+
provider: 'openai-compatible' as const,
|
|
471
|
+
model: 'chatgpt-4o-latest',
|
|
472
|
+
baseURL: 'https://api.openai.com/v1',
|
|
473
|
+
apiKey: '',
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
id: 'openai-gpt-4o',
|
|
477
|
+
name: 'GPT-4o',
|
|
478
|
+
provider: 'openai-compatible' as const,
|
|
479
|
+
model: 'gpt-4o',
|
|
480
|
+
baseURL: 'https://api.openai.com/v1',
|
|
481
|
+
apiKey: '',
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
id: 'openai-o3',
|
|
485
|
+
name: 'OpenAI o3',
|
|
486
|
+
provider: 'openai-compatible' as const,
|
|
487
|
+
model: 'o3',
|
|
488
|
+
baseURL: 'https://api.openai.com/v1',
|
|
489
|
+
apiKey: '',
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
id: 'gemini-2.5-pro',
|
|
493
|
+
name: 'Gemini 2.5 Pro',
|
|
494
|
+
provider: 'openai-compatible' as const,
|
|
495
|
+
model: 'gemini-2.5-pro',
|
|
496
|
+
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
|
|
497
|
+
apiKey: '',
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
id: 'gemini-2.5-flash',
|
|
501
|
+
name: 'Gemini 2.5 Flash',
|
|
502
|
+
provider: 'openai-compatible' as const,
|
|
503
|
+
model: 'gemini-2.5-flash',
|
|
504
|
+
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
|
|
505
|
+
apiKey: '',
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
id: 'ollama-local',
|
|
509
|
+
name: 'Ollama (local)',
|
|
510
|
+
provider: 'openai-compatible' as const,
|
|
511
|
+
model: 'llama3.2',
|
|
512
|
+
baseURL: 'http://localhost:11434/v1',
|
|
513
|
+
apiKey: 'ollama',
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
id: 'sakana-fugu',
|
|
517
|
+
name: 'Sakana Fugu',
|
|
518
|
+
provider: 'openai-compatible' as const,
|
|
519
|
+
model: 'fugu',
|
|
520
|
+
baseURL: 'https://api.sakana.ai/v1',
|
|
521
|
+
apiKey: '',
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
id: 'sakana-fugu-ultra',
|
|
525
|
+
name: 'Sakana Fugu Ultra',
|
|
526
|
+
provider: 'openai-compatible' as const,
|
|
527
|
+
model: 'fugu-ultra',
|
|
528
|
+
baseURL: 'https://api.sakana.ai/v1',
|
|
529
|
+
apiKey: '',
|
|
530
|
+
},
|
|
531
|
+
// Nexus - AEGIS's pooled aegis-key. Auto-routes server-side (smart_router) to the
|
|
532
|
+
// cheapest backend that fits the tier; OpenAI-wire-compatible, billed via token bank.
|
|
533
|
+
{
|
|
534
|
+
id: 'nexus-fast',
|
|
535
|
+
name: 'Nexus (Fast)',
|
|
536
|
+
provider: 'openai-compatible' as const,
|
|
537
|
+
model: 'nexus-fast',
|
|
538
|
+
baseURL: 'https://aegisintel.up.railway.app/api/v1',
|
|
539
|
+
apiKey: '',
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
id: 'nexus-smart',
|
|
543
|
+
name: 'Nexus (Smart)',
|
|
544
|
+
provider: 'openai-compatible' as const,
|
|
545
|
+
model: 'nexus-smart',
|
|
546
|
+
baseURL: 'https://aegisintel.up.railway.app/api/v1',
|
|
547
|
+
apiKey: '',
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
id: 'nexus-neo',
|
|
551
|
+
name: 'Nexus (NEO)',
|
|
552
|
+
provider: 'openai-compatible' as const,
|
|
553
|
+
model: 'nexus-neo',
|
|
554
|
+
baseURL: 'https://aegisintel.up.railway.app/api/v1',
|
|
555
|
+
apiKey: '',
|
|
556
|
+
},
|
|
557
|
+
];
|
|
558
|
+
|
|
559
|
+
export const DEFAULT_CONFIG: ClawdConfig = {
|
|
560
|
+
default: {
|
|
561
|
+
model: 'claude-sonnet-4-6',
|
|
562
|
+
baseURL: 'https://api.anthropic.com/v1',
|
|
563
|
+
apiKey: '',
|
|
564
|
+
},
|
|
565
|
+
models: DEFAULT_MODELS,
|
|
566
|
+
currentModelId: 'claude-sonnet-4',
|
|
567
|
+
temperature: 0.7,
|
|
568
|
+
maxContextTokens: 200000,
|
|
569
|
+
maxOutputTokens: 16384,
|
|
570
|
+
stream: true,
|
|
571
|
+
timeout: 900000, // 15 minutes
|
|
572
|
+
ui: {
|
|
573
|
+
theme: 'dark',
|
|
574
|
+
},
|
|
575
|
+
theme: 'dark',
|
|
576
|
+
language: 'en',
|
|
577
|
+
mcpEnabled: true,
|
|
578
|
+
autoRouter: { enabled: false, tiers: {} },
|
|
579
|
+
thinking: { budget: 'off' },
|
|
580
|
+
mcpServers: {},
|
|
581
|
+
permissions: DEFAULT_PERMISSIONS,
|
|
582
|
+
defaultPermissionMode: 'default',
|
|
583
|
+
maxTurns: -1,
|
|
584
|
+
};
|