@aibyzero/cm-workflow 0.10.5

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 (448) hide show
  1. package/.codex-plugin/plugin.json +30 -0
  2. package/AGENTS.md +74 -0
  3. package/CONTRIBUTING.md +62 -0
  4. package/LICENSE +21 -0
  5. package/README.md +263 -0
  6. package/SECURITY.md +49 -0
  7. package/THIRD_PARTY_NOTICES.md +29 -0
  8. package/VERSION +1 -0
  9. package/agents/cm-backend-agent.md +34 -0
  10. package/agents/cm-contract-agent.md +34 -0
  11. package/agents/cm-database-agent.md +34 -0
  12. package/agents/cm-frontend-agent.md +33 -0
  13. package/agents/cm-miniprogram-agent.md +33 -0
  14. package/agents/cm-ui-agent.md +34 -0
  15. package/assets/docs/command-picker-mobile.svg +56 -0
  16. package/assets/docs/command-picker.svg +56 -0
  17. package/assets/docs/user-guide-hero-mobile.svg +35 -0
  18. package/assets/docs/user-guide-hero.svg +36 -0
  19. package/assets/readme/delivery-flow.svg +86 -0
  20. package/assets/readme/hero.svg +77 -0
  21. package/assets/readme/recovery-record.svg +73 -0
  22. package/assets/readme/test-evidence.svg +64 -0
  23. package/compat/claude-commands/cm-ai.md +3 -0
  24. package/compat/claude-commands/cm-check.md +3 -0
  25. package/compat/claude-commands/cm-fix.md +3 -0
  26. package/compat/claude-commands/cm-idea.md +3 -0
  27. package/compat/claude-commands/cm-init.md +3 -0
  28. package/compat/claude-commands/cm-prd.md +3 -0
  29. package/compat/claude-commands/cm-refactor.md +3 -0
  30. package/compat/claude-commands/cm-test.md +3 -0
  31. package/docs/architecture.md +155 -0
  32. package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a1-handoff.json +57 -0
  33. package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a2-handoff.json +58 -0
  34. package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-r1.md +121 -0
  35. package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-a1-handoff.json +56 -0
  36. package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-r1.md +100 -0
  37. package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a1-handoff.json +61 -0
  38. package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a2-handoff.json +63 -0
  39. package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r1.md +58 -0
  40. package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r2.md +55 -0
  41. package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-a1-handoff.json +65 -0
  42. package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-r1.md +88 -0
  43. package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r1.md +33 -0
  44. package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r2.md +31 -0
  45. package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a1-handoff.json +56 -0
  46. package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a2-handoff.json +85 -0
  47. package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r1.md +53 -0
  48. package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r2.md +80 -0
  49. package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-a1-handoff.json +35 -0
  50. package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-r1.md +33 -0
  51. package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r1.md +30 -0
  52. package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r2.md +16 -0
  53. package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-a1-handoff.json +40 -0
  54. package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-r1.md +30 -0
  55. package/docs/fixes/20260729-windows-cp1252-log-output.md +65 -0
  56. package/docs/fixes/20260804-manifest-runtime-checkbox-drift.md +67 -0
  57. package/docs/fixes/20260806-model-call-boundary-identity.md +80 -0
  58. package/docs/fixes/20260807-prelanding-integrity.md +58 -0
  59. package/docs/fixes/20260826-openai-compatible-depth-fixture.md +39 -0
  60. package/docs/fixes/20260903-cm-js-n1n2-admission-r1.md +64 -0
  61. package/docs/fixes/20260903-cm-js-n1n2-admission-successor.md +83 -0
  62. package/docs/fixes/20260903-s4c1b-v3-cancel-throw.md +89 -0
  63. package/docs/fixes/20260904-f01-codex-dual-failure-terminal.md +89 -0
  64. package/docs/fixes/20260907-wip-triage-log.md +44 -0
  65. package/docs/installation.md +202 -0
  66. package/docs/js-workflow-control.md +1010 -0
  67. package/docs/sample-prd/prd-funding-rate-alert.md +42 -0
  68. package/docs/sample-specs/docs//351/234/200/346/261/202/347/244/272/344/276/213.md +24 -0
  69. package/docs/user-guide.md +526 -0
  70. package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/README.md +19 -0
  71. package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.excalidraw +3650 -0
  72. package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.mp4 +0 -0
  73. package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.png +0 -0
  74. package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.spec.json +223 -0
  75. package/install-codex.sh +184 -0
  76. package/install.ps1 +206 -0
  77. package/install.sh +244 -0
  78. package/package.json +58 -0
  79. package/runtime/external-expert.md +302 -0
  80. package/runtime/js/cm-ai/accepted-fix.mjs +28 -0
  81. package/runtime/js/cm-ai/claude-developer-adapter.mjs +6 -0
  82. package/runtime/js/cm-ai/claude-review-adapter.mjs +16 -0
  83. package/runtime/js/cm-ai/claude-review-stream.mjs +53 -0
  84. package/runtime/js/cm-ai/claude-tool-preview.mjs +107 -0
  85. package/runtime/js/cm-ai/cm-ai-admission.mjs +353 -0
  86. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +217 -0
  87. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +538 -0
  88. package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +119 -0
  89. package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +172 -0
  90. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +320 -0
  91. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +107 -0
  92. package/runtime/js/cm-ai/code-projects.mjs +85 -0
  93. package/runtime/js/cm-ai/codex-config.mjs +48 -0
  94. package/runtime/js/cm-ai/codex-developer-adapter.mjs +5 -0
  95. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +6 -0
  96. package/runtime/js/cm-ai/codex-developer-output.schema.json +37 -0
  97. package/runtime/js/cm-ai/codex-review-adapter.mjs +73 -0
  98. package/runtime/js/cm-ai/contracts.mjs +156 -0
  99. package/runtime/js/cm-ai/developer-adapter.mjs +93 -0
  100. package/runtime/js/cm-ai/durable-runner-state.mjs +504 -0
  101. package/runtime/js/cm-ai/effect-contract.mjs +102 -0
  102. package/runtime/js/cm-ai/execution-platform.mjs +7 -0
  103. package/runtime/js/cm-ai/execution-store.mjs +211 -0
  104. package/runtime/js/cm-ai/fix-code-association.mjs +40 -0
  105. package/runtime/js/cm-ai/gate-bridge.mjs +25 -0
  106. package/runtime/js/cm-ai/host-bootstrap.mjs +170 -0
  107. package/runtime/js/cm-ai/host-check.mjs +89 -0
  108. package/runtime/js/cm-ai/host-conversation-execution.mjs +125 -0
  109. package/runtime/js/cm-ai/host-documentation.mjs +40 -0
  110. package/runtime/js/cm-ai/host-handoff.mjs +71 -0
  111. package/runtime/js/cm-ai/host-project-execution.mjs +58 -0
  112. package/runtime/js/cm-ai/host-qa-executor.mjs +238 -0
  113. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +131 -0
  114. package/runtime/js/cm-ai/host-qa-fix.mjs +30 -0
  115. package/runtime/js/cm-ai/host-qa-policy.mjs +70 -0
  116. package/runtime/js/cm-ai/host-review-authority.mjs +36 -0
  117. package/runtime/js/cm-ai/host-review-file.mjs +56 -0
  118. package/runtime/js/cm-ai/host-role-routing.mjs +41 -0
  119. package/runtime/js/cm-ai/host-session.mjs +96 -0
  120. package/runtime/js/cm-ai/host-tool-bridge.mjs +53 -0
  121. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +45 -0
  122. package/runtime/js/cm-ai/host.mjs +20 -0
  123. package/runtime/js/cm-ai/index.mjs +7 -0
  124. package/runtime/js/cm-ai/provider-review-observation.mjs +86 -0
  125. package/runtime/js/cm-ai/qa-fix-definition.mjs +21 -0
  126. package/runtime/js/cm-ai/review-evidence-file.mjs +38 -0
  127. package/runtime/js/cm-ai/review-package.mjs +426 -0
  128. package/runtime/js/cm-ai/review-result.schema.json +40 -0
  129. package/runtime/js/cm-ai/review-runner.mjs +35 -0
  130. package/runtime/js/cm-ai/task-commit-codec.mjs +54 -0
  131. package/runtime/js/cm-ai/task-commit.mjs +201 -0
  132. package/runtime/js/cm-ai/task-owner.mjs +97 -0
  133. package/runtime/js/cm-ai/task-runner.mjs +766 -0
  134. package/runtime/js/cm-ai/tool-preview.mjs +205 -0
  135. package/runtime/js/cm-ai/worker-claude.mjs +104 -0
  136. package/runtime/js/cm-ai/worker-codex-developer.mjs +124 -0
  137. package/runtime/js/cm-ai/worker-codex.mjs +143 -0
  138. package/runtime/js/cm-check/host.mjs +101 -0
  139. package/runtime/js/cm-fix/baseline.mjs +70 -0
  140. package/runtime/js/cm-fix/cause-evidence.mjs +24 -0
  141. package/runtime/js/cm-fix/cause-invocation.mjs +40 -0
  142. package/runtime/js/cm-fix/cause-package.mjs +68 -0
  143. package/runtime/js/cm-fix/dossier.mjs +140 -0
  144. package/runtime/js/cm-fix/execution.mjs +1549 -0
  145. package/runtime/js/cm-fix/final-review-evidence.mjs +20 -0
  146. package/runtime/js/cm-fix/final-review.mjs +156 -0
  147. package/runtime/js/cm-fix/finish.mjs +124 -0
  148. package/runtime/js/cm-fix/handoff.mjs +64 -0
  149. package/runtime/js/cm-fix/host-review.mjs +38 -0
  150. package/runtime/js/cm-fix/host.mjs +96 -0
  151. package/runtime/js/cm-fix/investigation.mjs +25 -0
  152. package/runtime/js/cm-fix/layout.mjs +17 -0
  153. package/runtime/js/cm-fix/learning-writeback.mjs +86 -0
  154. package/runtime/js/cm-fix/learning.mjs +31 -0
  155. package/runtime/js/cm-fix/metrics.mjs +75 -0
  156. package/runtime/js/cm-fix/progress.mjs +64 -0
  157. package/runtime/js/cm-fix/protected-edits.mjs +95 -0
  158. package/runtime/js/cm-fix/qa-source.mjs +58 -0
  159. package/runtime/js/cm-fix/red-test.mjs +92 -0
  160. package/runtime/js/cm-fix/regression-evidence.mjs +64 -0
  161. package/runtime/js/cm-fix/regression.mjs +41 -0
  162. package/runtime/js/cm-fix/repair.mjs +95 -0
  163. package/runtime/js/cm-fix/reproduce.mjs +54 -0
  164. package/runtime/js/cm-fix/retrospective.mjs +41 -0
  165. package/runtime/js/cm-fix/review-baseline.mjs +47 -0
  166. package/runtime/js/cm-fix/start.mjs +49 -0
  167. package/runtime/js/cm-fix/test-author.mjs +63 -0
  168. package/runtime/js/cm-fix/visual.mjs +72 -0
  169. package/runtime/js/cm-fix/walkthrough.mjs +126 -0
  170. package/runtime/js/cm-idea/session.mjs +79 -0
  171. package/runtime/js/cm-init/draft-generation.mjs +66 -0
  172. package/runtime/js/cm-init/draft-inspection.mjs +70 -0
  173. package/runtime/js/cm-init/project-analysis.mjs +60 -0
  174. package/runtime/js/cm-init/project-scan.mjs +55 -0
  175. package/runtime/js/cm-init/review-evidence.mjs +80 -0
  176. package/runtime/js/cm-prd/accepted-design.mjs +46 -0
  177. package/runtime/js/cm-prd/analysis.mjs +260 -0
  178. package/runtime/js/cm-prd/change.mjs +268 -0
  179. package/runtime/js/cm-prd/correction-check.mjs +49 -0
  180. package/runtime/js/cm-prd/design-risk.mjs +30 -0
  181. package/runtime/js/cm-prd/disposition-plan.mjs +33 -0
  182. package/runtime/js/cm-prd/draft-save.mjs +122 -0
  183. package/runtime/js/cm-prd/draft.mjs +70 -0
  184. package/runtime/js/cm-prd/materials.mjs +48 -0
  185. package/runtime/js/cm-prd/review-correction.mjs +158 -0
  186. package/runtime/js/cm-prd/review-disposition.mjs +96 -0
  187. package/runtime/js/cm-prd/review-findings.mjs +36 -0
  188. package/runtime/js/cm-prd/review-host.mjs +48 -0
  189. package/runtime/js/cm-prd/review-preparation.mjs +49 -0
  190. package/runtime/js/cm-prd/review-publication.mjs +56 -0
  191. package/runtime/js/cm-prd/self-check.mjs +75 -0
  192. package/runtime/js/cm-prd/session.mjs +74 -0
  193. package/runtime/js/cm-prd/summary.mjs +133 -0
  194. package/runtime/js/cm-refactor/host.mjs +2 -0
  195. package/runtime/js/cm-refactor/records.mjs +86 -0
  196. package/runtime/js/cm-refactor/workflow.mjs +478 -0
  197. package/runtime/js/cm-test/declared-command.mjs +32 -0
  198. package/runtime/js/cm-test/host.mjs +319 -0
  199. package/runtime/js/cm-test/logic-results.mjs +39 -0
  200. package/runtime/js/cm-test/recovery.mjs +58 -0
  201. package/runtime/js/cm-test/session.mjs +56 -0
  202. package/runtime/js/cm-test/source-snapshot.mjs +136 -0
  203. package/runtime/logging.md +207 -0
  204. package/runtime/model-efficiency.md +201 -0
  205. package/runtime/orchestration.md +113 -0
  206. package/runtime/project-context.md +43 -0
  207. package/runtime/project-learning.md +49 -0
  208. package/runtime/review.md +140 -0
  209. package/runtime/steelman-review.md +111 -0
  210. package/runtime/task-gates.md +283 -0
  211. package/runtime/task-handoff.schema.json +103 -0
  212. package/runtime/test-contract.md +212 -0
  213. package/runtime/workflow-config.md +118 -0
  214. package/runtime/workflow-routing.md +82 -0
  215. package/scripts/cm-ai-admission.mjs +50 -0
  216. package/scripts/cm-ai-admission.test.mjs +38 -0
  217. package/scripts/cm-ai-batch-host.mjs +77 -0
  218. package/scripts/cm-ai-batch-host.test.mjs +155 -0
  219. package/scripts/cm-ai-batch-run.mjs +136 -0
  220. package/scripts/cm-ai-batch-run.test.mjs +128 -0
  221. package/scripts/cm-ai-bootstrap.test.mjs +228 -0
  222. package/scripts/cm-ai-fix-integration.test.mjs +233 -0
  223. package/scripts/cm-ai-host.mjs +175 -0
  224. package/scripts/cm-ai-host.test.mjs +368 -0
  225. package/scripts/cm-ai-multi-root.test.mjs +289 -0
  226. package/scripts/cm-ai-nested-execution.test.mjs +313 -0
  227. package/scripts/cm-ai-run.mjs +293 -0
  228. package/scripts/cm-ai-run.test.mjs +336 -0
  229. package/scripts/cm-check-entry.mjs +120 -0
  230. package/scripts/cm-check-host.mjs +29 -0
  231. package/scripts/cm-check-host.test.mjs +71 -0
  232. package/scripts/cm-check-runtime.ps1 +69 -0
  233. package/scripts/cm-check-runtime.sh +910 -0
  234. package/scripts/cm-claude-probe.test.mjs +54 -0
  235. package/scripts/cm-claude-review-stream.test.mjs +45 -0
  236. package/scripts/cm-claude-worker.test.mjs +92 -0
  237. package/scripts/cm-codex-developer-adapter.test.mjs +85 -0
  238. package/scripts/cm-codex-developer-worker.test.mjs +128 -0
  239. package/scripts/cm-codex-review-progress.test.mjs +96 -0
  240. package/scripts/cm-execution-platform.test.mjs +47 -0
  241. package/scripts/cm-fix-cause-invocation.test.mjs +72 -0
  242. package/scripts/cm-fix-cause-package.test.mjs +68 -0
  243. package/scripts/cm-fix-code-association.test.mjs +55 -0
  244. package/scripts/cm-fix-entry.mjs +132 -0
  245. package/scripts/cm-fix-execution.test.mjs +63 -0
  246. package/scripts/cm-fix-final-review.test.mjs +124 -0
  247. package/scripts/cm-fix-host-review-assembly.test.mjs +34 -0
  248. package/scripts/cm-fix-host-review.test.mjs +261 -0
  249. package/scripts/cm-fix-host-sequence.test.mjs +26 -0
  250. package/scripts/cm-fix-host.mjs +89 -0
  251. package/scripts/cm-fix-host.test.mjs +105 -0
  252. package/scripts/cm-fix-learning-writeback.test.mjs +73 -0
  253. package/scripts/cm-fix-learning.test.mjs +66 -0
  254. package/scripts/cm-fix-metrics.test.mjs +58 -0
  255. package/scripts/cm-fix-no-existing-tests.test.mjs +92 -0
  256. package/scripts/cm-fix-observation-dossier.test.mjs +452 -0
  257. package/scripts/cm-fix-progress.test.mjs +45 -0
  258. package/scripts/cm-fix-protected-edits.test.mjs +54 -0
  259. package/scripts/cm-fix-qa-source.test.mjs +206 -0
  260. package/scripts/cm-fix-red-owner.test.mjs +143 -0
  261. package/scripts/cm-fix-red-test.test.mjs +38 -0
  262. package/scripts/cm-fix-regression.test.mjs +57 -0
  263. package/scripts/cm-fix-repair-owner.test.mjs +370 -0
  264. package/scripts/cm-fix-repair.test.mjs +68 -0
  265. package/scripts/cm-fix-reproduce.test.mjs +31 -0
  266. package/scripts/cm-fix-retrospective.test.mjs +46 -0
  267. package/scripts/cm-fix-review-baseline.test.mjs +54 -0
  268. package/scripts/cm-fix-review-recovery.test.mjs +197 -0
  269. package/scripts/cm-fix-test-author.test.mjs +105 -0
  270. package/scripts/cm-fix-visual-bare.test.mjs +171 -0
  271. package/scripts/cm-fix-walkthrough.test.mjs +45 -0
  272. package/scripts/cm-host-check.test.mjs +113 -0
  273. package/scripts/cm-host-documentation.test.mjs +45 -0
  274. package/scripts/cm-host-handoff.test.mjs +58 -0
  275. package/scripts/cm-host-qa-executor.test.mjs +156 -0
  276. package/scripts/cm-host-qa-policy.test.mjs +59 -0
  277. package/scripts/cm-host-review-authority.test.mjs +60 -0
  278. package/scripts/cm-host-role-routing.test.mjs +33 -0
  279. package/scripts/cm-idea-entry.mjs +104 -0
  280. package/scripts/cm-idea-host.mjs +144 -0
  281. package/scripts/cm-idea-host.test.mjs +75 -0
  282. package/scripts/cm-idea-recovery.test.mjs +90 -0
  283. package/scripts/cm-init-analysis-host.test.mjs +50 -0
  284. package/scripts/cm-init-draft-generation.test.mjs +52 -0
  285. package/scripts/cm-init-draft-inspection.test.mjs +41 -0
  286. package/scripts/cm-init-entry.mjs +170 -0
  287. package/scripts/cm-init-host.mjs +284 -0
  288. package/scripts/cm-init-host.test.mjs +231 -0
  289. package/scripts/cm-init-project-analysis.test.mjs +47 -0
  290. package/scripts/cm-init-project-scan.test.mjs +41 -0
  291. package/scripts/cm-init-revision-host.test.mjs +61 -0
  292. package/scripts/cm-init-session.test.mjs +122 -0
  293. package/scripts/cm-log-event.mjs +538 -0
  294. package/scripts/cm-log-event.py +133 -0
  295. package/scripts/cm-log-event.test.mjs +70 -0
  296. package/scripts/cm-openai-compatible-call.py +661 -0
  297. package/scripts/cm-prd-analysis.test.mjs +67 -0
  298. package/scripts/cm-prd-completion.test.mjs +190 -0
  299. package/scripts/cm-prd-design-phase.test.mjs +296 -0
  300. package/scripts/cm-prd-draft-save.test.mjs +63 -0
  301. package/scripts/cm-prd-draft.test.mjs +39 -0
  302. package/scripts/cm-prd-entry.mjs +245 -0
  303. package/scripts/cm-prd-host.mjs +273 -0
  304. package/scripts/cm-prd-host.test.mjs +169 -0
  305. package/scripts/cm-prd-materials.test.mjs +41 -0
  306. package/scripts/cm-prd-review-claim.test.mjs +42 -0
  307. package/scripts/cm-prd-review-disposition.test.mjs +196 -0
  308. package/scripts/cm-prd-review-gate.mjs +194 -0
  309. package/scripts/cm-prd-review-gate.py +26 -0
  310. package/scripts/cm-prd-review-host.test.mjs +30 -0
  311. package/scripts/cm-prd-review-preparation.test.mjs +69 -0
  312. package/scripts/cm-prd-review-publication.test.mjs +95 -0
  313. package/scripts/cm-prd-revision.test.mjs +32 -0
  314. package/scripts/cm-prd-self-check.test.mjs +23 -0
  315. package/scripts/cm-prd-sources.test.mjs +76 -0
  316. package/scripts/cm-prd-timing.py +272 -0
  317. package/scripts/cm-refactor-entry.mjs +145 -0
  318. package/scripts/cm-refactor-host.mjs +26 -0
  319. package/scripts/cm-refactor-host.test.mjs +201 -0
  320. package/scripts/cm-review-dependency-snapshot.test.mjs +67 -0
  321. package/scripts/cm-review-inventory.test.mjs +109 -0
  322. package/scripts/cm-spec-manifest.mjs +104 -0
  323. package/scripts/cm-spec-manifest.py +26 -0
  324. package/scripts/cm-task-gate.mjs +879 -0
  325. package/scripts/cm-task-gate.py +312 -0
  326. package/scripts/cm-task-gate.test.mjs +202 -0
  327. package/scripts/cm-test-declared-command.test.mjs +18 -0
  328. package/scripts/cm-test-entry.mjs +231 -0
  329. package/scripts/cm-test-host.mjs +40 -0
  330. package/scripts/cm-test-host.test.mjs +169 -0
  331. package/scripts/cm-test-logic-results.test.mjs +26 -0
  332. package/scripts/cm-test-session.test.mjs +138 -0
  333. package/scripts/cm-usage-report.py +516 -0
  334. package/scripts/cm-workflow-config.mjs +463 -0
  335. package/scripts/cm-workflow-config.test.mjs +181 -0
  336. package/scripts/cm-workflow.mjs +36 -0
  337. package/scripts/cm-workflow.test.mjs +51 -0
  338. package/scripts/cm_workflow_config.py +52 -0
  339. package/scripts/fixtures/claude-review-process.mjs +35 -0
  340. package/scripts/fixtures/codex-review-process.mjs +22 -0
  341. package/scripts/fixtures/prd-review-gate-python-oracle.py +320 -0
  342. package/scripts/fixtures/spec-manifest-python-oracle.py +172 -0
  343. package/scripts/scan-public-safety.py +117 -0
  344. package/scripts/test-cm-log-event.py +1213 -0
  345. package/scripts/test-cm-openai-compatible-call.py +1185 -0
  346. package/scripts/test-cm-prd-review-gate.py +272 -0
  347. package/scripts/test-cm-prd-timing.py +168 -0
  348. package/scripts/test-cm-usage-report.py +584 -0
  349. package/scripts/test-npm-install.py +171 -0
  350. package/scripts/test-scan-public-safety.py +76 -0
  351. package/scripts/test-shell-compat.sh +365 -0
  352. package/scripts/test-spec-manifest.py +263 -0
  353. package/scripts/test-task-gate.py +46 -0
  354. package/scripts/test-workflow-config.py +30 -0
  355. package/scripts/validate-public-repo.py +245 -0
  356. package/scripts/validate-test-cases.mjs +71 -0
  357. package/scripts/validate-test-cases.py +27 -0
  358. package/scripts/validate-test-cases.test.mjs +36 -0
  359. package/skills/cm-ai/SKILL.md +137 -0
  360. package/skills/cm-ai/references/N1-init.md +108 -0
  361. package/skills/cm-ai/references/N2-enter-feature.md +38 -0
  362. package/skills/cm-ai/references/N3-execute-task.md +123 -0
  363. package/skills/cm-ai/references/N4-review.md +103 -0
  364. package/skills/cm-ai/references/N5-mark-done.md +117 -0
  365. package/skills/cm-ai/references/N6-qa-eval.md +102 -0
  366. package/skills/cm-ai/references/N7-context.md +23 -0
  367. package/skills/cm-ai/references/N8-finish.md +103 -0
  368. package/skills/cm-ai/references/js-host.md +126 -0
  369. package/skills/cm-backend-engineer/SKILL.md +100 -0
  370. package/skills/cm-check/SKILL.md +52 -0
  371. package/skills/cm-check/references/js-host.md +44 -0
  372. package/skills/cm-contract-engineer/SKILL.md +136 -0
  373. package/skills/cm-database-engineer/SKILL.md +89 -0
  374. package/skills/cm-devops-engineer/SKILL.md +137 -0
  375. package/skills/cm-doc-syncer/SKILL.md +150 -0
  376. package/skills/cm-finance-expert/SKILL.md +85 -0
  377. package/skills/cm-fix/SKILL.md +199 -0
  378. package/skills/cm-fix/references/cross-boundary-debugging.md +44 -0
  379. package/skills/cm-fix/references/js-host.md +135 -0
  380. package/skills/cm-frontend-engineer/SKILL.md +127 -0
  381. package/skills/cm-idea/SKILL.md +55 -0
  382. package/skills/cm-idea/references/domains/trading.md +97 -0
  383. package/skills/cm-idea/references/example-prd.md +92 -0
  384. package/skills/cm-idea/references/idea-to-prd.md +282 -0
  385. package/skills/cm-idea/references/js-host.md +63 -0
  386. package/skills/cm-init/SKILL.md +191 -0
  387. package/skills/cm-init/references/js-host.md +123 -0
  388. package/skills/cm-miniprogram-engineer/SKILL.md +141 -0
  389. package/skills/cm-miniprogram-engineer/references/platform-readiness.md +58 -0
  390. package/skills/cm-miniprogram-engineer/references/release-checklist.md +59 -0
  391. package/skills/cm-prd/SKILL.md +548 -0
  392. package/skills/cm-prd/references/brownfield.md +13 -0
  393. package/skills/cm-prd/references/change-mode.md +145 -0
  394. package/skills/cm-prd/references/context-scope.md +62 -0
  395. package/skills/cm-prd/references/greenfield.md +80 -0
  396. package/skills/cm-prd/references/js-change-recovery.md +57 -0
  397. package/skills/cm-prd/references/js-host.md +98 -0
  398. package/skills/cm-prd/references/phase-timing.md +68 -0
  399. package/skills/cm-prd/references/spec-self-check.md +22 -0
  400. package/skills/cm-product-manager/SKILL.md +83 -0
  401. package/skills/cm-qa-engineer/SKILL.md +142 -0
  402. package/skills/cm-refactor/SKILL.md +236 -0
  403. package/skills/cm-refactor/references/js-batch.md +75 -0
  404. package/skills/cm-refactor/references/js-host.md +78 -0
  405. package/skills/cm-test/SKILL.md +288 -0
  406. package/skills/cm-test/references/js-host.md +118 -0
  407. package/skills/cm-ui-engineer/SKILL.md +105 -0
  408. package/skills/codebase-context/SKILL.md +489 -0
  409. package/skills/darwin-skill/NOTICE.md +26 -0
  410. package/skills/darwin-skill/README.md +272 -0
  411. package/skills/darwin-skill/SKILL.md +492 -0
  412. package/skills/darwin-skill/references/runtime-neutrality.md +68 -0
  413. package/skills/darwin-skill/references/skilllens-evidence.md +142 -0
  414. package/skills/darwin-skill/scripts/screenshot.mjs +71 -0
  415. package/skills/darwin-skill/templates/result-card-dark.html +698 -0
  416. package/skills/darwin-skill/templates/result-card-white.html +444 -0
  417. package/skills/darwin-skill/templates/result-card.html +616 -0
  418. package/skills/external-expert/SKILL.md +250 -0
  419. package/templates/arch-reference.md +68 -0
  420. package/templates/auto-update/cm-announce.sh +19 -0
  421. package/templates/auto-update/cm-update.sh +274 -0
  422. package/templates/cm-workflow.yml +52 -0
  423. package/templates/dashboard/dashboard.html +153 -0
  424. package/templates/dashboard/serve.sh +10 -0
  425. package/templates/hooks/pre-commit-cm-task-check +67 -0
  426. package/templates/pixel/cm-pixel.html +388 -0
  427. package/templates/pixel/cm-pixel.sh +212 -0
  428. package/templates/pixel/dev/README.md +20 -0
  429. package/templates/pixel/dev/atlas-preview.png +0 -0
  430. package/templates/pixel/dev/build.py +55 -0
  431. package/templates/pixel/dev/sheets/roguelikeChar_transparent.png +0 -0
  432. package/templates/pixel/dev/sheets/roguelikeCity_tilemap.png +0 -0
  433. package/templates/pixel/dev/sheets/roguelikeIndoor_transparent.png +0 -0
  434. package/templates/pixel/dev/template.html +388 -0
  435. package/templates/pixel/serve.sh +12 -0
  436. package/templates/refactor/cm-refactor-denies.json +14 -0
  437. package/templates/rules/backend-api.md +36 -0
  438. package/templates/rules/coding-style.md +44 -0
  439. package/templates/rules/database.md +27 -0
  440. package/templates/rules/finance.md +32 -0
  441. package/templates/rules/frontend.md +32 -0
  442. package/templates/rules/git-workflow.md +25 -0
  443. package/templates/rules/miniprogram.md +31 -0
  444. package/templates/rules/security.md +31 -0
  445. package/templates/rules/smart-contract.md +28 -0
  446. package/templates/rules/testing.md +36 -0
  447. package/templates/statusline/cm-statusline.sh +73 -0
  448. package/templates/ui-lens/cm-ui-lens-extract.mjs +55 -0
@@ -0,0 +1,228 @@
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 {spawn,spawnSync} from 'node:child_process';
7
+ import {fileURLToPath} from 'node:url';
8
+ import {createHostBootstrap} from '../runtime/js/cm-ai/host-bootstrap.mjs';
9
+ import {cmInitRuleTargets} from '../runtime/js/cm-init/draft-generation.mjs';
10
+ import {createTaskRunner} from '../runtime/js/cm-ai/task-runner.mjs';
11
+ import {openTaskExecutionStore} from '../runtime/js/cm-ai/task-owner.mjs';
12
+ import {createDeveloperRun,validateDeveloperScope} from '../runtime/js/cm-ai/developer-adapter.mjs';
13
+ import {inspectCmAiAdmission} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
14
+ import {inspectCmAiContextRefresh,inspectCmAiTaskLearningInput} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
15
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
16
+ import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
17
+ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
18
+
19
+ const workflowRoot=fileURLToPath(new URL('..',import.meta.url)).replace(/\/$/,'');
20
+ const selection={versionControl:'none',modules:['frontend'],analysis:'Approved synthetic JavaScript project'};
21
+ const checks=()=>Object.fromEntries(['commands','globs','file_references','constraint_preservation','rule_applicability']
22
+ .map(name=>[name,{status:'verified',evidence:'Synthetic semantic report for the local fixture'}]));
23
+ function fixture(t){
24
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-')));
25
+ t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
26
+ const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');
27
+ fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,'0.bootstrap'),{recursive:true});fs.mkdirSync(path.join(specsDir,'.reviews'));
28
+ fs.writeFileSync(path.join(specsDir,'0.bootstrap','requirements.md'),'# Requirements\nSynthetic approved scaffold and project instructions.\n');
29
+ fs.writeFileSync(path.join(specsDir,'0.bootstrap','design.md'),'# Design\nJavaScript; no Git; frontend module.\n');
30
+ fs.writeFileSync(path.join(specsDir,'0.bootstrap','tasks.md'),'- [ ] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 .claude/ 规范(cm-init)\n');
31
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.bootstrap']}));
32
+ return {root,codeProject,specsDir,calls:[],reviews:[],businessCalls:0};
33
+ }
34
+ function definition(f,taskId){
35
+ return {version:1,codeProject:f.codeProject,specsDir:f.specsDir,feature:'0.bootstrap',
36
+ identity:{repositoryId:'bootstrap-fixture',runId:'run-'+taskId,taskId,attempt:1},
37
+ scope:taskId==='T-001'?['app.mjs']:[...cmInitRuleTargets(selection)],requirements:[]};
38
+ }
39
+ function reply(f,kind,payload){
40
+ f.calls.push(kind);
41
+ if(kind==='init_generate')return {status:'generated',documents:payload.targets.map(file=>({path:file,
42
+ content:file==='AGENTS.md'&&fs.existsSync(path.join(f.codeProject,file))?fs.readFileSync(path.join(f.codeProject,file),'utf8'):
43
+ file==='.claude/CLAUDE.md'?'# Fixture instructions\n'+payload.targets.filter(p=>p.startsWith('.claude/rules/'))
44
+ .map(p=>'@rules/'+path.basename(p)).join('\n')+'\n':'# Fixture instructions\nUse approved scope.\n'}))};
45
+ if(kind==='init_verify')return {checks:checks(),constraintChanges:[],application:{status:'no_relevant_lesson',note:null},
46
+ retrospective:f.lesson&&f.calls.filter(kind=>kind==='init_verify').length===1
47
+ ?{status:'lesson_candidate',candidates:[{classification:'structured',trigger:'Bootstrap recovery',
48
+ action:'Preserve reviewed instruction lessons across attempts',evidence:['app.mjs']}],reason:null}
49
+ :{status:'no_new_lesson',candidates:[],reason:null}};
50
+ assert.fail('unexpected host call '+kind);
51
+ }
52
+ function open(f,taskId,mode='create',overrides={}){
53
+ const d=definition(f,taskId),bridge={call:async(kind,payload)=>overrides.reply?overrides.reply(kind,payload):reply(f,kind,payload)};
54
+ const bootstrap=createHostBootstrap({definition:d,workflowRoot,selection:taskId==='T-001'?null:selection,bridge,
55
+ allowWrite:overrides.allowWrite??true});
56
+ const store=openTaskExecutionStore({tasksPath:path.join(f.specsDir,'0.bootstrap','tasks.md'),feature:'bootstrap',specsRoot:f.specsDir,
57
+ identity:{repositoryId:d.identity.repositoryId,runId:d.identity.runId},
58
+ fingerprints:{workflow:digest('bootstrap-test'),config:digest({d,bootstrap:bootstrap.configuration}),inputs:digest(taskId)},create:mode==='create'});
59
+ const developer={provider:'codex',requestedModel:'synthetic',contextId:'scaffold-author',run:createDeveloperRun({provider:'codex',requestedModel:'synthetic',worker:async request=>{
60
+ f.businessCalls++;assert(!request.prompt.includes('"scope":["AGENTS.md"'));
61
+ assert(request.prompt.includes(Buffer.from('JavaScript; no Git; frontend module.').toString('base64').slice(0,12))
62
+ ||request.prompt.includes('0.bootstrap/design.md'));
63
+ fs.writeFileSync(path.join(f.codeProject,'app.mjs'),'export const fixture = true;\n');
64
+ return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
65
+ retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
66
+ }})};
67
+ const runner=createTaskRunner({root:f.codeProject,identity:d.identity,scope:d.scope,requirements:d.requirements,bootstrap,
68
+ taskLearning:{feature:'0.bootstrap',hostHandoff:true},developer,excludedContexts:['main'],timeoutMs:5000,
69
+ reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic-review',allowed:true,available:true,contexts:['review-one','review-two'],
70
+ run:async(request,{onEvent})=>{f.reviews.push(request.payload.reviewPackage);
71
+ onEvent({event:'thread.started',provider_thread:'actual-review-'+request.identity.attempt});
72
+ onEvent({event:'turn.started',item_type:null});onEvent({event:'item.completed',item_type:'agent_message'});
73
+ onEvent({event:'turn.completed',item_type:null});onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
74
+ const revise=f.requestRevision&&taskId==='T-002'&&request.identity.attempt===1;
75
+ return {status:'succeeded',value:{verdict:revise?'changes_requested':'approved',packageDigest:request.payload.reviewPackage.packageDigest,
76
+ examinedPaths:reviewPaths(request.payload.reviewPackage),findings:revise?[{id:'F1',severity:'P2',path:'AGENTS.md',
77
+ message:'Reverify instruction applicability',evidence:'Synthetic revision fixture'}]:[],summary:'Synthetic independent review'}};}}],
78
+ reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main'],authorize:(request,{authorizationAt})=>{
79
+ const body={version:1,kind:'cm-review-dispatch-grant',grantId:'grant-'+request.identity.attempt,adapterId:'codex-review-adapter',
80
+ invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,reviewerId:'reviewer',
81
+ logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'main',
82
+ decisionId:'decision-'+request.identity.attempt,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
83
+ return {...body,grantDigest:digest(body)};
84
+ }},
85
+ check:createHostCheck({cwd:f.codeProject,timeoutMs:1000,commands:[{id:'syntax',command:[process.execPath,'--check','app.mjs']}]}),
86
+ taskCompletion:{reviewsDir:path.join(f.specsDir,'.reviews'),handoffs:[1,2].map(a=>path.join(f.specsDir,'.reviews',`bootstrap-${taskId}-a${a}-handoff.json`))},
87
+ persistence:{store,mode,version:3}});
88
+ return {runner,store,definition:d,close:()=>store.close(),effect:kind=>{
89
+ const identity=runner.status().identity;
90
+ return runner.executeEffect({version:1,id:kind+'-'+identity.attempt,kind,identity,...(kind==='develop'?{
91
+ learningInput:inspectCmAiTaskLearningInput({specsDir:f.specsDir,codeProject:f.codeProject,feature:'0.bootstrap',identity,
92
+ applicableAgentFiles:[]},{admission:runner.inspectBootstrapAdmission()})}:{})});
93
+ }};
94
+ }
95
+
96
+ function prepareCli(f){
97
+ const config=path.join(f.root,'run.json'),bin=path.join(f.root,'bin');fs.mkdirSync(bin);
98
+ const realCodex=spawnSync('which',['codex'],{encoding:'utf8'});assert.equal(realCodex.status,0);
99
+ // Only the sandbox subcommand reaches native Codex. All review/preflight
100
+ // processes use the existing synthetic fixture, never a provider endpoint.
101
+ fs.writeFileSync(path.join(bin,'codex'),`#!${process.execPath}\n`
102
+ +`const {spawnSync}=await import('node:child_process');\n`
103
+ +`if(process.argv[2]==='sandbox'){const r=spawnSync(${JSON.stringify(realCodex.stdout.trim())},process.argv.slice(2),{stdio:'inherit'});process.exitCode=r.status??1;}`
104
+ +`else await import(${JSON.stringify(new URL('./fixtures/codex-review-process.mjs',import.meta.url).href)});\n`,{mode:0o700});
105
+ const env={...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_LOG_HOME:path.join(f.root,'mirror')};
106
+ fs.writeFileSync(config,JSON.stringify(definition(f,'T-002')));
107
+ const cli=path.join(workflowRoot,'scripts/cm-ai-host.mjs');
108
+ const preflight=spawnSync(process.execPath,[cli,'preflight','--config',config,'--review-model','synthetic-review'],
109
+ {env,encoding:'utf8',timeout:10000});assert.equal(preflight.status,0,preflight.stderr);
110
+ const receipt=JSON.parse(preflight.stdout);assert.equal(receipt.preflight.real_model_requests,0);
111
+ const files={review:receipt,bootstrap:{selection},protection:{checkCommands:[{id:'syntax',command:[process.execPath,'--check','app.mjs']}],timeoutMs:5000},
112
+ workflow:{qa:{commands:[{id:'bootstrap-qa',command:[process.execPath,'--check','app.mjs'],caseIds:[]}],
113
+ environment:{kind:'web',carrier:'browser',target:'isolated fixture; command QA only',scope:'local'}},documentationPaths:[],applicableAgentFiles:[]}};
114
+ for(const [name,value] of Object.entries(files))fs.writeFileSync(path.join(f.root,name+'.json'),JSON.stringify(value));
115
+ return {cli,env,args:['serve','--config',config,'--mode','create','--host-context','bootstrap-current-host','--allow-development',
116
+ '--protected-conversation-config',path.join(f.root,'protection.json'),'--bootstrap-config',path.join(f.root,'bootstrap.json'),
117
+ '--allow-bootstrap-write','--review-config',path.join(f.root,'review.json'),'--allow-review-attempt','1',
118
+ '--workflow-config',path.join(f.root,'workflow.json'),'--allow-qa']};
119
+ }
120
+
121
+ function runCli(f,config,mode,operation){
122
+ return new Promise((resolve,reject)=>{
123
+ const args=[...config.args];args[4]=mode;
124
+ const child=spawn(process.execPath,[config.cli,...args],{env:config.env,stdio:['pipe','pipe','pipe']});
125
+ let buffer='',stderr='',sessionId;const calls=[];let result;
126
+ const timer=setTimeout(()=>{child.kill('SIGTERM');reject(Error('bootstrap CLI timeout: '+stderr));},15000);
127
+ const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
128
+ child.stderr.on('data',chunk=>{stderr+=chunk;});child.once('error',reject);
129
+ child.stdout.on('data',chunk=>{
130
+ buffer+=chunk;let index;
131
+ while((index=buffer.indexOf('\n'))!==-1){
132
+ const line=buffer.slice(0,index);buffer=buffer.slice(index+1);if(!line)continue;
133
+ try{
134
+ const row=JSON.parse(line);
135
+ if(row.type==='host_ready')sessionId=row.sessionId;
136
+ if(row.type==='host_request'){
137
+ calls.push(row.kind);let response;
138
+ if(['init_generate','init_verify'].includes(row.kind)){assert.equal(mode,'create');response=reply(f,row.kind,row.payload);}
139
+ else if(row.kind==='qa_assess')response={scores:{scope:5,risk:5,accumulation:5,boundary:5},
140
+ changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
141
+ else if(row.kind==='documentation_inspect'){
142
+ const {syncId,identity,packageDigest,contextDigest}=row.payload;
143
+ response={syncId,identity,packageDigest,contextDigest,status:'completed',reason:'Fixture instructions inspected; no documentation paths configured',
144
+ at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')};
145
+ }else assert.fail('unexpected bootstrap CLI host call '+row.kind);
146
+ send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result:response});
147
+ }
148
+ if(row.requestId===operation){assert(!row.error,JSON.stringify(row));result=row.result;send({type:'host_close',sessionId});}
149
+ }catch(error){clearTimeout(timer);child.kill('SIGTERM');reject(error);return;}
150
+ }
151
+ });
152
+ child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,result});});
153
+ send({version:1,operation,requestId:operation,identity:definition(f,'T-002').identity});
154
+ });
155
+ }
156
+
157
+ test('empty T001 then protected current-host CLI rules task, actual QA and N7 use original gates',{timeout:30000},async t=>{
158
+ const f=fixture(t);assert.deepEqual(fs.readdirSync(f.codeProject),[]);
159
+ let run=open(f,'T-001');
160
+ assert.equal((await run.effect('develop')).state,'awaiting_review');run.close();
161
+ assert.equal(inspectCmAiAdmission(f).reason,'bootstrap_conflict');
162
+ run=open(f,'T-001','resume');assert.equal(run.runner.inspectBootstrapAdmission().state,'ready');
163
+ assert.equal(run.runner.status().state,'awaiting_review');assert.equal((await run.effect('review')).state,'approved');
164
+ assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
165
+ assert.equal(f.businessCalls,1);assert.equal(f.calls.length,0);
166
+ assert.equal(f.reviews[0].bootstrapRequirements.files.length,2);assert.deepEqual(f.reviews[0].requirements,[]);
167
+ assert.equal(inspectCmAiAdmission(f).nextTask.id,'T-002');
168
+ const cli=prepareCli(f),completed=await runCli(f,cli,'create','advance');
169
+ assert.equal(completed.code,0,JSON.stringify(completed));assert.equal(completed.result.state,'run_done',JSON.stringify(completed));
170
+ assert(completed.calls.includes('qa_assess'));
171
+ assert.equal(f.businessCalls,1);assert.deepEqual(f.calls,['init_generate','init_verify']);
172
+ const handoff=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','bootstrap-T-002-a1-handoff.json'),'utf8'));
173
+ assert.deepEqual(handoff.changed_files.sort(),[...cmInitRuleTargets(selection)].sort());
174
+ const qaReports=fs.readdirSync(path.join(f.specsDir,'.reviews')).filter(file=>file.endsWith('-execution.md'));
175
+ assert.equal(qaReports.length,1);assert.match(fs.readFileSync(path.join(f.specsDir,'.reviews',qaReports[0]),'utf8'),/Overall: PASS/);
176
+ const refresh=inspectCmAiContextRefresh({codeProject:f.codeProject,specsDir:f.specsDir,feature:'0.bootstrap',applicableAgentFiles:[]});
177
+ assert.equal(refresh.state,'complete');assert(refresh.contextFiles.some(file=>file.path==='.claude/rules/frontend.md'));
178
+ const resumed=await runCli(f,cli,'resume','status');assert.equal(resumed.code,0,resumed.stderr);
179
+ assert.equal(resumed.result.state,'fixture_completed');assert.deepEqual(resumed.calls,[]);
180
+ assert.throws(()=>validateDeveloperScope(['AGENTS.md']),{code:'protected_scope'});
181
+ assert.match(fs.readFileSync(path.join(f.specsDir,'0.bootstrap','tasks.md'),'utf8'),/\[x\] T-002/);
182
+ });
183
+
184
+ test('bootstrap denies missing authority before intent and a newly authorized launch can continue',{timeout:15000},async t=>{
185
+ const f=fixture(t);
186
+ let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
187
+ run=open(f,'T-002','create',{allowWrite:false});
188
+ const revision=run.store.snapshot().revision;
189
+ assert.deepEqual(await run.effect('develop'),{outcome:'rejected',code:'bootstrap_write_authorization_required'});
190
+ assert.equal(run.runner.status().state,'ready');assert.equal(run.store.snapshot().revision,revision);
191
+ assert.equal(f.calls.length,0);run.close();assert.equal(fs.existsSync(path.join(f.codeProject,'AGENTS.md')),false);
192
+ f.lesson=true;f.requestRevision=true;
193
+ run=open(f,'T-002','resume');assert.equal((await run.effect('develop')).state,'awaiting_review');run.close();
194
+ run=open(f,'T-002','resume');assert.equal((await run.effect('review')).state,'changes_requested');run.close();
195
+ const originalAgents=fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8');assert.match(originalAgents,/Bootstrap recovery/);
196
+ run=open(f,'T-002','resume',{allowWrite:false});const retryRevision=run.store.snapshot().revision,callCount=f.calls.length;
197
+ assert.deepEqual(await run.effect('develop'),{outcome:'rejected',code:'bootstrap_write_authorization_required'});
198
+ assert.equal(run.runner.status().state,'changes_requested');assert.equal(run.store.snapshot().revision,retryRevision);
199
+ assert.equal(f.calls.length,callCount);run.close();
200
+ run=open(f,'T-002','resume');assert.equal((await run.effect('develop')).state,'awaiting_review');run.close();
201
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8'),originalAgents);
202
+ run=open(f,'T-002','resume');assert.equal((await run.effect('review')).state,'approved');
203
+ assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
204
+ });
205
+
206
+ for(const scenario of ['existing-instructions','failed-verification','target-drift'])
207
+ test('rules task preserves files and original unknown outcome: '+scenario,{timeout:5000},async t=>{
208
+ const f=fixture(t),tasks=path.join(f.specsDir,'0.bootstrap','tasks.md');
209
+ // A previously accepted scaffold is test setup, not a second execution path.
210
+ fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('[ ] T-001','[x] T-001'));
211
+ fs.writeFileSync(path.join(f.codeProject,'app.mjs'),'export const fixture = true;\n');
212
+ const agents=path.join(f.codeProject,'AGENTS.md');
213
+ if(scenario==='existing-instructions')fs.writeFileSync(agents,'# User-owned rules\n');
214
+ const run=open(f,'T-002','create',{reply:(kind,payload)=>{
215
+ const response=reply(f,kind,payload);
216
+ if(kind==='init_verify'){
217
+ if(scenario==='failed-verification')response.checks.commands.status='unverified';
218
+ if(scenario==='target-drift')fs.writeFileSync(agents,'# Concurrent user rules\n');
219
+ }
220
+ return response;
221
+ }});
222
+ const result=await run.effect('develop');assert.equal(result.state,'unknown');run.close();
223
+ assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
224
+ if(scenario==='failed-verification')assert.equal(fs.existsSync(agents),false);
225
+ else assert.match(fs.readFileSync(agents,'utf8'),/user|User/);
226
+ const before=[...f.calls],resumed=open(f,'T-002','resume');
227
+ assert.equal(resumed.runner.status().state,'unknown');resumed.close();assert.deepEqual(f.calls,before);
228
+ });
@@ -0,0 +1,233 @@
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 {openControlRun} from './cm-ai-run.mjs';
7
+ import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
8
+ import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
9
+ import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
10
+ import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
11
+ import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
12
+ import {qaFixIdentity} from '../runtime/js/cm-fix/qa-source.mjs';
13
+ import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
14
+ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
15
+ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
16
+ import {recordCmAiQaRun} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
17
+ import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
18
+ import {createFixHost} from '../runtime/js/cm-fix/host.mjs';
19
+
20
+ for(const mode of ['history','retest','unknown','failed-retest','double-pass','double-fail','automatic','automatic-explicit','automatic-cancel','automatic-observation'])test(`real parent owner switches through child repair: ${mode}`,async()=>{
21
+ const double=mode.startsWith('double-');
22
+ const automatic=mode.startsWith('automatic');
23
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-parent-fix-')));
24
+ const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.value';
25
+ fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
26
+ const identity={repositoryId:'fixture',runId:'parent-run',taskId:'T-001',attempt:1};
27
+ const definition={version:1,specsDir,codeProject,feature,identity,scope:['value.mjs'],requirements:['requirements.md']};
28
+ fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=0;');
29
+ fs.writeFileSync(path.join(codeProject,'requirements.md'),double?'Value should be 3.':'Value should be 2.');
30
+ if(double)fs.writeFileSync(path.join(codeProject,'red-second.mjs'),"import {value} from './value.mjs';if(value!==3){console.error('BUG');process.exit(1)}");
31
+ fs.writeFileSync(path.join(codeProject,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
32
+ fs.writeFileSync(path.join(codeProject,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
33
+ fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff',
34
+ ...(automatic?{auto_fix:mode==='automatic-explicit'?'explicit':'auto'}:{})}}));
35
+ for(const name of ['requirements','design'])fs.writeFileSync(path.join(specsDir,feature,`${name}.md`),'# Synthetic fixture');
36
+ fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: implement value\n');
37
+ fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature]}));
38
+ let developers=0,parentReviews=0,childReviews=0,repairs=0,qaRuns=0,parent=null,serial=null;
39
+ const events=(onEvent,thread)=>{
40
+ for(const event of [{event:'thread.started',provider_thread:thread},{event:'turn.started',item_type:null},
41
+ {event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},
42
+ {event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
43
+ };
44
+ const authority=createHostReviewAuthority({hostContextId:'parent-host',reviewerId:'reviewer',adapterId:'codex-review-adapter',decide:async()=>({status:'approved'})});
45
+ const execution={configuration:{kind:'synthetic-parent-fix'},timeoutMs:2000,excludedContexts:['parent-host'],hostDecision:null,
46
+ hostDecisionProvider:authority.hostDecisionProvider,
47
+ developer:{provider:'codex',requestedModel:'synthetic',contextId:'author',run:createCodexDeveloperRun({requestedModel:'synthetic',worker:async()=>{
48
+ developers++;fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;');
49
+ return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
50
+ retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
51
+ }})},
52
+ reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic',allowed:true,available:true,
53
+ contexts:['parent-review-1','parent-review-2'],run:async(request,{onEvent})=>{
54
+ parentReviews++;events(onEvent,'synthetic-parent-review');
55
+ return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
56
+ examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic parent review; QA exposes remaining defect'}};
57
+ }}],
58
+ reviewInvocation:{developerThreadId:'author',excludedThreadIds:['parent-host'],authorize:authority.authorize},
59
+ check:createHostCheck({cwd:codeProject,commands:[{id:'existing',command:[process.execPath,'existing.mjs']}]}),
60
+ qaLogHome:path.join(root,'logs'),qaDecisionProvider:{timeoutMs:1000,decide:async binding=>({decisionId:'qa-parent',identity:binding.identity,packageDigest:binding.packageDigest,
61
+ status:'triggered',reason:'feature_complete',score:null,at:'2026-09-08T01:00:00Z'})},
62
+ qaExecutor:{mode:'commands',caseCount:1,timeoutMs:1000,run:async binding=>{
63
+ qaRuns++;
64
+ if(qaRuns>1){
65
+ assert.equal(binding.qaRound,qaRuns);
66
+ if(mode==='unknown')throw Error('Synthetic QA interruption');
67
+ assert.equal(fs.readFileSync(path.join(codeProject,'value.mjs'),'utf8'),`export const value=${qaRuns};`);
68
+ const report=path.join(specsDir,'.reviews',`qa-retest-${qaRuns}.md`);fs.writeFileSync(report,`Synthetic QA round ${qaRuns}.`);
69
+ return mode==='failed-retest'||mode==='automatic-observation'||(double&&(qaRuns===2||mode==='double-fail'))?{result:'FAIL',passed:0,failed:1,blocked:0,report}
70
+ :{result:'PASS',passed:1,failed:0,blocked:0,report};
71
+ }
72
+ const report=path.join(specsDir,'.reviews','qa-failure.md');fs.writeFileSync(report,'Synthetic QA: value 1 does not satisfy expected 2.');
73
+ return {result:'FAIL',passed:0,failed:1,blocked:0,report};
74
+ }},...(mode==='retest'||double||automatic?{applicableAgentFiles:[],documentationProvider:{timeoutMs:1000,inspect:async binding=>({
75
+ syncId:binding.syncId,identity:binding.identity,packageDigest:binding.packageDigest,contextDigest:binding.contextDigest,
76
+ status:'completed',reason:'Synthetic documentation unchanged',at:'2026-09-08T02:00:00Z'})}}:{})};
77
+ const request=operation=>({version:1,requestId:operation,operation,identity});
78
+ try{
79
+ parent=await openControlRun(definition,'create',execution);
80
+ const failed=await parent.host.handle(request('advance'));
81
+ assert.equal(failed.code,'qa_failed',JSON.stringify(failed));
82
+ const tasksPath=path.join(specsDir,feature,'tasks.md'),tasks=fs.readFileSync(tasksPath);
83
+ assert(tasks.toString().includes('[x]'));
84
+ const handoff=failed.fixHandoff,qaSource={feature,identity,packageDigest:failed.packageDigest,
85
+ testRunId:handoff.source.testRunId,handoffDigest:handoff.handoffDigest};
86
+ const childIdentity=qaFixIdentity(qaSource),permissions=['--allow-red-test','--allow-baseline','--allow-repair',
87
+ '--allow-regression','--allow-final-review','--allow-walkthrough','--allow-finish'];
88
+ const review={model:'synthetic',disabledSkills:[],preflight:{passed:true,cli_model:'synthetic',prompt_transport:'stdin',
89
+ config_fingerprint:configFingerprint({cwd:codeProject,model:'synthetic',disabledSkills:[],promptTransport:'stdin'})}};
90
+ const reviewHost=createFixReviewHost({codeProject,hostContextId:'parent-host',review,permissions,workerFactory:()=>async({prompt},{onEvent})=>{
91
+ childReviews++;const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);events(onEvent,`synthetic-child-review-${childReviews}`);
92
+ return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,
93
+ examinedPaths:data.examinedPaths,findings:[],summary:'Synthetic independent child review'}};
94
+ }});
95
+ const configuration={hostContextId:'parent-host',qaSource,defect:'Value must be 2',causeReview:reviewHost.reviewer,
96
+ reproduction:{cwd:codeProject,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
97
+ redTest:{cwd:codeProject,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
98
+ baseline:{cwd:codeProject,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
99
+ repair:{scope:['value.mjs'],requirements:['requirements.md']},
100
+ walkthrough:{timeoutMs:2000,flows:[{id:'value',modules:['value'],steps:['Read value'],expected:['2'],kind:'commands',command:[process.execPath,'red.mjs']}]}};
101
+ const makeSerial=(parent,childIdentity,configuration,repairValue)=>createQaFixOwnerHost({parent,reopenParent:()=>openControlRun(definition,'resume',execution),
102
+ ...(double||automatic?{template:{specsRoot:specsDir,feature,identity,configuration:Object.fromEntries(Object.entries(configuration).filter(([key])=>key!=='qaSource'))}}
103
+ :{fix:{specsRoot:specsDir,identity:childIdentity,configuration}}),allowStart:true,autoFix:automatic,fixPermissions:permissions,
104
+ fixAuthorities:{authority:reviewHost.authority,finalAuthority:reviewHost.finalAuthority},fixExecution:{...reviewHost.execution,
105
+ prepare:async()=>({files:[],contextDigest:digest([]),application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'Fixture'}}),
106
+ bridge:{async call(kind){
107
+ if(kind==='fix_diagnose'&&mode==='automatic-cancel'){
108
+ assert.equal((await serial.handle(request('status'))).code,'qa_fix_active');
109
+ await assert.rejects(serial.handle(request('advance')),{code:'host_busy'});
110
+ await assert.rejects(serial.handle({...request('cancel'),identity:{...identity,runId:'wrong'}}),{code:'qa_fix_source_mismatch'});
111
+ assert.equal((await serial.handle(request('cancel'))).code,'qa_fix_active');
112
+ }
113
+ if(kind==='fix_diagnose')return {status:'diagnosed',rootCause:'Wrong constant',affectedPaths:['value.mjs'],affectedModules:['value'],
114
+ plan:`Change ${repairValue-1} to ${repairValue}`,crossLayer:false,investigation:{discardedAlternatives:[],boundaryAnalysis:null}};
115
+ if(kind==='fix_repair'){repairs++;fs.writeFileSync(path.join(codeProject,'value.mjs'),`export const value=${repairValue};`);return {outcome:'repaired'};}
116
+ if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};
117
+ throw Error(`Unexpected host capability: ${kind}`);
118
+ }}}});
119
+ serial=makeSerial(parent,childIdentity,configuration,2);parent=null;
120
+ if(automatic){
121
+ const result=await serial.handle(request('advance'));
122
+ const expected=mode==='automatic'?'run_done':mode==='automatic-explicit'?'qa_failed':'qa_fix_incomplete';
123
+ assert.equal(result.code,expected,JSON.stringify(result));
124
+ if(mode==='automatic-cancel')assert.equal(result.fixStage,'cancelled');
125
+ if(mode==='automatic-observation')assert.equal(result.fixStage,'observation');
126
+ const repaired=['automatic','automatic-observation'].includes(mode);
127
+ assert.equal(qaRuns,repaired?2:1);
128
+ assert.equal(repairs,repaired?1:0);assert.equal(childReviews,repaired?1:0);
129
+ assert.deepEqual(fs.readFileSync(tasksPath),tasks);
130
+ const again=await serial.handle(request('advance'));
131
+ assert.equal(again.code,expected,JSON.stringify(again));
132
+ assert.equal(qaRuns,repaired?2:1);assert.equal(developers,1);assert.equal(parentReviews,1);
133
+ return;
134
+ }
135
+ const bound={...request('fix_advance'),packageDigest:failed.packageDigest,testRunId:qaSource.testRunId};
136
+ assert.equal((await serial.handle(bound)).fixStage,'red_test_required');
137
+ let result;
138
+ for(const fixOperation of ['red_test','baseline','repair','regression','retrospective','handoff','final_review',
139
+ 'publish_review','check_n5','post_review_regression','walkthrough','finish']){
140
+ result=await serial.handle({...bound,operation:'fix_action',fixOperation});
141
+ assert.notEqual(result.fixStage,'unknown',`${fixOperation}: ${JSON.stringify(result)}`);
142
+ if(fixOperation==='repair')assert.equal((await serial.handle(request('status'))).code,'correction_review_required');
143
+ }
144
+ assert.equal(result.code,'qa_fix_completed',JSON.stringify(result));
145
+ assert.equal(result.association.kind,'cm-fix-code-association');
146
+ assert.equal(result.association.parentPackageDigest,failed.packageDigest);
147
+ assert.equal(result.association.fixPackageDigest,result.evidence.reviewPackage.packageDigest);
148
+ assert.equal(result.accepted.qaRound,1);
149
+ assert.deepEqual(result.accepted.evidence,result.evidence);
150
+ assert.deepEqual(result.evidence.qaSource,qaSource);
151
+ assert.equal(result.evidence.identity.runId,childIdentity.runId);
152
+ assert.deepEqual((await serial.handle({...bound,operation:'fix_status'})).evidence,result.evidence);
153
+ const resumed=await serial.handle(request('status'));
154
+ assert.equal(resumed.state,'fixture_completed');assert.equal(resumed.code,null);
155
+ assert.equal(resumed.packageDigest,failed.packageDigest);assert.deepEqual(fs.readFileSync(tasksPath),tasks);
156
+ assert.equal(qaRuns,1);
157
+ assert.equal(developers,1);assert.equal(parentReviews,1);assert.equal(childReviews,1);assert.equal(repairs,1);
158
+ serial.close();serial=null;
159
+ parent=await openControlRun(definition,'resume',execution);
160
+ const acceptedRevision=parent.checkpoint();
161
+ assert.deepEqual(parent.acceptCompletedFix(result.evidence),result.accepted);
162
+ assert.equal(parent.checkpoint(),acceptedRevision); // Resume/idempotence, not a second acceptance.
163
+ assert.equal((await parent.host.handle(request('status'))).code,null);
164
+ assert.equal(parent.checkpoint(),acceptedRevision); // Status remains read-only.
165
+ parent.close();parent=null;
166
+ if(double){
167
+ parent=await openControlRun(definition,'resume',execution);
168
+ const secondFailure=await parent.host.handle(request('advance'));
169
+ assert.equal(secondFailure.code,'qa_failed');assert.equal(secondFailure.fixHandoff.source.qaRound,2);
170
+ const nextSource={feature,identity,packageDigest:failed.packageDigest,
171
+ testRunId:secondFailure.fixHandoff.source.testRunId,handoffDigest:secondFailure.fixHandoff.handoffDigest};
172
+ const nextIdentity=qaFixIdentity(nextSource);
173
+ const nextConfiguration={...configuration,qaSource:nextSource,defect:'Remaining defect: value must be 3',
174
+ reproduction:{...configuration.reproduction,command:[process.execPath,'red-second.mjs']},
175
+ redTest:{...configuration.redTest,testFiles:['red-second.mjs'],command:[process.execPath,'red-second.mjs']},
176
+ walkthrough:{...configuration.walkthrough,flows:[{...configuration.walkthrough.flows[0],
177
+ expected:['3'],command:[process.execPath,'red-second.mjs']}]}};
178
+ serial=makeSerial(parent,nextIdentity,nextConfiguration,3);parent=null;
179
+ const nextBound={...bound,testRunId:nextSource.testRunId};
180
+ const second=await serial.handle({...nextBound,operation:'fix_run'});
181
+ assert.equal(second.code,'qa_fix_completed',JSON.stringify(second));assert.equal(second.accepted.qaRound,2);
182
+ serial.close();serial=null;
183
+ parent=await openControlRun(definition,'resume',execution);
184
+ assert.deepEqual(parent.acceptCompletedFix(second.evidence),second.accepted);
185
+ const third=await parent.host.handle(request('advance'));
186
+ assert.equal(third.code,mode==='double-pass'?'run_done':'qa_failed',JSON.stringify(third));
187
+ if(mode==='double-fail'){
188
+ assert.equal(third.fixHandoff.source.qaRound,3);
189
+ assert.equal(third.fixHandoff.status,'blocked');assert.equal(third.fixHandoff.reason,'qa_round_limit');
190
+ }
191
+ assert.equal(qaRuns,3);assert.equal(repairs,2);assert.equal(childReviews,2);
192
+ parent.close();parent=await openControlRun(definition,'resume',execution);
193
+ assert.equal((await parent.host.handle(request('advance'))).code,third.code);
194
+ assert.equal(qaRuns,3);assert.deepEqual(fs.readFileSync(tasksPath),tasks);
195
+ assert.equal(developers,1);assert.equal(parentReviews,1);
196
+ return;
197
+ }
198
+ if(mode!=='history'){
199
+ parent=await openControlRun(definition,'resume',execution);
200
+ const retested=await parent.host.handle(request('advance'));
201
+ assert.equal(retested.code,mode==='unknown'?'invalid_input':mode==='failed-retest'?'qa_failed':'run_done',JSON.stringify(retested));
202
+ if(mode==='failed-retest')assert.equal(retested.fixHandoff.source.qaRound,2);
203
+ assert.equal(qaRuns,2);
204
+ parent.close();parent=await openControlRun(definition,'resume',execution);
205
+ const repeated=await parent.host.handle(request('advance'));
206
+ assert.equal(repeated.code,mode==='unknown'?'qa_execution_unknown':mode==='failed-retest'?'qa_failed':'run_done',JSON.stringify(repeated));
207
+ assert.equal(qaRuns,2);assert.deepEqual(fs.readFileSync(tasksPath),tasks);
208
+ fs.writeFileSync(path.join(codeProject,'value.mjs'),'unreviewed drift');
209
+ assert.equal((await parent.host.handle(request('advance'))).code,'correction_review_required');
210
+ assert.equal(qaRuns,2);
211
+ return;
212
+ }
213
+ // A later QA must not erase the prior completed child's evidence. Use the
214
+ // existing log writer; this is not automatic parent re-QA implementation.
215
+ const nextQa={specsDir,codeProject,feature,identity,packageDigest:failed.packageDigest,
216
+ testRunId:'qa-round-two',qaRound:2,mode:'commands',caseCount:1,logHome:path.join(root,'logs')};
217
+ recordCmAiQaRun({...nextQa,phase:'start'});
218
+ const childOptions={specsRoot:specsDir,identity:childIdentity,configuration,create:false};
219
+ let reopened=openFixExecution(childOptions);
220
+ try{
221
+ assert.deepEqual(reopened.completionEvidence(),result.evidence);
222
+ const host=createFixHost({owner:reopened,config:{...configuration,specsRoot:specsDir,identity:childIdentity},permissions:['--allow-reproduction']});
223
+ assert.deepEqual(await host.handle({requestId:'history',operation:'completion_evidence'}),result.evidence);
224
+ await assert.rejects(host.handle({requestId:'stale-action',operation:'advance'}),{code:'qa_result_stale'});
225
+ }finally{reopened.close();}
226
+ const passedReport=path.join(specsDir,'.reviews','qa-second.md');fs.writeFileSync(passedReport,'Synthetic second round PASS');
227
+ recordCmAiQaRun({...nextQa,phase:'complete',result:{result:'PASS',passed:1,failed:0,blocked:0,report:passedReport}});
228
+ reopened=openFixExecution(childOptions);
229
+ try{assert.deepEqual(reopened.completionEvidence(),result.evidence);}finally{reopened.close();}
230
+ fs.appendFileSync(handoff.source.report,'tampered historical report');
231
+ assert.throws(()=>openFixExecution(childOptions),{code:'fix_qa_source_changed'});
232
+ }finally{serial?.close();parent?.close();fs.rmSync(root,{recursive:true,force:true});}
233
+ });