@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,339 @@
1
+ // render/hosts.ts — workflow and prompt sources → host agent, command and skill copies
2
+ // (claude T1/T2, cursor T3, opencode, codex) and the frontmatter parser they share.
3
+ import { formatModelPin, lookupEffort } from "./models.js";
4
+ import { LOG_PREFIX } from "../shared/log-prefix.js";
5
+ /**
6
+ * Convert a Claude `tools:` frontmatter block (a YAML array of capitalized tool names,
7
+ * e.g. `- Read`/`- Write`) into opencode's `AgentConfig.tools` shape: an object map of
8
+ * lowercase tool names → true (`tools:\n read: true`). opencode REJECTS the array form
9
+ * ("tools: Expected object | undefined, got [...]"), and its tool names are lowercase.
10
+ * MCP tools are `<server>_<tool>` on opencode, so Claude's `mcp__<server>__<tool>` (or
11
+ * `mcp__<server>__*`) is respelled rather than lowercased; the key may be a `*` pattern.
12
+ * Returns "" when there are no tools (field omitted — also valid per the schema).
13
+ */
14
+ export function opencodeToolsBlock(toolsBlock) {
15
+ if (!toolsBlock)
16
+ return "";
17
+ const names = [];
18
+ for (const m of toolsBlock.matchAll(/^[ \t]*-[ \t]*([A-Za-z][\w*-]*)/gm))
19
+ names.push(m[1]);
20
+ if (names.length === 0) {
21
+ // Fallback: inline array form `tools: [Read, Write]`.
22
+ const inline = toolsBlock.match(/\[([^\]]*)\]/);
23
+ if (inline) {
24
+ for (const t of inline[1].split(",")) {
25
+ const n = t.trim().replace(/['"]/g, "");
26
+ if (n)
27
+ names.push(n);
28
+ }
29
+ }
30
+ }
31
+ if (names.length === 0)
32
+ return "";
33
+ let out = "tools:\n";
34
+ for (const n of names) {
35
+ const mcp = /^mcp__(.+?)__(.+)$/.exec(n);
36
+ out += ` ${mcp ? `${mcp[1]}_${mcp[2]}` : n.toLowerCase()}: true\n`;
37
+ }
38
+ return out;
39
+ }
40
+ /**
41
+ * OC1: opencode agent frontmatter rewrite.
42
+ * Emits: mode, name, description, model, tools (Claude array → opencode object map),
43
+ * variant (the effort table's value for this agent, from the one shared "OpenCode"
44
+ * ladder). The variant is a SEPARATE field, not a `#`-suffix on the model: 1.x reads
45
+ * `variant:` natively, 2.0 joins `model` + `variant` internally, and a variant joined
46
+ * to the model string with `#` breaks 1.x (its model id lookup keeps the suffix). The
47
+ * ollama gateway is exempt from `variant:` — its provider builds model entries with no
48
+ * variants, so any variant there is a hard 2.0 error; omit it and let opencode use its
49
+ * own default. Drops: Claude-only fields (permissionMode, maxTurns, is_background,
50
+ * readonly) and the original effort field. Hard-fails with non-zero exit if model
51
+ * lookup missing for name.
52
+ */
53
+ export function applyOpencodeAgent(content, opencodeModelLookup, effortMap, provider) {
54
+ const fmMatch = content.match(/^(---\r?\n)([\s\S]*?)(\r?\n---\r?\n?)/);
55
+ if (!fmMatch)
56
+ return content;
57
+ const fmBlock = fmMatch[2];
58
+ const afterFm = content.slice(fmMatch[0].length);
59
+ const parsed = parseFrontmatter(fmBlock);
60
+ const name = parsed.get("name") ?? "";
61
+ if (!name) {
62
+ console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
63
+ process.exit(1);
64
+ }
65
+ const opencodeModel = opencodeModelLookup.get(name);
66
+ if (!opencodeModel) {
67
+ console.error(`${LOG_PREFIX} Missing opencode model lookup for ${name}`);
68
+ process.exit(1);
69
+ }
70
+ const description = parsed.get("description") ?? "";
71
+ const effort = parsed.get("effort");
72
+ const toolsBlock = extractFrontmatterField(fmBlock, "tools");
73
+ let newFm = "---\n";
74
+ newFm += `mode: subagent\n`;
75
+ newFm += `name: ${name}\n`;
76
+ if (description.includes("\n")) {
77
+ const indented = description.split("\n").join("\n ");
78
+ newFm += `description: |\n ${indented}\n`;
79
+ }
80
+ else {
81
+ newFm += `description: ${description}\n`;
82
+ }
83
+ // Thinking effort is a model variant in its own `variant:` field. Program-keyed: every
84
+ // opencode gateway shares the one "OpenCode" ladder; the gateway is not consulted —
85
+ // except ollama, which cannot carry a variant at all (see the function docstring).
86
+ const modelPin = formatModelPin("opencode", provider ?? "", opencodeModel);
87
+ newFm += `model: ${modelPin}\n`;
88
+ const variant = provider !== "ollama" && effort && effortMap
89
+ ? lookupEffort(effortMap, "opencode", effort)
90
+ : null;
91
+ if (variant)
92
+ newFm += `variant: ${variant}\n`;
93
+ newFm += opencodeToolsBlock(toolsBlock);
94
+ newFm += "---\n";
95
+ return newFm + afterFm;
96
+ }
97
+ /**
98
+ * Remap frontmatter `effort:` through the prompts.md effort table for a host column
99
+ * (Claude / Cursor). Used by Claude (native `effort:`) and Cursor (emits `effort:` from
100
+ * the Cursor column so thinking intent survives the T3 rewrite).
101
+ */
102
+ export function applyEffortRemap(content, effortMap, host) {
103
+ const fmMatch = content.match(/^(---\r?\n)([\s\S]*?)(\r?\n---\r?\n?)/);
104
+ if (!fmMatch)
105
+ return content;
106
+ const fmBlock = fmMatch[2];
107
+ const afterFm = content.slice(fmMatch[0].length);
108
+ const parsed = parseFrontmatter(fmBlock);
109
+ const effort = parsed.get("effort");
110
+ if (!effort)
111
+ return content;
112
+ const mapped = lookupEffort(effortMap, host, effort);
113
+ if (mapped === effort)
114
+ return content;
115
+ const newFm = fmBlock.replace(/^effort:\s*\S+\s*$/m, `effort: ${mapped}`);
116
+ return `---\n${newFm}\n---\n${afterFm}`;
117
+ }
118
+ /**
119
+ * Escape a body for a TOML basic multi-line string (`"""` … `"""`).
120
+ *
121
+ * The body is emitted as a basic multi-line string with every sequence that would terminate
122
+ * or corrupt it (backslashes, a triple-quote run) neutralised.
123
+ */
124
+ export function escapeTomlMultiline(body) {
125
+ return body
126
+ .replace(/\\/g, "\\\\") // backslash first, or the escapes below get double-escaped
127
+ .replace(/"""/g, '\\"\\"\\"')
128
+ .replace(/\r\n/g, "\n");
129
+ }
130
+ /** Emit a TOML `key = "value"` line, escaping the basic-string metacharacters. */
131
+ function tomlString(key, value) {
132
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
133
+ return `${key} = "${escaped}"\n`;
134
+ }
135
+ /**
136
+ * Convert a Claude-format prompt (`.bkit/prompts/*.md`) into a Codex agent definition
137
+ * (`.codex/agents/<name>.toml`).
138
+ *
139
+ * Field mapping — `name`, `description` and `developer_instructions` are REQUIRED by Codex:
140
+ * name <- frontmatter `name`
141
+ * description <- frontmatter `description`
142
+ * developer_instructions <- the markdown body
143
+ * model <- § Models `OpenAI` column (bare id; Codex names its gateway
144
+ * in `[model_providers.<id>]`, not in the pin)
145
+ * model_reasoning_effort <- § Effort `Codex` column
146
+ *
147
+ * NOT emitted — `tools:`. Codex has no per-agent tool allowlist (openai/codex#6049 is open);
148
+ * `sandbox_mode` is not emitted either. The declared `tools:` block is NOT enforced on this
149
+ * host (documented in providers.md).
150
+ */
151
+ export function applyCodexAgent(content, codexModelLookup, effortMap) {
152
+ const fmMatch = content.match(/^(---\r?\n)([\s\S]*?)(\r?\n---\r?\n?)/);
153
+ if (!fmMatch)
154
+ return content;
155
+ const fmBlock = fmMatch[2];
156
+ const body = content.slice(fmMatch[0].length).trim();
157
+ const parsed = parseFrontmatter(fmBlock);
158
+ const name = parsed.get("name") ?? "";
159
+ if (!name) {
160
+ console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
161
+ process.exit(1);
162
+ }
163
+ const model = codexModelLookup.get(name);
164
+ if (!model) {
165
+ console.error(`${LOG_PREFIX} Missing codex model lookup for ${name}`);
166
+ process.exit(1);
167
+ }
168
+ const effort = parsed.get("effort");
169
+ let out = "";
170
+ out += tomlString("name", name);
171
+ out += tomlString("description", parsed.get("description") ?? "");
172
+ out += tomlString("model", formatModelPin("codex", "openai", model));
173
+ if (effort && effortMap) {
174
+ out += tomlString("model_reasoning_effort", lookupEffort(effortMap, "codex", effort));
175
+ }
176
+ out += `developer_instructions = """\n${escapeTomlMultiline(body)}\n"""\n`;
177
+ return out;
178
+ }
179
+ /**
180
+ * Session-prompt anchor prepended to every opencode command body. OpenCode
181
+ * substitutes `$ARGUMENTS` with everything typed after the slash command before
182
+ * the template is sent to the model; this anchor carries the user's input into the
183
+ * command. One top anchor, at the head where the workflows' Step 1 issue-extraction
184
+ * ("scan session prompt") reads it. The managed-version stamp is prepended afterwards,
185
+ * so this renders just below it.
186
+ */
187
+ export const OPENCODE_SESSION_PROMPT_ANCHOR = "**Session prompt:**\n\n$ARGUMENTS\n\n---\n\n";
188
+ /**
189
+ * Command invocation rewrite, parameterised by the host's tool names. The rest of the
190
+ * rewrite (the `@name` → `/name` respelling on **Subagent:** lines) is host-agnostic.
191
+ * - `Agent` tool → the host's subagent tool (delegating to a child agent)
192
+ * - `Skill` tool → the host's skill tool (loading a slash-command skill)
193
+ * - @name → /name on **Subagent:** lines:
194
+ * - bare `**Subagent:** @name` (exact line)
195
+ * - real workflow shape `**Subagent:** Invoke \`@name\`…` (incl. indented lists)
196
+ * - Caution placeholder `Invoke using \`@name\`` → `\`/name\``
197
+ * Does NOT rewrite body prose, npm scopes, emails, or gate-checklist `@agent` refs.
198
+ */
199
+ function rewriteInvocations(content, tools) {
200
+ let result = content.replace(/`Agent` tool/g, `\`${tools.agent}\` tool`);
201
+ result = result.replace(/using `Agent` tool/g, `using \`${tools.agent}\` tool`);
202
+ result = result.replace(/`Skill` tool/g, `\`${tools.skill}\` tool`);
203
+ result = result.replace(/using `Skill` tool/g, `using \`${tools.skill}\` tool`);
204
+ // Backticked `@agent` on any **Subagent:** line (numbered, list-indented, or bare).
205
+ result = result.replace(/^([^\n]*?\*\*Subagent:\*\*[^\n]*?)`@([a-z][a-z0-9-]*)`/gm, "$1`/$2`");
206
+ // Bare `@agent` immediately after **Subagent:** (exact-line form).
207
+ result = result.replace(/^([^\n]*?\*\*Subagent:\*\* )@([a-z][a-z0-9-]*)\b/gm, "$1/$2");
208
+ result = result.replace(/Invoke using `@name`/g, "Invoke using `/name`");
209
+ return result;
210
+ }
211
+ /**
212
+ * Cursor command invocation rewrite. Cursor's one `Task` tool covers BOTH the subagent
213
+ * and the skill surface, so both Claude tools rewrite to `Task`. Paired with applyT1 in
214
+ * the Cursor render pipeline.
215
+ */
216
+ export function applyT2(content) {
217
+ return rewriteInvocations(content, { agent: "Task", skill: "Task" });
218
+ }
219
+ /**
220
+ * OpenCode command invocation rewrite. OpenCode 2.0 splits the surfaces: delegating to a
221
+ * child agent uses the `subagent` tool, and loading a skill uses the dedicated `skill`
222
+ * tool. (OpenCode 1.x had a single `task` tool; 2.0 renamed it and added `skill`.)
223
+ */
224
+ export function applyOpencodeToolRewrites(content) {
225
+ return rewriteInvocations(content, { agent: "subagent", skill: "skill" });
226
+ }
227
+ /**
228
+ * OC2: opencode command rewrite.
229
+ * - Strips leading YAML frontmatter block (same as T1).
230
+ * - Rewrites invocation spelling for opencode (see `applyOpencodeToolRewrites` — the
231
+ * `subagent` / `skill` tools, NOT Cursor's single `Task`).
232
+ * - Prepends the session-prompt `$ARGUMENTS` anchor.
233
+ */
234
+ export function applyOpencodeCommand(content) {
235
+ // Step 1: strip frontmatter (same as T1)
236
+ const stripped = content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").replace(/^\n+/, "");
237
+ // Step 2: rewrite invocations to opencode's tool names.
238
+ const result = applyOpencodeToolRewrites(stripped);
239
+ // Step 3: prepend the session-prompt anchor so the slash-command args survive.
240
+ return OPENCODE_SESSION_PROMPT_ANCHOR + result;
241
+ }
242
+ // T1: Replace the leading YAML frontmatter block with its `description:` value as a
243
+ // plain first line, for Cursor commands. Cursor prints a command file's literal first
244
+ // line as the description in the picker and hover, and it does not read frontmatter.
245
+ // Derived from the frontmatter at render time. No frontmatter, or frontmatter without
246
+ // `description`, falls back to a plain strip.
247
+ export function applyT1(content) {
248
+ const fm = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
249
+ if (!fm)
250
+ return content;
251
+ const body = content.slice(fm[0].length).replace(/^\n+/, "");
252
+ const eol = fm[0].includes("\r\n") ? "\r\n" : "\n";
253
+ const raw = parseFrontmatter(fm[1]).get("description")?.trim() ?? "";
254
+ const description = raw.replace(/^(['"])([\s\S]*)\1$/, "$2").trim();
255
+ return description ? `${description}${eol}${eol}${body}` : body;
256
+ }
257
+ // Parse simple YAML frontmatter block (key: value, or key: | multiline)
258
+ export function parseFrontmatter(fmBlock) {
259
+ const map = new Map();
260
+ const lines = fmBlock.split("\n");
261
+ let i = 0;
262
+ while (i < lines.length) {
263
+ const line = lines[i];
264
+ const keyMatch = line.match(/^([a-zA-Z_][a-zA-Z0-9_-]*):\s*(.*)/);
265
+ if (!keyMatch) {
266
+ i++;
267
+ continue;
268
+ }
269
+ const key = keyMatch[1];
270
+ const valueOnLine = keyMatch[2].trim();
271
+ if (valueOnLine === "|") {
272
+ const blockLines = [];
273
+ i++;
274
+ while (i < lines.length) {
275
+ const nextLine = lines[i];
276
+ if (/^[a-zA-Z_][a-zA-Z0-9_-]*:/.test(nextLine))
277
+ break;
278
+ blockLines.push(nextLine.replace(/^ {2}/, ""));
279
+ i++;
280
+ }
281
+ map.set(key, blockLines.join("\n").trim());
282
+ }
283
+ else {
284
+ map.set(key, valueOnLine);
285
+ i++;
286
+ }
287
+ }
288
+ return map;
289
+ }
290
+ // Extract a YAML field's raw block (including continuation lines) from a frontmatter string.
291
+ // Handles both inline (`field: [a, b]`) and multi-line list (`field:\n - a\n - b`) formats.
292
+ // Returns null if field absent.
293
+ function extractFrontmatterField(fmBlock, field) {
294
+ const re = new RegExp(`^(${field}:[ \\t]*[^\\n]*(?:\\n[ \\t]+[^\\n]*)*)`, "m");
295
+ const m = fmBlock.match(re);
296
+ return m ? m[1] : null;
297
+ }
298
+ // T3: Cursor subagent frontmatter rewrite.
299
+ // Emits: name, description, model, tools (passthrough — Cursor 2.4+ accepts identical tool names per BAR-113),
300
+ // effort (from prompts.md Cursor column). Drops: permissionMode, maxTurns, readonly, is_background.
301
+ // Hard-fails with non-zero exit if model lookup missing for name.
302
+ export function applyT3(content, modelLookup, effortMap) {
303
+ const fmMatch = content.match(/^(---\r?\n)([\s\S]*?)(\r?\n---\r?\n?)/);
304
+ if (!fmMatch)
305
+ return content;
306
+ const fmBlock = fmMatch[2];
307
+ const afterFm = content.slice(fmMatch[0].length);
308
+ const parsed = parseFrontmatter(fmBlock);
309
+ const name = parsed.get("name") ?? "";
310
+ if (!name) {
311
+ console.error(`${LOG_PREFIX} Subagent frontmatter missing 'name' field`);
312
+ process.exit(1);
313
+ }
314
+ const cursorModel = modelLookup.get(name);
315
+ if (!cursorModel) {
316
+ console.error(`${LOG_PREFIX} Missing model lookup for ${name}`);
317
+ process.exit(1);
318
+ }
319
+ const description = parsed.get("description") ?? "";
320
+ const effort = parsed.get("effort");
321
+ const toolsBlock = extractFrontmatterField(fmBlock, "tools");
322
+ let newFm = "---\n";
323
+ newFm += `name: ${name}\n`;
324
+ if (description.includes("\n")) {
325
+ const indented = description.split("\n").join("\n ");
326
+ newFm += `description: |\n ${indented}\n`;
327
+ }
328
+ else {
329
+ newFm += `description: ${description}\n`;
330
+ }
331
+ newFm += `model: ${formatModelPin("cursor", "cursor", cursorModel)}\n`;
332
+ if (effort && effortMap) {
333
+ newFm += `effort: ${lookupEffort(effortMap, "cursor", effort)}\n`;
334
+ }
335
+ if (toolsBlock)
336
+ newFm += `${toolsBlock}\n`;
337
+ newFm += "---\n";
338
+ return newFm + afterFm;
339
+ }
@@ -0,0 +1,288 @@
1
+ // render/models.ts — the `.bkit/prompts.md` § Models lookup: per-host model pins, consumer
2
+ // overrides, and the effort map.
3
+ import * as fs from "node:fs";
4
+ import { findLineAnchoredMarkers, selectMarkers } from "../install/managed-block.js";
5
+ import { LOG_PREFIX } from "../shared/log-prefix.js";
6
+ import { OPENCODE_PROVIDER_DEFAULTS } from "../shared/egress.js";
7
+ /**
8
+ * Parse .bkit/prompts.md § Models table → Map<name, columnValue>.
9
+ * columnHeader is the column header label to extract (e.g. "Cursor model", "opencode model").
10
+ * The function is header-addressed: it finds the column by name, never by position.
11
+ * Hard-fails (process.exit(1)) if the section or column header is not found.
12
+ */
13
+ export function parseModelLookupForColumn(subagentsMdPath, columnHeader) {
14
+ const content = fs.readFileSync(subagentsMdPath, "utf-8");
15
+ const map = new Map();
16
+ const modelsIdx = content.indexOf("## Models");
17
+ if (modelsIdx === -1) {
18
+ console.error(`${LOG_PREFIX} Could not find ## Models section in ${subagentsMdPath}`);
19
+ process.exit(1);
20
+ }
21
+ const lines = content.slice(modelsIdx).split("\n");
22
+ let inTable = false;
23
+ let columnIndex = -1;
24
+ for (const line of lines) {
25
+ const trimmed = line.trim();
26
+ if (!trimmed.startsWith("|")) {
27
+ if (inTable)
28
+ break;
29
+ continue;
30
+ }
31
+ inTable = true;
32
+ const cols = trimmed
33
+ .split("|")
34
+ .map((c) => c.trim())
35
+ .filter(Boolean);
36
+ // Header row: find the column index for our target header
37
+ if (columnIndex === -1) {
38
+ // Check if this is the header row by looking for the target column
39
+ const lowerCols = cols.map((c) => c.toLowerCase().replace(/`/g, ""));
40
+ const targetLower = columnHeader.toLowerCase().replace(/`/g, "");
41
+ const idx = lowerCols.findIndex((c) => c === targetLower);
42
+ if (idx !== -1) {
43
+ columnIndex = idx;
44
+ }
45
+ // Also skip separator rows (all --- cells)
46
+ if (trimmed.includes("---"))
47
+ continue;
48
+ continue;
49
+ }
50
+ // Separator row
51
+ if (trimmed.includes("---"))
52
+ continue;
53
+ if (cols.length <= columnIndex)
54
+ continue;
55
+ const nameMatch = cols[0].match(/^`([^`]+)`$/);
56
+ if (!nameMatch)
57
+ continue;
58
+ // Strip optional backtick wrapping from model value (table cells may use `model-name`)
59
+ const modelRaw = cols[columnIndex];
60
+ const modelClean = modelRaw.replace(/^`|`$/g, "");
61
+ map.set(nameMatch[1], modelClean);
62
+ }
63
+ if (columnIndex === -1) {
64
+ console.error(`${LOG_PREFIX} Could not find column "${columnHeader}" in ## Models table in ${subagentsMdPath}`);
65
+ process.exit(1);
66
+ }
67
+ return map;
68
+ }
69
+ /**
70
+ * Parse .bkit/prompts.md § Models table → Map<name, cursorModel>.
71
+ * Header-addressed: finds the "Cursor model" column by header name. Delegates to
72
+ * parseModelLookupForColumn.
73
+ */
74
+ export function parseModelLookup(subagentsMdPath) {
75
+ return parseModelLookupForColumn(subagentsMdPath, GATEWAY_COLUMN.cursor);
76
+ }
77
+ /**
78
+ * Gateway key → its prompts.md § Models column header.
79
+ *
80
+ * § Models is keyed on GATEWAY, never on program — a gateway shared by two programs is one
81
+ * column, not two. `anthropic` and `cursor` are the pinned gateways of the claude and cursor
82
+ * programs.
83
+ *
84
+ * Cells hold the BARE, gateway-scoped model id. Any prefix a program's config format needs
85
+ * is added at render time by formatModelPin — never stored in the table.
86
+ */
87
+ const GATEWAY_COLUMN = {
88
+ anthropic: "Anthropic",
89
+ cursor: "Cursor",
90
+ openrouter: "OpenRouter",
91
+ ollama: "Ollama",
92
+ "opencode-zen": "OpenCode Zen",
93
+ "opencode-go": "OpenCode Go",
94
+ openai: "OpenAI",
95
+ };
96
+ /**
97
+ * Spell a model pin the way a program's config file expects it.
98
+ *
99
+ * The § Models cell is the bare, gateway-scoped model id (`kimi-k2.7-code`). Claude and
100
+ * Cursor write it unchanged; opencode requires `<providerId>/<model>`, where providerId is
101
+ * the opencode-side id and is NOT always the bkit gateway key — the `opencode-zen` gateway
102
+ * is `opencode` on the opencode side. Route through opencodeProviderId, never the raw key.
103
+ */
104
+ export function formatModelPin(program, gateway, bareModel) {
105
+ if (program === "opencode")
106
+ return `${opencodeProviderId(gateway)}/${bareModel}`;
107
+ // claude / cursor / codex all take the bare id: Claude's and Cursor's gateway is implicit,
108
+ // Codex names its gateway in `[model_providers.<id>]`.
109
+ return bareModel;
110
+ }
111
+ /**
112
+ * Build the per-agent opencode model lookup for the selected provider.
113
+ * Source of truth = prompts.md § Models, which carries one curated column per
114
+ * provider ("OpenRouter", "Ollama"). Header-addressed. Every allowlisted provider
115
+ * ships a column; an absent one throws.
116
+ */
117
+ export function buildOpencodeModelLookup(subagentsMdPath, provider) {
118
+ const header = GATEWAY_COLUMN[provider];
119
+ if (!header) {
120
+ throw new Error(`buildOpencodeModelLookup: no prompts.md § Models column for provider ${JSON.stringify(provider)}`);
121
+ }
122
+ return parseModelLookupForColumn(subagentsMdPath, header);
123
+ }
124
+ /**
125
+ * Parse the consumer-owned `## Model Overrides` table (below the `bkit:end` marker)
126
+ * from an installed prompts.md. Rows are `| Prompt | Provider | Model |`. Best-effort:
127
+ * returns [] when the file, the marker, the section, or the rows are absent.
128
+ * Only the region after the line-anchored `bkit:end` is read — the bkit-managed block is
129
+ * never an override, even when its prose quotes the marker.
130
+ */
131
+ export function parseModelOverrides(promptsMdPath) {
132
+ if (!fs.existsSync(promptsMdPath))
133
+ return [];
134
+ const content = fs.readFileSync(promptsMdPath, "utf-8");
135
+ const endIdx = findLineAnchoredMarkers(content, selectMarkers("html-comment")[1])[0];
136
+ const region = endIdx === undefined ? "" : content.slice(endIdx);
137
+ const ovIdx = region.indexOf("## Model Overrides");
138
+ if (ovIdx === -1)
139
+ return [];
140
+ const out = [];
141
+ let inTable = false;
142
+ for (const line of region.slice(ovIdx).split("\n")) {
143
+ const t = line.trim();
144
+ if (!t.startsWith("|")) {
145
+ if (inTable)
146
+ break;
147
+ continue;
148
+ }
149
+ inTable = true;
150
+ const cells = t
151
+ .replace(/^\||\|$/g, "")
152
+ .split("|")
153
+ .map((s) => s.trim().replace(/^`|`$/g, ""));
154
+ if (cells.length < 3)
155
+ continue;
156
+ const [prompt, provider, model] = cells;
157
+ if (!prompt || !provider || !model)
158
+ continue;
159
+ if (prompt.toLowerCase() === "prompt")
160
+ continue; // header row
161
+ if (/^-+$/.test(prompt))
162
+ continue; // separator row
163
+ out.push({ prompt, provider, model });
164
+ }
165
+ return out;
166
+ }
167
+ /**
168
+ * Merge consumer overrides (from `overridesPath`, an installed prompts.md) into a
169
+ * per-agent model `lookup` for one host/provider key. Mutates `lookup` in place;
170
+ * only rows whose Provider matches `providerKey` and whose Prompt is a known agent win.
171
+ */
172
+ export function applyModelOverrides(lookup, providerKey, overridesPath) {
173
+ for (const o of parseModelOverrides(overridesPath)) {
174
+ if (o.provider.toLowerCase() === providerKey.toLowerCase() && lookup.has(o.prompt)) {
175
+ lookup.set(o.prompt, o.model);
176
+ }
177
+ }
178
+ }
179
+ // column → (sourceEffort → target)
180
+ /**
181
+ * Program → prompts.md effort-table column header.
182
+ *
183
+ * The effort table is keyed on PROGRAM, never on gateway — how hard to think is a property
184
+ * of the program's config format (`effort:` on Claude and Cursor, `reasoningEffort:` on
185
+ * opencode, on a different ladder), not of the model. Every opencode gateway therefore
186
+ * shares one column. That is the opposite axis to GATEWAY_COLUMN, and keeping the two apart
187
+ * is what stops either table growing as programs x gateways.
188
+ */
189
+ const EFFORT_COLUMN_FOR_PROGRAM = {
190
+ claude: "Claude",
191
+ cursor: "Cursor",
192
+ opencode: "OpenCode",
193
+ codex: "Codex",
194
+ };
195
+ /**
196
+ * Parse prompts.md effort→provider table (header starts with Default | Claude | …).
197
+ * Returns column → (sourceEffort → target). Hard-fails if the table is absent/malformed.
198
+ */
199
+ export function parseEffortMap(promptsMdPath) {
200
+ if (!fs.existsSync(promptsMdPath)) {
201
+ throw new Error(`${LOG_PREFIX} Effort map: file not found: ${promptsMdPath}`);
202
+ }
203
+ const content = fs.readFileSync(promptsMdPath, "utf-8");
204
+ const lines = content.split("\n");
205
+ let headerIdx = -1;
206
+ for (let i = 0; i < lines.length; i++) {
207
+ const t = lines[i].trim();
208
+ if (!t.startsWith("|"))
209
+ continue;
210
+ const headers = t
211
+ .replace(/^\||\|$/g, "")
212
+ .split("|")
213
+ .map((c) => c.trim().replace(/`/g, ""));
214
+ if (headers[0]?.toLowerCase() === "default" &&
215
+ headers.some((h) => h.toLowerCase() === "claude") &&
216
+ headers.some((h) => /opencode/i.test(h))) {
217
+ headerIdx = i;
218
+ break;
219
+ }
220
+ }
221
+ if (headerIdx === -1) {
222
+ throw new Error(`${LOG_PREFIX} Could not find Effort → provider thinking table (Default | Claude | …) in ${promptsMdPath}`);
223
+ }
224
+ const headerCells = lines[headerIdx]
225
+ .trim()
226
+ .replace(/^\||\|$/g, "")
227
+ .split("|")
228
+ .map((c) => c.trim().replace(/`/g, ""));
229
+ // Skip separator row
230
+ let rowStart = headerIdx + 1;
231
+ if (rowStart < lines.length && /^[|\s:-]+$/.test(lines[rowStart].trim()))
232
+ rowStart++;
233
+ const out = new Map();
234
+ for (const h of headerCells)
235
+ out.set(h, new Map());
236
+ for (let i = rowStart; i < lines.length; i++) {
237
+ const t = lines[i].trim();
238
+ if (!t.startsWith("|"))
239
+ break;
240
+ const cells = t
241
+ .replace(/^\||\|$/g, "")
242
+ .split("|")
243
+ .map((c) => c.trim().replace(/`/g, ""));
244
+ if (cells.length < headerCells.length)
245
+ continue;
246
+ const sourceEffort = cells[0];
247
+ if (!sourceEffort || /^-+$/.test(sourceEffort))
248
+ continue;
249
+ for (let c = 0; c < headerCells.length; c++) {
250
+ const target = cells[c];
251
+ if (!target)
252
+ continue;
253
+ out.get(headerCells[c]).set(sourceEffort, target);
254
+ }
255
+ }
256
+ const defaultCol = out.get("Default");
257
+ if (!defaultCol || defaultCol.size === 0) {
258
+ throw new Error(`${LOG_PREFIX} Effort map Default column empty in ${promptsMdPath}`);
259
+ }
260
+ return out;
261
+ }
262
+ /**
263
+ * Resolve the prompts.md effort-table column for a program.
264
+ * Throws on an unknown program; never falls back. Callers pass a program ("claude" /
265
+ * "cursor" / "opencode"), not a gateway.
266
+ */
267
+ export function effortColumnForProgram(program) {
268
+ const col = EFFORT_COLUMN_FOR_PROGRAM[program];
269
+ if (!col) {
270
+ throw new Error(`effortColumnForProgram: no prompts.md effort column for program ${JSON.stringify(program)}`);
271
+ }
272
+ return col;
273
+ }
274
+ /**
275
+ * Look up the emitted thinking value for a program + source prompt effort.
276
+ * Column resolution: program → named column → identity when the row is absent.
277
+ */
278
+ export function lookupEffort(effortMap, program, sourceEffort) {
279
+ return effortMap.get(effortColumnForProgram(program))?.get(sourceEffort) ?? sourceEffort;
280
+ }
281
+ /**
282
+ * The opencode-side provider id for a bkit provider key. Equal to the key for all providers
283
+ * (opencode → opencode, openrouter → openrouter, etc.). Model ids are `<providerId>/<model>`. Unknown
284
+ * keys pass through unchanged.
285
+ */
286
+ export function opencodeProviderId(providerKey) {
287
+ return OPENCODE_PROVIDER_DEFAULTS[providerKey]?.providerId ?? providerKey;
288
+ }
@@ -0,0 +1,33 @@
1
+ // render/parts.ts — splice the shared hook parts into each host's hook template.
2
+ //
3
+ // A host hook template (`.bkit/core/.claude/hooks/bkit-gateguard.cjs`, …) carries only
4
+ // what differs per host: its module syntax, its payload adapter, its output envelope.
5
+ // The code every host shares lives once in `.bkit/core/hooks/` and is spliced
6
+ // in wherever a template line reads `// {{BKIT_PART <file>}}` (JS) or
7
+ // `# {{BKIT_PART <file>}}` (shell). The generated hook is plain JS / bash with no runtime
8
+ // dependency on bkit, so it works before and without `node_modules`.
9
+ //
10
+ // Every template read on the install path goes through `readTemplate`, so install,
11
+ // upgrade, `bkit check` drift and uninstall all see the generated file.
12
+ import * as fs from "node:fs";
13
+ import * as path from "node:path";
14
+ import { getHooksRoot } from "../shared/package-roots.js";
15
+ /** A whole line naming one part: `// {{BKIT_PART name}}` or `# {{BKIT_PART name}}`. */
16
+ const PART_LINE = /^[ \t]*(?:\/\/|#)[ \t]*\{\{BKIT_PART[ \t]+([A-Za-z0-9._-]+)\}\}[ \t]*$/gm;
17
+ /**
18
+ * `content` with every part line replaced by that part's text. A part never names
19
+ * another part. A missing part is a corrupt package: it throws.
20
+ */
21
+ export function renderParts(content, partsDir = getHooksRoot()) {
22
+ return content.replace(PART_LINE, (_line, name) => {
23
+ const file = path.join(partsDir, name);
24
+ if (!fs.existsSync(file)) {
25
+ throw new Error(`[bkit-render] hook part not found: ${file}`);
26
+ }
27
+ return fs.readFileSync(file, "utf-8").replace(/\n$/, "");
28
+ });
29
+ }
30
+ /** A template file's content as install writes it, before token substitution. */
31
+ export function readTemplate(srcPath) {
32
+ return renderParts(fs.readFileSync(srcPath, "utf-8"));
33
+ }