aegiscode 3.1.10 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aegis.js +165 -0
- package/package.json +18 -86
- package/LICENSE +0 -21
- package/README.md +0 -394
- package/dist/main.js +0 -2171
- package/gui/run-gui.cjs +0 -13
- package/src/agent/Agent.ts +0 -903
- package/src/agent/SimpleAgent.ts +0 -48
- package/src/agent/index.ts +0 -54
- package/src/agent/orchestrator/AppBuilder.ts +0 -443
- package/src/agent/orchestrator/CouncilAgent.ts +0 -310
- package/src/agent/orchestrator/DiscussionRoom.ts +0 -462
- package/src/agent/orchestrator/OrchestratorAgent.ts +0 -637
- package/src/agent/orchestrator/index.ts +0 -38
- package/src/agent/orchestrator/utils.ts +0 -397
- package/src/agent/pricing.ts +0 -115
- package/src/agent/router.ts +0 -74
- package/src/agent/routerStats.ts +0 -121
- package/src/agent/types.ts +0 -318
- package/src/auth/login.ts +0 -383
- package/src/cli/config.ts +0 -189
- package/src/cli/index.ts +0 -17
- package/src/cli/middleware.ts +0 -119
- package/src/cli/types.ts +0 -75
- package/src/config/ConfigManager.ts +0 -587
- package/src/config/index.ts +0 -7
- package/src/config/types.ts +0 -584
- package/src/context/CompactionService.ts +0 -300
- package/src/context/ContextManager.ts +0 -450
- package/src/context/FileAnalyzer.ts +0 -267
- package/src/context/TokenCounter.ts +0 -265
- package/src/context/index.ts +0 -27
- package/src/context/storage/CacheStore.ts +0 -176
- package/src/context/storage/JSONLStore.ts +0 -201
- package/src/context/storage/MemoryStore.ts +0 -205
- package/src/context/storage/PersistentStore.ts +0 -327
- package/src/context/storage/index.ts +0 -9
- package/src/context/storage/pathUtils.ts +0 -114
- package/src/context/test.ts +0 -309
- package/src/context/types.ts +0 -268
- package/src/hooks/HookExecutor.ts +0 -434
- package/src/hooks/HookManager.ts +0 -596
- package/src/hooks/HookService.ts +0 -269
- package/src/hooks/Matcher.ts +0 -157
- package/src/hooks/index.ts +0 -63
- package/src/hooks/types.ts +0 -424
- package/src/main.tsx +0 -596
- package/src/mcp/HealthMonitor.ts +0 -150
- package/src/mcp/McpClient.ts +0 -491
- package/src/mcp/McpRegistry.ts +0 -321
- package/src/mcp/createMcpTool.ts +0 -251
- package/src/mcp/index.ts +0 -15
- package/src/mcp/server.ts +0 -334
- package/src/mcp/test-server.ts +0 -88
- package/src/mcp/test.ts +0 -372
- package/src/mcp/types.ts +0 -247
- package/src/memory/AgentMemoryBus.ts +0 -432
- package/src/memory/CloudSync.ts +0 -99
- package/src/memory/DriveSync.ts +0 -106
- package/src/memory/SharedMemory.ts +0 -951
- package/src/memory/index.ts +0 -14
- package/src/memory/machineFingerprint.ts +0 -40
- package/src/orchestrator/SubAgentMetadata.ts +0 -136
- package/src/prompts/builder.ts +0 -213
- package/src/prompts/default.ts +0 -144
- package/src/prompts/index.ts +0 -16
- package/src/prompts/plan.ts +0 -64
- package/src/prompts/test.ts +0 -78
- package/src/services/AnthropicChatService.ts +0 -341
- package/src/services/ChatService.ts +0 -347
- package/src/services/ClaudeCliChatService.ts +0 -256
- package/src/services/CloudSync.ts +0 -168
- package/src/services/CostLedger.ts +0 -211
- package/src/services/Heartbeat.ts +0 -135
- package/src/services/LearningCollector.ts +0 -291
- package/src/services/OllamaInstaller.ts +0 -342
- package/src/services/VersionChecker.ts +0 -445
- package/src/services/index.ts +0 -57
- package/src/services/streaming/OpenAIEventAdapter.ts +0 -126
- package/src/services/streaming/RenderingProfile.ts +0 -90
- package/src/services/streaming/StreamEventParser.ts +0 -181
- package/src/services/streaming/ThrottledRenderer.ts +0 -139
- package/src/services/streaming/TranscriptBuffer.ts +0 -574
- package/src/services/streaming/eventStatusMap.ts +0 -52
- package/src/services/streaming/index.ts +0 -46
- package/src/services/streaming/renderFormatting.ts +0 -79
- package/src/services/streaming/types.ts +0 -234
- package/src/skills/SkillLoader.ts +0 -126
- package/src/skills/SkillRegistry.ts +0 -366
- package/src/skills/index.ts +0 -48
- package/src/skills/types.ts +0 -146
- package/src/slash-commands/billing.ts +0 -70
- package/src/slash-commands/build.ts +0 -413
- package/src/slash-commands/builtinCommands.ts +0 -2733
- package/src/slash-commands/clone.ts +0 -242
- package/src/slash-commands/council.ts +0 -125
- package/src/slash-commands/custom/CustomCommandExecutor.ts +0 -143
- package/src/slash-commands/custom/CustomCommandLoader.ts +0 -251
- package/src/slash-commands/custom/CustomCommandRegistry.ts +0 -144
- package/src/slash-commands/custom/index.ts +0 -7
- package/src/slash-commands/debate.ts +0 -254
- package/src/slash-commands/gmail.ts +0 -105
- package/src/slash-commands/index.ts +0 -388
- package/src/slash-commands/mcpCommand.ts +0 -205
- package/src/slash-commands/types.ts +0 -201
- package/src/store/index.ts +0 -76
- package/src/store/selectors.ts +0 -246
- package/src/store/slices/appSlice.ts +0 -205
- package/src/store/slices/commandSlice.ts +0 -115
- package/src/store/slices/configSlice.ts +0 -46
- package/src/store/slices/focusSlice.ts +0 -64
- package/src/store/slices/index.ts +0 -9
- package/src/store/slices/sessionSlice.ts +0 -424
- package/src/store/streaming-buffer.ts +0 -425
- package/src/store/test.ts +0 -296
- package/src/store/types.ts +0 -274
- package/src/store/vanilla.ts +0 -186
- package/src/tools/builtin/bash.ts +0 -236
- package/src/tools/builtin/council.ts +0 -105
- package/src/tools/builtin/edit.ts +0 -213
- package/src/tools/builtin/glob.ts +0 -136
- package/src/tools/builtin/grep.ts +0 -263
- package/src/tools/builtin/index.ts +0 -61
- package/src/tools/builtin/memory.ts +0 -66
- package/src/tools/builtin/read.ts +0 -168
- package/src/tools/builtin/skill.ts +0 -97
- package/src/tools/builtin/snapshot.ts +0 -40
- package/src/tools/builtin/task.ts +0 -106
- package/src/tools/builtin/write.ts +0 -134
- package/src/tools/createTool.ts +0 -221
- package/src/tools/execution/ExecutionPipeline.ts +0 -263
- package/src/tools/execution/index.ts +0 -40
- package/src/tools/execution/stages/CacheStage.ts +0 -131
- package/src/tools/execution/stages/ConfirmationStage.ts +0 -203
- package/src/tools/execution/stages/DiscoveryStage.ts +0 -46
- package/src/tools/execution/stages/ExecutionStage.ts +0 -48
- package/src/tools/execution/stages/FormattingStage.ts +0 -44
- package/src/tools/execution/stages/HookStage.ts +0 -72
- package/src/tools/execution/stages/PermissionStage.ts +0 -287
- package/src/tools/execution/stages/PostHookStage.ts +0 -71
- package/src/tools/execution/stages/index.ts +0 -12
- package/src/tools/execution/test.ts +0 -266
- package/src/tools/execution/types.ts +0 -273
- package/src/tools/index.ts +0 -81
- package/src/tools/registry.ts +0 -304
- package/src/tools/schemas.ts +0 -109
- package/src/tools/test.ts +0 -220
- package/src/tools/types.ts +0 -175
- package/src/tools/validation/PermissionChecker.ts +0 -242
- package/src/tools/validation/SensitiveFileDetector.ts +0 -210
- package/src/tools/validation/index.ts +0 -11
- package/src/ui/App.tsx +0 -166
- package/src/ui/components/AegisInterface.tsx +0 -484
- package/src/ui/components/common/ChatSearch.tsx +0 -150
- package/src/ui/components/common/ErrorBoundary.tsx +0 -82
- package/src/ui/components/common/ExitMessage.tsx +0 -120
- package/src/ui/components/common/LoadingIndicator.tsx +0 -49
- package/src/ui/components/common/index.ts +0 -6
- package/src/ui/components/dialog/ConfirmationPrompt.tsx +0 -208
- package/src/ui/components/dialog/InteractiveSelector.tsx +0 -149
- package/src/ui/components/dialog/SetupWizard.tsx +0 -297
- package/src/ui/components/dialog/UpdatePrompt.tsx +0 -155
- package/src/ui/components/dialog/index.ts +0 -8
- package/src/ui/components/index.ts +0 -28
- package/src/ui/components/input/CommandSuggestions.tsx +0 -139
- package/src/ui/components/input/CustomTextInput.tsx +0 -220
- package/src/ui/components/input/InputArea.tsx +0 -361
- package/src/ui/components/input/PromptSuggestions.tsx +0 -66
- package/src/ui/components/input/index.ts +0 -6
- package/src/ui/components/layout/ChatStatusBar.tsx +0 -90
- package/src/ui/components/layout/ContextBar.tsx +0 -79
- package/src/ui/components/layout/MessageArea.tsx +0 -96
- package/src/ui/components/layout/MessageList.tsx +0 -647
- package/src/ui/components/layout/MessageSeparator.tsx +0 -26
- package/src/ui/components/layout/WelcomeMessage.tsx +0 -93
- package/src/ui/components/layout/index.ts +0 -7
- package/src/ui/components/markdown/CodeHighlighter.tsx +0 -292
- package/src/ui/components/markdown/MessageRenderer.tsx +0 -1211
- package/src/ui/components/markdown/index.ts +0 -8
- package/src/ui/components/markdown/parser.ts +0 -336
- package/src/ui/components/markdown/types.ts +0 -66
- package/src/ui/focus/FocusManager.ts +0 -137
- package/src/ui/focus/index.ts +0 -13
- package/src/ui/focus/types.ts +0 -54
- package/src/ui/focus/useFocus.ts +0 -75
- package/src/ui/hooks/index.ts +0 -11
- package/src/ui/hooks/useAgent.ts +0 -284
- package/src/ui/hooks/useCommandHistory.ts +0 -87
- package/src/ui/hooks/useCommandProcessor.ts +0 -443
- package/src/ui/hooks/useConfirmation.ts +0 -99
- package/src/ui/hooks/useCtrlCHandler.ts +0 -100
- package/src/ui/hooks/useInputBuffer.ts +0 -122
- package/src/ui/hooks/useTerminalSize.ts +0 -68
- package/src/ui/hooks/useTerminalWidth.ts +0 -5
- package/src/ui/hooks/useWindowedList.ts +0 -118
- package/src/ui/render-debugger.ts +0 -621
- package/src/ui/test.ts +0 -189
- package/src/ui/themes/ThemeManager.ts +0 -332
- package/src/ui/themes/aegisTheme.ts +0 -87
- package/src/ui/themes/darkTheme.ts +0 -87
- package/src/ui/themes/defaultTheme.ts +0 -85
- package/src/ui/themes/index.ts +0 -10
- package/src/ui/themes/lightTheme.ts +0 -89
- package/src/ui/themes/popularThemes.ts +0 -187
- package/src/ui/themes/types.ts +0 -130
- package/src/utils/clipboard.ts +0 -48
- package/src/utils/debug.ts +0 -43
- package/src/utils/environment.ts +0 -68
- package/src/utils/index.ts +0 -10
|
@@ -1,587 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ConfigManager - 配置管理器(双文件配置架构)
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* - config.json: 基础配置(API、模型、UI、MCP)
|
|
6
|
-
* - settings.json: 行为配置(权限、Hooks、环境变量)
|
|
7
|
-
* - settings.local.json: 本地行为配置(不提交到 Git)
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 1. 默认配置
|
|
11
|
-
* 2. 用户 config.json (~/.aegiscode/config.json)
|
|
12
|
-
* 3. 用户 settings.json (~/.aegiscode/settings.json)
|
|
13
|
-
* 4. 项目 config.json (./.aegiscode/config.json)
|
|
14
|
-
* 5. 项目 settings.json (./.aegiscode/settings.json)
|
|
15
|
-
* 6. 本地 settings.local.json (./.aegiscode/settings.local.json)
|
|
16
|
-
* 7. 环境变量
|
|
17
|
-
* 8. CLI 参数
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import * as fs from 'node:fs';
|
|
21
|
-
import * as path from 'node:path';
|
|
22
|
-
import * as os from 'node:os';
|
|
23
|
-
import {
|
|
24
|
-
Config,
|
|
25
|
-
ConfigSchema,
|
|
26
|
-
DEFAULT_CONFIG,
|
|
27
|
-
ModelConfig,
|
|
28
|
-
type PermissionConfig,
|
|
29
|
-
type McpServerConfig,
|
|
30
|
-
} from './types.js';
|
|
31
|
-
|
|
32
|
-
export class ConfigManager {
|
|
33
|
-
private static instance: ConfigManager;
|
|
34
|
-
private config: Config;
|
|
35
|
-
private configPaths: string[] = [];
|
|
36
|
-
|
|
37
|
-
private constructor() {
|
|
38
|
-
this.config = { ...DEFAULT_CONFIG };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
static getInstance(): ConfigManager {
|
|
45
|
-
if (!ConfigManager.instance) {
|
|
46
|
-
ConfigManager.instance = new ConfigManager();
|
|
47
|
-
}
|
|
48
|
-
return ConfigManager.instance;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
* @returns 加载后的配置
|
|
54
|
-
*/
|
|
55
|
-
async initialize(projectPath?: string): Promise<Config> {
|
|
56
|
-
// 1. 从默认配置开
|
|
57
|
-
this.config = { ...DEFAULT_CONFIG };
|
|
58
|
-
|
|
59
|
-
const userConfigDir = this.getUserConfigDir();
|
|
60
|
-
const projectDir = projectPath || process.cwd();
|
|
61
|
-
const projectConfigDir = path.join(projectDir, '.aegiscode');
|
|
62
|
-
|
|
63
|
-
// 2. 加载用
|
|
64
|
-
await this.loadConfigFile(path.join(userConfigDir, 'config.json'));
|
|
65
|
-
|
|
66
|
-
// 3. 加载用
|
|
67
|
-
await this.loadConfigFile(path.join(userConfigDir, 'settings.json'));
|
|
68
|
-
|
|
69
|
-
// 4. 加载项
|
|
70
|
-
await this.loadConfigFile(path.join(projectConfigDir, 'config.json'));
|
|
71
|
-
|
|
72
|
-
// 5. 加载项
|
|
73
|
-
await this.loadConfigFile(path.join(projectConfigDir, 'settings.json'));
|
|
74
|
-
|
|
75
|
-
// 6. 加载本地 settings.local.json(不提交
|
|
76
|
-
await this.loadConfigFile(path.join(projectConfigDir, 'settings.local.json'));
|
|
77
|
-
|
|
78
|
-
// 7. 应用环境变
|
|
79
|
-
this.applyEnvironmentVariables();
|
|
80
|
-
|
|
81
|
-
return this.config;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
*/
|
|
87
|
-
getUserConfigDir(): string {
|
|
88
|
-
return path.join(os.homedir(), '.aegiscode');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
getUserConfigPath(): string {
|
|
95
|
-
return path.join(this.getUserConfigDir(), 'config.json');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
*/
|
|
101
|
-
private async loadConfigFile(configPath: string): Promise<boolean> {
|
|
102
|
-
try {
|
|
103
|
-
if (!fs.existsSync(configPath)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const content = fs.readFileSync(configPath, 'utf-8');
|
|
108
|
-
const parsed = JSON.parse(content);
|
|
109
|
-
|
|
110
|
-
// Backward compat: if root has apiKey/baseURL/model, wrap in 'default'
|
|
111
|
-
if (parsed.apiKey || parsed.baseURL || parsed.baseUrl || parsed.model) {
|
|
112
|
-
if (!parsed.default) {
|
|
113
|
-
parsed.default = {};
|
|
114
|
-
}
|
|
115
|
-
if (parsed.apiKey && !parsed.default.apiKey) parsed.default.apiKey = parsed.apiKey;
|
|
116
|
-
if (parsed.baseURL && !parsed.default.baseURL) parsed.default.baseURL = parsed.baseURL;
|
|
117
|
-
if (parsed.baseUrl && !parsed.default.baseURL) parsed.default.baseURL = parsed.baseUrl;
|
|
118
|
-
if (parsed.model && !parsed.default.model) parsed.default.model = parsed.model;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const validated = ConfigSchema.partial().parse(parsed);
|
|
122
|
-
|
|
123
|
-
// 深度合并配
|
|
124
|
-
this.config = this.mergeConfig(this.config, validated);
|
|
125
|
-
this.configPaths.push(configPath);
|
|
126
|
-
|
|
127
|
-
return true;
|
|
128
|
-
} catch (error) {
|
|
129
|
-
console.warn(`Warning: Failed to load config from ${configPath}:`, (error as Error).message);
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
*
|
|
137
|
-
*/
|
|
138
|
-
private applyEnvironmentVariables(): void {
|
|
139
|
-
// Load ~/.aegiscode/.env
|
|
140
|
-
try {
|
|
141
|
-
const lines = (fs.existsSync(path.join(os.homedir(), '.aegiscode', '.env')) ? fs.readFileSync(path.join(os.homedir(), '.aegiscode', '.env'), 'utf8') : '').split('\n');
|
|
142
|
-
for (const line of lines) {
|
|
143
|
-
const eq = line.indexOf('=');
|
|
144
|
-
if (eq < 0 || line.trim().startsWith('#')) continue;
|
|
145
|
-
const k = line.slice(0, eq).trim();
|
|
146
|
-
const v = line.slice(eq + 1).trim().replace(/^["']|["']$/g, '');
|
|
147
|
-
if (k && v && !v.startsWith('YOUR_') && !process.env[k]) process.env[k] = v;
|
|
148
|
-
}
|
|
149
|
-
} catch {}
|
|
150
|
-
|
|
151
|
-
this.config.default = this.config.default || {};
|
|
152
|
-
const defaultConfig = this.config.default;
|
|
153
|
-
|
|
154
|
-
// Normalize baseUrl -> baseURL
|
|
155
|
-
if (!defaultConfig.baseURL && (defaultConfig as any).baseUrl) {
|
|
156
|
-
defaultConfig.baseURL = (defaultConfig as any).baseUrl;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Inject env keys into each model by provider
|
|
160
|
-
const allModels: any[] = (this.config as any).models || [];
|
|
161
|
-
for (const m of allModels) {
|
|
162
|
-
const bu: string = m.baseURL || m.baseUrl || '';
|
|
163
|
-
// Claude Code Pro/Max subscription OAuth token (from `claude setup-token`,
|
|
164
|
-
// or `aegis login --claude-pro`) works as a drop-in for ANTHROPIC_API_KEY
|
|
165
|
-
// against the same model — it does not change which model is selected.
|
|
166
|
-
// It takes priority over ANTHROPIC_API_KEY: logging in with --claude-pro
|
|
167
|
-
// is a deliberate choice and shouldn't be shadowed by a stale/out-of-credit
|
|
168
|
-
// API key still sitting in the environment.
|
|
169
|
-
if (bu.includes('anthropic') && process.env.CLAUDE_CODE_OAUTH_TOKEN) {
|
|
170
|
-
m.apiKey = process.env.CLAUDE_CODE_OAUTH_TOKEN;
|
|
171
|
-
} else if (bu.includes('anthropic') && process.env.ANTHROPIC_API_KEY) {
|
|
172
|
-
m.apiKey = process.env.ANTHROPIC_API_KEY;
|
|
173
|
-
} else if (bu.includes('deepseek') && process.env.DEEPSEEK_API_KEY) {
|
|
174
|
-
m.apiKey = process.env.DEEPSEEK_API_KEY;
|
|
175
|
-
} else if (bu.includes('groq') && process.env.GROQ_API_KEY) {
|
|
176
|
-
m.apiKey = process.env.GROQ_API_KEY;
|
|
177
|
-
} else if (bu.includes('sakana') && process.env.SAKANA_API_KEY) {
|
|
178
|
-
m.apiKey = process.env.SAKANA_API_KEY;
|
|
179
|
-
} else if (bu.includes('googleapis') && process.env.GEMINI_API_KEY) {
|
|
180
|
-
m.apiKey = process.env.GEMINI_API_KEY;
|
|
181
|
-
} else if (bu.includes('aegisintel') && process.env.NEXUS_API_KEY) {
|
|
182
|
-
// Nexus - AEGIS's pooled aegis-key, auto-routed across providers server-side.
|
|
183
|
-
// OpenAI-wire-compatible (streaming + tool_calls), billed via the token bank.
|
|
184
|
-
m.apiKey = process.env.NEXUS_API_KEY;
|
|
185
|
-
} else if (bu.includes('openai.com') && process.env.OPENAI_API_KEY) {
|
|
186
|
-
// Google's OpenAI-compatibility endpoint is
|
|
187
|
-
// generativelanguage.googleapis.com/v1beta/openai/ — it contains the
|
|
188
|
-
// bare substring "openai", so when GEMINI_API_KEY isn't set this
|
|
189
|
-
// branch's old `bu.includes('openai')` check fell through and matched
|
|
190
|
-
// it anyway, handing Gemini models the OpenAI key (wrong key format,
|
|
191
|
-
// Google's API rejects it with a bare 400). 'openai.com' only matches
|
|
192
|
-
// the real api.openai.com host.
|
|
193
|
-
m.apiKey = process.env.OPENAI_API_KEY;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// currentModelId defaults to a Claude model regardless of which provider's key
|
|
198
|
-
// the user actually set (env var, .env, or SetupWizard — none of them touch
|
|
199
|
-
// currentModelId). If the selected model still has no key but a key was found
|
|
200
|
-
// for a different provider above, switch to that model so getDefaultModel()
|
|
201
|
-
// doesn't keep returning a keyless Claude entry and reporting "No API key configured".
|
|
202
|
-
{
|
|
203
|
-
const currentId = (this.config as any).currentModelId;
|
|
204
|
-
const selected = allModels.find((m: any) => m.id === currentId);
|
|
205
|
-
if (!selected?.apiKey) {
|
|
206
|
-
const fallback = allModels.find((m: any) => m.apiKey);
|
|
207
|
-
if (fallback) (this.config as any).currentModelId = fallback.id;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Use currentModelId to pick the right default — don't override with env key priority
|
|
212
|
-
if (!defaultConfig.apiKey) {
|
|
213
|
-
const currentId = (this.config as any).currentModelId;
|
|
214
|
-
const currentModel = allModels.find((m: any) => m.id === currentId);
|
|
215
|
-
if (currentModel && currentModel.apiKey) {
|
|
216
|
-
defaultConfig.apiKey = currentModel.apiKey;
|
|
217
|
-
defaultConfig.baseURL = currentModel.baseURL || currentModel.baseUrl;
|
|
218
|
-
defaultConfig.model = currentModel.model;
|
|
219
|
-
} else if (process.env.DEEPSEEK_API_KEY) {
|
|
220
|
-
defaultConfig.apiKey = process.env.DEEPSEEK_API_KEY;
|
|
221
|
-
defaultConfig.baseURL = 'https://api.deepseek.com/v1';
|
|
222
|
-
defaultConfig.model = 'deepseek-chat';
|
|
223
|
-
} else if (process.env.GROQ_API_KEY) {
|
|
224
|
-
defaultConfig.apiKey = process.env.GROQ_API_KEY;
|
|
225
|
-
defaultConfig.baseURL = 'https://api.groq.com/openai/v1';
|
|
226
|
-
defaultConfig.model = 'llama-3.3-70b-versatile';
|
|
227
|
-
} else if (process.env.OPENAI_API_KEY) {
|
|
228
|
-
defaultConfig.apiKey = process.env.OPENAI_API_KEY;
|
|
229
|
-
if (process.env.OPENAI_BASE_URL) defaultConfig.baseURL = process.env.OPENAI_BASE_URL;
|
|
230
|
-
if (process.env.OPENAI_MODEL) defaultConfig.model = process.env.OPENAI_MODEL;
|
|
231
|
-
else if (!defaultConfig.model) defaultConfig.model = 'gpt-4o';
|
|
232
|
-
} else if (process.env.CLAUDE_CODE_OAUTH_TOKEN) {
|
|
233
|
-
defaultConfig.apiKey = process.env.CLAUDE_CODE_OAUTH_TOKEN;
|
|
234
|
-
defaultConfig.baseURL = 'https://api.anthropic.com/v1';
|
|
235
|
-
defaultConfig.model = defaultConfig.model || 'claude-sonnet-4-6';
|
|
236
|
-
} else if (process.env.ANTHROPIC_API_KEY) {
|
|
237
|
-
defaultConfig.apiKey = process.env.ANTHROPIC_API_KEY;
|
|
238
|
-
defaultConfig.baseURL = 'https://api.anthropic.com/v1';
|
|
239
|
-
defaultConfig.model = defaultConfig.model || 'claude-sonnet-4-6';
|
|
240
|
-
} else if (process.env.NEXUS_API_KEY) {
|
|
241
|
-
defaultConfig.apiKey = process.env.NEXUS_API_KEY;
|
|
242
|
-
defaultConfig.baseURL = 'https://aegisintel.up.railway.app/api/v1';
|
|
243
|
-
defaultConfig.model = defaultConfig.model || 'nexus-smart';
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
*
|
|
250
|
-
*/
|
|
251
|
-
applyCliArgs(args: Partial<ModelConfig>): void {
|
|
252
|
-
this.config.default = this.config.default || {};
|
|
253
|
-
const defaultConfig = this.config.default;
|
|
254
|
-
|
|
255
|
-
if (args.apiKey) {
|
|
256
|
-
defaultConfig.apiKey = args.apiKey;
|
|
257
|
-
}
|
|
258
|
-
if (args.baseURL) {
|
|
259
|
-
defaultConfig.baseURL = args.baseURL;
|
|
260
|
-
}
|
|
261
|
-
if (args.model) {
|
|
262
|
-
const models: any[] = (this.config as any).models || [];
|
|
263
|
-
const found = models.find((m: any) => m.id === args.model || m.model === args.model);
|
|
264
|
-
if (found) {
|
|
265
|
-
// args.model is a model ID — switch fully to that model's config
|
|
266
|
-
(this.config as any).currentModelId = found.id;
|
|
267
|
-
this.config.default = { ...defaultConfig, ...found };
|
|
268
|
-
} else {
|
|
269
|
-
defaultConfig.model = args.model;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
*
|
|
276
|
-
*/
|
|
277
|
-
private mergeConfig(base: Config, override: Partial<Config>): Config {
|
|
278
|
-
const merged: Config = {
|
|
279
|
-
...base,
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
if (override.default || base.default) {
|
|
283
|
-
merged.default = {
|
|
284
|
-
...base.default,
|
|
285
|
-
...override.default,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (override.models) {
|
|
290
|
-
merged.models = override.models;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (override.ui || base.ui) {
|
|
294
|
-
merged.ui = {
|
|
295
|
-
...base.ui,
|
|
296
|
-
...override.ui,
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// 合并权限配置(数组合并而非覆
|
|
301
|
-
if (override.permissions || base.permissions) {
|
|
302
|
-
merged.permissions = {
|
|
303
|
-
allow: [
|
|
304
|
-
...(base.permissions?.allow || []),
|
|
305
|
-
...(override.permissions?.allow || []),
|
|
306
|
-
],
|
|
307
|
-
deny: [
|
|
308
|
-
...(base.permissions?.deny || []),
|
|
309
|
-
...(override.permissions?.deny || []),
|
|
310
|
-
],
|
|
311
|
-
ask: [
|
|
312
|
-
...(base.permissions?.ask || []),
|
|
313
|
-
...(override.permissions?.ask || []),
|
|
314
|
-
],
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// currentModelId — explicit merge
|
|
319
|
-
if ((override as any).currentModelId) {
|
|
320
|
-
(merged as any).currentModelId = (override as any).currentModelId;
|
|
321
|
-
}
|
|
322
|
-
// 其他字段使用后者覆
|
|
323
|
-
if (override.defaultPermissionMode) {
|
|
324
|
-
merged.defaultPermissionMode = override.defaultPermissionMode;
|
|
325
|
-
}
|
|
326
|
-
if (override.toolWhitelist) {
|
|
327
|
-
merged.toolWhitelist = override.toolWhitelist;
|
|
328
|
-
}
|
|
329
|
-
if (override.toolBlacklist) {
|
|
330
|
-
merged.toolBlacklist = override.toolBlacklist;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// 合并 MCP 服务器配置(深度合
|
|
334
|
-
if (override.mcpServers || base.mcpServers) {
|
|
335
|
-
merged.mcpServers = {
|
|
336
|
-
...(base.mcpServers || {}),
|
|
337
|
-
...(override.mcpServers || {}),
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// MCP 启用状
|
|
342
|
-
if (override.mcpEnabled !== undefined) {
|
|
343
|
-
merged.mcpEnabled = override.mcpEnabled;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// 合并 Hooks 配置(深度合
|
|
347
|
-
if (override.hooks || base.hooks) {
|
|
348
|
-
merged.hooks = {
|
|
349
|
-
...(base.hooks || {}),
|
|
350
|
-
...(override.hooks || {}),
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
return merged;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
*
|
|
359
|
-
*/
|
|
360
|
-
getConfig(): Config {
|
|
361
|
-
return this.config;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
*
|
|
366
|
-
*/
|
|
367
|
-
getDefaultModel(): ModelConfig {
|
|
368
|
-
// Prefer currentModelId from config
|
|
369
|
-
// Läs currentModelId direkt från fil (Zod strippar det)
|
|
370
|
-
let currentId = (this.config as any).currentModelId;
|
|
371
|
-
if (!currentId) {
|
|
372
|
-
try {
|
|
373
|
-
const raw = JSON.parse(fs.readFileSync(
|
|
374
|
-
path.join(os.homedir(), '.aegiscode', 'config.json'), 'utf8'
|
|
375
|
-
));
|
|
376
|
-
currentId = raw.currentModelId;
|
|
377
|
-
} catch {}
|
|
378
|
-
}
|
|
379
|
-
const models: any[] = (this.config as any).models || [];
|
|
380
|
-
if (currentId && models.length > 0) {
|
|
381
|
-
let found = models.find((m: any) => m.id === currentId);
|
|
382
|
-
// Fallback: match by model name
|
|
383
|
-
if (!found) found = models.find((m: any) => m.model === currentId);
|
|
384
|
-
if (found) {
|
|
385
|
-
const result: any = { ...found };
|
|
386
|
-
if (!result.baseURL && result.baseUrl) result.baseURL = result.baseUrl;
|
|
387
|
-
return result;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
// Fallback to default
|
|
391
|
-
const base: any = { ...(this.config.default ?? {}) };
|
|
392
|
-
if (!base.baseURL && base.baseUrl) base.baseURL = base.baseUrl;
|
|
393
|
-
return base;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
*
|
|
398
|
-
*/
|
|
399
|
-
getLoadedConfigPaths(): string[] {
|
|
400
|
-
return [...this.configPaths];
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
*
|
|
405
|
-
*/
|
|
406
|
-
getPermissionConfig(): PermissionConfig {
|
|
407
|
-
return this.config.permissions || { allow: [], deny: [], ask: [] };
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Hämta modellspecifika verktygsbegränsningar
|
|
412
|
-
*
|
|
413
|
-
*/
|
|
414
|
-
getModelToolRestrictions(modelId?: string): { allowedTools?: string[]; disallowedTools?: string[] } {
|
|
415
|
-
if (!modelId) return {};
|
|
416
|
-
const models: any[] = (this.config as any).models || [];
|
|
417
|
-
let model = models.find((m: any) => m.id === modelId);
|
|
418
|
-
if (!model) model = models.find((m: any) => m.model === modelId);
|
|
419
|
-
if (!model && (this.config.default as any)?.model === modelId) {
|
|
420
|
-
model = this.config.default;
|
|
421
|
-
}
|
|
422
|
-
if (!model) return {};
|
|
423
|
-
return {
|
|
424
|
-
allowedTools: model.allowedTools,
|
|
425
|
-
disallowedTools: model.disallowedTools,
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
*
|
|
431
|
-
*/
|
|
432
|
-
getDefaultPermissionMode(): string {
|
|
433
|
-
return this.config.defaultPermissionMode || 'default';
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Update the default permission mode at runtime (used by /yolo toggle).
|
|
438
|
-
* This keeps ConfigManager in sync with config file changes without a full reload.
|
|
439
|
-
*/
|
|
440
|
-
setDefaultPermissionMode(mode: 'default' | 'autoEdit' | 'yolo' | 'plan'): void {
|
|
441
|
-
this.config.defaultPermissionMode = mode;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
*
|
|
446
|
-
*/
|
|
447
|
-
getMcpServers(): Record<string, McpServerConfig> {
|
|
448
|
-
return this.config.mcpServers || {};
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
*
|
|
453
|
-
*/
|
|
454
|
-
isMcpEnabled(): boolean {
|
|
455
|
-
return this.config.mcpEnabled !== false;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Extended-thinking budget tier — drives `thinking`/`output_config.effort`
|
|
460
|
-
* on the native Anthropic request path. Defaults to 'off'.
|
|
461
|
-
*/
|
|
462
|
-
getThinkingBudget(): 'off' | 'low' | 'medium' | 'high' | 'max' {
|
|
463
|
-
return this.config.thinking?.budget || 'off';
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
*
|
|
468
|
-
*/
|
|
469
|
-
async createDefaultConfig(): Promise<string> {
|
|
470
|
-
const configDir = this.getUserConfigDir();
|
|
471
|
-
const configPath = this.getUserConfigPath();
|
|
472
|
-
|
|
473
|
-
// 创建目
|
|
474
|
-
if (!fs.existsSync(configDir)) {
|
|
475
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// 写入默认配置(不包含敏感信
|
|
479
|
-
const defaultConfig: Config = {
|
|
480
|
-
default: {
|
|
481
|
-
model: 'claude-sonnet-4-6',
|
|
482
|
-
// apiKey: 'your-api-key', // 需要用户自己填
|
|
483
|
-
// baseURL: 'https://api.openai.com/v1',
|
|
484
|
-
},
|
|
485
|
-
ui: {
|
|
486
|
-
theme: 'dark',
|
|
487
|
-
},
|
|
488
|
-
mcpEnabled: true,
|
|
489
|
-
mcpServers: {
|
|
490
|
-
// 示例 MCP 服务器配置(已注
|
|
491
|
-
// github: {
|
|
492
|
-
// type: 'stdio',
|
|
493
|
-
// command: 'npx',
|
|
494
|
-
// args: ['-y', '@modelcontextprotocol/server-github'],
|
|
495
|
-
// env: { GITHUB_TOKEN: '${GITHUB_TOKEN}' },
|
|
496
|
-
// },
|
|
497
|
-
},
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
const content = JSON.stringify(defaultConfig, null, 2);
|
|
501
|
-
fs.writeFileSync(configPath, content, 'utf-8');
|
|
502
|
-
|
|
503
|
-
return configPath;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
*
|
|
508
|
-
*/
|
|
509
|
-
isConfigValid(): boolean {
|
|
510
|
-
return !!this.config.default?.apiKey;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*/
|
|
519
|
-
getTheme(): string | null {
|
|
520
|
-
// 优先读取用户配置中的主题(用户主动设置
|
|
521
|
-
const userConfigPath = this.getUserConfigPath();
|
|
522
|
-
|
|
523
|
-
if (fs.existsSync(userConfigPath)) {
|
|
524
|
-
try {
|
|
525
|
-
const content = fs.readFileSync(userConfigPath, 'utf-8');
|
|
526
|
-
const userConfig = JSON.parse(content);
|
|
527
|
-
|
|
528
|
-
// 如果用户配置中有明确设置的主题,使用
|
|
529
|
-
if (userConfig.theme) {
|
|
530
|
-
return userConfig.theme;
|
|
531
|
-
}
|
|
532
|
-
if (userConfig.ui?.theme) {
|
|
533
|
-
return userConfig.ui.theme;
|
|
534
|
-
}
|
|
535
|
-
} catch {
|
|
536
|
-
// 解析失败,返
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// 没有用户设置的主题,返回 null 表示应该自动检
|
|
541
|
-
return null;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
*
|
|
546
|
-
*/
|
|
547
|
-
saveTheme(themeName: string): void {
|
|
548
|
-
const configPath = this.getUserConfigPath();
|
|
549
|
-
const configDir = this.getUserConfigDir();
|
|
550
|
-
|
|
551
|
-
// 确保目录存
|
|
552
|
-
if (!fs.existsSync(configDir)) {
|
|
553
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// 读取现有配置或创建新配
|
|
557
|
-
let existingConfig: Partial<Config> = {};
|
|
558
|
-
if (fs.existsSync(configPath)) {
|
|
559
|
-
try {
|
|
560
|
-
const content = fs.readFileSync(configPath, 'utf-8');
|
|
561
|
-
existingConfig = JSON.parse(content);
|
|
562
|
-
} catch {
|
|
563
|
-
// 如果解析失败,使用空配
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// 更新主
|
|
568
|
-
existingConfig.theme = themeName;
|
|
569
|
-
if (!existingConfig.ui) {
|
|
570
|
-
existingConfig.ui = {};
|
|
571
|
-
}
|
|
572
|
-
existingConfig.ui.theme = themeName;
|
|
573
|
-
|
|
574
|
-
// 同时更新内存中的配
|
|
575
|
-
this.config.theme = themeName;
|
|
576
|
-
if (this.config.ui) {
|
|
577
|
-
this.config.ui.theme = themeName;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// 写入文
|
|
581
|
-
const content = JSON.stringify(existingConfig, null, 2);
|
|
582
|
-
fs.writeFileSync(configPath, content, 'utf-8');
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// 导出单
|
|
587
|
-
export const configManager = ConfigManager.getInstance();
|