Splice
Span-safe refactoring kernel for 7 languages using tree-sitter and SQLiteGraph.
Version: 2.2.2 License: GPL-3.0-or-later
What This Is
Splice is a command-line tool that performs byte-accurate, AST-validated refactoring operations on code in 7 languages: Rust, Python, C, C++, Java, JavaScript, and TypeScript. It can replace function bodies, delete symbols, apply batch changes, perform pattern replacements, query code graphs, and undo operations.
v2.2.2 Features
Splice v2.2.2 delivers a unified CLI interface with Magellan query commands for code discovery alongside span-safe editing:
- Unified CLI: Single tool for code graph queries (Magellan) and refactoring (Splice)
- Query Commands:
status,query,find,refs,filesfor code graph navigation - Export Command: Export graph data in JSON, JSONL, or CSV formats
- Magellan Integration: In-process library delegation for optimal performance
- CLI Alignment:
--output(human/json/pretty),--dbfor database path, Magellan-compatible exit codes - Error Handling: SPL-E091 Magellan error code with full error chain preservation
v2.2 Features
- Rich Span Extensions: Context, semantic kind, language, checksums, error codes
- Rich Span Advanced: Relationships (callers, callees, imports, exports), tool hints
- CLI Conventions:
-ndry-run,-A/-B/-Ccontext, unified diff, git-style exit codes - Enhanced Errors: SPL-E### codes, severity levels, fuzzy suggestions,
splice explain
v2.0 Features
- Structured JSON Output: All operations return structured JSON with explicit fields
- Span-Aware Metadata: Line and column coordinates in all output
- Deterministic Ordering: All operations return sorted results
- Validation Hooks: Pre/post-operation checksums verify code integrity
- Execution Logging: Complete audit trail in
.splice/operations.db - SQLiteGraph v1.0: Native V2 backend for improved performance
- Enhanced Safety: Eliminated unwrap() calls, comprehensive error handling
What This Is NOT
- An IDE or LSP server - Use Rust Analyzer, IntelliJ, PyCharm, VSCode, or your editor
- A general-purpose refactoring tool - Focused on specific operations
- A complete solution - It's a focused tool for specific jobs
- Production-hardened - Use with version control
What It Does
Edit Commands:
- patch: Replace function bodies, class definitions, enum variants with validation (single or batch)
- delete: Remove symbol definitions and all references (cross-file, Rust-only)
- apply-files: Multi-file pattern replacement with AST confirmation
- search: Pattern-based search with glob filtering
Query Commands (Magellan Integration):
- status: Display database statistics (files, symbols, references, calls, code_chunks)
- query: Query symbols by labels (language, kind) with optional context
- find: Locate symbols by name or symbol_id with disambiguation
- refs: Show callers/callees for a symbol (bidirectional traversal)
- files: List indexed files with optional symbol counts
- export: Export graph data (JSON, JSONL, CSV formats)
Utility Commands:
- undo: Restore files from backup manifest
- plan: Orchestrate multi-step refactors via JSON plans
- log: Query execution audit trail from operations.db
- explain: Get detailed explanations for error codes
Validation:
- Validates syntax with tree-sitter after every operation
- Validates compilation with language-specific compilers
- Rolls back atomically on any failure
Supported Languages
| Language | Extensions | Delete | Patch | Validation |
|---|---|---|---|---|
| Rust | .rs |
Full | Full | cargo check |
| Python | .py |
Basic | Full | python -m py_compile |
| C | .c, .h |
Basic | Full | gcc -fsyntax-only |
| C++ | .cpp, .hpp, .cc, .cxx |
Basic | Full | g++ -fsyntax-only |
| Java | .java |
Basic | Full | javac |
| JavaScript | .js, .mjs, .cjs |
Basic | Full | node --check |
| TypeScript | .ts, .tsx |
Basic | Full | tsc --noEmit |
Delete modes:
- Full: Finds all references across files (Rust only)
- Basic: Deletes definition only, no reference finding (other languages)
Installation
Or from source:
Quick Start
Delete a Symbol (Rust)
Delete a function and all its references:
Output (structured JSON):
Patch a Symbol (Rust)
Replace a function body:
Patch a Symbol (Python)
Patch a Symbol (TypeScript)
Multi-Step Plan
Batch Patch
Apply multiple patches at once from a JSON file:
Pattern Replace
Replace a pattern across multiple files:
# Replace "42" with "99" in all Python files
# With validation and backup
Preview Mode
Inspect changes before applying:
Backup and Undo
Create a backup before changes:
Restore from backup:
Query Symbols by Label (Magellan Integration)
# List all available labels
# Find all Rust functions
# Show code for each result
Get Code Chunks (Magellan Integration)
# Get code by byte span without re-reading the file
Query Commands (Magellan Integration)
# Show database statistics
# Find all functions in a file
# Find symbol by name
# Show call relationships
# List indexed files
# Export graph data
Commands
splice delete
Remove a symbol definition and all its references.
Optional Arguments:
--kind <KIND>: Symbol kind filter--language <LANG>: Language override--analyzer <MODE>: Validation mode (off, os, path)--create-backup: Create backup before deleting--operation-id <ID>: Custom operation ID for auditing--metadata <JSON>: Optional metadata attachment
Rust-specific features:
- Finds references across the entire workspace
- Tracks imports and re-exports
- Handles shadowing correctly
- Cross-file reference resolution
Other languages:
- Deletes the symbol definition only
- Use with
--languageflag or auto-detection from file extension
splice patch
Apply a patch to a symbol's span.
Optional Arguments:
--kind <KIND>: Symbol kind filter (function, method, class, struct, interface, enum, trait, impl, module, variable, constructor, type-alias)--language <LANG>: Language override (rust, python, c, cpp, java, java-script, type-script)--analyzer <MODE>: Validation mode (off, os, path)--preview: Run in preview mode without modifying files--batch <FILE>: JSON file describing batch replacements--create-backup: Create backup before patching--operation-id <ID>: Custom operation ID for auditing--metadata <JSON>: Optional metadata attachment
splice apply-files
Apply a pattern replacement to multiple files.
Required Arguments:
--glob <GLOB>: Glob pattern for matching files (e.g.,tests/**/*.rs,src/**/*.py)--find <PATTERN>: Text pattern to find--replace <REPLACEMENT>: Replacement text
Optional Arguments:
--language <LANG>: Language override (auto-detected from extension by default)--no-validate: Skip validation gates--create-backup: Create backup before applying--operation-id <ID>: Custom operation ID for auditing--metadata <JSON>: Optional metadata attachment
splice undo
Undo a previous operation by restoring from a backup manifest.
splice plan
Execute a multi-step refactoring plan.
splice query
Query symbols by labels using Magellan integration.
Optional Arguments:
--db <FILE>: Path to the Magellan database (required)--label <LABEL>: Label to query (can be specified multiple times for AND semantics)--list: List all available labels with counts--count: Count entities with specified label(s)--show-code: Show source code for each result
Available labels:
- Language labels:
rust,python,javascript,typescript,c,cpp,java - Symbol kind labels:
fn,method,struct,class,enum,interface,module,union,namespace,typealias
splice get
Get code chunks from the database using Magellan integration.
Required Arguments:
--db <FILE>: Path to the Magellan database--file <PATH>: File path--start <N>: Start byte offset--end <N>: End byte offset
splice status
Display database statistics.
Required Arguments:
--db <FILE>: Path to the Magellan database
Optional Arguments:
--output FORMAT: Output format (human, json, pretty) - default: human
splice find
Find symbols by name or symbol_id.
| )
Required Arguments:
--db <FILE>: Path to the Magellan database--name <NAME>: Symbol name to find--symbol-id <ID>: 16-character hex symbol ID
Optional Arguments:
--ambiguous: Show all matches for ambiguous names--output FORMAT: Output format (human, json, pretty)
splice refs
Show callers/callees for a symbol.
| )
Required Arguments:
--db <FILE>: Path to the Magellan database--name <NAME>: Symbol name--path <PATH>: File path (for disambiguation)
Optional Arguments:
--direction DIR: Relationship direction (in, out, both) - default: both--output FORMAT: Output format (human, json, pretty)
splice files
List indexed files.
Required Arguments:
--db <FILE>: Path to the Magellan database
Optional Arguments:
--symbols: Show symbol counts per file--output FORMAT: Output format (human, json, pretty)
splice export
Export graph data.
Required Arguments:
--db <FILE>: Path to the Magellan database--format FORMAT: Export format (json, jsonl, csv)--file <PATH>: Output file path
splice log
Query the execution audit trail from .splice/operations.db.
# Show recent operations
# Filter by operation type
# Filter by status
# Filter by date range
# Query specific execution
# Show statistics
# JSON output for programmatic access
Optional Arguments:
--operation-type <TYPE>: Filter by operation type (patch, delete, plan, apply-files)--status <STATUS>: Filter by status (success, failure, partial)--after <DATE>: Show operations after this date (ISO8601 format)--before <DATE>: Show operations before this date (ISO8601 format)--execution-id <ID>: Query specific execution by ID--format <FORMAT>: Output format (table, json) - default: table--stats: Show statistics summary instead of individual operations--limit <N>: Limit number of results (default: 50)
Output Fields:
- execution_id: Unique identifier for each operation
- operation_type: Type of operation performed
- status: Success/failure status
- timestamp: ISO8601 timestamp when operation started
- duration_ms: Operation duration in milliseconds
- command_line: Full command-line invocation
- workspace: Working directory path
- affected_files: Number of files modified
Documentation
- docs/magellan_integration.md - Magellan integration guide (query commands, export formats, LLM usage)
- manual.md - Complete user manual
- CHANGELOG.md - Version history
- docs/DIAGNOSTICS_HUMAN_LLM.md - CLI diagnostics contract for humans and LLMs, including rust-analyzer and multi-language validation output
Requirements
- Rust 1.70+ (for building)
- Language-specific compilers (for validation):
- Rust:
cargo - Python:
python - C/C++:
gcc/g++ - Java:
javac - JavaScript:
node - TypeScript:
tsc
- Rust:
Architecture
- src/cli/ - CLI argument parsing
- src/ingest/ - Symbol parsing for 7 languages
- src/graph/ - SQLiteGraph integration with Native V2 backend
- src/resolve/ - Symbol resolution and reference finding
- src/patch/ - Span-safe replacement + validation + batch operations + pattern replace + backup
- src/validate/ - Tree-sitter + compiler validation gates with checksum verification
- src/plan/ - JSON plan orchestration with deterministic ordering
- src/execution/ - Execution logging audit trail with operations.db
- src/output/ - Structured JSON output with v2.0 schema
- src/checksum/ - SHA-256 checksum computation for verification hooks
Validation Gates
Every operation passes:
- UTF-8 boundary validation
- Pre-operation checksum computation (SHA-256)
- Tree-sitter reparse (syntax check)
- Language-specific compiler check (cargo check, python -m py_compile, etc.)
- Post-operation checksum verification
- Atomic rollback on any failure
All operations are logged to .splice/operations.db with timestamps, durations, and command-line capture for complete auditability.
Testing
Test Coverage: 215+ tests passing, including:
- 171 unit tests for core functionality
- 26 Magellan integration tests for all 7 languages
- 18 cross-language compatibility tests
- End-to-end refactoring workflow tests
Feedback
If you use this tool and find a bug or miss a feature that would be useful, drop a line. It's appreciated.
License
GPL-3.0-or-later
Disclaimer
This software modifies source code. Always commit your changes before running Splice.
Integration with Magellan
Splice works best with Magellan for code graph indexing and querying.
Magellan is a code understanding and indexing library that provides:
- Multi-language parsing (Rust, Python, C, C++, Java, JavaScript, TypeScript)
- Symbol discovery and relationship tracking
- Call graph analysis
- Fast code graph queries
Links:
When you use Splice's query commands (status, query, find, refs, files, export), you're leveraging Magellan's powerful code graph capabilities through Splice's unified CLI interface.