rskim-core

Crates.iorskim-core
lib.rsrskim-core
version0.6.0
created_at2025-10-15 23:07:55.456573+00
updated_at2025-10-25 20:39:24.834721+00
descriptionCore library for smart code reading and transformation
homepage
repositoryhttps://github.com/dean0x/skim
max_upload_size
id1885094
size101,918
Dean Sharon (dean0x)

documentation

README

rskim-core

Core library for smart code reading and transformation.

Crates.io Documentation License: MIT

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: 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, returns Result<String>

Installation

[dependencies]
rskim-core = "0.3"

Usage

use rskim_core::{transform, Language, Mode};

fn main() {
    let source = r#"
function add(a: number, b: number): number {
    return a + b;
}
    "#;

    let result = transform(source, Language::TypeScript, Mode::Structure)
        .expect("Transformation failed");

    println!("{}", result);
    // Output: function add(a: number, b: number): number { /* ... */ }
}

Transformation Modes

Structure Mode (70-80% reduction)

Removes function bodies while preserving signatures and structure.

let result = transform(code, Language::TypeScript, Mode::Structure)?;

Signatures Mode (85-92% reduction)

Extracts only function and method signatures.

let result = transform(code, Language::Python, Mode::Signatures)?;

Types Mode (90-95% reduction)

Extracts only type definitions (interfaces, enums, structs, etc.).

let result = transform(code, Language::Rust, Mode::Types)?;

Full Mode (0% reduction)

Returns the original code unchanged.

let result = transform(code, Language::Java, Mode::Full)?;

Auto-Detection

Use transform_auto for automatic language detection from file paths:

use rskim_core::transform_auto;
use std::path::Path;

let result = transform_auto(
    source,
    Path::new("example.ts"),
    Mode::Structure
)?;

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: 14.6ms for 3000-line files (verified)
  • Token Reduction: 60-95% depending on mode
  • Zero Allocations: Uses &str slices where possible

Error Handling

All functions return Result<String, SkimError>:

use rskim_core::{transform, SkimError};

match transform(source, Language::TypeScript, Mode::Structure) {
    Ok(result) => println!("{}", result),
    Err(SkimError::ParseError(msg)) => eprintln!("Parse error: {}", msg),
    Err(SkimError::UnsupportedLanguage(ext)) => eprintln!("Unsupported: {}", ext),
    Err(e) => eprintln!("Error: {}", e),
}

CLI Tool

For command-line usage, see the rskim binary crate.

Links

License

MIT

Commit count: 0

cargo fmt