For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task with review checkpoints.
Goal: 在 Windows 本地桌面 Host 中按需启动 C:\Users\dev\zcode-cua 源码构建出的独立 Node Helper,让官方 zcode-cua plugin 获得随机 named pipe、token 和 authority,并在记事本完成 UIA 观察、点击和输入闭环。
Architecture: 保留 macOS 现有 Host -> Helper -> broker -> MCP plugin 分层。Windows 新增源码开发专用 Helper 入口和 Host lifecycle adapter;Helper 使用 process.execPath + ELECTRON_RUN_AS_NODE=1 运行,自动加载源码树的 build/Release/ax_native.node。ZCode Host 只负责源码根校验、子进程生命周期、健康检查和凭据注入;UIA、输入与 Windows system surface 仍归 zcode-cua。本计划不增加 tool、不修改 tool schema、不接入 SSH/WSL/Docker,也不做 WGC、完整指针或产品打包。
Tech Stack: TypeScript 5/6、Node.js 24、Electron utility process、Vitest 4、Node child_process.fork、Windows named pipe、N-API/node-addon-api、C++/UI Automation、pnpm 10。
Global Constraints:
docs/superpowers/specs/2026-07-28-windows-cua-development-runtime-design.md,范围只覆盖 Phase 0 和 Phase 1。desktop-attached-remote、SSH、WSL、Docker、Web remote 均不得创建 Helper。createProductCuaHelperHost()、Helper.app、TCC、签名和安装器,行为不得改变。createServiceLogger("cua-product-helper"),协议逐条输出仅允许 debug。packages/ui;因此本里程碑不触碰 Windows 设置页和权限引导。C:\Users\dev\zcode-cuapackage.jsonpnpm-lock.yamlscripts/build.mjssrc/broker/server/index.tssrc/broker/server/nodeSystemSurface.tssrc/broker/server/windowsSystemSurface.tssrc/broker/server/windowsDevHelperMain.tssrc/windows-helper.tstest/broker/windowsSystemSurface.test.tstest/windowsDevHelperMain.test.tstest/broker/helpers/tempSocket.tstest/broker/fakes/fakeBrokerServer.tstest/broker-client.claim.test.tstest/broker-client.refresh-marker.test.tstest/standalone/helper-launch/fakes.tstest/mock-broker-e2e.test.tstest/standalone/helper-launch/discovery.test.tstest/standalone/helper-launch/ownerLock.test.tstest/standalone/helper-launch/launcher.test.tstest/standalone/cli-launch.test.tstest/broker/broker.peerCheck.parity.test.tstest/broker/m3/rotation.selfHeal.test.tstest/lib/06-resize-jpeg.test.tsdocs/KNOWN-ISSUES.mddocs/platforms.mdC:\Users\dev\z-codedocs/superpowers/specs/2026-07-28-windows-cua-development-runtime-design.mdapps/zcode-cli/docs/design/v2/tool/00-tool-change-chain.mdpackages/services/src/cua-permission-broker/windowsCuaDevRuntime.tspackages/services/src/cua-permission-broker/windowsCuaDevHelperHost.tspackages/services/src/cua-permission-broker/index.tspackages/services/src/node.tspackages/services/test/windowsCuaDevRuntime.test.tspackages/services/test/windowsCuaDevHelperHost.test.tspackages/services/test/windowsCuaDevHelper.integration.test.tspackages/services/test/cuaPermissionBrokerProductAgentEnv.test.tspackages/services/test/cuaPermissionBrokerServiceDispose.test.tsdocs/cua/windows-source-development.mdFiles:
C:\Users\dev\zcode-cua\package.jsonC:\Users\dev\zcode-cua\pnpm-lock.yamlC:\Users\dev\zcode-cua\docs\KNOWN-ISSUES.mdStep 1: Record the current failing baseline
Run:
cd C:\Users\dev\zcode-cua
pnpm typecheck
pnpm lint
pnpm test -- --reporter=verbose
pnpm rebuild:native
Expected before the fix:
typecheck passes.lint fails because oxlint is not declared.rebuild:native fails until the Visual Studio C++ Desktop workload is installed.Retain the exact native-build error in the task notes. Do not let the best-effort install script count as native-build evidence.
Step 2: Make the native toolchain an explicit prerequisite
Use vswhere.exe to detect an installation containing:
Microsoft.VisualStudio.Component.VC.Tools.x86.x64
Microsoft.VisualStudio.Component.Windows11SDK.26100
If absent, install the Visual Studio Build Tools “Desktop development with C++” workload, then rerun:
pnpm rebuild:native
Test-Path .\build\Release\ax_native.node
Expected: native rebuild exits 0; the final command prints True.
Step 3: Repair the lint dependency
Add oxlint to devDependencies at the version used by ZCode (^1.57.0), run pnpm install, and verify:
pnpm lint
Expected: exit 0.
Step 4: Write the Windows-portable test helper first
Change test/broker/helpers/tempSocket.ts so live broker tests use:
win32 -> \\.\pipe\zcode-cua-test-<random>
other -> <fresh tmpdir>/broker.sock
Use the same helper from every test that creates a live listener:
test/broker-client.claim.test.tstest/broker-client.refresh-marker.test.tstest/broker/fakes/fakeBrokerServer.tstest/standalone/helper-launch/fakes.tstest/mock-broker-e2e.test.tsRun:
pnpm exec vitest run test/broker-client.claim.test.ts test/standalone/helper-launch/connection.test.ts test/standalone/helper-launch/orchestrator.test.ts test/mock-broker-e2e.test.ts
Expected: no listen EACCES and no timeout caused by an unbound fake broker.
Step 5: Separate POSIX contracts from cross-platform contracts
Apply these rules:
join() or inject path.posix when the test is explicitly checking a macOS/POSIX contract.0600/0700, uid ownership and symlink-permission assertions use describe.skipIf(process.platform === "win32").test/broker/broker.peerCheck.win32.test.ts remains the Windows named-pipe security contract; do not weaken production peer-check.ts to satisfy POSIX tests.test/lib/06-resize-jpeg.test.ts resolves fixtures relative to import.meta.url, never a developer’s /Users/... path.Run:
pnpm exec vitest run test/standalone/helper-launch/discovery.test.ts test/standalone/helper-launch/ownerLock.test.ts test/standalone/helper-launch/launcher.test.ts test/standalone/cli-launch.test.ts test/broker/broker.peerCheck.parity.test.ts test/broker/broker.peerCheck.win32.test.ts test/broker/m3/rotation.selfHeal.test.ts test/lib/06-resize-jpeg.test.ts
Expected: pass, with only explicitly named POSIX-only cases skipped on Windows.
Step 6: Run the complete repository gate
Run:
pnpm typecheck
pnpm lint
pnpm test
pnpm build
Expected: all commands exit 0. pnpm test may contain intentional platform skips, but no failures or unhandled errors.
Step 7: Document the corrected baseline
Update docs/KNOWN-ISSUES.md with:
Step 8: Commit
git add package.json pnpm-lock.yaml test docs/KNOWN-ISSUES.md
git diff --cached --check
git commit -m "test(windows): establish CUA development baseline"
Files:
C:\Users\dev\zcode-cua\src\broker\server\windowsSystemSurface.tsC:\Users\dev\zcode-cua\src\broker\server\nodeSystemSurface.tsC:\Users\dev\zcode-cua\src\broker\server\index.tsC:\Users\dev\zcode-cua\test\broker\windowsSystemSurface.test.tsStep 1: Write failing tests
Cover:
createNodeSystemSurface({ platform: "win32" }) dispatches to the Windows factory.captureScreenPng and captureWindowPng return null in Phase 1 and never invoke macOS commands.""; writes are a no-op until a native clipboard adapter exists.resolveApplicationBundleId returns null.openApplication({ name: "notepad.exe", activate: false }) invokes an injected async runner with an argv array and returns { pid, name, bundleId: null, active: false }.Run:
pnpm exec vitest run test/broker/windowsSystemSurface.test.ts
Expected: fail because the Windows factory does not exist and win32 currently falls into the macOS branch.
Step 2: Implement the minimal surface
Create createWindowsNodeSystemSurface() with an injected openRunner. The default runner uses child_process.spawn() without a shell, returns the child PID, calls unref(), and never invokes PowerShell.
Keep capture and clipboard explicitly fail-closed for Phase 1. Do not add BitBlt, PowerShell screenshot code or WGC placeholders that claim success.
Update createNodeSystemSurface() to dispatch:
linux -> createLinuxNodeSystemSurface
win32 -> createWindowsNodeSystemSurface
darwin -> existing macOS implementation
Step 3: Verify
Run:
pnpm exec vitest run test/broker/windowsSystemSurface.test.ts
pnpm typecheck
pnpm lint
Expected: pass.
Step 4: Commit
git add src/broker/server/windowsSystemSurface.ts src/broker/server/nodeSystemSurface.ts src/broker/server/index.ts test/broker/windowsSystemSurface.test.ts
git diff --cached --check
git commit -m "feat(windows): add CUA system surface"
Files:
C:\Users\dev\zcode-cua\src\broker\server\windowsDevHelperMain.tsC:\Users\dev\zcode-cua\src\windows-helper.tsC:\Users\dev\zcode-cua\scripts\build.mjsC:\Users\dev\zcode-cua\src\broker\server\index.tsC:\Users\dev\zcode-cua\test\windowsDevHelperMain.test.tsC:\Users\dev\zcode-cua\docs\platforms.mdStep 1: Write failing parser and lifecycle tests
The versioned Host/Helper control protocol is:
{"protocol":"zcode-cua-windows-dev/v1","type":"ready","socketPath":"\\\\.\\pipe\\...","pid":123}
{"protocol":"zcode-cua-windows-dev/v1","type":"shutdown"}
Cover:
win32 is accepted;--socket must be a Windows named pipe;--parent-pid must be a positive integer;ZCODE_CUA_PERMISSION_BROKER_TOKEN;--token is rejected and token text never appears in errors/messages;runHelper;SIGINT and SIGTERM share one idempotent async stop;Run:
pnpm exec vitest run test/windowsDevHelperMain.test.ts
Expected: fail because the entry does not exist.
Step 2: Implement the platform-specific composition root
windowsDevHelperMain.ts must:
loadRealNativeAddon({ platform: "win32" });createNodeSystemSurface({ platform: "win32" });runHelper();authToken;startLauncherLivenessWatchdog() for the parent PID;Do not call macOS helperMain.main(): that path requires token files, code-signature checks, TCC permission modes and /usr/bin/ps.
Step 3: Add the executable bundle
Add an esbuild entry:
src/windows-helper.ts -> dist/windows-helper.js
Use Node 24 target and the same externals as the existing bundles. Add a shebang so the file can also be run directly with Node during diagnostics.
Run:
pnpm build
Test-Path .\dist\windows-helper.js
node .\dist\windows-helper.js --socket invalid --parent-pid $PID
Expected:
0;Step 4: Run a read-only native smoke
Start the entry with a random pipe/token, connect using probeHelperHealth, call broker_info, then stop it through the v1 shutdown message. Assert:
broker_info.pid equals the child PID;This smoke is implemented in the test with the real addon and guarded by:
process.platform === "win32" && build/Release/ax_native.node exists
The Phase 0 gate guarantees the guard is true on the development machine.
Step 5: Document and verify
Update docs/platforms.md to distinguish:
Run:
pnpm exec vitest run test/windowsDevHelperMain.test.ts test/broker/windowsSystemSurface.test.ts
pnpm typecheck
pnpm lint
pnpm test
pnpm build
Expected: all exit 0.
Step 6: Commit
git add src scripts/build.mjs test/windowsDevHelperMain.test.ts docs/platforms.md
git diff --cached --check
git commit -m "feat(windows): add source Computer Use Helper entry"
Files:
C:\Users\dev\z-code\docs\superpowers\specs\2026-07-28-windows-cua-development-runtime-design.mdC:\Users\dev\z-code\apps\zcode-cli\docs\design\v2\tool\00-tool-change-chain.mdC:\Users\dev\z-code\packages\services\src\cua-permission-broker\windowsCuaDevRuntime.tsC:\Users\dev\z-code\packages\services\test\windowsCuaDevRuntime.test.tsStep 1: Close the spec’s accepted open item
Update the design status to “已确认” and resolve the Node choice:
command = process.execPath
env.ELECTRON_RUN_AS_NODE = "1"
Reason: desktop Host already uses this pattern for zcode-agent; CLI/test hosts naturally have process.execPath pointing to Node. The addon is N-API and is rebuilt on the target Windows machine.
Update the tool change chain before implementation. Record that the existing 30 tools, schemas, side-effect annotations and delivery-state semantics are unchanged; only the Windows backend admission/execution route becomes available.
Step 2: Write failing resolver tests
Cover:
platform="win32" accepts ZCODE_CUA_DEV_ROOT;package.json.name must equal @zcode/zcode-cua;dist/windows-helper.js and build/Release/ax_native.node must both be files;process.execPath;ELECTRON_RUN_AS_NODE=1 but no broker token yet;Run:
pnpm exec vitest run packages/services/test/windowsCuaDevRuntime.test.ts
Expected: fail because the resolver does not exist.
Step 3: Implement the resolver
Expose:
export interface WindowsCuaDevRuntime {
root: string;
entryPath: string;
addonPath: string;
command: string;
commandEnv: Record<string, string>;
}
export async function resolveWindowsCuaDevRuntime(
options?: WindowsCuaDevRuntimeResolveOptions,
): Promise<WindowsCuaDevRuntime>;
The default root comes only from ZCODE_CUA_DEV_ROOT. Do not search sibling directories or silently fall back to a macOS Helper path.
Step 4: Verify and commit
Run:
pnpm exec vitest run packages/services/test/windowsCuaDevRuntime.test.ts
pnpm typecheck
pnpm lint
Expected: pass.
git add docs/superpowers/specs/2026-07-28-windows-cua-development-runtime-design.md apps/zcode-cli/docs/design/v2/tool/00-tool-change-chain.md packages/services/src/cua-permission-broker/windowsCuaDevRuntime.ts packages/services/test/windowsCuaDevRuntime.test.ts
git diff --cached --check
git commit -m "docs(cua): finalize Windows runtime contract"
Files:
C:\Users\dev\z-code\packages\services\src\cua-permission-broker\windowsCuaDevHelperHost.tsC:\Users\dev\z-code\packages\services\src\cua-permission-broker\index.tsC:\Users\dev\z-code\packages\services\test\windowsCuaDevHelperHost.test.tsStep 1: Write failing lifecycle tests
Use an injected child-process adapter and health probe. Cover:
start() calls share one fork;runtime.command, entry is runtime.entryPath, cwd is runtime.root;ZCODE_CUA_HELPER_ADDON=runtime.addonPath and ELECTRON_RUN_AS_NODE=1;start() returns a handle;restart() stops H1, mints a different pipe/token, starts H2 and keeps authority stable;restartAfterCurrentStart() serializes behind a pending start;restartAfterCurrentStartPreservingTransport() invokes beforeFreshStart before fork and returns reused:false;stop() sends the v1 shutdown message, waits a bounded interval, then kills only the exact child if it has not exited;running;Run:
pnpm exec vitest run packages/services/test/windowsCuaDevHelperHost.test.ts
Expected: fail because the host does not exist.
Step 2: Define the minimal common Host contract
Use the existing CuaProductHelperHost resolver contract and add the two lifecycle capabilities ZCode owns:
export type ManagedCuaProductHelperHost = CuaProductHelperHost & {
stop(): Promise<void>;
checkHealth(timeoutMs?: number): Promise<unknown>;
};
Do not require macOS-only queryPermissionStatus() or queryScreenCaptureProbe() on the Windows class.
Step 3: Implement lifecycle and credential ownership
Implementation requirements:
mintBrokerSocketPath() and mintBrokerToken() per generation; unit tests inject deterministic mint functions instead of faking process.platform;child_process.fork() wrapped in an injectable adapter;unref() where safe;probeHelperHealth;createServiceLogger, never console.Step 4: Verify
Run:
pnpm exec vitest run packages/services/test/windowsCuaDevHelperHost.test.ts packages/services/test/cuaPermissionBrokerProductMcpResolver.test.ts packages/services/test/cuaPermissionBrokerHelperLivenessWatchdog.test.ts
pnpm typecheck
pnpm lint
Expected: pass.
Step 5: Commit
git add packages/services/src/cua-permission-broker/windowsCuaDevHelperHost.ts packages/services/src/cua-permission-broker/index.ts packages/services/test/windowsCuaDevHelperHost.test.ts
git diff --cached --check
git commit -m "feat(cua): manage Windows development Helper"
Files:
C:\Users\dev\z-code\packages\services\src\node.tsC:\Users\dev\z-code\packages\services\test\cuaPermissionBrokerProductAgentEnv.test.tsC:\Users\dev\z-code\packages\services\test\cuaPermissionBrokerServiceDispose.test.tsStep 1: Write failing admission tests
Add cases proving:
ZCODE_CUA_DEV_ROOT is non-empty;isDesktopAttachedRemote=true prevents Windows Host creation;BROKER_UNAVAILABLE, not empty env and not macOS fallback;Run:
pnpm exec vitest run packages/services/test/cuaPermissionBrokerProductAgentEnv.test.ts packages/services/test/cuaPermissionBrokerServiceDispose.test.ts
Expected: fail on Windows admission/host factory cases.
Step 2: Generalize the default helper type without weakening macOS
Change the default helper record to hold:
host: ManagedCuaProductHelperHost;
macPermissionHost?: CuaHelperHost;
Factory behavior:
darwin -> existing createProductCuaHelperHost(), assigned to both fields
win32 -> createWindowsCuaDevHelperHost(), no macPermissionHost
other -> undefined
Only run reapOrphanedHelpers() on darwin. Windows cleanup is child ownership + parent PID watchdog.
Step 3: Preserve macOS permission-service boundaries
getStatus() and permission onboarding continue to use macPermissionHost and remain unavailable on Windows. getHelperStatus() may report the Windows development Helper’s running state, but must not claim macOS permissions are available.
No UI changes are part of this task.
Step 4: Verify focused and regression suites
Run:
pnpm exec vitest run packages/services/test/cuaPermissionBrokerProductAgentEnv.test.ts packages/services/test/cuaPermissionBrokerServiceDispose.test.ts packages/services/test/cuaPermissionService.test.ts packages/services/test/cuaPermissionBrokerHelperHost.test.ts packages/services/test/cuaPermissionBrokerProductMcpResolver.test.ts
pnpm typecheck
pnpm lint
Expected: pass.
Step 5: Commit
git add packages/services/src/node.ts packages/services/test/cuaPermissionBrokerProductAgentEnv.test.ts packages/services/test/cuaPermissionBrokerServiceDispose.test.ts
git diff --cached --check
git commit -m "feat(cua): enable Windows source Helper"
Files:
C:\Users\dev\z-code\packages\services\test\windowsCuaDevHelper.integration.test.tsC:\Users\dev\z-code\docs\cua\windows-source-development.mdStep 1: Write the opt-in real integration test
The test runs only when all are true:
process.platform === "win32"
ZCODE_CUA_DEV_ROOT is set
dist/windows-helper.js exists
build/Release/ax_native.node exists
It must:
broker_info;list_apps broker method and receive an array;buildCuaProductHelperAgentEnv() and assert all three official env values;Run:
$env:ZCODE_CUA_DEV_ROOT='C:\Users\dev\zcode-cua'
pnpm exec vitest run packages/services/test/windowsCuaDevHelper.integration.test.ts
Expected: pass with the real named pipe and addon.
Step 2: Verify official plugin fail-closed behavior
Run the existing plugin tests with:
pnpm --filter @zcode/zcode-cua-plugin test
Expected:
Do not update the plugin dependency or tool surface in this milestone unless an actual failing protocol incompatibility proves it is required.
Step 3: Write the development runbook
docs/cua/windows-source-development.md must include:
cd C:\Users\dev\zcode-cua
pnpm install
pnpm rebuild:native
pnpm build
pnpm test
cd C:\Users\dev\z-code
$env:ZCODE_CUA_DEV_MODE='1'
$env:ZCODE_CUA_DEV_ROOT='C:\Users\dev\zcode-cua'
pnpm dev:desktop:prod
Also document:
zcode-cua plugin must be enabled;zcode-cua, while ZCode product packaging is not required;Step 4: Verify and commit
Run:
pnpm exec vitest run packages/services/test/windowsCuaDevHelper.integration.test.ts
pnpm typecheck
pnpm lint
Expected: pass.
git add packages/services/test/windowsCuaDevHelper.integration.test.ts docs/cua/windows-source-development.md
git diff --cached --check
git commit -m "test(cua): verify Windows source runtime"
Files:
Step 1: Start from clean builds
Run:
cd C:\Users\dev\zcode-cua
pnpm rebuild:native
pnpm build
pnpm typecheck
pnpm lint
pnpm test
cd C:\Users\dev\z-code
pnpm typecheck
pnpm lint
pnpm exec vitest run packages/services/test/windowsCuaDevRuntime.test.ts packages/services/test/windowsCuaDevHelperHost.test.ts packages/services/test/windowsCuaDevHelper.integration.test.ts packages/services/test/cuaPermissionBrokerProductAgentEnv.test.ts packages/services/test/cuaPermissionBrokerServiceDispose.test.ts
Expected: every command exits 0.
Step 2: Start ZCode source development
$env:ZCODE_CUA_DEV_MODE='1'
$env:ZCODE_CUA_DEV_ROOT='C:\Users\dev\zcode-cua'
pnpm dev:desktop:prod
Confirm before invoking a CUA task:
\\.\pipe\zcode-cua-helper-*.Step 3: Execute the Notepad scenario
Use one ZCode task to:
list_apps;notepad.exe without shell;ZCode Windows CUA Phase 1;Ctrl+A, type replacement text, and verify again.Acceptance:
Step 4: Exercise recovery and teardown
While ZCode remains open:
Expected: no orphan Helper and no stale credential reuse.
Step 5: Inspect runtime evidence
Check service logs and task rollout:
info/warn;debug only;If the first live attempt fails, collect the actual service log, child stderr, process tree and broker error before changing code.
Step 6: Run repository-wide mandatory gates
In C:\Users\dev\z-code:
pnpm typecheck
pnpm lint
pnpm test:unit:affected
In C:\Users\dev\zcode-cua:
pnpm typecheck
pnpm lint
pnpm test
pnpm build
Expected: all exit 0.
Step 7: Review commit history and working trees
Run:
git -C C:\Users\dev\z-code status --short
git -C C:\Users\dev\zcode-cua status --short
git -C C:\Users\dev\z-code log --oneline -5
git -C C:\Users\dev\zcode-cua log --oneline -5
Expected: both worktrees clean; each task has an independently reviewable Conventional Commit.
Do not tag, publish, push a release, build a signed package or close Phase 2/3 in this plan.
zcode-cua builds dist/windows-helper.js and build/Release/ax_native.node on Windows.process.execPath.pnpm typecheck and pnpm lint pass.zcode-cua typecheck, lint, full test and build pass on Windows.