@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
@@ -0,0 +1,156 @@
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]`).
8
+
9
+ import * as fs from "node:fs";
10
+ import * as path from "node:path";
11
+ import { CommandError, DEV, EXIT, git, runGit } from "./lib.js";
12
+ import { TIMEOUTS } from "../shared/timeouts.js";
13
+
14
+ const REMOTE = "origin";
15
+ const UPSTREAM = `${REMOTE}/${DEV}`;
16
+
17
+ /** dev moved before git sent anything: git compared the remote's dev and stopped. */
18
+ const MOVED_BEFORE = /\[rejected\][^\n]*\((?:fetch first|non-fast-forward)\)/;
19
+ /** dev moved while the push was in flight: the server's ref update lost the race. */
20
+ const MOVED_DURING =
21
+ /\[remote rejected\][^\n]*\((?:incorrect old value provided|cannot lock ref[^\n]*)\)/;
22
+ /** The server turned the push away: branch protection, a ruleset, an HTTP 403. */
23
+ const REFUSED = /\[remote rejected\]|returned error: 403|\bGH0\d\d\b/;
24
+
25
+ /** A dev push rejected only because dev moved: rebuild on the new dev, push again. */
26
+ export const devMoved = (stderr: string) => MOVED_BEFORE.test(stderr) || MOVED_DURING.test(stderr);
27
+
28
+ /** A dev push the server refused for a reason other than dev moving. */
29
+ export const devRefused = (stderr: string) => !devMoved(stderr) && REFUSED.test(stderr);
30
+
31
+ /**
32
+ * Milliseconds to wait before retry `retry` (1-based) of a landing: `startS`
33
+ * doubling per retry, capped at `capS`, then jittered down by up to half so two
34
+ * landings that collided once do not retry in step.
35
+ */
36
+ export function landBackoffMs(
37
+ retry: number,
38
+ random: () => number = Math.random,
39
+ startS: number = TIMEOUTS.LAND_BACKOFF_START_S,
40
+ capS: number = TIMEOUTS.LAND_BACKOFF_CAP_S,
41
+ ): number {
42
+ const s = Math.min(startS * 2 ** (retry - 1), capS);
43
+ return Math.round(s * 1000 * (0.5 + random() / 2));
44
+ }
45
+
46
+ export const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
47
+
48
+ /** A FID names one folder: no separators, no `..`. */
49
+ const SAFE_FID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
50
+
51
+ /** The throwaway checkout a landing is built in, beside the feature worktrees. */
52
+ export function landDir(root: string, fid: string): string {
53
+ if (!SAFE_FID.test(fid) || fid.includes(".."))
54
+ throw new CommandError(EXIT.USAGE, `--fid "${fid}" is not a feature id`);
55
+ return path.join(root, ".worktrees", `_land-${fid}`);
56
+ }
57
+
58
+ /**
59
+ * Remove a throwaway checkout. A landing killed inside `worktree add` leaves it
60
+ * locked ("initializing"), which a single `--force` and `prune` both skip, so it
61
+ * is unlocked first; a folder git no longer lists is the landing's own scratch.
62
+ */
63
+ export function dropLandTree(root: string, dir: string): void {
64
+ runGit(root, ["worktree", "unlock", dir]);
65
+ if (fs.existsSync(dir)) runGit(root, ["worktree", "remove", "--force", "--force", dir]);
66
+ runGit(root, ["worktree", "prune"]);
67
+ if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true, force: true });
68
+ }
69
+
70
+ /** `core.hooksPath` pointing nowhere, so no hook runs. */
71
+ const NO_HOOKS = process.platform === "win32" ? "NUL" : "/dev/null";
72
+
73
+ /**
74
+ * Run `fn` with git hooks off for every git child it starts: one more
75
+ * `GIT_CONFIG_*` entry (git >= 2.31) setting `core.hooksPath`, restored after.
76
+ */
77
+ export async function withoutHooks<T>(fn: () => T | Promise<T>): Promise<T> {
78
+ const saved = process.env.GIT_CONFIG_COUNT;
79
+ const n = Number(saved ?? 0) || 0;
80
+ const key = `GIT_CONFIG_KEY_${n}`;
81
+ const value = `GIT_CONFIG_VALUE_${n}`;
82
+ process.env.GIT_CONFIG_COUNT = String(n + 1);
83
+ process.env[key] = "core.hooksPath";
84
+ process.env[value] = NO_HOOKS;
85
+ try {
86
+ return await fn();
87
+ } finally {
88
+ if (saved === undefined) delete process.env.GIT_CONFIG_COUNT;
89
+ else process.env.GIT_CONFIG_COUNT = saved;
90
+ delete process.env[key];
91
+ delete process.env[value];
92
+ }
93
+ }
94
+
95
+ export type DevPush =
96
+ | { kind: "landed"; sha: string; attempts: number }
97
+ /** The server refused for a reason other than dev moving (branch protection, a ruleset, a 403). */
98
+ | { kind: "refused"; stderr: string }
99
+ /** The push failed without a server answer (network, credentials): nothing landed, no PR. */
100
+ | { kind: "push-failed"; stderr: string }
101
+ /** dev moved before every one of LAND_ATTEMPTS pushes. */
102
+ | { kind: "exhausted"; attempts: number }
103
+ | { kind: "fetch-failed"; stderr: string }
104
+ | { kind: "setup-failed"; stderr: string };
105
+
106
+ /**
107
+ * Land one commit on dev: per attempt, fetch dev, add `dir` detached at
108
+ * origin/dev, let `build` make the commit there, push `HEAD:dev` — git hooks
109
+ * off. `build` throwing stops the landing with that throw. A server refusal runs
110
+ * `refused` on the built commit first, when given. `dir` is removed on every path.
111
+ */
112
+ export async function pushToDev(o: {
113
+ root: string;
114
+ dir: string;
115
+ build: (dir: string, attempt: number) => void;
116
+ refused?: (dir: string, stderr: string) => Promise<void>;
117
+ log: (line: string) => void;
118
+ }): Promise<DevPush> {
119
+ o.log("git hooks skipped in the throwaway dev checkout — it lands bookkeeping only");
120
+ for (let attempt = 1; ; attempt++) {
121
+ let wait = 0;
122
+ dropLandTree(o.root, o.dir);
123
+ try {
124
+ const outcome = await withoutHooks(async (): Promise<DevPush | null> => {
125
+ const fetched = runGit(o.root, ["fetch", REMOTE, DEV]);
126
+ if (!fetched.ok) return { kind: "fetch-failed", stderr: fetched.stderr };
127
+ const added = runGit(o.root, ["worktree", "add", "--detach", o.dir, UPSTREAM]);
128
+ if (!added.ok) return { kind: "setup-failed", stderr: added.stderr };
129
+ o.build(o.dir, attempt);
130
+ const pushed = runGit(o.dir, ["push", REMOTE, `HEAD:${DEV}`]);
131
+ if (pushed.ok) {
132
+ return {
133
+ kind: "landed",
134
+ sha: git(o.dir, ["rev-parse", "HEAD"]) ?? "",
135
+ attempts: attempt,
136
+ };
137
+ }
138
+ if (devRefused(pushed.stderr)) {
139
+ await o.refused?.(o.dir, pushed.stderr);
140
+ return { kind: "refused", stderr: pushed.stderr };
141
+ }
142
+ if (!devMoved(pushed.stderr)) return { kind: "push-failed", stderr: pushed.stderr };
143
+ return null;
144
+ });
145
+ if (outcome !== null) return outcome;
146
+ if (attempt >= TIMEOUTS.LAND_ATTEMPTS) return { kind: "exhausted", attempts: attempt };
147
+ wait = landBackoffMs(attempt);
148
+ o.log(
149
+ `dev moved before push ${attempt} of ${TIMEOUTS.LAND_ATTEMPTS} — rebuilding on the new dev in ${(wait / 1000).toFixed(1)}s`,
150
+ );
151
+ } finally {
152
+ dropLandTree(o.root, o.dir);
153
+ }
154
+ await sleep(wait);
155
+ }
156
+ }
@@ -3,9 +3,9 @@
3
3
  // Flag parsing, one JSON object on stdout, `[bkit-<noun>]`-tagged logs on stderr,
4
4
  // the exit-code table, `--help` rendering, and the repo facts several workflow
5
5
  // steps each re-derived by hand: repo root, UTC month, where `status.jsonl` lives,
6
- // and the skip-CI tokens. A command declares its flags, output keys and exit codes
7
- // in its spec; `--help` and the convention test both read that spec, so the help
8
- // text cannot drift from what the command accepts.
6
+ // the skip-CI tokens, and which branches are shared. A command declares its flags,
7
+ // output keys and exit codes in its spec; `--help` and the convention test both read
8
+ // that spec, so the help text cannot drift from what the command accepts.
9
9
 
10
10
  import { spawnSync } from "node:child_process";
11
11
  import * as fs from "node:fs";
@@ -331,16 +331,34 @@ export async function runCommand(
331
331
  // Repo facts
332
332
  // ---------------------------------------------------------------------------
333
333
 
334
+ /** Captured stdout / stderr cap for `runGit` / `runTool`; hook output (pre-push) counts. */
335
+ const OUTPUT_LIMIT = 1 << 26;
336
+
337
+ /** Spawn error as a stderr lead line: ENOBUFS names the limit, anything else Node's message. */
338
+ function spawnErrorText(cmd: string, args: string[], err: NodeJS.ErrnoException): string {
339
+ return err.code === "ENOBUFS"
340
+ ? `${cmd} ${args[0] ?? ""}: output passed the ${OUTPUT_LIMIT / (1 << 20)} MiB limit (ENOBUFS)`
341
+ : err.message;
342
+ }
343
+
334
344
  /** `git <args>` in `cwd`, never throwing: exit status plus trimmed stdout / stderr. */
335
345
  export function runGit(
336
346
  cwd: string,
337
347
  args: string[],
338
348
  ): { ok: boolean; stdout: string; stderr: string } {
339
- const res = spawnSync("git", args, { cwd, encoding: "utf-8", env: gitEnv() });
349
+ const res = spawnSync("git", args, {
350
+ cwd,
351
+ encoding: "utf-8",
352
+ env: gitEnv(),
353
+ maxBuffer: OUTPUT_LIMIT,
354
+ });
355
+ const stderr = (res.stderr ?? "").trim();
340
356
  return {
341
- ok: res.status === 0,
357
+ ok: !res.error && res.status === 0,
342
358
  stdout: (res.stdout ?? "").trim(),
343
- stderr: (res.stderr ?? "").trim(),
359
+ stderr: res.error
360
+ ? [spawnErrorText("git", args, res.error), stderr].filter(Boolean).join("\n")
361
+ : stderr,
344
362
  };
345
363
  }
346
364
 
@@ -355,6 +373,9 @@ export function git(cwd: string, args: string[]): string | null {
355
373
  // for the command modules that already import it from this module.
356
374
  export { parseJson } from "../shared/json.js";
357
375
 
376
+ // The shared-branch rule (`dev`, `main`) lives in shared/ so checks can read it too.
377
+ export { DEV, isSharedBranch } from "../shared/branches.js";
378
+
358
379
  export interface ToolResult {
359
380
  /** False when the binary is not on PATH (or could not be spawned). */
360
381
  found: boolean;
@@ -379,16 +400,20 @@ export function runTool(
379
400
  encoding: "utf-8",
380
401
  env: gitEnv(),
381
402
  input: opts.input,
382
- maxBuffer: 1 << 26,
403
+ maxBuffer: OUTPUT_LIMIT,
383
404
  });
384
- if (res.error) {
405
+ if (res.error && res.pid === 0) {
385
406
  return { found: false, status: 127, stdout: "", stderr: `${cmd} not found on PATH` };
386
407
  }
408
+ const status = res.status ?? 128 + signalNumber(res.signal);
387
409
  return {
388
410
  found: true,
389
- status: res.status ?? 128 + signalNumber(res.signal),
411
+ // A spawn error is never a success: the child can exit 0 before ENOBUFS kills it.
412
+ status: res.error && status === 0 ? 1 : status,
390
413
  stdout: res.stdout ?? "",
391
- stderr: res.stderr ?? "",
414
+ stderr: res.error
415
+ ? [spawnErrorText(cmd, args, res.error), res.stderr ?? ""].filter(Boolean).join("\n")
416
+ : (res.stderr ?? ""),
392
417
  };
393
418
  }
394
419
 
@@ -417,8 +442,13 @@ export function runGh(cwd: string, args: string[], input?: string): GhResult {
417
442
  };
418
443
  }
419
444
 
420
- /** gh cannot serve this call here: not installed, or exit 4 (not logged in). */
421
- export const ghUnavailable = (res: GhResult): boolean => res.missing || res.status === 4;
445
+ /**
446
+ * gh cannot serve this call here: not installed, exit 4 (not logged in), or an
447
+ * HTTP 403 — a token or proxy that may not use this API, where the GitHub MCP
448
+ * (its own credentials) can.
449
+ */
450
+ export const ghUnavailable = (res: GhResult): boolean =>
451
+ res.missing || res.status === 4 || (!res.ok && /\bHTTP 403\b/.test(res.stderr));
422
452
 
423
453
  /**
424
454
  * The main checkout's root, from any worktree. `--git-common-dir` points at the
@@ -451,22 +481,19 @@ export interface StatusLocation {
451
481
  *
452
482
  * - design / plan / build / debug: the feature worktree's copy when it exists
453
483
  * (`.worktrees/{fid}`), else the main checkout's.
454
- * - ship: the main checkout when this runtime pushes to dev, else the current
455
- * worktree's top (the branch being shipped). An unresolved runtime takes the
456
- * least-capable answer: current worktree.
484
+ * - ship: the current worktree's top — the tree ship works in (the feature
485
+ * worktree, or the adopted checkout), so asked from inside it.
457
486
  */
458
487
  export function statusLocation(opts: {
459
488
  cwd: string;
460
489
  workflow: string;
461
490
  fid: string;
462
491
  month: string;
463
- devPushes?: boolean;
464
492
  }): StatusLocation {
465
493
  const root = repoRoot(opts.cwd);
466
494
  const rel = statusRelPath(opts.month, opts.fid);
467
495
  if (opts.workflow === "ship") {
468
- const bookRoot =
469
- opts.devPushes === true ? root : (git(opts.cwd, ["rev-parse", "--show-toplevel"]) ?? root);
496
+ const bookRoot = git(opts.cwd, ["rev-parse", "--show-toplevel"]) ?? root;
470
497
  return { bookRoot, path: path.join(bookRoot, rel) };
471
498
  }
472
499
  const worktree = path.join(root, ".worktrees", opts.fid);
@@ -11,6 +11,7 @@ import { setupCommand } from "./setup/setup.js";
11
11
  import { branchesCommand } from "./workflow/branches.js";
12
12
  import { contextCommand } from "./workflow/context.js";
13
13
  import { countersCommand } from "./workflow/counters.js";
14
+ import { diskCommand } from "./workflow/disk.js";
14
15
  import { fidsCommand } from "./workflow/fids.js";
15
16
  import { issuesCommand } from "./workflow/issues.js";
16
17
  import { ledgersCommand } from "./workflow/ledgers.js";
@@ -39,6 +40,7 @@ export const COMMANDS: readonly CommandSpec[] = [
39
40
  locksCommand,
40
41
  workflowsCommand,
41
42
  worktreesCommand,
43
+ diskCommand,
42
44
  branchesCommand,
43
45
  skillsCommand,
44
46
  prsCommand,
@@ -1,16 +1,23 @@
1
1
  // commands/tips.ts — `bkit tips [--workflow=<name>] [--all]`: print the setup tips that
2
2
  // apply to this repo. Each workflow passes its name at its close and gets the one tip that
3
- // matters most there; bare `bkit tips` prints the top three. Local checks only, no
4
- // network; prints nothing when no tip fires; exits 0.
3
+ // matters most there (`audit` / `utility` for the audit agent and the ledger / roadmap
4
+ // updaters); bare `bkit tips` prints the top three. The star line closes bare and phase
5
+ // output unless `bkit-star` is in `bkit.ignoreAdvisories`. Local checks only, no network; prints
6
+ // nothing when no tip fires and no star line shows; exits 0. What the last disk clean-up left
7
+ // for the person to decide (`bkit disk prune` notes) comes first, outside the tip cap.
5
8
 
6
- import type { ComplyPhase } from "../cli.js";
9
+ import type { TipsContext } from "../cli.js";
7
10
  import { collectTips, formatTips } from "../checks/tips/index.js";
11
+ import { formatNotes, readNotes } from "./workflow/disk.js";
8
12
 
9
13
  export function runTipsCommand(
10
14
  all: boolean,
11
- workflow: ComplyPhase | null,
15
+ workflow: TipsContext | null,
12
16
  cwd: string = process.cwd(),
13
17
  ): void {
14
- const output = formatTips(collectTips(cwd).tips, { all, workflow });
18
+ const { tips, star } = collectTips(cwd);
19
+ const output = [formatNotes(readNotes(cwd)), formatTips(tips, { all, workflow, star })]
20
+ .filter((part) => part !== "")
21
+ .join("\n\n");
15
22
  if (output) console.log(output);
16
23
  }