diff --git a/apps/texturecraft-cli/src/main.rs b/apps/texturecraft-cli/src/main.rs index ec1e4f2d..b03174c1 100644 --- a/apps/texturecraft-cli/src/main.rs +++ b/apps/texturecraft-cli/src/main.rs @@ -38,7 +38,8 @@ USAGE: New project; --sample bakes and applies a smart material to every texture set. texturecraft-cli mcp [--bridge ] [--token ] [--read-root ] [--write-root ] MCP server on stdio: headless (file access only below the roots), or bridged to - `texturecraft --control `. + `texturecraft --control `. --automation-read-root / --automation-write-root are + the same as --read-root / --write-root (mcp and serve). texturecraft-cli serve [--port ] [--read-root ] [--write-root ] JSON lines ({\"id\",\"method\",\"params\"}) on stdio, or on 127.0.0.1: with a token. @@ -57,8 +58,8 @@ const SUBCOMMANDS: &[(&str, &[&str], &[&str])] = &[ ("export", &["--preset", "--format", "--padding", "--size"], &[]), ("render", &["--size", "--view", "--camera", "--yaw", "--pitch", "--samples", "--bounces"], &["--cpu"]), ("new", &["--resolution"], &["--sample"]), - ("mcp", &["--bridge", "--token", "--read-root", "--write-root"], &[]), - ("serve", &["--port", "--read-root", "--write-root"], &[]), + ("mcp", &["--bridge", "--token", "--read-root", "--write-root", "--automation-read-root", "--automation-write-root"], &[]), + ("serve", &["--port", "--read-root", "--write-root", "--automation-read-root", "--automation-write-root"], &[]), ]; struct Args { @@ -367,7 +368,9 @@ fn new(a: &Args) -> R { } fn workspace(a: &Args) -> Result { - let (r, w) = (a.get("--read-root").map(Path::new), a.get("--write-root").map(Path::new)); + // `--automation-*-root` is the spelling the other crafting apps use. + let root = |k: &str| a.get(&format!("--automation-{k}")).or_else(|| a.get(&format!("--{k}"))).map(Path::new); + let (r, w) = (root("read-root"), root("write-root")); if r.is_none() && w.is_none() { return Ok(Filesystem::Denied); } diff --git a/apps/texturecraft-cli/tests/cli.rs b/apps/texturecraft-cli/tests/cli.rs index 254eabb4..7232e2b7 100644 --- a/apps/texturecraft-cli/tests/cli.rs +++ b/apps/texturecraft-cli/tests/cli.rs @@ -97,6 +97,24 @@ fn info_on_a_mesh_reports_uvs() { let _ = std::fs::remove_dir_all(&d); } +#[test] +fn serve_takes_the_automation_root_spelling_too() { + use std::io::Write as _; + let d = tmp("automation-root"); + let mut child = Command::new(env!("CARGO_BIN_EXE_texturecraft-cli")) + .args(["serve", "--automation-write-root", p(&d)]) + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap(); + child.stdin.take().unwrap().write_all(b"{\"id\":1,\"method\":\"project.save\",\"params\":{\"path\":\"a.tcraft\"}}\n").unwrap(); + let out = child.wait_with_output().unwrap(); + let reply: Value = serde_json::from_slice(&out.stdout).unwrap(); + assert_eq!(reply["ok"], true, "{reply}"); + assert!(d.join("a.tcraft").is_file()); + let _ = std::fs::remove_dir_all(&d); +} + #[test] fn render_writes_a_png() { let d = tmp("render"); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 14dd6de4..3123ce2e 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -100,7 +100,9 @@ print(call("command.run", {"id": "layer.add.fill", "params": {"color": [0.8, 0.1 - **Headless** (default): an in-process session that starts on the material ball (1024). Files are reachable only below the roots given at launch, as forward-slash paths relative to them: `--read-root ` for `project_open` / `mesh_import` / `mesh_reimport` / `bake_mesh_add`, - `--write-root ` for `project_save` / `material_save` / `textures_export` / `mesh_export`. Without roots there is no file access. `..`, absolute + `--write-root ` for `project_save` / `material_save` / `textures_export` / `mesh_export` + (`--automation-read-root` / `--automation-write-root`, as in the other crafting apps, are the + same flags). Without roots there is no file access. `..`, absolute paths, drive letters, device names and symlink or junction escapes are refused. - **Bridge**: `--bridge ` forwards to a running `texturecraft --control ` (token from `--token`, `TEXTURECRAFT_CONTROL_TOKEN` or the app's token file). The app reads and writes its