@aibyzero/cm-workflow 0.17.1 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +23 -0
  3. package/CHANGELOG.md +224 -0
  4. package/README.md +14 -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/cm-ai/batch-location.mjs +55 -0
  22. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  23. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  24. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  25. package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
  26. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  27. package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
  28. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  29. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  30. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  31. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  32. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  33. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  34. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  35. package/runtime/js/cm-ai/control-policy.mjs +21 -4
  36. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  37. package/runtime/js/cm-ai/drive-core.mjs +114 -11
  38. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  39. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  40. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  41. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  42. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  43. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  44. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  45. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  46. package/runtime/js/cm-ai/host-check.mjs +11 -5
  47. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  48. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  49. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  50. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  51. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  52. package/runtime/js/cm-ai/host-session.mjs +1 -1
  53. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  54. package/runtime/js/cm-ai/host.mjs +1 -1
  55. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  56. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  57. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  58. package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
  59. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  60. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  61. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  62. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  63. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  64. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  65. package/runtime/js/cm-ai/review-package.mjs +79 -7
  66. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  67. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  68. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  69. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  70. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  71. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  72. package/runtime/js/cm-ai/task-runner.mjs +242 -39
  73. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  74. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  75. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  76. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  77. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  78. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  79. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  80. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  81. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  82. package/runtime/js/cm-fix/dossier.mjs +8 -2
  83. package/runtime/js/cm-fix/execution.mjs +578 -100
  84. package/runtime/js/cm-fix/final-review.mjs +39 -8
  85. package/runtime/js/cm-fix/finish.mjs +15 -11
  86. package/runtime/js/cm-fix/host-review.mjs +65 -10
  87. package/runtime/js/cm-fix/host.mjs +35 -12
  88. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  89. package/runtime/js/cm-fix/metrics.mjs +18 -5
  90. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  91. package/runtime/js/cm-fix/regression.mjs +16 -7
  92. package/runtime/js/cm-fix/repair.mjs +29 -8
  93. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  94. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  95. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  96. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  97. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  98. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  99. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  100. package/runtime/js/cm-fix/start.mjs +6 -3
  101. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  102. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  103. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  104. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  105. package/runtime/js/cm-prd/analysis.mjs +13 -9
  106. package/runtime/js/cm-prd/change.mjs +37 -16
  107. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  108. package/runtime/js/cm-prd/draft.mjs +31 -3
  109. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  110. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  111. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  112. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  113. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  114. package/runtime/js/cm-prd/self-check.mjs +125 -6
  115. package/runtime/js/cm-prd/session.mjs +30 -1
  116. package/runtime/js/cm-prd/summary.mjs +11 -5
  117. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  118. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  119. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  120. package/runtime/js/cm-security/scan.mjs +1 -1
  121. package/runtime/js/commander/decision.mjs +44 -0
  122. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  123. package/runtime/js/commander/ledger.mjs +265 -0
  124. package/runtime/js/commander/preflight.mjs +107 -0
  125. package/runtime/js/notify-later.mjs +13 -0
  126. package/runtime/js/notify-send.mjs +6 -2
  127. package/runtime/js/notify.mjs +570 -63
  128. package/runtime/js/review-findings.mjs +38 -0
  129. package/runtime/js/session-boundary.mjs +56 -0
  130. package/runtime/js/session-handoff.mjs +68 -0
  131. package/runtime/js/spec-task-line.mjs +27 -13
  132. package/runtime/js/specs-status.mjs +1 -1
  133. package/runtime/js/task-scope.mjs +197 -0
  134. package/runtime/logging.md +6 -1
  135. package/runtime/model-efficiency.md +69 -10
  136. package/runtime/orchestration.md +3 -1
  137. package/runtime/project-learning.md +2 -0
  138. package/runtime/review.md +3 -2
  139. package/runtime/test-contract.md +1 -0
  140. package/scripts/ci-test-weights.json +3 -0
  141. package/scripts/cm-ai-admission.mjs +11 -5
  142. package/scripts/cm-ai-admission.test.mjs +23 -2
  143. package/scripts/cm-ai-batch-drive.mjs +79 -18
  144. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  145. package/scripts/cm-ai-batch-host.mjs +38 -9
  146. package/scripts/cm-ai-batch-host.test.mjs +6 -5
  147. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  148. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  149. package/scripts/cm-ai-batch-plan.mjs +52 -0
  150. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  151. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  152. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  153. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  154. package/scripts/cm-ai-batch-run.mjs +471 -57
  155. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  156. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  157. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  158. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  159. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  160. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  161. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  162. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  163. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  164. package/scripts/cm-ai-control-policy.test.mjs +14 -0
  165. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  166. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  167. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  168. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  169. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  170. package/scripts/cm-ai-drive.mjs +73 -17
  171. package/scripts/cm-ai-drive.test.mjs +34 -2
  172. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  173. package/scripts/cm-ai-host.mjs +60 -19
  174. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  175. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  176. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  177. package/scripts/cm-ai-integration-preview.mjs +41 -0
  178. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  179. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  180. package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
  181. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  182. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  183. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  184. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  185. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  186. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  187. package/scripts/cm-ai-run.mjs +88 -21
  188. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  189. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  190. package/scripts/cm-ai-supersede.test.mjs +28 -0
  191. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  192. package/scripts/cm-announce-hook.mjs +35 -8
  193. package/scripts/cm-announce-hook.test.mjs +25 -0
  194. package/scripts/cm-challenge.test.mjs +61 -0
  195. package/scripts/cm-check-drive-files.mjs +1 -1
  196. package/scripts/cm-check-runtime.sh +58 -1
  197. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  198. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  199. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  200. package/scripts/cm-claude-review-stream.test.mjs +13 -0
  201. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  202. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  203. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  204. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  205. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  206. package/scripts/cm-commander-ledger.test.mjs +260 -0
  207. package/scripts/cm-commander-p2.test.mjs +295 -0
  208. package/scripts/cm-commander-preflight.mjs +84 -0
  209. package/scripts/cm-commander.mjs +116 -0
  210. package/scripts/cm-config-lock.mjs +35 -0
  211. package/scripts/cm-controlled-correction.test.mjs +10 -1
  212. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  213. package/scripts/cm-display-task-id.test.mjs +41 -0
  214. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  215. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  216. package/scripts/cm-external-batch-host.test.mjs +4 -3
  217. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  218. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  219. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  220. package/scripts/cm-failover.mjs +48 -10
  221. package/scripts/cm-failover.test.mjs +46 -0
  222. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  223. package/scripts/cm-fix-command-correction.mjs +17 -0
  224. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  225. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  226. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  227. package/scripts/cm-fix-drive.mjs +33 -5
  228. package/scripts/cm-fix-drive.test.mjs +49 -0
  229. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  230. package/scripts/cm-fix-host-review.test.mjs +21 -9
  231. package/scripts/cm-fix-host.mjs +26 -8
  232. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  233. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  234. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  235. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  236. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  237. package/scripts/cm-fix-review-preflight.mjs +24 -0
  238. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  239. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  240. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  241. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  242. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  243. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  244. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  245. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  246. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  247. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  248. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  249. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  250. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  251. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  252. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  253. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  254. package/scripts/cm-host-replay.test.mjs +176 -0
  255. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  256. package/scripts/cm-install-manifest.sh +351 -0
  257. package/scripts/cm-live-evidence.test.mjs +59 -1
  258. package/scripts/cm-log-event.mjs +61 -10
  259. package/scripts/cm-log-event.test.mjs +121 -1
  260. package/scripts/cm-matt-skills.mjs +576 -0
  261. package/scripts/cm-matt-skills.test.mjs +550 -0
  262. package/scripts/cm-notify-command.test.mjs +42 -10
  263. package/scripts/cm-notify.mjs +14 -10
  264. package/scripts/cm-notify.test.mjs +575 -59
  265. package/scripts/cm-patrol.mjs +4 -1
  266. package/scripts/cm-patrol.test.mjs +23 -5
  267. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  268. package/scripts/cm-prd-completion.test.mjs +56 -13
  269. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  270. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  271. package/scripts/cm-prd-draft.test.mjs +1 -1
  272. package/scripts/cm-prd-drive.mjs +13 -6
  273. package/scripts/cm-prd-drive.test.mjs +45 -1
  274. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  275. package/scripts/cm-prd-host.mjs +10 -5
  276. package/scripts/cm-prd-host.test.mjs +4 -2
  277. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  278. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  279. package/scripts/cm-prd-revision.test.mjs +1 -1
  280. package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
  281. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  282. package/scripts/cm-prd-self-check.test.mjs +105 -5
  283. package/scripts/cm-prd-summary.test.mjs +24 -3
  284. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  285. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  286. package/scripts/cm-refactor-drive.mjs +2 -1
  287. package/scripts/cm-refactor-drive.test.mjs +9 -0
  288. package/scripts/cm-release-smoke.sh +1 -1
  289. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  290. package/scripts/cm-skill-hints-exam.mjs +149 -0
  291. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  292. package/scripts/cm-skill-hints.exam.json +706 -0
  293. package/scripts/cm-skill-hints.json +119 -0
  294. package/scripts/cm-skill-hints.mjs +669 -0
  295. package/scripts/cm-skill-hints.test.mjs +831 -0
  296. package/scripts/cm-skill-judge.mjs +181 -0
  297. package/scripts/cm-skill-judge.test.mjs +255 -0
  298. package/scripts/cm-specs-status.test.mjs +4 -2
  299. package/scripts/cm-start-check.mjs +208 -0
  300. package/scripts/cm-start-check.test.mjs +321 -0
  301. package/scripts/cm-task-gate.mjs +150 -29
  302. package/scripts/cm-task-gate.test.mjs +73 -1
  303. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  304. package/scripts/cm-task-scope.test.mjs +308 -0
  305. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  306. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  307. package/scripts/cm-workflow-config.mjs +12 -2
  308. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  309. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  310. package/scripts/scan-public-safety.py +1 -0
  311. package/scripts/session-boundary.test.mjs +170 -0
  312. package/scripts/test-npm-install.py +14 -3
  313. package/scripts/test-shell-compat.sh +2 -0
  314. package/scripts/validate-public-repo.py +1 -0
  315. package/scripts/validate-test-cases.mjs +3 -2
  316. package/skills/cm-ai/SKILL.md +5 -2
  317. package/skills/cm-ai/references/N4-review.md +2 -1
  318. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  319. package/skills/cm-ai/references/N8-finish.md +22 -0
  320. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  321. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  322. package/skills/cm-ai/references/js-host.md +56 -16
  323. package/skills/cm-challenge/SKILL.md +65 -0
  324. package/skills/cm-challenge/evals/README.md +18 -0
  325. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  326. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  327. package/skills/cm-challenge/references/examples.md +15 -0
  328. package/skills/cm-check/SKILL.md +5 -0
  329. package/skills/cm-check/references/js-host.md +2 -0
  330. package/skills/cm-fix/SKILL.md +12 -3
  331. package/skills/cm-fix/references/command-correction.md +67 -0
  332. package/skills/cm-fix/references/isolated-review.md +54 -0
  333. package/skills/cm-fix/references/js-host.md +62 -2
  334. package/skills/cm-fix/references/test-type-correction.md +72 -0
  335. package/skills/cm-fix/references/verification-recovery.md +114 -0
  336. package/skills/cm-idea/SKILL.md +2 -0
  337. package/skills/cm-idea/references/js-host.md +2 -0
  338. package/skills/cm-notify/SKILL.md +2 -0
  339. package/skills/cm-prd/SKILL.md +12 -8
  340. package/skills/cm-prd/references/brownfield.md +8 -1
  341. package/skills/cm-prd/references/change-mode.md +6 -0
  342. package/skills/cm-prd/references/greenfield.md +4 -0
  343. package/skills/cm-prd/references/js-host.md +4 -2
  344. package/skills/cm-prd/references/spec-self-check.md +5 -1
  345. package/skills/cm-refactor/SKILL.md +8 -0
  346. package/skills/cm-refactor/references/js-host.md +2 -0
  347. package/skills/cm-test/SKILL.md +4 -0
  348. package/templates/dashboard/dashboard.html +2 -2
  349. package/templates/pixel/cm-pixel.html +1 -1
  350. package/templates/pixel/cm-pixel.sh +1 -1
  351. package/templates/pixel/dev/template.html +1 -1
  352. package/templates/statusline/cm-statusline.sh +1 -1
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/env node
2
+ // Read-only start check for a cm-ai single-task drive PLAN. It reports the blocks that
3
+ // are already knowable before create: protected scope, check budget, dirty scope files.
4
+ // It never writes a file, never starts a host and never runs a check command.
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import {pathToFileURL} from 'node:url';
8
+ import {protectedScopePaths, validateDeveloperScope} from '../runtime/js/cm-ai/developer-adapter.mjs';
9
+ import {planCheckTimeout} from '../runtime/js/cm-ai/drive-core.mjs';
10
+ import {git as safeGit} from '../runtime/js/cm-security/scan.mjs';
11
+
12
+ // The whole check step of a current-session run is one host call with this deadline
13
+ // (runtime/js/cm-ai/host-conversation-execution.mjs, outerTimeoutMs). The test
14
+ // file guards that the literal is still there.
15
+ export const CHECK_CALL_LIMIT_MS = 1800000;
16
+ const MAX_LISTED = 20;
17
+ // validateRunDefinition (scripts/cm-ai-run.mjs) refuses more than this many scope paths.
18
+ // The test file guards that the literal is still there.
19
+ export const MAX_SCOPE_PATHS = 256;
20
+
21
+ class InputError extends Error {}
22
+
23
+ const usage = '用法: cm-start-check.mjs --plan PLAN.json [--json] [--strict]\n'
24
+ + '只读体检,开工前跑一次。只支持普通单任务、当前会话模式的 PLAN;\n'
25
+ + 'PLAN.permissions 含受保护模式、provider 开发或 bootstrap 参数时退出 2,不给出结论。\n'
26
+ + ' 1. scope 是否含受保护路径(AGENTS.md、tasks.md、.reviews、.cm-* 等)——error;\n'
27
+ + ' scope 为空、重复、绝对路径、含 ../反斜杠/冒号等创建必拒的写法——输入不合法,退出 2\n'
28
+ + ' 2. PLAN.checks 是否重复、是否重复跑全量测试、各检查超时之和是否超过整步 30 分钟——warn\n'
29
+ + ' 3. scope 内文件在代码根是否已有未提交改动——warn(Git 不可用时是 warn,不是 Git 仓库时是 info)\n'
30
+ + '退出码:0 无 error(warn 只提示);1 有 error,或加 --strict 时有 warn;2 输入读不了或不支持。\n';
31
+
32
+ // Modes this check does not model: another check budget (provider), another scope rule
33
+ // (bootstrap may name protected rule files) or another check source (protected configs).
34
+ const UNSUPPORTED_MODE_FLAGS = new Map([
35
+ ['--protected-config', '受保护模式'], ['--protected-conversation-config', '受保护的当前会话模式'],
36
+ ['--allow-provider-development-attempt', 'provider 开发'],
37
+ ['--bootstrap-config', 'bootstrap'], ['--allow-bootstrap-write', 'bootstrap']]);
38
+
39
+ function readJson(file, label) {
40
+ let raw;
41
+ try { raw = fs.readFileSync(file, 'utf8'); }
42
+ catch (error) { throw new InputError(`读不了${label}: ${file}(${error.code ?? error.message})`); }
43
+ try { return JSON.parse(raw); }
44
+ catch { throw new InputError(`${label}不是合法 JSON: ${file}`); }
45
+ }
46
+
47
+ export function loadStartInputs(planFile) {
48
+ const planPath = path.resolve(planFile), base = path.dirname(planPath);
49
+ const plan = readJson(planPath, 'PLAN');
50
+ if (plan === null || typeof plan !== 'object' || Array.isArray(plan)) throw new InputError('PLAN 必须是 JSON 对象');
51
+ if (typeof plan.config !== 'string' || plan.config === '') throw new InputError('PLAN 缺少字段 config(已批准的运行定义路径)');
52
+ if (plan.permissions !== undefined && (!Array.isArray(plan.permissions) || !plan.permissions.every(item => typeof item === 'string')))
53
+ throw new InputError('PLAN.permissions 必须是字符串数组');
54
+ for (const item of plan.permissions ?? []) {
55
+ if (UNSUPPORTED_MODE_FLAGS.has(item))
56
+ throw new InputError(`PLAN.permissions 含 ${item}(${UNSUPPORTED_MODE_FLAGS.get(item)}):本体检只支持普通单任务、当前会话模式,不给出结论;请按 js-host.md 启动前第 8 项手工核对`);
57
+ }
58
+ const definition = readJson(path.resolve(base, plan.config), '运行定义');
59
+ if (definition === null || typeof definition !== 'object' || !Array.isArray(definition.scope)
60
+ || !definition.scope.every(item => typeof item === 'string'))
61
+ throw new InputError('运行定义没有 scope 数组:本体检只支持单任务运行定义,批次请逐个任务检查');
62
+ if (typeof definition.codeProject !== 'string' || !path.isAbsolute(definition.codeProject))
63
+ throw new InputError('运行定义的 codeProject 必须是绝对路径');
64
+ return {plan, definition};
65
+ }
66
+
67
+ function checkProtectedScope(scope) {
68
+ if (scope.length > MAX_SCOPE_PATHS)
69
+ throw new InputError(`scope 有 ${scope.length} 条路径,超过创建运行允许的 ${MAX_SCOPE_PATHS} 条;创建会被拒绝,先拆任务或收窄 scope`);
70
+ const protectedPaths = protectedScopePaths(scope);
71
+ const rest = scope.filter(item => !protectedPaths.includes(item));
72
+ if (rest.length > 0 || protectedPaths.length === 0) {
73
+ // Shape errors the runtime refuses at create (empty, duplicate, absolute, .., backslash, colon):
74
+ // not a finding, because "passed" would be wrong for an input that cannot start.
75
+ try { validateDeveloperScope(rest); }
76
+ catch { throw new InputError('scope 不合法:为空、有重复项,或含绝对路径、..、反斜杠、冒号等写法;创建运行会被拒绝,先改 scope'); }
77
+ }
78
+ return protectedPaths.map(item => ({level: 'error', code: 'protected_scope', path: item,
79
+ message: `scope 含受保护路径 ${item}:创建运行会被 protected_scope 拒绝。先走人工通道同步该文件,再把它从 scope 里去掉`}));
80
+ }
81
+
82
+ const isXcodebuild = tokens => tokens.some(token => path.basename(token) === 'xcodebuild');
83
+ const isTestAction = tokens => tokens.some(token => token === 'test' || token === 'test-without-building');
84
+ const optionValue = (tokens, name) => {
85
+ const at = tokens.indexOf(name);
86
+ return at === -1 ? '' : tokens[at + 1] ?? '';
87
+ };
88
+
89
+ function checkChecks(plan) {
90
+ const findings = [];
91
+ if (!Array.isArray(plan.checks)) return findings;
92
+ const items = plan.checks.filter(item => item !== null && typeof item === 'object' && !Array.isArray(item));
93
+ let timeouts;
94
+ try { timeouts = items.map(item => planCheckTimeout(plan, item)); }
95
+ catch (error) { throw new InputError(error.message); }
96
+ // sameExecutionAs entries reuse the previous execution: they neither repeat it nor add time.
97
+ const own = items.map((item, index) => ({item, timeoutMs: timeouts[index]}))
98
+ .filter(entry => !Object.hasOwn(entry.item, 'sameExecutionAs'));
99
+ const byCommand = new Map();
100
+ for (const entry of own) {
101
+ const key = JSON.stringify(entry.item.command ?? null);
102
+ byCommand.set(key, [...(byCommand.get(key) ?? []), entry]);
103
+ }
104
+ for (const group of byCommand.values()) {
105
+ if (group.length < 2) continue;
106
+ findings.push({level: 'warn', code: 'duplicate_check', ids: group.map(entry => entry.item.id),
107
+ message: `检查 ${group.map(entry => entry.item.id).join('、')} 的命令完全相同,会白跑 ${group.length - 1} 遍。去掉重复项,或给后面的加 sameExecutionAs`});
108
+ }
109
+ const overlap = new Map();
110
+ for (const group of byCommand.values()) {
111
+ const tokens = group[0].item.command;
112
+ if (!Array.isArray(tokens) || !tokens.every(token => typeof token === 'string')) continue;
113
+ if (!isXcodebuild(tokens) || !isTestAction(tokens) || tokens.some(token => token.startsWith('-only-testing'))) continue;
114
+ const key = ['-workspace', '-project', '-scheme', '-destination', '-testPlan'].map(name => optionValue(tokens, name)).join('\u0000');
115
+ overlap.set(key, [...(overlap.get(key) ?? []), group[0]]);
116
+ }
117
+ for (const group of overlap.values()) {
118
+ if (group.length < 2) continue;
119
+ findings.push({level: 'warn', code: 'overlapping_full_test', ids: group.map(entry => entry.item.id),
120
+ message: `检查 ${group.map(entry => entry.item.id).join('、')} 都是同一 scheme/目的地、没有 -only-testing 的 xcodebuild test,很可能各自跑了一遍全量。保留一个,或用 -only-testing 分开`});
121
+ }
122
+ const totalMs = own.reduce((sum, entry) => sum + entry.timeoutMs, 0);
123
+ if (totalMs > CHECK_CALL_LIMIT_MS)
124
+ findings.push({level: 'warn', code: 'check_budget_over_call_limit', totalMs, limitMs: CHECK_CALL_LIMIT_MS,
125
+ message: `各检查超时之和 ${Math.round(totalMs / 60000)} 分钟,超过检查整步的 ${CHECK_CALL_LIMIT_MS / 60000} 分钟期限;这是最坏情况,实际可能更短。拆成多次运行,或缩减检查`});
126
+ return findings;
127
+ }
128
+
129
+ function hasGitMarker(root) {
130
+ for (let current = root; ; current = path.dirname(current)) {
131
+ if (fs.existsSync(path.join(current, '.git'))) return true;
132
+ if (path.dirname(current) === current) return false;
133
+ }
134
+ }
135
+
136
+ function checkDirtyScope(definition) {
137
+ if (!fs.existsSync(definition.codeProject)) return [{level: 'warn', code: 'code_project_missing',
138
+ message: `代码根不存在:${definition.codeProject},没能核对 scope 是否干净`}];
139
+ // The reader keeps a PATH git that lives inside the project out of reach by comparing real
140
+ // paths, so hand it the real path of the root (a symlinked temp dir otherwise defeats that).
141
+ const root = fs.realpathSync(definition.codeProject);
142
+ // safeGit is the scanner's reader: trusted git binary, no repository-configured fsmonitor or
143
+ // clean/process/required filters, no user config. A failure to run it is a warn, never a pass.
144
+ let inside;
145
+ try { inside = safeGit(root, ['rev-parse', '--is-inside-work-tree'], true); }
146
+ catch (error) {
147
+ return [{level: 'warn', code: 'git_unavailable',
148
+ message: `Git 不可用或被拒绝(${error.message}),没能核对 scope 是否干净`}];
149
+ }
150
+ if (inside === null || inside.toString('utf8').trim() !== 'true') {
151
+ // The reader folds every non-zero exit into null. A repository marker that exists while git
152
+ // refuses it (damaged repo, unsafe owner) is a failed check, not a project without git.
153
+ if (hasGitMarker(root)) return [{level: 'warn', code: 'git_refused',
154
+ message: '代码根或其上级有 .git,但 Git 拒绝读取(仓库损坏或目录属主不同等),没能核对 scope 是否干净'}];
155
+ return [{level: 'info', code: 'not_git', message: '代码根不是 Git 仓库,已跳过 scope 未提交改动核对'}];
156
+ }
157
+ let output;
158
+ try { output = safeGit(root, ['--literal-pathspecs', 'status', '--porcelain=v1', '-z', '--untracked-files=all', '--', ...definition.scope]); }
159
+ catch (error) {
160
+ return [{level: 'warn', code: 'git_status_failed', message: `git status 失败(${error.message}),没能核对 scope 是否干净`}];
161
+ }
162
+ const dirty = [];
163
+ const entries = output.toString('utf8').split('\0');
164
+ for (let i = 0; i < entries.length; i += 1) {
165
+ const entry = entries[i];
166
+ if (entry.length < 4) continue;
167
+ dirty.push({status: entry.slice(0, 2).trim() || '?', path: entry.slice(3)});
168
+ if (/[RC]/.test(entry.slice(0, 2))) i += 1;
169
+ }
170
+ if (dirty.length === 0) return [];
171
+ const shown = dirty.slice(0, MAX_LISTED).map(item => `${item.status} ${item.path}`);
172
+ return [{level: 'warn', code: 'scope_dirty', count: dirty.length, paths: dirty.slice(0, MAX_LISTED).map(item => item.path),
173
+ message: `scope 内 ${dirty.length} 个文件已有未提交改动(含新建):${shown.join(';')}${dirty.length > MAX_LISTED ? '…' : ''}。`
174
+ + '运行基线会把它们当起点,交审包里看不到这部分改动;若是上次的任务代码,先还原,确认是有意保留的再继续'}];
175
+ }
176
+
177
+ export function startCheck(planFile) {
178
+ const {plan, definition} = loadStartInputs(planFile);
179
+ return [...checkProtectedScope(definition.scope), ...checkChecks(plan), ...checkDirtyScope(definition)];
180
+ }
181
+
182
+ export function main(argv = process.argv.slice(2), out = process.stdout, err = process.stderr) {
183
+ const rest = argv.filter(arg => arg !== '--json' && arg !== '--strict');
184
+ const at = rest.indexOf('--plan');
185
+ if (argv.includes('--help') || argv.includes('-h')) { out.write(usage); return 0; }
186
+ if (at === -1 || !rest[at + 1] || rest.length !== 2) { err.write(usage); return 2; }
187
+ let findings;
188
+ try { findings = startCheck(rest[at + 1]); }
189
+ catch (error) {
190
+ if (!(error instanceof InputError)) throw error;
191
+ err.write(`${error.message}\n`);
192
+ return 2;
193
+ }
194
+ const errors = findings.filter(item => item.level === 'error').length;
195
+ const warns = findings.filter(item => item.level === 'warn').length;
196
+ const skipped = findings.filter(item => item.level === 'info').length;
197
+ if (argv.includes('--json')) out.write(`${JSON.stringify({errors, warns, skipped, findings})}\n`);
198
+ else {
199
+ for (const item of findings) out.write(`[${item.level}] ${item.code}: ${item.message}\n`);
200
+ const note = skipped > 0 ? `(另有 ${skipped} 项核对被跳过,见上)` : '';
201
+ if (errors + warns > 0) out.write(`体检结果:${errors} 个 error,${warns} 个 warn${note}\n`);
202
+ else if (skipped > 0) out.write(`体检完成:已核对的项目没有发现阻塞,但有 ${skipped} 项核对被跳过,见上\n`);
203
+ else out.write('体检通过:没有发现可提前识别的阻塞\n');
204
+ }
205
+ return errors > 0 || (argv.includes('--strict') && warns > 0) ? 1 : 0;
206
+ }
207
+
208
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) process.exitCode = main();
@@ -0,0 +1,321 @@
1
+ import assert from 'node:assert/strict';
2
+ import crypto from 'node:crypto';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import test from 'node:test';
7
+ import {fileURLToPath} from 'node:url';
8
+ import {spawnSync} from 'node:child_process';
9
+ import {CHECK_CALL_LIMIT_MS, MAX_SCOPE_PATHS} from './cm-start-check.mjs';
10
+
11
+ const here = path.dirname(fileURLToPath(import.meta.url));
12
+ const script = path.join(here, 'cm-start-check.mjs');
13
+ const gitEnv = {...process.env, GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t'};
14
+
15
+ function git(cwd, ...args) {
16
+ const result = spawnSync('git', ['-c', 'commit.gpgsign=false', ...args], {cwd, env: gitEnv, encoding: 'utf8'});
17
+ assert.equal(result.status, 0, result.stderr);
18
+ }
19
+
20
+ // A code root (optionally a git repo with every file committed) plus a plan directory beside it.
21
+ function project(t, {scope = ['src/a.js'], files = {'src/a.js': 'a\n', 'src/b.js': 'b\n'}, repo = true, checks, plan = {}} = {}) {
22
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cm-start-check-'));
23
+ t.after(() => fs.rmSync(dir, {recursive: true, force: true}));
24
+ const root = path.join(dir, 'code');
25
+ for (const [name, text] of Object.entries(files)) {
26
+ fs.mkdirSync(path.dirname(path.join(root, name)), {recursive: true});
27
+ fs.writeFileSync(path.join(root, name), text);
28
+ }
29
+ fs.mkdirSync(root, {recursive: true});
30
+ if (repo) { git(root, 'init', '-q'); git(root, 'add', '-A'); git(root, 'commit', '-q', '-m', 'base'); }
31
+ const planDir = path.join(dir, 'plan');
32
+ fs.mkdirSync(planDir);
33
+ fs.writeFileSync(path.join(planDir, 'run.json'), JSON.stringify({version: 1, codeProject: root, scope}));
34
+ const planFile = path.join(planDir, 'PLAN.json');
35
+ fs.writeFileSync(planFile, JSON.stringify({config: 'run.json', checks, ...plan}));
36
+ return {dir, root, planDir, planFile};
37
+ }
38
+
39
+ const run = (...args) => {
40
+ const result = spawnSync(process.execPath, [script, ...args], {encoding: 'utf8'});
41
+ return {status: result.status, out: result.stdout, err: result.stderr};
42
+ };
43
+ const check = (p, ...extra) => {
44
+ const result = run('--plan', p.planFile, '--json', ...extra);
45
+ return {...result, report: result.out ? JSON.parse(result.out) : null};
46
+ };
47
+ const checkWithEnv = (p, env) => {
48
+ const result = spawnSync(process.execPath, [script, '--plan', p.planFile, '--json'], {encoding: 'utf8', env});
49
+ return {status: result.status, out: result.stdout, err: result.stderr, report: result.stdout ? JSON.parse(result.stdout) : null};
50
+ };
51
+ const codes = report => report.findings.map(item => item.code);
52
+ const cmd = (id, command, timeoutMs) => ({id, command, ...(timeoutMs === undefined ? {} : {timeoutMs})});
53
+ const xcode = (id, ...extra) => cmd(id, ['xcodebuild', 'test', '-scheme', 'App', '-destination', 'id=U1', ...extra]);
54
+
55
+ function snapshot(dir) {
56
+ const rows = [];
57
+ const walk = current => {
58
+ for (const entry of fs.readdirSync(current, {withFileTypes: true}).sort((a, b) => a.name.localeCompare(b.name))) {
59
+ const full = path.join(current, entry.name);
60
+ if (entry.isDirectory()) { rows.push(`d ${path.relative(dir, full)}`); walk(full); continue; }
61
+ const stat = fs.statSync(full);
62
+ rows.push(`f ${path.relative(dir, full)} ${stat.mtimeMs} ${crypto.createHash('sha256').update(fs.readFileSync(full)).digest('hex')}`);
63
+ }
64
+ };
65
+ walk(dir);
66
+ return rows.join('\n');
67
+ }
68
+
69
+ test('a clean scope with distinct checks passes with no finding', t => {
70
+ const p = project(t, {checks: [cmd('unit', ['node', '--test']), cmd('lint', ['node', '--check', 'src/a.js'])]});
71
+ const r = check(p);
72
+ assert.equal(r.status, 0);
73
+ assert.deepEqual(r.report, {errors: 0, warns: 0, skipped: 0, findings: []});
74
+ const text = run('--plan', p.planFile);
75
+ assert.equal(text.status, 0);
76
+ assert.match(text.out, /体检通过/);
77
+ });
78
+
79
+ test('protected scope paths are errors and exit 1 (the create refusal known in advance)', t => {
80
+ const p = project(t, {scope: ['AGENTS.md', 'src/a.js', 'docs/.cm-run.json', '.reviews/x.md', 'specs/tasks.md']});
81
+ const r = check(p);
82
+ assert.equal(r.status, 1);
83
+ const errors = r.report.findings.filter(item => item.code === 'protected_scope').map(item => item.path).sort();
84
+ assert.deepEqual(errors, ['.reviews/x.md', 'AGENTS.md', 'docs/.cm-run.json', 'specs/tasks.md']);
85
+ assert.equal(r.report.findings.every(item => item.level === 'error' && /[一-鿿]/.test(item.message)), true);
86
+ });
87
+
88
+ test('identical checks warn; sameExecutionAs aliases are neither duplicates nor extra time', t => {
89
+ const dup = project(t, {plan: {checkTimeoutMs: 300000}, checks: [cmd('a', ['npm', 'test']), cmd('b', ['npm', 'test']), cmd('c', ['npm', 'run', 'lint'])]});
90
+ const r = check(dup);
91
+ assert.equal(r.status, 0);
92
+ assert.deepEqual(r.report.findings.map(item => [item.code, item.ids]), [['duplicate_check', ['a', 'b']]]);
93
+ const alias = project(t, {checks: [cmd('a', ['npm', 'test'], 900000), {...cmd('b', ['npm', 'test'], 900000), sameExecutionAs: 'a'}]});
94
+ assert.deepEqual(check(alias).report.findings, []);
95
+ });
96
+
97
+ test('two xcodebuild test checks on one scheme and destination warn unless one is narrowed or differs', t => {
98
+ const overlap = check(project(t, {checks: [xcode('unit'), xcode('ui', '-resultBundlePath', 'x')]}));
99
+ assert.deepEqual(overlap.report.findings.map(item => [item.code, item.ids]), [['overlapping_full_test', ['unit', 'ui']]]);
100
+ assert.equal(overlap.status, 0);
101
+ assert.deepEqual(check(project(t, {checks: [xcode('unit'), xcode('ui', '-only-testing:AppUITests')]})).report.findings, []);
102
+ const other = cmd('ui', ['xcodebuild', 'test', '-scheme', 'Other', '-destination', 'id=U1']);
103
+ assert.deepEqual(check(project(t, {checks: [xcode('unit'), other]})).report.findings, []);
104
+ const build = cmd('build', ['xcodebuild', 'build', '-scheme', 'App', '-destination', 'id=U1']);
105
+ assert.deepEqual(check(project(t, {checks: [xcode('unit'), build]})).report.findings, []);
106
+ });
107
+
108
+ test('the summed check timeouts warn only above the 30 minute call limit', t => {
109
+ assert.equal(CHECK_CALL_LIMIT_MS, 1800000);
110
+ const exact = project(t, {checks: [cmd('a', ['a']), cmd('b', ['b'])]});
111
+ assert.deepEqual(check(exact).report.findings, []);
112
+ const over = project(t, {checks: [cmd('a', ['a']), cmd('b', ['b']), cmd('c', ['c'])]});
113
+ const r = check(over);
114
+ assert.deepEqual(r.report.findings.map(item => [item.code, item.totalMs, item.limitMs]), [['check_budget_over_call_limit', 2700000, 1800000]]);
115
+ const custom = project(t, {plan: {checkTimeoutMs: 600000}, checks: [cmd('a', ['a']), cmd('b', ['b']), cmd('c', ['c'])]});
116
+ assert.deepEqual(check(custom).report.findings, []);
117
+ const raised = project(t, {plan: {checkTimeoutMs: 1200000}, checks: [cmd('a', ['a']), cmd('b', ['b'])]});
118
+ assert.deepEqual(codes(check(raised).report), ['check_budget_over_call_limit']);
119
+ const tight = project(t, {checks: [cmd('a', ['a'], 1200000), cmd('b', ['b'], 1200000)]});
120
+ assert.deepEqual(codes(check(tight).report), ['check_budget_over_call_limit']);
121
+ });
122
+
123
+ test('the call limit constant still matches the host source', () => {
124
+ const source = fs.readFileSync(path.join(here, '..', 'runtime/js/cm-ai/host-conversation-execution.mjs'), 'utf8');
125
+ assert.match(source, /const outerTimeoutMs=provider\?protection\.timeoutMs:1800000;/);
126
+ });
127
+
128
+ test('dirty scope files warn (tracked change and new file), files outside scope do not, --strict turns warns into exit 1', t => {
129
+ const p = project(t, {scope: ['src/a.js', 'src/new.js'], checks: [cmd('unit', ['node', '--test'])]});
130
+ fs.writeFileSync(path.join(p.root, 'src/b.js'), 'outside\n');
131
+ assert.deepEqual(check(p).report.findings, []);
132
+ fs.writeFileSync(path.join(p.root, 'src/a.js'), 'changed\n');
133
+ fs.writeFileSync(path.join(p.root, 'src/new.js'), 'new\n');
134
+ const r = check(p);
135
+ assert.equal(r.status, 0);
136
+ assert.equal(r.report.warns, 1);
137
+ const [finding] = r.report.findings;
138
+ assert.equal(finding.code, 'scope_dirty');
139
+ assert.deepEqual(finding.paths.sort(), ['src/a.js', 'src/new.js']);
140
+ assert.equal(check(p, '--strict').status, 1);
141
+ });
142
+
143
+ test('a deleted and a renamed scope file are reported as dirty too', t => {
144
+ const p = project(t, {scope: ['src/a.js', 'src/b.js'], checks: [cmd('unit', ['x'])]});
145
+ fs.rmSync(path.join(p.root, 'src/a.js'));
146
+ git(p.root, 'mv', 'src/b.js', 'src/c.js');
147
+ const finding = check(p).report.findings[0];
148
+ assert.equal(finding.code, 'scope_dirty');
149
+ assert.deepEqual(finding.paths.sort(), ['src/a.js', 'src/b.js']);
150
+ });
151
+
152
+ test('a code root that is not a git repository is reported as info and exits 0', t => {
153
+ const p = project(t, {repo: false, checks: [cmd('unit', ['x'])]});
154
+ const r = check(p);
155
+ assert.equal(r.status, 0);
156
+ assert.deepEqual(r.report.findings.map(item => [item.level, item.code]), [['info', 'not_git']]);
157
+ assert.equal(r.report.skipped, 1);
158
+ const text = run('--plan', p.planFile);
159
+ assert.equal(text.status, 0);
160
+ assert.match(text.out, /被跳过/);
161
+ assert.doesNotMatch(text.out, /体检通过/);
162
+ });
163
+
164
+ test('a .git that git refuses is a warn (--strict fails), unlike a project without any .git', t => {
165
+ const p = project(t, {repo: false, checks: [cmd('unit', ['x'])]});
166
+ fs.mkdirSync(path.join(p.root, '.git'));
167
+ const r = check(p);
168
+ assert.equal(r.status, 0);
169
+ assert.deepEqual(r.report.findings.map(item => [item.level, item.code]), [['warn', 'git_refused']]);
170
+ assert.equal(r.report.skipped, 0);
171
+ assert.equal(check(p, '--strict').status, 1);
172
+ });
173
+
174
+ test('a refused .git in a parent directory of the code root is a warn too', t => {
175
+ const p = project(t, {repo: false, checks: [cmd('unit', ['x'])]});
176
+ fs.mkdirSync(path.join(p.root, '.git'));
177
+ const nested = path.join(p.root, 'app');
178
+ fs.mkdirSync(nested);
179
+ fs.writeFileSync(path.join(p.planDir, 'run.json'), JSON.stringify({version: 1, codeProject: nested, scope: ['src/a.js']}));
180
+ assert.deepEqual(check(p).report.findings.map(item => [item.level, item.code]), [['warn', 'git_refused']]);
181
+ });
182
+
183
+ test('the scope path cap matches the run definition and is enforced at the boundary', t => {
184
+ assert.equal(MAX_SCOPE_PATHS, 256);
185
+ const source = fs.readFileSync(path.join(here, 'cm-ai-run.mjs'), 'utf8');
186
+ assert.match(source, /value\[key\]\.length>256/);
187
+ const scopeOf = count => Array.from({length: count}, (_, i) => `src/f${i}.js`);
188
+ const ok = check(project(t, {scope: scopeOf(256), checks: [cmd('unit', ['x'])]}));
189
+ assert.equal(ok.status, 0);
190
+ const over = run('--plan', project(t, {scope: scopeOf(257), checks: [cmd('unit', ['x'])]}).planFile, '--json');
191
+ assert.equal(over.status, 2);
192
+ assert.equal(over.out, '');
193
+ assert.match(over.err, /257 条路径,超过创建运行允许的 256 条/);
194
+ const mixed = run('--plan', project(t, {scope: ['AGENTS.md', ...scopeOf(256)], checks: [cmd('unit', ['x'])]}).planFile, '--json');
195
+ assert.equal(mixed.status, 2);
196
+ });
197
+
198
+ test('git that cannot run is a warn, not a pass: --strict then fails (no git on PATH)', t => {
199
+ const p = project(t, {checks: [cmd('unit', ['x'])]});
200
+ const r = checkWithEnv(p, {PATH: ''});
201
+ assert.equal(r.status, 0);
202
+ assert.deepEqual(r.report.findings.map(item => [item.level, item.code]), [['warn', 'git_unavailable']]);
203
+ assert.match(r.report.findings[0].message, /没能核对/);
204
+ const strict = spawnSync(process.execPath, [script, '--plan', p.planFile, '--json', '--strict'], {encoding: 'utf8', env: {PATH: ''}});
205
+ assert.equal(strict.status, 1);
206
+ });
207
+
208
+ test('unreadable or unsupported input exits 2 with a Chinese reason and no report', t => {
209
+ const good = project(t, {checks: [cmd('unit', ['x'])]});
210
+ const missing = run('--plan', path.join(good.dir, 'nope.json'));
211
+ assert.equal(missing.status, 2);
212
+ assert.match(missing.err, /读不了PLAN/);
213
+ const badJson = path.join(good.planDir, 'bad.json');
214
+ fs.writeFileSync(badJson, '{');
215
+ assert.match(run('--plan', badJson).err, /不是合法 JSON/);
216
+ const noConfig = path.join(good.planDir, 'noconfig.json');
217
+ fs.writeFileSync(noConfig, JSON.stringify({checks: []}));
218
+ assert.match(run('--plan', noConfig).err, /缺少字段 config/);
219
+ fs.writeFileSync(path.join(good.planDir, 'batch.json'), JSON.stringify({version: 1, workflows: []}));
220
+ fs.writeFileSync(path.join(good.planDir, 'batchplan.json'), JSON.stringify({config: 'batch.json'}));
221
+ assert.match(run('--plan', path.join(good.planDir, 'batchplan.json')).err, /没有 scope 数组/);
222
+ const relative = project(t, {checks: [cmd('unit', ['x'])]});
223
+ fs.writeFileSync(path.join(relative.planDir, 'run.json'), JSON.stringify({version: 1, codeProject: 'code', scope: ['a']}));
224
+ assert.match(run('--plan', relative.planFile).err, /codeProject 必须是绝对路径/);
225
+ const badTimeout = project(t, {checks: [cmd('unit', ['x'], 0)]});
226
+ const r = run('--plan', badTimeout.planFile, '--json');
227
+ assert.equal(r.status, 2);
228
+ assert.equal(r.out, '');
229
+ assert.match(r.err, /timeoutMs/);
230
+ assert.equal(run().status, 2);
231
+ assert.equal(run('--plan').status, 2);
232
+ assert.equal(run('--help').status, 0);
233
+ });
234
+
235
+ test('the check never writes: every file, mtime and the git index are unchanged, dirty tree included', t => {
236
+ const p = project(t, {scope: ['src/a.js', 'AGENTS.md'], checks: [xcode('unit'), xcode('ui'), cmd('d', ['x']), cmd('e', ['x'])]});
237
+ fs.writeFileSync(path.join(p.root, 'src/a.js'), 'dirty\n');
238
+ fs.writeFileSync(path.join(p.root, 'src/untracked.js'), 'u\n');
239
+ const before = snapshot(p.dir);
240
+ const r = check(p);
241
+ assert.equal(r.status, 1);
242
+ assert.ok(r.report.findings.length >= 3);
243
+ assert.equal(snapshot(p.dir), before);
244
+ });
245
+
246
+ test('modes the check does not model exit 2 instead of a verdict (protected, provider, bootstrap)', t => {
247
+ const flags = ['--protected-config', '--protected-conversation-config', '--allow-provider-development-attempt', '--bootstrap-config', '--allow-bootstrap-write'];
248
+ for (const flag of flags) {
249
+ // A rule file in scope is legal for bootstrap; a 45 minute check is fine for a provider run.
250
+ const p = project(t, {scope: ['AGENTS.md'], checks: [cmd('ui', ['x'], 2700000)],
251
+ plan: {permissions: ['--allow-development', flag, ...(flag.endsWith('-write') ? [] : ['x.json'])]}});
252
+ const r = run('--plan', p.planFile, '--json');
253
+ assert.equal(r.status, 2, flag);
254
+ assert.equal(r.out, '', flag);
255
+ assert.match(r.err, new RegExp(`${flag}.*不给出结论`), flag);
256
+ }
257
+ const plain = project(t, {scope: ['src/a.js'], checks: [cmd('unit', ['x'])], plan: {permissions: ['--allow-development', '--review-config', 'review.json']}});
258
+ assert.equal(check(plain).status, 0);
259
+ const bad = project(t, {checks: [cmd('unit', ['x'])], plan: {permissions: 'nope'}});
260
+ assert.match(run('--plan', bad.planFile).err, /permissions 必须是字符串数组/);
261
+ });
262
+
263
+ test('a scope the runtime refuses at create is an input error, not a pass', t => {
264
+ const bads = [[], ['src/a.js', 'src/a.js'], ['src/../a.js'], ['/abs.js'], ['src\\a.js'], ['src:a.js'], ['./a.js'], ['']];
265
+ for (const scope of bads) {
266
+ const p = project(t, {scope, checks: [cmd('unit', ['x'])]});
267
+ const r = run('--plan', p.planFile, '--json');
268
+ assert.equal(r.status, 2, JSON.stringify(scope));
269
+ assert.equal(r.out, '', JSON.stringify(scope));
270
+ assert.match(r.err, /scope 不合法/, JSON.stringify(scope));
271
+ }
272
+ // A protected path next to a good one is still a finding (exit 1), and so is a protected-only scope.
273
+ assert.equal(check(project(t, {scope: ['AGENTS.md', 'src/a.js'], checks: [cmd('unit', ['x'])]})).status, 1);
274
+ assert.equal(check(project(t, {scope: ['AGENTS.md'], checks: [cmd('unit', ['x'])]})).status, 1);
275
+ // A bad path next to a protected one is still an input error.
276
+ assert.equal(run('--plan', project(t, {scope: ['AGENTS.md', '../x.js'], checks: [cmd('unit', ['x'])]}).planFile).status, 2);
277
+ });
278
+
279
+ test('repository config cannot run programs: fsmonitor, clean, process and required filters and a project-local git stay unexecuted', t => {
280
+ const cases = {
281
+ fsmonitor: (p, mark) => {
282
+ const hook = path.join(p.dir, 'fsmonitor.sh');
283
+ fs.writeFileSync(hook, `#!/bin/sh\ntouch '${mark}'\nprintf '\\0'\n`, {mode: 0o755});
284
+ git(p.root, 'config', 'core.fsmonitor', hook);
285
+ },
286
+ clean: (p, mark) => {
287
+ const filter = path.join(p.dir, 'clean.sh');
288
+ fs.writeFileSync(filter, `#!/bin/sh\ntouch '${mark}'\ncat\n`, {mode: 0o755});
289
+ git(p.root, 'config', 'filter.probe.clean', filter);
290
+ git(p.root, 'config', 'filter.probe.required', 'true');
291
+ },
292
+ process: (p, mark) => {
293
+ const filter = path.join(p.dir, 'process.sh');
294
+ fs.writeFileSync(filter, `#!/bin/sh\ntouch '${mark}'\nexit 1\n`, {mode: 0o755});
295
+ git(p.root, 'config', 'filter.probe.process', filter);
296
+ git(p.root, 'config', 'filter.probe.required', 'true');
297
+ }};
298
+ for (const [name, configure] of Object.entries(cases)) {
299
+ const p = project(t, {checks: [cmd('unit', ['x'])]});
300
+ const mark = path.join(p.dir, `ran-${name}`);
301
+ configure(p, mark);
302
+ fs.writeFileSync(path.join(p.root, '.gitattributes'), 'src/a.js filter=probe\n');
303
+ // Same size as the committed 'a\n': git then has to read the content (running the filter) to tell it changed.
304
+ fs.writeFileSync(path.join(p.root, 'src/a.js'), 'z\n');
305
+ // Control: a plain git status in this repository does run the configured program.
306
+ spawnSync('git', ['status', '--porcelain'], {cwd: p.root, env: gitEnv});
307
+ assert.equal(fs.existsSync(mark), true, `control ${name}: the fixture must make plain git run the program`);
308
+ fs.rmSync(mark);
309
+ const r = check(p);
310
+ assert.equal(fs.existsSync(mark), false, `${name} program ran during the check`);
311
+ assert.deepEqual(r.report.findings.map(item => item.code), ['scope_dirty'], name);
312
+ }
313
+ const p = project(t, {checks: [cmd('unit', ['x'])]});
314
+ const bin = path.join(p.root, 'bin');
315
+ fs.mkdirSync(bin);
316
+ const mark = path.join(p.dir, 'ran-local-git');
317
+ fs.writeFileSync(path.join(bin, 'git'), `#!/bin/sh\ntouch '${mark}'\nexit 1\n`, {mode: 0o755});
318
+ const r = checkWithEnv(p, {...process.env, PATH: `${bin}${path.delimiter}${process.env.PATH}`});
319
+ assert.equal(fs.existsSync(mark), false);
320
+ assert.equal(r.status, 0);
321
+ });