For agentic workers: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: 撤掉这轮 Bash background 中新增的 generic runBackgroundable 抽象,把 Bash timeout auto-background 收回 Bash 专属路径,并复用已有 background notification / wake / runtime command queue。
Architecture: 保留现有 ExecutionPort.run()、ExecutionPort.start()、getBackgroundTask()、cancelBackgroundTask() 作为公共 execution 边界;新增能力只作为 Bash handler 与 Node execution adapter 之间的窄结构化 capability,不扩展公共 ExecutionPort。Bash auto-background 只负责“同一个前台进程超时后转后台任务”,完成后仍通过 BackgroundTaskTracker 走现有 task-notification、runtime wake、runtime command queue 和 post-turn goal driver。
Tech Stack: TypeScript, Vitest, pnpm, @zcode/contracts, @zcode/adapters, @zcode/core, current workspace source only.
docs/bash-background-parity.md;不参考其它分支。git commit,除非用户在当前任务里明确要求。ExecutionPort.runBackgroundable、BackgroundableExecutionRunOptions、BackgroundableExecutionRunResult。persistOutput: "always" 语义。git status --short,确认没有用户新改动被覆盖。当前工作区里 Bash background WIP 已经实现了大部分 notification/wake/queue 能力,但 auto-background 入口过宽:
apps/zcode-cli/packages/contracts/src/interfaces/execution.port.ts 新增了 runBackgroundable、waitForBackgroundTask、BackgroundableExecution* 类型。apps/zcode-cli/packages/adapters/src/exec/index.ts 在 NodeExecutionAdapter.runBackgroundable() 内做 foreground completion 和 timeout promotion。apps/zcode-cli/packages/core/src/tool/handlers/bash.ts 通过 executionPort.runBackgroundable() 调用 auto-background,并强制 persistOutput: "always"。apps/zcode-cli/packages/core/src/tool/executor/background-tasks.ts 已经能发 Bash local_bash task notification,并且可以用 direct waiter 避免 Bash poller。目标形态:
ExecutionPort 不再出现 runBackgroundable / BackgroundableExecution*。runBashWithAutoBackground(request, options)。run() 或 start()。BackgroundTaskTracker、formatTaskNotification({ taskType: "local_bash" })、enqueueBackgroundTaskNotification、runtime command queue。Modify: apps/zcode-cli/packages/contracts/src/interfaces/execution.port.ts
BackgroundExecutionStartResult、BackgroundExecutionSnapshot、ExecutionPort.start/getBackgroundTask/cancelBackgroundTask。Modify: apps/zcode-cli/packages/adapters/src/exec/index.ts
NodeExecutionAdapter.runBackgroundable()。runBashWithAutoBackground(request, options),只处理 Bash timeout promotion。waitForBackgroundTask(taskId, options?) 作为内部结构化 capability,但不放回公共 ExecutionPort。run() 的 persistOutput 语义。Create: apps/zcode-cli/packages/core/src/tool/handlers/bash-auto-background.ts
bash.ts 不直接写 structural cast。Modify: apps/zcode-cli/packages/core/src/tool/handlers/bash.ts
createAutoBackgroundExecutionRequest() 和 restoreForegroundOutputPersistence()。runBashWithOptionalAutoBackground()。run_in_background 走 executionPort.start()。Modify: apps/zcode-cli/packages/core/src/tool/executor/background-tasks.ts
ExecutionPort["waitForBackgroundTask"]。getBackgroundTask() fallback。Modify: tests
apps/zcode-cli/packages/adapters/tests/exec.test.tsapps/zcode-cli/packages/core/tests/bash-run-conformance.test.tsapps/zcode-cli/packages/core/tests/runtime-tool-loop.test.tsapps/zcode-cli/packages/core/tests/tool-contracts.test.tsModify: docs
docs/bash-background-parity.mddocs/superpowers/plans/2026-07-01-bash-background-refactor.mdPurpose: 在动代码前重新确认当前 diff 和目标 Bash background 行为,避免按过期结论继续 patch。
Files: no code changes in this phase.
Checklist
Run:
git status --short
Expected:
如果出现本 plan 外的新文件或用户新改动,先停下来读 diff。
[ ] Step 0.2: Confirm generic abstraction is current WIP, not HEAD baseline
Run:
git show HEAD:apps/zcode-cli/packages/contracts/src/interfaces/execution.port.ts | rg -n "runBackgroundable|BackgroundableExecution|waitForBackgroundTask|BackgroundExecution" -C 2
Expected:
BackgroundExecution*、start()、getBackgroundTask()、cancelBackgroundTask()。不应看到 runBackgroundable 或 BackgroundableExecution*。
[ ] Step 0.3: Confirm current WIP references to remove or narrow
Run:
rg -n "runBackgroundable|BackgroundableExecution|autoBackgroundOnTimeout|waitForBackgroundTask" apps/zcode-cli/packages docs/bash-background-parity.md
Expected:
后续 phase 完成后,runBackgroundable|BackgroundableExecution|autoBackgroundOnTimeout 在 apps/zcode-cli/packages 下应为 0。
[ ] Step 0.4: Recheck target Bash background facts
Run:
rg -n "assistantAutoBackgrounded|backgroundTaskId|persistedOutputPath|run_in_background|TaskOutput" apps/zcode-cli/packages/contracts/src/tools/bash.ts docs/bash-background-parity.md
Expected:
backgroundTaskId, backgroundedByUser, assistantAutoBackgrounded, persistedOutputPath.Phase 0 Pass Criteria
Purpose: 先把测试从 generic API 改到 Bash 专属 capability,形成重构目标的失败测试。
Files:
apps/zcode-cli/packages/adapters/tests/exec.test.tsapps/zcode-cli/packages/core/tests/bash-run-conformance.test.tsapps/zcode-cli/packages/core/tests/runtime-tool-loop.test.tsapps/zcode-cli/packages/core/tests/tool-contracts.test.tsInterfaces:
runBashWithAutoBackground(request: ExecutionRequest, options?: ExecutionRunOptions): Promise<BashAutoBackgroundRunResult>waitForBackgroundTask(taskId: string, options?: { signal?: AbortSignal }): Promise<BackgroundExecutionSnapshot | undefined>Checklist
In apps/zcode-cli/packages/adapters/tests/exec.test.ts, rename auto-background tests so they call runBashWithAutoBackground instead of runBackgroundable.
Use this structural helper in the test file:
type BashAutoBackgroundCapableAdapter = NodeExecutionAdapter & {
runBashWithAutoBackground?: (
request: ExecutionRequest,
options?: ExecutionRunOptions,
) => Promise<
| { kind: "completed"; result: ExecutionResult }
| {
assistantAutoBackgrounded: true;
kind: "backgrounded";
task: BackgroundExecutionStartResult;
}
>;
waitForBackgroundTask?: (
taskId: string,
options?: { signal?: AbortSignal },
) => Promise<BackgroundExecutionSnapshot | undefined>;
};
Add one explicit boundary assertion near the first auto-background adapter test:
expect("runBackgroundable" in adapter).toBe(false);
expect(typeof capable.runBashWithAutoBackground).toBe("function");
In apps/zcode-cli/packages/core/tests/bash-run-conformance.test.ts, change the fake execution port test from runBackgroundableCalled to runBashWithAutoBackgroundCalled.
The fake method should return:
async runBashWithAutoBackground() {
runBashWithAutoBackgroundCalled = true;
return {
assistantAutoBackgrounded: true,
kind: "backgrounded" as const,
task: {
outputPath: "/tmp/zcode-bash-output.log",
startedAt: new Date(),
status: "running" as const,
taskId: "exec_auto_background",
},
};
}
Expected assertion:
expect(runBashWithAutoBackgroundCalled).toBe(true);
expect(output.status).toBe("backgrounded");
expect(output.assistantAutoBackgrounded).toBe(true);
In apps/zcode-cli/packages/core/tests/tool-contracts.test.ts, add a runtime shape check that Bash provider schema still exposes background result fields but does not rely on execution-port generic promotion.
Use this expectation style:
expect(BashOutputJsonSchema.properties).toHaveProperty("backgroundTaskId");
expect(BashOutputJsonSchema.properties).toHaveProperty("assistantAutoBackgrounded");
expect(BashInputJsonSchema.properties).toHaveProperty("run_in_background");
Do not assert any provider-visible field for runBackgroundable; it must remain implementation-only and absent from tool schema.
Run:
../../node_modules/.bin/vitest run packages/adapters/tests/exec.test.ts -t "auto-background|foreground results foreground|persisted output"
../../node_modules/.bin/vitest run packages/core/tests/bash-run-conformance.test.ts -t "auto-backgrounds eligible foreground commands"
Expected:
NodeExecutionAdapter.runBashWithAutoBackground does not exist yet.bashHandler still calls runBackgroundable.Phase 1 Pass Criteria
Purpose: 从公共 contracts 移除 generic foreground-promotion API,先把边界收窄。
Files:
apps/zcode-cli/packages/contracts/src/interfaces/execution.port.tsapps/zcode-cli/packages/adapters/src/exec/index.tsChecklist
Delete these declarations from apps/zcode-cli/packages/contracts/src/interfaces/execution.port.ts:
export interface BackgroundableExecutionRunOptions extends ExecutionRunOptions {
autoBackgroundOnTimeout?: {
taskId?: string;
enabled: boolean;
};
}
export type BackgroundableExecutionRunResult = ...
ExecutionPortRemove these optional methods from ExecutionPort:
waitForBackgroundTask?(
taskId: string,
options?: { signal?: AbortSignal },
): Promise<BackgroundExecutionSnapshot | undefined>;
runBackgroundable?(
request: ExecutionRequest,
options?: BackgroundableExecutionRunOptions,
): Promise<BackgroundableExecutionRunResult>;
Keep:
start?(
request: ExecutionRequest,
options?: ExecutionRunOptions,
): Promise<BackgroundExecutionStartResult>;
getBackgroundTask?(taskId: string): Promise<BackgroundExecutionSnapshot | undefined>;
cancelBackgroundTask?(taskId: string): Promise<BackgroundExecutionSnapshot | undefined>;
In apps/zcode-cli/packages/adapters/src/exec/index.ts, remove imports of:
BackgroundableExecutionRunOptions,
BackgroundableExecutionRunResult,
Run:
cd apps/zcode-cli/packages/contracts && ../../../../node_modules/.bin/tsc --noEmit
Expected:
Phase 2 Pass Criteria
ExecutionPort no longer exposes generic auto-background.Purpose: 保留同进程 timeout promotion 能力,但把它限定为 Bash 专属 adapter capability。
Files:
apps/zcode-cli/packages/adapters/src/exec/index.tsapps/zcode-cli/packages/adapters/tests/exec.test.tsInterfaces:
Add local adapter-only types near the existing background task types in index.ts:
interface BashAutoBackgroundRunOptions extends ExecutionRunOptions {}
type BashAutoBackgroundRunResult =
| {
kind: "completed";
result: ExecutionResult;
}
| {
assistantAutoBackgrounded: true;
kind: "backgrounded";
task: BackgroundExecutionStartResult;
};
Add class method:
async runBashWithAutoBackground(
request: ExecutionRequest,
options: BashAutoBackgroundRunOptions = {},
): Promise<BashAutoBackgroundRunResult>
Checklist
In NodeExecutionAdapter, replace runBackgroundable() with runBashWithAutoBackground().
Required semantic changes:
autoBackgroundOnTimeout options object.request.timeoutMs ?? DEFAULT_TIMEOUT_MS as the auto-background threshold.<= 0, return { kind: "completed", result: await this.run(request, options) }.exec_${crypto.randomUUID()}.Do not accept caller-supplied task id.
[ ] Step 3.2: Keep forced persistence internal
Inside runBashWithAutoBackground(), create an internal run request:
const originalPersistOutput = request.outputLimit?.persistOutput ?? "none";
const runRequest: ExecutionRequest = {
...request,
timeoutMs: 0,
outputLimit: {
...request.outputLimit,
persistOutput: "always",
},
};
This internal persistOutput: "always" must not be created in bash.ts.
Replace cleanupAutoBackgroundForegroundArtifacts() with a narrower helper:
private normalizeBashAutoBackgroundForegroundResult(
result: ExecutionResult,
paths: ExecutionOutputPaths,
originalPersistOutput: OutputPersistenceMode,
): ExecutionResult
Required behavior:
originalPersistOutput === "always", return result unchanged.originalPersistOutput === "on_truncate", preserve artifact metadata only for streams where stream.truncated === true; delete internal non-truncated output files.If originalPersistOutput === "none", delete internal output files and remove artifact metadata from both streams unless the stream is truncated by existing output-limit semantics.
[ ] Step 3.4: Keep output-limit kill only after promotion
Preserve the current fixed behavior:
let backgrounded = false;
let persistedLimitReached = false;
const backgroundRunOptions: InternalExecutionRunOptions = {
...options,
signal: controller.signal,
onPersistedLimit: () => {
persistedLimitReached = true;
},
onEvent: (event) => {
this.updateBackgroundTaskRecordFromEvent(record, event);
return options.onEvent?.(event);
},
shouldStopOnPersistedLimit: () => backgrounded,
};
When timeout promotion wins:
backgrounded = true;
this.backgroundTasks.set(taskId, record);
if (persistedLimitReached) {
controller.abort("output_limit");
}
Keep this method on NodeExecutionAdapter:
async waitForBackgroundTask(
taskId: string,
options: { signal?: AbortSignal } = {},
): Promise<BackgroundExecutionSnapshot | undefined>
Do not re-add it to ExecutionPort.
Run:
../../node_modules/.bin/vitest run packages/adapters/tests/exec.test.ts -t "auto-background|foreground results foreground|persisted output"
Expected:
waitForBackgroundTask.Phase 3 Pass Criteria
runBackgroundable.rg -n "runBackgroundable|BackgroundableExecution|autoBackgroundOnTimeout" apps/zcode-cli/packages/adapters apps/zcode-cli/packages/contracts returns no matches.Purpose: 让 Bash handler 使用 Bash 专属 capability,并删除 handler 里的 forced persistence patch。
Files:
apps/zcode-cli/packages/core/src/tool/handlers/bash-auto-background.tsapps/zcode-cli/packages/core/src/tool/handlers/bash.tsapps/zcode-cli/packages/core/tests/bash-run-conformance.test.tsInterfaces:
Create apps/zcode-cli/packages/core/src/tool/handlers/bash-auto-background.ts:
import type {
BackgroundExecutionSnapshot,
BackgroundExecutionStartResult,
ExecutionPort,
ExecutionRequest,
ExecutionResult,
ExecutionRunOptions,
} from "@zcode/contracts";
export type BashAutoBackgroundRunResult =
| {
kind: "completed";
result: ExecutionResult;
}
| {
assistantAutoBackgrounded: true;
kind: "backgrounded";
task: BackgroundExecutionStartResult;
};
export interface BashAutoBackgroundExecutionPort extends ExecutionPort {
runBashWithAutoBackground(
request: ExecutionRequest,
options?: ExecutionRunOptions,
): Promise<BashAutoBackgroundRunResult>;
waitForBackgroundTask?(
taskId: string,
options?: { signal?: AbortSignal },
): Promise<BackgroundExecutionSnapshot | undefined>;
}
export function supportsBashAutoBackground(
executionPort: ExecutionPort,
): executionPort is BashAutoBackgroundExecutionPort {
return typeof (executionPort as Partial<BashAutoBackgroundExecutionPort>)
.runBashWithAutoBackground === "function";
}
export async function runBashWithOptionalAutoBackground(input: {
eligible: boolean;
executionPort: ExecutionPort;
options: ExecutionRunOptions;
request: ExecutionRequest;
}): Promise<BashAutoBackgroundRunResult> {
if (input.eligible && supportsBashAutoBackground(input.executionPort)) {
return await input.executionPort.runBashWithAutoBackground(input.request, input.options);
}
return {
kind: "completed",
result: await input.executionPort.run(input.request, input.options),
};
}
Checklist
Create bash-auto-background.ts exactly for the narrow Bash capability and wrapper. Do not export this from contracts.
bash.ts call siteReplace the current runResult block with:
const runResult = await runBashWithOptionalAutoBackground({
eligible: isBashAutoBackgroundEligible(parsed),
executionPort,
options: runOptions,
request,
});
Remove from bash.ts:
function createAutoBackgroundExecutionRequest(...)
function restoreForegroundOutputPersistence(...)
Also remove any now-unused imports:
type ExecutionResult
Run:
../../node_modules/.bin/vitest run packages/core/tests/bash-run-conformance.test.ts -t "auto-backgrounds eligible foreground commands|conformance"
Expected:
Phase 4 Pass Criteria
runBackgroundable.Purpose: 继续复用已有的 background notification / wake / runtime command queue,不新增 Bash 专用 wake 机制。
Files:
apps/zcode-cli/packages/core/src/tool/executor/background-tasks.tsapps/zcode-cli/packages/core/tests/runtime-tool-loop.test.tsInterfaces:
In background-tasks.ts, define a local structural waiter type:
type BackgroundTaskWaiter = {
waitForBackgroundTask(
taskId: string,
options?: { signal?: AbortSignal },
): Promise<BackgroundTaskSnapshot | undefined>;
};
Add helper:
function getBackgroundTaskWaiter(
executionPort: ExecutionPort | undefined,
): BackgroundTaskWaiter | undefined {
const candidate = executionPort as Partial<BackgroundTaskWaiter> | undefined;
return typeof candidate?.waitForBackgroundTask === "function"
? (candidate as BackgroundTaskWaiter)
: undefined;
}
Checklist
ExecutionPort["waitForBackgroundTask"]Change the BackgroundTaskSnapshot type so it no longer references ExecutionPort["waitForBackgroundTask"].
Keep this union:
type BackgroundTaskSnapshot =
| Awaited<ReturnType<NonNullable<ExecutionPort["getBackgroundTask"]>>>
| SubagentTaskSnapshot
| WorkflowTaskSnapshot;
Replace:
return toolCall.name === "Bash" && Boolean(this.deps.executionPort?.waitForBackgroundTask);
with:
return toolCall.name === "Bash" && Boolean(getBackgroundTaskWaiter(this.deps.executionPort));
Replace the waiter call with:
return getBackgroundTaskWaiter(this.deps.executionPort)?.waitForBackgroundTask(taskId);
Do not remove the existing getBackgroundTask() polling fallback in this phase; it remains for execution ports that cannot provide direct waiter. Bash on NodeExecutionAdapter should use direct waiter and therefore not poll.
Keep maybeEnqueueBackgroundTaskNotification() unchanged except for type fallout. It must still call:
this.deps.enqueueBackgroundTaskNotification({ text, traceContext });
The text must still come from:
formatTaskNotification({
taskType: "local_bash",
...
});
Run:
../../node_modules/.bin/vitest run packages/core/tests/runtime-tool-loop.test.ts -t "background Bash|direct execution wait|stale Bash|task-notification|goal|notification"
Expected:
Phase 5 Pass Criteria
ExecutionPort.waitForBackgroundTask.Purpose: 清掉多轮 patch 留下的概念债,确保文档描述的是最终实现,而不是过期抽象。
Files:
docs/bash-background-parity.mddocs/superpowers/plans/2026-07-01-bash-background-parity.md only if it contains now-dangerous implementation guidancedocs/superpowers/plans/2026-07-01-bash-background-refactor.mdChecklist
In docs/bash-background-parity.md, describe the final architecture as:
Bash timeout auto-background is implemented as a Bash-owned execution path.
It reuses existing background task events, task notification enqueue, runtime wake,
and runtime command queue. It does not expose a generic foreground-promotion method
on ExecutionPort.
Use Chinese if the rest of the file is Chinese; keep wording short.
Run:
rg -n "runBackgroundable|BackgroundableExecution|autoBackgroundOnTimeout|persistOutput: \"always\"" apps/zcode-cli/packages docs/bash-background-parity.md
Expected:
runBackgroundable, BackgroundableExecution, autoBackgroundOnTimeout.persistOutput: "always" may still appear in existing explicit background tests or adapter internals for current output persistence semantics, but not in Bash handler auto-background policy.
[ ] Step 6.3: Check naming stays local
Run:
node opensource/tools/check-competitor-terms.mjs apps/zcode-cli/packages/core/src/tool/handlers/bash.ts apps/zcode-cli/packages/core/src/tool/handlers/bash-auto-background.ts apps/zcode-cli/packages/core/src/tool/executor/background-tasks.ts docs/bash-background-parity.md
Expected:
Phase 6 Pass Criteria
Purpose: 证明这次重构没有破坏现有 Bash、background、notification、contracts、typecheck 和 lint。
Files: no intended code changes.
Checklist
Run:
../../node_modules/.bin/vitest run packages/adapters/tests/exec.test.ts
Expected:
PASS with existing skips only.
[ ] Step 7.2: Core Bash and tool tests
Run:
../../node_modules/.bin/vitest run packages/core/tests/bash-run-conformance.test.ts packages/core/tests/tool-contracts.test.ts
Expected:
PASS with existing skips only.
[ ] Step 7.3: Runtime background tests
Run:
../../node_modules/.bin/vitest run packages/core/tests/runtime-tool-loop.test.ts -t "background Bash|direct execution wait|stale Bash|task-notification|goal|notification"
Expected:
PASS.
[ ] Step 7.4: Package typechecks
Run:
cd apps/zcode-cli/packages/contracts && ../../../../node_modules/.bin/tsc --noEmit
cd ../adapters && ../../../../node_modules/.bin/tsc --noEmit
cd ../core && ../../../../node_modules/.bin/tsc --noEmit
Expected:
All PASS.
[ ] Step 7.5: Repo checks
Run from repo root:
pnpm lint
pnpm typecheck
git diff --check
Expected:
pnpm lint: exit 0; existing warnings are acceptable if not introduced by this refactor.pnpm typecheck: exit 0.git diff --check: no whitespace errors.
[ ] Step 7.6: Final source scan
Run:
rg -n "runBackgroundable|BackgroundableExecution|autoBackgroundOnTimeout" apps/zcode-cli/packages
node opensource/tools/check-competitor-terms.mjs apps/zcode-cli/packages/core/src/tool/handlers/bash.ts apps/zcode-cli/packages/core/src/tool/handlers/bash-auto-background.ts apps/zcode-cli/packages/core/src/tool/executor/background-tasks.ts docs/bash-background-parity.md
Expected:
Phase 7 Pass Criteria
ExecutionPort public contract is back to existing execution/background primitives only.runBashWithAutoBackground() narrow structural capability, not generic runBackgroundable().persistOutput: "always" at call site.local_bash task notification.run_in_background behavior still uses executionPort.start().