@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,310 @@
|
|
|
1
|
+
// commands/comply.ts — compliance grader for the bkit workflow suite.
|
|
2
|
+
//
|
|
3
|
+
// Grader:
|
|
4
|
+
// - Pure functions over `git diff parentSha..HEAD` + filesystem state.
|
|
5
|
+
// - Deterministic, advisory (NEVER gating). Fail-open: callers use the idiom
|
|
6
|
+
// `pnpm bkit comply --phase={p} || echo "[bkit-comply] grader unavailable, skipping"`.
|
|
7
|
+
// - Emits one `kind:"compliance"` row per run×rule into `.bkit/stats.jsonl`.
|
|
8
|
+
// - Surfaces violations in ship-summary.md.
|
|
9
|
+
//
|
|
10
|
+
// Smallest-first rule set:
|
|
11
|
+
// `no-mirror-edit` — .claude/* and .cursor/* must not appear in the diff
|
|
12
|
+
// `skip-ci-not-head` — the HEAD commit must carry `[skip ci]` if the workflow
|
|
13
|
+
// close convention requires it (advisory only)
|
|
14
|
+
//
|
|
15
|
+
// See DE-34 for the shared-entrypoint + crash-isolation contract.
|
|
16
|
+
import { execFileSync } from "node:child_process";
|
|
17
|
+
import * as fs from "node:fs";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
import { getPkgRoot } from "../shared/package-roots.js";
|
|
20
|
+
import { isMirrorPath } from "../shared/protected-paths.js";
|
|
21
|
+
import { resolveGitSha, resolveRepoSlug, } from "../ledgers/telemetry.js";
|
|
22
|
+
/** SHA charset guard — only raw hex SHAs from the ledger are accepted. */
|
|
23
|
+
const SHA_RE = /^[0-9a-f]{7,40}$/;
|
|
24
|
+
export const realGitAdapter = {
|
|
25
|
+
diffPaths(parentSha, cwd) {
|
|
26
|
+
if (!SHA_RE.test(parentSha)) {
|
|
27
|
+
console.error(`[bkit-comply] diffPaths: parentSha "${parentSha}" does not match /^[0-9a-f]{7,40}$/ — skipping diff`);
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const output = execFileSync("git", ["diff", "--name-only", `${parentSha}..HEAD`], {
|
|
32
|
+
cwd,
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
35
|
+
});
|
|
36
|
+
return output
|
|
37
|
+
.split("\n")
|
|
38
|
+
.map((l) => l.trim())
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.error("[bkit-comply] git diff failed (fail-open):", e);
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
headSubject(cwd) {
|
|
47
|
+
try {
|
|
48
|
+
return execFileSync("git", ["log", "-1", "--format=%s"], {
|
|
49
|
+
cwd,
|
|
50
|
+
encoding: "utf8",
|
|
51
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
52
|
+
}).trim();
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error("[bkit-comply] git log failed (fail-open):", e);
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Individual rules (pure functions)
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
/**
|
|
64
|
+
* no-mirror-edit — flags any path in the diff that falls inside a bkit-managed
|
|
65
|
+
* mirror directory. Mirror dirs must never be hand-edited; edits belong in the
|
|
66
|
+
* canonical `.bkit/` source and are regenerated by `bkit install` / `bkit upgrade`.
|
|
67
|
+
*/
|
|
68
|
+
export function ruleNoMirrorEdit(diffPaths) {
|
|
69
|
+
const mirrored = diffPaths.filter((p) => isMirrorPath(p));
|
|
70
|
+
if (mirrored.length === 0)
|
|
71
|
+
return null;
|
|
72
|
+
return {
|
|
73
|
+
ruleId: "no-mirror-edit",
|
|
74
|
+
description: "One or more bkit-managed mirror files were hand-edited. " +
|
|
75
|
+
"Mirror files must only be regenerated by `bkit install` / `bkit upgrade`, " +
|
|
76
|
+
"not edited directly.",
|
|
77
|
+
evidence: mirrored.join(", "),
|
|
78
|
+
result: "fail",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* skip-ci-not-head — advisory check that the final commit before ship does NOT
|
|
83
|
+
* carry `[skip ci]` (which would leave the PR's statusCheckRollup empty and admit
|
|
84
|
+
* a vacuously green PR). Fires only for the `ship` phase.
|
|
85
|
+
*
|
|
86
|
+
* Advisory: a `[skip ci]` HEAD is legitimate for worktree-setup / create-pr commits
|
|
87
|
+
* (DE-21 D2); the ship close step's CI-Dispatch Gate is the deterministic guard. This
|
|
88
|
+
* rule adds a grader-level record.
|
|
89
|
+
*/
|
|
90
|
+
export function ruleSkipCiNotHead(headSubject, phase) {
|
|
91
|
+
if (phase !== "ship")
|
|
92
|
+
return null;
|
|
93
|
+
const hasSkipCi = headSubject.includes("[skip ci]");
|
|
94
|
+
if (!hasSkipCi)
|
|
95
|
+
return null;
|
|
96
|
+
return {
|
|
97
|
+
ruleId: "skip-ci-not-head",
|
|
98
|
+
description: "HEAD commit carries `[skip ci]` at ship close. " +
|
|
99
|
+
"This leaves the PR statusCheckRollup empty, admitting a vacuously green PR. " +
|
|
100
|
+
"The CI-Dispatch Gate (#261) handles recovery, but this advisory records the occurrence.",
|
|
101
|
+
evidence: `HEAD subject: ${headSubject}`,
|
|
102
|
+
result: "fail",
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Run all rules and return the Violation array.
|
|
107
|
+
* Returns an empty array on any unexpected error (fail-open).
|
|
108
|
+
*/
|
|
109
|
+
export function runGrader(input) {
|
|
110
|
+
try {
|
|
111
|
+
const cwd = input.cwd ?? process.cwd();
|
|
112
|
+
const adapter = input.gitAdapter ?? realGitAdapter;
|
|
113
|
+
const diffPaths = adapter.diffPaths(input.parentSha, cwd);
|
|
114
|
+
const headSubject = adapter.headSubject(cwd);
|
|
115
|
+
const violations = [];
|
|
116
|
+
const noMirrorViolation = ruleNoMirrorEdit(diffPaths);
|
|
117
|
+
if (noMirrorViolation)
|
|
118
|
+
violations.push(noMirrorViolation);
|
|
119
|
+
const skipCiViolation = ruleSkipCiNotHead(headSubject, input.phase);
|
|
120
|
+
if (skipCiViolation)
|
|
121
|
+
violations.push(skipCiViolation);
|
|
122
|
+
return violations;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// Fail-open: unhandled errors yield no violations rather than crashing.
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build one `kind:"compliance"` row per rule.
|
|
131
|
+
* Rules that produced no violation emit a "pass" row.
|
|
132
|
+
* Every row carries `bkitVersion`.
|
|
133
|
+
*
|
|
134
|
+
* Called by the CLI dispatch after `runGrader`.
|
|
135
|
+
*/
|
|
136
|
+
export function buildComplianceRows(input) {
|
|
137
|
+
const ts = Date.now();
|
|
138
|
+
const { violations, phase, parentSha, repo, bkitVersion, extra } = input;
|
|
139
|
+
const violationByRule = new Map();
|
|
140
|
+
for (const v of violations) {
|
|
141
|
+
violationByRule.set(v.ruleId, v);
|
|
142
|
+
}
|
|
143
|
+
const ALL_RULES = ["no-mirror-edit", "skip-ci-not-head"];
|
|
144
|
+
const rows = [];
|
|
145
|
+
for (const ruleId of ALL_RULES) {
|
|
146
|
+
const violation = violationByRule.get(ruleId);
|
|
147
|
+
const result = violation != null ? violation.result : "pass";
|
|
148
|
+
const evidence = violation?.evidence;
|
|
149
|
+
const envelope = {
|
|
150
|
+
ts: ts + rows.length, // micro-offset so each row has a unique ts within the batch
|
|
151
|
+
kind: "compliance",
|
|
152
|
+
repo,
|
|
153
|
+
bkitVersion,
|
|
154
|
+
workflow: phase,
|
|
155
|
+
step: "close-gate",
|
|
156
|
+
...(extra ?? {}),
|
|
157
|
+
};
|
|
158
|
+
const payload = {
|
|
159
|
+
rule: ruleId,
|
|
160
|
+
result,
|
|
161
|
+
...(evidence != null ? { evidence } : {}),
|
|
162
|
+
phase,
|
|
163
|
+
parentSha,
|
|
164
|
+
};
|
|
165
|
+
rows.push({ ...envelope, ...payload });
|
|
166
|
+
}
|
|
167
|
+
return rows;
|
|
168
|
+
}
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
// Append helper — writes rows to .bkit/stats.jsonl (best-effort)
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
/**
|
|
173
|
+
* Append compliance rows to the stats ledger.
|
|
174
|
+
* Best-effort: prints `[bkit-comply] append failed: …` on error, never throws.
|
|
175
|
+
*/
|
|
176
|
+
export function appendComplianceRows(rows, statsPath) {
|
|
177
|
+
try {
|
|
178
|
+
const ndjson = rows.map((r) => JSON.stringify(r)).join("\n") + "\n";
|
|
179
|
+
fs.appendFileSync(statsPath, ndjson, "utf8");
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
183
|
+
console.error(`[bkit-comply] append failed: ${statsPath} — ${msg}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
// One grading pass, as `bkit workflows close` runs it before its report
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
/**
|
|
190
|
+
* Grade `phase` over HEAD~1..HEAD (HEAD alone in a one-commit repo) and append
|
|
191
|
+
* its compliance rows to `<cwd>/.bkit/stats.jsonl`. Fail-open: any error is
|
|
192
|
+
* logged and returns null, so a close never stops on the grader.
|
|
193
|
+
*/
|
|
194
|
+
export function gradeCompliance(cwd, phase, log) {
|
|
195
|
+
try {
|
|
196
|
+
const parentSha = resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
|
|
197
|
+
if (!parentSha) {
|
|
198
|
+
log("[bkit-comply] cannot resolve a parent SHA (no commits?) — skipping grade");
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const violations = runGrader({ parentSha, phase, cwd });
|
|
202
|
+
const rows = buildComplianceRows({
|
|
203
|
+
violations,
|
|
204
|
+
phase,
|
|
205
|
+
parentSha,
|
|
206
|
+
repo: resolveRepoSlug(cwd) || "unknown/repo",
|
|
207
|
+
bkitVersion: readBkitVersion(),
|
|
208
|
+
});
|
|
209
|
+
appendComplianceRows(rows, path.join(cwd, ".bkit", "stats.jsonl"));
|
|
210
|
+
log(violations.length > 0
|
|
211
|
+
? `[bkit-comply] Compliance violations found:\n${formatComplianceSummary(violations)}`
|
|
212
|
+
: "[bkit-comply] All rules pass.");
|
|
213
|
+
return violations;
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
// Fail-open: the grader is advisory and never gates a close.
|
|
217
|
+
log(`[bkit-comply] grader error (fail-open): ${err.message}`);
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// ---------------------------------------------------------------------------
|
|
222
|
+
// Summarise violations for surfacing in ship-summary.md
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
/**
|
|
225
|
+
* Format a human-readable compliance summary block for inclusion in
|
|
226
|
+
* ship-summary.md. Empty string when all rules pass.
|
|
227
|
+
*/
|
|
228
|
+
export function formatComplianceSummary(violations) {
|
|
229
|
+
if (violations.length === 0)
|
|
230
|
+
return "";
|
|
231
|
+
const lines = [
|
|
232
|
+
"## Compliance Violations",
|
|
233
|
+
"",
|
|
234
|
+
...violations.map((v) => `- **${v.ruleId}** (${v.result}): ${v.description}\n Evidence: ${v.evidence}`),
|
|
235
|
+
"",
|
|
236
|
+
"_Advisory — these violations are recorded in `.bkit/stats.jsonl` and do NOT block the workflow._",
|
|
237
|
+
];
|
|
238
|
+
return lines.join("\n");
|
|
239
|
+
}
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// bkitVersion reader (used by CLI dispatch and tests)
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
/**
|
|
244
|
+
* Read the bkit version from the package.json nearest to `searchFrom` (default: the
|
|
245
|
+
* running bkit package's root). Returns "0.0.0" on any read/parse error (fail-open).
|
|
246
|
+
*/
|
|
247
|
+
export function readBkitVersion(searchFrom) {
|
|
248
|
+
try {
|
|
249
|
+
// Walk up looking for a package.json with a `version` field; stop at the filesystem root.
|
|
250
|
+
let dir = path.resolve(searchFrom ?? getPkgRoot());
|
|
251
|
+
for (let i = 0; i < 8; i++) {
|
|
252
|
+
const candidate = path.join(dir, "package.json");
|
|
253
|
+
if (fs.existsSync(candidate)) {
|
|
254
|
+
const pkg = JSON.parse(fs.readFileSync(candidate, "utf8"));
|
|
255
|
+
if (typeof pkg.version === "string")
|
|
256
|
+
return pkg.version;
|
|
257
|
+
}
|
|
258
|
+
const parent = path.dirname(dir);
|
|
259
|
+
if (parent === dir)
|
|
260
|
+
break;
|
|
261
|
+
dir = parent;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (_e) {
|
|
265
|
+
void _e; // fail-open: version read errors return default
|
|
266
|
+
}
|
|
267
|
+
return "0.0.0";
|
|
268
|
+
}
|
|
269
|
+
// comply — compliance grader (advisory, never gating, fail-open).
|
|
270
|
+
// Runs `runGrader` over `git diff parentSha..HEAD`, appends `kind:"compliance"`
|
|
271
|
+
// rows to `.bkit/stats.jsonl`, and logs violations. Always exits 0 (fail-open);
|
|
272
|
+
// callers MUST use the pinned idiom:
|
|
273
|
+
// `pnpm bkit comply --phase=<phase> || echo "[bkit-comply] grader unavailable, skipping"`
|
|
274
|
+
// See DE-34 for the shared-entrypoint + crash-isolation contract.
|
|
275
|
+
export function runComplyCommand(complyPhase) {
|
|
276
|
+
try {
|
|
277
|
+
const cwd = process.cwd();
|
|
278
|
+
const phase = complyPhase ?? "unknown";
|
|
279
|
+
const logPrefix = "[bkit-comply]";
|
|
280
|
+
// parentSha MUST be a resolved hex SHA: diffPaths returns [] for anything not
|
|
281
|
+
// matching /^[0-9a-f]{7,40}$/, and parentSha is part of the compliance identity().
|
|
282
|
+
// Resolves HEAD~1, else HEAD; neither → skip the grade.
|
|
283
|
+
const statsPath = path.join(cwd, ".bkit", "stats.jsonl");
|
|
284
|
+
const parentSha = resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
|
|
285
|
+
if (!parentSha) {
|
|
286
|
+
console.log(`${logPrefix} cannot resolve a parent SHA (no commits?) — skipping grade`);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
console.log(`${logPrefix} Running compliance grader (phase=${phase}, parentSha=${parentSha})`);
|
|
290
|
+
const violations = runGrader({ parentSha, phase, cwd });
|
|
291
|
+
// The origin remote's owner/repo, the same slug every other telemetry writer uses.
|
|
292
|
+
const repo = resolveRepoSlug(cwd) || "unknown/repo";
|
|
293
|
+
const bkitVersion = readBkitVersion();
|
|
294
|
+
const rows = buildComplianceRows({ violations, phase, parentSha, repo, bkitVersion });
|
|
295
|
+
appendComplianceRows(rows, statsPath);
|
|
296
|
+
if (violations.length > 0) {
|
|
297
|
+
const summary = formatComplianceSummary(violations);
|
|
298
|
+
console.log(`${logPrefix} Compliance violations found:\n${summary}`);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
console.log(`${logPrefix} All rules pass.`);
|
|
302
|
+
}
|
|
303
|
+
console.log(`${logPrefix} Appended ${rows.length} compliance row(s) to .bkit/stats.jsonl (advisory — not gating).`);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
// Fail-open: any unexpected error in the dispatch body must not gate the workflow.
|
|
307
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
308
|
+
console.error(`[bkit-comply] grader error (fail-open): ${msg}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// commands/harvest.ts — Cross-repo harvest CLI.
|
|
2
|
+
//
|
|
3
|
+
// MOVES consumer `.bkit/friction.jsonl` and COPIES `.bkit/stats.jsonl` into bkit's
|
|
4
|
+
// central store at `harvest/`. COUNT-ONLY aggregates `docs/{deferrals,failures}.jsonl`
|
|
5
|
+
// (dimensional counts from envelope metadata; prose NOT copied). Deduplicates by
|
|
6
|
+
// row content; entity counts fold by per-kind composite identity.
|
|
7
|
+
//
|
|
8
|
+
// INVARIANTS (PII guard + move/copy contract):
|
|
9
|
+
// - Touches ONLY the named .jsonl ledgers — never any .env/secret files.
|
|
10
|
+
// - NEVER commits in any repo (bkit's or a consumer's) — the caller commits.
|
|
11
|
+
// - stats.jsonl is COPY-ONLY: consumer mtime + content unchanged.
|
|
12
|
+
// - friction.jsonl is MOVE: harvested rows are pruned from the consumer, but ONLY
|
|
13
|
+
// after that exact row is durably fsync'd + read back from the central store.
|
|
14
|
+
// - The prune gate is byte-for-byte CONTENT, never identity.
|
|
15
|
+
// - The central store ACCUMULATES across runs (never cleared) and holds every
|
|
16
|
+
// DISTINCT row, deduped by content only. It is never rewritten from the fold. It is
|
|
17
|
+
// the only record of pruned consumer friction until the caller commits it; readers
|
|
18
|
+
// fold it.
|
|
19
|
+
// - Malformed consumer lines are NEVER pruned (not ours to delete).
|
|
20
|
+
// - Grep-able [bkit-harvest] log lines.
|
|
21
|
+
// - Relies on the tolerant `parse` for half-written tails.
|
|
22
|
+
//
|
|
23
|
+
// Friction is moved, not copied: consumers start each cycle clean. Ordering is
|
|
24
|
+
// copy -> fsync -> verify -> prune; a crash at any point re-copies idempotently on the
|
|
25
|
+
// next run.
|
|
26
|
+
//
|
|
27
|
+
// Consumers are listed in `docs/consumers.md` (one absolute path per line).
|
|
28
|
+
// See DE-34 for the shared-entrypoint + crash-isolation contract.
|
|
29
|
+
import * as fs from "node:fs";
|
|
30
|
+
import * as path from "node:path";
|
|
31
|
+
import { fold, parse, resolveRepoSlug, } from "../ledgers/telemetry.js";
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Constants
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/** Files to COPY from each consumer's `.bkit/` directory (content + dedup). */
|
|
36
|
+
export const HARVEST_COPY_FILES = ["stats.jsonl", "friction.jsonl"];
|
|
37
|
+
/**
|
|
38
|
+
* Files PRUNED from the consumer after their rows are durably in the central store.
|
|
39
|
+
* Must be a subset of HARVEST_COPY_FILES. `stats.jsonl` is absent: it is copied, never
|
|
40
|
+
* moved.
|
|
41
|
+
*/
|
|
42
|
+
export const HARVEST_PRUNE_FILES = ["friction.jsonl"];
|
|
43
|
+
/** Files to COUNT-ONLY from each consumer's `docs/` directory (metadata only). */
|
|
44
|
+
export const HARVEST_COUNT_FILES = ["deferrals.jsonl", "failures.jsonl"];
|
|
45
|
+
/** Path (relative to bkit repo root) for the consumers list. */
|
|
46
|
+
export const CONSUMERS_FILE = "docs/consumers.md";
|
|
47
|
+
/**
|
|
48
|
+
* Destination directory in bkit for harvested data. Repo root, NOT under `.bkit/`
|
|
49
|
+
* (bkit's managed/installed surface).
|
|
50
|
+
*/
|
|
51
|
+
export const HARVEST_DEST_DIR = "harvest";
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Read consumer list from `docs/consumers.md`
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
/**
|
|
56
|
+
* Read the list of consumer repo root paths from `docs/consumers.md`.
|
|
57
|
+
* Returns an array of absolute paths (non-empty lines, comments stripped).
|
|
58
|
+
*/
|
|
59
|
+
export function readConsumerPaths(bkitRoot) {
|
|
60
|
+
const consumersFile = path.join(bkitRoot, CONSUMERS_FILE);
|
|
61
|
+
if (!fs.existsSync(consumersFile)) {
|
|
62
|
+
console.error(`[bkit-harvest] consumers file not found: ${consumersFile}`);
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
const raw = fs.readFileSync(consumersFile, "utf-8");
|
|
66
|
+
return raw
|
|
67
|
+
.split("\n")
|
|
68
|
+
.map((line) => line.trim())
|
|
69
|
+
.filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
70
|
+
}
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Harvest a single consumer
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
/**
|
|
75
|
+
* Harvest one consumer's `.bkit/{stats,friction}.jsonl` (COPY) and
|
|
76
|
+
* `docs/{deferrals,failures}.jsonl` (COUNT-ONLY).
|
|
77
|
+
* NEVER writes to the consumer repo.
|
|
78
|
+
*/
|
|
79
|
+
export function harvestConsumer(consumerPath, bkitRoot) {
|
|
80
|
+
const result = {
|
|
81
|
+
consumerPath,
|
|
82
|
+
copiedRows: 0,
|
|
83
|
+
countOnlyRows: {},
|
|
84
|
+
countOnlyRawRows: {},
|
|
85
|
+
malformedLineCount: 0,
|
|
86
|
+
skipped: false,
|
|
87
|
+
prunedRows: {},
|
|
88
|
+
};
|
|
89
|
+
if (!fs.existsSync(consumerPath)) {
|
|
90
|
+
result.skipped = true;
|
|
91
|
+
result.skipReason = `consumer path not found: ${consumerPath}`;
|
|
92
|
+
console.error(`[bkit-harvest] SKIP ${consumerPath} — path not found`);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
const destDir = path.join(bkitRoot, HARVEST_DEST_DIR);
|
|
96
|
+
if (!fs.existsSync(destDir)) {
|
|
97
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
98
|
+
}
|
|
99
|
+
// COPY: .bkit/{stats,friction}.jsonl
|
|
100
|
+
for (const filename of HARVEST_COPY_FILES) {
|
|
101
|
+
const srcPath = path.join(consumerPath, ".bkit", filename);
|
|
102
|
+
if (!fs.existsSync(srcPath)) {
|
|
103
|
+
console.error(`[bkit-harvest] ${consumerPath}/.bkit/${filename} — not found, skipping`);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// Record mtime BEFORE reading (copy-only invariant verification support)
|
|
107
|
+
const statBefore = fs.statSync(srcPath);
|
|
108
|
+
const raw = fs.readFileSync(srcPath, "utf-8");
|
|
109
|
+
const statAfter = fs.statSync(srcPath);
|
|
110
|
+
// Verify consumer file was not modified by our read (should always hold)
|
|
111
|
+
if (statBefore.mtimeMs !== statAfter.mtimeMs) {
|
|
112
|
+
console.error(`[bkit-harvest] WARNING: ${srcPath} mtime changed during read — harvest continues but data may be inconsistent`);
|
|
113
|
+
}
|
|
114
|
+
const parsed = parse(raw);
|
|
115
|
+
result.copiedRows += parsed.events.length;
|
|
116
|
+
result.malformedLineCount += parsed.malformedLineCount;
|
|
117
|
+
// Stamp repo on each event if missing
|
|
118
|
+
const consumerSlug = consumerPathToSlug(consumerPath);
|
|
119
|
+
const stamped = parsed.events.map((ev) => stampRepo(ev, consumerSlug));
|
|
120
|
+
// Write to harvest dest (append)
|
|
121
|
+
const destPath = path.join(destDir, filename);
|
|
122
|
+
for (const ev of stamped) {
|
|
123
|
+
fs.appendFileSync(destPath, JSON.stringify(ev) + "\n", "utf-8");
|
|
124
|
+
}
|
|
125
|
+
console.error(`[bkit-harvest] ${consumerPath}/.bkit/${filename} — copied ${parsed.events.length} rows (malformed: ${parsed.malformedLineCount})`);
|
|
126
|
+
}
|
|
127
|
+
// COUNT-ONLY: docs/{deferrals,failures}.jsonl
|
|
128
|
+
for (const filename of HARVEST_COUNT_FILES) {
|
|
129
|
+
const srcPath = path.join(consumerPath, "docs", filename);
|
|
130
|
+
if (!fs.existsSync(srcPath)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const raw = fs.readFileSync(srcPath, "utf-8");
|
|
134
|
+
const parsed = parse(raw);
|
|
135
|
+
// Count ENTITIES, not lines: updating a deferral appends a new same-key row, and
|
|
136
|
+
// `fold` collapses same-key rows to the current state. See .bkit/jsonl.md § Updating
|
|
137
|
+
// a Row.
|
|
138
|
+
const folded = fold(parsed.events);
|
|
139
|
+
result.countOnlyRows[filename] = folded.size;
|
|
140
|
+
result.countOnlyRawRows[filename] = parsed.events.length;
|
|
141
|
+
result.malformedLineCount += parsed.malformedLineCount;
|
|
142
|
+
console.error(`[bkit-harvest] ${consumerPath}/docs/${filename} — count-only: ${folded.size} entities (${parsed.events.length} rows)`);
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
// Prune — remove durably-stored rows from a consumer ledger
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
/**
|
|
150
|
+
* Stamp `repo` on an event when the consumer wrote the row without one.
|
|
151
|
+
* MUST be applied on both the store side and the prune side, or the two contents
|
|
152
|
+
* diverge and a stored row is never recognised as prunable.
|
|
153
|
+
*/
|
|
154
|
+
export function stampRepo(event, consumerSlug) {
|
|
155
|
+
return {
|
|
156
|
+
...event,
|
|
157
|
+
repo: event.repo && event.repo.length > 0 ? event.repo : consumerSlug,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Remove from `srcPath` exactly those rows whose CONTENT is durably in the store.
|
|
162
|
+
*
|
|
163
|
+
* Gated on byte-for-byte content, NOT on identity.
|
|
164
|
+
*
|
|
165
|
+
* Line-level, NOT event-level: a line that does not parse is kept verbatim.
|
|
166
|
+
*
|
|
167
|
+
* Re-reads the file at prune time, so rows appended by the consumer DURING the harvest
|
|
168
|
+
* survive.
|
|
169
|
+
*
|
|
170
|
+
* Writes via temp-file + rename; an interrupted prune never leaves a torn ledger.
|
|
171
|
+
*/
|
|
172
|
+
export function pruneConsumerFile(srcPath, consumerSlug, durable) {
|
|
173
|
+
const raw = fs.readFileSync(srcPath, "utf-8");
|
|
174
|
+
const kept = [];
|
|
175
|
+
let removed = 0;
|
|
176
|
+
for (const line of raw.split("\n")) {
|
|
177
|
+
if (line.trim() === "")
|
|
178
|
+
continue;
|
|
179
|
+
let event;
|
|
180
|
+
try {
|
|
181
|
+
event = JSON.parse(line.trim());
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
kept.push(line); // malformed — never ours to delete
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (durable.rows.has(canonicalRow(stampRepo(event, consumerSlug)))) {
|
|
188
|
+
removed++;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
kept.push(line);
|
|
192
|
+
}
|
|
193
|
+
if (removed === 0)
|
|
194
|
+
return { removed: 0, kept: kept.length };
|
|
195
|
+
const next = kept.length > 0 ? kept.join("\n") + "\n" : "";
|
|
196
|
+
const tmpPath = `${srcPath}.bkit-harvest.tmp`;
|
|
197
|
+
fs.writeFileSync(tmpPath, next, "utf-8");
|
|
198
|
+
fs.renameSync(tmpPath, srcPath);
|
|
199
|
+
return { removed, kept: kept.length };
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Canonical serialisation used to compare a consumer row against a stored row.
|
|
203
|
+
* Safe as a plain `JSON.stringify`: the store was written from exactly this function's
|
|
204
|
+
* output, and a JSON.parse -> JSON.stringify round-trip preserves key order, so the
|
|
205
|
+
* store's own rewrite is byte-stable.
|
|
206
|
+
*/
|
|
207
|
+
function canonicalRow(event) {
|
|
208
|
+
return JSON.stringify(event);
|
|
209
|
+
}
|
|
210
|
+
/** fsync a file to disk, so a durability check is not just a page-cache read. */
|
|
211
|
+
function fsyncFile(filePath) {
|
|
212
|
+
const fd = fs.openSync(filePath, "r+");
|
|
213
|
+
try {
|
|
214
|
+
fs.fsyncSync(fd);
|
|
215
|
+
}
|
|
216
|
+
finally {
|
|
217
|
+
fs.closeSync(fd);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// ---------------------------------------------------------------------------
|
|
221
|
+
// Run harvest across all consumers
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
/**
|
|
224
|
+
* Run harvest across all consumers listed in `docs/consumers.md`.
|
|
225
|
+
* Deduplicates the store by row content after collecting all rows.
|
|
226
|
+
*/
|
|
227
|
+
export function runHarvest(bkitRoot) {
|
|
228
|
+
const consumerPaths = readConsumerPaths(bkitRoot);
|
|
229
|
+
console.error(`[bkit-harvest] Found ${consumerPaths.length} consumer(s) in ${CONSUMERS_FILE}`);
|
|
230
|
+
const consumerResults = [];
|
|
231
|
+
let totalCopied = 0;
|
|
232
|
+
const totalCountOnly = {};
|
|
233
|
+
// The central store ACCUMULATES — it is NEVER cleared between runs. Re-copied rows
|
|
234
|
+
// collapse via the content dedup below.
|
|
235
|
+
const destDir = path.join(bkitRoot, HARVEST_DEST_DIR);
|
|
236
|
+
for (const consumerPath of consumerPaths) {
|
|
237
|
+
console.error(`[bkit-harvest] Harvesting: ${consumerPath}`);
|
|
238
|
+
const res = harvestConsumer(consumerPath, bkitRoot);
|
|
239
|
+
consumerResults.push(res);
|
|
240
|
+
if (!res.skipped) {
|
|
241
|
+
totalCopied += res.copiedRows;
|
|
242
|
+
for (const [k, v] of Object.entries(res.countOnlyRows)) {
|
|
243
|
+
totalCountOnly[k] = (totalCountOnly[k] ?? 0) + v;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Deduplicate by content: drop exact re-copies, keep every distinct row in first-seen
|
|
248
|
+
// order. Entity counts come from the fold, which is a read — never what is written.
|
|
249
|
+
let mergedState = new Map();
|
|
250
|
+
let dedupedRows = 0;
|
|
251
|
+
/** Per-file durable content read BACK OFF DISK — the prune gate. */
|
|
252
|
+
const durableByFile = {};
|
|
253
|
+
for (const filename of HARVEST_COPY_FILES) {
|
|
254
|
+
const destPath = path.join(destDir, filename);
|
|
255
|
+
if (!fs.existsSync(destPath))
|
|
256
|
+
continue;
|
|
257
|
+
const raw = fs.readFileSync(destPath, "utf-8");
|
|
258
|
+
const parsed = parse(raw);
|
|
259
|
+
const folded = fold(parsed.events);
|
|
260
|
+
mergedState = new Map([...mergedState, ...folded]);
|
|
261
|
+
dedupedRows += folded.size;
|
|
262
|
+
const distinctLines = [...new Set(parsed.events.map((ev) => canonicalRow(ev)))].join("\n");
|
|
263
|
+
fs.writeFileSync(destPath, distinctLines + (distinctLines.length > 0 ? "\n" : ""), "utf-8");
|
|
264
|
+
// Durability gate: fsync, then read the rows BACK OFF DISK; prune against those.
|
|
265
|
+
fsyncFile(destPath);
|
|
266
|
+
const verified = parse(fs.readFileSync(destPath, "utf-8"));
|
|
267
|
+
durableByFile[filename] = {
|
|
268
|
+
rows: new Set(verified.events.map((ev) => canonicalRow(ev))),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
// Prune ONLY now — every row below is confirmed byte-for-byte in the store on disk.
|
|
272
|
+
let totalPruned = 0;
|
|
273
|
+
let totalKept = 0;
|
|
274
|
+
for (const res of consumerResults) {
|
|
275
|
+
if (res.skipped)
|
|
276
|
+
continue;
|
|
277
|
+
const consumerSlug = consumerPathToSlug(res.consumerPath);
|
|
278
|
+
for (const filename of HARVEST_PRUNE_FILES) {
|
|
279
|
+
const srcPath = path.join(res.consumerPath, ".bkit", filename);
|
|
280
|
+
if (!fs.existsSync(srcPath))
|
|
281
|
+
continue;
|
|
282
|
+
const durable = durableByFile[filename];
|
|
283
|
+
if (!durable || durable.rows.size === 0)
|
|
284
|
+
continue;
|
|
285
|
+
const { removed, kept } = pruneConsumerFile(srcPath, consumerSlug, durable);
|
|
286
|
+
if (removed > 0) {
|
|
287
|
+
res.prunedRows[filename] = removed;
|
|
288
|
+
totalPruned += removed;
|
|
289
|
+
console.error(`[bkit-harvest] ${res.consumerPath}/.bkit/${filename} — pruned ${removed} harvested row(s)`);
|
|
290
|
+
}
|
|
291
|
+
if (kept > 0) {
|
|
292
|
+
totalKept += kept;
|
|
293
|
+
console.error(`[bkit-harvest] ${res.consumerPath}/.bkit/${filename} — kept ${kept} line(s) not in the store (malformed, or appended after the copy)`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
console.error(`[bkit-harvest] Done — total rows collected: ${totalCopied}, entities after fold: ${dedupedRows}, pruned from consumers: ${totalPruned}, kept in consumers: ${totalKept}`);
|
|
298
|
+
if (totalPruned > 0) {
|
|
299
|
+
console.error(`[bkit-harvest] ${totalPruned} row(s) now exist ONLY in ${HARVEST_DEST_DIR}/ — commit it to make them durable.`);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
consumers: consumerResults,
|
|
303
|
+
totalCopiedRows: totalCopied,
|
|
304
|
+
totalCountOnly,
|
|
305
|
+
dedupedRows,
|
|
306
|
+
totalPrunedRows: totalPruned,
|
|
307
|
+
mergedState,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
// ---------------------------------------------------------------------------
|
|
311
|
+
// Helpers
|
|
312
|
+
// ---------------------------------------------------------------------------
|
|
313
|
+
/** Convert an absolute consumer path to a repo slug for stamping. */
|
|
314
|
+
export function consumerPathToSlug(consumerPath) {
|
|
315
|
+
// The consumer's OWN git remote — the only authoritative source.
|
|
316
|
+
const slug = resolveRepoSlug(consumerPath);
|
|
317
|
+
if (slug)
|
|
318
|
+
return slug;
|
|
319
|
+
// Last resort, and loud: a remote-less consumer still harvests.
|
|
320
|
+
const parts = consumerPath
|
|
321
|
+
.replace(/\/+$/, "")
|
|
322
|
+
.split("/")
|
|
323
|
+
.filter((p) => p.length > 0);
|
|
324
|
+
const fallback = parts[parts.length - 1] ?? consumerPath;
|
|
325
|
+
console.error(`[bkit-harvest] no git remote at ${consumerPath} — falling back to path-derived slug "${fallback}". ` +
|
|
326
|
+
`This is NOT an owner/repo slug and will not join rows from the same repo harvested elsewhere.`);
|
|
327
|
+
return fallback;
|
|
328
|
+
}
|
|
329
|
+
// harvest — cross-repo harvest CLI.
|
|
330
|
+
// Copies consumer .bkit/stats.jsonl and MOVES .bkit/friction.jsonl into harvest/;
|
|
331
|
+
// COUNT-ONLY for docs/{deferrals,failures}.jsonl. Friction rows are pruned from the
|
|
332
|
+
// consumer only after they are fsync'd + read back from the store. Fail-open: exits 0.
|
|
333
|
+
// See DE-34 for the shared-entrypoint + crash-isolation contract.
|
|
334
|
+
export function runHarvestCommand() {
|
|
335
|
+
try {
|
|
336
|
+
const cwd = process.cwd();
|
|
337
|
+
console.log("[bkit-harvest] Starting cross-repo harvest...");
|
|
338
|
+
const result = runHarvest(cwd);
|
|
339
|
+
console.log(`[bkit-harvest] Harvest complete — consumers: ${result.consumers.length}, rows copied: ${result.totalCopiedRows}, entities after fold: ${result.dedupedRows}, pruned from consumers: ${result.totalPrunedRows}`);
|
|
340
|
+
const countOnlyEntries = Object.entries(result.totalCountOnly);
|
|
341
|
+
if (countOnlyEntries.length > 0) {
|
|
342
|
+
for (const [file, count] of countOnlyEntries) {
|
|
343
|
+
console.log(`[bkit-harvest] count-only ${file}: ${count} rows (not copied)`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (result.totalPrunedRows > 0) {
|
|
347
|
+
console.log(`[bkit-harvest] ${result.totalPrunedRows} friction row(s) were REMOVED from consumers and now exist only in ${HARVEST_DEST_DIR}/ — commit it.`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch (err) {
|
|
351
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
352
|
+
console.error(`[bkit-harvest] harvest error (fail-open): ${msg}`);
|
|
353
|
+
}
|
|
354
|
+
}
|