$npx -y skills add Borda/AI-Rig --skill refactorTest-first refactoring — audit coverage, add characterization tests, apply changes with safety net, run quality stack and review loop. TRIGGER when: user wants to restructure existing Python code without changing behaviour; phrases: \"refactor X\", \"clean up Y\", \"extract Z\",
| 1 | <objective> |
| 2 | |
| 3 | Test-first refactoring. Audit coverage, add characterization tests if missing, apply changes with safety net. |
| 4 | |
| 5 | NOT for: |
| 6 | - bug fixes (use `/develop:fix`) |
| 7 | - new features (use `/develop:feature`) |
| 8 | - `.claude/` config changes (use `/foundry:manage` (requires foundry plugin)) |
| 9 | - non-Python projects (JS/TS/Go/Rust) — toolchain assumes pytest; use language-native toolchain instead |
| 10 | - mixed refactor+feature tasks — run /develop:refactor first, then /develop:feature; do not attempt both in single skill run |
| 11 | |
| 12 | Quality stack (Branch Safety Guard, Codex Pre-pass, Progressive Review) requires `foundry` plugin; when absent, Step 5 quality stack skipped with a visible warning — output lower quality but workflow still completes. |
| 13 | |
| 14 | </objective> |
| 15 | |
| 16 | <constants> |
| 17 | |
| 18 | - MAX_INNER_CYCLES: 5 (change-test cycles per outer session — Step 4 safety break) |
| 19 | |
| 20 | </constants> |
| 21 | |
| 22 | <compaction> |
| 23 | |
| 24 | Key boundary: end of Step 2 — coverage audit complete, before characterization test writing in Step 3. |
| 25 | Second boundary: end of Step 4 — refactor edits applied, before review stack in Step 5. |
| 26 | Preserve at boundary 1: dev-dir, target path, coverage audit summary, plan-file, --keep items. |
| 27 | Preserve at boundary 2: dev-dir, changed files list, test outcomes. |
| 28 | |
| 29 | </compaction> |
| 30 | |
| 31 | <workflow> |
| 32 | |
| 33 | <!-- Agent Resolution: resolved at runtime via $_DEV_SHARED; source at develop/skills/_shared/agent-resolution.md (installed path) --> |
| 34 | |
| 35 | ## Agent Resolution |
| 36 | |
| 37 | ```bash |
| 38 | _PATHS=$(python "${CLAUDE_PLUGIN_ROOT:-plugins/cc_develop}/bin/dev_shared_resolve.py" --foundry 2>/dev/null) # timeout: 5000 |
| 39 | _DEV_SHARED=$(echo "$_PATHS" | head -1) |
| 40 | _FOUNDRY_SHARED=$(echo "$_PATHS" | tail -1) |
| 41 | [ -z "$_FOUNDRY_SHARED" ] && _FOUNDRY_SHARED="plugins/cc_foundry/skills/_shared" |
| 42 | # loads: compaction-contract.md |
| 43 | cat "$_DEV_SHARED/agent-resolution.md" |
| 44 | ``` |
| 45 | |
| 46 | Contains: foundry check + fallback table. If foundry not installed: substitute each `foundry:X` with `general-purpose` per table. Agents skill uses: `foundry:sw-engineer`, `foundry:qa-specialist`, `foundry:linting-expert`, `foundry:challenger`. |
| 47 | |
| 48 | ```bash |
| 49 | _DEV_SHARED=$(python "${CLAUDE_PLUGIN_ROOT:-plugins/cc_develop}/bin/dev_shared_resolve.py" 2>/dev/null) # timeout: 5000 |
| 50 | cat "$_DEV_SHARED/task-hygiene.md" |
| 51 | ``` |
| 52 | |
| 53 | <!-- Reference only — execution-dead at runtime; included for agent behavioral context --> |
| 54 | ## Anti-Rationalizations |
| 55 | |
| 56 | | Temptation | Reality | |
| 57 | | --- | --- | |
| 58 | | "The code is simple enough — I can skip characterization tests" | No safety net = no proof behavior unchanged. Characterization tests only proof. | |
| 59 | | "I'll fix this adjacent bug while I'm in here" | Scope creep conflates history. Adjacent bugs go in Follow-up, not this session. | |
| 60 | | "The tests are too brittle — I'll refactor them as well" | Refactoring tests + prod code simultaneously makes regressions unattributable. Fix tests first, separate pass. | |
| 61 | | "I know the codebase — no need for coverage audit" | Untested edge cases = most common refactoring breakage. Audit finds what you don't know you don't know. | |
| 62 | | "This is a small change — Step 4's max-5 cycles are overkill" | Simple changes = simple test loops. Guard costs nothing when unneeded; prevents runaway sessions when it is. | |
| 63 | |
| 64 | ## Project Detection |
| 65 | |
| 66 | ```bash |
| 67 | _DEV_SHARED=$(python "${CLAUDE_PLUGIN_ROOT:-plugins/cc_develop}/bin/dev_shared_resolve.py" 2>/dev/null) # timeout: 5000 |
| 68 | cat "$_DEV_SHARED/runner-detection.md" |
| 69 | ``` |
| 70 | Sets `$TEST_CMD` (full suite) and `$PYTEST_CMD` (pytest flags). Run at skill start. |
| 71 | |
| 72 | **Optional `--plan <path>`**: if `$ARGUMENTS` contains `--plan <path>` (at any position), read plan file first. Extract `Affected files`, `Risks`, `Suggested approach` — use to inform Step 1 scope analysis. Skip redundant codebase exploration for already-classified files. Store plan path as `PLAN_FILE`. |
| 73 | |
| 74 | ```bash |
| 75 | _DEV_SHARED=$(python "${CLAUDE_PLUGIN_ROOT:-plugins/cc_develop}/bin/dev_shared_resolve.py" 2>/dev/null) # timeout: 5000 |
| 76 | cat "$_DEV_SHARED/preflight-helpers.md" |
| 77 | ``` |
| 78 | Execute --plan path extraction; sets `$PLAN_FILE`. |
| 79 | |
| 80 | **Checkpoint init**: run `DEV_DIR=$(python "${CLAUDE_PLUGIN_ROOT:-plugins/cc_develop}/bin/dev_run_dir.py" 2>/dev/null) # |