@cbartens/bkit 5.5.1 → 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 (288) 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 +35 -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 +19 -18
  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 +91 -167
  13. package/.bkit/core/.bkit/providers.md +29 -32
  14. package/.bkit/core/.bkit/templates.md +12 -11
  15. package/.bkit/core/.bkit/trackers.md +51 -28
  16. package/.bkit/core/.bkit/workflows.md +394 -355
  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 -29
  55. package/.bkit/core/engine/checks/after/github.ts +95 -17
  56. package/.bkit/core/engine/checks/after/index.ts +10 -7
  57. package/.bkit/core/engine/checks/after/suppression.ts +8 -5
  58. package/.bkit/core/engine/checks/after/tools.ts +46 -91
  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 +6 -6
  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 +407 -64
  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 +58 -8
  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 +185 -8
  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 +250 -3
  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 +157 -20
  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 +29 -15
  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 +32 -14
  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 +72 -18
  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 +29 -14
  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 +27 -12
  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 +41 -18
  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 +11 -11
  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 +16 -7
  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 +1 -1
  195. package/.bkit/templates/.github/workflows/bkit-cloud.yml +21 -19
  196. package/.bkit/templates/.husky/pre-push +4 -4
  197. package/.bkit/templates/.prettierignore +7 -0
  198. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +1 -1
  199. package/CHANGELOG.md +112 -0
  200. package/README.md +50 -35
  201. package/dist/checks/after/ci-yml.js +39 -28
  202. package/dist/checks/after/github.js +91 -17
  203. package/dist/checks/after/index.js +11 -8
  204. package/dist/checks/after/suppression.js +8 -5
  205. package/dist/checks/after/tools.js +39 -82
  206. package/dist/checks/before/env.js +2 -2
  207. package/dist/checks/before/files.js +5 -3
  208. package/dist/checks/before/index.js +15 -2
  209. package/dist/checks/before/repo.js +163 -2
  210. package/dist/checks/tips/catalogue.js +14 -5
  211. package/dist/checks/tips/detect.js +32 -0
  212. package/dist/checks/tips/index.js +4 -4
  213. package/dist/cli.js +19 -47
  214. package/dist/commands/analysis.js +109 -100
  215. package/dist/commands/ci/ci.js +6 -6
  216. package/dist/commands/comply.js +54 -91
  217. package/dist/commands/install/doctor.js +2 -2
  218. package/dist/commands/install/install.js +50 -19
  219. package/dist/commands/install/uninstall.js +59 -28
  220. package/dist/commands/land.js +16 -12
  221. package/dist/commands/lib.js +51 -16
  222. package/dist/commands/registry.js +4 -0
  223. package/dist/commands/setup/setup.js +7 -7
  224. package/dist/commands/stats.js +136 -0
  225. package/dist/commands/tips.js +7 -3
  226. package/dist/commands/workflow/branches.js +656 -56
  227. package/dist/commands/workflow/challenge.js +556 -0
  228. package/dist/commands/workflow/context.js +709 -30
  229. package/dist/commands/workflow/counters.js +208 -75
  230. package/dist/commands/workflow/decisions.js +441 -0
  231. package/dist/commands/workflow/disk.js +2 -2
  232. package/dist/commands/workflow/fids.js +689 -33
  233. package/dist/commands/workflow/issues.js +343 -59
  234. package/dist/commands/workflow/ledgers.js +762 -27
  235. package/dist/commands/workflow/locks.js +24 -2
  236. package/dist/commands/workflow/plan-blocks.js +437 -0
  237. package/dist/commands/workflow/plan-versions.js +22 -0
  238. package/dist/commands/workflow/prs.js +142 -32
  239. package/dist/commands/workflow/repo.js +52 -8
  240. package/dist/commands/workflow/roadmap.js +9 -7
  241. package/dist/commands/workflow/run-facts.js +426 -0
  242. package/dist/commands/workflow/runs.js +144 -43
  243. package/dist/commands/workflow/runtime.js +12 -1
  244. package/dist/commands/workflow/status.js +130 -29
  245. package/dist/commands/workflow/step-table.js +276 -0
  246. package/dist/commands/workflow/steps.js +171 -80
  247. package/dist/commands/workflow/summary.js +275 -0
  248. package/dist/commands/workflow/tests.js +834 -136
  249. package/dist/commands/workflow/tracker.js +983 -0
  250. package/dist/commands/workflow/workflows.js +834 -195
  251. package/dist/commands/workflow/workstreams.js +11 -5
  252. package/dist/commands/workflow/worktrees.js +147 -9
  253. package/dist/install/manifest.js +11 -9
  254. package/dist/install/modules/cloud.js +22 -13
  255. package/dist/install/modules/core.js +247 -3
  256. package/dist/install/modules/opencode.js +2 -2
  257. package/dist/install/version-file.js +6 -2
  258. package/dist/ledgers/migrate.js +81 -0
  259. package/dist/ledgers/status.js +61 -8
  260. package/dist/ledgers/telemetry.js +905 -124
  261. package/dist/render/hosts.js +4 -0
  262. package/dist/render/models.js +12 -0
  263. package/dist/shared/branches.js +3 -1
  264. package/dist/shared/egress.js +7 -0
  265. package/dist/shared/json.js +20 -7
  266. package/dist/shared/settings.js +125 -17
  267. package/dist/shared/text.js +333 -0
  268. package/dist/tools/grammar-density.js +183 -0
  269. package/dist/tools/instructions-sources.js +721 -0
  270. package/dist/tools/instructions.js +1579 -0
  271. package/package.json +113 -24
  272. package/.bkit/core/engine/commands/harvest.ts +0 -459
  273. package/.bkit/core/engine/tools/wording.ts +0 -748
  274. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
  275. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
  276. package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
  277. package/.bkit/core/prompts/bkit-build-summary.md +0 -94
  278. package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
  279. package/.bkit/core/prompts/bkit-design-summary.md +0 -107
  280. package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
  281. package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
  282. package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
  283. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
  284. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
  285. package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
  286. package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
  287. package/dist/commands/harvest.js +0 -353
  288. package/dist/tools/wording.js +0 -680
@@ -8,27 +8,31 @@
8
8
  // be 0 there, so 0 is refused (it means the row was dropped).
9
9
  // count routing on a DIFFERENT step, prior or not yet run: the bare count, and
10
10
  // 0 is a legal answer (that step simply has not run).
11
- import { activeDoneSteps, runNumber } from "../../ledgers/status.js";
12
- import { CommandError, EXIT } from "../lib.js";
13
- import { EXIT_NO_STATUS, FILE_FLAG, STEP_FLAG, SUB_PLAN_FLAG, WORKFLOW_FLAG, positiveInt, readRuns, readStatusRows, statusFile, str, } from "./status.js";
14
- /** Every MAX_* threshold the workflows route on. */
15
- export const THRESHOLDS = {
16
- // build
17
- MAX_VERIFY_ATTEMPT: 3,
18
- MAX_TEST_ATTEMPT: 3,
19
- MAX_CHALLENGE_REMEDIATE_ATTEMPT: 1,
20
- // debug — mode-matched pairs
21
- MAX_DEBUG_ATTEMPT: 3,
22
- MAX_NORMAL_ATTEMPT: 3,
23
- MAX_SOAK_ATTEMPT: 3,
24
- // ship
25
- MAX_MERGE_ATTEMPT: 3,
26
- /** gate-refusal (10/11/14) poll-only re-entries into the sweep step */
27
- MAX_REVALIDATE_ATTEMPT: 3,
28
- // bkit-cloud.yml
29
- /** distinct failed dev CI SHAs per FID that may each dispatch a debug run */
30
- MAX_DEV_DISPATCH_ATTEMPTS: 3,
31
- };
11
+ import * as path from "node:path";
12
+ import { activeDoneSteps, allRunsDoneSteps, lastDoneStepAllRuns, nextStrategy, runNumber, } from "../../ledgers/status.js";
13
+ import { ASK_POINTS, readBkitConfig, } from "../../shared/settings.js";
14
+ import { headlessRun } from "./runtime.js";
15
+ import { CommandError, EXIT, git, runGit, } from "../lib.js";
16
+ import { EXIT_NO_STATUS, FILE_FLAG, GROUP_FLAG, STEP_FLAG, WORKFLOW_FLAG, positiveInt, readRuns, readStatusRows, statusFile, str, } from "./status.js";
17
+ /** An ask point by name (`build.verify`); an unknown name is a usage error. */
18
+ export function askPoint(name) {
19
+ if (!ASK_POINTS.includes(name))
20
+ throw new CommandError(EXIT.USAGE, `unknown point ${name}; known: ${ASK_POINTS.join(", ")}`);
21
+ return name;
22
+ }
23
+ /** The checkout `cwd` sits in. */
24
+ const checkoutRoot = (cwd) => git(cwd, ["rev-parse", "--show-toplevel"]) ?? cwd;
25
+ /** `bkit.workflows.<point>` for the checkout `cwd` sits in. */
26
+ export function askSetting(cwd, point) {
27
+ return readBkitConfig(checkoutRoot(cwd)).asks[point];
28
+ }
29
+ /** Paths a fix round's code change is judged on: everything but plan logs and ledgers. */
30
+ const SOURCE_PATHS = [
31
+ ".",
32
+ ":(exclude)docs/plans",
33
+ ":(exclude)docs/*.jsonl",
34
+ ":(exclude).bkit/*.jsonl",
35
+ ];
32
36
  /** Exit code: `--position=current` found no row — the step's own row is missing. */
33
37
  export const EXIT_NO_OWN_ROW = 4;
34
38
  const nonNegativeInt = (v, flag) => {
@@ -40,7 +44,8 @@ const nonNegativeInt = (v, flag) => {
40
44
  };
41
45
  /**
42
46
  * `--of=<step>:<position>` over `--file` / `--workflow`: the counter at that position.
43
- * `--of=<step>,<step>...:count` sums the DONE rows of every listed step.
47
+ * `--of=<step>,<step>...:count` sums the DONE rows of every listed step. `--all-runs`
48
+ * counts every run of the workflow in the file, not only the active one.
44
49
  */
45
50
  function derivedOf(ctx) {
46
51
  const [list, position] = String(ctx.flags.of).split(":");
@@ -52,24 +57,110 @@ function derivedOf(ctx) {
52
57
  if (ctx.flags.file === undefined || ctx.flags.workflow === undefined)
53
58
  throw new CommandError(EXIT.USAGE, "--of needs --file and --workflow");
54
59
  const runs = readRuns(statusFile(ctx));
55
- const subPlan = positiveInt(ctx.flags.subPlan, "sub-plan");
56
- const count = steps.reduce((n, step) => n +
57
- activeDoneSteps(runs, String(ctx.flags.workflow), { step, subPlan }, str(ctx.flags.since))
58
- .length, 0);
60
+ const group = positiveInt(ctx.flags.group, "group");
61
+ const doneSteps = ctx.flags.allRuns === true ? allRunsDoneSteps : activeDoneSteps;
62
+ const count = steps.reduce((n, step) => n + doneSteps(runs, String(ctx.flags.workflow), { step, group }).length, 0);
59
63
  if (position === "current" && count === 0)
60
64
  throw new CommandError(EXIT_NO_OWN_ROW, `${steps[0]}: no DONE row in the active run — the step's own row is missing`);
61
65
  return position === "next" ? count + 1 : count;
62
66
  }
63
- function threshold(name) {
64
- const value = THRESHOLDS[name];
65
- if (value === undefined) {
66
- throw new CommandError(EXIT.USAGE, `unknown threshold ${name}; known: ${Object.keys(THRESHOLDS).join(", ")}`);
67
+ /** `--all-runs`: count every run of the workflow in `--file`, not only the active one. */
68
+ const ALL_RUNS_FLAG = {
69
+ name: "all-runs",
70
+ type: "boolean",
71
+ help: "count every run of the workflow in --file, not only the active one",
72
+ };
73
+ /** Rows of `type` in `workflow`'s active run (since its last workflow-started row). */
74
+ function typedRowCount(file, workflow, type) {
75
+ const rows = readStatusRows(file);
76
+ let start = -1;
77
+ rows.forEach((r, i) => {
78
+ if (r.type === "workflow-started" && r.workflow === workflow)
79
+ start = i;
80
+ });
81
+ return rows
82
+ .slice(start + 1)
83
+ .filter((r) => r.type === type && (r.workflow === undefined || r.workflow === workflow)).length;
84
+ }
85
+ /** `route --rows=<type>:count`: rows of that type in the active run. */
86
+ function derivedRows(ctx) {
87
+ const [type, position] = String(ctx.flags.rows).split(":");
88
+ if (!type || position !== "count")
89
+ throw new CommandError(EXIT.USAGE, "--rows must be <row type>:count");
90
+ if (ctx.flags.file === undefined || ctx.flags.workflow === undefined)
91
+ throw new CommandError(EXIT.USAGE, "--rows needs --file and --workflow");
92
+ return typedRowCount(statusFile(ctx), String(ctx.flags.workflow), type);
93
+ }
94
+ /** The checkout a status.jsonl under `docs/plans/` belongs to; `cwd` when it is elsewhere. */
95
+ function checkoutOf(file, cwd) {
96
+ const abs = path.resolve(cwd, file);
97
+ const at = abs.lastIndexOf(`${path.sep}docs${path.sep}plans${path.sep}`);
98
+ return at < 0 ? cwd : abs.slice(0, at);
99
+ }
100
+ /**
101
+ * The loop's direction from its check rounds: `worse` when the problem count rose,
102
+ * `closing` when it fell and the rounds changed code, `stuck` otherwise.
103
+ */
104
+ export function loopTrend(rounds, codeChanged) {
105
+ if (rounds.length < 2)
106
+ return "first-round";
107
+ const first = rounds[0]?.failures;
108
+ const last = rounds.at(-1)?.failures;
109
+ if (first === undefined || last === undefined)
110
+ return "stuck";
111
+ if (last > first)
112
+ return "worse";
113
+ if (last < first && codeChanged !== false)
114
+ return "closing";
115
+ return "stuck";
116
+ }
117
+ /** A fix loop's progress in the active run: `check` counts problems, `fix` fixes them. */
118
+ export function loopProgress(file, cwd, workflow, check, fix, group) {
119
+ const runs = readRuns(file);
120
+ const rounds = activeDoneSteps(runs, workflow, { step: check, group });
121
+ const fixes = activeDoneSteps(runs, workflow, { step: fix, group });
122
+ const first = rounds[0];
123
+ const last = rounds.at(-1);
124
+ let codeChanged = null;
125
+ if (first && last && first !== last && first.parentSha && last.parentSha) {
126
+ const diff = runGit(checkoutOf(file, cwd), [
127
+ "diff",
128
+ "--quiet",
129
+ first.parentSha,
130
+ last.parentSha,
131
+ "--",
132
+ ...SOURCE_PATHS,
133
+ ]);
134
+ // --quiet: exit 0 = no change, 1 = changed; anything else (unknown sha) leaves null.
135
+ if (diff.ok)
136
+ codeChanged = false;
137
+ else if (diff.stderr === "")
138
+ codeChanged = true;
67
139
  }
68
- return value;
140
+ const ladder = lastDoneStepAllRuns(runs, workflow, { step: fix, group })?.strategy;
141
+ const trend = loopTrend(rounds, codeChanged);
142
+ const span = first && last && rounds.length > 1
143
+ ? (Date.parse(last.at) - Date.parse(first.at)) / 60000 / (rounds.length - 1)
144
+ : null;
145
+ return {
146
+ rounds: rounds.map((r) => ({
147
+ attempt: r.attempt ?? null,
148
+ failures: r.failures ?? null,
149
+ at: r.at,
150
+ })),
151
+ counts: rounds.map((r) => (r.failures === undefined ? "?" : String(r.failures))).join(" → "),
152
+ codeChanged,
153
+ lastStrategy: fixes.at(-1)?.strategy ?? null,
154
+ nextStrategy: nextStrategy(ladder),
155
+ finalSpent: fixes.some((r) => r.strategy === "FINAL") || ladder === "FINAL",
156
+ minutesPerRound: span === null || Number.isNaN(span) ? null : Math.round(span),
157
+ trend,
158
+ recommend: trend === "first-round" ? null : trend === "closing" ? "try-again" : "stop",
159
+ };
69
160
  }
70
161
  export const countersCommand = {
71
162
  noun: "counters",
72
- summary: "Attempt counters derived from status.jsonl, and the MAX_* thresholds.",
163
+ summary: "Attempt counters derived from status.jsonl, and the ask points' limits.",
73
164
  verbs: {
74
165
  derive: {
75
166
  summary: "Count a step's DONE rows in the active run, at one of three positions.",
@@ -77,18 +168,14 @@ export const countersCommand = {
77
168
  FILE_FLAG,
78
169
  WORKFLOW_FLAG,
79
170
  STEP_FLAG,
80
- SUB_PLAN_FLAG,
171
+ GROUP_FLAG,
81
172
  {
82
173
  name: "position",
83
174
  type: "string",
84
175
  required: true,
85
176
  help: "next (step start: count+1) | current (after own row: count, 0 refused) | count (other step: 0 legal)",
86
177
  },
87
- {
88
- name: "since",
89
- type: "string",
90
- help: "run field holding a timestamp; only rows after it count (soakEntryAt)",
91
- },
178
+ ALL_RUNS_FLAG,
92
179
  ],
93
180
  output: { value: "the counter at that position", count: "DONE rows counted" },
94
181
  exitCodes: {
@@ -100,7 +187,7 @@ export const countersCommand = {
100
187
  if (!["next", "current", "count"].includes(position)) {
101
188
  throw new CommandError(EXIT.USAGE, "--position must be next, current, or count");
102
189
  }
103
- const count = activeDoneSteps(readRuns(statusFile(ctx)), String(ctx.flags.workflow), { step: String(ctx.flags.step), subPlan: positiveInt(ctx.flags.subPlan, "sub-plan") }, str(ctx.flags.since)).length;
190
+ const count = (ctx.flags.allRuns === true ? allRunsDoneSteps : activeDoneSteps)(readRuns(statusFile(ctx)), String(ctx.flags.workflow), { step: String(ctx.flags.step), group: positiveInt(ctx.flags.group, "group") }).length;
104
191
  if (position === "current" && count === 0) {
105
192
  ctx.log(`${String(ctx.flags.step)}: no DONE row in the active run — the step's own row is missing`);
106
193
  return EXIT_NO_OWN_ROW;
@@ -120,29 +207,34 @@ export const countersCommand = {
120
207
  },
121
208
  },
122
209
  route: {
123
- summary: "Compare a counter to its max: exit 0 continue, exit 1 exceeded.",
210
+ summary: "Compare a counter to its max: exit 0 continue, exit 1 exceeded; with --point, also whether to ask.",
124
211
  flags: [
125
212
  { name: "name", type: "string", required: true, help: "counter name, for the log line" },
126
213
  {
127
214
  name: "value",
128
215
  type: "string",
129
- help: "counter value (non-negative integer), or derive it with --of",
216
+ help: "counter value (non-negative integer), or derive it with --of / --rows",
130
217
  },
131
218
  {
132
219
  name: "of",
133
220
  type: "string",
134
221
  help: "<step>:<next|current|count> — derive the value from --file (active run); <step>,<step>...:count sums the listed steps",
135
222
  },
136
- { ...FILE_FLAG, required: false, help: "status.jsonl, with --of" },
137
- { ...WORKFLOW_FLAG, required: false, help: "workflow, with --of" },
138
- { ...SUB_PLAN_FLAG, help: "with --of: only rows for this sub-plan" },
139
223
  {
140
- name: "since",
224
+ name: "rows",
225
+ type: "string",
226
+ help: "<row type>:count — rows of that type in --file's active run; with --of, added to it",
227
+ },
228
+ { ...FILE_FLAG, required: false, help: "status.jsonl, with --of or --rows" },
229
+ { ...WORKFLOW_FLAG, required: false, help: "workflow, with --of or --rows" },
230
+ { ...GROUP_FLAG, help: "with --of: only rows for this plan group" },
231
+ { ...ALL_RUNS_FLAG, help: "with --of: count every run of the workflow in --file" },
232
+ { name: "max", type: "string", help: "max as a number (or use --point)" },
233
+ {
234
+ name: "point",
141
235
  type: "string",
142
- help: "with --of: run field holding a timestamp; only rows after it count (soakEntryAt)",
236
+ help: `ask point whose limit is the max: ${ASK_POINTS.join(" | ")}`,
143
237
  },
144
- { name: "max", type: "string", help: "max as a number (or use --limit)" },
145
- { name: "limit", type: "string", help: "max as a threshold name, e.g. MAX_VERIFY_ATTEMPT" },
146
238
  { name: "continue", type: "string", help: "step to go to when value <= max" },
147
239
  { name: "exceeded", type: "string", help: "step to go to when value > max" },
148
240
  ],
@@ -151,46 +243,97 @@ export const countersCommand = {
151
243
  exceeded: "true when value > max",
152
244
  next: "--continue or --exceeded step, whichever applies (null when not given)",
153
245
  max: "the max compared against",
246
+ ask: "with --point: the point's ask setting, false when headless (GITHUB_ACTION); else false",
154
247
  },
155
248
  exitCodes: {
156
- [EXIT_NO_STATUS]: "--of: status.jsonl missing, unreadable, or not valid NDJSON",
249
+ [EXIT_NO_STATUS]: "--of / --rows: status.jsonl missing, unreadable, or not valid NDJSON",
157
250
  [EXIT_NO_OWN_ROW]: "--of=<step>:current counted 0: the step's own row is missing",
158
251
  },
159
252
  run: (ctx) => {
160
253
  const name = String(ctx.flags.name);
161
- if ((ctx.flags.value === undefined) === (ctx.flags.of === undefined))
162
- throw new CommandError(EXIT.USAGE, "give exactly one of --value or --of");
163
- const value = ctx.flags.of !== undefined ? derivedOf(ctx) : nonNegativeInt(ctx.flags.value, "value");
164
- if ((ctx.flags.max === undefined) === (ctx.flags.limit === undefined)) {
165
- throw new CommandError(EXIT.USAGE, "give exactly one of --max or --limit");
254
+ const derived = ctx.flags.of !== undefined || ctx.flags.rows !== undefined;
255
+ if (derived === (ctx.flags.value !== undefined))
256
+ throw new CommandError(EXIT.USAGE, "give --value, or --of and/or --rows");
257
+ const value = derived
258
+ ? (ctx.flags.of !== undefined ? derivedOf(ctx) : 0) +
259
+ (ctx.flags.rows !== undefined ? derivedRows(ctx) : 0)
260
+ : nonNegativeInt(ctx.flags.value, "value");
261
+ if ((ctx.flags.max === undefined) === (ctx.flags.point === undefined)) {
262
+ throw new CommandError(EXIT.USAGE, "give exactly one of --max or --point");
166
263
  }
167
- const max = ctx.flags.limit !== undefined
168
- ? threshold(String(ctx.flags.limit))
169
- : nonNegativeInt(ctx.flags.max, "max");
264
+ const point = ctx.flags.point === undefined ? undefined : askPoint(String(ctx.flags.point));
265
+ const setting = point === undefined ? undefined : askSetting(ctx.cwd, point);
266
+ const max = setting === undefined ? nonNegativeInt(ctx.flags.max, "max") : setting.max;
170
267
  const exceeded = value > max;
171
268
  if (exceeded)
172
269
  ctx.log(`counter ${name} exceeded max=${max} (value=${value})`);
173
270
  ctx.emit({
174
271
  value,
175
272
  exceeded,
176
- next: str(exceeded ? ctx.flags.exceeded : ctx.flags.continue) ?? null,
273
+ next: (exceeded ? str(ctx.flags.exceeded) : str(ctx.flags.continue)) ?? null,
177
274
  max,
275
+ ask: setting !== undefined && setting.ask && !headlessRun(ctx.cwd),
178
276
  });
179
277
  return exceeded ? EXIT.NO : EXIT.OK;
180
278
  },
181
279
  },
182
280
  max: {
183
- summary: "The MAX_* thresholds: one by --name, or all.",
281
+ summary: "The ask points' limits and ask settings: one by --point, or all.",
282
+ flags: [{ name: "point", type: "string", help: "ask point, e.g. debug.fix" }],
283
+ output: {
284
+ value: "the point's limit (with --point)",
285
+ ask: "the point's ask setting, false when headless (with --point)",
286
+ points: "every point's {ask, max} as set (without --point)",
287
+ },
288
+ run: (ctx) => {
289
+ const name = str(ctx.flags.point);
290
+ if (name === undefined) {
291
+ ctx.emit({ points: readBkitConfig(checkoutRoot(ctx.cwd)).asks });
292
+ return EXIT.OK;
293
+ }
294
+ const setting = askSetting(ctx.cwd, askPoint(name));
295
+ ctx.emit({
296
+ value: setting.max,
297
+ ask: setting.ask && !headlessRun(ctx.cwd),
298
+ });
299
+ return EXIT.OK;
300
+ },
301
+ },
302
+ progress: {
303
+ summary: "Progress report for a fix loop in the active run: counts per round, code change, strategy, trend.",
184
304
  flags: [
185
- { name: "name", type: "string", help: "threshold name, e.g. MAX_DEV_DISPATCH_ATTEMPTS" },
305
+ FILE_FLAG,
306
+ WORKFLOW_FLAG,
307
+ {
308
+ name: "check",
309
+ type: "string",
310
+ required: true,
311
+ help: "the step that counts problems, e.g. build-plan-verify",
312
+ },
313
+ {
314
+ name: "fix",
315
+ type: "string",
316
+ required: true,
317
+ help: "the step that fixes them, e.g. build-plan-gaps-remediate",
318
+ },
319
+ GROUP_FLAG,
186
320
  ],
187
321
  output: {
188
- value: "the named threshold (with --name)",
189
- thresholds: "every threshold (without --name)",
322
+ rounds: "the check rounds counted: attempt, failures, at",
323
+ counts: "problem count after each round, e.g. 5 → 2",
324
+ codeChanged: "source changed between the first and last check round (null when git cannot tell)",
325
+ lastStrategy: "strategy of the last fix round (null when none ran)",
326
+ nextStrategy: "strategy the next fix round would use",
327
+ finalSpent: "true when a fix round already ran FINAL",
328
+ minutesPerRound: "average minutes between check rounds (null under two rounds)",
329
+ trend: "first-round | closing | stuck | worse",
330
+ recommend: "try-again when closing, else stop (null on the first round)",
190
331
  },
332
+ exitCodes: { [EXIT_NO_STATUS]: "status.jsonl missing, unreadable, or not valid NDJSON" },
191
333
  run: (ctx) => {
192
- const name = str(ctx.flags.name);
193
- ctx.emit(name === undefined ? { thresholds: THRESHOLDS } : { value: threshold(name) });
334
+ ctx.emit({
335
+ ...loopProgress(statusFile(ctx), ctx.cwd, String(ctx.flags.workflow), String(ctx.flags.check), String(ctx.flags.fix), positiveInt(ctx.flags.group, "group")),
336
+ });
194
337
  return EXIT.OK;
195
338
  },
196
339
  },
@@ -218,17 +361,7 @@ export const countersCommand = {
218
361
  const position = String(ctx.flags.position);
219
362
  if (!["next", "count"].includes(position))
220
363
  throw new CommandError(EXIT.USAGE, "--position must be next or count");
221
- const workflow = String(ctx.flags.workflow);
222
- const type = String(ctx.flags.type);
223
- const rows = readStatusRows(statusFile(ctx));
224
- let start = -1;
225
- rows.forEach((r, i) => {
226
- if (r.type === "workflow-started" && r.workflow === workflow)
227
- start = i;
228
- });
229
- const count = rows
230
- .slice(start + 1)
231
- .filter((r) => r.type === type && (r.workflow === undefined || r.workflow === workflow)).length;
364
+ const count = typedRowCount(statusFile(ctx), String(ctx.flags.workflow), String(ctx.flags.type));
232
365
  ctx.emit({ value: position === "next" ? count + 1 : count, count });
233
366
  return EXIT.OK;
234
367
  },