Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Control channel: report the dialog as data, the open tool windows, and what ui.start opened (#9087) (#10740)

froglemonade2e9b08f4af4f5
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index d2e9994ba0..086d52f15a 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -187,6 +187,55 @@ fn wrap(r: Result<Value, String>) -> Outcome {
/// The design's own Sketches folder (`Visibility::hidden_folders`), which `showSketches` sets.
const SKETCHES_FOLDER: &str = "c0/sketches";
+/// The open dialog as `ui.inspect`, `ui.start` and `ui.editFeature` report it: its command, its
+/// picks and what OK runs, in the commands' own terms rather than the form's internals (#9087).
+fn dialog_state(app: &SolveApp) -> Value {
+ let Some(d) = app.dialog.as_ref() else { return Value::Null };
+ let runs = crate::dialogs::apply_commands(app, d);
+ json!({
+ "command": d.command(),
+ "title": crate::dialogs::report_title(d),
+ "editing": d.editing.map(|(feature, _)| feature),
+ "inputs": d.inputs.iter().enumerate().map(|(i, input)| json!({"label": input.label, "items": input.items, "active": i == d.active})).collect::<Vec<_>>(),
+ "error": d.error,
+ "commands": runs.as_ref().ok().map(|cmds| cmds.iter().map(|(command, params)| json!({"command": command, "params": params})).collect::<Vec<_>>()),
+ "waiting": runs.err(),
+ })
+}
+
+/// The windows open beside the model (#9087), each named by what opens it: the command
+/// `ui.start` takes, or the `ui.help` item.
+fn open_windows(app: &SolveApp) -> Vec<&'static str> {
+ [
+ (app.params.is_some(), "parameters.change"),
+ (app.design_properties.is_some(), "document.metadata"),
+ (app.sketch_report.is_some(), "sketch.inspect"),
+ (app.bom.is_some(), "assembly.bom"),
+ (app.material_card_review.is_some(), "material.properties.validate"),
+ (app.help.about, "about"),
+ (app.updater.open, "updates"),
+ (app.keymap.open, "shortcuts"),
+ (app.crashes.open, "crashes"),
+ (app.issue_report.draft.is_some(), "report"),
+ (app.messages.open, "messages"),
+ ]
+ .into_iter()
+ .filter_map(|(open, command)| open.then_some(command))
+ .collect()
+}
+
+/// What a start or an edit opened: the tool, the dialog and the windows. `pending` while it
+/// waits for the history to compute first; it opens on a later frame (`ui.inspect` shows it).
+fn started(app: &SolveApp) -> Value {
+ json!({
+ "tool": app.tool.as_ref().map(|t| t.cmd),
+ "dialog": dialog_state(app),
+ "windows": open_windows(app),
+ "pending": app.pending_feature_edit.is_some() || app.start_after_roll.is_some(),
+ "status": app.status.as_ref().map(|(text, _, error)| json!({"text": text, "error": error})),
+ })
+}
+
/// `UiState` as `ui.inspect` and `ui.set` report it, with the browser's view of the design
/// (kept in the session) under the names the UI state used to give it.
fn ui_state(app: &SolveApp) -> Value {
@@ -665,9 +714,10 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->
"viewport": app.viewport.rect.map(|r| json!([r.left(), r.top(), r.width(), r.height()])),
"camera": app.cam,
"tool": app.tool.as_ref().map(|t| t.cmd),
- "dialog": app.dialog.as_ref().map(|d| format!("{d:?}")),
+ "dialog": dialog_state(app),
+ "windows": open_windows(app),
"status": app.status.as_ref().map(|(text, _, error)| json!({"text": text, "error": error})),
- "hover": app.viewport.hover.as_ref().map(|h| format!("{h:?}")),
+ "hover": app.viewport.hover,
"renderer": if app.viewport.gpu.is_some() { "gpu" } else { "cpu" },
"frame_ms": app.frame_ms,
"draw": app.viewport.draw_stats.as_ref().and_then(|s| s.lock().ok().map(|d| json!({
@@ -841,7 +891,7 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->
return err(e);
}
}
- ok(json!({"tool": app.tool.as_ref().map(|t| t.cmd), "dialog": app.dialog.as_ref().map(|d| format!("{d:?}"))}))
+ ok(started(app))
}
"ui.move" | "ui.click" => {
let (Some(x), Some(y)) = (f("x"), f("y")) else { return err("missing x/y") };
@@ -921,12 +971,16 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->
};
let Some(id) = app.session.doc.find_feature(&key).map(|f| f.id) else { return err(format!("no feature `{key}`")) };
app.edit_feature(id);
- ok(json!({"dialog": app.dialog.as_ref().map(|d| format!("{d:?}")), "marker": app.session.doc.marker}))
+ let mut reply = started(app);
+ if let Some(o) = reply.as_object_mut() {
+ o.insert("marker".into(), json!(app.session.doc.marker));
+ }
+ ok(reply)
}
"ui.selection" => ok(json!({
"selection": app.session.selection,
"dialog": app.dialog.as_ref().map(|d| d.inputs.iter().map(|i| json!({"label": i.label, "items": i.items})).collect::<Vec<_>>()),
- "hover": app.viewport.hover.as_ref().map(|h| format!("{h:?}")),
+ "hover": app.viewport.hover,
"dimensions": crate::dim_view::drawn().into_iter().map(|(id, p)| json!({"id": id, "x": p.x, "y": p.y})).collect::<Vec<_>>(),
"shown_dimensions": crate::dim_view::model_drawn()
.into_iter()
@@ -2496,6 +2550,56 @@ mod tests {
}
}
+ /// #9087: the dialog is reported as data (its command, inputs and what OK runs), not as the
+ /// form's Debug text; `ui.start` and `ui.editFeature` reply with what they opened, and the
+ /// tool windows (Parameters, Bill of Materials) are reported by the command that opens them.
+ #[test]
+ fn dialogs_and_tool_windows_are_reported_as_data() {
+ let mut s = Session::default();
+ s.execute("solid.box", &json!({"length": 40, "width": 30, "height": 20})).unwrap();
+ let mut h = crate::scenario::Harness::new();
+ h.app = SolveApp::new(s, Services::default());
+ let r = h.call("ui.start", json!({"command": "solid.fillet"}));
+ let d = &r["result"]["dialog"];
+ assert_eq!((&d["command"], &d["title"], &d["editing"]), (&json!("solid.fillet"), &json!("FILLET"), &Value::Null), "{r}");
+ assert_eq!((&d["inputs"][0]["active"], &d["inputs"][0]["items"]), (&json!(true), &json!([])), "{r}");
+ assert!(d["commands"].is_null() && d["waiting"].is_string(), "no edge picked yet: {r}");
+ assert_eq!((&r["result"]["pending"], &r["result"]["windows"]), (&json!(false), &json!([])), "{r}");
+ assert_eq!(h.call("ui.inspect", json!({}))["result"]["dialog"], *d, "ui.inspect reports the same");
+ crate::dialogs::cancel(&mut h.app);
+
+ let feature = h.app.session.doc.features[0].id;
+ let r = h.call("ui.editFeature", json!({"feature": feature}));
+ let d = &r["result"]["dialog"];
+ assert_eq!((&d["command"], &d["editing"]), (&json!("solid.box"), &json!(feature)), "{r}");
+ // OK rebuilds the feature in place, from what the form holds.
+ let runs = &d["commands"][0];
+ assert_eq!((&runs["command"], &runs["params"]["command"]), (&json!("timeline.redefine"), &json!("solid.box")), "{r}");
+ assert_eq!((&runs["params"]["feature"], &runs["params"]["params"]["length"]), (&json!(feature), &json!("40")), "{r}");
+ assert!(r["result"].get("marker").is_some(), "{r}");
+ crate::dialogs::cancel(&mut h.app);
+
+ for (command, windows) in
+ [("parameters.change", json!(["parameters.change"])), ("assembly.bom", json!(["parameters.change", "assembly.bom"]))]
+ {
+ let r = h.call("ui.start", json!({"command": command}));
+ assert_eq!((&r["result"]["dialog"], &r["result"]["tool"], &r["result"]["windows"]), (&Value::Null, &Value::Null, &windows), "{r}");
+ assert_eq!(h.call("ui.inspect", json!({}))["result"]["windows"], windows, "{command}");
+ }
+ h.call("ui.help", json!({"item": "about"}));
+ assert_eq!(
+ h.call("ui.inspect", json!({}))["result"]["windows"],
+ json!(["parameters.change", "assembly.bom", "about"]),
+ "the Help menu's windows too"
+ );
+
+ // What is under the pointer is a selection-like item, not the viewport's Debug text.
+ h.app.viewport.hover =
+ Some(crate::viewport::Hit::Face { body: "Body1".into(), index: 2, point: solidcraft_engine::geom::Vec3::new(1.0, 2.0, 3.0) });
+ let hover = json!({"type": "face", "body": "Body1", "index": 2, "point": [1.0, 2.0, 3.0]});
+ assert_eq!(h.call("ui.selection", json!({}))["result"]["hover"], hover);
+ }
+
/// #9087: a sample index that names no sample is refused, so an agent can tell a typo from
/// a sample that opened. The index is checked before it reaches `open_sample`, which would
/// otherwise drop it and reply `ok`.
diff --git a/crates/ui-egui/src/scenario.rs b/crates/ui-egui/src/scenario.rs
index 757141daff..e8c9c333a4 100644
--- a/crates/ui-egui/src/scenario.rs
+++ b/crates/ui-egui/src/scenario.rs
@@ -897,14 +897,16 @@ pub fn check(h: &mut Harness, e: &Value) -> Result<(), String> {
}
}
"dialog" => {
- let d = &ui["dialog"];
+ // A word of the dialog's state as the code holds it: scenarios check fields that
+ // `ui.inspect` reports only as the command OK runs.
+ let d = h.app.dialog.as_ref().map(|d| format!("{d:?}"));
let ok = match v {
- Value::Null => d.is_null(),
- Value::String(w) => d.as_str().is_some_and(|d| d.contains(w.as_str())),
+ Value::Null => d.is_none() && ui["dialog"].is_null(),
+ Value::String(w) => d.as_deref().is_some_and(|d| d.contains(w.as_str())),
_ => false,
};
if !ok {
- return Err(format!("dialog: got {d}, want {v}"));
+ return Err(format!("dialog: got {d:?}, want {v}"));
}
}
"tool" => {
diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs
index 74e69eb763..f9c78e1749 100644
--- a/crates/ui-egui/src/viewport.rs
+++ b/crates/ui-egui/src/viewport.rs
@@ -229,8 +229,10 @@ pub struct ViewportState {
pub(crate) grid_plane: std::sync::Mutex<GridPlane>,
}
-/// Something under the cursor.
-#[derive(Clone, Debug, PartialEq)]
+/// Something under the cursor. The control channel reports it in the selection's own form
+/// (`{"type": "edge", "body", "index", …}`, #9087).
+#[derive(Clone, Debug, PartialEq, serde::Serialize)]
+#[serde(tag = "type", rename_all = "snake_case")]
pub enum Hit {
SketchPoint {
sketch: u64,
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 7bcd5ea29f..78d8ac7b65 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -372,11 +372,11 @@ no box selection.
| Method | Params | Notes |
|---|---|---|
-| `ui.inspect` | — | UI state, pending file picker (`file_picker_busy`; compatibility alias `file_dialog_open`, no path), what is hidden (`visibility`: bodies, origin and construction items, sketches, joints (`hidden_joints`, joint ids); set it with the `browser.visibility` command), viewport rect, camera, active tool/dialog, the status line (`status`: text and whether it is an error), hover, renderer, timings, what the GPU drew last frame (`draw`: `draw_calls`, `triangles`, `line_segments`, `supersampled`; null without a GPU) and the graphics `adapter`, live preview (`active`, `busy`, `error`, `ms`, bodies it stands in for) |
+| `ui.inspect` | — | UI state, pending file picker (`file_picker_busy`; compatibility alias `file_dialog_open`, no path), what is hidden (`visibility`: bodies, origin and construction items, sketches, joints (`hidden_joints`, joint ids); set it with the `browser.visibility` command), viewport rect, camera, the active tool (its command id), the open dialog (`dialog`, below), the windows open beside the model (`windows`, each named by what opens it: the `ui.start` command `parameters.change`, `document.metadata`, `sketch.inspect`, `assembly.bom` or `material.properties.validate`, or the `ui.help` item `about`, `updates`, `shortcuts`, `crashes`, `report`, or `messages`), what is under the pointer (`hover`, in the form of a selection item: `{"type": "edge", "body", "index", "mid", "point"}`, or null), the status line (`status`: text and whether it is an error), renderer, timings, what the GPU drew last frame (`draw`: `draw_calls`, `triangles`, `line_segments`, `supersampled`; null without a GPU) and the graphics `adapter`, live preview (`active`, `busy`, `error`, `ms`, bodies it stands in for) |
| `ui.set` | any `UiState` field (`tab`, `perspective`, `showGrid`, `dark`, `layout`, …), and the browser's view of the design, saved with it: `showOrigin` (the Origin folder's eye), `showSketches` (the design's Sketches folder, `c0/sketches` in `hiddenFolders`), `hiddenBodies`, `hiddenOrigin`, `hiddenSketches`, `shownSketches`, `hiddenJoints`, `hiddenFolders`, `hiddenProfiles`, `shownDims`, `lockedBodies` (whole lists; `browser.visibility` changes single items) | `dark: false` switches to the light theme; `layout: "floating"` (default) or `"compact"` (`"docked"` is also accepted) selects the transient shell layout without saving a preference. Scenarios use `{"call":"ui.set","params":{"layout":"docked"}}` |
| `ui.view` | `view`: `front`, `back`, `top`, `bottom`, `left`, `right`, `iso`, `home`, `fit`; `animate` (bool, default false: snap) | |
| `ui.camera` | `target?`: `[x, y, z]` (mm), `yaw?`, `pitch?`, `roll?` (radians), `distance?` (mm), `fov?`, `up?`; `fit?`: `true`, `false` or `[occurrence id or name…]` (`root`: the bodies outside every component) | the viewport's orbit camera: it looks at `target` from `distance` away; `yaw` 0 looks along +Y (from the front), `pitch` is the elevation (±π/2: straight down or up), `roll` turns the image. Fields given are set first (the others keep their values), then `fit` frames the listed occurrences (or everything), keeping the direction. The reply, passed back, sets the same view again, so a framing can be stored and replayed. `fov` is the angle the view is drawn with: 0 (parallel) with Perspective view off or while a sketch is open, else `perspective_fov`; in Render, the Render camera's own. `fov` and `up` follow the perspective setting (`ui.set`), its angle (`ui.prefs {perspective_fov}`) and the up axis preference (`ui.prefs`) and can't change here; a refused field changes nothing |
-| `ui.start` | `command`, `params?` | like a toolbar click: starts the sketch tool or dialog for the command. `params` sets what the dialog opens on, and nothing runs until OK: `joint.drive` takes `joint` (id or name; without it, the joint picked in the browser, else the first joint that moves; a rigid joint opens to say why it has nothing to drive, with an Edit Joint button, handle `drive:edit_joint`) and `values` (numbers in degrees or millimetres, or expressions); `motion.study` takes `study` (id or name), which opens that study to edit and chart. A command that takes no params is refused before it starts; a param the dialog doesn't take is refused and the dialog closes |
+| `ui.start` | `command`, `params?` | like a toolbar click: starts the sketch tool or dialog for the command. `params` sets what the dialog opens on, and nothing runs until OK: `joint.drive` takes `joint` (id or name; without it, the joint picked in the browser, else the first joint that moves; a rigid joint opens to say why it has nothing to drive, with an Edit Joint button, handle `drive:edit_joint`) and `values` (numbers in degrees or millimetres, or expressions); `motion.study` takes `study` (id or name), which opens that study to edit and chart. A command that takes no params is refused before it starts; a param the dialog doesn't take is refused and the dialog closes. Replies what it opened: `tool`, `dialog` and `windows` as `ui.inspect` gives them, `status` (where a command that starts nothing says why), and `pending: true` when the start waits for the history to compute and opens on a later frame |
| `ui.click` | `x`, `y` (screen points), `button?`: left/right/middle, `shift?`, `ctrl?`, `double?` | real pointer input |
| `ui.move` | `x`, `y`, `shift?`, `alt?`, `ctrl?`, `cmd?` | pointer movement without a button; modifiers apply until the next synthetic move/click; a move with omitted modifiers releases them. With `nav: "touchpad"`, Shift pans and Alt/Option orbits. |
| `ui.drag` | `x0`, `y0`, `x1`, `y1`, `via?`, `button?`, `shift?`, `ctrl?`, `steps?`, `hold?`, `hold_end?` | press, move, release; `via` is a list of `[x, y]` points passed through on the way (`steps` moves to each); a left drag on the model is a box selection (left to right: window, right to left: crossing), or with `lassoSelect` on (`ui.set`, the SELECT panel's Lasso) a freehand lasso that takes what is wholly inside it; with OpenSCAD navigation, plain left-drag on empty space orbits, Shift+left-drag box-selects, and drags starting on sketch geometry edit it; `hold` keeps the button down that many frames first (a right press-and-hold opens the marking menu, releasing over a direction picks it), `hold_end` that many frames at the end (a sketch drag shows its snap) |
@@ -393,7 +393,7 @@ no box selection.
| `ui.at` | `world: [x,y,z]` \| `sketch: [x,y]` \| `plane: "XY"` \| `axis: "Z"` \| `dimension: "d1"` (its value text) \| `handle: "arrow"` (a manipulator handle, see `scenario::publish_handle`) | the screen point (a scenario step's target; see `crates/ui-egui/src/scenario.rs`) |
| `ui.pick` | `pixels?: [[x,y]…]`, `rays?: [{origin, dir}…]`, `frame?: "window"\|"model"`, `width?`, `height?`, `edges?` (default true), `edge_px?` (default 6), `all?`, `include_ghosted?` | read-only geometry under each pixel or ray (#6304): one entry per input, `null` where nothing is hit — body, face index, exact world `point` and outward `normal`, `depth`, `occurrence`/`component` for placed parts, `edge`/`vertex` within `edge_px` of a pixel, `section_cap: true` on a cut face. `window` pixels are physical pixels of a window screenshot; `model` pixels are pixels of a `ui.render` of `width`×`height` (default 960×600), so it works headless. As `view.pick` through `engine.execute`/`engine.batch`. See `crates/ui-egui/src/view_pick.rs` |
| `ui.handles` | `prefix?` | the handles drawn last frame, `[{name, x, y}]`: toolbar buttons and drop-down items `toolbar:<command id>` (the button alone: `button:<command id>`; a drop-down row: `dropdown:<command id>`, highlighted `dropdown_hot:<command id>`, its pin `dropdown_pin:<command id>`; Customize Toolbar's check boxes `customize:<command id>`), ribbon tabs `tab:<name>` (MODEL, SURFACE, ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW, SHEET METAL, WELDMENTS; contextual SKETCH; workspace RENDER), the toolbar menu button `ribbon:add_tab`, the hint when every tab is hidden `ribbon:tabs_hidden`, Preferences tab check boxes `prefs:toolbar_tab:<NAME>`, panel labels `panel:<tab>:<panel>` (also `ribbon:section:<TAB>:<SECTION>`), document overflow list `tab:overflow`, workspace column `ribbon:workspace`, command-search launcher `ribbon:search`, browser rows `row:<label>`, where each row's depth puts it `indent:<label>`, and fold arrows `fold:<label>`, manipulator handles; signed-axis tips `axis_view:z`, `axis_view:-y`; optional cube facets `navigation_cube:top`, `navigation_cube:top_front_right`, controls `navigation_cube:control:home` (and other actions), plus signed-axis aliases for visible cube faces; Preferences navigator picker `prefs:navigator`, options `prefs:navigator:Signed axes` and `prefs:navigator:Cube`; in the Motion Study dialog, where the chart puts its first and last step `motion:chart_start` and `motion:chart_end`, the Check collisions button `motion:check` and each collision found `motion:collision:<n>` |
-| `ui.editFeature` | `feature` (id or name) | what double-clicking a timeline item does: rolls back to it and opens its dialog filled in (sketches open in sketch mode) |
+| `ui.editFeature` | `feature` (id or name) | what double-clicking a timeline item does: rolls back to it and opens its dialog filled in (sketches open in sketch mode). Replies as `ui.start` does, with the history `marker` |
| `ui.scroll` | `x`, `y`, `delta?`, `ctrl?`, `unit?`: `point` \| `line` | wheel zoom at the cursor. `ctrl: true` replays a Ctrl+wheel pinch (Ctrl held and the wheel in points); `unit` selects the wheel unit and defaults to points with `ctrl` and lines without it. `delta` is in points either way. Invalid units or coordinates outside the finite screen-coordinate range are rejected before queuing input |
| `ui.key` | `key` (egui key name, `Enter`, `Escape`…), `cmd?`, `ctrl?`, `shift?`, `alt?`, `pressed?` | By default, press and release, then release modifiers. With `pressed: true` or `false`, send only that edge; modifiers remain as given. `cmd` retains the legacy primary-modifier alias unless `ctrl` is explicit: `cmd:true, ctrl:false` sends physical Command, and both true sends Control+Command. `ui.move` can change modifiers between edges. |
| `ui.text` | `text` | typed text |
@@ -418,6 +418,25 @@ no box selection.
| `ui.resize` | `width`, `height` | |
| `app.quit` | `force?` (quit without asking about unsaved designs) | `quitting` (the window closes), `asking` (a "save changes?" prompt is open) |
+`dialog` (in `ui.inspect`, `ui.start` and `ui.editFeature`) is `null`, or the open dialog as
+an object that doesn't change with the form's internals:
+
+```json
+{"command": "solid.extrude", "title": "EXTRUDE", "editing": null,
+ "inputs": [{"label": "Profiles", "items": [{"type": "profile", "sketch": 10, "index": 0}], "active": true}],
+ "error": null,
+ "commands": [{"command": "solid.extrude", "params": {"sketch": 10, "profiles": [0], "distance": "10 mm",
+ "direction": "positive", "operation": "join", "exact_regions": true}}],
+ "waiting": null}
+```
+
+`command` is the command the dialog runs (null for a few forms that run none), `title` its
+header, `editing` the feature id an edit rebuilds, `inputs` its selection inputs (`active`: the
+one picks go to), `error` the refusal it shows. `commands` is what OK runs now, with the
+parameters as that command takes them (an edit runs `timeline.redefine` with the feature's command and
+parameters inside); when OK can't run yet, `commands` is null and `waiting`
+says what it waits for (`select profiles first`).
+
For an ACP agent advertising configuration options, `ui.agent_chat` also accepts
`{"config_option": {"id": "effort", "value": "high"}}`. Use an option ID and choice value
from its reported `configOptions`; IDs and available values belong to the agent. The reply's