Chrysopoeia

From pjt222/agent-almanac · View interactive version

Chrysopoeia is an AI agent skill from the GitHub repository pjt222/agent-almanac. Extract maximum value from existing code — performance optimization, API surface refinement, and dead weight elimination. The art of turning base code into gold through systematic identification and amplification of value-bearing patterns. Use when optimizing a working but sluggish codebase, refinin

How to use this skill

Skill file

Chrysopoeia

Systematically extract maximum value from existing code — identify what's golden (high-value, well-designed), what's lead (resource-heavy, poorly optimized), and what's dross (dead weight). Then amplify the gold, transmute the lead, and remove the dross.

When to Use

Inputs

Procedure

Step 1: Assay — Classify the Material

Systematically classify every element by its value contribution.

  1. Define the value metric from Inputs (performance, clarity, size, etc.)
  2. Inventory the codebase elements (functions, modules, exports, dependencies)
  3. Classify each element:
Value Classification:
+--------+---------------------------------------------------------+
| Gold   | High value, well-designed. Amplify and protect.         |
| Silver | Good value, minor imperfections. Polish.                |
| Lead   | Functional but heavy — poor performance, complex API.   |
|        | Transmute into something lighter.                       |
| Dross  | Dead code, unused exports, vestigial features.          |
|        | Remove entirely.                                        |
+--------+---------------------------------------------------------+
  1. For performance optimization, profile first:
  1. Produce the Assay Report: element-by-element classification with evidence

Got: Every significant element classified with evidence. Gold elements are identified for protection during optimization. Lead elements are prioritized by impact.

If fail: If profiling tools aren't available, use static analysis: function complexity (cyclomatic), dependency count, and code size as proxies. If the codebase is too large, focus on the critical path first.

Step 2: Refine — Amplify the Gold

Protect and enhance the highest-value elements.

  1. For each Gold element:
  1. For each Silver element:
  1. Do not modify Gold/Silver behavior — only improve their polish and protection

Got: Gold and Silver elements are better tested, documented, and protected. No behavioral changes, only quality improvements.

If fail: If a "Gold" element reveals hidden problems during closer inspection, reclassify it. Better to be honest about value than to protect flawed code.

Step 3: Transmute — Convert Lead to Gold

Transform heavy, inefficient elements into optimized equivalents.

  1. Prioritize Lead elements by impact (highest resource consumption first)
  2. For each Lead element, choose a transmutation strategy:
  1. Apply the strategy and measure the improvement:
  1. Verify behavioral equivalence after each transmutation

Got: Measurable improvement on the target value metric. Each transmuted element performs better than its Lead predecessor while maintaining identical behavior.

If fail: If a Lead element resists optimization within its current interface, consider whether the interface itself is the problem. Sometimes the transmutation requires changing how the element is called, not how it's implemented.

Step 4: Purge — Remove the Dross

Eliminate dead weight systematically.

  1. For each Dross element, verify it's truly unused:
  1. Remove confirmed dross:
  1. Verify nothing breaks after each removal (run tests)
  2. Document what was removed and why (in commit messages, not in code)

Got: The codebase is lighter. Bundle size, dependency count, or code volume measurably reduced. All tests still pass.

If fail: If removing an element breaks something, it wasn't dross — reclassify it. If dynamic references make it hard to verify usage, add temporary logging before deletion to confirm no runtime access.

Step 5: Verify — Weigh the Gold

Measure the overall improvement.

  1. Run the same benchmarks/metrics used in Step 1
  2. Compare before/after on the target value metric
  3. Document the chrysopoeia results:

Got: Measurable, documented improvement on the target value metric. The codebase is demonstrably more valuable than before.

If fail: If overall improvement is marginal, the original code may have been better than assumed. Document what was learned — knowing that code is already near-optimal is itself valuable.

Validation Checklist

Pitfalls

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.