agentmux_common/api_types.rs
1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Canonical HTTP request/response DTOs shared between agentmux-srv,
5//! agentmux-mcp, and agentmux-bashwrap. Every struct here is the single
6//! source of truth for the corresponding wire shape; the three crates all
7//! import rather than redeclare these types.
8
9use serde::{Deserialize, Serialize};
10pub use crate::file_rename_types::FileRenameRequest;
11pub use crate::ui_record_types::{UiRecordRequest, UiRecordResponse};
12pub use crate::ui_screenshot_types::{ScreenshotRegion, UiScreenshotRequest, UiScreenshotResponse};
13pub use crate::agent_create_types::{ContainerAsk, CreateAgentRequest, ImportAgentRequest, RouteAsk, SpawnAgentRequest, SpawnManyRequest, SpawnWorkerSpec};
14pub use crate::browser_control_types::{
15 UiBrowserHandoffStatusRequest, UiBrowserReleaseRequest, UiBrowserRequestRequest, UiBrowserRetakeRequest,
16 UiBrowserTakeControlRequest, UiBrowserZoomRequest, UiBrowserLocateRequest,
17};
18use std::collections::HashMap;
19
20pub use crate::place_args::{PanePlaceRequest, PlaceArgs};
21
22fn is_zero(n: &usize) -> bool {
23 *n == 0
24}
25
26// ── MPS publish ───────────────────────────────────────────────────────────────
27
28/// `POST /agentmux/wps/publish` — shared client/server envelope.
29///
30/// Sent by `agentmux-bashwrap` and received by `agentmux-srv`.
31/// Mirrors `MuxEvent` but omits the server-populated `sender` field.
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct WpsPublishRequest {
34 pub event: String,
35 #[serde(default, skip_serializing_if = "Vec::is_empty")]
36 pub scopes: Vec<String>,
37 #[serde(default, skip_serializing_if = "is_zero")]
38 pub persist: usize,
39 pub data: serde_json::Value,
40}
41
42// ── Shell ─────────────────────────────────────────────────────────────────────
43
44/// `POST /api/v1/shell/create`
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct ShellCreateRequest {
47 pub agent_block_id: String,
48 pub cmd: String,
49 #[serde(default, skip_serializing_if = "Option::is_none")]
50 pub cwd: Option<String>,
51 #[serde(default, skip_serializing_if = "Option::is_none")]
52 pub title: Option<String>,
53 #[serde(default, skip_serializing_if = "Option::is_none")]
54 pub env: Option<HashMap<String, String>>,
55 /// If true, pipe the child's stdin so ShellInput() can write to it.
56 /// Default false (stdin is /dev/null) — avoids blocking programs that
57 /// read stdin to EOF (e.g. `cat` with no args).
58 #[serde(default, skip_serializing_if = "Option::is_none")]
59 pub capture_stdin: Option<bool>,
60 /// Where the command runs: `local` (the default) or `wsl://<distro>`. An
61 /// SSH destination is refused until SSH terminals ship
62 /// (SPEC_REMOTE_TERMINALS_AND_DURABLE_SESSIONS_2026_10_02.md §8).
63 #[serde(default, skip_serializing_if = "Option::is_none")]
64 pub connection: Option<String>,
65 /// The calling agent's signed identity (`UiAutomationAuth`, its own jekt
66 /// key). Required for an SSH `connection`: srv derives the agent's pane
67 /// from it and refuses a request naming another pane, so no agent can
68 /// borrow another's SSH consent.
69 #[serde(default, skip_serializing_if = "Option::is_none")]
70 pub auth: Option<UiAutomationAuth>,
71 /// Vault entries to put in the command's environment: `{ENV_NAME: entry id}`
72 /// (`id.part` for a part other than the kind's main one). srv asks the person
73 /// first and scrubs the values from the output; the agent never holds one.
74 /// Needs `auth`, and a local `connection`.
75 #[serde(default, skip_serializing_if = "Option::is_none")]
76 pub secrets: Option<HashMap<String, String>>,
77 /// One Vault entry whose value is written to the command's stdin, followed by a
78 /// newline, after which stdin is closed (`docker login --password-stdin`). Not with
79 /// `capture_stdin`. Needs `auth`, and a local `connection`.
80 #[serde(default, skip_serializing_if = "Option::is_none")]
81 pub stdin_secret: Option<String>,
82 /// Vault entries written to files only the user can read, removed when the command
83 /// ends: `{ENV_NAME: entry id}`, with the file's path in `ENV_NAME`. Needs `auth`,
84 /// and a local `connection`.
85 #[serde(default, skip_serializing_if = "Option::is_none")]
86 pub secret_files: Option<HashMap<String, String>>,
87 /// Values the command prints that go straight into the Vault: srv holds the
88 /// output until the command ends, stores each match, and publishes the output
89 /// with the values taken out (`[vault:<id>]`). If a rule matches nothing, the
90 /// output is withheld whole. Needs `auth`; works over any `connection`.
91 #[serde(default, skip_serializing_if = "Option::is_none")]
92 pub capture: Option<Vec<CaptureRule>>,
93 /// Why the command takes, or stores a value in, the Vault: one line of 8 to 300 characters, required with
94 /// `secrets`, `stdin_secret`, `secret_files` or `capture`. The person sees it in the approval ("<agent> says"),
95 /// and it is kept in the entry's history. It is the agent's own claim and decides nothing.
96 #[serde(default, skip_serializing_if = "Option::is_none")]
97 pub reason: Option<String>,
98}
99
100/// One value `Terminal` `run` takes out of a command's output into the Vault
101/// (SPEC_VAULT_GENERATE_CAPTURE_AND_BROWSER_SIGNINS_2026_10_28.md §4.2).
102#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
103pub struct CaptureRule {
104 /// The entry it goes into.
105 #[serde(rename = "as")]
106 pub into: CaptureInto,
107 /// Where in the output it is.
108 pub from: CaptureFrom,
109}
110
111/// A new entry (`kind` and `label`), or an existing one by `id`, whose value is
112/// then replaced and the old one kept 7 days. `part` defaults to the kind's main
113/// value.
114#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
115pub struct CaptureInto {
116 #[serde(default, skip_serializing_if = "Option::is_none")]
117 pub id: Option<String>,
118 #[serde(default, skip_serializing_if = "Option::is_none")]
119 pub kind: Option<String>,
120 #[serde(default, skip_serializing_if = "Option::is_none")]
121 pub label: Option<String>,
122 #[serde(default, skip_serializing_if = "Option::is_none")]
123 pub part: Option<String>,
124}
125
126/// Where a captured value is in the command's standard output.
127#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
128#[serde(rename_all = "lowercase")]
129pub enum CaptureFrom {
130 /// `"all"`: the whole output, trimmed.
131 Stdout(String),
132 /// A field of JSON output: `$.AccessKey.SecretAccessKey`, `$.items[0].token`.
133 Json(String),
134 /// A pattern with one capture group; its first match.
135 Regex(String),
136 /// One line, counted from 1, trimmed.
137 Line(u32),
138 /// A new card, made whole from several values of one output: `number`, `exp` (one text, "03/30" or
139 /// "2030-03"), `exp_month`, `exp_year`, `cvc`, `name`, `zip`, each as one of the forms above (not a `parts`
140 /// again). `number` is required. Only for `as` with `kind: "card"` and no `id`.
141 Parts(std::collections::BTreeMap<String, CaptureFrom>),
142}
143
144/// Response from `POST /api/v1/shell/create`
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct ShellCreateResponse {
147 pub shell_id: String,
148 /// The Vault entries it was given because nobody answered the person's
149 /// prompt in 30 s, so it went ahead: the agent is told so.
150 #[serde(default, skip_serializing_if = "Option::is_none")]
151 pub approval: Option<String>,
152}
153
154/// `POST /api/v1/shell/stop`
155#[derive(Debug, Clone, Serialize, Deserialize)]
156pub struct ShellStopRequest {
157 pub shell_id: String,
158}
159
160/// Response from `POST /api/v1/shell/stop`
161#[derive(Debug, Clone, Serialize, Deserialize)]
162pub struct ShellStopResponse {
163 pub stopped: bool,
164}
165
166/// `POST /api/v1/shell/input` — write text to a running shell's stdin.
167#[derive(Debug, Clone, Serialize, Deserialize)]
168pub struct ShellInputRequest {
169 pub shell_id: String,
170 /// Text to write. A newline is appended automatically so single answers
171 /// like "y" work without the caller knowing the line discipline.
172 pub text: String,
173}
174
175/// Response from `POST /api/v1/shell/input`
176#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct ShellInputResponse {
178 /// false if the shell is not running, has no captured stdin, or the write failed.
179 pub written: bool,
180 /// Why the write did not happen (None when `written` is true). Lets callers
181 /// distinguish "shell exited" from "shell is running but was created without
182 /// capture_stdin=true", which are otherwise indistinguishable from `written`.
183 #[serde(default, skip_serializing_if = "Option::is_none")]
184 pub reason: Option<ShellInputFailure>,
185}
186
187/// Reason a `ShellInput` write did not happen.
188#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
189#[serde(rename_all = "snake_case")]
190pub enum ShellInputFailure {
191 /// The shell id is unknown or the process has already exited.
192 NotRunning,
193 /// The shell is running but was created without `capture_stdin=true`, so its
194 /// stdin is `/dev/null` — recreate it with capture_stdin to send input.
195 StdinNotCaptured,
196 /// The stdin relay is gone / the write channel is closed (process closed stdin).
197 WriteFailed,
198}
199
200/// `POST /api/v1/shell/status` — query whether a shell is still running.
201#[derive(Debug, Clone, Serialize, Deserialize)]
202pub struct ShellStatusRequest {
203 pub shell_id: String,
204}
205
206/// Response from `POST /api/v1/shell/status`
207#[derive(Debug, Clone, Serialize, Deserialize)]
208pub struct ShellStatusResponse {
209 pub running: bool,
210 #[serde(skip_serializing_if = "Option::is_none")]
211 pub exit_code: Option<i32>,
212 pub line_count: u64,
213}
214
215/// `POST /api/v1/shell/output` - the cleaned output of a job that was given Vault
216/// secrets (`ShellCreateRequest.secrets`). Only such a job keeps its output, and
217/// only the agent whose pane started it may read it: the request carries the
218/// agent's signed identity, and srv derives the pane from that, never from a
219/// field the caller fills in (every agent holds the instance auth key).
220#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct ShellOutputRequest {
222 pub shell_id: String,
223 pub auth: UiAutomationAuth,
224}
225
226/// Response from `POST /api/v1/shell/output`
227#[derive(Debug, Clone, Serialize, Deserialize)]
228pub struct ShellOutputResponse {
229 pub running: bool,
230 #[serde(skip_serializing_if = "Option::is_none")]
231 pub exit_code: Option<i32>,
232 /// The last lines the job wrote, with every Vault value taken out.
233 pub output: String,
234 /// Older lines were left out, or a line was cut short.
235 pub truncated: bool,
236 /// The entries `capture` stored, in the order of its rules, once the job ended.
237 #[serde(default, skip_serializing_if = "Vec::is_empty")]
238 pub captured: Vec<String>,
239 /// Why `capture` failed, and so why the output is withheld.
240 #[serde(default, skip_serializing_if = "Option::is_none")]
241 pub withheld: Option<String>,
242}
243
244// ── PTY Shell ─────────────────────────────────────────────────────────────────
245//
246// A REAL PTY-backed shell (not the piped subprocess `Shell` above) — for
247// driving genuinely interactive programs that check for a real terminal
248// (Sharprompt-style wizards, `sudo`, `ssh`, REPLs). Reuses the same backend
249// `blockcontroller::shell` already uses for the `term` widget and
250// `AgentShellSubblock.tsx`; this is a new agent-facing entry point onto
251// existing PTY plumbing, not a new implementation. See
252// docs/specs/SPEC_AGENT_INTERACTIVE_PTY_SHELL_API_2026_09_10.md.
253//
254// Deliberately NOT UI-driven: every one of these is a plain backend RPC
255// (agent -> agentmux-mcp -> agentmux-srv), with no dependency on any window
256// being open, focused, or even rendering the shell's `term` sub-block — the
257// same posture the existing `Shell`/`ShellInput` family already has.
258//
259// `create` attaches to (creating if needed) the SAME shell a human's
260// composer-drawer session uses, not an independent, invisible one —
261// whichever side gets there first, the other joins. While the agent is
262// actively writing (`input`/`resize`), the human's own keyboard input to
263// that shell is locked out, for a short, self-expiring window
264// (`AGENT_LOCK_WINDOW_MS`) rather than an explicit lock/unlock the agent
265// could fail to release — "bound to the shell only when necessary," per
266// the repo owner's own framing of the requirement.
267
268/// `POST /api/v1/ptyshell/create`
269#[derive(Debug, Clone, Serialize, Deserialize)]
270pub struct PtyShellCreateRequest {
271 pub agent_block_id: String,
272 #[serde(default, skip_serializing_if = "Option::is_none")]
273 pub cwd: Option<String>,
274 #[serde(default, skip_serializing_if = "Option::is_none")]
275 pub rows: Option<u16>,
276 #[serde(default, skip_serializing_if = "Option::is_none")]
277 pub cols: Option<u16>,
278 /// Where the shell runs: `local` (the default) or `wsl://<distro>`. An
279 /// SSH destination is refused until SSH terminals ship
280 /// (SPEC_REMOTE_TERMINALS_AND_DURABLE_SESSIONS_2026_10_02.md §8).
281 #[serde(default, skip_serializing_if = "Option::is_none")]
282 pub connection: Option<String>,
283 /// The calling agent's signed identity (`UiAutomationAuth`, its own jekt
284 /// key). Required for an SSH `connection`: srv derives the agent's pane
285 /// from it and refuses a request naming another pane, so no agent can
286 /// borrow another's SSH consent.
287 #[serde(default, skip_serializing_if = "Option::is_none")]
288 pub auth: Option<UiAutomationAuth>,
289}
290
291/// Response from `POST /api/v1/ptyshell/create`. `shell_id` is the new
292/// sub-block's id — the same value every other `PtyShell*` call takes.
293#[derive(Debug, Clone, Serialize, Deserialize)]
294pub struct PtyShellCreateResponse {
295 pub shell_id: String,
296}
297
298/// `POST /api/v1/ptyshell/input` — write raw text to the PTY, as if typed.
299///
300/// `agent_block_id` is filled in by `agentmux-mcp` from its own trusted
301/// env (`AGENTMUX_AGENT_BUS_ID`/`AGENTMUX_BLOCKID`), never a model-facing
302/// tool parameter — same non-forgeable guarantee `agent_slug()` documents.
303/// It's what lets the backend verify `shell_id` is actually a sub-block of
304/// THIS caller's own pane before acting on it (see
305/// `is_owned_by_agent` in `agentmux-srv`).
306#[derive(Debug, Clone, Serialize, Deserialize)]
307pub struct PtyShellInputRequest {
308 pub shell_id: String,
309 pub agent_block_id: String,
310 pub text: String,
311}
312
313/// Response from `POST /api/v1/ptyshell/input`
314#[derive(Debug, Clone, Serialize, Deserialize)]
315pub struct PtyShellInputResponse {
316 pub written: bool,
317 #[serde(default, skip_serializing_if = "Option::is_none")]
318 pub error: Option<String>,
319}
320
321/// `POST /api/v1/ptyshell/resize` — resize the PTY. Some TUIs render
322/// differently or wrap badly at the fallback geometry (25x200).
323#[derive(Debug, Clone, Serialize, Deserialize)]
324pub struct PtyShellResizeRequest {
325 pub shell_id: String,
326 pub agent_block_id: String,
327 pub rows: u16,
328 pub cols: u16,
329}
330
331/// Response from `POST /api/v1/ptyshell/resize`
332#[derive(Debug, Clone, Serialize, Deserialize)]
333pub struct PtyShellResizeResponse {
334 pub resized: bool,
335 #[serde(default, skip_serializing_if = "Option::is_none")]
336 pub error: Option<String>,
337}
338
339/// `POST /api/v1/ptyshell/read` — read back the shell's raw output tail.
340///
341/// This is a raw byte/line log, not a rendered-screen snapshot — a
342/// full-screen TUI that redraws in place (cursor movement, `\r`-only
343/// updates) will not read back the way it visually renders. Sufficient for
344/// line-oriented wizards (the common case); see the spec's §5 for the
345/// rendered-snapshot follow-up this deliberately does not attempt yet.
346#[derive(Debug, Clone, Serialize, Deserialize)]
347pub struct PtyShellReadRequest {
348 pub shell_id: String,
349 pub agent_block_id: String,
350 /// Number of trailing lines to return. Defaults to 200.
351 #[serde(default, skip_serializing_if = "Option::is_none")]
352 pub tail_lines: Option<u32>,
353 /// Only output from this byte offset on (a previous response's `end`), so
354 /// a caller reads just what is new. Absent: from the start of the log.
355 #[serde(default, skip_serializing_if = "Option::is_none")]
356 pub since: Option<u64>,
357}
358
359/// Response from `POST /api/v1/ptyshell/read`
360#[derive(Debug, Clone, Serialize, Deserialize)]
361pub struct PtyShellReadResponse {
362 pub content: String,
363 /// True if the shell's output has more lines than `tail_lines` returned.
364 pub truncated: bool,
365 /// The log's length in bytes when read: pass it back as `since`.
366 #[serde(default)]
367 pub end: u64,
368}
369
370/// `POST /api/v1/ptyshell/status` — query whether the shell is still running.
371#[derive(Debug, Clone, Serialize, Deserialize)]
372pub struct PtyShellStatusRequest {
373 pub shell_id: String,
374 pub agent_block_id: String,
375}
376
377/// Response from `POST /api/v1/ptyshell/status`
378#[derive(Debug, Clone, Serialize, Deserialize)]
379pub struct PtyShellStatusResponse {
380 /// False both for "still initializing" and "exited" — callers that need
381 /// to distinguish those should check `exit_code` (`None` for the former).
382 pub running: bool,
383 #[serde(default, skip_serializing_if = "Option::is_none")]
384 pub exit_code: Option<i32>,
385}
386
387/// `POST /api/v1/ptyshell/stop` — release the agent's lock on the shell
388/// *now*, without waiting for `AGENT_LOCK_WINDOW_MS` to lapse.
389///
390/// Does **not** kill the process or delete the block. The shell this API
391/// drives is, by default, the same one a human's composer-drawer session
392/// uses (see `META_KEY_SHELL_SUBBLOCK_ID`) — it's a shared, pane-scoped
393/// resource with the pane's own lifetime ("only killed when the pane
394/// closes," `AgentShellSubblock.tsx`'s own doc comment), not a private,
395/// disposable one this tool owns outright. An earlier version of this API
396/// (PR #3177) did delete on stop, which was correct for that version's
397/// model (an agent's own throwaway shell) but would destroy a human's live
398/// terminal session under this one.
399#[derive(Debug, Clone, Serialize, Deserialize)]
400pub struct PtyShellStopRequest {
401 pub shell_id: String,
402 pub agent_block_id: String,
403}
404
405/// Response from `POST /api/v1/ptyshell/stop`
406#[derive(Debug, Clone, Serialize, Deserialize)]
407pub struct PtyShellStopResponse {
408 /// False if the id was unrecognized, wasn't owned by the caller, or
409 /// simply had no active lock to release.
410 pub released: bool,
411}
412
413// ── Inject (Message + Schedule) ───────────────────────────────────────────────
414
415/// `POST /agentmux/reactive/inject` — deliver a message to an agent.
416///
417/// Used by the `Message` and `Schedule` MCP tools.
418#[derive(Debug, Clone, Default, Serialize, Deserialize)]
419pub struct InjectRequest {
420 pub target_agent: String,
421 pub message: String,
422 #[serde(default, skip_serializing_if = "Option::is_none")]
423 pub source_agent: Option<String>,
424 /// Message id this jekt was signed under — required for `jekt_sig` to be
425 /// verifiable (the signed material binds msgid, sender, target, and
426 /// timestamp together). `None` when unsigned (e.g. `AGENTMUX_JEKT_KEY`
427 /// wasn't available — legacy/unverified, same as omitting `jekt_sig`).
428 #[serde(default, skip_serializing_if = "Option::is_none")]
429 pub request_id: Option<String>,
430 /// Unix seconds this jekt was signed at — part of the signed material,
431 /// not just a display timestamp. See `agentmux_common::jekt_sign`.
432 #[serde(default, skip_serializing_if = "Option::is_none")]
433 pub ts_secs: Option<i64>,
434 /// Base64 HMAC-SHA256 over (msgid, source_agent, target_agent, ts_secs,
435 /// message), signed with the sender's own `AGENTMUX_JEKT_KEY`. Absent
436 /// when the sending agent has no key yet (first-ever send before one is
437 /// provisioned) — srv treats an absent/invalid signature as unverified,
438 /// not as an error, and downgrades trust accordingly rather than
439 /// rejecting the message outright.
440 #[serde(default, skip_serializing_if = "Option::is_none")]
441 pub jekt_sig: Option<String>,
442 /// Base64 Ed25519 signature over the same signed material as `jekt_sig`,
443 /// produced with the sender's own `AGENTMUX_LAN_KEY`
444 /// (SPEC_JEKT_LAN_TIER_SIGNING_2026_08_15.md §2.3). Sent unconditionally
445 /// alongside `jekt_sig` regardless of the message's actual destination
446 /// — this process can't know in advance whether delivery will end up
447 /// LAN, host, or WAN (that's a server-side routing decision); srv only
448 /// ever consults this field when it has independently determined
449 /// `delivery_tier == "lan"`, so it's simply ignored otherwise. Absent
450 /// under the same "no key yet" conditions as `jekt_sig`.
451 #[serde(default, skip_serializing_if = "Option::is_none")]
452 pub lan_sig: Option<String>,
453 /// The sending instance's channel id (`AGENTMUX_CHANNEL`, injected into
454 /// the MCP env at spawn alongside the keys). Bound into `channel_sig`'s
455 /// signed material (SPEC_JEKT_CROSS_CHANNEL_TRUST_2026_09_02.md §D5) so
456 /// a signature minted in one channel can't be replayed as the same agent
457 /// speaking from another. Absent whenever `channel_sig` is.
458 #[serde(default, skip_serializing_if = "Option::is_none")]
459 pub source_channel: Option<String>,
460 /// Base64 Ed25519 signature for the same-machine, different-instance
461 /// (cross-channel) tier, produced with the sender's own `AGENTMUX_LAN_KEY`
462 /// over a domain-separated payload that also binds `source_channel`
463 /// (`agentmux_common::jekt_sign::sign_channel_jekt`). Sent unconditionally
464 /// for the same reason `lan_sig` is: srv only consults it once it has
465 /// itself labelled the delivery `channel`. Absent under the same "no key
466 /// yet" conditions as `lan_sig`.
467 #[serde(default, skip_serializing_if = "Option::is_none")]
468 pub channel_sig: Option<String>,
469 /// Identity M4d-6 (`SPEC_AGENT_IDENTITY_CARRIED_NOT_DERIVED_2026_09_23.md`
470 /// §6.5.10): the sending agent's UID, as its MCP fetched it with its
471 /// UID-keyed key (M4d-3). Bound into `channel_sig_v2`; a forwarding srv
472 /// never sets or changes it. Absent when the sender has no UID key.
473 #[serde(default, skip_serializing_if = "Option::is_none")]
474 pub source_uid: Option<String>,
475 /// Base64 Ed25519 signature, made only with the sender's UID-keyed LAN
476 /// key, over the cross-channel material plus `source_uid`
477 /// (`agentmux_common::jekt_sign::sign_channel_jekt_v2`). Verified by UID
478 /// against the `uid_public_key` an instance published for it (M4d-5), so
479 /// it proves *which* agent sent the jekt, not just which name. The v1
480 /// `channel_sig` is still sent beside it.
481 #[serde(default, skip_serializing_if = "Option::is_none")]
482 pub channel_sig_v2: Option<String>,
483 /// Identity M4d-6: base64 Ed25519 signature, made only with the sender's
484 /// UID-keyed LAN key, over the LAN material plus `source_uid`
485 /// (`agentmux_common::jekt_sign::sign_lan_jekt_v2`). A receiver checks it
486 /// only after the v1 `lan_sig` verified, and records the UID as claimed by
487 /// that LAN path, never as verified attribution.
488 #[serde(default, skip_serializing_if = "Option::is_none")]
489 pub lan_sig_v2: Option<String>,
490 // No WAN signature: srv signs a WAN jekt itself, at the origin, for the
491 // agent its token names (docs/specs/SPEC_WAN_JEKT_SIGNED_BY_SRV_2026_10_14.md).
492 /// Files sent with this jekt, already in the sender's attachment store.
493 /// `request_id` ends in their manifest digest, which binds them to every
494 /// signature (`agentmux_common::jekt_files`). Absent on a text-only jekt.
495 #[serde(default, skip_serializing_if = "Option::is_none")]
496 pub files: Option<Vec<crate::jekt_files::JektFile>>,
497 /// `urgent` when the sender wants it delivered now even to a session that
498 /// has been idle (`Message` `urgent: true`); absent otherwise. Not part of
499 /// any signature: it only skips a wait.
500 #[serde(default, skip_serializing_if = "Option::is_none")]
501 pub priority: Option<String>,
502 /// `none` when the sender asks for no reply (`Message` `reply: "none"`): the receiver's
503 /// marker says `REPLY=none`, and srv refuses a reply to it. Not part of any signature.
504 #[serde(default, skip_serializing_if = "Option::is_none")]
505 pub reply: Option<String>,
506 /// The MSGID of the message this one answers (`Message` `in_reply_to`), so srv can refuse
507 /// an answer to a message that asked for none. Not part of any signature.
508 #[serde(default, skip_serializing_if = "Option::is_none")]
509 pub in_reply_to: Option<String>,
510}
511
512// ── Pane ──────────────────────────────────────────────────────────────────────
513
514/// `POST /api/v1/pane/open` — open a new pane.
515///
516/// Structurally equivalent to `rpc_types::CommandPaneOpenData` (same wire
517/// fields) so the two are interchangeable on the wire; srv deserializes into
518/// `CommandPaneOpenData`, mcp serializes from this type.
519#[derive(Debug, Clone, Serialize, Deserialize)]
520pub struct PaneOpenRequest {
521 pub view: String,
522 #[serde(default, skip_serializing_if = "Option::is_none")]
523 pub file: Option<String>,
524 #[serde(default, skip_serializing_if = "Option::is_none")]
525 pub url: Option<String>,
526 #[serde(default, skip_serializing_if = "Option::is_none")]
527 pub cwd: Option<String>,
528 #[serde(default, skip_serializing_if = "Option::is_none")]
529 pub title: Option<String>,
530 #[serde(default, skip_serializing_if = "Option::is_none")]
531 pub tab_id: Option<String>,
532 #[serde(default, skip_serializing_if = "Option::is_none")]
533 pub split_direction: Option<String>,
534 #[serde(default, skip_serializing_if = "Option::is_none")]
535 pub split_reference_block_id: Option<String>,
536 #[serde(default, skip_serializing_if = "Option::is_none")]
537 pub focus: Option<bool>,
538 #[serde(default, skip_serializing_if = "Option::is_none")]
539 pub tree_expanded: Option<bool>,
540 #[serde(default, skip_serializing_if = "Option::is_none")]
541 pub floating: Option<bool>,
542 /// `Some(true)`, `view: "editor"` only: explicit opt-in to reuse an
543 /// already-open Editor pane in the caller's own tab (identified via
544 /// `split_reference_block_id`) instead of always creating a new one.
545 /// Set only by the `OpenEditor` MCP tool — NOT inferred from other
546 /// fields, since other legitimate `pane.open` callers also set
547 /// `split_reference_block_id` for split placement without wanting
548 /// reuse (`EditorViewModel.openToTheSide`/`openInTerminal`).
549 #[serde(default, skip_serializing_if = "Option::is_none")]
550 pub reuse_editor_pane: Option<bool>,
551 /// `view: "editor"` only: the Editor pane (block_id) to put `file` in.
552 #[serde(default, skip_serializing_if = "Option::is_none")]
553 pub target_block_id: Option<String>,
554 /// `view: "editor"` only: an image or video tab follows newer matching
555 /// files in its folder. Set by the `OpenMedia` alias (`Pane` open, view `media`).
556 #[serde(default, skip_serializing_if = "Option::is_none")]
557 pub follow_folder: Option<bool>,
558 /// `view: "editor"` only: the viewer to open `file` in (`text`, `image`, `media`, `pdf`, `hex`, `info`), and where
559 /// in it: a text `line` (1-based), a hex byte `offset`, a PDF `page` (1-based).
560 #[serde(default, skip_serializing_if = "Option::is_none")]
561 pub viewer: Option<String>,
562 #[serde(default, skip_serializing_if = "Option::is_none")]
563 pub line: Option<u32>,
564 #[serde(default, skip_serializing_if = "Option::is_none")]
565 pub offset: Option<u64>,
566 #[serde(default, skip_serializing_if = "Option::is_none")]
567 pub page: Option<u32>,
568 /// `view: "files"` only: names (or full paths) inside `file` to select
569 /// once the Files pane has listed it. Set by the `OpenFiles` MCP tool.
570 #[serde(default, skip_serializing_if = "Option::is_none")]
571 pub select: Option<Vec<String>>,
572 /// The connection the pane works on (an SSH host, `wsl://<distro>`);
573 /// absent for this computer. An SSH host needs `auth`.
574 #[serde(default, skip_serializing_if = "Option::is_none")]
575 pub connection: Option<String>,
576 /// The calling agent's signed identity, for an SSH `connection`.
577 #[serde(default, skip_serializing_if = "Option::is_none")]
578 pub auth: Option<UiAutomationAuth>,
579 /// With `floating`: the window's size and place.
580 #[serde(flatten)]
581 pub place: PlaceArgs,
582}
583
584/// Response from `POST /api/v1/pane/open`
585#[derive(Debug, Clone, Serialize, Deserialize)]
586pub struct PaneOpenResponse {
587 pub block_id: String,
588 /// A floating open: where its window went (`x`, `y`, `width`, `height`, `spot`, `clamped`, `display_scale`).
589 #[serde(default, skip_serializing_if = "Option::is_none")]
590 pub placed: Option<serde_json::Value>,
591 /// A floating open whose window had not answered yet: the pane is made and takes its place when its window opens.
592 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
593 pub queued: bool,
594 /// Something the agent should know about the pane (a container agent's file is a snapshot).
595 #[serde(default, skip_serializing_if = "Option::is_none")]
596 pub note: Option<String>,
597}
598
599/// `POST /api/v1/pane/title` — set a pane's display title.
600#[derive(Debug, Clone, Serialize, Deserialize)]
601pub struct PaneTitleRequest {
602 #[serde(default, skip_serializing_if = "Option::is_none")]
603 pub block_id: Option<String>,
604 pub title: String,
605}
606
607// ── Tab ───────────────────────────────────────────────────────────────────────
608
609/// `POST /api/v1/tab/activate` — switch the active tab.
610#[derive(Debug, Clone, Serialize, Deserialize)]
611pub struct TabActivateRequest {
612 pub tab_id: String,
613}
614
615/// `POST /api/v1/tab/new` — create a new tab in a workspace.
616#[derive(Debug, Clone, Serialize, Deserialize)]
617pub struct TabNewRequest {
618 #[serde(default, skip_serializing_if = "Option::is_none")]
619 pub block_id: Option<String>,
620 #[serde(default, skip_serializing_if = "Option::is_none")]
621 pub workspace_id: Option<String>,
622 #[serde(default, skip_serializing_if = "Option::is_none")]
623 pub name: Option<String>,
624}
625
626/// `POST /api/v1/tab/name` — rename a tab.
627#[derive(Debug, Clone, Serialize, Deserialize)]
628pub struct TabNameRequest {
629 #[serde(default, skip_serializing_if = "Option::is_none")]
630 pub block_id: Option<String>,
631 #[serde(default, skip_serializing_if = "Option::is_none")]
632 pub tab_id: Option<String>,
633 pub name: String,
634}
635
636// ── Window ────────────────────────────────────────────────────────────────────
637
638/// `POST /api/v1/window/focus` — bring a window to the foreground.
639#[derive(Debug, Clone, Serialize, Deserialize)]
640pub struct WindowFocusRequest {
641 #[serde(default, skip_serializing_if = "Option::is_none")]
642 pub block_id: Option<String>,
643 #[serde(default, skip_serializing_if = "Option::is_none")]
644 pub window_id: Option<String>,
645}
646
647/// `POST /api/v1/window/name` — set a window's display name.
648#[derive(Debug, Clone, Serialize, Deserialize)]
649pub struct WindowNameRequest {
650 #[serde(default, skip_serializing_if = "Option::is_none")]
651 pub block_id: Option<String>,
652 pub name: String,
653 #[serde(default, skip_serializing_if = "Option::is_none")]
654 pub window_id: Option<String>,
655}
656
657// ── Workspace ─────────────────────────────────────────────────────────────────
658
659/// `POST /api/v1/workspace/name` — rename a workspace.
660#[derive(Debug, Clone, Serialize, Deserialize)]
661pub struct WorkspaceNameRequest {
662 #[serde(default, skip_serializing_if = "Option::is_none")]
663 pub block_id: Option<String>,
664 #[serde(default, skip_serializing_if = "Option::is_none")]
665 pub workspace_id: Option<String>,
666 pub name: String,
667}
668
669// ── UI automation ───────────────────────────────────────────────────────────
670//
671// `block_id` is NOT a field on any of these requests, on purpose (2026-08-19,
672// reagent + Codex review, PR #2662 — a client-supplied `block_id` here was a
673// real cross-agent content-disclosure vulnerability: /api/v1/ui/* shares the
674// same instance-wide X-AuthKey every App-API route trusts, and any agent can
675// read that key from its own environment, so a bare `block_id` field could
676// never be trusted from the request body no matter which layer stamped it).
677//
678// Instead, every request here carries `UiAutomationAuth`: the calling
679// agent's own slug, a timestamp, and an HMAC-SHA256 signature over them
680// using that agent's own `AGENTMUX_JEKT_KEY` (the SAME per-agent signing key
681// already used for jekt sender authentication — reused rather than inventing
682// a parallel credential system; see `agentmux_common::jekt_sign`). srv
683// verifies the signature against the claimed agent_id's key on file
684// (`Store::agent_jekt_key_load`) and, ONLY once that succeeds, looks up that
685// agent's actual current block_id server-side (`ReactiveHandler::get_agent`)
686// — the block_id a UI-automation call actually operates on is never taken
687// from the client at all, so there is nothing left to spoof. See
688// `crates/srv/src/server/ui_handlers.rs::verified_block_id` and
689// docs/specs/SPEC_AGENT_UI_AUTOMATION_CLICK_SCREENSHOT_2026_08_18.md.
690
691/// Identity proof shared by every `/api/v1/ui/*` request. `sig` is
692/// `jekt_sign::sign_jekt(key, "ui-automation-identity", agent_id,
693/// "__srv__", ts_secs, "")` — the fixed msgid/target_agent/message values
694/// exist purely for domain separation from real jekt message signatures
695/// (no genuine jekt uses this literal msgid, and "__srv__" is not a
696/// spawnable agent name), not because those fields carry meaning here.
697#[derive(Debug, Clone, Serialize, Deserialize)]
698pub struct UiAutomationAuth {
699 pub agent_id: String,
700 pub ts_secs: i64,
701 pub sig: String,
702}
703
704/// `POST /api/v1/ui/click`
705#[derive(Debug, Clone, Serialize, Deserialize)]
706pub struct UiClickRequest {
707 #[serde(flatten)]
708 pub auth: UiAutomationAuth,
709 /// Target a browser pane this agent opened with `OpenBrowser`
710 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
711 /// against its owner map; absent = the caller's own pane, as before.
712 #[serde(default, skip_serializing_if = "Option::is_none")]
713 pub pane: Option<String>,
714 pub selector: String,
715}
716
717/// `POST /api/v1/ui/query`
718#[derive(Debug, Clone, Serialize, Deserialize)]
719pub struct UiQueryRequest {
720 #[serde(flatten)]
721 pub auth: UiAutomationAuth,
722 /// Target a browser pane this agent opened with `OpenBrowser`
723 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
724 /// against its owner map; absent = the caller's own pane, as before.
725 #[serde(default, skip_serializing_if = "Option::is_none")]
726 pub pane: Option<String>,
727 pub selector: String,
728 #[serde(default, skip_serializing_if = "Option::is_none")]
729 pub limit: Option<u32>,
730}
731
732// ── Shortcuts (ListShortcuts/RunCommand/PressKeys) ────────────────────────
733// docs/specs/PLAN_SHORTCUTS_VERIFIED_AND_APP_API_2026_10_10.md §4. They act
734// in the window that holds the caller's own pane (owner decision §8.1), so
735// there is no `pane` field; `target` is a pane in that window's active tab.
736
737/// `POST /api/v1/ui/shortcuts/list`
738#[derive(Debug, Clone, Serialize, Deserialize)]
739pub struct UiShortcutsListRequest {
740 #[serde(flatten)]
741 pub auth: UiAutomationAuth,
742}
743
744/// `POST /api/v1/ui/shortcuts/run`
745#[derive(Debug, Clone, Serialize, Deserialize)]
746pub struct UiRunCommandRequest {
747 #[serde(flatten)]
748 pub auth: UiAutomationAuth,
749 /// A command id from `ListShortcuts` (`split:right`, `files:refresh`).
750 pub command: String,
751 /// Your own pane, or a browser pane you opened, to focus first; absent = your own pane.
752 #[serde(default, skip_serializing_if = "Option::is_none")]
753 pub target: Option<String>,
754}
755
756/// `POST /api/v1/ui/shortcuts/press`
757#[derive(Debug, Clone, Serialize, Deserialize)]
758pub struct UiPressKeysRequest {
759 #[serde(flatten)]
760 pub auth: UiAutomationAuth,
761 /// A key from `ListShortcuts`' `raw` list, in the table's syntax
762 /// (`ctrl+shift+d`; a chord is two keys separated by a space).
763 pub keys: String,
764 /// Your own pane, or a browser pane you opened, to focus first; absent = your own pane.
765 #[serde(default, skip_serializing_if = "Option::is_none")]
766 pub target: Option<String>,
767}
768
769/// `POST /api/v1/ui/shortcuts/set` — gives one command exactly these keys (docs/specs/SPEC_KEYBOARD_SHORTCUTS_SETTINGS_2026_11_06.md §10).
770#[derive(Debug, Clone, Serialize, Deserialize)]
771pub struct UiSetShortcutRequest {
772 #[serde(flatten)]
773 pub auth: UiAutomationAuth,
774 /// A command id from `ListShortcuts`.
775 pub command: String,
776 /// The keys the command ends with, in the table's syntax (`ctrl+shift+d`; a chord is two keys separated by a
777 /// space). Empty unbinds the command.
778 #[serde(default)]
779 pub bindings: Vec<String>,
780 /// Where they work (`!textInputFocus`, `viewType == editor`); absent = where the command works today.
781 #[serde(default, skip_serializing_if = "Option::is_none")]
782 pub when: Option<String>,
783}
784
785/// `POST /api/v1/ui/shortcuts/reset` — puts one command, or every command, back on its defaults.
786#[derive(Debug, Clone, Serialize, Deserialize)]
787pub struct UiResetShortcutsRequest {
788 #[serde(flatten)]
789 pub auth: UiAutomationAuth,
790 /// A command id from `ListShortcuts`.
791 #[serde(default, skip_serializing_if = "Option::is_none")]
792 pub command: Option<String>,
793 /// Every command, instead of one.
794 #[serde(default)]
795 pub all: bool,
796}
797
798// ── Browser-pane deep control (Navigate/Back/Forward/Reload/Eval/
799// DispatchKey/FocusElement/FocusInfo) ─────────────────────────────────
800//
801// Same `UiAutomationAuth`-derived own-pane scoping as the UI-automation
802// section above (block_id is never a client field, always server-derived
803// via `verified_block_id`). Additionally, `Navigate`/`Back`/`Forward`/
804// `Reload`/`Eval` only succeed when the caller's own pane resolves to a
805// DEDICATED browser-pane CDP target (not a DOM node inside a page shared
806// with other panes / the app's own chrome) — enforced host-side by
807// `crates/cef/src/browser_api/routes.rs::reject_if_shared_target`.
808// See docs/specs/SPEC_AGENT_BROWSER_PANE_DEEP_CONTROL_2026_09_20.md.
809
810/// `POST /api/v1/ui/browser/navigate`
811#[derive(Debug, Clone, Serialize, Deserialize)]
812pub struct UiBrowserNavigateRequest {
813 #[serde(flatten)]
814 pub auth: UiAutomationAuth,
815 /// Target a browser pane this agent opened with `OpenBrowser`
816 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
817 /// against its owner map; absent = the caller's own pane, as before.
818 #[serde(default, skip_serializing_if = "Option::is_none")]
819 pub pane: Option<String>,
820 pub url: String,
821}
822
823/// `POST /api/v1/ui/browser/back`, `/forward`, `/reload` — all three only
824/// need the target block id; `ignore_cache` is meaningful for `/reload`
825/// only (ignored by back/forward, mirrors `browser_api::types::HistoryReq`).
826#[derive(Debug, Clone, Serialize, Deserialize)]
827pub struct UiBrowserHistoryRequest {
828 #[serde(flatten)]
829 pub auth: UiAutomationAuth,
830 /// Target a browser pane this agent opened with `OpenBrowser`
831 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
832 /// against its owner map; absent = the caller's own pane, as before.
833 #[serde(default, skip_serializing_if = "Option::is_none")]
834 pub pane: Option<String>,
835 #[serde(default, skip_serializing_if = "Option::is_none")]
836 pub ignore_cache: Option<bool>,
837}
838
839/// `POST /api/v1/ui/browser/eval`
840#[derive(Debug, Clone, Serialize, Deserialize)]
841pub struct UiBrowserEvalRequest {
842 #[serde(flatten)]
843 pub auth: UiAutomationAuth,
844 /// Target a browser pane this agent opened with `OpenBrowser`
845 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
846 /// against its owner map; absent = the caller's own pane, as before.
847 #[serde(default, skip_serializing_if = "Option::is_none")]
848 pub pane: Option<String>,
849 pub script: String,
850 /// If true and the script returns a Promise, wait for it to resolve
851 /// before returning.
852 #[serde(default, skip_serializing_if = "Option::is_none")]
853 pub await_promise: Option<bool>,
854}
855
856/// `POST /api/v1/ui/browser/dispatch_key`
857#[derive(Debug, Clone, Serialize, Deserialize)]
858pub struct UiBrowserDispatchKeyRequest {
859 #[serde(flatten)]
860 pub auth: UiAutomationAuth,
861 /// Target a browser pane this agent opened with `OpenBrowser`
862 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
863 /// against its owner map; absent = the caller's own pane, as before.
864 #[serde(default, skip_serializing_if = "Option::is_none")]
865 pub pane: Option<String>,
866 /// Optional CSS selector: focus this element before dispatching.
867 #[serde(default, skip_serializing_if = "Option::is_none")]
868 pub selector: Option<String>,
869 /// Exactly one of `text`/`key` must be set. Sent via `Input.insertText`.
870 #[serde(default, skip_serializing_if = "Option::is_none")]
871 pub text: Option<String>,
872 /// Named key (`Enter`, `Tab`, `Escape`, `Backspace`, arrow keys,
873 /// `Space`) sent as a `keyDown`+`keyUp` pair.
874 #[serde(default, skip_serializing_if = "Option::is_none")]
875 pub key: Option<String>,
876}
877
878/// `POST /api/v1/ui/browser/focus_element`
879#[derive(Debug, Clone, Serialize, Deserialize)]
880pub struct UiBrowserFocusElementRequest {
881 #[serde(flatten)]
882 pub auth: UiAutomationAuth,
883 /// Target a browser pane this agent opened with `OpenBrowser`
884 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
885 /// against its owner map; absent = the caller's own pane, as before.
886 #[serde(default, skip_serializing_if = "Option::is_none")]
887 pub pane: Option<String>,
888 pub selector: String,
889}
890
891/// `POST /api/v1/ui/browser/focus_info`
892#[derive(Debug, Clone, Serialize, Deserialize)]
893pub struct UiBrowserFocusInfoRequest {
894 #[serde(flatten)]
895 pub auth: UiAutomationAuth,
896 /// Target a browser pane this agent opened with `OpenBrowser`
897 /// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3). srv checks it
898 /// against its owner map; absent = the caller's own pane, as before.
899 #[serde(default, skip_serializing_if = "Option::is_none")]
900 pub pane: Option<String>,
901}
902
903/// `POST /api/v1/ui/browser/snapshot` — backs `BrowserSnapshot`
904/// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §4.1).
905#[derive(Debug, Clone, Serialize, Deserialize)]
906pub struct UiBrowserSnapshotRequest {
907 #[serde(flatten)]
908 pub auth: UiAutomationAuth,
909 /// Target a browser pane this agent opened with `OpenBrowser`; absent =
910 /// the caller's own pane.
911 #[serde(default, skip_serializing_if = "Option::is_none")]
912 pub pane: Option<String>,
913 /// A reference from the previous snapshot: narrow to that element.
914 #[serde(default, skip_serializing_if = "Option::is_none")]
915 pub scope: Option<String>,
916 /// Or narrow to the first element with this role and name, as `find`
917 /// would list it, so a page's first read can be narrow. Not with `scope`.
918 #[serde(default, skip_serializing_if = "Option::is_none")]
919 pub scope_match: Option<UiBrowserElementMatch>,
920 /// Characters of one text, name or value a line shows: 160 by default, up to 8000, to read a
921 /// long text (an email) in full.
922 #[serde(default, skip_serializing_if = "Option::is_none")]
923 pub max_text: Option<u32>,
924 /// List text the page hides with CSS (opacity 0, zero size, off the page) too.
925 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
926 pub include_hidden: bool,
927}
928
929/// Elements by role and accessible name: `find`'s query, and a `scope`
930/// given by name. `role` is the role a snapshot line shows, in any case;
931/// `name` a part of the accessible name in any case, or with `exact` the
932/// whole name as written.
933#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
934pub struct UiBrowserElementMatch {
935 #[serde(default, skip_serializing_if = "Option::is_none")]
936 pub role: Option<String>,
937 #[serde(default)]
938 pub name: String,
939 #[serde(default)]
940 pub exact: bool,
941}
942
943/// `POST /api/v1/ui/browser/find` — backs Browser's `find`: only the lines
944/// of the elements matching, each with a reference `click` and the rest take.
945#[derive(Debug, Clone, Serialize, Deserialize)]
946pub struct UiBrowserFindRequest {
947 #[serde(flatten)]
948 pub auth: UiAutomationAuth,
949 /// Target a browser pane this agent opened with `OpenBrowser`; absent =
950 /// the caller's own pane.
951 #[serde(default, skip_serializing_if = "Option::is_none")]
952 pub pane: Option<String>,
953 #[serde(flatten)]
954 pub query: UiBrowserElementMatch,
955}
956
957/// `POST /api/v1/ui/browser/act` — backs `BrowserClick`, `BrowserFill`,
958/// `BrowserSelect` and `BrowserCheck` (spec §4.2).
959#[derive(Debug, Clone, Serialize, Deserialize)]
960pub struct UiBrowserActRequest {
961 #[serde(flatten)]
962 pub auth: UiAutomationAuth,
963 /// Target a browser pane this agent opened with `OpenBrowser`; absent =
964 /// the caller's own pane.
965 #[serde(default, skip_serializing_if = "Option::is_none")]
966 pub pane: Option<String>,
967 /// A reference from the latest snapshot, e.g. `e12`.
968 #[serde(rename = "ref")]
969 pub ref_: String,
970 /// `click`, `fill`, `select` or `check`.
971 pub action: String,
972 #[serde(default, skip_serializing_if = "Option::is_none")]
973 pub text: Option<String>,
974 #[serde(default, skip_serializing_if = "Option::is_none")]
975 pub option: Option<String>,
976 #[serde(default, skip_serializing_if = "Option::is_none")]
977 pub checked: Option<bool>,
978 /// A click or a drag in a canvas (`ref` is the canvas): where, in the canvas's own pixels.
979 #[serde(default, skip_serializing_if = "Option::is_none")]
980 pub point: Option<crate::browser_control_types::ActPoint>,
981}
982
983/// `POST /api/v1/ui/browser/set_files` — backs `BrowserSetFiles`
984/// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §5.3). srv allows only
985/// files inside the calling agent's own workspace.
986#[derive(Debug, Clone, Serialize, Deserialize)]
987pub struct UiBrowserSetFilesRequest {
988 #[serde(flatten)]
989 pub auth: UiAutomationAuth,
990 /// Target a browser pane this agent opened with `OpenBrowser`; absent =
991 /// the caller's own pane.
992 #[serde(default, skip_serializing_if = "Option::is_none")]
993 pub pane: Option<String>,
994 /// The file input's reference from the latest snapshot. Empty with `chooser`.
995 #[serde(rename = "ref", default)]
996 pub ref_: String,
997 /// Absolute, or relative to the agent's workspace.
998 pub paths: Vec<String>,
999 /// Fill the file chooser the page last opened, instead of the input `ref` names (the uploads
1000 /// power; SPEC_BROWSER_WEB_TERMINAL_TYPING_2026_10_23.md §6).
1001 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1002 pub chooser: bool,
1003}
1004
1005/// `POST /api/v1/ui/browser/wait_for` — backs `BrowserWaitFor`.
1006/// At most one of `text`, `url_contains`, `gone`, `state`.
1007#[derive(Debug, Clone, Serialize, Deserialize)]
1008pub struct UiBrowserWaitForRequest {
1009 #[serde(flatten)]
1010 pub auth: UiAutomationAuth,
1011 /// Target a browser pane this agent opened with `OpenBrowser`; absent =
1012 /// the caller's own pane.
1013 #[serde(default, skip_serializing_if = "Option::is_none")]
1014 pub pane: Option<String>,
1015 #[serde(default, skip_serializing_if = "Option::is_none")]
1016 pub text: Option<String>,
1017 #[serde(default, skip_serializing_if = "Option::is_none")]
1018 pub url_contains: Option<String>,
1019 /// A reference whose element should leave the page.
1020 #[serde(default, skip_serializing_if = "Option::is_none")]
1021 pub gone: Option<String>,
1022 /// `load` or `idle`: the page has settled. With no condition at all, `idle`.
1023 #[serde(default, skip_serializing_if = "Option::is_none")]
1024 pub state: Option<String>,
1025 #[serde(default, skip_serializing_if = "Option::is_none")]
1026 pub timeout_ms: Option<u64>,
1027}
1028
1029/// `POST /api/v1/ui/browser/handoff` — backs `BrowserHandoff`
1030/// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §5.2): show the user a
1031/// banner in the pane and wait for Done or Cancel.
1032#[derive(Debug, Clone, Serialize, Deserialize)]
1033pub struct UiBrowserHandoffRequest {
1034 #[serde(flatten)]
1035 pub auth: UiAutomationAuth,
1036 /// Target a browser pane this agent opened with `OpenBrowser`; absent =
1037 /// the caller's own pane.
1038 #[serde(default, skip_serializing_if = "Option::is_none")]
1039 pub pane: Option<String>,
1040 /// What the user is asked to do, e.g. "Sign in to your Microsoft account".
1041 pub reason: String,
1042 #[serde(default, skip_serializing_if = "Option::is_none")]
1043 pub timeout_minutes: Option<u64>,
1044 /// `true`: float the pane first, so the step is in a window in front of the person. The page is made again
1045 /// in the new window, so it reloads at its address; the agent asks for it before it fills anything in.
1046 #[serde(default, skip_serializing_if = "Option::is_none")]
1047 pub floating: Option<bool>,
1048}
1049
1050/// `POST /api/v1/ui/browser/request_bypass` — backs Browser's `request_bypass`
1051/// (SPEC_BROWSER_PANE_BYPASS_2026_10_16.md §6): ask the user, in the pane, to
1052/// let the agent act without asking first, and wait for their answer.
1053#[derive(Debug, Clone, Serialize, Deserialize)]
1054pub struct UiBrowserRequestBypassRequest {
1055 #[serde(flatten)]
1056 pub auth: UiAutomationAuth,
1057 #[serde(default, skip_serializing_if = "Option::is_none")]
1058 pub pane: Option<String>,
1059 /// What the agent needs it for, e.g. "Delete 75 old drafts".
1060 pub reason: String,
1061 /// How long, in minutes: 15, 60 (default) or 240; other values round down.
1062 #[serde(default, skip_serializing_if = "Option::is_none")]
1063 pub minutes: Option<u64>,
1064 /// What it needs besides committing clicks, which every grant has:
1065 /// `"terminal"` (run commands in a web terminal). None: just clicks.
1066 #[serde(default, skip_serializing_if = "Option::is_none")]
1067 pub powers: Option<Vec<String>>,
1068}
1069
1070/// `POST /api/v1/ui/browser/terminal` — backs Browser's `terminal` action
1071/// (SPEC_BROWSER_WEB_TERMINAL_TYPING_2026_10_23.md §4.2): type and run commands
1072/// in a web terminal on a site the person granted.
1073#[derive(Debug, Clone, Serialize, Deserialize)]
1074pub struct UiBrowserTerminalRequest {
1075 #[serde(flatten)]
1076 pub auth: UiAutomationAuth,
1077 #[serde(default, skip_serializing_if = "Option::is_none")]
1078 pub pane: Option<String>,
1079 /// Text to type. Each line break is a real Enter press.
1080 #[serde(default, skip_serializing_if = "Option::is_none")]
1081 pub text: Option<String>,
1082 /// Press Enter after `text` (default true).
1083 #[serde(default, skip_serializing_if = "Option::is_none")]
1084 pub enter: Option<bool>,
1085 /// Named keys to press after the text: Enter, Tab, Ctrl+C and the rest.
1086 #[serde(default, skip_serializing_if = "Option::is_none")]
1087 pub keys: Option<Vec<String>>,
1088 /// Wait until the terminal shows this text.
1089 #[serde(default, skip_serializing_if = "Option::is_none")]
1090 pub until_text: Option<String>,
1091 /// How long to wait for output, in seconds (default 5, at most 60).
1092 #[serde(default, skip_serializing_if = "Option::is_none")]
1093 pub timeout_seconds: Option<u64>,
1094 #[serde(default, skip_serializing_if = "Option::is_none")]
1095 pub reason: Option<String>,
1096}
1097
1098/// `POST /api/v1/ui/browser/end_bypass` — backs Browser's `end_bypass`: the
1099/// agent ends its own bypass when the job is done.
1100#[derive(Debug, Clone, Serialize, Deserialize)]
1101pub struct UiBrowserEndBypassRequest {
1102 #[serde(flatten)]
1103 pub auth: UiAutomationAuth,
1104 #[serde(default, skip_serializing_if = "Option::is_none")]
1105 pub pane: Option<String>,
1106}
1107
1108/// `POST /api/v1/ui/browser/close` — backs Browser's `close`: the agent closes a browser pane it drives.
1109/// `pane` is required: with none, the request would name the caller's own pane.
1110#[derive(Debug, Clone, Serialize, Deserialize)]
1111pub struct UiBrowserCloseRequest {
1112 #[serde(flatten)]
1113 pub auth: UiAutomationAuth,
1114 #[serde(default, skip_serializing_if = "Option::is_none")]
1115 pub pane: Option<String>,
1116}
1117
1118/// `POST /api/v1/ui/browser/actions` — backs Browser's `log`: what the agent
1119/// did in a browser pane it drives, as the pane's action log records it
1120/// (PLAN_BROWSER_DRIVER_FIXES_2026_10_17.md §5). Read-only, own panes only.
1121#[derive(Debug, Clone, Serialize, Deserialize)]
1122pub struct UiBrowserActionsRequest {
1123 #[serde(flatten)]
1124 pub auth: UiAutomationAuth,
1125 #[serde(default, skip_serializing_if = "Option::is_none")]
1126 pub pane: Option<String>,
1127}
1128
1129/// `POST /api/v1/ui/browser/dialogs` — the page dialogs the caller's browser
1130/// panes showed since it last asked (SPEC_BROWSER_PANE_NATIVE_DIALOGS_2026_10_17.md §6.1).
1131#[derive(Debug, Clone, Serialize, Deserialize)]
1132pub struct UiBrowserDialogsRequest {
1133 #[serde(flatten)]
1134 pub auth: UiAutomationAuth,
1135}
1136
1137/// `POST /api/v1/ui/browser/open` — backs `OpenBrowser`. Opens a browser
1138/// pane below the caller's own pane and records the caller as its owner
1139/// (SPEC_AGENT_DRIVEN_BROWSER_PANES_2026_10_07.md §3).
1140#[derive(Debug, Clone, Serialize, Deserialize)]
1141pub struct UiBrowserOpenRequest {
1142 #[serde(flatten)]
1143 pub auth: UiAutomationAuth,
1144 pub url: String,
1145 /// `right`, `left`, `up` or `down`, relative to the caller's pane. Left out, the pane opens below
1146 /// the caller's, taking half of its space.
1147 #[serde(default, skip_serializing_if = "Option::is_none")]
1148 pub split: Option<String>,
1149 #[serde(default, skip_serializing_if = "Option::is_none")]
1150 pub title: Option<String>,
1151 /// Keep the pane on these sites (`allowed_origins::parse` forms); a
1152 /// navigation elsewhere asks the person
1153 /// (SPEC_BROWSER_PANE_ALLOWED_ORIGINS_2026_10_09.md).
1154 #[serde(default, skip_serializing_if = "Option::is_none")]
1155 pub allowed_origins: Option<Vec<String>>,
1156 /// Browse as `"incognito"` (a fresh jar of its own), `"personal"` (the user's own sign-ins; not for a container
1157 /// agent) or a named browser profile the user lets agents use; absent: the agent's own profile, made the first
1158 /// time (SPEC_AGENT_OWN_BROWSER_PROFILE_2026_11_04.md; SPEC_BROWSER_PANE_PROFILES_MENU_2026_10_09.md §5).
1159 #[serde(default, skip_serializing_if = "Option::is_none")]
1160 pub profile: Option<String>,
1161 /// Open as a floating window instead of below the caller's pane.
1162 #[serde(default, skip_serializing_if = "Option::is_none")]
1163 pub floating: Option<bool>,
1164 /// `false`: a background session, a window kept off every screen (SPEC_BACKGROUND_BROWSER_SESSIONS_2026_11_28.md).
1165 #[serde(default, skip_serializing_if = "Option::is_none")]
1166 pub visible: Option<bool>,
1167 /// With `floating`: its size and place. A floating browser with none is 1040 x 760, flush right.
1168 #[serde(flatten)]
1169 pub place: PlaceArgs,
1170}
1171
1172/// Response for `POST /api/v1/ui/browser/open`: the new pane's block id,
1173/// which the `Browser*` and `UI*` tools take as `pane`.
1174#[derive(Debug, Clone, Serialize, Deserialize)]
1175pub struct UiBrowserOpenResponse {
1176 pub pane: String,
1177}
1178
1179/// `POST /api/v1/agent/pane/close` — backs the `ClosePane` MCP tool.
1180/// See docs/specs/SPEC_AGENT_PANE_LIFECYCLE_CONTROL_2026_09_10.md.
1181///
1182/// `auth` is reused unchanged from `UiAutomationAuth` (the same signed
1183/// per-agent identity `verified_block_id` already checks for UI automation)
1184/// — it is what resolves the caller's OWN pane when `block_id` is omitted,
1185/// and what supplies a verified `source_agent` for the audit log when
1186/// `block_id` targets another agent's pane (§5.2 of that spec).
1187/// `QuitSelf` — an agent ends its own session on the user's direct
1188/// instruction (docs/specs/SPEC_AGENT_SELF_QUIT_2026_09_24.md §6). There is
1189/// no target field: the caller's own block, from `auth`, is the only one it
1190/// can name.
1191#[derive(Debug, Clone, Serialize, Deserialize)]
1192pub struct QuitSelfRequest {
1193 #[serde(flatten)]
1194 pub auth: UiAutomationAuth,
1195 /// One line: why. Shown to the user and audited.
1196 pub reason: String,
1197 /// The user's own words telling the agent to quit, verbatim. Checked
1198 /// against the message that started the current turn (§6.3).
1199 pub user_instruction: String,
1200}
1201
1202/// `POST /api/v1/agent/self/upgrade` — backs the `App` tool's `upgrade`
1203/// (docs/specs/SPEC_UPGRADE_FOR_USERS_AND_AGENTS_2026_10_15.md §5.1).
1204#[derive(Debug, Clone, Serialize, Deserialize)]
1205pub struct RequestUpgradeRequest {
1206 #[serde(flatten)]
1207 pub auth: UiAutomationAuth,
1208 /// One line: why. Shown to the user.
1209 pub reason: String,
1210 /// The user's own words in this turn asking for it, verbatim; empty when
1211 /// the user didn't ask. Checked like `QuitSelf`'s (`self_quit::gate`).
1212 #[serde(default)]
1213 pub user_instruction: String,
1214 /// The release the agent expects; refused unless it is the latest.
1215 #[serde(default, skip_serializing_if = "Option::is_none")]
1216 pub version: Option<String>,
1217}
1218
1219/// A window as `Desktop` names it to srv: the id `apps` gave, the app's
1220/// executable (name or path), and the window's title.
1221#[derive(Debug, Clone, Serialize, Deserialize)]
1222pub struct DesktopWindowRef {
1223 pub id: u32,
1224 pub app: String,
1225 pub title: String,
1226}
1227
1228/// `POST /api/v1/agent/desktop/policy` — backs `Desktop`'s `apps`
1229/// (docs/specs/SPEC_DESKTOP_DRIVING_2026_10_20.md §5.1): whether the tool is
1230/// on, and for each window whether it is blocked or already granted.
1231#[derive(Debug, Clone, Serialize, Deserialize)]
1232pub struct DesktopPolicyRequest {
1233 #[serde(flatten)]
1234 pub auth: UiAutomationAuth,
1235 pub windows: Vec<DesktopWindowRef>,
1236}
1237
1238/// `POST /api/v1/agent/desktop/authorize` — asked before every `Desktop`
1239/// action but `apps` (§5.4); waits while the user is asked.
1240#[derive(Debug, Clone, Serialize, Deserialize)]
1241pub struct DesktopAuthorizeRequest {
1242 #[serde(flatten)]
1243 pub auth: UiAutomationAuth,
1244 /// `look`, `click`, `scroll`, `type`, `key` or `wait`.
1245 pub action: String,
1246 pub window: DesktopWindowRef,
1247 /// The id of a call that asks for several apps at once. Each app is still its own request; the
1248 /// requests of one call share one note when they have all ended. `action` `seal` with this id says
1249 /// the call has asked for every app.
1250 #[serde(default, skip_serializing_if = "Option::is_none")]
1251 pub group: Option<String>,
1252}
1253
1254/// `POST /api/v1/agent/desktop/record` — what an authorized action did
1255/// (§5.10). Typed text is never sent, only its length in `details`.
1256#[derive(Debug, Clone, Serialize, Deserialize)]
1257pub struct DesktopRecordRequest {
1258 #[serde(flatten)]
1259 pub auth: UiAutomationAuth,
1260 #[serde(default)]
1261 pub grant_id: Option<String>,
1262 pub action: String,
1263 pub window: DesktopWindowRef,
1264 /// The point, the key names, the text length, the screenshot's hash.
1265 #[serde(default)]
1266 pub details: serde_json::Value,
1267 /// `ok`, or `error: <why>`.
1268 pub result: String,
1269}
1270
1271/// `POST /api/v1/agent/desktop/release` — the agent gives its grant back.
1272#[derive(Debug, Clone, Serialize, Deserialize)]
1273pub struct DesktopReleaseRequest {
1274 #[serde(flatten)]
1275 pub auth: UiAutomationAuth,
1276 pub window: DesktopWindowRef,
1277}
1278
1279/// `POST /api/v1/agent/spawn` — backs the `Agents` tool's `spawn`
1280/// (docs/specs/SPEC_AGENT_WORKERS_2026_10_15.md §3.1): the calling agent, the
1281/// leader, opens a worker: a new agent built from its own definition (not a
1282/// fork: no history), in its team tab.
1283/// `POST /api/v1/agent/workers` — backs the `Agents` tool's `workers`
1284/// (docs/specs/SPEC_AGENT_WORKERS_2026_10_15.md §3.4): the calling agent's own
1285/// workers, by its signed identity.
1286#[derive(Debug, Clone, Serialize, Deserialize)]
1287pub struct AgentWorkersRequest {
1288 #[serde(flatten)]
1289 pub auth: UiAutomationAuth,
1290}
1291
1292#[derive(Debug, Clone, Serialize, Deserialize)]
1293pub struct ClosePaneRequest {
1294 #[serde(flatten)]
1295 pub auth: UiAutomationAuth,
1296 /// Target pane to close. Omitted = the caller's own pane (self-only,
1297 /// no ownership check needed — it's already the caller's). Present =
1298 /// fleet tier: close ANY pane by block_id, no ownership check on the
1299 /// TARGET either, by design (§5.1) — this is the capability that
1300 /// motivated the whole spec.
1301 #[serde(default, skip_serializing_if = "Option::is_none")]
1302 pub block_id: Option<String>,
1303 /// Optional human-readable reason, threaded into the audit log entry
1304 /// when closing another agent's pane.
1305 #[serde(default, skip_serializing_if = "Option::is_none")]
1306 pub reason: Option<String>,
1307}
1308
1309/// `POST /api/v1/agent/dev_server/register` — backs the `RegisterDevServer`
1310/// MCP tool. See docs/specs/SPEC_NATIVE_CONTAINER_DEV_PROXY_2026_09_19.md.
1311///
1312/// `auth` is reused unchanged from `UiAutomationAuth`, same as
1313/// `ClosePaneRequest` above — the calling agent proves it IS `auth.agent_id`
1314/// via its own `AGENTMUX_JEKT_KEY` signature; there is no client-supplied
1315/// agent id to spoof. The backend address the routing table actually
1316/// stores is resolved server-side from THAT agent's own container (never a
1317/// client-supplied address) — this request only ever supplies the PORT the
1318/// caller's own dev server is listening on inside its own container.
1319#[derive(Debug, Clone, Serialize, Deserialize)]
1320pub struct RegisterDevServerRequest {
1321 #[serde(flatten)]
1322 pub auth: UiAutomationAuth,
1323 /// Project name — becomes part of the routing hostname,
1324 /// `<project>-<agent_id>.localhost`. Lowercased server-side before use;
1325 /// should be a short, hostname-safe slug.
1326 pub project: String,
1327 /// Port the dev server is listening on INSIDE the caller's own
1328 /// container (container-internal — never a host-published port).
1329 pub port: u16,
1330 /// The shell command that starts the server (e.g. `npm run dev`). With it AgentMux starts the
1331 /// server when it isn't listening yet and starts it again, and re-registers it, whenever the
1332 /// container is recreated; without it the registration lasts only as long as the container.
1333 #[serde(default, skip_serializing_if = "Option::is_none")]
1334 pub command: Option<String>,
1335 /// The folder the command runs in: `/workspace/...` or relative to `/workspace` (default `/workspace`).
1336 #[serde(default, skip_serializing_if = "Option::is_none")]
1337 pub dir: Option<String>,
1338}
1339
1340/// Response for `POST /api/v1/agent/dev_server/register`.
1341#[derive(Debug, Clone, Serialize, Deserialize)]
1342pub struct RegisterDevServerResponse {
1343 /// The full routable URL, e.g. `"http://pulse-korp.localhost:8090"` —
1344 /// what to actually browse to.
1345 pub url: String,
1346 /// The server was started for you and is not listening yet: the URL works once it does.
1347 #[serde(default)]
1348 pub starting: bool,
1349}
1350
1351#[cfg(test)]
1352mod app_api_manifest_contract_tests {
1353 //! Rust half of the DRY contract check for the `shell.*` routes,
1354 //! described in docs/specs/SPEC_MUXSH_FULL_COLLECTION_2026_09_16.md
1355 //! §2.8 — same mechanism and rationale as
1356 //! `crates/srv-core/src/backend/rpc_types/block.rs`'s
1357 //! `app_api_manifest_contract_tests` module for `pane.open`. A Node-side
1358 //! test (`muxsh.contract.test.mjs`) makes the matching assertion against
1359 //! the same manifest.
1360 use super::*;
1361 use std::collections::HashSet;
1362 use std::path::Path;
1363
1364 fn repo_root() -> std::path::PathBuf {
1365 Path::new(env!("CARGO_MANIFEST_DIR"))
1366 .parent()
1367 .and_then(Path::parent)
1368 .expect("crates/<name> is two levels below the repo root")
1369 .to_path_buf()
1370 }
1371
1372 fn load_manifest() -> serde_json::Value {
1373 let path = repo_root().join("docs/specs/app-api-manifest.json");
1374 let raw = std::fs::read_to_string(&path)
1375 .unwrap_or_else(|e| panic!("failed to read {}: {e}", path.display()));
1376 serde_json::from_str(&raw).expect("app-api-manifest.json must be valid JSON")
1377 }
1378
1379 fn manifest_fields(manifest: &serde_json::Value, route: &str, key: &str) -> HashSet<String> {
1380 manifest["routes"][route][key]
1381 .as_array()
1382 .unwrap_or_else(|| panic!("routes.{route}.{key} must be an array"))
1383 .iter()
1384 .map(|v| v.as_str().expect("field name must be a string").to_string())
1385 .collect()
1386 }
1387
1388 fn assert_exact_match(manifest_fields: &HashSet<String>, struct_fields: &HashSet<String>, route: &str) {
1389 let manifest_only: Vec<_> = manifest_fields.difference(struct_fields).collect();
1390 let struct_only: Vec<_> = struct_fields.difference(manifest_fields).collect();
1391 assert!(
1392 manifest_only.is_empty() && struct_only.is_empty(),
1393 "app-api-manifest.json's {route} has drifted from the real struct — \
1394 in manifest but not the struct: {manifest_only:?}; \
1395 in the struct but not the manifest: {struct_only:?}"
1396 );
1397 }
1398
1399 #[test]
1400 fn shell_create_request_fields_match_the_real_struct() {
1401 let manifest = load_manifest();
1402 let instance = ShellCreateRequest {
1403 agent_block_id: "b".to_string(),
1404 cmd: "echo hi".to_string(),
1405 cwd: Some("/tmp".to_string()),
1406 title: Some("t".to_string()),
1407 env: Some(Default::default()),
1408 capture_stdin: Some(true),
1409 connection: Some("wsl://Ubuntu".to_string()),
1410 auth: Some(UiAutomationAuth { agent_id: "a".into(), ts_secs: 1, sig: "s".into() }),
1411 secrets: Some(Default::default()),
1412 stdin_secret: Some("api-key-x".to_string()),
1413 secret_files: Some(Default::default()),
1414 capture: Some(Vec::new()),
1415 reason: Some("why".to_string()),
1416 };
1417 let value = serde_json::to_value(&instance).expect("must serialize");
1418 let struct_fields: HashSet<String> =
1419 value.as_object().expect("must be an object").keys().cloned().collect();
1420 assert_exact_match(&manifest_fields(&manifest, "shell.create", "requestFields"), &struct_fields, "shell.create.requestFields");
1421 }
1422
1423 #[test]
1424 fn shell_create_response_fields_match_the_real_struct() {
1425 let manifest = load_manifest();
1426 let instance = ShellCreateResponse { shell_id: "s".to_string(), approval: None };
1427 let value = serde_json::to_value(&instance).expect("must serialize");
1428 let struct_fields: HashSet<String> =
1429 value.as_object().expect("must be an object").keys().cloned().collect();
1430 assert_exact_match(&manifest_fields(&manifest, "shell.create", "responseFields"), &struct_fields, "shell.create.responseFields");
1431 }
1432
1433 #[test]
1434 fn shell_status_fields_match_the_real_structs() {
1435 let manifest = load_manifest();
1436 let req = ShellStatusRequest { shell_id: "s".to_string() };
1437 let req_fields: HashSet<String> = serde_json::to_value(&req)
1438 .expect("must serialize")
1439 .as_object()
1440 .expect("must be an object")
1441 .keys()
1442 .cloned()
1443 .collect();
1444 assert_exact_match(&manifest_fields(&manifest, "shell.status", "requestFields"), &req_fields, "shell.status.requestFields");
1445
1446 let resp = ShellStatusResponse { running: true, exit_code: Some(0), line_count: 1 };
1447 let resp_fields: HashSet<String> = serde_json::to_value(&resp)
1448 .expect("must serialize")
1449 .as_object()
1450 .expect("must be an object")
1451 .keys()
1452 .cloned()
1453 .collect();
1454 assert_exact_match(&manifest_fields(&manifest, "shell.status", "responseFields"), &resp_fields, "shell.status.responseFields");
1455 }
1456
1457 #[test]
1458 fn shell_stop_fields_match_the_real_structs() {
1459 let manifest = load_manifest();
1460 let req = ShellStopRequest { shell_id: "s".to_string() };
1461 let req_fields: HashSet<String> = serde_json::to_value(&req)
1462 .expect("must serialize")
1463 .as_object()
1464 .expect("must be an object")
1465 .keys()
1466 .cloned()
1467 .collect();
1468 assert_exact_match(&manifest_fields(&manifest, "shell.stop", "requestFields"), &req_fields, "shell.stop.requestFields");
1469
1470 let resp = ShellStopResponse { stopped: true };
1471 let resp_fields: HashSet<String> = serde_json::to_value(&resp)
1472 .expect("must serialize")
1473 .as_object()
1474 .expect("must be an object")
1475 .keys()
1476 .cloned()
1477 .collect();
1478 assert_exact_match(&manifest_fields(&manifest, "shell.stop", "responseFields"), &resp_fields, "shell.stop.responseFields");
1479 }
1480}