claude-coder 1.8.0 → 1.8.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/README.md +167 -177
- package/bin/cli.js +172 -159
- package/package.json +52 -52
- package/src/commands/auth.js +240 -294
- package/src/commands/setup-modules/helpers.js +99 -105
- 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 -192
- package/src/common/config.js +125 -138
- package/src/common/constants.js +55 -56
- package/src/common/indicator.js +222 -222
- package/src/common/interaction.js +170 -170
- package/src/common/logging.js +77 -76
- package/src/common/sdk.js +50 -50
- package/src/common/tasks.js +88 -157
- package/src/common/utils.js +161 -146
- package/src/core/coding.js +55 -55
- package/src/core/context.js +117 -132
- package/src/core/go.js +310 -0
- package/src/core/harness.js +484 -0
- package/src/core/hooks.js +533 -528
- package/src/core/init.js +171 -163
- package/src/core/plan.js +325 -318
- package/src/core/prompts.js +227 -253
- package/src/core/query.js +49 -47
- package/src/core/repair.js +46 -58
- package/src/core/runner.js +195 -352
- package/src/core/scan.js +89 -89
- package/src/core/{base.js → session.js} +56 -53
- package/src/core/simplify.js +52 -59
- package/templates/bash-process.md +12 -5
- package/templates/codingSystem.md +65 -0
- package/templates/codingUser.md +17 -31
- package/templates/coreProtocol.md +29 -0
- package/templates/goSystem.md +130 -0
- package/templates/guidance.json +52 -34
- package/templates/planSystem.md +78 -0
- package/templates/planUser.md +9 -0
- package/templates/playwright.md +16 -16
- package/templates/requirements.example.md +57 -56
- package/templates/scanSystem.md +120 -0
- package/templates/scanUser.md +10 -17
- package/templates/test_rule.md +194 -194
- package/src/core/validator.js +0 -138
- package/templates/addGuide.md +0 -98
- package/templates/addUser.md +0 -26
- package/templates/agentProtocol.md +0 -195
- package/templates/scanProtocol.md +0 -118
package/src/common/assets.js
CHANGED
|
@@ -1,192 +1,236 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
|
|
6
|
-
const BUNDLED_DIR = path.join(__dirname, '..', '..', 'templates');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// kind: '
|
|
10
|
-
// kind: '
|
|
11
|
-
// kind: '
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
['
|
|
16
|
-
['
|
|
17
|
-
['
|
|
18
|
-
['
|
|
19
|
-
['
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
['
|
|
23
|
-
['
|
|
24
|
-
['
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
['
|
|
28
|
-
['
|
|
29
|
-
['
|
|
30
|
-
['
|
|
31
|
-
['
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
['
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
['
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
['
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
['
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
['
|
|
48
|
-
]);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
for (const
|
|
177
|
-
const
|
|
178
|
-
if (fs.existsSync(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const BUNDLED_DIR = path.join(__dirname, '..', '..', 'templates');
|
|
7
|
+
const BUNDLED_RECIPES_DIR = path.join(__dirname, '..', '..', 'recipes');
|
|
8
|
+
|
|
9
|
+
// kind: 'template' — 双目录解析(用户 assets → 内置 bundled),有缓存
|
|
10
|
+
// kind: 'data' — .claude-coder/ 目录,无缓存
|
|
11
|
+
// kind: 'runtime' — .claude-coder/.runtime/ 目录,无缓存
|
|
12
|
+
// kind: 'root' — 项目根目录,无缓存
|
|
13
|
+
const REGISTRY = new Map([
|
|
14
|
+
// System Prompt Templates (per session type)
|
|
15
|
+
['coreProtocol', { file: 'coreProtocol.md', kind: 'template' }],
|
|
16
|
+
['codingSystem', { file: 'codingSystem.md', kind: 'template' }],
|
|
17
|
+
['planSystem', { file: 'planSystem.md', kind: 'template' }],
|
|
18
|
+
['scanSystem', { file: 'scanSystem.md', kind: 'template' }],
|
|
19
|
+
['goSystem', { file: 'goSystem.md', kind: 'template' }],
|
|
20
|
+
|
|
21
|
+
// User Prompt Templates
|
|
22
|
+
['codingUser', { file: 'codingUser.md', kind: 'template' }],
|
|
23
|
+
['scanUser', { file: 'scanUser.md', kind: 'template' }],
|
|
24
|
+
['planUser', { file: 'planUser.md', kind: 'template' }],
|
|
25
|
+
|
|
26
|
+
// Other Templates
|
|
27
|
+
['testRule', { file: 'test_rule.md', kind: 'template' }],
|
|
28
|
+
['guidance', { file: 'guidance.json', kind: 'template' }],
|
|
29
|
+
['playwright', { file: 'playwright.md', kind: 'template' }],
|
|
30
|
+
['bashProcess', { file: 'bash-process.md', kind: 'template' }],
|
|
31
|
+
['requirements', { file: 'requirements.example.md', kind: 'template' }],
|
|
32
|
+
|
|
33
|
+
// Data files (.claude-coder/)
|
|
34
|
+
['env', { file: '.env', kind: 'data' }],
|
|
35
|
+
['tasks', { file: 'tasks.json', kind: 'data' }],
|
|
36
|
+
['progress', { file: 'progress.json', kind: 'data' }],
|
|
37
|
+
['sessionResult', { file: 'session_result.json', kind: 'data' }],
|
|
38
|
+
['profile', { file: 'project_profile.json', kind: 'data' }],
|
|
39
|
+
['testEnv', { file: 'test.env', kind: 'data' }],
|
|
40
|
+
['playwrightAuth', { file: 'playwright-auth.json', kind: 'data' }],
|
|
41
|
+
|
|
42
|
+
// Runtime files (.claude-coder/.runtime/)
|
|
43
|
+
['harnessState', { file: 'harness_state.json', kind: 'runtime' }],
|
|
44
|
+
['browserProfile', { file: 'browser-profile', kind: 'runtime' }],
|
|
45
|
+
|
|
46
|
+
// Root files (project root)
|
|
47
|
+
['mcpConfig', { file: '.mcp.json', kind: 'root' }],
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
const DIRS = new Map([
|
|
51
|
+
['loop', ''],
|
|
52
|
+
['assets', 'assets'],
|
|
53
|
+
['runtime', '.runtime'],
|
|
54
|
+
['logs', '.runtime/logs'],
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
function renderTemplate(template, vars = {}) {
|
|
58
|
+
return template
|
|
59
|
+
.replace(/\{\{(\w+)\}\}/g, (_, key) =>
|
|
60
|
+
Object.prototype.hasOwnProperty.call(vars, key) ? String(vars[key]) : ''
|
|
61
|
+
)
|
|
62
|
+
.replace(/^\s+$/gm, '')
|
|
63
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
64
|
+
.trim();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class AssetManager {
|
|
68
|
+
constructor() {
|
|
69
|
+
this.projectRoot = null;
|
|
70
|
+
this.loopDir = null;
|
|
71
|
+
this.assetsDir = null;
|
|
72
|
+
this.bundledDir = BUNDLED_DIR;
|
|
73
|
+
this.registry = new Map(REGISTRY);
|
|
74
|
+
this.cache = new Map();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
init(projectRoot) {
|
|
78
|
+
this.projectRoot = projectRoot || process.cwd();
|
|
79
|
+
this.loopDir = path.join(this.projectRoot, '.claude-coder');
|
|
80
|
+
this.assetsDir = path.join(this.loopDir, 'assets');
|
|
81
|
+
this.cache.clear();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_ensureInit() {
|
|
85
|
+
if (!this.loopDir) this.init();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
path(name) {
|
|
89
|
+
this._ensureInit();
|
|
90
|
+
const entry = this.registry.get(name);
|
|
91
|
+
if (!entry) return null;
|
|
92
|
+
switch (entry.kind) {
|
|
93
|
+
case 'template': return this._resolveTemplate(entry.file);
|
|
94
|
+
case 'data': return path.join(this.loopDir, entry.file);
|
|
95
|
+
case 'runtime': return path.join(this.loopDir, '.runtime', entry.file);
|
|
96
|
+
case 'root': return path.join(this.projectRoot, entry.file);
|
|
97
|
+
default: return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_resolveTemplate(filename) {
|
|
102
|
+
if (this.assetsDir) {
|
|
103
|
+
const userPath = path.join(this.assetsDir, filename);
|
|
104
|
+
if (fs.existsSync(userPath)) return userPath;
|
|
105
|
+
}
|
|
106
|
+
const bundled = path.join(this.bundledDir, filename);
|
|
107
|
+
if (fs.existsSync(bundled)) return bundled;
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
dir(name) {
|
|
112
|
+
this._ensureInit();
|
|
113
|
+
const rel = DIRS.get(name);
|
|
114
|
+
if (rel === undefined) return null;
|
|
115
|
+
return rel === '' ? this.loopDir : path.join(this.loopDir, rel);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
exists(name) {
|
|
119
|
+
const p = this.path(name);
|
|
120
|
+
return p ? fs.existsSync(p) : false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
read(name) {
|
|
124
|
+
this._ensureInit();
|
|
125
|
+
const entry = this.registry.get(name);
|
|
126
|
+
if (!entry) return null;
|
|
127
|
+
|
|
128
|
+
if (entry.kind === 'template') {
|
|
129
|
+
const key = entry.file;
|
|
130
|
+
if (this.cache.has(key)) return this.cache.get(key);
|
|
131
|
+
const filePath = this._resolveTemplate(entry.file);
|
|
132
|
+
if (!filePath) return '';
|
|
133
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
134
|
+
this.cache.set(key, content);
|
|
135
|
+
return content;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const filePath = this.path(name);
|
|
139
|
+
if (!filePath || !fs.existsSync(filePath)) return null;
|
|
140
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
readJson(name, fallback = null) {
|
|
144
|
+
const content = this.read(name);
|
|
145
|
+
if (content === null || content === '') return fallback;
|
|
146
|
+
try {
|
|
147
|
+
return JSON.parse(content);
|
|
148
|
+
} catch {
|
|
149
|
+
return fallback;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
write(name, content) {
|
|
154
|
+
this._ensureInit();
|
|
155
|
+
const entry = this.registry.get(name);
|
|
156
|
+
if (!entry || entry.kind === 'template') return;
|
|
157
|
+
const filePath = this.path(name);
|
|
158
|
+
if (!filePath) return;
|
|
159
|
+
const dir = path.dirname(filePath);
|
|
160
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
161
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
writeJson(name, data) {
|
|
165
|
+
this.write(name, JSON.stringify(data, null, 2) + '\n');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
render(name, vars = {}) {
|
|
169
|
+
const raw = this.read(name);
|
|
170
|
+
if (!raw) return '';
|
|
171
|
+
return renderTemplate(raw, vars);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
ensureDirs() {
|
|
175
|
+
this._ensureInit();
|
|
176
|
+
for (const [, rel] of DIRS) {
|
|
177
|
+
const dir = rel === '' ? this.loopDir : path.join(this.loopDir, rel);
|
|
178
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
deployAll() {
|
|
183
|
+
this._ensureInit();
|
|
184
|
+
if (!fs.existsSync(this.assetsDir)) {
|
|
185
|
+
fs.mkdirSync(this.assetsDir, { recursive: true });
|
|
186
|
+
}
|
|
187
|
+
const files = fs.readdirSync(this.bundledDir);
|
|
188
|
+
const deployed = [];
|
|
189
|
+
for (const file of files) {
|
|
190
|
+
const dest = path.join(this.assetsDir, file);
|
|
191
|
+
if (fs.existsSync(dest)) continue;
|
|
192
|
+
const src = path.join(this.bundledDir, file);
|
|
193
|
+
try {
|
|
194
|
+
fs.copyFileSync(src, dest);
|
|
195
|
+
deployed.push(file);
|
|
196
|
+
} catch { /* skip */ }
|
|
197
|
+
}
|
|
198
|
+
return deployed;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
deployRecipes() {
|
|
202
|
+
this._ensureInit();
|
|
203
|
+
const destDir = path.join(this.loopDir, 'recipes');
|
|
204
|
+
if (!fs.existsSync(BUNDLED_RECIPES_DIR)) return [];
|
|
205
|
+
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
|
206
|
+
|
|
207
|
+
const deployed = [];
|
|
208
|
+
const walk = (srcBase, destBase) => {
|
|
209
|
+
const entries = fs.readdirSync(srcBase, { withFileTypes: true });
|
|
210
|
+
for (const entry of entries) {
|
|
211
|
+
const srcPath = path.join(srcBase, entry.name);
|
|
212
|
+
const destPath = path.join(destBase, entry.name);
|
|
213
|
+
if (entry.isDirectory()) {
|
|
214
|
+
if (!fs.existsSync(destPath)) fs.mkdirSync(destPath, { recursive: true });
|
|
215
|
+
walk(srcPath, destPath);
|
|
216
|
+
} else {
|
|
217
|
+
if (fs.existsSync(destPath)) continue;
|
|
218
|
+
try {
|
|
219
|
+
fs.copyFileSync(srcPath, destPath);
|
|
220
|
+
deployed.push(path.relative(destDir, destPath));
|
|
221
|
+
} catch { /* skip */ }
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
walk(BUNDLED_RECIPES_DIR, destDir);
|
|
226
|
+
return deployed;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
clearCache() {
|
|
230
|
+
this.cache.clear();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const assets = new AssetManager();
|
|
235
|
+
|
|
236
|
+
module.exports = { AssetManager, assets, renderTemplate };
|