Rereview loop

From drn/dots · View interactive version

Rereview loop is an AI agent skill from the GitHub repository drn/dots. Iteratively run /rereview, fix the findings, and loop until reviewers approve clean. Use for iterative automated review, when you want /rereview to loop until clean, or for a paranoid pre-merge review that auto-addresses every blocker.

How to use this skill

Skill file

Re-Review Loop

Run /rereview repeatedly: review → fix the findings → re-review → repeat. Stop when all three reviewers approve with zero BLOCKING and zero WARNING findings, when the iteration cap is hit, or when an iteration makes no progress.

Arguments

Context

Overview

You are the lead coordinator for an iterative re-review loop. Your job is to drive findings to zero by alternating between review (delegated to /rereview) and fixes (applied here).

Core principle: trust the reviewers. Fix what they flag, do not argue with the verdict to escape the loop. The loop exits when reviewers say it's clean -- not when you decide it's clean.

Hard rules:


Phase 0: Parse arguments and initialize state

Parse $ARGUMENTS:

max_iterations = 5             (override with max=<N>)
severity_filter = "blocking+warning"   (override with severity=blocking | severity=all)
rereview_scope = ""            (any non-key=value token; passed to /rereview verbatim)
iteration = 0
prior_blocking_count = -1      (B count from previous iteration; -1 = no prior)
prior_warning_count = -1       (W count from previous iteration; -1 = no prior)
prior_info_count = -1          (I count from previous iteration; -1 = no prior)
last_iteration_committed = false   (did the previous iteration produce a commit?)
total_pushbacks = 0            (cumulative judgment-call pushbacks across all iterations)
total_verified_false_positives = 0   (cumulative findings disproven by an actually-executed command, not judgment)
total_findings_addressed = 0   (cumulative findings touched, for the pushback rate)
push_each_iteration = false    (override with push)
accepted_limits = []           (running list of accepted limits and pushed-back findings, with file:line and one-line rationale)
stashed = false                (set true if Phase 0 stashes unrelated work)

Preflight:

  1. Detached HEAD guard. Run git symbolic-ref --short HEAD (or git branch --show-current). If empty, exit immediately: "Cannot run /rereview-loop in detached HEAD state -- check out a named branch first." Do not proceed.
  1. No-changes guard. If there are no commits ahead of the base branch and no uncommitted changes, tell the user "Nothing to re-review -- branch has no changes vs base." and stop.
  1. Stash unrelated work. If git status --short shows uncommitted changes that are NOT part of the work being reviewed (i.e., the user has unrelated dirty files), run git stash push -u -m "rereview-loop pre-loop" and set stashed = true. Tell the user you stashed. The stash MUST be popped on every exit path -- see Phase 4 and the failure-handling table.

Announce the run:

## Re-review loop starting

**Scope:** {rereview_scope or "current branch vs default"}
**Max iterations:** {max_iterations}
**Auto-fix severity:** {severity_filter}

Phase 1: Run /rereview

Invoke the /rereview skill via the Skill tool, passing rereview_scope as its argument (empty string if no scope was given). Pass the current accepted_limits list along (state it in the invocation so /rereview includes it in the reviewer briefing under ACCEPTED LIMITS); without it reviewers re-flag settled items every round. Wait for it to complete and capture the full final report.

/rereview will:

  1. Gather all changed files and dependents
  2. Run the test + lint baseline
  3. Launch 3 independent reviewers in parallel
  4. Synthesize a final verdict

You will receive a markdown report with: a final verdict, a per-reviewer agreement table, and consolidated lists of Blocking Issues, Warnings, Suggestions, Disagreements, and Missing Test Coverage.

If /rereview reports "no changes to review," the loop is trivially clean -- exit with the success summary in Phase 4.


Phase 2: Decide whether to exit

Read the final verdict and the agreement table. Record this iteration's B (blocking), W (warning), and I (info) counts from the consolidated report.

The exit condition depends on severity_filter:

| severity_filter | "Clean" means |

|-----------------------|------------------------|

| blocking | B == 0 |

| blocking+warning | B == 0 AND W == 0 |

| all | B == 0 AND W == 0 AND I == 0 |

IF this iteration's counts meet the "clean" condition for severity_filter:
  → EXIT. Go to Phase 4 with status = CLEAN.
  (If severity_filter == "blocking" and W > 0, status = APPROVED_WITH_WARNINGS_IGNORED.)

IF iteration >= max_iterations:
  → EXIT (cap hit). Go to Phase 4 with status = MAX_ITERATIONS.

OTHERWISE:
  → Continue to Phase 3 to address findings.

Cap semantics. iteration counts completed fix rounds, and Phase 1 reviews before every check. With max=N the loop runs at most N fix rounds and therefore at most N+1 reviews: the cap check fires only after a review, so every fix round is always followed by a review. When the cap fires, that final review's findings are reported but not fixed. State this plainly in Phase 4 (for example: "cap hit after N fix rounds; the final review's M findings were not addressed").

Stuck-state detection

After Phase 3 commits the iteration's fixes, the next iteration's Phase 2 must check whether progress was actually made. Use a hard counter, not a paraphrased-text signature:

IF iteration > 0 AND last_iteration_committed == true AND
   B >= prior_blocking_count AND
   W >= prior_warning_count AND
   I >= prior_info_count:
  → Apparent no-progress. The fix did not reduce the finding counts.
    Re-read the report carefully:
      - If the SAME items are flagged at the SAME file:line, try a
        different approach to those specific findings in this iteration.
      - If this is the second consecutive iteration with no progress,
        EXIT with status = STUCK after applying best-effort fixes once more.

    **Second-order findings are progress.** New findings caused by the
    previous fix (a fix surfaces a follow-on issue at a different file:line
    or a different aspect of the same code) count as progress even when the
    B/W/I counts do not fall. Only treat the loop as stuck when the SAME
    findings recur at the same location after a fix attempt. Note
    second-order findings in the heartbeat as "new, caused by iter {N} fix".

    A finding resolved as a **verified false positive** (Phase 3(b)) counts as
    genuine progress even though no code changed. Note it explicitly as
    "resolved via verification" in the heartbeat so it does not read as an
    unaddressed repeat finding if a later reviewer re-flags the same code
    with different wording -- that re-flag should be checked against the
    same verification evidence, not treated as a fresh unconfirmed claim.

IF iteration > 0 AND last_iteration_committed == false:
  → The previous iteration applied no fixes (everything was pushed back
    or deferred). Counts may legitimately be unchanged. Do NOT treat as
    stuck on this basis alone -- continue with the loop.

Save the current B/W/I counts as prior_blocking_count, prior_warning_count, prior_info_count for the next iteration's comparison. Reset last_iteration_committed to false -- Phase 3 sets it back to true if a commit lands.


Phase 3: Address findings

Build the worklist from the consolidated report based on severity_filter:

| severity_filter | Includes |

|-----------------------|-----------------------------------|

| blocking | BLOCKING only |

| blocking+warning | BLOCKING + WARNING (default) |

| all | BLOCKING + WARNING + INFO |

Always include items in this order: BLOCKING first, then WARNING, then INFO. Within a tier, group by file so related fixes can share a single read of that file.

For each finding:

  1. Read the cited file fully (and any caller/dependent the reviewers referenced). Do not work from the snippet alone.
  1. Classify the finding into one of three buckets:

Distinguish two kinds of pushback:

Track judgment-call pushbacks at two levels:

Count each distinct finding once. Keep a record of every judgment-call pushback and every deferral with its justification. When a later reviewer re-flags the same issue, even reworded, check it against that record: if nothing new was raised, reuse the recorded response and do NOT increment total_pushbacks or total_findings_addressed again. Only a genuinely new argument or evidence makes it a new finding. This mirrors the verified-false-positive re-flag rule in Phase 2.

Pushing back on a quarter of an independent panel's findings -- in any single iteration or cumulatively -- usually means you're rationalizing rather than reviewing. Verified false positives do not count toward this ceiling because they are proven with a command's real output, not argued.

  1. After all findings in this iteration are processed:
  1. Commit the iteration's fixes as a single commit per iteration. List the changed paths explicitly -- never use git add -A (the Phase 0 stash already moved unrelated work aside, but explicit paths are still the safe default):

```

git add path/to/changed-file-1 path/to/changed-file-2 ...

git commit -m "rereview-loop iter {N}: address {M} findings

{bulleted list of finding summaries with file:line, prefixed by [BLOCKING] / [WARNING] / [INFO]}"

```

Set last_iteration_committed = true once the commit succeeds. If push_each_iteration is true, run git push -u origin HEAD now (never a bare git push). If no findings led to code changes in this iteration (everything was pushed back or deferred), do NOT create an empty commit -- leave last_iteration_committed = false.

  1. Heartbeat. Output the per-iteration summary defined below before looping back.
  1. Increment iteration. Loop back to Phase 1.

Iteration heartbeat (output at end of every Phase 3 cycle)

## Iteration {N} complete

**Verdict from /rereview:** {verdict}
**Findings this iteration:** {B} blocking, {W} warning, {I} info
**Applied fixes:** {count}
**Verified false positives:** {count} (disproven by an actually-executed command, see summary for evidence)
**Pushed back:** {count} this iteration, {total_pushbacks} cumulative ({rate}% of {total_findings_addressed})
**Deferred:** {count}
**Tests after fixes:** {PASS / FAIL}
**Lint after fixes:** {CLEAN / WARNINGS / ERRORS}

Next: running /rereview again (iteration {N+1} of {max_iterations}).

If there are pushback or deferred items, list them under the heartbeat with file:line + one-sentence reason.

What NOT to do in Phase 3


Phase 4: Final report

Stash pop guard. Every exit path (CLEAN, APPROVED_WITH_WARNINGS_IGNORED, MAX_ITERATIONS, STUCK, ERROR, and any early exit from Phase 0 after the stash was pushed) MUST run git stash pop if stashed == true before printing the final report. The user's unrelated work-in-progress is not the loop's to discard.

If the stash pop reports conflicts, surface them to the user verbatim and stop -- do NOT attempt to resolve unrelated conflicts.

When the loop exits, output:

# Re-review loop finished

**Status:** {CLEAN / APPROVED_WITH_WARNINGS_IGNORED / MAX_ITERATIONS / STUCK}
**Iterations run:** {N} of {max_iterations}
**Total findings addressed:** {count} (B: {x}, W: {y}, I: {z})
**Total verified false positives:** {count} (disproven by real command output, not judgment)
**Total findings pushed back:** {count} (judgment calls; excludes verified false positives)
**Total findings deferred:** {count}
**Final verdict from /rereview:** {verdict}
**Final regression risk:** {LOW / MEDIUM / HIGH}

## Commits added by this loop
{git log --oneline of commits made during the loop}

## Outstanding items (deferred or pushed back)
{numbered list, or "None."}

## Accepted limits fed to reviewers
{the accepted_limits list, or "None."}

## Recommendation
{One of:
  - "Clean — safe to push and merge." (if `push` was passed: "Clean — already pushed; safe to merge.")
  - "Warnings remain (ignored per `severity=blocking`). Review the warnings list before merging."
  - "Iteration cap hit with findings still open. Re-run /rereview-loop, raise max=, or address remaining items manually."
  - "Loop is stuck — reviewers re-flagged the same findings after a fix attempt. Manual investigation needed."}

Do NOT push the branch unless push was passed or the user asked for it (use git push -u origin HEAD). Do NOT open a PR. The loop's job is to drive findings to zero; merging is the user's decision.


Failure handling

| Failure | Action |

|---------|--------|

| /rereview errors out or returns no report | Retry once. If still failing, exit with status = ERROR and surface the message. |

| Test suite breaks mid-loop and you can't fix it | Stop. Do NOT commit broken tests. Report the failing test and last attempted fix. |

| A finding is unclear or contradictory across reviewers | Apply the most conservative interpretation. Note the ambiguity in the iteration heartbeat. |

| Same findings re-appear after a fix attempt (stuck) | One more attempt with a different approach, then exit with status = STUCK and surface the diff of the failed fix. |

| Reviewers disagree sharply (e.g., one APPROVE, one REJECT) | Trust the strictest. Address the REJECT findings in this iteration. |

| User has uncommitted unrelated changes | Stash them up front in Phase 0 (git stash push -u -m "rereview-loop pre-loop") and pop on every exit path -- see Phase 4's stash-pop guard. |


Design notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.