feat: WS Gateway server + Cognitive Bridge (#69, #70) #72

Merged
perplexity merged 2 commits from feat/ws-gateway-bridge into main 2026-03-19 20:44:45 -04:00
Owner

What

The nervous system connecting Timmy's brain to his Matrix body.

Gateway (server/gateway.py) — Issue #70

Central WebSocket hub that all Matrix participants connect to:

Timmy's Dashboard ──ws──→ Gateway ──ws──→ Matrix 3D Client (iPad)
                              ↕
                    Perplexity Bot ──ws──→
                              ↕
                    Future agents ──ws──→
  • Configurable port (default 8765), optional token auth
  • Message routing: broadcast (all clients) + directed (target_id → specific agent + browsers)
  • agent_registeragent_joined/agent_left lifecycle events
  • 30s heartbeat with dead connection pruning
  • Optional REST /api/gateway/status endpoint
  • Pass-through for all Matrix protocol message types
  • 10/10 integration tests

Cognitive Bridge (server/bridge.py) — Issue #69

Translates Timmy's cognitive events into Matrix protocol messages:

Timmy Event Matrix Action
think_once() fires agent_behavior:ponder + bark with thought excerpt
Mood changes agent_state with mapped state + glow intensity
Energy < 0.3 agent_state:idle override
Gitea issue filed agent_behavior:place + bark
Visitor enters agent_state:active + agent_behavior:converse
Visitor leaves agent_behavior:return_home + idle

Two modes:

  • Standalone: polls presence.json, auto-translates
  • Integrated: import into Timmy's dashboard, call methods directly from thinking engine / cognitive tracker

State deduplication prevents redundant messages. Auto-reconnect on drop.

8/8 integration tests

Also includes

  • server/README.md with architecture, quick-start, and usage
  • .gitignore for Python bytecode

Test Results

  • Existing smoke tests: 87/87 pass
  • Gateway tests: 10/10 pass
  • Bridge integration tests: 8/8 pass

Supersedes

  • #48 (WS Gateway for interview) — this is the permanent version
  • The server portions of #8 (gateway adapter)

Closes

## What The nervous system connecting Timmy's brain to his Matrix body. ### Gateway (`server/gateway.py`) — Issue #70 Central WebSocket hub that all Matrix participants connect to: ``` Timmy's Dashboard ──ws──→ Gateway ──ws──→ Matrix 3D Client (iPad) ↕ Perplexity Bot ──ws──→ ↕ Future agents ──ws──→ ``` - Configurable port (default 8765), optional token auth - Message routing: broadcast (all clients) + directed (`target_id` → specific agent + browsers) - `agent_register` → `agent_joined`/`agent_left` lifecycle events - 30s heartbeat with dead connection pruning - Optional REST `/api/gateway/status` endpoint - Pass-through for all Matrix protocol message types - **10/10 integration tests** ### Cognitive Bridge (`server/bridge.py`) — Issue #69 Translates Timmy's cognitive events into Matrix protocol messages: | Timmy Event | Matrix Action | |---|---| | `think_once()` fires | `agent_behavior:ponder` + `bark` with thought excerpt | | Mood changes | `agent_state` with mapped state + glow intensity | | Energy < 0.3 | `agent_state:idle` override | | Gitea issue filed | `agent_behavior:place` + `bark` | | Visitor enters | `agent_state:active` + `agent_behavior:converse` | | Visitor leaves | `agent_behavior:return_home` + idle | Two modes: - **Standalone**: polls `presence.json`, auto-translates - **Integrated**: import into Timmy's dashboard, call methods directly from thinking engine / cognitive tracker State deduplication prevents redundant messages. Auto-reconnect on drop. **8/8 integration tests** ### Also includes - `server/README.md` with architecture, quick-start, and usage - `.gitignore` for Python bytecode ## Test Results - Existing smoke tests: **87/87 pass** - Gateway tests: **10/10 pass** - Bridge integration tests: **8/8 pass** ## Supersedes - #48 (WS Gateway for interview) — this is the permanent version - The server portions of #8 (gateway adapter) ## Closes - Closes #69 - Closes #70
perplexity added 2 commits 2026-03-19 20:44:37 -04:00
Gateway (server/gateway.py):
- Central WebSocket hub on configurable port (default 8765)
- Message routing: broadcast + directed (target_id)
- agent_register → agent_joined/agent_left lifecycle
- 30s heartbeat with dead connection pruning
- Optional REST /api/gateway/status endpoint
- Concurrent dict-safe broadcast (snapshot keys)
- Pass-through for all Matrix protocol messages
- 10/10 integration tests

Cognitive Bridge (server/bridge.py):
- Connects to gateway as agent:timmy
- Maps think_once() → agent_behavior:ponder + bark
- Maps mood/engagement → agent_state with glow
- Low energy (<0.3) → idle override
- Issue filed → agent_behavior:place + bark
- Visitor enter/leave → converse/return_home
- Standalone mode: polls presence.json
- Integrated mode: direct method calls from dashboard
- State dedup (skips redundant messages)
- 8/8 integration tests

Server README with quick-start, architecture, and usage.
Supersedes #48 (interview gateway). Relates to #8, #49, #45.
perplexity merged commit 004f27f453 into main 2026-03-19 20:44:45 -04:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: perplexity/the-matrix#72