@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
@@ -0,0 +1,550 @@
1
+ // Offline fixtures: every fetch reads a local fake repository, never the network.
2
+ import test from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import fs from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import crypto from 'node:crypto';
8
+ import {execFileSync} from 'node:child_process';
9
+ import {fileURLToPath} from 'node:url';
10
+ import {UPSTREAM,SKILLS,skillRoots,skillState,status,statusText,hint,install,installCommand,main,placeSkill,gitEnv,autoInstall,installGate,settledSkills,localPath,autoPath} from './cm-matt-skills.mjs';
11
+
12
+ const root=fileURLToPath(new URL('..',import.meta.url));
13
+ const read=file=>fs.readFileSync(path.join(root,file),'utf8');
14
+ const sha256=text=>crypto.createHash('sha256').update(text).digest('hex');
15
+ const git=(cwd,...args)=>execFileSync('git',['-c','user.name=cm-test','-c','user.email=cm-test@example.invalid','-c','commit.gpgsign=false',...args],{cwd,stdio:['ignore','pipe','pipe']}).toString().trim();
16
+
17
+ function tempDir(t,prefix){
18
+ const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),prefix)));
19
+ t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
20
+ return dir;
21
+ }
22
+
23
+ const FAKE_FILES={
24
+ LICENSE:'MIT License\nfake upstream\n',
25
+ 'skills/productivity/alpha/SKILL.md':'---\nname: alpha\n---\nalpha\n',
26
+ 'skills/productivity/alpha/agents/openai.yaml':'alpha: yes\n',
27
+ 'skills/engineering/beta/SKILL.md':'---\nname: beta\n---\nbeta\n',
28
+ 'skills/engineering/beta/NOTES.md':'beta notes\n',
29
+ };
30
+
31
+ // A fake upstream whose pinned manifest matches FAKE_FILES; `mutate` runs before
32
+ // the commit so a test can make the repository disagree with that manifest.
33
+ function fakeUpstream(t,mutate=()=>{}){
34
+ const repo=tempDir(t,'cm-matt-repo-');
35
+ git(repo,'init','-q');
36
+ for(const [file,text] of Object.entries(FAKE_FILES)){
37
+ fs.mkdirSync(path.dirname(path.join(repo,file)),{recursive:true});
38
+ fs.writeFileSync(path.join(repo,file),text);
39
+ }
40
+ const skills=[
41
+ {name:'alpha',dir:'skills/productivity/alpha',use:'alpha use',files:{
42
+ 'SKILL.md':sha256(FAKE_FILES['skills/productivity/alpha/SKILL.md']),
43
+ 'agents/openai.yaml':sha256(FAKE_FILES['skills/productivity/alpha/agents/openai.yaml'])}},
44
+ {name:'beta',dir:'skills/engineering/beta',use:'beta use',files:{
45
+ 'SKILL.md':sha256(FAKE_FILES['skills/engineering/beta/SKILL.md']),
46
+ 'NOTES.md':sha256(FAKE_FILES['skills/engineering/beta/NOTES.md'])}},
47
+ ];
48
+ mutate(repo);
49
+ git(repo,'add','-A');
50
+ git(repo,'commit','-q','-m','fixture');
51
+ const commit=git(repo,'rev-parse','HEAD');
52
+ return {repo,skills,upstream:{repo,commit,license:{path:'LICENSE',sha256:sha256(FAKE_FILES.LICENSE)}}};
53
+ }
54
+
55
+ function home(t){
56
+ const dir=tempDir(t,'cm-matt-home-');
57
+ const tmpRoot=path.join(dir,'tmp');
58
+ fs.mkdirSync(tmpRoot);
59
+ return {dir,tmpRoot,env:{HOME:dir,CM_WORKFLOW_HOME:path.join(dir,'.cm-workflow')},
60
+ claude:path.join(dir,'.claude','skills'),codex:path.join(dir,'.agents','skills')};
61
+ }
62
+
63
+ function runInstall(h,f,extra={}){
64
+ let text='';
65
+ const code=install({env:h.env,source:f.repo,upstream:f.upstream,skills:f.skills,tmpRoot:h.tmpRoot,write:s=>{text+=s;},...extra});
66
+ return {code,text};
67
+ }
68
+
69
+ // Every path under a directory with its bytes, so "nothing written" is checked exactly.
70
+ function snapshot(dir){
71
+ if(!fs.existsSync(dir))return null;
72
+ const out={};
73
+ const walk=d=>{for(const name of fs.readdirSync(d).sort()){
74
+ const p=path.join(d,name),st=fs.lstatSync(p),rel=path.relative(dir,p);
75
+ if(st.isSymbolicLink())out[rel]=`link:${fs.readlinkSync(p)}`;
76
+ else if(st.isDirectory()){out[rel]='dir';walk(p);}
77
+ else out[rel]=fs.readFileSync(p,'utf8');
78
+ }};
79
+ walk(dir);
80
+ return out;
81
+ }
82
+
83
+ test('pinned manifest: fixed full commit, thirteen skills, well-formed checksums',()=>{
84
+ assert.equal(UPSTREAM.commit,'5beb35b040e3de97e54fa9e386d7e42d15c295c2');
85
+ assert.equal(UPSTREAM.repo,'https://github.com/mattpocock/skills.git');
86
+ assert.match(UPSTREAM.license.sha256,/^[0-9a-f]{64}$/);
87
+ assert.deepEqual(SKILLS.map(s=>s.name).sort(),['codebase-design','domain-modeling','grill-me','grill-with-docs','grilling',
88
+ 'handoff','improve-codebase-architecture','prototype','retro','setup-matt-pocock-skills','wait-what','wayfinder','writing-for-agents']);
89
+ for(const skill of SKILLS){
90
+ assert.equal(path.basename(skill.dir),skill.name);
91
+ assert.ok(skill.files['SKILL.md'],`${skill.name} pins SKILL.md`);
92
+ assert.ok(!('LICENSE' in skill.files),'LICENSE comes from the repository root');
93
+ for(const [file,sum] of Object.entries(skill.files)){
94
+ assert.match(sum,/^[0-9a-f]{64}$/,`${skill.name}/${file}`);
95
+ assert.ok(!file.startsWith('/')&&!file.split('/').includes('..'),file);
96
+ }
97
+ }
98
+ assert.equal(SKILLS.reduce((n,s)=>n+Object.keys(s.files).length,0),39);
99
+ });
100
+
101
+ test('install copies every verified skill with LICENSE into both directories',t=>{
102
+ const f=fakeUpstream(t),h=home(t);
103
+ const {code,text}=runInstall(h,f);
104
+ assert.equal(code,0,text);
105
+ for(const dir of [h.claude,h.codex]){
106
+ assert.equal(fs.readFileSync(path.join(dir,'alpha/agents/openai.yaml'),'utf8'),FAKE_FILES['skills/productivity/alpha/agents/openai.yaml']);
107
+ assert.equal(fs.readFileSync(path.join(dir,'beta/NOTES.md'),'utf8'),FAKE_FILES['skills/engineering/beta/NOTES.md']);
108
+ assert.equal(fs.readFileSync(path.join(dir,'alpha/LICENSE'),'utf8'),FAKE_FILES.LICENSE);
109
+ assert.equal(fs.readFileSync(path.join(dir,'beta/LICENSE'),'utf8'),FAKE_FILES.LICENSE);
110
+ assert.deepEqual(fs.readdirSync(dir).sort(),['alpha','beta'],'no staging directory is left behind');
111
+ }
112
+ assert.ok(status({env:h.env,skills:f.skills,upstream:f.upstream}).every(r=>r.skills.every(s=>s.state==='author')));
113
+ assert.deepEqual(fs.readdirSync(h.tmpRoot),[],'the private fetch repository is removed');
114
+ assert.match(text,/Claude.*新装 2 个/);
115
+ assert.match(text,/Codex.*新装 2 个/);
116
+ });
117
+
118
+ test('existing same-name skills are skipped, reported and left byte-for-byte unchanged',t=>{
119
+ const f=fakeUpstream(t),h=home(t);
120
+ fs.mkdirSync(path.join(h.claude,'alpha'),{recursive:true});
121
+ fs.writeFileSync(path.join(h.claude,'alpha/SKILL.md'),'my own alpha\n');
122
+ fs.mkdirSync(h.codex,{recursive:true});
123
+ fs.symlinkSync('/srv/elsewhere/beta',path.join(h.codex,'beta'));
124
+ const before={claude:snapshot(path.join(h.claude,'alpha')),link:fs.readlinkSync(path.join(h.codex,'beta'))};
125
+ const {code,text}=runInstall(h,f);
126
+ assert.equal(code,0,text);
127
+ assert.deepEqual(snapshot(path.join(h.claude,'alpha')),before.claude,'a hand-made skill is never overwritten');
128
+ assert.equal(fs.readlinkSync(path.join(h.codex,'beta')),before.link,'a dangling link counts as existing');
129
+ assert.ok(fs.existsSync(path.join(h.claude,'beta/SKILL.md')));
130
+ assert.ok(fs.existsSync(path.join(h.codex,'alpha/SKILL.md')));
131
+ assert.match(text,/跳过 1 个,未覆盖:alpha(已有同名技能但内容不同)/);
132
+ assert.match(text,/跳过 1 个,未覆盖:beta(已有同名技能但内容不同)/);
133
+ });
134
+
135
+ test('a directory that appears after planning is still never replaced',t=>{
136
+ const dir=tempDir(t,'cm-matt-place-');
137
+ const files=new Map([['SKILL.md',Buffer.from('new\n')]]);
138
+ for(const make of [p=>{fs.mkdirSync(p);},p=>{fs.mkdirSync(p);fs.writeFileSync(path.join(p,'SKILL.md'),'mine\n');},p=>fs.writeFileSync(p,'file\n'),p=>fs.symlinkSync('/srv/x',p)]){
139
+ const target=path.join(dir,'late');
140
+ make(target);
141
+ const before=snapshot(dir);
142
+ assert.equal(placeSkill(dir,'late',files),'exists');
143
+ assert.deepEqual(snapshot(dir),before,'the late directory and its parent stay untouched');
144
+ fs.rmSync(target,{recursive:true,force:true});
145
+ }
146
+ assert.equal(placeSkill(dir,'fresh',files),'installed');
147
+ assert.equal(fs.readFileSync(path.join(dir,'fresh/SKILL.md'),'utf8'),'new\n');
148
+ assert.deepEqual(fs.readdirSync(dir),['fresh']);
149
+ });
150
+
151
+ for(const [name,mutate,reason] of [
152
+ ['a changed file',repo=>fs.writeFileSync(path.join(repo,'skills/engineering/beta/NOTES.md'),'tampered\n'),/NOTES\.md 的 SHA-256 与内置清单不一致/],
153
+ ['a changed LICENSE',repo=>fs.writeFileSync(path.join(repo,'LICENSE'),'other\n'),/LICENSE 的 SHA-256/],
154
+ ['an extra file',repo=>fs.writeFileSync(path.join(repo,'skills/productivity/alpha/extra.md'),'x\n'),/多出 extra\.md/],
155
+ ['a missing file',repo=>fs.rmSync(path.join(repo,'skills/engineering/beta/NOTES.md')),/缺少 NOTES\.md/],
156
+ ['a symlink in a skill',repo=>{fs.rmSync(path.join(repo,'skills/engineering/beta/NOTES.md'));fs.symlinkSync('/srv/notes',path.join(repo,'skills/engineering/beta/NOTES.md'));},/不是普通文件(120000)/],
157
+ ]){
158
+ test(`${name} aborts the whole install before anything is written`,t=>{
159
+ const f=fakeUpstream(t,mutate),h=home(t);
160
+ fs.mkdirSync(path.join(h.claude,'mine'),{recursive:true});
161
+ fs.writeFileSync(path.join(h.claude,'mine/SKILL.md'),'keep\n');
162
+ const before=snapshot(h.claude);
163
+ const {code,text}=runInstall(h,f);
164
+ assert.equal(code,1,text);
165
+ assert.match(text,/核对失败,整批放弃,未写入任何文件/);
166
+ assert.match(text,reason);
167
+ assert.deepEqual(snapshot(h.claude),before);
168
+ assert.equal(snapshot(h.codex),null,'the Codex directory is not even created');
169
+ assert.deepEqual(fs.readdirSync(h.tmpRoot),[]);
170
+ });
171
+ }
172
+
173
+ test('a source without the pinned commit is refused; the CLI cannot swap the manifest',t=>{
174
+ const f=fakeUpstream(t),h=home(t);
175
+ let text='';
176
+ const code=main(['install','--source',f.repo],{env:h.env,write:s=>{text+=s;}});
177
+ assert.equal(code,1,text);
178
+ assert.match(text,new RegExp(`无法从 .* 拉取固定提交 ${UPSTREAM.commit}`));
179
+ assert.equal(snapshot(h.claude),null);
180
+ assert.equal(snapshot(h.codex),null);
181
+ for(const argv of [['install','--manifest','/srv/m.json'],['install','--source'],['status','--json'],['download'],[]]){
182
+ assert.equal(main(argv,{env:h.env,write:()=>{},error:()=>{}}),2,argv.join(' '));
183
+ }
184
+ });
185
+
186
+ test('a relative local source is read from the current directory',t=>{
187
+ const f=fakeUpstream(t),h=home(t);
188
+ const cwd=process.cwd();
189
+ t.after(()=>process.chdir(cwd));
190
+ process.chdir(path.dirname(f.repo));
191
+ const {code,text}=runInstall(h,f,{source:`./${path.basename(f.repo)}`});
192
+ assert.equal(code,0,text);
193
+ assert.match(text,new RegExp(`拉取 ${f.repo.replace(/[.*+?^${}()|[\]\\]/g,'\\$&')} 的固定提交`));
194
+ assert.ok(fs.existsSync(path.join(h.claude,'alpha/SKILL.md')));
195
+ });
196
+
197
+ test('downloaded files are copied, never executed',t=>{
198
+ const marker=path.join(tempDir(t,'cm-matt-marker-'),'ran');
199
+ const f=fakeUpstream(t,repo=>{
200
+ const script=path.join(repo,'skills/productivity/alpha/run.sh');
201
+ fs.writeFileSync(script,`#!/bin/sh\ntouch '${marker}'\n`,{mode:0o755});
202
+ });
203
+ f.skills[0].files['run.sh']=sha256(`#!/bin/sh\ntouch '${marker}'\n`);
204
+ const h=home(t);
205
+ const {code,text}=runInstall(h,f);
206
+ assert.equal(code,0,text);
207
+ assert.ok(fs.existsSync(path.join(h.claude,'alpha/run.sh')));
208
+ assert.equal(fs.statSync(path.join(h.claude,'alpha/run.sh')).mode&0o111,0,'copied without execute bits');
209
+ assert.equal(fs.existsSync(marker),false);
210
+ });
211
+
212
+ test('status counts only pinned author content; a same-named skill is "other"',t=>{
213
+ const f=fakeUpstream(t),h=home(t);
214
+ runInstall(h,f);
215
+ fs.writeFileSync(path.join(h.codex,'alpha/SKILL.md'),'edited\n');
216
+ fs.rmSync(path.join(h.codex,'beta'),{recursive:true});
217
+ const [claude,codex]=skillRoots(h.env);
218
+ const license=f.upstream.license.sha256;
219
+ assert.equal(skillState(claude.root,f.skills[0],license),'author');
220
+ assert.equal(skillState(codex.root,f.skills[0],license),'other');
221
+ assert.equal(skillState(codex.root,f.skills[1],license),'missing');
222
+ fs.writeFileSync(path.join(claude.root,'beta/.DS_Store'),'finder');
223
+ assert.equal(skillState(claude.root,f.skills[1],license),'author','Finder metadata does not demote a skill');
224
+ const text=statusText({env:h.env,skills:f.skills,upstream:f.upstream,command:'node /srv/cm/scripts/cm-matt-skills.mjs install'});
225
+ assert.match(text,/recommended skills \[claude\] 2\/2 author versions/);
226
+ assert.match(text,/recommended skills \[codex\] 0\/2 author versions/);
227
+ assert.match(text,/\[codex\] alpha: same name, different content/);
228
+ assert.match(text,/\[codex\] beta: missing/);
229
+ assert.match(text,/install \(optional\): node \/srv\/cm\/scripts\/cm-matt-skills\.mjs install/);
230
+ });
231
+
232
+ test('installer hint: full list once, one line while the same set is missing, full again when it changes',t=>{
233
+ const f=fakeUpstream(t),h=home(t);
234
+ const command='node /srv/cm/scripts/cm-matt-skills.mjs install';
235
+ const first=hint({env:h.env,skills:f.skills,upstream:f.upstream,command});
236
+ assert.match(first,/Claude(~\/\.claude\/skills)和Codex(~\/\.agents\/skills)都缺 2 个/);
237
+ assert.match(first,/alpha +alpha use/);
238
+ assert.match(first,/CM 不依赖)/);
239
+ assert.ok(first.includes(command));
240
+ const second=hint({env:h.env,skills:f.skills,upstream:f.upstream,command});
241
+ assert.equal(second.trim().split('\n').length,1);
242
+ assert.match(second,/还缺 2 个.*node \/srv\/cm/);
243
+ fs.mkdirSync(path.join(h.codex,'alpha'),{recursive:true});
244
+ fs.writeFileSync(path.join(h.codex,'alpha/SKILL.md'),'other\n');
245
+ const third=hint({env:h.env,skills:f.skills,upstream:f.upstream,command});
246
+ assert.match(third,/Claude(~\/\.claude\/skills)缺 2 个/);
247
+ assert.match(third,/Codex(~\/\.agents\/skills)缺 2 个/);
248
+ assert.match(third,/alpha +alpha use(已有同名技能但内容不同,安装时会跳过)/);
249
+ fs.rmSync(path.join(h.codex,'alpha'),{recursive:true});
250
+ runInstall(h,f);
251
+ assert.match(hint({env:h.env,skills:f.skills,upstream:f.upstream,command}),/^✓ 推荐搭配的 2 个 Matt Pocock 技能已齐/);
252
+ });
253
+
254
+ test('a gap that closes and then reopens identically is listed in full again',t=>{
255
+ const f=fakeUpstream(t),h=home(t);
256
+ const ask=()=>hint({env:h.env,skills:f.skills,upstream:f.upstream,command:'x'}).trim().split('\n').length;
257
+ const removeAlpha=()=>{for(const dir of [h.claude,h.codex])fs.rmSync(path.join(dir,'alpha'),{recursive:true});};
258
+ runInstall(h,f);
259
+ removeAlpha();
260
+ assert.ok(ask()>1);
261
+ assert.equal(ask(),1);
262
+ runInstall(h,f);
263
+ assert.equal(ask(),1,'all present');
264
+ removeAlpha();
265
+ assert.ok(ask()>1,'the same gap after being closed is new again');
266
+ });
267
+
268
+ test('the hint state never writes through a link planted at its path',t=>{
269
+ const f=fakeUpstream(t),h=home(t);
270
+ const stateFile=path.join(h.env.CM_WORKFLOW_HOME,'matt-skills-hint');
271
+ fs.mkdirSync(h.env.CM_WORKFLOW_HOME,{recursive:true});
272
+ const victim=path.join(h.dir,'victim.txt');
273
+ fs.writeFileSync(victim,'precious\n');
274
+ fs.symlinkSync(victim,stateFile);
275
+ hint({env:h.env,skills:f.skills,upstream:f.upstream,command:'x'});
276
+ assert.equal(fs.readFileSync(victim,'utf8'),'precious\n');
277
+ assert.equal(fs.lstatSync(stateFile).isSymbolicLink(),false,'the link entry itself is replaced');
278
+ // A hard link holding the very fingerprint the hint would trust: still not trusted.
279
+ const shared=path.join(h.dir,'shared.txt');
280
+ fs.writeFileSync(shared,fs.readFileSync(stateFile,'utf8'));
281
+ const sharedBefore=fs.readFileSync(shared,'utf8');
282
+ fs.rmSync(stateFile);
283
+ fs.linkSync(shared,stateFile);
284
+ const text=hint({env:h.env,skills:f.skills,upstream:f.upstream,command:'x'});
285
+ assert.ok(text.trim().split('\n').length>1,'a hard-linked state file is not trusted');
286
+ assert.equal(fs.readFileSync(shared,'utf8'),sharedBefore,'the shared inode is not rewritten');
287
+ assert.deepEqual(fs.readdirSync(h.env.CM_WORKFLOW_HOME).filter(n=>n.endsWith('.tmp')),[]);
288
+ });
289
+
290
+ test('author state needs the exact file set and the upstream LICENSE',t=>{
291
+ const f=fakeUpstream(t),h=home(t);
292
+ runInstall(h,f);
293
+ const license=f.upstream.license.sha256;
294
+ const [claude,codex]=skillRoots(h.env);
295
+ fs.writeFileSync(path.join(claude.root,'alpha/LICENSE'),'changed\n');
296
+ assert.equal(skillState(claude.root,f.skills[0],license),'other');
297
+ fs.rmSync(path.join(claude.root,'beta/LICENSE'));
298
+ assert.equal(skillState(claude.root,f.skills[1],license),'other');
299
+ fs.writeFileSync(path.join(codex.root,'alpha/extra.md'),'x\n');
300
+ assert.equal(skillState(codex.root,f.skills[0],license),'other');
301
+ fs.symlinkSync('/srv/notes',path.join(codex.root,'beta/link.md'));
302
+ assert.equal(skillState(codex.root,f.skills[1],license),'other');
303
+ });
304
+
305
+ test('an unusable skills root is a reported failure, never "already installed"',t=>{
306
+ const f=fakeUpstream(t),h=home(t);
307
+ fs.mkdirSync(path.dirname(h.claude),{recursive:true});
308
+ fs.writeFileSync(h.claude,'not a directory\n');
309
+ const {code,text}=runInstall(h,f);
310
+ assert.equal(code,1,text);
311
+ assert.match(text,/Claude 技能目录 .* 不是目录,这一侧不安装/);
312
+ assert.ok(fs.existsSync(path.join(h.codex,'alpha/SKILL.md')),'the other side still installs');
313
+ assert.equal(fs.readFileSync(h.claude,'utf8'),'not a directory\n');
314
+ const report=status({env:h.env,skills:f.skills,upstream:f.upstream});
315
+ assert.equal(report[0].problem,'不是目录');
316
+ assert.ok(report[0].skills.every(s=>s.state==='unreadable'));
317
+ assert.match(statusText({env:h.env,skills:f.skills,upstream:f.upstream,command:'x'}),/\[claude\] WARN skills directory .*: 不是目录/);
318
+ fs.rmSync(path.join(h.codex,'alpha'),{recursive:true});
319
+ fs.rmSync(path.join(h.codex,'beta'),{recursive:true});
320
+ fs.rmSync(h.claude);
321
+ fs.symlinkSync('/srv/missing-target',h.claude);
322
+ const again=runInstall(h,f);
323
+ assert.equal(again.code,1);
324
+ assert.match(again.text,/是失效的链接/);
325
+ });
326
+
327
+ test('git runs without the user configuration or GIT_* control variables',t=>{
328
+ const leaked={GIT_DIR:'/srv/not-a-repo',GIT_CONFIG_COUNT:'1',GIT_CONFIG_KEY_0:'core.hooksPath',
329
+ GIT_CONFIG_VALUE_0:'/srv/hooks',GIT_CONFIG_PARAMETERS:"'core.hookspath'='/srv/hooks'",GIT_SSH_COMMAND:'/srv/ssh',
330
+ GIT_ASKPASS:'/srv/askpass',https_proxy:'http://proxy.invalid:1'};
331
+ const env=gitEnv({...leaked,PATH:'/usr/bin'},'/srv/fetch-home');
332
+ for(const key of ['GIT_DIR','GIT_CONFIG_COUNT','GIT_CONFIG_KEY_0','GIT_CONFIG_VALUE_0','GIT_CONFIG_PARAMETERS','GIT_SSH_COMMAND'])
333
+ assert.equal(env[key],undefined,key);
334
+ assert.equal(env.GIT_ASKPASS,'');
335
+ assert.equal(env.GIT_CONFIG_GLOBAL,os.devNull);
336
+ assert.equal(env.GIT_CONFIG_NOSYSTEM,'1');
337
+ assert.equal(env.HOME,'/srv/fetch-home');
338
+ assert.equal(env.https_proxy,'http://proxy.invalid:1','proxies pass through');
339
+ // End to end: leaked variables that would break or hook a git call change nothing.
340
+ const f=fakeUpstream(t),h=home(t);
341
+ const marker=path.join(h.dir,'hook-ran');
342
+ const hooks=path.join(h.dir,'hooks');
343
+ fs.mkdirSync(hooks);
344
+ for(const name of ['reference-transaction','post-checkout','post-merge'])
345
+ fs.writeFileSync(path.join(hooks,name),`#!/bin/sh\ntouch '${marker}'\n`,{mode:0o755});
346
+ const saved={...process.env};
347
+ t.after(()=>{for(const key of Object.keys(process.env))if(!(key in saved))delete process.env[key];Object.assign(process.env,saved);});
348
+ Object.assign(process.env,{GIT_DIR:'/srv/not-a-repo',GIT_CONFIG_COUNT:'1',GIT_CONFIG_KEY_0:'core.hooksPath',GIT_CONFIG_VALUE_0:hooks});
349
+ const {code,text}=runInstall(h,f);
350
+ assert.equal(code,0,text);
351
+ assert.equal(fs.existsSync(marker),false);
352
+ });
353
+
354
+ test('the printed command is shell-safe',()=>{
355
+ const env={HOME:'/srv/u'};
356
+ assert.equal(installCommand(env,'/srv/u/.claude/scripts/cm-matt-skills.mjs'),'node ~/.claude/scripts/cm-matt-skills.mjs install');
357
+ assert.equal(installCommand(env,"/srv/my dir/it's/cm-matt-skills.mjs"),`node '/srv/my dir/it'\\''s/cm-matt-skills.mjs' install`);
358
+ });
359
+
360
+ test('installers put the skills in by default and accept --no-matt-skills; /cm-check only reports',()=>{
361
+ for(const [file,dest] of [['install.sh','$DEST'],['install-codex.sh','$PLUGIN_DEST']]){
362
+ const text=read(file);
363
+ assert.ok(text.includes(`node "${dest}/scripts/cm-matt-skills.mjs" auto \${SKIP_MATT_SKILLS:+--no-matt-skills} </dev/null || true`),file);
364
+ assert.ok(text.includes('--no-matt-skills) SKIP_MATT_SKILLS=1 ;;'),`${file} accepts --no-matt-skills`);
365
+ assert.ok(!/cm-matt-skills\.mjs"? install/.test(text),`${file} never runs the manual install`);
366
+ }
367
+ const ps=read('install.ps1');
368
+ assert.ok(ps.includes('[switch]$NoMattSkills'),'install.ps1 accepts -NoMattSkills');
369
+ assert.ok(ps.includes('$MattArgs = @("auto")')&&ps.includes('if ($NoMattSkills) { $MattArgs += "--no-matt-skills" }'),'install.ps1 runs auto');
370
+ const checker=read('scripts/cm-check-runtime.sh');
371
+ assert.match(checker,/if \[ "\$PRINT_EFFECTIVE" -eq 1 \] && \[ -f "\$ROOT\/scripts\/cm-matt-skills\.mjs" \]; then\n "\$NODE_BIN" "\$ROOT\/scripts\/cm-matt-skills\.mjs" status \|\|\n warn /);
372
+ for(const [skill,name] of [['cm-challenge','grill-with-docs'],['cm-refactor','improve-codebase-architecture']]){
373
+ const text=read(`skills/${skill}/SKILL.md`);
374
+ assert.ok(text.includes('cm-matt-skills.mjs" status'),skill);
375
+ assert.ok(text.includes(name),skill);
376
+ assert.match(text,/照旧/,`${skill} keeps its own flow when the author skill is absent`);
377
+ }
378
+ });
379
+
380
+ // ---- install-time default ----
381
+ async function runAuto(h,f,extra={}){
382
+ let text='';
383
+ const code=await autoInstall({env:h.env,source:f.repo,upstream:f.upstream,skills:f.skills,tmpRoot:h.tmpRoot,write:s=>{text+=s;},command:'x',...extra});
384
+ return {code,text};
385
+ }
386
+ const readRecord=h=>JSON.parse(fs.readFileSync(autoPath(h.env),'utf8'));
387
+ const writeLocal=(h,text)=>{fs.mkdirSync(path.dirname(localPath(h.env)),{recursive:true});fs.writeFileSync(localPath(h.env),text);};
388
+
389
+ test('auto installs the missing skills into both directories by default and records what is there',async t=>{
390
+ const f=fakeUpstream(t),h=home(t);
391
+ const {code,text}=await runAuto(h,f);
392
+ assert.equal(code,0);
393
+ for(const root of [h.claude,h.codex])for(const s of f.skills)assert.equal(skillState(root,s,f.upstream.license.sha256),'author');
394
+ assert.match(text,/新装 2 个:alpha、beta/);
395
+ assert.match(text,/--no-matt-skills 只管这一次/);
396
+ assert.deepEqual(readRecord(h),{version:1,installed:{claude:['alpha','beta'],codex:['alpha','beta']}});
397
+ const again=await runAuto(h,f);
398
+ assert.equal(again.code,0);
399
+ assert.match(again.text,/无需安装/);
400
+ assert.deepEqual(readRecord(h),{version:1,installed:{claude:['alpha','beta'],codex:['alpha','beta']}});
401
+ });
402
+
403
+ test('a skill the user removed after CM saw it there is never put back; one not yet seen still is',async t=>{
404
+ const f=fakeUpstream(t),h=home(t);
405
+ await runAuto(h,f);
406
+ fs.rmSync(path.join(h.claude,'alpha'),{recursive:true});
407
+ fs.rmSync(path.join(h.codex,'alpha'),{recursive:true});
408
+ fs.rmSync(path.join(h.codex,'beta'),{recursive:true});
409
+ // Pretend CM never saw beta at codex: it is missing and unsettled, so it is installed again.
410
+ fs.writeFileSync(autoPath(h.env),JSON.stringify({version:1,installed:{claude:['alpha','beta'],codex:['alpha']}})+'\n');
411
+ const {code,text}=await runAuto(h,f);
412
+ assert.equal(code,0);
413
+ assert.equal(skillState(h.claude,f.skills[0],f.upstream.license.sha256),'missing');
414
+ assert.equal(skillState(h.codex,f.skills[0],f.upstream.license.sha256),'missing');
415
+ assert.equal(skillState(h.codex,f.skills[1],f.upstream.license.sha256),'author');
416
+ assert.match(text,/Codex[^\n]*新装 1 个:beta/);
417
+ assert.match(text,/alpha 之前装过后被你删掉,不再自动装回/);
418
+ assert.deepEqual(readRecord(h),{version:1,installed:{claude:['alpha','beta'],codex:['alpha','beta']}});
419
+ const both=await runAuto(h,f);
420
+ assert.ok(!/新装/.test(both.text),'nothing left to install');
421
+ assert.match(both.text,/不再自动装回/);
422
+ });
423
+
424
+ test('a skill already there before the first auto run counts as seen, so removing it later is respected',async t=>{
425
+ const f=fakeUpstream(t),h=home(t);
426
+ const first=await runAuto(h,f,{skills:[f.skills[0]]});
427
+ assert.equal(first.code,0);
428
+ const second=await runAuto(h,f);
429
+ assert.equal(second.code,0);
430
+ assert.deepEqual(readRecord(h).installed,{claude:['alpha','beta'],codex:['alpha','beta']});
431
+ fs.rmSync(path.join(h.claude,'alpha'),{recursive:true});
432
+ const third=await runAuto(h,f);
433
+ assert.equal(skillState(h.claude,f.skills[0],f.upstream.license.sha256),'missing');
434
+ assert.match(third.text,/不再自动装回/);
435
+ });
436
+
437
+ test('--no-matt-skills and CM_MATT_SKILLS_INSTALL=off skip this run and only hint; {"install": false} turns it off for good',async t=>{
438
+ const f=fakeUpstream(t),h=home(t);
439
+ for(const extra of [{skip:true},{env:{...h.env,CM_MATT_SKILLS_INSTALL:'off'}}]){
440
+ const {code,text}=await runAuto(h,f,extra);
441
+ assert.equal(code,0);
442
+ assert.match(text,/这次不自动安装(只管这一次/);
443
+ assert.match(text,/推荐(搭配 Matt Pocock 的技能|的 Matt Pocock 技能还缺 2 个)/,'the plain hint still says what is missing');
444
+ assert.equal(snapshot(h.claude),null);
445
+ assert.equal(snapshot(h.codex),null);
446
+ assert.ok(!fs.existsSync(autoPath(h.env)),'an opted-out run settles nothing');
447
+ }
448
+ writeLocal(h,'{"install": false}\n');
449
+ const off=await runAuto(h,f);
450
+ assert.equal(off.code,0);
451
+ assert.match(off.text,/install 为 false,不自动安装;要装运行 x/);
452
+ assert.equal(snapshot(h.claude),null);
453
+ assert.ok(!fs.existsSync(autoPath(h.env)));
454
+ assert.match(statusText({env:h.env,skills:f.skills,upstream:f.upstream,command:'x'}),/auto-install at install time: off \(/);
455
+ });
456
+
457
+ test('a local file CM cannot use pauses the default: a warning, nothing written, the file kept',async t=>{
458
+ for(const bad of ['',' ','{bad','{"install": "no"}','[]','{"install": 1}']){
459
+ const f=fakeUpstream(t),h=home(t);
460
+ writeLocal(h,bad);
461
+ const {code,text}=await runAuto(h,f);
462
+ assert.equal(code,1,JSON.stringify(bad));
463
+ assert.match(text,/⚠ 作者技能:.*这次不自动安装;改好后重装或运行 x/);
464
+ assert.equal(snapshot(h.claude),null);
465
+ assert.equal(fs.readFileSync(localPath(h.env),'utf8'),bad);
466
+ assert.match(statusText({env:h.env,skills:f.skills,upstream:f.upstream,command:'x'}),/auto-install at install time: paused \(/);
467
+ }
468
+ });
469
+
470
+ test('a record CM cannot read pauses the default and is kept as is',async t=>{
471
+ for(const bad of ['{"version": 2, "installed": {}}','{"version": 1, "installed": {"other": []}}','{"version": 1, "installed": {"claude": ["Bad Name"]}}','nope']){
472
+ const f=fakeUpstream(t),h=home(t);
473
+ fs.mkdirSync(path.dirname(autoPath(h.env)),{recursive:true});
474
+ fs.writeFileSync(autoPath(h.env),bad);
475
+ const {code,text}=await runAuto(h,f);
476
+ assert.equal(code,1,bad);
477
+ assert.match(text,/⚠ 作者技能:.*异常/);
478
+ assert.match(text,/推荐搭配 Matt Pocock 的技能/);
479
+ assert.equal(snapshot(h.claude),null);
480
+ assert.equal(fs.readFileSync(autoPath(h.env),'utf8'),bad);
481
+ assert.equal(settledSkills(h.env).state,'invalid');
482
+ }
483
+ });
484
+
485
+ test('a fetch that fails only warns and names the manual command; nothing is written or recorded',async t=>{
486
+ const f=fakeUpstream(t),h=home(t);
487
+ const {code,text}=await runAuto(h,f,{upstream:{...f.upstream,commit:'0'.repeat(40)}});
488
+ assert.equal(code,1);
489
+ assert.match(text,/✗ 核对失败,整批放弃,未写入任何文件/);
490
+ assert.match(text,/作者技能不影响 CM 使用;稍后可手动运行 x/);
491
+ assert.equal(snapshot(h.claude),null);
492
+ assert.equal(snapshot(h.codex),null);
493
+ assert.ok(!fs.existsSync(autoPath(h.env)));
494
+ });
495
+
496
+ test('the gate reads the environment and the local file only',t=>{
497
+ const h=home(t);
498
+ assert.equal(installGate(h.env),null);
499
+ assert.deepEqual(installGate(h.env,true),{optOut:'安装参数 --no-matt-skills'});
500
+ assert.deepEqual(installGate({...h.env,CM_MATT_SKILLS_INSTALL:'off'}),{optOut:'环境变量 CM_MATT_SKILLS_INSTALL=off'});
501
+ assert.equal(installGate({...h.env,CM_MATT_SKILLS_INSTALL:'on'}),null);
502
+ writeLocal(h,'{"install": true}');
503
+ assert.equal(installGate(h.env),null);
504
+ });
505
+
506
+ test('the auto command parses its arguments like install',async t=>{
507
+ const f=fakeUpstream(t),h=home(t);
508
+ let text='',err='';
509
+ assert.equal(await main(['auto','--bogus'],{env:h.env,write:s=>{text+=s;},error:s=>{err+=s;}}),2);
510
+ assert.equal(await main(['auto','--source'],{env:h.env,write:s=>{text+=s;},error:s=>{err+=s;}}),2);
511
+ assert.match(err,/auto \[--no-matt-skills\]/);
512
+ assert.equal(await main(['auto','--no-matt-skills','--source',f.repo],{env:{...h.env},write:s=>{text+=s;},error:s=>{err+=s;}}),0);
513
+ assert.match(text,/这次不自动安装/);
514
+ assert.equal(snapshot(h.claude),null);
515
+ });
516
+
517
+ test('a same-named skill with other content counts as seen too: removed later, it is not put back',async t=>{
518
+ const f=fakeUpstream(t),h=home(t);
519
+ fs.mkdirSync(path.join(h.claude,'alpha'),{recursive:true});
520
+ fs.writeFileSync(path.join(h.claude,'alpha','SKILL.md'),'mine\n');
521
+ const first=await runAuto(h,f);
522
+ assert.equal(first.code,0);
523
+ assert.match(first.text,/跳过 1 个,未覆盖:alpha(已有同名技能但内容不同)/);
524
+ assert.equal(fs.readFileSync(path.join(h.claude,'alpha','SKILL.md'),'utf8'),'mine\n');
525
+ assert.deepEqual(readRecord(h).installed,{claude:['alpha','beta'],codex:['alpha','beta']});
526
+ fs.rmSync(path.join(h.claude,'alpha'),{recursive:true});
527
+ const second=await runAuto(h,f);
528
+ assert.equal(second.code,0);
529
+ assert.equal(skillState(h.claude,f.skills[0],f.upstream.license.sha256),'missing');
530
+ assert.match(second.text,/Claude 的 alpha 之前装过后被你删掉,不再自动装回/);
531
+ });
532
+
533
+ test('an unreadable skill is never recorded as seen',async t=>{
534
+ const f=fakeUpstream(t),h=home(t);
535
+ fs.mkdirSync(h.claude,{recursive:true});
536
+ fs.writeFileSync(path.join(h.claude,'alpha'),'not a directory\n');
537
+ const {code}=await runAuto(h,f);
538
+ assert.equal(code,0);
539
+ assert.deepEqual(readRecord(h).installed,{claude:['alpha','beta'],codex:['alpha','beta']},'a file at the name is "other": present, kept, seen');
540
+ const g=fakeUpstream(t),k=home(t);
541
+ fs.mkdirSync(k.claude,{recursive:true});
542
+ fs.mkdirSync(path.join(k.claude,'alpha'),{mode:0o000});
543
+ try{
544
+ if(process.getuid?.()!==0){
545
+ const r=await runAuto(k,g);
546
+ assert.equal(r.code,1,'an unreadable skill is reported as a failure');
547
+ assert.deepEqual(readRecord(k).installed,{claude:['beta'],codex:['alpha','beta']});
548
+ }
549
+ }finally{fs.chmodSync(path.join(k.claude,'alpha'),0o755);}
550
+ });