@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
@@ -18,62 +25,28 @@
18
25
  import * as fs from "node:fs";
19
26
  import * as path from "node:path";
20
27
 
21
- import { readJsonFile } from "../../shared/json.js";
28
+ import { readJsonFile, readTextFile } from "../../shared/json.js";
29
+ import { oneLine } from "../../shared/text.js";
22
30
  import { CommandError, EXIT, git, type CommandSpec } from "../lib.js";
23
31
  import { loopProgress } from "./counters.js";
24
32
  import { appendLedgerRows } from "./ledgers.js";
33
+ import { LOOPS, loopGateStep } from "./loops.js";
34
+ import {
35
+ ITEM_SPLIT,
36
+ letterAt,
37
+ parseDecisionItems,
38
+ skipProblem,
39
+ undecidedBesidesLoop,
40
+ type DecisionItem,
41
+ } from "./open-decision.js";
25
42
  import { classifyAt } from "./runtime.js";
26
43
  import { positiveInt, str } from "./status.js";
27
44
 
28
- /** One question of a decision file. */
29
- export interface DecisionItem {
30
- n: number;
31
- title: string;
32
- /** The item's whole text, from its `**Q{n}` line to the next item. */
33
- text: string;
34
- options: string[];
35
- /** The recommended option; null for a hard blocker. */
36
- recommended: string | null;
37
- reason: string;
38
- /** The `Decision:` line's text, a lettered answer read as its option (`optionAnswer`). */
39
- decision: string | null;
40
- assumed: boolean;
41
- rejected: boolean;
42
- deferred: boolean;
43
- }
44
-
45
45
  /** Exit code: `apply --by=headless` left hard blockers (no recommendation) for the owner. */
46
46
  export const EXIT_HARD_BLOCKERS = 4;
47
47
 
48
- const ITEM_SPLIT = /^(?=\*\*Q\d+ — )/m;
49
- const lineOf = (text: string, key: string): string | null =>
50
- new RegExp(`^${key}:[ \\t]*(.+?)[ \\t]*$`, "m").exec(text)?.[1] ?? null;
51
-
52
48
  /** Options one item may hold: one per letter, `A` to `Z`. */
53
49
  const MAX_OPTIONS = 26;
54
- /** `A`, `B`, … for option index `i`. */
55
- const letterAt = (i: number): string => String.fromCharCode(65 + i);
56
- /** An option entry's leading letter (`A) `) dropped, so a parsed name stays bare. */
57
- const bareName = (s: string): string => s.replace(/^[A-Z]\)[ \t]*/, "");
58
- /** A reply opening on an option letter: `B`, `B)`, `B — …`, `B) {option} …`, `B {option} …`. */
59
- const LETTER_REPLY = /^([A-Za-z])(?:\)|(?=[ \t—:,.-]|$))[ \t]*(?:[—:,.-][ \t]*)?/;
60
-
61
- /**
62
- * An answer read as the option it names. A leading letter of `options` (either case, with or
63
- * without `)`) becomes the option it labels: `B`, `B) Reject` and `B — too risky` read as
64
- * `Reject`, `Reject` and `Reject — too risky`. Any other answer is returned unchanged; with
65
- * no options known, only a leading `A) ` is dropped.
66
- */
67
- export function optionAnswer(answer: string, options: string[]): string {
68
- if (options.length === 0) return bareName(answer);
69
- const m = LETTER_REPLY.exec(answer);
70
- const name = m === null ? undefined : options[m[1]!.toUpperCase().charCodeAt(0) - 65];
71
- if (m === null || name === undefined) return answer;
72
- const rest = answer.slice(m[0].length);
73
- if (rest.toLowerCase().startsWith(name.toLowerCase())) return name + rest.slice(name.length);
74
- if (rest === "") return name;
75
- return /[)—:,.-]/.test(m[0]) ? `${name} — ${rest}` : answer;
76
- }
77
50
  /** The option list as it is written: `A) {A} / B) {B}`. */
78
51
  const letteredOptions = (options: string[]): string =>
79
52
  options.map((o, i) => `${letterAt(i)}) ${o}`).join(" / ");
@@ -81,37 +54,6 @@ const letteredOptions = (options: string[]): string =>
81
54
  const letterOf = (options: string[], name: string): string | null =>
82
55
  options.includes(name) ? letterAt(options.indexOf(name)) : null;
83
56
 
84
- /** The items of a decision file's text, in file order. */
85
- export function parseDecisionItems(text: string): DecisionItem[] {
86
- return text
87
- .split(ITEM_SPLIT)
88
- .slice(1)
89
- .map((part) => {
90
- const head = /^\*\*Q(\d+) — (.+?):\*\*/.exec(part);
91
- const rec = lineOf(part, "Recommended");
92
- const none = /^No recommendation\b/m.test(part);
93
- const [option, ...why] = (rec ?? "").split(" — ");
94
- const options = (lineOf(part, "Options") ?? "")
95
- .split(" / ")
96
- .map((o) => bareName(o.trim()))
97
- .filter(Boolean);
98
- const answer = lineOf(part, "Decision");
99
- const decision = answer === null ? null : optionAnswer(answer, options);
100
- return {
101
- n: Number(head?.[1] ?? 0),
102
- title: head?.[2] ?? "",
103
- text: part.trimEnd(),
104
- options,
105
- recommended: none || rec === null ? null : bareName((option ?? "").trim()),
106
- reason: why.join(" — ").trim(),
107
- decision,
108
- assumed: decision !== null && /^Accept \(assumed\)/.test(decision),
109
- rejected: lineOf(part, "Rejected") !== null,
110
- deferred: lineOf(part, "Deferred") !== null,
111
- };
112
- });
113
- }
114
-
115
57
  /** `Status:` set to `status`. */
116
58
  const withStatus = (text: string, status: string) =>
117
59
  /^Status:.*$/m.test(text)
@@ -160,42 +102,123 @@ const slug = (s: string) =>
160
102
  // compose
161
103
  // ---------------------------------------------------------------------------
162
104
 
105
+ interface ComposeOption {
106
+ name: string;
107
+ effect: string;
108
+ }
109
+
163
110
  interface ComposeItem {
164
111
  title: string;
165
112
  question: string;
166
- options: string[];
113
+ options: ComposeOption[];
167
114
  recommended?: string;
168
115
  reason?: string;
169
116
  /** Set for a hard blocker: why no agent can settle it. No recommendation is written. */
170
117
  noRecommendation?: string;
171
118
  }
172
119
 
173
- const LOOPS: Record<string, { title: string; check: string; fix: string; point: string }> = {
174
- verify: {
175
- title: "Verify",
176
- check: "build-plan-verify",
177
- fix: "build-plan-gaps-remediate",
178
- point: "verify",
179
- },
180
- tests: {
181
- title: "Tests",
182
- check: "build-run-tests",
183
- fix: "build-failure-diagnose",
184
- point: "tests",
185
- },
120
+ interface BaseCheck {
121
+ verdict: "all" | "some" | "none" | "unknown";
122
+ reason: string | null;
123
+ base: string | null;
124
+ source: string | null;
125
+ failing: number;
126
+ baseRed: number;
127
+ branch: number;
128
+ undetermined: number;
129
+ adopt: boolean;
130
+ }
131
+
132
+ /** The `bkit tests base` output, checked field by field; a bad file is a usage error naming it. */
133
+ function readBaseCheck(file: string): BaseCheck {
134
+ const read = readJsonFile(file);
135
+ if (!read.ok) throw new CommandError(EXIT.USAGE, `--base-check ${file} is missing or not JSON`);
136
+ const o = read.value as Record<string, unknown> | null;
137
+ const bad = (field: string, want: string) =>
138
+ new CommandError(EXIT.USAGE, `--base-check ${file}: field "${field}" ${want}`);
139
+ if (typeof o !== "object" || o === null || Array.isArray(o))
140
+ throw new CommandError(EXIT.USAGE, `--base-check ${file} must hold a JSON object`);
141
+ const verdict = o.verdict;
142
+ if (verdict !== "all" && verdict !== "some" && verdict !== "none" && verdict !== "unknown")
143
+ throw bad("verdict", "must be all, some, none or unknown");
144
+ const { failing, baseRed, adopt } = o;
145
+ const count = (k: string, fallback: number): number => {
146
+ const v = o[k];
147
+ if (v === undefined) return fallback;
148
+ if (typeof v !== "number" || !Number.isFinite(v)) throw bad(k, "must be a number");
149
+ return v;
150
+ };
151
+ if (typeof failing !== "number" || !Number.isFinite(failing))
152
+ throw bad("failing", "must be a number");
153
+ if (typeof baseRed !== "number" || !Number.isFinite(baseRed))
154
+ throw bad("baseRed", "must be a number");
155
+ if (typeof adopt !== "boolean") throw bad("adopt", "must be true or false");
156
+ const text = (k: string): string | null => {
157
+ const v = o[k];
158
+ if (v === null) return null;
159
+ if (typeof v !== "string") throw bad(k, "must be a string or null");
160
+ return v;
161
+ };
162
+ return {
163
+ verdict,
164
+ reason: text("reason"),
165
+ base: text("base"),
166
+ source: text("source"),
167
+ failing,
168
+ baseRed,
169
+ branch: count("branch", failing - baseRed),
170
+ undetermined: count("undetermined", 0),
171
+ adopt,
172
+ };
173
+ }
174
+
175
+ /** The effect a bare fixed option name gets. */
176
+ const FIXED_EFFECTS: Record<string, string> = {
177
+ Accept: "the item is recorded as accepted and the build moves on",
178
+ "Fix now": "one more fix round runs before the build moves on",
179
+ Stop: "the run ends here with a handover; the next run resumes here",
180
+ "Try again": "one more fix round runs",
181
+ Decide: "the questions below are asked instead of another round",
186
182
  };
187
183
 
188
184
  function composeItems(raw: unknown): ComposeItem[] {
189
185
  if (!Array.isArray(raw)) throw new CommandError(EXIT.USAGE, "--items must hold a JSON array");
190
186
  return raw.map((r, i) => {
191
187
  const o = (r ?? {}) as Record<string, unknown>;
192
- const s = (k: string) => (typeof o[k] === "string" ? (o[k] as string).trim() : "");
193
- const options = Array.isArray(o.options) ? o.options.filter((x) => typeof x === "string") : [];
194
- if (s("title") === "" || s("question") === "" || options.length === 0)
188
+ const s = (k: string) => (typeof o[k] === "string" ? oneLine(o[k] as string) : "");
189
+ const rawOptions: unknown[] = Array.isArray(o.options) ? o.options : [];
190
+ if (s("title") === "" || s("question") === "" || rawOptions.length === 0)
195
191
  throw new CommandError(EXIT.USAGE, `item ${i + 1}: needs title, question and options`);
196
- if (options.length > MAX_OPTIONS)
192
+ if (rawOptions.length > MAX_OPTIONS)
197
193
  throw new CommandError(EXIT.USAGE, `item ${i + 1}: at most ${MAX_OPTIONS} options (A-Z)`);
198
- if (s("noRecommendation") === "" && !options.includes(s("recommended")))
194
+ const options: ComposeOption[] = rawOptions.map((x, k) => {
195
+ const bad = () =>
196
+ new CommandError(
197
+ EXIT.USAGE,
198
+ `item ${i + 1} (Q${i + 1}): option ${letterAt(k)} needs a name and an effect`,
199
+ );
200
+ let name: string;
201
+ let effect: string;
202
+ if (typeof x === "string") {
203
+ name = x.trim();
204
+ const fixed = FIXED_EFFECTS[name];
205
+ if (fixed === undefined) throw bad();
206
+ effect = fixed;
207
+ } else {
208
+ const ob = (x ?? {}) as Record<string, unknown>;
209
+ if (typeof ob.name !== "string" || typeof ob.effect !== "string") throw bad();
210
+ name = oneLine(ob.name);
211
+ effect = oneLine(ob.effect);
212
+ if (name === "" || effect === "") throw bad();
213
+ }
214
+ if (name.includes("—"))
215
+ throw new CommandError(
216
+ EXIT.USAGE,
217
+ `item ${i + 1} (Q${i + 1}): option name "${name}" must not contain a dash (—); put it in the effect`,
218
+ );
219
+ return { name, effect };
220
+ });
221
+ if (s("noRecommendation") === "" && !options.some((x) => x.name === s("recommended")))
199
222
  throw new CommandError(
200
223
  EXIT.USAGE,
201
224
  `item ${i + 1}: recommended must be one of its options, or set noRecommendation`,
@@ -203,7 +226,7 @@ function composeItems(raw: unknown): ComposeItem[] {
203
226
  return {
204
227
  title: s("title"),
205
228
  question: s("question"),
206
- options: options as string[],
229
+ options,
207
230
  recommended: s("recommended"),
208
231
  reason: s("reason"),
209
232
  noRecommendation: s("noRecommendation"),
@@ -213,16 +236,22 @@ function composeItems(raw: unknown): ComposeItem[] {
213
236
 
214
237
  const itemLines = (n: number, it: ComposeItem): string[] => {
215
238
  const rec = it.recommended ?? "";
216
- const letter = letterOf(it.options, rec);
239
+ const names = it.options.map((o) => o.name);
240
+ const letter = letterOf(names, rec);
217
241
  return [
218
242
  `**Q${n} — ${it.title}:** ${it.question}`,
219
- `Options: ${letteredOptions(it.options)}`,
243
+ ...it.options.map((o, i) => `${letterAt(i)}) ${o.name} — ${o.effect}`),
220
244
  it.noRecommendation
221
- ? `No recommendation — ${it.noRecommendation}`
245
+ ? `Recommended: none — ${it.noRecommendation}`
222
246
  : `Recommended: ${letter === null ? rec : `${letter}) ${rec}`} — ${it.reason || "the orchestrator's call"}`,
247
+ it.noRecommendation || letter === null
248
+ ? "Default if unanswered: the run waits for you; the run stops when nobody can be asked"
249
+ : `Default if unanswered: the run waits for you; taken as ${letter} when nobody can be asked`,
223
250
  ];
224
251
  };
225
252
 
253
+ const fixed = (name: string): ComposeOption => ({ name, effect: FIXED_EFFECTS[name]! });
254
+
226
255
  // ---------------------------------------------------------------------------
227
256
  // apply
228
257
  // ---------------------------------------------------------------------------
@@ -330,17 +359,26 @@ export const decisionsCommand: CommandSpec = {
330
359
  {
331
360
  name: "items",
332
361
  type: "string",
333
- help: "JSON file: [{title, question, options, recommended, reason} | {…, noRecommendation}]",
362
+ help: "JSON file: [{title, question, options: [{name, effect}], recommended, reason} | {…, noRecommendation}]",
334
363
  },
335
364
  {
336
365
  name: "loop",
337
366
  type: "string",
338
- help: "verify | tests: add the progress block and the loop question as Q1",
367
+ help: "verify | holistic | tests: add the progress block and the loop question as Q1",
339
368
  },
340
369
  { name: "file", type: "string", help: "status.jsonl, with --loop" },
341
370
  { name: "group", type: "string", help: "with --loop=verify: the task group" },
342
- { name: "attempt", type: "string", help: "with --loop: the attempt just failed" },
371
+ {
372
+ name: "attempt",
373
+ type: "string",
374
+ help: "with --loop: the attempt just failed; one above --max (the round the limit refused) prints as --max",
375
+ },
343
376
  { name: "max", type: "string", help: "with --loop: the point's maxAttempts" },
377
+ {
378
+ name: "base-check",
379
+ type: "string",
380
+ help: "with --loop: the `bkit tests base` output JSON; adds the base-commit line and steers the recommendation",
381
+ },
344
382
  ],
345
383
  output: {
346
384
  file: "the decision file written",
@@ -360,57 +398,103 @@ export const decisionsCommand: CommandSpec = {
360
398
  if (!read.ok) throw new CommandError(EXIT.USAGE, "--items is missing or not JSON");
361
399
  items = composeItems(read.value);
362
400
  }
401
+ const baseFlag = str(ctx.flags.baseCheck);
402
+ const baseCheck =
403
+ baseFlag === undefined ? undefined : readBaseCheck(path.resolve(ctx.cwd, baseFlag));
363
404
  const lines = ["Status: OPEN", ...headers.filter((h) => !h.startsWith("Status:")), ""];
364
405
  let loopRecommended: string | null = null;
365
406
  const loopName = str(ctx.flags.loop);
366
407
  if (loopName !== undefined) {
367
408
  const loop = LOOPS[loopName];
368
409
  if (loop === undefined)
369
- throw new CommandError(EXIT.USAGE, "--loop must be verify or tests");
410
+ throw new CommandError(EXIT.USAGE, "--loop must be verify, holistic or tests");
370
411
  if (ctx.flags.file === undefined)
371
412
  throw new CommandError(EXIT.USAGE, "--loop needs --file");
413
+ const group = positiveInt(ctx.flags.group, "group");
414
+ // A grouped gate counts only for a named group.
415
+ const gate = loopGateStep(loop, group) === undefined ? undefined : loop.gate;
372
416
  const p = loopProgress(
373
417
  path.resolve(ctx.cwd, String(ctx.flags.file)),
374
418
  ctx.cwd,
375
419
  "build",
376
420
  loop.check,
377
421
  loop.fix,
378
- positiveInt(ctx.flags.group, "group"),
422
+ group,
423
+ loop.sinceClean === true,
424
+ gate,
379
425
  );
380
- const attempt = str(ctx.flags.attempt) ?? String(p.rounds.length);
381
426
  const max = str(ctx.flags.max) ?? "?";
382
427
  const changed = p.codeChanged === null ? "unknown" : p.codeChanged ? "yes" : "no";
383
- const trendLine = {
384
- "first-round": "This was the first round, so there is no trend yet.",
385
- closing: "Fewer problems after each round, and the code changed.",
386
- stuck: "No fewer problems, or the code did not change.",
387
- worse: "More problems than the first round.",
388
- }[p.trend];
389
428
  loopRecommended = p.recommend === "stop" ? "Decide" : "Try again";
429
+ const given = str(ctx.flags.attempt) ?? String(p.rounds.length);
430
+ const attemptNum = Number(given);
431
+ const maxNum = Number(max);
432
+ const limitUsed =
433
+ Number.isFinite(attemptNum) && Number.isFinite(maxNum) && attemptNum >= maxNum;
434
+ // An attempt above max is the round the limit refused (`counters route ... :next`
435
+ // exits 1 with max + 1), so the rounds run are max.
436
+ const attempt = limitUsed && attemptNum > maxNum ? max : given;
437
+ const trendReason =
438
+ p.trend === "unknown"
439
+ ? limitUsed
440
+ ? `the limit is used up and the counts cannot show whether the rounds helped (${p.trendLine})`
441
+ : `the counts cannot show whether the rounds helped (${p.trendLine})`
442
+ : loopRecommended === "Try again"
443
+ ? "the last round made progress"
444
+ : "another round is unlikely to close the remaining items";
445
+ let reason = trendReason;
446
+ let baseLine: string[] = [];
447
+ if (baseCheck !== undefined) {
448
+ const b = baseCheck;
449
+ const at = b.base ?? "unknown";
450
+ baseLine = [
451
+ b.verdict === "unknown"
452
+ ? `Also red on base ${at}: can't tell (${b.reason ?? "no reason given"})`
453
+ : `Also red on base ${at}: ${b.baseRed} of ${b.failing} (${b.source ?? "unknown"} run)`,
454
+ ];
455
+ if (b.verdict === "all") {
456
+ loopRecommended = items.length > 0 ? "Decide" : "Stop";
457
+ 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." : ""}`;
458
+ } else if (b.verdict === "some") {
459
+ const unchecked =
460
+ b.undetermined > 0
461
+ ? ` ${b.undetermined} could not be checked: ${b.reason ?? "no reason given"}.`
462
+ : "";
463
+ reason = `a round can fix ${b.branch} of ${b.failing}; the build will still stop on the ${b.baseRed} from \`dev\`.${unchecked} ${trendReason}`;
464
+ } else if (b.verdict === "none") {
465
+ reason = `the failures come from this branch, so a round can fix them. ${trendReason}`;
466
+ } else {
467
+ reason = `cause unknown: ${b.reason ?? "no reason given"}. ${trendReason}`;
468
+ }
469
+ }
390
470
  lines.push(
391
471
  `build ${loop.point}: attempt ${attempt} of ${max}`,
392
472
  "",
393
473
  "## Progress",
394
474
  "",
395
475
  `Problems after each round: ${p.counts || "none recorded"}`,
476
+ ...(p.gateCounts === undefined
477
+ ? []
478
+ : [`${loop.gateTitle ?? "Gate"} failures after each round: ${p.gateCounts}`]),
396
479
  `Code changed: ${changed}`,
397
480
  `Strategy: ${p.lastStrategy ?? "none"} → next ${p.nextStrategy}${p.finalSpent ? " (FINAL already used)" : ""}`,
398
481
  `Minutes per round: ${p.minutesPerRound ?? "unknown"}`,
399
482
  `Trend: ${p.trend}`,
483
+ ...baseLine,
400
484
  "",
401
485
  ...itemLines(1, {
402
486
  title: loop.title,
403
487
  question:
404
488
  loopRecommended === "Try again"
405
- ? `another fix round? ${trendLine}`
406
- : `decide the items below instead of another round? ${trendLine}`,
407
- options: items.length > 0 ? ["Try again", "Decide"] : ["Try again", "Stop"],
489
+ ? `another fix round? ${p.trendLine}`
490
+ : `decide the items below instead of another round? ${p.trendLine}`,
491
+ options:
492
+ items.length > 0
493
+ ? [fixed("Try again"), fixed("Decide")]
494
+ : [fixed("Try again"), fixed("Stop")],
408
495
  recommended:
409
496
  items.length > 0 || loopRecommended === "Try again" ? loopRecommended : "Stop",
410
- reason:
411
- loopRecommended === "Try again"
412
- ? "the last round made progress"
413
- : "another round is unlikely to close the remaining items",
497
+ reason,
414
498
  }),
415
499
  "",
416
500
  );
@@ -418,10 +502,12 @@ export const decisionsCommand: CommandSpec = {
418
502
  }
419
503
  const first = loopName === undefined ? 1 : 2;
420
504
  items.forEach((it, i) => lines.push(...itemLines(first + i, it), ""));
505
+ const questionCount = items.length + (loopName === undefined ? 0 : 1);
421
506
  lines.push(
422
- 'Reply per question. "yes" takes every recommendation. "stop" writes a handover; the run can be resumed.',
423
- "",
507
+ 'Reply with a letter per question, or "yes" to take every recommendation. "stop" ends here with a handover; the next run resumes here.',
424
508
  );
509
+ if (questionCount >= 3) lines.push('Or say "one by one" and I\'ll ask them one at a time.');
510
+ lines.push("");
425
511
  fs.mkdirSync(path.dirname(out), { recursive: true });
426
512
  fs.writeFileSync(out, lines.join("\n"), "utf-8");
427
513
  ctx.emit({
@@ -438,7 +524,7 @@ export const decisionsCommand: CommandSpec = {
438
524
  use: "workflow",
439
525
  flags: [
440
526
  { name: "file", type: "string", required: true, help: "the decision file" },
441
- { name: "by", type: "string", required: true, help: "headless | owner" },
527
+ { name: "by", type: "string", required: true, help: "headless | owner | rerun" },
442
528
  { name: "q", type: "string", help: "--by=owner: the question number" },
443
529
  { name: "confirm", type: "boolean", help: "--by=owner: confirm the assumed Accept" },
444
530
  { name: "reject", type: "boolean", help: "--by=owner: reject the assumed Accept" },
@@ -485,7 +571,36 @@ export const decisionsCommand: CommandSpec = {
485
571
  ctx.log(`hard blockers need the owner: Q${r.hardBlockers.join(", Q")}`);
486
572
  return r.hardBlockers.length > 0 ? EXIT_HARD_BLOCKERS : EXIT.OK;
487
573
  }
488
- if (by !== "owner") throw new CommandError(EXIT.USAGE, "--by must be headless or owner");
574
+ if (by === "rerun") {
575
+ const name = path.basename(file);
576
+ if (!/^Gate:[ \t]*FAIL\b/m.test(text.split(/\r?\n[ \t]*\r?\n/, 1)[0] ?? ""))
577
+ throw new CommandError(EXIT.USAGE, `${name} has no Gate: FAIL header`);
578
+ const status = /^Status:[ \t]*(\S+)/m.exec(text)?.[1] ?? "OPEN";
579
+ if (status !== "OPEN")
580
+ throw new CommandError(EXIT.USAGE, `${name} is Status: ${status}, not OPEN`);
581
+ const { hasLoop, undecided } = undecidedBesidesLoop(text);
582
+ if (!hasLoop)
583
+ throw new CommandError(
584
+ EXIT.USAGE,
585
+ `${name}: Q1 is not the loop question (no ## Progress block), so a re-run cannot answer it; undecided: ${undecided.join(", ") || "none"}`,
586
+ );
587
+ if (undecided.length > 0)
588
+ throw new CommandError(
589
+ EXIT.USAGE,
590
+ `${name} has undecided questions besides the loop question: ${undecided.join(", ")}`,
591
+ );
592
+ const out = withStatus(
593
+ addUnder(text, 1, [
594
+ `Decision: Re-run gate — the owner resumed the run, so the gate runs again first (${today()})`,
595
+ ]),
596
+ "DECIDED",
597
+ );
598
+ fs.writeFileSync(file, out, "utf-8");
599
+ ctx.emit({ status: "DECIDED" });
600
+ return EXIT.OK;
601
+ }
602
+ if (by !== "owner")
603
+ throw new CommandError(EXIT.USAGE, "--by must be headless, owner or rerun");
489
604
  const n = positiveInt(ctx.flags.q, "q");
490
605
  const reason = str(ctx.flags.reason);
491
606
  if (
@@ -524,6 +639,26 @@ export const decisionsCommand: CommandSpec = {
524
639
  return EXIT.OK;
525
640
  },
526
641
  },
642
+ skip: {
643
+ summary:
644
+ "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.",
645
+ use: "workflow",
646
+ flags: [{ name: "file", type: "string", required: true, help: "the decision file" }],
647
+ output: {
648
+ route: "continue when every condition holds, else null",
649
+ problem:
650
+ "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",
651
+ },
652
+ run: (ctx) => {
653
+ const file = path.resolve(ctx.cwd, String(ctx.flags.file));
654
+ const read = readTextFile(file);
655
+ if (!read.ok) throw new CommandError(EXIT.USAGE, `${file} is missing or unreadable`);
656
+ const problem = skipProblem(read.text);
657
+ if (problem !== null) ctx.log(`${path.basename(file)}: ${problem}`);
658
+ ctx.emit({ route: problem === null ? "continue" : null, problem });
659
+ return problem === null ? EXIT.OK : EXIT.NO;
660
+ },
661
+ },
527
662
  pending: {
528
663
  summary:
529
664
  "List the feature's assumed Accepts nobody confirmed; --defer writes one needs-decision deferral per item.",
@@ -213,7 +213,8 @@ function touch(key: string, ...names: string[]): void {
213
213
  }
214
214
  }
215
215
 
216
- function pidAlive(pid: number): boolean {
216
+ /** True while a process with this id exists, including one this user may not signal. */
217
+ export function pidAlive(pid: number): boolean {
217
218
  try {
218
219
  process.kill(pid, 0);
219
220
  return true;
@@ -0,0 +1,66 @@
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
+
4
+ import { git } from "../lib.js";
5
+
6
+ export const ORIGIN_DEV = "origin/dev";
7
+
8
+ /**
9
+ * The commit the feature's own work starts after: the later of HEAD's meeting points with
10
+ * `origin/dev` and with local `dev`. Neither later than the other (origin/dev was merged
11
+ * into a branch cut from local dev) → a commit of the two merged, with both as parents;
12
+ * a conflict there → the `origin/dev` meeting point, logged once. No `origin/dev` meeting
13
+ * point → the name `origin/dev`.
14
+ */
15
+ export function featureBase(cwd: string, log: (line: string) => void = () => undefined): string {
16
+ const o = git(cwd, ["merge-base", "HEAD", ORIGIN_DEV]);
17
+ if (o === null || o === "") return ORIGIN_DEV;
18
+ const l = git(cwd, ["merge-base", "HEAD", "refs/heads/dev"]);
19
+ if (l === null || l === "" || l === o) return o;
20
+ // Local dev already contains HEAD: its meeting point is HEAD itself, an empty range.
21
+ if (l === git(cwd, ["rev-parse", "HEAD"])) return o;
22
+ const isAncestor = (a: string, b: string) =>
23
+ git(cwd, ["merge-base", "--is-ancestor", a, b]) !== null;
24
+ if (isAncestor(o, l)) return l;
25
+ if (isAncestor(l, o)) return o;
26
+ const tree = git(cwd, ["merge-tree", "--write-tree", l, o])?.split("\n")[0];
27
+ const combined =
28
+ 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(
46
+ `feature base: local dev and ${ORIGIN_DEV} do not merge cleanly — measuring from the ${ORIGIN_DEV} meeting point ${o}`,
47
+ );
48
+ return o;
49
+ }
50
+ return combined;
51
+ }
52
+
53
+ /**
54
+ * The base and range a diff reader measures when `--base` is absent. A feature base that is
55
+ * the `origin/dev` meeting point is named `origin/dev` (`origin/dev...HEAD`); any other is a
56
+ * commit read straight to HEAD (`{sha}..HEAD`), because the combined commit is not an ancestor.
57
+ */
58
+ export function defaultRange(
59
+ cwd: string,
60
+ log: (line: string) => void = () => undefined,
61
+ ): { base: string; range: string } {
62
+ const sha = featureBase(cwd, log);
63
+ if (sha === ORIGIN_DEV || sha === git(cwd, ["merge-base", "HEAD", ORIGIN_DEV]))
64
+ return { base: ORIGIN_DEV, range: `${ORIGIN_DEV}...HEAD` };
65
+ return { base: sha, range: `${sha}..HEAD` };
66
+ }