rskim-core
Core library for smart code reading and transformation.
Overview
rskim-core is a Rust library that transforms source code by intelligently removing implementation details while preserving structure, signatures, and types. Perfect for optimizing code for LLM context windows.
Features
- 6 Languages: TypeScript, JavaScript, Python, Rust, Go, Java
- 4 Transformation Modes: Structure, Signatures, Types, Full
- Fast: <50ms for 1000-line files
- Safe: Built-in DoS protections and memory limits
- Zero-copy: Efficient string slicing where possible
Installation
[]
= "0.2"
Usage
use ;
Transformation Modes
Structure Mode (70-80% reduction)
Removes function bodies while preserving signatures and structure.
let result = transform?;
Signatures Mode (85-92% reduction)
Extracts only function and method signatures.
let result = transform?;
Types Mode (90-95% reduction)
Extracts only type definitions (interfaces, enums, structs, etc.).
let result = transform?;
Full Mode (0% reduction)
Returns the original code unchanged.
let result = transform?;
Auto-Detection
Use transform_auto for automatic language detection from file paths:
use transform_auto;
use Path;
let result = transform_auto?;
Supported Languages
| Language | Extensions | Node Types |
|---|---|---|
| TypeScript | .ts, .tsx |
Full support |
| JavaScript | .js, .jsx, .mjs |
Full support |
| Python | .py |
Full support |
| Rust | .rs |
Full support |
| Go | .go |
Full support |
| Java | .java |
Full support |
Security
Built-in protections against:
- Stack overflow: Max recursion depth (500)
- Memory exhaustion: Max input size (50MB), max AST nodes (100k)
- UTF-8 violations: Boundary validation before string slicing
- Path traversal: Rejects
..in file paths
Performance
- Parse + Transform: <50ms for 1000-line files
- Token Reduction: 60-95% depending on mode
- Zero Allocations: Uses
&strslices where possible
Error Handling
All functions return Result<String, SkimError>:
use ;
match transform
CLI Tool
For command-line usage, see the rskim binary crate.
Links
License
MIT