@aibyzero/cm-workflow 0.17.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +23 -0
  3. package/CHANGELOG.md +242 -0
  4. package/README.md +20 -3
  5. package/THIRD_PARTY_NOTICES.md +13 -0
  6. package/VERSION +1 -1
  7. package/compat/claude-commands/cm-challenge.md +3 -0
  8. package/docs/architecture.md +11 -0
  9. package/docs/cm-control-policy-v2.md +127 -9
  10. package/docs/installation.md +310 -4
  11. package/docs/js-workflow-control.md +150 -15
  12. package/docs/live-evidence-drivers.md +28 -4
  13. package/docs/out-of-scope/README.md +25 -0
  14. package/docs/out-of-scope/background-supervisor.md +32 -0
  15. package/docs/reviewed-integration.md +48 -0
  16. package/docs/user-guide.md +50 -21
  17. package/install-codex.sh +331 -18
  18. package/install.ps1 +28 -2
  19. package/install.sh +321 -17
  20. package/package.json +2 -1
  21. package/runtime/js/autonomy.mjs +152 -0
  22. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  23. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  24. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  25. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  26. package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
  27. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  28. package/runtime/js/cm-ai/cm-ai-admission.mjs +56 -17
  29. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  30. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  31. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  32. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  33. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  34. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  35. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  36. package/runtime/js/cm-ai/control-policy.mjs +21 -4
  37. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  38. package/runtime/js/cm-ai/drive-core.mjs +115 -11
  39. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  40. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  41. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  42. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  43. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  44. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  45. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  46. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  47. package/runtime/js/cm-ai/host-check.mjs +11 -5
  48. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  49. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  50. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  51. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  52. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  53. package/runtime/js/cm-ai/host-session.mjs +1 -1
  54. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  55. package/runtime/js/cm-ai/host.mjs +1 -1
  56. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  57. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  58. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  59. package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
  60. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  61. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  62. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  63. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  64. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  65. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  66. package/runtime/js/cm-ai/review-package.mjs +79 -7
  67. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  68. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  69. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  70. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  71. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  72. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  73. package/runtime/js/cm-ai/task-runner.mjs +242 -39
  74. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  75. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  76. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  77. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  78. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  79. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  80. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  81. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  82. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  83. package/runtime/js/cm-fix/dossier.mjs +8 -2
  84. package/runtime/js/cm-fix/execution.mjs +578 -100
  85. package/runtime/js/cm-fix/final-review.mjs +39 -8
  86. package/runtime/js/cm-fix/finish.mjs +15 -11
  87. package/runtime/js/cm-fix/host-review.mjs +65 -10
  88. package/runtime/js/cm-fix/host.mjs +35 -12
  89. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  90. package/runtime/js/cm-fix/metrics.mjs +18 -5
  91. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  92. package/runtime/js/cm-fix/regression.mjs +16 -7
  93. package/runtime/js/cm-fix/repair.mjs +29 -8
  94. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  95. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  96. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  97. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  98. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  99. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  100. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  101. package/runtime/js/cm-fix/start.mjs +6 -3
  102. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  103. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  104. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  105. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  106. package/runtime/js/cm-prd/analysis.mjs +13 -9
  107. package/runtime/js/cm-prd/change.mjs +37 -16
  108. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  109. package/runtime/js/cm-prd/draft.mjs +31 -3
  110. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  111. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  112. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  113. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  114. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  115. package/runtime/js/cm-prd/self-check.mjs +125 -6
  116. package/runtime/js/cm-prd/session.mjs +30 -1
  117. package/runtime/js/cm-prd/summary.mjs +11 -5
  118. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  119. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  120. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  121. package/runtime/js/cm-security/scan.mjs +1 -1
  122. package/runtime/js/commander/decision.mjs +44 -0
  123. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  124. package/runtime/js/commander/ledger.mjs +265 -0
  125. package/runtime/js/commander/preflight.mjs +107 -0
  126. package/runtime/js/notify-later.mjs +13 -0
  127. package/runtime/js/notify-send.mjs +6 -2
  128. package/runtime/js/notify.mjs +581 -65
  129. package/runtime/js/review-findings.mjs +38 -0
  130. package/runtime/js/session-boundary.mjs +56 -0
  131. package/runtime/js/session-handoff.mjs +68 -0
  132. package/runtime/js/spec-task-line.mjs +27 -13
  133. package/runtime/js/specs-status.mjs +5 -4
  134. package/runtime/js/task-scope.mjs +197 -0
  135. package/runtime/logging.md +6 -1
  136. package/runtime/model-efficiency.md +69 -10
  137. package/runtime/orchestration.md +3 -1
  138. package/runtime/project-learning.md +2 -0
  139. package/runtime/review.md +3 -2
  140. package/runtime/test-contract.md +1 -0
  141. package/scripts/ci-test-weights.json +3 -0
  142. package/scripts/cm-ai-admission.mjs +21 -7
  143. package/scripts/cm-ai-admission.test.mjs +171 -3
  144. package/scripts/cm-ai-batch-drive.mjs +79 -18
  145. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  146. package/scripts/cm-ai-batch-host.mjs +38 -9
  147. package/scripts/cm-ai-batch-host.test.mjs +6 -5
  148. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  149. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  150. package/scripts/cm-ai-batch-plan.mjs +52 -0
  151. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  152. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  153. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  154. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  155. package/scripts/cm-ai-batch-run.mjs +471 -57
  156. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  157. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  158. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  159. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  160. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  161. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  162. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  163. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  164. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  165. package/scripts/cm-ai-control-policy.test.mjs +14 -0
  166. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  167. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  168. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  169. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  170. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  171. package/scripts/cm-ai-drive.mjs +73 -17
  172. package/scripts/cm-ai-drive.test.mjs +34 -2
  173. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  174. package/scripts/cm-ai-host.mjs +60 -19
  175. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  176. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  177. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  178. package/scripts/cm-ai-integration-preview.mjs +41 -0
  179. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  180. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  181. package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
  182. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  183. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  184. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  185. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  186. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  187. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  188. package/scripts/cm-ai-run.mjs +88 -21
  189. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  190. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  191. package/scripts/cm-ai-supersede.test.mjs +28 -0
  192. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  193. package/scripts/cm-announce-hook.mjs +35 -8
  194. package/scripts/cm-announce-hook.test.mjs +25 -0
  195. package/scripts/cm-autonomy.mjs +94 -0
  196. package/scripts/cm-autonomy.test.mjs +162 -0
  197. package/scripts/cm-challenge.test.mjs +61 -0
  198. package/scripts/cm-check-drive-files.mjs +1 -1
  199. package/scripts/cm-check-runtime.sh +60 -1
  200. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  201. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  202. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  203. package/scripts/cm-claude-review-stream.test.mjs +13 -0
  204. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  205. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  206. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  207. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  208. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  209. package/scripts/cm-commander-ledger.test.mjs +260 -0
  210. package/scripts/cm-commander-p2.test.mjs +295 -0
  211. package/scripts/cm-commander-preflight.mjs +84 -0
  212. package/scripts/cm-commander.mjs +116 -0
  213. package/scripts/cm-config-lock.mjs +35 -0
  214. package/scripts/cm-controlled-correction.test.mjs +10 -1
  215. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  216. package/scripts/cm-display-task-id.test.mjs +41 -0
  217. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  218. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  219. package/scripts/cm-external-batch-host.test.mjs +4 -3
  220. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  221. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  222. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  223. package/scripts/cm-failover.mjs +48 -10
  224. package/scripts/cm-failover.test.mjs +46 -0
  225. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  226. package/scripts/cm-fix-command-correction.mjs +17 -0
  227. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  228. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  229. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  230. package/scripts/cm-fix-drive.mjs +33 -5
  231. package/scripts/cm-fix-drive.test.mjs +49 -0
  232. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  233. package/scripts/cm-fix-host-review.test.mjs +21 -9
  234. package/scripts/cm-fix-host.mjs +26 -8
  235. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  236. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  237. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  238. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  239. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  240. package/scripts/cm-fix-review-preflight.mjs +24 -0
  241. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  242. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  243. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  244. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  245. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  246. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  247. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  248. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  249. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  250. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  251. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  252. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  253. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  254. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  255. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  256. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  257. package/scripts/cm-host-replay.test.mjs +176 -0
  258. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  259. package/scripts/cm-install-manifest.sh +351 -0
  260. package/scripts/cm-live-evidence.test.mjs +59 -1
  261. package/scripts/cm-log-event.mjs +61 -10
  262. package/scripts/cm-log-event.test.mjs +121 -1
  263. package/scripts/cm-matt-skills.mjs +576 -0
  264. package/scripts/cm-matt-skills.test.mjs +550 -0
  265. package/scripts/cm-notify-command.test.mjs +42 -10
  266. package/scripts/cm-notify.mjs +14 -10
  267. package/scripts/cm-notify.test.mjs +581 -59
  268. package/scripts/cm-patrol.mjs +4 -1
  269. package/scripts/cm-patrol.test.mjs +23 -5
  270. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  271. package/scripts/cm-prd-completion.test.mjs +56 -13
  272. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  273. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  274. package/scripts/cm-prd-draft.test.mjs +1 -1
  275. package/scripts/cm-prd-drive.mjs +13 -6
  276. package/scripts/cm-prd-drive.test.mjs +45 -1
  277. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  278. package/scripts/cm-prd-host.mjs +10 -5
  279. package/scripts/cm-prd-host.test.mjs +4 -2
  280. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  281. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  282. package/scripts/cm-prd-revision.test.mjs +1 -1
  283. package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
  284. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  285. package/scripts/cm-prd-self-check.test.mjs +105 -5
  286. package/scripts/cm-prd-summary.test.mjs +24 -3
  287. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  288. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  289. package/scripts/cm-refactor-drive.mjs +2 -1
  290. package/scripts/cm-refactor-drive.test.mjs +9 -0
  291. package/scripts/cm-release-smoke.sh +1 -1
  292. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  293. package/scripts/cm-skill-hints-exam.mjs +149 -0
  294. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  295. package/scripts/cm-skill-hints.exam.json +706 -0
  296. package/scripts/cm-skill-hints.json +119 -0
  297. package/scripts/cm-skill-hints.mjs +669 -0
  298. package/scripts/cm-skill-hints.test.mjs +831 -0
  299. package/scripts/cm-skill-judge.mjs +181 -0
  300. package/scripts/cm-skill-judge.test.mjs +255 -0
  301. package/scripts/cm-specs-status.test.mjs +4 -2
  302. package/scripts/cm-start-check.mjs +323 -0
  303. package/scripts/cm-start-check.test.mjs +406 -0
  304. package/scripts/cm-task-gate.mjs +150 -29
  305. package/scripts/cm-task-gate.test.mjs +73 -1
  306. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  307. package/scripts/cm-task-scope.test.mjs +308 -0
  308. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  309. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  310. package/scripts/cm-workflow-config.mjs +12 -2
  311. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  312. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  313. package/scripts/scan-public-safety.py +1 -0
  314. package/scripts/session-boundary.test.mjs +170 -0
  315. package/scripts/test-npm-install.py +14 -3
  316. package/scripts/test-shell-compat.sh +2 -0
  317. package/scripts/validate-public-repo.py +4 -0
  318. package/scripts/validate-test-cases.mjs +3 -2
  319. package/skills/cm-ai/SKILL.md +5 -2
  320. package/skills/cm-ai/references/N3-execute-task.md +1 -1
  321. package/skills/cm-ai/references/N4-review.md +2 -1
  322. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  323. package/skills/cm-ai/references/N8-finish.md +22 -0
  324. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  325. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  326. package/skills/cm-ai/references/js-host.md +82 -16
  327. package/skills/cm-challenge/SKILL.md +65 -0
  328. package/skills/cm-challenge/evals/README.md +18 -0
  329. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  330. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  331. package/skills/cm-challenge/references/examples.md +15 -0
  332. package/skills/cm-check/SKILL.md +5 -0
  333. package/skills/cm-check/references/js-host.md +2 -0
  334. package/skills/cm-fix/SKILL.md +12 -3
  335. package/skills/cm-fix/references/command-correction.md +67 -0
  336. package/skills/cm-fix/references/isolated-review.md +54 -0
  337. package/skills/cm-fix/references/js-host.md +62 -2
  338. package/skills/cm-fix/references/test-type-correction.md +72 -0
  339. package/skills/cm-fix/references/verification-recovery.md +114 -0
  340. package/skills/cm-idea/SKILL.md +2 -0
  341. package/skills/cm-idea/references/js-host.md +2 -0
  342. package/skills/cm-notify/SKILL.md +2 -0
  343. package/skills/cm-prd/SKILL.md +14 -9
  344. package/skills/cm-prd/references/brownfield.md +8 -1
  345. package/skills/cm-prd/references/change-mode.md +8 -1
  346. package/skills/cm-prd/references/greenfield.md +4 -0
  347. package/skills/cm-prd/references/js-change-recovery.md +14 -0
  348. package/skills/cm-prd/references/js-host.md +4 -2
  349. package/skills/cm-prd/references/spec-self-check.md +5 -1
  350. package/skills/cm-refactor/SKILL.md +8 -0
  351. package/skills/cm-refactor/references/js-host.md +2 -0
  352. package/skills/cm-test/SKILL.md +4 -0
  353. package/templates/dashboard/dashboard.html +2 -2
  354. package/templates/pixel/cm-pixel.html +1 -1
  355. package/templates/pixel/cm-pixel.sh +1 -1
  356. package/templates/pixel/dev/template.html +1 -1
  357. package/templates/statusline/cm-statusline.sh +1 -1
package/install.sh CHANGED
@@ -9,14 +9,45 @@ VERSION="$(cat "$SRC_DIR/VERSION" 2>/dev/null || echo 未知)"
9
9
  STAGE="$DEST_PARENT/.cm-claude.stage.$$"
10
10
  BACKUP="$DEST_PARENT/.cm-claude.backup.$$"
11
11
  ASSUME_YES=0
12
+ OVERWRITE_LOCAL_EDITS=0
13
+ # Non-empty when --no-skill-hints is given: this run does not wire the skill-hints hook.
14
+ SKIP_SKILL_HINTS=""
15
+ # Non-empty when --no-matt-skills is given: this run does not install the companion skills.
16
+ SKIP_MATT_SKILLS=""
12
17
  INSTALL_COMPLETE=0
13
18
  DEST_TOUCHED=0
19
+ # Records what this install wrote so the next install can tell hand edits apart.
20
+ INSTALL_MANIFEST_RELATIVE="cm-workflow/install-manifest.sha256"
21
+ INSTALL_MANIFEST="$DEST/$INSTALL_MANIFEST_RELATIVE"
22
+ GUARD_TMP=""
23
+ MANIFEST_PUBLISHED=0
24
+ MANIFEST_TMP=""
25
+ # One install transaction per target; never taken over automatically. The path
26
+ # is set from the canonical target below (shared rule with install-codex.sh).
27
+ LOCK_DIR=""
28
+ LOCK_HELD=0
29
+ ROLLBACK_FAILED=0
30
+ # Files this run started writing; rollback restores only these, so a file that
31
+ # was never copied (e.g. one found hand-edited mid-copy) is left untouched.
32
+ WRITTEN_LIST=""
33
+ # Each rollback record is "<relative><TAB>W"; a record without this ending was
34
+ # cut short (e.g. a disk-full partial write) and is never used.
35
+ WRITTEN_MARK="$(printf '\tW')"
36
+ VERIFIED_MANIFEST=""
37
+ MANIFEST_SAVED_NAME=".cm-previous-install-manifest"
14
38
 
15
- case "${1:-}" in
16
- "") ;;
17
- --yes) ASSUME_YES=1 ;;
18
- *) echo "用法: $0 [--yes]" >&2; exit 2 ;;
19
- esac
39
+ for arg in "$@"; do
40
+ case "$arg" in
41
+ --yes) ASSUME_YES=1 ;;
42
+ --overwrite-local-edits) OVERWRITE_LOCAL_EDITS=1 ;;
43
+ --no-skill-hints) SKIP_SKILL_HINTS=1 ;;
44
+ --no-matt-skills) SKIP_MATT_SKILLS=1 ;;
45
+ *) echo "用法: $0 [--yes] [--overwrite-local-edits] [--no-skill-hints] [--no-matt-skills]" >&2; exit 2 ;;
46
+ esac
47
+ done
48
+
49
+ # shellcheck source=scripts/cm-install-manifest.sh
50
+ . "$SRC_DIR/scripts/cm-install-manifest.sh"
20
51
 
21
52
  if ! command -v node >/dev/null 2>&1 ||
22
53
  ! node -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 18 ? 0 : 1)' >/dev/null 2>&1; then
@@ -24,24 +55,108 @@ if ! command -v node >/dev/null 2>&1 ||
24
55
  exit 1
25
56
  fi
26
57
 
58
+ # Canonical install root: one physical path per real target, never a symlink.
59
+ if DEST_CANONICAL=$(cm_install_canonical_target "$DEST"); then
60
+ :
61
+ else
62
+ canonical_status=$?
63
+ if [ "$canonical_status" -eq 2 ]; then
64
+ echo "安装目录不能是符号链接或非目录: ${DEST};安装已停止,未修改任何文件。" >&2
65
+ else
66
+ echo "无法确定安装目录的真实路径: ${DEST};安装已停止,未修改任何文件。" >&2
67
+ fi
68
+ exit 2
69
+ fi
70
+ DEST="$DEST_CANONICAL"
71
+ DEST_PARENT="$(dirname "$DEST")"
72
+ STAGE="$DEST_PARENT/.cm-claude.stage.$$"
73
+ BACKUP="$DEST_PARENT/.cm-claude.backup.$$"
74
+ INSTALL_MANIFEST="$DEST/$INSTALL_MANIFEST_RELATIVE"
75
+ LOCK_DIR="$(cm_install_lock_path "$DEST")"
76
+
77
+ # Rollback keeps going after a failed step (no errexit, signals ignored), keeps
78
+ # the backup whenever anything could not be restored, and always unlocks.
79
+ rollback_fail() {
80
+ echo " 恢复失败: $1" >&2
81
+ ROLLBACK_FAILED=1
82
+ }
83
+
27
84
  cleanup() {
28
85
  status=$?
29
- trap - EXIT HUP INT TERM
86
+ set +e
87
+ trap '' HUP INT TERM
88
+ trap - EXIT
30
89
  if [ "$INSTALL_COMPLETE" -ne 1 ] && [ "$DEST_TOUCHED" -eq 1 ]; then
31
- while IFS= read -r relative; do
32
- [ -n "$relative" ] || continue
90
+ # Without a readable list of what was written nothing can be restored
91
+ # safely: report it and keep the backup instead of claiming success.
92
+ if written_files=$(cat "$WRITTEN_LIST" 2>/dev/null); then
93
+ :
94
+ else
95
+ written_files=""
96
+ rollback_fail "回滚清单不可读: ${WRITTEN_LIST}(已写入的文件未恢复)"
97
+ fi
98
+ # Split on newlines only (no temporary file, unlike a here-document).
99
+ saved_ifs=$IFS
100
+ IFS='
101
+ '
102
+ set -f
103
+ for record in $written_files; do
104
+ [ -n "$record" ] || continue
105
+ # Only complete records naming a file this install manages are used; a
106
+ # cut-short prefix could name an unrelated user file.
107
+ case "$record" in
108
+ *"$WRITTEN_MARK") relative=${record%"$WRITTEN_MARK"} ;;
109
+ *) rollback_fail "回滚清单记录不完整,未使用: ${record}"; continue ;;
110
+ esac
111
+ member=0
112
+ grep -Fxq -- "$relative" "$STAGE/.cm-managed-files" || member=$?
113
+ if [ "$member" -ne 0 ]; then
114
+ rollback_fail "回滚清单记录不属于本次安装或无法核对,未使用: ${relative}"
115
+ continue
116
+ fi
33
117
  target="$DEST/$relative"
34
118
  saved="$BACKUP/$relative"
119
+ access=0
120
+ cm_manifest_parent_is_safe "$DEST" "$relative" || access=$?
121
+ if [ "$access" -eq 2 ]; then
122
+ rollback_fail "$target(上级目录无法访问,未写入)"
123
+ continue
124
+ fi
125
+ if ! assert_safe_target "$relative"; then
126
+ rollback_fail "$target(路径类型已变化,未写入)"
127
+ continue
128
+ fi
35
129
  if [ -f "$saved" ]; then
36
- mkdir -p "$(dirname "$target")"
37
- cp -p "$saved" "$target"
38
- elif [ -f "$target" ] || [ -L "$target" ]; then
39
- rm -f "$target"
130
+ { mkdir -p "$(dirname "$target")" && cp -p "$saved" "$target"; } || rollback_fail "$target"
131
+ elif [ -f "$target" ]; then
132
+ rm -f "$target" || rollback_fail "$target"
133
+ fi
134
+ done
135
+ set +f
136
+ IFS=$saved_ifs
137
+ # Keep the manifest paired with the restored files.
138
+ if [ "$MANIFEST_PUBLISHED" -eq 1 ]; then
139
+ if ! assert_safe_target "$INSTALL_MANIFEST_RELATIVE"; then
140
+ rollback_fail "$INSTALL_MANIFEST(路径类型已变化,未写入)"
141
+ elif [ -f "$BACKUP/$MANIFEST_SAVED_NAME" ]; then
142
+ cp -p "$BACKUP/$MANIFEST_SAVED_NAME" "$INSTALL_MANIFEST" || rollback_fail "$INSTALL_MANIFEST"
143
+ else
144
+ rm -f "$INSTALL_MANIFEST" || rollback_fail "$INSTALL_MANIFEST"
40
145
  fi
41
- done < "$STAGE/.cm-managed-files"
42
- echo "安装失败,已回滚本次写入。" >&2
146
+ fi
147
+ if [ "$ROLLBACK_FAILED" -eq 1 ]; then
148
+ echo "⚠ 安装失败,回滚不完整。恢复材料保留在: ${BACKUP}" >&2
149
+ echo " (按相对路径存放的原文件;旧安装清单为 ${BACKUP}/${MANIFEST_SAVED_NAME})" >&2
150
+ else
151
+ echo "安装失败,已回滚本次写入。" >&2
152
+ fi
43
153
  fi
44
- rm -rf "$STAGE" "$BACKUP"
154
+ rm -rf "$STAGE"
155
+ [ "$ROLLBACK_FAILED" -eq 1 ] || rm -rf "$BACKUP"
156
+ [ -z "$GUARD_TMP" ] || rm -rf "$GUARD_TMP"
157
+ # Only the temporary manifest this run created (mktemp) is removed.
158
+ [ -z "$MANIFEST_TMP" ] || rm -f "$MANIFEST_TMP"
159
+ [ "$LOCK_HELD" -ne 1 ] || rm -rf "$LOCK_DIR" || echo "⚠ 无法释放安装锁: ${LOCK_DIR}" >&2
45
160
  exit "$status"
46
161
  }
47
162
  trap cleanup EXIT
@@ -121,13 +236,69 @@ confirm_bundle_conflicts() {
121
236
  echo "⚠ 以下 CM 文件已存在,将作为一个整体更新:"
122
237
  printf '%s' "$conflicts" | sed '/^$/d; s/^/ /'
123
238
  [ "$ASSUME_YES" -eq 1 ] && return 0
124
- read -r -p " 继续原子更新全部 CM 文件?[y/N] " answer
239
+ read -r -p " 继续整体更新全部 CM 文件(失败时回滚)?[y/N] " answer
125
240
  case "$answer" in
126
241
  y|Y) return 0 ;;
127
242
  *) echo "安装已取消,未修改现有运行时。"; return 1 ;;
128
243
  esac
129
244
  }
130
245
 
246
+ # Stop before any write when a file recorded by the previous install changed.
247
+ # --yes only accepts replacing CM files; it never discards hand edits.
248
+ # Runs twice: once up front, and again ("recheck") after staging and the
249
+ # overwrite prompt, right before the first write, because another session may
250
+ # edit an installed file while this one waits for an answer.
251
+ guard_local_edits() {
252
+ guard_mode=${1:-initial}
253
+ if ! cm_manifest_select_hasher; then
254
+ echo "未找到 shasum 或 sha256sum,无法核对已安装文件是否被手改;安装已停止,未修改任何文件。" >&2
255
+ return 2
256
+ fi
257
+ if ! assert_safe_target "$INSTALL_MANIFEST_RELATIVE"; then
258
+ return 2
259
+ fi
260
+ manifest_access=0
261
+ cm_manifest_parent_is_safe "$DEST" "$INSTALL_MANIFEST_RELATIVE" || manifest_access=$?
262
+ if [ "$manifest_access" -eq 2 ]; then
263
+ echo "安装目录无法访问,无法判断上次的安装清单是否存在: ${INSTALL_MANIFEST};安装已停止,未修改任何文件。" >&2
264
+ return 2
265
+ fi
266
+ if [ ! -e "$INSTALL_MANIFEST" ]; then
267
+ [ "$guard_mode" = recheck ] ||
268
+ echo "ℹ 未找到上次的安装清单(首次安装或旧版本安装),本次不核对手改;安装成功后会生成清单。"
269
+ return 0
270
+ fi
271
+ edits="$GUARD_TMP/local-edits"
272
+ if cm_manifest_find_edits "$DEST" "$INSTALL_MANIFEST" "$edits" "$GUARD_TMP"; then
273
+ :
274
+ else
275
+ find_status=$?
276
+ if [ "$find_status" -ne 3 ]; then
277
+ echo "核对已安装文件失败,安装已停止,未修改任何文件。" >&2
278
+ return 2
279
+ fi
280
+ echo "⚠ 安装清单格式无法识别: ${INSTALL_MANIFEST}" >&2
281
+ if [ "$OVERWRITE_LOCAL_EDITS" -eq 1 ]; then
282
+ echo "已指定 --overwrite-local-edits,跳过手改核对并重新生成清单。"
283
+ return 0
284
+ fi
285
+ echo "安装已停止,未修改任何文件。确认要覆盖现有 CM 文件时,加 --overwrite-local-edits 重新运行。" >&2
286
+ return 1
287
+ fi
288
+ [ -s "$edits" ] || return 0
289
+ if [ "$OVERWRITE_LOCAL_EDITS" -eq 1 ] && [ "$guard_mode" = recheck ]; then
290
+ return 0
291
+ fi
292
+ echo "⚠ 以下 CM 文件在上次安装后被改动过(与安装清单记录的 sha256 不一致):" >&2
293
+ sed 's/^/ /' "$edits" >&2
294
+ if [ "$OVERWRITE_LOCAL_EDITS" -eq 1 ]; then
295
+ echo "已指定 --overwrite-local-edits,将覆盖以上改动。"
296
+ return 0
297
+ fi
298
+ echo "安装已停止,未修改任何文件。--yes 不会覆盖手改;请先保存或合并这些改动,确认丢弃时加 --overwrite-local-edits 重新运行。" >&2
299
+ return 1
300
+ }
301
+
131
302
  copy_file_atomic() {
132
303
  src=$1
133
304
  dst=$2
@@ -156,7 +327,47 @@ echo " 来源: $SRC_DIR"
156
327
  echo " 目标: $DEST"
157
328
  echo
158
329
 
159
- mkdir -p "$DEST_PARENT" "$STAGE"
330
+ mkdir -p "$DEST_PARENT"
331
+ cm_defer_signals
332
+ if cm_install_lock_acquire "$LOCK_DIR"; then
333
+ LOCK_HELD=1
334
+ cm_install_test_hook lock-acquired
335
+ cm_install_lock_write_owner "$LOCK_DIR" "$DEST"
336
+ fi
337
+ cm_resume_signals
338
+ if [ "$LOCK_HELD" -eq 1 ]; then
339
+ :
340
+ elif [ ! -d "$LOCK_DIR" ] || [ -L "$LOCK_DIR" ]; then
341
+ echo "无法创建安装锁: ${LOCK_DIR};安装已停止,未修改任何文件。" >&2
342
+ exit 2
343
+ else
344
+ lock_pid=$(cm_install_lock_field "$LOCK_DIR" pid)
345
+ lock_started=$(cm_install_lock_field "$LOCK_DIR" started)
346
+ lock_state=$(cm_install_lock_pid_state "$lock_pid")
347
+ echo "⚠ 另一个 CM 安装正在写同一目标,本次已停止,未修改任何文件。" >&2
348
+ echo " 锁: ${LOCK_DIR}" >&2
349
+ echo " 持有进程: ${lock_pid:-未知}(开始于 ${lock_started:-未知})" >&2
350
+ case "$lock_state" in
351
+ alive) echo " 该进程仍在运行;等它结束后重试。" >&2 ;;
352
+ not-running) echo " 该进程已不在运行,锁可能是中断遗留。确认没有安装在进行后,手动清理再重试:" >&2
353
+ echo " rm -rf $(cm_install_quote "$LOCK_DIR")" >&2 ;;
354
+ *) echo " 无法判断持有进程是否还在;确认没有安装在进行后,手动清理再重试:" >&2
355
+ echo " rm -rf $(cm_install_quote "$LOCK_DIR")" >&2 ;;
356
+ esac
357
+ exit 4
358
+ fi
359
+ GUARD_TMP="$(mktemp -d "${TMPDIR:-/tmp}/cm-install-guard.XXXXXX")"
360
+ WRITTEN_LIST="$GUARD_TMP/written-files"
361
+ : > "$WRITTEN_LIST"
362
+ if guard_local_edits; then
363
+ :
364
+ else
365
+ guard_status=$?
366
+ [ "$guard_status" -eq 1 ] && exit 3
367
+ exit "$guard_status"
368
+ fi
369
+
370
+ mkdir -p "$STAGE"
160
371
  for part in skills agents runtime scripts compat; do
161
372
  stage_tree "$SRC_DIR/$part" "$part"
162
373
  done
@@ -203,6 +414,10 @@ done
203
414
 
204
415
  (cd "$STAGE" && find . -type f ! -name .cm-managed-files | sed 's#^\./##' | sort) \
205
416
  > "$STAGE/.cm-managed-files"
417
+ if ! cm_manifest_write "$STAGE" "$STAGE/.cm-managed-files" "$GUARD_TMP/new-manifest"; then
418
+ echo "生成安装清单失败,安装已停止,未修改任何文件。" >&2
419
+ exit 1
420
+ fi
206
421
 
207
422
  if confirm_bundle_conflicts; then
208
423
  :
@@ -215,22 +430,101 @@ fi
215
430
  mkdir -p "$BACKUP"
216
431
  while IFS= read -r relative; do
217
432
  [ -n "$relative" ] || continue
433
+ if ! assert_safe_target "$relative"; then
434
+ echo "安装目标在确认后发生结构变化,安装已停止,未修改任何文件。" >&2
435
+ exit 3
436
+ fi
437
+ access=0
438
+ cm_manifest_parent_is_safe "$DEST" "$relative" || access=$?
439
+ if [ "$access" -eq 2 ]; then
440
+ echo "安装目标 ${relative} 的上级目录无法访问,安装已停止,未修改任何文件。" >&2
441
+ exit 2
442
+ fi
218
443
  if [ -f "$DEST/$relative" ]; then
219
444
  mkdir -p "$(dirname "$BACKUP/$relative")"
220
445
  cp -p "$DEST/$relative" "$BACKUP/$relative"
221
446
  fi
222
447
  done < "$STAGE/.cm-managed-files"
448
+ if [ -f "$INSTALL_MANIFEST" ] && [ ! -L "$INSTALL_MANIFEST" ]; then
449
+ cp -p "$INSTALL_MANIFEST" "$BACKUP/$MANIFEST_SAVED_NAME"
450
+ fi
451
+
452
+ # Second check, just before the first write to the real target.
453
+ if guard_local_edits recheck; then
454
+ :
455
+ else
456
+ guard_status=$?
457
+ [ "$guard_status" -eq 1 ] && exit 3
458
+ exit "$guard_status"
459
+ fi
460
+ # Freeze the manifest the recheck just accepted for the per-file checks below.
461
+ if [ "$OVERWRITE_LOCAL_EDITS" -ne 1 ] && [ -f "$INSTALL_MANIFEST" ]; then
462
+ VERIFIED_MANIFEST="$GUARD_TMP/verified-manifest"
463
+ cp "$INSTALL_MANIFEST" "$VERIFIED_MANIFEST"
464
+ if ! cm_manifest_validate "$VERIFIED_MANIFEST"; then
465
+ echo "⚠ 安装清单在核对后发生变化,安装已停止,未修改任何文件。" >&2
466
+ exit 3
467
+ fi
468
+ fi
223
469
 
470
+ # Narrow the check-to-write window to a single file: right before each copy,
471
+ # compare the file's current sha256 with the previous manifest. This cannot be
472
+ # atomic; do not edit installed CM files while an install is running.
473
+ # CM_INSTALL_TEST_HOOK is for the repository's tests only (unset by default):
474
+ # it runs as `$CM_INSTALL_TEST_HOOK before-copy <relative>` before each file.
224
475
  mkdir -p "$DEST"
225
476
  DEST_TOUCHED=1
226
477
  while IFS= read -r relative; do
227
478
  [ -n "$relative" ] || continue
479
+ cm_install_test_hook before-copy "$relative"
480
+ # Type and parent path first: never write through a symlink or into a
481
+ # directory that replaced a file after the earlier checks.
482
+ if ! assert_safe_target "$relative"; then
483
+ echo "⚠ 安装过程中 ${relative} 的路径类型发生变化,已停止并回滚已写入的文件;该路径保持原样。" >&2
484
+ exit 3
485
+ fi
486
+ access=0
487
+ cm_manifest_parent_is_safe "$DEST" "$relative" || access=$?
488
+ if [ "$access" -eq 2 ]; then
489
+ echo "⚠ 安装过程中 ${relative} 的上级目录无法访问,已停止并回滚已写入的文件。" >&2
490
+ exit 2
491
+ fi
492
+ if [ -n "$VERIFIED_MANIFEST" ] && [ -f "$DEST/$relative" ]; then
493
+ recorded=$(cm_manifest_recorded_hash "$VERIFIED_MANIFEST" "$relative")
494
+ if [ -n "$recorded" ]; then
495
+ current=$(cm_manifest_file_hash "$DEST/$relative")
496
+ if [ "$current" != "$recorded" ]; then
497
+ echo "⚠ 安装过程中 ${relative} 被改动(与安装清单记录的 sha256 不一致),已停止并回滚已写入的文件;该文件保持原样。" >&2
498
+ echo " 确认丢弃这个改动时,加 --overwrite-local-edits 重新运行。" >&2
499
+ exit 3
500
+ fi
501
+ fi
502
+ fi
503
+ printf '%s\tW\n' "$relative" >> "$WRITTEN_LIST"
228
504
  mkdir -p "$(dirname "$DEST/$relative")"
229
505
  cp -p "$STAGE/$relative" "$DEST/$relative"
230
506
  done < "$STAGE/.cm-managed-files"
231
507
 
232
508
  "$DEST/scripts/cm-check-runtime.sh" --project "$SRC_DIR"
509
+ mkdir -p "$(dirname "$INSTALL_MANIFEST")"
510
+ if ! assert_safe_target "$INSTALL_MANIFEST_RELATIVE"; then
511
+ echo "安装清单路径类型发生变化,已停止并回滚。" >&2
512
+ exit 3
513
+ fi
514
+ # The temporary manifest is created exclusively by mktemp under a random name
515
+ # in the checked directory; cleanup removes only this file.
516
+ cm_defer_signals
517
+ MANIFEST_TMP=$(cm_run_shielded mktemp "$(dirname "$INSTALL_MANIFEST")/.install-manifest.XXXXXX")
518
+ cm_resume_signals
519
+ cp "$GUARD_TMP/new-manifest" "$MANIFEST_TMP"
520
+ chmod 644 "$MANIFEST_TMP"
521
+ cm_install_test_hook before-manifest-publish
522
+ MANIFEST_PUBLISHED=1
523
+ mv -f "$MANIFEST_TMP" "$INSTALL_MANIFEST"
524
+ MANIFEST_TMP=""
525
+ cm_install_test_hook after-manifest-publish
233
526
  INSTALL_COMPLETE=1
527
+ echo "✓ 安装清单已写入: ${INSTALL_MANIFEST}"
234
528
 
235
529
  # User runtimes.yml: only after the verified core install, before updater prompts.
236
530
  if [ "$ASSUME_YES" -ne 1 ] && [ -t 0 ] && [ -t 1 ]; then
@@ -258,3 +552,13 @@ else
258
552
  echo "自动更新器未自动启用;按 docs/installation.md 手工配置 SessionStart hook。"
259
553
  fi
260
554
  echo "后台自动升级仍需另行开启,见 docs/installation.md。"
555
+ # Skill hints: wire the hook into Claude settings once by default (not with --no-skill-hints,
556
+ # CM_SKILL_HINTS_INSTALL=off, "enabled": false, or after the user removed it); otherwise
557
+ # only refresh the copy under ~/.cm-workflow/skill-hints. Failure only warns.
558
+ node "$DEST/scripts/cm-skill-hints.mjs" install --host claude ${SKIP_SKILL_HINTS:+--no-skill-hints} </dev/null ||
559
+ echo "⚠ 技能提醒钩子未处理完(不影响本次安装)" >&2
560
+ # Optional Matt Pocock companion skills: put the pinned set in by default (not with
561
+ # --no-matt-skills, CM_MATT_SKILLS_INSTALL=off, {"install": false} in ~/.cm-workflow/matt-skills.local.json,
562
+ # or a skill the user removed after CM saw it there); a fetch that fails only warns.
563
+ echo
564
+ node "$DEST/scripts/cm-matt-skills.mjs" auto ${SKIP_MATT_SKILLS:+--no-matt-skills} </dev/null || true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibyzero/cm-workflow",
3
- "version": "0.17.1",
3
+ "version": "0.19.0",
4
4
  "description": "Spec-driven business development workflow for Pi, Codex, and Claude Code",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -44,6 +44,7 @@
44
44
  "pi": {
45
45
  "skills": [
46
46
  "./skills/cm-ai",
47
+ "./skills/cm-challenge",
47
48
  "./skills/cm-check",
48
49
  "./skills/cm-fix",
49
50
  "./skills/cm-idea",
@@ -0,0 +1,152 @@
1
+ // Standing "run to the end" authorization (scripts/cm-autonomy.mjs). Like
2
+ // --approval-response, the session relays the person's own words; the record
3
+ // changes three things: a driver stop waits waitMinutes instead of paging at once
4
+ // (the session usually carries on), cm-ai admission may approve a change proposal
5
+ // that leaves the requirement contract alone, and the session may reopen a task
6
+ // up to AUTO_REOPEN_LIMIT times. Fatal stops page at once (cm-autonomy.mjs notify).
7
+ import fs from 'node:fs';
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
+ import {randomUUID,createHash} from 'node:crypto';
11
+
12
+ export const AUTONOMY_FILE='autonomy.json',AUTONOMY_OFF_FILE='autonomy.off.json',REOPEN_DIR='autonomy-reopens',AUTO_REOPEN_LIMIT=2;
13
+ // Same directory as notify.json (notify.mjs notifyHome); kept here so notify.mjs can import this module.
14
+ export const autonomyHome=(env=process.env)=>path.resolve(env.CM_WORKFLOW_HOME||path.join(os.homedir(),'.cm-workflow'));
15
+ const iso=value=>typeof value==='string'&&/^\d{4}-\d\d-\d\dT/.test(value)&&Number.isFinite(Date.parse(value));
16
+ const words=value=>typeof value==='string'&&value.trim()!==''&&Array.from(value).length<=500;
17
+ const record=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
18
+
19
+ function readJson(file){
20
+ try{if(!fs.lstatSync(file).isFile())return {invalid:true};return {value:JSON.parse(fs.readFileSync(file,'utf8'))};}
21
+ catch(error){return error.code==='ENOENT'?{missing:true}:{invalid:true};}
22
+ }
23
+ function writeJson(home,name,value){
24
+ fs.mkdirSync(home,{recursive:true,mode:0o700});
25
+ const target=path.join(home,name),temporary=path.join(home,`.${name}-${randomUUID()}`);
26
+ try{fs.writeFileSync(temporary,JSON.stringify(value,null,1)+'\n',{mode:0o600,flag:'wx'});fs.renameSync(temporary,target);}
27
+ finally{try{fs.unlinkSync(temporary);}catch(error){if(error.code!=='ENOENT')throw error;}}
28
+ }
29
+
30
+ // {on:true,value} only for a regular file the writer below would produce; anything else is off.
31
+ export function readAutonomy(env=process.env){
32
+ const read=readJson(path.join(autonomyHome(env),AUTONOMY_FILE));
33
+ if(read.missing)return {on:false,reason:'missing'};
34
+ const value=read.value;
35
+ if(read.invalid||!record(value)||Object.keys(value).sort().join()!=='at,mode,response,version'
36
+ ||value.version!==1||value.mode!=='until_fatal'||!words(value.response)||!iso(value.at))return {on:false,reason:'invalid'};
37
+ return {on:true,value:{version:1,mode:'until_fatal',response:value.response,at:value.at}};
38
+ }
39
+
40
+ export function writeAutonomy(response,{env=process.env,now=Date.now()}={}){
41
+ if(!words(response))throw new Error('autonomy_response_invalid');
42
+ const value={version:1,mode:'until_fatal',response,at:new Date(now).toISOString()};
43
+ writeJson(autonomyHome(env),AUTONOMY_FILE,value);
44
+ return value;
45
+ }
46
+
47
+ // Turning it off keeps the record (renamed) so the last grant stays auditable.
48
+ export function clearAutonomy({env=process.env}={}){
49
+ const home=autonomyHome(env);
50
+ try{fs.renameSync(path.join(home,AUTONOMY_FILE),path.join(home,AUTONOMY_OFF_FILE));return true;}
51
+ catch(error){if(error.code==='ENOENT')return false;throw error;}
52
+ }
53
+
54
+ // Automatic reopens per task. Each reopen claims one numbered slot file with an
55
+ // exclusive create, which is atomic: concurrent takers (any project) can never
56
+ // claim the same slot, and there is no lock to reclaim. A slot left half-written
57
+ // by a crash still counts. {count} when a slot was claimed, {refused:true,count}
58
+ // when all AUTO_REOPEN_LIMIT are taken (a fatal stop).
59
+ const reopenKey=(project,task)=>`${path.resolve(project)}|${task}`;
60
+ const slotPrefix=key=>createHash('sha256').update(key).digest('hex').slice(0,32);
61
+ // Counted by slot file name, like takeReopen; a group whose files are all unreadable is still shown.
62
+ export function readReopens(env=process.env){
63
+ const dir=path.join(autonomyHome(env),REOPEN_DIR),groups={};
64
+ let names;try{names=fs.readdirSync(dir);}catch(error){if(error.code==='ENOENT')return {};throw error;}
65
+ for(const name of names){
66
+ const prefix=/^([0-9a-f]{32})-\d+$/.exec(name)?.[1];if(!prefix)continue;
67
+ let key=null;try{key=JSON.parse(fs.readFileSync(path.join(dir,name),'utf8')).key;}catch{}
68
+ const group=groups[prefix]??={key:null,count:0};group.count++;
69
+ if(typeof key==='string'&&slotPrefix(key)===prefix)group.key=key;
70
+ }
71
+ return Object.fromEntries(Object.entries(groups).map(([prefix,{key,count}])=>[key??`未识别|名额 ${prefix}`,count]));
72
+ }
73
+ export function takeReopen(project,task,{env=process.env,now=Date.now()}={}){
74
+ if(typeof task!=='string'||!/^\d+\.[^/\\\s]+\/T-\d+$/.test(task))throw new Error('autonomy_task_invalid');
75
+ const dir=path.join(autonomyHome(env),REOPEN_DIR),key=reopenKey(project,task);
76
+ // A count kept some other way is never taken as "none yet".
77
+ if(fs.existsSync(path.join(autonomyHome(env),'autonomy-reopens.json')))throw new Error('autonomy_reopens_legacy');
78
+ fs.mkdirSync(dir,{recursive:true,mode:0o700});
79
+ for(let slot=1;slot<=AUTO_REOPEN_LIMIT;slot++){
80
+ try{fs.writeFileSync(path.join(dir,`${slotPrefix(key)}-${slot}`),JSON.stringify({key,slot,at:new Date(now).toISOString()})+'\n',{flag:'wx',mode:0o600});}
81
+ catch(error){if(error.code==='EEXIST')continue;throw error;}
82
+ return {count:slot};
83
+ }
84
+ return {refused:true,count:AUTO_REOPEN_LIMIT};
85
+ }
86
+
87
+ const DOCUMENTS=['requirements.md','design.md','tasks.md'],CHANGEABLE=new Set(['design.md','tasks.md','test-cases.json']);
88
+ const userCases=source=>{
89
+ if(source===undefined)return new Map();
90
+ const cases=JSON.parse(source)?.cases;
91
+ if(!Array.isArray(cases))throw new Error('cases');
92
+ return new Map(cases.filter(item=>item?.origin==='user').map(item=>[item.id,JSON.stringify(item)]));
93
+ };
94
+
95
+ // Whether a change proposal may be approved under the standing authorization,
96
+ // judged from the complete before/after contents: it may change design, tasks and
97
+ // generated cases of existing features, never a requirement, the feature list or a
98
+ // user case. Returns null when it may, else the reason in plain words.
99
+ export function standingProposalProblem(before,proposal){
100
+ if(!record(before)||!Array.isArray(before.directories)||!before.directories.every(dir=>typeof dir==='string')
101
+ ||!record(before.files)||!Object.values(before.files).every(value=>typeof value==='string')
102
+ ||!record(proposal)||!record(proposal.files)||!Object.keys(proposal.files).length
103
+ ||!Object.values(proposal.files).every(value=>typeof value==='string')
104
+ ||!Array.isArray(proposal.changedUserCases)||!Array.isArray(proposal.removed))return '提案内容不完整,无法判断';
105
+ if(proposal.changedUserCases.length)return '提案删除或减弱了用户用例';
106
+ if(proposal.removed.length)return '提案删除了功能';
107
+ const features=new Set(Object.keys(proposal.files).map(file=>file.split('/')[0]));
108
+ for(const feature of features){
109
+ if(!before.directories.includes(feature))return '提案新增了功能';
110
+ if(DOCUMENTS.some(name=>typeof proposal.files[`${feature}/${name}`]!=='string'))return '提案内容不完整,无法判断';
111
+ }
112
+ for(const [file,content] of Object.entries(proposal.files)){
113
+ const [feature,name,...rest]=file.split('/');
114
+ if(rest.length||!DOCUMENTS.includes(name)&&name!=='test-cases.json')return `提案改了规格以外的文件(${file})`;
115
+ if(content!==before.files[file]&&!CHANGEABLE.has(name))return '提案改了需求';
116
+ }
117
+ for(const feature of features){
118
+ const file=`${feature}/test-cases.json`;
119
+ let was,now;
120
+ // A test-cases.json the proposal leaves out is deleted on save: its user cases count as removed.
121
+ try{was=userCases(before.files[file]);now=userCases(proposal.files[file]);}
122
+ catch{return '提案的测试用例无法解析';}
123
+ for(const [id,item] of was)if(now.get(id)!==item)return '提案删除或减弱了用户用例';
124
+ }
125
+ return null;
126
+ }
127
+
128
+ // The saved archive (.reviews/prd-change-<digest>.json) must be this proposal and
129
+ // must be exactly what the specs now hold: features listed, proposal files written,
130
+ // every other feature untouched.
131
+ export function standingArchiveProblem(specsDir,archive,digest){
132
+ if(!record(archive)||archive.proposal?.proposalDigest!==digest)return '找不到这份提案的归档';
133
+ const problem=standingProposalProblem(archive.before,archive.proposal);
134
+ if(problem)return problem;
135
+ const {before,proposal}=archive;
136
+ const listed=fs.readdirSync(specsDir).filter(dir=>/^\d+\./.test(dir)).sort();
137
+ if(listed.join('\n')!==[...before.directories].sort().join('\n'))return '规格目录的功能与提案不一致';
138
+ // What the save leaves (cm-prd change.mjs applyPrdChange): the selected features hold
139
+ // exactly the proposal's files, every other feature its original ones. Compare the
140
+ // complete spec file set, so a file the archive does not list cannot stay on disk.
141
+ const selected=Array.isArray(archive.selected)?archive.selected:[...new Set(Object.keys(proposal.files).map(file=>file.split('/')[0]))];
142
+ const expected={...before.files};
143
+ for(const file of Object.keys(expected))if(selected.includes(file.split('/')[0]))delete expected[file];
144
+ Object.assign(expected,proposal.files);
145
+ const onDisk={};
146
+ for(const dir of listed)for(const name of [...DOCUMENTS,'test-cases.json']){
147
+ const file=`${dir}/${name}`;try{onDisk[file]=fs.readFileSync(path.join(specsDir,file),'utf8');}catch(error){if(error.code!=='ENOENT')return '规格文件与提案不一致';}
148
+ }
149
+ const files=Object.keys(expected).sort();
150
+ if(files.join('\n')!==Object.keys(onDisk).sort().join('\n')||files.some(file=>onDisk[file]!==expected[file]))return '规格文件与提案不一致';
151
+ return null;
152
+ }
@@ -0,0 +1,55 @@
1
+ // Where a batch's parallel members live: .cm-worktrees/<segment>/<taskId> and
2
+ // branch cm/<segment>/<feature>/<taskId>. One function for the scheduler, the
3
+ // driver and the batch host, so the three never disagree.
4
+ //
5
+ // Batches used to take the first 8 characters of batchId as the segment, so
6
+ // "batch-20261022-A" and "batch-20261022-B" shared worktrees and branches. A new
7
+ // batch now records a segment derived from its full id in its batch_start row.
8
+ // A batch that already started without that field keeps the old segment, so a
9
+ // resumed batch still finds the worktrees and branches it created.
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import {createHash} from 'node:crypto';
13
+ import {need} from './effect-contract.mjs';
14
+ import {scanRows} from './log-rows.mjs';
15
+
16
+ export const BATCH_SEGMENT_FIELD='worktree_segment';
17
+
18
+ // Git rejects ".." and a trailing dot in a ref component while batchId allows
19
+ // dots, so the readable prefix normalises them; the digest keeps it unique.
20
+ export function batchSegment(batchId){
21
+ need(typeof batchId==='string'&&batchId.length>0,'invalid_input');
22
+ return `${batchId.slice(0,8).replace(/\./g,'-')}-${createHash('sha256').update(batchId).digest('hex').slice(0,12)}`;
23
+ }
24
+
25
+ export function batchStarted({specsDir,batchId}){return startRow(specsDir,batchId)!==null;}
26
+ // The same bounded, no-follow, strict reader the scheduler's progress() uses: a
27
+ // log it would refuse is refused here too, before any decision rests on it.
28
+ function startRow(specsDir,batchId){
29
+ const log=path.join(specsDir,'运行日志.jsonl');
30
+ if(!fs.existsSync(log))return null;
31
+ let found=null;
32
+ scanRows(log,row=>{if(found===null&&row?.workflow==='cm-ai'&&row.event==='decision'&&row.phase==='batch_start'&&row.run_id===batchId)found=row;});
33
+ return found;
34
+ }
35
+
36
+ // {dir, ref}: the directory segment and the ref segment. They differ only for a
37
+ // legacy batch whose 8-character prefix contains a dot.
38
+ export function batchSegments({specsDir,batchId}){
39
+ const row=startRow(specsDir,batchId);
40
+ if(row!==null&&!Object.hasOwn(row,BATCH_SEGMENT_FIELD)){
41
+ const legacy=batchId.slice(0,8);
42
+ return {dir:legacy,ref:legacy.replace(/\./g,'-'),legacy:true};
43
+ }
44
+ const segment=batchSegment(batchId);
45
+ // A recorded segment must be the one this id derives; never a path from the log.
46
+ if(row!==null)need(row[BATCH_SEGMENT_FIELD]===segment,'batch_history_invalid');
47
+ return {dir:segment,ref:segment,legacy:false};
48
+ }
49
+
50
+ export function batchMemberWorktree({codeProject,segments,taskId}){
51
+ return path.resolve(codeProject,'..','.cm-worktrees',segments.dir,taskId);
52
+ }
53
+ export function batchMemberBranch({segments,feature,taskId}){
54
+ return `cm/${segments.ref}/${feature.replace(/^\d+\./,'')}/${taskId}`;
55
+ }