@cbartens/bkit 5.5.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/.bkit/README.md +30 -20
  2. package/.bkit/core/.agents/docs.md +1 -0
  3. package/.bkit/core/.agents/rules.md +35 -26
  4. package/.bkit/core/.bkit/README.md +29 -19
  5. package/.bkit/core/.bkit/authoring.md +117 -0
  6. package/.bkit/core/.bkit/cloud.md +11 -11
  7. package/.bkit/core/.bkit/comparison.md +5 -5
  8. package/.bkit/core/.bkit/install.md +19 -18
  9. package/.bkit/core/.bkit/jsonl.md +202 -122
  10. package/.bkit/core/.bkit/lite.md +1 -1
  11. package/.bkit/core/.bkit/pipeline.md +49 -52
  12. package/.bkit/core/.bkit/prompts.md +91 -167
  13. package/.bkit/core/.bkit/providers.md +29 -32
  14. package/.bkit/core/.bkit/templates.md +12 -11
  15. package/.bkit/core/.bkit/trackers.md +51 -28
  16. package/.bkit/core/.bkit/workflows.md +394 -355
  17. package/.bkit/core/AGENTS.md +16 -22
  18. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +14 -38
  19. package/.bkit/core/docs/templates/bkit-audit-adoption.md +16 -40
  20. package/.bkit/core/docs/templates/bkit-audit-agents.md +19 -43
  21. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +16 -40
  22. package/.bkit/core/docs/templates/bkit-audit-analytics.md +14 -38
  23. package/.bkit/core/docs/templates/bkit-audit-annotations.md +11 -35
  24. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +15 -39
  25. package/.bkit/core/docs/templates/bkit-audit-app-store.md +12 -36
  26. package/.bkit/core/docs/templates/bkit-audit-architecture.md +16 -40
  27. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +16 -40
  28. package/.bkit/core/docs/templates/bkit-audit-config.md +18 -42
  29. package/.bkit/core/docs/templates/bkit-audit-cost.md +16 -40
  30. package/.bkit/core/docs/templates/bkit-audit-coverage.md +15 -39
  31. package/.bkit/core/docs/templates/bkit-audit-database.md +16 -40
  32. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +15 -39
  33. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +15 -38
  34. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +16 -40
  35. package/.bkit/core/docs/templates/bkit-audit-documentation.md +11 -35
  36. package/.bkit/core/docs/templates/bkit-audit-duplication.md +18 -42
  37. package/.bkit/core/docs/templates/bkit-audit-failures.md +13 -37
  38. package/.bkit/core/docs/templates/bkit-audit-flakes.md +12 -36
  39. package/.bkit/core/docs/templates/bkit-audit-gates.md +14 -38
  40. package/.bkit/core/docs/templates/bkit-audit-issues.md +15 -39
  41. package/.bkit/core/docs/templates/bkit-audit-llm.md +16 -40
  42. package/.bkit/core/docs/templates/bkit-audit-logs.md +14 -38
  43. package/.bkit/core/docs/templates/bkit-audit-models.md +12 -36
  44. package/.bkit/core/docs/templates/bkit-audit-privacy.md +12 -36
  45. package/.bkit/core/docs/templates/bkit-audit-prompts.md +15 -39
  46. package/.bkit/core/docs/templates/bkit-audit-red-team.md +15 -39
  47. package/.bkit/core/docs/templates/bkit-audit-reliability.md +15 -39
  48. package/.bkit/core/docs/templates/bkit-audit-repo.md +12 -36
  49. package/.bkit/core/docs/templates/bkit-audit-security.md +13 -37
  50. package/.bkit/core/docs/templates/bkit-audit-slop.md +14 -38
  51. package/.bkit/core/docs/templates/bkit-audit-testing.md +12 -36
  52. package/.bkit/core/docs/templates/bkit-audit-usability.md +16 -40
  53. package/.bkit/core/docs/templates/bkit-plan.md +97 -226
  54. package/.bkit/core/engine/checks/after/ci-yml.ts +39 -29
  55. package/.bkit/core/engine/checks/after/github.ts +95 -17
  56. package/.bkit/core/engine/checks/after/index.ts +10 -7
  57. package/.bkit/core/engine/checks/after/suppression.ts +8 -5
  58. package/.bkit/core/engine/checks/after/tools.ts +46 -91
  59. package/.bkit/core/engine/checks/before/env.ts +2 -2
  60. package/.bkit/core/engine/checks/before/files.ts +5 -4
  61. package/.bkit/core/engine/checks/before/index.ts +18 -1
  62. package/.bkit/core/engine/checks/before/repo.ts +168 -2
  63. package/.bkit/core/engine/checks/tips/catalogue.ts +16 -5
  64. package/.bkit/core/engine/checks/tips/detect.ts +34 -0
  65. package/.bkit/core/engine/checks/tips/index.ts +6 -6
  66. package/.bkit/core/engine/cli.ts +20 -53
  67. package/.bkit/core/engine/commands/analysis.ts +171 -140
  68. package/.bkit/core/engine/commands/ci/ci.ts +6 -6
  69. package/.bkit/core/engine/commands/comply.ts +77 -103
  70. package/.bkit/core/engine/commands/install/doctor.ts +2 -2
  71. package/.bkit/core/engine/commands/install/install.ts +57 -18
  72. package/.bkit/core/engine/commands/install/uninstall.ts +65 -28
  73. package/.bkit/core/engine/commands/land.ts +18 -12
  74. package/.bkit/core/engine/commands/lib.ts +79 -17
  75. package/.bkit/core/engine/commands/registry.ts +4 -0
  76. package/.bkit/core/engine/commands/setup/setup.ts +7 -7
  77. package/.bkit/core/engine/commands/stats.ts +204 -0
  78. package/.bkit/core/engine/commands/tips.ts +10 -5
  79. package/.bkit/core/engine/commands/workflow/branches.ts +741 -62
  80. package/.bkit/core/engine/commands/workflow/challenge.ts +673 -0
  81. package/.bkit/core/engine/commands/workflow/context.ts +853 -29
  82. package/.bkit/core/engine/commands/workflow/counters.ts +267 -84
  83. package/.bkit/core/engine/commands/workflow/decisions.ts +541 -0
  84. package/.bkit/core/engine/commands/workflow/disk.ts +2 -2
  85. package/.bkit/core/engine/commands/workflow/fids.ts +793 -33
  86. package/.bkit/core/engine/commands/workflow/issues.ts +407 -64
  87. package/.bkit/core/engine/commands/workflow/ledgers.ts +884 -27
  88. package/.bkit/core/engine/commands/workflow/locks.ts +26 -2
  89. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +582 -0
  90. package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
  91. package/.bkit/core/engine/commands/workflow/prs.ts +166 -30
  92. package/.bkit/core/engine/commands/workflow/repo.ts +58 -8
  93. package/.bkit/core/engine/commands/workflow/roadmap.ts +16 -7
  94. package/.bkit/core/engine/commands/workflow/run-facts.ts +501 -0
  95. package/.bkit/core/engine/commands/workflow/runs.ts +179 -49
  96. package/.bkit/core/engine/commands/workflow/runtime.ts +22 -1
  97. package/.bkit/core/engine/commands/workflow/status.ts +142 -29
  98. package/.bkit/core/engine/commands/workflow/step-table.ts +339 -0
  99. package/.bkit/core/engine/commands/workflow/steps.ts +213 -88
  100. package/.bkit/core/engine/commands/workflow/summary.ts +398 -0
  101. package/.bkit/core/engine/commands/workflow/tests.ts +1013 -148
  102. package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
  103. package/.bkit/core/engine/commands/workflow/workflows.ts +984 -207
  104. package/.bkit/core/engine/commands/workflow/workstreams.ts +11 -5
  105. package/.bkit/core/engine/commands/workflow/worktrees.ts +185 -8
  106. package/.bkit/core/engine/install/manifest.ts +11 -9
  107. package/.bkit/core/engine/install/modules/cloud.ts +21 -13
  108. package/.bkit/core/engine/install/modules/core.ts +250 -3
  109. package/.bkit/core/engine/install/modules/opencode.ts +2 -2
  110. package/.bkit/core/engine/install/version-file.ts +6 -2
  111. package/.bkit/core/engine/ledgers/migrate.ts +92 -0
  112. package/.bkit/core/engine/ledgers/status.ts +92 -15
  113. package/.bkit/core/engine/ledgers/telemetry.ts +1261 -254
  114. package/.bkit/core/engine/render/hosts.ts +4 -0
  115. package/.bkit/core/engine/render/models.ts +12 -0
  116. package/.bkit/core/engine/shared/branches.ts +4 -1
  117. package/.bkit/core/engine/shared/egress.ts +7 -0
  118. package/.bkit/core/engine/shared/json.ts +25 -7
  119. package/.bkit/core/engine/shared/settings.ts +157 -20
  120. package/.bkit/core/engine/shared/text.ts +361 -0
  121. package/.bkit/core/engine/tools/grammar-density.ts +215 -0
  122. package/.bkit/core/engine/tools/instructions-sources.ts +834 -0
  123. package/.bkit/core/engine/tools/instructions.ts +1751 -0
  124. package/.bkit/core/hooks/gateguard-engine.js +24 -23
  125. package/.bkit/core/hooks/guardrails-shell.js +2 -3
  126. package/.bkit/core/hooks/guardrails-tiers.js +7 -1
  127. package/.bkit/core/hooks/readguard-engine.js +2 -2
  128. package/.bkit/core/prompts/bkit-audit-generate.md +62 -25
  129. package/.bkit/core/prompts/bkit-build-challenge-1.md +40 -17
  130. package/.bkit/core/prompts/bkit-build-challenge-2.md +44 -17
  131. package/.bkit/core/prompts/bkit-build-install-skills.md +26 -13
  132. package/.bkit/core/prompts/bkit-build-plan-convert.md +74 -0
  133. package/.bkit/core/prompts/bkit-build-plan-current.md +26 -13
  134. package/.bkit/core/prompts/bkit-build-plan-execute.md +74 -26
  135. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +64 -23
  136. package/.bkit/core/prompts/bkit-build-plan-verify.md +57 -33
  137. package/.bkit/core/prompts/bkit-debug-abort-handover.md +29 -15
  138. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +34 -14
  139. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +34 -17
  140. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +26 -13
  141. package/.bkit/core/prompts/bkit-debug-failure-soak.md +31 -16
  142. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +21 -11
  143. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +20 -11
  144. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +20 -11
  145. package/.bkit/core/prompts/bkit-design-generate.md +32 -14
  146. package/.bkit/core/prompts/bkit-design-organise.md +25 -12
  147. package/.bkit/core/prompts/bkit-design-review-1.md +31 -15
  148. package/.bkit/core/prompts/bkit-design-review-2.md +28 -13
  149. package/.bkit/core/prompts/bkit-design-spike.md +30 -13
  150. package/.bkit/core/prompts/bkit-design-update.md +33 -19
  151. package/.bkit/core/prompts/bkit-plan-generate.md +72 -18
  152. package/.bkit/core/prompts/bkit-plan-review-1.md +50 -27
  153. package/.bkit/core/prompts/bkit-plan-review-2.md +59 -28
  154. package/.bkit/core/prompts/bkit-plan-scope-check.md +109 -0
  155. package/.bkit/core/prompts/bkit-plan-update.md +61 -24
  156. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +27 -15
  157. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +31 -16
  158. package/.bkit/core/prompts/bkit-ship-update-docs.md +29 -14
  159. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +24 -14
  160. package/.bkit/core/prompts/bkit-utility-update-decisions.md +32 -14
  161. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +29 -14
  162. package/.bkit/core/prompts/bkit-utility-update-documentation.md +27 -12
  163. package/.bkit/core/prompts/bkit-utility-update-failures.md +31 -14
  164. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +33 -14
  165. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +38 -17
  166. package/.bkit/core/prompts/bkit-utility-update-tracker.md +41 -18
  167. package/.bkit/core/workflows/bkit-auto.md +54 -46
  168. package/.bkit/core/workflows/bkit-build.md +577 -458
  169. package/.bkit/core/workflows/bkit-debug.md +348 -333
  170. package/.bkit/core/workflows/bkit-design.md +201 -237
  171. package/.bkit/core/workflows/bkit-plan.md +210 -321
  172. package/.bkit/core/workflows/bkit-ship.md +328 -278
  173. package/.bkit/shared/.bkit/.env.example +2 -2
  174. package/.bkit/shared/.claude/settings.json +11 -0
  175. package/.bkit/shared/.cursor/mcp.json +1 -1
  176. package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
  177. package/.bkit/shared/.gitattributes +1 -1
  178. package/.bkit/shared/.mcp.json +1 -1
  179. package/.bkit/shared/.opencode/opencode.json +11 -0
  180. package/.bkit/shared/CLAUDE.md +2 -2
  181. package/.bkit/shared/GEMINI.md +2 -2
  182. package/.bkit/shared/docs/architecture.md +1 -1
  183. package/.bkit/shared/docs/data-schema.md +1 -1
  184. package/.bkit/shared/docs/deployments.md +11 -11
  185. package/.bkit/shared/docs/design.md +1 -1
  186. package/.bkit/shared/docs/noise.md +1 -1
  187. package/.bkit/shared/docs/observability.md +2 -2
  188. package/.bkit/shared/docs/security.md +1 -1
  189. package/.bkit/shared/docs/setup.md +1 -1
  190. package/.bkit/shared/docs/technology.md +1 -1
  191. package/.bkit/shared/docs/testing.md +16 -7
  192. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +1 -1
  193. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +26 -5
  194. package/.bkit/templates/.github/workflows/bkit-ci.yml +1 -1
  195. package/.bkit/templates/.github/workflows/bkit-cloud.yml +21 -19
  196. package/.bkit/templates/.husky/pre-push +4 -4
  197. package/.bkit/templates/.prettierignore +7 -0
  198. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +1 -1
  199. package/CHANGELOG.md +112 -0
  200. package/README.md +50 -35
  201. package/dist/checks/after/ci-yml.js +39 -28
  202. package/dist/checks/after/github.js +91 -17
  203. package/dist/checks/after/index.js +11 -8
  204. package/dist/checks/after/suppression.js +8 -5
  205. package/dist/checks/after/tools.js +39 -82
  206. package/dist/checks/before/env.js +2 -2
  207. package/dist/checks/before/files.js +5 -3
  208. package/dist/checks/before/index.js +15 -2
  209. package/dist/checks/before/repo.js +163 -2
  210. package/dist/checks/tips/catalogue.js +14 -5
  211. package/dist/checks/tips/detect.js +32 -0
  212. package/dist/checks/tips/index.js +4 -4
  213. package/dist/cli.js +19 -47
  214. package/dist/commands/analysis.js +109 -100
  215. package/dist/commands/ci/ci.js +6 -6
  216. package/dist/commands/comply.js +54 -91
  217. package/dist/commands/install/doctor.js +2 -2
  218. package/dist/commands/install/install.js +50 -19
  219. package/dist/commands/install/uninstall.js +59 -28
  220. package/dist/commands/land.js +16 -12
  221. package/dist/commands/lib.js +51 -16
  222. package/dist/commands/registry.js +4 -0
  223. package/dist/commands/setup/setup.js +7 -7
  224. package/dist/commands/stats.js +136 -0
  225. package/dist/commands/tips.js +7 -3
  226. package/dist/commands/workflow/branches.js +656 -56
  227. package/dist/commands/workflow/challenge.js +556 -0
  228. package/dist/commands/workflow/context.js +709 -30
  229. package/dist/commands/workflow/counters.js +208 -75
  230. package/dist/commands/workflow/decisions.js +441 -0
  231. package/dist/commands/workflow/disk.js +2 -2
  232. package/dist/commands/workflow/fids.js +689 -33
  233. package/dist/commands/workflow/issues.js +343 -59
  234. package/dist/commands/workflow/ledgers.js +762 -27
  235. package/dist/commands/workflow/locks.js +24 -2
  236. package/dist/commands/workflow/plan-blocks.js +437 -0
  237. package/dist/commands/workflow/plan-versions.js +22 -0
  238. package/dist/commands/workflow/prs.js +142 -32
  239. package/dist/commands/workflow/repo.js +52 -8
  240. package/dist/commands/workflow/roadmap.js +9 -7
  241. package/dist/commands/workflow/run-facts.js +426 -0
  242. package/dist/commands/workflow/runs.js +144 -43
  243. package/dist/commands/workflow/runtime.js +12 -1
  244. package/dist/commands/workflow/status.js +130 -29
  245. package/dist/commands/workflow/step-table.js +276 -0
  246. package/dist/commands/workflow/steps.js +171 -80
  247. package/dist/commands/workflow/summary.js +275 -0
  248. package/dist/commands/workflow/tests.js +834 -136
  249. package/dist/commands/workflow/tracker.js +983 -0
  250. package/dist/commands/workflow/workflows.js +834 -195
  251. package/dist/commands/workflow/workstreams.js +11 -5
  252. package/dist/commands/workflow/worktrees.js +147 -9
  253. package/dist/install/manifest.js +11 -9
  254. package/dist/install/modules/cloud.js +22 -13
  255. package/dist/install/modules/core.js +247 -3
  256. package/dist/install/modules/opencode.js +2 -2
  257. package/dist/install/version-file.js +6 -2
  258. package/dist/ledgers/migrate.js +81 -0
  259. package/dist/ledgers/status.js +61 -8
  260. package/dist/ledgers/telemetry.js +905 -124
  261. package/dist/render/hosts.js +4 -0
  262. package/dist/render/models.js +12 -0
  263. package/dist/shared/branches.js +3 -1
  264. package/dist/shared/egress.js +7 -0
  265. package/dist/shared/json.js +20 -7
  266. package/dist/shared/settings.js +125 -17
  267. package/dist/shared/text.js +333 -0
  268. package/dist/tools/grammar-density.js +183 -0
  269. package/dist/tools/instructions-sources.js +721 -0
  270. package/dist/tools/instructions.js +1579 -0
  271. package/package.json +113 -24
  272. package/.bkit/core/engine/commands/harvest.ts +0 -459
  273. package/.bkit/core/engine/tools/wording.ts +0 -748
  274. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
  275. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
  276. package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
  277. package/.bkit/core/prompts/bkit-build-summary.md +0 -94
  278. package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
  279. package/.bkit/core/prompts/bkit-design-summary.md +0 -107
  280. package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
  281. package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
  282. package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
  283. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
  284. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
  285. package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
  286. package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
  287. package/dist/commands/harvest.js +0 -353
  288. package/dist/tools/wording.js +0 -680
@@ -14,12 +14,10 @@
14
14
  //
15
15
  // See DE-34 for the shared-entrypoint + crash-isolation contract.
16
16
  import { execFileSync } from "node:child_process";
17
- import * as fs from "node:fs";
18
17
  import * as path from "node:path";
19
- import { readJsonFile } from "../shared/json.js";
20
- import { getPkgRoot } from "../shared/package-roots.js";
21
18
  import { isMirrorPath } from "../shared/protected-paths.js";
22
- import { gitEnv, resolveGitSha, resolveRepoSlug, } from "../ledgers/telemetry.js";
19
+ import { gitEnv, resolveGitSha, } from "../ledgers/telemetry.js";
20
+ import { appendLedgerRows } from "./workflow/ledgers.js";
23
21
  /** SHA charset guard — only raw hex SHAs from the ledger are accepted. */
24
22
  const SHA_RE = /^[0-9a-f]{7,40}$/;
25
23
  export const realGitAdapter = {
@@ -134,89 +132,74 @@ export function runGrader(input) {
134
132
  /**
135
133
  * Build one `kind:"compliance"` row per rule.
136
134
  * Rules that produced no violation emit a "pass" row.
137
- * Every row carries `bkitVersion`.
138
- *
139
- * Called by the CLI dispatch after `runGrader`.
140
135
  */
141
136
  export function buildComplianceRows(input) {
142
- const ts = Date.now();
143
- const { violations, phase, parentSha, repo, bkitVersion, extra } = input;
137
+ const { violations, workflow, parentSha, step } = input;
144
138
  const violationByRule = new Map();
145
139
  for (const v of violations) {
146
140
  violationByRule.set(v.ruleId, v);
147
141
  }
148
142
  const ALL_RULES = ["no-mirror-edit", "skip-ci-not-head"];
149
- const rows = [];
150
- for (const ruleId of ALL_RULES) {
143
+ return ALL_RULES.map((ruleId) => {
151
144
  const violation = violationByRule.get(ruleId);
152
- const result = violation != null ? violation.result : "pass";
145
+ const verdict = violation != null ? violation.result : "pass";
153
146
  const evidence = violation?.evidence;
154
- const envelope = {
155
- ts: ts + rows.length, // micro-offset so each row has a unique ts within the batch
147
+ return {
156
148
  kind: "compliance",
157
- repo,
158
- bkitVersion,
159
- workflow: phase,
160
- step: "close-gate",
161
- ...(extra ?? {}),
162
- };
163
- const payload = {
164
- rule: ruleId,
165
- result,
166
- ...(evidence != null ? { evidence } : {}),
167
- phase,
168
- parentSha,
149
+ by: { workflow, step },
150
+ run: { parentSha },
151
+ rule: { id: ruleId, verdict, ...(evidence != null ? { evidence } : {}) },
169
152
  };
170
- rows.push({ ...envelope, ...payload });
171
- }
172
- return rows;
153
+ });
173
154
  }
174
155
  // ---------------------------------------------------------------------------
175
156
  // Append helper — writes rows to .bkit/stats.jsonl (best-effort)
176
157
  // ---------------------------------------------------------------------------
177
158
  /**
178
- * Append compliance rows to the stats ledger.
179
- * Best-effort: prints `[bkit-comply] append failed: …` on error, never throws.
159
+ * Append compliance rows to `<root>/.bkit/stats.jsonl` through `bkit ledgers append`.
160
+ * Best-effort: prints `[bkit-comply] append failed: …` and returns false on error,
161
+ * never throws.
180
162
  */
181
- export function appendComplianceRows(rows, statsPath) {
163
+ export function appendComplianceRows(rows, root, log = (m) => console.error(m)) {
164
+ if (rows.length === 0)
165
+ return false;
182
166
  try {
183
- const ndjson = rows.map((r) => JSON.stringify(r)).join("\n") + "\n";
184
- fs.appendFileSync(statsPath, ndjson, "utf8");
167
+ appendLedgerRows(root, "stats", rows);
168
+ return true;
185
169
  }
186
170
  catch (err) {
187
171
  const msg = err instanceof Error ? err.message : String(err);
188
- console.error(`[bkit-comply] append failed: ${statsPath} — ${msg}`);
172
+ log(`[bkit-comply] append failed: ${path.join(root, ".bkit", "stats.jsonl")} — ${msg}`);
173
+ return false;
189
174
  }
190
175
  }
191
- // ---------------------------------------------------------------------------
192
- // One grading pass, as `bkit workflows close` runs it before its report
193
- // ---------------------------------------------------------------------------
194
176
  /**
195
177
  * Grade `phase` over HEAD~1..HEAD (HEAD alone in a one-commit repo) and append
196
178
  * its compliance rows to `<cwd>/.bkit/stats.jsonl`. With `squashSha` (ship's
197
179
  * close, run in the feature worktree) the squash commit is graded instead —
198
180
  * its subject and `squash~1..squash` — so the grade covers the whole feature
199
- * as it reaches main, not the worktree's last commit. Fail-open: any
200
- * error is logged and returns null, so a close never stops on the grader.
181
+ * as it reaches main, not the worktree's last commit. The rows carry `run`'s
182
+ * `parentSha` and step (default: HEAD and `close-gate`), so they join the
183
+ * close's other rows. Fail-open: any error is logged and returns null, so a
184
+ * close never stops on the grader.
201
185
  */
202
- export function gradeCompliance(cwd, phase, log, squashSha) {
186
+ export function gradeCompliance(cwd, phase, log, squashSha, run) {
203
187
  try {
204
188
  const squashParent = squashSha === undefined ? "" : resolveGitSha(`${squashSha}~1`, cwd);
205
- const parentSha = squashParent || resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
206
- if (!parentSha) {
189
+ const base = squashParent || resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
190
+ if (!base) {
207
191
  log("[bkit-comply] cannot resolve a parent SHA (no commits?) — skipping grade");
208
192
  return null;
209
193
  }
210
194
  const headSha = squashParent ? squashSha : undefined;
211
- const violations = runGrader({ parentSha, phase, cwd, ...(headSha ? { headSha } : {}) });
195
+ const violations = runGrader({ parentSha: base, phase, cwd, ...(headSha ? { headSha } : {}) });
212
196
  const rows = buildComplianceRows({
213
197
  violations,
214
- phase,
215
- parentSha,
216
- repo: resolveRepoSlug(cwd) || "unknown/repo",
217
- bkitVersion: readBkitVersion(),
198
+ workflow: phase,
199
+ parentSha: run?.parentSha ?? resolveGitSha("HEAD", cwd),
200
+ step: run?.step ?? "close-gate",
218
201
  });
219
- appendComplianceRows(rows, path.join(cwd, ".bkit", "stats.jsonl"));
202
+ appendComplianceRows(rows, cwd, log);
220
203
  log(violations.length > 0
221
204
  ? `[bkit-comply] Compliance violations found:\n${formatComplianceSummary(violations)}`
222
205
  : "[bkit-comply] All rules pass.");
@@ -247,34 +230,6 @@ export function formatComplianceSummary(violations) {
247
230
  ];
248
231
  return lines.join("\n");
249
232
  }
250
- // ---------------------------------------------------------------------------
251
- // bkitVersion reader (used by CLI dispatch and tests)
252
- // ---------------------------------------------------------------------------
253
- /**
254
- * Read the bkit version from the package.json nearest to `searchFrom` (default: the
255
- * running bkit package's root). Returns "0.0.0" on any read/parse error (fail-open).
256
- */
257
- export function readBkitVersion(searchFrom) {
258
- // Walk up looking for a package.json with a `version` field; stop at the filesystem root.
259
- let dir = path.resolve(searchFrom ?? getPkgRoot());
260
- for (let i = 0; i < 8; i++) {
261
- const candidate = path.join(dir, "package.json");
262
- if (fs.existsSync(candidate)) {
263
- const read = readJsonFile(candidate);
264
- // Fail-open: a package.json that cannot be read ends the search with the default.
265
- if (!read.ok || read.value === null)
266
- return "0.0.0";
267
- const pkg = read.value;
268
- if (typeof pkg.version === "string")
269
- return pkg.version;
270
- }
271
- const parent = path.dirname(dir);
272
- if (parent === dir)
273
- break;
274
- dir = parent;
275
- }
276
- return "0.0.0";
277
- }
278
233
  // comply — compliance grader (advisory, never gating, fail-open).
279
234
  // Runs `runGrader` over `git diff parentSha..HEAD`, appends `kind:"compliance"`
280
235
  // rows to `.bkit/stats.jsonl`, and logs violations. Always exits 0 (fail-open);
@@ -286,22 +241,25 @@ export function runComplyCommand(complyPhase) {
286
241
  const cwd = process.cwd();
287
242
  const phase = complyPhase ?? "unknown";
288
243
  const logPrefix = "[bkit-comply]";
289
- // parentSha MUST be a resolved hex SHA: diffPaths returns [] for anything not
290
- // matching /^[0-9a-f]{7,40}$/, and parentSha is part of the compliance identity().
291
- // Resolves HEAD~1, else HEAD; neither → skip the grade.
292
- const statsPath = path.join(cwd, ".bkit", "stats.jsonl");
293
- const parentSha = resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
294
- if (!parentSha) {
244
+ // The grade's diff base MUST be a resolved hex SHA: diffPaths returns [] for anything
245
+ // not matching /^[0-9a-f]{7,40}$/. Resolves HEAD~1, else HEAD; neither → skip the grade.
246
+ const base = resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
247
+ if (!base) {
295
248
  console.log(`${logPrefix} cannot resolve a parent SHA (no commits?) — skipping grade`);
296
249
  return;
297
250
  }
298
- console.log(`${logPrefix} Running compliance grader (phase=${phase}, parentSha=${parentSha})`);
299
- const violations = runGrader({ parentSha, phase, cwd });
300
- // The origin remote's owner/repo, the same slug every other telemetry writer uses.
301
- const repo = resolveRepoSlug(cwd) || "unknown/repo";
302
- const bkitVersion = readBkitVersion();
303
- const rows = buildComplianceRows({ violations, phase, parentSha, repo, bkitVersion });
304
- appendComplianceRows(rows, statsPath);
251
+ console.log(`${logPrefix} Running compliance grader (phase=${phase}, base=${base})`);
252
+ const violations = runGrader({ parentSha: base, phase, cwd });
253
+ // A row names the closing workflow it grades: without one, the grade is printed only.
254
+ const rows = complyPhase === null
255
+ ? []
256
+ : buildComplianceRows({
257
+ violations,
258
+ workflow: complyPhase,
259
+ parentSha: resolveGitSha("HEAD", cwd),
260
+ step: "close-gate",
261
+ });
262
+ const written = complyPhase !== null && appendComplianceRows(rows, cwd);
305
263
  if (violations.length > 0) {
306
264
  const summary = formatComplianceSummary(violations);
307
265
  console.log(`${logPrefix} Compliance violations found:\n${summary}`);
@@ -309,7 +267,12 @@ export function runComplyCommand(complyPhase) {
309
267
  else {
310
268
  console.log(`${logPrefix} All rules pass.`);
311
269
  }
312
- console.log(`${logPrefix} Appended ${rows.length} compliance row(s) to .bkit/stats.jsonl (advisory — not gating).`);
270
+ if (complyPhase === null) {
271
+ console.log(`${logPrefix} no --phase: rows not written to .bkit/stats.jsonl.`);
272
+ }
273
+ else if (written) {
274
+ console.log(`${logPrefix} Appended ${rows.length} compliance row(s) to .bkit/stats.jsonl (advisory — not gating).`);
275
+ }
313
276
  }
314
277
  catch (err) {
315
278
  // Fail-open: any unexpected error in the dispatch body must not gate the workflow.
@@ -147,7 +147,7 @@ export async function runDoctor(modules, opencodeProvider) {
147
147
  allFindings.push({
148
148
  id: "opencode-provider-missing",
149
149
  severity: "blocker",
150
- detect: "`.opencode/` is present but no provider is recorded — neither package.json `bkit.opencodeProvider` nor an `opencode.json` provider block.",
150
+ detect: "`.opencode/` is present but no provider is recorded — neither package.json `bkit.providers.opencode.default` nor an `opencode.json` provider block.",
151
151
  action: `Re-run \`bkit install --opencode=<provider>\` (${OPENCODE_PROVIDERS.join(", ")}). Until then \`bkit check\` and \`bkit upgrade\` exit 1 rather than render every agent pin against a substitute provider.`,
152
152
  });
153
153
  }
@@ -185,7 +185,7 @@ export async function runDoctor(modules, opencodeProvider) {
185
185
  let detectedProvider = detectOpencodeProvider(process.cwd());
186
186
  if (opencodeProvider)
187
187
  detectedProvider = opencodeProvider;
188
- // Multi-provider: all installed providers. bkit.opencodeProviders when populated,
188
+ // Multi-provider: all installed providers. bkit.providers.opencode.installed when populated,
189
189
  // else the single detected provider.
190
190
  const allProviders = detectOpencodeProviders(process.cwd());
191
191
  const activeProvider = detectedProvider ?? allProviders[0] ?? null;
@@ -15,8 +15,9 @@ import { formatChecklist, readChangelogVersionDelta, runPostInstallCheck, writeA
15
15
  import { collectTips } from "../../checks/tips/index.js";
16
16
  import { findMissingOwnedHooks, detectOwnedHookMissing } from "../../checks/after/managed.js";
17
17
  import { resolveTokens } from "../../install/placeholders.js";
18
- import { parseModelLookup, applyModelOverrides, buildOpencodeModelLookup, buildAntigravityModelLookup, parseEffortMap, } from "../../render/models.js";
18
+ import { parseModelLookup, applyModelOverrides, unknownModelOverrides, buildOpencodeModelLookup, buildAntigravityModelLookup, parseEffortMap, } from "../../render/models.js";
19
19
  import { getBkitDocsRoot } from "../../shared/package-roots.js";
20
+ import { migrateBkitLayout, migrateGithubProjectKey, migrateLinearTeamKey, } from "../../install/modules/core.js";
20
21
  import { removeUnusedTrackerMcpEntries, runUninstall } from "./uninstall.js";
21
22
  // ---------------------------------------------------------------------------
22
23
  // Staging scratch area
@@ -43,7 +44,7 @@ export function discardAllStaging(cwd = process.cwd()) {
43
44
  * The installed opencode provider, or exit(1) with the fix.
44
45
  *
45
46
  * `bkit check` / `bkit upgrade` take no `--opencode=` flag, so they read the provider the
46
- * consumer actually installed (package.json `bkit.opencodeProvider`, else the opencode.json
47
+ * consumer actually installed (package.json `bkit.providers.opencode.default`, else the opencode.json
47
48
  * provider block). There is no default: a repo carrying `.opencode/` with no recorded
48
49
  * provider is a broken install.
49
50
  *
@@ -53,7 +54,7 @@ export function requireOpencodeProvider(cwd, context) {
53
54
  const detected = detectOpencodeProvider(cwd);
54
55
  if (!detected) {
55
56
  console.error(`${LOG_PREFIX} ${context}: the opencode host is installed but no provider is recorded ` +
56
- `(package.json \`bkit.opencodeProvider\` and .opencode/opencode.json are both silent). ` +
57
+ `(package.json \`bkit.providers.opencode.default\` and .opencode/opencode.json are both silent). ` +
57
58
  `Re-run \`bkit install --opencode=<provider>\` — one of ${OPENCODE_PROVIDERS.join(", ")}.`);
58
59
  process.exit(1);
59
60
  }
@@ -99,11 +100,20 @@ export function validateCloudTrackerMatch(cloudVariant, hasCloudModule, issueTra
99
100
  ? `Set the tracker first: bkit install --tracker=${requiredTracker} --auto=${cloudVariant}`
100
101
  : `Re-run with the matching tracker: bkit install --tracker=${requiredTracker} --auto=${cloudVariant} (tracker switching is free).`));
101
102
  }
103
+ /** `parent[key]` as an object, set to a fresh `{}` first when it is absent or not an object. */
104
+ function section(parent, key) {
105
+ const v = parent[key];
106
+ if (v !== null && typeof v === "object" && !Array.isArray(v))
107
+ return v;
108
+ const fresh = {};
109
+ parent[key] = fresh;
110
+ return fresh;
111
+ }
102
112
  /**
103
113
  * Detect the bkit opencode provider key a consumer installed.
104
114
  *
105
115
  * Resolution order:
106
- * 1. `package.json` `bkit.opencodeProvider` — the authoritative record written on install.
116
+ * 1. `package.json` `bkit.providers.opencode.default` — the authoritative record written on install.
107
117
  * This is the ONLY signal for managed-auth gateways (opencode) whose opencode.json carries no
108
118
  * custom provider block.
109
119
  * 2. `.opencode/opencode.json` first provider key — for installs without the manifest field
@@ -136,7 +146,7 @@ export function detectOpencodeProvider(cwd) {
136
146
  }
137
147
  /**
138
148
  * Returns all bkit-installed opencode providers from the consumer package.json
139
- * `bkit.opencodeProviders` array, filtered to valid OPENCODE_PROVIDERS entries; [] when
149
+ * `bkit.providers.opencode.installed` array, filtered to valid OPENCODE_PROVIDERS entries; [] when
140
150
  * the field is absent.
141
151
  */
142
152
  export function detectOpencodeProviders(cwd) {
@@ -183,6 +193,17 @@ export async function runInstall(args, upgradeReport = false) {
183
193
  console.log(`${LOG_PREFIX} Checking advisories (read-only)`);
184
194
  else if (dryRun)
185
195
  console.log(`${LOG_PREFIX} Running in check (dry-run) mode`);
196
+ // The package.json key moves run before anything below reads `bkit` settings: the tracker,
197
+ // the opencode provider and the cloud agent are read from the new paths only, so a 5.x
198
+ // layout read first renders every host as if no tracker were set. The core module runs
199
+ // the same moves again; each is a no-op once applied. Check moves nothing and reports
200
+ // the old keys as drift.
201
+ const ws = { writes: [] };
202
+ if (!dryRun) {
203
+ migrateLinearTeamKey(false, ws, LOG_PREFIX);
204
+ migrateGithubProjectKey(false, ws, LOG_PREFIX);
205
+ migrateBkitLayout(false, ws, LOG_PREFIX);
206
+ }
186
207
  // `bkit check` scopes drift detection to what is INSTALLED (detected by sentinel files),
187
208
  // not to a fixed full set. `install` keeps its explicit resolved set, plus every installed
188
209
  // host when `--tracker=` is given: each host renders tracker-specific commands, agents and
@@ -194,13 +215,13 @@ export async function runInstall(args, upgradeReport = false) {
194
215
  : modules;
195
216
  // RENDER-input provider resolution. `bkit check` takes no `--opencode=` flag, so the parsed
196
217
  // `opencodeProvider` is null on the check path; it falls back to the INSTALLED provider
197
- // (package.json `bkit.opencodeProvider`, else the opencode.json provider block). On install
218
+ // (package.json `bkit.providers.opencode.default`, else the opencode.json provider block). On install
198
219
  // `?? detect` fires only when opencode joins as an installed host under `--tracker=`; with
199
220
  // `--opencode=<provider>` the flag wins. The PARSED `opencodeProvider` alone drives the persist-to-package.json logic
200
221
  // below (gated on `!dryRun` + a real flag). The tracker is resolved from package.json below,
201
222
  // so the tracker-dependent opencode mcp block renders the same way on check.
202
223
  const renderOpencodeProvider = opencodeProvider ?? detectOpencodeProvider(process.cwd());
203
- // Resolve issueTracker: --tracker= flag overrides; else read bkit.issueTracker from consumer
224
+ // Resolve issueTracker: --tracker= flag overrides; else read bkit.tracker.default from consumer
204
225
  // package.json; else default to "none".
205
226
  // A `--tracker=` value always applies, whether first-set or a re-set of an
206
227
  // already-recorded tracker.
@@ -294,7 +315,17 @@ export async function runInstall(args, upgradeReport = false) {
294
315
  }
295
316
  // Seed preflight advisories into ctx so modules can accumulate into the same list.
296
317
  const advisories = [...preflightAdvisories];
297
- const ws = { writes: [] };
318
+ const deadOverrides = modelLookup.size > 0
319
+ ? unknownModelOverrides(consumerPromptsMdPath, new Set(modelLookup.keys()))
320
+ : [];
321
+ if (deadOverrides.length > 0) {
322
+ advisories.push({
323
+ id: "model-override-unknown-agent",
324
+ severity: "advisory",
325
+ detect: `.bkit/prompts.md § Model Overrides names agents bkit no longer ships: ${deadOverrides.join(", ")}. Those rows are not applied.`,
326
+ action: "Delete the rows, or move each pin to the agent that now does that work (see .bkit/prompts.md § Models).",
327
+ });
328
+ }
298
329
  const postDispatch = [];
299
330
  // Symmetric cloud/tracker constraint (FINAL SCOPE decision 3/4) — see
300
331
  // validateCloudTrackerMatch for the full rationale. Checked BEFORE any
@@ -316,8 +347,8 @@ export async function runInstall(args, upgradeReport = false) {
316
347
  }
317
348
  // Persist bkit manifest fields to consumer package.json AFTER all hard-error gates pass.
318
349
  // This preserves the "no files written on mismatch" invariant. Two fields are recorded:
319
- // - issueTracker: when a `--tracker=` value was given this run.
320
- // - opencodeProvider: when an `--opencode=<provider>` value was given this run. This is
350
+ // - tracker.default: when a `--tracker=` value was given this run.
351
+ // - providers.opencode.default: when an `--opencode=<provider>` value was given this run. This is
321
352
  // the authoritative provider record detectOpencodeProvider reads on upgrade — REQUIRED
322
353
  // for managed-auth gateways (opencode), whose opencode.json carries no provider block to
323
354
  // detect from. Both are merged in one read-modify-write to avoid double-writing.
@@ -332,30 +363,30 @@ export async function runInstall(args, upgradeReport = false) {
332
363
  const parsed = parseJson(raw);
333
364
  if (parsed.ok) {
334
365
  const pkg = parsed.value;
335
- const bkit = (pkg.bkit ?? {});
366
+ const bkit = section(pkg, "bkit");
336
367
  if (persistTracker)
337
- bkit.issueTracker = tracker;
368
+ section(bkit, "tracker").default = tracker;
338
369
  if (persistProvider) {
339
- bkit.opencodeProvider = opencodeProvider; // active (drives agent frontmatter)
370
+ const opencode = section(section(bkit, "providers"), "opencode");
371
+ opencode.default = opencodeProvider; // active (drives agent frontmatter)
340
372
  // Update providers array (deduped).
341
- const existingArr = Array.isArray(bkit.opencodeProviders)
342
- ? [...bkit.opencodeProviders]
373
+ const existingArr = Array.isArray(opencode.installed)
374
+ ? [...opencode.installed]
343
375
  : [];
344
376
  if (!existingArr.includes(opencodeProvider)) {
345
377
  existingArr.push(opencodeProvider);
346
378
  }
347
- bkit.opencodeProviders = existingArr;
379
+ opencode.installed = existingArr;
348
380
  }
349
- pkg.bkit = bkit;
350
381
  const indentMatch = raw.match(/\n([ \t]+)"/);
351
382
  const indent = indentMatch ? indentMatch[1] : " ";
352
383
  const trailingNewline = raw.endsWith("\n") ? "\n" : "";
353
384
  fs.writeFileSync(consumerPkgPath2, JSON.stringify(pkg, null, indent) + trailingNewline, "utf-8");
354
385
  if (persistTracker) {
355
- console.log(`${LOG_PREFIX} Set bkit.issueTracker = "${tracker}" in package.json`);
386
+ console.log(`${LOG_PREFIX} Set bkit.tracker.default = "${tracker}" in package.json`);
356
387
  }
357
388
  if (persistProvider) {
358
- console.log(`${LOG_PREFIX} Set bkit.opencodeProvider = "${opencodeProvider}" and updated bkit.opencodeProviders in package.json`);
389
+ console.log(`${LOG_PREFIX} Set bkit.providers.opencode.default = "${opencodeProvider}" and updated bkit.providers.opencode.installed in package.json`);
359
390
  }
360
391
  }
361
392
  }
@@ -34,6 +34,7 @@ import { removeOpencodeProviderBlock, renderOpencodeAgentsCommands, renderOpenco
34
34
  import { applyModelOverrides, buildOpencodeModelLookup, parseEffortMap, } from "../../render/models.js";
35
35
  import { readInstallingVersion } from "../../shared/package-json.js";
36
36
  import { readBkitConfig } from "../../shared/settings.js";
37
+ import { SEEDED_BKIT_DEFAULTS } from "../../install/modules/core.js";
37
38
  import { CLAUDE_CLOUD_RELPATH, CURSOR_CLOUD_RELPATH, resolveClaudeDerivedAllows, } from "../../install/cloud-env.js";
38
39
  import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
39
40
  import { unusedTrackerMcpServers } from "../../checks/before/mcp.js";
@@ -654,7 +655,7 @@ export async function runUninstall(modules, ctx) {
654
655
  }
655
656
  }
656
657
  // Full/core uninstall: strip the `bkit` install-state object from package.json
657
- // (issueTracker / opencodeProvider(s) / cloudAgents), whatever keys it holds. Scripts
658
+ // (tracker / providers / cloud and every other section), whatever keys it holds. Scripts
658
659
  // and devDeps are the consumer's and stay. No try/catch — malformed package.json is a hard failure on full
659
660
  // teardown (same as a missing dest would be).
660
661
  if (moduleList.includes("core") && !ctx.dryRun) {
@@ -669,8 +670,8 @@ export async function runUninstall(modules, ctx) {
669
670
  }
670
671
  }
671
672
  }
672
- // Targeted uninstall: drop the `bkit.*` keys the removed module records, so its advisories
673
- // stop firing. Core keeps every other key.
673
+ // Targeted uninstall: reset the `bkit.*` keys the removed module records to unset, so its
674
+ // advisories stop firing. Core keeps every other key.
674
675
  if (!moduleList.includes("core")) {
675
676
  stripModuleBkitKeys(moduleList, ctx, result);
676
677
  }
@@ -863,15 +864,33 @@ export async function runUninstall(modules, ctx) {
863
864
  }
864
865
  return result;
865
866
  }
866
- /** `package.json` `bkit.*` keys each module records on install. */
867
+ /** `package.json` `bkit.*` keys (dotted paths) each module records on install. */
867
868
  const MODULE_BKIT_KEYS = {
868
- cloud: ["cloudAgents"],
869
- opencode: ["opencodeProvider", "opencodeProviders"],
869
+ cloud: ["cloud.agent"],
870
+ opencode: ["providers.opencode.default", "providers.opencode.installed"],
870
871
  };
872
+ /** The object at dotted `keys` under `root`; null when a step is absent or not an object. */
873
+ function objectAt(root, keys) {
874
+ let node = root;
875
+ for (const k of keys) {
876
+ const next = node[k];
877
+ if (!isJsonObject(next))
878
+ return null;
879
+ node = next;
880
+ }
881
+ return node;
882
+ }
883
+ /** The seeded value at dotted `key` in SEEDED_BKIT_DEFAULTS, copied. */
884
+ function seededValue(key) {
885
+ const segs = key.split(".");
886
+ const parent = objectAt(SEEDED_BKIT_DEFAULTS, segs.slice(0, -1));
887
+ return structuredClone(parent?.[segs[segs.length - 1]]);
888
+ }
871
889
  /**
872
- * Remove the `bkit.*` keys recorded by the modules in `moduleList` from the consumer's
873
- * package.json, keeping its indent. Lists each removed key in `result.stripped`; a dry run
874
- * lists without writing.
890
+ * Reset the `bkit.*` keys recorded by the modules in `moduleList` to the value install
891
+ * seeds (`""` / `[]`, read as unset), keeping the package.json indent. Deleting them
892
+ * would leave `bkit check` reporting the seeded key as missing. Lists each reset key in
893
+ * `result.stripped`; a dry run lists without writing.
875
894
  */
876
895
  function stripModuleBkitKeys(moduleList, ctx, result) {
877
896
  const keys = moduleList.flatMap((m) => MODULE_BKIT_KEYS[m] ?? []);
@@ -886,14 +905,22 @@ function stripModuleBkitKeys(moduleList, ctx, result) {
886
905
  if (pkg === null || !isJsonObject(pkg.bkit))
887
906
  return;
888
907
  const bkit = pkg.bkit;
889
- const present = keys.filter((k) => k in bkit);
890
- if (present.length === 0)
908
+ const reset = keys.filter((k) => {
909
+ const segs = k.split(".");
910
+ const parent = objectAt(bkit, segs.slice(0, -1));
911
+ const key = segs[segs.length - 1];
912
+ return (parent !== null &&
913
+ key in parent &&
914
+ JSON.stringify(parent[key]) !== JSON.stringify(seededValue(k)));
915
+ });
916
+ if (reset.length === 0)
891
917
  return;
892
- for (const k of present) {
893
- delete bkit[k];
918
+ for (const k of reset) {
919
+ const segs = k.split(".");
920
+ objectAt(bkit, segs.slice(0, -1))[segs[segs.length - 1]] = seededValue(k);
894
921
  result.stripped.push(`package.json#bkit.${k}`);
895
922
  }
896
- console.log(`${ctx.logPrefix}${ctx.dryRun ? " [dry-run]" : ""} package.json: removed bkit.${present.join(", bkit.")}`);
923
+ console.log(`${ctx.logPrefix}${ctx.dryRun ? " [dry-run]" : ""} package.json: reset bkit.${reset.join(", bkit.")} to unset`);
897
924
  if (ctx.dryRun)
898
925
  return;
899
926
  const indentMatch = raw.match(/\n([ \t]+)"/);
@@ -908,8 +935,8 @@ function stripModuleBkitKeys(moduleList, ctx, result) {
908
935
  *
909
936
  * Distinct from bare `bkit uninstall --opencode` (full host teardown):
910
937
  * - Removes the provider block from `.opencode/opencode.json`
911
- * - Updates `bkit.opencodeProviders` in `package.json`
912
- * - If the removed provider was the active one, re-points `bkit.opencodeProvider`
938
+ * - Updates `bkit.providers.opencode.installed` in `package.json`
939
+ * - If the removed provider was the active one, re-points `bkit.providers.opencode.default`
913
940
  * to the first remaining provider and emits a re-render advisory
914
941
  * - If no providers remain, falls through to full host teardown via `runUninstall`
915
942
  */
@@ -923,7 +950,7 @@ export async function runSurgicalOpencodeUninstall(providerKey, dryRun, cwd) {
923
950
  if (ws.writes.length > 0) {
924
951
  console.log(`${LOG_PREFIX}${tag} removed provider block "${providerKey}" from opencode.json`);
925
952
  }
926
- // 2. Update bkit.opencodeProviders in package.json (read inline — no detectOpencodeProviders import)
953
+ // 2. Update bkit.providers.opencode.installed in package.json (read inline — no detectOpencodeProviders import)
927
954
  const pkgPath = path.join(cwd, "package.json");
928
955
  let remainingProviders = [];
929
956
  let wasActive = false;
@@ -936,31 +963,35 @@ export async function runSurgicalOpencodeUninstall(providerKey, dryRun, cwd) {
936
963
  console.warn(`${LOG_PREFIX} package.json is malformed — skipping bkit section update`);
937
964
  return;
938
965
  }
939
- const bkit = (pkg.bkit ?? {});
940
- const arr = Array.isArray(bkit.opencodeProviders)
941
- ? [...bkit.opencodeProviders]
942
- : [];
966
+ const opencode = objectAt(pkg, ["bkit", "providers", "opencode"]) ?? {};
967
+ const arr = Array.isArray(opencode.installed) ? [...opencode.installed] : [];
943
968
  remainingProviders = arr.filter((p) => p !== providerKey);
944
- wasActive = bkit.opencodeProvider === providerKey;
969
+ wasActive = opencode.default === providerKey;
945
970
  if (wasActive && remainingProviders.length > 0) {
946
971
  newActive = remainingProviders[0];
947
972
  }
948
973
  if (!dryRun) {
949
- bkit.opencodeProviders = remainingProviders;
974
+ opencode.installed = remainingProviders;
950
975
  if (wasActive) {
951
976
  if (newActive !== null) {
952
- bkit.opencodeProvider = newActive;
977
+ opencode.default = newActive;
953
978
  }
954
979
  else {
955
- delete bkit.opencodeProvider;
980
+ delete opencode.default;
956
981
  }
957
982
  }
958
- pkg.bkit = bkit;
983
+ if (objectAt(pkg, ["bkit", "providers", "opencode"]) === null) {
984
+ const bkit = objectAt(pkg, ["bkit"]) ?? {};
985
+ const providers = objectAt(bkit, ["providers"]) ?? {};
986
+ providers.opencode = opencode;
987
+ bkit.providers = providers;
988
+ pkg.bkit = bkit;
989
+ }
959
990
  const indentMatch = raw.match(/\n([ \t]+)"/);
960
991
  const indent = indentMatch ? indentMatch[1] : " ";
961
992
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + "\n", "utf-8");
962
- console.log(`${LOG_PREFIX} updated package.json: opencodeProviders=[${remainingProviders.join(", ")}]` +
963
- (wasActive ? ` opencodeProvider=${newActive ?? "(removed)"}` : ""));
993
+ console.log(`${LOG_PREFIX} updated package.json: bkit.providers.opencode.installed=[${remainingProviders.join(", ")}]` +
994
+ (wasActive ? ` bkit.providers.opencode.default=${newActive ?? "(removed)"}` : ""));
964
995
  }
965
996
  }
966
997
  // 3. If none remain → full host teardown
@@ -1,10 +1,13 @@
1
- // The one way bkit lands a commit on dev: build it in a detached throwaway
2
- // worktree off a fresh origin/dev and push it as dev. The main checkout's
3
- // branch, index and edits are never touched, and local dev commits missing from
4
- // origin/dev are never pushed. dev moved underneath → rebuild on the new dev and
5
- // push again, with backoff. Used by the design / plan close, the build / debug
6
- // roadmap mirror, and ship's close and FAILED record. The throwaway runs no git
7
- // hooks: what it lands is bookkeeping only (docs, logs, ledgers, `[skip ci]`).
1
+ // The one way bkit lands commits on dev from a throwaway: build them in a
2
+ // detached worktree off a fresh origin/dev and push it as dev. The main
3
+ // checkout's branch, index and edits are never touched, and local dev commits
4
+ // missing from origin/dev are never pushed as they stand — a caller that wants
5
+ // some of them replays exactly those. dev moved underneath → rebuild on the new
6
+ // dev and push again, with backoff. Used by the design / plan close, the
7
+ // build / debug roadmap mirror, ship's close and FAILED record, and the
8
+ // own-commit push of a debug run in place on dev, which replays the run's
9
+ // commits. The throwaway runs no git hooks: it lands bookkeeping (docs, logs,
10
+ // ledgers, `[skip ci]`) or the commits a debug run on dev made.
8
11
  import * as fs from "node:fs";
9
12
  import * as path from "node:path";
10
13
  import { CommandError, DEV, EXIT, git, runGit } from "./lib.js";
@@ -79,13 +82,14 @@ export async function withoutHooks(fn) {
79
82
  }
80
83
  }
81
84
  /**
82
- * Land one commit on dev: per attempt, fetch dev, add `dir` detached at
83
- * origin/dev, let `build` make the commit there, push `HEAD:dev` — git hooks
84
- * off. `build` throwing stops the landing with that throw. A server refusal runs
85
- * `refused` on the built commit first, when given. `dir` is removed on every path.
85
+ * Land on dev what `build` makes: per attempt, fetch dev, add `dir` detached at
86
+ * origin/dev, let `build` make one or more commits there (a bookkeeping commit,
87
+ * or a replay of a run's commits), push `HEAD:dev` — git hooks off. `build`
88
+ * throwing stops the landing with that throw. A server refusal runs `refused` on
89
+ * the built commits first, when given. `dir` is removed on every path.
86
90
  */
87
91
  export async function pushToDev(o) {
88
- o.log("git hooks skipped in the throwaway dev checkout — it lands bookkeeping only");
92
+ o.log("git hooks skipped in the throwaway dev checkout — it lands bookkeeping, or the commits a debug run on dev made");
89
93
  for (let attempt = 1;; attempt++) {
90
94
  let wait = 0;
91
95
  dropLandTree(o.root, o.dir);