Replace deep links and signal files with local HTTP server - #43
Merged
Conversation
New `crates/redpen-server` crate implementing an optional local HTTP server to replace deep links and signal files for CLI/agent ↔ GUI communication. All endpoints are POST with JSON request/response (RPC-style, not REST): - /rpc/open — open file in GUI (replaces redpen:// deep links) - /rpc/refresh — refresh annotations for a file - /rpc/get_annotations — load annotations from sidecar store - /rpc/review.start — start a review session, returns session_id - /rpc/review.done — signal review completion with verdict - /rpc/review.wait — long-poll until review is done - /rpc/review — combined open + wait (main agent use case) Key design decisions: - AppBridge trait abstracts Tauri, making the server fully testable - In-memory session tracking via oneshot channels (no signal files) - Concurrent review sessions supported (multiple agents, different files) - Dynamic port binding with ~/.redpen/server.json discovery file 21 tests covering all endpoints, session lifecycle, concurrency, timeouts, and error cases. https://claude.ai/code/session_017QStjBJgwHBPdDNcwUEFzN
Tauri side: - TauriBridge implements AppBridge by emitting deep-link-open events and loading annotations from the sidecar store - Server spawned in setup() as an async task (non-blocking) CLI side: - server_client module discovers the server via ~/.redpen/server.json - Validates server PID is alive before connecting - All CLI operations try the HTTP server first, fall back gracefully: - redpen open → POST /rpc/open, fallback to deep links - redpen wait → POST /rpc/review (combined), fallback to signal files - redpen open --wait → POST /rpc/review, fallback to deep link + signals - notify_app/notify_app_refresh → POST /rpc/open or /rpc/refresh The server is purely additive — everything works without it. https://claude.ai/code/session_017QStjBJgwHBPdDNcwUEFzN
- Run cargo fmt on CLI and server crate - Add Default impl for ReviewSessions (clippy new_without_default) - Add urlencoding dependency to src-tauri/Cargo.toml (used by bridge.rs) - Allow dead_code on review_start/review_wait (available for future use) https://claude.ai/code/session_017QStjBJgwHBPdDNcwUEFzN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a local HTTP server (
redpen-server) that replaces deep links, signal files, and the channel server with reliable, bidirectional RPC-style communication. The server runs as a background task in the Tauri app and provides a stable interface for CLI tools and external agents to interact with the GUI.Key Changes
New
redpen-servercrate: Implements a local HTTP server using Axum with RPC-style POST endpoints:/rpc/open— Open a file in the GUI/rpc/refresh— Refresh annotations for a file/rpc/get_annotations— Fetch annotations from the sidecar store/rpc/review— Combined open + wait (blocks until review is done)/rpc/review.start,/rpc/review.done,/rpc/review.wait— Granular review session controlAppBridgetrait: Abstracts Tauri interactions so the server is testable without the full app. Implemented byTauriBridgein the Tauri crate.ReviewSessionsmanager: Replaces signal files with in-memory session tracking usingtokio::sync::oneshotchannels. Sessions are identified by UUIDs and support configurable timeouts.Server discovery: Writes
~/.redpen/server.jsoncontaining the server's PID and port, allowing CLI clients to locate and connect to the running server.CLI integration (
redpen-cli):server_clientmodule provides high-level functions (open_file,refresh_file,review, etc.)cmd_openandcmd_waitnow try the HTTP server first, falling back to deep links and signal files if unavailablecmd_open_and_waituses the server's/rpc/reviewendpoint for atomic open + wait operationskill(pid, 0)to detect stale server entriesTauri app integration:
TauriBridgeimplementsAppBridgeby delegating to Tauri's event systemComprehensive test suite: 30+ tests covering:
Notable Implementation Details
POSTwith JSON request/response bodiesoneshotchannels for efficient blocking waitsAppBridgeand spawn temporary test servers on random portshttps://claude.ai/code/session_017QStjBJgwHBPdDNcwUEFzN