This plan outlines the design and steps required to port the Python-based context-pipe orchestrator and CLI to Rust. The goals are to achieve near-instantaneous startup times (~5ms), eliminate Python runtime dependencies, reduce memory overhead to zero in agent runtimes, and enable direct, high-performance integration with Tauri apps (like Meechi/Side-Hustle) and cross-language wrappers.
Important
Coexistence of Rust and Python Versions
The Rust core will be built as an addition, not a replacement. Rust and Python will coexist in the repository. The Python implementation remains the primary and default MCP server, while the Rust core (cpipe CLI and crate) is added as a high-performance alternative (providing ~5ms startup times and zero-dependency execution).
Important
Workspace Location for the Crate
The Rust crate will be created in a new directory named crates/cpipe within the existing context-pipe repository.
Important
Binary Name and Command Line Aliases
cpipe will be the primary name of the compiled Rust binary. We will support compatibility aliases so that the Rust binary can be invoked in place of context-pipe or mcp-pipe.
Note
TOML Configuration Support
We will support both pipes.json (for backwards compatibility and cross-parity with the Python engine) and pipes.toml.
Advantages of TOML over JSON for configurations:
- Native Comments: TOML supports standard comments (
# comment), eliminating the need for hacky JSON string fields like"_comment". - Multi-line Strings: TOML supports raw multi-line strings (
"""), which is incredibly useful for writing complex node arguments, command descriptions, or inline sifting patterns without escaping quotes and newlines with\n. - Human Friendliness: TOML is designed for humans to write configurations and does not fail on trailing commas or strict quote formatting.
We will introduce a Cargo workspace in the project root or create a standalone crate under crates/cpipe.
Defines the crate dependencies (e.g., serde, serde_json, tokio with process and rt features, clap for CLI parsing, and log/env_logger for telemetry).
The library entry point exposing core orchestration, parsing, and execution APIs so it can be integrated directly into other Rust applications (like Tauri backend projects).
Handles loading, merging, and parsing local pipes.json and global ~/.mcp-pipe.json configurations.
- Resolves
${VAR}placeholders inside environment settings. - Performs schema validation on pipes, mappings, and server configurations.
Port of orchestrator.py and dynamic.py stream-routing algorithms:
- Manages standard I/O redirection between sequential pipe nodes.
- Employs timeout guards using
tokio::time::timeout. - Implements the Self-Aware Node Bypass rule (checking for
--- [Semantic-Sift Audit] ---).
Probes the system PATH for curated CLI tools (jq, rg, markitdown, pandoc, etc.) and parses their availability to return a live capability manifest.
Calculates and updates the Context Balance Sheet (local JSON ledger) and formats the standard Markdown audit headers.
Standard input/output JSON-RPC handler that registers and runs the MCP tools: pipe_run, pipe_run_dynamic, pipe_read_file, pipe_analyze_file, pipe_list_shadow_tools, and get_pipe_stats.
The executable entry point parsing command-line parameters (run, run-dynamic, list, stats, serve) using clap.
- Unit Tests:
- Config loading and schema merge validation.
- Timeout guard correctness.
- Node bypass validation (header detection).
- Path probing robustness.
- Integration Tests:
- Execute standard pipeline runs (e.g., feeding test streams to
cpipe run standard-distill) and verifying character reduction. - Verify MCP JSON-RPC protocol compliance by feeding mock MCP stdio messages to
cpipe serve.
- Execute standard pipeline runs (e.g., feeding test streams to
- Compare binary startup latency against the Python package (
context-pipe) using PowerShell'sMeasure-Command. Target startup latency is <10ms. - Verify integration as a global MCP server in a test Antigravity session.