build-fix
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/build-fix
/build-fix
What
概述
The kit's autonomous iteration-loop skill. It drives a broken
(or failing ) to green by looping: run, parse failures,
categorize by root cause, apply targeted fixes, re-run. It repeats until
green or a guard fires — the same way an experienced developer works through
a wall of red, but with hard limits that stop it from thrashing.
dotnet builddotnet testThis is not a single-pass fix. It handles cascading errors where fixing one
issue reveals the next.
本工具包的自动迭代循环技能。它通过循环执行以下步骤将失败的(或失败的)修复至正常状态:运行、解析错误、按根本原因分类、应用针对性修复、重新运行。重复此过程直到状态正常或触发防护机制——这与经验丰富的开发者解决大量错误的方式相同,但有严格限制以避免无效操作。
dotnet builddotnet test这并非单次修复流程。它能处理修复一个问题后暴露下一个问题的连锁错误。
When
适用场景
- The build is broken and there are multiple compiler errors
- Tests are failing after code changes or a build-fix pass
- After a major refactor that touched type names, namespaces, or signatures
- After updating NuGet packages (especially major version bumps)
- After merging a branch with conflicts resolved but not compiled
- After scaffolding or code generation that needs manual adjustments
- User says: "fix the build", "make it compile", "make the tests pass", "keep going until it works", "keep fixing"
- 构建失败且存在多个编译错误
- 代码变更或构建修复后测试失败
- 完成涉及类型名称、命名空间或签名的重大重构后
- 更新NuGet包后(尤其是大版本升级)
- 合并分支并解决冲突但未编译后
- 脚手架或代码生成后需要手动调整时
- 用户说出以下指令时:“修复构建”“让它编译通过”“让测试通过”“一直修复直到正常”“持续修复”
How
工作原理
Loop Discipline (applies to every loop)
循环规则(适用于所有循环)
- Bounded iteration, always — Default max 5 iterations, hard cap 10 (user "keep going" extends by 3, never past 10). If 5 iterations cannot solve it, the problem needs human judgment, not a 6th identical attempt.
- Progress or exit — Each iteration must reduce the error/failure count. Same errors after a fix attempt = STUCK: stop, report, and re-plan with a different approach. Never retry the same fix that already failed.
- Categorize before fixing — Group errors by root cause and fix the
highest-leverage first (one missing can erase a dozen downstream errors).
using - Transparency per iteration — Report what changed and why:
. Never modify files silently.
Iteration 3/5: fixed CS0246 by adding using System.Text.Json, 2 remain - Atomicity — Each iteration leaves the codebase no worse than before. If iteration 3 fails, the code stays in iteration 2's state.
- 始终限制迭代次数 — 默认最多5次迭代,硬上限为10次(用户指令“一直修复”可额外增加3次,但绝不超过10次)。若5次迭代无法解决问题,则该问题需要人工判断,而非第6次重复尝试。
- 有进展才继续,否则退出 — 每次迭代必须减少错误/失败数量。尝试修复后错误无变化=陷入僵局:停止操作、报告情况并改用其他方法重新规划。绝不重复已失败的相同修复方案。
- 先分类再修复 — 按根本原因对错误分组,优先修复影响最大的问题(一个缺失的指令可能消除十几个下游错误)。
using - 每次迭代保持透明 — 报告修改内容及原因:。绝不静默修改文件。
第3/5次迭代:通过添加using System.Text.Json修复CS0246错误,剩余2个错误 - 原子性 — 每次迭代结束后,代码库状态不会比之前更差。若第3次迭代失败,代码将保留第2次迭代后的状态。
Primary Flow: Build-Fix Loop (max 5 iterations)
核心流程:构建修复循环(最多5次迭代)
-
Build — Run, capture full error output
dotnet build -
Parse — Extract everywith file, line, and message
error CS#### -
Categorize — Group by root cause:
Category Codes Fix strategy Missing using/reference CS0246, CS0234 Add using, package, or project ref Type mismatch CS0029, CS1503 Check expected type, cast or convert API change CS0117, CS7036 Check new signature, update call sites Nullability CS8600–CS8604 Add null check, or?.??Ambiguity / duplicate CS0104, CS0121, CS0111 Qualify namespace, remove dupe Missing member CS1061 Check spelling, verify member exists Missing implementation CS0535 Implement interface/abstract members Obsolete API CS0618 Replace with recommended alternative -
Fix — Apply targeted fixes, root-cause/highest-leverage errors first
-
Rebuild — Runagain, compare error count
dotnet build -
Evaluate — Zero errors: runas a sanity check, report success. Fewer errors: continue. Same errors: STUCK — exit and re-plan. More errors: revert the iteration, report REGRESSION.
dotnet test
-
构建 — 运行,捕获完整错误输出
dotnet build -
解析 — 提取所有带文件、行号和消息的错误
error CS#### -
分类 — 按根本原因分组:
分类 错误代码 修复策略 缺失using/引用 CS0246、CS0234 添加using指令、包引用或项目引用 类型不匹配 CS0029、CS1503 检查预期类型,进行强制转换或转换 API变更 CS0117、CS7036 检查新签名,更新调用位置 可空性 CS8600–CS8604 添加空值检查、 或?.运算符??歧义/重复 CS0104、CS0121、CS0111 限定命名空间,移除重复项 缺失成员 CS1061 检查拼写,验证成员是否存在 缺失实现 CS0535 实现接口/抽象成员 过时API CS0618 替换为推荐的替代方案 -
修复 — 应用针对性修复,优先处理根本原因/影响最大的错误
-
重建 — 再次运行,对比错误数量
dotnet build -
评估 — 错误数量为0:运行作为 sanity check,报告成功。错误数量减少:继续循环。错误数量不变:陷入僵局——退出并重新规划。错误数量增加:回滚本次迭代的修改,报告退化。
dotnet test
Variant: Test-Fix Loop (max 5; 3 if it follows a build-fix pass)
变体:测试修复循环(最多5次;若在构建修复流程后执行则最多3次)
Same loop, same guards, with as the runner and one
critical extra step — diagnose before fixing:
dotnet test --no-build- Read the test — understand the assertion and setup
- Read the production code — understand the actual behavior
- Decide where the bug lives: wrong expectation → fix the test; production bug → fix the code; incomplete setup → fix the setup; contract changed → update the test to match
- Never weaken an assertion to make a test pass.
BAD: →
Assert.Equal(expected, actual). GOOD: fix the production code so the original assertion passes.Assert.NotNull(actual)
循环规则相同,安全防护机制相同,但以作为运行器,并增加一个关键步骤——修复前诊断:
dotnet test --no-build- 阅读测试代码——理解断言和设置逻辑
- 阅读生产代码——理解实际行为
- 判断错误位置:预期错误→修复测试;生产代码Bug→修复代码;设置不完整→修复设置;契约变更→更新测试以匹配新契约
- 绝不要通过弱化断言来让测试通过。
错误示例:→
Assert.Equal(expected, actual)。 正确示例:修复生产代码使原始断言通过。Assert.NotNull(actual)
Fail-Safe Guards (immediate exit)
安全防护机制(立即退出)
- STUCK — same errors/failures after a fix, or count oscillates (3 → 2 → 3): report what could not be fixed and what a human should check
- REGRESSION — an iteration introduced more errors than it fixed: revert its changes, report
- Cascading failures — fixing one error spawns 3+ new ones twice in a row: the approach is wrong, stop
- Critical error — wrong SDK, missing project file, corrupted solution, or the test runner itself fails: human intervention needed, stop
- User interruption — finish the current iteration, report progress, ask how to proceed
- 陷入僵局 — 修复后错误/失败数量不变,或数量波动(3→2→3):报告无法修复的问题及人工需检查的内容
- 退化 — 某次迭代引入的错误比修复的更多:回滚本次修改,报告情况
- 连锁失败 — 修复一个错误连续两次引发3个以上新错误:当前方法有误,停止操作
- 严重错误 — SDK版本错误、项目文件缺失、解决方案损坏或测试运行器本身失败:需人工干预,停止操作
- 用户中断 — 完成当前迭代,报告进度,询问后续操作
Other Loops
其他循环
The same discipline — bounded iterations, progress detection, fail-safe
guards — governs refactor passes (: verify build + tests after
each target, revert on failure) and scaffolding (: generate, then
run nested build-fix and test-fix loops). Nested loops get a smaller budget
(parent 5 → nested 3), max nesting depth 2, total budget 15.
/de-sloppify/scaffold相同规则——有限迭代、进度检测、安全防护机制——适用于重构流程(:每次目标修改后验证构建+测试,失败则回滚)和脚手架流程(:生成代码后,运行嵌套的构建修复和测试修复循环)。嵌套循环的迭代次数更少(父循环5次→子循环3次),最大嵌套深度为2,总迭代次数上限为15次。
/de-sloppify/scaffoldInvokes
调用对象
| Type | Name | Purpose |
|---|---|---|
| Skill | | Capture fix patterns in MEMORY.md |
| Agent | | Consulted for architectural error patterns |
| 类型 | 名称 | 用途 |
|---|---|---|
| Skill | | 在MEMORY.md中记录修复模式 |
| Agent | | 咨询架构相关错误模式 |
MCP Tools Used
使用的MCP工具
- — Compiler errors/warnings scoped to file or project
get_diagnostics - — Locate moved or renamed types
find_symbol - — Assess blast radius of a broken API change
find_references - — Dependency order for fixing reference errors
get_project_graph
- — 限定在文件或项目范围内的编译器错误/警告
get_diagnostics - — 定位移动或重命名的类型
find_symbol - — 评估API变更的影响范围
find_references - — 修复引用错误的依赖顺序
get_project_graph
Example
示例
User: /build-fix
Claude: Running dotnet build...
Found 12 errors across 4 files.
Iteration 1/5:
- 6 errors: Missing namespace (CS0246) — adding using directives
- 3 errors: Type mismatch (CS1503) — updating method signatures
- 3 errors: Interface not implemented (CS0738) — package API changed
Rebuilding... 3 errors remaining.
Iteration 2/5:
- 3 errors: CS0738 after xunit.v3 upgrade
- IAsyncLifetime.InitializeAsync now returns ValueTask (was Task in v2),
and DisposeAsync comes from IAsyncDisposable
- Updating 3 test fixtures to the ValueTask signatures
Rebuilding... 0 errors. Build is green.
Running dotnet test... All 47 tests passed.
Added to Memory > Packages: "xunit.v3 IAsyncLifetime uses ValueTask signatures"User: /build-fix
Claude: 正在运行dotnet build...
在4个文件中发现12个错误。
第1/5次迭代:
- 6个错误:缺失命名空间(CS0246)——添加using指令
- 3个错误:类型不匹配(CS1503)——更新方法签名
- 3个错误:未实现接口(CS0738)——包API已变更
正在重建... 剩余3个错误。
第2/5次迭代:
- 3个错误:xunit.v3升级后的CS0738错误
- IAsyncLifetime.InitializeAsync现在返回ValueTask(v2中为Task),且DisposeAsync来自IAsyncDisposable
- 将3个测试夹具更新为ValueTask签名
正在重建... 0个错误。构建已正常。
正在运行dotnet test... 全部47个测试通过。
已添加至Memory > Packages:"xunit.v3 IAsyncLifetime使用ValueTask签名"Related
相关功能
- — Full verification pass (build + test + format + diagnostics)
/verify - — Red-green-refactor when building new features test-first
/tdd - — Clean up code quality issues after the build is green
/de-sloppify
- — 完整验证流程(构建+测试+格式化+诊断)
/verify - — 测试优先构建新功能时的红-绿-重构流程
/tdd - — 构建正常后清理代码质量问题
/de-sloppify