prepare-agent-node-bundle.mjs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. #!/usr/bin/env node
  2. // 桌面打包态的 agent 运行时资产:把 agent 的 JS bundle(zcode.cjs)放进 bundled-agents/<platform>/glm,
  3. // 由 app 内置的 Electron Node runtime(ELECTRON_RUN_AS_NODE)执行,替代以前随包内置的独立 Node 二进制。
  4. //
  5. // 为什么这么做:
  6. // - agent 没有任何原生 NAPI 插件(ripgrep 是 WASM,其余纯 JS),可直接跑在 Electron 的 Node 上;
  7. // - Electron 41 内置 Node 24.x,与 zcode-cli 的目标运行时一致;
  8. // - 单平台体积从 ~180MB 降到 ~16MB,且同一份 JS 跨平台通用;
  9. // - app-server 命令路径不会加载 @zcode/tui,所以这里天然不打包 TUI。
  10. //
  11. // 远端(SSH/WSL/Docker)没有 Electron,仍走 prepare:remote-assets 的原生二进制,互不影响。
  12. import { cpSync, existsSync, mkdirSync } from "node:fs";
  13. import { basename, dirname, resolve } from "node:path";
  14. import process from "node:process";
  15. import { fileURLToPath } from "node:url";
  16. import { runCommand } from "../../../scripts/spawn-command.mjs";
  17. import { stageAgentBundle } from "./stage-agent-bundle.mjs";
  18. import { isSharpRequiredByComputerUse, stageSharpIntoBundledAgents } from "./sharp-package-assets.mjs";
  19. import { stageKoffiIntoBundledAgents } from "./koffi-package-assets.mjs";
  20. const scriptDir = dirname(fileURLToPath(import.meta.url));
  21. const desktopRoot = resolve(scriptDir, "..");
  22. const repoRoot = resolve(desktopRoot, "..", "..");
  23. const cliBundlePath = resolve(repoRoot, "apps/zcode-cli/packages/cli/dist/zcode.cjs");
  24. const adaptersRoot = resolve(repoRoot, "apps/zcode-cli/packages/adapters");
  25. const pnpmRunEnv = {
  26. ...process.env,
  27. // pnpm 11 会在 apps/zcode-cli 子 workspace 执行 run 前触发 install;
  28. // 子 workspace 不能解析根 workspace 的 @zcode/shared,Docker/web app 打包会因此卡在插件 runtime 构建。
  29. PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN: "false",
  30. };
  31. const BROWSER_USE_PLUGIN_PACKAGE_NAME = "@zcode/browser-use-plugin";
  32. const NODE_REPL_HOST_PACKAGE_NAME = "@zcode/node-repl-host";
  33. const CUA_PLUGIN_PACKAGE_NAME = "@zcode/zcode-cua-plugin";
  34. // 平台目录命名:darwin/win32/linux + x64/arm64,
  35. // 支持 ZCODE_TARGET_OS / ZCODE_TARGET_ARCH 覆盖(交叉打包时由 CI 注入)。
  36. function normalizePlatform(raw) {
  37. switch (raw) {
  38. case "mac":
  39. case "macos":
  40. case "darwin":
  41. case "osx":
  42. return "darwin";
  43. case "win":
  44. case "windows":
  45. case "win32":
  46. return "win32";
  47. case "linux":
  48. return "linux";
  49. default:
  50. return raw;
  51. }
  52. }
  53. function normalizeArch(raw) {
  54. switch (raw) {
  55. case "x86_64":
  56. case "x64":
  57. case "amd64":
  58. return "x64";
  59. case "aarch64":
  60. case "arm64":
  61. return "arm64";
  62. default:
  63. return raw;
  64. }
  65. }
  66. const platform = normalizePlatform(process.env.ZCODE_TARGET_OS || "") || process.platform;
  67. const arch = normalizeArch(process.env.ZCODE_TARGET_ARCH || "") || process.arch;
  68. const platformKey = `${platform}-${arch}`;
  69. const glmDir = resolve(desktopRoot, "bundled-agents", platformKey, "glm");
  70. // zcode.cjs / .node-bundle-meta.json 的落点由 stage-agent-bundle.mjs 自己解析(同源)。
  71. // node_repl 宿主抽成独立包
  72. // @zcode/node-repl-host 之后,browser-use 不再产出 dist/mcp/server.js,CUA 资产
  73. // (docs/computer-use.md、scripts/computer-use-client.mjs)也已归 @zcode/zcode-cua-plugin。
  74. // 这份清单当时漏改,打包准备阶段照旧去 browser-use 要那三个文件,直接 missing runtime 挂掉。
  75. // dev 链路走的是 scripts/build-desktop-agent-cli.mjs 的 requiredDevPluginRuntimeBuilds(那份改对了),
  76. // 两份平行清单各自维护,所以 dev 测不出来 —— 权威归属见 bootstrap/official-plugin-definitions.ts。
  77. const browserUseRequiredRuntimePaths = [
  78. "scripts/browser-client.mjs",
  79. "docs/api.json",
  80. "docs/documents.json",
  81. "docs/overview.md",
  82. // documents.json 已暴露 recording lookup,桌面安装包不能复用缺少正文的 runtime。
  83. "docs/recording.md",
  84. "docs/workflow.md",
  85. "skills/control-browser/SKILL.md",
  86. "skills/web-gui-tester/SKILL.md",
  87. ];
  88. const officialPluginPackages = [
  89. {
  90. packageName: "@zcode/android-emulator-plugin",
  91. relativePath: "apps/zcode-cli/packages/android-emulator-plugin",
  92. requiresRuntime: true,
  93. requiredRuntimePaths: ["dist/mcp/server.js"],
  94. runtimeBuildScript: "scripts/build-mcp.mjs",
  95. stagedPath: "packages/android-emulator-plugin",
  96. },
  97. {
  98. packageName: "@zcode/documents-plugin",
  99. relativePath: "apps/zcode-cli/packages/documents-plugin",
  100. requiresRuntime: false,
  101. requiredSeedPaths: ["agents/visual-judge.md", "skills/docx/SKILL.md"],
  102. stagedPath: "packages/documents-plugin",
  103. },
  104. {
  105. packageName: "@zcode/image-search-plugin",
  106. relativePath: "apps/zcode-cli/packages/image-search-plugin",
  107. requiresRuntime: false,
  108. requiredSeedPaths: [".mcp.json"],
  109. stagedPath: "packages/image-search-plugin",
  110. },
  111. {
  112. packageName: "@zcode/pdf-plugin",
  113. relativePath: "apps/zcode-cli/packages/pdf-plugin",
  114. requiresRuntime: false,
  115. requiredSeedPaths: ["agents/visual-judge.md", "skills/pdf/SKILL.md"],
  116. stagedPath: "packages/pdf-plugin",
  117. },
  118. {
  119. packageName: "@zcode/presentations-plugin",
  120. relativePath: "apps/zcode-cli/packages/presentations-plugin",
  121. requiresRuntime: false,
  122. requiredSeedPaths: ["agents/visual-judge.md", "skills/pptx/SKILL.md"],
  123. stagedPath: "packages/presentations-plugin",
  124. },
  125. {
  126. packageName: "@zcode/spreadsheets-plugin",
  127. relativePath: "apps/zcode-cli/packages/spreadsheets-plugin",
  128. requiresRuntime: false,
  129. requiredSeedPaths: ["agents/visual-judge.md", "skills/xlsx/SKILL.md"],
  130. stagedPath: "packages/spreadsheets-plugin",
  131. },
  132. {
  133. packageName: "@zcode/visualize-plugin",
  134. relativePath: "apps/zcode-cli/packages/visualize-plugin",
  135. requiresRuntime: false,
  136. requiredSeedPaths: [
  137. "skills/visualize/SKILL.md",
  138. "skills/visualize/references/api.md",
  139. "skills/visualize/references/styles.md",
  140. "skills/visualize/tweak.md",
  141. "skills/visualize/LICENSE.md",
  142. "skills/visualize/scripts/render.py",
  143. "skills/visualize/assets/visualize.css",
  144. "skills/visualize/assets/visualize.html",
  145. "skills/visualize/assets/calendar.js",
  146. "skills/visualize/assets/runtime-manifest.json",
  147. "skills/visualize/scripts/vendor.py",
  148. "skills/visualize/assets/vendor/manifest.json",
  149. "skills/visualize/assets/vendor/floating-ui-core-1.7.3.min.js",
  150. "skills/visualize/assets/vendor/floating-ui-core-1.7.3.min.js.LICENSE",
  151. "skills/visualize/assets/vendor/floating-ui-dom-1.7.4.min.js",
  152. "skills/visualize/assets/vendor/floating-ui-dom-1.7.4.min.js.LICENSE",
  153. "skills/visualize/assets/vendor/lucide-1.17.0.js",
  154. "skills/visualize/assets/vendor/lucide-1.17.0.js.LICENSE",
  155. "skills/visualize/assets/vendor/d3-7.9.0.min.js",
  156. "skills/visualize/assets/vendor/d3-7.9.0.min.js.LICENSE",
  157. "skills/visualize/widgets/calendar.md",
  158. "skills/visualize/examples/calendar.html",
  159. "skills/visualize/assets/standalone-host-bridge.js",
  160. "skills/visualize/assets/standalone-shell.js",
  161. ],
  162. requiredRuntimePaths: [],
  163. stagedPath: "packages/visualize-plugin",
  164. },
  165. {
  166. // browser-use 只携带自己的 client script 与 skill/docs;node_repl MCP runtime 归
  167. // @zcode/node-repl-host(见上方常量注释)。
  168. packageName: "@zcode/browser-use-plugin",
  169. relativePath: "apps/zcode-cli/packages/browser-use-plugin",
  170. requiresRuntime: true,
  171. requiredRuntimePaths: browserUseRequiredRuntimePaths,
  172. runtimeBuildScript: "scripts/build.mjs",
  173. stagedPath: "packages/browser-use-plugin",
  174. },
  175. {
  176. packageName: "@zcode/ios-simulator-plugin",
  177. relativePath: "apps/zcode-cli/packages/ios-simulator-plugin",
  178. requiresRuntime: true,
  179. requiredRuntimePaths: ["dist/mcp/server.js"],
  180. runtimeBuildScript: "scripts/build-mcp.mjs",
  181. stagedPath: "packages/ios-simulator-plugin",
  182. },
  183. {
  184. // 修复原因:restore-legacy-sessions 已注册为官方插件,但 Electron 生产包只会拷贝
  185. // 这里列出的资源。漏掉它会导致用户生产包首次启动后 plugins list 里看不到该插件。
  186. packageName: "@zcode/restore-legacy-sessions-plugin",
  187. relativePath: "apps/zcode-cli/packages/restore-legacy-sessions-plugin",
  188. requiresRuntime: false,
  189. stagedPath: "packages/restore-legacy-sessions-plugin",
  190. },
  191. {
  192. packageName: "@zcode/skill-creator-plugin",
  193. relativePath: "apps/zcode-cli/packages/skill-creator-plugin",
  194. requiresRuntime: false,
  195. stagedPath: "packages/skill-creator-plugin",
  196. },
  197. {
  198. packageName: "@zcode/plugin-creator-plugin",
  199. relativePath: "apps/zcode-cli/packages/plugin-creator-plugin",
  200. requiresRuntime: false,
  201. stagedPath: "packages/plugin-creator-plugin",
  202. },
  203. {
  204. // 修复原因:zcode-guide 已注册为官方默认启用内容型插件(见 official-plugin-definitions.ts)。
  205. // Electron 生产包不是 SEA 路径,官方插件 seed 依赖这里 stage 的 resources/glm/packages/*-plugin;
  206. // 漏掉它会导致生产桌面包首启 seed 不到该插件,用户拿不到默认启用的配置指南技能。
  207. packageName: "@zcode/zcode-guide-plugin",
  208. relativePath: "apps/zcode-cli/packages/zcode-guide-plugin",
  209. requiresRuntime: false,
  210. stagedPath: "packages/zcode-guide-plugin",
  211. },
  212. {
  213. // node_repl 宿主:Browser Use 与 Computer Use 共用的 MCP runtime,本轮抽成独立包。
  214. // 它没有 listing(不进插件市场展示面),但生产包首启 seed 必须拿到它的 dist runtime,
  215. // 否则 bua/cua 任一开启时都会连不上 node_repl。
  216. packageName: "@zcode/node-repl-host",
  217. relativePath: "apps/zcode-cli/packages/node-repl-host",
  218. requiresRuntime: true,
  219. requiredRuntimePaths: ["dist/mcp/server.js"],
  220. runtimeBuildScript: "scripts/build.mjs",
  221. stagedPath: "packages/node-repl-host",
  222. },
  223. {
  224. // CUA 插件只携带 SDK/skill/docs;node_repl MCP runtime 归 @zcode/node-repl-host。
  225. packageName: "@zcode/zcode-cua-plugin",
  226. relativePath: "apps/zcode-cli/packages/zcode-cua-plugin",
  227. requiresRuntime: false,
  228. stagedPath: "packages/zcode-cua-plugin",
  229. },
  230. // superpowers 已从内置插件下线,改走 UI 推荐区按需安装;这里不再 stage 它的资源。
  231. ];
  232. // 随 CLI 内置的技能包(不是插件):bootstrap 的 resolveBundledSkillRoots 沿官方插件同款候选目录
  233. // 在 zcode.cjs 旁找 packages/bundled-skills 并原地读取。漏 stage 它,桌面包的 /workflow 会展开成
  234. // 「先加载 dynamic-workflows 技能」而技能不存在——这正是把它从可卸载的 zcode-guide 插件搬出来要修的事故形态。
  235. const bundledSkillPack = {
  236. relativePath: "apps/zcode-cli/packages/bundled-skills",
  237. requiredPaths: [
  238. "skills/dynamic-workflows/SKILL.md",
  239. "skills/dynamic-workflows/patterns.md",
  240. "skills/dynamic-workflows/examples.md",
  241. ],
  242. stagedPath: "packages/bundled-skills",
  243. topLevelPaths: ["README.md", "skills"],
  244. };
  245. const includedOfficialPluginTopLevelPaths = new Set([
  246. ".mcp.json",
  247. ".zcode-plugin",
  248. "README.md",
  249. // Electron 生产资源复制有独立白名单,遗漏 agents 会让首启 filesystem seed 永久缺少子代理。
  250. "agents",
  251. "commands",
  252. "dist",
  253. "docs",
  254. "hooks",
  255. "output-styles",
  256. "package.json",
  257. "scripts",
  258. "skills",
  259. "templates",
  260. ]);
  261. const excludedOfficialPluginAssetNames = new Set([
  262. ".DS_Store",
  263. ".venv",
  264. "__pycache__",
  265. "node_modules",
  266. ]);
  267. function shouldCopyOfficialPluginAsset(sourcePath) {
  268. const name = basename(sourcePath);
  269. return !excludedOfficialPluginAssetNames.has(name) && !name.endsWith(".pyc");
  270. }
  271. const isBootstrapWithRemote = process.env.ZCODE_BOOTSTRAP_WITH_REMOTE === "1";
  272. function buildCliBundle() {
  273. console.log("[prepare:agent-bundle] building zcode-cli app-server bundle ...");
  274. // 复用仓库根脚本(turbo build:desktop-agent --filter=@zcode/cli),命中缓存时几乎瞬时。
  275. runCommand(process.execPath, [resolve(repoRoot, "scripts/build-desktop-agent-cli.mjs")], {
  276. cwd: repoRoot,
  277. env: pnpmRunEnv,
  278. });
  279. if (!existsSync(cliBundlePath)) {
  280. throw new Error(
  281. `[prepare:agent-bundle] expected cli bundle missing after build: ${cliBundlePath}`,
  282. );
  283. }
  284. }
  285. function buildOfficialPluginRuntimes() {
  286. for (const plugin of officialPluginPackages) {
  287. if (!plugin.requiresRuntime) continue;
  288. console.log(`[prepare:agent-bundle] building ${plugin.packageName} runtime ...`);
  289. if (isBootstrapWithRemote) {
  290. buildOfficialPluginRuntimeForBootstrap(plugin);
  291. assertOfficialPluginRuntime(plugin);
  292. continue;
  293. }
  294. runCommand(
  295. "pnpm",
  296. ["--dir", resolve(repoRoot, "apps/zcode-cli"), "--filter", plugin.packageName, "build"],
  297. {
  298. cwd: repoRoot,
  299. env: pnpmRunEnv,
  300. },
  301. );
  302. assertOfficialPluginRuntime(plugin);
  303. }
  304. }
  305. function buildOfficialPluginRuntimeForBootstrap(plugin) {
  306. const pluginRoot = resolve(repoRoot, plugin.relativePath);
  307. const hasCompleteRuntime = plugin.requiredRuntimePaths.every((relativePath) =>
  308. existsSync(resolve(pluginRoot, ...relativePath.split("/"))),
  309. );
  310. if (plugin.packageName !== BROWSER_USE_PLUGIN_PACKAGE_NAME && hasCompleteRuntime) {
  311. console.log(
  312. `[prepare:agent-bundle] reuse existing official plugin runtime: ${plugin.packageName}`,
  313. );
  314. return;
  315. }
  316. // bootstrap:with-remote 会连续构建 remote assets 和桌面 agent bundle。
  317. // 通过 pnpm/filter 进入插件 build 时,tsc shim 在本地低内存环境中容易被 SIGKILL;
  318. // 这里仅在 bootstrap 开关下用当前 Node 直接执行等价 tsc + build-mcp,不改变插件自身 build 脚本。
  319. // browser-use 的 server 与 browser-client 是同一发布对;即使旧 server.js 存在也必须重建,
  320. // 否则会把旧 server 与当前 client(或缺失 client)一起 stage 到桌面安装包。
  321. runCommand(process.execPath, ["../../node_modules/typescript/bin/tsc"], {
  322. cwd: pluginRoot,
  323. env: process.env,
  324. });
  325. runCommand(process.execPath, [plugin.runtimeBuildScript], {
  326. cwd: pluginRoot,
  327. env: process.env,
  328. });
  329. }
  330. function assertOfficialPluginRuntime(plugin) {
  331. const pluginRoot = resolve(repoRoot, plugin.relativePath);
  332. for (const relativePath of plugin.requiredRuntimePaths) {
  333. const runtimePath = resolve(pluginRoot, ...relativePath.split("/"));
  334. if (!existsSync(runtimePath)) {
  335. throw new Error(`[prepare:agent-bundle] missing official plugin runtime: ${runtimePath}`);
  336. }
  337. }
  338. }
  339. function stageBundle() {
  340. // 实现已抽到 stage-agent-bundle.mjs:dev 链(scripts/build-desktop-agent-cli.mjs)
  341. // 必须用同一份,否则 dev 会继续跑上一次打包留下的陈旧 agent。
  342. stageAgentBundle({ repoRoot, platformKey });
  343. }
  344. function stageOfficialPlugins() {
  345. for (const plugin of officialPluginPackages) {
  346. const sourceRoot = resolve(repoRoot, plugin.relativePath);
  347. const manifestPath = resolve(sourceRoot, ".zcode-plugin", "plugin.json");
  348. if (!existsSync(manifestPath)) {
  349. throw new Error(`[prepare:agent-bundle] missing official plugin manifest: ${manifestPath}`);
  350. }
  351. const targetRoot = resolve(glmDir, plugin.stagedPath);
  352. mkdirSync(targetRoot, { recursive: true });
  353. for (const entryName of includedOfficialPluginTopLevelPaths) {
  354. const sourcePath = resolve(sourceRoot, entryName);
  355. if (!existsSync(sourcePath)) continue;
  356. cpSync(sourcePath, resolve(targetRoot, entryName), {
  357. recursive: true,
  358. filter: shouldCopyOfficialPluginAsset,
  359. });
  360. }
  361. for (const relativePath of plugin.requiredSeedPaths ?? []) {
  362. const stagedAssetPath = resolve(targetRoot, ...relativePath.split("/"));
  363. if (!existsSync(stagedAssetPath)) {
  364. throw new Error(
  365. `[prepare:agent-bundle] missing staged official plugin seed asset: ${stagedAssetPath}`,
  366. );
  367. }
  368. }
  369. console.log(`[prepare:agent-bundle] staged official plugin ${plugin.stagedPath}`);
  370. }
  371. }
  372. function stageBundledSkillPack() {
  373. const sourceRoot = resolve(repoRoot, bundledSkillPack.relativePath);
  374. const targetRoot = resolve(glmDir, bundledSkillPack.stagedPath);
  375. mkdirSync(targetRoot, { recursive: true });
  376. for (const entryName of bundledSkillPack.topLevelPaths) {
  377. const sourcePath = resolve(sourceRoot, entryName);
  378. if (!existsSync(sourcePath)) continue;
  379. cpSync(sourcePath, resolve(targetRoot, entryName), {
  380. recursive: true,
  381. filter: shouldCopyOfficialPluginAsset,
  382. });
  383. }
  384. for (const relativePath of bundledSkillPack.requiredPaths) {
  385. const stagedAssetPath = resolve(targetRoot, ...relativePath.split("/"));
  386. if (!existsSync(stagedAssetPath)) {
  387. throw new Error(
  388. `[prepare:agent-bundle] missing staged bundled skill asset: ${stagedAssetPath}`,
  389. );
  390. }
  391. }
  392. console.log(`[prepare:agent-bundle] staged bundled skill pack ${bundledSkillPack.stagedPath}`);
  393. }
  394. function stageSharpForNodeReplPlugin() {
  395. if (!isSharpRequiredByComputerUse({ desktopPackageRoot: desktopRoot })) {
  396. console.log("[prepare:agent-bundle] Computer Use package does not declare sharp, skip sharp staging");
  397. return;
  398. }
  399. // `sharp` 仍然外部化——它包含无法内联的 native .node,运行时从**所在包**的 node_modules
  400. // 解析。2026-09-11 起 node_repl 宿主的 bundle 归 @zcode/node-repl-host,所以 sharp 必须
  401. // stage 到宿主目录,否则宿主里的 `import sharp` 在打包后的 app 里解析不到。
  402. // CUA screenshot / get_app_state 的 native 依赖仍要放进 CUA plugin 自己的 node_modules;
  403. // Browser Use 目录保留一份兼容 staging。三份 staging 都位于 plugin 子目录下,避免
  404. // electron-builder 过滤 extraResources 根目录的 node_modules。
  405. const pluginStagedDirs = [
  406. [NODE_REPL_HOST_PACKAGE_NAME, resolve(glmDir, "packages", "node-repl-host")],
  407. [BROWSER_USE_PLUGIN_PACKAGE_NAME, resolve(glmDir, "packages", "browser-use-plugin")],
  408. [CUA_PLUGIN_PACKAGE_NAME, resolve(glmDir, "packages", "zcode-cua-plugin")],
  409. ];
  410. for (const [packageName, pluginStagedDir] of pluginStagedDirs) {
  411. if (!existsSync(resolve(pluginStagedDir, ".zcode-plugin", "plugin.json"))) {
  412. console.log(`[prepare:agent-bundle] ${packageName} not staged, skip sharp staging`);
  413. continue;
  414. }
  415. stageSharpIntoBundledAgents({
  416. desktopPackageRoot: desktopRoot,
  417. glmDir: pluginStagedDir,
  418. targetPlatform: { os: platform, arch },
  419. });
  420. console.log(
  421. `[prepare:agent-bundle] staged sharp into ${resolve(pluginStagedDir, "node_modules")} (${platform}-${arch})`,
  422. );
  423. }
  424. }
  425. function stageKoffiForCuaPlugin() {
  426. const cuaPluginStagedDir = resolve(glmDir, "packages", "zcode-cua-plugin");
  427. if (!existsSync(resolve(cuaPluginStagedDir, ".zcode-plugin", "plugin.json"))) {
  428. console.log("[prepare:agent-bundle] zcode-cua-plugin not staged, skip koffi staging");
  429. return;
  430. }
  431. stageKoffiIntoBundledAgents({
  432. koffiPackageRoot: adaptersRoot,
  433. glmDir: cuaPluginStagedDir,
  434. targetPlatform: { os: platform, arch },
  435. });
  436. console.log(
  437. `[prepare:agent-bundle] staged koffi into ${resolve(cuaPluginStagedDir, "node_modules")} (${platform}-${arch})`,
  438. );
  439. }
  440. // 修复原因:Electron 生产包只带 resources/glm/zcode.cjs 时,app-server 进程的
  441. // __dirname 附近没有官方插件目录,启动时 seed 找不到 source,用户侧不会自动得到内置插件。
  442. // 这里把官方插件按 bootstrap 的 rootCandidates 期望放到 glm/packages/*-plugin,
  443. // 让 Electron Node 运行 zcode.cjs 时复用同一套 filesystem seed 逻辑。
  444. // browser-use runtime 的声明生成依赖 @zcode/core/dist。CI 干净检出没有该产物,
  445. // 必须先构建 CLI 依赖,再构建官方插件;开发机残留的 dist 曾掩盖这个顺序问题。
  446. buildCliBundle();
  447. buildOfficialPluginRuntimes();
  448. stageBundle();
  449. stageOfficialPlugins();
  450. stageBundledSkillPack();
  451. stageKoffiForCuaPlugin();
  452. stageSharpForNodeReplPlugin();