@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,323 @@
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, affected old UI tests
4
+ // left out of the checks, dirty scope files.
5
+ // It never writes a file, never starts a host and never runs a check command.
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import {pathToFileURL} from 'node:url';
9
+ import {protectedScopePaths, validateDeveloperScope} from '../runtime/js/cm-ai/developer-adapter.mjs';
10
+ import {planCheckTimeout} from '../runtime/js/cm-ai/drive-core.mjs';
11
+ import {git as safeGit} from '../runtime/js/cm-security/scan.mjs';
12
+
13
+ // The whole check step of a current-session run is one host call with this deadline
14
+ // (runtime/js/cm-ai/host-conversation-execution.mjs, outerTimeoutMs). The test
15
+ // file guards that the literal is still there.
16
+ export const CHECK_CALL_LIMIT_MS = 1800000;
17
+ const MAX_LISTED = 20;
18
+ // validateRunDefinition (scripts/cm-ai-run.mjs) refuses more than this many scope paths.
19
+ // The test file guards that the literal is still there.
20
+ export const MAX_SCOPE_PATHS = 256;
21
+
22
+ class InputError extends Error {}
23
+
24
+ const usage = '用法: cm-start-check.mjs --plan PLAN.json [--json] [--strict]\n'
25
+ + '只读体检,开工前跑一次。只支持普通单任务、当前会话模式的 PLAN;\n'
26
+ + 'PLAN.permissions 含受保护模式、provider 开发或 bootstrap 参数时退出 2,不给出结论。\n'
27
+ + ' 1. scope 是否含受保护路径(AGENTS.md、tasks.md、.reviews、.cm-* 等)——error;\n'
28
+ + ' scope 为空、重复、绝对路径、含 ../反斜杠/冒号等创建必拒的写法——输入不合法,退出 2\n'
29
+ + ' 2. PLAN.checks 是否重复、是否重复跑全量测试、各检查超时之和是否超过整步 30 分钟——warn\n'
30
+ + ' scope 改到代码根 TESTING.md「## 牵连测试」表里的路径,却没跑表里对应的旧界面测试——warn;\n'
31
+ + ' 只跑了部分界面测试(-only-testing)而项目没有这张表——info(没能核对)\n'
32
+ + ' 3. scope 内文件在代码根是否已有未提交改动——warn(Git 不可用时是 warn,不是 Git 仓库时是 info)\n'
33
+ + '退出码:0 无 error(warn 只提示);1 有 error,或加 --strict 时有 warn;2 输入读不了或不支持。\n';
34
+
35
+ // Modes this check does not model: another check budget (provider), another scope rule
36
+ // (bootstrap may name protected rule files) or another check source (protected configs).
37
+ const UNSUPPORTED_MODE_FLAGS = new Map([
38
+ ['--protected-config', '受保护模式'], ['--protected-conversation-config', '受保护的当前会话模式'],
39
+ ['--allow-provider-development-attempt', 'provider 开发'],
40
+ ['--bootstrap-config', 'bootstrap'], ['--allow-bootstrap-write', 'bootstrap']]);
41
+
42
+ function readJson(file, label) {
43
+ let raw;
44
+ try { raw = fs.readFileSync(file, 'utf8'); }
45
+ catch (error) { throw new InputError(`读不了${label}: ${file}(${error.code ?? error.message})`); }
46
+ try { return JSON.parse(raw); }
47
+ catch { throw new InputError(`${label}不是合法 JSON: ${file}`); }
48
+ }
49
+
50
+ export function loadStartInputs(planFile) {
51
+ const planPath = path.resolve(planFile), base = path.dirname(planPath);
52
+ const plan = readJson(planPath, 'PLAN');
53
+ if (plan === null || typeof plan !== 'object' || Array.isArray(plan)) throw new InputError('PLAN 必须是 JSON 对象');
54
+ if (typeof plan.config !== 'string' || plan.config === '') throw new InputError('PLAN 缺少字段 config(已批准的运行定义路径)');
55
+ if (plan.permissions !== undefined && (!Array.isArray(plan.permissions) || !plan.permissions.every(item => typeof item === 'string')))
56
+ throw new InputError('PLAN.permissions 必须是字符串数组');
57
+ for (const item of plan.permissions ?? []) {
58
+ if (UNSUPPORTED_MODE_FLAGS.has(item))
59
+ throw new InputError(`PLAN.permissions 含 ${item}(${UNSUPPORTED_MODE_FLAGS.get(item)}):本体检只支持普通单任务、当前会话模式,不给出结论;请按 js-host.md 启动前第 8 项手工核对`);
60
+ }
61
+ const definition = readJson(path.resolve(base, plan.config), '运行定义');
62
+ if (definition === null || typeof definition !== 'object' || !Array.isArray(definition.scope)
63
+ || !definition.scope.every(item => typeof item === 'string'))
64
+ throw new InputError('运行定义没有 scope 数组:本体检只支持单任务运行定义,批次请逐个任务检查');
65
+ if (typeof definition.codeProject !== 'string' || !path.isAbsolute(definition.codeProject))
66
+ throw new InputError('运行定义的 codeProject 必须是绝对路径');
67
+ return {plan, definition};
68
+ }
69
+
70
+ function checkProtectedScope(scope) {
71
+ if (scope.length > MAX_SCOPE_PATHS)
72
+ throw new InputError(`scope 有 ${scope.length} 条路径,超过创建运行允许的 ${MAX_SCOPE_PATHS} 条;创建会被拒绝,先拆任务或收窄 scope`);
73
+ const protectedPaths = protectedScopePaths(scope);
74
+ const rest = scope.filter(item => !protectedPaths.includes(item));
75
+ if (rest.length > 0 || protectedPaths.length === 0) {
76
+ // Shape errors the runtime refuses at create (empty, duplicate, absolute, .., backslash, colon):
77
+ // not a finding, because "passed" would be wrong for an input that cannot start.
78
+ try { validateDeveloperScope(rest); }
79
+ catch { throw new InputError('scope 不合法:为空、有重复项,或含绝对路径、..、反斜杠、冒号等写法;创建运行会被拒绝,先改 scope'); }
80
+ }
81
+ return protectedPaths.map(item => ({level: 'error', code: 'protected_scope', path: item,
82
+ message: `scope 含受保护路径 ${item}:创建运行会被 protected_scope 拒绝。先走人工通道同步该文件,再把它从 scope 里去掉`}));
83
+ }
84
+
85
+ const isXcodebuild = tokens => tokens.some(token => path.basename(token) === 'xcodebuild');
86
+ // xcodebuild options that take no value (xcodebuild -help, Xcode 26). A bare word counts as an
87
+ // action only right after xcodebuild, another bare word (an action or an option's value), an
88
+ // -option:value, or one of these. After any other option it may be that option's value
89
+ // (`-resultBundlePath test`), so it is not an action: an unknown flag then makes the coverage
90
+ // check warn instead of passing, never the other way round.
91
+ const XCODE_FLAGS = new Set(['-usage', '-help', '-verbose', '-license', '-checkFirstLaunchStatus', '-runFirstLaunch',
92
+ '-checkForNewerComponents', '-downloadAllPlatforms', '-prepareDeviceSupport', '-alltargets', '-parallelizeTargets', '-quiet',
93
+ '-hideShellScriptEnvironment', '-showsdks', '-showdestinations', '-showTestPlans', '-showBuildSettings', '-showBuildSettingsForIndex',
94
+ '-list', '-version', '-exportArchive', '-exportNotarizedApp', '-skipUnavailableActions', '-exportLocalizations', '-importLocalizations',
95
+ '-retry-tests-on-failure', '-run-tests-until-failure', '-disable-concurrent-destination-testing', '-enumerate-tests',
96
+ '-resolvePackageDependencies', '-disableAutomaticPackageResolution', '-onlyUsePackageVersionsFromResolvedFile', '-skipPackageUpdates',
97
+ '-disablePackageRepositoryCache', '-skipPackagePluginValidation', '-skipMacroValidation', '-skipPackageSignatureValidation', '-json',
98
+ '-allowProvisioningUpdates', '-allowProvisioningDeviceRegistration', '-showBuildTimingSummary']);
99
+ function xcodeActions(tokens) {
100
+ const start = tokens.findIndex(token => path.basename(token) === 'xcodebuild');
101
+ if (start === -1) return [];
102
+ return tokens.slice(start + 1).filter((token, index, rest) => {
103
+ if (token.startsWith('-')) return false;
104
+ const before = index === 0 ? null : rest[index - 1];
105
+ return before === null || !before.startsWith('-') || before.includes(':') || XCODE_FLAGS.has(before);
106
+ });
107
+ }
108
+ // Modes that list, show, export or set up instead of running the scheme action: a `test` beside them
109
+ // selects what to show (xcodebuild -showBuildSettings test) and runs nothing.
110
+ const XCODE_NON_RUNNING = new Set(['-usage', '-help', '-license', '-checkFirstLaunchStatus', '-runFirstLaunch', '-downloadAllPlatforms',
111
+ '-prepareDeviceSupport', '-downloadPlatform', '-importPlatform', '-downloadComponent', '-importComponent', '-deleteComponent',
112
+ '-showComponent', '-showsdks', '-showdestinations', '-showTestPlans', '-showBuildSettings', '-showBuildSettingsForIndex', '-list',
113
+ '-find-executable', '-find-library', '-version', '-exportArchive', '-exportNotarizedApp', '-exportLocalizations', '-importLocalizations',
114
+ '-enumerate-tests', '-resolvePackageDependencies', '-create-xcframework']);
115
+ // Whether a direct xcodebuild actually runs tests; shared by the overlap and the coverage checks.
116
+ const isTestAction = tokens => !tokens.some(token => XCODE_NON_RUNNING.has(token))
117
+ && xcodeActions(tokens).some(action => action === 'test' || action === 'test-without-building');
118
+ const optionValue = (tokens, name) => {
119
+ const at = tokens.indexOf(name);
120
+ return at === -1 ? '' : tokens[at + 1] ?? '';
121
+ };
122
+
123
+ function checkChecks(plan) {
124
+ const findings = [];
125
+ if (!Array.isArray(plan.checks)) return findings;
126
+ const items = plan.checks.filter(item => item !== null && typeof item === 'object' && !Array.isArray(item));
127
+ let timeouts;
128
+ try { timeouts = items.map(item => planCheckTimeout(plan, item)); }
129
+ catch (error) { throw new InputError(error.message); }
130
+ // sameExecutionAs entries reuse the previous execution: they neither repeat it nor add time.
131
+ const own = items.map((item, index) => ({item, timeoutMs: timeouts[index]}))
132
+ .filter(entry => !Object.hasOwn(entry.item, 'sameExecutionAs'));
133
+ const byCommand = new Map();
134
+ for (const entry of own) {
135
+ const key = JSON.stringify(entry.item.command ?? null);
136
+ byCommand.set(key, [...(byCommand.get(key) ?? []), entry]);
137
+ }
138
+ for (const group of byCommand.values()) {
139
+ if (group.length < 2) continue;
140
+ findings.push({level: 'warn', code: 'duplicate_check', ids: group.map(entry => entry.item.id),
141
+ message: `检查 ${group.map(entry => entry.item.id).join('、')} 的命令完全相同,会白跑 ${group.length - 1} 遍。去掉重复项,或给后面的加 sameExecutionAs`});
142
+ }
143
+ const overlap = new Map();
144
+ for (const group of byCommand.values()) {
145
+ const tokens = group[0].item.command;
146
+ if (!Array.isArray(tokens) || !tokens.every(token => typeof token === 'string')) continue;
147
+ if (!isXcodebuild(tokens) || !isTestAction(tokens) || tokens.some(token => token.startsWith('-only-testing'))) continue;
148
+ const key = ['-workspace', '-project', '-scheme', '-destination', '-testPlan'].map(name => optionValue(tokens, name)).join('\u0000');
149
+ overlap.set(key, [...(overlap.get(key) ?? []), group[0]]);
150
+ }
151
+ for (const group of overlap.values()) {
152
+ if (group.length < 2) continue;
153
+ findings.push({level: 'warn', code: 'overlapping_full_test', ids: group.map(entry => entry.item.id),
154
+ message: `检查 ${group.map(entry => entry.item.id).join('、')} 都是同一 scheme/目的地、没有 -only-testing 的 xcodebuild test,很可能各自跑了一遍全量。保留一个,或用 -only-testing 分开`});
155
+ }
156
+ const totalMs = own.reduce((sum, entry) => sum + entry.timeoutMs, 0);
157
+ if (totalMs > CHECK_CALL_LIMIT_MS)
158
+ findings.push({level: 'warn', code: 'check_budget_over_call_limit', totalMs, limitMs: CHECK_CALL_LIMIT_MS,
159
+ message: `各检查超时之和 ${Math.round(totalMs / 60000)} 分钟,超过检查整步的 ${CHECK_CALL_LIMIT_MS / 60000} 分钟期限;这是最坏情况,实际可能更短。`
160
+ + '按分层缩减(单元测试全跑,界面测试只跑本任务新写的和牵连的,其余留到功能末尾回归任务),或拆成多次运行'});
161
+ return findings;
162
+ }
163
+
164
+ // The project's own record of which old UI tests a change reaches: a "## 牵连测试" table in
165
+ // TESTING.md (code root first, then docs/). After the header row, each row is
166
+ // | changed paths (a trailing / is a directory) | test identifiers as the check command names them |.
167
+ const AFFECTED_HEADING = /^##\s+牵连测试\s*$/;
168
+ const TESTING_FILES = ['TESTING.md', path.join('docs', 'TESTING.md')];
169
+ // Backticks are optional and may be mixed with plain items in one cell; a backticked item is
170
+ // kept whole (it may hold spaces), the plain rest is split on 、 , ; and spaces.
171
+ const cellItems = cell => [...[...cell.matchAll(/`([^`]+)`/g)].map(match => match[1].trim()),
172
+ ...cell.replace(/`[^`]*`/g, ' ').split(/[、,,;;\s]+/)].filter(Boolean);
173
+
174
+ export function readAffectedMap(root) {
175
+ for (const name of TESTING_FILES) {
176
+ let text;
177
+ try { text = fs.readFileSync(path.join(root, name), 'utf8'); } catch { continue; }
178
+ const lines = text.split(/\r?\n/);
179
+ const start = lines.findIndex(line => AFFECTED_HEADING.test(line.trim()));
180
+ if (start === -1) continue;
181
+ const rows = [];
182
+ let header = true;
183
+ for (const line of lines.slice(start + 1)) {
184
+ if (/^#{1,2}\s/.test(line)) break;
185
+ const cells = line.trim().match(/^\|(.*)\|$/)?.[1].split('|').map(cell => cell.trim());
186
+ if (!cells || cells.length < 2) continue;
187
+ if (cells.every(cell => /^:?-+:?$/.test(cell))) { header = false; continue; }
188
+ if (header) continue;
189
+ const paths = cellItems(cells[0]).map(item => item.replace(/^\.\//, '')), tests = cellItems(cells[1]);
190
+ if (paths.length > 0 && tests.length > 0) rows.push({paths, tests});
191
+ }
192
+ // A heading with no usable row is not a table: report it like a missing one, not as "nothing affected".
193
+ if (rows.length > 0) return {file: name, rows};
194
+ }
195
+ return null;
196
+ }
197
+
198
+ const ONLY = '-only-testing:', SKIP = '-skip-testing:';
199
+ const within = (id, target) => id === target || id.startsWith(`${target}/`);
200
+ // Whether one check command runs all of test `id`. A direct xcodebuild counts only with a test
201
+ // action and only through its selection: unnarrowed, or an -only-testing naming `id` or an
202
+ // ancestor. Any other command (wrapper script, other runner) counts when an argument contains
203
+ // `id`; the start check cannot see inside it. An -skip-testing on `id`, an ancestor or a part
204
+ // of it (one method of the class) means it does not run all of it.
205
+ function runsTest(tokens, id) {
206
+ if (tokens.some(token => token.startsWith(SKIP)
207
+ && (within(id, token.slice(SKIP.length)) || within(token.slice(SKIP.length), id)))) return false;
208
+ if (isXcodebuild(tokens)) {
209
+ if (!isTestAction(tokens)) return false;
210
+ const only = tokens.filter(token => token.startsWith(ONLY)).map(token => token.slice(ONLY.length));
211
+ return !tokens.some(token => token.startsWith('-only-testing')) || only.some(target => within(id, target));
212
+ }
213
+ return tokens.some(token => !token.startsWith('-skip-testing') && token.includes(id));
214
+ }
215
+
216
+ function checkAffectedTests(plan, definition) {
217
+ const commands = (Array.isArray(plan.checks) ? plan.checks : [])
218
+ .map(item => item?.command).filter(tokens => Array.isArray(tokens) && tokens.every(token => typeof token === 'string'));
219
+ const map = fs.existsSync(definition.codeProject) ? readAffectedMap(definition.codeProject) : null;
220
+ if (map === null) {
221
+ if (!commands.some(tokens => tokens.some(token => token.startsWith('-only-testing')))) return [];
222
+ return [{level: 'info', code: 'affected_map_missing',
223
+ message: '只跑了部分界面测试(-only-testing),但代码根 TESTING.md/docs/TESTING.md 没有「## 牵连测试」表,'
224
+ + '没能核对本任务改动牵连的旧界面测试是否都跑了'}];
225
+ }
226
+ const touches = (scopePath, rowPath) => rowPath.endsWith('/') ? scopePath.startsWith(rowPath) : scopePath === rowPath;
227
+ const missing = new Map();
228
+ for (const row of map.rows) {
229
+ const hit = definition.scope.filter(scopePath => row.paths.some(rowPath => touches(scopePath, rowPath)));
230
+ if (hit.length === 0) continue;
231
+ for (const id of row.tests) {
232
+ if (commands.some(tokens => runsTest(tokens, id))) continue;
233
+ missing.set(id, [...new Set([...(missing.get(id) ?? []), ...hit])]);
234
+ }
235
+ }
236
+ if (missing.size === 0) return [];
237
+ const tests = [...missing.keys()], paths = [...new Set([...missing.values()].flat())];
238
+ return [{level: 'warn', code: 'affected_tests_not_run', file: map.file, tests: tests.slice(0, MAX_LISTED), paths: paths.slice(0, MAX_LISTED),
239
+ message: `scope 改到 ${paths.slice(0, MAX_LISTED).join('、')}${paths.length > MAX_LISTED ? '…' : ''},按 ${map.file} 的牵连测试表,`
240
+ + `要在本任务当场跑 ${tests.slice(0, MAX_LISTED).join('、')}${tests.length > MAX_LISTED ? '…' : ''},PLAN.checks 里没有跑它们的检查。`
241
+ + '改了共用模块不能只跑新测试、留到功能末尾回归;补上这些测试,确实不牵连就改 TESTING.md 的表'}];
242
+ }
243
+
244
+ function hasGitMarker(root) {
245
+ for (let current = root; ; current = path.dirname(current)) {
246
+ if (fs.existsSync(path.join(current, '.git'))) return true;
247
+ if (path.dirname(current) === current) return false;
248
+ }
249
+ }
250
+
251
+ function checkDirtyScope(definition) {
252
+ if (!fs.existsSync(definition.codeProject)) return [{level: 'warn', code: 'code_project_missing',
253
+ message: `代码根不存在:${definition.codeProject},没能核对 scope 是否干净`}];
254
+ // The reader keeps a PATH git that lives inside the project out of reach by comparing real
255
+ // paths, so hand it the real path of the root (a symlinked temp dir otherwise defeats that).
256
+ const root = fs.realpathSync(definition.codeProject);
257
+ // safeGit is the scanner's reader: trusted git binary, no repository-configured fsmonitor or
258
+ // clean/process/required filters, no user config. A failure to run it is a warn, never a pass.
259
+ let inside;
260
+ try { inside = safeGit(root, ['rev-parse', '--is-inside-work-tree'], true); }
261
+ catch (error) {
262
+ return [{level: 'warn', code: 'git_unavailable',
263
+ message: `Git 不可用或被拒绝(${error.message}),没能核对 scope 是否干净`}];
264
+ }
265
+ if (inside === null || inside.toString('utf8').trim() !== 'true') {
266
+ // The reader folds every non-zero exit into null. A repository marker that exists while git
267
+ // refuses it (damaged repo, unsafe owner) is a failed check, not a project without git.
268
+ if (hasGitMarker(root)) return [{level: 'warn', code: 'git_refused',
269
+ message: '代码根或其上级有 .git,但 Git 拒绝读取(仓库损坏或目录属主不同等),没能核对 scope 是否干净'}];
270
+ return [{level: 'info', code: 'not_git', message: '代码根不是 Git 仓库,已跳过 scope 未提交改动核对'}];
271
+ }
272
+ let output;
273
+ try { output = safeGit(root, ['--literal-pathspecs', 'status', '--porcelain=v1', '-z', '--untracked-files=all', '--', ...definition.scope]); }
274
+ catch (error) {
275
+ return [{level: 'warn', code: 'git_status_failed', message: `git status 失败(${error.message}),没能核对 scope 是否干净`}];
276
+ }
277
+ const dirty = [];
278
+ const entries = output.toString('utf8').split('\0');
279
+ for (let i = 0; i < entries.length; i += 1) {
280
+ const entry = entries[i];
281
+ if (entry.length < 4) continue;
282
+ dirty.push({status: entry.slice(0, 2).trim() || '?', path: entry.slice(3)});
283
+ if (/[RC]/.test(entry.slice(0, 2))) i += 1;
284
+ }
285
+ if (dirty.length === 0) return [];
286
+ const shown = dirty.slice(0, MAX_LISTED).map(item => `${item.status} ${item.path}`);
287
+ return [{level: 'warn', code: 'scope_dirty', count: dirty.length, paths: dirty.slice(0, MAX_LISTED).map(item => item.path),
288
+ message: `scope 内 ${dirty.length} 个文件已有未提交改动(含新建):${shown.join(';')}${dirty.length > MAX_LISTED ? '…' : ''}。`
289
+ + '运行基线会把它们当起点,交审包里看不到这部分改动;若是上次的任务代码,先还原,确认是有意保留的再继续'}];
290
+ }
291
+
292
+ export function startCheck(planFile) {
293
+ const {plan, definition} = loadStartInputs(planFile);
294
+ return [...checkProtectedScope(definition.scope), ...checkChecks(plan), ...checkAffectedTests(plan, definition), ...checkDirtyScope(definition)];
295
+ }
296
+
297
+ export function main(argv = process.argv.slice(2), out = process.stdout, err = process.stderr) {
298
+ const rest = argv.filter(arg => arg !== '--json' && arg !== '--strict');
299
+ const at = rest.indexOf('--plan');
300
+ if (argv.includes('--help') || argv.includes('-h')) { out.write(usage); return 0; }
301
+ if (at === -1 || !rest[at + 1] || rest.length !== 2) { err.write(usage); return 2; }
302
+ let findings;
303
+ try { findings = startCheck(rest[at + 1]); }
304
+ catch (error) {
305
+ if (!(error instanceof InputError)) throw error;
306
+ err.write(`${error.message}\n`);
307
+ return 2;
308
+ }
309
+ const errors = findings.filter(item => item.level === 'error').length;
310
+ const warns = findings.filter(item => item.level === 'warn').length;
311
+ const skipped = findings.filter(item => item.level === 'info').length;
312
+ if (argv.includes('--json')) out.write(`${JSON.stringify({errors, warns, skipped, findings})}\n`);
313
+ else {
314
+ for (const item of findings) out.write(`[${item.level}] ${item.code}: ${item.message}\n`);
315
+ const note = skipped > 0 ? `(另有 ${skipped} 项核对被跳过,见上)` : '';
316
+ if (errors + warns > 0) out.write(`体检结果:${errors} 个 error,${warns} 个 warn${note}\n`);
317
+ else if (skipped > 0) out.write(`体检完成:已核对的项目没有发现阻塞,但有 ${skipped} 项核对被跳过,见上\n`);
318
+ else out.write('体检通过:没有发现可提前识别的阻塞\n');
319
+ }
320
+ return errors > 0 || (argv.includes('--strict') && warns > 0) ? 1 : 0;
321
+ }
322
+
323
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) process.exitCode = main();