Transmute
Transform a specific piece of code or data from one form to another — language translation, paradigm shift, format conversion, or API migration — while preserving essential behavior and semantics.
When to Use
- Converting a function from one language to another (Python to R, JavaScript to TypeScript)
- Shifting a module from one paradigm (class-based to functional, callbacks to async/await)
- Migrating an API consumer from v1 to v2 of an external service
- Converting data between formats (CSV to Parquet, REST to GraphQL schema)
- Replacing a dependency with an equivalent (moment.js to date-fns, jQuery to vanilla JS)
- When the transformation scope is a single function, class, or module (not a full system)
Inputs
- Required: Source material (file path, function name, or data sample)
- Required: Target form (language, paradigm, format, or API version)
- Optional: Behavioral contract (tests, type signatures, or expected I/O pairs)
- Optional: Constraints (must maintain backward compatibility, performance budget)
Procedure
Step 1: Analyze the Source Material
Understand exactly what the source does before attempting transformation.
- Read the source completely — every branch, edge case, and error path
- Identify the behavioral contract:
- What inputs does it accept? (types, ranges, edge cases)
- What outputs does it produce? (return values, side effects, error signals)
- What invariants does it maintain? (ordering, uniqueness, referential integrity)
- Catalog dependencies: what does the source import, call, or rely on?
- If tests exist, read them to understand expected behavior
- If no tests exist, write behavioral characterization tests before transmuting
Expected: A complete understanding of what the source does (not how it does it). The behavioral contract is explicit and testable.
On failure: If the source is too complex for a single transmute, consider breaking it into smaller pieces or escalating to the full athanor procedure. If behavior is ambiguous, ask for clarification rather than guessing.
Step 2: Map Source to Target Form
Design the transformation mapping.
- For each element in the source, identify the target equivalent:
- Language constructs: loops → map/filter, classes → closures, etc.
- API calls: old endpoint → new endpoint, request/response shape changes
- Data types: data frame columns → schema fields, nested JSON → flat tables
- Identify elements with no direct equivalent:
- Source features missing in target (e.g., pattern matching in a language without it)
- Target idioms that don't exist in source (e.g., R's vectorization vs. Python loops)
- For each gap, choose an adaptation strategy:
- Emulate: reproduce the behavior with target-native constructs
- Simplify: if the source construct was a workaround, use the target's native solution
- Document: if behavior changes slightly, note the difference explicitly
- Write the transformation map: source element → target element, for every piece
Expected: A complete mapping where every source element has a target destination. Gaps are identified and adaptation strategies chosen.
On failure: If too many elements lack direct equivalents, the transformation may be inappropriate (e.g., transmuting a highly object-oriented design into a language without classes). Reconsider the target form or escalate to athanor.
Step 3: Execute the Transformation
Write the target form following the map.
- Create the target file(s) with appropriate structure and boilerplate
- Transmute each element following the map from Step 2:
- Preserve the behavioral contract — same inputs produce same outputs
- Use target-native idioms rather than literal translations
- Maintain or improve error handling
- Handle dependencies:
- Replace source dependencies with target equivalents
- If a dependency has no equivalent, implement a minimal adapter
- Add inline comments only where the transformation was non-obvious
Expected: A complete target implementation that follows the transformation map. The code reads like it was written natively in the target form, not mechanically translated.
On failure: If a specific element resists transformation, isolate it. Transform everything else first, then tackle the resistant element with focused attention. If it truly cannot be transmuted, document why and provide a workaround.
Step 4: Verify Behavioral Equivalence
Confirm the transmuted form preserves the original's behavior.
- Run the behavioral contract tests against the target implementation
- For each test case, verify:
- Same inputs → same outputs (within acceptable tolerance for numeric conversions)
- Same error conditions → equivalent error signals
- Side effects (if any) are preserved or documented as changed
- Check edge cases explicitly:
- Null/NA/undefined handling
- Empty collections
- Boundary values (max int, empty string, zero-length arrays)
- If the target form adds capabilities (e.g., type safety), verify those too
Expected: All behavioral contract tests pass. Edge cases are handled equivalently. Any behavioral differences are documented and intentional.
On failure: If tests fail, diff the source and target behavior to find the divergence. Fix the target to match the source contract. If the divergence is intentional (e.g., fixing a bug in the original), document it explicitly.
Validation Checklist
Common Pitfalls
- Literal translation: Writing Python-in-R or Java-in-JavaScript instead of using target idioms. The result should look native
- Skipping behavioral tests: Transmuting without tests means you can't verify equivalence. Write characterization tests first
- Ignoring edge cases: The happy path transmutes easily; edge cases are where bugs hide
- Over-engineering the adapter: If a dependency needs a 200-line adapter, the transmutation scope is too large
- Transmuting comments verbatim: Comments should explain the target code, not echo the source. Rewrite them
Related Skills
athanor — Full four-stage transformation for systems too large for a single transmute
chrysopoeia — Optimizing transmuted code for maximum value extraction
review-software-architecture — Post-transmutation architecture review for larger conversions
serialize-data-formats — Specialized data format conversion procedures
1---2name: transmute3description: Transform a single function, module, or data structure from one form to another while preserving its essential behavior. Lighter-weight than the full athanor cycle, suitable for targeted conversions where the input and output forms are well-understood. Use when converting a function between languages, shifting a module between paradigms, migrating an API consumer to a new version, converting data formats, or replacing a dependency — when the transformation scope is a single function, class, or module rather than a full system.4license: MIT5---67# Transmute89Transform a specific piece of code or data from one form to another — language translation, paradigm shift, format conversion, or API migration — while preserving essential behavior and semantics.1011## When to Use1213- Converting a function from one language to another (Python to R, JavaScript to TypeScript)14- Shifting a module from one paradigm (class-based to functional, callbacks to async/await)15- Migrating an API consumer from v1 to v2 of an external service16- Converting data between formats (CSV to Parquet, REST to GraphQL schema)17- Replacing a dependency with an equivalent (moment.js to date-fns, jQuery to vanilla JS)18- When the transformation scope is a single function, class, or module (not a full system)1920## Inputs2122- **Required**: Source material (file path, function name, or data sample)23- **Required**: Target form (language, paradigm, format, or API version)24- **Optional**: Behavioral contract (tests, type signatures, or expected I/O pairs)25- **Optional**: Constraints (must maintain backward compatibility, performance budget)2627## Procedure2829### Step 1: Analyze the Source Material3031Understand exactly what the source does before attempting transformation.32331. Read the source completely — every branch, edge case, and error path342. Identify the **behavioral contract**:35 - What inputs does it accept? (types, ranges, edge cases)36 - What outputs does it produce? (return values, side effects, error signals)37 - What invariants does it maintain? (ordering, uniqueness, referential integrity)383. Catalog dependencies: what does the source import, call, or rely on?394. If tests exist, read them to understand expected behavior405. If no tests exist, write behavioral characterization tests before transmuting4142**Expected:** A complete understanding of what the source does (not how it does it). The behavioral contract is explicit and testable.4344**On failure:** If the source is too complex for a single transmute, consider breaking it into smaller pieces or escalating to the full `athanor` procedure. If behavior is ambiguous, ask for clarification rather than guessing.4546### Step 2: Map Source to Target Form4748Design the transformation mapping.49501. For each element in the source, identify the target equivalent:51 - Language constructs: loops → map/filter, classes → closures, etc.52 - API calls: old endpoint → new endpoint, request/response shape changes53 - Data types: data frame columns → schema fields, nested JSON → flat tables542. Identify elements with **no direct equivalent**:55 - Source features missing in target (e.g., pattern matching in a language without it)56 - Target idioms that don't exist in source (e.g., R's vectorization vs. Python loops)573. For each gap, choose an adaptation strategy:58 - Emulate: reproduce the behavior with target-native constructs59 - Simplify: if the source construct was a workaround, use the target's native solution60 - Document: if behavior changes slightly, note the difference explicitly614. Write the **transformation map**: source element → target element, for every piece6263**Expected:** A complete mapping where every source element has a target destination. Gaps are identified and adaptation strategies chosen.6465**On failure:** If too many elements lack direct equivalents, the transformation may be inappropriate (e.g., transmuting a highly object-oriented design into a language without classes). Reconsider the target form or escalate to `athanor`.6667### Step 3: Execute the Transformation6869Write the target form following the map.70711. Create the target file(s) with appropriate structure and boilerplate722. Transmute each element following the map from Step 2:73 - Preserve the behavioral contract — same inputs produce same outputs74 - Use target-native idioms rather than literal translations75 - Maintain or improve error handling763. Handle dependencies:77 - Replace source dependencies with target equivalents78 - If a dependency has no equivalent, implement a minimal adapter794. Add inline comments only where the transformation was non-obvious8081**Expected:** A complete target implementation that follows the transformation map. The code reads like it was written natively in the target form, not mechanically translated.8283**On failure:** If a specific element resists transformation, isolate it. Transform everything else first, then tackle the resistant element with focused attention. If it truly cannot be transmuted, document why and provide a workaround.8485### Step 4: Verify Behavioral Equivalence8687Confirm the transmuted form preserves the original's behavior.88891. Run the behavioral contract tests against the target implementation902. For each test case, verify:91 - Same inputs → same outputs (within acceptable tolerance for numeric conversions)92 - Same error conditions → equivalent error signals93 - Side effects (if any) are preserved or documented as changed943. Check edge cases explicitly:95 - Null/NA/undefined handling96 - Empty collections97 - Boundary values (max int, empty string, zero-length arrays)984. If the target form adds capabilities (e.g., type safety), verify those too99100**Expected:** All behavioral contract tests pass. Edge cases are handled equivalently. Any behavioral differences are documented and intentional.101102**On failure:** If tests fail, diff the source and target behavior to find the divergence. Fix the target to match the source contract. If the divergence is intentional (e.g., fixing a bug in the original), document it explicitly.103104## Validation Checklist105106- [ ] Source material fully analyzed with explicit behavioral contract107- [ ] Transformation map covers every source element108- [ ] Gaps identified with adaptation strategies documented109- [ ] Target implementation uses native idioms (not literal translation)110- [ ] All behavioral contract tests pass against target111- [ ] Edge cases verified (null, empty, boundary values)112- [ ] Dependencies resolved with target equivalents113- [ ] Any behavioral differences documented and intentional114115## Common Pitfalls116117- **Literal translation**: Writing Python-in-R or Java-in-JavaScript instead of using target idioms. The result should look native118- **Skipping behavioral tests**: Transmuting without tests means you can't verify equivalence. Write characterization tests first119- **Ignoring edge cases**: The happy path transmutes easily; edge cases are where bugs hide120- **Over-engineering the adapter**: If a dependency needs a 200-line adapter, the transmutation scope is too large121- **Transmuting comments verbatim**: Comments should explain the target code, not echo the source. Rewrite them122123## Related Skills124125- `athanor` — Full four-stage transformation for systems too large for a single transmute126- `chrysopoeia` — Optimizing transmuted code for maximum value extraction127- `review-software-architecture` — Post-transmutation architecture review for larger conversions128- `serialize-data-formats` — Specialized data format conversion procedures