#tree-sitter #llm #code-analysis #ast

rskim-core

Core library for smart code reading and transformation

10 releases (4 breaking)

0.6.0 Oct 25, 2025
0.5.0 Oct 21, 2025
0.4.0 Oct 18, 2025
0.3.3 Oct 16, 2025
0.2.4 Oct 16, 2025

#71 in #code-analysis


Used in rskim

MIT license

60KB
914 lines

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.

License

MIT

Dependencies

~44MB
~1.5M SLoC