@aibyzero/cm-workflow 0.21.7 → 0.25.1

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 (227) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +64 -0
  3. package/README.md +15 -1
  4. package/VERSION +1 -1
  5. package/docs/architecture.md +9 -0
  6. package/docs/cm-acceptance-completion.md +3 -1
  7. package/docs/cm-control-policy-v2.md +35 -3
  8. package/docs/execution-optimizations.md +1 -1
  9. package/docs/external-models.md +1 -0
  10. package/docs/human-correction.md +1 -1
  11. package/docs/installation.md +63 -19
  12. package/docs/js-workflow-control.md +67 -31
  13. package/docs/next-steps.md +10 -0
  14. package/docs/runtime-failover.md +2 -2
  15. package/docs/user-guide.md +1 -1
  16. package/package.json +1 -1
  17. package/runtime/js/cm-ai/batch-location.mjs +14 -0
  18. package/runtime/js/cm-ai/batch-plan.mjs +6 -2
  19. package/runtime/js/cm-ai/claude-probe-diagnosis.mjs +21 -0
  20. package/runtime/js/cm-ai/claude-review-stream.mjs +20 -7
  21. package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -2
  22. package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
  23. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
  24. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
  25. package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
  26. package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
  27. package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
  28. package/runtime/js/cm-ai/drive-core.mjs +50 -6
  29. package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
  30. package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
  31. package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
  32. package/runtime/js/cm-ai/execution-store.mjs +21 -3
  33. package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
  34. package/runtime/js/cm-ai/host-check.mjs +4 -2
  35. package/runtime/js/cm-ai/host-conversation-execution.mjs +29 -2
  36. package/runtime/js/cm-ai/host-handoff.mjs +7 -0
  37. package/runtime/js/cm-ai/host-progress.mjs +18 -0
  38. package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
  39. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
  40. package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
  41. package/runtime/js/cm-ai/host-session.mjs +1 -1
  42. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
  43. package/runtime/js/cm-ai/host.mjs +1 -1
  44. package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
  45. package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
  46. package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
  47. package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
  48. package/runtime/js/cm-ai/review-continuation.mjs +102 -0
  49. package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
  50. package/runtime/js/cm-ai/review-package.mjs +25 -4
  51. package/runtime/js/cm-ai/review-presentation.mjs +31 -14
  52. package/runtime/js/cm-ai/review-runner.mjs +5 -4
  53. package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
  54. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
  55. package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
  56. package/runtime/js/cm-ai/task-commit.mjs +7 -4
  57. package/runtime/js/cm-ai/task-owner.mjs +5 -2
  58. package/runtime/js/cm-ai/task-runner.mjs +343 -52
  59. package/runtime/js/cm-ai/worker-claude-developer.mjs +3 -1
  60. package/runtime/js/cm-ai/worker-claude.mjs +5 -1
  61. package/runtime/js/cm-check/host.mjs +13 -3
  62. package/runtime/js/cm-fix/diagnosis.mjs +16 -3
  63. package/runtime/js/cm-fix/execution.mjs +47 -9
  64. package/runtime/js/cm-fix/finish.mjs +9 -1
  65. package/runtime/js/cm-fix/step-timing.mjs +222 -0
  66. package/runtime/js/cm-idea/session.mjs +22 -3
  67. package/runtime/js/cm-init/review-evidence.mjs +20 -7
  68. package/runtime/js/cm-prd/ai-draft.mjs +260 -0
  69. package/runtime/js/cm-prd/analysis.mjs +27 -9
  70. package/runtime/js/cm-prd/change.mjs +29 -8
  71. package/runtime/js/cm-prd/failed-correction.mjs +24 -4
  72. package/runtime/js/cm-prd/narrow-review.mjs +63 -3
  73. package/runtime/js/cm-prd/review-channels.mjs +5 -0
  74. package/runtime/js/cm-prd/review-correction.mjs +65 -5
  75. package/runtime/js/cm-prd/review-disposition.mjs +10 -1
  76. package/runtime/js/cm-prd/review-publication.mjs +2 -1
  77. package/runtime/js/cm-prd/self-check.mjs +121 -9
  78. package/runtime/js/cm-prd/session.mjs +55 -13
  79. package/runtime/js/cm-prd/summary.mjs +34 -6
  80. package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
  81. package/runtime/js/cm-refactor/records.mjs +82 -11
  82. package/runtime/js/cm-refactor/workflow.mjs +3 -1
  83. package/runtime/js/executor-version.mjs +81 -0
  84. package/runtime/js/python-log-writer.mjs +15 -0
  85. package/runtime/js/run-analysis.mjs +136 -11
  86. package/runtime/logging.md +6 -0
  87. package/runtime/review.md +2 -1
  88. package/scripts/ci-test-weights.json +1 -0
  89. package/scripts/cm-ai-admission.mjs +27 -1
  90. package/scripts/cm-ai-admission.test.mjs +34 -2
  91. package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
  92. package/scripts/cm-ai-batch-drive.mjs +54 -17
  93. package/scripts/cm-ai-batch-drive.test.mjs +123 -6
  94. package/scripts/cm-ai-batch-host.mjs +64 -11
  95. package/scripts/cm-ai-batch-host.test.mjs +23 -3
  96. package/scripts/cm-ai-batch-location.test.mjs +22 -1
  97. package/scripts/cm-ai-batch-merge.mjs +102 -0
  98. package/scripts/cm-ai-batch-plan.mjs +55 -2
  99. package/scripts/cm-ai-batch-plan.test.mjs +228 -6
  100. package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
  101. package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
  102. package/scripts/cm-ai-batch-run.mjs +437 -34
  103. package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
  104. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
  105. package/scripts/cm-ai-completion-summary.test.mjs +2 -1
  106. package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
  107. package/scripts/cm-ai-direct-review.test.mjs +1 -1
  108. package/scripts/cm-ai-disk-edits.test.mjs +229 -0
  109. package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
  110. package/scripts/cm-ai-drive.mjs +66 -14
  111. package/scripts/cm-ai-drive.test.mjs +13 -3
  112. package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
  113. package/scripts/cm-ai-host.mjs +20 -9
  114. package/scripts/cm-ai-host.test.mjs +12 -0
  115. package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
  116. package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
  117. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
  118. package/scripts/cm-ai-review-continuation.test.mjs +335 -0
  119. package/scripts/cm-ai-review-failure.test.mjs +13 -10
  120. package/scripts/cm-ai-review-timeout.test.mjs +1 -1
  121. package/scripts/cm-ai-run.mjs +42 -11
  122. package/scripts/cm-ai-run.test.mjs +26 -0
  123. package/scripts/cm-ai-supersede.test.mjs +10 -2
  124. package/scripts/cm-capability-gate.test.mjs +1 -1
  125. package/scripts/cm-check-host.test.mjs +54 -0
  126. package/scripts/cm-check-runtime.sh +27 -15
  127. package/scripts/cm-check-update.mjs +83 -8
  128. package/scripts/cm-check-update.test.mjs +114 -1
  129. package/scripts/cm-claude-developer-worker.test.mjs +29 -1
  130. package/scripts/cm-claude-managed-preflight.test.mjs +126 -0
  131. package/scripts/cm-claude-probe.test.mjs +5 -0
  132. package/scripts/cm-claude-review-stream.test.mjs +4 -1
  133. package/scripts/cm-claude-worker.test.mjs +29 -0
  134. package/scripts/cm-codex-prompt-input.test.mjs +2 -1
  135. package/scripts/cm-developer-self-review.test.mjs +27 -0
  136. package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
  137. package/scripts/cm-efficiency-response.test.mjs +2 -1
  138. package/scripts/cm-executor-version-draft.test.mjs +251 -0
  139. package/scripts/cm-executor-version-entries.test.mjs +93 -0
  140. package/scripts/cm-executor-version-prd.test.mjs +154 -0
  141. package/scripts/cm-executor-version-records.test.mjs +256 -0
  142. package/scripts/cm-executor-version.test.mjs +250 -0
  143. package/scripts/cm-external-model-host.test.mjs +6 -1
  144. package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
  145. package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
  146. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
  147. package/scripts/cm-fix-drive.mjs +7 -2
  148. package/scripts/cm-fix-drive.test.mjs +45 -0
  149. package/scripts/cm-fix-entry.mjs +5 -2
  150. package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
  151. package/scripts/cm-fix-host.mjs +9 -2
  152. package/scripts/cm-fix-review-preflight.mjs +2 -0
  153. package/scripts/cm-fix-review-verification-integration.test.mjs +19 -0
  154. package/scripts/cm-fix-test-extension.test.mjs +30 -2
  155. package/scripts/cm-host-check.test.mjs +12 -0
  156. package/scripts/cm-host-qa-executor.test.mjs +172 -1
  157. package/scripts/cm-host-qa-policy.test.mjs +55 -1
  158. package/scripts/cm-idea-drive.mjs +5 -2
  159. package/scripts/cm-idea-entry.mjs +5 -2
  160. package/scripts/cm-idea-host.mjs +3 -1
  161. package/scripts/cm-init-drive.mjs +8 -5
  162. package/scripts/cm-init-entry.mjs +5 -2
  163. package/scripts/cm-init-host.mjs +6 -2
  164. package/scripts/cm-log-event.mjs +10 -2
  165. package/scripts/cm-log-event.test.mjs +29 -0
  166. package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
  167. package/scripts/cm-prd-ai-draft.test.mjs +505 -0
  168. package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
  169. package/scripts/cm-prd-completion.test.mjs +67 -4
  170. package/scripts/cm-prd-design-phase.test.mjs +48 -13
  171. package/scripts/cm-prd-drive.mjs +91 -21
  172. package/scripts/cm-prd-drive.test.mjs +126 -4
  173. package/scripts/cm-prd-entry.mjs +5 -2
  174. package/scripts/cm-prd-host.mjs +89 -20
  175. package/scripts/cm-prd-host.test.mjs +17 -8
  176. package/scripts/cm-prd-narrow-review.test.mjs +49 -1
  177. package/scripts/cm-prd-review-disposition.test.mjs +94 -1
  178. package/scripts/cm-prd-review-gate.mjs +13 -5
  179. package/scripts/cm-prd-review-publication.test.mjs +34 -0
  180. package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
  181. package/scripts/cm-prd-self-check.test.mjs +1 -1
  182. package/scripts/cm-refactor-drive.mjs +10 -4
  183. package/scripts/cm-refactor-entry.mjs +5 -2
  184. package/scripts/cm-refactor-host.mjs +3 -1
  185. package/scripts/cm-release-smoke.sh +3 -2
  186. package/scripts/cm-run-analysis.test.mjs +373 -1
  187. package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
  188. package/scripts/cm-skill-hints-exam.mjs +3 -1
  189. package/scripts/cm-skill-hints-install.test.mjs +1 -1
  190. package/scripts/cm-skill-hints.mjs +106 -10
  191. package/scripts/cm-skill-hints.test.mjs +162 -6
  192. package/scripts/cm-skill-judge.mjs +2 -1
  193. package/scripts/cm-task-gate.mjs +88 -18
  194. package/scripts/cm-task-scope.test.mjs +1 -1
  195. package/scripts/cm-test-drive.mjs +13 -8
  196. package/scripts/cm-test-entry.mjs +5 -2
  197. package/scripts/cm-test-host.mjs +3 -1
  198. package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
  199. package/scripts/cm-workflow-config.test.mjs +8 -3
  200. package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
  201. package/scripts/fixtures/prd-review-gate-python-oracle.py +10 -1
  202. package/scripts/policy-binding-compat.test.mjs +3 -2
  203. package/scripts/scan-public-safety.py +1 -0
  204. package/scripts/shell-pipe-early-exit.test.mjs +96 -0
  205. package/scripts/test-cm-prd-review-gate.py +55 -0
  206. package/scripts/test-shell-compat.sh +7 -5
  207. package/skills/cm-ai/SKILL.md +1 -1
  208. package/skills/cm-ai/references/N1-init.md +1 -1
  209. package/skills/cm-ai/references/N4-review.md +2 -2
  210. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  211. package/skills/cm-ai/references/js-host-recovery.md +5 -1
  212. package/skills/cm-ai/references/js-host.md +17 -8
  213. package/skills/cm-check/SKILL.md +3 -0
  214. package/skills/cm-fix/references/isolated-review.md +1 -1
  215. package/skills/cm-fix/references/js-host.md +20 -0
  216. package/skills/cm-fix/references/test-extension.md +1 -1
  217. package/skills/cm-prd/SKILL.md +8 -6
  218. package/skills/cm-prd/references/ai-draft.md +81 -0
  219. package/skills/cm-prd/references/change-mode.md +2 -0
  220. package/skills/cm-prd/references/greenfield.md +2 -0
  221. package/skills/cm-prd/references/js-change-recovery.md +2 -2
  222. package/skills/cm-prd/references/js-host.md +9 -6
  223. package/skills/cm-prd/references/light-mode.md +19 -0
  224. package/skills/cm-prd/references/requirement-grilling.md +2 -0
  225. package/skills/cm-prd/references/spec-self-check.md +1 -0
  226. package/skills/cm-prd/references/summary-card.md +1 -0
  227. package/templates/auto-update/cm-update.sh +2 -2
@@ -3,10 +3,13 @@ import assert from 'node:assert/strict';
3
3
  import fs from 'node:fs';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
+ import {fileURLToPath} from 'node:url';
6
7
  import {preparePrdReview} from '../runtime/js/cm-prd/review-preparation.mjs';
7
8
  import {publishPrdReview} from '../runtime/js/cm-prd/review-publication.mjs';
8
9
  import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
9
10
  import {claimPrdReview,inspectPrdReview} from './cm-prd-review-gate.mjs';
11
+ import {REVIEWER_SOURCES} from '../runtime/js/review-findings.mjs';
12
+ import {PRD_REVIEWER_SOURCES,PRD_INDEPENDENT_REVIEWERS} from '../runtime/js/cm-prd/review-channels.mjs';
10
13
  function fixture(t){
11
14
  const specs=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-r1-')));
12
15
  t.after(()=>fs.rmSync(specs,{recursive:true,force:true}));fs.mkdirSync(path.join(specs,'.reviews'));
@@ -64,6 +67,37 @@ test('invalid identities and canonical IDs from other channels cannot publish',t
64
67
  response.independent=true;response.reviewer='codex-cli';assert.throws(publish,/invalid_input/);
65
68
  assert.equal(inspectPrdReview(prepared.paths).outcome,'dispatch_unknown');
66
69
  });
70
+ // External report 2026-12 item 3: the claude-only preset declares reviewer claude-cli, and cm-prd
71
+ // refused it while task review accepted it. Every independent channel in the shared list publishes.
72
+ for(const reviewer of PRD_INDEPENDENT_REVIEWERS)
73
+ test(`independent ${reviewer} declaration publishes r1 under the same checks`,t=>{
74
+ const {prepared,response,claim,publish}=fixture(t);claim();response.reviewer=reviewer;
75
+ const result=publish();assert.equal(result.independent,true);assert.equal(result.completionAuthorized,false);
76
+ assert.match(fs.readFileSync(prepared.paths.evidence,'utf8'),new RegExp(`reviewer: ${reviewer}\\n`));
77
+ });
78
+ // Guard: cm-prd validators read one cm-prd list instead of their own copies. That list must equal the
79
+ // task review channels and the Python oracle, so adding or removing a channel anywhere fails here
80
+ // until a maintainer decides whether cm-prd accepts it (review r1: no silent widening).
81
+ test('cm-prd reviewer channels are one list, matched to task review and the Python oracle',()=>{
82
+ const repo=fileURLToPath(new URL('..',import.meta.url));
83
+ assert.deepEqual([...PRD_REVIEWER_SOURCES],[...REVIEWER_SOURCES],
84
+ 'reviewer channels changed: decide whether cm-prd accepts it, then update runtime/js/cm-prd/review-channels.mjs and the Python oracle');
85
+ const oracle=fs.readFileSync(path.join(repo,'scripts/fixtures/prd-review-gate-python-oracle.py'),'utf8');
86
+ const literal=/if reviewer not in \{([^}]*)\}:/.exec(oracle);assert.ok(literal,'oracle reviewer check not found');
87
+ assert.deepEqual(literal[1].split(',').map(item=>item.trim().replace(/^"|"$/g,'')).sort(),[...PRD_REVIEWER_SOURCES].sort());
88
+ for(const file of ['runtime/js/cm-prd/review-publication.mjs','scripts/cm-prd-drive.mjs','scripts/cm-prd-review-gate.mjs']){
89
+ const source=fs.readFileSync(path.join(repo,file),'utf8');
90
+ assert.doesNotMatch(source,/\[\s*(['"`])(?:codex-subagent|codex-cli|claude-cli|self-degraded)\1\s*,/,`${file}: use runtime/js/cm-prd/review-channels.mjs`);
91
+ assert.match(source,/PRD_(?:INDEPENDENT_)?REVIEWER/,file);
92
+ }
93
+ });
94
+ test('claude-cli keeps the independence rules and unknown channels stay refused',t=>{
95
+ const {prepared,response,claim,publish}=fixture(t);claim();response.reviewer='claude-cli';
96
+ response.contextId='author-context';assert.throws(publish,/prd_review_independence_invalid/);
97
+ response.contextId='reviewer-context';response.independent=false;assert.throws(publish,/prd_review_independence_invalid/);
98
+ response.independent=true;response.reviewer='claude-api';assert.throws(publish,/prd_review_independence_invalid/);
99
+ assert.equal(fs.existsSync(prepared.paths.evidence),false);
100
+ });
67
101
  test('changes and explicit self-degradation stay findings, not completion or independent approval',t=>{
68
102
  const {prepared,response,claim,publish}=fixture(t);claim();
69
103
  response.reviewer='self-degraded';response.contextId='author-context';response.independent=false;
@@ -8,8 +8,9 @@ import path from 'node:path';
8
8
  import {fileURLToPath} from 'node:url';
9
9
  import {createCmPrdAnalysis} from '../runtime/js/cm-prd/analysis.mjs';
10
10
  import {openPrdSession,prdSessionVersions} from '../runtime/js/cm-prd/session.mjs';
11
- import {PRD_SELF_CHECK_RULES,PRD_SELF_CHECK_RULE_VERSIONS,checkPrdDraftMechanics,matchesPrdDraftMechanics} from '../runtime/js/cm-prd/self-check.mjs';
12
- import {recordPrdTaskScopes,prdTaskScopeOptions} from '../runtime/js/cm-prd/task-scope-record.mjs';
11
+ import {PRD_SELF_CHECK_RULES,PRD_SELF_CHECK_RULE_VERSIONS,checkPrdDraftMechanics,matchesPrdDraftMechanics,sessionTaskDigest} from '../runtime/js/cm-prd/self-check.mjs';
12
+ import {createHash} from 'node:crypto';
13
+ import {recordPrdTaskScopes,prdTaskScopeOptions,approvedScopeExemptions} from '../runtime/js/cm-prd/task-scope-record.mjs';
13
14
  import {TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
14
15
  const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
15
16
  const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-rules-home-'));
@@ -108,7 +109,7 @@ test('a session binding outside the known versions is refused',t=>{
108
109
  const {dir,entry}=specs(t),sessionId='prd-invalid-fixture',open=()=>openPrdSession({specs:dir,sessionId,identity:{entry,runtime:'codex'}});
109
110
  created(open);
110
111
  for(const change of [state=>{delete state.taskGrammar;},state=>{state.taskGrammar=1;},state=>{state.taskGrammar=TASK_GRAMMAR+1;},
111
- state=>{state.selfCheckRules=7;},state=>{state.selfCheckRules='3';},state=>{state.selfCheckRules=6;}]){
112
+ state=>{state.selfCheckRules=9;},state=>{state.selfCheckRules='3';},state=>{state.selfCheckRules=6;}]){
112
113
  const file=stateFile(dir,sessionId),bytes=fs.readFileSync(file);edit(file,change);
113
114
  assert.throws(open,/prd_session_versions_invalid/);fs.writeFileSync(file,bytes,{mode:0o600});
114
115
  }
@@ -118,7 +119,7 @@ test('the historical rule set lists rule 3 explicitly, so raising the current ru
118
119
  for(const rules of [3,2,1,PRD_SELF_CHECK_RULES])assert.ok(PRD_SELF_CHECK_RULE_VERSIONS.includes(rules));
119
120
  assert.equal(new Set(PRD_SELF_CHECK_RULE_VERSIONS).size,PRD_SELF_CHECK_RULE_VERSIONS.length);
120
121
  const source=fs.readFileSync(path.join(root,'runtime/js/cm-prd/self-check.mjs'),'utf8');
121
- assert.match(source,/new Set\(\[PRD_SELF_CHECK_RULES,PRD_SELF_CHECK_LEGACY_GRAMMAR_RULES,4,3,2,1\]\)/);
122
+ assert.match(source,/new Set\(\[PRD_SELF_CHECK_RULES,PRD_SELF_CHECK_LEGACY_GRAMMAR_RULES,7,5,4,3,2,1\]\)/);
122
123
  assert.doesNotMatch(source,/\[PRD_SELF_CHECK_RULES,2,1\]|\[1,2,PRD_SELF_CHECK_RULES\]/);
123
124
  });
124
125
 
@@ -203,7 +204,7 @@ test('a sessionTasks-only re-check reports a bad, repeated or stray developer li
203
204
  // outside the saving operation; the task-scope record carries a rule-4 save's rule.
204
205
  test('a save records the session rule (4 or later) for the re-checks; an earlier rule or an operation without a rule keeps the old record',t=>{
205
206
  const {dir,entry}=specs(t),sessionId='prd-record-fixture',open=()=>openPrdSession({specs:dir,sessionId,identity:{entry,runtime:'codex'}});
206
- const tasks=['- [ ] T-001: Build',' - 范围: `src/a.js`','- [ ] T-002: Walk',' - 范围: `docs/qa.md`',' - 开发: 会话',''].join('\n');
207
+ const tasks=['- [ ] T-001: Build',' - 范围: `src/a.js`','- [ ] T-002: Walk',' - 范围: `docs/qa.md`',' - 开发: 会话',' - 必跑检查: `sh scripts/check-walk.sh`',''].join('\n');
207
208
  const feature=content=>({directory:'1.walk',name:'walk',documents:[
208
209
  {path:'requirements.md',content:'## 功能需求\n1. [F-001] Walk\n- [ ] [AC-001] Walk it.'},
209
210
  {path:'design.md',content:'## 方案摘要\nx'},{path:'tasks.md',content}]});
@@ -217,13 +218,19 @@ test('a save records the session rule (4 or later) for the re-checks; an earlier
217
218
  try{session.begin({requestId:'r1',operation:'save_draft'},null,{selfCheckRules:session.versions().selfCheckRules});}finally{session.close();}
218
219
  save();
219
220
  assert.deepEqual(JSON.parse(fs.readFileSync(record,'utf8')),{version:1,enforced:true,exempt:[],selfCheckRules:PRD_SELF_CHECK_RULES});
220
- assert.deepEqual(prdTaskScopeOptions(dir,'1.walk'),{scopes:{'1.walk':{exempt:[]}},sessionTasks:['1.walk'],inapplicableAcceptance:['1.walk']});
221
+ assert.deepEqual(prdTaskScopeOptions(dir,'1.walk'),{scopes:{'1.walk':{exempt:[]}},sessionTasks:['1.walk'],inapplicableAcceptance:['1.walk'],sessionEvidence:['1.walk']});
221
222
  assert.deepEqual(recheck(tasks),[]);
222
- assert.deepEqual(recheck(moved),['session_task_not_final']);
223
- assert.deepEqual(recheck(second),['session_task_multiple']);
224
- // The bound options add nothing to a rule-4 report, so recorded reports still match.
223
+ // Rule 8's evidence check rides along: the newly marked T-001 declares no 必跑检查.
224
+ assert.deepEqual(recheck(moved),['session_task_not_final','session_task_evidence_missing']);
225
+ assert.deepEqual(recheck(second),['session_task_multiple','session_task_evidence_missing']);
226
+ // A report recorded under the session's rule matches its own record's options.
225
227
  const draft={draftDigest:'d'.repeat(64),features:[feature(moved)]};
228
+ assert.ok(matchesPrdDraftMechanics(draft,checkPrdDraftMechanics(draft,{rules:PRD_SELF_CHECK_RULES}),prdTaskScopeOptions(dir,'1.walk')));
229
+ // A rule-5 record's options add nothing to a rule-4 report, so reports recorded before rule 8 still match.
230
+ const saved=fs.readFileSync(record);
231
+ fs.writeFileSync(record,JSON.stringify({version:1,enforced:true,exempt:[],selfCheckRules:5})+'\n',{mode:0o600});
226
232
  assert.ok(matchesPrdDraftMechanics(draft,checkPrdDraftMechanics(draft,{rules:4}),prdTaskScopeOptions(dir,'1.walk')));
233
+ fs.writeFileSync(record,saved,{mode:0o600});
227
234
  // The state an older host left: the active operation without a rule saves as rule 1, the old record.
228
235
  edit(stateFile(dir,sessionId),state=>{delete state.active.selfCheckRules;});
229
236
  save();
@@ -233,7 +240,7 @@ test('a save records the session rule (4 or later) for the re-checks; an earlier
233
240
  // Rule 3 adds nothing beyond the scope record, so its save keeps the old bytes too.
234
241
  recordPrdTaskScopes(dir,[feature(tasks)],{},{selfCheckRules:3});
235
242
  assert.equal(fs.readFileSync(record,'utf8'),JSON.stringify({version:1,enforced:true,exempt:[]})+'\n');
236
- for(const value of [3,7,'4']){
243
+ for(const value of [3,9,'4']){
237
244
  fs.writeFileSync(record,JSON.stringify({version:1,enforced:true,exempt:[],selfCheckRules:value})+'\n',{mode:0o600});
238
245
  assert.throws(()=>prdTaskScopeOptions(dir,'1.walk'),/prd_task_scope_record_invalid/);
239
246
  }
@@ -249,3 +256,161 @@ test('rule 6 keeps 开发 lines as prose and otherwise reports exactly what rule
249
256
  assert.ok(!codes(6).includes('session_task_not_final'));
250
257
  assert.ok(codes(5).includes('session_task_not_final'));
251
258
  });
259
+
260
+ // 防回归(aihot specs12 T-002,2026-12-01):会话走查任务唯一的检查是 `test -f 走查文件`,审查方只能凭文字判断。
261
+ // 规则 8 要求新写的会话任务在任务自己下面用「必跑检查:」声明一条执行脚本文件的检查;规则 1–7 与原样未改的已批准会话任务不受影响。
262
+ const WALK_REQUIREMENTS='## 功能需求\n1. [F-001] Walk\n- [ ] [AC-001] Walk it.';
263
+ const walkDraft=(lines,requirements=WALK_REQUIREMENTS,walk='- [ ] T-002: Walk')=>({draftDigest:'f'.repeat(64),features:[{directory:'1.walk',name:'walk',documents:[
264
+ {path:'requirements.md',content:requirements},{path:'design.md',content:'## 方案摘要\nx'},
265
+ {path:'tasks.md',content:['- [ ] T-001: Build',' - 范围: `src/a.js`, `scripts/check-walk.sh`',walk,' - 范围: `docs/qa.md`',
266
+ ' - 开发: 会话',...lines,'','## 依赖关系','- T-002 依赖 T-001',''].join('\n')}]}]});
267
+ const evidence=(lines,options={rules:PRD_SELF_CHECK_RULES},requirements)=>checkPrdDraftMechanics(walkDraft(lines,requirements),options).findings
268
+ .filter(item=>item.code==='session_task_evidence_missing');
269
+ test('rule 8: a session task without an own script-file 必跑检查 fails and the hint says how to write one',()=>{
270
+ assert.equal(PRD_SELF_CHECK_RULES,8);
271
+ for(const lines of [[],[' - 验证要求: 走查文件存在'],[' - 必跑检查: `test -f docs/qa.md`'],[' - 必跑检查: `ls docs/qa.md`'],
272
+ [' - 必跑检查: `sh -c test -f docs/qa.md`'],[' - 验证要求: 运行 `sh scripts/check-walk.sh`']]){
273
+ const found=evidence(lines);
274
+ assert.equal(found.length,1,lines.join(' / ')||'(no check)');
275
+ assert.deepEqual(found[0].reason.tasks,['T-002']);
276
+ assert.equal(found[0].reason.field,'1.walk/tasks.md');
277
+ assert.match(found[0].reason.expected,/必跑检查: `sh scripts\/check-\{功能\}-walkthrough\.sh`/);
278
+ assert.match(found[0].reason.expected,/AC 编号/);
279
+ assert.match(found[0].reason.expected,/`test -f`/);
280
+ }
281
+ for(const line of [' - 必跑检查: `sh scripts/check-walk.sh`',' - 必跑检查: `node scripts/check-walk.mjs docs/qa.md`',
282
+ ' - 必跑检查: `bash scripts/check-walk.sh docs/qa.md`',' - 必跑检查: `python3 scripts/check_walk.py`',' - 必跑检查: `./scripts/check-walk.sh`'])
283
+ assert.equal(checkPrdDraftMechanics(walkDraft([line]),{rules:PRD_SELF_CHECK_RULES}).status,'mechanical_subset_passed',line);
284
+ });
285
+ // 防回归(审查 r1 B3):只列目录、只查语法、内联脚本或 -c/-ec 包装的命令承担不了走查核对。
286
+ test('rule 8 only counts running a script file: inline code, grep, ls, test -f and syntax checks fail',()=>{
287
+ for(const command of ['node -e process.exit(0)','grep AC-001 docs/qa.md','sh -ec ls','bash -c ls docs','node --check scripts/check-walk.js',
288
+ 'node -c scripts/check-walk.js','sh -n scripts/check-walk.sh','node scripts/check-walk.sh','python3 -m pytest','python3 -c print(1)',
289
+ 'node --test scripts/check-walk.test.mjs','sh /tmp/check.sh','sh ../check.sh','test -f docs/qa.md'])
290
+ assert.equal(evidence([` - 必跑检查: \`${command}\``]).length,1,command);
291
+ });
292
+ // 防回归(审查 r1 B2):必须用「必跑检查:」声明;只写「运行:」等标签时 cm-ai 不启用必验,也不是任务自己的必跑检查。
293
+ test('rule 8 requires the 必跑检查 label; 运行, 执行 and 必跑命令 lines do not count even when a 必验 marker enables the contract',()=>{
294
+ for(const lines of [[' - 运行: `sh scripts/check-walk.sh`'],[' - 执行: `sh scripts/check-walk.sh`'],[' - 必跑命令: `sh scripts/check-walk.sh`'],
295
+ [' - 必验: 走查核对',' - 运行: `sh scripts/check-walk.sh`']])assert.equal(evidence(lines).length,1,lines.join(' / '));
296
+ // A fenced example is not a declaration.
297
+ assert.equal(evidence([' ```text',' - 必跑检查: `sh scripts/check-walk.sh`',' ```']).length,1);
298
+ });
299
+ // 防回归(审查 r3 B2):关联 AC 下的脚本能被 cm-ai 收进合同,但不能代替会话任务自己的必跑检查。
300
+ test('rule 8: a script declared only under the linked AC does not stand in for the task own check',()=>{
301
+ const linked='## 功能需求\n1. [F-001] Walk\n- [ ] [AC-001] Walk it.\n - 必验: 走查核对\n - 必跑检查: `sh scripts/check-walk.sh`';
302
+ const walk='- [ ] T-002: Walk(AC-001)';
303
+ const draft=lines=>walkDraft(lines,linked,walk);
304
+ const missing=lines=>checkPrdDraftMechanics(draft(lines),{rules:PRD_SELF_CHECK_RULES}).findings
305
+ .filter(item=>item.code==='session_task_evidence_missing').length;
306
+ assert.equal(missing([]),1,'the AC script alone does not count');
307
+ assert.equal(missing([' - 运行: `sh scripts/check-walk.sh`']),1,'a 运行 line enabled by the AC 必验 still does not count');
308
+ assert.equal(missing([' - 必跑检查: `sh scripts/check-walk.sh`']),0,'the task own 必跑检查 passes, read together with the requirements as cm-ai reads them');
309
+ });
310
+ // 防回归(审查 r2 B2):需求文本一起交给 cm-ai 同一合同函数;合同建不出(用例表坏了)时任务自己的声明也不算数。
311
+ test('rule 8 builds the contract from the same texts cm-ai uses; an unbuildable contract counts as missing',()=>{
312
+ const base=walkDraft([' - 必跑检查: `sh scripts/check-walk.sh`']);
313
+ const withCases=cases=>({...base,features:[{...base.features[0],documents:[...base.features[0].documents,{path:'test-cases.json',content:cases}]}]});
314
+ const codes=draft=>checkPrdDraftMechanics(draft,{rules:PRD_SELF_CHECK_RULES}).findings.map(item=>item.code);
315
+ assert.ok(!codes(withCases(JSON.stringify({schemaVersion:'1.0',feature:'walk',cases:[{id:'TC-001',origin:'user',kind:'logic',blocking:true,
316
+ acIds:['AC-001'],taskIds:['T-002'],title:'Walk',preconditions:[],steps:['Walk'],expected:['Seen'],cleanup:[]}]}))).includes('session_task_evidence_missing'));
317
+ assert.ok(codes(withCases('{"cases":[{"taskIds":"T-002"}]}')).includes('session_task_evidence_missing'));
318
+ });
319
+ test('rule 8 evidence check spares rules 1-6 and only unchanged approved session tasks',()=>{
320
+ for(const rules of [1,2,3,4,5,6])assert.deepEqual(evidence([],{rules}),[],`rule ${rules}`);
321
+ const text=walkDraft([]).features[0].documents[2].content,held={'T-002':sessionTaskDigest(text,'T-002')};
322
+ assert.deepEqual(evidence([],{rules:PRD_SELF_CHECK_RULES,change:true,scopes:{'1.walk':{exempt:['T-001','T-002'],evidence:held}}}),[]);
323
+ // A re-check outside the session (record saved under rule 8) keeps the check and the same exemption.
324
+ assert.equal(evidence([],{rules:1,sessionTasks:['1.walk'],sessionEvidence:['1.walk']}).length,1);
325
+ assert.deepEqual(evidence([],{rules:1,sessionTasks:['1.walk'],sessionEvidence:['1.walk'],sessionEvidenceExempt:{'1.walk':held}}),[]);
326
+ // An approved task id alone (the scope exemption) never exempts the evidence check.
327
+ assert.equal(evidence([],{rules:PRD_SELF_CHECK_RULES,change:true,scopes:{'1.walk':{exempt:['T-001','T-002']}}}).length,1);
328
+ });
329
+ // 防回归(审查 r1 B4):变更里把已批准的开发任务改标会话、保留编号,旧编号不能豁免;已批准的会话任务内容改了也要补检查。
330
+ test('a change exempts only approved session tasks left unchanged, never a task newly marked as session',()=>{
331
+ const sha=text=>createHash('sha256').update(text).digest('hex');
332
+ const approved=['- [ ] T-001: Build',' - 范围: `src/a.js`','- [ ] T-002: Walk',' - 范围: `docs/qa.md`',' - 开发: 会话',''].join('\n');
333
+ const exemptions=text=>approvedScopeExemptions({files:{'1.walk/tasks.md':text},
334
+ status:JSON.stringify({status:'approved',specFiles:[{path:'1.walk/tasks.md',sha256:sha(text)}]})},['1.walk'],TASK_GRAMMAR);
335
+ const check=(before,after)=>checkPrdDraftMechanics({draftDigest:'f'.repeat(64),features:[{directory:'1.walk',name:'walk',documents:[
336
+ {path:'requirements.md',content:WALK_REQUIREMENTS},{path:'design.md',content:'## 方案摘要\nx'},
337
+ {path:'tasks.md',content:after}]}]},{rules:PRD_SELF_CHECK_RULES,change:true,previous:{'1.walk':before},scopes:exemptions(before)})
338
+ .findings.filter(item=>item.code==='session_task_evidence_missing').flatMap(item=>item.reason.tasks);
339
+ assert.deepEqual(check(approved,approved),[],'unchanged approved session task stays exempt');
340
+ assert.deepEqual(check(approved,approved.replace('- [ ] T-002: Walk','- [ ] T-002: Walk again [CHANGED v2]')),['T-002']);
341
+ const devOnly=['- [ ] T-001: Build',' - 范围: `src/a.js`','- [ ] T-002: Wire',' - 范围: `src/b.js`',''].join('\n');
342
+ const marked=devOnly.replace('- [ ] T-002: Wire','- [ ] T-002: Walk [CHANGED v2]').replace('`src/b.js`','`docs/qa.md`\n - 开发: 会话');
343
+ assert.deepEqual(check(devOnly,marked),['T-002'],'an approved task id never exempts a newly marked session task');
344
+ // Grammar 2 approvals have no session tasks, so they hold no evidence exemption either.
345
+ assert.equal(exemptions(devOnly)['1.walk'].evidence,undefined);
346
+ });
347
+ // 防回归(审查 r1 B4):变更保存后的复查(修正、处置、汇总)沿用同一豁免,哈希取自已校验的记录。
348
+ test('a rule-8 change save records the unchanged approved session tasks for later re-checks',t=>{
349
+ const {dir}=specs(t),sha=text=>createHash('sha256').update(text).digest('hex');
350
+ const approved=['- [ ] T-001: Build',' - 范围: `src/a.js`','- [ ] T-002: Walk',' - 范围: `docs/qa.md`',' - 开发: 会话',''].join('\n');
351
+ const exemptions=approvedScopeExemptions({files:{'1.walk/tasks.md':approved},
352
+ status:JSON.stringify({status:'approved',specFiles:[{path:'1.walk/tasks.md',sha256:sha(approved)}]})},['1.walk'],TASK_GRAMMAR);
353
+ const feature=content=>({directory:'1.walk',name:'walk',documents:[{path:'requirements.md',content:WALK_REQUIREMENTS},
354
+ {path:'design.md',content:'## 方案摘要\nx'},{path:'tasks.md',content}]});
355
+ recordPrdTaskScopes(dir,[feature(approved)],exemptions,{selfCheckRules:PRD_SELF_CHECK_RULES});
356
+ const options=prdTaskScopeOptions(dir,'1.walk');
357
+ assert.deepEqual(options.sessionEvidenceExempt,{'1.walk':{'T-002':sessionTaskDigest(approved,'T-002')}});
358
+ const recheck=content=>checkPrdDraftMechanics({draftDigest:'d'.repeat(64),features:[feature(content)]},options)
359
+ .findings.filter(item=>item.code==='session_task_evidence_missing').length;
360
+ assert.equal(recheck(approved),0);
361
+ assert.equal(recheck(approved.replace('T-002: Walk','T-002: Walk faster')),1);
362
+ // Earlier rules never write the field, and a record carrying it under another rule is refused.
363
+ for(const rules of [5,7]){
364
+ recordPrdTaskScopes(dir,[feature(approved)],exemptions,{selfCheckRules:rules});
365
+ assert.equal(prdTaskScopeOptions(dir,'1.walk').sessionEvidenceExempt,undefined);
366
+ fs.writeFileSync(path.join(dir,'.reviews/prd-walk-task-scope.json'),JSON.stringify({version:1,enforced:true,exempt:[],selfCheckRules:rules,
367
+ sessionEvidenceExempt:{'T-002':'a'.repeat(64)}})+'\n',{mode:0o600});
368
+ assert.throws(()=>prdTaskScopeOptions(dir,'1.walk'),/prd_task_scope_record_invalid/);
369
+ }
370
+ });
371
+ // 防回归(审查 r2 阻断 2、r3 阻断 2):规则 7 是未发布首版(40806f2)。它落盘的会话、范围记录和报告仍按首版的判定与文案复算,
372
+ // 包括「脚本只写在关联 AC 下」时首版报缺、而规则 8 也报缺的情况,以及首版放行而规则 8 拒绝的内联命令。
373
+ const FIRST_HINT='在会话任务下写一行 - 必跑检查: `sh scripts/check-{功能}-walkthrough.sh`(脚本列入本任务或更早任务的范围)。'
374
+ +'脚本核对走查文件里本任务的每个 AC 编号都有观察记录,且记录引用的截图或日志路径真实存在,缺一项就非零退出;'
375
+ +'`test -f`、`ls` 这类只看走查文件在不在的命令不算';
376
+ test('rule 7 keeps the first version: its wording, its verdicts and its recorded reports',t=>{
377
+ const linked='## 功能需求\n1. [F-001] Walk\n- [ ] [AC-001] Walk it.\n - 必验: 走查核对\n - 必跑检查: `sh scripts/check-walk.sh`';
378
+ const acOnly=walkDraft([],linked,'- [ ] T-002: Walk(AC-001)');
379
+ const report=checkPrdDraftMechanics(acOnly,{rules:7});
380
+ const found=report.findings.filter(item=>item.code==='session_task_evidence_missing');
381
+ assert.equal(found.length,1);assert.equal(found[0].reason.expected,FIRST_HINT);
382
+ assert.ok(matchesPrdDraftMechanics(acOnly,report));
383
+ const reword=text=>({...report,findings:report.findings.map(item=>item.code==='session_task_evidence_missing'
384
+ ?{...item,reason:{...item.reason,expected:text}}:item)});
385
+ assert.ok(!matchesPrdDraftMechanics(acOnly,reword(`${FIRST_HINT}。`)));
386
+ // The first version took any non-existence command; rule 8 does not.
387
+ assert.deepEqual(evidence([' - 必跑检查: `node --check scripts/check-walk.js`'],{rules:7}),[]);
388
+ assert.equal(evidence([' - 必跑检查: `node --check scripts/check-walk.js`']).length,1);
389
+ // A rule-7 scope record (the first version's shape) re-checks with the first version's semantics.
390
+ const {dir}=specs(t);
391
+ fs.mkdirSync(path.join(dir,'.reviews'),{recursive:true});
392
+ fs.writeFileSync(path.join(dir,'.reviews/prd-walk-task-scope.json'),JSON.stringify({version:1,enforced:true,exempt:[],selfCheckRules:7})+'\n',{mode:0o600});
393
+ const options=prdTaskScopeOptions(dir,'1.walk');
394
+ assert.deepEqual(evidence([' - 必跑检查: `node --check scripts/check-walk.js`'],options),[]);
395
+ assert.equal(evidence([],options)[0].reason.expected,FIRST_HINT);
396
+ });
397
+ // 防回归(审查 r1 第 1–4 项,本次重做):任务行里 cm-ai 不认的声明、独立 验证要求 章节的命令、`./` 开头的非脚本命令都不算;
398
+ // 任务块里的行挪到 验证要求 章节也算改动,不再沿用原样豁免。
399
+ test('rule 8 counts only declarations cm-ai accepts on the task own block, and ./ commands must be script files',()=>{
400
+ const linked='## 功能需求\n1. [F-001] Walk\n- [ ] [AC-001] Walk it.\n - 必验: 走查核对\n - 必跑检查: `sh scripts/check-walk.sh`';
401
+ const missing=(lines,tail=[])=>{
402
+ const draft=walkDraft(lines,linked,'- [ ] T-002: Walk(AC-001)');
403
+ draft.features[0].documents[2].content+=tail.join('\n');
404
+ return checkPrdDraftMechanics(draft,{rules:PRD_SELF_CHECK_RULES}).findings.filter(item=>item.code==='session_task_evidence_missing').length;
405
+ };
406
+ assert.equal(missing([' - 必跑检查: 示例 `sh scripts/check-walk.sh`']),1,'a line cm-ai rejects does not borrow the AC command');
407
+ assert.equal(missing([],['','## 验证要求','- T-002: 必跑检查: `sh scripts/check-walk.sh`','']),1,'a 验证要求 section is not the task own block');
408
+ // 审查 r2 第 1 项:标题前带空格、检查行带缩进也不属于任务块。
409
+ assert.equal(missing(['',' ## 验证要求',' - 必跑检查: `sh scripts/check-walk.sh`']),1,'an indented heading ends the task block');
410
+ for(const command of ['./tools/node --check scripts/walk.js','./tools/ls docs'])
411
+ assert.equal(evidence([` - 必跑检查: \`${command}\``]).length,1,command);
412
+ assert.deepEqual(evidence([' - 必跑检查: `./scripts/check-walk.sh docs/qa.md`']),[]);
413
+ const block='- [ ] T-002: Walk\n - 开发: 会话\n - T-002: 走查时记录空态\n\n## 验证要求\n';
414
+ const moved='- [ ] T-002: Walk\n - 开发: 会话\n\n## 验证要求\n - T-002: 走查时记录空态\n';
415
+ assert.notEqual(sessionTaskDigest(block,'T-002'),sessionTaskDigest(moved,'T-002'));
416
+ });
@@ -75,7 +75,7 @@ test('an ordinary draft gets the same report under both rules; records match onl
75
75
  assert.ok(matchesPrdDraftMechanics(odd,legacy));
76
76
  assert.ok(matchesPrdDraftMechanics(odd,checkPrdDraftMechanics(odd,R2)));
77
77
  assert.ok(!matchesPrdDraftMechanics(odd,{...legacy,status:'failed'}));
78
- assert.throws(()=>checkPrdDraftMechanics(odd,{rules:7}),{code:'prd_self_check_rules_invalid'});
78
+ assert.throws(()=>checkPrdDraftMechanics(odd,{rules:9}),{code:'prd_self_check_rules_invalid'});
79
79
  });
80
80
  test('a self-check revision recorded under rule 1 still verifies after rule 2',()=>{
81
81
  const sha=value=>createHash('sha256').update(value).digest('hex');
@@ -29,7 +29,8 @@ import {refactorDiscardable,REFACTOR_REASKABLE_KINDS} from '../runtime/js/cm-ref
29
29
  import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
30
30
  import {readLearningRetrospectiveContent} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
31
31
  import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
32
- import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,deliberatelyUnanswered} from '../runtime/js/cm-ai/drive-core.mjs';
32
+ import {assertResumable,executorRelease} from '../runtime/js/executor-version.mjs';
33
+ import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,deliberatelyUnanswered,errorLine} from '../runtime/js/cm-ai/drive-core.mjs';
33
34
  import {statesZeroBlockingFindings} from '../runtime/js/review-findings.mjs';
34
35
 
35
36
  const HOST=fileURLToPath(new URL('./cm-refactor-host.mjs',import.meta.url));
@@ -179,20 +180,25 @@ function main(){
179
180
  const root=fileURLToPath(new URL('..',import.meta.url));
180
181
  valid(config.skillDir===path.join(root,'skills/cm-refactor'),'config.skillDir 必须指向当前 checkout');
181
182
  try{createCmRefactorHost(config,{call:()=>{throw Error('preflight must not call host')}});}
182
- catch(error){stop(2,`宿主配置无效: ${error.code??error.message}`);}
183
+ catch(error){stop(2,`宿主配置无效: ${errorLine(error)}`);}
183
184
  for(const [label,command] of [['judgeCommand',config.judgeCommand],...(config.baselineCommands??[]).map(item=>[item.id,item.command]),
184
185
  ...(config.batch?.cheapCommands??[]).map(item=>[item.id,item.command.map(arg=>arg.replaceAll('{file}',config.scope[0]))])]){
185
186
  try{createHostCheck({cwd:config.project,commands:[{id:label,command}]});}
186
- catch(error){stop(2,`命令定义无效 ${label}: ${error.code??error.message}`);}
187
+ catch(error){stop(2,`命令定义无效 ${label}: ${errorLine(error)}`);}
187
188
  }
188
189
  for(const mutation of config.mutations){valid(config.scope.includes(mutation.path)&&nonempty(mutation.find)
189
190
  &&typeof mutation.replace==='string'&&mutation.find!==mutation.replace,`config.mutations: ${mutation.path}`);}
190
191
  const directory=path.join(config.specs??path.join(config.project,'docs'),'refactors',config.slug);
191
- let records;try{records=openRefactorRecords(directory,{discardable:refactorDiscardable});}catch(error){stop(2,`恢复记录无效: ${error.code??error.message}`);}
192
+ let records;try{records=openRefactorRecords(directory,{discardable:refactorDiscardable});}catch(error){stop(2,`恢复记录无效: ${errorLine(error)}`);}
192
193
  if(operation==='start'&&records.context)stop(2,`start 已有运行记录,请用 resume: ${path.join(directory,'execution.jsonl')}`);
193
194
  if(['resume','finish','prepare_judge_revision'].includes(operation)&&!records.context)
194
195
  stop(2,`恢复记录不存在: ${path.join(directory,'execution.jsonl')}`);
195
196
  if(records.context&&records.context.configDigest!==digest(config))stop(2,'resume 配置绑定不匹配');
197
+ // Same gate the host applies before writing: status/cancel stay readable.
198
+ if(['start','resume','finish','prepare_judge_revision'].includes(operation)){
199
+ try{if(records.createdBy)assertResumable(records.createdBy);else if(!records.context)executorRelease();}
200
+ catch(error){stop(2,errorLine(error));}
201
+ }
196
202
  if(Object.hasOwn(plan,'discard')){
197
203
  if(operation!=='resume')stop(2,'PLAN.discard 只能配合 resume');
198
204
  const value=plan.discard,entry=records.effects.get(value?.key),last=records.recovery.lastAnswer,unknown=records.recovery.unknown;
@@ -2,6 +2,8 @@
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import {fileURLToPath} from 'node:url';
5
+ import {executorRelease} from '../runtime/js/executor-version.mjs';
6
+ import {diagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
5
7
 
6
8
  const INTENTS=new Set(['defect','behavior-change','gradual-adoption','structure-only']);
7
9
 
@@ -57,7 +59,8 @@ function workflowRoot(skillDir) {
57
59
  ownedFile(root,'VERSION','skill_path_invalid');layout='plugin';
58
60
  }else if(fs.existsSync(path.join(root,'templates','cm-VERSION'))){
59
61
  ownedFile(root,'templates/cm-VERSION','skill_path_invalid');layout='claude-compat';
60
- }else reject('skill_path_invalid');
62
+ // No release marker at all: a broken install, reported with its reinstall hint.
63
+ }else{executorRelease(root);reject('skill_path_invalid');}
61
64
  if(realDirectory(path.join(root,'templates'),'skill_path_invalid')!==path.join(root,'templates'))
62
65
  reject('skill_path_invalid');
63
66
  for(const file of ['skills/cm-refactor/SKILL.md','templates/refactor/cm-refactor-denies.json',
@@ -139,7 +142,7 @@ if(isMainModule(process.argv[1])){
139
142
  else { process.stderr.write(output);process.exitCode=2; }
140
143
  } catch(error) {
141
144
  process.stderr.write(`${JSON.stringify({schemaVersion:1,workflow:'cm-refactor',status:'error',
142
- reason:error?.code??'admission_failed',executionAuthorized:false,writeAuthorized:false})}\n`);
145
+ reason:error?.code??'admission_failed',...(diagnosticReason(error)?{detail:diagnosticReason(error)}:{}),executionAuthorized:false,writeAuthorized:false})}\n`);
143
146
  process.exitCode=2;
144
147
  }
145
148
  }
@@ -6,6 +6,7 @@ import {createCmRefactorHost} from '../runtime/js/cm-refactor/host.mjs';
6
6
  import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
7
7
  import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
8
8
  import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
9
+ import {diagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
9
10
  export async function main(argv=process.argv.slice(2)){
10
11
  let bridge;
11
12
  try{
@@ -20,7 +21,8 @@ export async function main(argv=process.argv.slice(2)){
20
21
  const raw=process.stdin.isTTY&&typeof process.stdin.setRawMode==='function';if(raw)process.stdin.setRawMode(true);
21
22
  try{await serveCmAiHost({host,input:process.stdin,output:process.stdout,toolBridge:bridge,inputLimit:2*1024*1024});}finally{if(raw)process.stdin.setRawMode(false);}
22
23
  return 0;
23
- }catch(error){process.stderr.write(JSON.stringify({error:{code:error.code??'refactor_host_failed'}})+'\n');return 1;}
24
+ }catch(error){const reason=diagnosticReason(error);
25
+ process.stderr.write(JSON.stringify({error:{code:error.code??'refactor_host_failed',...(reason?{reason}:{})}})+'\n');return 1;}
24
26
  finally{bridge?.close();}
25
27
  }
26
28
  if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
@@ -69,8 +69,9 @@ HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" \
69
69
 
70
70
  PLUGIN_LIST="$(HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" codex plugin list)"
71
71
  printf '%s\n' "$PLUGIN_LIST"
72
- printf '%s\n' "$PLUGIN_LIST" |
73
- grep -Eq '^cm-workflow@personal[[:space:]]+installed, enabled' ||
72
+ # grep -c reads all input; grep -q could close the pipe early and fail under pipefail.
73
+ plugin_enabled="$(printf '%s\n' "$PLUGIN_LIST" | grep -Ec '^cm-workflow@personal[[:space:]]+installed, enabled' || true)"
74
+ [ "$plugin_enabled" -gt 0 ] ||
74
75
  fail "Codex did not report cm-workflow@personal as installed and enabled"
75
76
 
76
77
  HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" \