@cbartens/bkit 5.2.3 → 5.3.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 (254) hide show
  1. package/.bkit/README.md +29 -12
  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 +11 -0
  6. package/.bkit/core/.bkit/README.md +28 -11
  7. package/.bkit/core/.bkit/cloud.md +9 -8
  8. package/.bkit/core/.bkit/comparison.md +68 -345
  9. package/.bkit/core/.bkit/install.md +15 -9
  10. package/.bkit/core/.bkit/lite.md +73 -0
  11. package/.bkit/core/.bkit/pipeline.md +345 -0
  12. package/.bkit/core/.bkit/prompts.md +88 -73
  13. package/.bkit/core/.bkit/providers.md +41 -22
  14. package/.bkit/core/.bkit/templates.md +125 -18
  15. package/.bkit/core/.bkit/trackers.md +47 -1
  16. package/.bkit/core/.bkit/workflows.md +51 -45
  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 +9 -1
  21. package/.bkit/core/docs/templates/bkit-audit-adoption.md +10 -2
  22. package/.bkit/core/docs/templates/bkit-audit-agents.md +9 -1
  23. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +9 -1
  24. package/.bkit/core/docs/templates/bkit-audit-analytics.md +9 -1
  25. package/.bkit/core/docs/templates/bkit-audit-annotations.md +10 -2
  26. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +9 -1
  27. package/.bkit/core/docs/templates/bkit-audit-app-store.md +9 -1
  28. package/.bkit/core/docs/templates/bkit-audit-architecture.md +9 -1
  29. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +9 -1
  30. package/.bkit/core/docs/templates/bkit-audit-config.md +9 -1
  31. package/.bkit/core/docs/templates/bkit-audit-cost.md +10 -2
  32. package/.bkit/core/docs/templates/bkit-audit-coverage.md +9 -1
  33. package/.bkit/core/docs/templates/bkit-audit-database.md +9 -1
  34. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +9 -1
  35. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +9 -1
  36. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +22 -10
  37. package/.bkit/core/docs/templates/bkit-audit-documentation.md +9 -1
  38. package/.bkit/core/docs/templates/bkit-audit-duplication.md +9 -1
  39. package/.bkit/core/docs/templates/bkit-audit-failures.md +9 -1
  40. package/.bkit/core/docs/templates/bkit-audit-flakes.md +10 -2
  41. package/.bkit/core/docs/templates/bkit-audit-gates.md +9 -1
  42. package/.bkit/core/docs/templates/bkit-audit-issues.md +9 -1
  43. package/.bkit/core/docs/templates/bkit-audit-llm.md +29 -15
  44. package/.bkit/core/docs/templates/bkit-audit-logs.md +10 -2
  45. package/.bkit/core/docs/templates/bkit-audit-models.md +9 -1
  46. package/.bkit/core/docs/templates/bkit-audit-privacy.md +9 -1
  47. package/.bkit/core/docs/templates/bkit-audit-prompts.md +11 -3
  48. package/.bkit/core/docs/templates/bkit-audit-red-team.md +19 -9
  49. package/.bkit/core/docs/templates/bkit-audit-reliability.md +9 -1
  50. package/.bkit/core/docs/templates/bkit-audit-repo.md +10 -2
  51. package/.bkit/core/docs/templates/bkit-audit-security.md +13 -5
  52. package/.bkit/core/docs/templates/bkit-audit-slop.md +9 -1
  53. package/.bkit/core/docs/templates/bkit-audit-testing.md +14 -5
  54. package/.bkit/core/docs/templates/bkit-audit-usability.md +9 -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 -5
  67. package/.bkit/core/engine/checks/tips/catalogue.ts +70 -24
  68. package/.bkit/core/engine/checks/tips/detect.ts +45 -2
  69. package/.bkit/core/engine/checks/tips/index.ts +37 -8
  70. package/.bkit/core/engine/cli.ts +39 -16
  71. package/.bkit/core/engine/commands/analysis.ts +36 -26
  72. package/.bkit/core/engine/commands/comply.ts +17 -16
  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 +62 -126
  76. package/.bkit/core/engine/commands/install/uninstall.ts +191 -33
  77. package/.bkit/core/engine/commands/install/upgrade.ts +58 -53
  78. package/.bkit/core/engine/commands/lib.ts +35 -10
  79. package/.bkit/core/engine/commands/tips.ts +8 -5
  80. package/.bkit/core/engine/commands/workflow/branches.ts +65 -11
  81. package/.bkit/core/engine/commands/workflow/counters.ts +21 -12
  82. package/.bkit/core/engine/commands/workflow/fids.ts +46 -0
  83. package/.bkit/core/engine/commands/workflow/ledgers.ts +3 -1
  84. package/.bkit/core/engine/commands/workflow/prs.ts +4 -2
  85. package/.bkit/core/engine/commands/workflow/repo.ts +18 -4
  86. package/.bkit/core/engine/commands/workflow/roadmap.ts +4 -3
  87. package/.bkit/core/engine/commands/workflow/runs.ts +8 -7
  88. package/.bkit/core/engine/commands/workflow/steps.ts +1 -0
  89. package/.bkit/core/engine/commands/workflow/tests.ts +17 -5
  90. package/.bkit/core/engine/commands/workflow/workflows.ts +19 -17
  91. package/.bkit/core/engine/commands/workflow/workstreams.ts +2 -1
  92. package/.bkit/core/engine/commands/workflow/worktrees.ts +13 -5
  93. package/.bkit/core/engine/install/cloud-env.ts +10 -31
  94. package/.bkit/core/engine/install/manifest.ts +14 -7
  95. package/.bkit/core/engine/install/modules/antigravity.ts +15 -26
  96. package/.bkit/core/engine/install/modules/claude.ts +20 -28
  97. package/.bkit/core/engine/install/modules/cloud.ts +5 -2
  98. package/.bkit/core/engine/install/modules/codex.ts +15 -29
  99. package/.bkit/core/engine/install/modules/core.ts +91 -70
  100. package/.bkit/core/engine/install/modules/cursor.ts +6 -20
  101. package/.bkit/core/engine/install/modules/index.ts +7 -1
  102. package/.bkit/core/engine/install/modules/opencode.ts +48 -70
  103. package/.bkit/core/engine/install/network-allowlist.ts +73 -0
  104. package/.bkit/core/engine/install/placeholders.ts +3 -18
  105. package/.bkit/core/engine/install/write.ts +59 -12
  106. package/.bkit/core/engine/ledgers/telemetry.ts +6 -4
  107. package/.bkit/core/engine/render/hosts.ts +47 -67
  108. package/.bkit/core/engine/render/models.ts +29 -11
  109. package/.bkit/core/engine/shared/bkit-latest.ts +164 -0
  110. package/.bkit/core/engine/shared/branches.ts +13 -0
  111. package/.bkit/core/engine/shared/egress.ts +3 -3
  112. package/.bkit/core/engine/shared/json.ts +18 -1
  113. package/.bkit/core/engine/shared/package-json.ts +63 -0
  114. package/.bkit/core/engine/shared/package-roots.ts +0 -10
  115. package/.bkit/core/engine/shared/protected-paths.ts +5 -130
  116. package/.bkit/core/engine/shared/settings.ts +36 -0
  117. package/.bkit/core/engine/shared/timeouts.ts +6 -0
  118. package/.bkit/core/hooks/antigravity-hook.js +1 -0
  119. package/.bkit/core/hooks/guardrails-shell.js +186 -40
  120. package/.bkit/core/hooks/guardrails-tiers.js +5 -78
  121. package/.bkit/core/prompts/bkit-audit-generate.md +65 -10
  122. package/.bkit/core/prompts/bkit-build-challenge-1.md +1 -1
  123. package/.bkit/core/prompts/bkit-build-challenge-2.md +1 -1
  124. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +1 -1
  125. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +1 -1
  126. package/.bkit/core/prompts/bkit-build-challenge-tests.md +1 -1
  127. package/.bkit/core/prompts/bkit-build-install-skills.md +1 -1
  128. package/.bkit/core/prompts/bkit-build-plan-current.md +1 -1
  129. package/.bkit/core/prompts/bkit-build-plan-execute.md +4 -4
  130. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +1 -1
  131. package/.bkit/core/prompts/bkit-build-plan-verify.md +2 -2
  132. package/.bkit/core/prompts/bkit-debug-abort-handover.md +1 -1
  133. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +1 -1
  134. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +1 -1
  135. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +78 -0
  136. package/.bkit/core/prompts/bkit-debug-failure-soak.md +1 -1
  137. package/.bkit/core/prompts/bkit-debug-summary.md +3 -3
  138. package/.bkit/core/prompts/bkit-design-spike.md +1 -1
  139. package/.bkit/core/prompts/bkit-design-summary.md +2 -2
  140. package/.bkit/core/prompts/bkit-design-update.md +1 -1
  141. package/.bkit/core/prompts/bkit-plan-complexity-check.md +1 -1
  142. package/.bkit/core/prompts/bkit-plan-generate.md +1 -1
  143. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +1 -1
  144. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +1 -1
  145. package/.bkit/core/prompts/bkit-plan-summary.md +1 -1
  146. package/.bkit/core/prompts/bkit-plan-update.md +1 -1
  147. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +1 -1
  148. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +1 -1
  149. package/.bkit/core/prompts/bkit-ship-update-docs.md +1 -1
  150. package/.bkit/core/prompts/bkit-utility-update-decisions.md +9 -2
  151. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +9 -2
  152. package/.bkit/core/prompts/bkit-utility-update-documentation.md +2 -1
  153. package/.bkit/core/prompts/bkit-utility-update-failures.md +9 -2
  154. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +9 -2
  155. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +11 -4
  156. package/.bkit/core/workflows/bkit-build.md +4 -4
  157. package/.bkit/core/workflows/bkit-debug.md +70 -34
  158. package/.bkit/core/workflows/bkit-design.md +3 -3
  159. package/.bkit/core/workflows/bkit-plan.md +12 -5
  160. package/.bkit/core/workflows/bkit-ship.md +6 -6
  161. package/.bkit/shared/.claude/bkit-cloud.md +46 -13
  162. package/.bkit/shared/.claude/settings.json +18 -0
  163. package/.bkit/shared/.cursor/mcp.json +2 -1
  164. package/.bkit/shared/.opencode/opencode.json +19 -1
  165. package/.bkit/shared/docs/deployments.md +20 -4
  166. package/.bkit/shared/docs/security.md +8 -6
  167. package/.bkit/shared/docs/testing.md +9 -5
  168. package/.bkit/templates/.cursor/Dockerfile +30 -16
  169. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +78 -0
  170. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +91 -0
  171. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +56 -0
  172. package/.bkit/templates/.github/renovate.json5 +91 -12
  173. package/.bkit/templates/.github/workflows/bkit-ci.yml +66 -53
  174. package/.bkit/templates/.github/workflows/bkit-cloud.yml +3 -1
  175. package/.bkit/templates/.github/workflows/bkit-renovate.yml +8 -1
  176. package/.bkit/templates/.github/workflows/bkit-trivy.yml +67 -0
  177. package/.bkit/templates/.husky/pre-push +15 -3
  178. package/.bkit/templates/.oxlintrc.json +21 -0
  179. package/.bkit/templates/docs/capabilities.md +1 -1
  180. package/.bkit/templates/scripts/ci/check-capstone.mjs +176 -0
  181. package/.bkit/templates/scripts/ci/check-capstone.test.mjs +311 -0
  182. package/.bkit/templates/scripts/cleanup/bkit-tmp-prune.mjs +115 -0
  183. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +2 -2
  184. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +43 -20
  185. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +33 -11
  186. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -2
  187. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +5 -5
  188. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +79 -19
  189. package/CHANGELOG.md +67 -3
  190. package/README.md +258 -129
  191. package/dist/checks/after/auth.js +10 -11
  192. package/dist/checks/after/ci-yml.js +11 -14
  193. package/dist/checks/after/github.js +32 -125
  194. package/dist/checks/after/index.js +3 -2
  195. package/dist/checks/after/managed.js +8 -24
  196. package/dist/checks/after/tools.js +3 -16
  197. package/dist/checks/before/context-fetch.js +1 -21
  198. package/dist/checks/before/index.js +6 -42
  199. package/dist/checks/before/mcp.js +14 -9
  200. package/dist/checks/before/repo.js +8 -11
  201. package/dist/checks/status-holes.js +5 -6
  202. package/dist/checks/tips/catalogue.js +60 -18
  203. package/dist/checks/tips/detect.js +41 -2
  204. package/dist/checks/tips/index.js +25 -5
  205. package/dist/cli.js +34 -14
  206. package/dist/commands/analysis.js +21 -5
  207. package/dist/commands/comply.js +20 -18
  208. package/dist/commands/harvest.js +12 -13
  209. package/dist/commands/install/doctor.js +55 -23
  210. package/dist/commands/install/install.js +62 -118
  211. package/dist/commands/install/uninstall.js +165 -31
  212. package/dist/commands/install/upgrade.js +55 -49
  213. package/dist/commands/lib.js +32 -10
  214. package/dist/commands/tips.js +6 -3
  215. package/dist/commands/workflow/branches.js +57 -13
  216. package/dist/commands/workflow/counters.js +17 -7
  217. package/dist/commands/workflow/fids.js +39 -0
  218. package/dist/commands/workflow/ledgers.js +3 -1
  219. package/dist/commands/workflow/prs.js +3 -3
  220. package/dist/commands/workflow/repo.js +16 -4
  221. package/dist/commands/workflow/roadmap.js +4 -4
  222. package/dist/commands/workflow/runs.js +5 -5
  223. package/dist/commands/workflow/steps.js +1 -0
  224. package/dist/commands/workflow/tests.js +16 -3
  225. package/dist/commands/workflow/workflows.js +19 -18
  226. package/dist/commands/workflow/workstreams.js +2 -1
  227. package/dist/commands/workflow/worktrees.js +4 -5
  228. package/dist/install/cloud-env.js +10 -23
  229. package/dist/install/manifest.js +14 -7
  230. package/dist/install/modules/antigravity.js +15 -26
  231. package/dist/install/modules/claude.js +17 -21
  232. package/dist/install/modules/cloud.js +6 -2
  233. package/dist/install/modules/codex.js +15 -29
  234. package/dist/install/modules/core.js +82 -63
  235. package/dist/install/modules/cursor.js +6 -9
  236. package/dist/install/modules/index.js +6 -1
  237. package/dist/install/modules/opencode.js +41 -72
  238. package/dist/install/network-allowlist.js +62 -0
  239. package/dist/install/placeholders.js +3 -16
  240. package/dist/install/write.js +55 -15
  241. package/dist/ledgers/telemetry.js +5 -4
  242. package/dist/render/hosts.js +30 -55
  243. package/dist/render/models.js +20 -9
  244. package/dist/shared/bkit-latest.js +150 -0
  245. package/dist/shared/branches.js +11 -0
  246. package/dist/shared/egress.js +0 -2
  247. package/dist/shared/json.js +14 -0
  248. package/dist/shared/package-json.js +61 -0
  249. package/dist/shared/package-roots.js +0 -8
  250. package/dist/shared/protected-paths.js +5 -122
  251. package/dist/shared/settings.js +18 -1
  252. package/dist/shared/timeouts.js +6 -0
  253. package/package.json +21 -17
  254. package/.bkit/core/.agents/shortcuts.md +0 -73
@@ -6,14 +6,9 @@ import * as fs from "node:fs";
6
6
  import * as path from "node:path";
7
7
  import { execFileSync } from "node:child_process";
8
8
  import type { PreflightFinding } from "../before/index.js";
9
- import {
10
- parseIssueTracker,
11
- DEFAULT_ISSUE_TRACKER,
12
- type IssueTracker,
13
- parseCloudAgents,
14
- DEFAULT_CLOUD_AGENTS,
15
- type CloudAgents,
16
- } from "../../install/manifest.js";
9
+ import { MCP_TOOLSETS_HEADER, parseToolsets } from "../../install/write.js";
10
+ import { parseJson, readJsonFile } from "../../shared/json.js";
11
+ import { readBkitConfig } from "../../shared/settings.js";
17
12
  import type { TokenPresence } from "./auth.js";
18
13
 
19
14
  /**
@@ -56,7 +51,9 @@ export function detectActionsWritePermissions(): TokenPresence {
56
51
  stdio: ["ignore", "pipe", "pipe"],
57
52
  timeout: 5000,
58
53
  });
59
- const parsed = JSON.parse(out) as {
54
+ const response = parseJson(out);
55
+ if (!response.ok) return "unknown";
56
+ const parsed = response.value as {
60
57
  default_workflow_permissions?: string;
61
58
  can_approve_pull_request_reviews?: boolean;
62
59
  };
@@ -68,23 +65,6 @@ export function detectActionsWritePermissions(): TokenPresence {
68
65
  }
69
66
  }
70
67
 
71
- /**
72
- * Read `bkit.issueTracker` from the consumer's package.json.
73
- * Returns the tracker value or the default ("none") when absent / unreadable.
74
- */
75
- export function readConsumerIssueTracker(cwd: string): IssueTracker {
76
- const pkgPath = path.join(cwd, "package.json");
77
- if (!fs.existsSync(pkgPath)) return DEFAULT_ISSUE_TRACKER;
78
- try {
79
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
80
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
81
- const parsed = parseIssueTracker(bkitField?.issueTracker);
82
- return parsed ?? DEFAULT_ISSUE_TRACKER;
83
- } catch {
84
- return DEFAULT_ISSUE_TRACKER;
85
- }
86
- }
87
-
88
68
  /**
89
69
  * Emit a tracker-specific setup advisory.
90
70
  *
@@ -99,7 +79,7 @@ export function buildTrackerSetupAdvisory(cwd: string): PreflightFinding | null
99
79
  const hasCursor = fs.existsSync(path.join(cwd, ".cursor"));
100
80
  if (!hasClaude && !hasCursor) return null;
101
81
 
102
- const tracker = readConsumerIssueTracker(cwd);
82
+ const { issueTracker: tracker, issueTrackerExplicit } = readBkitConfig(cwd);
103
83
 
104
84
  if (tracker === "github") {
105
85
  return {
@@ -125,7 +105,7 @@ export function buildTrackerSetupAdvisory(cwd: string): PreflightFinding | null
125
105
  // tracker === "none". Distinguish opt-out (explicit `bkit.issueTracker: "none"`)
126
106
  // from undecided (field absent). An explicit `none` silences the nudge, as with the
127
107
  // dep-updater advisory.
128
- if (hasExplicitIssueTrackerField(cwd)) return null;
108
+ if (issueTrackerExplicit) return null;
129
109
 
130
110
  return {
131
111
  id: "tracker-setup-none",
@@ -137,19 +117,6 @@ export function buildTrackerSetupAdvisory(cwd: string): PreflightFinding | null
137
117
  };
138
118
  }
139
119
 
140
- /** True when package.json has an explicit `bkit.issueTracker` field (any value). */
141
- function hasExplicitIssueTrackerField(cwd: string): boolean {
142
- const pkgPath = path.join(cwd, "package.json");
143
- if (!fs.existsSync(pkgPath)) return false;
144
- try {
145
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
146
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
147
- return bkitField !== undefined && bkitField.issueTracker !== undefined;
148
- } catch {
149
- return false;
150
- }
151
- }
152
-
153
120
  /**
154
121
  * Classify the `bkit.githubProject` board-sync config in package.json:
155
122
  * - "configured" → object with at least `owner` + `number` (the lookup keys)
@@ -157,21 +124,10 @@ function hasExplicitIssueTrackerField(cwd: string): boolean {
157
124
  * - "absent" → missing, malformed, or unreadable
158
125
  */
159
126
  function readGithubProjectConfig(cwd: string): "configured" | "opted-out" | "absent" {
160
- const pkgPath = path.join(cwd, "package.json");
161
- if (!fs.existsSync(pkgPath)) return "absent";
162
- try {
163
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
164
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
165
- const gp = bkitField?.githubProject;
166
- if (gp === false) return "opted-out";
167
- if (gp && typeof gp === "object" && !Array.isArray(gp)) {
168
- const obj = gp as Record<string, unknown>;
169
- if (obj.owner !== undefined && obj.number !== undefined) return "configured";
170
- }
171
- return "absent";
172
- } catch {
173
- return "absent";
174
- }
127
+ const gp = readBkitConfig(cwd).githubProject;
128
+ if (gp === false) return "opted-out";
129
+ if (gp !== null && gp.owner !== undefined && gp.number !== undefined) return "configured";
130
+ return "absent";
175
131
  }
176
132
 
177
133
  /**
@@ -182,27 +138,20 @@ function readGithubProjectConfig(cwd: string): "configured" | "opted-out" | "abs
182
138
  * (installs predating the toolset addition)
183
139
  * - "unknown" → no `.mcp.json`, no github server, or no header (can't judge)
184
140
  *
185
- * Scoped to root `.mcp.json` only — bkit omits the header from `.cursor/mcp.json`.
141
+ * Scoped to root `.mcp.json` only.
186
142
  */
187
143
  export function detectProjectsToolset(cwd: string): TokenPresence {
188
144
  const mcpPath = path.join(cwd, ".mcp.json");
189
145
  if (!fs.existsSync(mcpPath)) return "unknown";
190
- try {
191
- const cfg = JSON.parse(fs.readFileSync(mcpPath, "utf-8")) as Record<string, unknown>;
192
- const servers = cfg.mcpServers as Record<string, unknown> | undefined;
193
- const gh = servers?.github as Record<string, unknown> | undefined;
194
- const headers = gh?.headers as Record<string, unknown> | undefined;
195
- const toolsets = headers?.["X-MCP-Toolsets"];
196
- if (typeof toolsets !== "string") return "unknown";
197
- return toolsets
198
- .split(",")
199
- .map((s) => s.trim())
200
- .includes("projects")
201
- ? "present"
202
- : "missing";
203
- } catch {
204
- return "unknown";
205
- }
146
+ const cfg = readJsonFile(mcpPath);
147
+ if (!cfg.ok || typeof cfg.value !== "object" || cfg.value === null) return "unknown";
148
+ const servers = (cfg.value as Record<string, unknown>).mcpServers as
149
+ Record<string, unknown> | undefined;
150
+ const gh = servers?.github as Record<string, unknown> | undefined;
151
+ const headers = gh?.headers as Record<string, unknown> | undefined;
152
+ const toolsets = headers?.[MCP_TOOLSETS_HEADER];
153
+ if (typeof toolsets !== "string") return "unknown";
154
+ return parseToolsets(toolsets).includes("projects") ? "present" : "missing";
206
155
  }
207
156
 
208
157
  /**
@@ -221,7 +170,7 @@ export function buildGithubProjectAdvisory(cwd: string): PreflightFinding | null
221
170
  const hasClaude = fs.existsSync(path.join(cwd, ".claude"));
222
171
  const hasCursor = fs.existsSync(path.join(cwd, ".cursor"));
223
172
  if (!hasClaude && !hasCursor) return null;
224
- if (readConsumerIssueTracker(cwd) !== "github") return null;
173
+ if (readBkitConfig(cwd).issueTracker !== "github") return null;
225
174
 
226
175
  const configState = readGithubProjectConfig(cwd);
227
176
  if (configState === "opted-out") return null;
@@ -259,7 +208,7 @@ export function buildGithubProjectAdvisory(cwd: string): PreflightFinding | null
259
208
  "and must NOT be used for `statusFieldId` — `projects_write` rejects it with " +
260
209
  "`updated_field.id: value must be a number`.\n\n" +
261
210
  "2. Ensure the root `.mcp.json` github server enables the `projects` toolset:\n\n" +
262
- ' "X-MCP-Toolsets": "context,issues,pull_requests,repos,users,projects"\n\n' +
211
+ ' "X-MCP-Toolsets": "context,issues,pull_requests,repos,users,projects,actions"\n\n' +
263
212
  "3. The `BKIT_GH_TOKEN` PAT needs organization-scoped Projects read & write (repo scope is not enough).\n\n" +
264
213
  "To opt out and silence this advisory, set `bkit.githubProject` to `false` in package.json.",
265
214
  };
@@ -282,19 +231,9 @@ export function detectGithubProjectFieldIdFormat(cwd: string): PreflightFinding
282
231
  const hasClaude = fs.existsSync(path.join(cwd, ".claude"));
283
232
  const hasCursor = fs.existsSync(path.join(cwd, ".cursor"));
284
233
  if (!hasClaude && !hasCursor) return null;
285
- if (readConsumerIssueTracker(cwd) !== "github") return null;
234
+ const { issueTracker, githubProject: gp } = readBkitConfig(cwd);
235
+ if (issueTracker !== "github") return null;
286
236
 
287
- const pkgPath = path.join(cwd, "package.json");
288
- if (!fs.existsSync(pkgPath)) return null;
289
- let gp: Record<string, unknown> | undefined;
290
- try {
291
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
292
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
293
- const raw = bkitField?.githubProject;
294
- if (raw && typeof raw === "object" && !Array.isArray(raw)) gp = raw as Record<string, unknown>;
295
- } catch {
296
- return null;
297
- }
298
237
  // Only judge a board that is otherwise configured (owner + number present) and
299
238
  // has a statusFieldId set — absent statusFieldId is handled by the setup advisory.
300
239
  if (!gp || gp.owner === undefined || gp.number === undefined) return null;
@@ -322,36 +261,6 @@ export function detectGithubProjectFieldIdFormat(cwd: string): PreflightFinding
322
261
  };
323
262
  }
324
263
 
325
- /**
326
- * Read `bkit.cloudAgents` from the consumer's package.json. Returns the value
327
- * or the default ("none") when absent / unreadable.
328
- */
329
- export function readConsumerCloudAgents(cwd: string): CloudAgents {
330
- const pkgPath = path.join(cwd, "package.json");
331
- if (!fs.existsSync(pkgPath)) return DEFAULT_CLOUD_AGENTS;
332
- try {
333
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
334
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
335
- const parsed = parseCloudAgents(bkitField?.cloudAgents);
336
- return parsed ?? DEFAULT_CLOUD_AGENTS;
337
- } catch {
338
- return DEFAULT_CLOUD_AGENTS;
339
- }
340
- }
341
-
342
- /** True when package.json has an explicit `bkit.cloudAgents` field (any value). */
343
- function hasExplicitCloudAgentsField(cwd: string): boolean {
344
- const pkgPath = path.join(cwd, "package.json");
345
- if (!fs.existsSync(pkgPath)) return false;
346
- try {
347
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
348
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
349
- return bkitField !== undefined && bkitField.cloudAgents !== undefined;
350
- } catch {
351
- return false;
352
- }
353
- }
354
-
355
264
  /**
356
265
  * Emit a cloud-agents setup advisory (parity with the tracker / dep-updater
357
266
  * advisories). Post-CI auto-routing (`bkit-cloud.yml`) is opt-in via
@@ -379,8 +288,7 @@ export function buildCloudSetupAdvisory(cwd: string): PreflightFinding | null {
379
288
  // Config-consistency assertion: cloud=claude requires id-token: write.
380
289
  // If the recorded variant is "claude" and the workflow file lacks id-token: write,
381
290
  // surface a consistency finding.
382
- const recordedVariant = readConsumerCloudAgents(cwd);
383
- if (recordedVariant === "claude") {
291
+ if (readBkitConfig(cwd).cloudAgents === "claude") {
384
292
  const workflowContent = fs.readFileSync(routerPath, "utf-8");
385
293
  if (!workflowContent.includes("id-token: write")) {
386
294
  return {
@@ -404,7 +312,8 @@ export function buildCloudSetupAdvisory(cwd: string): PreflightFinding | null {
404
312
  }
405
313
 
406
314
  // No router present — distinguish opt-out from undecided.
407
- if (readConsumerCloudAgents(cwd) === "none" && hasExplicitCloudAgentsField(cwd)) {
315
+ const { cloudAgents, cloudAgentsExplicit } = readBkitConfig(cwd);
316
+ if (cloudAgents === "none" && cloudAgentsExplicit) {
408
317
  return null; // consumer explicitly chose `none` — stay quiet
409
318
  }
410
319
 
@@ -12,6 +12,7 @@ import {
12
12
  detectDirenvNotAllowed,
13
13
  } from "../before/env.js";
14
14
  import { getPkgRoot } from "../../shared/package-roots.js";
15
+ import { readBkitConfig } from "../../shared/settings.js";
15
16
  import { detectOpencodeYmlProviderDrift } from "../../install/modules/opencode.js";
16
17
  import { detectManagedDuplicate, detectManagedStale } from "./managed.js";
17
18
  import { buildCloudDashboardsAdvisory, detectCiRouterSecrets, detectGhMcpToken } from "./auth.js";
@@ -22,7 +23,6 @@ import {
22
23
  detectActionsWritePermissions,
23
24
  detectGithubProjectFieldIdFormat,
24
25
  detectMainBranchProtection,
25
- readConsumerIssueTracker,
26
26
  } from "./github.js";
27
27
  import {
28
28
  buildDepUpdaterSetupAdvisory,
@@ -489,7 +489,7 @@ export function runPostInstallCheck(
489
489
  // writes, so Phase 1 cannot see it on first install.
490
490
  // Pass the consumer's tracker so the mcp-env prose omits BKIT_LINEAR_API_KEY on github/none
491
491
  // repos.
492
- const mcpEnvTracker = readConsumerIssueTracker(cwd);
492
+ const mcpEnvTracker = readBkitConfig(cwd).issueTracker;
493
493
  const missingDotenv = detectMissingDotenv(cwd, mcpEnvTracker);
494
494
  if (missingDotenv) phase3.push(missingDotenv);
495
495
  phase3.push(...detectBlankDotenvKeys(cwd, mcpEnvTracker));
@@ -8,7 +8,8 @@ import type { PreflightFinding } from "../before/index.js";
8
8
  import type { ModuleFlag } from "../../cli.js";
9
9
  import { getModuleManifest } from "../../install/manifest.js";
10
10
  import { readManagedVersion } from "../../install/version-file.js";
11
- import { getPkgRoot } from "../../shared/package-roots.js";
11
+ import { isSharedBranch } from "../../shared/branches.js";
12
+ import { readInstallingVersion } from "../../shared/package-json.js";
12
13
  import {
13
14
  detectMarkerStyle,
14
15
  extractManagedBlock,
@@ -18,26 +19,7 @@ import {
18
19
  stripManagedBlock,
19
20
  } from "../../install/managed-block.js";
20
21
  import { listStampedFiles } from "../../install/modules/index.js";
21
-
22
- // ---------------------------------------------------------------------------
23
- // detectManagedStale — managed-version marker gate over every stamped file
24
- // ---------------------------------------------------------------------------
25
-
26
- /**
27
- * Best-effort read of the installing bkit version from the package root.
28
- * Mirrors getInstallingVersion (commands/install/install.ts) / readInstallingVersion
29
- * (install/modules/index.ts); kept local to avoid a postinstall → install/modules import.
30
- */
31
- function readPkgVersion(): string {
32
- try {
33
- const pkg = JSON.parse(fs.readFileSync(path.join(getPkgRoot(), "package.json"), "utf-8")) as {
34
- version?: string;
35
- };
36
- return pkg.version ?? "0.0.0";
37
- } catch {
38
- return "0.0.0";
39
- }
40
- }
22
+ import { gitEnv } from "../../ledgers/telemetry.js";
41
23
 
42
24
  // ---------------------------------------------------------------------------
43
25
  // Branch-scoped severity for the stale gates
@@ -47,9 +29,6 @@ function readPkgVersion(): string {
47
29
  // INTO main/dev re-asserts the blocker (via GITHUB_BASE_REF).
48
30
  // ---------------------------------------------------------------------------
49
31
 
50
- /** Branches where a stale managed-version marker is a hard blocker, not a warning. */
51
- const PROTECTED_BRANCHES = new Set(["main", "dev"]);
52
-
53
32
  /**
54
33
  * Resolve the branch the check is effectively gating, preferring the CI signal:
55
34
  * 1. `GITHUB_BASE_REF` — set on `pull_request` events to the MERGE TARGET. A PR
@@ -67,6 +46,7 @@ function currentBranch(cwd: string): string | null {
67
46
  // not a thrown error needing a swallowing catch — null then means "undeterminable".
68
47
  const r = spawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
69
48
  cwd,
49
+ env: gitEnv(),
70
50
  encoding: "utf-8",
71
51
  stdio: ["ignore", "pipe", "ignore"],
72
52
  });
@@ -82,7 +62,7 @@ function currentBranch(cwd: string): string | null {
82
62
  export function isOnProtectedBranch(cwd: string = process.cwd()): boolean {
83
63
  const b = currentBranch(cwd);
84
64
  if (b === null) return true; // undeterminable → fail safe to blocker
85
- return PROTECTED_BRANCHES.has(b);
65
+ return isSharedBranch(b);
86
66
  }
87
67
 
88
68
  /**
@@ -122,16 +102,16 @@ export function readManagedBlockVersion(content: string): string | null | undefi
122
102
  *
123
103
  * A block-scoped file without a bkit block is the consumer's (they dropped the block, or
124
104
  * never had bkit's) and is skipped; a whole file without a marker is stale. Files absent
125
- * on disk are skipped. A dev tree without a readable package version (`0.0.0` / empty)
105
+ * on disk are skipped. An installing version of `0.0.0` or empty (an unreleased tree)
126
106
  * yields null, as does a repo with nothing stamped.
127
107
  *
128
- * Severity is branch-scoped (see PROTECTED_BRANCHES): a `blocker` on main/dev (or a PR
108
+ * Severity is branch-scoped (see isSharedBranch): a `blocker` on main/dev (or a PR
129
109
  * into them), an `advisory` on feature branches. `installingVersion` and
130
110
  * `onProtectedBranch` are injected for testability.
131
111
  */
132
112
  export function detectManagedStale(
133
113
  cwd: string,
134
- installingVersion: string = readPkgVersion(),
114
+ installingVersion: string = readInstallingVersion(),
135
115
  onProtectedBranch: boolean = isOnProtectedBranch(cwd),
136
116
  ): PreflightFinding | null {
137
117
  if (!installingVersion || installingVersion === "0.0.0") return null;
@@ -5,6 +5,7 @@ import * as fs from "node:fs";
5
5
  import * as path from "node:path";
6
6
  import { spawnSync } from "node:child_process";
7
7
  import type { PreflightFinding } from "../before/index.js";
8
+ import { readBkitConfig } from "../../shared/settings.js";
8
9
 
9
10
  /** True when `cmd --version` runs (binary on PATH, exits 0). */
10
11
  function toolVersionRuns(cmd: string): boolean {
@@ -147,7 +148,7 @@ const BKIT_STUBS: BkitStub[] = [
147
148
  id: "coverage",
148
149
  file: ".github/workflows/bkit-ci.yml",
149
150
  description:
150
- "Report vitest coverage on PRs via davelosert/vitest-coverage-report-action (free, runs inside Actions with GITHUB_TOKEN — no third-party service, safe for private repos). PER-TIER: unit and integration are measured and commented SEPARATELY (a single merged number lets integration mask a hollow unit suite — coverage is a union). Report-only by default: nothing fails the build until a threshold is set. Enabling (documented in the stub header): (1) add `@vitest/coverage-v8` (pinned to your vitest major) plus a vitest.config coverage block with `reporter: ['text','json-summary','json']` and `reportOnFailure: true` — json-summary + json are load-bearing (the action reads coverage-summary.json and coverage-final.json); (2) run coverage TWICE into separate dirs — unit → coverage/unit (exclude integration files), integration → coverage/integration — so each tier gets its own honest number (avoids the last-writer-wins clobber a second same-dir run would cause); (3) add a JOB-LEVEL permissions block to bkit-tests-unit with `actions: read` + `contents: read` + `pull-requests: write` — job-level REPLACES the workflow-level block (not additive) and the Check SHA Cache step needs `actions: read`, so omitting it breaks the cache step; (4) two report steps with distinct `name:` (unit / integration) pointing at each dir's coverage-summary.json + coverage-final.json. SEPARATE LANES (one job per tier): put the integration run + report + its OWN pull-requests: write block in bkit-tests-integration, not bkit-tests-unit — each lane posts its own comment. Thresholds are opt-in and PER TIER: UNIT is the gate — pass `--coverage.thresholds.branches` as a CLI flag on the unit run ONLY (vitest coverage is per-RUN/root config, NOT per-project — `projects` does not scope it and a config `thresholds` block reds BOTH runs; a per-run flag cannot leak to integration; branches is the meaningful floor, set to current and ratchet up). INTEGRATION is REPORT-ONLY — gate it on EXECUTION (the capstone's integration_ran > 0), not a %: a whole-repo integration % is denominator-noise (it covers boundaries/flows, not pure logic). For a real integration %, add `--coverage.include=src/server/**` on the integration run (same CLI-flag idiom as --exclude) then set a floor, or ratchet from current — never a picked number. Fork PRs: GITHUB_TOKEN is read-only, so keep the `head.repo == repo` guard on the steps (or use the action's workflow_run two-workflow pattern). Guard the integration report on `hashFiles('coverage/integration/coverage-summary.json') != ''` so a repo with no integration tier skips it cleanly.",
151
+ "Report vitest coverage on PRs and in every run's job summary via davelosert/vitest-coverage-report-action (free, runs inside Actions with GITHUB_TOKEN — no third-party service, safe for private repos). PER-TIER: unit and integration are measured and commented SEPARATELY (a single merged number lets integration mask a hollow unit suite — coverage is a union). Report-only by default: nothing fails the build until a threshold is set. Enabling (documented in the stub header): (1) add `@vitest/coverage-v8` (pinned to your vitest major) plus a vitest.config coverage block with `reporter: ['text','json-summary','json']` and `reportOnFailure: true` — json-summary + json are load-bearing (the action reads coverage-summary.json and coverage-final.json); (2) run coverage TWICE into separate dirs — unit → coverage/unit (exclude integration files), integration → coverage/integration — so each tier gets its own honest number (avoids the last-writer-wins clobber a second same-dir run would cause); (3) add a JOB-LEVEL permissions block to bkit-tests-unit with `actions: read` + `contents: read` + `pull-requests: write` — job-level REPLACES the workflow-level block (not additive) and the Check SHA Cache step needs `actions: read`, so omitting it breaks the cache step; (4) two report steps with distinct `name:` (unit / integration) pointing at each dir's coverage-summary.json + coverage-final.json; the unit step runs on every event (`if: !cancelled()` plus a `hashFiles` guard on its summary), sets `vite-config-path: vitest.unit.config.ts` so the job summary and PR comment show the floor as the target, and comments only on same-repo PRs (`comment-on: pr`, else `none`). SEPARATE LANES (one job per tier): put the integration run + report + its OWN pull-requests: write block in bkit-tests-integration, not bkit-tests-unit — each lane posts its own comment. Thresholds are opt-in and PER TIER: UNIT is the gate — put `coverage.thresholds.branches` in a `vitest.unit.config.ts` (`mergeConfig` over vitest.config) that ONLY the unit run loads via `-c` (vitest coverage is per-RUN/root config, NOT per-project — `projects` does not scope it and a `thresholds` block in vitest.config reds BOTH runs; the report action reads the same file as raw text, so keep the floor on one unquoted `branches: <n>` line and no other metric name + colon + number in it; branches is the meaningful floor, set to current and ratchet up). INTEGRATION is REPORT-ONLY — gate it on EXECUTION (the capstone's integration_ran > 0), not a %: a whole-repo integration % is denominator-noise (it covers boundaries/flows, not pure logic). For a real integration %, add `--coverage.include=src/server/**` on the integration run (same CLI-flag idiom as --exclude) then set a floor, or ratchet from current — never a picked number. Fork PRs: GITHUB_TOKEN is read-only, so the unit step sets `comment-on: none` there (its job summary still lands) and the integration step keeps the `head.repo == repo` guard (or use the action's workflow_run two-workflow pattern). Guard the integration report on `hashFiles('coverage/integration/coverage-summary.json') != ''` so a repo with no integration tier skips it cleanly.",
151
152
  },
152
153
  {
153
154
  id: "e2e-coverage",
@@ -376,19 +377,6 @@ function updaterConfigPaths(cwd: string): { renovate: string | null; dependabot:
376
377
  return { renovate, dependabot };
377
378
  }
378
379
 
379
- /** `bkit.depUpdater: "none"` silences the missing-updater suggestion. Other values are ignored. */
380
- function depUpdaterOptOut(cwd: string): boolean {
381
- const pkgPath = path.join(cwd, "package.json");
382
- if (!fs.existsSync(pkgPath)) return false;
383
- try {
384
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
385
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
386
- return bkitField?.depUpdater === "none";
387
- } catch {
388
- return false;
389
- }
390
- }
391
-
392
380
  /**
393
381
  * Read-only dependency-updater check.
394
382
  *
@@ -411,7 +399,7 @@ export function buildDepUpdaterSetupAdvisory(cwd: string): PreflightFinding | nu
411
399
  }
412
400
 
413
401
  if (renovate || dependabot) return null;
414
- if (depUpdaterOptOut(cwd)) return null;
402
+ if (readBkitConfig(cwd).depUpdaterOptOut) return null;
415
403
  if (!fs.existsSync(path.join(cwd, ".github", "workflows"))) return null;
416
404
 
417
405
  return {
@@ -4,7 +4,7 @@
4
4
  import * as fs from "node:fs";
5
5
  import * as path from "node:path";
6
6
  import { getTemplatesRoot } from "../../shared/package-roots.js";
7
- import { readPackageJson } from "../../shared/package-json.js";
7
+ import { readDependencyNames } from "../../shared/package-json.js";
8
8
  import type { PreflightFinding } from "./index.js";
9
9
 
10
10
  /**
@@ -104,26 +104,6 @@ const CONTEXT_FETCH_BACKEND_EVIDENCE: Record<string, (cwd: string) => boolean> =
104
104
  readDependencyNames(cwd).includes("vercel"),
105
105
  };
106
106
 
107
- /** Every dependency name across the four package.json dependency fields. */
108
- function readDependencyNames(cwd: string): string[] {
109
- const read = readPackageJson(cwd);
110
- if (!read.ok) return [];
111
- const pkg = read.pkg;
112
- const names: string[] = [];
113
- for (const field of [
114
- "dependencies",
115
- "devDependencies",
116
- "optionalDependencies",
117
- "peerDependencies",
118
- ]) {
119
- const deps = pkg[field];
120
- if (deps && typeof deps === "object") {
121
- names.push(...Object.keys(deps as Record<string, unknown>));
122
- }
123
- }
124
- return names;
125
- }
126
-
127
107
  /**
128
108
  * Advisory: consumer's `.agents/context.md` has the bkit-managed block but no
129
109
  * `<!-- context-fetch:start <name> --> ... <!-- context-fetch:end -->` block AFTER
@@ -7,18 +7,14 @@
7
7
  // deepContains — from install/write.ts (JSON containment primitive)
8
8
  // extractManagedBlock — from install/managed-block.ts (marker block extraction)
9
9
  // findTemplateSource — from shared/package-roots.ts (dest → payload source, the dotfile remap)
10
- // parseIssueTracker — from install/manifest.ts (pure data, no cycle)
10
+ // readBkitConfig — from shared/settings.ts (the consumer's `bkit` settings)
11
+ // readInstallingVersion — from shared/package-json.ts (the version of the bkit doing the install)
11
12
  // readTemplate — from render/parts.ts (template with its shared parts spliced in)
12
13
 
13
- import * as fs from "node:fs";
14
- import * as path from "node:path";
15
14
  import type { ModuleFlag } from "../../cli.js";
16
- import { getPkgRoot } from "../../shared/package-roots.js";
17
- import {
18
- parseIssueTracker,
19
- DEFAULT_ISSUE_TRACKER,
20
- type IssueTracker,
21
- } from "../../install/manifest.js";
15
+ import { readInstallingVersion } from "../../shared/package-json.js";
16
+ import type { IssueTracker } from "../../install/manifest.js";
17
+ import { readBkitConfig } from "../../shared/settings.js";
22
18
  import {
23
19
  detectBkitNotOnPath,
24
20
  detectMalformedPackageJson,
@@ -70,24 +66,6 @@ export function dedupeById(findings: PreflightFinding[]): PreflightFinding[] {
70
66
  // runPreflight — main Phase 1 entry point
71
67
  // ---------------------------------------------------------------------------
72
68
 
73
- /**
74
- * Read `bkit.issueTracker` from the consumer's package.json.
75
- * Returns the tracker value or the default ("none") when absent / unreadable.
76
- * Internal helper — not exported; use runPreflight's `issueTracker` param.
77
- */
78
- function readConsumerIssueTrackerForPreflight(cwd: string): IssueTracker {
79
- const pkgPath = path.join(cwd, "package.json");
80
- if (!fs.existsSync(pkgPath)) return DEFAULT_ISSUE_TRACKER;
81
- try {
82
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
83
- const bkitField = pkg.bkit as Record<string, unknown> | undefined;
84
- const parsed = parseIssueTracker(bkitField?.issueTracker);
85
- return parsed ?? DEFAULT_ISSUE_TRACKER;
86
- } catch {
87
- return DEFAULT_ISSUE_TRACKER;
88
- }
89
- }
90
-
91
69
  /**
92
70
  * Run all Phase 1 (read-only) detectors.
93
71
  * Returns deduplicated { blockers, advisories } — intra-phase dedup by id,
@@ -108,26 +86,12 @@ export function runPreflight(
108
86
  installingVersion?: string,
109
87
  issueTracker?: IssueTracker,
110
88
  ): { blockers: PreflightFinding[]; advisories: PreflightFinding[] } {
111
- // Resolve installing version if not provided
112
- let version = installingVersion;
113
- if (!version) {
114
- try {
115
- const pkgJsonPath = path.join(getPkgRoot(), "package.json");
116
- if (fs.existsSync(pkgJsonPath)) {
117
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")) as { version?: string };
118
- version = pkg.version ?? "0.0.0";
119
- } else {
120
- version = "0.0.0";
121
- }
122
- } catch {
123
- version = "0.0.0";
124
- }
125
- }
89
+ const version = installingVersion || readInstallingVersion();
126
90
 
127
91
  // Resolve issueTracker: use provided value or read from consumer package.json.
128
92
  // GitHub tracker gate: when issueTracker === "github", Linear preflight is a no-op
129
93
  // (the GitHub gate is enforced by workflow Step 1 via MCP — hook is no-op).
130
- const resolvedTracker = issueTracker ?? readConsumerIssueTrackerForPreflight(cwd);
94
+ const resolvedTracker = issueTracker ?? readBkitConfig(cwd).issueTracker;
131
95
 
132
96
  const blockers: PreflightFinding[] = [];
133
97
  const advisories: PreflightFinding[] = [];
@@ -89,15 +89,26 @@ export function detectMissingMcpServers(
89
89
  return findings;
90
90
  }
91
91
 
92
+ /**
93
+ * The bkit-written MCP servers `tracker` has no use for: `BKIT_MCP_SERVERS` minus the
94
+ * tracker's own server and `TRACKER_INDEPENDENT_MCP_SERVERS`. What `detectExtraMcpServers`
95
+ * flags, and what a tracker switch removes while the entry still equals bkit's template.
96
+ */
97
+ export function unusedTrackerMcpServers(tracker: IssueTracker): readonly string[] {
98
+ const allowed = requiredMcpServersForTracker(tracker);
99
+ return BKIT_MCP_SERVERS.filter(
100
+ (key) => !allowed.includes(key) && !TRACKER_INDEPENDENT_MCP_SERVERS.includes(key),
101
+ );
102
+ }
103
+
92
104
  /**
93
105
  * Advisory: one finding per bkit-written MCP server that is present in the file but NOT
94
106
  * required by the resolved tracker (the symmetric counterpart to `detectMissingMcpServers`).
95
- * Catches the stale-leftover case — e.g. a repo switched to `--tracker=github` but still
96
- * carrying the `linear` entry.
107
+ * Catches a leftover a tracker switch kept because the consumer edited it — e.g. a repo
108
+ * switched to `--tracker=github` still carrying a customised `linear` entry.
97
109
  *
98
- * Only flags tracker-only servers bkit itself writes (`BKIT_MCP_SERVERS` minus
99
- * `TRACKER_INDEPENDENT_MCP_SERVERS`). Consumer-added MCP servers (custom tooling, other
100
- * providers) are never flagged for removal.
110
+ * Only flags `unusedTrackerMcpServers(tracker)`. Consumer-added MCP servers (custom tooling,
111
+ * other providers) are never flagged for removal.
101
112
  *
102
113
  * `mapKey` names the server map: `mcpServers` (`.mcp.json`, `.cursor/mcp.json`) or `mcp`
103
114
  * (`.opencode/opencode.json`).
@@ -117,10 +128,8 @@ export function detectExtraMcpServers(
117
128
  const servers = readMcpServerMap(cwd, relPath, mapKey);
118
129
  if (!servers) return [];
119
130
 
120
- const allowed = requiredMcpServersForTracker(issueTracker);
121
131
  const findings: PreflightFinding[] = [];
122
- for (const key of BKIT_MCP_SERVERS) {
123
- if (allowed.includes(key) || TRACKER_INDEPENDENT_MCP_SERVERS.includes(key)) continue;
132
+ for (const key of unusedTrackerMcpServers(issueTracker)) {
124
133
  if (!Object.prototype.hasOwnProperty.call(servers, key)) continue;
125
134
  findings.push({
126
135
  id: `mcp-extra-server-${key}-${advisoryPathSlug(relPath)}`,
@@ -5,6 +5,7 @@ import * as fs from "node:fs";
5
5
  import * as path from "node:path";
6
6
  import { spawnSync } from "node:child_process";
7
7
  import type { ModuleFlag } from "../../cli.js";
8
+ import { readJsonFile } from "../../shared/json.js";
8
9
  import type { PreflightFinding } from "./index.js";
9
10
  import { isCloudOrCi } from "./env.js";
10
11
 
@@ -26,18 +27,14 @@ export function detectNoPackageJson(cwd: string): PreflightFinding | null {
26
27
  export function detectMalformedPackageJson(cwd: string): PreflightFinding | null {
27
28
  const pkgPath = path.join(cwd, "package.json");
28
29
  if (!fs.existsSync(pkgPath)) return null;
29
- try {
30
- JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
31
- return null;
32
- } catch {
33
- return {
34
- id: "malformed-package-json",
35
- severity: "blocker",
36
- detect: "package.json exists but contains invalid JSON.",
37
- action:
38
- "Fix the JSON syntax error in package.json (run `node -e \"JSON.parse(require('fs').readFileSync('package.json','utf8'))\"` to locate the error), then re-run `pnpm bkit install`.",
39
- };
40
- }
30
+ if (readJsonFile(pkgPath).ok) return null;
31
+ return {
32
+ id: "malformed-package-json",
33
+ severity: "blocker",
34
+ detect: "package.json exists but contains invalid JSON.",
35
+ action:
36
+ "Fix the JSON syntax error in package.json (run `node -e \"JSON.parse(require('fs').readFileSync('package.json','utf8'))\"` to locate the error), then re-run `pnpm bkit install`.",
37
+ };
41
38
  }
42
39
 
43
40
  export function detectNotGitRepo(cwd: string, modules: Set<ModuleFlag>): PreflightFinding | null {
@@ -27,6 +27,7 @@ import * as fs from "node:fs";
27
27
  import * as path from "node:path";
28
28
  import { fileURLToPath } from "node:url";
29
29
 
30
+ import { parseJson } from "../shared/json.js";
30
31
  import { getWorkflowsRoot } from "../shared/package-roots.js";
31
32
 
32
33
  // ---------------------------------------------------------------------------
@@ -344,11 +345,9 @@ export function auditStatusJsonl(statusJsonl: string, shipMd: string): HoleRepor
344
345
  for (const line of statusJsonl.split("\n")) {
345
346
  const trimmed = line.trim();
346
347
  if (!trimmed) continue;
347
- try {
348
- rows.push(JSON.parse(trimmed) as StatusRow);
349
- } catch (_e) {
350
- void _e; // skip unparseable lines (advisory — never throw)
351
- }
348
+ // Unparseable lines are skipped (advisory — never throw).
349
+ const row = parseJson(trimmed);
350
+ if (row.ok) rows.push(row.value as StatusRow);
352
351
  }
353
352
 
354
353
  // Filter to ship step-done rows + workflow-failed rows