skills/refactor/SKILL.md
Safe multi-file refactoring with automatic rollback. Establishes a type/test baseline, plans all changes, executes file-by-file, and verifies zero regressions. Reverts if verification fails after two fix attempts. Handles renames, extracts, moves, splits, merges, and inlines.
npx skillsauth add SethGammon/Citadel refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use /refactor when you need to:
Don't use when: debugging a specific bug (use /systematic-debugging); adding new features (use /marshal or /scaffold); deleting dead code (use /marshal for a targeted cleanup).
Behavior does not change. Tests pass before and after, no new type errors — the refactoring is correct.
| Command | Behavior |
|---|---|
| /refactor rename [old] to [new] | Rename symbol, file, or module |
| /refactor extract [target] from [source] | Extract function/component/module |
| /refactor inline [target] | Inline a function/module into callers |
| /refactor move [source] to [dest] | Move file(s) with import updates |
| /refactor split [file] | Split a file into logical pieces |
| /refactor merge [files...] | Merge related files into one |
| /refactor [freeform description] | Auto-detect refactoring type from description |
| /refactor --dry-run [any above] | Plan only, show what would change |
Run typecheck (via node scripts/run-with-timeout.js 300 npm run typecheck) and tests. Record error/failure counts — pre-existing issues are not your responsibility, but you must not add to them. Warn if there are uncommitted changes in files you plan to modify.
Baseline established:
Typecheck: {pass | N errors (pre-existing)}
Tests: {pass | N failures (pre-existing) | no test suite found}
Git: {clean | M files with uncommitted changes}
Analyze the refactoring target and produce a concrete plan.
Identify scope: Search the codebase for every reference to the target. Use grep/search for:
Classify the refactoring type and apply type-specific analysis:
Rename (symbol): all imports + usage sites + string references + dynamic access patterns (obj[key])
Rename (file/module): all import paths + path aliases + dynamic imports + index re-exports
Extract (function/component/module): code to extract, enclosing-scope dependencies, return values back to caller, destination file, interface design
Move (file): every import of old path → compute new relative paths, check alias boundary changes, barrel updates
Split (file): logical groupings, internal cross-references, which group keeps the original path, new files per group, index if needed
Merge (files): duplicates/conflicts, import consolidation, merged file organization
Produce the plan — list every file that will change and what changes:
Refactoring Plan: {type} — {description}
Files to modify:
1. {file}: {what changes and why}
2. {file}: {what changes and why}
...
Files to create:
- {file}: {extracted from where, contains what}
Files to delete:
- {file}: {contents moved to where}
Risk assessment:
- {any concerns: dynamic references, string-based lookups, config files}
--dry-run was specified, output the plan and stop.Apply changes in this order to minimize intermediate breakage:
Read each file before editing. Make the minimal change needed — do not reformat unrelated code.
Run typecheck and tests from Phase 1. Compare against baseline — any NEW errors or failures? Search for import paths referencing old/deleted files.
Verification: PASS
Typecheck: {pass | same N pre-existing errors}
Tests: {pass | same N pre-existing failures}
No new broken imports detected.
Two attempts: read errors, identify root cause (missed import update, missing re-export, type mismatch), fix, re-run verification. After 2 failed attempts: REVERT.
git checkout -- [files] to restore every modified fileREVERTED — Refactoring could not be completed cleanly.
Root cause: {why the refactoring failed}
Errors encountered:
- {error 1}
- {error 2}
Suggestion: {what the user might do differently}
git revert HEAD --no-edit, then report which verification step introduced the regression and what the failing error is.Report the result:
=== Refactor Report ===
Type: {rename | extract | inline | move | split | merge}
Target: {what was refactored}
Changes:
Modified: {N} files
Created: {N} files
Deleted: {N} files
Verification:
Typecheck: {pass | same baseline errors}
Tests: {pass | same baseline failures | no test suite}
Key decisions:
- {any non-obvious choices made during execution}
---HANDOFF---
- Refactored {target}: {what changed}
- {N} files modified, {N} created, {N} deleted
- Typecheck and tests pass (no regressions)
- {any follow-up suggestions}
- Reversibility: green -- single atomic commit, revert with git revert HEAD
---
development
GitHub issue and PR investigator. Pulls open issues/PRs, classifies them, searches the codebase for root cause or reviews contributed code, proposes fixes with file:line references, and optionally implements fixes. Use for investigating GitHub issues and reviewing PRs; do NOT use for general code review unrelated to GitHub issues.
development
Unified telemetry hub. Shows current session cost, today's spend, all-time totals, hook activity, trust level, and a directory of every telemetry command available. Also the control surface to toggle telemetry on/off and tune thresholds. Single entry point for anyone asking "what does this cost" or "what telemetry does Citadel have".
devops
Manages recurring and one-off scheduled tasks. Session-scoped scheduling via CronCreate/CronDelete/CronList. Documents the cloud path for tasks that need to survive machine sleep or network drops.
tools
Browser-based QA verification. Launches a real browser, navigates the app, clicks buttons, fills forms, and tests user flows. Works as a standalone skill or as a phase end condition in campaigns. Requires Playwright (optional dependency, graceful skip if not installed).