@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,839 @@
1
+ // commands/install/uninstall.ts — Single owner of all uninstall logic. (P2.T5-P2.T8)
2
+ //
3
+ // runUninstall(modules, ctx) orchestrates:
4
+ // 1. For each installed file — single dispatch on entry.format:
5
+ // - "json" : stripTier2JsonScope (strip bkit-owned JSON scope)
6
+ // - "markered-text" : stripManagedBlock, remove file if empty remainder
7
+ // - "byte-equal-text" : delete only if unchanged since bkit wrote it (canonicalHashes)
8
+ // 2. package.json: the `bkit` install-state block (full/core uninstall). Scripts and
9
+ // devDeps are the consumer's — the bkit:gate:* names included — and are left alone.
10
+ // 2b. docs/ (full/core uninstall): bkit's managed block stripped from every installed
11
+ // `docs/*.md`, the owned `docs/templates/bkit-*.md` deleted.
12
+ // 3. .agents/ mirror files (bkit-prefix .md files in .claude/ .cursor/)
13
+ //
14
+ // Flags:
15
+ // --dry-run print decision table (FILE / DECISION / REASON) without writes
16
+ // --force override the byte-equal-text hash guard (delete even if consumer modified)
17
+ // --nuke confirm prompt then wipe ALL bkit-managed files regardless of format
18
+ // --yes skip interactive confirm for --nuke
19
+ //
20
+ // Observability: console.error("[bkit-uninstall] …") for all error paths.
21
+ import * as fs from "node:fs";
22
+ import * as path from "node:path";
23
+ import * as readline from "node:readline";
24
+ import { stripManagedBlock, detectMarkerStyle } from "../../install/managed-block.js";
25
+ import { readTemplate } from "../../render/parts.js";
26
+ import { getInstallManifest, } from "../../install/manifest.js";
27
+ import { isConsumerModified, readBkitVersion } from "../../install/version-file.js";
28
+ import { getPkgRoot, getSharedRoot, findTemplateSource, TEMPLATE_COPIES_DIR, } from "../../shared/package-roots.js";
29
+ import { PAYLOAD_LINKS } from "../../install/payload-links.js";
30
+ import { removeOpencodeProviderBlock, renderOpencodeJson } from "../../install/modules/opencode.js";
31
+ import { CLAUDE_CLOUD_RELPATH, CURSOR_CLOUD_RELPATH, resolveClaudeDerivedAllows, } from "../../install/cloud-env.js";
32
+ import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
33
+ // ---------------------------------------------------------------------------
34
+ // stripTier2JsonScope — remove bkit-owned JSON scope from consumer doc (BAR-167 Phase 1)
35
+ //
36
+ // Pure function — no file I/O.
37
+ //
38
+ // Algorithm:
39
+ // 1. Deep-clone consumer to `out`.
40
+ // 2. Walk template; for each leaf path `p`:
41
+ // - If `out[p]` deep-equals template[p] → delete it from `out`.
42
+ // - Else leave it (consumer has customised it — preserve).
43
+ // 3. Prune empty intermediate objects ONLY where template populated them
44
+ // (NOT arrays; NOT consumer-only siblings).
45
+ // 4. Return `out`.
46
+ //
47
+ // Consumer-only keys at any level are preserved byte-identical.
48
+ // ---------------------------------------------------------------------------
49
+ /**
50
+ * Detect the tracker bkit seeded into opencode.json from its mcp keys. The template ships an
51
+ * `@@OPENCODE_TRACKER_MCP@@` sentinel KEY that renders to `github` / `linear` at install, so a
52
+ * strip-scope keyed on the raw template never matches — these detectors let uninstall render the
53
+ * template the same way the install did before stripping. Keyed on bkit's known tracker names so
54
+ * a consumer-added mcp server is never mistaken for bkit's.
55
+ */
56
+ function detectOpencodeTracker(doc) {
57
+ const mcp = doc.mcp;
58
+ if (mcp !== null && typeof mcp === "object" && !Array.isArray(mcp)) {
59
+ if ("github" in mcp)
60
+ return "github";
61
+ if ("linear" in mcp)
62
+ return "linear";
63
+ }
64
+ return "none";
65
+ }
66
+ /** Detect the opencode provider key bkit seeded (the first `provider` block key). */
67
+ function detectOpencodeProvider(doc) {
68
+ const provider = doc.provider;
69
+ if (provider !== null && typeof provider === "object" && !Array.isArray(provider)) {
70
+ const keys = Object.keys(provider);
71
+ if (keys.length > 0) {
72
+ const first = keys[0];
73
+ // Zen block is keyed `opencode` (built-in id); map back to the bkit CLI key.
74
+ return first === "opencode" ? "opencode-zen" : first;
75
+ }
76
+ }
77
+ return "opencode-zen";
78
+ }
79
+ export function stripTier2JsonScope(consumerDoc, templateDoc) {
80
+ const out = JSON.parse(JSON.stringify(consumerDoc));
81
+ _stripScope(out, templateDoc);
82
+ return out;
83
+ }
84
+ function _stripScope(consumer, template) {
85
+ for (const key of Object.keys(template)) {
86
+ const tVal = template[key];
87
+ const cVal = consumer[key];
88
+ if (cVal === undefined)
89
+ continue; // consumer doesn't have it — nothing to strip
90
+ if (tVal !== null &&
91
+ typeof tVal === "object" &&
92
+ !Array.isArray(tVal) &&
93
+ cVal !== null &&
94
+ typeof cVal === "object" &&
95
+ !Array.isArray(cVal)) {
96
+ // Both plain objects — recurse into them
97
+ const tObj = tVal;
98
+ const cObj = cVal;
99
+ _stripScope(cObj, tObj);
100
+ // Prune empty intermediate only if template populated this key
101
+ if (Object.keys(cObj).length === 0) {
102
+ delete consumer[key];
103
+ }
104
+ }
105
+ else if (Array.isArray(tVal) && Array.isArray(cVal)) {
106
+ // Both arrays — strip ELEMENT-WISE, not whole-array: install enriches some lists
107
+ // after rendering the template (apex-domain `WebFetch` entries in
108
+ // `.claude/settings.json` `permissions.allow`).
109
+ const tSerialised = new Set(tVal.map((el) => JSON.stringify(el)));
110
+ const kept = cVal.filter((el) => !tSerialised.has(JSON.stringify(el)));
111
+ if (kept.length === 0) {
112
+ delete consumer[key];
113
+ }
114
+ else {
115
+ consumer[key] = kept;
116
+ }
117
+ }
118
+ else {
119
+ // Leaf (primitive, null) — remove if deep-equal to template
120
+ if (JSON.stringify(cVal) === JSON.stringify(tVal)) {
121
+ delete consumer[key];
122
+ }
123
+ // else: consumer has a different value — preserve it
124
+ }
125
+ }
126
+ }
127
+ // `.mcp.json` / `.cursor/mcp.json`: bkit owns only its tracker entry under `mcpServers`
128
+ // (reconcileMcpJson), so uninstall removes exactly that, never a leaf-by-leaf strip.
129
+ const MCP_JSON_RELPATHS = new Set([".mcp.json", path.join(".cursor", "mcp.json")]);
130
+ /**
131
+ * Remove each `mcpServers` entry that is identical to a tracker entry in the template — the
132
+ * entry bkit wrote. A consumer's own servers, and a bkit entry the consumer edited, stay. Drops
133
+ * `mcpServers` once empty, so a file bkit wrote alone strips to `{}` (deleted by the caller).
134
+ * Pure function — no file I/O.
135
+ */
136
+ export function stripMcpTrackerEntries(consumer, template) {
137
+ const out = JSON.parse(JSON.stringify(consumer));
138
+ const servers = out.mcpServers;
139
+ const owned = template.mcpServers;
140
+ if (!isJsonObject(servers) || !isJsonObject(owned))
141
+ return out;
142
+ for (const [key, entry] of Object.entries(owned)) {
143
+ if (JSON.stringify(servers[key]) === JSON.stringify(entry))
144
+ delete servers[key];
145
+ }
146
+ if (Object.keys(servers).length === 0)
147
+ delete out.mcpServers;
148
+ return out;
149
+ }
150
+ function isJsonObject(v) {
151
+ return v !== null && typeof v === "object" && !Array.isArray(v);
152
+ }
153
+ // ---------------------------------------------------------------------------
154
+ // Decision table builder (for --dry-run output and UninstallResult)
155
+ // ---------------------------------------------------------------------------
156
+ /**
157
+ * Build a decision table for all files that would be affected by uninstall.
158
+ * Does NOT perform any writes.
159
+ */
160
+ // Core doctrine files installed by the templates pass (runCoreTemplates), NOT the manifest —
161
+ // so the manifest-driven table never sees them and a full uninstall would orphan bkit's own
162
+ // rules/docs. Each carries a bkit managed block (markered-text), so strip-block preserves any
163
+ // consumer content added below `bkit:end`, exactly like the root AGENTS.md. Removed only on a
164
+ // full/core uninstall (gated on core in moduleList below).
165
+ const CORE_TEMPLATE_DOCTRINE = [
166
+ { path: ".agents/context.md", format: "markered-text", module: "core" },
167
+ { path: ".agents/docs.md", format: "markered-text", module: "core" },
168
+ { path: ".agents/rules.md", format: "markered-text", module: "core" },
169
+ { path: ".agents/skills.md", format: "markered-text", module: "core" },
170
+ ];
171
+ /**
172
+ * The top-level `docs/*.md` the core payload pass installs: each carries bkit's managed
173
+ * block (`bkit:start` / `bkit:end`, managed marker inside), so uninstall strips the block
174
+ * and keeps the consumer's content, exactly like `.agents/*.md`. The payload's
175
+ * `shared/docs/` holds only these block docs; `docs/capabilities.md` is a template
176
+ * (copied, never installed) and is left alone.
177
+ */
178
+ function coreDocEntries() {
179
+ const dir = path.join(getSharedRoot(), "docs");
180
+ if (!fs.existsSync(dir))
181
+ return [];
182
+ return fs
183
+ .readdirSync(dir, { withFileTypes: true })
184
+ .filter((e) => e.isFile() && e.name.endsWith(".md"))
185
+ .map((e) => ({
186
+ path: path.join("docs", e.name),
187
+ format: "markered-text",
188
+ module: "core",
189
+ }));
190
+ }
191
+ /** Prefix of the bkit-owned files under `docs/templates/`; uninstall deletes them whole. */
192
+ const DOCS_TEMPLATES_DIR = path.join("docs", "templates");
193
+ const isOwnedDocsTemplate = (name) => name.startsWith("bkit-") && name.endsWith(".md");
194
+ export function buildDecisionTable(modules, ctx) {
195
+ const moduleList = modules instanceof Set
196
+ ? [...modules].filter((m) =>
197
+ // Includes the opt-in add-ons (cloud) a Set caller passes.
198
+ ["core", "claude", "cursor", "opencode", "codex", "cloud"].includes(m))
199
+ : modules;
200
+ const entries = [
201
+ ...getInstallManifest(moduleList),
202
+ ...(moduleList.includes("core") ? [...CORE_TEMPLATE_DOCTRINE, ...coreDocEntries()] : []),
203
+ ];
204
+ // The hash of every owned file as bkit last wrote it.
205
+ const versionFilePath = path.join(ctx.cwd, ".bkit", "version");
206
+ const canonicalHashes = readBkitVersion(versionFilePath)?.canonicalHashes ?? {};
207
+ const table = [];
208
+ const seen = new Set();
209
+ for (const entry of entries) {
210
+ const absPath = path.join(ctx.cwd, entry.path);
211
+ const key = entry.path;
212
+ if (seen.has(key))
213
+ continue; // deduplicate (a path listed by more than one module)
214
+ seen.add(key);
215
+ if (!fs.existsSync(absPath)) {
216
+ table.push({
217
+ file: entry.path,
218
+ decision: "skip-absent",
219
+ reason: "file not found — nothing to do",
220
+ format: entry.format,
221
+ });
222
+ continue;
223
+ }
224
+ if (ctx.nuke) {
225
+ // Nuke: delete everything regardless of format
226
+ table.push({
227
+ file: entry.path,
228
+ decision: "delete",
229
+ reason: "--nuke: forcibly remove",
230
+ format: entry.format,
231
+ });
232
+ continue;
233
+ }
234
+ // Single dispatch on entry.format
235
+ switch (entry.format) {
236
+ case "json": {
237
+ // JSON deep-containment: strip bkit-owned scope from consumer doc
238
+ // For uninstall, treat as strip-block (handled in runUninstall via stripTier2JsonScope)
239
+ table.push({
240
+ file: entry.path,
241
+ decision: "strip-block",
242
+ reason: "json (deep-containment) — strip bkit-owned scope, preserve consumer keys",
243
+ format: "json",
244
+ });
245
+ break;
246
+ }
247
+ case "markered-text": {
248
+ const content = fs.readFileSync(absPath, "utf-8");
249
+ const style = detectMarkerStyle(content);
250
+ if (!style) {
251
+ table.push({
252
+ file: entry.path,
253
+ decision: "preserve",
254
+ reason: "markered-text but no bkit markers found — 100% consumer content",
255
+ format: "markered-text",
256
+ });
257
+ }
258
+ else {
259
+ table.push({
260
+ file: entry.path,
261
+ decision: "strip-block",
262
+ reason: "markered-text — strip bkit block, preserve consumer content",
263
+ format: "markered-text",
264
+ });
265
+ }
266
+ break;
267
+ }
268
+ case "byte-equal-text": {
269
+ // .bkit/version is bkit's own install-state manifest (pinnedVersion + hashes), never
270
+ // consumer content. It records no hash for itself, so the generic hash-guard preserves it
271
+ // as "consumer-modified" — leaving bkit state behind after a full teardown. It is
272
+ // `module: core`, so it only reaches this table on a full/core uninstall; delete it there
273
+ // (zero-footprint). A targeted (non-core) uninstall never sees it, so the modules that
274
+ // remain keep working. The hashes are read into memory before the delete loop, so
275
+ // removing this file mid-loop cannot affect any other file's decision.
276
+ if (entry.path === ".bkit/version") {
277
+ table.push({
278
+ file: entry.path,
279
+ decision: "delete",
280
+ reason: "bkit install-state manifest — removed on full/core uninstall",
281
+ format: "byte-equal-text",
282
+ });
283
+ break;
284
+ }
285
+ if (ctx.force) {
286
+ table.push({
287
+ file: entry.path,
288
+ decision: "delete",
289
+ reason: "--force: delete byte-equal-text regardless of hash",
290
+ format: "byte-equal-text",
291
+ });
292
+ break;
293
+ }
294
+ if (canonicalHashes[entry.path] === undefined) {
295
+ table.push({
296
+ file: entry.path,
297
+ decision: "skip-unknown",
298
+ reason: "byte-equal-text: no recorded install-time hash — preserve (consumer may have modified it)",
299
+ format: "byte-equal-text",
300
+ });
301
+ }
302
+ else if (!isConsumerModified(entry.path, absPath, canonicalHashes)) {
303
+ table.push({
304
+ file: entry.path,
305
+ decision: "delete",
306
+ reason: "byte-equal-text: content matches install-time hash — safe to delete",
307
+ format: "byte-equal-text",
308
+ });
309
+ }
310
+ else {
311
+ table.push({
312
+ file: entry.path,
313
+ decision: "skip-modified",
314
+ reason: "byte-equal-text: content differs from install-time hash — consumer modified, preserve",
315
+ format: "byte-equal-text",
316
+ });
317
+ }
318
+ break;
319
+ }
320
+ }
321
+ }
322
+ // `docs/templates/bkit-*.md` are bkit-owned whole (the audit templates and the plan
323
+ // template); the consumer's own files in that folder stay. Full/core uninstall only.
324
+ const templatesDir = path.join(ctx.cwd, DOCS_TEMPLATES_DIR);
325
+ if (moduleList.includes("core") && fs.existsSync(templatesDir)) {
326
+ for (const name of fs.readdirSync(templatesDir).sort()) {
327
+ const rel = path.join(DOCS_TEMPLATES_DIR, name);
328
+ if (!isOwnedDocsTemplate(name) || seen.has(rel))
329
+ continue;
330
+ if (!fs.statSync(path.join(ctx.cwd, rel)).isFile())
331
+ continue;
332
+ seen.add(rel);
333
+ table.push({
334
+ file: rel,
335
+ decision: "delete",
336
+ reason: "bkit-owned docs template — removed on full/core uninstall",
337
+ format: "markered-text",
338
+ });
339
+ }
340
+ }
341
+ return table;
342
+ }
343
+ // ---------------------------------------------------------------------------
344
+ // Format dry-run decision table
345
+ // ---------------------------------------------------------------------------
346
+ /**
347
+ * Format a decision table as a human-readable string.
348
+ * Format: FILE | DECISION | REASON
349
+ */
350
+ export function formatDecisionTable(table) {
351
+ if (table.length === 0)
352
+ return "[bkit-uninstall] No files to process.\n";
353
+ const COL_FILE = 48;
354
+ const COL_DEC = 22;
355
+ const header = `${"FILE".padEnd(COL_FILE)} | ${"DECISION".padEnd(COL_DEC)} | REASON\n` +
356
+ `${"-".repeat(COL_FILE)}-+-${"-".repeat(COL_DEC)}-+-${"-".repeat(40)}\n`;
357
+ const rows = table
358
+ .map((r) => `${r.file.padEnd(COL_FILE)} | ${r.decision.padEnd(COL_DEC)} | ${r.reason}`)
359
+ .join("\n");
360
+ return header + rows + "\n";
361
+ }
362
+ // ---------------------------------------------------------------------------
363
+ // Prompt helper (--nuke confirmation)
364
+ // ---------------------------------------------------------------------------
365
+ async function confirmNuke() {
366
+ return new Promise((resolve) => {
367
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
368
+ rl.question("[bkit-uninstall] --nuke will delete ALL bkit-managed files. Type 'yes' to confirm: ", (answer) => {
369
+ rl.close();
370
+ resolve(answer.trim().toLowerCase() === "yes");
371
+ });
372
+ });
373
+ }
374
+ // ---------------------------------------------------------------------------
375
+ // runUninstall — main orchestrator
376
+ // ---------------------------------------------------------------------------
377
+ /**
378
+ * Perform the uninstall operation for the given modules.
379
+ * Returns an UninstallResult describing what was done.
380
+ */
381
+ export async function runUninstall(modules, ctx) {
382
+ const result = {
383
+ deleted: [],
384
+ stripped: [],
385
+ preserved: [],
386
+ decisions: [],
387
+ dryRun: ctx.dryRun,
388
+ };
389
+ const moduleList = modules instanceof Set
390
+ ? [...modules].filter((m) =>
391
+ // Includes the opt-in add-ons (cloud) a Set caller passes.
392
+ ["core", "claude", "cursor", "opencode", "codex", "cloud"].includes(m))
393
+ : modules;
394
+ // Nuke confirmation
395
+ if (ctx.nuke && !ctx.yes && !ctx.dryRun) {
396
+ const confirmed = await confirmNuke();
397
+ if (!confirmed) {
398
+ console.log(`${ctx.logPrefix} --nuke cancelled.`);
399
+ return result;
400
+ }
401
+ }
402
+ const table = buildDecisionTable(moduleList, ctx);
403
+ result.decisions = table;
404
+ if (ctx.dryRun) {
405
+ console.log(`${ctx.logPrefix} [dry-run] Decision table:`);
406
+ console.log(formatDecisionTable(table));
407
+ }
408
+ const seen = new Set();
409
+ for (const summary of table) {
410
+ if (seen.has(summary.file))
411
+ continue;
412
+ seen.add(summary.file);
413
+ const absPath = path.join(ctx.cwd, summary.file);
414
+ switch (summary.decision) {
415
+ case "skip-absent":
416
+ case "skip-modified":
417
+ case "skip-unknown":
418
+ case "preserve": {
419
+ result.preserved.push(summary.file);
420
+ if (!ctx.dryRun) {
421
+ console.log(`${ctx.logPrefix} preserve: ${summary.file} (${summary.reason})`);
422
+ }
423
+ break;
424
+ }
425
+ case "delete": {
426
+ result.deleted.push(summary.file);
427
+ if (!ctx.dryRun) {
428
+ try {
429
+ fs.rmSync(absPath, { force: true });
430
+ console.log(`${ctx.logPrefix} delete: ${summary.file}`);
431
+ }
432
+ catch (err) {
433
+ console.error(`${ctx.logPrefix} error deleting ${summary.file}: ${err.message}`);
434
+ }
435
+ }
436
+ break;
437
+ }
438
+ case "strip-block": {
439
+ if (!ctx.dryRun) {
440
+ try {
441
+ if (summary.format === "json") {
442
+ // JSON deep-containment: strip bkit-owned scope, preserve consumer keys
443
+ const templatePath = findTemplateSource(summary.file);
444
+ if (templatePath === null || !fs.existsSync(templatePath)) {
445
+ // No payload source — preserve as-is
446
+ console.warn(`${ctx.logPrefix} no template found for ${summary.file} — preserving`);
447
+ result.preserved.push(summary.file);
448
+ break;
449
+ }
450
+ const raw = fs.readFileSync(absPath, "utf-8");
451
+ const consumerDoc = JSON.parse(raw);
452
+ let templateRaw = fs.readFileSync(templatePath, "utf-8");
453
+ // opencode.json ships `@@OPENCODE_*@@` sentinel KEYS that render to the consumer's
454
+ // tracker / provider at install; strip-scope keyed on the RAW template never matches
455
+ // the rendered keys, so bkit's mcp + provider blocks (a token-referencing config)
456
+ // survive a full uninstall. Render the template with the consumer's OWN tracker +
457
+ // provider first so the keys line up and the bkit-owned scope strips cleanly.
458
+ if (templateRaw.includes("@@OPENCODE_TRACKER_MCP@@")) {
459
+ templateRaw = renderOpencodeJson(templatePath, detectOpencodeTracker(consumerDoc), detectOpencodeProvider(consumerDoc));
460
+ }
461
+ const templateDoc = JSON.parse(templateRaw);
462
+ // `.claude/settings.json` is not written verbatim: after rendering the
463
+ // template, install appends one `WebFetch(domain:<d>)` grant per entry in
464
+ // the resolved network allowlist and `mcp__…` grants per declared MCP
465
+ // server (enrichClaudeSettingsAllows). Stripping
466
+ // against the RAW template leaves those grants behind as if the consumer
467
+ // had added them. Recompute the same set — the very function that produced
468
+ // them — and treat it as part of the template, exactly as the opencode.json
469
+ // sentinel render above does.
470
+ if (summary.file === path.join(".claude", "settings.json")) {
471
+ const perms = templateDoc.permissions;
472
+ if (perms !== null && typeof perms === "object" && !Array.isArray(perms)) {
473
+ const permsObj = perms;
474
+ const allow = permsObj.allow;
475
+ if (Array.isArray(allow)) {
476
+ const enriched = resolveClaudeDerivedAllows(ctx.cwd);
477
+ permsObj.allow = [
478
+ ...allow,
479
+ ...enriched.filter((e) => !allow.includes(e)),
480
+ ];
481
+ }
482
+ }
483
+ }
484
+ const stripped = MCP_JSON_RELPATHS.has(summary.file)
485
+ ? stripMcpTrackerEntries(consumerDoc, templateDoc)
486
+ : stripTier2JsonScope(consumerDoc, templateDoc);
487
+ const strippedJson = JSON.stringify(stripped, null, 2) + "\n";
488
+ if (Object.keys(stripped).length === 0) {
489
+ // All keys were bkit-owned → delete file
490
+ fs.rmSync(absPath, { force: true });
491
+ result.deleted.push(summary.file);
492
+ console.log(`${ctx.logPrefix} delete (empty after JSON scope strip): ${summary.file}`);
493
+ }
494
+ else {
495
+ fs.writeFileSync(absPath, strippedJson, "utf-8");
496
+ result.stripped.push(summary.file);
497
+ console.log(`${ctx.logPrefix} strip-json-scope: ${summary.file}`);
498
+ }
499
+ }
500
+ else {
501
+ // markered-text: strip bkit marker block, preserve consumer content
502
+ const content = fs.readFileSync(absPath, "utf-8");
503
+ const style = detectMarkerStyle(content) ?? "html-comment";
504
+ const stripped = stripManagedBlock(content, style);
505
+ // A bkit-seeded markdown file (AGENTS.md, CLAUDE.md) keeps its `# Title` H1
506
+ // OUTSIDE the bkit block. A markdown file reduced to a lone ATX heading (its only
507
+ // non-blank line) is a husk and is deleted. Scoped to .md/.mdc (shell/gitignore
508
+ // residue such as a lone `# comment` is unaffected); a multi-line residual (e.g.
509
+ // prompts.md's consumer `## Model Overrides`) is preserved.
510
+ const nonBlank = stripped.split("\n").filter((l) => l.trim().length > 0);
511
+ const isMarkdown = /\.mdc?$/.test(summary.file);
512
+ const isLoneHeadingHusk = isMarkdown && nonBlank.length === 1 && /^#{1,6}\s+\S/.test(nonBlank[0].trim());
513
+ // A file whose post-strip residual equals the bkit-seeded scaffold OUTSIDE the block
514
+ // (i.e. the template stripped the same way) carries NO genuine consumer content — it is
515
+ // 100% bkit-authored (hook shells left with only a shebang/header, a `.mdc` frontmatter
516
+ // shell, a pristine prompts.md) and is deleted. A consumer who added content outside
517
+ // the block strips UNEQUAL → preserved. Read is covered by the enclosing try/catch.
518
+ const normResidual = (s) => s
519
+ .split("\n")
520
+ .map((l) => l.replace(/[ \t]+$/, ""))
521
+ .join("\n")
522
+ .trim();
523
+ let isBkitOnlyScaffold = false;
524
+ const markeredTemplatePath = findTemplateSource(summary.file);
525
+ if (markeredTemplatePath !== null && fs.existsSync(markeredTemplatePath)) {
526
+ const templateContent = readTemplate(markeredTemplatePath);
527
+ const templateStripped = stripManagedBlock(templateContent, detectMarkerStyle(templateContent) ?? style);
528
+ isBkitOnlyScaffold = normResidual(stripped) === normResidual(templateStripped);
529
+ }
530
+ if (stripped.trim().length === 0 || isLoneHeadingHusk || isBkitOnlyScaffold) {
531
+ // File is now empty (or a bkit-seeded heading husk) → delete it
532
+ fs.rmSync(absPath, { force: true });
533
+ result.deleted.push(summary.file);
534
+ console.log(`${ctx.logPrefix} delete (empty after strip): ${summary.file}`);
535
+ }
536
+ else {
537
+ fs.writeFileSync(absPath, stripped, "utf-8");
538
+ result.stripped.push(summary.file);
539
+ console.log(`${ctx.logPrefix} strip-block: ${summary.file}`);
540
+ }
541
+ }
542
+ }
543
+ catch (err) {
544
+ console.error(`${ctx.logPrefix} error stripping block from ${summary.file}: ${err.message}`);
545
+ }
546
+ }
547
+ else {
548
+ result.stripped.push(summary.file);
549
+ }
550
+ break;
551
+ }
552
+ }
553
+ }
554
+ // Full/core uninstall: strip the `bkit` install-state object from package.json
555
+ // (issueTracker / opencodeProvider(s) / cloudAgents), whatever keys it holds. Scripts
556
+ // and devDeps are the consumer's and stay. No try/catch — malformed package.json is a hard failure on full
557
+ // teardown (same as a missing dest would be).
558
+ if (moduleList.includes("core") && !ctx.dryRun) {
559
+ const pkgPath = path.join(ctx.cwd, "package.json");
560
+ if (fs.existsSync(pkgPath)) {
561
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
562
+ if (pkg.bkit !== undefined) {
563
+ delete pkg.bkit;
564
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
565
+ console.log(`${ctx.logPrefix} package.json: removed bkit install-state block`);
566
+ result.stripped.push("package.json#bkit");
567
+ }
568
+ }
569
+ }
570
+ // Clean up .agents/ bkit-prefix mirror files
571
+ // (.claude/commands/bkit-*.md, .claude/agents/bkit-*.md, .opencode/agents/bkit-*.md, etc.)
572
+ if (!ctx.dryRun) {
573
+ const mirrorDirs = [
574
+ // Each host's mirror dirs are gated on its own module so a targeted
575
+ // uninstall (e.g. --claude / --auto) leaves other hosts
576
+ // untouched — symmetric with install. A bare/full uninstall populates
577
+ // moduleList with every host, so all mirrors are still swept then.
578
+ ...(moduleList.includes("claude") ? [".claude/commands", ".claude/agents"] : []),
579
+ ...(moduleList.includes("cursor") ? [".cursor/commands", ".cursor/agents"] : []),
580
+ // opencode mirrors (plural dir names per opencode.ai/docs)
581
+ ...(moduleList.includes("opencode") ? [".opencode/agents", ".opencode/commands"] : []),
582
+ // codex agent mirrors. The workflow skills under `.agents/skills/bkit-*` are swept
583
+ // separately below: `.agents/skills/` is SHARED with third-party skills installed via
584
+ // skills.sh, so the directory itself must never be removed wholesale.
585
+ ...(moduleList.includes("codex") ? [".codex/agents"] : []),
586
+ ];
587
+ for (const dir of mirrorDirs) {
588
+ const absDir = path.join(ctx.cwd, dir);
589
+ if (!fs.existsSync(absDir))
590
+ continue;
591
+ try {
592
+ for (const f of fs.readdirSync(absDir)) {
593
+ // .toml as well as .md: codex agent mirrors are TOML.
594
+ if (!f.startsWith("bkit-") || !(f.endsWith(".md") || f.endsWith(".toml")))
595
+ continue;
596
+ const absFile = path.join(absDir, f);
597
+ fs.rmSync(absFile, { force: true });
598
+ result.deleted.push(path.join(dir, f));
599
+ console.log(`${ctx.logPrefix} delete mirror: ${path.join(dir, f)}`);
600
+ }
601
+ }
602
+ catch (err) {
603
+ console.error(`${ctx.logPrefix} error cleaning up ${dir}: ${err.message}`);
604
+ }
605
+ }
606
+ // Workflow skills: `.agents/skills/` is SHARED with third-party skills installed via
607
+ // skills.sh, so only the bkit-prefixed DIRECTORIES are removed — never the parent.
608
+ if (moduleList.includes("codex")) {
609
+ const skillsDir = path.join(ctx.cwd, ".agents", "skills");
610
+ if (fs.existsSync(skillsDir)) {
611
+ try {
612
+ for (const d of fs.readdirSync(skillsDir)) {
613
+ if (!d.startsWith("bkit-"))
614
+ continue;
615
+ const abs = path.join(skillsDir, d);
616
+ if (!fs.statSync(abs).isDirectory())
617
+ continue;
618
+ fs.rmSync(abs, { recursive: true, force: true });
619
+ result.deleted.push(path.join(".agents/skills", d));
620
+ console.log(`${ctx.logPrefix} delete mirror: ${path.join(".agents/skills", d)}`);
621
+ }
622
+ }
623
+ catch (err) {
624
+ const msg = err.message;
625
+ console.error(`${ctx.logPrefix} error cleaning up .agents/skills: ${msg}`);
626
+ }
627
+ }
628
+ }
629
+ }
630
+ // Remove the generated `.claude/bkit-cloud.md` (untracked, gitignored — holds resolved
631
+ // secrets). It is not in the manifest, so the table-driven pass never sees it;
632
+ // delete it explicitly when the claude host is uninstalled so a live-secrets file
633
+ // is never left behind. Pushed to result.deleted so a dry-run reports it too.
634
+ if (moduleList.includes("claude")) {
635
+ const cloudAbs = path.join(ctx.cwd, CLAUDE_CLOUD_RELPATH);
636
+ if (fs.existsSync(cloudAbs)) {
637
+ result.deleted.push(CLAUDE_CLOUD_RELPATH);
638
+ if (!ctx.dryRun) {
639
+ fs.rmSync(cloudAbs, { force: true });
640
+ console.log(`${ctx.logPrefix} delete: ${CLAUDE_CLOUD_RELPATH} (generated cloud setup doc)`);
641
+ }
642
+ }
643
+ }
644
+ // Same for the Cursor twin `.cursor/bkit-cloud.md` (writeCursorCloudDoc) — untracked,
645
+ // gitignored, holds resolved secrets; delete it explicitly when the cursor host is
646
+ // uninstalled so a live-secrets file is never left behind.
647
+ if (moduleList.includes("cursor")) {
648
+ const cloudAbs = path.join(ctx.cwd, CURSOR_CLOUD_RELPATH);
649
+ if (fs.existsSync(cloudAbs)) {
650
+ result.deleted.push(CURSOR_CLOUD_RELPATH);
651
+ if (!ctx.dryRun) {
652
+ fs.rmSync(cloudAbs, { force: true });
653
+ console.log(`${ctx.logPrefix} delete: ${CURSOR_CLOUD_RELPATH} (generated cloud setup doc)`);
654
+ }
655
+ }
656
+ }
657
+ // Full/core uninstall: the consumer's template copies (`.bkit/templates/`) are
658
+ // bkit's folder, refreshed whole on every install and upgrade, so they go whole.
659
+ // Never in dogfood, where that folder is bkit's own template source. Adopted copies
660
+ // elsewhere in the repo stay.
661
+ if (moduleList.includes("core")) {
662
+ const templatesDir = path.join(ctx.cwd, TEMPLATE_COPIES_DIR);
663
+ if (path.resolve(ctx.cwd) !== getPkgRoot() && fs.existsSync(templatesDir)) {
664
+ result.deleted.push(TEMPLATE_COPIES_DIR);
665
+ if (!ctx.dryRun) {
666
+ fs.rmSync(templatesDir, { recursive: true, force: true });
667
+ console.log(`${ctx.logPrefix} delete: ${TEMPLATE_COPIES_DIR}/`);
668
+ }
669
+ }
670
+ }
671
+ // Full/core uninstall: the payload view links (`.bkit/core`, `.bkit/shared`) are
672
+ // bkit-created symlinks into the package and go with it. Symlinks ONLY — a real
673
+ // directory or file at that path is consumer content (install's no-clobber guard)
674
+ // and stays. Never in dogfood, where `.bkit/core` is bkit's own source.
675
+ if (moduleList.includes("core") && path.resolve(ctx.cwd) !== getPkgRoot()) {
676
+ for (const { relPath } of PAYLOAD_LINKS) {
677
+ const linkAbs = path.join(ctx.cwd, relPath);
678
+ let st = null;
679
+ try {
680
+ st = fs.lstatSync(linkAbs);
681
+ }
682
+ catch {
683
+ st = null; // absent
684
+ }
685
+ if (st?.isSymbolicLink() !== true)
686
+ continue;
687
+ result.deleted.push(relPath);
688
+ if (!ctx.dryRun) {
689
+ fs.rmSync(linkAbs, { force: true });
690
+ console.log(`${ctx.logPrefix} delete: ${relPath} (payload view link)`);
691
+ }
692
+ }
693
+ }
694
+ // Prune bkit-authored dirs left empty by the deletions above (e.g. .claude/agents,
695
+ // .claude/hooks). Candidates are the parent
696
+ // dirs of everything deleted, plus their ancestors; each is removed ONLY when it is actually
697
+ // empty (never touches a dir still holding consumer files), deepest-first so the removal
698
+ // cascades up. Skipped in dry-run — nothing was deleted, so nothing is empty to report.
699
+ if (!ctx.dryRun) {
700
+ const dirCandidates = new Set();
701
+ for (const rel of result.deleted) {
702
+ let dir = path.dirname(rel);
703
+ while (dir && dir !== "." && dir !== path.sep) {
704
+ dirCandidates.add(dir);
705
+ dir = path.dirname(dir);
706
+ }
707
+ }
708
+ const byDepthDesc = [...dirCandidates].sort((a, b) => b.split(path.sep).length - a.split(path.sep).length);
709
+ for (const rel of byDepthDesc) {
710
+ const absDir = path.join(ctx.cwd, rel);
711
+ // rmdirSync removes ONLY an empty dir (throws on non-empty) — the emptiness check
712
+ // above makes it a no-op on any dir still holding consumer files. Single-threaded, so
713
+ // the check and the remove cannot race.
714
+ if (fs.existsSync(absDir) && fs.readdirSync(absDir).length === 0) {
715
+ fs.rmdirSync(absDir);
716
+ console.log(`${ctx.logPrefix} prune empty dir: ${rel}`);
717
+ }
718
+ }
719
+ }
720
+ return result;
721
+ }
722
+ // ---------------------------------------------------------------------------
723
+ // runSurgicalOpencodeUninstall — remove exactly ONE provider block
724
+ // ---------------------------------------------------------------------------
725
+ /**
726
+ * Surgical removal of a single opencode provider installed by bkit.
727
+ *
728
+ * Distinct from bare `bkit uninstall --opencode` (full host teardown):
729
+ * - Removes the provider block from `.opencode/opencode.json`
730
+ * - Updates `bkit.opencodeProviders` in `package.json`
731
+ * - If the removed provider was the active one, re-points `bkit.opencodeProvider`
732
+ * to the first remaining provider and emits a re-render advisory
733
+ * - If no providers remain, falls through to full host teardown via `runUninstall`
734
+ */
735
+ export async function runSurgicalOpencodeUninstall(providerKey, dryRun, cwd) {
736
+ const LOG_PREFIX = "[bkit-uninstall]";
737
+ const tag = dryRun ? " (dry-run)" : "";
738
+ const jsonDst = path.join(cwd, ".opencode", "opencode.json");
739
+ const ws = { writes: [] };
740
+ // 1. Remove provider block from opencode.json
741
+ removeOpencodeProviderBlock(jsonDst, providerKey, dryRun, ws);
742
+ if (ws.writes.length > 0) {
743
+ console.log(`${LOG_PREFIX}${tag} removed provider block "${providerKey}" from opencode.json`);
744
+ }
745
+ // 2. Update bkit.opencodeProviders in package.json (read inline — no detectOpencodeProviders import)
746
+ const pkgPath = path.join(cwd, "package.json");
747
+ let remainingProviders = [];
748
+ let wasActive = false;
749
+ let newActive = null;
750
+ if (fs.existsSync(pkgPath)) {
751
+ const raw = fs.readFileSync(pkgPath, "utf-8");
752
+ // Parse-or-sentinel idiom: keep the early-return outside the catch body.
753
+ let pkg = null;
754
+ try {
755
+ pkg = JSON.parse(raw);
756
+ }
757
+ catch {
758
+ pkg = null;
759
+ }
760
+ if (pkg === null) {
761
+ console.warn(`${LOG_PREFIX} package.json is malformed — skipping bkit section update`);
762
+ return;
763
+ }
764
+ const bkit = (pkg.bkit ?? {});
765
+ const arr = Array.isArray(bkit.opencodeProviders)
766
+ ? [...bkit.opencodeProviders]
767
+ : [];
768
+ remainingProviders = arr.filter((p) => p !== providerKey);
769
+ wasActive = bkit.opencodeProvider === providerKey;
770
+ if (wasActive && remainingProviders.length > 0) {
771
+ newActive = remainingProviders[0];
772
+ }
773
+ if (!dryRun) {
774
+ bkit.opencodeProviders = remainingProviders;
775
+ if (wasActive) {
776
+ if (newActive !== null) {
777
+ bkit.opencodeProvider = newActive;
778
+ }
779
+ else {
780
+ delete bkit.opencodeProvider;
781
+ }
782
+ }
783
+ pkg.bkit = bkit;
784
+ const indentMatch = raw.match(/\n([ \t]+)"/);
785
+ const indent = indentMatch ? indentMatch[1] : " ";
786
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + "\n", "utf-8");
787
+ console.log(`${LOG_PREFIX} updated package.json: opencodeProviders=[${remainingProviders.join(", ")}]` +
788
+ (wasActive ? ` opencodeProvider=${newActive ?? "(removed)"}` : ""));
789
+ }
790
+ }
791
+ // 3. If none remain → full host teardown
792
+ if (remainingProviders.length === 0) {
793
+ console.log(`${LOG_PREFIX}${tag} no providers remain — triggering full opencode host teardown...`);
794
+ await runUninstall(["opencode"], {
795
+ cwd,
796
+ dryRun,
797
+ force: false,
798
+ nuke: false,
799
+ yes: false,
800
+ logPrefix: LOG_PREFIX,
801
+ });
802
+ return;
803
+ }
804
+ // 4. If was active → emit advisory (re-rendering agents requires full ModuleContext)
805
+ if (wasActive && newActive !== null) {
806
+ console.log(`${LOG_PREFIX}${tag} active provider switched to "${newActive}". ` +
807
+ `Run \`bkit install --opencode=${newActive}\` or \`bkit upgrade\` to re-render agent frontmatter.`);
808
+ }
809
+ }
810
+ export async function runUninstallCommand(modules, opencodeProvider, uninstallFlags) {
811
+ setLogPrefix("[bkit-uninstall]");
812
+ // Surgical single-provider removal: `uninstall --opencode=<provider>`
813
+ if (modules.has("opencode") && opencodeProvider !== null) {
814
+ const tag = uninstallFlags.dryRun ? " (dry-run)" : "";
815
+ console.log(`${LOG_PREFIX} Surgical opencode uninstall: removing provider "${opencodeProvider}"${tag}...`);
816
+ await runSurgicalOpencodeUninstall(opencodeProvider, uninstallFlags.dryRun, process.cwd());
817
+ return;
818
+ }
819
+ const uninstallCtx = {
820
+ cwd: process.cwd(),
821
+ dryRun: uninstallFlags.dryRun,
822
+ force: uninstallFlags.force,
823
+ nuke: uninstallFlags.nuke,
824
+ yes: uninstallFlags.yes,
825
+ logPrefix: LOG_PREFIX,
826
+ };
827
+ const moduleList = [...modules];
828
+ console.log(`${LOG_PREFIX} Running uninstall${uninstallCtx.dryRun ? " (dry-run)" : ""}...`);
829
+ const result = await runUninstall(moduleList, uninstallCtx);
830
+ const totalDeleted = result.deleted.length;
831
+ const totalStripped = result.stripped.length;
832
+ const totalPreserved = result.preserved.length;
833
+ if (uninstallCtx.dryRun) {
834
+ console.log(`${LOG_PREFIX} [dry-run] Would delete: ${totalDeleted}, strip: ${totalStripped}, preserve: ${totalPreserved}`);
835
+ }
836
+ else {
837
+ console.log(`${LOG_PREFIX} Done. Deleted: ${totalDeleted}, stripped: ${totalStripped}, preserved: ${totalPreserved}`);
838
+ }
839
+ }