@aibyzero/cm-workflow 0.13.3 → 0.15.0

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 (88) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/README.md +22 -1
  4. package/VERSION +1 -1
  5. package/docs/installation.md +1 -1
  6. package/docs/js-workflow-control.md +2 -0
  7. package/docs/user-guide.md +3 -0
  8. package/package.json +1 -1
  9. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +1 -0
  10. package/runtime/js/cm-ai/cm-ai-admission.mjs +53 -22
  11. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +4 -5
  12. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +40 -17
  13. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +103 -23
  14. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -4
  15. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +5 -2
  16. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  17. package/runtime/js/cm-ai/developer-adapter.mjs +17 -5
  18. package/runtime/js/cm-ai/durable-runner-state.mjs +7 -2
  19. package/runtime/js/cm-ai/effect-contract.mjs +8 -1
  20. package/runtime/js/cm-ai/execution-store.mjs +25 -5
  21. package/runtime/js/cm-ai/host-check.mjs +20 -1
  22. package/runtime/js/cm-ai/host-conversation-execution.mjs +5 -4
  23. package/runtime/js/cm-ai/host-documentation.mjs +2 -2
  24. package/runtime/js/cm-ai/host-qa-executor.mjs +43 -21
  25. package/runtime/js/cm-ai/host-qa-policy.mjs +3 -1
  26. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +41 -3
  27. package/runtime/js/cm-ai/task-runner.mjs +1 -0
  28. package/runtime/js/cm-ai/worker-claude-developer.mjs +2 -1
  29. package/runtime/js/cm-fix/cause-package.mjs +3 -1
  30. package/runtime/js/cm-fix/dossier.mjs +7 -2
  31. package/runtime/js/cm-fix/reproduce.mjs +26 -5
  32. package/runtime/js/cm-init/draft-generation.mjs +3 -2
  33. package/runtime/js/cm-init/draft-inspection.mjs +17 -3
  34. package/runtime/js/cm-init/review-evidence.mjs +1 -1
  35. package/runtime/js/cm-prd/summary.mjs +6 -8
  36. package/runtime/js/cm-security/finalize.mjs +164 -0
  37. package/runtime/js/specs-status.mjs +66 -0
  38. package/scripts/cm-ai-admission.mjs +46 -7
  39. package/scripts/cm-ai-admission.test.mjs +50 -0
  40. package/scripts/cm-ai-batch-host.mjs +72 -10
  41. package/scripts/cm-ai-batch-host.test.mjs +128 -4
  42. package/scripts/cm-ai-batch-run.mjs +351 -17
  43. package/scripts/cm-ai-batch-run.test.mjs +190 -13
  44. package/scripts/cm-ai-bootstrap.test.mjs +3 -2
  45. package/scripts/cm-ai-host.mjs +38 -21
  46. package/scripts/cm-ai-host.test.mjs +68 -4
  47. package/scripts/cm-ai-nested-execution.test.mjs +1 -1
  48. package/scripts/cm-ai-run.mjs +25 -15
  49. package/scripts/cm-ai-run.test.mjs +48 -0
  50. package/scripts/cm-blocked-reason.test.mjs +104 -0
  51. package/scripts/cm-capability-gate.test.mjs +179 -0
  52. package/scripts/cm-codex-developer-adapter.test.mjs +70 -0
  53. package/scripts/cm-fix-cause-package.test.mjs +18 -1
  54. package/scripts/cm-fix-execution.test.mjs +31 -0
  55. package/scripts/cm-fix-host-review.test.mjs +2 -1
  56. package/scripts/cm-fix-host.test.mjs +2 -1
  57. package/scripts/cm-fix-observation-dossier.test.mjs +2 -0
  58. package/scripts/cm-fix-qa-source.test.mjs +1 -3
  59. package/scripts/cm-fix-reproduce.test.mjs +53 -2
  60. package/scripts/cm-fix-review-recovery.test.mjs +4 -3
  61. package/scripts/cm-host-check.test.mjs +22 -0
  62. package/scripts/cm-host-qa-executor.test.mjs +302 -3
  63. package/scripts/cm-host-qa-policy.test.mjs +34 -0
  64. package/scripts/cm-init-draft-generation.test.mjs +24 -3
  65. package/scripts/cm-init-draft-inspection.test.mjs +80 -0
  66. package/scripts/cm-init-host.mjs +2 -2
  67. package/scripts/cm-init-host.test.mjs +3 -1
  68. package/scripts/cm-init-session.test.mjs +37 -0
  69. package/scripts/cm-log-event.mjs +28 -7
  70. package/scripts/cm-prd-design-phase.test.mjs +2 -1
  71. package/scripts/cm-prd-host.test.mjs +3 -2
  72. package/scripts/cm-prd-session-recovery.test.mjs +5 -4
  73. package/scripts/cm-security.mjs +12 -4
  74. package/scripts/cm-security.test.mjs +109 -0
  75. package/scripts/cm-specs-status.test.mjs +130 -0
  76. package/scripts/cm-workflow-config.mjs +4 -0
  77. package/scripts/test-shell-compat.sh +0 -0
  78. package/skills/cm-ai/references/N1-init.md +20 -15
  79. package/skills/cm-ai/references/N6-qa-eval.md +9 -4
  80. package/skills/cm-ai/references/js-host.md +10 -0
  81. package/skills/cm-fix/SKILL.md +5 -4
  82. package/skills/cm-fix/references/js-host.md +13 -0
  83. package/skills/cm-idea/SKILL.md +2 -0
  84. package/skills/cm-init/references/runtime-declaration.md +2 -0
  85. package/skills/cm-prd/SKILL.md +9 -8
  86. package/skills/cm-prd/references/spec-self-check.md +1 -0
  87. package/skills/cm-security/SKILL.md +11 -6
  88. package/skills/cm-security/references/scan-contract.md +45 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-workflow",
3
- "version": "0.13.3",
3
+ "version": "0.15.0",
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
@@ -7,6 +7,32 @@
7
7
 
8
8
  (暂无)
9
9
 
10
+ ## 0.15.0 — 2026-09-19
11
+
12
+ - 浏览器验收能力改为启动时断言:开启 QA,且规格含阻塞 browser 用例或被 `policies.tests` 选中的 browser 用例时,`cm-ai-host` 与 `cm-ai-batch-host` 必须显式给 `--browser-qa available|unavailable`;因任务未完成而延后的适用用例也计入。`unavailable` 以 `browser_capability_unavailable` 拒绝启动,错误 JSON 仍只输出 code;使用者需换到具备浏览器能力的会话,或调整验收范围并重新审批规格。不命中时给该参数报 `invalid_arguments`。这是**声明不是探测**,声明不持久化,创建与恢复均须重新声明。
13
+ - **配置兼容性变更**:共享配置加载器现在要求 `policies.tests` 含 `browser` 时,`roles.browser_qa.adapter` 必须为 `browser`。此前可用的显式 `browser_qa: {adapter: local, model: none, source: local}` 配合默认测试策略(包含 browser),升级后会被拒绝,影响所有使用共享配置加载器的入口。需要浏览器 QA 的使用者应将适配器改为 `browser`(保留 `model: none, source: local`),或删除该角色覆盖以继承默认 browser 角色;不需要浏览器 QA 时,应将 `policies.tests` 显式设为如 `[logic, commands]`。省略整个 browser_qa 角色仍可继承默认值;移除策略中的 browser 不会排除阻塞 browser 用例,相关验收范围仍需明确处理。
14
+ - 统一 `.cm-specs-status` 读写:cm-prd 使用共享原子 writer;cm-ai 新增 `--approve --approval-response`,只放行指定准入原因,禁止 `--yes` 写审批位,写后重跑准入。审批沿用原 `summaryDigest`(缺失为 null),兼容读取旧文件并在下次写入去掉 `via` 等自由字段;cm-idea 明确保持在 specs 上游。
15
+
16
+ - `cm-security` 新增报告门禁 `--finalize --scan ... --review ...`:严格校验逐路径复核输入,机械补齐漏报、重验复核窗口漂移并保留扫描窗口证据,统一在项目外生成报告并给出四种结论之一。无发现且覆盖为 FULL 仍是 `REVIEWED_PARTIAL`,不存在「干净」的结论词;模型不能传入 `result`、`coverage` 或 `aiReview`。报告原样保留通过校验的分析结论与修复建议,stdout 只含摘要字段。
17
+ - 批次首次推进要求 Git 主工作区干净(含未跟踪文件);否则以 `batch_main_dirty` 列出脏文件,在任务启动及创建工作树之前阻断。串行任务在 `start_next_task` 交接前自动提交,`batch_handoff.task_commit` 记录 SHA(无改动为 null)。并行组先合并 ready 成员,再保存终态成员 WIP、移除工作树并保留分支;通过 `batch_member_blocked` 日志恢复一次性的 generation 2 串行降级。
18
+ - 开发者结构化输出模式(Codex 两个 schema 与 Claude 提案 schema)新增可空 `reason`,`validateClaudeProposal` 同步放行该键:此前模式为 `additionalProperties:false` 且不含该键,CLI 派发下模型无法给出 blocked 原因,落盘功能在真实路径上等同未生效。`validateDeveloperValue` 将任意 outcome 下的 `reason: null` 归一为缺省,`implemented` 带非空 reason 仍按 `invalid_result` 拒绝。
19
+ - 开发结果 `blocked` 的可选 `reason` 以 `blockedReason` 持久化到开发调用记录:字符串 trim 后非空、至多 1000 UTF-8 字节,禁止 NUL 及除换行、制表符外的 C0 控制字符。终态仍为 `failed/result:null`,入口仍为 `blocked/failed`,重试与结果摘要语义不变;并行成员日志及 WIP 提交正文保留原因。旧日志无该字段照常回放;含新字段的日志会被旧运行时按未知键拒绝,不做版本协商。契约拆分明确告知调用方与实现方:抛错占位体是预期状态,不应等待或据此 blocked。
20
+ - 批次入口支持 `bundle.batch.parallel`:通过 `eligibleTasks` / 受信 `parallelSelection` 绑定并行准入与恢复,`parallelMember` 将成员 QA 延后到主分支串行末任务;成员工作树逐个执行审查预检并缓存,恢复时仅复用匹配凭证,预检失败则整组在 start 前阻断。新增 `--protected-config` 与逐任务 `--allow-provider-development` 授权,按成员工作树的项目声明派发 CLI 写码,并复用配置执行合并后检查。
21
+ - 执行存储锁改为运行级,不同 runId 可独立持锁;创建新运行时先探测旧布局锁,成功释放后继续,失败返回 `store_busy`,旧文件不迁移、不改写。
22
+ 恢复已有运行时,缺少本运行 `writer.sqlite` 返回 `store_layout_legacy`,须用旧版本收尾或退休该 runId;已有运行级锁则正常恢复。
23
+
24
+ ## 0.14.0 — 2026-09-18
25
+
26
+ - 第 32 步:`cm-fix` 按描述未复现后先做最多 3 个场景或 15 分钟的单维度复现探索;档案新增复现尝试,JS 结果兼容旧记录并校验尝试结论,观测闭环要求至少一条尝试。
27
+ - 第 33 步:`cm-ai` 准入新增只读 `--print-run-definition` 直接生成运行定义(`--scope` 必填),`invalid_config` 点名多余/缺失字段、版本与文件类型,usage 与文档说明键集精确且参与摘要绑定。
28
+ - 第 34 步:受保护检查证据仅追加白名单测试计数摘要,同标签保留首次、最多 8 条、总长不超过 200 字符;不记录原始输出、凭证、路径或耗时,无计数及 unavailable 行为保持不变。
29
+
30
+ ## 0.13.4 — 2026-09-18
31
+
32
+ - 第 29 步:`cm-init` 机械核验配置草稿的运行时五字段与所选预设一致,不符时阻断;从模板新建配置时按版本控制与 UI 模块事实裁剪 delivery/tests,并对不适用的默认策略给出非阻塞 warning,已有配置仍保留无关字段。
33
+ - 第 30 步:修复 `cm-ai` N6 中途 QA 提前执行未完成任务用例;延后用例写入日志与报告,命令按选中逻辑用例映射,显式恢复可用新 testRunId 绑定更新后的计划。`five_tasks_without_qa` 不再把已收尾 feature 缺失的 N6 历史行计为当前积压。第 30b 步:中途用例全部延后且无可调度命令时,以单条 `no-applicable-cases` BLOCKED 行显式报告空计划。
34
+ - 第 31 步:`cm-ai` 单任务 resume 新增 `--rerun-blocked-qa`,显式授权后仅将最新已完成的纯宿主/环境证据 BLOCKED 记为 superseded,并在最多三轮内全量重跑;保留原 QA 决策、开发/审查和任务状态,QA complete 同步 N6 状态镜像。
35
+
10
36
  ## 0.13.3 — 2026-09-17
11
37
 
12
38
  - 第 28 步:`cm-runtime` 无参数在 TTY 中进入范围、工具/写码方、确认三问向导,复用安装器提问与既有 set/decision 日志,完成后显示有效配置;非 TTY 退出 2。安装器、向导与诊断共用系统语言中英文文案,机器字段不变;会话无参数按对话语言提问,文档与帮助同步。
package/README.md CHANGED
@@ -17,6 +17,27 @@
17
17
 
18
18
  ## 最近更新
19
19
 
20
+ **0.15.0**
21
+
22
+ - **兼容性变更(升级前必读)**:旧布局执行存储恢复时返回 `store_layout_legacy`,请用旧版本收尾或退休该 `runId`,旧文件不会自动迁移;显式将 `roles.browser_qa.adapter` 设为非 `browser` 却沿用含 `browser` 的默认测试策略会被拒绝,需要浏览器 QA 时请改为 `browser`(保留 `model: none, source: local`)或删除角色覆盖以继承默认值,不需要时请显式将 `policies.tests` 设为如 `[logic, commands]`,阻塞 browser 用例仍须另行处理验收范围并重新审批;含新字段的运行日志会被旧版本按未知键拒绝,请用 0.15.0 或兼容该字段的后续版本继续运行,不要用旧版本回放这类日志。
23
+ - **同 feature 并行开发**:无依赖任务可在各自工作树中并行开发,再串行合并到主分支,成员 QA 延后到末任务统一执行;批次会自动提交与合并,首次推进前请保持 Git 主工作区干净(含未跟踪文件),被阻塞成员的 WIP 与原因会保留。
24
+ - **规格审批位统一写入**:`cm-prd` 与 `cm-ai` 共用 `.cm-specs-status` 原子写入入口,模型不再手拼审批文件;`cm-ai` 新增 `--approve --approval-response`,记录审批后重新核验准入,`--yes` 不能代替审批。
25
+ - **cm-security 报告门禁**:新增 `--finalize --scan ... --review ...`,由代码校验逐路径复核、补齐漏报并判定报告结论,模型不再自述最终状态;无发现且扫描覆盖为 FULL 时仍为 `REVIEWED_PARTIAL`,报告保留通过校验的分析与修复建议。
26
+ - **浏览器验收能力提前声明**:开启 QA 且规格需要浏览器验收时,单任务与批次入口在启动或恢复时要求显式传入 `--browser-qa available|unavailable`,不再等到最后一步才暴露能力缺失;不可用时请换到具备浏览器能力的会话,或调整验收范围并重新审批规格,这是能力声明,并非自动探测。
27
+ - **开发阻塞原因可追溯**:开发结果 `blocked` 的可选 `reason` 现在能从 CLI 结构化输出落盘为 `blockedReason`,并保留在并行成员日志和 WIP 提交正文中,恢复排查时可查看具体原因。
28
+
29
+ **0.14.0**
30
+
31
+ - **运行定义不再手写**:`cm-ai` 准入新增只读 `--print-run-definition`,把它已经解析出的 specs/代码根、feature 与任务直接生成为合法运行定义(`--scope` 必填,因为"本任务允许改哪些文件"是框架推不出来的唯一一项);`invalid_config` 改为点名多余/缺失字段、版本与文件类型。
32
+ - **N6 QA 更贴合实际进度**:feature 未完成时只执行已完成任务的用例,其余记入 `deferred_cases` 延后到 feature 收尾;`five_tasks_without_qa` 不再把已收尾 feature 的历史计为积压;QA 因宿主或环境证据问题整体 BLOCKED 时可用 `--rerun-blocked-qa` 显式重跑一轮,QA 结束同步写回状态镜像。
33
+ - **审查证据更可判**:受保护检查的证据追加测试计数(`host check exited 0 (tests 27, pass 27, fail 0)`),原始输出仍不进入审查数据。
34
+ - **cm-fix 先复现再修**:按描述未复现时不直接进观测闭环,先沿输入值、前置状态、时序、环境、规模五个维度单维度构造场景,上限 3 个场景或 15 分钟,命中即作为红灯测试骨架;缺陷档案新增复现尝试记录。
35
+ - **cm-init 配置核验**:机械核验配置草稿与所选运行时预设一致,并按版本控制与 UI 模块事实裁剪新建配置的 delivery/tests。
36
+
37
+ **0.13.4**
38
+
39
+ - **第二轮真项目 dogfood 修复**:在 specs 与代码分离的真实项目上再跑一遍 `cm-init → cm-prd → cm-ai`(Codex 写码、Claude CLI 独立审查、feature 收尾 QA)并修复沿路暴露的 3 处运行时缺陷——`cm-init` 现在机械核验配置草稿与所选运行时预设一致并按项目事实裁剪新建配置的 delivery/tests;`cm-ai` 的 N6 在 feature 未完成时只执行已完成任务的用例、其余记入 `deferred_cases`,`five_tasks_without_qa` 不再把已收尾 feature 的历史计为积压;QA 因宿主/环境证据问题整体 BLOCKED 时可用 `--rerun-blocked-qa` 显式重跑一轮,QA 结束同步写回状态镜像。详见[更新日志](CHANGELOG.md)。
40
+
20
41
  **0.13.3**
21
42
 
22
43
  - **`cm-runtime` 直接敲就是向导**:不带参数运行时按编号三问——改哪一层(当前项目 / 用户级默认)→ 手上有哪个 AI(只有 Codex / 只有 Claude / 两个都有)→ 谁写代码,预览后确认才写入,然后回显有效配置;非终端环境只打印用法并退出 2,脚本化仍用 `show` / `set` / `unset --user`。
@@ -101,7 +122,7 @@ $cm-check
101
122
 
102
123
  仓库直接分发 Skills 和脚本,无需在仓库根目录运行 `npm install` 或构建。完整安装行为、覆盖范围和卸载说明见[安装指南](docs/installation.md)。
103
124
 
104
- 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.13.3 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
125
+ 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.15.0 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
105
126
 
106
127
  ## 升级旧版本
107
128
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.3
1
+ 0.15.0
@@ -73,7 +73,7 @@ Install or upgrade with the same command:
73
73
  npx @aibyzero/cm-workflow@latest install
74
74
  ```
75
75
 
76
- To pin a version, use `npx @aibyzero/cm-workflow@0.13.3 install` from outside
76
+ To pin a version, use `npx @aibyzero/cm-workflow@0.15.0 install` from outside
77
77
  the CM Workflow source checkout (for example, your home directory). Inside a
78
78
  checkout with the same package name and version, npm can select the local
79
79
  uninstalled package and report `cm-workflow: command not found`.
@@ -239,6 +239,8 @@ constraintChanges必须空;application/retrospective沿原Learning字段。此
239
239
  ```
240
240
 
241
241
  scope 和 requirements 是相对代码根的已有 runner 输入,不是额外写入授权。
242
+ 键必须恰好如示例,不得新增字段(已声明的多代码根模式仅允许原有可选 `codeProjects`);定义参与摘要绑定,擅加字段会使同一次 run 的摘要漂移并导致 resume 失败。
243
+ 用准入生成器产出定义(`--scope` 必填,填写相对代码根、逗号分隔的允许修改文件;`--requirements` 可选,省略时为空数组):`node scripts/cm-ai-admission.mjs --specs-dir /absolute/specs --code-project /absolute/code --print-run-definition --scope src/login.js --requirements requirements.md > run.json`。
242
244
 
243
245
  ```bash
244
246
  node scripts/cm-ai-run.mjs serve --config /absolute/run.json --mode create
@@ -341,6 +341,8 @@ $cm-test ~/code/my-app 用户登录
341
341
  $cm-fix ~/projects/my-app-specs ~/code/my-app 登录成功后仍然停留在登录页
342
342
  ```
343
343
 
344
+ 按描述未复现时,`$cm-fix` 会先按输入、状态、时序、环境、规模逐次改变一个维度主动探索,最多 3 个场景或 15 分钟(先到为准);命中场景用作红灯测试骨架,到上限仍未复现才进入观测闭环,档案记录全部复现尝试。
345
+
344
346
  `$cm-fix` 会先建立可复现的红灯测试,再定位根因、做最小修复、回归并审查。跨服务、异步或偶现问题会在本地记录最小观测、调用链和假设;仅在无法稳定复现时才进入“观测中”,证据到手后按原 slug 续跑。已可复现的问题则带着证据链走正常七步。若调查发现实际需要新增行为或改变契约,应退出修复流,改走 `$cm-prd --change`。
345
347
 
346
348
  </details>
@@ -565,6 +567,7 @@ $cm-security {项目路径} --semgrep-rules {外部本地规则文件} --osv-db
565
567
  优先级:**项目 > 用户级默认 > 未声明**。项目没有 `runtimes.available` 才读取用户文件;
566
568
  显式项目角色字段覆盖用户预设的角色默认值,矛盾配置报字段路径并阻断。
567
569
  `cm-init` 遇到用户默认直接继承、报告 `来源: 用户级默认`,两级都没有才询问。
570
+ 配置草稿的运行时五字段必须与所选预设一致;新建配置时还按项目事实裁剪 delivery/tests(local/none 用 branch 或 diff,无 frontend/miniprogram 去掉 browser,未裁剪则给出非阻塞 warning),已有配置只更新运行时五字段。
568
571
 
569
572
  | 预设 | 写代码 | 审代码 |
570
573
  | --- | --- | --- |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibyzero/cm-workflow",
3
- "version": "0.13.3",
3
+ "version": "0.15.0",
4
4
  "description": "Spec-driven business development workflow for Pi, Codex, and Claude Code",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -30,6 +30,7 @@
30
30
  "blocked"
31
31
  ]
32
32
  },
33
+ "reason": {"type": ["string", "null"]},
33
34
  "application": {
34
35
  "type": "object",
35
36
  "additionalProperties": false,
@@ -1,9 +1,10 @@
1
- // Read-only N1/N2 admission for the fixed cm-ai workflow. It never writes project state.
1
+ // N1/N2 inspection is read-only; explicit approval uses the shared status writer.
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { spawnSync } from 'node:child_process';
6
6
  import { fileURLToPath } from 'node:url';
7
+ import {readSpecsStatus,writeSpecsStatus} from '../specs-status.mjs';
7
8
  import {buildManifest,verifyManifest} from '../../../scripts/cm-spec-manifest.mjs';
8
9
 
9
10
  const TASK=/^\s*-\s*\[([ xX])\]\s+(?:~~)?(T-[A-Za-z0-9][A-Za-z0-9._-]*)(?=[:\s])[:\s]*(.*)$/;
@@ -33,22 +34,24 @@ export function inspectCmAiQaTaskContext({specsDir,codeProject,feature,taskId})
33
34
  const fail=code=>{throw Object.assign(new Error(code),{code});};
34
35
  if(!['ready','complete'].includes(admission.state))fail(admission.reason);
35
36
  const discovered=discoverFeatures(admission.specsDir);if(discovered.error)fail(discovered.error);
36
- const completed=[];let selected=null;
37
+ const completed=[],pendingFeatures=[];let selected=null;
37
38
  for(const name of discovered.names){
38
39
  const parsed=readFeature(admission.specsDir,name);if(parsed.error)fail(parsed.error);
39
40
  if(name===feature)selected=parsed.tasks;
41
+ if(parsed.tasks.some(task=>!task.completed&&!task.dropped))pendingFeatures.push(name);
40
42
  for(const task of parsed.tasks)if(task.completed&&!task.dropped)completed.push({feature:name,id:task.id});
41
43
  }
42
- if(!selected?.some(task=>task.id===taskId&&task.completed&&!task.dropped))fail('qa_not_ready');
44
+ // Plan construction happens before task completion; decisions still bind a completed task.
45
+ if(!selected||(taskId!==undefined&&!selected.some(task=>task.id===taskId&&task.completed&&!task.dropped)))fail('qa_not_ready');
43
46
  const pending=selected.filter(task=>!task.completed&&!task.dropped).length;
44
- return frozen({completed,pending,mergeEligible:pending===1&&admission.nextTask?.feature===feature});
47
+ return frozen({completed,pendingFeatures,pending,mergeEligible:pending===1&&admission.nextTask?.feature===feature});
45
48
  }
46
49
 
47
50
  // Admission's public feature summary stops at the selected feature. Count all
48
51
  // approved features with the same parser before treating a task as the last one.
49
- export function isFinalCmAiTask({specsDir,codeProject,feature,taskId}) {
52
+ export function isFinalCmAiTask({specsDir,codeProject,feature,taskId,parallelSelection=null}) {
50
53
  const admission=inspectCmAiAdmission({specsDir,codeProject});
51
- if(admission.state!=='ready'||admission.nextTask.feature!==feature||admission.nextTask.id!==taskId)
54
+ if(!matchesCmAiTaskSelection(admission,feature,taskId,parallelSelection))
52
55
  throw Object.assign(new Error('documentation_admission_required'),{code:'documentation_admission_required'});
53
56
  const discovered=discoverFeatures(admission.specsDir);
54
57
  if(discovered.error)throw Object.assign(new Error(discovered.error),{code:discovered.error});
@@ -67,7 +70,7 @@ function frozen(value){
67
70
  }
68
71
 
69
72
  function result(base,state,reason,extra={}){
70
- return frozen({...base,state,reason,features:[],nextTask:null,warnings:[],...extra});
73
+ return frozen({...base,state,reason,features:[],nextTask:null,eligibleTasks:[],warnings:[],...extra});
71
74
  }
72
75
 
73
76
  function directory(value){
@@ -82,18 +85,6 @@ function approvalIntent(response,assumeYes){
82
85
  return typeof response==='string'&&response.trim()==='开始'?'explicit':'not_approval';
83
86
  }
84
87
 
85
- function readStatus(specsDir){
86
- const target=path.join(specsDir,'.cm-specs-status');
87
- if(!fs.existsSync(target))return {kind:'missing'};
88
- try{
89
- const specsRoot=fs.realpathSync(specsDir),realTarget=fs.realpathSync(target);
90
- if(!contained(specsRoot,realTarget))return {kind:'invalid'};
91
- const value=JSON.parse(fs.readFileSync(realTarget,'utf8'));
92
- if(value===null||typeof value!=='object'||Array.isArray(value)||!['approved','awaiting_review'].includes(value.status))
93
- return {kind:'invalid'};
94
- return {kind:'valid',value};
95
- }catch{return {kind:'invalid'};}
96
- }
97
88
 
98
89
  function contained(root,target){
99
90
  const relative=path.relative(root,target);
@@ -331,7 +322,9 @@ function selectTask(specsDir,names){
331
322
  return dependency&&(dependency.completed||dependency.dropped);
332
323
  }));
333
324
  if(!eligible)return {error:'dependencies_not_ready',features,warnings};
334
- return {features,warnings,nextTask:{feature:name,id:eligible.id,description:eligible.description}};
325
+ return {features,warnings,nextTask:{feature:name,id:eligible.id,description:eligible.description},
326
+ eligibleTasks:pending.filter(task=>(parsed.dependencies.get(task.id)||[]).every(id=>byId.get(id)?.completed))
327
+ .map(task=>({feature:name,id:task.id}))};
335
328
  }
336
329
  return {features,warnings,nextTask:null};
337
330
  }
@@ -340,6 +333,32 @@ export function inspectCmAiAdmission(options){
340
333
  return admissionFor(options);
341
334
  }
342
335
 
336
+ // The CLI supplies every code project so no project can be skipped before writing.
337
+ export function approveCmAiSpecs(options){
338
+ const projects=options.codeProjects??[options.codeProject];
339
+ const inspect=()=>projects.map(codeProject=>inspectCmAiAdmission({...options,codeProject}));
340
+ const projectResults=inspect();
341
+ const refuse=approveRefused=>({projectResults,approveRefused});
342
+ if(options.assumeYes)return refuse('assume_yes_not_allowed');
343
+ if(typeof options.approvalResponse!=='string'||!options.approvalResponse.trim())
344
+ return refuse('approval_response_required');
345
+ const allowed=new Set(['approval_write_required','spec_features_changed','test_cases_changed']);
346
+ const rejected=projectResults.find(item=>item.state!=='awaiting_spec_approval'
347
+ ||item.approvalIntent!=='explicit'||!allowed.has(item.reason));
348
+ if(rejected)return refuse(rejected.approvalIntent!=='explicit'?'explicit_approval_required':rejected.reason);
349
+ const specsDir=projectResults[0].specsDir,status=readSpecsStatus(specsDir);
350
+ if(status.kind==='invalid')return refuse('spec_status_invalid');
351
+ try{
352
+ const discovered=discoverFeatures(specsDir);
353
+ if(discovered.error)return refuse(discovered.error);
354
+ const specFiles=buildManifest(specsDir),at=new Date().toISOString();
355
+ writeSpecsStatus(specsDir,{status:'approved',summaryDigest:status.value?.summaryDigest??null,at,
356
+ features:discovered.names,specFiles,testCases:specFiles.filter(item=>item.path.endsWith('/test-cases.json')),
357
+ approval:{response:options.approvalResponse,at}});
358
+ }catch(error){return refuse(error.code??error.message);}
359
+ return {projectResults:inspect()};
360
+ }
361
+
343
362
  function admissionFor(options,inProgressBootstrap=null){
344
363
  const input=options&&typeof options==='object'&&!Array.isArray(options)?options:{};
345
364
  const specsDir=directory(input.specsDir),codeProject=directory(input.codeProject);
@@ -348,7 +367,7 @@ function admissionFor(options,inProgressBootstrap=null){
348
367
  if(!codeProject)return result(base,'blocked','code_project_missing');
349
368
  const discovered=discoverFeatures(specsDir);
350
369
  if(discovered.error)return result(base,'blocked',discovered.error);
351
- const status=readStatus(specsDir);
370
+ const status=readSpecsStatus(specsDir);
352
371
  if(status.kind==='invalid')return result(base,'blocked','spec_status_invalid');
353
372
  if(status.kind==='missing'||status.value.status==='awaiting_review'){
354
373
  const reason=base.approvalIntent==='explicit'?'approval_write_required':'spec_approval_required';
@@ -371,5 +390,17 @@ function admissionFor(options,inProgressBootstrap=null){
371
390
  if(selection.error)return result(base,'blocked',selection.error,{features:selection.features,warnings:selection.warnings,
372
391
  ...(selection.detail?{detail:selection.detail}:{})});
373
392
  if(!selection.nextTask)return result(base,'complete','all_tasks_terminal',{features:selection.features,warnings:selection.warnings});
374
- return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,warnings:selection.warnings});
393
+ return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,eligibleTasks:selection.eligibleTasks,warnings:selection.warnings});
394
+ }
395
+
396
+ // Trusted caller selection is data bound by openControlRun, never message authority.
397
+ export function matchesCmAiTaskSelection(admission,feature,taskId,parallelSelection=null){
398
+ if(parallelSelection===null)return admission.state==='ready'
399
+ &&admission.nextTask?.feature===feature&&admission.nextTask.id===taskId;
400
+ const value=parallelSelection;
401
+ return admission.state==='ready'&&value?.version===1
402
+ &&Object.keys(value).sort().join(',')==='group,version'&&Array.isArray(value.group)
403
+ &&value.group.length>=2&&new Set(value.group).size===value.group.length
404
+ &&value.group.every(id=>typeof id==='string'&&TASK_ID.test(id))&&value.group.includes(taskId)
405
+ &&admission.eligibleTasks?.some(task=>task.feature===feature&&task.id===taskId)===true;
375
406
  }
@@ -2,7 +2,7 @@
2
2
  import {createHash} from 'node:crypto';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
- import {inspectCmAiAdmission} from './cm-ai-admission.mjs';
5
+ import {inspectCmAiAdmission,matchesCmAiTaskSelection} from './cm-ai-admission.mjs';
6
6
  import {arrayItems,digest,freeze,hex,json,need,shape,text,validIdentity,validTaskLearningInput} from './effect-contract.mjs';
7
7
 
8
8
  const BASELINE_RULES=['coding-style.md','testing.md','security.md'];
@@ -65,7 +65,7 @@ export function inspectCmAiContextRefresh(input,{admission:trustedAdmission=null
65
65
  if(trustedAdmission!==null)need(input.feature==='0.bootstrap'
66
66
  &&admission.specsDir===input.specsDir&&admission.codeProject===input.codeProject,'context_invalid');
67
67
  if(!['ready','complete'].includes(admission.state))return freeze({state:admission.state,reason:admission.reason,
68
- nextTask:null,contextDigest:null,contextFiles:[]});
68
+ nextTask:null,eligibleTasks:[],contextDigest:null,contextFiles:[]});
69
69
  need(admission.features.some(item=>item.name===input.feature),'context_invalid');
70
70
  const featureNames=admission.state==='complete'?admission.features.map(item=>item.name):[input.feature];
71
71
  const files=featureNames.flatMap(feature=>['requirements.md','design.md','tasks.md'].map(name=>
@@ -74,7 +74,7 @@ export function inspectCmAiContextRefresh(input,{admission:trustedAdmission=null
74
74
  files.push(...projectFiles(input.codeProject,input.applicableAgentFiles));
75
75
  const contextFiles=files.map(file=>file.metadata).sort((left,right)=>
76
76
  left.scope.localeCompare(right.scope)||left.path.localeCompare(right.path));
77
- return freeze({state:admission.state,reason:admission.reason,nextTask:admission.nextTask,
77
+ return freeze({state:admission.state,reason:admission.reason,nextTask:admission.nextTask,eligibleTasks:admission.eligibleTasks??[],
78
78
  contextDigest:digest({version:1,files:contextFiles}),contextFiles});
79
79
  }
80
80
 
@@ -83,8 +83,7 @@ export function inspectCmAiTaskLearningInput(input,authority={}) {
83
83
  text(input.feature);const identity=json(input.identity);validIdentity(identity);
84
84
  const refresh=inspectCmAiContextRefresh({specsDir:input.specsDir,codeProject:input.codeProject,
85
85
  feature:input.feature,applicableAgentFiles:input.applicableAgentFiles},authority);
86
- need(refresh.state==='ready'&&refresh.nextTask?.feature===input.feature
87
- &&refresh.nextTask.id===identity.taskId,'learning_context_invalid');
86
+ need(matchesCmAiTaskSelection(refresh,input.feature,identity.taskId,authority.parallelSelection??null),'learning_context_invalid');
88
87
  const agentPaths=new Set(['AGENTS.md',...arrayItems(input.applicableAgentFiles)]);
89
88
  const selected=refresh.contextFiles.filter(file=>file.scope==='specs'?file.path==='LESSONS.md':
90
89
  file.scope==='project'&&agentPaths.has(file.path));
@@ -1,5 +1,5 @@
1
1
  // Fixed Codex-host entry for the existing cm-ai admission and V3 task runner.
2
- import {inspectCmAiAdmission} from './cm-ai-admission.mjs';
2
+ import {inspectCmAiAdmission,matchesCmAiTaskSelection} from './cm-ai-admission.mjs';
3
3
  import {inspectCmAiContextRefresh,inspectCmAiTaskLearningInput} from './cm-ai-context-refresh.mjs';
4
4
  import {findCmAiQaDecision,inspectCmAiQaDecision,inspectCmAiQaResult,recordCmAiQaDecision,
5
5
  latestCmAiQaRun,recordCmAiQaRun,inspectCmAiQaRecovery} from './cm-ai-qa-log.mjs';
@@ -31,7 +31,9 @@ const pendingAction=status=>status.state==='awaiting_spec_approval'?'spec_approv
31
31
  status.state==='fixture_completed'?'qa':'none';
32
32
  const summary=(operation,status,outcome)=>freeze({version:1,workflow:'cm-ai',operation:operation.operation,
33
33
  requestDigest:digest(operation),identity:status.identity,outcome,state:status.state,code:status.code??null,
34
- packageDigest:status.packageDigest??null,pendingAction:pendingAction(status)});
34
+ packageDigest:status.packageDigest??null,pendingAction:pendingAction(status),
35
+ ...(status.state==='blocked'&&status.calls?.at(-1)?.blockedReason!==undefined
36
+ ?{blockedReason:status.calls.at(-1).blockedReason}:{})});
35
37
  const correctionSummary=(operation,status)=>status.code==='correction_review_required'
36
38
  ?summary(operation,status,'blocked'):null;
37
39
 
@@ -126,10 +128,12 @@ export function createCmAiConversationEntry(options) {
126
128
  if(options&&Object.hasOwn(options,'qaDecisionProvider'))optionKeys.push('qaDecisionProvider');
127
129
  if(options&&Object.hasOwn(options,'qaExecutor'))optionKeys.push('qaExecutor');
128
130
  if(options&&Object.hasOwn(options,'rerunUnknownQa'))optionKeys.push('rerunUnknownQa');
131
+ if(options&&Object.hasOwn(options,'rerunBlockedQa'))optionKeys.push('rerunBlockedQa');
129
132
  if(options&&Object.hasOwn(options,'qaLogHome'))optionKeys.push('qaLogHome');
130
133
  if(options&&Object.hasOwn(options,'applicableAgentFiles'))optionKeys.push('applicableAgentFiles');
131
134
  if(options&&Object.hasOwn(options,'documentationResult'))optionKeys.push('documentationResult');
132
135
  if(options&&Object.hasOwn(options,'documentationProvider'))optionKeys.push('documentationProvider');
136
+ if(options&&Object.hasOwn(options,'parallelSelection'))optionKeys.push('parallelSelection');
133
137
  shape(options,optionKeys);
134
138
  if(Object.hasOwn(options,'developmentAttempt'))need([1,2].includes(options.developmentAttempt),'invalid_development_attempt');
135
139
  text(options.specsDir);text(options.codeProject);text(options.feature);
@@ -169,11 +173,15 @@ export function createCmAiConversationEntry(options) {
169
173
  let pendingQa=null;
170
174
  let qaExecutor=null,pendingExecution=null,cancellationEpoch=0;
171
175
  let rerunUnknownQa=options.rerunUnknownQa??false;need(typeof rerunUnknownQa==='boolean');
176
+ let rerunBlockedQa=options.rerunBlockedQa??false;need(typeof rerunBlockedQa==='boolean');
177
+ need(!(rerunUnknownQa&&rerunBlockedQa),'qa_recovery_authorization_required');
172
178
  if(Object.hasOwn(options,'qaExecutor')){
173
179
  shape(options.qaExecutor,['mode','caseCount','timeoutMs','run',
174
- ...(Object.hasOwn(options.qaExecutor,'configuration')?['configuration']:[])]);
175
- const {run,...config}=options.qaExecutor;
176
- need(typeof run==='function');qaExecutor={...json(config),run};
180
+ ...(Object.hasOwn(options.qaExecutor,'configuration')?['configuration']:[]),
181
+ ...(Object.hasOwn(options.qaExecutor,'prepare')?['prepare']:[])]);
182
+ const {run,prepare,...config}=options.qaExecutor;
183
+ need(typeof run==='function'&&(prepare===undefined||typeof prepare==='function'));
184
+ qaExecutor={...json(config),run,...(prepare?{prepare}:{})};
177
185
  need(['commands','browser','all'].includes(config.mode)&&Number.isSafeInteger(config.caseCount)&&config.caseCount>0);
178
186
  need(Number.isInteger(config.timeoutMs)&&config.timeoutMs>=1&&config.timeoutMs<=3600000);
179
187
  }
@@ -266,6 +274,14 @@ export function createCmAiConversationEntry(options) {
266
274
  notCancelled();
267
275
  result=await call('qa',result.packageDigest);
268
276
  if(result.outcome==='recorded'&&result.code==='qa_triggered'&&qaExecutor!==null){
277
+ // The host is constructed before N5 marks the task complete. Freeze the
278
+ // execution plan only now, then retain it throughout this invocation.
279
+ if(qaExecutor.prepare){
280
+ const prepared=json(qaExecutor.prepare());shape(prepared,['mode','caseCount','configuration']);
281
+ need(['commands','browser','all'].includes(prepared.mode)
282
+ &&Number.isSafeInteger(prepared.caseCount)&&prepared.caseCount>0,'qa_plan_invalid');
283
+ qaExecutor={...qaExecutor,...prepared};
284
+ }
269
285
  notCancelled();
270
286
  need(pendingExecution===null,'qa_execution_pending');
271
287
  const binding={specsDir:options.specsDir,feature:options.feature,identity:result.identity,packageDigest:result.packageDigest};
@@ -280,13 +296,17 @@ export function createCmAiConversationEntry(options) {
280
296
  if(recovery===null)return summary(operation,{...runner.status(),code:'qa_execution_unknown'},'blocked');
281
297
  previous=null;
282
298
  }
299
+ if(rerunBlockedQa){
300
+ need(previous!==null,'qa_rerun_not_blocked_by_evidence');
301
+ recovery=inspectCmAiQaRecovery(binding,{blocked:true,environment:qaExecutor.configuration?.environment});
302
+ }
283
303
  let testRunId=previous?.testRunId;
284
304
  const accepted=runner.status().acceptedQaFix;
285
305
  const repaired=previous?.status==='failed'&&accepted?.testRunId===previous.testRunId;
286
- if(previous===null||repaired){
287
- // Later rounds require an original completed child accepted by the
288
- // parent journal. Unknown executions and unrepaired failures stop.
289
- const qaRound=recovery?.qaRound??(repaired?accepted.qaRound+1:1);
306
+ if(previous===null||repaired||rerunBlockedQa){
307
+ // Later rounds require an accepted completed repair or explicit
308
+ // evidence-only BLOCKED recovery. Unknown and unrepaired FAIL stop.
309
+ const qaRound=recovery?recovery.qaRound+(rerunBlockedQa?1:0):(repaired?accepted.qaRound+1:1);
290
310
  need(qaRound>=1&&qaRound<=3,'qa_round_invalid');
291
311
  testRunId=`qa-${digest(recovery?{...binding,previousTestRunId:recovery.testRunId}:
292
312
  repaired?{...binding,qaRound,repair:accepted.evidenceDigest}:binding).slice(0,48)}`;
@@ -295,11 +315,14 @@ export function createCmAiConversationEntry(options) {
295
315
  const logInput={...invocation,...(Object.hasOwn(options,'qaLogHome')?{logHome:options.qaLogHome}:{})};
296
316
  notCancelled();
297
317
  if(recovery){
298
- need(qaExecutor.mode===recovery.mode&&qaExecutor.caseCount===recovery.caseCount,'qa_execution_mismatch');
299
- recordCmAiQaRun({...logInput,testRunId:recovery.testRunId,phase:'abandoned'});
300
- rerunUnknownQa=false;
318
+ recordCmAiQaRun({...logInput,testRunId:recovery.testRunId,mode:recovery.mode,
319
+ caseCount:recovery.caseCount,qaRound:recovery.qaRound,phase:rerunBlockedQa?'superseded':'abandoned',
320
+ ...(rerunBlockedQa?{expectedEnvironment:qaExecutor.configuration?.environment??null}:{})});
321
+ rerunUnknownQa=false;rerunBlockedQa=false;
301
322
  }
302
- recordCmAiQaRun({...logInput,phase:'start',...(recovery?{previousTestRunId:recovery.testRunId}:{})});
323
+ recordCmAiQaRun({...logInput,phase:'start',
324
+ deferredCases:qaExecutor.configuration?.plan?.deferred_cases??[],
325
+ ...(recovery?{previousTestRunId:recovery.testRunId}:{})});
303
326
  const controller=new AbortController();pendingExecution=controller;
304
327
  let timer,timedOut=false;
305
328
  try{
@@ -466,7 +489,8 @@ export function createCmAiConversationEntry(options) {
466
489
  pendingAction:fixHandoff.status==='authorization_required'?'fix_authorization':
467
490
  fixHandoff.status==='dispatch_required'?'fix_dispatch':'none'});
468
491
  }
469
- return summary(operation,{...status,code},'verified');
492
+ return freeze({...summary(operation,{...status,code},'verified'),
493
+ ...(code==='qa_result_blocked'&&rerunBlockedQa?{pendingAction:'qa'}:{})});
470
494
  }
471
495
  if(operation.operation==='context_refresh'){
472
496
  const status=boundStatus(runner.status(),identity);
@@ -538,8 +562,7 @@ export function createCmAiConversationEntry(options) {
538
562
  deduplicated:result.deduplicated,degraded:result.degraded});
539
563
  }
540
564
  need(['start','resume'].includes(operation.operation),'invalid_input');
541
- need(admission.state==='ready'&&admission.nextTask?.feature===options.feature
542
- &&admission.nextTask.id===identity.taskId,'task_mismatch');
565
+ need(matchesCmAiTaskSelection(admission,options.feature,identity.taskId,options.parallelSelection??null),'task_mismatch');
543
566
  const status=boundStatus(runner.status(),identity);
544
567
  const developable=['ready','changes_requested'].includes(status.state)||retryDeveloper(status);
545
568
  const repeatable=operation.operation==='start'&&status.state==='awaiting_review';
@@ -551,7 +574,7 @@ export function createCmAiConversationEntry(options) {
551
574
  return summary(operation,{...status,code:'provider_development_authorization_required'},'awaiting');
552
575
  const learningInput=inspectCmAiTaskLearningInput({specsDir:options.specsDir,codeProject:options.codeProject,
553
576
  feature:options.feature,identity,applicableAgentFiles:applicableAgentFiles??[]},
554
- {admission:runner.inspectBootstrapAdmission?.()??null});
577
+ {admission:runner.inspectBootstrapAdmission?.()??null,parallelSelection:options.parallelSelection??null});
555
578
  // Keep rejected effects immutable. A run-wide rejection count gives each
556
579
  // corrected result a new effect id without changing the provider attempt.
557
580
  const rejectedValues=status.calls.filter(call=>call.terminal==='failed'