Sweep

From SDiamante13/dotfiles · View interactive version

Sweep is an AI agent skill from the GitHub repository SDiamante13/dotfiles. Two-phase code quality skill: (1) review codebase for structural smells — file LOC, method LOC, accidental complexity, test readability — producing a structured report, then (2) fix all smells via provable refactorings with ACN micro commits and green-bar-at-all-times discipline. Use this skill when

How to use this skill

Skill file

Sweep

Two-phase code quality workflow: Review structural smells, then Refactor them away with provable safety.

The philosophy: see clearly first, then cut precisely. Every commit is provably safe. The tests never go red.

Arguments

Accepts optional focus areas as arguments. When provided, narrow the review to those areas only:

When no arguments are given, review all areas.

Phase 1: Review

Launch up to 2 Explore sub-agents in parallel to scan the codebase:

Agent 1 — Source scan: Read all source files. For each file report:

Agent 2 — Test scan: Read all test files. For each file report:

Report Format

Present findings as a structured report with these sections:

## File LOC (top offenders)
| File | LOC | Concern |

## Methods Over 25 Lines
| File | Method | Lines | Severity |
(Severity: Critical >60, High 40-60, Medium 30-40, Low 25-30)

## Accidental Complexity
Numbered list with file, description, and what's duplicated/nested/unclear.

## Test Readability
| File | Lines | Score /10 | Issue |

## What's Good
Acknowledge what's already clean — this matters for morale.

After the report, ask:

Would you like me to refactor all identified smells?

Do NOT proceed to Phase 2 until the user confirms.

Phase 2: Refactor

When the user confirms, execute refactorings using provable safety discipline.

Step 0: Test Runner Script

Create bin/check.sh — a silent test runner that only outputs on failure:

#!/usr/bin/env bash
set -euo pipefail
output=$(flutter test --reporter compact 2>&1) || {
  echo "$output"
  exit 1
}

Adapt the test command to the project's stack:

Run it once to verify green, then commit: t - add silent test runner script

Refactoring Order

This order exists because each phase makes the next safer:

1. Test helpers first — Factory functions, state builders, assertion helpers. These reduce boilerplate and make tests more readable, but more importantly they make the test suite more resilient to the source refactorings that follow.

2. Source code extractions — Extract method, extract variable. Break long methods into composed pieces. Each extraction is one commit.

3. Accidental complexity — Deduplicate patterns, replace magic numbers with named constants, extract shared logic. These are often enabled by the extractions in step 2.

Provable Refactorings

Only use refactorings that are provably behavior-preserving:

| Refactoring | What it does |

|---|---|

| Extract method | Move lines into a new method, call it from the original site |

| Extract variable | Name a sub-expression |

| Inline | Replace a call/variable with its definition |

| Rename | Change a name everywhere |

| Extract constant | Replace magic number/string with a named constant |

| Move | Relocate code to a better home |

If a change cannot be proven safe by inspection alone, use parallel change: add the new version alongside the old, migrate all callers, then remove the old version. Each step is its own commit.

Arlo's Commit Notation (ACN)

Every commit message starts with a prefix that communicates intent and risk:

| Prefix | Meaning | Risk |

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

| t | Test-only change | Known safe |

| r | Provable refactoring | Provably safe |

| e | Extract (method, class, variable) | Provably safe |

| R | Rename | Provably safe |

| F | Feature (new behavior) | Requires review |

| B | Bugfix | Requires review |

Format: <prefix> - <description>

Examples:

Green Bar Protocol

This is non-negotiable. After every single commit:

  1. Run bin/check.sh
  2. If it fails: fix the issue, do NOT commit the broken state
  3. Only commit when green

After all commits are done, run the project's static analyzer (flutter analyze, eslint, mypy, etc.) and fix any warnings introduced.

Execution Pattern

For each smell from the review:

  1. Read the file (if not already in context)
  2. Make the extraction/change
  3. Run bin/check.sh — silent means green
  4. Commit with ACN prefix
  5. Move to next smell

Keep commits small. One extraction = one commit. Do not batch multiple changes.

Verification Sub-Agent

After all refactoring commits are done, launch a review sub-agent to double-check:

Report the final commit log with all ACN-prefixed messages as a summary.

Principles

These guide judgment calls throughout the workflow:

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.