agentleFS
momentmakermomentmaker/kaijutsu/skills/core/refactor-plan/SKILL.md

refactor-plan

Skill3 starsChanged 6 months agoMITView on GitHub

Multi-agent refactor planning — files + goal in, ordered step plan with risk per step out. Wraps `jutsu swarm refactor-plan <path>... --goal "<goal>"` to run claude / codex / antigravity with three angles (claude=architectural decomposition, codex=stepwise risk, antigravity=pattern consistency). Designed to feed into `planning-and-task-breakdown` for execution. Use when the user says "plan this refactor", "how do I restructure", "step plan to extract X", or invokes /refactor-plan.

11 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before the first invocation in a repo:

    line 39
  2. Very specific:

    --goal is required: If the user can't articulate the goal in one line, the refactor isn't well-defined yet — go back to brainstorm.

    line 84
  3. Distinctive:

    Cite line ranges: Every step references existing code by file:line.

    line 86
  4. Very specific:

    Default --max-cost $1.00. With 3 agents in --quick mode, typical refactor-plan runs ~$0.10–0.40 depending on file size.

    line 97

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

refactor-plan

Three angles on the same refactor:

LensAgentLooks for
Architectural decompositionclaudeThe right new shape — abstractions, boundaries, test seams
Stepwise riskcodexOrder that minimizes regression — small reversible steps first
Pattern consistencyantigravityExisting repo patterns the refactor should follow, not invent around

Synthesizer takes all three step proposals, clusters by what-changes, sorts low-risk-first, surfaces ordering disagreements as callouts. Output is an ordered plan with per-step risk + files-touched.

When to invoke

# Single-file refactor
jutsu swarm refactor-plan handlers/users.go --goal "extract auth check into middleware"

# Multi-file (concatenated review — agents reason cross-file)
jutsu swarm refactor-plan cmd/server/handlers.go cmd/server/router.go \
  --goal "split monolithic handler module into per-resource services"

# High-stakes — debate + filter
jutsu swarm refactor-plan db/migrations.go --goal "split into per-table migration files" --full --strict

# Iterate on synth prompt without re-spending
jutsu swarm refactor-plan --replay <key>

The --goal flag is REQUIRED. Missing-goal invocation hard-errors with a usage hint. Goal text counts against the 200 KB InputFiles cap (negligible in practice).

First-run consent

Before the first invocation in a repo:

jutsu swarm refactor-plan --grant-consent

Persists allow-multi-model: true to .kaijutsu/refactor-plan.yaml. Files + goal go to remote model providers; explicit consent required.

Reading the output

### Plan
1. **Step 1 — Extract auth check into separate function** (recommended, agreement 3/3)
   - What: Move lines 42-58 from handlers/users.go into a new authMiddleware function.
   - Why: Single responsibility; isolates auth from request handling.
   - Risk: Low. No behavior change. Tests in handlers_test.go cover the path.
   - Files touched: handlers/users.go:42-58

2. **Step 2 — Wire middleware into router** (recommended, agreement 2/3)
   - ...

### Ordering disagreements
- claude wanted Step 4 before Step 3; codex argued Step 3's reversibility
  makes it lower-risk to ship first. Going with codex's order.

### Speculative additions
- Optional: extract a TokenValidator interface for easier mocking.
  Defer unless tests need it.

The disagreement table (rendered separately) shows which agent proposed each step. 1/N rows are usually the speculative bucket — interesting but not required.

Composes

This skill chains naturally:

  1. brainstorm — pick the refactor approach (if not yet decided)
  2. refactor-plan — turn that approach into ordered steps with risk
  3. planning-and-task-breakdown — convert the steps into shippable vertical slices with per-task acceptance
  4. Implementation in a separate session, slice by slice

Each tool gets its own multi-agent pass at the appropriate level of detail.

Hard rules

  • --goal is required. If the user can't articulate the goal in one line, the refactor isn't well-defined yet — go back to brainstorm.
  • Read-only on inputs. refactor-plan never modifies files; it produces a plan markdown the user reads + executes manually (or via planning-and-task-breakdown → implementation).
  • Cite line ranges. Every step references existing code by file:line. Plans without citations are aspirational, not actionable.
  • Don't run on the WHOLE repo. The 200 KB cap exists because cross-file refactors only synthesize well over a focused subset. If the refactor touches 30 files, narrow to the core 5-10 the agents need to reason about, then plan the rest based on the pattern.

When NOT to use

  • Single-line behavioral fixes — overkill.
  • Pure stylistic refactors (renames, formatting) — polish is the right primitive.
  • Refactors that need to read external dependencies (third-party source) — refactor-plan is sandboxed; supply the relevant external code as input files OR brainstorm the approach instead.

Cost

Default --max-cost $1.00. With 3 agents in --quick mode, typical refactor-plan runs ~$0.10–0.40 depending on file size. --full (debate round) adds ~50%. --strict (lie-to-them filter on synthesis) adds another synthesis call.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.