@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,504 @@
|
|
|
1
|
+
// install/modules/opencode.ts — the opencode host module: `.opencode/` agents and commands, and
|
|
2
|
+
// the provider-templated `opencode.json`.
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { writeTier2, deepMergeJson, ensureDir } from "../write.js";
|
|
6
|
+
import { stampManagedVersion } from "../version-file.js";
|
|
7
|
+
import { applyOpencodeAgent, applyOpencodeCommand } from "../../render/hosts.js";
|
|
8
|
+
import { getCoreRoot, getSharedRoot, getWorkflowsRoot, getPromptsRoot, } from "../../shared/package-roots.js";
|
|
9
|
+
import { DEFAULT_ISSUE_TRACKER } from "../manifest.js";
|
|
10
|
+
import { substituteWorkflow } from "../../render/trackers.js";
|
|
11
|
+
import { resolveNetworkAllowlist, extractMcpServers, networkAllowlistBases } from "../cloud-env.js";
|
|
12
|
+
import { OPENCODE_PROVIDER_DEFAULTS } from "../../shared/egress.js";
|
|
13
|
+
import { BKIT_PREFIX, installFile, listMdFiles, readInstallingVersion, trackMirrorWrite, } from "./core.js";
|
|
14
|
+
import { opencodeProviderId } from "../../render/models.js";
|
|
15
|
+
export function renderOpencodeAgentsCommands(ctx) {
|
|
16
|
+
const { dryRun, opencodeModelLookup, effortMap, opencodeProvider, logPrefix } = ctx;
|
|
17
|
+
const tag = dryRun ? "[dry-run] " : "";
|
|
18
|
+
const issueTracker = ctx.issueTracker ?? DEFAULT_ISSUE_TRACKER;
|
|
19
|
+
const version = ctx.version ?? readInstallingVersion();
|
|
20
|
+
const written = [];
|
|
21
|
+
// The opencode host cannot render without a provider — `--opencode=<provider>` is
|
|
22
|
+
// unary at the CLI; an absent value here throws.
|
|
23
|
+
if (!opencodeProvider) {
|
|
24
|
+
throw new Error("renderOpencodeAgentsCommands: ctx.opencodeProvider is required");
|
|
25
|
+
}
|
|
26
|
+
const provider = opencodeProvider;
|
|
27
|
+
// --- Agents: tracker substitution → applyOpencodeAgent → managed-version stamp (last) ---
|
|
28
|
+
{
|
|
29
|
+
const src = getPromptsRoot();
|
|
30
|
+
const dest = ".opencode/agents";
|
|
31
|
+
// dryRun-gated so `bkit check` stays read-only — installFile/removeOrphans below are
|
|
32
|
+
// already dryRun-guarded, so the dir is only needed for a real write.
|
|
33
|
+
if (!dryRun)
|
|
34
|
+
ensureDir(dest);
|
|
35
|
+
const files = listMdFiles(src, BKIT_PREFIX);
|
|
36
|
+
const sourceSet = new Set(files);
|
|
37
|
+
for (const f of files) {
|
|
38
|
+
const transform = (c) => stampManagedVersion(applyOpencodeAgent(substituteWorkflow(c, issueTracker).output, opencodeModelLookup, effortMap, provider), version);
|
|
39
|
+
if (installFile(path.join(src, f), path.join(dest, f), transform, dryRun)) {
|
|
40
|
+
const rel = path.join(dest, f);
|
|
41
|
+
console.log(`${logPrefix} ${tag}write: ${rel}`);
|
|
42
|
+
trackMirrorWrite(ctx, rel, written);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Remove orphan agent files (bkit-prefix only, no allowlist gate needed — .opencode/agents
|
|
46
|
+
// is a dynamic mirror dir like .claude/agents and .cursor/agents). dryRun still reports
|
|
47
|
+
// would-deletes into ws.writes so `bkit check` fails on stale mirrors.
|
|
48
|
+
if (fs.existsSync(dest)) {
|
|
49
|
+
for (const f of fs.readdirSync(dest)) {
|
|
50
|
+
if (!f.endsWith(".md"))
|
|
51
|
+
continue;
|
|
52
|
+
if (!f.startsWith(BKIT_PREFIX))
|
|
53
|
+
continue;
|
|
54
|
+
if (!sourceSet.has(f)) {
|
|
55
|
+
const rel = path.join(dest, f);
|
|
56
|
+
if (!dryRun)
|
|
57
|
+
fs.rmSync(path.join(dest, f));
|
|
58
|
+
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
59
|
+
trackMirrorWrite(ctx, rel, written);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// --- Commands: tracker substitution + applyOpencodeCommand ---
|
|
65
|
+
{
|
|
66
|
+
const src = getWorkflowsRoot();
|
|
67
|
+
const dest = ".opencode/commands";
|
|
68
|
+
// dryRun-gated (see .opencode/agents above) — `bkit check` stays read-only.
|
|
69
|
+
if (!dryRun)
|
|
70
|
+
ensureDir(dest);
|
|
71
|
+
const files = listMdFiles(src, BKIT_PREFIX);
|
|
72
|
+
const sourceSet = new Set(files);
|
|
73
|
+
for (const f of files) {
|
|
74
|
+
const transform = (c) => stampManagedVersion(applyOpencodeCommand(substituteWorkflow(c, issueTracker).output), version);
|
|
75
|
+
if (installFile(path.join(src, f), path.join(dest, f), transform, dryRun)) {
|
|
76
|
+
const rel = path.join(dest, f);
|
|
77
|
+
console.log(`${logPrefix} ${tag}write: ${rel}`);
|
|
78
|
+
trackMirrorWrite(ctx, rel, written);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (fs.existsSync(dest)) {
|
|
82
|
+
for (const f of fs.readdirSync(dest)) {
|
|
83
|
+
if (!f.endsWith(".md"))
|
|
84
|
+
continue;
|
|
85
|
+
if (!f.startsWith(BKIT_PREFIX))
|
|
86
|
+
continue;
|
|
87
|
+
if (!sourceSet.has(f)) {
|
|
88
|
+
const rel = path.join(dest, f);
|
|
89
|
+
if (!dryRun)
|
|
90
|
+
fs.rmSync(path.join(dest, f));
|
|
91
|
+
console.log(`${logPrefix} ${tag}delete orphan: ${rel}`);
|
|
92
|
+
trackMirrorWrite(ctx, rel, written);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return written;
|
|
98
|
+
}
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// runOpencodeModule — opencode provider-agnostic host (opt-in via --opencode=<provider>)
|
|
101
|
+
//
|
|
102
|
+
// Additive alongside always-on claude/cursor: .opencode/agents/*.md (via applyOpencodeAgent),
|
|
103
|
+
// .opencode/commands/*.md (via applyOpencodeCommand + tracker substitution),
|
|
104
|
+
// .opencode/opencode.json (Tier-2 deep-contained), .opencode/plugin/bkit-gateguard.js (Tier-1).
|
|
105
|
+
//
|
|
106
|
+
// Dir names: .opencode/agents/ and .opencode/commands/ (plural) per opencode.ai/docs.
|
|
107
|
+
// Spike initially observed singular; official docs are plural — plural is correct.
|
|
108
|
+
// .opencode/plugin/ (singular, not plugins/)
|
|
109
|
+
//
|
|
110
|
+
// Provider config is seeded into opencode.json; consumers tune model IDs and provider
|
|
111
|
+
// keys after install. opencode.json is Tier-2 deep-contained (ownership-mixed) so bkit
|
|
112
|
+
// reconverges its keys on upgrade without clobbering consumer additions (KN-17).
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* The provider secret env var name for a bkit provider key (`BKIT_OPENROUTER_API_KEY`,
|
|
116
|
+
* `BKIT_OPENCODE_API_KEY`, ...). Empty string for an unknown key. Mirrors
|
|
117
|
+
* {@link opencodeProviderId}; used to compare a self-installed opencode.yml handler's `env:`
|
|
118
|
+
* secret against the installed provider.
|
|
119
|
+
*/
|
|
120
|
+
export function opencodeProviderEnvVar(providerKey) {
|
|
121
|
+
return OPENCODE_PROVIDER_DEFAULTS[providerKey]?.envVar ?? "";
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Detect drift between the self-installed `.github/workflows/opencode.yml` reactive `/oc` handler
|
|
125
|
+
* and the installed opencode provider.
|
|
126
|
+
*
|
|
127
|
+
* opencode.yml is NOT bkit-managed: it is self-installed via `opencode github install` (the `/oc`
|
|
128
|
+
* | `/opencode` comment handler — the opencode analogue of the App-generated claude.yml). It
|
|
129
|
+
* HARDCODES two provider-specific values: a `model: <providerId>/<model>` line and a provider
|
|
130
|
+
* secret `env:` var. `bkit install --opencode=<provider>` rewrites neither; this advisory names
|
|
131
|
+
* the hand-edit.
|
|
132
|
+
*
|
|
133
|
+
* bkit-cloud.yml runs `opencode run` against the committed `.opencode/` config and fans one
|
|
134
|
+
* `OPENCODE_PROVIDER_KEY` secret out to every provider env var, so it is not checked.
|
|
135
|
+
*
|
|
136
|
+
* No-op when opencode.yml is absent. No equivalent check for claude.yml (provider-fixed to
|
|
137
|
+
* Claude). Severity "advisory": never gates `bkit check`; surfaces on both check and postinstall.
|
|
138
|
+
*/
|
|
139
|
+
export function detectOpencodeYmlProviderDrift(cwd) {
|
|
140
|
+
const ymlPath = path.join(cwd, ".github", "workflows", "opencode.yml");
|
|
141
|
+
if (!fs.existsSync(ymlPath))
|
|
142
|
+
return null;
|
|
143
|
+
// The installed provider — package.json `bkit.opencodeProvider` is the authoritative record
|
|
144
|
+
// written on install. Absent/broken → the null-guard below skips silently.
|
|
145
|
+
let provider = null;
|
|
146
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
147
|
+
if (fs.existsSync(pkgPath)) {
|
|
148
|
+
try {
|
|
149
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
150
|
+
if (typeof pkg.bkit?.opencodeProvider === "string")
|
|
151
|
+
provider = pkg.bkit.opencodeProvider;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Malformed package.json — leave provider null; a JSON-drift advisory covers that separately.
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!provider)
|
|
158
|
+
return null;
|
|
159
|
+
const expectedPrefix = opencodeProviderId(provider); // model id form is `<providerId>/<model>`
|
|
160
|
+
const expectedEnvVar = opencodeProviderEnvVar(provider);
|
|
161
|
+
if (!expectedEnvVar)
|
|
162
|
+
return null; // unknown provider key — no registry entry to compare against.
|
|
163
|
+
const content = fs.readFileSync(ymlPath, "utf-8");
|
|
164
|
+
// The handler's hardcoded `model: <providerId>/<model>` line (opencode `run --model`).
|
|
165
|
+
const ymlModel = content.match(/^\s*model:\s*(\S+)/m)?.[1] ?? null;
|
|
166
|
+
const ymlPrefix = ymlModel ? ymlModel.split("/")[0] : null;
|
|
167
|
+
// The handler's hardcoded provider secret — an `env:` key like BKIT_OPENROUTER_API_KEY / BKIT_OPENCODE_API_KEY.
|
|
168
|
+
const ymlEnvVar = content.match(/^\s*([A-Z][A-Z0-9_]*(?:_API_KEY|_HOST)):/m)?.[1] ?? null;
|
|
169
|
+
// Two independent drift signals. The model prefix is the precise one (it distinguishes the two
|
|
170
|
+
// opencode gateways that share BKIT_OPENCODE_API_KEY); the env var catches a wrong/absent secret.
|
|
171
|
+
const modelDrift = ymlPrefix !== null && ymlPrefix !== expectedPrefix;
|
|
172
|
+
const envDrift = !new RegExp(`\\b${expectedEnvVar}\\b`).test(content);
|
|
173
|
+
if (!modelDrift && !envDrift)
|
|
174
|
+
return null;
|
|
175
|
+
const foundModel = ymlModel ?? "(none)";
|
|
176
|
+
const foundEnvVar = ymlEnvVar ?? "(none)";
|
|
177
|
+
return {
|
|
178
|
+
id: "opencode-yml-provider-drift",
|
|
179
|
+
severity: "advisory",
|
|
180
|
+
detect: ".github/workflows/opencode.yml (the self-installed /oc handler, NOT bkit-managed) is pinned to model `" +
|
|
181
|
+
foundModel +
|
|
182
|
+
"` with secret `" +
|
|
183
|
+
foundEnvVar +
|
|
184
|
+
"`, but the installed opencode provider is `" +
|
|
185
|
+
provider +
|
|
186
|
+
"` (model ids `" +
|
|
187
|
+
expectedPrefix +
|
|
188
|
+
"/<model>`, secret `" +
|
|
189
|
+
expectedEnvVar +
|
|
190
|
+
"`). The reactive handler will call the wrong provider's model and/or authenticate with the wrong (likely-unset) secret. bkit install does not rewrite this file.",
|
|
191
|
+
action: "opencode.yml is self-installed via `opencode github install` and is NOT bkit-managed, so `bkit install --opencode=<provider>` will not fix it. Hand-edit the two hardcoded lines to match the installed provider:\n\n" +
|
|
192
|
+
" env:\n" +
|
|
193
|
+
" " +
|
|
194
|
+
expectedEnvVar +
|
|
195
|
+
": ${{ secrets." +
|
|
196
|
+
expectedEnvVar +
|
|
197
|
+
" }}\n" +
|
|
198
|
+
" with:\n" +
|
|
199
|
+
" model: " +
|
|
200
|
+
expectedPrefix +
|
|
201
|
+
"/<model> # a model your provider serves (see .opencode/opencode.json)\n\n" +
|
|
202
|
+
"Keep opencode.yml in sync with .opencode/opencode.json on every provider switch. (bkit-cloud.yml needs no such edit: it reads .opencode/ and fans OPENCODE_PROVIDER_KEY out to every provider env var.)",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
// Sentinel values used in the opencode.json template for tracker-filtered mcp injection.
|
|
206
|
+
const OPENCODE_TRACKER_MCP_SENTINEL = '"@@OPENCODE_TRACKER_MCP@@": {}';
|
|
207
|
+
const OPENCODE_PROVIDER_KEY_SENTINEL = "@@OPENCODE_PROVIDER_KEY@@";
|
|
208
|
+
const OPENCODE_PROVIDER_ENV_VAR_SENTINEL = "@@OPENCODE_PROVIDER_ENV_VAR@@";
|
|
209
|
+
const OPENCODE_PROVIDER_BASE_URL_SENTINEL = "@@OPENCODE_PROVIDER_BASE_URL@@";
|
|
210
|
+
/**
|
|
211
|
+
* Render the opencode.json template with tracker-filtered mcp + provider config.
|
|
212
|
+
* Resolves the @@OPENCODE_TRACKER_MCP@@ sentinel into the correct mcpServers entry
|
|
213
|
+
* and fills in provider-specific fields.
|
|
214
|
+
*
|
|
215
|
+
* Also injects `curl *{domain}*` / `wget *{domain}*` **allow** rules (after the
|
|
216
|
+
* template's `curl *` / `wget *` ask) for {@link resolveNetworkAllowlist} so
|
|
217
|
+
* context-fetch / provider hosts do not prompt (OpenCode bash is last-match-wins), and
|
|
218
|
+
* `<server>_*` allows for the consumer's `mcp-servers` block.
|
|
219
|
+
*/
|
|
220
|
+
export function renderOpencodeJson(templatePath, tracker, provider, cwd = process.cwd()) {
|
|
221
|
+
const raw = fs.readFileSync(templatePath, "utf-8");
|
|
222
|
+
// Strict allowlist: provider is gated to OPENCODE_PROVIDERS at the CLI, so it is always
|
|
223
|
+
// a known key here. An unknown id throws; no substitute provider.
|
|
224
|
+
const providerDefaults = OPENCODE_PROVIDER_DEFAULTS[provider];
|
|
225
|
+
if (!providerDefaults) {
|
|
226
|
+
throw new Error(`renderOpencodeJson: unknown opencode provider ${JSON.stringify(provider)}`);
|
|
227
|
+
}
|
|
228
|
+
// Resolve tracker MCP entry
|
|
229
|
+
// opencode's MCP schema differs from Claude/Cursor: remote servers use type "remote"
|
|
230
|
+
// (NOT "http" — not in opencode's enum, which makes the whole config invalid) and read
|
|
231
|
+
// secrets via {env:VAR} (NOT shell ${VAR}). See https://opencode.ai/config.json.
|
|
232
|
+
let mcpEntry;
|
|
233
|
+
if (tracker === "github") {
|
|
234
|
+
mcpEntry =
|
|
235
|
+
'"github": { "type": "remote", "url": "https://api.githubcopilot.com/mcp/", "headers": { "Authorization": "Bearer {env:BKIT_GH_TOKEN}", "X-MCP-Toolsets": "context,issues,pull_requests,repos,users,projects" } }';
|
|
236
|
+
}
|
|
237
|
+
else if (tracker === "linear") {
|
|
238
|
+
mcpEntry = '"linear": { "type": "remote", "url": "https://mcp.linear.app/mcp" }';
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
mcpEntry = "";
|
|
242
|
+
}
|
|
243
|
+
let rendered = raw.replace(OPENCODE_TRACKER_MCP_SENTINEL, mcpEntry);
|
|
244
|
+
rendered = rendered.replace(OPENCODE_PROVIDER_KEY_SENTINEL, provider);
|
|
245
|
+
rendered = rendered.replace(OPENCODE_PROVIDER_ENV_VAR_SENTINEL, providerDefaults.envVar);
|
|
246
|
+
rendered = rendered.replace(OPENCODE_PROVIDER_BASE_URL_SENTINEL, providerDefaults.baseURL);
|
|
247
|
+
// Parse + re-serialize to normalise JSON (removes empty mcp entry if tracker=none)
|
|
248
|
+
try {
|
|
249
|
+
const parsed = JSON.parse(rendered);
|
|
250
|
+
// Clean up empty mcp object when tracker=none
|
|
251
|
+
const mcp = parsed.mcp;
|
|
252
|
+
if (mcp && Object.keys(mcp).length === 0) {
|
|
253
|
+
delete parsed.mcp;
|
|
254
|
+
}
|
|
255
|
+
// Built-in opencode gateways (Zen/Go): opencode resolves the provider from models.dev,
|
|
256
|
+
// so there is no npm driver and no baseURL — emit a minimal block keyed by the
|
|
257
|
+
// opencode-side provider id carrying only the apiKey ({env:BKIT_OPENCODE_API_KEY}).
|
|
258
|
+
if (providerDefaults.builtin) {
|
|
259
|
+
const pid = providerDefaults.providerId ?? provider;
|
|
260
|
+
const options = { apiKey: providerDefaults.apiPlaceholder };
|
|
261
|
+
parsed.provider = { [pid]: { options } };
|
|
262
|
+
injectOpencodeDerivedAllows(parsed, cwd);
|
|
263
|
+
return JSON.stringify(parsed, null, 2) + "\n";
|
|
264
|
+
}
|
|
265
|
+
// For npm-based custom providers (e.g. openrouter), replace the api-openai provider
|
|
266
|
+
// block with the npm-driver format: { npm, name, options: { baseURL, apiKey } }
|
|
267
|
+
if (providerDefaults.npmPackage) {
|
|
268
|
+
// Every custom provider carries an apiKey as {env:VAR}. opencode rejects an unknown
|
|
269
|
+
// "api" field, so the block is rebuilt to the npm-driver shape only.
|
|
270
|
+
const options = {
|
|
271
|
+
baseURL: providerDefaults.baseURL,
|
|
272
|
+
apiKey: providerDefaults.apiPlaceholder,
|
|
273
|
+
};
|
|
274
|
+
parsed.provider = {
|
|
275
|
+
[provider]: {
|
|
276
|
+
npm: providerDefaults.npmPackage,
|
|
277
|
+
name: providerDefaults.displayName ?? provider,
|
|
278
|
+
options,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
injectOpencodeDerivedAllows(parsed, cwd);
|
|
283
|
+
return JSON.stringify(parsed, null, 2) + "\n";
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
return rendered;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Append curl/wget domain allows after template ask rules (OpenCode last-match-wins),
|
|
291
|
+
* and one `<server>_*` allow per declared MCP server — opencode names MCP tools
|
|
292
|
+
* `<server>_<tool>` and matches permission keys as globs against the tool name.
|
|
293
|
+
*/
|
|
294
|
+
function injectOpencodeDerivedAllows(parsed, cwd) {
|
|
295
|
+
const permission = parsed.permission;
|
|
296
|
+
if (!permission)
|
|
297
|
+
return;
|
|
298
|
+
for (const server of extractMcpServers(cwd)) {
|
|
299
|
+
permission[`${server}_*`] = "allow";
|
|
300
|
+
}
|
|
301
|
+
if (typeof permission.bash !== "object" || permission.bash === null)
|
|
302
|
+
return;
|
|
303
|
+
const bash = permission.bash;
|
|
304
|
+
for (const base of networkAllowlistBases(resolveNetworkAllowlist(cwd))) {
|
|
305
|
+
bash[`curl *${base}*`] = "allow";
|
|
306
|
+
bash[`wget *${base}*`] = "allow";
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Reconcile a consumer's `.opencode/opencode.json` against the freshly-rendered template.
|
|
311
|
+
* Install is additive across provider keys: existing blocks for other providers
|
|
312
|
+
* (bkit-seeded or consumer-added) are preserved. For each provider key present in the
|
|
313
|
+
* template, the block is REPLACED (not deep-merged), so a hijacked npm/baseURL does not
|
|
314
|
+
* survive reinstall.
|
|
315
|
+
*
|
|
316
|
+
* To remove a stale bkit provider block (e.g. after switching providers), use the surgical
|
|
317
|
+
* `removeOpencodeProviderBlock` below — called by the uninstall path, not install.
|
|
318
|
+
*
|
|
319
|
+
* Mirrors writeTier2JsonContained's contract (first-install write, idempotent no-op via
|
|
320
|
+
* final equality, else merge), so dry-run and real runs compute the identical writeset.
|
|
321
|
+
*/
|
|
322
|
+
export function reconcileOpencodeJson(renderedTemplate, relDst, dryRun, ws) {
|
|
323
|
+
const template = JSON.parse(renderedTemplate);
|
|
324
|
+
if (!fs.existsSync(relDst)) {
|
|
325
|
+
// First install — write template as-is.
|
|
326
|
+
if (!dryRun) {
|
|
327
|
+
ensureDir(path.dirname(relDst));
|
|
328
|
+
fs.writeFileSync(relDst, JSON.stringify(template, null, 2) + "\n", "utf-8");
|
|
329
|
+
}
|
|
330
|
+
ws.writes.push({ path: relDst, action: "write" });
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
// Parse into a sentinel and validate AFTER the catch — keeping the throw out of the catch
|
|
334
|
+
// body (matches the codebase's parse-or-sentinel idiom; a throw inside catch obscures the
|
|
335
|
+
// original error). Malformed consumer JSON is a hard stop: refuse to merge, require a fix.
|
|
336
|
+
let existing = null;
|
|
337
|
+
try {
|
|
338
|
+
existing = JSON.parse(fs.readFileSync(relDst, "utf-8"));
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
existing = null;
|
|
342
|
+
}
|
|
343
|
+
if (existing === null) {
|
|
344
|
+
throw new Error(`[bkit] ${relDst} is malformed JSON — fix manually before running bkit install`);
|
|
345
|
+
}
|
|
346
|
+
const merged = deepMergeJson(existing, template);
|
|
347
|
+
// Replace (do not deep-merge) each provider key the template seeds — heals hijacked
|
|
348
|
+
// npm/baseURL/name while keeping other provider keys additive.
|
|
349
|
+
//
|
|
350
|
+
// Preserve the EXISTING file's provider key order (deepMergeJson orders template keys
|
|
351
|
+
// first, which is right for last-match-wins maps like permission.bash): rebuild from the
|
|
352
|
+
// existing order — replacing template-seeded blocks in place — then append new template
|
|
353
|
+
// providers in template order. Install and upgrade render the same order.
|
|
354
|
+
const tmplProv = template.provider;
|
|
355
|
+
if (tmplProv !== null && typeof tmplProv === "object" && !Array.isArray(tmplProv)) {
|
|
356
|
+
const tmplProvObj = tmplProv;
|
|
357
|
+
const existingProvObj = existing.provider !== null &&
|
|
358
|
+
typeof existing.provider === "object" &&
|
|
359
|
+
!Array.isArray(existing.provider)
|
|
360
|
+
? existing.provider
|
|
361
|
+
: {};
|
|
362
|
+
const orderedProv = {};
|
|
363
|
+
for (const k of Object.keys(existingProvObj)) {
|
|
364
|
+
orderedProv[k] =
|
|
365
|
+
k in tmplProvObj
|
|
366
|
+
? JSON.parse(JSON.stringify(tmplProvObj[k]))
|
|
367
|
+
: existingProvObj[k];
|
|
368
|
+
}
|
|
369
|
+
for (const [k, v] of Object.entries(tmplProvObj)) {
|
|
370
|
+
if (!(k in orderedProv))
|
|
371
|
+
orderedProv[k] = JSON.parse(JSON.stringify(v));
|
|
372
|
+
}
|
|
373
|
+
merged.provider = orderedProv;
|
|
374
|
+
}
|
|
375
|
+
const mergedStr = JSON.stringify(merged, null, 2) + "\n";
|
|
376
|
+
if (mergedStr === fs.readFileSync(relDst, "utf-8"))
|
|
377
|
+
return; // idempotent guard
|
|
378
|
+
if (!dryRun) {
|
|
379
|
+
fs.writeFileSync(relDst, mergedStr, "utf-8");
|
|
380
|
+
}
|
|
381
|
+
ws.writes.push({ path: relDst, action: "update" });
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Remove exactly one bkit-seeded provider block from the consumer's opencode.json.
|
|
385
|
+
* `dst` may be an absolute or relative path (fs.* accepts both).
|
|
386
|
+
* Used by the surgical uninstall path — this is NOT called during install (install is additive).
|
|
387
|
+
* Compares on opencodeProviderId(providerKey) to resolve the opencode-side block key.
|
|
388
|
+
* The caller is responsible for passing only bkit-seeded provider keys; this function does not
|
|
389
|
+
* validate providerKey against OPENCODE_PROVIDER_DEFAULTS (shared/egress.ts).
|
|
390
|
+
*/
|
|
391
|
+
export function removeOpencodeProviderBlock(dst, providerKey, dryRun, ws) {
|
|
392
|
+
if (!fs.existsSync(dst))
|
|
393
|
+
return;
|
|
394
|
+
// Parse-or-sentinel idiom: keep the early-return outside the catch body.
|
|
395
|
+
let existing = null;
|
|
396
|
+
try {
|
|
397
|
+
existing = JSON.parse(fs.readFileSync(dst, "utf-8"));
|
|
398
|
+
}
|
|
399
|
+
catch {
|
|
400
|
+
existing = null;
|
|
401
|
+
}
|
|
402
|
+
if (existing === null) {
|
|
403
|
+
console.warn(`[bkit] ${dst} is malformed — leaving as-is`);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const blockKey = opencodeProviderId(providerKey);
|
|
407
|
+
const providerObj = existing.provider;
|
|
408
|
+
if (providerObj === null || typeof providerObj !== "object" || Array.isArray(providerObj))
|
|
409
|
+
return;
|
|
410
|
+
const pObj = providerObj;
|
|
411
|
+
if (!(blockKey in pObj))
|
|
412
|
+
return; // already absent — idempotent
|
|
413
|
+
delete pObj[blockKey];
|
|
414
|
+
if (Object.keys(pObj).length === 0)
|
|
415
|
+
delete existing.provider;
|
|
416
|
+
const updatedStr = JSON.stringify(existing, null, 2) + "\n";
|
|
417
|
+
if (!dryRun) {
|
|
418
|
+
fs.writeFileSync(dst, updatedStr, "utf-8");
|
|
419
|
+
}
|
|
420
|
+
ws.writes.push({ path: dst, action: "update" });
|
|
421
|
+
}
|
|
422
|
+
export function runOpencodeModule(ctx) {
|
|
423
|
+
const { dryRun, advisories, ws, logPrefix } = ctx;
|
|
424
|
+
const tag = dryRun ? "[dry-run] " : "";
|
|
425
|
+
const issueTracker = ctx.issueTracker ?? DEFAULT_ISSUE_TRACKER;
|
|
426
|
+
// See renderOpencodeAgentsCommands — the opencode host is unary; no provider throws.
|
|
427
|
+
if (!ctx.opencodeProvider) {
|
|
428
|
+
throw new Error("runOpencodeModule: ctx.opencodeProvider is required");
|
|
429
|
+
}
|
|
430
|
+
const provider = ctx.opencodeProvider;
|
|
431
|
+
// Source-rendered agents/commands (.opencode/agents + .opencode/commands). Extracted to
|
|
432
|
+
// renderOpencodeAgentsCommands so `bkit upgrade` re-renders them identically —
|
|
433
|
+
// bkit-owned output, force-overwritten.
|
|
434
|
+
renderOpencodeAgentsCommands(ctx);
|
|
435
|
+
// --- opencode.json — Tier-2 deep-contained (reconverged on upgrade) ---
|
|
436
|
+
{
|
|
437
|
+
const opencodeShared = path.join(getSharedRoot(), ".opencode");
|
|
438
|
+
const jsonSrc = path.join(opencodeShared, "opencode.json");
|
|
439
|
+
const jsonDst = ".opencode/opencode.json";
|
|
440
|
+
if (fs.existsSync(jsonSrc)) {
|
|
441
|
+
// Render the template with tracker-filtered mcp + provider config, then reconcile it into
|
|
442
|
+
// the consumer file. Install is additive: existing provider blocks are preserved.
|
|
443
|
+
// reconcileOpencodeJson computes an identical writeset for dry-run vs real runs — no
|
|
444
|
+
// `.bkit-staging` scratch file.
|
|
445
|
+
const rendered = renderOpencodeJson(jsonSrc, issueTracker, provider, process.cwd());
|
|
446
|
+
const prevLen = ws.writes.length;
|
|
447
|
+
reconcileOpencodeJson(rendered, jsonDst, dryRun, ws);
|
|
448
|
+
if (ws.writes.length > prevLen) {
|
|
449
|
+
console.log(`${logPrefix} ${tag}opencode: ${jsonDst}`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
// --- bkit-gateguard.js — Tier-2 markered-text (slash-comment); see install/manifest.ts ---
|
|
454
|
+
{
|
|
455
|
+
const opencodeCore = path.join(getCoreRoot(), ".opencode", "plugin");
|
|
456
|
+
const pluginSrc = path.join(opencodeCore, "bkit-gateguard.js");
|
|
457
|
+
const pluginDst = ".opencode/plugin/bkit-gateguard.js";
|
|
458
|
+
if (fs.existsSync(pluginSrc)) {
|
|
459
|
+
// dryRun-gated — writeTier2 honours dryRun, so the dir is only needed for a real
|
|
460
|
+
// write; `bkit check` stays read-only when gateguard's parent dir is absent.
|
|
461
|
+
if (!dryRun)
|
|
462
|
+
ensureDir(path.dirname(pluginDst));
|
|
463
|
+
const prevLen = ws.writes.length;
|
|
464
|
+
writeTier2(pluginSrc, pluginDst, ctx.tokens, "slash-comment", dryRun, ws);
|
|
465
|
+
if (ws.writes.length > prevLen) {
|
|
466
|
+
console.log(`${logPrefix} ${tag}opencode: ${pluginDst}`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// opencode post-install advisory — provider key + launch + model-ID lookup pointer.
|
|
471
|
+
advisories.push({
|
|
472
|
+
id: "opencode-setup",
|
|
473
|
+
severity: "advisory",
|
|
474
|
+
detect: `opencode host installed (provider: ${provider}). The opencode CLI and your provider credentials are required before running agents.`,
|
|
475
|
+
action: `opencode setup for provider "${provider}":\n\n` +
|
|
476
|
+
(() => {
|
|
477
|
+
const pd = OPENCODE_PROVIDER_DEFAULTS[provider];
|
|
478
|
+
if (!pd) {
|
|
479
|
+
return (` 1. Set ${provider.toUpperCase()}_API_KEY in your environment / .bkit/.env.\n` +
|
|
480
|
+
` 2. Update .opencode/opencode.json provider.${provider}.options.baseURL for your endpoint.\n`);
|
|
481
|
+
}
|
|
482
|
+
// opencode-native gateways (opencode-zen / opencode-go) → BKIT_OPENCODE_API_KEY only.
|
|
483
|
+
// Built-in: no baseURL to seed; models use the opencode-side provider id.
|
|
484
|
+
if (pd.builtin || pd.envVar === "BKIT_OPENCODE_API_KEY") {
|
|
485
|
+
const modelPrefix = opencodeProviderId(provider);
|
|
486
|
+
return (` 1. opencode gateway "${provider}". Create an API key at https://opencode.ai/auth (one BKIT_OPENCODE_API_KEY covers both opencode-zen and opencode-go).\n` +
|
|
487
|
+
` 2. Set ${pd.envVar} in your environment / .bkit/.env:\n` +
|
|
488
|
+
` ${pd.envVar}=<your-api-key>\n` +
|
|
489
|
+
` 3. Built-in provider (no npm/baseURL). Models are referenced as ${modelPrefix}/<id>.\n`);
|
|
490
|
+
}
|
|
491
|
+
return (` 1. Set ${pd.envVar} in your environment / .bkit/.env:\n` +
|
|
492
|
+
` ${pd.envVar}=<your-api-key>\n` +
|
|
493
|
+
` 2. Provider base URL is pre-seeded: ${pd.baseURL}.\n`);
|
|
494
|
+
})() +
|
|
495
|
+
` 3. Launch opencode: \`opencode\` (CLI, reads .opencode/opencode.json automatically), or\n` +
|
|
496
|
+
` \`bkit opencode\` to launch the desktop app with .bkit/.env merged into its environment.\n` +
|
|
497
|
+
` macOS GUI apps launched from the Dock/Finder do not inherit the login-shell / direnv\n` +
|
|
498
|
+
` env — {env:KEY} placeholders in opencode.json resolve empty without this. Quit the\n` +
|
|
499
|
+
` running app first (a running instance ignores the new env).\n` +
|
|
500
|
+
` 4. Model IDs: all four providers (openrouter, ollama, opencode-zen, opencode-go) install ready-to-run curated per-agent pins. ` +
|
|
501
|
+
`Re-pin any agent via .bkit/prompts.md § Model Overrides or by probing the provider's live /v1/models — see .bkit/providers.md § Models. NOTE: ollama opus/convergent pins (kimi-k2.7-code, deepseek-v4-pro) need a paid Ollama plan; its sonnet/haiku pins run on the free tier. opencode-go pins (minimax-m3, qwen3.7-plus, deepseek-v4-pro/-flash) — prefer pins that stay within the Go 5h usage window; opencode-zen pins are existence-validated via models.dev (the /zen/v1/models REST probe cannot see Go-only models — models.dev is the source of truth).\n` +
|
|
502
|
+
` 5. Verify with: \`bkit doctor\` (credentials + tools) and \`bkit status\` (installed hosts + providers).`,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
import { getPkgRoot } from "../shared/package-roots.js";
|
|
5
|
+
import { managedVersionMarker } from "./version-file.js";
|
|
6
|
+
import { gitEnv, resolveRepoSlug } from "../ledgers/telemetry.js";
|
|
7
|
+
// Read the INSTALLING bkit version from the package root (NOT the consumer's
|
|
8
|
+
// package.json — that is a different version). Mirrors readInstallingVersion
|
|
9
|
+
// (install/modules/index.ts) / readPkgVersion (checks/after/index.ts); kept local to avoid a
|
|
10
|
+
// tokens → modules import cycle. "0.0.0" on any read failure.
|
|
11
|
+
function readInstallingBkitVersion() {
|
|
12
|
+
try {
|
|
13
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(getPkgRoot(), "package.json"), "utf-8"));
|
|
14
|
+
return pkg.version ?? "0.0.0";
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return "0.0.0";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Resolve DEFAULT_BRANCH: git symbolic-ref refs/remotes/origin/HEAD → "main"
|
|
21
|
+
function resolveDefaultBranch(cwd) {
|
|
22
|
+
try {
|
|
23
|
+
const raw = execSync("git symbolic-ref refs/remotes/origin/HEAD", {
|
|
24
|
+
cwd,
|
|
25
|
+
encoding: "utf-8",
|
|
26
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
27
|
+
env: gitEnv(),
|
|
28
|
+
}).trim();
|
|
29
|
+
// raw is like "refs/remotes/origin/main"
|
|
30
|
+
const parts = raw.split("/");
|
|
31
|
+
const branch = parts[parts.length - 1];
|
|
32
|
+
if (branch)
|
|
33
|
+
return branch;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// not a git repo or no remote HEAD configured — fall back
|
|
37
|
+
}
|
|
38
|
+
return "main";
|
|
39
|
+
}
|
|
40
|
+
// Read and parse package.json from cwd. Throws if absent.
|
|
41
|
+
function readPackageJson(cwd) {
|
|
42
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
43
|
+
if (!fs.existsSync(pkgPath)) {
|
|
44
|
+
throw new Error(`[bkit-placeholders] package.json not found at ${pkgPath}`);
|
|
45
|
+
}
|
|
46
|
+
const raw = fs.readFileSync(pkgPath, "utf-8");
|
|
47
|
+
return JSON.parse(raw);
|
|
48
|
+
}
|
|
49
|
+
// Resolve all tokens in a single read-once pass at install-start.
|
|
50
|
+
// Hard-fails (throws) if package.json.name is absent.
|
|
51
|
+
export async function resolveTokens(cwd) {
|
|
52
|
+
const pkg = readPackageJson(cwd);
|
|
53
|
+
const name = pkg["name"];
|
|
54
|
+
if (typeof name !== "string" || name.trim() === "") {
|
|
55
|
+
throw new Error(`[bkit-placeholders] package.json.name is required but missing or empty in ${cwd}`);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
DEFAULT_BRANCH: resolveDefaultBranch(cwd),
|
|
59
|
+
PROJECT_NAME: name.trim(),
|
|
60
|
+
REPO_SLUG: resolveRepoSlug(cwd),
|
|
61
|
+
BKIT_VERSION: readInstallingBkitVersion(),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Substitute {{TOKEN}} placeholders in content string.
|
|
65
|
+
// Substitution happens at write-time (caller's responsibility), not at template-read time.
|
|
66
|
+
// Uses function-form replacers to prevent $& / $1 / $$ substitution patterns from leaking
|
|
67
|
+
// through when token values contain dollar signs.
|
|
68
|
+
export function applyTokens(content, tokens) {
|
|
69
|
+
const defaultBranch = tokens.DEFAULT_BRANCH;
|
|
70
|
+
const projectName = tokens.PROJECT_NAME;
|
|
71
|
+
const repoSlug = tokens.REPO_SLUG;
|
|
72
|
+
let out = content
|
|
73
|
+
.replace(/\{\{DEFAULT_BRANCH\}\}/g, () => defaultBranch)
|
|
74
|
+
.replace(/\{\{PROJECT_NAME\}\}/g, () => projectName)
|
|
75
|
+
.replace(/\{\{REPO_SLUG\}\}/g, () => repoSlug);
|
|
76
|
+
// {{BKIT_MANAGED_MARKER}} → the managed-version marker. A token after `// ` at a line
|
|
77
|
+
// start resolves to the slash form (JS); every other occurrence to the HTML comment,
|
|
78
|
+
// so `# {{BKIT_MANAGED_MARKER}}` yields the hash form. The version is read from the
|
|
79
|
+
// package only when the token is present and the TokenMap omits BKIT_VERSION.
|
|
80
|
+
if (out.includes("{{BKIT_MANAGED_MARKER}}")) {
|
|
81
|
+
const version = tokens.BKIT_VERSION ?? readInstallingBkitVersion();
|
|
82
|
+
out = out
|
|
83
|
+
.replace(/^\/\/ \{\{BKIT_MANAGED_MARKER\}\}/gm, () => managedVersionMarker(version, "slash"))
|
|
84
|
+
.replace(/\{\{BKIT_MANAGED_MARKER\}\}/g, () => managedVersionMarker(version));
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|