@aibyzero/cm-workflow 0.17.0 → 0.18.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 (372) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +27 -0
  3. package/CHANGELOG.md +230 -1
  4. package/CONTRIBUTING.md +47 -0
  5. package/README.md +21 -3
  6. package/THIRD_PARTY_NOTICES.md +13 -0
  7. package/VERSION +1 -1
  8. package/compat/claude-commands/cm-challenge.md +3 -0
  9. package/docs/architecture.md +40 -13
  10. package/docs/cm-control-policy-v2.md +127 -9
  11. package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
  12. package/docs/installation.md +310 -4
  13. package/docs/js-workflow-control.md +153 -16
  14. package/docs/live-evidence-drivers.md +28 -4
  15. package/docs/out-of-scope/README.md +25 -0
  16. package/docs/out-of-scope/background-supervisor.md +32 -0
  17. package/docs/reviewed-integration.md +48 -0
  18. package/docs/user-guide.md +50 -21
  19. package/install-codex.sh +331 -18
  20. package/install.ps1 +28 -2
  21. package/install.sh +321 -17
  22. package/package.json +2 -1
  23. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  24. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  25. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  26. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  27. package/runtime/js/cm-ai/claude-review-stream.mjs +94 -21
  28. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  29. package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
  30. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  31. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  32. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  33. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  34. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  35. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  36. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  37. package/runtime/js/cm-ai/control-policy.mjs +24 -6
  38. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  39. package/runtime/js/cm-ai/drive-core.mjs +236 -34
  40. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  41. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  42. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  43. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  44. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  45. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  46. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  47. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  48. package/runtime/js/cm-ai/host-check.mjs +14 -6
  49. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  50. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  51. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  52. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  53. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  54. package/runtime/js/cm-ai/host-session.mjs +42 -9
  55. package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
  56. package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
  57. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  58. package/runtime/js/cm-ai/host.mjs +1 -1
  59. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  60. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  61. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  62. package/runtime/js/cm-ai/operator-guidance.mjs +63 -30
  63. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  64. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  65. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  66. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  67. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  68. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  69. package/runtime/js/cm-ai/review-package.mjs +79 -7
  70. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  71. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  72. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  73. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  74. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  75. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  76. package/runtime/js/cm-ai/task-runner.mjs +247 -41
  77. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  78. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  79. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  80. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  81. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  82. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  83. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  84. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  85. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  86. package/runtime/js/cm-fix/dossier.mjs +8 -2
  87. package/runtime/js/cm-fix/execution.mjs +578 -100
  88. package/runtime/js/cm-fix/final-review.mjs +39 -8
  89. package/runtime/js/cm-fix/finish.mjs +15 -11
  90. package/runtime/js/cm-fix/host-review.mjs +65 -10
  91. package/runtime/js/cm-fix/host.mjs +35 -12
  92. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  93. package/runtime/js/cm-fix/metrics.mjs +18 -5
  94. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  95. package/runtime/js/cm-fix/regression.mjs +16 -7
  96. package/runtime/js/cm-fix/repair.mjs +29 -8
  97. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  98. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  99. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  100. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  101. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  102. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  103. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  104. package/runtime/js/cm-fix/start.mjs +6 -3
  105. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  106. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  107. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  108. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  109. package/runtime/js/cm-prd/analysis.mjs +13 -9
  110. package/runtime/js/cm-prd/change.mjs +37 -16
  111. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  112. package/runtime/js/cm-prd/draft.mjs +31 -3
  113. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  114. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  115. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  116. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  117. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  118. package/runtime/js/cm-prd/self-check.mjs +125 -6
  119. package/runtime/js/cm-prd/session.mjs +30 -1
  120. package/runtime/js/cm-prd/summary.mjs +38 -17
  121. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  122. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  123. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  124. package/runtime/js/cm-security/scan.mjs +1 -1
  125. package/runtime/js/commander/decision.mjs +44 -0
  126. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  127. package/runtime/js/commander/ledger.mjs +265 -0
  128. package/runtime/js/commander/preflight.mjs +107 -0
  129. package/runtime/js/notify-later.mjs +13 -0
  130. package/runtime/js/notify-send.mjs +6 -2
  131. package/runtime/js/notify.mjs +570 -63
  132. package/runtime/js/review-findings.mjs +38 -0
  133. package/runtime/js/session-boundary.mjs +56 -0
  134. package/runtime/js/session-handoff.mjs +68 -0
  135. package/runtime/js/spec-task-line.mjs +27 -13
  136. package/runtime/js/specs-status.mjs +1 -1
  137. package/runtime/js/task-scope.mjs +197 -0
  138. package/runtime/logging.md +6 -1
  139. package/runtime/model-efficiency.md +69 -10
  140. package/runtime/orchestration.md +3 -1
  141. package/runtime/project-learning.md +2 -0
  142. package/runtime/review.md +12 -2
  143. package/runtime/test-contract.md +1 -0
  144. package/scripts/ci-test-weights.json +3 -0
  145. package/scripts/cm-ai-admission.mjs +11 -5
  146. package/scripts/cm-ai-admission.test.mjs +23 -2
  147. package/scripts/cm-ai-batch-drive.mjs +79 -18
  148. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  149. package/scripts/cm-ai-batch-host.mjs +38 -9
  150. package/scripts/cm-ai-batch-host.test.mjs +27 -14
  151. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  152. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  153. package/scripts/cm-ai-batch-plan.mjs +52 -0
  154. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  155. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  156. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  157. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  158. package/scripts/cm-ai-batch-run.mjs +483 -63
  159. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  160. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  161. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  162. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  163. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  164. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  165. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  166. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  167. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  168. package/scripts/cm-ai-control-policy.test.mjs +82 -0
  169. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  170. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  171. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  172. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  173. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  174. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +3 -2
  175. package/scripts/cm-ai-drive.mjs +73 -17
  176. package/scripts/cm-ai-drive.test.mjs +37 -5
  177. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  178. package/scripts/cm-ai-host-fixture.mjs +9 -6
  179. package/scripts/cm-ai-host-protected.test.mjs +1 -1
  180. package/scripts/cm-ai-host.mjs +60 -19
  181. package/scripts/cm-ai-host.test.mjs +15 -0
  182. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  183. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  184. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  185. package/scripts/cm-ai-integration-preview.mjs +41 -0
  186. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  187. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  188. package/scripts/cm-ai-operator-guidance.test.mjs +71 -0
  189. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  190. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  191. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  192. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  193. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  194. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  195. package/scripts/cm-ai-review-timeout.test.mjs +20 -0
  196. package/scripts/cm-ai-run.mjs +88 -21
  197. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  198. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  199. package/scripts/cm-ai-supersede.test.mjs +28 -0
  200. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  201. package/scripts/cm-announce-hook.mjs +35 -8
  202. package/scripts/cm-announce-hook.test.mjs +25 -0
  203. package/scripts/cm-challenge.test.mjs +61 -0
  204. package/scripts/cm-check-drive-files.mjs +2 -2
  205. package/scripts/cm-check-host.test.mjs +1 -1
  206. package/scripts/cm-check-runtime.sh +58 -1
  207. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  208. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  209. package/scripts/cm-claude-probe.test.mjs +26 -0
  210. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  211. package/scripts/cm-claude-review-stream.test.mjs +49 -0
  212. package/scripts/cm-claude-worker.test.mjs +16 -0
  213. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  214. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  215. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  216. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  217. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  218. package/scripts/cm-commander-ledger.test.mjs +260 -0
  219. package/scripts/cm-commander-p2.test.mjs +295 -0
  220. package/scripts/cm-commander-preflight.mjs +84 -0
  221. package/scripts/cm-commander.mjs +116 -0
  222. package/scripts/cm-config-lock.mjs +35 -0
  223. package/scripts/cm-controlled-correction.test.mjs +10 -1
  224. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  225. package/scripts/cm-display-task-id.test.mjs +41 -0
  226. package/scripts/cm-drive-liveness.test.mjs +83 -0
  227. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  228. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  229. package/scripts/cm-external-batch-host.test.mjs +12 -9
  230. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  231. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  232. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  233. package/scripts/cm-failover.mjs +48 -10
  234. package/scripts/cm-failover.test.mjs +46 -0
  235. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  236. package/scripts/cm-fix-command-correction.mjs +17 -0
  237. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  238. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  239. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  240. package/scripts/cm-fix-drive.mjs +33 -5
  241. package/scripts/cm-fix-drive.test.mjs +49 -0
  242. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  243. package/scripts/cm-fix-host-review.test.mjs +21 -9
  244. package/scripts/cm-fix-host.mjs +26 -8
  245. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  246. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  247. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  248. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  249. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  250. package/scripts/cm-fix-review-preflight.mjs +24 -0
  251. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  252. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  253. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  254. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  255. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  256. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  257. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  258. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  259. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  260. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  261. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  262. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  263. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  264. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  265. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  266. package/scripts/cm-host-diagnostic.test.mjs +33 -0
  267. package/scripts/cm-host-liveness.test.mjs +150 -0
  268. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  269. package/scripts/cm-host-replay.test.mjs +176 -0
  270. package/scripts/cm-host-stage-observer.test.mjs +41 -0
  271. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  272. package/scripts/cm-install-manifest.sh +351 -0
  273. package/scripts/cm-live-evidence.test.mjs +59 -1
  274. package/scripts/cm-log-event.mjs +61 -10
  275. package/scripts/cm-log-event.test.mjs +121 -1
  276. package/scripts/cm-matt-skills.mjs +576 -0
  277. package/scripts/cm-matt-skills.test.mjs +550 -0
  278. package/scripts/cm-notify-command.test.mjs +42 -10
  279. package/scripts/cm-notify.mjs +14 -10
  280. package/scripts/cm-notify.test.mjs +625 -75
  281. package/scripts/cm-patrol.mjs +4 -1
  282. package/scripts/cm-patrol.test.mjs +23 -5
  283. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  284. package/scripts/cm-prd-completion.test.mjs +56 -13
  285. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  286. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  287. package/scripts/cm-prd-draft.test.mjs +1 -1
  288. package/scripts/cm-prd-drive.mjs +13 -6
  289. package/scripts/cm-prd-drive.test.mjs +46 -2
  290. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  291. package/scripts/cm-prd-host.mjs +10 -5
  292. package/scripts/cm-prd-host.test.mjs +4 -2
  293. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  294. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  295. package/scripts/cm-prd-revision.test.mjs +1 -1
  296. package/scripts/cm-prd-self-check-revision.test.mjs +16 -1
  297. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  298. package/scripts/cm-prd-self-check.test.mjs +105 -5
  299. package/scripts/cm-prd-session-recovery.test.mjs +5 -3
  300. package/scripts/cm-prd-summary.test.mjs +55 -3
  301. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  302. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  303. package/scripts/cm-refactor-drive.mjs +2 -1
  304. package/scripts/cm-refactor-drive.test.mjs +9 -0
  305. package/scripts/cm-release-smoke.sh +3 -15
  306. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  307. package/scripts/cm-skill-hints-exam.mjs +149 -0
  308. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  309. package/scripts/cm-skill-hints.exam.json +706 -0
  310. package/scripts/cm-skill-hints.json +119 -0
  311. package/scripts/cm-skill-hints.mjs +669 -0
  312. package/scripts/cm-skill-hints.test.mjs +831 -0
  313. package/scripts/cm-skill-judge.mjs +181 -0
  314. package/scripts/cm-skill-judge.test.mjs +255 -0
  315. package/scripts/cm-specs-status.test.mjs +4 -2
  316. package/scripts/cm-start-check.mjs +208 -0
  317. package/scripts/cm-start-check.test.mjs +321 -0
  318. package/scripts/cm-task-gate.mjs +150 -29
  319. package/scripts/cm-task-gate.test.mjs +73 -1
  320. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  321. package/scripts/cm-task-scope.test.mjs +308 -0
  322. package/scripts/cm-test-suite.mjs +109 -0
  323. package/scripts/cm-test-suite.test.mjs +162 -0
  324. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  325. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  326. package/scripts/cm-workflow-config.mjs +12 -2
  327. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  328. package/scripts/fixtures/host-diagnostic.mjs +33 -0
  329. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  330. package/scripts/scan-public-safety.py +1 -0
  331. package/scripts/session-boundary.test.mjs +170 -0
  332. package/scripts/test-npm-install.py +14 -3
  333. package/scripts/test-shell-compat.sh +2 -0
  334. package/scripts/validate-public-repo.py +1 -0
  335. package/scripts/validate-test-cases.mjs +3 -2
  336. package/skills/cm-ai/SKILL.md +5 -2
  337. package/skills/cm-ai/references/N4-review.md +2 -1
  338. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  339. package/skills/cm-ai/references/N8-finish.md +22 -0
  340. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  341. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  342. package/skills/cm-ai/references/js-host.md +89 -17
  343. package/skills/cm-challenge/SKILL.md +65 -0
  344. package/skills/cm-challenge/evals/README.md +18 -0
  345. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  346. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  347. package/skills/cm-challenge/references/examples.md +15 -0
  348. package/skills/cm-check/SKILL.md +5 -0
  349. package/skills/cm-check/references/js-host.md +2 -0
  350. package/skills/cm-fix/SKILL.md +12 -3
  351. package/skills/cm-fix/references/command-correction.md +67 -0
  352. package/skills/cm-fix/references/isolated-review.md +54 -0
  353. package/skills/cm-fix/references/js-host.md +62 -2
  354. package/skills/cm-fix/references/test-type-correction.md +72 -0
  355. package/skills/cm-fix/references/verification-recovery.md +114 -0
  356. package/skills/cm-idea/SKILL.md +2 -0
  357. package/skills/cm-idea/references/js-host.md +2 -0
  358. package/skills/cm-notify/SKILL.md +2 -0
  359. package/skills/cm-prd/SKILL.md +12 -8
  360. package/skills/cm-prd/references/brownfield.md +8 -1
  361. package/skills/cm-prd/references/change-mode.md +6 -0
  362. package/skills/cm-prd/references/greenfield.md +4 -0
  363. package/skills/cm-prd/references/js-host.md +4 -2
  364. package/skills/cm-prd/references/spec-self-check.md +5 -1
  365. package/skills/cm-refactor/SKILL.md +8 -0
  366. package/skills/cm-refactor/references/js-host.md +2 -0
  367. package/skills/cm-test/SKILL.md +4 -0
  368. package/templates/dashboard/dashboard.html +2 -2
  369. package/templates/pixel/cm-pixel.html +1 -1
  370. package/templates/pixel/cm-pixel.sh +1 -1
  371. package/templates/pixel/dev/template.html +1 -1
  372. package/templates/statusline/cm-statusline.sh +1 -1
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import {readBatchExecutionPolicy,freezeBatchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
3
+ import {batchSegments,batchMemberWorktree} from '../runtime/js/cm-ai/batch-location.mjs';
3
4
  import {readBatchExternalModels,freezeBatchExternalModels,batchModelsFile} from '../runtime/js/cm-ai/external-group-models.mjs';
4
5
  // Current-conversation transport for the existing batch driver, not a new loop.
5
6
  import fs from 'node:fs';
@@ -89,7 +90,7 @@ export function migrateLegacyPreflightCache(batch,review,runtime){
89
90
  try{const a=fs.lstatSync(file),b=fs.lstatSync(destination);interrupted=a.dev===b.dev&&a.ino===b.ino;}catch(error){if(error.code!=='ENOENT')throw error;}
90
91
  const source=pinned(file,interrupted?2:1);
91
92
  if(source===null)refuse(`${entry.name} 在核对时消失`);
92
- const cwd=path.resolve(batch.codeProject,'..','.cm-worktrees',batch.batchId.slice(0,8),taskId);
93
+ const cwd=batchMemberWorktree({codeProject:batch.codeProject,taskId,segments:batchSegments({specsDir:batch.specsDir,batchId:batch.batchId})});
93
94
  const options={cwd,model:review.model,disabledSkills:review.disabledSkills,promptTransport:'stdin'};
94
95
  let cached;try{cached=readConversationReviewConfigurationValue(JSON.parse(source.bytes.toString('utf8')),null);}
95
96
  catch{refuse(`${entry.name} 不是预检缓存格式`);}
@@ -179,6 +180,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
179
180
  const {batch,workflows,bootstraps=null}=bundle;need(Array.isArray(batch.tasks),'invalid_batch_config');
180
181
  need(workflows!==null&&typeof workflows==='object'&&!Array.isArray(workflows),'invalid_batch_config');
181
182
  const keys=batch.tasks.map(task=>`${task.feature}/${task.taskId}`);
183
+ // Grammar 3 execution table (batch-plan.mjs; validated again by createCmAiBatch): the
184
+ // members the current session develops even when a provider develops the rest.
185
+ const sessionMembers=new Set(batch.memberDevelopment!==null&&typeof batch.memberDevelopment==='object'?Object.keys(batch.memberDevelopment):[]);
182
186
  if(bootstraps!==null){
183
187
  need(typeof bootstraps==='object'&&!Array.isArray(bootstraps),'invalid_bootstrap_config');
184
188
  for(const [key,config] of Object.entries(bootstraps)){
@@ -245,12 +249,14 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
245
249
  }
246
250
  else need(false,'invalid_arguments');
247
251
  }
252
+ if([...developments.keys()].some(key=>sessionMembers.has(key)))throw Object.assign(new Error('invalid_arguments'),
253
+ {code:'invalid_arguments',reason:'--allow-provider-development 不能授权批次执行表里由会话开发的成员'});
248
254
  if(controlPolicy){
249
255
  allowQa=controlPolicy.qa==='run';allowBootstrap=controlPolicy.bootstrap==='write';
250
256
  need((controlPolicy.development==='provider')===Boolean(providerConfig),'invalid_arguments');
251
257
  need(controlPolicy.bootstrap!=='write'||bootstraps!==null,'invalid_arguments');
252
258
  need(bootstraps===null||controlPolicy.bootstrap==='write','invalid_arguments');
253
- if(providerConfig)for(const key of keys)developments.set(key,1);
259
+ if(providerConfig)for(const key of keys)if(!sessionMembers.has(key))developments.set(key,1);
254
260
  need(!rerunUnknownQa&&!rerunBlockedQa,'supersede_unavailable');
255
261
  }
256
262
  const started=keys.some(key=>fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,key),'state.json')));
@@ -268,6 +274,15 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
268
274
  need(!Object.hasOwn(providerConfig,'effort')||providerConfig.effort===pair.effort,'external_model_configuration_conflict');
269
275
  providerConfig={...providerConfig,...pair};
270
276
  }
277
+ need(!sessionMembers.size||!externalModels&&!executionPolicy,'session_member_unsupported_config');
278
+ // A v2 provider batch: a session member's coder is this host, so it must be the
279
+ // declared coder; it is reviewed by the declared reviewer like the provider members
280
+ // (reviewRuntime), never by the host itself.
281
+ const sessionReviewRuntime=controlPolicy?.development==='provider'&&sessionMembers.size?routes.reviewerRuntime:null;
282
+ if(sessionReviewRuntime!==null&&routes.coderRuntime!==(runtime??'codex'))
283
+ throw Object.assign(new Error('session_coder_runtime_mismatch'),{code:'session_coder_runtime_mismatch',
284
+ reason:`成员 ${[...sessionMembers].join(', ')} 由当前会话开发,宿主运行时必须是项目声明的写代码方 ${routes.coderRuntime};`
285
+ +`现在是 ${runtime??'codex(未传 --runtime 时的缺省值)'}。在 PLAN.permissions 加 --runtime ${routes.coderRuntime}`});
271
286
  review=review===null?null:readConversationReviewConfiguration(review,externalModels?.providers[routes.reviewerRuntime]??null);
272
287
  need(!developments.size||providerConfig!==null,'protected_configuration_required');
273
288
  // Same launch-time assertion as the single-task host, evaluated across every
@@ -302,14 +317,23 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
302
317
  let reconciling=false;
303
318
  const driver=createCmAiBatch({configuration:{...batch,...(controlPolicy?{controlPolicy}:{}),...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
304
319
  runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
305
- rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),
306
- executionFor:async(definition,{parallelMember=false}={})=>{
320
+ rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),workflows,
321
+ executionFor:async(definition,{parallelMember=false,soloMember=false}={})=>{
307
322
  await freezeBatchExecutionPolicy(batch,executionPolicy);
308
323
  freezeBatchExternalModels(batch,externalModels);
309
324
  const key=`${definition.feature}/${definition.identity.taskId}`;
310
- const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,externalModels?routes.reviewerRuntime:runtime??'codex',externalModels?.providers[routes.reviewerRuntime]??null,!reconciling,Boolean(executionPolicy)):review;
325
+ // A parallel member's review loopback runs on the reviewer the factory will bind: the
326
+ // declared one for a provider-developed member (the host runtime may be the coder
327
+ // there), else the one this member always had (host runtime, or the external route).
328
+ const memberReviewer=developments.has(key)?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime??'codex').reviewerRuntime
329
+ :externalModels?routes.reviewerRuntime:runtime??'codex';
330
+ const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,memberReviewer,externalModels?.providers[routes.reviewerRuntime]??null,!reconciling,Boolean(executionPolicy)):review;
311
331
  const execution=createConversationExecution(definition,hostContextId,parallelMember?memberBridge:bridge,memberReview,null,workflows[key],allowQa,runtime??'codex',
312
- {parallelMember,...(controlPolicy?{controlPolicy}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
332
+ {parallelMember,...(soloMember?{soloMember}:{}),...(controlPolicy?{controlPolicy}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),
333
+ // A batch without an execution table keeps its exact projection.
334
+ batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}
335
+ :Object.hasOwn(batch,'memberDevelopment')?{workflows,bootstraps,memberDevelopment:batch.memberDevelopment}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
336
+ ...(sessionMembers.has(key)?{memberDevelopment:'session',...(sessionReviewRuntime!==null?{reviewRuntime:sessionReviewRuntime}:{})}:{}),
313
337
  // A protected CLI config also protects unauthorized tasks: they stay on the
314
338
  // current-session transport but with the same sandbox checks (protected-text edits).
315
339
  ...(protection?{protection}:providerConfig?{protection:{checkCommands:providerConfig.checkCommands,timeoutMs:providerConfig.timeoutMs}}:{}),
@@ -324,8 +348,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
324
348
  const host={async handle(request){
325
349
  try{
326
350
  reconciling=request.operation==='reconcile_review';const result=await driver.handle(request);
327
- if(controlPolicy&&request.operation==='status'&&result.state!=='running')
328
- return {...result,controlTarget:await driver.controlTarget()};
351
+ if(controlPolicy&&request.operation==='status'&&result.state!=='running'){
352
+ // A merge conflict stays reported when its member cannot be targeted (e.g.
353
+ // its worktree is gone); the target is marked unavailable, not invented.
354
+ if(result.code!=='merge_conflict')return {...result,controlTarget:await driver.controlTarget()};
355
+ try{return {...result,controlTarget:await driver.controlTarget()};}
356
+ catch(cause){return {...result,controlTargetUnavailable:{code:safeCode(cause)}};}
357
+ }
329
358
  return result;
330
359
  }
331
360
  catch(cause){const reason=boundedReason(cause);return {outcome:'blocked',code:safeCode(cause),...(reason?{reason}:{})};}
@@ -334,7 +363,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
334
363
  try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
335
364
  finally{if(rawMode)input.setRawMode(false);}
336
365
  return 0;
337
- }catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope',...Object.keys(UNSUPPORTED_REASON)].includes(code)
366
+ }catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope','session_coder_runtime_mismatch',...Object.keys(UNSUPPORTED_REASON)].includes(code)
338
367
  &&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
339
368
  finally{bridge?.close();}
340
369
  }
@@ -1,4 +1,6 @@
1
+ import {hostDiagnostic} from './fixtures/host-diagnostic.mjs';
1
2
  import test from 'node:test';
3
+ import {batchSegment} from '../runtime/js/cm-ai/batch-location.mjs';
2
4
  import assert from 'node:assert/strict';
3
5
  import fs from 'node:fs';
4
6
  import os from 'node:os';
@@ -83,24 +85,33 @@ function execute(f,{cancel=false,args=[],operations=[{operation:'advance',reques
83
85
  return new Promise((resolve,reject)=>{
84
86
  const child=spawn(process.execPath,[cli,...f.args,...args],
85
87
  {env:f.env,stdio:['pipe','pipe','pipe']});
86
- let buffer='',stderr='',sessionId;const calls=[],rows=[];
87
- const timer=setTimeout(()=>{child.kill('SIGTERM');reject(Error('batch host timeout'));},Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
88
- child.stderr.on('data',part=>{stderr+=part;});child.once('error',reject);
89
- const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
88
+ let buffer='',stderr='',sessionId;const calls=[],rows=[],pendingControls=new Set();
89
+ let finalOperationReceived=false,closeRequested=false;
90
+ // Cancellation can finish the original advance before its status/cancel
91
+ // handlers return. Await those replies before requesting an idle close.
92
+ const closeWhenIdle=()=>{
93
+ if(finalOperationReceived&&pendingControls.size===0&&!closeRequested){
94
+ closeRequested=true;send({type:'host_close',sessionId});
95
+ }
96
+ };
97
+ const timeoutMs=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000),trace=hostDiagnostic(child,{timeoutMs});
98
+ const timer=setTimeout(()=>{child.kill('SIGTERM');reject(trace.attach(Error('batch host timeout')));},timeoutMs);
99
+ child.stderr.on('data',part=>{stderr+=part;});child.once('error',error=>reject(trace.attach(error)));
100
+ const send=value=>{trace.send(value);child.stdin.write(JSON.stringify(value)+'\n');};
90
101
  const respond=(row,result)=>send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
91
102
  child.stdout.on('data',part=>{
92
103
  buffer+=part;let newline;
93
104
  while((newline=buffer.indexOf('\n'))!==-1){
94
105
  const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);if(!line)continue;
95
106
  try{
96
- const row=JSON.parse(line);rows.push(row);
107
+ const row=JSON.parse(line);rows.push(row);trace.receive(row);
97
108
  if(row.type==='host_ready')sessionId=row.sessionId;
98
109
  if(row.type==='host_request'){
99
110
  const payload=row.payload,identity=payload.identity??payload.request.identity;
100
111
  const cwd=f.parallel&&identity.taskId!=='T-003'
101
- ?path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),identity.taskId):f.codeProject;
112
+ ?path.join(f.root,'.cm-worktrees',batchSegment(f.batch.batchId),identity.taskId):f.codeProject;
102
113
  calls.push(`${identity.taskId}:${row.kind}`);
103
- if(cancel){send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
114
+ if(cancel){pendingControls.add('status');pendingControls.add('cancel');send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
104
115
  if(row.kind==='develop'){
105
116
  assert.equal(payload.request.provider,f.runtime);
106
117
  const n=Number(identity.taskId.slice(-1));
@@ -133,12 +144,14 @@ function execute(f,{cancel=false,args=[],operations=[{operation:'advance',reques
133
144
  }
134
145
  const index=operations.findIndex(item=>item.requestId===row.requestId);
135
146
  if(index>=0&&(row.result||row.error)){
136
- if(index+1<operations.length)send(operations[index+1]);else send({type:'host_close',sessionId});
147
+ if(index+1<operations.length)send(operations[index+1]);else finalOperationReceived=true;
137
148
  }
138
- }catch(error){clearTimeout(timer);child.kill('SIGTERM');reject(error);}
149
+ if(row.result||row.error)pendingControls.delete(row.requestId);
150
+ closeWhenIdle();
151
+ }catch(error){clearTimeout(timer);child.kill('SIGTERM');reject(trace.attach(error));}
139
152
  }
140
153
  });
141
- child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,
154
+ child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,diagnostic:trace.snapshot(),
142
155
  results:Object.fromEntries(operations.map(item=>[item.requestId,rows.find(row=>row.requestId===item.requestId)?.result])),
143
156
  result:rows.find(row=>row.requestId===operations.at(-1).requestId)?.result});});
144
157
  send(operations[0]);
@@ -227,7 +240,7 @@ test('parallel member loopback preflights bind worktree cwd, stop before start a
227
240
  try{
228
241
  f.batch.tasks=[1,2,3].map(n=>({feature:'1.work',taskId:`T-00${n}`,scope:[`task${n}.mjs`],requirements:['requirements.md']}));
229
242
  f.batch.parallel=[['1.work/T-001','1.work/T-002']];
230
- fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
243
+ fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n - 范围: `task1.mjs`\n- [ ] T-002: second\n - 范围: `task2.mjs`\n- [ ] T-003: final\n - 范围: `task3.mjs`\n\n- T-003 依赖 T-001, T-002\n');
231
244
  fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir)}));
232
245
  const original=JSON.parse(fs.readFileSync(f.config,'utf8')).workflows['1.work/T-001'];
233
246
  fs.writeFileSync(f.config,JSON.stringify({batch:f.batch,workflows:Object.fromEntries(f.batch.tasks.map(task=>[`1.work/${task.taskId}`,original]))}));
@@ -260,7 +273,7 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
260
273
  const directory=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
261
274
  const receipts=[1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8'));
262
275
  for(const [index,bytes] of receipts.entries()){
263
- const config=JSON.parse(bytes),cwd=path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),`T-00${index+1}`);
276
+ const config=JSON.parse(bytes),cwd=path.join(f.root,'.cm-worktrees',batchSegment(f.batch.batchId),`T-00${index+1}`);
264
277
  assert(preflightMatches(config.preflight,{cwd,model:'fixture',disabledSkills:[],promptTransport:'stdin'}));
265
278
  assert(!preflightMatches(config.preflight,{cwd:f.codeProject,model:'fixture',disabledSkills:[],promptTransport:'stdin'}));
266
279
  assert.equal(config.preflight.real_model_requests,0);assert.equal(config.preflight.listener_closed,true);
@@ -286,13 +299,13 @@ function legacyParallelFixture(){
286
299
  const f=fixture();f.parallel=true;
287
300
  f.batch.tasks=[1,2,3].map(n=>({feature:'1.work',taskId:`T-00${n}`,scope:[`task${n}.mjs`],requirements:['requirements.md']}));
288
301
  f.batch.parallel=[['1.work/T-001','1.work/T-002']];
289
- fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
302
+ fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n - 范围: `task1.mjs`\n- [ ] T-002: second\n - 范围: `task2.mjs`\n- [ ] T-003: final\n - 范围: `task3.mjs`\n\n- T-003 依赖 T-001, T-002\n');
290
303
  fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir)}));
291
304
  const original=JSON.parse(fs.readFileSync(f.config,'utf8')).workflows['1.work/T-001'];
292
305
  fs.writeFileSync(f.config,JSON.stringify({batch:f.batch,workflows:Object.fromEntries(f.batch.tasks.map(task=>[`1.work/${task.taskId}`,original]))}));
293
306
  f.legacy=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
294
307
  f.current=path.join(f.specsDir,'.reviews','external-preflight',f.batch.batchId);
295
- f.worktree=taskId=>path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),taskId);
308
+ f.worktree=taskId=>path.join(f.root,'.cm-worktrees',batchSegment(f.batch.batchId),taskId);
296
309
  return f;
297
310
  }
298
311
  const legacyReceipt=(f,taskId,extra={})=>JSON.stringify({model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',
@@ -0,0 +1,36 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {spawnSync} from 'node:child_process';
7
+ import {mergeLessons} from '../runtime/js/cm-ai/cm-ai-learning-writer.mjs';
8
+
9
+ // Two parallel members each write their lesson into AGENTS.md in their own
10
+ // worktree; the batch merges with AGENTS.md merge=union (cm-ai-batch-run.mjs
11
+ // unionAttributes). When the base has no "## 项目教训" section, both members
12
+ // create it. Git refines the identical added lines as common, so the merged
13
+ // file has one heading and both lessons, not a conflict or a doubled heading.
14
+ const git=(cwd,args)=>{const run=spawnSync('git',['-C',cwd,'-c','user.email=t@example.invalid','-c','user.name=t',...args],{encoding:'utf8'});
15
+ assert.equal(run.status,0,run.stderr);return run.stdout.trim();};
16
+ const lesson=(taskId,trigger)=>({feature:'1.work',identity:{repositoryId:'r',runId:'u',taskId,attempt:1},
17
+ candidates:[{classification:'memory_only',trigger,action:`${trigger} 的做法`,evidence:['src/a.js']}]});
18
+
19
+ for(const base of ['# 项目\n\n规则\n','# 项目\n\n## 项目教训\n\n- 旧教训\n\n## 其他\n\n内容\n'])
20
+ test(`two members' lessons merge into one section (${base.includes('项目教训')?'section exists':'no section yet'})`,t=>{
21
+ const repo=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-learning-union-')));
22
+ t.after(()=>fs.rmSync(repo,{recursive:true,force:true}));
23
+ git(repo,['init','-q','-b','base']);fs.writeFileSync(path.join(repo,'AGENTS.md'),base);git(repo,['add','.']);git(repo,['commit','-qm','base']);
24
+ for(const [branch,taskId,trigger] of [['a','T-002','左边的教训'],['b','T-003','右边的教训']]){
25
+ git(repo,['checkout','-q','-b',branch,'base']);
26
+ fs.writeFileSync(path.join(repo,'AGENTS.md'),mergeLessons(fs.readFileSync(path.join(repo,'AGENTS.md'),'utf8'),lesson(taskId,trigger)));
27
+ git(repo,['commit','-qam',branch]);
28
+ }
29
+ git(repo,['checkout','-q','a']);
30
+ fs.writeFileSync(path.join(repo,'.git','info','attributes'),'AGENTS.md merge=union\n');
31
+ git(repo,['merge','-q','--no-ff','--no-edit','b']);
32
+ const merged=fs.readFileSync(path.join(repo,'AGENTS.md'),'utf8');
33
+ assert.equal(merged.match(/^## 项目教训$/gm).length,1,merged);
34
+ assert.match(merged,/左边的教训/);assert.match(merged,/右边的教训/);
35
+ if(base.includes('## 其他'))assert.ok(merged.indexOf('右边的教训')<merged.indexOf('## 其他'),'lessons stay inside their section');
36
+ });
@@ -0,0 +1,57 @@
1
+ // A batch's member worktrees and branches. New batches derive their segment from
2
+ // the full batchId and record it in batch_start; a batch that started without it
3
+ // keeps the old 8-character prefix so a resume finds what it created.
4
+ import test from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import fs from 'node:fs';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
9
+ import {BATCH_SEGMENT_FIELD,batchSegment,batchSegments,batchMemberWorktree,batchMemberBranch} from '../runtime/js/cm-ai/batch-location.mjs';
10
+
11
+ function specs(t,rows=[]){
12
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-location-')));
13
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
14
+ const specsDir=path.join(root,'specs');fs.mkdirSync(specsDir);
15
+ if(rows.length)fs.writeFileSync(path.join(specsDir,'运行日志.jsonl'),rows.map(row=>JSON.stringify(row)).join('\n')+'\n');
16
+ return {root,specsDir,codeProject:path.join(root,'app')};
17
+ }
18
+ const start=(batchId,extra={})=>({schema_version:1,workflow:'cm-ai',event:'decision',phase:'batch_start',run_id:batchId,...extra});
19
+
20
+ test('two batches sharing an 8-character prefix get different worktrees and branches',t=>{
21
+ const f=specs(t);
22
+ const a=batchSegments({specsDir:f.specsDir,batchId:'batch-20261022-A'}),b=batchSegments({specsDir:f.specsDir,batchId:'batch-20261022-B'});
23
+ assert.notEqual(a.dir,b.dir);assert.notEqual(a.ref,b.ref);
24
+ const where=segments=>[batchMemberWorktree({codeProject:f.codeProject,segments,taskId:'T-001'}),
25
+ batchMemberBranch({segments,feature:'1.work',taskId:'T-001'})];
26
+ assert.notDeepEqual(where(a),where(b));
27
+ assert.equal(where(a)[0],path.join(f.root,'.cm-worktrees',batchSegment('batch-20261022-A'),'T-001'));
28
+ assert.equal(where(a)[1],`cm/${batchSegment('batch-20261022-A')}/work/T-001`);
29
+ });
30
+
31
+ test('a batch that already started without a recorded segment keeps the old prefix',t=>{
32
+ const f=specs(t,[start('v1.2.3-batch')]);
33
+ const segments=batchSegments({specsDir:f.specsDir,batchId:'v1.2.3-batch'});
34
+ assert.equal(segments.legacy,true);
35
+ assert.equal(batchMemberWorktree({codeProject:f.codeProject,segments,taskId:'T-002'}),path.join(f.root,'.cm-worktrees','v1.2.3-b','T-002'));
36
+ assert.equal(batchMemberBranch({segments,feature:'2.search',taskId:'T-002'}),'cm/v1-2-3-b/search/T-002');
37
+ });
38
+
39
+ test('a recorded segment is used only when it is the one the full id derives',t=>{
40
+ const good=specs(t,[start('batch-ok',{[BATCH_SEGMENT_FIELD]:batchSegment('batch-ok')})]);
41
+ assert.deepEqual(batchSegments({specsDir:good.specsDir,batchId:'batch-ok'}),{dir:batchSegment('batch-ok'),ref:batchSegment('batch-ok'),legacy:false});
42
+ for(const forged of ['../../etc','batch-ok',batchSegment('other-batch'),null]){
43
+ const f=specs(t,[start('batch-ok',{[BATCH_SEGMENT_FIELD]:forged})]);
44
+ assert.throws(()=>batchSegments({specsDir:f.specsDir,batchId:'batch-ok'}),{code:'batch_history_invalid'},String(forged));
45
+ }
46
+ });
47
+
48
+ test('rows of other batches and other workflows do not decide the segment',t=>{
49
+ const f=specs(t,[start('another-batch'),{schema_version:1,workflow:'cm-prd',event:'run_done',run_id:'mine-1234'},
50
+ {schema_version:1,workflow:'cm-ai',event:'progress',run_id:'mine-1234'}]);
51
+ assert.equal(batchSegments({specsDir:f.specsDir,batchId:'mine-1234'}).dir,batchSegment('mine-1234'));
52
+ });
53
+
54
+ test('the segment is a safe single path component and ref component',()=>{
55
+ for(const id of ['a','a.b.c.d.e.f.g.h','....----','batch_2026.10.23-x'])
56
+ assert.match(batchSegment(id),/^[A-Za-z0-9_-]{1,8}-[a-f0-9]{12}$/,id);
57
+ });
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ // Prints the batch configuration /cm-ai runs for the feature admission selects,
3
+ // grouped from the approved tasks.md (runtime/js/cm-ai/batch-plan.mjs). The
4
+ // session no longer writes groups by hand; the batch host validates them again.
5
+ //
6
+ // stdout: {mode:"batch",feature,groups,config} — pass config to cm-ai-batch-host
7
+ // as the batch configuration file;
8
+ // {mode:"serial",feature,reason} — run the feature's tasks one at a time
9
+ // with cm-ai-admission --print-run-definition, as before;
10
+ // {mode:"complete"} — no task is left.
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import {fileURLToPath} from 'node:url';
14
+ import {loadConfig} from './cm-workflow-config.mjs';
15
+ import {planCmAiBatch,parallelSettings} from '../runtime/js/cm-ai/batch-plan.mjs';
16
+ import {validateHostWorkflowConfiguration} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
17
+
18
+ const usage='usage: cm-ai-batch-plan.mjs --specs-dir PATH --code-project PATH --repository-id ID --batch-id ID [--workflow-config PATH]';
19
+ function parse(argv){
20
+ const flags=new Map([['--specs-dir','specsDir'],['--code-project','codeProject'],['--repository-id','repositoryId'],
21
+ ['--batch-id','batchId'],['--workflow-config','workflowConfig']]);
22
+ const input={};
23
+ for(let index=0;index<argv.length;index+=2){
24
+ const key=flags.get(argv[index]);
25
+ if(!key||index+1>=argv.length||Object.hasOwn(input,key))return null;
26
+ input[key]=argv[index+1];
27
+ }
28
+ return ['specsDir','codeProject','repositoryId','batchId'].every(key=>typeof input[key]==='string')?input:null;
29
+ }
30
+ export function main(argv=process.argv.slice(2)){
31
+ if(argv.length===1&&['--help','-h'].includes(argv[0])){process.stdout.write(usage+'\n');return 0;}
32
+ const input=parse(argv);
33
+ if(!input){process.stderr.write(usage+'\n');return 2;}
34
+ try{
35
+ const specsDir=fs.realpathSync(path.resolve(input.specsDir)),codeProject=fs.realpathSync(path.resolve(input.codeProject));
36
+ const settings=parallelSettings(loadConfig({projectRoot:codeProject}));
37
+ // The single-task workflow configuration the batch host gets for these tasks: its
38
+ // QA critical paths keep tasks that would hit them out of one-member groups.
39
+ const workflow=input.workflowConfig===undefined?null
40
+ :validateHostWorkflowConfiguration(JSON.parse(fs.readFileSync(path.resolve(input.workflowConfig),'utf8')));
41
+ const plan=planCmAiBatch({specsDir,codeProject,repositoryId:input.repositoryId,batchId:input.batchId,settings,workflow});
42
+ process.stdout.write(JSON.stringify(plan)+'\n');return 0;
43
+ }catch(error){
44
+ process.stderr.write(JSON.stringify({error:{code:error.code??'batch_plan_failed',
45
+ ...(typeof error.reason==='string'?{reason:error.reason}:{})}})+'\n');return 1;
46
+ }
47
+ }
48
+ function isMain(entry){
49
+ if(!entry)return false;
50
+ try{return fs.realpathSync(entry)===fileURLToPath(import.meta.url);}catch{return path.resolve(entry)===fileURLToPath(import.meta.url);}
51
+ }
52
+ if(isMain(process.argv[1]))process.exitCode=main();