refactor: consolidate MCP logic into utils as single source of truth#353
refactor: consolidate MCP logic into utils as single source of truth#353khaliqgant merged 2 commits intomainfrom
Conversation
Code Review: PR #353 — MCP/SDK ConsolidationReviewer: CodexReviewer (automated thorough review) 1. Code Correctness & Consolidation Completeness ✅The consolidation is complete and correctly implemented:
All re-export modules contain zero implementation logic. No stale duplicate class definitions remain. 2. Duplication Elimination ✅~560 lines of duplication eliminated — claim verified. Net positive lines accounted for by 404 lines of new tests, 55 lines of re-export barrels, and the unrelated PR audit report. 3. Backwards Compatibility ✅All public APIs preserved via re-exports. MCP consumers can still import from 4. Dependency Graph — No Cycles ✅Verified all 5 package.json files. Proper DAG: No circular dependencies. 5. Test Coverage ✅
6. Error Handling Improvements ✅SDK 7. Minor Observations (Non-blocking)
8. Trail TrajectoryRecorded: Summary: Well-executed refactoring eliminating significant code duplication with clean dependency graph, maintained backwards compatibility, and thorough test coverage. Recommend merge. |
discoverSocket() now returns the determined socket path even when the socket file doesn't exist yet (daemon may not have started). This fixes cloud agents getting null/fallback paths when WORKSPACE_ID is set but the daemon hasn't created the socket yet. Also updates hybrid-client.ts to log socket source for debugging and not blindly fall back to local relay.sock for cloud workspaces. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move duplicated logic from MCP package into @agent-relay/utils so both SDK and MCP share a single implementation: - Socket discovery (discoverSocket, detectCloudWorkspace, getCloudSocketPath, discoverAgentName) moved from MCP cloud.ts → utils/discovery.ts - Error classes (RelayError, DaemonNotRunningError, etc.) moved from MCP errors.ts → utils/errors.ts - MCP cloud.ts and errors.ts now thin re-exports from @agent-relay/utils - SDK discovery.ts and errors.ts re-export from @agent-relay/utils - SDK client.ts now uses discoverSocket() for smart socket resolution instead of hardcoded /tmp/agent-relay.sock - SDK client.ts now uses typed errors (DaemonNotRunningError, ConnectionError) Dependency changes: - @agent-relay/utils now depends on @agent-relay/config (for findProjectRoot) - @agent-relay/sdk now depends on @agent-relay/utils (for discovery + errors) - @agent-relay/mcp now explicitly depends on @agent-relay/utils Tests: 51 new tests for discovery, errors, and consolidation verification. All existing tests pass (206 utils, 50 SDK, 102 MCP = 358 total). No breaking changes - all public APIs preserved, MCP re-exports maintain backwards compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
b477e46 to
b2a03cc
Compare
Summary
discoverSocket,detectCloudWorkspace,getCloudSocketPath,discoverAgentName, etc.) moved from MCP'scloud.ts(522 lines) to@agent-relay/utils/discovery.ts— MCP now a thin re-export (41 lines, -92%)RelayError,DaemonNotRunningError, etc.) moved from MCP'serrors.tsto@agent-relay/utils/errors.ts— MCP now a thin re-export (17 lines, -69%)RelayClientnow usesdiscoverSocket()for cloud-aware socket resolution instead of hardcoded/tmp/agent-relay.sock; uses typed errors (DaemonNotRunningError,ConnectionError) on connect failureDependency graph (no cycles)
Test plan
🤖 Generated with Claude Code