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<