From agent-almanac
Executes four-stage alchemical code transmutation (nigredo decomposition, albedo purification, citrinitas illumination, rubedo synthesis) for refactoring legacy or tangled modules into modern structures when incremental fixes fail.
npx claudepluginhub pjt222/agent-almanacThis skill uses the workspace's default tool permissions.
---
Orchestrates multi-session refactoring of legacy/messy codebases: autopsy assessment, safety nets, incremental module surgery, progress tracking. Use for 'refactor' or old code cleanup.
Applies disciplined refactoring in small, verifiable steps to improve code structure without changing behavior: extract functions, rename, move code.
Identifies code smells like god classes and bloaters, assesses refactoring risks, and builds incremental execution plans with rollback strategies for existing code improvements.
Share bugs, ideas, or general feedback.
Execute a four-stage alchemical transmutation of code or data — decomposing the prima materia, purifying its essence, illuminating its target form, and synthesizing the refined output. The athanor is the furnace that maintains steady heat across all stages.
Break the prima materia into its constituent elements. Nothing is sacred; everything is cataloged.
Expected: A complete, unflinching inventory of the material. The inventory should feel uncomfortable — if it doesn't, the decomposition isn't thorough enough. Every hidden assumption is now explicit.
On failure: If the material is too large to inventory fully, decompose by module boundary and treat each module as a separate athanor run. If dependencies are too tangled to map, use grep/Grep to trace actual call sites rather than relying on documentation.
Run the meditate skill to clear assumptions accumulated during nigredo.
Expected: A clear, unbiased state ready to evaluate the material without being anchored to its current form. The goal feels fresh rather than constrained by what was found.
On failure: If the nigredo findings keep pulling attention (a particularly bad anti-pattern, a clever hack that's tempting to preserve), write it down and explicitly set it aside. Proceed only when the goal is clearer than the current form.
Separate the essential from the accidental. Strip away everything that doesn't serve the target form.
Expected: A set of pure, isolated functions/modules that represent the core value of the original material. Each piece is testable in isolation. The extract is significantly smaller than the original.
On failure: If essential and accidental are too intertwined to separate, introduce seam points (interfaces) first. If the material resists purification, it may need dissolve-form before the athanor can continue.
Run the heal skill to assess whether the purification was thorough.
Expected: Confidence that the albedo extract is complete, clean, and ready for illumination. No essential logic was lost; no toxic patterns remain.
On failure: If the assessment reveals significant gaps, return to Step 3 with the specific gaps identified. Do not proceed to citrinitas with incomplete material.
See the target form. Map the purified elements to their optimal structure.
Expected: A clear, detailed blueprint where every essential element has a home and every interface is defined. The blueprint should feel inevitable — given the purified elements, this structure is the natural fit.
On failure: If multiple valid architectures compete, evaluate each against the constraints from Inputs. If no clear winner emerges, prefer the simplest option and document the alternatives as future options.
Run the meditate skill to prepare for the final synthesis.
Expected: Calm clarity about what needs to be built. The synthesis phase should be execution, not design.
On failure: If doubt persists about the blueprint, revisit Step 5 with the specific concerns. Better to refine the blueprint than to begin synthesis with uncertainty.
Compose the purified elements into their target form. The philosopher's stone: working, optimized code.
Expected: Working code that is measurably better than the original: fewer lines, clearer structure, better test coverage, fewer dependencies. The transformation is complete and the old form can be retired.
On failure: If synthesis reveals gaps in the blueprint, do not patch — return to Step 5 (citrinitas) to revise the design. If individual components fail, isolate and fix them before attempting full integration. The rubedo must not produce a half-transformed chimera.
transmute — Lighter-weight transformation for single functions or small moduleschrysopoeia — Value extraction and optimization (turning base code into gold)meditate — Meta-cognitive clearing used as stage-gate checkpointsheal — Subsystem assessment used for purification validationdissolve-form — When material is too rigid for the athanor, dissolve firstadapt-architecture — Complementary approach for system-level migration patternsreview-software-architecture — Post-synthesis architecture review