@cbartens/bkit 5.5.1 → 6.1.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 (425) hide show
  1. package/.bkit/README.md +167 -154
  2. package/.bkit/core/.agents/context.md +95 -29
  3. package/.bkit/core/.agents/docs.md +18 -15
  4. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +1 -0
  5. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +6 -5
  6. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-readguard.cjs +1 -0
  7. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-rules.cjs +65 -0
  8. package/.bkit/core/.agents/rules.md +112 -102
  9. package/.bkit/core/.agents/skills.md +63 -15
  10. package/.bkit/core/.bkit/README.md +167 -154
  11. package/.bkit/core/.bkit/authoring.md +747 -0
  12. package/.bkit/core/.bkit/cli.md +407 -0
  13. package/.bkit/core/.bkit/cloud.md +283 -195
  14. package/.bkit/core/.bkit/comparison.md +45 -43
  15. package/.bkit/core/.bkit/install.md +166 -95
  16. package/.bkit/core/.bkit/jsonl.md +339 -196
  17. package/.bkit/core/.bkit/pipeline.md +142 -145
  18. package/.bkit/core/.bkit/prompts.md +295 -264
  19. package/.bkit/core/.bkit/providers.md +460 -277
  20. package/.bkit/core/.bkit/router.md +69 -0
  21. package/.bkit/core/.bkit/templates.md +530 -256
  22. package/.bkit/core/.bkit/trackers.md +116 -65
  23. package/.bkit/core/.bkit/workflows.md +742 -618
  24. package/.bkit/core/.claude/hooks/bkit-gateguard.cjs +2 -2
  25. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +3 -3
  26. package/.bkit/core/.claude/hooks/bkit-preflight.sh +45 -14
  27. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +3 -3
  28. package/.bkit/core/.codex/hooks/bkit-rules.cjs +57 -0
  29. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +7 -7
  30. package/.bkit/core/.cursor/hooks/bkit-preflight.sh +47 -12
  31. package/.bkit/core/.opencode/plugin/bkit-rules.js +89 -0
  32. package/.bkit/core/AGENTS.md +6 -80
  33. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +128 -130
  34. package/.bkit/core/docs/templates/bkit-audit-adoption.md +104 -94
  35. package/.bkit/core/docs/templates/bkit-audit-agents.md +96 -98
  36. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +100 -103
  37. package/.bkit/core/docs/templates/bkit-audit-analytics.md +141 -107
  38. package/.bkit/core/docs/templates/bkit-audit-annotations.md +99 -97
  39. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +122 -121
  40. package/.bkit/core/docs/templates/bkit-audit-app-store.md +158 -101
  41. package/.bkit/core/docs/templates/bkit-audit-architecture.md +114 -96
  42. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +76 -97
  43. package/.bkit/core/docs/templates/bkit-audit-config.md +123 -101
  44. package/.bkit/core/docs/templates/bkit-audit-cost.md +86 -99
  45. package/.bkit/core/docs/templates/bkit-audit-coverage.md +76 -93
  46. package/.bkit/core/docs/templates/bkit-audit-database.md +102 -95
  47. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +165 -108
  48. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +115 -109
  49. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +265 -113
  50. package/.bkit/core/docs/templates/bkit-audit-documentation.md +119 -118
  51. package/.bkit/core/docs/templates/bkit-audit-duplication.md +140 -111
  52. package/.bkit/core/docs/templates/bkit-audit-failures.md +111 -106
  53. package/.bkit/core/docs/templates/bkit-audit-flakes.md +100 -99
  54. package/.bkit/core/docs/templates/bkit-audit-gates.md +107 -103
  55. package/.bkit/core/docs/templates/bkit-audit-issues.md +105 -105
  56. package/.bkit/core/docs/templates/bkit-audit-llm.md +134 -85
  57. package/.bkit/core/docs/templates/bkit-audit-logs.md +124 -125
  58. package/.bkit/core/docs/templates/bkit-audit-models.md +99 -78
  59. package/.bkit/core/docs/templates/bkit-audit-privacy.md +56 -76
  60. package/.bkit/core/docs/templates/bkit-audit-prompts.md +63 -78
  61. package/.bkit/core/docs/templates/bkit-audit-red-team.md +125 -93
  62. package/.bkit/core/docs/templates/bkit-audit-reliability.md +97 -96
  63. package/.bkit/core/docs/templates/bkit-audit-repo.md +170 -98
  64. package/.bkit/core/docs/templates/bkit-audit-security.md +207 -121
  65. package/.bkit/core/docs/templates/bkit-audit-slop.md +78 -95
  66. package/.bkit/core/docs/templates/bkit-audit-testing.md +163 -139
  67. package/.bkit/core/docs/templates/bkit-audit-usability.md +114 -96
  68. package/.bkit/core/docs/templates/bkit-plan.md +158 -281
  69. package/.bkit/core/engine/checks/after/auth.ts +40 -37
  70. package/.bkit/core/engine/checks/after/ci-yml.ts +104 -31
  71. package/.bkit/core/engine/checks/after/github.ts +95 -17
  72. package/.bkit/core/engine/checks/after/index.ts +21 -8
  73. package/.bkit/core/engine/checks/after/suppression.ts +8 -5
  74. package/.bkit/core/engine/checks/after/tools.ts +125 -123
  75. package/.bkit/core/engine/checks/before/context-fetch.ts +227 -33
  76. package/.bkit/core/engine/checks/before/env.ts +3 -3
  77. package/.bkit/core/engine/checks/before/files.ts +5 -4
  78. package/.bkit/core/engine/checks/before/index.ts +25 -1
  79. package/.bkit/core/engine/checks/before/repo.ts +208 -2
  80. package/.bkit/core/engine/checks/status-holes.ts +916 -123
  81. package/.bkit/core/engine/checks/tips/catalogue.ts +82 -20
  82. package/.bkit/core/engine/checks/tips/detect.ts +66 -0
  83. package/.bkit/core/engine/checks/tips/index.ts +52 -11
  84. package/.bkit/core/engine/cli.ts +251 -130
  85. package/.bkit/core/engine/commands/analysis.ts +282 -199
  86. package/.bkit/core/engine/commands/ci/ci.ts +363 -29
  87. package/.bkit/core/engine/commands/ci/pins.ts +172 -0
  88. package/.bkit/core/engine/commands/ci/push-gate.ts +223 -0
  89. package/.bkit/core/engine/commands/comply.ts +77 -103
  90. package/.bkit/core/engine/commands/install/doctor.ts +2 -2
  91. package/.bkit/core/engine/commands/install/install.ts +57 -18
  92. package/.bkit/core/engine/commands/install/uninstall.ts +86 -55
  93. package/.bkit/core/engine/commands/install/upgrade.ts +32 -15
  94. package/.bkit/core/engine/commands/land.ts +139 -18
  95. package/.bkit/core/engine/commands/lib.ts +381 -22
  96. package/.bkit/core/engine/commands/registry.ts +10 -2
  97. package/.bkit/core/engine/commands/setup/setup.ts +8 -7
  98. package/.bkit/core/engine/commands/stats.ts +260 -0
  99. package/.bkit/core/engine/commands/tips.ts +10 -5
  100. package/.bkit/core/engine/commands/workflow/branches.ts +2215 -176
  101. package/.bkit/core/engine/commands/workflow/challenge.ts +748 -0
  102. package/.bkit/core/engine/commands/workflow/completeness.ts +109 -0
  103. package/.bkit/core/engine/commands/workflow/context.ts +1249 -47
  104. package/.bkit/core/engine/commands/workflow/counters.ts +483 -95
  105. package/.bkit/core/engine/commands/workflow/decisions.ts +585 -0
  106. package/.bkit/core/engine/commands/workflow/disk.ts +238 -56
  107. package/.bkit/core/engine/commands/workflow/fids.ts +811 -33
  108. package/.bkit/core/engine/commands/workflow/issues.ts +413 -64
  109. package/.bkit/core/engine/commands/workflow/ledgers.ts +1333 -36
  110. package/.bkit/core/engine/commands/workflow/locks.ts +28 -2
  111. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +691 -0
  112. package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
  113. package/.bkit/core/engine/commands/workflow/plans.ts +257 -0
  114. package/.bkit/core/engine/commands/workflow/prs.ts +178 -33
  115. package/.bkit/core/engine/commands/workflow/repo.ts +66 -8
  116. package/.bkit/core/engine/commands/workflow/roadmap.ts +72 -22
  117. package/.bkit/core/engine/commands/workflow/run-facts.ts +492 -0
  118. package/.bkit/core/engine/commands/workflow/runs.ts +827 -79
  119. package/.bkit/core/engine/commands/workflow/runtime.ts +25 -1
  120. package/.bkit/core/engine/commands/workflow/skills.ts +1 -0
  121. package/.bkit/core/engine/commands/workflow/status.ts +329 -33
  122. package/.bkit/core/engine/commands/workflow/step-table.ts +381 -0
  123. package/.bkit/core/engine/commands/workflow/steps.ts +841 -105
  124. package/.bkit/core/engine/commands/workflow/summary-findings.ts +177 -0
  125. package/.bkit/core/engine/commands/workflow/summary.ts +544 -0
  126. package/.bkit/core/engine/commands/workflow/tasks.ts +409 -0
  127. package/.bkit/core/engine/commands/workflow/test-blocks.ts +254 -0
  128. package/.bkit/core/engine/commands/workflow/tests-changed.ts +201 -0
  129. package/.bkit/core/engine/commands/workflow/tests.ts +2124 -330
  130. package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
  131. package/.bkit/core/engine/commands/workflow/workflows.ts +1197 -235
  132. package/.bkit/core/engine/commands/workflow/worktrees.ts +543 -24
  133. package/.bkit/core/engine/install/cloud-env.ts +251 -121
  134. package/.bkit/core/engine/install/context-ci-workflow.ts +102 -0
  135. package/.bkit/core/engine/install/manifest.ts +67 -17
  136. package/.bkit/core/engine/install/modules/antigravity.ts +3 -2
  137. package/.bkit/core/engine/install/modules/cloud.ts +24 -16
  138. package/.bkit/core/engine/install/modules/codex.ts +15 -2
  139. package/.bkit/core/engine/install/modules/core.ts +1196 -45
  140. package/.bkit/core/engine/install/modules/cursor.ts +6 -6
  141. package/.bkit/core/engine/install/modules/opencode.ts +18 -6
  142. package/.bkit/core/engine/install/template-notes.ts +130 -0
  143. package/.bkit/core/engine/install/version-file.ts +9 -4
  144. package/.bkit/core/engine/install/write.ts +5 -0
  145. package/.bkit/core/engine/ledgers/compact.ts +124 -0
  146. package/.bkit/core/engine/ledgers/journal.ts +291 -0
  147. package/.bkit/core/engine/ledgers/migrate.ts +92 -0
  148. package/.bkit/core/engine/ledgers/status.ts +249 -21
  149. package/.bkit/core/engine/ledgers/telemetry.ts +1397 -253
  150. package/.bkit/core/engine/render/hosts.ts +118 -14
  151. package/.bkit/core/engine/render/models.ts +12 -0
  152. package/.bkit/core/engine/shared/bkit-latest.ts +26 -4
  153. package/.bkit/core/engine/shared/branches.ts +4 -1
  154. package/.bkit/core/engine/shared/dep-updater.ts +60 -0
  155. package/.bkit/core/engine/shared/egress.ts +8 -1
  156. package/.bkit/core/engine/shared/json.ts +25 -7
  157. package/.bkit/core/engine/shared/package-manager.ts +9 -0
  158. package/.bkit/core/engine/shared/settings.ts +243 -31
  159. package/.bkit/core/engine/shared/text.ts +361 -0
  160. package/.bkit/core/engine/shared/timeouts.ts +2 -0
  161. package/.bkit/core/engine/tools/cli-doc.ts +111 -0
  162. package/.bkit/core/engine/tools/grammar-density.ts +215 -0
  163. package/.bkit/core/engine/tools/instructions-sources.ts +832 -0
  164. package/.bkit/core/engine/tools/instructions.ts +1802 -0
  165. package/.bkit/core/hooks/antigravity-hook.js +25 -10
  166. package/.bkit/core/hooks/gateguard-engine.js +54 -29
  167. package/.bkit/core/hooks/guardrails-shell.js +4 -5
  168. package/.bkit/core/hooks/guardrails-tiers.js +10 -4
  169. package/.bkit/core/hooks/preflight-linear.sh +9 -9
  170. package/.bkit/core/hooks/preflight-rules.sh +8 -0
  171. package/.bkit/core/hooks/readguard-engine.js +29 -10
  172. package/.bkit/core/hooks/session-rules-advisory.js +61 -0
  173. package/.bkit/core/prompts/bkit-audit-generate.md +202 -94
  174. package/.bkit/core/prompts/bkit-build-challenge-1.md +76 -34
  175. package/.bkit/core/prompts/bkit-build-challenge-2.md +85 -38
  176. package/.bkit/core/prompts/bkit-build-install-skills.md +50 -28
  177. package/.bkit/core/prompts/bkit-build-plan-convert.md +85 -0
  178. package/.bkit/core/prompts/bkit-build-plan-current.md +59 -36
  179. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +101 -36
  180. package/.bkit/core/prompts/bkit-build-plan-tasks.md +149 -0
  181. package/.bkit/core/prompts/bkit-build-plan-tests.md +120 -0
  182. package/.bkit/core/prompts/bkit-build-plan-verify.md +104 -43
  183. package/.bkit/core/prompts/bkit-debug-abort-handover.md +47 -32
  184. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +109 -57
  185. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +65 -39
  186. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +53 -31
  187. package/.bkit/core/prompts/bkit-debug-failure-soak.md +65 -34
  188. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +46 -31
  189. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +45 -31
  190. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +43 -30
  191. package/.bkit/core/prompts/bkit-design-generate.md +80 -46
  192. package/.bkit/core/prompts/bkit-design-organise.md +83 -32
  193. package/.bkit/core/prompts/bkit-design-review-1.md +70 -50
  194. package/.bkit/core/prompts/bkit-design-review-2.md +65 -46
  195. package/.bkit/core/prompts/bkit-design-spike.md +64 -40
  196. package/.bkit/core/prompts/bkit-design-update.md +53 -28
  197. package/.bkit/core/prompts/bkit-plan-generate.md +101 -29
  198. package/.bkit/core/prompts/bkit-plan-review-1.md +78 -41
  199. package/.bkit/core/prompts/bkit-plan-review-2.md +78 -35
  200. package/.bkit/core/prompts/bkit-plan-scope-check.md +116 -0
  201. package/.bkit/core/prompts/bkit-plan-update.md +86 -31
  202. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +94 -50
  203. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +91 -41
  204. package/.bkit/core/prompts/bkit-ship-update-docs.md +45 -24
  205. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +65 -49
  206. package/.bkit/core/prompts/bkit-utility-update-decisions.md +87 -42
  207. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +81 -37
  208. package/.bkit/core/prompts/bkit-utility-update-documentation.md +43 -25
  209. package/.bkit/core/prompts/bkit-utility-update-failures.md +84 -37
  210. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +88 -42
  211. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +92 -39
  212. package/.bkit/core/prompts/bkit-utility-update-tracker.md +159 -60
  213. package/.bkit/core/workflows/bkit-auto.md +89 -58
  214. package/.bkit/core/workflows/bkit-build.md +967 -517
  215. package/.bkit/core/workflows/bkit-debug.md +555 -387
  216. package/.bkit/core/workflows/bkit-design.md +319 -283
  217. package/.bkit/core/workflows/bkit-plan.md +319 -342
  218. package/.bkit/core/workflows/bkit-ship.md +525 -328
  219. package/.bkit/shared/.agents/plugins/bkit/hooks.json +10 -0
  220. package/.bkit/shared/.bkit/.env.example +2 -2
  221. package/.bkit/shared/.claude/bkit-cloud.md +12 -10
  222. package/.bkit/shared/.claude/settings.json +14 -0
  223. package/.bkit/shared/.codex/bkit-cloud.md +98 -0
  224. package/.bkit/shared/.codex/hooks.json +20 -0
  225. package/.bkit/shared/.cursor/bkit-cloud.md +3 -3
  226. package/.bkit/shared/.cursor/mcp.json +1 -1
  227. package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
  228. package/.bkit/shared/.gitattributes +1 -1
  229. package/.bkit/shared/.mcp.json +1 -1
  230. package/.bkit/shared/.opencode/opencode.json +12 -1
  231. package/.bkit/shared/CLAUDE.md +6 -2
  232. package/.bkit/shared/GEMINI.md +5 -2
  233. package/.bkit/shared/docs/architecture.md +4 -7
  234. package/.bkit/shared/docs/data-schema.md +4 -7
  235. package/.bkit/shared/docs/deployments.md +241 -168
  236. package/.bkit/shared/docs/design.md +11 -12
  237. package/.bkit/shared/docs/noise.md +8 -7
  238. package/.bkit/shared/docs/observability.md +5 -8
  239. package/.bkit/shared/docs/security.md +35 -17
  240. package/.bkit/shared/docs/setup.md +29 -18
  241. package/.bkit/shared/docs/technology.md +3 -6
  242. package/.bkit/shared/docs/testing.md +289 -174
  243. package/.bkit/shared/gitignore +6 -2
  244. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +15 -16
  245. package/.bkit/templates/.cursor/Dockerfile +12 -8
  246. package/.bkit/templates/.cursor/environment.json +1 -1
  247. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +10 -8
  248. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +45 -12
  249. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +3 -3
  250. package/.bkit/templates/.github/renovate.json5 +34 -6
  251. package/.bkit/templates/.github/workflows/bkit-ci.yml +54 -51
  252. package/.bkit/templates/.github/workflows/bkit-cloud.yml +34 -33
  253. package/.bkit/templates/.github/workflows/bkit-health.yml +97 -0
  254. package/.bkit/templates/.github/workflows/bkit-renovate.yml +5 -4
  255. package/.bkit/templates/.github/workflows/bkit-trivy.yml +5 -4
  256. package/.bkit/templates/.husky/pre-commit +2 -2
  257. package/.bkit/templates/.husky/pre-push +96 -36
  258. package/.bkit/templates/.prettierignore +6 -0
  259. package/.bkit/templates/.vale.ini +27 -27
  260. package/.bkit/templates/context/bkit-cloudrun.md +23 -15
  261. package/.bkit/templates/context/bkit-expo.md +70 -52
  262. package/.bkit/templates/context/bkit-github.md +93 -56
  263. package/.bkit/templates/context/bkit-inngest.md +21 -15
  264. package/.bkit/templates/context/bkit-maestro.md +22 -16
  265. package/.bkit/templates/context/bkit-playwright.md +23 -17
  266. package/.bkit/templates/context/bkit-resend.md +12 -10
  267. package/.bkit/templates/context/bkit-sentry.md +30 -20
  268. package/.bkit/templates/context/bkit-serena.md +8 -7
  269. package/.bkit/templates/context/bkit-stripe.md +14 -13
  270. package/.bkit/templates/context/bkit-supabase.md +16 -13
  271. package/.bkit/templates/context/bkit-tavily.md +14 -11
  272. package/.bkit/templates/context/bkit-vercel.md +27 -18
  273. package/.bkit/templates/docs/capabilities.md +15 -14
  274. package/.bkit/templates/scripts/ci/{check-accepted-divergences.mjs → bkit-check-accepted-divergences.mjs} +6 -3
  275. package/.bkit/templates/scripts/ci/{check-accepted-divergences.test.mjs → bkit-check-accepted-divergences.test.mjs} +3 -3
  276. package/.bkit/templates/scripts/ci/{check-capstone.mjs → bkit-check-capstone.mjs} +2 -2
  277. package/.bkit/templates/scripts/ci/{check-capstone.test.mjs → bkit-check-capstone.test.mjs} +4 -4
  278. package/.bkit/templates/scripts/ci/{check-dependency-audit.mjs → bkit-check-dependency-audit.mjs} +103 -18
  279. package/.bkit/templates/scripts/ci/{check-dependency-audit.test.mjs → bkit-check-dependency-audit.test.mjs} +31 -3
  280. package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +387 -0
  281. package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +75 -0
  282. package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +160 -0
  283. package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.mjs → bkit-resolve-push-base.mjs} +3 -3
  284. package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.test.mjs → bkit-resolve-push-base.test.mjs} +4 -4
  285. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +10 -2
  286. package/.bkit/templates/scripts/graphify/bkit-graph-drift.py +1 -1
  287. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +3 -3
  288. package/.bkit/templates/scripts/graphify/bkit-graph-embed.py +63 -0
  289. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +2 -2
  290. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +69 -18
  291. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -3
  292. package/.bkit/templates/scripts/graphify/bkit-graph-surface.py +1 -1
  293. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
  294. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +197 -126
  295. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +64 -41
  296. package/.bkit/templates/scripts/slop/bkit-slop-type-suppression.mjs +23 -7
  297. package/.bkit/templates/slop-scan.config.json +9 -2
  298. package/CHANGELOG.md +231 -0
  299. package/README.md +278 -89
  300. package/dist/checks/after/auth.js +36 -33
  301. package/dist/checks/after/ci-yml.js +91 -30
  302. package/dist/checks/after/github.js +91 -17
  303. package/dist/checks/after/index.js +22 -11
  304. package/dist/checks/after/suppression.js +8 -5
  305. package/dist/checks/after/tools.js +111 -114
  306. package/dist/checks/before/context-fetch.js +218 -33
  307. package/dist/checks/before/env.js +3 -3
  308. package/dist/checks/before/files.js +5 -3
  309. package/dist/checks/before/index.js +20 -3
  310. package/dist/checks/before/repo.js +197 -2
  311. package/dist/checks/status-holes.js +739 -114
  312. package/dist/checks/tips/catalogue.js +70 -19
  313. package/dist/checks/tips/detect.js +62 -0
  314. package/dist/checks/tips/index.js +51 -9
  315. package/dist/cli.js +234 -124
  316. package/dist/commands/analysis.js +174 -141
  317. package/dist/commands/ci/ci.js +302 -25
  318. package/dist/commands/ci/pins.js +142 -0
  319. package/dist/commands/ci/push-gate.js +194 -0
  320. package/dist/commands/comply.js +54 -91
  321. package/dist/commands/install/doctor.js +2 -2
  322. package/dist/commands/install/install.js +50 -19
  323. package/dist/commands/install/uninstall.js +82 -55
  324. package/dist/commands/install/upgrade.js +21 -11
  325. package/dist/commands/land.js +137 -17
  326. package/dist/commands/lib.js +295 -21
  327. package/dist/commands/registry.js +10 -2
  328. package/dist/commands/setup/setup.js +8 -7
  329. package/dist/commands/stats.js +175 -0
  330. package/dist/commands/tips.js +7 -3
  331. package/dist/commands/workflow/branches.js +1873 -152
  332. package/dist/commands/workflow/challenge.js +609 -0
  333. package/dist/commands/workflow/completeness.js +97 -0
  334. package/dist/commands/workflow/context.js +1045 -46
  335. package/dist/commands/workflow/counters.js +385 -86
  336. package/dist/commands/workflow/decisions.js +484 -0
  337. package/dist/commands/workflow/disk.js +214 -56
  338. package/dist/commands/workflow/fids.js +706 -33
  339. package/dist/commands/workflow/issues.js +349 -59
  340. package/dist/commands/workflow/ledgers.js +1123 -37
  341. package/dist/commands/workflow/locks.js +26 -2
  342. package/dist/commands/workflow/plan-blocks.js +501 -0
  343. package/dist/commands/workflow/plan-versions.js +22 -0
  344. package/dist/commands/workflow/plans.js +205 -0
  345. package/dist/commands/workflow/prs.js +154 -35
  346. package/dist/commands/workflow/repo.js +58 -8
  347. package/dist/commands/workflow/roadmap.js +58 -23
  348. package/dist/commands/workflow/run-facts.js +421 -0
  349. package/dist/commands/workflow/runs.js +670 -72
  350. package/dist/commands/workflow/runtime.js +15 -1
  351. package/dist/commands/workflow/skills.js +1 -0
  352. package/dist/commands/workflow/status.js +282 -34
  353. package/dist/commands/workflow/step-table.js +308 -0
  354. package/dist/commands/workflow/steps.js +703 -96
  355. package/dist/commands/workflow/summary-findings.js +117 -0
  356. package/dist/commands/workflow/summary.js +388 -0
  357. package/dist/commands/workflow/tasks.js +378 -0
  358. package/dist/commands/workflow/test-blocks.js +231 -0
  359. package/dist/commands/workflow/tests-changed.js +172 -0
  360. package/dist/commands/workflow/tests.js +1695 -305
  361. package/dist/commands/workflow/tracker.js +983 -0
  362. package/dist/commands/workflow/workflows.js +1014 -222
  363. package/dist/commands/workflow/worktrees.js +432 -26
  364. package/dist/install/cloud-env.js +233 -99
  365. package/dist/install/context-ci-workflow.js +85 -0
  366. package/dist/install/manifest.js +64 -17
  367. package/dist/install/modules/antigravity.js +3 -2
  368. package/dist/install/modules/cloud.js +25 -16
  369. package/dist/install/modules/codex.js +12 -2
  370. package/dist/install/modules/core.js +1090 -48
  371. package/dist/install/modules/cursor.js +6 -6
  372. package/dist/install/modules/opencode.js +13 -7
  373. package/dist/install/template-notes.js +116 -0
  374. package/dist/install/version-file.js +9 -4
  375. package/dist/ledgers/compact.js +87 -0
  376. package/dist/ledgers/journal.js +233 -0
  377. package/dist/ledgers/migrate.js +81 -0
  378. package/dist/ledgers/status.js +176 -13
  379. package/dist/ledgers/telemetry.js +1010 -125
  380. package/dist/render/hosts.js +104 -14
  381. package/dist/render/models.js +12 -0
  382. package/dist/shared/bkit-latest.js +26 -4
  383. package/dist/shared/branches.js +3 -1
  384. package/dist/shared/dep-updater.js +49 -0
  385. package/dist/shared/egress.js +8 -1
  386. package/dist/shared/json.js +20 -7
  387. package/dist/shared/package-manager.js +6 -0
  388. package/dist/shared/settings.js +181 -24
  389. package/dist/shared/text.js +333 -0
  390. package/dist/shared/timeouts.js +2 -0
  391. package/dist/tools/cli-doc.js +97 -0
  392. package/dist/tools/grammar-density.js +183 -0
  393. package/dist/tools/instructions-sources.js +720 -0
  394. package/dist/tools/instructions.js +1623 -0
  395. package/package.json +156 -51
  396. package/.bkit/core/.bkit/lite.md +0 -73
  397. package/.bkit/core/engine/commands/harvest.ts +0 -459
  398. package/.bkit/core/engine/commands/workflow/workstreams.ts +0 -166
  399. package/.bkit/core/engine/tools/wording.ts +0 -748
  400. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
  401. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
  402. package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
  403. package/.bkit/core/prompts/bkit-build-plan-execute.md +0 -76
  404. package/.bkit/core/prompts/bkit-build-summary.md +0 -94
  405. package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
  406. package/.bkit/core/prompts/bkit-design-summary.md +0 -107
  407. package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
  408. package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
  409. package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
  410. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
  411. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
  412. package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
  413. package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
  414. package/.bkit/templates/scripts/ci/bkit-local-stack-lock.sh +0 -194
  415. package/dist/commands/harvest.js +0 -353
  416. package/dist/commands/workflow/workstreams.js +0 -143
  417. package/dist/tools/wording.js +0 -680
  418. /package/.bkit/templates/.vale/styles/{House → Bkit}/Filler.yml +0 -0
  419. /package/.bkit/templates/.vale/styles/{House → Bkit}/Hedging.yml +0 -0
  420. /package/.bkit/templates/.vale/styles/{House → Bkit}/LLMSlop.yml +0 -0
  421. /package/.bkit/templates/.vale/styles/{House → Bkit}/Verbose.yml +0 -0
  422. /package/.bkit/templates/scripts/ci/{accepted-advisories.json → bkit-accepted-advisories.json} +0 -0
  423. /package/.bkit/templates/scripts/ci/{accepted-divergences.json → bkit-accepted-divergences.json} +0 -0
  424. /package/.bkit/templates/scripts/launchd/{launchd.env.example → bkit-launchd.env.example} +0 -0
  425. /package/.bkit/templates/scripts/launchd/{ai.bkit.launchd.plist → bkit-launchd.plist} +0 -0
@@ -10,20 +10,32 @@ import {
10
10
  writeBkitVersion,
11
11
  hashFile,
12
12
  mergeCanonicalHashes,
13
+ sha256,
13
14
  } from "../version-file.js";
14
- import { extractManagedBlock, stripManagedBlock } from "../managed-block.js";
15
+ import {
16
+ extractManagedBlock,
17
+ findLineAnchoredMarkers,
18
+ selectMarkers,
19
+ stripManagedBlock,
20
+ } from "../managed-block.js";
15
21
  import type { TokenMap } from "../placeholders.js";
16
22
  import { listFilesRecursive, syncTemplateCopies } from "../template-copies.js";
17
23
  import { PAYLOAD_LINK_RELPATHS, syncPayloadLinks } from "../payload-links.js";
18
24
  import { writeNetworkAllowlist } from "../network-allowlist.js";
25
+ import { migrateContextCiWorkflow } from "../context-ci-workflow.js";
26
+ import { migrateTemplateNotes } from "../template-notes.js";
19
27
  import type { PreflightFinding } from "../../checks/before/index.js";
28
+ import { isAdvisorySuppressed } from "../../checks/after/suppression.js";
20
29
  import { parseJson, readJsonFile } from "../../shared/json.js";
21
30
  import { readInstallingVersion } from "../../shared/package-json.js";
22
- import { CONFIG_DEFAULTS } from "../../shared/settings.js";
31
+ import { detectDepUpdater, type DepUpdater } from "../../shared/dep-updater.js";
32
+ import { ASK_POINTS, CONFIG_DEFAULTS, ciWorkflowPath, limitKey } from "../../shared/settings.js";
33
+ import { CI_SCRIPT_UNITS } from "../../checks/after/ci-yml.js";
23
34
  import {
24
35
  getCoreRoot,
25
36
  getSharedRoot,
26
37
  getBkitDocsRoot,
38
+ getTemplatesRoot,
27
39
  TEMPLATE_COPIES_DIR,
28
40
  } from "../../shared/package-roots.js";
29
41
  import {
@@ -31,8 +43,11 @@ import {
31
43
  BKIT_GATE_SCRIPTS,
32
44
  BKIT_OPTIONAL_GATES,
33
45
  BKIT_PUSH_GATES,
46
+ BKIT_GATE_CHANGED_SCRIPT,
47
+ BKIT_LINT_FILE_SCRIPT,
34
48
  BKIT_TEST_FILE_SCRIPT,
35
49
  } from "../manifest.js";
50
+ import { migrateLedgers } from "../../ledgers/migrate.js";
36
51
  import type { ModuleContext } from "./index.js";
37
52
 
38
53
  export function listMdFiles(dir: string, prefix?: string): string[] {
@@ -249,25 +264,39 @@ function runCoreTemplates(
249
264
  // in-repo without spelunking node_modules. Force-overwritten (Tier 1) — bkit owns
250
265
  // them, so a consumer edit is replaced. Source of truth is the package's own
251
266
  // `.bkit/core/.bkit/<name>`. (`advisories.md` is a regenerated runtime artifact and
252
- // `wording.md` is repo-only tooling — neither belongs here. `LICENSE.md` is the MIT
267
+ // `instructions.md` is repo-only tooling — neither belongs here. `LICENSE.md` is the MIT
253
268
  // notice that travels with the files bkit writes: MIT requires the copyright and
254
269
  // permission notice in every copy.)
255
270
  export const BKIT_CANONICAL_DOCS = [
271
+ "authoring.md",
256
272
  "cloud.md",
273
+ "cli.md",
257
274
  "comparison.md",
258
275
  "install.md",
259
276
  "jsonl.md",
260
277
  "LICENSE.md",
261
- "lite.md",
262
278
  "pipeline.md",
263
279
  "providers.md",
264
280
  "prompts.md",
281
+ "router.md",
265
282
  "templates.md",
266
283
  "trackers.md",
267
284
  "workflows.md",
268
285
  "README.md",
269
286
  ] as const;
270
287
 
288
+ // The token map for `.bkit/*.md` docs: only `{{BKIT_MANAGED_MARKER}}` resolves. The other
289
+ // tokens map to themselves, so a doc that tells the consumer which token to replace in a
290
+ // template (`templates.md`) still names the token.
291
+ export function bkitDocTokens(tokens: TokenMap): TokenMap {
292
+ return {
293
+ ...tokens,
294
+ DEFAULT_BRANCH: "{{DEFAULT_BRANCH}}",
295
+ PROJECT_NAME: "{{PROJECT_NAME}}",
296
+ REPO_SLUG: "{{REPO_SLUG}}",
297
+ };
298
+ }
299
+
271
300
  // Mirror the package's canonical `.bkit/*.md` docs into the consumer's `.bkit/`.
272
301
  // Tier 1 (force-overwrite + ws-tracked for dry-run/install parity). Each source carries
273
302
  // the `{{BKIT_MANAGED_MARKER}}` token. Skipped in dogfood: the consumer destination
@@ -280,6 +309,7 @@ export function runBkitDocs(
280
309
  ): void {
281
310
  const tag = dryRun ? "[dry-run] " : "";
282
311
  const docsRoot = getBkitDocsRoot();
312
+ const docTokens = bkitDocTokens(tokens);
283
313
  // Per-doc write strategy from the manifest: markered-text docs (e.g. prompts.md,
284
314
  // which carries the consumer-owned `## Model Overrides` section below `bkit:end`)
285
315
  // are block-merged so consumer content survives; the rest are force-overwritten.
@@ -292,53 +322,174 @@ export function runBkitDocs(
292
322
  const dstPath = path.join(".bkit", name);
293
323
  const prevLen = ws.writes.length;
294
324
  if (formatByPath.get(path.join(".bkit", name)) === "markered-text") {
295
- writeTier2(srcPath, dstPath, tokens, "html-comment", dryRun, ws);
325
+ writeTier2(srcPath, dstPath, docTokens, "html-comment", dryRun, ws);
296
326
  } else {
297
- writeTier1(srcPath, dstPath, tokens, dryRun, ws);
327
+ writeTier1(srcPath, dstPath, docTokens, dryRun, ws);
298
328
  }
299
329
  if (ws.writes.length > prevLen) {
300
330
  console.log(`${logPrefix} ${tag}core: ${dstPath}`);
301
331
  }
302
332
  }
303
- migrateShortcutsToLite(dryRun, ws, logPrefix);
333
+ migrateRetiredLite(dryRun, ws, logPrefix);
304
334
  migrateRetiredDevLock(dryRun, ws, logPrefix);
335
+ migrateLedgerSchema(dryRun, ws, logPrefix);
336
+ migrateJiraKeyName(dryRun, logPrefix);
337
+ migrateModelOverrideAgentNames(dryRun, ws, logPrefix);
338
+ migrateTemplateNotes(dryRun, ws, logPrefix);
339
+ migrateContextCiWorkflow(dryRun, ws, logPrefix);
340
+ migrateSlopTypeSuppression(dryRun, ws, logPrefix);
341
+ const renames = migrateBrandedTemplateFiles(dryRun, ws, logPrefix);
342
+ migrateBrandedFileTokens(dryRun, ws, logPrefix, renames);
343
+ migrateBrandedCheckNames(dryRun, ws, logPrefix, tokens.DEFAULT_BRANCH);
344
+ migrateValeHouseStyle(dryRun, ws, logPrefix);
345
+ }
346
+
347
+ // Migration (installs up to 6.0.x, `docs/migrations.md`): agents renamed since. A
348
+ // consumer's `## Model Overrides` row below `bkit:end` in `.bkit/prompts.md` naming an
349
+ // old agent is renamed in place, provider and model kept, so the override keeps applying
350
+ // (`parseModelOverrides` reports a row naming no agent as unknown and skips it). Runs
351
+ // after the docs loop, which block-merges the file and leaves the consumer region alone.
352
+ // A row already naming the new agent wins: the old row is then left for the unknown
353
+ // report. Recorded in ws as an update; the canonical hash covers the managed block only.
354
+ const PROMPTS_FILE = path.join(".bkit", "prompts.md");
355
+ const MODEL_OVERRIDES_HEADING = "## Model Overrides";
356
+ export const RENAMED_AGENTS: Readonly<Record<string, string>> = {
357
+ "bkit-build-plan-execute": "bkit-build-plan-tasks",
358
+ };
359
+
360
+ export function migrateModelOverrideAgentNames(
361
+ dryRun: boolean,
362
+ ws: WriteSet,
363
+ logPrefix: string,
364
+ ): void {
365
+ if (!fs.existsSync(PROMPTS_FILE)) return;
366
+ const text = fs.readFileSync(PROMPTS_FILE, "utf-8");
367
+ const endIdx = findLineAnchoredMarkers(text, selectMarkers("html-comment")[1])[0];
368
+ if (endIdx === undefined) return;
369
+ const headingAt = text.indexOf(MODEL_OVERRIDES_HEADING, endIdx);
370
+ if (headingAt === -1) return;
371
+ const head = text.slice(0, headingAt);
372
+ const lines = text.slice(headingAt).split("\n");
373
+ // The first cell of a table row, backticks and padding aside.
374
+ const promptCell = (line: string): string | undefined =>
375
+ /^\s*\|/.test(line) ? line.split("|")[1]?.trim().replace(/^`|`$/g, "") : undefined;
376
+ const named = new Set(lines.map(promptCell).filter((c): c is string => c !== undefined));
377
+ const renamed: string[] = [];
378
+ const out = lines.map((line) => {
379
+ const cell = promptCell(line);
380
+ const to = cell === undefined ? undefined : RENAMED_AGENTS[cell];
381
+ if (cell === undefined || to === undefined || named.has(to)) return line;
382
+ renamed.push(`${cell} -> ${to}`);
383
+ return line.replace(cell, to);
384
+ });
385
+ if (renamed.length === 0) return;
386
+ if (!dryRun) fs.writeFileSync(PROMPTS_FILE, head + out.join("\n"), "utf-8");
387
+ ws.writes.push({ path: PROMPTS_FILE, action: "update" });
388
+ console.log(
389
+ `${logPrefix} ${dryRun ? "[dry-run] " : ""}core: ${PROMPTS_FILE} — Model Overrides renamed: ${renamed.join(", ")}`,
390
+ );
391
+ }
392
+
393
+ // Migration (installs up to 5.5.x, `docs/migrations.md`): the Jira key was
394
+ // `BKIT_JIRA_API_TOKEN`; the engine and the MCP configs now read `BKIT_JIRA_API_KEY`.
395
+ // `.bkit/.env` lines naming the old key are renamed in place, value kept. Logged only,
396
+ // never recorded in ws: a ws write gets a canonical hash, and a secrets file never does.
397
+ // A file already naming the new key is left alone.
398
+ const ENV_FILE = path.join(".bkit", ".env");
399
+ const OLD_JIRA_KEY = "BKIT_JIRA_API_TOKEN";
400
+ const NEW_JIRA_KEY = "BKIT_JIRA_API_KEY";
401
+
402
+ export function migrateJiraKeyName(dryRun: boolean, logPrefix: string): void {
403
+ if (!fs.lstatSync(ENV_FILE, { throwIfNoEntry: false })?.isFile()) return;
404
+ const text = fs.readFileSync(ENV_FILE, "utf-8");
405
+ const assigns = (key: string) => new RegExp(`^\\s*(export\\s+)?${key}=`, "m").test(text);
406
+ if (!assigns(OLD_JIRA_KEY) || assigns(NEW_JIRA_KEY)) return;
407
+ if (!dryRun) fs.writeFileSync(ENV_FILE, text.split(OLD_JIRA_KEY).join(NEW_JIRA_KEY), "utf-8");
408
+ console.log(
409
+ `${logPrefix} ${dryRun ? "[dry-run] " : ""}core: ${ENV_FILE} — ${OLD_JIRA_KEY} renamed to ${NEW_JIRA_KEY}`,
410
+ );
305
411
  }
306
412
 
307
- // Migration (5.1.0 – 5.2.4 installs, `docs/migrations.md`): the lite workflows lived at
308
- // `.agents/shortcuts.md`. The consumer's own lines below `bkit:end` (minus the seeded
309
- // heading) move under `.bkit/lite.md`'s consumer section; the old file is deleted. Runs
310
- // after the docs loop, so `.bkit/lite.md` is already written. The delete is recorded in
311
- // ws (as orphan-mirror deletes are) so `bkit check` fails until upgrade runs.
413
+ // Migration (5.1.0 – 6.0.x installs, `docs/migrations.md`): the lite workflows are retired.
414
+ // The managed block of `.bkit/lite.md` (and of its 5.1.0 – 5.2.4 predecessor
415
+ // `.agents/shortcuts.md`) is stripped; the consumer's own lines (minus the seeded headings)
416
+ // land in `.bkit/lite.md` under a sentinel first line, or the file is deleted when none
417
+ // remain. A file holding the sentinel and no managed block is the already-retired stub:
418
+ // silent, no write. A blockless or multi-block `.bkit/lite.md` is left byte-for-byte with
419
+ // a logged fix. Writes are recorded in ws (dry-run parity; `bkit check` fails until upgrade).
420
+ export const RETIRED_LITE_STUB_SENTINEL = "<!-- bkit:retired-lite-stub -->";
312
421
  const RETIRED_SHORTCUTS = path.join(".agents", "shortcuts.md");
313
422
  const RETIRED_SHORTCUTS_HEADING = "## Project Shortcuts";
423
+ const RETIRED_LITE = path.join(".bkit", "lite.md");
424
+ const RETIRED_LITE_HEADING = "## Project Lite Workflows";
314
425
 
315
- export function migrateShortcutsToLite(dryRun: boolean, ws: WriteSet, logPrefix: string): void {
316
- if (!fs.existsSync(RETIRED_SHORTCUTS)) return;
317
- if (!fs.existsSync(path.join(getBkitDocsRoot(), "lite.md"))) return;
318
- const tag = dryRun ? "[dry-run] " : "";
319
- const dst = path.join(".bkit", "lite.md");
320
- const old = fs.readFileSync(RETIRED_SHORTCUTS, "utf-8");
321
- if (extractManagedBlock(old, "html-comment") === null) {
322
- console.warn(
323
- `${logPrefix} ${RETIRED_SHORTCUTS} has no single bkit managed block — left in place. Move your own lines into ${dst} below \`<!-- bkit:end -->\`, then delete it.`,
324
- );
325
- return;
326
- }
327
- const own = stripManagedBlock(old, "html-comment")
328
- .split("\n")
329
- .filter((line) => line.trim() !== RETIRED_SHORTCUTS_HEADING)
426
+ /** The consumer lines left once the managed block and the given seeded heading are removed. */
427
+ function consumerLines(text: string, heading: string): string {
428
+ const lines = stripManagedBlock(text, "html-comment").split("\n");
429
+ return lines
430
+ .filter((line) => line.trim() !== heading)
330
431
  .join("\n")
331
432
  .trim();
332
- if (own.length > 0) {
333
- if (!dryRun) {
334
- const current = fs.readFileSync(dst, "utf-8");
335
- fs.writeFileSync(dst, `${current.replace(/\n*$/, "\n\n")}${own}\n`, "utf-8");
433
+ }
434
+
435
+ export function migrateRetiredLite(dryRun: boolean, ws: WriteSet, logPrefix: string): void {
436
+ const hasShortcuts = fs.existsSync(RETIRED_SHORTCUTS);
437
+ const hasLite = fs.existsSync(RETIRED_LITE);
438
+ if (!hasShortcuts && !hasLite) return;
439
+ const tag = dryRun ? "[dry-run] " : "";
440
+
441
+ let liteOwn = "";
442
+ let liteIsManaged = false;
443
+ if (hasLite) {
444
+ const lite = fs.readFileSync(RETIRED_LITE, "utf-8");
445
+ if (extractManagedBlock(lite, "html-comment") !== null) {
446
+ liteIsManaged = true;
447
+ liteOwn = consumerLines(lite, RETIRED_LITE_HEADING);
448
+ } else if (lite.split("\n")[0]?.trim() === RETIRED_LITE_STUB_SENTINEL) {
449
+ liteOwn = lite.slice(lite.indexOf("\n") + 1).trim();
450
+ } else {
451
+ console.warn(
452
+ `${logPrefix} ${RETIRED_LITE} has no single bkit managed block — left in place. The lite workflows are retired: keep your own lines in it (or in your own docs) and delete any leftover bkit-managed text.`,
453
+ );
454
+ return;
455
+ }
456
+ }
457
+
458
+ let shortcutsOwn = "";
459
+ let shortcutsMovable = false;
460
+ if (hasShortcuts) {
461
+ const old = fs.readFileSync(RETIRED_SHORTCUTS, "utf-8");
462
+ if (extractManagedBlock(old, "html-comment") === null) {
463
+ console.warn(
464
+ `${logPrefix} ${RETIRED_SHORTCUTS} has no single bkit managed block — left in place. Move your own lines into ${RETIRED_LITE}, then delete it.`,
465
+ );
466
+ } else {
467
+ shortcutsMovable = true;
468
+ shortcutsOwn = consumerLines(old, RETIRED_SHORTCUTS_HEADING);
469
+ }
470
+ }
471
+
472
+ const own = [liteOwn, shortcutsOwn].filter((part) => part.length > 0).join("\n\n");
473
+ const stubText = `${RETIRED_LITE_STUB_SENTINEL}\n\n${own}\n`;
474
+ const liteChanges = liteIsManaged || (own.length > 0 && shortcutsOwn.length > 0);
475
+ if (liteChanges) {
476
+ if (own.length > 0) {
477
+ if (!dryRun) {
478
+ fs.mkdirSync(path.dirname(RETIRED_LITE), { recursive: true });
479
+ fs.writeFileSync(RETIRED_LITE, stubText, "utf-8");
480
+ }
481
+ ws.writes.push({ path: RETIRED_LITE, action: hasLite ? "update" : "write" });
482
+ } else if (hasLite) {
483
+ if (!dryRun) fs.rmSync(RETIRED_LITE);
484
+ ws.writes.push({ path: RETIRED_LITE, action: "write" });
336
485
  }
337
- ws.writes.push({ path: dst, action: "update" });
486
+ console.log(`${logPrefix} ${tag}core: retired ${RETIRED_LITE}`);
487
+ }
488
+ if (shortcutsMovable) {
489
+ if (!dryRun) fs.rmSync(RETIRED_SHORTCUTS);
490
+ ws.writes.push({ path: RETIRED_SHORTCUTS, action: "write" });
491
+ console.log(`${logPrefix} ${tag}core: retired ${RETIRED_SHORTCUTS}`);
338
492
  }
339
- if (!dryRun) fs.rmSync(RETIRED_SHORTCUTS);
340
- ws.writes.push({ path: RETIRED_SHORTCUTS, action: "write" });
341
- console.log(`${logPrefix} ${tag}core: moved ${RETIRED_SHORTCUTS} → ${dst}`);
342
493
  }
343
494
 
344
495
  // Migration (installs up to 5.3.x, `docs/migrations.md`): `.bkit/.dev.lock` was the
@@ -355,6 +506,20 @@ export function migrateRetiredDevLock(dryRun: boolean, ws: WriteSet, logPrefix:
355
506
  );
356
507
  }
357
508
 
509
+ // Migration (installs up to 5.5.x, `docs/migrations.md`): ledger rows written before
510
+ // `schema: 2` are rewritten into the current shape (`.bkit/jsonl.md` § Generic Fields).
511
+ // Recorded in ws so `bkit check` fails until upgrade runs; ledgers never get a
512
+ // canonical hash (`mergeCanonicalHashes`).
513
+ export function migrateLedgerSchema(dryRun: boolean, ws: WriteSet, logPrefix: string): void {
514
+ for (const { file, rewritten, dropped } of migrateLedgers(process.cwd(), dryRun)) {
515
+ ws.writes.push({ path: file, action: "update" });
516
+ const copies = dropped > 0 ? `, ${dropped} old copy(ies) of rewritten rows dropped` : "";
517
+ console.log(
518
+ `${logPrefix} ${dryRun ? "[dry-run] " : ""}core: ${file} — ${rewritten} row(s) rewritten to schema 2${copies}`,
519
+ );
520
+ }
521
+ }
522
+
358
523
  // ---------------------------------------------------------------------------
359
524
  // Source-rendered host outputs — agents (.agents/prompts source) and commands
360
525
  // (.bkit/workflows source). Extracted from the host module functions so BOTH
@@ -389,10 +554,13 @@ export function seedCorePackageJsonScripts(
389
554
  const tag = dryRun ? "[dry-run] " : "";
390
555
  const written: string[] = [];
391
556
 
557
+ if (migrateBrandedScriptNames(dryRun, ws, logPrefix)) written.push("package.json");
392
558
  const gates = ensurePackageJsonScripts({ ...BKIT_GATE_SCRIPTS }, dryRun, ws);
393
559
  if (gates.added.length > 0) {
394
- written.push("package.json");
395
- console.log(`${logPrefix} ${tag}core: package.json scripts added [${gates.added.join(", ")}]`);
560
+ if (!written.includes("package.json")) written.push("package.json");
561
+ console.log(
562
+ `${logPrefix} ${tag}core: package.json scripts added [${gates.added.join(", ")}] — what a gate may run: .bkit/workflows.md § Local gate scripts`,
563
+ );
396
564
  }
397
565
  if (migrateLinearTeamKey(dryRun, ws, logPrefix) && !written.includes("package.json")) {
398
566
  written.push("package.json");
@@ -400,9 +568,153 @@ export function seedCorePackageJsonScripts(
400
568
  if (migrateGithubProjectKey(dryRun, ws, logPrefix) && !written.includes("package.json")) {
401
569
  written.push("package.json");
402
570
  }
571
+ if (migrateBkitLayout(dryRun, ws, logPrefix) && !written.includes("package.json")) {
572
+ written.push("package.json");
573
+ }
574
+ if (pruneMinPushPaths(dryRun, ws, logPrefix) && !written.includes("package.json")) {
575
+ written.push("package.json");
576
+ }
577
+ if (seedBkitDefaults(dryRun, ws, logPrefix) && !written.includes("package.json")) {
578
+ written.push("package.json");
579
+ }
403
580
  return written;
404
581
  }
405
582
 
583
+ /**
584
+ * Every `bkit.*` setting, written on every install and upgrade so consumers see them all;
585
+ * add-if-missing, nested blocks included. A key with a default gets it; a choice not made
586
+ * yet is `""` or `[]`, which every reader treats as unset. `dependencies.updater` is the one
587
+ * choice install makes: `seedBkitDefaults` fills it from the updater config present.
588
+ */
589
+ export const SEEDED_BKIT_DEFAULTS: Readonly<Record<string, unknown>> = {
590
+ tracker: {
591
+ default: "",
592
+ github: {
593
+ project: "",
594
+ progress: CONFIG_DEFAULTS.github.progress,
595
+ review: CONFIG_DEFAULTS.github.review,
596
+ },
597
+ linear: {
598
+ team: "",
599
+ project: "",
600
+ progress: CONFIG_DEFAULTS.linear.progress,
601
+ review: CONFIG_DEFAULTS.linear.review,
602
+ },
603
+ jira: {
604
+ site: "",
605
+ project: "",
606
+ progress: CONFIG_DEFAULTS.jira.progress,
607
+ review: CONFIG_DEFAULTS.jira.review,
608
+ },
609
+ },
610
+ cloud: { agent: "" },
611
+ providers: { opencode: { default: "", installed: [] } },
612
+ testing: {
613
+ // What bkit writes (ship's bookkeeping allow-list, the plans tree) is always a min push;
614
+ // the seed adds nothing, because a project doc can be a test's input.
615
+ minPushPaths: [...CONFIG_DEFAULTS.minPushPaths],
616
+ ciWorkflow: CONFIG_DEFAULTS.ciWorkflow,
617
+ ciCapstone: CONFIG_DEFAULTS.capstoneJob,
618
+ ciRequired: [...CONFIG_DEFAULTS.ciRequired],
619
+ // Project docs ship's [skip ci] bookkeeping commit may carry onto the PR untested; a
620
+ // repo names its own (bkit's: CHANGELOG.md, README.md), so the seed is the empty choice.
621
+ ciSkipPaths: [...CONFIG_DEFAULTS.ciSkipPaths],
622
+ // CI steps whose failure bkit:generate fixes, beyond the floor bkit's own template
623
+ // steps form (CI_GENERATED_FLOOR); a repo names its own, so the seed is the empty choice.
624
+ ciGenerated: [...CONFIG_DEFAULTS.ciGenerated],
625
+ },
626
+ workflows: {
627
+ minFreeGb: CONFIG_DEFAULTS.diskMinFreeGb,
628
+ worktree: { copy: [...CONFIG_DEFAULTS.worktreeCopy], install: CONFIG_DEFAULTS.worktreeInstall },
629
+ tasks: { ...CONFIG_DEFAULTS.tasks },
630
+ ...withBuildPublish(askBlocks()),
631
+ },
632
+ // bkit-utility-update-roadmap list length; the prompt falls back to 25 too.
633
+ prompts: { roadmapNext: 25 },
634
+ dependencies: { updater: "" },
635
+ advisories: { ignore: [] },
636
+ };
637
+
638
+ /** `{design: {grill: {ask, maxTurns}}, build: {...}, ...}`, from `CONFIG_DEFAULTS.asks`. */
639
+ function askBlocks(): Record<string, Record<string, Record<string, unknown>>> {
640
+ const out: Record<string, Record<string, Record<string, unknown>>> = {};
641
+ for (const point of ASK_POINTS) {
642
+ const [workflow, name] = point.split(".") as [string, string];
643
+ const d = CONFIG_DEFAULTS.asks[point];
644
+ (out[workflow] ??= {})[name] = { ask: d.ask, [limitKey(point)]: d.max };
645
+ }
646
+ return out;
647
+ }
648
+
649
+ /** Merge the `build.publish` choice beside the build ask blocks. */
650
+ function withBuildPublish(
651
+ blocks: Record<string, Record<string, Record<string, unknown>>>,
652
+ ): Record<string, Record<string, unknown>> {
653
+ return { ...blocks, build: { ...blocks.build, publish: { remote: true, local: true } } };
654
+ }
655
+
656
+ const plainObject = (v: unknown): v is Record<string, unknown> =>
657
+ v !== null && typeof v === "object" && !Array.isArray(v);
658
+
659
+ // Copy each `defaults` key missing from `target`, descending into blocks both sides hold.
660
+ // A present key keeps its value, whatever it is. Pushes each added key's dotted path.
661
+ function addMissingKeys(
662
+ target: Record<string, unknown>,
663
+ defaults: Readonly<Record<string, unknown>>,
664
+ prefix: string,
665
+ added: string[],
666
+ ): void {
667
+ for (const [k, v] of Object.entries(defaults)) {
668
+ if (!Object.prototype.hasOwnProperty.call(target, k)) {
669
+ target[k] = structuredClone(v);
670
+ added.push(`${prefix}${k}`);
671
+ } else if (plainObject(v) && plainObject(target[k])) {
672
+ addMissingKeys(target[k], v, `${prefix}${k}.`, added);
673
+ }
674
+ }
675
+ }
676
+
677
+ // Add each SEEDED_BKIT_DEFAULTS key missing from `package.json` `bkit`, creating the block
678
+ // when absent. Runs after the legacy-key migrations, which test `=== undefined`. Returns
679
+ // true when package.json changed.
680
+ export function seedBkitDefaults(dryRun: boolean, ws: WriteSet, logPrefix: string): boolean {
681
+ const pkgPath = "package.json";
682
+ if (!fs.existsSync(pkgPath)) return false;
683
+ const raw = fs.readFileSync(pkgPath, "utf-8");
684
+ const parsed = parseJson(raw);
685
+ if (!parsed.ok) return false;
686
+ const pkg = parsed.value as Record<string, unknown>;
687
+ if (pkg.bkit !== undefined && !plainObject(pkg.bkit)) return false;
688
+ const cfg = (pkg.bkit ?? {}) as Record<string, unknown>;
689
+ const added: string[] = [];
690
+ addMissingKeys(cfg, SEEDED_BKIT_DEFAULTS, "bkit.", added);
691
+ const updater = fillDepUpdater(cfg);
692
+ if (added.length === 0 && !updater) return false;
693
+ pkg.bkit = cfg;
694
+ ws.writes.push({ path: pkgPath, action: "update" });
695
+ if (!dryRun) writePackageJsonLike(raw, pkg);
696
+ const dry = dryRun ? "[dry-run] " : "";
697
+ if (added.length > 0) {
698
+ console.log(`${logPrefix} ${dry}core: added ${added.join(", ")} to package.json`);
699
+ }
700
+ if (updater) {
701
+ console.log(
702
+ `${logPrefix} ${dry}core: set bkit.dependencies.updater to "${updater}" (its config is present)`,
703
+ );
704
+ }
705
+ return true;
706
+ }
707
+
708
+ // An empty `dependencies.updater` takes the one updater whose config is present; a set value
709
+ // stays. Returns the updater written, else null.
710
+ function fillDepUpdater(cfg: Record<string, unknown>): DepUpdater | null {
711
+ const deps = cfg.dependencies;
712
+ if (!plainObject(deps) || deps.updater !== "") return null;
713
+ const found = detectDepUpdater(".");
714
+ if (found) deps.updater = found;
715
+ return found;
716
+ }
717
+
406
718
  /** Rewrite package.json with `pkg`, keeping the file's indent and trailing newline. */
407
719
  function writePackageJsonLike(raw: string, pkg: unknown): void {
408
720
  const indentMatch = raw.match(/\n([ \t]+)"/);
@@ -411,6 +723,668 @@ function writePackageJsonLike(raw: string, pkg: unknown): void {
411
723
  fs.writeFileSync("package.json", JSON.stringify(pkg, null, indent) + trailingNewline, "utf-8");
412
724
  }
413
725
 
726
+ // Migration (up to 6.0.x installs, `docs/migrations.md`): the package.json scripts bkit runs
727
+ // carry the `bkit:` prefix. Old name -> new name. A `graph*` key moves only when its value
728
+ // runs bkit's graph scripts; any other `graph*` script is the consumer's own.
729
+ export const BKIT_SCRIPT_RENAMES: Readonly<Record<string, string>> = {
730
+ "lint:prose": "bkit:lint:prose",
731
+ "slop:delta": "bkit:slop:delta",
732
+ graph: "bkit:graph",
733
+ ...Object.fromEntries(
734
+ ["check", "clean", "graphml", "refresh", "rollup", "scoped", "tree", "update"].map((verb) => [
735
+ `graph:${verb}`,
736
+ `bkit:graph:${verb}`,
737
+ ]),
738
+ ),
739
+ };
740
+
741
+ const GRAPH_VALUE_GUARD = "scripts/graphify/bkit-";
742
+
743
+ // The pairs a migration acts on. A pair is inactive when `package.json` holds both keys, or
744
+ // when the old key is a `graph*` script whose value is not bkit's; a pair with neither key
745
+ // is active, so its tokens in other values and in default gate chains are rewritten.
746
+ function activeScriptRenames(
747
+ scripts: Record<string, unknown>,
748
+ renames: Readonly<Record<string, string>>,
749
+ ): { active: Record<string, string>; bothPresent: string[] } {
750
+ const has = (k: string): boolean => Object.prototype.hasOwnProperty.call(scripts, k);
751
+ const active: Record<string, string> = {};
752
+ const bothPresent: string[] = [];
753
+ for (const [oldName, newName] of Object.entries(renames)) {
754
+ if (has(oldName) && has(newName)) {
755
+ bothPresent.push(oldName);
756
+ continue;
757
+ }
758
+ const value = scripts[oldName];
759
+ if (
760
+ has(oldName) &&
761
+ oldName.startsWith("graph") &&
762
+ !(typeof value === "string" && value.includes(GRAPH_VALUE_GUARD))
763
+ ) {
764
+ continue;
765
+ }
766
+ active[oldName] = newName;
767
+ }
768
+ return { active, bothPresent };
769
+ }
770
+
771
+ function isLink(p: string): boolean {
772
+ return fs.lstatSync(p, { throwIfNoEntry: false })?.isSymbolicLink() === true;
773
+ }
774
+
775
+ // True when `p` or any directory above it (within the relative path) is a symlink.
776
+ function linkedPath(p: string): boolean {
777
+ const parts = path.normalize(p).split(path.sep);
778
+ for (let i = 1; i <= parts.length; i++) {
779
+ if (isLink(parts.slice(0, i).join(path.sep))) return true;
780
+ }
781
+ return false;
782
+ }
783
+
784
+ // Exact v6.0.0 template bytes, also present immediately before 22d6b75f3.
785
+ const RETIRED_SLOP_PLUGIN_HASH = "3748c27577fb384118c4754378038e3d68d087c28fb314a85b7d427f6093292d";
786
+
787
+ // Migration (up to 6.0.x installs, docs/migrations.md): replace the shipped slop plugin
788
+ // that reports inert skip text. The copy stays consumer-owned; edited copies need a merge.
789
+ function migrateSlopTypeSuppression(dryRun: boolean, ws: WriteSet, logPrefix: string): void {
790
+ const file = path.join("scripts", "slop", "bkit-slop-type-suppression.mjs");
791
+ const stat = fs.lstatSync(file, { throwIfNoEntry: false });
792
+ if (!stat) return;
793
+ const tag = dryRun ? "[dry-run] " : "";
794
+ const manual = (reason: string): void => {
795
+ console.warn(
796
+ `${logPrefix} ${tag}core: ${file} left unchanged (${reason}); merge the corrected .bkit/templates/${file} by hand to avoid false skip/focus findings in inert text`,
797
+ );
798
+ };
799
+ if (linkedPath(file) || !stat.isFile()) {
800
+ manual("the path is not a regular file or sits under a symlink");
801
+ return;
802
+ }
803
+ const current = fs.readFileSync(file);
804
+ const template = fs.readFileSync(path.join(getTemplatesRoot(), file));
805
+ if (current.equals(template)) return;
806
+ if (sha256(current) !== RETIRED_SLOP_PLUGIN_HASH) {
807
+ manual("the copy differs from the shipped version");
808
+ return;
809
+ }
810
+ if (!dryRun) fs.writeFileSync(file, template);
811
+ ws.writes.push({ path: file, action: "update", unhashed: true });
812
+ console.log(`${logPrefix} ${tag}core: ${file} — slop plugin updated`);
813
+ }
814
+
815
+ // Every `.github/workflows/*.yml` / `*.yaml` regular file outside `skip`.
816
+ function otherWorkflows(skip: readonly string[]): string[] {
817
+ const dir = path.join(".github", "workflows");
818
+ if (!fs.lstatSync(dir, { throwIfNoEntry: false })?.isDirectory()) return [];
819
+ const skipped = new Set(skip.map((f) => path.normalize(f)));
820
+ return fs
821
+ .readdirSync(dir)
822
+ .filter((f) => /\.ya?ml$/.test(f))
823
+ .map((f) => path.join(dir, f))
824
+ .filter((f) => !skipped.has(f) && fs.lstatSync(f).isFile());
825
+ }
826
+
827
+ // Every regular `action.yml` / `action.yaml` file under `.github/actions/`, at any depth.
828
+ function compositeActions(): string[] {
829
+ const dir = path.join(".github", "actions");
830
+ if (!fs.lstatSync(dir, { throwIfNoEntry: false })?.isDirectory()) return [];
831
+ const walk = (d: string): string[] =>
832
+ fs.readdirSync(d).flatMap((f) => {
833
+ const p = path.join(d, f);
834
+ const st = fs.lstatSync(p);
835
+ if (st.isDirectory()) return walk(p);
836
+ return st.isFile() && /^action\.ya?ml$/.test(f) ? [p] : [];
837
+ });
838
+ return walk(dir);
839
+ }
840
+
841
+ function escapeRegExp(text: string): string {
842
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
843
+ }
844
+
845
+ /**
846
+ * Rewrites `pnpm [flags] [run] [flags] <old>` to the new name, keeping the flags and `run`.
847
+ * Each flag is a value-less `-x` / `--x[=v]` token, except the package selectors (`-F`, `-C`,
848
+ * `-r`, `--recursive`, `--filter`, `--dir`, `--prefix`), which leave the call alone; `<old>` ends at a character outside
849
+ * `[\w:-]` or at the end of the text. Anything else (`npm run`, `echo`, `--filter web`) stays.
850
+ */
851
+ export function renameScriptTokens(
852
+ text: string,
853
+ renames: Readonly<Record<string, string>>,
854
+ ): string {
855
+ const names = Object.keys(renames).sort((a, b) => b.length - a.length);
856
+ if (names.length === 0) return text;
857
+ const re = new RegExp(
858
+ `\\bpnpm((?:\\s+(?:run|(?!-(?:F|C|r|-filter|-dir|-prefix|-recursive))--?\\w[\\w-]*(?:=\\S*)?))*)(\\s+)(${names.map(escapeRegExp).join("|")})(?![\\w:-])`,
859
+ "g",
860
+ );
861
+ return text.replace(
862
+ re,
863
+ (_m, flags: string, gap: string, old: string) => `pnpm${flags}${gap}${renames[old]}`,
864
+ );
865
+ }
866
+
867
+ /**
868
+ * Each old script name still in `text`, with its 1-based line. A name without `:` (`graph`) is
869
+ * a plain word, so it counts only after `pnpm` / `npm` / `yarn` / `bun` on the same line and
870
+ * before any `#`.
871
+ */
872
+ export function findOldScriptNames(
873
+ text: string,
874
+ renames: Readonly<Record<string, string>>,
875
+ ): { line: number; name: string }[] {
876
+ const found: { line: number; name: string }[] = [];
877
+ const lines = text.split("\n");
878
+ for (const name of Object.keys(renames)) {
879
+ const re = name.includes(":")
880
+ ? new RegExp(`(?<![\\w:./-])${escapeRegExp(name)}(?![\\w:-])`)
881
+ : new RegExp(`\\b(?:pnpm|npm|yarn|bun)\\b[^#\\n]*\\s${escapeRegExp(name)}(?![\\w:./-])`);
882
+ lines.forEach((l, i) => {
883
+ if (re.test(l)) found.push({ line: i + 1, name });
884
+ });
885
+ }
886
+ return found;
887
+ }
888
+
889
+ // Renames the old script keys in place (values kept), rewrites old `pnpm` tokens in every
890
+ // script value, and warns on an old name it cannot reach. Returns true when package.json
891
+ // changed.
892
+ export function migrateBrandedScriptNames(
893
+ dryRun: boolean,
894
+ ws: WriteSet,
895
+ logPrefix: string,
896
+ ): boolean {
897
+ const pkgPath = "package.json";
898
+ if (!fs.existsSync(pkgPath)) return false;
899
+ const raw = fs.readFileSync(pkgPath, "utf-8");
900
+ const parsed = parseJson(raw);
901
+ if (!parsed.ok) {
902
+ console.warn(`${logPrefix} core: package.json is not valid JSON; script names not migrated`);
903
+ return false;
904
+ }
905
+ const pkg = parsed.value as Record<string, unknown>;
906
+ if (!plainObject(pkg.scripts)) return false;
907
+ const scripts = pkg.scripts;
908
+ const { active, bothPresent } = activeScriptRenames(scripts, BKIT_SCRIPT_RENAMES);
909
+ const tag = dryRun ? "[dry-run] " : "";
910
+ for (const oldName of bothPresent) {
911
+ console.warn(
912
+ `${logPrefix} ${tag}core: package.json scripts hold both "${oldName}" and "${BKIT_SCRIPT_RENAMES[oldName]}"; left "${oldName}" in place — remove it once nothing uses it`,
913
+ );
914
+ }
915
+ const next: Record<string, unknown> = {};
916
+ const renamed: string[] = [];
917
+ let changed = false;
918
+ for (const [key, value] of Object.entries(scripts)) {
919
+ const newKey = active[key];
920
+ if (newKey !== undefined) {
921
+ renamed.push(key);
922
+ changed = true;
923
+ }
924
+ let newValue = value;
925
+ if (typeof value === "string") {
926
+ newValue = renameScriptTokens(value, active);
927
+ if (newValue !== value) changed = true;
928
+ }
929
+ next[newKey ?? key] = newValue;
930
+ }
931
+ if (!changed) return false;
932
+ for (const [key, value] of Object.entries(next)) {
933
+ if (typeof value !== "string") continue;
934
+ for (const { name } of findOldScriptNames(value, active)) {
935
+ console.warn(
936
+ `${logPrefix} ${tag}core: package.json script "${key}" still runs the old name "${name}"; rename it to "${active[name]}" by hand`,
937
+ );
938
+ }
939
+ }
940
+ pkg.scripts = next;
941
+ ws.writes.push({ path: pkgPath, action: "update" });
942
+ if (!dryRun) writePackageJsonLike(raw, pkg);
943
+ console.log(
944
+ `${logPrefix} ${tag}core: package.json script names branded${renamed.length > 0 ? ` [${renamed.join(", ")}]` : ""}`,
945
+ );
946
+ return true;
947
+ }
948
+
949
+ // Migration (up to 6.0.x installs, `docs/migrations.md`): the husky hooks and the CI workflow
950
+ // are copy-and-own files that run the old script names. `renameScriptTokens` rewrites them in
951
+ // place, for the pairs `migrateBrandedScriptNames` acts on; a name it cannot reach is
952
+ // warned with file and line. With `pathRenames` (`migrateBrandedTemplateFiles`) the
953
+ // `scripts/ci/<old>` path tokens in those files, `bkit-trivy.yml` and the package.json script
954
+ // values are rewritten too. Absent files are skipped. Writes are `unhashed`: the file stays the
955
+ // consumer's, bkit never records a hash for it.
956
+ export interface PathRename {
957
+ from: string;
958
+ to: string;
959
+ }
960
+
961
+ function renamePathTokens(text: string, pathRenames: readonly PathRename[]): string {
962
+ let out = text;
963
+ for (const { from, to } of pathRenames) {
964
+ out = out.replace(new RegExp(`${escapeRegExp(from)}(?![\\w.-])`, "g"), to);
965
+ }
966
+ return out;
967
+ }
968
+
969
+ export function migrateBrandedFileTokens(
970
+ dryRun: boolean,
971
+ ws: WriteSet,
972
+ logPrefix: string,
973
+ pathRenames: readonly PathRename[] = [],
974
+ ): void {
975
+ const tag = dryRun ? "[dry-run] " : "";
976
+ let scripts: Record<string, unknown> = {};
977
+ let pkgRaw: string | undefined;
978
+ let pkg: Record<string, unknown> | undefined;
979
+ if (fs.existsSync("package.json")) {
980
+ pkgRaw = fs.readFileSync("package.json", "utf-8");
981
+ const parsed = parseJson(pkgRaw);
982
+ if (parsed.ok && plainObject(parsed.value)) {
983
+ pkg = parsed.value;
984
+ if (plainObject(pkg.scripts)) scripts = pkg.scripts;
985
+ }
986
+ }
987
+ const { active } = activeScriptRenames(scripts, BKIT_SCRIPT_RENAMES);
988
+ const tokenFiles = [
989
+ path.join(".husky", "pre-commit"),
990
+ path.join(".husky", "pre-push"),
991
+ ciWorkflowPath("."),
992
+ ];
993
+ const files = [...new Set([...tokenFiles, path.join(".github", "workflows", "bkit-trivy.yml")])];
994
+ for (const file of files) {
995
+ if (!fs.lstatSync(file, { throwIfNoEntry: false })?.isFile()) continue;
996
+ const text = fs.readFileSync(file, "utf-8");
997
+ let next = tokenFiles.includes(file) ? renameScriptTokens(text, active) : text;
998
+ next = renamePathTokens(next, pathRenames);
999
+ if (tokenFiles.includes(file)) {
1000
+ for (const { name, line } of findOldScriptNames(next, active)) {
1001
+ console.warn(
1002
+ `${logPrefix} ${tag}core: ${file}:${line} still runs the old script name "${name}"; rename it to "${active[name]}" by hand`,
1003
+ );
1004
+ }
1005
+ }
1006
+ if (next === text) continue;
1007
+ if (!dryRun) fs.writeFileSync(file, next, "utf-8");
1008
+ ws.writes.push({ path: file, action: "update", unhashed: true });
1009
+ console.log(`${logPrefix} ${tag}core: ${file} — branded script and path names rewritten`);
1010
+ }
1011
+ for (const file of otherWorkflows(files)) {
1012
+ for (const { name, line } of findOldScriptNames(fs.readFileSync(file, "utf-8"), active)) {
1013
+ console.warn(
1014
+ `${logPrefix} ${tag}core: ${file}:${line} still runs the old script name "${name}"; rename it to "${active[name]}" by hand`,
1015
+ );
1016
+ }
1017
+ }
1018
+ if (pkg === undefined || pkgRaw === undefined || pathRenames.length === 0) return;
1019
+ let changed = false;
1020
+ const nextScripts: Record<string, unknown> = {};
1021
+ for (const [key, value] of Object.entries(scripts)) {
1022
+ const nextValue = typeof value === "string" ? renamePathTokens(value, pathRenames) : value;
1023
+ if (nextValue !== value) changed = true;
1024
+ nextScripts[key] = nextValue;
1025
+ }
1026
+ if (!changed) return;
1027
+ pkg.scripts = nextScripts;
1028
+ ws.writes.push({ path: "package.json", action: "update", unhashed: true });
1029
+ if (!dryRun) writePackageJsonLike(pkgRaw, pkg);
1030
+ console.log(`${logPrefix} ${tag}core: package.json — branded CI script paths rewritten`);
1031
+ }
1032
+
1033
+ // sha256 of every distinct release content of the CI script `.mjs` files, per old path, from
1034
+ // each `v*` tag. An unedited copy matches one of them.
1035
+ export const SHIPPED_CI_SCRIPT_HASHES: Readonly<Record<string, readonly string[]>> = {
1036
+ "scripts/ci/check-capstone.mjs": [
1037
+ "3813d9fe3cfae79788990b0a7a4914d18350dde165a3c2fe5940e8348362cea6",
1038
+ "45078e630f5ec9ff4e7704c99ac5f56fd37b9c2e94c052f084c03feddc86ef71",
1039
+ ],
1040
+ "scripts/ci/check-capstone.test.mjs": [
1041
+ "0554d64652dcc32ea368a4791372e860a5e3314ecfb7084256627015333c7afb",
1042
+ "ad58a0095528fdb3fe7310586b4091824f29fda261542df73c324c8dd574a0d6",
1043
+ ],
1044
+ "scripts/ci/check-dependency-audit.mjs": [
1045
+ "b410ab27cdbeed8d659fdf523d1af9b519beb874901186bb59e2889646cdaa19",
1046
+ ],
1047
+ "scripts/ci/check-dependency-audit.test.mjs": [
1048
+ "db3643ae6ef7ad01d628e6110aa2f7b47cdf2423ca07efc1a8bc6176eb98b6a2",
1049
+ ],
1050
+ "scripts/ci/check-accepted-divergences.mjs": [
1051
+ "3b410c53535e66b7a65b54d574ba7f7e47139bfba58a883a60697b8ab44deef4",
1052
+ "66e6f1f9ce22b52afe93454c268613b8f5b03c1c58b5817cac958435fefbe5b1",
1053
+ ],
1054
+ "scripts/ci/check-accepted-divergences.test.mjs": [
1055
+ "743e623f0dcb118a96744d31611fb599e9041a8007a3202fb46c30d72a3e183e",
1056
+ "f130f5784349c21c5ae4f02626243362d9c29f783b9ad4b9c158beeca9bf4107",
1057
+ ],
1058
+ "scripts/ci/lanes/resolve-push-base.mjs": [
1059
+ "016c4dacf34ce6edffcc7c7f666027a0a34669ce299d755679c877540fc751e7",
1060
+ "11930bf63081ca2b5201799e0262acfcfc148e15bce41e17ebead688a94fe8ce",
1061
+ "84acc7ff1596234af0c614236608e2009e794da9549bf77a4cc9560c2784a8f8",
1062
+ ],
1063
+ "scripts/ci/lanes/resolve-push-base.test.mjs": [
1064
+ "1ce7b5fdf1de756f56e6b9710952c1e272c633107b06c0d47780fce36b90d1ad",
1065
+ "32e17be38751f2744d660acdd99c6a08e7f437cdeaeb7075bc876b1cd31f0237",
1066
+ "6883deb2b20f99af68721b085fbf3e2ab14e4b58d17dd676afaf734c75195e96",
1067
+ ],
1068
+ };
1069
+
1070
+ // Migration (up to 6.0.x installs, `docs/migrations.md`): the CI script files carry the
1071
+ // `bkit-` prefix. A unit (script, test and data file, `CI_SCRIPT_UNITS`) moves whole when each
1072
+ // present `.mjs` matches a shipped release and no `bkit-` target exists: the old files go, the
1073
+ // `.mjs` targets come from the shipped templates, the data file moves byte for byte. Any
1074
+ // other unit stays, with a warning naming the manual move (the `ci-scripts-old-names`
1075
+ // advisory lists it too). Returns the renames applied plus those already applied (old absent,
1076
+ // new present), for the path-token rewrite.
1077
+ export function migrateBrandedTemplateFiles(
1078
+ dryRun: boolean,
1079
+ ws: WriteSet,
1080
+ logPrefix: string,
1081
+ ): PathRename[] {
1082
+ const tag = dryRun ? "[dry-run] " : "";
1083
+ const renames: PathRename[] = [];
1084
+ const templates = getTemplatesRoot();
1085
+ for (const unit of CI_SCRIPT_UNITS) {
1086
+ const exists = (p: string): boolean => fs.lstatSync(p, { throwIfNoEntry: false }) !== undefined;
1087
+ const present = unit.filter(([from]) => exists(from));
1088
+ const done = unit.filter(([from, to]) => !exists(from) && exists(to));
1089
+ for (const [from, to] of done) renames.push({ from, to });
1090
+ if (present.length === 0) continue;
1091
+ const linkedTargets = present.map(([, to]) => to).filter((to) => linkedPath(to));
1092
+ const linkedAll = [
1093
+ ...new Set([...present.map(([from]) => from).filter((f) => linkedPath(f)), ...linkedTargets]),
1094
+ ];
1095
+ if (linkedAll.length > 0) {
1096
+ console.warn(
1097
+ `${logPrefix} ${tag}core: ${linkedAll.join(", ")} is a symlink (or sits under one); ${present.map(([from]) => from).join(", ")} not moved to the bkit- names; move them by hand and update every reference`,
1098
+ );
1099
+ continue;
1100
+ }
1101
+ const referenced = [
1102
+ ...otherWorkflows([ciWorkflowPath("."), path.join(".github", "workflows", "bkit-trivy.yml")]),
1103
+ ...compositeActions(),
1104
+ ].flatMap((file) => {
1105
+ const lines = fs.readFileSync(file, "utf-8").split("\n");
1106
+ return present.flatMap(([from]) =>
1107
+ lines.flatMap((l, i) =>
1108
+ new RegExp(`${escapeRegExp(from)}(?![\\w.-])`).test(l)
1109
+ ? [{ file, line: i + 1, from }]
1110
+ : [],
1111
+ ),
1112
+ );
1113
+ });
1114
+ if (referenced.length > 0) {
1115
+ for (const { file, line, from } of referenced) {
1116
+ console.warn(
1117
+ `${logPrefix} ${tag}core: ${file}:${line} still names ${from}; the unit was not moved to the bkit- names — move the files by hand and update that reference`,
1118
+ );
1119
+ }
1120
+ continue;
1121
+ }
1122
+ const edited = present.filter(
1123
+ ([from]) =>
1124
+ from.endsWith(".mjs") &&
1125
+ !SHIPPED_CI_SCRIPT_HASHES[from]?.includes(sha256(fs.readFileSync(from))),
1126
+ );
1127
+ const taken = present.filter(([, to]) => exists(to));
1128
+ const noTemplate = present.filter(
1129
+ ([, to]) => to.endsWith(".mjs") && !fs.existsSync(path.join(templates, to)),
1130
+ );
1131
+ if (edited.length > 0 || taken.length > 0 || noTemplate.length > 0) {
1132
+ const why =
1133
+ edited.length > 0
1134
+ ? `${edited.map(([from]) => from).join(", ")} differs from every shipped release`
1135
+ : taken.length > 0
1136
+ ? `${taken.map(([, to]) => to).join(", ")} already exists`
1137
+ : "the shipped template is missing";
1138
+ console.warn(
1139
+ `${logPrefix} ${tag}core: ${present.map(([from]) => from).join(", ")} not moved to the bkit- names (${why}); move them by hand and update every reference`,
1140
+ );
1141
+ continue;
1142
+ }
1143
+ for (const [from, to] of present) {
1144
+ if (!dryRun) {
1145
+ fs.mkdirSync(path.dirname(to), { recursive: true });
1146
+ if (to.endsWith(".mjs")) fs.copyFileSync(path.join(templates, to), to);
1147
+ else fs.copyFileSync(from, to);
1148
+ fs.rmSync(from);
1149
+ }
1150
+ ws.writes.push({ path: from, action: "write", unhashed: true });
1151
+ ws.writes.push({ path: to, action: "write", unhashed: true });
1152
+ renames.push({ from, to });
1153
+ console.log(`${logPrefix} ${tag}core: ${from} moved to ${to}`);
1154
+ }
1155
+ }
1156
+ return renames;
1157
+ }
1158
+
1159
+ // The old `bkit-stub:health` block, as shipped by every release up to 6.0.x.
1160
+ const OLD_HEALTH_STUB = [
1161
+ "# bkit-stub:health — copy into .github/workflows/health.yml. workflow_run cannot share a file with",
1162
+ "# push / pull_request. WHEN: you have a live URL to smoke after CI. Trigger on CI completed, default",
1163
+ "# branch only, if the CI run succeeded. Then hit the health URL of the deployment this SHA promoted.",
1164
+ "# e.g. poll the host until that deployment is ready, then GET /health. Not a required check.",
1165
+ "# DROP if you have no deployed health URL.",
1166
+ ].join("\n");
1167
+
1168
+ // Exact old workflow `name:` lines the three shipped example workflows carried, with the
1169
+ // branded line and the check each one renames. `job` names the job whose display name the
1170
+ // workflow name branded (the job has no `name:` of its own, so its check showed the bare id).
1171
+ const BRANDED_WORKFLOWS = [
1172
+ { file: "bkit-renovate.yml", oldName: "Renovate", newName: "bkit-renovate", job: "renovate" },
1173
+ { file: "bkit-trivy.yml", oldName: "Trivy", newName: "bkit-trivy", job: "trivy" },
1174
+ ] as const;
1175
+ const CHECK_RENAME_FIX =
1176
+ "update the branch-protection required checks (and any ruleset) to the new name";
1177
+
1178
+ // Migration (up to 6.0.x installs, `docs/migrations.md`): the shipped example workflows and
1179
+ // the health stub in the CI workflow carry bkit- check names. Only the exact shipped old
1180
+ // lines are rewritten, so a customised `name:` stays; the job `name:` is inserted only when
1181
+ // the workflow name was rewritten and the job has none. The health stub block is replaced
1182
+ // by the current one when it is byte-identical to the shipped old one. Writes are `unhashed`:
1183
+ // the files stay the consumer's. One log line per renamed check names old -> new, because
1184
+ // branch protection matches the check name.
1185
+ export function migrateBrandedCheckNames(
1186
+ dryRun: boolean,
1187
+ ws: WriteSet,
1188
+ logPrefix: string,
1189
+ defaultBranch = "main",
1190
+ ): void {
1191
+ const tag = dryRun ? "[dry-run] " : "";
1192
+ const wfDir = path.join(".github", "workflows");
1193
+ const finish = (file: string, text: string, next: string, renamed: string[]): void => {
1194
+ if (next === text) return;
1195
+ if (!dryRun) fs.writeFileSync(file, next, "utf-8");
1196
+ ws.writes.push({ path: file, action: "update", unhashed: true });
1197
+ for (const line of renamed) {
1198
+ console.log(`${logPrefix} ${tag}core: ${file} — check renamed ${line}; ${CHECK_RENAME_FIX}`);
1199
+ }
1200
+ };
1201
+ const readFile = (file: string): string | undefined =>
1202
+ fs.lstatSync(file, { throwIfNoEntry: false })?.isFile()
1203
+ ? fs.readFileSync(file, "utf-8")
1204
+ : undefined;
1205
+
1206
+ const cloud = path.join(wfDir, "bkit-cloud.yml");
1207
+ const cloudText = readFile(cloud);
1208
+ if (cloudText !== undefined) {
1209
+ const renamed: string[] = [];
1210
+ const next = cloudText.replace(
1211
+ /^( {4}name: )(context|claude|opencode)( \(\$\{\{ github\.event_name \}\}\))$/gm,
1212
+ (_m, pre: string, job: string, post: string) => {
1213
+ renamed.push(`bkit-cloud / ${job}${post} -> bkit-cloud / bkit-cloud-${job}${post}`);
1214
+ return `${pre}bkit-cloud-${job}${post}`;
1215
+ },
1216
+ );
1217
+ finish(cloud, cloudText, next, renamed);
1218
+ }
1219
+
1220
+ for (const { file, oldName, newName, job } of BRANDED_WORKFLOWS) {
1221
+ const target = path.join(wfDir, file);
1222
+ const text = readFile(target);
1223
+ if (text === undefined) continue;
1224
+ const nameLine = new RegExp(`^name: ${escapeRegExp(oldName)}$`, "m");
1225
+ if (!nameLine.test(text)) continue;
1226
+ let next = text.replace(nameLine, `name: ${newName}`);
1227
+ const jobStart = new RegExp(`^ {2}${escapeRegExp(job)}:[ \\t]*\\n`, "m").exec(next);
1228
+ if (jobStart !== null) {
1229
+ const bodyStart = jobStart.index + jobStart[0].length;
1230
+ const rest = next.slice(bodyStart);
1231
+ const end = rest.search(/^(?: {2}[^\s#]|[^\s#])/m);
1232
+ const body = end === -1 ? rest : rest.slice(0, end);
1233
+ if (!/^ {4}name:/m.test(body)) {
1234
+ next = `${next.slice(0, bodyStart)} name: ${newName}\n${next.slice(bodyStart)}`;
1235
+ }
1236
+ const after = new RegExp(`^ {2}${escapeRegExp(job)}:[ \\t]*\\n`, "m").exec(next);
1237
+ const afterRest = after === null ? "" : next.slice(after.index + after[0].length);
1238
+ const afterEnd = afterRest.search(/^(?: {2}[^\s#]|[^\s#])/m);
1239
+ const afterBody = afterEnd === -1 ? afterRest : afterRest.slice(0, afterEnd);
1240
+ if ((afterBody.match(/^ {4}name:/gm) ?? []).length > 1) {
1241
+ console.warn(
1242
+ `${logPrefix} ${tag}core: ${target} not renamed (a second job name: would make the workflow invalid YAML); rename by hand: name: ${oldName} -> name: ${newName} and set the ${job} job name: to ${newName}`,
1243
+ );
1244
+ continue;
1245
+ }
1246
+ }
1247
+ finish(target, text, next, [`${oldName} / ${job} -> ${newName} / ${newName}`]);
1248
+ }
1249
+
1250
+ const ci = ciWorkflowPath(".");
1251
+ const ciText = readFile(ci);
1252
+ if (ciText !== undefined && ciText.includes(OLD_HEALTH_STUB)) {
1253
+ const template = readFile(path.join(getTemplatesRoot(), ".github", "workflows", "bkit-ci.yml"));
1254
+ const current = template?.match(
1255
+ /^# bkit-stub:health[^\n]*\n(?:#[^\n]*\n)*?#[^\n]*DROP if you have no deployed health URL\./m,
1256
+ )?.[0];
1257
+ if (current !== undefined) {
1258
+ const next = ciText.replace(OLD_HEALTH_STUB, () =>
1259
+ current.replace(/\{\{DEFAULT_BRANCH\}\}/g, () => defaultBranch),
1260
+ );
1261
+ if (next !== ciText) {
1262
+ if (!dryRun) fs.writeFileSync(ci, next, "utf-8");
1263
+ ws.writes.push({ path: ci, action: "update", unhashed: true });
1264
+ console.log(
1265
+ `${logPrefix} ${tag}core: ${ci} — old bkit-stub:health text replaced by the current block`,
1266
+ );
1267
+ }
1268
+ }
1269
+ }
1270
+ }
1271
+
1272
+ // sha256 of every distinct release content of the four shipped `House` Vale rules, from each
1273
+ // `v*` tag, across `.agents/templates/.vale/styles/House/` and `.bkit/templates/.vale/styles/House/`.
1274
+ // An unedited copy matches one of them. Same shape as `RETIRED_DRIVER_HASHES` (write.ts).
1275
+ export const SHIPPED_HOUSE_RULE_HASHES: Readonly<Record<string, readonly string[]>> = {
1276
+ Filler: [
1277
+ "96139df9ffc61835e23014addac887d9465169d62cd1be24c2f272f838166524",
1278
+ "9b10438de3158a1923c51375fcba56de7a8dd2f17de97d62385407eee2a6e377",
1279
+ "e04e9e76a4857de0d13ff106343e25000418c535a983317f5a2e1710fa68cbc7",
1280
+ ],
1281
+ Hedging: [
1282
+ "7289b6bfe98f48803734c016c6ba49661071b5d8ded0f4678509b37c6ab8aff9",
1283
+ "b7425861cb3085cc798379d8e92f01a0420aa2c40f7be1ba1bbfabd908767a37",
1284
+ "c46cda04406629377555d3add75e56edaad40521864743dbbd47781f2c048ef0",
1285
+ ],
1286
+ LLMSlop: [
1287
+ "17a22ab44f0bd37de4d4c972fbb39a71dc256712ba0cfc39320043381f180a8e",
1288
+ "c39313e229249786ba189bb1abe55728f83e325a54777b41b54e0a1dec47b4f7",
1289
+ "e1ce58da6c86d7bc746698fbf17fd3d0075980ca78f2d8b8c927ea3ddc35094e",
1290
+ ],
1291
+ Verbose: [
1292
+ "8278791997cca85a2df63b2c93decac480e685215e0569e8472aa433e7a27ac8",
1293
+ "bcb18beb903e7bd57780905778ea4d1a4f294589cf191375db144ecb11f4c619",
1294
+ "f7939a5be92562803183108581538a1b4ca73c3b8a1b68ceeb2b2149ba1a4357",
1295
+ ],
1296
+ };
1297
+
1298
+ // Migration (up to 6.0.x installs, `docs/migrations.md`): the shipped Vale style is `Bkit`,
1299
+ // it was `House`. A `House/<rule>.yml` byte-identical to a shipped release moves to
1300
+ // `Bkit/<rule>.yml` when that is absent; an edited rule or a taken target stays with one
1301
+ // warning naming the manual move. In `.vale.ini`, `House.<moved>` becomes `Bkit.<moved>`;
1302
+ // `BasedOnStyles` swaps `House` for `Bkit` once `House/` is empty (the directory goes), else
1303
+ // appends `Bkit`. Own rules in `House/` stay. Writes are `unhashed`.
1304
+ export function migrateValeHouseStyle(dryRun: boolean, ws: WriteSet, logPrefix: string): void {
1305
+ const tag = dryRun ? "[dry-run] " : "";
1306
+ const stylesDir = path.join(".vale", "styles");
1307
+ const houseDir = path.join(stylesDir, "House");
1308
+ const bkitDir = path.join(stylesDir, "Bkit");
1309
+ const linkedVale = [".vale", stylesDir, houseDir, bkitDir].find((p) => isLink(p));
1310
+ if (linkedVale === houseDir || linkedVale === ".vale" || linkedVale === stylesDir) {
1311
+ console.warn(
1312
+ `${logPrefix} ${tag}core: ${linkedVale} is a symlink; the House rules were not moved to the Bkit style — move them by hand: mv .vale/styles/House/<rule>.yml .vale/styles/Bkit/ and rename the House.<rule> toggles in .vale.ini to Bkit.<rule>`,
1313
+ );
1314
+ return;
1315
+ }
1316
+ if (!fs.lstatSync(houseDir, { throwIfNoEntry: false })?.isDirectory()) return;
1317
+ if (linkedVale !== undefined) {
1318
+ console.warn(
1319
+ `${logPrefix} ${tag}core: ${linkedVale} is a symlink; the House rules were not moved to the Bkit style — move them by hand: mv .vale/styles/House/<rule>.yml .vale/styles/Bkit/ and rename the House.<rule> toggles in .vale.ini to Bkit.<rule>`,
1320
+ );
1321
+ return;
1322
+ }
1323
+ const moved: string[] = [];
1324
+ for (const [rule, hashes] of Object.entries(SHIPPED_HOUSE_RULE_HASHES)) {
1325
+ const from = path.join(houseDir, `${rule}.yml`);
1326
+ if (isLink(from)) {
1327
+ console.warn(
1328
+ `${logPrefix} ${tag}core: ${from} is a symlink and was not moved to the Bkit style; move it by hand: mv .vale/styles/House/${rule}.yml .vale/styles/Bkit/ and rename the House.${rule} toggle in .vale.ini to Bkit.${rule}`,
1329
+ );
1330
+ continue;
1331
+ }
1332
+ if (!fs.lstatSync(from, { throwIfNoEntry: false })?.isFile()) continue;
1333
+ const to = path.join(bkitDir, `${rule}.yml`);
1334
+ const stays = !hashes.includes(sha256(fs.readFileSync(from)))
1335
+ ? "differs from every shipped release"
1336
+ : fs.lstatSync(to, { throwIfNoEntry: false }) !== undefined
1337
+ ? `${to} already exists`
1338
+ : undefined;
1339
+ if (stays !== undefined) {
1340
+ console.warn(
1341
+ `${logPrefix} ${tag}core: ${from} not moved to the Bkit style (${stays}); move it by hand: mv .vale/styles/House/${rule}.yml .vale/styles/Bkit/ and rename the House.${rule} toggle in .vale.ini to Bkit.${rule}`,
1342
+ );
1343
+ continue;
1344
+ }
1345
+ if (!dryRun) {
1346
+ fs.mkdirSync(bkitDir, { recursive: true });
1347
+ fs.copyFileSync(from, to);
1348
+ fs.rmSync(from);
1349
+ }
1350
+ ws.writes.push({ path: from, action: "write", unhashed: true });
1351
+ ws.writes.push({ path: to, action: "write", unhashed: true });
1352
+ moved.push(rule);
1353
+ console.log(`${logPrefix} ${tag}core: ${from} moved to ${to}`);
1354
+ }
1355
+ const remaining = fs.readdirSync(houseDir).filter((f) => !moved.some((r) => f === `${r}.yml`));
1356
+ const houseGone = remaining.length === 0;
1357
+ if (houseGone) {
1358
+ if (!dryRun) fs.rmSync(houseDir, { recursive: true });
1359
+ ws.writes.push({ path: houseDir, action: "write", unhashed: true });
1360
+ }
1361
+ if (moved.length === 0 && !houseGone) return;
1362
+ const ini = ".vale.ini";
1363
+ if (!fs.lstatSync(ini, { throwIfNoEntry: false })?.isFile()) return;
1364
+ const text = fs.readFileSync(ini, "utf-8");
1365
+ let next = text;
1366
+ if (moved.length > 0) {
1367
+ next = next.replace(
1368
+ new RegExp(`^(\\s*)House\\.(${moved.join("|")})\\b`, "gm"),
1369
+ (_m, lead: string, rule: string) => `${lead}Bkit.${rule}`,
1370
+ );
1371
+ }
1372
+ if (houseGone) next = next.replace(/^(#.*)\bHouse rules\b/gm, "$1Bkit rules");
1373
+ next = next.replace(/^(BasedOnStyles\s*=\s*)(.*)$/gm, (line, pre: string, list: string) => {
1374
+ const styles = list.split(",").map((s) => s.trim());
1375
+ if (!styles.includes("House")) return line;
1376
+ if (houseGone) {
1377
+ const swapped = styles.map((s) => (s === "House" ? "Bkit" : s));
1378
+ return pre + [...new Set(swapped)].join(", ");
1379
+ }
1380
+ return styles.includes("Bkit") ? line : `${line}, Bkit`;
1381
+ });
1382
+ if (next === text) return;
1383
+ if (!dryRun) fs.writeFileSync(ini, next, "utf-8");
1384
+ ws.writes.push({ path: ini, action: "update", unhashed: true });
1385
+ console.log(`${logPrefix} ${tag}core: ${ini} — House style names rewritten to Bkit`);
1386
+ }
1387
+
414
1388
  // Status option ids of GitHub's Kanban and Team planning board templates; every board
415
1389
  // made from one carries the same ids.
416
1390
  const TEMPLATE_STATUS_OPTIONS: Readonly<Record<string, string>> = {
@@ -470,11 +1444,149 @@ export function migrateGithubProjectKey(dryRun: boolean, ws: WriteSet, logPrefix
470
1444
  console.log(`${logPrefix} ${tag}core: moved bkit.githubProject to bkit.github in package.json`);
471
1445
  for (const moment of unnamed)
472
1446
  console.log(
473
- `${logPrefix} ${tag}core: bkit.githubProject named its ${moment} Status option by id; set bkit.github.${moment} to that option's name (default "${CONFIG_DEFAULTS.github[moment]}")`,
1447
+ `${logPrefix} ${tag}core: bkit.githubProject named its ${moment} Status option by id; set bkit.tracker.github.${moment} to that option's name (default "${CONFIG_DEFAULTS.github[moment]}")`,
474
1448
  );
475
1449
  return true;
476
1450
  }
477
1451
 
1452
+ // Migration (up to 5.5.x installs, `docs/migrations.md`): `bkit` settings sat flat; they
1453
+ // are grouped into named sections. Each old key moves to its new path; a value already at
1454
+ // the new path wins, and two blocks merge key by key. `loopPause: true|false` becomes
1455
+ // `ask` on every point under `workflows.<workflow>`, where an `ask` already set wins.
1456
+ // Runs after the linearTeam and githubProject moves, which write the flat keys. Returns
1457
+ // true when package.json changed.
1458
+ export const BKIT_LAYOUT_MOVES: readonly (readonly [string, string])[] = [
1459
+ ["issueTracker", "tracker.default"],
1460
+ ["github", "tracker.github"],
1461
+ ["linear", "tracker.linear"],
1462
+ ["jira", "tracker.jira"],
1463
+ ["cloudAgents", "cloud.agent"],
1464
+ ["opencodeProvider", "providers.opencode.default"],
1465
+ ["opencodeProviders", "providers.opencode.installed"],
1466
+ ["minPushPaths", "testing.minPushPaths"],
1467
+ ["capstoneJob", "testing.ciCapstone"],
1468
+ ["ciWorkflow", "testing.ciWorkflow"],
1469
+ ["shipGateRequiredLanes", "testing.ciRequired"],
1470
+ // 6.0.0 installs named the required-lane list `testing.shipGate`.
1471
+ ["testing.shipGate", "testing.ciRequired"],
1472
+ ["disk.minFreeGb", "workflows.minFreeGb"],
1473
+ ["worktree", "workflows.worktree"],
1474
+ ["tasks", "workflows.tasks"],
1475
+ ["roadmapNext", "prompts.roadmapNext"],
1476
+ ["depUpdater", "dependencies.updater"],
1477
+ ["ignoreAdvisories", "advisories.ignore"],
1478
+ ];
1479
+
1480
+ // Migration (up to 6.0.x installs, `docs/migrations.md`): `bkit.testing.minPushPaths` was the
1481
+ // whole min-push list, so installs seeded and repos restated what bkit itself writes. The
1482
+ // engine now always allows that floor (ship's bookkeeping allow-list, `docs/plans/**`) and
1483
+ // `bkit.testing.ciSkipPaths`; the setting only adds. Entries the floor already covers are
1484
+ // dropped from the list. Returns true when package.json changed.
1485
+ export const MIN_PUSH_FLOOR_ENTRIES: readonly string[] = [
1486
+ "docs/plans/**",
1487
+ "docs/*.jsonl",
1488
+ ".bkit/*.jsonl",
1489
+ ];
1490
+
1491
+ export function pruneMinPushPaths(dryRun: boolean, ws: WriteSet, logPrefix: string): boolean {
1492
+ const pkgPath = "package.json";
1493
+ if (!fs.existsSync(pkgPath)) return false;
1494
+ const raw = fs.readFileSync(pkgPath, "utf-8");
1495
+ const parsed = parseJson(raw);
1496
+ if (!parsed.ok) return false;
1497
+ const pkg = parsed.value as Record<string, unknown>;
1498
+ if (!plainObject(pkg.bkit) || !plainObject(pkg.bkit.testing)) return false;
1499
+ const testing = pkg.bkit.testing;
1500
+ if (!Array.isArray(testing.minPushPaths)) return false;
1501
+ const skip = Array.isArray(testing.ciSkipPaths) ? testing.ciSkipPaths : [];
1502
+ const covered = new Set<unknown>([...MIN_PUSH_FLOOR_ENTRIES, ...skip]);
1503
+ const kept = testing.minPushPaths.filter((p) => !covered.has(p));
1504
+ if (kept.length === testing.minPushPaths.length) return false;
1505
+ const dropped = testing.minPushPaths.filter((p) => covered.has(p)).map(String);
1506
+ testing.minPushPaths = kept;
1507
+ ws.writes.push({ path: pkgPath, action: "update" });
1508
+ if (!dryRun) writePackageJsonLike(raw, pkg);
1509
+ console.log(
1510
+ `${logPrefix} ${dryRun ? "[dry-run] " : ""}core: dropped [${dropped.join(", ")}] from bkit.testing.minPushPaths in package.json — bkit always allows what it writes, and ciSkipPaths counts`,
1511
+ );
1512
+ return true;
1513
+ }
1514
+
1515
+ // Fill `into` with each `from` key it lacks, descending into blocks both sides hold.
1516
+ function mergeMissing(into: Record<string, unknown>, from: Record<string, unknown>): void {
1517
+ for (const [k, v] of Object.entries(from)) {
1518
+ if (into[k] === undefined) into[k] = v;
1519
+ else if (plainObject(v) && plainObject(into[k])) mergeMissing(into[k], v);
1520
+ }
1521
+ }
1522
+
1523
+ export function migrateBkitLayout(dryRun: boolean, ws: WriteSet, logPrefix: string): boolean {
1524
+ const pkgPath = "package.json";
1525
+ if (!fs.existsSync(pkgPath)) return false;
1526
+ const raw = fs.readFileSync(pkgPath, "utf-8");
1527
+ const parsed = parseJson(raw);
1528
+ if (!parsed.ok) return false;
1529
+ const pkg = parsed.value as Record<string, unknown>;
1530
+ if (!plainObject(pkg.bkit)) return false;
1531
+ const cfg = pkg.bkit;
1532
+ const moved: string[] = [];
1533
+ for (const [from, to] of BKIT_LAYOUT_MOVES) {
1534
+ const fromPath = from.split(".");
1535
+ const fromParent = fromPath
1536
+ .slice(0, -1)
1537
+ .reduce<unknown>((o, k) => (plainObject(o) ? o[k] : undefined), cfg);
1538
+ const fromKey = fromPath[fromPath.length - 1]!;
1539
+ if (!plainObject(fromParent) || !Object.prototype.hasOwnProperty.call(fromParent, fromKey))
1540
+ continue;
1541
+ const old = fromParent[fromKey];
1542
+ const toPath = to.split(".");
1543
+ let parent: Record<string, unknown> = cfg;
1544
+ let blocked = false;
1545
+ for (const k of toPath.slice(0, -1)) {
1546
+ if (parent[k] === undefined) parent[k] = {};
1547
+ if (!plainObject(parent[k])) {
1548
+ blocked = true;
1549
+ break;
1550
+ }
1551
+ parent = parent[k];
1552
+ }
1553
+ // A non-object where the new section belongs: leave the old key for `bkit check` to show.
1554
+ if (blocked) continue;
1555
+ const toKey = toPath[toPath.length - 1]!;
1556
+ if (parent[toKey] === undefined) parent[toKey] = old;
1557
+ else if (plainObject(parent[toKey]) && plainObject(old)) mergeMissing(parent[toKey], old);
1558
+ delete fromParent[fromKey];
1559
+ if (fromParent !== cfg && Object.keys(fromParent).length === 0) delete cfg[fromPath[0]!];
1560
+ moved.push(`bkit.${from} -> bkit.${to}`);
1561
+ }
1562
+ if (Object.prototype.hasOwnProperty.call(cfg, "loopPause")) {
1563
+ const old = cfg.loopPause;
1564
+ if (typeof old === "boolean") {
1565
+ if (cfg.workflows === undefined) cfg.workflows = {};
1566
+ if (plainObject(cfg.workflows)) mergeMissing(cfg.workflows, askOnly(old));
1567
+ }
1568
+ delete cfg.loopPause;
1569
+ moved.push("bkit.loopPause -> bkit.workflows.<workflow>.<point>.ask");
1570
+ }
1571
+ if (moved.length === 0) return false;
1572
+ ws.writes.push({ path: pkgPath, action: "update" });
1573
+ if (!dryRun) writePackageJsonLike(raw, pkg);
1574
+ console.log(
1575
+ `${logPrefix} ${dryRun ? "[dry-run] " : ""}core: moved ${moved.join(", ")} in package.json`,
1576
+ );
1577
+ return true;
1578
+ }
1579
+
1580
+ /** `{design: {grill: {ask}}, build: {verify: {ask}, ...}, ...}` with every `ask` = `ask`. */
1581
+ function askOnly(ask: boolean): Record<string, unknown> {
1582
+ const out: Record<string, Record<string, Record<string, unknown>>> = {};
1583
+ for (const point of ASK_POINTS) {
1584
+ const [workflow, name] = point.split(".") as [string, string];
1585
+ (out[workflow] ??= {})[name] = { ask };
1586
+ }
1587
+ return out;
1588
+ }
1589
+
478
1590
  // Migration (up to 5.4.x installs, `docs/migrations.md`): the Linear team lived at
479
1591
  // `bkit.linearTeam`; it is `bkit.linear.team`, beside the project and state names. An
480
1592
  // existing `bkit.linear.team` wins over the old key. Returns true when package.json changed.
@@ -541,11 +1653,19 @@ export function gateLeafScripts(
541
1653
  return leaves;
542
1654
  }
543
1655
 
1656
+ /**
1657
+ * What a gate may run. bkit never reads a gate's value beyond its seeded default, so it
1658
+ * cannot check this; every gate advisory restates it (`.bkit/workflows.md` § Local gate
1659
+ * scripts).
1660
+ */
1661
+ export const GATE_CONTENTS_NOTE =
1662
+ "Gate contents (`.bkit/workflows.md` § Local gate scripts): every gate but `bkit:gate:static-unit-integration-e2e` and `bkit:gate:static-unit-integration-e2e-live` runs on a push or inside `/bkit-build`, so it MUST NOT run tests that need a deployed boundary or remote service; local services (a database in Docker) are fine.";
1663
+
544
1664
  /**
545
1665
  * Advisories for the `bkit:gate:*` scripts: the scripts a still-default gate
546
1666
  * chains that package.json does not declare, the deeper test tiers the repo has
547
- * but no gate runs, a commit gate that repeats the push gate, and a missing
548
- * `bkit:test:file`. Judges the scripts as install
1667
+ * but no gate runs, a commit gate that repeats the push gate, a missing
1668
+ * `bkit:test:file`, and a missing `bkit:gate:changed`. Judges the scripts as install
549
1669
  * leaves them (missing gate names at their seeded defaults), so install, `bkit check`
550
1670
  * and `bkit upgrade` report the same set. Read-only; an absent or unparseable
551
1671
  * package.json yields none.
@@ -576,7 +1696,7 @@ export function detectGateAdvisories(cwd: string): PreflightFinding[] {
576
1696
  id: "gate-missing-called-scripts",
577
1697
  severity: "advisory",
578
1698
  detect: `The bkit:gate scripts call scripts package.json does not declare: ${names.join(", ")}.`,
579
- action: `Every bkit workflow runs a \`bkit:gate*\` script, so a missing link fails the whole gate. Add ${names.join(", ")} to package.json (\`.bkit/templates.md\` lists the tool scripts and the devDeps they need), or edit the \`bkit:gate*\` scripts to drop what this repo does not have.`,
1699
+ action: `Every bkit workflow runs a \`bkit:gate*\` script, so a missing link fails the whole gate. Add ${names.join(", ")} to package.json (\`.bkit/templates.md\` lists the tool scripts and the devDeps they need), or edit the \`bkit:gate*\` scripts to drop what this repo does not have.\n\n${GATE_CONTENTS_NOTE}`,
580
1700
  });
581
1701
  }
582
1702
 
@@ -598,7 +1718,8 @@ export function detectGateAdvisories(cwd: string): PreflightFinding[] {
598
1718
  action:
599
1719
  "Each workflow runs the DEEPEST gate you declare, and `.husky/pre-push` runs `bkit:gate:static-unit-integration` when it is declared; an undeclared one is skipped, never guessed. Add the gates you want the agent loop to run:\n\n" +
600
1720
  unwired.join("\n") +
601
- "\n\nOrder matters — each chains the one above it. Omit a level deliberately to keep it CI-only (E2E in the build loop costs a production build on every remediation attempt). `.bkit/templates.md` lists the tool scripts the gates chain.",
1721
+ "\n\nOrder matters — each chains the one above it. Omit a level deliberately to keep it CI-only (E2E in the build loop costs a production build on every remediation attempt). `.bkit/templates.md` lists the tool scripts the gates chain.\n\n" +
1722
+ GATE_CONTENTS_NOTE,
602
1723
  });
603
1724
  }
604
1725
 
@@ -614,7 +1735,7 @@ export function detectGateAdvisories(cwd: string): PreflightFinding[] {
614
1735
  id: "gate-commit-repeats-push",
615
1736
  severity: "advisory",
616
1737
  detect: `\`bkit:gate:format\` (pre-commit) runs ${names}, which \`${pushGate}\` (pre-push) runs again.`,
617
- action: `Drop ${names} from \`bkit:gate:format\`. The commit gate formats staged files and nothing else; every whole-repo check runs once, at pre-push.`,
1738
+ action: `Drop ${names} from \`bkit:gate:format\`. The commit gate formats staged files and nothing else; every whole-repo check runs once, at pre-push.\n\n${GATE_CONTENTS_NOTE}`,
618
1739
  });
619
1740
  }
620
1741
 
@@ -628,6 +1749,33 @@ export function detectGateAdvisories(cwd: string): PreflightFinding[] {
628
1749
  action: `Add \`${BKIT_TEST_FILE_SCRIPT}\` to package.json: it runs the ONE test file bkit appends as its argument (repo-relative path) and writes a JUnit report to the path in \`$BKIT_TEST_REPORT\`. Vitest example:\n\n "${BKIT_TEST_FILE_SCRIPT}": "vitest run --reporter=default --reporter=junit --outputFile.junit=\\"$BKIT_TEST_REPORT\\""\n\nCall the runner directly, not through a task runner that caches results or runs dependent packages first. A monorepo routes the path to the package and config that own it.`,
629
1750
  });
630
1751
  }
1752
+
1753
+ // A red recorded before the linter sees the test: a lint rewrite after it reads as an
1754
+ // edited test, and no red can be recorded again once the task's code makes it pass.
1755
+ if (BKIT_TEST_FILE_SCRIPT in declared && !(BKIT_LINT_FILE_SCRIPT in declared)) {
1756
+ findings.push({
1757
+ id: "lint-file-script-missing",
1758
+ severity: "advisory",
1759
+ detect: `package.json declares \`${BKIT_TEST_FILE_SCRIPT}\` but not \`${BKIT_LINT_FILE_SCRIPT}\`, so \`/bkit-build\` records a task's red before the linter sees the test; a lint fix after it pauses the build for an owner exception.`,
1760
+ action: `Add \`${BKIT_LINT_FILE_SCRIPT}\` to package.json: it lints the ONE test file bkit appends as its argument (repo-relative path) with the rules your static gate applies, exiting 0 when clean. \`bkit tests red\` runs it before the test and records no red while it fails. Examples:\n\n "${BKIT_LINT_FILE_SCRIPT}": "eslint --max-warnings=0"\n "${BKIT_LINT_FILE_SCRIPT}": "ruff check"\n\nUse the same linter config as the static gate, or the gate can still demand a rewrite after the red.`,
1761
+ });
1762
+ }
1763
+
1764
+ // Build and debug agents check their own change through this script; without it each
1765
+ // one runs a whole gate after every change. bkit cannot seed it: what finds the tests
1766
+ // a file affects is the stack's.
1767
+ const changedId = "gate-changed-script-missing";
1768
+ if (
1769
+ !(BKIT_GATE_CHANGED_SCRIPT in declared) &&
1770
+ !isAdvisorySuppressed(cwd, changedId, "advisory")
1771
+ ) {
1772
+ findings.push({
1773
+ id: changedId,
1774
+ severity: "advisory",
1775
+ detect: `package.json does not declare \`${BKIT_GATE_CHANGED_SCRIPT}\`, so \`/bkit-build\` and \`/bkit-debug\` agents run a whole gate (\`bkit:gate:static\` or \`bkit:gate:static-unit\`) after every change instead of checking only what changed.`,
1776
+ action: `Add \`${BKIT_GATE_CHANGED_SCRIPT}\` to package.json. \`bkit tests changed\` calls it with the changed files as its arguments (repo-relative paths: uncommitted, untracked and committed since the step began; deleted files left out) and never with none. It runs the tests that import those files, the tests that name their paths, and the static checks (lint, format, typecheck) on those files, exiting 0 when clean. Vitest + ESLint example, with \`scripts/gate-changed.sh\` holding \`vitest related --run "$@" && eslint --max-warnings=0 --no-error-on-unmatched-pattern "$@" && prettier --check --ignore-unknown "$@"\`:\n\n "${BKIT_GATE_CHANGED_SCRIPT}": "sh scripts/gate-changed.sh"\n\n\`vitest related\` finds only importers; also run the tests that read a changed file by its path (a text search of the test files for each path). The orchestrator's group gate, pre-push and CI still run the whole gates. To keep the whole gate on every change, add \`${changedId}\` to \`bkit.advisories.ignore\` in package.json.\n\n${GATE_CONTENTS_NOTE}`,
1777
+ });
1778
+ }
631
1779
  return findings;
632
1780
  }
633
1781
 
@@ -665,7 +1813,8 @@ export function detectNoopGates(cwd: string): PreflightFinding[] {
665
1813
  severity: "advisory",
666
1814
  detect: `These bkit:gate scripts are empty or cannot fail, so they check nothing: ${noop.join(", ")}.`,
667
1815
  action:
668
- 'Every bkit workflow and the pre-push hook trust a green `bkit:gate*` script, so a no-op gate passes every agent run and push. Point each at the checks it should run (e.g. `"bkit:gate:static": "pnpm typecheck && pnpm lint"`), or delete it from package.json and run `bkit upgrade` to get bkit\'s default back.',
1816
+ 'Every bkit workflow and the pre-push hook trust a green `bkit:gate*` script, so a no-op gate passes every agent run and push. Point each at the checks it should run (e.g. `"bkit:gate:static": "pnpm typecheck && pnpm lint"`), or delete it from package.json and run `bkit upgrade` to get bkit\'s default back.\n\n' +
1817
+ GATE_CONTENTS_NOTE,
669
1818
  },
670
1819
  ];
671
1820
  }
@@ -757,6 +1906,8 @@ export function runCoreModule(ctx: ModuleContext): void {
757
1906
  // Exclude .bkit/version itself and .agents/ internal files (not consumer-facing).
758
1907
  const newCanonicalEntries: Record<string, string> = {};
759
1908
  for (const entry of ws.writes) {
1909
+ // Brand-migrated copy-and-own files carry no hash.
1910
+ if (entry.unhashed) continue;
760
1911
  const absPath = path.isAbsolute(entry.path) ? entry.path : path.resolve(cwd, entry.path);
761
1912
  const relPath = path.relative(cwd, absPath);
762
1913
  if (relPath === path.join(".bkit", "version")) continue;
@@ -815,7 +1966,7 @@ export function runCoreModule(ctx: ModuleContext): void {
815
1966
  "2. See `.bkit/install.md` for consumer setup and `.bkit/README.md` for ongoing ops.\n\n" +
816
1967
  "Note: bkit seeded the bkit:gate:* / bkit:deps:* package.json scripts every workflow\n" +
817
1968
  "runs (existing values are never touched). The tool scripts they chain (typecheck,\n" +
818
- "lint, format:check, lint:prose, slop:delta) and the devDeps those need are yours to\n" +
1969
+ "lint, format:check, bkit:lint:prose, bkit:slop:delta) and the devDeps those need are yours to\n" +
819
1970
  "add: see .bkit/templates.md.",
820
1971
  });
821
1972
  }