@aibyzero/cm-workflow 0.16.8 → 0.17.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 (226) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +31 -0
  3. package/README.md +22 -3
  4. package/VERSION +1 -1
  5. package/compat/claude-commands/cm-notify.md +3 -0
  6. package/docs/cm-control-policy-v2.md +331 -0
  7. package/docs/execution-optimizations.md +1 -1
  8. package/docs/external-models.md +3 -3
  9. package/docs/human-correction.md +5 -5
  10. package/docs/installation.md +1 -1
  11. package/docs/js-workflow-control.md +119 -78
  12. package/docs/next-steps.md +19 -2
  13. package/docs/untested-branches.md +2 -3
  14. package/docs/user-guide.md +105 -5
  15. package/package.json +2 -1
  16. package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
  17. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
  18. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
  19. package/runtime/js/cm-ai/code-projects.mjs +4 -1
  20. package/runtime/js/cm-ai/control-policy.mjs +111 -0
  21. package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
  22. package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
  23. package/runtime/js/cm-ai/drive-core.mjs +9 -0
  24. package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
  25. package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
  26. package/runtime/js/cm-ai/effect-contract.mjs +6 -1
  27. package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
  28. package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
  29. package/runtime/js/cm-ai/host-check.mjs +4 -1
  30. package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
  31. package/runtime/js/cm-ai/host-documentation.mjs +53 -12
  32. package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
  33. package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
  34. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
  35. package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
  36. package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
  37. package/runtime/js/cm-ai/host-review-file.mjs +1 -1
  38. package/runtime/js/cm-ai/host-session.mjs +1 -1
  39. package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
  40. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
  41. package/runtime/js/cm-ai/host.mjs +1 -2
  42. package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
  43. package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
  44. package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
  45. package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
  46. package/runtime/js/cm-ai/review-package.mjs +26 -5
  47. package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
  48. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
  49. package/runtime/js/cm-ai/task-commit.mjs +39 -0
  50. package/runtime/js/cm-ai/task-runner.mjs +629 -121
  51. package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
  52. package/runtime/js/cm-ai/worker-claude.mjs +10 -3
  53. package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
  54. package/runtime/js/cm-fix/execution.mjs +176 -48
  55. package/runtime/js/cm-fix/host.mjs +2 -1
  56. package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
  57. package/runtime/js/cm-fix/progress.mjs +13 -3
  58. package/runtime/js/cm-fix/protected-edits.mjs +10 -3
  59. package/runtime/js/cm-fix/repair.mjs +11 -3
  60. package/runtime/js/cm-fix/test-author.mjs +10 -3
  61. package/runtime/js/cm-idea/session.mjs +67 -4
  62. package/runtime/js/cm-init/review-evidence.mjs +3 -1
  63. package/runtime/js/cm-prd/review-correction.mjs +10 -4
  64. package/runtime/js/cm-prd/review-host.mjs +1 -1
  65. package/runtime/js/cm-prd/review-publication.mjs +5 -3
  66. package/runtime/js/cm-prd/session.mjs +43 -0
  67. package/runtime/js/cm-refactor/records.mjs +98 -8
  68. package/runtime/js/cm-refactor/workflow.mjs +80 -10
  69. package/runtime/js/cm-test/host.mjs +10 -3
  70. package/runtime/js/cm-test/session.mjs +45 -6
  71. package/runtime/js/notify-safe-read.mjs +49 -0
  72. package/runtime/js/notify-send.mjs +313 -0
  73. package/runtime/js/notify.mjs +164 -37
  74. package/runtime/js/policy-binding-compat.mjs +55 -0
  75. package/runtime/review.md +52 -7
  76. package/runtime/task-gates.md +107 -9
  77. package/scripts/ci-test-shards.mjs +67 -0
  78. package/scripts/ci-test-shards.test.mjs +64 -0
  79. package/scripts/ci-test-weights.json +222 -0
  80. package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
  81. package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
  82. package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
  83. package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
  84. package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
  85. package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
  86. package/scripts/cm-ai-batch-drive.mjs +98 -34
  87. package/scripts/cm-ai-batch-drive.test.mjs +124 -16
  88. package/scripts/cm-ai-batch-host.mjs +167 -29
  89. package/scripts/cm-ai-batch-host.test.mjs +303 -31
  90. package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
  91. package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
  92. package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
  93. package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
  94. package/scripts/cm-ai-batch-run.mjs +213 -25
  95. package/scripts/cm-ai-batch-run.test.mjs +21 -341
  96. package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
  97. package/scripts/cm-ai-bootstrap.test.mjs +2 -3
  98. package/scripts/cm-ai-control-launch.test.mjs +219 -0
  99. package/scripts/cm-ai-control-policy.test.mjs +124 -0
  100. package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
  101. package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
  102. package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
  103. package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
  104. package/scripts/cm-ai-direct-review.test.mjs +348 -0
  105. package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
  106. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
  107. package/scripts/cm-ai-drive.mjs +142 -58
  108. package/scripts/cm-ai-drive.test.mjs +70 -84
  109. package/scripts/cm-ai-fix-integration.test.mjs +3 -5
  110. package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
  111. package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
  112. package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
  113. package/scripts/cm-ai-host-fixture.mjs +296 -0
  114. package/scripts/cm-ai-host-protected.test.mjs +253 -0
  115. package/scripts/cm-ai-host.mjs +122 -100
  116. package/scripts/cm-ai-host.test.mjs +35 -776
  117. package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
  118. package/scripts/cm-ai-legacy-history.test.mjs +53 -0
  119. package/scripts/cm-ai-light-modules.test.mjs +54 -0
  120. package/scripts/cm-ai-multi-root.test.mjs +4 -4
  121. package/scripts/cm-ai-nested-execution.test.mjs +16 -19
  122. package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
  123. package/scripts/cm-ai-progress.test.mjs +10 -8
  124. package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
  125. package/scripts/cm-ai-protected-scope.test.mjs +8 -5
  126. package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
  127. package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
  128. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
  129. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
  130. package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
  131. package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
  132. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
  133. package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
  134. package/scripts/cm-ai-review-failure.test.mjs +137 -32
  135. package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
  136. package/scripts/cm-ai-review-timeout.test.mjs +132 -67
  137. package/scripts/cm-ai-run.mjs +91 -28
  138. package/scripts/cm-ai-run.test.mjs +11 -38
  139. package/scripts/cm-ai-selection-guard.test.mjs +2 -2
  140. package/scripts/cm-ai-session-chain.test.mjs +18 -15
  141. package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
  142. package/scripts/cm-ai-supersede.test.mjs +489 -51
  143. package/scripts/cm-blocked-reason.test.mjs +2 -3
  144. package/scripts/cm-capability-gate.test.mjs +33 -1
  145. package/scripts/cm-check-drive-files.mjs +8 -0
  146. package/scripts/cm-check-drive.test.mjs +2 -5
  147. package/scripts/cm-check-runtime.sh +4 -2
  148. package/scripts/cm-claude-developer-worker.test.mjs +15 -0
  149. package/scripts/cm-claude-review-stream.test.mjs +21 -16
  150. package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
  151. package/scripts/cm-claude-worker.test.mjs +23 -5
  152. package/scripts/cm-controlled-correction.test.mjs +469 -0
  153. package/scripts/cm-external-batch-host.test.mjs +30 -11
  154. package/scripts/cm-external-model-host.test.mjs +1 -1
  155. package/scripts/cm-external-model-recovery.test.mjs +32 -12
  156. package/scripts/cm-external-qa-fix.test.mjs +1 -1
  157. package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
  158. package/scripts/cm-fix-abandon.test.mjs +163 -10
  159. package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
  160. package/scripts/cm-fix-drive.mjs +25 -7
  161. package/scripts/cm-fix-host.mjs +8 -7
  162. package/scripts/cm-fix-review-budget.test.mjs +13 -0
  163. package/scripts/cm-fix-review-recovery.test.mjs +36 -1
  164. package/scripts/cm-host-answer-timeout.test.mjs +65 -0
  165. package/scripts/cm-host-call-kinds.test.mjs +28 -0
  166. package/scripts/cm-host-documentation.test.mjs +49 -0
  167. package/scripts/cm-host-qa-executor.test.mjs +23 -12
  168. package/scripts/cm-host-qa-policy.test.mjs +43 -16
  169. package/scripts/cm-host-review-authority.test.mjs +0 -31
  170. package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
  171. package/scripts/cm-idea-drive.mjs +49 -11
  172. package/scripts/cm-idea-drive.test.mjs +66 -0
  173. package/scripts/cm-idea-host.mjs +106 -16
  174. package/scripts/cm-init-answer-gaps.test.mjs +258 -0
  175. package/scripts/cm-init-drive.mjs +41 -7
  176. package/scripts/cm-init-host.mjs +61 -12
  177. package/scripts/cm-knowledge-closeout.test.mjs +3 -3
  178. package/scripts/cm-log-event.mjs +21 -10
  179. package/scripts/cm-notify-command.test.mjs +936 -0
  180. package/scripts/cm-notify-read-drift.test.mjs +270 -0
  181. package/scripts/cm-notify.mjs +481 -0
  182. package/scripts/cm-notify.test.mjs +312 -23
  183. package/scripts/cm-patrol.test.mjs +3 -2
  184. package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
  185. package/scripts/cm-prd-drive.mjs +18 -5
  186. package/scripts/cm-prd-drive.test.mjs +15 -0
  187. package/scripts/cm-prd-host.mjs +37 -4
  188. package/scripts/cm-prd-review-disposition.test.mjs +6 -1
  189. package/scripts/cm-prd-review-gate.mjs +56 -0
  190. package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
  191. package/scripts/cm-refactor-drive.mjs +52 -8
  192. package/scripts/cm-refactor-drive.test.mjs +44 -0
  193. package/scripts/cm-refactor-host.test.mjs +10 -6
  194. package/scripts/cm-release-smoke.sh +2 -0
  195. package/scripts/cm-task-gate-correction.test.mjs +69 -16
  196. package/scripts/cm-task-gate.mjs +368 -34
  197. package/scripts/cm-task-gate.py +2 -0
  198. package/scripts/cm-task-gate.test.mjs +252 -4
  199. package/scripts/cm-test-answer-gaps.test.mjs +151 -0
  200. package/scripts/cm-test-drive.mjs +21 -5
  201. package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
  202. package/scripts/fixtures/claude-review-process.mjs +1 -1
  203. package/scripts/fixtures/native-gate-fixture.mjs +18 -0
  204. package/scripts/policy-binding-compat.test.mjs +103 -0
  205. package/scripts/scan-public-safety.py +4 -0
  206. package/scripts/validate-public-repo.py +4 -0
  207. package/skills/cm-ai/SKILL.md +8 -6
  208. package/skills/cm-ai/references/N3-execute-task.md +17 -2
  209. package/skills/cm-ai/references/N4-review.md +11 -21
  210. package/skills/cm-ai/references/N5-mark-done.md +1 -1
  211. package/skills/cm-ai/references/N6-qa-eval.md +49 -21
  212. package/skills/cm-ai/references/js-host-modes.md +35 -14
  213. package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
  214. package/skills/cm-ai/references/js-host-recovery.md +181 -21
  215. package/skills/cm-ai/references/js-host.md +76 -32
  216. package/skills/cm-check/SKILL.md +3 -3
  217. package/skills/cm-fix/SKILL.md +12 -0
  218. package/skills/cm-fix/references/js-host.md +44 -5
  219. package/skills/cm-idea/references/js-host.md +27 -2
  220. package/skills/cm-init/references/js-host.md +17 -4
  221. package/skills/cm-notify/SKILL.md +34 -0
  222. package/skills/cm-prd/references/js-change-recovery.md +35 -1
  223. package/skills/cm-prd/references/js-host.md +1 -1
  224. package/skills/cm-refactor/SKILL.md +12 -0
  225. package/skills/cm-refactor/references/js-host.md +17 -0
  226. package/skills/cm-test/references/js-host.md +14 -1
@@ -0,0 +1,55 @@
1
+ // Durable cm-init / cm-test sessions bind the policy documents they ran under.
2
+ // The external answer gap fixes (batch 3) added recovery sections to two of
3
+ // them, which would refuse every session created before (idea_session_binding_
4
+ // changed / cm_test_session_binding_changed) — not even status could run.
5
+ // This is a controlled migration, not a relaxed check: an older binding is
6
+ // accepted only when it is one of the known legacy digests below, every other
7
+ // bound file is byte-identical to that legacy version, and the changed document
8
+ // is one of the known successors. Any other drift still refuses. When a bound
9
+ // document changes again, add its new digest to the successors (a test checks
10
+ // that the current documents are listed).
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import {createHash} from 'node:crypto';
14
+ export const sha256=text=>createHash('sha256').update(text).digest('hex');
15
+ // origin/main 0b3040e (before batch 3).
16
+ export const LEGACY_INIT_POLICIES=Object.freeze([Object.freeze({since:'0b3040e',
17
+ policyDigest:'d467afb7082e608c0be4b2affca9a1005edc13a39d61202abede6dfead8e0d6f',
18
+ changed:'skills/cm-init/references/js-host.md',
19
+ files:Object.freeze({
20
+ 'skills/cm-init/SKILL.md':'4b69e2a2fa14676e3aa105729ba3dccc9f54053b2876cad0af1bf66e344bd7ec',
21
+ 'skills/cm-init/references/js-host.md':'da04c4bc6d9c5a40b99a8dd6c2c44e9c719663b4032bbf2b0ef0ae4c53948e8a',
22
+ 'templates/rules/backend-api.md':'4c2b8d85358c81081ab3d039b23a5fb9cb8640f069b222253d612bb48bafdc7e', // gitleaks:allow SHA-256 文件摘要,不是密钥
23
+ 'templates/rules/coding-style.md':'74b789f8aa44f2ec9643ea85d05705c702ceb278f7cc10731ca5fe78320af796',
24
+ 'templates/rules/database.md':'b7c69d7b29870db0f725c0bf80c1d1b989f0c315a5d8f0fb9d311008922b6926',
25
+ 'templates/rules/finance.md':'faeac9aedc4aec79161940ae422f56c65872e63c5909642a3fe27714e5646e9c',
26
+ 'templates/rules/frontend.md':'9247f607f050ed18cfdc2ac28ee5d0b8b2f4b54b757d860fed3be5dae0a9a976',
27
+ 'templates/rules/git-workflow.md':'28142563f8146ffe155da0b845035bcfccf828bc6312c26c9166d655e76b31cd',
28
+ 'templates/rules/miniprogram.md':'43193532bfa1237f2f4c085eb854b332e6589ea6e3176b8bc0adbeb56f96fc3f',
29
+ 'templates/rules/security.md':'afa53ae25dc434a690006cb7eabeb33d2656ce7371d1f7c57d70ca6b385b7fbc',
30
+ 'templates/rules/smart-contract.md':'eabe294e3194ddbe2eff5470736db4985c3e88c1cbbc1f21a8262dd4fa15d2b7',
31
+ 'templates/rules/testing.md':'e992de31f24b99d0b2bc9fd105c61ea9b0d6bc298190a3cf830a8f6a506c8455'})})]);
32
+ export const LEGACY_TEST_POLICIES=Object.freeze([Object.freeze({since:'0b3040e',
33
+ policy:'0a80dde424c5aea90fc05ea2bb919a8bdb1ae4a2788d252e2b97a7de135f8bf4',changed:'skills/cm-test/references/js-host.md'})]);
34
+ // Known versions of the changed documents that may continue a legacy binding.
35
+ export const POLICY_DOC_SUCCESSORS=Object.freeze({
36
+ 'skills/cm-init/references/js-host.md':Object.freeze(['d3d6ad0b02ee7d3863302c49a9434b1a9f423e8ab4ff332cd9ad077a0b270fb1',
37
+ '223dd3a4a4172591480bff818bc81216d5554ea1c7c7785619ccab33ee3fd833',
38
+ 'b218527db47bfa2c995173a0d80e3927e1bb8946c397a2945c3c09e73639af59']),
39
+ 'skills/cm-test/references/js-host.md':Object.freeze(['0a6023c9036693a93a17650872b634b33d68eecc2fbece188519e94e31452e8c']),
40
+ });
41
+ // cm-init: files is the current [[relativePath, content|null], ...] policy list.
42
+ export function legacyInitBindings({project,workflowRoot,files}){
43
+ const current=Object.fromEntries(files.map(([file,content])=>[file,content===null?null:sha256(content)]));
44
+ return LEGACY_INIT_POLICIES.filter(legacy=>{
45
+ const names=Object.keys(legacy.files).sort();
46
+ return JSON.stringify(names)===JSON.stringify(Object.keys(current).sort())
47
+ &&names.every(file=>file===legacy.changed?POLICY_DOC_SUCCESSORS[file].includes(current[file]):current[file]===legacy.files[file]);
48
+ }).map(legacy=>({project,workflowRoot,policyDigest:legacy.policyDigest}));
49
+ }
50
+ // cm-test: binding is the current binding; skillDir holds references/js-host.md.
51
+ export function legacyTestBindings(binding,skillDir){
52
+ const doc=sha256(fs.readFileSync(path.join(skillDir,'references/js-host.md'),'utf8'));
53
+ return LEGACY_TEST_POLICIES.filter(legacy=>POLICY_DOC_SUCCESSORS[legacy.changed].includes(doc))
54
+ .map(legacy=>({...binding,policy:legacy.policy}));
55
+ }
package/runtime/review.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Every implementation task requires an independent review before it can be marked complete. The reviewer must not inherit the author's reasoning narrative.
4
4
 
5
+ CM 门禁检查来源声明的格式、任务与轮次、材料摘要、当前文件和执行记录的一致性,用于防手滑与过期证据。来源声明不验证审查者身份或实际人工交互;门禁不承诺抵抗拥有完整文件写权限和 shell 能力的会话造假。fresh 上下文、审查结果、检查通过和完成复查仍是正常工作流路径的完成条件。发布、部署、资金及其他范围外动作继续遵守其单独确认要求。
6
+
5
7
  N4 accepts only a `ready_for_review` implementation handoff validated through
6
8
  `runtime/task-gates.md`. The handoff is author evidence, never an approval. The
7
9
  review file owns the disposition that controls whether N3 retries or N5 may mark
@@ -62,10 +64,18 @@ to erase a valid blocking finding.
62
64
 
63
65
  The shared-JS target supports a fresh reviewer on whichever provider is available.
64
66
  The shared V3 runner now also accepts Claude-bound normalized review invocations,
65
- using the same grant, registration, independent identity, replay and completion checks.
67
+ using the same request/package binding, registration, reviewer source declarations, replay and completion checks.
68
+ cm-ai uses the `host-review` source channel; cm-fix retains its existing
69
+ `host-authorized` contract. A cm-ai journal with old grant-channel invocations is
70
+ rejected as `runner_invocation`; preserve it and use the original version's
71
+ read-only tools to inspect history. This entry does not replay or migrate those
72
+ invocations.
66
73
  Its registered result is published as `claude-cli`, never relabeled as Codex.
67
74
  The single-task host connects the Claude worker only with a matching diagnostic and
68
- separately authorized attempt. Claude preflight uses a macOS loopback-only sandbox,
75
+ the active control contract: cm-ai advances ordinary review rounds directly within
76
+ the confirmed scope, for both existing and new runs. Requests and receipts bind
77
+ the actual invocation, package and execution records to detect stale or mismatched
78
+ materials. Claude preflight uses a macOS loopback-only sandbox,
69
79
  synthetic credentials and a rejecting local sink; it does not obtain a model review.
70
80
  The producer permits one empty startup health probe and rejects model requests locally.
71
81
  Installed CLI has passed this local request-surface probe. It uses the same bounded temporary
@@ -105,10 +115,46 @@ PRD artifact 回执先比对原始字节,仅 Markdown 中 `tasks.md` 的任务
105
115
  proceed only when the reviewer records `approved` and the disagreement is
106
116
  preserved in `LESSONS.md`.
107
117
 
108
- A concrete human-approved local correction after blocked round two may use the
118
+ A concrete local correction after the user confirms its scope may use the
109
119
  one-shot task-gate entrance in `docs/human-correction.md`. It preserves the original
110
- reports, seals a fresh independent correction review, and does not reopen a host
111
- journal or reset ordinary attempts. Without explicit human authorization, stop.
120
+ reports, records the correction reason and bound source declaration, seals a fresh
121
+ independent correction review, and does not reopen a host journal or reset ordinary
122
+ attempts. The record reports the supplied decision source; it does not create approval.
123
+
124
+ A separate version-two taskgate protocol, `cm-controlled-correction`, is one-shot
125
+ (`version:2`, `continuation:1`), described in `docs/cm-control-policy-v2.md`.
126
+ It supports only compatibility taskgate tasks without JS ownership. A retained
127
+ JS journal, JS run or unknown ownership evidence blocks the compatibility writer
128
+ and must be rejected before correction preparation. Do not delete that evidence
129
+ or hand-edit ownership to enter this protocol. It
130
+ records the concrete correction decision as provenance-only `operator` or `model`,
131
+ without claiming human authentication or approval. It keeps the original blocked
132
+ round-two report and every blocking finding, including P2, as immutable history.
133
+ Finalize the actual in-scope revision, relevant checks and Learning/handoff first;
134
+ then review the complete revised package through a fresh independent channel.
135
+ Only approved, zero-blocking evidence bound to the correction record, final
136
+ handoff and current implementation can enter the existing N4/N5 completion gate.
137
+ Its v2 correction review body is strict raw JSON with exactly `conclusion`,
138
+ `findings`, and `resolved_findings`. Each finding has exactly `id`, `priority`
139
+ (P0-P3), and nonempty `evidence`; ids are unique across both arrays. Active
140
+ `findings.length` equals the header's `blocking_findings`. Approved requires
141
+ `conclusion: "Zero findings."` and an empty active findings array; other verdicts
142
+ require `"Blocking findings."`. Fixed historical P2 belongs only in
143
+ `resolved_findings`. A zero-findings phrase cannot hide a remaining P2, extra prose
144
+ or a mismatched count. This structured-body rule does not change legacy human
145
+ correction review bodies.
146
+ This slice connects only owner-free compatibility taskgate correction evidence
147
+ and the exact task checkbox. cm-ai v2 single-task and batch round-two runs remain
148
+ formally blocked; no runner-owned correction completion entrance exists. Even
149
+ prepared/published taskgate evidence cannot complete a JS-owned run. No original
150
+ batch restoration, N6/N7/N8 advance or `run_done` follows this compatibility
151
+ protocol. Do not hand-edit journal or batch state to claim workflow completion.
152
+ It is not attempt 3, does not reset a host journal, and cannot coexist with the
153
+ legacy human continuation. Source labels, model output and V3 grants do not expand
154
+ real conversation authorization, code scope, external sends, Git/push, publication,
155
+ deployment or financial permissions. Safety/data-correctness disputes that need
156
+ a human decision still require that decision; unavailable review capacity remains
157
+ pending, never self-approved.
112
158
 
113
159
  At any stage, changing reviewed code, tests, or execution instructions invalidates
114
160
  approval for the changed content. N5 may record improvement suggestions, not make
@@ -145,8 +191,7 @@ verdict 至少为 1。`self-degraded` 必须写 `independent: false` 并增加
145
191
  `--project-root` 复算;否则文件内容在审查后变化时无法进入 N5。历史恢复显式使用
146
192
  `--allow-legacy-unbound` 时不属于内容绑定审查,必须在证据中披露。
147
193
  历史 `self-degraded` 可读取和审计,但不得据此授权新完成或补造独立审查。
148
- 声明字段和 handoff 哈希不证明 reviewer 实际执行或代码快照未变;主执行者仍须
149
- 核对真实通道、任务增量及验证证据,不把当前声明门禁当成完整执行凭据机制。
194
+ `reviewer` 与 `independent` 是审查来源声明;`decision_source` 若由相应入口记录,也仅表示决定来源。字段和摘要用于核对本轮材料与执行记录的一致性。主执行者仍按正常工作流取得 fresh 审查、核对任务增量及验证证据。
150
195
 
151
196
  No matching evidence file means review did not happen. File existence alone is
152
197
  not approval: the completion node must run the `cm-task-gate.py mark-done` lock
@@ -5,6 +5,8 @@ creating a second task-state database. `tasks.md` remains the authoritative
5
5
  business-task state. Handoffs and review files are content-bound evidence under the
6
6
  existing `{SPECS_DIR}/.reviews/` domain.
7
7
 
8
+ CM 门禁检查来源声明的格式、任务与轮次、材料摘要、当前文件和执行记录的一致性,用于防手滑与过期证据。来源声明不验证审查者身份或实际人工交互;门禁不承诺抵抗拥有完整文件写权限和 shell 能力的会话造假。fresh 上下文、审查结果、检查通过和完成复查仍是正常工作流路径的完成条件。发布、部署、资金及其他范围外动作继续遵守其单独确认要求。
9
+
8
10
  ## Implementation handoff
9
11
 
10
12
  The active cm-ai Skill passes `--require-learning` to `check-n4` and the existing
@@ -15,6 +17,42 @@ The flag checks record completeness, not the truth of an agent's statement; inde
15
17
  review still verifies the actual work. Legacy callers remain compatible without this
16
18
  flag, and the persistent runner retains its existing structured Learning checks.
17
19
 
20
+ Inventory verification is enabled only by the compatibility command-line entry.
21
+ `main()` passes the internal function option `inventory: 'required'` to `check-n4`,
22
+ `check-n5`, `prepare-mark-done`, `verify-mark-done-plan` and `mark-done-locked`.
23
+ Completion preparation and rechecks forward the same selectors to N5, including
24
+ human corrections. This is not a CLI flag. Exported library functions default to
25
+ the original result fields and errors without inventory checks; JS task completion,
26
+ cm-fix and cm-refactor retain their own review-package baselines.
27
+
28
+ Before compatibility N3 edits any file, the main executor captures the task's starting inventory:
29
+
30
+ ```bash
31
+ node {CM_WORKFLOW_ROOT}/scripts/cm-task-gate.mjs capture-baseline \
32
+ --project-root {CODE_PROJECT} \
33
+ --reviews-dir {SPECS_DIR}/.reviews \
34
+ --feature {FEATURE_SLUG} --task {T-xxx}
35
+ ```
36
+
37
+ This writes `{feature}-{task}-baseline.json` under the reviews directory. It seals
38
+ identity, canonical-root digest, stable ignore policy, relative file paths, SHA-256,
39
+ byte sizes and executable bits with a whole-record digest; it stores no file bodies.
40
+ The existing review-package scanner excludes dependencies, fixed junk, Git-ignored
41
+ paths and specs. A nested canonical `.reviews` parent is the specs subtree; when
42
+ `.reviews` is at the code root only that directory is excluded. Any other directory
43
+ that merely shares the `.reviews` name is ordinary code and stays in the inventory.
44
+ External specs do not enter the code root.
45
+ The same baseline/current ignore union filters both sides; AGENTS.md remains checked.
46
+ When Git ignore policy is unavailable (as may happen on Windows), scanning falls back to built-in rules; Git-ignored files count as changes and must be listed or handled before the gate can pass.
47
+ Capture refuses beyond 10,000 files or 1 GiB of inventory bytes, names the triggering
48
+ file and writes no partial baseline. Capture cannot prove it preceded an edit;
49
+ executors and independent reviewers must verify that ordering.
50
+
51
+ An existing baseline is never overwritten. If it is wrong, a human must delete
52
+ that file, capture again, and add one `decision` line to the authoritative run log.
53
+ Attempt 2 reuses attempt 1's baseline; changes accumulate from the task start.
54
+ This compatibility command supports one `--project-root`, not `codeProjectPaths`.
55
+
18
56
  For attempt 1 or 2, N3 writes:
19
57
 
20
58
  ```text
@@ -36,7 +74,7 @@ portable across macOS, Linux, and Windows.
36
74
  Before writing a new handoff, hash the exact `changed_files` set:
37
75
 
38
76
  ```bash
39
- python3 {CM_WORKFLOW_ROOT}/scripts/cm-task-gate.py hash-implementation \
77
+ node {CM_WORKFLOW_ROOT}/scripts/cm-task-gate.mjs hash-implementation \
40
78
  --project-root {CODE_PROJECT} \
41
79
  --file path/one --file path/two
42
80
  ```
@@ -48,9 +86,23 @@ symlinks and directories are rejected. Historical unbound handoffs require the
48
86
  explicit recovery flag `--allow-legacy-unbound` and return `content_bound: false`;
49
87
  new work must not use that flag.
50
88
 
51
- The gate validates declaration consistency; it does not reconstruct a task diff
52
- from an already-dirty or multi-repository working tree. N3 remains responsible
53
- for comparing `changed_files` with the task-scoped diff before writing handoff.
89
+ With a baseline, CLI `check-n4` and `check-n5` reconstruct the actual added, modified
90
+ (including executable-bit changes) and deleted paths from the starting inventory
91
+ and current tree. `changed_files` must equal that set. Mismatch lists “改了但没列”
92
+ and “列了但没改”, each capped at 20 paths with `+N more`. Success returns
93
+ `inventory: "verified"` and `inventory_counts: {added, modified, deleted}`.
94
+ Content binding remains mandatory and independent of inventory verification.
95
+ Preexisting dirty content is part of the baseline; concurrent unrelated edits are
96
+ still task-period changes and must be reconciled before review.
97
+
98
+ A missing baseline blocks these CLI entries. Only explicit `--allow-legacy-unbound`
99
+ recovery returns `inventory: "unverified"` and the fixed `inventory_note`:
100
+ “未捕获编辑前基线,不保证清单完整,只保证已列文件的内容绑定”。
101
+ If the legacy handoff also lacks its content digest, `content_bound` remains false;
102
+ the note does not create a missing content binding. The flag cannot bypass a corrupt,
103
+ wrong-task or wrong-root baseline. The unchanged handoff schema carries no baseline
104
+ fields. Before writing the handoff, reconcile the complete file list; after writing,
105
+ run N4 and keep its digest and inventory result for independent review.
54
106
 
55
107
  Validate the evidence before N4:
56
108
 
@@ -82,14 +134,58 @@ handoff_sha256: <lowercase SHA-256 returned by check-n4>
82
134
  entry and the body must contain findings or an explicit zero-findings result.
83
135
  `changes_requested` returns to N3 and produces the next attempt. N4 never edits
84
136
  implementation files. Round 2 cannot create attempt 3: another blocking result
85
- becomes `blocked` and requires human resolution under `runtime/review.md`.
137
+ becomes `blocked`. Safety/data-correctness disputes still require a real human
138
+ decision under `runtime/review.md`; the separately bounded continuation protocols
139
+ below do not create ordinary attempt 3 or erase blocking findings.
86
140
 
87
- For an explicitly human-authorized correction after round-two blocked, see
141
+ For a correction with confirmed scope after round-two blocked, see
88
142
  `docs/human-correction.md`: `prepare-human-correction` and
89
143
  `publish-human-correction-review` keep the original four records and bind a separate
90
- one-shot correction. N4/N5 and locked completion accept its fixed `--correction`
144
+ one-shot correction with its reason and bound decision-source declaration. These
145
+ records do not create approval. N4/N5 and locked completion accept its fixed `--correction`
91
146
  record; legacy-unbound flags do not weaken correction checks.
92
147
 
148
+ A separate version-two compatibility taskgate entrance provides one-shot
149
+ `cm-controlled-correction` evidence
150
+ (`version:2`, `continuation:1`), prepared by `prepare-controlled-correction` and
151
+ sealed by `publish-controlled-correction-review`; see `docs/cm-control-policy-v2.md`.
152
+ It supports only tasks without JS ownership. Retained JS journal/run/unknown
153
+ evidence blocks the compatibility writer and must reject preparation first;
154
+ prepared/published correction evidence cannot bypass that ownership gate.
155
+ `--decision-source operator|model` is provenance only, not authentication or human
156
+ approval. Neither entrance accepts `--human-authorized`; the legacy human protocol
157
+ binds only its reason and source declaration. The two continuations are mutually exclusive.
158
+ Both prepare commands hold the shared `{feature}-{task}-correction-prepare.lock`
159
+ through preparation, with PID/time ownership and fail-fast contention. A peer's
160
+ orphan handoff alone is preserved for bounded preparation recovery; any peer
161
+ record/review/receipt prevents another continuation. Interrupted locks are not
162
+ automatically removed: verify the owner has exited, inspect preparation/sealed
163
+ evidence and coordinate explicitly. An active or unknown owner never authorizes
164
+ lock deletion, retry or automatic crash recovery.
165
+ The gate pins the original r1/r2 handoff/review history, keeps blocked r2 and P2
166
+ findings, and binds the corrected implementation plus finalized Learning/handoff.
167
+ A fresh independent review must cover the complete correction scope, bind
168
+ `correction_sha256` and `handoff_sha256`, and report approved with zero blocking
169
+ findings. The v2 review's strict raw JSON body has exactly `conclusion`, `findings`
170
+ and `resolved_findings`; item keys are exactly `id`, `priority` (P0-P3), and
171
+ `evidence`, with ids unique across both arrays. Active findings count must equal
172
+ `blocking_findings`; approved requires `"Zero findings."` with no active finding,
173
+ while non-approved requires `"Blocking findings."`. Repaired historical P2 is
174
+ recorded only in resolved findings. A zero-findings phrase does not suppress an
175
+ active P2 or extra text; the old human body contract stays unchanged.
176
+ N4/N5 and locked completion consume that sealed evidence through the
177
+ existing fixed `--correction` selector. Drift, missing Learning, duplicate
178
+ continuation or a new blocking finding refuses completion; no manual checkbox,
179
+ third ordinary round, journal reset or extra completion path is introduced.
180
+ This correction slice changes only owner-free compatibility taskgate evidence
181
+ and the exact task checkbox. cm-ai v2 single-task and batch r2 remains formally
182
+ blocked, with no runner-owned correction completion entrance. Compatibility
183
+ `mark-done` cannot finish that JS-owned run, restore its batch, advance N6/N7/N8
184
+ or publish `run_done`. Never delete ownership evidence or hand-edit journal/batch
185
+ state to imply completion.
186
+ The source declaration cannot widen real dialogue authorization or external
187
+ push, publication, deployment and financial permissions.
188
+
93
189
  N5 must let the JavaScript gate validate and update the exact task checkbox while
94
190
  the compatibility entry holds the existing platform ownership lock:
95
191
 
@@ -180,8 +276,10 @@ completion. Missing independent capacity leaves work pending; do not add a skip
180
276
  flag or treat diagnostic approval as independent. Existing completed tasks are
181
277
  not automatically reopened or assigned fabricated review evidence.
182
278
 
183
- This is a declaration gate, not proof of reviewer execution, an immutable code
184
- snapshot, or full crash-recoverable completion. Any post-review change to reviewed code,
279
+ `reviewer`, `independent` and any `decision_source` are source declarations.
280
+ This gate checks their format and binding to the task, materials and execution
281
+ records; it does not authenticate the reviewer or the reported interaction. It
282
+ also does not provide an immutable code snapshot or full crash-recoverable completion. Any post-review change to reviewed code,
185
283
  tests, or instructions needs fresh evidence under `runtime/review.md`, including
186
284
  changes suggested during N5 lesson recording.
187
285
 
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ // CI 分片:把测试文件按实测耗时分到 N 份,每个文件恰好落在一份里。
3
+ // 以前按排序后的序号轮流分,最慢的几个文件挤进同一份,那一份比别的慢近一倍。
4
+ // 现在用 ci-test-weights.json 里记的秒数做贪心分配(最重的先放进当前最轻的一份),
5
+ // 表里没有的新文件按表中位数计,所以新增测试不用先改表也会被分到某一份。
6
+ // 只决定哪份跑哪些文件,不跳过、不过滤任何文件。
7
+ // 用法:node scripts/ci-test-shards.mjs --shards 4 --index 0 scripts/a.test.mjs scripts/b.test.mjs ...
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import {fileURLToPath} from 'node:url';
11
+
12
+ const weightsFile=fileURLToPath(new URL('./ci-test-weights.json',import.meta.url));
13
+
14
+ export function readWeights(file=weightsFile){
15
+ const raw=JSON.parse(fs.readFileSync(file,'utf8'));
16
+ const weights=new Map();
17
+ for(const [name,seconds] of Object.entries(raw.seconds??{})){
18
+ if(!Number.isFinite(seconds)||seconds<0)throw new Error(`invalid weight for ${name}`);
19
+ weights.set(name,seconds);
20
+ }
21
+ return weights;
22
+ }
23
+
24
+ export function median(values){
25
+ const sorted=[...values].sort((a,b)=>a-b);
26
+ if(sorted.length===0)return 1;
27
+ const mid=Math.floor(sorted.length/2);
28
+ return sorted.length%2?sorted[mid]:(sorted[mid-1]+sorted[mid])/2;
29
+ }
30
+
31
+ // Deterministic longest-processing-time assignment: heaviest file first, ties by
32
+ // name; each goes to the currently lightest shard, ties by lowest shard index.
33
+ export function assignShards(files,shards,weights){
34
+ if(!Number.isInteger(shards)||shards<1)throw new Error('shards must be a positive integer');
35
+ const unique=[...new Set(files)];
36
+ if(unique.length!==files.length)throw new Error('duplicate test file');
37
+ const fallback=median(weights.values());
38
+ const weightOf=file=>weights.get(path.basename(file))??fallback;
39
+ const order=[...files].sort((a,b)=>weightOf(b)-weightOf(a)||(a<b?-1:a>b?1:0));
40
+ const result=Array.from({length:shards},()=>({files:[],seconds:0}));
41
+ for(const file of order){
42
+ let target=0;
43
+ for(let i=1;i<shards;i++)if(result[i].seconds<result[target].seconds)target=i;
44
+ result[target].files.push(file);result[target].seconds+=weightOf(file);
45
+ }
46
+ for(const shard of result)shard.files.sort();
47
+ return result;
48
+ }
49
+
50
+ function main(argv){
51
+ let shards=null,index=null;const files=[];
52
+ for(let i=0;i<argv.length;i++){
53
+ if(argv[i]==='--shards')shards=Number(argv[++i]);
54
+ else if(argv[i]==='--index')index=Number(argv[++i]);
55
+ else if(argv[i]==='--summary')index='summary';
56
+ else files.push(argv[i]);
57
+ }
58
+ const result=assignShards(files,shards,readWeights());
59
+ if(index==='summary'){
60
+ result.forEach((shard,i)=>process.stdout.write(`shard ${i}: ${shard.files.length} files, ~${Math.round(shard.seconds)}s\n`));
61
+ return;
62
+ }
63
+ if(!Number.isInteger(index)||index<0||index>=shards)throw new Error('index must be in [0, shards)');
64
+ for(const file of result[index].files)process.stdout.write(file+'\n');
65
+ }
66
+
67
+ if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))main(process.argv.slice(2));
@@ -0,0 +1,64 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import {spawnSync} from 'node:child_process';
5
+ import {fileURLToPath} from 'node:url';
6
+ import {assignShards,median,readWeights} from './ci-test-shards.mjs';
7
+
8
+ const script=fileURLToPath(new URL('./ci-test-shards.mjs',import.meta.url));
9
+ const scriptsDir=fileURLToPath(new URL('.',import.meta.url));
10
+ const realFiles=fs.readdirSync(scriptsDir).filter(name=>name.endsWith('.test.mjs')).map(name=>`scripts/${name}`).sort();
11
+
12
+ test('every test file lands in exactly one shard for any shard count',()=>{
13
+ const weights=readWeights();
14
+ for(let shards=1;shards<=6;shards++){
15
+ const result=assignShards(realFiles,shards,weights);
16
+ assert.equal(result.length,shards);
17
+ const all=result.flatMap(shard=>shard.files);
18
+ assert.equal(all.length,realFiles.length);
19
+ assert.deepEqual([...all].sort(),realFiles);
20
+ }
21
+ });
22
+
23
+ test('assignment is deterministic and independent of input order',()=>{
24
+ const weights=readWeights();
25
+ const forward=assignShards(realFiles,4,weights),backward=assignShards([...realFiles].reverse(),4,weights);
26
+ assert.deepEqual(backward,forward);
27
+ });
28
+
29
+ test('heaviest-first assignment keeps every shard within one file of the average',()=>{
30
+ const weights=new Map([['a.test.mjs',100],['b.test.mjs',90],['c.test.mjs',50],['d.test.mjs',40],['e.test.mjs',10],['f.test.mjs',10]]);
31
+ const files=[...weights.keys()].map(name=>`scripts/${name}`);
32
+ const result=assignShards(files,2,weights);
33
+ assert.deepEqual(result.map(shard=>shard.seconds),[150,150]);
34
+ const real=readWeights(),shards=assignShards(realFiles,4,real);
35
+ const total=shards.reduce((sum,shard)=>sum+shard.seconds,0);
36
+ const heaviest=Math.max(...realFiles.map(file=>real.get(file.slice('scripts/'.length))??median(real.values())));
37
+ for(const shard of shards)assert(shard.seconds<=total/4+heaviest,`${shard.seconds} > ${total/4}+${heaviest}`);
38
+ });
39
+
40
+ test('a file missing from the weight table counts as the median and is still scheduled',()=>{
41
+ const weights=new Map([['a.test.mjs',1],['b.test.mjs',5],['c.test.mjs',9]]);
42
+ assert.equal(median(weights.values()),5);
43
+ const result=assignShards(['scripts/a.test.mjs','scripts/b.test.mjs','scripts/c.test.mjs','scripts/new.test.mjs'],2,weights);
44
+ // c(9) -> 0, b(5) -> 1, new(median 5) -> 1, a(1) -> 0.
45
+ assert.deepEqual(result.map(shard=>shard.files),[['scripts/a.test.mjs','scripts/c.test.mjs'],['scripts/b.test.mjs','scripts/new.test.mjs']]);
46
+ assert.deepEqual(result.map(shard=>shard.seconds),[10,10]);
47
+ });
48
+
49
+ test('duplicate files and invalid shard counts are refused',()=>{
50
+ assert.throws(()=>assignShards(['scripts/a.test.mjs','scripts/a.test.mjs'],2,new Map()),/duplicate/);
51
+ for(const shards of [0,1.5,NaN])assert.throws(()=>assignShards(['scripts/a.test.mjs'],shards,new Map()),/positive integer/);
52
+ });
53
+
54
+ test('CLI prints exactly its shard and the shards together cover the input',()=>{
55
+ const printed=[];
56
+ for(let index=0;index<4;index++){
57
+ const run=spawnSync(process.execPath,[script,'--shards','4','--index',String(index),...realFiles],{encoding:'utf8'});
58
+ assert.equal(run.status,0,run.stderr);
59
+ printed.push(...run.stdout.trim().split('\n').filter(Boolean));
60
+ }
61
+ assert.deepEqual(printed.sort(),realFiles);
62
+ const bad=spawnSync(process.execPath,[script,'--shards','4','--index','4',...realFiles],{encoding:'utf8'});
63
+ assert.notEqual(bad.status,0);assert.match(bad.stderr,/index must be/);
64
+ });