For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Make WSL workspaces in the same Electron window, distro, and Linux user share one Remote Host and zcode-server, while releasing unused workspace runtimes and deterministically disposing the pool after a 60-second idle TTL or immediately during owner teardown.
Architecture: Desktop Main owns a window-scoped WSL pool and keeps logical remoteSessionId attachments separate from the shared Host process. The Host exposes its existing remote service collection on multiple ports, accepts workspace-release control messages, and reports workspace task activity so Main never expires a pool with a running task. WSL remains desktop-continuous; Docker remains dedicated and SSH keeps its existing pool policy.
Tech Stack: TypeScript, Electron UtilityProcess/MessagePort, Zod internal message schemas, Vitest fake timers, pnpm/oxlint.
(windowWebContentsId, normalized requested distro/default sentinel, normalized requested user/default sentinel) for the current implementation; one key may own at most one live Host.remoteSessionId, attachmentId, workspacePath, and optional workspaceIdentity.workspaceIdentity?.trim() || workspacePath; filesystem execution continues to use workspacePath.desktop-continuous and must not register relay_bridge.60_000 ms; real window close, App quit, and update shutdown bypass it.wsl --terminate, wsl --shutdown, process-name scanning, or Docker pooling.pnpm typecheck and pnpm lint before completion.Files:
packages/shared/src/channels.tspackages/shared/src/validation.tspackages/desktop/src/main/desktopHostProcess.tspackages/shared/test/validation.test.tsInterfaces:
HostMessageTypes.InitRemoteWslHost with a WSL target and no initial service port.HostMessageTypes.ReleaseRemoteWorkspace carrying workspacePath and optional workspaceIdentity.Produces: HostResponseTypes.WorkspaceRunningTaskCountChanged carrying workspace context and a non-negative count.
[ ] Step 1: Write failing schema tests
Add assertions that hostMessageSchema accepts:
{
type: HostMessageTypes.InitRemoteWslHost,
target: { kind: "wsl", distro: "Ubuntu", user: "zcode" },
remoteAssets,
}
and:
{
type: HostMessageTypes.ReleaseRemoteWorkspace,
workspacePath: "/work/a",
workspaceIdentity: "remote:wsl:a",
}
Add a response-schema assertion for:
{
type: HostResponseTypes.WorkspaceRunningTaskCountChanged,
workspacePath: "/work/a",
workspaceIdentity: "remote:wsl:a",
runningTaskCount: 0,
}
Run: pnpm vitest run packages/shared/test/validation.test.ts
Expected: FAIL because the three message constants/schemas do not exist.
Add distinct message constants and Zod schemas. Extend HostInitMessage with:
{
type: typeof HostMessageTypes.InitRemoteWslHost;
target: Extract<RemoteTarget, { kind: "wsl" }>;
remoteAssets: RemoteAssetDirs;
hostId?: string;
deliveryKind?: TaskRealtimeHostDeliveryKind;
}
Do not widen InitRemoteSshHost to WSL; the two modes have different realtime behavior.
Run: pnpm vitest run packages/shared/test/validation.test.ts
Expected: PASS.
[ ] Step 5: Commit
git add packages/shared/src/channels.ts packages/shared/src/validation.ts packages/shared/test/validation.test.ts packages/desktop/src/main/desktopHostProcess.ts
git commit -m "feat(remote): define shared WSL host lifecycle messages"
Files:
packages/services/src/zcode-agent/zcodeTaskServiceAdapter.tspackages/desktop/src/host/index.tspackages/desktop/src/main/desktopHostProcess.tspackages/services/test/zcodeLegacyTaskCompatTaskIndex.test.tspackages/desktop/test/desktopHostProcess.test.tsInterfaces:
ReleaseRemoteWorkspace and WorkspaceRunningTaskCountChanged from Task 1.releaseWorkspacePreparation(params): Promise<void> delegating to IZCodeAgentService.disposeWorkspace().Produces: optional onWorkspaceRunningTaskCountChanged(process, event) callback from spawnHostProcess dependencies.
[ ] Step 1: Write a failing adapter test
Construct the adapter with a mocked zcodeAgentService.disposeWorkspace and call:
await service.releaseWorkspacePreparation({
workspacePath: "/work/a",
workspaceIdentity: "remote:wsl:a",
provider: "zcode",
});
Assert one call with normalized workspace path/identity and no provider field.
Run the narrow existing adapter test file that contains releaseWorkspacePreparation; if no focused file exists, run:
pnpm vitest run packages/services/test/zcodeLegacyTaskCompatTaskIndex.test.ts -t "releases workspace preparation"
Expected: FAIL because the current method is an empty operation.
Implement:
async releaseWorkspacePreparation(params): Promise<void> {
// 修复原因:只关闭 workspace UI 不会自动释放预热 Agent;共享 WSL Host 下 Host 仍会继续存活。
await options.zcodeAgentService.disposeWorkspace(normalizeWorkspaceParams(params));
}
Test that ReleaseRemoteWorkspace calls the active IZCodeTaskService.releaseWorkspacePreparation and that a workspace activity response is forwarded through the optional Main callback with the originating process.
In Host, reject release before services are ready, otherwise await the task service method and log one lifecycle result. Extend the reporting task-service proxy to maintain counts by the remembered task's workspace context and post WorkspaceRunningTaskCountChanged on 0→1 and 1→0 transitions. In desktopHostProcess.ts, parse that response and call:
onWorkspaceRunningTaskCountChanged?.(child, {
workspacePath,
workspaceIdentity,
runningTaskCount,
});
Run:
pnpm vitest run packages/services/test/zcodeLegacyTaskCompatTaskIndex.test.ts -t "releases workspace preparation"
pnpm vitest run packages/desktop/test/desktopHostProcess.test.ts
Expected: PASS.
[ ] Step 7: Commit
git add packages/services/src/zcode-agent/zcodeTaskServiceAdapter.ts packages/desktop/src/host/index.ts packages/desktop/src/main/desktopHostProcess.ts packages/services/test/zcodeLegacyTaskCompatTaskIndex.test.ts packages/desktop/test/desktopHostProcess.test.ts
git commit -m "fix(remote): release inactive workspace runtimes"
Files:
packages/desktop/src/main/remoteWslHostPool.tspackages/desktop/test/remoteWslHostPool.test.tsInterfaces:
WSL_HOST_IDLE_TTL_MS = 60_000.buildWslHostPoolKey(windowWebContentsId, target).Produces: createRemoteWslHostPool({ disposeHost, hasRunningWorkspace }) with get, setConnecting, markReady, retain, release, handleWorkspaceTaskCount, disposeWindow, and disposeAll.
[ ] Step 1: Write failing pure state-machine tests
Use fake timers to cover:
expect(buildWslHostPoolKey(7, { kind: "wsl", distro: " Ubuntu ", user: " dev " }))
.toBe("7\0wsl:v1:Ubuntu\0dev");
Then assert one entry is reused, last release schedules exactly 60 seconds, retain cancels the timer, a running workspace prevents disposal, transition to zero tasks starts a fresh 60-second TTL, and stale generation timers do nothing.
Run: pnpm vitest run packages/desktop/test/remoteWslHostPool.test.ts
Expected: FAIL because the module does not exist.
The pool owns one timer and one dispose Promise per entry. Every timer closure captures entry identity and generation, then verifies the map still points at both before disposal. disposeWindow and disposeAll clear timers and bypass TTL.
Run: pnpm vitest run packages/desktop/test/remoteWslHostPool.test.ts
Expected: PASS.
[ ] Step 5: Commit
git add packages/desktop/src/main/remoteWslHostPool.ts packages/desktop/test/remoteWslHostPool.test.ts
git commit -m "feat(remote): add window-scoped WSL host pool"
Files:
packages/desktop/src/main/desktopRemoteSessions.tspackages/desktop/src/host/index.tspackages/desktop/src/host/taskRealtimeBridge.tspackages/desktop/src/main/index.tspackages/desktop/test/desktopRemoteSessions.test.tspackages/desktop/test/taskRealtimeBridge.test.tsInterfaces:
{ kind: "shared-wsl"; entry; attachmentId }.Produces: manager method handleWorkspaceRunningTaskCountChanged(process, context, count).
[ ] Step 1: Write failing WSL sharing tests
Add tests proving:
InitRemoteWslHost.Connected, each gets a distinct AttachServicePort using desktop-continuous.taskRealtime.deliveryKind = "relay_bridge" is registered.Docker remains InitRemoteWorkspace dedicated.
[ ] Step 2: Run manager tests and verify RED
Run: pnpm vitest run packages/desktop/test/desktopRemoteSessions.test.ts
Expected: FAIL because WSL still uses the dedicated path.
Make Host accept InitRemoteWslHost wherever InitRemoteSshHost currently means “shared remote workspace Host without initial port”. Keep task realtime bridge creation disabled for WSL desktop.
On WSL connect, get/create the pool Host, wait on its readiness, attach a unique port, and track context. On detach, queue ReleaseRemoteWorkspace only when no logical/mobile owner remains and no running task is reported. Pool release installs TTL. Main's task-count callback cancels or restarts TTL and flushes pending workspace release when count reaches zero.
Window dispose, App shutdown and update shutdown clear WSL pool timers, reject pending waiters, dedupe process identities, and reuse disposeHostProcessAndWait. Every ready/exit/timer continuation compare-and-deletes the same entry.
Run:
pnpm vitest run packages/desktop/test/desktopRemoteSessions.test.ts
pnpm vitest run packages/desktop/test/taskRealtimeBridge.test.ts
pnpm vitest run packages/desktop/test/desktopHostProcess.test.ts
Expected: PASS.
[ ] Step 7: Commit
git add packages/desktop/src/main/desktopRemoteSessions.ts packages/desktop/src/host/index.ts packages/desktop/src/host/taskRealtimeBridge.ts packages/desktop/src/main/index.ts packages/desktop/test/desktopRemoteSessions.test.ts packages/desktop/test/taskRealtimeBridge.test.ts packages/desktop/test/desktopHostProcess.test.ts
git commit -m "feat(remote): share WSL hosts across workspaces"
Files:
packages/server/src/remote/wsl-detect.tspackages/server/src/remote/deploy.tspackages/server/src/remote/remoteAssetInstaller.tspackages/server/test/wslDetect.test.tspackages/server/test/remoteAssetInstaller.test.tsInterfaces:
Produces: unique staging path per asset installation and install-root lock with version recheck.
[ ] Step 1: Write failing discovery single-flight tests
Inject a clock/command runner, call availability/list discovery concurrently, and assert one underlying command. Advance 5 seconds and assert a new command. Reject once and assert the next call retries rather than reusing a rejected Promise.
Run: pnpm vitest run packages/server/test/wslDetect.test.ts
Expected: FAIL because discovery is currently per-call.
Cache only status and distro list. Clear cache on rejection and expose an invalidation function for explicit UI refresh/connection failure. Do not globally cache resolved user or $HOME.
Run two installers against one remote path and assert staging paths differ, only the lock owner uploads, and the waiter rechecks installed version after acquiring the lock. Assert a failed install removes only its own staging path.
Use an owner token in the staging suffix, an atomic lock directory under the install root, bounded stale-lock recovery, lock-internal version recheck, and exact-path cleanup. Keep the existing fast version-match skip.
Run:
pnpm vitest run packages/server/test/wslDetect.test.ts
pnpm vitest run packages/server/test/remoteAssetInstaller.test.ts
pnpm vitest run packages/server/test/wslBackend.test.ts packages/server/test/remoteConnect.test.ts
Expected: PASS.
[ ] Step 7: Commit
git add packages/server/src/remote/wsl-detect.ts packages/server/src/remote/deploy.ts packages/server/src/remote/remoteAssetInstaller.ts packages/server/test/wslDetect.test.ts packages/server/test/remoteAssetInstaller.test.ts
git commit -m "perf(remote): deduplicate WSL discovery and deployment"
Files:
docs/superpowers/specs/2026-07-20-window-scoped-wsl-host-pooling-design.mddocs/testing/wsl-host-pooling-runtime-evidence.mdInterfaces:
Produces: automated verification and a real Windows + WSL PID/RSS evidence table.
[ ] Step 1: Run all focused tests
pnpm vitest run packages/shared/test/validation.test.ts
pnpm vitest run packages/services/test/zcodeLegacyTaskCompatTaskIndex.test.ts -t "releases workspace preparation"
pnpm vitest run packages/desktop/test/remoteWslHostPool.test.ts packages/desktop/test/desktopRemoteSessions.test.ts packages/desktop/test/desktopHostProcess.test.ts packages/desktop/test/taskRealtimeBridge.test.ts
pnpm vitest run packages/server/test/wslDetect.test.ts packages/server/test/remoteAssetInstaller.test.ts packages/server/test/wslBackend.test.ts packages/server/test/remoteConnect.test.ts
Expected: PASS with zero failed tests.
[ ] Step 2: Run mechanical verification
pnpm typecheck
pnpm lint
Expected: both commands exit 0; existing warnings are recorded separately from new errors.
Open 1, then 3, then 5 same-distro/user workspaces. Record timestamp, Windows Host PID, wsl.exe PID, WSL zcode-server PID, Agent PIDs, RSS, first-connect time, and later-attach times. Verify one Host/server, per-workspace Agents only as needed, individual workspace release, 60-second idle expiry, TTL reuse, App-exit override, and no effect on a control user process.
Write exact commands, sampled PID tables, observed deadlines, environment versions, failures/limitations, and whether Docker remained dedicated. Do not claim a runtime case that was not executed.
[ ] Step 5: Commit
git add docs/superpowers/specs/2026-07-20-window-scoped-wsl-host-pooling-design.md docs/testing/wsl-host-pooling-runtime-evidence.md
git commit -m "test(remote): document WSL host pool runtime evidence"