rmux-proto 0.1.0

RMUX detached IPC protocol DTOs, framing, and wire-safe error types.
Documentation
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
//! Detached request contracts.

use serde::{Deserialize, Serialize};
use std::path::PathBuf;

use crate::{
    ControlModeRequest, HandshakeRequest, PaneTarget, SdkWaitId, SdkWaitOwnerId, SessionName,
    Target, WindowTarget,
};

#[path = "request/show.rs"]
mod show;
pub use show::ShowHooksRequest;
pub use show::{ShowEnvironmentRequest, ShowOptionsRequest};

#[path = "request/layout.rs"]
mod layout;
pub use layout::{
    NextLayoutRequest, PreviousLayoutRequest, SelectCustomLayoutRequest, SelectLayoutRequest,
    SelectLayoutTarget, SelectOldLayoutRequest, SpreadLayoutRequest,
};

#[path = "request/pane.rs"]
mod pane;
pub use pane::{
    BreakPaneRequest, DisplayPanesRequest, JoinPaneRequest, KillPaneRequest, LastPaneRequest,
    MovePaneRequest, PaneOutputCursorRequest, PaneOutputSubscriptionStart, PaneSnapshotRequest,
    PaneSplitSize, PipePaneRequest, ResizePaneRequest, RespawnPaneRequest,
    SelectPaneAdjacentRequest, SelectPaneDirection, SelectPaneMarkRequest, SelectPaneRequest,
    SendKeysExtRequest, SendKeysRequest, SplitWindowExtRequest, SplitWindowRequest,
    SplitWindowTarget, SubscribePaneOutputRequest, SwapPaneDirection, SwapPaneRequest,
    UnsubscribePaneOutputRequest,
};

#[path = "request/window.rs"]
mod window;
pub use window::{
    KillWindowRequest, LastWindowRequest, LinkWindowRequest, ListWindowsRequest, MoveWindowRequest,
    MoveWindowTarget, NewWindowRequest, NextWindowRequest, PreviousWindowRequest,
    RenameWindowRequest, ResizeWindowAdjustment, ResizeWindowRequest, RespawnWindowRequest,
    RotateWindowDirection, RotateWindowRequest, SelectWindowRequest, SwapWindowRequest,
};

#[path = "request/target.rs"]
mod target;
pub use target::{ResolveTargetRequest, ResolveTargetType};

#[path = "request/session.rs"]
mod session;
pub use session::{
    HasSessionRequest, KillSessionRequest, ListSessionsRequest, NewSessionExtRequest,
    NewSessionRequest, RenameSessionRequest,
};

#[path = "request/server.rs"]
mod server;
pub use server::{
    KillServerRequest, LockClientRequest, LockServerRequest, LockSessionRequest,
    ServerAccessRequest,
};

#[path = "request/client.rs"]
mod client;
pub use client::{
    AttachSessionExt2Request, AttachSessionExtRequest, AttachSessionRequest,
    DetachClientExtRequest, DetachClientRequest, ListClientsRequest, RefreshClientRequest,
    SuspendClientRequest, SwitchClientExt2Request, SwitchClientExt3Request, SwitchClientExtRequest,
    SwitchClientRequest,
};

#[path = "request/keys.rs"]
mod keys;
pub use keys::{
    BindKeyRequest, ClockModeRequest, CopyModeRequest, ListKeysRequest, SendPrefixRequest,
    UnbindKeyRequest,
};

#[path = "request/options.rs"]
mod options;
pub use options::{
    SetEnvironmentMode, SetEnvironmentRequest, SetHookMutationRequest, SetHookRequest,
    SetOptionByNameRequest, SetOptionRequest,
};

#[path = "request/buffer.rs"]
mod buffer;
pub use buffer::{
    CapturePaneRequest, ClearHistoryRequest, DeleteBufferRequest, ListBuffersRequest,
    LoadBufferRequest, PasteBufferRequest, SaveBufferRequest, SetBufferRequest, ShowBufferRequest,
};

/// All detached public command and internal RPC requests supported by the wire
/// protocol.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum Request {
    /// `new-session`
    NewSession(NewSessionRequest),
    /// `has-session`
    HasSession(HasSessionRequest),
    /// `kill-session`
    KillSession(KillSessionRequest),
    /// `new-window`
    NewWindow(NewWindowRequest),
    /// `kill-window`
    KillWindow(KillWindowRequest),
    /// `select-window`
    SelectWindow(SelectWindowRequest),
    /// `rename-window`
    RenameWindow(RenameWindowRequest),
    /// `next-window`
    NextWindow(NextWindowRequest),
    /// `previous-window`
    PreviousWindow(PreviousWindowRequest),
    /// `last-window`
    LastWindow(LastWindowRequest),
    /// `list-windows`
    ListWindows(ListWindowsRequest),
    /// `move-window`
    MoveWindow(MoveWindowRequest),
    /// `swap-window`
    SwapWindow(SwapWindowRequest),
    /// `rotate-window`
    RotateWindow(RotateWindowRequest),
    /// `split-window`
    SplitWindow(SplitWindowRequest),
    /// `swap-pane`
    SwapPane(SwapPaneRequest),
    /// `last-pane`
    LastPane(LastPaneRequest),
    /// `join-pane`
    JoinPane(JoinPaneRequest),
    /// `break-pane`
    BreakPane(BreakPaneRequest),
    /// `kill-pane`
    KillPane(KillPaneRequest),
    /// `select-layout`
    SelectLayout(SelectLayoutRequest),
    /// `resize-pane`
    ResizePane(ResizePaneRequest),
    /// `display-panes`
    DisplayPanes(DisplayPanesRequest),
    /// `select-pane`
    SelectPane(SelectPaneRequest),
    /// `select-pane -U/-D/-L/-R`
    SelectPaneAdjacent(SelectPaneAdjacentRequest),
    /// `send-keys`
    SendKeys(SendKeysRequest),
    /// `attach-session`
    AttachSession(AttachSessionRequest),
    /// `switch-client`
    SwitchClient(SwitchClientRequest),
    /// `detach-client`
    DetachClient(DetachClientRequest),
    /// `set-option`
    SetOption(SetOptionRequest),
    /// `set-environment`
    SetEnvironment(SetEnvironmentRequest),
    /// `set-hook`
    SetHook(SetHookRequest),
    /// `next-layout`
    NextLayout(NextLayoutRequest),
    /// `previous-layout`
    PreviousLayout(PreviousLayoutRequest),
    /// `show-options`
    ShowOptions(ShowOptionsRequest),
    /// `show-environment`
    ShowEnvironment(ShowEnvironmentRequest),
    /// `set-buffer`
    SetBuffer(SetBufferRequest),
    /// `show-buffer`
    ShowBuffer(ShowBufferRequest),
    /// `paste-buffer`
    PasteBuffer(PasteBufferRequest),
    /// `list-buffers`
    ListBuffers(ListBuffersRequest),
    /// `delete-buffer`
    DeleteBuffer(DeleteBufferRequest),
    /// `load-buffer`
    LoadBuffer(LoadBufferRequest),
    /// `save-buffer`
    SaveBuffer(SaveBufferRequest),
    /// `capture-pane`
    CapturePane(CapturePaneRequest),
    /// `display-message`
    DisplayMessage(DisplayMessageRequest),
    /// `run-shell`
    RunShell(RunShellRequest),
    /// `if-shell`
    IfShell(IfShellRequest),
    /// `wait-for`
    WaitFor(WaitForRequest),
    /// `rename-session`
    RenameSession(RenameSessionRequest),
    /// `list-sessions`
    ListSessions(ListSessionsRequest),
    /// `list-panes`
    ListPanes(ListPanesRequest),
    /// `source-file`
    SourceFile(SourceFileRequest),
    /// `set-option` using an open string-based option name.
    SetOptionByName(SetOptionByNameRequest),
    /// Extended `set-hook` mutation semantics.
    SetHookMutation(SetHookMutationRequest),
    /// `show-hooks`
    ShowHooks(ShowHooksRequest),
    /// Extended `send-keys` semantics including key-table dispatch and format expansion.
    SendKeysExt(SendKeysExtRequest),
    /// Extended `switch-client` semantics including `-T key-table`.
    SwitchClientExt(SwitchClientExtRequest),
    /// `bind-key`
    BindKey(BindKeyRequest),
    /// `unbind-key`
    UnbindKey(UnbindKeyRequest),
    /// `list-keys`
    ListKeys(ListKeysRequest),
    /// `send-prefix`
    SendPrefix(SendPrefixRequest),
    /// `clear-history`
    ClearHistory(ClearHistoryRequest),
    /// `copy-mode`
    CopyMode(CopyModeRequest),
    /// Internal detached upgrade into tmux-compatible control mode.
    ControlMode(ControlModeRequest),
    /// `clock-mode`
    ClockMode(ClockModeRequest),
    /// `show-messages`
    ShowMessages(ShowMessagesRequest),
    /// Extended `new-session` semantics including grouped sessions and attach-if-exists.
    NewSessionExt(NewSessionExtRequest),
    /// Extended `attach-session` semantics including client flags and detach-others.
    AttachSessionExt(AttachSessionExtRequest),
    /// Extended `switch-client` semantics including `-l`, `-n`, `-p`, and readonly toggles.
    SwitchClientExt2(SwitchClientExt2Request),
    /// `select-layout` with a tmux custom layout string.
    SelectCustomLayout(SelectCustomLayoutRequest),
    /// `select-layout -o`
    SelectOldLayout(SelectOldLayoutRequest),
    /// `select-layout -E`
    SpreadLayout(SpreadLayoutRequest),
    /// `kill-server`
    KillServer(KillServerRequest),
    /// `lock-server`
    LockServer(LockServerRequest),
    /// `lock-session`
    LockSession(LockSessionRequest),
    /// `lock-client`
    LockClient(LockClientRequest),
    /// `server-access`
    ServerAccess(ServerAccessRequest),
    /// `refresh-client`
    RefreshClient(RefreshClientRequest),
    /// `list-clients`
    ListClients(ListClientsRequest),
    /// `suspend-client`
    SuspendClient(SuspendClientRequest),
    /// Extended `detach-client` semantics including `-a`, `-s`, `-P`, and `-E`.
    DetachClientExt(DetachClientExtRequest),
    /// Further-extended `attach-session` semantics including `-c working-directory`.
    AttachSessionExt2(AttachSessionExt2Request),
    /// Further-extended `switch-client` semantics including `-c target-client` and `-Z`.
    SwitchClientExt3(SwitchClientExt3Request),
    /// `resize-window`
    ResizeWindow(ResizeWindowRequest),
    /// `respawn-window`
    RespawnWindow(RespawnWindowRequest),
    /// `move-pane`
    MovePane(MovePaneRequest),
    /// `pipe-pane`
    PipePane(PipePaneRequest),
    /// `respawn-pane`
    RespawnPane(RespawnPaneRequest),
    /// `link-window`
    LinkWindow(LinkWindowRequest),
    /// `unlink-window`
    UnlinkWindow(UnlinkWindowRequest),
    /// `select-pane -m` / `select-pane -M`
    SelectPaneMark(SelectPaneMarkRequest),
    /// Internal detached target resolution for tmux-style raw target text.
    ResolveTarget(ResolveTargetRequest),
    /// Extended `split-window` semantics including an explicit shell command.
    SplitWindowExt(SplitWindowExtRequest),
    /// Internal SDK/daemon version and capability negotiation.
    Handshake(HandshakeRequest),
    /// Internal daemon-backed structured pane snapshot endpoint.
    PaneSnapshot(PaneSnapshotRequest),
    /// Internal daemon-backed pane output subscription endpoint.
    SubscribePaneOutput(SubscribePaneOutputRequest),
    /// Internal daemon-backed pane output unsubscription endpoint.
    UnsubscribePaneOutput(UnsubscribePaneOutputRequest),
    /// Internal daemon-backed pane output cursor polling endpoint.
    PaneOutputCursor(PaneOutputCursorRequest),
    /// Internal daemon-backed SDK byte wait endpoint.
    SdkWaitForOutput(SdkWaitForOutputRequest),
    /// Internal daemon-backed SDK wait cancellation endpoint.
    CancelSdkWait(CancelSdkWaitRequest),
}

impl Request {
    /// Returns the stable routing name for the request variant.
    #[must_use]
    pub const fn command_name(&self) -> &'static str {
        match self {
            Self::NewSession(_) => "new-session",
            Self::HasSession(_) => "has-session",
            Self::KillSession(_) => "kill-session",
            Self::NewWindow(_) => "new-window",
            Self::KillWindow(_) => "kill-window",
            Self::SelectWindow(_) => "select-window",
            Self::RenameWindow(_) => "rename-window",
            Self::NextWindow(_) => "next-window",
            Self::PreviousWindow(_) => "previous-window",
            Self::LastWindow(_) => "last-window",
            Self::ListWindows(_) => "list-windows",
            Self::LinkWindow(_) => "link-window",
            Self::MoveWindow(_) => "move-window",
            Self::SwapWindow(_) => "swap-window",
            Self::RotateWindow(_) => "rotate-window",
            Self::SplitWindow(_) | Self::SplitWindowExt(_) => "split-window",
            Self::SwapPane(_) => "swap-pane",
            Self::LastPane(_) => "last-pane",
            Self::JoinPane(_) => "join-pane",
            Self::BreakPane(_) => "break-pane",
            Self::KillPane(_) => "kill-pane",
            Self::SelectLayout(_) => "select-layout",
            Self::ResizePane(_) => "resize-pane",
            Self::DisplayPanes(_) => "display-panes",
            Self::SelectPane(_) | Self::SelectPaneAdjacent(_) | Self::SelectPaneMark(_) => {
                "select-pane"
            }
            Self::SendKeys(_) => "send-keys",
            Self::AttachSession(_) => "attach-session",
            Self::SwitchClient(_) => "switch-client",
            Self::DetachClient(_) => "detach-client",
            Self::SetOption(_) => "set-option",
            Self::SetEnvironment(_) => "set-environment",
            Self::SetHook(_) => "set-hook",
            Self::NextLayout(_) => "next-layout",
            Self::PreviousLayout(_) => "previous-layout",
            Self::ShowOptions(_) => "show-options",
            Self::ShowEnvironment(_) => "show-environment",
            Self::SetBuffer(_) => "set-buffer",
            Self::ShowBuffer(_) => "show-buffer",
            Self::PasteBuffer(_) => "paste-buffer",
            Self::ListBuffers(_) => "list-buffers",
            Self::DeleteBuffer(_) => "delete-buffer",
            Self::LoadBuffer(_) => "load-buffer",
            Self::SaveBuffer(_) => "save-buffer",
            Self::CapturePane(_) => "capture-pane",
            Self::PaneSnapshot(_) => "pane-snapshot",
            Self::SubscribePaneOutput(_) => "subscribe-pane-output",
            Self::UnsubscribePaneOutput(_) => "unsubscribe-pane-output",
            Self::PaneOutputCursor(_) => "pane-output-cursor",
            Self::SdkWaitForOutput(_) => "sdk-wait-output",
            Self::CancelSdkWait(_) => "cancel-sdk-wait",
            Self::DisplayMessage(_) => "display-message",
            Self::ResolveTarget(_) => "resolve-target",
            Self::RunShell(_) => "run-shell",
            Self::IfShell(_) => "if-shell",
            Self::WaitFor(_) => "wait-for",
            Self::RenameSession(_) => "rename-session",
            Self::ListSessions(_) => "list-sessions",
            Self::ListPanes(_) => "list-panes",
            Self::SourceFile(_) => "source-file",
            Self::UnlinkWindow(_) => "unlink-window",
            Self::SetOptionByName(_) => "set-option",
            Self::SetHookMutation(_) => "set-hook",
            Self::ShowHooks(_) => "show-hooks",
            Self::SendKeysExt(_) => "send-keys",
            Self::SwitchClientExt(_) => "switch-client",
            Self::BindKey(_) => "bind-key",
            Self::UnbindKey(_) => "unbind-key",
            Self::ListKeys(_) => "list-keys",
            Self::SendPrefix(_) => "send-prefix",
            Self::ClearHistory(_) => "clear-history",
            Self::CopyMode(_) => "copy-mode",
            Self::ControlMode(_) => "control-mode",
            Self::ClockMode(_) => "clock-mode",
            Self::ShowMessages(_) => "show-messages",
            Self::NewSessionExt(_) => "new-session",
            Self::AttachSessionExt(_) => "attach-session",
            Self::SwitchClientExt2(_) => "switch-client",
            Self::SelectCustomLayout(_) => "select-layout",
            Self::SelectOldLayout(_) => "select-layout",
            Self::SpreadLayout(_) => "select-layout",
            Self::ResizeWindow(_) => "resize-window",
            Self::RespawnWindow(_) => "respawn-window",
            Self::MovePane(_) => "move-pane",
            Self::PipePane(_) => "pipe-pane",
            Self::RespawnPane(_) => "respawn-pane",
            Self::KillServer(_) => "kill-server",
            Self::LockServer(_) => "lock-server",
            Self::LockSession(_) => "lock-session",
            Self::LockClient(_) => "lock-client",
            Self::ServerAccess(_) => "server-access",
            Self::RefreshClient(_) => "refresh-client",
            Self::ListClients(_) => "list-clients",
            Self::SuspendClient(_) => "suspend-client",
            Self::DetachClientExt(_) => "detach-client",
            Self::AttachSessionExt2(_) => "attach-session",
            Self::SwitchClientExt3(_) => "switch-client",
            Self::Handshake(_) => "handshake",
        }
    }
}

/// Request payload for `display-message`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DisplayMessageRequest {
    /// The optional exact session, window, or pane target used as format context.
    pub target: Option<Target>,
    /// Whether to print the expanded message to stdout instead of displaying it.
    pub print: bool,
    /// The optional format string. When omitted, the tmux-compatible default is used.
    pub message: Option<String>,
}

/// Request payload for `show-messages`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ShowMessagesRequest {
    /// Whether to print the server job summary.
    pub jobs: bool,
    /// Whether to print terminal information.
    pub terminals: bool,
    /// The optional target client filter used by terminal and job summaries.
    pub target_client: Option<String>,
}

/// Request payload for `run-shell`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RunShellRequest {
    /// The server-local shell command passed to `sh -c`.
    pub command: String,
    /// Whether the command should run fire-and-forget without output capture.
    pub background: bool,
    /// Whether the command should be executed as tmux commands instead of `sh -c`.
    #[serde(default)]
    pub as_commands: bool,
    /// Whether stderr should be captured alongside stdout.
    #[serde(default)]
    pub show_stderr: bool,
    /// Optional delay, in seconds, before the command runs.
    #[serde(default)]
    pub delay_seconds: Option<RunShellDelaySeconds>,
    /// Optional explicit working directory.
    #[serde(default)]
    pub start_directory: Option<PathBuf>,
    /// Optional explicit target pane used for format and session context.
    #[serde(default)]
    pub target: Option<PaneTarget>,
}

/// Losslessly serializable `run-shell -d` seconds value with stable `Eq`.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct RunShellDelaySeconds(pub f64);

impl RunShellDelaySeconds {
    /// Returns the raw seconds value.
    #[must_use]
    pub const fn as_secs_f64(self) -> f64 {
        self.0
    }
}

impl PartialEq for RunShellDelaySeconds {
    fn eq(&self, other: &Self) -> bool {
        self.0.to_bits() == other.0.to_bits()
    }
}

impl Eq for RunShellDelaySeconds {}

/// Request payload for `if-shell`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct IfShellRequest {
    /// The condition string expanded through the shared formatter before evaluation.
    pub condition: String,
    /// Whether to evaluate the expanded condition with format truthiness instead of `sh -c`.
    pub format_mode: bool,
    /// The nested RMUX command string dispatched when the condition is true.
    pub then_command: String,
    /// The optional nested RMUX command string dispatched when the condition is false.
    pub else_command: Option<String>,
    /// Optional exact target used as shared-format context.
    pub target: Option<Target>,
    /// The caller working directory used to resolve nested relative file paths.
    pub caller_cwd: Option<PathBuf>,
    /// Whether the condition should be evaluated asynchronously.
    #[serde(default)]
    pub background: bool,
}

/// Request payload for `source-file`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SourceFileRequest {
    /// The path arguments to expand, glob, parse, and optionally execute.
    pub paths: Vec<String>,
    /// Whether missing files and glob misses should be suppressed.
    pub quiet: bool,
    /// Whether to parse only without executing parsed commands.
    pub parse_only: bool,
    /// Whether parsed commands should be printed to stdout.
    pub verbose: bool,
    /// Whether each path argument should be format-expanded before globbing.
    pub expand_paths: bool,
    /// Optional pane target used as the `-F` format context.
    pub target: Option<PaneTarget>,
    /// The caller working directory used to resolve relative paths.
    pub caller_cwd: Option<PathBuf>,
    /// Content read from client stdin for `source-file -`.
    pub stdin: Option<String>,
}

/// Request payload for `unlink-window`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UnlinkWindowRequest {
    /// The window slot to remove.
    pub target: WindowTarget,
    /// Whether removing the final link is allowed (`-k`).
    #[serde(default)]
    pub kill_if_last: bool,
}

/// The supported `wait-for` operation modes.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum WaitForMode {
    /// Wait for the next signal on the named channel.
    Wait,
    /// Signal all current plain waiters on the named channel.
    Signal,
    /// Acquire the named server-local lock, waiting in FIFO order when held.
    Lock,
    /// Release the named server-local lock.
    Unlock,
}

/// Request payload for `wait-for`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WaitForRequest {
    /// The server-local wait channel name.
    pub channel: String,
    /// The selected wait operation.
    pub mode: WaitForMode,
}

/// Request payload for a daemon-backed SDK byte wait.
///
/// This is intentionally distinct from tmux-compatible [`WaitForRequest`].
/// SDK waits are pane-output waits with typed IDs used only for cancellation
/// and teardown bookkeeping; they never signal or lock tmux `wait-for`
/// channels.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SdkWaitForOutputRequest {
    /// Opaque SDK transport owner for this wait.
    pub owner_id: SdkWaitOwnerId,
    /// Wait ID allocated by the SDK under `owner_id`.
    pub wait_id: SdkWaitId,
    /// Pane whose raw output stream is observed.
    pub target: PaneTarget,
    /// Raw byte sequence to search for in pane output.
    pub bytes: Vec<u8>,
    /// Cursor position used when arming the wait.
    pub start: PaneOutputSubscriptionStart,
}

/// Request payload for best-effort cancellation of a daemon-backed SDK wait.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct CancelSdkWaitRequest {
    /// Opaque SDK transport owner for the wait being cancelled.
    pub owner_id: SdkWaitOwnerId,
    /// Wait ID allocated by the SDK under `owner_id`.
    pub wait_id: SdkWaitId,
}

/// Request payload for `list-panes`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ListPanesRequest {
    /// The exact target session name.
    pub target: SessionName,
    /// Optional exact target window index.
    #[serde(default)]
    pub target_window_index: Option<u32>,
    /// An optional server-side format template.
    pub format: Option<String>,
}

#[cfg(test)]
#[path = "request/compat_tests.rs"]
mod compat_tests;

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        OptionScopeSelector, PaneTarget, ScopeSelector, SelectPaneDirection, SetOptionMode,
        SplitDirection,
    };

    fn alpha() -> SessionName {
        SessionName::new("alpha").expect("valid session")
    }

    fn pane() -> PaneTarget {
        PaneTarget::new(alpha(), 0)
    }

    #[test]
    fn request_command_names_cover_extended_aliases_and_internal_tags() {
        assert_eq!(
            Request::NewSessionExt(NewSessionExtRequest {
                session_name: None,
                working_directory: None,
                detached: true,
                size: None,
                environment: None,
                group_target: None,
                attach_if_exists: false,
                detach_other_clients: false,
                kill_other_clients: false,
                flags: None,
                window_name: None,
                print_session_info: false,
                print_format: None,
                command: None,
            })
            .command_name(),
            "new-session"
        );
        assert_eq!(
            Request::SplitWindowExt(SplitWindowExtRequest {
                target: SplitWindowTarget::Pane(pane()),
                direction: SplitDirection::Vertical,
                before: false,
                environment: None,
                command: None,
            })
            .command_name(),
            "split-window"
        );
        assert_eq!(
            Request::SelectPaneAdjacent(SelectPaneAdjacentRequest {
                target: pane(),
                direction: SelectPaneDirection::Right,
            })
            .command_name(),
            "select-pane"
        );
        assert_eq!(
            Request::SelectPaneMark(SelectPaneMarkRequest {
                target: pane(),
                clear: false,
                title: None,
            })
            .command_name(),
            "select-pane"
        );
        assert_eq!(
            Request::SetOptionByName(SetOptionByNameRequest {
                scope: OptionScopeSelector::ServerGlobal,
                name: "status".to_owned(),
                value: Some("on".to_owned()),
                mode: SetOptionMode::Replace,
                only_if_unset: false,
                unset: false,
                unset_pane_overrides: false,
            })
            .command_name(),
            "set-option"
        );
        assert_eq!(
            Request::SetHookMutation(SetHookMutationRequest {
                scope: ScopeSelector::Global,
                hook: crate::HookName::AfterNewSession,
                command: None,
                lifecycle: crate::HookLifecycle::Persistent,
                append: false,
                unset: true,
                run_immediately: false,
                index: None,
            })
            .command_name(),
            "set-hook"
        );
        assert_eq!(
            Request::AttachSessionExt2(AttachSessionExt2Request {
                target: Some(alpha()),
                target_spec: None,
                detach_other_clients: false,
                kill_other_clients: false,
                read_only: false,
                skip_environment_update: false,
                flags: None,
                working_directory: None,
                client_terminal: crate::ClientTerminalContext::default(),
                client_size: None,
            })
            .command_name(),
            "attach-session"
        );
        assert_eq!(
            Request::SwitchClientExt3(SwitchClientExt3Request {
                target_client: None,
                target: Some("alpha:0.0".to_owned()),
                key_table: None,
                last_session: false,
                next_session: false,
                previous_session: false,
                toggle_read_only: false,
                sort_order: None,
                skip_environment_update: false,
                zoom: false,
            })
            .command_name(),
            "switch-client"
        );
        assert_eq!(
            Request::ResolveTarget(ResolveTargetRequest {
                target: Some("alpha:0.0".to_owned()),
                target_type: ResolveTargetType::Pane,
                window_index: false,
                prefer_unattached: false,
            })
            .command_name(),
            "resolve-target"
        );
        assert_eq!(
            Request::Handshake(HandshakeRequest::current()).command_name(),
            "handshake"
        );
        assert_eq!(
            Request::SdkWaitForOutput(SdkWaitForOutputRequest {
                owner_id: SdkWaitOwnerId::new(1),
                wait_id: SdkWaitId::new(1),
                target: pane(),
                bytes: b"ready".to_vec(),
                start: PaneOutputSubscriptionStart::Now,
            })
            .command_name(),
            "sdk-wait-output"
        );
        assert_eq!(
            Request::CancelSdkWait(CancelSdkWaitRequest {
                owner_id: SdkWaitOwnerId::new(1),
                wait_id: SdkWaitId::new(1),
            })
            .command_name(),
            "cancel-sdk-wait"
        );
        assert_eq!(
            Request::WaitFor(WaitForRequest {
                channel: "ready".to_owned(),
                mode: WaitForMode::Wait,
            })
            .command_name(),
            "wait-for"
        );
    }
}