@cbartens/bkit 6.1.0 → 6.2.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 (317) hide show
  1. package/.bkit/README.md +14 -12
  2. package/.bkit/core/.agents/docs.md +1 -11
  3. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +30 -9
  4. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +25 -27
  5. package/.bkit/core/.agents/rules.md +22 -9
  6. package/.bkit/core/.bkit/README.md +13 -11
  7. package/.bkit/core/.bkit/authoring.md +58 -13
  8. package/.bkit/core/.bkit/cli.md +43 -33
  9. package/.bkit/core/.bkit/cloud.md +93 -30
  10. package/.bkit/core/.bkit/install.md +55 -16
  11. package/.bkit/core/.bkit/jsonl.md +24 -7
  12. package/.bkit/core/.bkit/pipeline.md +8 -8
  13. package/.bkit/core/.bkit/prompts.md +160 -43
  14. package/.bkit/core/.bkit/providers.md +99 -36
  15. package/.bkit/core/.bkit/templates.md +167 -37
  16. package/.bkit/core/.bkit/trackers.md +39 -6
  17. package/.bkit/core/.bkit/workflows.md +344 -136
  18. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +50 -27
  19. package/.bkit/core/.claude/hooks/bkit-preflight.sh +11 -11
  20. package/.bkit/core/.codex/hooks/bkit-gateguard.cjs +13 -8
  21. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +14 -25
  22. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +20 -9
  23. package/.bkit/core/.cursor/hooks/bkit-preflight.sh +8 -8
  24. package/.bkit/core/.opencode/plugin/bkit-gateguard.js +14 -4
  25. package/.bkit/core/.opencode/plugin/bkit-guardrails.js +114 -0
  26. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +1 -1
  27. package/.bkit/core/docs/templates/bkit-audit-adoption.md +30 -6
  28. package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
  29. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
  30. package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
  31. package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
  32. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
  33. package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
  34. package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
  35. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +2 -2
  36. package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
  37. package/.bkit/core/docs/templates/bkit-audit-cost.md +1 -1
  38. package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
  39. package/.bkit/core/docs/templates/bkit-audit-database.md +3 -3
  40. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +1 -1
  41. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
  42. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +3 -3
  43. package/.bkit/core/docs/templates/bkit-audit-documentation.md +32 -2
  44. package/.bkit/core/docs/templates/bkit-audit-duplication.md +1 -1
  45. package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
  46. package/.bkit/core/docs/templates/bkit-audit-flakes.md +2 -2
  47. package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -3
  48. package/.bkit/core/docs/templates/bkit-audit-issues.md +1 -1
  49. package/.bkit/core/docs/templates/bkit-audit-llm.md +2 -2
  50. package/.bkit/core/docs/templates/bkit-audit-logs.md +1 -1
  51. package/.bkit/core/docs/templates/bkit-audit-models.md +2 -2
  52. package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
  53. package/.bkit/core/docs/templates/bkit-audit-prompts.md +1 -1
  54. package/.bkit/core/docs/templates/bkit-audit-red-team.md +2 -2
  55. package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
  56. package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
  57. package/.bkit/core/docs/templates/bkit-audit-security.md +1 -1
  58. package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
  59. package/.bkit/core/docs/templates/bkit-audit-testing.md +3 -2
  60. package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
  61. package/.bkit/core/docs/templates/bkit-plan.md +38 -8
  62. package/.bkit/core/engine/checks/after/auth.ts +118 -47
  63. package/.bkit/core/engine/checks/after/github.ts +161 -37
  64. package/.bkit/core/engine/checks/after/index.ts +18 -3
  65. package/.bkit/core/engine/checks/after/tools.ts +245 -1
  66. package/.bkit/core/engine/checks/before/files.ts +59 -1
  67. package/.bkit/core/engine/checks/before/index.ts +8 -0
  68. package/.bkit/core/engine/checks/status-holes.ts +20 -26
  69. package/.bkit/core/engine/checks/tips/catalogue.ts +107 -10
  70. package/.bkit/core/engine/checks/tips/detect.ts +36 -3
  71. package/.bkit/core/engine/checks/tips/index.ts +1 -1
  72. package/.bkit/core/engine/cli.ts +13 -13
  73. package/.bkit/core/engine/commands/ci/ci.ts +124 -19
  74. package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
  75. package/.bkit/core/engine/commands/install/doctor.ts +5 -5
  76. package/.bkit/core/engine/commands/install/install.ts +28 -25
  77. package/.bkit/core/engine/commands/install/uninstall.ts +42 -30
  78. package/.bkit/core/engine/commands/install/upgrade.ts +14 -2
  79. package/.bkit/core/engine/commands/land.ts +2 -3
  80. package/.bkit/core/engine/commands/lib.ts +394 -39
  81. package/.bkit/core/engine/commands/registry.ts +1 -1
  82. package/.bkit/core/engine/commands/workflow/branches.ts +351 -78
  83. package/.bkit/core/engine/commands/workflow/challenge.ts +63 -14
  84. package/.bkit/core/engine/commands/workflow/context.ts +71 -10
  85. package/.bkit/core/engine/commands/workflow/counters.ts +298 -23
  86. package/.bkit/core/engine/commands/workflow/decisions.ts +260 -125
  87. package/.bkit/core/engine/commands/workflow/disk.ts +2 -1
  88. package/.bkit/core/engine/commands/workflow/feature-base.ts +66 -0
  89. package/.bkit/core/engine/commands/workflow/issues.ts +312 -17
  90. package/.bkit/core/engine/commands/workflow/junit.ts +204 -0
  91. package/.bkit/core/engine/commands/workflow/ledgers.ts +904 -99
  92. package/.bkit/core/engine/commands/workflow/locks.ts +186 -29
  93. package/.bkit/core/engine/commands/workflow/loops.ts +87 -0
  94. package/.bkit/core/engine/commands/workflow/open-decision.ts +251 -0
  95. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +8 -0
  96. package/.bkit/core/engine/commands/workflow/plans.ts +1 -1
  97. package/.bkit/core/engine/commands/workflow/prs.ts +311 -16
  98. package/.bkit/core/engine/commands/workflow/repo.ts +1 -1
  99. package/.bkit/core/engine/commands/workflow/run-facts.ts +6 -0
  100. package/.bkit/core/engine/commands/workflow/runs.ts +877 -174
  101. package/.bkit/core/engine/commands/workflow/runtime.ts +12 -4
  102. package/.bkit/core/engine/commands/workflow/status.ts +324 -11
  103. package/.bkit/core/engine/commands/workflow/step-table.ts +41 -15
  104. package/.bkit/core/engine/commands/workflow/steps.ts +604 -29
  105. package/.bkit/core/engine/commands/workflow/summary-findings.ts +1 -1
  106. package/.bkit/core/engine/commands/workflow/summary.ts +314 -8
  107. package/.bkit/core/engine/commands/workflow/tasks.ts +400 -27
  108. package/.bkit/core/engine/commands/workflow/tests-base.ts +319 -0
  109. package/.bkit/core/engine/commands/workflow/tests-changed.ts +138 -74
  110. package/.bkit/core/engine/commands/workflow/tests-jump.ts +93 -0
  111. package/.bkit/core/engine/commands/workflow/tests.ts +815 -182
  112. package/.bkit/core/engine/commands/workflow/tracker.ts +1134 -137
  113. package/.bkit/core/engine/commands/workflow/workflows.ts +100 -72
  114. package/.bkit/core/engine/commands/workflow/worktrees.ts +421 -57
  115. package/.bkit/core/engine/install/cloud-env.ts +38 -10
  116. package/.bkit/core/engine/install/managed-block.ts +105 -0
  117. package/.bkit/core/engine/install/manifest.ts +7 -1
  118. package/.bkit/core/engine/install/modules/claude.ts +6 -2
  119. package/.bkit/core/engine/install/modules/cloud.ts +84 -95
  120. package/.bkit/core/engine/install/modules/codex.ts +10 -2
  121. package/.bkit/core/engine/install/modules/core.ts +202 -26
  122. package/.bkit/core/engine/install/modules/opencode.ts +18 -23
  123. package/.bkit/core/engine/install/network-allowlist.ts +8 -3
  124. package/.bkit/core/engine/install/project-docs.ts +650 -0
  125. package/.bkit/core/engine/install/template-copies.ts +58 -5
  126. package/.bkit/core/engine/install/write.ts +128 -7
  127. package/.bkit/core/engine/ledgers/journal.ts +18 -10
  128. package/.bkit/core/engine/ledgers/migrate.ts +20 -8
  129. package/.bkit/core/engine/ledgers/status.ts +604 -8
  130. package/.bkit/core/engine/ledgers/telemetry.ts +115 -13
  131. package/.bkit/core/engine/render/trackers.ts +46 -11
  132. package/.bkit/core/engine/shared/package-manager.ts +7 -3
  133. package/.bkit/core/engine/shared/settings.ts +12 -1
  134. package/.bkit/core/engine/shared/text.ts +14 -0
  135. package/.bkit/core/engine/tools/instructions-sources.ts +1 -0
  136. package/.bkit/core/engine/tools/instructions.ts +116 -20
  137. package/.bkit/core/hooks/antigravity-hook.js +20 -4
  138. package/.bkit/core/hooks/gateguard-edit-payload.js +8 -5
  139. package/.bkit/core/hooks/gateguard-engine.js +249 -23
  140. package/.bkit/core/hooks/guardrails-deny.js +167 -0
  141. package/.bkit/core/hooks/guardrails-read.js +3 -3
  142. package/.bkit/core/hooks/guardrails-shell.js +1122 -167
  143. package/.bkit/core/hooks/guardrails-tiers.js +247 -176
  144. package/.bkit/core/hooks/preflight-tracker.sh +219 -0
  145. package/.bkit/core/prompts/bkit-audit-generate.md +23 -6
  146. package/.bkit/core/prompts/bkit-build-challenge-1.md +5 -4
  147. package/.bkit/core/prompts/bkit-build-challenge-2.md +6 -5
  148. package/.bkit/core/prompts/bkit-build-install-skills.md +2 -2
  149. package/.bkit/core/prompts/bkit-build-plan-convert.md +21 -7
  150. package/.bkit/core/prompts/bkit-build-plan-current.md +5 -4
  151. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +22 -17
  152. package/.bkit/core/prompts/bkit-build-plan-tasks.md +16 -12
  153. package/.bkit/core/prompts/bkit-build-plan-tests.md +14 -10
  154. package/.bkit/core/prompts/bkit-build-plan-verify.md +21 -8
  155. package/.bkit/core/prompts/bkit-debug-abort-handover.md +10 -5
  156. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +22 -6
  157. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +19 -3
  158. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +22 -6
  159. package/.bkit/core/prompts/bkit-debug-failure-soak.md +10 -7
  160. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +3 -3
  161. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +4 -4
  162. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +3 -3
  163. package/.bkit/core/prompts/bkit-design-generate.md +6 -4
  164. package/.bkit/core/prompts/bkit-design-organise.md +4 -3
  165. package/.bkit/core/prompts/bkit-design-review-1.md +5 -4
  166. package/.bkit/core/prompts/bkit-design-review-2.md +6 -5
  167. package/.bkit/core/prompts/bkit-design-spike.md +4 -3
  168. package/.bkit/core/prompts/bkit-design-update.md +6 -4
  169. package/.bkit/core/prompts/bkit-plan-generate.md +35 -14
  170. package/.bkit/core/prompts/bkit-plan-review-1.md +9 -7
  171. package/.bkit/core/prompts/bkit-plan-review-2.md +9 -7
  172. package/.bkit/core/prompts/bkit-plan-scope-check.md +8 -6
  173. package/.bkit/core/prompts/bkit-plan-update.md +22 -8
  174. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +11 -8
  175. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +9 -5
  176. package/.bkit/core/prompts/bkit-ship-update-docs.md +26 -4
  177. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +3 -3
  178. package/.bkit/core/prompts/bkit-utility-update-decisions.md +10 -7
  179. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +8 -5
  180. package/.bkit/core/prompts/bkit-utility-update-documentation.md +31 -7
  181. package/.bkit/core/prompts/bkit-utility-update-failures.md +8 -5
  182. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +10 -7
  183. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +4 -4
  184. package/.bkit/core/prompts/bkit-utility-update-tracker.md +4 -4
  185. package/.bkit/core/workflows/bkit-auto.md +23 -11
  186. package/.bkit/core/workflows/bkit-build.md +331 -100
  187. package/.bkit/core/workflows/bkit-debug.md +135 -64
  188. package/.bkit/core/workflows/bkit-design.md +58 -32
  189. package/.bkit/core/workflows/bkit-plan.md +73 -45
  190. package/.bkit/core/workflows/bkit-ship.md +233 -167
  191. package/.bkit/shared/.agents/plugins/bkit/hooks.json +1 -1
  192. package/.bkit/shared/.bkit/.env.example +5 -0
  193. package/.bkit/shared/.claude/bkit-cloud.md +7 -7
  194. package/.bkit/shared/.claude/settings.json +5 -1
  195. package/.bkit/shared/.cursor/bkit-cloud.md +1 -1
  196. package/.bkit/shared/.cursor/hooks.json +1 -1
  197. package/.bkit/shared/.opencode/opencode.json +11 -2
  198. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +27 -0
  199. package/.bkit/templates/.cursor/Dockerfile +7 -7
  200. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +1 -1
  201. package/.bkit/templates/.github/dependabot.yml +5 -0
  202. package/.bkit/templates/.github/renovate.json5 +5 -3
  203. package/.bkit/templates/.github/workflows/bkit-ci.yml +11 -11
  204. package/.bkit/templates/.github/workflows/bkit-cloud.yml +525 -161
  205. package/.bkit/templates/.github/workflows/bkit-renovate.yml +2 -2
  206. package/.bkit/templates/.husky/pre-push +123 -6
  207. package/.bkit/templates/context/bkit-serena.md +1 -1
  208. package/.bkit/templates/context/bkit-vercel.md +103 -59
  209. package/.bkit/templates/docs/architecture.md +98 -0
  210. package/.bkit/templates/docs/capabilities.md +33 -37
  211. package/.bkit/templates/docs/components.md +142 -0
  212. package/.bkit/templates/docs/data-schema.md +87 -0
  213. package/.bkit/{shared → templates}/docs/deployments.md +128 -142
  214. package/.bkit/templates/docs/design.md +117 -0
  215. package/.bkit/templates/docs/noise.md +54 -0
  216. package/.bkit/templates/docs/observability.md +99 -0
  217. package/.bkit/templates/docs/security.md +137 -0
  218. package/.bkit/templates/docs/setup.md +93 -0
  219. package/.bkit/templates/docs/technology.md +70 -0
  220. package/.bkit/{shared → templates}/docs/testing.md +200 -87
  221. package/.bkit/templates/scripts/ci/bkit-check-accepted-divergences.mjs +1 -6
  222. package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
  223. package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +314 -28
  224. package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +500 -1
  225. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
  226. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +91 -62
  227. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
  228. package/.bkit/templates/slop-scan.config.json +2 -0
  229. package/CHANGELOG.md +79 -0
  230. package/DETAILS.md +661 -0
  231. package/README.md +73 -604
  232. package/dist/checks/after/auth.js +114 -46
  233. package/dist/checks/after/github.js +138 -35
  234. package/dist/checks/after/index.js +16 -4
  235. package/dist/checks/after/tools.js +224 -1
  236. package/dist/checks/before/files.js +59 -1
  237. package/dist/checks/before/index.js +7 -1
  238. package/dist/checks/status-holes.js +20 -21
  239. package/dist/checks/tips/catalogue.js +99 -10
  240. package/dist/checks/tips/detect.js +35 -3
  241. package/dist/checks/tips/index.js +1 -1
  242. package/dist/cli.js +13 -13
  243. package/dist/commands/ci/ci.js +113 -20
  244. package/dist/commands/ci/push-gate.js +79 -44
  245. package/dist/commands/install/doctor.js +5 -5
  246. package/dist/commands/install/install.js +23 -22
  247. package/dist/commands/install/uninstall.js +36 -30
  248. package/dist/commands/install/upgrade.js +10 -2
  249. package/dist/commands/land.js +2 -3
  250. package/dist/commands/lib.js +323 -25
  251. package/dist/commands/workflow/branches.js +312 -72
  252. package/dist/commands/workflow/challenge.js +66 -13
  253. package/dist/commands/workflow/context.js +46 -10
  254. package/dist/commands/workflow/counters.js +231 -23
  255. package/dist/commands/workflow/decisions.js +221 -106
  256. package/dist/commands/workflow/disk.js +2 -1
  257. package/dist/commands/workflow/feature-base.js +60 -0
  258. package/dist/commands/workflow/issues.js +243 -15
  259. package/dist/commands/workflow/junit.js +137 -0
  260. package/dist/commands/workflow/ledgers.js +726 -112
  261. package/dist/commands/workflow/locks.js +150 -29
  262. package/dist/commands/workflow/loops.js +67 -0
  263. package/dist/commands/workflow/open-decision.js +199 -0
  264. package/dist/commands/workflow/plan-blocks.js +6 -0
  265. package/dist/commands/workflow/plans.js +1 -1
  266. package/dist/commands/workflow/prs.js +272 -16
  267. package/dist/commands/workflow/repo.js +1 -1
  268. package/dist/commands/workflow/run-facts.js +6 -0
  269. package/dist/commands/workflow/runs.js +747 -155
  270. package/dist/commands/workflow/runtime.js +8 -4
  271. package/dist/commands/workflow/status.js +259 -13
  272. package/dist/commands/workflow/step-table.js +41 -15
  273. package/dist/commands/workflow/steps.js +530 -26
  274. package/dist/commands/workflow/summary-findings.js +1 -1
  275. package/dist/commands/workflow/summary.js +289 -8
  276. package/dist/commands/workflow/tasks.js +294 -27
  277. package/dist/commands/workflow/tests-base.js +266 -0
  278. package/dist/commands/workflow/tests-changed.js +130 -56
  279. package/dist/commands/workflow/tests-jump.js +77 -0
  280. package/dist/commands/workflow/tests.js +608 -131
  281. package/dist/commands/workflow/tracker.js +920 -112
  282. package/dist/commands/workflow/workflows.js +80 -59
  283. package/dist/commands/workflow/worktrees.js +387 -58
  284. package/dist/install/cloud-env.js +32 -10
  285. package/dist/install/managed-block.js +101 -0
  286. package/dist/install/manifest.js +7 -1
  287. package/dist/install/modules/claude.js +6 -2
  288. package/dist/install/modules/cloud.js +73 -86
  289. package/dist/install/modules/codex.js +9 -2
  290. package/dist/install/modules/core.js +190 -27
  291. package/dist/install/modules/opencode.js +18 -23
  292. package/dist/install/network-allowlist.js +8 -3
  293. package/dist/install/project-docs.js +551 -0
  294. package/dist/install/template-copies.js +55 -5
  295. package/dist/install/write.js +117 -5
  296. package/dist/ledgers/journal.js +10 -8
  297. package/dist/ledgers/migrate.js +20 -9
  298. package/dist/ledgers/status.js +461 -8
  299. package/dist/ledgers/telemetry.js +71 -13
  300. package/dist/render/trackers.js +21 -12
  301. package/dist/shared/package-manager.js +7 -2
  302. package/dist/shared/settings.js +8 -0
  303. package/dist/shared/text.js +13 -0
  304. package/dist/tools/instructions-sources.js +1 -0
  305. package/dist/tools/instructions.js +97 -24
  306. package/package.json +23 -15
  307. package/.bkit/core/hooks/preflight-linear.sh +0 -73
  308. package/.bkit/shared/docs/architecture.md +0 -16
  309. package/.bkit/shared/docs/data-schema.md +0 -16
  310. package/.bkit/shared/docs/design.md +0 -38
  311. package/.bkit/shared/docs/noise.md +0 -20
  312. package/.bkit/shared/docs/observability.md +0 -22
  313. package/.bkit/shared/docs/security.md +0 -62
  314. package/.bkit/shared/docs/setup.md +0 -52
  315. package/.bkit/shared/docs/technology.md +0 -15
  316. /package/.bkit/templates/{.lintstagedrc.json → lintstagedrc.example.json} +0 -0
  317. /package/.bkit/templates/{.prettierignore → prettierignore.example} +0 -0
@@ -4,77 +4,145 @@
4
4
  // changed and hands them to the consumer's `bkit:gate:changed`, which runs the tests that
5
5
  // import them, the tests that name their paths and static checks on them. Undeclared →
6
6
  // the --fallback whole gate runs, exactly as before the script existed.
7
- import { spawnSync } from "node:child_process";
8
7
  import * as fs from "node:fs";
9
8
  import * as os from "node:os";
10
9
  import * as path from "node:path";
11
10
  import { BKIT_GATE_CHANGED_SCRIPT } from "../../install/manifest.js";
12
- import { classifyLockExit, CommandError, EXIT, git, testsLockHolder, wholeNumber, } from "../lib.js";
11
+ import { CommandError, EXIT, git, runGit, wholeNumber } from "../lib.js";
13
12
  import { readPackageJson } from "../../shared/package-json.js";
14
- import { COULD_NOT_RUN_EXIT_CODES, scriptCommand, testCommand, } from "../../shared/package-manager.js";
13
+ import { COULD_NOT_RUN_EXIT_CODES, scriptCommand } from "../../shared/package-manager.js";
14
+ import { runGateUnderLock } from "./junit.js";
15
15
  /** Exit code: neither `bkit:gate:changed` nor the --fallback gate is declared. */
16
16
  const EXIT_NO_GATE = 3;
17
17
  /** Exit code: the gate could not run (exit 126 / 127, or the package runner is missing). */
18
18
  const EXIT_COULD_NOT_RUN = 4;
19
+ /** The NUL-separated paths `git <args>` prints in `top`; none when it fails. */
20
+ const gitPaths = (top, args) => (git(top, args) ?? "").split("\0").filter(Boolean);
19
21
  /**
20
22
  * Files changed since `base`, repo-relative and sorted: uncommitted (staged or not),
21
- * untracked and not ignored, plus every file a commit after `base` touched. A file
22
- * missing from the working tree (deleted) is left out: there is nothing to check.
23
+ * untracked and not ignored, plus every file a commit after `base` touched. Existing
24
+ * files only: a deleted file is a change `deletedFiles` lists, and `importersOf` turns
25
+ * into the files that still mention it.
23
26
  */
24
27
  export function changedFiles(top, base) {
25
- const list = (args) => (git(top, args) ?? "").split("\0").filter(Boolean);
26
28
  const all = new Set([
27
- ...list(["diff", "--name-only", "--no-renames", "-z", "HEAD"]),
28
- ...list(["ls-files", "--others", "--exclude-standard", "-z"]),
29
- ...list(["diff", "--name-only", "--no-renames", "-z", `${base}...HEAD`]),
29
+ ...gitPaths(top, ["diff", "--name-only", "--no-renames", "-z", "HEAD"]),
30
+ ...gitPaths(top, ["ls-files", "--others", "--exclude-standard", "-z"]),
31
+ ...gitPaths(top, ["diff", "--name-only", "--no-renames", "-z", `${base}...HEAD`]),
30
32
  ]);
31
33
  return [...all].filter((f) => fs.existsSync(path.join(top, f))).sort();
32
34
  }
33
- /** Whether `dir/package.json` declares `name` as a non-empty script. */
34
- function declares(dir, name) {
35
- const read = readPackageJson(dir);
36
- const scripts = read.ok ? read.pkg.scripts : undefined;
37
- if (typeof scripts !== "object" || scripts === null)
38
- return false;
39
- const body = scripts[name];
40
- return typeof body === "string" && body.trim() !== "";
41
- }
42
35
  /**
43
- * Run argv in `cwd` with stdout and stderr interleaved, each output line passed to `log`.
44
- * Exit 127 when the binary is missing; 128 + n when killed by signal n.
36
+ * A commit holding the working tree as it is now: tracked files as edited, untracked files
37
+ * that are not ignored, deleted files gone; its parent is HEAD (none before the first
38
+ * commit). It is built in a copy of the index, so no ref, the index and the working tree
39
+ * stay as they were; no ref points at it, and `git gc` prunes it once unreachable objects
40
+ * expire. Null when git cannot build it.
45
41
  */
46
- function runLogged(argv, cwd, log, env) {
47
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-tests-changed-"));
48
- const file = path.join(dir, "out.log");
42
+ export function snapshotTree(top) {
43
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-snapshot-"));
49
44
  try {
50
- const fd = fs.openSync(file, "w");
51
- const protectedArgv = testCommand(argv);
52
- const res = spawnSync(protectedArgv[0], protectedArgv.slice(1), {
53
- cwd,
54
- stdio: ["ignore", fd, fd],
55
- env: { ...process.env, ...env },
56
- });
57
- fs.closeSync(fd);
58
- for (const line of fs
59
- .readFileSync(file, "utf-8")
60
- .replace(/\r?\n$/, "")
61
- .split(/\r?\n/))
62
- if (line !== "")
63
- log(line);
64
- if (res.error) {
65
- log(`${argv[0]}: not found on PATH (${res.error.message})`);
66
- return 127;
67
- }
68
- if (res.status !== null)
69
- return res.status;
70
- return 128 + ((res.signal ? os.constants.signals[res.signal] : undefined) ?? 1);
45
+ const index = path.join(dir, "index");
46
+ const real = git(top, ["rev-parse", "--path-format=absolute", "--git-path", "index"]);
47
+ // The real index's stat data lets `git add -A` skip unchanged files instead of hashing them.
48
+ if (real !== null && fs.existsSync(real))
49
+ fs.copyFileSync(real, index);
50
+ const env = { GIT_INDEX_FILE: index };
51
+ if (!runGit(top, ["add", "-A"], env).ok)
52
+ return null;
53
+ const tree = runGit(top, ["write-tree"], env);
54
+ if (!tree.ok)
55
+ return null;
56
+ const head = git(top, ["rev-parse", "-q", "--verify", "HEAD^{commit}"]);
57
+ const commit = runGit(top, [
58
+ "-c",
59
+ "user.name=bkit",
60
+ "-c",
61
+ "user.email=bkit@localhost",
62
+ "commit-tree",
63
+ "--no-gpg-sign",
64
+ tree.stdout,
65
+ ...(head === null ? [] : ["-p", head]),
66
+ "-m",
67
+ "bkit tested snapshot",
68
+ ]);
69
+ return commit.ok ? commit.stdout : null;
71
70
  }
72
71
  finally {
73
72
  fs.rmSync(dir, { recursive: true, force: true });
74
73
  }
75
74
  }
75
+ /** Whether `sha` names a commit the object store still holds. */
76
+ export const commitExists = (top, sha) => git(top, ["cat-file", "-e", `${sha}^{commit}`]) !== null;
77
+ /**
78
+ * The files that differ between snapshot `from` and the working tree now (`now`, else a
79
+ * fresh `snapshotTree`), sorted: `files` the ones that exist now, `deleted` the ones that do
80
+ * not. Null when `from` is gone from the object store or the tree cannot be snapshotted.
81
+ */
82
+ export function changedBetween(top, from, now = snapshotTree(top)) {
83
+ if (now === null || !commitExists(top, from))
84
+ return null;
85
+ const listed = runGit(top, ["diff", "--name-only", "--no-renames", "-z", from, now]);
86
+ if (!listed.ok)
87
+ return null;
88
+ const all = listed.stdout.split("\0").filter(Boolean).sort();
89
+ const exists = (f) => fs.existsSync(path.join(top, f));
90
+ return { files: all.filter(exists), deleted: all.filter((f) => !exists(f)) };
91
+ }
92
+ /**
93
+ * Files removed since `base`, repo-relative and sorted: deleted in the working tree or
94
+ * the index, or by a commit after `base`, and missing from the working tree now.
95
+ */
96
+ export function deletedFiles(top, base) {
97
+ const all = new Set([
98
+ ...gitPaths(top, ["diff", "--name-only", "--no-renames", "--diff-filter=D", "-z", "HEAD"]),
99
+ ...gitPaths(top, [
100
+ "diff",
101
+ "--name-only",
102
+ "--no-renames",
103
+ "--diff-filter=D",
104
+ "-z",
105
+ `${base}...HEAD`,
106
+ ]),
107
+ ]);
108
+ return [...all].filter((f) => !fs.existsSync(path.join(top, f))).sort();
109
+ }
110
+ /**
111
+ * For each deleted file, the files of the `base` tree that mention its name without the
112
+ * extension (`git grep -l -F`) and still exist, sorted; a file nothing mentions maps to
113
+ * `[]`. Null when a search fails (`base` names no tree, or the tree cannot be read):
114
+ * the caller cannot tell which tests the deletion touches.
115
+ */
116
+ export function importersOf(top, base, deleted) {
117
+ const found = new Map();
118
+ for (const file of deleted) {
119
+ const name = path.basename(file, path.extname(file));
120
+ const res = runGit(top, ["grep", "-l", "-z", "-F", "-e", name, base, "--"]);
121
+ // Exit 1 with nothing on stderr is "no match". Any stderr fails the search: git grep
122
+ // exits 0 when it found a match even though it could not read another blob.
123
+ if (res.stderr !== "")
124
+ return null;
125
+ const prefix = `${base}:`;
126
+ found.set(file, res.stdout
127
+ .split("\0")
128
+ .filter(Boolean)
129
+ .map((hit) => (hit.startsWith(prefix) ? hit.slice(prefix.length) : hit))
130
+ .filter((hit) => !deleted.includes(hit) && fs.existsSync(path.join(top, hit)))
131
+ .sort());
132
+ }
133
+ return found;
134
+ }
135
+ /** Whether `dir/package.json` declares `name` as a non-empty script. */
136
+ export function declares(dir, name) {
137
+ const read = readPackageJson(dir);
138
+ const scripts = read.ok ? read.pkg.scripts : undefined;
139
+ if (typeof scripts !== "object" || scripts === null)
140
+ return false;
141
+ const body = scripts[name];
142
+ return typeof body === "string" && body.trim() !== "";
143
+ }
76
144
  export const testsChangedVerb = {
77
- summary: `Check only the files changed since --base: run \`${BKIT_GATE_CHANGED_SCRIPT}\` with them as arguments, else the --fallback gate; exit 0 PASS or nothing changed, 1 FAIL, 4 could not run, 81 tests lock held.`,
145
+ summary: `Check only the files changed since --base: run \`${BKIT_GATE_CHANGED_SCRIPT}\` with them as arguments, else the --fallback gate; exit 0 PASS or nothing changed, 1 FAIL, 4 could not run, 81 tests lock held (read from the lock status file, never from the exit code alone).`,
78
146
  use: "by-hand",
79
147
  flags: [
80
148
  {
@@ -148,20 +216,26 @@ export const testsChangedVerb = {
148
216
  const scope = scriptCommand(gate).join(" ");
149
217
  ctx.log(`running ${scope}`);
150
218
  const who = `bkit tests changed ${gate}`;
151
- const lines = [];
152
- const exitCode = runLogged(argv, top, (line) => {
153
- lines.push(line);
154
- ctx.log(line);
155
- }, {
156
- LOCAL_STACK_LOCK_WAIT_S: String(waitS),
157
- LOCAL_STACK_LOCK_WHO: who,
158
- });
159
- const log = lines.join("\n");
160
- const lockExit = classifyLockExit({ exitCode, log, who });
219
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-tests-changed-"));
220
+ const log = path.join(dir, "out.log");
221
+ let run;
222
+ try {
223
+ run = runGateUnderLock(argv, top, log, {
224
+ LOCAL_STACK_LOCK_WAIT_S: String(waitS),
225
+ LOCAL_STACK_LOCK_WHO: who,
226
+ });
227
+ for (const line of fs.readFileSync(log, "utf-8").split(/\r?\n/))
228
+ if (line !== "")
229
+ ctx.log(line);
230
+ }
231
+ finally {
232
+ fs.rmSync(dir, { recursive: true, force: true });
233
+ }
234
+ const { exitCode, status: lockStatus, lock: lockExit } = run;
161
235
  const couldNotRun = lockExit === "could-not-run" || COULD_NOT_RUN_EXIT_CODES.has(exitCode);
162
236
  const lockWait = lockExit === "lock-wait";
163
237
  const verdict = couldNotRun || lockWait ? null : exitCode === 0 ? "PASS" : "FAIL";
164
- const lockHolder = lockWait ? testsLockHolder(log, who) : null;
238
+ const lockHolder = lockWait ? (lockStatus?.holder ?? null) : null;
165
239
  ctx.emit({ files, gate, scope, exitCode, verdict, lockHolder });
166
240
  if (lockWait)
167
241
  return EXIT.AGENT_WAIT;
@@ -0,0 +1,77 @@
1
+ // commands/workflow/tests-jump.ts — `bkit tests jump <run>`: move one waiting run to the front
2
+ // of the tests line.
3
+ //
4
+ // The verb asks bkit's own copy of the lock script (the template, never the consumer's copy) to
5
+ // write the jump marker: `bkit-machine-lock.sh jump --lock tests <run> [<checkout>]`. The lock's
6
+ // waiting helpers sort a ticket carrying the marker's line first and delete the marker once the
7
+ // run has the lock. The script never touches the lock, the holder file or a slot file, so the
8
+ // current holder keeps the lock. With no match the verb lists the queue (`queue --lock tests`).
9
+ import { spawnSync } from "node:child_process";
10
+ import * as path from "node:path";
11
+ import { CommandError, EXIT } from "../lib.js";
12
+ import { getTemplatesRoot } from "../../shared/package-roots.js";
13
+ /** Exit code: the lock script could not read the queue or write the jump marker. */
14
+ export const EXIT_JUMP_FAILED = 3;
15
+ /** Run a queue subcommand of the template's lock script on the tests lock. */
16
+ function lockScript(args) {
17
+ const script = path.join(getTemplatesRoot(), "scripts", "ci", "bkit-machine-lock.sh");
18
+ const res = spawnSync("bash", [script, args[0], "--lock", "tests", ...args.slice(1)], {
19
+ encoding: "utf-8",
20
+ stdio: ["ignore", "pipe", "pipe"],
21
+ });
22
+ if (res.error) {
23
+ throw new CommandError(EXIT_JUMP_FAILED, `cannot run ${script}: ${res.error.message}`);
24
+ }
25
+ return { status: res.status ?? 1, stdout: res.stdout, stderr: res.stderr.trim() };
26
+ }
27
+ const lines = (text) => text.split("\n").filter((line) => line !== "");
28
+ export const testsJumpVerb = {
29
+ summary: "Move the waiting run named <run> to the front of the tests line; the holder keeps the lock. Every use needs the human's approval, so ask them to approve it; exit 0 moved, 1 no single run matched, 3 the lock script failed.",
30
+ use: "by-hand",
31
+ flags: [
32
+ {
33
+ name: "run",
34
+ type: "string",
35
+ positional: true,
36
+ required: true,
37
+ help: "the waiting run's name, as the waiting note prints it",
38
+ },
39
+ {
40
+ name: "checkout",
41
+ type: "string",
42
+ help: "the waiting run's checkout path, to pick one when several runs share the name",
43
+ },
44
+ ],
45
+ output: {
46
+ run: "the run name moved to the front",
47
+ checkout: "the checkout path of the run moved",
48
+ },
49
+ exitCodes: {
50
+ [EXIT_JUMP_FAILED]: "the lock script could not read the queue or write the jump marker",
51
+ },
52
+ run: (ctx) => {
53
+ const run = String(ctx.flags.run);
54
+ const wanted = typeof ctx.flags.checkout === "string" ? [ctx.flags.checkout] : [];
55
+ const res = lockScript(["jump", run, ...wanted]);
56
+ if (res.status === 1) {
57
+ const waiting = lockScript(["queue"]);
58
+ const queued = waiting.status === 0 ? lines(waiting.stdout) : [];
59
+ throw new CommandError(EXIT.NO, `no run named ${run} waits for tests` +
60
+ (queued.length > 0
61
+ ? `\nwaiting now:\n${queued.map((line) => ` ${line}`).join("\n")}`
62
+ : ""));
63
+ }
64
+ if (res.status === 3) {
65
+ throw new CommandError(EXIT.NO, `several runs named ${run} wait for tests:\n${lines(res.stdout)
66
+ .map((line) => ` ${line}`)
67
+ .join("\n")}\npass --checkout <path> to pick one`);
68
+ }
69
+ if (res.status !== 0) {
70
+ throw new CommandError(EXIT_JUMP_FAILED, res.stderr || `the lock script's jump exited ${res.status}`);
71
+ }
72
+ const line = lines(res.stdout)[0] ?? "";
73
+ ctx.log(`${run} moves to the front of the tests line`);
74
+ ctx.emit({ run, checkout: line.slice(`${run} — `.length) });
75
+ return EXIT.OK;
76
+ },
77
+ };