Make the automation runtime its own subsystem, with MCP as one front end

Everything that drives OrcaSlicer by command (the dispatch of the command
catalog, jobs, the journal, replays, Python scripts, recordings) lived
inside the MCP server's service class. So Action Replay, the Run Script
panel, a plugin's tool call, a person's recording and a run from the
command line each had to start "the MCP service", with all of its GUI
hooks, although none of them needs a server or an agent.

The automation runtime is now a subsystem of its own. It starts the first
time a front end asks for it and knows none of them. The MCP endpoint
(HTTP, the protocol, the token, the discovery file, the takeover of a port
another window holds) is one front end beside the others, opened and
closed without stopping what the others run. The widget inspector, menu
capture and ImGui item recording are turned on only by a front end that
drives the GUI, so a person's recording or long command does not carry
them.

The part of the runtime that needs no GUI is the library
libslic3r_automation, built without wxWidgets and tested by its own suite,
automation_tests. A wx dependency in it fails to build, and its tests no
longer link the GUI library or the embedded Python.

The command line has one option set for this: --run FILE runs a replay or
a Python script once the GUI is ready, with --outputdir for its files, and
--unrestricted-scripts and --cad turn their settings on for one run
without saving them. --mcp-run, --mcp-run-out and --mcp-token are gone;
the scripts setting is python_scripts_unrestricted and a session's output
folder is <datadir>/automation/out. get_app_state reports ready and
version at the top level, and its mcp block describes the endpoint only.

No change to slicing output.
This commit is contained in:
SoftFever committed 2026-11-14 23:41:01 +08:00
1 parent b4be9d8374
commit fece418ae0
147 files changed
+7575 -5288

No files matched your search

+23 -7
View File
@@ -168,8 +168,10 @@ using json = nlohmann::json;
#endif
#ifdef SLIC3R_GUI
#include "slic3r/GUI/CommandCatalog.hpp"
#include "slic3r/GUI/GUI_Init.hpp"
#include "slic3r/GUI/Mcp/McpStdioBridge.hpp"
#include "slic3r/GUI/NativeCommands.hpp"
// BBLPrinterAgent::from_orca_filament_id(); the map and its lookups live in libslic3r_gui,
// which only a SLIC3R_GUI build links (see target_link_libraries(OrcaSlicer libslic3r_gui)
// in CMakeLists).
@@ -1223,7 +1225,9 @@ int CLI::run(int argc, char **argv)
// The stdio bridge is a plain pipe to a running GUI instance; it needs none of the setup below.
for (int i = 1; i < argc; ++i)
if (std::strcmp(argv[i], "--mcp-stdio") == 0)
return Slic3r::GUI::Mcp::run_stdio_bridge(argc, argv);
return Slic3r::GUI::Mcp::run_stdio_bridge(argc, argv, []() -> const Slic3r::GUI::CommandCatalog& {
return Slic3r::GUI::NativeCommands::instance();
});
#endif
#ifdef __WXGTK__
@@ -1490,6 +1494,14 @@ int CLI::run(int argc, char **argv)
}
bool start_gui = m_actions.empty() && !downward_check;
// --run runs its file in the GUI, so it is refused where no GUI starts rather than left unrun.
if (!start_gui && m_given_option_keys.count("run") > 0) {
std::string flag = m_actions.empty() ? std::string("downward_check") : m_actions.front();
std::replace(flag.begin(), flag.end(), '_', '-');
boost::nowide::cerr << "--run cannot be combined with --" << flag << std::endl;
record_exit_reson(outfile_dir, CLI_INVALID_PARAMS, 0, cli_errors[CLI_INVALID_PARAMS], sliced_info);
flush_and_exit(CLI_INVALID_PARAMS);
}
if (start_gui) {
BOOST_LOG_TRIVIAL(info) << "no action, start gui directly" << std::endl;
#ifdef SLIC3R_GUI
@@ -1534,17 +1546,21 @@ int CLI::run(int argc, char **argv)
//BBS: remove GCodeViewer as separate APP logic
//params.start_as_gcodeviewer = start_as_gcodeviewer;
// --mcp-port opens the endpoint as --mcp does, whatever its value. Every option has a value after setup(),
// so whether it was given is read from the options the command line named.
if (const auto *opt = m_config.opt<ConfigOptionBool>("mcp"))
params.mcp.enable = opt->value;
if (m_given_option_keys.count("mcp_port") > 0)
params.mcp.enable = true;
if (const auto *opt = m_config.opt<ConfigOptionInt>("mcp_port"))
params.mcp.port = opt->value;
if (const auto *opt = m_config.opt<ConfigOptionString>("mcp_token"))
params.mcp.token = opt->value;
// Resolved now: the GUI moves the working directory to <data_dir>/log before the replay or script runs.
if (const auto *opt = m_config.opt<ConfigOptionString>("mcp_run"))
params.mcp.run_file = resolve_cli_input_path(opt->value);
if (const auto *opt = m_config.opt<ConfigOptionString>("mcp_run_out"))
params.mcp.run_out = resolve_cli_input_path(opt->value);
if (m_given_option_keys.count("run") > 0) {
params.mcp.run_file = resolve_cli_input_path(m_config.opt_string("run"));
params.mcp.run_out = resolve_cli_input_path(m_config.opt_string("outputdir"));
}
params.unrestricted_scripts = m_config.opt_bool("unrestricted_scripts");
params.cad = m_config.opt_bool("cad");
BOOST_LOG_TRIVIAL(info) << "begin to launch OrcaSlicer GUI soon";
return Slic3r::GUI::GUI_Run(params);