@cbartens/bkit 5.2.4 → 5.4.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 (271) hide show
  1. package/.bkit/README.md +27 -11
  2. package/.bkit/core/.agents/context.md +1 -1
  3. package/.bkit/core/.agents/docs.md +1 -1
  4. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +1 -1
  5. package/.bkit/core/.agents/rules.md +18 -1
  6. package/.bkit/core/.bkit/README.md +26 -10
  7. package/.bkit/core/.bkit/cloud.md +40 -39
  8. package/.bkit/core/.bkit/comparison.md +68 -345
  9. package/.bkit/core/.bkit/install.md +16 -9
  10. package/.bkit/core/.bkit/lite.md +73 -0
  11. package/.bkit/core/.bkit/pipeline.md +346 -0
  12. package/.bkit/core/.bkit/prompts.md +90 -74
  13. package/.bkit/core/.bkit/providers.md +42 -23
  14. package/.bkit/core/.bkit/templates.md +138 -19
  15. package/.bkit/core/.bkit/trackers.md +49 -4
  16. package/.bkit/core/.bkit/workflows.md +144 -123
  17. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +1 -1
  18. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +7 -4
  19. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -5
  20. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +3 -2
  21. package/.bkit/core/docs/templates/bkit-audit-adoption.md +2 -2
  22. package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
  23. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
  24. package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
  25. package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
  26. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
  27. package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
  28. package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
  29. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +4 -2
  30. package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
  31. package/.bkit/core/docs/templates/bkit-audit-cost.md +3 -2
  32. package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
  33. package/.bkit/core/docs/templates/bkit-audit-database.md +3 -2
  34. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +5 -5
  35. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
  36. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +26 -21
  37. package/.bkit/core/docs/templates/bkit-audit-documentation.md +1 -1
  38. package/.bkit/core/docs/templates/bkit-audit-duplication.md +2 -2
  39. package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
  40. package/.bkit/core/docs/templates/bkit-audit-flakes.md +3 -2
  41. package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -2
  42. package/.bkit/core/docs/templates/bkit-audit-issues.md +3 -2
  43. package/.bkit/core/docs/templates/bkit-audit-llm.md +22 -15
  44. package/.bkit/core/docs/templates/bkit-audit-logs.md +10 -6
  45. package/.bkit/core/docs/templates/bkit-audit-models.md +1 -1
  46. package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
  47. package/.bkit/core/docs/templates/bkit-audit-prompts.md +7 -7
  48. package/.bkit/core/docs/templates/bkit-audit-red-team.md +12 -9
  49. package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
  50. package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
  51. package/.bkit/core/docs/templates/bkit-audit-security.md +14 -12
  52. package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
  53. package/.bkit/core/docs/templates/bkit-audit-testing.md +10 -8
  54. package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
  55. package/.bkit/core/docs/templates/bkit-plan.md +8 -6
  56. package/.bkit/core/engine/checks/after/auth.ts +9 -9
  57. package/.bkit/core/engine/checks/after/ci-yml.ts +14 -12
  58. package/.bkit/core/engine/checks/after/github.ts +29 -120
  59. package/.bkit/core/engine/checks/after/index.ts +2 -2
  60. package/.bkit/core/engine/checks/after/managed.ts +8 -28
  61. package/.bkit/core/engine/checks/after/tools.ts +3 -15
  62. package/.bkit/core/engine/checks/before/context-fetch.ts +1 -21
  63. package/.bkit/core/engine/checks/before/index.ts +7 -43
  64. package/.bkit/core/engine/checks/before/mcp.ts +17 -8
  65. package/.bkit/core/engine/checks/before/repo.ts +9 -12
  66. package/.bkit/core/engine/checks/status-holes.ts +4 -6
  67. package/.bkit/core/engine/checks/tips/catalogue.ts +76 -24
  68. package/.bkit/core/engine/checks/tips/detect.ts +45 -2
  69. package/.bkit/core/engine/checks/tips/index.ts +77 -26
  70. package/.bkit/core/engine/cli.ts +57 -27
  71. package/.bkit/core/engine/commands/analysis.ts +36 -26
  72. package/.bkit/core/engine/commands/comply.ts +42 -32
  73. package/.bkit/core/engine/commands/harvest.ts +12 -12
  74. package/.bkit/core/engine/commands/install/doctor.ts +57 -28
  75. package/.bkit/core/engine/commands/install/install.ts +73 -130
  76. package/.bkit/core/engine/commands/install/uninstall.ts +191 -33
  77. package/.bkit/core/engine/commands/install/upgrade.ts +49 -43
  78. package/.bkit/core/engine/commands/land.ts +156 -0
  79. package/.bkit/core/engine/commands/lib.ts +45 -18
  80. package/.bkit/core/engine/commands/registry.ts +2 -0
  81. package/.bkit/core/engine/commands/tips.ts +12 -5
  82. package/.bkit/core/engine/commands/workflow/branches.ts +386 -286
  83. package/.bkit/core/engine/commands/workflow/counters.ts +21 -12
  84. package/.bkit/core/engine/commands/workflow/disk.ts +556 -0
  85. package/.bkit/core/engine/commands/workflow/fids.ts +46 -0
  86. package/.bkit/core/engine/commands/workflow/issues.ts +73 -28
  87. package/.bkit/core/engine/commands/workflow/ledgers.ts +3 -1
  88. package/.bkit/core/engine/commands/workflow/locks.ts +38 -152
  89. package/.bkit/core/engine/commands/workflow/prs.ts +15 -4
  90. package/.bkit/core/engine/commands/workflow/repo.ts +2 -2
  91. package/.bkit/core/engine/commands/workflow/roadmap.ts +49 -53
  92. package/.bkit/core/engine/commands/workflow/runs.ts +8 -7
  93. package/.bkit/core/engine/commands/workflow/runtime.ts +3 -2
  94. package/.bkit/core/engine/commands/workflow/status.ts +33 -11
  95. package/.bkit/core/engine/commands/workflow/steps.ts +25 -15
  96. package/.bkit/core/engine/commands/workflow/tests.ts +17 -5
  97. package/.bkit/core/engine/commands/workflow/workflows.ts +436 -267
  98. package/.bkit/core/engine/commands/workflow/workstreams.ts +4 -2
  99. package/.bkit/core/engine/commands/workflow/worktrees.ts +24 -6
  100. package/.bkit/core/engine/install/cloud-env.ts +10 -31
  101. package/.bkit/core/engine/install/manifest.ts +14 -7
  102. package/.bkit/core/engine/install/modules/antigravity.ts +15 -26
  103. package/.bkit/core/engine/install/modules/claude.ts +20 -28
  104. package/.bkit/core/engine/install/modules/cloud.ts +5 -2
  105. package/.bkit/core/engine/install/modules/codex.ts +15 -29
  106. package/.bkit/core/engine/install/modules/core.ts +106 -70
  107. package/.bkit/core/engine/install/modules/cursor.ts +6 -20
  108. package/.bkit/core/engine/install/modules/index.ts +7 -1
  109. package/.bkit/core/engine/install/modules/opencode.ts +48 -70
  110. package/.bkit/core/engine/install/network-allowlist.ts +73 -0
  111. package/.bkit/core/engine/install/placeholders.ts +16 -35
  112. package/.bkit/core/engine/install/write.ts +59 -12
  113. package/.bkit/core/engine/ledgers/telemetry.ts +6 -4
  114. package/.bkit/core/engine/render/hosts.ts +47 -67
  115. package/.bkit/core/engine/render/models.ts +29 -11
  116. package/.bkit/core/engine/shared/branches.ts +13 -0
  117. package/.bkit/core/engine/shared/egress.ts +3 -3
  118. package/.bkit/core/engine/shared/json.ts +18 -1
  119. package/.bkit/core/engine/shared/package-json.ts +63 -0
  120. package/.bkit/core/engine/shared/package-roots.ts +0 -10
  121. package/.bkit/core/engine/shared/protected-paths.ts +5 -130
  122. package/.bkit/core/engine/shared/settings.ts +44 -0
  123. package/.bkit/core/engine/shared/timeouts.ts +8 -7
  124. package/.bkit/core/hooks/antigravity-hook.js +1 -0
  125. package/.bkit/core/hooks/guardrails-shell.js +186 -40
  126. package/.bkit/core/hooks/guardrails-tiers.js +5 -78
  127. package/.bkit/core/prompts/bkit-audit-generate.md +103 -7
  128. package/.bkit/core/prompts/bkit-build-challenge-1.md +1 -1
  129. package/.bkit/core/prompts/bkit-build-challenge-2.md +1 -1
  130. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +1 -1
  131. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +1 -1
  132. package/.bkit/core/prompts/bkit-build-challenge-tests.md +1 -1
  133. package/.bkit/core/prompts/bkit-build-install-skills.md +1 -1
  134. package/.bkit/core/prompts/bkit-build-plan-current.md +1 -1
  135. package/.bkit/core/prompts/bkit-build-plan-execute.md +4 -4
  136. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +1 -1
  137. package/.bkit/core/prompts/bkit-build-plan-verify.md +2 -2
  138. package/.bkit/core/prompts/bkit-debug-abort-handover.md +1 -1
  139. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +1 -1
  140. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +1 -1
  141. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +78 -0
  142. package/.bkit/core/prompts/bkit-debug-failure-soak.md +1 -1
  143. package/.bkit/core/prompts/bkit-debug-summary.md +3 -3
  144. package/.bkit/core/prompts/bkit-design-spike.md +1 -1
  145. package/.bkit/core/prompts/bkit-design-summary.md +2 -2
  146. package/.bkit/core/prompts/bkit-design-update.md +1 -1
  147. package/.bkit/core/prompts/bkit-plan-complexity-check.md +1 -1
  148. package/.bkit/core/prompts/bkit-plan-generate.md +1 -1
  149. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +1 -1
  150. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +1 -1
  151. package/.bkit/core/prompts/bkit-plan-summary.md +1 -1
  152. package/.bkit/core/prompts/bkit-plan-update.md +1 -1
  153. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +1 -1
  154. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +1 -1
  155. package/.bkit/core/prompts/bkit-ship-update-docs.md +1 -1
  156. package/.bkit/core/prompts/bkit-utility-update-decisions.md +9 -2
  157. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +9 -2
  158. package/.bkit/core/prompts/bkit-utility-update-documentation.md +2 -1
  159. package/.bkit/core/prompts/bkit-utility-update-failures.md +9 -2
  160. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +9 -2
  161. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +11 -4
  162. package/.bkit/core/workflows/bkit-auto.md +2 -2
  163. package/.bkit/core/workflows/bkit-build.md +10 -10
  164. package/.bkit/core/workflows/bkit-debug.md +80 -44
  165. package/.bkit/core/workflows/bkit-design.md +22 -13
  166. package/.bkit/core/workflows/bkit-plan.md +33 -16
  167. package/.bkit/core/workflows/bkit-ship.md +87 -98
  168. package/.bkit/shared/.claude/bkit-cloud.md +58 -25
  169. package/.bkit/shared/.claude/settings.json +19 -0
  170. package/.bkit/shared/.cursor/mcp.json +2 -1
  171. package/.bkit/shared/.opencode/opencode.json +19 -1
  172. package/.bkit/shared/docs/deployments.md +49 -29
  173. package/.bkit/shared/docs/security.md +8 -6
  174. package/.bkit/shared/docs/testing.md +9 -5
  175. package/.bkit/shared/gitignore +1 -2
  176. package/.bkit/templates/.cursor/Dockerfile +30 -16
  177. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +78 -0
  178. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +91 -0
  179. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +56 -0
  180. package/.bkit/templates/.github/renovate.json5 +91 -12
  181. package/.bkit/templates/.github/workflows/bkit-ci.yml +73 -55
  182. package/.bkit/templates/.github/workflows/bkit-cloud.yml +3 -1
  183. package/.bkit/templates/.github/workflows/bkit-renovate.yml +8 -1
  184. package/.bkit/templates/.github/workflows/bkit-trivy.yml +67 -0
  185. package/.bkit/templates/.husky/pre-commit +6 -0
  186. package/.bkit/templates/.husky/pre-push +15 -3
  187. package/.bkit/templates/.lintstagedrc.json +5 -1
  188. package/.bkit/templates/.oxlintrc.json +21 -0
  189. package/.bkit/templates/docs/capabilities.md +1 -1
  190. package/.bkit/templates/scripts/ci/check-capstone.mjs +176 -0
  191. package/.bkit/templates/scripts/ci/check-capstone.test.mjs +311 -0
  192. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.machine.mjs +197 -0
  193. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +164 -0
  194. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +2 -2
  195. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +43 -20
  196. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +33 -11
  197. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -2
  198. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +5 -5
  199. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +79 -19
  200. package/CHANGELOG.md +98 -3
  201. package/README.md +252 -122
  202. package/dist/checks/after/auth.js +10 -11
  203. package/dist/checks/after/ci-yml.js +11 -14
  204. package/dist/checks/after/github.js +32 -125
  205. package/dist/checks/after/index.js +3 -2
  206. package/dist/checks/after/managed.js +8 -24
  207. package/dist/checks/after/tools.js +3 -16
  208. package/dist/checks/before/context-fetch.js +1 -21
  209. package/dist/checks/before/index.js +6 -42
  210. package/dist/checks/before/mcp.js +14 -9
  211. package/dist/checks/before/repo.js +8 -11
  212. package/dist/checks/status-holes.js +5 -7
  213. package/dist/checks/tips/catalogue.js +65 -18
  214. package/dist/checks/tips/detect.js +41 -2
  215. package/dist/checks/tips/index.js +61 -25
  216. package/dist/cli.js +52 -26
  217. package/dist/commands/analysis.js +21 -5
  218. package/dist/commands/comply.js +40 -31
  219. package/dist/commands/harvest.js +12 -13
  220. package/dist/commands/install/doctor.js +55 -23
  221. package/dist/commands/install/install.js +72 -122
  222. package/dist/commands/install/uninstall.js +165 -31
  223. package/dist/commands/install/upgrade.js +46 -39
  224. package/dist/commands/land.js +129 -0
  225. package/dist/commands/lib.js +41 -16
  226. package/dist/commands/registry.js +2 -0
  227. package/dist/commands/tips.js +10 -3
  228. package/dist/commands/workflow/branches.js +303 -248
  229. package/dist/commands/workflow/counters.js +17 -7
  230. package/dist/commands/workflow/disk.js +452 -0
  231. package/dist/commands/workflow/fids.js +39 -0
  232. package/dist/commands/workflow/issues.js +63 -27
  233. package/dist/commands/workflow/ledgers.js +3 -1
  234. package/dist/commands/workflow/locks.js +35 -130
  235. package/dist/commands/workflow/prs.js +8 -5
  236. package/dist/commands/workflow/repo.js +2 -2
  237. package/dist/commands/workflow/roadmap.js +50 -57
  238. package/dist/commands/workflow/runs.js +5 -5
  239. package/dist/commands/workflow/runtime.js +3 -2
  240. package/dist/commands/workflow/status.js +32 -12
  241. package/dist/commands/workflow/steps.js +19 -11
  242. package/dist/commands/workflow/tests.js +16 -3
  243. package/dist/commands/workflow/workflows.js +390 -249
  244. package/dist/commands/workflow/workstreams.js +4 -2
  245. package/dist/commands/workflow/worktrees.js +15 -6
  246. package/dist/install/cloud-env.js +10 -23
  247. package/dist/install/manifest.js +14 -7
  248. package/dist/install/modules/antigravity.js +15 -26
  249. package/dist/install/modules/claude.js +17 -21
  250. package/dist/install/modules/cloud.js +6 -2
  251. package/dist/install/modules/codex.js +15 -29
  252. package/dist/install/modules/core.js +95 -63
  253. package/dist/install/modules/cursor.js +6 -9
  254. package/dist/install/modules/index.js +6 -1
  255. package/dist/install/modules/opencode.js +41 -72
  256. package/dist/install/network-allowlist.js +62 -0
  257. package/dist/install/placeholders.js +16 -35
  258. package/dist/install/write.js +55 -15
  259. package/dist/ledgers/telemetry.js +5 -4
  260. package/dist/render/hosts.js +30 -55
  261. package/dist/render/models.js +20 -9
  262. package/dist/shared/branches.js +11 -0
  263. package/dist/shared/egress.js +0 -2
  264. package/dist/shared/json.js +14 -0
  265. package/dist/shared/package-json.js +61 -0
  266. package/dist/shared/package-roots.js +0 -8
  267. package/dist/shared/protected-paths.js +5 -122
  268. package/dist/shared/settings.js +23 -1
  269. package/dist/shared/timeouts.js +8 -7
  270. package/package.json +21 -17
  271. package/.bkit/core/.agents/shortcuts.md +0 -73
@@ -3,9 +3,11 @@
3
3
  import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
5
  import { OPENCODE_PROVIDERS } from "../../shared/egress.js";
6
- import { getPkgRoot } from "../../shared/package-roots.js";
6
+ import { readInstallingVersion } from "../../shared/package-json.js";
7
7
  import { dispatchModules } from "../../install/modules/index.js";
8
- import { DEFAULT_ISSUE_TRACKER, parseIssueTracker, } from "../../install/manifest.js";
8
+ import { DEFAULT_ISSUE_TRACKER, } from "../../install/manifest.js";
9
+ import { parseJson, readJsonFile } from "../../shared/json.js";
10
+ import { readBkitConfig } from "../../shared/settings.js";
9
11
  import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
10
12
  import { detectInstalledModules, reportCheckDrift } from "./check.js";
11
13
  import { runPreflight } from "../../checks/before/index.js";
@@ -15,7 +17,7 @@ import { findMissingOwnedHooks, detectOwnedHookMissing } from "../../checks/afte
15
17
  import { resolveTokens } from "../../install/placeholders.js";
16
18
  import { parseModelLookup, applyModelOverrides, buildOpencodeModelLookup, buildAntigravityModelLookup, parseEffortMap, } from "../../render/models.js";
17
19
  import { getBkitDocsRoot } from "../../shared/package-roots.js";
18
- import { runUninstall } from "./uninstall.js";
20
+ import { removeUnusedTrackerMcpEntries, runUninstall } from "./uninstall.js";
19
21
  // ---------------------------------------------------------------------------
20
22
  // Staging scratch area
21
23
  //
@@ -57,24 +59,6 @@ export function requireOpencodeProvider(cwd, context) {
57
59
  }
58
60
  return detected;
59
61
  }
60
- /**
61
- * Read the installing bkit version from the package root's package.json.
62
- * Returns "0.0.0" when unreadable (e.g. dev tree without a package.json at the
63
- * resolved root) — keeps the advisories artifact informational, not fatal.
64
- */
65
- export function getInstallingVersion() {
66
- try {
67
- const pkgJsonPath = path.join(getPkgRoot(), "package.json");
68
- if (fs.existsSync(pkgJsonPath)) {
69
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
70
- return pkg.version ?? "0.0.0";
71
- }
72
- }
73
- catch {
74
- return "0.0.0"; // best-effort: unreadable/garbled package.json
75
- }
76
- return "0.0.0";
77
- }
78
62
  /**
79
63
  * Render a resolved module set back into valid CLI flags for
80
64
  * recovery-hint text. Skips core (implicit) and spells opt-ins with their value flags.
@@ -130,35 +114,23 @@ export function validateCloudTrackerMatch(cloudVariant, hasCloudModule, issueTra
130
114
  * smuggle an unsupported provider into the render path.
131
115
  */
132
116
  export function detectOpencodeProvider(cwd) {
133
- const pkgPath = path.join(cwd, "package.json");
134
- if (fs.existsSync(pkgPath)) {
135
- try {
136
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
137
- const stored = pkg.bkit?.opencodeProvider;
138
- if (typeof stored === "string" &&
139
- OPENCODE_PROVIDERS.includes(stored)) {
140
- return stored;
141
- }
142
- }
143
- catch {
144
- // unparseable package.json — fall through to opencode.json detection
145
- }
146
- }
117
+ const stored = readBkitConfig(cwd).opencodeProvider;
118
+ if (stored !== null)
119
+ return stored;
147
120
  const jsonPath = path.join(cwd, ".opencode", "opencode.json");
148
121
  if (!fs.existsSync(jsonPath))
149
122
  return null;
150
- try {
151
- const cfg = JSON.parse(fs.readFileSync(jsonPath, "utf-8"));
152
- if (cfg.provider && typeof cfg.provider === "object") {
153
- const first = Object.keys(cfg.provider)[0];
154
- if (!first)
155
- return null;
156
- // Zen's opencode.json block is keyed by the built-in id `opencode`, not the CLI key.
157
- return first === "opencode" ? "opencode-zen" : first;
158
- }
159
- }
160
- catch {
161
- return null; // unparseable opencode.json — fall back to the default provider
123
+ // Unparseable opencode.json — fall back to the default provider.
124
+ const read = readJsonFile(jsonPath);
125
+ if (!read.ok || typeof read.value !== "object" || read.value === null)
126
+ return null;
127
+ const cfg = read.value;
128
+ if (cfg.provider && typeof cfg.provider === "object") {
129
+ const first = Object.keys(cfg.provider)[0];
130
+ if (!first)
131
+ return null;
132
+ // Zen's opencode.json block is keyed by the built-in id `opencode`, not the CLI key.
133
+ return first === "opencode" ? "opencode-zen" : first;
162
134
  }
163
135
  return null;
164
136
  }
@@ -168,20 +140,7 @@ export function detectOpencodeProvider(cwd) {
168
140
  * the field is absent.
169
141
  */
170
142
  export function detectOpencodeProviders(cwd) {
171
- const pkgPath = path.join(cwd, "package.json");
172
- if (!fs.existsSync(pkgPath))
173
- return [];
174
- try {
175
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
176
- const arr = pkg.bkit?.opencodeProviders;
177
- if (Array.isArray(arr)) {
178
- return arr.filter((v) => typeof v === "string" && OPENCODE_PROVIDERS.includes(v));
179
- }
180
- }
181
- catch {
182
- // unparseable — return empty
183
- }
184
- return [];
143
+ return readBkitConfig(cwd).opencodeProviders;
185
144
  }
186
145
  /**
187
146
  * Re-run Phase 1 detection after the writes. The Phase 1 advisory seeds (the first
@@ -225,13 +184,19 @@ export async function runInstall(args, upgradeReport = false) {
225
184
  else if (dryRun)
226
185
  console.log(`${LOG_PREFIX} Running in check (dry-run) mode`);
227
186
  // `bkit check` scopes drift detection to what is INSTALLED (detected by sentinel files),
228
- // not to a fixed full set. `install` keeps its explicit resolved set.
229
- const effectiveModules = verb === "check" ? detectInstalledModules(process.cwd()) : modules;
187
+ // not to a fixed full set. `install` keeps its explicit resolved set, plus every installed
188
+ // host when `--tracker=` is given: each host renders tracker-specific commands, agents and
189
+ // MCP entries, so a host left out would keep the old tracker's.
190
+ const effectiveModules = verb === "check"
191
+ ? detectInstalledModules(process.cwd())
192
+ : tracker !== null
193
+ ? new Set([...modules, ...detectInstalledModules(process.cwd())])
194
+ : modules;
230
195
  // RENDER-input provider resolution. `bkit check` takes no `--opencode=` flag, so the parsed
231
196
  // `opencodeProvider` is null on the check path; it falls back to the INSTALLED provider
232
197
  // (package.json `bkit.opencodeProvider`, else the opencode.json provider block). On install
233
- // `?? detect` never fires: opencode joins the module set only when `--opencode=<provider>`
234
- // was given. The PARSED `opencodeProvider` alone drives the persist-to-package.json logic
198
+ // `?? detect` fires only when opencode joins as an installed host under `--tracker=`; with
199
+ // `--opencode=<provider>` the flag wins. The PARSED `opencodeProvider` alone drives the persist-to-package.json logic
235
200
  // below (gated on `!dryRun` + a real flag). The tracker is resolved from package.json below,
236
201
  // so the tracker-dependent opencode mcp block renders the same way on check.
237
202
  const renderOpencodeProvider = opencodeProvider ?? detectOpencodeProvider(process.cwd());
@@ -241,24 +206,8 @@ export async function runInstall(args, upgradeReport = false) {
241
206
  // already-recorded tracker.
242
207
  // Resolved BEFORE preflight: preflight's tracker-dependent detectors grade the tracker
243
208
  // this run INSTALLS, not the one on disk from the previous run. Read-only — no writes here.
244
- let issueTracker = DEFAULT_ISSUE_TRACKER;
245
- {
246
- const consumerPkgPath = path.join(process.cwd(), "package.json");
247
- if (fs.existsSync(consumerPkgPath)) {
248
- try {
249
- const pkg = JSON.parse(fs.readFileSync(consumerPkgPath, "utf-8"));
250
- const bkitField = pkg.bkit;
251
- const stored = parseIssueTracker(bkitField?.issueTracker);
252
- if (stored !== null)
253
- issueTracker = stored;
254
- }
255
- catch {
256
- // non-fatal — keep default
257
- }
258
- }
259
- if (tracker !== null)
260
- issueTracker = tracker;
261
- }
209
+ const recordedTracker = readBkitConfig(process.cwd()).issueTracker;
210
+ const issueTracker = tracker ?? recordedTracker;
262
211
  // --- Phase 1: Preflight (read-only, before any writes) ---
263
212
  // Must run BEFORE resolveTokens to short-circuit cleanly on blockers.
264
213
  const { blockers, advisories: preflightAdvisories } = runPreflight(effectiveModules, process.cwd(), undefined, issueTracker);
@@ -271,7 +220,7 @@ export async function runInstall(args, upgradeReport = false) {
271
220
  writeAdvisoriesArtifact(blockers, {
272
221
  cwd: process.cwd(),
273
222
  mode: "upgrade",
274
- version: getInstallingVersion(),
223
+ version: readInstallingVersion(),
275
224
  logPrefix: LOG_PREFIX,
276
225
  });
277
226
  return;
@@ -379,31 +328,35 @@ export async function runInstall(args, upgradeReport = false) {
379
328
  if (fs.existsSync(consumerPkgPath2)) {
380
329
  try {
381
330
  const raw = fs.readFileSync(consumerPkgPath2, "utf-8");
382
- const pkg = JSON.parse(raw);
383
- const bkit = (pkg.bkit ?? {});
384
- if (persistTracker)
385
- bkit.issueTracker = tracker;
386
- if (persistProvider) {
387
- bkit.opencodeProvider = opencodeProvider; // active (drives agent frontmatter)
388
- // Update providers array (deduped).
389
- const existingArr = Array.isArray(bkit.opencodeProviders)
390
- ? [...bkit.opencodeProviders]
391
- : [];
392
- if (!existingArr.includes(opencodeProvider)) {
393
- existingArr.push(opencodeProvider);
331
+ // A package.json that is not JSON is left as-is (the preflight blocker reports it).
332
+ const parsed = parseJson(raw);
333
+ if (parsed.ok) {
334
+ const pkg = parsed.value;
335
+ const bkit = (pkg.bkit ?? {});
336
+ if (persistTracker)
337
+ bkit.issueTracker = tracker;
338
+ if (persistProvider) {
339
+ bkit.opencodeProvider = opencodeProvider; // active (drives agent frontmatter)
340
+ // Update providers array (deduped).
341
+ const existingArr = Array.isArray(bkit.opencodeProviders)
342
+ ? [...bkit.opencodeProviders]
343
+ : [];
344
+ if (!existingArr.includes(opencodeProvider)) {
345
+ existingArr.push(opencodeProvider);
346
+ }
347
+ bkit.opencodeProviders = existingArr;
348
+ }
349
+ pkg.bkit = bkit;
350
+ const indentMatch = raw.match(/\n([ \t]+)"/);
351
+ const indent = indentMatch ? indentMatch[1] : " ";
352
+ const trailingNewline = raw.endsWith("\n") ? "\n" : "";
353
+ fs.writeFileSync(consumerPkgPath2, JSON.stringify(pkg, null, indent) + trailingNewline, "utf-8");
354
+ if (persistTracker) {
355
+ console.log(`${LOG_PREFIX} Set bkit.issueTracker = "${tracker}" in package.json`);
356
+ }
357
+ if (persistProvider) {
358
+ console.log(`${LOG_PREFIX} Set bkit.opencodeProvider = "${opencodeProvider}" and updated bkit.opencodeProviders in package.json`);
394
359
  }
395
- bkit.opencodeProviders = existingArr;
396
- }
397
- pkg.bkit = bkit;
398
- const indentMatch = raw.match(/\n([ \t]+)"/);
399
- const indent = indentMatch ? indentMatch[1] : " ";
400
- const trailingNewline = raw.endsWith("\n") ? "\n" : "";
401
- fs.writeFileSync(consumerPkgPath2, JSON.stringify(pkg, null, indent) + trailingNewline, "utf-8");
402
- if (persistTracker) {
403
- console.log(`${LOG_PREFIX} Set bkit.issueTracker = "${tracker}" in package.json`);
404
- }
405
- if (persistProvider) {
406
- console.log(`${LOG_PREFIX} Set bkit.opencodeProvider = "${opencodeProvider}" and updated bkit.opencodeProviders in package.json`);
407
360
  }
408
361
  }
409
362
  catch {
@@ -411,6 +364,12 @@ export async function runInstall(args, upgradeReport = false) {
411
364
  }
412
365
  }
413
366
  }
367
+ // Tracker switch: drop the bkit MCP entries the new tracker does not use, while each still
368
+ // equals bkit's template (an edited one stays, with a warning). Runs before dispatch so the
369
+ // `.bkit/version` hashes core records cover the final file content.
370
+ if (!dryRun && tracker !== null && tracker !== recordedTracker) {
371
+ removeUnusedTrackerMcpEntries(process.cwd(), tracker, dryRun, ws, LOG_PREFIX);
372
+ }
414
373
  const ctx = {
415
374
  dryRun,
416
375
  tokens,
@@ -427,7 +386,7 @@ export async function runInstall(args, upgradeReport = false) {
427
386
  issueTracker,
428
387
  cloudVariant,
429
388
  // Stamped into every rendered agent + command as the managed-version marker.
430
- version: getInstallingVersion(),
389
+ version: readInstallingVersion(),
431
390
  // Full host set for this run: dispatched ∪ already-on-disk. Read by the Antigravity
432
391
  // module to warn when Codex is also installed (both hosts' `bkit-*` workflow skills
433
392
  // then surface in Antigravity's skill selector).
@@ -477,18 +436,9 @@ export async function runInstall(args, upgradeReport = false) {
477
436
  // Runs for both install AND check — detectors are read-only, so check produces
478
437
  // the same advisory set as install would emit against the same filesystem state.
479
438
  // Changelog version-delta header (A7): surface what changed in the installed version.
480
- try {
481
- const pkgJsonPath = path.join(getPkgRoot(), "package.json");
482
- if (fs.existsSync(pkgJsonPath)) {
483
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
484
- const deltaHeader = readChangelogVersionDelta(pkg.version ?? "");
485
- if (deltaHeader)
486
- console.log(deltaHeader);
487
- }
488
- }
489
- catch (err) {
490
- void err; // Non-fatal — changelog header is informational
491
- }
439
+ const deltaHeader = readChangelogVersionDelta(readInstallingVersion());
440
+ if (deltaHeader)
441
+ console.log(deltaHeader);
492
442
  const suppressed = [];
493
443
  const postFindings = runPostInstallCheck(ctx.advisories, process.cwd(), suppressed);
494
444
  if (postWriteBlockers.length > 0) {
@@ -509,7 +459,7 @@ export async function runInstall(args, upgradeReport = false) {
509
459
  writeAdvisoriesArtifact(postFindings, {
510
460
  cwd: process.cwd(),
511
461
  mode: upgradeReport ? "upgrade" : dryRun ? "check" : "install",
512
- version: getInstallingVersion(),
462
+ version: readInstallingVersion(),
513
463
  logPrefix: LOG_PREFIX,
514
464
  suppressed,
515
465
  tips,
@@ -21,16 +21,22 @@
21
21
  import * as fs from "node:fs";
22
22
  import * as path from "node:path";
23
23
  import * as readline from "node:readline";
24
+ import { isJsonObject } from "../../install/write.js";
24
25
  import { stripManagedBlock, detectMarkerStyle } from "../../install/managed-block.js";
25
26
  import { readTemplate } from "../../render/parts.js";
26
27
  import { getInstallManifest, ISSUE_TRACKERS, } from "../../install/manifest.js";
27
28
  import { OPENCODE_PROVIDERS } from "../../shared/egress.js";
28
- import { isConsumerModified, mergeCanonicalHashes, readBkitVersion, writeBkitVersion, } from "../../install/version-file.js";
29
- import { getPkgRoot, getSharedRoot, findTemplateSource, TEMPLATE_COPIES_DIR, } from "../../shared/package-roots.js";
29
+ import { parseJson } from "../../shared/json.js";
30
+ import { hashFile, isConsumerModified, mergeCanonicalHashes, readBkitVersion, writeBkitVersion, } from "../../install/version-file.js";
31
+ import { getBkitDocsRoot, getPkgRoot, getSharedRoot, findTemplateSource, TEMPLATE_COPIES_DIR, } from "../../shared/package-roots.js";
30
32
  import { PAYLOAD_LINKS } from "../../install/payload-links.js";
31
- import { removeOpencodeProviderBlock, renderOpencodeJson } from "../../install/modules/opencode.js";
33
+ import { removeOpencodeProviderBlock, renderOpencodeAgentsCommands, renderOpencodeJson, } from "../../install/modules/opencode.js";
34
+ import { applyModelOverrides, buildOpencodeModelLookup, parseEffortMap, } from "../../render/models.js";
35
+ import { readInstallingVersion } from "../../shared/package-json.js";
36
+ import { readBkitConfig } from "../../shared/settings.js";
32
37
  import { CLAUDE_CLOUD_RELPATH, CURSOR_CLOUD_RELPATH, resolveClaudeDerivedAllows, } from "../../install/cloud-env.js";
33
38
  import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
39
+ import { unusedTrackerMcpServers } from "../../checks/before/mcp.js";
34
40
  // ---------------------------------------------------------------------------
35
41
  // stripTier2JsonScope — remove bkit-owned JSON scope from consumer doc (BAR-167 Phase 1)
36
42
  //
@@ -57,13 +63,8 @@ import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
57
63
  * leaf like any Tier-2 JSON file. Reads only the template.
58
64
  */
59
65
  export function stripOpencodeJsonScope(consumer, templatePath, cwd) {
60
- const render = (tracker, provider) => JSON.parse(renderOpencodeJson(templatePath, tracker, provider, cwd));
61
- const ownedMcp = {};
62
- for (const tracker of ISSUE_TRACKERS) {
63
- const { mcp } = render(tracker, OPENCODE_PROVIDERS[0]);
64
- if (isJsonObject(mcp))
65
- Object.assign(ownedMcp, mcp);
66
- }
66
+ const render = (tracker, provider) => renderOpencodeDoc(templatePath, tracker, provider, cwd);
67
+ const ownedMcp = ownedOpencodeMcpEntries(templatePath, cwd);
67
68
  const ownedProviders = {};
68
69
  for (const provider of OPENCODE_PROVIDERS) {
69
70
  const rendered = render("none", provider).provider;
@@ -78,6 +79,19 @@ export function stripOpencodeJsonScope(consumer, templatePath, cwd) {
78
79
  removeOwnedEntries(out, "provider", ownedProviders);
79
80
  return stripTier2JsonScope(out, rest);
80
81
  }
82
+ function renderOpencodeDoc(templatePath, tracker, provider, cwd) {
83
+ return JSON.parse(renderOpencodeJson(templatePath, tracker, provider, cwd));
84
+ }
85
+ /** Every tracker's `mcp` entry exactly as bkit renders it into `.opencode/opencode.json`. */
86
+ function ownedOpencodeMcpEntries(templatePath, cwd) {
87
+ const owned = {};
88
+ for (const tracker of ISSUE_TRACKERS) {
89
+ const { mcp } = renderOpencodeDoc(templatePath, tracker, OPENCODE_PROVIDERS[0], cwd);
90
+ if (isJsonObject(mcp))
91
+ Object.assign(owned, mcp);
92
+ }
93
+ return owned;
94
+ }
81
95
  export function stripTier2JsonScope(consumerDoc, templateDoc) {
82
96
  const out = JSON.parse(JSON.stringify(consumerDoc));
83
97
  _stripScope(out, templateDoc);
@@ -144,21 +158,87 @@ export function stripMcpTrackerEntries(consumer, template) {
144
158
  }
145
159
  /**
146
160
  * Delete each entry of `doc[key]` identical to the same-named entry in `owned`, then drop
147
- * `doc[key]` once empty. Entries that differ, and names `owned` lacks, stay. Mutates `doc`.
161
+ * `doc[key]` once empty (unless `dropEmpty` is false). Entries that differ, and names `owned`
162
+ * lacks, stay. Mutates `doc`; returns the names deleted.
148
163
  */
149
- function removeOwnedEntries(doc, key, owned) {
164
+ function removeOwnedEntries(doc, key, owned, dropEmpty = true) {
150
165
  const entries = doc[key];
151
166
  if (!isJsonObject(entries))
152
- return;
167
+ return [];
168
+ const removed = [];
153
169
  for (const [name, entry] of Object.entries(owned)) {
154
- if (JSON.stringify(entries[name]) === JSON.stringify(entry))
170
+ if (name in entries && JSON.stringify(entries[name]) === JSON.stringify(entry)) {
155
171
  delete entries[name];
172
+ removed.push(name);
173
+ }
156
174
  }
157
- if (Object.keys(entries).length === 0)
175
+ if (dropEmpty && Object.keys(entries).length === 0)
158
176
  delete doc[key];
177
+ return removed;
159
178
  }
160
- function isJsonObject(v) {
161
- return v !== null && typeof v === "object" && !Array.isArray(v);
179
+ /** The files bkit writes a tracker MCP entry into, and the key of each one's server map. */
180
+ const TRACKER_MCP_FILES = [
181
+ { relPath: ".mcp.json", mapKey: "mcpServers" },
182
+ { relPath: path.join(".cursor", "mcp.json"), mapKey: "mcpServers" },
183
+ { relPath: path.join(".opencode", "opencode.json"), mapKey: "mcp" },
184
+ ];
185
+ /**
186
+ * Tracker switch: remove each `unusedTrackerMcpServers(tracker)` entry from `.mcp.json`,
187
+ * `.cursor/mcp.json` and `.opencode/opencode.json` while it still equals bkit's template entry
188
+ * — the rule uninstall applies (`removeOwnedEntries`). An entry the consumer edited stays and
189
+ * is named in a warning. `.mcp.json` / `.cursor/mcp.json` keep an emptied `mcpServers` (the
190
+ * tracker-`none` render); `.opencode/opencode.json` drops an emptied `mcp`, as its render does.
191
+ * Absent and malformed files are skipped (the host module reports malformed JSON). Pushes each
192
+ * rewritten file onto `ws` and returns its path.
193
+ */
194
+ export function removeUnusedTrackerMcpEntries(cwd, tracker, dryRun, ws, logPrefix) {
195
+ const unused = unusedTrackerMcpServers(tracker);
196
+ const written = [];
197
+ for (const { relPath, mapKey } of TRACKER_MCP_FILES) {
198
+ const absPath = path.join(cwd, relPath);
199
+ const templatePath = findTemplateSource(relPath);
200
+ if (unused.length === 0 || templatePath === null || !fs.existsSync(absPath))
201
+ continue;
202
+ const parsed = parseJson(fs.readFileSync(absPath, "utf-8"));
203
+ const doc = parsed.ok ? parsed.value : null;
204
+ if (!isJsonObject(doc))
205
+ continue;
206
+ const servers = doc[mapKey];
207
+ if (!isJsonObject(servers))
208
+ continue;
209
+ let templateEntries;
210
+ if (mapKey === "mcp") {
211
+ templateEntries = ownedOpencodeMcpEntries(templatePath, cwd);
212
+ }
213
+ else {
214
+ const template = parseJson(fs.readFileSync(templatePath, "utf-8"));
215
+ const templateDoc = template.ok ? template.value : null;
216
+ templateEntries = isJsonObject(templateDoc) ? templateDoc[mapKey] : undefined;
217
+ }
218
+ if (!isJsonObject(templateEntries))
219
+ continue;
220
+ const owned = {};
221
+ for (const name of unused) {
222
+ if (name in servers && name in templateEntries)
223
+ owned[name] = templateEntries[name];
224
+ }
225
+ const removed = removeOwnedEntries(doc, mapKey, owned, mapKey === "mcp");
226
+ for (const name of Object.keys(owned).filter((n) => !removed.includes(n))) {
227
+ console.warn(`${logPrefix} kept ${relPath} ${mapKey}.${name}: edited since bkit wrote it, and the ` +
228
+ `${tracker} tracker does not use it — remove it by hand if unneeded.`);
229
+ }
230
+ if (removed.length === 0)
231
+ continue;
232
+ if (!dryRun)
233
+ fs.writeFileSync(absPath, JSON.stringify(doc, null, 2) + "\n", "utf-8");
234
+ ws.writes.push({ path: absPath, action: "update" });
235
+ written.push(absPath);
236
+ for (const name of removed) {
237
+ console.log(`${logPrefix} ${dryRun ? "[dry-run] " : ""}removed ${relPath} ${mapKey}.${name} ` +
238
+ `(the ${tracker} tracker does not use it)`);
239
+ }
240
+ }
241
+ return written;
162
242
  }
163
243
  // ---------------------------------------------------------------------------
164
244
  // Decision table builder (for --dry-run output and UninstallResult)
@@ -176,8 +256,9 @@ const CORE_TEMPLATE_DOCTRINE = [
176
256
  { path: ".agents/context.md", format: "markered-text", module: "core" },
177
257
  { path: ".agents/docs.md", format: "markered-text", module: "core" },
178
258
  { path: ".agents/rules.md", format: "markered-text", module: "core" },
179
- { path: ".agents/shortcuts.md", format: "markered-text", module: "core" },
180
259
  { path: ".agents/skills.md", format: "markered-text", module: "core" },
260
+ // Retired path of `.bkit/lite.md` (5.1.0 – 5.2.4), for an install never upgraded since.
261
+ { path: ".agents/shortcuts.md", format: "markered-text", module: "core" },
181
262
  ];
182
263
  /**
183
264
  * The top-level `docs/*.md` the core payload pass installs: each carries bkit's managed
@@ -466,12 +547,18 @@ export async function runUninstall(modules, ctx) {
466
547
  break;
467
548
  }
468
549
  const raw = fs.readFileSync(absPath, "utf-8");
469
- const consumerDoc = JSON.parse(raw);
550
+ const consumerParsed = parseJson(raw);
551
+ if (!consumerParsed.ok)
552
+ throw new Error(`${summary.file} is not valid JSON`);
553
+ const consumerDoc = consumerParsed.value;
470
554
  const templateRaw = fs.readFileSync(templatePath, "utf-8");
471
555
  // opencode.json ships `@@OPENCODE_*@@` sentinel KEYS; stripOpencodeJsonScope
472
556
  // renders them for every tracker and provider bkit can have written.
473
557
  const isOpencodeJson = templateRaw.includes("@@OPENCODE_TRACKER_MCP@@");
474
- const templateDoc = JSON.parse(templateRaw);
558
+ const templateParsed = parseJson(templateRaw);
559
+ if (!templateParsed.ok)
560
+ throw new Error(`${templatePath} is not valid JSON`);
561
+ const templateDoc = templateParsed.value;
475
562
  // `.claude/settings.json` is not written verbatim: after rendering the
476
563
  // template, install appends one `WebFetch(domain:<d>)` grant per entry in
477
564
  // the resolved network allowlist and `mcp__…` grants per declared MCP
@@ -801,14 +888,8 @@ export async function runSurgicalOpencodeUninstall(providerKey, dryRun, cwd) {
801
888
  let newActive = null;
802
889
  if (fs.existsSync(pkgPath)) {
803
890
  const raw = fs.readFileSync(pkgPath, "utf-8");
804
- // Parse-or-sentinel idiom: keep the early-return outside the catch body.
805
- let pkg = null;
806
- try {
807
- pkg = JSON.parse(raw);
808
- }
809
- catch {
810
- pkg = null;
811
- }
891
+ const parsed = parseJson(raw);
892
+ const pkg = parsed.ok ? parsed.value : null;
812
893
  if (pkg === null) {
813
894
  console.warn(`${LOG_PREFIX} package.json is malformed — skipping bkit section update`);
814
895
  return;
@@ -853,11 +934,64 @@ export async function runSurgicalOpencodeUninstall(providerKey, dryRun, cwd) {
853
934
  });
854
935
  return;
855
936
  }
856
- // 4. If was active → emit advisory (re-rendering agents requires full ModuleContext)
937
+ // 4. If was active → re-render the agent pins for the new active provider, so `bkit check`
938
+ // finds the mirrors in sync right after.
857
939
  if (wasActive && newActive !== null) {
858
- console.log(`${LOG_PREFIX}${tag} active provider switched to "${newActive}". ` +
859
- `Run \`bkit install --opencode=${newActive}\` or \`bkit upgrade\` to re-render agent frontmatter.`);
940
+ if (dryRun) {
941
+ console.log(`${LOG_PREFIX}${tag} active provider would switch to "${newActive}" — .opencode/agents/ ` +
942
+ `would be re-rendered to its model pins.`);
943
+ return;
944
+ }
945
+ const previousCwd = process.cwd();
946
+ process.chdir(cwd);
947
+ try {
948
+ const written = rerenderOpencodeMirrors(newActive, LOG_PREFIX);
949
+ console.log(`${LOG_PREFIX} active provider switched to "${newActive}" — re-rendered ` +
950
+ `${written.length} .opencode/ agent/command file(s) to its model pins.`);
951
+ }
952
+ finally {
953
+ process.chdir(previousCwd);
954
+ }
955
+ }
956
+ }
957
+ /**
958
+ * Re-render `.opencode/agents/` + `.opencode/commands/` for `provider` — the per-agent model
959
+ * pins `bkit check` expects once `provider` is the active one, consumer `.bkit/prompts.md`
960
+ * § Model Overrides applied — and refresh their `.bkit/version` hashes. Renders into
961
+ * process.cwd(), as the host renderers resolve consumer paths from it. Returns the paths written.
962
+ */
963
+ function rerenderOpencodeMirrors(provider, logPrefix) {
964
+ const cwd = process.cwd();
965
+ const promptsMd = path.join(getBkitDocsRoot(), "prompts.md");
966
+ const opencodeModelLookup = buildOpencodeModelLookup(promptsMd, provider);
967
+ applyModelOverrides(opencodeModelLookup, provider, path.join(cwd, ".bkit", "prompts.md"));
968
+ const written = renderOpencodeAgentsCommands({
969
+ dryRun: false,
970
+ tokens: { DEFAULT_BRANCH: "", PROJECT_NAME: "", REPO_SLUG: "" },
971
+ modelLookup: new Map(),
972
+ opencodeModelLookup,
973
+ effortMap: parseEffortMap(promptsMd),
974
+ opencodeProvider: provider,
975
+ advisories: [],
976
+ ws: { writes: [] },
977
+ logPrefix,
978
+ postDispatch: [],
979
+ issueTracker: readBkitConfig(cwd).issueTracker,
980
+ version: readInstallingVersion(),
981
+ });
982
+ const versionFile = path.join(cwd, ".bkit", "version");
983
+ const existing = readBkitVersion(versionFile);
984
+ if (existing && written.length > 0) {
985
+ const fresh = {};
986
+ for (const rel of written) {
987
+ const hash = hashFile(path.join(cwd, rel));
988
+ if (hash)
989
+ fresh[rel] = hash;
990
+ }
991
+ const { canonicalHashes } = mergeCanonicalHashes(cwd, existing.canonicalHashes, fresh);
992
+ writeBkitVersion(versionFile, { ...existing, canonicalHashes });
860
993
  }
994
+ return written;
861
995
  }
862
996
  export async function runUninstallCommand(modules, opencodeProvider, uninstallFlags) {
863
997
  setLogPrefix("[bkit-uninstall]");