Post-Merge Cleanup
Audit and clean up the diff from the last N commits. Catches dead code,
unused imports, stale comments, and obvious duplicates that slipped in
during rapid development.
Configuration
Reads .rig/config.json:
sourceScope[0] — the default directory to audit when no scope is
given (default: src).
test.command — the suite run in the verify step (default: npm test).
agents.reviewer — the project's name for the canonical reviewer
role (default: reviewer).
If the file is absent, use the defaults above and note you're running
unconfigured.
Arguments
The user invoked this with: $ARGUMENTS
What to do
Parse the arguments.
- scope: directory to audit (default: the default source scope from
.rig/config.json (sourceScope[0], default src)).
- commits: number of recent commits to review (default:
10)
Examples:
/rig-tidy → default scope, 10 commits
/rig-tidy path/to/dir 5 → that directory, 5 commits
/rig-tidy 20 → default scope, 20 commits
Show what will be audited.
git log --oneline -${commits}
git diff HEAD~${commits} --stat -- ${scope} | tail -20
Audit the diff via a fresh-context subagent. Spawn a reviewer
agent (mapped through agents.reviewer) with this prompt (don't do the
audit inline — the implementer context is too close to the code to spot
dead-on-arrival abstractions):
"Audit the diff git diff HEAD~${commits} -- ${scope} for
cleanup candidates. Categories: (a) dead code — exported symbols
with no callers in the tree, internal helpers used once; (b)
unused imports; (c) stale comments — TODOs completed by the diff,
comments describing prior behavior, doc lines that no longer
match the code; (d) duplicates — near-identical helpers, repeated
inline expressions that could collapse; (e) inconsistencies —
naming drift, mixed patterns introduced during the window.
For each finding give file:line, the category, one-line
justification, and the proposed deletion or merge. Skip anything
you're not confident about. If the window is clean, say so."
Apply the high-confidence findings. For each item the reviewer
flagged with concrete file:line + proposed edit, apply the Edit.
Skip anything ambiguous and surface it to the user instead.
Verify. Run the test command from .rig/config.json
(test.command, default npm test):
<test.command>
If anything fails, revert the offending edits (git checkout -- <file>)
and report which removal broke tests so the user can decide whether
to keep or rework.
Report. Lines removed, files touched, anything skipped and why.
1---2name: rig-tidy3description: Run post-merge code cleanup: audit recent changes for dead code, duplicates, and stale comments, then safely remove them. Triggers on: 'cleanup', 'simplify', 'clean up code', 'remove dead code', 'post-merge cleanup'.4---56# Post-Merge Cleanup78Audit and clean up the diff from the last N commits. Catches dead code,9unused imports, stale comments, and obvious duplicates that slipped in10during rapid development.1112## Configuration1314Reads `.rig/config.json`:1516- `sourceScope[0]` — the default directory to audit when no scope is17 given (default: `src`).18- `test.command` — the suite run in the verify step (default: `npm test`).19- `agents.reviewer` — the project's name for the canonical `reviewer`20 role (default: `reviewer`).2122If the file is absent, use the defaults above and note you're running23unconfigured.2425## Arguments2627The user invoked this with: $ARGUMENTS2829## What to do30311. **Parse the arguments.**32 - **scope**: directory to audit (default: the default source scope from33 `.rig/config.json` (`sourceScope[0]`, default `src`)).34 - **commits**: number of recent commits to review (default: `10`)3536 Examples:37 - `/rig-tidy` → default scope, 10 commits38 - `/rig-tidy path/to/dir 5` → that directory, 5 commits39 - `/rig-tidy 20` → default scope, 20 commits40412. **Show what will be audited.**42 ```bash43 git log --oneline -${commits}44 git diff HEAD~${commits} --stat -- ${scope} | tail -2045 ```46473. **Audit the diff via a fresh-context subagent.** Spawn a `reviewer`48 agent (mapped through `agents.reviewer`) with this prompt (don't do the49 audit inline — the implementer context is too close to the code to spot50 dead-on-arrival abstractions):5152 > "Audit the diff `git diff HEAD~${commits} -- ${scope}` for53 > cleanup candidates. Categories: (a) dead code — exported symbols54 > with no callers in the tree, internal helpers used once; (b)55 > unused imports; (c) stale comments — TODOs completed by the diff,56 > comments describing prior behavior, doc lines that no longer57 > match the code; (d) duplicates — near-identical helpers, repeated58 > inline expressions that could collapse; (e) inconsistencies —59 > naming drift, mixed patterns introduced during the window.60 >61 > For each finding give file:line, the category, one-line62 > justification, and the proposed deletion or merge. Skip anything63 > you're not confident about. If the window is clean, say so."64654. **Apply the high-confidence findings.** For each item the reviewer66 flagged with concrete file:line + proposed edit, apply the Edit.67 Skip anything ambiguous and surface it to the user instead.68695. **Verify.** Run the test command from `.rig/config.json`70 (`test.command`, default `npm test`):71 ```bash72 <test.command>73 ```74 If anything fails, revert the offending edits (`git checkout -- <file>`)75 and report which removal broke tests so the user can decide whether76 to keep or rework.77786. **Report.** Lines removed, files touched, anything skipped and why.