当前 ZCode 的 ExitPlanMode 仍通过 tool input 的 plan 字段承载完整 plan。若 ExitPlanMode 审批后很快触发 compact,summary 可能没有保留完整 plan,compact/resume 后模型无法稳定拿回已批准 plan。
审批通过后的 ExitPlanMode.plan 必须同步写入 workspace root 下的确定性 plan file。compact 成功后,runtime 必须把该 plan file 的路径和完整内容作为 plan_file_reference model-only reminder 持久化到 compact 后历史里。
plan file 路径为:
${workspaceRoot}/.zcode/plans/plan-${sanitizedSessionId}.md
workspaceRoot 表示工作区根路径;不能使用可能被 Bash cd 改变的 workingDirectory。sanitizedSessionId 只保留 A-Z、a-z、0-9、.、_、-,其他字符替换成 -,并去掉首尾 -。
ExitPlanMode 在用户审批通过并应用 permission broker 返回的最终 input 后写 plan file。写入内容必须是最终 plan 原始字符串,不能 trim、补换行或做其他规范化;空 plan 只用于输入校验。写入使用 FileSystemPort.writeTextFile(),参数必须包含 createParents: true、atomic: true、encoding: "utf8"。写失败只影响后续 compact continuity,不阻断用户已批准的退出 plan mode。
compact 成功后,如果确定性 plan file 存在且内容非空,runtime 在 postCompactReminderEntries 中追加 source 为 plan_file_reference 的 model-only reminder,内容格式为:
A plan file exists from plan mode at: ${planFilePath}
Plan contents:
${planContent}
If this plan is relevant to the current work and not already complete, continue working on it.
该 reminder 排在 generic read-state reminders 前面,并通过现有 persistCompactSummary() 与 compact summary 一起持久化;任一步持久化失败时沿用现有 compact persistence rollback。
ExitPlanMode input schema。plan / planFilePath。ExitPlanMode output shape。.zcode/plans 后的恢复。.md,不是 ExitPlanMode、compact 或 session 结束时的即时删除。