@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,14 +3,12 @@
3
3
 
4
4
  import * as fs from "node:fs";
5
5
  import * as path from "node:path";
6
- import {
7
- detectOpencodeProvider,
8
- detectOpencodeProviders,
9
- getInstallingVersion,
10
- } from "./install.js";
6
+ import { detectOpencodeProvider, detectOpencodeProviders } from "./install.js";
11
7
  import { type ModuleFlag } from "../../cli.js";
12
8
  import { OPENCODE_PROVIDERS } from "../../shared/egress.js";
9
+ import { readJsonFile } from "../../shared/json.js";
13
10
  import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
11
+ import { readInstallingVersion } from "../../shared/package-json.js";
14
12
  import { getCoreRoot, getSharedRoot, getTemplatesRoot } from "../../shared/package-roots.js";
15
13
  import { runPreflight } from "../../checks/before/index.js";
16
14
  import {
@@ -22,11 +20,47 @@ import type { SuppressionNote } from "../../checks/after/suppression.js";
22
20
  import { collectTips } from "../../checks/tips/index.js";
23
21
  import { parseDotenv } from "../../install/cloud-env.js";
24
22
  import { detectInstalledHostModules } from "../../install/hosts.js";
23
+ import { parseFrontmatter } from "../../render/hosts.js";
24
+
25
+ /** One distinct opencode model pin and how many agent files carry it. */
26
+ export interface OpencodeModelPin {
27
+ model: string;
28
+ agents: number;
29
+ }
30
+
31
+ /**
32
+ * The `model:` pins in the frontmatter of `.opencode/agents/*.md` — where bkit renders the
33
+ * opencode per-agent pins — grouped by model, most-used first (ties by model id). `[]` when
34
+ * the directory is absent or no agent carries a pin.
35
+ */
36
+ export function readOpencodeModelPins(cwd: string): OpencodeModelPin[] {
37
+ const agentsDir = path.join(cwd, ".opencode", "agents");
38
+ if (!fs.existsSync(agentsDir)) return [];
39
+ const counts = new Map<string, number>();
40
+ for (const name of fs.readdirSync(agentsDir)) {
41
+ if (!name.endsWith(".md")) continue;
42
+ const content = fs.readFileSync(path.join(agentsDir, name), "utf-8");
43
+ const fm = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
44
+ const model = fm ? parseFrontmatter(fm[1]).get("model")?.trim() : undefined;
45
+ if (model) counts.set(model, (counts.get(model) ?? 0) + 1);
46
+ }
47
+ return [...counts]
48
+ .map(([model, agents]) => ({ model, agents }))
49
+ .sort((a, b) => b.agents - a.agents || a.model.localeCompare(b.model));
50
+ }
51
+
52
+ /** `model: <id>` for one distinct pin, else `models: <id> (N agents), …`. */
53
+ export function formatOpencodeModelPins(pins: readonly OpencodeModelPin[]): string {
54
+ if (pins.length === 0) return "model: none pinned in .opencode/agents/";
55
+ if (pins.length === 1) return `model: ${pins[0].model}`;
56
+ const list = pins.map((p) => `${p.model} (${p.agents} agent${p.agents === 1 ? "" : "s"})`);
57
+ return `models: ${list.join(", ")}`;
58
+ }
25
59
 
26
60
  /**
27
61
  * `bkit status` — read-only host/provider status.
28
- * Reports current host+provider sampled from .opencode/opencode.json,
29
- * .claude/, and .cursor/ presence. Writes nothing.
62
+ * Reports current host+provider sampled from .claude/, .cursor/, package.json and the
63
+ * opencode agent model pins in .opencode/agents/. Writes nothing.
30
64
  */
31
65
  export function runStatus(cwd: string, logPrefix: string): void {
32
66
  console.log(`${logPrefix} Host/provider status (read-only — no writes)`);
@@ -38,13 +72,11 @@ export function runStatus(cwd: string, logPrefix: string): void {
38
72
  const claudeSettingsPath = path.join(claudeDir, "settings.json");
39
73
  let claudeModel = "claude (default)";
40
74
  if (claudePresent && fs.existsSync(claudeSettingsPath)) {
41
- try {
42
- const settings = JSON.parse(fs.readFileSync(claudeSettingsPath, "utf-8")) as {
43
- model?: string;
44
- };
75
+ // Best-effort: an unreadable settings file keeps the default label.
76
+ const read = readJsonFile(claudeSettingsPath);
77
+ if (read.ok && typeof read.value === "object" && read.value !== null) {
78
+ const settings = read.value as { model?: string };
45
79
  if (settings.model) claudeModel = settings.model;
46
- } catch {
47
- // best-effort
48
80
  }
49
81
  }
50
82
  console.log(
@@ -63,22 +95,19 @@ export function runStatus(cwd: string, logPrefix: string): void {
63
95
  const activeOpencodeProvider = detectOpencodeProvider(cwd);
64
96
  // All installed providers.
65
97
  const allOpencodeProviders = detectOpencodeProviders(cwd);
66
- let opencodeModel = "unknown";
98
+ // bkit pins models per agent in .opencode/agents/*.md frontmatter; opencode.json carries
99
+ // only the consumer's optional top-level default `model`.
100
+ let opencodeModel = formatOpencodeModelPins(readOpencodeModelPins(cwd));
67
101
  const opencodeJsonPath = path.join(opencodeDir, "opencode.json");
68
102
  if (opencodePresent && fs.existsSync(opencodeJsonPath)) {
69
- try {
70
- const cfg = JSON.parse(fs.readFileSync(opencodeJsonPath, "utf-8")) as {
71
- model?: string;
72
- models?: Record<string, unknown>;
73
- };
74
- if (cfg.model) opencodeModel = cfg.model;
75
- // Fallback: look for non-empty models map
76
- if (opencodeModel === "unknown" && cfg.models) {
77
- const modelKeys = Object.keys(cfg.models);
78
- if (modelKeys.length > 0) opencodeModel = `${modelKeys.length} model(s) configured`;
103
+ const read = readJsonFile(opencodeJsonPath);
104
+ if (!read.ok || read.value === null || typeof read.value !== "object") {
105
+ opencodeModel += "; opencode.json: parse-error";
106
+ } else {
107
+ const cfg = read.value as { model?: unknown };
108
+ if (typeof cfg.model === "string" && cfg.model) {
109
+ opencodeModel += `; default model: ${cfg.model}`;
79
110
  }
80
- } catch {
81
- opencodeModel = "parse-error";
82
111
  }
83
112
  }
84
113
  let opencodeProviderDisplay: string;
@@ -103,7 +132,7 @@ export function runStatus(cwd: string, logPrefix: string): void {
103
132
  const antigravityPresent = detectInstalledHostModules(cwd).has("antigravity");
104
133
 
105
134
  const opencodeStatus = opencodePresent
106
- ? `INSTALLED (${providerLabel}: ${opencodeProviderDisplay} / model: ${opencodeModel})`
135
+ ? `INSTALLED (${providerLabel}: ${opencodeProviderDisplay} / ${opencodeModel})`
107
136
  : "absent (run: bkit install --opencode=<provider>)";
108
137
  console.log(`${logPrefix} opencode: ${opencodeStatus}`);
109
138
  console.log(
@@ -168,7 +197,7 @@ export async function runDoctor(
168
197
  writeAdvisoriesArtifact(allFindings, {
169
198
  cwd: process.cwd(),
170
199
  mode: "doctor",
171
- version: getInstallingVersion(),
200
+ version: readInstallingVersion(),
172
201
  logPrefix: LOG_PREFIX,
173
202
  suppressed,
174
203
  tips,
@@ -5,14 +5,15 @@ import * as fs from "node:fs";
5
5
  import * as path from "node:path";
6
6
  import { OPENCODE_PROVIDERS } from "../../shared/egress.js";
7
7
  import { type ModuleFlag, type CloudVariant } from "../../cli.js";
8
- import { getPkgRoot } from "../../shared/package-roots.js";
8
+ import { readInstallingVersion } from "../../shared/package-json.js";
9
9
  import { type ModuleContext, dispatchModules } from "../../install/modules/index.js";
10
10
  import {
11
11
  type IssueTracker,
12
12
  DEFAULT_ISSUE_TRACKER,
13
- parseIssueTracker,
14
13
  type ModuleName,
15
14
  } from "../../install/manifest.js";
15
+ import { parseJson, readJsonFile } from "../../shared/json.js";
16
+ import { readBkitConfig } from "../../shared/settings.js";
16
17
  import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
17
18
  import type { ParsedArgs } from "../../cli.js";
18
19
  import { detectInstalledModules, reportCheckDrift } from "./check.js";
@@ -37,7 +38,7 @@ import {
37
38
  } from "../../render/models.js";
38
39
  import { getBkitDocsRoot } from "../../shared/package-roots.js";
39
40
  import type { WriteSet } from "../../install/write.js";
40
- import { type UninstallContext, runUninstall } from "./uninstall.js";
41
+ import { type UninstallContext, removeUnusedTrackerMcpEntries, runUninstall } from "./uninstall.js";
41
42
 
42
43
  // ---------------------------------------------------------------------------
43
44
  // Staging scratch area
@@ -86,24 +87,6 @@ export function requireOpencodeProvider(cwd: string, context: string): string {
86
87
  return detected;
87
88
  }
88
89
 
89
- /**
90
- * Read the installing bkit version from the package root's package.json.
91
- * Returns "0.0.0" when unreadable (e.g. dev tree without a package.json at the
92
- * resolved root) — keeps the advisories artifact informational, not fatal.
93
- */
94
- export function getInstallingVersion(): string {
95
- try {
96
- const pkgJsonPath = path.join(getPkgRoot(), "package.json");
97
- if (fs.existsSync(pkgJsonPath)) {
98
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")) as { version?: string };
99
- return pkg.version ?? "0.0.0";
100
- }
101
- } catch {
102
- return "0.0.0"; // best-effort: unreadable/garbled package.json
103
- }
104
- return "0.0.0";
105
- }
106
-
107
90
  /**
108
91
  * Render a resolved module set back into valid CLI flags for
109
92
  * recovery-hint text. Skips core (implicit) and spells opt-ins with their value flags.
@@ -163,37 +146,19 @@ export function validateCloudTrackerMatch(
163
146
  * smuggle an unsupported provider into the render path.
164
147
  */
165
148
  export function detectOpencodeProvider(cwd: string): string | null {
166
- const pkgPath = path.join(cwd, "package.json");
167
- if (fs.existsSync(pkgPath)) {
168
- try {
169
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as {
170
- bkit?: { opencodeProvider?: unknown };
171
- };
172
- const stored = pkg.bkit?.opencodeProvider;
173
- if (
174
- typeof stored === "string" &&
175
- (OPENCODE_PROVIDERS as readonly string[]).includes(stored)
176
- ) {
177
- return stored;
178
- }
179
- } catch {
180
- // unparseable package.json — fall through to opencode.json detection
181
- }
182
- }
149
+ const stored = readBkitConfig(cwd).opencodeProvider;
150
+ if (stored !== null) return stored;
183
151
  const jsonPath = path.join(cwd, ".opencode", "opencode.json");
184
152
  if (!fs.existsSync(jsonPath)) return null;
185
- try {
186
- const cfg = JSON.parse(fs.readFileSync(jsonPath, "utf-8")) as {
187
- provider?: Record<string, unknown>;
188
- };
189
- if (cfg.provider && typeof cfg.provider === "object") {
190
- const first = Object.keys(cfg.provider)[0];
191
- if (!first) return null;
192
- // Zen's opencode.json block is keyed by the built-in id `opencode`, not the CLI key.
193
- return first === "opencode" ? "opencode-zen" : first;
194
- }
195
- } catch {
196
- return null; // unparseable opencode.json — fall back to the default provider
153
+ // Unparseable opencode.json — fall back to the default provider.
154
+ const read = readJsonFile(jsonPath);
155
+ if (!read.ok || typeof read.value !== "object" || read.value === null) return null;
156
+ const cfg = read.value as { provider?: Record<string, unknown> };
157
+ if (cfg.provider && typeof cfg.provider === "object") {
158
+ const first = Object.keys(cfg.provider)[0];
159
+ if (!first) return null;
160
+ // Zen's opencode.json block is keyed by the built-in id `opencode`, not the CLI key.
161
+ return first === "opencode" ? "opencode-zen" : first;
197
162
  }
198
163
  return null;
199
164
  }
@@ -204,23 +169,7 @@ export function detectOpencodeProvider(cwd: string): string | null {
204
169
  * the field is absent.
205
170
  */
206
171
  export function detectOpencodeProviders(cwd: string): string[] {
207
- const pkgPath = path.join(cwd, "package.json");
208
- if (!fs.existsSync(pkgPath)) return [];
209
- try {
210
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as {
211
- bkit?: { opencodeProviders?: unknown };
212
- };
213
- const arr = pkg.bkit?.opencodeProviders;
214
- if (Array.isArray(arr)) {
215
- return arr.filter(
216
- (v): v is string =>
217
- typeof v === "string" && (OPENCODE_PROVIDERS as readonly string[]).includes(v),
218
- );
219
- }
220
- } catch {
221
- // unparseable — return empty
222
- }
223
- return [];
172
+ return readBkitConfig(cwd).opencodeProviders;
224
173
  }
225
174
 
226
175
  /**
@@ -279,14 +228,21 @@ export async function runInstall(
279
228
  else if (dryRun) console.log(`${LOG_PREFIX} Running in check (dry-run) mode`);
280
229
 
281
230
  // `bkit check` scopes drift detection to what is INSTALLED (detected by sentinel files),
282
- // not to a fixed full set. `install` keeps its explicit resolved set.
283
- const effectiveModules = verb === "check" ? detectInstalledModules(process.cwd()) : modules;
231
+ // not to a fixed full set. `install` keeps its explicit resolved set, plus every installed
232
+ // host when `--tracker=` is given: each host renders tracker-specific commands, agents and
233
+ // MCP entries, so a host left out would keep the old tracker's.
234
+ const effectiveModules =
235
+ verb === "check"
236
+ ? detectInstalledModules(process.cwd())
237
+ : tracker !== null
238
+ ? new Set<ModuleFlag>([...modules, ...detectInstalledModules(process.cwd())])
239
+ : modules;
284
240
 
285
241
  // RENDER-input provider resolution. `bkit check` takes no `--opencode=` flag, so the parsed
286
242
  // `opencodeProvider` is null on the check path; it falls back to the INSTALLED provider
287
243
  // (package.json `bkit.opencodeProvider`, else the opencode.json provider block). On install
288
- // `?? detect` never fires: opencode joins the module set only when `--opencode=<provider>`
289
- // was given. The PARSED `opencodeProvider` alone drives the persist-to-package.json logic
244
+ // `?? detect` fires only when opencode joins as an installed host under `--tracker=`; with
245
+ // `--opencode=<provider>` the flag wins. The PARSED `opencodeProvider` alone drives the persist-to-package.json logic
290
246
  // below (gated on `!dryRun` + a real flag). The tracker is resolved from package.json below,
291
247
  // so the tracker-dependent opencode mcp block renders the same way on check.
292
248
  const renderOpencodeProvider = opencodeProvider ?? detectOpencodeProvider(process.cwd());
@@ -297,24 +253,8 @@ export async function runInstall(
297
253
  // already-recorded tracker.
298
254
  // Resolved BEFORE preflight: preflight's tracker-dependent detectors grade the tracker
299
255
  // this run INSTALLS, not the one on disk from the previous run. Read-only — no writes here.
300
- let issueTracker: IssueTracker = DEFAULT_ISSUE_TRACKER;
301
- {
302
- const consumerPkgPath = path.join(process.cwd(), "package.json");
303
- if (fs.existsSync(consumerPkgPath)) {
304
- try {
305
- const pkg = JSON.parse(fs.readFileSync(consumerPkgPath, "utf-8")) as Record<
306
- string,
307
- unknown
308
- >;
309
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
310
- const stored = parseIssueTracker(bkitField?.issueTracker);
311
- if (stored !== null) issueTracker = stored;
312
- } catch {
313
- // non-fatal — keep default
314
- }
315
- }
316
- if (tracker !== null) issueTracker = tracker;
317
- }
256
+ const recordedTracker: IssueTracker = readBkitConfig(process.cwd()).issueTracker;
257
+ const issueTracker: IssueTracker = tracker ?? recordedTracker;
318
258
 
319
259
  // --- Phase 1: Preflight (read-only, before any writes) ---
320
260
  // Must run BEFORE resolveTokens to short-circuit cleanly on blockers.
@@ -332,7 +272,7 @@ export async function runInstall(
332
272
  writeAdvisoriesArtifact(blockers, {
333
273
  cwd: process.cwd(),
334
274
  mode: "upgrade",
335
- version: getInstallingVersion(),
275
+ version: readInstallingVersion(),
336
276
  logPrefix: LOG_PREFIX,
337
277
  });
338
278
  return;
@@ -447,36 +387,40 @@ export async function runInstall(
447
387
  if (fs.existsSync(consumerPkgPath2)) {
448
388
  try {
449
389
  const raw = fs.readFileSync(consumerPkgPath2, "utf-8");
450
- const pkg = JSON.parse(raw) as Record<string, unknown>;
451
- const bkit = (pkg.bkit ?? {}) as Record<string, unknown>;
452
- if (persistTracker) bkit.issueTracker = tracker;
453
- if (persistProvider) {
454
- bkit.opencodeProvider = opencodeProvider; // active (drives agent frontmatter)
455
- // Update providers array (deduped).
456
- const existingArr: string[] = Array.isArray(bkit.opencodeProviders)
457
- ? [...(bkit.opencodeProviders as string[])]
458
- : [];
459
- if (!existingArr.includes(opencodeProvider!)) {
460
- existingArr.push(opencodeProvider!);
390
+ // A package.json that is not JSON is left as-is (the preflight blocker reports it).
391
+ const parsed = parseJson(raw);
392
+ if (parsed.ok) {
393
+ const pkg = parsed.value as Record<string, unknown>;
394
+ const bkit = (pkg.bkit ?? {}) as Record<string, unknown>;
395
+ if (persistTracker) bkit.issueTracker = tracker;
396
+ if (persistProvider) {
397
+ bkit.opencodeProvider = opencodeProvider; // active (drives agent frontmatter)
398
+ // Update providers array (deduped).
399
+ const existingArr: string[] = Array.isArray(bkit.opencodeProviders)
400
+ ? [...(bkit.opencodeProviders as string[])]
401
+ : [];
402
+ if (!existingArr.includes(opencodeProvider!)) {
403
+ existingArr.push(opencodeProvider!);
404
+ }
405
+ bkit.opencodeProviders = existingArr;
461
406
  }
462
- bkit.opencodeProviders = existingArr;
463
- }
464
- pkg.bkit = bkit;
465
- const indentMatch = raw.match(/\n([ \t]+)"/);
466
- const indent = indentMatch ? indentMatch[1] : " ";
467
- const trailingNewline = raw.endsWith("\n") ? "\n" : "";
468
- fs.writeFileSync(
469
- consumerPkgPath2,
470
- JSON.stringify(pkg, null, indent) + trailingNewline,
471
- "utf-8",
472
- );
473
- if (persistTracker) {
474
- console.log(`${LOG_PREFIX} Set bkit.issueTracker = "${tracker}" in package.json`);
475
- }
476
- if (persistProvider) {
477
- console.log(
478
- `${LOG_PREFIX} Set bkit.opencodeProvider = "${opencodeProvider}" and updated bkit.opencodeProviders in package.json`,
407
+ pkg.bkit = bkit;
408
+ const indentMatch = raw.match(/\n([ \t]+)"/);
409
+ const indent = indentMatch ? indentMatch[1] : " ";
410
+ const trailingNewline = raw.endsWith("\n") ? "\n" : "";
411
+ fs.writeFileSync(
412
+ consumerPkgPath2,
413
+ JSON.stringify(pkg, null, indent) + trailingNewline,
414
+ "utf-8",
479
415
  );
416
+ if (persistTracker) {
417
+ console.log(`${LOG_PREFIX} Set bkit.issueTracker = "${tracker}" in package.json`);
418
+ }
419
+ if (persistProvider) {
420
+ console.log(
421
+ `${LOG_PREFIX} Set bkit.opencodeProvider = "${opencodeProvider}" and updated bkit.opencodeProviders in package.json`,
422
+ );
423
+ }
480
424
  }
481
425
  } catch {
482
426
  // non-fatal
@@ -484,6 +428,13 @@ export async function runInstall(
484
428
  }
485
429
  }
486
430
 
431
+ // Tracker switch: drop the bkit MCP entries the new tracker does not use, while each still
432
+ // equals bkit's template (an edited one stays, with a warning). Runs before dispatch so the
433
+ // `.bkit/version` hashes core records cover the final file content.
434
+ if (!dryRun && tracker !== null && tracker !== recordedTracker) {
435
+ removeUnusedTrackerMcpEntries(process.cwd(), tracker, dryRun, ws, LOG_PREFIX);
436
+ }
437
+
487
438
  const ctx: ModuleContext = {
488
439
  dryRun,
489
440
  tokens,
@@ -500,7 +451,7 @@ export async function runInstall(
500
451
  issueTracker,
501
452
  cloudVariant,
502
453
  // Stamped into every rendered agent + command as the managed-version marker.
503
- version: getInstallingVersion(),
454
+ version: readInstallingVersion(),
504
455
  // Full host set for this run: dispatched ∪ already-on-disk. Read by the Antigravity
505
456
  // module to warn when Codex is also installed (both hosts' `bkit-*` workflow skills
506
457
  // then surface in Antigravity's skill selector).
@@ -559,16 +510,8 @@ export async function runInstall(
559
510
  // Runs for both install AND check — detectors are read-only, so check produces
560
511
  // the same advisory set as install would emit against the same filesystem state.
561
512
  // Changelog version-delta header (A7): surface what changed in the installed version.
562
- try {
563
- const pkgJsonPath = path.join(getPkgRoot(), "package.json");
564
- if (fs.existsSync(pkgJsonPath)) {
565
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")) as { version?: string };
566
- const deltaHeader = readChangelogVersionDelta(pkg.version ?? "");
567
- if (deltaHeader) console.log(deltaHeader);
568
- }
569
- } catch (err) {
570
- void err; // Non-fatal — changelog header is informational
571
- }
513
+ const deltaHeader = readChangelogVersionDelta(readInstallingVersion());
514
+ if (deltaHeader) console.log(deltaHeader);
572
515
  const suppressed: SuppressionNote[] = [];
573
516
  const postFindings = runPostInstallCheck(ctx.advisories, process.cwd(), suppressed);
574
517
  if (postWriteBlockers.length > 0) {
@@ -589,7 +532,7 @@ export async function runInstall(
589
532
  writeAdvisoriesArtifact(postFindings, {
590
533
  cwd: process.cwd(),
591
534
  mode: upgradeReport ? "upgrade" : dryRun ? "check" : "install",
592
- version: getInstallingVersion(),
535
+ version: readInstallingVersion(),
593
536
  logPrefix: LOG_PREFIX,
594
537
  suppressed,
595
538
  tips,