claude-coder 1.8.0 → 1.8.1

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