For agentic workers: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: 修复 Windows legacy 会话在 resume 后实际使用 Git Bash 执行 Bash tool,但模型仍沿用历史 CMD 语法并写出 nul 文件的问题。
Architecture: 保持现有 session-start shell snapshot 契约不变:shell 设置变更仍只对新 session 生效。只在 cold resume 发现旧会话没有可用 shell snapshot、最终由当前 auto Git Bash 接管执行时,通过现有 shell_environment_change provider-visible attachment 插入一次语法迁移提醒。实现集中在 runtime shell owner,不改 executor、protocol schema 或设置 UI。
Tech Stack: TypeScript, Vitest, @zcode/core runtime, existing MessageHistory.addAttachment(), existing shell_environment_change system reminder source.
shell_environment_change,避免 provider projection / hydrate / MCS 分类额外迁移面。source: "auto-detected" 且 dialect: "git-bash" 的 selection 接管执行。shell_environment_change attachment 时不重复插入。Modify: apps/zcode-cli/packages/core/src/runtime/methods/shell-environment.ts
ShellEnvironmentResumeNoticeKind,把 “display drift” 和 “Windows auto Git Bash migration” 收敛成一个决策函数。Modify: apps/zcode-cli/packages/core/src/runtime/methods/session-shell-environment.ts
announceSessionShellEnvironmentDriftAfterResume() 重构为 announceSessionShellEnvironmentNoticeAfterResume()。shell-environment.ts 的判定和文案函数,并在插入前检查已有 shell_environment_change attachment。Modify: apps/zcode-cli/packages/core/tests/runtime-persistence.test.ts
Modify: apps/zcode-cli/packages/core/tests/runtime-trace.test.ts
Modify: docs/runtime-tools/bash-effective-shell-snapshot.md
Files:
apps/zcode-cli/packages/core/tests/runtime-persistence.test.tsInterfaces:
AgentRuntime.resumeFromStore(): Promise<ResumeSessionResult>AgentRuntime.executeTurn(input: string): Promise<unknown>providerMessagesToText(messages: readonly ModelInputMessage[]): stringcreateRecordingSessionStore(), createTestSessionEventStore()Produces:
[ ] Step 1: 在 runtime-persistence.test.ts 的 Bash shell persistence 用例附近添加 failing test
Add this test after announces legacy cold-resume Bash shell drift when no shell snapshot exists:
it("announces Windows Git Bash syntax migration for legacy cold-resume sessions", async () => {
const sessionId = createSessionId("runtime-persistence-windows-git-bash-migration");
const store = createRecordingSessionStore();
const workingDirectory = "/tmp/zcode-runtime-windows-git-bash-migration";
const firstRuntime = new AgentRuntime(
sessionId,
{
currentDate: "2026-06-26",
envInfo: {
cwd: workingDirectory,
platform: "win32",
shell: "CMD",
osVersion: "Windows 11",
nodeVersion: "v24.14.0",
},
workingDirectory,
},
{
eventStore: createTestSessionEventStore(),
modelAdapter: {
async generateText() {
return {
text: "first answer",
finishReason: "stop",
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
};
},
} as never,
sessionStore: store,
},
);
await firstRuntime.executeTurn("persisted prompt");
let resumedMessages: ModelInputMessage[] = [];
const resumedRuntime = new AgentRuntime(
sessionId,
{
bashShellSelection: {
dialect: "git-bash",
display: { name: "Git Bash" },
id: "auto:git-bash",
label: "Git Bash",
path: "C:\\Program Files\\Git\\bin\\bash.exe",
source: "auto-detected",
},
currentDate: "2026-06-26",
workingDirectory,
},
{
eventStore: createTestSessionEventStore(),
modelAdapter: {
async generateText(request) {
resumedMessages = request.messages;
return {
text: "resumed answer",
finishReason: "stop",
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
};
},
} as never,
sessionStore: store,
},
);
await resumedRuntime.resumeFromStore();
await resumedRuntime.executeTurn("resumed prompt");
const providerText = providerMessagesToText(resumedMessages);
expect(providerText).toContain("- Shell: CMD");
expect(providerText).toContain(
"The Bash tool shell is Git Bash.",
);
});
Run:
pnpm --filter @zcode/core exec vitest run tests/runtime-persistence.test.ts -t "Windows Git Bash syntax migration"
Expected: FAIL because provider text does not contain the new Git Bash migration reminder.
Add this test after the migration test:
it("does not duplicate the Windows Git Bash migration reminder after repeated resume", async () => {
const sessionId = createSessionId("runtime-persistence-windows-git-bash-migration-once");
const store = createRecordingSessionStore();
const workingDirectory = "/tmp/zcode-runtime-windows-git-bash-migration-once";
const firstRuntime = new AgentRuntime(
sessionId,
{
currentDate: "2026-06-26",
envInfo: {
cwd: workingDirectory,
platform: "win32",
shell: "CMD",
osVersion: "Windows 11",
nodeVersion: "v24.14.0",
},
workingDirectory,
},
{
eventStore: createTestSessionEventStore(),
modelAdapter: {
async generateText() {
return {
text: "first answer",
finishReason: "stop",
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
};
},
} as never,
sessionStore: store,
},
);
await firstRuntime.executeTurn("persisted prompt");
const createResumedRuntime = (capture: (messages: ModelInputMessage[]) => void) =>
new AgentRuntime(
sessionId,
{
bashShellSelection: {
dialect: "git-bash",
display: { name: "Git Bash" },
id: "auto:git-bash",
label: "Git Bash",
path: "C:\\Program Files\\Git\\bin\\bash.exe",
source: "auto-detected",
},
currentDate: "2026-06-26",
workingDirectory,
},
{
eventStore: createTestSessionEventStore(),
modelAdapter: {
async generateText(request) {
capture(request.messages);
return {
text: "resumed answer",
finishReason: "stop",
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
};
},
} as never,
sessionStore: store,
},
);
let firstResumeMessages: ModelInputMessage[] = [];
const firstResume = createResumedRuntime((messages) => {
firstResumeMessages = messages;
});
await firstResume.resumeFromStore();
await firstResume.executeTurn("first resumed prompt");
let secondResumeMessages: ModelInputMessage[] = [];
const secondResume = createResumedRuntime((messages) => {
secondResumeMessages = messages;
});
await secondResume.resumeFromStore();
await secondResume.executeTurn("second resumed prompt");
const firstProviderText = providerMessagesToText(firstResumeMessages);
const secondProviderText = providerMessagesToText(secondResumeMessages);
const reminder =
"The Bash tool shell is Git Bash.";
expect(firstProviderText.match(new RegExp(escapeRegExp(reminder), "g")) ?? []).toHaveLength(1);
expect(secondProviderText.match(new RegExp(escapeRegExp(reminder), "g")) ?? []).toHaveLength(1);
});
Also add this helper near providerMessagesToText():
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
Run:
pnpm --filter @zcode/core exec vitest run tests/runtime-persistence.test.ts -t "Git Bash migration"
Expected: FAIL because implementation does not yet insert the migration reminder and does not yet have idempotence logic.
Files:
apps/zcode-cli/packages/core/src/runtime/methods/shell-environment.tsapps/zcode-cli/packages/core/src/runtime/methods/session-shell-environment.tsInterfaces:
BashShellSnapshotRestore["status"]ExecutionShellSelectionruntime.messageHistory.toRuntimeEntries()runtime.messageHistory.addAttachment("shell_environment_change", body)Produces:
getShellEnvironmentResumeNoticeKind(options): ShellEnvironmentResumeNoticeKind | undefinedbuildShellEnvironmentResumeNotice(kind, selection): stringannounceSessionShellEnvironmentNoticeAfterResume(runtime, options): void[ ] Step 1: Replace shell reminder helpers in shell-environment.ts
Change apps/zcode-cli/packages/core/src/runtime/methods/shell-environment.ts to this shape:
import type { ExecutionShellSelection } from "../deps.js";
import type { BashShellSnapshotRestore } from "./bash-shell-snapshot.js";
export type ShellEnvironmentResumeNoticeKind =
| "display_change"
| "windows_git_bash_auto_migration";
export function getShellEnvironmentResumeNoticeKind(options: {
persistedShell: string | undefined;
restoreStatus: BashShellSnapshotRestore["status"];
selection: ExecutionShellSelection | undefined;
}): ShellEnvironmentResumeNoticeKind | undefined {
if (!options.selection || options.restoreStatus === "restored") {
return undefined;
}
if (isWindowsGitBashAutoMigration(options.selection)) {
return "windows_git_bash_auto_migration";
}
return hasShellDisplayChanged(options.persistedShell, options.selection)
? "display_change"
: undefined;
}
export function buildShellEnvironmentResumeNotice(
kind: ShellEnvironmentResumeNoticeKind,
selection: ExecutionShellSelection,
): string {
if (kind === "windows_git_bash_auto_migration") {
return "The Bash tool shell is Git Bash.";
}
return `The Bash tool shell is ${selection.display.name}.`;
}
export function hasShellDisplayChanged(
previousShell: string | undefined,
selection: ExecutionShellSelection | undefined,
): selection is ExecutionShellSelection {
const previousDisplayName = normalizeShellDisplayName(previousShell);
const nextDisplayName = normalizeShellDisplayName(selection?.display.name);
return previousDisplayName !== undefined && nextDisplayName !== undefined
? previousDisplayName !== nextDisplayName
: false;
}
function isWindowsGitBashAutoMigration(selection: ExecutionShellSelection): boolean {
return selection.dialect === "git-bash" && selection.source === "auto-detected";
}
function normalizeShellDisplayName(value: string | undefined): string | undefined {
const trimmed = value?.trim();
return trimmed && trimmed.length > 0 ? trimmed : undefined;
}
session-shell-environment.ts announce functionUpdate imports:
import {
buildShellEnvironmentResumeNotice,
getShellEnvironmentResumeNoticeKind,
} from "./shell-environment.js";
Replace announceSessionShellEnvironmentDriftAfterResume() with:
export function announceSessionShellEnvironmentNoticeAfterResume(
runtime: AgentRuntimeInternal,
options: {
persistedEnvInfo: EnvInfo | undefined;
restore: BashShellSnapshotRestore;
},
): void {
const selection = getSessionShellSelection(runtime);
const noticeKind = getShellEnvironmentResumeNoticeKind({
persistedShell: options.persistedEnvInfo?.shell,
restoreStatus: options.restore.status,
selection,
});
if (!selection || !noticeKind || hasShellEnvironmentChangeAttachment(runtime)) {
return;
}
// 修复原因:旧 Windows 会话没有可用 shell snapshot 时,升级后可能由 auto Git Bash
// 接管 Bash 执行。历史上下文仍可能让模型继续沿用旧 shell 习惯,因此必须在
// resume 后补一个 provider-visible shell 提醒;可用 snapshot 恢复时不插,避免
// 破坏“shell 设置变更只对新 session 生效”的契约。
runtime.messageHistory.addAttachment(
"shell_environment_change",
buildShellEnvironmentResumeNotice(noticeKind, selection),
);
}
function hasShellEnvironmentChangeAttachment(runtime: AgentRuntimeInternal): boolean {
return runtime.messageHistory
.toRuntimeEntries()
.some((entry) => entry.metadata?.source === "shell_environment_change");
}
In apps/zcode-cli/packages/core/src/runtime/methods/resume.ts, replace the import and call:
import {
announceSessionShellEnvironmentNoticeAfterResume,
getSessionShellSelection,
restoreSessionShellEnvironmentSelectionForResume,
} from "./session-shell-environment.js";
And:
announceSessionShellEnvironmentNoticeAfterResume(this, {
persistedEnvInfo,
restore: shellRestore,
});
Run:
pnpm --filter @zcode/core exec vitest run tests/runtime-persistence.test.ts -t "Git Bash migration"
Expected: PASS for the two migration tests.
Files:
apps/zcode-cli/packages/core/tests/runtime-persistence.test.tsapps/zcode-cli/packages/core/tests/runtime-trace.test.tsInterfaces:
buildShellEnvironmentResumeNotice("display_change", selection) text:
The Bash tool shell is ${selection.display.name}.Produces:
[ ] Step 1: Update missing snapshot drift expectation
In runtime-persistence.test.ts, update:
expect(providerText).toContain(
"The Bash tool shell was changed by the user. Future Bash commands will run using CMD.",
);
to:
expect(providerText).toContain(
"The Bash tool shell is CMD.",
);
In runtime-persistence.test.ts, update:
expect(providerText).toContain(
"The Bash tool shell was changed by the user. Future Bash commands will run using zsh.",
);
to:
expect(providerText).toContain(
"The Bash tool shell is zsh.",
);
In runtime-trace.test.ts, replace the old negative assertion:
expect(requestText).not.toContain(
"The Bash tool shell was changed by the user. Future Bash commands will run using Git Bash.",
);
with:
expect(requestText).not.toContain(
"The Bash tool shell is Git Bash.",
);
expect(requestText).not.toContain(
"The Bash tool shell is Git Bash.",
);
Run:
pnpm --filter @zcode/core exec vitest run tests/runtime-persistence.test.ts -t "shell"
pnpm --filter @zcode/core exec vitest run tests/runtime-trace.test.ts -t "Shell"
Expected: PASS. If runtime-trace.test.ts -t "Shell" matches no tests because test names changed, run the whole file:
pnpm --filter @zcode/core exec vitest run tests/runtime-trace.test.ts
Expected: PASS.
Files:
docs/runtime-tools/bash-effective-shell-snapshot.mdInterfaces:
核心契约, Prompt 与缓存, 非目标Produces:
[ ] Step 1: Update 核心契约 legacy resume bullet
Replace:
- legacy session 如果没有持久化 selection,或持久化 selection 已失效,只能按当前自动解析逻辑 best-effort 恢复;当历史 `# Environment` 的 Shell 与当前执行 shell 不一致时,必须通过 `shell_environment_change` attachment 告知模型。
with:
- legacy session 如果没有持久化 selection,或持久化 selection 已失效,只能按当前自动解析逻辑 best-effort 恢复;当历史 `# Environment` 的 Shell 与当前执行 shell 不一致时,必须通过 `shell_environment_change` attachment 告知模型。Windows legacy session 被当前 auto Git Bash 接管时,即使历史 `# Environment` 没有可靠 Shell 字段,也会插入一次 Git Bash shell 提醒,避免模型继续沿用旧 shell 习惯。
Prompt 与缓存After:
切换 shell 不会向已有 session 追加 `shell_environment_change` attachment。因为 Bash 执行仍然使用 session-start selection,模型看到的初始 `# Environment` 和真实 Bash 执行环境保持一致。
Add:
例外是 legacy/no-usable snapshot 的 cold resume:这类会话没有稳定的 session-start shell selection 可恢复,runtime 只能用当前解析出的 selection 继续执行。若 Windows 上最终由 auto Git Bash 接管,会通过 `shell_environment_change` 插入一次短提醒,告诉模型后续 Bash command 当前使用 Git Bash 执行。这不是同 session 内 shell hot update,也不会读取用户最新设置覆盖已有可用 snapshot。
Run:
git diff -- docs/runtime-tools/bash-effective-shell-snapshot.md
Expected: Diff only documents legacy/no-usable snapshot resume reminder behavior and does not claim existing sessions hot update shell.
Files:
Interfaces:
Produces:
[ ] Step 1: Run focused tests
Run:
pnpm --filter @zcode/core exec vitest run tests/runtime-persistence.test.ts -t "shell"
pnpm --filter @zcode/core exec vitest run tests/runtime-trace.test.ts
Expected: PASS.
Run:
pnpm --filter @zcode/core exec vitest run tests/system-reminder-source.test.ts
Expected: PASS. This verifies reusing shell_environment_change did not break descriptor assumptions.
Run:
pnpm --filter @zcode/core typecheck
Expected: PASS.
Run:
pnpm typecheck
pnpm lint
Expected: PASS. If these are too slow or blocked by unrelated existing workspace changes, capture the exact failure and do not claim full verification.
Run:
git diff -- apps/zcode-cli/packages/core/src/runtime/methods/shell-environment.ts \
apps/zcode-cli/packages/core/src/runtime/methods/session-shell-environment.ts \
apps/zcode-cli/packages/core/src/runtime/methods/resume.ts \
apps/zcode-cli/packages/core/tests/runtime-persistence.test.ts \
apps/zcode-cli/packages/core/tests/runtime-trace.test.ts \
docs/runtime-tools/bash-effective-shell-snapshot.md
Expected:
session-shell-environment.ts.Git Bash migration reminder text is limited to legacy/no usable snapshot resume paths.
[ ] Step 6: Commit
Run:
git add apps/zcode-cli/packages/core/src/runtime/methods/shell-environment.ts \
apps/zcode-cli/packages/core/src/runtime/methods/session-shell-environment.ts \
apps/zcode-cli/packages/core/src/runtime/methods/resume.ts \
apps/zcode-cli/packages/core/tests/runtime-persistence.test.ts \
apps/zcode-cli/packages/core/tests/runtime-trace.test.ts \
docs/runtime-tools/bash-effective-shell-snapshot.md
git commit -m "fix(cli): remind legacy windows sessions about git bash syntax"
Expected: Commit succeeds with only the planned files.
ExecutionShellSelection, BashShellSnapshotRestore, MessageHistory.addAttachment(), and existing shell_environment_change source. It does not introduce protocol/settings/schema fields.if logic is centralized in getShellEnvironmentResumeNoticeKind(), leaving session-shell-environment.ts as the single runtime owner that decides whether to attach a resume notice.