grinding-until-pass

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Grind Until Pass

持续迭代直至通过

Use this skill when you want the agent to keep working autonomously until a specific goal is met — all tests pass, the build succeeds, or linting is clean. Instead of stopping after one attempt, the agent loops until done.
当你希望Agent自主持续工作直至达成特定目标(所有测试通过、构建成功或代码检查无问题)时,使用此技能。Agent不会仅尝试一次就停止,而是循环执行直至完成目标。

Steps

步骤

  1. Define the goal command — the command whose exit code determines success:
    • Tests:
      npm test
      or
      npx vitest run
    • Build:
      npm run build
    • Lint:
      npm run lint
    • Type-check:
      npx tsc --noEmit
    • All of the above:
      npm run lint && npx tsc --noEmit && npm test && npm run build
  2. Run the command — execute it and capture the output.
  3. If it fails — analyze and fix:
    • Read the error output carefully.
    • Identify the root cause: failing test assertion, type error, lint violation, import error, etc.
    • Make the minimal fix. Don't refactor — just fix the error.
    • Go back to step 2.
  4. If it passes — stop and report:
    • Report what was fixed and how many iterations it took.
    • Summarize the changes made.
  1. 定义目标命令 —— 该命令的退出码将决定是否成功:
    • 测试:
      npm test
      npx vitest run
    • 构建:
      npm run build
    • 代码检查:
      npm run lint
    • 类型检查:
      npx tsc --noEmit
    • 以上全部:
      npm run lint && npx tsc --noEmit && npm test && npm run build
  2. 运行命令 —— 执行命令并捕获输出。
  3. 若失败——分析并修复
    • 仔细读取错误输出。
    • 识别根本原因:测试断言失败、类型错误、代码检查违规、导入错误等。
    • 进行最小化修复。不要重构——仅修复错误即可。
    • 返回至步骤2。
  4. 若成功——停止并报告
    • 报告修复内容及迭代次数。
    • 总结所做的更改。

Rules for the Loop

循环规则

  • Maximum 10 iterations — if after 10 attempts the command still fails, stop and report what's blocking progress. Something fundamental is wrong and needs human input.
  • Fix one thing at a time — don't try to fix all errors at once. Fix the first error, re-run, and see if the fix resolves downstream errors too.
  • Don't delete tests — if a test is failing, fix the code to make it pass. Don't modify the test unless the test itself is clearly wrong (testing old behavior that was intentionally changed).
  • Don't suppress errors — don't add
    @ts-ignore
    ,
    eslint-disable
    , or
    any
    types to silence errors. Fix the actual problem.
  • Track progress — if the number of errors is increasing instead of decreasing, stop and reassess the approach.
  • 最多10次迭代 —— 如果经过10次尝试后命令仍失败,停止并报告阻碍进度的问题。此时存在需要人工介入的根本性问题。
  • 一次只修复一个问题 —— 不要尝试一次性修复所有错误。先修复第一个错误,重新运行,查看该修复是否也解决了后续错误。
  • 不要删除测试 —— 如果测试失败,修复代码使其通过。除非测试本身明显有误(测试的是已被有意更改的旧行为),否则不要修改测试。
  • 不要抑制错误 —— 不要添加
    @ts-ignore
    eslint-disable
    any
    类型来掩盖错误。修复实际问题。
  • 跟踪进度 —— 如果错误数量不减反增,停止并重新评估方法。

When to Use This

使用场景

  • After a large refactor that broke multiple tests
  • After upgrading a dependency that introduced type errors
  • After merging a branch with conflicts that need resolution
  • When you want to "just make it green" and trust the agent to grind through it
  • 大型重构导致多个测试失败后
  • 升级依赖引入类型错误后
  • 合并存在冲突的分支后
  • 当你希望“直接让结果达标”并信任Agent自主解决问题时

Advanced: Cursor Hooks Integration

进阶:Cursor Hooks集成

You can automate this with a Cursor hook in
.cursor/hooks.json
that triggers after the agent's turn ends, checks if tests pass, and sends a follow-up message if they don't:
json
{
  "hooks": [
    {
      "event": "stop",
      "command": "bash .cursor/scripts/check-tests.sh",
      "description": "Re-run tests after agent stops and send follow-up if failing"
    }
  ]
}
The script checks the exit code and returns a
followup_message
if tests are still failing.
你可以通过
.cursor/hooks.json
中的Cursor Hook实现自动化,在Agent任务结束后触发,检查测试是否通过,若未通过则发送后续消息:
json
{
  "hooks": [
    {
      "event": "stop",
      "command": "bash .cursor/scripts/check-tests.sh",
      "description": "Re-run tests after agent stops and send follow-up if failing"
    }
  ]
}
该脚本会检查退出码,若测试仍失败则返回
followup_message

Notes

注意事项

  • This works best with fast test suites. If your tests take 5+ minutes, the loop will be slow.
  • Use
    --bail
    or
    --fail-fast
    flags to stop at the first failure for faster iteration.
  • The agent will be thorough but not creative — if the fix requires a design change, it'll need human guidance.
  • 此功能在测试套件运行速度快时效果最佳。如果测试需要5分钟以上,循环执行会很慢。
  • 使用
    --bail
    --fail-fast
    标志在第一个失败点停止,以加快迭代速度。
  • Agent会执行得很彻底但缺乏创造性——如果修复需要设计变更,则需要人工指导。