@cbartens/bkit 6.1.1 → 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 (313) 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 +42 -32
  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 +97 -36
  15. package/.bkit/core/.bkit/templates.md +162 -34
  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 +89 -37
  64. package/.bkit/core/engine/checks/after/index.ts +15 -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 +64 -11
  74. package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
  75. package/.bkit/core/engine/commands/install/install.ts +28 -25
  76. package/.bkit/core/engine/commands/install/uninstall.ts +42 -30
  77. package/.bkit/core/engine/commands/install/upgrade.ts +14 -2
  78. package/.bkit/core/engine/commands/land.ts +2 -3
  79. package/.bkit/core/engine/commands/lib.ts +394 -39
  80. package/.bkit/core/engine/commands/registry.ts +1 -1
  81. package/.bkit/core/engine/commands/workflow/branches.ts +351 -78
  82. package/.bkit/core/engine/commands/workflow/challenge.ts +63 -14
  83. package/.bkit/core/engine/commands/workflow/context.ts +71 -10
  84. package/.bkit/core/engine/commands/workflow/counters.ts +298 -23
  85. package/.bkit/core/engine/commands/workflow/decisions.ts +260 -125
  86. package/.bkit/core/engine/commands/workflow/disk.ts +2 -1
  87. package/.bkit/core/engine/commands/workflow/feature-base.ts +66 -0
  88. package/.bkit/core/engine/commands/workflow/issues.ts +312 -17
  89. package/.bkit/core/engine/commands/workflow/junit.ts +204 -0
  90. package/.bkit/core/engine/commands/workflow/ledgers.ts +904 -99
  91. package/.bkit/core/engine/commands/workflow/locks.ts +186 -29
  92. package/.bkit/core/engine/commands/workflow/loops.ts +87 -0
  93. package/.bkit/core/engine/commands/workflow/open-decision.ts +251 -0
  94. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +8 -0
  95. package/.bkit/core/engine/commands/workflow/plans.ts +1 -1
  96. package/.bkit/core/engine/commands/workflow/prs.ts +311 -16
  97. package/.bkit/core/engine/commands/workflow/repo.ts +1 -1
  98. package/.bkit/core/engine/commands/workflow/run-facts.ts +6 -0
  99. package/.bkit/core/engine/commands/workflow/runs.ts +877 -174
  100. package/.bkit/core/engine/commands/workflow/runtime.ts +12 -4
  101. package/.bkit/core/engine/commands/workflow/status.ts +324 -11
  102. package/.bkit/core/engine/commands/workflow/step-table.ts +41 -15
  103. package/.bkit/core/engine/commands/workflow/steps.ts +604 -29
  104. package/.bkit/core/engine/commands/workflow/summary-findings.ts +1 -1
  105. package/.bkit/core/engine/commands/workflow/summary.ts +314 -8
  106. package/.bkit/core/engine/commands/workflow/tasks.ts +400 -27
  107. package/.bkit/core/engine/commands/workflow/tests-base.ts +319 -0
  108. package/.bkit/core/engine/commands/workflow/tests-changed.ts +138 -74
  109. package/.bkit/core/engine/commands/workflow/tests-jump.ts +93 -0
  110. package/.bkit/core/engine/commands/workflow/tests.ts +815 -182
  111. package/.bkit/core/engine/commands/workflow/tracker.ts +1134 -137
  112. package/.bkit/core/engine/commands/workflow/workflows.ts +100 -72
  113. package/.bkit/core/engine/commands/workflow/worktrees.ts +421 -57
  114. package/.bkit/core/engine/install/cloud-env.ts +38 -10
  115. package/.bkit/core/engine/install/managed-block.ts +105 -0
  116. package/.bkit/core/engine/install/manifest.ts +7 -1
  117. package/.bkit/core/engine/install/modules/claude.ts +6 -2
  118. package/.bkit/core/engine/install/modules/cloud.ts +84 -95
  119. package/.bkit/core/engine/install/modules/codex.ts +10 -2
  120. package/.bkit/core/engine/install/modules/core.ts +148 -14
  121. package/.bkit/core/engine/install/modules/opencode.ts +18 -23
  122. package/.bkit/core/engine/install/network-allowlist.ts +8 -3
  123. package/.bkit/core/engine/install/project-docs.ts +650 -0
  124. package/.bkit/core/engine/install/template-copies.ts +58 -5
  125. package/.bkit/core/engine/install/write.ts +128 -7
  126. package/.bkit/core/engine/ledgers/journal.ts +18 -10
  127. package/.bkit/core/engine/ledgers/migrate.ts +20 -8
  128. package/.bkit/core/engine/ledgers/status.ts +604 -8
  129. package/.bkit/core/engine/ledgers/telemetry.ts +115 -13
  130. package/.bkit/core/engine/render/trackers.ts +3 -1
  131. package/.bkit/core/engine/shared/package-manager.ts +7 -3
  132. package/.bkit/core/engine/shared/settings.ts +12 -1
  133. package/.bkit/core/engine/shared/text.ts +14 -0
  134. package/.bkit/core/engine/tools/instructions-sources.ts +1 -0
  135. package/.bkit/core/engine/tools/instructions.ts +116 -20
  136. package/.bkit/core/hooks/antigravity-hook.js +20 -4
  137. package/.bkit/core/hooks/gateguard-edit-payload.js +8 -5
  138. package/.bkit/core/hooks/gateguard-engine.js +249 -23
  139. package/.bkit/core/hooks/guardrails-deny.js +167 -0
  140. package/.bkit/core/hooks/guardrails-read.js +3 -3
  141. package/.bkit/core/hooks/guardrails-shell.js +1122 -167
  142. package/.bkit/core/hooks/guardrails-tiers.js +247 -176
  143. package/.bkit/core/hooks/preflight-tracker.sh +219 -0
  144. package/.bkit/core/prompts/bkit-audit-generate.md +23 -6
  145. package/.bkit/core/prompts/bkit-build-challenge-1.md +5 -4
  146. package/.bkit/core/prompts/bkit-build-challenge-2.md +6 -5
  147. package/.bkit/core/prompts/bkit-build-install-skills.md +2 -2
  148. package/.bkit/core/prompts/bkit-build-plan-convert.md +21 -7
  149. package/.bkit/core/prompts/bkit-build-plan-current.md +5 -4
  150. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +22 -17
  151. package/.bkit/core/prompts/bkit-build-plan-tasks.md +16 -12
  152. package/.bkit/core/prompts/bkit-build-plan-tests.md +14 -10
  153. package/.bkit/core/prompts/bkit-build-plan-verify.md +21 -8
  154. package/.bkit/core/prompts/bkit-debug-abort-handover.md +10 -5
  155. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +22 -6
  156. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +19 -3
  157. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +22 -6
  158. package/.bkit/core/prompts/bkit-debug-failure-soak.md +10 -7
  159. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +3 -3
  160. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +4 -4
  161. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +3 -3
  162. package/.bkit/core/prompts/bkit-design-generate.md +6 -4
  163. package/.bkit/core/prompts/bkit-design-organise.md +4 -3
  164. package/.bkit/core/prompts/bkit-design-review-1.md +5 -4
  165. package/.bkit/core/prompts/bkit-design-review-2.md +6 -5
  166. package/.bkit/core/prompts/bkit-design-spike.md +4 -3
  167. package/.bkit/core/prompts/bkit-design-update.md +6 -4
  168. package/.bkit/core/prompts/bkit-plan-generate.md +35 -14
  169. package/.bkit/core/prompts/bkit-plan-review-1.md +9 -7
  170. package/.bkit/core/prompts/bkit-plan-review-2.md +9 -7
  171. package/.bkit/core/prompts/bkit-plan-scope-check.md +8 -6
  172. package/.bkit/core/prompts/bkit-plan-update.md +22 -8
  173. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +11 -8
  174. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +9 -5
  175. package/.bkit/core/prompts/bkit-ship-update-docs.md +26 -4
  176. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +3 -3
  177. package/.bkit/core/prompts/bkit-utility-update-decisions.md +10 -7
  178. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +8 -5
  179. package/.bkit/core/prompts/bkit-utility-update-documentation.md +31 -7
  180. package/.bkit/core/prompts/bkit-utility-update-failures.md +8 -5
  181. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +10 -7
  182. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +4 -4
  183. package/.bkit/core/prompts/bkit-utility-update-tracker.md +4 -4
  184. package/.bkit/core/workflows/bkit-auto.md +23 -11
  185. package/.bkit/core/workflows/bkit-build.md +331 -100
  186. package/.bkit/core/workflows/bkit-debug.md +135 -64
  187. package/.bkit/core/workflows/bkit-design.md +58 -32
  188. package/.bkit/core/workflows/bkit-plan.md +73 -45
  189. package/.bkit/core/workflows/bkit-ship.md +233 -167
  190. package/.bkit/shared/.agents/plugins/bkit/hooks.json +1 -1
  191. package/.bkit/shared/.bkit/.env.example +5 -0
  192. package/.bkit/shared/.claude/bkit-cloud.md +7 -7
  193. package/.bkit/shared/.claude/settings.json +5 -1
  194. package/.bkit/shared/.cursor/bkit-cloud.md +1 -1
  195. package/.bkit/shared/.cursor/hooks.json +1 -1
  196. package/.bkit/shared/.opencode/opencode.json +11 -2
  197. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +27 -0
  198. package/.bkit/templates/.cursor/Dockerfile +7 -7
  199. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +1 -1
  200. package/.bkit/templates/.github/dependabot.yml +5 -0
  201. package/.bkit/templates/.github/renovate.json5 +5 -3
  202. package/.bkit/templates/.github/workflows/bkit-ci.yml +11 -11
  203. package/.bkit/templates/.github/workflows/bkit-cloud.yml +525 -161
  204. package/.bkit/templates/.github/workflows/bkit-renovate.yml +2 -2
  205. package/.bkit/templates/.husky/pre-push +123 -6
  206. package/.bkit/templates/context/bkit-serena.md +1 -1
  207. package/.bkit/templates/docs/architecture.md +98 -0
  208. package/.bkit/templates/docs/capabilities.md +33 -37
  209. package/.bkit/templates/docs/components.md +142 -0
  210. package/.bkit/templates/docs/data-schema.md +87 -0
  211. package/.bkit/{shared → templates}/docs/deployments.md +128 -142
  212. package/.bkit/templates/docs/design.md +117 -0
  213. package/.bkit/templates/docs/noise.md +54 -0
  214. package/.bkit/templates/docs/observability.md +99 -0
  215. package/.bkit/templates/docs/security.md +137 -0
  216. package/.bkit/templates/docs/setup.md +93 -0
  217. package/.bkit/templates/docs/technology.md +70 -0
  218. package/.bkit/{shared → templates}/docs/testing.md +200 -87
  219. package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
  220. package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +228 -35
  221. package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +270 -2
  222. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
  223. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +92 -63
  224. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
  225. package/.bkit/templates/slop-scan.config.json +2 -0
  226. package/CHANGELOG.md +64 -0
  227. package/DETAILS.md +24 -19
  228. package/README.md +1 -1
  229. package/dist/checks/after/auth.js +114 -46
  230. package/dist/checks/after/github.js +77 -35
  231. package/dist/checks/after/index.js +12 -3
  232. package/dist/checks/after/tools.js +224 -1
  233. package/dist/checks/before/files.js +59 -1
  234. package/dist/checks/before/index.js +7 -1
  235. package/dist/checks/status-holes.js +20 -21
  236. package/dist/checks/tips/catalogue.js +99 -10
  237. package/dist/checks/tips/detect.js +35 -3
  238. package/dist/checks/tips/index.js +1 -1
  239. package/dist/cli.js +13 -13
  240. package/dist/commands/ci/ci.js +56 -12
  241. package/dist/commands/ci/push-gate.js +79 -44
  242. package/dist/commands/install/install.js +23 -22
  243. package/dist/commands/install/uninstall.js +36 -30
  244. package/dist/commands/install/upgrade.js +10 -2
  245. package/dist/commands/land.js +2 -3
  246. package/dist/commands/lib.js +323 -25
  247. package/dist/commands/workflow/branches.js +312 -72
  248. package/dist/commands/workflow/challenge.js +66 -13
  249. package/dist/commands/workflow/context.js +46 -10
  250. package/dist/commands/workflow/counters.js +231 -23
  251. package/dist/commands/workflow/decisions.js +221 -106
  252. package/dist/commands/workflow/disk.js +2 -1
  253. package/dist/commands/workflow/feature-base.js +60 -0
  254. package/dist/commands/workflow/issues.js +243 -15
  255. package/dist/commands/workflow/junit.js +137 -0
  256. package/dist/commands/workflow/ledgers.js +726 -112
  257. package/dist/commands/workflow/locks.js +150 -29
  258. package/dist/commands/workflow/loops.js +67 -0
  259. package/dist/commands/workflow/open-decision.js +199 -0
  260. package/dist/commands/workflow/plan-blocks.js +6 -0
  261. package/dist/commands/workflow/plans.js +1 -1
  262. package/dist/commands/workflow/prs.js +272 -16
  263. package/dist/commands/workflow/repo.js +1 -1
  264. package/dist/commands/workflow/run-facts.js +6 -0
  265. package/dist/commands/workflow/runs.js +747 -155
  266. package/dist/commands/workflow/runtime.js +8 -4
  267. package/dist/commands/workflow/status.js +259 -13
  268. package/dist/commands/workflow/step-table.js +41 -15
  269. package/dist/commands/workflow/steps.js +530 -26
  270. package/dist/commands/workflow/summary-findings.js +1 -1
  271. package/dist/commands/workflow/summary.js +289 -8
  272. package/dist/commands/workflow/tasks.js +294 -27
  273. package/dist/commands/workflow/tests-base.js +266 -0
  274. package/dist/commands/workflow/tests-changed.js +130 -56
  275. package/dist/commands/workflow/tests-jump.js +77 -0
  276. package/dist/commands/workflow/tests.js +608 -131
  277. package/dist/commands/workflow/tracker.js +920 -112
  278. package/dist/commands/workflow/workflows.js +80 -59
  279. package/dist/commands/workflow/worktrees.js +387 -58
  280. package/dist/install/cloud-env.js +32 -10
  281. package/dist/install/managed-block.js +101 -0
  282. package/dist/install/manifest.js +7 -1
  283. package/dist/install/modules/claude.js +6 -2
  284. package/dist/install/modules/cloud.js +73 -86
  285. package/dist/install/modules/codex.js +9 -2
  286. package/dist/install/modules/core.js +133 -14
  287. package/dist/install/modules/opencode.js +18 -23
  288. package/dist/install/network-allowlist.js +8 -3
  289. package/dist/install/project-docs.js +551 -0
  290. package/dist/install/template-copies.js +55 -5
  291. package/dist/install/write.js +117 -5
  292. package/dist/ledgers/journal.js +10 -8
  293. package/dist/ledgers/migrate.js +20 -9
  294. package/dist/ledgers/status.js +461 -8
  295. package/dist/ledgers/telemetry.js +71 -13
  296. package/dist/render/trackers.js +3 -1
  297. package/dist/shared/package-manager.js +7 -2
  298. package/dist/shared/settings.js +8 -0
  299. package/dist/shared/text.js +13 -0
  300. package/dist/tools/instructions-sources.js +1 -0
  301. package/dist/tools/instructions.js +97 -24
  302. package/package.json +22 -15
  303. package/.bkit/core/hooks/preflight-linear.sh +0 -73
  304. package/.bkit/shared/docs/architecture.md +0 -16
  305. package/.bkit/shared/docs/data-schema.md +0 -16
  306. package/.bkit/shared/docs/design.md +0 -38
  307. package/.bkit/shared/docs/noise.md +0 -20
  308. package/.bkit/shared/docs/observability.md +0 -22
  309. package/.bkit/shared/docs/security.md +0 -62
  310. package/.bkit/shared/docs/setup.md +0 -52
  311. package/.bkit/shared/docs/technology.md +0 -15
  312. /package/.bkit/templates/{.lintstagedrc.json → lintstagedrc.example.json} +0 -0
  313. /package/.bkit/templates/{.prettierignore → prettierignore.example} +0 -0
@@ -1,12 +1,19 @@
1
- // bkit decisions compose|apply|pending — the build's decision files, from question to ship.
1
+ // bkit decisions compose|apply|skip|pending — the build's decision files, from question to ship.
2
+ // `open-decision.ts` reads them; `skip` applies its `skipProblem` rule.
2
3
  //
3
4
  // A decision file (`docs/plans/{YYYYMM}/logs/{FID}/build-decision-{RUN}-{N}.md`) holds header
4
5
  // lines, an optional progress block, then one item per question:
5
6
  //
6
7
  // **Q{n} — {title}:** {question}
7
- // Options: A) {A} / B) {B}
8
- // Recommended: A) {A} — {reason} (a hard blocker: `No recommendation — {why}`)
8
+ // A) {name} — {what happens if it is picked}
9
+ // B) {name} — {what happens if it is picked}
10
+ // Recommended: A) {name} — {reason} (a hard blocker: `Recommended: none — {why}`)
11
+ // Default if unanswered: {what happens}
9
12
  // Decision: {answer} — {words} (once decided)
13
+ // Fix task: {N} (a `Fix now` item: the plan task that carries its fix)
14
+ //
15
+ // The old layout is still read: one `Options: A) {A} / B) {B}` line in place of the option lines,
16
+ // and `No recommendation — {why}` in place of `Recommended: none — {why}`.
10
17
  //
11
18
  // `apply --by=headless` takes each recommendation when nobody can or should be asked: an
12
19
  // `Accept` is written `Accept (assumed)` and the file says `Status: ASSUMED`. It never writes a
@@ -16,78 +23,23 @@
16
23
  // deferral per item nobody confirmed.
17
24
  import * as fs from "node:fs";
18
25
  import * as path from "node:path";
19
- import { readJsonFile } from "../../shared/json.js";
26
+ import { readJsonFile, readTextFile } from "../../shared/json.js";
27
+ import { oneLine } from "../../shared/text.js";
20
28
  import { CommandError, EXIT, git } from "../lib.js";
21
29
  import { loopProgress } from "./counters.js";
22
30
  import { appendLedgerRows } from "./ledgers.js";
31
+ import { LOOPS, loopGateStep } from "./loops.js";
32
+ import { ITEM_SPLIT, letterAt, parseDecisionItems, skipProblem, undecidedBesidesLoop, } from "./open-decision.js";
23
33
  import { classifyAt } from "./runtime.js";
24
34
  import { positiveInt, str } from "./status.js";
25
35
  /** Exit code: `apply --by=headless` left hard blockers (no recommendation) for the owner. */
26
36
  export const EXIT_HARD_BLOCKERS = 4;
27
- const ITEM_SPLIT = /^(?=\*\*Q\d+ — )/m;
28
- const lineOf = (text, key) => new RegExp(`^${key}:[ \\t]*(.+?)[ \\t]*$`, "m").exec(text)?.[1] ?? null;
29
37
  /** Options one item may hold: one per letter, `A` to `Z`. */
30
38
  const MAX_OPTIONS = 26;
31
- /** `A`, `B`, … for option index `i`. */
32
- const letterAt = (i) => String.fromCharCode(65 + i);
33
- /** An option entry's leading letter (`A) `) dropped, so a parsed name stays bare. */
34
- const bareName = (s) => s.replace(/^[A-Z]\)[ \t]*/, "");
35
- /** A reply opening on an option letter: `B`, `B)`, `B — …`, `B) {option} …`, `B {option} …`. */
36
- const LETTER_REPLY = /^([A-Za-z])(?:\)|(?=[ \t—:,.-]|$))[ \t]*(?:[—:,.-][ \t]*)?/;
37
- /**
38
- * An answer read as the option it names. A leading letter of `options` (either case, with or
39
- * without `)`) becomes the option it labels: `B`, `B) Reject` and `B — too risky` read as
40
- * `Reject`, `Reject` and `Reject — too risky`. Any other answer is returned unchanged; with
41
- * no options known, only a leading `A) ` is dropped.
42
- */
43
- export function optionAnswer(answer, options) {
44
- if (options.length === 0)
45
- return bareName(answer);
46
- const m = LETTER_REPLY.exec(answer);
47
- const name = m === null ? undefined : options[m[1].toUpperCase().charCodeAt(0) - 65];
48
- if (m === null || name === undefined)
49
- return answer;
50
- const rest = answer.slice(m[0].length);
51
- if (rest.toLowerCase().startsWith(name.toLowerCase()))
52
- return name + rest.slice(name.length);
53
- if (rest === "")
54
- return name;
55
- return /[)—:,.-]/.test(m[0]) ? `${name} — ${rest}` : answer;
56
- }
57
39
  /** The option list as it is written: `A) {A} / B) {B}`. */
58
40
  const letteredOptions = (options) => options.map((o, i) => `${letterAt(i)}) ${o}`).join(" / ");
59
41
  /** The letter `name` holds in `options`, or null when it is not one of them. */
60
42
  const letterOf = (options, name) => options.includes(name) ? letterAt(options.indexOf(name)) : null;
61
- /** The items of a decision file's text, in file order. */
62
- export function parseDecisionItems(text) {
63
- return text
64
- .split(ITEM_SPLIT)
65
- .slice(1)
66
- .map((part) => {
67
- const head = /^\*\*Q(\d+) — (.+?):\*\*/.exec(part);
68
- const rec = lineOf(part, "Recommended");
69
- const none = /^No recommendation\b/m.test(part);
70
- const [option, ...why] = (rec ?? "").split(" — ");
71
- const options = (lineOf(part, "Options") ?? "")
72
- .split(" / ")
73
- .map((o) => bareName(o.trim()))
74
- .filter(Boolean);
75
- const answer = lineOf(part, "Decision");
76
- const decision = answer === null ? null : optionAnswer(answer, options);
77
- return {
78
- n: Number(head?.[1] ?? 0),
79
- title: head?.[2] ?? "",
80
- text: part.trimEnd(),
81
- options,
82
- recommended: none || rec === null ? null : bareName((option ?? "").trim()),
83
- reason: why.join(" — ").trim(),
84
- decision,
85
- assumed: decision !== null && /^Accept \(assumed\)/.test(decision),
86
- rejected: lineOf(part, "Rejected") !== null,
87
- deferred: lineOf(part, "Deferred") !== null,
88
- };
89
- });
90
- }
91
43
  /** `Status:` set to `status`. */
92
44
  const withStatus = (text, status) => /^Status:.*$/m.test(text)
93
45
  ? text.replace(/^Status:.*$/m, `Status: ${status}`)
@@ -127,37 +79,102 @@ const slug = (s) => s
127
79
  .replace(/[^a-z0-9]+/g, "-")
128
80
  .replace(/^-+|-+$/g, "")
129
81
  .slice(0, 60);
130
- const LOOPS = {
131
- verify: {
132
- title: "Verify",
133
- check: "build-plan-verify",
134
- fix: "build-plan-gaps-remediate",
135
- point: "verify",
136
- },
137
- tests: {
138
- title: "Tests",
139
- check: "build-run-tests",
140
- fix: "build-failure-diagnose",
141
- point: "tests",
142
- },
82
+ /** The `bkit tests base` output, checked field by field; a bad file is a usage error naming it. */
83
+ function readBaseCheck(file) {
84
+ const read = readJsonFile(file);
85
+ if (!read.ok)
86
+ throw new CommandError(EXIT.USAGE, `--base-check ${file} is missing or not JSON`);
87
+ const o = read.value;
88
+ const bad = (field, want) => new CommandError(EXIT.USAGE, `--base-check ${file}: field "${field}" ${want}`);
89
+ if (typeof o !== "object" || o === null || Array.isArray(o))
90
+ throw new CommandError(EXIT.USAGE, `--base-check ${file} must hold a JSON object`);
91
+ const verdict = o.verdict;
92
+ if (verdict !== "all" && verdict !== "some" && verdict !== "none" && verdict !== "unknown")
93
+ throw bad("verdict", "must be all, some, none or unknown");
94
+ const { failing, baseRed, adopt } = o;
95
+ const count = (k, fallback) => {
96
+ const v = o[k];
97
+ if (v === undefined)
98
+ return fallback;
99
+ if (typeof v !== "number" || !Number.isFinite(v))
100
+ throw bad(k, "must be a number");
101
+ return v;
102
+ };
103
+ if (typeof failing !== "number" || !Number.isFinite(failing))
104
+ throw bad("failing", "must be a number");
105
+ if (typeof baseRed !== "number" || !Number.isFinite(baseRed))
106
+ throw bad("baseRed", "must be a number");
107
+ if (typeof adopt !== "boolean")
108
+ throw bad("adopt", "must be true or false");
109
+ const text = (k) => {
110
+ const v = o[k];
111
+ if (v === null)
112
+ return null;
113
+ if (typeof v !== "string")
114
+ throw bad(k, "must be a string or null");
115
+ return v;
116
+ };
117
+ return {
118
+ verdict,
119
+ reason: text("reason"),
120
+ base: text("base"),
121
+ source: text("source"),
122
+ failing,
123
+ baseRed,
124
+ branch: count("branch", failing - baseRed),
125
+ undetermined: count("undetermined", 0),
126
+ adopt,
127
+ };
128
+ }
129
+ /** The effect a bare fixed option name gets. */
130
+ const FIXED_EFFECTS = {
131
+ Accept: "the item is recorded as accepted and the build moves on",
132
+ "Fix now": "one more fix round runs before the build moves on",
133
+ Stop: "the run ends here with a handover; the next run resumes here",
134
+ "Try again": "one more fix round runs",
135
+ Decide: "the questions below are asked instead of another round",
143
136
  };
144
137
  function composeItems(raw) {
145
138
  if (!Array.isArray(raw))
146
139
  throw new CommandError(EXIT.USAGE, "--items must hold a JSON array");
147
140
  return raw.map((r, i) => {
148
141
  const o = (r ?? {});
149
- const s = (k) => (typeof o[k] === "string" ? o[k].trim() : "");
150
- const options = Array.isArray(o.options) ? o.options.filter((x) => typeof x === "string") : [];
151
- if (s("title") === "" || s("question") === "" || options.length === 0)
142
+ const s = (k) => (typeof o[k] === "string" ? oneLine(o[k]) : "");
143
+ const rawOptions = Array.isArray(o.options) ? o.options : [];
144
+ if (s("title") === "" || s("question") === "" || rawOptions.length === 0)
152
145
  throw new CommandError(EXIT.USAGE, `item ${i + 1}: needs title, question and options`);
153
- if (options.length > MAX_OPTIONS)
146
+ if (rawOptions.length > MAX_OPTIONS)
154
147
  throw new CommandError(EXIT.USAGE, `item ${i + 1}: at most ${MAX_OPTIONS} options (A-Z)`);
155
- if (s("noRecommendation") === "" && !options.includes(s("recommended")))
148
+ const options = rawOptions.map((x, k) => {
149
+ const bad = () => new CommandError(EXIT.USAGE, `item ${i + 1} (Q${i + 1}): option ${letterAt(k)} needs a name and an effect`);
150
+ let name;
151
+ let effect;
152
+ if (typeof x === "string") {
153
+ name = x.trim();
154
+ const fixed = FIXED_EFFECTS[name];
155
+ if (fixed === undefined)
156
+ throw bad();
157
+ effect = fixed;
158
+ }
159
+ else {
160
+ const ob = (x ?? {});
161
+ if (typeof ob.name !== "string" || typeof ob.effect !== "string")
162
+ throw bad();
163
+ name = oneLine(ob.name);
164
+ effect = oneLine(ob.effect);
165
+ if (name === "" || effect === "")
166
+ throw bad();
167
+ }
168
+ if (name.includes("—"))
169
+ throw new CommandError(EXIT.USAGE, `item ${i + 1} (Q${i + 1}): option name "${name}" must not contain a dash (—); put it in the effect`);
170
+ return { name, effect };
171
+ });
172
+ if (s("noRecommendation") === "" && !options.some((x) => x.name === s("recommended")))
156
173
  throw new CommandError(EXIT.USAGE, `item ${i + 1}: recommended must be one of its options, or set noRecommendation`);
157
174
  return {
158
175
  title: s("title"),
159
176
  question: s("question"),
160
- options: options,
177
+ options,
161
178
  recommended: s("recommended"),
162
179
  reason: s("reason"),
163
180
  noRecommendation: s("noRecommendation"),
@@ -166,15 +183,20 @@ function composeItems(raw) {
166
183
  }
167
184
  const itemLines = (n, it) => {
168
185
  const rec = it.recommended ?? "";
169
- const letter = letterOf(it.options, rec);
186
+ const names = it.options.map((o) => o.name);
187
+ const letter = letterOf(names, rec);
170
188
  return [
171
189
  `**Q${n} — ${it.title}:** ${it.question}`,
172
- `Options: ${letteredOptions(it.options)}`,
190
+ ...it.options.map((o, i) => `${letterAt(i)}) ${o.name} — ${o.effect}`),
173
191
  it.noRecommendation
174
- ? `No recommendation — ${it.noRecommendation}`
192
+ ? `Recommended: none — ${it.noRecommendation}`
175
193
  : `Recommended: ${letter === null ? rec : `${letter}) ${rec}`} — ${it.reason || "the orchestrator's call"}`,
194
+ it.noRecommendation || letter === null
195
+ ? "Default if unanswered: the run waits for you; the run stops when nobody can be asked"
196
+ : `Default if unanswered: the run waits for you; taken as ${letter} when nobody can be asked`,
176
197
  ];
177
198
  };
199
+ const fixed = (name) => ({ name, effect: FIXED_EFFECTS[name] });
178
200
  // ---------------------------------------------------------------------------
179
201
  // apply
180
202
  // ---------------------------------------------------------------------------
@@ -268,17 +290,26 @@ export const decisionsCommand = {
268
290
  {
269
291
  name: "items",
270
292
  type: "string",
271
- help: "JSON file: [{title, question, options, recommended, reason} | {…, noRecommendation}]",
293
+ help: "JSON file: [{title, question, options: [{name, effect}], recommended, reason} | {…, noRecommendation}]",
272
294
  },
273
295
  {
274
296
  name: "loop",
275
297
  type: "string",
276
- help: "verify | tests: add the progress block and the loop question as Q1",
298
+ help: "verify | holistic | tests: add the progress block and the loop question as Q1",
277
299
  },
278
300
  { name: "file", type: "string", help: "status.jsonl, with --loop" },
279
301
  { name: "group", type: "string", help: "with --loop=verify: the task group" },
280
- { name: "attempt", type: "string", help: "with --loop: the attempt just failed" },
302
+ {
303
+ name: "attempt",
304
+ type: "string",
305
+ help: "with --loop: the attempt just failed; one above --max (the round the limit refused) prints as --max",
306
+ },
281
307
  { name: "max", type: "string", help: "with --loop: the point's maxAttempts" },
308
+ {
309
+ name: "base-check",
310
+ type: "string",
311
+ help: "with --loop: the `bkit tests base` output JSON; adds the base-commit line and steers the recommendation",
312
+ },
282
313
  ],
283
314
  output: {
284
315
  file: "the decision file written",
@@ -300,43 +331,88 @@ export const decisionsCommand = {
300
331
  throw new CommandError(EXIT.USAGE, "--items is missing or not JSON");
301
332
  items = composeItems(read.value);
302
333
  }
334
+ const baseFlag = str(ctx.flags.baseCheck);
335
+ const baseCheck = baseFlag === undefined ? undefined : readBaseCheck(path.resolve(ctx.cwd, baseFlag));
303
336
  const lines = ["Status: OPEN", ...headers.filter((h) => !h.startsWith("Status:")), ""];
304
337
  let loopRecommended = null;
305
338
  const loopName = str(ctx.flags.loop);
306
339
  if (loopName !== undefined) {
307
340
  const loop = LOOPS[loopName];
308
341
  if (loop === undefined)
309
- throw new CommandError(EXIT.USAGE, "--loop must be verify or tests");
342
+ throw new CommandError(EXIT.USAGE, "--loop must be verify, holistic or tests");
310
343
  if (ctx.flags.file === undefined)
311
344
  throw new CommandError(EXIT.USAGE, "--loop needs --file");
312
- const p = loopProgress(path.resolve(ctx.cwd, String(ctx.flags.file)), ctx.cwd, "build", loop.check, loop.fix, positiveInt(ctx.flags.group, "group"));
313
- const attempt = str(ctx.flags.attempt) ?? String(p.rounds.length);
345
+ const group = positiveInt(ctx.flags.group, "group");
346
+ // A grouped gate counts only for a named group.
347
+ const gate = loopGateStep(loop, group) === undefined ? undefined : loop.gate;
348
+ const p = loopProgress(path.resolve(ctx.cwd, String(ctx.flags.file)), ctx.cwd, "build", loop.check, loop.fix, group, loop.sinceClean === true, gate);
314
349
  const max = str(ctx.flags.max) ?? "?";
315
350
  const changed = p.codeChanged === null ? "unknown" : p.codeChanged ? "yes" : "no";
316
- const trendLine = {
317
- "first-round": "This was the first round, so there is no trend yet.",
318
- closing: "Fewer problems after each round, and the code changed.",
319
- stuck: "No fewer problems, or the code did not change.",
320
- worse: "More problems than the first round.",
321
- }[p.trend];
322
351
  loopRecommended = p.recommend === "stop" ? "Decide" : "Try again";
323
- lines.push(`build ${loop.point}: attempt ${attempt} of ${max}`, "", "## Progress", "", `Problems after each round: ${p.counts || "none recorded"}`, `Code changed: ${changed}`, `Strategy: ${p.lastStrategy ?? "none"} → next ${p.nextStrategy}${p.finalSpent ? " (FINAL already used)" : ""}`, `Minutes per round: ${p.minutesPerRound ?? "unknown"}`, `Trend: ${p.trend}`, "", ...itemLines(1, {
352
+ const given = str(ctx.flags.attempt) ?? String(p.rounds.length);
353
+ const attemptNum = Number(given);
354
+ const maxNum = Number(max);
355
+ const limitUsed = Number.isFinite(attemptNum) && Number.isFinite(maxNum) && attemptNum >= maxNum;
356
+ // An attempt above max is the round the limit refused (`counters route ... :next`
357
+ // exits 1 with max + 1), so the rounds run are max.
358
+ const attempt = limitUsed && attemptNum > maxNum ? max : given;
359
+ const trendReason = p.trend === "unknown"
360
+ ? limitUsed
361
+ ? `the limit is used up and the counts cannot show whether the rounds helped (${p.trendLine})`
362
+ : `the counts cannot show whether the rounds helped (${p.trendLine})`
363
+ : loopRecommended === "Try again"
364
+ ? "the last round made progress"
365
+ : "another round is unlikely to close the remaining items";
366
+ let reason = trendReason;
367
+ let baseLine = [];
368
+ if (baseCheck !== undefined) {
369
+ const b = baseCheck;
370
+ const at = b.base ?? "unknown";
371
+ baseLine = [
372
+ b.verdict === "unknown"
373
+ ? `Also red on base ${at}: can't tell (${b.reason ?? "no reason given"})`
374
+ : `Also red on base ${at}: ${b.baseRed} of ${b.failing} (${b.source ?? "unknown"} run)`,
375
+ ];
376
+ if (b.verdict === "all") {
377
+ loopRecommended = items.length > 0 ? "Decide" : "Stop";
378
+ reason = `all ${b.failing} failing tests fail on \`dev\` too, so no round here can fix them. Fix \`dev\`, then resume. If the gate is still red after \`dev\` is fixed and the run resumed, the rest comes from this branch, and the gate re-run on resume shows it.${b.adopt ? " This run has no worktrees: merge \`dev\` into the branch before resuming." : ""}`;
379
+ }
380
+ else if (b.verdict === "some") {
381
+ const unchecked = b.undetermined > 0
382
+ ? ` ${b.undetermined} could not be checked: ${b.reason ?? "no reason given"}.`
383
+ : "";
384
+ reason = `a round can fix ${b.branch} of ${b.failing}; the build will still stop on the ${b.baseRed} from \`dev\`.${unchecked} ${trendReason}`;
385
+ }
386
+ else if (b.verdict === "none") {
387
+ reason = `the failures come from this branch, so a round can fix them. ${trendReason}`;
388
+ }
389
+ else {
390
+ reason = `cause unknown: ${b.reason ?? "no reason given"}. ${trendReason}`;
391
+ }
392
+ }
393
+ lines.push(`build ${loop.point}: attempt ${attempt} of ${max}`, "", "## Progress", "", `Problems after each round: ${p.counts || "none recorded"}`, ...(p.gateCounts === undefined
394
+ ? []
395
+ : [`${loop.gateTitle ?? "Gate"} failures after each round: ${p.gateCounts}`]), `Code changed: ${changed}`, `Strategy: ${p.lastStrategy ?? "none"} → next ${p.nextStrategy}${p.finalSpent ? " (FINAL already used)" : ""}`, `Minutes per round: ${p.minutesPerRound ?? "unknown"}`, `Trend: ${p.trend}`, ...baseLine, "", ...itemLines(1, {
324
396
  title: loop.title,
325
397
  question: loopRecommended === "Try again"
326
- ? `another fix round? ${trendLine}`
327
- : `decide the items below instead of another round? ${trendLine}`,
328
- options: items.length > 0 ? ["Try again", "Decide"] : ["Try again", "Stop"],
398
+ ? `another fix round? ${p.trendLine}`
399
+ : `decide the items below instead of another round? ${p.trendLine}`,
400
+ options: items.length > 0
401
+ ? [fixed("Try again"), fixed("Decide")]
402
+ : [fixed("Try again"), fixed("Stop")],
329
403
  recommended: items.length > 0 || loopRecommended === "Try again" ? loopRecommended : "Stop",
330
- reason: loopRecommended === "Try again"
331
- ? "the last round made progress"
332
- : "another round is unlikely to close the remaining items",
404
+ reason,
333
405
  }), "");
334
406
  if (items.length === 0 && loopRecommended === "Decide")
335
407
  loopRecommended = "Stop";
336
408
  }
337
409
  const first = loopName === undefined ? 1 : 2;
338
410
  items.forEach((it, i) => lines.push(...itemLines(first + i, it), ""));
339
- lines.push('Reply per question. "yes" takes every recommendation. "stop" writes a handover; the run can be resumed.', "");
411
+ const questionCount = items.length + (loopName === undefined ? 0 : 1);
412
+ lines.push('Reply with a letter per question, or "yes" to take every recommendation. "stop" ends here with a handover; the next run resumes here.');
413
+ if (questionCount >= 3)
414
+ lines.push('Or say "one by one" and I\'ll ask them one at a time.');
415
+ lines.push("");
340
416
  fs.mkdirSync(path.dirname(out), { recursive: true });
341
417
  fs.writeFileSync(out, lines.join("\n"), "utf-8");
342
418
  ctx.emit({
@@ -352,7 +428,7 @@ export const decisionsCommand = {
352
428
  use: "workflow",
353
429
  flags: [
354
430
  { name: "file", type: "string", required: true, help: "the decision file" },
355
- { name: "by", type: "string", required: true, help: "headless | owner" },
431
+ { name: "by", type: "string", required: true, help: "headless | owner | rerun" },
356
432
  { name: "q", type: "string", help: "--by=owner: the question number" },
357
433
  { name: "confirm", type: "boolean", help: "--by=owner: confirm the assumed Accept" },
358
434
  { name: "reject", type: "boolean", help: "--by=owner: reject the assumed Accept" },
@@ -394,8 +470,27 @@ export const decisionsCommand = {
394
470
  ctx.log(`hard blockers need the owner: Q${r.hardBlockers.join(", Q")}`);
395
471
  return r.hardBlockers.length > 0 ? EXIT_HARD_BLOCKERS : EXIT.OK;
396
472
  }
473
+ if (by === "rerun") {
474
+ const name = path.basename(file);
475
+ if (!/^Gate:[ \t]*FAIL\b/m.test(text.split(/\r?\n[ \t]*\r?\n/, 1)[0] ?? ""))
476
+ throw new CommandError(EXIT.USAGE, `${name} has no Gate: FAIL header`);
477
+ const status = /^Status:[ \t]*(\S+)/m.exec(text)?.[1] ?? "OPEN";
478
+ if (status !== "OPEN")
479
+ throw new CommandError(EXIT.USAGE, `${name} is Status: ${status}, not OPEN`);
480
+ const { hasLoop, undecided } = undecidedBesidesLoop(text);
481
+ if (!hasLoop)
482
+ throw new CommandError(EXIT.USAGE, `${name}: Q1 is not the loop question (no ## Progress block), so a re-run cannot answer it; undecided: ${undecided.join(", ") || "none"}`);
483
+ if (undecided.length > 0)
484
+ throw new CommandError(EXIT.USAGE, `${name} has undecided questions besides the loop question: ${undecided.join(", ")}`);
485
+ const out = withStatus(addUnder(text, 1, [
486
+ `Decision: Re-run gate — the owner resumed the run, so the gate runs again first (${today()})`,
487
+ ]), "DECIDED");
488
+ fs.writeFileSync(file, out, "utf-8");
489
+ ctx.emit({ status: "DECIDED" });
490
+ return EXIT.OK;
491
+ }
397
492
  if (by !== "owner")
398
- throw new CommandError(EXIT.USAGE, "--by must be headless or owner");
493
+ throw new CommandError(EXIT.USAGE, "--by must be headless, owner or rerun");
399
494
  const n = positiveInt(ctx.flags.q, "q");
400
495
  const reason = str(ctx.flags.reason);
401
496
  if (n === undefined ||
@@ -422,6 +517,26 @@ export const decisionsCommand = {
422
517
  return EXIT.OK;
423
518
  },
424
519
  },
520
+ skip: {
521
+ summary: "Whether a settled verify or holistic pause may route continue: exit 0 and route=continue when all five conditions hold, else exit 1 naming the first fact that fails.",
522
+ use: "workflow",
523
+ flags: [{ name: "file", type: "string", required: true, help: "the decision file" }],
524
+ output: {
525
+ route: "continue when every condition holds, else null",
526
+ problem: "null, or the first fact that fails: From not verify or holistic, an item not Accept or Accept (assumed), the loop question not Decide, a Gate: FAIL header, or a Source changed header missing or not false",
527
+ },
528
+ run: (ctx) => {
529
+ const file = path.resolve(ctx.cwd, String(ctx.flags.file));
530
+ const read = readTextFile(file);
531
+ if (!read.ok)
532
+ throw new CommandError(EXIT.USAGE, `${file} is missing or unreadable`);
533
+ const problem = skipProblem(read.text);
534
+ if (problem !== null)
535
+ ctx.log(`${path.basename(file)}: ${problem}`);
536
+ ctx.emit({ route: problem === null ? "continue" : null, problem });
537
+ return problem === null ? EXIT.OK : EXIT.NO;
538
+ },
539
+ },
425
540
  pending: {
426
541
  summary: "List the feature's assumed Accepts nobody confirmed; --defer writes one needs-decision deferral per item.",
427
542
  use: "workflow",
@@ -159,7 +159,8 @@ function touch(key, ...names) {
159
159
  fs.rmSync(file, { force: true });
160
160
  }
161
161
  }
162
- function pidAlive(pid) {
162
+ /** True while a process with this id exists, including one this user may not signal. */
163
+ export function pidAlive(pid) {
163
164
  try {
164
165
  process.kill(pid, 0);
165
166
  return true;
@@ -0,0 +1,60 @@
1
+ // The commit a feature's own work starts after, and the diff range measured from it.
2
+ // Kept apart from context.ts and status.ts so both can import it without an import cycle.
3
+ import { git } from "../lib.js";
4
+ export const ORIGIN_DEV = "origin/dev";
5
+ /**
6
+ * The commit the feature's own work starts after: the later of HEAD's meeting points with
7
+ * `origin/dev` and with local `dev`. Neither later than the other (origin/dev was merged
8
+ * into a branch cut from local dev) → a commit of the two merged, with both as parents;
9
+ * a conflict there → the `origin/dev` meeting point, logged once. No `origin/dev` meeting
10
+ * point → the name `origin/dev`.
11
+ */
12
+ export function featureBase(cwd, log = () => undefined) {
13
+ const o = git(cwd, ["merge-base", "HEAD", ORIGIN_DEV]);
14
+ if (o === null || o === "")
15
+ return ORIGIN_DEV;
16
+ const l = git(cwd, ["merge-base", "HEAD", "refs/heads/dev"]);
17
+ if (l === null || l === "" || l === o)
18
+ return o;
19
+ // Local dev already contains HEAD: its meeting point is HEAD itself, an empty range.
20
+ if (l === git(cwd, ["rev-parse", "HEAD"]))
21
+ return o;
22
+ const isAncestor = (a, b) => git(cwd, ["merge-base", "--is-ancestor", a, b]) !== null;
23
+ if (isAncestor(o, l))
24
+ return l;
25
+ if (isAncestor(l, o))
26
+ return o;
27
+ const tree = git(cwd, ["merge-tree", "--write-tree", l, o])?.split("\n")[0];
28
+ const combined = tree === undefined || tree === ""
29
+ ? null
30
+ : git(cwd, [
31
+ "-c",
32
+ "user.name=bkit",
33
+ "-c",
34
+ "user.email=bkit@localhost",
35
+ "commit-tree",
36
+ tree,
37
+ "-p",
38
+ l,
39
+ "-p",
40
+ o,
41
+ "-m",
42
+ "feature base",
43
+ ]);
44
+ if (combined === null || combined === "") {
45
+ log(`feature base: local dev and ${ORIGIN_DEV} do not merge cleanly — measuring from the ${ORIGIN_DEV} meeting point ${o}`);
46
+ return o;
47
+ }
48
+ return combined;
49
+ }
50
+ /**
51
+ * The base and range a diff reader measures when `--base` is absent. A feature base that is
52
+ * the `origin/dev` meeting point is named `origin/dev` (`origin/dev...HEAD`); any other is a
53
+ * commit read straight to HEAD (`{sha}..HEAD`), because the combined commit is not an ancestor.
54
+ */
55
+ export function defaultRange(cwd, log = () => undefined) {
56
+ const sha = featureBase(cwd, log);
57
+ if (sha === ORIGIN_DEV || sha === git(cwd, ["merge-base", "HEAD", ORIGIN_DEV]))
58
+ return { base: ORIGIN_DEV, range: `${ORIGIN_DEV}...HEAD` };
59
+ return { base: sha, range: `${sha}..HEAD` };
60
+ }