Transmute
Transform specific code/data → another form (lang translation, paradigm shift, format conversion, API migration) preserving essential behavior + semantics.
Use When
- Convert fn between langs (Python → R, JS → TS)
- Shift module between paradigms (class-based → functional, callbacks → async/await)
- Migrate API consumer v1 → v2
- Convert data formats (CSV → Parquet, REST → GraphQL schema)
- Replace dep w/ equiv (moment.js → date-fns, jQuery → vanilla JS)
- Scope = single fn, class, module (NOT full system)
In
- Required: Source (file path, fn name, data sample)
- Required: Target form (lang, paradigm, format, API ver)
- Optional: Behavioral contract (tests, type signatures, expected I/O pairs)
- Optional: Constraints (backward compat, perf budget)
Do
Step 1: Analyze Source
Understand exactly what src does before transforming.
- Read src completely — every branch, edge case, err path
- ID behavioral contract:
- What ins accepts? (types, ranges, edge cases)
- What outs produces? (return values, side effects, err signals)
- What invariants maintains? (ordering, uniqueness, ref integrity)
- Catalog deps: what src imports, calls, relies on?
- Tests exist → read for expected behavior
- No tests → write behavioral characterization tests before transmuting
Got: Complete understanding of what src does (not how). Behavioral contract explicit + testable.
If err: Src too complex for single transmute → break into smaller pieces | escalate to full athanor proc. Behavior ambiguous → ask clarification vs guess.
Step 2: Map Source → Target
Design transformation mapping.
- Per src element, ID target equivalent:
- Lang constructs: loops → map/filter, classes → closures
- API calls: old endpoint → new, req/res shape changes
- Data types: dataframe cols → schema fields, nested JSON → flat tables
- ID elements w/ no direct equiv:
- Src features missing in target (pattern matching in lang w/o it)
- Target idioms not in src (R vectorization vs Python loops)
- Per gap, choose adaptation strategy:
- Emulate: reproduce behavior w/ target-native constructs
- Simplify: src construct was workaround → use target's native solution
- Document: behavior changes slightly → note explicit
- Write transformation map: src → target per piece
Got: Complete mapping where every src element has target dest. Gaps ID'd + adaptation chosen.
If err: Too many no direct equivs → transformation may be inappropriate (highly OO design → lang w/o classes). Reconsider target | escalate athanor.
Step 3: Execute
Write target form following map.
- Create target file(s) w/ structure + boilerplate
- Transmute each element per Step 2 map:
- Preserve behavioral contract — same ins → same outs
- Use target-native idioms not literal translations
- Maintain | improve err handling
- Handle deps:
- Replace src deps w/ target equivs
- No equiv → impl minimal adapter
- Inline comments ONLY where transformation non-obvious
Got: Complete target impl following map. Reads like written natively in target, not mechanically translated.
If err: Specific element resists → isolate. Transform everything else first, tackle resistant w/ focused attention. Truly can't be transmuted → doc why + workaround.
Step 4: Verify Behavioral Equivalence
Confirm transmuted preserves original's behavior.
- Run behavioral contract tests vs target impl
- Per test:
- Same ins → same outs (within tolerance for numeric conversions)
- Same err conditions → equiv err signals
- Side effects (if any) preserved | doc'd as changed
- Check edge cases explicit:
- Null/NA/undefined handling
- Empty collections
- Boundary values (max int, empty string, zero-length arrays)
- Target adds capabilities (type safety) → verify those too
Got: All behavioral contract tests pass. Edge cases handled equivalent. Behavioral diffs doc'd + intentional.
If err: Tests fail → diff src vs target behavior, find divergence. Fix target → match src contract. Divergence intentional (fixing src bug) → doc explicit.
Check
Traps
- Literal translation: Python-in-R | Java-in-JS vs using target idioms. Result should look native.
- Skip behavioral tests: Transmute w/o tests → can't verify equivalence. Write characterization tests first.
- Ignore edge cases: Happy path transmutes easy; edge cases hide bugs.
- Over-engineer adapter: Dep needs 200-line adapter → scope too large.
- Transmute comments verbatim: Comments explain target code, not echo src. Rewrite.
→
athanor — Full 4-stage transformation for systems too large for single transmute
chrysopoeia — Optimizing transmuted code for max value extraction
review-software-architecture — Post-transmutation arch review for larger conversions
serialize-data-formats — Specialized data format conversion procedures
1---2name: transmute-103description: Transform single fn, module, data structure → another form preserving essential behavior. Lighter-weight than full athanor cycle, suitable for targeted conversions where in/out forms well-understood. Use → convert fn between langs, shift module between paradigms, migrate API consumer to new ver, convert data formats, replace dep — when scope = single fn, class, module not full system.4license: MIT5---67# Transmute89Transform specific code/data → another form (lang translation, paradigm shift, format conversion, API migration) preserving essential behavior + semantics.1011## Use When1213- Convert fn between langs (Python → R, JS → TS)14- Shift module between paradigms (class-based → functional, callbacks → async/await)15- Migrate API consumer v1 → v216- Convert data formats (CSV → Parquet, REST → GraphQL schema)17- Replace dep w/ equiv (moment.js → date-fns, jQuery → vanilla JS)18- Scope = single fn, class, module (NOT full system)1920## In2122- **Required**: Source (file path, fn name, data sample)23- **Required**: Target form (lang, paradigm, format, API ver)24- **Optional**: Behavioral contract (tests, type signatures, expected I/O pairs)25- **Optional**: Constraints (backward compat, perf budget)2627## Do2829### Step 1: Analyze Source3031Understand exactly what src does before transforming.32331. Read src completely — every branch, edge case, err path342. ID **behavioral contract**:35 - What ins accepts? (types, ranges, edge cases)36 - What outs produces? (return values, side effects, err signals)37 - What invariants maintains? (ordering, uniqueness, ref integrity)383. Catalog deps: what src imports, calls, relies on?394. Tests exist → read for expected behavior405. No tests → write behavioral characterization tests before transmuting4142**Got:** Complete understanding of what src does (not how). Behavioral contract explicit + testable.4344**If err:** Src too complex for single transmute → break into smaller pieces | escalate to full `athanor` proc. Behavior ambiguous → ask clarification vs guess.4546### Step 2: Map Source → Target4748Design transformation mapping.49501. Per src element, ID target equivalent:51 - Lang constructs: loops → map/filter, classes → closures52 - API calls: old endpoint → new, req/res shape changes53 - Data types: dataframe cols → schema fields, nested JSON → flat tables542. ID elements w/ **no direct equiv**:55 - Src features missing in target (pattern matching in lang w/o it)56 - Target idioms not in src (R vectorization vs Python loops)573. Per gap, choose adaptation strategy:58 - Emulate: reproduce behavior w/ target-native constructs59 - Simplify: src construct was workaround → use target's native solution60 - Document: behavior changes slightly → note explicit614. Write **transformation map**: src → target per piece6263**Got:** Complete mapping where every src element has target dest. Gaps ID'd + adaptation chosen.6465**If err:** Too many no direct equivs → transformation may be inappropriate (highly OO design → lang w/o classes). Reconsider target | escalate `athanor`.6667### Step 3: Execute6869Write target form following map.70711. Create target file(s) w/ structure + boilerplate722. Transmute each element per Step 2 map:73 - Preserve behavioral contract — same ins → same outs74 - Use target-native idioms not literal translations75 - Maintain | improve err handling763. Handle deps:77 - Replace src deps w/ target equivs78 - No equiv → impl minimal adapter794. Inline comments ONLY where transformation non-obvious8081**Got:** Complete target impl following map. Reads like written natively in target, not mechanically translated.8283**If err:** Specific element resists → isolate. Transform everything else first, tackle resistant w/ focused attention. Truly can't be transmuted → doc why + workaround.8485### Step 4: Verify Behavioral Equivalence8687Confirm transmuted preserves original's behavior.88891. Run behavioral contract tests vs target impl902. Per test:91 - Same ins → same outs (within tolerance for numeric conversions)92 - Same err conditions → equiv err signals93 - Side effects (if any) preserved | doc'd as changed943. Check edge cases explicit:95 - Null/NA/undefined handling96 - Empty collections97 - Boundary values (max int, empty string, zero-length arrays)984. Target adds capabilities (type safety) → verify those too99100**Got:** All behavioral contract tests pass. Edge cases handled equivalent. Behavioral diffs doc'd + intentional.101102**If err:** Tests fail → diff src vs target behavior, find divergence. Fix target → match src contract. Divergence intentional (fixing src bug) → doc explicit.103104## Check105106- [ ] Src fully analyzed w/ explicit behavioral contract107- [ ] Transformation map covers every src element108- [ ] Gaps ID'd w/ adaptation strategies doc'd109- [ ] Target uses native idioms (not literal translation)110- [ ] All behavioral contract tests pass vs target111- [ ] Edge cases verified (null, empty, boundary)112- [ ] Deps resolved w/ target equivs113- [ ] Behavioral diffs doc'd + intentional114115## Traps116117- **Literal translation**: Python-in-R | Java-in-JS vs using target idioms. Result should look native.118- **Skip behavioral tests**: Transmute w/o tests → can't verify equivalence. Write characterization tests first.119- **Ignore edge cases**: Happy path transmutes easy; edge cases hide bugs.120- **Over-engineer adapter**: Dep needs 200-line adapter → scope too large.121- **Transmute comments verbatim**: Comments explain target code, not echo src. Rewrite.122123## →124125- `athanor` — Full 4-stage transformation for systems too large for single transmute126- `chrysopoeia` — Optimizing transmuted code for max value extraction127- `review-software-architecture` — Post-transmutation arch review for larger conversions128- `serialize-data-formats` — Specialized data format conversion procedures