The CUA MCP bundle externalizes sharp because its native binary cannot be
embedded in the JavaScript bundle. The plugin therefore resolves sharp from
its own node_modules at runtime.
The development cache synchronizer currently stages the complete Sharp runtime directly into:
~/.zcode/cli/plugins/cache/zcode-plugins-official/zcode-cua/0.5.2/node_modules
That cache is not the durable source of truth. On desktop startup, bootstrap
computes the filesystem seed from
apps/zcode-cli/packages/zcode-cua-plugin, removes a stale cache root, and
atomically recreates it from the seed. The source plugin's node_modules does
not contain Sharp, so the restart deletes the runtime staged by sync:cache.
The next screenshot or zoom call fails with Cannot find module 'sharp'.
sync:cache
source dist/skill -> plugin cache
desktop Sharp -> plugin cache/node_modules (works immediately)
|
v
desktop restart -> official filesystem reseed
source plugin/node_modules (Sharp absent)
rm(cache root) -> copy source -> cache (Sharp removed)
|
v
screenshot -> loadSharp() -> MODULE_NOT_FOUND
The Helper source override is unrelated: logs prove the Windows Helper starts
from ZCODE_CUA_DEV_ROOT and reports ready before the MCP image encoder fails.
ZCODE_CUA_DEV_MODE=1 desktop startup must prepare the filesystem seed source
before bootstrap can read it.EPERM and EBUSY directory replacement failures must be treated as
transient replacement races alongside EEXIST and ENOTEMPTY.sharp must be loadable from the reseeded cache's package.json resolution
base after an actual restart-equivalent seed pass.ZCODE_CUA_DEV_MODE=1 must not stage CUA runtime assets.stageSharpIntoBundledAgents; it must not
duplicate native package lists or platform suffix rules.process.platform and
process.arch.Add a focused dev staging script that copies the Sharp runtime closure into
apps/zcode-cli/packages/zcode-cua-plugin/node_modules when
ZCODE_CUA_DEV_MODE=1. Invoke it from the desktop-agent CLI preparation path
before Electron starts. Bootstrap then hashes and copies a self-contained
source plugin, exactly as it does for packaged plugin roots.
Advantages:
The generated runtime lives under the ignored workspace node_modules tree and
does not alter lockfiles or tracked package metadata.
Bootstrap would need to import desktop packaging code or expose a new hook for one plugin. This couples the standalone CLI bootstrap layer to desktop package layout and still leaves the filesystem seed incomplete.
sync:cache to suppress reseeding — rejectedThis would make an untracked extra runtime appear current even though it is not part of the seed hash. It is fragile after source changes, can retain stale native binaries, and hides rather than repairs the source/cache contract.
A repository-level script owns the dev-only policy:
stageDevCuaPluginRuntime({
env,
platform,
arch,
desktopPackageRoot,
pluginRoot,
}): StagedRuntimePackage[]
It returns without mutation unless env.ZCODE_CUA_DEV_MODE === "1". When
enabled, it validates the plugin manifest exists and delegates to
stageSharpIntoBundledAgents with the plugin root as the staging destination.
Missing roots or dependencies fail startup loudly rather than launching a
partially functional CUA plugin.
scripts/build-desktop-agent-cli.mjs calls the staging entry after building the
desktop-agent CLI. Both dev:desktop:prod and direct
@zcode/desktop dev:local-cli already pass through this script, so there is one
startup boundary to maintain.
The existing runtimeTopLevelPaths: ["node_modules"] contract copies the
prepared Sharp closure and includes it in the seed hash. Replacement of one
official plugin version is guarded by a filesystem lock because desktop startup
warms multiple workspace Agent processes concurrently. The lock holder performs
the seed; waiters acquire the lock in turn, re-check the marker, and return
without another replacement when the first seed is complete.
The lock is cache infrastructure rather than CUA-specific behavior. It uses an
atomic directory creation, bounded waiting, and stale-lock takeover so a crashed
process cannot permanently block startup. Existing atomic replacement remains
the commit operation, with Windows transient error classification covering
EPERM and EBUSY.
createRequire(<root>/package.json).ZCODE_CUA_DEV_MODE=1.build-desktop-agent-cli.mjs to the dev staging
entry so direct and root desktop launch commands cannot bypass it.pnpm typecheck, full
pnpm lint, restarts desktop with ZCODE_CUA_DEV_MODE=1 and
ZCODE_CUA_DEV_ROOT, and checks that the live cache resolves Sharp.ZCODE_ALLOW_HOST_SHARP.