Regroup the slicer's MCP commands and let each run from its arguments

Outside the Design tab an agent had 175 commands, 50 of them in the tool
list. There are now 118, named by what they act on (`object_`, `plate_`,
`preset_`, `filament_`, `plugin_` and so on), and 115 are listed. Each takes
its target and values in the call, acts on the selection when it names no
target and says what it acted on; an old name is refused. Printers and
system filaments install and uninstall, preferences read and write, plugins
enable, reload, uninstall and refresh, and objects reorder, with no dialog
to drive.

The Speed Dial keeps its 129 tiles under the same ids. Eight defects in the
rows these commands share with the menus are fixed. For a person: an object
row that cannot run says why instead of "Select an object first.", rows
that failed no longer claim success, Duplicate Plate can be undone, and
Refresh Plugins picked while a refresh runs now runs after it instead of
beside it.
This commit is contained in:
SoftFever committed 2026-11-18 16:50:32 +08:00
1 parent 74c98e197c
commit d64e10f4dd
287 files changed
+40484 -16770

No files matched your search

+49 -49
View File
@@ -235,7 +235,7 @@ TEST_CASE("code run from a file sees the file's path as __file__, and code under
REQUIRE(from_file.status == "finished");
CHECK(from_file.result == json{{"file", path}, {"name", "__main__"}});
const PythonRunOutcome from_name = run_file("<run_script>", code);
const PythonRunOutcome from_name = run_file("<script_run>", code);
REQUIRE(from_name.status == "finished");
CHECK(from_name.result["file"].is_null());
}
@@ -600,7 +600,7 @@ TEST_CASE("a script that raises reports the exception and its traceback", "[Pyth
const PythonRunOutcome out = run("print('before')\nraise ValueError('x')");
CHECK(out.status == "raised");
CHECK(out.message == "ValueError: x");
CHECK_THAT(out.traceback, ContainsSubstring("<run_script>"));
CHECK_THAT(out.traceback, ContainsSubstring("<script_run>"));
CHECK_THAT(out.traceback, ContainsSubstring("ValueError: x"));
CHECK(out.output == "before\n");
@@ -727,7 +727,7 @@ TEST_CASE("a restricted script's file run reads its own folder and writes nothin
namespace {
// Answers tool calls as the MCP core would for a run: get_app_state and run_replay succeed, anything else is
// Answers tool calls as the MCP core would for a run: app_state and replay_run succeed, anything else is
// an error.
struct FakeBridge : ToolBridge
{
@@ -757,11 +757,11 @@ struct FakeBridge : ToolBridge
if (hook)
if (std::optional<json> answer = hook(tool, args))
return *answer;
if (tool == "get_app_state")
if (tool == "app_state")
return json{{"ready", true}, {"args", args}};
if (tool == "run_replay")
if (tool == "replay_run")
return json{{"passed", true}};
throw ToolCallError("Unknown tool: " + tool, json{{"did_you_mean", {"get_app_state"}}});
throw ToolCallError("Unknown tool: " + tool, json{{"did_you_mean", {"app_state"}}});
}
};
@@ -777,7 +777,7 @@ TEST_CASE("a script calls tools through its run's bridge, and an error result ra
ScopedToolBridge bound(bridge);
const PythonRunOutcome out = run(R"PY(
import orca
state = orca.host.tools.call("get_app_state", {"verbose": True})
state = orca.host.tools.call("app_state", {"verbose": True})
try:
orca.host.tools.call("no_such_tool")
error = None
@@ -788,11 +788,11 @@ result = {"state": state, "error": error}
REQUIRE(out.status == "finished");
CHECK(out.result["state"] == json{{"ready", true}, {"args", {{"verbose", true}}}});
CHECK(out.result["error"]["message"] == "Unknown tool: no_such_tool");
CHECK(out.result["error"]["details"] == json{{"did_you_mean", {"get_app_state"}}});
CHECK(bridge.calls == std::vector<std::string>{"get_app_state", "no_such_tool"});
CHECK(out.result["error"]["details"] == json{{"did_you_mean", {"app_state"}}});
CHECK(bridge.calls == std::vector<std::string>{"app_state", "no_such_tool"});
}
TEST_CASE("a script hands run_replay a script given as JSON text as it is, with its vars", "[PythonScript][Python]")
TEST_CASE("a script hands replay_run a script given as JSON text as it is, with its vars", "[PythonScript][Python]")
{
RunnerHarness harness;
if (!harness.initialized)
@@ -802,13 +802,13 @@ TEST_CASE("a script hands run_replay a script given as JSON text as it is, with
ScopedToolBridge bound(bridge);
const PythonRunOutcome out = run(R"PY(
import orca
text = '{"orca_replay_version": "0.1.0", "steps": []} // replayed'
text = '{"orca_replay_version": "0.2.0", "steps": []} // replayed'
result = orca.host.tools.run_replay(text, {"part": "lid"})
)PY");
REQUIRE(out.status == "finished");
CHECK(out.result == json{{"passed", true}});
CHECK(bridge.calls == std::vector<std::string>{"run_replay"});
CHECK(bridge.last_args == json{{"replay", R"({"orca_replay_version": "0.1.0", "steps": []} // replayed)"}, {"vars", {{"part", "lid"}}}});
CHECK(bridge.calls == std::vector<std::string>{"replay_run"});
CHECK(bridge.last_args == json{{"replay", R"({"orca_replay_version": "0.2.0", "steps": []} // replayed)"}, {"vars", {{"part", "lid"}}}});
}
TEST_CASE("a run waits for the non-daemon threads it starts, which call tools through it", "[PythonScript][Python]")
@@ -820,10 +820,10 @@ TEST_CASE("a run waits for the non-daemon threads it starts, which call tools th
FakeBridge bridge;
ScopedToolBridge bound(bridge);
const PythonRunOutcome out = run("import orca, threading, time\n"
"def work():\n time.sleep(0.2)\n orca.host.tools.call('get_app_state')\n"
"def work():\n time.sleep(0.2)\n orca.host.tools.call('app_state')\n"
"threading.Thread(target=work).start()\n");
CHECK(out.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
}
TEST_CASE("a run on a thread Python didn't start waits for the threads it starts", "[PythonScript][Python]")
@@ -838,12 +838,12 @@ TEST_CASE("a run on a thread Python didn't start waits for the threads it starts
std::thread job([&] {
ScopedToolBridge bound(bridge);
out = run("import orca, threading, time\n"
"def work(orca=orca, time=time):\n time.sleep(0.2)\n orca.host.tools.call('get_app_state')\n"
"def work(orca=orca, time=time):\n time.sleep(0.2)\n orca.host.tools.call('app_state')\n"
"threading.Thread(target=work).start()\n");
});
job.join();
CHECK(out.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
}
TEST_CASE("a thread started just before the code returns is waited for", "[PythonScript][Python]")
@@ -855,9 +855,9 @@ TEST_CASE("a thread started just before the code returns is waited for", "[Pytho
FakeBridge bridge;
ScopedToolBridge bound(bridge);
CHECK(run("import orca, threading\n"
"threading.Thread(target=lambda: orca.host.tools.call('get_app_state')).start()\n")
"threading.Thread(target=lambda: orca.host.tools.call('app_state')).start()\n")
.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
}
TEST_CASE("a thread started by another of the run's threads after the code returned is waited for", "[PythonScript][Python]")
@@ -869,11 +869,11 @@ TEST_CASE("a thread started by another of the run's threads after the code retur
FakeBridge bridge;
ScopedToolBridge bound(bridge);
CHECK(run("import orca, threading, time\n"
"def second():\n time.sleep(0.3)\n orca.host.tools.call('get_app_state')\n"
"def second():\n time.sleep(0.3)\n orca.host.tools.call('app_state')\n"
"def first():\n time.sleep(0.3)\n threading.Thread(target=second).start()\n"
"threading.Thread(target=first).start()\n")
.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
}
TEST_CASE("a callback already running when the code returns is waited for, and the thread it starts too", "[PythonScript][Python]")
@@ -902,14 +902,14 @@ TEST_CASE("a callback already running when the code returns is waited for, and t
if (!run_scope->callback_entering())
return;
py_run("import orca, threading, time, _cb\n_cb.entered.set()\ntime.sleep(0.3)\n"
"threading.Thread(target=lambda: orca.host.tools.call('get_app_state')).start()\n");
"threading.Thread(target=lambda: orca.host.tools.call('app_state')).start()\n");
run_scope->callback_left();
});
};
const PythonRunOutcome out = run("import orca, _cb\norca.host.tools.call('capture_run')\n_cb.entered.wait(10)\n");
callback.join();
CHECK(out.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"capture_run", "get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"capture_run", "app_state"});
}
TEST_CASE("a raw thread can't start a thread after its run has ended", "[PythonScript][Python]")
@@ -940,10 +940,10 @@ TEST_CASE("a script that exits with sys.exit(0) still waits for its threads", "[
FakeBridge bridge;
ScopedToolBridge bound(bridge);
CHECK(run("import orca, sys, threading, time\n"
"def work():\n time.sleep(0.2)\n orca.host.tools.call('get_app_state')\n"
"def work():\n time.sleep(0.2)\n orca.host.tools.call('app_state')\n"
"threading.Thread(target=work).start()\nsys.exit(0)\n")
.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
}
TEST_CASE("a daemon thread still running after its run is refused tool calls", "[PythonScript][Python]")
@@ -956,7 +956,7 @@ TEST_CASE("a daemon thread still running after its run is refused tool calls", "
FakeBridge bridge;
ScopedToolBridge bound(bridge);
REQUIRE(run("import orca, threading, _late\n"
"def work(orca=orca, late=_late):\n late.go.wait(10)\n try:\n orca.host.tools.call('get_app_state')\n"
"def work(orca=orca, late=_late):\n late.go.wait(10)\n try:\n orca.host.tools.call('app_state')\n"
" except RuntimeError as e:\n late.error = str(e)\n late.done.set()\n"
"threading.Thread(target=work, daemon=True).start()\n")
.status == "finished");
@@ -982,7 +982,7 @@ TEST_CASE("a tool call in flight when the run ends finishes before the run does"
ScopedToolBridge bound(bridge);
const auto start = std::chrono::steady_clock::now();
REQUIRE(run("import orca, threading, _late\n"
"def work(orca=orca, late=_late):\n late.result = orca.host.tools.call('get_app_state')\n"
"def work(orca=orca, late=_late):\n late.result = orca.host.tools.call('app_state')\n"
"threading.Thread(target=work, daemon=True).start()\n_late.in_call.wait(10)\n")
.status == "finished");
CHECK(std::chrono::steady_clock::now() - start >= std::chrono::seconds(1));
@@ -1010,7 +1010,7 @@ TEST_CASE("a stop during the in-flight wait still ends the run as cancelled", "[
int stops = 0;
PythonRunRequest request;
request.code = "import orca, threading, _late\n"
"threading.Thread(target=lambda: orca.host.tools.call('get_app_state'), daemon=True).start()\n"
"threading.Thread(target=lambda: orca.host.tools.call('app_state'), daemon=True).start()\n"
"_late.in_call.wait(10)\n";
request.identity = kScriptIdentityAgent;
request.budget = by_budget ? std::chrono::milliseconds(1000) : std::chrono::minutes(1);
@@ -1048,13 +1048,13 @@ TEST_CASE("a task the run submits is waited for and runs inside the run", "[Pyth
"pool = libpool_task.POOL\n";
const std::string code = "import orca, time, _kept\n" + make +
"_kept.pool = pool\n"
"def task():\n time.sleep(0.3)\n orca.host.tools.call('get_app_state')\n"
"def task():\n time.sleep(0.3)\n orca.host.tools.call('app_state')\n"
"pool.submit(task)\n";
FakeBridge bridge;
ScopedToolBridge bound(bridge);
const PythonRunOutcome out = run_file(macro.write("main.py", code), code, std::chrono::seconds(20));
CHECK(out.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
CHECK(shared.get("pool._shutdown") == (where != "library"));
if (where == "library") {
CHECK(py_json("__import__('_kept').pool.submit(int, '3').result()") == 3);
@@ -1078,11 +1078,11 @@ TEST_CASE("a pool worker another run started runs this run's task inside this ru
}
{
ScopedToolBridge bound(bridge_b);
REQUIRE(run("import orca, _kept\n_kept.pool.submit(lambda: orca.host.tools.call('get_app_state')).result()\n").status ==
REQUIRE(run("import orca, _kept\n_kept.pool.submit(lambda: orca.host.tools.call('app_state')).result()\n").status ==
"finished");
}
CHECK(bridge_a.calls.empty());
CHECK(bridge_b.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge_b.calls == std::vector<std::string>{"app_state"});
py_run("import _kept\n_kept.pool.shutdown()\n");
}
@@ -1171,11 +1171,11 @@ TEST_CASE("a task's done callbacks run inside the run that submitted it, and it
shared.set("release");
});
const PythonRunOutcome out = run("import orca, time, _cb\n"
"def cb(future):\n time.sleep(0.3)\n print('callback ran')\n orca.host.tools.call('get_app_state')\n"
"def cb(future):\n time.sleep(0.3)\n print('callback ran')\n orca.host.tools.call('app_state')\n"
"_cb.pool.submit(_cb.release.wait, 10).add_done_callback(cb)\n");
releaser.join();
CHECK(out.status == "finished");
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
CHECK_THAT(out.output, ContainsSubstring("callback ran"));
py_run("import _cb\n_cb.pool.shutdown()\n");
}
@@ -1268,12 +1268,12 @@ TEST_CASE("a pool's initializer runs inside the run that started its worker", "[
FakeBridge bridge;
ScopedToolBridge bound(bridge);
const PythonRunOutcome out = run("import orca\nfrom concurrent.futures import ThreadPoolExecutor\n"
"def init():\n print('init ran')\n orca.host.tools.call('get_app_state')\n"
"def init():\n print('init ran')\n orca.host.tools.call('app_state')\n"
"pool = ThreadPoolExecutor(1, initializer=init)\nresult = pool.submit(int, '5').result(10)\n");
CHECK(out.status == "finished");
CHECK(out.result == 5);
CHECK_THAT(out.output, ContainsSubstring("init ran"));
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
}
TEST_CASE("a pool's initializer in a plugin's run runs under the plugin's identity", "[PythonScript][Python]")
@@ -1311,13 +1311,13 @@ TEST_CASE("a run waits for a pool's initializer whose task it cancelled", "[Pyth
});
const PythonRunOutcome out = run("import orca, _ini\nfrom concurrent.futures import ThreadPoolExecutor\n"
"def init():\n _ini.entered.set()\n _ini.go.wait(10)\n print('init done')\n"
" orca.host.tools.call('get_app_state')\n"
" orca.host.tools.call('app_state')\n"
"pool = ThreadPoolExecutor(1, initializer=init)\nf = pool.submit(int)\n_ini.entered.wait(10)\n"
"cancelled = f.cancel()\n");
releaser.join();
CHECK(out.status == "finished");
CHECK_THAT(out.output, ContainsSubstring("init done"));
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
}
TEST_CASE("a thread of an ended run can't start a pool worker whose initializer would run outside it", "[PythonScript][Python]")
@@ -1471,9 +1471,9 @@ TEST_CASE("an untagged pool is still a pool to a run", "[PythonScript][Python]")
FakeBridge bridge;
ScopedToolBridge bound(bridge);
const auto start = std::chrono::steady_clock::now();
CHECK(run("import orca, _kept\n_kept.pool.submit(lambda: orca.host.tools.call('get_app_state'))\n").status == "finished");
CHECK(run("import orca, _kept\n_kept.pool.submit(lambda: orca.host.tools.call('app_state'))\n").status == "finished");
CHECK(std::chrono::steady_clock::now() - start < std::chrono::seconds(5));
CHECK(bridge.calls == std::vector<std::string>{"get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"app_state"});
py_run("import _kept\n_kept.pool.shutdown()\n");
}
@@ -1759,7 +1759,7 @@ TEST_CASE("a window callback of a run is refused tool calls", "[PythonScript][Py
ScopedPythonRun in_run(scope, PythonRunThread::Callback);
PythonGILState gil;
py::dict ns;
py::exec("import orca\ntry:\n orca.host.tools.call('get_app_state')\n error = None\nexcept RuntimeError as e:\n error = str(e)\n", ns);
py::exec("import orca\ntry:\n orca.host.tools.call('app_state')\n error = None\nexcept RuntimeError as e:\n error = str(e)\n", ns);
CHECK_THAT(ns["error"].cast<std::string>(), ContainsSubstring("window callbacks"));
CHECK(bridge.calls.empty());
}
@@ -1846,10 +1846,10 @@ import orca, threading, _cb
def on_message(data):
_cb.storage = orca.host.plugin.storage()
try:
orca.host.tools.call("get_app_state")
orca.host.tools.call("app_state")
except RuntimeError as e:
_cb.refused = str(e)
worker = threading.Thread(target=lambda: orca.host.tools.call("get_app_state"))
worker = threading.Thread(target=lambda: orca.host.tools.call("app_state"))
worker.start()
worker.join()
_cb.done.set()
@@ -1861,7 +1861,7 @@ _cb.done.wait(10)
delivery.join();
CHECK(utf8_path(shared.get("storage").get<std::string>()) == macro.dir);
CHECK_THAT(shared.get("refused").get<std::string>(), ContainsSubstring("window callbacks"));
CHECK(bridge.calls == std::vector<std::string>{"take_callback", "get_app_state"});
CHECK(bridge.calls == std::vector<std::string>{"take_callback", "app_state"});
}
TEST_CASE("a run's callbacks do nothing and its threads open no UI once its UI is closed", "[PythonScript][Python]")
@@ -1955,7 +1955,7 @@ TEST_CASE("orca.host.tools refuses code that is neither a plugin nor a script",
// Code with no audit identity: a plugin window's callback today.
PythonRunRequest request;
request.code = "import orca\ntry:\n orca.host.tools.call('get_app_state')\n result = 'called'\nexcept RuntimeError as e:\n result = str(e)";
request.code = "import orca\ntry:\n orca.host.tools.call('app_state')\n result = 'called'\nexcept RuntimeError as e:\n result = str(e)";
request.identity = "";
const PythonRunOutcome out = run_python_code(request);
REQUIRE(out.status == "finished");
@@ -2055,7 +2055,7 @@ TEST_CASE("a plugin calls tools only from a thread that may wait for the UI thre
return json{{"plugin", plugin}};
});
PythonRunRequest request;
request.code = "import orca\ntry:\n result = orca.host.tools.call('get_app_state')\n"
request.code = "import orca\ntry:\n result = orca.host.tools.call('app_state')\n"
"except RuntimeError as e:\n result = str(e)";
request.identity = "measure";
@@ -2071,7 +2071,7 @@ TEST_CASE("a plugin calls tools only from a thread that may wait for the UI thre
REQUIRE(called.status == "finished");
CHECK(called.result == json{{"plugin", "measure"}});
}
CHECK(calls == std::vector<std::string>{"measure:get_app_state"});
CHECK(calls == std::vector<std::string>{"measure:app_state"});
set_plugin_tool_caller({});
}
@@ -2294,7 +2294,7 @@ struct HostedSession
std::thread host;
std::atomic<bool> returned{false};
static PythonSessionRequest person_session(std::string filename = "<run_script>")
static PythonSessionRequest person_session(std::string filename = "<script_run>")
{
PythonSessionRequest request;
request.identity = kScriptIdentityPerson;
@@ -2474,7 +2474,7 @@ TEST_CASE("a cell ending in an expression shows its value, and so does a file ru
CHECK(file.finished->status == "finished");
CHECK(file.output() == "2\n");
const PythonRunOutcome agent = run_file("<run_script>", "1 + 1\n[1, 2]\n");
const PythonRunOutcome agent = run_file("<script_run>", "1 + 1\n[1, 2]\n");
CHECK(agent.status == "finished");
CHECK(agent.output.empty());
}