Skip to main content

Module workstreams

Module workstreams 

Source
Expand description

Workstream domain model + flat JSON persistence + boot reconciliation (DOC-48 Phase 1A, issue #3293).

Why: DOC-39 §4B’s Workstream domain object had no daemon-owned identity — a restart silently discarded the in-memory SessionRegistry’s workstream grouping. This module gives it one: a serializable domain object plus a single flat, atomically-written JSON store per project. What: WorkstreamId, WorkstreamState (computed, never persisted), Workstream (the domain record); WorkstreamStore (load/save/create/get/ list, the set_active persistence primitive, and boot reconciliation). Activation-lock RPC semantics, the RPC/REST/CLI surface, and SSE aggregation are out of scope here (#3294–#3297). Test: cargo test -p trusty-code workstreams::. Workstream domain model + flat JSON persistence + boot reconciliation (DOC-48 Phase 1A, issue #3293).

§Spec References

Why: DOC-39 §4B introduced Workstream as a durable named grouping of sessions that must survive daemon restarts, but tcode’s SessionRegistry is in-memory only — a restart silently loses the workstream list (DOC-48 §1.1). This module is the foundation slice that fixes that: a serializable domain object plus a single flat JSON store per project, written with an atomic temp+rename so a crash mid-write never corrupts the file.

Disambiguation (DOC-48 §11): trusty_agents_common::workstreams::Workstream is a different type — the cross-tool engineering-lead ledger entry (DOC-44). This module’s Workstream is tcode’s own native domain object. Code that touches both MUST use qualified imports (trusty_agents_common::workstreams::Workstream for the ledger, trusty_code::workstreams::Workstream for tcode-native state) — never a bare use ...::Workstream in a module that needs both.

What: WorkstreamId (a UUID newtype), WorkstreamState (the computed active | idle | closed enum — never persisted, see §2.2/§3.2), Workstream (the domain record — see model); WorkstreamStore (the flat-JSON, atomic-write, fingerprint-reload store plus boot reconciliation — see store); path/filename derivation from the daemon’s crate::binding::ProjectBinding (see path); (issue #3294) activation — the activation-lock exclusivity layer above the store (ActiveConflict/force-switch semantics WorkstreamStore::set_active deliberately left out) — protocol, the full workstream.* JSON-RPC surface (create/get/list/close from #3295 plus activate/deactivate from #3294, built on activation); and (issue #3297) sse — the GET /workstreams/{id}/events fan-out aggregation route, built directly on store::WorkstreamStore (bypassing the JSON-RPC router, mirroring crate::serve::http::session_events_sse’s per-session precedent).

Scope note (Phase 1A): #3293 built ONLY the domain model and persistence layer (this module’s model/path/store submodules); #3294 added the activation-lock RPC semantics (activation, plus activate/deactivate in protocol); #3295 added the rest of protocol’s surface (create/get/list/close) and the REST wrappers (crate::serve::rest::workstreams); #3297 (this ticket) adds sse — the GET /workstreams/{id}/events aggregation route — plus activation’s new role as the sole publisher of crate::events::Event::WorkstreamActivationChanged. The CLI (#3296) and the trusty-agents-common extraction of sse’s aggregation layer (Phase 1B, #3299) remain out of scope.

Test: cargo test -p trusty-code workstreams:: exercises every submodule in place; see each submodule’s own Test: line for specifics.

Re-exports§

pub use activation::ActivateOutcome;
pub use activation::ActivationError;
pub use activation::SharedWorkstreamStore;
pub use model::Workstream;
pub use model::WorkstreamId;
pub use model::WorkstreamState;
pub use sse::WorkstreamEventEnvelope;
pub use store::BindError;
pub use store::ReconcileOutcome;
pub use store::StoreError;
pub use store::WorkstreamStore;

Modules§

activation
Activation-lock exclusivity layer over WorkstreamStore (DOC-48 §6, issue #3294).
events_stream
(#6637) workstream.events: the socket transport’s live fan-out, a bridge onto the same sse::aggregate_live combinator the HTTP route uses. workstream.events — the streaming method a UDS client observes one workstream through (#6637).
model
Workstream domain types (DOC-48 §2).
protocol
workstream.* JSON-RPC method handlers (issues #3294, #3295, epic #3292).
sse
Workstream-level SSE event aggregation route (DOC-48 §5.3, §5.3.1; issue #3297, epic #3292); thin trusty-agents-common::transport adapter (issue #3299, Phase 1B).
store
On-disk JSON persistence + boot reconciliation for workstream records (DOC-48 §3).

Functions§

default_data_dir
Resolve ~/.trusty-code, creating it at mode 0700 and tightening it if a previous run left it permissive.
store_path
Join [store_filename] under a data directory to get the full store path.