1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Workstream domain model + flat JSON persistence + boot reconciliation
//! (DOC-48 Phase 1A, issue #3293).
//!
//! # Spec References
//!
//! - [`SPEC-WS-01~draft`](docs/specs/DOC-48-tcode-workstreams.md#SPEC-WS-01~draft)
//! - [`SPEC-WS-02~draft`](docs/specs/DOC-48-tcode-workstreams.md#SPEC-WS-02~draft)
//! - [`SPEC-WS-03~draft`](docs/specs/DOC-48-tcode-workstreams.md#SPEC-WS-03~draft)
//! - [`SPEC-WS-05~draft`](docs/specs/DOC-48-tcode-workstreams.md#SPEC-WS-05~draft)
//! - [`SPEC-WS-06~draft`](docs/specs/DOC-48-tcode-workstreams.md#SPEC-WS-06~draft)
//! - [`SPEC-WS-07~draft`](docs/specs/DOC-48-tcode-workstreams.md#SPEC-WS-07~draft) AC-7
//!
//! 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 workstream fan-out aggregation, built directly on
//! [`store::WorkstreamStore`] (bypassing the JSON-RPC router) and served as
//! the socket's `workstream.events` stream since #6637.
//!
//! **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 REST wrappers
//! (retired with the HTTP listener, #6637); #3297 adds [`sse`] —
//! the workstream aggregation — 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.
//!
//! [`Workstream`]: crate::workstreams::Workstream
//! [`WorkstreamId`]: crate::workstreams::WorkstreamId
//! [`WorkstreamState`]: crate::workstreams::WorkstreamState
//! [`model`]: crate::workstreams::model
//! [`WorkstreamStore`]: crate::workstreams::WorkstreamStore
//! [`store`]: crate::workstreams::store
//! [`activation`]: crate::workstreams::activation
//! [`protocol`]: crate::workstreams::protocol
//! [`sse`]: crate::workstreams::sse
//! [`store::WorkstreamStore`]: crate::workstreams::store::WorkstreamStore
/// (#6637) `workstream.events`: the socket transport's live fan-out, a bridge
/// onto the `sse::aggregate_live` combinator.
pub use ;
pub use ;
pub use ;
pub use WorkstreamEventEnvelope;
pub use ;
/// Test-only helper: a fresh, in-memory-backed [`SharedWorkstreamStore`]
/// rooted at a throwaway tempdir (issue #3298).
///
/// Why: `session::protocol::register`/`task::protocol::register` both now
/// require a `SharedWorkstreamStore` — every test call site across the
/// crate that wires either `register` but does not itself care about
/// workstream binding needs a cheap, disposable store rather than resolving
/// the real `~/.trusty-code` directory. One helper here (rather than each
/// call site re-deriving its own) keeps that boilerplate in exactly one
/// place.
/// What: loads a fresh [`WorkstreamStore`] at a tempdir path and wraps it in
/// the same `Arc<tokio::sync::Mutex<_>>` shape production code uses. The
/// `TempDir` guard is intentionally dropped here — `WorkstreamStore::save`
/// re-creates its parent directory on every write (see that method's docs),
/// so a test that never asserts on persisted file contents (the common case)
/// is unaffected by the directory's removal.
pub async