diff --git a/.claude/skills/orca-mcp/SKILL.md b/.claude/skills/orca-mcp/SKILL.md index 22eb9392da..d1242a8020 100644 --- a/.claude/skills/orca-mcp/SKILL.md +++ b/.claude/skills/orca-mcp/SKILL.md @@ -18,6 +18,9 @@ Build Release (`cmake --build build --config Release --target all --` on Linux), tools/mcp/orca_mcp.py launch --xvfb --print-config ``` +On Windows, build with `build_win.bat` and run `python tools/mcp/orca_mcp.py launch --print-config` +(there is no `--xvfb`); it finds `build-clang\src\Release\orca-slicer.exe` too. + `launch` starts `build/src/Release/orca-slicer` (or `--bin PATH`) with `--mcp` and a fresh temporary datadir. The datadir is seeded with a finished setup wizard and one printer, Bambu Lab X1 Carbon 0.4 by default. To use another printer, pass @@ -103,7 +106,8 @@ You can talk to the app in two ways: - **`blocked_by_dialog`** lists the dialog's `title`, `message` and `buttons`. Answer it with `dialog_respond`, then wait for the job. A dialog marked `native: true` (message boxes, file pickers) can't be clicked, so register `dialog_auto_answer` before the step that opens it, or use - a typed tool that needs no dialog. In a script, put `dialog_auto_answer` first. + a typed tool that needs no dialog. In a script, put `dialog_auto_answer` first. A file picker's + text is its prompt, such as "Choose one or more files", not the name of the menu item that opened it. - "A modal dialog is open; answer it first" means `get_state.dialogs` lists what is in the way. - While a slice or G-code export runs, other changes are refused. `wait` for it, or `cancel` it. - Before a screenshot after arrange, orient or anything else that runs in the background, call @@ -168,3 +172,10 @@ lets a step fail without stopping the run. - When launching by hand on a fresh datadir, set `SSL_CERT_FILE` (the harness does), or a CA-bundle prompt blocks startup. - Testing in the Fedora or Debian VMs follows the machine's own notes and is not covered here. + +## Windows notes + +- `window` and `dialog` screenshots come from `PrintWindow`, so they are exact even when other + windows cover OrcaSlicer, web views and the 3D views included. A minimized window can't be captured. +- The app takes the foreground for a moment while it starts, so keystrokes typed elsewhere then can + reach it. The GUI tools synthesize their input inside the app and never move the real pointer. diff --git a/tools/mcp/README.md b/tools/mcp/README.md index ac9e5c486c..ac140a97c5 100644 --- a/tools/mcp/README.md +++ b/tools/mcp/README.md @@ -21,8 +21,10 @@ an `OrcaSlicer.conf` that has a finished setup wizard and one printer and filame Carbon 0.4 by default), with update checks and daily tips turned off. The token comes from `ORCA_MCP_TOKEN` or is generated, and it reaches the app through the environment, not the command line. On Linux, `launch` also sets `SSL_CERT_FILE`, so a fresh datadir doesn't prompt for a CA -bundle. `--xvfb` starts Xvfb on a free display between `:90` and `:119`, with -`--width`×`--height` (default 1600×1000), and sets `GDK_BACKEND=x11`. Xvfb runs with `-noreset`, +bundle. On Windows, it gives the instance its own WebView2 profile in the datadir, apart from the one +your own OrcaSlicer uses, and finds `build-clang\src\Release\orca-slicer.exe` as well; run the +commands as `python tools/mcp/orca_mcp.py …`. `--xvfb` starts Xvfb on a free display between `:90` +and `:119`, with `--width`×`--height` (default 1600×1000), and sets `GDK_BACKEND=x11`. Xvfb runs with `-noreset`, and its pointer is parked in the bottom-right corner. In the middle of the screen, the pointer would raise tooltips over whatever opens there, and they would show in screenshots. The app's output goes to `/mcp-launch.log`. `--timeout` (default 120 s) limits how long `launch` waits for diff --git a/tools/mcp/orca_mcp.py b/tools/mcp/orca_mcp.py index 1b73c5ed1c..fa6ead5745 100644 --- a/tools/mcp/orca_mcp.py +++ b/tools/mcp/orca_mcp.py @@ -147,8 +147,10 @@ def find_binary(explicit): candidates = [explicit] if explicit else [] here = os.path.dirname(os.path.abspath(__file__)) repo = os.path.dirname(os.path.dirname(here)) - candidates += [os.path.join(repo, "build", "src", "Release", "orca-slicer"), - os.path.join(repo, "build", "package", "bin", "orca-slicer"), + exe = ".exe" if os.name == "nt" else "" + # build_win.bat names a clang-cl tree build-clang. + candidates += [os.path.join(repo, tree, "src", "Release", "orca-slicer" + exe) for tree in ("build", "build-clang")] + candidates += [os.path.join(repo, "build", "package", "bin", "orca-slicer"), shutil.which("orca-slicer") or ""] for c in candidates: if c and os.path.exists(c): @@ -168,6 +170,9 @@ def seed_datadir(datadir, printer): "filaments": [filament], "presets": {"machine": f"{model} {nozzle} nozzle"}, "app": {"check_for_updates": False, "show_daily_tips": False}}, f, indent=2) + # On Windows the loader expects a line after the closing brace, where it keeps a checksum, and + # fails to start the app when the file ends at the brace. + f.write("\n") def start_xvfb(width, height): @@ -235,6 +240,9 @@ def launch(args): if os.path.exists(bundle): env.setdefault("SSL_CERT_FILE", bundle) break + if os.name == "nt": + # The WebView2 profile otherwise lives in %LOCALAPPDATA%\OrcaSlicer, shared with the user's own OrcaSlicer. + env.setdefault("WEBVIEW2_USER_DATA_FOLDER", os.path.join(datadir, "webview2")) cmd = [find_binary(args.bin), "--datadir", datadir, "--mcp", "--mcp-port", str(args.port)] + args.extra log = open(os.path.join(datadir, "mcp-launch.log"), "w") proc = subprocess.Popen(cmd, env=env, stdout=log, stderr=subprocess.STDOUT, start_new_session=True) @@ -267,12 +275,13 @@ def session_client(): def stop(_args): _, s = session_client() + kill = os.kill if os.name == "nt" else os.killpg # Windows has no process groups to signal for key in ("pid", "xvfb_pid"): pid = s.get(key) if pid: try: - os.killpg(pid, signal.SIGTERM) - except ProcessLookupError: + kill(pid, signal.SIGTERM) + except OSError: # already gone pass os.remove(SESSION_FILE)