@cbartens/bkit 6.1.0 → 6.2.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 (317) hide show
  1. package/.bkit/README.md +14 -12
  2. package/.bkit/core/.agents/docs.md +1 -11
  3. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +30 -9
  4. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +25 -27
  5. package/.bkit/core/.agents/rules.md +22 -9
  6. package/.bkit/core/.bkit/README.md +13 -11
  7. package/.bkit/core/.bkit/authoring.md +58 -13
  8. package/.bkit/core/.bkit/cli.md +43 -33
  9. package/.bkit/core/.bkit/cloud.md +93 -30
  10. package/.bkit/core/.bkit/install.md +55 -16
  11. package/.bkit/core/.bkit/jsonl.md +24 -7
  12. package/.bkit/core/.bkit/pipeline.md +8 -8
  13. package/.bkit/core/.bkit/prompts.md +160 -43
  14. package/.bkit/core/.bkit/providers.md +99 -36
  15. package/.bkit/core/.bkit/templates.md +167 -37
  16. package/.bkit/core/.bkit/trackers.md +39 -6
  17. package/.bkit/core/.bkit/workflows.md +344 -136
  18. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +50 -27
  19. package/.bkit/core/.claude/hooks/bkit-preflight.sh +11 -11
  20. package/.bkit/core/.codex/hooks/bkit-gateguard.cjs +13 -8
  21. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +14 -25
  22. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +20 -9
  23. package/.bkit/core/.cursor/hooks/bkit-preflight.sh +8 -8
  24. package/.bkit/core/.opencode/plugin/bkit-gateguard.js +14 -4
  25. package/.bkit/core/.opencode/plugin/bkit-guardrails.js +114 -0
  26. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +1 -1
  27. package/.bkit/core/docs/templates/bkit-audit-adoption.md +30 -6
  28. package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
  29. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
  30. package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
  31. package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
  32. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
  33. package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
  34. package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
  35. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +2 -2
  36. package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
  37. package/.bkit/core/docs/templates/bkit-audit-cost.md +1 -1
  38. package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
  39. package/.bkit/core/docs/templates/bkit-audit-database.md +3 -3
  40. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +1 -1
  41. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
  42. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +3 -3
  43. package/.bkit/core/docs/templates/bkit-audit-documentation.md +32 -2
  44. package/.bkit/core/docs/templates/bkit-audit-duplication.md +1 -1
  45. package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
  46. package/.bkit/core/docs/templates/bkit-audit-flakes.md +2 -2
  47. package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -3
  48. package/.bkit/core/docs/templates/bkit-audit-issues.md +1 -1
  49. package/.bkit/core/docs/templates/bkit-audit-llm.md +2 -2
  50. package/.bkit/core/docs/templates/bkit-audit-logs.md +1 -1
  51. package/.bkit/core/docs/templates/bkit-audit-models.md +2 -2
  52. package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
  53. package/.bkit/core/docs/templates/bkit-audit-prompts.md +1 -1
  54. package/.bkit/core/docs/templates/bkit-audit-red-team.md +2 -2
  55. package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
  56. package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
  57. package/.bkit/core/docs/templates/bkit-audit-security.md +1 -1
  58. package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
  59. package/.bkit/core/docs/templates/bkit-audit-testing.md +3 -2
  60. package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
  61. package/.bkit/core/docs/templates/bkit-plan.md +38 -8
  62. package/.bkit/core/engine/checks/after/auth.ts +118 -47
  63. package/.bkit/core/engine/checks/after/github.ts +161 -37
  64. package/.bkit/core/engine/checks/after/index.ts +18 -3
  65. package/.bkit/core/engine/checks/after/tools.ts +245 -1
  66. package/.bkit/core/engine/checks/before/files.ts +59 -1
  67. package/.bkit/core/engine/checks/before/index.ts +8 -0
  68. package/.bkit/core/engine/checks/status-holes.ts +20 -26
  69. package/.bkit/core/engine/checks/tips/catalogue.ts +107 -10
  70. package/.bkit/core/engine/checks/tips/detect.ts +36 -3
  71. package/.bkit/core/engine/checks/tips/index.ts +1 -1
  72. package/.bkit/core/engine/cli.ts +13 -13
  73. package/.bkit/core/engine/commands/ci/ci.ts +124 -19
  74. package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
  75. package/.bkit/core/engine/commands/install/doctor.ts +5 -5
  76. package/.bkit/core/engine/commands/install/install.ts +28 -25
  77. package/.bkit/core/engine/commands/install/uninstall.ts +42 -30
  78. package/.bkit/core/engine/commands/install/upgrade.ts +14 -2
  79. package/.bkit/core/engine/commands/land.ts +2 -3
  80. package/.bkit/core/engine/commands/lib.ts +394 -39
  81. package/.bkit/core/engine/commands/registry.ts +1 -1
  82. package/.bkit/core/engine/commands/workflow/branches.ts +351 -78
  83. package/.bkit/core/engine/commands/workflow/challenge.ts +63 -14
  84. package/.bkit/core/engine/commands/workflow/context.ts +71 -10
  85. package/.bkit/core/engine/commands/workflow/counters.ts +298 -23
  86. package/.bkit/core/engine/commands/workflow/decisions.ts +260 -125
  87. package/.bkit/core/engine/commands/workflow/disk.ts +2 -1
  88. package/.bkit/core/engine/commands/workflow/feature-base.ts +66 -0
  89. package/.bkit/core/engine/commands/workflow/issues.ts +312 -17
  90. package/.bkit/core/engine/commands/workflow/junit.ts +204 -0
  91. package/.bkit/core/engine/commands/workflow/ledgers.ts +904 -99
  92. package/.bkit/core/engine/commands/workflow/locks.ts +186 -29
  93. package/.bkit/core/engine/commands/workflow/loops.ts +87 -0
  94. package/.bkit/core/engine/commands/workflow/open-decision.ts +251 -0
  95. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +8 -0
  96. package/.bkit/core/engine/commands/workflow/plans.ts +1 -1
  97. package/.bkit/core/engine/commands/workflow/prs.ts +311 -16
  98. package/.bkit/core/engine/commands/workflow/repo.ts +1 -1
  99. package/.bkit/core/engine/commands/workflow/run-facts.ts +6 -0
  100. package/.bkit/core/engine/commands/workflow/runs.ts +877 -174
  101. package/.bkit/core/engine/commands/workflow/runtime.ts +12 -4
  102. package/.bkit/core/engine/commands/workflow/status.ts +324 -11
  103. package/.bkit/core/engine/commands/workflow/step-table.ts +41 -15
  104. package/.bkit/core/engine/commands/workflow/steps.ts +604 -29
  105. package/.bkit/core/engine/commands/workflow/summary-findings.ts +1 -1
  106. package/.bkit/core/engine/commands/workflow/summary.ts +314 -8
  107. package/.bkit/core/engine/commands/workflow/tasks.ts +400 -27
  108. package/.bkit/core/engine/commands/workflow/tests-base.ts +319 -0
  109. package/.bkit/core/engine/commands/workflow/tests-changed.ts +138 -74
  110. package/.bkit/core/engine/commands/workflow/tests-jump.ts +93 -0
  111. package/.bkit/core/engine/commands/workflow/tests.ts +815 -182
  112. package/.bkit/core/engine/commands/workflow/tracker.ts +1134 -137
  113. package/.bkit/core/engine/commands/workflow/workflows.ts +100 -72
  114. package/.bkit/core/engine/commands/workflow/worktrees.ts +421 -57
  115. package/.bkit/core/engine/install/cloud-env.ts +38 -10
  116. package/.bkit/core/engine/install/managed-block.ts +105 -0
  117. package/.bkit/core/engine/install/manifest.ts +7 -1
  118. package/.bkit/core/engine/install/modules/claude.ts +6 -2
  119. package/.bkit/core/engine/install/modules/cloud.ts +84 -95
  120. package/.bkit/core/engine/install/modules/codex.ts +10 -2
  121. package/.bkit/core/engine/install/modules/core.ts +202 -26
  122. package/.bkit/core/engine/install/modules/opencode.ts +18 -23
  123. package/.bkit/core/engine/install/network-allowlist.ts +8 -3
  124. package/.bkit/core/engine/install/project-docs.ts +650 -0
  125. package/.bkit/core/engine/install/template-copies.ts +58 -5
  126. package/.bkit/core/engine/install/write.ts +128 -7
  127. package/.bkit/core/engine/ledgers/journal.ts +18 -10
  128. package/.bkit/core/engine/ledgers/migrate.ts +20 -8
  129. package/.bkit/core/engine/ledgers/status.ts +604 -8
  130. package/.bkit/core/engine/ledgers/telemetry.ts +115 -13
  131. package/.bkit/core/engine/render/trackers.ts +46 -11
  132. package/.bkit/core/engine/shared/package-manager.ts +7 -3
  133. package/.bkit/core/engine/shared/settings.ts +12 -1
  134. package/.bkit/core/engine/shared/text.ts +14 -0
  135. package/.bkit/core/engine/tools/instructions-sources.ts +1 -0
  136. package/.bkit/core/engine/tools/instructions.ts +116 -20
  137. package/.bkit/core/hooks/antigravity-hook.js +20 -4
  138. package/.bkit/core/hooks/gateguard-edit-payload.js +8 -5
  139. package/.bkit/core/hooks/gateguard-engine.js +249 -23
  140. package/.bkit/core/hooks/guardrails-deny.js +167 -0
  141. package/.bkit/core/hooks/guardrails-read.js +3 -3
  142. package/.bkit/core/hooks/guardrails-shell.js +1122 -167
  143. package/.bkit/core/hooks/guardrails-tiers.js +247 -176
  144. package/.bkit/core/hooks/preflight-tracker.sh +219 -0
  145. package/.bkit/core/prompts/bkit-audit-generate.md +23 -6
  146. package/.bkit/core/prompts/bkit-build-challenge-1.md +5 -4
  147. package/.bkit/core/prompts/bkit-build-challenge-2.md +6 -5
  148. package/.bkit/core/prompts/bkit-build-install-skills.md +2 -2
  149. package/.bkit/core/prompts/bkit-build-plan-convert.md +21 -7
  150. package/.bkit/core/prompts/bkit-build-plan-current.md +5 -4
  151. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +22 -17
  152. package/.bkit/core/prompts/bkit-build-plan-tasks.md +16 -12
  153. package/.bkit/core/prompts/bkit-build-plan-tests.md +14 -10
  154. package/.bkit/core/prompts/bkit-build-plan-verify.md +21 -8
  155. package/.bkit/core/prompts/bkit-debug-abort-handover.md +10 -5
  156. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +22 -6
  157. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +19 -3
  158. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +22 -6
  159. package/.bkit/core/prompts/bkit-debug-failure-soak.md +10 -7
  160. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +3 -3
  161. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +4 -4
  162. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +3 -3
  163. package/.bkit/core/prompts/bkit-design-generate.md +6 -4
  164. package/.bkit/core/prompts/bkit-design-organise.md +4 -3
  165. package/.bkit/core/prompts/bkit-design-review-1.md +5 -4
  166. package/.bkit/core/prompts/bkit-design-review-2.md +6 -5
  167. package/.bkit/core/prompts/bkit-design-spike.md +4 -3
  168. package/.bkit/core/prompts/bkit-design-update.md +6 -4
  169. package/.bkit/core/prompts/bkit-plan-generate.md +35 -14
  170. package/.bkit/core/prompts/bkit-plan-review-1.md +9 -7
  171. package/.bkit/core/prompts/bkit-plan-review-2.md +9 -7
  172. package/.bkit/core/prompts/bkit-plan-scope-check.md +8 -6
  173. package/.bkit/core/prompts/bkit-plan-update.md +22 -8
  174. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +11 -8
  175. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +9 -5
  176. package/.bkit/core/prompts/bkit-ship-update-docs.md +26 -4
  177. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +3 -3
  178. package/.bkit/core/prompts/bkit-utility-update-decisions.md +10 -7
  179. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +8 -5
  180. package/.bkit/core/prompts/bkit-utility-update-documentation.md +31 -7
  181. package/.bkit/core/prompts/bkit-utility-update-failures.md +8 -5
  182. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +10 -7
  183. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +4 -4
  184. package/.bkit/core/prompts/bkit-utility-update-tracker.md +4 -4
  185. package/.bkit/core/workflows/bkit-auto.md +23 -11
  186. package/.bkit/core/workflows/bkit-build.md +331 -100
  187. package/.bkit/core/workflows/bkit-debug.md +135 -64
  188. package/.bkit/core/workflows/bkit-design.md +58 -32
  189. package/.bkit/core/workflows/bkit-plan.md +73 -45
  190. package/.bkit/core/workflows/bkit-ship.md +233 -167
  191. package/.bkit/shared/.agents/plugins/bkit/hooks.json +1 -1
  192. package/.bkit/shared/.bkit/.env.example +5 -0
  193. package/.bkit/shared/.claude/bkit-cloud.md +7 -7
  194. package/.bkit/shared/.claude/settings.json +5 -1
  195. package/.bkit/shared/.cursor/bkit-cloud.md +1 -1
  196. package/.bkit/shared/.cursor/hooks.json +1 -1
  197. package/.bkit/shared/.opencode/opencode.json +11 -2
  198. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +27 -0
  199. package/.bkit/templates/.cursor/Dockerfile +7 -7
  200. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +1 -1
  201. package/.bkit/templates/.github/dependabot.yml +5 -0
  202. package/.bkit/templates/.github/renovate.json5 +5 -3
  203. package/.bkit/templates/.github/workflows/bkit-ci.yml +11 -11
  204. package/.bkit/templates/.github/workflows/bkit-cloud.yml +525 -161
  205. package/.bkit/templates/.github/workflows/bkit-renovate.yml +2 -2
  206. package/.bkit/templates/.husky/pre-push +123 -6
  207. package/.bkit/templates/context/bkit-serena.md +1 -1
  208. package/.bkit/templates/context/bkit-vercel.md +103 -59
  209. package/.bkit/templates/docs/architecture.md +98 -0
  210. package/.bkit/templates/docs/capabilities.md +33 -37
  211. package/.bkit/templates/docs/components.md +142 -0
  212. package/.bkit/templates/docs/data-schema.md +87 -0
  213. package/.bkit/{shared → templates}/docs/deployments.md +128 -142
  214. package/.bkit/templates/docs/design.md +117 -0
  215. package/.bkit/templates/docs/noise.md +54 -0
  216. package/.bkit/templates/docs/observability.md +99 -0
  217. package/.bkit/templates/docs/security.md +137 -0
  218. package/.bkit/templates/docs/setup.md +93 -0
  219. package/.bkit/templates/docs/technology.md +70 -0
  220. package/.bkit/{shared → templates}/docs/testing.md +200 -87
  221. package/.bkit/templates/scripts/ci/bkit-check-accepted-divergences.mjs +1 -6
  222. package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
  223. package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +314 -28
  224. package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +500 -1
  225. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
  226. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +91 -62
  227. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
  228. package/.bkit/templates/slop-scan.config.json +2 -0
  229. package/CHANGELOG.md +79 -0
  230. package/DETAILS.md +661 -0
  231. package/README.md +73 -604
  232. package/dist/checks/after/auth.js +114 -46
  233. package/dist/checks/after/github.js +138 -35
  234. package/dist/checks/after/index.js +16 -4
  235. package/dist/checks/after/tools.js +224 -1
  236. package/dist/checks/before/files.js +59 -1
  237. package/dist/checks/before/index.js +7 -1
  238. package/dist/checks/status-holes.js +20 -21
  239. package/dist/checks/tips/catalogue.js +99 -10
  240. package/dist/checks/tips/detect.js +35 -3
  241. package/dist/checks/tips/index.js +1 -1
  242. package/dist/cli.js +13 -13
  243. package/dist/commands/ci/ci.js +113 -20
  244. package/dist/commands/ci/push-gate.js +79 -44
  245. package/dist/commands/install/doctor.js +5 -5
  246. package/dist/commands/install/install.js +23 -22
  247. package/dist/commands/install/uninstall.js +36 -30
  248. package/dist/commands/install/upgrade.js +10 -2
  249. package/dist/commands/land.js +2 -3
  250. package/dist/commands/lib.js +323 -25
  251. package/dist/commands/workflow/branches.js +312 -72
  252. package/dist/commands/workflow/challenge.js +66 -13
  253. package/dist/commands/workflow/context.js +46 -10
  254. package/dist/commands/workflow/counters.js +231 -23
  255. package/dist/commands/workflow/decisions.js +221 -106
  256. package/dist/commands/workflow/disk.js +2 -1
  257. package/dist/commands/workflow/feature-base.js +60 -0
  258. package/dist/commands/workflow/issues.js +243 -15
  259. package/dist/commands/workflow/junit.js +137 -0
  260. package/dist/commands/workflow/ledgers.js +726 -112
  261. package/dist/commands/workflow/locks.js +150 -29
  262. package/dist/commands/workflow/loops.js +67 -0
  263. package/dist/commands/workflow/open-decision.js +199 -0
  264. package/dist/commands/workflow/plan-blocks.js +6 -0
  265. package/dist/commands/workflow/plans.js +1 -1
  266. package/dist/commands/workflow/prs.js +272 -16
  267. package/dist/commands/workflow/repo.js +1 -1
  268. package/dist/commands/workflow/run-facts.js +6 -0
  269. package/dist/commands/workflow/runs.js +747 -155
  270. package/dist/commands/workflow/runtime.js +8 -4
  271. package/dist/commands/workflow/status.js +259 -13
  272. package/dist/commands/workflow/step-table.js +41 -15
  273. package/dist/commands/workflow/steps.js +530 -26
  274. package/dist/commands/workflow/summary-findings.js +1 -1
  275. package/dist/commands/workflow/summary.js +289 -8
  276. package/dist/commands/workflow/tasks.js +294 -27
  277. package/dist/commands/workflow/tests-base.js +266 -0
  278. package/dist/commands/workflow/tests-changed.js +130 -56
  279. package/dist/commands/workflow/tests-jump.js +77 -0
  280. package/dist/commands/workflow/tests.js +608 -131
  281. package/dist/commands/workflow/tracker.js +920 -112
  282. package/dist/commands/workflow/workflows.js +80 -59
  283. package/dist/commands/workflow/worktrees.js +387 -58
  284. package/dist/install/cloud-env.js +32 -10
  285. package/dist/install/managed-block.js +101 -0
  286. package/dist/install/manifest.js +7 -1
  287. package/dist/install/modules/claude.js +6 -2
  288. package/dist/install/modules/cloud.js +73 -86
  289. package/dist/install/modules/codex.js +9 -2
  290. package/dist/install/modules/core.js +190 -27
  291. package/dist/install/modules/opencode.js +18 -23
  292. package/dist/install/network-allowlist.js +8 -3
  293. package/dist/install/project-docs.js +551 -0
  294. package/dist/install/template-copies.js +55 -5
  295. package/dist/install/write.js +117 -5
  296. package/dist/ledgers/journal.js +10 -8
  297. package/dist/ledgers/migrate.js +20 -9
  298. package/dist/ledgers/status.js +461 -8
  299. package/dist/ledgers/telemetry.js +71 -13
  300. package/dist/render/trackers.js +21 -12
  301. package/dist/shared/package-manager.js +7 -2
  302. package/dist/shared/settings.js +8 -0
  303. package/dist/shared/text.js +13 -0
  304. package/dist/tools/instructions-sources.js +1 -0
  305. package/dist/tools/instructions.js +97 -24
  306. package/package.json +23 -15
  307. package/.bkit/core/hooks/preflight-linear.sh +0 -73
  308. package/.bkit/shared/docs/architecture.md +0 -16
  309. package/.bkit/shared/docs/data-schema.md +0 -16
  310. package/.bkit/shared/docs/design.md +0 -38
  311. package/.bkit/shared/docs/noise.md +0 -20
  312. package/.bkit/shared/docs/observability.md +0 -22
  313. package/.bkit/shared/docs/security.md +0 -62
  314. package/.bkit/shared/docs/setup.md +0 -52
  315. package/.bkit/shared/docs/technology.md +0 -15
  316. /package/.bkit/templates/{.lintstagedrc.json → lintstagedrc.example.json} +0 -0
  317. /package/.bkit/templates/{.prettierignore → prettierignore.example} +0 -0
@@ -118,11 +118,17 @@ const LINT_STAGED_CONFIGS = [
118
118
  ".lintstagedrc.yaml",
119
119
  ".lintstagedrc.yml",
120
120
  ".lintstagedrc.mjs",
121
- ".lintstagedrc.cjs",
121
+ ".lintstagedrc.mts",
122
122
  ".lintstagedrc.js",
123
+ ".lintstagedrc.ts",
124
+ ".lintstagedrc.cjs",
125
+ ".lintstagedrc.cts",
123
126
  "lint-staged.config.mjs",
124
- "lint-staged.config.cjs",
127
+ "lint-staged.config.mts",
125
128
  "lint-staged.config.js",
129
+ "lint-staged.config.ts",
130
+ "lint-staged.config.cjs",
131
+ "lint-staged.config.cts",
126
132
  ];
127
133
  /** True when any `.github/workflows/*.yml` / `*.yaml` contains `needle`. */
128
134
  export function anyWorkflowMentions(cwd, needle) {
@@ -134,10 +140,12 @@ export function anyWorkflowMentions(cwd, needle) {
134
140
  .filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))
135
141
  .some((f) => readText(cwd, path.join(".github", "workflows", f)).includes(needle));
136
142
  }
137
- /** True when lint-staged is configured: any of its config files, or `package.json` `lint-staged`. */
143
+ /** True when lint-staged is configured: any of its config files, `package.json` or `package.yaml` / `package.yml` `lint-staged` key. */
138
144
  export function hasLintStagedConfig(cwd) {
139
145
  if (LINT_STAGED_CONFIGS.some((rel) => exists(cwd, rel)))
140
146
  return true;
147
+ if (["package.yaml", "package.yml"].some((rel) => /^lint-staged\s*:/m.test(readText(cwd, rel))))
148
+ return true;
141
149
  const pkg = readPackageJson(cwd);
142
150
  return pkg.ok && pkg.pkg["lint-staged"] !== undefined;
143
151
  }
@@ -202,6 +210,30 @@ export function readsBkitText(cwd) {
202
210
  return text.split("\n").some((line) => READS_BKIT_TEXT.some((re) => re.test(line)));
203
211
  });
204
212
  }
213
+ /** `.agents/rules.md` below `<!-- bkit:end -->` with HTML comments removed; null without the file. */
214
+ function rulesBelowEnd(cwd) {
215
+ const text = readText(cwd, ".agents/rules.md");
216
+ if (!text)
217
+ return null;
218
+ const end = text.indexOf("<!-- bkit:end -->");
219
+ return (end === -1 ? text : text.slice(end)).replace(/<!--[\s\S]*?-->/g, "");
220
+ }
221
+ /** True when the rules file already has a `## Project Goals` heading below `<!-- bkit:end -->`. */
222
+ export function hasProjectGoalsHeading(cwd) {
223
+ return /^## Project Goals/m.test(rulesBelowEnd(cwd) ?? "");
224
+ }
225
+ /**
226
+ * True when `.agents/rules.md` exists and no `## Project Goals` section, read below
227
+ * `<!-- bkit:end -->`, holds a list item (`-`, `*`, `+` or `1.` / `1)`) once HTML comments
228
+ * are removed.
229
+ */
230
+ export function hasNoProjectGoals(cwd) {
231
+ const below = rulesBelowEnd(cwd);
232
+ if (below === null)
233
+ return false;
234
+ const sections = [...below.matchAll(/^## Project Goals[^\n]*\n([\s\S]*?)(?=^## |(?![\s\S]))/gm)];
235
+ return !sections.some((m) => /^\s*(?:[-*+]|\d+[.)])\s/m.test(m[1] ?? ""));
236
+ }
205
237
  /**
206
238
  * True when `.bkit/friction.jsonl` holds an entry worth sending to bkit: its fold winner
207
239
  * is `OPEN` (or has no status) and its `scope` is not `consumer`. A shared entry gets a
@@ -94,7 +94,7 @@ export function collectTips(cwd, catalogue = SETUP_TIPS) {
94
94
  if (isTipSilenced(tip, ignored))
95
95
  suppressed.push({ id: tip.id, scope: "." });
96
96
  else
97
- tips.push(tip);
97
+ tips.push(tip.resolve ? { ...tip, ...tip.resolve(base) } : tip);
98
98
  }
99
99
  const star = !ignored.has(STAR_TIP_ID) && !ignored.has(STAR_TIP_OLD_ID);
100
100
  return { tips, suppressed, star };
package/dist/cli.js CHANGED
@@ -19,7 +19,7 @@ import { runInstall } from "./commands/install/install.js";
19
19
  import { OPTIN_MODULES } from "./install/manifest.js";
20
20
  import { OPENCODE_PROVIDERS } from "./shared/egress.js";
21
21
  /** Cloud-agent variant chosen via `--auto=<variant>`. */
22
- export const CLOUD_VARIANTS = ["claude", "cursor", "opencode"];
22
+ export const CLOUD_VARIANTS = ["claude", "cursor", "opencode", "codex"];
23
23
  /** Narrow an unknown string to `CloudVariant` or return `null` if invalid. */
24
24
  export function parseCloudVariant(value) {
25
25
  return typeof value === "string" && CLOUD_VARIANTS.includes(value)
@@ -424,7 +424,7 @@ export const CLASSIC_VERB_HELP = [
424
424
  "--antigravity",
425
425
  "--cursor",
426
426
  "--opencode=<provider>",
427
- "--auto=<claude|cursor|opencode>",
427
+ "--auto=<claude|cursor|opencode|codex>",
428
428
  "--tracker=<name>",
429
429
  "--auto-revert",
430
430
  ],
@@ -480,7 +480,7 @@ export const CLASSIC_VERB_HELP = [
480
480
  "--antigravity",
481
481
  "--cursor",
482
482
  "--opencode=<provider>",
483
- "--auto=<claude|cursor|opencode>",
483
+ "--auto=<claude|cursor|opencode|codex>",
484
484
  "--dry-run",
485
485
  "--force",
486
486
  "--nuke",
@@ -658,7 +658,7 @@ Module flags (composable; symmetric install ↔ uninstall):
658
658
  opencode-zen, opencode-go (opencode-native gateways;
659
659
  auth via BKIT_OPENCODE_API_KEY).
660
660
  Ships .opencode/** (agents, commands, opencode.json, bkit-gateguard.js,
661
- bkit-readguard.js).
661
+ bkit-readguard.js, bkit-guardrails.js).
662
662
  Configure your provider key; verify with \`bkit doctor\`. All installed
663
663
  providers tracked in bkit.providers.opencode.installed.
664
664
  --codex Codex CLI host. BARE flag — takes no value: Codex runs on one gateway
@@ -682,14 +682,14 @@ Dependency updaters (copy an example and own it):
682
682
  blocks when that value and the configs disagree.
683
683
  All templates and install steps: .bkit/templates.md
684
684
 
685
- --auto=<claude|cursor|opencode>
686
- Cloud-agent (auto-dispatch) integration (opt-in). --auto=claude needs
687
- tracker=github + the ANTHROPIC_API_KEY repo secret (or the
688
- ANTHROPIC_FEDERATION_RULE_ID + ANTHROPIC_ORGANIZATION_ID repo variables
689
- for keyless federation) + the Claude GitHub App; --auto=cursor
690
- needs tracker=linear; --auto=opencode needs tracker=github + a remote
691
- opencode provider (OPENCODE_PROVIDER_KEY). Bare --auto is accepted on
692
- uninstall only.
685
+ --auto=<claude|cursor|opencode|codex>
686
+ Cloud-agent (auto-dispatch) integration (opt-in). Every variant needs
687
+ a wired tracker (github, linear or jira). Claude needs the
688
+ BKIT_ANTHROPIC_API_KEY repo secret or the ANTHROPIC_FEDERATION_RULE_ID
689
+ + ANTHROPIC_ORGANIZATION_ID repo variables, plus the Claude GitHub App.
690
+ Codex needs --codex and BKIT_OPENAI_API_KEY. OpenCode needs --opencode
691
+ and its configured provider's BKIT_ key. Cursor uses its dashboard
692
+ triggers. Bare --auto is accepted on uninstall only.
693
693
 
694
694
  Cross-cutting / modifiers:
695
695
  --tracker=<name> Wire issue tracker integration. Values: github, linear, jira, none
@@ -786,7 +786,7 @@ export function validateModuleFlagsForVerb(verb, moduleFlags, tracker = null) {
786
786
  // The CLI entrypoint, run only when this file is executed and driven by real
787
787
  // argv/fs/process.exit side effects; install.integration.test.ts exercises it through
788
788
  // spawned processes. Pure decision logic lives in exported functions
789
- // (validateModuleFlagsForVerb above, validateCloudTrackerMatch in commands/install/install.ts)
789
+ // (validateModuleFlagsForVerb above, validateCloudTrackerWired in commands/install/install.ts)
790
790
  // for unit coverage.
791
791
  export async function main() {
792
792
  const commandExit = await runCommand(process.argv.slice(2), COMMANDS, {
@@ -9,15 +9,15 @@
9
9
  // zero. The pre-existing baseline is never the change's to fix. On failure it names each
10
10
  // net-new or worsened finding (`path:line`, rule, message), with line shifts dropped.
11
11
  //
12
- // `prose` — the prose gate (`bkit:lint:prose`): Vale over the markdown files the globs
13
- // select. Restores the gitignored write-good package from the main worktree (else
12
+ // `prose` — the prose gate (`bkit:lint:prose`): Vale over tracked and unignored markdown,
13
+ // or explicit globs. Restores the gitignored write-good package from the main worktree (else
14
14
  // `vale sync`) when it is missing, and fails when vale or write-good is unavailable.
15
15
  //
16
16
  // `skip-token` — whether a commit message carries a GitHub skip-CI token
17
17
  // (`SKIP_CI_TOKEN`), for the `.husky/pre-push` CI-suppressor guard.
18
18
  //
19
19
  // `min-push` — whether every file a push changes is one bkit's workflows write (ship's bookkeeping
20
- // allow-list, the plans tree) or one `bkit.testing.minPushPaths` / `ciSkipPaths` adds, so
20
+ // allow-list, the plans tree, the audit reports) or one `bkit.testing.minPushPaths` / `ciSkipPaths` adds, so
21
21
  // `.husky/pre-push` runs `bkit:gate:min`. Files decide, never `[skip ci]` (a typed label
22
22
  // GitHub reads off the last commit only).
23
23
  //
@@ -33,9 +33,11 @@ import { spawnSync } from "node:child_process";
33
33
  import * as fs from "node:fs";
34
34
  import * as os from "node:os";
35
35
  import * as path from "node:path";
36
+ import { gitEnv } from "../../ledgers/telemetry.js";
36
37
  import { readBkitConfig } from "../../shared/settings.js";
37
- import { CommandError, commitMessage, EXIT, git, parseJson, runGit, SKIP_CI_TOKEN, } from "../lib.js";
38
- import { bookPathspecs, changedOutside, checkOnlyBookkeeping, globPathspecs, } from "../workflow/ledgers.js";
38
+ import { CommandError, commitMessage, EXIT, OUTPUT_LIMIT, git, parseJson, runGit, SKIP_CI_TOKEN, } from "../lib.js";
39
+ import { bookPathspecs, changedOutside, checkOnlyBookkeeping, gitRaw, globPathspecs, } from "../workflow/ledgers.js";
40
+ import { managedHead } from "../../install/managed-block.js";
39
41
  import { pins } from "./pins.js";
40
42
  import { hasVerifiedIncrement, runPushGate } from "./push-gate.js";
41
43
  /** Exit code: slop-scan could not be started (not installed, not executable). */
@@ -197,7 +199,7 @@ const tail = (text) => text.trim().split("\n").slice(-20).join("\n");
197
199
  * the signal would. Without the listeners Node dies on the signal and leaves the base
198
200
  * worktree registered in the repo.
199
201
  */
200
- async function withCleanup(body, cleanup) {
202
+ export async function withCleanup(body, cleanup) {
201
203
  const received = [];
202
204
  const onSignal = (sig) => received.push(sig);
203
205
  for (const sig of CLEANUP_SIGNALS)
@@ -371,11 +373,15 @@ function globWalk(glob) {
371
373
  * Every file under `root` down to `depth` levels (relative to `cwd`, `/`-separated).
372
374
  * Skips WALK_SKIP folders and never follows a symlinked folder.
373
375
  */
374
- function walkFiles(cwd, root, depth) {
376
+ function walkFiles(cwd, root, depth, skipCheckouts = false) {
375
377
  const out = [];
376
378
  const visit = (rel, level) => {
377
379
  const abs = path.join(cwd, rel);
378
- if (!fs.existsSync(abs))
380
+ if (!fs.lstatSync(abs, { throwIfNoEntry: false }))
381
+ return;
382
+ if (skipCheckouts &&
383
+ rel !== "." &&
384
+ fs.lstatSync(path.join(abs, ".git"), { throwIfNoEntry: false }))
379
385
  return;
380
386
  for (const ent of fs.readdirSync(abs, { withFileTypes: true })) {
381
387
  const child = rel === "." ? ent.name : `${rel}/${ent.name}`;
@@ -391,8 +397,44 @@ function walkFiles(cwd, root, depth) {
391
397
  visit(root, 1);
392
398
  return out;
393
399
  }
394
- /** The files the globs select under `cwd`, `/`-separated, sorted, each once. */
400
+ /** Default prose uses tracked and unignored files; explicit globs select directly from disk. */
395
401
  export function proseFiles(cwd, globs) {
402
+ if (!globs) {
403
+ let ancestor = path.resolve(cwd);
404
+ while (!fs.lstatSync(path.join(ancestor, ".git"), { throwIfNoEntry: false })) {
405
+ const parent = path.dirname(ancestor);
406
+ if (parent === ancestor) {
407
+ return walkFiles(cwd, ".", Infinity, true)
408
+ .filter((rel) => rel.endsWith(".md"))
409
+ .sort();
410
+ }
411
+ ancestor = parent;
412
+ }
413
+ const listed = spawnSync("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
414
+ cwd,
415
+ encoding: "utf-8",
416
+ env: gitEnv(),
417
+ maxBuffer: OUTPUT_LIMIT,
418
+ });
419
+ if (listed.error || listed.status !== 0) {
420
+ throw new Error(`cannot list prose sources: ${listed.error?.message ?? listed.stderr}`);
421
+ }
422
+ return [...new Set(listed.stdout.split("\0"))]
423
+ .filter((rel) => {
424
+ if (!rel.endsWith(".md") || rel.split("/").some((part) => WALK_SKIP.has(part)))
425
+ return false;
426
+ for (let parent = path.dirname(rel); parent !== "."; parent = path.dirname(parent)) {
427
+ const dir = fs.lstatSync(path.join(cwd, parent), { throwIfNoEntry: false });
428
+ if (!dir?.isDirectory())
429
+ return false;
430
+ if (fs.lstatSync(path.join(cwd, parent, ".git"), { throwIfNoEntry: false }))
431
+ return false;
432
+ }
433
+ const stat = fs.lstatSync(path.join(cwd, rel), { throwIfNoEntry: false });
434
+ return stat?.isFile() === true || stat?.isSymbolicLink() === true;
435
+ })
436
+ .sort();
437
+ }
396
438
  const files = new Set();
397
439
  for (const given of globs) {
398
440
  const glob = given.replace(/^\.\//, "");
@@ -444,7 +486,15 @@ function prose(ctx) {
444
486
  if (!restoreWriteGood(ctx)) {
445
487
  return unavailable("write-good-missing", "PROSE LINT UNAVAILABLE: vale is installed but .vale/styles/write-good could not be restored (main-worktree copy and vale sync both failed). Run: vale sync");
446
488
  }
447
- const files = proseFiles(ctx.cwd, globs);
489
+ let files;
490
+ try {
491
+ files = proseFiles(ctx.cwd, globs === DEFAULT_PROSE_GLOBS ? undefined : globs);
492
+ for (const rel of files)
493
+ fs.accessSync(path.join(ctx.cwd, rel), fs.constants.R_OK);
494
+ }
495
+ catch (error) {
496
+ return unavailable("source-unavailable", `PROSE LINT UNAVAILABLE: ${String(error)}`);
497
+ }
448
498
  if (files.length === 0) {
449
499
  return skip("no-files", `no files match ${globs.join(" ")} - nothing to lint`);
450
500
  }
@@ -477,14 +527,14 @@ function skipToken(ctx) {
477
527
  /**
478
528
  * The min-push pathspecs: ship's `pr` bookkeeping allow-list for every month and feature
479
529
  * (the same list `bkit ci bookkeeping-push` and the ship gate accept untested, including
480
- * `bkit.testing.ciSkipPaths`), the plans tree bkit's workflows write, and whatever the repo
530
+ * `bkit.testing.ciSkipPaths`), the plans tree and audit reports bkit's workflows write, and whatever the repo
481
531
  * adds in `bkit.testing.minPushPaths` (`:(glob)` unless an entry carries its own magic).
482
532
  * The engine hardcodes no consumer file: the floor is what bkit itself writes.
483
533
  */
484
534
  export function minPushPathspecs(cfg) {
485
535
  return [
486
536
  ...bookPathspecs("*", "*", "pr", cfg.ciSkipPaths),
487
- ...globPathspecs(["docs/plans/**", ...cfg.minPushPaths]),
537
+ ...globPathspecs(["docs/plans/**", "docs/audits/**", ...cfg.minPushPaths]),
488
538
  ];
489
539
  }
490
540
  /** Where a pushed commit's range starts: its merge-base with origin/dev, else origin/main. */
@@ -498,6 +548,36 @@ export function pushBase(cwd, sha) {
498
548
  }
499
549
  return null;
500
550
  }
551
+ /** An audit template the project owns below its managed block; no other template qualifies. */
552
+ const AUDIT_TEMPLATE_RE = /^docs\/templates\/bkit-audit-[^/]+\.md$/;
553
+ /**
554
+ * `changedOutside` plus the audit-template exception: a top-level `docs/templates/bkit-audit-*.md`
555
+ * present at both commits whose text through the `bkit:end` line is identical at both (so only
556
+ * the project section below it changed) is moved from `outside` to `sections`.
557
+ */
558
+ export function minPushOutside(root, from, to, paths) {
559
+ const diff = changedOutside(root, from, to, paths);
560
+ if (!diff.ok)
561
+ return diff;
562
+ const sections = [];
563
+ const outside = [];
564
+ const head = (sha, file) => {
565
+ const res = gitRaw(root, ["cat-file", "blob", `${sha}:${file}`]);
566
+ return res.status === 0 ? managedHead(res.stdout) : null;
567
+ };
568
+ for (const file of diff.outside) {
569
+ if (AUDIT_TEMPLATE_RE.test(file)) {
570
+ const before = head(from, file);
571
+ if (before !== null && before === head(to, file)) {
572
+ sections.push(file);
573
+ continue;
574
+ }
575
+ }
576
+ outside.push(file);
577
+ }
578
+ return { ok: true, changed: diff.changed, outside, sections };
579
+ }
580
+ const sectionNote = (file) => `${file}: only its project section below <!-- bkit:end --> changed`;
501
581
  function minPush(ctx) {
502
582
  const top = runGit(ctx.cwd, ["rev-parse", "--show-toplevel"]);
503
583
  if (!top.ok)
@@ -515,10 +595,11 @@ function minPush(ctx) {
515
595
  }
516
596
  const changed = new Set();
517
597
  const outside = new Set();
598
+ const sections = new Set();
518
599
  for (const ref of refs) {
519
600
  const sha = git(ctx.cwd, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
520
601
  const base = sha ? (baseFlag ?? pushBase(ctx.cwd, sha)) : null;
521
- const diff = sha && base ? changedOutside(top.stdout, base, sha, paths) : null;
602
+ const diff = sha && base ? minPushOutside(top.stdout, base, sha, paths) : null;
522
603
  if (!diff?.ok) {
523
604
  const why = !sha
524
605
  ? `cannot read commit '${ref}'`
@@ -533,7 +614,11 @@ function minPush(ctx) {
533
614
  changed.add(p);
534
615
  for (const p of diff.outside)
535
616
  outside.add(p);
617
+ for (const p of diff.sections)
618
+ sections.add(p);
536
619
  }
620
+ for (const p of [...sections].sort())
621
+ ctx.log(sectionNote(p));
537
622
  const result = (reason, code, message) => {
538
623
  ctx.log(message);
539
624
  ctx.emit({
@@ -557,6 +642,7 @@ function minPush(ctx) {
557
642
  function minPushUpdates(ctx, cwd, updates, paths) {
558
643
  const changed = new Set();
559
644
  const outside = new Set();
645
+ const sections = new Set();
560
646
  let unknown = false;
561
647
  let failed = false;
562
648
  for (const update of updates) {
@@ -571,13 +657,16 @@ function minPushUpdates(ctx, cwd, updates, paths) {
571
657
  unknown = true;
572
658
  continue;
573
659
  }
574
- const increment = isNew ? null : changedOutside(cwd, oldSha, newSha, paths);
660
+ const increment = isNew ? null : minPushOutside(cwd, oldSha, newSha, paths);
575
661
  const base = pushBase(cwd, newSha);
576
- const whole = base ? changedOutside(cwd, base, newSha, paths) : null;
577
- if (hasVerifiedIncrement(cwd, oldSha, newSha, paths)) {
662
+ const whole = base ? minPushOutside(cwd, base, newSha, paths) : null;
663
+ if (hasVerifiedIncrement(cwd, oldSha, newSha, (a, b) => minPushOutside(cwd, a, b, paths))) {
578
664
  if (increment?.ok)
579
665
  for (const file of increment.changed)
580
666
  changed.add(file);
667
+ if (increment?.ok)
668
+ for (const file of increment.sections)
669
+ sections.add(file);
581
670
  ctx.log(`${oldSha}..${newSha}: covered by a successful full push gate`);
582
671
  continue;
583
672
  }
@@ -586,6 +675,8 @@ function minPushUpdates(ctx, cwd, updates, paths) {
586
675
  changed.add(file);
587
676
  for (const file of whole.outside)
588
677
  outside.add(file);
678
+ for (const file of whole.sections)
679
+ sections.add(file);
589
680
  if (whole.changed.length > 0 &&
590
681
  whole.outside.length === 0 &&
591
682
  (isNew || (increment?.ok && increment.changed.length > 0)))
@@ -595,6 +686,8 @@ function minPushUpdates(ctx, cwd, updates, paths) {
595
686
  unknown = true;
596
687
  failed = true;
597
688
  }
689
+ for (const file of [...sections].sort())
690
+ ctx.log(sectionNote(file));
598
691
  const reason = !failed ? null : unknown ? "unknown" : outside.size ? "outside" : "no-changes";
599
692
  ctx.emit({
600
693
  minPush: !failed,
@@ -684,7 +777,7 @@ export const ciCommand = {
684
777
  run: slop,
685
778
  },
686
779
  prose: {
687
- summary: "Run Vale over the markdown files the globs select; fail when Vale or required styles are unavailable.",
780
+ summary: "Run Vale over tracked and unignored Markdown, or explicit globs; fail when sources, Vale or required styles are unavailable.",
688
781
  use: "by-hand",
689
782
  flags: [
690
783
  {
@@ -734,11 +827,11 @@ export const ciCommand = {
734
827
  },
735
828
  ],
736
829
  output: {
737
- minPush: "true when every changed file matches a min-push path",
830
+ minPush: "true when every changed file matches a min-push path, or is a docs/templates/bkit-audit-*.md changed only below its <!-- bkit:end -->",
738
831
  reason: "null when a min push; else no-changes | outside | unknown",
739
832
  changed: "files the push changes, across every ref",
740
- outside: "the changed files no min-push path matches",
741
- paths: "the min-push pathspecs in force: ship's pr bookkeeping allow-list (with bkit.testing.ciSkipPaths), docs/plans/**, bkit.testing.minPushPaths",
833
+ outside: "the changed files no min-push path matches (an audit template changed only below its <!-- bkit:end --> is not listed)",
834
+ paths: "the min-push pathspecs in force: ship's pr bookkeeping allow-list (with bkit.testing.ciSkipPaths), docs/plans/**, docs/audits/**, bkit.testing.minPushPaths",
742
835
  },
743
836
  exitCodes: {
744
837
  [EXIT_RANGE_UNKNOWN]: "a pushed commit, its base, or its git diff could not be read",
@@ -1,15 +1,14 @@
1
1
  // Local full-gate receipts, shared by linked worktrees and bound to committed trees.
2
- import { spawnSync } from "node:child_process";
3
2
  import { createHash, randomUUID } from "node:crypto";
4
3
  import * as fs from "node:fs";
5
- import * as os from "node:os";
6
4
  import * as path from "node:path";
7
5
  import { gitEnv } from "../../ledgers/telemetry.js";
8
6
  import { parseJson, readJsonFile } from "../../shared/json.js";
9
7
  import { readPackageJson } from "../../shared/package-json.js";
10
- import { scriptCommand, testCommand } from "../../shared/package-manager.js";
11
- import { EXIT, git, outboxRoot, runGit } from "../lib.js";
12
- import { changedOutside } from "../workflow/ledgers.js";
8
+ import { scriptCommand } from "../../shared/package-manager.js";
9
+ import { EXIT, git, LOCK_STATUS_FILE_ENV, outboxRoot, runGit } from "../lib.js";
10
+ import { pidAlive } from "../workflow/disk.js";
11
+ import { runGateUnderLock } from "../workflow/junit.js";
13
12
  const UNIT = "bkit:gate:static-unit";
14
13
  const INTEGRATION = "bkit:gate:static-unit-integration";
15
14
  const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
@@ -42,29 +41,48 @@ const receiptPath = (cwd, sha) => {
42
41
  const outbox = outboxRoot(cwd);
43
42
  return outbox ? path.join(outbox, "push-gates", `${sha}.json`) : null;
44
43
  };
45
- function cleanHead(cwd) {
46
- const status = git(cwd, [
47
- "status",
48
- "--porcelain",
49
- "--untracked-files=all",
50
- "--ignore-submodules=none",
51
- ]);
52
- if (status !== "")
44
+ const STATUS = [
45
+ "status",
46
+ "--porcelain",
47
+ "--no-renames",
48
+ "--untracked-files=all",
49
+ "--ignore-submodules=none",
50
+ ];
51
+ const lineCount = (text) => text === null ? -1 : text === "" ? 0 : text.split("\n").length;
52
+ /** HEAD when every uncommitted path lies inside `tolerated` (none given: the tree must be clean). */
53
+ function cleanHead(cwd, tolerated = []) {
54
+ const all = lineCount(git(cwd, STATUS));
55
+ if (all < 0)
53
56
  return null;
57
+ if (all > 0) {
58
+ if (tolerated.length === 0)
59
+ return null;
60
+ if (lineCount(git(cwd, [...STATUS, "--", ...tolerated])) !== all)
61
+ return null;
62
+ }
54
63
  const sha = git(cwd, ["rev-parse", "--verify", "HEAD^{commit}"]);
55
64
  const tree = git(cwd, ["rev-parse", "--verify", "HEAD^{tree}"]);
56
65
  return sha && tree ? { sha, tree } : null;
57
66
  }
58
- /** Execute a consumer gate; only a successful deepest full gate on an unchanged clean tree earns proof. */
59
- export function runPushGate(cwd, gate, log) {
67
+ /** The recorded runner's process id of a `.running` attempt file; null when unreadable. */
68
+ function attemptPid(file) {
69
+ const read = readJsonFile(file);
70
+ if (!read.ok || !read.value || typeof read.value !== "object")
71
+ return null;
72
+ const pid = read.value.pid;
73
+ return typeof pid === "number" && Number.isInteger(pid) && pid > 0 ? pid : null;
74
+ }
75
+ /**
76
+ * Run a gate through `run` and record its receipt: the `.running` marker while it runs, a
77
+ * `.failed` marker when it fails, the before/after HEAD and fingerprint check, and the
78
+ * receipt write. An attempt on the same commit whose runner process is gone counts as a
79
+ * failed run and is cleared. Uncommitted paths in `tolerated` do not block the receipt; a
80
+ * lock wait (`waited`, default never) leaves the receipt and markers as they were.
81
+ */
82
+ export function runWithReceipt(cwd, gate, tolerated, run, log, waited = () => false) {
60
83
  const pkg = readPackageJson(cwd);
61
- const script = pkg.ok ? scriptsOf(pkg.pkg)?.[gate] : null;
62
- if (typeof script !== "string" || script.trim() === "") {
63
- log(`package.json must declare a non-empty ${gate} script`);
64
- return EXIT.USAGE;
65
- }
66
84
  const definition = pkg.ok ? gateDefinition(pkg.pkg) : null;
67
- const before = cleanHead(cwd);
85
+ const before = cleanHead(cwd, tolerated);
68
86
  const head = git(cwd, ["rev-parse", "--verify", "HEAD^{commit}"]);
69
87
  const file = head ? receiptPath(cwd, head) : null;
70
88
  const attempt = file && definition?.gate === gate ? path.join(`${file}.running`, randomUUID()) : null;
@@ -76,33 +94,30 @@ export function runPushGate(cwd, gate, log) {
76
94
  fs.rmSync(file, { force: true });
77
95
  };
78
96
  if (attempt) {
79
- fs.mkdirSync(path.dirname(attempt), { recursive: true });
97
+ const dir = path.dirname(attempt);
98
+ fs.mkdirSync(dir, { recursive: true });
99
+ for (const entry of fs.readdirSync(dir)) {
100
+ const pid = attemptPid(path.join(dir, entry));
101
+ if (pid === null || pidAlive(pid))
102
+ continue;
103
+ fs.rmSync(path.join(dir, entry), { force: true });
104
+ fail();
105
+ }
80
106
  fs.writeFileSync(attempt, JSON.stringify({ pid: process.pid, sha: head }) + "\n");
81
- fail();
82
107
  }
83
108
  const finish = (code) => {
84
109
  if (attempt)
85
110
  fs.rmSync(attempt, { force: true });
86
111
  return code;
87
112
  };
88
- const argv = testCommand(scriptCommand(gate));
89
- log(`running ${scriptCommand(gate).join(" ")}`);
90
- const result = spawnSync(argv[0], argv.slice(1), {
91
- cwd,
92
- env: gitEnv(),
93
- stdio: ["ignore", 2, 2],
94
- });
95
- const status = result.error
96
- ? 127
97
- : (result.status ??
98
- 128 + ((result.signal ? os.constants.signals[result.signal] : undefined) ?? 1));
99
- if (result.error)
100
- log(result.error.message);
113
+ const status = run();
114
+ if (waited(status))
115
+ return finish(status);
101
116
  if (status !== 0 || !before || definition?.gate !== gate) {
102
117
  fail();
103
118
  return finish(status);
104
119
  }
105
- const after = cleanHead(cwd);
120
+ const after = cleanHead(cwd, tolerated);
106
121
  const afterPkg = readPackageJson(cwd);
107
122
  if (after?.sha !== before.sha ||
108
123
  after.tree !== before.tree ||
@@ -120,6 +135,26 @@ export function runPushGate(cwd, gate, log) {
120
135
  }
121
136
  return finish(status);
122
137
  }
138
+ /**
139
+ * Execute a consumer gate; only a successful deepest full gate on an unchanged clean tree earns
140
+ * proof. A tests-lock wait (the lock wrapper gave up, exit 75) leaves the receipt and its
141
+ * markers as they were, and its status file is handed on to a caller that asked for one.
142
+ */
143
+ export function runPushGate(cwd, gate, log) {
144
+ const pkg = readPackageJson(cwd);
145
+ const script = pkg.ok ? scriptsOf(pkg.pkg)?.[gate] : null;
146
+ if (typeof script !== "string" || script.trim() === "") {
147
+ log(`package.json must declare a non-empty ${gate} script`);
148
+ return EXIT.USAGE;
149
+ }
150
+ const env = gitEnv();
151
+ const lock = {};
152
+ return runWithReceipt(cwd, gate, [], () => {
153
+ log(`running ${scriptCommand(gate).join(" ")}`);
154
+ lock.run = runGateUnderLock(scriptCommand(gate), cwd, 2, { LOCAL_STACK_LOCK_WHO: env.LOCAL_STACK_LOCK_WHO || `bkit ci push-gate ${gate}` }, { base: env, forwardStatusTo: env[LOCK_STATUS_FILE_ENV] });
155
+ return lock.run.exitCode;
156
+ }, log, () => lock.run?.lock === "lock-wait");
157
+ }
123
158
  /** Pending files survive interrupted runners; one read suffices to block earlier proof. */
124
159
  function pendingAttempt(file) {
125
160
  const dir = `${file}.running`;
@@ -163,11 +198,11 @@ function noLaterFailure(cwd, dir, sha, newSha, definition) {
163
198
  return true;
164
199
  }
165
200
  /** A bounded ancestor search; absent, malformed or stale proof always requires the full gate. */
166
- export function hasVerifiedIncrement(cwd, oldSha, newSha, paths) {
167
- if (!SHA.test(oldSha) ||
201
+ export function hasVerifiedIncrement(cwd, oldSha, newSha, outsideOf) {
202
+ const isNew = /^0+$/.test(oldSha);
203
+ if ((!isNew && !SHA.test(oldSha)) ||
168
204
  !SHA.test(newSha) ||
169
- /^0+$/.test(oldSha) ||
170
- !runGit(cwd, ["merge-base", "--is-ancestor", oldSha, newSha]).ok)
205
+ (!isNew && !runGit(cwd, ["merge-base", "--is-ancestor", oldSha, newSha]).ok))
171
206
  return false;
172
207
  const raw = git(cwd, ["show", `${newSha}:package.json`]);
173
208
  const parsed = raw === null ? null : parseJson(raw);
@@ -177,8 +212,8 @@ export function hasVerifiedIncrement(cwd, oldSha, newSha, paths) {
177
212
  !localPkg.ok ||
178
213
  gateDefinition(localPkg.pkg)?.fingerprint !== definition.fingerprint)
179
214
  return false;
180
- const ancestors = git(cwd, ["rev-list", "--max-count=128", oldSha]);
181
- const firstFile = receiptPath(cwd, oldSha);
215
+ const ancestors = git(cwd, ["rev-list", "--max-count=128", isNew ? newSha : oldSha]);
216
+ const firstFile = receiptPath(cwd, newSha);
182
217
  if (!ancestors || !firstFile)
183
218
  return false;
184
219
  const dir = path.dirname(firstFile);
@@ -186,7 +221,7 @@ export function hasVerifiedIncrement(cwd, oldSha, newSha, paths) {
186
221
  const file = path.join(dir, `${sha}.json`);
187
222
  if (!validReceipt(cwd, file, sha, definition))
188
223
  continue;
189
- const diff = changedOutside(cwd, sha, newSha, paths);
224
+ const diff = outsideOf(sha, newSha);
190
225
  if (diff.ok && diff.outside.length === 0 && noLaterFailure(cwd, dir, sha, newSha, definition))
191
226
  return true;
192
227
  }
@@ -75,7 +75,7 @@ export function runStatus(cwd, logPrefix) {
75
75
  console.log(`${logPrefix} cursor: ${cursorPresent ? "INSTALLED" : "absent"}`);
76
76
  // --- opencode host ---
77
77
  const opencodeDir = path.join(cwd, ".opencode");
78
- const opencodePresent = fs.existsSync(opencodeDir);
78
+ const opencodePresent = detectInstalledHostModules(cwd).has("opencode");
79
79
  // Resolve active provider (manifest-first; covers managed-auth gateways like opencode).
80
80
  const activeOpencodeProvider = detectOpencodeProvider(cwd);
81
81
  // All installed providers.
@@ -142,12 +142,13 @@ export async function runDoctor(modules, opencodeProvider) {
142
142
  // Broken install: the opencode host is on disk but neither provider signal survives.
143
143
  // `bkit check` and `bkit upgrade` exit 1 with the fix; doctor reports it here and does
144
144
  // not enforce.
145
- if (fs.existsSync(path.join(process.cwd(), ".opencode"))) {
145
+ const opencodePresent = detectInstalledHostModules(process.cwd()).has("opencode");
146
+ if (opencodePresent) {
146
147
  if (detectOpencodeProvider(process.cwd()) === null) {
147
148
  allFindings.push({
148
149
  id: "opencode-provider-missing",
149
150
  severity: "blocker",
150
- detect: "`.opencode/` is present but no provider is recorded — neither package.json `bkit.providers.opencode.default` nor an `opencode.json` provider block.",
151
+ detect: "`.opencode/agents/` is present but no provider is recorded — neither package.json `bkit.providers.opencode.default` nor an `opencode.json` provider block.",
151
152
  action: `Re-run \`bkit install --opencode=<provider>\` (${OPENCODE_PROVIDERS.join(", ")}). Until then \`bkit check\` and \`bkit upgrade\` exit 1 rather than render every agent pin against a substitute provider.`,
152
153
  });
153
154
  }
@@ -171,8 +172,7 @@ export async function runDoctor(modules, opencodeProvider) {
171
172
  });
172
173
  // opencode host diagnostics: report required tools and cred presence per provider.
173
174
  // Never echoes key values — only reports present/absent.
174
- const opencodeDir = path.join(process.cwd(), ".opencode");
175
- if (fs.existsSync(opencodeDir) || modules.has("opencode")) {
175
+ if (opencodePresent || modules.has("opencode")) {
176
176
  console.log(`${LOG_PREFIX} --- opencode host diagnostics ---`);
177
177
  // Check opencode binary
178
178
  const { spawnSync: spawnSyncLocal } = await import("node:child_process");