@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,312 @@
1
+ #!/usr/bin/env python3
2
+ """Compatibility lock adapter for the JavaScript CM task gate."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ from contextlib import contextmanager
8
+ import hashlib
9
+ import json
10
+ import os
11
+ from pathlib import Path
12
+ import re
13
+ import sqlite3
14
+ import stat
15
+ import subprocess
16
+ import sys
17
+ from typing import Iterator, Mapping, Sequence
18
+
19
+
20
+ class GateError(ValueError):
21
+ """Expected lock-adapter failure."""
22
+
23
+
24
+ def sync_control_path(path: Path) -> None:
25
+ descriptor = os.open(path, os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0))
26
+ try:
27
+ os.fsync(descriptor)
28
+ finally:
29
+ os.close(descriptor)
30
+
31
+
32
+ def control_directory(path: Path, *, create: bool = False, private: bool = False) -> os.stat_result:
33
+ if create:
34
+ try:
35
+ path.mkdir(mode=0o700)
36
+ sync_control_path(path)
37
+ sync_control_path(path.parent)
38
+ except FileExistsError:
39
+ pass
40
+ info = path.lstat()
41
+ if not stat.S_ISDIR(info.st_mode) or (private and info.st_mode & 0o077):
42
+ raise GateError(f"unsupported control directory: {path}")
43
+ return info
44
+
45
+
46
+ def private_control_file(path: Path, limit: int) -> os.stat_result:
47
+ info = path.lstat()
48
+ if not stat.S_ISREG(info.st_mode) or info.st_nlink != 1 or info.st_mode & 0o077 or info.st_size > limit:
49
+ raise GateError(f"unsupported private control file: {path}")
50
+ return info
51
+
52
+
53
+ def file_revision(path: Path) -> tuple[tuple[int, ...], bytes]:
54
+ def identity(info: os.stat_result) -> tuple[int, ...]:
55
+ return (info.st_dev, info.st_ino, info.st_mode, info.st_nlink, info.st_size, info.st_mtime_ns, info.st_ctime_ns)
56
+
57
+ before = path.lstat()
58
+ if not stat.S_ISREG(before.st_mode):
59
+ raise GateError(f"revision source must be a regular non-symlink file: {path}")
60
+ with path.open("rb") as handle:
61
+ opened = os.fstat(handle.fileno())
62
+ content = handle.read()
63
+ after = os.fstat(handle.fileno())
64
+ if not identity(before) == identity(opened) == identity(after) == identity(path.lstat()):
65
+ raise GateError(f"revision changed while reading: {path}")
66
+ return identity(after), content
67
+
68
+
69
+ def bind_task_owner(tasks: Path, root: Path, feature: str) -> tuple[Path, tuple[tuple[int, ...], bytes]]:
70
+ tasks = tasks.resolve()
71
+ info = tasks.lstat()
72
+ if tasks.name != "tasks.md" or not stat.S_ISREG(info.st_mode) or info.st_nlink != 1:
73
+ raise GateError("task owner requires regular non-hardlinked tasks.md")
74
+ parent = tasks.parent
75
+ suffix = "." + feature
76
+ numbered = parent.name.endswith(suffix) and re.fullmatch(r"[0-9]+", parent.name[: -len(suffix)])
77
+ if parent != root and not (parent.parent == root and (parent.name == feature or numbered)):
78
+ raise GateError("unsupported owner layout (numbered prefixes require ASCII digits)")
79
+ reviews = parent / ".reviews"
80
+ control_directory(reviews, create=True)
81
+ binding = reviews / ".cm-task-owner.json"
82
+ expected = (json.dumps({"version": 1, "tasksPath": str(tasks), "specsRoot": str(root)}, ensure_ascii=False, separators=(",", ":")) + "\n").encode("utf-8")
83
+ if len(expected) > 16384:
84
+ raise GateError("task owner binding exceeds limit")
85
+ try:
86
+ descriptor = os.open(binding, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0), 0o600)
87
+ with os.fdopen(descriptor, "wb") as handle:
88
+ handle.write(expected)
89
+ handle.flush()
90
+ os.fsync(handle.fileno())
91
+ except FileExistsError:
92
+ pass
93
+ private_control_file(binding, 16384)
94
+ revision = file_revision(binding)
95
+ if revision[1] != expected:
96
+ raise GateError("task owner mismatch or corrupt binding; refusing rebind")
97
+ sync_control_path(binding)
98
+ sync_control_path(reviews)
99
+ sync_control_path(parent)
100
+ if file_revision(binding) != revision:
101
+ raise GateError("task owner binding changed")
102
+ return binding, revision
103
+
104
+
105
+ def writer_database_digest(lock: Path, descriptor: int) -> str:
106
+ before = private_control_file(lock, 65536)
107
+ opened = os.fstat(descriptor)
108
+ content = os.pread(descriptor, 65537, 0)
109
+ after = os.fstat(descriptor)
110
+ current = lock.lstat()
111
+ key = lambda value: (value.st_dev, value.st_ino, value.st_size, value.st_mtime_ns, value.st_ctime_ns)
112
+ if not key(before) == key(opened) == key(after) == key(current) or len(content) != before.st_size:
113
+ raise GateError("writer database changed")
114
+ return hashlib.sha256(content).hexdigest()
115
+
116
+
117
+ def writer_ready(lock: Path, descriptor: int) -> tuple[Path, tuple[tuple[int, ...], bytes]]:
118
+ marker = lock.parent / "writer-ready.json"
119
+ private_control_file(marker, 1024)
120
+ revision = file_revision(marker)
121
+ expected = (json.dumps({"version": 1, "protocol": "cm-writer-ready", "databaseDigest": writer_database_digest(lock, descriptor)}, separators=(",", ":")) + "\n").encode("utf-8")
122
+ if revision[1] != expected:
123
+ raise GateError("invalid writer readiness; refusing recovery/adoption")
124
+ if file_revision(marker) != revision:
125
+ raise GateError("writer readiness changed")
126
+ return marker, revision
127
+
128
+
129
+ def publish_writer_ready(lock: Path, descriptor: int) -> None:
130
+ if os.path.lexists(str(lock) + "-journal"):
131
+ raise GateError("retained initialization journal")
132
+ private_control_file(lock, 65536)
133
+ payload = (json.dumps({"version": 1, "protocol": "cm-writer-ready", "databaseDigest": writer_database_digest(lock, descriptor)}, separators=(",", ":")) + "\n").encode("utf-8")
134
+ descriptor_out = os.open(lock.parent / "writer-ready.json", os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0), 0o600)
135
+ with os.fdopen(descriptor_out, "wb") as handle:
136
+ handle.write(payload)
137
+ handle.flush()
138
+ os.fsync(handle.fileno())
139
+ sync_control_path(lock.parent)
140
+
141
+
142
+ @contextmanager
143
+ def posix_writer(reviews: Path, tasks: Path, feature: str) -> Iterator[Path]:
144
+ root = reviews.resolve().parent
145
+ execution = reviews / ".execution"
146
+ database = None
147
+ inspection_fd = None
148
+ try:
149
+ if reviews.name != ".reviews":
150
+ raise GateError("task ownership requires the canonical .reviews directory")
151
+ control_directory(reviews)
152
+ binding, binding_revision = bind_task_owner(tasks, root, feature)
153
+ control_directory(execution, create=True, private=True)
154
+ for item in execution.iterdir():
155
+ if item.name not in {"writer.sqlite", "writer-ready.json"}:
156
+ raise GateError("retained journal, JS run or unknown evidence blocks compatibility writer")
157
+ private_control_file(item, 65536)
158
+ lock = execution / "writer.sqlite"
159
+ created = False
160
+ if not os.path.lexists(lock):
161
+ if list(execution.iterdir()):
162
+ raise GateError("missing writer database with retained execution evidence")
163
+ try:
164
+ descriptor = os.open(lock, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0), 0o600)
165
+ os.fsync(descriptor)
166
+ os.close(descriptor)
167
+ sync_control_path(execution)
168
+ created = True
169
+ except FileExistsError:
170
+ pass
171
+ info = private_control_file(lock, 65536)
172
+ if not created and info.st_size == 0:
173
+ raise GateError("incomplete writer database")
174
+ inspection_fd = os.open(lock, os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0))
175
+ prior_ready = None
176
+ if os.path.lexists(str(lock) + "-journal"):
177
+ raise GateError("retained initialization journal")
178
+ if not created:
179
+ marker, prior_ready = writer_ready(lock, inspection_fd)
180
+ os.fsync(inspection_fd)
181
+ sync_control_path(marker)
182
+ sync_control_path(execution)
183
+ database = sqlite3.connect(str(lock), timeout=0, isolation_level=None)
184
+ database.executescript("PRAGMA busy_timeout=0; PRAGMA trusted_schema=OFF; PRAGMA synchronous=EXTRA; PRAGMA fullfsync=ON;")
185
+ protocol_sql = "CREATE TABLE protocol(version INTEGER NOT NULL CHECK(version=1))"
186
+ if created:
187
+ database.executescript("BEGIN IMMEDIATE; PRAGMA application_id=1129142321; PRAGMA user_version=1; " + protocol_sql + "; INSERT INTO protocol VALUES(1); COMMIT;")
188
+ os.fsync(inspection_fd)
189
+ sync_control_path(execution)
190
+ database.execute("BEGIN IMMEDIATE")
191
+ if (database.execute("PRAGMA application_id").fetchone() != (0x434D5831,) or database.execute("PRAGMA user_version").fetchone() != (1,) or database.execute("PRAGMA journal_mode").fetchone() != ("delete",) or database.execute("SELECT name,type,tbl_name,sql FROM sqlite_master").fetchall() != [("protocol", "table", "protocol", protocol_sql)] or database.execute("SELECT version FROM protocol").fetchall() != [(1,)]):
192
+ raise GateError("unknown writer protocol; refusing reset")
193
+ if created:
194
+ publish_writer_ready(lock, inspection_fd)
195
+ marker, current_ready = writer_ready(lock, inspection_fd)
196
+ if prior_ready is not None and prior_ready != current_ready:
197
+ raise GateError("writer readiness changed")
198
+ if file_revision(binding) != binding_revision or file_revision(marker) != current_ready:
199
+ raise GateError("task ownership evidence changed")
200
+ yield lock.resolve()
201
+ except (OSError, sqlite3.Error) as error:
202
+ raise GateError(f"task writer unavailable: {error}") from error
203
+ finally:
204
+ if database is not None:
205
+ database.close()
206
+ if inspection_fd is not None:
207
+ os.close(inspection_fd)
208
+
209
+
210
+ @contextmanager
211
+ def windows_writer(reviews: Path) -> Iterator[Path]:
212
+ import msvcrt
213
+
214
+ if reviews.name != ".reviews" or not reviews.is_dir() or reviews.is_symlink():
215
+ raise GateError("task ownership requires the canonical .reviews directory")
216
+ lock = reviews / ".cm-task-write.lock"
217
+ descriptor = os.open(lock, os.O_RDWR | os.O_CREAT | getattr(os, "O_BINARY", 0), 0o600)
218
+ try:
219
+ if os.fstat(descriptor).st_size == 0:
220
+ os.write(descriptor, b"0")
221
+ os.fsync(descriptor)
222
+ os.lseek(descriptor, 0, os.SEEK_SET)
223
+ msvcrt.locking(descriptor, msvcrt.LK_LOCK, 1)
224
+ yield lock.resolve()
225
+ except OSError as error:
226
+ raise GateError(f"task writer unavailable: {error}") from error
227
+ finally:
228
+ try:
229
+ os.lseek(descriptor, 0, os.SEEK_SET)
230
+ msvcrt.locking(descriptor, msvcrt.LK_UNLCK, 1)
231
+ except OSError:
232
+ pass
233
+ os.close(descriptor)
234
+
235
+
236
+ @contextmanager
237
+ def task_writer(reviews: Path, tasks: Path, feature: str) -> Iterator[Path]:
238
+ if os.name == "nt":
239
+ with windows_writer(reviews) as lock:
240
+ yield lock
241
+ else:
242
+ with posix_writer(reviews, tasks, feature) as lock:
243
+ yield lock
244
+
245
+
246
+ def run_js(arguments: Sequence[str], *, environment: Mapping[str, str] | None = None, capture: bool = False):
247
+ entry = Path(__file__).resolve().with_name("cm-task-gate.mjs")
248
+ return subprocess.run(["node", str(entry), *arguments], check=False, text=True, capture_output=capture, env=dict(environment) if environment is not None else None)
249
+
250
+
251
+ def read_js_object(arguments: Sequence[str], *, environment: Mapping[str, str] | None = None) -> dict[str, object]:
252
+ result = run_js(arguments, environment=environment, capture=True)
253
+ if result.returncode != 0:
254
+ detail = result.stderr.strip() or result.stdout.strip() or "JavaScript task gate failed"
255
+ raise GateError(detail.removeprefix("ERROR: "))
256
+ try:
257
+ value = json.loads(result.stdout)
258
+ except json.JSONDecodeError as error:
259
+ raise GateError("JavaScript task gate returned invalid JSON") from error
260
+ if not isinstance(value, dict):
261
+ raise GateError("JavaScript task gate returned a non-object result")
262
+ return value
263
+
264
+
265
+ def mark_parser() -> argparse.ArgumentParser:
266
+ parser = argparse.ArgumentParser(prog="cm-task-gate.py")
267
+ parser.add_argument("command", choices=["mark-done"])
268
+ parser.add_argument("--handoff", required=True)
269
+ parser.add_argument("--reviews-dir", required=True)
270
+ parser.add_argument("--feature", required=True)
271
+ parser.add_argument("--task", required=True)
272
+ parser.add_argument("--tasks", required=True)
273
+ parser.add_argument("--project-root")
274
+ parser.add_argument("--allow-legacy-unbound", action="store_true")
275
+ parser.add_argument("--require-learning", action="store_true")
276
+ return parser
277
+
278
+
279
+ def mark_done(raw_arguments: Sequence[str]) -> dict[str, object]:
280
+ args = mark_parser().parse_args(raw_arguments)
281
+ prepare_arguments = ["prepare-mark-done", *raw_arguments[1:]]
282
+ initial = read_js_object(prepare_arguments)
283
+ tasks = Path(str(initial.get("tasksPath", "")))
284
+ if not tasks.is_absolute():
285
+ raise GateError("JavaScript task gate returned an invalid completion plan")
286
+ reviews = Path(args.reviews_dir).resolve()
287
+ with task_writer(reviews, tasks, args.feature) as lock:
288
+ plan = read_js_object(prepare_arguments)
289
+ plan_digest = str(plan.get("planDigest", ""))
290
+ if Path(str(plan.get("tasksPath", ""))) != tasks or not re.fullmatch(r"[0-9a-f]{64}", plan_digest):
291
+ raise GateError("JavaScript task gate returned an invalid completion plan")
292
+ environment = os.environ.copy()
293
+ environment.update({"CM_TASK_GATE_LOCK_ADAPTER": "1", "CM_TASK_GATE_LOCK_PARENT_PID": str(os.getpid()), "CM_TASK_GATE_WRITER_LOCK": str(lock)})
294
+ return read_js_object(["mark-done-locked", *raw_arguments[1:], "--expected-plan-digest", plan_digest], environment=environment)
295
+
296
+
297
+ def main(argv: Sequence[str] | None = None) -> int:
298
+ raw_arguments = list(argv) if argv is not None else sys.argv[1:]
299
+ if not raw_arguments or raw_arguments[0] != "mark-done":
300
+ result = run_js(raw_arguments)
301
+ return result.returncode if result.returncode >= 0 else 128 - result.returncode
302
+ try:
303
+ result = mark_done(raw_arguments)
304
+ except GateError as error:
305
+ print(f"ERROR: {error}", file=sys.stderr)
306
+ return 1
307
+ print(json.dumps(result, ensure_ascii=False, separators=(",", ":")))
308
+ return 0
309
+
310
+
311
+ if __name__ == "__main__":
312
+ raise SystemExit(main())
@@ -0,0 +1,202 @@
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 {createHash} from 'node:crypto';
7
+ import {spawn,spawnSync} from 'node:child_process';
8
+ import {fileURLToPath} from 'node:url';
9
+
10
+ import {
11
+ GateError,checkN4,checkN5,implementationSha256,loadHandoff,prepareMarkDone,verifyMarkDonePlan,
12
+ checkParallelWrite,markDoneLocked,
13
+ } from './cm-task-gate.mjs';
14
+
15
+ const scriptsRoot=fileURLToPath(new URL('.',import.meta.url));
16
+ const jsGate=path.join(scriptsRoot,'cm-task-gate.mjs');
17
+ const pythonGate=path.join(scriptsRoot,'cm-task-gate.py');
18
+
19
+ async function fixture(run){
20
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-task-gate-js-')));
21
+ try{return await run(root);}finally{fs.rmSync(root,{recursive:true,force:true});}
22
+ }
23
+
24
+ function writeHandoff(file,{attempt=1,status='ready_for_review',task='T-001',implementation=null}={}){
25
+ const payload={
26
+ schema_version:1,
27
+ task_id:task,
28
+ attempt,
29
+ status,
30
+ changed_files:['src/example.ts'],
31
+ verification:[{command:'npm test -- example',status:'passed',evidence:'tests passed'}],
32
+ evidence:['src/example.ts','tests passed'],
33
+ blockers:status==='blocked'?['needs input']:[],
34
+ scope_deviation:[],
35
+ };
36
+ if(implementation!==null)payload.implementation_sha256=implementation;
37
+ fs.writeFileSync(file,`${JSON.stringify(payload,null,2)}\n`);
38
+ }
39
+
40
+ function writeReview(file,{handoff,attempt=1,verdict='approved',task='T-001'}={}){
41
+ const digest=createHash('sha256').update(fs.readFileSync(handoff)).digest('hex');
42
+ const blocking=verdict==='approved'?0:1;
43
+ const body=verdict==='approved'?'Zero findings.':'Changes are required.';
44
+ fs.writeFileSync(file,`---
45
+ at: 2026-09-06T07:00:00-07:00
46
+ reviewer: codex-subagent
47
+ independent: true
48
+ task: ${task}
49
+ attempt: ${attempt}
50
+ round: ${attempt}
51
+ verdict: ${verdict}
52
+ blocking_findings: ${blocking}
53
+ handoff: ${path.basename(handoff)}
54
+ handoff_sha256: ${digest}
55
+ scope:
56
+ - src/example.ts
57
+ ---
58
+
59
+ ${body}
60
+ `);
61
+ }
62
+
63
+ test('Skill Learning gate rejects missing or pending records and binds reviewed writeback',()=>fixture(root=>{
64
+ const reviews=path.join(root,'.reviews');fs.mkdirSync(reviews);
65
+ fs.mkdirSync(path.join(root,'src'));fs.writeFileSync(path.join(root,'src/example.ts'),'fixture');
66
+ const handoff=path.join(reviews,'login-T-001-a1-handoff.json'),review=path.join(reviews,'login-T-001-r1.md');
67
+ const tasks=path.join(root,'tasks.md');fs.writeFileSync(tasks,'- [ ] T-001: fixture\n');
68
+ writeHandoff(handoff,{implementation:implementationSha256(root,['src/example.ts'])});
69
+ const options={handoff,reviewsDir:reviews,feature:'login',task:'T-001',projectRoot:root,requireLearning:true};
70
+ assert.throws(()=>checkN4(options),/Learning/);
71
+ const payload=JSON.parse(fs.readFileSync(handoff));
72
+ const save=()=>{fs.writeFileSync(handoff,JSON.stringify(payload));writeReview(review,{handoff});};
73
+ payload.evidence=['learning: no_relevant_lesson','learning: retrospective writeback_pending'];save();
74
+ assert.throws(()=>checkN5(options),/Learning/);
75
+ payload.evidence[1]='learning: retrospective no_new_lesson';save();
76
+ assert.equal(checkN4(options).outcome,'ready_for_review');
77
+ assert.equal(checkN5(options).outcome,'approved');
78
+ payload.evidence[1]='learning: retrospective written AGENTS.md';save();
79
+ assert.throws(()=>checkN5(options),/AGENTS/);
80
+ fs.writeFileSync(path.join(root,'AGENTS.md'),'# A reviewed lesson\n');payload.changed_files.push('AGENTS.md');
81
+ payload.implementation_sha256=implementationSha256(root,payload.changed_files);save();
82
+ fs.writeFileSync(review,fs.readFileSync(review,'utf8').replace(' - src/example.ts',' - src/example.ts\n - AGENTS.md'));
83
+ assert.equal(checkN5(options).outcome,'approved');
84
+ fs.appendFileSync(path.join(root,'AGENTS.md'),'unreviewed');
85
+ assert.throws(()=>checkN5(options),/content changed/);
86
+ payload.evidence=['learning: no_relevant_lesson','learning: retrospective no_new_lesson'];
87
+ payload.changed_files=['src/example.ts'];payload.implementation_sha256=implementationSha256(root,payload.changed_files);save();
88
+ const args=['mark-done','--require-learning','--handoff',handoff,'--reviews-dir',reviews,'--feature','login','--task','T-001','--tasks',tasks,'--project-root',root];
89
+ payload.evidence=['synthetic implementation check passed'];save();
90
+ assert.equal(checkN5({...options,requireLearning:false}).outcome,'approved');
91
+ const blocked=spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonGate,...args],{encoding:'utf8'});
92
+ assert.notEqual(blocked.status,0);assert.match(blocked.stderr,/Learning/);
93
+ assert.match(fs.readFileSync(tasks,'utf8'),/\[ \]/);
94
+ // Exercise the locked JS entry independently of Python's earlier prepare rejection.
95
+ const selectors={...options,tasksPath:tasks},legacyPlan=prepareMarkDone({...selectors,requireLearning:false});
96
+ const lock=process.platform==='win32'?path.join(reviews,'.cm-task-write.lock'):path.join(reviews,'.execution','writer.sqlite');
97
+ fs.mkdirSync(path.dirname(lock),{recursive:true,mode:0o700});const madeLock=!fs.existsSync(lock);
98
+ if(madeLock)fs.writeFileSync(lock,'');
99
+ try{assert.throws(()=>markDoneLocked(selectors,legacyPlan.planDigest,{
100
+ CM_TASK_GATE_LOCK_ADAPTER:'1',CM_TASK_GATE_LOCK_PARENT_PID:String(process.ppid),CM_TASK_GATE_WRITER_LOCK:lock}),/Learning/);
101
+ }finally{if(madeLock)fs.unlinkSync(lock);}
102
+ assert.match(fs.readFileSync(tasks,'utf8'),/\[ \]/);
103
+ payload.evidence=['learning: no_relevant_lesson','learning: retrospective no_new_lesson'];save();
104
+ const done=spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonGate,...args],{encoding:'utf8'});
105
+ assert.equal(done.status,0,done.stderr);assert.match(fs.readFileSync(tasks,'utf8'),/\[x\]/);
106
+ }));
107
+
108
+ test('JS read-only task gate handles the full attempt-2 N4/N5 chain',()=>fixture(root=>{
109
+ const reviews=path.join(root,'.reviews');fs.mkdirSync(reviews);
110
+ const handoff1=path.join(reviews,'login-T-001-a1-handoff.json');
111
+ const review1=path.join(reviews,'login-T-001-r1.md');
112
+ const handoff2=path.join(reviews,'login-T-001-a2-handoff.json');
113
+ const review2=path.join(reviews,'login-T-001-r2.md');
114
+ writeHandoff(handoff1);writeReview(review1,{handoff:handoff1,verdict:'changes_requested'});
115
+ writeHandoff(handoff2,{attempt:2});writeReview(review2,{handoff:handoff2,attempt:2});
116
+ const tasks=path.join(root,'tasks.md');fs.writeFileSync(tasks,'标题\r\n- [ ] T-001: 中文任务\r- [ ] T-010: unrelated\n');
117
+
118
+ assert.equal(checkN4({handoff:handoff2,reviewsDir:reviews,feature:'login',task:'T-001',allowLegacyUnbound:true}).outcome,'ready_for_review');
119
+ assert.equal(checkN5({handoff:handoff2,reviewsDir:reviews,feature:'login',task:'T-001',allowLegacyUnbound:true}).outcome,'approved');
120
+
121
+ const args=['check-n5','--handoff',handoff2,'--reviews-dir',reviews,'--feature','login','--task','T-001','--allow-legacy-unbound'];
122
+ const js=spawnSync(process.execPath,[jsGate,...args],{encoding:'utf8'});
123
+ const py=spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonGate,...args],{encoding:'utf8'});
124
+ assert.equal(js.status,0);assert.equal(py.status,0);
125
+ assert.deepEqual(JSON.parse(js.stdout),JSON.parse(py.stdout));
126
+
127
+ const selectors={handoff:handoff2,reviewsDir:reviews,feature:'login',task:'T-001',tasksPath:tasks,allowLegacyUnbound:true};
128
+ const plan=prepareMarkDone(selectors);
129
+ assert.equal(Buffer.from(plan.afterBase64,'base64').toString(),'标题\r\n- [x] T-001: 中文任务\r- [ ] T-010: unrelated\n');
130
+ assert.deepEqual(verifyMarkDonePlan(selectors,plan.planDigest),{outcome:'matched',planDigest:plan.planDigest});
131
+ const planArgs=['prepare-mark-done',...args.slice(1),'--tasks',tasks];
132
+ const jsPlan=spawnSync(process.execPath,[jsGate,...planArgs],{encoding:'utf8'});
133
+ const pyPlan=spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonGate,...planArgs],{encoding:'utf8'});
134
+ assert.equal(jsPlan.status,0);assert.equal(pyPlan.status,0);
135
+ assert.deepEqual(JSON.parse(jsPlan.stdout),JSON.parse(pyPlan.stdout));
136
+ fs.appendFileSync(tasks,'changed\n');
137
+ assert.throws(()=>verifyMarkDonePlan(selectors,plan.planDigest),GateError);
138
+ fs.writeFileSync(tasks,'标题\r\n- [ ] T-001: 中文任务\r- [ ] T-010: unrelated\n');
139
+ const marked=spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonGate,'mark-done',...args.slice(1),'--tasks',tasks],{encoding:'utf8'});
140
+ assert.equal(marked.status,0,marked.stderr);assert.equal(JSON.parse(marked.stdout).outcome,'marked_done');
141
+ assert.match(fs.readFileSync(tasks,'utf8'),/- \[x\] T-001/);
142
+ }));
143
+
144
+ test('JS read-only task gate rejects malformed handoff and non-approved N5 evidence',()=>fixture(root=>{
145
+ const reviews=path.join(root,'.reviews');fs.mkdirSync(reviews);
146
+ const duplicate=path.join(reviews,'login-T-001-a1-handoff.json');
147
+ fs.writeFileSync(duplicate,'{"schema_version":1,"schema_version":1}\n');
148
+ assert.throws(()=>loadHandoff(duplicate,{task:'T-001',attempt:1}),GateError);
149
+ fs.writeFileSync(duplicate,'{"schema_version":1.0,"task_id":"T-001","attempt":1,"status":"ready_for_review","changed_files":[],"verification":[{"command":"test","status":"passed","evidence":"passed"}],"evidence":["passed"],"blockers":[],"scope_deviation":[]}\n');
150
+ assert.throws(()=>loadHandoff(duplicate,{task:'T-001',attempt:1}),GateError);
151
+
152
+ writeHandoff(duplicate);
153
+ writeReview(path.join(reviews,'login-T-001-r1.md'),{handoff:duplicate,verdict:'changes_requested'});
154
+ assert.throws(()=>checkN5({handoff:duplicate,reviewsDir:reviews,feature:'login',task:'T-001',allowLegacyUnbound:true}),GateError);
155
+ }));
156
+
157
+ test('JS task gate binds N4/N5 to current implementation bytes and rejects drift',()=>fixture(root=>{
158
+ const project=path.join(root,'project'),reviews=path.join(root,'.reviews');
159
+ fs.mkdirSync(path.join(project,'src'),{recursive:true});fs.mkdirSync(reviews);
160
+ const source=path.join(project,'src','example.ts');fs.writeFileSync(source,'export const value = 1;\n');
161
+ const digest=implementationSha256(project,['src/example.ts']);
162
+ const handoff=path.join(reviews,'bound-T-001-a1-handoff.json');
163
+ writeHandoff(handoff,{implementation:digest});writeReview(path.join(reviews,'bound-T-001-r1.md'),{handoff});
164
+ const selectors={handoff,reviewsDir:reviews,feature:'bound',task:'T-001',projectRoot:project};
165
+ assert.equal(checkN4(selectors).content_bound,true);assert.equal(checkN5(selectors).content_bound,true);
166
+ const cli=spawnSync(process.execPath,[jsGate,'hash-implementation','--project-root',project,'--file','src/example.ts'],{encoding:'utf8'});
167
+ assert.equal(cli.status,0,cli.stderr);assert.equal(JSON.parse(cli.stdout).implementation_sha256,digest);
168
+ fs.writeFileSync(source,'export const value = 2;\n');
169
+ assert.throws(()=>checkN5(selectors),/implementation content changed after handoff/);
170
+ }));
171
+
172
+ test('JS parallel-write gate accepts isolated worktrees and rejects duplicate assignments',()=>fixture(root=>{
173
+ const repo=path.join(root,'repo'),worktree=path.join(root,'worker');fs.mkdirSync(repo);
174
+ const git=(directory,...args)=>{
175
+ const result=spawnSync('git',['-C',directory,...args],{encoding:'utf8'});
176
+ assert.equal(result.status,0,result.stderr);return result.stdout.trim();
177
+ };
178
+ git(repo,'init','-b','main');git(repo,'config','user.name','CM Fixture');git(repo,'config','user.email','fixture@example.invalid');
179
+ fs.writeFileSync(path.join(repo,'fixture.txt'),'fixture\n');git(repo,'add','fixture.txt');git(repo,'commit','-m','fixture');
180
+ git(repo,'worktree','add','-b','worker',worktree);
181
+ const assignments=[`T-001=${repo}`,`T-002=${worktree}`];
182
+ assert.equal(checkParallelWrite({repo,assignment:assignments}).outcome,'isolated');
183
+ assert.throws(()=>checkParallelWrite({repo,assignment:[assignments[0],`T-001=${worktree}`]}),GateError);
184
+ }));
185
+
186
+ test('Windows lock serializes two task completions without losing either checkbox',{skip:process.platform!=='win32'},()=>fixture(async root=>{
187
+ const reviews=path.join(root,'.reviews');fs.mkdirSync(reviews);
188
+ const tasks=path.join(root,'tasks.md');fs.writeFileSync(tasks,'- [ ] T-001: first\r\n- [ ] T-002: second\r\n');
189
+ const launch=task=>{
190
+ const handoff=path.join(reviews,`login-${task}-a1-handoff.json`);
191
+ writeHandoff(handoff,{task});writeReview(path.join(reviews,`login-${task}-r1.md`),{handoff,task});
192
+ const child=spawn(process.env.CM_PYTHON_BIN||'python3',[pythonGate,'mark-done','--handoff',handoff,
193
+ '--reviews-dir',reviews,'--feature','login','--task',task,'--tasks',tasks,'--allow-legacy-unbound'],{stdio:['ignore','pipe','pipe']});
194
+ return new Promise((resolve,reject)=>{
195
+ let stdout='',stderr='';child.stdout.on('data',chunk=>stdout+=chunk);child.stderr.on('data',chunk=>stderr+=chunk);
196
+ child.on('error',reject);child.on('close',status=>resolve({status,stdout,stderr}));
197
+ });
198
+ };
199
+ const results=await Promise.all([launch('T-001'),launch('T-002')]);
200
+ for(const result of results)assert.equal(result.status,0,result.stderr);
201
+ assert.equal(fs.readFileSync(tasks,'utf8'),'- [x] T-001: first\r\n- [x] T-002: second\r\n');
202
+ }));
@@ -0,0 +1,18 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {inspectDeclaredTestCommand} from '../runtime/js/cm-test/declared-command.mjs';
4
+ const sources=[{path:'package.json',sha256:'fixture-digest',content:JSON.stringify({scripts:{test:'node --test',
5
+ pretest:'node scripts/prepare.mjs',posttest:'node scripts/cleanup.mjs',typecheck:'tsc --noEmit'}})}];
6
+ const item=command=>({command,declaration:{path:'package.json',line:1}});
7
+ test('package script declarations preserve original argv and disclose lifecycle scripts',()=>{
8
+ for(const manager of ['npm','pnpm','yarn','bun'])for(const argv of [...(manager==='bun'?[]:[[manager,'test']]),[manager,'run','test'],[manager,'run','typecheck','--','--pretty','false']]){
9
+ const before=[...argv],result=inspectDeclaredTestCommand(item(argv),sources);
10
+ assert.equal(result.kind,'package-script');assert.deepEqual(argv,before);
11
+ if(result.script==='test')assert.deepEqual(Object.keys(result.lifecycle),['pretest','test','posttest']);
12
+ }
13
+ });
14
+ test('package declaration cannot authorize install, missing scripts, prefix/workspace or if-present flags',()=>{
15
+ for(const argv of [['npm','install'],['pnpm','dlx','vitest'],['npm','--prefix','/tmp','test'],['npm','run','missing'],
16
+ ['npm','run','test','--if-present'],['bun','test'],['yarn','workspace','other','test'],['sh','-c','npm test']])
17
+ assert.throws(()=>inspectDeclaredTestCommand(item(argv),sources));
18
+ });