@aibyzero/cm-workflow 0.21.1 → 0.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +7 -1
  4. package/VERSION +1 -1
  5. package/docs/installation.md +1 -1
  6. package/docs/js-workflow-control.md +1 -1
  7. package/package.json +1 -1
  8. package/runtime/js/cm-ai/codex-config.mjs +6 -1
  9. package/runtime/js/cm-ai/spec-amendment.mjs +20 -0
  10. package/runtime/js/cm-ai/task-runner.mjs +2 -1
  11. package/runtime/js/cm-ai/worker-codex-developer.mjs +3 -1
  12. package/runtime/js/cm-prd/change.mjs +4 -1
  13. package/runtime/js/cm-prd/review-findings.mjs +3 -2
  14. package/runtime/js/cm-prd/review-publication.mjs +3 -2
  15. package/runtime/js/cm-prd/split-design.mjs +4 -4
  16. package/scripts/cm-ai-admission.test.mjs +5 -5
  17. package/scripts/cm-ai-drive.mjs +1 -1
  18. package/scripts/cm-ai-review-failure.test.mjs +3 -0
  19. package/scripts/cm-codex-developer-worker.test.mjs +13 -1
  20. package/scripts/cm-notify-command.test.mjs +3 -0
  21. package/scripts/cm-notify.test.mjs +3 -0
  22. package/scripts/cm-patrol.test.mjs +3 -0
  23. package/scripts/cm-prd-design-phase.test.mjs +31 -0
  24. package/scripts/cm-prd-review-gate.mjs +28 -3
  25. package/scripts/cm-prd-summary.test.mjs +5 -5
  26. package/scripts/cm-spec-amend.test.mjs +107 -1
  27. package/scripts/cm-specs-status.test.mjs +5 -5
  28. package/scripts/cm-tool-preview-context.test.mjs +20 -1
  29. package/scripts/cm-upgrade-compat.test.mjs +7 -0
  30. package/skills/cm-prd/SKILL.md +14 -27
  31. package/skills/cm-prd/references/change-mode.md +2 -0
  32. package/skills/cm-prd/references/cm-optout.md +11 -0
  33. package/skills/cm-prd/references/context-scope.md +2 -1
  34. package/skills/cm-prd/references/js-host.md +2 -2
  35. package/skills/cm-prd/references/requirement-grilling.md +116 -0
  36. package/skills/cm-product-manager/SKILL.md +13 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-workflow",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "Spec-driven product development workflow for Codex: external research, PRD, implementation, read-only feature testing, review, QA, fixes, refactors, and documentation.",
5
5
  "author": {
6
6
  "name": "cm-workflow maintainers",
package/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@
5
5
 
6
6
  ## 未发布
7
7
 
8
+ ## 0.21.2 — 2026-11-18
9
+
10
+ - **任务提交意图写入与读取同用存档上限,存档上限说明更正**:写入改用 `JOURNAL_PAYLOAD_LIMIT`(4 MiB),与 0.21.1 修好的读取端一致;操作指南与 `cm-ai-drive --help` 写明可归档运行首条记录按 4 MiB、归档引用后的检查点按 4 MiB 减预留,不支持归档的运行仍按 1 MiB 内联上限。(#270)
11
+
12
+ - **cm-prd 遇到项目规则禁用 CM 时先停下问一次**(真实项目实跑:项目规则先后写过「只用 CM」和「不用 CM」):按规则自身声明的优先级判断是否仍生效,仍生效或判断不了就在生成 specs 前引用原文位置问用户,未确认则不写 specs。上下文范围规则的地图读取顺序改为以 Step 4 B1 为准(先看 CLAUDE.md「业务地图」字段),不再与 B1 冲突。
13
+
14
+ - **用 gpt-6.2-sol 审查时预检不再必然失败**(真实项目实跑:codex-cli 0.167.0 给 gpt-6.2-sol 的请求默认带 `request_user_input`、`view_image` 两个工具,「审查进程零工具」预检必然 `passed=false`):审查参数关闭 `view_image` 功能,并加 `-c tools.experimental_request_user_input.enabled=false`;零工具判定不变,编码进程参数不变。审查路径需要 codex-cli 0.153.4 或更新(更旧版本至少有一项不受支持,会在发出请求前启动失败)。参数变了,升级前生成的预检回执不再匹配,原运行需用同样配置重新预检;早期严格批次留有旧缓存时会报 `legacy_preflight_cache_invalid`,按原人工归档出口处理。
15
+
16
+ - **cm-prd 变更不再被旧审查回执误拦**:已批准或经补正换绑的规格,保存变更时改以批准时的版本为准核对,不再因和旧审查回执对不上而被拦;四个规格文件仍整套核对,未经批准的删除仍会被拦(批准轮次里移除可选的 `test-cases.json` 可以放行)。
17
+
18
+ - **cm-prd 会对照现有业务倒推需求缺口,逐轮追问后再出规格**(产品文档常范围不明或漏项,开发中途才暴露):需求分析后按七项清单(角色权限、状态流转、增删改查成对、存量数据、相邻线路、入口通知、报表导出)对照业务地图和代码找缺口;按设计树分轮提问,每轮最多 5 题,每题带出处,能推荐时给推荐答案,可合理默认的汇成默认清单一次确认;改变范围、权限、数据等的问题答完才生成规格。结论写入 `requirements.md` 新增的「范围与覆盖核对」一节;变更模式同样适用。
19
+
8
20
  ## 0.21.1 — 2026-11-17
9
21
 
10
22
  - **接近存档上限的任务提交可以正常读回**(CI 历史组夹具暴露:存档单条上限放到 4 MiB 后,`readCommitIntent` 仍按通用 JSON 校验的 1 MiB 默认值读取,计划接近或超过 1 MiB 的提交意图写得进却读不回):任务提交意图的读取改用 `JOURNAL_PAYLOAD_LIMIT`,与写入侧一致;运行器构造记录(`boundRunnerRecord`)先按同一上限校验载荷,再校验整条记录(上限加 1 KiB 外层余量)。
package/README.md CHANGED
@@ -17,6 +17,12 @@
17
17
 
18
18
  ## 最近更新
19
19
 
20
+ **0.21.2**
21
+
22
+ - **cm-prd 遇到项目规则禁用 CM 时先问一次**:项目规则写了「不用 CM」且仍有效时,生成规格前先问你,未确认不写规格。
23
+ - **用 gpt-6.2-sol 审查时预检不再必然失败**:审查进程关掉 Codex 0.167 默认带上的两个工具。
24
+ - **cm-prd 会对照现有业务倒推需求缺口,逐轮追问后再出规格**:分析需求后,对照业务地图和代码检查角色权限、状态流转、增删改查、老数据、相邻功能、入口通知、报表导出七项,找出文档漏掉的地方;分轮提问,每轮最多 5 题,每题带出处,能推荐时给推荐答案;会改变范围、权限、数据的问题答完才生成规格。详见[更新日志](CHANGELOG.md)。
25
+
20
26
  **0.21.1**
21
27
 
22
28
  - **接近存档上限的任务提交可以正常读回**:单条存档上限放到 4 MiB 后,任务提交记录读取时仍按 1 MiB 校验,超过 1 MiB 的提交写得进却读不回;现在读写同用一个上限。
@@ -281,7 +287,7 @@ $cm-check
281
287
 
282
288
  仓库直接分发 Skills 和脚本,无需在仓库根目录运行 `npm install` 或构建。完整安装行为、覆盖范围和卸载说明见[安装指南](docs/installation.md)。
283
289
 
284
- 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.1 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
290
+ 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.2 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
285
291
 
286
292
  ## 升级旧版本
287
293
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 0.21.1
1
+ 0.21.2
@@ -76,7 +76,7 @@ Install or upgrade with the same command:
76
76
  npx @aibyzero/cm-workflow@latest install
77
77
  ```
78
78
 
79
- To pin a version, use `npx @aibyzero/cm-workflow@0.21.1 install` from outside
79
+ To pin a version, use `npx @aibyzero/cm-workflow@0.21.2 install` from outside
80
80
  the CM Workflow source checkout (for example, your home directory). Inside a
81
81
  checkout with the same package name and version, npm can select the local
82
82
  uninstalled package and report `cm-workflow: command not found`.
@@ -779,7 +779,7 @@ node scripts/cm-ai-host.mjs serve --config /absolute/run.json --mode create \
779
779
 
780
780
  批次驾驶员同样直接审查;缺第二轮答案时为该任务加 `--hold-revision FEATURE/TASK`。旗标只缩小本次启动能力,不持久化、不进入指纹;审查批准时不受影响。
781
781
 
782
- `develop.json.edits` 的值可以是内容文件名(写入,已有文件保留权限,新文件 0644)、`{file,mode}`、`{mode}`(只改权限位)或 `{delete:true}`;`mode` 只接受 `"0755"`、`"0644"`,改名为删旧写新;同时是 requirements 的 scope 路径不能删除,启动前拒绝,当前会话仍删除时停在可重试的 `blocked/develop_requirement_missing`(范围外改动仍先按 `unknown/out_of_scope` 处理)。运行存档单条记录上限为 1 MiB:开发检查点连同 base64 审查包须在 1 MiB 减去为后续审查与完成记录推出的预留之内。审查结果除 examinedPaths 外以 12 KiB JSON 为界(超出按固定规则截断 finding 文字与 summary、必要时从末尾省略 finding,先 P3 且至少保留一条阻断 finding,verdict 不变),完成检查点最多重复它 13 次,预留 = 13 ×(examinedPaths + 12 KiB)+ 2 ×(已有回执 + 调用 + Learning 回写)+ 96 KiB;驾驶员用宿主同一套审查包、handoff、Learning 证据与 AGENTS.md 回写代码在启动前核算(含 handoff)并拒绝超限交付,任务基线装不进一条记录时驾驶员与宿主都在建存档前拒绝;当前会话仍交付超限改动时停在可重试的 `blocked/develop_package_too_large`,不再以 `unknown/store_failure` 结束,旧 journal 格式与回放不变。开发阶段阻断在第 2 轮重做本轮交付时不再对照第 1 轮审查包(该交付本就改了代码),第 2 轮 `develop_checks_not_passed` 等因此可在原轮次重试;审查中漂移的 `review_package_changed` 仍须先恢复到已审代码。审查包的文件记录本就含 `mode`,删除为 `after:null`,审查提示会说明二者;包验证逐字段比较,事后改权限同样判为漂移,旧基线和旧包格式不变。驾驶员启动前按审查包上限拒绝单文件超过 1 MiB、材料(与审查包快照同一选取:scope、requirements 与树中全部 AGENTS.md)合计超过 2 MiB 或 256 个文件及与基线完全相同的交付,报错带路径与上限;当前会话若仍交付空改动,运行停在可重试的 `blocked/develop_empty_changes`,旧 `unknown/empty_changes` 历史按原样回放。新建运行要求 `runId` 满足运行日志规则(8–128 个字符),已有运行恢复不变。
782
+ `develop.json.edits` 的值可以是内容文件名(写入,已有文件保留权限,新文件 0644)、`{file,mode}`、`{mode}`(只改权限位)或 `{delete:true}`;`mode` 只接受 `"0755"`、`"0644"`,改名为删旧写新;同时是 requirements 的 scope 路径不能删除,启动前拒绝,当前会话仍删除时停在可重试的 `blocked/develop_requirement_missing`(范围外改动仍先按 `unknown/out_of_scope` 处理)。运行存档单条记录上限为 4 MiB(`JOURNAL_PAYLOAD_LIMIT`)。开发检查点的内联预算为单条记录上限(默认 4 MiB)与 1 MiB 取较小值后减去为有界审查与完成记录推出的预留,最低为 0 字节;不支持材料归档的运行(批量、并行、bootstrap 等)按含 base64 审查包的完整检查点核算此预算;支持归档的运行若同一审查包已有归档则直接引用,并要求完整检查点减去审查包大小再加 512 字节后不超过单条记录上限减去预留;若尚未归档且完整检查点装得进内联预算则内联;否则仅在完整检查点加 1 KiB 仍不超过单条记录上限、且引用后的估算大小也符合上述引用预算时首次归档。审查结果除 examinedPaths 外以 12 KiB JSON 为界(超出按固定规则截断 finding 文字与 summary、必要时从末尾省略 finding,先 P3 且至少保留一条阻断 finding,verdict 不变),完成检查点最多重复它 13 次,预留 = 13 ×(examinedPaths + 12 KiB)+ 2 ×(已有回执 + 调用 + Learning 回写)+ 96 KiB;驾驶员用宿主同一套审查包、handoff、Learning 证据与 AGENTS.md 回写代码在启动前核算(含 handoff)并拒绝超限交付,任务基线装不进一条记录时驾驶员与宿主都在建存档前拒绝;当前会话仍交付超限改动时停在可重试的 `blocked/develop_package_too_large`,不再以 `unknown/store_failure` 结束,旧 journal 格式与回放不变。开发阶段阻断在第 2 轮重做本轮交付时不再对照第 1 轮审查包(该交付本就改了代码),第 2 轮 `develop_checks_not_passed` 等因此可在原轮次重试;审查中漂移的 `review_package_changed` 仍须先恢复到已审代码。审查包的文件记录本就含 `mode`,删除为 `after:null`,审查提示会说明二者;包验证逐字段比较,事后改权限同样判为漂移,旧基线和旧包格式不变。驾驶员启动前按审查包上限拒绝单文件超过 1 MiB、材料(与审查包快照同一选取:scope、requirements 与树中全部 AGENTS.md)合计超过 2 MiB 或 256 个文件及与基线完全相同的交付,报错带路径与上限;当前会话若仍交付空改动,运行停在可重试的 `blocked/develop_empty_changes`,旧 `unknown/empty_changes` 历史按原样回放。新建运行要求 `runId` 满足运行日志规则(8–128 个字符),已有运行恢复不变。
783
783
 
784
784
  review.json 含 `{model, disabledSkills, preflight}`,另有可选 `timeoutMs`;disabledSkills 是本机探测实际发现并
785
785
  禁用的 Skill 路径,preflight 沿原配置指纹/模型/stdin 合同。探测输出不包含原始诊断、
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibyzero/cm-workflow",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "Spec-driven business development workflow for Pi, Codex, and Claude Code",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -24,14 +24,19 @@ export const disabledFeatures = Object.freeze([
24
24
  'shell_tool', 'unified_exec', 'shell_snapshot', 'multi_agent', 'goals',
25
25
  'memories', 'image_generation', 'code_mode_host', 'workspace_dependencies',
26
26
  'skill_mcp_dependency_install', 'tool_suggest',
27
+ // codex-cli 0.167.0 sends view_image to gpt-6.2-sol by default (2026-11-17 preflight failure).
28
+ 'view_image',
27
29
  ]);
30
+ // Review-only config: codex-cli 0.167.0 also sends request_user_input to gpt-6.2-sol, and no
31
+ // feature flag removes it; this key does (checked offline with tool-preview, 6.1 and 6.2 both 0 tools).
32
+ export const NO_USER_INPUT_TOOL='tools.experimental_request_user_input.enabled=false';
28
33
 
29
34
  export function commonArgs({ cwd, model, effort, disabledSkills = [] }) {
30
35
  if (!/^[a-zA-Z0-9._-]+$/.test(model)) throw new Error('invalid model');
31
36
  return ['exec', '--ignore-user-config', '--strict-config', '--ephemeral',
32
37
  '--sandbox', 'read-only', '--skip-git-repo-check', '--cd', cwd, '--json',
33
38
  ...disabledFeatures.flatMap(name => ['--disable', name]),
34
- '-c', 'approval_policy="never"', '-c', 'web_search="disabled"',
39
+ '-c', 'approval_policy="never"', '-c', 'web_search="disabled"', '-c', NO_USER_INPUT_TOOL,
35
40
  '-c', 'project_doc_max_bytes=0', '-c', 'mcp_servers={}',
36
41
  '-c', 'check_for_update_on_startup=false', '-c', 'analytics.enabled=false',
37
42
  '-c', `model="${model}"`, '-c', `model_reasoning_effort=${JSON.stringify(externalEffort('codex',effort))}`,
@@ -27,6 +27,7 @@ export function roundLedgerPath(specsDir){
27
27
  export const AMEND_LIMIT=3;
28
28
  export const REVIEW_MARKER='cmSpecAmendReview';
29
29
  const FILES=['requirements.md','design.md','tasks.md','test-cases.json'];
30
+ export const APPROVED_SPEC_FILES=Object.freeze([...FILES]);
30
31
  const FEATURE=/^\d+\.[^/\\]+$/;
31
32
  const ACCEPTANCE=/^\s*[-*]\s+(?:\[[ xX]\]\s+)?(?:\[(AC-\d{3,})\]|(AC-\d{3,}))(?=[:\s])/;
32
33
  const AC_REF=/AC-\d{3,}/g;
@@ -293,6 +294,25 @@ function compareTestCases(before,after,reasons,name){
293
294
  const rawBytes=target=>{try{return fs.readFileSync(target);}catch{return null;}};
294
295
  const sameBytes=(a,b)=>a===null?b===null:b!==null&&a.equals(b);
295
296
 
297
+ // The bytes the latest human approval bound, as re-bound only by applied amendments:
298
+ // path -> runtime-mark-normalized sha256. Null unless status is approved and the
299
+ // snapshot, the out-of-tree round ledger and the status all name the same round, so a
300
+ // restored older snapshot or a hand-synced one never becomes a baseline.
301
+ export function approvedSpecBaseline(specsDir){
302
+ const statusPath=path.join(specsDir,'.cm-specs-status'),snapshotPath=path.join(specsDir,SNAPSHOT_FILE);
303
+ const statusBytes=rawBytes(statusPath),snapshotBytes=rawBytes(snapshotPath),roundBytes=readRound(specsDir);
304
+ const status=readSpecsStatus(specsDir),snapshot=readApprovalSnapshot(specsDir);
305
+ if(!sameBytes(statusBytes,rawBytes(statusPath))||!sameBytes(snapshotBytes,rawBytes(snapshotPath))
306
+ ||!sameBytes(roundBytes,readRound(specsDir)))return null;
307
+ if(status.kind!=='valid'||snapshot.kind!=='valid'||status.value.status!=='approved')return null;
308
+ const listed=status.value.specFiles;
309
+ if(!Array.isArray(listed)||!listed.every(row=>record(row)&&typeof row.path==='string'&&typeof row.sha256==='string'))return null;
310
+ const bound=snapshot.value,rows=snapshotRows(bound.files);
311
+ if(roundProblem(roundBytes,snapshotBytes,bound.approval.at)
312
+ ||rowsDigest(listed)!==rowsDigest(rows)||status.value.approval?.at!==bound.approval.at)return null;
313
+ return new Map(rows.map(row=>[row.path,row.sha256]));
314
+ }
315
+
296
316
  export function inspectSpecAmendment(specsDir){
297
317
  const reasons=[],statusPath=path.join(specsDir,'.cm-specs-status'),snapshotPath=path.join(specsDir,SNAPSHOT_FILE);
298
318
  const statusBytes=rawBytes(statusPath),snapshotBytes=rawBytes(snapshotPath),roundBytes=readRound(specsDir);
@@ -816,7 +816,8 @@ export function createTaskRunner(options) {
816
816
  need(liveToken===token&&state==='committing'&&busy&&completeEffect,'commit_capability_invalid');
817
817
  if(action==='guard'){storeOperation(currentStore);return ack();}
818
818
  need(action==='append-intent'?phase==='prepared':phase==='intent','commit_phase_invalid');
819
- const fields={effectId:completeEffect.effect.id,completeIntentDigest:completeEffect.digest,commit:json(payload)};
819
+ // Same bound as readCommitIntent: a commit record the reader accepts must also be writable.
820
+ const fields={effectId:completeEffect.effect.id,completeIntentDigest:completeEffect.digest,commit:json(payload,JOURNAL_PAYLOAD_LIMIT)};
820
821
  const type=action==='append-intent'?'task-commit-intent':'task-commit-result';
821
822
  // Invalid caller data is rejected before invoking the appender. The actual
822
823
  // append repeats preflight against its protected current cursor.
@@ -4,7 +4,7 @@ import {createProviderUsageCapture} from './provider-usage.mjs';
4
4
  import {signalOwnedGroup} from './process-group-exit.mjs';
5
5
  import {spawn} from 'node:child_process';
6
6
  import {fileURLToPath} from 'node:url';
7
- import {commonArgs,cleanEnvironment,specsPermissionArgs} from './codex-config.mjs';
7
+ import {commonArgs,cleanEnvironment,specsPermissionArgs,NO_USER_INPUT_TOOL} from './codex-config.mjs';
8
8
  import {need,text,validCallTimeout,json} from './effect-contract.mjs';
9
9
  import {CODEX_RECONNECT_NOTICE_LIMIT,isCodexReconnectNotice} from './codex-reconnect-notice.mjs';
10
10
  import {codexRateLimited,CODEX_FAILURE_GRACE_MS} from './worker-codex.mjs';
@@ -20,6 +20,8 @@ export function developerArgs({cwd,model,effort,schemaPath,disabledSkills=[],spe
20
20
  // Codex 0.153.4 uses code_mode_host for tool execution; keep its default
21
21
  // on the coding path without enabling the separate code_mode feature.
22
22
  if(args[i]==='--disable'&&(coding.has(args[i+1])||args[i+1]==='code_mode_host')){i++;continue;}
23
+ // The review-only removals for Codex 0.167 leave the coding tool surface as it was.
24
+ if(args[i]==='--disable'&&args[i+1]==='view_image'||args[i]==='-c'&&args[i+1]===NO_USER_INPUT_TOOL){i++;continue;}
23
25
  result.push(args[i]==='read-only'&&args[i-1]==='--sandbox'?'workspace-write':args[i]);
24
26
  }
25
27
  return [...result,...[...coding].flatMap(name=>['--enable',name]),
@@ -10,6 +10,7 @@ import {loadConfig,resolveRole} from '../../../scripts/cm-workflow-config.mjs';
10
10
  import {buildManifest} from '../../../scripts/cm-spec-manifest.mjs';
11
11
  import {specLines,taskDeclarations,TASK_GRAMMAR,LEGACY_TASK_GRAMMAR,recordedTaskGrammar} from '../spec-task-line.mjs';
12
12
  import {inspectPrdReview} from '../../../scripts/cm-prd-review-gate.mjs';
13
+ import {approvedSpecBaseline} from '../cm-ai/spec-amendment.mjs';
13
14
  import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
14
15
  import {prdTreeFileDigest} from './tree-digest.mjs';
15
16
  import {writeImmutableWorkflowFile} from '../cm-ai/review-evidence-file.mjs';
@@ -290,6 +291,8 @@ export function assertPrdReviewsSettled(specs,selected,{requireSplit=false}={}){
290
291
  const archive=read(specs,`.reviews/prd-change-${status.revisionDigest}.json`);
291
292
  if(archive!==null){const value=JSON.parse(archive);need(value.proposal.proposalDigest===status.revisionDigest,'prd_revision_archive_invalid');historical=value.before.reviews;}
292
293
  }
294
+ // Receipts predate later human approvals and applied amendments; those bound bytes count too.
295
+ const approvedBaseline=approvedSpecBaseline(specs);
293
296
  for(const directory of selected)for(const stage of ['design','split']){
294
297
  const feature=directory.replace(/^\d+\./,''),prefix=`prd-${feature}-${stage}`;
295
298
  for(const suffix of ['-dispatch.json','-r1.md','-r2.md','-disposition.json'])readCmInitSource(specs,`.reviews/${prefix}${suffix}`);
@@ -299,7 +302,7 @@ export function assertPrdReviewsSettled(specs,selected,{requireSplit=false}={}){
299
302
  need(sha(readCmInitSource(specs,file))===hash,'prd_change_review_changed');
300
303
  continue;
301
304
  }
302
- const gate=inspectPrdReview({stage,feature,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)});
305
+ const gate=inspectPrdReview({stage,feature,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`),approvedBaseline});
303
306
  need(['dispatch_once','completed'].includes(gate.outcome),'prd_revision_prior_review_unresolved');
304
307
  if(requireSplit&&stage==='split')need(gate.outcome==='completed','prd_revision_original_split_required');
305
308
  }
@@ -5,7 +5,8 @@ import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
5
5
  import {publishPrdReview} from './review-publication.mjs';
6
6
  import {need,shape,json,digest} from '../cm-ai/effect-contract.mjs';
7
7
 
8
- export function inspectPrdFindings({specs,stage,feature,pendingSplit=null}){
8
+ // approvedBaseline: change-mode only, see assertPrdReviewsSettled.
9
+ export function inspectPrdFindings({specs,stage,feature,pendingSplit=null,approvedBaseline=null}){
9
10
  need(typeof specs==='string'&&fs.realpathSync(specs)===specs,'prd_review_root_invalid');
10
11
  need(['design','split'].includes(stage),'prd_review_stage_invalid');
11
12
  const match=typeof feature==='string'&&feature.match(/^([1-9]\d*)\.([a-z0-9]+(?:-[a-z0-9]+)*)$/);
@@ -23,7 +24,7 @@ export function inspectPrdFindings({specs,stage,feature,pendingSplit=null}){
23
24
  const packageDigest=digest(archive.reviewPackage);
24
25
  // Reuse the publisher's complete validation and exact-byte projection, but
25
26
  // inspect only: never repair, recreate, overwrite or dispatch from this read.
26
- const verified=publishPrdReview({specs,...archive,packageDigest,inspectOnly:true,pendingSplit});
27
+ const verified=publishPrdReview({specs,...archive,packageDigest,inspectOnly:true,pendingSplit,approvedBaseline});
27
28
  const result=archive.response.result;
28
29
  return json({status:'review_findings_ready',stage,feature,packageDigest,
29
30
  draftDigest:archive.reviewPackage.draftDigest,evidence:relative,gate:verified.gate,
@@ -36,7 +36,8 @@ export function inspectPrdReviewResponse({reviewPackage,packageDigest,authorCont
36
36
  return {response,result,examinedPaths,degraded};
37
37
  }
38
38
 
39
- export function publishPrdReview({specs,reviewPackage,packageDigest,authorContextId,response,inspectOnly=false,pendingSplit=null}){
39
+ export function publishPrdReview({specs,reviewPackage,packageDigest,authorContextId,response,inspectOnly=false,pendingSplit=null,approvedBaseline=null}){
40
+ need(approvedBaseline===null||inspectOnly,'prd_review_approved_baseline_inspect_only');
40
41
  inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId,response});
41
42
  if(!inspectOnly)assertPrdBatchActive(specs,[reviewPackage.feature]);
42
43
  reviewPackage=json(reviewPackage,256*1024);response=json(response,64*1024);id(authorContextId);
@@ -48,7 +49,7 @@ export function publishPrdReview({specs,reviewPackage,packageDigest,authorContex
48
49
  const reviews=path.join(specs,'.reviews');
49
50
  need(fs.realpathSync(reviews)===reviews&&fs.lstatSync(reviews).isDirectory(),'prd_review_path_invalid');
50
51
  const stage=reviewPackage.stage,feature=match[2],prefix=`prd-${feature}-${stage}`;
51
- const args={stage,feature,pendingSplit,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)};
52
+ const args={stage,feature,pendingSplit,approvedBaseline,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)};
52
53
  const gate=inspectPrdReview(args);
53
54
  need(gate.package_sha256===packageDigest&&['dispatch_unknown','resume_disposition','completed'].includes(gate.outcome),
54
55
  'prd_review_unclaimed');
@@ -8,13 +8,13 @@ import {inspectPrdDispositionPlan} from './disposition-plan.mjs';
8
8
  import {need,digest} from '../cm-ai/effect-contract.mjs';
9
9
  const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
10
10
 
11
- export function inspectPrdSplitDesign({specs,feature,originalSha,requirementsSha,draftDigest,pendingSplit=null,document='design.md'}){
11
+ export function inspectPrdSplitDesign({specs,feature,originalSha,requirementsSha,draftDigest,pendingSplit=null,document='design.md',approvedBaseline=null}){
12
12
  need(['requirements.md','design.md'].includes(document),'prd_split_document_invalid');
13
13
  const targetPath=`${feature}/${document}`;
14
14
  const changedError=document==='requirements.md'?'prd_design_requirements_changed':'prd_design_receipt_changed';
15
15
  const prefix=`.reviews/prd-${feature.replace(/^\d+\./,'')}-split`;
16
16
  if(readCmInitSource(specs,prefix+'-r1.md')===null)return null;
17
- const review=inspectPrdFindings({specs,stage:'split',feature});
17
+ const review=inspectPrdFindings({specs,stage:'split',feature,approvedBaseline});
18
18
  const designPath=`${feature}/design.md`,requirementsPath=`${feature}/requirements.md`;
19
19
  const baseline=prdSelfCheckRevisionBaseline(specs,feature,{originalSha,requirementsSha,draftDigest});
20
20
  need(draftDigest===undefined||draftDigest===baseline.draftDigest,'prd_split_design_binding_changed');
@@ -45,7 +45,7 @@ export function inspectPrdSplitDesign({specs,feature,originalSha,requirementsSha
45
45
 
46
46
  // Used by the shared receipt gate, including summary, publication and revision.
47
47
  // Legacy receipts without a host archive retain their original strict behavior.
48
- export function acceptsPrdSplitDesign({specs,evidence,receipt,item,currentSha,pendingSplit=null}){
48
+ export function acceptsPrdSplitDesign({specs,evidence,receipt,item,currentSha,pendingSplit=null,approvedBaseline=null}){
49
49
  if(receipt.stage!=='design'||!item.path.endsWith('/design.md'))return null;
50
50
  const bytes=readCmInitSource(specs,evidence);
51
51
  const line=bytes?.toString('utf8').match(/\n```json\n([^\n]+)\n```\n$/);
@@ -61,7 +61,7 @@ export function acceptsPrdSplitDesign({specs,evidence,receipt,item,currentSha,pe
61
61
  // accepted requirements/design bytes; pending plans require exact saved hashes.
62
62
  const baseline=prdSelfCheckRevisionBaseline(specs,pkg.feature,{designDraftDigest:pkg.draftDigest,originalSha:item.sha256,requirementsSha});
63
63
  const splitSha=inspectPrdSplitDesign({specs,feature:pkg.feature,originalSha:item.sha256,requirementsSha,
64
- pendingSplit:currentSha===baseline.originalSha?null:pendingSplit});
64
+ pendingSplit:currentSha===baseline.originalSha?null:pendingSplit,approvedBaseline});
65
65
  const completed=readCmInitSource(specs,`.reviews/prd-${receipt.feature}-split-disposition.json`)!==null;
66
66
  return (completed||splitSha!==null?splitSha:baseline.originalSha)===currentSha;
67
67
  }
@@ -9,11 +9,11 @@ import {parseFeatureTaskText,validDependencies,identifyApprovedBootstrapFeature,
9
9
  import {validateRunDefinition} from './cm-ai-run.mjs';
10
10
  import {buildManifest} from './cm-spec-manifest.mjs';
11
11
  // Spec approvals write a round ledger under CM_WORKFLOW_HOME; keep it off the real home.
12
- if(!process.env.CM_WORKFLOW_HOME){
13
- const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
14
- process.env.CM_WORKFLOW_HOME=isolatedHome;
15
- process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
16
- }
12
+ // Always, not only when unset: an exported CM_WORKFLOW_HOME may be the tester's real home
13
+ // (review 2026-11-17: these suites left 11 approval records in an externally named home).
14
+ const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
15
+ process.env.CM_WORKFLOW_HOME=isolatedHome;
16
+ process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
17
17
 
18
18
  const entry=fileURLToPath(new URL('./cm-ai-admission.mjs',import.meta.url));
19
19
  function fixture(run){
@@ -607,7 +607,7 @@ function load(){
607
607
  process.stdout.write('新版 PLAN.controlConfig 为相对 PLAN 的 v2 控制配置路径;development、bootstrap、qa、qaFix 使用明确模式,permissions 禁止所有 --allow-*。普通 advance 自动独立审查;缺少 develop-a2.json 时保持 revision_answer_required。显式恢复需要 resume 与此前 status 返回的 PLAN.expectedControl,驾驶员不会读取新目标覆盖它。\n');
608
608
  process.stdout.write('用法: cm-ai-drive.mjs --plan PLAN.json <operation>\nPLAN: config, mode, hostContext, originalHostContext (换会话 resume 必填), runtime, permissions, answers, checks, checkTimeoutMs。\nchecks 每项为 {id,command,timeoutMs?};checkTimeoutMs 与每项 timeoutMs 为 1..3600000 整数,默认 900000 ms(15 分钟)。\nabandon_review 需要 mode:resume、permissions:["--allow-abandon-review"] 与 PLAN.reason;abandon_effect 需要 mode:resume、permissions:["--allow-abandon-effect"] 与 PLAN.reason(均为单行、最多 500 UTF-8 字节)。develop_redo 需要 mode:resume、permissions:["--allow-develop-redo"] 与 PLAN.reason,先确认会话已停止修改代码。 bootstrap_review_recover 需要 mode:resume、permissions:["--allow-bootstrap-review-recovery"] 与 PLAN.reason;只核对原运行的已写规则与 handoff,不需要答案文件。\n人工答案放 answers/;check 只运行 PLAN.checks,不读取静态执行证据。bootstrap T-001 骨架可用;T-002 规范任务(纯规范 scope、单代码根、非 --protected-config)读 answers/init-generate.json({status:"generated",documents:[{path,contentFile}]},覆盖全部 targets)与 answers/init-verify.json(commands 为驾驶员实跑的草稿命令 {id,command,timeoutMs?},可选 commandsNotRun;checks 只含 globs/file_references/constraint_preservation/rule_applicability;constraintChanges:[];application/retrospective 沿原 Learning);第 1 轮也可用 *-a1.json,第 2 轮只读 init-generate-a2.json 与 init-verify-a2.json,审查自动派发;缺少第2轮草稿时先停在 changes_requested,读取首轮 findings 后再写草稿。commands 在宿主接受启动后、发送操作前由驾驶员实跑(须先带 --allow-bootstrap-write 等宿主授权;受保护模式在 specs 沙箱内),失败或改动了预检核对的文件即退出 2 且不发送操作(create 时改用 resume 重跑);结果只来自实跑,答案文件不能提供。\n'
609
609
  +'develop.json.edits 每项是 scope 路径到下列之一:"内容文件"(写入;已有文件保留权限,新文件 0644)、{"file":"内容文件","mode":"0755"|"0644"}、{"mode":"0755"|"0644"}(只改已有文件权限)、{"delete":true}(删除已有文件)。改名 = 删旧路径 + 写新路径,两者都要在 scope 内;同时列在 requirements 里的路径不能删除。\n'
610
- +'启动前拒绝:单个 scope 文件超过 1 MiB、审查材料(按审查包快照:scope、requirements 与树中全部 AGENTS.md 正文)合计超过 2 MiB 或超过 256 个文件、交付后与任务基线完全相同(edits 为空或内容和权限都没变)、开发检查点(含 handoff 与 AGENTS.md 回写,按宿主同一套构建代码计)装不进运行存档单条 1 MiB 记录减去为有界审查与完成记录推出的预留,或任务基线装不进一条记录。受保护模式(--protected-conversation-config)只收合法 UTF-8 文本,应答大于 --input-limit(默认 65536)时提示应加的值。\n'
610
+ +'启动前拒绝:单个 scope 文件超过 1 MiB、审查材料(按审查包快照:scope、requirements 与树中全部 AGENTS.md 正文)合计超过 2 MiB 或超过 256 个文件、交付后与任务基线完全相同(edits 为空或内容和权限都没变)、开发检查点(含 handoff 与 AGENTS.md 回写,按宿主同一套构建代码计)超出存档上限(开发检查点的内联预算为单条记录上限(默认 4 MiB)与 1 MiB 取较小值后减去为有界审查与完成记录推出的预留,最低为 0 字节;不支持材料归档的运行(批量、并行、bootstrap 等)按含 base64 审查包的完整检查点核算此预算;支持归档的运行若同一审查包已有归档则直接引用,并要求完整检查点减去审查包大小再加 512 字节后不超过单条记录上限减去预留;若尚未归档且完整检查点装得进内联预算则内联;否则仅在完整检查点加 1 KiB 仍不超过单条记录上限、且引用后的估算大小也符合上述引用预算时首次归档),或任务基线装不进一条记录。受保护模式(--protected-conversation-config)只收合法 UTF-8 文本,应答大于 --input-limit(默认 65536)时提示应加的值。\n'
611
611
  +'runId 需 8–128 个字符(运行日志要求),create 前检查。resume 时按存档里的当前轮次发送 identity,第 2 轮的 decision/complete/qa 等无需手改。\n');
612
612
  process.exit(0);
613
613
  }
@@ -24,6 +24,9 @@ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
24
24
  import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
25
25
  import {rateLimitRetryEligible} from '../runtime/js/cm-ai/drive-rate-limit.mjs';
26
26
  import {guardFixtureSource,killFixtureProcesses} from './fixtures/process-cleanup.mjs';
27
+ // An exported CM_NOTIFY_OFF silences every notice; these fixtures expect notices on
28
+ // (review 2026-11-17). Tests of the switch itself set it explicitly.
29
+ delete process.env.CM_NOTIFY_OFF;
27
30
 
28
31
  // Native V3 runner fixtures require Node 24.14+ on macOS/Linux. Preserve the
29
32
  // suite's existing explicit platform gate; only CLI fixtures spawn POSIX shims.
@@ -42,13 +42,25 @@ test('coding argv enables tools without weakening reviewer argv',()=>{
42
42
  for(const name of ['shell_tool','unified_exec','code_mode_host']){
43
43
  assert(reviewDisabled.includes(name));assert(!codingDisabled.includes(name));
44
44
  }
45
- assert.deepEqual(codingDisabled,reviewDisabled.filter(name=>!['shell_tool','unified_exec','code_mode_host'].includes(name)));
45
+ // view_image is a review-only removal (Codex 0.167 / gpt-6.2); coding keeps its old surface.
46
+ assert.deepEqual(codingDisabled,reviewDisabled.filter(name=>!['shell_tool','unified_exec','code_mode_host','view_image'].includes(name)));
46
47
  assert.deepEqual(values(coding,'--enable'),['shell_tool','unified_exec']);
47
48
  assert(!coding.includes('code_mode'));assert(!coding.includes('code_mode_host'));
48
49
  assert(coding.includes('sandbox_workspace_write.network_access=false'));
49
50
  assert.equal(coding.at(-1),'-');assert(!coding.includes('--dangerously-bypass-approvals-and-sandbox'));
50
51
  });
51
52
 
53
+ // 实跑事故(2026-11-17,codex-cli 0.167.0):gpt-6.2-sol 默认多带 request_user_input、view_image
54
+ // 两个工具,审查预检的「零工具」判定必然失败。审查参数关掉这两个;编码参数保持原样。
55
+ test('review argv removes the default tools Codex 0.167 adds for gpt-6.2; coding argv keeps them',()=>{
56
+ const options={cwd:'/fixture',model:'gpt-6.2-sol',schemaPath:'/schema.json'};
57
+ const review=commonArgs(options),coding=developerArgs(options);
58
+ const values=(args,flag)=>args.flatMap((arg,i)=>arg===flag?[args[i+1]]:[]);
59
+ assert(values(review,'--disable').includes('view_image'));
60
+ assert.equal(values(review,'-c').filter(arg=>arg==='tools.experimental_request_user_input.enabled=false').length,1);
61
+ assert(!values(coding,'--disable').includes('view_image'));
62
+ assert(!coding.includes('tools.experimental_request_user_input.enabled=false'));
63
+ });
52
64
  test('coding and review argv both suppress the user skills catalog (2026-09-16: 18249 -> 11706 input tokens)',()=>{
53
65
  const options={cwd:'/fixture',model:'fixture',schemaPath:'/schema.json'};
54
66
  for(const args of [developerArgs(options),commonArgs(options)]){
@@ -11,6 +11,9 @@ import {spawnSync} from 'node:child_process';
11
11
  import {fileURLToPath} from 'node:url';
12
12
  import {parseAssignments,readPrivateFile,readSecret,runSender,responseCodeType,readRegularFile,entryDecision,WINDOWS_UNSUPPORTED,SEND_EXIT} from '../runtime/js/notify-send.mjs';
13
13
  import {main,notifyStatus,switchChannel,turnOff,sendTest,formatTest,previewText,formatPreview,managedSenderPath,classifyCommand,SENDER_SOURCE,TEMPLATES} from './cm-notify.mjs';
14
+ // An exported CM_NOTIFY_OFF silences every notice; these fixtures expect notices on
15
+ // (review 2026-11-17). Tests of the switch itself set it explicitly.
16
+ delete process.env.CM_NOTIFY_OFF;
14
17
 
15
18
  // Every test works in its own temp CM_WORKFLOW_HOME / log home / HOME: the
16
19
  // real ~/.cm-workflow/notify.json would push to the user's phone.
@@ -15,6 +15,9 @@ import {notify,notifyLater,cancelPendingNotice,clearAttention,sessionTitle,sched
15
15
  const DEFAULT_HOME=fs.mkdtempSync(path.join(os.tmpdir(),'cm-notify-default-home-'));
16
16
  process.env.CM_WORKFLOW_HOME=DEFAULT_HOME;
17
17
  process.on('exit',()=>fs.rmSync(DEFAULT_HOME,{recursive:true,force:true}));
18
+ // The same for the per-process off switch: an exported CM_NOTIFY_OFF would silence every
19
+ // fixture that expects a notice (review 2026-11-17). Tests that need it set it explicitly.
20
+ delete process.env.CM_NOTIFY_OFF;
18
21
  const NOW=Date.parse('2026-10-08T08:00:00.000Z');
19
22
  const DRIVE_CORE=new URL('../runtime/js/cm-ai/drive-core.mjs',import.meta.url).href;
20
23
  const BRIDGE=new URL('../runtime/js/cm-ai/host-tool-bridge.mjs',import.meta.url).href;
@@ -7,6 +7,9 @@ import {spawn,spawnSync} from 'node:child_process';
7
7
  import {fileURLToPath} from 'node:url';
8
8
  import {patrol,inspectHosts,processAlive} from './cm-patrol.mjs';
9
9
  import {hostRegistryDir,buildNotifyMessage,removeHostRegistry} from '../runtime/js/notify.mjs';
10
+ // An exported CM_NOTIFY_OFF silences every notice; these fixtures expect notices on
11
+ // (review 2026-11-17). Tests of the switch itself set it explicitly.
12
+ delete process.env.CM_NOTIFY_OFF;
10
13
 
11
14
  const HOST_SESSION=new URL('../runtime/js/cm-ai/host-session.mjs',import.meta.url).href;
12
15
  const PATROL=fileURLToPath(new URL('./cm-patrol.mjs',import.meta.url));
@@ -20,6 +20,9 @@ import {preparePrdReview} from '../runtime/js/cm-prd/review-preparation.mjs';
20
20
  import {inspectAcceptedPrdDesign,acceptedPrdDesignForPlanning} from '../runtime/js/cm-prd/accepted-design.mjs';
21
21
  import {createPrdSummaryOwner,inspectPrdSummaryEvidence,publishPrdAwaitingReview} from '../runtime/js/cm-prd/summary.mjs';
22
22
  import {assertPrdReviewsSettled} from '../runtime/js/cm-prd/change.mjs';
23
+ import {writeApprovalSnapshot} from '../runtime/js/cm-ai/spec-amendment.mjs';
24
+ import {writeSpecsStatus} from '../runtime/js/specs-status.mjs';
25
+ import {buildManifest} from './cm-spec-manifest.mjs';
23
26
  import {recordPrdHostDisposition,createPrdDispositionOwner} from '../runtime/js/cm-prd/review-disposition.mjs';
24
27
  const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
25
28
  const riskSignals=high=>({greenfieldAdr:false,architectureOrDataFlow:high,newRuntimeDependencyOrToolchain:false,
@@ -544,6 +547,34 @@ for(const mode of ['failed','drift'])test(`disposed-design split self-check cann
544
547
  else assert.equal((await owner(f.args,new AbortController().signal)).gate.disposition,'self_check_failed');
545
548
  assert.equal(checks,1);assert.equal(fs.existsSync(path.join(f.specs,'.reviews/prd-guide-split-disposition.json')),mode==='failed');
546
549
  });
550
+ // Models a human 「开始」 binding the current specs; the round ledger stays in a temporary home.
551
+ function isolateApprovalHome(t){
552
+ const home=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-approved-home-')),previous=process.env.CM_WORKFLOW_HOME;
553
+ process.env.CM_WORKFLOW_HOME=home;
554
+ t.after(()=>{if(previous===undefined)delete process.env.CM_WORKFLOW_HOME;else process.env.CM_WORKFLOW_HOME=previous;fs.rmSync(home,{recursive:true,force:true});});
555
+ }
556
+ function approveCurrentSpecs(specs){
557
+ const specFiles=buildManifest(specs),features=[...new Set(specFiles.map(row=>row.path.split('/')[0]))];
558
+ const approval={response:'开始',at:'2026-11-17T00:00:00.000Z'};
559
+ writeSpecsStatus(specs,{status:'approved',at:approval.at,features,specFiles,testCases:specFiles.filter(row=>row.path.endsWith('/test-cases.json')),approval,taskGrammar:3});
560
+ writeApprovalSnapshot(specs,{features,specFiles,approval});
561
+ }
562
+ // Codex 审查 #1:批准基线只替代指纹比对,设计与拆分审查的关联校验照常执行。
563
+ test('change save accepts an approved design after a completed split but keeps the split binding check',async t=>{
564
+ isolateApprovalHome(t);const f=await splitDesignFixture(t);f.edit();
565
+ await createPrdDispositionOwner({checkContext:async payload=>checked(payload)})(f.args,new AbortController().signal);
566
+ fs.writeFileSync(path.join(f.specs,f.feature,'design.md'),f.content+'\nLater approved design');
567
+ assert.throws(()=>assertPrdReviewsSettled(f.specs,[f.feature]));
568
+ approveCurrentSpecs(f.specs);
569
+ assert.doesNotThrow(()=>assertPrdReviewsSettled(f.specs,[f.feature]));
570
+ const g=await splitDesignFixture(t),other=await splitDesignFixture(t,{featureName:'other'});
571
+ other.edit();await createPrdDispositionOwner({checkContext:async payload=>checked(payload)})(other.args,new AbortController().signal);
572
+ g.edit();
573
+ for(const suffix of ['-r1.md','-dispatch.json','-disposition.json'])fs.copyFileSync(
574
+ path.join(other.specs,`.reviews/prd-other-split${suffix}`),path.join(g.specs,`.reviews/prd-guide-split${suffix}`));
575
+ approveCurrentSpecs(g.specs);
576
+ assert.throws(()=>assertPrdReviewsSettled(g.specs,[g.feature]),/prd_review_archive_identity_mismatch/);
577
+ });
547
578
  test('unchanged split disposition preserves legacy accepted binding and both receipt bytes',async t=>{
548
579
  const f=await splitDesignFixture(t),args=structuredClone(f.args);
549
580
  args.decisions[0].status='escalated';args.decisions[0].changedPaths=[];
@@ -8,7 +8,8 @@ import {TextDecoder} from 'node:util';
8
8
  import {fileURLToPath} from 'node:url';
9
9
  import {acceptsPrdSplitDesign} from '../runtime/js/cm-prd/split-design.mjs';
10
10
  import {inspectPrdFailedCorrection} from '../runtime/js/cm-prd/failed-correction.mjs';
11
- import {normalizeRuntimeMarks} from './cm-spec-manifest.mjs';
11
+ import {normalizeRuntimeMarks,normalizeRuntimeMarkBytes} from './cm-spec-manifest.mjs';
12
+ import {APPROVED_SPEC_FILES} from '../runtime/js/cm-ai/spec-amendment.mjs';
12
13
  import {tagDiagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
13
14
 
14
15
  // Messages stay byte-identical for the CLI and its Python oracle. Hosts get a stable
@@ -135,6 +136,11 @@ function loadReceipt(file,args,evidence){
135
136
  if(value.disposition==='self_check_failed')need(value.stage==='split','prd_failed_check_split_only','prd_failed_check_split_only',where);
136
137
  need(Array.isArray(value.artifacts)&&value.artifacts.length>0,'PRD review receipt must contain artifact hashes','prd_review_receipt_invalid',where);
137
138
  const root=resolve(path.dirname(path.dirname(file))),seen=new Set();
139
+ // Change mode only (assertPrdReviewsSettled): the bytes the latest human approval bound,
140
+ // as re-bound by applied amendments, path -> runtime-mark-normalized sha256. It stands in
141
+ // for this receipt's fingerprints only; every other receipt and split-binding check runs.
142
+ const approved=args.approvedBaseline instanceof Map?args.approvedBaseline:null;
143
+ const normalizedSha=(bytes,name)=>createHash('sha256').update(normalizeRuntimeMarkBytes(bytes,name)).digest('hex');
138
144
  for(const item of value.artifacts){
139
145
  need(keys(item,['path','sha256'])&&typeof item.path==='string'&&typeof item.sha256==='string'
140
146
  &&/^[0-9a-f]{64}$/.test(item.sha256),'PRD review receipt contains an invalid artifact','prd_review_receipt_invalid',where);
@@ -144,6 +150,11 @@ function loadReceipt(file,args,evidence){
144
150
  const named=()=>({receipt,artifact:item.path});
145
151
  const raw=path.join(root,item.path);need(!link(raw),'PRD review artifact is missing or unsafe','prd_review_artifact_unsafe',named);
146
152
  const artifact=resolve(raw);need(within(root,artifact),'PRD review artifact escapes the specs directory','prd_review_artifact_unsafe',named);
153
+ // Only the optional test-cases.json may be gone, and only when the approved round of a
154
+ // feature it binds no longer lists it; the whole-set check below enforces that round.
155
+ const parts=item.path.split('/');
156
+ if(!stat(artifact)&&approved!==null&&parts.length===2&&parts[1]==='test-cases.json'&&!approved.has(item.path)
157
+ &&approved.has(`${parts[0]}/design.md`)){value.approvedBaselineAccepted=true;continue;}
147
158
  need(stat(artifact)?.isFile(),'PRD review artifact is missing or unsafe','prd_review_artifact_unsafe',named);
148
159
  const bytes=bytesOf(artifact,'prd_review_artifact_unsafe',named());
149
160
  const currentSha=createHash('sha256').update(bytes).digest('hex');
@@ -151,8 +162,9 @@ function loadReceipt(file,args,evidence){
151
162
  &&stat(path.join(path.dirname(file),`prd-${value.feature}-split-disposition.json`));
152
163
  if(currentSha!==item.sha256||completedSplit){
153
164
  const accepted=acceptsPrdSplitDesign({specs:root,evidence:path.relative(root,evidence).split(path.sep).join('/'),
154
- receipt:value,item,currentSha,pendingSplit:args.pendingSplit??null});
165
+ receipt:value,item,currentSha,pendingSplit:args.pendingSplit??null,approvedBaseline:approved});
155
166
  if(accepted===true)continue;
167
+ if(approved?.has(item.path)&&normalizedSha(bytes,path.basename(artifact))===approved.get(item.path)){value.approvedBaselineAccepted=true;continue;}
156
168
  if(completedSplit&&accepted!==null)need(false,'prd_design_receipt_changed','prd_design_receipt_changed',named);
157
169
  if(currentSha===item.sha256)continue;
158
170
  const text=bytes.toString('utf8');
@@ -163,6 +175,19 @@ function loadReceipt(file,args,evidence){
163
175
  value.runtimeMarksNormalized=true;
164
176
  }
165
177
  }
178
+ // Once any file leans on the approved round, every file of the receipt's features must be
179
+ // exactly that round: old receipt bytes cannot be mixed with newly approved ones.
180
+ if(value.approvedBaselineAccepted){
181
+ // Every spec file the approval binds, present or not; other receipt artifacts were
182
+ // already held to the receipt's own fingerprints above.
183
+ const features=[...new Set(value.artifacts.map(item=>item.path.split('/')).filter(parts=>parts.length>1&&/^\d+\./.test(parts[0])).map(parts=>parts[0]))].sort();
184
+ for(const row of features.flatMap(feature=>APPROVED_SPEC_FILES.map(name=>`${feature}/${name}`))){
185
+ const target=path.join(root,row),present=stat(target);
186
+ need(!link(target)&&(present===null||present.isFile()),'PRD review artifact is missing or unsafe','prd_review_artifact_unsafe',()=>({receipt,artifact:row}));
187
+ const current=present===null?undefined:normalizedSha(bytesOf(target,'prd_review_artifact_unsafe',{receipt,artifact:row}),path.basename(row));
188
+ need(current===approved.get(row),'PRD review artifact changed after disposition','prd_review_artifact_changed',()=>({receipt,artifact:row}));
189
+ }
190
+ }
166
191
  if(value.disposition==='self_check_failed')inspectPrdFailedCorrection({specs:root,receipt:value});
167
192
  return value;
168
193
  }
@@ -272,7 +297,7 @@ export function inspectPrdReview(args){
272
297
  {...base,outcome:'dispatch_once'};
273
298
  evidenceHeader(evidence);if(!stat(receipt))return {...base,outcome:'resume_disposition'};
274
299
  const value=loadReceipt(receipt,args,evidence);return {...base,outcome:'completed',disposition:value.disposition,
275
- ...(value.runtimeMarksNormalized?{runtimeMarksNormalized:true}:{})};
300
+ ...(value.runtimeMarksNormalized?{runtimeMarksNormalized:true}:{}),...(value.approvedBaselineAccepted?{approvedBaseline:true}:{})};
276
301
  }
277
302
  export function recordPrdReview(args){
278
303
  counts(args.disposition,args.finding_count,args.unresolved_count,typeof args.receipt==='string'?reviewFile(args.receipt):null);
@@ -16,11 +16,11 @@ import {loadConfig} from './cm-workflow-config.mjs';
16
16
  import {TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
17
17
  import {writeSpecsStatus} from '../runtime/js/specs-status.mjs';
18
18
  // Spec approvals write a round ledger under CM_WORKFLOW_HOME; keep it off the real home.
19
- if(!process.env.CM_WORKFLOW_HOME){
20
- const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
21
- process.env.CM_WORKFLOW_HOME=isolatedHome;
22
- process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
23
- }
19
+ // Always, not only when unset: an exported CM_WORKFLOW_HOME may be the tester's real home
20
+ // (review 2026-11-17: these suites left 11 approval records in an externally named home).
21
+ const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
22
+ process.env.CM_WORKFLOW_HOME=isolatedHome;
23
+ process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
24
24
  const sha=content=>createHash('sha256').update(content).digest('hex');
25
25
  function fixture(t,{pendingCorrection=false,mandatory=false}={}){
26
26
  const specs=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-summary-marks-')));
@@ -9,7 +9,9 @@ import path from 'node:path';
9
9
  import {spawnSync} from 'node:child_process';
10
10
  import {fileURLToPath} from 'node:url';
11
11
  import {approveCmAiSpecs} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
12
- import {applySpecAmendment,withApprovalLock} from '../runtime/js/cm-ai/spec-amendment.mjs';
12
+ import {applySpecAmendment,withApprovalLock,roundLedgerPath} from '../runtime/js/cm-ai/spec-amendment.mjs';
13
+ import {recordPrdReview} from './cm-prd-review-gate.mjs';
14
+ import {assertPrdReviewsSettled} from '../runtime/js/cm-prd/change.mjs';
13
15
 
14
16
  // The round ledger lives under CM_WORKFLOW_HOME; never touch the real home.
15
17
  const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-spec-amend-home-'));
@@ -508,3 +510,107 @@ test('a failed approval snapshot write leaves no round to restore',()=>fixture((
508
510
  reset();fs.writeFileSync(target,roundA);edit('tasks.md',addTask);
509
511
  assert.deepEqual(inspect().reasons,['snapshot_round_missing']);
510
512
  }));
513
+
514
+ // wue 实跑事故(2026-11-17):拆分审查回执之后,设计稿经用户重新批准、任务经 1 级补正换绑,
515
+ // cm-prd --change 的 save_draft 仍拿最早回执指纹比对,误报 prd_review_artifact_changed。
516
+ function splitReceipt(specs,names=['requirements.md','design.md','tasks.md','test-cases.json']){
517
+ const reviews=path.join(specs,'.reviews');fs.mkdirSync(reviews,{recursive:true});
518
+ const args={stage:'split',feature:'login',evidence:path.join(reviews,'prd-login-split-r1.md'),receipt:path.join(reviews,'prd-login-split-disposition.json')};
519
+ fs.writeFileSync(args.evidence,'---\nat: 2026-11-01T00:00:00Z\nreviewer: codex-subagent\nindependent: true\nscope:\n - tasks.md\n---\nSynthetic split review\n');
520
+ recordPrdReview({...args,disposition:'no_findings',finding_count:0,unresolved_count:0,
521
+ artifact:names.map(name=>path.join(specs,'1.login',name))});
522
+ }
523
+ test('change save accepts specs re-bound by a later approval or applied amendment after the split receipt',()=>fixture(({specs,approve,inspect,apply,review,edit})=>{
524
+ splitReceipt(specs);assert.equal(approve().status,0);
525
+ const settled=()=>assertPrdReviewsSettled(specs,['1.login']);
526
+ assert.doesNotThrow(settled);
527
+ edit('design.md',text=>text+'\n模块 2:设计稿换版。\n');
528
+ // The design swap goes back through cm-prd (awaiting_review) and a fresh human 「开始」.
529
+ fs.writeFileSync(path.join(specs,'.cm-specs-status'),JSON.stringify({status:'awaiting_review',features:['1.login'],testCases:[]}));
530
+ const again=approve();assert.equal(again.status,0,JSON.stringify(again.json));
531
+ assert.doesNotThrow(settled);
532
+ edit('tasks.md',addTask);const {tier,deltaDigest}=inspect();assert.equal(tier,1);
533
+ assert.equal(apply(['--review-output',review(deltaDigest),'--reviewer','codex']).status,0);
534
+ assert.doesNotThrow(settled);
535
+ // Runtime completion marks stay outside the comparison, as for the receipt itself.
536
+ edit('tasks.md',text=>text.replace('- [ ] T-001: 登录页','- [x] T-001: 登录页'));
537
+ assert.doesNotThrow(settled);
538
+ },{cases:true}));
539
+ test('change save still refuses specs that match no approved version',()=>{
540
+ fixture(({specs,approve,edit})=>{
541
+ splitReceipt(specs);assert.equal(approve().status,0);
542
+ edit('tasks.md',addTask);
543
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact changed after disposition/);
544
+ },{cases:true});
545
+ // An approved snapshot whose round ledger is gone (or a restored older one) is no baseline.
546
+ fixture(({specs,approve,edit})=>{
547
+ splitReceipt(specs);edit('design.md',text=>text+'\n换版\n');assert.equal(approve().status,0);
548
+ fs.rmSync(roundLedgerPath(specs));
549
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact changed after disposition/);
550
+ },{cases:true});
551
+ // A snapshot never approved (status back to awaiting_review) is no baseline either.
552
+ fixture(({specs,approve,edit})=>{
553
+ splitReceipt(specs);edit('design.md',text=>text+'\n换版\n');assert.equal(approve().status,0);
554
+ const status=path.join(specs,'.cm-specs-status');
555
+ fs.writeFileSync(status,JSON.stringify({...JSON.parse(fs.readFileSync(status,'utf8')),status:'awaiting_review'}));
556
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact changed after disposition/);
557
+ },{cases:true});
558
+ });
559
+ // Codex 审查 #2:同一功能不能拼接旧回执字节与新批准字节。
560
+ test('change save refuses mixing receipt bytes with a later approved round',()=>fixture(({specs,approve,edit})=>{
561
+ splitReceipt(specs);const original=fs.readFileSync(path.join(specs,'1.login/tasks.md'));
562
+ edit('design.md',text=>text+'\n换版\n');edit('tasks.md',addTask);assert.equal(approve().status,0);
563
+ assert.doesNotThrow(()=>assertPrdReviewsSettled(specs,['1.login']));
564
+ fs.writeFileSync(path.join(specs,'1.login/tasks.md'),original);
565
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact changed after disposition/);
566
+ },{cases:true}));
567
+ // Codex 审查 #3:批准轮次已合法去掉 test-cases.json 时不再误拦;未批准的删除仍拦。
568
+ test('change save follows an approved round that no longer has test-cases.json',()=>{
569
+ fixture(({specs,approve})=>{
570
+ splitReceipt(specs);fs.rmSync(path.join(specs,'1.login/test-cases.json'));assert.equal(approve().status,0);
571
+ assert.doesNotThrow(()=>assertPrdReviewsSettled(specs,['1.login']));
572
+ },{cases:true});
573
+ fixture(({specs,approve})=>{
574
+ splitReceipt(specs);assert.equal(approve().status,0);fs.rmSync(path.join(specs,'1.login/test-cases.json'));
575
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact is missing or unsafe/);
576
+ },{cases:true});
577
+ });
578
+ // Codex 审查 #4:畸形状态清单不是基线,也不能打断原回执校验。
579
+ test('malformed approved status falls back to the strict receipt check',()=>fixture(({specs,approve,edit})=>{
580
+ splitReceipt(specs);assert.equal(approve().status,0);
581
+ const status=path.join(specs,'.cm-specs-status');
582
+ fs.writeFileSync(status,JSON.stringify({...JSON.parse(fs.readFileSync(status,'utf8')),specFiles:{}}));
583
+ assert.doesNotThrow(()=>assertPrdReviewsSettled(specs,['1.login']));
584
+ edit('tasks.md',addTask);
585
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact changed after disposition/);
586
+ },{cases:true}));
587
+ // Codex 复审 #1:两份清单都没有的 test-cases.json 后来出现,也要拦。
588
+ test('change save refuses a test-cases.json no approval or receipt bound',()=>fixture(({specs,approve,edit})=>{
589
+ splitReceipt(specs,['requirements.md','design.md','tasks.md']);edit('design.md',text=>text+'\n换版\n');assert.equal(approve().status,0);
590
+ assert.doesNotThrow(()=>assertPrdReviewsSettled(specs,['1.login']));
591
+ fs.writeFileSync(path.join(specs,'1.login/test-cases.json'),JSON.stringify(CASES));
592
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact changed after disposition/);
593
+ }));
594
+ // Codex 复审 #2:批准清单范围外的回执产物仍按回执指纹核对,删除不能借基线放行。
595
+ test('approved baseline never covers receipt artifacts outside the approved spec files',()=>fixture(({specs,approve,edit})=>{
596
+ fs.writeFileSync(path.join(specs,'1.login/api-schema.json'),'{"type":"object"}\n');
597
+ splitReceipt(specs,['requirements.md','design.md','tasks.md','test-cases.json','api-schema.json']);
598
+ edit('design.md',text=>text+'\n换版\n');assert.equal(approve().status,0);
599
+ assert.doesNotThrow(()=>assertPrdReviewsSettled(specs,['1.login']));
600
+ fs.rmSync(path.join(specs,'1.login/api-schema.json'));
601
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact is missing or unsafe/);
602
+ },{cases:true}));
603
+ // Codex 复审第 3 轮:规格根目录下指纹未变的辅助产物不是功能目录,不能被误拦。
604
+ test('approved baseline keeps root-level receipt artifacts on their own fingerprints',()=>fixture(({specs,approve,edit})=>{
605
+ const extra=path.join(specs,'api-schema.json');fs.writeFileSync(extra,'{"type":"object"}\n');
606
+ splitReceipt(specs);
607
+ const receipt=path.join(specs,'.reviews/prd-login-split-disposition.json'),value=JSON.parse(fs.readFileSync(receipt,'utf8'));
608
+ // Old `record` accepted any file inside the specs root; model such a receipt directly.
609
+ fs.rmSync(receipt);
610
+ recordPrdReview({stage:'split',feature:'login',evidence:path.join(specs,'.reviews/prd-login-split-r1.md'),receipt,
611
+ disposition:'no_findings',finding_count:0,unresolved_count:0,artifact:[...value.artifacts.map(item=>path.join(specs,item.path)),extra]});
612
+ edit('design.md',text=>text+'\n换版\n');assert.equal(approve().status,0);
613
+ assert.doesNotThrow(()=>assertPrdReviewsSettled(specs,['1.login']));
614
+ fs.appendFileSync(extra,' ');
615
+ assert.throws(()=>assertPrdReviewsSettled(specs,['1.login']),/PRD review artifact changed after disposition/);
616
+ },{cases:true}));
@@ -14,11 +14,11 @@ import {publishPrdReview} from '../runtime/js/cm-prd/review-publication.mjs';
14
14
  import {recordPrdHostDisposition} from '../runtime/js/cm-prd/review-disposition.mjs';
15
15
  import {createPrdSummaryOwner,publishPrdAwaitingReview} from '../runtime/js/cm-prd/summary.mjs';
16
16
  // Spec approvals write a round ledger under CM_WORKFLOW_HOME; keep it off the real home.
17
- if(!process.env.CM_WORKFLOW_HOME){
18
- const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
19
- process.env.CM_WORKFLOW_HOME=isolatedHome;
20
- process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
21
- }
17
+ // Always, not only when unset: an exported CM_WORKFLOW_HOME may be the tester's real home
18
+ // (review 2026-11-17: these suites left 11 approval records in an externally named home).
19
+ const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
20
+ process.env.CM_WORKFLOW_HOME=isolatedHome;
21
+ process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
22
22
  const entry=fileURLToPath(new URL('./cm-ai-admission.mjs',import.meta.url));
23
23
  const at='2026-09-18T00:00:00.000Z';
24
24
  const keys=['status','summaryDigest','at','features','specFiles','testCases','approval'];
@@ -1,6 +1,8 @@
1
1
  import test from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
- import {skillContext} from '../runtime/js/cm-ai/tool-preview.mjs';
3
+ import {createHash} from 'node:crypto';
4
+ import {skillContext,requestTools} from '../runtime/js/cm-ai/tool-preview.mjs';
5
+ import {commonArgs,configFingerprint,NO_USER_INPUT_TOOL} from '../runtime/js/cm-ai/codex-config.mjs';
4
6
  const retainedPreamble = "Each entry includes a name, description, and location for its `SKILL.md`. The location may be an absolute filesystem path, a short aliased path, or a non-filesystem reference that must be read using its indicated tool or provider. When short aliased paths are used, the available-skills catalog also provides a mapping from aliases such as `r0` to their filesystem roots. Expand the alias before accessing the skill.\n\nThe user's instructions take precedence over guidelines provided in a skill. If explicit user instructions conflict with a skill's instructions, prioritize the user's instructions.\n\nThe first time in a conversation that you decide to apply a skill, inform the user in the commentary channel.\n\nIf a skill causes you to ask for permission or confirmation, pause, or leave requested work unfinished, name the skill and summarize the specific instruction in the skill that led to your decision. Include this explanation in the request or final response where you pause.";
5
7
  const input = text => ({input:[{content:[{text}]}]});
6
8
  test('Codex 0.159.2 retained empty skill preamble is not a catalog',()=>{
@@ -10,3 +12,20 @@ test('real, unresolved and unknown catalogs remain blocked',()=>{
10
12
  for(const content of ['- sample (file: /tmp/sample/SKILL.md)','- sample (file: r99/sample/SKILL.md)','Unrecognized catalog content'])
11
13
  assert.equal(skillContext(input('<skills_instructions>\n### Available skills\n'+retainedPreamble+'\n'+content+'\n</skills_instructions>')).present,true);
12
14
  });
15
+ // codex-cli 0.167.0 / gpt-6.2-sol 实跑请求形状:两个默认工具必须被零工具判定看见。
16
+ test('a request carrying the Codex 0.167 default tools is not zero tools',()=>{
17
+ const body={model:'gpt-6.2-sol',input:[],tools:[{type:'function',name:'request_user_input'},{type:'function',name:'view_image'}]};
18
+ assert.deepEqual(requestTools(body).map(tool=>tool.name),['request_user_input','view_image']);
19
+ assert.deepEqual(requestTools({...body,tools:[]}),[]);
20
+ assert.equal(requestTools({...body,tools:{}}),null);
21
+ });
22
+ test('the fingerprint binds each review-only tool removal, so older preflight receipts no longer match',()=>{
23
+ const options={cwd:'/fixture',model:'gpt-6.2-sol',effort:'high'},args=commonArgs(options);
24
+ const hash=list=>createHash('sha256').update(JSON.stringify(list)).digest('hex');
25
+ const without=(flag,value)=>args.filter((arg,i)=>!(arg===flag&&args[i+1]===value||arg===value&&args[i-1]===flag));
26
+ assert.equal(configFingerprint(options),hash(args));
27
+ for(const [flag,value] of [['--disable','view_image'],['-c',NO_USER_INPUT_TOOL]]){
28
+ const older=without(flag,value);assert.equal(older.length,args.length-2);
29
+ assert.notEqual(configFingerprint(options),hash(older));
30
+ }
31
+ });
@@ -23,6 +23,13 @@ import {checkPrdDraftMechanics,matchesPrdDraftMechanics} from '../runtime/js/cm-
23
23
  import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
24
24
  import {buildManifest} from './cm-spec-manifest.mjs';
25
25
 
26
+ // Spec approvals write a round ledger under CM_WORKFLOW_HOME; keep it off the real home.
27
+ // Always, not only when unset: an exported CM_WORKFLOW_HOME may be the tester's real home
28
+ // (review 2026-11-17: these suites left 11 approval records in an externally named home).
29
+ const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-approval-home-'));
30
+ process.env.CM_WORKFLOW_HOME=isolatedHome;
31
+ process.on('exit',()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
32
+
26
33
  const TIMEOUT=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??120000);
27
34
  const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
28
35
  const UPGRADE_BASE='f73402d';
@@ -16,7 +16,7 @@ allowed-tools:
16
16
  新建和变更模式都读取 `references/phase-timing.md`,只为实际执行的阶段写配对
17
17
  `progress/start|complete`;人工等待前关闭 segment,恢复后递增,不手算耗时。
18
18
 
19
- 用户明确要求外部专家,或为本次规格任务开启 AUTO 时,读取
19
+ 通过 `references/cm-optout.md` 核对后,用户明确要求外部专家或为本次规格任务开启 AUTO 时,读取
20
20
  `../../runtime/external-expert.md` 并执行 `../external-expert/SKILL.md` 的任务路由。
21
21
  AUTO 可把复杂方案比较路由到 CONSULT、权威事实查证路由到 VERIFY,其余保持 LOCAL。
22
22
  外部结论属于需求/设计输入,必须在本地对照项目事实并进入正常规格人审;AUTO 不
@@ -44,7 +44,7 @@ AUTO 可把复杂方案比较路由到 CONSULT、权威事实查证路由到 VER
44
44
 
45
45
  ## JS 准入与当前会话执行
46
46
 
47
- 在读取需求正文、解析角色、写 `run_start`、创建或修改 specs 之前,把已解析路径和模式传给:
47
+ 先按 `references/cm-optout.md` 核对项目规则是否禁用 CM(两种模式都做);通过后,在读取需求正文、解析角色、写 `run_start`、创建或修改 specs 之前,把已解析路径和模式传给:
48
48
 
49
49
  ```bash
50
50
  node "{CM_WORKFLOW_ROOT}/scripts/cm-prd-entry.mjs" \
@@ -148,8 +148,8 @@ node {CM_WORKFLOW_ROOT}/scripts/cm-workflow-config.mjs \
148
148
  ### Step 4: 读取项目上下文(存量项目 = 二开模式,叠加 B 规则)
149
149
 
150
150
  - 按 `runtime/project-context.md` 读取项目约束和本需求相关规则,扫描两层目录了解模块划分
151
- - 读取 `references/context-scope.md`,先做定向代码搜索,再设置
152
- `CONTEXT_SCOPE=targeted|full`、加载对应地图/代码,并写 `decision/context_scope` 日志
151
+ - 读取 `references/context-scope.md`:按下方 B1 读取适用地图或索引,再定向搜索代码,最后设置
152
+ `CONTEXT_SCOPE=targeted|full`、加载补充地图/代码,并写 `decision/context_scope` 日志
153
153
  - **B1 代码库参考文档判定**:先读代码项目根 CLAUDE.md 的「业务地图」字段(多层仓库
154
154
  下以代码项目根为准,仓库根 CLAUDE.md 无此字段再看地图 00-index 头部;init 已判定过,
155
155
  仍须核对相关内容与当前代码)。字段=已生成/已刷新或目录存在 → 按 context-scope 渐进加载并核实;字段=
@@ -162,7 +162,7 @@ node {CM_WORKFLOW_ROOT}/scripts/cm-workflow-config.mjs \
162
162
 
163
163
  ### Step 5: 分析需求
164
164
 
165
- **调用 `cm-product-manager` skill 执行本步和 Step 5.5**——用户故事、编号功能需求、验收标准的编写方法和歧义五问以该 skill 为准。
165
+ **调用 `cm-product-manager` skill 执行本步和 Step 5.5**——用户故事、编号功能需求、验收标准的编写方法、歧义五问和七项倒推清单以该 skill 为准。
166
166
 
167
167
  需求涉及**交易/资产/支付/代币/证券/金融营销**时,同时加载 `cm-finance-expert` skill 协同:领域正确性审核 + 营销合规红线扫描 + 合规开放问题(并入 Step 5.5)。法域确认结果须写入代码项目 `.claude/rules/finance.md` 头部字段;文件不存在时,以 `{CM_WORKFLOW_ROOT}/templates/rules/finance.md` 为骨架现场补生成,并在 AGENTS.md 与 CLAUDE.md 的相关规则说明中补充引用。
168
168
 
@@ -170,34 +170,15 @@ node {CM_WORKFLOW_ROOT}/scripts/cm-workflow-config.mjs \
170
170
 
171
171
  命中重要歧义或方案分歧时,按 `../../runtime/steelman-review.md` 区分已观察事实、参与者主张、当前推断和未知项;“用户真正想要什么”只能写成可修正假设,不能替用户补全业务规则。
172
172
 
173
- ### Step 5.5: 开放问题确认
173
+ ### Step 5.5: 需求倒推与逐轮追问
174
174
 
175
- 分析需求后,如果存在以下情况,**必须暂停并与用户对话确认**,不要自行假设:
176
-
177
- - 需求描述模糊或有歧义的功能点
178
- - 多种技术实现方案且差异较大
179
- - 缺少关键信息(如目标平台、兼容性要求、第三方服务选型)
180
- - 业务逻辑有矛盾或不完整
181
- - 涉及权限、支付、敏感操作等需要明确确认的功能
175
+ 读取 `references/requirement-grilling.md` 执行 G1–G4:对照现有业务倒推缺口,按设计树逐轮提问(每题带出处与推荐答案),满足其 G4 停止条件后才进入 Step 6,不得自行假设。
182
176
 
183
177
  `DELIVERY_SHAPE=wechat-miniprogram` 时追加平台就绪检查:账号主体、服务类目/资质、
184
178
  变现路径、权限与隐私、后端/合法域名和发布通道。会改变功能可行性或范围但未确认的
185
179
  项目必须暂停;只影响后续提审的材料可记为发布待决,不阻塞本地规格与开发。平台政策
186
180
  结论须记录当前官方查证日期与来源,无法查证时保留开放问题。
187
181
 
188
- 格式:
189
-
190
- ```
191
- ❓ 需要确认以下问题:
192
-
193
- 1. {问题描述} — {为什么需要确认}
194
- 2. {问题描述} — {为什么需要确认}
195
-
196
- 请逐一回复后继续生成 specs
197
- ```
198
-
199
- 所有问题确认完毕后再进入 Step 6。
200
-
201
182
  双向钢人审查只用于暴露假设和失败场景:支持方与反方都取最强版本,但按证据质量加权;无法验证的反方写入开放问题,不强迫给确定结论。
202
183
 
203
184
  ### Step 6: 推断 feature 名称
@@ -267,6 +248,12 @@ node {CM_WORKFLOW_ROOT}/scripts/cm-workflow-config.mjs \
267
248
  {按 cm-miniprogram-engineer/references/platform-readiness.md 记录状态、证据与负责人;
268
249
  不写任何密钥、证件、Cookie 或测试账号密码}
269
250
 
251
+ ## 范围与覆盖核对
252
+
253
+ - 本期做: {范围}
254
+ - 明确不做: {排除项}
255
+ - 追问补齐项: {检查项 — 问题 → 用户答案(出处: 位置)};无缺口写「倒推核对 7 项无缺口」
256
+
270
257
  ## 开放问题
271
258
 
272
259
  - {待确认事项}
@@ -518,7 +505,7 @@ AC、design 和 tasks 补齐,保证 AC→TC→Task 可追踪。纯文档/注
518
505
  │ Feature: {N 个}: {名称列表}
519
506
  │ 历史 feature:{N} 个已登记,{M} 个含旧版归档说明
520
507
  │ 功能点: {N} 个 | AC: {N} 条 | 任务: {N} 个(预估 {x}h)
521
- │ 开放问题: {已答 N / 共 N}——{逐条一行: 问题→答案}
508
+ │ 开放问题: {倒推核对结果(见 requirement-grilling G4);已答 N / 共 N}——{逐条一行: 问题→答案}
522
509
  │ 风险点: {金融/合规/破坏性操作等敏感项,无则"无"}
523
510
  │ 上下文范围: {定向 / 完整 / 定向→完整(reason_code)}
524
511
  │ 平台就绪: {就绪/待官方核验 N 项/不适用}
@@ -46,6 +46,8 @@
46
46
  - **删除**的功能需求
47
47
  - 对验收标准的影响
48
48
 
49
+ 对比完成后读取 `requirement-grilling.md`,对本次变更执行倒推核对与逐轮追问;满足其 G4 停止条件后才进入 C5,C5 按其 G4 写入「范围与覆盖核对」。
50
+
49
51
  ### Step C5: 更新 requirements.md
50
52
 
51
53
  - 在「需求版本」表中追加新版本行:
@@ -0,0 +1,11 @@
1
+ # $cm-prd 项目规则禁用 CM 时的确认
2
+
3
+ > 新建与变更模式在外部专家路由、调用 `cm-prd-entry.mjs` 准入、启动 JS 宿主之前执行本文件(实跑教训:aihot 的
4
+ > AGENTS.md 先后写过「只用 CM」和「不用 CM」,流程没有规定怎么处理)。本步只读,不读需求正文。
5
+
6
+ 1. 以代码项目根(Step 3 的判定,不是当前会话所在仓库)为准,读其 AGENTS.md 链、根目录 `CLAUDE.md`、`.claude/CLAUDE.md`
7
+ 和 `.claude/rules/` 下全部文件(本步不按相关性筛选),只找不用 CM 工作流的条款;没有 → 照常继续准入。
8
+ 2. 按规则自身声明的优先级(如「本节优先」「已被覆盖」)判断该条款是否仍生效;已被后续条款明确覆盖 → 照常继续。
9
+ 3. 仍生效、无法判断,或条款只限某类需求而本步不读正文无法确定是否适用 → 在对话里问用户一次,问题里引用条款的文件与行号,等真实答复;不调用准入。
10
+ 4. 用户明确同意运行 cm-prd,或说明本次需求不在条款限定范围内 → 继续准入;
11
+ 其余回复 → 不启动准入与宿主、不写 specs,说明原因后结束。
@@ -9,7 +9,8 @@
9
9
  `coding-style.md`、`testing.md`、`security.md` 和本需求已命中层的规则。需求源、项目
10
10
  描述文件和两层目录概览已经由 Step 1–3 读取,不重复打开。
11
11
 
12
- 先读项目指定地图或存在的 `docs/codebase-context/00-index.md`;再用需求中的页面名、路由、可见
12
+ 地图读取顺序以主 `SKILL.md` Step 4 的 B1 为准:先看代码项目根 CLAUDE.md 的「业务地图」字段,
13
+ 再按字段结果读项目指定地图或存在的 `docs/codebase-context/00-index.md`;然后用需求中的页面名、路由、可见
13
14
  文案、接口名、类型名和业务术语做代码搜索,定位候选模块、直接调用方与最近测试。
14
15
  搜索只用于定位,不把命中源码或需求正文写入运行日志。
15
16
 
@@ -69,13 +69,13 @@ result必须填真实结果,不留空对象。不同kind的合同见当前请
69
69
 
70
70
  | kind | 当前宿主执行 |
71
71
  | --- | --- |
72
- | prd_analyze | 按原Step 0–5分析与提问;保留用户用例、形态、平台与范围约束。question交给用户,不能代答。 |
72
+ | prd_analyze | 按原Step 0–5.5分析,并按requirement-grilling.md逐轮追问(每轮一个question,阻断项答完才回analyzed);保留用户用例、形态、平台与范围约束。question交给用户,不能代答。 |
73
73
  | prd_materials | 用已可用、已授权的实际工具处理材料;HTML交互只走Codex内置浏览器,PDF逐页覆盖,不伪造截图/页数/证据。能力不足返回blocked。 |
74
74
  | prd_generate | 按payload.phase执行:design只做Step6–9的需求/设计;tasks_after_design默认保留acceptedDesign原feature及正文,每个feature只回tasks.md和适用的test-cases.json,省略的requirements.md/design.md由宿主按原字节补回(64KB只算新回的文档;照旧回全文也须逐字一致);整稿自检失败时按下文登记同清单修订;full_draft走原Step6–10。保留UI基准与原粒度约束,只回正文不写文件。 |
75
75
  | prd_self_check | 读取spec-self-check.md与相关真实代码/地图/用例,逐项返回有依据的结果;机械通过不等于语义通过,不能用自检冒充独立审查。 |
76
76
  | prd_review | 按原9.5或10.6,使用实际授权的新上下文独立审查,核对作者与审查者上下文标识、材料摘要并原样回传。无法独立时只允许预先选定的显式self-degraded;开始后不换模式或补审。 |
77
77
  | prd_correct | 对原findings提出完整原路径清单与逐项采纳/升级决定;不自行写规格,不新增范围/勾任务/再次review。 |
78
- | prd_summary | 按原Step11核对交付形态、开放问题、风险、平台/UI基准及原9.5风险信号;未知明确写待核对,不能推断人工批准。 |
78
+ | prd_summary | 按原Step11核对交付形态、开放问题(先写requirement-grilling G4的倒推结果)、风险、平台/UI基准及原9.5风险信号;未知明确写待核对,不能推断人工批准。 |
79
79
 
80
80
  读取角色Skill不代表配置模型已调用;非当前runtime角色路由被JS阻断时如实报告。
81
81
  JS拥有日志、草稿保存、修订写入、自检轮次、审查记录、处置和审批位写入;宿主不再运行
@@ -0,0 +1,116 @@
1
+ # $cm-prd 需求倒推与逐轮追问
2
+
3
+ > 新建模式 Step 5.5 与变更模式 C4 之后读取本文件。七项倒推清单的内容以
4
+ > `../../cm-product-manager/SKILL.md` 第 2 节为准;本文件规定执行顺序、提问格式、停止条件与交接。
5
+
6
+ 目标:不只核对需求文档写了什么,还要对照项目现有业务找出文档漏掉的范围,把缺口和产品逐轮
7
+ 对清后再生成规格(实跑反馈:产品文档常范围不明或直接漏项,开发中途才暴露)。
8
+
9
+ ## G1 合并问题清单(每次都跑)
10
+
11
+ 1. **证据来源**:新建模式复用 Step 4 已加载的地图与代码,变更模式复用 C2–C4 读过的规格与代码;
12
+ 不够时按 `context-scope.md` 补读相关代码与直接调用方,不为追问另做全量扫描。
13
+ 2. **倒推七项**:对需求涉及的每条业务线路逐项过七项清单。
14
+ 3. **原必问项**:同时检查原 Step 5.5 的触发条件——功能点模糊或有歧义、实现方案差异大、
15
+ 缺关键信息(目标平台、兼容性、第三方服务选型)、业务逻辑矛盾或不完整、涉及权限/支付/隐私/删除等敏感操作;
16
+ 以及歧义五问、`cm-finance-expert` 合规问题、greenfield G1;微信小程序平台就绪中会改变功能可行性或范围的项
17
+ (只影响后续提审的材料按主 Skill Step 5.5 记为发布待决,不进清单);宿主材料阶段用户未逐项答复的原型死区(不许静默丢弃)。
18
+ 以上全部进清单,影响级按第 4 条的表判定。
19
+ 4. 每个缺口记录:
20
+
21
+ | 字段 | 写法 |
22
+ | ---- | ---- |
23
+ | 检查项 | 七项之一,或「范围」「成功判据」「技术选型」「合规」「平台就绪」「原型死区」 |
24
+ | 出处 | 需求文档 `文件:行`、代码 `路径:行`、地图章节名 |
25
+ | 影响级 | `阻断` 或 `默认`,判定见下表 |
26
+ | 推荐答案 | 依据现有业务给出的建议;没把握时写「无推荐,需产品决定」 |
27
+
28
+ | 影响级 | 条件 |
29
+ | ---- | ---- |
30
+ | `阻断` | 决定功能做不做或主流程怎么走;改变交付形态、数据结构或存量数据;涉及权限、支付、隐私、删除;实现方案差异大、缺关键信息、业务逻辑矛盾或不完整 |
31
+ | `默认` | 只影响上限值、文案、排序、展示细节等,且有合理默认 |
32
+
33
+ 5. 能从代码、地图或文档查到的事实自己查清,写进出处,不问用户。
34
+ 6. 地图没有对应线路(盲区)时,用代码定向搜索作出处;本阶段只读,盲区留给 B5 在拆分前补扫。
35
+ 7. 只有确认为全新项目(GREENFIELD)时才只核对文档内部缺口;存量项目缺地图时照常查代码。
36
+ 8. 当前为 `CONTEXT_SCOPE=targeted` 且发现改变实现范围的缺口 → 按 `context-scope.md` 第 4 节升级。
37
+ 9. 合并清单为空 → 不提问,直接进入 G4,结论记「倒推核对 7 项无缺口」。
38
+
39
+ ## G2 设计树与前沿
40
+
41
+ 问题按依赖排序:一题的答案会改变另一题的问法或是否需要问,后者就依赖前者。
42
+ 「前沿」是依赖的题都已有答案的问题,本轮只从前沿取题。互相依赖(成环)的未答题彼此不算前置,
43
+ 一起进入前沿;超过 5 题时按 G3 分到后续轮次。参考层次(同层内无依赖的题可同轮问,
44
+ 下层题不依赖未决上层题时也可提前):
45
+
46
+ 1. 范围与交付形态(本期做什么、明确不做什么)
47
+ 2. 角色与权限
48
+ 3. 状态流转与数据(含存量数据处理)
49
+ 4. 相邻线路、入口、通知、报表与导出
50
+ 5. 异常、空态与文案
51
+
52
+ 默认清单同样只列前沿内的 `默认` 项;依赖未决题的默认项留到之后的轮次。
53
+ 某个 `阻断` 题依赖的 `默认` 项按 `阻断` 处理。
54
+ 上游答案使某题不再适用时(如本期不做导出,导出权限题随之失效),该题记「不适用:{依据的答案}」移出清单,
55
+ 不再计入未答 `阻断` 题,并在「范围与覆盖核对」中保留这条记录。
56
+ 用户改答某题时,所有依赖它的已答题和「不适用」题都恢复为未答,按新答案重新确认。
57
+ 「不适用」的题算作已解决,其他题对它的依赖随之解除。
58
+ 兜底:仍有未答 `阻断` 题而前沿为空时,这些题直接进入前沿(按 G3 分轮),不得因此卡住或放行。
59
+
60
+ ## G3 每轮格式
61
+
62
+ - 每轮最多 5 题,`阻断` 级优先;每题写清出处与推荐答案。
63
+ - `默认` 级不单独出题,汇成本轮末尾的「默认清单」。
64
+ - 每轮文字能原样转发给产品:不依赖前文,不写内部步骤名。第 2 轮起开头用「已记下:」复述上一轮已采纳的结论。
65
+ - 题号带轮次:第 N 轮写 `RN-Q1`、`RN-D1`,按轮次对应。回复不带轮次时:此前各轮已无未答题 → 指最近一轮;
66
+ 否则先问清指哪一轮再记录。
67
+ - 原型死区问题由宿主在分析前一次性发出(`materials` 阶段的既有行为),不受 5 题限制;
68
+ 用户逐项答复的死区作为已知事实不再重问,未答复的按 G1 第 3 条进入合并清单。
69
+
70
+ ```text
71
+ ❓ 第 {N} 轮需求确认(最多 5 题)
72
+
73
+ R{N}-Q1 【{检查项}】{问题}
74
+ 出处:{文档/代码/地图位置}
75
+ 推荐:{推荐答案}
76
+
77
+ R{N}-Q2 ...
78
+
79
+ 默认清单(需明确回复,未提到的默认项不算同意):
80
+ R{N}-D1 {默认做法}(出处:{位置})
81
+
82
+ 回复方式:「R{N} 全部按推荐」采纳本轮有推荐的题与默认清单;或逐题写「R{N}-Q1 是」「R{N}-Q2 否:{你的答案}」,
83
+ 默认项写「R{N} 默认全同意」或「R{N}-D1 是」「R{N}-D1 否:{你的答案}」;
84
+ 标「无推荐」的题请直接写答案,如「R{N}-Q3:{你的答案}」。
85
+ ```
86
+
87
+ - 本轮只有一题且该题有推荐答案时,回「是」即采纳该题推荐。本轮不止一题时,单回「是」不算任何一题的答案,
88
+ 下一条消息先问清指哪几题。
89
+ - 「全部按推荐」「默认全同意」同样按上条规则对应轮次。「全部按推荐」采纳写了推荐答案的题和默认清单,
90
+ 「默认全同意」只采纳默认清单;「无推荐,需产品决定」的题必须逐题回答。
91
+ - 未提到的题和默认项都保持未答,下一轮是否再问由 G2 重算前沿决定,不按沉默视为同意。
92
+
93
+ ## G4 停止、交接与记录
94
+
95
+ - **停止**:每次答复后重算前沿,前沿为空且全部 `阻断` 级已有用户答案即停止;
96
+ `阻断` 级答完后新解锁的 `默认` 项继续出默认清单,
97
+ 直到前沿为空(用户已说「先这样」时剩余默认项记为「留待人审」)。
98
+ 用户说「先这样」时,`默认` 级未答题转为「留待人审」;仍有 `阻断` 级未答题时只继续提问这些题,
99
+ 不进入生成。超时、沉默或推荐答案都不能代替用户答案。
100
+ - **答案矛盾**:每次答复后核对已答内容与需求、现有业务之间有无矛盾;有矛盾时把它作为新的 `阻断` 题
101
+ (检查项「业务矛盾」,出处写冲突的两条答案),解决前不满足停止条件。
102
+ - **宿主交接**:
103
+ - 每轮返回 `{status:"question", question:"<整轮文本>"}`;用户答复经 advance 回来后重算前沿。
104
+ - 满足「停止」条件才返回 `analyzed`(任何情况下都要求全部 `阻断` 级已有用户答案),
105
+ `openQuestions` 必须为 `[]`(非空会让宿主停在等待)。
106
+ - 逐条决定写进 `analyzed.summary` 的「范围与覆盖核对」段:本期做、明确不做、
107
+ 追问补齐项(检查项、出处、问题、答案或「默认」)、留待人审项。
108
+ - **写入规格**:新建模式 Step 8、变更模式 C5 读取该段,写入 `requirements.md` 的
109
+ 「范围与覆盖核对」一节,并同步受影响的功能需求与验收标准;留待人审项同时列入「开放问题」。
110
+ - **摘要卡**:Step 11 的 `openQuestions` 字符串先写一句倒推结果:
111
+ `倒推核对:{N} 项缺口,已答 {M},留待人审 {K}` 或 `倒推核对 7 项无缺口`。
112
+
113
+ ## 变更模式
114
+
115
+ C4 影响分析之后执行 G1–G4,倒推重点放在本次变更对已有线路、已完成任务和存量数据的影响。
116
+ C5 更新「范围与覆盖核对」时保留历史条目,新条目后标注本次需求版本(如 `[v2]`)。
@@ -42,7 +42,19 @@ description: 产品经理 Skill,负责需求分析、用户故事与验收标
42
42
  4. 异常怎么办?失败 / 超时 / 冲突时用户看到什么?
43
43
  5. 有没有敏感操作?支付 / 删除 / 隐私相关 → 必须人工确认
44
44
 
45
- **克制原则**:只列真正无法合理推断的问题;可以合理默认的写成"默认 X,如不符请指出"——不做无限追问式的确认(SuperPowers 的教训)。
45
+ **七项倒推清单**(对照现有业务找文档漏掉的范围;存量项目以业务地图和代码为出处,全新项目只查文档内部):
46
+
47
+ | 检查项 | 倒推什么 |
48
+ | ---- | ---- |
49
+ | 角色与权限 | 现有角色在新功能里各能做什么,谁不能做 |
50
+ | 状态流转 | 新增或改动的状态与现有状态机怎么衔接,有无到不了或出不去的状态 |
51
+ | 增删改查成对 | 只写了新增时,修改、删除、查看、撤销是否本期要做 |
52
+ | 存量数据 | 已有数据怎么迁移、补默认值或兼容展示 |
53
+ | 相邻线路 | 业务地图里共用同一数据或模块的其他线路是否受牵连 |
54
+ | 入口与通知 | 从哪里进入,是否需要提醒、消息或回到原处 |
55
+ | 报表与导出 | 现有统计、导出、搜索是否要纳入新数据 |
56
+
57
+ **克制原则**:只列真正无法合理推断的问题;可以合理默认的写成"默认 X,如不符请指出"——不做无限追问式的确认(SuperPowers 的教训)。cm-prd 中的分级、分轮与默认清单格式见 `../cm-prd/references/requirement-grilling.md`。
46
58
 
47
59
  ### 3. 拆分与优先级建议(服务 Step 6-7)
48
60