# Fmt Sweep

> Run cargo fmt --all across N Rust workspaces, verify tests still pass, commit per-repo with a uniform body, push to origin. Compresses what would otherwise be 6-8 tool calls per repo into one invocation. Use when the user says "fmt sweep", "canonicalize whitespace", or as a /loop PRIORITY 5 hygiene step.

- Skill: `thepictishbeast/fmt-sweep` (Agent Skill)
- Install (CLI): `npx skillmds@latest add thepictishbeast/fmt-sweep`
- Raw SKILL.md: https://api.skillmd.com/api/skills/thepictishbeast/fmt-sweep/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: thepictishbeast (https://skillmd.com/u/thepictishbeast)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/thepictishbeast/fmt-sweep

---


# /fmt-sweep — multi-repo cargo fmt + test + commit + push

Walks a configured list of Rust workspaces and, per repo:
1. Runs `cargo fmt --all --check` to count drifted regions
2. If drift > 0: runs `cargo fmt --all` to canonicalize
3. Runs `cargo test --workspace` to verify no regression
4. `chown -R paul:paul` (when running as root) so the autogenerated artifacts have correct ownership before git
5. Stages **only** `.rs` files (filters out generated `static/`, `reports/`, etc.)
6. Commits with an auto-generated body listing the drift count + files touched
7. 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_REPOS` env (colon-separated absolute paths)
- `~/.config/fmt-sweep/repos.txt` (one path per line)
- Positional args
- `--include-lfi` flag

### 2. Per repo: drift check + apply + test

```sh
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

```sh
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
- `cargo` not installed → exit 2 with the install URL
- `cargo fmt` not installed → exit 2 with `rustup 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-`.rs` files in the commit (generated artifacts under `static/`, `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.

