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
- 12 Languages: TypeScript, JavaScript, Python, Rust, Go, Java, C, C++, Markdown, JSON, YAML, TOML
- 5 Transformation Modes: Structure, Signatures, Types, Minimal, Full
- Fast: 14.6ms for 3000-line files (verified benchmarks)
- Safe: Built-in DoS protections and memory limits
- Zero-copy: Efficient string slicing where possible
- Pure Library: No I/O - accepts
&str, returnsResult<String>
Installation
[]
= "1.0"
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 |
| C | .c, .h |
Full support |
| C++ | .cpp, .hpp, .cc, .hh, .cxx, .hxx |
Full support |
| Markdown | .md, .markdown |
Full support |
| JSON | .json |
Full support |
| YAML | .yaml, .yml |
Full support |
| TOML | .toml |
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: 14.6ms for 3000-line files (verified)
- 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