feat: communication spine — gateway, TUI, Discord #61

Merged
jason.woltje merged 2 commits from feat/communication-spine into main 2026-03-13 01:33:32 +00:00
Owner

Summary

  • Gateway (NestJS + Fastify): WebSocket chat gateway with Pi SDK agent sessions, REST /api/chat endpoint
  • TUI (Ink/React): Interactive terminal client connecting to gateway via Socket.IO
  • Discord plugin: Bot that relays Discord messages through the gateway to Pi agent sessions

Establishes the vertical slice communication spine: all channels → Gateway → Pi SDK → LLM.

Review Remediation

Three-agent gatekeeper review identified 16 issues. 10 remediated in this PR. 4 deferred to natural milestone tasks (DTOs → P0-002, auth → P1-002, Discord hardening → P5-002).

Test plan

  • Gateway boots
  • TUI connects and streams agent responses
  • Typecheck/lint/format all pass (verified locally)

🤖 Generated with Claude Code

## Summary - **Gateway** (NestJS + Fastify): WebSocket chat gateway with Pi SDK agent sessions, REST /api/chat endpoint - **TUI** (Ink/React): Interactive terminal client connecting to gateway via Socket.IO - **Discord plugin**: Bot that relays Discord messages through the gateway to Pi agent sessions Establishes the vertical slice communication spine: all channels → Gateway → Pi SDK → LLM. ## Review Remediation Three-agent gatekeeper review identified 16 issues. 10 remediated in this PR. 4 deferred to natural milestone tasks (DTOs → P0-002, auth → P1-002, Discord hardening → P5-002). ## Test plan - [ ] Gateway boots - [ ] TUI connects and streams agent responses - [ ] Typecheck/lint/format all pass (verified locally) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jason.woltje added 2 commits 2026-03-13 01:33:24 +00:00
Gateway:
- Agent service wrapping Pi SDK createAgentSession (in-process)
- Chat WebSocket gateway (Socket.IO) streaming agent events
- Chat REST controller for synchronous requests
- NestJS module structure: AgentModule (global), ChatModule

CLI:
- Ink-based TUI client connecting to gateway via WebSocket
- Commander-based CLI with `mosaic tui` command
- Streaming message display with React components

Discord:
- Discord.js bot with mention-based activation + DM support
- Routes messages through gateway WebSocket
- Chunked response delivery (2000-char Discord limit)
- Single-guild binding for v0.1.0

Architecture: All channels → Gateway WebSocket → Pi SDK → LLM

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix createSession race condition with in-flight promise map
- Fix listener leak: always cleanup previous subscription per client
- Fix REST timeout returning HTTP 200 — now rejects with 504
- Fix fire-and-forget Discord sends — await with error handling
- Fix non-null assertion on client.user in Discord plugin
- Fix TUI disconnect mid-stream deadlock (reset streaming state)
- Add connect_error handler to TUI and Discord plugin
- Add connected guard on TUI message submit
- Add relayEvent guard for disconnected sockets
- Sanitize error messages sent to WebSocket clients
- Add error logging/context to AgentService create/prompt/destroy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jason.woltje merged commit 4f84a01072 into main 2026-03-13 01:33:32 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#61