Skip to content

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

Agent chat: hand WSL paths to agents started through wsl.exe (#5546) (#5549)

ISHII YUKI34e75979b226
diff --git a/crates/ui-egui/src/agent_chat/acp.rs b/crates/ui-egui/src/agent_chat/acp.rs
index 96555942a8..fc8c0cb0ed 100644
--- a/crates/ui-egui/src/agent_chat/acp.rs
+++ b/crates/ui-egui/src/agent_chat/acp.rs
@@ -68,6 +68,36 @@ impl McpBridge {
"env": [],
})
}
+
+ /// The same bridge for an agent inside WSL: the CLI as WSL sees it. It still runs on the
+ /// Windows side (WSL starts Windows programs itself), so the port is the same.
+ pub fn in_wsl(&self) -> McpBridge {
+ McpBridge { cli: wsl_path(&self.cli), port: self.port }
+ }
+}
+
+/// The agent runs inside WSL: its program is `wsl` or `wsl.exe` (any case, with or without a
+/// folder). Such an agent can't use Windows paths, so the session hands it [`wsl_path`]s (#5546).
+pub fn runs_in_wsl(argv: &[String]) -> bool {
+ argv.first().is_some_and(|program| {
+ let name = program.rsplit(['\\', '/']).next().unwrap_or(program);
+ name.eq_ignore_ascii_case("wsl") || name.eq_ignore_ascii_case("wsl.exe")
+ })
+}
+
+/// A Windows drive path as WSL shows it under its default mount root: `C:\Users\u` is
+/// `/mnt/c/Users/u`. Anything else (a UNC share, a path already in that form) is kept.
+pub fn wsl_path(path: &std::path::Path) -> std::path::PathBuf {
+ let text = path.to_string_lossy();
+ let text = text.strip_prefix(r"\\?\").unwrap_or(&text);
+ let mut chars = text.chars();
+ match (chars.next(), chars.next(), chars.next()) {
+ (Some(drive), Some(':'), Some('\\' | '/') | None) if drive.is_ascii_alphabetic() => {
+ let rest: String = chars.map(|c| if c == '\\' { '/' } else { c }).collect();
+ format!("/mnt/{}/{rest}", drive.to_ascii_lowercase()).into()
+ }
+ _ => path.to_path_buf(),
+ }
}
/// What every session is told about where it is. Agents that don't read `_meta` ignore it.
@@ -513,6 +543,32 @@ mod tests {
assert_eq!(session_new_params(std::path::Path::new("/tmp"), None)["mcpServers"], json!([]));
}
+ /// #5546: an agent started through `wsl.exe` gets the session's paths as WSL shows them.
+ #[test]
+ fn an_agent_inside_wsl_gets_wsl_paths() {
+ let argv = |line: &str| split_command(line);
+ assert!(runs_in_wsl(&argv("wsl.exe -d Ubuntu -e bash -lc claude-agent-acp")));
+ assert!(runs_in_wsl(&argv("WSL claude-agent-acp")));
+ assert!(runs_in_wsl(&argv(r#""C:\Windows\System32\wsl.exe" -e claude-agent-acp"#)));
+ assert!(!runs_in_wsl(&argv("claude-agent-acp")));
+ assert!(!runs_in_wsl(&argv("wslconfig /l")));
+ assert!(!runs_in_wsl(&[]));
+
+ let wsl = |p: &str| wsl_path(std::path::Path::new(p)).to_string_lossy().into_owned();
+ assert_eq!(wsl(r"C:\Users\u\AppData\Local\SolidCraft\agent-chat\work"), "/mnt/c/Users/u/AppData/Local/SolidCraft/agent-chat/work");
+ assert_eq!(wsl(r"\\?\D:\Program Files\SolidCraft\solidcraft-cli.exe"), "/mnt/d/Program Files/SolidCraft/solidcraft-cli.exe");
+ assert_eq!(wsl("E:/designs"), "/mnt/e/designs");
+ assert_eq!(wsl("C:"), "/mnt/c/");
+ assert_eq!(wsl("/home/u/designs"), "/home/u/designs");
+ assert_eq!(wsl(r"\\server\share\x"), r"\\server\share\x");
+
+ let b = McpBridge { cli: r"C:\Program Files\SolidCraft\solidcraft-cli.exe".into(), port: 41234 };
+ let p = session_new_params(&wsl_path(std::path::Path::new(r"C:\Users\u\work")), Some(&b.in_wsl()));
+ assert_eq!(p["cwd"], "/mnt/c/Users/u/work");
+ assert_eq!(p["mcpServers"][0]["command"], "/mnt/c/Program Files/SolidCraft/solidcraft-cli.exe");
+ assert_eq!(p["mcpServers"][0]["args"], json!(["mcp", "--connect", "127.0.0.1:41234"]));
+ }
+
#[test]
fn auth_methods_of_both_adapters_are_read() {
// As the Claude adapter offers them to a client with terminal login.
diff --git a/crates/ui-egui/src/agent_chat/acp_client.rs b/crates/ui-egui/src/agent_chat/acp_client.rs
index 82918e90fd..730c0cf0cc 100644
--- a/crates/ui-egui/src/agent_chat/acp_client.rs
+++ b/crates/ui-egui/src/agent_chat/acp_client.rs
@@ -46,10 +46,13 @@ impl AcpBackend {
pub fn start(argv: &[String], ctx: StartContext) -> Result<AcpBackend, String> {
let wake = ctx.wake;
let proc = AgentProcess::spawn(argv, &ctx.cwd, ENV_REMOVE, wake)?;
+ // An agent inside WSL is told the same folder and bridge as WSL shows them (#5546).
+ let (cwd, bridge) =
+ if acp::runs_in_wsl(argv) { (acp::wsl_path(&ctx.cwd), ctx.bridge.as_ref().map(acp::McpBridge::in_wsl)) } else { (ctx.cwd, ctx.bridge) };
let mut b = AcpBackend {
proc,
- cwd: ctx.cwd,
- bridge: ctx.bridge,
+ cwd,
+ bridge,
next_id: 0,
pending: HashMap::new(),
session: None,
@@ -257,8 +260,9 @@ pub fn test_agent(argv: &[String], cwd: &std::path::Path) -> Result<String, Stri
};
p.send(&acp::request(1, "initialize", acp::initialize_params(env!("CARGO_PKG_VERSION"))));
let init = wait_for(&p, 1);
+ let session_cwd = if acp::runs_in_wsl(argv) { acp::wsl_path(cwd) } else { cwd.to_path_buf() };
let result = init.and_then(|v| {
- p.send(&acp::request(2, "session/new", acp::session_new_params(cwd, None)));
+ p.send(&acp::request(2, "session/new", acp::session_new_params(&session_cwd, None)));
wait_for(&p, 2).map(|_| {
let who = acp::agent_info(&v);
crate::i18n::format("ui.ai_test_acp_ok", &[("agent", if who.is_empty() { "?" } else { &who })])
diff --git a/docs/agent-chat.md b/docs/agent-chat.md
index ec1608934b..a1c8eeda8c 100644
--- a/docs/agent-chat.md
+++ b/docs/agent-chat.md
@@ -214,6 +214,22 @@ Grok Build also supports `XAI_API_KEY` for users who choose API authentication.
endpoint's entry under **Agents**, where a change applies from the next request. A request that
runs out of time ends the message with the limit it hit and where to raise it.
+### An agent inside WSL (Windows)
+
+An agent installed inside WSL keeps its own settings, skills and sign-in there. Add it as a
+**Custom command** that starts it through `wsl.exe`, for example:
+
+```
+wsl.exe -d Ubuntu -e bash -lc claude-agent-acp
+```
+
+`bash -lc` runs your login shell's setup, so the agent is found where your `PATH` puts it (npm,
+nvm, Volta). When the command's program is `wsl` or `wsl.exe`, SolidCraft gives the agent its
+working folder and the `solidcraft-app` server's program as WSL shows them (`C:\Users\…` becomes
+`/mnt/c/Users/…`). The server itself still runs on Windows and reaches the app at `127.0.0.1`, so
+this works with WSL's default networking. If you moved WSL's drive mounts away from `/mnt`
+(`automount.root` in `/etc/wsl.conf`), those paths won't match and the agent can't start the server.
+
## Signing in
If a coding agent isn't signed in, it says so and the panel shows **Sign in to the agent** with