@cbartens/bkit 5.2.4 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/.bkit/README.md +27 -11
  2. package/.bkit/core/.agents/context.md +1 -1
  3. package/.bkit/core/.agents/docs.md +1 -1
  4. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +1 -1
  5. package/.bkit/core/.agents/rules.md +18 -1
  6. package/.bkit/core/.bkit/README.md +26 -10
  7. package/.bkit/core/.bkit/cloud.md +40 -39
  8. package/.bkit/core/.bkit/comparison.md +68 -345
  9. package/.bkit/core/.bkit/install.md +16 -9
  10. package/.bkit/core/.bkit/lite.md +73 -0
  11. package/.bkit/core/.bkit/pipeline.md +346 -0
  12. package/.bkit/core/.bkit/prompts.md +90 -74
  13. package/.bkit/core/.bkit/providers.md +42 -23
  14. package/.bkit/core/.bkit/templates.md +138 -19
  15. package/.bkit/core/.bkit/trackers.md +49 -4
  16. package/.bkit/core/.bkit/workflows.md +144 -123
  17. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +1 -1
  18. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +7 -4
  19. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -5
  20. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +3 -2
  21. package/.bkit/core/docs/templates/bkit-audit-adoption.md +2 -2
  22. package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
  23. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
  24. package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
  25. package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
  26. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
  27. package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
  28. package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
  29. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +4 -2
  30. package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
  31. package/.bkit/core/docs/templates/bkit-audit-cost.md +3 -2
  32. package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
  33. package/.bkit/core/docs/templates/bkit-audit-database.md +3 -2
  34. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +5 -5
  35. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
  36. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +26 -21
  37. package/.bkit/core/docs/templates/bkit-audit-documentation.md +1 -1
  38. package/.bkit/core/docs/templates/bkit-audit-duplication.md +2 -2
  39. package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
  40. package/.bkit/core/docs/templates/bkit-audit-flakes.md +3 -2
  41. package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -2
  42. package/.bkit/core/docs/templates/bkit-audit-issues.md +3 -2
  43. package/.bkit/core/docs/templates/bkit-audit-llm.md +22 -15
  44. package/.bkit/core/docs/templates/bkit-audit-logs.md +10 -6
  45. package/.bkit/core/docs/templates/bkit-audit-models.md +1 -1
  46. package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
  47. package/.bkit/core/docs/templates/bkit-audit-prompts.md +7 -7
  48. package/.bkit/core/docs/templates/bkit-audit-red-team.md +12 -9
  49. package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
  50. package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
  51. package/.bkit/core/docs/templates/bkit-audit-security.md +14 -12
  52. package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
  53. package/.bkit/core/docs/templates/bkit-audit-testing.md +10 -8
  54. package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
  55. package/.bkit/core/docs/templates/bkit-plan.md +8 -6
  56. package/.bkit/core/engine/checks/after/auth.ts +9 -9
  57. package/.bkit/core/engine/checks/after/ci-yml.ts +14 -12
  58. package/.bkit/core/engine/checks/after/github.ts +29 -120
  59. package/.bkit/core/engine/checks/after/index.ts +2 -2
  60. package/.bkit/core/engine/checks/after/managed.ts +8 -28
  61. package/.bkit/core/engine/checks/after/tools.ts +3 -15
  62. package/.bkit/core/engine/checks/before/context-fetch.ts +1 -21
  63. package/.bkit/core/engine/checks/before/index.ts +7 -43
  64. package/.bkit/core/engine/checks/before/mcp.ts +17 -8
  65. package/.bkit/core/engine/checks/before/repo.ts +9 -12
  66. package/.bkit/core/engine/checks/status-holes.ts +4 -6
  67. package/.bkit/core/engine/checks/tips/catalogue.ts +76 -24
  68. package/.bkit/core/engine/checks/tips/detect.ts +45 -2
  69. package/.bkit/core/engine/checks/tips/index.ts +77 -26
  70. package/.bkit/core/engine/cli.ts +57 -27
  71. package/.bkit/core/engine/commands/analysis.ts +36 -26
  72. package/.bkit/core/engine/commands/comply.ts +42 -32
  73. package/.bkit/core/engine/commands/harvest.ts +12 -12
  74. package/.bkit/core/engine/commands/install/doctor.ts +57 -28
  75. package/.bkit/core/engine/commands/install/install.ts +73 -130
  76. package/.bkit/core/engine/commands/install/uninstall.ts +191 -33
  77. package/.bkit/core/engine/commands/install/upgrade.ts +49 -43
  78. package/.bkit/core/engine/commands/land.ts +156 -0
  79. package/.bkit/core/engine/commands/lib.ts +45 -18
  80. package/.bkit/core/engine/commands/registry.ts +2 -0
  81. package/.bkit/core/engine/commands/tips.ts +12 -5
  82. package/.bkit/core/engine/commands/workflow/branches.ts +386 -286
  83. package/.bkit/core/engine/commands/workflow/counters.ts +21 -12
  84. package/.bkit/core/engine/commands/workflow/disk.ts +556 -0
  85. package/.bkit/core/engine/commands/workflow/fids.ts +46 -0
  86. package/.bkit/core/engine/commands/workflow/issues.ts +73 -28
  87. package/.bkit/core/engine/commands/workflow/ledgers.ts +3 -1
  88. package/.bkit/core/engine/commands/workflow/locks.ts +38 -152
  89. package/.bkit/core/engine/commands/workflow/prs.ts +15 -4
  90. package/.bkit/core/engine/commands/workflow/repo.ts +2 -2
  91. package/.bkit/core/engine/commands/workflow/roadmap.ts +49 -53
  92. package/.bkit/core/engine/commands/workflow/runs.ts +8 -7
  93. package/.bkit/core/engine/commands/workflow/runtime.ts +3 -2
  94. package/.bkit/core/engine/commands/workflow/status.ts +33 -11
  95. package/.bkit/core/engine/commands/workflow/steps.ts +25 -15
  96. package/.bkit/core/engine/commands/workflow/tests.ts +17 -5
  97. package/.bkit/core/engine/commands/workflow/workflows.ts +436 -267
  98. package/.bkit/core/engine/commands/workflow/workstreams.ts +4 -2
  99. package/.bkit/core/engine/commands/workflow/worktrees.ts +24 -6
  100. package/.bkit/core/engine/install/cloud-env.ts +10 -31
  101. package/.bkit/core/engine/install/manifest.ts +14 -7
  102. package/.bkit/core/engine/install/modules/antigravity.ts +15 -26
  103. package/.bkit/core/engine/install/modules/claude.ts +20 -28
  104. package/.bkit/core/engine/install/modules/cloud.ts +5 -2
  105. package/.bkit/core/engine/install/modules/codex.ts +15 -29
  106. package/.bkit/core/engine/install/modules/core.ts +106 -70
  107. package/.bkit/core/engine/install/modules/cursor.ts +6 -20
  108. package/.bkit/core/engine/install/modules/index.ts +7 -1
  109. package/.bkit/core/engine/install/modules/opencode.ts +48 -70
  110. package/.bkit/core/engine/install/network-allowlist.ts +73 -0
  111. package/.bkit/core/engine/install/placeholders.ts +16 -35
  112. package/.bkit/core/engine/install/write.ts +59 -12
  113. package/.bkit/core/engine/ledgers/telemetry.ts +6 -4
  114. package/.bkit/core/engine/render/hosts.ts +47 -67
  115. package/.bkit/core/engine/render/models.ts +29 -11
  116. package/.bkit/core/engine/shared/branches.ts +13 -0
  117. package/.bkit/core/engine/shared/egress.ts +3 -3
  118. package/.bkit/core/engine/shared/json.ts +18 -1
  119. package/.bkit/core/engine/shared/package-json.ts +63 -0
  120. package/.bkit/core/engine/shared/package-roots.ts +0 -10
  121. package/.bkit/core/engine/shared/protected-paths.ts +5 -130
  122. package/.bkit/core/engine/shared/settings.ts +44 -0
  123. package/.bkit/core/engine/shared/timeouts.ts +8 -7
  124. package/.bkit/core/hooks/antigravity-hook.js +1 -0
  125. package/.bkit/core/hooks/guardrails-shell.js +186 -40
  126. package/.bkit/core/hooks/guardrails-tiers.js +5 -78
  127. package/.bkit/core/prompts/bkit-audit-generate.md +103 -7
  128. package/.bkit/core/prompts/bkit-build-challenge-1.md +1 -1
  129. package/.bkit/core/prompts/bkit-build-challenge-2.md +1 -1
  130. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +1 -1
  131. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +1 -1
  132. package/.bkit/core/prompts/bkit-build-challenge-tests.md +1 -1
  133. package/.bkit/core/prompts/bkit-build-install-skills.md +1 -1
  134. package/.bkit/core/prompts/bkit-build-plan-current.md +1 -1
  135. package/.bkit/core/prompts/bkit-build-plan-execute.md +4 -4
  136. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +1 -1
  137. package/.bkit/core/prompts/bkit-build-plan-verify.md +2 -2
  138. package/.bkit/core/prompts/bkit-debug-abort-handover.md +1 -1
  139. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +1 -1
  140. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +1 -1
  141. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +78 -0
  142. package/.bkit/core/prompts/bkit-debug-failure-soak.md +1 -1
  143. package/.bkit/core/prompts/bkit-debug-summary.md +3 -3
  144. package/.bkit/core/prompts/bkit-design-spike.md +1 -1
  145. package/.bkit/core/prompts/bkit-design-summary.md +2 -2
  146. package/.bkit/core/prompts/bkit-design-update.md +1 -1
  147. package/.bkit/core/prompts/bkit-plan-complexity-check.md +1 -1
  148. package/.bkit/core/prompts/bkit-plan-generate.md +1 -1
  149. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +1 -1
  150. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +1 -1
  151. package/.bkit/core/prompts/bkit-plan-summary.md +1 -1
  152. package/.bkit/core/prompts/bkit-plan-update.md +1 -1
  153. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +1 -1
  154. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +1 -1
  155. package/.bkit/core/prompts/bkit-ship-update-docs.md +1 -1
  156. package/.bkit/core/prompts/bkit-utility-update-decisions.md +9 -2
  157. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +9 -2
  158. package/.bkit/core/prompts/bkit-utility-update-documentation.md +2 -1
  159. package/.bkit/core/prompts/bkit-utility-update-failures.md +9 -2
  160. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +9 -2
  161. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +11 -4
  162. package/.bkit/core/workflows/bkit-auto.md +2 -2
  163. package/.bkit/core/workflows/bkit-build.md +10 -10
  164. package/.bkit/core/workflows/bkit-debug.md +80 -44
  165. package/.bkit/core/workflows/bkit-design.md +22 -13
  166. package/.bkit/core/workflows/bkit-plan.md +33 -16
  167. package/.bkit/core/workflows/bkit-ship.md +87 -98
  168. package/.bkit/shared/.claude/bkit-cloud.md +58 -25
  169. package/.bkit/shared/.claude/settings.json +19 -0
  170. package/.bkit/shared/.cursor/mcp.json +2 -1
  171. package/.bkit/shared/.opencode/opencode.json +19 -1
  172. package/.bkit/shared/docs/deployments.md +49 -29
  173. package/.bkit/shared/docs/security.md +8 -6
  174. package/.bkit/shared/docs/testing.md +9 -5
  175. package/.bkit/shared/gitignore +1 -2
  176. package/.bkit/templates/.cursor/Dockerfile +30 -16
  177. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +78 -0
  178. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +91 -0
  179. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +56 -0
  180. package/.bkit/templates/.github/renovate.json5 +91 -12
  181. package/.bkit/templates/.github/workflows/bkit-ci.yml +73 -55
  182. package/.bkit/templates/.github/workflows/bkit-cloud.yml +3 -1
  183. package/.bkit/templates/.github/workflows/bkit-renovate.yml +8 -1
  184. package/.bkit/templates/.github/workflows/bkit-trivy.yml +67 -0
  185. package/.bkit/templates/.husky/pre-commit +6 -0
  186. package/.bkit/templates/.husky/pre-push +15 -3
  187. package/.bkit/templates/.lintstagedrc.json +5 -1
  188. package/.bkit/templates/.oxlintrc.json +21 -0
  189. package/.bkit/templates/docs/capabilities.md +1 -1
  190. package/.bkit/templates/scripts/ci/check-capstone.mjs +176 -0
  191. package/.bkit/templates/scripts/ci/check-capstone.test.mjs +311 -0
  192. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.machine.mjs +197 -0
  193. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +164 -0
  194. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +2 -2
  195. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +43 -20
  196. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +33 -11
  197. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -2
  198. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +5 -5
  199. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +79 -19
  200. package/CHANGELOG.md +98 -3
  201. package/README.md +252 -122
  202. package/dist/checks/after/auth.js +10 -11
  203. package/dist/checks/after/ci-yml.js +11 -14
  204. package/dist/checks/after/github.js +32 -125
  205. package/dist/checks/after/index.js +3 -2
  206. package/dist/checks/after/managed.js +8 -24
  207. package/dist/checks/after/tools.js +3 -16
  208. package/dist/checks/before/context-fetch.js +1 -21
  209. package/dist/checks/before/index.js +6 -42
  210. package/dist/checks/before/mcp.js +14 -9
  211. package/dist/checks/before/repo.js +8 -11
  212. package/dist/checks/status-holes.js +5 -7
  213. package/dist/checks/tips/catalogue.js +65 -18
  214. package/dist/checks/tips/detect.js +41 -2
  215. package/dist/checks/tips/index.js +61 -25
  216. package/dist/cli.js +52 -26
  217. package/dist/commands/analysis.js +21 -5
  218. package/dist/commands/comply.js +40 -31
  219. package/dist/commands/harvest.js +12 -13
  220. package/dist/commands/install/doctor.js +55 -23
  221. package/dist/commands/install/install.js +72 -122
  222. package/dist/commands/install/uninstall.js +165 -31
  223. package/dist/commands/install/upgrade.js +46 -39
  224. package/dist/commands/land.js +129 -0
  225. package/dist/commands/lib.js +41 -16
  226. package/dist/commands/registry.js +2 -0
  227. package/dist/commands/tips.js +10 -3
  228. package/dist/commands/workflow/branches.js +303 -248
  229. package/dist/commands/workflow/counters.js +17 -7
  230. package/dist/commands/workflow/disk.js +452 -0
  231. package/dist/commands/workflow/fids.js +39 -0
  232. package/dist/commands/workflow/issues.js +63 -27
  233. package/dist/commands/workflow/ledgers.js +3 -1
  234. package/dist/commands/workflow/locks.js +35 -130
  235. package/dist/commands/workflow/prs.js +8 -5
  236. package/dist/commands/workflow/repo.js +2 -2
  237. package/dist/commands/workflow/roadmap.js +50 -57
  238. package/dist/commands/workflow/runs.js +5 -5
  239. package/dist/commands/workflow/runtime.js +3 -2
  240. package/dist/commands/workflow/status.js +32 -12
  241. package/dist/commands/workflow/steps.js +19 -11
  242. package/dist/commands/workflow/tests.js +16 -3
  243. package/dist/commands/workflow/workflows.js +390 -249
  244. package/dist/commands/workflow/workstreams.js +4 -2
  245. package/dist/commands/workflow/worktrees.js +15 -6
  246. package/dist/install/cloud-env.js +10 -23
  247. package/dist/install/manifest.js +14 -7
  248. package/dist/install/modules/antigravity.js +15 -26
  249. package/dist/install/modules/claude.js +17 -21
  250. package/dist/install/modules/cloud.js +6 -2
  251. package/dist/install/modules/codex.js +15 -29
  252. package/dist/install/modules/core.js +95 -63
  253. package/dist/install/modules/cursor.js +6 -9
  254. package/dist/install/modules/index.js +6 -1
  255. package/dist/install/modules/opencode.js +41 -72
  256. package/dist/install/network-allowlist.js +62 -0
  257. package/dist/install/placeholders.js +16 -35
  258. package/dist/install/write.js +55 -15
  259. package/dist/ledgers/telemetry.js +5 -4
  260. package/dist/render/hosts.js +30 -55
  261. package/dist/render/models.js +20 -9
  262. package/dist/shared/branches.js +11 -0
  263. package/dist/shared/egress.js +0 -2
  264. package/dist/shared/json.js +14 -0
  265. package/dist/shared/package-json.js +61 -0
  266. package/dist/shared/package-roots.js +0 -8
  267. package/dist/shared/protected-paths.js +5 -122
  268. package/dist/shared/settings.js +23 -1
  269. package/dist/shared/timeouts.js +8 -7
  270. package/package.json +21 -17
  271. package/.bkit/core/.agents/shortcuts.md +0 -73
@@ -154,7 +154,17 @@ function textVerb(ctx: RunContext): number {
154
154
  // ---------------------------------------------------------------------------
155
155
 
156
156
  /** Mutually exclusive: setting one drops the others. */
157
- export const PHASE_LABELS = ["bkit:design", "bkit:plan", "bkit:build", "bkit:ship", "bkit:merged"];
157
+ export const PHASE_LABELS = [
158
+ "bkit:design",
159
+ "bkit:plan",
160
+ "bkit:build",
161
+ "bkit:debug",
162
+ "bkit:ship",
163
+ "bkit:merged",
164
+ ];
165
+
166
+ /** Prefix of the labels naming an issue's next best workflow; setting a phase drops them. */
167
+ export const NEXT_LABEL_PREFIX = "next:";
158
168
 
159
169
  /** The issue label that opts a feature into CI auto-routing. */
160
170
  export const AUTO_LABEL = "bkit:auto";
@@ -164,7 +174,6 @@ export const AUTO_ROUTE_SUFFIX = " bkit [auto route]";
164
174
  export interface LabelTransition {
165
175
  phase?: string;
166
176
  failed?: boolean;
167
- debug?: boolean;
168
177
  }
169
178
 
170
179
  export function transitionLabels(current: string[], t: LabelTransition) {
@@ -178,10 +187,12 @@ export function transitionLabels(current: string[], t: LabelTransition) {
178
187
  if (t.phase !== undefined) {
179
188
  const label = `bkit:${t.phase}`;
180
189
  for (const l of have) if (PHASE_LABELS.includes(l) && l !== label) remove.add(l);
190
+ for (const l of have) if (l.startsWith(NEXT_LABEL_PREFIX)) remove.add(l);
181
191
  want(label, true);
182
192
  }
183
- if (t.failed !== undefined) want("bkit:failed", t.failed);
184
- if (t.debug !== undefined) want("bkit:debug", t.debug);
193
+ // A phase starting supersedes any earlier Failure Path.
194
+ const failed = t.failed ?? (t.phase !== undefined ? false : undefined);
195
+ if (failed !== undefined) want("bkit:failed", failed);
185
196
  return {
186
197
  add,
187
198
  remove: [...remove],
@@ -191,11 +202,11 @@ export function transitionLabels(current: string[], t: LabelTransition) {
191
202
 
192
203
  /**
193
204
  * Linear's issue state for the same transition, as the workflows set it: a
194
- * shipped, failed or debugged issue waits on a human ("In Review"); a phase
205
+ * shipped or failed issue waits on a human ("In Review"); a phase
195
206
  * starting is "In Progress". Null when the transition sets no state.
196
207
  */
197
208
  export function linearState(t: LabelTransition, board: string | undefined): string | null {
198
- if (t.phase === "merged" || t.failed === true || t.debug === true) return "In Review";
209
+ if (t.phase === "merged" || t.failed === true) return "In Review";
199
210
  if (t.phase !== undefined) return "In Progress";
200
211
  if (board === "review") return "In Review";
201
212
  if (board === "progress") return "In Progress";
@@ -288,21 +299,19 @@ function boardPayload(
288
299
  function labelsVerb(ctx: RunContext): number {
289
300
  const phase = str(ctx.flags.phase);
290
301
  if (phase !== undefined && !PHASE_LABELS.includes(`bkit:${phase}`)) {
291
- throw new CommandError(EXIT.USAGE, "--phase must be design, plan, build, ship, or merged");
292
- }
293
- let failed = onOff(ctx.flags.failed, "failed");
294
- const debug = onOff(ctx.flags.debug, "debug");
295
- // A merged issue must not keep a stale Failure Path marker.
296
- if (phase === "merged") {
297
- if (failed === true)
298
- throw new CommandError(EXIT.USAGE, "--phase=merged clears bkit:failed; drop --failed=on");
299
- failed = false;
302
+ throw new CommandError(
303
+ EXIT.USAGE,
304
+ "--phase must be design, plan, build, debug, ship, or merged",
305
+ );
300
306
  }
307
+ const failed = onOff(ctx.flags.failed, "failed");
308
+ if (phase !== undefined && failed === true)
309
+ throw new CommandError(EXIT.USAGE, "--phase clears bkit:failed; drop --failed=on");
301
310
  const board = str(ctx.flags.board);
302
311
  if (board !== undefined && BOARD_OPTION[board] === undefined) {
303
312
  throw new CommandError(EXIT.USAGE, "--board must be progress or review");
304
313
  }
305
- const t: LabelTransition = { phase, failed, debug };
314
+ const t: LabelTransition = { phase, failed };
306
315
  const { add, remove, labels } = transitionLabels(
307
316
  (ctx.flags.label as string[] | undefined) ?? [],
308
317
  t,
@@ -383,7 +392,9 @@ function fenced(text: string): string {
383
392
 
384
393
  /** Everything one `###### bkit:generated` comment is built from. */
385
394
  export interface CommentInput {
386
- kind?: "step" | "failure" | "handover";
395
+ kind?: "step" | "failure" | "handover" | "audit";
396
+ /** Audit: the template slug in `### Audit Summary: <slug>`. */
397
+ auditSlug?: string;
387
398
  /** With `workflowHeading`: Step 1 puts `## <Workflow>` above the step. */
388
399
  workflow?: string;
389
400
  workflowHeading?: boolean;
@@ -401,7 +412,7 @@ export interface CommentInput {
401
412
  prNumber?: string;
402
413
  prUrl?: string;
403
414
  runId?: string;
404
- /** Repo paths linked at `ref` (default `tree`). */
415
+ /** Repo paths linked at `ref` (default `tree`); `path#Heading` links that section. */
405
416
  artifacts?: string[];
406
417
  ref?: string;
407
418
  lines?: string[];
@@ -429,13 +440,37 @@ function links(o: CommentInput): string[] {
429
440
  if (artifacts.length) {
430
441
  const ref = o.ref ?? o.tree;
431
442
  if (ref === undefined) throw new CommandError(EXIT.USAGE, "--artifact needs --ref (or --tree)");
432
- for (const a of artifacts)
433
- out.push(`[${path.basename(a)}](${gh}/blob/${ref}/${a.replace(/^\/+/, "")})`);
443
+ for (const a of artifacts) {
444
+ const hash = a.indexOf("#");
445
+ const file = (hash < 0 ? a : a.slice(0, hash)).replace(/^\/+/, "");
446
+ const heading = hash < 0 ? undefined : a.slice(hash + 1).trim();
447
+ if (heading === "")
448
+ throw new CommandError(EXIT.USAGE, `--artifact "${a}" has an empty #Heading`);
449
+ const url = `${gh}/blob/${ref}/${file}`;
450
+ out.push(
451
+ heading === undefined
452
+ ? `[${path.basename(file)}](${url})`
453
+ : `[${path.basename(file)} § ${heading}](${url}#${headingAnchor(heading)})`,
454
+ );
455
+ }
434
456
  }
435
457
  return out;
436
458
  }
437
459
 
438
- const KINDS = ["step", "failure", "handover"];
460
+ /**
461
+ * GitHub's anchor for a markdown heading: lowercased, punctuation dropped,
462
+ * spaces to hyphens. A repeated heading's later copies take `-1`, `-2`; this
463
+ * names the first.
464
+ */
465
+ export function headingAnchor(heading: string): string {
466
+ return heading
467
+ .trim()
468
+ .toLowerCase()
469
+ .replace(/[^\p{L}\p{M}\p{N}\p{Pc} -]/gu, "")
470
+ .replace(/ /g, "-");
471
+ }
472
+
473
+ const KINDS = ["step", "failure", "handover", "audit"];
439
474
 
440
475
  /** The exact comment body; files (`bodyFile`, `sections`, `stderrFile`, `errorFile`) resolve against `cwd`. */
441
476
  export function buildComment(cwd: string, o: CommentInput): string {
@@ -490,6 +525,14 @@ export function buildComment(cwd: string, o: CommentInput): string {
490
525
  const captured = tail(readInput(cwd, o.stderrFile, "stderr-file"), 20);
491
526
  if (captured.trim() !== "") lines.push("Stderr:", fenced(captured));
492
527
  }
528
+ } else if (kind === "audit") {
529
+ const slug = o.auditSlug;
530
+ if (slug === undefined || !/^[a-z0-9-]+$/.test(slug)) {
531
+ throw new CommandError(EXIT.USAGE, "--kind=audit needs --audit-slug=<template slug>");
532
+ }
533
+ lines.push(
534
+ [`### Audit Summary: ${slug}`, ...(o.fields ?? []).map(([k, v]) => `${k}: ${v}`)].join(" - "),
535
+ );
493
536
  } else {
494
537
  lines.push("### Workflow Handover");
495
538
  }
@@ -522,11 +565,12 @@ export function commentBody(ctx: RunContext): string {
522
565
  }
523
566
  return buildComment(ctx.cwd, {
524
567
  kind: kind as CommentInput["kind"],
568
+ auditSlug: str(ctx.flags.auditSlug),
525
569
  workflow: str(ctx.flags.workflow),
526
570
  workflowHeading: ctx.flags.workflowHeading === true,
527
571
  stepNumber: str(ctx.flags.stepNumber),
528
572
  stepTitle: str(ctx.flags.stepTitle),
529
- fields: kind === "step" ? headerFields(ctx) : [],
573
+ fields: kind === "step" || kind === "audit" ? headerFields(ctx) : [],
530
574
  subStep: str(ctx.flags.subStep),
531
575
  error: str(ctx.flags.error),
532
576
  errorFile: str(ctx.flags.errorFile),
@@ -578,10 +622,9 @@ export const issuesCommand: CommandSpec = {
578
622
  {
579
623
  name: "phase",
580
624
  type: "string",
581
- help: "set this phase: design | plan | build | ship | merged",
625
+ help: "set this phase: design | plan | build | debug | ship | merged (drops next:* and bkit:failed)",
582
626
  },
583
- { name: "failed", type: "string", help: "bkit:failed on | off (merged implies off)" },
584
- { name: "debug", type: "string", help: "bkit:debug on | off" },
627
+ { name: "failed", type: "string", help: "bkit:failed on | off (a phase implies off)" },
585
628
  {
586
629
  name: "board",
587
630
  type: "string",
@@ -604,9 +647,11 @@ export const issuesCommand: CommandSpec = {
604
647
  run: labelsVerb,
605
648
  },
606
649
  comment: {
607
- summary: "The exact body of a ###### bkit:generated step, failure, or handover comment.",
650
+ summary:
651
+ "The exact body of a ###### bkit:generated step, failure, handover, or audit comment.",
608
652
  flags: [
609
- { name: "kind", type: "string", help: "step (default) | failure | handover" },
653
+ { name: "kind", type: "string", help: "step (default) | failure | handover | audit" },
654
+ { name: "audit-slug", type: "string", help: "audit: template slug, e.g. security" },
610
655
  { name: "step-number", type: "string", help: "step number in the heading" },
611
656
  { name: "step-title", type: "string", help: "step title in the heading, e.g. Plan Verify" },
612
657
  { name: "workflow", type: "string", help: "design | plan | build | debug | ship | auto" },
@@ -637,7 +682,7 @@ export const issuesCommand: CommandSpec = {
637
682
  name: "artifact",
638
683
  type: "string",
639
684
  repeatable: true,
640
- help: "link this repo path at --ref",
685
+ help: "link this repo path at --ref; path#Heading links that section",
641
686
  },
642
687
  { name: "ref", type: "string", help: "ref the --artifact links point at (default --tree)" },
643
688
  { name: "line", type: "string", repeatable: true, help: "a raw line after the links" },
@@ -91,7 +91,9 @@ function gitRaw(cwd: string, args: string[]): GitResult {
91
91
  env: gitEnv(),
92
92
  maxBuffer: 1 << 28,
93
93
  });
94
- return { status: res.status, stdout: res.stdout ?? "", stderr: (res.stderr ?? "").trim() };
94
+ // A spawn error is never a success: the child can exit 0 before ENOBUFS kills it.
95
+ const status = res.error && res.status === 0 ? 1 : res.status;
96
+ return { status, stdout: res.stdout ?? "", stderr: (res.stderr ?? "").trim() };
95
97
  }
96
98
 
97
99
  const nulList = (out: string) => out.split("\0").filter((p) => p !== "");
@@ -1,16 +1,13 @@
1
- // bkit locks acquire|release — the per-feature workflow lock and the dev lock.
1
+ // bkit locks acquire|release — the per-feature workflow lock.
2
2
  //
3
- // workflow `docs/plans/{month}/logs/{fid}/.lock`: one phase workflow per feature
4
- // at a time. A lock left behind is reclaimed as soon as its holder is
5
- // idle: its run is not IN_PROGRESS, or stepped no sooner than 30 minutes
6
- // ago. The lock file's own age is not checked.
7
- // dev `.bkit/.dev.lock` in the main checkout: held across every checkout /
8
- // commit / push of `dev` there. Acquire waits a bounded time; the shell
9
- // releases it from `trap ... EXIT`.
3
+ // `docs/plans/{month}/logs/{fid}/.lock` in the main checkout: one phase workflow
4
+ // per feature at a time. A lock left behind is reclaimed as soon as its holder is
5
+ // idle: its run is not IN_PROGRESS, or stepped no sooner than 30 minutes ago. The
6
+ // lock file's own age is not checked.
10
7
  //
11
- // Both write one line, `{at} {workflow} {fid} {token}`. Release removes only a lock
12
- // this caller owns (same token, else same workflow and feature), so a Failure Path
13
- // that never got the lock cannot delete the holder's.
8
+ // The lock holds one line, `{at} {workflow} {fid} {token}`. Release removes only a
9
+ // lock this caller owns (same token, else same workflow and feature), so a Failure
10
+ // Path that never got the lock cannot delete the holder's.
14
11
 
15
12
  import { randomBytes } from "node:crypto";
16
13
  import * as fs from "node:fs";
@@ -26,7 +23,6 @@ import {
26
23
  import {
27
24
  CommandError,
28
25
  EXIT,
29
- git,
30
26
  parseJson,
31
27
  repoRoot,
32
28
  statusRelPath,
@@ -35,13 +31,10 @@ import {
35
31
  type FlagSpec,
36
32
  type RunContext,
37
33
  } from "../lib.js";
38
- import { TIMEOUTS } from "../../shared/timeouts.js";
39
34
  import { str } from "./status.js";
40
35
 
41
36
  /** A workflow lock whose holder shows no sign of life for this long is stale. */
42
37
  export const WORKFLOW_LOCK_IDLE_S = 1800;
43
- /** Seconds between dev-lock attempts while it is busy. */
44
- export const DEV_LOCK_POLL_S = 5;
45
38
 
46
39
  /** Exit code: the feature has logs in more than one month bucket. */
47
40
  export const EXIT_SPLIT_BUCKET = 7;
@@ -50,7 +43,7 @@ export const EXIT_NOT_OWNER = 4;
50
43
  /** Exit code: the lock file is still there after removing it. */
51
44
  export const EXIT_REMOVE_FAILED = 5;
52
45
 
53
- const KINDS = ["workflow", "dev"] as const;
46
+ const KINDS = ["workflow"] as const;
54
47
  type Kind = (typeof KINDS)[number];
55
48
 
56
49
  // ---------------------------------------------------------------------------
@@ -92,20 +85,9 @@ export function resolveMonth(root: string, fid: string, month: string | undefine
92
85
  return buckets[0] ?? utcMonth();
93
86
  }
94
87
 
95
- /**
96
- * Root the workflow books its logs under: the main checkout, except ship in a
97
- * runtime that does not push to dev, which books on the branch being shipped.
98
- */
99
- export function lockRoot(cwd: string, workflow: string, devPushes: boolean): string {
100
- const root = repoRoot(cwd);
101
- if (workflow !== "ship" || devPushes) return root;
102
- return git(cwd, ["rev-parse", "--show-toplevel"]) ?? root;
103
- }
104
-
105
- export const workflowLockPath = (bookRoot: string, month: string, fid: string) =>
106
- path.join(bookRoot, "docs", "plans", month, "logs", fid, ".lock");
107
-
108
- export const devLockPath = (root: string) => path.join(root, ".bkit", ".dev.lock");
88
+ /** The feature's workflow lock, in the main checkout `root` (gitignored). */
89
+ export const workflowLockPath = (root: string, month: string, fid: string) =>
90
+ path.join(root, "docs", "plans", month, "logs", fid, ".lock");
109
91
 
110
92
  // ---------------------------------------------------------------------------
111
93
  // Lock file
@@ -127,7 +109,7 @@ export function readHolder(file: string): Holder | undefined {
127
109
  }
128
110
 
129
111
  /** Create `file` only if absent (`set -C`); false when someone else holds it. */
130
- function tryCreate(file: string, line: string): boolean {
112
+ export function tryCreate(file: string, line: string): boolean {
131
113
  fs.mkdirSync(path.dirname(file), { recursive: true });
132
114
  const fd = openExclusive(file);
133
115
  if (fd === undefined) return false;
@@ -146,11 +128,6 @@ function openExclusive(file: string): number | undefined {
146
128
  }
147
129
  }
148
130
 
149
- const ageSeconds = (file: string, now: number): number | undefined => {
150
- const st = fs.statSync(file, { throwIfNoEntry: false });
151
- return st === undefined ? undefined : Math.floor((now - st.mtimeMs) / 1000);
152
- };
153
-
154
131
  const newToken = () => randomBytes(4).toString("hex");
155
132
 
156
133
  const lockLine = (workflow: string, fid: string, token: string) =>
@@ -177,7 +154,6 @@ export interface WorkflowLockResult {
177
154
  /** Why a held workflow lock is still live, or why it may be reclaimed. */
178
155
  function liveReason(
179
156
  root: string,
180
- bookRoot: string,
181
157
  month: string,
182
158
  fid: string,
183
159
  holder: Holder,
@@ -185,7 +161,7 @@ function liveReason(
185
161
  ): { live: string } | { reason: "finished" | "stale" | "orphaned" } {
186
162
  const rel = statusRelPath(month, fid);
187
163
  const worktreeCopy = path.join(root, ".worktrees", fid, rel);
188
- const own = fs.existsSync(worktreeCopy) ? worktreeCopy : path.join(bookRoot, rel);
164
+ const own = fs.existsSync(worktreeCopy) ? worktreeCopy : path.join(root, rel);
189
165
  const run =
190
166
  holder.workflow === undefined ? undefined : lastRun(readRunsLenient(own), holder.workflow);
191
167
  const lastAt = run?.steps.at(-1)?.at;
@@ -219,19 +195,17 @@ export function acquireWorkflowLock(opts: {
219
195
  workflow: string;
220
196
  fid: string;
221
197
  month?: string;
222
- devPushes: boolean;
223
198
  log: (m: string) => void;
224
199
  }): WorkflowLockResult {
225
200
  const root = repoRoot(opts.cwd);
226
201
  const month = resolveMonth(root, opts.fid, opts.month);
227
- const bookRoot = lockRoot(opts.cwd, opts.workflow, opts.devPushes);
228
- const file = workflowLockPath(bookRoot, month, opts.fid);
202
+ const file = workflowLockPath(root, month, opts.fid);
229
203
  const token = newToken();
230
204
  const line = lockLine(opts.workflow, opts.fid, token);
231
205
  if (tryCreate(file, line)) return { path: file, month, token, reclaimed: null };
232
206
 
233
207
  const holder = readHolder(file) ?? { line: "" };
234
- const verdict = liveReason(root, bookRoot, month, opts.fid, holder, Date.now());
208
+ const verdict = liveReason(root, month, opts.fid, holder, Date.now());
235
209
  if ("live" in verdict) {
236
210
  throw new CommandError(
237
211
  EXIT.NO,
@@ -244,47 +218,6 @@ export function acquireWorkflowLock(opts: {
244
218
  return { path: file, month, token, reclaimed: { holder: holder.line, reason: verdict.reason } };
245
219
  }
246
220
 
247
- // ---------------------------------------------------------------------------
248
- // Dev lock
249
- // ---------------------------------------------------------------------------
250
-
251
- const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
252
-
253
- export async function acquireDevLock(opts: {
254
- cwd: string;
255
- workflow: string;
256
- fid: string;
257
- deadlineS: number;
258
- log: (m: string) => void;
259
- }): Promise<{ path: string; token: string; reclaimed: string | null; waitedS: number }> {
260
- const file = devLockPath(repoRoot(opts.cwd));
261
- const token = newToken();
262
- const start = Date.now();
263
- const deadline = start + opts.deadlineS * 1000;
264
- let reclaimed: string | null = null;
265
- for (;;) {
266
- if (tryCreate(file, lockLine(opts.workflow, opts.fid, token))) {
267
- return { path: file, token, reclaimed, waitedS: Math.round((Date.now() - start) / 1000) };
268
- }
269
- const now = Date.now();
270
- const age = ageSeconds(file, now);
271
- if (age === undefined) continue; // released between the attempt and the stat
272
- if (age >= TIMEOUTS.SHIP_DEV_LOCK_STALE_S) {
273
- reclaimed = readHolder(file)?.line ?? "";
274
- opts.log(`reclaiming stale dev lock (${age}s old): ${reclaimed}`);
275
- fs.rmSync(file, { force: true });
276
- continue;
277
- }
278
- if (now >= deadline) {
279
- throw new CommandError(
280
- EXIT.NO,
281
- `dev lock held by: ${readHolder(file)?.line ?? "?"} — serialise this run or use a separate clone`,
282
- );
283
- }
284
- await sleep(Math.min(DEV_LOCK_POLL_S * 1000, deadline - now));
285
- }
286
- }
287
-
288
221
  // ---------------------------------------------------------------------------
289
222
  // Release
290
223
  // ---------------------------------------------------------------------------
@@ -324,7 +257,7 @@ const KIND_FLAG: FlagSpec = {
324
257
  name: "kind",
325
258
  type: "string",
326
259
  required: true,
327
- help: "workflow (per-feature .lock) or dev (.bkit/.dev.lock)",
260
+ help: "workflow (the per-feature .lock)",
328
261
  };
329
262
  const LOCK_WORKFLOW_FLAG: FlagSpec = {
330
263
  name: "workflow",
@@ -338,83 +271,41 @@ const MONTH_FLAG: FlagSpec = {
338
271
  type: "string",
339
272
  help: "workflow kind: month bucket YYYYMM (default: the feature's bucket, else this UTC month)",
340
273
  };
341
- const DEV_PUSHES_FLAG: FlagSpec = {
342
- name: "dev-pushes",
343
- type: "boolean",
344
- help: "ship only: this runtime pushes to dev (lock lives in the main checkout)",
345
- };
346
274
 
347
275
  function kindOf(ctx: RunContext): Kind {
348
276
  const kind = String(ctx.flags.kind);
349
277
  if (!(KINDS as readonly string[]).includes(kind))
350
- throw new CommandError(EXIT.USAGE, "--kind must be workflow or dev");
278
+ throw new CommandError(EXIT.USAGE, "--kind must be workflow");
351
279
  return kind as Kind;
352
280
  }
353
281
 
354
- function deadlineOf(ctx: RunContext): number {
355
- const raw = str(ctx.flags.deadline);
356
- if (raw === undefined) return TIMEOUTS.SHIP_DEV_LOCK_ACQUIRE_DEADLINE_S;
357
- if (!/^[0-9]+$/.test(raw))
358
- throw new CommandError(EXIT.USAGE, `--deadline must be whole seconds, got "${raw}"`);
359
- return Number(raw);
360
- }
361
-
362
282
  export const locksCommand: CommandSpec = {
363
283
  noun: "locks",
364
- summary: "Acquire and release the per-feature workflow lock and the dev lock.",
284
+ summary: "Acquire and release the per-feature workflow lock.",
365
285
  verbs: {
366
286
  acquire: {
367
- summary: "Take a lock: workflow (reclaims a dead holder's) or dev (bounded wait).",
368
- flags: [
369
- KIND_FLAG,
370
- LOCK_WORKFLOW_FLAG,
371
- FID_FLAG,
372
- MONTH_FLAG,
373
- DEV_PUSHES_FLAG,
374
- {
375
- name: "deadline",
376
- type: "string",
377
- help: `dev kind: seconds to wait for a busy lock (default ${TIMEOUTS.SHIP_DEV_LOCK_ACQUIRE_DEADLINE_S})`,
378
- },
379
- ],
287
+ summary: "Take the workflow lock, reclaiming a dead holder's.",
288
+ flags: [KIND_FLAG, LOCK_WORKFLOW_FLAG, FID_FLAG, MONTH_FLAG],
380
289
  output: {
381
- kind: "workflow or dev",
290
+ kind: "workflow",
382
291
  path: "absolute path of the lock file",
383
292
  token: "this holder's token; pass it to release",
384
- month: "workflow kind: the month bucket (null for dev)",
385
- reclaimed:
386
- "workflow kind: {holder, reason: finished|stale|orphaned}; dev kind: the stale line; null when none",
387
- waitedS: "dev kind: seconds spent waiting (null for workflow)",
293
+ month: "the month bucket",
294
+ reclaimed: "{holder, reason: finished|stale|orphaned}; null when none",
388
295
  },
389
296
  exitCodes: {
390
- [EXIT_SPLIT_BUCKET]: "workflow kind: the feature has logs in more than one month bucket",
297
+ [EXIT_SPLIT_BUCKET]: "the feature has logs in more than one month bucket",
391
298
  },
392
- run: async (ctx) => {
299
+ run: (ctx) => {
393
300
  const kind = kindOf(ctx);
394
- const workflow = String(ctx.flags.workflow);
395
- const fid = String(ctx.flags.fid);
396
- if (kind === "workflow") {
397
- if (ctx.flags.deadline !== undefined)
398
- throw new CommandError(EXIT.USAGE, "--deadline applies to --kind=dev only");
399
- const lock = acquireWorkflowLock({
400
- cwd: ctx.cwd,
401
- workflow,
402
- fid,
403
- month: str(ctx.flags.month),
404
- devPushes: ctx.flags.devPushes === true,
405
- log: ctx.log,
406
- });
407
- ctx.emit({ kind, ...lock, waitedS: null });
408
- return EXIT.OK;
409
- }
410
- const lock = await acquireDevLock({
301
+ const lock = acquireWorkflowLock({
411
302
  cwd: ctx.cwd,
412
- workflow,
413
- fid,
414
- deadlineS: deadlineOf(ctx),
303
+ workflow: String(ctx.flags.workflow),
304
+ fid: String(ctx.flags.fid),
305
+ month: str(ctx.flags.month),
415
306
  log: ctx.log,
416
307
  });
417
- ctx.emit({ kind, ...lock, month: null });
308
+ ctx.emit({ kind, ...lock });
418
309
  return EXIT.OK;
419
310
  },
420
311
  },
@@ -425,7 +316,6 @@ export const locksCommand: CommandSpec = {
425
316
  LOCK_WORKFLOW_FLAG,
426
317
  FID_FLAG,
427
318
  MONTH_FLAG,
428
- DEV_PUSHES_FLAG,
429
319
  {
430
320
  name: "token",
431
321
  type: "string",
@@ -433,15 +323,14 @@ export const locksCommand: CommandSpec = {
433
323
  },
434
324
  ],
435
325
  output: {
436
- kind: "workflow or dev",
326
+ kind: "workflow",
437
327
  path: "absolute path of the lock file",
438
328
  existed: "a lock file was there",
439
329
  released: "this call removed it",
440
330
  heldBy: "the other owner's lock line when it was left in place, else null",
441
331
  },
442
332
  exitCodes: {
443
- [EXIT_SPLIT_BUCKET]:
444
- "workflow kind without --month: the feature has logs in more than one month bucket",
333
+ [EXIT_SPLIT_BUCKET]: "no --month and the feature has logs in more than one month bucket",
445
334
  [EXIT_NOT_OWNER]: "the lock belongs to another owner and was left in place",
446
335
  [EXIT_REMOVE_FAILED]: "the lock file is still there after removing it",
447
336
  },
@@ -453,14 +342,11 @@ export const locksCommand: CommandSpec = {
453
342
  token: str(ctx.flags.token),
454
343
  };
455
344
  const root = repoRoot(ctx.cwd);
456
- const file =
457
- kind === "dev"
458
- ? devLockPath(root)
459
- : workflowLockPath(
460
- lockRoot(ctx.cwd, who.workflow, ctx.flags.devPushes === true),
461
- resolveMonth(root, who.fid, str(ctx.flags.month)),
462
- who.fid,
463
- );
345
+ const file = workflowLockPath(
346
+ root,
347
+ resolveMonth(root, who.fid, str(ctx.flags.month)),
348
+ who.fid,
349
+ );
464
350
  const { removeFailed, ...result } = releaseLock(file, who);
465
351
  ctx.emit({ kind, ...result });
466
352
  if (removeFailed) {
@@ -16,9 +16,11 @@ import { appendLine, statusTimestamp, type StatusRow } from "../../ledgers/statu
16
16
  import {
17
17
  bodySkipToken,
18
18
  CommandError,
19
+ DEV,
19
20
  EXIT,
20
21
  ghUnavailable,
21
22
  git,
23
+ isSharedBranch,
22
24
  parseJson,
23
25
  repoRoot,
24
26
  runGh,
@@ -241,9 +243,9 @@ export function openPrFor(cwd: string, o: OpenInput, log: (m: string) => void):
241
243
  return { code: EXIT_SKIP_CI_TITLE, out: null };
242
244
  }
243
245
 
244
- const base = refFlag(o.base ?? "dev", "base");
246
+ const base = refFlag(o.base ?? DEV, "base");
245
247
  const head = o.head === undefined ? currentBranch(cwd) : refFlag(o.head, "head");
246
- if (head === base || head === "dev" || head === "main") {
248
+ if (head === base || isSharedBranch(head)) {
247
249
  throw new CommandError(EXIT.USAGE, `refusing to open a PR from "${head}" into "${base}"`);
248
250
  }
249
251
 
@@ -618,17 +620,26 @@ export function crossCheckFile(
618
620
  file: string,
619
621
  transport: string,
620
622
  log: (m: string) => void,
623
+ ): { ok: boolean; runtimeGithubCli: boolean | null; transport: string; fallbackRows: number } {
624
+ return crossCheckRows(readStatusRows(file), file, transport, log);
625
+ }
626
+
627
+ /** crossCheckFile over rows already read; `label` names where they came from. */
628
+ export function crossCheckRows(
629
+ rows: StatusRow[],
630
+ label: string,
631
+ transport: string,
632
+ log: (m: string) => void,
621
633
  ): { ok: boolean; runtimeGithubCli: boolean | null; transport: string; fallbackRows: number } {
622
634
  if (!TRANSPORTS.includes(transport)) {
623
635
  throw new CommandError(EXIT.USAGE, `--transport must be ${TRANSPORTS.join(", ")}`);
624
636
  }
625
- const rows = readStatusRows(file);
626
637
  const runtimeGithubCli = capability(lastRow(rows, "runtime-resolved")?.runtimeGithubCli);
627
638
  const fallbackRows = rows.filter((r) => r.type === "transport-fallback").length;
628
639
  const violated = runtimeGithubCli === false && transport === "mcp" && fallbackRows === 0;
629
640
  if (violated) {
630
641
  log(
631
- `runtime-resolved logged runtimeGithubCli=false and this close used transport mcp, but no transport-fallback row exists in ${file}`,
642
+ `runtime-resolved logged runtimeGithubCli=false and this close used transport mcp, but no transport-fallback row exists in ${label}`,
632
643
  );
633
644
  }
634
645
  return { ok: !violated, runtimeGithubCli, transport, fallbackRows };
@@ -11,7 +11,7 @@ import * as fs from "node:fs";
11
11
  import * as path from "node:path";
12
12
 
13
13
  import { parseRemoteUrlToSlug } from "../../ledgers/telemetry.js";
14
- import { EXIT, git, repoRoot, runGit, runTool, type CommandSpec } from "../lib.js";
14
+ import { DEV, EXIT, git, repoRoot, runGit, runTool, type CommandSpec } from "../lib.js";
15
15
  import { bkitVersionStatus } from "../../shared/bkit-latest.js";
16
16
 
17
17
  /** Exit code: neither gh nor the origin remote named an owner/repo. */
@@ -137,7 +137,7 @@ export const repoCommand: CommandSpec = {
137
137
  },
138
138
  run: (ctx) => {
139
139
  if (ctx.flags.fetch === true) {
140
- const res = runGit(ctx.cwd, ["fetch", "origin", "dev"]);
140
+ const res = runGit(ctx.cwd, ["fetch", "origin", DEV]);
141
141
  if (!res.ok)
142
142
  ctx.log(
143
143
  `git fetch origin dev failed — behindDev is as of the last fetch: ${res.stderr}`,