Terminal App: WebSocket-to-Claude-Code Bridge
Description
Recent Comments
## Review: PASS ✓ Implementation matches technical spec: - Go 1.21 with PTY, WebSocket, terminal libs ✓ - ActionCable integration with auto-reconnect ✓ - Multi-stage Docker build integrated ✓ - Environment var configuration ✓ **Code quality**: Clean, readable, proper error handling. **Notes:** - No Go tests per user approval - Ready for end-to-end testing with live Rails WebSocket - Minor: PTY goroutines could use mutex for theoretical safety (not blocking)
## Implementation Complete ✅ Successfully implemented the WebSocket-to-Claude-Code bridge as specified. ### What Was Built **agent-bridge.go** - A Go application that: - Starts Claude Code in a PTY for natural terminal interaction - Connects to Rails ActionCable WebSocket at `ws://host.docker.internal:3000/cable` - Subscribes to `AgentChannel` with agent type identifier - Receives commands from Rails and passes them to Claude's stdin - Displays all Claude output for full observability - Auto-reconnects to WebSocket on disconnect (5s backoff) - Handles terminal resize signals (SIGWINCH) - Uses color-coded logging for bridge status messages **Docker Integration**: - Added multi-stage Go builder to Dockerfile.sandbox - Binary compiled and copied to `/usr/local/bin/agent-bridge` - Updated run-claude-agent.rb to exec agent-bridge instead of claude directly **Configuration**: - `AGENT_TYPE` env var: worker|reviewer|orchestrator - `RAILS_WS_URL` env var: WebSocket endpoint (defaults to ws://host.docker.internal:3000/cable) ### Testing Results ✅ Code compiles successfully ✅ PTY integration works - Claude Code starts properly ✅ WebSocket client attempts connection (fails gracefully when Rails not running) ✅ Terminal resize handling works ✅ Color-coded status messages display correctly ### Files Changed - **New**: agent-bridge.go, go.mod, go.sum - **Modified**: Dockerfile.sandbox, run-claude-agent.rb ### Pull Request Created: https://github.com/RoM4iK/tinker/pull/16 Ready for review and end-to-end testing with live Rails server.
## Technical Decisions (from research) Based on collaboration, here are the chosen approaches: ### 1. Technology Stack: **Go** - Compiled, single binary - Libraries: `github.com/creack/pty`, `nhooyr.io/websocket`, `golang.org/x/term` - Integrated into existing Dockerfile.sandbox build process ### 2. WebSocket Client - Library: `nhooyr.io/websocket` - Connects to Rails ActionCable via `host.docker.internal:3000/cable` - Subscribes to `AgentChannel` with agent type identifier - Auto-retry on disconnect (5s backoff) ### 3. Claude Code Integration: **PTY (Pseudo-Terminal)** - Uses `github.com/creack/pty` for natural terminal emulation - Handles window resize signals (SIGWINCH) - Raw terminal mode for proper Tab/Arrow key handling - Claude runs with `--dangerously-skip-permissions` flag ### 4. Message Flow ``` Rails → WebSocket → Go Bridge → PTY → Claude Code ↓ Visual indicator: "[RAILS COMMAND] ..." ``` ### 5. Console/Observability - Direct PTY output to stdout (full Claude UI visible) - Rails commands prefixed with blue `[RAILS COMMAND]` indicator - stderr for bridge status messages ### 6. Process Management - Bridge spawns claude process on startup - Automatic reconnection to Rails on WS disconnect - Claude crash handling through process exit ### 7. Configuration: **Environment Variables** ```bash AGENT_TYPE=worker|reviewer|orchestrator RAILS_WS_URL=ws://host.docker.internal:3000/cable ``` ### 8. Deployment: **Integrated into Dockerfile.sandbox** - Multi-stage build: Go builder stage → Node stage - Binary copied to `/usr/local/bin/agent-bridge` - Existing `run-claude-agent.rb` modified to exec `agent-bridge` instead of `claude` ## Files to Create/Modify **New:** - `agent-bridge.go` - Main bridge application **Modify:** - `Dockerfile.sandbox` - Add Go builder stage - `run-claude-agent.rb` - Change `exec claude` to `exec agent-bridge`
Ticket Stats
Comments
3 commentsAdd a Comment
No Subtasks Yet
Break down this ticket into smaller, manageable subtasks