For agentic workers: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: background task completion 的 <task-notification> 仍进入 runtime command queue,但 active query loop 在即将发起下一次模型请求的合法边界前,应按 command priority 尽早消费 pending runtime commands;如果 runtime 已空闲,则保留现有 idle wake / next command 行为。
Architecture: 在 runtime command queue 提供 priority 候选能力,让 runRegularTurnLoop() 在每次 provider request projection 前查看“priority rank 不大于 next”的 pending runtime commands,也就是优先级至少为 next 的 now / next commands。候选集进入 active loop 前还必须经过显式白名单;本阶段只允许 task-notification 在 active loop 合流,普通 prompt / target continuation 仍留在 outer runtime command queue。idle 路径继续由 task-notification command 调 executeTurnCommand();subagent child runtime terminal 后的 nested Bash cleanup-only suppression 在 active-loop 和 idle 消费侧共用同一个判定。
Tech Stack: TypeScript, Vitest, zcode runtime command queue, MessageHistoryImpl, runtime task notification, conversation-session E2E fixtures.
getByMaxPriority("next") + explicit removeById(), with unit coverage.runRegularTurnLoop() only for post-first-request active-loop roundtrips (modelStepCount > 0), preserving idle command fallback.runtime-compact.test.ts.pnpm typecheck, root pnpm lint, direct core/adapters/bootstrap tsc, and git diff --check executed.apps/zcode-cli package-level pnpm typecheck / turbo run typecheck is blocked by current workspace dependency resolution: @zcode/shared@workspace:* is referenced by packages/adapters, but the workspace only contains @zcode/shared-types.pnpm --filter @zcode/desktop typecheck:e2e and pnpm --filter @zcode/desktop e2e:fixture:check -- --spec ./test/e2e/conversation-session/background/conversation-session-background.test.ts.now = 0、next = 1、later = 2,取 rank <= rank(next),语义是“优先级至少为 next”;随后必须经过显式白名单。本阶段白名单只放行 task-notification,其它 command mode 保持在 outer runtime command queue,不静默吞掉、不改 promise 生命周期。<task-notification> 文案;Bash 单 output-file surface、Workflow output-file artifact、手动 background controls 均不在本计划范围。git diff,确认没有被后续改动改变前提。apps/zcode-cli/packages/core/src/runtime/command-queue.ts
"next" 的 commands,保持现有优先级顺序。apps/zcode-cli/packages/core/src/runtime/internal-methods.ts
apps/zcode-cli/packages/core/src/runtime/internal.ts
AgentRuntimeInternal 类型。apps/zcode-cli/packages/core/src/runtime/methods/index.ts
apps/zcode-cli/packages/core/src/runtime/methods/background-notifications.ts
persistBackgroundTaskNotificationCommand(),新增 active-loop runtime command intake helper。apps/zcode-cli/packages/core/src/runtime/methods/turn-loop.ts
apps/zcode-cli/packages/core/src/runtime/methods/runtime-command-queue.ts
task-notification command path 保持现有语义;必要时复用提取出的 helper,避免 persistence 逻辑分叉。apps/zcode-cli/packages/core/tests/runtime-command-queue.test.ts
apps/zcode-cli/packages/core/tests/subagent-background.test.ts
apps/zcode-cli/packages/core/tests/runtime-tool-loop.test.ts
apps/zcode-cli/packages/core/tests/runtime-compact.test.ts
docs/testing/conversation-session-background-e2e-coverage-matrix.md
docs/conversation-session-case-catalog.md
packages/desktop/test/e2e/conversation-session/background/conversation-session-background.test.ts
Purpose: 在动代码前固定当前偏差、目标行为和本次验收口径,避免继续 patch-on-patch。
Checklist:
git diff --stat,确认当前 worktree 仍是 background/subagent/BG06 相关改动,没有混入不相关 UI 或 remote-control 改动。prompt / task-notification 和 now < next < later。mode: "task-notification", priority: "next"。mode: "task-notification", priority: "next"。apps/zcode-cli/packages/core/src/runtime/methods/runtime-command-queue.ts:task-notification 作为 outer command 调 executeTurnCommand(command.text)。apps/zcode-cli/packages/core/src/runtime/methods/turn-loop.ts:下一次 provider request 前只 drain steer 和旧 subagent notification,没有 drain runtime command queue task-notification。Pass Criteria:
Purpose: 让 active loop 可以从 runtime command queue 中查看优先级至少为 next 的 pending command 候选。rank 模型为:now = 0、next = 1、later = 2,所以判断写作 rank <= rank(next)。queue 层只负责 priority ordering,不关心 command mode;真正消费时由 runtime intake 按 id 显式 removeById()。
Interfaces:
Add type export:
export interface RuntimeCommandQueue {
getByMaxPriority(maxPriority: RuntimeCommandPriority): readonly RuntimeCommand[];
}
Selection rule:
RUNTIME_COMMAND_PRIORITY_ORDER[command.priority] <= RUNTIME_COMMAND_PRIORITY_ORDER[maxPriority]。<= 比的是 rank,不是自然语言里的“优先级更低”;rank 越小优先级越高。removeById() 删除。Checklist:
git diff。apps/zcode-cli/packages/core/tests/runtime-command-queue.test.ts 先写失败测试:
getByMaxPriority("next") 返回所有 now 和 next commands。later commands。dequeue() 正常取出。[ ] 运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/runtime-command-queue.test.ts --run
Expected: 新增测试失败,错误应指向 getByMaxPriority 未实现或行为不符。
apps/zcode-cli/packages/core/src/runtime/command-queue.ts,实现 getByMaxPriority()。[ ] 再次运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/runtime-command-queue.test.ts --run
Expected: PASS。
Pass Criteria:
dequeue() / peek() / snapshot() 现有行为未改。Purpose: 复用现有 persistence,把 active loop 按 priority 候选 + 白名单取出的 pending runtime commands 转成下一次 provider request 前应该进入 runtime history 的 entries。本阶段只实现 task-notification adapter;普通 prompt / target continuation 不进入 active-loop intake。
Interfaces:
Add internal method:
drainPendingRuntimeCommandsForActiveLoop(traceContext: TraceContext): Promise<{
drained: number;
messageIds: MessageId[];
consumedCommandIds: RuntimeCommandId[];
}>;
Behavior:
runtimeCommandQueue.getByMaxPriority("next") 取得候选 commands。mode === "task-notification" 的 command 调用 persistBackgroundTaskNotificationCommand(),保持 model-only synthetic input。mode === "prompt" 的 command 不做 active-loop 消费,保持在 queue 中,继续等待 outer runtime command queue drain。mode === "target-continuation" / mode === "target-continuation-loop" 必须保持原有 queue 执行语义,不能在 active loop 内直接转成 history entry。executeTurnCommand(),不创建新 turn。runPostCommandActiveTargetLoop();active-loop 本轮结束后仍走现有 prompt/target post-turn 逻辑。{ drained: 0, messageIds: [], consumedCommandIds: [] }。Checklist:
git diff。apps/zcode-cli/packages/core/tests/subagent-background.test.ts 或更合适的 runtime test 中先写失败测试:
sessionStore.savedMessages 中有两条 source === "background_task"、visibility === "model-only"。messageHistory.toRuntimeEntries() 包含两条 <task-notification>。prompt command 后调用内部 helper;断言该 command 仍留在 queue 且 promise 未 settle。[ ] 运行 focused test,确认失败:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/subagent-background.test.ts --run
[ ] 修改:
apps/zcode-cli/packages/core/src/runtime/methods/background-notifications.tsapps/zcode-cli/packages/core/src/runtime/internal-methods.tsapps/zcode-cli/packages/core/src/runtime/internal.tsapps/zcode-cli/packages/core/src/runtime/methods/index.ts[ ] 再次运行 focused test。
Pass Criteria:
task-notification command mode 没有被静默吞掉,仍保留在 outer runtime command queue。persistBackgroundTaskNotificationCommand()。Purpose: 将 helper 接到 runRegularTurnLoop() 的合法边界:steer drain 之后、compact/provider projection 之前。这样 background completion 如果赶上下一个 roundtrip,会合进这一轮模型请求。
Placement:
In apps/zcode-cli/packages/core/src/runtime/methods/turn-loop.ts:
await this.drainPendingSubagentNotifications(state.turnTraceContext);
const drainedRuntimeCommands =
await this.drainPendingRuntimeCommandsForActiveLoop(state.turnTraceContext);
if (drainedRuntimeCommands.drained > 0) {
state.repeatedToolCallSignature = undefined;
state.repeatedToolCallStreakCount = 0;
}
The exact placement must remain before:
const providerProjection = buildRuntimeProviderRequestMessages(this, {
entries: this.messageHistory.toRuntimeEntries(),
applyCacheControl: true,
});
Checklist:
git diff。apps/zcode-cli/packages/core/tests/runtime-tool-loop.test.ts 写失败测试:background Bash 在一个 tool step 执行完成后、下一次 provider request 前 enqueue notification。
messages 必须同时包含 tool result 和 <task-notification>。[ ] 运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/runtime-tool-loop.test.ts --run -t "background notification"
Expected: 新测试先失败,表现为 notification 只在当前 prompt command 完成后作为独立 request 出现。
apps/zcode-cli/packages/core/src/runtime/methods/turn-loop.ts,接入 helper。apps/zcode-cli/packages/core/tests/subagent-background.test.ts 里“queues task-notification commands behind an active prompt command”如果只断言 active prompt 期间不打断 in-flight request,应保留;如果断言 prompt 完成后一定是独立 notification turn,应改成 active-loop 合流或 idle fallback 分别覆盖。[ ] 运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/subagent-background.test.ts packages/core/tests/runtime-tool-loop.test.ts --run
Pass Criteria:
Purpose: 确保 runtime idle 时的 background notification 仍按当前 command queue 路径唤醒 main agent;这条路径是 background subagent/bash 主链路的基础。
Checklist:
git diff。apps/zcode-cli/packages/core/tests/subagent-background.test.ts 中的 idle wake 测试:
runs each idle background notification as a model-only task-notification commandwakes idle runtime synchronously when a background notification is enqueuedenqueueRuntimeCommand() 触发 drain。<task-notification>。[ ] 运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/subagent-background.test.ts --run
Pass Criteria:
persistBackgroundTaskNotificationCommand() 仍只落 model-only session message,不在用户可见内容里泄漏。runtime-command-queue.ts 的 post-notification goal continuation 逻辑仍只服务 idle notification command,不影响 active-loop intake。Purpose: 保护 goal + background 的既有结论:goal verification 必须等 running background settle,并且 notification 被消费后再做 verifier/continuation。
Checklist:
git diff。apps/zcode-cli/packages/core/tests/runtime-tool-loop.test.ts goal 相关用例:
RuntimeTaskRegistry 仍有 running background task,verifier defer。targetCompletionVerification.enabled === false 时,notification 不无条件启动 active target continuation。[ ] 运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/runtime-tool-loop.test.ts --run -t "target"
[ ] 再运行完整 runtime tool-loop focused suite:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/runtime-tool-loop.test.ts --run
Pass Criteria:
Purpose: 将 BG06 语义和新的 active-loop intake 对齐:child runtime 活跃时可以消费 nested Bash notification;child runtime sealed 后只 cleanup,不复活。
Checklist:
git diff。apps/zcode-cli/packages/core/tests/runtime-tool-loop.test.ts 或 subagent-background.test.ts 更新 BG06 单测:
<task-notification>。executeTurn() 已返回并 seal。[ ] 运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/runtime-tool-loop.test.ts packages/core/tests/subagent-background.test.ts --run -t "background"
Pass Criteria:
Purpose: 确保 active-loop runtime command intake 插入 synthetic user entry 后,不重新引入 non-incremental trajectory、cache anchor 漂移或 UI 可见泄漏。
Checklist:
git diff。apps/zcode-cli/packages/core/tests/runtime-compact.test.ts:
<task-notification> 仍保留在 provider-visible history 中。buildRuntimeProviderRequestMessages() 统一投影。[ ] 运行:
pnpm --dir apps/zcode-cli exec vitest packages/core/tests/runtime-compact.test.ts --run -t "task-notification"
[ ] 如有轨迹转换 helper 测试覆盖,补充一次 “active-loop notification 合流后 append-only” fixture 或 snapshot 检查。
Pass Criteria:
<task-notification>。Purpose: 将语义变化反映到 conversation-session background coverage 中,避免文档仍描述旧的 “next turn only” 行为。
Checklist:
git diff。docs/testing/conversation-session-background-e2e-coverage-matrix.md:
docs/testing/conversation-session-e2e-coverage-matrix.md 中对应汇总项。docs/conversation-session-case-catalog.md 中 background case 描述。packages/desktop/test/e2e/conversation-session/background/conversation-session-background.test.tspackages/desktop/test/e2e/fixtures/cases/conversation-session/conversation-session-background.jsonpackages/desktop/test/e2e/fixtures/upstream/conversation-session/conversation-session-background.json[ ] 运行 coverage/doc gate:
node scripts/audit-conversation-session-case-coverage.mjs --check --json
pnpm typecheck:e2e
[ ] 如新增 fixture,运行:
pnpm e2e:fixture:check -- --case conversation-session-background
Pass Criteria:
Purpose: 提交前做完整回归,确保 active-loop 合流没有破坏现有 background/subagent/bash/workflow 主链路。
Checklist:
git diff。[ ] 运行 focused core tests:
pnpm --dir apps/zcode-cli exec vitest \
packages/core/tests/runtime-command-queue.test.ts \
packages/core/tests/subagent-background.test.ts \
packages/core/tests/runtime-tool-loop.test.ts \
packages/core/tests/runtime-compact.test.ts \
--run
[ ] 运行 Bash/background focused tests:
pnpm --dir apps/zcode-cli exec vitest \
packages/adapters/src/exec/index.test.ts \
packages/core/tests/bash-run-conformance.test.ts \
--run -t "background|auto-background|task-notification"
[ ] 运行 workflow detach focused test:
pnpm --dir apps/zcode-cli exec vitest packages/bootstrap/tests/script-workflow.test.ts --run -t "background"
[ ] 运行 repo gates:
pnpm typecheck
pnpm lint
git diff --check
node scripts/audit-conversation-session-case-coverage.mjs --check --json
[ ] 手动 review git diff:
Pass Criteria:
pnpm typecheck 通过。pnpm lint 通过或仅有本任务无关的既有 warning。git diff --check 通过。task-notification。rank <= rank(next) 得到候选,也就是取 now / next,然后按显式白名单过滤;本阶段只放行 task-notification。task-notification 会作为 model-only synthetic input 让模型在最近合法 roundtrip 看到结果。