[kimi-task] [refactor] Extract WebSocket message types into shared protocol module #667

Closed
opened 2026-03-21 03:12:01 +00:00 by kimi · 1 comment
Collaborator

Epic: Matrix Unification

Task

Create src/infrastructure/protocol.py defining all WebSocket message types as an enum and dataclasses.
The Matrix PROTOCOL.md defines these types: agent_state, visitor_state, bark, thought, system_status,
connection_ack, error, task_update, memory_flash. Codify them as Python dataclasses with validation.

Files

  • src/infrastructure/protocol.py — NEW: MessageType enum + dataclasses for each message
  • tests/unit/test_protocol.py — NEW: validation tests

Acceptance Criteria

  • MessageType enum with all 9 types from Matrix PROTOCOL.md
  • Dataclass for each message type with required fields
  • to_json() and from_json() on each dataclass
  • tox -e unit passes
  • tox -e lint passes

Context

The Matrix frontend expects WebSocket messages in this format:

{"type": "agent_state", "agent_id": "timmy", "data": {...}, "ts": 1234567890}

We need a shared protocol module so the gateway and all producers speak the same language.
The current /api/world/ws endpoint in the dashboard uses ad-hoc dicts — this replaces that.

## Epic: Matrix Unification ## Task Create `src/infrastructure/protocol.py` defining all WebSocket message types as an enum and dataclasses. The Matrix PROTOCOL.md defines these types: agent_state, visitor_state, bark, thought, system_status, connection_ack, error, task_update, memory_flash. Codify them as Python dataclasses with validation. ## Files - src/infrastructure/protocol.py — NEW: MessageType enum + dataclasses for each message - tests/unit/test_protocol.py — NEW: validation tests ## Acceptance Criteria - [ ] MessageType enum with all 9 types from Matrix PROTOCOL.md - [ ] Dataclass for each message type with required fields - [ ] to_json() and from_json() on each dataclass - [ ] tox -e unit passes - [ ] tox -e lint passes ## Context The Matrix frontend expects WebSocket messages in this format: ```json {"type": "agent_state", "agent_id": "timmy", "data": {...}, "ts": 1234567890} ``` We need a shared protocol module so the gateway and all producers speak the same language. The current /api/world/ws endpoint in the dashboard uses ad-hoc dicts — this replaces that.
kimi self-assigned this 2026-03-21 03:12:01 +00:00
Author
Collaborator

PR created. Added src/infrastructure/protocol.py with MessageType StrEnum (all 9 Matrix PROTOCOL.md types) and typed dataclasses with to_json()/from_json() serialisation. Comprehensive tests in tests/unit/test_protocol.py. All CI gates pass.

PR created. Added `src/infrastructure/protocol.py` with `MessageType` StrEnum (all 9 Matrix PROTOCOL.md types) and typed dataclasses with `to_json()`/`from_json()` serialisation. Comprehensive tests in `tests/unit/test_protocol.py`. All CI gates pass.
kimi closed this issue 2026-03-21 13:37:29 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#667