@cbartens/bkit 5.5.0 → 6.0.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 (297) hide show
  1. package/.bkit/README.md +30 -20
  2. package/.bkit/core/.agents/docs.md +1 -0
  3. package/.bkit/core/.agents/rules.md +51 -26
  4. package/.bkit/core/.bkit/README.md +29 -19
  5. package/.bkit/core/.bkit/authoring.md +117 -0
  6. package/.bkit/core/.bkit/cloud.md +11 -11
  7. package/.bkit/core/.bkit/comparison.md +5 -5
  8. package/.bkit/core/.bkit/install.md +20 -20
  9. package/.bkit/core/.bkit/jsonl.md +202 -122
  10. package/.bkit/core/.bkit/lite.md +1 -1
  11. package/.bkit/core/.bkit/pipeline.md +49 -52
  12. package/.bkit/core/.bkit/prompts.md +106 -167
  13. package/.bkit/core/.bkit/providers.md +29 -32
  14. package/.bkit/core/.bkit/templates.md +44 -18
  15. package/.bkit/core/.bkit/trackers.md +60 -28
  16. package/.bkit/core/.bkit/workflows.md +399 -359
  17. package/.bkit/core/AGENTS.md +16 -22
  18. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +14 -38
  19. package/.bkit/core/docs/templates/bkit-audit-adoption.md +16 -40
  20. package/.bkit/core/docs/templates/bkit-audit-agents.md +19 -43
  21. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +16 -40
  22. package/.bkit/core/docs/templates/bkit-audit-analytics.md +14 -38
  23. package/.bkit/core/docs/templates/bkit-audit-annotations.md +11 -35
  24. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +15 -39
  25. package/.bkit/core/docs/templates/bkit-audit-app-store.md +12 -36
  26. package/.bkit/core/docs/templates/bkit-audit-architecture.md +16 -40
  27. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +16 -40
  28. package/.bkit/core/docs/templates/bkit-audit-config.md +18 -42
  29. package/.bkit/core/docs/templates/bkit-audit-cost.md +16 -40
  30. package/.bkit/core/docs/templates/bkit-audit-coverage.md +15 -39
  31. package/.bkit/core/docs/templates/bkit-audit-database.md +16 -40
  32. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +15 -39
  33. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +15 -38
  34. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +16 -40
  35. package/.bkit/core/docs/templates/bkit-audit-documentation.md +11 -35
  36. package/.bkit/core/docs/templates/bkit-audit-duplication.md +18 -42
  37. package/.bkit/core/docs/templates/bkit-audit-failures.md +13 -37
  38. package/.bkit/core/docs/templates/bkit-audit-flakes.md +12 -36
  39. package/.bkit/core/docs/templates/bkit-audit-gates.md +14 -38
  40. package/.bkit/core/docs/templates/bkit-audit-issues.md +15 -39
  41. package/.bkit/core/docs/templates/bkit-audit-llm.md +16 -40
  42. package/.bkit/core/docs/templates/bkit-audit-logs.md +14 -38
  43. package/.bkit/core/docs/templates/bkit-audit-models.md +12 -36
  44. package/.bkit/core/docs/templates/bkit-audit-privacy.md +12 -36
  45. package/.bkit/core/docs/templates/bkit-audit-prompts.md +15 -39
  46. package/.bkit/core/docs/templates/bkit-audit-red-team.md +15 -39
  47. package/.bkit/core/docs/templates/bkit-audit-reliability.md +15 -39
  48. package/.bkit/core/docs/templates/bkit-audit-repo.md +12 -36
  49. package/.bkit/core/docs/templates/bkit-audit-security.md +13 -37
  50. package/.bkit/core/docs/templates/bkit-audit-slop.md +14 -38
  51. package/.bkit/core/docs/templates/bkit-audit-testing.md +12 -36
  52. package/.bkit/core/docs/templates/bkit-audit-usability.md +16 -40
  53. package/.bkit/core/docs/templates/bkit-plan.md +97 -226
  54. package/.bkit/core/engine/checks/after/ci-yml.ts +39 -30
  55. package/.bkit/core/engine/checks/after/github.ts +101 -72
  56. package/.bkit/core/engine/checks/after/index.ts +10 -12
  57. package/.bkit/core/engine/checks/after/suppression.ts +8 -5
  58. package/.bkit/core/engine/checks/after/tools.ts +47 -92
  59. package/.bkit/core/engine/checks/before/env.ts +2 -2
  60. package/.bkit/core/engine/checks/before/files.ts +5 -4
  61. package/.bkit/core/engine/checks/before/index.ts +18 -1
  62. package/.bkit/core/engine/checks/before/repo.ts +168 -2
  63. package/.bkit/core/engine/checks/tips/catalogue.ts +16 -5
  64. package/.bkit/core/engine/checks/tips/detect.ts +34 -0
  65. package/.bkit/core/engine/checks/tips/index.ts +10 -7
  66. package/.bkit/core/engine/cli.ts +20 -53
  67. package/.bkit/core/engine/commands/analysis.ts +171 -140
  68. package/.bkit/core/engine/commands/ci/ci.ts +6 -6
  69. package/.bkit/core/engine/commands/comply.ts +77 -103
  70. package/.bkit/core/engine/commands/install/doctor.ts +2 -2
  71. package/.bkit/core/engine/commands/install/install.ts +57 -18
  72. package/.bkit/core/engine/commands/install/uninstall.ts +65 -28
  73. package/.bkit/core/engine/commands/land.ts +18 -12
  74. package/.bkit/core/engine/commands/lib.ts +79 -17
  75. package/.bkit/core/engine/commands/registry.ts +4 -0
  76. package/.bkit/core/engine/commands/setup/setup.ts +7 -7
  77. package/.bkit/core/engine/commands/stats.ts +204 -0
  78. package/.bkit/core/engine/commands/tips.ts +10 -5
  79. package/.bkit/core/engine/commands/workflow/branches.ts +741 -62
  80. package/.bkit/core/engine/commands/workflow/challenge.ts +673 -0
  81. package/.bkit/core/engine/commands/workflow/context.ts +853 -29
  82. package/.bkit/core/engine/commands/workflow/counters.ts +267 -84
  83. package/.bkit/core/engine/commands/workflow/decisions.ts +541 -0
  84. package/.bkit/core/engine/commands/workflow/disk.ts +2 -2
  85. package/.bkit/core/engine/commands/workflow/fids.ts +793 -33
  86. package/.bkit/core/engine/commands/workflow/issues.ts +427 -105
  87. package/.bkit/core/engine/commands/workflow/ledgers.ts +884 -27
  88. package/.bkit/core/engine/commands/workflow/locks.ts +26 -2
  89. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +582 -0
  90. package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
  91. package/.bkit/core/engine/commands/workflow/prs.ts +166 -30
  92. package/.bkit/core/engine/commands/workflow/repo.ts +59 -7
  93. package/.bkit/core/engine/commands/workflow/roadmap.ts +16 -7
  94. package/.bkit/core/engine/commands/workflow/run-facts.ts +501 -0
  95. package/.bkit/core/engine/commands/workflow/runs.ts +179 -49
  96. package/.bkit/core/engine/commands/workflow/runtime.ts +22 -1
  97. package/.bkit/core/engine/commands/workflow/status.ts +142 -29
  98. package/.bkit/core/engine/commands/workflow/step-table.ts +339 -0
  99. package/.bkit/core/engine/commands/workflow/steps.ts +213 -88
  100. package/.bkit/core/engine/commands/workflow/summary.ts +398 -0
  101. package/.bkit/core/engine/commands/workflow/tests.ts +1013 -148
  102. package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
  103. package/.bkit/core/engine/commands/workflow/workflows.ts +984 -207
  104. package/.bkit/core/engine/commands/workflow/workstreams.ts +11 -5
  105. package/.bkit/core/engine/commands/workflow/worktrees.ts +276 -22
  106. package/.bkit/core/engine/install/manifest.ts +11 -9
  107. package/.bkit/core/engine/install/modules/cloud.ts +21 -13
  108. package/.bkit/core/engine/install/modules/core.ts +325 -7
  109. package/.bkit/core/engine/install/modules/opencode.ts +2 -2
  110. package/.bkit/core/engine/install/version-file.ts +6 -2
  111. package/.bkit/core/engine/ledgers/migrate.ts +92 -0
  112. package/.bkit/core/engine/ledgers/status.ts +92 -15
  113. package/.bkit/core/engine/ledgers/telemetry.ts +1261 -254
  114. package/.bkit/core/engine/render/hosts.ts +4 -0
  115. package/.bkit/core/engine/render/models.ts +12 -0
  116. package/.bkit/core/engine/shared/branches.ts +4 -1
  117. package/.bkit/core/engine/shared/egress.ts +7 -0
  118. package/.bkit/core/engine/shared/json.ts +25 -7
  119. package/.bkit/core/engine/shared/settings.ts +202 -33
  120. package/.bkit/core/engine/shared/text.ts +361 -0
  121. package/.bkit/core/engine/tools/grammar-density.ts +215 -0
  122. package/.bkit/core/engine/tools/instructions-sources.ts +834 -0
  123. package/.bkit/core/engine/tools/instructions.ts +1751 -0
  124. package/.bkit/core/hooks/gateguard-engine.js +24 -23
  125. package/.bkit/core/hooks/guardrails-shell.js +2 -3
  126. package/.bkit/core/hooks/guardrails-tiers.js +7 -1
  127. package/.bkit/core/hooks/readguard-engine.js +2 -2
  128. package/.bkit/core/prompts/bkit-audit-generate.md +62 -25
  129. package/.bkit/core/prompts/bkit-build-challenge-1.md +40 -17
  130. package/.bkit/core/prompts/bkit-build-challenge-2.md +44 -17
  131. package/.bkit/core/prompts/bkit-build-install-skills.md +26 -13
  132. package/.bkit/core/prompts/bkit-build-plan-convert.md +74 -0
  133. package/.bkit/core/prompts/bkit-build-plan-current.md +26 -13
  134. package/.bkit/core/prompts/bkit-build-plan-execute.md +74 -26
  135. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +64 -23
  136. package/.bkit/core/prompts/bkit-build-plan-verify.md +57 -33
  137. package/.bkit/core/prompts/bkit-debug-abort-handover.md +30 -14
  138. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +34 -14
  139. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +34 -17
  140. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +26 -13
  141. package/.bkit/core/prompts/bkit-debug-failure-soak.md +31 -16
  142. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +21 -11
  143. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +20 -11
  144. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +20 -11
  145. package/.bkit/core/prompts/bkit-design-generate.md +33 -13
  146. package/.bkit/core/prompts/bkit-design-organise.md +25 -12
  147. package/.bkit/core/prompts/bkit-design-review-1.md +31 -15
  148. package/.bkit/core/prompts/bkit-design-review-2.md +28 -13
  149. package/.bkit/core/prompts/bkit-design-spike.md +30 -13
  150. package/.bkit/core/prompts/bkit-design-update.md +33 -19
  151. package/.bkit/core/prompts/bkit-plan-generate.md +75 -19
  152. package/.bkit/core/prompts/bkit-plan-review-1.md +50 -27
  153. package/.bkit/core/prompts/bkit-plan-review-2.md +59 -28
  154. package/.bkit/core/prompts/bkit-plan-scope-check.md +109 -0
  155. package/.bkit/core/prompts/bkit-plan-update.md +61 -24
  156. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +27 -15
  157. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +31 -16
  158. package/.bkit/core/prompts/bkit-ship-update-docs.md +30 -15
  159. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +24 -14
  160. package/.bkit/core/prompts/bkit-utility-update-decisions.md +32 -14
  161. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +29 -14
  162. package/.bkit/core/prompts/bkit-utility-update-documentation.md +28 -13
  163. package/.bkit/core/prompts/bkit-utility-update-failures.md +31 -14
  164. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +33 -14
  165. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +38 -17
  166. package/.bkit/core/prompts/bkit-utility-update-tracker.md +43 -20
  167. package/.bkit/core/workflows/bkit-auto.md +54 -46
  168. package/.bkit/core/workflows/bkit-build.md +577 -458
  169. package/.bkit/core/workflows/bkit-debug.md +348 -333
  170. package/.bkit/core/workflows/bkit-design.md +201 -237
  171. package/.bkit/core/workflows/bkit-plan.md +210 -321
  172. package/.bkit/core/workflows/bkit-ship.md +328 -278
  173. package/.bkit/shared/.bkit/.env.example +2 -2
  174. package/.bkit/shared/.claude/settings.json +11 -0
  175. package/.bkit/shared/.cursor/mcp.json +1 -1
  176. package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
  177. package/.bkit/shared/.gitattributes +1 -1
  178. package/.bkit/shared/.mcp.json +1 -1
  179. package/.bkit/shared/.opencode/opencode.json +11 -0
  180. package/.bkit/shared/CLAUDE.md +2 -2
  181. package/.bkit/shared/GEMINI.md +2 -2
  182. package/.bkit/shared/docs/architecture.md +1 -1
  183. package/.bkit/shared/docs/data-schema.md +1 -1
  184. package/.bkit/shared/docs/deployments.md +16 -28
  185. package/.bkit/shared/docs/design.md +1 -1
  186. package/.bkit/shared/docs/noise.md +1 -1
  187. package/.bkit/shared/docs/observability.md +2 -2
  188. package/.bkit/shared/docs/security.md +1 -1
  189. package/.bkit/shared/docs/setup.md +1 -1
  190. package/.bkit/shared/docs/technology.md +1 -1
  191. package/.bkit/shared/docs/testing.md +27 -10
  192. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +1 -1
  193. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +26 -5
  194. package/.bkit/templates/.github/workflows/bkit-ci.yml +22 -84
  195. package/.bkit/templates/.github/workflows/bkit-cloud.yml +21 -19
  196. package/.bkit/templates/.husky/pre-push +52 -13
  197. package/.bkit/templates/.prettierignore +7 -0
  198. package/.bkit/templates/scripts/ci/bkit-local-stack-lock.sh +194 -0
  199. package/.bkit/templates/scripts/ci/check-capstone.mjs +2 -4
  200. package/.bkit/templates/scripts/ci/check-capstone.test.mjs +4 -23
  201. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.mjs +104 -23
  202. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.test.mjs +103 -6
  203. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +1 -1
  204. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +3 -1
  205. package/.bkit/templates/scripts/prettier/bkit-insert-ignore.mjs +49 -29
  206. package/CHANGELOG.md +142 -0
  207. package/README.md +58 -34
  208. package/dist/checks/after/ci-yml.js +39 -29
  209. package/dist/checks/after/github.js +99 -72
  210. package/dist/checks/after/index.js +11 -13
  211. package/dist/checks/after/suppression.js +8 -5
  212. package/dist/checks/after/tools.js +40 -83
  213. package/dist/checks/before/env.js +2 -2
  214. package/dist/checks/before/files.js +5 -3
  215. package/dist/checks/before/index.js +15 -2
  216. package/dist/checks/before/repo.js +163 -2
  217. package/dist/checks/tips/catalogue.js +14 -5
  218. package/dist/checks/tips/detect.js +32 -0
  219. package/dist/checks/tips/index.js +7 -5
  220. package/dist/cli.js +19 -47
  221. package/dist/commands/analysis.js +109 -100
  222. package/dist/commands/ci/ci.js +6 -6
  223. package/dist/commands/comply.js +54 -91
  224. package/dist/commands/install/doctor.js +2 -2
  225. package/dist/commands/install/install.js +50 -19
  226. package/dist/commands/install/uninstall.js +59 -28
  227. package/dist/commands/land.js +16 -12
  228. package/dist/commands/lib.js +51 -16
  229. package/dist/commands/registry.js +4 -0
  230. package/dist/commands/setup/setup.js +7 -7
  231. package/dist/commands/stats.js +136 -0
  232. package/dist/commands/tips.js +7 -3
  233. package/dist/commands/workflow/branches.js +656 -56
  234. package/dist/commands/workflow/challenge.js +556 -0
  235. package/dist/commands/workflow/context.js +709 -30
  236. package/dist/commands/workflow/counters.js +208 -75
  237. package/dist/commands/workflow/decisions.js +441 -0
  238. package/dist/commands/workflow/disk.js +2 -2
  239. package/dist/commands/workflow/fids.js +689 -33
  240. package/dist/commands/workflow/issues.js +362 -99
  241. package/dist/commands/workflow/ledgers.js +762 -27
  242. package/dist/commands/workflow/locks.js +24 -2
  243. package/dist/commands/workflow/plan-blocks.js +437 -0
  244. package/dist/commands/workflow/plan-versions.js +22 -0
  245. package/dist/commands/workflow/prs.js +142 -32
  246. package/dist/commands/workflow/repo.js +52 -7
  247. package/dist/commands/workflow/roadmap.js +9 -7
  248. package/dist/commands/workflow/run-facts.js +426 -0
  249. package/dist/commands/workflow/runs.js +144 -43
  250. package/dist/commands/workflow/runtime.js +12 -1
  251. package/dist/commands/workflow/status.js +130 -29
  252. package/dist/commands/workflow/step-table.js +276 -0
  253. package/dist/commands/workflow/steps.js +171 -80
  254. package/dist/commands/workflow/summary.js +275 -0
  255. package/dist/commands/workflow/tests.js +834 -136
  256. package/dist/commands/workflow/tracker.js +983 -0
  257. package/dist/commands/workflow/workflows.js +834 -195
  258. package/dist/commands/workflow/workstreams.js +11 -5
  259. package/dist/commands/workflow/worktrees.js +221 -22
  260. package/dist/install/manifest.js +11 -9
  261. package/dist/install/modules/cloud.js +22 -13
  262. package/dist/install/modules/core.js +326 -7
  263. package/dist/install/modules/opencode.js +2 -2
  264. package/dist/install/version-file.js +6 -2
  265. package/dist/ledgers/migrate.js +81 -0
  266. package/dist/ledgers/status.js +61 -8
  267. package/dist/ledgers/telemetry.js +905 -124
  268. package/dist/render/hosts.js +4 -0
  269. package/dist/render/models.js +12 -0
  270. package/dist/shared/branches.js +3 -1
  271. package/dist/shared/egress.js +7 -0
  272. package/dist/shared/json.js +20 -7
  273. package/dist/shared/settings.js +147 -26
  274. package/dist/shared/text.js +333 -0
  275. package/dist/tools/grammar-density.js +183 -0
  276. package/dist/tools/instructions-sources.js +721 -0
  277. package/dist/tools/instructions.js +1579 -0
  278. package/package.json +114 -23
  279. package/.bkit/core/engine/commands/harvest.ts +0 -459
  280. package/.bkit/core/engine/tools/wording.ts +0 -748
  281. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
  282. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
  283. package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
  284. package/.bkit/core/prompts/bkit-build-summary.md +0 -94
  285. package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
  286. package/.bkit/core/prompts/bkit-design-summary.md +0 -107
  287. package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
  288. package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
  289. package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
  290. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
  291. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
  292. package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
  293. package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
  294. package/.bkit/templates/scripts/ci/lanes/check-tree-cache.mjs +0 -138
  295. package/.bkit/templates/scripts/ci/lanes/check-tree-cache.test.mjs +0 -181
  296. package/dist/commands/harvest.js +0 -353
  297. package/dist/tools/wording.js +0 -680
@@ -1,8 +1,11 @@
1
- // bkit status route|meta|path|row — read and annotate a workflow's `status.jsonl`.
1
+ // bkit status route|resume|meta|path|row — read and annotate a workflow's `status.jsonl`.
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
- import { activeDoneSteps, appendLine, fold, lastDoneStepAllRuns, lastRun, nextStrategy, runOrStepField, statusTimestamp, } from "../../ledgers/status.js";
4
+ import { BKIT_DEBUG_GATES } from "../../install/manifest.js";
5
+ import { readBkitConfig } from "../../shared/settings.js";
6
+ import { activeDoneSteps, allRunsDoneSteps, appendLine, fold, lastDoneStepAllRuns, lastRun, nextStrategy, runNumber, runOrStepField, statusTimestamp, } from "../../ledgers/status.js";
5
7
  import { CommandError, EXIT, git, parseJson, statusLocation, } from "../lib.js";
8
+ import { WORKFLOW_STEPS, isResumable, resumePoint } from "./step-table.js";
6
9
  // ---------------------------------------------------------------------------
7
10
  // Shared with counters / steps
8
11
  // ---------------------------------------------------------------------------
@@ -24,10 +27,10 @@ export const STEP_FLAG = {
24
27
  required: true,
25
28
  help: "step name",
26
29
  };
27
- export const SUB_PLAN_FLAG = {
28
- name: "sub-plan",
30
+ export const GROUP_FLAG = {
31
+ name: "group",
29
32
  type: "string",
30
- help: "only rows for this sub-plan (positive integer)",
33
+ help: "only rows for this plan group (positive integer)",
31
34
  };
32
35
  /** Exit code: status.jsonl missing, unreadable, or not valid NDJSON. */
33
36
  export const EXIT_NO_STATUS = 3;
@@ -127,7 +130,7 @@ const STRATEGIES = ["STANDARD", "PIVOT", "FINAL"];
127
130
  const ROUTE_FIELDS = ["verdict", "failures", "strategy", "debugMode", "pushMode"];
128
131
  /** Exit code: a `--require`d field is missing or holds a value outside its set. */
129
132
  export const EXIT_ROUTE_MISSING = 4;
130
- function route(runs, workflow, step, subPlan) {
133
+ function route(runs, workflow, step, group) {
131
134
  const out = {
132
135
  verdict: null,
133
136
  failures: null,
@@ -136,10 +139,13 @@ function route(runs, workflow, step, subPlan) {
136
139
  debugMode: null,
137
140
  pushMode: null,
138
141
  debugAttempt: 0,
142
+ parentSha: null,
139
143
  };
140
144
  const problems = {};
141
145
  if (step !== undefined) {
142
- const last = activeDoneSteps(runs, workflow, { step, subPlan }).at(-1);
146
+ const last = activeDoneSteps(runs, workflow, { step, group }).at(-1);
147
+ if (typeof last?.parentSha === "string")
148
+ out.parentSha = last.parentSha;
143
149
  if (!last) {
144
150
  problems.verdict = `no DONE ${step} row in the active ${workflow} run`;
145
151
  problems.failures = problems.verdict;
@@ -150,13 +156,16 @@ function route(runs, workflow, step, subPlan) {
150
156
  }
151
157
  else {
152
158
  out.verdict = last.verdict;
153
- const failures = last.failures ?? 0;
154
- if (Number.isInteger(failures) && failures >= 0)
159
+ // An absent count on FAIL is unknown, never 0: a FAIL always has failures.
160
+ const failures = last.failures ?? (last.verdict === "FAIL" ? null : 0);
161
+ if (failures === null)
162
+ out.failures = null;
163
+ else if (Number.isInteger(failures) && failures >= 0)
155
164
  out.failures = failures;
156
165
  else
157
166
  problems.failures = `${step} failures "${String(failures)}" is not a non-negative integer`;
158
167
  }
159
- const prior = lastDoneStepAllRuns(runs, workflow, { step, subPlan })?.strategy;
168
+ const prior = lastDoneStepAllRuns(runs, workflow, { step, group })?.strategy;
160
169
  if (prior === undefined || STRATEGIES.includes(prior)) {
161
170
  out.strategy = prior ?? null;
162
171
  out.nextStrategy = nextStrategy(prior);
@@ -180,6 +189,43 @@ function route(runs, workflow, step, subPlan) {
180
189
  out.debugAttempt = Number.isFinite(attempt) ? attempt : 0;
181
190
  return { out, problems };
182
191
  }
192
+ /**
193
+ * The debug run's start decisions, from the session prompt and the feature's debug runs.
194
+ * `fixMax` is `bkit.workflows.debug.fix.maxAttempts`: once that many fix rounds ran across
195
+ * every debug run, the run starts in SOAK.
196
+ */
197
+ export function debugStart(runs, promptText, fixMax) {
198
+ const attempt = runNumber(runs, "debug");
199
+ const latest = runs.at(-1);
200
+ // A resume: the newest run is debug's and still open. A finished run's modes never
201
+ // carry into the next run; its fix rounds count against `fixMax`.
202
+ const open = latest?.workflow === "debug" && latest.status === "IN_PROGRESS" ? latest : null;
203
+ const soaking = open !== null &&
204
+ (runOrStepField([open], "debug", "debugMode") === "SOAK" ||
205
+ open.steps.some((s) => s.step === "debug-failure-soak" && s.status === "DONE"));
206
+ const fixes = allRunsDoneSteps(runs, "debug", { step: "debug-failure-remediate" }).length;
207
+ const debugMode = promptText.includes("[soak]") || soaking || fixes >= fixMax ? "SOAK" : "NORMAL";
208
+ return {
209
+ debugAttempt: attempt,
210
+ debugMode,
211
+ repro: promptText.includes("[repro]"),
212
+ gates: promptText.includes("[live=off]")
213
+ ? BKIT_DEBUG_GATES.filter((g) => !g.endsWith("-live"))
214
+ : [...BKIT_DEBUG_GATES],
215
+ };
216
+ }
217
+ /** `--file`, else the debug status.jsonl `--fid` and `--month` name. */
218
+ function routeFile(ctx) {
219
+ if (ctx.flags.file !== undefined)
220
+ return statusFile(ctx);
221
+ const fid = str(ctx.flags.fid);
222
+ const month = str(ctx.flags.month);
223
+ if (fid === undefined || month === undefined || ctx.flags.promptFile === undefined)
224
+ throw new CommandError(EXIT.USAGE, "give --file, or --prompt-file with --fid and --month");
225
+ if (!/^[0-9]{6}$/.test(month))
226
+ throw new CommandError(EXIT.USAGE, "--month must be YYYYMM");
227
+ return statusLocation({ cwd: ctx.cwd, workflow: "debug", fid, month }).path;
228
+ }
183
229
  // ---------------------------------------------------------------------------
184
230
  // meta
185
231
  // ---------------------------------------------------------------------------
@@ -187,7 +233,6 @@ const META_FIELDS = {
187
233
  "debug-mode": { key: "debugMode", check: (v) => oneOf(v, DEBUG_MODES, "--debug-mode") },
188
234
  "push-mode": { key: "pushMode", check: (v) => oneOf(v, PUSH_MODES, "--push-mode") },
189
235
  "debug-attempt": { key: "debugAttempt", check: (v) => positiveInt(v, "debug-attempt") },
190
- "plan-source": { key: "planSource", check: (v) => oneOf(v, PLAN_SOURCES, "--plan-source") },
191
236
  };
192
237
  /** Row types the fold reads; each has its own verb (workflows start|fail|close, steps done, status meta). */
193
238
  const FOLDED_TYPES = new Set([
@@ -197,13 +242,10 @@ const FOLDED_TYPES = new Set([
197
242
  "workflow-done",
198
243
  "workflow-failed",
199
244
  ]);
200
- /** Markers that record the row's own time or a fact, not a value. */
245
+ /** Markers that record a fact, not a value. */
201
246
  const META_MARKS = {
202
- "soak-entry": (at) => ({ soakEntryAt: at }),
203
247
  "opened-pr": () => ({ openedPr: true }),
204
248
  };
205
- /** `brief` = the run had no plan file and works from its input file. */
206
- const PLAN_SOURCES = ["brief", "plan"];
207
249
  const camelFlag = (kebab) => kebab.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
208
250
  function oneOf(v, allowed, flag) {
209
251
  if (!allowed.includes(v))
@@ -244,16 +286,16 @@ export const statusCommand = {
244
286
  },
245
287
  },
246
288
  route: {
247
- summary: "Routing state: last verdict / failures / strategy of a step, debug and push mode.",
289
+ summary: "Routing state: last verdict / failures / strategy of a step, debug and push mode; with --prompt-file, debug's start decisions.",
248
290
  flags: [
249
- FILE_FLAG,
291
+ { ...FILE_FLAG, required: false, help: `${FILE_FLAG.help}; or --fid and --month` },
250
292
  WORKFLOW_FLAG,
251
293
  {
252
294
  ...STEP_FLAG,
253
295
  required: false,
254
296
  help: "step whose last DONE row gives verdict, failures, strategy",
255
297
  },
256
- SUB_PLAN_FLAG,
298
+ GROUP_FLAG,
257
299
  {
258
300
  name: "require",
259
301
  type: "string",
@@ -266,15 +308,25 @@ export const statusCommand = {
266
308
  repeatable: true,
267
309
  help: "field=value — fail (exit 4) unless the field holds this value, e.g. debugMode=NORMAL",
268
310
  },
311
+ {
312
+ name: "prompt-file",
313
+ type: "string",
314
+ help: "debug only: the session prompt; decides this run's attempt, mode, repro and gates (a missing status.jsonl is a fresh run)",
315
+ },
316
+ { name: "fid", type: "string", help: "with --prompt-file, in place of --file: feature id" },
317
+ { name: "month", type: "string", help: "with --prompt-file, in place of --file: YYYYMM" },
269
318
  ],
270
319
  output: {
271
320
  verdict: "PASS|CONCERNS|FAIL of the step's last DONE row in the active run, or null",
272
- failures: "its failures (absent with a verdict = 0), or null",
321
+ failures: "its failures (absent on PASS|CONCERNS = 0, absent on FAIL = null: count unknown), or null",
273
322
  strategy: "the step's last strategy across ALL runs, or null",
274
323
  nextStrategy: "next rung: STANDARD, PIVOT, FINAL (null without --step)",
275
- debugMode: "NORMAL|SOAK of the active run, or null",
324
+ debugMode: "NORMAL|SOAK of the active run, or null; with --prompt-file, the mode this invocation runs in (SOAK on [soak] in the prompt, an open run already in SOAK, or bkit.workflows.debug.fix.maxAttempts fix rounds already run across every debug run; else NORMAL)",
276
325
  pushMode: "PR|LOCAL of the active run, or null",
277
- debugAttempt: "debugAttempt of the active run (0 when unset)",
326
+ debugAttempt: "debugAttempt of the active run (0 when unset); with --prompt-file, this invocation's run number (a resume keeps its number)",
327
+ repro: "with --prompt-file: [repro] in the prompt",
328
+ gates: "with --prompt-file: the gates to try, deepest first; [live=off] in the prompt drops the live gate",
329
+ parentSha: "HEAD when the step's last DONE row in the active run was written — a build-group-start row's is the group's start commit, the base for `context diff` — or null",
278
330
  },
279
331
  exitCodes: {
280
332
  [EXIT_NO_STATUS]: "status.jsonl missing, unreadable, or not valid NDJSON",
@@ -302,8 +354,25 @@ export const statusCommand = {
302
354
  throw new CommandError(EXIT.USAGE, `--require ${r} needs --step`);
303
355
  }
304
356
  }
305
- const runs = readRuns(statusFile(ctx));
306
- const { out, problems } = route(runs, String(ctx.flags.workflow), step, positiveInt(ctx.flags.subPlan, "sub-plan"));
357
+ const promptFile = str(ctx.flags.promptFile);
358
+ if (promptFile !== undefined && ctx.flags.workflow !== "debug")
359
+ throw new CommandError(EXIT.USAGE, "--prompt-file is for --workflow=debug");
360
+ const file = routeFile(ctx);
361
+ let promptText = "";
362
+ if (promptFile !== undefined) {
363
+ const abs = path.resolve(ctx.cwd, promptFile);
364
+ if (!fs.existsSync(abs))
365
+ throw new CommandError(EXIT.USAGE, `--prompt-file ${abs} does not exist`);
366
+ promptText = fs.readFileSync(abs, "utf-8");
367
+ }
368
+ const runs = promptFile !== undefined && !fs.existsSync(file) ? [] : readRuns(file);
369
+ const { out, problems } = route(runs, String(ctx.flags.workflow), step, positiveInt(ctx.flags.group, "group"));
370
+ if (promptFile !== undefined) {
371
+ const root = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
372
+ const fixMax = readBkitConfig(root).asks["debug.fix"].max;
373
+ Object.assign(out, debugStart(runs, promptText, fixMax));
374
+ delete problems.debugMode;
375
+ }
307
376
  ctx.emit(out);
308
377
  const failed = required.filter((r) => problems[r] !== undefined);
309
378
  for (const r of failed)
@@ -315,6 +384,36 @@ export const statusCommand = {
315
384
  return failed.length === 0 && differ.length === 0 ? EXIT.OK : EXIT_ROUTE_MISSING;
316
385
  },
317
386
  },
387
+ resume: {
388
+ summary: "The step a stopped run continues at: after its last DONE step, setup steps and retired rows aside.",
389
+ flags: [
390
+ { ...FILE_FLAG, help: "path to status.jsonl; a missing file is a run with no rows" },
391
+ { ...WORKFLOW_FLAG, help: `workflow name: ${Object.keys(WORKFLOW_STEPS).join(", ")}` },
392
+ ],
393
+ output: {
394
+ step: "the step's row name, or null for a step that writes no row",
395
+ number: "the step number to continue at (1 when no run is active)",
396
+ title: "the step heading's title",
397
+ after: "the DONE row that placed it, or null",
398
+ group: "that row's plan group, or null",
399
+ active: "whether the latest run is this workflow, still IN_PROGRESS",
400
+ challengeRound: "build: the round Step 10's challenge runs as (1 up to bkit.workflows.build.challenge.maxAttempts), from the build-challenge rows' round field; null for other workflows",
401
+ challengeDone: "build: true once the last allowed challenge round has merged, so Step 10 goes on to Step 11; null for other workflows",
402
+ },
403
+ exitCodes: { [EXIT_NO_STATUS]: "status.jsonl unreadable or not valid NDJSON" },
404
+ run: (ctx) => {
405
+ const workflow = String(ctx.flags.workflow);
406
+ if (!isResumable(workflow))
407
+ throw new CommandError(EXIT.USAGE, `--workflow must be ${Object.keys(WORKFLOW_STEPS).join("|")}, got "${workflow}"`);
408
+ const file = statusFile(ctx);
409
+ const root = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
410
+ const challengeMax = readBkitConfig(root).asks["build.challenge"].max;
411
+ ctx.emit({
412
+ ...resumePoint(fs.existsSync(file) ? readRuns(file) : [], workflow, challengeMax),
413
+ });
414
+ return EXIT.OK;
415
+ },
416
+ },
318
417
  meta: {
319
418
  summary: "Append a workflow-meta row (run-level routing state).",
320
419
  flags: [
@@ -322,12 +421,10 @@ export const statusCommand = {
322
421
  WORKFLOW_FLAG,
323
422
  { name: "debug-mode", type: "string", help: "NORMAL|SOAK" },
324
423
  { name: "push-mode", type: "string", help: "PR|LOCAL" },
325
- { name: "debug-attempt", type: "string", help: "positive integer" },
326
- { name: "plan-source", type: "string", help: "brief|plan" },
327
424
  {
328
- name: "soak-entry",
329
- type: "boolean",
330
- help: "record soakEntryAt (the soak budget counts from here)",
425
+ name: "debug-attempt",
426
+ type: "string",
427
+ help: "positive integer, or run (the active run's number)",
331
428
  },
332
429
  { name: "opened-pr", type: "boolean", help: "record openedPr: this run opened the PR" },
333
430
  ],
@@ -339,8 +436,9 @@ export const statusCommand = {
339
436
  const fields = {};
340
437
  for (const { key, check } of Object.values(META_FIELDS)) {
341
438
  const v = str(ctx.flags[key]);
439
+ // `--debug-attempt=run`: the active run's number, read once the log is known to exist.
342
440
  if (v !== undefined)
343
- fields[key] = check(v);
441
+ fields[key] = key === "debugAttempt" && v === "run" ? v : check(v);
344
442
  }
345
443
  for (const [flag, mark] of Object.entries(META_MARKS)) {
346
444
  if (ctx.flags[camelFlag(flag)] === true)
@@ -353,6 +451,9 @@ export const statusCommand = {
353
451
  }
354
452
  if (!fs.existsSync(file))
355
453
  throw new CommandError(EXIT_NO_STATUS, `${file} does not exist`);
454
+ if (fields.debugAttempt === "run") {
455
+ fields.debugAttempt = runNumber(readRuns(file), String(ctx.flags.workflow));
456
+ }
356
457
  const row = {
357
458
  type: "workflow-meta",
358
459
  workflow: String(ctx.flags.workflow),
@@ -0,0 +1,276 @@
1
+ // The ordered steps of each workflow, and where a stopped run resumes.
2
+ //
3
+ // `bkit status resume` folds the active run and names the step to continue at.
4
+ // The rule: take the run's last DONE row for a step this table knows (rows for
5
+ // steps a workflow no longer has are ignored, except the retired steps mapped
6
+ // below, and Decision Pause rows that record their route), skip the setup steps
7
+ // (1-2 run again on every resume), and resume at the
8
+ // step after it — or at its `resumeOnVerdict` entry for the row's verdict, or its
9
+ // `resumeAt`, for a step whose next step depends on a verdict or that loops back. `workflow-shape.test.ts` holds this table to the
10
+ // workflows' `## Step N — Title` headings and `--step=` calls.
11
+ import { CONFIG_DEFAULTS } from "../../shared/settings.js";
12
+ export const WORKFLOW_STEPS = {
13
+ plan: [
14
+ { step: "plan-start-workflow", number: 1, title: "Start Workflow", setup: true },
15
+ { step: "plan-worktree-setup", number: 2, title: "Worktree Setup", setup: true },
16
+ { step: "plan-generate", number: 3, title: "Generate Plan" },
17
+ { step: "plan-fetch-context", number: 4, title: "Fetch Context" },
18
+ { step: "plan-review", number: 5, title: "Review Plan" },
19
+ { step: "plan-apply-review", number: 6, title: "Apply Review" },
20
+ { step: "plan-summary", number: 7, title: "Summary" },
21
+ { step: "plan-close-workflow", number: 8, title: "Close Workflow" },
22
+ ],
23
+ design: [
24
+ { step: "design-start-workflow", number: 1, title: "Start Workflow", setup: true },
25
+ { step: "design-worktree-setup", number: 2, title: "Worktree Setup", setup: true },
26
+ { step: "design-grill", number: 3, title: "Grill" },
27
+ { step: "design-brainstorm-ideate", number: 4, title: "Brainstorm & Ideate" },
28
+ { step: "design-generate", number: 5, title: "Generate Design" },
29
+ { step: "design-review", number: 6, title: "Design Review" },
30
+ { step: "design-spike", number: 7, title: "Spike" },
31
+ { step: "design-apply-review", number: 8, title: "Apply Review" },
32
+ { step: "design-organise", number: 9, title: "Design Organise" },
33
+ { step: "design-summary", number: 10, title: "Summary" },
34
+ { step: "design-workstream-suggest", number: 11, title: "Suggest Workstreams" },
35
+ { step: "design-close-workflow", number: 12, title: "Close Workflow" },
36
+ ],
37
+ build: [
38
+ { step: "build-start-workflow", number: 1, title: "Start Workflow", setup: true },
39
+ { step: "build-worktree-setup", number: 2, title: "Worktree Setup", setup: true },
40
+ // A converted plan is checked again: Step 3 runs its plan check once more.
41
+ { step: "build-plan-convert", number: 3, title: "Branch Sync", resumeAt: "build-branch-sync" },
42
+ { step: "build-branch-sync", number: 3, title: "Branch Sync" },
43
+ { step: "build-plan-current", number: 4, title: "Plan Current" },
44
+ { step: "build-install-skills", number: 5, title: "Install Skills" },
45
+ // A group's start commit is recorded before its execute runs: Step 6 again.
46
+ {
47
+ step: "build-group-start",
48
+ number: 6,
49
+ title: "Plan Execute",
50
+ resumeAt: "build-plan-execute",
51
+ },
52
+ // A handover stops a group part-done: Step 6 runs again with a fresh brief.
53
+ {
54
+ step: "build-plan-execute",
55
+ number: 6,
56
+ title: "Plan Execute",
57
+ resumeOnVerdict: { HANDOVER: "build-plan-execute" },
58
+ },
59
+ // Verify, its group gate and the gaps fix route on the verify verdict: Step 7 again.
60
+ { step: "build-plan-verify", number: 7, title: "Plan Verify", resumeAt: "build-plan-verify" },
61
+ { step: "build-group-gate", number: 7, title: "Plan Verify", resumeAt: "build-plan-verify" },
62
+ {
63
+ step: "build-plan-gaps-remediate",
64
+ number: 8,
65
+ title: "Plan Gaps Remediate",
66
+ resumeAt: "build-plan-verify",
67
+ },
68
+ { step: "build-plan-verify-holistic", number: 9, title: "Plan Verify Holistic" },
69
+ // The reports are written: Step 10 continues at `bkit challenge merge`.
70
+ { step: "build-challenge", number: 10, title: "Build Challenge", resumeAt: "build-challenge" },
71
+ // Run Tests routes on its own verdict, and a fix loops back to it.
72
+ { step: "build-run-tests", number: 11, title: "Run Tests", resumeAt: "build-run-tests" },
73
+ { step: "build-failure-diagnose", number: 12, title: "Failure Diagnose" },
74
+ {
75
+ step: "build-failure-remediate",
76
+ number: 13,
77
+ title: "Failure Remediate",
78
+ resumeAt: "build-run-tests",
79
+ },
80
+ { step: "build-summary", number: 14, title: "Summary" },
81
+ { step: "build-create-pr", number: 15, title: "Close Workflow & Create PR" },
82
+ { step: "build-close-workflow", number: 15, title: "Close Workflow & Create PR" },
83
+ ],
84
+ debug: [
85
+ { step: "debug-start-workflow", number: 1, title: "Start Workflow", setup: true },
86
+ { step: "debug-worktree-setup", number: 2, title: "Worktree Setup", setup: true },
87
+ // Run Tests routes on its own verdict, and every fix loops back to it.
88
+ { step: "debug-run-tests", number: 3, title: "Run Tests", resumeAt: "debug-run-tests" },
89
+ { step: "context-fetch", number: 4, title: "Fetch Context" },
90
+ { step: "debug-failure-reproduce", number: 5, title: "Failure Reproduce" },
91
+ { step: "debug-failure-diagnose", number: 6, title: "Failure Diagnose" },
92
+ {
93
+ step: "debug-failure-remediate",
94
+ number: 7,
95
+ title: "Failure Remediate",
96
+ resumeAt: "debug-run-tests",
97
+ },
98
+ {
99
+ step: "debug-failure-soak",
100
+ number: 8,
101
+ title: "Failure Remediate Soak",
102
+ resumeAt: "debug-run-tests",
103
+ },
104
+ { step: "debug-push-remediation", number: 9, title: "Push Remediation" },
105
+ { step: "debug-summary", number: 10, title: "Summary" },
106
+ { step: "debug-create-pr", number: 11, title: "Close Workflow" },
107
+ { step: "debug-close-workflow", number: 11, title: "Close Workflow" },
108
+ ],
109
+ ship: [
110
+ { step: "ship-start-workflow", number: 1, title: "Start Workflow", setup: true },
111
+ {
112
+ step: "ship-worktree-setup",
113
+ number: 2,
114
+ title: "Verify PR (Worktree Setup + Regression Guard)",
115
+ setup: true,
116
+ },
117
+ {
118
+ step: "ship-regression-guard",
119
+ number: 2,
120
+ title: "Verify PR (Worktree Setup + Regression Guard)",
121
+ setup: true,
122
+ },
123
+ { number: 3, title: "Base Check" },
124
+ { step: "ship-conflict-resolve", number: 4, title: "Integrate (Path B only)" },
125
+ { step: "ship-deferred-sweep", number: 5, title: "Deferred Sweep" },
126
+ // Docs and summary are one step: the summary half still has to run.
127
+ {
128
+ step: "ship-update-docs",
129
+ number: 6,
130
+ title: "Update Docs & Summary",
131
+ resumeAt: "ship-summary",
132
+ },
133
+ { step: "ship-summary", number: 6, title: "Update Docs & Summary" },
134
+ { step: "ship-prune-skills", number: 7, title: "Prune Skills" },
135
+ { step: "ship-bookkeeping-push", number: 8, title: "Commit + Push Bookkeeping" },
136
+ { number: 9, title: "Re-validate" },
137
+ // The merge gate reads the PR state again: a merged PR goes on to Step 13.
138
+ {
139
+ step: "ship-merge-pr",
140
+ number: 10,
141
+ title: "Merge Gate + Merge PR",
142
+ resumeAt: "ship-merge-pr",
143
+ },
144
+ { step: "ship-failure-diagnose", number: 11, title: "Failure Diagnose" },
145
+ // A PASS fix is committed and pushed at Step 12 sub-step 4 (a re-run commits nothing
146
+ // new), then re-validated at Step 9; any other verdict re-reads the PR at Step 10.
147
+ {
148
+ step: "ship-failure-remediate",
149
+ number: 12,
150
+ title: "Failure Remediate",
151
+ resumeAt: "ship-merge-pr",
152
+ resumeOnVerdict: { PASS: "ship-failure-remediate" },
153
+ },
154
+ { step: "ship-switch-to-dev", number: 13, title: "Update Local Dev" },
155
+ { step: "ship-close-workflow", number: 14, title: "Close Workflow" },
156
+ ],
157
+ };
158
+ /**
159
+ * Rows of steps a workflow no longer has that still place a resume point: the
160
+ * old build challenge steps ran after the reports, so a run stopped in them
161
+ * resumes at Run Tests.
162
+ */
163
+ export const RETIRED_STEPS = {
164
+ build: {
165
+ "build-challenge-reconcile": "build-run-tests",
166
+ "build-challenge-remediate": "build-run-tests",
167
+ "build-challenge-tests": "build-run-tests",
168
+ },
169
+ };
170
+ /**
171
+ * Decision Pause rows (`build-decision`, no step number) that place a resume point: the
172
+ * row's `route` names the step the decision sent the run to, either directly or keyed on
173
+ * the step of the last non-decision row before it (the loop the pause came from). A row
174
+ * without a known `route`, or a keyed route with no matching prior row, places none.
175
+ */
176
+ export const DECISION_ROUTES = {
177
+ build: {
178
+ step: "build-decision",
179
+ routes: {
180
+ fix: "build-plan-execute",
181
+ verify: "build-plan-verify",
182
+ tests: "build-run-tests",
183
+ // Try again: a verify loop goes on to its gaps fix (Step 8), a tests loop to Step 12.
184
+ retry: {
185
+ "build-plan-verify": "build-plan-gaps-remediate",
186
+ "build-group-gate": "build-plan-gaps-remediate",
187
+ "build-run-tests": "build-failure-diagnose",
188
+ },
189
+ },
190
+ },
191
+ };
192
+ export const isResumable = (w) => w in WORKFLOW_STEPS;
193
+ const CHALLENGE_ROUTES = new Set(["build-plan-execute", "build-decision", "build-run-tests"]);
194
+ const roundOf = (s) => {
195
+ const round = Number(s.round);
196
+ return Number.isInteger(round) && round >= 1 ? round : 1;
197
+ };
198
+ /** The run's DONE `build-challenge` rows and the route rows after them, in order. */
199
+ const challengeRows = (steps) => steps.filter((s) => s.status === "DONE" && (s.step === "build-challenge" || CHALLENGE_ROUTES.has(s.step)));
200
+ /** Whether a challenge row at round `max` or later has a route row after it: no round is left. */
201
+ function challengeDone(steps, max) {
202
+ const rows = challengeRows(steps);
203
+ return rows.some((s, i) => s.step === "build-challenge" && roundOf(s) >= max && rows[i + 1] !== undefined);
204
+ }
205
+ /**
206
+ * The build challenge's round, read from the run's `build-challenge` rows (each carries the
207
+ * `round` it ran as; a row without one counts as round 1) and the step row after each: the
208
+ * next of `build-plan-execute` (route fix), `build-decision` (route pause) or
209
+ * `build-run-tests` (route none). A challenge row with no such row after it has not merged
210
+ * yet, so the run keeps that row's round. Otherwise one past the highest round whose merge
211
+ * wrote tasks (route fix or pause), or that ran past round 1; at most `max`
212
+ * (`bkit.workflows.build.challenge.maxAttempts`).
213
+ */
214
+ function challengeRound(steps, max) {
215
+ const rows = challengeRows(steps);
216
+ const last = rows.at(-1);
217
+ if (last?.step === "build-challenge")
218
+ return roundOf(last);
219
+ const done = rows
220
+ .filter((s, i) => s.step === "build-challenge" && (roundOf(s) > 1 || rows[i + 1]?.step !== "build-run-tests"))
221
+ .map(roundOf);
222
+ return done.length === 0 ? 1 : Math.min(Math.max(...done) + 1, max);
223
+ }
224
+ /** Where `workflow`'s active run resumes; Step 1 when no run is active or no known step is DONE. */
225
+ export function resumePoint(runs, workflow, challengeMax = CONFIG_DEFAULTS.asks["build.challenge"].max) {
226
+ const table = WORKFLOW_STEPS[workflow];
227
+ const retired = RETIRED_STEPS[workflow] ?? {};
228
+ const decision = DECISION_ROUTES[workflow];
229
+ const byStep = new Map(table.filter((s) => s.step !== undefined).map((s) => [s.step, s]));
230
+ const latest = runs.at(-1);
231
+ const active = latest?.workflow === workflow && latest.status === "IN_PROGRESS";
232
+ const steps = active ? latest.steps : [];
233
+ const at = (entry, after, group) => ({
234
+ step: entry.step ?? null,
235
+ number: entry.number,
236
+ title: entry.title,
237
+ after,
238
+ group,
239
+ active,
240
+ challengeRound: workflow === "build" ? challengeRound(steps, challengeMax) : null,
241
+ challengeDone: workflow === "build" ? challengeDone(steps, challengeMax) : null,
242
+ });
243
+ const routeOf = (s) => {
244
+ if (decision === undefined || s.step !== decision.step)
245
+ return undefined;
246
+ const route = decision.routes[String(s.route)];
247
+ if (typeof route !== "object")
248
+ return route;
249
+ const prior = steps
250
+ .slice(0, steps.lastIndexOf(s))
251
+ .filter((r) => r.status === "DONE" && r.step !== decision.step && byStep.has(r.step))
252
+ .at(-1);
253
+ return prior === undefined ? undefined : route[prior.step];
254
+ };
255
+ const done = steps.filter((s) => s.status === "DONE" && (byStep.has(s.step) || s.step in retired || routeOf(s) !== undefined));
256
+ const last = done.filter((s) => byStep.get(s.step)?.setup !== true).at(-1) ?? done.at(-1);
257
+ if (last === undefined)
258
+ return at(table[0], null, null);
259
+ const routed = routeOf(last);
260
+ if (routed !== undefined) {
261
+ // A decision row carries no group: the group is the one the paused step worked on.
262
+ const before = done.slice(0, done.lastIndexOf(last)).reverse();
263
+ const prior = before.find((s) => (s.group ?? s.subPlan) !== undefined);
264
+ return at(byStep.get(routed), last.step, prior?.group ?? prior?.subPlan ?? null);
265
+ }
266
+ const group = last.group ?? last.subPlan ?? null;
267
+ const verdict = String(last.verdict);
268
+ const target = retired[last.step] ??
269
+ byStep.get(last.step).resumeOnVerdict?.[verdict] ??
270
+ byStep.get(last.step).resumeAt;
271
+ if (target !== undefined)
272
+ return at(byStep.get(target), last.step, group);
273
+ const own = byStep.get(last.step);
274
+ const next = table.find((s) => s.number > own.number);
275
+ return at(next ?? own, last.step, group);
276
+ }