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 scoringregex-- 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
| Type | Description |
|---|---|
SptBooster | Main API for applying code edits |
Config | Configuration for chunk limits and thresholds |
EditRequest | Input describing the edit to apply |
EditResult | Output with merged code and confidence score |
CodeChunk | A parsed region of source code |
Language | Supported programming language enum |
MergeStrategy | How the edit was applied (ExactReplace, FuzzyReplace, etc.) |
TemplateEngine | Fast-path template-based code transforms |
SptBoosterError | Error type for parsing and merge failures |