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
package/build/tools/fix_bug.js
CHANGED
|
@@ -1,199 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* fix_bug 工具
|
|
3
|
-
*
|
|
4
|
-
* 功能:基于 TBP 8 步法输出真因分析与修复指南
|
|
5
|
-
* 模式:指令生成器模式 - 返回详细的 RCA 与修复指南,由 AI 执行实际操作
|
|
6
|
-
*
|
|
7
|
-
* 流程:定义现象 → 复盘时间线 → 排除错误方向 → 找共同模式 → 定位边界 → 陈述真因 → 闭合证据链 → 设计修复方案
|
|
2
|
+
* fix_bug 工具 — SRC-8 delegated plan + 真因工作表
|
|
8
3
|
*/
|
|
9
4
|
import { parseArgs, getString } from "../utils/parseArgs.js";
|
|
10
5
|
import { okStructured } from "../lib/response.js";
|
|
11
|
-
import {
|
|
6
|
+
import { renderOrchestrationHeader } from "../lib/orchestration-guidance.js";
|
|
12
7
|
import { handleToolError } from "../utils/error-handler.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
**错误信息**:
|
|
18
|
-
\`\`\`
|
|
19
|
-
{error_message}
|
|
20
|
-
\`\`\`
|
|
21
|
-
|
|
22
|
-
{stack_trace_section}
|
|
23
|
-
|
|
24
|
-
{reproduce_section}
|
|
25
|
-
|
|
26
|
-
{behavior_section}
|
|
27
|
-
|
|
28
|
-
{code_context_section}
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## TBP-1 现象
|
|
33
|
-
|
|
34
|
-
先把用户可见的问题定义准确,避免“坏了/卡了/有问题”这类泛化描述。
|
|
35
|
-
|
|
36
|
-
要求:
|
|
37
|
-
1. 用 1-2 句定义现象
|
|
38
|
-
2. 明确是“慢”“停滞”“失败”“回归”还是“未生效”
|
|
39
|
-
3. 如果提供了期望/实际行为,必须纳入现象定义
|
|
40
|
-
|
|
41
|
-
## TBP-2 时间线
|
|
42
|
-
|
|
43
|
-
基于现有信息复盘事件顺序,至少回答:
|
|
44
|
-
1. 什么时候开始
|
|
45
|
-
2. 中间发生了什么
|
|
46
|
-
3. 最后停在什么状态
|
|
47
|
-
|
|
48
|
-
优先记录:
|
|
49
|
-
- 用户输入 / 复现步骤
|
|
50
|
-
- first progress / first error
|
|
51
|
-
- tool call / stack / stop / timeout
|
|
52
|
-
- 关键文件或模块
|
|
53
|
-
|
|
54
|
-
## TBP-3 不是这个
|
|
55
|
-
|
|
56
|
-
列出当前应优先排除的错误方向,并说明需要什么证据排除。
|
|
57
|
-
|
|
58
|
-
常见排除项:
|
|
59
|
-
- 不是单纯网络慢
|
|
60
|
-
- 不是前端展示截断
|
|
61
|
-
- 不是消息没转发
|
|
62
|
-
- 不是纯粹的超时表象
|
|
63
|
-
- 不是用户输入丢失
|
|
64
|
-
|
|
65
|
-
## TBP-4 共同模式
|
|
66
|
-
|
|
67
|
-
对比成功/失败样本,找出从哪一步开始分叉。
|
|
68
|
-
|
|
69
|
-
重点检查:
|
|
70
|
-
- 传输层
|
|
71
|
-
- 会话状态机
|
|
72
|
-
- 完成态判定
|
|
73
|
-
- 工具执行
|
|
74
|
-
- 文件写入
|
|
75
|
-
- 重试策略
|
|
76
|
-
|
|
77
|
-
## TBP-5 边界
|
|
78
|
-
|
|
79
|
-
明确指出问题失控落在哪一层:
|
|
80
|
-
- 上游模型 / SDK
|
|
81
|
-
- 网关状态机
|
|
82
|
-
- session 复用
|
|
83
|
-
- tool 执行层
|
|
84
|
-
- 文件系统
|
|
85
|
-
- 环境配置
|
|
86
|
-
- UI 展示层
|
|
87
|
-
|
|
88
|
-
## TBP-6 真因
|
|
89
|
-
|
|
90
|
-
真因必须写成因果句:
|
|
91
|
-
\`A + B 在条件 D 下导致了 C\`
|
|
92
|
-
|
|
93
|
-
不允许只写:
|
|
94
|
-
- 超时了
|
|
95
|
-
- SDK 有 bug
|
|
96
|
-
- 返回慢
|
|
97
|
-
|
|
98
|
-
## TBP-7 证据链
|
|
99
|
-
|
|
100
|
-
说明:
|
|
101
|
-
1. 哪些证据支持真因
|
|
102
|
-
2. 哪些现象若出现会推翻它,但现场没有出现
|
|
103
|
-
3. 为什么其他解释更弱
|
|
104
|
-
|
|
105
|
-
## TBP-8 修复
|
|
106
|
-
|
|
107
|
-
只有在证据链闭合后,才开始设计修复。
|
|
108
|
-
|
|
109
|
-
每个修复方案都要说明:
|
|
110
|
-
- 改哪一层
|
|
111
|
-
- 为什么这是修真因,不是补症状
|
|
112
|
-
- 风险是什么
|
|
113
|
-
- 怎么验证
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## 📤 输出格式要求
|
|
118
|
-
|
|
119
|
-
请严格按以下 JSON 格式输出修复指南:
|
|
120
|
-
|
|
121
|
-
\`\`\`json
|
|
122
|
-
{
|
|
123
|
-
"bug_summary": "Bug 简述(一句话)",
|
|
124
|
-
"analysis_mode": "tbp8",
|
|
125
|
-
"analysis": {
|
|
126
|
-
"error_type": "错误类型",
|
|
127
|
-
"direct_cause": "直接原因",
|
|
128
|
-
"root_cause": "根本原因",
|
|
129
|
-
"affected_scope": "影响范围"
|
|
130
|
-
},
|
|
131
|
-
"tbp": {
|
|
132
|
-
"phenomenon": "TBP-1 现象",
|
|
133
|
-
"timeline": [],
|
|
134
|
-
"ruled_out": [],
|
|
135
|
-
"common_pattern": "TBP-4 共同模式",
|
|
136
|
-
"boundary": "TBP-5 边界",
|
|
137
|
-
"root_cause_statement": "A + B 在条件 D 下导致 C",
|
|
138
|
-
"evidence": [],
|
|
139
|
-
"repair": []
|
|
140
|
-
},
|
|
141
|
-
"location": {
|
|
142
|
-
"file": "问题文件路径",
|
|
143
|
-
"line": 42,
|
|
144
|
-
"function": "问题函数名",
|
|
145
|
-
"code_snippet": "问题代码片段"
|
|
146
|
-
},
|
|
147
|
-
"fix_plan": {
|
|
148
|
-
"chosen_solution": "选择的修复方案",
|
|
149
|
-
"reason": "选择理由",
|
|
150
|
-
"steps": [
|
|
151
|
-
{ "step": 1, "action": "修复步骤", "file": "文件", "change": "变更内容" }
|
|
152
|
-
],
|
|
153
|
-
"code_before": "修改前代码",
|
|
154
|
-
"code_after": "修改后代码"
|
|
155
|
-
},
|
|
156
|
-
"verification": {
|
|
157
|
-
"test_cases": ["测试用例1", "测试用例2"],
|
|
158
|
-
"manual_checks": ["手动验证项1", "手动验证项2"]
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
\`\`\`
|
|
162
|
-
|
|
163
|
-
## ⚠️ 护栏
|
|
164
|
-
|
|
165
|
-
- 不要一看到新现象就补一个新分支,先判断是不是同一类根因在换表现
|
|
166
|
-
- 不要把“超时”直接当真因,要先分清是没进展、慢进展,还是结果已出现但判定过严
|
|
167
|
-
- 不要只看单一样本就下结论,有对比样本时必须做对比
|
|
168
|
-
- 如果证据不足,要明确说明还缺什么证据
|
|
169
|
-
|
|
170
|
-
---
|
|
171
|
-
|
|
172
|
-
*指南版本: 2.0.0*
|
|
173
|
-
*工具: MCP Probe Kit - fix_bug*
|
|
174
|
-
`;
|
|
175
|
-
function inferBugType(text) {
|
|
176
|
-
if (/timeout|latency|slow|卡|慢|超时/i.test(text))
|
|
177
|
-
return "performance";
|
|
178
|
-
if (/auth|permission|unauthor|token|登录|权限/i.test(text))
|
|
179
|
-
return "security";
|
|
180
|
-
if (/ui|render|white screen|白屏|按钮|页面/i.test(text))
|
|
181
|
-
return "ui";
|
|
182
|
-
if (/sql|db|data|schema|缓存|数据/i.test(text))
|
|
183
|
-
return "data";
|
|
184
|
-
if (/api|request|network|gateway|integration|调用失败/i.test(text))
|
|
185
|
-
return "integration";
|
|
186
|
-
return "functional";
|
|
187
|
-
}
|
|
188
|
-
function inferSeverity(text) {
|
|
189
|
-
if (/crash|fatal|panic|生产故障|数据丢失|security|权限绕过/i.test(text))
|
|
190
|
-
return "critical";
|
|
191
|
-
if (/white screen|白屏|500|无法登录|阻塞|不可用|timeout|超时/i.test(text))
|
|
192
|
-
return "high";
|
|
193
|
-
if (/error|exception|失败|异常/i.test(text))
|
|
194
|
-
return "medium";
|
|
195
|
-
return "low";
|
|
196
|
-
}
|
|
8
|
+
import { resolveGuidanceCode, trimCodeForPrompt } from "../lib/code-review-input.js";
|
|
9
|
+
import { resolveWorkspaceRoot } from "../lib/workspace-root.js";
|
|
10
|
+
import { ATTRIBUTION_LAYERS, SRC8_METHODOLOGY, ROOT_CAUSE_WORKSHEET_GATES, buildRootCauseWorksheet, buildSrc8Checklist, buildSrc8DelegatedPlan, buildSrc8EvidenceFromInput, renderFixBugAgentPromptBody, resolveAnalysisMode, } from "../lib/src8-guidance.js";
|
|
197
11
|
function extractFilePaths(text) {
|
|
198
12
|
if (!text)
|
|
199
13
|
return [];
|
|
@@ -202,13 +16,10 @@ function extractFilePaths(text) {
|
|
|
202
16
|
}
|
|
203
17
|
function summarizePhenomenon(errorMessage, expectedBehavior, actualBehavior) {
|
|
204
18
|
if (expectedBehavior || actualBehavior) {
|
|
205
|
-
return
|
|
19
|
+
return `实际表现为「${actualBehavior || errorMessage}」,但期望是「${expectedBehavior || "保持正常行为"}」。`;
|
|
206
20
|
}
|
|
207
|
-
return
|
|
21
|
+
return `当前可见现象是「${errorMessage}」,需要先区分它属于失败、停滞、未生效还是性能退化。`;
|
|
208
22
|
}
|
|
209
|
-
/**
|
|
210
|
-
* fix_bug 工具实现
|
|
211
|
-
*/
|
|
212
23
|
export async function fixBug(args) {
|
|
213
24
|
try {
|
|
214
25
|
const parsedArgs = parseArgs(args, {
|
|
@@ -216,134 +27,171 @@ export async function fixBug(args) {
|
|
|
216
27
|
error_message: "",
|
|
217
28
|
stack_trace: "",
|
|
218
29
|
code_context: "",
|
|
219
|
-
|
|
30
|
+
file_path: "",
|
|
31
|
+
project_root: "",
|
|
32
|
+
analysis_mode: SRC8_METHODOLOGY,
|
|
220
33
|
steps_to_reproduce: "",
|
|
221
34
|
expected_behavior: "",
|
|
222
35
|
actual_behavior: "",
|
|
36
|
+
success_sample: "",
|
|
37
|
+
verification_target: "",
|
|
223
38
|
},
|
|
224
39
|
primaryField: "error_message",
|
|
225
40
|
fieldAliases: {
|
|
226
|
-
error_message: ["error", "err", "message", "错误", "错误信息"],
|
|
41
|
+
error_message: ["error", "err", "message", "错误", "错误信息", "description", "desc", "summary", "问题", "bug", "issue"],
|
|
227
42
|
stack_trace: ["stack", "trace", "堆栈", "调用栈"],
|
|
228
43
|
code_context: ["code_context", "code", "context", "相关代码", "代码上下文"],
|
|
229
|
-
|
|
44
|
+
file_path: ["filePath", "filepath", "path", "文件路径"],
|
|
45
|
+
project_root: ["projectRoot", "project_path", "dir", "directory", "项目路径"],
|
|
46
|
+
analysis_mode: ["analysis_mode", "methodology", "tbp", "src8", "rca", "分析方法"],
|
|
230
47
|
steps_to_reproduce: ["steps", "reproduce", "步骤", "复现步骤"],
|
|
231
48
|
expected_behavior: ["expected", "期望", "期望行为"],
|
|
232
49
|
actual_behavior: ["actual", "实际", "实际行为"],
|
|
50
|
+
success_sample: ["success", "working_case", "正常样本", "成功样本", "对比样本"],
|
|
51
|
+
verification_target: ["target", "acceptance", "验收标准", "验证目标", "done_criteria"],
|
|
233
52
|
},
|
|
234
53
|
});
|
|
235
|
-
const errorMessage = getString(parsedArgs.error_message);
|
|
54
|
+
const errorMessage = getString(parsedArgs.error_message) || getString(parsedArgs.description);
|
|
236
55
|
const stackTrace = getString(parsedArgs.stack_trace);
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
56
|
+
const inlineCodeContext = getString(parsedArgs.code_context);
|
|
57
|
+
const filePath = getString(parsedArgs.file_path);
|
|
58
|
+
const projectRoot = getString(parsedArgs.project_root);
|
|
59
|
+
const analysisMode = resolveAnalysisMode(getString(parsedArgs.analysis_mode));
|
|
241
60
|
const stepsToReproduce = getString(parsedArgs.steps_to_reproduce);
|
|
242
61
|
const expectedBehavior = getString(parsedArgs.expected_behavior);
|
|
243
62
|
const actualBehavior = getString(parsedArgs.actual_behavior);
|
|
63
|
+
const successSample = getString(parsedArgs.success_sample);
|
|
64
|
+
const verificationTarget = getString(parsedArgs.verification_target);
|
|
244
65
|
if (!errorMessage) {
|
|
245
66
|
throw new Error("缺少必填参数: error_message(错误信息)");
|
|
246
67
|
}
|
|
68
|
+
const resolvedProjectRoot = projectRoot ? resolveWorkspaceRoot(projectRoot) : undefined;
|
|
69
|
+
const resolvedCode = resolveGuidanceCode({
|
|
70
|
+
code: inlineCodeContext,
|
|
71
|
+
filePath: filePath || undefined,
|
|
72
|
+
projectRoot: resolvedProjectRoot,
|
|
73
|
+
});
|
|
74
|
+
const hasSuccessSample = Boolean(successSample.trim());
|
|
75
|
+
const rootCauseWorksheet = buildRootCauseWorksheet({ hasComparisonSample: hasSuccessSample });
|
|
76
|
+
const plan = buildSrc8DelegatedPlan({
|
|
77
|
+
error_message: errorMessage,
|
|
78
|
+
stack_trace: stackTrace || undefined,
|
|
79
|
+
analysis_mode: analysisMode,
|
|
80
|
+
code_context: resolvedCode.code || inlineCodeContext || undefined,
|
|
81
|
+
project_root: resolvedProjectRoot,
|
|
82
|
+
file_path: filePath || resolvedCode.file || undefined,
|
|
83
|
+
});
|
|
84
|
+
if (resolvedCode.error) {
|
|
85
|
+
return okStructured(`❌ fix_bug 无法读取代码上下文: ${resolvedCode.error}`, {
|
|
86
|
+
mode: "delegated",
|
|
87
|
+
methodology: analysisMode,
|
|
88
|
+
src8Checklist: buildSrc8Checklist(),
|
|
89
|
+
rootCauseWorksheet,
|
|
90
|
+
metadata: { plan },
|
|
91
|
+
bugfixInput: {
|
|
92
|
+
received: false,
|
|
93
|
+
error: resolvedCode.error,
|
|
94
|
+
error_message: errorMessage,
|
|
95
|
+
file: filePath || null,
|
|
96
|
+
analysis_mode: analysisMode,
|
|
97
|
+
},
|
|
98
|
+
}, {
|
|
99
|
+
note: "请修正 file_path/project_root 后重试;执行顺序见 metadata.plan",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const codeContext = resolvedCode.code;
|
|
103
|
+
const hasCodeContext = Boolean(codeContext.trim());
|
|
104
|
+
const promptCodeContext = hasCodeContext ? trimCodeForPrompt(codeContext, 24000, "bugfixInput") : "";
|
|
247
105
|
const stackTraceSection = stackTrace
|
|
248
106
|
? `**堆栈跟踪**:\n\`\`\`\n${stackTrace}\n\`\`\``
|
|
249
107
|
: "**堆栈跟踪**: 未提供(建议提供以便更准确定位)";
|
|
250
|
-
const reproduceSection = stepsToReproduce
|
|
251
|
-
? `**复现步骤**:\n${stepsToReproduce}`
|
|
252
|
-
: "";
|
|
108
|
+
const reproduceSection = stepsToReproduce ? `**复现步骤**:\n${stepsToReproduce}` : "";
|
|
253
109
|
const behaviorSection = [expectedBehavior ? `**期望行为**: ${expectedBehavior}` : "", actualBehavior ? `**实际行为**: ${actualBehavior}` : ""]
|
|
254
110
|
.filter(Boolean)
|
|
255
111
|
.join("\n\n");
|
|
256
|
-
const
|
|
257
|
-
?
|
|
112
|
+
const comparisonSection = hasSuccessSample
|
|
113
|
+
? `**成功样本(SRC-4c 对比分叉)**:\n${successSample}`
|
|
114
|
+
: "**成功样本**: 未提供(SRC-4c 须在 rootCauseAnalysis.evidenceGaps 说明缺口)";
|
|
115
|
+
const verificationTargetSection = verificationTarget
|
|
116
|
+
? `**验收契约(SRC-3)**:\n${verificationTarget}`
|
|
117
|
+
: "**验收契约**: 未提供(SRC-3 须设定 SMART 标准,如 failing test 变绿)";
|
|
118
|
+
const codeContextSection = hasCodeContext
|
|
119
|
+
? `**代码/图谱上下文**${resolvedCode.file ? `(来源: ${resolvedCode.file})` : ""}:\n\`\`\`\n${promptCodeContext}\n\`\`\``
|
|
258
120
|
: "";
|
|
259
|
-
const header =
|
|
121
|
+
const header = renderOrchestrationHeader({
|
|
260
122
|
tool: "fix_bug",
|
|
261
|
-
goal:
|
|
262
|
-
tasks: [
|
|
263
|
-
|
|
123
|
+
goal: `SRC-8 修复 Bug:${errorMessage.substring(0, 120)}${errorMessage.length > 120 ? "..." : ""}`,
|
|
124
|
+
tasks: [
|
|
125
|
+
"严格按 structuredContent.metadata.plan.steps 顺序执行(禁止从 src8-4 跳起)",
|
|
126
|
+
"src8-4 闭合 rootCauseWorksheet 并输出 rootCauseAnalysis 后才可进入 src8-5/6",
|
|
127
|
+
"src8-6 前满足复现门禁;src8-8 用 memorize_asset 沉淀",
|
|
128
|
+
],
|
|
129
|
+
notes: [
|
|
130
|
+
"MCP 为 guidance-only,不自动修 Bug",
|
|
131
|
+
hasCodeContext ? `已注入代码上下文(${codeContext.split("\n").length} 行)` : "建议补充 code_context 或 file_path + project_root",
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
const guide = `${header}${renderFixBugAgentPromptBody({
|
|
135
|
+
error_message: errorMessage,
|
|
136
|
+
stack_trace_section: stackTraceSection,
|
|
137
|
+
reproduce_section: reproduceSection,
|
|
138
|
+
behavior_section: behaviorSection,
|
|
139
|
+
comparison_section: comparisonSection,
|
|
140
|
+
verification_target_section: verificationTargetSection,
|
|
141
|
+
code_context_section: codeContextSection,
|
|
142
|
+
plan,
|
|
143
|
+
})}`;
|
|
144
|
+
const evidence = buildSrc8EvidenceFromInput({
|
|
145
|
+
error_message: errorMessage,
|
|
146
|
+
stack_trace: stackTrace || undefined,
|
|
147
|
+
code_context: codeContext || undefined,
|
|
148
|
+
steps_to_reproduce: stepsToReproduce || undefined,
|
|
149
|
+
expected_behavior: expectedBehavior || undefined,
|
|
150
|
+
actual_behavior: actualBehavior || undefined,
|
|
151
|
+
success_sample: successSample || undefined,
|
|
152
|
+
verification_target: verificationTarget || undefined,
|
|
264
153
|
});
|
|
265
|
-
const guide = `${header}${PROMPT_TEMPLATE
|
|
266
|
-
.replace(/{error_message}/g, errorMessage)
|
|
267
|
-
.replace(/{stack_trace_section}/g, stackTraceSection)
|
|
268
|
-
.replace(/{reproduce_section}/g, reproduceSection)
|
|
269
|
-
.replace(/{behavior_section}/g, behaviorSection)
|
|
270
|
-
.replace(/{code_context_section}/g, codeContextSection)}`;
|
|
271
|
-
const evidence = [
|
|
272
|
-
{ type: "symptom", detail: errorMessage, source: "error_message" },
|
|
273
|
-
...(stepsToReproduce ? [{ type: "timeline", detail: stepsToReproduce, source: "steps_to_reproduce" }] : []),
|
|
274
|
-
...(stackTrace ? [{ type: "stack", detail: stackTrace, source: "stack_trace" }] : []),
|
|
275
|
-
...(codeContext ? [{ type: "code", detail: codeContext, source: "code_context" }] : []),
|
|
276
|
-
...(expectedBehavior ? [{ type: "comparison", detail: `期望行为: ${expectedBehavior}`, source: "expected_behavior" }] : []),
|
|
277
|
-
...(actualBehavior ? [{ type: "comparison", detail: `实际行为: ${actualBehavior}`, source: "actual_behavior" }] : []),
|
|
278
|
-
];
|
|
279
154
|
const affectedFiles = [...extractFilePaths(stackTrace), ...extractFilePaths(codeContext)]
|
|
280
155
|
.filter((value, index, array) => array.indexOf(value) === index);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
],
|
|
296
|
-
estimatedTime: "30-90 分钟(取决于证据完整度)",
|
|
297
|
-
risks: [
|
|
298
|
-
"如果跳过 TBP 1-7,容易只修表象不修真因",
|
|
299
|
-
"如果没有成功样本对比,TBP-4 共同模式结论可能偏弱",
|
|
300
|
-
],
|
|
156
|
+
return okStructured(guide, {
|
|
157
|
+
mode: "delegated",
|
|
158
|
+
methodology: analysisMode,
|
|
159
|
+
src8Checklist: buildSrc8Checklist(),
|
|
160
|
+
attributionLayers: ATTRIBUTION_LAYERS,
|
|
161
|
+
rootCauseWorksheet,
|
|
162
|
+
agentMustProduce: "BugAnalysis",
|
|
163
|
+
src8Gate: {
|
|
164
|
+
blockCodeChangeUntilStep: 4,
|
|
165
|
+
blockCountermeasuresUntilRootCauseWorksheetClosed: true,
|
|
166
|
+
implementAtStep: 6,
|
|
167
|
+
rootCauseWorksheetGates: ROOT_CAUSE_WORKSHEET_GATES,
|
|
168
|
+
requireReproductionBeforeImplement: true,
|
|
169
|
+
escalateAfterFailedFixAttempts: 3,
|
|
301
170
|
},
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
"
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
ruledOut: [
|
|
321
|
-
"尚不能直接归因于“纯超时”或“SDK 有 bug”,需要先完成时间线与边界分析",
|
|
322
|
-
"尚不能直接归因于“网络慢”,除非有传输层证据支持",
|
|
323
|
-
],
|
|
324
|
-
commonPattern: "优先比较成功与失败样本,从调用链、状态机、工具执行、文件写入等维度找分叉点。",
|
|
325
|
-
boundary: "待定位;默认优先排查工具执行层、状态机、文件写入层和环境配置层。",
|
|
326
|
-
rootCauseStatement: "待形成 “A + B 在条件 D 下导致 C” 的因果句;在证据闭环前不下最终结论。",
|
|
171
|
+
metadata: { plan },
|
|
172
|
+
bugfixInput: {
|
|
173
|
+
received: true,
|
|
174
|
+
error_message: errorMessage,
|
|
175
|
+
stack_trace: stackTrace || null,
|
|
176
|
+
code_context: hasCodeContext ? codeContext : null,
|
|
177
|
+
file: resolvedCode.file ?? (filePath || null),
|
|
178
|
+
lineCount: hasCodeContext ? codeContext.split("\n").length : 0,
|
|
179
|
+
truncatedInPrompt: hasCodeContext && codeContext.length !== promptCodeContext.length,
|
|
180
|
+
steps_to_reproduce: stepsToReproduce || null,
|
|
181
|
+
expected_behavior: expectedBehavior || null,
|
|
182
|
+
actual_behavior: actualBehavior || null,
|
|
183
|
+
success_sample: successSample || null,
|
|
184
|
+
verification_target: verificationTarget || null,
|
|
185
|
+
hasComparisonSample: hasSuccessSample,
|
|
186
|
+
hasVerificationTarget: Boolean(verificationTarget.trim()),
|
|
187
|
+
analysis_mode: analysisMode,
|
|
188
|
+
affectedFiles,
|
|
327
189
|
evidence,
|
|
328
|
-
|
|
329
|
-
{
|
|
330
|
-
layer: "analysis",
|
|
331
|
-
action: "先补齐现象、时间线、对比样本和边界信息,再进入代码修复",
|
|
332
|
-
risk: "证据不足时过早修复,可能导致重复返工",
|
|
333
|
-
verification: "确认 TBP-7 证据链能解释全部关键现象",
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
layer: "implementation",
|
|
337
|
-
action: "只修改真因所在层,不以“兜底分支”替代根因修复",
|
|
338
|
-
risk: "补症状会掩盖真正失控边界",
|
|
339
|
-
verification: "验证原问题消失且未引入新的回归",
|
|
340
|
-
},
|
|
341
|
-
],
|
|
190
|
+
phenomenon: summarizePhenomenon(errorMessage, expectedBehavior, actualBehavior),
|
|
342
191
|
},
|
|
343
|
-
}
|
|
344
|
-
return okStructured(guide, structuredData, {
|
|
192
|
+
}, {
|
|
345
193
|
schema: (await import("../schemas/output/core-tools.js")).BugAnalysisSchema,
|
|
346
|
-
note: "
|
|
194
|
+
note: "按 metadata.plan 执行 SRC-8;src8-4 闭合前禁止改代码",
|
|
347
195
|
});
|
|
348
196
|
}
|
|
349
197
|
catch (error) {
|