@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,972 @@
|
|
|
1
|
+
// commands/install/uninstall.ts — Single owner of all uninstall logic. (P2.T5-P2.T8)
|
|
2
|
+
//
|
|
3
|
+
// runUninstall(modules, ctx) orchestrates:
|
|
4
|
+
// 1. For each installed file — single dispatch on entry.format:
|
|
5
|
+
// - "json" : stripTier2JsonScope (strip bkit-owned JSON scope)
|
|
6
|
+
// - "markered-text" : stripManagedBlock, remove file if empty remainder
|
|
7
|
+
// - "byte-equal-text" : delete only if unchanged since bkit wrote it (canonicalHashes)
|
|
8
|
+
// 2. package.json: the `bkit` install-state block (full/core uninstall). Scripts and
|
|
9
|
+
// devDeps are the consumer's — the bkit:gate:* names included — and are left alone.
|
|
10
|
+
// 2b. docs/ (full/core uninstall): bkit's managed block stripped from every installed
|
|
11
|
+
// `docs/*.md`, the owned `docs/templates/bkit-*.md` deleted.
|
|
12
|
+
// 3. .agents/ mirror files (bkit-prefix .md files in .claude/ .cursor/)
|
|
13
|
+
//
|
|
14
|
+
// Flags:
|
|
15
|
+
// --dry-run print decision table (FILE / DECISION / REASON) without writes
|
|
16
|
+
// --force override the byte-equal-text hash guard (delete even if consumer modified)
|
|
17
|
+
// --nuke confirm prompt then wipe ALL bkit-managed files regardless of format
|
|
18
|
+
// --yes skip interactive confirm for --nuke
|
|
19
|
+
//
|
|
20
|
+
// Observability: console.error("[bkit-uninstall] …") for all error paths.
|
|
21
|
+
|
|
22
|
+
import * as fs from "node:fs";
|
|
23
|
+
import * as path from "node:path";
|
|
24
|
+
import * as readline from "node:readline";
|
|
25
|
+
import type { JsonValue, WriteSet } from "../../install/write.js";
|
|
26
|
+
import { stripManagedBlock, detectMarkerStyle } from "../../install/managed-block.js";
|
|
27
|
+
import { readTemplate } from "../../render/parts.js";
|
|
28
|
+
import {
|
|
29
|
+
getInstallManifest,
|
|
30
|
+
type ManifestEntry,
|
|
31
|
+
type ModuleName,
|
|
32
|
+
type IssueTracker,
|
|
33
|
+
} from "../../install/manifest.js";
|
|
34
|
+
import { isConsumerModified, readBkitVersion } from "../../install/version-file.js";
|
|
35
|
+
import {
|
|
36
|
+
getPkgRoot,
|
|
37
|
+
getSharedRoot,
|
|
38
|
+
findTemplateSource,
|
|
39
|
+
TEMPLATE_COPIES_DIR,
|
|
40
|
+
} from "../../shared/package-roots.js";
|
|
41
|
+
import { removeOpencodeProviderBlock, renderOpencodeJson } from "../../install/modules/opencode.js";
|
|
42
|
+
import {
|
|
43
|
+
CLAUDE_CLOUD_RELPATH,
|
|
44
|
+
CURSOR_CLOUD_RELPATH,
|
|
45
|
+
resolveClaudeDerivedAllows,
|
|
46
|
+
} from "../../install/cloud-env.js";
|
|
47
|
+
import type { ModuleFlag, UninstallFlags } from "../../cli.js";
|
|
48
|
+
import { LOG_PREFIX, setLogPrefix } from "../../shared/log-prefix.js";
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Types
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
export interface UninstallContext {
|
|
55
|
+
/** Consumer repo root (defaults to process.cwd()). */
|
|
56
|
+
cwd: string;
|
|
57
|
+
/** Dry-run: compute decisions but do NOT write to disk. */
|
|
58
|
+
dryRun: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Force-delete byte-equal-text files even if their hash differs (consumer modified).
|
|
61
|
+
* Default: false (preserve consumer modifications).
|
|
62
|
+
*/
|
|
63
|
+
force: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Nuke mode: remove ALL bkit-managed files regardless of format or
|
|
66
|
+
* consumer modifications. Requires --yes or interactive confirm.
|
|
67
|
+
* Default: false.
|
|
68
|
+
*/
|
|
69
|
+
nuke: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Skip interactive confirm for --nuke. Useful in non-interactive scripts.
|
|
72
|
+
*/
|
|
73
|
+
yes: boolean;
|
|
74
|
+
/** Log prefix for console output. */
|
|
75
|
+
logPrefix: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Decision taken for each file during uninstall. */
|
|
79
|
+
export type FileDecision =
|
|
80
|
+
"delete" | "strip-block" | "preserve" | "skip-absent" | "skip-modified" | "skip-unknown";
|
|
81
|
+
|
|
82
|
+
export interface FileSummary {
|
|
83
|
+
file: string;
|
|
84
|
+
decision: FileDecision;
|
|
85
|
+
reason: string;
|
|
86
|
+
format: "json" | "markered-text" | "byte-equal-text";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface UninstallResult {
|
|
90
|
+
deleted: string[];
|
|
91
|
+
stripped: string[];
|
|
92
|
+
preserved: string[];
|
|
93
|
+
decisions: FileSummary[];
|
|
94
|
+
dryRun: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// stripTier2JsonScope — remove bkit-owned JSON scope from consumer doc (BAR-167 Phase 1)
|
|
99
|
+
//
|
|
100
|
+
// Pure function — no file I/O.
|
|
101
|
+
//
|
|
102
|
+
// Algorithm:
|
|
103
|
+
// 1. Deep-clone consumer to `out`.
|
|
104
|
+
// 2. Walk template; for each leaf path `p`:
|
|
105
|
+
// - If `out[p]` deep-equals template[p] → delete it from `out`.
|
|
106
|
+
// - Else leave it (consumer has customised it — preserve).
|
|
107
|
+
// 3. Prune empty intermediate objects ONLY where template populated them
|
|
108
|
+
// (NOT arrays; NOT consumer-only siblings).
|
|
109
|
+
// 4. Return `out`.
|
|
110
|
+
//
|
|
111
|
+
// Consumer-only keys at any level are preserved byte-identical.
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Detect the tracker bkit seeded into opencode.json from its mcp keys. The template ships an
|
|
116
|
+
* `@@OPENCODE_TRACKER_MCP@@` sentinel KEY that renders to `github` / `linear` at install, so a
|
|
117
|
+
* strip-scope keyed on the raw template never matches — these detectors let uninstall render the
|
|
118
|
+
* template the same way the install did before stripping. Keyed on bkit's known tracker names so
|
|
119
|
+
* a consumer-added mcp server is never mistaken for bkit's.
|
|
120
|
+
*/
|
|
121
|
+
function detectOpencodeTracker(doc: Record<string, JsonValue>): IssueTracker {
|
|
122
|
+
const mcp = doc.mcp;
|
|
123
|
+
if (mcp !== null && typeof mcp === "object" && !Array.isArray(mcp)) {
|
|
124
|
+
if ("github" in mcp) return "github";
|
|
125
|
+
if ("linear" in mcp) return "linear";
|
|
126
|
+
}
|
|
127
|
+
return "none";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Detect the opencode provider key bkit seeded (the first `provider` block key). */
|
|
131
|
+
function detectOpencodeProvider(doc: Record<string, JsonValue>): string {
|
|
132
|
+
const provider = doc.provider;
|
|
133
|
+
if (provider !== null && typeof provider === "object" && !Array.isArray(provider)) {
|
|
134
|
+
const keys = Object.keys(provider);
|
|
135
|
+
if (keys.length > 0) {
|
|
136
|
+
const first = keys[0];
|
|
137
|
+
// Zen block is keyed `opencode` (built-in id); map back to the bkit CLI key.
|
|
138
|
+
return first === "opencode" ? "opencode-zen" : first;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return "opencode-zen";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function stripTier2JsonScope(
|
|
145
|
+
consumerDoc: Record<string, JsonValue>,
|
|
146
|
+
templateDoc: Record<string, JsonValue>,
|
|
147
|
+
): Record<string, JsonValue> {
|
|
148
|
+
const out = JSON.parse(JSON.stringify(consumerDoc)) as Record<string, JsonValue>;
|
|
149
|
+
_stripScope(out, templateDoc);
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function _stripScope(
|
|
154
|
+
consumer: Record<string, JsonValue>,
|
|
155
|
+
template: Record<string, JsonValue>,
|
|
156
|
+
): void {
|
|
157
|
+
for (const key of Object.keys(template)) {
|
|
158
|
+
const tVal = template[key];
|
|
159
|
+
const cVal = consumer[key];
|
|
160
|
+
if (cVal === undefined) continue; // consumer doesn't have it — nothing to strip
|
|
161
|
+
|
|
162
|
+
if (
|
|
163
|
+
tVal !== null &&
|
|
164
|
+
typeof tVal === "object" &&
|
|
165
|
+
!Array.isArray(tVal) &&
|
|
166
|
+
cVal !== null &&
|
|
167
|
+
typeof cVal === "object" &&
|
|
168
|
+
!Array.isArray(cVal)
|
|
169
|
+
) {
|
|
170
|
+
// Both plain objects — recurse into them
|
|
171
|
+
const tObj = tVal as Record<string, JsonValue>;
|
|
172
|
+
const cObj = cVal as Record<string, JsonValue>;
|
|
173
|
+
_stripScope(cObj, tObj);
|
|
174
|
+
// Prune empty intermediate only if template populated this key
|
|
175
|
+
if (Object.keys(cObj).length === 0) {
|
|
176
|
+
delete consumer[key];
|
|
177
|
+
}
|
|
178
|
+
} else if (Array.isArray(tVal) && Array.isArray(cVal)) {
|
|
179
|
+
// Both arrays — strip ELEMENT-WISE, not whole-array: install enriches some lists
|
|
180
|
+
// after rendering the template (apex-domain `WebFetch` entries in
|
|
181
|
+
// `.claude/settings.json` `permissions.allow`).
|
|
182
|
+
const tSerialised = new Set(tVal.map((el) => JSON.stringify(el)));
|
|
183
|
+
const kept = cVal.filter((el) => !tSerialised.has(JSON.stringify(el)));
|
|
184
|
+
if (kept.length === 0) {
|
|
185
|
+
delete consumer[key];
|
|
186
|
+
} else {
|
|
187
|
+
consumer[key] = kept as JsonValue;
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
// Leaf (primitive, null) — remove if deep-equal to template
|
|
191
|
+
if (JSON.stringify(cVal) === JSON.stringify(tVal)) {
|
|
192
|
+
delete consumer[key];
|
|
193
|
+
}
|
|
194
|
+
// else: consumer has a different value — preserve it
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// `.mcp.json` / `.cursor/mcp.json`: bkit owns only its tracker entry under `mcpServers`
|
|
200
|
+
// (reconcileMcpJson), so uninstall removes exactly that, never a leaf-by-leaf strip.
|
|
201
|
+
const MCP_JSON_RELPATHS = new Set([".mcp.json", path.join(".cursor", "mcp.json")]);
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Remove each `mcpServers` entry that is identical to a tracker entry in the template — the
|
|
205
|
+
* entry bkit wrote. A consumer's own servers, and a bkit entry the consumer edited, stay. Drops
|
|
206
|
+
* `mcpServers` once empty, so a file bkit wrote alone strips to `{}` (deleted by the caller).
|
|
207
|
+
* Pure function — no file I/O.
|
|
208
|
+
*/
|
|
209
|
+
export function stripMcpTrackerEntries(
|
|
210
|
+
consumer: Record<string, JsonValue>,
|
|
211
|
+
template: Record<string, JsonValue>,
|
|
212
|
+
): Record<string, JsonValue> {
|
|
213
|
+
const out = JSON.parse(JSON.stringify(consumer)) as Record<string, JsonValue>;
|
|
214
|
+
const servers = out.mcpServers;
|
|
215
|
+
const owned = template.mcpServers;
|
|
216
|
+
if (!isJsonObject(servers) || !isJsonObject(owned)) return out;
|
|
217
|
+
for (const [key, entry] of Object.entries(owned)) {
|
|
218
|
+
if (JSON.stringify(servers[key]) === JSON.stringify(entry)) delete servers[key];
|
|
219
|
+
}
|
|
220
|
+
if (Object.keys(servers).length === 0) delete out.mcpServers;
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function isJsonObject(v: JsonValue | undefined): v is Record<string, JsonValue> {
|
|
225
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
// Decision table builder (for --dry-run output and UninstallResult)
|
|
230
|
+
// ---------------------------------------------------------------------------
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Build a decision table for all files that would be affected by uninstall.
|
|
234
|
+
* Does NOT perform any writes.
|
|
235
|
+
*/
|
|
236
|
+
// Core doctrine files installed by the templates pass (runCoreTemplates), NOT the manifest —
|
|
237
|
+
// so the manifest-driven table never sees them and a full uninstall would orphan bkit's own
|
|
238
|
+
// rules/docs. Each carries a bkit managed block (markered-text), so strip-block preserves any
|
|
239
|
+
// consumer content added below `bkit:end`, exactly like the root AGENTS.md. Removed only on a
|
|
240
|
+
// full/core uninstall (gated on core in moduleList below).
|
|
241
|
+
const CORE_TEMPLATE_DOCTRINE: ManifestEntry[] = [
|
|
242
|
+
{ path: ".agents/context.md", format: "markered-text", module: "core" },
|
|
243
|
+
{ path: ".agents/docs.md", format: "markered-text", module: "core" },
|
|
244
|
+
{ path: ".agents/rules.md", format: "markered-text", module: "core" },
|
|
245
|
+
{ path: ".agents/skills.md", format: "markered-text", module: "core" },
|
|
246
|
+
];
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The top-level `docs/*.md` the core payload pass installs: each carries bkit's managed
|
|
250
|
+
* block (`bkit:start` / `bkit:end`, managed marker inside), so uninstall strips the block
|
|
251
|
+
* and keeps the consumer's content, exactly like `.agents/*.md`. The payload's
|
|
252
|
+
* `shared/docs/` holds only these block docs; `docs/capabilities.md` is a template
|
|
253
|
+
* (copied, never installed) and is left alone.
|
|
254
|
+
*/
|
|
255
|
+
function coreDocEntries(): ManifestEntry[] {
|
|
256
|
+
const dir = path.join(getSharedRoot(), "docs");
|
|
257
|
+
if (!fs.existsSync(dir)) return [];
|
|
258
|
+
return fs
|
|
259
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
260
|
+
.filter((e) => e.isFile() && e.name.endsWith(".md"))
|
|
261
|
+
.map((e): ManifestEntry => ({
|
|
262
|
+
path: path.join("docs", e.name),
|
|
263
|
+
format: "markered-text",
|
|
264
|
+
module: "core",
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Prefix of the bkit-owned files under `docs/templates/`; uninstall deletes them whole. */
|
|
269
|
+
const DOCS_TEMPLATES_DIR = path.join("docs", "templates");
|
|
270
|
+
const isOwnedDocsTemplate = (name: string) => name.startsWith("bkit-") && name.endsWith(".md");
|
|
271
|
+
|
|
272
|
+
export function buildDecisionTable(
|
|
273
|
+
modules: ModuleName[] | Set<string>,
|
|
274
|
+
ctx: Pick<UninstallContext, "cwd" | "force" | "nuke">,
|
|
275
|
+
): FileSummary[] {
|
|
276
|
+
const moduleList =
|
|
277
|
+
modules instanceof Set
|
|
278
|
+
? ([...modules].filter((m) =>
|
|
279
|
+
// Includes the opt-in add-ons (cloud) a Set caller passes.
|
|
280
|
+
["core", "claude", "cursor", "opencode", "codex", "cloud"].includes(m),
|
|
281
|
+
) as ModuleName[])
|
|
282
|
+
: (modules as ModuleName[]);
|
|
283
|
+
|
|
284
|
+
const entries = [
|
|
285
|
+
...getInstallManifest(moduleList),
|
|
286
|
+
...(moduleList.includes("core") ? [...CORE_TEMPLATE_DOCTRINE, ...coreDocEntries()] : []),
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
// The hash of every owned file as bkit last wrote it.
|
|
290
|
+
const versionFilePath = path.join(ctx.cwd, ".bkit", "version");
|
|
291
|
+
const canonicalHashes = readBkitVersion(versionFilePath)?.canonicalHashes ?? {};
|
|
292
|
+
|
|
293
|
+
const table: FileSummary[] = [];
|
|
294
|
+
const seen = new Set<string>();
|
|
295
|
+
|
|
296
|
+
for (const entry of entries) {
|
|
297
|
+
const absPath = path.join(ctx.cwd, entry.path);
|
|
298
|
+
const key = entry.path;
|
|
299
|
+
if (seen.has(key)) continue; // deduplicate (a path listed by more than one module)
|
|
300
|
+
seen.add(key);
|
|
301
|
+
|
|
302
|
+
if (!fs.existsSync(absPath)) {
|
|
303
|
+
table.push({
|
|
304
|
+
file: entry.path,
|
|
305
|
+
decision: "skip-absent",
|
|
306
|
+
reason: "file not found — nothing to do",
|
|
307
|
+
format: entry.format,
|
|
308
|
+
});
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (ctx.nuke) {
|
|
313
|
+
// Nuke: delete everything regardless of format
|
|
314
|
+
table.push({
|
|
315
|
+
file: entry.path,
|
|
316
|
+
decision: "delete",
|
|
317
|
+
reason: "--nuke: forcibly remove",
|
|
318
|
+
format: entry.format,
|
|
319
|
+
});
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Single dispatch on entry.format
|
|
324
|
+
switch (entry.format) {
|
|
325
|
+
case "json": {
|
|
326
|
+
// JSON deep-containment: strip bkit-owned scope from consumer doc
|
|
327
|
+
// For uninstall, treat as strip-block (handled in runUninstall via stripTier2JsonScope)
|
|
328
|
+
table.push({
|
|
329
|
+
file: entry.path,
|
|
330
|
+
decision: "strip-block",
|
|
331
|
+
reason: "json (deep-containment) — strip bkit-owned scope, preserve consumer keys",
|
|
332
|
+
format: "json",
|
|
333
|
+
});
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
case "markered-text": {
|
|
337
|
+
const content = fs.readFileSync(absPath, "utf-8");
|
|
338
|
+
const style = detectMarkerStyle(content);
|
|
339
|
+
if (!style) {
|
|
340
|
+
table.push({
|
|
341
|
+
file: entry.path,
|
|
342
|
+
decision: "preserve",
|
|
343
|
+
reason: "markered-text but no bkit markers found — 100% consumer content",
|
|
344
|
+
format: "markered-text",
|
|
345
|
+
});
|
|
346
|
+
} else {
|
|
347
|
+
table.push({
|
|
348
|
+
file: entry.path,
|
|
349
|
+
decision: "strip-block",
|
|
350
|
+
reason: "markered-text — strip bkit block, preserve consumer content",
|
|
351
|
+
format: "markered-text",
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case "byte-equal-text": {
|
|
357
|
+
// .bkit/version is bkit's own install-state manifest (pinnedVersion + hashes), never
|
|
358
|
+
// consumer content. It records no hash for itself, so the generic hash-guard preserves it
|
|
359
|
+
// as "consumer-modified" — leaving bkit state behind after a full teardown. It is
|
|
360
|
+
// `module: core`, so it only reaches this table on a full/core uninstall; delete it there
|
|
361
|
+
// (zero-footprint). A targeted (non-core) uninstall never sees it, so the modules that
|
|
362
|
+
// remain keep working. The hashes are read into memory before the delete loop, so
|
|
363
|
+
// removing this file mid-loop cannot affect any other file's decision.
|
|
364
|
+
if (entry.path === ".bkit/version") {
|
|
365
|
+
table.push({
|
|
366
|
+
file: entry.path,
|
|
367
|
+
decision: "delete",
|
|
368
|
+
reason: "bkit install-state manifest — removed on full/core uninstall",
|
|
369
|
+
format: "byte-equal-text",
|
|
370
|
+
});
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
if (ctx.force) {
|
|
374
|
+
table.push({
|
|
375
|
+
file: entry.path,
|
|
376
|
+
decision: "delete",
|
|
377
|
+
reason: "--force: delete byte-equal-text regardless of hash",
|
|
378
|
+
format: "byte-equal-text",
|
|
379
|
+
});
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
if (canonicalHashes[entry.path] === undefined) {
|
|
383
|
+
table.push({
|
|
384
|
+
file: entry.path,
|
|
385
|
+
decision: "skip-unknown",
|
|
386
|
+
reason:
|
|
387
|
+
"byte-equal-text: no recorded install-time hash — preserve (consumer may have modified it)",
|
|
388
|
+
format: "byte-equal-text",
|
|
389
|
+
});
|
|
390
|
+
} else if (!isConsumerModified(entry.path, absPath, canonicalHashes)) {
|
|
391
|
+
table.push({
|
|
392
|
+
file: entry.path,
|
|
393
|
+
decision: "delete",
|
|
394
|
+
reason: "byte-equal-text: content matches install-time hash — safe to delete",
|
|
395
|
+
format: "byte-equal-text",
|
|
396
|
+
});
|
|
397
|
+
} else {
|
|
398
|
+
table.push({
|
|
399
|
+
file: entry.path,
|
|
400
|
+
decision: "skip-modified",
|
|
401
|
+
reason:
|
|
402
|
+
"byte-equal-text: content differs from install-time hash — consumer modified, preserve",
|
|
403
|
+
format: "byte-equal-text",
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// `docs/templates/bkit-*.md` are bkit-owned whole (the audit templates and the plan
|
|
412
|
+
// template); the consumer's own files in that folder stay. Full/core uninstall only.
|
|
413
|
+
const templatesDir = path.join(ctx.cwd, DOCS_TEMPLATES_DIR);
|
|
414
|
+
if (moduleList.includes("core") && fs.existsSync(templatesDir)) {
|
|
415
|
+
for (const name of fs.readdirSync(templatesDir).sort()) {
|
|
416
|
+
const rel = path.join(DOCS_TEMPLATES_DIR, name);
|
|
417
|
+
if (!isOwnedDocsTemplate(name) || seen.has(rel)) continue;
|
|
418
|
+
if (!fs.statSync(path.join(ctx.cwd, rel)).isFile()) continue;
|
|
419
|
+
seen.add(rel);
|
|
420
|
+
table.push({
|
|
421
|
+
file: rel,
|
|
422
|
+
decision: "delete",
|
|
423
|
+
reason: "bkit-owned docs template — removed on full/core uninstall",
|
|
424
|
+
format: "markered-text",
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return table;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// ---------------------------------------------------------------------------
|
|
433
|
+
// Format dry-run decision table
|
|
434
|
+
// ---------------------------------------------------------------------------
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Format a decision table as a human-readable string.
|
|
438
|
+
* Format: FILE | DECISION | REASON
|
|
439
|
+
*/
|
|
440
|
+
export function formatDecisionTable(table: FileSummary[]): string {
|
|
441
|
+
if (table.length === 0) return "[bkit-uninstall] No files to process.\n";
|
|
442
|
+
|
|
443
|
+
const COL_FILE = 48;
|
|
444
|
+
const COL_DEC = 22;
|
|
445
|
+
|
|
446
|
+
const header =
|
|
447
|
+
`${"FILE".padEnd(COL_FILE)} | ${"DECISION".padEnd(COL_DEC)} | REASON\n` +
|
|
448
|
+
`${"-".repeat(COL_FILE)}-+-${"-".repeat(COL_DEC)}-+-${"-".repeat(40)}\n`;
|
|
449
|
+
|
|
450
|
+
const rows = table
|
|
451
|
+
.map((r) => `${r.file.padEnd(COL_FILE)} | ${r.decision.padEnd(COL_DEC)} | ${r.reason}`)
|
|
452
|
+
.join("\n");
|
|
453
|
+
|
|
454
|
+
return header + rows + "\n";
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// ---------------------------------------------------------------------------
|
|
458
|
+
// Prompt helper (--nuke confirmation)
|
|
459
|
+
// ---------------------------------------------------------------------------
|
|
460
|
+
|
|
461
|
+
async function confirmNuke(): Promise<boolean> {
|
|
462
|
+
return new Promise((resolve) => {
|
|
463
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
464
|
+
rl.question(
|
|
465
|
+
"[bkit-uninstall] --nuke will delete ALL bkit-managed files. Type 'yes' to confirm: ",
|
|
466
|
+
(answer) => {
|
|
467
|
+
rl.close();
|
|
468
|
+
resolve(answer.trim().toLowerCase() === "yes");
|
|
469
|
+
},
|
|
470
|
+
);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ---------------------------------------------------------------------------
|
|
475
|
+
// runUninstall — main orchestrator
|
|
476
|
+
// ---------------------------------------------------------------------------
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Perform the uninstall operation for the given modules.
|
|
480
|
+
* Returns an UninstallResult describing what was done.
|
|
481
|
+
*/
|
|
482
|
+
export async function runUninstall(
|
|
483
|
+
modules: ModuleName[] | Set<string>,
|
|
484
|
+
ctx: UninstallContext,
|
|
485
|
+
): Promise<UninstallResult> {
|
|
486
|
+
const result: UninstallResult = {
|
|
487
|
+
deleted: [],
|
|
488
|
+
stripped: [],
|
|
489
|
+
preserved: [],
|
|
490
|
+
decisions: [],
|
|
491
|
+
dryRun: ctx.dryRun,
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const moduleList =
|
|
495
|
+
modules instanceof Set
|
|
496
|
+
? ([...modules].filter((m) =>
|
|
497
|
+
// Includes the opt-in add-ons (cloud) a Set caller passes.
|
|
498
|
+
["core", "claude", "cursor", "opencode", "codex", "cloud"].includes(m),
|
|
499
|
+
) as ModuleName[])
|
|
500
|
+
: (modules as ModuleName[]);
|
|
501
|
+
|
|
502
|
+
// Nuke confirmation
|
|
503
|
+
if (ctx.nuke && !ctx.yes && !ctx.dryRun) {
|
|
504
|
+
const confirmed = await confirmNuke();
|
|
505
|
+
if (!confirmed) {
|
|
506
|
+
console.log(`${ctx.logPrefix} --nuke cancelled.`);
|
|
507
|
+
return result;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const table = buildDecisionTable(moduleList, ctx);
|
|
512
|
+
result.decisions = table;
|
|
513
|
+
|
|
514
|
+
if (ctx.dryRun) {
|
|
515
|
+
console.log(`${ctx.logPrefix} [dry-run] Decision table:`);
|
|
516
|
+
console.log(formatDecisionTable(table));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const seen = new Set<string>();
|
|
520
|
+
|
|
521
|
+
for (const summary of table) {
|
|
522
|
+
if (seen.has(summary.file)) continue;
|
|
523
|
+
seen.add(summary.file);
|
|
524
|
+
|
|
525
|
+
const absPath = path.join(ctx.cwd, summary.file);
|
|
526
|
+
|
|
527
|
+
switch (summary.decision) {
|
|
528
|
+
case "skip-absent":
|
|
529
|
+
case "skip-modified":
|
|
530
|
+
case "skip-unknown":
|
|
531
|
+
case "preserve": {
|
|
532
|
+
result.preserved.push(summary.file);
|
|
533
|
+
if (!ctx.dryRun) {
|
|
534
|
+
console.log(`${ctx.logPrefix} preserve: ${summary.file} (${summary.reason})`);
|
|
535
|
+
}
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
case "delete": {
|
|
540
|
+
result.deleted.push(summary.file);
|
|
541
|
+
if (!ctx.dryRun) {
|
|
542
|
+
try {
|
|
543
|
+
fs.rmSync(absPath, { force: true });
|
|
544
|
+
console.log(`${ctx.logPrefix} delete: ${summary.file}`);
|
|
545
|
+
} catch (err) {
|
|
546
|
+
console.error(
|
|
547
|
+
`${ctx.logPrefix} error deleting ${summary.file}: ${(err as Error).message}`,
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
case "strip-block": {
|
|
555
|
+
if (!ctx.dryRun) {
|
|
556
|
+
try {
|
|
557
|
+
if (summary.format === "json") {
|
|
558
|
+
// JSON deep-containment: strip bkit-owned scope, preserve consumer keys
|
|
559
|
+
const templatePath = findTemplateSource(summary.file);
|
|
560
|
+
if (templatePath === null || !fs.existsSync(templatePath)) {
|
|
561
|
+
// No payload source — preserve as-is
|
|
562
|
+
console.warn(`${ctx.logPrefix} no template found for ${summary.file} — preserving`);
|
|
563
|
+
result.preserved.push(summary.file);
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
const raw = fs.readFileSync(absPath, "utf-8");
|
|
567
|
+
const consumerDoc = JSON.parse(raw) as Record<string, JsonValue>;
|
|
568
|
+
let templateRaw = fs.readFileSync(templatePath, "utf-8");
|
|
569
|
+
// opencode.json ships `@@OPENCODE_*@@` sentinel KEYS that render to the consumer's
|
|
570
|
+
// tracker / provider at install; strip-scope keyed on the RAW template never matches
|
|
571
|
+
// the rendered keys, so bkit's mcp + provider blocks (a token-referencing config)
|
|
572
|
+
// survive a full uninstall. Render the template with the consumer's OWN tracker +
|
|
573
|
+
// provider first so the keys line up and the bkit-owned scope strips cleanly.
|
|
574
|
+
if (templateRaw.includes("@@OPENCODE_TRACKER_MCP@@")) {
|
|
575
|
+
templateRaw = renderOpencodeJson(
|
|
576
|
+
templatePath,
|
|
577
|
+
detectOpencodeTracker(consumerDoc),
|
|
578
|
+
detectOpencodeProvider(consumerDoc),
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
const templateDoc = JSON.parse(templateRaw) as Record<string, JsonValue>;
|
|
582
|
+
// `.claude/settings.json` is not written verbatim: after rendering the
|
|
583
|
+
// template, install appends one `WebFetch(domain:<d>)` grant per entry in
|
|
584
|
+
// the resolved network allowlist and `mcp__…` grants per declared MCP
|
|
585
|
+
// server (enrichClaudeSettingsAllows). Stripping
|
|
586
|
+
// against the RAW template leaves those grants behind as if the consumer
|
|
587
|
+
// had added them. Recompute the same set — the very function that produced
|
|
588
|
+
// them — and treat it as part of the template, exactly as the opencode.json
|
|
589
|
+
// sentinel render above does.
|
|
590
|
+
if (summary.file === path.join(".claude", "settings.json")) {
|
|
591
|
+
const perms = templateDoc.permissions;
|
|
592
|
+
if (perms !== null && typeof perms === "object" && !Array.isArray(perms)) {
|
|
593
|
+
const permsObj = perms as Record<string, JsonValue>;
|
|
594
|
+
const allow = permsObj.allow;
|
|
595
|
+
if (Array.isArray(allow)) {
|
|
596
|
+
const enriched = resolveClaudeDerivedAllows(ctx.cwd);
|
|
597
|
+
permsObj.allow = [
|
|
598
|
+
...allow,
|
|
599
|
+
...enriched.filter((e) => !allow.includes(e)),
|
|
600
|
+
] as JsonValue;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const stripped = MCP_JSON_RELPATHS.has(summary.file)
|
|
605
|
+
? stripMcpTrackerEntries(consumerDoc, templateDoc)
|
|
606
|
+
: stripTier2JsonScope(consumerDoc, templateDoc);
|
|
607
|
+
const strippedJson = JSON.stringify(stripped, null, 2) + "\n";
|
|
608
|
+
if (Object.keys(stripped).length === 0) {
|
|
609
|
+
// All keys were bkit-owned → delete file
|
|
610
|
+
fs.rmSync(absPath, { force: true });
|
|
611
|
+
result.deleted.push(summary.file);
|
|
612
|
+
console.log(
|
|
613
|
+
`${ctx.logPrefix} delete (empty after JSON scope strip): ${summary.file}`,
|
|
614
|
+
);
|
|
615
|
+
} else {
|
|
616
|
+
fs.writeFileSync(absPath, strippedJson, "utf-8");
|
|
617
|
+
result.stripped.push(summary.file);
|
|
618
|
+
console.log(`${ctx.logPrefix} strip-json-scope: ${summary.file}`);
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
// markered-text: strip bkit marker block, preserve consumer content
|
|
622
|
+
const content = fs.readFileSync(absPath, "utf-8");
|
|
623
|
+
const style = detectMarkerStyle(content) ?? "html-comment";
|
|
624
|
+
const stripped = stripManagedBlock(content, style);
|
|
625
|
+
// A bkit-seeded markdown file (AGENTS.md, CLAUDE.md) keeps its `# Title` H1
|
|
626
|
+
// OUTSIDE the bkit block. A markdown file reduced to a lone ATX heading (its only
|
|
627
|
+
// non-blank line) is a husk and is deleted. Scoped to .md/.mdc (shell/gitignore
|
|
628
|
+
// residue such as a lone `# comment` is unaffected); a multi-line residual (e.g.
|
|
629
|
+
// prompts.md's consumer `## Model Overrides`) is preserved.
|
|
630
|
+
const nonBlank = stripped.split("\n").filter((l) => l.trim().length > 0);
|
|
631
|
+
const isMarkdown = /\.mdc?$/.test(summary.file);
|
|
632
|
+
const isLoneHeadingHusk =
|
|
633
|
+
isMarkdown && nonBlank.length === 1 && /^#{1,6}\s+\S/.test(nonBlank[0].trim());
|
|
634
|
+
// A file whose post-strip residual equals the bkit-seeded scaffold OUTSIDE the block
|
|
635
|
+
// (i.e. the template stripped the same way) carries NO genuine consumer content — it is
|
|
636
|
+
// 100% bkit-authored (hook shells left with only a shebang/header, a `.mdc` frontmatter
|
|
637
|
+
// shell, a pristine prompts.md) and is deleted. A consumer who added content outside
|
|
638
|
+
// the block strips UNEQUAL → preserved. Read is covered by the enclosing try/catch.
|
|
639
|
+
const normResidual = (s: string): string =>
|
|
640
|
+
s
|
|
641
|
+
.split("\n")
|
|
642
|
+
.map((l) => l.replace(/[ \t]+$/, ""))
|
|
643
|
+
.join("\n")
|
|
644
|
+
.trim();
|
|
645
|
+
let isBkitOnlyScaffold = false;
|
|
646
|
+
const markeredTemplatePath = findTemplateSource(summary.file);
|
|
647
|
+
if (markeredTemplatePath !== null && fs.existsSync(markeredTemplatePath)) {
|
|
648
|
+
const templateContent = readTemplate(markeredTemplatePath);
|
|
649
|
+
const templateStripped = stripManagedBlock(
|
|
650
|
+
templateContent,
|
|
651
|
+
detectMarkerStyle(templateContent) ?? style,
|
|
652
|
+
);
|
|
653
|
+
isBkitOnlyScaffold = normResidual(stripped) === normResidual(templateStripped);
|
|
654
|
+
}
|
|
655
|
+
if (stripped.trim().length === 0 || isLoneHeadingHusk || isBkitOnlyScaffold) {
|
|
656
|
+
// File is now empty (or a bkit-seeded heading husk) → delete it
|
|
657
|
+
fs.rmSync(absPath, { force: true });
|
|
658
|
+
result.deleted.push(summary.file);
|
|
659
|
+
console.log(`${ctx.logPrefix} delete (empty after strip): ${summary.file}`);
|
|
660
|
+
} else {
|
|
661
|
+
fs.writeFileSync(absPath, stripped, "utf-8");
|
|
662
|
+
result.stripped.push(summary.file);
|
|
663
|
+
console.log(`${ctx.logPrefix} strip-block: ${summary.file}`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
} catch (err) {
|
|
667
|
+
console.error(
|
|
668
|
+
`${ctx.logPrefix} error stripping block from ${summary.file}: ${(err as Error).message}`,
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
} else {
|
|
672
|
+
result.stripped.push(summary.file);
|
|
673
|
+
}
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// Full/core uninstall: strip the `bkit` install-state object from package.json
|
|
680
|
+
// (issueTracker / opencodeProvider(s) / cloudAgents), whatever keys it holds. Scripts
|
|
681
|
+
// and devDeps are the consumer's and stay. No try/catch — malformed package.json is a hard failure on full
|
|
682
|
+
// teardown (same as a missing dest would be).
|
|
683
|
+
if (moduleList.includes("core") && !ctx.dryRun) {
|
|
684
|
+
const pkgPath = path.join(ctx.cwd, "package.json");
|
|
685
|
+
if (fs.existsSync(pkgPath)) {
|
|
686
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record<string, unknown>;
|
|
687
|
+
if (pkg.bkit !== undefined) {
|
|
688
|
+
delete pkg.bkit;
|
|
689
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
|
|
690
|
+
console.log(`${ctx.logPrefix} package.json: removed bkit install-state block`);
|
|
691
|
+
result.stripped.push("package.json#bkit");
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// Clean up .agents/ bkit-prefix mirror files
|
|
697
|
+
// (.claude/commands/bkit-*.md, .claude/agents/bkit-*.md, .opencode/agents/bkit-*.md, etc.)
|
|
698
|
+
if (!ctx.dryRun) {
|
|
699
|
+
const mirrorDirs = [
|
|
700
|
+
// Each host's mirror dirs are gated on its own module so a targeted
|
|
701
|
+
// uninstall (e.g. --claude / --auto) leaves other hosts
|
|
702
|
+
// untouched — symmetric with install. A bare/full uninstall populates
|
|
703
|
+
// moduleList with every host, so all mirrors are still swept then.
|
|
704
|
+
...(moduleList.includes("claude") ? [".claude/commands", ".claude/agents"] : []),
|
|
705
|
+
...(moduleList.includes("cursor") ? [".cursor/commands", ".cursor/agents"] : []),
|
|
706
|
+
// opencode mirrors (plural dir names per opencode.ai/docs)
|
|
707
|
+
...(moduleList.includes("opencode") ? [".opencode/agents", ".opencode/commands"] : []),
|
|
708
|
+
// codex agent mirrors. The workflow skills under `.agents/skills/bkit-*` are swept
|
|
709
|
+
// separately below: `.agents/skills/` is SHARED with third-party skills installed via
|
|
710
|
+
// skills.sh, so the directory itself must never be removed wholesale.
|
|
711
|
+
...(moduleList.includes("codex") ? [".codex/agents"] : []),
|
|
712
|
+
];
|
|
713
|
+
for (const dir of mirrorDirs) {
|
|
714
|
+
const absDir = path.join(ctx.cwd, dir);
|
|
715
|
+
if (!fs.existsSync(absDir)) continue;
|
|
716
|
+
try {
|
|
717
|
+
for (const f of fs.readdirSync(absDir)) {
|
|
718
|
+
// .toml as well as .md: codex agent mirrors are TOML.
|
|
719
|
+
if (!f.startsWith("bkit-") || !(f.endsWith(".md") || f.endsWith(".toml"))) continue;
|
|
720
|
+
const absFile = path.join(absDir, f);
|
|
721
|
+
fs.rmSync(absFile, { force: true });
|
|
722
|
+
result.deleted.push(path.join(dir, f));
|
|
723
|
+
console.log(`${ctx.logPrefix} delete mirror: ${path.join(dir, f)}`);
|
|
724
|
+
}
|
|
725
|
+
} catch (err) {
|
|
726
|
+
console.error(`${ctx.logPrefix} error cleaning up ${dir}: ${(err as Error).message}`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Workflow skills: `.agents/skills/` is SHARED with third-party skills installed via
|
|
731
|
+
// skills.sh, so only the bkit-prefixed DIRECTORIES are removed — never the parent.
|
|
732
|
+
if (moduleList.includes("codex")) {
|
|
733
|
+
const skillsDir = path.join(ctx.cwd, ".agents", "skills");
|
|
734
|
+
if (fs.existsSync(skillsDir)) {
|
|
735
|
+
try {
|
|
736
|
+
for (const d of fs.readdirSync(skillsDir)) {
|
|
737
|
+
if (!d.startsWith("bkit-")) continue;
|
|
738
|
+
const abs = path.join(skillsDir, d);
|
|
739
|
+
if (!fs.statSync(abs).isDirectory()) continue;
|
|
740
|
+
fs.rmSync(abs, { recursive: true, force: true });
|
|
741
|
+
result.deleted.push(path.join(".agents/skills", d));
|
|
742
|
+
console.log(`${ctx.logPrefix} delete mirror: ${path.join(".agents/skills", d)}`);
|
|
743
|
+
}
|
|
744
|
+
} catch (err) {
|
|
745
|
+
const msg = (err as Error).message;
|
|
746
|
+
console.error(`${ctx.logPrefix} error cleaning up .agents/skills: ${msg}`);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// Remove the generated `.claude/bkit-cloud.md` (untracked, gitignored — holds resolved
|
|
753
|
+
// secrets). It is not in the manifest, so the table-driven pass never sees it;
|
|
754
|
+
// delete it explicitly when the claude host is uninstalled so a live-secrets file
|
|
755
|
+
// is never left behind. Pushed to result.deleted so a dry-run reports it too.
|
|
756
|
+
if (moduleList.includes("claude")) {
|
|
757
|
+
const cloudAbs = path.join(ctx.cwd, CLAUDE_CLOUD_RELPATH);
|
|
758
|
+
if (fs.existsSync(cloudAbs)) {
|
|
759
|
+
result.deleted.push(CLAUDE_CLOUD_RELPATH);
|
|
760
|
+
if (!ctx.dryRun) {
|
|
761
|
+
fs.rmSync(cloudAbs, { force: true });
|
|
762
|
+
console.log(`${ctx.logPrefix} delete: ${CLAUDE_CLOUD_RELPATH} (generated cloud setup doc)`);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Same for the Cursor twin `.cursor/bkit-cloud.md` (writeCursorCloudDoc) — untracked,
|
|
768
|
+
// gitignored, holds resolved secrets; delete it explicitly when the cursor host is
|
|
769
|
+
// uninstalled so a live-secrets file is never left behind.
|
|
770
|
+
if (moduleList.includes("cursor")) {
|
|
771
|
+
const cloudAbs = path.join(ctx.cwd, CURSOR_CLOUD_RELPATH);
|
|
772
|
+
if (fs.existsSync(cloudAbs)) {
|
|
773
|
+
result.deleted.push(CURSOR_CLOUD_RELPATH);
|
|
774
|
+
if (!ctx.dryRun) {
|
|
775
|
+
fs.rmSync(cloudAbs, { force: true });
|
|
776
|
+
console.log(`${ctx.logPrefix} delete: ${CURSOR_CLOUD_RELPATH} (generated cloud setup doc)`);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// Full/core uninstall: the consumer's template copies (`.bkit/templates/`) are
|
|
782
|
+
// bkit's folder, refreshed whole on every install and upgrade, so they go whole.
|
|
783
|
+
// Never in dogfood, where that folder is bkit's own template source. Adopted copies
|
|
784
|
+
// elsewhere in the repo stay.
|
|
785
|
+
if (moduleList.includes("core")) {
|
|
786
|
+
const templatesDir = path.join(ctx.cwd, TEMPLATE_COPIES_DIR);
|
|
787
|
+
if (path.resolve(ctx.cwd) !== getPkgRoot() && fs.existsSync(templatesDir)) {
|
|
788
|
+
result.deleted.push(TEMPLATE_COPIES_DIR);
|
|
789
|
+
if (!ctx.dryRun) {
|
|
790
|
+
fs.rmSync(templatesDir, { recursive: true, force: true });
|
|
791
|
+
console.log(`${ctx.logPrefix} delete: ${TEMPLATE_COPIES_DIR}/`);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// Prune bkit-authored dirs left empty by the deletions above (e.g. .claude/agents,
|
|
797
|
+
// .claude/hooks). Candidates are the parent
|
|
798
|
+
// dirs of everything deleted, plus their ancestors; each is removed ONLY when it is actually
|
|
799
|
+
// empty (never touches a dir still holding consumer files), deepest-first so the removal
|
|
800
|
+
// cascades up. Skipped in dry-run — nothing was deleted, so nothing is empty to report.
|
|
801
|
+
if (!ctx.dryRun) {
|
|
802
|
+
const dirCandidates = new Set<string>();
|
|
803
|
+
for (const rel of result.deleted) {
|
|
804
|
+
let dir = path.dirname(rel);
|
|
805
|
+
while (dir && dir !== "." && dir !== path.sep) {
|
|
806
|
+
dirCandidates.add(dir);
|
|
807
|
+
dir = path.dirname(dir);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
const byDepthDesc = [...dirCandidates].sort(
|
|
811
|
+
(a, b) => b.split(path.sep).length - a.split(path.sep).length,
|
|
812
|
+
);
|
|
813
|
+
for (const rel of byDepthDesc) {
|
|
814
|
+
const absDir = path.join(ctx.cwd, rel);
|
|
815
|
+
// rmdirSync removes ONLY an empty dir (throws on non-empty) — the emptiness check
|
|
816
|
+
// above makes it a no-op on any dir still holding consumer files. Single-threaded, so
|
|
817
|
+
// the check and the remove cannot race.
|
|
818
|
+
if (fs.existsSync(absDir) && fs.readdirSync(absDir).length === 0) {
|
|
819
|
+
fs.rmdirSync(absDir);
|
|
820
|
+
console.log(`${ctx.logPrefix} prune empty dir: ${rel}`);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return result;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// ---------------------------------------------------------------------------
|
|
829
|
+
// runSurgicalOpencodeUninstall — remove exactly ONE provider block
|
|
830
|
+
// ---------------------------------------------------------------------------
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Surgical removal of a single opencode provider installed by bkit.
|
|
834
|
+
*
|
|
835
|
+
* Distinct from bare `bkit uninstall --opencode` (full host teardown):
|
|
836
|
+
* - Removes the provider block from `.opencode/opencode.json`
|
|
837
|
+
* - Updates `bkit.opencodeProviders` in `package.json`
|
|
838
|
+
* - If the removed provider was the active one, re-points `bkit.opencodeProvider`
|
|
839
|
+
* to the first remaining provider and emits a re-render advisory
|
|
840
|
+
* - If no providers remain, falls through to full host teardown via `runUninstall`
|
|
841
|
+
*/
|
|
842
|
+
export async function runSurgicalOpencodeUninstall(
|
|
843
|
+
providerKey: string,
|
|
844
|
+
dryRun: boolean,
|
|
845
|
+
cwd: string,
|
|
846
|
+
): Promise<void> {
|
|
847
|
+
const LOG_PREFIX = "[bkit-uninstall]";
|
|
848
|
+
const tag = dryRun ? " (dry-run)" : "";
|
|
849
|
+
const jsonDst = path.join(cwd, ".opencode", "opencode.json");
|
|
850
|
+
const ws: WriteSet = { writes: [] };
|
|
851
|
+
|
|
852
|
+
// 1. Remove provider block from opencode.json
|
|
853
|
+
removeOpencodeProviderBlock(jsonDst, providerKey, dryRun, ws);
|
|
854
|
+
if (ws.writes.length > 0) {
|
|
855
|
+
console.log(`${LOG_PREFIX}${tag} removed provider block "${providerKey}" from opencode.json`);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// 2. Update bkit.opencodeProviders in package.json (read inline — no detectOpencodeProviders import)
|
|
859
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
860
|
+
let remainingProviders: string[] = [];
|
|
861
|
+
let wasActive = false;
|
|
862
|
+
let newActive: string | null = null;
|
|
863
|
+
|
|
864
|
+
if (fs.existsSync(pkgPath)) {
|
|
865
|
+
const raw = fs.readFileSync(pkgPath, "utf-8");
|
|
866
|
+
// Parse-or-sentinel idiom: keep the early-return outside the catch body.
|
|
867
|
+
let pkg: Record<string, unknown> | null = null;
|
|
868
|
+
try {
|
|
869
|
+
pkg = JSON.parse(raw) as Record<string, unknown>;
|
|
870
|
+
} catch {
|
|
871
|
+
pkg = null;
|
|
872
|
+
}
|
|
873
|
+
if (pkg === null) {
|
|
874
|
+
console.warn(`${LOG_PREFIX} package.json is malformed — skipping bkit section update`);
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
const bkit = (pkg.bkit ?? {}) as Record<string, unknown>;
|
|
878
|
+
const arr = Array.isArray(bkit.opencodeProviders)
|
|
879
|
+
? [...(bkit.opencodeProviders as string[])]
|
|
880
|
+
: [];
|
|
881
|
+
remainingProviders = arr.filter((p) => p !== providerKey);
|
|
882
|
+
wasActive = bkit.opencodeProvider === providerKey;
|
|
883
|
+
if (wasActive && remainingProviders.length > 0) {
|
|
884
|
+
newActive = remainingProviders[0]!;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
if (!dryRun) {
|
|
888
|
+
bkit.opencodeProviders = remainingProviders;
|
|
889
|
+
if (wasActive) {
|
|
890
|
+
if (newActive !== null) {
|
|
891
|
+
bkit.opencodeProvider = newActive;
|
|
892
|
+
} else {
|
|
893
|
+
delete bkit.opencodeProvider;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
pkg.bkit = bkit;
|
|
897
|
+
const indentMatch = raw.match(/\n([ \t]+)"/);
|
|
898
|
+
const indent = indentMatch ? indentMatch[1] : " ";
|
|
899
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + "\n", "utf-8");
|
|
900
|
+
console.log(
|
|
901
|
+
`${LOG_PREFIX} updated package.json: opencodeProviders=[${remainingProviders.join(", ")}]` +
|
|
902
|
+
(wasActive ? ` opencodeProvider=${newActive ?? "(removed)"}` : ""),
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// 3. If none remain → full host teardown
|
|
908
|
+
if (remainingProviders.length === 0) {
|
|
909
|
+
console.log(
|
|
910
|
+
`${LOG_PREFIX}${tag} no providers remain — triggering full opencode host teardown...`,
|
|
911
|
+
);
|
|
912
|
+
await runUninstall(["opencode"], {
|
|
913
|
+
cwd,
|
|
914
|
+
dryRun,
|
|
915
|
+
force: false,
|
|
916
|
+
nuke: false,
|
|
917
|
+
yes: false,
|
|
918
|
+
logPrefix: LOG_PREFIX,
|
|
919
|
+
});
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// 4. If was active → emit advisory (re-rendering agents requires full ModuleContext)
|
|
924
|
+
if (wasActive && newActive !== null) {
|
|
925
|
+
console.log(
|
|
926
|
+
`${LOG_PREFIX}${tag} active provider switched to "${newActive}". ` +
|
|
927
|
+
`Run \`bkit install --opencode=${newActive}\` or \`bkit upgrade\` to re-render agent frontmatter.`,
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
export async function runUninstallCommand(
|
|
933
|
+
modules: Set<ModuleFlag>,
|
|
934
|
+
opencodeProvider: string | null,
|
|
935
|
+
uninstallFlags: UninstallFlags,
|
|
936
|
+
): Promise<void> {
|
|
937
|
+
setLogPrefix("[bkit-uninstall]");
|
|
938
|
+
|
|
939
|
+
// Surgical single-provider removal: `uninstall --opencode=<provider>`
|
|
940
|
+
if (modules.has("opencode") && opencodeProvider !== null) {
|
|
941
|
+
const tag = uninstallFlags.dryRun ? " (dry-run)" : "";
|
|
942
|
+
console.log(
|
|
943
|
+
`${LOG_PREFIX} Surgical opencode uninstall: removing provider "${opencodeProvider}"${tag}...`,
|
|
944
|
+
);
|
|
945
|
+
await runSurgicalOpencodeUninstall(opencodeProvider, uninstallFlags.dryRun, process.cwd());
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const uninstallCtx: UninstallContext = {
|
|
950
|
+
cwd: process.cwd(),
|
|
951
|
+
dryRun: uninstallFlags.dryRun,
|
|
952
|
+
force: uninstallFlags.force,
|
|
953
|
+
nuke: uninstallFlags.nuke,
|
|
954
|
+
yes: uninstallFlags.yes,
|
|
955
|
+
logPrefix: LOG_PREFIX,
|
|
956
|
+
};
|
|
957
|
+
const moduleList = [...modules] as ModuleName[];
|
|
958
|
+
console.log(`${LOG_PREFIX} Running uninstall${uninstallCtx.dryRun ? " (dry-run)" : ""}...`);
|
|
959
|
+
const result = await runUninstall(moduleList, uninstallCtx);
|
|
960
|
+
const totalDeleted = result.deleted.length;
|
|
961
|
+
const totalStripped = result.stripped.length;
|
|
962
|
+
const totalPreserved = result.preserved.length;
|
|
963
|
+
if (uninstallCtx.dryRun) {
|
|
964
|
+
console.log(
|
|
965
|
+
`${LOG_PREFIX} [dry-run] Would delete: ${totalDeleted}, strip: ${totalStripped}, preserve: ${totalPreserved}`,
|
|
966
|
+
);
|
|
967
|
+
} else {
|
|
968
|
+
console.log(
|
|
969
|
+
`${LOG_PREFIX} Done. Deleted: ${totalDeleted}, stripped: ${totalStripped}, preserved: ${totalPreserved}`,
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
}
|