claude-coder 1.9.0 → 1.9.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.
Files changed (74) hide show
  1. package/README.md +214 -214
  2. package/bin/cli.js +155 -155
  3. package/package.json +55 -55
  4. package/recipes/_shared/roles/developer.md +11 -11
  5. package/recipes/_shared/roles/product.md +12 -12
  6. package/recipes/_shared/roles/tester.md +12 -12
  7. package/recipes/_shared/test/report-format.md +86 -86
  8. package/recipes/backend/base.md +27 -27
  9. package/recipes/backend/components/auth.md +18 -18
  10. package/recipes/backend/components/crud-api.md +18 -18
  11. package/recipes/backend/components/file-service.md +15 -15
  12. package/recipes/backend/manifest.json +20 -20
  13. package/recipes/backend/test/api-test.md +25 -25
  14. package/recipes/console/base.md +37 -37
  15. package/recipes/console/components/modal-form.md +20 -20
  16. package/recipes/console/components/pagination.md +17 -17
  17. package/recipes/console/components/search.md +17 -17
  18. package/recipes/console/components/table-list.md +18 -18
  19. package/recipes/console/components/tabs.md +14 -14
  20. package/recipes/console/components/tree.md +15 -15
  21. package/recipes/console/components/upload.md +15 -15
  22. package/recipes/console/manifest.json +24 -24
  23. package/recipes/console/test/crud-e2e.md +47 -47
  24. package/recipes/h5/base.md +26 -26
  25. package/recipes/h5/components/animation.md +11 -11
  26. package/recipes/h5/components/countdown.md +11 -11
  27. package/recipes/h5/components/share.md +11 -11
  28. package/recipes/h5/components/swiper.md +11 -11
  29. package/recipes/h5/manifest.json +21 -21
  30. package/recipes/h5/test/h5-e2e.md +20 -20
  31. package/src/commands/auth.js +420 -362
  32. package/src/commands/setup-modules/helpers.js +100 -100
  33. package/src/commands/setup-modules/index.js +25 -25
  34. package/src/commands/setup-modules/mcp.js +115 -115
  35. package/src/commands/setup-modules/provider.js +260 -260
  36. package/src/commands/setup-modules/safety.js +47 -47
  37. package/src/commands/setup-modules/simplify.js +52 -52
  38. package/src/commands/setup.js +172 -172
  39. package/src/common/assets.js +245 -245
  40. package/src/common/config.js +125 -125
  41. package/src/common/constants.js +55 -55
  42. package/src/common/indicator.js +260 -260
  43. package/src/common/interaction.js +170 -170
  44. package/src/common/logging.js +77 -77
  45. package/src/common/sdk.js +50 -50
  46. package/src/common/tasks.js +88 -88
  47. package/src/common/utils.js +213 -213
  48. package/src/core/coding.js +33 -33
  49. package/src/core/go.js +264 -264
  50. package/src/core/hooks.js +500 -500
  51. package/src/core/init.js +166 -165
  52. package/src/core/plan.js +188 -187
  53. package/src/core/prompts.js +247 -247
  54. package/src/core/repair.js +36 -36
  55. package/src/core/runner.js +471 -458
  56. package/src/core/scan.js +93 -93
  57. package/src/core/session.js +280 -271
  58. package/src/core/simplify.js +74 -74
  59. package/src/core/state.js +105 -105
  60. package/src/index.js +76 -76
  61. package/templates/bash-process.md +12 -12
  62. package/templates/codingSystem.md +65 -65
  63. package/templates/codingUser.md +17 -17
  64. package/templates/coreProtocol.md +29 -29
  65. package/templates/goSystem.md +130 -130
  66. package/templates/guidance.json +72 -72
  67. package/templates/planSystem.md +78 -78
  68. package/templates/planUser.md +8 -8
  69. package/templates/requirements.example.md +57 -57
  70. package/templates/scanSystem.md +120 -120
  71. package/templates/scanUser.md +10 -10
  72. package/templates/test_rule.md +194 -194
  73. package/templates/web-testing.md +17 -17
  74. package/types/index.d.ts +217 -217
@@ -1,247 +1,247 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { loadConfig } = require('../common/config');
6
- const { assets } = require('../common/assets');
7
- const { loadTasks, getStats } = require('../common/tasks');
8
- const { loadState, selectNextTask } = require('./state');
9
-
10
- // --------------- System Prompt ---------------
11
-
12
- function buildSystemPrompt(type) {
13
- const core = assets.read('coreProtocol') || '';
14
- let specific = '';
15
- switch (type) {
16
- case 'scan': specific = assets.read('scanSystem') || ''; break;
17
- case 'coding': specific = assets.read('codingSystem') || ''; break;
18
- case 'plan': specific = assets.read('planSystem') || ''; break;
19
- case 'go': specific = assets.read('goSystem') || ''; break;
20
- }
21
- return specific ? `${specific}\n\n${core}` : core;
22
- }
23
-
24
- // --------------- Task Type Detection ---------------
25
-
26
- const WEB_CATEGORIES = new Set(['frontend', 'fullstack', 'test', 'e2e']);
27
- const WEB_KEYWORDS = /playwright|browser|页面|前端|UI|端到端|e2e/i;
28
-
29
- function needsWebTools(task) {
30
- if (!task) return true;
31
- if (WEB_CATEGORIES.has(task.category)) return true;
32
- const text = [task.description || '', ...(task.steps || [])].join(' ');
33
- return WEB_KEYWORDS.test(text);
34
- }
35
-
36
- // --------------- Hint Builders ---------------
37
-
38
- function buildMcpHint(config, task) {
39
- if (!config.webTestTool) return '';
40
- if (!needsWebTools(task)) return '';
41
- if (config.webTestTool === 'chrome-devtools') {
42
- return '前端/全栈任务可用 Chrome DevTools MCP(navigate、click、type_text、screenshot 等)做端到端测试和调试。';
43
- }
44
- return '前端/全栈任务可用 Playwright MCP(browser_navigate、browser_snapshot、browser_click 等)做端到端测试。';
45
- }
46
-
47
- function buildRetryHint(consecutiveFailures, lastValidateLog) {
48
- if (consecutiveFailures > 0 && lastValidateLog) {
49
- return `注意:上次会话校验失败,原因:${lastValidateLog}。请避免同样的问题。`;
50
- }
51
- return '';
52
- }
53
-
54
- function buildEnvHint(consecutiveFailures, sessionNum) {
55
- if (sessionNum <= 1) return '首次会话,需要时执行 claude-coder init 初始化环境。';
56
- if (consecutiveFailures > 0) return '上次失败,建议先确认环境状态。';
57
- return '';
58
- }
59
-
60
- function buildDocsHint() {
61
- const profile = assets.readJson('profile', null);
62
- if (!profile) return '';
63
- const docs = profile.existing_docs || [];
64
- if (docs.length > 0) {
65
- return `项目文档: ${docs.join(', ')}。编码前先读与任务相关的文档,了解接口约定和编码规范。`;
66
- }
67
- return '';
68
- }
69
-
70
- function buildTaskContext(projectRoot, taskId) {
71
- try {
72
- const taskData = loadTasks();
73
- if (!taskData) return '无法读取 tasks.json,请手动检查。';
74
- const features = taskData.features || [];
75
- const stats = getStats(taskData);
76
-
77
- const task = taskId
78
- ? features.find(f => f.id === taskId)
79
- : selectNextTask(taskData);
80
-
81
- if (!task) return '无待处理任务。';
82
-
83
- const { id, description, status, category, priority, depends_on, steps, ...rest } = task;
84
-
85
- const stepLines = (steps || [])
86
- .map((s, i) => ` ${i + 1}. ${s}`)
87
- .join('\n');
88
-
89
- const deps = (depends_on || []).length > 0
90
- ? `depends_on: [${depends_on.join(', ')}]`
91
- : '';
92
-
93
- const lines = [
94
- `**${id}**: "${description}"`,
95
- `状态: ${status}, category: ${category}, priority: ${priority || 'N/A'} ${deps}`,
96
- `步骤:\n${stepLines}`,
97
- `进度: ${stats.done}/${stats.total} done, ${stats.failed} failed`,
98
- `项目路径: ${projectRoot}`,
99
- ];
100
-
101
- const extras = Object.entries(rest).filter(([, v]) => v != null && v !== '');
102
- if (extras.length > 0) {
103
- lines.push('补充信息:');
104
- for (const [k, v] of extras) {
105
- lines.push(` ${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`);
106
- }
107
- }
108
-
109
- return lines.join('\n');
110
- } catch {
111
- return '任务上下文加载失败,请读取 .claude-coder/tasks.json 自行确认。';
112
- }
113
- }
114
-
115
- function buildTestEnvHint(projectRoot) {
116
- if (assets.exists('testEnv')) {
117
- return `测试凭证文件: ${projectRoot}/.claude-coder/test.env(含 API Key、测试账号等),测试前用 source 加载。`;
118
- }
119
- return '';
120
- }
121
-
122
- function buildWebTestHint(config, task) {
123
- if (!config.webTestTool) return '';
124
- if (!needsWebTools(task)) return '';
125
-
126
- if (config.webTestTool === 'chrome-devtools') {
127
- return 'Chrome DevTools MCP 已启用,通过 autoConnect 连接已打开的 Chrome 浏览器,直接复用已有登录态。';
128
- }
129
-
130
- const mode = config.webTestMode;
131
- switch (mode) {
132
- case 'persistent':
133
- return 'Playwright MCP 使用 persistent 模式,浏览器登录状态持久保存,无需额外登录操作。';
134
- case 'isolated':
135
- return assets.exists('playwrightAuth')
136
- ? 'Playwright MCP 使用 isolated 模式,已检测到登录状态文件,每次会话自动加载。'
137
- : 'Playwright MCP 使用 isolated 模式,未检测到登录状态文件。如需登录,请先运行 claude-coder auth <URL>。';
138
- case 'extension':
139
- return 'Playwright MCP 使用 extension 模式,已连接用户真实浏览器,直接复用已有登录态。';
140
- default:
141
- return '';
142
- }
143
- }
144
-
145
- function buildMemoryHint() {
146
- const sr = assets.readJson('sessionResult', null);
147
- if (!sr?.session_result) return '';
148
- const base = `上次会话 ${sr.session_result}(${sr.status_before || '?'} → ${sr.status_after || '?'})。`;
149
- if (!sr.notes || !sr.notes.trim()) return base;
150
- return `${base}遗留: ${sr.notes}`;
151
- }
152
-
153
- function buildServiceHint(maxSessions) {
154
- return maxSessions === 1
155
- ? '单次模式:收尾时停止所有后台服务。'
156
- : '连续模式:收尾时不要停止后台服务,保持服务运行以便下个 session 继续使用。';
157
- }
158
-
159
- // --------------- Context Builders ---------------
160
-
161
- function _resolveTask(taskId) {
162
- try {
163
- const taskData = loadTasks();
164
- if (!taskData) return null;
165
- const features = taskData.features || [];
166
- return taskId ? features.find(f => f.id === taskId) : selectNextTask(taskData);
167
- } catch { return null; }
168
- }
169
-
170
- /**
171
- * 构建 coding session 的完整上下文(user prompt)
172
- */
173
- function buildCodingContext(sessionNum, opts = {}) {
174
- const config = loadConfig();
175
- const consecutiveFailures = opts.consecutiveFailures || 0;
176
- const projectRoot = assets.projectRoot;
177
- const task = _resolveTask(opts.taskId);
178
-
179
- return assets.render('codingUser', {
180
- sessionNum,
181
- taskContext: buildTaskContext(projectRoot, opts.taskId),
182
- mcpHint: buildMcpHint(config, task),
183
- retryContext: buildRetryHint(consecutiveFailures, opts.lastValidateLog),
184
- envHint: buildEnvHint(consecutiveFailures, sessionNum),
185
- docsHint: buildDocsHint(),
186
- testEnvHint: buildTestEnvHint(projectRoot),
187
- webTestHint: buildWebTestHint(config, task),
188
- memoryHint: buildMemoryHint(),
189
- serviceHint: buildServiceHint(opts.maxSessions || 50),
190
- });
191
- }
192
-
193
- // --------------- Scan Session ---------------
194
-
195
- function buildScanPrompt(projectType) {
196
- return assets.render('scanUser', { projectType });
197
- }
198
-
199
- // --------------- Plan Session ---------------
200
-
201
- function buildPlanPrompt(planPath) {
202
- const projectRoot = assets.projectRoot;
203
-
204
- let taskContext = '';
205
- let recentExamples = '';
206
- try {
207
- const taskData = loadTasks();
208
- if (taskData) {
209
- const features = taskData.features || [];
210
- const state = loadState();
211
- const nextId = `feat-${String(state.next_task_id).padStart(3, '0')}`;
212
- const categories = [...new Set(features.map(f => f.category))].join(', ');
213
-
214
- taskContext = `新任务 ID 从 ${nextId} 开始,priority 从 ${state.next_priority} 开始。已有 category: ${categories || '无'}。`;
215
-
216
- const recent = features.slice(-3);
217
- if (recent.length) {
218
- recentExamples = '已有任务格式参考(保持一致性):\n' +
219
- recent.map(f => ` ${f.id}: "${f.description}" (category=${f.category}, steps=${(f.steps || []).length}步, depends_on=[${(f.depends_on || []).join(',')}])`).join('\n');
220
- }
221
- }
222
- } catch { /* ignore */ }
223
-
224
- let testRuleHint = '';
225
- if (assets.exists('testRule') && assets.exists('mcpConfig')) {
226
- testRuleHint = '【浏览器测试规则】项目已配置浏览器测试工具(.mcp.json),' +
227
- '`.claude-coder/assets/test_rule.md` 包含测试规范(Smart Snapshot、等待策略、步骤模板等)。' +
228
- '前端页面 test 类任务 steps 首步加入 `【规则】阅读 .claude-coder/assets/test_rule.md`。';
229
- }
230
-
231
- return assets.render('planUser', {
232
- taskContext,
233
- recentExamples,
234
- projectRoot,
235
- planPath,
236
- testRuleHint,
237
- });
238
- }
239
-
240
- // --------------- Exports ---------------
241
-
242
- module.exports = {
243
- buildSystemPrompt,
244
- buildCodingContext,
245
- buildScanPrompt,
246
- buildPlanPrompt,
247
- };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { loadConfig } = require('../common/config');
6
+ const { assets } = require('../common/assets');
7
+ const { loadTasks, getStats } = require('../common/tasks');
8
+ const { loadState, selectNextTask } = require('./state');
9
+
10
+ // --------------- System Prompt ---------------
11
+
12
+ function buildSystemPrompt(type) {
13
+ const core = assets.read('coreProtocol') || '';
14
+ let specific = '';
15
+ switch (type) {
16
+ case 'scan': specific = assets.read('scanSystem') || ''; break;
17
+ case 'coding': specific = assets.read('codingSystem') || ''; break;
18
+ case 'plan': specific = assets.read('planSystem') || ''; break;
19
+ case 'go': specific = assets.read('goSystem') || ''; break;
20
+ }
21
+ return specific ? `${specific}\n\n${core}` : core;
22
+ }
23
+
24
+ // --------------- Task Type Detection ---------------
25
+
26
+ const WEB_CATEGORIES = new Set(['frontend', 'fullstack', 'test', 'e2e']);
27
+ const WEB_KEYWORDS = /playwright|browser|页面|前端|UI|端到端|e2e/i;
28
+
29
+ function needsWebTools(task) {
30
+ if (!task) return true;
31
+ if (WEB_CATEGORIES.has(task.category)) return true;
32
+ const text = [task.description || '', ...(task.steps || [])].join(' ');
33
+ return WEB_KEYWORDS.test(text);
34
+ }
35
+
36
+ // --------------- Hint Builders ---------------
37
+
38
+ function buildMcpHint(config, task) {
39
+ if (!config.webTestTool) return '';
40
+ if (!needsWebTools(task)) return '';
41
+ if (config.webTestTool === 'chrome-devtools') {
42
+ return '前端/全栈任务可用 Chrome DevTools MCP(navigate、click、type_text、screenshot 等)做端到端测试和调试。';
43
+ }
44
+ return '前端/全栈任务可用 Playwright MCP(browser_navigate、browser_snapshot、browser_click 等)做端到端测试。';
45
+ }
46
+
47
+ function buildRetryHint(consecutiveFailures, lastValidateLog) {
48
+ if (consecutiveFailures > 0 && lastValidateLog) {
49
+ return `注意:上次会话校验失败,原因:${lastValidateLog}。请避免同样的问题。`;
50
+ }
51
+ return '';
52
+ }
53
+
54
+ function buildEnvHint(consecutiveFailures, sessionNum) {
55
+ if (sessionNum <= 1) return '首次会话,需要时执行 claude-coder init 初始化环境。';
56
+ if (consecutiveFailures > 0) return '上次失败,建议先确认环境状态。';
57
+ return '';
58
+ }
59
+
60
+ function buildDocsHint() {
61
+ const profile = assets.readJson('profile', null);
62
+ if (!profile) return '';
63
+ const docs = profile.existing_docs || [];
64
+ if (docs.length > 0) {
65
+ return `项目文档: ${docs.join(', ')}。编码前先读与任务相关的文档,了解接口约定和编码规范。`;
66
+ }
67
+ return '';
68
+ }
69
+
70
+ function buildTaskContext(projectRoot, taskId) {
71
+ try {
72
+ const taskData = loadTasks();
73
+ if (!taskData) return '无法读取 tasks.json,请手动检查。';
74
+ const features = taskData.features || [];
75
+ const stats = getStats(taskData);
76
+
77
+ const task = taskId
78
+ ? features.find(f => f.id === taskId)
79
+ : selectNextTask(taskData);
80
+
81
+ if (!task) return '无待处理任务。';
82
+
83
+ const { id, description, status, category, priority, depends_on, steps, ...rest } = task;
84
+
85
+ const stepLines = (steps || [])
86
+ .map((s, i) => ` ${i + 1}. ${s}`)
87
+ .join('\n');
88
+
89
+ const deps = (depends_on || []).length > 0
90
+ ? `depends_on: [${depends_on.join(', ')}]`
91
+ : '';
92
+
93
+ const lines = [
94
+ `**${id}**: "${description}"`,
95
+ `状态: ${status}, category: ${category}, priority: ${priority || 'N/A'} ${deps}`,
96
+ `步骤:\n${stepLines}`,
97
+ `进度: ${stats.done}/${stats.total} done, ${stats.failed} failed`,
98
+ `项目路径: ${projectRoot}`,
99
+ ];
100
+
101
+ const extras = Object.entries(rest).filter(([, v]) => v != null && v !== '');
102
+ if (extras.length > 0) {
103
+ lines.push('补充信息:');
104
+ for (const [k, v] of extras) {
105
+ lines.push(` ${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`);
106
+ }
107
+ }
108
+
109
+ return lines.join('\n');
110
+ } catch {
111
+ return '任务上下文加载失败,请读取 .claude-coder/tasks.json 自行确认。';
112
+ }
113
+ }
114
+
115
+ function buildTestEnvHint(projectRoot) {
116
+ if (assets.exists('testEnv')) {
117
+ return `测试凭证文件: ${projectRoot}/.claude-coder/test.env(含 API Key、测试账号等),测试前用 source 加载。`;
118
+ }
119
+ return '';
120
+ }
121
+
122
+ function buildWebTestHint(config, task) {
123
+ if (!config.webTestTool) return '';
124
+ if (!needsWebTools(task)) return '';
125
+
126
+ if (config.webTestTool === 'chrome-devtools') {
127
+ return 'Chrome DevTools MCP 已启用,通过 autoConnect 连接已打开的 Chrome 浏览器,直接复用已有登录态。';
128
+ }
129
+
130
+ const mode = config.webTestMode;
131
+ switch (mode) {
132
+ case 'persistent':
133
+ return 'Playwright MCP 使用 persistent 模式,浏览器登录状态持久保存,无需额外登录操作。';
134
+ case 'isolated':
135
+ return assets.exists('playwrightAuth')
136
+ ? 'Playwright MCP 使用 isolated 模式,已检测到登录状态文件,每次会话自动加载。'
137
+ : 'Playwright MCP 使用 isolated 模式,未检测到登录状态文件。如需登录,请先运行 claude-coder auth <URL>。';
138
+ case 'extension':
139
+ return 'Playwright MCP 使用 extension 模式,已连接用户真实浏览器,直接复用已有登录态。';
140
+ default:
141
+ return '';
142
+ }
143
+ }
144
+
145
+ function buildMemoryHint() {
146
+ const sr = assets.readJson('sessionResult', null);
147
+ if (!sr?.session_result) return '';
148
+ const base = `上次会话 ${sr.session_result}(${sr.status_before || '?'} → ${sr.status_after || '?'})。`;
149
+ if (!sr.notes || !sr.notes.trim()) return base;
150
+ return `${base}遗留: ${sr.notes}`;
151
+ }
152
+
153
+ function buildServiceHint(maxSessions) {
154
+ return maxSessions === 1
155
+ ? '单次模式:收尾时停止所有后台服务。'
156
+ : '连续模式:收尾时不要停止后台服务,保持服务运行以便下个 session 继续使用。';
157
+ }
158
+
159
+ // --------------- Context Builders ---------------
160
+
161
+ function _resolveTask(taskId) {
162
+ try {
163
+ const taskData = loadTasks();
164
+ if (!taskData) return null;
165
+ const features = taskData.features || [];
166
+ return taskId ? features.find(f => f.id === taskId) : selectNextTask(taskData);
167
+ } catch { return null; }
168
+ }
169
+
170
+ /**
171
+ * 构建 coding session 的完整上下文(user prompt)
172
+ */
173
+ function buildCodingContext(sessionNum, opts = {}) {
174
+ const config = loadConfig();
175
+ const consecutiveFailures = opts.consecutiveFailures || 0;
176
+ const projectRoot = assets.projectRoot;
177
+ const task = _resolveTask(opts.taskId);
178
+
179
+ return assets.render('codingUser', {
180
+ sessionNum,
181
+ taskContext: buildTaskContext(projectRoot, opts.taskId),
182
+ mcpHint: buildMcpHint(config, task),
183
+ retryContext: buildRetryHint(consecutiveFailures, opts.lastValidateLog),
184
+ envHint: buildEnvHint(consecutiveFailures, sessionNum),
185
+ docsHint: buildDocsHint(),
186
+ testEnvHint: buildTestEnvHint(projectRoot),
187
+ webTestHint: buildWebTestHint(config, task),
188
+ memoryHint: buildMemoryHint(),
189
+ serviceHint: buildServiceHint(opts.maxSessions || 50),
190
+ });
191
+ }
192
+
193
+ // --------------- Scan Session ---------------
194
+
195
+ function buildScanPrompt(projectType) {
196
+ return assets.render('scanUser', { projectType });
197
+ }
198
+
199
+ // --------------- Plan Session ---------------
200
+
201
+ function buildPlanPrompt(planPath) {
202
+ const projectRoot = assets.projectRoot;
203
+
204
+ let taskContext = '';
205
+ let recentExamples = '';
206
+ try {
207
+ const taskData = loadTasks();
208
+ if (taskData) {
209
+ const features = taskData.features || [];
210
+ const state = loadState();
211
+ const nextId = `feat-${String(state.next_task_id).padStart(3, '0')}`;
212
+ const categories = [...new Set(features.map(f => f.category))].join(', ');
213
+
214
+ taskContext = `新任务 ID 从 ${nextId} 开始,priority 从 ${state.next_priority} 开始。已有 category: ${categories || '无'}。`;
215
+
216
+ const recent = features.slice(-3);
217
+ if (recent.length) {
218
+ recentExamples = '已有任务格式参考(保持一致性):\n' +
219
+ recent.map(f => ` ${f.id}: "${f.description}" (category=${f.category}, steps=${(f.steps || []).length}步, depends_on=[${(f.depends_on || []).join(',')}])`).join('\n');
220
+ }
221
+ }
222
+ } catch { /* ignore */ }
223
+
224
+ let testRuleHint = '';
225
+ if (assets.exists('testRule') && assets.exists('mcpConfig')) {
226
+ testRuleHint = '【浏览器测试规则】项目已配置浏览器测试工具(.mcp.json),' +
227
+ '`.claude-coder/assets/test_rule.md` 包含测试规范(Smart Snapshot、等待策略、步骤模板等)。' +
228
+ '前端页面 test 类任务 steps 首步加入 `【规则】阅读 .claude-coder/assets/test_rule.md`。';
229
+ }
230
+
231
+ return assets.render('planUser', {
232
+ taskContext,
233
+ recentExamples,
234
+ projectRoot,
235
+ planPath,
236
+ testRuleHint,
237
+ });
238
+ }
239
+
240
+ // --------------- Exports ---------------
241
+
242
+ module.exports = {
243
+ buildSystemPrompt,
244
+ buildCodingContext,
245
+ buildScanPrompt,
246
+ buildPlanPrompt,
247
+ };
@@ -1,36 +1,36 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { log } = require('../common/config');
6
- const { Session } = require('./session');
7
-
8
- async function executeRepair(config, filePath, opts = {}) {
9
- if (!fs.existsSync(filePath)) return;
10
-
11
- const rawContent = fs.readFileSync(filePath, 'utf8');
12
- if (!rawContent || !rawContent.trim()) return;
13
-
14
- const fileName = path.basename(filePath);
15
- log('info', `正在使用 AI 修复 ${fileName}...`);
16
-
17
- const prompt = `文件 ${filePath} 的 JSON 格式已损坏,请修复并用 Write 工具写入原路径。\n\n当前损坏内容:\n${rawContent}`;
18
-
19
- try {
20
- await Session.run('repair', config, {
21
- logFileName: `repair_${fileName.replace('.json', '')}.log`,
22
- label: `repair:${fileName}`,
23
-
24
- async execute(session) {
25
- const queryOpts = session.buildQueryOptions(opts);
26
- await session.runQuery(prompt, queryOpts);
27
- log('ok', `AI 修复 ${fileName} 完成`);
28
- return {};
29
- },
30
- });
31
- } catch (err) {
32
- log('warn', `AI 修复 ${fileName} 失败: ${err.message}`);
33
- }
34
- }
35
-
36
- module.exports = { executeRepair };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { log } = require('../common/config');
6
+ const { Session } = require('./session');
7
+
8
+ async function executeRepair(config, filePath, opts = {}) {
9
+ if (!fs.existsSync(filePath)) return;
10
+
11
+ const rawContent = fs.readFileSync(filePath, 'utf8');
12
+ if (!rawContent || !rawContent.trim()) return;
13
+
14
+ const fileName = path.basename(filePath);
15
+ log('info', `正在使用 AI 修复 ${fileName}...`);
16
+
17
+ const prompt = `文件 ${filePath} 的 JSON 格式已损坏,请修复并用 Write 工具写入原路径。\n\n当前损坏内容:\n${rawContent}`;
18
+
19
+ try {
20
+ await Session.run('repair', config, {
21
+ logFileName: `repair_${fileName.replace('.json', '')}.log`,
22
+ label: `repair:${fileName}`,
23
+
24
+ async execute(session) {
25
+ const queryOpts = session.buildQueryOptions(opts);
26
+ await session.runQuery(prompt, queryOpts);
27
+ log('ok', `AI 修复 ${fileName} 完成`);
28
+ return {};
29
+ },
30
+ });
31
+ } catch (err) {
32
+ log('warn', `AI 修复 ${fileName} 失败: ${err.message}`);
33
+ }
34
+ }
35
+
36
+ module.exports = { executeRepair };