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