@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,14 +10,37 @@
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
 
13
25
  import * as fs from "node:fs";
14
26
  import * as path from "node:path";
15
27
 
16
28
  import { parseIssueTracker, type IssueTracker } from "../../install/manifest.js";
17
- import { CommandError, EXIT, git, repoRoot, type CommandSpec, type FlagSpec } from "../lib.js";
29
+ import {
30
+ CommandError,
31
+ EXIT,
32
+ git,
33
+ parseJson,
34
+ repoRoot,
35
+ statusRelPath,
36
+ type CommandSpec,
37
+ type FlagSpec,
38
+ } from "../lib.js";
18
39
  import { readBkitConfig } from "../../shared/settings.js";
19
- import { str } from "./status.js";
40
+ import { originOwnerRepo } from "./repo.js";
41
+ import { lastRun } from "../../ledgers/status.js";
42
+ import { monthBuckets, readRunsLenient } from "./locks.js";
43
+ import { WORKFLOW_FLAG, str } from "./status.js";
20
44
 
21
45
  export type FidTracker = IssueTracker | "any";
22
46
 
@@ -36,10 +60,62 @@ const ISSUE_KEY = { linear: /^[A-Z]+-[0-9]+$/, jira: /^[A-Z][A-Z0-9]+-[0-9]+$/ }
36
60
  /** The slug every recovered FID must pass before it touches a path (auto's branch fallback). */
37
61
  const SLUG = FID_PATTERNS.none;
38
62
 
63
+ /** An issue-less FID: a slug with no all-digit `-`-separated word, so it never parses as an issue id. */
64
+ export const ISSUE_LESS_FID = /^(?!.*(?:^|-)[0-9]+(?:-|$))[a-z0-9][a-z0-9-]*$/;
65
+
66
+ /** The issue id each wired tracker mints (`#` stripped; linear and jira keys are uppercase). */
67
+ export const ISSUE_ID_PATTERNS: Readonly<Record<Exclude<IssueTracker, "none">, RegExp>> = {
68
+ github: /^[0-9]+$/,
69
+ linear: /^[A-Z]+-[0-9]+$/,
70
+ jira: /^[A-Z][A-Z0-9]+-[0-9]+$/,
71
+ };
72
+
73
+ /**
74
+ * The problem with a FID for the tracker and the run's issue, or undefined when it is valid.
75
+ * `issue` absent: the tracker's FID shape alone. A non-empty `issue`: the issue id and the
76
+ * FID both match the tracker, and the issue id the FID embeds is that issue. An empty
77
+ * `issue` (a run with no issue): the FID is any slug (a minted one is held to
78
+ * `ISSUE_LESS_FID` by `fids resolve`). The `none` tracker has no issue-id shape, so `issue`
79
+ * is ignored.
80
+ */
81
+ export function fidProblem(fid: string, tracker: FidTracker, issue?: string): string | undefined {
82
+ const shape = FID_PATTERNS[tracker];
83
+ const shapeProblem = shape.test(fid)
84
+ ? undefined
85
+ : `FID "${fid}" does not match the ${tracker} shape ${shape.source}`;
86
+ if (issue === undefined || tracker === "none") return shapeProblem;
87
+ if (issue === "") {
88
+ return SLUG.test(fid)
89
+ ? undefined
90
+ : `FID "${fid}" is not a slug (${SLUG.source}): a run with no issue needs a lowercase slug`;
91
+ }
92
+ const idShapes =
93
+ tracker === "any" ? Object.values(ISSUE_ID_PATTERNS) : [ISSUE_ID_PATTERNS[tracker]];
94
+ if (!idShapes.some((re) => re.test(issue))) {
95
+ return `issue "${issue}" is not a ${tracker} issue id`;
96
+ }
97
+ if (shapeProblem !== undefined) return shapeProblem;
98
+ const embedded = issueIdOf(fid, tracker);
99
+ return embedded === issue
100
+ ? undefined
101
+ : `FID "${fid}" embeds issue ${embedded ?? "none"}, not the run's issue ${issue}`;
102
+ }
103
+
39
104
  /** Exit code: no FID could be recovered from the marker or the branch. */
40
105
  export const EXIT_NO_FID = 3;
41
106
  /** Exit code (find): more than one feature is logged for the issue. */
42
107
  export const EXIT_SEVERAL = 4;
108
+ /** Exit code (resolve): the minted name and every suffix of it are used. */
109
+ export const EXIT_NO_FREE = 5;
110
+ /** Exit code: a file a flag names is missing. */
111
+ export const EXIT_NO_FILE = 7;
112
+ /** Exit code (parse --prompt-file): the prompt names more than one issue. */
113
+ export const EXIT_AMBIGUOUS = 8;
114
+ /** Exit code (resolve): the prompt holds only a bare number, so the FID would mint from the workflow name. */
115
+ export const EXIT_BARE_NUMBER = 9;
116
+
117
+ /** The stop message for a prompt that does not say which issue it means. */
118
+ const NAME_THE_ISSUE = "name the issue as #N, its key or its URL";
43
119
 
44
120
  /**
45
121
  * Features already logged for an issue: every `docs/plans/{YYYYMM}/logs/{issue}-*`
@@ -60,6 +136,360 @@ export function logged(root: string, issue: string): string[] {
60
136
  return [...found].sort();
61
137
  }
62
138
 
139
+ /** Suffixes tried after a minted name that an earlier run used: `-b` … `-z`. */
140
+ const MINT_SUFFIXES = [..."bcdefghijklmnopqrstuvwxyz"];
141
+
142
+ /**
143
+ * The FID a minted issue-less run takes: `fid` itself, or the first of `fid-b`, `fid-c`, ...
144
+ * that no earlier run used. A name is used when it has a log folder (any month bucket) in
145
+ * one of `roots` whose last `workflow` run is not IN_PROGRESS; an in-progress one is
146
+ * continued. null when every name is used.
147
+ */
148
+ export function freeFid(roots: string[], fid: string, workflow: string): string | null {
149
+ for (const name of [fid, ...MINT_SUFFIXES.map((x) => `${fid}-${x}`)]) {
150
+ let used = false;
151
+ for (const root of roots) {
152
+ for (const month of monthBuckets(root, name)) {
153
+ const run = lastRun(readRunsLenient(path.join(root, statusRelPath(month, name))), workflow);
154
+ if (run?.status === "IN_PROGRESS") return name;
155
+ used = true;
156
+ }
157
+ }
158
+ if (!used) return name;
159
+ }
160
+ return null;
161
+ }
162
+
163
+ /** A file a flag names, or exit 7 when it is missing. */
164
+ function readNamed(file: string, flag: string): string {
165
+ if (!fs.existsSync(file) || !fs.statSync(file).isFile())
166
+ throw new CommandError(EXIT_NO_FILE, `--${flag}: no file at ${file}`);
167
+ return fs.readFileSync(file, "utf-8");
168
+ }
169
+
170
+ /** The issue title a `--title-file` holds: a JSON object's `title`, else the text itself. */
171
+ export function titleOf(text: string): string {
172
+ const parsed = parseJson(text);
173
+ if (parsed.ok && typeof parsed.value === "object" && parsed.value !== null) {
174
+ const title = (parsed.value as Record<string, unknown>).title;
175
+ if (typeof title === "string") return title;
176
+ }
177
+ return text.trim();
178
+ }
179
+
180
+ /** English words a minted slug drops. */
181
+ export const STOPWORDS: ReadonlySet<string> = new Set(
182
+ (
183
+ "a about after all also an and any are as at be been before being but by can could " +
184
+ "did do does doing for from had has have he her his how i if in into is it its just " +
185
+ "let me more most my no nor not now of off on once only or other our out over per " +
186
+ "please same she should so some such than that the their them then there these they " +
187
+ "this those through to too under until up us very via was we were what when where " +
188
+ "which while who why will with would you your"
189
+ ).split(" "),
190
+ );
191
+
192
+ /**
193
+ * The slug words of free text in order: URLs, `<tags>` and `/commands` removed, letters
194
+ * folded to ASCII, lowercased, split on anything else; stopwords and all-digit words dropped.
195
+ */
196
+ export function slugWords(text: string): string[] {
197
+ return text
198
+ .replace(/\S+:\/\/\S+/g, " ")
199
+ .replace(/<[^>]*>/g, " ")
200
+ .replace(/(^|\s)\/\S+/g, " ")
201
+ .normalize("NFKD")
202
+ .replace(/[\u0300-\u036f]/g, "")
203
+ .toLowerCase()
204
+ .split(/[^a-z0-9]+/)
205
+ .filter((w) => w !== "" && !STOPWORDS.has(w) && !/^[0-9]+$/.test(w));
206
+ }
207
+
208
+ /** The FID a run mints; see the header comment for the rules. */
209
+ export function mintFid(o: {
210
+ issue: string;
211
+ title?: string;
212
+ prompt: string;
213
+ branch?: string | null;
214
+ workflow?: string;
215
+ }): string {
216
+ const fromTitle = slugWords(o.title ?? "");
217
+ const words = (fromTitle.length > 0 ? fromTitle : slugWords(o.prompt)).slice(0, 3);
218
+ const slug = (words.length > 0 ? words : [o.workflow ?? "feature"]).join("-");
219
+ if (o.issue !== "") return `${o.issue.replace(/^#/, "").toLowerCase()}-${slug}`;
220
+ const suffix = (o.branch ?? "")
221
+ .split("/")
222
+ .at(-1)!
223
+ .toLowerCase()
224
+ .split(/[^a-z0-9]+/)
225
+ .filter((w) => w !== "" && !/^[0-9]+$/.test(w));
226
+ return [...suffix, slug].join("-");
227
+ }
228
+
229
+ const MONTH = /^[0-9]{6}$/;
230
+
231
+ /** Every `docs/plans/{YYYYMM}/logs/{name}` folder name under the roots. */
232
+ function loggedNames(roots: string[]): Set<string> {
233
+ const names = new Set<string>();
234
+ for (const root of roots) {
235
+ const plans = path.join(root, "docs", "plans");
236
+ if (!fs.existsSync(plans)) continue;
237
+ for (const month of fs.readdirSync(plans).filter((m) => MONTH.test(m))) {
238
+ const logs = path.join(plans, month, "logs");
239
+ if (!fs.existsSync(logs)) continue;
240
+ for (const name of fs.readdirSync(logs)) {
241
+ if (fs.statSync(path.join(logs, name)).isDirectory()) names.add(name);
242
+ }
243
+ }
244
+ }
245
+ return names;
246
+ }
247
+
248
+ /** Features logged for an issue on `origin/dev` (else local `dev`), read from git, not the working tree. */
249
+ export function loggedOnDev(cwd: string, issue: string): string[] {
250
+ const ref = git(cwd, ["rev-parse", "--verify", "-q", "origin/dev"]) ? "origin/dev" : "dev";
251
+ const out = git(cwd, ["ls-tree", "-r", "-d", "--name-only", ref, "--", "docs/plans"]);
252
+ if (!out) return [];
253
+ const key = `${issue.replace(/^#/, "").toLowerCase()}-`;
254
+ const found = new Set<string>();
255
+ for (const line of out.split("\n")) {
256
+ const m = /^docs\/plans\/[0-9]{6}\/logs\/([^/]+)$/.exec(line.trim());
257
+ if (m && m[1]!.startsWith(key)) found.add(m[1]!);
258
+ }
259
+ return [...found].sort();
260
+ }
261
+
262
+ type Hit = { value: string; at: number };
263
+
264
+ function hits(text: string, re: RegExp, map: (m: RegExpExecArray) => string | null): Hit[] {
265
+ const out: Hit[] = [];
266
+ for (const m of text.matchAll(re)) {
267
+ const value = map(m);
268
+ if (value !== null) out.push({ value, at: m.index });
269
+ }
270
+ return out;
271
+ }
272
+
273
+ /** The line text before a `#N` ends in a CSS colour property (`color: `, `background-color: `). */
274
+ const CSS_COLOUR_LEAD = /(?:colou?r|background|border|fill|stroke|outline|shadow)[\w-]*\s*:\s*$/i;
275
+
276
+ /** A `#N` hit that is a 3- or 6-digit CSS colour (`color: #123456`), not an issue. */
277
+ function cssColour(text: string, h: Hit): boolean {
278
+ if (h.value.length !== 3 && h.value.length !== 6) return false;
279
+ return CSS_COLOUR_LEAD.test(text.slice(text.lastIndexOf("\n", h.at) + 1, h.at));
280
+ }
281
+
282
+ const byPosition = (a: Hit, b: Hit) => a.at - b.at;
283
+
284
+ /** Where this repo's issues live: what a tracker URL and a bare key must match to count. */
285
+ export interface IssueScope {
286
+ /** `bkit.tracker.linear.team` / `bkit.tracker.jira.project`: the prefix a key must carry. null = unset. */
287
+ key?: string | null;
288
+ /** `owner/repo` from the `origin` remote (github). null = no origin. */
289
+ ownerRepo?: string | null;
290
+ /** `bkit.tracker.jira.site` (jira). null = unset. */
291
+ site?: string | null;
292
+ }
293
+
294
+ /** Start and end of every match of `re` in `text`. */
295
+ const spans = (text: string, re: RegExp): [number, number][] =>
296
+ [...text.matchAll(re)].map((m) => [m.index, m.index + m[0].length]);
297
+
298
+ /** The host of a URL or bare host, lowercased: `https://Acme.atlassian.net/` -> `acme.atlassian.net`. */
299
+ const hostOf = (site: string) =>
300
+ site
301
+ .replace(/^[a-z][a-z0-9+.-]*:\/\//i, "")
302
+ .split("/")[0]!
303
+ .toLowerCase();
304
+
305
+ /** A URL in prose: a bare key or `#N` inside one is part of the URL, not a mention. */
306
+ const ANY_URL = /\b[a-z][a-z0-9+.-]*:\/\/\S+/gi;
307
+
308
+ /**
309
+ * Every issue reference the prompt makes for the tracker, in text order (ids may repeat),
310
+ * split by form. `explicit`: an `<id>` / `<{tracker}_issue>` tag, a labelled form
311
+ * (`GitHub issue: #N`, `issue #N`, `issue ABC-12`, `ISSUE-N`), or a tracker issue URL /
312
+ * `owner/repo#N` pointing at this repo / team / site (`scope`). `bare`: a `#N` (a CSS
313
+ * colour after `color:` and the like dropped), `owner/repo#N` with no origin to compare,
314
+ * or a bare Linear / Jira key carrying the `scope.key` prefix; with no prefix configured a
315
+ * bare key never counts and lands in `skipped` instead. A tracker URL or `owner/repo#N`
316
+ * pointing elsewhere counts as neither, and a key or `#N` inside any URL is never bare.
317
+ */
318
+ export function issueRefs(
319
+ text: string,
320
+ tracker: IssueTracker,
321
+ scope: IssueScope = {},
322
+ ): { explicit: Hit[]; bare: Hit[]; skipped: Hit[] } {
323
+ const id = (m: RegExpExecArray) => m[1]!;
324
+ const upper = (m: RegExpExecArray) => {
325
+ const k = m[1]!.toUpperCase();
326
+ return k.startsWith("ISSUE-") && !/^ISSUE-[0-9]+$/.test(k) ? null : k;
327
+ };
328
+ const prefix = scope.key ? `${scope.key.toUpperCase()}-` : null;
329
+ let explicit: Hit[];
330
+ let bare: Hit[];
331
+ let skipped: Hit[] = [];
332
+ let urlForm: RegExp;
333
+ if (tracker === "github") {
334
+ // With no origin to compare against, a URL to any repo counts and `owner/repo#N` stays bare.
335
+ const ours = scope.ownerRepo?.toLowerCase() ?? null;
336
+ const isOurs = (m: RegExpExecArray) => m[1]!.toLowerCase() === ours;
337
+ urlForm = /https?:\/\/[^\s/]+\/([^\s/]+\/[^\s/]+)\/issues\/([0-9]+)(?![\w])/g;
338
+ const shortRef = /(?<![\w&#/])([\w.-]+\/[\w.-]+)#([0-9]+)(?![\w-])/g;
339
+ const inShortRef = spans(text, shortRef);
340
+ explicit = [
341
+ ...hits(text, /<id>\s*#?([0-9]+)\s*<\/id>/gi, id),
342
+ ...hits(text, /<github_issue>\s*#?([0-9]+)\s*<\/github_issue>/gi, id),
343
+ ...hits(text, /GitHub issue:\s*#?([0-9]+)\b/gi, id),
344
+ ...hits(text, /\bissue:?\s*#([0-9]+)\b/gi, id),
345
+ ...hits(text, /\bISSUE-([0-9]+)\b/g, id),
346
+ ...hits(text, urlForm, (m) => (ours === null || isOurs(m) ? m[2]! : null)),
347
+ ...hits(text, shortRef, (m) => (ours !== null && isOurs(m) ? m[2]! : null)),
348
+ ];
349
+ bare = [
350
+ ...hits(text, /(?<![\w&#/])#([0-9]+)(?![\w-])/g, id).filter(
351
+ (h) => !cssColour(text, h) && !inShortRef.some(([from, to]) => h.at >= from && h.at < to),
352
+ ),
353
+ ...hits(text, shortRef, (m) => (ours === null ? m[2]! : null)),
354
+ ];
355
+ } else if (tracker === "linear" || tracker === "jira") {
356
+ const k = tracker === "linear" ? "[A-Za-z]+-[0-9]+" : "[A-Za-z][A-Za-z0-9]+-[0-9]+";
357
+ const plain = tracker === "linear" ? "[A-Z]+-[0-9]+" : "[A-Z][A-Z0-9]+-[0-9]+";
358
+ // bkit has no Linear workspace setting, so a Linear URL is matched on the team key alone.
359
+ // With no team / project / site configured, that part of the URL is not compared.
360
+ const site = tracker === "jira" && scope.site ? hostOf(scope.site) : null;
361
+ urlForm =
362
+ tracker === "linear"
363
+ ? new RegExp(`()linear\\.app\\/[^\\s/]+\\/issue\\/(${k})`, "gi")
364
+ : new RegExp(
365
+ `(?:[a-z][a-z0-9+.-]*:\\/\\/)?([^\\s/]+)(?:\\/\\S*?)?\\/browse\\/(${k})`,
366
+ "gi",
367
+ );
368
+ const ourUrl = (m: RegExpExecArray) => {
369
+ const key = m[2]!.toUpperCase();
370
+ if (prefix !== null && !key.startsWith(prefix)) return null;
371
+ if (site !== null && m[1]!.toLowerCase() !== site) return null;
372
+ return key;
373
+ };
374
+ explicit = [
375
+ ...hits(text, new RegExp(`<id>\\s*(${k})\\s*<\\/id>`, "gi"), upper),
376
+ ...hits(
377
+ text,
378
+ new RegExp(`<${tracker}_issue>\\s*(${k})\\s*<\\/${tracker}_issue>`, "gi"),
379
+ upper,
380
+ ),
381
+ ...hits(text, new RegExp(`${tracker} issue:\\s*(${k})\\b`, "gi"), upper),
382
+ ...hits(text, new RegExp(`\\b[Ii]ssue:?\\s+(${plain})\\b`, "g"), upper),
383
+ ...hits(text, new RegExp(`\\bISSUE-(${plain})\\b`, "g"), upper),
384
+ ...hits(text, urlForm, ourUrl),
385
+ ];
386
+ bare = hits(text, new RegExp(`(?<![\\w-])(${plain})(?![\\w-])`, "g"), upper);
387
+ if (prefix === null) {
388
+ skipped = bare;
389
+ bare = [];
390
+ } else {
391
+ bare = bare.filter((h) => h.value.startsWith(prefix));
392
+ }
393
+ } else {
394
+ return { explicit: [], bare: [], skipped: [] };
395
+ }
396
+ const urls = [...spans(text, ANY_URL), ...spans(text, urlForm)];
397
+ const outsideUrls = (h: Hit) => !urls.some(([from, to]) => h.at >= from && h.at < to);
398
+ const shape = ISSUE_ID_PATTERNS[tracker];
399
+ const keep = (list: Hit[]) => list.filter((h) => shape.test(h.value)).sort(byPosition);
400
+ return {
401
+ explicit: keep(explicit),
402
+ bare: keep(bare.filter(outsideUrls)),
403
+ skipped: keep(skipped.filter(outsideUrls)),
404
+ };
405
+ }
406
+
407
+ /** The issues a prompt names: the distinct explicit ids, else the distinct bare ones, in text order. */
408
+ export function issueCandidates(refs: { explicit: Hit[]; bare: Hit[] }): string[] {
409
+ const pool = refs.explicit.length > 0 ? refs.explicit : refs.bare;
410
+ return [...new Set(pool.map((h) => h.value))];
411
+ }
412
+
413
+ /** All-digit words a prompt holds outside URLs, tags, `/commands` and `#N`: an issue typed without its `#`. */
414
+ export function bareNumbers(text: string): string[] {
415
+ const plain = text
416
+ .replace(/\S+:\/\/\S+/g, " ")
417
+ .replace(/<[^>]*>/g, " ")
418
+ .replace(/(^|\s)\/\S+/g, " ");
419
+ return [...plain.matchAll(/(?<![\w#/.-])([0-9]+)(?![\w/.-])/g)].map((m) => m[1]!);
420
+ }
421
+
422
+ /** The stderr hint for a bare number: how to write it so it names the issue. */
423
+ function bareNumberHint(n: string, tracker: IssueTracker, key: string | null): string {
424
+ const write = tracker === "github" ? `#${n}` : `its issue key (${key ?? "KEY"}-${n})`;
425
+ return `${n} reads as a bare number; write ${write}`;
426
+ }
427
+
428
+ /** The FID a prompt names explicitly: `feat/` and `docs/plans/` paths always, a bare word only when `logs/{word}/` exists. */
429
+ export function namedFid(text: string, roots: string[]): string | null {
430
+ const fid = (m: RegExpExecArray) => {
431
+ const f = m[1]!.replace(/-+$/, "");
432
+ return SLUG.test(f) ? f : null;
433
+ };
434
+ const logged = loggedNames(roots);
435
+ const found = [
436
+ ...hits(text, /\bfeat\/([a-z0-9][a-z0-9-]*)/g, fid),
437
+ ...hits(text, /docs\/plans\/[0-9]{6}\/logs\/([a-z0-9][a-z0-9-]*)/g, fid),
438
+ ...hits(
439
+ text,
440
+ /docs\/plans\/[0-9]{6}\/([a-z0-9][a-z0-9-]*?)-(?:design|plan)(?:-[0-9]+)?\.md/g,
441
+ fid,
442
+ ),
443
+ ...hits(text, /(?<![\w/-])([a-z0-9][a-z0-9-]*[a-z0-9])(?![\w/-])/g, (m) =>
444
+ logged.has(m[1]!) ? m[1]! : null,
445
+ ),
446
+ ].sort((a, b) => a.at - b.at);
447
+ return found[0]?.value ?? null;
448
+ }
449
+
450
+ /** `#N` for GitHub, the key itself for Linear and Jira, "" with no issue. */
451
+ export const issueRef = (issue: string, tracker: IssueTracker) =>
452
+ issue === "" ? "" : tracker === "github" ? `#${issue}` : issue;
453
+
454
+ /** A feature's plan in a month bucket, as ship reads it: `{FID}-plan.md`, or none. */
455
+ export function planFiles(
456
+ root: string,
457
+ fid: string,
458
+ month: string,
459
+ ): { source: "single" | "none"; plan: string | null } {
460
+ const name = `${fid}-plan.md`;
461
+ return fs.existsSync(path.join(root, "docs", "plans", month, name))
462
+ ? { source: "single", plan: `docs/plans/${month}/${name}` }
463
+ : { source: "none", plan: null };
464
+ }
465
+
466
+ /** The `**Parent design:**` link target's FID and month in the text, or null. */
467
+ export function parentDesignLink(text: string): { fid: string; month: string } | null {
468
+ const m =
469
+ /\*\*Parent design:\*\*[^\n]*?docs\/plans\/([0-9]{6})\/([a-z0-9][a-z0-9-]*)-design\.md/.exec(
470
+ text,
471
+ );
472
+ return m ? { month: m[1]!, fid: m[2]! } : null;
473
+ }
474
+
475
+ /** The `WS-{N}` ids on the first `**Workstreams:**` line in the texts; [] when none. */
476
+ export function workstreamIds(...texts: string[]): string[] {
477
+ for (const text of texts) {
478
+ const line = /\*\*Workstreams:\*\*([^\n]*)/.exec(text)?.[1];
479
+ if (line !== undefined) return [...new Set(line.match(/WS-\d+/g) ?? [])];
480
+ }
481
+ return [];
482
+ }
483
+
484
+ /** Every `docs/audits/{YYYYMM}/*.md` path in the texts, first mention order, unique. */
485
+ export function auditPaths(...texts: string[]): string[] {
486
+ const seen = new Set<string>();
487
+ for (const text of texts) {
488
+ for (const m of text.matchAll(/docs\/audits\/[0-9]{6}\/[A-Za-z0-9._-]+\.md/g)) seen.add(m[0]);
489
+ }
490
+ return [...seen];
491
+ }
492
+
63
493
  /**
64
494
  * The canonical design doc for a feature, `docs/plans/{YYYYMM}/{fid}-design.md`: the
65
495
  * `month` bucket first, else the newest bucket holding one. null when none exists.
@@ -81,10 +511,46 @@ export function designDoc(
81
511
  return hit === undefined ? null : { month: hit, path: `docs/plans/${hit}/${fid}-design.md` };
82
512
  }
83
513
 
84
- /** `package.json` `bkit.issueTracker` at the main checkout (cwd outside git); default `none`. */
85
- export function readIssueTracker(cwd: string): IssueTracker {
514
+ /** `package.json` `bkit` config at the main checkout (cwd outside git). */
515
+ function mainConfig(cwd: string) {
86
516
  const common = git(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
87
- return readBkitConfig(common ? path.dirname(common) : cwd).issueTracker;
517
+ return readBkitConfig(common ? path.dirname(common) : cwd);
518
+ }
519
+
520
+ /** `package.json` `bkit.tracker.default` at the main checkout (cwd outside git); default `none`. */
521
+ export function readIssueTracker(cwd: string): IssueTracker {
522
+ return mainConfig(cwd).issueTracker;
523
+ }
524
+
525
+ /**
526
+ * Where this repo's issues live, per tracker: github the `origin` owner/repo (read from the
527
+ * remote, not gh, so a prompt parse makes no network call); linear `bkit.tracker.linear.team`; jira
528
+ * `bkit.tracker.jira.project` and `bkit.tracker.jira.site`. Each is null when unset.
529
+ */
530
+ function issueScope(cwd: string, tracker: IssueTracker): IssueScope {
531
+ if (tracker === "github") return { key: null, ownerRepo: originOwnerRepo(cwd), site: null };
532
+ if (tracker !== "linear" && tracker !== "jira") return { key: null };
533
+ const cfg = mainConfig(cwd);
534
+ return tracker === "linear"
535
+ ? { key: cfg.linear.team }
536
+ : { key: cfg.jira.project, site: cfg.jira.site };
537
+ }
538
+
539
+ /** The setting that names the issue-key prefix of a keyed tracker. */
540
+ const KEY_SETTING = {
541
+ linear: "bkit.tracker.linear.team",
542
+ jira: "bkit.tracker.jira.project",
543
+ } as const;
544
+
545
+ /** The stderr hint for bare keys skipped because no key prefix is configured. */
546
+ function skippedKeyHint(skipped: string[], tracker: "linear" | "jira"): string {
547
+ 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"`;
548
+ }
549
+
550
+ /** The current tree and the main checkout: where log folders are looked for. */
551
+ function fidRoots(cwd: string): string[] {
552
+ const top = git(cwd, ["rev-parse", "--show-toplevel"]) ?? cwd;
553
+ return [...new Set([top, repoRoot(cwd)])];
88
554
  }
89
555
 
90
556
  function trackerFlag(value: string | undefined, cwd: string, allowAny: boolean): FidTracker {
@@ -136,27 +602,69 @@ export interface ParsedFid {
136
602
  source: "marker" | "branch";
137
603
  }
138
604
 
139
- /** FID from the marker, when present and well-formed for the tracker. */
605
+ /**
606
+ * FID from the marker, when present and well-formed for the tracker. A wired tracker also
607
+ * accepts the FID-only marker of an issue-less run: its FID must be issue-less, and it
608
+ * resolves to `issueId: null`.
609
+ */
140
610
  export function fromMarker(text: string, tracker: IssueTracker): ParsedFid | null {
141
611
  const m = MARKERS[tracker].exec(text);
142
- if (!m) return null;
612
+ if (!m) {
613
+ if (tracker === "none") return null;
614
+ const bare = MARKERS.none.exec(text);
615
+ const fid = bare?.[1];
616
+ return fid !== undefined && ISSUE_LESS_FID.test(fid)
617
+ ? { fid, issueId: null, source: "marker" }
618
+ : null;
619
+ }
143
620
  const fid = normaliseFid(m[m.length - 1]!, tracker);
144
621
  if (!FID_PATTERNS[tracker].test(fid)) return null;
145
622
  const issueId = tracker === "none" ? null : KEYED.has(tracker) ? m[1]!.toUpperCase() : m[1]!;
146
623
  return { fid, issueId, source: "marker" };
147
624
  }
148
625
 
149
- /** FID from `feat/{FID}`; the slug check, then the issue id the tracker needs. */
626
+ /**
627
+ * The issue ids a repo's feature rows in `.bkit/issues.jsonl` carry in their FID keys,
628
+ * per the tracker's FID shape (`650-x` -> `650`; linear and jira keys uppercased).
629
+ */
630
+ export function featureIssueIds(root: string, tracker: IssueTracker): ReadonlySet<string> {
631
+ const file = path.join(root, ".bkit", "issues.jsonl");
632
+ const ids = new Set<string>();
633
+ if (tracker === "none" || !fs.existsSync(file) || !fs.statSync(file).isFile()) return ids;
634
+ for (const line of fs.readFileSync(file, "utf-8").split("\n")) {
635
+ if (line.trim() === "") continue;
636
+ const row = parseJson(line);
637
+ if (!row.ok || typeof row.value !== "object" || row.value === null) continue;
638
+ const { kind, key } = row.value as Record<string, unknown>;
639
+ if (kind !== "feature" || typeof key !== "string") continue;
640
+ const id = issueIdOf(key, tracker);
641
+ if (id !== null) ids.add(id);
642
+ }
643
+ return ids;
644
+ }
645
+
646
+ /**
647
+ * FID from `feat/{FID}`; the slug check, then the issue id the tracker needs. A wired
648
+ * tracker also accepts an issue-less FID (no issue id embedded, no all-digit word) as `issueId: null`.
649
+ * With `known` (the issue ids the repo's feature rows carry), the FID is the suffix verbatim
650
+ * for any slug: the issue id its shape embeds counts only when `known` holds it, else the
651
+ * run is issue-less (`issueId: null`).
652
+ */
150
653
  export function fromBranch(
151
654
  branch: string,
152
655
  tracker: IssueTracker,
656
+ known?: ReadonlySet<string>,
153
657
  ): { ok: true; parsed: ParsedFid } | { ok: false; why: string } {
154
658
  if (!branch.startsWith("feat/"))
155
659
  return { ok: false, why: `branch "${branch}" is not feat/{FID}` };
156
660
  const fid = branch.slice("feat/".length);
157
661
  if (!SLUG.test(fid)) return { ok: false, why: `"${fid}" is not a slug (${SLUG.source})` };
158
662
  const issueId = issueIdOf(fid, tracker);
159
- if (tracker !== "none" && issueId === null) {
663
+ if (known !== undefined) {
664
+ const linked = issueId !== null && known.has(issueId) ? issueId : null;
665
+ return { ok: true, parsed: { fid, issueId: linked, source: "branch" } };
666
+ }
667
+ if (tracker !== "none" && issueId === null && !ISSUE_LESS_FID.test(fid)) {
160
668
  return { ok: false, why: `"${fid}" embeds no ${tracker} issue id` };
161
669
  }
162
670
  return { ok: true, parsed: { fid, issueId, source: "branch" } };
@@ -165,32 +673,41 @@ export function fromBranch(
165
673
  const TRACKER_FLAG: FlagSpec = {
166
674
  name: "tracker",
167
675
  type: "string",
168
- help: "github | linear | jira | none (default: package.json bkit.issueTracker, else none)",
676
+ help: "github | linear | jira | none (default: package.json bkit.tracker.default, else none)",
169
677
  };
170
678
 
171
679
  export const fidsCommand: CommandSpec = {
172
680
  noun: "fids",
173
- summary: "Feature-id format per tracker, and FID recovery from a branch or PR-body marker.",
681
+ summary:
682
+ "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.",
174
683
  verbs: {
175
684
  check: {
176
685
  summary: "Validate a FID for the tracker: exit 0 valid, exit 1 not.",
686
+ use: "by-hand",
177
687
  flags: [
178
688
  { name: "fid", type: "string", required: true, help: "feature id to check" },
179
689
  { ...TRACKER_FLAG, help: `${TRACKER_FLAG.help}; any = any tracker's shape (CI_DEV)` },
690
+ {
691
+ name: "issue",
692
+ type: "string",
693
+ 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',
694
+ },
180
695
  ],
181
696
  output: {
182
697
  fid: "the FID as checked (linear, jira: lowercased)",
183
698
  tracker: "tracker the shape came from",
184
699
  valid: "true when the FID matches",
185
- pattern: "the regex checked",
700
+ pattern: "the regex checked (the slug rule when --issue is empty)",
186
701
  issueId: "issue id the FID embeds (null under none, or when invalid)",
187
702
  },
188
703
  run: (ctx) => {
189
704
  const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, true);
190
705
  const fid = normaliseFid(String(ctx.flags.fid), tracker);
191
- const pattern = FID_PATTERNS[tracker];
192
- const valid = pattern.test(fid);
193
- if (!valid) ctx.log(`FID "${fid}" does not match the ${tracker} shape ${pattern.source}`);
706
+ const issue = str(ctx.flags.issue)?.replace(/^#/, "");
707
+ const pattern = issue === "" && tracker !== "none" ? SLUG : FID_PATTERNS[tracker];
708
+ const problem = fidProblem(fid, tracker, issue);
709
+ const valid = problem === undefined;
710
+ if (!valid) ctx.log(problem);
194
711
  ctx.emit({
195
712
  fid,
196
713
  tracker,
@@ -202,8 +719,15 @@ export const fidsCommand: CommandSpec = {
202
719
  },
203
720
  },
204
721
  parse: {
205
- summary: "Recover FID and issue id: the PR-body marker first, then a feat/{FID} branch.",
722
+ summary:
723
+ "--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).",
724
+ use: "by-hand",
206
725
  flags: [
726
+ {
727
+ name: "prompt-file",
728
+ type: "string",
729
+ help: "the session prompt, written verbatim (Step 1: {SESSION_DIR}/prompt.md); not with --marker / --branch",
730
+ },
207
731
  {
208
732
  name: "marker",
209
733
  type: "string",
@@ -213,17 +737,77 @@ export const fidsCommand: CommandSpec = {
213
737
  TRACKER_FLAG,
214
738
  ],
215
739
  output: {
216
- fid: "the recovered FID",
217
- issueId: "tracker issue id (null under none)",
218
- source: "marker | branch",
219
- tracker: "tracker the shapes came from",
740
+ source:
741
+ "--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",
742
+ issue:
743
+ '--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 ""',
744
+ ambiguous:
745
+ "--prompt-file, exit 8 only: the issues named, as a person types them (then no other key prints)",
746
+ ref: '--prompt-file: the issue as a person types it (github: #N, linear / jira: the key), else ""',
747
+ fidNamed:
748
+ "--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",
749
+ fid: "--marker / --branch: the recovered FID",
750
+ issueId:
751
+ "--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)",
752
+ tracker: "--marker / --branch: tracker the shapes came from",
753
+ },
754
+ exitCodes: {
755
+ [EXIT_NO_FID]:
756
+ "neither the marker nor the branch yielded a FID (a branch that is not feat/ or whose suffix is not a slug)",
757
+ [EXIT_NO_FILE]: "the --prompt-file is missing",
758
+ [EXIT_AMBIGUOUS]: `--prompt-file names more than one issue (explicit forms first) — ${NAME_THE_ISSUE}`,
220
759
  },
221
- exitCodes: { [EXIT_NO_FID]: "neither the marker nor the branch yielded a valid FID" },
222
760
  run: (ctx) => {
223
761
  const marker = str(ctx.flags.marker);
224
762
  const branch = str(ctx.flags.branch);
763
+ const promptFile = str(ctx.flags.promptFile);
764
+ if (promptFile !== undefined) {
765
+ if (marker !== undefined || branch !== undefined)
766
+ throw new CommandError(
767
+ EXIT.USAGE,
768
+ "--prompt-file goes alone, without --marker / --branch",
769
+ );
770
+ const text = readNamed(path.resolve(ctx.cwd, promptFile), "prompt-file");
771
+ const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, false) as IssueTracker;
772
+ const scope = issueScope(ctx.cwd, tracker);
773
+ const key = scope.key ?? null;
774
+ const refs = issueRefs(text, tracker, scope);
775
+ const candidates = issueCandidates(refs);
776
+ if (candidates.length > 1) {
777
+ const named = candidates.map((c) => issueRef(c, tracker));
778
+ ctx.log(
779
+ `the prompt names more than one issue (${named.join(", ")}); ${NAME_THE_ISSUE}`,
780
+ );
781
+ ctx.emit({ ambiguous: named });
782
+ return EXIT_AMBIGUOUS;
783
+ }
784
+ const issue = candidates[0] ?? "";
785
+ const others = [...new Set([...refs.explicit, ...refs.bare].map((r) => r.value))].filter(
786
+ (v) => v !== issue,
787
+ );
788
+ if (others.length > 0)
789
+ ctx.log(
790
+ `taking ${issueRef(issue, tracker)}, named explicitly; not the bare mention ${others.map((o) => issueRef(o, tracker)).join(", ")}`,
791
+ );
792
+ const bareNumber = bareNumbers(text)[0];
793
+ if (issue === "" && tracker !== "none" && bareNumber !== undefined)
794
+ ctx.log(bareNumberHint(bareNumber, tracker, key));
795
+ if (
796
+ issue === "" &&
797
+ refs.skipped.length > 0 &&
798
+ (tracker === "linear" || tracker === "jira")
799
+ )
800
+ ctx.log(skippedKeyHint([...new Set(refs.skipped.map((h) => h.value))], tracker));
801
+ ctx.emit({
802
+ source: issue === "" ? "none" : tracker,
803
+ issue,
804
+ ref: issueRef(issue, tracker),
805
+ fidNamed: namedFid(text, fidRoots(ctx.cwd)),
806
+ });
807
+ return EXIT.OK;
808
+ }
225
809
  if (marker === undefined && branch === undefined) {
226
- throw new CommandError(EXIT.USAGE, "give --marker, --branch, or both");
810
+ throw new CommandError(EXIT.USAGE, "give --prompt-file, or --marker, --branch, or both");
227
811
  }
228
812
  const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, false) as IssueTracker;
229
813
  const viaMarker = marker === undefined ? null : fromMarker(marker, tracker);
@@ -234,7 +818,8 @@ export const fidsCommand: CommandSpec = {
234
818
  if (marker !== undefined)
235
819
  ctx.log(`no well-formed ${tracker} bkit:fid marker — trying the branch`);
236
820
  if (branch === undefined) return EXIT_NO_FID;
237
- const viaBranch = fromBranch(branch, tracker);
821
+ const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
822
+ const viaBranch = fromBranch(branch, tracker, featureIssueIds(top, tracker));
238
823
  if (!viaBranch.ok) {
239
824
  ctx.log(viaBranch.why);
240
825
  return EXIT_NO_FID;
@@ -243,9 +828,143 @@ export const fidsCommand: CommandSpec = {
243
828
  return EXIT.OK;
244
829
  },
245
830
  },
831
+ resolve: {
832
+ summary:
833
+ "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).",
834
+ use: "workflow",
835
+ flags: [
836
+ {
837
+ name: "prompt-file",
838
+ type: "string",
839
+ required: true,
840
+ help: "the session prompt, written verbatim ({SESSION_DIR}/prompt.md)",
841
+ },
842
+ {
843
+ name: "issue",
844
+ type: "string",
845
+ help: 'the run\'s issue id (github: 123; linear / jira: ABC-123), or "" / absent for a run with no issue',
846
+ },
847
+ {
848
+ name: "title-file",
849
+ type: "string",
850
+ help: "the issue title: a JSON object with a title key, else the file's text; drop it for a run with no issue",
851
+ },
852
+ {
853
+ ...WORKFLOW_FLAG,
854
+ help: "the workflow starting; an in-progress run of it continues a used mint instead of suffixing",
855
+ },
856
+ TRACKER_FLAG,
857
+ ],
858
+ output: {
859
+ fid: "the FID to use",
860
+ source:
861
+ "prompt | branch | logged | minted | suffixed — the link of the chain that gave fid",
862
+ month: "the newest bucket holding logs/{fid}/, else null",
863
+ existing: "true when logs/{fid}/ exists in some bucket",
864
+ fids: "every FID logged for the issue (working tree and dev) when the chain reached that link, else []",
865
+ },
866
+ exitCodes: {
867
+ [EXIT_SEVERAL]: "several features are logged for the issue — name one in the prompt",
868
+ [EXIT_NO_FREE]: "the mint and every -b … -z suffix of it are used by finished runs",
869
+ [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}`,
870
+ [EXIT_NO_FILE]: "the --prompt-file or --title-file is missing",
871
+ },
872
+ run: (ctx) => {
873
+ const tracker = trackerFlag(str(ctx.flags.tracker), ctx.cwd, false) as IssueTracker;
874
+ const issue = (str(ctx.flags.issue) ?? "").replace(/^#/, "");
875
+ const prompt = readNamed(
876
+ path.resolve(ctx.cwd, String(ctx.flags.promptFile)),
877
+ "prompt-file",
878
+ );
879
+ const titleFile = str(ctx.flags.titleFile);
880
+ const title =
881
+ titleFile === undefined
882
+ ? ""
883
+ : titleOf(readNamed(path.resolve(ctx.cwd, titleFile), "title-file"));
884
+ const workflow = String(ctx.flags.workflow);
885
+ const roots = fidRoots(ctx.cwd);
886
+ const branch = git(ctx.cwd, ["branch", "--show-current"]) || null;
887
+ const prefix = KEYED.has(tracker) ? `${issue.toLowerCase()}-` : `${issue}-`;
888
+
889
+ let fids: string[] = [];
890
+ let pick: { fid: string; source: string } | null = null;
891
+ const named = namedFid(prompt, roots);
892
+ if (named !== null) pick = { fid: named, source: "prompt" };
893
+ const onBranch = branch?.startsWith("feat/") ? branch.slice("feat/".length) : null;
894
+ if (pick === null && onBranch !== null && SLUG.test(onBranch)) {
895
+ if (issue === "" || onBranch.startsWith(prefix))
896
+ pick = { fid: onBranch, source: "branch" };
897
+ }
898
+ if (pick === null && issue !== "") {
899
+ fids = [
900
+ ...new Set([...roots.flatMap((r) => logged(r, issue)), ...loggedOnDev(ctx.cwd, issue)]),
901
+ ].sort();
902
+ if (fids.length > 1) {
903
+ ctx.log(`several features logged for ${issue}: ${fids.join(", ")}`);
904
+ ctx.emit({ fid: null, source: null, month: null, existing: false, fids });
905
+ return EXIT_SEVERAL;
906
+ }
907
+ if (fids.length === 1) pick = { fid: fids[0]!, source: "logged" };
908
+ }
909
+ const bareNumber = bareNumbers(prompt)[0];
910
+ if (
911
+ pick === null &&
912
+ issue === "" &&
913
+ tracker !== "none" &&
914
+ bareNumber !== undefined &&
915
+ slugWords(title).length === 0 &&
916
+ slugWords(prompt).length === 0
917
+ ) {
918
+ ctx.log(
919
+ `${bareNumberHint(bareNumber, tracker, issueScope(ctx.cwd, tracker).key ?? null)} — refusing to mint a FID from the workflow name alone`,
920
+ );
921
+ return EXIT_BARE_NUMBER;
922
+ }
923
+ if (pick === null) {
924
+ const minted = normaliseFid(mintFid({ issue, title, prompt, branch, workflow }), tracker);
925
+ const free = freeFid(roots, minted, workflow);
926
+ if (free === null) {
927
+ ctx.log(`"${minted}" and every -b … -z suffix of it are used by finished runs`);
928
+ return EXIT_NO_FREE;
929
+ }
930
+ pick = { fid: free, source: free === minted ? "minted" : "suffixed" };
931
+ }
932
+ const fid = normaliseFid(pick.fid, tracker);
933
+ const problem = fidProblem(fid, tracker, issue);
934
+ if (problem !== undefined) {
935
+ ctx.log(`${pick.source} FID: ${problem}`);
936
+ return EXIT.NO;
937
+ }
938
+ const month =
939
+ roots
940
+ .flatMap((r) => monthBuckets(r, fid))
941
+ .sort()
942
+ .at(-1) ?? null;
943
+ ctx.emit({ fid, source: pick.source, month, existing: month !== null, fids });
944
+ return EXIT.OK;
945
+ },
946
+ },
947
+ plans: {
948
+ summary: "A feature's plan in a month bucket: docs/plans/{YYYYMM}/{FID}-plan.md, or none.",
949
+ use: "by-hand",
950
+ flags: [
951
+ { name: "fid", type: "string", required: true, help: "feature id" },
952
+ { name: "month", type: "string", required: true, help: "YYYYMM bucket" },
953
+ ],
954
+ output: {
955
+ source: "single ({FID}-plan.md exists) | none (no plan file)",
956
+ plan: "the repo-relative plan file, or null",
957
+ },
958
+ run: (ctx) => {
959
+ const top = git(ctx.cwd, ["rev-parse", "--show-toplevel"]) ?? ctx.cwd;
960
+ ctx.emit(planFiles(top, String(ctx.flags.fid), String(ctx.flags.month)));
961
+ return EXIT.OK;
962
+ },
963
+ },
246
964
  design: {
247
965
  summary:
248
- "The feature's own design doc, docs/plans/{YYYYMM}/{FID}-design.md: exit 0 found, exit 1 none.",
966
+ "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).",
967
+ use: "by-hand",
249
968
  flags: [
250
969
  { name: "fid", type: "string", required: true, help: "feature id" },
251
970
  {
@@ -253,23 +972,82 @@ export const fidsCommand: CommandSpec = {
253
972
  type: "string",
254
973
  help: "YYYYMM bucket checked first; else the newest bucket holding the doc",
255
974
  },
975
+ {
976
+ name: "description-file",
977
+ type: "string",
978
+ help: "the issue description; drop it for a run with no issue",
979
+ },
980
+ {
981
+ name: "prompt-file",
982
+ type: "string",
983
+ help: "the session prompt ({SESSION_DIR}/prompt.md)",
984
+ },
256
985
  ],
257
986
  output: {
258
- fid: "the FID when its design doc exists, else null",
987
+ fid: "the FID when its own design doc exists, else null",
259
988
  month: "the bucket holding it, else null",
260
989
  path: "repo-relative path, else null",
990
+ parentFid: "the parent design's FID (the link's, else the feature's own), else null",
991
+ parentMonth: "its bucket, else null",
992
+ parentPath: "its repo-relative path, else null",
993
+ parentSource: "link | fid | null",
994
+ auditPaths:
995
+ "every docs/audits/{YYYYMM}/*.md path the description, then the prompt, names, first mention order",
996
+ workstreams:
997
+ "the WS-{N} ids the first **Workstreams:** line (description, then prompt) names: the plan covers only those; [] = the whole design",
998
+ },
999
+ exitCodes: {
1000
+ [EXIT_NO_FILE]:
1001
+ "a --description-file / --prompt-file is missing, or a linked design or named audit path is not a file",
261
1002
  },
262
1003
  run: (ctx) => {
263
1004
  const fid = String(ctx.flags.fid);
264
- const hit = designDoc(repoRoot(ctx.cwd), fid, str(ctx.flags.month));
265
- ctx.emit(
266
- hit ? { fid, month: hit.month, path: hit.path } : { fid: null, month: null, path: null },
267
- );
268
- return hit ? EXIT.OK : EXIT.NO;
1005
+ const root = repoRoot(ctx.cwd);
1006
+ const texts = (["descriptionFile", "promptFile"] as const).flatMap((k) => {
1007
+ const file = str(ctx.flags[k]);
1008
+ return file === undefined
1009
+ ? []
1010
+ : [
1011
+ readNamed(
1012
+ path.resolve(ctx.cwd, file),
1013
+ k === "promptFile" ? "prompt-file" : "description-file",
1014
+ ),
1015
+ ];
1016
+ });
1017
+ const own = designDoc(root, fid, str(ctx.flags.month));
1018
+ const link = texts.map(parentDesignLink).find((l) => l !== null) ?? null;
1019
+ const parent = link
1020
+ ? {
1021
+ fid: link.fid,
1022
+ month: link.month,
1023
+ path: `docs/plans/${link.month}/${link.fid}-design.md`,
1024
+ source: "link",
1025
+ }
1026
+ : own
1027
+ ? { fid, month: own.month, path: own.path, source: "fid" }
1028
+ : null;
1029
+ const audits = auditPaths(...texts);
1030
+ for (const rel of [...(link && parent ? [parent.path] : []), ...audits]) {
1031
+ if (!fs.statSync(path.join(root, rel), { throwIfNoEntry: false })?.isFile())
1032
+ throw new CommandError(EXIT_NO_FILE, `${rel} is named but is not a file`);
1033
+ }
1034
+ ctx.emit({
1035
+ ...(own
1036
+ ? { fid, month: own.month, path: own.path }
1037
+ : { fid: null, month: null, path: null }),
1038
+ parentFid: parent?.fid ?? null,
1039
+ parentMonth: parent?.month ?? null,
1040
+ parentPath: parent?.path ?? null,
1041
+ parentSource: parent?.source ?? null,
1042
+ auditPaths: audits,
1043
+ workstreams: workstreamIds(...texts),
1044
+ });
1045
+ return parent ? EXIT.OK : EXIT.NO;
269
1046
  },
270
1047
  },
271
1048
  find: {
272
1049
  summary: "The feature already logged for an issue: exit 0 one, exit 1 none, exit 4 several.",
1050
+ use: "by-hand",
273
1051
  flags: [
274
1052
  {
275
1053
  name: "issue",