@cbartens/bkit 5.5.1 → 6.1.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 (425) hide show
  1. package/.bkit/README.md +167 -154
  2. package/.bkit/core/.agents/context.md +95 -29
  3. package/.bkit/core/.agents/docs.md +18 -15
  4. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +1 -0
  5. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +6 -5
  6. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-readguard.cjs +1 -0
  7. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-rules.cjs +65 -0
  8. package/.bkit/core/.agents/rules.md +112 -102
  9. package/.bkit/core/.agents/skills.md +63 -15
  10. package/.bkit/core/.bkit/README.md +167 -154
  11. package/.bkit/core/.bkit/authoring.md +747 -0
  12. package/.bkit/core/.bkit/cli.md +407 -0
  13. package/.bkit/core/.bkit/cloud.md +283 -195
  14. package/.bkit/core/.bkit/comparison.md +45 -43
  15. package/.bkit/core/.bkit/install.md +166 -95
  16. package/.bkit/core/.bkit/jsonl.md +339 -196
  17. package/.bkit/core/.bkit/pipeline.md +142 -145
  18. package/.bkit/core/.bkit/prompts.md +295 -264
  19. package/.bkit/core/.bkit/providers.md +460 -277
  20. package/.bkit/core/.bkit/router.md +69 -0
  21. package/.bkit/core/.bkit/templates.md +530 -256
  22. package/.bkit/core/.bkit/trackers.md +116 -65
  23. package/.bkit/core/.bkit/workflows.md +742 -618
  24. package/.bkit/core/.claude/hooks/bkit-gateguard.cjs +2 -2
  25. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +3 -3
  26. package/.bkit/core/.claude/hooks/bkit-preflight.sh +45 -14
  27. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +3 -3
  28. package/.bkit/core/.codex/hooks/bkit-rules.cjs +57 -0
  29. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +7 -7
  30. package/.bkit/core/.cursor/hooks/bkit-preflight.sh +47 -12
  31. package/.bkit/core/.opencode/plugin/bkit-rules.js +89 -0
  32. package/.bkit/core/AGENTS.md +6 -80
  33. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +128 -130
  34. package/.bkit/core/docs/templates/bkit-audit-adoption.md +104 -94
  35. package/.bkit/core/docs/templates/bkit-audit-agents.md +96 -98
  36. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +100 -103
  37. package/.bkit/core/docs/templates/bkit-audit-analytics.md +141 -107
  38. package/.bkit/core/docs/templates/bkit-audit-annotations.md +99 -97
  39. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +122 -121
  40. package/.bkit/core/docs/templates/bkit-audit-app-store.md +158 -101
  41. package/.bkit/core/docs/templates/bkit-audit-architecture.md +114 -96
  42. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +76 -97
  43. package/.bkit/core/docs/templates/bkit-audit-config.md +123 -101
  44. package/.bkit/core/docs/templates/bkit-audit-cost.md +86 -99
  45. package/.bkit/core/docs/templates/bkit-audit-coverage.md +76 -93
  46. package/.bkit/core/docs/templates/bkit-audit-database.md +102 -95
  47. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +165 -108
  48. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +115 -109
  49. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +265 -113
  50. package/.bkit/core/docs/templates/bkit-audit-documentation.md +119 -118
  51. package/.bkit/core/docs/templates/bkit-audit-duplication.md +140 -111
  52. package/.bkit/core/docs/templates/bkit-audit-failures.md +111 -106
  53. package/.bkit/core/docs/templates/bkit-audit-flakes.md +100 -99
  54. package/.bkit/core/docs/templates/bkit-audit-gates.md +107 -103
  55. package/.bkit/core/docs/templates/bkit-audit-issues.md +105 -105
  56. package/.bkit/core/docs/templates/bkit-audit-llm.md +134 -85
  57. package/.bkit/core/docs/templates/bkit-audit-logs.md +124 -125
  58. package/.bkit/core/docs/templates/bkit-audit-models.md +99 -78
  59. package/.bkit/core/docs/templates/bkit-audit-privacy.md +56 -76
  60. package/.bkit/core/docs/templates/bkit-audit-prompts.md +63 -78
  61. package/.bkit/core/docs/templates/bkit-audit-red-team.md +125 -93
  62. package/.bkit/core/docs/templates/bkit-audit-reliability.md +97 -96
  63. package/.bkit/core/docs/templates/bkit-audit-repo.md +170 -98
  64. package/.bkit/core/docs/templates/bkit-audit-security.md +207 -121
  65. package/.bkit/core/docs/templates/bkit-audit-slop.md +78 -95
  66. package/.bkit/core/docs/templates/bkit-audit-testing.md +163 -139
  67. package/.bkit/core/docs/templates/bkit-audit-usability.md +114 -96
  68. package/.bkit/core/docs/templates/bkit-plan.md +158 -281
  69. package/.bkit/core/engine/checks/after/auth.ts +40 -37
  70. package/.bkit/core/engine/checks/after/ci-yml.ts +104 -31
  71. package/.bkit/core/engine/checks/after/github.ts +95 -17
  72. package/.bkit/core/engine/checks/after/index.ts +21 -8
  73. package/.bkit/core/engine/checks/after/suppression.ts +8 -5
  74. package/.bkit/core/engine/checks/after/tools.ts +125 -123
  75. package/.bkit/core/engine/checks/before/context-fetch.ts +227 -33
  76. package/.bkit/core/engine/checks/before/env.ts +3 -3
  77. package/.bkit/core/engine/checks/before/files.ts +5 -4
  78. package/.bkit/core/engine/checks/before/index.ts +25 -1
  79. package/.bkit/core/engine/checks/before/repo.ts +208 -2
  80. package/.bkit/core/engine/checks/status-holes.ts +916 -123
  81. package/.bkit/core/engine/checks/tips/catalogue.ts +82 -20
  82. package/.bkit/core/engine/checks/tips/detect.ts +66 -0
  83. package/.bkit/core/engine/checks/tips/index.ts +52 -11
  84. package/.bkit/core/engine/cli.ts +251 -130
  85. package/.bkit/core/engine/commands/analysis.ts +282 -199
  86. package/.bkit/core/engine/commands/ci/ci.ts +363 -29
  87. package/.bkit/core/engine/commands/ci/pins.ts +172 -0
  88. package/.bkit/core/engine/commands/ci/push-gate.ts +223 -0
  89. package/.bkit/core/engine/commands/comply.ts +77 -103
  90. package/.bkit/core/engine/commands/install/doctor.ts +2 -2
  91. package/.bkit/core/engine/commands/install/install.ts +57 -18
  92. package/.bkit/core/engine/commands/install/uninstall.ts +86 -55
  93. package/.bkit/core/engine/commands/install/upgrade.ts +32 -15
  94. package/.bkit/core/engine/commands/land.ts +139 -18
  95. package/.bkit/core/engine/commands/lib.ts +381 -22
  96. package/.bkit/core/engine/commands/registry.ts +10 -2
  97. package/.bkit/core/engine/commands/setup/setup.ts +8 -7
  98. package/.bkit/core/engine/commands/stats.ts +260 -0
  99. package/.bkit/core/engine/commands/tips.ts +10 -5
  100. package/.bkit/core/engine/commands/workflow/branches.ts +2215 -176
  101. package/.bkit/core/engine/commands/workflow/challenge.ts +748 -0
  102. package/.bkit/core/engine/commands/workflow/completeness.ts +109 -0
  103. package/.bkit/core/engine/commands/workflow/context.ts +1249 -47
  104. package/.bkit/core/engine/commands/workflow/counters.ts +483 -95
  105. package/.bkit/core/engine/commands/workflow/decisions.ts +585 -0
  106. package/.bkit/core/engine/commands/workflow/disk.ts +238 -56
  107. package/.bkit/core/engine/commands/workflow/fids.ts +811 -33
  108. package/.bkit/core/engine/commands/workflow/issues.ts +413 -64
  109. package/.bkit/core/engine/commands/workflow/ledgers.ts +1333 -36
  110. package/.bkit/core/engine/commands/workflow/locks.ts +28 -2
  111. package/.bkit/core/engine/commands/workflow/plan-blocks.ts +691 -0
  112. package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
  113. package/.bkit/core/engine/commands/workflow/plans.ts +257 -0
  114. package/.bkit/core/engine/commands/workflow/prs.ts +178 -33
  115. package/.bkit/core/engine/commands/workflow/repo.ts +66 -8
  116. package/.bkit/core/engine/commands/workflow/roadmap.ts +72 -22
  117. package/.bkit/core/engine/commands/workflow/run-facts.ts +492 -0
  118. package/.bkit/core/engine/commands/workflow/runs.ts +827 -79
  119. package/.bkit/core/engine/commands/workflow/runtime.ts +25 -1
  120. package/.bkit/core/engine/commands/workflow/skills.ts +1 -0
  121. package/.bkit/core/engine/commands/workflow/status.ts +329 -33
  122. package/.bkit/core/engine/commands/workflow/step-table.ts +381 -0
  123. package/.bkit/core/engine/commands/workflow/steps.ts +841 -105
  124. package/.bkit/core/engine/commands/workflow/summary-findings.ts +177 -0
  125. package/.bkit/core/engine/commands/workflow/summary.ts +544 -0
  126. package/.bkit/core/engine/commands/workflow/tasks.ts +409 -0
  127. package/.bkit/core/engine/commands/workflow/test-blocks.ts +254 -0
  128. package/.bkit/core/engine/commands/workflow/tests-changed.ts +201 -0
  129. package/.bkit/core/engine/commands/workflow/tests.ts +2124 -330
  130. package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
  131. package/.bkit/core/engine/commands/workflow/workflows.ts +1197 -235
  132. package/.bkit/core/engine/commands/workflow/worktrees.ts +543 -24
  133. package/.bkit/core/engine/install/cloud-env.ts +251 -121
  134. package/.bkit/core/engine/install/context-ci-workflow.ts +102 -0
  135. package/.bkit/core/engine/install/manifest.ts +67 -17
  136. package/.bkit/core/engine/install/modules/antigravity.ts +3 -2
  137. package/.bkit/core/engine/install/modules/cloud.ts +24 -16
  138. package/.bkit/core/engine/install/modules/codex.ts +15 -2
  139. package/.bkit/core/engine/install/modules/core.ts +1196 -45
  140. package/.bkit/core/engine/install/modules/cursor.ts +6 -6
  141. package/.bkit/core/engine/install/modules/opencode.ts +18 -6
  142. package/.bkit/core/engine/install/template-notes.ts +130 -0
  143. package/.bkit/core/engine/install/version-file.ts +9 -4
  144. package/.bkit/core/engine/install/write.ts +5 -0
  145. package/.bkit/core/engine/ledgers/compact.ts +124 -0
  146. package/.bkit/core/engine/ledgers/journal.ts +291 -0
  147. package/.bkit/core/engine/ledgers/migrate.ts +92 -0
  148. package/.bkit/core/engine/ledgers/status.ts +249 -21
  149. package/.bkit/core/engine/ledgers/telemetry.ts +1397 -253
  150. package/.bkit/core/engine/render/hosts.ts +118 -14
  151. package/.bkit/core/engine/render/models.ts +12 -0
  152. package/.bkit/core/engine/shared/bkit-latest.ts +26 -4
  153. package/.bkit/core/engine/shared/branches.ts +4 -1
  154. package/.bkit/core/engine/shared/dep-updater.ts +60 -0
  155. package/.bkit/core/engine/shared/egress.ts +8 -1
  156. package/.bkit/core/engine/shared/json.ts +25 -7
  157. package/.bkit/core/engine/shared/package-manager.ts +9 -0
  158. package/.bkit/core/engine/shared/settings.ts +243 -31
  159. package/.bkit/core/engine/shared/text.ts +361 -0
  160. package/.bkit/core/engine/shared/timeouts.ts +2 -0
  161. package/.bkit/core/engine/tools/cli-doc.ts +111 -0
  162. package/.bkit/core/engine/tools/grammar-density.ts +215 -0
  163. package/.bkit/core/engine/tools/instructions-sources.ts +832 -0
  164. package/.bkit/core/engine/tools/instructions.ts +1802 -0
  165. package/.bkit/core/hooks/antigravity-hook.js +25 -10
  166. package/.bkit/core/hooks/gateguard-engine.js +54 -29
  167. package/.bkit/core/hooks/guardrails-shell.js +4 -5
  168. package/.bkit/core/hooks/guardrails-tiers.js +10 -4
  169. package/.bkit/core/hooks/preflight-linear.sh +9 -9
  170. package/.bkit/core/hooks/preflight-rules.sh +8 -0
  171. package/.bkit/core/hooks/readguard-engine.js +29 -10
  172. package/.bkit/core/hooks/session-rules-advisory.js +61 -0
  173. package/.bkit/core/prompts/bkit-audit-generate.md +202 -94
  174. package/.bkit/core/prompts/bkit-build-challenge-1.md +76 -34
  175. package/.bkit/core/prompts/bkit-build-challenge-2.md +85 -38
  176. package/.bkit/core/prompts/bkit-build-install-skills.md +50 -28
  177. package/.bkit/core/prompts/bkit-build-plan-convert.md +85 -0
  178. package/.bkit/core/prompts/bkit-build-plan-current.md +59 -36
  179. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +101 -36
  180. package/.bkit/core/prompts/bkit-build-plan-tasks.md +149 -0
  181. package/.bkit/core/prompts/bkit-build-plan-tests.md +120 -0
  182. package/.bkit/core/prompts/bkit-build-plan-verify.md +104 -43
  183. package/.bkit/core/prompts/bkit-debug-abort-handover.md +47 -32
  184. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +109 -57
  185. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +65 -39
  186. package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +53 -31
  187. package/.bkit/core/prompts/bkit-debug-failure-soak.md +65 -34
  188. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +46 -31
  189. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +45 -31
  190. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +43 -30
  191. package/.bkit/core/prompts/bkit-design-generate.md +80 -46
  192. package/.bkit/core/prompts/bkit-design-organise.md +83 -32
  193. package/.bkit/core/prompts/bkit-design-review-1.md +70 -50
  194. package/.bkit/core/prompts/bkit-design-review-2.md +65 -46
  195. package/.bkit/core/prompts/bkit-design-spike.md +64 -40
  196. package/.bkit/core/prompts/bkit-design-update.md +53 -28
  197. package/.bkit/core/prompts/bkit-plan-generate.md +101 -29
  198. package/.bkit/core/prompts/bkit-plan-review-1.md +78 -41
  199. package/.bkit/core/prompts/bkit-plan-review-2.md +78 -35
  200. package/.bkit/core/prompts/bkit-plan-scope-check.md +116 -0
  201. package/.bkit/core/prompts/bkit-plan-update.md +86 -31
  202. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +94 -50
  203. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +91 -41
  204. package/.bkit/core/prompts/bkit-ship-update-docs.md +45 -24
  205. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +65 -49
  206. package/.bkit/core/prompts/bkit-utility-update-decisions.md +87 -42
  207. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +81 -37
  208. package/.bkit/core/prompts/bkit-utility-update-documentation.md +43 -25
  209. package/.bkit/core/prompts/bkit-utility-update-failures.md +84 -37
  210. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +88 -42
  211. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +92 -39
  212. package/.bkit/core/prompts/bkit-utility-update-tracker.md +159 -60
  213. package/.bkit/core/workflows/bkit-auto.md +89 -58
  214. package/.bkit/core/workflows/bkit-build.md +967 -517
  215. package/.bkit/core/workflows/bkit-debug.md +555 -387
  216. package/.bkit/core/workflows/bkit-design.md +319 -283
  217. package/.bkit/core/workflows/bkit-plan.md +319 -342
  218. package/.bkit/core/workflows/bkit-ship.md +525 -328
  219. package/.bkit/shared/.agents/plugins/bkit/hooks.json +10 -0
  220. package/.bkit/shared/.bkit/.env.example +2 -2
  221. package/.bkit/shared/.claude/bkit-cloud.md +12 -10
  222. package/.bkit/shared/.claude/settings.json +14 -0
  223. package/.bkit/shared/.codex/bkit-cloud.md +98 -0
  224. package/.bkit/shared/.codex/hooks.json +20 -0
  225. package/.bkit/shared/.cursor/bkit-cloud.md +3 -3
  226. package/.bkit/shared/.cursor/mcp.json +1 -1
  227. package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
  228. package/.bkit/shared/.gitattributes +1 -1
  229. package/.bkit/shared/.mcp.json +1 -1
  230. package/.bkit/shared/.opencode/opencode.json +12 -1
  231. package/.bkit/shared/CLAUDE.md +6 -2
  232. package/.bkit/shared/GEMINI.md +5 -2
  233. package/.bkit/shared/docs/architecture.md +4 -7
  234. package/.bkit/shared/docs/data-schema.md +4 -7
  235. package/.bkit/shared/docs/deployments.md +241 -168
  236. package/.bkit/shared/docs/design.md +11 -12
  237. package/.bkit/shared/docs/noise.md +8 -7
  238. package/.bkit/shared/docs/observability.md +5 -8
  239. package/.bkit/shared/docs/security.md +35 -17
  240. package/.bkit/shared/docs/setup.md +29 -18
  241. package/.bkit/shared/docs/technology.md +3 -6
  242. package/.bkit/shared/docs/testing.md +289 -174
  243. package/.bkit/shared/gitignore +6 -2
  244. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +15 -16
  245. package/.bkit/templates/.cursor/Dockerfile +12 -8
  246. package/.bkit/templates/.cursor/environment.json +1 -1
  247. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +10 -8
  248. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +45 -12
  249. package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +3 -3
  250. package/.bkit/templates/.github/renovate.json5 +34 -6
  251. package/.bkit/templates/.github/workflows/bkit-ci.yml +54 -51
  252. package/.bkit/templates/.github/workflows/bkit-cloud.yml +34 -33
  253. package/.bkit/templates/.github/workflows/bkit-health.yml +97 -0
  254. package/.bkit/templates/.github/workflows/bkit-renovate.yml +5 -4
  255. package/.bkit/templates/.github/workflows/bkit-trivy.yml +5 -4
  256. package/.bkit/templates/.husky/pre-commit +2 -2
  257. package/.bkit/templates/.husky/pre-push +96 -36
  258. package/.bkit/templates/.prettierignore +6 -0
  259. package/.bkit/templates/.vale.ini +27 -27
  260. package/.bkit/templates/context/bkit-cloudrun.md +23 -15
  261. package/.bkit/templates/context/bkit-expo.md +70 -52
  262. package/.bkit/templates/context/bkit-github.md +93 -56
  263. package/.bkit/templates/context/bkit-inngest.md +21 -15
  264. package/.bkit/templates/context/bkit-maestro.md +22 -16
  265. package/.bkit/templates/context/bkit-playwright.md +23 -17
  266. package/.bkit/templates/context/bkit-resend.md +12 -10
  267. package/.bkit/templates/context/bkit-sentry.md +30 -20
  268. package/.bkit/templates/context/bkit-serena.md +8 -7
  269. package/.bkit/templates/context/bkit-stripe.md +14 -13
  270. package/.bkit/templates/context/bkit-supabase.md +16 -13
  271. package/.bkit/templates/context/bkit-tavily.md +14 -11
  272. package/.bkit/templates/context/bkit-vercel.md +27 -18
  273. package/.bkit/templates/docs/capabilities.md +15 -14
  274. package/.bkit/templates/scripts/ci/{check-accepted-divergences.mjs → bkit-check-accepted-divergences.mjs} +6 -3
  275. package/.bkit/templates/scripts/ci/{check-accepted-divergences.test.mjs → bkit-check-accepted-divergences.test.mjs} +3 -3
  276. package/.bkit/templates/scripts/ci/{check-capstone.mjs → bkit-check-capstone.mjs} +2 -2
  277. package/.bkit/templates/scripts/ci/{check-capstone.test.mjs → bkit-check-capstone.test.mjs} +4 -4
  278. package/.bkit/templates/scripts/ci/{check-dependency-audit.mjs → bkit-check-dependency-audit.mjs} +103 -18
  279. package/.bkit/templates/scripts/ci/{check-dependency-audit.test.mjs → bkit-check-dependency-audit.test.mjs} +31 -3
  280. package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +387 -0
  281. package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +75 -0
  282. package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +160 -0
  283. package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.mjs → bkit-resolve-push-base.mjs} +3 -3
  284. package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.test.mjs → bkit-resolve-push-base.test.mjs} +4 -4
  285. package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +10 -2
  286. package/.bkit/templates/scripts/graphify/bkit-graph-drift.py +1 -1
  287. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +3 -3
  288. package/.bkit/templates/scripts/graphify/bkit-graph-embed.py +63 -0
  289. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +2 -2
  290. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +69 -18
  291. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -3
  292. package/.bkit/templates/scripts/graphify/bkit-graph-surface.py +1 -1
  293. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
  294. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +197 -126
  295. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +64 -41
  296. package/.bkit/templates/scripts/slop/bkit-slop-type-suppression.mjs +23 -7
  297. package/.bkit/templates/slop-scan.config.json +9 -2
  298. package/CHANGELOG.md +231 -0
  299. package/README.md +278 -89
  300. package/dist/checks/after/auth.js +36 -33
  301. package/dist/checks/after/ci-yml.js +91 -30
  302. package/dist/checks/after/github.js +91 -17
  303. package/dist/checks/after/index.js +22 -11
  304. package/dist/checks/after/suppression.js +8 -5
  305. package/dist/checks/after/tools.js +111 -114
  306. package/dist/checks/before/context-fetch.js +218 -33
  307. package/dist/checks/before/env.js +3 -3
  308. package/dist/checks/before/files.js +5 -3
  309. package/dist/checks/before/index.js +20 -3
  310. package/dist/checks/before/repo.js +197 -2
  311. package/dist/checks/status-holes.js +739 -114
  312. package/dist/checks/tips/catalogue.js +70 -19
  313. package/dist/checks/tips/detect.js +62 -0
  314. package/dist/checks/tips/index.js +51 -9
  315. package/dist/cli.js +234 -124
  316. package/dist/commands/analysis.js +174 -141
  317. package/dist/commands/ci/ci.js +302 -25
  318. package/dist/commands/ci/pins.js +142 -0
  319. package/dist/commands/ci/push-gate.js +194 -0
  320. package/dist/commands/comply.js +54 -91
  321. package/dist/commands/install/doctor.js +2 -2
  322. package/dist/commands/install/install.js +50 -19
  323. package/dist/commands/install/uninstall.js +82 -55
  324. package/dist/commands/install/upgrade.js +21 -11
  325. package/dist/commands/land.js +137 -17
  326. package/dist/commands/lib.js +295 -21
  327. package/dist/commands/registry.js +10 -2
  328. package/dist/commands/setup/setup.js +8 -7
  329. package/dist/commands/stats.js +175 -0
  330. package/dist/commands/tips.js +7 -3
  331. package/dist/commands/workflow/branches.js +1873 -152
  332. package/dist/commands/workflow/challenge.js +609 -0
  333. package/dist/commands/workflow/completeness.js +97 -0
  334. package/dist/commands/workflow/context.js +1045 -46
  335. package/dist/commands/workflow/counters.js +385 -86
  336. package/dist/commands/workflow/decisions.js +484 -0
  337. package/dist/commands/workflow/disk.js +214 -56
  338. package/dist/commands/workflow/fids.js +706 -33
  339. package/dist/commands/workflow/issues.js +349 -59
  340. package/dist/commands/workflow/ledgers.js +1123 -37
  341. package/dist/commands/workflow/locks.js +26 -2
  342. package/dist/commands/workflow/plan-blocks.js +501 -0
  343. package/dist/commands/workflow/plan-versions.js +22 -0
  344. package/dist/commands/workflow/plans.js +205 -0
  345. package/dist/commands/workflow/prs.js +154 -35
  346. package/dist/commands/workflow/repo.js +58 -8
  347. package/dist/commands/workflow/roadmap.js +58 -23
  348. package/dist/commands/workflow/run-facts.js +421 -0
  349. package/dist/commands/workflow/runs.js +670 -72
  350. package/dist/commands/workflow/runtime.js +15 -1
  351. package/dist/commands/workflow/skills.js +1 -0
  352. package/dist/commands/workflow/status.js +282 -34
  353. package/dist/commands/workflow/step-table.js +308 -0
  354. package/dist/commands/workflow/steps.js +703 -96
  355. package/dist/commands/workflow/summary-findings.js +117 -0
  356. package/dist/commands/workflow/summary.js +388 -0
  357. package/dist/commands/workflow/tasks.js +378 -0
  358. package/dist/commands/workflow/test-blocks.js +231 -0
  359. package/dist/commands/workflow/tests-changed.js +172 -0
  360. package/dist/commands/workflow/tests.js +1695 -305
  361. package/dist/commands/workflow/tracker.js +983 -0
  362. package/dist/commands/workflow/workflows.js +1014 -222
  363. package/dist/commands/workflow/worktrees.js +432 -26
  364. package/dist/install/cloud-env.js +233 -99
  365. package/dist/install/context-ci-workflow.js +85 -0
  366. package/dist/install/manifest.js +64 -17
  367. package/dist/install/modules/antigravity.js +3 -2
  368. package/dist/install/modules/cloud.js +25 -16
  369. package/dist/install/modules/codex.js +12 -2
  370. package/dist/install/modules/core.js +1090 -48
  371. package/dist/install/modules/cursor.js +6 -6
  372. package/dist/install/modules/opencode.js +13 -7
  373. package/dist/install/template-notes.js +116 -0
  374. package/dist/install/version-file.js +9 -4
  375. package/dist/ledgers/compact.js +87 -0
  376. package/dist/ledgers/journal.js +233 -0
  377. package/dist/ledgers/migrate.js +81 -0
  378. package/dist/ledgers/status.js +176 -13
  379. package/dist/ledgers/telemetry.js +1010 -125
  380. package/dist/render/hosts.js +104 -14
  381. package/dist/render/models.js +12 -0
  382. package/dist/shared/bkit-latest.js +26 -4
  383. package/dist/shared/branches.js +3 -1
  384. package/dist/shared/dep-updater.js +49 -0
  385. package/dist/shared/egress.js +8 -1
  386. package/dist/shared/json.js +20 -7
  387. package/dist/shared/package-manager.js +6 -0
  388. package/dist/shared/settings.js +181 -24
  389. package/dist/shared/text.js +333 -0
  390. package/dist/shared/timeouts.js +2 -0
  391. package/dist/tools/cli-doc.js +97 -0
  392. package/dist/tools/grammar-density.js +183 -0
  393. package/dist/tools/instructions-sources.js +720 -0
  394. package/dist/tools/instructions.js +1623 -0
  395. package/package.json +156 -51
  396. package/.bkit/core/.bkit/lite.md +0 -73
  397. package/.bkit/core/engine/commands/harvest.ts +0 -459
  398. package/.bkit/core/engine/commands/workflow/workstreams.ts +0 -166
  399. package/.bkit/core/engine/tools/wording.ts +0 -748
  400. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
  401. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
  402. package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
  403. package/.bkit/core/prompts/bkit-build-plan-execute.md +0 -76
  404. package/.bkit/core/prompts/bkit-build-summary.md +0 -94
  405. package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
  406. package/.bkit/core/prompts/bkit-design-summary.md +0 -107
  407. package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
  408. package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
  409. package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
  410. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
  411. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
  412. package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
  413. package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
  414. package/.bkit/templates/scripts/ci/bkit-local-stack-lock.sh +0 -194
  415. package/dist/commands/harvest.js +0 -353
  416. package/dist/commands/workflow/workstreams.js +0 -143
  417. package/dist/tools/wording.js +0 -680
  418. /package/.bkit/templates/.vale/styles/{House → Bkit}/Filler.yml +0 -0
  419. /package/.bkit/templates/.vale/styles/{House → Bkit}/Hedging.yml +0 -0
  420. /package/.bkit/templates/.vale/styles/{House → Bkit}/LLMSlop.yml +0 -0
  421. /package/.bkit/templates/.vale/styles/{House → Bkit}/Verbose.yml +0 -0
  422. /package/.bkit/templates/scripts/ci/{accepted-advisories.json → bkit-accepted-advisories.json} +0 -0
  423. /package/.bkit/templates/scripts/ci/{accepted-divergences.json → bkit-accepted-divergences.json} +0 -0
  424. /package/.bkit/templates/scripts/launchd/{launchd.env.example → bkit-launchd.env.example} +0 -0
  425. /package/.bkit/templates/scripts/launchd/{ai.bkit.launchd.plist → bkit-launchd.plist} +0 -0
@@ -1,6 +1,7 @@
1
- // bkit fids check|parse|find — feature-id format per tracker, recovering a FID
2
- // from a branch name or a PR-body marker, and finding the feature already logged
3
- // for an issue.
1
+ // bkit fids check|parse|resolve|plans|design|find — feature-id format per tracker,
2
+ // the issue and FID a session prompt names, recovering a FID from a branch name or a
3
+ // PR-body marker, the one FID chain Step 1 resolves, a feature's plan files and its
4
+ // plan inputs, and finding the feature already logged for an issue.
4
5
  //
5
6
  // A FID names the branch (`feat/{FID}`), the log folder and every artifact, so
6
7
  // it is checked before first use. Its shape follows the tracker that minted it:
@@ -9,12 +10,26 @@
9
10
  // jira {project}-{N}-{slug} ^[a-z][a-z0-9]+-[0-9]+-[a-z0-9-]+$ (issue key lowercased first)
10
11
  // none any slug ^[a-z0-9][a-z0-9-]*$ (no tracker shape; still path-safe)
11
12
  // any any tracker's shape ^([0-9]+|[a-z][a-z0-9]*-[0-9]+)-[a-z0-9-]+$ (auto's CI_DEV allowlist)
13
+ // A run with no issue carries an issue-less FID under every tracker. One minted from a
14
+ // prompt is a slug with no all-digit word (`dev-ci-failures`), so it can never parse as an
15
+ // issue id; one taken verbatim from the branch (`feat/upgrade-react-19`) or the prompt is
16
+ // any slug.
17
+ //
18
+ // Minting (`fids resolve`): `{issue}-{slug}` with an issue (Linear / Jira key lowercased),
19
+ // `{branch-suffix}-{slug}` without one. The slug is the first three words of the issue
20
+ // title (the prompt when the title has none, the workflow name when neither has any),
21
+ // ASCII-folded and lowercased, with `STOPWORDS` and all-digit words dropped. The branch
22
+ // suffix is the last `/` segment of the current branch, all-digit words dropped; it does
23
+ // not count toward the three words.
12
24
  import * as fs from "node:fs";
13
25
  import * as path from "node:path";
14
26
  import { parseIssueTracker } from "../../install/manifest.js";
15
- import { CommandError, EXIT, git, repoRoot } from "../lib.js";
27
+ import { CommandError, EXIT, git, parseJson, repoRoot, statusRelPath, } from "../lib.js";
16
28
  import { readBkitConfig } from "../../shared/settings.js";
17
- import { str } from "./status.js";
29
+ import { originOwnerRepo } from "./repo.js";
30
+ import { lastRun } from "../../ledgers/status.js";
31
+ import { monthBuckets, readRunsLenient } from "./locks.js";
32
+ import { WORKFLOW_FLAG, str } from "./status.js";
18
33
  export const FID_PATTERNS = {
19
34
  github: /^[0-9]+-[a-z0-9-]+$/,
20
35
  linear: /^[a-z]+-[0-9]+-[a-z0-9-]+$/,
@@ -28,10 +43,59 @@ const KEYED = new Set(["linear", "jira"]);
28
43
  const ISSUE_KEY = { linear: /^[A-Z]+-[0-9]+$/, jira: /^[A-Z][A-Z0-9]+-[0-9]+$/ };
29
44
  /** The slug every recovered FID must pass before it touches a path (auto's branch fallback). */
30
45
  const SLUG = FID_PATTERNS.none;
46
+ /** An issue-less FID: a slug with no all-digit `-`-separated word, so it never parses as an issue id. */
47
+ export const ISSUE_LESS_FID = /^(?!.*(?:^|-)[0-9]+(?:-|$))[a-z0-9][a-z0-9-]*$/;
48
+ /** The issue id each wired tracker mints (`#` stripped; linear and jira keys are uppercase). */
49
+ export const ISSUE_ID_PATTERNS = {
50
+ github: /^[0-9]+$/,
51
+ linear: /^[A-Z]+-[0-9]+$/,
52
+ jira: /^[A-Z][A-Z0-9]+-[0-9]+$/,
53
+ };
54
+ /**
55
+ * The problem with a FID for the tracker and the run's issue, or undefined when it is valid.
56
+ * `issue` absent: the tracker's FID shape alone. A non-empty `issue`: the issue id and the
57
+ * FID both match the tracker, and the issue id the FID embeds is that issue. An empty
58
+ * `issue` (a run with no issue): the FID is any slug (a minted one is held to
59
+ * `ISSUE_LESS_FID` by `fids resolve`). The `none` tracker has no issue-id shape, so `issue`
60
+ * is ignored.
61
+ */
62
+ export function fidProblem(fid, tracker, issue) {
63
+ const shape = FID_PATTERNS[tracker];
64
+ const shapeProblem = shape.test(fid)
65
+ ? undefined
66
+ : `FID "${fid}" does not match the ${tracker} shape ${shape.source}`;
67
+ if (issue === undefined || tracker === "none")
68
+ return shapeProblem;
69
+ if (issue === "") {
70
+ return SLUG.test(fid)
71
+ ? undefined
72
+ : `FID "${fid}" is not a slug (${SLUG.source}): a run with no issue needs a lowercase slug`;
73
+ }
74
+ const idShapes = tracker === "any" ? Object.values(ISSUE_ID_PATTERNS) : [ISSUE_ID_PATTERNS[tracker]];
75
+ if (!idShapes.some((re) => re.test(issue))) {
76
+ return `issue "${issue}" is not a ${tracker} issue id`;
77
+ }
78
+ if (shapeProblem !== undefined)
79
+ return shapeProblem;
80
+ const embedded = issueIdOf(fid, tracker);
81
+ return embedded === issue
82
+ ? undefined
83
+ : `FID "${fid}" embeds issue ${embedded ?? "none"}, not the run's issue ${issue}`;
84
+ }
31
85
  /** Exit code: no FID could be recovered from the marker or the branch. */
32
86
  export const EXIT_NO_FID = 3;
33
87
  /** Exit code (find): more than one feature is logged for the issue. */
34
88
  export const EXIT_SEVERAL = 4;
89
+ /** Exit code (resolve): the minted name and every suffix of it are used. */
90
+ export const EXIT_NO_FREE = 5;
91
+ /** Exit code: a file a flag names is missing. */
92
+ export const EXIT_NO_FILE = 7;
93
+ /** Exit code (parse --prompt-file): the prompt names more than one issue. */
94
+ export const EXIT_AMBIGUOUS = 8;
95
+ /** Exit code (resolve): the prompt holds only a bare number, so the FID would mint from the workflow name. */
96
+ export const EXIT_BARE_NUMBER = 9;
97
+ /** The stop message for a prompt that does not say which issue it means. */
98
+ const NAME_THE_ISSUE = "name the issue as #N, its key or its URL";
35
99
  /**
36
100
  * Features already logged for an issue: every `docs/plans/{YYYYMM}/logs/{issue}-*`
37
101
  * folder, the issue id lowercased (a Linear or Jira FID carries it lowercased). Sorted, unique.
@@ -53,6 +117,300 @@ export function logged(root, issue) {
53
117
  }
54
118
  return [...found].sort();
55
119
  }
120
+ /** Suffixes tried after a minted name that an earlier run used: `-b` … `-z`. */
121
+ const MINT_SUFFIXES = [..."bcdefghijklmnopqrstuvwxyz"];
122
+ /**
123
+ * The FID a minted issue-less run takes: `fid` itself, or the first of `fid-b`, `fid-c`, ...
124
+ * that no earlier run used. A name is used when it has a log folder (any month bucket) in
125
+ * one of `roots` whose last `workflow` run is not IN_PROGRESS; an in-progress one is
126
+ * continued. null when every name is used.
127
+ */
128
+ export function freeFid(roots, fid, workflow) {
129
+ for (const name of [fid, ...MINT_SUFFIXES.map((x) => `${fid}-${x}`)]) {
130
+ let used = false;
131
+ for (const root of roots) {
132
+ for (const month of monthBuckets(root, name)) {
133
+ const run = lastRun(readRunsLenient(path.join(root, statusRelPath(month, name))), workflow);
134
+ if (run?.status === "IN_PROGRESS")
135
+ return name;
136
+ used = true;
137
+ }
138
+ }
139
+ if (!used)
140
+ return name;
141
+ }
142
+ return null;
143
+ }
144
+ /** A file a flag names, or exit 7 when it is missing. */
145
+ function readNamed(file, flag) {
146
+ if (!fs.existsSync(file) || !fs.statSync(file).isFile())
147
+ throw new CommandError(EXIT_NO_FILE, `--${flag}: no file at ${file}`);
148
+ return fs.readFileSync(file, "utf-8");
149
+ }
150
+ /** The issue title a `--title-file` holds: a JSON object's `title`, else the text itself. */
151
+ export function titleOf(text) {
152
+ const parsed = parseJson(text);
153
+ if (parsed.ok && typeof parsed.value === "object" && parsed.value !== null) {
154
+ const title = parsed.value.title;
155
+ if (typeof title === "string")
156
+ return title;
157
+ }
158
+ return text.trim();
159
+ }
160
+ /** English words a minted slug drops. */
161
+ export const STOPWORDS = new Set(("a about after all also an and any are as at be been before being but by can could " +
162
+ "did do does doing for from had has have he her his how i if in into is it its just " +
163
+ "let me more most my no nor not now of off on once only or other our out over per " +
164
+ "please same she should so some such than that the their them then there these they " +
165
+ "this those through to too under until up us very via was we were what when where " +
166
+ "which while who why will with would you your").split(" "));
167
+ /**
168
+ * The slug words of free text in order: URLs, `<tags>` and `/commands` removed, letters
169
+ * folded to ASCII, lowercased, split on anything else; stopwords and all-digit words dropped.
170
+ */
171
+ export function slugWords(text) {
172
+ return text
173
+ .replace(/\S+:\/\/\S+/g, " ")
174
+ .replace(/<[^>]*>/g, " ")
175
+ .replace(/(^|\s)\/\S+/g, " ")
176
+ .normalize("NFKD")
177
+ .replace(/[\u0300-\u036f]/g, "")
178
+ .toLowerCase()
179
+ .split(/[^a-z0-9]+/)
180
+ .filter((w) => w !== "" && !STOPWORDS.has(w) && !/^[0-9]+$/.test(w));
181
+ }
182
+ /** The FID a run mints; see the header comment for the rules. */
183
+ export function mintFid(o) {
184
+ const fromTitle = slugWords(o.title ?? "");
185
+ const words = (fromTitle.length > 0 ? fromTitle : slugWords(o.prompt)).slice(0, 3);
186
+ const slug = (words.length > 0 ? words : [o.workflow ?? "feature"]).join("-");
187
+ if (o.issue !== "")
188
+ return `${o.issue.replace(/^#/, "").toLowerCase()}-${slug}`;
189
+ const suffix = (o.branch ?? "")
190
+ .split("/")
191
+ .at(-1)
192
+ .toLowerCase()
193
+ .split(/[^a-z0-9]+/)
194
+ .filter((w) => w !== "" && !/^[0-9]+$/.test(w));
195
+ return [...suffix, slug].join("-");
196
+ }
197
+ const MONTH = /^[0-9]{6}$/;
198
+ /** Every `docs/plans/{YYYYMM}/logs/{name}` folder name under the roots. */
199
+ function loggedNames(roots) {
200
+ const names = new Set();
201
+ for (const root of roots) {
202
+ const plans = path.join(root, "docs", "plans");
203
+ if (!fs.existsSync(plans))
204
+ continue;
205
+ for (const month of fs.readdirSync(plans).filter((m) => MONTH.test(m))) {
206
+ const logs = path.join(plans, month, "logs");
207
+ if (!fs.existsSync(logs))
208
+ continue;
209
+ for (const name of fs.readdirSync(logs)) {
210
+ if (fs.statSync(path.join(logs, name)).isDirectory())
211
+ names.add(name);
212
+ }
213
+ }
214
+ }
215
+ return names;
216
+ }
217
+ /** Features logged for an issue on `origin/dev` (else local `dev`), read from git, not the working tree. */
218
+ export function loggedOnDev(cwd, issue) {
219
+ const ref = git(cwd, ["rev-parse", "--verify", "-q", "origin/dev"]) ? "origin/dev" : "dev";
220
+ const out = git(cwd, ["ls-tree", "-r", "-d", "--name-only", ref, "--", "docs/plans"]);
221
+ if (!out)
222
+ return [];
223
+ const key = `${issue.replace(/^#/, "").toLowerCase()}-`;
224
+ const found = new Set();
225
+ for (const line of out.split("\n")) {
226
+ const m = /^docs\/plans\/[0-9]{6}\/logs\/([^/]+)$/.exec(line.trim());
227
+ if (m && m[1].startsWith(key))
228
+ found.add(m[1]);
229
+ }
230
+ return [...found].sort();
231
+ }
232
+ function hits(text, re, map) {
233
+ const out = [];
234
+ for (const m of text.matchAll(re)) {
235
+ const value = map(m);
236
+ if (value !== null)
237
+ out.push({ value, at: m.index });
238
+ }
239
+ return out;
240
+ }
241
+ /** The line text before a `#N` ends in a CSS colour property (`color: `, `background-color: `). */
242
+ const CSS_COLOUR_LEAD = /(?:colou?r|background|border|fill|stroke|outline|shadow)[\w-]*\s*:\s*$/i;
243
+ /** A `#N` hit that is a 3- or 6-digit CSS colour (`color: #123456`), not an issue. */
244
+ function cssColour(text, h) {
245
+ if (h.value.length !== 3 && h.value.length !== 6)
246
+ return false;
247
+ return CSS_COLOUR_LEAD.test(text.slice(text.lastIndexOf("\n", h.at) + 1, h.at));
248
+ }
249
+ const byPosition = (a, b) => a.at - b.at;
250
+ /** Start and end of every match of `re` in `text`. */
251
+ const spans = (text, re) => [...text.matchAll(re)].map((m) => [m.index, m.index + m[0].length]);
252
+ /** The host of a URL or bare host, lowercased: `https://Acme.atlassian.net/` -> `acme.atlassian.net`. */
253
+ const hostOf = (site) => site
254
+ .replace(/^[a-z][a-z0-9+.-]*:\/\//i, "")
255
+ .split("/")[0]
256
+ .toLowerCase();
257
+ /** A URL in prose: a bare key or `#N` inside one is part of the URL, not a mention. */
258
+ const ANY_URL = /\b[a-z][a-z0-9+.-]*:\/\/\S+/gi;
259
+ /**
260
+ * Every issue reference the prompt makes for the tracker, in text order (ids may repeat),
261
+ * split by form. `explicit`: an `<id>` / `<{tracker}_issue>` tag, a labelled form
262
+ * (`GitHub issue: #N`, `issue #N`, `issue ABC-12`, `ISSUE-N`), or a tracker issue URL /
263
+ * `owner/repo#N` pointing at this repo / team / site (`scope`). `bare`: a `#N` (a CSS
264
+ * colour after `color:` and the like dropped), `owner/repo#N` with no origin to compare,
265
+ * or a bare Linear / Jira key carrying the `scope.key` prefix; with no prefix configured a
266
+ * bare key never counts and lands in `skipped` instead. A tracker URL or `owner/repo#N`
267
+ * pointing elsewhere counts as neither, and a key or `#N` inside any URL is never bare.
268
+ */
269
+ export function issueRefs(text, tracker, scope = {}) {
270
+ const id = (m) => m[1];
271
+ const upper = (m) => {
272
+ const k = m[1].toUpperCase();
273
+ return k.startsWith("ISSUE-") && !/^ISSUE-[0-9]+$/.test(k) ? null : k;
274
+ };
275
+ const prefix = scope.key ? `${scope.key.toUpperCase()}-` : null;
276
+ let explicit;
277
+ let bare;
278
+ let skipped = [];
279
+ let urlForm;
280
+ if (tracker === "github") {
281
+ // With no origin to compare against, a URL to any repo counts and `owner/repo#N` stays bare.
282
+ const ours = scope.ownerRepo?.toLowerCase() ?? null;
283
+ const isOurs = (m) => m[1].toLowerCase() === ours;
284
+ urlForm = /https?:\/\/[^\s/]+\/([^\s/]+\/[^\s/]+)\/issues\/([0-9]+)(?![\w])/g;
285
+ const shortRef = /(?<![\w&#/])([\w.-]+\/[\w.-]+)#([0-9]+)(?![\w-])/g;
286
+ const inShortRef = spans(text, shortRef);
287
+ explicit = [
288
+ ...hits(text, /<id>\s*#?([0-9]+)\s*<\/id>/gi, id),
289
+ ...hits(text, /<github_issue>\s*#?([0-9]+)\s*<\/github_issue>/gi, id),
290
+ ...hits(text, /GitHub issue:\s*#?([0-9]+)\b/gi, id),
291
+ ...hits(text, /\bissue:?\s*#([0-9]+)\b/gi, id),
292
+ ...hits(text, /\bISSUE-([0-9]+)\b/g, id),
293
+ ...hits(text, urlForm, (m) => (ours === null || isOurs(m) ? m[2] : null)),
294
+ ...hits(text, shortRef, (m) => (ours !== null && isOurs(m) ? m[2] : null)),
295
+ ];
296
+ bare = [
297
+ ...hits(text, /(?<![\w&#/])#([0-9]+)(?![\w-])/g, id).filter((h) => !cssColour(text, h) && !inShortRef.some(([from, to]) => h.at >= from && h.at < to)),
298
+ ...hits(text, shortRef, (m) => (ours === null ? m[2] : null)),
299
+ ];
300
+ }
301
+ else if (tracker === "linear" || tracker === "jira") {
302
+ const k = tracker === "linear" ? "[A-Za-z]+-[0-9]+" : "[A-Za-z][A-Za-z0-9]+-[0-9]+";
303
+ const plain = tracker === "linear" ? "[A-Z]+-[0-9]+" : "[A-Z][A-Z0-9]+-[0-9]+";
304
+ // bkit has no Linear workspace setting, so a Linear URL is matched on the team key alone.
305
+ // With no team / project / site configured, that part of the URL is not compared.
306
+ const site = tracker === "jira" && scope.site ? hostOf(scope.site) : null;
307
+ urlForm =
308
+ tracker === "linear"
309
+ ? new RegExp(`()linear\\.app\\/[^\\s/]+\\/issue\\/(${k})`, "gi")
310
+ : new RegExp(`(?:[a-z][a-z0-9+.-]*:\\/\\/)?([^\\s/]+)(?:\\/\\S*?)?\\/browse\\/(${k})`, "gi");
311
+ const ourUrl = (m) => {
312
+ const key = m[2].toUpperCase();
313
+ if (prefix !== null && !key.startsWith(prefix))
314
+ return null;
315
+ if (site !== null && m[1].toLowerCase() !== site)
316
+ return null;
317
+ return key;
318
+ };
319
+ explicit = [
320
+ ...hits(text, new RegExp(`<id>\\s*(${k})\\s*<\\/id>`, "gi"), upper),
321
+ ...hits(text, new RegExp(`<${tracker}_issue>\\s*(${k})\\s*<\\/${tracker}_issue>`, "gi"), upper),
322
+ ...hits(text, new RegExp(`${tracker} issue:\\s*(${k})\\b`, "gi"), upper),
323
+ ...hits(text, new RegExp(`\\b[Ii]ssue:?\\s+(${plain})\\b`, "g"), upper),
324
+ ...hits(text, new RegExp(`\\bISSUE-(${plain})\\b`, "g"), upper),
325
+ ...hits(text, urlForm, ourUrl),
326
+ ];
327
+ bare = hits(text, new RegExp(`(?<![\\w-])(${plain})(?![\\w-])`, "g"), upper);
328
+ if (prefix === null) {
329
+ skipped = bare;
330
+ bare = [];
331
+ }
332
+ else {
333
+ bare = bare.filter((h) => h.value.startsWith(prefix));
334
+ }
335
+ }
336
+ else {
337
+ return { explicit: [], bare: [], skipped: [] };
338
+ }
339
+ const urls = [...spans(text, ANY_URL), ...spans(text, urlForm)];
340
+ const outsideUrls = (h) => !urls.some(([from, to]) => h.at >= from && h.at < to);
341
+ const shape = ISSUE_ID_PATTERNS[tracker];
342
+ const keep = (list) => list.filter((h) => shape.test(h.value)).sort(byPosition);
343
+ return {
344
+ explicit: keep(explicit),
345
+ bare: keep(bare.filter(outsideUrls)),
346
+ skipped: keep(skipped.filter(outsideUrls)),
347
+ };
348
+ }
349
+ /** The issues a prompt names: the distinct explicit ids, else the distinct bare ones, in text order. */
350
+ export function issueCandidates(refs) {
351
+ const pool = refs.explicit.length > 0 ? refs.explicit : refs.bare;
352
+ return [...new Set(pool.map((h) => h.value))];
353
+ }
354
+ /** All-digit words a prompt holds outside URLs, tags, `/commands` and `#N`: an issue typed without its `#`. */
355
+ export function bareNumbers(text) {
356
+ const plain = text
357
+ .replace(/\S+:\/\/\S+/g, " ")
358
+ .replace(/<[^>]*>/g, " ")
359
+ .replace(/(^|\s)\/\S+/g, " ");
360
+ return [...plain.matchAll(/(?<![\w#/.-])([0-9]+)(?![\w/.-])/g)].map((m) => m[1]);
361
+ }
362
+ /** The stderr hint for a bare number: how to write it so it names the issue. */
363
+ function bareNumberHint(n, tracker, key) {
364
+ const write = tracker === "github" ? `#${n}` : `its issue key (${key ?? "KEY"}-${n})`;
365
+ return `${n} reads as a bare number; write ${write}`;
366
+ }
367
+ /** The FID a prompt names explicitly: `feat/` and `docs/plans/` paths always, a bare word only when `logs/{word}/` exists. */
368
+ export function namedFid(text, roots) {
369
+ const fid = (m) => {
370
+ const f = m[1].replace(/-+$/, "");
371
+ return SLUG.test(f) ? f : null;
372
+ };
373
+ const logged = loggedNames(roots);
374
+ const found = [
375
+ ...hits(text, /\bfeat\/([a-z0-9][a-z0-9-]*)/g, fid),
376
+ ...hits(text, /docs\/plans\/[0-9]{6}\/logs\/([a-z0-9][a-z0-9-]*)/g, fid),
377
+ ...hits(text, /docs\/plans\/[0-9]{6}\/([a-z0-9][a-z0-9-]*?)-(?:design|plan)(?:-[0-9]+)?\.md/g, fid),
378
+ ...hits(text, /(?<![\w/-])([a-z0-9][a-z0-9-]*[a-z0-9])(?![\w/-])/g, (m) => logged.has(m[1]) ? m[1] : null),
379
+ ].sort((a, b) => a.at - b.at);
380
+ return found[0]?.value ?? null;
381
+ }
382
+ /** `#N` for GitHub, the key itself for Linear and Jira, "" with no issue. */
383
+ export const issueRef = (issue, tracker) => issue === "" ? "" : tracker === "github" ? `#${issue}` : issue;
384
+ /** A feature's plan in a month bucket, as ship reads it: `{FID}-plan.md`, or none. */
385
+ export function planFiles(root, fid, month) {
386
+ const name = `${fid}-plan.md`;
387
+ return fs.existsSync(path.join(root, "docs", "plans", month, name))
388
+ ? { source: "single", plan: `docs/plans/${month}/${name}` }
389
+ : { source: "none", plan: null };
390
+ }
391
+ /** The `**Parent design:**` link target's FID and month in the text, or null. */
392
+ export function parentDesignLink(text) {
393
+ const m = /\*\*Parent design:\*\*[^\n]*?docs\/plans\/([0-9]{6})\/([a-z0-9][a-z0-9-]*)-design\.md/.exec(text);
394
+ return m ? { month: m[1], fid: m[2] } : null;
395
+ }
396
+ /** The `WS-{N}` ids on the first `**Workstreams:**` line in the texts; [] when none. */
397
+ export function workstreamIds(...texts) {
398
+ for (const text of texts) {
399
+ const line = /\*\*Workstreams:\*\*([^\n]*)/.exec(text)?.[1];
400
+ if (line !== undefined)
401
+ return [...new Set(line.match(/WS-\d+/g) ?? [])];
402
+ }
403
+ return [];
404
+ }
405
+ /** Every `docs/audits/{YYYYMM}/*.md` path in the texts, first mention order, unique. */
406
+ export function auditPaths(...texts) {
407
+ const seen = new Set();
408
+ for (const text of texts) {
409
+ for (const m of text.matchAll(/docs\/audits\/[0-9]{6}\/[A-Za-z0-9._-]+\.md/g))
410
+ seen.add(m[0]);
411
+ }
412
+ return [...seen];
413
+ }
56
414
  /**
57
415
  * The canonical design doc for a feature, `docs/plans/{YYYYMM}/{fid}-design.md`: the
58
416
  * `month` bucket first, else the newest bucket holding one. null when none exists.
@@ -70,10 +428,43 @@ export function designDoc(root, fid, month) {
70
428
  const hit = month !== undefined && months.includes(month) && at(month) ? month : months.find(at);
71
429
  return hit === undefined ? null : { month: hit, path: `docs/plans/${hit}/${fid}-design.md` };
72
430
  }
73
- /** `package.json` `bkit.issueTracker` at the main checkout (cwd outside git); default `none`. */
74
- export function readIssueTracker(cwd) {
431
+ /** `package.json` `bkit` config at the main checkout (cwd outside git). */
432
+ function mainConfig(cwd) {
75
433
  const common = git(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
76
- return readBkitConfig(common ? path.dirname(common) : cwd).issueTracker;
434
+ return readBkitConfig(common ? path.dirname(common) : cwd);
435
+ }
436
+ /** `package.json` `bkit.tracker.default` at the main checkout (cwd outside git); default `none`. */
437
+ export function readIssueTracker(cwd) {
438
+ return mainConfig(cwd).issueTracker;
439
+ }
440
+ /**
441
+ * Where this repo's issues live, per tracker: github the `origin` owner/repo (read from the
442
+ * remote, not gh, so a prompt parse makes no network call); linear `bkit.tracker.linear.team`; jira
443
+ * `bkit.tracker.jira.project` and `bkit.tracker.jira.site`. Each is null when unset.
444
+ */
445
+ function issueScope(cwd, tracker) {
446
+ if (tracker === "github")
447
+ return { key: null, ownerRepo: originOwnerRepo(cwd), site: null };
448
+ if (tracker !== "linear" && tracker !== "jira")
449
+ return { key: null };
450
+ const cfg = mainConfig(cwd);
451
+ return tracker === "linear"
452
+ ? { key: cfg.linear.team }
453
+ : { key: cfg.jira.project, site: cfg.jira.site };
454
+ }
455
+ /** The setting that names the issue-key prefix of a keyed tracker. */
456
+ const KEY_SETTING = {
457
+ linear: "bkit.tracker.linear.team",
458
+ jira: "bkit.tracker.jira.project",
459
+ };
460
+ /** The stderr hint for bare keys skipped because no key prefix is configured. */
461
+ function skippedKeyHint(skipped, tracker) {
462
+ return `${skipped.join(", ")} not read as an issue: bare keys count only once ${KEY_SETTING[tracker]} is set in package.json; or name the issue as "issue KEY-N"`;
463
+ }
464
+ /** The current tree and the main checkout: where log folders are looked for. */
465
+ function fidRoots(cwd) {
466
+ const top = git(cwd, ["rev-parse", "--show-toplevel"]) ?? cwd;
467
+ return [...new Set([top, repoRoot(cwd)])];
77
468
  }
78
469
  function trackerFlag(value, cwd, allowAny) {
79
470
  if (value === undefined)
@@ -113,26 +504,71 @@ const MARKERS = {
113
504
  jira: /<!-- bkit:issue=([A-Za-z][A-Za-z0-9]+-[0-9]+) bkit:fid=(\S+) -->/,
114
505
  none: /<!-- bkit:fid=(\S+) -->/,
115
506
  };
116
- /** FID from the marker, when present and well-formed for the tracker. */
507
+ /**
508
+ * FID from the marker, when present and well-formed for the tracker. A wired tracker also
509
+ * accepts the FID-only marker of an issue-less run: its FID must be issue-less, and it
510
+ * resolves to `issueId: null`.
511
+ */
117
512
  export function fromMarker(text, tracker) {
118
513
  const m = MARKERS[tracker].exec(text);
119
- if (!m)
120
- return null;
514
+ if (!m) {
515
+ if (tracker === "none")
516
+ return null;
517
+ const bare = MARKERS.none.exec(text);
518
+ const fid = bare?.[1];
519
+ return fid !== undefined && ISSUE_LESS_FID.test(fid)
520
+ ? { fid, issueId: null, source: "marker" }
521
+ : null;
522
+ }
121
523
  const fid = normaliseFid(m[m.length - 1], tracker);
122
524
  if (!FID_PATTERNS[tracker].test(fid))
123
525
  return null;
124
526
  const issueId = tracker === "none" ? null : KEYED.has(tracker) ? m[1].toUpperCase() : m[1];
125
527
  return { fid, issueId, source: "marker" };
126
528
  }
127
- /** FID from `feat/{FID}`; the slug check, then the issue id the tracker needs. */
128
- export function fromBranch(branch, tracker) {
529
+ /**
530
+ * The issue ids a repo's feature rows in `.bkit/issues.jsonl` carry in their FID keys,
531
+ * per the tracker's FID shape (`650-x` -> `650`; linear and jira keys uppercased).
532
+ */
533
+ export function featureIssueIds(root, tracker) {
534
+ const file = path.join(root, ".bkit", "issues.jsonl");
535
+ const ids = new Set();
536
+ if (tracker === "none" || !fs.existsSync(file) || !fs.statSync(file).isFile())
537
+ return ids;
538
+ for (const line of fs.readFileSync(file, "utf-8").split("\n")) {
539
+ if (line.trim() === "")
540
+ continue;
541
+ const row = parseJson(line);
542
+ if (!row.ok || typeof row.value !== "object" || row.value === null)
543
+ continue;
544
+ const { kind, key } = row.value;
545
+ if (kind !== "feature" || typeof key !== "string")
546
+ continue;
547
+ const id = issueIdOf(key, tracker);
548
+ if (id !== null)
549
+ ids.add(id);
550
+ }
551
+ return ids;
552
+ }
553
+ /**
554
+ * FID from `feat/{FID}`; the slug check, then the issue id the tracker needs. A wired
555
+ * tracker also accepts an issue-less FID (no issue id embedded, no all-digit word) as `issueId: null`.
556
+ * With `known` (the issue ids the repo's feature rows carry), the FID is the suffix verbatim
557
+ * for any slug: the issue id its shape embeds counts only when `known` holds it, else the
558
+ * run is issue-less (`issueId: null`).
559
+ */
560
+ export function fromBranch(branch, tracker, known) {
129
561
  if (!branch.startsWith("feat/"))
130
562
  return { ok: false, why: `branch "${branch}" is not feat/{FID}` };
131
563
  const fid = branch.slice("feat/".length);
132
564
  if (!SLUG.test(fid))
133
565
  return { ok: false, why: `"${fid}" is not a slug (${SLUG.source})` };
134
566
  const issueId = issueIdOf(fid, tracker);
135
- if (tracker !== "none" && issueId === null) {
567
+ if (known !== undefined) {
568
+ const linked = issueId !== null && known.has(issueId) ? issueId : null;
569
+ return { ok: true, parsed: { fid, issueId: linked, source: "branch" } };
570
+ }
571
+ if (tracker !== "none" && issueId === null && !ISSUE_LESS_FID.test(fid)) {
136
572
  return { ok: false, why: `"${fid}" embeds no ${tracker} issue id` };
137
573
  }
138
574
  return { ok: true, parsed: { fid, issueId, source: "branch" } };
@@ -140,32 +576,40 @@ export function fromBranch(branch, tracker) {
140
576
  const TRACKER_FLAG = {
141
577
  name: "tracker",
142
578
  type: "string",
143
- help: "github | linear | jira | none (default: package.json bkit.issueTracker, else none)",
579
+ help: "github | linear | jira | none (default: package.json bkit.tracker.default, else none)",
144
580
  };
145
581
  export const fidsCommand = {
146
582
  noun: "fids",
147
- summary: "Feature-id format per tracker, and FID recovery from a branch or PR-body marker.",
583
+ summary: "Feature-id format per tracker; the issue, FID, plan files and plan inputs Step 1 resolves; FID recovery from a branch or PR-body marker.",
148
584
  verbs: {
149
585
  check: {
150
586
  summary: "Validate a FID for the tracker: exit 0 valid, exit 1 not.",
587
+ use: "by-hand",
151
588
  flags: [
152
589
  { name: "fid", type: "string", required: true, help: "feature id to check" },
153
590
  { ...TRACKER_FLAG, help: `${TRACKER_FLAG.help}; any = any tracker's shape (CI_DEV)` },
591
+ {
592
+ name: "issue",
593
+ type: "string",
594
+ help: 'the run\'s issue id (the FID must embed it), or "" for a run with no issue (then the FID must be a slug); absent = the tracker shape alone',
595
+ },
154
596
  ],
155
597
  output: {
156
598
  fid: "the FID as checked (linear, jira: lowercased)",
157
599
  tracker: "tracker the shape came from",
158
600
  valid: "true when the FID matches",
159
- pattern: "the regex checked",
601
+ pattern: "the regex checked (the slug rule when --issue is empty)",
160
602
  issueId: "issue id the FID embeds (null under none, or when invalid)",
161
603
  },
162
604
  run: (ctx) => {
163
605
  const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, true);
164
606
  const fid = normaliseFid(String(ctx.flags.fid), tracker);
165
- const pattern = FID_PATTERNS[tracker];
166
- const valid = pattern.test(fid);
607
+ const issue = str(ctx.flags.issue)?.replace(/^#/, "");
608
+ const pattern = issue === "" && tracker !== "none" ? SLUG : FID_PATTERNS[tracker];
609
+ const problem = fidProblem(fid, tracker, issue);
610
+ const valid = problem === undefined;
167
611
  if (!valid)
168
- ctx.log(`FID "${fid}" does not match the ${tracker} shape ${pattern.source}`);
612
+ ctx.log(problem);
169
613
  ctx.emit({
170
614
  fid,
171
615
  tracker,
@@ -177,8 +621,14 @@ export const fidsCommand = {
177
621
  },
178
622
  },
179
623
  parse: {
180
- summary: "Recover FID and issue id: the PR-body marker first, then a feat/{FID} branch.",
624
+ summary: "--prompt-file: the issue and the FID a session prompt names. --marker / --branch: recover FID and issue id, the PR-body marker first, then a feat/{FID} branch (any slug; its issue id counts only when .bkit/issues.jsonl has a feature row for it, else the run is issue-less).",
625
+ use: "by-hand",
181
626
  flags: [
627
+ {
628
+ name: "prompt-file",
629
+ type: "string",
630
+ help: "the session prompt, written verbatim (Step 1: {SESSION_DIR}/prompt.md); not with --marker / --branch",
631
+ },
182
632
  {
183
633
  name: "marker",
184
634
  type: "string",
@@ -188,17 +638,60 @@ export const fidsCommand = {
188
638
  TRACKER_FLAG,
189
639
  ],
190
640
  output: {
191
- fid: "the recovered FID",
192
- issueId: "tracker issue id (null under none)",
193
- source: "marker | branch",
194
- tracker: "tracker the shapes came from",
641
+ source: "--prompt-file: github | linear | jira — the wired tracker, when the prompt names one of its issues; none otherwise (a bare number, another tracker's form, tracker none). --marker / --branch: marker | branch",
642
+ issue: '--prompt-file: the issue named (github: the number, linear / jira: the key): an explicit form (<id> tag, "GitHub issue: #N", "issue #N" / "issue KEY", owner/repo#N or a tracker URL into the origin repo / bkit.tracker.linear.team / bkit.tracker.jira.site + bkit.tracker.jira.project; a URL elsewhere is ignored) over a bare #N / key; a bare Linear / Jira key only with the bkit.tracker.linear.team / bkit.tracker.jira.project prefix set; else ""',
643
+ ambiguous: "--prompt-file, exit 8 only: the issues named, as a person types them (then no other key prints)",
644
+ ref: '--prompt-file: the issue as a person types it (github: #N, linear / jira: the key), else ""',
645
+ fidNamed: "--prompt-file: the first FID the prompt names (feat/{FID}, a docs/plans/{YYYYMM}/ path, or a bare word with a logs/{word}/ folder), else null",
646
+ fid: "--marker / --branch: the recovered FID",
647
+ issueId: "--marker / --branch: tracker issue id; null under none, for a marker with none, and for a branch whose embedded issue id has no feature row (an issue-less run)",
648
+ tracker: "--marker / --branch: tracker the shapes came from",
649
+ },
650
+ exitCodes: {
651
+ [EXIT_NO_FID]: "neither the marker nor the branch yielded a FID (a branch that is not feat/ or whose suffix is not a slug)",
652
+ [EXIT_NO_FILE]: "the --prompt-file is missing",
653
+ [EXIT_AMBIGUOUS]: `--prompt-file names more than one issue (explicit forms first) — ${NAME_THE_ISSUE}`,
195
654
  },
196
- exitCodes: { [EXIT_NO_FID]: "neither the marker nor the branch yielded a valid FID" },
197
655
  run: (ctx) => {
198
656
  const marker = str(ctx.flags.marker);
199
657
  const branch = str(ctx.flags.branch);
658
+ const promptFile = str(ctx.flags.promptFile);
659
+ if (promptFile !== undefined) {
660
+ if (marker !== undefined || branch !== undefined)
661
+ throw new CommandError(EXIT.USAGE, "--prompt-file goes alone, without --marker / --branch");
662
+ const text = readNamed(path.resolve(ctx.cwd, promptFile), "prompt-file");
663
+ const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, false);
664
+ const scope = issueScope(ctx.cwd, tracker);
665
+ const key = scope.key ?? null;
666
+ const refs = issueRefs(text, tracker, scope);
667
+ const candidates = issueCandidates(refs);
668
+ if (candidates.length > 1) {
669
+ const named = candidates.map((c) => issueRef(c, tracker));
670
+ ctx.log(`the prompt names more than one issue (${named.join(", ")}); ${NAME_THE_ISSUE}`);
671
+ ctx.emit({ ambiguous: named });
672
+ return EXIT_AMBIGUOUS;
673
+ }
674
+ const issue = candidates[0] ?? "";
675
+ const others = [...new Set([...refs.explicit, ...refs.bare].map((r) => r.value))].filter((v) => v !== issue);
676
+ if (others.length > 0)
677
+ ctx.log(`taking ${issueRef(issue, tracker)}, named explicitly; not the bare mention ${others.map((o) => issueRef(o, tracker)).join(", ")}`);
678
+ const bareNumber = bareNumbers(text)[0];
679
+ if (issue === "" && tracker !== "none" && bareNumber !== undefined)
680
+ ctx.log(bareNumberHint(bareNumber, tracker, key));
681
+ if (issue === "" &&
682
+ refs.skipped.length > 0 &&
683
+ (tracker === "linear" || tracker === "jira"))
684
+ ctx.log(skippedKeyHint([...new Set(refs.skipped.map((h) => h.value))], tracker));
685
+ ctx.emit({
686
+ source: issue === "" ? "none" : tracker,
687
+ issue,
688
+ ref: issueRef(issue, tracker),
689
+ fidNamed: namedFid(text, fidRoots(ctx.cwd)),
690
+ });
691
+ return EXIT.OK;
692
+ }
200
693
  if (marker === undefined && branch === undefined) {
201
- throw new CommandError(EXIT.USAGE, "give --marker, --branch, or both");
694
+ throw new CommandError(EXIT.USAGE, "give --prompt-file, or --marker, --branch, or both");
202
695
  }
203
696
  const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, false);
204
697
  const viaMarker = marker === undefined ? null : fromMarker(marker, tracker);
@@ -210,7 +703,8 @@ export const fidsCommand = {
210
703
  ctx.log(`no well-formed ${tracker} bkit:fid marker — trying the branch`);
211
704
  if (branch === undefined)
212
705
  return EXIT_NO_FID;
213
- const viaBranch = fromBranch(branch, tracker);
706
+ const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
707
+ const viaBranch = fromBranch(branch, tracker, featureIssueIds(top, tracker));
214
708
  if (!viaBranch.ok) {
215
709
  ctx.log(viaBranch.why);
216
710
  return EXIT_NO_FID;
@@ -219,8 +713,132 @@ export const fidsCommand = {
219
713
  return EXIT.OK;
220
714
  },
221
715
  },
716
+ resolve: {
717
+ summary: "The run's FID, first hit wins: a FID the prompt names, the feat/{FID} branch, a FID logged for the issue on dev, a mint from the title (or prompt), a free -b, -c, ... suffix when a finished run used the mint; then the format check (exit 0 resolved, exit 1 fails the check).",
718
+ use: "workflow",
719
+ flags: [
720
+ {
721
+ name: "prompt-file",
722
+ type: "string",
723
+ required: true,
724
+ help: "the session prompt, written verbatim ({SESSION_DIR}/prompt.md)",
725
+ },
726
+ {
727
+ name: "issue",
728
+ type: "string",
729
+ help: 'the run\'s issue id (github: 123; linear / jira: ABC-123), or "" / absent for a run with no issue',
730
+ },
731
+ {
732
+ name: "title-file",
733
+ type: "string",
734
+ help: "the issue title: a JSON object with a title key, else the file's text; drop it for a run with no issue",
735
+ },
736
+ {
737
+ ...WORKFLOW_FLAG,
738
+ help: "the workflow starting; an in-progress run of it continues a used mint instead of suffixing",
739
+ },
740
+ TRACKER_FLAG,
741
+ ],
742
+ output: {
743
+ fid: "the FID to use",
744
+ source: "prompt | branch | logged | minted | suffixed — the link of the chain that gave fid",
745
+ month: "the newest bucket holding logs/{fid}/, else null",
746
+ existing: "true when logs/{fid}/ exists in some bucket",
747
+ fids: "every FID logged for the issue (working tree and dev) when the chain reached that link, else []",
748
+ },
749
+ exitCodes: {
750
+ [EXIT_SEVERAL]: "several features are logged for the issue — name one in the prompt",
751
+ [EXIT_NO_FREE]: "the mint and every -b … -z suffix of it are used by finished runs",
752
+ [EXIT_BARE_NUMBER]: `a wired tracker, no issue, and the prompt holds only a bare number (the mint would be the workflow name) — ${NAME_THE_ISSUE}`,
753
+ [EXIT_NO_FILE]: "the --prompt-file or --title-file is missing",
754
+ },
755
+ run: (ctx) => {
756
+ const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, false);
757
+ const issue = (str(ctx.flags.issue) ?? "").replace(/^#/, "");
758
+ const prompt = readNamed(path.resolve(ctx.cwd, String(ctx.flags.promptFile)), "prompt-file");
759
+ const titleFile = str(ctx.flags.titleFile);
760
+ const title = titleFile === undefined
761
+ ? ""
762
+ : titleOf(readNamed(path.resolve(ctx.cwd, titleFile), "title-file"));
763
+ const workflow = String(ctx.flags.workflow);
764
+ const roots = fidRoots(ctx.cwd);
765
+ const branch = git(ctx.cwd, ["branch", "--show-current"]) || null;
766
+ const prefix = KEYED.has(tracker) ? `${issue.toLowerCase()}-` : `${issue}-`;
767
+ let fids = [];
768
+ let pick = null;
769
+ const named = namedFid(prompt, roots);
770
+ if (named !== null)
771
+ pick = { fid: named, source: "prompt" };
772
+ const onBranch = branch?.startsWith("feat/") ? branch.slice("feat/".length) : null;
773
+ if (pick === null && onBranch !== null && SLUG.test(onBranch)) {
774
+ if (issue === "" || onBranch.startsWith(prefix))
775
+ pick = { fid: onBranch, source: "branch" };
776
+ }
777
+ if (pick === null && issue !== "") {
778
+ fids = [
779
+ ...new Set([...roots.flatMap((r) => logged(r, issue)), ...loggedOnDev(ctx.cwd, issue)]),
780
+ ].sort();
781
+ if (fids.length > 1) {
782
+ ctx.log(`several features logged for ${issue}: ${fids.join(", ")}`);
783
+ ctx.emit({ fid: null, source: null, month: null, existing: false, fids });
784
+ return EXIT_SEVERAL;
785
+ }
786
+ if (fids.length === 1)
787
+ pick = { fid: fids[0], source: "logged" };
788
+ }
789
+ const bareNumber = bareNumbers(prompt)[0];
790
+ if (pick === null &&
791
+ issue === "" &&
792
+ tracker !== "none" &&
793
+ bareNumber !== undefined &&
794
+ slugWords(title).length === 0 &&
795
+ slugWords(prompt).length === 0) {
796
+ ctx.log(`${bareNumberHint(bareNumber, tracker, issueScope(ctx.cwd, tracker).key ?? null)} — refusing to mint a FID from the workflow name alone`);
797
+ return EXIT_BARE_NUMBER;
798
+ }
799
+ if (pick === null) {
800
+ const minted = normaliseFid(mintFid({ issue, title, prompt, branch, workflow }), tracker);
801
+ const free = freeFid(roots, minted, workflow);
802
+ if (free === null) {
803
+ ctx.log(`"${minted}" and every -b … -z suffix of it are used by finished runs`);
804
+ return EXIT_NO_FREE;
805
+ }
806
+ pick = { fid: free, source: free === minted ? "minted" : "suffixed" };
807
+ }
808
+ const fid = normaliseFid(pick.fid, tracker);
809
+ const problem = fidProblem(fid, tracker, issue);
810
+ if (problem !== undefined) {
811
+ ctx.log(`${pick.source} FID: ${problem}`);
812
+ return EXIT.NO;
813
+ }
814
+ const month = roots
815
+ .flatMap((r) => monthBuckets(r, fid))
816
+ .sort()
817
+ .at(-1) ?? null;
818
+ ctx.emit({ fid, source: pick.source, month, existing: month !== null, fids });
819
+ return EXIT.OK;
820
+ },
821
+ },
822
+ plans: {
823
+ summary: "A feature's plan in a month bucket: docs/plans/{YYYYMM}/{FID}-plan.md, or none.",
824
+ use: "by-hand",
825
+ flags: [
826
+ { name: "fid", type: "string", required: true, help: "feature id" },
827
+ { name: "month", type: "string", required: true, help: "YYYYMM bucket" },
828
+ ],
829
+ output: {
830
+ source: "single ({FID}-plan.md exists) | none (no plan file)",
831
+ plan: "the repo-relative plan file, or null",
832
+ },
833
+ run: (ctx) => {
834
+ const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
835
+ ctx.emit(planFiles(top, String(ctx.flags.fid), String(ctx.flags.month)));
836
+ return EXIT.OK;
837
+ },
838
+ },
222
839
  design: {
223
- summary: "The feature's own design doc, docs/plans/{YYYYMM}/{FID}-design.md: exit 0 found, exit 1 none.",
840
+ summary: "The plan's parent design: the **Parent design:** link in the description or prompt, else the feature's own docs/plans/{YYYYMM}/{FID}-design.md; plus the audit reports and the **Workstreams:** ids they name (exit 0 a parent, exit 1 none).",
841
+ use: "by-hand",
224
842
  flags: [
225
843
  { name: "fid", type: "string", required: true, help: "feature id" },
226
844
  {
@@ -228,21 +846,76 @@ export const fidsCommand = {
228
846
  type: "string",
229
847
  help: "YYYYMM bucket checked first; else the newest bucket holding the doc",
230
848
  },
849
+ {
850
+ name: "description-file",
851
+ type: "string",
852
+ help: "the issue description; drop it for a run with no issue",
853
+ },
854
+ {
855
+ name: "prompt-file",
856
+ type: "string",
857
+ help: "the session prompt ({SESSION_DIR}/prompt.md)",
858
+ },
231
859
  ],
232
860
  output: {
233
- fid: "the FID when its design doc exists, else null",
861
+ fid: "the FID when its own design doc exists, else null",
234
862
  month: "the bucket holding it, else null",
235
863
  path: "repo-relative path, else null",
864
+ parentFid: "the parent design's FID (the link's, else the feature's own), else null",
865
+ parentMonth: "its bucket, else null",
866
+ parentPath: "its repo-relative path, else null",
867
+ parentSource: "link | fid | null",
868
+ auditPaths: "every docs/audits/{YYYYMM}/*.md path the description, then the prompt, names, first mention order",
869
+ workstreams: "the WS-{N} ids the first **Workstreams:** line (description, then prompt) names: the plan covers only those; [] = the whole design",
870
+ },
871
+ exitCodes: {
872
+ [EXIT_NO_FILE]: "a --description-file / --prompt-file is missing, or a linked design or named audit path is not a file",
236
873
  },
237
874
  run: (ctx) => {
238
875
  const fid = String(ctx.flags.fid);
239
- const hit = designDoc(repoRoot(ctx.cwd), fid, str(ctx.flags.month));
240
- ctx.emit(hit ? { fid, month: hit.month, path: hit.path } : { fid: null, month: null, path: null });
241
- return hit ? EXIT.OK : EXIT.NO;
876
+ const root = repoRoot(ctx.cwd);
877
+ const texts = ["descriptionFile", "promptFile"].flatMap((k) => {
878
+ const file = str(ctx.flags[k]);
879
+ return file === undefined
880
+ ? []
881
+ : [
882
+ readNamed(path.resolve(ctx.cwd, file), k === "promptFile" ? "prompt-file" : "description-file"),
883
+ ];
884
+ });
885
+ const own = designDoc(root, fid, str(ctx.flags.month));
886
+ const link = texts.map(parentDesignLink).find((l) => l !== null) ?? null;
887
+ const parent = link
888
+ ? {
889
+ fid: link.fid,
890
+ month: link.month,
891
+ path: `docs/plans/${link.month}/${link.fid}-design.md`,
892
+ source: "link",
893
+ }
894
+ : own
895
+ ? { fid, month: own.month, path: own.path, source: "fid" }
896
+ : null;
897
+ const audits = auditPaths(...texts);
898
+ for (const rel of [...(link && parent ? [parent.path] : []), ...audits]) {
899
+ if (!fs.statSync(path.join(root, rel), { throwIfNoEntry: false })?.isFile())
900
+ throw new CommandError(EXIT_NO_FILE, `${rel} is named but is not a file`);
901
+ }
902
+ ctx.emit({
903
+ ...(own
904
+ ? { fid, month: own.month, path: own.path }
905
+ : { fid: null, month: null, path: null }),
906
+ parentFid: parent?.fid ?? null,
907
+ parentMonth: parent?.month ?? null,
908
+ parentPath: parent?.path ?? null,
909
+ parentSource: parent?.source ?? null,
910
+ auditPaths: audits,
911
+ workstreams: workstreamIds(...texts),
912
+ });
913
+ return parent ? EXIT.OK : EXIT.NO;
242
914
  },
243
915
  },
244
916
  find: {
245
917
  summary: "The feature already logged for an issue: exit 0 one, exit 1 none, exit 4 several.",
918
+ use: "by-hand",
246
919
  flags: [
247
920
  {
248
921
  name: "issue",