Codebase Analysis
Extract an Intermediate Representation (IR) from source code to enable cross-language conversion and analysis.
Usage
/codebase-analysis <path> [--language <lang>] [--depth <0-4>] [--output <format>]
Parameters
| Parameter |
Description |
Default |
path |
File or directory to analyze |
Required |
--language |
Source language (auto-detected if omitted) |
auto |
--depth |
IR extraction depth (0-4) |
4 |
--output |
Output format (json, yaml, summary) |
json |
Process
1. Language Detection
If --language is not specified, detect based on:
- File extension (
.py, .rs, .ts, .go, .scala, .roc)
- Shebang line
- Package files (
pyproject.toml, Cargo.toml, package.json)
2. Module Discovery
Identify all modules and their relationships:
- Import/export statements
- Module boundaries
- Dependency graph
3. Type Extraction
Extract type definitions and relationships:
- Struct/class/record definitions
- Enum/ADT/union types
- Type aliases and generics
- Trait/interface definitions
4. Function Analysis
Extract function signatures and semantics:
- Parameter types and defaults
- Return types
- Purity annotations (where inferrable)
- Effect annotations (I/O, async, etc.)
5. Semantic Annotation
Infer semantic properties:
- Nullability (Option, nullable, undefined)
- Mutability (const, let, var)
- Error handling patterns (Result, exceptions, error returns)
- Concurrency patterns (async, channels, actors)
6. Gap Detection
Mark concepts that may not convert cleanly:
- Language-specific patterns (ownership, HKT, macros)
- Family-specific idioms (pattern matching, effects)
- Cross-language semantic gaps
Output
IR Layers
The IR is organized into 5 layers of increasing abstraction:
| Layer |
Name |
Description |
| 0 |
Expressions |
AST-level expression nodes |
| 1 |
Data Flow |
Value flow through variables |
| 2 |
Control Flow |
Execution paths and branches |
| 3 |
Type System |
Type definitions and relationships |
| 4 |
Module Structure |
Imports, exports, dependencies |
IR Schema
ir:
version: "1.0"
source_language: "python"
source_path: "src/main.py"
modules:
- name: "main"
imports: [...]
exports: [...]
types:
- name: "User"
kind: "struct"
properties:
- name: "id"
type: "int"
- name: "name"
type: "str"
functions:
- name: "get_user"
parameters:
- name: "id"
type: "int"
return_type: "Optional[User]"
purity: "pure"
annotations:
- kind: "PY-003"
target: "get_user"
message: "Generator usage detected"
severity: "medium"
Gap Annotations
Gaps are annotated with:
kind: Gap identifier (e.g., "PY-RS-001")
target: What element has the gap
message: Human-readable description
severity: critical, high, medium, low, info
suggestion: Recommended resolution
Examples
Analyze a Python file
/codebase-analysis src/models.py
Analyze a Rust crate with summary
/codebase-analysis ./src --language rust --output summary
Analyze specific depth level
/codebase-analysis lib/ --depth 2 # Control flow only
Reference
- IR Overview
- IR Schema
- Extraction Guide
- Tool Usage
- Language Families
- Python Patterns
- Rust Patterns
- TypeScript Patterns
Related Skills
1---2name: codebase-analysis3version: 1.0.04description: Extract IR from source code for cross-language conversion5category: conversion6languages: [python, typescript, rust, java, go, scala, roc, kotlin, swift, elixir]7tools: [ir-extract-python, ir-extract-rust, ir-extract-typescript, ir-extract-go, ir-extract-scala, ir-extract-roc]8metadata:9 source: https://skillmd.com/skills/arustydev/codebase-analysis10---1112# Codebase Analysis1314Extract an Intermediate Representation (IR) from source code to enable cross-language conversion and analysis.1516## Usage1718```19/codebase-analysis <path> [--language <lang>] [--depth <0-4>] [--output <format>]20```2122### Parameters2324| Parameter | Description | Default |25|-----------|-------------|---------|26| `path` | File or directory to analyze | Required |27| `--language` | Source language (auto-detected if omitted) | auto |28| `--depth` | IR extraction depth (0-4) | 4 |29| `--output` | Output format (json, yaml, summary) | json |3031## Process3233### 1. Language Detection3435If `--language` is not specified, detect based on:36- File extension (`.py`, `.rs`, `.ts`, `.go`, `.scala`, `.roc`)37- Shebang line38- Package files (`pyproject.toml`, `Cargo.toml`, `package.json`)3940### 2. Module Discovery4142Identify all modules and their relationships:43- Import/export statements44- Module boundaries45- Dependency graph4647### 3. Type Extraction4849Extract type definitions and relationships:50- Struct/class/record definitions51- Enum/ADT/union types52- Type aliases and generics53- Trait/interface definitions5455### 4. Function Analysis5657Extract function signatures and semantics:58- Parameter types and defaults59- Return types60- Purity annotations (where inferrable)61- Effect annotations (I/O, async, etc.)6263### 5. Semantic Annotation6465Infer semantic properties:66- Nullability (Option, nullable, undefined)67- Mutability (const, let, var)68- Error handling patterns (Result, exceptions, error returns)69- Concurrency patterns (async, channels, actors)7071### 6. Gap Detection7273Mark concepts that may not convert cleanly:74- Language-specific patterns (ownership, HKT, macros)75- Family-specific idioms (pattern matching, effects)76- Cross-language semantic gaps7778## Output7980### IR Layers8182The IR is organized into 5 layers of increasing abstraction:8384| Layer | Name | Description |85|-------|------|-------------|86| 0 | Expressions | AST-level expression nodes |87| 1 | Data Flow | Value flow through variables |88| 2 | Control Flow | Execution paths and branches |89| 3 | Type System | Type definitions and relationships |90| 4 | Module Structure | Imports, exports, dependencies |9192### IR Schema9394```yaml95ir:96 version: "1.0"97 source_language: "python"98 source_path: "src/main.py"99100 modules:101 - name: "main"102 imports: [...]103 exports: [...]104105 types:106 - name: "User"107 kind: "struct"108 properties:109 - name: "id"110 type: "int"111 - name: "name"112 type: "str"113114 functions:115 - name: "get_user"116 parameters:117 - name: "id"118 type: "int"119 return_type: "Optional[User]"120 purity: "pure"121122 annotations:123 - kind: "PY-003"124 target: "get_user"125 message: "Generator usage detected"126 severity: "medium"127```128129### Gap Annotations130131Gaps are annotated with:132- `kind`: Gap identifier (e.g., "PY-RS-001")133- `target`: What element has the gap134- `message`: Human-readable description135- `severity`: critical, high, medium, low, info136- `suggestion`: Recommended resolution137138## Examples139140### Analyze a Python file141142```bash143/codebase-analysis src/models.py144```145146### Analyze a Rust crate with summary147148```bash149/codebase-analysis ./src --language rust --output summary150```151152### Analyze specific depth level153154```bash155/codebase-analysis lib/ --depth 2 # Control flow only156```157158## Reference159160- [IR Overview](reference/ir/overview.md)161- [IR Schema](reference/ir/schema.md)162- [Extraction Guide](reference/ir/extraction-guide.md)163- [Tool Usage](reference/ir/tools.md)164- [Language Families](reference/families/overview.md)165- [Python Patterns](reference/languages/python.md)166- [Rust Patterns](reference/languages/rust.md)167- [TypeScript Patterns](reference/languages/typescript.md)168169## Related Skills170171- [codebase-implement-from-ir](../codebase-implement-from-ir/SKILL.md) - Synthesize code from IR172- [idiomatic-python](../idiomatic-python/SKILL.md) - Python-specific idioms173- [idiomatic-rust](../idiomatic-rust/SKILL.md) - Rust-specific idioms