Skip to content

Replace deep links and signal files with local HTTP server - #43

Merged
sam-phinizy merged 3 commits into
mainfrom
claude/multi-language-support-neJot
Mar 25, 2026
Merged

Replace deep links and signal files with local HTTP server#43
sam-phinizy merged 3 commits into
mainfrom
claude/multi-language-support-neJot

Conversation

@sam-phinizy

Copy link
Copy Markdown
Contributor

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-server crate: 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 control
  • AppBridge trait: Abstracts Tauri interactions so the server is testable without the full app. Implemented by TauriBridge in the Tauri crate.

  • ReviewSessions manager: Replaces signal files with in-memory session tracking using tokio::sync::oneshot channels. Sessions are identified by UUIDs and support configurable timeouts.

  • Server discovery: Writes ~/.redpen/server.json containing the server's PID and port, allowing CLI clients to locate and connect to the running server.

  • CLI integration (redpen-cli):

    • New server_client module provides high-level functions (open_file, refresh_file, review, etc.)
    • cmd_open and cmd_wait now try the HTTP server first, falling back to deep links and signal files if unavailable
    • Combined cmd_open_and_wait uses the server's /rpc/review endpoint for atomic open + wait operations
    • Process liveness check using kill(pid, 0) to detect stale server entries
  • Tauri app integration:

    • TauriBridge implements AppBridge by delegating to Tauri's event system
    • Server starts automatically on app launch as a background task
    • Emits deep-link events for file operations (maintains compatibility with existing handlers)
  • Comprehensive test suite: 30+ tests covering:

    • Individual RPC endpoints (open, refresh, get_annotations)
    • Review session lifecycle (start, done, wait, combined flow)
    • Timeout and error handling
    • Concurrent sessions
    • Session state management

Notable Implementation Details

  • All endpoints are POST with JSON request/response bodies
  • Review sessions use oneshot channels for efficient blocking waits
  • Server discovery file includes PID for liveness verification
  • Graceful fallback: CLI tools work with or without the server running
  • Tests use mock AppBridge and spawn temporary test servers on random ports
  • Timeout defaults to 300 seconds for review operations, 86400 for CLI waits

https://claude.ai/code/session_017QStjBJgwHBPdDNcwUEFzN

claude added 3 commits March 25, 2026 12:46
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
@sam-phinizy
sam-phinizy merged commit f50d677 into main Mar 25, 2026
8 of 15 checks passed
@sam-phinizy
sam-phinizy deleted the claude/multi-language-support-neJot branch March 25, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants