podbox_protocol/messages.rs
1use serde::{Deserialize, Serialize};
2
3/// Messages sent from guest to host.
4#[derive(Debug, Serialize, Deserialize)]
5#[serde(tag = "type", rename_all = "snake_case")]
6pub enum GuestMessage {
7 Hello {
8 protocol_version: u32,
9 guest_version: String,
10 container: String,
11 capabilities: Vec<String>,
12 },
13 Notify {
14 summary: String,
15 body: String,
16 urgency: String,
17 #[serde(default)]
18 actions: Vec<NotifyAction>,
19 #[serde(default)]
20 app_name: String,
21 },
22 XdgOpen {
23 uri: String,
24 },
25 ClipboardSet {
26 text: String,
27 },
28 ClipboardGet,
29 HostExec {
30 cmd: String,
31 args: Vec<String>,
32 },
33 /// Host-exec with the child's stdio taken from descriptors the guest
34 /// attaches to this frame (capability `host_exec_fds`).
35 ///
36 /// Exactly three descriptors ride via `SCM_RIGHTS` on the same message,
37 /// in stdin, stdout, stderr order. The host uses them directly as the
38 /// child's stdio, so binary data and large outputs never pass through
39 /// the protocol. A guest whose request is refused by this capability
40 /// keeps using [`GuestMessage::HostExec`] instead.
41 ///
42 /// The optional fields are serde-defaulted so the wire format here is
43 /// frozen now, while the host phases in behaviour behind them:
44 /// `cmd`/`args`/`env` are consumed, `cwd` is carried but not yet
45 /// processed, and `tty` must be false (the host refuses `true` with a
46 /// typed error until the TTY path exists).
47 HostExecV2 {
48 cmd: String,
49 args: Vec<String>,
50 /// Key/value pairs the guest asks the host to export to the child.
51 /// The host applies only [`crate::is_host_exec_env`] keys.
52 #[serde(default)]
53 env: Vec<(String, String)>,
54 #[serde(default)]
55 cwd: Option<String>,
56 #[serde(default)]
57 tty: bool,
58 },
59 /// Relay a signal (SIGINT, SIGTERM, SIGHUP or SIGWINCH) from the guest
60 /// shim to a running host-exec child. Only sent on a `host_exec_fds`
61 /// session: the host forwards it to the child's process group. The
62 /// child's death is reported through the regular `HostExecDone` frame.
63 HostExecSignal {
64 sig: i32,
65 },
66 /// Sent by the host CLI to register a new terminal session.
67 /// The `pidfd` follows via `SCM_RIGHTS` on the same connection.
68 RegisterSession,
69 /// Sent by the guest daemon when user processes are still running.
70 Busy,
71 /// Sent by the guest daemon when no user processes remain.
72 IdleTimeout,
73 /// Guest reply to host `GetInfo`.
74 Info {
75 guest_version: String,
76 protocol_version: u32,
77 },
78}
79
80#[derive(Debug, Serialize, Deserialize, Clone)]
81pub struct NotifyAction {
82 pub key: String,
83 pub label: String,
84}
85
86/// Which pipe of a streaming host-exec child a chunk came from.
87#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
88#[serde(rename_all = "snake_case")]
89pub enum ExecStream {
90 Stdout,
91 Stderr,
92}
93
94/// Messages sent from host to guest.
95#[derive(Debug, Serialize, Deserialize)]
96#[serde(tag = "type", rename_all = "snake_case")]
97pub enum HostMessage {
98 HelloAck {
99 accepted: Vec<String>,
100 rejected: Vec<String>,
101 #[serde(default)]
102 idle_timeout_secs: u64,
103 /// List of command names for which the guest daemon should create PATH shims.
104 #[serde(default)]
105 host_exec_shims: Vec<String>,
106 /// Version of the live host speaking this handshake, so the guest can
107 /// compare it with the version baked into the image.
108 #[serde(default)]
109 host_version: String,
110 },
111 ClipboardData {
112 text: String,
113 },
114 HostExecStdout {
115 data: String,
116 },
117 HostExecStderr {
118 data: String,
119 },
120 /// One chunk of a streaming command's output, sent as the child
121 /// produces it. `data` is raw bytes (up to 16 KiB per chunk) so binary
122 /// output survives intact. Only sent when the guest negotiated
123 /// `host_exec_stream`; older guests keep receiving the buffered
124 /// `HostExecStdout`/`HostExecStderr` frames.
125 HostExecOutput {
126 stream: ExecStream,
127 data: Vec<u8>,
128 },
129 HostExecDone {
130 exit_code: i32,
131 /// Signal that killed the child, if any. `exit_code` already
132 /// follows the shell convention (`128 + signal`); this names the
133 /// cause. Old guests ignore the unknown field.
134 #[serde(default)]
135 signal: Option<i32>,
136 },
137 NotifyActionResult {
138 notification_id: u32,
139 action_key: String,
140 },
141 Ping,
142 Shutdown,
143 /// Sent by the host when all CLI sessions have ended; guest responds
144 /// with `IdleTimeout` or `Busy` after scanning `/proc`.
145 CheckIdle,
146 /// Sent by the host when a guest message is rejected (missing `Hello`
147 /// negotiation, or a capability that was not accepted).
148 Error {
149 reason: String,
150 /// Optional machine-readable code (e.g. `busy`) so clients can
151 /// distinguish rejection kinds without parsing `reason`.
152 #[serde(default)]
153 code: Option<String>,
154 },
155 /// Host → guest version/info query (doctor).
156 GetInfo,
157}