From 0156ddcbe10bde10cef1cd362961d5d9d3785b60 Mon Sep 17 00:00:00 2001 From: can1357 Date: Mon, 3 Aug 2026 00:02:29 +0200 Subject: [PATCH] fix(coding-agent): kept computer worker graph off CLI startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The PR #7205 merge left cli.ts statically importing startComputerWorker, dragging the computer worker graph (and pi_natives via the pi-utils barrel) into normal CLI startup; --version died under --no-addons and dotenv loaded before profile bootstrap. worker-entry is now a self-starting side-effect module dispatched via dynamic import like every other worker selector, and utils/clipboard.ts imports the mime constant from its submodule instead of the barrel. - Repointed the clipboard test spy at @oh-my-pi/pi-natives/clipboard — spying the barrel never intercepted the subpath the code imports, so the real native bridge ran (X11 timeouts on headless CI). - Refreshed the pinned HTML export template digest and the scout gate phrase the system-prompt rewrite changed. --- packages/coding-agent/src/cli.ts | 3 +-- .../src/tools/computer/worker-entry.ts | 20 +++++++++---------- packages/coding-agent/src/utils/clipboard.ts | 2 +- .../test/export-html-template.test.ts | 6 +++--- .../fixtures/computer-worker-bundled-host.ts | 5 +++-- .../test/system-prompt-inventory.test.ts | 2 +- .../coding-agent/test/utils/clipboard.test.ts | 2 +- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/coding-agent/src/cli.ts b/packages/coding-agent/src/cli.ts index 237fe99b1..e597a8588 100755 --- a/packages/coding-agent/src/cli.ts +++ b/packages/coding-agent/src/cli.ts @@ -36,7 +36,6 @@ import { TERMINAL_OUTPUT_WORKER_ARG } from "./launch/terminal-output-worker-prot import { LSP_MUX_WORKER_ARG } from "./lsp/mux/protocol"; import { COMPUTER_WORKER_ARG } from "./tools/computer/protocol"; import { smokeTestComputerWorker } from "./tools/computer/supervisor"; -import { startComputerWorker } from "./tools/computer/worker-entry"; if (Bun.semver.order(Bun.version, MIN_BUN_VERSION) < 0) { process.stderr.write( @@ -170,7 +169,7 @@ async function runWorkerEntrypoint(arg: string | undefined): Promise { } if (arg === COMPUTER_WORKER_ARG) { if (parentPort) installWorkerInbox(parentPort); - startComputerWorker(); + await import("./tools/computer/worker-entry"); return true; } if (arg === JS_EVAL_WORKER_ARG) { diff --git a/packages/coding-agent/src/tools/computer/worker-entry.ts b/packages/coding-agent/src/tools/computer/worker-entry.ts index 0613e7ee2..68bbe3490 100644 --- a/packages/coding-agent/src/tools/computer/worker-entry.ts +++ b/packages/coding-agent/src/tools/computer/worker-entry.ts @@ -1,14 +1,16 @@ import { parentPort } from "node:worker_threads"; -import { consumeWorkerInbox, isWorkerHostSelector } from "@oh-my-pi/pi-utils/worker-host"; +import { consumeWorkerInbox } from "@oh-my-pi/pi-utils/worker-host"; import type { ComputerWorkerInbound, ComputerWorkerTransport } from "./protocol"; import { ComputerWorkerCore } from "./worker"; -let started = false; - -/** Starts the computer worker once when running inside a Bun worker thread. */ -export function startComputerWorker(): void { - if (started || !parentPort) return; - started = true; +// Side-effect entry module: evaluating it inside a worker thread starts the +// computer worker; importing it from the main thread (tests, SDK embedding) is +// a no-op. The CLI host dispatches the `__omp_worker_computer` selector by +// dynamically importing this module after installing the worker inbox, so the +// computer worker graph stays off normal CLI startup. Loaded directly (source +// fallback outside a CLI host), top-level evaluation runs synchronously at +// worker start and `parentPort.on` below wins the flush on its own. +if (parentPort) { const port = parentPort; const inbox = consumeWorkerInbox(); const transport: ComputerWorkerTransport = { @@ -28,7 +30,3 @@ export function startComputerWorker(): void { new ComputerWorkerCore(transport); } - -if (!Bun.argv.some(isWorkerHostSelector)) { - startComputerWorker(); -} diff --git a/packages/coding-agent/src/utils/clipboard.ts b/packages/coding-agent/src/utils/clipboard.ts index 88cb49b03..77051a023 100644 --- a/packages/coding-agent/src/utils/clipboard.ts +++ b/packages/coding-agent/src/utils/clipboard.ts @@ -3,8 +3,8 @@ import { copyToClipboard as nativeCopyToClipboard, readImageFromClipboard as nativeReadImageFromClipboard, } from "@oh-my-pi/pi-natives/clipboard"; -import { SUPPORTED_IMAGE_MIME_TYPES } from "@oh-my-pi/pi-utils"; import * as logger from "@oh-my-pi/pi-utils/logger"; +import { SUPPORTED_IMAGE_MIME_TYPES } from "@oh-my-pi/pi-utils/mime"; import MAC_FILE_URL_SCRIPT from "./mac-file-urls.applescript" with { type: "text" }; type SpawnCaptureOptions = { input?: string; timeoutMs?: number }; diff --git a/packages/coding-agent/test/export-html-template.test.ts b/packages/coding-agent/test/export-html-template.test.ts index 2ff61a5b0..9192e9ccb 100644 --- a/packages/coding-agent/test/export-html-template.test.ts +++ b/packages/coding-agent/test/export-html-template.test.ts @@ -19,9 +19,9 @@ interface TemplateProbeResult { } const expectedTemplate: TemplateProbeResult = { - chars: 377_286, - bytes: 377_464, - sha256: "6598b2d74f905e3105474ea8033c938e92df4c33035421603ea363d72d1c81c1", + chars: 376_316, + bytes: 376_472, + sha256: "72721b125d8eaa0e995ef0b77e01cf561c9a76e36e745510b19734def07936e0", stableCache: true, assetsRemoved: 0, }; diff --git a/packages/coding-agent/test/fixtures/computer-worker-bundled-host.ts b/packages/coding-agent/test/fixtures/computer-worker-bundled-host.ts index ca18e05df..899c68a68 100644 --- a/packages/coding-agent/test/fixtures/computer-worker-bundled-host.ts +++ b/packages/coding-agent/test/fixtures/computer-worker-bundled-host.ts @@ -1,9 +1,10 @@ import { parentPort } from "node:worker_threads"; import { installWorkerInbox } from "@oh-my-pi/pi-utils/worker-host"; import { COMPUTER_WORKER_ARG } from "../../src/tools/computer/protocol"; -import { startComputerWorker } from "../../src/tools/computer/worker-entry"; if (process.argv[2] !== COMPUTER_WORKER_ARG) throw new Error(`unknown worker selector: ${process.argv[2]}`); if (!parentPort) throw new Error("computer worker fixture: missing parentPort"); installWorkerInbox(parentPort); -startComputerWorker(); +// Mirrors the CLI host: the worker entry is a self-starting side-effect module +// dispatched via dynamic import after the inbox is installed. +await import("../../src/tools/computer/worker-entry"); diff --git a/packages/coding-agent/test/system-prompt-inventory.test.ts b/packages/coding-agent/test/system-prompt-inventory.test.ts index 592d6c187..fad61a35f 100644 --- a/packages/coding-agent/test/system-prompt-inventory.test.ts +++ b/packages/coding-agent/test/system-prompt-inventory.test.ts @@ -679,7 +679,7 @@ describe("system prompt tool inventory", () => { }) ).systemPrompt.join("\n\n"); - expect(withScout).toContain("a read-only scout keeping bulk exploration"); + expect(withScout).toContain("a single read-only scout while you keep working is fine"); expect(withoutScout).not.toContain("read-only scout"); }); }); diff --git a/packages/coding-agent/test/utils/clipboard.test.ts b/packages/coding-agent/test/utils/clipboard.test.ts index e91061e6b..618e4b8aa 100644 --- a/packages/coding-agent/test/utils/clipboard.test.ts +++ b/packages/coding-agent/test/utils/clipboard.test.ts @@ -4,7 +4,7 @@ import { readMacFileUrlsFromClipboard, readTextFromClipboard, } from "@oh-my-pi/pi-coding-agent/utils/clipboard"; -import * as native from "@oh-my-pi/pi-natives"; +import * as native from "@oh-my-pi/pi-natives/clipboard"; import type { Subprocess } from "bun"; type SpawnOptions = Bun.SpawnOptions.SpawnOptions<