mcp-probe-kit 3.6.9 → 3.6.11

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 (42) hide show
  1. package/README.md +13 -7
  2. package/build/index.js +16 -13
  3. package/build/lib/__tests__/gitnexus-bridge.unit.test.js +28 -1
  4. package/build/lib/__tests__/src8-guidance.unit.test.d.ts +1 -0
  5. package/build/lib/__tests__/src8-guidance.unit.test.js +62 -0
  6. package/build/lib/__tests__/task-defaults.unit.test.js +16 -2
  7. package/build/lib/code-review-input.d.ts +15 -0
  8. package/build/lib/code-review-input.js +47 -0
  9. package/build/lib/gitnexus-bridge.d.ts +1 -0
  10. package/build/lib/gitnexus-bridge.js +15 -6
  11. package/build/lib/src8-guidance.d.ts +178 -0
  12. package/build/lib/src8-guidance.js +633 -0
  13. package/build/lib/task-defaults.d.ts +2 -1
  14. package/build/lib/task-defaults.js +7 -4
  15. package/build/lib/tbp8-guidance.d.ts +4 -0
  16. package/build/lib/tbp8-guidance.js +4 -0
  17. package/build/schemas/code-analysis-tools.d.ts +49 -5
  18. package/build/schemas/code-analysis-tools.js +49 -5
  19. package/build/schemas/code-gen-tools.d.ts +9 -1
  20. package/build/schemas/code-gen-tools.js +9 -1
  21. package/build/schemas/index.d.ts +65 -9
  22. package/build/schemas/orchestration-tools.d.ts +7 -3
  23. package/build/schemas/orchestration-tools.js +7 -3
  24. package/build/schemas/output/core-tools.d.ts +238 -13
  25. package/build/schemas/output/core-tools.js +63 -13
  26. package/build/schemas/structured-output.d.ts +26 -8
  27. package/build/schemas/structured-output.js +17 -7
  28. package/build/tools/__tests__/code_review.unit.test.d.ts +1 -0
  29. package/build/tools/__tests__/code_review.unit.test.js +43 -0
  30. package/build/tools/__tests__/fix_bug.unit.test.js +54 -17
  31. package/build/tools/__tests__/gentest.unit.test.d.ts +1 -0
  32. package/build/tools/__tests__/gentest.unit.test.js +40 -0
  33. package/build/tools/__tests__/refactor.unit.test.d.ts +1 -0
  34. package/build/tools/__tests__/refactor.unit.test.js +40 -0
  35. package/build/tools/__tests__/start_bugfix.unit.test.js +31 -18
  36. package/build/tools/code_review.js +149 -164
  37. package/build/tools/fix_bug.d.ts +1 -9
  38. package/build/tools/fix_bug.js +137 -289
  39. package/build/tools/gentest.js +149 -186
  40. package/build/tools/refactor.js +132 -360
  41. package/build/tools/start_bugfix.js +258 -344
  42. package/package.json +1 -1
@@ -9,6 +9,7 @@ import { buildBugfixGraphContext } from "../lib/gitnexus-bridge.js";
9
9
  import { buildMemoryPlanStep, loadMemoryInjectionContext, renderMemoryGuideSection, buildOrchestrationHandles, } from "../lib/memory-orchestration.js";
10
10
  import { resolveWorkspaceRoot, isLikelyProjectNamedRelativePath, buildProjectRootRetryHint } from "../lib/workspace-root.js";
11
11
  import { layoutAbsPath, parseLayoutArgsFromRecord, resolveProjectContextLayout, } from "../lib/project-context-layout.js";
12
+ import { resolveAnalysisMode, mergeBugfixOrchestrationPlan } from "../lib/src8-guidance.js";
12
13
  import { buildCheckSpecPlanStep, renderSpecGatePromptSection, resolveBugfixSpecGate, } from "../lib/spec-gate.js";
13
14
  function decideTemplateProfile(description) {
14
15
  const text = description || '';
@@ -48,235 +49,196 @@ function resolveTemplateProfile(rawProfile, description) {
48
49
  warning: `模板档位 "${rawProfile}" 不支持,已回退为 ${fallback}`,
49
50
  };
50
51
  }
51
- const PROMPT_TEMPLATE_GUIDED = `# 🐛 Bug 修复编排指南(TBP 8 步真因分析)
52
-
53
- ## 🎯 目标
54
-
55
- 修复以下 Bug:
56
-
57
- **错误信息**:
58
- \`\`\`
59
- {error_message}
60
- \`\`\`
61
-
62
- {stack_trace_section}
63
-
64
- ---
65
-
66
- ## 📋 步骤 0: 项目上下文与取证基线(自动处理)
67
-
68
- **操作**:
69
- 1. 检查 \`docs/project-context.md\` 是否存在
70
- 2. 检查 \`docs/graph-insights/latest.md\` 和 \`docs/graph-insights/latest.json\` 是否存在
71
- 3. **如果任一缺失**:
72
- - 调用 \`init_project_context\` 工具
73
- - 等待生成完成
74
- 4. **读取** \`docs/project-context.md\` 与图谱文档
75
- 5. 了解项目的技术栈、架构、测试框架和调用链
76
- 6. 后续步骤参考此上下文
77
-
78
- ---
79
-
80
- ## 🔍 步骤 1: 先做 TBP 1-7,再决定修复
81
-
82
- **调用工具**: \`fix_bug\`
83
-
84
- **参数**:
85
- \`\`\`json
86
- {
87
- "error_message": "{error_message}",
88
- "stack_trace": "{stack_trace}"
89
- }
90
- \`\`\`
91
-
92
- **执行要点**:
93
- 1. 先定义现象,不能泛化
94
- 2. 复盘时间线,尽量带时间/步骤/状态
95
- 3. 明确排除错误方向,并说明为什么不是
96
- 4. 对比成功/失败样本,找分叉点
97
- 5. 定位问题边界(模型 / 状态机 / 工具 / 文件 / 环境)
98
- 6. 用因果句陈述真因:A + B 在条件 D 下导致 C
99
- 7. 闭合证据链后,才进入修复设计
100
- 8. 修复必须说明风险与验证方式
101
-
102
- **产出**: 修复后的代码
103
-
104
- ---
105
-
106
- ## 🧪 步骤 2: 生成回归测试
107
-
108
- **调用工具**: \`gentest\`
109
-
110
- **参数**:
111
- \`\`\`json
112
- {
113
- "code": "[修复后的代码]",
114
- "framework": "[根据项目上下文选择: jest/vitest/mocha]"
115
- }
116
- \`\`\`
117
-
118
- **执行要点**:
119
- 1. 为修复的代码生成测试
120
- 2. 包含 Bug 场景的测试用例
121
- 3. 包含边界情况测试
122
-
123
- **产出**: 测试代码
124
-
125
- {spec_gate_section}
126
-
127
- ---
128
-
129
- ## ✅ 完成检查
130
-
131
- - [ ] 项目上下文已读取
132
- - [ ] TBP-1~TBP-7 已闭合
133
- - [ ] 真因已写成因果句
134
- - [ ] 代码已修复
135
- - [ ] 测试已添加
136
- - [ ] 测试已通过
137
-
138
- ---
139
-
140
- ## 📝 输出汇总
141
-
142
- 完成后,向用户汇总:
143
-
144
- 1. **TBP 现象**: [精确定义的问题]
145
- 2. **TBP 时间线**: [关键事件顺序]
146
- 3. **已排除方向**: [不是哪些原因]
147
- 4. **问题边界**: [失控发生在哪一层]
148
- 5. **Bug 真因**: [根本原因]
149
- 6. **修复方案**: [修复说明]
150
- 7. **修改文件**: [文件列表]
151
- 8. **测试覆盖**: [测试情况]
152
-
153
- ---
154
-
155
- *编排工具: MCP Probe Kit - start_bugfix*
52
+ const PROMPT_TEMPLATE_GUIDED = `# 🐛 Bug 修复编排指南(SRC-8 真因分析)
53
+
54
+ ## 🎯 目标
55
+
56
+ 修复以下 Bug:
57
+
58
+ **错误信息**:
59
+ \`\`\`
60
+ {error_message}
61
+ \`\`\`
62
+
63
+ {stack_trace_section}
64
+
65
+ ---
66
+
67
+ ## 📋 步骤 0: 项目上下文与取证基线(自动处理)
68
+
69
+ **操作**:
70
+ 1. 检查 \`docs/project-context.md\` 是否存在
71
+ 2. 检查 \`docs/graph-insights/latest.md\` 和 \`docs/graph-insights/latest.json\` 是否存在
72
+ 3. **如果任一缺失**:
73
+ - 调用 \`init_project_context\` 工具
74
+ - 等待生成完成
75
+ 4. **读取** \`docs/project-context.md\` 与图谱文档
76
+ 5. 了解项目的技术栈、架构、测试框架和调用链
77
+ 6. 后续步骤参考此上下文
78
+
79
+ ---
80
+
81
+ ## 🔍 步骤 1~8: SRC-8(delegated plan)
82
+
83
+ **执行方式**: 严格按 \`structuredContent.metadata.plan.steps\` 顺序执行(与 \`start_feature\` 相同模式)。
84
+
85
+ **SRC 概要**:
86
+ 1. **src8-1** 明确差距 → \`BugAnalysis.tbp.phenomenon\`
87
+ 2. **src8-2** \`code_insight\` → 边界/时间线
88
+ 3. **src8-3** 验收契约 → \`BugAnalysis.testPlan\`
89
+ 4. **src8-4** 真因工作表 4a~4e → \`rootCauseAnalysis\`(闭合前禁止改代码)
90
+ 5. **src8-5** 制定对策 → \`BugAnalysis.fixPlan\`
91
+ 6. **src8-6** 贯彻修复 → 代码补丁
92
+ 7. **src8-7** \`gentest\` → 回归测试
93
+ 8. **src8-8** \`memorize_asset\` → 沉淀经验
94
+
95
+ **Bug 上下文**:
96
+ \`\`\`
97
+ {error_message}
98
+ \`\`\`
99
+
100
+ {stack_trace_section}
101
+
102
+ ---
103
+
104
+ ## ✅ 完成检查
105
+
106
+ - [ ] 项目上下文已读取
107
+ - [ ] SRC-8 Step 1~3 已完成
108
+ - [ ] **rootCauseWorksheet / rootCauseAnalysis 已闭合**
109
+ - [ ] 真因已写成因果句
110
+ - [ ] 代码已修复
111
+ - [ ] 测试已添加
112
+ - [ ] 测试已通过
113
+
114
+ ---
115
+
116
+ ## 📝 输出汇总
117
+
118
+ 完成后,向用户汇总:
119
+
120
+ 1. **SRC-1 差距**: [精确定义的问题]
121
+ 2. **SRC-2 时间线/边界**: [关键事件与归因层]
122
+ 3. **已排除方向**: [不是哪些原因]
123
+ 4. **问题边界**: [失控发生在哪一层]
124
+ 5. **Bug 真因**: [根本原因]
125
+ 6. **修复方案**: [修复说明]
126
+ 7. **修改文件**: [文件列表]
127
+ 8. **测试覆盖**: [测试情况]
128
+
129
+ ---
130
+
131
+ *编排工具: MCP Probe Kit - start_bugfix*
156
132
  `;
157
- const PROMPT_TEMPLATE_STRICT = `# 🐛 Bug 修复编排(严格 | TBP 8 步)
158
-
159
- ## 🎯 目标
160
- 修复 Bug:{error_message}
161
-
162
- {stack_trace_section}
163
-
164
- ---
165
-
166
- ## ✅ 执行计划(按顺序)
167
-
168
- 1) 检查 \`docs/project-context.md\` \`docs/graph-insights/latest.*\`,任一缺失则调用 \`init_project_context\`
169
- 2) 调用 \`fix_bug\`
170
- \`\`\`json
171
- {
172
- "error_message": "{error_message}",
173
- "stack_trace": "{stack_trace}",
174
- "analysis_mode": "{analysis_mode}"
175
- }
176
- \`\`\`
177
- 3) 调用 \`gentest\`
178
- \`\`\`json
179
- {
180
- "code": "[修复后的代码]",
181
- "framework": "[根据项目上下文选择: jest/vitest/mocha]"
182
- }
183
- \`\`\`
184
- {spec_gate_section}
185
-
186
- ---
187
-
188
- ## 输出汇总
189
- 1. TBP 现象
190
- 2. TBP 时间线
191
- 3. 已排除方向
192
- 4. 问题边界
193
- 5. Bug 真因
194
- 6. 修复方案
195
- 7. 修改文件
196
- 8. 测试覆盖
197
-
198
- ---
199
-
200
- *编排工具: MCP Probe Kit - start_bugfix*
133
+ const PROMPT_TEMPLATE_STRICT = `# 🐛 Bug 修复编排(严格 | SRC-8
134
+
135
+ ## 🎯 目标
136
+ 修复 Bug:{error_message}
137
+
138
+ {stack_trace_section}
139
+
140
+ ---
141
+
142
+ ## ✅ 执行计划
143
+
144
+ 严格按 \`structuredContent.metadata.plan.steps\` 顺序执行(context → src8-1 → … → src8-8)。
145
+
146
+ **要点**: src8-4 闭合 \`rootCauseWorksheet\` 前禁止改代码;src8-6 前满足复现门禁。
147
+
148
+ {spec_gate_section}
149
+
150
+ ---
151
+
152
+ ## ✅ 输出汇总
153
+ 1. SRC-1 差距
154
+ 2. SRC-2 时间线/边界
155
+ 3. 已排除方向
156
+ 4. 问题边界
157
+ 5. Bug 真因
158
+ 6. 修复方案
159
+ 7. 修改文件
160
+ 8. 测试覆盖
161
+
162
+ ---
163
+
164
+ *编排工具: MCP Probe Kit - start_bugfix*
201
165
  `;
202
- const LOOP_PROMPT_TEMPLATE_GUIDED = `# 🧭 Bug 需求澄清与补全(TBP RCA Loop)
203
-
204
- 本模式用于**生产级稳健补全**:在不改变用户意图的前提下补齐 TBP 8 步真因分析所需证据。
205
-
206
- ## 🎯 目标
207
- 修复 Bug:{error_message}
208
-
209
- ## ✅ 规则
210
- 1. **不覆盖用户原始描述**
211
- 2. **补全内容必须标注来源**(User / Derived / Assumption)
212
- 3. **假设必须进入待确认列表**
213
- 4. **每轮问题 ≤ {question_budget},假设 ≤ {assumption_cap}**
214
-
215
- ---
216
-
217
- ## 🔁 执行步骤(每轮)
218
-
219
- ### 1) 生成待确认问题
220
- 使用 \`ask_user\` 提问,问题来源于 TBP 清单(现象/时间线/对比样本/边界/验证)。
221
-
222
- **调用示例**:
223
- \`\`\`json
224
- {
225
- "questions": [
226
- { "question": "复现步骤是什么?", "context": "复现步骤", "required": true },
227
- { "question": "期望行为是什么?", "context": "期望行为", "required": true }
228
- ]
229
- }
230
- \`\`\`
231
-
232
- ### 2) 更新结构化输出
233
- 将回答补入 \`requirements\`,并标注来源:
234
- - User:用户明确回答
235
- - Derived:合理推导
236
- - Assumption:无法确认但补全(需确认)
237
-
238
- ### 3) 自检与结束
239
- 若 \`openQuestions\` 为空且无高风险假设,则结束 loop,进入 TBP-6/7/8 修复流程。
240
-
241
- ---
242
-
243
- ## ✅ 结束后继续
244
- 当满足结束条件时,执行:
245
- 1. 调用 \`fix_bug\` 完成 TBP 8 步分析与修复方案
246
- 2. 调用 \`gentest\` 生成回归测试
247
-
248
- ---
249
-
250
- *编排工具: MCP Probe Kit - start_bugfix (requirements loop)*
166
+ const LOOP_PROMPT_TEMPLATE_GUIDED = `# 🧭 Bug 需求澄清与补全(SRC-8 RCA Loop)
167
+
168
+ 本模式用于**生产级稳健补全**:在不改变用户意图的前提下补齐 SRC-8 真因分析(尤其 Step 4 工作表)所需证据。
169
+
170
+ ## 🎯 目标
171
+ 修复 Bug:{error_message}
172
+
173
+ ## ✅ 规则
174
+ 1. **不覆盖用户原始描述**
175
+ 2. **补全内容必须标注来源**(User / Derived / Assumption)
176
+ 3. **假设必须进入待确认列表**
177
+ 4. **每轮问题 ≤ {question_budget},假设 ≤ {assumption_cap}**
178
+
179
+ ---
180
+
181
+ ## 🔁 执行步骤(每轮)
182
+
183
+ ### 1) 生成待确认问题
184
+ 使用 \`ask_user\` 提问,问题来源于 SRC-8 清单(差距/边界/验收契约/对比样本/真因工作表)。
185
+
186
+ **调用示例**:
187
+ \`\`\`json
188
+ {
189
+ "questions": [
190
+ { "question": "复现步骤是什么?", "context": "复现步骤", "required": true },
191
+ { "question": "期望行为是什么?", "context": "期望行为", "required": true }
192
+ ]
193
+ }
194
+ \`\`\`
195
+
196
+ ### 2) 更新结构化输出
197
+ 将回答补入 \`requirements\`,并标注来源:
198
+ - User:用户明确回答
199
+ - Derived:合理推导
200
+ - Assumption:无法确认但补全(需确认)
201
+
202
+ ### 3) 自检与结束
203
+ 若 \`openQuestions\` 为空且无高风险假设,则结束 loop,进入 SRC-8 Step 5~8(对策→修复→评价→巩固)。
204
+
205
+ ---
206
+
207
+ ## ✅ 结束后继续
208
+ 当满足结束条件时,严格按 \`structuredContent.metadata.plan.steps\` 中 src8-1~8 执行(禁止跳步)。
209
+
210
+ ---
211
+
212
+ *编排工具: MCP Probe Kit - start_bugfix (requirements loop)*
251
213
  `;
252
- const LOOP_PROMPT_TEMPLATE_STRICT = `# 🧭 Bug 需求澄清与补全(TBP RCA Loop | 严格)
253
-
254
- 本模式用于稳健补全关键信息,不改变用户意图。
255
-
256
- ## 🎯 目标
257
- 修复 Bug:{error_message}
258
-
259
- ## ✅ 规则
260
- 1. 不覆盖用户原始描述
261
- 2. 补全内容标注来源(User / Derived / Assumption)
262
- 3. 假设进入待确认列表
263
- 4. 每轮问题 ≤ {question_budget},假设 ≤ {assumption_cap}
264
-
265
- ---
266
-
267
- ## 🔁 执行步骤(每轮)
268
- 1) 使用 \`ask_user\` 提问补全关键信息
269
- 2) 更新结构化输出并标注来源
270
- 3) 若 \`openQuestions\` 为空且无高风险假设则结束
271
-
272
- ---
273
-
274
- ## ✅ 结束后继续
275
- 当满足结束条件时,调用 \`fix_bug\` \`gentest\`
276
-
277
- ---
278
-
279
- *编排工具: MCP Probe Kit - start_bugfix (requirements loop)*
214
+ const LOOP_PROMPT_TEMPLATE_STRICT = `# 🧭 Bug 需求澄清与补全(SRC-8 RCA Loop | 严格)
215
+
216
+ 本模式用于稳健补全关键信息,不改变用户意图。
217
+
218
+ ## 🎯 目标
219
+ 修复 Bug:{error_message}
220
+
221
+ ## ✅ 规则
222
+ 1. 不覆盖用户原始描述
223
+ 2. 补全内容标注来源(User / Derived / Assumption)
224
+ 3. 假设进入待确认列表
225
+ 4. 每轮问题 ≤ {question_budget},假设 ≤ {assumption_cap}
226
+
227
+ ---
228
+
229
+ ## 🔁 执行步骤(每轮)
230
+ 1) 使用 \`ask_user\` 提问补全关键信息
231
+ 2) 更新结构化输出并标注来源
232
+ 3) 若 \`openQuestions\` 为空且无高风险假设则结束
233
+
234
+ ---
235
+
236
+ ## ✅ 结束后继续
237
+ 当满足结束条件时,按 \`metadata.plan\` 执行 src8-1~8。
238
+
239
+ ---
240
+
241
+ *编排工具: MCP Probe Kit - start_bugfix (requirements loop)*
280
242
  `;
281
243
  function buildBugfixQuestions(questionBudget) {
282
244
  const base = [
@@ -299,7 +261,7 @@ export async function startBugfix(args, context) {
299
261
  error_message: "",
300
262
  stack_trace: "",
301
263
  code_context: "",
302
- analysis_mode: "tbp8",
264
+ analysis_mode: "src8",
303
265
  template_profile: "auto",
304
266
  requirements_mode: "steady",
305
267
  loop_max_rounds: 2,
@@ -308,7 +270,7 @@ export async function startBugfix(args, context) {
308
270
  },
309
271
  primaryField: "error_message", // 纯文本输入默认映射到 error_message 字段
310
272
  fieldAliases: {
311
- error_message: ["error", "err", "message", "错误", "错误信息"],
273
+ error_message: ["error", "err", "message", "错误", "错误信息", "description", "desc", "summary", "问题", "bug", "issue"],
312
274
  stack_trace: ["stack", "trace", "堆栈", "调用栈"],
313
275
  code_context: ["code_context", "code", "context", "相关代码", "代码上下文"],
314
276
  project_root: ["projectRoot", "project_path", "projectPath", "root", "project_root", "项目路径", "项目根目录"],
@@ -322,7 +284,7 @@ export async function startBugfix(args, context) {
322
284
  loop_assumption_cap: ["assumption_cap", "假设上限"],
323
285
  },
324
286
  });
325
- const errorMessage = getString(parsedArgs.error_message);
287
+ const errorMessage = getString(parsedArgs.error_message) || getString(parsedArgs.description);
326
288
  const stackTrace = getString(parsedArgs.stack_trace);
327
289
  const codeContext = getString(parsedArgs.code_context);
328
290
  const projectRoot = getString(parsedArgs.project_root);
@@ -342,9 +304,7 @@ export async function startBugfix(args, context) {
342
304
  },
343
305
  };
344
306
  }
345
- const analysisMode = ((getString(parsedArgs.analysis_mode) || "tbp8").toLowerCase() === "tbp8"
346
- ? "tbp8"
347
- : "tbp8");
307
+ const analysisMode = resolveAnalysisMode(getString(parsedArgs.analysis_mode));
348
308
  const rawProfile = getString(parsedArgs.template_profile);
349
309
  const requirementsMode = getString(parsedArgs.requirements_mode) || "steady";
350
310
  const maxRounds = getNumber(parsedArgs.loop_max_rounds, 2);
@@ -430,22 +390,21 @@ export async function startBugfix(args, context) {
430
390
  ]
431
391
  .filter(Boolean)
432
392
  .join("\n\n");
433
- const graphGuideSection = `
434
-
435
- ## 🧠 代码图谱上下文
436
- - 基线入口: ${graphDocs.latestMarkdownPath}
437
- - 基线结构化副本: ${graphDocs.latestJsonPath}
438
- - 基线状态: ${graphDocsMissing ? "缺失(需要补初始化)" : "可用"}
439
- - 任务级收敛: ${graphContext.available ? "可用" : "降级"}
440
- - 任务级摘要: ${graphContext.summary}
393
+ const graphGuideSection = `
394
+
395
+ ## 🧠 代码图谱上下文
396
+ - 基线入口: ${graphDocs.latestMarkdownPath}
397
+ - 基线结构化副本: ${graphDocs.latestJsonPath}
398
+ - 基线状态: ${graphDocsMissing ? "缺失(需要补初始化)" : "可用"}
399
+ - 任务级收敛: ${graphContext.available ? "可用" : "降级"}
400
+ - 任务级摘要: ${graphContext.summary}
441
401
  ${graphContext.highlights.length > 0
442
402
  ? `- 任务级线索:\n${graphContext.highlights.slice(0, 3).map((item) => ` - ${item}`).join("\n")}`
443
- : "- 任务级线索: 无"}
444
- - 使用方式: 先读取基线图谱,再用本次任务图谱做 TBP-4 / TBP-5 / TBP-6 的边界与真因收敛
403
+ : "- 任务级线索: 无"}
404
+ - 使用方式: 先读取基线图谱,再用本次任务图谱做 SRC-2/4 的边界与真因收敛
445
405
  `;
446
406
  const memoryContext = await loadMemoryInjectionContext([errorMessage, stackTrace, codeContext].filter(Boolean).join("\n"), "bugfix");
447
407
  const memoryGuideSection = renderMemoryGuideSection(memoryContext);
448
- // 记忆优先:先消化历史同类 Bug 的根因/修复(坑),再做 TBP 真因分析
449
408
  const memoryRecallStep = memoryContext.enabled
450
409
  ? [{
451
410
  id: 'recall-memory',
@@ -453,9 +412,45 @@ ${graphContext.highlights.length > 0
453
412
  when: '开干前(下方「历史经验与坑」已自动注入相似历史修复;需要更多同类案例时再调)',
454
413
  args: { query: errorMessage, limit: 5 },
455
414
  outputs: [],
456
- note: '先看历史同类 Bug 的根因与已验证修复,优先复用其修复路径并规避同类坑;据此收敛 TBP-4/5/6 的真因方向',
415
+ note: '先看历史同类 Bug 的根因与已验证修复,优先复用其修复路径并规避同类坑;据此收敛 SRC-4 真因方向',
457
416
  }]
458
417
  : [];
418
+ const buildOrchestrationPlan = (options) => {
419
+ const contextStep = {
420
+ id: 'context',
421
+ tool: 'init_project_context',
422
+ when: `缺少 ${layout.indexPath} 或 ${graphDocs.latestMarkdownPath} / ${graphDocs.latestJsonPath}`,
423
+ args: {
424
+ docs_dir: layout.contextRoot,
425
+ ...(projectRoot ? { project_root: projectRoot } : {}),
426
+ },
427
+ outputs: [layout.indexPath, graphDocs.latestMarkdownPath, graphDocs.latestJsonPath],
428
+ note: `兼容老项目:如果旧项目没有 graph-insights/latest.*,先补齐图谱初始化再进入 bug 收敛`,
429
+ };
430
+ const src8Plan = mergeBugfixOrchestrationPlan({
431
+ src8Input: {
432
+ error_message: errorMessage,
433
+ stack_trace: stackTrace || undefined,
434
+ analysis_mode: analysisMode,
435
+ code_context: graphCodeContext || undefined,
436
+ project_root: resolvedProjectRoot,
437
+ includeMemorize: !memoryContext.enabled,
438
+ },
439
+ preambleSteps: [...memoryRecallStep, contextStep, ...(options?.loopSteps ?? [])],
440
+ deferMemorize: memoryContext.enabled,
441
+ appendSteps: [
442
+ ...(specGate ? [buildCheckSpecPlanStep(specGate.featureName, specGate.docsDir)] : []),
443
+ ...(memoryContext.enabled ? [buildMemoryPlanStep('bugfix')] : []),
444
+ ],
445
+ });
446
+ if (options?.src8When) {
447
+ const firstSrc8 = src8Plan.steps.find((step) => step.id.startsWith('src8-'));
448
+ if (firstSrc8) {
449
+ firstSrc8.when = options.src8When;
450
+ }
451
+ }
452
+ return src8Plan;
453
+ };
459
454
  if (requirementsMode === "loop") {
460
455
  throwIfAborted(context?.signal, "start_bugfix(loop) 已取消");
461
456
  await reportToolProgress(context, 70, "start_bugfix: 生成 loop 计划");
@@ -478,21 +473,9 @@ ${graphContext.highlights.length > 0
478
473
  const assumptions = [];
479
474
  const missingFields = openQuestions.map((q) => q.context || q.question);
480
475
  const stopReady = openQuestions.length === 0 && assumptions.length === 0;
481
- const plan = {
482
- mode: 'delegated',
483
- steps: [
484
- ...memoryRecallStep,
485
- {
486
- id: 'context',
487
- tool: 'init_project_context',
488
- when: `缺少 ${layout.indexPath} 或 ${graphDocs.latestMarkdownPath} / ${graphDocs.latestJsonPath}`,
489
- args: {
490
- docs_dir: 'docs',
491
- ...(projectRoot ? { project_root: projectRoot } : {}),
492
- },
493
- outputs: [layout.indexPath, graphDocs.latestMarkdownPath, graphDocs.latestJsonPath],
494
- note: `兼容老项目:如果旧项目没有 graph-insights/latest.*,先补齐图谱初始化再进入 bug 收敛`,
495
- },
476
+ const plan = buildOrchestrationPlan({
477
+ src8When: 'stopConditions.ready=true',
478
+ loopSteps: [
496
479
  {
497
480
  id: 'loop-1',
498
481
  tool: 'ask_user',
@@ -500,41 +483,16 @@ ${graphContext.highlights.length > 0
500
483
  outputs: [],
501
484
  },
502
485
  ...(maxRounds > 1
503
- ? [
504
- {
486
+ ? [{
505
487
  id: 'loop-2',
506
488
  tool: 'ask_user',
507
489
  when: '仍存在 openQuestions 或 assumptions',
508
490
  args: { questions: '[根据上一轮补全结果生成问题]' },
509
491
  outputs: [],
510
- },
511
- ]
492
+ }]
512
493
  : []),
513
- {
514
- id: 'fix',
515
- tool: 'fix_bug',
516
- when: 'stopConditions.ready=true',
517
- args: {
518
- error_message: errorMessage,
519
- ...(stackTrace ? { stack_trace: stackTrace } : {}),
520
- analysis_mode: analysisMode,
521
- ...(graphCodeContext ? { code_context: graphCodeContext } : {}),
522
- },
523
- outputs: [],
524
- },
525
- {
526
- id: 'test',
527
- tool: 'gentest',
528
- when: 'stopConditions.ready=true',
529
- args: {
530
- code: '[修复后的代码]',
531
- framework: '[根据项目上下文选择: jest/vitest/mocha]',
532
- },
533
- outputs: [],
534
- },
535
- ...(memoryContext.enabled ? [buildMemoryPlanStep('bugfix')] : []),
536
494
  ],
537
- };
495
+ });
538
496
  const header = renderOrchestrationHeader({
539
497
  tool: 'start_bugfix',
540
498
  goal: `修复 Bug:${errorMessage}`,
@@ -603,8 +561,8 @@ ${graphContext.highlights.length > 0
603
561
  tool: 'start_bugfix',
604
562
  goal: `修复 Bug:${errorMessage}`,
605
563
  tasks: [
606
- '按 delegated plan 顺序调用工具',
607
- '完成修复并生成回归测试',
564
+ '按 delegated plan 顺序执行 metadata.plan.steps(src8-1~8)',
565
+ '完成修复、回归测试与记忆沉淀',
608
566
  ],
609
567
  notes: [
610
568
  ...headerNotes,
@@ -621,45 +579,7 @@ ${graphContext.highlights.length > 0
621
579
  .replace(/{stack_trace_section}/g, stackTraceSection)
622
580
  .replace(/{spec_gate_section}/g, specGateSection);
623
581
  const guide = header + memoryGuideSection + renderedPrompt + graphGuideSection;
624
- const plan = {
625
- mode: 'delegated',
626
- steps: [
627
- ...memoryRecallStep,
628
- {
629
- id: 'context',
630
- tool: 'init_project_context',
631
- when: `缺少 ${layout.indexPath} 或 ${graphDocs.latestMarkdownPath} / ${graphDocs.latestJsonPath}`,
632
- args: {
633
- docs_dir: layout.contextRoot,
634
- ...(projectRoot ? { project_root: projectRoot } : {}),
635
- },
636
- outputs: [layout.indexPath, graphDocs.latestMarkdownPath, graphDocs.latestJsonPath],
637
- note: `兼容老项目:如果旧项目没有 graph-insights/latest.*,先补齐图谱初始化再进入 bug 收敛`,
638
- },
639
- {
640
- id: 'fix',
641
- tool: 'fix_bug',
642
- args: {
643
- error_message: errorMessage,
644
- ...(stackTrace ? { stack_trace: stackTrace } : {}),
645
- analysis_mode: analysisMode,
646
- ...(graphCodeContext ? { code_context: graphCodeContext } : {}),
647
- },
648
- outputs: [],
649
- },
650
- {
651
- id: 'test',
652
- tool: 'gentest',
653
- args: {
654
- code: '[修复后的代码]',
655
- framework: '[根据项目上下文选择: jest/vitest/mocha]',
656
- },
657
- outputs: [],
658
- },
659
- ...(specGate ? [buildCheckSpecPlanStep(specGate.featureName, specGate.docsDir)] : []),
660
- ...(memoryContext.enabled ? [buildMemoryPlanStep('bugfix')] : []),
661
- ],
662
- };
582
+ const plan = buildOrchestrationPlan();
663
583
  // 创建结构化的 Bug 修复报告
664
584
  const bugfixReport = {
665
585
  summary: `Bug 修复工作流:${errorMessage.substring(0, 50)}${errorMessage.length > 50 ? '...' : ''}`,
@@ -672,14 +592,9 @@ ${graphContext.highlights.length > 0
672
592
  description: `检查 ${layout.indexPath} 与 graph-insights/latest.* 是否存在,缺失则调用 init_project_context`,
673
593
  },
674
594
  {
675
- name: 'Bug 分析与修复',
676
- status: 'pending',
677
- description: '调用 fix_bug 工具进行问题定位和修复',
678
- },
679
- {
680
- name: '生成回归测试',
595
+ name: 'SRC-8 真因分析与修复',
681
596
  status: 'pending',
682
- description: '调用 gentest 工具生成测试用例',
597
+ description: ' metadata.plan 执行 src8-1~8(src8-4 闭合前禁止改代码)',
683
598
  },
684
599
  ...(specGate
685
600
  ? [{
@@ -694,18 +609,17 @@ ${graphContext.highlights.length > 0
694
609
  '检查并读取项目上下文文档',
695
610
  `如果缺少 ${graphDocs.latestMarkdownPath} / ${graphDocs.latestJsonPath},先调用 init_project_context 补齐图谱初始化`,
696
611
  `优先读取 ${graphDocs.latestMarkdownPath} 获取调用链、依赖和影响面摘要`,
697
- '结合本次任务图谱线索收敛问题边界,避免扩大改动面',
698
- '按 TBP-1~TBP-7 完成真因分析',
699
- '调用 fix_bug 工具分析问题并形成因果句真因',
700
- '调用 gentest 工具生成回归测试',
701
- '运行测试验证修复',
612
+ '严格按 metadata.plan 执行 src8-1~8,禁止从 src8-4 跳起',
613
+ 'src8-4 完成 rootCauseWorksheet 与 rootCauseAnalysis 后再改代码',
614
+ 'src8-7 gentest 生成回归测试并验证',
702
615
  ...(specGate
703
616
  ? [`修复后调用 check_spec 校验 ${specGate.specDir}/,未通过先补规格再重跑`]
704
617
  : []),
618
+ ...(memoryContext.enabled ? ['src8-8 或 memorize-bugfix 沉淀 bugfix 记忆'] : []),
705
619
  ],
706
- rootCause: '待分析(需要调用 fix_bug 工具)',
707
- fixPlan: '待制定(需要调用 fix_bug 工具)',
708
- testPlan: '待生成(需要调用 gentest 工具)',
620
+ rootCause: '待分析(src8-4 rootCauseAnalysis)',
621
+ fixPlan: '待制定(src8-5)',
622
+ testPlan: '待定义(src8-3 验收契约 + src8-7 gentest',
709
623
  affectedFiles: [],
710
624
  tbp: {
711
625
  phenomenon: `待确认:${errorMessage}`,
@@ -725,7 +639,7 @@ ${graphContext.highlights.length > 0
725
639
  repair: [
726
640
  {
727
641
  layer: 'analysis',
728
- action: '先完成 TBP 1-7 取证与真因闭合,再进入修复',
642
+ action: '先按 metadata.plan 完成 src8-1~4 真因工作表闭合,再进入修复',
729
643
  risk: '若直接改代码,容易补症状而非修真因',
730
644
  verification: '检查真因是否能解释全部关键现象并排除竞争假设',
731
645
  },