Agents Implement from IR

Synthesize target language code from IR

install
source · Clone the upstream repo
git clone https://github.com/aRustyDev/agents
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/aRustyDev/agents "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/plans/merge-convert-skills/skills/codebase-implement-from-ir" ~/.claude/skills/arustydev-agents-implement-from-ir && rm -rf "$T"
manifest: .claude/plans/merge-convert-skills/skills/codebase-implement-from-ir/SKILL.md
source content

Implement from IR

Generate idiomatic code in a target language from an Intermediate Representation (IR).

Usage

/codebase-implement-from-ir <ir-path> --target <language> [--style <mode>] [--gaps <handling>]

Parameters

ParameterDescriptionDefault
ir-path
Path to IR file (JSON/YAML)Required
--target
Target languageRequired
--style
Generation style (minimal, idiomatic, verbose)idiomatic
--gaps
Gap handling (warn, error, annotate, ignore)warn

Process

1. IR Validation

Validate the input IR:

  • Schema compliance
  • Required fields present
  • Internal consistency (referenced types exist)

2. Gap Resolution

Review detected gaps and apply mitigations:

Gap SeverityDefault Action
CriticalHalt, require human decision
HighWarn, suggest alternatives
MediumAuto-convert with TODO comment
LowAuto-convert silently
InfoLog for reference

3. Pattern Translation

Map IR patterns to target idioms:

Type Mappings

SourcePythonRustTypeScriptGoScala
int
int
i64
number
int64
Long
str
str
String
string
string
String
bool
bool
bool
boolean
bool
Boolean
Option[T]
Optional[T]
Option<T>
T | undefined
*T
Option[T]
Result[T,E]
Result[T,E]
Result<T,E>
Result<T,E>
(T, error)
Either[E,T]
List[T]
list[T]
Vec<T>
T[]
[]T
List[T]
Dict[K,V]
dict[K,V]
HashMap<K,V>
Map<K,V>
map[K]V
Map[K,V]

Pattern Mappings

PatternSource IRTarget Transformation
Pattern Match
MatchExpression
switch/if-else chain (if needed)
ADT
TypeDef.adt
sealed class/enum
Type Class
TypeClassDef
trait/interface + instances
Async
AsyncAnnotation
async/await, Future, goroutine
Error Handling
ResultType
Result, Either, (T, error)

4. Code Generation

Generate syntactically correct code:

  • Proper indentation and formatting
  • Valid identifier names
  • Correct import statements
  • Appropriate module structure

5. Idiom Application

Apply target-language conventions:

  • Naming conventions (snake_case, camelCase, PascalCase)
  • Documentation style (docstrings, JSDoc, rustdoc)
  • Error handling idioms
  • Common patterns (builder, factory, etc.)

6. Formatting

Format code with target's standard tools:

  • Python:
    black
    ,
    ruff
  • Rust:
    rustfmt
  • TypeScript:
    prettier
  • Go:
    gofmt
  • Scala:
    scalafmt

Output

Generated Code Structure

output/
├── src/
│   ├── models.{ext}      # Type definitions
│   ├── services.{ext}    # Functions and methods
│   └── utils.{ext}       # Helper functions
├── tests/
│   └── test_models.{ext} # Generated test stubs
├── Cargo.toml            # (Rust) Package manifest
├── pyproject.toml        # (Python) Package manifest
└── GAPS.md               # Gap resolution notes

Gap Resolution Report

# Gap Resolution Report

## Critical Gaps (Require Human Decision)

### 1. Higher-Kinded Types (SC-001)
- **Source**: `Functor[F[_]]` in `types.scala`
- **Target**: TypeScript
- **Issue**: TypeScript cannot express HKT
- **Options**:
  1. Monomorphize to specific types (List, Option, etc.)
  2. Use type-level programming with conditional types
  3. Simplify to concrete implementation

## High Severity Gaps (Auto-Converted with Warning)

### 1. Ownership Transfer (RS-001)
- **Source**: `fn take(self)` in `entity.rs`
- **Target**: Python
- **Resolution**: Converted to normal method, added runtime validation

Semantic Preservation Levels

Target these levels in order of priority:

1. Semantically Equivalent

Same observable behavior in all cases:

  • Pure functions map directly
  • Immutable data structures preserve semantics
  • Error handling maintains all cases

2. Idiomatically Correct

Follows target conventions even if slightly different:

  • Use target-native collections
  • Apply target naming conventions
  • Use target error handling patterns

3. Optimized

Efficient for target platform:

  • Use target-specific optimizations
  • Leverage platform features
  • Minimize overhead from conversion

Examples

Synthesize Rust from Python IR

/codebase-implement-from-ir analysis.ir.json --target rust

Synthesize with verbose style

/codebase-implement-from-ir analysis.ir.json --target python --style verbose

Strict gap handling

/codebase-implement-from-ir analysis.ir.json --target go --gaps error

Reference

Target-Specific Guides

Related Skills