A compact, unixy suite of agent-grade CLI tools built on top of Lens's SPI, designed for AI agent workflows with strict contracts, reproducibility, and safety measures.
This suite provides 11 CLI tools (1 library + 10 binaries) that enable reliable, deterministic access to code analysis and transformation capabilities. All tools follow shared contracts with JSONL I/O, deterministic output ordering, and budget enforcement.
- Search latency: p95 < 120ms for kβ€50 queries
- Patch success rate: β₯95% with verification
- Memory budget: β€256MB per operation
- CPU budget: β€200ms per operation
Ripgrep-like search over Lens SPI with hybrid mode support.
sripgrep "function main" --mode hybrid --token-budget 10000 --budget-ms 200Constructs deduped, token-capped packs from refs/queries.
scontext --ref lens://abc123/src/main.rs@def456#B1:10 --token-budget 2000Applies edit plans under drift using AST+fuzzy+semantic anchoring.
spatch --plan patch-plan.yaml --verify "cargo test" --strictRanks downstream symbols/files affected by changes.
simpact --target "function_name" --depth 3 --explainProvides deps/rdeps/who-calls/path queries with visualization.
sgraph --query deps --source "main" --output dotAST-aware diff with move/rename detection.
sdiffx old_version.rs new_version.rs --detect-moves --ignore-whitespaceSafe rename/extract/reorder with verification.
srefactor rename old_function_name --new-name new_function_name --verify "cargo check"Assembles docstrings/examples/tests with ranked exemplars.
sdoc function_name --include-examples --max-tokens 1024Extractive Q&A over context packs with citations.
sqa "What does this function do?" --ref lens://... --strictHealth checks, budget enforcement, and degradation detection.
shealth check --component all --enforce-budgetsgit clone <repository>
cd lens-agent-cli-suite
cargo build --release
cargo install --path .- Rust 1.70+
- Lens SPI service running at http://localhost:3000/v1/spi
All tools support common arguments:
# Common options
--spi-url <URL> # Lens SPI endpoint (default: http://localhost:3000/v1/spi)
--format <FORMAT> # Output format: jsonl, json, text (default: jsonl)
--strict # Fail fast on ambiguity (default: true)
--budget-ms <MS> # CPU budget in milliseconds (default: 200)
--budget-mb <MB> # Memory budget in MB (default: 256)
--debug # Enable debug tracing
--quiet # Suppress non-essential outputAll tools produce deterministic JSONL output by default:
{"type": "result", "rank": 1, "ref": "lens://...", "score": 0.95}
{"type": "timing", "total_ms": 127, "breakdown": {"search": 45, "rank": 82}}
{"type": "summary", "total_results": 15, "success_rate": 1.0}cargo buildcargo testcargo clippycargo doc --openThe shared library provides:
- Lens SPI Client: Async HTTP client with budget enforcement
- Reference Handling: Stable lens:// URI parsing and validation
- Output Formatting: Deterministic JSONL with sorted keys
- Budget Enforcement: CPU/memory/wall-time constraints
- Common Types: Shared data structures and error handling
Each tool follows the pattern:
- Argument Parsing: Clap-based CLI with validation
- Budget Setup: Resource constraint enforcement
- SPI Integration: Query Lens backend with retries
- Processing: Tool-specific logic with error handling
- Output Generation: Structured JSONL results
- Verification: Optional verification gates
- Deterministic Output: Same input produces same output
- Budget Enforcement: Hard limits prevent resource exhaustion
- Error Transparency: Structured error reporting with context
- Verification Gates: Optional validation of operations
- Streaming Processing: Handle large codebases efficiently
- Parallel Operations: Concurrent processing where safe
- Smart Caching: LRU caches for repeated operations
- Budget Awareness: Graceful degradation under constraints
- Strict Mode: Fail fast on ambiguous operations
- Input Validation: All external input validated
- Reference Stability: Immutable lens:// references
- Verification Hooks: Optional build/test validation
This implementation follows the SRF v1.1 specification with:
- β 11 Artifacts: 1 library + 10 CLI tools
- β Performance SLOs: Sub-120ms search, >95% patch success
- β JSONL Contracts: Deterministic output ordering
- β Budget Enforcement: CPU/memory/time constraints
- β Lens SPI Integration: Unified backend communication
- β Verification Gates: Optional validation steps
- β Error Handling: Structured error reporting
- β Test Coverage: Comprehensive test suite
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
cargo test - Run clippy:
cargo clippy - Submit a pull request
- Follow existing code style
- Add comprehensive tests
- Document public APIs with rustdoc
- Use structured error handling
- Maintain backwards compatibility
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
- Lens SPI - Backend indexing service
- Tree-sitter - Parser generator for AST operations
Built for AI agents, by AI agents π€