Skip to main content

Module protocol

Module protocol 

Source
Expand description

workstream.* JSON-RPC method handlers (issues #3294, #3295, epic #3292).

§Spec References

Why: mirrors crate::session::protocol’s role for session.* — the RPC surface the daemon exposes over POST /rpc (and, via crate::serve::rest::workstreams, the REST twin). #3293 (merged) built the domain model and the flat-JSON super::store::WorkstreamStore, but left it unreachable from any transport. This file is where BOTH concurrent follow-up tickets against that foundation land: #3294’s activation-lock exclusivity model (activate/deactivate, built on super::activation) and #3295’s CRUD/inspection surface (create/get/list/close, built directly on the store) — six thin handlers, one shared SharedWorkstreamStore, one register call.

Scope note: activate/deactivate’s business logic (conflict detection, force-switch) lives entirely in super::activation — this file only parses params and maps ActivationError onto the JSON-RPC taxonomy. create/get/list/close have no activation-lock rules to apply, so they call super::store::WorkstreamStore directly. The CLI (#3296) and the SSE aggregation route (#3297) remain out of scope.

What: register wires workstream.create, workstream.get, workstream.list, workstream.close, workstream.activate, workstream.deactivate, workstream.rename (Phase C, issue #3300) onto a crate::jsonrpc::Router, all sharing one SharedWorkstreamStore. Every verb that takes a wire id parses it via [parse_id] (a manual Uuid::parse_str + -32602 Invalid params on failure) rather than deserializing straight into a WorkstreamId — chosen as the ONE id-parsing style for this file since #3294 landed it first. [WorkstreamView] is the wire-shape adapter get/list share: the domain Workstream has no state FIELD (§2.2 — it is computed, never stored), so every read path builds this view by pairing a record with the store’s current active_workstream_id pointer via Workstream::state, exactly once, right before serializing. Test: protocol_tests.

Functions§

check_workstream_immutable
Enforce DOC-48 §4.1’s binding immutability on a REUSED session (AC-1.3, issue #3298): “if a session with an existing workstream binding receives a task with a different workstream, the task is rejected.”
register
Register every workstream.* method onto router, all sharing store.
resolve_validate_bind
Resolve + VALIDATE the EFFECTIVE workstream target, then mint a session and persist its binding — all under one store lock (DOC-48 §4.1/§4.2, issue #3298; validate-before-mint ordering per PR #3354 code-critic HIGH findings 1 & 2).