@cbartens/bkit 5.5.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bkit/README.md +167 -154
- package/.bkit/core/.agents/context.md +95 -29
- package/.bkit/core/.agents/docs.md +18 -15
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +1 -0
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +6 -5
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-readguard.cjs +1 -0
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-rules.cjs +65 -0
- package/.bkit/core/.agents/rules.md +112 -102
- package/.bkit/core/.agents/skills.md +63 -15
- package/.bkit/core/.bkit/README.md +167 -154
- package/.bkit/core/.bkit/authoring.md +747 -0
- package/.bkit/core/.bkit/cli.md +407 -0
- package/.bkit/core/.bkit/cloud.md +283 -195
- package/.bkit/core/.bkit/comparison.md +45 -43
- package/.bkit/core/.bkit/install.md +166 -95
- package/.bkit/core/.bkit/jsonl.md +339 -196
- package/.bkit/core/.bkit/pipeline.md +142 -145
- package/.bkit/core/.bkit/prompts.md +295 -264
- package/.bkit/core/.bkit/providers.md +460 -277
- package/.bkit/core/.bkit/router.md +69 -0
- package/.bkit/core/.bkit/templates.md +530 -256
- package/.bkit/core/.bkit/trackers.md +116 -65
- package/.bkit/core/.bkit/workflows.md +742 -618
- package/.bkit/core/.claude/hooks/bkit-gateguard.cjs +2 -2
- package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +3 -3
- package/.bkit/core/.claude/hooks/bkit-preflight.sh +45 -14
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +3 -3
- package/.bkit/core/.codex/hooks/bkit-rules.cjs +57 -0
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +7 -7
- package/.bkit/core/.cursor/hooks/bkit-preflight.sh +47 -12
- package/.bkit/core/.opencode/plugin/bkit-rules.js +89 -0
- package/.bkit/core/AGENTS.md +6 -80
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +128 -130
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +104 -94
- package/.bkit/core/docs/templates/bkit-audit-agents.md +96 -98
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +100 -103
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +141 -107
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +99 -97
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +122 -121
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +158 -101
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +114 -96
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +76 -97
- package/.bkit/core/docs/templates/bkit-audit-config.md +123 -101
- package/.bkit/core/docs/templates/bkit-audit-cost.md +86 -99
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +76 -93
- package/.bkit/core/docs/templates/bkit-audit-database.md +102 -95
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +165 -108
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +115 -109
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +265 -113
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +119 -118
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +140 -111
- package/.bkit/core/docs/templates/bkit-audit-failures.md +111 -106
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +100 -99
- package/.bkit/core/docs/templates/bkit-audit-gates.md +107 -103
- package/.bkit/core/docs/templates/bkit-audit-issues.md +105 -105
- package/.bkit/core/docs/templates/bkit-audit-llm.md +134 -85
- package/.bkit/core/docs/templates/bkit-audit-logs.md +124 -125
- package/.bkit/core/docs/templates/bkit-audit-models.md +99 -78
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +56 -76
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +63 -78
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +125 -93
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +97 -96
- package/.bkit/core/docs/templates/bkit-audit-repo.md +170 -98
- package/.bkit/core/docs/templates/bkit-audit-security.md +207 -121
- package/.bkit/core/docs/templates/bkit-audit-slop.md +78 -95
- package/.bkit/core/docs/templates/bkit-audit-testing.md +163 -139
- package/.bkit/core/docs/templates/bkit-audit-usability.md +114 -96
- package/.bkit/core/docs/templates/bkit-plan.md +158 -281
- package/.bkit/core/engine/checks/after/auth.ts +40 -37
- package/.bkit/core/engine/checks/after/ci-yml.ts +104 -31
- package/.bkit/core/engine/checks/after/github.ts +95 -17
- package/.bkit/core/engine/checks/after/index.ts +21 -8
- package/.bkit/core/engine/checks/after/suppression.ts +8 -5
- package/.bkit/core/engine/checks/after/tools.ts +125 -123
- package/.bkit/core/engine/checks/before/context-fetch.ts +227 -33
- package/.bkit/core/engine/checks/before/env.ts +3 -3
- package/.bkit/core/engine/checks/before/files.ts +5 -4
- package/.bkit/core/engine/checks/before/index.ts +25 -1
- package/.bkit/core/engine/checks/before/repo.ts +208 -2
- package/.bkit/core/engine/checks/status-holes.ts +916 -123
- package/.bkit/core/engine/checks/tips/catalogue.ts +82 -20
- package/.bkit/core/engine/checks/tips/detect.ts +66 -0
- package/.bkit/core/engine/checks/tips/index.ts +52 -11
- package/.bkit/core/engine/cli.ts +251 -130
- package/.bkit/core/engine/commands/analysis.ts +282 -199
- package/.bkit/core/engine/commands/ci/ci.ts +363 -29
- package/.bkit/core/engine/commands/ci/pins.ts +172 -0
- package/.bkit/core/engine/commands/ci/push-gate.ts +223 -0
- package/.bkit/core/engine/commands/comply.ts +77 -103
- package/.bkit/core/engine/commands/install/doctor.ts +2 -2
- package/.bkit/core/engine/commands/install/install.ts +57 -18
- package/.bkit/core/engine/commands/install/uninstall.ts +86 -55
- package/.bkit/core/engine/commands/install/upgrade.ts +32 -15
- package/.bkit/core/engine/commands/land.ts +139 -18
- package/.bkit/core/engine/commands/lib.ts +381 -22
- package/.bkit/core/engine/commands/registry.ts +10 -2
- package/.bkit/core/engine/commands/setup/setup.ts +8 -7
- package/.bkit/core/engine/commands/stats.ts +260 -0
- package/.bkit/core/engine/commands/tips.ts +10 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +2215 -176
- package/.bkit/core/engine/commands/workflow/challenge.ts +748 -0
- package/.bkit/core/engine/commands/workflow/completeness.ts +109 -0
- package/.bkit/core/engine/commands/workflow/context.ts +1249 -47
- package/.bkit/core/engine/commands/workflow/counters.ts +483 -95
- package/.bkit/core/engine/commands/workflow/decisions.ts +585 -0
- package/.bkit/core/engine/commands/workflow/disk.ts +238 -56
- package/.bkit/core/engine/commands/workflow/fids.ts +811 -33
- package/.bkit/core/engine/commands/workflow/issues.ts +413 -64
- package/.bkit/core/engine/commands/workflow/ledgers.ts +1333 -36
- package/.bkit/core/engine/commands/workflow/locks.ts +28 -2
- package/.bkit/core/engine/commands/workflow/plan-blocks.ts +691 -0
- package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
- package/.bkit/core/engine/commands/workflow/plans.ts +257 -0
- package/.bkit/core/engine/commands/workflow/prs.ts +178 -33
- package/.bkit/core/engine/commands/workflow/repo.ts +66 -8
- package/.bkit/core/engine/commands/workflow/roadmap.ts +72 -22
- package/.bkit/core/engine/commands/workflow/run-facts.ts +492 -0
- package/.bkit/core/engine/commands/workflow/runs.ts +827 -79
- package/.bkit/core/engine/commands/workflow/runtime.ts +25 -1
- package/.bkit/core/engine/commands/workflow/skills.ts +1 -0
- package/.bkit/core/engine/commands/workflow/status.ts +329 -33
- package/.bkit/core/engine/commands/workflow/step-table.ts +381 -0
- package/.bkit/core/engine/commands/workflow/steps.ts +841 -105
- package/.bkit/core/engine/commands/workflow/summary-findings.ts +177 -0
- package/.bkit/core/engine/commands/workflow/summary.ts +544 -0
- package/.bkit/core/engine/commands/workflow/tasks.ts +409 -0
- package/.bkit/core/engine/commands/workflow/test-blocks.ts +254 -0
- package/.bkit/core/engine/commands/workflow/tests-changed.ts +201 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +2124 -330
- package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
- package/.bkit/core/engine/commands/workflow/workflows.ts +1197 -235
- package/.bkit/core/engine/commands/workflow/worktrees.ts +543 -24
- package/.bkit/core/engine/install/cloud-env.ts +251 -121
- package/.bkit/core/engine/install/context-ci-workflow.ts +102 -0
- package/.bkit/core/engine/install/manifest.ts +67 -17
- package/.bkit/core/engine/install/modules/antigravity.ts +3 -2
- package/.bkit/core/engine/install/modules/cloud.ts +24 -16
- package/.bkit/core/engine/install/modules/codex.ts +15 -2
- package/.bkit/core/engine/install/modules/core.ts +1196 -45
- package/.bkit/core/engine/install/modules/cursor.ts +6 -6
- package/.bkit/core/engine/install/modules/opencode.ts +18 -6
- package/.bkit/core/engine/install/template-notes.ts +130 -0
- package/.bkit/core/engine/install/version-file.ts +9 -4
- package/.bkit/core/engine/install/write.ts +5 -0
- package/.bkit/core/engine/ledgers/compact.ts +124 -0
- package/.bkit/core/engine/ledgers/journal.ts +291 -0
- package/.bkit/core/engine/ledgers/migrate.ts +92 -0
- package/.bkit/core/engine/ledgers/status.ts +249 -21
- package/.bkit/core/engine/ledgers/telemetry.ts +1397 -253
- package/.bkit/core/engine/render/hosts.ts +118 -14
- package/.bkit/core/engine/render/models.ts +12 -0
- package/.bkit/core/engine/shared/bkit-latest.ts +26 -4
- package/.bkit/core/engine/shared/branches.ts +4 -1
- package/.bkit/core/engine/shared/dep-updater.ts +60 -0
- package/.bkit/core/engine/shared/egress.ts +8 -1
- package/.bkit/core/engine/shared/json.ts +25 -7
- package/.bkit/core/engine/shared/package-manager.ts +9 -0
- package/.bkit/core/engine/shared/settings.ts +243 -31
- package/.bkit/core/engine/shared/text.ts +361 -0
- package/.bkit/core/engine/shared/timeouts.ts +2 -0
- package/.bkit/core/engine/tools/cli-doc.ts +111 -0
- package/.bkit/core/engine/tools/grammar-density.ts +215 -0
- package/.bkit/core/engine/tools/instructions-sources.ts +832 -0
- package/.bkit/core/engine/tools/instructions.ts +1802 -0
- package/.bkit/core/hooks/antigravity-hook.js +25 -10
- package/.bkit/core/hooks/gateguard-engine.js +54 -29
- package/.bkit/core/hooks/guardrails-shell.js +4 -5
- package/.bkit/core/hooks/guardrails-tiers.js +10 -4
- package/.bkit/core/hooks/preflight-linear.sh +9 -9
- package/.bkit/core/hooks/preflight-rules.sh +8 -0
- package/.bkit/core/hooks/readguard-engine.js +29 -10
- package/.bkit/core/hooks/session-rules-advisory.js +61 -0
- package/.bkit/core/prompts/bkit-audit-generate.md +202 -94
- package/.bkit/core/prompts/bkit-build-challenge-1.md +76 -34
- package/.bkit/core/prompts/bkit-build-challenge-2.md +85 -38
- package/.bkit/core/prompts/bkit-build-install-skills.md +50 -28
- package/.bkit/core/prompts/bkit-build-plan-convert.md +85 -0
- package/.bkit/core/prompts/bkit-build-plan-current.md +59 -36
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +101 -36
- package/.bkit/core/prompts/bkit-build-plan-tasks.md +149 -0
- package/.bkit/core/prompts/bkit-build-plan-tests.md +120 -0
- package/.bkit/core/prompts/bkit-build-plan-verify.md +104 -43
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +47 -32
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +109 -57
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +65 -39
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +53 -31
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +65 -34
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +46 -31
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +45 -31
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +43 -30
- package/.bkit/core/prompts/bkit-design-generate.md +80 -46
- package/.bkit/core/prompts/bkit-design-organise.md +83 -32
- package/.bkit/core/prompts/bkit-design-review-1.md +70 -50
- package/.bkit/core/prompts/bkit-design-review-2.md +65 -46
- package/.bkit/core/prompts/bkit-design-spike.md +64 -40
- package/.bkit/core/prompts/bkit-design-update.md +53 -28
- package/.bkit/core/prompts/bkit-plan-generate.md +101 -29
- package/.bkit/core/prompts/bkit-plan-review-1.md +78 -41
- package/.bkit/core/prompts/bkit-plan-review-2.md +78 -35
- package/.bkit/core/prompts/bkit-plan-scope-check.md +116 -0
- package/.bkit/core/prompts/bkit-plan-update.md +86 -31
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +94 -50
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +91 -41
- package/.bkit/core/prompts/bkit-ship-update-docs.md +45 -24
- package/.bkit/core/prompts/bkit-utility-compress-markdown.md +65 -49
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +87 -42
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +81 -37
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +43 -25
- package/.bkit/core/prompts/bkit-utility-update-failures.md +84 -37
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +88 -42
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +92 -39
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +159 -60
- package/.bkit/core/workflows/bkit-auto.md +89 -58
- package/.bkit/core/workflows/bkit-build.md +967 -517
- package/.bkit/core/workflows/bkit-debug.md +555 -387
- package/.bkit/core/workflows/bkit-design.md +319 -283
- package/.bkit/core/workflows/bkit-plan.md +319 -342
- package/.bkit/core/workflows/bkit-ship.md +525 -328
- package/.bkit/shared/.agents/plugins/bkit/hooks.json +10 -0
- package/.bkit/shared/.bkit/.env.example +2 -2
- package/.bkit/shared/.claude/bkit-cloud.md +12 -10
- package/.bkit/shared/.claude/settings.json +14 -0
- package/.bkit/shared/.codex/bkit-cloud.md +98 -0
- package/.bkit/shared/.codex/hooks.json +20 -0
- package/.bkit/shared/.cursor/bkit-cloud.md +3 -3
- package/.bkit/shared/.cursor/mcp.json +1 -1
- package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
- package/.bkit/shared/.gitattributes +1 -1
- package/.bkit/shared/.mcp.json +1 -1
- package/.bkit/shared/.opencode/opencode.json +12 -1
- package/.bkit/shared/CLAUDE.md +6 -2
- package/.bkit/shared/GEMINI.md +5 -2
- package/.bkit/shared/docs/architecture.md +4 -7
- package/.bkit/shared/docs/data-schema.md +4 -7
- package/.bkit/shared/docs/deployments.md +241 -168
- package/.bkit/shared/docs/design.md +11 -12
- package/.bkit/shared/docs/noise.md +8 -7
- package/.bkit/shared/docs/observability.md +5 -8
- package/.bkit/shared/docs/security.md +35 -17
- package/.bkit/shared/docs/setup.md +29 -18
- package/.bkit/shared/docs/technology.md +3 -6
- package/.bkit/shared/docs/testing.md +289 -174
- package/.bkit/shared/gitignore +6 -2
- package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +15 -16
- package/.bkit/templates/.cursor/Dockerfile +12 -8
- package/.bkit/templates/.cursor/environment.json +1 -1
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +10 -8
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +45 -12
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +3 -3
- package/.bkit/templates/.github/renovate.json5 +34 -6
- package/.bkit/templates/.github/workflows/bkit-ci.yml +54 -51
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +34 -33
- package/.bkit/templates/.github/workflows/bkit-health.yml +97 -0
- package/.bkit/templates/.github/workflows/bkit-renovate.yml +5 -4
- package/.bkit/templates/.github/workflows/bkit-trivy.yml +5 -4
- package/.bkit/templates/.husky/pre-commit +2 -2
- package/.bkit/templates/.husky/pre-push +96 -36
- package/.bkit/templates/.prettierignore +6 -0
- package/.bkit/templates/.vale.ini +27 -27
- package/.bkit/templates/context/bkit-cloudrun.md +23 -15
- package/.bkit/templates/context/bkit-expo.md +70 -52
- package/.bkit/templates/context/bkit-github.md +93 -56
- package/.bkit/templates/context/bkit-inngest.md +21 -15
- package/.bkit/templates/context/bkit-maestro.md +22 -16
- package/.bkit/templates/context/bkit-playwright.md +23 -17
- package/.bkit/templates/context/bkit-resend.md +12 -10
- package/.bkit/templates/context/bkit-sentry.md +30 -20
- package/.bkit/templates/context/bkit-serena.md +8 -7
- package/.bkit/templates/context/bkit-stripe.md +14 -13
- package/.bkit/templates/context/bkit-supabase.md +16 -13
- package/.bkit/templates/context/bkit-tavily.md +14 -11
- package/.bkit/templates/context/bkit-vercel.md +27 -18
- package/.bkit/templates/docs/capabilities.md +15 -14
- package/.bkit/templates/scripts/ci/{check-accepted-divergences.mjs → bkit-check-accepted-divergences.mjs} +6 -3
- package/.bkit/templates/scripts/ci/{check-accepted-divergences.test.mjs → bkit-check-accepted-divergences.test.mjs} +3 -3
- package/.bkit/templates/scripts/ci/{check-capstone.mjs → bkit-check-capstone.mjs} +2 -2
- package/.bkit/templates/scripts/ci/{check-capstone.test.mjs → bkit-check-capstone.test.mjs} +4 -4
- package/.bkit/templates/scripts/ci/{check-dependency-audit.mjs → bkit-check-dependency-audit.mjs} +103 -18
- package/.bkit/templates/scripts/ci/{check-dependency-audit.test.mjs → bkit-check-dependency-audit.test.mjs} +31 -3
- package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +387 -0
- package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +75 -0
- package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +160 -0
- package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.mjs → bkit-resolve-push-base.mjs} +3 -3
- package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.test.mjs → bkit-resolve-push-base.test.mjs} +4 -4
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +10 -2
- package/.bkit/templates/scripts/graphify/bkit-graph-drift.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +3 -3
- package/.bkit/templates/scripts/graphify/bkit-graph-embed.py +63 -0
- package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +2 -2
- package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +69 -18
- package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -3
- package/.bkit/templates/scripts/graphify/bkit-graph-surface.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +197 -126
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +64 -41
- package/.bkit/templates/scripts/slop/bkit-slop-type-suppression.mjs +23 -7
- package/.bkit/templates/slop-scan.config.json +9 -2
- package/CHANGELOG.md +231 -0
- package/README.md +278 -89
- package/dist/checks/after/auth.js +36 -33
- package/dist/checks/after/ci-yml.js +91 -30
- package/dist/checks/after/github.js +91 -17
- package/dist/checks/after/index.js +22 -11
- package/dist/checks/after/suppression.js +8 -5
- package/dist/checks/after/tools.js +111 -114
- package/dist/checks/before/context-fetch.js +218 -33
- package/dist/checks/before/env.js +3 -3
- package/dist/checks/before/files.js +5 -3
- package/dist/checks/before/index.js +20 -3
- package/dist/checks/before/repo.js +197 -2
- package/dist/checks/status-holes.js +739 -114
- package/dist/checks/tips/catalogue.js +70 -19
- package/dist/checks/tips/detect.js +62 -0
- package/dist/checks/tips/index.js +51 -9
- package/dist/cli.js +234 -124
- package/dist/commands/analysis.js +174 -141
- package/dist/commands/ci/ci.js +302 -25
- package/dist/commands/ci/pins.js +142 -0
- package/dist/commands/ci/push-gate.js +194 -0
- package/dist/commands/comply.js +54 -91
- package/dist/commands/install/doctor.js +2 -2
- package/dist/commands/install/install.js +50 -19
- package/dist/commands/install/uninstall.js +82 -55
- package/dist/commands/install/upgrade.js +21 -11
- package/dist/commands/land.js +137 -17
- package/dist/commands/lib.js +295 -21
- package/dist/commands/registry.js +10 -2
- package/dist/commands/setup/setup.js +8 -7
- package/dist/commands/stats.js +175 -0
- package/dist/commands/tips.js +7 -3
- package/dist/commands/workflow/branches.js +1873 -152
- package/dist/commands/workflow/challenge.js +609 -0
- package/dist/commands/workflow/completeness.js +97 -0
- package/dist/commands/workflow/context.js +1045 -46
- package/dist/commands/workflow/counters.js +385 -86
- package/dist/commands/workflow/decisions.js +484 -0
- package/dist/commands/workflow/disk.js +214 -56
- package/dist/commands/workflow/fids.js +706 -33
- package/dist/commands/workflow/issues.js +349 -59
- package/dist/commands/workflow/ledgers.js +1123 -37
- package/dist/commands/workflow/locks.js +26 -2
- package/dist/commands/workflow/plan-blocks.js +501 -0
- package/dist/commands/workflow/plan-versions.js +22 -0
- package/dist/commands/workflow/plans.js +205 -0
- package/dist/commands/workflow/prs.js +154 -35
- package/dist/commands/workflow/repo.js +58 -8
- package/dist/commands/workflow/roadmap.js +58 -23
- package/dist/commands/workflow/run-facts.js +421 -0
- package/dist/commands/workflow/runs.js +670 -72
- package/dist/commands/workflow/runtime.js +15 -1
- package/dist/commands/workflow/skills.js +1 -0
- package/dist/commands/workflow/status.js +282 -34
- package/dist/commands/workflow/step-table.js +308 -0
- package/dist/commands/workflow/steps.js +703 -96
- package/dist/commands/workflow/summary-findings.js +117 -0
- package/dist/commands/workflow/summary.js +388 -0
- package/dist/commands/workflow/tasks.js +378 -0
- package/dist/commands/workflow/test-blocks.js +231 -0
- package/dist/commands/workflow/tests-changed.js +172 -0
- package/dist/commands/workflow/tests.js +1695 -305
- package/dist/commands/workflow/tracker.js +983 -0
- package/dist/commands/workflow/workflows.js +1014 -222
- package/dist/commands/workflow/worktrees.js +432 -26
- package/dist/install/cloud-env.js +233 -99
- package/dist/install/context-ci-workflow.js +85 -0
- package/dist/install/manifest.js +64 -17
- package/dist/install/modules/antigravity.js +3 -2
- package/dist/install/modules/cloud.js +25 -16
- package/dist/install/modules/codex.js +12 -2
- package/dist/install/modules/core.js +1090 -48
- package/dist/install/modules/cursor.js +6 -6
- package/dist/install/modules/opencode.js +13 -7
- package/dist/install/template-notes.js +116 -0
- package/dist/install/version-file.js +9 -4
- package/dist/ledgers/compact.js +87 -0
- package/dist/ledgers/journal.js +233 -0
- package/dist/ledgers/migrate.js +81 -0
- package/dist/ledgers/status.js +176 -13
- package/dist/ledgers/telemetry.js +1010 -125
- package/dist/render/hosts.js +104 -14
- package/dist/render/models.js +12 -0
- package/dist/shared/bkit-latest.js +26 -4
- package/dist/shared/branches.js +3 -1
- package/dist/shared/dep-updater.js +49 -0
- package/dist/shared/egress.js +8 -1
- package/dist/shared/json.js +20 -7
- package/dist/shared/package-manager.js +6 -0
- package/dist/shared/settings.js +181 -24
- package/dist/shared/text.js +333 -0
- package/dist/shared/timeouts.js +2 -0
- package/dist/tools/cli-doc.js +97 -0
- package/dist/tools/grammar-density.js +183 -0
- package/dist/tools/instructions-sources.js +720 -0
- package/dist/tools/instructions.js +1623 -0
- package/package.json +156 -51
- package/.bkit/core/.bkit/lite.md +0 -73
- package/.bkit/core/engine/commands/harvest.ts +0 -459
- package/.bkit/core/engine/commands/workflow/workstreams.ts +0 -166
- package/.bkit/core/engine/tools/wording.ts +0 -748
- package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
- package/.bkit/core/prompts/bkit-build-plan-execute.md +0 -76
- package/.bkit/core/prompts/bkit-build-summary.md +0 -94
- package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
- package/.bkit/core/prompts/bkit-design-summary.md +0 -107
- package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
- package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
- package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
- package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
- package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
- package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
- package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
- package/.bkit/templates/scripts/ci/bkit-local-stack-lock.sh +0 -194
- package/dist/commands/harvest.js +0 -353
- package/dist/commands/workflow/workstreams.js +0 -143
- package/dist/tools/wording.js +0 -680
- /package/.bkit/templates/.vale/styles/{House → Bkit}/Filler.yml +0 -0
- /package/.bkit/templates/.vale/styles/{House → Bkit}/Hedging.yml +0 -0
- /package/.bkit/templates/.vale/styles/{House → Bkit}/LLMSlop.yml +0 -0
- /package/.bkit/templates/.vale/styles/{House → Bkit}/Verbose.yml +0 -0
- /package/.bkit/templates/scripts/ci/{accepted-advisories.json → bkit-accepted-advisories.json} +0 -0
- /package/.bkit/templates/scripts/ci/{accepted-divergences.json → bkit-accepted-divergences.json} +0 -0
- /package/.bkit/templates/scripts/launchd/{launchd.env.example → bkit-launchd.env.example} +0 -0
- /package/.bkit/templates/scripts/launchd/{ai.bkit.launchd.plist → bkit-launchd.plist} +0 -0
|
@@ -14,10 +14,13 @@
|
|
|
14
14
|
// builds against superseded work.
|
|
15
15
|
|
|
16
16
|
import { spawnSync } from "node:child_process";
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
17
18
|
import * as fs from "node:fs";
|
|
18
19
|
import * as path from "node:path";
|
|
19
20
|
|
|
20
|
-
import {
|
|
21
|
+
import { actionHash, actionKey, lastRun, recordAction } from "../../ledgers/status.js";
|
|
22
|
+
import { APPEND_LEDGERS, gitEnv } from "../../ledgers/telemetry.js";
|
|
23
|
+
import { parseJson } from "../../shared/json.js";
|
|
21
24
|
import { readBkitConfig } from "../../shared/settings.js";
|
|
22
25
|
import { COULD_NOT_RUN_EXIT_CODES, installCommand } from "../../shared/package-manager.js";
|
|
23
26
|
import {
|
|
@@ -25,14 +28,26 @@ import {
|
|
|
25
28
|
DEV,
|
|
26
29
|
EXIT,
|
|
27
30
|
git,
|
|
31
|
+
isIgnoredPath,
|
|
28
32
|
isSharedBranch,
|
|
33
|
+
MAIN,
|
|
34
|
+
mainCheckoutRoot,
|
|
29
35
|
repoRoot,
|
|
30
36
|
runGit,
|
|
31
37
|
type CommandSpec,
|
|
32
38
|
} from "../lib.js";
|
|
33
39
|
import { ensureDiskSpace } from "./disk.js";
|
|
40
|
+
import {
|
|
41
|
+
listRecords,
|
|
42
|
+
newRecord,
|
|
43
|
+
readRecord,
|
|
44
|
+
removeRecord,
|
|
45
|
+
withSetupGuard,
|
|
46
|
+
writeRecord,
|
|
47
|
+
} from "./ledgers.js";
|
|
48
|
+
import { workflowLockFresh, workflowLockLive } from "./locks.js";
|
|
34
49
|
import { detect } from "./runtime.js";
|
|
35
|
-
import { WORKFLOW_FLAG } from "./status.js";
|
|
50
|
+
import { WORKFLOW_FLAG, readRuns } from "./status.js";
|
|
36
51
|
|
|
37
52
|
const WORKFLOWS = ["design", "plan", "build", "debug", "ship"];
|
|
38
53
|
const ORIGIN_DEV = `origin/${DEV}`;
|
|
@@ -47,6 +62,7 @@ export const EXIT_REBASE_NOT_STARTED = 9;
|
|
|
47
62
|
export const EXIT_NOT_A_WORKTREE = 10;
|
|
48
63
|
export const EXIT_REMOVE = 11;
|
|
49
64
|
export const EXIT_DISK_FULL = 12;
|
|
65
|
+
export const EXIT_SHARED_BUSY = 13;
|
|
50
66
|
|
|
51
67
|
const FID_FLAG = { name: "fid", type: "string", required: true, help: "feature id" } as const;
|
|
52
68
|
|
|
@@ -111,6 +127,41 @@ function fetchBranch(cwd: string, branch: string): void {
|
|
|
111
127
|
}
|
|
112
128
|
}
|
|
113
129
|
|
|
130
|
+
/**
|
|
131
|
+
* The shared-checkout record for an in-place run on `dev`. Another feature's
|
|
132
|
+
* record with a live workflow lock means that run owns the checkout; one
|
|
133
|
+
* without is left over and removed. The same feature with an open run in
|
|
134
|
+
* `{logDir}/status.jsonl` is a resume and keeps its record; a new run rewrites it.
|
|
135
|
+
*/
|
|
136
|
+
function openSharedRecord(root: string, fid: string, workflow: string, logDir: string) {
|
|
137
|
+
const busy = (other: string) =>
|
|
138
|
+
new CommandError(
|
|
139
|
+
EXIT_SHARED_BUSY,
|
|
140
|
+
`${other} is running in this checkout (workflow lock held) — wait for it to finish, then re-run`,
|
|
141
|
+
);
|
|
142
|
+
const guarded = withSetupGuard(root, () => {
|
|
143
|
+
for (const other of listRecords(root)) {
|
|
144
|
+
if (other.fid === fid) continue;
|
|
145
|
+
// A closed run that has not released its lock still pushes and waits for CI.
|
|
146
|
+
if (workflowLockLive(root, other.fid) || workflowLockFresh(root, other.fid)) {
|
|
147
|
+
throw busy(other.fid);
|
|
148
|
+
}
|
|
149
|
+
removeRecord(root, other.fid);
|
|
150
|
+
}
|
|
151
|
+
const existing = readRecord(root, fid);
|
|
152
|
+
const statusFile = path.join(logDir, "status.jsonl");
|
|
153
|
+
const open =
|
|
154
|
+
fs.existsSync(statusFile) &&
|
|
155
|
+
lastRun(readRuns(statusFile), workflow)?.status === "IN_PROGRESS";
|
|
156
|
+
if (existing !== null && existing.branch === DEV && open) return existing;
|
|
157
|
+
const fresh = newRecord(root, fid, DEV);
|
|
158
|
+
writeRecord(root, fresh);
|
|
159
|
+
return fresh;
|
|
160
|
+
});
|
|
161
|
+
if (guarded === null) throw busy("another run");
|
|
162
|
+
return guarded.value;
|
|
163
|
+
}
|
|
164
|
+
|
|
114
165
|
/** Ship's branch: the one the prompt names, else `feat/{fid}` when it exists, else the session's. */
|
|
115
166
|
function shipBranch(root: string, fid: string, named: string | undefined, session: string) {
|
|
116
167
|
if (named) return named;
|
|
@@ -143,9 +194,64 @@ export function devBase(cwd: string, log?: (m: string) => void): string {
|
|
|
143
194
|
return ORIGIN_DEV;
|
|
144
195
|
}
|
|
145
196
|
|
|
197
|
+
/** Workflows whose close lands docs and ledgers only: their branch may carry no unpushed dev work. */
|
|
198
|
+
const DOCS_ONLY_WORKFLOWS: readonly string[] = ["design", "plan"];
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The ref a feature branch starts from and rebases onto. A docs-only workflow
|
|
202
|
+
* (design, plan) always starts from `origin/dev`: its close lands docs and
|
|
203
|
+
* ledgers on `origin/dev` and may carry nothing else, so a branch holding
|
|
204
|
+
* unpushed `dev` commits could never land (issue #639). Every other workflow
|
|
205
|
+
* keeps `devBase`'s choice — local `dev` while it is a fast-forward of `origin/dev`.
|
|
206
|
+
*/
|
|
207
|
+
export function worktreeBase(cwd: string, workflow: string, log?: (m: string) => void): string {
|
|
208
|
+
if (!DOCS_ONLY_WORKFLOWS.includes(workflow)) return devBase(cwd, log);
|
|
209
|
+
const local = git(cwd, ["rev-parse", "-q", "--verify", `refs/heads/${DEV}`]);
|
|
210
|
+
const remote = git(cwd, ["rev-parse", "-q", "--verify", `refs/remotes/${ORIGIN_DEV}`]);
|
|
211
|
+
if (
|
|
212
|
+
local !== null &&
|
|
213
|
+
remote !== null &&
|
|
214
|
+
local !== remote &&
|
|
215
|
+
runGit(cwd, ["merge-base", "--is-ancestor", remote, local]).ok
|
|
216
|
+
) {
|
|
217
|
+
const count = git(cwd, ["rev-list", "--count", `${remote}..${local}`]) ?? "?";
|
|
218
|
+
log?.(
|
|
219
|
+
`local ${DEV} is ${count} commit(s) ahead of ${ORIGIN_DEV} — basing this ${workflow} branch on ${ORIGIN_DEV}: its close lands docs and ledgers only`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return ORIGIN_DEV;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The commits `branch` carries that local `dev` holds and `origin/dev` does not:
|
|
227
|
+
* work inherited from unpushed `dev`. A docs-only close lands on `origin/dev` and
|
|
228
|
+
* may bring docs and ledgers only, so such a branch can never land.
|
|
229
|
+
*/
|
|
230
|
+
function inheritedDevCommits(root: string, branch: string): string[] {
|
|
231
|
+
const unpushed = new Set(
|
|
232
|
+
(git(root, ["rev-list", `${ORIGIN_DEV}..${DEV}`]) ?? "").split("\n").filter(Boolean),
|
|
233
|
+
);
|
|
234
|
+
if (unpushed.size === 0) return [];
|
|
235
|
+
return (git(root, ["rev-list", branch, "--not", ORIGIN_DEV]) ?? "")
|
|
236
|
+
.split("\n")
|
|
237
|
+
.filter((c) => unpushed.has(c));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Why a docs-only branch carrying unpushed `dev` cannot land, and what unblocks it. */
|
|
241
|
+
function inheritedDevRefusal(
|
|
242
|
+
root: string,
|
|
243
|
+
target: string,
|
|
244
|
+
workflow: string,
|
|
245
|
+
count: number,
|
|
246
|
+
): string {
|
|
247
|
+
const ahead = git(root, ["rev-list", "--count", `${ORIGIN_DEV}..${DEV}`]) ?? "?";
|
|
248
|
+
const tip = git(root, ["rev-parse", "--short", DEV]) ?? DEV;
|
|
249
|
+
return `${target} carries ${count} commit(s) of unpushed ${DEV} (tip ${tip}, ${ahead} commit(s) ahead of ${ORIGIN_DEV}), and a ${workflow} close lands docs and ledgers only — this branch cannot land. Publish ${DEV} (git push origin ${DEV}), then re-run.`;
|
|
250
|
+
}
|
|
251
|
+
|
|
146
252
|
/**
|
|
147
253
|
* `git worktree add` for `branch`: the local branch, else a tracking branch off
|
|
148
|
-
* `origin`, else (when `mayCreate`) a new branch off `
|
|
254
|
+
* `origin`, else (when `mayCreate`) a new branch off `worktreeBase` after a fresh
|
|
149
255
|
* fetch. Returns false when there was nothing to add and `mayCreate` is off.
|
|
150
256
|
*/
|
|
151
257
|
function addWorktree(
|
|
@@ -153,6 +259,7 @@ function addWorktree(
|
|
|
153
259
|
wt: string,
|
|
154
260
|
branch: string,
|
|
155
261
|
mayCreate: boolean,
|
|
262
|
+
workflow: string,
|
|
156
263
|
log: (m: string) => void,
|
|
157
264
|
): boolean {
|
|
158
265
|
let args: string[];
|
|
@@ -168,7 +275,7 @@ function addWorktree(
|
|
|
168
275
|
args = [wt, "--track", "-b", branch, `origin/${branch}`];
|
|
169
276
|
} else if (mayCreate) {
|
|
170
277
|
fetchBranch(root, DEV);
|
|
171
|
-
args = [wt, "-b", branch,
|
|
278
|
+
args = [wt, "-b", branch, worktreeBase(root, workflow, log)];
|
|
172
279
|
} else {
|
|
173
280
|
return false;
|
|
174
281
|
}
|
|
@@ -178,6 +285,24 @@ function addWorktree(
|
|
|
178
285
|
return true;
|
|
179
286
|
}
|
|
180
287
|
|
|
288
|
+
/**
|
|
289
|
+
* An engine-action row for a rebase that rewrote the branch, keyed on the tip it
|
|
290
|
+
* replaced, so the run's record shows the rewrite. Nothing when HEAD did not move.
|
|
291
|
+
*/
|
|
292
|
+
export function recordRebase(
|
|
293
|
+
statusFile: string,
|
|
294
|
+
before: string | null,
|
|
295
|
+
after: string | null,
|
|
296
|
+
): void {
|
|
297
|
+
if (before === null || after === null || before === after) return;
|
|
298
|
+
recordAction(statusFile, {
|
|
299
|
+
action: "rebase",
|
|
300
|
+
key: actionKey("rebase", before),
|
|
301
|
+
hash: actionHash(`${before}..${after}`),
|
|
302
|
+
ref: after,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
181
306
|
function rebaseInProgress(wt: string): boolean {
|
|
182
307
|
return ["rebase-merge", "rebase-apply"].some((p) => {
|
|
183
308
|
const dir = git(wt, ["rev-parse", "--path-format=absolute", "--git-path", p]);
|
|
@@ -185,6 +310,196 @@ function rebaseInProgress(wt: string): boolean {
|
|
|
185
310
|
});
|
|
186
311
|
}
|
|
187
312
|
|
|
313
|
+
/**
|
|
314
|
+
* bkit's own worktree copy entry, excluded from every bkit commit beside
|
|
315
|
+
* `bkit.workflows.worktree.copy`: it holds the sign-in tokens, and a consumer whose
|
|
316
|
+
* `.gitignore` lost bkit's `.bkit/.env` line would otherwise commit a link to them.
|
|
317
|
+
*/
|
|
318
|
+
export const BKIT_OWN_COPY: readonly string[] = [".bkit/.env"];
|
|
319
|
+
|
|
320
|
+
/** A normalized copy entry inside the checkout: neither absolute nor climbing out with `..`. */
|
|
321
|
+
const insideCheckout = (rel: string) =>
|
|
322
|
+
!path.isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${path.sep}`);
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Every `bkit.workflows.worktree.copy` entry setup may have copied into `tree`: the
|
|
326
|
+
* tree's own `package.json` list and the main checkout's, which setup copies by and
|
|
327
|
+
* which an uncommitted edit or the feature branch can make differ.
|
|
328
|
+
*/
|
|
329
|
+
function worktreeCopyLists(tree: string): string[] {
|
|
330
|
+
const main = mainCheckoutRoot(tree) ?? tree;
|
|
331
|
+
return [...new Set([...readBkitConfig(tree).worktreeCopy, ...readBkitConfig(main).worktreeCopy])];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* `:(exclude)` pathspecs for the entries setup copies into `tree` (`copied`, default
|
|
336
|
+
* every list that may name one) and `BKIT_OWN_COPY`. An entry outside the tree is left
|
|
337
|
+
* out: git refuses it as a pathspec (exit 128) and setup never copies it. So is one git
|
|
338
|
+
* already ignores: naming it in a `:(exclude)` pathspec trips git's ignored-paths guard
|
|
339
|
+
* and fails the whole `add`, and `git add -A` skips an ignored file anyway.
|
|
340
|
+
*/
|
|
341
|
+
export function copyExcludes(tree: string, copied: string[] = worktreeCopyLists(tree)): string[] {
|
|
342
|
+
return [...copied, ...BKIT_OWN_COPY]
|
|
343
|
+
.map((e) => path.normalize(e))
|
|
344
|
+
.filter((e) => insideCheckout(e) && !isIgnoredPath(tree, e))
|
|
345
|
+
.map((e) => `:(exclude)${e}`);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* `git add -A` in `tree`, leaving out the entries setup copies in from the main
|
|
350
|
+
* checkout (`.env` and the like) and `BKIT_OWN_COPY` (`copyExcludes`): no bkit commit
|
|
351
|
+
* may carry them, gitignored or not.
|
|
352
|
+
*/
|
|
353
|
+
export function addAllButCopied(tree: string, copied?: string[]): ReturnType<typeof runGit> {
|
|
354
|
+
return runGit(tree, ["add", "-A", "--", ".", ...copyExcludes(tree, copied)]);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Whether `wt` holds changes beyond the entries setup copies in (`copyExcludes`). */
|
|
358
|
+
export const hasLeftovers = (wt: string) =>
|
|
359
|
+
(git(wt, ["status", "--porcelain", "--untracked-files=all", "--", ".", ...copyExcludes(wt)]) ??
|
|
360
|
+
"") !== "";
|
|
361
|
+
|
|
362
|
+
/** A tracked file split into its committed text and the rows appended after it. */
|
|
363
|
+
type Appended = { committed: string; rows: string };
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The rows the dispatch seam appended after the last commit, by tracked path, when they
|
|
367
|
+
* are the only changes in `wt`: `engine-call` rows at the end of `statusFile`, and
|
|
368
|
+
* `friction` rows at the end of `.bkit/friction.jsonl` (a hook-launched command's
|
|
369
|
+
* unexpected exit). Null when anything else changed.
|
|
370
|
+
*/
|
|
371
|
+
function journalRowsAppended(wt: string, statusFile: string): Map<string, Appended> | null {
|
|
372
|
+
const allowed = new Map<string, (row: Record<string, unknown>) => boolean>([
|
|
373
|
+
[path.relative(wt, statusFile), (row) => row["type"] === "engine-call"],
|
|
374
|
+
[APPEND_LEDGERS.friction.file, (row) => row["kind"] === "friction"],
|
|
375
|
+
]);
|
|
376
|
+
const changed = (
|
|
377
|
+
git(wt, ["status", "--porcelain", "--untracked-files=all", "--", ".", ...copyExcludes(wt)]) ??
|
|
378
|
+
""
|
|
379
|
+
)
|
|
380
|
+
.split("\n")
|
|
381
|
+
.filter((l) => l !== "");
|
|
382
|
+
if (changed.length === 0) return null;
|
|
383
|
+
const out = new Map<string, Appended>();
|
|
384
|
+
for (const line of changed) {
|
|
385
|
+
const rel = [...allowed.keys()].find((r) => line.endsWith(` ${r}`));
|
|
386
|
+
const appended = rel === undefined ? null : appendedRows(wt, rel, allowed.get(rel)!);
|
|
387
|
+
if (rel === undefined || appended === null) return null;
|
|
388
|
+
out.set(rel, appended);
|
|
389
|
+
}
|
|
390
|
+
return out;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** `rel` as its committed text plus one or more appended rows `accepts` takes; null otherwise. */
|
|
394
|
+
function appendedRows(
|
|
395
|
+
wt: string,
|
|
396
|
+
rel: string,
|
|
397
|
+
accepts: (row: Record<string, unknown>) => boolean,
|
|
398
|
+
): Appended | null {
|
|
399
|
+
const committed = git(wt, ["cat-file", "blob", `HEAD:${rel}`]);
|
|
400
|
+
const file = path.join(wt, rel);
|
|
401
|
+
if (committed === null || !fs.existsSync(file)) return null;
|
|
402
|
+
const text = fs.readFileSync(file, "utf-8");
|
|
403
|
+
if (!text.startsWith(committed)) return null;
|
|
404
|
+
// `git` trims its output: the committed text's own last newline comes back with it.
|
|
405
|
+
const rest = text.slice(committed.length);
|
|
406
|
+
const lead = rest.startsWith("\n") ? "\n" : "";
|
|
407
|
+
const rows = rest.slice(lead.length);
|
|
408
|
+
const added = rows.split("\n").filter((l) => l.trim() !== "");
|
|
409
|
+
const ok =
|
|
410
|
+
added.length > 0 &&
|
|
411
|
+
added.every((l) => {
|
|
412
|
+
const parsed = parseJson(l);
|
|
413
|
+
return (
|
|
414
|
+
parsed.ok &&
|
|
415
|
+
parsed.value !== null &&
|
|
416
|
+
typeof parsed.value === "object" &&
|
|
417
|
+
!Array.isArray(parsed.value) &&
|
|
418
|
+
accepts(parsed.value as Record<string, unknown>)
|
|
419
|
+
);
|
|
420
|
+
});
|
|
421
|
+
return ok ? { committed: text.slice(0, committed.length) + lead, rows } : null;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Appends the rows `journalRowsAppended` set aside back onto their files and returns "".
|
|
426
|
+
* A rebase that stopped part-way cannot continue past unstaged rows, so then nothing is
|
|
427
|
+
* appended and the rows come back as text for the rebase log.
|
|
428
|
+
*/
|
|
429
|
+
function putJournalRowsBack(wt: string, journal: Map<string, Appended>): string {
|
|
430
|
+
if (rebaseInProgress(wt)) {
|
|
431
|
+
return [...journal]
|
|
432
|
+
.map(
|
|
433
|
+
([rel, a]) =>
|
|
434
|
+
`rows set aside from ${rel}; append them once the rebase finishes:\n${a.rows}`,
|
|
435
|
+
)
|
|
436
|
+
.join("");
|
|
437
|
+
}
|
|
438
|
+
for (const [rel, a] of journal) {
|
|
439
|
+
const file = path.join(wt, rel);
|
|
440
|
+
const text = fs.existsSync(file) ? fs.readFileSync(file, "utf-8") : "";
|
|
441
|
+
fs.appendFileSync(file, `${text !== "" && !text.endsWith("\n") ? "\n" : ""}${a.rows}`);
|
|
442
|
+
}
|
|
443
|
+
return "";
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Commit what an earlier run left uncommitted in a resumed worktree, so the
|
|
448
|
+
* resume rebase can start: a failed ship's flush lands its record on dev and
|
|
449
|
+
* leaves the worktree as it was, for whatever runs next. An untracked file in a
|
|
450
|
+
* log folder of this feature that `onto` already holds is dropped first: dev's
|
|
451
|
+
* copy, landed by that flush, wins, and a second copy would stop the rebase. One
|
|
452
|
+
* whose content differs from `onto`'s is moved to the feature's outbox folder
|
|
453
|
+
* (`dropped-logs/{time}/`), never deleted. The entries setup copies in are never
|
|
454
|
+
* committed and alone do not count as leftovers. No leftovers → null; a failed
|
|
455
|
+
* commit is narrated and leaves the tree for the rebase to refuse.
|
|
456
|
+
*/
|
|
457
|
+
function carryLeftovers(
|
|
458
|
+
wt: string,
|
|
459
|
+
o: { fid: string; onto: string; statusFile: string },
|
|
460
|
+
log: (m: string) => void,
|
|
461
|
+
): { sha: string | null; dropped: string[] } | null {
|
|
462
|
+
if (!hasLeftovers(wt)) return null;
|
|
463
|
+
const logs = new RegExp(`^docs/plans/[^/]+/logs/${o.fid.replace(/\./g, "\\.")}/`);
|
|
464
|
+
const dropped = (git(wt, ["ls-files", "--others", "--exclude-standard"]) ?? "")
|
|
465
|
+
.split("\n")
|
|
466
|
+
.filter((f) => logs.test(f) && runGit(wt, ["cat-file", "-e", `${o.onto}:${f}`]).ok);
|
|
467
|
+
const keepDir = path.join(
|
|
468
|
+
path.dirname(ownershipMarker(wt, o.fid)),
|
|
469
|
+
"dropped-logs",
|
|
470
|
+
new Date().toISOString().replace(/[:.]/g, "-"),
|
|
471
|
+
);
|
|
472
|
+
for (const f of dropped) {
|
|
473
|
+
const file = path.join(wt, f);
|
|
474
|
+
if (git(wt, ["hash-object", "--", f]) !== git(wt, ["rev-parse", `${o.onto}:${f}`])) {
|
|
475
|
+
const kept = path.join(keepDir, f);
|
|
476
|
+
fs.mkdirSync(path.dirname(kept), { recursive: true });
|
|
477
|
+
fs.cpSync(file, kept);
|
|
478
|
+
log(`moved ${f} to ${kept}: it differs from ${o.onto}'s copy, which wins in the worktree`);
|
|
479
|
+
}
|
|
480
|
+
fs.rmSync(file);
|
|
481
|
+
}
|
|
482
|
+
if (dropped.length > 0)
|
|
483
|
+
log(
|
|
484
|
+
`dropped ${dropped.length} untracked log(s) ${o.onto} already holds: ${dropped.join(", ")}`,
|
|
485
|
+
);
|
|
486
|
+
if (!hasLeftovers(wt)) return { sha: null, dropped };
|
|
487
|
+
|
|
488
|
+
const prior = fs.existsSync(o.statusFile) ? readRuns(o.statusFile).at(-1) : undefined;
|
|
489
|
+
const what =
|
|
490
|
+
prior === undefined
|
|
491
|
+
? "uncommitted work left in the worktree"
|
|
492
|
+
: `the ${prior.status === "FAILED" ? "failed " : ""}${prior.workflow} record left uncommitted`;
|
|
493
|
+
addAllButCopied(wt);
|
|
494
|
+
const made = runGit(wt, ["commit", "-m", `chore(${o.fid}): carry ${what} bkit`]);
|
|
495
|
+
if (!made.ok) {
|
|
496
|
+
log(`could not commit what an earlier run left in ${wt}: ${made.stderr || made.stdout}`);
|
|
497
|
+
return { sha: null, dropped };
|
|
498
|
+
}
|
|
499
|
+
log(`committed ${what} before the resume rebase`);
|
|
500
|
+
return { sha: git(wt, ["rev-parse", "HEAD"]), dropped };
|
|
501
|
+
}
|
|
502
|
+
|
|
188
503
|
// ---------------------------------------------------------------------------
|
|
189
504
|
// Copy and install
|
|
190
505
|
// ---------------------------------------------------------------------------
|
|
@@ -195,7 +510,7 @@ function copyListed(root: string, wt: string, entries: string[], log: (m: string
|
|
|
195
510
|
const copyMissing: string[] = [];
|
|
196
511
|
for (const entry of entries) {
|
|
197
512
|
const rel = path.normalize(entry);
|
|
198
|
-
if (
|
|
513
|
+
if (!insideCheckout(rel)) {
|
|
199
514
|
log(`worktree copy: ${entry} is outside the main checkout — skipped`);
|
|
200
515
|
continue;
|
|
201
516
|
}
|
|
@@ -213,6 +528,73 @@ function copyListed(root: string, wt: string, entries: string[], log: (m: string
|
|
|
213
528
|
return { copied, copyMissing };
|
|
214
529
|
}
|
|
215
530
|
|
|
531
|
+
/** What `linkBkitEnv` did with a worktree's `.bkit/.env` (the `bkitEnv` output key). */
|
|
532
|
+
export type BkitEnvState = "linked" | "unchanged" | "copied" | "differs" | "none" | "failed";
|
|
533
|
+
|
|
534
|
+
const sha256 = (content: Buffer) => createHash("sha256").update(content).digest("hex");
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* bkit's own token file, `.bkit/.env`, in a worktree. `copyListed` covers the app env
|
|
538
|
+
* files a repo configures; this one is bkit's, and it is gitignored — so a fresh
|
|
539
|
+
* checkout has none, `.envrc`'s `dotenv_if_exists .bkit/.env` loads nothing and says
|
|
540
|
+
* nothing, and every sign-in here fails with nothing looking wrong.
|
|
541
|
+
*
|
|
542
|
+
* Link to the main checkout's copy: one source of truth, so rotating a token needs no
|
|
543
|
+
* second edit and no copy goes stale. Fall back to a copy where the filesystem refuses
|
|
544
|
+
* a symlink, recording its hash in the feature's outbox folder (`.bkit-env-copy`): a
|
|
545
|
+
* copy bkit made is replaced on the next setup, so a rotated token reaches it too. Any
|
|
546
|
+
* other regular file that differs from the main checkout's is left for a human to read,
|
|
547
|
+
* like a differing `.envrc`; `none` means the main checkout holds no `.bkit/.env` to
|
|
548
|
+
* bring in, which the tip and the advisory then report; `failed` means neither the link
|
|
549
|
+
* nor the copy could be written, narrated.
|
|
550
|
+
*/
|
|
551
|
+
function linkBkitEnv(
|
|
552
|
+
root: string,
|
|
553
|
+
wt: string,
|
|
554
|
+
fid: string,
|
|
555
|
+
log: (m: string) => void,
|
|
556
|
+
): BkitEnvState {
|
|
557
|
+
const main = path.join(root, ".bkit", ".env");
|
|
558
|
+
if (!fs.existsSync(main)) return "none";
|
|
559
|
+
const dest = path.join(wt, ".bkit", ".env");
|
|
560
|
+
const record = path.join(path.dirname(ownershipMarker(root, fid)), ".bkit-env-copy");
|
|
561
|
+
// lstat, so a dangling link is seen (and replaced) rather than followed and missed.
|
|
562
|
+
const stat = fs.lstatSync(dest, { throwIfNoEntry: false });
|
|
563
|
+
if (stat?.isSymbolicLink() && fs.existsSync(dest)) return "unchanged";
|
|
564
|
+
if (stat?.isFile()) {
|
|
565
|
+
const here = fs.readFileSync(dest);
|
|
566
|
+
const bkitMade = fs.existsSync(record) && fs.readFileSync(record, "utf-8") === sha256(here);
|
|
567
|
+
if (!bkitMade && !here.equals(fs.readFileSync(main))) {
|
|
568
|
+
log(
|
|
569
|
+
`bkit-env: ${dest} differs from the main checkout's — left as it is; delete it to link the main checkout's copy`,
|
|
570
|
+
);
|
|
571
|
+
return "differs";
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
575
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
576
|
+
try {
|
|
577
|
+
fs.symlinkSync(main, dest);
|
|
578
|
+
fs.rmSync(record, { force: true });
|
|
579
|
+
return "linked";
|
|
580
|
+
} catch (err) {
|
|
581
|
+
try {
|
|
582
|
+
fs.cpSync(main, dest);
|
|
583
|
+
} catch (copyErr) {
|
|
584
|
+
log(
|
|
585
|
+
`bkit-env: could not link or copy the main checkout's .bkit/.env to ${dest} (${(err as Error).message}; ${(copyErr as Error).message}) — sign-ins in this worktree fail until it is there`,
|
|
586
|
+
);
|
|
587
|
+
return "failed";
|
|
588
|
+
}
|
|
589
|
+
fs.mkdirSync(path.dirname(record), { recursive: true });
|
|
590
|
+
fs.writeFileSync(record, sha256(fs.readFileSync(dest)));
|
|
591
|
+
log(
|
|
592
|
+
`bkit-env: symlink failed (${(err as Error).message}) — copied the main checkout's .bkit/.env`,
|
|
593
|
+
);
|
|
594
|
+
return "copied";
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
216
598
|
/**
|
|
217
599
|
* `direnv allow` the worktree's `.envrc` when it matches the main checkout's
|
|
218
600
|
* byte for byte, so the worktree inherits the trust given there and nothing
|
|
@@ -359,12 +741,24 @@ export function removeWorktree(
|
|
|
359
741
|
// Command
|
|
360
742
|
// ---------------------------------------------------------------------------
|
|
361
743
|
|
|
744
|
+
/**
|
|
745
|
+
* The warning ship prints when the branch it ships names neither the FID nor the
|
|
746
|
+
* issue (case-insensitive); null when it names one. A hand-made branch still ships.
|
|
747
|
+
*/
|
|
748
|
+
export function shipBranchWarning(branch: string, fid: string, issue?: string): string | null {
|
|
749
|
+
const b = branch.toLowerCase();
|
|
750
|
+
const id = (issue ?? "").replace(/^#/, "").toLowerCase();
|
|
751
|
+
if (b.includes(fid.toLowerCase()) || (id !== "" && b.includes(id))) return null;
|
|
752
|
+
return `[bkit-ship] WARNING branch ${branch} not named for ${fid} — shipping it as named`;
|
|
753
|
+
}
|
|
754
|
+
|
|
362
755
|
export const worktreesCommand: CommandSpec = {
|
|
363
756
|
noun: "worktrees",
|
|
364
757
|
summary: "Set up and remove the per-feature worktrees under .worktrees/.",
|
|
365
758
|
verbs: {
|
|
366
759
|
setup: {
|
|
367
760
|
summary: "Create, resume or adopt the feature's worktree (Step 2 — Worktree Setup).",
|
|
761
|
+
use: "workflow",
|
|
368
762
|
flags: [
|
|
369
763
|
WORKFLOW_FLAG,
|
|
370
764
|
FID_FLAG,
|
|
@@ -382,7 +776,12 @@ export const worktreesCommand: CommandSpec = {
|
|
|
382
776
|
{
|
|
383
777
|
name: "branch",
|
|
384
778
|
type: "string",
|
|
385
|
-
help: "ship
|
|
779
|
+
help: "ship or debug: an existing branch the session prompt names; debug refuses a conflicting checkout",
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
name: "issue",
|
|
783
|
+
type: "string",
|
|
784
|
+
help: "ship only: the issue id; a branch naming it (or the FID) prints no branchWarning",
|
|
386
785
|
},
|
|
387
786
|
],
|
|
388
787
|
output: {
|
|
@@ -390,6 +789,8 @@ export const worktreesCommand: CommandSpec = {
|
|
|
390
789
|
repoRoot: "the main checkout",
|
|
391
790
|
branch: "branch checked out at worktreePath",
|
|
392
791
|
mode: "created | resumed | adopted",
|
|
792
|
+
branchWarning:
|
|
793
|
+
"ship: the warning printed when the branch names neither the FID nor --issue, else null",
|
|
393
794
|
owned: "the .worktree-owned marker is present (a workflow created this worktree)",
|
|
394
795
|
rebaseConflict:
|
|
395
796
|
"a resume rebase onto baseRef stopped on a conflict and is left in progress",
|
|
@@ -398,11 +799,21 @@ export const worktreesCommand: CommandSpec = {
|
|
|
398
799
|
baseRef:
|
|
399
800
|
"dev when local dev is a fast-forward of origin/dev (unpushed commits), else origin/dev",
|
|
400
801
|
baseSha: "git merge-base baseRef HEAD at worktreePath, or null",
|
|
802
|
+
carriedSha:
|
|
803
|
+
"resume: the commit holding what an earlier run left uncommitted (a failed ship's record), made before the rebase; else null",
|
|
804
|
+
carriedDropped:
|
|
805
|
+
"resume: untracked logs of this feature dropped because baseRef already holds them (dev's copy wins); one whose content differs is first moved to the feature's outbox folder (dropped-logs/), named in the log",
|
|
401
806
|
copied: "worktree copy entries copied from the main checkout",
|
|
402
807
|
copyMissing: "worktree copy entries absent from the main checkout",
|
|
808
|
+
bkitEnv:
|
|
809
|
+
"bkit's own .bkit/.env: linked to the main checkout's copy, or copied where a symlink is refused (a copy bkit made is refreshed on the next setup); unchanged when already linked, differs when a differing file was left to read, none when the main checkout holds none, failed when neither the link nor the copy could be written, null in adopt mode",
|
|
403
810
|
direnvAllowed:
|
|
404
811
|
"direnv allow ran on the worktree's .envrc (present and identical to the main checkout's)",
|
|
405
812
|
installed: "dependencies were installed",
|
|
813
|
+
startSha:
|
|
814
|
+
"in place on dev (debug): HEAD when the run started, recorded in the shared-checkout record; absent otherwise",
|
|
815
|
+
aheadAtStart:
|
|
816
|
+
"in place on dev (debug): commits local dev held beyond origin/dev when the run started; absent otherwise",
|
|
406
817
|
},
|
|
407
818
|
exitCodes: {
|
|
408
819
|
[EXIT_REBASE_CONFLICT]:
|
|
@@ -411,12 +822,15 @@ export const worktreesCommand: CommandSpec = {
|
|
|
411
822
|
[EXIT_INSTALL]: "dependency install failed",
|
|
412
823
|
[EXIT_INSTALL_COULD_NOT_RUN]: "the package manager could not run (exit 126 / 127)",
|
|
413
824
|
[EXIT_REFUSED]:
|
|
414
|
-
"refused:
|
|
825
|
+
"refused: main as the working branch (dev too, except debug in place), ship of dev / main, detached HEAD, ship could not switch to its branch (a missing feat/{fid} is named), or a design / plan branch carrying unpushed dev commits (publish dev, then re-run)",
|
|
415
826
|
[EXIT_WORKTREE_ADD]: "git worktree add failed",
|
|
416
|
-
[EXIT_REBASE_NOT_STARTED]:
|
|
827
|
+
[EXIT_REBASE_NOT_STARTED]:
|
|
828
|
+
"resume rebase could not start, even after committing what an earlier run left (e.g. a commit hook refused that commit)",
|
|
417
829
|
[EXIT_NOT_A_WORKTREE]: ".worktrees/{fid} exists but is not a registered git worktree",
|
|
830
|
+
[EXIT_SHARED_BUSY]:
|
|
831
|
+
"in place on dev: another feature's run holds this checkout (its shared-checkout record has a live workflow lock); nothing written",
|
|
418
832
|
[EXIT_DISK_FULL]:
|
|
419
|
-
"free disk under bkit.
|
|
833
|
+
"free disk under bkit.workflows.minFreeGb even after your max cleanup steps (`bkit disk prune`); nothing created",
|
|
420
834
|
},
|
|
421
835
|
run: async (ctx) => {
|
|
422
836
|
const f = ctx.flags;
|
|
@@ -428,8 +842,11 @@ export const worktreesCommand: CommandSpec = {
|
|
|
428
842
|
const month = String(f.month);
|
|
429
843
|
if (!/^[0-9]{6}$/.test(month)) throw new CommandError(EXIT.USAGE, "--month must be YYYYMM");
|
|
430
844
|
const named = f.branch === undefined ? undefined : String(f.branch);
|
|
431
|
-
if (named !== undefined && workflow !== "ship") {
|
|
432
|
-
throw new CommandError(EXIT.USAGE, "--branch is ship only");
|
|
845
|
+
if (named !== undefined && workflow !== "ship" && workflow !== "debug") {
|
|
846
|
+
throw new CommandError(EXIT.USAGE, "--branch is ship or debug only");
|
|
847
|
+
}
|
|
848
|
+
if (f.issue !== undefined && workflow !== "ship") {
|
|
849
|
+
throw new CommandError(EXIT.USAGE, "--issue is ship only");
|
|
433
850
|
}
|
|
434
851
|
if (named !== undefined && !runGit(ctx.cwd, ["check-ref-format", "--branch", named]).ok) {
|
|
435
852
|
throw new CommandError(EXIT.USAGE, `--branch "${named}" is not a valid branch name`);
|
|
@@ -444,9 +861,30 @@ export const worktreesCommand: CommandSpec = {
|
|
|
444
861
|
"detached HEAD — check out a branch before debugging",
|
|
445
862
|
);
|
|
446
863
|
}
|
|
447
|
-
const target =
|
|
448
|
-
|
|
449
|
-
|
|
864
|
+
const target =
|
|
865
|
+
workflow === "ship"
|
|
866
|
+
? shipBranch(root, fid, named, session)
|
|
867
|
+
: workflow === "debug" && named
|
|
868
|
+
? named
|
|
869
|
+
: `feat/${fid}`;
|
|
870
|
+
if (isSharedBranch(target) && !(workflow === "debug" && target === DEV)) {
|
|
871
|
+
throw new CommandError(
|
|
872
|
+
EXIT_REFUSED,
|
|
873
|
+
workflow === "ship"
|
|
874
|
+
? `refusing to ship ${target}: /bkit-ship ships a feature branch into ${DEV} only; it never opens a PR from ${DEV} into ${MAIN} or merges into ${MAIN}, releases stay manual. Name the feature branch to ship.`
|
|
875
|
+
: `refusing to ship ${target} as a feature branch`,
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
if (
|
|
879
|
+
workflow === "debug" &&
|
|
880
|
+
named &&
|
|
881
|
+
!hasLocal(root, target) &&
|
|
882
|
+
!runGit(root, ["show-ref", "--verify", "--quiet", `refs/remotes/origin/${target}`]).ok
|
|
883
|
+
) {
|
|
884
|
+
throw new CommandError(
|
|
885
|
+
EXIT_REFUSED,
|
|
886
|
+
`${target} does not exist — debug adopts an existing branch`,
|
|
887
|
+
);
|
|
450
888
|
}
|
|
451
889
|
|
|
452
890
|
// Ship mints only when the session is not already on the branch it ships:
|
|
@@ -477,10 +915,21 @@ export const worktreesCommand: CommandSpec = {
|
|
|
477
915
|
`${wtDir} is not a registered git worktree`,
|
|
478
916
|
);
|
|
479
917
|
}
|
|
918
|
+
if (
|
|
919
|
+
workflow === "debug" &&
|
|
920
|
+
named &&
|
|
921
|
+
git(wtDir, ["branch", "--show-current"]) !== target
|
|
922
|
+
) {
|
|
923
|
+
throw new CommandError(
|
|
924
|
+
EXIT_REFUSED,
|
|
925
|
+
`${wtDir} is on another branch; requested ${target} — leave its work intact and use the matching checkout`,
|
|
926
|
+
);
|
|
927
|
+
}
|
|
480
928
|
mode = "resumed";
|
|
481
929
|
} else if (workflow !== "debug" || session !== target) {
|
|
482
930
|
// Debug adopts an existing feat/{fid}; it never mints a branch of its own.
|
|
483
|
-
if (addWorktree(root, wtDir, target, workflow !== "debug", ctx.log))
|
|
931
|
+
if (addWorktree(root, wtDir, target, workflow !== "debug", workflow, ctx.log))
|
|
932
|
+
mode = "created";
|
|
484
933
|
}
|
|
485
934
|
}
|
|
486
935
|
const wt = mode === "adopted" ? root : wtDir;
|
|
@@ -488,9 +937,21 @@ export const worktreesCommand: CommandSpec = {
|
|
|
488
937
|
const marker = ownershipMarker(root, fid);
|
|
489
938
|
|
|
490
939
|
if (mode === "adopted") {
|
|
940
|
+
if (workflow === "debug" && named && git(root, ["branch", "--show-current"]) !== target) {
|
|
941
|
+
throw new CommandError(
|
|
942
|
+
EXIT_REFUSED,
|
|
943
|
+
`adopt mode: checkout does not hold requested ${target}; use its existing checkout or enable worktrees`,
|
|
944
|
+
);
|
|
945
|
+
}
|
|
491
946
|
if (workflow === "ship" && git(root, ["branch", "--show-current"]) !== target) {
|
|
492
947
|
const sw = runGit(root, ["switch", target]);
|
|
493
948
|
if (!sw.ok) {
|
|
949
|
+
if (!hasLocal(root, target) && remoteHas(root, target) !== "yes") {
|
|
950
|
+
throw new CommandError(
|
|
951
|
+
EXIT_REFUSED,
|
|
952
|
+
`${target} does not exist — name the feature branch to ship`,
|
|
953
|
+
);
|
|
954
|
+
}
|
|
494
955
|
throw new CommandError(
|
|
495
956
|
EXIT_REFUSED,
|
|
496
957
|
`adopt mode: cannot switch to ${target} — commit or stash local changes, then re-run (${sw.stderr})`,
|
|
@@ -498,8 +959,8 @@ export const worktreesCommand: CommandSpec = {
|
|
|
498
959
|
}
|
|
499
960
|
}
|
|
500
961
|
const here = git(root, ["branch", "--show-current"]) ?? "";
|
|
501
|
-
|
|
502
|
-
if (here === "" || here ===
|
|
962
|
+
// Debug may work in place on dev (its shared-checkout path); nothing works in place on main.
|
|
963
|
+
if (here === "" || here === MAIN || (here === DEV && workflow !== "debug")) {
|
|
503
964
|
throw new CommandError(
|
|
504
965
|
EXIT_REFUSED,
|
|
505
966
|
here === ""
|
|
@@ -509,9 +970,30 @@ export const worktreesCommand: CommandSpec = {
|
|
|
509
970
|
}
|
|
510
971
|
}
|
|
511
972
|
|
|
973
|
+
// An in-place run on a shared branch records what was dirty before it, so its
|
|
974
|
+
// commits and push take only its own work.
|
|
975
|
+
const shared =
|
|
976
|
+
mode === "adopted" && isSharedBranch(git(root, ["branch", "--show-current"]) ?? "")
|
|
977
|
+
? openSharedRecord(root, fid, workflow, logDir)
|
|
978
|
+
: undefined;
|
|
979
|
+
|
|
512
980
|
let rebaseConflict = false;
|
|
513
981
|
let sentinel: string | null = null;
|
|
982
|
+
let carried: ReturnType<typeof carryLeftovers> = null;
|
|
514
983
|
const sentinelPath = path.join(logDir, ".rebase-failed");
|
|
984
|
+
// A docs-only branch cannot land while it carries unpushed dev work: refuse
|
|
985
|
+
// now, not after the whole phase. Checked before the resume rebase, which
|
|
986
|
+
// replays such commits under new SHAs this commit-by-commit check no longer
|
|
987
|
+
// knows; the close itself names them then.
|
|
988
|
+
if (DOCS_ONLY_WORKFLOWS.includes(workflow) && mode !== "adopted") {
|
|
989
|
+
const inherited = inheritedDevCommits(root, target);
|
|
990
|
+
if (inherited.length > 0) {
|
|
991
|
+
throw new CommandError(
|
|
992
|
+
EXIT_REFUSED,
|
|
993
|
+
inheritedDevRefusal(root, target, workflow, inherited.length),
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
515
997
|
if (mode === "resumed" && workflow !== "ship") {
|
|
516
998
|
// Cleared before every attempt: a sentinel left by an earlier run would
|
|
517
999
|
// send this one to the Failure Path after a clean rebase.
|
|
@@ -521,16 +1003,37 @@ export const worktreesCommand: CommandSpec = {
|
|
|
521
1003
|
failure = {
|
|
522
1004
|
conflict: true,
|
|
523
1005
|
detail: "a rebase is already in progress",
|
|
524
|
-
onto:
|
|
1006
|
+
onto: worktreeBase(wt, workflow),
|
|
525
1007
|
};
|
|
526
1008
|
} else {
|
|
527
1009
|
fetchBranch(wt, DEV);
|
|
528
|
-
const onto =
|
|
529
|
-
const
|
|
1010
|
+
const onto = worktreeBase(wt, workflow, ctx.log);
|
|
1011
|
+
const statusFile = path.join(logDir, "status.jsonl");
|
|
1012
|
+
carried = carryLeftovers(wt, { fid, onto, statusFile }, ctx.log);
|
|
1013
|
+
// Journal rows a hook appended after the carry commit go aside by hand and
|
|
1014
|
+
// back after the rebase, never through `--autostash`: a dev that appended to
|
|
1015
|
+
// the same file makes the autostash pop conflict, and git still exits 0.
|
|
1016
|
+
const journal = hasLeftovers(wt) ? journalRowsAppended(wt, statusFile) : null;
|
|
1017
|
+
for (const [rel, a] of journal ?? []) fs.writeFileSync(path.join(wt, rel), a.committed);
|
|
1018
|
+
// A tracked copy entry setup copied over (a committed placeholder `.env`) is
|
|
1019
|
+
// never committed, so the rebase sets it aside and puts it back. Only when
|
|
1020
|
+
// nothing else is left: a refused carry commit still stops the rebase.
|
|
1021
|
+
const aside = hasLeftovers(wt) ? [] : ["--autostash"];
|
|
1022
|
+
const before = git(wt, ["rev-parse", "HEAD"]);
|
|
1023
|
+
const rb = runGit(wt, ["rebase", "--rebase-merges", ...aside, onto]);
|
|
1024
|
+
const unput = journal === null ? "" : putJournalRowsBack(wt, journal);
|
|
1025
|
+
// The rebase replays the carry commit on top: report the replayed one.
|
|
1026
|
+
if (rb.ok && carried?.sha) carried.sha = git(wt, ["rev-parse", "HEAD"]);
|
|
1027
|
+
if (rb.ok)
|
|
1028
|
+
recordRebase(
|
|
1029
|
+
path.join(logDir, "status.jsonl"),
|
|
1030
|
+
before,
|
|
1031
|
+
git(wt, ["rev-parse", "HEAD"]),
|
|
1032
|
+
);
|
|
530
1033
|
if (!rb.ok) {
|
|
531
1034
|
failure = {
|
|
532
1035
|
conflict: rebaseInProgress(wt),
|
|
533
|
-
detail: [rb.stdout, rb.stderr].filter(Boolean).join("\n"),
|
|
1036
|
+
detail: [rb.stdout, rb.stderr, unput].filter(Boolean).join("\n"),
|
|
534
1037
|
onto,
|
|
535
1038
|
};
|
|
536
1039
|
}
|
|
@@ -559,26 +1062,41 @@ export const worktreesCommand: CommandSpec = {
|
|
|
559
1062
|
const { copied, copyMissing } = done
|
|
560
1063
|
? copyListed(root, wt, config.worktreeCopy, ctx.log)
|
|
561
1064
|
: { copied: [], copyMissing: [] };
|
|
1065
|
+
const bkitEnv = done ? linkBkitEnv(root, wt, fid, ctx.log) : null;
|
|
562
1066
|
const direnvAllowed = done && allowDirenv(root, wt, ctx.log);
|
|
563
|
-
const wantInstall =
|
|
1067
|
+
const wantInstall =
|
|
1068
|
+
done && config.worktreeInstall && fs.existsSync(path.join(wt, "package.json"));
|
|
564
1069
|
const installStatus = wantInstall ? install(wt, ctx.log) : 0;
|
|
565
1070
|
|
|
566
|
-
const baseRef =
|
|
1071
|
+
const baseRef = worktreeBase(wt, workflow);
|
|
1072
|
+
const branch = git(wt, ["branch", "--show-current"]) ?? "";
|
|
1073
|
+
const branchWarning =
|
|
1074
|
+
workflow === "ship"
|
|
1075
|
+
? shipBranchWarning(branch, fid, f.issue === undefined ? undefined : String(f.issue))
|
|
1076
|
+
: null;
|
|
1077
|
+
if (branchWarning !== null) ctx.log(branchWarning);
|
|
567
1078
|
ctx.emit({
|
|
568
1079
|
worktreePath: wt,
|
|
569
1080
|
repoRoot: root,
|
|
570
|
-
branch
|
|
1081
|
+
branch,
|
|
571
1082
|
mode,
|
|
1083
|
+
branchWarning,
|
|
572
1084
|
owned: fs.existsSync(marker),
|
|
573
1085
|
rebaseConflict,
|
|
574
1086
|
sentinel,
|
|
575
1087
|
logDir,
|
|
576
1088
|
baseRef,
|
|
577
1089
|
baseSha: git(wt, ["merge-base", baseRef, "HEAD"]),
|
|
1090
|
+
carriedSha: carried?.sha ?? null,
|
|
1091
|
+
carriedDropped: carried?.dropped ?? [],
|
|
578
1092
|
copied,
|
|
579
1093
|
copyMissing,
|
|
1094
|
+
bkitEnv,
|
|
580
1095
|
direnvAllowed,
|
|
581
1096
|
installed: wantInstall && installStatus === 0,
|
|
1097
|
+
...(shared === undefined
|
|
1098
|
+
? {}
|
|
1099
|
+
: { startSha: shared.startSha, aheadAtStart: shared.aheadAtStart }),
|
|
582
1100
|
});
|
|
583
1101
|
if (sentinel !== null)
|
|
584
1102
|
return rebaseConflict ? EXIT_REBASE_CONFLICT : EXIT_REBASE_NOT_STARTED;
|
|
@@ -598,6 +1116,7 @@ export const worktreesCommand: CommandSpec = {
|
|
|
598
1116
|
remove: {
|
|
599
1117
|
summary:
|
|
600
1118
|
"Remove .worktrees/{fid} when a workflow created it, prune stale entries, and delete the feature branch.",
|
|
1119
|
+
use: "workflow",
|
|
601
1120
|
flags: [
|
|
602
1121
|
FID_FLAG,
|
|
603
1122
|
{
|