mcp-probe-kit 3.6.10 → 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.
- package/README.md +13 -7
- package/build/index.js +16 -13
- package/build/lib/__tests__/src8-guidance.unit.test.d.ts +1 -0
- package/build/lib/__tests__/src8-guidance.unit.test.js +62 -0
- package/build/lib/code-review-input.d.ts +15 -0
- package/build/lib/code-review-input.js +47 -0
- package/build/lib/src8-guidance.d.ts +178 -0
- package/build/lib/src8-guidance.js +633 -0
- package/build/lib/tbp8-guidance.d.ts +4 -0
- package/build/lib/tbp8-guidance.js +4 -0
- package/build/schemas/code-analysis-tools.d.ts +49 -5
- package/build/schemas/code-analysis-tools.js +49 -5
- package/build/schemas/code-gen-tools.d.ts +9 -1
- package/build/schemas/code-gen-tools.js +9 -1
- package/build/schemas/index.d.ts +65 -9
- package/build/schemas/orchestration-tools.d.ts +7 -3
- package/build/schemas/orchestration-tools.js +7 -3
- package/build/schemas/output/core-tools.d.ts +238 -13
- package/build/schemas/output/core-tools.js +63 -13
- package/build/schemas/structured-output.d.ts +26 -8
- package/build/schemas/structured-output.js +17 -7
- package/build/tools/__tests__/code_review.unit.test.d.ts +1 -0
- package/build/tools/__tests__/code_review.unit.test.js +43 -0
- package/build/tools/__tests__/fix_bug.unit.test.js +54 -17
- package/build/tools/__tests__/gentest.unit.test.d.ts +1 -0
- package/build/tools/__tests__/gentest.unit.test.js +40 -0
- package/build/tools/__tests__/refactor.unit.test.d.ts +1 -0
- package/build/tools/__tests__/refactor.unit.test.js +40 -0
- package/build/tools/__tests__/start_bugfix.unit.test.js +31 -18
- package/build/tools/code_review.js +149 -164
- package/build/tools/fix_bug.d.ts +1 -9
- package/build/tools/fix_bug.js +137 -289
- package/build/tools/gentest.js +149 -186
- package/build/tools/refactor.js +132 -360
- package/build/tools/start_bugfix.js +258 -344
- package/package.json +1 -1
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SRC-8(Software Root-Cause 8-step)
|
|
3
|
+
*
|
|
4
|
+
* 面向软件与 Agent 的真因分析协议,受丰田 TBP(Toyota Business Practice)八步法与 PDCA 启发,
|
|
5
|
+
* 但使用代码世界的语言(复现、分层、贡献因子、测试契约、记忆沉淀)。
|
|
6
|
+
*
|
|
7
|
+
* @see docs/src8-methodology.md
|
|
8
|
+
* @see docs/src8-methodology.zh-CN.md
|
|
9
|
+
*/
|
|
10
|
+
export const SRC8_METHODOLOGY = "src8";
|
|
11
|
+
/** @deprecated 使用 src8;保留兼容旧调用方 */
|
|
12
|
+
export const TBP8_ALIAS = "tbp8";
|
|
13
|
+
export const ATTRIBUTION_LAYERS = [
|
|
14
|
+
{ id: "code", label: "代码", hint: "逻辑/类型/边界/空值" },
|
|
15
|
+
{ id: "runtime", label: "运行时", hint: "并发/超时/内存/进程" },
|
|
16
|
+
{ id: "data_contract", label: "数据契约", hint: "API/Schema/序列化/缓存" },
|
|
17
|
+
{ id: "integration", label: "集成", hint: "第三方/网关/MCP/外部服务" },
|
|
18
|
+
{ id: "agent_behavior", label: "Agent 行为", hint: "工具未调/参数空/guidance 当结论/跳步" },
|
|
19
|
+
{ id: "environment", label: "环境", hint: "配置/权限/路径/cwd" },
|
|
20
|
+
];
|
|
21
|
+
export const SRC8_STEPS = [
|
|
22
|
+
{
|
|
23
|
+
step: 1,
|
|
24
|
+
id: "clarify_gap",
|
|
25
|
+
title: "明确差距",
|
|
26
|
+
pdca: "plan",
|
|
27
|
+
inspiredByTbpStep: 1,
|
|
28
|
+
question: "真正目的是什么?理想行为 vs 实际行为?差距如何可观察、可量化?",
|
|
29
|
+
techniques: [
|
|
30
|
+
"理想 / 实际 / 差距(gap)三要素",
|
|
31
|
+
"区分:慢 / 停滞 / 失败 / 回归 / 未生效",
|
|
32
|
+
"纳入期望行为与实际行为",
|
|
33
|
+
],
|
|
34
|
+
antiPatterns: ["坏了", "卡了", "有问题", "只有情绪没有差距"],
|
|
35
|
+
schemaFields: ["tbp.phenomenon"],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
step: 2,
|
|
39
|
+
id: "narrow_boundary",
|
|
40
|
+
title: "收敛边界",
|
|
41
|
+
pdca: "plan",
|
|
42
|
+
inspiredByTbpStep: 2,
|
|
43
|
+
question: "问题落在哪条链、哪一层?优先调查点(priority point)在哪?",
|
|
44
|
+
techniques: [
|
|
45
|
+
"时间线:何时开始、经过、终止",
|
|
46
|
+
"现码现志:日志、堆栈、复现、读源码、code_insight 图谱",
|
|
47
|
+
"归因层枚举:code / runtime / data_contract / integration / agent_behavior / environment",
|
|
48
|
+
],
|
|
49
|
+
antiPatterns: ["大问题不分解", "边界模糊", "跨层甩锅"],
|
|
50
|
+
schemaFields: ["tbp.timeline", "tbp.boundary"],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
step: 3,
|
|
54
|
+
id: "acceptance_contract",
|
|
55
|
+
title: "验收契约",
|
|
56
|
+
pdca: "plan",
|
|
57
|
+
inspiredByTbpStep: 3,
|
|
58
|
+
question: "什么叫「修好了」?验收标准是否 SMART?",
|
|
59
|
+
techniques: [
|
|
60
|
+
"优先:failing test → fix → green",
|
|
61
|
+
"或:可重复 repro 命令 / 明确手动步骤",
|
|
62
|
+
"先写验收标准,再进入真因与对策",
|
|
63
|
+
],
|
|
64
|
+
antiPatterns: ["修好就行", "无验收标准", "改善质量"],
|
|
65
|
+
schemaFields: ["testPlan"],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
step: 4,
|
|
69
|
+
id: "root_cause",
|
|
70
|
+
title: "把握真因",
|
|
71
|
+
pdca: "plan",
|
|
72
|
+
inspiredByTbpStep: 4,
|
|
73
|
+
question: "基于事实(非假设),完成真因工作表:假设→排除→对比→5 Why→因果陈述",
|
|
74
|
+
techniques: [
|
|
75
|
+
"4a 假设清单(2~5 条,含 agent_behavior)",
|
|
76
|
+
"4b 排除矩阵(证据/反证/结论)",
|
|
77
|
+
"4c 对比分叉(成功 vs 失败;无样本写 evidenceGaps)",
|
|
78
|
+
"4d 5 Why 链(≥3 层,每层绑定观察事实)",
|
|
79
|
+
"4e 真因陈述:simple=因果句 | complex=主因+contributingFactors",
|
|
80
|
+
],
|
|
81
|
+
antiPatterns: ["超时了", "SDK 有 bug", "从 Step 4 跳起", "无对比仍断言", "脑暴代替观察"],
|
|
82
|
+
schemaFields: ["rootCauseAnalysis", "tbp.ruledOut", "tbp.commonPattern", "tbp.rootCauseStatement", "rootCause"],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
step: 5,
|
|
86
|
+
id: "countermeasures",
|
|
87
|
+
title: "制定对策",
|
|
88
|
+
pdca: "plan",
|
|
89
|
+
inspiredByTbpStep: 5,
|
|
90
|
+
question: "最小 patch 能否消除真因?有效性、可行性、副作用?",
|
|
91
|
+
techniques: [
|
|
92
|
+
"countermeasure 针对真因,非症状兜底",
|
|
93
|
+
"评估:有效性 / 可行性 / 回归风险",
|
|
94
|
+
"code judo:最少文件、最少概念",
|
|
95
|
+
],
|
|
96
|
+
antiPatterns: ["加巡检掩盖根因", "未评估就动手", "夹带重构"],
|
|
97
|
+
schemaFields: ["fixPlan", "tbp.repair"],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
step: 6,
|
|
101
|
+
id: "implement",
|
|
102
|
+
title: "贯彻修复",
|
|
103
|
+
pdca: "do",
|
|
104
|
+
inspiredByTbpStep: 6,
|
|
105
|
+
question: "复现门禁通过后,改动是否仅限 Bug 范围?",
|
|
106
|
+
techniques: [
|
|
107
|
+
"Step 1~5 + 真因工作表闭合后才可改代码",
|
|
108
|
+
"一次只验证一个假设",
|
|
109
|
+
"三次修复仍失败 → 回 Step 2/4 换假设",
|
|
110
|
+
],
|
|
111
|
+
antiPatterns: ["无复现就改", "连改多处无法归因", "三次失败后盲试"],
|
|
112
|
+
schemaFields: ["fixPlan.steps", "affectedFiles"],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
step: 7,
|
|
116
|
+
id: "evaluate",
|
|
117
|
+
title: "评价双轨",
|
|
118
|
+
pdca: "check",
|
|
119
|
+
inspiredByTbpStep: 7,
|
|
120
|
+
question: "验收契约达成了吗?过程哪步证据不足?",
|
|
121
|
+
techniques: [
|
|
122
|
+
"结果轨:对照 Step 3 验收契约",
|
|
123
|
+
"过程轨:哪步应更早做、哪条假设应更早排除",
|
|
124
|
+
"重跑 repro + 回归测试",
|
|
125
|
+
],
|
|
126
|
+
antiPatterns: ["未验证就声称修好", "只评结果不评过程"],
|
|
127
|
+
schemaFields: ["summary", "testPlan"],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
step: 8,
|
|
131
|
+
id: "standardize",
|
|
132
|
+
title: "巩固传播",
|
|
133
|
+
pdca: "act",
|
|
134
|
+
inspiredByTbpStep: 8,
|
|
135
|
+
question: "如何防复发?经验如何跨项目复用(yokoten)?",
|
|
136
|
+
techniques: [
|
|
137
|
+
"补回归测试锁定边界",
|
|
138
|
+
"memorize_asset type=bugfix:【现象】【根因】【修复】【验证】",
|
|
139
|
+
"同类路径/模块排查",
|
|
140
|
+
],
|
|
141
|
+
antiPatterns: ["修完即走", "不沉淀记忆", "不补测试"],
|
|
142
|
+
schemaFields: ["preventionMeasures"],
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
export const ROOT_CAUSE_WORKSHEET_GATES = {
|
|
146
|
+
minHypotheses: 2,
|
|
147
|
+
minRuledOutWithEvidence: 2,
|
|
148
|
+
minWhyLevels: 3,
|
|
149
|
+
requireEvidenceGapsIfNoComparison: true,
|
|
150
|
+
blockCountermeasuresIfConfidenceLow: true,
|
|
151
|
+
symptomOnlyPatterns: [/超时/, /SDK.*bug/i, /网络慢/, /返回慢/],
|
|
152
|
+
};
|
|
153
|
+
export function buildSrc8Checklist() {
|
|
154
|
+
return SRC8_STEPS.map((item) => ({
|
|
155
|
+
...item,
|
|
156
|
+
status: "agent_must_complete",
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
export function buildRootCauseWorksheetSubsteps() {
|
|
160
|
+
return [
|
|
161
|
+
{
|
|
162
|
+
id: "4a",
|
|
163
|
+
title: "假设清单",
|
|
164
|
+
status: "agent_must_complete",
|
|
165
|
+
description: "列出 2~5 个可能原因;至少 1 条覆盖 agent_behavior 或 attributionLayer",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "4b",
|
|
169
|
+
title: "排除矩阵",
|
|
170
|
+
status: "agent_must_complete",
|
|
171
|
+
description: "每条假设:支持证据、反证、结论(ruled_out | pending | confirmed)",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
id: "4c",
|
|
175
|
+
title: "对比分叉",
|
|
176
|
+
status: "agent_must_complete",
|
|
177
|
+
description: "成功 vs 失败从哪一步分叉;无 success_sample 则写 evidenceGaps",
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: "4d",
|
|
181
|
+
title: "5 Why 链",
|
|
182
|
+
status: "agent_must_complete",
|
|
183
|
+
description: "≥3 层;每层 observation(事实)→ why → because",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: "4e",
|
|
187
|
+
title: "真因陈述",
|
|
188
|
+
status: "agent_must_complete",
|
|
189
|
+
description: "simple:一条因果句 A+B 在 D 下→C;complex:primaryCause + contributingFactors[]",
|
|
190
|
+
},
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
export function buildRootCauseWorksheet(input) {
|
|
194
|
+
return {
|
|
195
|
+
step: 4,
|
|
196
|
+
title: "把握真因",
|
|
197
|
+
substeps: buildRootCauseWorksheetSubsteps(),
|
|
198
|
+
gates: ROOT_CAUSE_WORKSHEET_GATES,
|
|
199
|
+
agentMustProduce: "rootCauseAnalysis",
|
|
200
|
+
template: {
|
|
201
|
+
mode: null,
|
|
202
|
+
attributionLayer: null,
|
|
203
|
+
hypotheses: [],
|
|
204
|
+
forkPoint: null,
|
|
205
|
+
whyChain: [],
|
|
206
|
+
primaryCause: null,
|
|
207
|
+
contributingFactors: [],
|
|
208
|
+
rootCauseStatement: null,
|
|
209
|
+
confidence: null,
|
|
210
|
+
evidenceGaps: input.hasComparisonSample ? [] : ["需补充:成功/正常样本或对比证据"],
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export function renderTbpInspirationSection() {
|
|
215
|
+
return `## 📚 方法论渊源:借鉴丰田 TBP 八步法
|
|
216
|
+
|
|
217
|
+
SRC-8 **不是**丰田 TBP 的逐字翻译,而是继承其 **PDCA 科学思维**,并针对**代码 + Agent** 场景升华:
|
|
218
|
+
|
|
219
|
+
| 丰田 TBP(制造) | SRC-8(软件/Agent) | 我们的亮点 |
|
|
220
|
+
|------------------|---------------------|------------|
|
|
221
|
+
| 1 明确问题(理想-实际差距) | 1 明确差距 | 期望/实际行为 + 可观察 gap |
|
|
222
|
+
| 2 分解问题(现地现物) | 2 收敛边界 | **现码现志** + code_insight 图谱 + **归因六层** |
|
|
223
|
+
| 3 设定目标 | 3 验收契约 | **failing test / repro** 作为 SMART 目标 |
|
|
224
|
+
| 4 把握真因(5 Why) | 4 把握真因 | **真因工作表**(假设/排除/对比/5Why/陈述)+ 主因/贡献因子 |
|
|
225
|
+
| 5 制定对策 | 5 制定对策 | 最小 patch + 三维评估 |
|
|
226
|
+
| 6 贯彻实施 | 6 贯彻修复 | **复现门禁** + 三次失败升级 |
|
|
227
|
+
| 7 评价结果和过程 | 7 评价双轨 | 结果 + 过程双评 |
|
|
228
|
+
| 8 巩固成果(yokoten) | 8 巩固传播 | 回归测试 + **memorize 跨仓库记忆** |
|
|
229
|
+
|
|
230
|
+
**继承的不变量**(来自 [Toyota TBP](https://artoflean.com/reference/tbp/)):
|
|
231
|
+
- 差距思维、先 Plan 后 Do、禁止跳步、基于事实、对策针对真因、评价后巩固
|
|
232
|
+
|
|
233
|
+
**我们的升华**:
|
|
234
|
+
- 归因层含 **agent_behavior**(工具链/跳步/幻觉修复)
|
|
235
|
+
- 复杂 Bug 允许 **contributingFactors**,不强行单因
|
|
236
|
+
- MCP **guidance-only**:强制思维顺序,由 Agent 执行与输出`;
|
|
237
|
+
}
|
|
238
|
+
export function renderSrc8PdcaMap() {
|
|
239
|
+
return `## 🔄 SRC-8 与 PDCA
|
|
240
|
+
|
|
241
|
+
| PDCA | SRC-8 |
|
|
242
|
+
|------|-------|
|
|
243
|
+
| **Plan** | 1 明确差距 → 2 收敛边界 → 3 验收契约 → **4 把握真因** → 5 制定对策 |
|
|
244
|
+
| **Do** | 6 贯彻修复 |
|
|
245
|
+
| **Check** | 7 评价双轨 |
|
|
246
|
+
| **Act** | 8 巩固传播 |
|
|
247
|
+
|
|
248
|
+
> Plan 阶段应占约 **60–70%** 精力;**Step 4 真因**是核心(建议占 Plan 的 40–50%)。`;
|
|
249
|
+
}
|
|
250
|
+
export function renderAttributionLayersMarkdown() {
|
|
251
|
+
return `## 🧭 归因层(软件原生,替代制造 4M)
|
|
252
|
+
|
|
253
|
+
${ATTRIBUTION_LAYERS.map((l) => `- **${l.id}**(${l.label}):${l.hint}`).join("\n")}`;
|
|
254
|
+
}
|
|
255
|
+
export function renderRootCauseWorksheetMarkdown() {
|
|
256
|
+
const gates = ROOT_CAUSE_WORKSHEET_GATES;
|
|
257
|
+
return `## 🎯 Step 4 真因工作表(SRC-8 核心)
|
|
258
|
+
|
|
259
|
+
${buildRootCauseWorksheetSubsteps()
|
|
260
|
+
.map((s) => `### ${s.id} ${s.title}\n${s.description}`)
|
|
261
|
+
.join("\n\n")}
|
|
262
|
+
|
|
263
|
+
### Step 4 硬门禁(未闭合不准进入 Step 5)
|
|
264
|
+
|
|
265
|
+
- 假设 ≥ ${gates.minHypotheses} 条;排除(含证据)≥ ${gates.minRuledOutWithEvidence} 条
|
|
266
|
+
- 5 Why ≥ ${gates.minWhyLevels} 层,每层绑定观察事实
|
|
267
|
+
- 无成功样本时 **必须** 填写 \`evidenceGaps\`
|
|
268
|
+
- \`confidence: low\` 时须补证据或 \`code_insight\`,不得直接改代码
|
|
269
|
+
- 因果句不得仅以「超时 / SDK bug / 网络慢」敷衍(须分解到可归因层)
|
|
270
|
+
|
|
271
|
+
### Step 4 输出 JSON 模板
|
|
272
|
+
|
|
273
|
+
\`\`\`json
|
|
274
|
+
{
|
|
275
|
+
"rootCauseAnalysis": {
|
|
276
|
+
"mode": "simple|complex",
|
|
277
|
+
"attributionLayer": "code|runtime|data_contract|integration|agent_behavior|environment",
|
|
278
|
+
"hypotheses": [
|
|
279
|
+
{
|
|
280
|
+
"id": "H1",
|
|
281
|
+
"statement": "假设描述",
|
|
282
|
+
"attributionLayer": "agent_behavior",
|
|
283
|
+
"status": "ruled_out|pending|confirmed",
|
|
284
|
+
"evidence": ["支持证据"],
|
|
285
|
+
"counterEvidence": ["反证"]
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
"forkPoint": "成功在 X 步通过,失败在 Y 步偏离",
|
|
289
|
+
"whyChain": [
|
|
290
|
+
{ "level": 1, "observation": "观察到的事实", "why": "为什么", "because": "因为..." }
|
|
291
|
+
],
|
|
292
|
+
"primaryCause": "复杂场景主因",
|
|
293
|
+
"contributingFactors": ["贡献因子1"],
|
|
294
|
+
"rootCauseStatement": "A + B 在条件 D 下导致 C",
|
|
295
|
+
"confidence": "high|medium|low",
|
|
296
|
+
"evidenceGaps": ["尚缺证据"]
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
\`\`\``;
|
|
300
|
+
}
|
|
301
|
+
/** Agent 用:可执行清单,不含 TBP 渊源长文(详见 docs/src8-methodology*.md) */
|
|
302
|
+
export function renderSrc8AgentChecklistMarkdown() {
|
|
303
|
+
return SRC8_STEPS.map((item) => {
|
|
304
|
+
const lines = [
|
|
305
|
+
`### SRC-${item.step} ${item.title}(${item.pdca.toUpperCase()})`,
|
|
306
|
+
"",
|
|
307
|
+
`**核心问题**:${item.question}`,
|
|
308
|
+
"",
|
|
309
|
+
`**技法**:${item.techniques.map((t) => `- ${t}`).join("\n")}`,
|
|
310
|
+
"",
|
|
311
|
+
`**反模式**:${item.antiPatterns.map((p) => `「${p}」`).join("、")}`,
|
|
312
|
+
];
|
|
313
|
+
if (item.schemaFields?.length) {
|
|
314
|
+
lines.push("", `**输出字段**:\`${item.schemaFields.join("`, `")}\``);
|
|
315
|
+
}
|
|
316
|
+
return lines.join("\n");
|
|
317
|
+
}).join("\n\n");
|
|
318
|
+
}
|
|
319
|
+
/** 文档/完整版:含 TBP 步骤对照标注 */
|
|
320
|
+
export function renderSrc8ChecklistMarkdown() {
|
|
321
|
+
return SRC8_STEPS.map((item) => {
|
|
322
|
+
const lines = [
|
|
323
|
+
`### SRC-${item.step} ${item.title}(${item.pdca.toUpperCase()}|借鉴 TBP Step ${item.inspiredByTbpStep})`,
|
|
324
|
+
"",
|
|
325
|
+
`**核心问题**:${item.question}`,
|
|
326
|
+
"",
|
|
327
|
+
`**技法**:${item.techniques.map((t) => `- ${t}`).join("\n")}`,
|
|
328
|
+
"",
|
|
329
|
+
`**反模式**:${item.antiPatterns.map((p) => `「${p}」`).join("、")}`,
|
|
330
|
+
];
|
|
331
|
+
if (item.schemaFields?.length) {
|
|
332
|
+
lines.push("", `**输出字段**:\`${item.schemaFields.join("`, `")}\``);
|
|
333
|
+
}
|
|
334
|
+
return lines.join("\n");
|
|
335
|
+
}).join("\n\n");
|
|
336
|
+
}
|
|
337
|
+
export function renderSrc8GateRules() {
|
|
338
|
+
return `## 🚧 SRC-8 硬门禁
|
|
339
|
+
|
|
340
|
+
1. **禁止从 Step 4 跳起** — 须先完成 Step 1~3
|
|
341
|
+
2. **Step 4 真因工作表闭合前** — 禁止进入 Step 5/6(不改代码)
|
|
342
|
+
3. **Step 4 子步 4a~4e 均须由 Agent 填写** — 见 rootCauseWorksheet
|
|
343
|
+
4. **Step 6 前须满足复现门禁** — failing test / repro / 或说明不可复现的技术原因
|
|
344
|
+
5. **三次修复仍失败** — 回 Step 2/4,不得盲试
|
|
345
|
+
6. **Step 8 须 memorize_asset** — 【现象】【根因】【修复】【验证】`;
|
|
346
|
+
}
|
|
347
|
+
export function renderReproductionGate() {
|
|
348
|
+
return `## 🧪 复现门禁(Step 6 前)
|
|
349
|
+
|
|
350
|
+
1. **failing test**(首选)
|
|
351
|
+
2. **failing command**
|
|
352
|
+
3. **manual repro + 证据**(日志/堆栈)
|
|
353
|
+
|
|
354
|
+
不可本地复现须说明**技术原因**(生产数据、第三方状态等),不得以省事跳过。`;
|
|
355
|
+
}
|
|
356
|
+
export function renderSrc8AgentOutputFormat() {
|
|
357
|
+
return `## 📤 Agent 必须输出的 BugAnalysis JSON
|
|
358
|
+
|
|
359
|
+
\`\`\`json
|
|
360
|
+
{
|
|
361
|
+
"summary": "Bug 简述",
|
|
362
|
+
"analysisMode": "src8",
|
|
363
|
+
"rootCause": "Step 4 真因摘要",
|
|
364
|
+
"rootCauseAnalysis": { "...": "见 Step 4 模板" },
|
|
365
|
+
"fixPlan": { "steps": ["Step 5~6"] },
|
|
366
|
+
"testPlan": { "unitTests": ["Step 3 契约"], "manualTests": ["原复现"] },
|
|
367
|
+
"preventionMeasures": ["Step 8"],
|
|
368
|
+
"tbp": {
|
|
369
|
+
"phenomenon": "SRC-1",
|
|
370
|
+
"timeline": [],
|
|
371
|
+
"ruledOut": ["SRC-4 已排除"],
|
|
372
|
+
"commonPattern": "SRC-4 分叉点",
|
|
373
|
+
"boundary": "SRC-2 边界",
|
|
374
|
+
"rootCauseStatement": "SRC-4e",
|
|
375
|
+
"evidence": [],
|
|
376
|
+
"repair": []
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
\`\`\`
|
|
380
|
+
|
|
381
|
+
> 字段 \`tbp\` 为历史兼容名,语义对齐 SRC-8 各步产出。`;
|
|
382
|
+
}
|
|
383
|
+
export function buildSrc8DelegatedPlan(input) {
|
|
384
|
+
const analysisMode = resolveAnalysisMode(input.analysis_mode);
|
|
385
|
+
const includeGentest = input.includeGentest !== false;
|
|
386
|
+
const includeMemorize = input.includeMemorize !== false;
|
|
387
|
+
const steps = [
|
|
388
|
+
{
|
|
389
|
+
id: "src8-1",
|
|
390
|
+
action: "SRC-1 明确差距(PLAN):写清理想行为、实际行为、可观察 gap;禁止只有情绪无差距",
|
|
391
|
+
outputs: ["BugAnalysis.tbp.phenomenon", "BugAnalysis.summary"],
|
|
392
|
+
note: "写入 structuredContent.bugfixInput.phenomenon;反模式:「坏了/卡了」",
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
id: "src8-2",
|
|
396
|
+
tool: "code_insight",
|
|
397
|
+
when: "边界/调用链不清,或需收敛影响面",
|
|
398
|
+
args: {
|
|
399
|
+
mode: "auto",
|
|
400
|
+
query: input.error_message,
|
|
401
|
+
...(input.stack_trace ? { task_context: input.stack_trace } : {}),
|
|
402
|
+
...(input.project_root ? { project_root: input.project_root } : {}),
|
|
403
|
+
},
|
|
404
|
+
outputs: ["BugAnalysis.tbp.boundary", "BugAnalysis.tbp.timeline"],
|
|
405
|
+
dependsOn: ["src8-1"],
|
|
406
|
+
note: "图谱缺失时先执行 init_project_context;再读本步输出收敛边界",
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
id: "src8-3",
|
|
410
|
+
action: "SRC-3 验收契约(PLAN):定义 SMART 验收(failing test 变绿 / repro 命令 / 明确手动步骤)",
|
|
411
|
+
outputs: ["BugAnalysis.testPlan"],
|
|
412
|
+
dependsOn: ["src8-1"],
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
id: "src8-4",
|
|
416
|
+
action: "SRC-4 把握真因(PLAN):按 rootCauseWorksheet 完成 4a~4e,输出 rootCauseAnalysis 与因果句",
|
|
417
|
+
outputs: [
|
|
418
|
+
"rootCauseAnalysis",
|
|
419
|
+
"BugAnalysis.rootCause",
|
|
420
|
+
"BugAnalysis.tbp.rootCauseStatement",
|
|
421
|
+
"BugAnalysis.tbp.ruledOut",
|
|
422
|
+
],
|
|
423
|
+
dependsOn: ["src8-1", "src8-2", "src8-3"],
|
|
424
|
+
note: "硬门禁:本步闭合前禁止改代码;见 structuredContent.rootCauseWorksheet",
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
id: "src8-5",
|
|
428
|
+
action: "SRC-5 制定对策(PLAN):最小 patch,评估有效性/可行性/回归风险",
|
|
429
|
+
outputs: ["BugAnalysis.fixPlan", "BugAnalysis.tbp.repair"],
|
|
430
|
+
dependsOn: ["src8-4"],
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
id: "src8-6",
|
|
434
|
+
action: "SRC-6 贯彻修复(DO):复现门禁通过后改代码,改动仅限 Bug 范围",
|
|
435
|
+
when: "rootCauseWorksheet 已闭合且复现/failing test 已就绪",
|
|
436
|
+
outputs: ["BugAnalysis.affectedFiles", "代码补丁"],
|
|
437
|
+
dependsOn: ["src8-5"],
|
|
438
|
+
note: "三次修复仍失败 → 回 src8-2 或 src8-4,不得盲试",
|
|
439
|
+
},
|
|
440
|
+
];
|
|
441
|
+
if (includeGentest) {
|
|
442
|
+
steps.push({
|
|
443
|
+
id: "src8-7",
|
|
444
|
+
tool: "gentest",
|
|
445
|
+
when: "SRC-6 代码已修改",
|
|
446
|
+
args: {
|
|
447
|
+
code: "[修复后的代码]",
|
|
448
|
+
framework: "[按项目上下文选择 vitest/jest/mocha]",
|
|
449
|
+
...(input.file_path ? { file_path: input.file_path } : {}),
|
|
450
|
+
...(input.project_root ? { project_root: input.project_root } : {}),
|
|
451
|
+
},
|
|
452
|
+
outputs: ["回归测试代码"],
|
|
453
|
+
dependsOn: ["src8-6"],
|
|
454
|
+
note: "SRC-7 评价双轨(结果轨):对照 Step 3 验收契约",
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
steps.push({
|
|
459
|
+
id: "src8-7",
|
|
460
|
+
action: "SRC-7 评价双轨(CHECK):对照验收契约验证,并复盘过程证据缺口",
|
|
461
|
+
outputs: ["BugAnalysis.summary(含验证结论)"],
|
|
462
|
+
dependsOn: ["src8-6"],
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
if (includeMemorize) {
|
|
466
|
+
steps.push({
|
|
467
|
+
id: "src8-8",
|
|
468
|
+
tool: "memorize_asset",
|
|
469
|
+
when: "验证通过",
|
|
470
|
+
args: {
|
|
471
|
+
type: "bugfix",
|
|
472
|
+
tags: "bugfix,root-cause",
|
|
473
|
+
summary: `[关键词] ${input.error_message.slice(0, 80)}`,
|
|
474
|
+
content: "【现象】【根因】【修复】【验证】",
|
|
475
|
+
},
|
|
476
|
+
outputs: ["记忆库 bugfix 条目"],
|
|
477
|
+
dependsOn: ["src8-7"],
|
|
478
|
+
note: "SRC-8 巩固传播(ACT)",
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
steps.push({
|
|
483
|
+
id: "src8-8",
|
|
484
|
+
action: "SRC-8 巩固传播(ACT):补回归测试并写 preventionMeasures",
|
|
485
|
+
outputs: ["BugAnalysis.preventionMeasures"],
|
|
486
|
+
dependsOn: ["src8-7"],
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
return {
|
|
490
|
+
mode: "delegated",
|
|
491
|
+
methodology: analysisMode,
|
|
492
|
+
steps,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
/** start_bugfix / loop 外层:上下文步骤 + SRC-8 八步 + 可选闸门/记忆 */
|
|
496
|
+
export function mergeBugfixOrchestrationPlan(input) {
|
|
497
|
+
const src8 = buildSrc8DelegatedPlan({
|
|
498
|
+
...input.src8Input,
|
|
499
|
+
includeMemorize: input.deferMemorize ? false : input.src8Input.includeMemorize,
|
|
500
|
+
});
|
|
501
|
+
return {
|
|
502
|
+
mode: "delegated",
|
|
503
|
+
methodology: resolveAnalysisMode(input.src8Input.analysis_mode),
|
|
504
|
+
steps: [
|
|
505
|
+
...(input.preambleSteps ?? []),
|
|
506
|
+
...src8.steps,
|
|
507
|
+
...(input.appendSteps ?? []),
|
|
508
|
+
],
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
export function renderSrc8PlanSummaryMarkdown(plan) {
|
|
512
|
+
const lines = [
|
|
513
|
+
"## 📋 SRC-8 执行计划(delegated)",
|
|
514
|
+
"",
|
|
515
|
+
"严格按 `structuredContent.metadata.plan.steps` 顺序执行,完成每步 `outputs` 后再进入下一步:",
|
|
516
|
+
"",
|
|
517
|
+
];
|
|
518
|
+
for (const step of plan.steps) {
|
|
519
|
+
const kind = step.tool ? `tool: \`${step.tool}\`` : "action";
|
|
520
|
+
lines.push(`### ${step.id} — ${kind}`);
|
|
521
|
+
if (step.action) {
|
|
522
|
+
lines.push(step.action);
|
|
523
|
+
}
|
|
524
|
+
if (step.tool && step.args) {
|
|
525
|
+
lines.push("```json");
|
|
526
|
+
lines.push(JSON.stringify(step.args, null, 2));
|
|
527
|
+
lines.push("```");
|
|
528
|
+
}
|
|
529
|
+
if (step.when) {
|
|
530
|
+
lines.push(`- **when**: ${step.when}`);
|
|
531
|
+
}
|
|
532
|
+
if (step.dependsOn?.length) {
|
|
533
|
+
lines.push(`- **dependsOn**: ${step.dependsOn.join(", ")}`);
|
|
534
|
+
}
|
|
535
|
+
if (step.outputs?.length) {
|
|
536
|
+
lines.push(`- **outputs**: ${step.outputs.join(", ")}`);
|
|
537
|
+
}
|
|
538
|
+
if (step.note) {
|
|
539
|
+
lines.push(`- **note**: ${step.note}`);
|
|
540
|
+
}
|
|
541
|
+
lines.push("");
|
|
542
|
+
}
|
|
543
|
+
return lines.join("\n");
|
|
544
|
+
}
|
|
545
|
+
export function buildSrc8EvidenceFromInput(input) {
|
|
546
|
+
const evidence = [
|
|
547
|
+
{ type: "symptom", detail: input.error_message, source: "error_message" },
|
|
548
|
+
];
|
|
549
|
+
if (input.steps_to_reproduce) {
|
|
550
|
+
evidence.push({ type: "timeline", detail: input.steps_to_reproduce, source: "steps_to_reproduce" });
|
|
551
|
+
}
|
|
552
|
+
if (input.stack_trace) {
|
|
553
|
+
evidence.push({ type: "stack", detail: input.stack_trace, source: "stack_trace" });
|
|
554
|
+
}
|
|
555
|
+
if (input.code_context) {
|
|
556
|
+
evidence.push({ type: "code", detail: input.code_context, source: "code_context" });
|
|
557
|
+
}
|
|
558
|
+
if (input.expected_behavior) {
|
|
559
|
+
evidence.push({ type: "comparison", detail: `期望: ${input.expected_behavior}`, source: "expected_behavior" });
|
|
560
|
+
}
|
|
561
|
+
if (input.actual_behavior) {
|
|
562
|
+
evidence.push({ type: "comparison", detail: `实际: ${input.actual_behavior}`, source: "actual_behavior" });
|
|
563
|
+
}
|
|
564
|
+
if (input.success_sample) {
|
|
565
|
+
evidence.push({ type: "comparison", detail: `成功样本: ${input.success_sample}`, source: "success_sample" });
|
|
566
|
+
}
|
|
567
|
+
if (input.verification_target) {
|
|
568
|
+
evidence.push({ type: "comparison", detail: `验收目标: ${input.verification_target}`, source: "verification_target" });
|
|
569
|
+
}
|
|
570
|
+
return evidence;
|
|
571
|
+
}
|
|
572
|
+
export function renderFixBugAgentPromptBody(sections) {
|
|
573
|
+
return `# SRC-8 Bug 真因分析与修复
|
|
574
|
+
|
|
575
|
+
## 🐛 Bug 信息
|
|
576
|
+
|
|
577
|
+
**错误信息**:
|
|
578
|
+
\`\`\`
|
|
579
|
+
${sections.error_message}
|
|
580
|
+
\`\`\`
|
|
581
|
+
|
|
582
|
+
${sections.stack_trace_section}
|
|
583
|
+
|
|
584
|
+
${sections.reproduce_section}
|
|
585
|
+
|
|
586
|
+
${sections.behavior_section}
|
|
587
|
+
|
|
588
|
+
${sections.comparison_section}
|
|
589
|
+
|
|
590
|
+
${sections.verification_target_section}
|
|
591
|
+
|
|
592
|
+
${sections.code_context_section}
|
|
593
|
+
|
|
594
|
+
---
|
|
595
|
+
|
|
596
|
+
${renderSrc8PlanSummaryMarkdown(sections.plan)}
|
|
597
|
+
|
|
598
|
+
---
|
|
599
|
+
|
|
600
|
+
${renderRootCauseWorksheetMarkdown()}
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
${renderReproductionGate()}
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
${renderSrc8GateRules()}
|
|
609
|
+
|
|
610
|
+
*方法论: SRC-8 | 执行: metadata.plan*`;
|
|
611
|
+
}
|
|
612
|
+
/** @deprecated 使用 renderFixBugAgentPromptBody;完整 TBP 对照版见 docs */
|
|
613
|
+
export function renderFixBugPromptBody(sections) {
|
|
614
|
+
return renderFixBugAgentPromptBody(sections);
|
|
615
|
+
}
|
|
616
|
+
export function resolveAnalysisMode(raw) {
|
|
617
|
+
const n = (raw || "").trim().toLowerCase();
|
|
618
|
+
if (n === TBP8_ALIAS || n === SRC8_METHODOLOGY || !n) {
|
|
619
|
+
return SRC8_METHODOLOGY;
|
|
620
|
+
}
|
|
621
|
+
return SRC8_METHODOLOGY;
|
|
622
|
+
}
|
|
623
|
+
// --- 向后兼容导出(旧模块名 tbp8-guidance) ---
|
|
624
|
+
export const TBP8_STEPS = SRC8_STEPS;
|
|
625
|
+
export const buildTbpChecklist = buildSrc8Checklist;
|
|
626
|
+
export const buildTbpEvidenceFromInput = buildSrc8EvidenceFromInput;
|
|
627
|
+
export const renderTbpPdcaMap = renderSrc8PdcaMap;
|
|
628
|
+
export const renderTbpChecklistMarkdown = renderSrc8ChecklistMarkdown;
|
|
629
|
+
export const renderTbpGateRules = renderSrc8GateRules;
|
|
630
|
+
export const renderTbpReproductionGate = renderReproductionGate;
|
|
631
|
+
export const renderTbpAgentOutputFormat = renderSrc8AgentOutputFormat;
|
|
632
|
+
export const renderTbpFiveWhyTemplate = () => renderRootCauseWorksheetMarkdown();
|
|
633
|
+
export const renderTbpBugInfoSections = renderFixBugPromptBody;
|