Community程式設計與開發github.com

audit-loop

Evidence-backed, anti-reward-hacking multi-round independent subagent code review and fix loop. Use when the user asks to run independent subagent reviews, iteratively audit and fix code until convergence (zero issues / zero high+medium), run multi-track frontend+backend or adversarial audits, resume an interrupted review loop, or orchestrate automated review-fix-reaudit workflows before committing or releasing.

audit-loop 是什麼?

audit-loop is a Gemini CLI agent skill that evidence-backed, anti-reward-hacking multi-round independent subagent code review and fix loop. Use when the user asks to run independent subagent reviews, iteratively audit and fix code until convergence (zero issues / zero high+medium), run multi-track frontend+backend or adversarial audits, resume an interrupted review loop, or orchestrate automated review-fix-reaudit workflows before committing or releasing.

相容平台~Claude Code~Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/lelouch0823/audit-loop-skill/tree/HEAD

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Audit-Loop: Multi-Round Independent Review & Fix Workflow

A high-controllability closed-loop engineering audit skill: sizes depth by consequence, binds every audit round to a SHA-256 source snapshot, dispatches independent read-only auditors, filters false positives before editing, guards against gate-weakening/zero-run-green hacks, freezes converged tracks, and reports honest coverage limits.

1. Configuration Precedence & Knobs

Resolve parameters in strict order: 1) Explicit user instructions in chat > 2) Project .agents/audit-loop.json (or .agent/audit-loop.json) > 3) Defaults below.

KnobValuesDefault
scopeuncommitted | branch | branch:<base> | commit:<spec> | paths (--scope paths --paths ...)uncommitted
depthauto (consequence & exec-line routed) | lite | standard | deepauto
tracksAuto-split by directory/stack (with auto-sharding on large tracks)Auto-detected
stop_policyzero_high_medium (0H/0M, report Low) | zero_all (0H/0M/0L) | zero_highzero_high_medium
max_roundsPositive integer fuse per track (lite auto-caps at 2)6
auditor_policyfresh_per_round | verify_then_fresh | adversarial_panelfresh_per_round
auditor_modelinherit | flash | pro (optional final_auditor_model override)inherit
verify_findingsauto (FP-check High, conf <= 7, or adversarial) | always | offauto
gate_integritytrue (run RH-1..RH-16 diff scan + PL-2 zero-run-green check) | falsetrue
fixer_policycoordinator (parent fixes directly) | persistent_subagent (reused via send_message)coordinator
fix_policyauto_fix | ask_before_fix | audit_onlyauto_fix
engineinteractive (invoke_subagent, hot-controllable) | workflow (run_workflow batch)interactive
funnel_after_roundBroad full-diff audit through round K, then tighten to last-round hunks + callers (0 disables)2
churn_limit / repeat_finding_limitPause on file edited >= 3 rounds (PAUSED_CHURN) or same finding surviving >= 2 fixes (PAUSED_REPEAT)3 / 2
on_convergedreport_only | local_commit | bump_commit_buildreport_only

Read references/project-config.md for .agents/audit-loop.json details and presets.


2. Closed-Loop Execution Procedure

Step 1: Collect Scope, Risk Tier, Guidelines & Snapshot

Run the scope collector and bind a deterministic SHA-256 snapshot first:

python3 ~/.gemini/config/skills/audit-loop/scripts/collect_scope.py --scope uncommitted --json
python3 ~/.gemini/config/skills/audit-loop/scripts/gate_integrity.py snapshot --scope uncommitted --out <artifactDir>/scratch/snapshot_r1.json
  • Pass --scope branch, --scope commit:<ref>, --scope paths --paths <p1> <p2> (or --paths as a filter on git scopes), or --config <path> to match the request.
  • If total_files == 0, stop immediately and report an empty scope.
  • Respect risk_summary.recommended_depth: tiny/docs-only (lite) changes need at most 1–2 lean passes without heavy ceremony; HIGH-risk changes (auth, crypto, payments, migrations, CI, deleted executable files, or >= 200 non-test exec lines) use deep with adversarial + silent_failure lenses.
  • Summarize active tracks, risk tier, effective depth, discovered scoped guidelines, verification gates, and knobs in 1–2 concise sentences before dispatching Round 1.

Step 2: Initialize or Resume the Audit Ledger

Maintain a persistent ledger at <artifactDir>/audit_ledger.md (NEVER inside the git workspace). Follow references/ledger-and-resume.md:

  • If resuming after compaction, 429 quota interruption, or restart, read the ledger, run gate_integrity.py diff-snapshots to check for external file drift, and resume from the last incomplete round instead of restarting from Round 1.
  • Track per-track state, snapshot_id, round history, ground-truth file churn, Won't-Fix, Rejected False Positives, and Unverified Items.

Step 3: Dispatch Independent Read-Only Auditors

  • Default (engine: interactive):
    • Read references/auditor-prompts.md and compose one focused prompt per unfrozen track (if recommended_sharding is true on a broad round, fan out across track.shards; if auditor_policy: adversarial_panel on Round 1, dispatch orthogonal core + adversarial lanes in parallel).
    • Launch all active jobs in parallel via invoke_subagent(TypeName="research", Model=auditor_model, ...).
    • Inject five mandatory blocks into every auditor prompt:
      1. Exact diff_meta.commands, file_list, deleted_files, and discovered scoped guidelines + extra_rules.
      2. Objective requirements/intent (NEVER author self-justifications like "I already verified this works").
      3. Evidence & Confidence Gate: verbatim code quote (evidence), confidence (1–10), concrete consequence, autofix_class (gated_auto/manual/advisory), PRE_EXISTING isolation, and unverified_items bucket.
      4. Funnel & Re-Verification Etiquette (Round 2+): isolate per-track prior fixes; instruct auditors to re-reproduce original defects AND attack the fix itself; tighten scope to prior-round hunks + callers on rounds > funnel_after_round.
      5. Settled Won't-Fix + Rejected False Positives table so decided/disproven items are never re-raised.
    • Stop calling tools and wait reactively for subagent messages (never poll).
  • Batch / Fan-out (engine: workflow):
    • Use when the user asks for automated workflow orchestration, multi-perspective fan-out, or unattended /goal runs.
    • Execute scripts/audit_workflow.py via run_workflow(ScriptPath="/Users/.../.gemini/config/skills/audit-loop/scripts/audit_workflow.py", Args={...}, Description="...").

Step 4: Freshness Check, Cross-Check Synthesis, FP-Check & Safety Fuses

Read references/triage-and-verification.md when triaging findings:

  1. Snapshot Freshness & Three Verdicts: Verify the working tree still matches snapshot_id. Any auditor crash, timeout, 429, malformed output, source mutation, or snapshot drift (STALE_REVIEW) yields UNVERIFIED — NEVER treat UNVERIFIED as ZERO_ISSUES and NEVER count it toward stall fuses.
  2. Cross-Check Synthesis: Demote unquotable or confidence <= 5 claims to unverified_items; trace consequence-chain compounding when multiple findings hit the same module; grade by concrete consequence rather than mechanism.
  3. Independent FP-Check (verify_findings): Under auto, verify High, confidence <= 7, or adversarial blockers before editing (under always, verify all blockers). Record confirmed false positives in Rejected False Positives with exact source evidence.
  4. Convergence & Six Safety Fuses: Exclude PRE_EXISTING and unverified_items, evaluate remaining findings against stop_policy:
    • Immediately mark any converged track FROZEN.
    • Trip fuses in strict precedence order: PAUSED_REPEAT (same finding survives >= 2 consecutive fix rounds) > PAUSED_DECISION (autofix_class: manual / architectural arbitration) > PAUSED_CHURN (ground-truth file modified >= churn_limit rounds) > PAUSED_FUSE (non-decreasing blockers for oscillation_limit valid rounds or ping-pong) > PAUSED_BUDGET (round >= max_rounds).

Step 5: Skeptical Triage, Minimal Fix, Gate Integrity & Hard Gates

  • audit_only: Do not edit files. Update ledger and output the honest coverage report.
  • ask_before_fix: Present numbered findings (with confidence & autofix_class) and wait for user selection before editing.
  • auto_fix:
    • Fixer Continuity: Keep the fixer stateful (coordinator or one reused persistent_subagent via send_message) so prior invariants are never lost while auditors stay fresh.
    • Anti-Sycophancy Skeptical Triage: Verify every gated_auto finding against actual codebase/platform/YAGNI constraints before editing; push back with source evidence into Rejected False Positives instead of applying harmful compliance hacks. Never guess on manual items.
    • Sibling-Sweep + Minimal Blast Radius + Bidirectional Regression Lock: Eliminate symmetric call-site/enum bug classes in one round without unrelated refactors; add positive + negative invariant tests for every High/Medium fix.
    • Objective Diff & Gate-Integrity Scan (gate_integrity: true):
      1. Run gate_integrity.py diff-snapshots --before <prev_snap> --cwd <repo> to obtain the ground-truth touched files for file_churn, funnel_mode, and Cross-Track Thaw (thaw any FROZEN track whose files were touched).
      2. Run gate_integrity.py scan-diff --cwd <repo> --paths <touched_files>. Any unjustified RH-1..RH-16 hit (skipped/deleted tests, suppression pragmas, placeholders, swallowed catches, relaxed assertions) trips PAUSED_GATE_INTEGRITY.
      3. Run all verification gates for modified tracks and verify real test execution (guard against PL-2 Zero-Run Green via gate_integrity.py check-test-output).
    • Hard Gate Rule: Never launch Round N+1 while any gate is red or gate-integrity is flagged. Save the new round snapshot, update <artifactDir>/audit_ledger.md, and return to Step 3.

Step 6: Mid-Flight Hot Controls

Honor natural-language overrides immediately at any turn and persist them in <artifactDir>/audit_ledger.md:

  • Waive / dispute (忽略 #3,理由:... / #2 是误报,因为...): Record in Won't-Fix or Rejected False Positives; re-evaluate convergence immediately.
  • Adjust knobs (切到 zero_all / Low 不修了 / 关闭 fp-check / 冻结 frontend / 重审 backend / 再加 3 轮 / 只审不改 / 立刻收尾): Apply immediately.

Step 7: Honest Closeout & Absolute Redlines

Once all tracks are FROZEN (or user closes early):

  1. Verify final snapshot matches the last verified audit/gates; if any post-convergence edit occurred, re-run full gates.
  2. Execute on_converged (report_only | local_commit | bump_commit_build) and deliver the Honest Coverage & Final Summary from references/ledger-and-resume.md (explicitly naming checked scope, fixed totals, rejected FPs, real gate test counts, coverage gaps, and remaining unverified_items/deferred debt).
  3. Absolute Redlines:
    • NEVER run git push, create/push tags, open/modify PRs, or deploy/restart live services without explicit user confirmation.
    • NEVER weaken tests, assertions, linters, or design gates to force convergence.
    • NEVER commit <artifactDir>/audit_ledger.md, snapshot JSONs, or scratch artifacts into the repository.

相關技能