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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
//! SDK pane event vocabulary.
//!
//! The [`PaneEvent`] enum models the tmux-compatible control-mode line
//! vocabulary the rmux daemon emits to attached `-C`/`-CC` clients. The
//! types here are *inert* DTOs: they do not parse the wire bytes, hold
//! channel handles, or run state machines. They exist so SDK consumers can
//! receive a typed projection of the daemon's control-mode stream without
//! pulling in `rmux-core`, `rmux-server`, `rmux-client`, or `rmux-pty`.
//!
//! ## Output sequencing semantics
//!
//! The order in which a daemon emits these events is intentionally
//! observable, because `rmux-server`'s control loop in
//! `crates/rmux-server/src/control.rs` matches the tmux compatibility
//! contract. Consumers that resequence events MUST preserve these rules:
//!
//! * **Command stdout flushes before `%end`/`%error`.** When an active
//! command block resolves, any [`PaneCommandSummary::stdout`]
//! bytes are written into the output queue *before* the trailing
//! [`%end` or `%error` guard line](PaneCommandSummary). The guard line
//! carries the same `command_number`/`timestamp` as the matching
//! `%begin`. Any [`PaneEvent::Output`] or [`PaneEvent::ExtendedOutput`]
//! that has already arrived for a non-paused pane is also drained ahead
//! of the guard line so the transcript respects causal order.
//! * **Notifications and exits defer until active command blocks close.**
//! While a `%begin`/`%end` block is in flight, any
//! [`PaneEvent::Notification`] or [`PaneEvent::Exit`] the server would
//! normally emit is queued and replayed only after the command block
//! has completed. A deferred [`PaneEvent::Exit`] additionally waits for
//! all queued notifications to flush, so the final transcript ends with
//! `%message` lines, then `%exit`.
//! * **EOF and empty input emit a bare `%exit`.** When the client closes
//! stdin (or sends an empty line), the server emits
//! [`PaneEvent::Exit`] with [`PaneExitReason::Bare`] — this is the
//! `%exit` line with no reason text and no preceding guard tuple, and
//! it is the canonical way the control transcript terminates.
//! * **Lag precedes the matching disconnect.** A [`PaneEvent::Lag`]
//! indicates the per-pane broadcast receiver skipped frames before
//! those frames reached the control output queue. When an SDK timeline
//! records the following transport teardown, the trailing
//! [`PaneEvent::Disconnect`] carries
//! [`PaneDisconnectReason::TooFarBehind`] and the same `pane_id` in its
//! optional attribution field. This is distinct from the daemon's aged
//! output-queue path, which writes `%exit too far behind` after a queued
//! output block waits past the tmux-compatible maximum age and has no
//! reliable pane attribution.
//!
//! These rules are exercised by the JSON/bincode roundtrip tests in
//! `crates/rmux-sdk/tests/events.rs`, which cover every variant including
//! raw byte payloads and [`PaneId`] identity fields.
use ;
use cratePaneId;
/// Tmux-compatible control-mode pane event vocabulary surfaced by the SDK.
///
/// The enum is externally tagged for serde, so the JSON projection of
/// each variant is `{"<kebab-case-tag>": {...}}` (or `"<tag>"` for unit
/// variants). External tagging is what `bincode` supports natively, so
/// the same encoding round-trips through both `serde_json` and
/// `bincode`.
///
/// Marked `#[non_exhaustive]` because the daemon vocabulary is a moving
/// target — added variants must not break downstream pattern matches.
/// Structured reason carried by [`PaneEvent::Disconnect`].
///
/// Marked `#[non_exhaustive]` so new transport-level disconnect causes can
/// be modelled without breaking downstream pattern matches. Externally
/// tagged for serde, so the encoding round-trips through both
/// `serde_json` and `bincode`.
/// Structured reason carried by [`PaneEvent::Exit`].
///
/// `Bare` denotes the canonical `%exit\n` form emitted on EOF / empty
/// input. `WithReason` carries the trailing reason text from
/// `%exit <reason>\n`; the daemon uses this for graceful operator-driven
/// closes (e.g. `%exit server shutting down`). Externally tagged for
/// serde, so the encoding round-trips through both `serde_json` and
/// `bincode`.
/// Permission scope that produced a [`PaneEvent::PermissionDenied`].
///
/// Marked `#[non_exhaustive]` so additional permission categories (such as
/// per-window or per-client policies) can be added without breaking
/// downstream pattern matches.
/// `%message`-style notification carried by [`PaneEvent::Notification`].
///
/// `text` is the already-decoded human-readable message text (the SDK
/// transport layer reverses the daemon's `encode_paste_bytes` escaping).
/// `pane_id` is set for pane-scoped notifications and omitted for
/// session/server-scoped lines such as `%sessions-changed`.
/// Status of a completed control-mode command block.
///
/// The daemon's trailing guard line is either `%end` or `%error`; command
/// output and error text have already been flushed as stdout bytes before
/// that guard line.
/// Summary of a `%begin`/`%end`/`%error` control-mode command block.
///
/// `timestamp`, `command_number`, and `flags` mirror the guard tuple
/// emitted by the daemon's
/// [`format_guard_line`](rmux_proto::format_guard_line). `status`
/// identifies the trailing guard kind. `stdout` carries every decoded byte
/// the daemon flushed *before* that guard line, including parse or command
/// error text for `%error` blocks.