@cbartens/bkit 0.0.0-stage → 5.0.1

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 (375) hide show
  1. package/.bkit/README.md +417 -0
  2. package/.bkit/core/.agents/context.md +95 -0
  3. package/.bkit/core/.agents/docs.md +62 -0
  4. package/.bkit/core/.agents/rules.md +147 -0
  5. package/.bkit/core/.agents/skills.md +43 -0
  6. package/.bkit/core/.bkit/LICENSE.md +151 -0
  7. package/.bkit/core/.bkit/README.md +417 -0
  8. package/.bkit/core/.bkit/cloud.md +493 -0
  9. package/.bkit/core/.bkit/comparison.md +321 -0
  10. package/.bkit/core/.bkit/install.md +401 -0
  11. package/.bkit/core/.bkit/jsonl.md +497 -0
  12. package/.bkit/core/.bkit/prompts.md +474 -0
  13. package/.bkit/core/.bkit/providers.md +598 -0
  14. package/.bkit/core/.bkit/templates.md +470 -0
  15. package/.bkit/core/.bkit/trackers.md +95 -0
  16. package/.bkit/core/.bkit/workflows.md +1550 -0
  17. package/.bkit/core/.claude/hooks/bkit-gateguard.cjs +82 -0
  18. package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +93 -0
  19. package/.bkit/core/.claude/hooks/bkit-preflight.sh +74 -0
  20. package/.bkit/core/.codex/hooks/bkit-gateguard.cjs +115 -0
  21. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +135 -0
  22. package/.bkit/core/.cursor/hooks/bkit-gateguard.cjs +111 -0
  23. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +169 -0
  24. package/.bkit/core/.cursor/hooks/bkit-preflight.sh +63 -0
  25. package/.bkit/core/.opencode/plugin/bkit-gateguard.js +225 -0
  26. package/.bkit/core/AGENTS.md +77 -0
  27. package/.bkit/core/LICENSE.md +149 -0
  28. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +272 -0
  29. package/.bkit/core/docs/templates/bkit-audit-adoption.md +223 -0
  30. package/.bkit/core/docs/templates/bkit-audit-agents.md +230 -0
  31. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +227 -0
  32. package/.bkit/core/docs/templates/bkit-audit-analytics.md +266 -0
  33. package/.bkit/core/docs/templates/bkit-audit-annotations.md +230 -0
  34. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +270 -0
  35. package/.bkit/core/docs/templates/bkit-audit-app-store.md +254 -0
  36. package/.bkit/core/docs/templates/bkit-audit-architecture.md +221 -0
  37. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +241 -0
  38. package/.bkit/core/docs/templates/bkit-audit-config.md +230 -0
  39. package/.bkit/core/docs/templates/bkit-audit-cost.md +218 -0
  40. package/.bkit/core/docs/templates/bkit-audit-coverage.md +221 -0
  41. package/.bkit/core/docs/templates/bkit-audit-database.md +229 -0
  42. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +251 -0
  43. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +283 -0
  44. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +268 -0
  45. package/.bkit/core/docs/templates/bkit-audit-documentation.md +280 -0
  46. package/.bkit/core/docs/templates/bkit-audit-duplication.md +253 -0
  47. package/.bkit/core/docs/templates/bkit-audit-failures.md +259 -0
  48. package/.bkit/core/docs/templates/bkit-audit-flakes.md +237 -0
  49. package/.bkit/core/docs/templates/bkit-audit-gates.md +250 -0
  50. package/.bkit/core/docs/templates/bkit-audit-issues.md +273 -0
  51. package/.bkit/core/docs/templates/bkit-audit-llm.md +239 -0
  52. package/.bkit/core/docs/templates/bkit-audit-logs.md +266 -0
  53. package/.bkit/core/docs/templates/bkit-audit-models.md +210 -0
  54. package/.bkit/core/docs/templates/bkit-audit-privacy.md +211 -0
  55. package/.bkit/core/docs/templates/bkit-audit-prompts.md +216 -0
  56. package/.bkit/core/docs/templates/bkit-audit-red-team.md +220 -0
  57. package/.bkit/core/docs/templates/bkit-audit-reliability.md +222 -0
  58. package/.bkit/core/docs/templates/bkit-audit-repo.md +224 -0
  59. package/.bkit/core/docs/templates/bkit-audit-security.md +274 -0
  60. package/.bkit/core/docs/templates/bkit-audit-slop.md +200 -0
  61. package/.bkit/core/docs/templates/bkit-audit-testing.md +270 -0
  62. package/.bkit/core/docs/templates/bkit-audit-usability.md +237 -0
  63. package/.bkit/core/docs/templates/bkit-plan.md +476 -0
  64. package/.bkit/core/engine/checks/after/auth.ts +149 -0
  65. package/.bkit/core/engine/checks/after/ci-yml.ts +701 -0
  66. package/.bkit/core/engine/checks/after/github.ts +424 -0
  67. package/.bkit/core/engine/checks/after/index.ts +530 -0
  68. package/.bkit/core/engine/checks/after/managed.ts +217 -0
  69. package/.bkit/core/engine/checks/after/suppression.ts +53 -0
  70. package/.bkit/core/engine/checks/after/tools.ts +427 -0
  71. package/.bkit/core/engine/checks/before/context-fetch.ts +429 -0
  72. package/.bkit/core/engine/checks/before/env.ts +187 -0
  73. package/.bkit/core/engine/checks/before/files.ts +204 -0
  74. package/.bkit/core/engine/checks/before/index.ts +206 -0
  75. package/.bkit/core/engine/checks/before/mcp.ts +127 -0
  76. package/.bkit/core/engine/checks/before/repo.ts +77 -0
  77. package/.bkit/core/engine/checks/before/version.ts +67 -0
  78. package/.bkit/core/engine/checks/status-holes.ts +479 -0
  79. package/.bkit/core/engine/cli.ts +867 -0
  80. package/.bkit/core/engine/commands/analysis.ts +550 -0
  81. package/.bkit/core/engine/commands/ci/ci.ts +483 -0
  82. package/.bkit/core/engine/commands/comply.ts +415 -0
  83. package/.bkit/core/engine/commands/harvest.ts +459 -0
  84. package/.bkit/core/engine/commands/install/check.ts +70 -0
  85. package/.bkit/core/engine/commands/install/doctor.ts +254 -0
  86. package/.bkit/core/engine/commands/install/install.ts +550 -0
  87. package/.bkit/core/engine/commands/install/uninstall.ts +995 -0
  88. package/.bkit/core/engine/commands/install/upgrade.ts +1037 -0
  89. package/.bkit/core/engine/commands/launch.ts +139 -0
  90. package/.bkit/core/engine/commands/lib.ts +495 -0
  91. package/.bkit/core/engine/commands/registry.ts +53 -0
  92. package/.bkit/core/engine/commands/setup/setup.ts +184 -0
  93. package/.bkit/core/engine/commands/telemetry.ts +32 -0
  94. package/.bkit/core/engine/commands/workflow/branches.ts +1514 -0
  95. package/.bkit/core/engine/commands/workflow/context.ts +961 -0
  96. package/.bkit/core/engine/commands/workflow/counters.ts +268 -0
  97. package/.bkit/core/engine/commands/workflow/fids.ts +243 -0
  98. package/.bkit/core/engine/commands/workflow/issues.ts +675 -0
  99. package/.bkit/core/engine/commands/workflow/ledgers.ts +575 -0
  100. package/.bkit/core/engine/commands/workflow/locks.ts +478 -0
  101. package/.bkit/core/engine/commands/workflow/prs.ts +1087 -0
  102. package/.bkit/core/engine/commands/workflow/repo.ts +220 -0
  103. package/.bkit/core/engine/commands/workflow/roadmap.ts +576 -0
  104. package/.bkit/core/engine/commands/workflow/runs.ts +2140 -0
  105. package/.bkit/core/engine/commands/workflow/runtime.ts +300 -0
  106. package/.bkit/core/engine/commands/workflow/skills.ts +118 -0
  107. package/.bkit/core/engine/commands/workflow/status.ts +455 -0
  108. package/.bkit/core/engine/commands/workflow/steps.ts +1300 -0
  109. package/.bkit/core/engine/commands/workflow/tests.ts +161 -0
  110. package/.bkit/core/engine/commands/workflow/workflows.ts +1573 -0
  111. package/.bkit/core/engine/commands/workflow/workstreams.ts +164 -0
  112. package/.bkit/core/engine/commands/workflow/worktrees.ts +534 -0
  113. package/.bkit/core/engine/install/cloud-env.ts +924 -0
  114. package/.bkit/core/engine/install/managed-block.ts +212 -0
  115. package/.bkit/core/engine/install/manifest.ts +448 -0
  116. package/.bkit/core/engine/install/modules/claude.ts +362 -0
  117. package/.bkit/core/engine/install/modules/cloud.ts +173 -0
  118. package/.bkit/core/engine/install/modules/codex.ts +219 -0
  119. package/.bkit/core/engine/install/modules/core.ts +620 -0
  120. package/.bkit/core/engine/install/modules/cursor.ts +231 -0
  121. package/.bkit/core/engine/install/modules/index.ts +242 -0
  122. package/.bkit/core/engine/install/modules/opencode.ts +573 -0
  123. package/.bkit/core/engine/install/payload-links.ts +150 -0
  124. package/.bkit/core/engine/install/placeholders.ts +108 -0
  125. package/.bkit/core/engine/install/template-copies.ts +119 -0
  126. package/.bkit/core/engine/install/version-file.ts +284 -0
  127. package/.bkit/core/engine/install/write.ts +467 -0
  128. package/.bkit/core/engine/ledgers/clamp-log.ts +32 -0
  129. package/.bkit/core/engine/ledgers/status.ts +213 -0
  130. package/.bkit/core/engine/ledgers/telemetry.ts +1143 -0
  131. package/.bkit/core/engine/render/hosts.ts +372 -0
  132. package/.bkit/core/engine/render/models.ts +323 -0
  133. package/.bkit/core/engine/render/parts.ts +38 -0
  134. package/.bkit/core/engine/render/trackers.ts +170 -0
  135. package/.bkit/core/engine/shared/egress.ts +345 -0
  136. package/.bkit/core/engine/shared/json.ts +16 -0
  137. package/.bkit/core/engine/shared/log-prefix.ts +9 -0
  138. package/.bkit/core/engine/shared/package-json.ts +29 -0
  139. package/.bkit/core/engine/shared/package-manager.ts +38 -0
  140. package/.bkit/core/engine/shared/package-roots.ts +163 -0
  141. package/.bkit/core/engine/shared/protected-paths.ts +164 -0
  142. package/.bkit/core/engine/shared/settings.ts +72 -0
  143. package/.bkit/core/engine/shared/timeouts.ts +20 -0
  144. package/.bkit/core/engine/tools/wording.ts +748 -0
  145. package/.bkit/core/hooks/gateguard-edit-payload.js +18 -0
  146. package/.bkit/core/hooks/gateguard-engine.js +193 -0
  147. package/.bkit/core/hooks/guardrails-shell.js +154 -0
  148. package/.bkit/core/hooks/guardrails-tiers.js +68 -0
  149. package/.bkit/core/hooks/preflight-linear.sh +73 -0
  150. package/.bkit/core/prompts/bkit-audit-generate.md +66 -0
  151. package/.bkit/core/prompts/bkit-build-challenge-1.md +79 -0
  152. package/.bkit/core/prompts/bkit-build-challenge-2.md +81 -0
  153. package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +68 -0
  154. package/.bkit/core/prompts/bkit-build-challenge-remediate.md +70 -0
  155. package/.bkit/core/prompts/bkit-build-challenge-tests.md +73 -0
  156. package/.bkit/core/prompts/bkit-build-install-skills.md +67 -0
  157. package/.bkit/core/prompts/bkit-build-plan-current.md +75 -0
  158. package/.bkit/core/prompts/bkit-build-plan-execute.md +72 -0
  159. package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +73 -0
  160. package/.bkit/core/prompts/bkit-build-plan-verify.md +88 -0
  161. package/.bkit/core/prompts/bkit-build-summary.md +93 -0
  162. package/.bkit/core/prompts/bkit-debug-abort-handover.md +90 -0
  163. package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +151 -0
  164. package/.bkit/core/prompts/bkit-debug-failure-remediate.md +78 -0
  165. package/.bkit/core/prompts/bkit-debug-failure-soak.md +73 -0
  166. package/.bkit/core/prompts/bkit-debug-summary.md +95 -0
  167. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +72 -0
  168. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +72 -0
  169. package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +75 -0
  170. package/.bkit/core/prompts/bkit-design-generate.md +110 -0
  171. package/.bkit/core/prompts/bkit-design-organise.md +85 -0
  172. package/.bkit/core/prompts/bkit-design-review-1.md +121 -0
  173. package/.bkit/core/prompts/bkit-design-review-2.md +111 -0
  174. package/.bkit/core/prompts/bkit-design-spike.md +97 -0
  175. package/.bkit/core/prompts/bkit-design-summary.md +106 -0
  176. package/.bkit/core/prompts/bkit-design-update.md +66 -0
  177. package/.bkit/core/prompts/bkit-plan-complexity-check.md +66 -0
  178. package/.bkit/core/prompts/bkit-plan-complexity-split.md +87 -0
  179. package/.bkit/core/prompts/bkit-plan-generate.md +74 -0
  180. package/.bkit/core/prompts/bkit-plan-review-1.md +90 -0
  181. package/.bkit/core/prompts/bkit-plan-review-2.md +80 -0
  182. package/.bkit/core/prompts/bkit-plan-review-3.md +92 -0
  183. package/.bkit/core/prompts/bkit-plan-scope-check-1.md +84 -0
  184. package/.bkit/core/prompts/bkit-plan-scope-check-2.md +84 -0
  185. package/.bkit/core/prompts/bkit-plan-summary.md +106 -0
  186. package/.bkit/core/prompts/bkit-plan-update.md +68 -0
  187. package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +90 -0
  188. package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +94 -0
  189. package/.bkit/core/prompts/bkit-ship-summary.md +77 -0
  190. package/.bkit/core/prompts/bkit-ship-update-docs.md +71 -0
  191. package/.bkit/core/prompts/bkit-utility-compress-markdown.md +91 -0
  192. package/.bkit/core/prompts/bkit-utility-update-decisions.md +75 -0
  193. package/.bkit/core/prompts/bkit-utility-update-deferrals.md +76 -0
  194. package/.bkit/core/prompts/bkit-utility-update-documentation.md +61 -0
  195. package/.bkit/core/prompts/bkit-utility-update-failures.md +76 -0
  196. package/.bkit/core/prompts/bkit-utility-update-knowledge.md +75 -0
  197. package/.bkit/core/prompts/bkit-utility-update-roadmap.md +82 -0
  198. package/.bkit/core/workflows/bkit-auto.md +121 -0
  199. package/.bkit/core/workflows/bkit-build.md +802 -0
  200. package/.bkit/core/workflows/bkit-debug.md +649 -0
  201. package/.bkit/core/workflows/bkit-design.md +495 -0
  202. package/.bkit/core/workflows/bkit-plan.md +510 -0
  203. package/.bkit/core/workflows/bkit-ship.md +650 -0
  204. package/.bkit/shared/.bkit/.env.example +86 -0
  205. package/.bkit/shared/.claude/bkit-cloud.md +117 -0
  206. package/.bkit/shared/.claude/settings.json +88 -0
  207. package/.bkit/shared/.codex/hooks.json +26 -0
  208. package/.bkit/shared/.cursor/bkit-cloud.md +84 -0
  209. package/.bkit/shared/.cursor/hooks.json +26 -0
  210. package/.bkit/shared/.cursor/mcp.json +15 -0
  211. package/.bkit/shared/.cursor/rules/bkit-rules.mdc +12 -0
  212. package/.bkit/shared/.gitattributes +37 -0
  213. package/.bkit/shared/.mcp.json +16 -0
  214. package/.bkit/shared/.opencode/opencode.json +62 -0
  215. package/.bkit/shared/CLAUDE.md +11 -0
  216. package/.bkit/shared/LICENSE.md +22 -0
  217. package/.bkit/shared/docs/architecture.md +19 -0
  218. package/.bkit/shared/docs/data-schema.md +19 -0
  219. package/.bkit/shared/docs/deployments.md +433 -0
  220. package/.bkit/shared/docs/design.md +39 -0
  221. package/.bkit/shared/docs/noise.md +19 -0
  222. package/.bkit/shared/docs/observability.md +25 -0
  223. package/.bkit/shared/docs/security.md +42 -0
  224. package/.bkit/shared/docs/setup.md +30 -0
  225. package/.bkit/shared/docs/technology.md +18 -0
  226. package/.bkit/shared/docs/testing.md +413 -0
  227. package/.bkit/shared/gitignore +97 -0
  228. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +187 -0
  229. package/.bkit/templates/.cursor/Dockerfile +68 -0
  230. package/.bkit/templates/.cursor/environment.json +6 -0
  231. package/.bkit/templates/.cursor/settings.json +11 -0
  232. package/.bkit/templates/.envrc +7 -0
  233. package/.bkit/templates/.github/dependabot.yml +52 -0
  234. package/.bkit/templates/.github/renovate.json5 +224 -0
  235. package/.bkit/templates/.github/workflows/bkit-ci.yml +1062 -0
  236. package/.bkit/templates/.github/workflows/bkit-cloud.yml +564 -0
  237. package/.bkit/templates/.github/workflows/bkit-renovate.yml +102 -0
  238. package/.bkit/templates/.graphifyignore +108 -0
  239. package/.bkit/templates/.husky/pre-commit +16 -0
  240. package/.bkit/templates/.husky/pre-push +91 -0
  241. package/.bkit/templates/.lintstagedrc.json +3 -0
  242. package/.bkit/templates/.prettierignore +41 -0
  243. package/.bkit/templates/.serena/project.yml +243 -0
  244. package/.bkit/templates/.vale/styles/House/Filler.yml +11 -0
  245. package/.bkit/templates/.vale/styles/House/Hedging.yml +12 -0
  246. package/.bkit/templates/.vale/styles/House/LLMSlop.yml +13 -0
  247. package/.bkit/templates/.vale/styles/House/Verbose.yml +12 -0
  248. package/.bkit/templates/.vale.ini +67 -0
  249. package/.bkit/templates/LICENSE.md +22 -0
  250. package/.bkit/templates/context/bkit-cloudrun.md +84 -0
  251. package/.bkit/templates/context/bkit-expo.md +186 -0
  252. package/.bkit/templates/context/bkit-github.md +79 -0
  253. package/.bkit/templates/context/bkit-inngest.md +45 -0
  254. package/.bkit/templates/context/bkit-maestro.md +76 -0
  255. package/.bkit/templates/context/bkit-playwright.md +62 -0
  256. package/.bkit/templates/context/bkit-resend.md +36 -0
  257. package/.bkit/templates/context/bkit-sentry.md +65 -0
  258. package/.bkit/templates/context/bkit-serena.md +33 -0
  259. package/.bkit/templates/context/bkit-stripe.md +36 -0
  260. package/.bkit/templates/context/bkit-supabase.md +59 -0
  261. package/.bkit/templates/context/bkit-tavily.md +49 -0
  262. package/.bkit/templates/context/bkit-vercel.md +64 -0
  263. package/.bkit/templates/docs/capabilities.md +72 -0
  264. package/.bkit/templates/scripts/ci/accepted-divergences.json +21 -0
  265. package/.bkit/templates/scripts/ci/check-accepted-divergences.mjs +152 -0
  266. package/.bkit/templates/scripts/ci/check-accepted-divergences.test.mjs +130 -0
  267. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.mjs +98 -0
  268. package/.bkit/templates/scripts/ci/lanes/resolve-push-base.test.mjs +86 -0
  269. package/.bkit/templates/scripts/graphify/bkit-graph-drift-rules.json +23 -0
  270. package/.bkit/templates/scripts/graphify/bkit-graph-drift.py +208 -0
  271. package/.bkit/templates/scripts/graphify/bkit-graph-eager-rules.json +35 -0
  272. package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +236 -0
  273. package/.bkit/templates/scripts/graphify/bkit-graph-external-rules.json +17 -0
  274. package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +290 -0
  275. package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +19 -0
  276. package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +120 -0
  277. package/.bkit/templates/scripts/graphify/bkit-graph-surface.py +232 -0
  278. package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +36 -0
  279. package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +927 -0
  280. package/.bkit/templates/scripts/graphify/bkit-graphify.sh +351 -0
  281. package/.bkit/templates/scripts/launchd/ai.bkit.launchd.plist +26 -0
  282. package/.bkit/templates/scripts/launchd/bkit-launchd-env.sh +53 -0
  283. package/.bkit/templates/scripts/launchd/launchd.env.example +13 -0
  284. package/.bkit/templates/scripts/prettier/bkit-insert-ignore.mjs +275 -0
  285. package/.bkit/templates/scripts/secrets/bkit-secrets.config.mjs +66 -0
  286. package/.bkit/templates/scripts/secrets/bkit-secrets.mjs +785 -0
  287. package/.bkit/templates/scripts/serena/bkit-serena-mcp.sh +30 -0
  288. package/.bkit/templates/scripts/serena/bkit-serena.mcp.json +9 -0
  289. package/.bkit/templates/scripts/slop/bkit-slop-type-suppression.mjs +286 -0
  290. package/.bkit/templates/slop-scan.config.json +120 -0
  291. package/CHANGELOG.md +1503 -0
  292. package/LICENSE.md +161 -0
  293. package/README.md +184 -2
  294. package/dist/checks/after/auth.js +140 -0
  295. package/dist/checks/after/ci-yml.js +681 -0
  296. package/dist/checks/after/github.js +400 -0
  297. package/dist/checks/after/index.js +431 -0
  298. package/dist/checks/after/managed.js +187 -0
  299. package/dist/checks/after/suppression.js +39 -0
  300. package/dist/checks/after/tools.js +351 -0
  301. package/dist/checks/before/context-fetch.js +426 -0
  302. package/dist/checks/before/env.js +163 -0
  303. package/dist/checks/before/files.js +187 -0
  304. package/dist/checks/before/index.js +162 -0
  305. package/dist/checks/before/mcp.js +111 -0
  306. package/dist/checks/before/repo.js +71 -0
  307. package/dist/checks/before/version.js +60 -0
  308. package/dist/checks/status-holes.js +393 -0
  309. package/dist/cli.js +688 -0
  310. package/dist/commands/analysis.js +325 -0
  311. package/dist/commands/ci/ci.js +438 -0
  312. package/dist/commands/comply.js +310 -0
  313. package/dist/commands/harvest.js +354 -0
  314. package/dist/commands/install/check.js +61 -0
  315. package/dist/commands/install/doctor.js +209 -0
  316. package/dist/commands/install/install.js +475 -0
  317. package/dist/commands/install/uninstall.js +839 -0
  318. package/dist/commands/install/upgrade.js +782 -0
  319. package/dist/commands/launch.js +118 -0
  320. package/dist/commands/lib.js +363 -0
  321. package/dist/commands/registry.js +50 -0
  322. package/dist/commands/setup/setup.js +158 -0
  323. package/dist/commands/telemetry.js +29 -0
  324. package/dist/commands/workflow/branches.js +1265 -0
  325. package/dist/commands/workflow/context.js +846 -0
  326. package/dist/commands/workflow/counters.js +227 -0
  327. package/dist/commands/workflow/fids.js +224 -0
  328. package/dist/commands/workflow/issues.js +585 -0
  329. package/dist/commands/workflow/ledgers.js +472 -0
  330. package/dist/commands/workflow/locks.js +364 -0
  331. package/dist/commands/workflow/prs.js +904 -0
  332. package/dist/commands/workflow/repo.js +199 -0
  333. package/dist/commands/workflow/roadmap.js +495 -0
  334. package/dist/commands/workflow/runs.js +1717 -0
  335. package/dist/commands/workflow/runtime.js +257 -0
  336. package/dist/commands/workflow/skills.js +110 -0
  337. package/dist/commands/workflow/status.js +392 -0
  338. package/dist/commands/workflow/steps.js +1093 -0
  339. package/dist/commands/workflow/tests.js +144 -0
  340. package/dist/commands/workflow/workflows.js +1342 -0
  341. package/dist/commands/workflow/workstreams.js +141 -0
  342. package/dist/commands/workflow/worktrees.js +473 -0
  343. package/dist/install/cloud-env.js +818 -0
  344. package/dist/install/managed-block.js +182 -0
  345. package/dist/install/manifest.js +376 -0
  346. package/dist/install/modules/claude.js +288 -0
  347. package/dist/install/modules/cloud.js +151 -0
  348. package/dist/install/modules/codex.js +193 -0
  349. package/dist/install/modules/core.js +531 -0
  350. package/dist/install/modules/cursor.js +186 -0
  351. package/dist/install/modules/index.js +152 -0
  352. package/dist/install/modules/opencode.js +504 -0
  353. package/dist/install/payload-links.js +119 -0
  354. package/dist/install/placeholders.js +87 -0
  355. package/dist/install/template-copies.js +106 -0
  356. package/dist/install/version-file.js +204 -0
  357. package/dist/install/write.js +342 -0
  358. package/dist/ledgers/clamp-log.js +27 -0
  359. package/dist/ledgers/status.js +156 -0
  360. package/dist/ledgers/telemetry.js +637 -0
  361. package/dist/render/hosts.js +339 -0
  362. package/dist/render/models.js +288 -0
  363. package/dist/render/parts.js +33 -0
  364. package/dist/render/trackers.js +135 -0
  365. package/dist/shared/egress.js +299 -0
  366. package/dist/shared/json.js +16 -0
  367. package/dist/shared/log-prefix.js +7 -0
  368. package/dist/shared/package-json.js +22 -0
  369. package/dist/shared/package-manager.js +32 -0
  370. package/dist/shared/package-roots.js +145 -0
  371. package/dist/shared/protected-paths.js +153 -0
  372. package/dist/shared/settings.js +44 -0
  373. package/dist/shared/timeouts.js +19 -0
  374. package/dist/tools/wording.js +680 -0
  375. package/package.json +101 -4
@@ -0,0 +1,534 @@
1
+ // bkit worktrees setup|remove — the feature worktree's lifecycle.
2
+ //
3
+ // `setup` is Step 2 of every phase workflow: mint or resume `.worktrees/{fid}`,
4
+ // or adopt the current branch in place when the runtime cannot mint (no
5
+ // `--worktrees`). A command cannot change its caller's directory, so it reports
6
+ // `worktreePath` for the workflow to `cd` into. A resume rebase that stops on a
7
+ // conflict is left in progress for `bkit branches rebase`; this command only
8
+ // reports it. `remove` is the close / cleanup half: it removes only a worktree a
9
+ // workflow created, marked in the git common dir's outbox so the marker outlives
10
+ // the worktree it describes, and with `--branch` deletes the feature branch
11
+ // unless another worktree still holds it.
12
+
13
+ import { spawnSync } from "node:child_process";
14
+ import * as fs from "node:fs";
15
+ import * as path from "node:path";
16
+
17
+ import { gitEnv } from "../../ledgers/telemetry.js";
18
+ import { readBkitConfig } from "../../shared/settings.js";
19
+ import { COULD_NOT_RUN_EXIT_CODES, installCommand } from "../../shared/package-manager.js";
20
+ import { CommandError, EXIT, git, repoRoot, runGit, type CommandSpec } from "../lib.js";
21
+ import { detect } from "./runtime.js";
22
+ import { WORKFLOW_FLAG } from "./status.js";
23
+
24
+ const WORKFLOWS = ["design", "plan", "build", "debug", "ship"];
25
+ const DEV = "dev";
26
+ const ORIGIN_DEV = `origin/${DEV}`;
27
+
28
+ export const EXIT_REBASE_CONFLICT = 3;
29
+ export const EXIT_FETCH = 4;
30
+ export const EXIT_INSTALL = 5;
31
+ export const EXIT_INSTALL_COULD_NOT_RUN = 6;
32
+ export const EXIT_REFUSED = 7;
33
+ export const EXIT_WORKTREE_ADD = 8;
34
+ export const EXIT_REBASE_NOT_STARTED = 9;
35
+ export const EXIT_NOT_A_WORKTREE = 10;
36
+ export const EXIT_REMOVE = 11;
37
+
38
+ const FID_FLAG = { name: "fid", type: "string", required: true, help: "feature id" } as const;
39
+
40
+ function fidOf(value: unknown): string {
41
+ const fid = String(value);
42
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(fid) || fid.includes("..")) {
43
+ throw new CommandError(EXIT.USAGE, `--fid "${fid}" is not a feature id`);
44
+ }
45
+ return fid;
46
+ }
47
+
48
+ export const worktreeDir = (root: string, fid: string) => path.join(root, ".worktrees", fid);
49
+
50
+ /** `.worktree-owned` in the git common dir's outbox: shared by every worktree, survives removal. */
51
+ export function ownershipMarker(root: string, fid: string): string {
52
+ const common = git(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
53
+ if (!common) throw new CommandError(EXIT.USAGE, `not inside a git repository: ${root}`);
54
+ return path.join(common, "bkit-outbox", fid, ".worktree-owned");
55
+ }
56
+
57
+ const logDirOf = (top: string, month: string, fid: string) =>
58
+ path.join(top, "docs", "plans", month, "logs", fid);
59
+
60
+ const real = (p: string) => (fs.existsSync(p) ? fs.realpathSync(p) : path.resolve(p));
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // Branches
64
+ // ---------------------------------------------------------------------------
65
+
66
+ const hasLocal = (cwd: string, branch: string) =>
67
+ runGit(cwd, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]).ok;
68
+
69
+ /**
70
+ * Whether `origin` has `branch`. `ls-remote --exit-code` exits 2 for "no such
71
+ * ref", so a network or auth failure is told apart from absence: a failed probe
72
+ * must not be read as "absent" and mint a second branch beside the real one.
73
+ */
74
+ function remoteHas(cwd: string, branch: string): "yes" | "no" | "error" {
75
+ const res = spawnSync("git", ["ls-remote", "--exit-code", "--heads", "origin", branch], {
76
+ cwd,
77
+ encoding: "utf-8",
78
+ env: gitEnv(),
79
+ });
80
+ if (res.status === 0) return "yes";
81
+ return res.status === 2 ? "no" : "error";
82
+ }
83
+
84
+ /**
85
+ * Fetch `branch` into its remote-tracking ref. The explicit refspec matters: a
86
+ * bare `git fetch origin dev` writes only FETCH_HEAD when the clone's fetch
87
+ * refspec does not cover `dev`, leaving `origin/dev` stale, and a branch cut
88
+ * from it silently builds against superseded work.
89
+ */
90
+ function fetchBranch(cwd: string, branch: string): void {
91
+ const res = runGit(cwd, [
92
+ "fetch",
93
+ "origin",
94
+ `+refs/heads/${branch}:refs/remotes/origin/${branch}`,
95
+ ]);
96
+ if (!res.ok) {
97
+ throw new CommandError(EXIT_FETCH, `could not fetch origin ${branch}: ${res.stderr}`);
98
+ }
99
+ }
100
+
101
+ /** Ship's branch: the one the prompt names, else `feat/{fid}` when it exists, else the session's. */
102
+ function shipBranch(root: string, fid: string, named: string | undefined, session: string) {
103
+ if (named) return named;
104
+ const feat = `feat/${fid}`;
105
+ if (hasLocal(root, feat) || remoteHas(root, feat) === "yes") return feat;
106
+ return session === DEV || session === "main" || session === "" ? feat : session;
107
+ }
108
+
109
+ /**
110
+ * `git worktree add` for `branch`: the local branch, else a tracking branch off
111
+ * `origin`, else (when `mayCreate`) a new branch off a freshly fetched
112
+ * `origin/dev`. Returns false when there was nothing to add and `mayCreate` is off.
113
+ */
114
+ function addWorktree(root: string, wt: string, branch: string, mayCreate: boolean): boolean {
115
+ let args: string[];
116
+ if (hasLocal(root, branch)) {
117
+ args = [wt, branch];
118
+ } else {
119
+ const remote = remoteHas(root, branch);
120
+ if (remote === "error") {
121
+ throw new CommandError(EXIT_FETCH, `could not ask origin whether ${branch} exists`);
122
+ }
123
+ if (remote === "yes") {
124
+ fetchBranch(root, branch);
125
+ args = [wt, "--track", "-b", branch, `origin/${branch}`];
126
+ } else if (mayCreate) {
127
+ fetchBranch(root, DEV);
128
+ args = [wt, "-b", branch, ORIGIN_DEV];
129
+ } else {
130
+ return false;
131
+ }
132
+ }
133
+ const res = runGit(root, ["worktree", "add", ...args]);
134
+ if (!res.ok) throw new CommandError(EXIT_WORKTREE_ADD, `git worktree add failed: ${res.stderr}`);
135
+ return true;
136
+ }
137
+
138
+ function rebaseInProgress(wt: string): boolean {
139
+ return ["rebase-merge", "rebase-apply"].some((p) => {
140
+ const dir = git(wt, ["rev-parse", "--path-format=absolute", "--git-path", p]);
141
+ return dir !== null && fs.existsSync(dir);
142
+ });
143
+ }
144
+
145
+ // ---------------------------------------------------------------------------
146
+ // Copy and install
147
+ // ---------------------------------------------------------------------------
148
+
149
+ /** Copy each `worktreeCopy` entry from the main checkout; a missing one is narrated, never fatal. */
150
+ function copyListed(root: string, wt: string, entries: string[], log: (m: string) => void) {
151
+ const copied: string[] = [];
152
+ const copyMissing: string[] = [];
153
+ for (const entry of entries) {
154
+ const rel = path.normalize(entry);
155
+ if (rel.startsWith("..") || path.isAbsolute(rel)) {
156
+ log(`worktree copy: ${entry} is outside the main checkout — skipped`);
157
+ continue;
158
+ }
159
+ const src = path.join(root, rel);
160
+ if (!fs.existsSync(src)) {
161
+ log(`worktree copy: ${rel} is not in the main checkout — skipped`);
162
+ copyMissing.push(rel);
163
+ continue;
164
+ }
165
+ const dest = path.join(wt, rel);
166
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
167
+ fs.cpSync(src, dest, { recursive: true });
168
+ copied.push(rel);
169
+ }
170
+ return { copied, copyMissing };
171
+ }
172
+
173
+ /** Run the frozen install in `wt`; the exit status, with a spawn failure read as "could not run". */
174
+ function install(wt: string, log: (m: string) => void): number {
175
+ const [cmd, ...args] = installCommand({ frozen: true });
176
+ const res = spawnSync(cmd!, args, { cwd: wt, encoding: "utf-8", maxBuffer: 1 << 26 });
177
+ const status = res.error ? 127 : (res.status ?? 1);
178
+ if (status !== 0) {
179
+ const tail = `${res.stdout ?? ""}${res.stderr ?? ""}`.trim().split("\n").slice(-20);
180
+ for (const line of tail) log(line);
181
+ }
182
+ return status;
183
+ }
184
+
185
+ // ---------------------------------------------------------------------------
186
+ // Branch cleanup
187
+ // ---------------------------------------------------------------------------
188
+
189
+ /** The worktree (main checkout included) with `branch` checked out, else null. */
190
+ export function worktreeHolding(root: string, branch: string): string | null {
191
+ const list = git(root, ["worktree", "list", "--porcelain"]) ?? "";
192
+ let current: string | null = null;
193
+ for (const line of list.split("\n")) {
194
+ if (line.startsWith("worktree ")) current = line.slice("worktree ".length);
195
+ else if (line === `branch refs/heads/${branch}` && current !== null) return current;
196
+ }
197
+ return null;
198
+ }
199
+
200
+ /**
201
+ * Delete `branch` locally and on origin. A worktree still holding it blocks
202
+ * both deletes: the local one would fail, and the remote one would strand that
203
+ * worktree's branch without its upstream.
204
+ */
205
+ function deleteBranch(
206
+ root: string,
207
+ branch: string,
208
+ log: (m: string) => void,
209
+ ): { branchDeleted: boolean; remoteDeleted: boolean; branchBlockedBy: string | null } {
210
+ const holder = worktreeHolding(root, branch);
211
+ if (holder !== null) {
212
+ log(
213
+ `${branch} is checked out in ${holder} (not a workflow worktree) — local and remote branch left in place`,
214
+ );
215
+ return { branchDeleted: false, remoteDeleted: false, branchBlockedBy: holder };
216
+ }
217
+ if (hasLocal(root, branch)) {
218
+ const del = runGit(root, ["branch", "-D", branch]);
219
+ if (!del.ok) log(`git branch -D ${branch} failed: ${del.stderr}`);
220
+ }
221
+ const remote = runGit(root, ["push", "origin", "--delete", branch]);
222
+ if (!remote.ok) log(`git push origin --delete ${branch} failed or it was already gone`);
223
+ runGit(root, ["fetch", "--prune", "origin"]);
224
+ return {
225
+ branchDeleted: !hasLocal(root, branch),
226
+ remoteDeleted: remote.ok,
227
+ branchBlockedBy: null,
228
+ };
229
+ }
230
+
231
+ export interface RemoveResult {
232
+ removed: boolean;
233
+ reason: string | null;
234
+ worktreePath: string;
235
+ repoRoot: string;
236
+ branchDeleted: boolean | null;
237
+ remoteDeleted: boolean | null;
238
+ branchBlockedBy: string | null;
239
+ }
240
+
241
+ /**
242
+ * Remove `.worktrees/{fid}` when a workflow created it (the ownership marker),
243
+ * prune stale entries, then delete `branch` locally and on origin unless another
244
+ * worktree holds it. Throws EXIT_REMOVE when `git worktree remove` fails.
245
+ */
246
+ export function removeWorktree(
247
+ cwd: string,
248
+ fid: string,
249
+ branch: string | undefined,
250
+ log: (m: string) => void,
251
+ ): RemoveResult {
252
+ if (branch !== undefined && (branch === DEV || branch === "main")) {
253
+ throw new CommandError(EXIT.USAGE, `refusing to delete branch ${branch}`);
254
+ }
255
+ const root = repoRoot(cwd);
256
+ const wt = worktreeDir(root, fid);
257
+ const marker = ownershipMarker(root, fid);
258
+ const result = (removed: boolean, reason: string | null): RemoveResult => {
259
+ const cleanup = branch === undefined ? null : deleteBranch(root, branch, log);
260
+ return {
261
+ removed,
262
+ reason,
263
+ worktreePath: wt,
264
+ repoRoot: root,
265
+ branchDeleted: cleanup?.branchDeleted ?? null,
266
+ remoteDeleted: cleanup?.remoteDeleted ?? null,
267
+ branchBlockedBy: cleanup?.branchBlockedBy ?? null,
268
+ };
269
+ };
270
+ if (!fs.existsSync(wt)) {
271
+ runGit(root, ["worktree", "prune"]);
272
+ return result(false, "absent");
273
+ }
274
+ if (!fs.existsSync(marker)) {
275
+ log(`${wt} exists but has no ownership marker (${marker}) — not ours, left in place`);
276
+ return result(false, "not-owned");
277
+ }
278
+ const inside = !path.relative(real(wt), real(cwd)).startsWith("..");
279
+ const res = runGit(root, ["worktree", "remove", "--force", wt]);
280
+ if (!res.ok) throw new CommandError(EXIT_REMOVE, `git worktree remove failed: ${res.stderr}`);
281
+ runGit(root, ["worktree", "prune"]);
282
+ fs.rmSync(marker, { force: true });
283
+ if (inside) log(`the working directory was inside ${wt} — cd to ${root}`);
284
+ return result(true, null);
285
+ }
286
+
287
+ // ---------------------------------------------------------------------------
288
+ // Command
289
+ // ---------------------------------------------------------------------------
290
+
291
+ export const worktreesCommand: CommandSpec = {
292
+ noun: "worktrees",
293
+ summary: "Set up and remove the per-feature worktrees under .worktrees/.",
294
+ verbs: {
295
+ setup: {
296
+ summary: "Create, resume or adopt the feature's worktree (Step 2 — Worktree Setup).",
297
+ flags: [
298
+ WORKFLOW_FLAG,
299
+ FID_FLAG,
300
+ { name: "month", type: "string", required: true, help: "month bucket, YYYYMM" },
301
+ {
302
+ name: "worktrees",
303
+ type: "boolean",
304
+ help: "this runtime mints worktrees (runtimeWorktrees=true); absent = adopt the current branch in place",
305
+ },
306
+ {
307
+ name: "detect",
308
+ type: "boolean",
309
+ help: "detect runtimeWorktrees here (`bkit runtime detect`) instead of passing --worktrees",
310
+ },
311
+ {
312
+ name: "branch",
313
+ type: "string",
314
+ help: "ship only: the branch the session prompt names (default: feat/{fid} when it exists, else the session branch)",
315
+ },
316
+ ],
317
+ output: {
318
+ worktreePath: "directory the workflow must cd into",
319
+ repoRoot: "the main checkout",
320
+ branch: "branch checked out at worktreePath",
321
+ mode: "created | resumed | adopted",
322
+ owned: "the .worktree-owned marker is present (a workflow created this worktree)",
323
+ rebaseConflict:
324
+ "a resume rebase onto origin/dev stopped on a conflict and is left in progress",
325
+ sentinel: "the .rebase-failed sentinel written on a failed rebase, else null",
326
+ logDir: "docs/plans/{month}/logs/{fid} under worktreePath (created)",
327
+ baseSha: "git merge-base origin/dev HEAD at worktreePath, or null",
328
+ copied: "worktree copy entries copied from the main checkout",
329
+ copyMissing: "worktree copy entries absent from the main checkout",
330
+ installed: "dependencies were installed",
331
+ },
332
+ exitCodes: {
333
+ [EXIT_REBASE_CONFLICT]:
334
+ "resume rebase stopped on a conflict, left in progress — run `bkit branches rebase`, then re-run setup; on its failure, Failure Path",
335
+ [EXIT_FETCH]: "could not fetch from origin",
336
+ [EXIT_INSTALL]: "dependency install failed",
337
+ [EXIT_INSTALL_COULD_NOT_RUN]: "the package manager could not run (exit 126 / 127)",
338
+ [EXIT_REFUSED]:
339
+ "refused: dev / main as the working branch, detached HEAD, or ship could not switch to its branch",
340
+ [EXIT_WORKTREE_ADD]: "git worktree add failed",
341
+ [EXIT_REBASE_NOT_STARTED]: "resume rebase could not start (e.g. uncommitted changes)",
342
+ [EXIT_NOT_A_WORKTREE]: ".worktrees/{fid} exists but is not a registered git worktree",
343
+ },
344
+ run: (ctx) => {
345
+ const f = ctx.flags;
346
+ const workflow = String(f.workflow);
347
+ if (!WORKFLOWS.includes(workflow)) {
348
+ throw new CommandError(EXIT.USAGE, `--workflow must be ${WORKFLOWS.join("|")}`);
349
+ }
350
+ const fid = fidOf(f.fid);
351
+ const month = String(f.month);
352
+ if (!/^[0-9]{6}$/.test(month)) throw new CommandError(EXIT.USAGE, "--month must be YYYYMM");
353
+ const named = f.branch === undefined ? undefined : String(f.branch);
354
+ if (named !== undefined && workflow !== "ship") {
355
+ throw new CommandError(EXIT.USAGE, "--branch is ship only");
356
+ }
357
+ if (named !== undefined && !runGit(ctx.cwd, ["check-ref-format", "--branch", named]).ok) {
358
+ throw new CommandError(EXIT.USAGE, `--branch "${named}" is not a valid branch name`);
359
+ }
360
+
361
+ const root = repoRoot(ctx.cwd);
362
+ const config = readBkitConfig(root);
363
+ const session = git(ctx.cwd, ["branch", "--show-current"]) ?? "";
364
+ if (workflow === "debug" && session === "") {
365
+ throw new CommandError(
366
+ EXIT_REFUSED,
367
+ "detached HEAD — check out a branch before debugging",
368
+ );
369
+ }
370
+ const target = workflow === "ship" ? shipBranch(root, fid, named, session) : `feat/${fid}`;
371
+ if (target === DEV || target === "main") {
372
+ throw new CommandError(EXIT_REFUSED, `refusing to ship ${target} as a feature branch`);
373
+ }
374
+
375
+ // Ship mints only when the session is not already on the branch it ships:
376
+ // that branch cannot be checked out in two places.
377
+ if (f.worktrees === true && f.detect === true)
378
+ throw new CommandError(EXIT.USAGE, "give --worktrees or --detect, not both");
379
+ const worktrees =
380
+ f.detect === true
381
+ ? detect(ctx.cwd, root, ctx.log).runtimeWorktrees
382
+ : f.worktrees === true;
383
+ const mint = worktrees && !(workflow === "ship" && session === target);
384
+ const wtDir = worktreeDir(root, fid);
385
+ let mode: "created" | "resumed" | "adopted" = "adopted";
386
+ if (mint) {
387
+ runGit(root, ["worktree", "prune"]);
388
+ if (fs.existsSync(wtDir)) {
389
+ // A plain directory there would resolve to the main checkout's repo,
390
+ // and the rebase below would rewrite the main checkout's branch.
391
+ if (real(git(wtDir, ["rev-parse", "--show-toplevel"]) ?? "") !== real(wtDir)) {
392
+ throw new CommandError(
393
+ EXIT_NOT_A_WORKTREE,
394
+ `${wtDir} is not a registered git worktree`,
395
+ );
396
+ }
397
+ mode = "resumed";
398
+ } else if (workflow !== "debug" || session !== target) {
399
+ // Debug adopts an existing feat/{fid}; it never mints a branch of its own.
400
+ if (addWorktree(root, wtDir, target, workflow !== "debug")) mode = "created";
401
+ }
402
+ }
403
+ const wt = mode === "adopted" ? root : wtDir;
404
+ const logDir = logDirOf(wt, month, fid);
405
+ const marker = ownershipMarker(root, fid);
406
+
407
+ if (mode === "adopted") {
408
+ if (workflow === "ship" && git(root, ["branch", "--show-current"]) !== target) {
409
+ const sw = runGit(root, ["switch", target]);
410
+ if (!sw.ok) {
411
+ throw new CommandError(
412
+ EXIT_REFUSED,
413
+ `adopt mode: cannot switch to ${target} — commit or stash local changes, then re-run (${sw.stderr})`,
414
+ );
415
+ }
416
+ }
417
+ const here = git(root, ["branch", "--show-current"]) ?? "";
418
+ const refused = workflow === "debug" ? "main" : DEV;
419
+ if (here === "" || here === refused) {
420
+ throw new CommandError(
421
+ EXIT_REFUSED,
422
+ here === ""
423
+ ? "adopt mode: detached HEAD — check out the feature branch"
424
+ : `adopt mode: current branch is ${here} — refusing to work in place on ${here}`,
425
+ );
426
+ }
427
+ }
428
+
429
+ let rebaseConflict = false;
430
+ let sentinel: string | null = null;
431
+ const sentinelPath = path.join(logDir, ".rebase-failed");
432
+ if (mode === "resumed" && workflow !== "ship") {
433
+ // Cleared before every attempt: a sentinel left by an earlier run would
434
+ // send this one to the Failure Path after a clean rebase.
435
+ fs.rmSync(sentinelPath, { force: true });
436
+ let failure: { conflict: boolean; detail: string } | undefined;
437
+ if (rebaseInProgress(wt)) {
438
+ failure = { conflict: true, detail: "a rebase is already in progress" };
439
+ } else {
440
+ fetchBranch(wt, DEV);
441
+ const rb = runGit(wt, ["rebase", "--rebase-merges", ORIGIN_DEV]);
442
+ if (!rb.ok) {
443
+ failure = {
444
+ conflict: rebaseInProgress(wt),
445
+ detail: [rb.stdout, rb.stderr].filter(Boolean).join("\n"),
446
+ };
447
+ }
448
+ }
449
+ if (failure) {
450
+ fs.mkdirSync(logDir, { recursive: true });
451
+ fs.appendFileSync(
452
+ path.join(logDir, "rebase-resolve-log.md"),
453
+ `[bkit-worktrees] ${new Date().toISOString()} rebase onto ${ORIGIN_DEV} stopped\n${failure.detail}\n`,
454
+ );
455
+ fs.writeFileSync(sentinelPath, "");
456
+ ctx.log(`rebase onto ${ORIGIN_DEV} failed in ${wt}: ${failure.detail.split("\n")[0]}`);
457
+ rebaseConflict = failure.conflict;
458
+ sentinel = sentinelPath;
459
+ }
460
+ }
461
+
462
+ fs.mkdirSync(logDir, { recursive: true });
463
+ if (mode === "created") {
464
+ fs.mkdirSync(path.dirname(marker), { recursive: true });
465
+ fs.writeFileSync(marker, "");
466
+ }
467
+ const done = sentinel === null && mode !== "adopted";
468
+ const { copied, copyMissing } = done
469
+ ? copyListed(root, wt, config.worktreeCopy, ctx.log)
470
+ : { copied: [], copyMissing: [] };
471
+ const wantInstall = done && config.worktreeInstall;
472
+ const installStatus = wantInstall ? install(wt, ctx.log) : 0;
473
+
474
+ ctx.emit({
475
+ worktreePath: wt,
476
+ repoRoot: root,
477
+ branch: git(wt, ["branch", "--show-current"]) ?? "",
478
+ mode,
479
+ owned: fs.existsSync(marker),
480
+ rebaseConflict,
481
+ sentinel,
482
+ logDir,
483
+ baseSha: git(wt, ["merge-base", ORIGIN_DEV, "HEAD"]),
484
+ copied,
485
+ copyMissing,
486
+ installed: wantInstall && installStatus === 0,
487
+ });
488
+ if (sentinel !== null)
489
+ return rebaseConflict ? EXIT_REBASE_CONFLICT : EXIT_REBASE_NOT_STARTED;
490
+ if (COULD_NOT_RUN_EXIT_CODES.has(installStatus)) {
491
+ ctx.log(
492
+ `the package manager could not run (exit ${installStatus}) — dependencies not installed`,
493
+ );
494
+ return EXIT_INSTALL_COULD_NOT_RUN;
495
+ }
496
+ if (installStatus !== 0) {
497
+ ctx.log(`dependency install failed (exit ${installStatus})`);
498
+ return EXIT_INSTALL;
499
+ }
500
+ return EXIT.OK;
501
+ },
502
+ },
503
+ remove: {
504
+ summary:
505
+ "Remove .worktrees/{fid} when a workflow created it, prune stale entries, and delete the feature branch.",
506
+ flags: [
507
+ FID_FLAG,
508
+ {
509
+ name: "branch",
510
+ type: "string",
511
+ help: "feature branch to delete locally and on origin once the worktree is gone; skipped when another worktree still holds it",
512
+ },
513
+ ],
514
+ output: {
515
+ removed: "the worktree was removed",
516
+ reason: "why it was not: absent | not-owned (no .worktree-owned marker); null when removed",
517
+ worktreePath: "the worktree's path",
518
+ repoRoot: "the main checkout — cd here if the shell was inside the removed worktree",
519
+ branchDeleted:
520
+ "--branch: the local branch is gone (deleted or already absent); null without --branch",
521
+ remoteDeleted:
522
+ "--branch: git push origin --delete succeeded; false when it failed or was already gone; null without --branch",
523
+ branchBlockedBy:
524
+ "--branch: the worktree still holding the branch, so neither the local nor the remote branch was deleted; null when none",
525
+ },
526
+ exitCodes: { [EXIT_REMOVE]: "git worktree remove failed" },
527
+ run: (ctx) => {
528
+ const branch = ctx.flags.branch === undefined ? undefined : String(ctx.flags.branch);
529
+ ctx.emit({ ...removeWorktree(ctx.cwd, fidOf(ctx.flags.fid), branch, ctx.log) });
530
+ return EXIT.OK;
531
+ },
532
+ },
533
+ },
534
+ };