| Crates.io | splice |
| lib.rs | splice |
| version | 2.2.2 |
| created_at | 2025-12-24 03:04:19.755442+00 |
| updated_at | 2026-01-24 16:19:47.065352+00 |
| description | Span-safe refactoring kernel for 7 languages with Magellan code graph integration |
| homepage | |
| repository | https://github.com/oldnordic/splice |
| max_upload_size | |
| id | 2002680 |
| size | 2,341,796 |
Span-safe refactoring kernel for 7 languages using tree-sitter and SQLiteGraph.
Version: 2.2.2 License: GPL-3.0-or-later
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.
Splice v2.2.2 delivers a unified CLI interface with Magellan query commands for code discovery alongside span-safe editing:
status, query, find, refs, files for code graph navigation--output (human/json/pretty), --db for database path, Magellan-compatible exit codes-n dry-run, -A/-B/-C context, unified diff, git-style exit codessplice explain.splice/operations.dbEdit Commands:
Query Commands (Magellan Integration):
Utility Commands:
Validation:
| 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:
cargo install splice
Or from source:
git clone https://github.com/oldnordic/splice.git
cd splice
cargo build --release
cp target/release/splice ~/.local/bin/
Delete a function and all its references:
splice delete --file src/lib.rs --symbol helper --kind function
Output (structured JSON):
{
"version": "2.0.0",
"operation_id": "20250118_123456_abc123",
"operation_type": "delete",
"status": "success",
"message": "Deleted 'helper' (3 references + definition) across 2 file(s).",
"timestamp": "2025-01-18T12:34:56.789Z",
"result": {
"symbol": "helper",
"kind": "function",
"spans_deleted": 4,
"files_affected": 2,
"spans": [
{
"file_path": "src/lib.rs",
"symbol": "helper",
"kind": "function",
"byte_start": 120,
"byte_end": 189,
"line_start": 5,
"line_end": 7,
"col_start": 0,
"col_end": 1,
"span_checksum_before": "a1b2c3d4..."
}
]
}
}
Replace a function body:
cat > new_greet.rs << 'EOF'
pub fn greet(name: &str) -> String {
format!("Hi, {}!", name)
}
EOF
splice patch --file src/lib.rs --symbol greet --kind function --with new_greet.rs
cat > new_calc.py << 'EOF'
def calculate(x: int, y: int) -> int:
return x * y
EOF
splice patch --file utils.py --symbol calculate --language python --with new_calc.py
cat > new_fn.ts << 'EOF'
function calculate(x: number, y: number): number {
return x * y;
}
EOF
splice patch --file src/math.ts --symbol calculate --language type-script --with new_fn.ts
cat > plan.json << 'EOF'
{
"steps": [
{
"file": "src/lib.rs",
"symbol": "foo",
"kind": "function",
"with": "patches/foo.rs"
},
{
"file": "src/lib.rs",
"symbol": "bar",
"kind": "function",
"with": "patches/bar.rs"
}
]
}
EOF
splice plan --file plan.json
Apply multiple patches at once from a JSON file:
cat > batch.json << 'EOF'
{
"patches": [
{
"file": "src/lib.rs",
"symbol": "foo",
"kind": "function",
"with": "patches/foo.rs"
},
{
"file": "src/lib.rs",
"symbol": "bar",
"kind": "function",
"with": "patches/bar.rs"
}
]
}
EOF
splice patch --batch batch.json --language rust
Replace a pattern across multiple files:
# Replace "42" with "99" in all Python files
splice apply-files --glob "*.py" --find "42" --replace "99"
# With validation and backup
splice apply-files --glob "tests/**/*.rs" --find "old_func" --replace "new_func" --create-backup
Inspect changes before applying:
splice patch --file src/lib.rs --symbol foo --with new_foo.rs --preview
Create a backup before changes:
splice patch --file src/lib.rs --symbol foo --with new_foo.rs --create-backup --operation-id "my-change"
Restore from backup:
splice undo --manifest .splice-backup/my-change/manifest.json
# List all available labels
splice query --db code.db --list
# Find all Rust functions
splice query --db code.db --label rust --label fn
# Show code for each result
splice query --db code.db --label struct --show-code
# Get code by byte span without re-reading the file
splice get --db code.db --file src/lib.rs --start 0 --end 100
# Show database statistics
splice status --db code.db
# Find all functions in a file
splice query --db code.db --file src/lib.rs --kind fn
# Find symbol by name
splice find --db code.db --name my_function
# Show call relationships
splice refs --db code.db --name my_function --direction out
# List indexed files
splice files --db code.db --symbols
# Export graph data
splice export --db code.db --format json --file export.json
Remove a symbol definition and all its references.
splice delete --file <PATH> --symbol <NAME> [--kind <KIND>] [--language <LANG>]
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 attachmentRust-specific features:
Other languages:
--language flag or auto-detection from file extensionApply a patch to a symbol's span.
splice patch --file <PATH> --symbol <NAME> --with <FILE> [--kind <KIND>] [--language <LANG>]
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 attachmentApply a pattern replacement to multiple files.
splice apply-files --glob <GLOB> --find <PATTERN> --replace <REPLACEMENT>
Required Arguments:
--glob <GLOB>: Glob pattern for matching files (e.g., tests/**/*.rs, src/**/*.py)--find <PATTERN>: Text pattern to find--replace <REPLACEMENT>: Replacement textOptional 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 attachmentUndo a previous operation by restoring from a backup manifest.
splice undo --manifest <PATH>
Execute a multi-step refactoring plan.
splice plan --file <PLAN.json>
Query symbols by labels using Magellan integration.
splice query --db <FILE> [--label <LABEL>]... [--list] [--count] [--show-code]
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 resultAvailable labels:
rust, python, javascript, typescript, c, cpp, javafn, method, struct, class, enum, interface, module, union, namespace, typealiasGet code chunks from the database using Magellan integration.
splice get --db <FILE> --file <PATH> --start <N> --end <N>
Required Arguments:
--db <FILE>: Path to the Magellan database--file <PATH>: File path--start <N>: Start byte offset--end <N>: End byte offsetDisplay database statistics.
splice status --db <FILE> [--output FORMAT]
Required Arguments:
--db <FILE>: Path to the Magellan databaseOptional Arguments:
--output FORMAT: Output format (human, json, pretty) - default: humanFind symbols by name or symbol_id.
splice find --db <FILE> (--name <NAME> | --symbol-id <ID>) [--ambiguous] [--output FORMAT]
Required Arguments:
--db <FILE>: Path to the Magellan database--name <NAME>: Symbol name to find--symbol-id <ID>: 16-character hex symbol IDOptional Arguments:
--ambiguous: Show all matches for ambiguous names--output FORMAT: Output format (human, json, pretty)Show callers/callees for a symbol.
splice refs --db <FILE> (--name <NAME> | --path <PATH> --name <NAME>) [--direction DIR] [--output FORMAT]
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)List indexed files.
splice files --db <FILE> [--symbols] [--output FORMAT]
Required Arguments:
--db <FILE>: Path to the Magellan databaseOptional Arguments:
--symbols: Show symbol counts per file--output FORMAT: Output format (human, json, pretty)Export graph data.
splice export --db <FILE> --format FORMAT --file <PATH>
Required Arguments:
--db <FILE>: Path to the Magellan database--format FORMAT: Export format (json, jsonl, csv)--file <PATH>: Output file pathQuery the execution audit trail from .splice/operations.db.
# Show recent operations
splice log
# Filter by operation type
splice log --operation-type patch
# Filter by status
splice log --status success
# Filter by date range
splice log --after "2025-01-01" --before "2025-01-31"
# Query specific execution
splice log --execution-id 20250118_123456_abc123
# Show statistics
splice log --stats
# JSON output for programmatic access
splice log --format json
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:
cargopythongcc/g++javacnodetscEvery operation passes:
All operations are logged to .splice/operations.db with timestamps, durations, and command-line capture for complete auditability.
cargo test
Test Coverage: 215+ tests passing, including:
If you use this tool and find a bug or miss a feature that would be useful, drop a line. It's appreciated.
GPL-3.0-or-later
This software modifies source code. Always commit your changes before running Splice.
Splice works best with Magellan for code graph indexing and querying.
Magellan is a code understanding and indexing library that provides:
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.