From formal-verify
Execute architectural refactoring from an assessment document with deterministic, chunked operations and aggressive verification at every step. Use when you have an architectural assessment, clean architecture review, refactoring recommendations, or seam-ripper output and need to actually perform the refactoring safely. Also use when asked to "refactor based on this assessment", "execute these architectural recommendations", "fix architectural drift", "refactor in chunks", or any request to systematically restructure a codebase according to a plan. Designed specifically to prevent the kind of agent drift that causes architectural problems in the first place.
npx claudepluginhub petekp/agent-skills --plugin literate-guideThis skill uses the workspace's default tool permissions.
Turn architectural recommendations into reality without breaking anything.
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Guides building MCP servers enabling LLMs to interact with external services via tools. Covers best practices, TypeScript/Node (MCP SDK), Python (FastMCP).
Generates original PNG/PDF visual art via design philosophy manifestos for posters, graphics, and static designs on user request.
Turn architectural recommendations into reality without breaking anything.
Coding agents are great at local changes but bad at maintaining architectural coherence across long sessions, context compactions, and multi-session work. This skill solves that by externalizing the plan to disk, tracking progress in a manifest, and enforcing verification gates between every chunk. The agent can lose context entirely and pick up exactly where it left off.
The entire approach rests on three files that live on disk (not in context):
refactor-plan.md — The concrete, ordered plan derived from the assessment. Every chunk has explicit entry criteria, steps, and exit criteria.refactor-manifest.json — Machine-readable progress tracker. What's done, what's next, what failed, verification results.refactor-log.md — Append-only human-readable log of what happened and why, so any agent (or human) can understand the history.These files are the source of truth. Not your memory. Not the conversation. The files.
Read the assessment document(s) the user provides. These might be markdown files, seam-ripper output, simplicity audit results, or any structured analysis with recommendations.
Extract from the assessment:
If the assessment is vague or missing critical details, stop and ask. A refactoring plan built on ambiguous recommendations will drift — which is exactly what we're trying to prevent.
Convert the assessment into a concrete, ordered sequence of chunks. Each chunk is a self-contained unit of refactoring that moves the codebase from one valid state to another.
A chunk should be:
Good chunks typically look like:
Bad chunks:
Before ordering chunks, map which chunks depend on which:
If you find circular dependencies between chunks, the chunk boundaries are wrong. Re-slice until the dependency graph is a DAG (directed acyclic graph — meaning no circular dependencies).
Create refactor-plan.md in the project root (or wherever the user prefers):
# Refactoring Plan
**Source:** [link/path to assessment document]
**Created:** [date]
**Target:** [one-sentence description of desired end state]
## Pre-flight Checks
- [ ] All tests pass before starting
- [ ] No uncommitted changes
- [ ] Working branch created
## Chunk 1: [Descriptive Name]
**Why:** [Which assessment finding this addresses]
**Entry criteria:** All tests pass, no prior chunks pending
**Steps:**
1. [Concrete action — e.g., "Create `src/auth/tokens.ts` with the TokenService class"]
2. [Next action — e.g., "Move `generateToken()` and `validateToken()` from `src/core/utils.ts`"]
3. [Continue — e.g., "Update imports in `src/api/middleware.ts` and `src/api/routes/login.ts`"]
4. [e.g., "Remove the now-empty token section from `src/core/utils.ts`"]
**Exit criteria:** All tests pass, types check, lint clean
**Commit message:** `refactor: extract token management into dedicated auth module`
## Chunk 2: [Descriptive Name]
**Depends on:** Chunk 1
**Why:** [...]
**Entry criteria:** Chunk 1 complete and verified
**Steps:**
1. [...]
**Exit criteria:** All tests pass, types check, lint clean
**Commit message:** `refactor: ...`
[...continue for all chunks...]
## Post-flight Checks
- [ ] Full test suite passes
- [ ] No TODO/FIXME markers left from refactoring
- [ ] Assessment findings are resolved
The steps within each chunk should be concrete enough that an agent with zero prior context could execute them mechanically. File paths, function names, specific moves — not "restructure as needed."
Create refactor-manifest.json:
{
"plan_file": "refactor-plan.md",
"assessment_source": "[path to assessment]",
"created": "[ISO date]",
"total_chunks": 5,
"current_chunk": 0,
"status": "ready",
"preflight_passed": false,
"chunks": [
{
"id": 1,
"name": "Extract token management",
"status": "pending",
"depends_on": [],
"verification": null,
"commit_sha": null,
"started_at": null,
"completed_at": null
},
{
"id": 2,
"name": "Decouple auth from core",
"status": "pending",
"depends_on": [1],
"verification": null,
"commit_sha": null,
"started_at": null,
"completed_at": null
}
]
}
Present the plan to the user before executing anything. They should confirm:
If the user wants changes, update the plan and manifest before proceeding.
This is the main loop. It's deliberately rigid because rigidity prevents drift.
Every time you begin work — whether it's the first time or you're resuming after a context compaction or new session — do this:
refactor-manifest.json — find where you arerefactor-plan.md — understand the current chunkrefactor-log.md — understand what happened recentlyThis takes 30 seconds and prevents the #1 cause of agent drift: starting work based on stale or assumed context.
FOR each chunk (in order):
1. READ the chunk from refactor-plan.md
2. CHECK entry criteria
- Dependencies met? (check manifest)
- Tests passing? (run them)
- If not: STOP. Fix or escalate to user.
3. UPDATE manifest: chunk status → "in_progress"
4. LOG: "Starting chunk N: [name]"
5. EXECUTE each step in the chunk sequentially
- Follow the plan literally
- If a step can't be done as written: STOP
→ Log what went wrong
→ Update manifest with the blocker
→ Ask the user how to proceed
→ Do NOT improvise a workaround
6. VERIFY (the gate)
- Run the full test suite
- Run type checking
- Run linter
- If ANY verification fails:
→ Fix the issue (if it's clearly caused by this chunk's changes)
→ Re-verify
→ If you can't fix it in 2 attempts: STOP
→ Revert the chunk (git checkout/restore)
→ Log the failure
→ Update manifest: chunk status → "failed"
→ Ask the user
7. COMMIT
- Stage only the files changed in this chunk
- Use the commit message from the plan
- Record the commit SHA in the manifest
8. UPDATE manifest: chunk status → "completed"
9. LOG: "Completed chunk N. Verification: [pass/fail details]"
10. Proceed to next chunk
When the skill says STOP, it means: do not continue to the next chunk, do not try creative workarounds, do not "fix it and move on." The whole point of this skill is that deviating from the plan is how codebases get into the mess that required this refactoring in the first place.
When you stop:
The user might say "skip this chunk," "modify the plan," or "here's how to handle it." All fine. The decision is theirs, not the agent's.
Watch for these signs that you're drifting from the plan:
If any of these happen, STOP and re-read the plan. If the plan is genuinely wrong, update it (and the manifest) with the user's approval. Don't silently deviate.
After all chunks are complete:
status → "completed"The verification commands depend on the project. Detect them on first run and record in the manifest so they're stable across sessions:
{
"verification": {
"test": "npm test",
"typecheck": "npx tsc --noEmit",
"lint": "npm run lint",
"detected_at": "[ISO date]"
}
}
Detection order:
package.json scripts, Makefile, Cargo.toml, pyproject.toml, etc.npm test, pytest, cargo test, go test ./...)All three checks (test, typecheck, lint) must pass at every gate. If the project doesn't have one of them (e.g., no type checker for plain JS), note it in the manifest and skip that check — but never skip tests.
If a chunk fails and you need to retry:
git stash or git checkout . to revert uncommitted changes from the failed chunkIf the same chunk fails twice, do not retry again. Update the manifest, log the details, and escalate to the user. Two failures on the same chunk means the plan needs revision, not more attempts.
If you're ending a session before all chunks are done, or if you're creating a handoff for another agent/session:
The next session starts by reading the manifest — all context needed to continue is on disk.
/seam-ripper, /simplicity-audit, or bring your own analysis).