Skip to main content

podbox_protocol/
capabilities.rs

1/// Guest protocol capability identifiers.
2///
3/// Single source of truth — always use these constants in match arms,
4/// construction, and capability negotiation rather than inline strings.
5pub const CAP_NOTIFY: &str = "notify";
6pub const CAP_XDG_OPEN: &str = "xdg_open";
7pub const CAP_CLIPBOARD: &str = "clipboard";
8pub const CAP_HOST_EXEC: &str = "host_exec";
9/// Streaming host-exec output (`HostExecOutput` byte chunks instead of one
10/// buffered `HostExecStdout`/`HostExecStderr` frame). Requested alongside
11/// `host_exec`; old hosts leave it in the rejected list and the guest falls
12/// back to buffered frames.
13pub const CAP_HOST_EXEC_STREAM: &str = "host_exec_stream";
14/// Host-exec with the child's stdio supplied by the guest: a
15/// `HostExecV2` frame with three descriptors attached via `SCM_RIGHTS`,
16/// plus `HostExecSignal` relay while the child runs. Old hosts leave it
17/// in the rejected list and the guest falls back to plain `HostExec`.
18pub const CAP_HOST_EXEC_FDS: &str = "host_exec_fds";
19
20/// All known capabilities in negotiation order.
21pub const ALL_CAPABILITIES: &[&str] = &[
22    CAP_NOTIFY,
23    CAP_XDG_OPEN,
24    CAP_CLIPBOARD,
25    CAP_HOST_EXEC,
26    CAP_HOST_EXEC_STREAM,
27    CAP_HOST_EXEC_FDS,
28];
29
30/// Host terminal variables that describe the invoking terminal.
31///
32/// These are presentation metadata, not host capabilities: they carry no
33/// socket paths or credentials. Podbox forwards them to interactive
34/// container sessions and host-exec children. Terminal control sockets
35/// (`KITTY_LISTEN_ON`, `WEZTERM_UNIX_SOCKET`) and multiplexer state (`TMUX`,
36/// `STY`) deliberately stay out.
37pub const TERMINAL_ENV_KEYS: &[&str] = &[
38    "TERM",
39    "COLORTERM",
40    "TERM_PROGRAM",
41    "TERM_PROGRAM_VERSION",
42    "TERM_SESSION_ID",
43    "VTE_VERSION",
44    "KONSOLE_VERSION",
45    "KITTY_WINDOW_ID",
46    "WEZTERM_PANE",
47    "WT_SESSION",
48    "LC_TERMINAL",
49    "LC_TERMINAL_VERSION",
50];
51
52/// Whether a guest may pass `key` through to a host-exec child.
53///
54/// The child runs on the host, so only presentation metadata and locale
55/// cross the boundary; `PATH`, `LD_PRELOAD` and host socket variables do
56/// not. Old hosts apply the narrower historical set and drop the rest,
57/// which is why extending this list needs no protocol bump.
58#[must_use]
59pub fn is_host_exec_env(key: &str) -> bool {
60    key == "LANG" || TERMINAL_ENV_KEYS.contains(&key)
61}
62
63/// Interceptor binaries and the capability each needs: `(binary, capability)`.
64///
65/// Single source of truth for shim installation and the core-interceptor
66/// guard in the guest daemon. (`podmgr-*` names are legacy aliases handled
67/// separately at the use sites.)
68pub const INTERCEPTORS: &[(&str, &str)] = &[
69    ("notify-send", CAP_NOTIFY),
70    ("xdg-open", CAP_XDG_OPEN),
71    ("podbox-clipboard", CAP_CLIPBOARD),
72    ("host-exec", CAP_HOST_EXEC),
73];