Skip to content

spt-booster

Fast code editing library using tree-sitter and similarity matching

Overview

spt-booster automatically applies code edits by finding the best matching location in existing source code. It uses tree-sitter parsing (or a lightweight regex-based parser for WASM targets) combined with text similarity algorithms to locate where an edit should be applied. This is the Tier 1 "Agent Booster" in the SPT 3-tier model routing system, enabling sub-millisecond code transforms without invoking an LLM.

Key Features

  • Tree-sitter parsing -- full AST-based code chunk extraction for JS/TS (optional feature)
  • Lite parser fallback -- regex-based parser for WASM and constrained environments
  • Template-based transforms -- fast path for common edits (var-to-const, add types) bypassing similarity matching
  • Similarity matching -- finds best-fit code chunks using string distance algorithms
  • Multi-language support -- JavaScript, TypeScript, Python, Rust, Go, Java, C, C++

Dependencies

Key internal dependencies:

  • tree-sitter / tree-sitter-javascript / tree-sitter-typescript -- AST parsing (optional)
  • strsim -- text similarity scoring
  • regex -- lite parser fallback

Usage

rust
use spt_booster::{SptBooster, Config, EditRequest, Language};

let config = Config::default();
let mut booster = SptBooster::new(config).unwrap();
let request = EditRequest {
    original_code: "let x = 1;".into(),
    edit_snippet: "const x = 1;".into(),
    language: Language::JavaScript,
    confidence_threshold: 0.8,
};
let result = booster.apply_edit(request).unwrap();

API Reference

Core Types

TypeDescription
SptBoosterMain API for applying code edits
ConfigConfiguration for chunk limits and thresholds
EditRequestInput describing the edit to apply
EditResultOutput with merged code and confidence score
CodeChunkA parsed region of source code
LanguageSupported programming language enum
MergeStrategyHow the edit was applied (ExactReplace, FuzzyReplace, etc.)
TemplateEngineFast-path template-based code transforms
SptBoosterErrorError type for parsing and merge failures

Released under the MIT License.