/fmt-sweep — multi-repo cargo fmt + test + commit + push
Walks a configured list of Rust workspaces and, per repo:
- Runs
cargo fmt --all --checkto count drifted regions - If drift > 0: runs
cargo fmt --allto canonicalize - Runs
cargo test --workspaceto verify no regression chown -R paul:paul(when running as root) so the autogenerated artifacts have correct ownership before git- Stages only
.rsfiles (filters out generatedstatic/,reports/, etc.) - Commits with an auto-generated body listing the drift count + files touched
- Pushes to
origin main
LFI repos excluded by default per feedback_lfi_out_of_scope_for_this_instance. Override via --include-lfi.
Why this exists
Surfaced 2026-05-20 during a manual fmt sweep across PlausiDen-Forge / PlausiDen-Crawler / PlausiDen-Loom / Crucible. Per-repo, the manual sequence was: cargo fmt --check → cargo fmt --all → cargo fmt --check again → cargo test --workspace → chown -R paul:paul → sudo -u paul git add (filtered) → sudo -u paul git commit (HEREDOC body) → sudo -u paul git push. That's ~8 tool calls per repo × 4 repos = 32 tool calls plus the verification + chown ceremony. Compresses to one invocation.
This is paul's contribute to claude tools repo any tasks that can be automated that can save tokens directive: each repeated agent workflow is a fmt-sweep waiting to happen.
Steps
1. Read the workspace list
Default in-scope set (PlausiDen substrate):
/home/paul/projects/PlausiDen-Forge
/home/paul/projects/PlausiDen-Loom
/home/paul/projects/PlausiDen-Crawler
/home/paul/projects/Crucible
Same overrides as workspace-tests:
$FMT_SWEEP_REPOSenv (colon-separated absolute paths)~/.config/fmt-sweep/repos.txt(one path per line)- Positional args
--include-lfiflag
2. Per repo: drift check + apply + test
DRIFT=$(sudo -u paul cargo fmt --all --check --manifest-path "$REPO/Cargo.toml" 2>&1 | grep -c '^Diff in')
if [ "$DRIFT" -eq 0 ]; then
printf '%-32s\tclean\n' "$(basename "$REPO")"
continue
fi
sudo -u paul cargo fmt --all --manifest-path "$REPO/Cargo.toml"
sudo -u paul cargo test --workspace --manifest-path "$REPO/Cargo.toml" > "$LOG" 2>&1 \
|| { echo "REGRESSION in $REPO post-fmt — reverting"; git -C "$REPO" checkout -- '*.rs'; exit 1; }
3. Per repo: stage filtered + commit + push
cd "$REPO"
sudo -u paul git diff --name-only HEAD | grep '\.rs$' | xargs sudo -u paul git -C "$REPO" add
sudo -u paul git -C "$REPO" commit -m "$(printf 'chore: cargo fmt --all sweep across %s workspace\n\n%d drifted regions across N .rs files canonicalized.\nWorkspace cargo test --workspace passes post-fmt.\ncargo fmt --all --check reports 0 drift after the sweep.\n' "$(basename "$REPO")" "$DRIFT")"
sudo -u paul git -C "$REPO" push origin main
4. Rollback safety
If cargo test --workspace returns non-zero post-fmt, revert the
fmt changes (git checkout -- '*.rs') and bail. Pre-existing
compile errors (E0063 etc.) are NOT fmt-introduced and surface
this way — the script reports the regression repo + tail-50 of
the test output for the next agent to investigate.
5. Output format
PlausiDen-Forge 0 drift — clean
PlausiDen-Loom 214 drift → fmt'd → tests pass → committed b4bac18 → pushed
PlausiDen-Crawler 101 drift → fmt'd → tests pass → committed 3a0871a → pushed
Crucible 4 drift → fmt'd → tests pass → committed 6e5d37c → pushed
-----
TOTAL 319 drifted regions canonicalized across 3 repos
6. Bypass conditions
- No drift in any repo → exit 0 with summary
- One repo has uncommitted non-fmt changes → skip that repo with warning
cargonot installed → exit 2 with the install URLcargo fmtnot installed → exit 2 withrustup component add rustfmt
Companion skills
workspace-tests— sibling skill that runs only the test step. fmt-sweep invokes workspace-tests internally as the post-fmt verification gate.regression-guard— adjacent; catches per-PR regressions on a single repo.
Don't
- Don't include any non-
.rsfiles in the commit (generated artifacts understatic/,reports/,target/etc. drift independently and have their own commit cadence). - Don't fmt-sweep with uncommitted semantic changes pending in the repo — separate the cleanup pass from the feature pass.
- Don't include LFI repos by default per the dedicated-instance doctrine.