@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,925 @@
|
|
|
1
|
+
// install/cloud-env.ts — resolve a copy-paste-ready Claude Code on the web env-var block
|
|
2
|
+
// by *following the consumer's `.envrc`*.
|
|
3
|
+
//
|
|
4
|
+
// The generated `.claude/bkit-cloud.md` (see runClaudeModule) inlines REAL SECRET
|
|
5
|
+
// VALUES so it is gitignored + chmod 600 and never committed. This module owns the
|
|
6
|
+
// stack-agnostic resolution: it reads whatever dotenv files the repo's `.envrc`
|
|
7
|
+
// sources, honours the `.envrc` `unset` lines, and drops session-hijack keys.
|
|
8
|
+
// bkit hardcodes NO stack-specific key lists — the stack knowledge lives in the
|
|
9
|
+
// consumer's `.envrc`, keeping bkit's shipped surface stack-independent.
|
|
10
|
+
//
|
|
11
|
+
// Excluded keys are exactly the vars `.envrc` unsets, and the review key is
|
|
12
|
+
// BKIT_ANTHROPIC_API_KEY — both derived here without a bespoke key list.
|
|
13
|
+
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import type { IssueTracker } from "./manifest.js";
|
|
17
|
+
import { getSharedRoot } from "../shared/package-roots.js";
|
|
18
|
+
import { applyTokens, type TokenMap } from "./placeholders.js";
|
|
19
|
+
import { BKIT_EGRESS_SOURCES, type EgressSource } from "../shared/egress.js";
|
|
20
|
+
import { sha256 } from "./version-file.js";
|
|
21
|
+
|
|
22
|
+
// Consumer-relative paths of the generated docs. Shared so the upgrade template walk
|
|
23
|
+
// (commands/install/install.ts) can exclude them — they are generated OUTPUT files, never
|
|
24
|
+
// templates to reconcile. One per cloud host (Claude Code on the web / Cursor
|
|
25
|
+
// Background Agents); both inline resolved secrets, both gitignored + chmod 600.
|
|
26
|
+
export const CLAUDE_CLOUD_RELPATH = path.join(".claude", "bkit-cloud.md");
|
|
27
|
+
export const CURSOR_CLOUD_RELPATH = path.join(".cursor", "bkit-cloud.md");
|
|
28
|
+
|
|
29
|
+
// Session-hijack keys: exporting these into a cloud env redirects Claude Code's
|
|
30
|
+
// OWN model calls onto API-key billing instead of the user's subscription
|
|
31
|
+
// (`.bkit/cloud.md` § Environment variables). Always dropped from the paste block.
|
|
32
|
+
export const SESSION_HIJACK_KEYS = [
|
|
33
|
+
"ANTHROPIC_API_KEY",
|
|
34
|
+
"BKIT_ANTHROPIC_API_KEY",
|
|
35
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
36
|
+
] as const;
|
|
37
|
+
|
|
38
|
+
// bkit baseline env-var NAMES every Claude-on-web environment needs. Emitted as a
|
|
39
|
+
// placeholder ONLY when absent from the resolved `.envrc` set — a present value
|
|
40
|
+
// (e.g. BKIT_GH_TOKEN already in `.bkit/.env`) keeps its real resolved value.
|
|
41
|
+
const BASELINE_TOKEN_PLACEHOLDERS: ReadonlyArray<readonly [string, string]> = [
|
|
42
|
+
["BKIT_GH_TOKEN", "<fine-grained PAT — see .bkit/cloud.md § BKIT_GH_TOKEN permissions>"],
|
|
43
|
+
["BKIT_GH_TOKEN_INSTALL", "<classic PAT with read:packages>"],
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// Earlier-compaction override — a bkit constant, not a secret. Appended to the
|
|
47
|
+
// block when not already resolved from a source file. Claude-harness-only knob —
|
|
48
|
+
// Cursor has no equivalent, so it is NOT in the Cursor policy's constants.
|
|
49
|
+
const AUTOCOMPACT_KEY = "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE";
|
|
50
|
+
const AUTOCOMPACT_VALUE = "70";
|
|
51
|
+
|
|
52
|
+
// Per-cloud env-var policy. The `.envrc`-following resolver core is identical for
|
|
53
|
+
// both clouds (same dotenv sources, same unset/hijack/empty drops) — only the
|
|
54
|
+
// baseline placeholder set and the appended constants differ. Claude pairs with the
|
|
55
|
+
// GitHub tracker and wants the autocompact override; Cursor pairs with Linear (and
|
|
56
|
+
// so also needs `BKIT_LINEAR_API_KEY`) and has no autocompact knob. Keeping one resolver
|
|
57
|
+
// with a small policy object is what guarantees the two generated docs describe the
|
|
58
|
+
// SAME cloud environment — just different mechanics (pasted setup vs. Dockerfile).
|
|
59
|
+
export interface CloudEnvPolicy {
|
|
60
|
+
/** Baseline env-var NAMES this cloud always needs; emitted as `NAME=<placeholder>`
|
|
61
|
+
* when absent from the resolved `.envrc` set. */
|
|
62
|
+
baseline: ReadonlyArray<readonly [string, string]>;
|
|
63
|
+
/** Constant KEY/value pairs appended when not already resolved from a source. */
|
|
64
|
+
constants: ReadonlyArray<readonly [string, string]>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Claude Code on the web: GitHub tracker, autocompact override.
|
|
68
|
+
export const CLAUDE_CLOUD_POLICY: CloudEnvPolicy = {
|
|
69
|
+
baseline: BASELINE_TOKEN_PLACEHOLDERS,
|
|
70
|
+
constants: [[AUTOCOMPACT_KEY, AUTOCOMPACT_VALUE]],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Cursor Background Agents: `BKIT_LINEAR_API_KEY` prepended for the Linear tracker
|
|
74
|
+
// (bkit-preflight.sh calls the Linear GraphQL API and hard-fails without it); GitHub
|
|
75
|
+
// tracker uses the same GH baseline as Claude, minus the autocompact knob.
|
|
76
|
+
const CURSOR_LINEAR_PLACEHOLDER: readonly [string, string] = [
|
|
77
|
+
"BKIT_LINEAR_API_KEY",
|
|
78
|
+
"<Linear personal API key — https://linear.app/settings/api>",
|
|
79
|
+
];
|
|
80
|
+
export function cursorCloudPolicy(tracker: IssueTracker): CloudEnvPolicy {
|
|
81
|
+
return {
|
|
82
|
+
baseline:
|
|
83
|
+
tracker === "linear"
|
|
84
|
+
? [CURSOR_LINEAR_PLACEHOLDER, ...BASELINE_TOKEN_PLACEHOLDERS]
|
|
85
|
+
: BASELINE_TOKEN_PLACEHOLDERS,
|
|
86
|
+
constants: [],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface CloudEnvResolution {
|
|
91
|
+
/** Resolved KEY/value pairs, non-empty, ordered first-seen with last-source value. */
|
|
92
|
+
included: Array<[string, string]>;
|
|
93
|
+
/** Vars a source file set that `.envrc` then `unset`s (dropped by design). */
|
|
94
|
+
unset: string[];
|
|
95
|
+
/** Session-hijack keys that were present and were dropped. */
|
|
96
|
+
hijackDropped: string[];
|
|
97
|
+
/** Keys whose resolved value was empty (skipped from the paste block). */
|
|
98
|
+
emptySkipped: string[];
|
|
99
|
+
/** Baseline token names absent from sources — emitted as placeholders. */
|
|
100
|
+
placeholders: string[];
|
|
101
|
+
/** `.envrc` dotenv targets that existed and were read (for the Notes line). */
|
|
102
|
+
sources: string[];
|
|
103
|
+
/** Whether an `.envrc` was found at all. */
|
|
104
|
+
hasEnvrc: boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Strip one layer of matching surrounding single/double quotes. */
|
|
108
|
+
function stripQuotes(v: string): string {
|
|
109
|
+
const t = v.trim();
|
|
110
|
+
if (
|
|
111
|
+
t.length >= 2 &&
|
|
112
|
+
((t.startsWith('"') && t.endsWith('"')) || (t.startsWith("'") && t.endsWith("'")))
|
|
113
|
+
) {
|
|
114
|
+
return t.slice(1, -1);
|
|
115
|
+
}
|
|
116
|
+
return t;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Parse an `.envrc` for the direnv directives bkit follows: `dotenv` /
|
|
121
|
+
* `dotenv_if_exists <file>` targets (in order), `unset <VAR...>` lines, and direct
|
|
122
|
+
* `export KEY=value` assignments. Arbitrary bash (conditionals, PATH_add, etc.) is
|
|
123
|
+
* ignored — bkit never executes the `.envrc`, it reads these declarative lines.
|
|
124
|
+
*/
|
|
125
|
+
export function parseEnvrc(content: string): {
|
|
126
|
+
dotenvFiles: string[];
|
|
127
|
+
unsets: string[];
|
|
128
|
+
exports: Array<[string, string]>;
|
|
129
|
+
} {
|
|
130
|
+
const dotenvFiles: string[] = [];
|
|
131
|
+
const unsets: string[] = [];
|
|
132
|
+
const exports: Array<[string, string]> = [];
|
|
133
|
+
for (const raw of content.split("\n")) {
|
|
134
|
+
const line = raw.trim();
|
|
135
|
+
if (line === "" || line.startsWith("#")) continue;
|
|
136
|
+
let m: RegExpMatchArray | null;
|
|
137
|
+
if ((m = line.match(/^dotenv(?:_if_exists)?\s+(.+)$/))) {
|
|
138
|
+
dotenvFiles.push(stripQuotes(m[1]!.trim()));
|
|
139
|
+
} else if ((m = line.match(/^unset\s+(.+)$/))) {
|
|
140
|
+
for (const v of m[1]!.split(/\s+/)) if (v) unsets.push(v);
|
|
141
|
+
} else if ((m = line.match(/^export\s+([A-Za-z_][A-Za-z0-9_]*)=(.*)$/))) {
|
|
142
|
+
exports.push([m[1]!, stripQuotes(m[2]!)]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return { dotenvFiles, unsets, exports };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Parse a dotenv file into ordered KEY/value pairs (values quote-stripped). */
|
|
149
|
+
export function parseDotenv(content: string): Array<[string, string]> {
|
|
150
|
+
const out: Array<[string, string]> = [];
|
|
151
|
+
for (const raw of content.split("\n")) {
|
|
152
|
+
const line = raw.trim();
|
|
153
|
+
if (line === "" || line.startsWith("#")) continue;
|
|
154
|
+
// `(.*)$` keeps `=` characters inside the value intact.
|
|
155
|
+
const m = line.match(/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/);
|
|
156
|
+
if (!m) continue;
|
|
157
|
+
out.push([m[1]!, stripQuotes(m[2]!)]);
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Resolve the cloud env-var set by following the consumer's `.envrc`. Later dotenv
|
|
164
|
+
* sources override earlier (direnv last-wins); direct `export`s win over files.
|
|
165
|
+
* Applies `.envrc` unsets, then drops session-hijack keys. Returns empty when no
|
|
166
|
+
* `.envrc` exists — the caller still emits a usable placeholder doc.
|
|
167
|
+
*/
|
|
168
|
+
export function resolveCloudEnvVars(
|
|
169
|
+
cwd: string,
|
|
170
|
+
policy: CloudEnvPolicy = CLAUDE_CLOUD_POLICY,
|
|
171
|
+
): CloudEnvResolution {
|
|
172
|
+
const res: CloudEnvResolution = {
|
|
173
|
+
included: [],
|
|
174
|
+
unset: [],
|
|
175
|
+
hijackDropped: [],
|
|
176
|
+
emptySkipped: [],
|
|
177
|
+
placeholders: [],
|
|
178
|
+
sources: [],
|
|
179
|
+
hasEnvrc: false,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const envrcPath = path.join(cwd, ".envrc");
|
|
183
|
+
let dotenvFiles: string[] = [];
|
|
184
|
+
let unsets: string[] = [];
|
|
185
|
+
let exports: Array<[string, string]> = [];
|
|
186
|
+
if (fs.existsSync(envrcPath)) {
|
|
187
|
+
res.hasEnvrc = true;
|
|
188
|
+
({ dotenvFiles, unsets, exports } = parseEnvrc(fs.readFileSync(envrcPath, "utf-8")));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Accumulate. A Map preserves first-seen insertion order; re-setting an existing
|
|
192
|
+
// key updates its value in place, giving "first-seen order, last-source value".
|
|
193
|
+
const map = new Map<string, string>();
|
|
194
|
+
for (const rel of dotenvFiles) {
|
|
195
|
+
const p = path.join(cwd, rel);
|
|
196
|
+
if (!fs.existsSync(p)) continue;
|
|
197
|
+
res.sources.push(rel);
|
|
198
|
+
for (const [k, v] of parseDotenv(fs.readFileSync(p, "utf-8"))) map.set(k, v);
|
|
199
|
+
}
|
|
200
|
+
for (const [k, v] of exports) map.set(k, v);
|
|
201
|
+
|
|
202
|
+
// Honour `.envrc` unsets (record only those a source actually set).
|
|
203
|
+
for (const k of unsets) {
|
|
204
|
+
if (map.has(k)) {
|
|
205
|
+
res.unset.push(k);
|
|
206
|
+
map.delete(k);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Drop session-hijack keys.
|
|
211
|
+
for (const k of SESSION_HIJACK_KEYS) {
|
|
212
|
+
if (map.has(k)) {
|
|
213
|
+
res.hijackDropped.push(k);
|
|
214
|
+
map.delete(k);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Partition non-empty (included) vs empty (skipped).
|
|
219
|
+
for (const [k, v] of map) {
|
|
220
|
+
if (v === "") res.emptySkipped.push(k);
|
|
221
|
+
else res.included.push([k, v]);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Baseline names absent from the resolved set → emitted as placeholders.
|
|
225
|
+
const present = new Set(res.included.map(([k]) => k));
|
|
226
|
+
for (const [name] of policy.baseline) {
|
|
227
|
+
if (!present.has(name)) res.placeholders.push(name);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return res;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Render the `.env`-format paste block: resolved KEY=value lines, then placeholder
|
|
235
|
+
* lines for any absent baseline token, then the autocompact override if unset.
|
|
236
|
+
*/
|
|
237
|
+
export function renderCloudEnvBlock(
|
|
238
|
+
res: CloudEnvResolution,
|
|
239
|
+
policy: CloudEnvPolicy = CLAUDE_CLOUD_POLICY,
|
|
240
|
+
): string {
|
|
241
|
+
const lines: string[] = [];
|
|
242
|
+
for (const [k, v] of res.included) lines.push(`${k}=${v}`);
|
|
243
|
+
for (const [name, placeholder] of policy.baseline) {
|
|
244
|
+
if (res.placeholders.includes(name)) lines.push(`${name}=${placeholder}`);
|
|
245
|
+
}
|
|
246
|
+
for (const [key, value] of policy.constants) {
|
|
247
|
+
if (!res.included.some(([k]) => k === key)) lines.push(`${key}=${value}`);
|
|
248
|
+
}
|
|
249
|
+
return lines.join("\n");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function fmtList(items: string[]): string {
|
|
253
|
+
return items.map((x) => `\`${x}\``).join(", ");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Render the markdown notes under the env-var block (transparency for what was dropped). */
|
|
257
|
+
export function renderCloudEnvNotes(res: CloudEnvResolution): string {
|
|
258
|
+
if (!res.hasEnvrc) {
|
|
259
|
+
return (
|
|
260
|
+
"_No `.envrc` found — the block above lists only the bkit baseline token names as " +
|
|
261
|
+
"placeholders. Add your `.envrc` (`bkit install` seeds one) and re-run to inline real values._"
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const bullets: string[] = [];
|
|
265
|
+
if (res.placeholders.length) {
|
|
266
|
+
bullets.push(
|
|
267
|
+
`- **Fill in (absent from your env files):** ${fmtList(res.placeholders)} — placeholder values above.`,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (res.unset.length) {
|
|
271
|
+
bullets.push(
|
|
272
|
+
`- **Dropped — \`.envrc\` unsets these:** ${fmtList(res.unset)} — kept out of the cloud env by design.`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
if (res.hijackDropped.length) {
|
|
276
|
+
bullets.push(
|
|
277
|
+
`- **Dropped — session-billing hijack:** ${fmtList(res.hijackDropped)} — would redirect the agent's own model calls onto API-key billing instead of your subscription.`,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
if (res.emptySkipped.length) {
|
|
281
|
+
bullets.push(`- **Empty in source (skipped):** ${fmtList(res.emptySkipped)}`);
|
|
282
|
+
}
|
|
283
|
+
const header = `_${res.included.length} var${res.included.length === 1 ? "" : "s"} resolved${
|
|
284
|
+
res.sources.length ? ` from ${fmtList(res.sources)}` : ""
|
|
285
|
+
}._`;
|
|
286
|
+
return bullets.length ? `${header}\n\n${bullets.join("\n")}` : header;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Parse the pnpm `X.Y.Z` from `package.json` `packageManager` ("" if absent/non-pnpm). */
|
|
290
|
+
export function resolveConsumerPnpm(cwd: string): string {
|
|
291
|
+
try {
|
|
292
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf-8")) as Record<
|
|
293
|
+
string,
|
|
294
|
+
unknown
|
|
295
|
+
>;
|
|
296
|
+
const pm = typeof pkg["packageManager"] === "string" ? (pkg["packageManager"] as string) : "";
|
|
297
|
+
const m = pm.match(/^pnpm@(\d+\.\d+\.\d+)/);
|
|
298
|
+
return m?.[1] ?? "";
|
|
299
|
+
} catch {
|
|
300
|
+
return "";
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Render the setup-script corepack line from the consumer's own `packageManager`
|
|
306
|
+
* pin (NOT bkit's — the pin is a snapshot pre-warm, non-load-bearing: corepack
|
|
307
|
+
* resolves each repo's `packageManager` in-repo). Degrades to bare `corepack
|
|
308
|
+
* enable` when the pin is absent.
|
|
309
|
+
*/
|
|
310
|
+
export function renderCorepackLine(cwd: string): string {
|
|
311
|
+
const v = resolveConsumerPnpm(cwd);
|
|
312
|
+
return v
|
|
313
|
+
? `corepack enable && corepack prepare pnpm@${v} --activate`
|
|
314
|
+
: `corepack enable # pnpm resolved from package.json "packageManager" in-repo`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Extract the bash body of every `context-fetch:provision <name>` block the consumer
|
|
319
|
+
* enabled below `<!-- bkit:end -->` in `.agents/context.md`. Stack-agnostic: bkit
|
|
320
|
+
* hardcodes no CLI names — the install recipe lives in the consumer's context.md,
|
|
321
|
+
* co-located with the fetch block that needs the CLI. `bkit context list-blocks` returns
|
|
322
|
+
* the same list as `provision`, which `.claude/hooks/bkit-cloud-bootstrap.sh` runs, so the web
|
|
323
|
+
* setup-script snapshot and the per-session hook provision the same CLIs. Returns one
|
|
324
|
+
* string per block (bash body).
|
|
325
|
+
*/
|
|
326
|
+
export function extractContextFetchProvisionRecipes(cwd: string): string[] {
|
|
327
|
+
const filePath = path.join(cwd, ".agents", "context.md");
|
|
328
|
+
if (!fs.existsSync(filePath)) return [];
|
|
329
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
330
|
+
const endIdx = content.search(/^<!-- bkit:end -->$/m);
|
|
331
|
+
if (endIdx === -1) return [];
|
|
332
|
+
const consumer = content.slice(endIdx);
|
|
333
|
+
const recipes: string[] = [];
|
|
334
|
+
let cur: string[] | null = null;
|
|
335
|
+
let inProv = false;
|
|
336
|
+
let inFence = false;
|
|
337
|
+
for (const line of consumer.split("\n")) {
|
|
338
|
+
if (/^<!-- context-fetch:provision/.test(line)) {
|
|
339
|
+
inProv = true;
|
|
340
|
+
inFence = false;
|
|
341
|
+
cur = [];
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (/^<!-- context-fetch:(start|end|none)/.test(line)) {
|
|
345
|
+
if (inProv && cur && cur.length > 0) recipes.push(cur.join("\n"));
|
|
346
|
+
inProv = false;
|
|
347
|
+
inFence = false;
|
|
348
|
+
cur = null;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (inProv && /^```/.test(line)) {
|
|
352
|
+
inFence = !inFence;
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
if (inProv && inFence && cur) cur.push(line);
|
|
356
|
+
}
|
|
357
|
+
return recipes;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Render the `@@CLOUD_CACHE_BUST@@` line — a `# cache-bust YYYY-MM-DD-N` comment at
|
|
362
|
+
* the top of the setup script. claude.ai/code snapshots the setup script keyed on its
|
|
363
|
+
* exact text and reuses that snapshot; a changing cache-bust line forces a fresh
|
|
364
|
+
* snapshot on the next paste, so "latest"-resolved downloads (gh, gcloud SDK) and
|
|
365
|
+
* base-image drift get re-pulled even when the rest of the script is byte-identical.
|
|
366
|
+
* The counter increments per regeneration WITHIN a day (read back from the prior doc)
|
|
367
|
+
* and resets to 1 on a new date, so every regeneration yields a distinct value —
|
|
368
|
+
* guaranteeing a re-paste always busts. `today` (YYYY-MM-DD) is injected so the caller
|
|
369
|
+
* owns the clock and this stays deterministic under test.
|
|
370
|
+
*/
|
|
371
|
+
export function renderCloudCacheBust(cwd: string, today: string): string {
|
|
372
|
+
const dst = path.join(cwd, CLAUDE_CLOUD_RELPATH);
|
|
373
|
+
let counter = 1;
|
|
374
|
+
if (fs.existsSync(dst)) {
|
|
375
|
+
const prev = fs.readFileSync(dst, "utf-8");
|
|
376
|
+
const m = prev.match(/^# cache-bust (\d{4}-\d{2}-\d{2})-(\d+)$/m);
|
|
377
|
+
if (m && m[1] === today) counter = Number.parseInt(m[2], 10) + 1;
|
|
378
|
+
}
|
|
379
|
+
return `# cache-bust ${today}-${counter}`;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* `pnpm add -g` aborts ("The configured global bin directory … is not in PATH")
|
|
384
|
+
* unless pnpm's global-bin dir is on PATH. corepack-activated pnpm never runs
|
|
385
|
+
* `pnpm setup`, so under the setup script's `set -euo pipefail` a single `pnpm add
|
|
386
|
+
* -g <cli>` provision block kills the whole snapshot build (observed in cloud with
|
|
387
|
+
* `pnpm@11`). Prepend an explicit `PNPM_HOME` + PATH export so every provision
|
|
388
|
+
* recipe runs in a shell where `pnpm add -g` succeeds. `$PNPM_HOME` and
|
|
389
|
+
* `$PNPM_HOME/bin` are both added — pnpm's global-bin dir has differed by version.
|
|
390
|
+
*/
|
|
391
|
+
const CLOUD_PNPM_GLOBAL_PATH_SETUP =
|
|
392
|
+
"# pnpm refuses `add -g` unless its global-bin dir is on PATH (corepack pnpm skips `pnpm setup`).\n" +
|
|
393
|
+
'export PNPM_HOME="${PNPM_HOME:-$HOME/.local/share/pnpm}"\n' +
|
|
394
|
+
'export PATH="$PNPM_HOME:$PNPM_HOME/bin:$PATH"';
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Render the `@@CLOUD_CONTEXT_FETCH_PROVISION@@` setup-script region: the consumer's
|
|
398
|
+
* `context-fetch:provision` recipes, or "" when none are enabled. Placed AFTER the
|
|
399
|
+
* corepack line in the template so `pnpm add -g …` recipes have pnpm available.
|
|
400
|
+
*
|
|
401
|
+
* Recipes run in a best-effort `( set +e … ) || …` subshell: the setup script is
|
|
402
|
+
* `set -euo pipefail`, so without this a single failing recipe (e.g. a heavy `curl |
|
|
403
|
+
* bash` CLI installer that trips over a missing base-image dep) aborts the whole
|
|
404
|
+
* snapshot build and discards every CLI provisioned before it. `set +e` also lets a
|
|
405
|
+
* later recipe run after an earlier one fails. Mirrors the non-blocking per-session
|
|
406
|
+
* hook (`… | bash || log`), keeping the two cloud provision paths behaviourally equal.
|
|
407
|
+
*/
|
|
408
|
+
export function renderCloudContextFetchProvision(cwd: string): string {
|
|
409
|
+
const recipes = extractContextFetchProvisionRecipes(cwd);
|
|
410
|
+
if (recipes.length === 0) return "";
|
|
411
|
+
return (
|
|
412
|
+
"# context-fetch CLIs (from .agents/context.md provision blocks) — self-guarded, best-effort.\n" +
|
|
413
|
+
CLOUD_PNPM_GLOBAL_PATH_SETUP +
|
|
414
|
+
"\n" +
|
|
415
|
+
"(\n" +
|
|
416
|
+
" set +e\n" +
|
|
417
|
+
recipes.join("\n") +
|
|
418
|
+
"\n" +
|
|
419
|
+
') || echo "[cloud-setup] a context-fetch provision recipe failed (non-blocking); its CLI will be absent" >&2'
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Entries of every `<!-- {tag}:start --> … <!-- {tag}:end -->` list block BELOW
|
|
425
|
+
* `<!-- bkit:end -->` in `.agents/context.md` — one entry per line; blank, `#` comment
|
|
426
|
+
* and marker lines ignored. Blocks above the marker are never read. Returns entries
|
|
427
|
+
* verbatim, in order.
|
|
428
|
+
*/
|
|
429
|
+
function extractConsumerListBlock(cwd: string, tag: string): string[] {
|
|
430
|
+
const filePath = path.join(cwd, ".agents", "context.md");
|
|
431
|
+
if (!fs.existsSync(filePath)) return [];
|
|
432
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
433
|
+
const endIdx = content.search(/^<!-- bkit:end -->$/m);
|
|
434
|
+
if (endIdx === -1) return [];
|
|
435
|
+
const consumer = content.slice(endIdx);
|
|
436
|
+
const entries: string[] = [];
|
|
437
|
+
let inBlock = false;
|
|
438
|
+
for (const line of consumer.split("\n")) {
|
|
439
|
+
if (line.startsWith(`<!-- ${tag}:start`)) {
|
|
440
|
+
inBlock = true;
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
if (line.startsWith(`<!-- ${tag}:end`) || line.startsWith(`<!-- ${tag}:none`)) {
|
|
444
|
+
inBlock = false;
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (!inBlock) continue;
|
|
448
|
+
const t = line.trim();
|
|
449
|
+
if (!t || t.startsWith("#") || t.startsWith("<!--")) continue;
|
|
450
|
+
entries.push(t);
|
|
451
|
+
}
|
|
452
|
+
return entries;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Cloud network-allowlist domains the consumer declared in `allowed-domains` blocks
|
|
457
|
+
* (one registrable domain per line). Stack-agnostic: bkit hardcodes no domains — the
|
|
458
|
+
* consumer declares which log-backend / API / app hosts their cloud sessions must
|
|
459
|
+
* reach. Returns declared entries verbatim (pre-expansion), in order.
|
|
460
|
+
*/
|
|
461
|
+
export function extractAllowedDomains(cwd: string): string[] {
|
|
462
|
+
return extractConsumerListBlock(cwd, "allowed-domains");
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* MCP server names the consumer declared in `mcp-servers` blocks (one per line,
|
|
467
|
+
* spelled exactly as each host names the server in its tool ids). Every tool on a
|
|
468
|
+
* listed server is pre-approved on every host — see `.bkit/providers.md` § MCP
|
|
469
|
+
* servers. Deduplicated, declaration order kept.
|
|
470
|
+
*/
|
|
471
|
+
export function extractMcpServers(cwd: string): string[] {
|
|
472
|
+
return [...new Set(extractConsumerListBlock(cwd, "mcp-servers"))];
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Expand each declared registrable domain to BOTH the apex and a `*.` wildcard so the
|
|
477
|
+
* WHOLE domain is allowlisted — the egress proxy matches apex and subdomains
|
|
478
|
+
* separately, so `inngest.com` alone misses `api.inngest.com` and vice-versa. A
|
|
479
|
+
* consumer entry already written as `*.x` is normalised to its apex `x` first, then
|
|
480
|
+
* both forms are emitted. Grouped apex-then-wildcard per domain, domains sorted.
|
|
481
|
+
*/
|
|
482
|
+
export function expandAllowedDomains(declared: string[]): string[] {
|
|
483
|
+
const bases = [
|
|
484
|
+
...new Set(declared.map((d) => d.replace(/^\*\./, "").trim()).filter(Boolean)),
|
|
485
|
+
].sort();
|
|
486
|
+
return bases.flatMap((b) => [b, `*.${b}`]);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** True for a bracketed IPv6 literal or a dotted-quad IPv4 literal. */
|
|
490
|
+
export function isIpLiteral(host: string): boolean {
|
|
491
|
+
return host.startsWith("[") || /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Propose the registrable base for a provider `baseURL`, or `""` when the URL
|
|
496
|
+
* contributes no allowlistable host. `URL.canParse` gates the parse, so this never
|
|
497
|
+
* throws and carries no `try` / `catch`; an unparseable value contributes nothing.
|
|
498
|
+
*
|
|
499
|
+
* Contributes nothing for an empty host, `localhost` and its subdomains, an IP
|
|
500
|
+
* literal, and any host of fewer than two labels: none of those is reachable through
|
|
501
|
+
* a cloud egress allowlist. Everything else collapses to its last two labels.
|
|
502
|
+
*
|
|
503
|
+
* The collapse is the naive last-two-labels rule. Multi-label public suffixes and
|
|
504
|
+
* shared-tenant apexes are a DENY at authoring time in the registry gate test, never a
|
|
505
|
+
* base rewrite here.
|
|
506
|
+
*/
|
|
507
|
+
export function proposeEgressBase(baseURL: string): string {
|
|
508
|
+
if (!URL.canParse(baseURL)) return "";
|
|
509
|
+
const host = new URL(baseURL).hostname;
|
|
510
|
+
if (host === "" || isIpLiteral(host)) return "";
|
|
511
|
+
if (host === "localhost" || host.endsWith(".localhost")) return "";
|
|
512
|
+
const labels = host.split(".");
|
|
513
|
+
if (labels.length < 2) return "";
|
|
514
|
+
return labels.slice(-2).join(".");
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Sorted-unique `hosts` and `bases` across a set of egress sources. Pure: takes the
|
|
519
|
+
* rows rather than reading {@link BKIT_EGRESS_SOURCES}, so a test can inject a fixture
|
|
520
|
+
* set without mocking the module.
|
|
521
|
+
*/
|
|
522
|
+
export function deriveEgressEntries(rows: readonly EgressSource[]): {
|
|
523
|
+
hosts: string[];
|
|
524
|
+
bases: string[];
|
|
525
|
+
} {
|
|
526
|
+
return {
|
|
527
|
+
hosts: [...new Set(rows.flatMap((r) => r.hosts))].sort(),
|
|
528
|
+
bases: [...new Set(rows.flatMap((r) => r.bases))].sort(),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Stack-agnostic tooling bases, derived from {@link BKIT_EGRESS_SOURCES} rather than
|
|
534
|
+
* hand-typed — adding a provider, tracker or shipped tooling host updates this export
|
|
535
|
+
* by editing one registry row. **Never** ship observability / app stacks here (Vercel,
|
|
536
|
+
* Supabase, Sentry, …) — those come solely from the consumer's `.agents/context.md`
|
|
537
|
+
* `allowed-domains` block (after `<!-- bkit:end -->`) via {@link resolveNetworkAllowlist}.
|
|
538
|
+
*/
|
|
539
|
+
export const BKIT_SHIPPED_NETWORK_DOMAINS: readonly string[] =
|
|
540
|
+
deriveEgressEntries(BKIT_EGRESS_SOURCES).bases;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* The exact hostnames behind {@link BKIT_SHIPPED_NETWORK_DOMAINS}. Consumers of the
|
|
544
|
+
* base list allowlist a whole domain; this is the narrower set, for surfaces that
|
|
545
|
+
* match a literal host.
|
|
546
|
+
*/
|
|
547
|
+
export const BKIT_SHIPPED_NETWORK_HOSTS: readonly string[] =
|
|
548
|
+
deriveEgressEntries(BKIT_EGRESS_SOURCES).hosts;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Apex-only unique bases from an expanded (apex + `*.`) domain list.
|
|
552
|
+
*
|
|
553
|
+
* Single call site (injectOpencodeDerivedAllows in install/modules/index.ts). Same apex-collapse
|
|
554
|
+
* shape as expandAllowedDomains above.
|
|
555
|
+
*/
|
|
556
|
+
export function networkAllowlistBases(expanded: string[]): string[] {
|
|
557
|
+
return [...new Set(expanded.map((d) => d.replace(/^\*\./, "").trim()).filter(Boolean))].sort();
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Local + cloud network allowlist: stack-agnostic tooling defaults ∪ consumer
|
|
562
|
+
* `allowed-domains` from `.agents/context.md` (after `<!-- bkit:end -->`), each as
|
|
563
|
+
* apex + `*.` wildcard. Empty consumer block ⇒ tooling hosts only — no Vercel/etc.
|
|
564
|
+
*/
|
|
565
|
+
export function resolveNetworkAllowlist(cwd: string): string[] {
|
|
566
|
+
return expandAllowedDomains([...BKIT_SHIPPED_NETWORK_DOMAINS, ...extractAllowedDomains(cwd)]);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Every `permissions.allow` row bkit derives into `.claude/settings.json`: one
|
|
571
|
+
* `WebFetch(domain:…)` per {@link resolveNetworkAllowlist} entry, then two MCP rows per
|
|
572
|
+
* {@link extractMcpServers} entry — `mcp__<s>__*` (`.mcp.json` servers, and claude.ai
|
|
573
|
+
* connectors in cloud sessions) and `mcp__claude_ai_<s>__*` (claude.ai connectors in
|
|
574
|
+
* the local CLI). Single source for install / upgrade enrichment and uninstall strip.
|
|
575
|
+
*/
|
|
576
|
+
export function resolveClaudeDerivedAllows(cwd: string): string[] {
|
|
577
|
+
return [
|
|
578
|
+
...resolveNetworkAllowlist(cwd).map((d) => `WebFetch(domain:${d})`),
|
|
579
|
+
...extractMcpServers(cwd).flatMap((s) => [`mcp__${s}__*`, `mcp__claude_ai_${s}__*`]),
|
|
580
|
+
];
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/** Cursor-relative path of the install-written curl/wget allowlist (guardrails). */
|
|
584
|
+
export const NETWORK_ALLOWLIST_RELPATH = path.join(".cursor", "allowlist.json");
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Write `.cursor/allowlist.json` for Cursor `bkit-guardrails.cjs` (runtime curl/wget host
|
|
588
|
+
* checks). Claude/OpenCode bake the same domain set into their own configs at
|
|
589
|
+
* install/upgrade — they do not read this file. Call only when the cursor module
|
|
590
|
+
* is installed (do not create `.cursor/` for claude-only consumers).
|
|
591
|
+
*/
|
|
592
|
+
export function writeNetworkAllowlistArtifact(
|
|
593
|
+
cwd: string,
|
|
594
|
+
dryRun: boolean,
|
|
595
|
+
): { path: string; domains: string[]; wrote: boolean } {
|
|
596
|
+
const domains = resolveNetworkAllowlist(cwd);
|
|
597
|
+
const rel = NETWORK_ALLOWLIST_RELPATH;
|
|
598
|
+
return { path: rel, domains, wrote: writeGeneratedJson(cwd, rel, { domains }, dryRun) };
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** Cursor-relative path of the install-written Cursor CLI permissions (MCP allows). */
|
|
602
|
+
export const CURSOR_CLI_PERMISSIONS_RELPATH = path.join(".cursor", "cli.json");
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Write `.cursor/cli.json` — the project-level Cursor CLI / cloud-agent permissions —
|
|
606
|
+
* with one `Mcp(<server>:*)` allow per {@link extractMcpServers} entry. bkit-owned and
|
|
607
|
+
* regenerated whole, like `.cursor/allowlist.json`: hand edits do not survive, the
|
|
608
|
+
* `mcp-servers` block is the source. Call only when the cursor module is installed.
|
|
609
|
+
*/
|
|
610
|
+
export function writeCursorCliPermissionsArtifact(
|
|
611
|
+
cwd: string,
|
|
612
|
+
dryRun: boolean,
|
|
613
|
+
): { path: string; wrote: boolean } {
|
|
614
|
+
const allow = extractMcpServers(cwd).map((s) => `Mcp(${s}:*)`);
|
|
615
|
+
const rel = CURSOR_CLI_PERMISSIONS_RELPATH;
|
|
616
|
+
const doc = { permissions: { allow, deny: [] } };
|
|
617
|
+
return { path: rel, wrote: writeGeneratedJson(cwd, rel, doc, dryRun) };
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Write a whole-file generated JSON artifact. Returns whether the on-disk bytes differ
|
|
622
|
+
* from the rendered body — under `dryRun` that is computed without writing, so dry
|
|
623
|
+
* and real runs report the identical write set (the `bkit check` drift signal).
|
|
624
|
+
*/
|
|
625
|
+
function writeGeneratedJson(cwd: string, rel: string, doc: unknown, dryRun: boolean): boolean {
|
|
626
|
+
const abs = path.join(cwd, rel);
|
|
627
|
+
const body = JSON.stringify(doc, null, 2) + "\n";
|
|
628
|
+
const prev = fs.existsSync(abs) ? fs.readFileSync(abs, "utf-8") : null;
|
|
629
|
+
if (prev === body) return false;
|
|
630
|
+
if (!dryRun) {
|
|
631
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
632
|
+
fs.writeFileSync(abs, body, "utf-8");
|
|
633
|
+
}
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* 8-hex fingerprint of the DERIVED egress set only — bases and hosts, sorted, never
|
|
639
|
+
* the consumer union. Hosts are included (the Cursor paste is hosts-only). Editing
|
|
640
|
+
* `allowed-domains` never moves it; editing a registry row does.
|
|
641
|
+
*/
|
|
642
|
+
export function egressFingerprint(): string {
|
|
643
|
+
const derived = [
|
|
644
|
+
...new Set([...BKIT_SHIPPED_NETWORK_DOMAINS, ...BKIT_SHIPPED_NETWORK_HOSTS]),
|
|
645
|
+
].sort();
|
|
646
|
+
return sha256(derived.join("\n")).slice(0, 8);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Render the `@@CLOUD_NETWORK_ALLOWLIST@@` region — the whole `## Network access`
|
|
651
|
+
* body. Always emits a **Custom** paste block: the list is the derived shipped bases
|
|
652
|
+
* union whatever the consumer declared, so it is never empty and there is no
|
|
653
|
+
* zero-declaration branch. Declaring nothing narrows the list, it does not change the
|
|
654
|
+
* instruction.
|
|
655
|
+
*/
|
|
656
|
+
export function renderCloudNetworkAllowlist(cwd: string): string {
|
|
657
|
+
const declared = extractAllowedDomains(cwd);
|
|
658
|
+
const domains = resolveNetworkAllowlist(cwd);
|
|
659
|
+
const derivedCount = BKIT_SHIPPED_NETWORK_DOMAINS.length;
|
|
660
|
+
const declaredNote =
|
|
661
|
+
declared.length === 0
|
|
662
|
+
? "\n\n_No `allowed-domains` block is declared in `.agents/context.md`. The list above is\n" +
|
|
663
|
+
"bkit's own shipped hosts. If you run cloud `/bkit-debug` or e2e against a deployment,\n" +
|
|
664
|
+
"declare your log-backend + app domains there (apex per line) and they join this list._"
|
|
665
|
+
: "";
|
|
666
|
+
return (
|
|
667
|
+
"Set to **Custom** and tick **Also include default list of common package\n" +
|
|
668
|
+
"managers** — this EXTENDS the trusted defaults (package registries, GitHub,\n" +
|
|
669
|
+
"cloud SDKs), it does not replace them. Paste into the **Allowed domains** field\n" +
|
|
670
|
+
"(one per line):\n\n" +
|
|
671
|
+
"```text\n" +
|
|
672
|
+
domains.join("\n") +
|
|
673
|
+
"\n```\n\n" +
|
|
674
|
+
`_${domains.length} entries — ${derivedCount} derived from bkit's shipped egress registry ` +
|
|
675
|
+
`and ${declared.length} declared in \`allowed-domains\` in \`.agents/context.md\`, ` +
|
|
676
|
+
"each as apex + `*.` wildcard. Derived set fingerprint `" +
|
|
677
|
+
egressFingerprint() +
|
|
678
|
+
"`._" +
|
|
679
|
+
declaredNote +
|
|
680
|
+
"\n\nUnder **Trusted**, your app domains and most observability / API hosts are\n" +
|
|
681
|
+
"unreachable, so cloud `/bkit-debug` gets no runtime logs and e2e can't hit your\n" +
|
|
682
|
+
"deployment. **Full** works too but opens all egress."
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Parent directory Claude Code on the web clones a repo into.
|
|
688
|
+
*
|
|
689
|
+
* Observed on the current image (`/home/user/<repo-name>`, agent running as uid=0
|
|
690
|
+
* with `HOME=/root`) and NOT a documented contract: no environment variable in the
|
|
691
|
+
* container names the repo root. The setup script bakes the resolved path and
|
|
692
|
+
* `bkit-cloud-bootstrap.sh` checks the DISCOVERED one, warning loudly on mismatch.
|
|
693
|
+
*/
|
|
694
|
+
const CLOUD_REPO_PARENT = "/home/user";
|
|
695
|
+
|
|
696
|
+
/** The path {@link renderCloudWorkspaceTrust} bakes into the setup script. */
|
|
697
|
+
export function cloudRepoPath(cwd: string): string {
|
|
698
|
+
return `${CLOUD_REPO_PARENT}/${path.basename(path.resolve(cwd))}`;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Render the `@@CLOUD_WORKSPACE_TRUST@@` setup-script region — the workspace-trust flip.
|
|
703
|
+
*
|
|
704
|
+
* `permissions.allow` and `permissions.additionalDirectories` in a project's
|
|
705
|
+
* `.claude/settings.json` GRANT capability, so Claude Code applies them only once the
|
|
706
|
+
* workspace trust dialog has been accepted — and it never shows that dialog in a
|
|
707
|
+
* `claude -p` or SDK session. (`deny` and `ask` are unaffected; they only restrict.)
|
|
708
|
+
*
|
|
709
|
+
* Runs in the setup script: as root, before the clone, before Claude Code starts, with
|
|
710
|
+
* its filesystem snapshotted. Settings resolve before SessionStart, and `.claude/` is a
|
|
711
|
+
* protected path allow rules never pre-approve.
|
|
712
|
+
*
|
|
713
|
+
* Merges into the file (it may or may not exist at snapshot time, and Claude Code
|
|
714
|
+
* stores its own state alongside the key on first run).
|
|
715
|
+
*/
|
|
716
|
+
export function renderCloudWorkspaceTrust(cwd: string): string {
|
|
717
|
+
const repoPath = cloudRepoPath(cwd);
|
|
718
|
+
return (
|
|
719
|
+
"# Workspace trust. Without this Claude Code IGNORES every permissions.allow row in\n" +
|
|
720
|
+
"# .claude/settings.json — it only applies them once the trust dialog is accepted, and\n" +
|
|
721
|
+
"# cloud sessions never show that dialog. deny/ask are unaffected. Nothing inside the\n" +
|
|
722
|
+
"# session can set this: settings resolve before SessionStart, and .claude/ is a\n" +
|
|
723
|
+
"# protected path that allow rules never pre-approve.\n" +
|
|
724
|
+
'CLAUDE_JSON="${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json"\n' +
|
|
725
|
+
'mkdir -p "$(dirname "$CLAUDE_JSON")"\n' +
|
|
726
|
+
'[ -f "$CLAUDE_JSON" ] || printf \'{}\' > "$CLAUDE_JSON"\n' +
|
|
727
|
+
`jq --arg p '${repoPath}' '.projects[$p].hasTrustDialogAccepted = true' \\\n` +
|
|
728
|
+
' "$CLAUDE_JSON" > "$CLAUDE_JSON.tmp" && mv "$CLAUDE_JSON.tmp" "$CLAUDE_JSON"'
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Environment entries seeded into `~/.claude/settings.json` by {@link renderCloudUserSettings}.
|
|
734
|
+
*
|
|
735
|
+
* `"$defaults"` is NOT optional: omitting it replaces the entire built-in list for that
|
|
736
|
+
* section, which for `environment` discards every built-in trust slot (including
|
|
737
|
+
* "Trusted repo"). It is always emitted first, and asserted in the tests.
|
|
738
|
+
*
|
|
739
|
+
* Unconfigured, the classifier trusts only the working repo and its configured remotes,
|
|
740
|
+
* and `Host containment` defaults to "an ordinary developer machine or CI runner with
|
|
741
|
+
* open internet". These entries name the context-fetch hosts, the egress-allowlisted
|
|
742
|
+
* sandbox, and the session's identity.
|
|
743
|
+
*/
|
|
744
|
+
export function cloudAutoModeEnvironment(cwd: string): string[] {
|
|
745
|
+
const entries = [
|
|
746
|
+
"$defaults",
|
|
747
|
+
"Host containment: Claude Code runs inside the Claude Code on the web sandbox — a " +
|
|
748
|
+
"single-tenant container with no neighbouring workloads to reach, and egress " +
|
|
749
|
+
"restricted to the allowed-domains list configured on that environment. The cloud " +
|
|
750
|
+
"metadata endpoint is not used and should stay unreachable. The only credentials " +
|
|
751
|
+
"in the session are the environment variables set in the Claude app, so nothing " +
|
|
752
|
+
"should ever request credentials belonging to the host itself.",
|
|
753
|
+
];
|
|
754
|
+
const bases = networkAllowlistBases(resolveNetworkAllowlist(cwd));
|
|
755
|
+
if (bases.length > 0) {
|
|
756
|
+
entries.push(
|
|
757
|
+
`Trusted internal domains: ${bases.join(", ")} — all on the egress allowlist for ` +
|
|
758
|
+
"this environment, rendered from declarations in this repository, and the hosts " +
|
|
759
|
+
"context-fetch blocks read logs and diagnostics from during /bkit-debug.",
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
// Apostrophes would terminate the single-quoted `--argjson` literal in the generated
|
|
763
|
+
// setup script; keep the seeded prose free of them (asserted in the tests).
|
|
764
|
+
return entries;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Render the `@@CLOUD_USER_SETTINGS@@` setup-script region — the auto-mode classifier config.
|
|
769
|
+
*
|
|
770
|
+
* Written host-side: the classifier does NOT read `autoMode` from `.claude/settings.json`
|
|
771
|
+
* or `.claude/settings.local.json`.
|
|
772
|
+
*
|
|
773
|
+
* Seeds with `//=`, not `=`: a consumer's own `autoMode.environment` is never stomped by a
|
|
774
|
+
* re-pasted setup script, and later bkit changes to the seeded entries do not reach a
|
|
775
|
+
* container that already has them.
|
|
776
|
+
*/
|
|
777
|
+
export function renderCloudUserSettings(cwd: string): string {
|
|
778
|
+
const env = JSON.stringify(cloudAutoModeEnvironment(cwd));
|
|
779
|
+
return (
|
|
780
|
+
"# Auto-mode classifier config. The classifier does NOT read `autoMode` from\n" +
|
|
781
|
+
"# .claude/settings.json or .claude/settings.local.json — deliberately, so a checked-in\n" +
|
|
782
|
+
"# repo cannot inject its own classifier rules — so this cannot be shipped in the repo.\n" +
|
|
783
|
+
"# Seeded with //= so a consumer's existing entries are never overwritten.\n" +
|
|
784
|
+
'CLAUDE_SETTINGS="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/settings.json"\n' +
|
|
785
|
+
'mkdir -p "$(dirname "$CLAUDE_SETTINGS")"\n' +
|
|
786
|
+
'[ -f "$CLAUDE_SETTINGS" ] || printf \'{}\' > "$CLAUDE_SETTINGS"\n' +
|
|
787
|
+
`jq --argjson e '${env}' '.autoMode.environment //= $e' \\\n` +
|
|
788
|
+
' "$CLAUDE_SETTINGS" > "$CLAUDE_SETTINGS.tmp" && mv "$CLAUDE_SETTINGS.tmp" "$CLAUDE_SETTINGS"'
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Generate `.claude/bkit-cloud.md` — a copy-paste-ready Claude Code on the web setup doc
|
|
794
|
+
* with the env-var block resolved to REAL VALUES from the consumer's `.envrc`.
|
|
795
|
+
*
|
|
796
|
+
* The file is gitignored + chmod 600 and holds live secrets: it is UNTRACKED (not
|
|
797
|
+
* pushed to any WriteSet / manifest / canonicalHashes) so it never enters `bkit
|
|
798
|
+
* check` drift or the upgrade template walk — its values are machine-local and
|
|
799
|
+
* expected to differ. Shared by install (runClaudeModule) and upgrade so a rotated
|
|
800
|
+
* secret or version bump reaches the doc either way. Callers MUST guard on
|
|
801
|
+
* `!dryRun` (never write secrets during `bkit check` / `--dry-run`) and on the
|
|
802
|
+
* claude host being installed. Returns true when a file was written (false when the
|
|
803
|
+
* template is absent). Never logs the resolved values.
|
|
804
|
+
*/
|
|
805
|
+
export function writeClaudeCloudDoc(cwd: string, tokens: TokenMap): boolean {
|
|
806
|
+
const src = path.join(getSharedRoot(), ".claude", "bkit-cloud.md");
|
|
807
|
+
if (!fs.existsSync(src)) return false;
|
|
808
|
+
const res = resolveCloudEnvVars(cwd);
|
|
809
|
+
// UTC day drives the cache-bust; renderCloudCacheBust reads the PRIOR dst below to
|
|
810
|
+
// continue the per-day counter, before dst is overwritten.
|
|
811
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
812
|
+
// Function-form replacers: resolved secret values may contain `$`, which a string
|
|
813
|
+
// replacement would interpret ($&, $1, …).
|
|
814
|
+
const content = applyTokens(fs.readFileSync(src, "utf-8"), tokens)
|
|
815
|
+
.replace(/@@CLOUD_CACHE_BUST@@/g, () => renderCloudCacheBust(cwd, today))
|
|
816
|
+
.replace(/@@CLOUD_NETWORK_ALLOWLIST@@/g, () => renderCloudNetworkAllowlist(cwd))
|
|
817
|
+
.replace(/@@CLOUD_WORKSPACE_TRUST@@/g, () => renderCloudWorkspaceTrust(cwd))
|
|
818
|
+
.replace(/@@CLOUD_USER_SETTINGS@@/g, () => renderCloudUserSettings(cwd))
|
|
819
|
+
.replace(/@@CLOUD_COREPACK@@/g, () => renderCorepackLine(cwd))
|
|
820
|
+
.replace(/@@CLOUD_CONTEXT_FETCH_PROVISION@@/g, () => renderCloudContextFetchProvision(cwd))
|
|
821
|
+
.replace(/@@CLOUD_ENV_VARS@@/g, () => renderCloudEnvBlock(res))
|
|
822
|
+
.replace(/@@CLOUD_ENV_NOTES@@/g, () => renderCloudEnvNotes(res));
|
|
823
|
+
const dst = path.join(cwd, CLAUDE_CLOUD_RELPATH);
|
|
824
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
825
|
+
fs.writeFileSync(dst, content, "utf-8");
|
|
826
|
+
fs.chmodSync(dst, 0o600);
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Render the `@@CURSOR_CONTEXT_FETCH@@` region of `.cursor/bkit-cloud.md`: the consumer's
|
|
832
|
+
* `context-fetch:provision` recipes formatted for the Cursor mechanic, or "" when none
|
|
833
|
+
* are enabled. On Claude these CLIs are baked into the pasted setup script (see
|
|
834
|
+
* renderCloudContextFetchProvision); Cursor has no setup script, so — to keep the two
|
|
835
|
+
* cloud environments aligned — the same recipes are surfaced as a copy-paste block for
|
|
836
|
+
* the per-snapshot `install` command in `.cursor/environment.json`. The recipes are
|
|
837
|
+
* already idempotent (`command -v X || pnpm add -g X`), so they are safe to re-run on
|
|
838
|
+
* every snapshot build. Reuses the SAME extractor as the Claude path so the two clouds
|
|
839
|
+
* never diverge on which CLIs they provision.
|
|
840
|
+
*/
|
|
841
|
+
export function renderCursorContextFetchProvision(cwd: string): string {
|
|
842
|
+
const recipes = extractContextFetchProvisionRecipes(cwd);
|
|
843
|
+
// Empty → "" and the template's sentinel line collapses to a single blank between
|
|
844
|
+
// sections; non-empty → a self-contained section with its own leading/trailing blank.
|
|
845
|
+
if (recipes.length === 0) return "";
|
|
846
|
+
return (
|
|
847
|
+
"\n## Context-fetch CLIs (parity with the Claude setup script)\n\n" +
|
|
848
|
+
"Your `.agents/context.md` declares these context-fetch CLIs. The Claude setup script\n" +
|
|
849
|
+
"bakes them into its snapshot; for the SAME tools on Cursor, chain them into the\n" +
|
|
850
|
+
"`install` command in `.cursor/environment.json` (idempotent — safe every rebuild):\n\n" +
|
|
851
|
+
"```bash\n" +
|
|
852
|
+
recipes.join("\n") +
|
|
853
|
+
"\n```\n"
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Render the `@@CURSOR_NETWORK@@` region — Cursor Cloud Agents DO have an egress
|
|
859
|
+
* allowlist (dashboard → Security: "Allow all" / "Default + allowlist" / "Allowlist
|
|
860
|
+
* only"), unlike the earlier assumption. Reuses the SAME declared `allowed-domains`
|
|
861
|
+
* as the Claude side, but — critically — does NOT apply Claude's apex+`*.`
|
|
862
|
+
* expansion: Cursor's own docs warn that a broad wildcard (`*.s3….amazonaws.com`)
|
|
863
|
+
* opens egress far wider than intended, so the declared apex entries are emitted
|
|
864
|
+
* verbatim with a note to add only the specific subdomains you need.
|
|
865
|
+
*/
|
|
866
|
+
export function renderCursorNetworkAllowlist(cwd: string): string {
|
|
867
|
+
const declared = extractAllowedDomains(cwd);
|
|
868
|
+
// Exact hosts, never apex + `*.`: Cursor's own docs warn a broad wildcard opens
|
|
869
|
+
// egress far wider than intended, so the shipped set contributes its HOSTS here
|
|
870
|
+
// while the Claude side takes the wildcard-expanded bases.
|
|
871
|
+
const entries = [...new Set([...BKIT_SHIPPED_NETWORK_HOSTS, ...declared])].sort();
|
|
872
|
+
return (
|
|
873
|
+
"If your org runs Cloud Agents in **Allowlist only** / **Default + allowlist** mode\n" +
|
|
874
|
+
"(dashboard → **Security**), add these hosts so cloud `/bkit-debug` + e2e can reach\n" +
|
|
875
|
+
"bkit's own tooling and your app and log backends:\n\n" +
|
|
876
|
+
"```text\n" +
|
|
877
|
+
entries.join("\n") +
|
|
878
|
+
"\n```\n\n" +
|
|
879
|
+
`_${entries.length} host(s) — ${BKIT_SHIPPED_NETWORK_HOSTS.length} derived from bkit's shipped ` +
|
|
880
|
+
`egress registry and ${declared.length} declared in \`allowed-domains\` in ` +
|
|
881
|
+
"`.agents/context.md`. Derived set fingerprint `" +
|
|
882
|
+
egressFingerprint() +
|
|
883
|
+
"`._ Add only the\n" +
|
|
884
|
+
"specific subdomains you need (e.g. `api.example.com`) — Cursor warns that a broad `*.`\n" +
|
|
885
|
+
"wildcard opens egress far wider than intended. (The Claude side auto-expands to apex + `*.`;\n" +
|
|
886
|
+
"Cursor's allowlist is deliberately narrower.)"
|
|
887
|
+
);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Generate `.cursor/bkit-cloud.md` — the Cursor Cloud Agents analogue of
|
|
892
|
+
* `.claude/bkit-cloud.md`. Both describe the SAME bkit cloud environment; only the
|
|
893
|
+
* mechanics differ. On Claude the doc carries a pasted setup script + network
|
|
894
|
+
* selector; on Cursor the toolchain lives in `.cursor/Dockerfile` + the per-snapshot
|
|
895
|
+
* `.cursor/environment.json` `install` (both committed, nothing to paste), so this doc
|
|
896
|
+
* is narrower: it resolves the **dashboard environment variables** to real values from
|
|
897
|
+
* the consumer's `.envrc` (Cursor policy — Linear tracker adds `BKIT_LINEAR_API_KEY`, no
|
|
898
|
+
* autocompact knob) and surfaces any context-fetch CLIs for parity.
|
|
899
|
+
*
|
|
900
|
+
* Like `.claude/bkit-cloud.md` it is gitignored + chmod 600 and UNTRACKED (never pushed to
|
|
901
|
+
* any WriteSet / manifest / canonicalHashes) — its values are machine-local and
|
|
902
|
+
* expected to differ, so it never enters `bkit check` drift or the upgrade template
|
|
903
|
+
* walk. Shared by install (runCursorModule) and upgrade. Callers MUST guard on
|
|
904
|
+
* `!dryRun` (never write secrets during `bkit check` / `--dry-run`) and on the cursor
|
|
905
|
+
* host being installed. Returns true when a file was written (false when the template
|
|
906
|
+
* is absent). Never logs the resolved values.
|
|
907
|
+
*/
|
|
908
|
+
export function writeCursorCloudDoc(cwd: string, tokens: TokenMap, tracker: IssueTracker): boolean {
|
|
909
|
+
const src = path.join(getSharedRoot(), ".cursor", "bkit-cloud.md");
|
|
910
|
+
if (!fs.existsSync(src)) return false;
|
|
911
|
+
const policy = cursorCloudPolicy(tracker);
|
|
912
|
+
const res = resolveCloudEnvVars(cwd, policy);
|
|
913
|
+
// Function-form replacers: resolved secret values may contain `$`, which a string
|
|
914
|
+
// replacement would interpret ($&, $1, …).
|
|
915
|
+
const content = applyTokens(fs.readFileSync(src, "utf-8"), tokens)
|
|
916
|
+
.replace(/@@CLOUD_ENV_VARS@@/g, () => renderCloudEnvBlock(res, policy))
|
|
917
|
+
.replace(/@@CLOUD_ENV_NOTES@@/g, () => renderCloudEnvNotes(res))
|
|
918
|
+
.replace(/@@CURSOR_NETWORK@@/g, () => renderCursorNetworkAllowlist(cwd))
|
|
919
|
+
.replace(/@@CURSOR_CONTEXT_FETCH@@/g, () => renderCursorContextFetchProvision(cwd));
|
|
920
|
+
const dst = path.join(cwd, CURSOR_CLOUD_RELPATH);
|
|
921
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
922
|
+
fs.writeFileSync(dst, content, "utf-8");
|
|
923
|
+
fs.chmodSync(dst, 0o600);
|
|
924
|
+
return true;
|
|
925
|
+
}
|