SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Agent chat: only the chat's own tools skip the panel's question (#10955)
bherbruck9fdf15305444
diff --git a/crates/ui-egui/examples/acp_test_agent.rs b/crates/ui-egui/examples/acp_test_agent.rsindex 95c625e7fd..58b48bd0d4 100644--- a/crates/ui-egui/examples/acp_test_agent.rs+++ b/crates/ui-egui/examples/acp_test_agent.rs@@ -177,7 +177,7 @@ fn main() {send(&json!({"jsonrpc": "2.0", "id": 900, "method": "session/request_permission", "params": {"sessionId": session,// Named as the Claude Code adapter names an MCP tool.- "toolCall": {"toolCallId": "t1", "title": "mcp__solidcraft__batch"},+ "toolCall": {"toolCallId": "t1", "title": "mcp__solidcraft-app__batch", "kind": "other"},"options": [{"optionId": "allow", "name": "Allow", "kind": "allow_once"}, {"optionId": "reject", "name": "Reject", "kind": "reject_once"}],}}));// Wait for the answer (other lines are not expected meanwhile).diff --git a/crates/ui-egui/src/agent_chat/acp.rs b/crates/ui-egui/src/agent_chat/acp.rsindex 2f5e4d49fa..efffaf3314 100644--- a/crates/ui-egui/src/agent_chat/acp.rs+++ b/crates/ui-egui/src/agent_chat/acp.rs@@ -160,6 +160,19 @@ pub fn initialize_params(version: &str) -> Value {/// keeps its own entry on a clash) can't shadow the bridge with a headless session.pub const BRIDGE_NAME: &str = "solidcraft-app";+/// Whether a permission question is about a tool of the chat's own MCP server, whose calls+/// SolidCraft's gate checks. The agent writes both values and ACP has nothing better to go on, so+/// the test is strict: the whole title is the tool's name as the Claude adapter forms it+/// (`mcp__solidcraft-app__batch`), one word with no room for a command line, a path or other free+/// text, and the kind is `other` (the kind an MCP tool has) or not given. Any other title goes+/// through the user's mode and remembered answers: agents that word their MCP tools differently,+/// and a user's own MCP server, which the gate doesn't see.+pub fn is_bridge_tool(title: &str, kind: Option<&str>) -> bool {+ let tool = title.strip_prefix("mcp__").and_then(|t| t.strip_prefix(BRIDGE_NAME)).and_then(|t| t.strip_prefix("__"));+ let named = tool.is_some_and(|t| !t.is_empty() && t.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'_'));+ named && matches!(kind, None | Some("other"))+}+/// The MCP server the agent starts to reach the design: `solidcraft-cli mcp --connect` bridged to/// this app's control port. The server finds the port's token in the token file the app wrote/// (docs/control-protocol.md), so the token never travels through the agent, and it keeps its@@ -473,6 +486,8 @@ pub enum Incoming {Permission {rpc: Value,title: String,+ /// The tool call's kind (`execute`, `edit`, `other`, …), as the agent gives it.+ kind: Option<String>,options: Vec<PermissionOption>,},/// The agent says whether it is logged in (an extension both adapters send).@@ -546,6 +561,7 @@ pub fn parse(line: &str) -> Option<Incoming> {(Some("session/request_permission"), Some(id)) => {let call = params.get("toolCall");let title = call.and_then(|c| c.get("title")).and_then(Value::as_str).unwrap_or("").to_string();+ let kind = call.and_then(|c| c.get("kind")).and_then(Value::as_str).map(str::to_string);let options = params.get("options").and_then(Value::as_array)@@ -562,7 +578,7 @@ pub fn parse(line: &str) -> Option<Incoming> {.collect()}).unwrap_or_default();- Some(Incoming::Permission { rpc: id.clone(), title, options })+ Some(Incoming::Permission { rpc: id.clone(), title, kind, options })}(Some(m), Some(id)) => Some(Incoming::Unsupported { rpc: id.clone(), method: m.to_string() }),(Some("session/update"), None) => Some(update(params.get("update")?, params.get("sessionId").and_then(Value::as_str).unwrap_or(""))),@@ -700,6 +716,48 @@ mod tests {// The panel still recognises the bridge's tools as SolidCraft's (agents name them after// their server, e.g. `mcp__solidcraft-app__batch`).assert!(BRIDGE_NAME.contains("solidcraft"));+ assert!(is_bridge_tool(&format!("mcp__{BRIDGE_NAME}__batch"), Some("other")));+ }++ /// Only the whole name of a tool of the chat's own server counts, whatever else a title holds.+ #[test]+ fn only_the_bridges_exact_tool_names_are_its_tools() {+ for tool in ["batch", "inspect_design", "set_parameter"] {+ assert!(is_bridge_tool(&format!("mcp__solidcraft-app__{tool}"), None), "{tool}");+ assert!(is_bridge_tool(&format!("mcp__solidcraft-app__{tool}"), Some("other")), "{tool}");+ }+ for title in [+ "",+ "solidcraft",+ "SolidCraft",+ "run solidcraft-cli; ls",+ "solidcraft-cli --version",+ "Edit ~/.local/share/solidcraft/agent-chat/work/notes.txt",+ // A user's own MCP server (docs/mcp.md), which SolidCraft's gate doesn't see.+ "mcp__solidcraft__batch",+ "mcp__solidcraft-live__batch",+ "mcp__other__solidcraft-app",+ "mcp__solidcraft-app__",+ "mcp__solidcraft-app",+ "solidcraft-app__batch",+ "solidcraft-app: batch",+ "Tool: solidcraft-app/batch",+ "mcp.solidcraft-app.batch",+ " mcp__solidcraft-app__batch",+ "mcp__solidcraft-app__batch ",+ "mcp__solidcraft-app__batch; ls",+ "mcp__solidcraft-app__batch && ls",+ "mcp__solidcraft-app__batch\nls",+ "mcp__solidcraft-app__../../tool",+ "mcp__SOLIDCRAFT-APP__batch",+ "MCP__solidcraft-app__batch",+ "mcp__solidcraft-app__Batch",+ ] {+ assert!(!is_bridge_tool(title, None), "{title:?}");+ }+ for kind in ["execute", "edit", "delete", "move", "read", "search", "fetch", "think", ""] {+ assert!(!is_bridge_tool("mcp__solidcraft-app__batch", Some(kind)), "{kind:?}");+ }}#[test]@@ -813,8 +871,9 @@ mod tests {}));let perm = r#"{"jsonrpc":"2.0","id":7,"method":"session/request_permission","params":{"sessionId":"s","toolCall":{"toolCallId":"t1","title":"batch"},"options":[{"optionId":"allow","name":"Allow","kind":"allow_once"},{"optionId":"reject","name":"Reject","kind":"reject_once"}]}}"#;- let Some(Incoming::Permission { rpc, title, options }) = parse(perm) else { panic!() };+ let Some(Incoming::Permission { rpc, title, kind, options }) = parse(perm) else { panic!() };assert_eq!((title.as_str(), options.len(), options[1].kind.as_str()), ("batch", 2, "reject_once"));+ assert_eq!(kind, None);assert_eq!(permission_reply(rpc.clone(), Some("allow"))["result"]["outcome"], json!({"outcome": "selected", "optionId": "allow"}));assert_eq!(permission_reply(rpc, None)["result"]["outcome"]["outcome"], "cancelled");let fs = r#"{"jsonrpc":"2.0","id":8,"method":"fs/read_text_file","params":{}}"#;diff --git a/crates/ui-egui/src/agent_chat/acp_client.rs b/crates/ui-egui/src/agent_chat/acp_client.rsindex 021eba0f5c..7255dab253 100644--- a/crates/ui-egui/src/agent_chat/acp_client.rs+++ b/crates/ui-egui/src/agent_chat/acp_client.rs@@ -195,10 +195,10 @@ impl AcpBackend {Incoming::Text { thought, text } => out.push(Event::Text { thought, text }),Incoming::Tool { id, title, kind, status, input, output } => out.push(Event::Tool { id, title, kind, status, input, output }),Incoming::Plan(p) => out.push(Event::Plan(p)),- Incoming::Permission { rpc, title, options } => {+ Incoming::Permission { rpc, title, kind, options } => {self.next_key += 1;self.permissions.insert(self.next_key, rpc);- out.push(Event::Permission { key: self.next_key, title, options });+ out.push(Event::Permission { key: self.next_key, title, kind, options });}Incoming::AuthStatus(s) => out.push(Event::AuthStatus(s)),Incoming::ModeChanged(m) if !self.modern_config => out.push(Event::Modes { current: m, available: Vec::new() }),diff --git a/crates/ui-egui/src/agent_chat/backend.rs b/crates/ui-egui/src/agent_chat/backend.rsindex ccd404c09e..51d88f0e40 100644--- a/crates/ui-egui/src/agent_chat/backend.rs+++ b/crates/ui-egui/src/agent_chat/backend.rs@@ -78,6 +78,8 @@ pub enum Event {Permission {key: u64,title: String,+ /// The tool call's kind, as the agent gives it.+ kind: Option<String>,options: Vec<PermissionOption>,},/// It needs the user to sign in; `methods` are its own ways to do so.diff --git a/crates/ui-egui/src/agent_chat/mod.rs b/crates/ui-egui/src/agent_chat/mod.rsindex c2f4b7261b..24966a7531 100644--- a/crates/ui-egui/src/agent_chat/mod.rs+++ b/crates/ui-egui/src/agent_chat/mod.rs@@ -732,7 +732,7 @@ impl AgentChat {self.push(Item::Plan(entries));}}- Event::Permission { key, title, options } => return Some(Outcome::Permission { key, title, options }),+ Event::Permission { key, title, kind, options } => return Some(Outcome::Permission { key, title, kind, options }),Event::Modes { current, available } => {if self.config_options.is_none() && !available.is_empty() {self.modes = available;@@ -860,7 +860,7 @@ enum Outcome {/// A message was answered (or the agent stopped): the turn's bookkeeping ends.TurnEnd,/// The agent asks before running something of its own: answered by the mode, or asked.- Permission { key: u64, title: String, options: Vec<PermissionOption> },+ Permission { key: u64, title: String, kind: Option<String>, options: Vec<PermissionOption> },}/// The AI features are on (the master switch in Settings → AI) and this is the desktop app.@@ -933,12 +933,6 @@ pub(crate) fn assistant_tip(app: &SolveApp, mark: AssistantMark) -> String {format!("{name} — {state}")}-/// Whether a permission question is about one of SolidCraft's own tools (which SolidCraft's own-/// gate checks): the agents name MCP tools after their server.-fn solidcraft_tool(title: &str) -> bool {- title.to_ascii_lowercase().contains("solidcraft")-}-/// `solidcraft-cli` next to this program, else on the search path.#[cfg(not(target_arch = "wasm32"))]pub(crate) fn find_cli() -> Option<std::path::PathBuf> {@@ -1668,14 +1662,15 @@ pub fn answer_permission(app: &mut SolveApp, index: usize, option: Option<&str>)app.agent_chat.answer(index, option);}-/// The agent asks before running something of its own. SolidCraft's own tools are checked by-/// SolidCraft's gate, so they're allowed here (no double question); otherwise the mode or an-/// earlier "always allow" may answer, and the chat says so; otherwise the user is asked.-fn on_permission(app: &mut SolveApp, key: u64, title: String, options: Vec<PermissionOption>) {+/// The agent asks before running something of its own. The chat's own MCP tools are checked by+/// SolidCraft's gate, so they're allowed here (no double question, see [`acp::is_bridge_tool`]);+/// otherwise the mode or an earlier "always allow" may answer, and the chat says so; otherwise the+/// user is asked.+fn on_permission(app: &mut SolveApp, key: u64, title: String, kind: Option<&str>, options: Vec<PermissionOption>) {let agent = app.agent_chat.running_id.clone();let mode = agents::mode_for(&app.preferences, &agent);let remembered = agents::always_allowed(&app.preferences, &agent, &title);- let why = if solidcraft_tool(&title) {+ let why = if acp::is_bridge_tool(&title, kind) {Some("ui.ai_auto_ours")} else if remembered {Some("ui.ai_auto_remembered")@@ -1959,7 +1954,7 @@ pub fn poll(app: &mut SolveApp, ctx: &egui::Context) {b.answer_permission(key, None);}}- Some(Outcome::Permission { key, title, options }) => on_permission(app, key, title, options),+ Some(Outcome::Permission { key, title, kind, options }) => on_permission(app, key, title, kind.as_deref(), options),None => {}}if let Some(model) = confirmed_model {diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rsindex 64b0940e82..ea0d61b547 100644--- a/crates/ui-egui/src/agent_chat/tests.rs+++ b/crates/ui-egui/src/agent_chat/tests.rs@@ -652,17 +652,48 @@ fn the_agents_own_questions_are_answered_by_the_mode_or_asked() {PermissionOption { id: "no".into(), name: "Reject".into(), kind: "reject_once".into() },]};- on_permission(&mut app, 1, "mcp__solidcraft__batch".into(), opts());- assert!(matches!(app.agent_chat.items.last(), Some(Item::Notice { text, .. }) if text.contains("mcp__solidcraft__batch")));- on_permission(&mut app, 2, "Run ls".into(), opts());+ on_permission(&mut app, 1, "mcp__solidcraft-app__batch".into(), Some("other"), opts());+ assert!(matches!(app.agent_chat.items.last(), Some(Item::Notice { text, .. }) if text.contains("mcp__solidcraft-app__batch")));+ on_permission(&mut app, 2, "Run ls".into(), None, opts());assert!(matches!(app.agent_chat.items.last(), Some(Item::Permission { answer: None, .. })));let n = app.agent_chat.items.len() - 1;answer_permission(&mut app, n, Some("always"));assert!(agents::always_allowed(&app.preferences, "claude", "Run ls"));- on_permission(&mut app, 3, "Run ls".into(), opts());+ on_permission(&mut app, 3, "Run ls".into(), None, opts());assert!(matches!(app.agent_chat.items.last(), Some(Item::Notice { .. })), "remembered");}+/// A title that only mentions SolidCraft is no tool of SolidCraft's: in every mode but Allow+/// everything the user is asked, and the mode still answers when it says to.+#[test]+fn a_title_that_mentions_solidcraft_goes_through_the_users_mode() {+ let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());+ app.agent_chat.running_id = "codex".into();+ let opts = || vec![PermissionOption { id: "allow".into(), name: "Allow".into(), kind: "allow_once".into() }];+ let titles = [+ ("run solidcraft-cli; ls", Some("execute")),+ ("run solidcraft-cli; ls", None),+ ("Edit ~/.local/share/solidcraft/agent-chat/work/notes.txt", Some("edit")),+ ("mcp__solidcraft__batch", Some("other")),+ ("mcp__solidcraft-app__batch", Some("execute")),+ ];+ for mode in [agents::Mode::Ask, agents::Mode::Edits] {+ app.preferences.agent_permissions.insert("codex".into(), mode);+ for (title, kind) in titles {+ on_permission(&mut app, 1, title.into(), kind, opts());+ assert!(matches!(app.agent_chat.items.last(), Some(Item::Permission { answer: None, .. })), "{mode:?}: {title}");+ app.agent_chat.items.clear();+ }+ // The chat's own tool stays a single question, the gate's.+ on_permission(&mut app, 2, "mcp__solidcraft-app__batch".into(), Some("other"), opts());+ assert!(matches!(app.agent_chat.items.last(), Some(Item::Notice { .. })), "{mode:?}");+ app.agent_chat.items.clear();+ }+ app.preferences.agent_permissions.insert("codex".into(), agents::Mode::All);+ on_permission(&mut app, 3, titles[0].0.into(), titles[0].1, opts());+ assert!(matches!(app.agent_chat.items.last(), Some(Item::Notice { .. })), "Allow everything answers it");+}+// ---- Messages typed while the agent works ----use std::sync::Mutex;@@ -818,7 +849,8 @@ fn a_late_sign_in_retry_or_permission_cannot_restart_a_departed_turn() {crate::documents::open_tab(&mut app, solidcraft_engine::Session::default()).unwrap();script.report(Event::Permission {key: 7,- title: "mcp__solidcraft__batch".into(),+ title: "mcp__solidcraft-app__batch".into(),+ kind: None,options: vec![PermissionOption { id: "allow".into(), name: "Allow".into(), kind: "allow_once".into() }],});ended(&script, "auth");diff --git a/docs/agent-chat.md b/docs/agent-chat.mdindex 27c3b01c4f..7d3717730a 100644--- a/docs/agent-chat.md+++ b/docs/agent-chat.md@@ -421,9 +421,12 @@ per agent, with **Reset**.These settings cover SolidCraft's tools. A coding agent's own tools (its shell, its file edits)follow the agent's own mode, which you pick in the panel's header. When an agent asks before-using one of SolidCraft's tools, SolidCraft answers for you, since its own gate checks the call,-and notes it in the chat as *Auto-allowed*. With **Allow everything**, or after **Always allow**,-the agent's other questions are answered the same way and noted too.+using one of the chat's own SolidCraft tools and names it exactly as the Claude adapter does+(`mcp__solidcraft-app__batch`), SolidCraft answers for you, since its own gate checks the call,+and notes it in the chat as *Auto-allowed*. Any other question appears in the panel, including+a SolidCraft tool an agent words differently and a SolidCraft MCP server you added to the agent+yourself. With **Allow everything**, or after **Always allow**, those questions are answered the+same way and noted too.What counts as "a command given a file name": a parameter that holds a file or folder (`file`,`dir`, `output`, …), or `path` and `source` when the value reads like a file name (a separator, `~`,