Skip to main content

agentmux_common/
place_args.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5
6/// The size and place an agent gives a floating pane (docs/specs/SPEC_AGENT_PANE_PLACEMENT_FLOATING_2026_11_22.md
7/// §2.1). Sent as given: srv checks them and says what is wrong.
8#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct PlaceArgs {
10    /// CSS pixels (a number) or a share of the work area (`"60%"`).
11    #[serde(default, skip_serializing_if = "Option::is_none")]
12    pub width: Option<serde_json::Value>,
13    #[serde(default, skip_serializing_if = "Option::is_none")]
14    pub height: Option<serde_json::Value>,
15    /// `center`, `right`, `left`, `top`, `bottom`, `top-right`, `top-left`, `bottom-right`, `bottom-left`.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub spot: Option<String>,
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub x: Option<f64>,
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub y: Option<f64>,
22}
23
24impl PlaceArgs {
25    /// The placement arguments of a tool call. A value of the wrong kind is refused here, in words the agent can act on.
26    pub fn of(arguments: &serde_json::Value) -> Result<Self, String> {
27        let size = |k: &str| match arguments.get(k) {
28            None | Some(serde_json::Value::Null) => Ok(None),
29            Some(v @ (serde_json::Value::Number(_) | serde_json::Value::String(_))) => Ok(Some(v.clone())),
30            Some(other) => Err(format!("{k} is a number of CSS pixels or a share of the work area such as 60%, not {other}")),
31        };
32        let coord = |k: &str| match arguments.get(k) {
33            None | Some(serde_json::Value::Null) => Ok(None),
34            Some(v) => v.as_f64().map(Some).ok_or_else(|| format!("{k} is a number of CSS pixels, not {v}")),
35        };
36        Ok(Self {
37            width: size("width")?,
38            height: size("height")?,
39            spot: arguments.get("spot").and_then(|v| v.as_str()).map(str::to_string),
40            x: coord("x")?,
41            y: coord("y")?,
42        })
43    }
44}
45
46/// `POST /api/v1/pane/place` — resize, move, place, dock or float a pane the caller opened
47/// (docs/specs/SPEC_AGENT_PANE_PLACEMENT_FLOATING_2026_11_22.md §2.2).
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct PanePlaceRequest {
50    /// `resize` (width and/or height), `move` (spot, or x and y), `place` (any of them, in one call), `dock`
51    /// (a floating pane back into a tab), `float` (a docked pane into its own window; the placement as an open takes it),
52    /// `pin` (a docked pane stays on screen in every tab of its window) or `unpin`.
53    pub op: String,
54    /// The pane to act on: a block id from `Pane layout`, one the caller opened.
55    pub target_id: String,
56    #[serde(flatten)]
57    pub place: PlaceArgs,
58    /// `dock`: put the pane beside the caller's own pane (`right`, `left`, `down`, `up`); absent, where it came from.
59    #[serde(default, skip_serializing_if = "Option::is_none")]
60    pub split: Option<String>,
61    /// The caller's own pane: `dock` goes into its tab, `float` is shown from its window.
62    #[serde(default, skip_serializing_if = "Option::is_none")]
63    pub block_id: Option<String>,
64}