splice 0.1.1

Span-safe refactoring kernel for Rust using SQLiteGraph
Documentation

Splice

Span-safe refactoring kernel for Rust using tree-sitter and cargo check.

Status: MVP / Proof of Concept Version: 0.1.0 License: GPL-3.0-or-later

What This Is

Splice is a command-line tool that performs byte-accurate, AST-validated replacements of Rust code. It replaces function bodies, struct definitions, and enum variants with validation.

What This Is NOT

  • An IDE - Use Rust Analyzer or IntelliJ Rust
  • A semantic refactoring tool - It doesn't track cross-file references
  • A complete solution - It's a focused tool for one specific job
  • Production-hardened - It's an MVP with known limitations

What It Does

  • Replaces function bodies, struct definitions, enum variants
  • Validates syntax with tree-sitter after every patch
  • Validates compilation with cargo check after every patch
  • Rolls back atomically on any failure
  • Orchestrates multi-step refactors via JSON plans

Known Limitations

  • No cross-file reference tracking
  • No persistent database
  • No resume mode for failed plans
  • No dry-run mode
  • No auto-discovery of symbols
  • Single-file symbol resolution only

Installation

git clone https://github.com/oldnordic/splice.git
cd splice
cargo build --release
mkdir -p ~/.local/bin
cp target/release/splice ~/.local/bin/splice

Quick Start

Single Patch

# Create replacement file
cat > new_greet.rs << 'EOF'
pub fn greet(name: &str) -> String {
    format!("Hi, {}!", name)
}
EOF

# Apply patch
splice patch \
  --file src/lib.rs \
  --symbol greet \
  --kind function \
  --with new_greet.rs

Multi-Step Plan

# Create plan.json
cat > plan.json << 'EOF'
{
  "steps": [
    {
      "file": "src/lib.rs",
      "symbol": "foo",
      "kind": "function",
      "with": "patches/foo.rs"
    }
  ]
}
EOF

# Execute plan
splice plan --file plan.json

Documentation

  • manual.md - Complete user manual
  • QUICKSTART.md - Quick reference

Requirements

  • Rust 1.70+ (for building)
  • Cargo workspace (for validation)
  • tree-sitter-rust (bundled)

Architecture

  • src/cli/ - CLI argument parsing
  • src/ingest/ - Rust file parsing
  • src/graph/ - SQLiteGraph integration
  • src/resolve/ - Symbol to byte span resolution
  • src/patch/ - Span-safe replacement + validation
  • src/validate/ - Tree-sitter + cargo check validation
  • src/plan/ - JSON plan orchestration

Validation Gates

Every patch passes:

  1. UTF-8 boundary validation
  2. Tree-sitter reparse (syntax check)
  3. Cargo check (compilation check)

Development Status

Complete Features:

  • Span-safe byte replacement
  • Tree-sitter validation
  • Cargo check validation
  • Atomic rollback
  • Multi-step plan execution
  • CLI interface

Not Implemented:

  • Cross-file reference tracking
  • Persistent symbol database
  • Resume mode for failed plans
  • Dry-run mode
  • Auto-discovery of symbols

Testing

cargo test

Test Coverage: 22/22 tests passing

Examples

  • tests/cli_tests.rs - CLI integration
  • tests/patch_tests.rs - Patch validation
  • tests/integration_refactor.rs - Symbol resolution

Contributing

This is an MVP / proof-of-concept. The codebase is feature-complete as of v0.1.0. No new features are planned.

License

GPL-3.0-or-later

Disclaimer

This is experimental software. Use at your own risk. Always commit your changes before running Splice.