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/src/scanner.js CHANGED
@@ -1,62 +1,62 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const { paths, log, ensureLoopDir } = require('./config');
5
- const { runScanSession } = require('./session');
6
-
7
- function validateProfile() {
8
- const p = paths();
9
- if (!fs.existsSync(p.profile)) return { valid: false, issues: ['profile 不存在'] };
10
-
11
- let profile;
12
- try {
13
- profile = JSON.parse(fs.readFileSync(p.profile, 'utf8'));
14
- } catch {
15
- return { valid: false, issues: ['profile JSON 格式错误'] };
16
- }
17
-
18
- const issues = [];
19
-
20
- if (!profile.tech_stack?.backend?.framework && !profile.tech_stack?.frontend?.framework) {
21
- issues.push('tech_stack 缺少 backend 或 frontend 框架');
22
- }
23
- if (profile.tech_stack?.backend?.framework &&
24
- (!profile.services || profile.services.length === 0)) {
25
- issues.push('有后端框架但 services 为空(缺少启动命令和端口)');
26
- }
27
- if (!profile.existing_docs || profile.existing_docs.length === 0) {
28
- issues.push('existing_docs 为空(至少需要 README.md)');
29
- }
30
-
31
- return { valid: issues.length === 0, issues };
32
- }
33
-
34
- async function scan(requirement, opts = {}) {
35
- const p = paths();
36
- ensureLoopDir();
37
-
38
- const maxAttempts = 3;
39
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
40
- log('info', `初始化尝试 ${attempt} / ${maxAttempts} ...`);
41
-
42
- const result = await runScanSession(requirement, opts);
43
-
44
- if (fs.existsSync(p.profile) && fs.existsSync(p.tasksFile)) {
45
- const profileCheck = validateProfile();
46
- if (!profileCheck.valid) {
47
- log('warn', `profile 质量问题: ${profileCheck.issues.join('; ')}`);
48
- }
49
- log('ok', '初始化完成');
50
- return { success: true, cost: result.cost };
51
- }
52
-
53
- if (attempt < maxAttempts) {
54
- log('warn', '初始化未完成,将重试...');
55
- }
56
- }
57
-
58
- log('error', `初始化失败:已重试 ${maxAttempts} 次,关键文件仍未生成`);
59
- return { success: false, cost: null };
60
- }
61
-
62
- module.exports = { scan, validateProfile };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const { paths, log, ensureLoopDir } = require('./config');
5
+ const { runScanSession } = require('./session');
6
+
7
+ function validateProfile() {
8
+ const p = paths();
9
+ if (!fs.existsSync(p.profile)) return { valid: false, issues: ['profile 不存在'] };
10
+
11
+ let profile;
12
+ try {
13
+ profile = JSON.parse(fs.readFileSync(p.profile, 'utf8'));
14
+ } catch {
15
+ return { valid: false, issues: ['profile JSON 格式错误'] };
16
+ }
17
+
18
+ const issues = [];
19
+
20
+ if (!profile.tech_stack?.backend?.framework && !profile.tech_stack?.frontend?.framework) {
21
+ issues.push('tech_stack 缺少 backend 或 frontend 框架');
22
+ }
23
+ if (profile.tech_stack?.backend?.framework &&
24
+ (!profile.services || profile.services.length === 0)) {
25
+ issues.push('有后端框架但 services 为空(缺少启动命令和端口)');
26
+ }
27
+ if (!profile.existing_docs || profile.existing_docs.length === 0) {
28
+ issues.push('existing_docs 为空(至少需要 README.md)');
29
+ }
30
+
31
+ return { valid: issues.length === 0, issues };
32
+ }
33
+
34
+ async function scan(requirement, opts = {}) {
35
+ const p = paths();
36
+ ensureLoopDir();
37
+
38
+ const maxAttempts = 3;
39
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
40
+ log('info', `初始化尝试 ${attempt} / ${maxAttempts} ...`);
41
+
42
+ const result = await runScanSession(requirement, opts);
43
+
44
+ if (fs.existsSync(p.profile)) {
45
+ const profileCheck = validateProfile();
46
+ if (!profileCheck.valid) {
47
+ log('warn', `profile 质量问题: ${profileCheck.issues.join('; ')}`);
48
+ }
49
+ log('ok', '项目扫描完成');
50
+ return { success: true, cost: result.cost };
51
+ }
52
+
53
+ if (attempt < maxAttempts) {
54
+ log('warn', '初始化未完成,将重试...');
55
+ }
56
+ }
57
+
58
+ log('error', `初始化失败:已重试 ${maxAttempts} 次,关键文件仍未生成`);
59
+ return { success: false, cost: null };
60
+ }
61
+
62
+ module.exports = { scan, validateProfile };