@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,169 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// bkit-guardrails.cjs — Cursor destructive-op + secret-exposure gates (parity with
|
|
3
|
+
// Claude `.claude/settings.json` permissions deny/ask and OpenCode permission map).
|
|
4
|
+
//
|
|
5
|
+
// Wired from `.cursor/hooks.json`:
|
|
6
|
+
// - beforeShellExecution → force-push / recursive-rm / dangerous git+gh
|
|
7
|
+
// - preToolUse (Read|TabRead) → .env ask; private-key deny
|
|
8
|
+
//
|
|
9
|
+
// Output: JSON `{ permission: "allow"|"ask"|"deny", user_message?, agent_message? }`
|
|
10
|
+
// Exit 0 always on a decided permission. failClosed:true in hooks.json blocks on crash.
|
|
11
|
+
// Fail-open: a single top-level catch allows on unexpected errors (same shape as gateguard).
|
|
12
|
+
//
|
|
13
|
+
// bkit generates the managed block at install: the shell detection and the deny / ask
|
|
14
|
+
// tiers are shared with the Claude and Codex hooks (bkit's `core/hooks/`); the output
|
|
15
|
+
// shape and the read gate below are Cursor's own.
|
|
16
|
+
//
|
|
17
|
+
// OWNERSHIP: everything between the markers below is bkit-managed and is
|
|
18
|
+
// overwritten on every `bkit install` / `bkit upgrade`. It is a pure decision
|
|
19
|
+
// engine only — no stdin read, no stdout write, no top-level invocation. Add your
|
|
20
|
+
// own gates in the driver that follows the managed block: call
|
|
21
|
+
// `bkitGuardrails(payload)`, fold in your own checks, and call `emit()` once.
|
|
22
|
+
|
|
23
|
+
"use strict";
|
|
24
|
+
|
|
25
|
+
// bkit:start
|
|
26
|
+
|
|
27
|
+
// {{BKIT_MANAGED_MARKER}}
|
|
28
|
+
|
|
29
|
+
const fs = require("node:fs");
|
|
30
|
+
const path = require("node:path");
|
|
31
|
+
|
|
32
|
+
// {{BKIT_PART guardrails-shell.js}}
|
|
33
|
+
|
|
34
|
+
// {{BKIT_PART guardrails-tiers.js}}
|
|
35
|
+
|
|
36
|
+
function allow() {
|
|
37
|
+
return { permission: "allow" };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function ask(userMessage, agentMessage) {
|
|
41
|
+
return {
|
|
42
|
+
permission: "ask",
|
|
43
|
+
user_message: userMessage,
|
|
44
|
+
agent_message: agentMessage ?? userMessage,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function deny(userMessage, agentMessage) {
|
|
49
|
+
return {
|
|
50
|
+
permission: "deny",
|
|
51
|
+
user_message: userMessage,
|
|
52
|
+
agent_message: agentMessage ?? userMessage,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @param {string} cmd */
|
|
57
|
+
function decideShell(cmd) {
|
|
58
|
+
const c = cmd.trim();
|
|
59
|
+
const v = classifyShell(c);
|
|
60
|
+
if (!v) return allow();
|
|
61
|
+
switch (v.tier) {
|
|
62
|
+
case "deny":
|
|
63
|
+
return deny(`Blocked: ${v.what} is denied by bkit Cursor guardrails.`, v.fix);
|
|
64
|
+
case "ask":
|
|
65
|
+
return ask(
|
|
66
|
+
"bkit Cursor guardrails: confirm this destructive / privileged shell command.",
|
|
67
|
+
`Command requires confirmation: ${c}`,
|
|
68
|
+
);
|
|
69
|
+
case "fetch":
|
|
70
|
+
return ask(
|
|
71
|
+
"bkit Cursor guardrails: confirm outbound curl/wget (host not on network allowlist).",
|
|
72
|
+
`Command requires confirmation: ${c}`,
|
|
73
|
+
);
|
|
74
|
+
default:
|
|
75
|
+
// Shell-as-edit-channel: ADVISORY, never a block — allow plus an `agent_message`
|
|
76
|
+
// naming the edited paths.
|
|
77
|
+
return { permission: "allow", agent_message: shellEditAdvisory(v.edits) };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** @param {string} filePath */
|
|
82
|
+
function decideRead(filePath) {
|
|
83
|
+
const p = filePath.replace(/\\/g, "/");
|
|
84
|
+
if (!p) return allow();
|
|
85
|
+
|
|
86
|
+
// Deny private-key material
|
|
87
|
+
if (/\.pem$/i.test(p) || /\.p12$/i.test(p) || /(^|\/)id_rsa$/i.test(p)) {
|
|
88
|
+
return deny(
|
|
89
|
+
"Blocked: reading private-key material is denied by bkit Cursor guardrails.",
|
|
90
|
+
`Do not read ${p}. Ask the user to supply needed material out-of-band.`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Ask on .env (allow .env.example)
|
|
95
|
+
const base = p.split("/").pop() || p;
|
|
96
|
+
if (base === ".env" || (/^\.env\./.test(base) && base !== ".env.example")) {
|
|
97
|
+
return ask(
|
|
98
|
+
"bkit Cursor guardrails: confirm reading an env/secrets file.",
|
|
99
|
+
`Reading ${p} may expose secrets. Prefer direnv / documented non-secret examples.`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return allow();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Entry point — pure. Takes the parsed hook payload, returns a decision object
|
|
108
|
+
* `{ permission, user_message?, agent_message? }`, or `null` when bkit has no
|
|
109
|
+
* opinion on this call (the caller decides what a no-opinion result means).
|
|
110
|
+
*/
|
|
111
|
+
function bkitGuardrails(payload) {
|
|
112
|
+
// beforeShellExecution: { command }
|
|
113
|
+
if (
|
|
114
|
+
typeof payload.command === "string" &&
|
|
115
|
+
payload.tool_name == null &&
|
|
116
|
+
payload.tool_input == null
|
|
117
|
+
) {
|
|
118
|
+
return decideShell(payload.command);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// preToolUse Read/TabRead: { tool_name, tool_input: { path|file_path|target_file|... } }
|
|
122
|
+
const tool = String(payload.tool_name || payload.toolName || "");
|
|
123
|
+
if (/^(Read|TabRead)$/i.test(tool) || payload.hook_event_name === "beforeReadFile") {
|
|
124
|
+
const input = payload.tool_input || payload.toolInput || payload;
|
|
125
|
+
const filePath =
|
|
126
|
+
input.path ||
|
|
127
|
+
input.file_path ||
|
|
128
|
+
input.filePath ||
|
|
129
|
+
input.target_file ||
|
|
130
|
+
input.targetFile ||
|
|
131
|
+
"";
|
|
132
|
+
return decideRead(String(filePath));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// beforeReadFile may put path at top level
|
|
136
|
+
if (typeof payload.path === "string" && !payload.command) {
|
|
137
|
+
return decideRead(payload.path);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// bkit:end
|
|
144
|
+
|
|
145
|
+
// --- driver (yours) ---------------------------------------------------------
|
|
146
|
+
// Reads stdin, calls into the managed block, and emits EXACTLY ONE JSON document.
|
|
147
|
+
// Add your own gates here: inspect the payload, and either return your own
|
|
148
|
+
// decision or defer to bkit's. Cursor discards the whole hook's output if two
|
|
149
|
+
// emitters both write to stdout.
|
|
150
|
+
|
|
151
|
+
function emit(decision) {
|
|
152
|
+
process.stdout.write(JSON.stringify(decision) + "\n");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function main() {
|
|
156
|
+
const raw = fs.readFileSync(0, "utf8").trim();
|
|
157
|
+
if (!raw) return emit({ permission: "allow" });
|
|
158
|
+
|
|
159
|
+
const payload = JSON.parse(raw);
|
|
160
|
+
const decision = bkitGuardrails(payload);
|
|
161
|
+
|
|
162
|
+
emit(decision ?? { permission: "allow" });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
main();
|
|
167
|
+
} catch {
|
|
168
|
+
emit({ permission: "allow" });
|
|
169
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# bkit-preflight.sh — Cursor Cloud sessionStart hook (failClosed: true)
|
|
3
|
+
#
|
|
4
|
+
# Validates Linear issue state before any background/cloud session does bkit
|
|
5
|
+
# work. Refuses the session if the issue isn't approved for automation.
|
|
6
|
+
#
|
|
7
|
+
# Trigger: is_background_agent === true (received via stdin JSON).
|
|
8
|
+
# Guards: `bkit:auto` label present; issue state not in {Cancelled, Done}.
|
|
9
|
+
# Setup: See `.bkit/README.md` § Linear setup.
|
|
10
|
+
#
|
|
11
|
+
# Cursor honours non-zero exit as a hard stop (failClosed: true) — non-zero
|
|
12
|
+
# blocks the session before the agent starts. Failures are also surfaced via
|
|
13
|
+
# `additional_context` so the user sees the reason.
|
|
14
|
+
#
|
|
15
|
+
# bkit generates the managed block at install: the Linear guard is shared with the
|
|
16
|
+
# Claude hook (bkit's `hooks/preflight-linear.sh`); the trigger, the runtime
|
|
17
|
+
# marker and the output shape below are Cursor's own.
|
|
18
|
+
|
|
19
|
+
# <!-- bkit:start -->
|
|
20
|
+
|
|
21
|
+
# {{BKIT_MANAGED_MARKER}}
|
|
22
|
+
|
|
23
|
+
set -euo pipefail
|
|
24
|
+
|
|
25
|
+
# Consume stdin so the writing process doesn't block.
|
|
26
|
+
# Cursor sessionStart payload: { session_id, is_background_agent, composer_mode } — used for IDE detection below.
|
|
27
|
+
INPUT=$(cat)
|
|
28
|
+
|
|
29
|
+
# IDE session bailout — grep only, no python3 on the skip path (failClosed:true in
|
|
30
|
+
# .cursor/hooks.json blocks the session if this exits non-zero). Background-agent
|
|
31
|
+
# sessions run inside the bkit Dockerfile, where python3 is present for the code below.
|
|
32
|
+
# (Claude variant: uses empty LINEAR_ISSUE_ID env var as the proxy.)
|
|
33
|
+
if ! printf '%s' "$INPUT" | grep -q '"is_background_agent"[[:space:]]*:[[:space:]]*true'; then
|
|
34
|
+
exit 0
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
# Runtime bridge — `is_background_agent` arrives ONLY on this hook's stdin JSON,
|
|
38
|
+
# so a workflow shell has no way to see it. Drop a marker `bkit runtime detect`
|
|
39
|
+
# reads back as RUNTIME=CLOUD_CURSOR. Gitignored, and a Cursor Cloud Agent gets
|
|
40
|
+
# a fresh clone per session, so it cannot go stale. Best-effort: a failure here
|
|
41
|
+
# degrades detection to LOCAL, it must never block the session.
|
|
42
|
+
if BKIT_REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) && [[ -d "$BKIT_REPO_ROOT/.bkit" ]]; then
|
|
43
|
+
printf 'CLOUD_CURSOR\n' > "$BKIT_REPO_ROOT/.bkit/.runtime-cursor" 2>/dev/null \
|
|
44
|
+
|| echo "[bkit-runtime] could not write .bkit/.runtime-cursor — runtime will resolve as LOCAL" >&2
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
# emit_context — Cursor sessionStart expects { additional_context: ... } directly.
|
|
48
|
+
# (Claude variant: wraps in { hookSpecificOutput: { hookEventName, additionalContext } }.)
|
|
49
|
+
emit_context() {
|
|
50
|
+
python3 - "$1" <<'PY'
|
|
51
|
+
import json, sys
|
|
52
|
+
print(json.dumps({"additional_context": sys.argv[1]}))
|
|
53
|
+
PY
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# Brew dep preflight — N/A on Cursor Cloud.
|
|
57
|
+
# Cursor Cloud runs in a containerised env where required CLIs (gh, jq, vale, pnpm, bun) are
|
|
58
|
+
# pre-installed via .cursor/Dockerfile, so the laptop-side brew check makes no sense here.
|
|
59
|
+
# (Claude variant: validates required CLIs are on PATH; missing → HARD STOP with brew install hint.)
|
|
60
|
+
|
|
61
|
+
# {{BKIT_PART preflight-linear.sh}}
|
|
62
|
+
|
|
63
|
+
# <!-- bkit:end -->
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// bkit-gateguard.js — bkit GateGuard plugin for opencode.
|
|
2
|
+
//
|
|
3
|
+
// Fires on opencode's tool hooks. On the FIRST touch of a given file in a session it
|
|
4
|
+
// delivers an investigation checklist into the model's tool result so the next edit is
|
|
5
|
+
// made with the investigation done. A second class of paths — quality-gate configs —
|
|
6
|
+
// gets a stronger "fix the code, don't weaken the gate" advisory.
|
|
7
|
+
// A write to a not-yet-existing path gets the reuse-over-duplicate checklist (rules.md
|
|
8
|
+
// "Improve over duplicate") instead of the read-this-file checklist.
|
|
9
|
+
//
|
|
10
|
+
// CONTRACT — do not regress:
|
|
11
|
+
// - ADVISORY BY DEFAULT: appends the checklist to the tool RESULT in the
|
|
12
|
+
// after-execute hook — never blocks. The before-execute hook is block-or-allow
|
|
13
|
+
// only (return = allow, throw = block) and has no "inject context without
|
|
14
|
+
// blocking" primitive, so it is reserved for deny mode; the after hook's result
|
|
15
|
+
// (`event.result.content` on 2.0, `output.output` on 1.x) is the channel the host
|
|
16
|
+
// reads back into the model's tool result. stderr is NOT a model channel on 2.0's
|
|
17
|
+
// detached server.
|
|
18
|
+
//
|
|
19
|
+
// - FAIL OPEN: top-level try/catch swallows every error except the deny-mode throw.
|
|
20
|
+
// - SUBAGENTS INCLUDED: a subagent edit is an edit. Dedup is per (session, file)
|
|
21
|
+
// and a subagent runs in its own session, so it gets its own checklist.
|
|
22
|
+
// - DEDUP: warns once per (session, file); state lives in OS temp dir keyed by
|
|
23
|
+
// sessionID and is GC'd after 24h. Never writes into the consumer repo.
|
|
24
|
+
//
|
|
25
|
+
// MODES (BKIT_GATEGUARD env var):
|
|
26
|
+
// - unset / anything else → advisory (append context to the tool result, never block) [DEFAULT]
|
|
27
|
+
// - "off" → disabled (no-op)
|
|
28
|
+
// - "deny" → deny the FIRST touch per file by throwing with the checklist
|
|
29
|
+
// as the reason; allow the retry (dedup). Opt-in.
|
|
30
|
+
//
|
|
31
|
+
// BKIT_ALLOW_CONFIG_EDIT=1 → suppress the gate-config advisory (sanctioned edit).
|
|
32
|
+
//
|
|
33
|
+
// opencode tool names: the edit surface is `write`, `edit` and `patch`. The terminal
|
|
34
|
+
// tool (`shell` in v2, `bash` before v2) is NOT guarded.
|
|
35
|
+
//
|
|
36
|
+
// The engine inside the managed block is generated at install from bkit's
|
|
37
|
+
// `core/hooks/gateguard-engine.js`, the same source as the Claude, Cursor and Codex hooks.
|
|
38
|
+
//
|
|
39
|
+
// OWNERSHIP: everything between the markers below is bkit-managed and is
|
|
40
|
+
// overwritten on every `bkit install` / `bkit upgrade`. It is a pure advisory
|
|
41
|
+
// engine only — no client calls, no stderr write, no throw — so it composes
|
|
42
|
+
// with your own checks in the exported plugin that follows the managed block,
|
|
43
|
+
// without bkit's block needing to know about them.
|
|
44
|
+
|
|
45
|
+
// bkit:start
|
|
46
|
+
|
|
47
|
+
// {{BKIT_MANAGED_MARKER}}
|
|
48
|
+
|
|
49
|
+
import * as fs from "node:fs";
|
|
50
|
+
import * as os from "node:os";
|
|
51
|
+
import * as path from "node:path";
|
|
52
|
+
|
|
53
|
+
// opencode edit-like tool names, lowercase in opencode's plugin API.
|
|
54
|
+
// The terminal tool (`shell` in v2, `bash` before v2) is NOT in this list.
|
|
55
|
+
const EDIT_TOOLS = new Set(["write", "edit", "patch"]);
|
|
56
|
+
|
|
57
|
+
// {{BKIT_PART gateguard-engine.js}}
|
|
58
|
+
|
|
59
|
+
// Pure: takes the tool name, the already-extracted file path, and the session id;
|
|
60
|
+
// returns the advisory to emit or null. Never touches opencode's client, stderr,
|
|
61
|
+
// or the throw path — the driver below owns all three, so it can fold in its own
|
|
62
|
+
// checks without bkit's block needing to change.
|
|
63
|
+
function bkitGateguard(toolName, filePath, sessionId) {
|
|
64
|
+
if (!EDIT_TOOLS.has(toolName)) return null;
|
|
65
|
+
// A write to a not-yet-existing path is a NEW file and gets the reuse checklist.
|
|
66
|
+
const isNewFile =
|
|
67
|
+
toolName === "write" && typeof filePath === "string" && !fs.existsSync(filePath);
|
|
68
|
+
return firstTouchAdvice(filePath, sessionId, isNewFile);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// bkit:end
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Driver — the one export shape OpenCode 1.x and 2.0 both load.
|
|
75
|
+
//
|
|
76
|
+
// - OpenCode 2.0 reads the default export's `id` and `setup()` and registers
|
|
77
|
+
// `ctx.tool.hook("execute.before", …)` (deny) and `ctx.tool.hook("execute.after", …)`
|
|
78
|
+
// (advisory). The event carries the tool name / arguments / session id as
|
|
79
|
+
// `event.tool` / `event.input` / `event.sessionID`; the after event also carries a
|
|
80
|
+
// mutable `event.result` the host reads back into the model's tool result.
|
|
81
|
+
// - OpenCode 1.18.29+ calls the default export's `server()` and uses the returned
|
|
82
|
+
// `"tool.execute.before"` / `"tool.execute.after"` hooks, whose arguments are
|
|
83
|
+
// `(input, output)` — tool args on `output.args`, result text on `output.output`.
|
|
84
|
+
//
|
|
85
|
+
// Both call the same bkitGateguard() engine above, so advisory / deny / off behaviour
|
|
86
|
+
// is identical across the two. The file deliberately imports NOTHING from
|
|
87
|
+
// `@opencode/plugin`: the engine needs nothing from it, and that package only exists
|
|
88
|
+
// on 2.0 — importing it would break the module load on 1.x.
|
|
89
|
+
//
|
|
90
|
+
// OpenCode 1.x earlier than 1.18.29 expects a FUNCTION default export; this file ships
|
|
91
|
+
// the object form the 2.0 loader requires. On such a release, delete and reinstall the
|
|
92
|
+
// plugin, or hand-port this driver to the function shape.
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
/** Edit-tool args → the target file path, across 1.x and 2.0 argument keys. */
|
|
96
|
+
function gateGuardFilePath(input) {
|
|
97
|
+
return input && typeof input === "object"
|
|
98
|
+
? (input.path ?? input.filePath ?? input.file_path)
|
|
99
|
+
: undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** True only for this plugin's deny-mode throw, so fail-open swallows nothing else. */
|
|
103
|
+
function isDenyThrow(err) {
|
|
104
|
+
return (
|
|
105
|
+
process.env.BKIT_GATEGUARD === "deny" &&
|
|
106
|
+
err instanceof Error &&
|
|
107
|
+
err.message.includes("[bkit GateGuard]")
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// opencode's advisory rides execute.after, by which point a `write` has already created
|
|
112
|
+
// the file, so `firstTouchAdvice`'s existsSync new-file test can no longer see that it
|
|
113
|
+
// was new. execute.before snapshots existence per call id; execute.after reads it back.
|
|
114
|
+
// Bounded: a call that never reaches after (a deny-mode throw) is dropped on overflow.
|
|
115
|
+
const NEW_FILE_BY_CALL = new Map();
|
|
116
|
+
|
|
117
|
+
function snapshotNewFile(callID, tool, filePath) {
|
|
118
|
+
if (callID === undefined || tool !== "write" || typeof filePath !== "string") return;
|
|
119
|
+
if (NEW_FILE_BY_CALL.size > 256) NEW_FILE_BY_CALL.clear();
|
|
120
|
+
NEW_FILE_BY_CALL.set(callID, !fs.existsSync(filePath));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function takeNewFile(callID) {
|
|
124
|
+
const isNew = NEW_FILE_BY_CALL.get(callID);
|
|
125
|
+
NEW_FILE_BY_CALL.delete(callID);
|
|
126
|
+
return isNew === true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* DENY MODE (execute.before — the only hook that can block). First touch of a file
|
|
131
|
+
* per session throws the checklist as the reason; the dedup lets the retry through.
|
|
132
|
+
* The before hook sees the file before a write creates it, so existence is accurate.
|
|
133
|
+
*/
|
|
134
|
+
function denyFirstTouch(tool, filePath, sessionID) {
|
|
135
|
+
if (process.env.BKIT_GATEGUARD !== "deny") return;
|
|
136
|
+
const result = bkitGateguard(tool, filePath, sessionID);
|
|
137
|
+
if (result && result.mode === "deny") throw new Error(result.context);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* ADVISORY MODE (execute.after). Returns the checklist to append to the tool result,
|
|
142
|
+
* or null when off / deny / already warned / no advice for this path. `isNewFile` is
|
|
143
|
+
* the pre-write snapshot (see NEW_FILE_BY_CALL), not the post-write filesystem.
|
|
144
|
+
*/
|
|
145
|
+
function advisoryFor(tool, filePath, sessionID, isNewFile) {
|
|
146
|
+
const mode = process.env.BKIT_GATEGUARD;
|
|
147
|
+
if (mode === "off" || mode === "deny") return null;
|
|
148
|
+
if (!EDIT_TOOLS.has(tool)) return null;
|
|
149
|
+
const result = firstTouchAdvice(filePath, sessionID, isNewFile);
|
|
150
|
+
return result ? result.context : null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** OpenCode 1.x before hook: `(input, output)`, tool args on `output.args`. */
|
|
154
|
+
async function bkitGateGuardBeforeV1(hookInput, output) {
|
|
155
|
+
try {
|
|
156
|
+
const { tool, sessionID, callID } = hookInput ?? {};
|
|
157
|
+
if (!EDIT_TOOLS.has(tool)) return;
|
|
158
|
+
const filePath = gateGuardFilePath(output?.args);
|
|
159
|
+
snapshotNewFile(callID, tool, filePath);
|
|
160
|
+
denyFirstTouch(tool, filePath, sessionID);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
if (isDenyThrow(err)) throw err;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** OpenCode 1.x after hook: append the checklist to `output.output`, the result text. */
|
|
167
|
+
async function bkitGateGuardAfterV1(hookInput, output) {
|
|
168
|
+
try {
|
|
169
|
+
const { tool, sessionID, callID, args } = hookInput ?? {};
|
|
170
|
+
const isNewFile = takeNewFile(callID);
|
|
171
|
+
if (!EDIT_TOOLS.has(tool)) return;
|
|
172
|
+
if (!output || typeof output !== "object") return;
|
|
173
|
+
const context = advisoryFor(tool, gateGuardFilePath(args ?? output.args), sessionID, isNewFile);
|
|
174
|
+
if (!context) return;
|
|
175
|
+
const existing = typeof output.output === "string" ? output.output : "";
|
|
176
|
+
output.output = existing.length > 0 ? `${existing}\n\n${context}` : context;
|
|
177
|
+
} catch {
|
|
178
|
+
// fail-open: never let an advisory error reach the host
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** OpenCode 2.0 before hook: one event, tool args on `event.input`. Snapshot + deny. */
|
|
183
|
+
async function bkitGateGuardBeforeV2(event) {
|
|
184
|
+
try {
|
|
185
|
+
const tool = event?.tool;
|
|
186
|
+
if (!EDIT_TOOLS.has(tool)) return;
|
|
187
|
+
const filePath = gateGuardFilePath(event?.input);
|
|
188
|
+
snapshotNewFile(event?.id, tool, filePath);
|
|
189
|
+
denyFirstTouch(tool, filePath, event?.sessionID);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
if (isDenyThrow(err)) throw err;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** OpenCode 2.0 after hook: append the checklist to `event.result.content`. */
|
|
196
|
+
async function bkitGateGuardAfterV2(event) {
|
|
197
|
+
try {
|
|
198
|
+
const tool = event?.tool;
|
|
199
|
+
const isNewFile = takeNewFile(event?.id);
|
|
200
|
+
if (!EDIT_TOOLS.has(tool)) return;
|
|
201
|
+
if (event?.status !== "completed" || !event.result) return;
|
|
202
|
+
const context = advisoryFor(tool, gateGuardFilePath(event?.input), event?.sessionID, isNewFile);
|
|
203
|
+
if (!context) return;
|
|
204
|
+
const content = Array.isArray(event.result.content) ? event.result.content : [];
|
|
205
|
+
event.result.content = [...content, { type: "text", text: context }];
|
|
206
|
+
} catch {
|
|
207
|
+
// fail-open: never let an advisory error reach the host
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const bkitGateGuardPlugin = {
|
|
212
|
+
id: "bkit-gateguard",
|
|
213
|
+
async setup(ctx) {
|
|
214
|
+
await ctx.tool.hook("execute.before", bkitGateGuardBeforeV2);
|
|
215
|
+
await ctx.tool.hook("execute.after", bkitGateGuardAfterV2);
|
|
216
|
+
},
|
|
217
|
+
async server() {
|
|
218
|
+
return {
|
|
219
|
+
"tool.execute.before": bkitGateGuardBeforeV1,
|
|
220
|
+
"tool.execute.after": bkitGateGuardAfterV1,
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export default bkitGateGuardPlugin;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
<!-- bkit:start -->
|
|
4
|
+
|
|
5
|
+
{{BKIT_MANAGED_MARKER}}
|
|
6
|
+
|
|
7
|
+
- **Rules:** Read `.agents/rules.md` → follow all rules.
|
|
8
|
+
|
|
9
|
+
> [!CAUTION]
|
|
10
|
+
> This file is a **workflow router only**. It does not execute workflows.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Route
|
|
15
|
+
|
|
16
|
+
### Step 1 — Extract from prompt XML (not MCP)
|
|
17
|
+
|
|
18
|
+
**If** prompt contains `<LINEAR_ISSUE>` XML block (Linear integration):
|
|
19
|
+
|
|
20
|
+
- `ISSUE_ID` ← `<id>` tag value (e.g. `LIN-123` or team-specific prefix)
|
|
21
|
+
- `DESCRIPTION` ← `<description>` tag content
|
|
22
|
+
- `LABELS` ← all `<label name="...">` values in `<labels>` block
|
|
23
|
+
- `COMMENTS` ← all `<comment>` entries from `<comment_thread>` + `<other_comment_threads>`, sorted newest-first by `created` attribute
|
|
24
|
+
|
|
25
|
+
**Else** scan entire session prompt for issue ID — try patterns in order, first match wins:
|
|
26
|
+
|
|
27
|
+
1. `#\d+` → GitHub issue number (e.g. `#123`); strip `#`, set `ISSUE_ID` = `123`
|
|
28
|
+
2. `[A-Z]+-\d+` → prefixed issue ID (e.g. `LIN-123`, `ISSUE-123`, or team-specific prefix)
|
|
29
|
+
3. bare `\d+` → numeric fallback (GitHub provider only; ambiguous — prefer `#\d+`)
|
|
30
|
+
|
|
31
|
+
Set `LABELS`, `DESCRIPTION`, `COMMENTS` = empty.
|
|
32
|
+
|
|
33
|
+
**If** no `ISSUE_ID` → **STOP** with `No issue ID provided.`
|
|
34
|
+
|
|
35
|
+
### Step 2 — Route from user message
|
|
36
|
+
|
|
37
|
+
In the bottom-most `USER:` entry in `# Message history` scan for commands (case-insensitive: Ship, Debug, Build, Plan, Design) → first match → `COMMAND`. **If** matched → skip Steps 3–4.
|
|
38
|
+
|
|
39
|
+
### Step 3 — Route from XML labels
|
|
40
|
+
|
|
41
|
+
Scan `LABELS` for commands (Ship, Debug, Build, Plan, Design) → first match → `COMMAND`. **If** matched → skip Step 4.
|
|
42
|
+
|
|
43
|
+
### Step 4 — MCP fallback (labels only)
|
|
44
|
+
|
|
45
|
+
Only if Steps 2–3 yield no `COMMAND`: read current issue labels via the configured tracker MCP (GitHub: `mcp__github__issue_read({ method: "get_labels", ... })`; Linear: `mcp__linear__get_issue({ id: "{ISSUE_ID}" })`) → scan returned labels → first match → `COMMAND`. Update `LABELS`, `DESCRIPTION`.
|
|
46
|
+
|
|
47
|
+
### Step 5 — No match
|
|
48
|
+
|
|
49
|
+
Emit: `Workflow not found for issue {ISSUE_ID}. Valid commands: Design / Plan / Build / Debug / Ship.` → **STOP**. (Do not post a tracker comment — the router does not know which tracker MCP to call at this point.)
|
|
50
|
+
|
|
51
|
+
### Step 6 — Execute command
|
|
52
|
+
|
|
53
|
+
Read and execute the matched command file for the current IDE.
|
|
54
|
+
|
|
55
|
+
**Cursor** (`.cursor/commands/`):
|
|
56
|
+
|
|
57
|
+
<!-- prettier-ignore -->
|
|
58
|
+
| Label | Command |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `Ship` | `.cursor/commands/bkit-ship.md` |
|
|
61
|
+
| `Debug` | `.cursor/commands/bkit-debug.md` |
|
|
62
|
+
| `Build` | `.cursor/commands/bkit-build.md` |
|
|
63
|
+
| `Plan` | `.cursor/commands/bkit-plan.md` |
|
|
64
|
+
| `Design` | `.cursor/commands/bkit-design.md` |
|
|
65
|
+
|
|
66
|
+
**Claude Code** (`.claude/commands/`):
|
|
67
|
+
|
|
68
|
+
<!-- prettier-ignore -->
|
|
69
|
+
| Label | Command |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `Ship` | `.claude/commands/bkit-ship.md` |
|
|
72
|
+
| `Debug` | `.claude/commands/bkit-debug.md` |
|
|
73
|
+
| `Build` | `.claude/commands/bkit-build.md` |
|
|
74
|
+
| `Plan` | `.claude/commands/bkit-plan.md` |
|
|
75
|
+
| `Design` | `.claude/commands/bkit-design.md` |
|
|
76
|
+
|
|
77
|
+
<!-- bkit:end -->
|