@boyingliu01/xp-gate 0.38.126 → 0.39.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 (421) hide show
  1. package/README.md +93 -0
  2. package/adapters/gate-3.sh +13 -2
  3. package/adapters/python.sh +36 -38
  4. package/bin/xp-gate.js +11 -0
  5. package/build-integrity/gate-10-lines.ts +98 -0
  6. package/build-integrity/gate-10.ts +98 -109
  7. package/build-integrity/quote-masker.ts +17 -3
  8. package/gate-3.sh +13 -2
  9. package/gates/common-process.ts +116 -34
  10. package/gates/common.ts +51 -15
  11. package/gates/gate-3.ts +166 -61
  12. package/gates/gate-8.ts +76 -24
  13. package/gates/gate-9.ts +276 -82
  14. package/gates/pbt-detect.ts +70 -39
  15. package/gates/python-health.ts +236 -98
  16. package/gates/test-layers.ts +103 -30
  17. package/hooks/gate-3.sh +13 -2
  18. package/hooks/gate-entries/gate-1-entry.sh +10 -1
  19. package/hooks/gate-entries/gate-5-entry.sh +5 -1
  20. package/hooks/lib/validate-code-walkthrough.cjs +324 -99
  21. package/hooks/pre-commit +52 -0
  22. package/hooks/pre-push +54 -3
  23. package/lib/agent-runtime-journal.js +104 -37
  24. package/lib/arch.js +6 -0
  25. package/lib/baseline.js +329 -201
  26. package/lib/check.js +38 -2
  27. package/lib/doctor-constants.js +43 -0
  28. package/lib/doctor.js +2008 -1001
  29. package/lib/flaky.js +178 -79
  30. package/lib/gate-runner.js +110 -63
  31. package/lib/init.js +6 -0
  32. package/lib/language-capability-surfaces.js +5 -2
  33. package/lib/language-registry.js +608 -0
  34. package/lib/language-tools.js +487 -1018
  35. package/lib/phase-transition.js +646 -446
  36. package/lib/prepush-evidence.js +174 -0
  37. package/lib/sprint-audit.js +52 -22
  38. package/lib/sprint-discovery.js +66 -35
  39. package/lib/sprint-format.js +114 -0
  40. package/lib/sprint-init.js +372 -118
  41. package/lib/sprint-status.js +134 -90
  42. package/lib/star-notice.js +346 -0
  43. package/lib/tool-display.js +52 -0
  44. package/lib/tool-install.js +179 -0
  45. package/lib/uninstall.js +331 -188
  46. package/mock-policy/gate-m3.ts +74 -23
  47. package/mock-policy/mock-decision-engine.ts +21 -7
  48. package/mock-policy/scope-scanner.ts +128 -69
  49. package/mutation/detect-ai-test.ts +20 -12
  50. package/mutation/gate-m.ts +6 -2
  51. package/mutation/init-baseline.ts +49 -13
  52. package/mutation/runners/go-mutant-runner.ts +7 -49
  53. package/mutation/runners/gremlins-runner.ts +53 -18
  54. package/mutation/runners/mutmut-runner.ts +455 -163
  55. package/mutation/runners/pitest-runner.ts +85 -131
  56. package/mutation/runners/spawn-with-capture.ts +304 -0
  57. package/mutation/runners/stryker-runner.ts +14 -55
  58. package/mutation/update-baseline.ts +25 -18
  59. package/package.json +20 -8
  60. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  61. package/plugins/claude-code/bin/delphi-review-guard.sh +12 -61
  62. package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +6 -11
  63. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  64. package/plugins/claude-code/skills/reinstall-xp-gate/.architecture-skip +8 -0
  65. package/plugins/claude-code/skills/reinstall-xp-gate/.github/workflows/test.yml +106 -0
  66. package/plugins/claude-code/skills/reinstall-xp-gate/CHANGELOG.md +379 -0
  67. package/plugins/claude-code/skills/reinstall-xp-gate/LICENSE +21 -0
  68. package/plugins/claude-code/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +173 -0
  69. package/plugins/claude-code/skills/reinstall-xp-gate/README.md +167 -0
  70. package/plugins/claude-code/skills/reinstall-xp-gate/SKILL.md +271 -0
  71. package/plugins/claude-code/skills/reinstall-xp-gate/TODO.md +253 -0
  72. package/plugins/claude-code/skills/reinstall-xp-gate/VERSION +1 -0
  73. package/plugins/claude-code/skills/reinstall-xp-gate/package.json +28 -0
  74. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/audit.mjs +193 -0
  75. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/coverage.mjs +140 -0
  76. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/hp-gate.mjs +175 -0
  77. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/install.mjs +64 -0
  78. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +67 -0
  79. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/agents.mjs +247 -0
  80. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/backups.mjs +96 -0
  81. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +101 -0
  82. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +124 -0
  83. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +61 -0
  84. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +108 -0
  85. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +290 -0
  86. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +37 -0
  87. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +154 -0
  88. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/platform.mjs +92 -0
  89. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/probes.mjs +102 -0
  90. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/proc.mjs +33 -0
  91. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/report.mjs +29 -0
  92. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/residue.mjs +188 -0
  93. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +75 -0
  94. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/skills.mjs +121 -0
  95. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +161 -0
  96. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +26 -0
  97. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/tools.mjs +238 -0
  98. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/util.mjs +33 -0
  99. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +45 -0
  100. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/version.mjs +29 -0
  101. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +66 -0
  102. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/mutation.mjs +132 -0
  103. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/preflight.mjs +75 -0
  104. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/reinstall.mjs +297 -0
  105. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/setup-wsl.sh +633 -0
  106. package/plugins/claude-code/skills/reinstall-xp-gate/scripts/verify.mjs +222 -0
  107. package/plugins/claude-code/skills/reinstall-xp-gate/tests/agents.test.mjs +168 -0
  108. package/plugins/claude-code/skills/reinstall-xp-gate/tests/baseline.test.mjs +104 -0
  109. package/plugins/claude-code/skills/reinstall-xp-gate/tests/ccn.test.mjs +87 -0
  110. package/plugins/claude-code/skills/reinstall-xp-gate/tests/cleanup.test.mjs +128 -0
  111. package/plugins/claude-code/skills/reinstall-xp-gate/tests/coverage.test.mjs +69 -0
  112. package/plugins/claude-code/skills/reinstall-xp-gate/tests/delphi.test.mjs +78 -0
  113. package/plugins/claude-code/skills/reinstall-xp-gate/tests/fixtures.mjs +61 -0
  114. package/plugins/claude-code/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +157 -0
  115. package/plugins/claude-code/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +57 -0
  116. package/plugins/claude-code/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +49 -0
  117. package/plugins/claude-code/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +58 -0
  118. package/plugins/claude-code/skills/reinstall-xp-gate/tests/proc.test.mjs +243 -0
  119. package/plugins/claude-code/skills/reinstall-xp-gate/tests/report.test.mjs +66 -0
  120. package/plugins/claude-code/skills/reinstall-xp-gate/tests/residue.test.mjs +278 -0
  121. package/plugins/claude-code/skills/reinstall-xp-gate/tests/selfsync.test.mjs +70 -0
  122. package/plugins/claude-code/skills/reinstall-xp-gate/tests/skills.test.mjs +171 -0
  123. package/plugins/claude-code/skills/reinstall-xp-gate/tests/testreport.test.mjs +40 -0
  124. package/plugins/claude-code/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +38 -0
  125. package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +323 -0
  126. package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +350 -0
  127. package/plugins/claude-code/skills/reinstall-xp-gate/tests/tools.test.mjs +131 -0
  128. package/plugins/claude-code/skills/reinstall-xp-gate/tests/util.test.mjs +154 -0
  129. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  130. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  131. package/plugins/dsh/package.json +1 -1
  132. package/plugins/dsh/scripts/prepack.cjs +43 -18
  133. package/plugins/dsh/scripts/verify-skill-provider.mjs +39 -14
  134. package/plugins/dsh/skills/delphi-review/.delphi-config.json.example +6 -11
  135. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  136. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  137. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  138. package/plugins/opencode/index.ts +337 -123
  139. package/plugins/opencode/package.json +1 -1
  140. package/plugins/opencode/scripts/prepack.cjs +41 -16
  141. package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +6 -11
  142. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  143. package/plugins/opencode/skills/reinstall-xp-gate/.architecture-skip +8 -0
  144. package/plugins/opencode/skills/reinstall-xp-gate/.github/workflows/test.yml +106 -0
  145. package/plugins/opencode/skills/reinstall-xp-gate/CHANGELOG.md +379 -0
  146. package/plugins/opencode/skills/reinstall-xp-gate/LICENSE +21 -0
  147. package/plugins/opencode/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +173 -0
  148. package/plugins/opencode/skills/reinstall-xp-gate/README.md +167 -0
  149. package/plugins/opencode/skills/reinstall-xp-gate/SKILL.md +271 -0
  150. package/plugins/opencode/skills/reinstall-xp-gate/TODO.md +253 -0
  151. package/plugins/opencode/skills/reinstall-xp-gate/VERSION +1 -0
  152. package/plugins/opencode/skills/reinstall-xp-gate/package.json +28 -0
  153. package/plugins/opencode/skills/reinstall-xp-gate/scripts/audit.mjs +193 -0
  154. package/plugins/opencode/skills/reinstall-xp-gate/scripts/coverage.mjs +140 -0
  155. package/plugins/opencode/skills/reinstall-xp-gate/scripts/hp-gate.mjs +175 -0
  156. package/plugins/opencode/skills/reinstall-xp-gate/scripts/install.mjs +64 -0
  157. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +67 -0
  158. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/agents.mjs +247 -0
  159. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/backups.mjs +96 -0
  160. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +101 -0
  161. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +124 -0
  162. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +61 -0
  163. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +108 -0
  164. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +290 -0
  165. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +37 -0
  166. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +154 -0
  167. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/platform.mjs +92 -0
  168. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/probes.mjs +102 -0
  169. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/proc.mjs +33 -0
  170. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/report.mjs +29 -0
  171. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/residue.mjs +188 -0
  172. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +75 -0
  173. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/skills.mjs +121 -0
  174. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +161 -0
  175. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +26 -0
  176. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/tools.mjs +238 -0
  177. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/util.mjs +33 -0
  178. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +45 -0
  179. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/version.mjs +29 -0
  180. package/plugins/opencode/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +66 -0
  181. package/plugins/opencode/skills/reinstall-xp-gate/scripts/mutation.mjs +132 -0
  182. package/plugins/opencode/skills/reinstall-xp-gate/scripts/preflight.mjs +75 -0
  183. package/plugins/opencode/skills/reinstall-xp-gate/scripts/reinstall.mjs +297 -0
  184. package/plugins/opencode/skills/reinstall-xp-gate/scripts/setup-wsl.sh +633 -0
  185. package/plugins/opencode/skills/reinstall-xp-gate/scripts/verify.mjs +222 -0
  186. package/plugins/opencode/skills/reinstall-xp-gate/tests/agents.test.mjs +168 -0
  187. package/plugins/opencode/skills/reinstall-xp-gate/tests/baseline.test.mjs +104 -0
  188. package/plugins/opencode/skills/reinstall-xp-gate/tests/ccn.test.mjs +87 -0
  189. package/plugins/opencode/skills/reinstall-xp-gate/tests/cleanup.test.mjs +128 -0
  190. package/plugins/opencode/skills/reinstall-xp-gate/tests/coverage.test.mjs +69 -0
  191. package/plugins/opencode/skills/reinstall-xp-gate/tests/delphi.test.mjs +78 -0
  192. package/plugins/opencode/skills/reinstall-xp-gate/tests/fixtures.mjs +61 -0
  193. package/plugins/opencode/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +157 -0
  194. package/plugins/opencode/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +57 -0
  195. package/plugins/opencode/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +49 -0
  196. package/plugins/opencode/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +58 -0
  197. package/plugins/opencode/skills/reinstall-xp-gate/tests/proc.test.mjs +243 -0
  198. package/plugins/opencode/skills/reinstall-xp-gate/tests/report.test.mjs +66 -0
  199. package/plugins/opencode/skills/reinstall-xp-gate/tests/residue.test.mjs +278 -0
  200. package/plugins/opencode/skills/reinstall-xp-gate/tests/selfsync.test.mjs +70 -0
  201. package/plugins/opencode/skills/reinstall-xp-gate/tests/skills.test.mjs +171 -0
  202. package/plugins/opencode/skills/reinstall-xp-gate/tests/testreport.test.mjs +40 -0
  203. package/plugins/opencode/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +38 -0
  204. package/plugins/opencode/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +323 -0
  205. package/plugins/opencode/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +350 -0
  206. package/plugins/opencode/skills/reinstall-xp-gate/tests/tools.test.mjs +131 -0
  207. package/plugins/opencode/skills/reinstall-xp-gate/tests/util.test.mjs +154 -0
  208. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  209. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  210. package/plugins/qoder/bin/sprint-flow-guard.sh +12 -60
  211. package/plugins/qoder/plugin.json +1 -1
  212. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +6 -11
  213. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  214. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  215. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  216. package/plugins/shared/README.md +3 -0
  217. package/plugins/shared/bin/delphi-review-guard.sh +68 -0
  218. package/principles/adapters/control-nesting.ts +481 -168
  219. package/principles/adapters/cpp.ts +61 -22
  220. package/principles/adapters/csharp.ts +183 -66
  221. package/principles/adapters/dart.ts +11 -1
  222. package/principles/adapters/duplication.ts +49 -16
  223. package/principles/adapters/import-clause.ts +62 -15
  224. package/principles/adapters/java.ts +199 -70
  225. package/principles/adapters/line-comment.ts +18 -0
  226. package/principles/adapters/member-scan.ts +50 -8
  227. package/principles/adapters/php.ts +232 -103
  228. package/principles/adapters/python.ts +25 -18
  229. package/principles/adapters/quote-state.ts +21 -8
  230. package/principles/adapters/typescript-mask.ts +276 -0
  231. package/principles/adapters/typescript.ts +206 -200
  232. package/principles/analyzer.ts +16 -6
  233. package/principles/baseline-prune.ts +18 -8
  234. package/principles/baseline.ts +28 -11
  235. package/principles/boy-scout-usage.ts +26 -0
  236. package/principles/boy-scout.ts +261 -180
  237. package/principles/config.ts +183 -57
  238. package/principles/direct-execution.ts +24 -12
  239. package/principles/lint-baseline.ts +235 -122
  240. package/principles/rules/arch/dependency.ts +34 -25
  241. package/principles/rules/arch/shared.ts +24 -20
  242. package/principles/rules/clean-code/deep-nesting.ts +23 -13
  243. package/principles/rules/clean-code/god-class.ts +67 -41
  244. package/principles/rules/clean-code/large-file.ts +30 -23
  245. package/principles/rules/clean-code/long-function.ts +51 -37
  246. package/principles/rules/clean-code/magic-numbers.ts +51 -36
  247. package/principles/rules/clean-code/many-exports.ts +46 -29
  248. package/principles/rules/clean-code/missing-error-handling.ts +38 -20
  249. package/principles/rules/clean-code/too-many-params.ts +41 -22
  250. package/principles/rules/function-source.ts +62 -0
  251. package/principles/rules/solid/dip.ts +10 -6
  252. package/principles/rules/solid/isp.ts +64 -24
  253. package/principles/rules/solid/lsp.ts +66 -18
  254. package/principles/rules/solid/ocp.ts +29 -13
  255. package/principles/rules/solid/srp.ts +34 -18
  256. package/principles/warnings-count.ts +43 -0
  257. package/scripts/__tests__/prepush-source-classification.test.js +129 -0
  258. package/scripts/delphi-config-read.cjs +245 -0
  259. package/scripts/delphi-external-review.cjs +410 -585
  260. package/scripts/delphi-json-extract.cjs +108 -0
  261. package/scripts/delphi-model-validation.cjs +297 -0
  262. package/scripts/delphi-prompts.cjs +55 -0
  263. package/scripts/delphi-repo-tools.cjs +273 -0
  264. package/scripts/delphi-seat-calibration.cjs +204 -0
  265. package/scripts/run-bats-ci.cjs +240 -97
  266. package/scripts/sync-package-content.js +18 -2
  267. package/skills/delphi-review/.delphi-config.json.example +6 -11
  268. package/skills/delphi-review/AGENTS.md +1 -1
  269. package/skills/sprint-flow/AGENTS.md +1 -1
  270. package/skills/test-specification-alignment/AGENTS.md +1 -1
  271. package/lib/__tests__/agent-runtime-journal.test.js +0 -326
  272. package/lib/__tests__/arch-config-template.test.js +0 -190
  273. package/lib/__tests__/arch.test.js +0 -430
  274. package/lib/__tests__/assertion-debt.test.js +0 -99
  275. package/lib/__tests__/audit-cli-contract.test.ts +0 -117
  276. package/lib/__tests__/audit-log.test.ts +0 -107
  277. package/lib/__tests__/audit-skip-reasons.test.ts +0 -143
  278. package/lib/__tests__/baseline-completeness.test.js +0 -264
  279. package/lib/__tests__/baseline-shell-scope.test.js +0 -60
  280. package/lib/__tests__/baseline-unevaluated.test.js +0 -142
  281. package/lib/__tests__/baseline.test.js +0 -212
  282. package/lib/__tests__/bootstrap.test.js +0 -60
  283. package/lib/__tests__/check-alignment-cli.test.mjs +0 -94
  284. package/lib/__tests__/check-alignment-reasons.test.mjs +0 -101
  285. package/lib/__tests__/check-all-skip-accounting.test.js +0 -171
  286. package/lib/__tests__/check-changed-brief.test.js +0 -63
  287. package/lib/__tests__/check-normalize-exit.test.js +0 -24
  288. package/lib/__tests__/check-single-file.test.js +0 -114
  289. package/lib/__tests__/check-tools-list.test.js +0 -155
  290. package/lib/__tests__/check-version.test.js +0 -463
  291. package/lib/__tests__/coverage-scope.test.js +0 -140
  292. package/lib/__tests__/coverage-threshold.test.js +0 -80
  293. package/lib/__tests__/crap-cli.test.js +0 -87
  294. package/lib/__tests__/crap.test.js +0 -494
  295. package/lib/__tests__/debt-classify.test.js +0 -78
  296. package/lib/__tests__/delphi-channel-doctor.test.js +0 -116
  297. package/lib/__tests__/delphi-channel-uninstall.test.js +0 -128
  298. package/lib/__tests__/delphi-channel.test.js +0 -109
  299. package/lib/__tests__/delphi-setup.test.js +0 -203
  300. package/lib/__tests__/deploy-manifest-check-wired.test.js +0 -138
  301. package/lib/__tests__/deploy-manifest-completeness.test.js +0 -151
  302. package/lib/__tests__/deploy-manifest-consumers-adapter-uninstall.test.js +0 -40
  303. package/lib/__tests__/deploy-manifest-consumers-no-private-lists.test.js +0 -74
  304. package/lib/__tests__/deploy-manifest-projection.test.js +0 -66
  305. package/lib/__tests__/deploy-manifest-shell-parity.test.js +0 -108
  306. package/lib/__tests__/deploy-manifest.test.js +0 -97
  307. package/lib/__tests__/detect-deps-dsh-profile.test.js +0 -323
  308. package/lib/__tests__/detect-deps-gate-identity.test.js +0 -135
  309. package/lib/__tests__/detect-deps.test.js +0 -655
  310. package/lib/__tests__/doctor-469-hook-env.test.js +0 -211
  311. package/lib/__tests__/doctor-arch-tools.test.js +0 -169
  312. package/lib/__tests__/doctor-audit-ledger.test.js +0 -61
  313. package/lib/__tests__/doctor-brief.test.js +0 -59
  314. package/lib/__tests__/doctor-delphi.test.js +0 -628
  315. package/lib/__tests__/doctor-drift-direction.test.js +0 -104
  316. package/lib/__tests__/doctor-drift-round2.test.js +0 -215
  317. package/lib/__tests__/doctor-exec-retry.test.js +0 -162
  318. package/lib/__tests__/doctor-executed-surface.test.js +0 -230
  319. package/lib/__tests__/doctor-helpers.test.js +0 -139
  320. package/lib/__tests__/doctor-hook-drift.test.js +0 -329
  321. package/lib/__tests__/doctor-hook-signatures.test.js +0 -65
  322. package/lib/__tests__/doctor-machine-mutation.test.js +0 -116
  323. package/lib/__tests__/doctor-module-drift.test.js +0 -212
  324. package/lib/__tests__/doctor-module-resolution-parity.test.js +0 -463
  325. package/lib/__tests__/doctor-path-equivalence.test.js +0 -70
  326. package/lib/__tests__/doctor-repair-boundary.test.js +0 -52
  327. package/lib/__tests__/doctor-signature-stability.test.js +0 -55
  328. package/lib/__tests__/doctor-spawn-capability.test.js +0 -116
  329. package/lib/__tests__/doctor-timeout-partial.test.js +0 -79
  330. package/lib/__tests__/doctor-tool-delegation.test.js +0 -156
  331. package/lib/__tests__/doctor-tui-skill-freshness.test.js +0 -385
  332. package/lib/__tests__/doctor.test.js +0 -1320
  333. package/lib/__tests__/find-bash-wsl.test.js +0 -121
  334. package/lib/__tests__/flaky.test.js +0 -128
  335. package/lib/__tests__/foreign-hooks-global.test.js +0 -125
  336. package/lib/__tests__/gate-audit-skip.test.ts +0 -81
  337. package/lib/__tests__/gate-audit.test.ts +0 -440
  338. package/lib/__tests__/gate-coverage-hook-floor.test.js +0 -94
  339. package/lib/__tests__/gate-coverage.test.js +0 -204
  340. package/lib/__tests__/gate-entry-provenance.test.js +0 -71
  341. package/lib/__tests__/gate-numbering.test.js +0 -79
  342. package/lib/__tests__/gate-rules.test.js +0 -58
  343. package/lib/__tests__/gate-runner-tsx-invocation.test.js +0 -149
  344. package/lib/__tests__/gate-runner-verdict.test.js +0 -105
  345. package/lib/__tests__/gate-runner.test.js +0 -371
  346. package/lib/__tests__/gate2-verdict.test.js +0 -183
  347. package/lib/__tests__/helpers/lib-sandbox.cjs +0 -55
  348. package/lib/__tests__/hook-health-path.test.js +0 -109
  349. package/lib/__tests__/hook-health.test.js +0 -85
  350. package/lib/__tests__/init-gitignore.test.js +0 -204
  351. package/lib/__tests__/init-gitleaks-notice.test.js +0 -57
  352. package/lib/__tests__/init.test.js +0 -530
  353. package/lib/__tests__/install-cmd.test.js +0 -6
  354. package/lib/__tests__/install-sh-deploy-manifest.test.js +0 -80
  355. package/lib/__tests__/install-skill-full-dir.test.js +0 -194
  356. package/lib/__tests__/install-skill.test.js +0 -416
  357. package/lib/__tests__/install-tools-repair.test.js +0 -263
  358. package/lib/__tests__/issue-519-phase-transition-guard.test.js +0 -233
  359. package/lib/__tests__/issue-566-sync-hooks-backup.test.js +0 -228
  360. package/lib/__tests__/issue-583-hook-deploy-log.test.js +0 -121
  361. package/lib/__tests__/issue-586-principles-cmdline.test.js +0 -218
  362. package/lib/__tests__/issue-589-check-all-gate3.test.js +0 -190
  363. package/lib/__tests__/issue-590-archlint-vacuous-pass.test.js +0 -138
  364. package/lib/__tests__/issue-618-gate-not-run.test.js +0 -100
  365. package/lib/__tests__/jscpd-entry-resolution.test.js +0 -143
  366. package/lib/__tests__/language-capability.test.js +0 -318
  367. package/lib/__tests__/language-tools-build-file-install.test.js +0 -82
  368. package/lib/__tests__/language-tools-detect.test.js +0 -301
  369. package/lib/__tests__/migrate.test.js +0 -232
  370. package/lib/__tests__/mirror-manifest.test.js +0 -64
  371. package/lib/__tests__/mirror-sync.test.js +0 -803
  372. package/lib/__tests__/next-sprint.test.js +0 -231
  373. package/lib/__tests__/npm-package.test.js +0 -140
  374. package/lib/__tests__/phase-transition.test.js +0 -1136
  375. package/lib/__tests__/principles-csharp-coverage.test.js +0 -227
  376. package/lib/__tests__/principles-directory.test.js +0 -87
  377. package/lib/__tests__/qoder-delphi-agents.test.js +0 -316
  378. package/lib/__tests__/retro-gate-m.test.js +0 -144
  379. package/lib/__tests__/retro.test.js +0 -131
  380. package/lib/__tests__/rework.test.js +0 -127
  381. package/lib/__tests__/rollback.test.js +0 -183
  382. package/lib/__tests__/runtime-journal.test.js +0 -164
  383. package/lib/__tests__/sastd-client.test.js +0 -514
  384. package/lib/__tests__/shared-paths-lazy-home.test.js +0 -67
  385. package/lib/__tests__/shared-paths.test.js +0 -130
  386. package/lib/__tests__/shared-utils-copyHooks-manifest.test.js +0 -69
  387. package/lib/__tests__/shared-utils.test.js +0 -180
  388. package/lib/__tests__/skill-flags.test.js +0 -48
  389. package/lib/__tests__/slo.test.js +0 -89
  390. package/lib/__tests__/sprint-audit.test.js +0 -207
  391. package/lib/__tests__/sprint-discovery.test.ts +0 -366
  392. package/lib/__tests__/sprint-state-manager.test.js +0 -310
  393. package/lib/__tests__/sprint-status-rework-704.test.js +0 -149
  394. package/lib/__tests__/sprint-status-rework.test.js +0 -329
  395. package/lib/__tests__/sprint-status.test.js +0 -193
  396. package/lib/__tests__/sprint-status.test.ts +0 -213
  397. package/lib/__tests__/test-alignment-java-702.test.ts +0 -177
  398. package/lib/__tests__/test-alignment-range-guard.test.ts +0 -82
  399. package/lib/__tests__/test-alignment.test.ts +0 -853
  400. package/lib/__tests__/tool-audit-collect.test.js +0 -184
  401. package/lib/__tests__/tool-audit-fixtures.js +0 -87
  402. package/lib/__tests__/tool-audit-latest.test.js +0 -84
  403. package/lib/__tests__/tool-audit.test.js +0 -428
  404. package/lib/__tests__/tsconfig.json +0 -8
  405. package/lib/__tests__/tsx-resolution.test.js +0 -89
  406. package/lib/__tests__/ui-detector.test.ts +0 -459
  407. package/lib/__tests__/ui-review.test.ts +0 -132
  408. package/lib/__tests__/uninstall-global-residue.test.js +0 -545
  409. package/lib/__tests__/uninstall-skill.test.js +0 -189
  410. package/lib/__tests__/uninstall.test.js +0 -717
  411. package/lib/__tests__/update-hooks.test.js +0 -737
  412. package/lib/__tests__/update-skill-flags.test.js +0 -78
  413. package/lib/__tests__/update-skill.test.js +0 -644
  414. package/lib/__tests__/upgrade-exec.test.js +0 -273
  415. package/lib/__tests__/upgrade-skill-sync.test.js +0 -65
  416. package/lib/__tests__/upgrade.test.js +0 -78
  417. package/lib/__tests__/windows-bash-probe.test.js +0 -123
  418. package/lib/check-alignment-runner.cjs +0 -97
  419. package/lib/coverage-total.sh +0 -92
  420. package/lib/layer-baseline.cjs +0 -94
  421. package/lib/mattpocock-license-verdict.json +0 -7
@@ -9,6 +9,18 @@
9
9
 
10
10
  const fs = require('fs');
11
11
  const path = require('path');
12
+ const { statusIcon, formatDuration: formatDurationShared } = require('./sprint-format.js');
13
+
14
+ /**
15
+ * A list row shows nothing for an unmeasured duration: "instantaneous" and "not
16
+ * measured" must not look alike, and neither should take visual weight.
17
+ *
18
+ * @param {number|null|undefined} seconds
19
+ * @returns {string}
20
+ */
21
+ function formatDuration(seconds) {
22
+ return formatDurationShared(seconds);
23
+ }
12
24
  const { execFileSync } = require('child_process');
13
25
  const { discoverActiveSprints } = require('./sprint-discovery');
14
26
  const { SprintStateManager } = require('./sprint-state-manager');
@@ -44,7 +56,7 @@ function getLatestTimestamp(state) {
44
56
  function isStale(state) {
45
57
  if (!state || !state.started_at) return false;
46
58
  const latest = getLatestTimestamp(state);
47
- return latest > 0 && Date.now() - latest > 3600000;
59
+ return latest > 0 && Date.now() - latest > STALE_AFTER_MS;
48
60
  }
49
61
 
50
62
  /**
@@ -62,33 +74,7 @@ function readSprintState(dir) {
62
74
  }
63
75
  }
64
76
 
65
- /**
66
- * Get a phase's status icon.
67
- * @param {'completed'|'in_progress'|'pending'|string} status
68
- * @returns {string} Icon character
69
- */
70
- function statusIcon(status) {
71
- switch (status) {
72
- case 'completed': return '✅';
73
- case 'in_progress': return '🔄';
74
- case 'skipped': return '⏭️';
75
- default: return '⏳';
76
- }
77
- }
78
77
 
79
- /**
80
- * Format a duration in seconds to a human-readable string.
81
- * @param {number|null} seconds
82
- * @returns {string}
83
- */
84
- function formatDuration(seconds) {
85
- if (seconds == null || seconds === 0) return '';
86
- if (seconds < 60) return `${seconds}s`;
87
- const mins = Math.floor(seconds / 60);
88
- if (mins < 60) return `${mins}m`;
89
- const hrs = Math.floor(mins / 60);
90
- return `${hrs}h ${mins % 60}m`;
91
- }
92
78
 
93
79
  /**
94
80
  * Format the sprint header lines (task description, ID, branch).
@@ -196,7 +182,7 @@ function formatSprintTable(state) {
196
182
  if (name.length > maxNameLen) maxNameLen = name.length;
197
183
  }
198
184
 
199
- const sep = '─'.repeat(maxNameLen + 40);
185
+ const sep = '─'.repeat(maxNameLen + TABLE_SIDE_PADDING);
200
186
  lines.push(sep);
201
187
 
202
188
  for (const key of PHASE_ORDER) {
@@ -218,7 +204,7 @@ function jsonMode(state) {
218
204
  }
219
205
 
220
206
  // #369: fix commit matching — conventional commits + keyword boundary
221
- const FIX_RE = /^(fix(\(.+\))?:)|\b(fix|bugfix|hotfix|patch|修复)\b/i;
207
+ const FIX_RE = /^(fix(\(.+\))?:)|\b(fix|bugfix|hotfix|patch)\b|修复/i;
222
208
 
223
209
  /**
224
210
  * Git env with every repo-redirecting variable stripped, so `cwd` is the only
@@ -289,42 +275,125 @@ function getWindowCommitCounts(repoDir, sinceDate, untilDate) {
289
275
  * @param {number} windowDays - Window in days after completed_at
290
276
  * @returns {Promise<number>} Exit code
291
277
  */
292
- async function handleReworkCheck(searchDir, windowDays) {
293
- const stateDir = path.join(searchDir, '.sprint-state');
294
- const historyDir = path.join(stateDir, 'sprint-history');
295
- const sprintStateFile = path.join(stateDir, 'sprint-state.json');
278
+ /** A sprint whose state file has not changed for an hour is reported as stale. */
279
+ const STALE_AFTER_MS = 3600000;
280
+ /** Characters a table rule adds around the widest name: two of margin per side. */
281
+ const TABLE_SIDE_PADDING = 40;
282
+ /** `fs.watchFile` polls; five seconds is frequent enough to feel live, cheap enough to ignore. */
283
+ const WATCH_POLL_INTERVAL_MS = 5000;
296
284
 
285
+ /** One day in milliseconds -- the unit the rework window is expressed in. */
286
+ const MS_PER_DAY = 86400000;
287
+
288
+ /**
289
+ * Every sprint that closed within the last `windowDays`, newest data included.
290
+ *
291
+ * A sprint counts only if it has `metrics.completed_at`: the rework rate is
292
+ * computed over a finished sprint's own window, so an open sprint has nothing to
293
+ * measure. Malformed files are skipped rather than aborting the report -- one
294
+ * corrupt history entry must not hide the other sprints.
295
+ *
296
+ * @param {{sprintStateFile: string, historyDir: string}} paths
297
+ * @param {number} windowDays
298
+ * @returns {Array<{id: string, state: object, file: string}>}
299
+ */
300
+ function collectClosedSprints(paths, windowDays) {
301
+ const { sprintStateFile, historyDir } = paths;
297
302
  const sprints = [];
298
303
 
299
- // Current sprint-state.json
300
- if (fs.existsSync(sprintStateFile)) {
304
+ const addIfClosed = (file, fallbackId) => {
301
305
  try {
302
- const state = JSON.parse(fs.readFileSync(sprintStateFile, 'utf8'));
306
+ const state = JSON.parse(fs.readFileSync(file, 'utf8'));
303
307
  if (state.metrics && state.metrics.completed_at) {
304
- sprints.push({ id: state.id || 'unknown', state, file: sprintStateFile });
308
+ sprints.push({ id: state.id || fallbackId, state, file });
305
309
  }
306
- } catch { /* skip malformed */ }
307
- }
310
+ } catch {
311
+ // A malformed entry is skipped; one bad file must not hide the others.
312
+ }
313
+ };
314
+
315
+ if (fs.existsSync(sprintStateFile)) addIfClosed(sprintStateFile, 'unknown');
308
316
 
309
- // History files
310
317
  if (fs.existsSync(historyDir)) {
311
- for (const f of fs.readdirSync(historyDir).filter(f => f.endsWith('.json'))) {
312
- try {
313
- const fp = path.join(historyDir, f);
314
- const state = JSON.parse(fs.readFileSync(fp, 'utf8'));
315
- if (state.metrics && state.metrics.completed_at) {
316
- sprints.push({ id: state.id || f.replace('.json', ''), state, file: fp });
317
- }
318
- } catch { /* skip malformed */ }
318
+ for (const name of fs.readdirSync(historyDir).filter((f) => f.endsWith('.json'))) {
319
+ addIfClosed(path.join(historyDir, name), name.replace('.json', ''));
319
320
  }
320
321
  }
321
322
 
322
323
  const now = Date.now();
323
- const windowMs = windowDays * 86400000;
324
- const inWindow = sprints.filter(s => {
324
+ const windowMs = windowDays * MS_PER_DAY;
325
+ return sprints.filter((s) => {
325
326
  const t = new Date(s.state.metrics.completed_at).getTime();
326
327
  return !isNaN(t) && (now - t) <= windowMs;
327
328
  });
329
+ }
330
+
331
+ /**
332
+ * Rework rate above this is an alert. 30% of a sprint's commits being fixes is
333
+ * the point at which the sprint was not really building the thing.
334
+ */
335
+ const REWORK_ALERT_THRESHOLD = 0.30;
336
+
337
+ /**
338
+ * Measure one sprint's rework rate over its own window, and report it.
339
+ *
340
+ * #704: the window is the sprint itself (start -> completion), and both counts
341
+ * come from one `git log` over it. Previously the total came from a field nothing
342
+ * wrote and the `--since` bound was the sprint's END, so both numbers were
343
+ * structurally 0 and the rate could only be 0 -- while the summary still said
344
+ * "within acceptable rate".
345
+ *
346
+ * No commits in the window means the rate is UNDEFINED, not zero. Reporting 0.0%
347
+ * would rebuild the same false reassurance one level down, so the sprint is
348
+ * surfaced as unmeasurable and never counts as within threshold.
349
+ *
350
+ * @param {string} searchDir
351
+ * @param {string} id
352
+ * @param {object} state
353
+ * @param {string} file
354
+ * @returns {{unmeasurable: boolean, alert: boolean}}
355
+ */
356
+ function measureSprint(searchDir, id, state, file) {
357
+ const { fix: fixCommits, total: totalCommits } = getWindowCommitCounts(
358
+ searchDir,
359
+ state.started_at,
360
+ state.metrics.completed_at,
361
+ );
362
+
363
+ if (totalCommits === 0) {
364
+ console.log(` ${id}: 0 fix / 0 total commits — NOT MEASURABLE (no commits in sprint window)`);
365
+ return { unmeasurable: true, alert: false };
366
+ }
367
+
368
+ const rate = fixCommits / totalCommits;
369
+
370
+ // Persist what was actually measured, denominator included: the previous code
371
+ // wrote the rate unconditionally, so a transposed 0 could overwrite a value a
372
+ // human had corrected.
373
+ state.metrics.rework_rate = rate;
374
+ state.metrics.total_sprint_commits = totalCommits;
375
+ state.metrics.fix_sprint_commits = fixCommits;
376
+ try {
377
+ fs.writeFileSync(file, JSON.stringify(state, null, 2));
378
+ } catch {
379
+ // Non-fatal: the report is still printable from the measured values.
380
+ }
381
+
382
+ const pct = (rate * 100).toFixed(1);
383
+ console.log(` ${id}: ${pct}% (${fixCommits} fix / ${totalCommits} total commits)`);
384
+ if (rate > REWORK_ALERT_THRESHOLD) {
385
+ console.log(` ⚠️ ${id}: ${pct}% rework — exceeds ${REWORK_ALERT_THRESHOLD * 100}% threshold`);
386
+ return { unmeasurable: false, alert: true };
387
+ }
388
+ return { unmeasurable: false, alert: false };
389
+ }
390
+
391
+ async function handleReworkCheck(searchDir, windowDays) {
392
+ const stateDir = path.join(searchDir, '.sprint-state');
393
+ const historyDir = path.join(stateDir, 'sprint-history');
394
+ const sprintStateFile = path.join(stateDir, 'sprint-state.json');
395
+
396
+ const inWindow = collectClosedSprints({ sprintStateFile, historyDir }, windowDays);
328
397
 
329
398
  if (inWindow.length === 0) {
330
399
  console.log(`No closed sprints within ${windowDays} day${windowDays === 1 ? '' : 's'}`);
@@ -337,45 +406,9 @@ async function handleReworkCheck(searchDir, windowDays) {
337
406
  let hasAlert = false;
338
407
  let hasUnmeasurable = false;
339
408
  for (const { id, state, file } of inWindow) {
340
- // #704: the window is the sprint itself (start → completion), and both
341
- // counts come from one `git log` over that window. Previously the total was
342
- // read from a field nothing wrote, and the `--since` bound was the END of
343
- // the sprint, so both numbers were structurally 0 and the rate could only
344
- // ever be 0 — while the summary line still said "within acceptable rate".
345
- const { fix: fixCommits, total: totalCommits } = getWindowCommitCounts(
346
- searchDir,
347
- state.started_at,
348
- state.metrics.completed_at,
349
- );
350
-
351
- // No commits in the window means the rate is undefined, not zero. Reporting
352
- // 0.0% here would rebuild the same false reassurance one level down, so the
353
- // sprint is surfaced as unmeasurable and never counts as "within threshold".
354
- if (totalCommits === 0) {
355
- hasUnmeasurable = true;
356
- console.log(` ${id}: 0 fix / 0 total commits — NOT MEASURABLE (no commits in sprint window)`);
357
- continue;
358
- }
359
-
360
- const rate = fixCommits / totalCommits;
361
-
362
- // Persist what was actually measured. The previous code wrote the rate
363
- // unconditionally, which meant a transposed 0 could overwrite a value a
364
- // human had already corrected; now the denominator is persisted alongside
365
- // it so the next run can be checked against its own evidence.
366
- state.metrics.rework_rate = rate;
367
- state.metrics.total_sprint_commits = totalCommits;
368
- state.metrics.fix_sprint_commits = fixCommits;
369
- try {
370
- fs.writeFileSync(file, JSON.stringify(state, null, 2));
371
- } catch { /* non-fatal */ }
372
-
373
- const pct = (rate * 100).toFixed(1);
374
- console.log(` ${id}: ${pct}% (${fixCommits} fix / ${totalCommits} total commits)`);
375
- if (rate > 0.30) {
376
- console.log(` ⚠️ ${id}: ${pct}% rework — exceeds 30% threshold`);
377
- hasAlert = true;
378
- }
409
+ const outcome = measureSprint(searchDir, id, state, file);
410
+ if (outcome.unmeasurable) hasUnmeasurable = true;
411
+ if (outcome.alert) hasAlert = true;
379
412
  }
380
413
 
381
414
  console.log('─'.repeat(60));
@@ -515,7 +548,7 @@ function watchMode(stateFile) {
515
548
  } catch {
516
549
  // Fallback to fs.watchFile
517
550
  try {
518
- fs.watchFile(stateFile, { interval: 5000 }, () => {
551
+ fs.watchFile(stateFile, { interval: WATCH_POLL_INTERVAL_MS }, () => {
519
552
  const state = readSprintState(path.dirname(dir));
520
553
  if (state) {
521
554
  console.clear();
@@ -558,4 +591,15 @@ module.exports = {
558
591
  // the CLI, so the only way to test it was to shell out and parse console
559
592
  // output. A function nobody can call directly is a function nobody can pin.
560
593
  handleReworkCheck,
594
+ // Pure display/parse helpers, exported so they can be pinned without rendering a
595
+ // whole table through the CLI.
596
+ parseTime,
597
+ getLatestTimestamp,
598
+ statusIcon,
599
+ formatDuration,
600
+ buildMetricsLine,
601
+ formatReqLines,
602
+ formatPhaseLine,
603
+ getWindowCommitCounts,
604
+ measureSprint,
561
605
  };
@@ -0,0 +1,346 @@
1
+ /**
2
+ * @test Issues #871 make the project discoverable from the CLI itself
3
+ * @intent A user who already trusts the tool is the one best placed to point
4
+ * others at it, so the invitation belongs where that trust is formed:
5
+ * --version, a finished `init`, and a clean `check`.
6
+ * @covers #871
7
+ *
8
+ * Restraint is part of the contract, not a courtesy. The module is silent on
9
+ * CI, silent when stdout is not a TTY, and repeats at most once a day. If the
10
+ * "already shown" timestamp cannot be persisted, the notice stays silent for
11
+ * the rest of the process rather than printing on every invocation -- a
12
+ * failure to record is never allowed to turn into nagging.
13
+ */
14
+ const fs = require('fs');
15
+ const os = require('os');
16
+
17
+ const { CONFIG_FILE } = require('./shared-paths.js');
18
+
19
+ const REPO_URL = 'https://github.com/boyingliu01/xp-gate';
20
+ const NOTICE_TEXT = `⭐ If XP-Gate saves you time, a star helps others find it: ${REPO_URL}`;
21
+
22
+ /**
23
+ * README badge markup offered once a project's gates come back clean.
24
+ *
25
+ * A badge is the cheapest honest claim a project can make about itself: it
26
+ * shows a passing gate, not a promise. That is why it is offered only after a
27
+ * run where nothing failed -- the markup would be false otherwise.
28
+ */
29
+ const BADGE_SHIELD_URL = 'https://img.shields.io/badge/gated%20by-XP--Gate-blueviolet';
30
+ const BADGE_MARKDOWN = `[![gated by XP-Gate](${BADGE_SHIELD_URL})](${REPO_URL})`;
31
+ const DAY_MS = 24 * 60 * 60 * 1000;
32
+
33
+ /**
34
+ * How long a dismissal lasts, in days.
35
+ *
36
+ * `xp-gate star-notice --off` writes this window, so the promised "ask us to
37
+ * stop and we stop" has an actual entry point rather than a hand-edited JSON.
38
+ */
39
+ const DISMISS_DAYS = 30;
40
+
41
+ /**
42
+ * In-process guard: set for the lifetime of the process.
43
+ *
44
+ * When the config cannot be written, the on-disk throttle is unavailable, so
45
+ * without this the notice would print on every call in a loop. One process
46
+ * printing it once is the most we can honestly promise in that state.
47
+ */
48
+ let shownInThisProcess = false;
49
+
50
+ /** Reset the in-process guard. Tests need a clean slate per case. */
51
+ function resetProcessGuard() {
52
+ shownInThisProcess = false;
53
+ }
54
+
55
+ /**
56
+ * Decide whether the star invitation may be shown right now.
57
+ *
58
+ * Pure: every input is a parameter. It reads no ambient state, so the policy
59
+ * is testable without faking a terminal.
60
+ *
61
+ * A `lastShownAt` in the future (clock rollback, a restored backup, a shared
62
+ * home across timezones with skewed clocks) is treated as "not yet shown"
63
+ * rather than "shown forever": a stale future timestamp must not silence the
64
+ * notice permanently.
65
+ *
66
+ * @param {{isTTY?: boolean, env?: Record<string, string|undefined>, config?: object, now?: number}} ctx
67
+ * @returns {boolean}
68
+ */
69
+ function shouldShowNotice({ isTTY, env = {}, config = {}, now = Date.now() } = {}) {
70
+ if (!isTTY) return false;
71
+ if (env.CI) return false;
72
+ if (env.NO_UPDATE_NOTIFIER) return false;
73
+ if (env.XP_GATE_NO_NOTICE) return false;
74
+
75
+ const notice = config.starNotice;
76
+ if (!notice || typeof notice !== 'object') return true;
77
+
78
+ if (notice.dismissedUntil && now < notice.dismissedUntil) return false;
79
+
80
+ if (notice.lastShownAt) {
81
+ const elapsed = now - notice.lastShownAt;
82
+ // Negative elapsed means the clock moved backwards; let the notice resume.
83
+ if (elapsed >= 0 && elapsed < DAY_MS) return false;
84
+ }
85
+
86
+ return true;
87
+ }
88
+
89
+ /**
90
+ * The config file this module reads and writes.
91
+ *
92
+ * Delegates to the canonical GLOBAL_DIRS.CONFIG_FILE so the notice's state
93
+ * lives beside the tool's other settings instead of in a second, silently
94
+ * diverging file.
95
+ *
96
+ * @returns {string}
97
+ */
98
+ function configFileFor() {
99
+ return CONFIG_FILE;
100
+ }
101
+
102
+ /**
103
+ * Read the config, tolerating a missing or corrupt file.
104
+ *
105
+ * A broken config must never turn into an uncaught throw on a `--version`
106
+ * call, so every failure here degrades to "no config" (which shows the
107
+ * notice at most daily).
108
+ *
109
+ * @param {string} [configFile]
110
+ * @returns {object}
111
+ */
112
+ function readConfig(configFile = configFileFor()) {
113
+ try {
114
+ const parsed = JSON.parse(fs.readFileSync(configFile, 'utf8'));
115
+ return parsed && typeof parsed === 'object' ? parsed : {};
116
+ } catch {
117
+ return {};
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Persist the config.
123
+ *
124
+ * @param {string} configFile
125
+ * @param {object} config
126
+ * @returns {boolean} whether the write succeeded
127
+ */
128
+ function writeConfig(configFile, config) {
129
+ try {
130
+ fs.mkdirSync(require('path').dirname(configFile), { recursive: true });
131
+ fs.writeFileSync(configFile, `${JSON.stringify(config, null, 2)}\n`);
132
+ return true;
133
+ } catch {
134
+ return false;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Record a dismissal so the notice stays silent for DISMISS_DAYS.
140
+ *
141
+ * @param {{configFile?: string, now?: number}} [opts]
142
+ * @returns {boolean} whether the dismissal was persisted
143
+ */
144
+ function dismiss({ configFile = configFileFor(), now = Date.now() } = {}) {
145
+ const config = readConfig(configFile);
146
+ config.starNotice = { ...(config.starNotice || {}), dismissedUntil: now + DISMISS_DAYS * DAY_MS };
147
+ return writeConfig(configFile, config);
148
+ }
149
+
150
+ /**
151
+ * Print the invitation at most once a day, then record that we did.
152
+ *
153
+ * @param {{
154
+ * configFile?: string,
155
+ * force?: boolean,
156
+ * log?: (s: string) => void,
157
+ * env?: Record<string, string|undefined>,
158
+ * isTTY?: boolean,
159
+ * now?: number,
160
+ * }} [opts]
161
+ * @returns {boolean} whether the notice was printed
162
+ */
163
+ function maybeShowStarNotice(opts = {}) {
164
+ const {
165
+ configFile = configFileFor(),
166
+ force = false,
167
+ log = (s) => console.log(s),
168
+ env = process.env,
169
+ isTTY = process.stdout.isTTY,
170
+ now = Date.now(),
171
+ } = opts;
172
+
173
+ // `force` bypasses the frequency and freshness checks and nothing else. It
174
+ // must still honour an explicit opt-out (`--off`, the env switches) and the
175
+ // guards that keep the notice out of logs: a user who asked us to stop has
176
+ // asked regardless of who is forcing.
177
+ const config = readConfig(configFile);
178
+ const optedOut = Boolean(env.CI || env.NO_UPDATE_NOTIFIER || env.XP_GATE_NO_NOTICE)
179
+ || Boolean(config.starNotice && config.starNotice.dismissedUntil && now < config.starNotice.dismissedUntil);
180
+ const eligible = force ? Boolean(isTTY) && !optedOut : shouldShowNotice({ isTTY, env, config, now });
181
+
182
+ if (!eligible || shownInThisProcess) return false;
183
+
184
+ log('');
185
+ log(NOTICE_TEXT);
186
+ shownInThisProcess = true;
187
+
188
+ config.starNotice = { ...(config.starNotice || {}), lastShownAt: now };
189
+ if (!writeConfig(configFile, config)) {
190
+ // The in-process guard alone now holds the promise: it is the only state
191
+ // we can keep for certain, so no further notice appears this run.
192
+ log(`(could not record the notice in ${configFile}; it will not repeat in this run)`);
193
+ }
194
+ return true;
195
+ }
196
+
197
+ /**
198
+ * Offer the README badge after a run where every gate passed.
199
+ *
200
+ * Deliberately silent in more places than the star notice is:
201
+ *
202
+ * - never on a failing run (the markup would be a false claim)
203
+ * - never when the project already carries the badge (it is advice, not news)
204
+ * - never in CI or a pipe, same as the notice
205
+ * - at most once per badge-offer day, tracked separately from the notice, so
206
+ * accepting one does not silence the other
207
+ *
208
+ * @param {{
209
+ * projectRoot?: string,
210
+ * configFile?: string,
211
+ * force?: boolean,
212
+ * log?: (s: string) => void,
213
+ * env?: Record<string, string|undefined>,
214
+ * isTTY?: boolean,
215
+ * now?: number,
216
+ * }} [opts]
217
+ * @returns {boolean} whether the badge was offered
218
+ */
219
+ function maybeOfferBadge(opts = {}) {
220
+ const {
221
+ projectRoot = process.cwd(),
222
+ configFile = configFileFor(),
223
+ force = false,
224
+ log = (s) => console.log(s),
225
+ env = process.env,
226
+ isTTY = process.stdout.isTTY,
227
+ now = Date.now(),
228
+ } = opts;
229
+
230
+ const config = readConfig(configFile);
231
+ const badgeNotice = config.badgeOffer || {};
232
+
233
+ // The badge keeps its OWN clock. Reusing shouldShowNotice would read
234
+ // `starNotice.lastShownAt` -- which the star invitation writes moments earlier
235
+ // in the same run -- and conclude the badge had already been offered. Measured
236
+ // 2026-11-26: the badge never printed after a clean check for exactly this
237
+ // reason, while the star line did.
238
+ //
239
+ // Only the dismiss window is shared: a user who ran `--off` has asked for
240
+ // silence about the project, and that covers both.
241
+ const dismissed = Boolean(config.starNotice
242
+ && config.starNotice.dismissedUntil
243
+ && now < config.starNotice.dismissedUntil);
244
+ const optedOut = Boolean(env.CI || env.NO_UPDATE_NOTIFIER || env.XP_GATE_NO_NOTICE) || dismissed;
245
+
246
+ // `force` bypasses the frequency and freshness checks and nothing else. It
247
+ // must still honour an explicit opt-out and the "already carries it" check:
248
+ // telling someone to claim what they have already claimed is not advice, and
249
+ // forcing it into CI puts the markup in a log nobody reads.
250
+ const eligible = Boolean(isTTY) && !optedOut;
251
+ if (!eligible) return false;
252
+ if (alreadyBadged(projectRoot)) return false;
253
+
254
+ // The frequency check must come BEFORE the first log line: printing and then
255
+ // deciding not to record would show the advice on every run.
256
+ if (!force && badgeNotice.lastShownAt && now - badgeNotice.lastShownAt < DAY_MS) return false;
257
+
258
+ log('');
259
+ log('✅ Every gate passed. Claim it in your README:');
260
+ log(` ${BADGE_MARKDOWN}`);
261
+
262
+ config.badgeOffer = { ...badgeNotice, lastShownAt: now };
263
+ writeConfig(configFile, config);
264
+ return true;
265
+ }
266
+
267
+ /**
268
+ * Whether the project's README already carries the badge.
269
+ *
270
+ * A missing or unreadable README is not an error -- it just means the project
271
+ * has not made the claim, so the offer stands.
272
+ *
273
+ * @param {string} projectRoot
274
+ * @returns {boolean}
275
+ */
276
+ function alreadyBadged(projectRoot) {
277
+ let readme;
278
+ try {
279
+ readme = fs.readFileSync(require('path').join(projectRoot, 'README.md'), 'utf8');
280
+ } catch {
281
+ // A missing README means the project has not made the claim, so the offer
282
+ // stands. An unreadable one (permissions, I/O) is deliberately treated the
283
+ // same: the alternative is to nag forever when the file cannot be read, and
284
+ // the offer is harmless -- it only prints the markup for a human to paste.
285
+ return false;
286
+ }
287
+ // Match the BADGE, not the project. An earlier draft used
288
+ // `readme.includes('boyingliu01/xp-gate')`, which is true of any README that
289
+ // mentions the repo in prose -- "built on boyingliu01/xp-gate", a credits
290
+ // line, a link-back. Those projects were silently treated as already badged
291
+ // and never told how to make the claim they could honestly make.
292
+ //
293
+ // The distinguishing part is the SHIELD IMAGE URL: prose never contains it.
294
+ return readme.includes(BADGE_SHIELD_URL) || readme.includes(BADGE_MARKDOWN);
295
+ }
296
+
297
+ /**
298
+ * Handle the `star-notice` CLI subcommand.
299
+ *
300
+ * @param {string[]} args
301
+ * @returns {number} exit code
302
+ */
303
+ function cli(args = []) {
304
+ if (args.includes('--off')) {
305
+ const ok = dismiss();
306
+ if (ok) {
307
+ console.log(`Star notice disabled for ${DISMISS_DAYS} days.`);
308
+ console.log(`Re-enable any time by deleting starNotice from ${configFileFor()}`);
309
+ return 0;
310
+ }
311
+ console.error(`Could not write ${configFileFor()}`);
312
+ return 1;
313
+ }
314
+ if (args.includes('--status')) {
315
+ const { starNotice = {} } = readConfig();
316
+ const now = Date.now();
317
+ const dismissed = starNotice.dismissedUntil && now < starNotice.dismissedUntil;
318
+ console.log(`Config file: ${configFileFor()}`);
319
+ console.log(`Last shown: ${starNotice.lastShownAt ? new Date(starNotice.lastShownAt).toISOString() : 'never'}`);
320
+ console.log(`Dismissed until: ${dismissed ? new Date(starNotice.dismissedUntil).toISOString() : 'not dismissed'}`);
321
+ return 0;
322
+ }
323
+ console.log('Usage: xp-gate star-notice [--off | --status]');
324
+ console.log(' --off Stop the star invitation for 30 days');
325
+ console.log(' --status Show when it was last shown and whether it is dismissed');
326
+ return 0;
327
+ }
328
+
329
+ module.exports = {
330
+ REPO_URL,
331
+ NOTICE_TEXT,
332
+ DAY_MS,
333
+ DISMISS_DAYS,
334
+ shouldShowNotice,
335
+ configFileFor,
336
+ readConfig,
337
+ writeConfig,
338
+ dismiss,
339
+ maybeShowStarNotice,
340
+ maybeOfferBadge,
341
+ alreadyBadged,
342
+ BADGE_MARKDOWN,
343
+ BADGE_SHIELD_URL,
344
+ resetProcessGuard,
345
+ cli,
346
+ };
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+ /**
3
+ * How one audited tool is shown: its status word, its glyph, and its qualifiers.
4
+ *
5
+ * Split out of `language-tools.js` when that file crossed its line ceiling. The
6
+ * behaviour moved unchanged -- these are pure readers of a row -- and the reasons
7
+ * they exist moved with them.
8
+ */
9
+
10
+ /**
11
+ * Handle check-tools CLI command.
12
+ * @param {string[]} args - Command arguments
13
+ * @returns {Promise<number>} Exit code
14
+ */
15
+ /**
16
+ * Render one audit row as the status the CLI contract uses.
17
+ *
18
+ * A row is unusable for two different reasons and they must not be merged:
19
+ * the probe failed (missing/broken), or the probe could not be interpreted.
20
+ * Both are "not usable", but only the first is "not installed".
21
+ */
22
+ function statusOfRow(row) {
23
+ return row.available ? 'available' : 'missing';
24
+ }
25
+
26
+ /** Icon for a row: present, present-but-flagged, or absent. */
27
+ function iconOfRow(row) {
28
+ if (!row.available) return '✗';
29
+ if (row.duplicated || row.outdated) return '⚠';
30
+ return '✓';
31
+ }
32
+
33
+ /** Extra qualifiers appended to a human line, e.g. "duplicate ×2, 2.14.0 → 2.15.1". */
34
+ function qualifiersOfRow(row) {
35
+ const parts = [];
36
+ if (row.duplicated) parts.push(`DUPLICATE ×${row.distinctRealPaths.length}`);
37
+ if (row.outdated && row.installedVersion && row.latestVersion) {
38
+ parts.push(`${row.installedVersion} → ${row.latestVersion} available`);
39
+ } else if (row.currency === 'unknown') {
40
+ parts.push('version currency unknown');
41
+ }
42
+ // #843: say WHERE the binary was found. "Installed but not on PATH" and
43
+ // "not installed" look identical in a pass/fail column and call for opposite
44
+ // actions -- add it to PATH (or symlink it), versus install it.
45
+ if (row.available && row.resolution === 'fallback' && row.resolvedPath) {
46
+ parts.push(`found at ${row.resolvedPath} (not on PATH)`);
47
+ }
48
+ if (!row.available && row.validityReason) parts.push(row.validityReason);
49
+ return parts.join('; ');
50
+ }
51
+
52
+ module.exports = { statusOfRow, iconOfRow, qualifiersOfRow };