@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,236 @@
|
|
|
1
|
+
# Example. Copy into the repo and own it.
|
|
2
|
+
# bkit install does not write this file and does not overwrite a copy.
|
|
3
|
+
# Adapt app roots, the workspace package scope, and the rules JSON to this repo.
|
|
4
|
+
|
|
5
|
+
#!/usr/bin/env python3
|
|
6
|
+
"""Find modules that do work when they are imported, and count who pays for it.
|
|
7
|
+
|
|
8
|
+
Called by `pnpm graph:rollup` (scripts/graphify/bkit-graphify.sh). Writes a JSON that
|
|
9
|
+
bkit-graphify-rollup.py renders as the import-time side-effect table in
|
|
10
|
+
docs/capabilities.md.
|
|
11
|
+
|
|
12
|
+
bkit-graph-eager.py <graph.json> <eager-out.json> [--rules R] [--quiet]
|
|
13
|
+
|
|
14
|
+
THE THING BEING LOOKED FOR. A call that runs at module scope runs on *import*,
|
|
15
|
+
not on first use, so every file that transitively imports it pays whatever that
|
|
16
|
+
call costs.
|
|
17
|
+
|
|
18
|
+
DETECTION reads source: graphify emits no node for a call in a module-level
|
|
19
|
+
initialiser expression. The DOWNSTREAM count uses graph.json's transitive inbound
|
|
20
|
+
imports.
|
|
21
|
+
|
|
22
|
+
HOW MODULE SCOPE IS DECIDED — a line counts only when both filters hold:
|
|
23
|
+
|
|
24
|
+
1. the line is OUTSIDE every callable's line range, taken from graph.json.
|
|
25
|
+
A `_callable` node's range runs from its line to the next symbol's line in
|
|
26
|
+
the same file — the same symbol-attribution trick bkit-graph-surface.py uses.
|
|
27
|
+
2. the line starts at column 0 (Prettier indents anything nested inside a
|
|
28
|
+
callback body, including an anonymous arrow graphify emitted no node for).
|
|
29
|
+
|
|
30
|
+
A file with no nodes in graph.json at all — newer than the graph, or never
|
|
31
|
+
extracted — keeps filter 2 and loses filter 1. Those rows are marked
|
|
32
|
+
`in_graph: false` and counted in the summary, never dropped.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
import argparse
|
|
36
|
+
import collections
|
|
37
|
+
import json
|
|
38
|
+
import os
|
|
39
|
+
import re
|
|
40
|
+
import sys
|
|
41
|
+
|
|
42
|
+
# bkit-graph-imports.py is hyphenated, which `import` cannot spell, so it is loaded
|
|
43
|
+
# by path.
|
|
44
|
+
import importlib.util as _ilu
|
|
45
|
+
_spec = _ilu.spec_from_file_location(
|
|
46
|
+
"graph_imports",
|
|
47
|
+
os.path.join(os.path.dirname(os.path.abspath(__file__)), "bkit-graph-imports.py"))
|
|
48
|
+
graph_imports = _ilu.module_from_spec(_spec)
|
|
49
|
+
_spec.loader.exec_module(graph_imports)
|
|
50
|
+
|
|
51
|
+
SRC = (".ts", ".tsx")
|
|
52
|
+
SKIP_DIR = {"node_modules", "dist", ".next", ".turbo", "coverage", "build", ".git",
|
|
53
|
+
".worktrees", "docs"}
|
|
54
|
+
# *.config.ts and *.setup.ts are harness bootstrap (import-time work is their job).
|
|
55
|
+
# `.test-d.` is a type-level test and needs listing separately: it does not
|
|
56
|
+
# contain `.test.`, so the ordinary test filter walks straight past it.
|
|
57
|
+
# Test files are excluded as sources but kept as downstream consumers: a stub in
|
|
58
|
+
# a test is the cost being measured, never a finding in its own right.
|
|
59
|
+
SKIP_FILE = (".test.", ".test-d.", ".spec.", ".d.ts", ".config.", ".setup.")
|
|
60
|
+
ROOTS = ("apps", "packages")
|
|
61
|
+
IS_TEST = re.compile(r"\.test\.|\.spec\.|/__tests__/|/e2e/")
|
|
62
|
+
|
|
63
|
+
# Statement keywords and test-harness callables that a bare-call regex would
|
|
64
|
+
# otherwise read as a callee. Matched on the FIRST segment, so the modifier
|
|
65
|
+
# forms come along for free — `describe.skipIf`, `it.each`, `vi.mock`.
|
|
66
|
+
NOT_A_CALLEE = {
|
|
67
|
+
"if", "for", "while", "switch", "catch", "return", "function", "require",
|
|
68
|
+
"import", "export", "typeof", "new", "await", "yield", "delete", "void",
|
|
69
|
+
"describe", "it", "test", "expect", "jest", "vi",
|
|
70
|
+
"beforeAll", "afterAll", "beforeEach", "afterEach",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# Either `const x = callee(` / `export const x = new Callee(` or a bare `callee(`
|
|
74
|
+
# statement. Anchored at column 0 by the caller, so this never has to model
|
|
75
|
+
# indentation itself.
|
|
76
|
+
CALL = re.compile(
|
|
77
|
+
r"^(?:export\s+)?(?:const|let|var)\s+[^=;]+=\s*(?:await\s+)?(?:new\s+)?"
|
|
78
|
+
r"([A-Za-z_$][\w$]*(?:\.[\w$]+)*)\s*\("
|
|
79
|
+
r"|^(?:await\s+)?(?:new\s+)?([A-Za-z_$][\w$]*(?:\.[\w$]+)*)\s*\("
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# Only these relations are a dependency; `contains` (structural nesting) and
|
|
83
|
+
# `indirect_call` (a name-matching heuristic) are not.
|
|
84
|
+
DEP_RELATIONS = {"imports", "imports_from", "re_exports", "dynamic_import"}
|
|
85
|
+
|
|
86
|
+
ap = argparse.ArgumentParser()
|
|
87
|
+
ap.add_argument("graph_json")
|
|
88
|
+
ap.add_argument("eager_out")
|
|
89
|
+
ap.add_argument("--rules", default="scripts/graphify/bkit-graph-eager-rules.json")
|
|
90
|
+
ap.add_argument("--quiet", action="store_true")
|
|
91
|
+
args = ap.parse_args()
|
|
92
|
+
|
|
93
|
+
rules = json.load(open(args.rules))
|
|
94
|
+
PURE = set(rules.get("pure", []))
|
|
95
|
+
PURE_PREFIXES = tuple(rules.get("pure_prefixes", []))
|
|
96
|
+
PURE_METHODS = tuple(rules.get("pure_methods", []))
|
|
97
|
+
PURE_RECEIVERS = set(rules.get("pure_receivers", []))
|
|
98
|
+
MIN_DOWNSTREAM = rules.get("min_downstream", 0)
|
|
99
|
+
|
|
100
|
+
raw = json.load(open(args.graph_json))
|
|
101
|
+
ns = {n["id"]: n for n in raw["nodes"]}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def is_pure(callee):
|
|
105
|
+
return (callee in PURE
|
|
106
|
+
or callee.startswith(PURE_PREFIXES)
|
|
107
|
+
or callee.endswith(PURE_METHODS)
|
|
108
|
+
or callee.rpartition(".")[0] in PURE_RECEIVERS)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# --- module scope, from the graph's symbol table ------------------------------
|
|
112
|
+
# Every symbol's line, per file. A callable owns the lines from its own line up
|
|
113
|
+
# to the next symbol in that file; the last one owns the rest.
|
|
114
|
+
_syms = collections.defaultdict(list)
|
|
115
|
+
for n in raw["nodes"]:
|
|
116
|
+
path = str(n.get("source_file") or "")
|
|
117
|
+
m = re.fullmatch(r"L(\d+)", str(n.get("source_location") or ""))
|
|
118
|
+
if path and m:
|
|
119
|
+
_syms[path].append((int(m.group(1)), bool(n.get("_callable"))))
|
|
120
|
+
|
|
121
|
+
CALLABLE_RANGES = {}
|
|
122
|
+
for path, syms in _syms.items():
|
|
123
|
+
syms.sort()
|
|
124
|
+
lines = [ln for ln, _ in syms]
|
|
125
|
+
CALLABLE_RANGES[path] = [
|
|
126
|
+
(ln, lines[i + 1] - 1 if i + 1 < len(lines) else sys.maxsize)
|
|
127
|
+
for i, (ln, callable_) in enumerate(syms) if callable_
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def inside_callable(path, line):
|
|
132
|
+
return any(a <= line <= b for a, b in CALLABLE_RANGES.get(path, ()))
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# --- who imports this, transitively -------------------------------------------
|
|
136
|
+
# graph.json already carries the ~540 imports graphify cannot resolve — a `.js`
|
|
137
|
+
# specifier never reaching a `.tsx` file, and workspace subpaths through an
|
|
138
|
+
# `exports` map. bkit-graph-repair.py injects them during `pnpm graph`, so they are
|
|
139
|
+
# read here like any other edge; warns if the graph predates that step.
|
|
140
|
+
INBOUND = collections.defaultdict(set)
|
|
141
|
+
for link in raw["links"]:
|
|
142
|
+
if link.get("relation") not in DEP_RELATIONS:
|
|
143
|
+
continue
|
|
144
|
+
src = str(ns.get(link["source"], {}).get("source_file") or "")
|
|
145
|
+
tgt = str(ns.get(link["target"], {}).get("source_file") or "")
|
|
146
|
+
if src and tgt and src != tgt:
|
|
147
|
+
INBOUND[tgt].add(src)
|
|
148
|
+
|
|
149
|
+
REPAIRED = graph_imports.warn_if_unrepaired(raw, "eager")
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def downstream(path):
|
|
153
|
+
"""Every file that reaches `path` through imports, at any depth."""
|
|
154
|
+
seen, stack = set(), [path]
|
|
155
|
+
while stack:
|
|
156
|
+
for parent in INBOUND.get(stack.pop(), ()):
|
|
157
|
+
if parent not in seen:
|
|
158
|
+
seen.add(parent)
|
|
159
|
+
stack.append(parent)
|
|
160
|
+
return seen
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def sources():
|
|
164
|
+
for root in ROOTS:
|
|
165
|
+
for dirpath, dirnames, filenames in os.walk(root):
|
|
166
|
+
dirnames[:] = [d for d in dirnames if d not in SKIP_DIR]
|
|
167
|
+
if "/e2e/" in dirpath + "/" or dirpath.endswith("/e2e"):
|
|
168
|
+
continue
|
|
169
|
+
for f in filenames:
|
|
170
|
+
if f.endswith(SRC) and not any(s in f for s in SKIP_FILE):
|
|
171
|
+
yield os.path.join(dirpath, f)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
scanned = ungraphed = 0
|
|
175
|
+
files = []
|
|
176
|
+
for path in sources():
|
|
177
|
+
scanned += 1
|
|
178
|
+
try:
|
|
179
|
+
text = open(path, encoding="utf-8", errors="ignore").read()
|
|
180
|
+
except OSError:
|
|
181
|
+
continue
|
|
182
|
+
in_graph = path in CALLABLE_RANGES
|
|
183
|
+
ungraphed += not in_graph
|
|
184
|
+
sites = []
|
|
185
|
+
for lineno, line in enumerate(text.split("\n"), 1):
|
|
186
|
+
if not line or line[0] in " \t" or inside_callable(path, lineno):
|
|
187
|
+
continue
|
|
188
|
+
m = CALL.match(line)
|
|
189
|
+
if not m:
|
|
190
|
+
continue
|
|
191
|
+
callee = m.group(1) or m.group(2)
|
|
192
|
+
if callee.partition(".")[0] in NOT_A_CALLEE or is_pure(callee):
|
|
193
|
+
continue
|
|
194
|
+
sites.append({"line": lineno, "callee": callee, "code": line.strip()[:120]})
|
|
195
|
+
if not sites:
|
|
196
|
+
continue
|
|
197
|
+
consumers = downstream(path)
|
|
198
|
+
tests = sorted(c for c in consumers if IS_TEST.search(c))
|
|
199
|
+
files.append({
|
|
200
|
+
"file": path,
|
|
201
|
+
"in_graph": in_graph,
|
|
202
|
+
"callees": sorted({s["callee"] for s in sites}),
|
|
203
|
+
"sites": sites,
|
|
204
|
+
"downstream": len(consumers),
|
|
205
|
+
"downstream_tests": len(tests),
|
|
206
|
+
"tests": tests,
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
# Worst first: reach is the cost, and the callee count only breaks ties.
|
|
210
|
+
files.sort(key=lambda r: (-r["downstream"], -r["downstream_tests"], r["file"]))
|
|
211
|
+
total_sites = sum(len(r["sites"]) for r in files)
|
|
212
|
+
|
|
213
|
+
json.dump({
|
|
214
|
+
"generated_from": args.rules,
|
|
215
|
+
"built_at_commit": raw.get("built_at_commit"),
|
|
216
|
+
"scanned": scanned,
|
|
217
|
+
"not_in_graph": ungraphed,
|
|
218
|
+
"repaired_edges": REPAIRED,
|
|
219
|
+
"min_downstream": MIN_DOWNSTREAM,
|
|
220
|
+
"files": files,
|
|
221
|
+
}, open(args.eager_out, "w"), indent=1)
|
|
222
|
+
|
|
223
|
+
if not args.quiet:
|
|
224
|
+
for r in files[:15]:
|
|
225
|
+
flag = "" if r["in_graph"] else " (not in graph — weaker filter)"
|
|
226
|
+
print(f"[eager] {r['downstream']:4} downstream ({r['downstream_tests']:3} tests) "
|
|
227
|
+
f"{r['file']} {', '.join(r['callees'])}{flag}")
|
|
228
|
+
print(f"[eager] {total_sites} module-scope side effects in {len(files)} of {scanned} files "
|
|
229
|
+
f"— {sum(1 for r in files if r['downstream'] >= MIN_DOWNSTREAM)} with "
|
|
230
|
+
f"{MIN_DOWNSTREAM}+ downstream")
|
|
231
|
+
print(f"[eager] {REPAIRED} of those edges came from bkit-graph-repair.py — imports "
|
|
232
|
+
f"graphify cannot resolve (.js -> .tsx, workspace exports subpaths)")
|
|
233
|
+
if ungraphed:
|
|
234
|
+
print(f"[eager] {ungraphed} scanned files absent from graph.json (column-0 filter only) "
|
|
235
|
+
f"— run 'pnpm graph:update' to close the gap", file=sys.stderr)
|
|
236
|
+
print(f"[eager] wrote {args.eager_out}", file=sys.stderr)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": [
|
|
3
|
+
"Example. Copy into the repo and own it.",
|
|
4
|
+
"bkit install does not write this file and does not overwrite a copy.",
|
|
5
|
+
"External API providers. sdk: import specifiers. env: variable holding a base URL. hosts: literal hostnames.",
|
|
6
|
+
"A provider may declare more than one. A hostname that matches no rule is still reported, named after the host.",
|
|
7
|
+
"Nothing here discovers an SDK on its own. List non-workspace dependencies and add a rule for each service client."
|
|
8
|
+
],
|
|
9
|
+
"providers": [
|
|
10
|
+
{
|
|
11
|
+
"provider": "Example",
|
|
12
|
+
"sdk": ["example-sdk"],
|
|
13
|
+
"hosts": ["api.example.com"],
|
|
14
|
+
"env": []
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# Example. Copy into the repo and own it.
|
|
2
|
+
# bkit install does not write this file and does not overwrite a copy.
|
|
3
|
+
# Adapt app roots, the workspace package scope, and the rules JSON to this repo.
|
|
4
|
+
|
|
5
|
+
"""Recover the import edges graphify does not resolve.
|
|
6
|
+
|
|
7
|
+
Importable module, not a CLI — underscored so `import graph_imports` works from
|
|
8
|
+
the sibling `graph-*.py` scripts, which are standalone and cannot be imported
|
|
9
|
+
themselves.
|
|
10
|
+
|
|
11
|
+
ONE WRITER. `bkit-graph-repair.py` is the only caller of `resolved_import_edges()`;
|
|
12
|
+
it injects the result into graph.json during `pnpm graph`, so `graphify affected` /
|
|
13
|
+
`explain` / `path` / `query` see the same edges these scripts do. bkit-graph-eager.py
|
|
14
|
+
and bkit-graphify-rollup.py call `warn_if_unrepaired()` and otherwise just read the
|
|
15
|
+
graph.
|
|
16
|
+
|
|
17
|
+
Two independent gaps, ~550 edges on this repo.
|
|
18
|
+
|
|
19
|
+
── GAP 1: a `.js` specifier never resolves to a `.tsx` file ──────────────────
|
|
20
|
+
|
|
21
|
+
graphify's `_resolve_js_import_path` (`graphify/extractors/resolution.py:43`)
|
|
22
|
+
maps `.js` to `.ts` and stops:
|
|
23
|
+
|
|
24
|
+
if candidate.suffix == ".js":
|
|
25
|
+
ts_candidate = candidate.with_suffix(".ts") # tries .ts, gives up
|
|
26
|
+
elif candidate.suffix == ".jsx":
|
|
27
|
+
tsx_candidate = candidate.with_suffix(".tsx")
|
|
28
|
+
|
|
29
|
+
TypeScript's order for a `.js` specifier is `.ts` -> `.tsx` -> `.d.ts` -> `.js`.
|
|
30
|
+
A `.tsx` file is imported as `.js`, never `.jsx` — `Foo.tsx` emits to `Foo.js`,
|
|
31
|
+
so `./Foo.js` is the specifier NodeNext requires. The append-extension fallback
|
|
32
|
+
underneath cannot rescue it: it appends to the whole filename, producing
|
|
33
|
+
`MessageBubble.js.tsx`. Confirmed on upstream branch `v8` at 0.9.58, so
|
|
34
|
+
upgrading does not fix it. Reported as Graphify-Labs/graphify#3486.
|
|
35
|
+
|
|
36
|
+
On a repo that imports `.tsx` through `.js` specifiers, most resolve and a
|
|
37
|
+
minority point at `.tsx`. Those are the recovered edges.
|
|
38
|
+
|
|
39
|
+
── GAP 2: workspace subpath imports through an `exports` map ─────────────────
|
|
40
|
+
|
|
41
|
+
`@scope/ui/components/Icon` resolves through that package's `exports`
|
|
42
|
+
map, which graphify does not read. The maps carry three conditions and they
|
|
43
|
+
are NOT interchangeable:
|
|
44
|
+
|
|
45
|
+
"./components/Icon": {
|
|
46
|
+
"types": "./dist/components/Icon.web.d.ts", <- build output, SKIP
|
|
47
|
+
"react-native": "./src/components/Icon.native.tsx", <- what mobile gets
|
|
48
|
+
"default": "./src/components/Icon.web.tsx" <- what web gets
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
`types` always points into `dist/`, which is gitignored and not in the corpus; it
|
|
52
|
+
is skipped.
|
|
53
|
+
|
|
54
|
+
CONDITION CHOICE IS PER IMPORTER, not per package. An importer under apps/mobile
|
|
55
|
+
or named `*.native.*` gets `react-native`; one under apps/web or `*.web.*` gets
|
|
56
|
+
`default`. Where the importer is shared (anything in packages/), both are
|
|
57
|
+
emitted.
|
|
58
|
+
|
|
59
|
+
── SCOPE ────────────────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
Extensionless relative specifiers are left to graphify's own append-extension
|
|
62
|
+
loop. A bare `@scope/services` root import, and a `.js`-suffixed subpath into a
|
|
63
|
+
package with no matching `exports` entry, do not resolve; `unresolved_specifiers()`
|
|
64
|
+
counts them.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
from __future__ import annotations
|
|
68
|
+
|
|
69
|
+
import json
|
|
70
|
+
import os
|
|
71
|
+
import re
|
|
72
|
+
|
|
73
|
+
SRC_EXTS = (".ts", ".tsx")
|
|
74
|
+
SKIP_DIR = {"node_modules", "dist", ".next", ".turbo", "coverage", "build", ".git",
|
|
75
|
+
".worktrees", "docs"}
|
|
76
|
+
DEFAULT_ROOTS = ("apps", "packages")
|
|
77
|
+
MANIFEST_GLOB_DIRS = ("packages", "apps", "tooling")
|
|
78
|
+
|
|
79
|
+
# `from "x"`, `import("x")`, `export ... from "x"`, `require("x")`. Group 1 is
|
|
80
|
+
# any specifier; relative and bare are told apart by the leading dot.
|
|
81
|
+
SPEC = re.compile(r"""(?:from|import|require)\s*\(?\s*["']([^"'\n]+)["']""")
|
|
82
|
+
|
|
83
|
+
# TypeScript rewrites these output extensions back to source when resolving.
|
|
84
|
+
TS_EQUIVALENT = {
|
|
85
|
+
".js": (".ts", ".tsx", ".d.ts"),
|
|
86
|
+
".jsx": (".tsx",),
|
|
87
|
+
".mjs": (".mts", ".mjs"),
|
|
88
|
+
".cjs": (".cts", ".cjs"),
|
|
89
|
+
}
|
|
90
|
+
# Tried after the TypeScript candidates, and every match is kept rather than the
|
|
91
|
+
# first: a platform split has no single answer.
|
|
92
|
+
PLATFORM_SUFFIXES = (".native.tsx", ".web.tsx", ".native.ts", ".web.ts")
|
|
93
|
+
|
|
94
|
+
# `types` is absent — it points into dist/, which is not in the corpus. Order
|
|
95
|
+
# matters only when a single condition is being picked.
|
|
96
|
+
NATIVE_CONDITIONS = ("react-native", "default", "node", "import", "require")
|
|
97
|
+
WEB_CONDITIONS = ("default", "node", "import", "require")
|
|
98
|
+
ALL_CONDITIONS = ("react-native", "default", "node", "import", "require")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
REPAIR_ORIGIN = "graph-repair"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def repair_state(graph):
|
|
105
|
+
"""(edges injected by bkit-graph-repair.py, was the repair run at all).
|
|
106
|
+
|
|
107
|
+
Consumers call this instead of re-deriving the edges themselves.
|
|
108
|
+
|
|
109
|
+
There is no top-level marker to check: `cluster-only` rewrites graph.json
|
|
110
|
+
and drops keys it does not own. The per-link `_origin` survives, so that is
|
|
111
|
+
the signal. A genuinely zero-repair graph reads as unrepaired here.
|
|
112
|
+
"""
|
|
113
|
+
n = sum(1 for l in graph.get("links", ()) if l.get("_origin") == REPAIR_ORIGIN)
|
|
114
|
+
return n, n > 0
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def warn_if_unrepaired(graph, who, stream=None):
|
|
118
|
+
"""Print a loud warning when graph.json has not been through bkit-graph-repair.py.
|
|
119
|
+
|
|
120
|
+
Warns only; never repairs on read.
|
|
121
|
+
"""
|
|
122
|
+
import sys as _sys
|
|
123
|
+
count, ok = repair_state(graph)
|
|
124
|
+
if not ok:
|
|
125
|
+
print(f"[{who}] WARNING: graph.json carries no graph-repair edges. "
|
|
126
|
+
f"graphify misses ~540 imports in this repo, so reachability and "
|
|
127
|
+
f"blast-radius numbers below are UNDERSTATED. Run 'pnpm graph:update'.",
|
|
128
|
+
file=stream or _sys.stderr)
|
|
129
|
+
return count
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _strip_output_ext(path):
|
|
133
|
+
"""`foo.js` -> (`foo`, `.js`); anything else -> (path, None)."""
|
|
134
|
+
stem, ext = os.path.splitext(path)
|
|
135
|
+
return (stem, ext) if ext in TS_EQUIVALENT else (path, None)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _source_files_for(stem, ext):
|
|
139
|
+
"""Every real source file a specifier ending `stem + ext` can denote.
|
|
140
|
+
|
|
141
|
+
Falls through to the platform suffixes in two situations, so it strips the
|
|
142
|
+
source extension below as well as the output extension the caller stripped:
|
|
143
|
+
|
|
144
|
+
./Icon.js an output extension, no Icon.ts/.tsx on disk
|
|
145
|
+
./src/controls/*.tsx an exports map naming a file that does not exist,
|
|
146
|
+
because the real pair is BottomNav.native.tsx and
|
|
147
|
+
BottomNav.web.tsx. packages/ui writes every wildcard
|
|
148
|
+
this way, so without it 8 controls and items read as
|
|
149
|
+
unimported.
|
|
150
|
+
"""
|
|
151
|
+
if ext is not None:
|
|
152
|
+
for candidate_ext in TS_EQUIVALENT[ext]:
|
|
153
|
+
path = stem + candidate_ext
|
|
154
|
+
if os.path.isfile(path):
|
|
155
|
+
return [path]
|
|
156
|
+
elif os.path.isfile(stem):
|
|
157
|
+
return [stem]
|
|
158
|
+
else:
|
|
159
|
+
base, source_ext = os.path.splitext(stem)
|
|
160
|
+
if source_ext in SRC_EXTS:
|
|
161
|
+
stem = base
|
|
162
|
+
return [stem + s for s in PLATFORM_SUFFIXES if os.path.isfile(stem + s)]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def workspace_packages(roots=MANIFEST_GLOB_DIRS):
|
|
166
|
+
"""{package name: (package dir, manifest)} for every workspace member."""
|
|
167
|
+
found = {}
|
|
168
|
+
for root in roots:
|
|
169
|
+
if not os.path.isdir(root):
|
|
170
|
+
continue
|
|
171
|
+
for entry in sorted(os.listdir(root)):
|
|
172
|
+
manifest = os.path.join(root, entry, "package.json")
|
|
173
|
+
if not os.path.isfile(manifest):
|
|
174
|
+
continue
|
|
175
|
+
try:
|
|
176
|
+
data = json.load(open(manifest, encoding="utf-8"))
|
|
177
|
+
except (OSError, json.JSONDecodeError):
|
|
178
|
+
continue
|
|
179
|
+
if data.get("name"):
|
|
180
|
+
found[data["name"]] = (os.path.join(root, entry), data)
|
|
181
|
+
return found
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _conditions_for(importer):
|
|
185
|
+
"""Which export conditions this importer actually resolves through."""
|
|
186
|
+
base = os.path.basename(importer)
|
|
187
|
+
if importer.startswith("apps/mobile/") or ".native." in base:
|
|
188
|
+
return NATIVE_CONDITIONS, True
|
|
189
|
+
if importer.startswith("apps/web/") or ".web." in base:
|
|
190
|
+
return WEB_CONDITIONS, True
|
|
191
|
+
return ALL_CONDITIONS, False
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _export_targets(pkg_dir, manifest, subpath, conditions, pick_one):
|
|
195
|
+
"""Resolve `subpath` ("." or "./x/y") against a package's exports map."""
|
|
196
|
+
exports = manifest.get("exports")
|
|
197
|
+
if not isinstance(exports, dict):
|
|
198
|
+
# No exports map: only the root specifier is reachable, via main/module.
|
|
199
|
+
if subpath != "." or exports:
|
|
200
|
+
return []
|
|
201
|
+
for key in ("module", "main"):
|
|
202
|
+
if manifest.get(key):
|
|
203
|
+
target = os.path.normpath(os.path.join(pkg_dir, manifest[key]))
|
|
204
|
+
if os.path.isfile(target):
|
|
205
|
+
return [target]
|
|
206
|
+
return []
|
|
207
|
+
|
|
208
|
+
for key, value in exports.items():
|
|
209
|
+
# Exact match first, then a single `*` wildcard, matched the way Node
|
|
210
|
+
# does it: fixed prefix, fixed suffix, `*` takes everything between.
|
|
211
|
+
if key == subpath:
|
|
212
|
+
star = ""
|
|
213
|
+
elif "*" in key:
|
|
214
|
+
prefix, _, suffix = key.partition("*")
|
|
215
|
+
if not (subpath.startswith(prefix) and subpath.endswith(suffix)
|
|
216
|
+
and len(subpath) >= len(prefix) + len(suffix)):
|
|
217
|
+
continue
|
|
218
|
+
star = subpath[len(prefix):len(subpath) - len(suffix) or None]
|
|
219
|
+
else:
|
|
220
|
+
continue
|
|
221
|
+
|
|
222
|
+
if isinstance(value, str):
|
|
223
|
+
values = [value]
|
|
224
|
+
else:
|
|
225
|
+
present = [c for c in conditions if c in value]
|
|
226
|
+
values = [value[present[0]]] if (pick_one and present) else \
|
|
227
|
+
[value[c] for c in present]
|
|
228
|
+
|
|
229
|
+
targets = []
|
|
230
|
+
for raw in values:
|
|
231
|
+
path = os.path.normpath(os.path.join(pkg_dir, raw.replace("*", star)))
|
|
232
|
+
if f"{os.sep}dist{os.sep}" in f"{os.sep}{path}{os.sep}":
|
|
233
|
+
continue
|
|
234
|
+
stem, ext = _strip_output_ext(path)
|
|
235
|
+
targets.extend(f for f in _source_files_for(stem, ext)
|
|
236
|
+
if f.endswith(SRC_EXTS))
|
|
237
|
+
return targets
|
|
238
|
+
return []
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _source_files(roots):
|
|
242
|
+
for root in roots:
|
|
243
|
+
for dirpath, dirnames, filenames in os.walk(root):
|
|
244
|
+
dirnames[:] = [d for d in dirnames if d not in SKIP_DIR]
|
|
245
|
+
for name in sorted(filenames):
|
|
246
|
+
if name.endswith(SRC_EXTS):
|
|
247
|
+
yield os.path.join(dirpath, name)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def resolved_import_edges(roots=DEFAULT_ROOTS, collect_unresolved=None):
|
|
251
|
+
"""Every (importer, imported) pair reachable through a static import.
|
|
252
|
+
|
|
253
|
+
Returns the FULL set, not only the repairs, so a caller can union it with
|
|
254
|
+
whatever graph.json carried without reasoning about which found a given
|
|
255
|
+
edge. Union is idempotent; a pair in both is one pair.
|
|
256
|
+
|
|
257
|
+
Pass a list as `collect_unresolved` to receive (importer, specifier) for
|
|
258
|
+
every workspace import that matched a package but no exports entry.
|
|
259
|
+
"""
|
|
260
|
+
packages = workspace_packages()
|
|
261
|
+
edges = set()
|
|
262
|
+
for src in _source_files(roots):
|
|
263
|
+
try:
|
|
264
|
+
text = open(src, encoding="utf-8", errors="ignore").read()
|
|
265
|
+
except OSError:
|
|
266
|
+
continue
|
|
267
|
+
conditions, pick_one = _conditions_for(src)
|
|
268
|
+
for spec in SPEC.findall(text):
|
|
269
|
+
targets = []
|
|
270
|
+
if spec.startswith("."):
|
|
271
|
+
path = os.path.normpath(os.path.join(os.path.dirname(src), spec))
|
|
272
|
+
stem, ext = _strip_output_ext(path)
|
|
273
|
+
# Extensionless is graphify's job and it does it correctly.
|
|
274
|
+
if ext is None:
|
|
275
|
+
continue
|
|
276
|
+
targets = _source_files_for(stem, ext)
|
|
277
|
+
else:
|
|
278
|
+
for name, (pkg_dir, manifest) in packages.items():
|
|
279
|
+
if spec != name and not spec.startswith(name + "/"):
|
|
280
|
+
continue
|
|
281
|
+
subpath = "." if spec == name else "./" + spec[len(name) + 1:]
|
|
282
|
+
targets = _export_targets(pkg_dir, manifest, subpath,
|
|
283
|
+
conditions, pick_one)
|
|
284
|
+
if not targets and collect_unresolved is not None:
|
|
285
|
+
collect_unresolved.append((src, spec))
|
|
286
|
+
break
|
|
287
|
+
for dst in targets:
|
|
288
|
+
if dst != src:
|
|
289
|
+
edges.add((src, dst))
|
|
290
|
+
return edges
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Example. Paste at the end of your .husky/pre-push, below the bkit lines, and own it.
|
|
3
|
+
# bkit install does not write this file and does not overwrite a copy.
|
|
4
|
+
#
|
|
5
|
+
# Warn-only. Never blocks a push, never writes, never runs graphify.
|
|
6
|
+
# A fresh docs/capabilities.md is stamped at the parent of the commit that
|
|
7
|
+
# carries it, so staleness is source files changed since that stamp.
|
|
8
|
+
CAP_DOC="docs/capabilities.md"
|
|
9
|
+
if [ -f "$CAP_DOC" ]; then
|
|
10
|
+
CAP_SHA=$(sed -n 's/.*Diagrams from `graph\.json` @ `\([0-9a-f]\{7,\}\)`.*/\1/p' "$CAP_DOC" | head -1)
|
|
11
|
+
if [ -n "$CAP_SHA" ] && git cat-file -e "$CAP_SHA^{commit}" 2>/dev/null; then
|
|
12
|
+
CAP_CHANGED=$(git diff --name-only "$CAP_SHA..HEAD" -- '*.ts' '*.tsx' 2>/dev/null | wc -l | tr -d ' ')
|
|
13
|
+
if [ "${CAP_CHANGED:-0}" -gt 0 ]; then
|
|
14
|
+
echo "[pre-push] NOTE: $CAP_DOC diagrams were built at $CAP_SHA; $CAP_CHANGED source files changed since." >&2
|
|
15
|
+
echo "[pre-push] Refresh when convenient: pnpm graph:update && pnpm graph:rollup" >&2
|
|
16
|
+
echo "[pre-push] Not a gate. The release gate is 'pnpm graph:check' before the dev -> main PR." >&2
|
|
17
|
+
fi
|
|
18
|
+
fi
|
|
19
|
+
fi
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Example. Copy into the repo and own it.
|
|
2
|
+
# bkit install does not write this file and does not overwrite a copy.
|
|
3
|
+
# Adapt app roots, the workspace package scope, and the rules JSON to this repo.
|
|
4
|
+
|
|
5
|
+
#!/usr/bin/env python3
|
|
6
|
+
"""Inject the import edges graphify could not resolve back into graph.json.
|
|
7
|
+
|
|
8
|
+
Called by `pnpm graph`, `:clean` and `:update` (scripts/graphify/bkit-graphify.sh),
|
|
9
|
+
between `extract` and `cluster-only`.
|
|
10
|
+
|
|
11
|
+
bkit-graph-repair.py <graph.json> [--rules R] [--quiet]
|
|
12
|
+
|
|
13
|
+
graph.json carries the repaired edges, so every reader sees them: our own
|
|
14
|
+
checks, the generated doc, and `graphify affected`, `god-nodes`, `explain`,
|
|
15
|
+
`path` and `query`. Readers call `warn_if_unrepaired`, so a graph built without
|
|
16
|
+
this step says so.
|
|
17
|
+
|
|
18
|
+
`graphify update` rewrites graph.json without the injected edges, so every
|
|
19
|
+
wrapper command that writes the file (`pnpm graph`, `:clean`, `:update`) runs
|
|
20
|
+
this step at the end. The step is idempotent: after a raw `graphify update .`,
|
|
21
|
+
run `pnpm graph:update`.
|
|
22
|
+
|
|
23
|
+
ORDER MATTERS: this runs BEFORE clustering, so communities, the god-node
|
|
24
|
+
ranking and the cycle list in graph-report.md are computed from the repaired graph.
|
|
25
|
+
|
|
26
|
+
WHAT IS WRITTEN. One `imports_from` link per recovered file pair, between the
|
|
27
|
+
two files' L1 nodes — that is the shape graphify itself uses for a file-to-file
|
|
28
|
+
dependency. Each carries `"_origin": "graph-repair"` so it is greppable and
|
|
29
|
+
never passes as graphify's own extraction. Edges already present are skipped, so
|
|
30
|
+
running twice changes nothing.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
import argparse
|
|
34
|
+
import collections
|
|
35
|
+
import json
|
|
36
|
+
import os
|
|
37
|
+
import sys
|
|
38
|
+
|
|
39
|
+
# bkit-graph-imports.py is hyphenated, which `import` cannot spell, so it is loaded
|
|
40
|
+
# by path.
|
|
41
|
+
import importlib.util as _ilu
|
|
42
|
+
_spec = _ilu.spec_from_file_location(
|
|
43
|
+
"graph_imports",
|
|
44
|
+
os.path.join(os.path.dirname(os.path.abspath(__file__)), "bkit-graph-imports.py"))
|
|
45
|
+
graph_imports = _ilu.module_from_spec(_spec)
|
|
46
|
+
_spec.loader.exec_module(graph_imports)
|
|
47
|
+
|
|
48
|
+
DEP_RELATIONS = {"imports", "imports_from", "re_exports", "dynamic_import"}
|
|
49
|
+
ORIGIN = "graph-repair"
|
|
50
|
+
|
|
51
|
+
ap = argparse.ArgumentParser()
|
|
52
|
+
ap.add_argument("graph_json")
|
|
53
|
+
ap.add_argument("--rules", default="scripts/graphify/bkit-graph-eager-rules.json")
|
|
54
|
+
ap.add_argument("--quiet", action="store_true")
|
|
55
|
+
args = ap.parse_args()
|
|
56
|
+
|
|
57
|
+
graph = json.load(open(args.graph_json, encoding="utf-8"))
|
|
58
|
+
nodes = {n["id"]: n for n in graph["nodes"]}
|
|
59
|
+
|
|
60
|
+
# The file-level node is the one graphify anchors at L1. Six files carry more
|
|
61
|
+
# than one; first by id wins, deterministically, so a rerun picks the same node.
|
|
62
|
+
file_node = {}
|
|
63
|
+
for node in sorted(graph["nodes"], key=lambda n: n["id"]):
|
|
64
|
+
path = str(node.get("source_file") or "")
|
|
65
|
+
if path and node.get("source_location") == "L1" and path not in file_node:
|
|
66
|
+
file_node[path] = node["id"]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def path_of(node_id):
|
|
70
|
+
return str(nodes.get(node_id, {}).get("source_file") or "")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# Strip a previous injection FIRST, before computing `existing`; the reverse order
|
|
74
|
+
# skips every candidate as already present and then deletes last run's edges.
|
|
75
|
+
before = len(graph["links"])
|
|
76
|
+
graph["links"] = [l for l in graph["links"] if l.get("_origin") != ORIGIN]
|
|
77
|
+
removed = before - len(graph["links"])
|
|
78
|
+
|
|
79
|
+
existing = {(path_of(l["source"]), path_of(l["target"]))
|
|
80
|
+
for l in graph["links"] if l.get("relation") in DEP_RELATIONS}
|
|
81
|
+
|
|
82
|
+
wanted = graph_imports.resolved_import_edges()
|
|
83
|
+
added, skipped_no_node = [], collections.Counter()
|
|
84
|
+
for src, dst in sorted(wanted):
|
|
85
|
+
if (src, dst) in existing:
|
|
86
|
+
continue
|
|
87
|
+
if src not in file_node or dst not in file_node:
|
|
88
|
+
# Only happens for a file outside the corpus (a fresh file the graph has
|
|
89
|
+
# not seen). Counted, never silently dropped.
|
|
90
|
+
skipped_no_node["src" if src not in file_node else "dst"] += 1
|
|
91
|
+
continue
|
|
92
|
+
added.append({
|
|
93
|
+
"source": file_node[src], "target": file_node[dst],
|
|
94
|
+
"relation": "imports_from", "_origin": ORIGIN,
|
|
95
|
+
"confidence": "EXTRACTED", "confidence_score": 1.0,
|
|
96
|
+
"context": "import", "source_file": src, "source_location": "L1",
|
|
97
|
+
"weight": 1.0,
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
graph["links"].extend(added)
|
|
101
|
+
|
|
102
|
+
# NO top-level marker: a `graph["import_repair"] = {...}` key does not survive
|
|
103
|
+
# `cluster-only`, which rewrites graph.json and keeps only the keys it writes
|
|
104
|
+
# itself (`built_at_commit` survives because graphify sets it). The per-link
|
|
105
|
+
# `_origin` DOES survive, so that is what consumers check
|
|
106
|
+
# — see warn_if_unrepaired / repair_state in bkit-graph-imports.py.
|
|
107
|
+
|
|
108
|
+
tmp = args.graph_json + ".repair.tmp"
|
|
109
|
+
with open(tmp, "w", encoding="utf-8") as fh:
|
|
110
|
+
json.dump(graph, fh)
|
|
111
|
+
os.replace(tmp, args.graph_json)
|
|
112
|
+
|
|
113
|
+
if not args.quiet:
|
|
114
|
+
if removed:
|
|
115
|
+
print(f"[repair] dropped {removed} edges from a previous run")
|
|
116
|
+
print(f"[repair] +{len(added)} import edges into {args.graph_json} "
|
|
117
|
+
f"({len(graph['links'])} links total)")
|
|
118
|
+
if skipped_no_node:
|
|
119
|
+
print(f"[repair] {sum(skipped_no_node.values())} skipped, endpoint absent "
|
|
120
|
+
f"from the graph: {dict(skipped_no_node)}", file=sys.stderr)
|