@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
@@ -18,16 +18,27 @@ import * as path from "node:path";
18
18
  import { parseJson } from "../../shared/json.js";
19
19
  import { CommandError, EXIT, type CommandSpec, git, runGit } from "../lib.js";
20
20
  import { EXIT_DIFF_FAILED, fetchRemoteRef } from "./branches.js";
21
- import { DIFF_BASE } from "./context.js";
21
+ import { decisionHeader, parseDecisionItems } from "./open-decision.js";
22
+ const DIFF_BASE = "origin/dev";
22
23
  import {
24
+ derivedTestMatrix,
23
25
  NO_MARKERS_REASON,
24
26
  parsePlanBlocks,
25
27
  type PlanGroup,
26
28
  type PlanRef,
27
29
  type PlanTaskBlock,
30
+ testTier,
28
31
  } from "./plan-blocks.js";
29
- import { positiveInt, str } from "./status.js";
30
- import { doneTasks } from "./tests.js";
32
+ import { positiveInt, readStatusRows, str } from "./status.js";
33
+ import { writeStepRow } from "./steps.js";
34
+ import {
35
+ doneTasks,
36
+ readTestFirst,
37
+ redEntries,
38
+ redKey,
39
+ sameTestName,
40
+ TAKEOVER_STEP,
41
+ } from "./tests.js";
31
42
 
32
43
  /** A task's heading line: the box and the number the tick addresses. */
33
44
  const TASK_BOX = /^(\s*)- \[([ xX])\] \*\*TASK (\d+):\*\*/;
@@ -95,18 +106,70 @@ function taskNumbers(values: readonly string[], flag: string): number[] {
95
106
 
96
107
  /**
97
108
  * The task numbers a `bkit tests green` report gaps: the `- Task {N} \`{kind}\`` lines of
98
- * its `## Gaps` section, or the `gaps` array of its `--json` payload.
109
+ * its `## Gaps` section, or the `gaps` array of its `--json` payload. Null when the report
110
+ * holds neither: a report with no Gaps section says nothing about which tasks are green.
99
111
  */
100
- export function gappedTasks(text: string): number[] {
112
+ export function gappedTasks(text: string): number[] | null {
113
+ const json = jsonGaps(text);
114
+ if (json !== null)
115
+ return json
116
+ .map((g) => (typeof g === "object" && g !== null ? (g as { task?: unknown }).task : null))
117
+ .filter((t): t is number => typeof t === "number");
118
+ const section = gapsSection(text);
119
+ return section === null ? null : [...section.matchAll(REPORT_GAP)].map((m) => Number(m[1]));
120
+ }
121
+
122
+ /** The `gaps` array of a `--json` report, else null. */
123
+ function jsonGaps(text: string): unknown[] | null {
101
124
  const json = parseJson(text);
102
- if (json.ok && typeof json.value === "object" && json.value !== null) {
103
- const gaps = (json.value as { gaps?: unknown }).gaps;
104
- if (Array.isArray(gaps))
105
- return gaps
106
- .map((g) => (typeof g === "object" && g !== null ? (g as { task?: unknown }).task : null))
107
- .filter((t): t is number => typeof t === "number");
108
- }
109
- return [...text.matchAll(REPORT_GAP)].map((m) => Number(m[1]));
125
+ if (!json.ok || typeof json.value !== "object" || json.value === null) return null;
126
+ const gaps = (json.value as { gaps?: unknown }).gaps;
127
+ return Array.isArray(gaps) ? gaps : null;
128
+ }
129
+
130
+ /** A text report's `## Gaps` section, up to the next `## ` heading; null when it has none. */
131
+ function gapsSection(text: string): string | null {
132
+ const start = text.search(/^## Gaps\b/m);
133
+ if (start < 0) return null;
134
+ const rest = text.slice(start).replace(/^## Gaps[^\n]*\n?/, "");
135
+ const end = rest.search(/^## /m);
136
+ return end < 0 ? rest : rest.slice(0, end);
137
+ }
138
+
139
+ /**
140
+ * Why a text report's Gaps section cannot be trusted: its header's `Gaps: N` counts more gap
141
+ * lines (`- Task {N}` or `- Plan`) than the section holds, so a line inside a gap's detail
142
+ * cut the section short. Null when the counts agree, or for a JSON report or one with no
143
+ * `Gaps:` header.
144
+ */
145
+ export function gapsShortfall(text: string): string | null {
146
+ if (jsonGaps(text) !== null) return null;
147
+ const header = text.split(/\r?\n[ \t]*\r?\n/, 1)[0] ?? "";
148
+ const want = /^Gaps:[ \t]*([0-9]+)[ \t]*$/m.exec(header)?.[1];
149
+ const section = gapsSection(text);
150
+ if (want === undefined || section === null) return null;
151
+ const read = [...section.matchAll(/^-\s+(?:Task\s+\d+|Plan)\s+`/gm)].length;
152
+ return read < Number(want)
153
+ ? `the header says Gaps: ${want} but the Gaps section holds ${read} gap line${read === 1 ? "" : "s"}`
154
+ : null;
155
+ }
156
+
157
+ /**
158
+ * The first header fact that stops `--decision` from ticking, or null: `From` is `verify` or
159
+ * `holistic`, no `Gate: FAIL` header, and a verify file's `Group` is `group`. Headers count
160
+ * only in the header block (`decisionHeader`).
161
+ */
162
+ function decisionProblem(text: string, group: number | undefined): string | null {
163
+ const header = decisionHeader(text);
164
+ const from = header.From;
165
+ if (from === undefined) return "no From header";
166
+ if (from !== "verify" && from !== "holistic") return `From is "${from}", not verify or holistic`;
167
+ if (/^FAIL\b/.test(header.Gate ?? "")) return "Gate: FAIL header: the gate is red";
168
+ if (from === "holistic") return null;
169
+ if (header.Group === undefined) return "no Group header";
170
+ if (group === undefined) return "missing required flag --group for a From: verify file";
171
+ if (header.Group !== String(group)) return `Group is "${header.Group}", not group ${group}`;
172
+ return null;
110
173
  }
111
174
 
112
175
  /** `task`'s heading line inside its block: its box and number, or null when the block holds none. */
@@ -146,13 +209,225 @@ const splitPaths = (stdout: string): string[] => stdout.split("\0").filter(Boole
146
209
  /** A workflow run log: another feature's record, never code a plan task reads or changes. */
147
210
  const RUN_LOG = /^docs\/plans\/[^/]+\/logs\//;
148
211
 
212
+ /** One `build-takeover` row: the takeover task the build added and the test it takes over. */
213
+ interface TakeoverRow {
214
+ task: number;
215
+ from: number;
216
+ test: string;
217
+ name: string;
218
+ }
219
+
220
+ /** The status file's `build-takeover` rows, in file order; none when the file does not exist. */
221
+ function takeoverRows(statusPath: string): TakeoverRow[] {
222
+ if (!fs.existsSync(statusPath)) return [];
223
+ return (readStatusRows(statusPath) as Array<Record<string, unknown>>)
224
+ .filter(
225
+ (r) =>
226
+ r.type === "step-done" &&
227
+ r.workflow === "build" &&
228
+ r.step === TAKEOVER_STEP &&
229
+ typeof r.task === "number" &&
230
+ typeof r.test === "string" &&
231
+ typeof r.name === "string",
232
+ )
233
+ .map((r) => ({
234
+ task: r.task as number,
235
+ from: typeof r.from === "number" ? r.from : 0,
236
+ test: r.test as string,
237
+ name: r.name as string,
238
+ }));
239
+ }
240
+
241
+ /**
242
+ * The group of takeover tasks whose tests half has not run: the plan's tasks a
243
+ * `build-takeover` row names, grouped, the latest group holding a planned test with no
244
+ * `tests red` entry. Null when every takeover group's tests are recorded.
245
+ */
246
+ function pendingTakeovers(
247
+ text: string,
248
+ statusPath: string,
249
+ ): { group: number; tasks: number[] } | null {
250
+ const named = new Set(takeoverRows(statusPath).map((r) => r.task));
251
+ const tasks = parsePlanBlocks(text).tasks.filter((t) => named.has(t.task));
252
+ const groups = [...new Set(tasks.map((t) => t.group))].sort((a, b) => b - a);
253
+ for (const group of groups) {
254
+ const reds = redEntries(statusPath, "build", group);
255
+ const open = readTestFirst(text, group).some(
256
+ (s) =>
257
+ named.has(s.task) &&
258
+ s.kind === "test" &&
259
+ s.tests.some((t) => !reds.has(redKey(s.task, t.test, t.name))),
260
+ );
261
+ if (open) return { group, tasks: tasks.filter((t) => t.group === group).map((t) => t.task) };
262
+ }
263
+ return null;
264
+ }
265
+
266
+ /** A plan line's text: one line, no backticks or pipes, so it never breaks a field or a table cell. */
267
+ const planWords = (s: string) => s.replace(/\s+/g, " ").replace(/[`|]/g, "'").trim();
268
+
269
+ /** The lines of one pure takeover task block. */
270
+ function takeoverTask(
271
+ n: number,
272
+ t: { test: string; name: string; from: number; reason: string },
273
+ dependsOn: number | undefined,
274
+ ): string[] {
275
+ const until =
276
+ dependsOn === undefined
277
+ ? "the change that contradicts it exists"
278
+ : `TASK ${dependsOn}'s code exists`;
279
+ return [
280
+ `<!-- bkit:task ${n} start -->`,
281
+ "",
282
+ `- [ ] **TASK ${n}:** Take over \`${t.name}\` from TASK ${t.from}`,
283
+ ...(dependsOn === undefined ? [] : [` - **DEPENDS ON:** ${dependsOn}`]),
284
+ ` - **DONE WHEN:** \`${t.test}\` \`${t.name}\` passes`,
285
+ " - **TEST FIRST:**",
286
+ ` - \`${t.test}\` \`${t.name}\` fails until ${until}: ${planWords(t.reason)}`,
287
+ "",
288
+ `<!-- bkit:task ${n} end -->`,
289
+ ];
290
+ }
291
+
292
+ /**
293
+ * The plan with takeover task `n` added: into the last group when it is a takeover group
294
+ * whose tests half has not run (`into`), else as a new last group after the last group's
295
+ * end marker; plus a Derived Test Matrix row when the plan has a matrix.
296
+ */
297
+ function withTakeoverTask(
298
+ text: string,
299
+ task: string[],
300
+ n: number,
301
+ group: number,
302
+ into: boolean,
303
+ row: { name: string; test: string; from: number },
304
+ ): string {
305
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
306
+ const lines = text.split(/\r?\n/);
307
+ const matrix = derivedTestMatrix(text);
308
+ if (matrix !== null) {
309
+ const at = matrix.rows.at(-1)?.number ?? matrix.line + 1;
310
+ lines.splice(
311
+ at,
312
+ 0,
313
+ `| Take over ${planWords(row.name)} from TASK ${row.from} | ${testTier(row.test)} | \`${row.test}\` | ${n} |`,
314
+ );
315
+ }
316
+ const endMarker = (g: number) =>
317
+ lines.findIndex((l) => l.trim() === `<!-- bkit:group ${g} end -->`);
318
+ if (into) {
319
+ lines.splice(endMarker(group), 0, ...task, "");
320
+ return lines.join(eol);
321
+ }
322
+ const last = Math.max(...parsePlanBlocks(text).groups.map((g) => g.group));
323
+ lines.splice(
324
+ endMarker(last) + 1,
325
+ 0,
326
+ "",
327
+ `<!-- bkit:group ${group} start -->`,
328
+ "",
329
+ `### TASK GROUP ${group}: Planned tests the build took over`,
330
+ "",
331
+ ...task,
332
+ "",
333
+ `<!-- bkit:group ${group} end -->`,
334
+ );
335
+ return lines.join(eol);
336
+ }
337
+
338
+ /** A contradicted planned test the build hands to a takeover task. */
339
+ export interface TakeoverEntry {
340
+ test: string;
341
+ name: string;
342
+ /** The earlier task that owns the test. */
343
+ from: number;
344
+ /** The task whose change contradicts the test; null for a `Gap N` line. */
345
+ task: number | null;
346
+ /** Why the earlier test no longer holds: the BLOCKED line's reason. */
347
+ reason: string;
348
+ }
349
+
350
+ /**
351
+ * Adds one pure takeover task per entry to the plan at `planFile`, plus its Derived Test
352
+ * Matrix row and its `build-takeover` row in `statusPath`. Safe to repeat: an open takeover
353
+ * task whose `TEST FIRST` already names the entry's file and name is reused, and only a
354
+ * missing row is written, so a second run or a run stopped between the two writes leaves one
355
+ * task and one row. The task goes into the plan's last group while that group is a takeover
356
+ * group whose tests half has not run, else into a new last group. Returns the takeover task
357
+ * number per entry, in entry order.
358
+ */
359
+ export function addTakeoverTasks(
360
+ cwd: string,
361
+ planFile: string,
362
+ statusPath: string,
363
+ entries: readonly TakeoverEntry[],
364
+ log: (m: string) => void,
365
+ ): number[] {
366
+ const out: number[] = [];
367
+ for (const e of entries) {
368
+ const test = path.posix.normalize(e.test);
369
+ const text = fs.readFileSync(planFile, "utf-8");
370
+ const plan = parsePlanBlocks(text);
371
+ const open = plan.tasks.find(
372
+ (t) =>
373
+ !t.done &&
374
+ t.title.startsWith("Take over ") &&
375
+ (t.testFirst?.tests ?? []).some(
376
+ (x) => path.posix.normalize(x.test) === test && sameTestName(x.name, e.name),
377
+ ),
378
+ );
379
+ let n: number;
380
+ if (open !== undefined) {
381
+ n = open.task;
382
+ log(`TASK ${n} already takes over "${e.name}" in ${test}`);
383
+ } else {
384
+ n = Math.max(...plan.tasks.map((t) => t.task)) + 1;
385
+ const lastGroup = Math.max(...plan.groups.map((g) => g.group));
386
+ const pending = pendingTakeovers(text, statusPath);
387
+ const into = pending !== null && pending.group === lastGroup;
388
+ const group = into ? lastGroup : lastGroup + 1;
389
+ const dependsOn =
390
+ e.task !== null && plan.tasks.some((t) => t.task === e.task) ? e.task : undefined;
391
+ fs.writeFileSync(
392
+ planFile,
393
+ withTakeoverTask(
394
+ text,
395
+ takeoverTask(n, { test, name: e.name, from: e.from, reason: e.reason }, dependsOn),
396
+ n,
397
+ group,
398
+ into,
399
+ { name: e.name, test, from: e.from },
400
+ ),
401
+ );
402
+ log(
403
+ `added TASK ${n} in group ${group}: takes over "${e.name}" in ${test} from TASK ${e.from}`,
404
+ );
405
+ }
406
+ if (!takeoverRows(statusPath).some((r) => r.task === n))
407
+ writeStepRow(
408
+ cwd,
409
+ {
410
+ file: statusPath,
411
+ workflow: "build",
412
+ step: TAKEOVER_STEP,
413
+ artifacts: [path.relative(cwd, planFile)],
414
+ extras: { task: n, from: e.from, test, name: e.name, reason: e.reason },
415
+ commit: "none",
416
+ },
417
+ log,
418
+ );
419
+ out.push(n);
420
+ }
421
+ return out;
422
+ }
423
+
149
424
  export const tasksCommand: CommandSpec = {
150
425
  noun: "tasks",
151
426
  summary: "Tick a plan's task boxes, from the tasks a verify judged satisfied.",
152
427
  verbs: {
153
428
  tick: {
154
429
  summary:
155
- "Tick the named tasks of one task group, less those a `tests green` report gaps; exit 0 ticked (including none), 1 a plan with no task blocks, 2 a bad flag value or plan.",
430
+ "Tick the named tasks of one task group, less those a `tests green` report gaps; exit 0 ticked (including none), 1 a plan with no task blocks, 2 a bad flag value or plan, a `--green` report with no Gaps section or fewer gap lines than its `Gaps:` header, or a `--decision` file that is not a verify or holistic pause of this group with a green gate.",
156
431
  use: "workflow",
157
432
  flags: [
158
433
  {
@@ -164,39 +439,59 @@ export const tasksCommand: CommandSpec = {
164
439
  {
165
440
  name: "group",
166
441
  type: "string",
167
- required: true,
168
- help: "the task group whose tasks are candidates (positive integer)",
442
+ help: "the task group whose tasks are candidates (positive integer); required, except with a `From: holistic` --decision alone, whose accepted tasks are ticked in their own groups",
169
443
  },
170
444
  {
171
445
  name: "tasks",
172
446
  type: "string",
173
447
  repeatable: true,
174
- help: "the task numbers to tick, comma-separated or once per number; `none` ticks nothing (one of --tasks / --green)",
448
+ help: "the task numbers to tick, comma-separated or once per number; `none` ticks nothing (one of --tasks / --green / --decision)",
449
+ },
450
+ {
451
+ name: "decision",
452
+ type: "string",
453
+ help: "a decision file with a `From: verify` (whose `Group` is --group) or `From: holistic` header and no `Gate: FAIL` header: the task each item answered `Accept` or `Accept (assumed)` names at the start of its title (`Task {N}`) is ticked; `Fix now` and undecided items tick nothing (one of --tasks / --green / --decision)",
175
454
  },
176
455
  {
177
456
  name: "green",
178
457
  type: "string",
179
- help: "a `bkit tests green` report: every task it gaps stays unticked (one of --tasks / --green)",
458
+ help: "a `bkit tests green` report: every task it gaps stays unticked (one of --tasks / --green / --decision)",
180
459
  },
181
460
  ],
182
461
  output: {
183
462
  plan: "the plan file ticked, as given",
184
- group: "the group whose tasks were candidates",
463
+ group:
464
+ "the group whose tasks were candidates; null for a holistic --decision without --group",
185
465
  ticked: "[task numbers] ticked by this call; a task already ticked is not repeated",
186
466
  },
187
467
  run: (ctx) => {
188
468
  const planArg = String(ctx.flags.plan);
189
469
  const group = positiveInt(ctx.flags.group, "group");
190
- if (group === undefined)
191
- throw new CommandError(EXIT.USAGE, "missing required flag --group");
192
470
  const tasksFlag = ctx.flags.tasks as string[] | undefined;
193
471
  const greenArg = str(ctx.flags.green);
194
472
  if (greenArg === "") throw new CommandError(EXIT.USAGE, "--green must be non-empty");
195
- if (tasksFlag === undefined && greenArg === undefined)
196
- throw new CommandError(EXIT.USAGE, "give one of --tasks and --green");
473
+ const decisionArg = str(ctx.flags.decision);
474
+ if (decisionArg === "") throw new CommandError(EXIT.USAGE, "--decision must be non-empty");
475
+ if (tasksFlag === undefined && greenArg === undefined && decisionArg === undefined)
476
+ throw new CommandError(EXIT.USAGE, "give one of --tasks, --green and --decision");
477
+ let decisionText: string | undefined;
478
+ if (decisionArg !== undefined) {
479
+ const decisionFile = path.resolve(ctx.cwd, decisionArg);
480
+ if (fs.statSync(decisionFile, { throwIfNoEntry: false })?.isFile() !== true)
481
+ throw new CommandError(EXIT.USAGE, `--decision ${decisionArg} does not exist`);
482
+ decisionText = fs.readFileSync(decisionFile, "utf-8");
483
+ }
484
+ // Only a holistic decision alone may leave out --group: its accepted tasks span groups.
485
+ const holisticOnly =
486
+ decisionText !== undefined &&
487
+ decisionHeader(decisionText).From === "holistic" &&
488
+ tasksFlag === undefined &&
489
+ greenArg === undefined;
490
+ if (group === undefined && !holisticOnly)
491
+ throw new CommandError(EXIT.USAGE, "missing required flag --group");
197
492
  const plan = readPlan(ctx.cwd, planArg);
198
- const candidates = groupTasks(plan, planArg, group);
199
- const named = tasksFlag === undefined ? undefined : taskNumbers(tasksFlag, "tasks");
493
+ const candidates = group === undefined ? plan.tasks : groupTasks(plan, planArg, group);
494
+ let named = tasksFlag === undefined ? undefined : taskNumbers(tasksFlag, "tasks");
200
495
  for (const n of named ?? []) {
201
496
  const task = plan.tasks.find((t) => t.task === n);
202
497
  if (task === undefined) throw new CommandError(EXIT.USAGE, `${planArg} has no TASK ${n}`);
@@ -206,12 +501,43 @@ export const tasksCommand: CommandSpec = {
206
501
  `TASK ${n} is in group ${task.group}, not group ${group}`,
207
502
  );
208
503
  }
504
+ if (decisionText !== undefined) {
505
+ const problem = decisionProblem(decisionText, group);
506
+ if (problem !== null)
507
+ throw new CommandError(
508
+ EXIT.USAGE,
509
+ `--decision ${decisionArg}: ${problem}, so nothing is ticked`,
510
+ );
511
+ // A title names its task only at its start (`Task {N}`): a gap that mentions a task elsewhere ticks nothing.
512
+ const accepted = parseDecisionItems(decisionText)
513
+ .filter((it) => it.decision !== null && /^Accept\b/.test(it.decision))
514
+ .map((it) => /^task\s+(\d+)\b/i.exec(it.title.trim()))
515
+ .filter((m): m is RegExpExecArray => m !== null)
516
+ .map((m) => Number(m[1]));
517
+ named = [
518
+ ...(named ?? []),
519
+ ...accepted.filter((n) => candidates.some((t) => t.task === n)),
520
+ ];
521
+ }
209
522
  const gapped = new Set<number>();
210
523
  if (greenArg !== undefined) {
211
524
  const greenFile = path.resolve(ctx.cwd, greenArg);
212
525
  if (fs.statSync(greenFile, { throwIfNoEntry: false })?.isFile() !== true)
213
526
  throw new CommandError(EXIT.USAGE, `--green ${greenArg} does not exist`);
214
- for (const n of gappedTasks(fs.readFileSync(greenFile, "utf-8"))) gapped.add(n);
527
+ const greenText = fs.readFileSync(greenFile, "utf-8");
528
+ const gaps = gappedTasks(greenText);
529
+ if (gaps === null)
530
+ throw new CommandError(
531
+ EXIT.USAGE,
532
+ `--green ${greenArg}: report has no Gaps section, so nothing is ticked`,
533
+ );
534
+ const shortfall = gapsShortfall(greenText);
535
+ if (shortfall !== null)
536
+ throw new CommandError(
537
+ EXIT.USAGE,
538
+ `--green ${greenArg}: ${shortfall}, so nothing is ticked`,
539
+ );
540
+ for (const n of gaps) gapped.add(n);
215
541
  }
216
542
  const wanted = named ?? candidates.map((t) => t.task);
217
543
  const lines = plan.text.split(/\r?\n/);
@@ -230,7 +556,7 @@ export const tasksCommand: CommandSpec = {
230
556
  for (const n of ticked) ctx.log(`ticked TASK ${n}`);
231
557
  ctx.emit({
232
558
  plan: planArg,
233
- group,
559
+ group: group ?? null,
234
560
  ticked,
235
561
  });
236
562
  return EXIT.OK;
@@ -285,6 +611,53 @@ export const tasksCommand: CommandSpec = {
285
611
  return EXIT.OK;
286
612
  },
287
613
  },
614
+ takeover: {
615
+ summary:
616
+ "Print the takeover group whose tests half has not run: the plan's takeover tasks (added by `steps finish` on a code step that contradicts a ticked task's planned test, each named by a build-takeover row) in the latest group holding a planned test with no `tests red` entry yet, or null. Writes nothing. Exit 0 (including nothing pending), 1 a plan with no task blocks, 2 a bad flag value or plan.",
617
+ use: "workflow",
618
+ flags: [
619
+ {
620
+ name: "plan",
621
+ type: "string",
622
+ required: true,
623
+ help: "plan file holding the task blocks",
624
+ },
625
+ {
626
+ name: "file",
627
+ type: "string",
628
+ required: true,
629
+ help: "the run's status.jsonl: its build-takeover and tests red rows are read",
630
+ },
631
+ {
632
+ name: "pending",
633
+ type: "boolean",
634
+ help: "print the takeover group whose tests half has not run, or null; required, since the verb only reads",
635
+ },
636
+ ],
637
+ output: {
638
+ plan: "the plan file, as given",
639
+ pending:
640
+ "{group, tasks} the takeover group whose tests have no tests red entry yet, else null",
641
+ },
642
+ run: (ctx) => {
643
+ const planArg = String(ctx.flags.plan);
644
+ const statusArg = String(ctx.flags.file);
645
+ if (statusArg === "") throw new CommandError(EXIT.USAGE, "--file must be non-empty");
646
+ if (ctx.flags.pending !== true)
647
+ throw new CommandError(
648
+ EXIT.USAGE,
649
+ "tasks takeover only reads, with --pending: steps finish adds the takeover tasks",
650
+ );
651
+ const plan = readPlan(ctx.cwd, planArg);
652
+ const pending = pendingTakeovers(plan.text, path.resolve(ctx.cwd, statusArg));
653
+ if (pending !== null)
654
+ ctx.log(
655
+ `takeover group ${pending.group} has tests to record: TASK ${pending.tasks.join(", ")}`,
656
+ );
657
+ ctx.emit({ plan: planArg, pending });
658
+ return EXIT.OK;
659
+ },
660
+ },
288
661
  currency: {
289
662
  summary:
290
663
  "Print each task whose CREATE / READ / UPDATE / DELETE paths or symbols moved between --base and --against, with its matched paths, needles and diff hunks (run logs under docs/plans/*/logs/ are left out); exit 0 (including no match), 1 a plan with no task blocks, 2 a bad plan.",