@cbartens/bkit 0.0.0-stage → 5.0.0

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