Files
2026Technology-Competition/docs/superpowers/specs/2026-08-20-custom-rule-suggestion-design.md
范智鹏 d16d680f0f feat: AI 修复链路扩展 + 修复预览两步确认 + 自定义规则/AI 审查条目支持 AI 修复
- AI 修复:无原生 fix 的 linter 条目走 AI 修复(aiFixEngine/fixPrompt,AI 重检收敛),自定义规则与 AI 审查条目新增 AI 修复按钮(customFixEngine),自定义规则条目展开显示 AI 建议(suggestion 字段)

- 修复预览:面板触发修复先用内置 diff 预览,面板内「应用/取消」两步确认后才写入(fixPreview/fixPending,单条与分 tab 批量均支持)

- 修复面板交互:linter/custom/ai 分 tab「全部修复」、已修复+撤销、pending 按钮状态同步

- bug 修复:修复按钮失败后卡  不恢复;custom/ai 修复不稳定(空修复重试、AI 重检收敛判定放宽、降级接受最后一次有效修复)

- 移除 AI codeDiff 展示块
2026-08-20 22:26:30 +08:00

51 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 自定义规则条目展开显示 AI 修复建议功能设计书
> 日期:2026-08-20
> 状态:已批准(Stage ④ 通过)
> 流程:① 用户提出 → ② 需求澄清 → ③ 方案设计 → ④ 人类审批
## 1. 背景与目标
审查面板「自定义规则」(custom tab)条目当前**不可展开**:点击无反应、无 AI 修复建议详情。用户期望自定义规则条目与静态分析(linter)条目一致,展开后显示 AI 给出的修复建议(💡 建议文本)。
## 2. 需求澄清结论(Stage ② 共识)
| 决策项 | 结论 |
|--------|------|
| 实现程度 | 展开显示 AI 修复建议**文本**(💡),不提供 AI 修复改代码按钮 |
| 展示方式 | 复用现有 `buildIssueItem``detail-suggestion` 展开详情 |
| 入口 | 完整审查 + 方法审查两条路径的自定义规则条目 |
## 3. 现状关键点(已核实)
- `CustomRuleResult`schema.ts:8-13)仅含 `ruleId/line/severity/message`,无 `suggestion` 字段。
- 自定义规则 AI promptengine.ts `buildCustomRuleSystemPrompt` 完整审查、`buildMethodSystemPrompt*` 方法审查)输出 JSON 格式均无 `suggestion`
- `merger.ts:92-97` 映射 custom 诊断时未传 `suggestion``LinterDiagnostic.suggestion` 为空。
- `webview.ts:365` `buildIssueItem(..., d.suggestion, false, false)``suggestion` 为空,展开条件 `suggestion && suggestion !== message` 不满足 → 不可展开。
## 4. 方案
### 4.1 `src/ai/schema.ts`
`CustomRuleResult` 增加可选字段 `suggestion?: string`
### 4.2 `src/ai/engine.ts`
- `buildCustomRuleSystemPrompt`(完整审查,zh/en/ja 三段):输出 JSON 格式加 `"suggestion"` 字段,并要求每条违规必须给出可执行的修复建议。
- `buildMethodSystemPromptEn/Zh/Ja`(方法审查):`customRuleResults` 输出段加 `"suggestion"` 字段。
- `runAIReview` / `runMethodReview` 已用 `...r` 展开映射,suggestion 自动透传,无需改动。
### 4.3 `src/merger/merger.ts`
custom 诊断映射补 `suggestion: r.suggestion`
### 4.4 `src/panel/webview.ts`
无需改动——`buildCustomList` 已传 `d.suggestion`suggestion 非空时 `buildIssueItem` 展开条件即满足,复用现有 `detail-suggestion` 渲染。
## 5. 影响面与风险
- **兼容性**`suggestion` 为可选字段,AI 未返回时条目不可展开(与现状一致),零回归。
- **AI 一致性**:仅提示词要求,AI 不保证 100% 返回——有则展开,无则不展开。
- 不新增 i18n;hover 快速修复、AI 修复按钮、两步确认逻辑均不受影响。
## 6. 验证
`lint → compile → test``npm run lint` / `npm run compile` / `npm test`)。