@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
@@ -5,9 +5,13 @@ import * as fs from "node:fs";
5
5
  import * as path from "node:path";
6
6
  import { writeTier1, writeTier2, ensurePackageJsonScripts } from "../write.js";
7
7
  import { readBkitVersion, writeBkitVersion, hashFile, mergeCanonicalHashes, } from "../version-file.js";
8
+ import { extractManagedBlock, stripManagedBlock } from "../managed-block.js";
8
9
  import { listFilesRecursive, syncTemplateCopies } from "../template-copies.js";
9
10
  import { PAYLOAD_LINK_RELPATHS, syncPayloadLinks } from "../payload-links.js";
10
- import { getPkgRoot, getCoreRoot, getSharedRoot, getBkitDocsRoot, TEMPLATE_COPIES_DIR, } from "../../shared/package-roots.js";
11
+ import { writeNetworkAllowlist } from "../network-allowlist.js";
12
+ import { readJsonFile } from "../../shared/json.js";
13
+ import { readInstallingVersion } from "../../shared/package-json.js";
14
+ import { getCoreRoot, getSharedRoot, getBkitDocsRoot, TEMPLATE_COPIES_DIR, } from "../../shared/package-roots.js";
11
15
  import { getInstallManifest, BKIT_GATE_SCRIPTS, BKIT_OPTIONAL_GATES, BKIT_TEST_FILE_SCRIPT, } from "../manifest.js";
12
16
  export function listMdFiles(dir, prefix) {
13
17
  if (!fs.existsSync(dir))
@@ -47,36 +51,43 @@ const ORPHAN_PRUNE_DIRS = [
47
51
  ".claude/commands",
48
52
  ".cursor/agents",
49
53
  ".cursor/commands",
54
+ ".opencode/agents",
55
+ ".opencode/commands",
56
+ ".codex/agents",
57
+ ".agents/skills",
58
+ ".agents/plugins/bkit/agents",
59
+ ".agents/plugins/bkit/skills",
50
60
  ];
51
- export function removeOrphans(destDir, sourceFiles, dryRun, prefix) {
61
+ /**
62
+ * Removes entries of `destDir` that start with `prefix` and are absent from `sourceNames`
63
+ * (entry names as they appear in `destDir`). Returns the removed names; with `dryRun` it
64
+ * reports them without deleting. Throws for any `destDir` outside `ORPHAN_PRUNE_DIRS`.
65
+ */
66
+ export function removeOrphans(destDir, sourceNames, dryRun, prefix, options = {}) {
52
67
  const resolved = path.resolve(destDir);
53
68
  if (!ORPHAN_PRUNE_DIRS.some((d) => path.resolve(d) === resolved)) {
54
69
  throw new Error(`removeOrphans: refusing orphan removal outside allowlist: ${destDir}`);
55
70
  }
56
71
  if (!fs.existsSync(destDir))
57
72
  return [];
73
+ const { extension = ".md", wholeFolders = false } = options;
58
74
  const removed = [];
59
75
  for (const f of fs.readdirSync(destDir)) {
60
- if (!f.endsWith(".md"))
76
+ if (!wholeFolders && !f.endsWith(extension))
61
77
  continue;
62
78
  if (prefix && !f.startsWith(prefix))
63
79
  continue;
64
- if (!sourceFiles.has(f)) {
80
+ if (!sourceNames.has(f)) {
81
+ const target = path.join(destDir, f);
65
82
  if (!dryRun)
66
- fs.rmSync(path.join(destDir, f));
83
+ fs.rmSync(target, { recursive: wholeFolders, force: wholeFolders });
67
84
  removed.push(f);
68
85
  }
69
86
  }
70
87
  return removed;
71
88
  }
72
89
  /** The markered-text `.agents/*.md` blocks core owns. */
73
- const CORE_AGENT_FILES = [
74
- "context.md",
75
- "docs.md",
76
- "rules.md",
77
- "shortcuts.md",
78
- "skills.md",
79
- ];
90
+ const CORE_AGENT_FILES = ["context.md", "docs.md", "rules.md", "skills.md"];
80
91
  // The two shared-root files core writes: stored in `shared/`, owned by the core
81
92
  // manifest, written as html-comment managed blocks.
82
93
  const CORE_SHARED_FILES = [
@@ -171,16 +182,18 @@ function runCoreTemplates(dryRun, tokens, ws, logPrefix) {
171
182
  // mirrored into the consumer's `.bkit/` on every install so a consumer can read them
172
183
  // in-repo without spelunking node_modules. Force-overwritten (Tier 1) — bkit owns
173
184
  // them, so a consumer edit is replaced. Source of truth is the package's own
174
- // `.bkit/core/.bkit/<name>`. (`advisories.md` is a regenerated runtime artifact,
175
- // `wording.md` is repo-only tooling and `friction.md` is a consumer-owned seed —
176
- // none belongs here. `LICENSE.md` is the MIT notice that travels with the files bkit
177
- // writes: MIT requires the copyright and permission notice in every copy.)
185
+ // `.bkit/core/.bkit/<name>`. (`advisories.md` is a regenerated runtime artifact and
186
+ // `wording.md` is repo-only tooling — neither belongs here. `LICENSE.md` is the MIT
187
+ // notice that travels with the files bkit writes: MIT requires the copyright and
188
+ // permission notice in every copy.)
178
189
  export const BKIT_CANONICAL_DOCS = [
179
190
  "cloud.md",
180
191
  "comparison.md",
181
192
  "install.md",
182
193
  "jsonl.md",
183
194
  "LICENSE.md",
195
+ "lite.md",
196
+ "pipeline.md",
184
197
  "providers.md",
185
198
  "prompts.md",
186
199
  "templates.md",
@@ -217,6 +230,43 @@ export function runBkitDocs(dryRun, tokens, ws, logPrefix) {
217
230
  console.log(`${logPrefix} ${tag}core: ${dstPath}`);
218
231
  }
219
232
  }
233
+ migrateShortcutsToLite(dryRun, ws, logPrefix);
234
+ }
235
+ // Migration (5.1.0 – 5.2.4 installs, `docs/migrations.md`): the lite workflows lived at
236
+ // `.agents/shortcuts.md`. The consumer's own lines below `bkit:end` (minus the seeded
237
+ // heading) move under `.bkit/lite.md`'s consumer section; the old file is deleted. Runs
238
+ // after the docs loop, so `.bkit/lite.md` is already written. The delete is recorded in
239
+ // ws (as orphan-mirror deletes are) so `bkit check` fails until upgrade runs.
240
+ const RETIRED_SHORTCUTS = path.join(".agents", "shortcuts.md");
241
+ const RETIRED_SHORTCUTS_HEADING = "## Project Shortcuts";
242
+ export function migrateShortcutsToLite(dryRun, ws, logPrefix) {
243
+ if (!fs.existsSync(RETIRED_SHORTCUTS))
244
+ return;
245
+ if (!fs.existsSync(path.join(getBkitDocsRoot(), "lite.md")))
246
+ return;
247
+ const tag = dryRun ? "[dry-run] " : "";
248
+ const dst = path.join(".bkit", "lite.md");
249
+ const old = fs.readFileSync(RETIRED_SHORTCUTS, "utf-8");
250
+ if (extractManagedBlock(old, "html-comment") === null) {
251
+ console.warn(`${logPrefix} ${RETIRED_SHORTCUTS} has no single bkit managed block — left in place. Move your own lines into ${dst} below \`<!-- bkit:end -->\`, then delete it.`);
252
+ return;
253
+ }
254
+ const own = stripManagedBlock(old, "html-comment")
255
+ .split("\n")
256
+ .filter((line) => line.trim() !== RETIRED_SHORTCUTS_HEADING)
257
+ .join("\n")
258
+ .trim();
259
+ if (own.length > 0) {
260
+ if (!dryRun) {
261
+ const current = fs.readFileSync(dst, "utf-8");
262
+ fs.writeFileSync(dst, `${current.replace(/\n*$/, "\n\n")}${own}\n`, "utf-8");
263
+ }
264
+ ws.writes.push({ path: dst, action: "update" });
265
+ }
266
+ if (!dryRun)
267
+ fs.rmSync(RETIRED_SHORTCUTS);
268
+ ws.writes.push({ path: RETIRED_SHORTCUTS, action: "write" });
269
+ console.log(`${logPrefix} ${tag}core: moved ${RETIRED_SHORTCUTS} → ${dst}`);
220
270
  }
221
271
  // ---------------------------------------------------------------------------
222
272
  // Source-rendered host outputs — agents (.agents/prompts source) and commands
@@ -229,28 +279,6 @@ export function runBkitDocs(dryRun, tokens, ws, logPrefix) {
229
279
  // (installFile does not touch ws), matching the install path exactly. Each returns
230
280
  // the consumer-relative dest paths it wrote (for the upgrade summary).
231
281
  // ---------------------------------------------------------------------------
232
- // ---------------------------------------------------------------------------
233
- // Managed-version stamping. The marker shape (stampManagedVersion + regexes) lives
234
- // in install/version-file.ts, shared by the renderer and the `bkit check` detector. Here we
235
- // only resolve WHICH version to stamp: ctx.version (set by install/upgrade) with a
236
- // package-root fallback.
237
- // ---------------------------------------------------------------------------
238
- /**
239
- * Best-effort read of the installing bkit version from the package root's
240
- * package.json. Mirrors getInstallingVersion in commands/install/install.ts; duplicated here
241
- * (not imported) to avoid a modules → install dependency cycle. Returns "0.0.0"
242
- * when unreadable — the same non-fatal fallback the install side uses.
243
- */
244
- export function readInstallingVersion() {
245
- try {
246
- const pkgPath = path.join(getPkgRoot(), "package.json");
247
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
248
- return pkg.version ?? "0.0.0";
249
- }
250
- catch {
251
- return "0.0.0";
252
- }
253
- }
254
282
  /** Record a host mirror would-write so `bkit check` exits 1 on content drift. */
255
283
  export function trackMirrorWrite(ctx, relPath, written) {
256
284
  written.push(relPath);
@@ -298,16 +326,13 @@ const PNPM_NOT_A_SCRIPT = new Set([
298
326
  * package.json yields none.
299
327
  */
300
328
  export function detectGateAdvisories(cwd) {
301
- let declared;
302
- try {
303
- const pkg = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf-8"));
304
- declared = { ...BKIT_GATE_SCRIPTS, ...pkg.scripts };
305
- }
306
- catch {
307
- // Absent or malformed package.json — preflight's no-package-json /
308
- // malformed-package-json blockers already report it.
329
+ const read = readJsonFile(path.join(cwd, "package.json"));
330
+ // Absent or malformed package.json — preflight's no-package-json /
331
+ // malformed-package-json blockers already report it.
332
+ if (!read.ok || read.value === null)
309
333
  return [];
310
- }
334
+ const pkg = read.value;
335
+ const declared = { ...BKIT_GATE_SCRIPTS, ...pkg.scripts };
311
336
  const findings = [];
312
337
  // Every script a seeded gate default chains MUST exist, or the gate dies on the first
313
338
  // missing one and the workflow reads that as a real failure. Checked only where the
@@ -379,15 +404,12 @@ export function isNoopScript(value) {
379
404
  * every branch. Read-only; an absent or unparseable package.json yields none.
380
405
  */
381
406
  export function detectNoopGates(cwd) {
382
- let declared;
383
- try {
384
- const pkg = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf-8"));
385
- declared = pkg.scripts ?? {};
386
- }
387
- catch {
388
- // Absent or malformed package.json — preflight's blockers already report it.
407
+ const read = readJsonFile(path.join(cwd, "package.json"));
408
+ // Absent or malformed package.json — preflight's blockers already report it.
409
+ if (!read.ok || read.value === null)
389
410
  return [];
390
- }
411
+ const pkg = read.value;
412
+ const declared = pkg.scripts ?? {};
391
413
  const noop = Object.entries(declared)
392
414
  .filter(([name, value]) => name.startsWith("bkit:gate:") && typeof value === "string")
393
415
  .filter(([, value]) => isNoopScript(value))
@@ -408,13 +430,7 @@ export function runCoreModule(ctx) {
408
430
  const { dryRun, ws, advisories, logPrefix, postDispatch } = ctx;
409
431
  const tag = dryRun ? "[dry-run] " : "";
410
432
  const cwd = process.cwd();
411
- const PKG_ROOT = getPkgRoot();
412
- const PKG_PACKAGE_JSON = path.join(PKG_ROOT, "package.json");
413
- if (!fs.existsSync(PKG_PACKAGE_JSON)) {
414
- console.error(`${logPrefix} package.json not found at ${PKG_PACKAGE_JSON} — package corrupt?`);
415
- process.exit(1);
416
- }
417
- const pkgVersion = JSON.parse(fs.readFileSync(PKG_PACKAGE_JSON, "utf-8")).version;
433
+ const pkgVersion = readInstallingVersion();
418
434
  // Capture first-install signal NOW (before any writes) — used for the post-install banner.
419
435
  // The .bkit/version write happens in postDispatch, so a mid-install crash in a later
420
436
  // module leaves no .bkit/version on disk.
@@ -425,7 +441,7 @@ export function runCoreModule(ctx) {
425
441
  console.log(`${logPrefix} ${tag}Running core payload pass`);
426
442
  runCoreTemplates(dryRun, ctx.tokens, ws, logPrefix);
427
443
  // 3b. bkit canonical docs pass — mirror the package's reference docs
428
- // (cloud/IDEs/prompts/trackers/workflows/README/install/comparison) into the
444
+ // (cloud/IDEs/prompts/trackers/workflows/README/install/comparison/pipeline) into the
429
445
  // consumer's `.bkit/` so they are readable in-repo. Force-overwrite (Tier 1).
430
446
  console.log(`${logPrefix} ${tag}Running bkit docs pass`);
431
447
  runBkitDocs(dryRun, ctx.tokens, ws, logPrefix);
@@ -465,6 +481,9 @@ export function runCoreModule(ctx) {
465
481
  action: `Browse-only — bkit reads its payload from the package regardless. To add the view by hand on POSIX: ln -s ../node_modules/@cbartens/bkit/${rel} ${rel}`,
466
482
  });
467
483
  }
484
+ // 3b4. `.bkit/allowlist.json` — the network allowlist every host's guardrails hook
485
+ // reads (writeNetworkAllowlist), plus the move off the retired `.cursor/` copy.
486
+ writeNetworkAllowlist(cwd, dryRun, ws, logPrefix);
468
487
  // 3c. The bkit:gate:* / bkit:deps:* package.json scripts (add-if-missing). The
469
488
  // advisories read the result.
470
489
  seedCorePackageJsonScripts(ctx);
@@ -7,8 +7,9 @@ import { applyT1, applyT2, applyT3 } from "../../render/hosts.js";
7
7
  import { getCoreRoot, getSharedRoot, getWorkflowsRoot, getPromptsRoot, } from "../../shared/package-roots.js";
8
8
  import { DEFAULT_ISSUE_TRACKER } from "../manifest.js";
9
9
  import { substituteWorkflow } from "../../render/trackers.js";
10
- import { writeCursorCloudDoc, writeNetworkAllowlistArtifact, writeCursorCliPermissionsArtifact, } from "../cloud-env.js";
11
- import { BKIT_PREFIX, installFile, listMdFiles, readInstallingVersion, removeOrphans, trackMirrorWrite, } from "./core.js";
10
+ import { writeCursorCloudDoc, writeCursorCliPermissionsArtifact } from "../cloud-env.js";
11
+ import { readInstallingVersion } from "../../shared/package-json.js";
12
+ import { BKIT_PREFIX, installFile, listMdFiles, removeOrphans, trackMirrorWrite } from "./core.js";
12
13
  import { reconcileMcpJson } from "./claude.js";
13
14
  export function renderCursorAgentsCommands(ctx) {
14
15
  const { dryRun, modelLookup, effortMap, logPrefix } = ctx;
@@ -143,15 +144,11 @@ export function runCursorModule(ctx) {
143
144
  }
144
145
  }
145
146
  }
146
- // Cursor-only runtime curl/wget allowlist (bkit-guardrails.cjs reads `.cursor/allowlist.json`).
147
- // Same domain set as Claude WebFetch / OpenCode bash allows — sourced from tooling
148
- // defaults ∪ consumer `allowed-domains`. Not under `.bkit/` (IDE-scoped artifact).
149
147
  // Cursor CLI / cloud-agent MCP allows (`.cursor/cli.json`) from consumer `mcp-servers` —
150
148
  // same server set as Claude `mcp__…` allows / OpenCode `<server>_*` permission rows.
151
- for (const art of [
152
- writeNetworkAllowlistArtifact(process.cwd(), dryRun),
153
- writeCursorCliPermissionsArtifact(process.cwd(), dryRun),
154
- ]) {
149
+ // The curl/wget allowlist the guardrails hook reads is core's `.bkit/allowlist.json`.
150
+ {
151
+ const art = writeCursorCliPermissionsArtifact(process.cwd(), dryRun);
155
152
  if (art.wrote) {
156
153
  ws.writes.push({ path: art.path, action: "write" });
157
154
  console.log(`${logPrefix} ${tag}cursor: ${art.path}`);
@@ -8,6 +8,7 @@ import * as fs from "node:fs";
8
8
  import * as path from "node:path";
9
9
  import { getCoreRoot, getSharedRoot } from "../../shared/package-roots.js";
10
10
  import { getInstallManifest } from "../manifest.js";
11
+ import { writeNetworkAllowlist } from "../network-allowlist.js";
11
12
  import { BKIT_PREFIX, listCoreTemplateFiles, listSharedTemplateFiles, runBkitDocs, runCoreModule, seedCorePackageJsonScripts, } from "./core.js";
12
13
  import { renderClaudeAgentsCommands, runClaudeModule } from "./claude.js";
13
14
  import { renderCursorAgentsCommands, runCursorModule } from "./cursor.js";
@@ -19,7 +20,8 @@ import { runCloudModule } from "./cloud.js";
19
20
  // renderManagedOutputs — re-render the bkit-managed OUTPUT files that the
20
21
  // `bkit upgrade` payload walk does NOT cover:
21
22
  // host agents/commands (source-rendered), the `.bkit/*.md` canonical docs
22
- // (runBkitDocs) and core's package.json scripts (seedCorePackageJsonScripts).
23
+ // (runBkitDocs), `.bkit/allowlist.json` (writeNetworkAllowlist) and core's
24
+ // package.json scripts (seedCorePackageJsonScripts).
23
25
  // `.bkit/prompts.md` is markered → runBkitDocs block-merges it (managed block
24
26
  // refreshed, consumer `## Model Overrides` below bkit:end preserved).
25
27
  //
@@ -41,6 +43,9 @@ export function renderManagedOutputs(modules, ctx) {
41
43
  for (let i = docsBefore; i < ctx.ws.writes.length; i++) {
42
44
  written.push(String(ctx.ws.writes[i].path));
43
45
  }
46
+ // `.bkit/allowlist.json` — the same pass install's core module runs (writeNetworkAllowlist
47
+ // records into ctx.ws, so the caller refreshes its canonicalHashes).
48
+ written.push(...writeNetworkAllowlist(process.cwd(), ctx.dryRun, ctx.ws, ctx.logPrefix));
44
49
  // Core package.json scripts — the same pass install runs, so `bkit check` after a
45
50
  // clean upgrade finds no missing gate name and no superseded script value.
46
51
  written.push(...seedCorePackageJsonScripts(ctx));
@@ -2,7 +2,7 @@
2
2
  // the provider-templated `opencode.json`.
3
3
  import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
- import { writeTier2, deepMergeJson, ensureDir } from "../write.js";
5
+ import { writeTier2, deepMergeJson, ensureDir, isJsonObject, mergeTrackerEntry, } from "../write.js";
6
6
  import { stampManagedVersion } from "../version-file.js";
7
7
  import { applyOpencodeAgent, applyOpencodeCommand } from "../../render/hosts.js";
8
8
  import { getCoreRoot, getSharedRoot, getWorkflowsRoot, getPromptsRoot, } from "../../shared/package-roots.js";
@@ -10,8 +10,11 @@ import { DEFAULT_ISSUE_TRACKER } from "../manifest.js";
10
10
  import { substituteWorkflow } from "../../render/trackers.js";
11
11
  import { resolveNetworkAllowlist, extractMcpServers, networkAllowlistBases } from "../cloud-env.js";
12
12
  import { OPENCODE_PROVIDER_DEFAULTS } from "../../shared/egress.js";
13
- import { BKIT_PREFIX, installFile, listMdFiles, readInstallingVersion, trackMirrorWrite, } from "./core.js";
14
- import { opencodeProviderId } from "../../render/models.js";
13
+ import { parseJson, readJsonFile } from "../../shared/json.js";
14
+ import { readBkitConfig } from "../../shared/settings.js";
15
+ import { readInstallingVersion } from "../../shared/package-json.js";
16
+ import { BKIT_PREFIX, installFile, listMdFiles, removeOrphans, trackMirrorWrite } from "./core.js";
17
+ import { isOpencodeProvider, opencodeProviderId } from "../../render/models.js";
15
18
  export function renderOpencodeAgentsCommands(ctx) {
16
19
  const { dryRun, opencodeModelLookup, effortMap, opencodeProvider, logPrefix } = ctx;
17
20
  const tag = dryRun ? "[dry-run] " : "";
@@ -42,23 +45,11 @@ export function renderOpencodeAgentsCommands(ctx) {
42
45
  trackMirrorWrite(ctx, rel, written);
43
46
  }
44
47
  }
45
- // Remove orphan agent files (bkit-prefix only, no allowlist gate needed — .opencode/agents
46
- // is a dynamic mirror dir like .claude/agents and .cursor/agents). dryRun still reports
47
- // would-deletes into ws.writes so `bkit check` fails on stale mirrors.
48
- if (fs.existsSync(dest)) {
49
- for (const f of fs.readdirSync(dest)) {
50
- if (!f.endsWith(".md"))
51
- continue;
52
- if (!f.startsWith(BKIT_PREFIX))
53
- continue;
54
- if (!sourceSet.has(f)) {
55
- const rel = path.join(dest, f);
56
- if (!dryRun)
57
- fs.rmSync(path.join(dest, f));
58
- console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
59
- trackMirrorWrite(ctx, rel, written);
60
- }
61
- }
48
+ // dryRun still reports would-deletes into ws.writes so `bkit check` fails on stale mirrors.
49
+ for (const f of removeOrphans(dest, sourceSet, dryRun, BKIT_PREFIX)) {
50
+ const rel = path.join(dest, f);
51
+ console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
52
+ trackMirrorWrite(ctx, rel, written);
62
53
  }
63
54
  }
64
55
  // --- Commands: tracker substitution + applyOpencodeCommand ---
@@ -78,20 +69,10 @@ export function renderOpencodeAgentsCommands(ctx) {
78
69
  trackMirrorWrite(ctx, rel, written);
79
70
  }
80
71
  }
81
- if (fs.existsSync(dest)) {
82
- for (const f of fs.readdirSync(dest)) {
83
- if (!f.endsWith(".md"))
84
- continue;
85
- if (!f.startsWith(BKIT_PREFIX))
86
- continue;
87
- if (!sourceSet.has(f)) {
88
- const rel = path.join(dest, f);
89
- if (!dryRun)
90
- fs.rmSync(path.join(dest, f));
91
- console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
92
- trackMirrorWrite(ctx, rel, written);
93
- }
94
- }
72
+ for (const f of removeOrphans(dest, sourceSet, dryRun, BKIT_PREFIX)) {
73
+ const rel = path.join(dest, f);
74
+ console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
75
+ trackMirrorWrite(ctx, rel, written);
95
76
  }
96
77
  }
97
78
  return written;
@@ -118,7 +99,7 @@ export function renderOpencodeAgentsCommands(ctx) {
118
99
  * secret against the installed provider.
119
100
  */
120
101
  export function opencodeProviderEnvVar(providerKey) {
121
- return OPENCODE_PROVIDER_DEFAULTS[providerKey]?.envVar ?? "";
102
+ return isOpencodeProvider(providerKey) ? OPENCODE_PROVIDER_DEFAULTS[providerKey].envVar : "";
122
103
  }
123
104
  /**
124
105
  * Detect drift between the self-installed `.github/workflows/opencode.yml` reactive `/oc` handler
@@ -141,19 +122,8 @@ export function detectOpencodeYmlProviderDrift(cwd) {
141
122
  if (!fs.existsSync(ymlPath))
142
123
  return null;
143
124
  // The installed provider — package.json `bkit.opencodeProvider` is the authoritative record
144
- // written on install. Absent/broken → the null-guard below skips silently.
145
- let provider = null;
146
- const pkgPath = path.join(cwd, "package.json");
147
- if (fs.existsSync(pkgPath)) {
148
- try {
149
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
150
- if (typeof pkg.bkit?.opencodeProvider === "string")
151
- provider = pkg.bkit.opencodeProvider;
152
- }
153
- catch {
154
- // Malformed package.json — leave provider null; a JSON-drift advisory covers that separately.
155
- }
156
- }
125
+ // written on install. Absent/broken/unsupported → the null-guard below skips silently.
126
+ const provider = readBkitConfig(cwd).opencodeProvider;
157
127
  if (!provider)
158
128
  return null;
159
129
  const expectedPrefix = opencodeProviderId(provider); // model id form is `<providerId>/<model>`
@@ -222,10 +192,10 @@ export function renderOpencodeJson(templatePath, tracker, provider, cwd = proces
222
192
  const raw = fs.readFileSync(templatePath, "utf-8");
223
193
  // Strict allowlist: provider is gated to OPENCODE_PROVIDERS at the CLI, so it is always
224
194
  // a known key here. An unknown id throws; no substitute provider.
225
- const providerDefaults = OPENCODE_PROVIDER_DEFAULTS[provider];
226
- if (!providerDefaults) {
195
+ if (!isOpencodeProvider(provider)) {
227
196
  throw new Error(`renderOpencodeJson: unknown opencode provider ${JSON.stringify(provider)}`);
228
197
  }
198
+ const providerDefaults = OPENCODE_PROVIDER_DEFAULTS[provider];
229
199
  // Resolve tracker MCP entry
230
200
  // opencode's MCP schema differs from Claude/Cursor: remote servers use type "remote"
231
201
  // (NOT "http" — not in opencode's enum, which makes the whole config invalid) and read
@@ -237,7 +207,7 @@ export function renderOpencodeJson(templatePath, tracker, provider, cwd = proces
237
207
  let mcpEntry;
238
208
  if (tracker === "github") {
239
209
  mcpEntry =
240
- '"github": { "type": "remote", "url": "https://api.githubcopilot.com/mcp/", "oauth": false, "headers": { "Authorization": "Bearer {env:BKIT_GH_TOKEN}", "X-MCP-Toolsets": "context,issues,pull_requests,repos,users,projects" } }';
210
+ '"github": { "type": "remote", "url": "https://api.githubcopilot.com/mcp/", "oauth": false, "headers": { "Authorization": "Bearer {env:BKIT_GH_TOKEN}", "X-MCP-Toolsets": "context,issues,pull_requests,repos,users,projects,actions" } }';
241
211
  }
242
212
  else if (tracker === "linear") {
243
213
  mcpEntry = '"linear": { "type": "remote", "url": "https://mcp.linear.app/mcp" }';
@@ -251,7 +221,10 @@ export function renderOpencodeJson(templatePath, tracker, provider, cwd = proces
251
221
  rendered = rendered.replace(OPENCODE_PROVIDER_BASE_URL_SENTINEL, providerDefaults.baseURL);
252
222
  // Parse + re-serialize to normalise JSON (removes empty mcp entry if tracker=none)
253
223
  try {
254
- const parsed = JSON.parse(rendered);
224
+ const renderedDoc = parseJson(rendered);
225
+ if (!renderedDoc.ok)
226
+ return rendered;
227
+ const parsed = renderedDoc.value;
255
228
  // Clean up empty mcp object when tracker=none
256
229
  const mcp = parsed.mcp;
257
230
  if (mcp && Object.keys(mcp).length === 0) {
@@ -350,20 +323,22 @@ export function reconcileOpencodeJson(renderedTemplate, relDst, dryRun, ws) {
350
323
  ws.writes.push({ path: relDst, action: "write" });
351
324
  return;
352
325
  }
353
- // Parse into a sentinel and validate AFTER the catch — keeping the throw out of the catch
354
- // body (matches the codebase's parse-or-sentinel idiom; a throw inside catch obscures the
355
- // original error). Malformed consumer JSON is a hard stop: refuse to merge, require a fix.
356
- let existing = null;
357
- try {
358
- existing = JSON.parse(fs.readFileSync(relDst, "utf-8"));
359
- }
360
- catch {
361
- existing = null;
362
- }
326
+ // Malformed consumer JSON is a hard stop: refuse to merge, require a fix.
327
+ const read = readJsonFile(relDst);
328
+ const existing = read.ok ? read.value : null;
363
329
  if (existing === null) {
364
330
  throw new Error(`[bkit] ${relDst} is malformed JSON — fix manually before running bkit install`);
365
331
  }
366
332
  const merged = deepMergeJson(existing, template);
333
+ // The tracker `mcp` entry keeps the consumer's extra toolsets (`mergeTrackerEntry`), which
334
+ // the plain merge above would overwrite with the template's list.
335
+ const tmplMcp = template.mcp;
336
+ const existingMcp = existing.mcp;
337
+ if (isJsonObject(tmplMcp) && isJsonObject(existingMcp) && isJsonObject(merged.mcp)) {
338
+ for (const [k, v] of Object.entries(tmplMcp)) {
339
+ merged.mcp[k] = mergeTrackerEntry(existingMcp[k], v);
340
+ }
341
+ }
367
342
  // Replace (do not deep-merge) each provider key the template seeds — heals hijacked
368
343
  // npm/baseURL/name while keeping other provider keys additive.
369
344
  //
@@ -411,14 +386,8 @@ export function reconcileOpencodeJson(renderedTemplate, relDst, dryRun, ws) {
411
386
  export function removeOpencodeProviderBlock(dst, providerKey, dryRun, ws) {
412
387
  if (!fs.existsSync(dst))
413
388
  return;
414
- // Parse-or-sentinel idiom: keep the early-return outside the catch body.
415
- let existing = null;
416
- try {
417
- existing = JSON.parse(fs.readFileSync(dst, "utf-8"));
418
- }
419
- catch {
420
- existing = null;
421
- }
389
+ const read = readJsonFile(dst);
390
+ const existing = read.ok ? read.value : null;
422
391
  if (existing === null) {
423
392
  console.warn(`[bkit] ${dst} is malformed — leaving as-is`);
424
393
  return;
@@ -494,7 +463,7 @@ export function runOpencodeModule(ctx) {
494
463
  detect: `opencode host installed (provider: ${provider}). The opencode CLI and your provider credentials are required before running agents.`,
495
464
  action: `opencode setup for provider "${provider}":\n\n` +
496
465
  (() => {
497
- const pd = OPENCODE_PROVIDER_DEFAULTS[provider];
466
+ const pd = isOpencodeProvider(provider) ? OPENCODE_PROVIDER_DEFAULTS[provider] : undefined;
498
467
  if (!pd) {
499
468
  return (` 1. Set ${provider.toUpperCase()}_API_KEY in your environment / .bkit/.env.\n` +
500
469
  ` 2. Update .opencode/opencode.json provider.${provider}.options.baseURL for your endpoint.\n`);
@@ -518,7 +487,7 @@ export function runOpencodeModule(ctx) {
518
487
  ` env — {env:KEY} placeholders in opencode.json resolve empty without this. Quit the\n` +
519
488
  ` running app first (a running instance ignores the new env).\n` +
520
489
  ` 4. Model IDs: all four providers (openrouter, ollama, opencode-zen, opencode-go) install ready-to-run curated per-agent pins. ` +
521
- `Re-pin any agent via .bkit/prompts.md § Model Overrides or by probing the provider's live /v1/models — see .bkit/providers.md § Models. NOTE: ollama opus/convergent pins (kimi-k2.7-code, deepseek-v4-pro) need a paid Ollama plan; its sonnet/haiku pins run on the free tier. opencode-go pins (minimax-m3, qwen3.7-plus, deepseek-v4-pro/-flash) — prefer pins that stay within the Go 5h usage window; opencode-zen pins are existence-validated via models.dev (the /zen/v1/models REST probe cannot see Go-only models — models.dev is the source of truth).\n` +
490
+ `Re-pin any agent via .bkit/prompts.md § Model Overrides or by probing the provider's live /v1/models — see .bkit/providers.md § Models. NOTE: every ollama pin (deepseek-v4.1-flash, kimi-k3) needs a paid Ollama plan. opencode-go pins (deepseek-v4.1-flash, kimi-k3) — prefer pins that stay within the Go 5h usage window; opencode-zen pins are existence-validated via models.dev (the /zen/v1/models REST probe cannot see Go-only models — models.dev is the source of truth).\n` +
522
491
  ` 5. Verify with: \`bkit doctor\` (credentials + tools) and \`bkit status\` (installed hosts + providers).`,
523
492
  });
524
493
  }
@@ -0,0 +1,62 @@
1
+ // install/network-allowlist.ts — `.bkit/allowlist.json`, the resolved network allowlist
2
+ // (shipped egress registry ∪ consumer `allowed-domains`) the guardrails hooks of Claude,
3
+ // Cursor, Codex and Antigravity read at runtime to host-check shell curl / wget. Core
4
+ // owns it: install (runCoreModule) and upgrade (renderManagedOutputs) both write it, so
5
+ // it exists for every host that reads it and `bkit check` reports it missing or stale.
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+ import { resolveNetworkAllowlist } from "./cloud-env.js";
9
+ import { readBkitVersion } from "./version-file.js";
10
+ /** Consumer-relative path of the install-written curl/wget allowlist. */
11
+ export const NETWORK_ALLOWLIST_RELPATH = path.join(".bkit", "allowlist.json");
12
+ /** Where the cursor module wrote the allowlist up to 5.2.4 (migrated away). */
13
+ export const RETIRED_NETWORK_ALLOWLIST_RELPATH = path.join(".cursor", "allowlist.json");
14
+ /** The allowlist file body: `{ domains }`, apex + `*.` wildcard per base, sorted. */
15
+ export function renderNetworkAllowlist(cwd) {
16
+ return JSON.stringify({ domains: resolveNetworkAllowlist(cwd) }, null, 2) + "\n";
17
+ }
18
+ /**
19
+ * Write `.bkit/allowlist.json` whole (hand edits do not survive — `allowed-domains` in
20
+ * `.agents/context.md` is the source), then migrate the retired copy. Every change is
21
+ * recorded in `ws` under dry-run too, so `bkit check` fails until install / upgrade runs.
22
+ * Returns the consumer-relative paths changed.
23
+ */
24
+ export function writeNetworkAllowlist(cwd, dryRun, ws, logPrefix) {
25
+ const tag = dryRun ? "[dry-run] " : "";
26
+ const changed = [];
27
+ const abs = path.join(cwd, NETWORK_ALLOWLIST_RELPATH);
28
+ const body = renderNetworkAllowlist(cwd);
29
+ const prev = fs.existsSync(abs) ? fs.readFileSync(abs, "utf-8") : null;
30
+ if (prev !== body) {
31
+ if (!dryRun) {
32
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
33
+ fs.writeFileSync(abs, body, "utf-8");
34
+ }
35
+ ws.writes.push({ path: NETWORK_ALLOWLIST_RELPATH, action: prev === null ? "write" : "update" });
36
+ changed.push(NETWORK_ALLOWLIST_RELPATH);
37
+ console.log(`${logPrefix} ${tag}core: ${NETWORK_ALLOWLIST_RELPATH}`);
38
+ }
39
+ if (migrateRetiredNetworkAllowlist(cwd, dryRun)) {
40
+ ws.writes.push({ path: RETIRED_NETWORK_ALLOWLIST_RELPATH, action: "write" });
41
+ changed.push(RETIRED_NETWORK_ALLOWLIST_RELPATH);
42
+ console.log(`${logPrefix} ${tag}core: removed ${RETIRED_NETWORK_ALLOWLIST_RELPATH} (moved to ${NETWORK_ALLOWLIST_RELPATH})`);
43
+ }
44
+ return changed;
45
+ }
46
+ /**
47
+ * Migration (installs up to 5.2.4, `docs/migrations.md`): delete `.cursor/allowlist.json`
48
+ * when `.bkit/version` records its hash — bkit wrote it and owned it whole. A file bkit
49
+ * never recorded is left alone. Returns whether the file is (or, under dry-run, would be)
50
+ * removed. The stale hash entry is pruned by the `.bkit/version` writer.
51
+ */
52
+ function migrateRetiredNetworkAllowlist(cwd, dryRun) {
53
+ const abs = path.join(cwd, RETIRED_NETWORK_ALLOWLIST_RELPATH);
54
+ if (!fs.existsSync(abs))
55
+ return false;
56
+ const hashes = readBkitVersion(path.join(cwd, ".bkit", "version"))?.canonicalHashes ?? {};
57
+ if (hashes[RETIRED_NETWORK_ALLOWLIST_RELPATH] === undefined)
58
+ return false;
59
+ if (!dryRun)
60
+ fs.rmSync(abs);
61
+ return true;
62
+ }
@@ -1,22 +1,9 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { execSync } from "node:child_process";
4
- import { getPkgRoot } from "../shared/package-roots.js";
4
+ import { readInstallingVersion } from "../shared/package-json.js";
5
5
  import { managedVersionMarker } from "./version-file.js";
6
6
  import { gitEnv, resolveRepoSlug } from "../ledgers/telemetry.js";
7
- // Read the INSTALLING bkit version from the package root (NOT the consumer's
8
- // package.json — that is a different version). Mirrors readInstallingVersion
9
- // (install/modules/index.ts) / readPkgVersion (checks/after/index.ts); kept local to avoid a
10
- // tokens → modules import cycle. "0.0.0" on any read failure.
11
- function readInstallingBkitVersion() {
12
- try {
13
- const pkg = JSON.parse(fs.readFileSync(path.join(getPkgRoot(), "package.json"), "utf-8"));
14
- return pkg.version ?? "0.0.0";
15
- }
16
- catch {
17
- return "0.0.0";
18
- }
19
- }
20
7
  // Resolve DEFAULT_BRANCH: git symbolic-ref refs/remotes/origin/HEAD → "main"
21
8
  function resolveDefaultBranch(cwd) {
22
9
  try {
@@ -58,7 +45,7 @@ export async function resolveTokens(cwd) {
58
45
  DEFAULT_BRANCH: resolveDefaultBranch(cwd),
59
46
  PROJECT_NAME: name.trim(),
60
47
  REPO_SLUG: resolveRepoSlug(cwd),
61
- BKIT_VERSION: readInstallingBkitVersion(),
48
+ BKIT_VERSION: readInstallingVersion(),
62
49
  };
63
50
  }
64
51
  // Substitute {{TOKEN}} placeholders in content string.
@@ -78,7 +65,7 @@ export function applyTokens(content, tokens) {
78
65
  // so `# {{BKIT_MANAGED_MARKER}}` yields the hash form. The version is read from the
79
66
  // package only when the token is present and the TokenMap omits BKIT_VERSION.
80
67
  if (out.includes("{{BKIT_MANAGED_MARKER}}")) {
81
- const version = tokens.BKIT_VERSION ?? readInstallingBkitVersion();
68
+ const version = tokens.BKIT_VERSION ?? readInstallingVersion();
82
69
  out = out
83
70
  .replace(/^\/\/ \{\{BKIT_MANAGED_MARKER\}\}/gm, () => managedVersionMarker(version, "slash"))
84
71
  .replace(/\{\{BKIT_MANAGED_MARKER\}\}/g, () => managedVersionMarker(version, "html"));