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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//! Portable value types for [`super::WorkstreamConnector`] — request/response
//! shapes both the tm and tcode backends speak (DOC-44 §5.2/§5.4).
//!
//! Why: DOC-44 §1.2/§4.1 requires the tm and tcode backends to be reachable
//! through ONE trait without forcing them to be symmetric — tm provisions a
//! git worktree per session and attaches via a tmux shell command; tcode
//! creates a session inside an existing local project and attaches via a
//! ring-buffer replay + SSE stream. Rather than lossy-flatten that asymmetry
//! into a single struct (which would leave half the fields meaningless for
//! either backend), the two points of genuine divergence — session creation
//! and attach — are modelled as explicit enums (`BackendParams`,
//! `AttachHandle`); everything else (list/status/send/delegate) is symmetric
//! enough to share one shape.
//! What: [`CreateSessionReq`] (common core + [`BackendParams`] extension),
//! [`SessionInfo`] (list-entry summary), [`SessionStatus`] (point-lookup
//! detail), [`AttachHandle`] (the tm-vs-tcode attach asymmetry),
//! [`AgentSpec`]/[`DelegateHandle`] (the `delegate` operation's request and
//! response).
//! Test: `types::tests` covers construction and the `BackendParams`/
//! `AttachHandle` variant matching; `test_kit::tests` drives the session types
//! through the connector trait.
use ;
/// Per-backend session-creation parameters (DOC-44 locked decision 4).
///
/// Why: tm provisions an isolated git worktree (needs `repo_url`/`git_ref`/
/// `runtime`/`ephemeral`); tcode binds to an existing local project directory
/// (needs `project`). Forcing one struct with all fields optional would let a
/// caller build a request that is valid for neither backend and silently
/// drop data; a backend rejects the variant it does not implement with
/// [`super::ConnectorError::InvalidRequest`] instead.
/// What: `Tm` mirrors the daemon's `SpawnRequest` provisioning fields
/// (`crates/trusty-mpm/src/daemon/managed_routes/mod.rs`); `Tcode` carries
/// the existing local project path `session.create` requires.
/// Test: `types::tests::backend_params_variants_are_distinct`.
/// Common core session-creation request, plus the per-backend extension.
///
/// Why: `task`/`name_hint`/`agent` are meaningful to both backends
/// (tm: task description + tmux name hint; tcode: `session.create`'s
/// `task`/`agent` params) — see DOC-44 locked decision 4.
/// What: `name_hint` is tm-specific in practice (tcode has no equivalent
/// concept and ignores it); `agent` is tcode-specific in practice (tm's
/// spawn request has no `agent` field and ignores it). Both stay on the
/// common core rather than moving into `BackendParams` because a caller
/// that doesn't know which backend it's talking to can still fill them in
/// harmlessly — the receiving backend ignores what it doesn't use rather
/// than erroring.
/// Test: `types::tests::create_session_req_round_trips_backend_params`.
/// One session as returned by `list_sessions`.
///
/// Why: both backends already expose a flat, string-typed summary
/// (tm's `SessionSummary`, tcode's `Session`) — this is the intersection a
/// caller can render without knowing which backend produced it.
/// What: `state` deliberately stays a raw backend-native string rather than
/// a shared enum — tm's lifecycle vocabulary (`"active"`, `"stopped"`,
/// `"errored"`, `"provisioning"`, `"decommissioned"`, …) and tcode's
/// (`"created"`, `"running"`, `"cancelled"`, `"finished"`, `"failed"`,
/// `"deadline_exceeded"`) do not have a 1:1 mapping; collapsing them into one
/// enum would either lose information or invent states neither backend has.
/// `task` is optional because a legacy tm record may omit it.
/// Test: `test_kit::tests::assert_basic_lifecycle_passes_against_mock`.
/// One session's detail as returned by `session_status`.
///
/// Why: a point lookup needs slightly more than the list summary (a pending
/// decision, when the backend surfaces one) without pulling the full
/// backend-native record.
/// What: `state` uses the same backend-native vocabulary as
/// [`SessionInfo::state`] — see that field's docs.
/// Test: `test_kit::tests::assert_basic_lifecycle_passes_against_mock`.
/// The asymmetric result of `attach` (DOC-44 locked decision 2).
///
/// Why: tm's attach surface is a tmux shell command an operator runs in
/// their own terminal (`GET .../attach-cmd`); tcode's is a ring-buffer
/// replay plus a live SSE stream URL (`session.attach`). These are not two
/// encodings of the same concept — forcing them into one shape (e.g. always
/// returning a URL, with tm's being a fake `tmux://` scheme) would invent a
/// protocol neither backend speaks. The enum keeps each backend's real
/// contract visible to the caller.
/// What: `ShellCommand` — a fully-formed command line the caller (a human
/// operator, or code that shells out) runs directly, e.g.
/// `"tmux attach -t '=tmpm-a1b2c3'"`. `EventStream` — the replayed ring-buffer
/// events plus the URL a caller GETs (as SSE) for live events.
/// Test: `types::tests::attach_handle_variants_are_distinct`.
/// Request payload for `delegate` — spawn a sub-agent within a session.
///
/// Why: shared by both backends' `delegate` signature even though only tm
/// implements it (tcode returns
/// [`super::ConnectorError::NotSupported`] — see that backend's docs).
/// What: `agent_name` names the sub-agent persona/role; `task` is its
/// instruction; `tier` is an optional model-tier hint (tm: `"haiku"` |
/// `"sonnet"` | `"opus"`, mirroring `agent_delegate`'s MCP tool signature).
/// Test: `test_kit::tests::assert_delegate_not_supported_passes_against_mock`.
/// Result of a successful `delegate` call.
///
/// Why: the caller needs a handle to correlate this delegation with later
/// status/audit lookups (DOC-44 §3.5's audit trail, future work) without the
/// connector owning any state itself (connectors are stateless — DOC-44
/// §2.1).
/// What: `delegate_id` is the backend-assigned tracking id (tm:
/// `Delegation::id`, a UUID); `note` carries any backend-supplied
/// human-readable context (tm: the circuit-breaker state at delegation
/// time).
/// Test: `types::tests::delegate_handle_construction`.