@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
@@ -8,11 +8,12 @@
8
8
  // The lock holds one line, `{at} {workflow} {fid} {token}`. Release removes only a
9
9
  // lock this caller owns (same token, else same workflow and feature), so a Failure
10
10
  // Path that never got the lock cannot delete the holder's.
11
- import { randomBytes } from "node:crypto";
11
+ import { createHash, randomBytes } from "node:crypto";
12
12
  import * as fs from "node:fs";
13
+ import * as os from "node:os";
13
14
  import * as path from "node:path";
14
- import { fold, lastRun, statusTimestamp, } from "../../ledgers/status.js";
15
- import { CommandError, EXIT, parseJson, repoRoot, statusRelPath, utcMonth, } from "../lib.js";
15
+ import { createExclusive, fold, lastRun, statusTimestamp, } from "../../ledgers/status.js";
16
+ import { CommandError, EXIT, git, parseJson, repoRoot, runTool, statusRelPath, utcMonth, } from "../lib.js";
16
17
  import { removeRecord } from "./ledgers.js";
17
18
  import { str } from "./status.js";
18
19
  /** A workflow lock whose holder shows no sign of life for this long is stale. */
@@ -23,6 +24,8 @@ export const EXIT_SPLIT_BUCKET = 7;
23
24
  export const EXIT_NOT_OWNER = 4;
24
25
  /** Exit code: the lock file is still there after removing it. */
25
26
  export const EXIT_REMOVE_FAILED = 5;
27
+ /** Exit code: another run of the feature holds the lock and is still stepping. */
28
+ export const EXIT_LOCK_BUSY = 8;
26
29
  const KINDS = ["workflow"];
27
30
  // ---------------------------------------------------------------------------
28
31
  // Paths
@@ -67,25 +70,99 @@ export function readHolder(file) {
67
70
  /** Create `file` only if absent (`set -C`); false when someone else holds it. */
68
71
  export function tryCreate(file, line) {
69
72
  fs.mkdirSync(path.dirname(file), { recursive: true });
70
- const fd = openExclusive(file);
71
- if (fd === undefined)
72
- return false;
73
- fs.writeSync(fd, `${line}\n`);
74
- fs.closeSync(fd);
75
- return true;
73
+ return createExclusive(file, `${line}\n`);
74
+ }
75
+ const newToken = () => randomBytes(4).toString("hex");
76
+ /** The OS start identity distinguishes a live reused PID from a recorded owner. */
77
+ function processStart(pid, timeoutMs = 1000) {
78
+ const result = runTool("ps", ["-p", String(pid), "-o", "lstart="], process.cwd(), {
79
+ timeoutMs: Math.max(50, Math.min(1000, timeoutMs)),
80
+ });
81
+ return result.found && result.status === 0 && result.stdout.trim() !== ""
82
+ ? result.stdout.trim()
83
+ : null;
84
+ }
85
+ function publicationHolder(file) {
86
+ const parsed = parseJson(fs.readFileSync(file, "utf8"));
87
+ if (!parsed.ok || typeof parsed.value !== "object" || parsed.value === null)
88
+ return null;
89
+ const raw = parsed.value;
90
+ return typeof raw.token === "string" &&
91
+ /^[a-f0-9]{32}$/.test(raw.token) &&
92
+ typeof raw.path === "string" &&
93
+ typeof raw.owner?.host === "string" &&
94
+ Number.isInteger(raw.owner.pid) &&
95
+ raw.owner.pid > 0 &&
96
+ typeof raw.owner.startTime === "string" &&
97
+ Number.isFinite(Date.parse(raw.owner.startTime))
98
+ ? { path: file, token: raw.token, owner: raw.owner }
99
+ : null;
76
100
  }
77
- function openExclusive(file) {
101
+ /** A separate best-effort lock for one issue and invocation; age never establishes death. */
102
+ export async function acquirePublicationLock(cwd, options) {
78
103
  try {
79
- return fs.openSync(file, "wx");
104
+ const end = performance.now() + Math.min(30_000, Math.max(0, options.timeoutMs ?? 30_000));
105
+ const common = git(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
106
+ const startTime = processStart(process.pid, end - performance.now());
107
+ if (!common || !startTime || !options.target || !options.invocation)
108
+ return null;
109
+ const digest = createHash("sha256")
110
+ .update(`${options.target}\0${options.invocation}`)
111
+ .digest("hex");
112
+ const file = path.join(common, "bkit-outbox", "publication-locks", `${digest}.lock`);
113
+ const lock = {
114
+ path: file,
115
+ token: randomBytes(16).toString("hex"),
116
+ owner: { host: os.hostname(), pid: process.pid, startTime },
117
+ };
118
+ fs.mkdirSync(path.dirname(file), { recursive: true });
119
+ do {
120
+ if (tryCreate(file, JSON.stringify(lock)))
121
+ return lock;
122
+ const holder = publicationHolder(file);
123
+ if (!holder || holder.owner.host !== lock.owner.host)
124
+ return null;
125
+ let dead = false;
126
+ try {
127
+ process.kill(holder.owner.pid, 0);
128
+ }
129
+ catch (error) {
130
+ dead = error.code === "ESRCH";
131
+ }
132
+ if (dead) {
133
+ if (publicationHolder(file)?.token !== holder.token)
134
+ return null;
135
+ fs.unlinkSync(file);
136
+ if (tryCreate(file, JSON.stringify(lock)))
137
+ return lock;
138
+ continue;
139
+ }
140
+ if (processStart(holder.owner.pid, end - performance.now()) !== holder.owner.startTime)
141
+ return null;
142
+ const remaining = end - performance.now();
143
+ if (remaining <= 0)
144
+ return null;
145
+ await new Promise((resolve) => setTimeout(resolve, Math.min(20, remaining)));
146
+ } while (performance.now() <= end);
147
+ return null;
80
148
  }
81
- catch (err) {
82
- // EEXIST is the expected "someone holds it" answer; anything else is a real error.
83
- if (err.code === "EEXIST")
84
- return undefined;
85
- throw err;
149
+ catch {
150
+ // Lock failures select standalone publication rather than fail substantive work.
151
+ return null;
152
+ }
153
+ }
154
+ /** Remove only this publication token; filesystem errors leave append unavailable. */
155
+ export async function releasePublicationLock(lock) {
156
+ try {
157
+ if (publicationHolder(lock.path)?.token !== lock.token)
158
+ return false;
159
+ fs.unlinkSync(lock.path);
160
+ return true;
161
+ }
162
+ catch {
163
+ return false;
86
164
  }
87
165
  }
88
- const newToken = () => randomBytes(4).toString("hex");
89
166
  const lockLine = (workflow, fid, token) => `${statusTimestamp()} ${workflow} ${fid} ${token}`;
90
167
  /** The caller owns the lock: same token when it gave one, else same workflow and feature. */
91
168
  export function owns(holder, who) {
@@ -103,7 +180,15 @@ function liveReason(root, month, fid, holder, now) {
103
180
  if (run?.status === "IN_PROGRESS" && lastAt) {
104
181
  const idle = Math.floor((now - Date.parse(lastAt)) / 1000);
105
182
  if (idle < WORKFLOW_LOCK_IDLE_S)
106
- return { live: `idle ${idle}s` };
183
+ return {
184
+ live: {
185
+ workflow: holder.workflow ?? null,
186
+ since: holder.at ?? null,
187
+ lastStepAt: lastAt,
188
+ idleSeconds: idle,
189
+ line: holder.line,
190
+ },
191
+ };
107
192
  }
108
193
  if (run === undefined)
109
194
  return { reason: "orphaned" };
@@ -146,7 +231,12 @@ export function workflowLockFresh(root, fid) {
146
231
  return stat !== undefined && (Date.now() - stat.mtimeMs) / 1000 < WORKFLOW_LOCK_IDLE_S;
147
232
  });
148
233
  }
149
- export function acquireWorkflowLock(opts) {
234
+ const busyMessage = (fid, by) => `workflow already running for ${fid} (workflow=${by.workflow ?? "?"}, ${by.idleSeconds === null ? "just started" : `idle ${by.idleSeconds}s`})`;
235
+ /**
236
+ * Take the feature's workflow lock, reclaiming an idle holder's. A holder still
237
+ * stepping keeps its lock, and the result names it in `heldBy`.
238
+ */
239
+ export function tryAcquireWorkflowLock(opts) {
150
240
  const root = repoRoot(opts.cwd);
151
241
  const month = resolveMonth(root, opts.fid, opts.month);
152
242
  const file = workflowLockPath(root, month, opts.fid);
@@ -156,15 +246,34 @@ export function acquireWorkflowLock(opts) {
156
246
  return { path: file, month, token, reclaimed: null };
157
247
  const holder = readHolder(file) ?? { line: "" };
158
248
  const verdict = liveReason(root, month, opts.fid, holder, Date.now());
159
- if ("live" in verdict) {
160
- throw new CommandError(EXIT.NO, `workflow already running for ${opts.fid} (workflow=${holder.workflow ?? "?"}, ${verdict.live})`);
161
- }
249
+ if ("live" in verdict)
250
+ return { path: file, month, heldBy: verdict.live };
162
251
  opts.log(`reclaiming ${verdict.reason} lock for ${opts.fid}: ${holder.line}`);
163
252
  fs.rmSync(file, { force: true });
164
- if (!tryCreate(file, line))
165
- throw new CommandError(EXIT.NO, `lock contended for ${opts.fid}`);
253
+ if (!tryCreate(file, line)) {
254
+ // Another acquirer took the lock between the removal and this create.
255
+ const winner = readHolder(file) ?? { line: "" };
256
+ return {
257
+ path: file,
258
+ month,
259
+ heldBy: {
260
+ workflow: winner.workflow ?? null,
261
+ since: winner.at ?? null,
262
+ lastStepAt: null,
263
+ idleSeconds: null,
264
+ line: winner.line,
265
+ },
266
+ };
267
+ }
166
268
  return { path: file, month, token, reclaimed: { holder: holder.line, reason: verdict.reason } };
167
269
  }
270
+ /** {@link tryAcquireWorkflowLock}, refusing with {@link EXIT_LOCK_BUSY} when a live run holds the lock. */
271
+ export function acquireWorkflowLock(opts) {
272
+ const lock = tryAcquireWorkflowLock(opts);
273
+ if ("heldBy" in lock)
274
+ throw new CommandError(EXIT_LOCK_BUSY, busyMessage(opts.fid, lock.heldBy));
275
+ return lock;
276
+ }
168
277
  /**
169
278
  * Remove a lock this caller owns. Missing is fine (already released); another
170
279
  * owner's lock is left in place and reported.
@@ -212,29 +321,41 @@ export const locksCommand = {
212
321
  summary: "Acquire and release the per-feature workflow lock.",
213
322
  verbs: {
214
323
  acquire: {
215
- summary: "Take the workflow lock, reclaiming a dead holder's.",
324
+ summary: "Take the workflow lock, reclaiming a dead holder's; a live holder exits 8 and prints heldBy.",
216
325
  use: "workflow",
217
326
  flags: [KIND_FLAG, LOCK_WORKFLOW_FLAG, FID_FLAG, MONTH_FLAG],
218
327
  output: {
219
328
  kind: "workflow",
220
329
  path: "absolute path of the lock file",
221
- token: "this holder's token; pass it to release",
330
+ token: "this holder's token; pass it to release (null when busy)",
222
331
  month: "the month bucket",
223
332
  reclaimed: "{holder, reason: finished|stale|orphaned}; null when none",
333
+ heldBy: "{workflow, since, lastStepAt, idleSeconds, line} of the live run that keeps the lock; null when this call took it",
334
+ route: "go when this call took the lock; stop when a live run keeps it (exit 8). An error exit prints no route",
335
+ message: "for stop: the line for the owner naming the holder, when it took the lock and last stepped, and when this run can start again; empty for go",
224
336
  },
225
337
  exitCodes: {
226
338
  [EXIT_SPLIT_BUCKET]: "the feature has logs in more than one month bucket",
339
+ [EXIT_LOCK_BUSY]: "another run of the feature holds the lock and stepped in the last 30 minutes; nothing was taken or changed",
227
340
  },
228
341
  run: (ctx) => {
229
342
  const kind = kindOf(ctx);
230
- const lock = acquireWorkflowLock({
343
+ const fid = String(ctx.flags.fid);
344
+ const lock = tryAcquireWorkflowLock({
231
345
  cwd: ctx.cwd,
232
346
  workflow: String(ctx.flags.workflow),
233
- fid: String(ctx.flags.fid),
347
+ fid,
234
348
  month: str(ctx.flags.month),
235
349
  log: ctx.log,
236
350
  });
237
- ctx.emit({ kind, ...lock });
351
+ if ("heldBy" in lock) {
352
+ const by = lock.heldBy;
353
+ const message = `${by.workflow ?? "another run"} has held ${fid} since ${by.since ?? "an unknown time"} and last stepped at ${by.lastStepAt ?? "no step yet"}. Nothing changed; this run can start again once that run ends or has been idle ${WORKFLOW_LOCK_IDLE_S / 60} minutes.`;
354
+ ctx.emit({ kind, ...lock, token: null, reclaimed: null, route: "stop", message });
355
+ ctx.log(busyMessage(fid, lock.heldBy));
356
+ return EXIT_LOCK_BUSY;
357
+ }
358
+ ctx.emit({ kind, ...lock, heldBy: null, route: "go", message: "" });
238
359
  return EXIT.OK;
239
360
  },
240
361
  },
@@ -0,0 +1,67 @@
1
+ // The build fix loops, and the step whose test-run rows judge each fix round.
2
+ // Kept apart from decisions.ts and status.ts so both can import it without an import cycle.
3
+ export const LOOPS = {
4
+ verify: {
5
+ title: "Verify",
6
+ check: "build-plan-verify",
7
+ fix: "build-plan-gaps-remediate",
8
+ point: "verify",
9
+ gate: "build-group-gate",
10
+ gateTitle: "Group gate",
11
+ grouped: true,
12
+ },
13
+ // The whole-feature check reopens after each clean round, so its loop starts there. Its allowance is `build.holistic`.
14
+ holistic: {
15
+ title: "Holistic verify",
16
+ check: "build-plan-verify-holistic",
17
+ fix: "build-plan-gaps-remediate-holistic",
18
+ point: "holistic",
19
+ sinceClean: true,
20
+ gate: "build-holistic-gate",
21
+ gateTitle: "Holistic gate",
22
+ },
23
+ tests: {
24
+ title: "Tests",
25
+ check: "build-run-tests",
26
+ fix: "build-failure-diagnose",
27
+ point: "tests",
28
+ },
29
+ };
30
+ /** Fix steps outside the build loops, and the test step each one's rounds are judged by. */
31
+ const OTHER_FIX_TESTS = {
32
+ "debug-failure-diagnose": "debug-run-tests",
33
+ };
34
+ /**
35
+ * The test-run step a loop's gate writes: the gate, with `-{group}` appended for a grouped
36
+ * loop. Undefined for a loop with no gate, or a grouped loop given no group.
37
+ */
38
+ export function loopGateStep(loop, group) {
39
+ if (loop.gate === undefined)
40
+ return undefined;
41
+ if (loop.grouped !== true)
42
+ return loop.gate;
43
+ return group === undefined ? undefined : `${loop.gate}-${group}`;
44
+ }
45
+ /**
46
+ * The step whose test-run rows show what a fix step's rounds left failing: the loop's gate
47
+ * (with the group for a grouped loop), else its check; `debug-failure-diagnose` gives
48
+ * `debug-run-tests`. Undefined for any other step, or a grouped loop given no group.
49
+ */
50
+ export function fixTestStep(fix, group) {
51
+ const other = OTHER_FIX_TESTS[fix];
52
+ if (other !== undefined)
53
+ return other;
54
+ const loop = Object.values(LOOPS).find((l) => l.fix === fix);
55
+ if (loop === undefined)
56
+ return undefined;
57
+ return loop.gate === undefined ? loop.check : loopGateStep(loop, group);
58
+ }
59
+ /**
60
+ * The check step whose current attempt a fix step's round follows, for a loop whose gate
61
+ * does not run on every round: the gate's newest row can belong to an older attempt.
62
+ * Undefined for a loop with no gate, whose test step is the check itself.
63
+ */
64
+ export function gatedCheckStep(fix) {
65
+ const loop = Object.values(LOOPS).find((l) => l.fix === fix);
66
+ return loop?.gate === undefined ? undefined : loop.check;
67
+ }
@@ -0,0 +1,199 @@
1
+ // Read a build Decision Pause file: its header, its items, the run's open pause, and the two
2
+ // rules read from them — whether a resume re-runs a red gate (`gateRerun`) and whether a
3
+ // pause may route `continue` (`skipProblem`). `decisions.ts` writes these files; this module
4
+ // only reads them and imports nothing from the command modules, so `status.ts`, `steps.ts`
5
+ // and `workflows.ts` read it without an import cycle.
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+ /** Splits a decision file before each `**Q{n} — ` item line. */
9
+ export const ITEM_SPLIT = /^(?=\*\*Q\d+ — )/m;
10
+ const lineOf = (text, key) => new RegExp(`^${key}:[ \\t]*(.+?)[ \\t]*$`, "m").exec(text)?.[1] ?? null;
11
+ /** `A`, `B`, … for option index `i`. */
12
+ export const letterAt = (i) => String.fromCharCode(65 + i);
13
+ /** An option entry's leading letter (`A) `) dropped, so a parsed name stays bare. */
14
+ const bareName = (s) => s.replace(/^[A-Z]\)[ \t]*/, "");
15
+ /** A reply opening on an option letter: `B`, `B)`, `B — …`, `B) {option} …`, `B {option} …`. */
16
+ const LETTER_REPLY = /^([A-Za-z])(?:\)|(?=[ \t—:,.-]|$))[ \t]*(?:[—:,.-][ \t]*)?/;
17
+ /**
18
+ * An answer read as the option it names. A leading letter of `options` (either case, with or
19
+ * without `)`) becomes the option it labels: `B`, `B) Reject` and `B — too risky` read as
20
+ * `Reject`, `Reject` and `Reject — too risky`. Any other answer is returned unchanged; with
21
+ * no options known, only a leading `A) ` is dropped.
22
+ */
23
+ export function optionAnswer(answer, options) {
24
+ if (options.length === 0)
25
+ return bareName(answer);
26
+ const m = LETTER_REPLY.exec(answer);
27
+ const name = m === null ? undefined : options[m[1].toUpperCase().charCodeAt(0) - 65];
28
+ if (m === null || name === undefined)
29
+ return answer;
30
+ const rest = answer.slice(m[0].length);
31
+ if (rest.toLowerCase().startsWith(name.toLowerCase()))
32
+ return name + rest.slice(name.length);
33
+ if (rest === "")
34
+ return name;
35
+ return /[)—:,.-]/.test(m[0]) ? `${name} — ${rest}` : answer;
36
+ }
37
+ /** A `Fix task:` value as a positive integer, else null. */
38
+ const fixTaskOf = (v) => v !== null && /^[1-9][0-9]*$/.test(v) ? Number(v) : null;
39
+ /** The `Key: value` lines before the file's first blank line. */
40
+ export function decisionHeader(text) {
41
+ const out = {};
42
+ for (const line of text.split("\n")) {
43
+ if (line.trim() === "" || line.startsWith("**Q"))
44
+ break;
45
+ const m = /^([A-Za-z][\w ]*):[ \t]*(.*?)[ \t]*$/.exec(line);
46
+ if (m !== null && !(m[1] in out))
47
+ out[m[1]] = m[2];
48
+ }
49
+ return out;
50
+ }
51
+ /** The items of a decision file's text, in file order. */
52
+ export function parseDecisionItems(text) {
53
+ return text
54
+ .split(ITEM_SPLIT)
55
+ .slice(1)
56
+ .map((part) => {
57
+ const head = /^\*\*Q(\d+) — (.+?):\*\*/.exec(part);
58
+ const rec = lineOf(part, "Recommended");
59
+ const [option, ...why] = (rec ?? "").split(" — ");
60
+ const none = /^No recommendation\b/m.test(part) || /^none$/i.test((option ?? "").trim());
61
+ const perLine = [...part.matchAll(/^[A-Z]\)[ \t]+(.+?)[ \t]*$/gm)].map((m) => (m[1] ?? "").split(" — ")[0].trim());
62
+ const options = perLine.length > 0
63
+ ? perLine.filter(Boolean)
64
+ : (lineOf(part, "Options") ?? "")
65
+ .split(" / ")
66
+ .map((o) => bareName(o.trim()))
67
+ .filter(Boolean);
68
+ const answer = lineOf(part, "Decision");
69
+ const decision = answer === null ? null : optionAnswer(answer, options);
70
+ return {
71
+ n: Number(head?.[1] ?? 0),
72
+ title: head?.[2] ?? "",
73
+ text: part.trimEnd(),
74
+ options,
75
+ recommended: none || rec === null ? null : bareName((option ?? "").trim()),
76
+ reason: why.join(" — ").trim(),
77
+ decision,
78
+ fixTask: fixTaskOf(lineOf(part, "Fix task")),
79
+ assumed: decision !== null && /^Accept \(assumed\)/.test(decision),
80
+ rejected: lineOf(part, "Rejected") !== null,
81
+ deferred: lineOf(part, "Deferred") !== null,
82
+ };
83
+ });
84
+ }
85
+ /**
86
+ * Whether Q1 is the loop question (the text before the first item holds a `## Progress`
87
+ * block), and the questions besides it that nobody answered, rejected or deferred.
88
+ */
89
+ export function undecidedBesidesLoop(text) {
90
+ const hasLoop = /^## Progress$/m.test(text.split(ITEM_SPLIT, 1)[0] ?? "");
91
+ const undecided = parseDecisionItems(text)
92
+ .filter((i) => (hasLoop ? i.n !== 1 : true) && i.decision === null && !i.rejected && !i.deferred)
93
+ .map((i) => `Q${i.n}`);
94
+ return { hasLoop, undecided };
95
+ }
96
+ /** The checks a red-gate pause re-runs, by the decision file's `From` header. */
97
+ export const RERUN_FROM = ["verify", "holistic", "tests"];
98
+ /**
99
+ * Whether a resume re-runs the pause's gate instead of asking it again: its `Gate` header is
100
+ * `FAIL`, its `Status` is `OPEN`, the loop question is its only undecided question, and its
101
+ * `From` names a check that re-runs. `rerunFrom` is that check, null when `gateRerun` is false.
102
+ */
103
+ export function gateRerun(open, text) {
104
+ const from = RERUN_FROM.find((f) => f === open?.from);
105
+ const { hasLoop, undecided } = undecidedBesidesLoop(text);
106
+ const rerun = open?.gate === "FAIL" &&
107
+ open.status === "OPEN" &&
108
+ from !== undefined &&
109
+ hasLoop &&
110
+ undecided.length === 0;
111
+ return { gateRerun: rerun, rerunFrom: rerun ? from : null };
112
+ }
113
+ /** An item answer that accepts the item: `Accept` or `Accept (assumed)`, with or without words. */
114
+ const ACCEPTED = /^Accept(?: \(assumed\))?(?:$|[ \t]+—)/;
115
+ /**
116
+ * The first fact that stops a settled pause from routing `continue`, or null when all five
117
+ * hold: `From` is `verify` or `holistic`; every item is `Accept` or `Accept (assumed)`; the
118
+ * loop question, when asked, is `Decide`; no `Gate: FAIL` header; and a `Source changed`
119
+ * header that reads `false`. Headers count only in the header block, so a line inside an item
120
+ * never stands in for one. A missing fact refuses; it is never guessed.
121
+ */
122
+ export function skipProblem(text) {
123
+ const header = decisionHeader(text);
124
+ const from = header.From;
125
+ if (from === undefined)
126
+ return "no From header";
127
+ if (from !== "verify" && from !== "holistic")
128
+ return `From is "${from}", not verify or holistic`;
129
+ const { hasLoop } = undecidedBesidesLoop(text);
130
+ const items = parseDecisionItems(text);
131
+ for (const it of items) {
132
+ if (hasLoop && it.n === 1)
133
+ continue;
134
+ if (it.rejected)
135
+ return `Q${it.n} is rejected, not Accept`;
136
+ if (it.decision === null || !ACCEPTED.test(it.decision))
137
+ return `Q${it.n} is ${it.decision === null ? "undecided" : `"${it.decision}"`}, not Accept`;
138
+ }
139
+ const loop = hasLoop ? items.find((i) => i.n === 1) : undefined;
140
+ if (loop !== undefined && !/^Decide\b/.test(loop.decision ?? ""))
141
+ return `the loop question Q1 is ${loop.decision === null ? "undecided" : `"${loop.decision}"`}, not Decide`;
142
+ if (/^FAIL\b/.test(header.Gate ?? ""))
143
+ return "Gate: FAIL header: the gate is red";
144
+ const changed = header["Source changed"];
145
+ if (changed === undefined)
146
+ return "no Source changed header";
147
+ if (changed !== "false")
148
+ return `Source changed is "${changed}", not false`;
149
+ return null;
150
+ }
151
+ /**
152
+ * The highest-numbered `{workflow}-decision-{run}-{N}.md` in `logDir` whose header holds
153
+ * `Status: OPEN`, or a `DECIDED` / `ASSUMED` file that none of the run's `{workflow}-decision`
154
+ * rows names (a pause stopped after its answers were written, before the step finished), or
155
+ * null. Only the given run's files count, so an earlier run's pause never resurfaces.
156
+ * `file` is relative to `tree`; `finished` lists the paths the run's decision rows name.
157
+ */
158
+ export function openDecision(logDir, tree, workflow, run, finished = []) {
159
+ if (!fs.existsSync(logDir))
160
+ return null;
161
+ const name = new RegExp(`^${workflow}-decision-${run}-([0-9]+)\\.md$`);
162
+ const found = fs
163
+ .readdirSync(logDir)
164
+ .map((f) => ({ f, m: name.exec(f) }))
165
+ .filter((x) => x.m !== null)
166
+ .map(({ f, m }) => ({ f, n: Number(m[1]) }))
167
+ .sort((a, b) => b.n - a.n);
168
+ for (const { f, n } of found) {
169
+ const text = fs.readFileSync(path.join(logDir, f), "utf-8");
170
+ const field = (key) => new RegExp(`^${key}:[ \\t]*(.+?)[ \\t]*$`, "m").exec(text)?.[1] ?? null;
171
+ const status = field("Status");
172
+ const rel = path.relative(tree, path.join(logDir, f));
173
+ const unfinished = (status === "DECIDED" || status === "ASSUMED") && !finished.includes(rel);
174
+ if (status !== "OPEN" && !unfinished)
175
+ continue;
176
+ // `Gate:` counts only in the header block (the lines before the first blank line).
177
+ const header = text.split(/\r?\n[ \t]*\r?\n/, 1)[0] ?? "";
178
+ const gate = /^Gate:[ \t]*(.+?)[ \t]*$/m.exec(header)?.[1] ?? null;
179
+ const num = (key) => {
180
+ const v = field(key);
181
+ return v !== null && /^[0-9]+$/.test(v) ? Number(v) : null;
182
+ };
183
+ return {
184
+ file: rel,
185
+ decision: n,
186
+ question: field("Question"),
187
+ from: field("From"),
188
+ pauseStep: num("Pause step"),
189
+ group: num("Group"),
190
+ verifyAttempt: num("Verify attempt"),
191
+ testAttempt: num("Test attempt"),
192
+ plan: field("Plan"),
193
+ gate,
194
+ sourceChanged: field("Source changed"),
195
+ status: status ?? "OPEN",
196
+ };
197
+ }
198
+ return null;
199
+ }
@@ -53,6 +53,12 @@ function firstTable(lines, heading) {
53
53
  return null;
54
54
  return { head, cols: tableCells(lines[head]) };
55
55
  }
56
+ /** The test tier `docs/testing.md` records for a test file's name. */
57
+ export const testTier = (file) => /\.integration\.test\./.test(file)
58
+ ? "Integration"
59
+ : /\.live\.test\./.test(file)
60
+ ? "@live (golden)"
61
+ : "Unit";
56
62
  /**
57
63
  * The plan's Reuse Inventory: the first table under the first heading naming Reuse
58
64
  * Inventory, before the next heading of the same or a higher level. Each row's `File`
@@ -197,7 +197,7 @@ export const plansCommand = {
197
197
  month: String(ctx.flags.month),
198
198
  fid: String(ctx.flags.fid),
199
199
  });
200
- ctx.emit({ comment: body, commentFile: commentFileOf(ctx.cwd, body), plans });
200
+ ctx.emit({ comment: body, commentFile: commentFileOf(ctx.cwd, body, ctx), plans });
201
201
  return EXIT.OK;
202
202
  },
203
203
  },