feat: agent relay mode — bridge AI agent to PeerJS players - #35
Merged
Conversation
…et-agent Includes: agent package (state, mcp, scryfall, server, index), design specs, plans, eslint/vite config, ActionLog cardSrcs, useCardReducer lastPlayedSrcs.
Replace dual sync client approach with a relay pattern: - Add agentRelay.ts — bridges WS (agent) ↔ PeerJS (players) - Relay browser applies agent shapes as local shapes (relay's peer ID) - Relay forwards all PeerJS players' shapes to agent via WS - Agent uses simple sync:agent-shapes / sync:remote-shapes messages - No separate WebSocket transport or agentSyncClient needed - Add Relay button to SelectionPanel and SetupScreen The relay browser doesn't play — it bridges. Open a second tab to play against the agent, or let a remote human connect via PeerJS.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
5 tasks
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
maginet-agent/MCP server that lets Claude Code play Magic: The GatheringHow it works
ws://localhost:3210Architecture
graph LR subgraph "Your Machine" CC["Claude Code<br/>(LLM)"] MCP["MCP Server<br/>(Node.js)"] CC -- "stdio<br/>MCP protocol" --> MCP MCP -- "WebSocket<br/>localhost:3210" --> Relay end subgraph "Browsers" Relay["Relay Tab<br/>(bridges WS ↔ PeerJS)"] You["Your Tab<br/>(player)"] Opp["Opponent<br/>(player)"] end Relay -- "PeerJS<br/>WebRTC" --> You Relay -- "PeerJS<br/>WebRTC" --> Opp style Relay fill:#f9f,stroke:#333,stroke-width:2px style MCP fill:#bbf,stroke:#333,stroke-width:2pxData flow
sequenceDiagram participant Agent as MCP Agent participant Relay as Relay Browser participant Player as Opponent (PeerJS) Note over Relay: User clicks "Start Relay" Relay->>Agent: WebSocket connect Agent->>Relay: sync:agent-shapes (agent plays card) Relay->>Relay: setShapes() — applies as local shapes Relay->>Player: PeerJS sync patch (relay's peer ID) Player->>Relay: PeerJS sync patch (opponent plays card) Relay->>Agent: sync:remote-shapes (all players' shapes) Player->>Relay: action-log (opponent drew a card) Relay->>Agent: action-log (forwarded) Agent->>Relay: action-log (agent's action) Relay->>Player: action-log (forwarded via PeerJS)Alternative to PR #34
This replaces the dual sync client approach from #34 with a simpler relay pattern:
src/sync/transport/websocket.ts(deleted)agentSyncClientin peerStoreTest plan