协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
audit-fix-loop【开发与工程】Use this skill when the user asks to "audit and fix", "review and fix all issues", "keep fixing until clean", "iterative fix cycle", or wants a thorough multi-round code quality pass. Runs code-reviewer audits and parallel fix agents in a loop until no high-confidence issues remain. Each round includes unit test + integration/e2e test authoring for f…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Iteratively audit, fix, test, and document code issues until the codebase is clean. Each round narrows scope — fixes from prior rounds can introduce new issues, so loop until convergence.
v2 additions over v1: Each round now includes test authoring (unit + integration/e2e) for every fix and incremental doc updates. Testing and docs are woven into the loop, not deferred to a final pass.
Round N:
1. Audit — parallel reviewer agents, one per layer/domain
2. Merge — deduplicate cross-layer issues
3. Fix — parallel fix agents, one per layer
4. Test — parallel test-authoring agents: unit tests + integration/e2e tests
5. Docs — incremental doc update for changed code
6. Verify — build → typecheck → lint → unit tests → integ tests → security → diff
7. Repeat — scope next round to changed files, or DONE
Every issue surfaced at confidence ≥80 gets fixed. Severity (CRITICAL / IMPORTANT / MINOR) controls how the fix is dispatched, NOT whether it happens.
If the audit thought it was worth flagging, the loop owes it a fix. "Defer as MINOR follow-up" is an anti-pattern — it's how PRs accumulate the long-tail rot the audit was supposed to clean up. Never skip a flagged issue based on severity alone.
Pick by cost to main thread, not by severity:
| Route to | When (any one trigger) |
|---|---|
| Inline (main thread) — Edit/MultiEdit + verify + commit | Touches ≤2 files · mechanical change (rename, add type, remove dead code, fix typo, add missing import) · well-understood domain · ≤500 lines of code to read for the fix · no new test scaffolding needed |
Opus subagent — spawn feature-dev:code-reviewer (for review-driven fixes) or a task-scoped fix agent | Touches 3+ files · requires deep refactor (architecture change, new abstraction) · unfamiliar domain (new lib, new pattern) · 500+ lines of context to load · touches concurrency / race / security / payment / auth / data-mutation logic (regardless of size — these always go to opus for the extra reasoning budget) · requires new test scaffolding for fixed behavior |
Subagent contract (compress every fix to ≤200 tokens of return value):
{
"issue_id": "<from REVIEW.md>",
"status": "FIXED" | "BLOCKED" | "DEFERRED-NEEDS-DECISION",
"files_touched": ["<paths>"],
"summary": "<≤2 sentences: what was changed and why>",
"verification": { "build": "PASS", "tests": "PASS|FAIL", "lint": "PASS" }
}
Main thread aggregates these, never sees raw fix output. This is what keeps long autonomous runs from blowing context on cosmetic refactors.
Only valid reason to NOT fix an issue immediately: the fix requires a Critical Decision (DB choice / auth boundary / breaking API / spec ambiguity) — escalate per big-task Phase -1. Then return DEFERRED-NEEDS-DECISION with the question. Tedium is not a valid reason.
Split the codebase by layer/domain and spawn one feature-dev:code-reviewer agent per slice in parallel (all in the same message):
| Agent | Scope |
|---|---|
| server-reviewer | apps/server/, packages/shared/ |
| client-reviewer | apps/mobile/, apps/web/ |
| infra-reviewer | scripts/, config files, CI |
Adapt slices to the actual project structure. Use claude-opus-4-6 for all reviewers.
Each reviewer:
After all reviewers return, merge results and deduplicate any cross-layer issues.
Group merged issues by the same layer slices. Spawn fix agents in parallel (all in the same message), one per layer:
claude-opus-4-6 for complex logic/race condition fixesclaude-sonnet-4-6 for style, dead code, console.log cleanupAfter fixes complete, spawn parallel test-authoring agents — one for unit tests, one for integration/e2e tests:
Spawn a tdd-guide agent (or go-reviewer/python-reviewer for Go/Python projects):
*.test.ts, *_test.go, test_*.py)Spawn an e2e-runner agent (or appropriate test agent for the stack):
tests/integration/, tests/e2e/, or project conventionSpawn a docs-agent (claude-sonnet-4-6) scoped to files changed in Steps 2-3:
// TODO references that are now resolvedAfter fixes + tests + docs, run the full verification chain. Stop at the first failure and fix before continuing.
# 1. Build
npm run build # or mvn compile / ./gradlew build / go build ./...
# 2. Type check
npx tsc --noEmit # or pyright . / mvn compile / go vet ./...
# 3. Lint
npm run lint # or ruff check . / ./gradlew spotlessCheck / golangci-lint run
# 4. Unit tests (with coverage)
npm run test -- --coverage # or pytest --cov / go test -cover ./...
# 5. Integration tests
npm run test:integration # or pytest tests/integration/ / go test -tags=integration ./...
# 6. E2E tests (if applicable and available)
npm run test:e2e # or npx playwright test / pytest tests/e2e/
# 7. Security scan
grep -rn "sk-\|api_key\|console\.log" --include="*.ts" --include="*.js" src/ 2>/dev/null | head -10
# 8. Diff review
git diff --stat
Produce a verification summary:
Build: [PASS/FAIL]
Types: [PASS/FAIL]
Lint: [PASS/FAIL]
Unit Tests: [PASS/FAIL] (X/Y passed, Z% coverage → target 80%+)
Integ Tests: [PASS/FAIL] (X/Y passed)
E2E Tests: [PASS/FAIL/SKIP] (X/Y passed)
Security: [PASS/FAIL]
Docs: [UPDATED/SKIPPED] (X files)
If any phase fails, fix errors before starting the next round. Test failures from newly authored tests are expected — fix the code or the test, don't delete the test.
Start next round scoped to files modified in the previous round (including new test files).
Loop terminates when:
Spawn three parallel agents:
docs/ and inline comments for anything outdated by the fixes just applied// TODO references that are now resolvedFinds and handles stray files:
.sh, .py, .ts files in project root or wrong dirs
scripts/<topic>/ or delete if truly disposabletest-something.ts, debug-*.js, try-*.py)
scripts/scratch/ if potentially useful, delete if clearly disposable.md, .txt files in project root that aren't config (e.g., NOTES.md, TODO.txt, analysis.md)
docs/<topic>/ with a meaningful nameReport every move/delete before executing. If unsure whether to delete, move to scripts/scratch/ or docs/archive/ instead.
Run final verification to confirm housekeeping didn't break anything:
npm run typecheck && npm run test && npm run test:integration
Keep a running tally visible to the user:
Round 1: 6 CRITICAL, 8 IMPORTANT, 2 MINOR → fixing → +12 unit tests, +3 integ tests, 4 docs updated
Round 2: 0 CRITICAL, 4 IMPORTANT, 1 MINOR → fixing → +5 unit tests, +1 integ test, 2 docs updated
Round 3: 0 CRITICAL, 0 IMPORTANT, 2 MINOR → DONE (minor issues skipped)
TOTALS: 17 unit tests added, 4 integration tests added, 6 docs updated
Coverage: 62% → 84% (+22%)
| Fix type | Unit test? | Integration test? | E2E test? |
|---|---|---|---|
| Logic bug in pure function | Yes (3+ cases) | No | No |
| API endpoint fix | Yes (handler) | Yes (HTTP roundtrip) | Maybe (if critical flow) |
| Database query fix | Yes (query builder) | Yes (real DB) | No |
| Auth/permission fix | Yes (guard logic) | Yes (full auth flow) | Yes (login flow) |
| UI component fix | Yes (render + events) | No | Yes (user interaction) |
| Config/env fix | Yes (config parsing) | Yes (startup with config) | No |
| Race condition fix | Yes (concurrent scenarios) | Yes (under load) | No |
| Style/formatting only | No | No | No |
The loop converges because each round:
Typically converges in 3-5 rounds for large changesets, 1-2 for focused fixes.