@cbartens/bkit 0.0.0-stage → 5.0.0

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