claude-coder 1.6.2 → 1.7.0
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 +125 -127
- package/bin/cli.js +161 -197
- package/package.json +47 -44
- package/prompts/ADD_GUIDE.md +98 -0
- package/{templates → prompts}/CLAUDE.md +199 -238
- package/{templates → prompts}/SCAN_PROTOCOL.md +118 -123
- package/prompts/add_user.md +24 -0
- package/prompts/coding_user.md +23 -0
- package/prompts/scan_user.md +17 -0
- package/src/auth.js +245 -245
- package/src/config.js +201 -223
- package/src/hooks.js +160 -96
- package/src/indicator.js +217 -160
- package/src/init.js +144 -144
- package/src/prompts.js +295 -339
- package/src/runner.js +420 -394
- package/src/scanner.js +62 -62
- package/src/session.js +352 -320
- package/src/setup.js +579 -397
- package/src/tasks.js +172 -172
- package/src/validator.js +181 -170
- package/templates/requirements.example.md +56 -56
- package/templates/test_rule.md +194 -157
- package/docs/ARCHITECTURE.md +0 -516
- package/docs/PLAYWRIGHT_CREDENTIALS.md +0 -178
- package/docs/README.en.md +0 -103
package/src/init.js
CHANGED
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const net = require('net');
|
|
5
|
-
const http = require('http');
|
|
6
|
-
const { spawn, execSync } = require('child_process');
|
|
7
|
-
const { paths, log, getProjectRoot } = require('./config');
|
|
8
|
-
|
|
9
|
-
function loadProfile() {
|
|
10
|
-
const p = paths();
|
|
11
|
-
if (!fs.existsSync(p.profile)) {
|
|
12
|
-
log('error', '未找到 project_profile.json,请先运行 claude-coder run 完成项目扫描');
|
|
13
|
-
process.exit(1);
|
|
14
|
-
}
|
|
15
|
-
return JSON.parse(fs.readFileSync(p.profile, 'utf8'));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function isPortFree(port) {
|
|
19
|
-
return new Promise(resolve => {
|
|
20
|
-
const server = net.createServer();
|
|
21
|
-
server.once('error', () => resolve(false));
|
|
22
|
-
server.once('listening', () => { server.close(); resolve(true); });
|
|
23
|
-
server.listen(port, '127.0.0.1');
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function waitForHealth(url, timeoutMs = 15000) {
|
|
28
|
-
const start = Date.now();
|
|
29
|
-
return new Promise(resolve => {
|
|
30
|
-
const check = () => {
|
|
31
|
-
if (Date.now() - start > timeoutMs) { resolve(false); return; }
|
|
32
|
-
const req = http.get(url, res => {
|
|
33
|
-
resolve(res.statusCode < 500);
|
|
34
|
-
});
|
|
35
|
-
req.on('error', () => setTimeout(check, 1000));
|
|
36
|
-
req.setTimeout(3000, () => { req.destroy(); setTimeout(check, 1000); });
|
|
37
|
-
};
|
|
38
|
-
check();
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function runCmd(cmd, cwd) {
|
|
43
|
-
try {
|
|
44
|
-
execSync(cmd, { cwd: cwd || getProjectRoot(), stdio: 'inherit', shell: true });
|
|
45
|
-
return true;
|
|
46
|
-
} catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function init() {
|
|
52
|
-
const profile = loadProfile();
|
|
53
|
-
const projectRoot = getProjectRoot();
|
|
54
|
-
let stepCount = 0;
|
|
55
|
-
|
|
56
|
-
// 1. Environment activation
|
|
57
|
-
const envSetup = profile.env_setup || {};
|
|
58
|
-
if (envSetup.python_env && envSetup.python_env !== 'system' && envSetup.python_env !== 'none') {
|
|
59
|
-
stepCount++;
|
|
60
|
-
if (envSetup.python_env.startsWith('conda:')) {
|
|
61
|
-
const envName = envSetup.python_env.slice(6);
|
|
62
|
-
log('info', `[${stepCount}] Python 环境: conda activate ${envName}`);
|
|
63
|
-
runCmd(`conda activate ${envName}`);
|
|
64
|
-
} else if (envSetup.python_env === 'venv') {
|
|
65
|
-
log('info', `[${stepCount}] Python 环境: venv`);
|
|
66
|
-
runCmd('source .venv/bin/activate || .venv\\Scripts\\activate');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (envSetup.node_version && envSetup.node_version !== 'none') {
|
|
70
|
-
stepCount++;
|
|
71
|
-
log('info', `[${stepCount}] Node.js: v${envSetup.node_version}`);
|
|
72
|
-
runCmd(`nvm use ${envSetup.node_version}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 2. Dependencies
|
|
76
|
-
const pkgManagers = (profile.tech_stack && profile.tech_stack.package_managers) || [];
|
|
77
|
-
for (const pm of pkgManagers) {
|
|
78
|
-
stepCount++;
|
|
79
|
-
if (pm === 'npm' || pm === 'yarn' || pm === 'pnpm') {
|
|
80
|
-
if (fs.existsSync(`${projectRoot}/node_modules`)) {
|
|
81
|
-
log('ok', `[${stepCount}] ${pm} 依赖已安装,跳过`);
|
|
82
|
-
} else {
|
|
83
|
-
log('info', `[${stepCount}] 安装依赖: ${pm} install`);
|
|
84
|
-
runCmd(`${pm} install`, projectRoot);
|
|
85
|
-
}
|
|
86
|
-
} else if (pm === 'pip') {
|
|
87
|
-
const reqFile = fs.existsSync(`${projectRoot}/requirements.txt`);
|
|
88
|
-
if (reqFile) {
|
|
89
|
-
log('info', `[${stepCount}] 安装依赖: pip install -r requirements.txt`);
|
|
90
|
-
runCmd('pip install -r requirements.txt', projectRoot);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 3. Custom init commands
|
|
96
|
-
const customInit = profile.custom_init || [];
|
|
97
|
-
for (const cmd of customInit) {
|
|
98
|
-
stepCount++;
|
|
99
|
-
log('info', `[${stepCount}] 自定义: ${cmd}`);
|
|
100
|
-
runCmd(cmd, projectRoot);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// 4. Services
|
|
104
|
-
const services = profile.services || [];
|
|
105
|
-
for (const svc of services) {
|
|
106
|
-
stepCount++;
|
|
107
|
-
const free = await isPortFree(svc.port);
|
|
108
|
-
if (!free) {
|
|
109
|
-
log('ok', `[${stepCount}] ${svc.name} 已在端口 ${svc.port} 运行,跳过`);
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
log('info', `[${stepCount}] 启动 ${svc.name} (端口 ${svc.port})...`);
|
|
114
|
-
const cwd = svc.cwd ? `${projectRoot}/${svc.cwd}` : projectRoot;
|
|
115
|
-
const child = spawn(svc.command, { cwd, shell: true, detached: true, stdio: 'ignore' });
|
|
116
|
-
child.unref();
|
|
117
|
-
|
|
118
|
-
if (svc.health_check) {
|
|
119
|
-
const healthy = await waitForHealth(svc.health_check);
|
|
120
|
-
if (healthy) {
|
|
121
|
-
log('ok', `${svc.name} 就绪: ${svc.health_check}`);
|
|
122
|
-
} else {
|
|
123
|
-
log('warn', `${svc.name} 健康检查超时 (${svc.health_check}),继续执行`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Summary
|
|
129
|
-
if (stepCount === 0) {
|
|
130
|
-
log('info', '无需初始化操作');
|
|
131
|
-
} else {
|
|
132
|
-
log('ok', `初始化完成 (${stepCount} 步)`);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (services.length > 0) {
|
|
136
|
-
console.log('');
|
|
137
|
-
for (const svc of services) {
|
|
138
|
-
console.log(` ${svc.name}: http://localhost:${svc.port}`);
|
|
139
|
-
}
|
|
140
|
-
console.log('');
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
module.exports = { init };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const net = require('net');
|
|
5
|
+
const http = require('http');
|
|
6
|
+
const { spawn, execSync } = require('child_process');
|
|
7
|
+
const { paths, log, getProjectRoot } = require('./config');
|
|
8
|
+
|
|
9
|
+
function loadProfile() {
|
|
10
|
+
const p = paths();
|
|
11
|
+
if (!fs.existsSync(p.profile)) {
|
|
12
|
+
log('error', '未找到 project_profile.json,请先运行 claude-coder run 完成项目扫描');
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(fs.readFileSync(p.profile, 'utf8'));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isPortFree(port) {
|
|
19
|
+
return new Promise(resolve => {
|
|
20
|
+
const server = net.createServer();
|
|
21
|
+
server.once('error', () => resolve(false));
|
|
22
|
+
server.once('listening', () => { server.close(); resolve(true); });
|
|
23
|
+
server.listen(port, '127.0.0.1');
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function waitForHealth(url, timeoutMs = 15000) {
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
return new Promise(resolve => {
|
|
30
|
+
const check = () => {
|
|
31
|
+
if (Date.now() - start > timeoutMs) { resolve(false); return; }
|
|
32
|
+
const req = http.get(url, res => {
|
|
33
|
+
resolve(res.statusCode < 500);
|
|
34
|
+
});
|
|
35
|
+
req.on('error', () => setTimeout(check, 1000));
|
|
36
|
+
req.setTimeout(3000, () => { req.destroy(); setTimeout(check, 1000); });
|
|
37
|
+
};
|
|
38
|
+
check();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function runCmd(cmd, cwd) {
|
|
43
|
+
try {
|
|
44
|
+
execSync(cmd, { cwd: cwd || getProjectRoot(), stdio: 'inherit', shell: true });
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function init() {
|
|
52
|
+
const profile = loadProfile();
|
|
53
|
+
const projectRoot = getProjectRoot();
|
|
54
|
+
let stepCount = 0;
|
|
55
|
+
|
|
56
|
+
// 1. Environment activation
|
|
57
|
+
const envSetup = profile.env_setup || {};
|
|
58
|
+
if (envSetup.python_env && envSetup.python_env !== 'system' && envSetup.python_env !== 'none') {
|
|
59
|
+
stepCount++;
|
|
60
|
+
if (envSetup.python_env.startsWith('conda:')) {
|
|
61
|
+
const envName = envSetup.python_env.slice(6);
|
|
62
|
+
log('info', `[${stepCount}] Python 环境: conda activate ${envName}`);
|
|
63
|
+
runCmd(`conda activate ${envName}`);
|
|
64
|
+
} else if (envSetup.python_env === 'venv') {
|
|
65
|
+
log('info', `[${stepCount}] Python 环境: venv`);
|
|
66
|
+
runCmd('source .venv/bin/activate || .venv\\Scripts\\activate');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (envSetup.node_version && envSetup.node_version !== 'none') {
|
|
70
|
+
stepCount++;
|
|
71
|
+
log('info', `[${stepCount}] Node.js: v${envSetup.node_version}`);
|
|
72
|
+
runCmd(`nvm use ${envSetup.node_version}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 2. Dependencies
|
|
76
|
+
const pkgManagers = (profile.tech_stack && profile.tech_stack.package_managers) || [];
|
|
77
|
+
for (const pm of pkgManagers) {
|
|
78
|
+
stepCount++;
|
|
79
|
+
if (pm === 'npm' || pm === 'yarn' || pm === 'pnpm') {
|
|
80
|
+
if (fs.existsSync(`${projectRoot}/node_modules`)) {
|
|
81
|
+
log('ok', `[${stepCount}] ${pm} 依赖已安装,跳过`);
|
|
82
|
+
} else {
|
|
83
|
+
log('info', `[${stepCount}] 安装依赖: ${pm} install`);
|
|
84
|
+
runCmd(`${pm} install`, projectRoot);
|
|
85
|
+
}
|
|
86
|
+
} else if (pm === 'pip') {
|
|
87
|
+
const reqFile = fs.existsSync(`${projectRoot}/requirements.txt`);
|
|
88
|
+
if (reqFile) {
|
|
89
|
+
log('info', `[${stepCount}] 安装依赖: pip install -r requirements.txt`);
|
|
90
|
+
runCmd('pip install -r requirements.txt', projectRoot);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 3. Custom init commands
|
|
96
|
+
const customInit = profile.custom_init || [];
|
|
97
|
+
for (const cmd of customInit) {
|
|
98
|
+
stepCount++;
|
|
99
|
+
log('info', `[${stepCount}] 自定义: ${cmd}`);
|
|
100
|
+
runCmd(cmd, projectRoot);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 4. Services
|
|
104
|
+
const services = profile.services || [];
|
|
105
|
+
for (const svc of services) {
|
|
106
|
+
stepCount++;
|
|
107
|
+
const free = await isPortFree(svc.port);
|
|
108
|
+
if (!free) {
|
|
109
|
+
log('ok', `[${stepCount}] ${svc.name} 已在端口 ${svc.port} 运行,跳过`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
log('info', `[${stepCount}] 启动 ${svc.name} (端口 ${svc.port})...`);
|
|
114
|
+
const cwd = svc.cwd ? `${projectRoot}/${svc.cwd}` : projectRoot;
|
|
115
|
+
const child = spawn(svc.command, { cwd, shell: true, detached: true, stdio: 'ignore' });
|
|
116
|
+
child.unref();
|
|
117
|
+
|
|
118
|
+
if (svc.health_check) {
|
|
119
|
+
const healthy = await waitForHealth(svc.health_check);
|
|
120
|
+
if (healthy) {
|
|
121
|
+
log('ok', `${svc.name} 就绪: ${svc.health_check}`);
|
|
122
|
+
} else {
|
|
123
|
+
log('warn', `${svc.name} 健康检查超时 (${svc.health_check}),继续执行`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Summary
|
|
129
|
+
if (stepCount === 0) {
|
|
130
|
+
log('info', '无需初始化操作');
|
|
131
|
+
} else {
|
|
132
|
+
log('ok', `初始化完成 (${stepCount} 步)`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (services.length > 0) {
|
|
136
|
+
console.log('');
|
|
137
|
+
for (const svc of services) {
|
|
138
|
+
console.log(` ${svc.name}: http://localhost:${svc.port}`);
|
|
139
|
+
}
|
|
140
|
+
console.log('');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = { init };
|