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: 让 Windows CUA 顶部提示从 CLI runtime 的真实工具生命周期获得状态,不再依赖当前 v4 桌面对话不会发送的旧 session/event。
Architecture: CLI 在原始 SessionEvent 进入协议投影时额外发送严格、精简、不可重放的 computer-use/operation-event 通知;通知与 v4 conversation frame 并行,且位于 record.deliveryKind 判断之前。Services 只用该通知驱动 CuaOperationTurnTracker,再沿既有 Host→Main cua-operation-state 链路显示浮层;旧 session/event、Renderer、snapshot 和 relay 都不拥有提示状态。
Tech Stack: TypeScript 6、Zod、Vitest 4、ZCode Protocol NDJSON、Electron UtilityProcess/BrowserWindow、pnpm。
packages/shared/src/zcode-protocol/index.ts,使用严格 runtime schema。computer-use/operation-event;官方身份只接受 computer-use 中划线形式,不新增 computer_use。session/event 的 deliveryKind 或 v4 subscription 状态影响,不进入 snapshot/replayable/v4 topic/relay。sequenceNumber,不与旧协议 seq 混用。debug;状态跃迁走 info;旁路异常不能阻断 v4 frame 或工具执行。pnpm typecheck、pnpm lint、git diff --check,并提交 Conventional Commit;不得 push。packages/shared/src/zcode-protocol/index.ts: 定义 sideband method、严格判别联合 schema 和导出类型。packages/shared/test/zcodeProtocol.test.ts: 验证 method、六类 payload、严格字段和非法输入。apps/zcode-cli/packages/bootstrap/src/zcode-protocol/computer-use-operation-event.ts: 将 runtime SessionEvent 投影为最小 sideband payload。apps/zcode-cli/packages/bootstrap/src/zcode-protocol/server-operations.ts: 在 v4/legacy 分流之前 best-effort 发送 sideband。apps/zcode-cli/packages/bootstrap/tests/zcode-protocol.test.ts: 验证无 deliveryKind 仍发送、无敏感 payload、发送失败不阻断 v4。packages/services/src/zcode-agent/cuaOperationTurnTracker.ts: 改为消费 sideband 类型并按 eventId/sequenceNumber 去重。packages/services/test/cuaOperationTurnTracker.test.ts: 将 fixture 和全部状态机断言迁移到 sideband 生命周期。packages/services/src/zcode-agent/zcodeAgentService.ts: 新增 sideband notification 分支,移除旧 session/event 对 tracker 的驱动。packages/services/test/zcodeAgentService.test.ts: fake agent 只发 sideband,验证 reporter 跃迁且普通 session 流不受影响。docs/product-capability-map-office-computer-use.md: 更新真实状态链。apps/dev-docs/src/data/productCapabilityMap.ts: 更新能力图 producer/consumer 描述。apps/dev-docs/test/capabilityMapOfficeComputerUse.test.ts: 固化 sideband 状态链。Files:
packages/shared/src/zcode-protocol/index.tspackages/shared/test/zcodeProtocol.test.tsInterfaces:
zcodeProtocolMethods.computerUseOperationEvent === "computer-use/operation-event"zcodeComputerUseOperationEventSchemaProduces: ZCodeComputerUseOperationEvent
[ ] Step 1: Write failing protocol contract tests
Import the new schema and assert exact method naming plus one valid payload for every kind:
expect(zcodeProtocolMethods.computerUseOperationEvent).toBe("computer-use/operation-event");
const base = {
eventId: "evt-1",
sequenceNumber: 1,
sessionId: "sess-1",
timestamp: 1_700_000_000_000,
};
for (const event of [
{ ...base, kind: "turn-started", turnId: "turn-1" },
{ ...base, kind: "turn-completed", turnId: "turn-1" },
{ ...base, kind: "turn-failed", turnId: "turn-1" },
{
...base,
kind: "tool-scheduled",
turnId: "turn-1",
toolCallId: "call-1",
toolName: "mcp__computer-use__left_click",
},
{
...base,
kind: "tool-started",
turnId: "turn-1",
toolCallId: "call-1",
},
{ ...base, kind: "session-closed" },
]) {
expect(zcodeComputerUseOperationEventSchema.safeParse(event).success).toBe(true);
}
Add table cases rejecting empty ids, negative sequenceNumber, missing turn/tool fields, toolName on an incompatible kind, unknown keys and unknown kinds.
Run: pnpm exec vitest run packages/shared/test/zcodeProtocol.test.ts
Expected: FAIL because the method and schema exports do not exist.
Define a shared strict base and discriminated union:
const zcodeComputerUseOperationEventBaseSchema = z.object({
eventId: nonEmptyString,
sequenceNumber: z.number().int().nonnegative(),
sessionId: nonEmptyString,
timestamp: timestampMsSchema,
});
export const zcodeComputerUseOperationEventSchema = z.discriminatedUnion("kind", [
...["turn-started", "turn-completed", "turn-failed"].map((kind) =>
zcodeComputerUseOperationEventBaseSchema
.extend({
kind: z.literal(kind),
turnId: nonEmptyString,
})
.strict(),
),
zcodeComputerUseOperationEventBaseSchema
.extend({
kind: z.literal("tool-scheduled"),
turnId: nonEmptyString,
toolCallId: nonEmptyString,
toolName: nonEmptyString,
})
.strict(),
zcodeComputerUseOperationEventBaseSchema
.extend({
kind: z.literal("tool-started"),
turnId: nonEmptyString.optional(),
toolCallId: nonEmptyString,
toolName: nonEmptyString.optional(),
})
.strict(),
zcodeComputerUseOperationEventBaseSchema
.extend({
kind: z.literal("session-closed"),
})
.strict(),
]);
Use explicit schema declarations instead of .map() if TypeScript cannot preserve the Zod tuple type. Export the inferred type and add the method constant.
Run: pnpm exec vitest run packages/shared/test/zcodeProtocol.test.ts
Expected: PASS with zero failures.
Files:
apps/zcode-cli/packages/bootstrap/src/zcode-protocol/computer-use-operation-event.tsapps/zcode-cli/packages/bootstrap/src/zcode-protocol/server-operations.tsapps/zcode-cli/packages/bootstrap/tests/zcode-protocol.test.tsInterfaces:
SessionEventmapComputerUseOperationEvent(event): ZCodeComputerUseOperationEvent | undefinedEmits: { method: zcodeProtocolMethods.computerUseOperationEvent, params }
[ ] Step 1: Write failing CLI projection and delivery tests
Add a test that builds a record without deliveryKind, passes TurnStarted, ToolCallScheduled, ToolCallStarted, ToolCallResult, TurnComplete and SessionEnded through onSessionEvent, and asserts:
expect(notify.mock.calls.map(([message]) => message.method)).toEqual([
"computer-use/operation-event",
"computer-use/operation-event",
"computer-use/operation-event",
"computer-use/operation-event",
"computer-use/operation-event",
]);
expect(notify.mock.calls.map(([message]) => message.params.kind)).toEqual([
"turn-started",
"tool-scheduled",
"tool-started",
"turn-completed",
"session-closed",
]);
expect(notify.mock.calls[1]?.[0].params).not.toHaveProperty("input");
expect(notify.mock.calls[2]?.[0].params).not.toHaveProperty("result");
Assert v4Gateway.ingest still receives every parent-session event. Add a separate test whose notify throws for a relevant event and assert onSessionEvent does not throw and v4Gateway.ingest still runs.
Run: pnpm --dir apps/zcode-cli exec vitest run packages/bootstrap/tests/zcode-protocol.test.ts
Expected: FAIL because no sideband is emitted.
Create a switch over SessionEventType that copies only id, sequenceNumber, sessionId, turnId, timestamp, toolCallId and toolName. Return undefined for all other events. Add a Chinese bug-cause comment explaining that the v4 desktop path has no legacy deliveryKind, so the overlay lifecycle must be emitted before that gate.
At the top of onSessionEvent, before the child-session return and before record.deliveryKind, call a helper:
const operationEvent = mapComputerUseOperationEvent(event);
if (operationEvent) {
try {
context.notify({
method: zcodeProtocolMethods.computerUseOperationEvent,
params: operationEvent,
});
} catch (error) {
context.logger?.warn("Computer Use operation lifecycle notification failed", {
event: "zcode_protocol.computer_use_operation_event.failed",
eventId: operationEvent.eventId,
sessionId: operationEvent.sessionId,
turnId: "turnId" in operationEvent ? operationEvent.turnId : undefined,
error: error instanceof Error ? error.message : String(error),
});
}
}
The log event identifier may use underscores as a logger key, but method/tool identity must stay computer-use. Do not return from the catch.
Run: pnpm --dir apps/zcode-cli exec vitest run packages/bootstrap/tests/zcode-protocol.test.ts
Expected: PASS with zero failures.
Files:
packages/services/src/zcode-agent/cuaOperationTurnTracker.tspackages/services/test/cuaOperationTurnTracker.test.tspackages/services/src/zcode-agent/zcodeAgentService.tspackages/services/test/zcodeAgentService.test.tsInterfaces:
CuaOperationTurnTracker.accept(workspace, event: ZCodeComputerUseOperationEvent): voidZCodeAgentService.wireClient consumes zcodeProtocolMethods.computerUseOperationEvent
[ ] Step 1: Migrate tracker tests to the new event contract
Replace ZCodeSessionEvent fixtures with sideband fixtures using kind, sequenceNumber and eventId. Preserve every existing activation, exclusion, terminal, workspace isolation and reporter-failure assertion. Remove result/error fixture delivery because the sideband deliberately omits them; retain the assertion that state stays active until a turn terminal.
Add an explicit duplicate-id test:
const started = operationEvent("tool-started", {
turnId: "turn-1",
toolCallId: "call-1",
toolName: "mcp__computer-use__left_click",
});
tracker.accept(workspace, started);
tracker.accept(workspace, started);
expect(states).toHaveLength(1);
Run: pnpm exec vitest run packages/services/test/cuaOperationTurnTracker.test.ts
Expected: FAIL because accept still expects legacy ZCodeSessionEvent kinds.
Import ZCodeComputerUseOperationEvent, replace seq with sequenceNumber, add a bounded seenEventIds set/order, and switch on the new kinds. Keep all existing canonical tool matching, non-operating actions, stop behavior, retired-turn protection, reporter isolation and workspace cleanup. Add a Chinese bug-cause comment explaining why legacy session/event and sideband sequence domains must not be mixed.
Run: pnpm exec vitest run packages/services/test/cuaOperationTurnTracker.test.ts
Expected: PASS with zero failures.
Update CUA_OPERATION_LIVE_EVENT_FAKE_AGENT so it sends strict computer-use/operation-event notifications after the existing subscribe ACK, but sends no session/event. Assert reporter states are [true, false], invalid payload is ignored, duplicate eventId is idempotent, and received legacy session events remain empty.
Run: pnpm exec vitest run packages/services/test/zcodeAgentService.test.ts
Expected: FAIL because wireClient ignores the new notification.
In wireClient, before generic state/interaction branches:
if (message.method === zcodeProtocolMethods.computerUseOperationEvent) {
const parsed = zcodeComputerUseOperationEventSchema.safeParse(message.params);
if (parsed.success) {
cuaOperationTurnTracker?.accept(workspace, parsed.data);
} else {
logger.warn(undefined, "丢弃无效 Computer Use operation event", {
issues: parsed.error.issues.map((issue) => ({
code: issue.code,
message: issue.message,
path: issue.path.join("."),
})),
workspaceKey: resolveWorkspaceKey(workspace),
});
}
return;
}
Remove cuaOperationTurnTracker?.accept(workspace, normalizedEvent) from handleSessionEvent. Do not alter ordinary session.event emission or v4 frame forwarding.
Run:
pnpm exec vitest run packages/services/test/cuaOperationTurnTracker.test.ts packages/services/test/zcodeAgentService.test.ts packages/services/test/cuaPermissionBrokerProductAgentEnv.test.ts
Expected: PASS with zero failures.
Files:
docs/product-capability-map-office-computer-use.mdapps/dev-docs/src/data/productCapabilityMap.tsapps/dev-docs/test/capabilityMapOfficeComputerUse.test.tsdocs/superpowers/specs/2026-08-04-windows-cua-operation-indicator-design.mdInterfaces:
Documents the chain CLI runtime lifecycle -> computer-use/operation-event -> desktop-local Host tracker -> cua-operation-state -> Desktop Main overlay.
[ ] Step 1: Write the failing capability graph assertion
Require the current Computer Use experience node/edge text to include computer-use/operation-event and the CLI lifecycle source rather than validated live session event.
Run: pnpm exec vitest run apps/dev-docs/test/capabilityMapOfficeComputerUse.test.ts
Expected: FAIL because capability truth still names the old source.
Change only the current source/edge wording; preserve that live video, pause and takeover remain planned. Update the document ASCII chain to:
CLI runtime lifecycle
-> computer-use/operation-event
-> desktop-local Host turn tracker
-> strict Host→Main cua-operation-state
-> capture-excluded Windows BrowserWindow
Run:
pnpm exec vitest run packages/shared/test/zcodeProtocol.test.ts packages/services/test/cuaOperationTurnTracker.test.ts packages/services/test/zcodeAgentService.test.ts packages/services/test/cuaPermissionBrokerProductAgentEnv.test.ts packages/desktop/test/desktopHostProcess.test.ts packages/desktop/test/windowsCuaOperationIndicator.test.ts apps/dev-docs/test/capabilityMapOfficeComputerUse.test.ts
pnpm --dir apps/zcode-cli exec vitest run packages/bootstrap/tests/zcode-protocol.test.ts
Expected: both commands pass with zero failed tests.
Run:
git diff --check
pnpm typecheck
pnpm lint
Expected: every command exits 0. Any failure introduced by this change blocks commit; pre-existing unrelated failures must be reported with exact evidence.
Verify:
git status --short
git diff --stat
rg -n -- "computer_use" packages/shared/src/zcode-protocol apps/zcode-cli/packages/bootstrap/src/zcode-protocol packages/services/src/zcode-agent
Confirm no new computer_use tool/method identity was introduced, .tmp/ and unrelated user files are not staged, and the final diff matches the approved spec. Then commit only scoped files:
git add -- packages/shared/src/zcode-protocol/index.ts packages/shared/test/zcodeProtocol.test.ts apps/zcode-cli/packages/bootstrap/src/zcode-protocol/computer-use-operation-event.ts apps/zcode-cli/packages/bootstrap/src/zcode-protocol/server-operations.ts apps/zcode-cli/packages/bootstrap/tests/zcode-protocol.test.ts packages/services/src/zcode-agent/cuaOperationTurnTracker.ts packages/services/src/zcode-agent/zcodeAgentService.ts packages/services/test/cuaOperationTurnTracker.test.ts packages/services/test/zcodeAgentService.test.ts apps/dev-docs/src/data/productCapabilityMap.ts apps/dev-docs/test/capabilityMapOfficeComputerUse.test.ts docs/product-capability-map-office-computer-use.md docs/superpowers/plans/2026-08-04-windows-cua-lifecycle-sideband.md
git diff --cached --check
git commit -m "fix(cua): drive Windows indicator from runtime lifecycle"
Expected: one Conventional Commit, no push.