@cbartens/bkit 0.0.0-stage → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/.bkit/README.md +417 -0
  2. package/.bkit/core/.agents/context.md +95 -0
  3. package/.bkit/core/.agents/docs.md +62 -0
  4. package/.bkit/core/.agents/rules.md +147 -0
  5. package/.bkit/core/.agents/skills.md +43 -0
  6. package/.bkit/core/.bkit/LICENSE.md +151 -0
  7. package/.bkit/core/.bkit/README.md +417 -0
  8. package/.bkit/core/.bkit/cloud.md +493 -0
  9. package/.bkit/core/.bkit/comparison.md +321 -0
  10. package/.bkit/core/.bkit/install.md +401 -0
  11. package/.bkit/core/.bkit/jsonl.md +497 -0
  12. package/.bkit/core/.bkit/prompts.md +474 -0
  13. package/.bkit/core/.bkit/providers.md +598 -0
  14. package/.bkit/core/.bkit/templates.md +470 -0
  15. package/.bkit/core/.bkit/trackers.md +95 -0
  16. package/.bkit/core/.bkit/workflows.md +1550 -0
  17. package/.bkit/core/.claude/hooks/bkit-gateguard.cjs +82 -0
  18. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +93 -0
  19. package/.bkit/core/.claude/hooks/bkit-preflight.sh +74 -0
  20. package/.bkit/core/.codex/hooks/bkit-gateguard.cjs +115 -0
  21. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +135 -0
  22. package/.bkit/core/.cursor/hooks/bkit-gateguard.cjs +111 -0
  23. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +169 -0
  24. package/.bkit/core/.cursor/hooks/bkit-preflight.sh +63 -0
  25. package/.bkit/core/.opencode/plugin/bkit-gateguard.js +225 -0
  26. package/.bkit/core/AGENTS.md +77 -0
  27. package/.bkit/core/LICENSE.md +149 -0
  28. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +272 -0
  29. package/.bkit/core/docs/templates/bkit-audit-adoption.md +223 -0
  30. package/.bkit/core/docs/templates/bkit-audit-agents.md +230 -0
  31. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +227 -0
  32. package/.bkit/core/docs/templates/bkit-audit-analytics.md +266 -0
  33. package/.bkit/core/docs/templates/bkit-audit-annotations.md +230 -0
  34. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +270 -0
  35. package/.bkit/core/docs/templates/bkit-audit-app-store.md +254 -0
  36. package/.bkit/core/docs/templates/bkit-audit-architecture.md +221 -0
  37. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +241 -0
  38. package/.bkit/core/docs/templates/bkit-audit-config.md +230 -0
  39. package/.bkit/core/docs/templates/bkit-audit-cost.md +218 -0
  40. package/.bkit/core/docs/templates/bkit-audit-coverage.md +221 -0
  41. package/.bkit/core/docs/templates/bkit-audit-database.md +229 -0
  42. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +251 -0
  43. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +283 -0
  44. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +268 -0
  45. package/.bkit/core/docs/templates/bkit-audit-documentation.md +280 -0
  46. package/.bkit/core/docs/templates/bkit-audit-duplication.md +253 -0
  47. package/.bkit/core/docs/templates/bkit-audit-failures.md +259 -0
  48. package/.bkit/core/docs/templates/bkit-audit-flakes.md +237 -0
  49. package/.bkit/core/docs/templates/bkit-audit-gates.md +250 -0
  50. package/.bkit/core/docs/templates/bkit-audit-issues.md +273 -0
  51. package/.bkit/core/docs/templates/bkit-audit-llm.md +239 -0
  52. package/.bkit/core/docs/templates/bkit-audit-logs.md +266 -0
  53. package/.bkit/core/docs/templates/bkit-audit-models.md +210 -0
  54. package/.bkit/core/docs/templates/bkit-audit-privacy.md +211 -0
  55. package/.bkit/core/docs/templates/bkit-audit-prompts.md +216 -0
  56. package/.bkit/core/docs/templates/bkit-audit-red-team.md +220 -0
  57. package/.bkit/core/docs/templates/bkit-audit-reliability.md +222 -0
  58. package/.bkit/core/docs/templates/bkit-audit-repo.md +224 -0
  59. package/.bkit/core/docs/templates/bkit-audit-security.md +274 -0
  60. package/.bkit/core/docs/templates/bkit-audit-slop.md +200 -0
  61. package/.bkit/core/docs/templates/bkit-audit-testing.md +270 -0
  62. package/.bkit/core/docs/templates/bkit-audit-usability.md +237 -0
  63. package/.bkit/core/docs/templates/bkit-plan.md +476 -0
  64. package/.bkit/core/engine/checks/after/auth.ts +149 -0
  65. package/.bkit/core/engine/checks/after/ci-yml.ts +701 -0
  66. package/.bkit/core/engine/checks/after/github.ts +424 -0
  67. package/.bkit/core/engine/checks/after/index.ts +530 -0
  68. package/.bkit/core/engine/checks/after/managed.ts +217 -0
  69. package/.bkit/core/engine/checks/after/suppression.ts +53 -0
  70. package/.bkit/core/engine/checks/after/tools.ts +427 -0
  71. package/.bkit/core/engine/checks/before/context-fetch.ts +429 -0
  72. package/.bkit/core/engine/checks/before/env.ts +187 -0
  73. package/.bkit/core/engine/checks/before/files.ts +204 -0
  74. package/.bkit/core/engine/checks/before/index.ts +206 -0
  75. package/.bkit/core/engine/checks/before/mcp.ts +127 -0
  76. package/.bkit/core/engine/checks/before/repo.ts +77 -0
  77. package/.bkit/core/engine/checks/before/version.ts +67 -0
  78. package/.bkit/core/engine/checks/status-holes.ts +479 -0
  79. package/.bkit/core/engine/cli.ts +867 -0
  80. package/.bkit/core/engine/commands/analysis.ts +550 -0
  81. package/.bkit/core/engine/commands/ci/ci.ts +483 -0
  82. package/.bkit/core/engine/commands/comply.ts +415 -0
  83. package/.bkit/core/engine/commands/harvest.ts +459 -0
  84. package/.bkit/core/engine/commands/install/check.ts +70 -0
  85. package/.bkit/core/engine/commands/install/doctor.ts +254 -0
  86. package/.bkit/core/engine/commands/install/install.ts +550 -0
  87. package/.bkit/core/engine/commands/install/uninstall.ts +995 -0
  88. package/.bkit/core/engine/commands/install/upgrade.ts +1037 -0
  89. package/.bkit/core/engine/commands/launch.ts +139 -0
  90. package/.bkit/core/engine/commands/lib.ts +495 -0
  91. package/.bkit/core/engine/commands/registry.ts +53 -0
  92. package/.bkit/core/engine/commands/setup/setup.ts +184 -0
  93. package/.bkit/core/engine/commands/telemetry.ts +32 -0
  94. package/.bkit/core/engine/commands/workflow/branches.ts +1514 -0
  95. package/.bkit/core/engine/commands/workflow/context.ts +961 -0
  96. package/.bkit/core/engine/commands/workflow/counters.ts +268 -0
  97. package/.bkit/core/engine/commands/workflow/fids.ts +243 -0
  98. package/.bkit/core/engine/commands/workflow/issues.ts +675 -0
  99. package/.bkit/core/engine/commands/workflow/ledgers.ts +575 -0
  100. package/.bkit/core/engine/commands/workflow/locks.ts +478 -0
  101. package/.bkit/core/engine/commands/workflow/prs.ts +1087 -0
  102. package/.bkit/core/engine/commands/workflow/repo.ts +220 -0
  103. package/.bkit/core/engine/commands/workflow/roadmap.ts +576 -0
  104. package/.bkit/core/engine/commands/workflow/runs.ts +2140 -0
  105. package/.bkit/core/engine/commands/workflow/runtime.ts +300 -0
  106. package/.bkit/core/engine/commands/workflow/skills.ts +118 -0
  107. package/.bkit/core/engine/commands/workflow/status.ts +455 -0
  108. package/.bkit/core/engine/commands/workflow/steps.ts +1300 -0
  109. package/.bkit/core/engine/commands/workflow/tests.ts +161 -0
  110. package/.bkit/core/engine/commands/workflow/workflows.ts +1573 -0
  111. package/.bkit/core/engine/commands/workflow/workstreams.ts +164 -0
  112. package/.bkit/core/engine/commands/workflow/worktrees.ts +534 -0
  113. package/.bkit/core/engine/install/cloud-env.ts +924 -0
  114. package/.bkit/core/engine/install/managed-block.ts +212 -0
  115. package/.bkit/core/engine/install/manifest.ts +448 -0
  116. package/.bkit/core/engine/install/modules/claude.ts +362 -0
  117. package/.bkit/core/engine/install/modules/cloud.ts +173 -0
  118. package/.bkit/core/engine/install/modules/codex.ts +219 -0
  119. package/.bkit/core/engine/install/modules/core.ts +620 -0
  120. package/.bkit/core/engine/install/modules/cursor.ts +231 -0
  121. package/.bkit/core/engine/install/modules/index.ts +242 -0
  122. package/.bkit/core/engine/install/modules/opencode.ts +573 -0
  123. package/.bkit/core/engine/install/payload-links.ts +150 -0
  124. package/.bkit/core/engine/install/placeholders.ts +108 -0
  125. package/.bkit/core/engine/install/template-copies.ts +119 -0
  126. package/.bkit/core/engine/install/version-file.ts +284 -0
  127. package/.bkit/core/engine/install/write.ts +467 -0
  128. package/.bkit/core/engine/ledgers/clamp-log.ts +32 -0
  129. package/.bkit/core/engine/ledgers/status.ts +213 -0
  130. package/.bkit/core/engine/ledgers/telemetry.ts +1143 -0
  131. package/.bkit/core/engine/render/hosts.ts +372 -0
  132. package/.bkit/core/engine/render/models.ts +323 -0
  133. package/.bkit/core/engine/render/parts.ts +38 -0
  134. package/.bkit/core/engine/render/trackers.ts +170 -0
  135. package/.bkit/core/engine/shared/egress.ts +345 -0
  136. package/.bkit/core/engine/shared/json.ts +16 -0
  137. package/.bkit/core/engine/shared/log-prefix.ts +9 -0
  138. package/.bkit/core/engine/shared/package-json.ts +29 -0
  139. package/.bkit/core/engine/shared/package-manager.ts +38 -0
  140. package/.bkit/core/engine/shared/package-roots.ts +163 -0
  141. package/.bkit/core/engine/shared/protected-paths.ts +164 -0
  142. package/.bkit/core/engine/shared/settings.ts +72 -0
  143. package/.bkit/core/engine/shared/timeouts.ts +20 -0
  144. package/.bkit/core/engine/tools/wording.ts +748 -0
  145. package/.bkit/core/hooks/gateguard-edit-payload.js +18 -0
  146. package/.bkit/core/hooks/gateguard-engine.js +193 -0
  147. package/.bkit/core/hooks/guardrails-shell.js +154 -0
  148. package/.bkit/core/hooks/guardrails-tiers.js +68 -0
  149. package/.bkit/core/hooks/preflight-linear.sh +73 -0
  150. package/.bkit/core/prompts/bkit-audit-generate.md +66 -0
  151. package/.bkit/core/prompts/bkit-build-challenge-1.md +79 -0
  152. package/.bkit/core/prompts/bkit-build-challenge-2.md +81 -0
  153. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +68 -0
  154. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +70 -0
  155. package/.bkit/core/prompts/bkit-build-challenge-tests.md +73 -0
  156. package/.bkit/core/prompts/bkit-build-install-skills.md +67 -0
  157. package/.bkit/core/prompts/bkit-build-plan-current.md +75 -0
  158. package/.bkit/core/prompts/bkit-build-plan-execute.md +72 -0
  159. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +73 -0
  160. package/.bkit/core/prompts/bkit-build-plan-verify.md +88 -0
  161. package/.bkit/core/prompts/bkit-build-summary.md +93 -0
  162. package/.bkit/core/prompts/bkit-debug-abort-handover.md +90 -0
  163. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +151 -0
  164. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +78 -0
  165. package/.bkit/core/prompts/bkit-debug-failure-soak.md +73 -0
  166. package/.bkit/core/prompts/bkit-debug-summary.md +95 -0
  167. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +72 -0
  168. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +72 -0
  169. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +75 -0
  170. package/.bkit/core/prompts/bkit-design-generate.md +110 -0
  171. package/.bkit/core/prompts/bkit-design-organise.md +85 -0
  172. package/.bkit/core/prompts/bkit-design-review-1.md +121 -0
  173. package/.bkit/core/prompts/bkit-design-review-2.md +111 -0
  174. package/.bkit/core/prompts/bkit-design-spike.md +97 -0
  175. package/.bkit/core/prompts/bkit-design-summary.md +106 -0
  176. package/.bkit/core/prompts/bkit-design-update.md +66 -0
  177. package/.bkit/core/prompts/bkit-plan-complexity-check.md +66 -0
  178. package/.bkit/core/prompts/bkit-plan-complexity-split.md +87 -0
  179. package/.bkit/core/prompts/bkit-plan-generate.md +74 -0
  180. package/.bkit/core/prompts/bkit-plan-review-1.md +90 -0
  181. package/.bkit/core/prompts/bkit-plan-review-2.md +80 -0
  182. package/.bkit/core/prompts/bkit-plan-review-3.md +92 -0
  183. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +84 -0
  184. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +84 -0
  185. package/.bkit/core/prompts/bkit-plan-summary.md +106 -0
  186. package/.bkit/core/prompts/bkit-plan-update.md +68 -0
  187. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +90 -0
  188. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +94 -0
  189. package/.bkit/core/prompts/bkit-ship-summary.md +77 -0
  190. package/.bkit/core/prompts/bkit-ship-update-docs.md +71 -0
  191. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +91 -0
  192. package/.bkit/core/prompts/bkit-utility-update-decisions.md +75 -0
  193. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +76 -0
  194. package/.bkit/core/prompts/bkit-utility-update-documentation.md +61 -0
  195. package/.bkit/core/prompts/bkit-utility-update-failures.md +76 -0
  196. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +75 -0
  197. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +82 -0
  198. package/.bkit/core/workflows/bkit-auto.md +121 -0
  199. package/.bkit/core/workflows/bkit-build.md +802 -0
  200. package/.bkit/core/workflows/bkit-debug.md +649 -0
  201. package/.bkit/core/workflows/bkit-design.md +495 -0
  202. package/.bkit/core/workflows/bkit-plan.md +510 -0
  203. package/.bkit/core/workflows/bkit-ship.md +650 -0
  204. package/.bkit/shared/.bkit/.env.example +86 -0
  205. package/.bkit/shared/.claude/bkit-cloud.md +117 -0
  206. package/.bkit/shared/.claude/settings.json +88 -0
  207. package/.bkit/shared/.codex/hooks.json +26 -0
  208. package/.bkit/shared/.cursor/bkit-cloud.md +84 -0
  209. package/.bkit/shared/.cursor/hooks.json +26 -0
  210. package/.bkit/shared/.cursor/mcp.json +15 -0
  211. package/.bkit/shared/.cursor/rules/bkit-rules.mdc +12 -0
  212. package/.bkit/shared/.gitattributes +37 -0
  213. package/.bkit/shared/.mcp.json +16 -0
  214. package/.bkit/shared/.opencode/opencode.json +62 -0
  215. package/.bkit/shared/CLAUDE.md +11 -0
  216. package/.bkit/shared/LICENSE.md +22 -0
  217. package/.bkit/shared/docs/architecture.md +19 -0
  218. package/.bkit/shared/docs/data-schema.md +19 -0
  219. package/.bkit/shared/docs/deployments.md +433 -0
  220. package/.bkit/shared/docs/design.md +39 -0
  221. package/.bkit/shared/docs/noise.md +19 -0
  222. package/.bkit/shared/docs/observability.md +25 -0
  223. package/.bkit/shared/docs/security.md +42 -0
  224. package/.bkit/shared/docs/setup.md +30 -0
  225. package/.bkit/shared/docs/technology.md +18 -0
  226. package/.bkit/shared/docs/testing.md +413 -0
  227. package/.bkit/shared/gitignore +97 -0
  228. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +187 -0
  229. package/.bkit/templates/.cursor/Dockerfile +68 -0
  230. package/.bkit/templates/.cursor/environment.json +6 -0
  231. package/.bkit/templates/.cursor/settings.json +11 -0
  232. package/.bkit/templates/.envrc +7 -0
  233. package/.bkit/templates/.github/dependabot.yml +52 -0
  234. package/.bkit/templates/.github/renovate.json5 +224 -0
  235. package/.bkit/templates/.github/workflows/bkit-ci.yml +1062 -0
  236. package/.bkit/templates/.github/workflows/bkit-cloud.yml +564 -0
  237. package/.bkit/templates/.github/workflows/bkit-renovate.yml +102 -0
  238. package/.bkit/templates/.graphifyignore +108 -0
  239. package/.bkit/templates/.husky/pre-commit +16 -0
  240. package/.bkit/templates/.husky/pre-push +91 -0
  241. package/.bkit/templates/.lintstagedrc.json +3 -0
  242. package/.bkit/templates/.prettierignore +41 -0
  243. package/.bkit/templates/.serena/project.yml +243 -0
  244. package/.bkit/templates/.vale/styles/House/Filler.yml +11 -0
  245. package/.bkit/templates/.vale/styles/House/Hedging.yml +12 -0
  246. package/.bkit/templates/.vale/styles/House/LLMSlop.yml +13 -0
  247. package/.bkit/templates/.vale/styles/House/Verbose.yml +12 -0
  248. package/.bkit/templates/.vale.ini +67 -0
  249. package/.bkit/templates/LICENSE.md +22 -0
  250. package/.bkit/templates/context/bkit-cloudrun.md +84 -0
  251. package/.bkit/templates/context/bkit-expo.md +186 -0
  252. package/.bkit/templates/context/bkit-github.md +79 -0
  253. package/.bkit/templates/context/bkit-inngest.md +45 -0
  254. package/.bkit/templates/context/bkit-maestro.md +76 -0
  255. package/.bkit/templates/context/bkit-playwright.md +62 -0
  256. package/.bkit/templates/context/bkit-resend.md +36 -0
  257. package/.bkit/templates/context/bkit-sentry.md +65 -0
  258. package/.bkit/templates/context/bkit-serena.md +33 -0
  259. package/.bkit/templates/context/bkit-stripe.md +36 -0
  260. package/.bkit/templates/context/bkit-supabase.md +59 -0
  261. package/.bkit/templates/context/bkit-tavily.md +49 -0
  262. package/.bkit/templates/context/bkit-vercel.md +64 -0
  263. package/.bkit/templates/docs/capabilities.md +72 -0
  264. package/.bkit/templates/scripts/ci/accepted-divergences.json +21 -0
  265. package/.bkit/templates/scripts/ci/check-accepted-divergences.mjs +152 -0
  266. package/.bkit/templates/scripts/ci/check-accepted-divergences.test.mjs +130 -0
  267. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.mjs +98 -0
  268. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.test.mjs +86 -0
  269. package/.bkit/templates/scripts/graphify/bkit-graph-drift-rules.json +23 -0
  270. package/.bkit/templates/scripts/graphify/bkit-graph-drift.py +208 -0
  271. package/.bkit/templates/scripts/graphify/bkit-graph-eager-rules.json +35 -0
  272. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +236 -0
  273. package/.bkit/templates/scripts/graphify/bkit-graph-external-rules.json +17 -0
  274. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +290 -0
  275. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +19 -0
  276. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +120 -0
  277. package/.bkit/templates/scripts/graphify/bkit-graph-surface.py +232 -0
  278. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +36 -0
  279. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +927 -0
  280. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +351 -0
  281. package/.bkit/templates/scripts/launchd/ai.bkit.launchd.plist +26 -0
  282. package/.bkit/templates/scripts/launchd/bkit-launchd-env.sh +53 -0
  283. package/.bkit/templates/scripts/launchd/launchd.env.example +13 -0
  284. package/.bkit/templates/scripts/prettier/bkit-insert-ignore.mjs +275 -0
  285. package/.bkit/templates/scripts/secrets/bkit-secrets.config.mjs +66 -0
  286. package/.bkit/templates/scripts/secrets/bkit-secrets.mjs +785 -0
  287. package/.bkit/templates/scripts/serena/bkit-serena-mcp.sh +30 -0
  288. package/.bkit/templates/scripts/serena/bkit-serena.mcp.json +9 -0
  289. package/.bkit/templates/scripts/slop/bkit-slop-type-suppression.mjs +286 -0
  290. package/.bkit/templates/slop-scan.config.json +120 -0
  291. package/CHANGELOG.md +1503 -0
  292. package/LICENSE.md +161 -0
  293. package/README.md +184 -2
  294. package/dist/checks/after/auth.js +140 -0
  295. package/dist/checks/after/ci-yml.js +681 -0
  296. package/dist/checks/after/github.js +400 -0
  297. package/dist/checks/after/index.js +431 -0
  298. package/dist/checks/after/managed.js +187 -0
  299. package/dist/checks/after/suppression.js +39 -0
  300. package/dist/checks/after/tools.js +351 -0
  301. package/dist/checks/before/context-fetch.js +426 -0
  302. package/dist/checks/before/env.js +163 -0
  303. package/dist/checks/before/files.js +187 -0
  304. package/dist/checks/before/index.js +162 -0
  305. package/dist/checks/before/mcp.js +111 -0
  306. package/dist/checks/before/repo.js +71 -0
  307. package/dist/checks/before/version.js +60 -0
  308. package/dist/checks/status-holes.js +393 -0
  309. package/dist/cli.js +688 -0
  310. package/dist/commands/analysis.js +325 -0
  311. package/dist/commands/ci/ci.js +438 -0
  312. package/dist/commands/comply.js +310 -0
  313. package/dist/commands/harvest.js +354 -0
  314. package/dist/commands/install/check.js +61 -0
  315. package/dist/commands/install/doctor.js +209 -0
  316. package/dist/commands/install/install.js +475 -0
  317. package/dist/commands/install/uninstall.js +839 -0
  318. package/dist/commands/install/upgrade.js +782 -0
  319. package/dist/commands/launch.js +118 -0
  320. package/dist/commands/lib.js +363 -0
  321. package/dist/commands/registry.js +50 -0
  322. package/dist/commands/setup/setup.js +158 -0
  323. package/dist/commands/telemetry.js +29 -0
  324. package/dist/commands/workflow/branches.js +1265 -0
  325. package/dist/commands/workflow/context.js +846 -0
  326. package/dist/commands/workflow/counters.js +227 -0
  327. package/dist/commands/workflow/fids.js +224 -0
  328. package/dist/commands/workflow/issues.js +585 -0
  329. package/dist/commands/workflow/ledgers.js +472 -0
  330. package/dist/commands/workflow/locks.js +364 -0
  331. package/dist/commands/workflow/prs.js +904 -0
  332. package/dist/commands/workflow/repo.js +199 -0
  333. package/dist/commands/workflow/roadmap.js +495 -0
  334. package/dist/commands/workflow/runs.js +1717 -0
  335. package/dist/commands/workflow/runtime.js +257 -0
  336. package/dist/commands/workflow/skills.js +110 -0
  337. package/dist/commands/workflow/status.js +392 -0
  338. package/dist/commands/workflow/steps.js +1093 -0
  339. package/dist/commands/workflow/tests.js +144 -0
  340. package/dist/commands/workflow/workflows.js +1342 -0
  341. package/dist/commands/workflow/workstreams.js +141 -0
  342. package/dist/commands/workflow/worktrees.js +473 -0
  343. package/dist/install/cloud-env.js +818 -0
  344. package/dist/install/managed-block.js +182 -0
  345. package/dist/install/manifest.js +376 -0
  346. package/dist/install/modules/claude.js +288 -0
  347. package/dist/install/modules/cloud.js +151 -0
  348. package/dist/install/modules/codex.js +193 -0
  349. package/dist/install/modules/core.js +531 -0
  350. package/dist/install/modules/cursor.js +186 -0
  351. package/dist/install/modules/index.js +152 -0
  352. package/dist/install/modules/opencode.js +504 -0
  353. package/dist/install/payload-links.js +119 -0
  354. package/dist/install/placeholders.js +87 -0
  355. package/dist/install/template-copies.js +106 -0
  356. package/dist/install/version-file.js +204 -0
  357. package/dist/install/write.js +342 -0
  358. package/dist/ledgers/clamp-log.js +27 -0
  359. package/dist/ledgers/status.js +156 -0
  360. package/dist/ledgers/telemetry.js +637 -0
  361. package/dist/render/hosts.js +339 -0
  362. package/dist/render/models.js +288 -0
  363. package/dist/render/parts.js +33 -0
  364. package/dist/render/trackers.js +135 -0
  365. package/dist/shared/egress.js +299 -0
  366. package/dist/shared/json.js +16 -0
  367. package/dist/shared/log-prefix.js +7 -0
  368. package/dist/shared/package-json.js +22 -0
  369. package/dist/shared/package-manager.js +32 -0
  370. package/dist/shared/package-roots.js +145 -0
  371. package/dist/shared/protected-paths.js +153 -0
  372. package/dist/shared/settings.js +44 -0
  373. package/dist/shared/timeouts.js +19 -0
  374. package/dist/tools/wording.js +680 -0
  375. package/package.json +101 -4
@@ -0,0 +1,564 @@
1
+ # Example. Copy into the repo and own it.
2
+ # bkit install does not write this file and does not overwrite a copy.
3
+ name: bkit-cloud
4
+
5
+ # Phase-routed cloud-agent workflow. One `context` job resolves the phase and its
6
+ # argument, then TWO dispatch jobs — `claude` (via claude-code-action@v1) and `opencode`
7
+ # (via the opencode CLI `run` subcommand) — run the same `/bkit-auto <phase> <arg>`
8
+ # orchestrator against the committed `.claude/` / `.opencode/` config respectively.
9
+ #
10
+ # RUNTIME GATING — secret-presence auto-detect (in the context job):
11
+ # - ANTHROPIC_API_KEY set → claude job runs.
12
+ # - OPENCODE_PROVIDER_KEY set → opencode job runs.
13
+ # Both can run on one event (additive); a missing secret skips that job (zero
14
+ # billable runner minutes).
15
+ #
16
+ # Trigger surfaces:
17
+ # - workflow_run (CI completion on feat/**): success -> ship, failure -> debug
18
+ # - workflow_run (CI completion on dev): success -> no-op (regression check passed),
19
+ # failure -> /bkit-debug {FID} (FID recovered from squash-merge commit scope;
20
+ # loop-bounded by MAX_DEV_DISPATCH_ATTEMPTS). [skip ci] close commits never trigger CI.
21
+ # - workflow_dispatch: pick ANY phase (ship|debug|design|plan|build) for an issue.
22
+ # design/plan/build have no tracker-event trigger; they run only via dispatch.
23
+ #
24
+ # Required secrets (claude job): ANTHROPIC_API_KEY + Claude GitHub App (one-time
25
+ # `/install-github-app` — grants `id-token: write` OIDC for claude-code-action@v1).
26
+ # Required secrets (opencode job): OPENCODE_PROVIDER_KEY (any provider key the
27
+ # committed .opencode/opencode.json references; fan-out maps it to known env var names).
28
+ # Required tracker label on the issue: `bkit:auto` (opt-in) for the CI-driven path.
29
+ # Docs: bkit's cloud.md § Post-CI auto-routing.
30
+
31
+ on:
32
+ workflow_run:
33
+ workflows: [bkit-ci]
34
+ branches: ['feat/**', 'dev']
35
+ types: [completed]
36
+ workflow_dispatch:
37
+ inputs:
38
+ phase:
39
+ description: 'bkit phase to run'
40
+ required: true
41
+ type: choice
42
+ options:
43
+ - ship
44
+ - debug
45
+ - design
46
+ - plan
47
+ - build
48
+ issue:
49
+ description: 'Tracker issue number/id supplying the brief'
50
+ required: true
51
+ type: string
52
+
53
+ # Dynamic run name (shown in the Actions runs list). Dispatched runs render
54
+ # `bkit auto <phase>(<issue>)`; CI-driven runs echo the triggering commit subject
55
+ # (`head_commit.message` — already `{type}({scope}): {message}`) prefixed with `bkit auto`.
56
+ run-name: >-
57
+ ${{ inputs.phase
58
+ && format('bkit auto {0}({1})', inputs.phase, inputs.issue)
59
+ || format('bkit auto {0}', github.event.workflow_run.head_commit.message) }}
60
+
61
+ concurrency:
62
+ # Serialises concurrent runs WITHIN each trigger surface:
63
+ # - dispatch path keys on inputs.issue (e.g. bkit-auto-141)
64
+ # - CI-completion keys on head_branch (e.g. bkit-auto-feat/141-cloud-app)
65
+ # The two keys never match for one FID, so a dispatched build and the auto-ship it
66
+ # triggers do not share a group; the orchestrator stale-run guard + the per-feature
67
+ # workflow lock (`bkit locks acquire`, `logs/{FID}/.lock`) handle that race (not this
68
+ # concurrency key).
69
+ group: bkit-auto-${{ inputs.issue || github.event.workflow_run.head_branch }}
70
+ # dev: queue, not cancel. With cancel-in-progress: false, GHA queues at most one
71
+ # pending run per group (older pendings are cancelled as newer ones arrive); the
72
+ # queued run re-evaluates the dispatch cap at its ctx step when it starts.
73
+ # feat/** cancels (latest wins). `bkit-auto-dev` is ONE group shared by ALL FIDs
74
+ # (concurrency.group resolves from the trigger payload, before the ctx step derives
75
+ # the FID): if two DIFFERENT FIDs' dev CI runs fail near-simultaneously, the older
76
+ # pending run can be dropped. The ctx step's stale-run guard then writes a
77
+ # `dev-dispatch-dropped` row to the job summary + a `::warning::`.
78
+ cancel-in-progress: ${{ github.event.workflow_run.head_branch != 'dev' }}
79
+
80
+ # Cap on dev-triggered debug dispatches per FID (distinct failed dev CI SHAs).
81
+ # A bkit test holds it equal to MAX_DEV_DISPATCH_ATTEMPTS in `bkit counters max`.
82
+ env:
83
+ MAX_DEV_DISPATCH_ATTEMPTS: 3
84
+
85
+ jobs:
86
+ # ---------------------------------------------------------------------------
87
+ # context job — checks which runner secrets are set and resolves phase + arg ONCE
88
+ # for both runner jobs. CI-driven runs fire only on terminal CI conclusions (skip
89
+ # cancelled / skipped). Free-tier gate: CI-driven runs additionally require
90
+ # 'bkit [auto route]' in the head commit message — zero runner minutes if the marker
91
+ # is absent (no opted-in close-workflow HEAD). Dispatched runs always proceed. When
92
+ # this job is skipped, both runner jobs are skipped with it.
93
+ # ---------------------------------------------------------------------------
94
+ context:
95
+ name: context (${{ github.event_name }})
96
+ if: >-
97
+ github.event_name == 'workflow_dispatch'
98
+ || (
99
+ github.event.workflow_run.head_repository.full_name == github.repository
100
+ && (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure')
101
+ && contains(github.event.workflow_run.head_commit.message, 'bkit [auto route]')
102
+ && !(github.event.workflow_run.head_branch == 'dev' && github.event.workflow_run.conclusion == 'success')
103
+ )
104
+ runs-on: {{CLOUD_RUNNER}}
105
+ permissions:
106
+ # contents: write — the dev arm commits its dispatch-cap counter row to dev.
107
+ contents: write
108
+ pull-requests: read
109
+ issues: read
110
+ actions: read
111
+ outputs:
112
+ claude: ${{ steps.gate.outputs.claude }}
113
+ opencode: ${{ steps.gate.outputs.opencode }}
114
+ skip: ${{ steps.ctx.outputs.skip }}
115
+ phase: ${{ steps.ctx.outputs.phase }}
116
+ arg: ${{ steps.ctx.outputs.arg }}
117
+ steps:
118
+ # A runner job whose secret is missing is a no-op; with neither secret set, nothing
119
+ # below runs (no counter row, no checkout).
120
+ - name: Check runner secrets
121
+ id: gate
122
+ env:
123
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
124
+ OPENCODE_PROVIDER_KEY: ${{ secrets.OPENCODE_PROVIDER_KEY }}
125
+ run: |
126
+ claude=false
127
+ opencode=false
128
+ if [ -n "$ANTHROPIC_API_KEY" ]; then
129
+ claude=true
130
+ else
131
+ echo "::notice::ANTHROPIC_API_KEY not set — claude job no-op."
132
+ fi
133
+ if [ -n "$OPENCODE_PROVIDER_KEY" ]; then
134
+ opencode=true
135
+ else
136
+ echo "::notice::OPENCODE_PROVIDER_KEY not set — opencode job no-op."
137
+ fi
138
+ enabled=false
139
+ if [ "$claude" = true ] || [ "$opencode" = true ]; then enabled=true; fi
140
+ {
141
+ echo "claude=$claude"
142
+ echo "opencode=$opencode"
143
+ echo "enabled=$enabled"
144
+ } >> "$GITHUB_OUTPUT"
145
+
146
+ # SHA pins in this file — your updater refreshes them in your copy (keep this file out
147
+ # of renovate.json5 `ignorePaths`); `bkit upgrade` lists this template when bkit's pins move.
148
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
149
+ if: steps.gate.outputs.enabled == 'true'
150
+ with:
151
+ # `dev` at the workspace root: the dev arm's dispatch-cap counter row is
152
+ # committed to dev's `status.jsonl`; the feat/** arm reads the branch's
153
+ # `status.jsonl` from origin.
154
+ ref: dev
155
+ fetch-depth: 0
156
+ # The auto-provided GITHUB_TOKEN inherits the `permissions:` block above.
157
+ token: ${{ github.token }}
158
+
159
+ - name: Configure git user
160
+ if: steps.gate.outputs.enabled == 'true'
161
+ run: |
162
+ git config user.name 'bkit-auto[bot]'
163
+ git config user.email 'bkit-auto@users.noreply.github.com'
164
+
165
+ - name: Resolve phase + brief context
166
+ id: ctx
167
+ if: steps.gate.outputs.enabled == 'true'
168
+ env:
169
+ GH_TOKEN: ${{ github.token }}
170
+ EVENT: ${{ github.event_name }}
171
+ IN_PHASE: ${{ inputs.phase }}
172
+ IN_ISSUE: ${{ inputs.issue }}
173
+ CONCLUSION: ${{ github.event.workflow_run.conclusion }}
174
+ BRANCH: ${{ github.event.workflow_run.head_branch }}
175
+ COMMIT_MSG: ${{ github.event.workflow_run.head_commit.message }}
176
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
177
+ run: |
178
+ set -euo pipefail
179
+ if [ "$EVENT" = "workflow_dispatch" ]; then
180
+ # Dispatched: phase + issue come straight from inputs.
181
+ PHASE="$IN_PHASE"
182
+ ARG="$IN_ISSUE"
183
+ FID="$IN_ISSUE"
184
+ else
185
+ # CI-driven: success -> ship, failure -> debug; route by branch + conclusion.
186
+ case "$CONCLUSION" in
187
+ success) PHASE=ship ;;
188
+ failure) PHASE=debug ;;
189
+ *) echo "::notice::Non-terminal CI conclusion '$CONCLUSION' — no-op exit."; echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0 ;;
190
+ esac
191
+
192
+ # SHARED-DERIV: FID/ISSUE recovery + dispatch-cap machinery for both
193
+ # CI-driven trigger surfaces (feat/** pre-merge, dev post-merge).
194
+
195
+ # bkit_dev_dispatch_guard <FID> <HEAD_SHA> — cap-check +
196
+ # counter-write + fail-closed-verify for the post-merge debug
197
+ # surface (dev CI failure). One post-feat/** debug budget per FID.
198
+ # Returns 1 (caller must skip) once the FID has MAX_DEV_DISPATCH_
199
+ # ATTEMPTS distinct failed-CI SHAs recorded, or if the counter row
200
+ # cannot be durably landed on origin/dev (fail-closed: one push
201
+ # retry against a re-fetched dev, then VERIFY landing before
202
+ # proceeding). Returns 0 to proceed to dispatch.
203
+ bkit_dev_dispatch_guard() {
204
+ local guard_fid="$1" guard_head_sha="$2"
205
+ # assert the FID against the same slug allowlist the dev arm
206
+ # already enforces BEFORE it's used to build any path (find -path /
207
+ # mkdir -p / git commit -m). Defence-in-depth re-check for the
208
+ # PR-body marker path (bkit:fid=<anything up to whitespace/'>'>
209
+ # admits '/', '.', '..').
210
+ if ! [[ "$guard_fid" =~ ^([0-9]+|[a-z]+-[0-9]+)-[a-z0-9-]+$ ]]; then
211
+ echo "::notice::Invalid FID '$guard_fid' — refusing to write dev-dispatch counter (fail-closed)."
212
+ return 1
213
+ fi
214
+ # The caller invokes this function as `... || { skip }`, which
215
+ # suppresses `set -e` for the whole body. An explicit test, not
216
+ # `${VAR:?}`: the `:?` expansion exits the whole shell even from
217
+ # inside a `|| {}`-guarded function. Fail closed when the
218
+ # workflow-level env does not define a whole-number cap.
219
+ case "${MAX_DEV_DISPATCH_ATTEMPTS:-}" in
220
+ '' | *[!0-9]*)
221
+ echo "::notice::MAX_DEV_DISPATCH_ATTEMPTS is not set to a whole number — refusing to dispatch uncounted (fail-closed)."
222
+ return 1
223
+ ;;
224
+ esac
225
+ local status_dir status_file dev_count parent_sha landed
226
+ # `sort` makes the month-bucket choice deterministic.
227
+ status_dir=$(find docs/plans -mindepth 3 -maxdepth 3 -type d -path "docs/plans/*/logs/$guard_fid" 2>/dev/null | sort | head -1 || true)
228
+ [ -n "$status_dir" ] && status_dir="${status_dir}/"
229
+ if [ -z "$status_dir" ]; then
230
+ status_dir="docs/plans/$(date -u +%Y%m)/logs/$guard_fid/"
231
+ fi
232
+ mkdir -p "$status_dir"
233
+ status_file="${status_dir}status.jsonl"
234
+ dev_count=0
235
+ # distinguish "no rows" from "cannot parse" — a truncated
236
+ # line, stray non-JSON row, or merge=union conflict artefact in the
237
+ # shared status.jsonl must NOT silently degrade to dev_count=0.
238
+ # Only an absent file is a legitimate zero.
239
+ if [ -f "$status_file" ]; then
240
+ if ! dev_count=$(jq -s --arg f "$guard_fid" \
241
+ '[.[] | select(.type=="dev-dispatch" and .fid==$f) | .headSha] | unique | length' \
242
+ "$status_file" 2>/dev/null); then
243
+ echo "::notice::$status_file is unparseable — refusing to dispatch for $guard_fid uncounted (fail-closed)."
244
+ return 1
245
+ fi
246
+ fi
247
+ if [ "$dev_count" -ge "$MAX_DEV_DISPATCH_ATTEMPTS" ]; then
248
+ echo "::notice::FID $guard_fid exhausted $MAX_DEV_DISPATCH_ATTEMPTS dev-triggered debug dispatches — operator review required (delete dev-dispatch rows in status.jsonl to reset)."
249
+ return 1
250
+ fi
251
+ parent_sha=$(git -C "$GITHUB_WORKSPACE" rev-parse origin/dev 2>/dev/null || echo "")
252
+ jq -nc --arg t "$(date -u +%FT%TZ)" --arg f "$guard_fid" --arg h "$guard_head_sha" --arg p "$parent_sha" \
253
+ '{type:"dev-dispatch", workflow:"auto", at:$t, fid:$f, headSha:$h, parentSha:$p}' \
254
+ >> "$status_file"
255
+ git -C "$GITHUB_WORKSPACE" add -- "$status_file"
256
+ git -C "$GITHUB_WORKSPACE" commit -m "docs($guard_fid): dev-dispatch telemetry [skip ci]" -- "$status_file"
257
+ if ! git -C "$GITHUB_WORKSPACE" push origin dev 2>/dev/null; then
258
+ git -C "$GITHUB_WORKSPACE" fetch origin dev
259
+ git -C "$GITHUB_WORKSPACE" rebase origin/dev || { git -C "$GITHUB_WORKSPACE" rebase --abort || true; }
260
+ git -C "$GITHUB_WORKSPACE" push origin dev 2>/dev/null || true
261
+ fi
262
+ git -C "$GITHUB_WORKSPACE" fetch origin dev
263
+ # `git show` has its own `|| true` so a missing file does not trip
264
+ # pipefail across `| jq`.
265
+ landed=$( (git -C "$GITHUB_WORKSPACE" show "origin/dev:${status_file}" 2>/dev/null || true) \
266
+ | jq -s --arg f "$guard_fid" --arg h "$guard_head_sha" \
267
+ '[.[] | select(.type=="dev-dispatch" and .fid==$f and .headSha==$h)] | length' 2>/dev/null || echo 0)
268
+ if [ "${landed:-0}" -lt 1 ]; then
269
+ echo "::notice::dev-dispatch row for $guard_fid @ $guard_head_sha is not on origin/dev after retry — refusing to dispatch uncounted (fail-closed). Resolve the dev push contention and re-run via workflow_dispatch."
270
+ return 1
271
+ fi
272
+ return 0
273
+ }
274
+
275
+ if [ "$BRANCH" = "dev" ]; then
276
+ # Post-merge dev CI — no open PR. Recover FID from squash-merge commit
277
+ # scope. dev success = regression check passed = no-op (the merge
278
+ # already happened).
279
+ if [ "$PHASE" = "ship" ]; then
280
+ echo "::notice::dev CI passed — post-merge regression check OK, no-op exit."
281
+ echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0
282
+ fi
283
+ # PHASE=debug below.
284
+ # Primary: parse FID from commit scope: feat(363-widen-bkit-cloud-trigger): ...
285
+ # Shape-tolerant: the regex accepts BOTH GitHub
286
+ # (363-slug) and Linear (bar-123-slug) FID SHAPES, mirroring the
287
+ # alternation the feat/** fallback below uses. The kill switch
288
+ # below (`gh issue view "$ISSUE"`) is GitHub-Issues-only, so a
289
+ # Linear FID no-ops there (empty labels -> bkit:auto absent).
290
+ # `head -1` FIRST — head_commit.message is subject+body and
291
+ # grep's `^` anchors per line, so without it a squash body line
292
+ # (GitHub's default body is the list of source commit subjects)
293
+ # like "feat(999-other): ..." would win and key the cap counter,
294
+ # status path and /bkit-debug dispatch to an unrelated feature.
295
+ FID=$(printf '%s' "$COMMIT_MSG" | head -1 | grep -oE '^\w+\((([0-9]+|[a-z]+-[0-9]+)-[a-z0-9-]+)\):' | sed -E 's/^\w+\(([^)]+)\):/\1/' | head -1 || true)
296
+ if [ -z "$FID" ]; then
297
+ # Fallback: gh api merge-commit linked PR -> PR body bkit:fid marker.
298
+ # filter to same-repo MERGED PRs (the endpoint also returns OPEN
299
+ # fork PRs at this SHA).
300
+ PR_BODY=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}/pulls" \
301
+ --jq '[.[] | select(.head.repo.full_name == env.GITHUB_REPOSITORY and .merged_at != null)] | .[0].body // empty' 2>/dev/null || echo "")
302
+ FID=$(printf '%s' "$PR_BODY" | grep -oE 'bkit:fid=[^[:space:]>]+' | sed 's/bkit:fid=//' | head -1 || true)
303
+ fi
304
+ if [ -z "$FID" ] || ! [[ "$FID" =~ ^([0-9]+|[a-z]+-[0-9]+)-[a-z0-9-]+$ ]]; then
305
+ echo "::notice::Cannot derive FID by dev commit scope or linked PR — no-op exit (fail-safe)."
306
+ echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0
307
+ fi
308
+ # `|| true` is load-bearing under `set -euo pipefail` —
309
+ # this runs BEFORE the slug allowlist, so a non-FID branch
310
+ # (Renovate, a hand-named hotfix) yields no match,
311
+ # pipefail propagates grep's exit 1, and the step dies red
312
+ # instead of reaching the designed no-op exit just below.
313
+ ISSUE=$(printf '%s' "$FID" | grep -oE '^[0-9]+|^[a-z]+-[0-9]+' | head -1 || true)
314
+ ARG="$FID"
315
+ # Kill switch: re-check bkit:auto on the issue (live revocation).
316
+ # exact label match, not substring. MUST precede the stale-run
317
+ # guard and the dispatch-cap guard below; it needs nothing they set.
318
+ if ! gh issue view "$ISSUE" --json labels --jq '.labels[].name' 2>/dev/null | grep -qxF 'bkit:auto'; then
319
+ echo "::notice::Issue #$ISSUE no longer carries bkit:auto — no-op exit (kill switch)."
320
+ echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0
321
+ fi
322
+ # Stale-run guard: HEAD_SHA is current iff it is the headSha of the
323
+ # most recent COMPLETED CI run on dev ([skip ci] close commits never
324
+ # appear in gh run list). --workflow bkit-ci.yml (filename), not `bkit-ci`
325
+ # (display name).
326
+ LATEST_CI_SHA=$(gh run list --branch dev --workflow bkit-ci.yml --status completed --limit 10 \
327
+ --json headSha --jq '.[0].headSha // empty' 2>/dev/null || echo "")
328
+ # an empty LATEST_CI_SHA disables the staleness check (fail-open)
329
+ # and emits a ::warning:: naming the bkit-ci.yml filename requirement.
330
+ if [ -z "$LATEST_CI_SHA" ]; then
331
+ echo "::warning::gh run list --branch dev --workflow bkit-ci.yml returned no completed runs — stale-run guard disabled for this dispatch (proceeding, fail-open). If this persists, verify the consumer CI workflow file is named bkit-ci.yml (\`gh workflow view ci.yml\`)."
332
+ fi
333
+ if [ -n "$LATEST_CI_SHA" ] && [ "$HEAD_SHA" != "$LATEST_CI_SHA" ]; then
334
+ # A DIFFERENT FID's dev CI failure may have superseded this run
335
+ # in the shared `bkit-auto-dev` concurrency group; this FID's
336
+ # post-merge failure is dropped here. The drop is recorded in the
337
+ # RUN SUMMARY, never as a committed status.jsonl row (dev already
338
+ # advanced).
339
+ DROP_ROW=$(jq -nc --arg t "$(date -u +%FT%TZ)" --arg f "$FID" --arg h "$HEAD_SHA" --arg latest "$LATEST_CI_SHA" \
340
+ '{type:"dev-dispatch-dropped", workflow:"auto", at:$t, fid:$f, headSha:$h, latestSha:$latest}')
341
+ {
342
+ echo "### bkit dev-dispatch dropped"
343
+ echo ""
344
+ echo "FID \`$FID\` had a post-merge \`dev\` CI failure that was superseded before dispatch."
345
+ echo ""
346
+ echo '```json'
347
+ echo "$DROP_ROW"
348
+ echo '```'
349
+ } >> "${GITHUB_STEP_SUMMARY:-/dev/null}"
350
+ echo "::warning::Stale dev CI (head_sha=$HEAD_SHA, latest completed dev CI head=$LATEST_CI_SHA) for FID $FID — no-op exit. This FID's post-merge CI failure may have been superseded by a DIFFERENT FID's dev push under the shared bkit-auto-dev concurrency group; see this run's job summary (dev-dispatch-dropped) if this FID does not otherwise recover."
351
+ echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0
352
+ fi
353
+ # Loop cap + counter write (fail-closed).
354
+ bkit_dev_dispatch_guard "$FID" "$HEAD_SHA" || { echo "skip=true" >> "$GITHUB_OUTPUT"; exit 0; }
355
+ else
356
+ # feat/** pre-merge path (PR-backed FID recovery).
357
+ PR_NUMBER=$(gh pr list --head "$BRANCH" --base dev --state open --json number --jq '.[0].number // empty')
358
+ if [ -z "$PR_NUMBER" ]; then
359
+ echo "::notice::No open PR for branch $BRANCH — no-op exit."
360
+ echo "skip=true" >> "$GITHUB_OUTPUT"
361
+ exit 0
362
+ fi
363
+ ARG="$PR_NUMBER"
364
+
365
+ # PRIMARY: parse the bkit:issue / bkit:fid markers shipped in every
366
+ # bkit-build PR body. Also assert the marker-derived FID
367
+ # against the slug allowlist here — bkit:fid=[^[:space:]>]+ admits
368
+ # '/', '.', '..' and glob metacharacters, so an unvalidated match
369
+ # falls through to path construction (find -path / mkdir -p / git
370
+ # commit) in bkit_dev_dispatch_guard below. A mismatch falls through
371
+ # to the branch fallback exactly like an empty/missing marker.
372
+ PR_BODY=$(gh pr view "$PR_NUMBER" --json body --jq .body 2>/dev/null || echo "")
373
+ ISSUE=$(echo "$PR_BODY" | grep -oE 'bkit:issue=#[0-9]+' | sed 's/bkit:issue=#//' | head -1 || true)
374
+ FID=$(echo "$PR_BODY" | grep -oE 'bkit:fid=[^[:space:]>]+' | sed 's/bkit:fid=//' | head -1 || true)
375
+ if [ -z "$ISSUE" ] || [ -z "$FID" ] || ! [[ "$FID" =~ ^([0-9]+|[a-z]+-[0-9]+)-[a-z0-9-]+$ ]]; then
376
+ # FALLBACK: extract FID from the branch name (feat/{FID}) when the
377
+ # PR body carries no usable bkit:fid= marker.
378
+ # keep the FULL slug (do NOT collapse to the leading
379
+ # numeric/alpha id, e.g. '363' instead of
380
+ # '363-widen-bkit-cloud-trigger'). ISSUE (short
381
+ # numeric/alpha prefix, used only for `gh issue view`) is derived
382
+ # FROM the full FID, not the other way round. NOTE the '#' sed
383
+ # delimiter: with '|' the alternation would need escaping and is
384
+ # ambiguous under -E.
385
+ FID=$(echo "$BRANCH" | sed -E 's#^feat/##')
386
+ # `|| true` is load-bearing under `set -euo pipefail` —
387
+ # this runs BEFORE the slug allowlist, so a non-FID branch
388
+ # (Renovate, a hand-named hotfix) yields no match,
389
+ # pipefail propagates grep's exit 1, and the step dies red
390
+ # instead of reaching the designed no-op exit just below.
391
+ ISSUE=$(printf '%s' "$FID" | grep -oE '^[0-9]+|^[a-z]+-[0-9]+' | head -1 || true)
392
+ fi
393
+ if [ -z "$FID" ] || [ -z "$ISSUE" ] || ! [[ "$FID" =~ ^([0-9]+|[a-z]+-[0-9]+)-[a-z0-9-]+$ ]]; then
394
+ echo "::notice::Cannot derive FID/ISSUE for branch $BRANCH — no-op exit (fail-safe)."
395
+ echo "skip=true" >> "$GITHUB_OUTPUT"
396
+ exit 0
397
+ fi
398
+
399
+ # Cheap-tier kill switch: re-check bkit:auto on the issue (live revocation).
400
+ # exact label match, not substring.
401
+ if ! gh issue view "$ISSUE" --json labels --jq '.labels[].name' 2>/dev/null | grep -qxF 'bkit:auto'; then
402
+ echo "::notice::Issue #$ISSUE no longer carries bkit:auto — no-op exit (kill switch)."
403
+ echo "skip=true" >> "$GITHUB_OUTPUT"
404
+ exit 0
405
+ fi
406
+
407
+ # A build still writing this branch owns it: no-op exit. "Still
408
+ # running" = the branch's status.jsonl has a build workflow-started
409
+ # with no later workflow-done / workflow-failed AND its newest build
410
+ # row is under 30 min old (the lock-staleness window — older means
411
+ # abandoned). Unreadable status fails open: dispatch.
412
+ git fetch -q origin "$BRANCH" 2>/dev/null || true
413
+ BUILD_STATUS=$(git ls-tree -r --name-only "origin/$BRANCH" -- docs/plans 2>/dev/null | grep -E "/logs/$FID/status\.jsonl$" | sort | tail -1 || true)
414
+ if [ -n "$BUILD_STATUS" ]; then
415
+ BUILD_AGE=$(git show "origin/$BRANCH:$BUILD_STATUS" 2>/dev/null | jq -rs '[.[] | select(.workflow=="build")] | sort_by(.at) as $r | ($r | map(select(.type=="workflow-started" or .type=="workflow-done" or .type=="workflow-failed")) | last | .type) as $t | if $t=="workflow-started" then (now - ($r | last | .at | fromdateiso8601) | floor) else empty end' 2>/dev/null || true)
416
+ if [ -n "$BUILD_AGE" ] && [ "$BUILD_AGE" -lt 1800 ]; then
417
+ echo "::notice::Build for $FID still running on $BRANCH (last row ${BUILD_AGE}s ago) — no-op exit; the build owns the branch."
418
+ echo "skip=true" >> "$GITHUB_OUTPUT"
419
+ exit 0
420
+ fi
421
+ fi
422
+
423
+ # feat/** is NOT capped by MAX_DEV_DISPATCH_ATTEMPTS: pre-merge,
424
+ # PR-scoped, bounded by the in-session MAX_DEBUG_ATTEMPT /
425
+ # MAX_NORMAL_ATTEMPT counters. The dev arm above is the only
426
+ # capped surface.
427
+ fi
428
+ fi
429
+ # Guard: arg must be alphanumeric/dash/dot/slash (numeric PR/issue ids + FIDs like
430
+ # 245-opencode-provider-host). workflow_dispatch inputs.issue flows unsanitized into
431
+ # both runner jobs' model prompt — reject anything else (prompt-injection guard).
432
+ if ! [[ "$ARG" =~ ^[0-9A-Za-z._/-]+$ ]]; then
433
+ echo "::error::Invalid arg value '${ARG}' — aborting." >&2
434
+ exit 1
435
+ fi
436
+ {
437
+ echo "skip=false"
438
+ echo "phase=$PHASE"
439
+ echo "arg=$ARG"
440
+ } >> "$GITHUB_OUTPUT"
441
+
442
+ # ---------------------------------------------------------------------------
443
+ # claude job — dispatch via claude-code-action@v1 (ANTHROPIC_API_KEY required).
444
+ # Runs only when the context job found ANTHROPIC_API_KEY set and resolved a phase.
445
+ # OIDC auth via Claude GitHub App (id-token: write); requires one-time
446
+ # `/install-github-app` in the consumer repo.
447
+ # ---------------------------------------------------------------------------
448
+ run:
449
+ name: claude (${{ github.event_name }})
450
+ needs: context
451
+ if: needs.context.outputs.claude == 'true' && needs.context.outputs.skip != 'true'
452
+ runs-on: {{CLOUD_RUNNER}}
453
+ permissions:
454
+ contents: write
455
+ pull-requests: write
456
+ issues: write
457
+ actions: read
458
+ # id-token: write — required for claude-code-action@v1 to authenticate as the
459
+ # Claude GitHub App via OIDC (getOidcToken).
460
+ id-token: write
461
+ steps:
462
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
463
+ with:
464
+ # Check out `dev` at the workspace root: the cloud orchestrator writes its own
465
+ # `cloud` run to dev's `status.jsonl`, and the dispatched phase skill creates its
466
+ # own `feat/{FID}` worktree under `.worktrees/`. ship/debug then read+write
467
+ # their branch-local `status.jsonl` on `feat/{FID}` (worktree-prefer at Step 1);
468
+ # design/plan/build start from dev. NDJSON + `*.jsonl merge=union` keeps it merge-safe.
469
+ ref: dev
470
+ fetch-depth: 0
471
+ # The auto-provided GITHUB_TOKEN inherits the `permissions:` block above.
472
+ token: ${{ github.token }}
473
+
474
+ # Installs the vale binary for bkit-cloud-bootstrap.sh's `vale sync` and the dispatched
475
+ # phase's lint:prose (as the cloud.md web env's setup script does). Pinned tarball +
476
+ # SHA mirror bkit-ci.yml.
477
+ - name: Install vale
478
+ env:
479
+ VALE_VERSION: "3.9.1"
480
+ VALE_SHA256: "fbc2eb47d0b8c50220ed1a2c5c611fbe0904ed567d638143d482016a18fd2db0"
481
+ run: |
482
+ curl -fsSL --retry 3 --retry-all-errors "https://github.com/errata-ai/vale/releases/download/v${VALE_VERSION}/vale_${VALE_VERSION}_Linux_64-bit.tar.gz" -o "$RUNNER_TEMP/vale.tar.gz"
483
+ echo "${VALE_SHA256} $RUNNER_TEMP/vale.tar.gz" | sha256sum -c -
484
+ tar -xzf "$RUNNER_TEMP/vale.tar.gz" -C "$RUNNER_TEMP" vale
485
+ echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
486
+
487
+ - name: Configure git user
488
+ run: |
489
+ git config user.name 'bkit-auto[bot]'
490
+ git config user.email 'bkit-auto@users.noreply.github.com'
491
+
492
+ - name: Dispatch /bkit-auto on Claude Code runner
493
+ uses: anthropics/claude-code-action@58985842b834ed26087302ba27d07bc24ca8697a # v1.0.244
494
+ with:
495
+ # Orchestrator contract: `/bkit-auto <phase> <arg>` where <arg> is the open
496
+ # PR number (ship/debug) or the tracker issue number/id (design/plan/build).
497
+ # The context job validated arg against its allowlist.
498
+ prompt: "/bkit-auto ${{ needs.context.outputs.phase }} ${{ needs.context.outputs.arg }}"
499
+ # Lock the runner-side session to the same tool surface bkit grants the local
500
+ # orchestrator. GitHub MCP surface is always available; this workflow is
501
+ # GitHub-tracker only (cloud=claude requires tracker=github).
502
+ claude_args: "--allowed-tools=Bash,Edit,Write,Read,Grep,Glob,WebFetch,Skill,mcp__github__*"
503
+ env:
504
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
505
+ GH_TOKEN: ${{ github.token }}
506
+
507
+ # ---------------------------------------------------------------------------
508
+ # opencode job — dispatch via `opencode run` CLI (OPENCODE_PROVIDER_KEY required).
509
+ # Runs only when the context job found OPENCODE_PROVIDER_KEY set and resolved a phase.
510
+ # The committed .opencode/opencode.json provides provider config + model pins —
511
+ # no model is hard-coded in this YAML. No OIDC / Claude identity.
512
+ # OPENCODE_PROVIDER_KEY is fanned out to all known provider env var names so the
513
+ # opencode.json ${VAR} reference resolves regardless of which provider is installed.
514
+ # ---------------------------------------------------------------------------
515
+ opencode:
516
+ name: opencode (${{ github.event_name }})
517
+ needs: context
518
+ if: needs.context.outputs.opencode == 'true' && needs.context.outputs.skip != 'true'
519
+ runs-on: {{CLOUD_RUNNER}}
520
+ permissions:
521
+ contents: write
522
+ pull-requests: write
523
+ issues: write
524
+ actions: read
525
+ steps:
526
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
527
+ with:
528
+ ref: dev
529
+ fetch-depth: 0
530
+ token: ${{ github.token }}
531
+
532
+ - name: Configure git user
533
+ run: |
534
+ git config user.name 'bkit-auto[bot]'
535
+ git config user.email 'bkit-auto@users.noreply.github.com'
536
+
537
+ - name: Install opencode
538
+ run: |
539
+ # Version-pinned. No updater bumps this pin: take the new version from bkit's
540
+ # template when `bkit upgrade` lists this file, or bump it by hand.
541
+ # 2.0.x ships ONLY on npm as `@opencode/cli` — there is no 2.x GitHub release (latest
542
+ # is v1.19.0), so the curl installer (https://opencode.ai/install downloads GitHub
543
+ # release binaries) cannot fetch 2.0.26. npm's postinstall selects the runner's
544
+ # platform binary.
545
+ npm install -g @opencode/cli@2.0.26
546
+ echo "$(npm prefix -g)/bin" >> "$GITHUB_PATH"
547
+
548
+ - name: Dispatch /bkit-auto on opencode runner
549
+ env:
550
+ GH_TOKEN: ${{ github.token }}
551
+ # Fan out the single OPENCODE_PROVIDER_KEY secret to every supported cloud provider's
552
+ # env var name, so the committed .opencode/opencode.json {env:VAR} reference resolves
553
+ # regardless of which provider the consumer installed (openrouter/ollama/opencode).
554
+ # `opencode` (the opencode-native Zen gateway) reads BKIT_OPENCODE_API_KEY. No Claude
555
+ # identity leak — ANTHROPIC_API_KEY is absent.
556
+ BKIT_OPENROUTER_API_KEY: ${{ secrets.OPENCODE_PROVIDER_KEY }}
557
+ BKIT_OLLAMA_API_KEY: ${{ secrets.OPENCODE_PROVIDER_KEY }}
558
+ BKIT_OPENCODE_API_KEY: ${{ secrets.OPENCODE_PROVIDER_KEY }}
559
+ OPENCODE_PROVIDER_KEY: ${{ secrets.OPENCODE_PROVIDER_KEY }}
560
+ # Pass phase/arg via env to avoid ${{ }} expansion in run: shell string (injection guard).
561
+ BKIT_PHASE: ${{ needs.context.outputs.phase }}
562
+ BKIT_ARG: ${{ needs.context.outputs.arg }}
563
+ run: |
564
+ opencode run "/bkit-auto $BKIT_PHASE $BKIT_ARG"