claude-coder 1.8.2 → 1.8.3
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 +167 -167
- package/bin/cli.js +172 -172
- package/package.json +52 -52
- package/src/commands/auth.js +290 -240
- package/src/commands/setup-modules/helpers.js +99 -99
- package/src/commands/setup-modules/index.js +25 -25
- package/src/commands/setup-modules/mcp.js +94 -94
- package/src/commands/setup-modules/provider.js +260 -260
- package/src/commands/setup-modules/safety.js +61 -61
- package/src/commands/setup-modules/simplify.js +52 -52
- package/src/commands/setup.js +172 -172
- package/src/common/assets.js +236 -236
- package/src/common/config.js +125 -125
- package/src/common/constants.js +55 -55
- package/src/common/indicator.js +222 -222
- package/src/common/interaction.js +170 -170
- package/src/common/logging.js +77 -77
- package/src/common/sdk.js +50 -50
- package/src/common/tasks.js +88 -88
- package/src/common/utils.js +161 -161
- package/src/core/coding.js +55 -55
- package/src/core/context.js +117 -117
- package/src/core/go.js +310 -310
- package/src/core/harness.js +484 -484
- package/src/core/hooks.js +533 -533
- package/src/core/init.js +171 -171
- package/src/core/plan.js +325 -325
- package/src/core/prompts.js +227 -227
- package/src/core/query.js +49 -49
- package/src/core/repair.js +46 -46
- package/src/core/runner.js +195 -195
- package/src/core/scan.js +89 -89
- package/src/core/session.js +56 -56
- package/src/core/simplify.js +53 -52
- package/templates/bash-process.md +12 -12
- package/templates/codingSystem.md +65 -65
- package/templates/codingUser.md +17 -17
- package/templates/coreProtocol.md +29 -29
- package/templates/goSystem.md +130 -130
- package/templates/guidance.json +52 -52
- package/templates/planSystem.md +78 -78
- package/templates/planUser.md +8 -8
- package/templates/playwright.md +16 -16
- package/templates/requirements.example.md +57 -57
- package/templates/scanSystem.md +120 -120
- package/templates/scanUser.md +10 -10
- package/templates/test_rule.md +194 -194
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { ask } = require('./helpers');
|
|
4
|
-
const { log, COLOR, updateEnvVar } = require('../../common/config');
|
|
5
|
-
|
|
6
|
-
// ── 自动审查配置 ──
|
|
7
|
-
|
|
8
|
-
async function updateSimplifyConfig(rl, existing) {
|
|
9
|
-
const currentInterval = existing.SIMPLIFY_INTERVAL ?? '5';
|
|
10
|
-
const currentCommits = existing.SIMPLIFY_COMMITS ?? '5';
|
|
11
|
-
|
|
12
|
-
console.log(`${COLOR.blue}自动代码审查配置:${COLOR.reset}`);
|
|
13
|
-
console.log(` 当前状态: ${currentInterval === '0' ? '禁用' : `每 ${currentInterval} 个 session 运行一次`}`);
|
|
14
|
-
console.log(` 审查范围: ${currentCommits} 个 commit`);
|
|
15
|
-
console.log('');
|
|
16
|
-
console.log(`${COLOR.yellow}说明:${COLOR.reset}`);
|
|
17
|
-
console.log(' 自动审查 — 在 run() 循环中定期运行代码审查,检查代码复用性、质量、效率');
|
|
18
|
-
console.log(' 审查间隔 — 每 N 个成功的 session 后运行一次(0 = 禁用)');
|
|
19
|
-
console.log(' 审查范围 — 审查最近 N 个 commit 的代码变更');
|
|
20
|
-
console.log('');
|
|
21
|
-
|
|
22
|
-
const intervalInput = await ask(rl, `审查间隔(输入 0 禁用,回车保留 ${currentInterval === '0' ? '禁用' : currentInterval}): `);
|
|
23
|
-
if (intervalInput.trim()) {
|
|
24
|
-
const interval = parseInt(intervalInput.trim(), 10);
|
|
25
|
-
if (isNaN(interval) || interval < 0) {
|
|
26
|
-
log('warn', '请输入 >= 0 的整数,跳过');
|
|
27
|
-
} else {
|
|
28
|
-
updateEnvVar('SIMPLIFY_INTERVAL', String(interval));
|
|
29
|
-
log('ok', `自动审查已${interval === 0 ? '禁用' : `设置为每 ${interval} 个 session 运行一次`}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const effectiveInterval = intervalInput.trim()
|
|
34
|
-
? String(parseInt(intervalInput.trim(), 10) || 0)
|
|
35
|
-
: currentInterval;
|
|
36
|
-
if (effectiveInterval !== '0') {
|
|
37
|
-
console.log('');
|
|
38
|
-
const commitsInput = await ask(rl, `审查 commit 数量(回车保留 ${currentCommits}): `);
|
|
39
|
-
if (commitsInput.trim()) {
|
|
40
|
-
const commits = parseInt(commitsInput.trim(), 10);
|
|
41
|
-
if (isNaN(commits) || commits < 1) {
|
|
42
|
-
log('warn', '请输入 >= 1 的整数,跳过');
|
|
43
|
-
} else {
|
|
44
|
-
updateEnvVar('SIMPLIFY_COMMITS', String(commits));
|
|
45
|
-
log('ok', `审查范围已设置为 ${commits} 个 commit`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = {
|
|
52
|
-
updateSimplifyConfig,
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { ask } = require('./helpers');
|
|
4
|
+
const { log, COLOR, updateEnvVar } = require('../../common/config');
|
|
5
|
+
|
|
6
|
+
// ── 自动审查配置 ──
|
|
7
|
+
|
|
8
|
+
async function updateSimplifyConfig(rl, existing) {
|
|
9
|
+
const currentInterval = existing.SIMPLIFY_INTERVAL ?? '5';
|
|
10
|
+
const currentCommits = existing.SIMPLIFY_COMMITS ?? '5';
|
|
11
|
+
|
|
12
|
+
console.log(`${COLOR.blue}自动代码审查配置:${COLOR.reset}`);
|
|
13
|
+
console.log(` 当前状态: ${currentInterval === '0' ? '禁用' : `每 ${currentInterval} 个 session 运行一次`}`);
|
|
14
|
+
console.log(` 审查范围: ${currentCommits} 个 commit`);
|
|
15
|
+
console.log('');
|
|
16
|
+
console.log(`${COLOR.yellow}说明:${COLOR.reset}`);
|
|
17
|
+
console.log(' 自动审查 — 在 run() 循环中定期运行代码审查,检查代码复用性、质量、效率');
|
|
18
|
+
console.log(' 审查间隔 — 每 N 个成功的 session 后运行一次(0 = 禁用)');
|
|
19
|
+
console.log(' 审查范围 — 审查最近 N 个 commit 的代码变更');
|
|
20
|
+
console.log('');
|
|
21
|
+
|
|
22
|
+
const intervalInput = await ask(rl, `审查间隔(输入 0 禁用,回车保留 ${currentInterval === '0' ? '禁用' : currentInterval}): `);
|
|
23
|
+
if (intervalInput.trim()) {
|
|
24
|
+
const interval = parseInt(intervalInput.trim(), 10);
|
|
25
|
+
if (isNaN(interval) || interval < 0) {
|
|
26
|
+
log('warn', '请输入 >= 0 的整数,跳过');
|
|
27
|
+
} else {
|
|
28
|
+
updateEnvVar('SIMPLIFY_INTERVAL', String(interval));
|
|
29
|
+
log('ok', `自动审查已${interval === 0 ? '禁用' : `设置为每 ${interval} 个 session 运行一次`}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const effectiveInterval = intervalInput.trim()
|
|
34
|
+
? String(parseInt(intervalInput.trim(), 10) || 0)
|
|
35
|
+
: currentInterval;
|
|
36
|
+
if (effectiveInterval !== '0') {
|
|
37
|
+
console.log('');
|
|
38
|
+
const commitsInput = await ask(rl, `审查 commit 数量(回车保留 ${currentCommits}): `);
|
|
39
|
+
if (commitsInput.trim()) {
|
|
40
|
+
const commits = parseInt(commitsInput.trim(), 10);
|
|
41
|
+
if (isNaN(commits) || commits < 1) {
|
|
42
|
+
log('warn', '请输入 >= 1 的整数,跳过');
|
|
43
|
+
} else {
|
|
44
|
+
updateEnvVar('SIMPLIFY_COMMITS', String(commits));
|
|
45
|
+
log('ok', `审查范围已设置为 ${commits} 个 commit`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
updateSimplifyConfig,
|
|
53
53
|
};
|
package/src/commands/setup.js
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const { log, COLOR, parseEnvFile } = require('../common/config');
|
|
5
|
-
const { assets } = require('../common/assets');
|
|
6
|
-
const {
|
|
7
|
-
createInterface,
|
|
8
|
-
ask,
|
|
9
|
-
askChoice,
|
|
10
|
-
writeConfig,
|
|
11
|
-
ensureGitignore,
|
|
12
|
-
showCurrentConfig,
|
|
13
|
-
selectProvider,
|
|
14
|
-
updateApiKeyOnly,
|
|
15
|
-
configureMCP,
|
|
16
|
-
appendMcpConfig,
|
|
17
|
-
updateMCPOnly,
|
|
18
|
-
updateSafetyLimits,
|
|
19
|
-
updateSimplifyConfig,
|
|
20
|
-
} = require('./setup-modules');
|
|
21
|
-
|
|
22
|
-
const PRESERVED_KEYS = [
|
|
23
|
-
'SESSION_STALL_TIMEOUT', 'SESSION_COMPLETION_TIMEOUT',
|
|
24
|
-
'SESSION_MAX_TURNS', 'SIMPLIFY_INTERVAL', 'SIMPLIFY_COMMITS',
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
function preserveSafetyConfig(lines, existing) {
|
|
28
|
-
const preserved = PRESERVED_KEYS
|
|
29
|
-
.filter(k => existing[k])
|
|
30
|
-
.map(k => `${k}=${existing[k]}`);
|
|
31
|
-
if (preserved.length > 0) {
|
|
32
|
-
lines.push('', '# 保留的安全限制和审查配置');
|
|
33
|
-
lines.push(...preserved);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function setup() {
|
|
38
|
-
assets.ensureDirs();
|
|
39
|
-
const rl = createInterface();
|
|
40
|
-
|
|
41
|
-
const envPath = assets.path('env');
|
|
42
|
-
let existing = {};
|
|
43
|
-
if (fs.existsSync(envPath)) {
|
|
44
|
-
existing = parseEnvFile(envPath);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
console.log('');
|
|
48
|
-
console.log('============================================');
|
|
49
|
-
console.log(' Claude Coder 配置');
|
|
50
|
-
console.log('============================================');
|
|
51
|
-
|
|
52
|
-
if (!fs.existsSync(envPath) || !existing.MODEL_PROVIDER) {
|
|
53
|
-
console.log('');
|
|
54
|
-
console.log(' 检测到未配置,开始初始化...');
|
|
55
|
-
console.log('');
|
|
56
|
-
|
|
57
|
-
const configResult = await selectProvider(rl, existing);
|
|
58
|
-
const mcpConfig = await configureMCP(rl);
|
|
59
|
-
|
|
60
|
-
appendMcpConfig(configResult.lines, mcpConfig);
|
|
61
|
-
writeConfig(envPath, configResult.lines);
|
|
62
|
-
ensureGitignore();
|
|
63
|
-
|
|
64
|
-
if (mcpConfig.enabled && mcpConfig.mode) {
|
|
65
|
-
const { updateMcpConfig } = require('./auth');
|
|
66
|
-
const mcpPath = assets.path('mcpConfig');
|
|
67
|
-
updateMcpConfig(mcpPath, mcpConfig.mode);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
console.log('');
|
|
71
|
-
log('info', '配置自动代码审查(可选)');
|
|
72
|
-
await updateSimplifyConfig(rl, {});
|
|
73
|
-
|
|
74
|
-
console.log('');
|
|
75
|
-
log('ok', `配置完成!提供商: ${configResult.summary}`);
|
|
76
|
-
console.log('');
|
|
77
|
-
console.log(` 配置文件: ${envPath}`);
|
|
78
|
-
console.log(' 使用方式: claude-coder run "你的需求"');
|
|
79
|
-
console.log(' 重新配置: claude-coder setup');
|
|
80
|
-
console.log('');
|
|
81
|
-
console.log(` ${COLOR.blue}当前默认值:${COLOR.reset}`);
|
|
82
|
-
console.log(` 停顿超时: 1200 秒 (20 分钟)`);
|
|
83
|
-
console.log(` 完成检测超时: 300 秒 (5 分钟)`);
|
|
84
|
-
console.log(` 自动审查: 每 5 个 session,审查 5 个 commit`);
|
|
85
|
-
console.log('');
|
|
86
|
-
console.log(` ${COLOR.yellow}调整方式: claude-coder setup → 配置安全限制 / 配置自动审查${COLOR.reset}`);
|
|
87
|
-
console.log('');
|
|
88
|
-
|
|
89
|
-
rl.close();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
while (true) {
|
|
94
|
-
existing = parseEnvFile(envPath);
|
|
95
|
-
showCurrentConfig(existing);
|
|
96
|
-
|
|
97
|
-
console.log('请选择要执行的操作:');
|
|
98
|
-
console.log('');
|
|
99
|
-
console.log(' 1) 切换模型提供商');
|
|
100
|
-
console.log(' 2) 更新 API Key');
|
|
101
|
-
console.log(' 3) 配置 MCP');
|
|
102
|
-
console.log(' 4) 配置安全限制');
|
|
103
|
-
console.log(' 5) 配置自动审查');
|
|
104
|
-
console.log(' 6) 完全重新配置');
|
|
105
|
-
console.log(' 7) 退出');
|
|
106
|
-
console.log('');
|
|
107
|
-
|
|
108
|
-
const action = await askChoice(rl, '选择 [1-7]: ', 1, 7);
|
|
109
|
-
console.log('');
|
|
110
|
-
|
|
111
|
-
if (action === 7) {
|
|
112
|
-
log('info', '退出配置');
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
switch (action) {
|
|
117
|
-
case 1: {
|
|
118
|
-
log('info', '放心切换,旧配置会自动备份,安全限制和审查配置会保留');
|
|
119
|
-
const configResult = await selectProvider(rl, existing);
|
|
120
|
-
preserveSafetyConfig(configResult.lines, existing);
|
|
121
|
-
appendMcpConfig(configResult.lines, {
|
|
122
|
-
enabled: existing.MCP_PLAYWRIGHT === 'true',
|
|
123
|
-
mode: existing.MCP_PLAYWRIGHT_MODE || null,
|
|
124
|
-
});
|
|
125
|
-
writeConfig(envPath, configResult.lines);
|
|
126
|
-
log('ok', `已切换到: ${configResult.summary}`);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
case 2: {
|
|
130
|
-
await updateApiKeyOnly(rl, existing);
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
case 3: {
|
|
134
|
-
await updateMCPOnly(rl);
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
case 4: {
|
|
138
|
-
await updateSafetyLimits(rl, existing);
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
case 5: {
|
|
142
|
-
await updateSimplifyConfig(rl, existing);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
case 6: {
|
|
146
|
-
log('info', '放心重新配置,旧配置会自动备份,安全限制和审查配置会保留');
|
|
147
|
-
const configResult = await selectProvider(rl, existing);
|
|
148
|
-
preserveSafetyConfig(configResult.lines, existing);
|
|
149
|
-
const mcpConfig = await configureMCP(rl);
|
|
150
|
-
appendMcpConfig(configResult.lines, mcpConfig);
|
|
151
|
-
writeConfig(envPath, configResult.lines);
|
|
152
|
-
|
|
153
|
-
if (mcpConfig.enabled && mcpConfig.mode) {
|
|
154
|
-
const { updateMcpConfig } = require('./auth');
|
|
155
|
-
const mcpPath = assets.path('mcpConfig');
|
|
156
|
-
updateMcpConfig(mcpPath, mcpConfig.mode);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
log('ok', '配置已更新');
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
console.log('');
|
|
165
|
-
const cont = await ask(rl, '继续配置其他项?(y/N) ');
|
|
166
|
-
if (!/^[Yy]/.test(cont.trim())) break;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
rl.close();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
module.exports = { setup };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { log, COLOR, parseEnvFile } = require('../common/config');
|
|
5
|
+
const { assets } = require('../common/assets');
|
|
6
|
+
const {
|
|
7
|
+
createInterface,
|
|
8
|
+
ask,
|
|
9
|
+
askChoice,
|
|
10
|
+
writeConfig,
|
|
11
|
+
ensureGitignore,
|
|
12
|
+
showCurrentConfig,
|
|
13
|
+
selectProvider,
|
|
14
|
+
updateApiKeyOnly,
|
|
15
|
+
configureMCP,
|
|
16
|
+
appendMcpConfig,
|
|
17
|
+
updateMCPOnly,
|
|
18
|
+
updateSafetyLimits,
|
|
19
|
+
updateSimplifyConfig,
|
|
20
|
+
} = require('./setup-modules');
|
|
21
|
+
|
|
22
|
+
const PRESERVED_KEYS = [
|
|
23
|
+
'SESSION_STALL_TIMEOUT', 'SESSION_COMPLETION_TIMEOUT',
|
|
24
|
+
'SESSION_MAX_TURNS', 'SIMPLIFY_INTERVAL', 'SIMPLIFY_COMMITS',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
function preserveSafetyConfig(lines, existing) {
|
|
28
|
+
const preserved = PRESERVED_KEYS
|
|
29
|
+
.filter(k => existing[k])
|
|
30
|
+
.map(k => `${k}=${existing[k]}`);
|
|
31
|
+
if (preserved.length > 0) {
|
|
32
|
+
lines.push('', '# 保留的安全限制和审查配置');
|
|
33
|
+
lines.push(...preserved);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function setup() {
|
|
38
|
+
assets.ensureDirs();
|
|
39
|
+
const rl = createInterface();
|
|
40
|
+
|
|
41
|
+
const envPath = assets.path('env');
|
|
42
|
+
let existing = {};
|
|
43
|
+
if (fs.existsSync(envPath)) {
|
|
44
|
+
existing = parseEnvFile(envPath);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.log('');
|
|
48
|
+
console.log('============================================');
|
|
49
|
+
console.log(' Claude Coder 配置');
|
|
50
|
+
console.log('============================================');
|
|
51
|
+
|
|
52
|
+
if (!fs.existsSync(envPath) || !existing.MODEL_PROVIDER) {
|
|
53
|
+
console.log('');
|
|
54
|
+
console.log(' 检测到未配置,开始初始化...');
|
|
55
|
+
console.log('');
|
|
56
|
+
|
|
57
|
+
const configResult = await selectProvider(rl, existing);
|
|
58
|
+
const mcpConfig = await configureMCP(rl);
|
|
59
|
+
|
|
60
|
+
appendMcpConfig(configResult.lines, mcpConfig);
|
|
61
|
+
writeConfig(envPath, configResult.lines);
|
|
62
|
+
ensureGitignore();
|
|
63
|
+
|
|
64
|
+
if (mcpConfig.enabled && mcpConfig.mode) {
|
|
65
|
+
const { updateMcpConfig } = require('./auth');
|
|
66
|
+
const mcpPath = assets.path('mcpConfig');
|
|
67
|
+
updateMcpConfig(mcpPath, mcpConfig.mode);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log('');
|
|
71
|
+
log('info', '配置自动代码审查(可选)');
|
|
72
|
+
await updateSimplifyConfig(rl, {});
|
|
73
|
+
|
|
74
|
+
console.log('');
|
|
75
|
+
log('ok', `配置完成!提供商: ${configResult.summary}`);
|
|
76
|
+
console.log('');
|
|
77
|
+
console.log(` 配置文件: ${envPath}`);
|
|
78
|
+
console.log(' 使用方式: claude-coder run "你的需求"');
|
|
79
|
+
console.log(' 重新配置: claude-coder setup');
|
|
80
|
+
console.log('');
|
|
81
|
+
console.log(` ${COLOR.blue}当前默认值:${COLOR.reset}`);
|
|
82
|
+
console.log(` 停顿超时: 1200 秒 (20 分钟)`);
|
|
83
|
+
console.log(` 完成检测超时: 300 秒 (5 分钟)`);
|
|
84
|
+
console.log(` 自动审查: 每 5 个 session,审查 5 个 commit`);
|
|
85
|
+
console.log('');
|
|
86
|
+
console.log(` ${COLOR.yellow}调整方式: claude-coder setup → 配置安全限制 / 配置自动审查${COLOR.reset}`);
|
|
87
|
+
console.log('');
|
|
88
|
+
|
|
89
|
+
rl.close();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
while (true) {
|
|
94
|
+
existing = parseEnvFile(envPath);
|
|
95
|
+
showCurrentConfig(existing);
|
|
96
|
+
|
|
97
|
+
console.log('请选择要执行的操作:');
|
|
98
|
+
console.log('');
|
|
99
|
+
console.log(' 1) 切换模型提供商');
|
|
100
|
+
console.log(' 2) 更新 API Key');
|
|
101
|
+
console.log(' 3) 配置 MCP');
|
|
102
|
+
console.log(' 4) 配置安全限制');
|
|
103
|
+
console.log(' 5) 配置自动审查');
|
|
104
|
+
console.log(' 6) 完全重新配置');
|
|
105
|
+
console.log(' 7) 退出');
|
|
106
|
+
console.log('');
|
|
107
|
+
|
|
108
|
+
const action = await askChoice(rl, '选择 [1-7]: ', 1, 7);
|
|
109
|
+
console.log('');
|
|
110
|
+
|
|
111
|
+
if (action === 7) {
|
|
112
|
+
log('info', '退出配置');
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
switch (action) {
|
|
117
|
+
case 1: {
|
|
118
|
+
log('info', '放心切换,旧配置会自动备份,安全限制和审查配置会保留');
|
|
119
|
+
const configResult = await selectProvider(rl, existing);
|
|
120
|
+
preserveSafetyConfig(configResult.lines, existing);
|
|
121
|
+
appendMcpConfig(configResult.lines, {
|
|
122
|
+
enabled: existing.MCP_PLAYWRIGHT === 'true',
|
|
123
|
+
mode: existing.MCP_PLAYWRIGHT_MODE || null,
|
|
124
|
+
});
|
|
125
|
+
writeConfig(envPath, configResult.lines);
|
|
126
|
+
log('ok', `已切换到: ${configResult.summary}`);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case 2: {
|
|
130
|
+
await updateApiKeyOnly(rl, existing);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case 3: {
|
|
134
|
+
await updateMCPOnly(rl);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case 4: {
|
|
138
|
+
await updateSafetyLimits(rl, existing);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
case 5: {
|
|
142
|
+
await updateSimplifyConfig(rl, existing);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 6: {
|
|
146
|
+
log('info', '放心重新配置,旧配置会自动备份,安全限制和审查配置会保留');
|
|
147
|
+
const configResult = await selectProvider(rl, existing);
|
|
148
|
+
preserveSafetyConfig(configResult.lines, existing);
|
|
149
|
+
const mcpConfig = await configureMCP(rl);
|
|
150
|
+
appendMcpConfig(configResult.lines, mcpConfig);
|
|
151
|
+
writeConfig(envPath, configResult.lines);
|
|
152
|
+
|
|
153
|
+
if (mcpConfig.enabled && mcpConfig.mode) {
|
|
154
|
+
const { updateMcpConfig } = require('./auth');
|
|
155
|
+
const mcpPath = assets.path('mcpConfig');
|
|
156
|
+
updateMcpConfig(mcpPath, mcpConfig.mode);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
log('ok', '配置已更新');
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
console.log('');
|
|
165
|
+
const cont = await ask(rl, '继续配置其他项?(y/N) ');
|
|
166
|
+
if (!/^[Yy]/.test(cont.trim())) break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
rl.close();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = { setup };
|