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.
Files changed (47) hide show
  1. package/README.md +167 -167
  2. package/bin/cli.js +172 -172
  3. package/package.json +52 -52
  4. package/src/commands/auth.js +290 -240
  5. package/src/commands/setup-modules/helpers.js +99 -99
  6. package/src/commands/setup-modules/index.js +25 -25
  7. package/src/commands/setup-modules/mcp.js +94 -94
  8. package/src/commands/setup-modules/provider.js +260 -260
  9. package/src/commands/setup-modules/safety.js +61 -61
  10. package/src/commands/setup-modules/simplify.js +52 -52
  11. package/src/commands/setup.js +172 -172
  12. package/src/common/assets.js +236 -236
  13. package/src/common/config.js +125 -125
  14. package/src/common/constants.js +55 -55
  15. package/src/common/indicator.js +222 -222
  16. package/src/common/interaction.js +170 -170
  17. package/src/common/logging.js +77 -77
  18. package/src/common/sdk.js +50 -50
  19. package/src/common/tasks.js +88 -88
  20. package/src/common/utils.js +161 -161
  21. package/src/core/coding.js +55 -55
  22. package/src/core/context.js +117 -117
  23. package/src/core/go.js +310 -310
  24. package/src/core/harness.js +484 -484
  25. package/src/core/hooks.js +533 -533
  26. package/src/core/init.js +171 -171
  27. package/src/core/plan.js +325 -325
  28. package/src/core/prompts.js +227 -227
  29. package/src/core/query.js +49 -49
  30. package/src/core/repair.js +46 -46
  31. package/src/core/runner.js +195 -195
  32. package/src/core/scan.js +89 -89
  33. package/src/core/session.js +56 -56
  34. package/src/core/simplify.js +53 -52
  35. package/templates/bash-process.md +12 -12
  36. package/templates/codingSystem.md +65 -65
  37. package/templates/codingUser.md +17 -17
  38. package/templates/coreProtocol.md +29 -29
  39. package/templates/goSystem.md +130 -130
  40. package/templates/guidance.json +52 -52
  41. package/templates/planSystem.md +78 -78
  42. package/templates/planUser.md +8 -8
  43. package/templates/playwright.md +16 -16
  44. package/templates/requirements.example.md +57 -57
  45. package/templates/scanSystem.md +120 -120
  46. package/templates/scanUser.md +10 -10
  47. package/templates/test_rule.md +194 -194
@@ -1,99 +1,99 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const readline = require('readline');
6
- const { log, COLOR, updateEnvVar } = require('../../common/config');
7
- const { ensureGitignore: ensureGitignoreBase } = require('../../common/utils');
8
- const { assets } = require('../../common/assets');
9
-
10
- function createInterface() {
11
- return readline.createInterface({ input: process.stdin, output: process.stdout });
12
- }
13
-
14
- function ask(rl, question) {
15
- return new Promise(resolve => rl.question(question, resolve));
16
- }
17
-
18
- function askChoice(rl, prompt, min, max, defaultVal) {
19
- return new Promise(async (resolve) => {
20
- while (true) {
21
- const raw = await ask(rl, prompt);
22
- const val = raw.trim() || String(defaultVal ?? '');
23
- const num = parseInt(val, 10);
24
- if (num >= min && num <= max) return resolve(num);
25
- console.log(`请输入 ${min}-${max}`);
26
- }
27
- });
28
- }
29
-
30
- async function askApiKey(rl, platform, apiUrl, existingKey) {
31
- if (existingKey) {
32
- console.log('回车保留当前 API Key,输入新 Key 更新,输入 q 返回上层菜单:');
33
- } else {
34
- console.log(`请输入 ${platform} 的 API Key:`);
35
- }
36
- if (apiUrl) {
37
- console.log(` ${COLOR.blue}获取入口: ${apiUrl}${COLOR.reset}`);
38
- console.log('');
39
- }
40
- const key = await ask(rl, ' API Key: ');
41
- const trimmed = key.trim();
42
- if (trimmed.toLowerCase() === 'q') {
43
- return null;
44
- }
45
- if (!trimmed) {
46
- if (existingKey) return existingKey;
47
- console.error('API Key 不能为空');
48
- process.exit(1);
49
- }
50
- return trimmed;
51
- }
52
-
53
- function writeConfig(filePath, lines) {
54
- const dir = path.dirname(filePath);
55
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
56
-
57
- if (fs.existsSync(filePath)) {
58
- const ts = new Date().toISOString().replace(/[:\-T]/g, '').slice(0, 14);
59
- const backup = `${filePath}.bak.${ts}`;
60
- fs.copyFileSync(filePath, backup);
61
- log('info', `已备份旧配置到: ${backup}`);
62
- }
63
-
64
- fs.writeFileSync(filePath, lines.join('\n') + '\n', 'utf8');
65
- }
66
-
67
- function ensureGitignore() {
68
- if (ensureGitignoreBase(assets.projectRoot)) {
69
- log('info', '已更新 .gitignore');
70
- }
71
- }
72
-
73
- function showCurrentConfig(existing) {
74
- console.log('');
75
- console.log(`${COLOR.blue}当前配置:${COLOR.reset}`);
76
- console.log(` 提供商: ${existing.MODEL_PROVIDER || '未配置'}`);
77
- console.log(` BASE_URL: ${existing.ANTHROPIC_BASE_URL || '默认'}`);
78
- console.log(` 模型: ${existing.ANTHROPIC_MODEL || '默认'}`);
79
- console.log(` MCP: ${existing.MCP_PLAYWRIGHT === 'true' ? `已启用 (${existing.MCP_PLAYWRIGHT_MODE || 'persistent'})` : '未启用'}`);
80
- const compTimeout = existing.SESSION_COMPLETION_TIMEOUT || '300';
81
- const turns = existing.SESSION_MAX_TURNS || '0';
82
- console.log(` 停顿超时: ${existing.SESSION_STALL_TIMEOUT || '600'} 秒`);
83
- console.log(` 完成检测: ${compTimeout} 秒`);
84
- console.log(` 工具轮次: ${turns === '0' ? '无限制' : turns}`);
85
- const simplifyInterval = existing.SIMPLIFY_INTERVAL ?? '5';
86
- const simplifyCommits = existing.SIMPLIFY_COMMITS ?? '5';
87
- console.log(` 自动审查: ${simplifyInterval === '0' ? '禁用' : `每 ${simplifyInterval} 个 session`}${simplifyInterval !== '0' ? `,审查 ${simplifyCommits} 个 commit` : ''}`);
88
- console.log('');
89
- }
90
-
91
- module.exports = {
92
- createInterface,
93
- ask,
94
- askChoice,
95
- askApiKey,
96
- writeConfig,
97
- ensureGitignore,
98
- showCurrentConfig,
99
- };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const readline = require('readline');
6
+ const { log, COLOR, updateEnvVar } = require('../../common/config');
7
+ const { ensureGitignore: ensureGitignoreBase } = require('../../common/utils');
8
+ const { assets } = require('../../common/assets');
9
+
10
+ function createInterface() {
11
+ return readline.createInterface({ input: process.stdin, output: process.stdout });
12
+ }
13
+
14
+ function ask(rl, question) {
15
+ return new Promise(resolve => rl.question(question, resolve));
16
+ }
17
+
18
+ function askChoice(rl, prompt, min, max, defaultVal) {
19
+ return new Promise(async (resolve) => {
20
+ while (true) {
21
+ const raw = await ask(rl, prompt);
22
+ const val = raw.trim() || String(defaultVal ?? '');
23
+ const num = parseInt(val, 10);
24
+ if (num >= min && num <= max) return resolve(num);
25
+ console.log(`请输入 ${min}-${max}`);
26
+ }
27
+ });
28
+ }
29
+
30
+ async function askApiKey(rl, platform, apiUrl, existingKey) {
31
+ if (existingKey) {
32
+ console.log('回车保留当前 API Key,输入新 Key 更新,输入 q 返回上层菜单:');
33
+ } else {
34
+ console.log(`请输入 ${platform} 的 API Key:`);
35
+ }
36
+ if (apiUrl) {
37
+ console.log(` ${COLOR.blue}获取入口: ${apiUrl}${COLOR.reset}`);
38
+ console.log('');
39
+ }
40
+ const key = await ask(rl, ' API Key: ');
41
+ const trimmed = key.trim();
42
+ if (trimmed.toLowerCase() === 'q') {
43
+ return null;
44
+ }
45
+ if (!trimmed) {
46
+ if (existingKey) return existingKey;
47
+ console.error('API Key 不能为空');
48
+ process.exit(1);
49
+ }
50
+ return trimmed;
51
+ }
52
+
53
+ function writeConfig(filePath, lines) {
54
+ const dir = path.dirname(filePath);
55
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
56
+
57
+ if (fs.existsSync(filePath)) {
58
+ const ts = new Date().toISOString().replace(/[:\-T]/g, '').slice(0, 14);
59
+ const backup = `${filePath}.bak.${ts}`;
60
+ fs.copyFileSync(filePath, backup);
61
+ log('info', `已备份旧配置到: ${backup}`);
62
+ }
63
+
64
+ fs.writeFileSync(filePath, lines.join('\n') + '\n', 'utf8');
65
+ }
66
+
67
+ function ensureGitignore() {
68
+ if (ensureGitignoreBase(assets.projectRoot)) {
69
+ log('info', '已更新 .gitignore');
70
+ }
71
+ }
72
+
73
+ function showCurrentConfig(existing) {
74
+ console.log('');
75
+ console.log(`${COLOR.blue}当前配置:${COLOR.reset}`);
76
+ console.log(` 提供商: ${existing.MODEL_PROVIDER || '未配置'}`);
77
+ console.log(` BASE_URL: ${existing.ANTHROPIC_BASE_URL || '默认'}`);
78
+ console.log(` 模型: ${existing.ANTHROPIC_MODEL || '默认'}`);
79
+ console.log(` MCP: ${existing.MCP_PLAYWRIGHT === 'true' ? `已启用 (${existing.MCP_PLAYWRIGHT_MODE || 'persistent'})` : '未启用'}`);
80
+ const compTimeout = existing.SESSION_COMPLETION_TIMEOUT || '300';
81
+ const turns = existing.SESSION_MAX_TURNS || '0';
82
+ console.log(` 停顿超时: ${existing.SESSION_STALL_TIMEOUT || '600'} 秒`);
83
+ console.log(` 完成检测: ${compTimeout} 秒`);
84
+ console.log(` 工具轮次: ${turns === '0' ? '无限制' : turns}`);
85
+ const simplifyInterval = existing.SIMPLIFY_INTERVAL ?? '5';
86
+ const simplifyCommits = existing.SIMPLIFY_COMMITS ?? '5';
87
+ console.log(` 自动审查: ${simplifyInterval === '0' ? '禁用' : `每 ${simplifyInterval} 个 session`}${simplifyInterval !== '0' ? `,审查 ${simplifyCommits} 个 commit` : ''}`);
88
+ console.log('');
89
+ }
90
+
91
+ module.exports = {
92
+ createInterface,
93
+ ask,
94
+ askChoice,
95
+ askApiKey,
96
+ writeConfig,
97
+ ensureGitignore,
98
+ showCurrentConfig,
99
+ };
@@ -1,26 +1,26 @@
1
- 'use strict';
2
-
3
- // ── setup 子模块统一入口 ──
4
-
5
- const helpers = require('./helpers');
6
- const provider = require('./provider');
7
- const mcp = require('./mcp');
8
- const safety = require('./safety');
9
- const simplify = require('./simplify');
10
-
11
- module.exports = {
12
- createInterface: helpers.createInterface,
13
- ask: helpers.ask,
14
- askChoice: helpers.askChoice,
15
- askApiKey: helpers.askApiKey,
16
- writeConfig: helpers.writeConfig,
17
- ensureGitignore: helpers.ensureGitignore,
18
- showCurrentConfig: helpers.showCurrentConfig,
19
- selectProvider: provider.selectProvider,
20
- updateApiKeyOnly: provider.updateApiKeyOnly,
21
- configureMCP: mcp.configureMCP,
22
- appendMcpConfig: mcp.appendMcpConfig,
23
- updateMCPOnly: mcp.updateMCPOnly,
24
- updateSafetyLimits: safety.updateSafetyLimits,
25
- updateSimplifyConfig: simplify.updateSimplifyConfig,
1
+ 'use strict';
2
+
3
+ // ── setup 子模块统一入口 ──
4
+
5
+ const helpers = require('./helpers');
6
+ const provider = require('./provider');
7
+ const mcp = require('./mcp');
8
+ const safety = require('./safety');
9
+ const simplify = require('./simplify');
10
+
11
+ module.exports = {
12
+ createInterface: helpers.createInterface,
13
+ ask: helpers.ask,
14
+ askChoice: helpers.askChoice,
15
+ askApiKey: helpers.askApiKey,
16
+ writeConfig: helpers.writeConfig,
17
+ ensureGitignore: helpers.ensureGitignore,
18
+ showCurrentConfig: helpers.showCurrentConfig,
19
+ selectProvider: provider.selectProvider,
20
+ updateApiKeyOnly: provider.updateApiKeyOnly,
21
+ configureMCP: mcp.configureMCP,
22
+ appendMcpConfig: mcp.appendMcpConfig,
23
+ updateMCPOnly: mcp.updateMCPOnly,
24
+ updateSafetyLimits: safety.updateSafetyLimits,
25
+ updateSimplifyConfig: simplify.updateSimplifyConfig,
26
26
  };
@@ -1,95 +1,95 @@
1
- 'use strict';
2
-
3
- const { ask, askChoice } = require('./helpers');
4
- const { log, COLOR, updateEnvVar } = require('../../common/config');
5
- const { assets } = require('../../common/assets');
6
-
7
- // ── MCP 配置 ──
8
-
9
- async function configureMCP(rl) {
10
- console.log('');
11
- console.log('是否启用 Playwright MCP(浏览器自动化测试)?');
12
- console.log('');
13
- console.log(' Playwright MCP 由微软官方维护 (github.com/microsoft/playwright-mcp)');
14
- console.log(' 提供 browser_click、browser_snapshot 等 25+ 浏览器自动化工具');
15
- console.log(' 适用于有 Web 前端的项目,Agent 可用它做端到端测试');
16
- console.log('');
17
- console.log(' 1) 是 - 启用 Playwright MCP(项目有 Web 前端)');
18
- console.log(' 2) 否 - 跳过(纯后端 / CLI 项目)');
19
- console.log('');
20
-
21
- const mcpChoice = await askChoice(rl, '选择 [1-2]: ', 1, 2);
22
-
23
- const mcpConfig = { enabled: false, mode: null };
24
-
25
- if (mcpChoice === 1) {
26
- mcpConfig.enabled = true;
27
- console.log('');
28
- console.log('请选择 Playwright MCP 浏览器模式:');
29
- console.log('');
30
- console.log(' 1) persistent - 懒人模式(默认,推荐)');
31
- console.log(' 登录一次永久生效,适合 Google SSO、企业内网 API 拉取等日常开发');
32
- console.log('');
33
- console.log(' 2) isolated - 开发模式');
34
- console.log(' 每次会话从快照加载,适合验证登录流程的自动化测试');
35
- console.log('');
36
- console.log(' 3) extension - 连接真实浏览器(实验性)');
37
- console.log(' 通过 Chrome 扩展复用已有登录态和插件');
38
- console.log(' 需要安装 "Playwright MCP Bridge" 扩展');
39
- console.log('');
40
-
41
- const modeChoice = await askChoice(rl, '选择 [1-3,默认 1]: ', 1, 3, 1);
42
- const modeMap = { 1: 'persistent', 2: 'isolated', 3: 'extension' };
43
- mcpConfig.mode = modeMap[modeChoice];
44
-
45
- console.log('');
46
- if (mcpConfig.mode === 'extension') {
47
- console.log(` ${COLOR.yellow}⚠ 前置条件:安装 Playwright MCP Bridge 浏览器扩展${COLOR.reset}`);
48
- console.log(` ${COLOR.blue} https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm${COLOR.reset}`);
49
- console.log('');
50
- console.log(' 安装扩展后,运行 claude-coder auth 生成 .mcp.json 配置');
51
- } else if (mcpConfig.mode === 'persistent') {
52
- console.log(' 使用 claude-coder auth <URL> 打开浏览器完成首次登录');
53
- console.log(' 登录状态将持久保存,后续 MCP 会话自动复用');
54
- console.log('');
55
- console.log(' 请确保已安装 Playwright:');
56
- console.log(` ${COLOR.blue}npx playwright install chromium${COLOR.reset}`);
57
- } else {
58
- console.log(' 使用 claude-coder auth <URL> 录制登录状态到 playwright-auth.json');
59
- console.log(' MCP 每次会话从此文件加载初始 cookies/localStorage');
60
- }
61
- }
62
-
63
- return mcpConfig;
64
- }
65
-
66
- // ── MCP 配置追加到 lines ──
67
-
68
- function appendMcpConfig(lines, mcpConfig) {
69
- lines.push('', '# MCP 工具配置');
70
- if (mcpConfig.enabled) {
71
- lines.push('MCP_PLAYWRIGHT=true');
72
- if (mcpConfig.mode) lines.push(`MCP_PLAYWRIGHT_MODE=${mcpConfig.mode}`);
73
- } else {
74
- lines.push('MCP_PLAYWRIGHT=false');
75
- }
76
- }
77
-
78
- // ── 仅更新 MCP 配置 ──
79
-
80
- async function updateMCPOnly(rl) {
81
- const mcpConfig = await configureMCP(rl);
82
- updateEnvVar('MCP_PLAYWRIGHT', mcpConfig.enabled ? 'true' : 'false');
83
- if (mcpConfig.enabled && mcpConfig.mode) {
84
- updateEnvVar('MCP_PLAYWRIGHT_MODE', mcpConfig.mode);
85
- const { updateMcpConfig } = require('../auth');
86
- updateMcpConfig(assets.path('mcpConfig'), mcpConfig.mode);
87
- }
88
- log('ok', 'MCP 配置已更新');
89
- }
90
-
91
- module.exports = {
92
- configureMCP,
93
- appendMcpConfig,
94
- updateMCPOnly,
1
+ 'use strict';
2
+
3
+ const { ask, askChoice } = require('./helpers');
4
+ const { log, COLOR, updateEnvVar } = require('../../common/config');
5
+ const { assets } = require('../../common/assets');
6
+
7
+ // ── MCP 配置 ──
8
+
9
+ async function configureMCP(rl) {
10
+ console.log('');
11
+ console.log('是否启用 Playwright MCP(浏览器自动化测试)?');
12
+ console.log('');
13
+ console.log(' Playwright MCP 由微软官方维护 (github.com/microsoft/playwright-mcp)');
14
+ console.log(' 提供 browser_click、browser_snapshot 等 25+ 浏览器自动化工具');
15
+ console.log(' 适用于有 Web 前端的项目,Agent 可用它做端到端测试');
16
+ console.log('');
17
+ console.log(' 1) 是 - 启用 Playwright MCP(项目有 Web 前端)');
18
+ console.log(' 2) 否 - 跳过(纯后端 / CLI 项目)');
19
+ console.log('');
20
+
21
+ const mcpChoice = await askChoice(rl, '选择 [1-2]: ', 1, 2);
22
+
23
+ const mcpConfig = { enabled: false, mode: null };
24
+
25
+ if (mcpChoice === 1) {
26
+ mcpConfig.enabled = true;
27
+ console.log('');
28
+ console.log('请选择 Playwright MCP 浏览器模式:');
29
+ console.log('');
30
+ console.log(' 1) persistent - 懒人模式(默认,推荐)');
31
+ console.log(' 登录一次永久生效,适合 Google SSO、企业内网 API 拉取等日常开发');
32
+ console.log('');
33
+ console.log(' 2) isolated - 开发模式');
34
+ console.log(' 每次会话从快照加载,适合验证登录流程的自动化测试');
35
+ console.log('');
36
+ console.log(' 3) extension - 连接真实浏览器(实验性)');
37
+ console.log(' 通过 Chrome 扩展复用已有登录态和插件');
38
+ console.log(' 需要安装 "Playwright MCP Bridge" 扩展');
39
+ console.log('');
40
+
41
+ const modeChoice = await askChoice(rl, '选择 [1-3,默认 1]: ', 1, 3, 1);
42
+ const modeMap = { 1: 'persistent', 2: 'isolated', 3: 'extension' };
43
+ mcpConfig.mode = modeMap[modeChoice];
44
+
45
+ console.log('');
46
+ if (mcpConfig.mode === 'extension') {
47
+ console.log(` ${COLOR.yellow}⚠ 前置条件:安装 Playwright MCP Bridge 浏览器扩展${COLOR.reset}`);
48
+ console.log(` ${COLOR.blue} https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm${COLOR.reset}`);
49
+ console.log('');
50
+ console.log(' 安装扩展后,运行 claude-coder auth 生成 .mcp.json 配置');
51
+ } else if (mcpConfig.mode === 'persistent') {
52
+ console.log(' 使用 claude-coder auth <URL> 打开浏览器完成首次登录');
53
+ console.log(' 登录状态将持久保存,后续 MCP 会话自动复用');
54
+ console.log('');
55
+ console.log(' 请确保已安装 Playwright:');
56
+ console.log(` ${COLOR.blue}npx playwright install chromium${COLOR.reset}`);
57
+ } else {
58
+ console.log(' 使用 claude-coder auth <URL> 录制登录状态到 playwright-auth.json');
59
+ console.log(' MCP 每次会话从此文件加载初始 cookies/localStorage');
60
+ }
61
+ }
62
+
63
+ return mcpConfig;
64
+ }
65
+
66
+ // ── MCP 配置追加到 lines ──
67
+
68
+ function appendMcpConfig(lines, mcpConfig) {
69
+ lines.push('', '# MCP 工具配置');
70
+ if (mcpConfig.enabled) {
71
+ lines.push('MCP_PLAYWRIGHT=true');
72
+ if (mcpConfig.mode) lines.push(`MCP_PLAYWRIGHT_MODE=${mcpConfig.mode}`);
73
+ } else {
74
+ lines.push('MCP_PLAYWRIGHT=false');
75
+ }
76
+ }
77
+
78
+ // ── 仅更新 MCP 配置 ──
79
+
80
+ async function updateMCPOnly(rl) {
81
+ const mcpConfig = await configureMCP(rl);
82
+ updateEnvVar('MCP_PLAYWRIGHT', mcpConfig.enabled ? 'true' : 'false');
83
+ if (mcpConfig.enabled && mcpConfig.mode) {
84
+ updateEnvVar('MCP_PLAYWRIGHT_MODE', mcpConfig.mode);
85
+ const { updateMcpConfig } = require('../auth');
86
+ updateMcpConfig(assets.path('mcpConfig'), mcpConfig.mode);
87
+ }
88
+ log('ok', 'MCP 配置已更新');
89
+ }
90
+
91
+ module.exports = {
92
+ configureMCP,
93
+ appendMcpConfig,
94
+ updateMCPOnly,
95
95
  };