@cbartens/bkit 6.1.0 → 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 (317) 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 +43 -33
  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 +99 -36
  15. package/.bkit/core/.bkit/templates.md +167 -37
  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 +161 -37
  64. package/.bkit/core/engine/checks/after/index.ts +18 -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 +124 -19
  74. package/.bkit/core/engine/commands/ci/push-gate.ts +101 -43
  75. package/.bkit/core/engine/commands/install/doctor.ts +5 -5
  76. package/.bkit/core/engine/commands/install/install.ts +28 -25
  77. package/.bkit/core/engine/commands/install/uninstall.ts +42 -30
  78. package/.bkit/core/engine/commands/install/upgrade.ts +14 -2
  79. package/.bkit/core/engine/commands/land.ts +2 -3
  80. package/.bkit/core/engine/commands/lib.ts +394 -39
  81. package/.bkit/core/engine/commands/registry.ts +1 -1
  82. package/.bkit/core/engine/commands/workflow/branches.ts +351 -78
  83. package/.bkit/core/engine/commands/workflow/challenge.ts +63 -14
  84. package/.bkit/core/engine/commands/workflow/context.ts +71 -10
  85. package/.bkit/core/engine/commands/workflow/counters.ts +298 -23
  86. package/.bkit/core/engine/commands/workflow/decisions.ts +260 -125
  87. package/.bkit/core/engine/commands/workflow/disk.ts +2 -1
  88. package/.bkit/core/engine/commands/workflow/feature-base.ts +66 -0
  89. package/.bkit/core/engine/commands/workflow/issues.ts +312 -17
  90. package/.bkit/core/engine/commands/workflow/junit.ts +204 -0
  91. package/.bkit/core/engine/commands/workflow/ledgers.ts +904 -99
  92. package/.bkit/core/engine/commands/workflow/locks.ts +186 -29
  93. package/.bkit/core/engine/commands/workflow/loops.ts +87 -0
  94. package/.bkit/core/engine/commands/workflow/open-decision.ts +251 -0
  95. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +8 -0
  96. package/.bkit/core/engine/commands/workflow/plans.ts +1 -1
  97. package/.bkit/core/engine/commands/workflow/prs.ts +311 -16
  98. package/.bkit/core/engine/commands/workflow/repo.ts +1 -1
  99. package/.bkit/core/engine/commands/workflow/run-facts.ts +6 -0
  100. package/.bkit/core/engine/commands/workflow/runs.ts +877 -174
  101. package/.bkit/core/engine/commands/workflow/runtime.ts +12 -4
  102. package/.bkit/core/engine/commands/workflow/status.ts +324 -11
  103. package/.bkit/core/engine/commands/workflow/step-table.ts +41 -15
  104. package/.bkit/core/engine/commands/workflow/steps.ts +604 -29
  105. package/.bkit/core/engine/commands/workflow/summary-findings.ts +1 -1
  106. package/.bkit/core/engine/commands/workflow/summary.ts +314 -8
  107. package/.bkit/core/engine/commands/workflow/tasks.ts +400 -27
  108. package/.bkit/core/engine/commands/workflow/tests-base.ts +319 -0
  109. package/.bkit/core/engine/commands/workflow/tests-changed.ts +138 -74
  110. package/.bkit/core/engine/commands/workflow/tests-jump.ts +93 -0
  111. package/.bkit/core/engine/commands/workflow/tests.ts +815 -182
  112. package/.bkit/core/engine/commands/workflow/tracker.ts +1134 -137
  113. package/.bkit/core/engine/commands/workflow/workflows.ts +100 -72
  114. package/.bkit/core/engine/commands/workflow/worktrees.ts +421 -57
  115. package/.bkit/core/engine/install/cloud-env.ts +38 -10
  116. package/.bkit/core/engine/install/managed-block.ts +105 -0
  117. package/.bkit/core/engine/install/manifest.ts +7 -1
  118. package/.bkit/core/engine/install/modules/claude.ts +6 -2
  119. package/.bkit/core/engine/install/modules/cloud.ts +84 -95
  120. package/.bkit/core/engine/install/modules/codex.ts +10 -2
  121. package/.bkit/core/engine/install/modules/core.ts +202 -26
  122. package/.bkit/core/engine/install/modules/opencode.ts +18 -23
  123. package/.bkit/core/engine/install/network-allowlist.ts +8 -3
  124. package/.bkit/core/engine/install/project-docs.ts +650 -0
  125. package/.bkit/core/engine/install/template-copies.ts +58 -5
  126. package/.bkit/core/engine/install/write.ts +128 -7
  127. package/.bkit/core/engine/ledgers/journal.ts +18 -10
  128. package/.bkit/core/engine/ledgers/migrate.ts +20 -8
  129. package/.bkit/core/engine/ledgers/status.ts +604 -8
  130. package/.bkit/core/engine/ledgers/telemetry.ts +115 -13
  131. package/.bkit/core/engine/render/trackers.ts +46 -11
  132. package/.bkit/core/engine/shared/package-manager.ts +7 -3
  133. package/.bkit/core/engine/shared/settings.ts +12 -1
  134. package/.bkit/core/engine/shared/text.ts +14 -0
  135. package/.bkit/core/engine/tools/instructions-sources.ts +1 -0
  136. package/.bkit/core/engine/tools/instructions.ts +116 -20
  137. package/.bkit/core/hooks/antigravity-hook.js +20 -4
  138. package/.bkit/core/hooks/gateguard-edit-payload.js +8 -5
  139. package/.bkit/core/hooks/gateguard-engine.js +249 -23
  140. package/.bkit/core/hooks/guardrails-deny.js +167 -0
  141. package/.bkit/core/hooks/guardrails-read.js +3 -3
  142. package/.bkit/core/hooks/guardrails-shell.js +1122 -167
  143. package/.bkit/core/hooks/guardrails-tiers.js +247 -176
  144. package/.bkit/core/hooks/preflight-tracker.sh +219 -0
  145. package/.bkit/core/prompts/bkit-audit-generate.md +23 -6
  146. package/.bkit/core/prompts/bkit-build-challenge-1.md +5 -4
  147. package/.bkit/core/prompts/bkit-build-challenge-2.md +6 -5
  148. package/.bkit/core/prompts/bkit-build-install-skills.md +2 -2
  149. package/.bkit/core/prompts/bkit-build-plan-convert.md +21 -7
  150. package/.bkit/core/prompts/bkit-build-plan-current.md +5 -4
  151. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +22 -17
  152. package/.bkit/core/prompts/bkit-build-plan-tasks.md +16 -12
  153. package/.bkit/core/prompts/bkit-build-plan-tests.md +14 -10
  154. package/.bkit/core/prompts/bkit-build-plan-verify.md +21 -8
  155. package/.bkit/core/prompts/bkit-debug-abort-handover.md +10 -5
  156. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +22 -6
  157. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +19 -3
  158. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +22 -6
  159. package/.bkit/core/prompts/bkit-debug-failure-soak.md +10 -7
  160. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +3 -3
  161. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +4 -4
  162. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +3 -3
  163. package/.bkit/core/prompts/bkit-design-generate.md +6 -4
  164. package/.bkit/core/prompts/bkit-design-organise.md +4 -3
  165. package/.bkit/core/prompts/bkit-design-review-1.md +5 -4
  166. package/.bkit/core/prompts/bkit-design-review-2.md +6 -5
  167. package/.bkit/core/prompts/bkit-design-spike.md +4 -3
  168. package/.bkit/core/prompts/bkit-design-update.md +6 -4
  169. package/.bkit/core/prompts/bkit-plan-generate.md +35 -14
  170. package/.bkit/core/prompts/bkit-plan-review-1.md +9 -7
  171. package/.bkit/core/prompts/bkit-plan-review-2.md +9 -7
  172. package/.bkit/core/prompts/bkit-plan-scope-check.md +8 -6
  173. package/.bkit/core/prompts/bkit-plan-update.md +22 -8
  174. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +11 -8
  175. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +9 -5
  176. package/.bkit/core/prompts/bkit-ship-update-docs.md +26 -4
  177. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +3 -3
  178. package/.bkit/core/prompts/bkit-utility-update-decisions.md +10 -7
  179. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +8 -5
  180. package/.bkit/core/prompts/bkit-utility-update-documentation.md +31 -7
  181. package/.bkit/core/prompts/bkit-utility-update-failures.md +8 -5
  182. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +10 -7
  183. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +4 -4
  184. package/.bkit/core/prompts/bkit-utility-update-tracker.md +4 -4
  185. package/.bkit/core/workflows/bkit-auto.md +23 -11
  186. package/.bkit/core/workflows/bkit-build.md +331 -100
  187. package/.bkit/core/workflows/bkit-debug.md +135 -64
  188. package/.bkit/core/workflows/bkit-design.md +58 -32
  189. package/.bkit/core/workflows/bkit-plan.md +73 -45
  190. package/.bkit/core/workflows/bkit-ship.md +233 -167
  191. package/.bkit/shared/.agents/plugins/bkit/hooks.json +1 -1
  192. package/.bkit/shared/.bkit/.env.example +5 -0
  193. package/.bkit/shared/.claude/bkit-cloud.md +7 -7
  194. package/.bkit/shared/.claude/settings.json +5 -1
  195. package/.bkit/shared/.cursor/bkit-cloud.md +1 -1
  196. package/.bkit/shared/.cursor/hooks.json +1 -1
  197. package/.bkit/shared/.opencode/opencode.json +11 -2
  198. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +27 -0
  199. package/.bkit/templates/.cursor/Dockerfile +7 -7
  200. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +1 -1
  201. package/.bkit/templates/.github/dependabot.yml +5 -0
  202. package/.bkit/templates/.github/renovate.json5 +5 -3
  203. package/.bkit/templates/.github/workflows/bkit-ci.yml +11 -11
  204. package/.bkit/templates/.github/workflows/bkit-cloud.yml +525 -161
  205. package/.bkit/templates/.github/workflows/bkit-renovate.yml +2 -2
  206. package/.bkit/templates/.husky/pre-push +123 -6
  207. package/.bkit/templates/context/bkit-serena.md +1 -1
  208. package/.bkit/templates/context/bkit-vercel.md +103 -59
  209. package/.bkit/templates/docs/architecture.md +98 -0
  210. package/.bkit/templates/docs/capabilities.md +33 -37
  211. package/.bkit/templates/docs/components.md +142 -0
  212. package/.bkit/templates/docs/data-schema.md +87 -0
  213. package/.bkit/{shared → templates}/docs/deployments.md +128 -142
  214. package/.bkit/templates/docs/design.md +117 -0
  215. package/.bkit/templates/docs/noise.md +54 -0
  216. package/.bkit/templates/docs/observability.md +99 -0
  217. package/.bkit/templates/docs/security.md +137 -0
  218. package/.bkit/templates/docs/setup.md +93 -0
  219. package/.bkit/templates/docs/technology.md +70 -0
  220. package/.bkit/{shared → templates}/docs/testing.md +200 -87
  221. package/.bkit/templates/scripts/ci/bkit-check-accepted-divergences.mjs +1 -6
  222. package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +511 -103
  223. package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +314 -28
  224. package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +500 -1
  225. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
  226. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +91 -62
  227. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +59 -11
  228. package/.bkit/templates/slop-scan.config.json +2 -0
  229. package/CHANGELOG.md +79 -0
  230. package/DETAILS.md +661 -0
  231. package/README.md +73 -604
  232. package/dist/checks/after/auth.js +114 -46
  233. package/dist/checks/after/github.js +138 -35
  234. package/dist/checks/after/index.js +16 -4
  235. package/dist/checks/after/tools.js +224 -1
  236. package/dist/checks/before/files.js +59 -1
  237. package/dist/checks/before/index.js +7 -1
  238. package/dist/checks/status-holes.js +20 -21
  239. package/dist/checks/tips/catalogue.js +99 -10
  240. package/dist/checks/tips/detect.js +35 -3
  241. package/dist/checks/tips/index.js +1 -1
  242. package/dist/cli.js +13 -13
  243. package/dist/commands/ci/ci.js +113 -20
  244. package/dist/commands/ci/push-gate.js +79 -44
  245. package/dist/commands/install/doctor.js +5 -5
  246. package/dist/commands/install/install.js +23 -22
  247. package/dist/commands/install/uninstall.js +36 -30
  248. package/dist/commands/install/upgrade.js +10 -2
  249. package/dist/commands/land.js +2 -3
  250. package/dist/commands/lib.js +323 -25
  251. package/dist/commands/workflow/branches.js +312 -72
  252. package/dist/commands/workflow/challenge.js +66 -13
  253. package/dist/commands/workflow/context.js +46 -10
  254. package/dist/commands/workflow/counters.js +231 -23
  255. package/dist/commands/workflow/decisions.js +221 -106
  256. package/dist/commands/workflow/disk.js +2 -1
  257. package/dist/commands/workflow/feature-base.js +60 -0
  258. package/dist/commands/workflow/issues.js +243 -15
  259. package/dist/commands/workflow/junit.js +137 -0
  260. package/dist/commands/workflow/ledgers.js +726 -112
  261. package/dist/commands/workflow/locks.js +150 -29
  262. package/dist/commands/workflow/loops.js +67 -0
  263. package/dist/commands/workflow/open-decision.js +199 -0
  264. package/dist/commands/workflow/plan-blocks.js +6 -0
  265. package/dist/commands/workflow/plans.js +1 -1
  266. package/dist/commands/workflow/prs.js +272 -16
  267. package/dist/commands/workflow/repo.js +1 -1
  268. package/dist/commands/workflow/run-facts.js +6 -0
  269. package/dist/commands/workflow/runs.js +747 -155
  270. package/dist/commands/workflow/runtime.js +8 -4
  271. package/dist/commands/workflow/status.js +259 -13
  272. package/dist/commands/workflow/step-table.js +41 -15
  273. package/dist/commands/workflow/steps.js +530 -26
  274. package/dist/commands/workflow/summary-findings.js +1 -1
  275. package/dist/commands/workflow/summary.js +289 -8
  276. package/dist/commands/workflow/tasks.js +294 -27
  277. package/dist/commands/workflow/tests-base.js +266 -0
  278. package/dist/commands/workflow/tests-changed.js +130 -56
  279. package/dist/commands/workflow/tests-jump.js +77 -0
  280. package/dist/commands/workflow/tests.js +608 -131
  281. package/dist/commands/workflow/tracker.js +920 -112
  282. package/dist/commands/workflow/workflows.js +80 -59
  283. package/dist/commands/workflow/worktrees.js +387 -58
  284. package/dist/install/cloud-env.js +32 -10
  285. package/dist/install/managed-block.js +101 -0
  286. package/dist/install/manifest.js +7 -1
  287. package/dist/install/modules/claude.js +6 -2
  288. package/dist/install/modules/cloud.js +73 -86
  289. package/dist/install/modules/codex.js +9 -2
  290. package/dist/install/modules/core.js +190 -27
  291. package/dist/install/modules/opencode.js +18 -23
  292. package/dist/install/network-allowlist.js +8 -3
  293. package/dist/install/project-docs.js +551 -0
  294. package/dist/install/template-copies.js +55 -5
  295. package/dist/install/write.js +117 -5
  296. package/dist/ledgers/journal.js +10 -8
  297. package/dist/ledgers/migrate.js +20 -9
  298. package/dist/ledgers/status.js +461 -8
  299. package/dist/ledgers/telemetry.js +71 -13
  300. package/dist/render/trackers.js +21 -12
  301. package/dist/shared/package-manager.js +7 -2
  302. package/dist/shared/settings.js +8 -0
  303. package/dist/shared/text.js +13 -0
  304. package/dist/tools/instructions-sources.js +1 -0
  305. package/dist/tools/instructions.js +97 -24
  306. package/package.json +23 -15
  307. package/.bkit/core/hooks/preflight-linear.sh +0 -73
  308. package/.bkit/shared/docs/architecture.md +0 -16
  309. package/.bkit/shared/docs/data-schema.md +0 -16
  310. package/.bkit/shared/docs/design.md +0 -38
  311. package/.bkit/shared/docs/noise.md +0 -20
  312. package/.bkit/shared/docs/observability.md +0 -22
  313. package/.bkit/shared/docs/security.md +0 -62
  314. package/.bkit/shared/docs/setup.md +0 -52
  315. package/.bkit/shared/docs/technology.md +0 -15
  316. /package/.bkit/templates/{.lintstagedrc.json → lintstagedrc.example.json} +0 -0
  317. /package/.bkit/templates/{.prettierignore → prettierignore.example} +0 -0
@@ -7,7 +7,7 @@ import {
7
7
  } from "./challenge.js";
8
8
  import type { PlanTaskBlock } from "./plan-blocks.js";
9
9
  import type { SummaryInput } from "./summary.js";
10
- import { parseDecisionItems } from "./decisions.js";
10
+ import { parseDecisionItems } from "./open-decision.js";
11
11
 
12
12
  type Row = Record<string, unknown>;
13
13
  type Task = PlanTaskBlock & { path: string };
@@ -5,9 +5,20 @@
5
5
 
6
6
  import { coversList, type Plan, type Workstream } from "./plans.js";
7
7
  import { issueIdOf, type FidTracker } from "./fids.js";
8
- import { parseDecisionItems } from "./decisions.js";
8
+ import { decisionHeader, parseDecisionItems } from "./open-decision.js";
9
9
  import { parsePlanBlocks } from "./plan-blocks.js";
10
+ import { parseJson } from "../../shared/json.js";
11
+ import { oneLine } from "../../shared/text.js";
10
12
  import { challengeResolution, taskVerified } from "./summary-findings.js";
13
+ import { RED_STEP, redTestsOf, TAKEOVER_STEP } from "./tests.js";
14
+
15
+ /** What a taken-over test's red state proves, in the summary's words. */
16
+ const handedWords = (state: string) => {
17
+ if (state === "red" || state === "red-not-loaded") return "recorded failing";
18
+ if (state === "taken-over") return "changed hands, not proven failing";
19
+ if (state === "updated") return "existing test updated and passing; verify judged its diff";
20
+ return `not recorded red (\`${state}\`)`;
21
+ };
11
22
 
12
23
  export const SUMMARY_WORKFLOWS = ["plan", "design", "build", "debug", "ship"] as const;
13
24
  export type SummaryWorkflow = (typeof SUMMARY_WORKFLOWS)[number];
@@ -60,14 +71,35 @@ export function refOf(fid: string, tracker: FidTracker = "any"): string | undefi
60
71
  }
61
72
 
62
73
  /**
63
- * Review updates cover their review's findings. Group verification covers failed
64
- * execution, but does not cover a remediation agent's separate warnings or flakes.
74
+ * Review updates cover their review's findings. The same group's verification, or a
75
+ * whole-plan verification, covers failed execution; a passing test run covers a failed
76
+ * test-failure fix. None covers a remediation agent's separate warnings or flakes.
65
77
  */
66
78
  const RESOLVED_BY: Readonly<Record<string, readonly string[]>> = {
67
79
  "plan/plan-review": ["plan-apply-review"],
68
80
  "design/design-review": ["design-apply-review"],
69
- "build/build-plan-tasks": ["build-plan-verify"],
70
- "build/build-plan-gaps-remediate": ["build-plan-verify"],
81
+ "build/build-plan-tasks": ["build-plan-verify", "build-plan-verify-holistic"],
82
+ "build/build-plan-gaps-remediate": ["build-plan-verify", "build-plan-verify-holistic"],
83
+ "build/build-plan-gaps-remediate-holistic": ["build-plan-verify-holistic"],
84
+ "build/build-failure-remediate": ["build-run-tests"],
85
+ "debug/debug-failure-remediate": ["debug-run-tests"],
86
+ };
87
+
88
+ /** Test-fix steps whose resolving run must have run the scope of the run the fix followed. */
89
+ const SAME_SCOPE = new Set(["build/build-failure-remediate", "debug/debug-failure-remediate"]);
90
+
91
+ /** Steps that check the whole run, so they answer a failure in any task group. */
92
+ const WHOLE_RUN = new Set(["build-plan-verify-holistic", "build-run-tests"]);
93
+
94
+ /**
95
+ * Whole-run checks that cover a failed check of any one group. A Decision Pause `Fix now`
96
+ * can put a group's fix in a new group, so that group is never verified again: the
97
+ * holistic verification judges every task, and the full test gate runs every group gate's suites.
98
+ */
99
+ const RESOLVED_BY_RUN: Readonly<Record<string, readonly string[]>> = {
100
+ "build/build-plan-verify": ["build-plan-verify-holistic"],
101
+ "build/build-group-gate": ["build-run-tests"],
102
+ "build/build-holistic-gate": ["build-run-tests"],
71
103
  };
72
104
 
73
105
  const RUN_TESTS = new Set(["build-run-tests", "debug-run-tests"]);
@@ -131,6 +163,133 @@ const taskGroupOf = (r: Row) => {
131
163
  return typeof taskGroup === "number" ? taskGroup : undefined;
132
164
  };
133
165
 
166
+ /** One consolidated documentation gap: a topic and gap key, with every distinct piece of evidence and action. */
167
+ interface DocWarning {
168
+ topic: string;
169
+ gap: string;
170
+ recommendedPath: string;
171
+ evidence: string[];
172
+ actions: string[];
173
+ }
174
+
175
+ const WARNING_FIELDS = [
176
+ "topic",
177
+ "gap",
178
+ "recommendedPath",
179
+ "alternativeEvidence",
180
+ "action",
181
+ ] as const;
182
+ /** Each field's length cap after folding to one line, in `WARNING_FIELDS` order. */
183
+ const WARNING_FIELD_MAX = [80, 80, 200, 400, 400] as const;
184
+ /** Raw inputs (`*-input-N.md`) are untrusted: never a source of warnings. */
185
+ const isRawInput = (rel: string) =>
186
+ /(^|\/)[a-z-]*-?input-[^/]*$/.test(rel) ||
187
+ /(^|\/)related-(issues|failures|deferrals)\.md$/.test(rel) ||
188
+ /(^|\/)context-related-[^/]*$/.test(rel);
189
+ /** Text between the untrusted-content markers is external data: never a source of warnings. */
190
+ const stripUntrusted = (text: string) => {
191
+ const open = /^[^\n]*={5} BEGIN UNTRUSTED ={5}/m.exec(text);
192
+ if (!open) return text;
193
+ // The fence ends at the LAST closing marker: any earlier closer inside the payload is forged.
194
+ const closers = [...text.matchAll(/^[^\n]*={5} END UNTRUSTED ={5}[^\n]*(?:\r?\n|$)/gm)].filter(
195
+ (m) => m.index >= open.index + open[0].length,
196
+ );
197
+ const last = closers.at(-1);
198
+ const end = last ? last.index + last[0].length : text.length;
199
+ return text.slice(0, open.index) + text.slice(end);
200
+ };
201
+
202
+ /**
203
+ * The top-level `{...}` objects in a fence body, in order. Each may span several lines (prettier
204
+ * rewrites a one-line record into that shape); braces inside strings are ignored. Text outside
205
+ * an object and an unterminated object are dropped.
206
+ */
207
+ function jsonObjectChunks(body: string): string[] {
208
+ const chunks: string[] = [];
209
+ let depth = 0;
210
+ let start = -1;
211
+ let inString = false;
212
+ let escaped = false;
213
+ for (let i = 0; i < body.length; i++) {
214
+ const ch = body[i]!;
215
+ if (inString) {
216
+ if (escaped) escaped = false;
217
+ else if (ch === "\\") escaped = true;
218
+ else if (ch === '"') inString = false;
219
+ continue;
220
+ }
221
+ if (ch === '"' && depth > 0) inString = true;
222
+ else if (ch === "{") {
223
+ if (depth === 0) start = i;
224
+ depth++;
225
+ } else if (ch === "}" && depth > 0) {
226
+ depth--;
227
+ if (depth === 0) chunks.push(body.slice(start, i + 1));
228
+ }
229
+ }
230
+ if (depth > 0) {
231
+ // An unterminated object must not swallow the records after it: rescan after its first line.
232
+ const nl = body.indexOf("\n", start);
233
+ if (nl !== -1) chunks.push(...jsonObjectChunks(body.slice(nl + 1)));
234
+ }
235
+ return chunks;
236
+ }
237
+
238
+ /**
239
+ * The structured records under `## Documentation Warnings` (JSON objects, one per line or pretty-printed, in a
240
+ * `jsonl` fence) of the run's own step artifacts, merged by normalised topic and gap. A missing
241
+ * section, a malformed line or a record without all five non-empty fields is skipped. Each
242
+ * field is folded to one line and capped (`oneLine`), and the path loses its backticks, so a
243
+ * record cannot add lines or markup to the summary.
244
+ */
245
+ function documentationWarnings(rows: Row[], read: (rel: string) => string | null): DocWarning[] {
246
+ const merged = new Map<string, DocWarning>();
247
+ const seenFiles = new Set<string>();
248
+ for (const row of rows) {
249
+ if (row.type !== "step-done") continue;
250
+ for (const rel of artifactsOf(row)) {
251
+ if (!rel.endsWith(".md") || isRawInput(rel) || seenFiles.has(rel)) continue;
252
+ seenFiles.add(rel);
253
+ const raw = read(rel);
254
+ if (raw === null) continue;
255
+ const text = stripUntrusted(raw);
256
+ const section = /^## Documentation Warnings[ \t]*\r?\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(
257
+ text,
258
+ );
259
+ const fence =
260
+ section === null
261
+ ? null
262
+ : /```jsonl[ \t]*\r?\n([\s\S]*?)(?:```|(?![\s\S]))/.exec(section[1]!);
263
+ if (fence === null) continue;
264
+ for (const chunk of jsonObjectChunks(fence[1]!)) {
265
+ const parsed = parseJson(chunk);
266
+ if (!parsed.ok) continue;
267
+ const value = parsed.value;
268
+ if (typeof value !== "object" || value === null || Array.isArray(value)) continue;
269
+ const rec = value as Record<string, unknown>;
270
+ const fields = WARNING_FIELDS.map((f) => rec[f]);
271
+ if (!fields.every((f): f is string => typeof f === "string" && f.trim() !== "")) continue;
272
+ const [topic, gap, path, evidence, action] = fields.map((f, i) =>
273
+ oneLine(f, WARNING_FIELD_MAX[i]),
274
+ );
275
+ const recommendedPath = path!.replace(/`/g, "").replace(/ {2,}/g, " ").trim();
276
+ const key = `${topic!.toLowerCase()}\u0000${gap!.toLowerCase()}`;
277
+ const found = merged.get(key) ?? {
278
+ topic: topic!.toLowerCase(),
279
+ gap: gap!.toLowerCase(),
280
+ recommendedPath: recommendedPath!,
281
+ evidence: [],
282
+ actions: [],
283
+ };
284
+ if (!found.evidence.includes(evidence!)) found.evidence.push(evidence!);
285
+ if (!found.actions.includes(action!)) found.actions.push(action!);
286
+ merged.set(key, found);
287
+ }
288
+ }
289
+ }
290
+ return [...merged.values()];
291
+ }
292
+
134
293
  /** The run's step rows grouped per step (and task group), in first-seen order. */
135
294
  function stepGroups(rows: Row[]): StepGroup[] {
136
295
  const groups = new Map<string, StepGroup>();
@@ -155,6 +314,37 @@ function stepGroups(rows: Row[]): StepGroup[] {
155
314
 
156
315
  const lastOf = (g: StepGroup) => g.rows.at(-1)!;
157
316
 
317
+ /** How a build pause, by its `From` header, settles the failed rows before it. */
318
+ interface PauseRule {
319
+ /** The loop question's title; every other item is a gap. */
320
+ loop: string;
321
+ /** The steps the pause settles when their last row before it ended FAIL. */
322
+ settles: readonly string[];
323
+ /** Settles the rows of the task group its `Group` header names, not the whole run's. */
324
+ grouped: boolean;
325
+ /** A `Fix now` gap settles once its `Fix task` is verified after the pause. */
326
+ fixNow: boolean;
327
+ /** The loop question, when asked, must be answered `Decide`; else any answer will do. */
328
+ loopDecide: boolean;
329
+ }
330
+
331
+ const PAUSE_RULES: Readonly<Record<string, PauseRule>> = {
332
+ verify: {
333
+ loop: "Verify",
334
+ settles: ["build-plan-tasks", "build-plan-verify", "build-plan-gaps-remediate"],
335
+ grouped: true,
336
+ fixNow: true,
337
+ loopDecide: false,
338
+ },
339
+ holistic: {
340
+ loop: "Holistic verify",
341
+ settles: ["build-plan-verify-holistic", "build-plan-gaps-remediate-holistic"],
342
+ grouped: false,
343
+ fixNow: false,
344
+ loopDecide: true,
345
+ },
346
+ };
347
+
158
348
  /** A level-2 section whose heading matches `title`, minus the template's non-content subsections. */
159
349
  function planSection(text: string, title: RegExp): string | undefined {
160
350
  const lines = text.split("\n");
@@ -219,9 +409,81 @@ export function buildSummary(input: SummaryInput): Summary {
219
409
  );
220
410
  }
221
411
 
412
+ // One rule for every verify and holistic pause (PAUSE_RULES): a pause answered in full
413
+ // settles the failed rows before it. Every gap is `Accept`, or (verify) a `Fix now` whose
414
+ // task was verified after the pause. An all-Accept pause whose `Source changed` header is
415
+ // present and not `false` settles nothing: source changed after the check the answers judged.
416
+ // The latest qualifying pause per task group (verify) or per run (holistic) settles.
417
+ const pauseSettled = new Set<string>();
418
+ if (workflow === "build") {
419
+ const latest = new Map<
420
+ string,
421
+ { rule: PauseRule; group: number | undefined; index: number; rel: string; how: string }
422
+ >();
423
+ input.rows.forEach((row, index) => {
424
+ if (row.type !== "step-done" || row.step !== "build-decision") return;
425
+ for (const rel of artifactsOf(row)) {
426
+ const text = read(rel);
427
+ if (text === null) continue;
428
+ const header = decisionHeader(text);
429
+ const rule = PAUSE_RULES[header.From ?? ""];
430
+ if (rule === undefined) continue;
431
+ const group = /^[0-9]+$/.test(header.Group ?? "") ? Number(header.Group) : undefined;
432
+ if (rule.grouped && group === undefined) continue;
433
+ const items = parseDecisionItems(text);
434
+ const gaps = items.filter((i) => i.title !== rule.loop);
435
+ const loop = items.filter((i) => i.title === rule.loop);
436
+ if (gaps.length === 0) continue;
437
+ const loopAnswered = (d: string | null) =>
438
+ rule.loopDecide ? /^Decide\b/.test(d ?? "") : d !== null;
439
+ if (!loop.every((i) => loopAnswered(i.decision))) continue;
440
+ const fixes = rule.fixNow ? gaps.filter((i) => /^Fix now\b/.test(i.decision ?? "")) : [];
441
+ if (!gaps.every((i) => fixes.includes(i) || /^Accept\b/.test(i.decision ?? ""))) continue;
442
+ let how = "every item accepted";
443
+ if (fixes.length === 0) {
444
+ const source = header["Source changed"];
445
+ if (source !== undefined && source !== "false") continue;
446
+ } else {
447
+ const fixTasks = fixes.map((i) => tasks.find((t) => t.task === i.fixTask));
448
+ if (fixTasks.some((t) => t === undefined || !taskVerified(input, t, index))) continue;
449
+ how = `task ${fixes.map((i) => i.fixTask).join(", ")} verified`;
450
+ }
451
+ const scope = rule.grouped ? `${header.From}#${group}` : String(header.From);
452
+ latest.set(scope, { rule, group: rule.grouped ? group : undefined, index, rel, how });
453
+ }
454
+ });
455
+ // Verify pauses list first, then holistic: the order the findings read in.
456
+ const pauses = Object.values(PAUSE_RULES).flatMap((rule) =>
457
+ [...latest.values()].filter((p) => p.rule === rule),
458
+ );
459
+ for (const pause of pauses)
460
+ for (const step of pause.rule.settles) {
461
+ const rows = input.rows
462
+ .map((row, index) => ({ row, index }))
463
+ .filter(
464
+ ({ row, index }) =>
465
+ row.type === "step-done" &&
466
+ row.step === step &&
467
+ (pause.group === undefined || taskGroupOf(row) === pause.group) &&
468
+ index < pause.index,
469
+ );
470
+ if (rows.at(-1)?.row.verdict !== "FAIL") continue;
471
+ const label = pause.group === undefined ? step : `${step} (group ${pause.group})`;
472
+ resolvedFindings.push(
473
+ `${label} FAIL, resolved by the Decision Pause (\`${pause.rel}\`), ${pause.how}`,
474
+ );
475
+ const g =
476
+ pause.group === undefined
477
+ ? groups.find((x) => x.step === step)
478
+ : groups.find((x) => x.key === `${step}#${pause.group}`);
479
+ if (g !== undefined && lastOf(g).index < pause.index) pauseSettled.add(g.key);
480
+ }
481
+ }
482
+
222
483
  for (const g of groups) {
223
484
  const { row, index } = lastOf(g);
224
485
  if (g.step === `${workflow}-summary`) continue;
486
+ if (pauseSettled.has(g.key) && row.verdict === "FAIL") continue;
225
487
  if (RUN_TESTS.has(g.step)) {
226
488
  if (row.verdict === "FAIL") fails.push(`${g.label} FAIL`);
227
489
  continue;
@@ -253,17 +515,30 @@ export function buildSummary(input: SummaryInput): Summary {
253
515
  : review || row.verdict === "FAIL"
254
516
  ? (RESOLVED_BY[`${workflow}/${g.step}`] ?? [])
255
517
  : [];
518
+ const runAnswers =
519
+ row.verdict === "FAIL" ? (RESOLVED_BY_RUN[`${workflow}/${g.step}`] ?? []) : [];
256
520
  const sub = taskGroupOf(row);
521
+ const needsScope = SAME_SCOPE.has(`${workflow}/${g.step}`);
522
+ const fixScope = needsScope
523
+ ? input.rows.find(
524
+ (r) =>
525
+ r.type === "step-done" &&
526
+ RUN_TESTS.has(String(r.step)) &&
527
+ r.attempt === row.attempt &&
528
+ typeof r.scope === "string",
529
+ )?.scope
530
+ : undefined;
257
531
  const answer = groups
258
532
  .map(lastOf)
259
533
  .find(
260
534
  ({ row: r, index: i }) =>
261
535
  i > index &&
262
- answers.includes(String(r.step)) &&
536
+ (answers.includes(String(r.step)) || runAnswers.includes(String(r.step))) &&
263
537
  (r.verdict === "PASS" || (review && r.verdict === "CONCERNS")) &&
264
538
  (r.failures === undefined || r.failures === 0) &&
265
- taskGroupOf(r) === sub &&
266
- (!review || r.attempt === row.attempt),
539
+ (WHOLE_RUN.has(String(r.step)) || taskGroupOf(r) === sub) &&
540
+ (!review || r.attempt === row.attempt) &&
541
+ (!needsScope || (fixScope !== undefined && r.scope === fixScope)),
267
542
  );
268
543
  if (answer !== undefined && spike) {
269
544
  const reports = artifactsOf(row).map((p) => read(p));
@@ -447,6 +722,26 @@ export function buildSummary(input: SummaryInput): Summary {
447
722
  );
448
723
  }
449
724
 
725
+ // Planned tests a later task took over (red entries with `from`), and the takeover tasks
726
+ // the build added itself (`build-takeover` rows).
727
+ if (workflow === "build") {
728
+ const handed = input.rows
729
+ .filter((r) => r.type === "step-done" && r.step === RED_STEP)
730
+ .flatMap((r) => redTestsOf(r))
731
+ .filter((t) => typeof t.from === "number");
732
+ const latest = new Map(handed.map((t) => [`${t.task}\0${t.test}\0${t.testName}`, t]));
733
+ const added = input.rows.filter((r) => r.type === "step-done" && r.step === TAKEOVER_STEP);
734
+ if (latest.size > 0 || added.length > 0) out.push("", "## Tests that changed hands", "");
735
+ for (const t of latest.values())
736
+ out.push(
737
+ `- TASK ${t.from} → TASK ${t.task}: \`${t.testName}\` ${handedWords(String(t.state))}`,
738
+ );
739
+ for (const r of added)
740
+ out.push(
741
+ `- TASK ${String(r.task)} added by the build: takes over \`${oneLine(String(r.name))}\` in \`${oneLine(String(r.test))}\` from TASK ${String(r.from)} — ${oneLine(String(r.reason ?? ""))}`,
742
+ );
743
+ }
744
+
450
745
  if (workflow === "plan") {
451
746
  const final = input.plans.at(-1)?.text ?? "";
452
747
  out.push(
@@ -499,6 +794,17 @@ export function buildSummary(input: SummaryInput): Summary {
499
794
  ...unconfirmed.map((u) => `- ${u}`),
500
795
  );
501
796
 
797
+ // Documentation warnings: advisory only, never part of the verdict.
798
+ const docWarnings = documentationWarnings(input.rows, read);
799
+ if (docWarnings.length > 0) {
800
+ out.push("", "## Documentation Warnings", "");
801
+ for (const w of docWarnings) {
802
+ out.push(`- **${w.topic}** (${w.gap}) — \`${w.recommendedPath}\``);
803
+ for (const e of w.evidence) out.push(` - Evidence: ${e}`);
804
+ for (const a of w.actions) out.push(` - Action: ${a}`);
805
+ }
806
+ }
807
+
502
808
  // Risks and action items.
503
809
  const items: string[] = [];
504
810
  for (const g of groups) {