@cbartens/bkit 5.5.1 → 6.1.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 +167 -154
- package/.bkit/core/.agents/context.md +95 -29
- package/.bkit/core/.agents/docs.md +18 -15
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-gateguard.cjs +1 -0
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +6 -5
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-readguard.cjs +1 -0
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-rules.cjs +65 -0
- package/.bkit/core/.agents/rules.md +112 -102
- package/.bkit/core/.agents/skills.md +63 -15
- package/.bkit/core/.bkit/README.md +167 -154
- package/.bkit/core/.bkit/authoring.md +747 -0
- package/.bkit/core/.bkit/cli.md +407 -0
- package/.bkit/core/.bkit/cloud.md +283 -195
- package/.bkit/core/.bkit/comparison.md +45 -43
- package/.bkit/core/.bkit/install.md +166 -95
- package/.bkit/core/.bkit/jsonl.md +339 -196
- package/.bkit/core/.bkit/pipeline.md +142 -145
- package/.bkit/core/.bkit/prompts.md +295 -264
- package/.bkit/core/.bkit/providers.md +460 -277
- package/.bkit/core/.bkit/router.md +69 -0
- package/.bkit/core/.bkit/templates.md +530 -256
- package/.bkit/core/.bkit/trackers.md +116 -65
- package/.bkit/core/.bkit/workflows.md +742 -618
- package/.bkit/core/.claude/hooks/bkit-gateguard.cjs +2 -2
- package/.bkit/core/.claude/hooks/bkit-guardrails.cjs +3 -3
- package/.bkit/core/.claude/hooks/bkit-preflight.sh +45 -14
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +3 -3
- package/.bkit/core/.codex/hooks/bkit-rules.cjs +57 -0
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +7 -7
- package/.bkit/core/.cursor/hooks/bkit-preflight.sh +47 -12
- package/.bkit/core/.opencode/plugin/bkit-rules.js +89 -0
- package/.bkit/core/AGENTS.md +6 -80
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +128 -130
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +104 -94
- package/.bkit/core/docs/templates/bkit-audit-agents.md +96 -98
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +100 -103
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +141 -107
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +99 -97
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +122 -121
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +158 -101
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +114 -96
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +76 -97
- package/.bkit/core/docs/templates/bkit-audit-config.md +123 -101
- package/.bkit/core/docs/templates/bkit-audit-cost.md +86 -99
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +76 -93
- package/.bkit/core/docs/templates/bkit-audit-database.md +102 -95
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +165 -108
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +115 -109
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +265 -113
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +119 -118
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +140 -111
- package/.bkit/core/docs/templates/bkit-audit-failures.md +111 -106
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +100 -99
- package/.bkit/core/docs/templates/bkit-audit-gates.md +107 -103
- package/.bkit/core/docs/templates/bkit-audit-issues.md +105 -105
- package/.bkit/core/docs/templates/bkit-audit-llm.md +134 -85
- package/.bkit/core/docs/templates/bkit-audit-logs.md +124 -125
- package/.bkit/core/docs/templates/bkit-audit-models.md +99 -78
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +56 -76
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +63 -78
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +125 -93
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +97 -96
- package/.bkit/core/docs/templates/bkit-audit-repo.md +170 -98
- package/.bkit/core/docs/templates/bkit-audit-security.md +207 -121
- package/.bkit/core/docs/templates/bkit-audit-slop.md +78 -95
- package/.bkit/core/docs/templates/bkit-audit-testing.md +163 -139
- package/.bkit/core/docs/templates/bkit-audit-usability.md +114 -96
- package/.bkit/core/docs/templates/bkit-plan.md +158 -281
- package/.bkit/core/engine/checks/after/auth.ts +40 -37
- package/.bkit/core/engine/checks/after/ci-yml.ts +104 -31
- package/.bkit/core/engine/checks/after/github.ts +95 -17
- package/.bkit/core/engine/checks/after/index.ts +21 -8
- package/.bkit/core/engine/checks/after/suppression.ts +8 -5
- package/.bkit/core/engine/checks/after/tools.ts +125 -123
- package/.bkit/core/engine/checks/before/context-fetch.ts +227 -33
- package/.bkit/core/engine/checks/before/env.ts +3 -3
- package/.bkit/core/engine/checks/before/files.ts +5 -4
- package/.bkit/core/engine/checks/before/index.ts +25 -1
- package/.bkit/core/engine/checks/before/repo.ts +208 -2
- package/.bkit/core/engine/checks/status-holes.ts +916 -123
- package/.bkit/core/engine/checks/tips/catalogue.ts +82 -20
- package/.bkit/core/engine/checks/tips/detect.ts +66 -0
- package/.bkit/core/engine/checks/tips/index.ts +52 -11
- package/.bkit/core/engine/cli.ts +251 -130
- package/.bkit/core/engine/commands/analysis.ts +282 -199
- package/.bkit/core/engine/commands/ci/ci.ts +363 -29
- package/.bkit/core/engine/commands/ci/pins.ts +172 -0
- package/.bkit/core/engine/commands/ci/push-gate.ts +223 -0
- package/.bkit/core/engine/commands/comply.ts +77 -103
- package/.bkit/core/engine/commands/install/doctor.ts +2 -2
- package/.bkit/core/engine/commands/install/install.ts +57 -18
- package/.bkit/core/engine/commands/install/uninstall.ts +86 -55
- package/.bkit/core/engine/commands/install/upgrade.ts +32 -15
- package/.bkit/core/engine/commands/land.ts +139 -18
- package/.bkit/core/engine/commands/lib.ts +381 -22
- package/.bkit/core/engine/commands/registry.ts +10 -2
- package/.bkit/core/engine/commands/setup/setup.ts +8 -7
- package/.bkit/core/engine/commands/stats.ts +260 -0
- package/.bkit/core/engine/commands/tips.ts +10 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +2215 -176
- package/.bkit/core/engine/commands/workflow/challenge.ts +748 -0
- package/.bkit/core/engine/commands/workflow/completeness.ts +109 -0
- package/.bkit/core/engine/commands/workflow/context.ts +1249 -47
- package/.bkit/core/engine/commands/workflow/counters.ts +483 -95
- package/.bkit/core/engine/commands/workflow/decisions.ts +585 -0
- package/.bkit/core/engine/commands/workflow/disk.ts +238 -56
- package/.bkit/core/engine/commands/workflow/fids.ts +811 -33
- package/.bkit/core/engine/commands/workflow/issues.ts +413 -64
- package/.bkit/core/engine/commands/workflow/ledgers.ts +1333 -36
- package/.bkit/core/engine/commands/workflow/locks.ts +28 -2
- package/.bkit/core/engine/commands/workflow/plan-blocks.ts +691 -0
- package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
- package/.bkit/core/engine/commands/workflow/plans.ts +257 -0
- package/.bkit/core/engine/commands/workflow/prs.ts +178 -33
- package/.bkit/core/engine/commands/workflow/repo.ts +66 -8
- package/.bkit/core/engine/commands/workflow/roadmap.ts +72 -22
- package/.bkit/core/engine/commands/workflow/run-facts.ts +492 -0
- package/.bkit/core/engine/commands/workflow/runs.ts +827 -79
- package/.bkit/core/engine/commands/workflow/runtime.ts +25 -1
- package/.bkit/core/engine/commands/workflow/skills.ts +1 -0
- package/.bkit/core/engine/commands/workflow/status.ts +329 -33
- package/.bkit/core/engine/commands/workflow/step-table.ts +381 -0
- package/.bkit/core/engine/commands/workflow/steps.ts +841 -105
- package/.bkit/core/engine/commands/workflow/summary-findings.ts +177 -0
- package/.bkit/core/engine/commands/workflow/summary.ts +544 -0
- package/.bkit/core/engine/commands/workflow/tasks.ts +409 -0
- package/.bkit/core/engine/commands/workflow/test-blocks.ts +254 -0
- package/.bkit/core/engine/commands/workflow/tests-changed.ts +201 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +2124 -330
- package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
- package/.bkit/core/engine/commands/workflow/workflows.ts +1197 -235
- package/.bkit/core/engine/commands/workflow/worktrees.ts +543 -24
- package/.bkit/core/engine/install/cloud-env.ts +251 -121
- package/.bkit/core/engine/install/context-ci-workflow.ts +102 -0
- package/.bkit/core/engine/install/manifest.ts +67 -17
- package/.bkit/core/engine/install/modules/antigravity.ts +3 -2
- package/.bkit/core/engine/install/modules/cloud.ts +24 -16
- package/.bkit/core/engine/install/modules/codex.ts +15 -2
- package/.bkit/core/engine/install/modules/core.ts +1196 -45
- package/.bkit/core/engine/install/modules/cursor.ts +6 -6
- package/.bkit/core/engine/install/modules/opencode.ts +18 -6
- package/.bkit/core/engine/install/template-notes.ts +130 -0
- package/.bkit/core/engine/install/version-file.ts +9 -4
- package/.bkit/core/engine/install/write.ts +5 -0
- package/.bkit/core/engine/ledgers/compact.ts +124 -0
- package/.bkit/core/engine/ledgers/journal.ts +291 -0
- package/.bkit/core/engine/ledgers/migrate.ts +92 -0
- package/.bkit/core/engine/ledgers/status.ts +249 -21
- package/.bkit/core/engine/ledgers/telemetry.ts +1397 -253
- package/.bkit/core/engine/render/hosts.ts +118 -14
- package/.bkit/core/engine/render/models.ts +12 -0
- package/.bkit/core/engine/shared/bkit-latest.ts +26 -4
- package/.bkit/core/engine/shared/branches.ts +4 -1
- package/.bkit/core/engine/shared/dep-updater.ts +60 -0
- package/.bkit/core/engine/shared/egress.ts +8 -1
- package/.bkit/core/engine/shared/json.ts +25 -7
- package/.bkit/core/engine/shared/package-manager.ts +9 -0
- package/.bkit/core/engine/shared/settings.ts +243 -31
- package/.bkit/core/engine/shared/text.ts +361 -0
- package/.bkit/core/engine/shared/timeouts.ts +2 -0
- package/.bkit/core/engine/tools/cli-doc.ts +111 -0
- package/.bkit/core/engine/tools/grammar-density.ts +215 -0
- package/.bkit/core/engine/tools/instructions-sources.ts +832 -0
- package/.bkit/core/engine/tools/instructions.ts +1802 -0
- package/.bkit/core/hooks/antigravity-hook.js +25 -10
- package/.bkit/core/hooks/gateguard-engine.js +54 -29
- package/.bkit/core/hooks/guardrails-shell.js +4 -5
- package/.bkit/core/hooks/guardrails-tiers.js +10 -4
- package/.bkit/core/hooks/preflight-linear.sh +9 -9
- package/.bkit/core/hooks/preflight-rules.sh +8 -0
- package/.bkit/core/hooks/readguard-engine.js +29 -10
- package/.bkit/core/hooks/session-rules-advisory.js +61 -0
- package/.bkit/core/prompts/bkit-audit-generate.md +202 -94
- package/.bkit/core/prompts/bkit-build-challenge-1.md +76 -34
- package/.bkit/core/prompts/bkit-build-challenge-2.md +85 -38
- package/.bkit/core/prompts/bkit-build-install-skills.md +50 -28
- package/.bkit/core/prompts/bkit-build-plan-convert.md +85 -0
- package/.bkit/core/prompts/bkit-build-plan-current.md +59 -36
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +101 -36
- package/.bkit/core/prompts/bkit-build-plan-tasks.md +149 -0
- package/.bkit/core/prompts/bkit-build-plan-tests.md +120 -0
- package/.bkit/core/prompts/bkit-build-plan-verify.md +104 -43
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +47 -32
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +109 -57
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +65 -39
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +53 -31
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +65 -34
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +46 -31
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +45 -31
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +43 -30
- package/.bkit/core/prompts/bkit-design-generate.md +80 -46
- package/.bkit/core/prompts/bkit-design-organise.md +83 -32
- package/.bkit/core/prompts/bkit-design-review-1.md +70 -50
- package/.bkit/core/prompts/bkit-design-review-2.md +65 -46
- package/.bkit/core/prompts/bkit-design-spike.md +64 -40
- package/.bkit/core/prompts/bkit-design-update.md +53 -28
- package/.bkit/core/prompts/bkit-plan-generate.md +101 -29
- package/.bkit/core/prompts/bkit-plan-review-1.md +78 -41
- package/.bkit/core/prompts/bkit-plan-review-2.md +78 -35
- package/.bkit/core/prompts/bkit-plan-scope-check.md +116 -0
- package/.bkit/core/prompts/bkit-plan-update.md +86 -31
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +94 -50
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +91 -41
- package/.bkit/core/prompts/bkit-ship-update-docs.md +45 -24
- package/.bkit/core/prompts/bkit-utility-compress-markdown.md +65 -49
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +87 -42
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +81 -37
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +43 -25
- package/.bkit/core/prompts/bkit-utility-update-failures.md +84 -37
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +88 -42
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +92 -39
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +159 -60
- package/.bkit/core/workflows/bkit-auto.md +89 -58
- package/.bkit/core/workflows/bkit-build.md +967 -517
- package/.bkit/core/workflows/bkit-debug.md +555 -387
- package/.bkit/core/workflows/bkit-design.md +319 -283
- package/.bkit/core/workflows/bkit-plan.md +319 -342
- package/.bkit/core/workflows/bkit-ship.md +525 -328
- package/.bkit/shared/.agents/plugins/bkit/hooks.json +10 -0
- package/.bkit/shared/.bkit/.env.example +2 -2
- package/.bkit/shared/.claude/bkit-cloud.md +12 -10
- package/.bkit/shared/.claude/settings.json +14 -0
- package/.bkit/shared/.codex/bkit-cloud.md +98 -0
- package/.bkit/shared/.codex/hooks.json +20 -0
- package/.bkit/shared/.cursor/bkit-cloud.md +3 -3
- package/.bkit/shared/.cursor/mcp.json +1 -1
- package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
- package/.bkit/shared/.gitattributes +1 -1
- package/.bkit/shared/.mcp.json +1 -1
- package/.bkit/shared/.opencode/opencode.json +12 -1
- package/.bkit/shared/CLAUDE.md +6 -2
- package/.bkit/shared/GEMINI.md +5 -2
- package/.bkit/shared/docs/architecture.md +4 -7
- package/.bkit/shared/docs/data-schema.md +4 -7
- package/.bkit/shared/docs/deployments.md +241 -168
- package/.bkit/shared/docs/design.md +11 -12
- package/.bkit/shared/docs/noise.md +8 -7
- package/.bkit/shared/docs/observability.md +5 -8
- package/.bkit/shared/docs/security.md +35 -17
- package/.bkit/shared/docs/setup.md +29 -18
- package/.bkit/shared/docs/technology.md +3 -6
- package/.bkit/shared/docs/testing.md +289 -174
- package/.bkit/shared/gitignore +6 -2
- package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +15 -16
- package/.bkit/templates/.cursor/Dockerfile +12 -8
- package/.bkit/templates/.cursor/environment.json +1 -1
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-bug.yml +10 -8
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +45 -12
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-idea.yml +3 -3
- package/.bkit/templates/.github/renovate.json5 +34 -6
- package/.bkit/templates/.github/workflows/bkit-ci.yml +54 -51
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +34 -33
- package/.bkit/templates/.github/workflows/bkit-health.yml +97 -0
- package/.bkit/templates/.github/workflows/bkit-renovate.yml +5 -4
- package/.bkit/templates/.github/workflows/bkit-trivy.yml +5 -4
- package/.bkit/templates/.husky/pre-commit +2 -2
- package/.bkit/templates/.husky/pre-push +96 -36
- package/.bkit/templates/.prettierignore +6 -0
- package/.bkit/templates/.vale.ini +27 -27
- package/.bkit/templates/context/bkit-cloudrun.md +23 -15
- package/.bkit/templates/context/bkit-expo.md +70 -52
- package/.bkit/templates/context/bkit-github.md +93 -56
- package/.bkit/templates/context/bkit-inngest.md +21 -15
- package/.bkit/templates/context/bkit-maestro.md +22 -16
- package/.bkit/templates/context/bkit-playwright.md +23 -17
- package/.bkit/templates/context/bkit-resend.md +12 -10
- package/.bkit/templates/context/bkit-sentry.md +30 -20
- package/.bkit/templates/context/bkit-serena.md +8 -7
- package/.bkit/templates/context/bkit-stripe.md +14 -13
- package/.bkit/templates/context/bkit-supabase.md +16 -13
- package/.bkit/templates/context/bkit-tavily.md +14 -11
- package/.bkit/templates/context/bkit-vercel.md +27 -18
- package/.bkit/templates/docs/capabilities.md +15 -14
- package/.bkit/templates/scripts/ci/{check-accepted-divergences.mjs → bkit-check-accepted-divergences.mjs} +6 -3
- package/.bkit/templates/scripts/ci/{check-accepted-divergences.test.mjs → bkit-check-accepted-divergences.test.mjs} +3 -3
- package/.bkit/templates/scripts/ci/{check-capstone.mjs → bkit-check-capstone.mjs} +2 -2
- package/.bkit/templates/scripts/ci/{check-capstone.test.mjs → bkit-check-capstone.test.mjs} +4 -4
- package/.bkit/templates/scripts/ci/{check-dependency-audit.mjs → bkit-check-dependency-audit.mjs} +103 -18
- package/.bkit/templates/scripts/ci/{check-dependency-audit.test.mjs → bkit-check-dependency-audit.test.mjs} +31 -3
- package/.bkit/templates/scripts/ci/bkit-machine-lock.sh +387 -0
- package/.bkit/templates/scripts/ci/bkit-test-awake.mjs +75 -0
- package/.bkit/templates/scripts/ci/bkit-test-awake.test.mjs +160 -0
- package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.mjs → bkit-resolve-push-base.mjs} +3 -3
- package/.bkit/templates/scripts/ci/lanes/{resolve-push-base.test.mjs → bkit-resolve-push-base.test.mjs} +4 -4
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +10 -2
- package/.bkit/templates/scripts/graphify/bkit-graph-drift.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graph-eager.py +3 -3
- package/.bkit/templates/scripts/graphify/bkit-graph-embed.py +63 -0
- package/.bkit/templates/scripts/graphify/bkit-graph-imports.py +2 -2
- package/.bkit/templates/scripts/graphify/bkit-graph-pre-push.sh +69 -18
- package/.bkit/templates/scripts/graphify/bkit-graph-repair.py +3 -3
- package/.bkit/templates/scripts/graphify/bkit-graph-surface.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-graphml.py +1 -1
- package/.bkit/templates/scripts/graphify/bkit-graphify-rollup.py +197 -126
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +64 -41
- package/.bkit/templates/scripts/slop/bkit-slop-type-suppression.mjs +23 -7
- package/.bkit/templates/slop-scan.config.json +9 -2
- package/CHANGELOG.md +231 -0
- package/README.md +278 -89
- package/dist/checks/after/auth.js +36 -33
- package/dist/checks/after/ci-yml.js +91 -30
- package/dist/checks/after/github.js +91 -17
- package/dist/checks/after/index.js +22 -11
- package/dist/checks/after/suppression.js +8 -5
- package/dist/checks/after/tools.js +111 -114
- package/dist/checks/before/context-fetch.js +218 -33
- package/dist/checks/before/env.js +3 -3
- package/dist/checks/before/files.js +5 -3
- package/dist/checks/before/index.js +20 -3
- package/dist/checks/before/repo.js +197 -2
- package/dist/checks/status-holes.js +739 -114
- package/dist/checks/tips/catalogue.js +70 -19
- package/dist/checks/tips/detect.js +62 -0
- package/dist/checks/tips/index.js +51 -9
- package/dist/cli.js +234 -124
- package/dist/commands/analysis.js +174 -141
- package/dist/commands/ci/ci.js +302 -25
- package/dist/commands/ci/pins.js +142 -0
- package/dist/commands/ci/push-gate.js +194 -0
- package/dist/commands/comply.js +54 -91
- package/dist/commands/install/doctor.js +2 -2
- package/dist/commands/install/install.js +50 -19
- package/dist/commands/install/uninstall.js +82 -55
- package/dist/commands/install/upgrade.js +21 -11
- package/dist/commands/land.js +137 -17
- package/dist/commands/lib.js +295 -21
- package/dist/commands/registry.js +10 -2
- package/dist/commands/setup/setup.js +8 -7
- package/dist/commands/stats.js +175 -0
- package/dist/commands/tips.js +7 -3
- package/dist/commands/workflow/branches.js +1873 -152
- package/dist/commands/workflow/challenge.js +609 -0
- package/dist/commands/workflow/completeness.js +97 -0
- package/dist/commands/workflow/context.js +1045 -46
- package/dist/commands/workflow/counters.js +385 -86
- package/dist/commands/workflow/decisions.js +484 -0
- package/dist/commands/workflow/disk.js +214 -56
- package/dist/commands/workflow/fids.js +706 -33
- package/dist/commands/workflow/issues.js +349 -59
- package/dist/commands/workflow/ledgers.js +1123 -37
- package/dist/commands/workflow/locks.js +26 -2
- package/dist/commands/workflow/plan-blocks.js +501 -0
- package/dist/commands/workflow/plan-versions.js +22 -0
- package/dist/commands/workflow/plans.js +205 -0
- package/dist/commands/workflow/prs.js +154 -35
- package/dist/commands/workflow/repo.js +58 -8
- package/dist/commands/workflow/roadmap.js +58 -23
- package/dist/commands/workflow/run-facts.js +421 -0
- package/dist/commands/workflow/runs.js +670 -72
- package/dist/commands/workflow/runtime.js +15 -1
- package/dist/commands/workflow/skills.js +1 -0
- package/dist/commands/workflow/status.js +282 -34
- package/dist/commands/workflow/step-table.js +308 -0
- package/dist/commands/workflow/steps.js +703 -96
- package/dist/commands/workflow/summary-findings.js +117 -0
- package/dist/commands/workflow/summary.js +388 -0
- package/dist/commands/workflow/tasks.js +378 -0
- package/dist/commands/workflow/test-blocks.js +231 -0
- package/dist/commands/workflow/tests-changed.js +172 -0
- package/dist/commands/workflow/tests.js +1695 -305
- package/dist/commands/workflow/tracker.js +983 -0
- package/dist/commands/workflow/workflows.js +1014 -222
- package/dist/commands/workflow/worktrees.js +432 -26
- package/dist/install/cloud-env.js +233 -99
- package/dist/install/context-ci-workflow.js +85 -0
- package/dist/install/manifest.js +64 -17
- package/dist/install/modules/antigravity.js +3 -2
- package/dist/install/modules/cloud.js +25 -16
- package/dist/install/modules/codex.js +12 -2
- package/dist/install/modules/core.js +1090 -48
- package/dist/install/modules/cursor.js +6 -6
- package/dist/install/modules/opencode.js +13 -7
- package/dist/install/template-notes.js +116 -0
- package/dist/install/version-file.js +9 -4
- package/dist/ledgers/compact.js +87 -0
- package/dist/ledgers/journal.js +233 -0
- package/dist/ledgers/migrate.js +81 -0
- package/dist/ledgers/status.js +176 -13
- package/dist/ledgers/telemetry.js +1010 -125
- package/dist/render/hosts.js +104 -14
- package/dist/render/models.js +12 -0
- package/dist/shared/bkit-latest.js +26 -4
- package/dist/shared/branches.js +3 -1
- package/dist/shared/dep-updater.js +49 -0
- package/dist/shared/egress.js +8 -1
- package/dist/shared/json.js +20 -7
- package/dist/shared/package-manager.js +6 -0
- package/dist/shared/settings.js +181 -24
- package/dist/shared/text.js +333 -0
- package/dist/shared/timeouts.js +2 -0
- package/dist/tools/cli-doc.js +97 -0
- package/dist/tools/grammar-density.js +183 -0
- package/dist/tools/instructions-sources.js +720 -0
- package/dist/tools/instructions.js +1623 -0
- package/package.json +156 -51
- package/.bkit/core/.bkit/lite.md +0 -73
- package/.bkit/core/engine/commands/harvest.ts +0 -459
- package/.bkit/core/engine/commands/workflow/workstreams.ts +0 -166
- package/.bkit/core/engine/tools/wording.ts +0 -748
- package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
- package/.bkit/core/prompts/bkit-build-plan-execute.md +0 -76
- package/.bkit/core/prompts/bkit-build-summary.md +0 -94
- package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
- package/.bkit/core/prompts/bkit-design-summary.md +0 -107
- package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
- package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
- package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
- package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
- package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
- package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
- package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
- package/.bkit/templates/scripts/ci/bkit-local-stack-lock.sh +0 -194
- package/dist/commands/harvest.js +0 -353
- package/dist/commands/workflow/workstreams.js +0 -143
- package/dist/tools/wording.js +0 -680
- /package/.bkit/templates/.vale/styles/{House → Bkit}/Filler.yml +0 -0
- /package/.bkit/templates/.vale/styles/{House → Bkit}/Hedging.yml +0 -0
- /package/.bkit/templates/.vale/styles/{House → Bkit}/LLMSlop.yml +0 -0
- /package/.bkit/templates/.vale/styles/{House → Bkit}/Verbose.yml +0 -0
- /package/.bkit/templates/scripts/ci/{accepted-advisories.json → bkit-accepted-advisories.json} +0 -0
- /package/.bkit/templates/scripts/ci/{accepted-divergences.json → bkit-accepted-divergences.json} +0 -0
- /package/.bkit/templates/scripts/launchd/{launchd.env.example → bkit-launchd.env.example} +0 -0
- /package/.bkit/templates/scripts/launchd/{ai.bkit.launchd.plist → bkit-launchd.plist} +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
// bkit ledgers commit|union|only-bookkeeping — stage and
|
|
2
|
-
// an allow-list, never `git add -A
|
|
1
|
+
// bkit ledgers commit|union|only-bookkeeping|append|check|triage|compact — stage and
|
|
2
|
+
// commit bookkeeping by an allow-list, never `git add -A`; append validated rows with
|
|
3
|
+
// a minted `ts`; check that the ledger rows a plan names are on disk; drop superseded
|
|
4
|
+
// rows from the keyed ledgers.
|
|
3
5
|
//
|
|
4
6
|
// The pathspec is built by `git ls-files` against quoted globs, so git does the
|
|
5
7
|
// matching and an unmatched glob is empty output, never a shell abort. Staging
|
|
@@ -10,9 +12,13 @@ import { spawnSync } from "node:child_process";
|
|
|
10
12
|
import * as fs from "node:fs";
|
|
11
13
|
import * as os from "node:os";
|
|
12
14
|
import * as path from "node:path";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
+
import { readBkitVersion } from "../../install/version-file.js";
|
|
16
|
+
import { readBkitConfig } from "../../shared/settings.js";
|
|
17
|
+
import { APPEND_LEDGERS, SCHEMA, UNJUSTIFIED_REASON, gitEnv, parse, mintTs, resolveRepoSlug, validate, withLineage, writerProblem, } from "../../ledgers/telemetry.js";
|
|
18
|
+
import { COMPACT_LEDGERS, compactLedgers } from "../../ledgers/compact.js";
|
|
19
|
+
import { CommandError, EXIT, isIgnoredPath, isSharedBranch, parseJson, } from "../lib.js";
|
|
15
20
|
import { str } from "./status.js";
|
|
21
|
+
import { NO_MARKERS_REASON, outOfScope, parsePlanBlocks, reuseInventory, } from "./plan-blocks.js";
|
|
16
22
|
/** Root is not a directory or repo, git is too old, or a ref does not resolve. */
|
|
17
23
|
export const EXIT_ROOT = 3;
|
|
18
24
|
/** `git add` / `git add -u` / mkdir / copy failed. */
|
|
@@ -23,13 +29,20 @@ export const EXIT_COMMIT = 5;
|
|
|
23
29
|
export const EXIT_EMPTY = 6;
|
|
24
30
|
/** only-bookkeeping: a non-bookkeeping path changed, or from is not an ancestor of to. */
|
|
25
31
|
export const EXIT_NOT_BOOKKEEPING = 7;
|
|
32
|
+
/** append: a row was refused (supplied `ts`, wrong kind, invalid, unlisted writer). */
|
|
33
|
+
export const EXIT_ROW_REFUSED = 8;
|
|
26
34
|
const SCOPES = ["core", "full", "pr"];
|
|
27
35
|
const MODES = ["stage", "commit", "commit-allow-empty"];
|
|
36
|
+
/** `package.json` globs as git pathspecs: `:(glob)` unless an entry carries its own magic. */
|
|
37
|
+
export const globPathspecs = (paths) => paths.map((p) => (p.startsWith(":") ? p : `:(glob)${p}`));
|
|
28
38
|
/**
|
|
29
39
|
* The bookkeeping allow-list. Plain git pathspec `*` crosses `/`, so the
|
|
30
|
-
* top-level-only
|
|
40
|
+
* top-level-only entries use the `:(glob)` magic. `extra` is
|
|
41
|
+
* `bkit.testing.ciSkipPaths` (`ciSkipPaths`), the project docs a repo
|
|
42
|
+
* keeps outside `docs/*.md` (bkit's own: `CHANGELOG.md`, `README.md`); it reaches
|
|
43
|
+
* the `pr` scope only.
|
|
31
44
|
*/
|
|
32
|
-
export function bookPathspecs(month, fid, scope) {
|
|
45
|
+
export function bookPathspecs(month, fid, scope, extra = []) {
|
|
33
46
|
const specs = [
|
|
34
47
|
`docs/plans/${month}/logs/${fid}/*`,
|
|
35
48
|
".bkit/friction.jsonl",
|
|
@@ -43,11 +56,14 @@ export function bookPathspecs(month, fid, scope) {
|
|
|
43
56
|
if (scope === "full" || scope === "pr") {
|
|
44
57
|
specs.push("docs/deferrals.jsonl", "docs/failures.jsonl", "docs/knowledge.jsonl", "docs/decisions.jsonl", "skills-lock.json", ".agents/skills/*", ".claude/skills/*", ".cursor/skills/*", ".opencode/skills/*");
|
|
45
58
|
}
|
|
46
|
-
// `pr` adds the project docs ship's docs sync edits, for the commit that rides
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
// `pr` adds the project docs ship's docs sync edits, for the commit that rides the
|
|
60
|
+
// PR: top-level `docs/*.md`, plus whatever the repo names in `ciSkipPaths` (the
|
|
61
|
+
// engine hardcodes no file name; a glob nothing matches selects nothing). Kept out
|
|
62
|
+
// of `full` so a close on a laptop's dev checkout never sweeps unrelated dirty docs
|
|
63
|
+
// into its commit.
|
|
64
|
+
if (scope === "pr") {
|
|
65
|
+
specs.push(":(glob)docs/*.md", ...globPathspecs(extra));
|
|
66
|
+
}
|
|
51
67
|
return specs;
|
|
52
68
|
}
|
|
53
69
|
/** Ledgers a worktree teardown carries into the destination checkout. */
|
|
@@ -61,12 +77,13 @@ const UNION_PATHSPECS = [
|
|
|
61
77
|
":(exclude).bkit/issues.jsonl",
|
|
62
78
|
];
|
|
63
79
|
/** `git <args>` in `cwd`, never throwing and never trimming (NUL-delimited output). */
|
|
64
|
-
function gitRaw(cwd, args) {
|
|
80
|
+
function gitRaw(cwd, args, env = {}, input) {
|
|
65
81
|
const res = spawnSync("git", args, {
|
|
66
82
|
cwd,
|
|
67
83
|
encoding: "utf-8",
|
|
68
|
-
env: gitEnv(),
|
|
84
|
+
env: { ...gitEnv(), ...env },
|
|
69
85
|
maxBuffer: 1 << 28,
|
|
86
|
+
...(input === undefined ? {} : { input }),
|
|
70
87
|
});
|
|
71
88
|
// A spawn error is never a success: the child can exit 0 before ENOBUFS kills it.
|
|
72
89
|
const status = res.error && res.status === 0 ? 1 : res.status;
|
|
@@ -116,14 +133,414 @@ function dirtyTracked(root) {
|
|
|
116
133
|
.filter((l) => l !== "" && !l.startsWith("??"));
|
|
117
134
|
}
|
|
118
135
|
// ---------------------------------------------------------------------------
|
|
136
|
+
// Shared-checkout record — the one home
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
//
|
|
139
|
+
// An in-place run on `dev` shares its checkout with whatever else is dirty or
|
|
140
|
+
// committed there. At `worktrees setup` the run snapshots which paths were
|
|
141
|
+
// already dirty (and the HEAD it started from) into a per-clone file under the
|
|
142
|
+
// git dir, never committed. Every commit the run makes goes through
|
|
143
|
+
// `ownPathCommit`, which leaves those paths alone, and records its SHA so the
|
|
144
|
+
// push sends exactly the run's commits. Nothing else reads or writes the file.
|
|
145
|
+
/** Exit code: a path that was dirty before the run changed during it, so no commit was made. */
|
|
146
|
+
export const EXIT_FOREIGN_PATH = 10;
|
|
147
|
+
/** check: the plan has no `**Ledger rows:**` line, it is unfilled, or a key it names is on no ledger. */
|
|
148
|
+
export const EXIT_ROWS_MISSING = 11;
|
|
149
|
+
/** commit --scope=pr: the checkout is on `dev`, `main` or a detached HEAD, so nothing is committed. */
|
|
150
|
+
export const EXIT_SHARED_BRANCH = 12;
|
|
151
|
+
const RECORD_DIR = "bkit/shared-checkout";
|
|
152
|
+
const RECORD_FID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
153
|
+
/** The checkout's top: git status and pathspecs are relative to it, whatever `cwd` is. */
|
|
154
|
+
function topOf(cwd) {
|
|
155
|
+
const top = gitRaw(cwd, ["rev-parse", "--show-toplevel"]);
|
|
156
|
+
return top.status === 0 ? top.stdout.trim() : cwd;
|
|
157
|
+
}
|
|
158
|
+
/** `$(git rev-parse --git-path bkit/shared-checkout/{sub})`, absolute; null outside a repo. */
|
|
159
|
+
function recordPathOf(cwd, sub) {
|
|
160
|
+
const res = gitRaw(cwd, ["rev-parse", "--git-path", `${RECORD_DIR}/${sub}`]);
|
|
161
|
+
return res.status === 0 && res.stdout.trim() !== "" ? path.resolve(cwd, res.stdout.trim()) : null;
|
|
162
|
+
}
|
|
163
|
+
const recordFile = (cwd, fid) => RECORD_FID.test(fid) && !fid.includes("..") ? recordPathOf(cwd, `${fid}.json`) : null;
|
|
164
|
+
function asRecord(value) {
|
|
165
|
+
if (typeof value !== "object" || value === null)
|
|
166
|
+
return null;
|
|
167
|
+
const r = value;
|
|
168
|
+
if (typeof r.fid !== "string" ||
|
|
169
|
+
typeof r.branch !== "string" ||
|
|
170
|
+
typeof r.startSha !== "string" ||
|
|
171
|
+
typeof r.aheadAtStart !== "number" ||
|
|
172
|
+
!Array.isArray(r.paths) ||
|
|
173
|
+
!Array.isArray(r.commits))
|
|
174
|
+
return null;
|
|
175
|
+
return {
|
|
176
|
+
fid: r.fid,
|
|
177
|
+
branch: r.branch,
|
|
178
|
+
startSha: r.startSha,
|
|
179
|
+
originSha: typeof r.originSha === "string" ? r.originSha : null,
|
|
180
|
+
aheadAtStart: r.aheadAtStart,
|
|
181
|
+
paths: r.paths.filter((p) => typeof p?.path === "string"),
|
|
182
|
+
commits: r.commits.filter((c) => typeof c === "string"),
|
|
183
|
+
...(Array.isArray(r.pushed)
|
|
184
|
+
? { pushed: r.pushed.filter((c) => typeof c === "string") }
|
|
185
|
+
: {}),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/** The FID's record, or null when absent or unreadable. */
|
|
189
|
+
export function readRecord(cwd, fid) {
|
|
190
|
+
const file = recordFile(cwd, fid);
|
|
191
|
+
if (file === null || !fs.existsSync(file))
|
|
192
|
+
return null;
|
|
193
|
+
const parsed = parseJson(fs.readFileSync(file, "utf-8"));
|
|
194
|
+
return parsed.ok ? asRecord(parsed.value) : null;
|
|
195
|
+
}
|
|
196
|
+
/** Note run commits that now sit on origin/dev as replayed copies, so a later push skips them. */
|
|
197
|
+
export function markRecordPushed(cwd, fid, shas) {
|
|
198
|
+
const rec = readRecord(cwd, fid);
|
|
199
|
+
if (rec === null)
|
|
200
|
+
return;
|
|
201
|
+
writeRecord(cwd, { ...rec, pushed: [...new Set([...(rec.pushed ?? []), ...shas])] });
|
|
202
|
+
}
|
|
203
|
+
/** Every record in this clone. */
|
|
204
|
+
export function listRecords(cwd) {
|
|
205
|
+
const dir = recordPathOf(cwd, "");
|
|
206
|
+
if (dir === null || !fs.existsSync(dir))
|
|
207
|
+
return [];
|
|
208
|
+
return fs
|
|
209
|
+
.readdirSync(dir)
|
|
210
|
+
.filter((f) => f.endsWith(".json"))
|
|
211
|
+
.map((f) => readRecord(cwd, f.slice(0, -".json".length)))
|
|
212
|
+
.filter((r) => r !== null);
|
|
213
|
+
}
|
|
214
|
+
export function writeRecord(cwd, rec) {
|
|
215
|
+
const file = recordFile(cwd, rec.fid);
|
|
216
|
+
if (file === null)
|
|
217
|
+
throw new CommandError(EXIT_ROOT, `cannot place a record for "${rec.fid}"`);
|
|
218
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
219
|
+
fs.writeFileSync(file, `${JSON.stringify(rec, null, 2)}\n`);
|
|
220
|
+
}
|
|
221
|
+
/** A setup guard older than this is a crashed setup's leftover. */
|
|
222
|
+
const SETUP_GUARD_STALE_MS = 30_000;
|
|
223
|
+
/**
|
|
224
|
+
* Run `fn` as the only record-setup in this clone: an exclusive-create guard file
|
|
225
|
+
* next to the records makes the busy check and the record write one step. Returns
|
|
226
|
+
* null, without running `fn`, when another setup holds a fresh guard.
|
|
227
|
+
*/
|
|
228
|
+
export function withSetupGuard(cwd, fn) {
|
|
229
|
+
const guard = recordPathOf(cwd, ".setup.lock");
|
|
230
|
+
if (guard === null)
|
|
231
|
+
return { value: fn() };
|
|
232
|
+
fs.mkdirSync(path.dirname(guard), { recursive: true });
|
|
233
|
+
const take = () => {
|
|
234
|
+
try {
|
|
235
|
+
fs.closeSync(fs.openSync(guard, "wx"));
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
if (err.code === "EEXIST")
|
|
240
|
+
return false;
|
|
241
|
+
throw err;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
if (!take()) {
|
|
245
|
+
const age = fs.existsSync(guard) ? Date.now() - fs.statSync(guard).mtimeMs : Infinity;
|
|
246
|
+
if (age < SETUP_GUARD_STALE_MS)
|
|
247
|
+
return null;
|
|
248
|
+
fs.rmSync(guard, { force: true });
|
|
249
|
+
if (!take())
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
return { value: fn() };
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
fs.rmSync(guard, { force: true });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/** Remove the FID's record; false when there was none. */
|
|
260
|
+
export function removeRecord(cwd, fid) {
|
|
261
|
+
const file = recordFile(cwd, fid);
|
|
262
|
+
if (file === null || !fs.existsSync(file))
|
|
263
|
+
return false;
|
|
264
|
+
fs.rmSync(file, { force: true });
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
/** The FID's record, only while its branch is still the one checked out. */
|
|
268
|
+
export function activeRecord(cwd, fid) {
|
|
269
|
+
const rec = readRecord(cwd, fid);
|
|
270
|
+
if (rec === null)
|
|
271
|
+
return null;
|
|
272
|
+
const here = gitRaw(cwd, ["branch", "--show-current"]).stdout.trim();
|
|
273
|
+
return here === rec.branch ? rec : null;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The record of the run in place on `branch`, for a command that is not told
|
|
277
|
+
* its FID (the push). Setup keeps one live record per clone; if several are left
|
|
278
|
+
* over, the one written last wins.
|
|
279
|
+
*/
|
|
280
|
+
export function recordOnBranch(cwd, branch) {
|
|
281
|
+
const dir = recordPathOf(cwd, "");
|
|
282
|
+
const written = (r) => {
|
|
283
|
+
const file = recordFile(cwd, r.fid);
|
|
284
|
+
return file !== null && fs.existsSync(file) ? fs.statSync(file).mtimeMs : 0;
|
|
285
|
+
};
|
|
286
|
+
const ours = listRecords(cwd).filter((r) => r.branch === branch);
|
|
287
|
+
if (dir === null || ours.length === 0)
|
|
288
|
+
return null;
|
|
289
|
+
return ours.reduce((a, b) => (written(b) > written(a) ? b : a));
|
|
290
|
+
}
|
|
291
|
+
/** Append a commit the run made; called only after the commit succeeded. */
|
|
292
|
+
export function appendRecordCommit(cwd, fid, sha) {
|
|
293
|
+
const rec = readRecord(cwd, fid);
|
|
294
|
+
if (rec === null || rec.commits.includes(sha))
|
|
295
|
+
return;
|
|
296
|
+
writeRecord(cwd, { ...rec, commits: [...rec.commits, sha] });
|
|
297
|
+
}
|
|
298
|
+
/** Paths git reports as changed or untracked, relative to the top, one per file. */
|
|
299
|
+
function dirtyPaths(top) {
|
|
300
|
+
const res = gitRaw(top, ["status", "--porcelain", "-z", "-uall", "--no-renames"]);
|
|
301
|
+
return nulList(res.stdout)
|
|
302
|
+
.filter((e) => e.length > 3 && !e.startsWith("!!"))
|
|
303
|
+
.map((e) => e.slice(3));
|
|
304
|
+
}
|
|
305
|
+
/** `git hash-object` of the working file; null when it is gone. */
|
|
306
|
+
function hashOf(top, rel) {
|
|
307
|
+
const abs = path.join(top, rel);
|
|
308
|
+
if (!fs.existsSync(abs))
|
|
309
|
+
return null;
|
|
310
|
+
if (!fs.statSync(abs).isFile())
|
|
311
|
+
return "not-a-file";
|
|
312
|
+
const res = gitRaw(top, ["hash-object", "--", rel]);
|
|
313
|
+
return res.status === 0 ? res.stdout.trim() : "unhashable";
|
|
314
|
+
}
|
|
315
|
+
/** A text's non-blank lines. */
|
|
316
|
+
const rowsOf = (text) => text.split("\n").filter((l) => l.trim() !== "");
|
|
317
|
+
/** Lines of `file` in `cwd`'s working copy that its HEAD blob lacks (compared trimmed). */
|
|
318
|
+
export function rowsHeadLacks(cwd, file) {
|
|
319
|
+
const head = new Set(rowsOf(gitRaw(cwd, ["show", `HEAD:${file}`]).stdout).map((l) => l.trim()));
|
|
320
|
+
return rowsOf(fs.readFileSync(path.join(cwd, file), "utf-8")).filter((l) => !head.has(l.trim()));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Rows of `file` the run appended: lines HEAD lacks, and past the recorded line
|
|
324
|
+
* count when the run's record holds the file (rows before it are someone else's).
|
|
325
|
+
*/
|
|
326
|
+
export function runRows(cwd, file, rec) {
|
|
327
|
+
const was = rec?.paths.find((p) => p.path === file);
|
|
328
|
+
if (was?.lines === undefined)
|
|
329
|
+
return rowsHeadLacks(cwd, file);
|
|
330
|
+
const head = gitRaw(cwd, ["show", `HEAD:${file}`]);
|
|
331
|
+
const have = new Set(rowsOf(head.status === 0 ? head.stdout : "").map((l) => l.trim()));
|
|
332
|
+
const lines = fs.readFileSync(path.join(cwd, file), "utf-8").split("\n").slice(was.lines);
|
|
333
|
+
return rowsOf(lines.join("\n")).filter((l) => !have.has(l.trim()));
|
|
334
|
+
}
|
|
335
|
+
/** The record for a run starting now in `cwd` on `branch`. */
|
|
336
|
+
export function newRecord(cwd, fid, branch) {
|
|
337
|
+
const top = topOf(cwd);
|
|
338
|
+
const startSha = gitRaw(top, ["rev-parse", "HEAD"]).stdout.trim();
|
|
339
|
+
const origin = gitRaw(top, ["rev-parse", "-q", "--verify", `refs/remotes/origin/${branch}`]);
|
|
340
|
+
const originSha = origin.status === 0 ? origin.stdout.trim() : null;
|
|
341
|
+
const ahead = originSha === null
|
|
342
|
+
? 0
|
|
343
|
+
: Number(gitRaw(top, ["rev-list", "--count", `${originSha}..HEAD`]).stdout);
|
|
344
|
+
const paths = dirtyPaths(top).map((rel) => {
|
|
345
|
+
const hash = hashOf(top, rel);
|
|
346
|
+
const abs = path.join(top, rel);
|
|
347
|
+
const text = hash !== null && rel.endsWith(".jsonl") ? fs.readFileSync(abs, "utf-8") : null;
|
|
348
|
+
return text !== null && (text === "" || text.endsWith("\n"))
|
|
349
|
+
? { path: rel, hash, lines: fileLines(text).length }
|
|
350
|
+
: { path: rel, hash };
|
|
351
|
+
});
|
|
352
|
+
return { fid, branch, startSha, originSha, aheadAtStart: ahead, paths, commits: [] };
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* The paths that are the run's own: dirty now, minus every recorded path. A
|
|
356
|
+
* recorded append-only ledger contributes only the rows appended after the
|
|
357
|
+
* recorded line count that HEAD lacks. Any other recorded path whose content
|
|
358
|
+
* changed, or a ledger whose recorded lines changed, throws EXIT_FOREIGN_PATH.
|
|
359
|
+
* `among` limits which recorded paths count (a bookkeeping commit only commits
|
|
360
|
+
* its allow-list).
|
|
361
|
+
*/
|
|
362
|
+
export function ownSet(cwd, rec, among) {
|
|
363
|
+
const top = topOf(cwd);
|
|
364
|
+
const recorded = new Map(rec.paths.map((p) => [p.path, p]));
|
|
365
|
+
const out = { plain: [], ledgers: [] };
|
|
366
|
+
const foreign = [];
|
|
367
|
+
for (const rel of dirtyPaths(top)) {
|
|
368
|
+
const was = recorded.get(rel);
|
|
369
|
+
if (was === undefined) {
|
|
370
|
+
out.plain.push(rel);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (among !== undefined && !among.includes(rel))
|
|
374
|
+
continue;
|
|
375
|
+
if (hashOf(top, rel) === was.hash)
|
|
376
|
+
continue;
|
|
377
|
+
if (was.lines === undefined) {
|
|
378
|
+
foreign.push(rel);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const text = fs.readFileSync(path.join(top, rel), "utf-8");
|
|
382
|
+
const lines = text.split("\n");
|
|
383
|
+
const prefix = `${lines.slice(0, was.lines).join("\n")}\n`;
|
|
384
|
+
// `--path` applies the same clean / eol filters `hashOf` hashed the file with.
|
|
385
|
+
const prefixHash = gitRaw(top, ["hash-object", `--path=${rel}`, "--stdin"], {}, prefix).stdout.trim();
|
|
386
|
+
if (was.lines > 0 && prefixHash !== was.hash) {
|
|
387
|
+
foreign.push(rel);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const own = runRows(top, rel, rec);
|
|
391
|
+
if (own.length === 0)
|
|
392
|
+
continue;
|
|
393
|
+
const head = gitRaw(top, ["show", `HEAD:${rel}`]);
|
|
394
|
+
const base = head.status === 0 ? head.stdout : "";
|
|
395
|
+
const sep = base === "" || base.endsWith("\n") ? "" : "\n";
|
|
396
|
+
out.ledgers.push({ path: rel, text: `${base}${sep}${own.join("\n")}\n` });
|
|
397
|
+
}
|
|
398
|
+
if (foreign.length > 0) {
|
|
399
|
+
throw new CommandError(EXIT_FOREIGN_PATH, `refusing to commit: ${foreign.join(", ")} changed during the run but was already modified before it started — nothing committed; commit or revert ${foreign.length === 1 ? "it" : "them"} yourself, then re-run`);
|
|
400
|
+
}
|
|
401
|
+
return out;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Rebuild the real index entry of a ledger the user staged before the run: the
|
|
405
|
+
* new HEAD blob plus the staged rows HEAD lacks, so the user's next plain commit
|
|
406
|
+
* keeps the run's committed rows.
|
|
407
|
+
*/
|
|
408
|
+
function restageLedger(top, rel) {
|
|
409
|
+
const staged = gitRaw(top, ["show", `:${rel}`]);
|
|
410
|
+
const head = gitRaw(top, ["show", `HEAD:${rel}`]);
|
|
411
|
+
if (staged.status !== 0 || head.status !== 0)
|
|
412
|
+
return;
|
|
413
|
+
const have = new Set(rowsOf(head.stdout).map((l) => l.trim()));
|
|
414
|
+
const theirs = rowsOf(staged.stdout).filter((l) => !have.has(l.trim()));
|
|
415
|
+
if (theirs.length === 0) {
|
|
416
|
+
gitRaw(top, ["reset", "-q", "--", rel]);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const sep = head.stdout === "" || head.stdout.endsWith("\n") ? "" : "\n";
|
|
420
|
+
const blob = gitRaw(top, ["hash-object", "-w", "--stdin"], {}, `${head.stdout}${sep}${theirs.join("\n")}\n`);
|
|
421
|
+
if (blob.status !== 0)
|
|
422
|
+
return;
|
|
423
|
+
gitRaw(top, ["update-index", "--cacheinfo", `100644,${blob.stdout.trim()},${rel}`]);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Commit `set` and nothing else: foreign index entries stay staged and foreign
|
|
427
|
+
* files stay out. Plain files go through a pathspec commit; ledger rows, or an
|
|
428
|
+
* empty set, go through a temporary index read from HEAD. With `skipIfEmpty`, no
|
|
429
|
+
* change against HEAD makes no commit (`sha` null). The caller records the SHA.
|
|
430
|
+
*/
|
|
431
|
+
export function commitOwnSet(cwd, set, message, o = {}) {
|
|
432
|
+
const top = topOf(cwd);
|
|
433
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-own-"));
|
|
434
|
+
try {
|
|
435
|
+
const list = path.join(tmp, "list");
|
|
436
|
+
const all = [...set.plain, ...set.ledgers.map((l) => l.path)];
|
|
437
|
+
// `dirtyPaths` drops ignored entries, so `all` never holds one today; name the
|
|
438
|
+
// failure if a future caller passes a gitignored path, rather than let git's
|
|
439
|
+
// ignored-paths guard surface as an opaque stage error.
|
|
440
|
+
const ignored = all.filter((p) => isIgnoredPath(top, p));
|
|
441
|
+
if (ignored.length > 0) {
|
|
442
|
+
return { ok: false, error: `refusing to stage gitignored path(s): ${ignored.join(", ")}` };
|
|
443
|
+
}
|
|
444
|
+
fs.writeFileSync(list, all.map((p) => `${p}\0`).join(""));
|
|
445
|
+
const stagedBefore = new Set(nulList(gitRaw(top, ["diff", "--cached", "--name-only", "-z"]).stdout));
|
|
446
|
+
const tail = ["-m", message];
|
|
447
|
+
let made;
|
|
448
|
+
if (set.ledgers.length === 0 && set.plain.length > 0) {
|
|
449
|
+
const add = gitRaw(top, ["add", `--pathspec-from-file=${list}`, "--pathspec-file-nul"]);
|
|
450
|
+
if (add.status !== 0)
|
|
451
|
+
return { ok: false, error: `'git add' failed: ${add.stderr}` };
|
|
452
|
+
if (o.skipIfEmpty === true &&
|
|
453
|
+
gitRaw(top, ["diff", "--cached", "--quiet", "--", ...set.plain]).status === 0)
|
|
454
|
+
return { ok: true, sha: null };
|
|
455
|
+
made = gitRaw(top, [
|
|
456
|
+
"commit",
|
|
457
|
+
...(o.allowEmpty === true ? ["--allow-empty"] : []),
|
|
458
|
+
`--pathspec-from-file=${list}`,
|
|
459
|
+
"--pathspec-file-nul",
|
|
460
|
+
...tail,
|
|
461
|
+
]);
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
const env = { GIT_INDEX_FILE: path.join(tmp, "index") };
|
|
465
|
+
if (gitRaw(top, ["rev-parse", "-q", "--verify", "HEAD"]).status === 0) {
|
|
466
|
+
const read = gitRaw(top, ["read-tree", "HEAD"], env);
|
|
467
|
+
if (read.status !== 0)
|
|
468
|
+
return { ok: false, error: `'git read-tree' failed: ${read.stderr}` };
|
|
469
|
+
}
|
|
470
|
+
if (set.plain.length > 0) {
|
|
471
|
+
const add = gitRaw(top, ["add", `--pathspec-from-file=${list}`, "--pathspec-file-nul"], env);
|
|
472
|
+
if (add.status !== 0)
|
|
473
|
+
return { ok: false, error: `'git add' failed: ${add.stderr}` };
|
|
474
|
+
}
|
|
475
|
+
for (const l of set.ledgers) {
|
|
476
|
+
const blob = gitRaw(top, ["hash-object", "-w", "--stdin"], env, l.text);
|
|
477
|
+
const upd = gitRaw(top, ["update-index", "--add", "--cacheinfo", `100644,${blob.stdout.trim()},${l.path}`], env);
|
|
478
|
+
if (blob.status !== 0 || upd.status !== 0) {
|
|
479
|
+
return { ok: false, error: `'git update-index' failed: ${upd.stderr || blob.stderr}` };
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (o.skipIfEmpty === true && gitRaw(top, ["diff", "--cached", "--quiet"], env).status === 0)
|
|
483
|
+
return { ok: true, sha: null };
|
|
484
|
+
made = gitRaw(top, ["commit", ...(o.allowEmpty === true ? ["--allow-empty"] : []), ...tail], env);
|
|
485
|
+
if (made.status === 0 && all.length > 0) {
|
|
486
|
+
// The real index still holds the pre-commit entries; bring the run's own
|
|
487
|
+
// (unstaged-by-anyone-else) paths level with the new HEAD.
|
|
488
|
+
const reset = all.filter((p) => !stagedBefore.has(p));
|
|
489
|
+
fs.writeFileSync(list, reset.map((p) => `${p}\0`).join(""));
|
|
490
|
+
if (reset.length > 0) {
|
|
491
|
+
gitRaw(top, ["reset", "-q", `--pathspec-from-file=${list}`, "--pathspec-file-nul"]);
|
|
492
|
+
}
|
|
493
|
+
// A ledger the user had staged keeps their rows in the index, on top of the new HEAD's.
|
|
494
|
+
for (const l of set.ledgers)
|
|
495
|
+
if (stagedBefore.has(l.path))
|
|
496
|
+
restageLedger(top, l.path);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (made.status !== 0) {
|
|
500
|
+
// Leave the index as it was: unstage what this attempt staged, never another's entry.
|
|
501
|
+
const unstage = all.filter((p) => !stagedBefore.has(p));
|
|
502
|
+
fs.writeFileSync(list, unstage.map((p) => `${p}\0`).join(""));
|
|
503
|
+
if (unstage.length > 0)
|
|
504
|
+
gitRaw(top, ["reset", "-q", `--pathspec-from-file=${list}`, "--pathspec-file-nul"]);
|
|
505
|
+
return { ok: false, error: made.stderr || made.stdout.trim() };
|
|
506
|
+
}
|
|
507
|
+
return { ok: true, sha: gitRaw(top, ["rev-parse", "HEAD"]).stdout.trim() };
|
|
508
|
+
}
|
|
509
|
+
finally {
|
|
510
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* The run's own-path commit: compute the own set from the record, commit it,
|
|
515
|
+
* append the SHA to the record. Throws EXIT_FOREIGN_PATH before committing.
|
|
516
|
+
*/
|
|
517
|
+
export function ownPathCommit(cwd, rec, message, o = {}) {
|
|
518
|
+
const made = commitOwnSet(cwd, ownSet(cwd, rec), message, o);
|
|
519
|
+
if (made.ok && made.sha !== null)
|
|
520
|
+
appendRecordCommit(cwd, rec.fid, made.sha);
|
|
521
|
+
return made;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* An empty commit of the run's own: nothing from the working tree or the real
|
|
525
|
+
* index goes in, so a path the user staged never lands in it. The SHA is
|
|
526
|
+
* appended to the record.
|
|
527
|
+
*/
|
|
528
|
+
export function retriggerCommit(cwd, rec, message) {
|
|
529
|
+
const made = commitOwnSet(cwd, { plain: [], ledgers: [] }, message, { allowEmpty: true });
|
|
530
|
+
if (made.ok && made.sha !== null)
|
|
531
|
+
appendRecordCommit(cwd, rec.fid, made.sha);
|
|
532
|
+
return made;
|
|
533
|
+
}
|
|
534
|
+
// ---------------------------------------------------------------------------
|
|
119
535
|
// Command
|
|
120
536
|
// ---------------------------------------------------------------------------
|
|
121
537
|
export const ledgersCommand = {
|
|
122
538
|
noun: "ledgers",
|
|
123
|
-
summary: "Stage and commit bookkeeping by allow-list; union ledgers; check a range is bookkeeping only.",
|
|
539
|
+
summary: "Stage and commit bookkeeping by allow-list; union ledgers; check a range is bookkeeping only; compact keyed ledgers.",
|
|
124
540
|
verbs: {
|
|
125
541
|
commit: {
|
|
126
542
|
summary: "Stage (and commit) the bookkeeping allow-list for one feature.",
|
|
543
|
+
use: "workflow",
|
|
127
544
|
flags: [
|
|
128
545
|
ROOT_FLAG,
|
|
129
546
|
MONTH_FLAG,
|
|
@@ -131,8 +548,7 @@ export const ledgersCommand = {
|
|
|
131
548
|
{
|
|
132
549
|
name: "scope",
|
|
133
550
|
type: "string",
|
|
134
|
-
|
|
135
|
-
help: "core (logs + ledgers) | full (+ docs ledgers, skills) | pr (+ top-level docs/*.md)",
|
|
551
|
+
help: "core (logs + ledgers) | full (+ docs ledgers, skills) | pr (+ top-level docs/*.md); not with --path",
|
|
136
552
|
},
|
|
137
553
|
{
|
|
138
554
|
name: "mode",
|
|
@@ -143,7 +559,12 @@ export const ledgersCommand = {
|
|
|
143
559
|
{
|
|
144
560
|
name: "stage-tracked-updates",
|
|
145
561
|
type: "boolean",
|
|
146
|
-
help: "run `git add -u` first (stages every tracked change)",
|
|
562
|
+
help: "run `git add -u` first (stages every tracked change; commit modes commit them too)",
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
name: "path",
|
|
566
|
+
type: "string",
|
|
567
|
+
help: "commit this one path alone, relative to --root (commit modes only; no --scope)",
|
|
147
568
|
},
|
|
148
569
|
{
|
|
149
570
|
name: "squash-of",
|
|
@@ -160,19 +581,23 @@ export const ledgersCommand = {
|
|
|
160
581
|
output: {
|
|
161
582
|
outcome: "committed | staged | nothing-to-commit | clean (no tracked changes, with --only-if-dirty-tracked)",
|
|
162
583
|
commit: "the new commit's sha, or null",
|
|
163
|
-
paths: "bookkeeping paths the allow-list matched",
|
|
584
|
+
paths: "bookkeeping paths the allow-list matched (the --path alone with --path)",
|
|
585
|
+
tracked: "tracked paths --stage-tracked-updates staged into the commit",
|
|
164
586
|
squashPaths: "paths the --squash-of ref brought in",
|
|
165
587
|
},
|
|
166
588
|
exitCodes: {
|
|
167
589
|
[EXIT_ROOT]: "root not a directory or git repo, git < 2.25, or --squash-of does not resolve",
|
|
168
590
|
[EXIT_STAGE]: "staging failed (git add / git add -u)",
|
|
169
591
|
[EXIT_COMMIT]: "git commit failed",
|
|
170
|
-
[EXIT_EMPTY]: "the allow-list matched nothing — refusing to commit the whole index",
|
|
592
|
+
[EXIT_EMPTY]: "the allow-list matched nothing — refusing to commit the whole index; or --path is outside the checkout",
|
|
593
|
+
[EXIT_FOREIGN_PATH]: "an in-place run's allow-listed path was already modified before the run and changed during it — nothing committed",
|
|
594
|
+
[EXIT_SHARED_BRANCH]: "--scope=pr commit on dev, main or a detached HEAD — refused, nothing committed",
|
|
171
595
|
},
|
|
172
596
|
run: (ctx) => commit(ctx),
|
|
173
597
|
},
|
|
174
598
|
union: {
|
|
175
599
|
summary: "Append a worktree's new ledger rows into another checkout (never .bkit/issues.jsonl).",
|
|
600
|
+
use: "workflow",
|
|
176
601
|
flags: [
|
|
177
602
|
{ name: "src", type: "string", required: true, help: "worktree to read ledgers from" },
|
|
178
603
|
{ name: "dst", type: "string", required: true, help: "checkout to append them to" },
|
|
@@ -186,6 +611,7 @@ export const ledgersCommand = {
|
|
|
186
611
|
},
|
|
187
612
|
"only-bookkeeping": {
|
|
188
613
|
summary: "Exit 0 when every path changed in from..to is on the --scope=pr allow-list.",
|
|
614
|
+
use: "by-hand",
|
|
189
615
|
flags: [
|
|
190
616
|
ROOT_FLAG,
|
|
191
617
|
MONTH_FLAG,
|
|
@@ -204,14 +630,161 @@ export const ledgersCommand = {
|
|
|
204
630
|
},
|
|
205
631
|
run: (ctx) => onlyBookkeeping(ctx),
|
|
206
632
|
},
|
|
633
|
+
append: {
|
|
634
|
+
summary: "Append validated rows to one ledger, minting each row's ts at append time.",
|
|
635
|
+
use: "by-hand",
|
|
636
|
+
flags: [
|
|
637
|
+
{ name: "root", type: "string", help: "checkout whose ledger to append to (default: cwd)" },
|
|
638
|
+
{
|
|
639
|
+
name: "ledger",
|
|
640
|
+
type: "string",
|
|
641
|
+
required: true,
|
|
642
|
+
help: Object.keys(APPEND_LEDGERS).join(" | "),
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
name: "rows",
|
|
646
|
+
type: "string",
|
|
647
|
+
required: true,
|
|
648
|
+
help: "file holding a JSON array of rows without schema, ts or bkit, or - for stdin",
|
|
649
|
+
},
|
|
650
|
+
],
|
|
651
|
+
output: {
|
|
652
|
+
ledger: "the ledger appended to",
|
|
653
|
+
file: "its path, relative to --root",
|
|
654
|
+
appended: "rows written",
|
|
655
|
+
keys: "each row's key, in order (null when a row has none)",
|
|
656
|
+
},
|
|
657
|
+
exitCodes: {
|
|
658
|
+
[EXIT_STAGE]: "mkdir or append failed",
|
|
659
|
+
[EXIT_ROW_REFUSED]: "a row carries ts, has the wrong kind, fails validation, or names a writer not listed for its kind — nothing written",
|
|
660
|
+
},
|
|
661
|
+
run: (ctx) => append(ctx),
|
|
662
|
+
},
|
|
663
|
+
triage: {
|
|
664
|
+
summary: "Bucket each deferral row the FID declared by the four Deferral Reason tests, and write the unjustified ones.",
|
|
665
|
+
use: "workflow",
|
|
666
|
+
flags: [
|
|
667
|
+
{ name: "root", type: "string", help: "checkout whose deferrals to read (default: cwd)" },
|
|
668
|
+
FID_FLAG,
|
|
669
|
+
{
|
|
670
|
+
name: "plan",
|
|
671
|
+
type: "string",
|
|
672
|
+
required: true,
|
|
673
|
+
help: "plan file whose task surfaces and Out of Scope rows the four tests read",
|
|
674
|
+
},
|
|
675
|
+
],
|
|
676
|
+
output: {
|
|
677
|
+
fid: "the feature id triaged",
|
|
678
|
+
plan: "the plan the tests were read from",
|
|
679
|
+
rows: "each matched deferral's key, bucket (Exempt | Lazy), test results (none for a settled row: closed, LOW, or already adjudicated) and whether a row was written",
|
|
680
|
+
total: "deferral rows the FID matched",
|
|
681
|
+
written: "unjustified rows appended",
|
|
682
|
+
},
|
|
683
|
+
exitCodes: {
|
|
684
|
+
[EXIT_ROW_REFUSED]: "a computed unjustified row fails validation or its writer check — nothing written",
|
|
685
|
+
},
|
|
686
|
+
run: (ctx) => triage(ctx),
|
|
687
|
+
},
|
|
688
|
+
check: {
|
|
689
|
+
summary: "Check that every decision / deferral key on a plan's `**Ledger rows:**` line is on disk.",
|
|
690
|
+
use: "by-hand",
|
|
691
|
+
flags: [
|
|
692
|
+
{ name: "root", type: "string", help: "checkout whose ledgers to read (default: cwd)" },
|
|
693
|
+
{ name: "plan", type: "string", required: true, help: "plan file, relative to --root" },
|
|
694
|
+
],
|
|
695
|
+
output: {
|
|
696
|
+
plan: "the plan checked",
|
|
697
|
+
keys: "the keys its Ledger rows line names (empty for None)",
|
|
698
|
+
missing: "keys on neither docs/decisions.jsonl nor docs/deferrals.jsonl",
|
|
699
|
+
},
|
|
700
|
+
exitCodes: {
|
|
701
|
+
[EXIT_ROWS_MISSING]: "no `**Ledger rows:**` line, the line is unfilled, or a key it names has no row",
|
|
702
|
+
},
|
|
703
|
+
run: (ctx) => check(ctx),
|
|
704
|
+
},
|
|
705
|
+
compact: {
|
|
706
|
+
summary: "Rewrite keyed ledgers to their fold winners, stamping each winner's firstTs + updates.",
|
|
707
|
+
use: "by-hand",
|
|
708
|
+
flags: [
|
|
709
|
+
{ name: "root", type: "string", help: "checkout whose ledgers to compact (default: cwd)" },
|
|
710
|
+
{
|
|
711
|
+
name: "ledger",
|
|
712
|
+
type: "string",
|
|
713
|
+
help: `${Object.keys(COMPACT_LEDGERS).join(" | ")} | all (default: all)`,
|
|
714
|
+
},
|
|
715
|
+
{ name: "dry-run", type: "boolean", help: "count only; write nothing" },
|
|
716
|
+
],
|
|
717
|
+
output: {
|
|
718
|
+
dryRun: "true when nothing was written by design",
|
|
719
|
+
ledgers: "per ledger: ledger, file, rows (keyed rows folded), dropped (superseded rows removed), stamped (winners given firstTs / updates), written",
|
|
720
|
+
dropped: "superseded rows removed across all ledgers",
|
|
721
|
+
},
|
|
722
|
+
exitCodes: { [EXIT_STAGE]: "writing a compacted ledger failed" },
|
|
723
|
+
run: (ctx) => compact(ctx),
|
|
724
|
+
},
|
|
207
725
|
},
|
|
208
726
|
};
|
|
727
|
+
/** Commit one named path alone: `git add` it, then `git commit -- <path>`. */
|
|
728
|
+
function commitOnePath(o, log) {
|
|
729
|
+
const { root, mode, message } = o;
|
|
730
|
+
const rel = o.path;
|
|
731
|
+
const abs = path.resolve(root, rel);
|
|
732
|
+
const inside = path.relative(root, abs);
|
|
733
|
+
if (inside === "" || inside.startsWith("..") || path.isAbsolute(inside)) {
|
|
734
|
+
throw new CommandError(EXIT_EMPTY, `--path is outside the checkout: ${rel}`);
|
|
735
|
+
}
|
|
736
|
+
const done = (outcome, sha) => ({
|
|
737
|
+
outcome,
|
|
738
|
+
commit: sha,
|
|
739
|
+
paths: [inside],
|
|
740
|
+
squashPaths: [],
|
|
741
|
+
tracked: [],
|
|
742
|
+
});
|
|
743
|
+
if (isIgnoredPath(root, inside)) {
|
|
744
|
+
throw new CommandError(EXIT_STAGE, `--path is gitignored, refusing to stage it: ${inside}`);
|
|
745
|
+
}
|
|
746
|
+
const add = gitRaw(root, ["add", "--", inside]);
|
|
747
|
+
if (add.status !== 0)
|
|
748
|
+
throw new CommandError(EXIT_STAGE, `'git add' failed: ${add.stderr}`);
|
|
749
|
+
if (mode === "commit" &&
|
|
750
|
+
gitRaw(root, ["diff", "--cached", "--quiet", "--", inside]).status === 0) {
|
|
751
|
+
log(`nothing to commit at ${inside}`);
|
|
752
|
+
return done("nothing-to-commit", null);
|
|
753
|
+
}
|
|
754
|
+
const made = gitRaw(root, [
|
|
755
|
+
"commit",
|
|
756
|
+
...(mode === "commit-allow-empty" ? ["--allow-empty"] : []),
|
|
757
|
+
"-m",
|
|
758
|
+
message,
|
|
759
|
+
"--",
|
|
760
|
+
inside,
|
|
761
|
+
]);
|
|
762
|
+
if (made.status !== 0) {
|
|
763
|
+
throw new CommandError(EXIT_COMMIT, `'git commit' failed: ${made.stderr || made.stdout.trim()}`);
|
|
764
|
+
}
|
|
765
|
+
const sha = gitRaw(root, ["rev-parse", "HEAD"]).stdout.trim();
|
|
766
|
+
if (activeRecord(root, o.fid) !== null)
|
|
767
|
+
appendRecordCommit(root, o.fid, sha);
|
|
768
|
+
return done("committed", sha);
|
|
769
|
+
}
|
|
209
770
|
/**
|
|
210
771
|
* Stage (and commit) the bookkeeping allow-list for one feature. Throws a
|
|
211
772
|
* CommandError with EXIT_ROOT / EXIT_STAGE / EXIT_COMMIT / EXIT_EMPTY.
|
|
212
773
|
*/
|
|
213
774
|
export function commitBookkeeping(o, log) {
|
|
214
775
|
const { root, month, fid, scope, mode, message, squashOf } = o;
|
|
776
|
+
if (o.path !== undefined) {
|
|
777
|
+
if (mode === "stage" || !MODES.includes(mode)) {
|
|
778
|
+
throw new CommandError(EXIT.USAGE, "--path needs --mode=commit or commit-allow-empty");
|
|
779
|
+
}
|
|
780
|
+
if (o.stageTrackedUpdates === true || squashOf !== undefined || o.onlyIfDirtyTracked === true) {
|
|
781
|
+
throw new CommandError(EXIT.USAGE, "--path commits one path alone; drop --stage-tracked-updates, --squash-of and --only-if-dirty-tracked");
|
|
782
|
+
}
|
|
783
|
+
if (!message)
|
|
784
|
+
throw new CommandError(EXIT.USAGE, `--message is required for --mode=${mode}`);
|
|
785
|
+
requireRepo(root);
|
|
786
|
+
return commitOnePath(o, log);
|
|
787
|
+
}
|
|
215
788
|
if (!SCOPES.includes(scope)) {
|
|
216
789
|
throw new CommandError(EXIT.USAGE, `--scope must be core, full, or pr (got '${scope}')`);
|
|
217
790
|
}
|
|
@@ -224,6 +797,12 @@ export function commitBookkeeping(o, log) {
|
|
|
224
797
|
throw new CommandError(EXIT.USAGE, "--squash-of applies to commit modes only");
|
|
225
798
|
}
|
|
226
799
|
requireRepo(root);
|
|
800
|
+
if (scope === "pr" && mode !== "stage") {
|
|
801
|
+
const branch = gitRaw(root, ["branch", "--show-current"]).stdout.trim();
|
|
802
|
+
if (branch === "" || isSharedBranch(branch)) {
|
|
803
|
+
throw new CommandError(EXIT_SHARED_BRANCH, `--scope=pr commits a feature branch's bookkeeping: refusing to commit on '${branch || "detached HEAD"}'`);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
227
806
|
if (squashOf !== undefined &&
|
|
228
807
|
gitRaw(root, ["rev-parse", "-q", "--verify", `${squashOf}^{commit}`]).status !== 0) {
|
|
229
808
|
throw new CommandError(EXIT_ROOT, `--squash-of: unknown commit: ${squashOf}`);
|
|
@@ -233,17 +812,38 @@ export function commitBookkeeping(o, log) {
|
|
|
233
812
|
const dirty = dirtyTracked(root);
|
|
234
813
|
if (dirty.length === 0) {
|
|
235
814
|
log("no tracked file has uncommitted changes — nothing to commit");
|
|
236
|
-
return { outcome: "clean", commit: null, paths: [], squashPaths: [] };
|
|
815
|
+
return { outcome: "clean", commit: null, paths: [], squashPaths: [], tracked: [] };
|
|
237
816
|
}
|
|
238
817
|
for (const line of dirty)
|
|
239
818
|
log(line);
|
|
240
819
|
}
|
|
820
|
+
// An in-place run on a shared branch: recorded paths are someone else's.
|
|
821
|
+
const rec = squashOf === undefined ? activeRecord(root, fid) : null;
|
|
822
|
+
let tracked = [];
|
|
241
823
|
if (o.stageTrackedUpdates === true) {
|
|
242
|
-
|
|
824
|
+
// Throws EXIT_FOREIGN_PATH when any recorded path changed, before anything is staged.
|
|
825
|
+
if (rec !== null)
|
|
826
|
+
ownSet(root, rec);
|
|
827
|
+
const keepOut = (rec?.paths ?? []).map((p) => `:(exclude,literal)${p.path}`);
|
|
828
|
+
const res = gitRaw(root, ["add", "-u", ...(keepOut.length > 0 ? ["--", ".", ...keepOut] : [])]);
|
|
243
829
|
if (res.status !== 0)
|
|
244
830
|
throw new CommandError(EXIT_STAGE, `'git add -u' failed: ${res.stderr}`);
|
|
831
|
+
if (mode !== "stage") {
|
|
832
|
+
const cached = gitRaw(root, [
|
|
833
|
+
"diff",
|
|
834
|
+
"--cached",
|
|
835
|
+
"--name-only",
|
|
836
|
+
"-z",
|
|
837
|
+
"--no-renames",
|
|
838
|
+
...(keepOut.length > 0 ? ["--", ".", ...keepOut] : []),
|
|
839
|
+
]);
|
|
840
|
+
if (cached.status !== 0) {
|
|
841
|
+
throw new CommandError(EXIT_STAGE, `'git diff --cached' failed: ${cached.stderr}`);
|
|
842
|
+
}
|
|
843
|
+
tracked = nulList(cached.stdout);
|
|
844
|
+
}
|
|
245
845
|
}
|
|
246
|
-
const specs = bookPathspecs(month, fid, scope);
|
|
846
|
+
const specs = bookPathspecs(month, fid, scope, readBkitConfig(root).ciSkipPaths);
|
|
247
847
|
const listed = gitRaw(root, [
|
|
248
848
|
"ls-files",
|
|
249
849
|
"-z",
|
|
@@ -256,7 +856,14 @@ export function commitBookkeeping(o, log) {
|
|
|
256
856
|
if (listed.status !== 0) {
|
|
257
857
|
throw new CommandError(EXIT_ROOT, `'git ls-files' failed while building the pathspec: ${listed.stderr}`);
|
|
258
858
|
}
|
|
259
|
-
|
|
859
|
+
let paths = nulList(listed.stdout);
|
|
860
|
+
let ledgerRows = [];
|
|
861
|
+
if (rec !== null) {
|
|
862
|
+
// Throws EXIT_FOREIGN_PATH when a recorded path in the allow-list changed.
|
|
863
|
+
ledgerRows = ownSet(root, rec, paths).ledgers;
|
|
864
|
+
const recorded = new Set(rec.paths.map((p) => p.path));
|
|
865
|
+
paths = paths.filter((p) => !recorded.has(p));
|
|
866
|
+
}
|
|
260
867
|
let squashPaths = [];
|
|
261
868
|
if (squashOf !== undefined) {
|
|
262
869
|
const diff = gitRaw(root, ["diff", "--name-only", "-z", "--no-renames", `HEAD...${squashOf}`]);
|
|
@@ -265,33 +872,50 @@ export function commitBookkeeping(o, log) {
|
|
|
265
872
|
}
|
|
266
873
|
squashPaths = nulList(diff.stdout);
|
|
267
874
|
}
|
|
268
|
-
if (mode !== "stage" &&
|
|
875
|
+
if (mode !== "stage" &&
|
|
876
|
+
paths.length + squashPaths.length + ledgerRows.length + tracked.length === 0) {
|
|
269
877
|
// The pre-worktree commit records only bookkeeping; a dirty tree with none
|
|
270
878
|
// of it (a fresh consumer repo) has nothing of ours to commit, and stopping
|
|
271
879
|
// here never reaches `git commit`.
|
|
272
880
|
if (o.onlyIfDirtyTracked === true) {
|
|
273
881
|
log(`no bookkeeping under scope=${scope} in ${root} — nothing to commit`);
|
|
274
|
-
return { outcome: "nothing-to-commit", commit: null, paths, squashPaths };
|
|
882
|
+
return { outcome: "nothing-to-commit", commit: null, paths, squashPaths, tracked };
|
|
275
883
|
}
|
|
276
884
|
throw new CommandError(EXIT_EMPTY, `empty pathspec list — refusing to commit (nothing under scope=${scope} matched in ${root})`);
|
|
277
885
|
}
|
|
886
|
+
if (rec !== null && mode !== "stage" && ledgerRows.length > 0) {
|
|
887
|
+
const made = commitOwnSet(root, { plain: [...paths, ...tracked], ledgers: ledgerRows }, message, {
|
|
888
|
+
allowEmpty: mode === "commit-allow-empty",
|
|
889
|
+
skipIfEmpty: mode === "commit",
|
|
890
|
+
});
|
|
891
|
+
if (!made.ok)
|
|
892
|
+
throw new CommandError(EXIT_COMMIT, `'git commit' failed: ${made.error}`);
|
|
893
|
+
if (made.sha === null) {
|
|
894
|
+
log("nothing to commit");
|
|
895
|
+
return { outcome: "nothing-to-commit", commit: null, paths, squashPaths, tracked };
|
|
896
|
+
}
|
|
897
|
+
appendRecordCommit(root, fid, made.sha);
|
|
898
|
+
return { outcome: "committed", commit: made.sha, paths, squashPaths, tracked };
|
|
899
|
+
}
|
|
278
900
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "bkit-ledgers-"));
|
|
279
901
|
try {
|
|
280
902
|
const bookList = path.join(tmp, "book");
|
|
281
903
|
const commitList = path.join(tmp, "commit");
|
|
282
904
|
fs.writeFileSync(bookList, paths.map((p) => `${p}\0`).join(""));
|
|
283
|
-
|
|
905
|
+
const commitPaths = [...new Set([...paths, ...squashPaths, ...tracked])];
|
|
906
|
+
fs.writeFileSync(commitList, commitPaths.map((p) => `${p}\0`).join(""));
|
|
284
907
|
const add = gitRaw(root, ["add", `--pathspec-from-file=${bookList}`, "--pathspec-file-nul"]);
|
|
285
908
|
if (add.status !== 0)
|
|
286
909
|
throw new CommandError(EXIT_STAGE, `'git add' failed: ${add.stderr}`);
|
|
287
910
|
if (mode === "stage") {
|
|
288
911
|
log(`staged (scope=${scope})`);
|
|
289
|
-
return { outcome: "staged", commit: null, paths, squashPaths };
|
|
912
|
+
return { outcome: "staged", commit: null, paths, squashPaths, tracked };
|
|
290
913
|
}
|
|
291
914
|
if (mode === "commit" &&
|
|
292
|
-
gitRaw(root, ["diff", "--cached", "--quiet", "--", ...specs, ...squashPaths])
|
|
915
|
+
gitRaw(root, ["diff", "--cached", "--quiet", "--", ...specs, ...squashPaths, ...tracked])
|
|
916
|
+
.status === 0) {
|
|
293
917
|
log("nothing to commit");
|
|
294
|
-
return { outcome: "nothing-to-commit", commit: null, paths, squashPaths };
|
|
918
|
+
return { outcome: "nothing-to-commit", commit: null, paths, squashPaths, tracked };
|
|
295
919
|
}
|
|
296
920
|
const made = gitRaw(root, [
|
|
297
921
|
"commit",
|
|
@@ -304,12 +928,10 @@ export function commitBookkeeping(o, log) {
|
|
|
304
928
|
if (made.status !== 0) {
|
|
305
929
|
throw new CommandError(EXIT_COMMIT, `'git commit' failed: ${made.stderr || made.stdout.trim()}`);
|
|
306
930
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
squashPaths,
|
|
312
|
-
};
|
|
931
|
+
const sha = gitRaw(root, ["rev-parse", "HEAD"]).stdout.trim();
|
|
932
|
+
if (rec !== null)
|
|
933
|
+
appendRecordCommit(root, fid, sha);
|
|
934
|
+
return { outcome: "committed", commit: sha, paths, squashPaths, tracked };
|
|
313
935
|
}
|
|
314
936
|
finally {
|
|
315
937
|
fs.rmSync(tmp, { recursive: true, force: true });
|
|
@@ -322,12 +944,13 @@ function commit(ctx) {
|
|
|
322
944
|
root: rootOf(ctx),
|
|
323
945
|
month: required(ctx, "month"),
|
|
324
946
|
fid: required(ctx, "fid"),
|
|
325
|
-
scope: String(f.scope),
|
|
947
|
+
scope: String(f.scope ?? ""),
|
|
326
948
|
mode: String(f.mode),
|
|
327
949
|
message: str(f.message),
|
|
328
950
|
stageTrackedUpdates: f.stageTrackedUpdates === true,
|
|
329
951
|
squashOf: str(f.squashOf),
|
|
330
952
|
onlyIfDirtyTracked: f.onlyIfDirtyTracked === true,
|
|
953
|
+
path: str(f.path),
|
|
331
954
|
}, ctx.log),
|
|
332
955
|
});
|
|
333
956
|
return EXIT.OK;
|
|
@@ -391,6 +1014,202 @@ function union(ctx) {
|
|
|
391
1014
|
ctx.emit({ unioned: files.length, files });
|
|
392
1015
|
return EXIT.OK;
|
|
393
1016
|
}
|
|
1017
|
+
/** The top section in its written order, then the row's own fields. */
|
|
1018
|
+
const TOP_ORDER = [
|
|
1019
|
+
"schema",
|
|
1020
|
+
"ts",
|
|
1021
|
+
"firstTs",
|
|
1022
|
+
"updates",
|
|
1023
|
+
"kind",
|
|
1024
|
+
"key",
|
|
1025
|
+
"repo",
|
|
1026
|
+
"bkit",
|
|
1027
|
+
"by",
|
|
1028
|
+
"references",
|
|
1029
|
+
];
|
|
1030
|
+
/**
|
|
1031
|
+
* Append `rows` to one ledger. Every row is checked before any is written, so a
|
|
1032
|
+
* refused row leaves the file byte-identical. Each row gets `schema` and a `ts`
|
|
1033
|
+
* minted now (never supplied), `repo` when it lacks one and `bkit.version` from
|
|
1034
|
+
* `.bkit/version`; an `AGED_KINDS` row also gets `firstTs` + `updates` carried
|
|
1035
|
+
* forward from its entry's rows already in the ledger (supplied values replaced).
|
|
1036
|
+
* Never rewrites existing rows. Throws a CommandError (USAGE / EXIT_ROW_REFUSED /
|
|
1037
|
+
* EXIT_STAGE).
|
|
1038
|
+
*/
|
|
1039
|
+
export function appendLedgerRows(root, ledger, rows) {
|
|
1040
|
+
if (!Object.hasOwn(APPEND_LEDGERS, ledger)) {
|
|
1041
|
+
throw new CommandError(EXIT.USAGE, `--ledger must be one of ${Object.keys(APPEND_LEDGERS).join(", ")} (got '${ledger}')`);
|
|
1042
|
+
}
|
|
1043
|
+
const { file, kinds } = APPEND_LEDGERS[ledger];
|
|
1044
|
+
const takes = kinds;
|
|
1045
|
+
if (!Array.isArray(rows))
|
|
1046
|
+
throw new CommandError(EXIT.USAGE, "--rows must hold a JSON array");
|
|
1047
|
+
if (rows.length === 0)
|
|
1048
|
+
throw new CommandError(EXIT.USAGE, "--rows holds no rows");
|
|
1049
|
+
let repo;
|
|
1050
|
+
let version;
|
|
1051
|
+
let last;
|
|
1052
|
+
const abs = path.join(root, file);
|
|
1053
|
+
const prior = fs.existsSync(abs) ? parse(fs.readFileSync(abs, "utf-8")).events : [];
|
|
1054
|
+
const out = rows.map((raw, i) => {
|
|
1055
|
+
const refuse = (why) => new CommandError(EXIT_ROW_REFUSED, `row ${i + 1}: ${why}`);
|
|
1056
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
1057
|
+
throw refuse("not a JSON object");
|
|
1058
|
+
}
|
|
1059
|
+
const r = raw;
|
|
1060
|
+
if (Object.hasOwn(r, "ts"))
|
|
1061
|
+
throw refuse("carries ts; ts is minted at append time");
|
|
1062
|
+
if (Object.hasOwn(r, "schema"))
|
|
1063
|
+
throw refuse("carries schema; it is set at append time");
|
|
1064
|
+
if (!takes.includes(String(r["kind"]))) {
|
|
1065
|
+
throw refuse(`kind must be ${takes.join(" | ")} in --ledger=${ledger} (got ${String(r["kind"])})`);
|
|
1066
|
+
}
|
|
1067
|
+
if (Object.hasOwn(r, "bkit"))
|
|
1068
|
+
throw refuse("carries bkit; bkit.version is set at append time");
|
|
1069
|
+
repo ??= resolveRepoSlug(root) || "unknown/repo";
|
|
1070
|
+
version ??= readBkitVersion(path.join(root, ".bkit", "version"))?.pinnedVersion || "unknown";
|
|
1071
|
+
last = mintTs(last);
|
|
1072
|
+
const filled = withLineage(prior, {
|
|
1073
|
+
repo,
|
|
1074
|
+
...r,
|
|
1075
|
+
schema: SCHEMA,
|
|
1076
|
+
ts: last,
|
|
1077
|
+
bkit: { version },
|
|
1078
|
+
});
|
|
1079
|
+
const row = {};
|
|
1080
|
+
for (const k of TOP_ORDER)
|
|
1081
|
+
if (filled[k] !== undefined)
|
|
1082
|
+
row[k] = filled[k];
|
|
1083
|
+
for (const [k, v] of Object.entries(filled))
|
|
1084
|
+
if (!(k in row))
|
|
1085
|
+
row[k] = v;
|
|
1086
|
+
const v = validate(row);
|
|
1087
|
+
if (!v.ok)
|
|
1088
|
+
throw refuse(v.reason ?? "invalid");
|
|
1089
|
+
const who = writerProblem(row);
|
|
1090
|
+
if (who !== undefined)
|
|
1091
|
+
throw refuse(who);
|
|
1092
|
+
prior.push(row);
|
|
1093
|
+
return row;
|
|
1094
|
+
});
|
|
1095
|
+
const made = mkdirp(path.dirname(abs));
|
|
1096
|
+
if (made)
|
|
1097
|
+
throw new CommandError(EXIT_STAGE, `mkdir failed for ${path.dirname(file)}: ${made}`);
|
|
1098
|
+
const block = out.map((r) => `${JSON.stringify(r)}\n`).join("");
|
|
1099
|
+
// A file missing its final newline would glue the first row onto its last one.
|
|
1100
|
+
const appendErr = appendText(abs, endsMidLine(abs) ? `\n${block}` : block);
|
|
1101
|
+
if (appendErr)
|
|
1102
|
+
throw new CommandError(EXIT_STAGE, `append failed: ${file} — ${appendErr}`);
|
|
1103
|
+
return {
|
|
1104
|
+
ledger: ledger,
|
|
1105
|
+
file,
|
|
1106
|
+
appended: out.length,
|
|
1107
|
+
keys: out.map((r) => (typeof r["key"] === "string" ? r["key"] : null)),
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
/** True when `abs` exists, is non-empty and its last byte is not a newline. */
|
|
1111
|
+
function endsMidLine(abs) {
|
|
1112
|
+
let fd;
|
|
1113
|
+
try {
|
|
1114
|
+
fd = fs.openSync(abs, "r");
|
|
1115
|
+
const size = fs.fstatSync(fd).size;
|
|
1116
|
+
if (size === 0)
|
|
1117
|
+
return false;
|
|
1118
|
+
const last = Buffer.alloc(1);
|
|
1119
|
+
fs.readSync(fd, last, 0, 1, size - 1);
|
|
1120
|
+
return last[0] !== 0x0a;
|
|
1121
|
+
}
|
|
1122
|
+
catch {
|
|
1123
|
+
// No file yet: the append creates it.
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1126
|
+
finally {
|
|
1127
|
+
if (fd !== undefined)
|
|
1128
|
+
fs.closeSync(fd);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
function append(ctx) {
|
|
1132
|
+
const root = path.resolve(ctx.cwd, str(ctx.flags.root) ?? ".");
|
|
1133
|
+
const src = String(ctx.flags.rows);
|
|
1134
|
+
const read = readText(src === "-" ? 0 : path.resolve(ctx.cwd, src));
|
|
1135
|
+
if (!read.ok)
|
|
1136
|
+
throw new CommandError(EXIT.USAGE, `--rows unreadable: ${read.error}`);
|
|
1137
|
+
const text = read.text;
|
|
1138
|
+
if (text.trim() === "")
|
|
1139
|
+
throw new CommandError(EXIT.USAGE, "--rows holds no rows");
|
|
1140
|
+
const parsed = parseJson(text);
|
|
1141
|
+
if (!parsed.ok)
|
|
1142
|
+
throw new CommandError(EXIT.USAGE, "--rows is not JSON");
|
|
1143
|
+
const r = appendLedgerRows(root, String(ctx.flags.ledger), parsed.value);
|
|
1144
|
+
ctx.log(`appended ${r.appended} row(s) to ${r.file}`);
|
|
1145
|
+
ctx.emit({ ...r });
|
|
1146
|
+
return EXIT.OK;
|
|
1147
|
+
}
|
|
1148
|
+
const LEDGER_ROWS_LINE = /^\*\*Ledger rows:\*\*(.*)$/m;
|
|
1149
|
+
const CHECKED_LEDGERS = [APPEND_LEDGERS.decisions, APPEND_LEDGERS.deferrals];
|
|
1150
|
+
/**
|
|
1151
|
+
* Read the plan's `**Ledger rows:**` line — backticked keys, or `None` — and
|
|
1152
|
+
* return the keys no `decision` / `deferral` row carries. Throws EXIT_ROWS_MISSING
|
|
1153
|
+
* when the line is absent or still a placeholder.
|
|
1154
|
+
*/
|
|
1155
|
+
export function checkPlanRows(root, plan) {
|
|
1156
|
+
const abs = path.resolve(root, plan);
|
|
1157
|
+
if (!fs.existsSync(abs))
|
|
1158
|
+
throw new CommandError(EXIT.USAGE, `--plan not found: ${plan}`);
|
|
1159
|
+
const text = fs.readFileSync(abs, "utf-8");
|
|
1160
|
+
const line = LEDGER_ROWS_LINE.exec(text)?.[1]?.trim();
|
|
1161
|
+
if (line === undefined) {
|
|
1162
|
+
throw new CommandError(EXIT_ROWS_MISSING, `${plan} has no **Ledger rows:** line`);
|
|
1163
|
+
}
|
|
1164
|
+
const keys = [...line.matchAll(/`([^`]+)`/g)].map((m) => m[1] ?? "");
|
|
1165
|
+
if (keys.length === 0) {
|
|
1166
|
+
if (line.replace(/[."\s]/g, "") === "None")
|
|
1167
|
+
return { keys: [], missing: [] };
|
|
1168
|
+
throw new CommandError(EXIT_ROWS_MISSING, `${plan}: **Ledger rows:** is unfilled (${line})`);
|
|
1169
|
+
}
|
|
1170
|
+
const onDisk = new Set();
|
|
1171
|
+
for (const { file, kinds } of CHECKED_LEDGERS) {
|
|
1172
|
+
const abs = path.join(root, file);
|
|
1173
|
+
if (!fs.existsSync(abs))
|
|
1174
|
+
continue;
|
|
1175
|
+
for (const e of parse(fs.readFileSync(abs, "utf-8")).events) {
|
|
1176
|
+
const key = e.key;
|
|
1177
|
+
if (kinds.includes(e.kind) && typeof key === "string")
|
|
1178
|
+
onDisk.add(key);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
return { keys, missing: keys.filter((k) => !onDisk.has(k)) };
|
|
1182
|
+
}
|
|
1183
|
+
function check(ctx) {
|
|
1184
|
+
const root = rootOf(ctx);
|
|
1185
|
+
const plan = String(ctx.flags.plan);
|
|
1186
|
+
const r = checkPlanRows(root, plan);
|
|
1187
|
+
ctx.emit({ plan, ...r });
|
|
1188
|
+
if (r.missing.length > 0) {
|
|
1189
|
+
ctx.log(`${plan}: no ledger row for ${r.missing.join(", ")}`);
|
|
1190
|
+
return EXIT_ROWS_MISSING;
|
|
1191
|
+
}
|
|
1192
|
+
ctx.log(`${plan}: ${r.keys.length} ledger row(s) on disk`);
|
|
1193
|
+
return EXIT.OK;
|
|
1194
|
+
}
|
|
1195
|
+
function compact(ctx) {
|
|
1196
|
+
const root = rootOf(ctx);
|
|
1197
|
+
const named = str(ctx.flags.ledger) ?? "all";
|
|
1198
|
+
if (named !== "all" && !Object.hasOwn(COMPACT_LEDGERS, named)) {
|
|
1199
|
+
throw new CommandError(EXIT.USAGE, `--ledger must be one of ${Object.keys(COMPACT_LEDGERS).join(", ")}, all (got '${named}')`);
|
|
1200
|
+
}
|
|
1201
|
+
const ledgers = (named === "all" ? Object.keys(COMPACT_LEDGERS) : [named]);
|
|
1202
|
+
const dryRun = ctx.flags.dryRun === true;
|
|
1203
|
+
const results = compactOrError(root, ledgers, dryRun);
|
|
1204
|
+
if (typeof results === "string")
|
|
1205
|
+
throw new CommandError(EXIT_STAGE, `compact failed: ${results}`);
|
|
1206
|
+
const dropped = results.reduce((n, r) => n + r.dropped, 0);
|
|
1207
|
+
for (const r of results) {
|
|
1208
|
+
ctx.log(`${r.file}: ${r.dropped} superseded row(s) dropped, ${r.stamped} winner(s) stamped`);
|
|
1209
|
+
}
|
|
1210
|
+
ctx.emit({ dryRun, ledgers: results, dropped });
|
|
1211
|
+
return EXIT.OK;
|
|
1212
|
+
}
|
|
394
1213
|
/** mkdir -p; the error text, or undefined on success. */
|
|
395
1214
|
function mkdirp(dir) {
|
|
396
1215
|
try {
|
|
@@ -402,6 +1221,37 @@ function mkdirp(dir) {
|
|
|
402
1221
|
return err.message;
|
|
403
1222
|
}
|
|
404
1223
|
}
|
|
1224
|
+
/** {@link compactLedgers}; its results, or the error text. A failed temp write or rename leaves the ledger untouched. */
|
|
1225
|
+
function compactOrError(root, ledgers, dryRun) {
|
|
1226
|
+
try {
|
|
1227
|
+
return compactLedgers(root, ledgers, dryRun);
|
|
1228
|
+
}
|
|
1229
|
+
catch (err) {
|
|
1230
|
+
// Reported as the command's staging exit code, with the reason.
|
|
1231
|
+
return err.message;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
/** Append `text` to `file`; the error text, or undefined on success. */
|
|
1235
|
+
function appendText(file, text) {
|
|
1236
|
+
try {
|
|
1237
|
+
fs.appendFileSync(file, text);
|
|
1238
|
+
return undefined;
|
|
1239
|
+
}
|
|
1240
|
+
catch (err) {
|
|
1241
|
+
// Reported as the command's staging exit code, with the reason.
|
|
1242
|
+
return err.message;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
/** Read `file` (0 = stdin) as UTF-8; the text, or the error text. */
|
|
1246
|
+
function readText(file) {
|
|
1247
|
+
try {
|
|
1248
|
+
return { ok: true, text: fs.readFileSync(file, "utf-8") };
|
|
1249
|
+
}
|
|
1250
|
+
catch (err) {
|
|
1251
|
+
// Reported as a usage error, with the reason.
|
|
1252
|
+
return { ok: false, error: err.message };
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
405
1255
|
function copy(from, to) {
|
|
406
1256
|
try {
|
|
407
1257
|
fs.copyFileSync(from, to);
|
|
@@ -425,7 +1275,7 @@ export function checkOnlyBookkeeping(root, o) {
|
|
|
425
1275
|
if (gitRaw(root, ["merge-base", "--is-ancestor", o.from, o.to]).status !== 0) {
|
|
426
1276
|
return { kind: "not-ancestor" };
|
|
427
1277
|
}
|
|
428
|
-
const diff = changedOutside(root, o.from, o.to, bookPathspecs(o.month, o.fid, "pr"));
|
|
1278
|
+
const diff = changedOutside(root, o.from, o.to, bookPathspecs(o.month, o.fid, "pr", readBkitConfig(root).ciSkipPaths));
|
|
429
1279
|
if (!diff.ok)
|
|
430
1280
|
return { kind: "diff-failed", stderr: diff.stderr };
|
|
431
1281
|
return diff.outside.length ? { kind: "outside", outside: diff.outside } : { kind: "ok" };
|
|
@@ -487,3 +1337,239 @@ function onlyBookkeeping(ctx) {
|
|
|
487
1337
|
return EXIT.OK;
|
|
488
1338
|
}
|
|
489
1339
|
}
|
|
1340
|
+
// ---------------------------------------------------------------------------
|
|
1341
|
+
// triage — the sweep's deferral tests, computed
|
|
1342
|
+
// ---------------------------------------------------------------------------
|
|
1343
|
+
//
|
|
1344
|
+
// `.bkit/jsonl.md` § Deferral Reason states the four tests: each names a way a
|
|
1345
|
+
// deferral reads as in-scope work that should have been finished, and all four
|
|
1346
|
+
// holding marks the row `unjustified`. The engine decides them from the row, its
|
|
1347
|
+
// own `references`, the plan's task surfaces, its Reuse Inventory and its
|
|
1348
|
+
// Out of Scope table. The sweep keeps the judgement the four cannot reach.
|
|
1349
|
+
/** The four tests, in `.bkit/jsonl.md` order; each holds when the row reads as in-scope work. */
|
|
1350
|
+
export const DEFERRAL_TESTS = [
|
|
1351
|
+
"bounded-remediation",
|
|
1352
|
+
"in-scope-surface",
|
|
1353
|
+
"no-external-blocker",
|
|
1354
|
+
"own-declaration",
|
|
1355
|
+
];
|
|
1356
|
+
/** The issue number a FID leads with (`701-engine-work` → `701`), else "". */
|
|
1357
|
+
const fidIssue = (fid) => /^(\d+)(?=$|[-_])/.exec(fid)?.[1] ?? "";
|
|
1358
|
+
/** A row's `references` entries, as written. */
|
|
1359
|
+
const rowRefs = (row) => Array.isArray(row["references"])
|
|
1360
|
+
? row["references"].filter((x) => typeof x === "string")
|
|
1361
|
+
: [];
|
|
1362
|
+
/** True when `ref` names the feature: the FID, or its leading issue number as `N` / `#N`. */
|
|
1363
|
+
const namesFeature = (ref, fid, issue) => ref.includes(fid) || (issue !== "" && new RegExp(`^#?${issue}(?![0-9])`).test(ref));
|
|
1364
|
+
/** Every well-formed row of a JSONL ledger, as written. */
|
|
1365
|
+
function readLedgerRows(file) {
|
|
1366
|
+
if (!fs.existsSync(file))
|
|
1367
|
+
return [];
|
|
1368
|
+
return fs
|
|
1369
|
+
.readFileSync(file, "utf-8")
|
|
1370
|
+
.split("\n")
|
|
1371
|
+
.flatMap((line) => {
|
|
1372
|
+
if (line.trim() === "")
|
|
1373
|
+
return [];
|
|
1374
|
+
const parsed = parseJson(line);
|
|
1375
|
+
const v = parsed.ok ? parsed.value : null;
|
|
1376
|
+
return typeof v === "object" && v !== null && !Array.isArray(v)
|
|
1377
|
+
? [v]
|
|
1378
|
+
: [];
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
/** The deferral rows `fid` declared, same-`key` folded last-wins, in first-seen order. */
|
|
1382
|
+
export function featureDeferrals(rows, fid) {
|
|
1383
|
+
const issue = fidIssue(fid);
|
|
1384
|
+
const kept = [];
|
|
1385
|
+
const at = new Map();
|
|
1386
|
+
for (const row of rows) {
|
|
1387
|
+
if (row["kind"] !== "deferral")
|
|
1388
|
+
continue;
|
|
1389
|
+
const key = typeof row["key"] === "string" ? row["key"] : "";
|
|
1390
|
+
const named = key !== "" && namesFeature(key, fid, issue);
|
|
1391
|
+
if (!named && !rowRefs(row).some((r) => namesFeature(r, fid, issue)))
|
|
1392
|
+
continue;
|
|
1393
|
+
const seen = key === "" ? undefined : at.get(key);
|
|
1394
|
+
if (seen !== undefined) {
|
|
1395
|
+
kept[seen] = row;
|
|
1396
|
+
continue;
|
|
1397
|
+
}
|
|
1398
|
+
if (key !== "")
|
|
1399
|
+
at.set(key, kept.length);
|
|
1400
|
+
kept.push(row);
|
|
1401
|
+
}
|
|
1402
|
+
return kept;
|
|
1403
|
+
}
|
|
1404
|
+
/** A repo path a token names, with any `:line` suffix cut; null when the token is no path. */
|
|
1405
|
+
function pathToken(token) {
|
|
1406
|
+
const t = token
|
|
1407
|
+
.trim()
|
|
1408
|
+
.replace(/:\d+(?:-\d+)?$/, "")
|
|
1409
|
+
.replace(/[.,;:]+$/, "")
|
|
1410
|
+
.replace(/^\.\//, "");
|
|
1411
|
+
if (t === "" || /\s/.test(t) || t.startsWith("#") || /^[a-z][a-z0-9+.-]*:\/\//i.test(t))
|
|
1412
|
+
return null;
|
|
1413
|
+
if (!t.includes("/") && !/\.[A-Za-z][A-Za-z0-9]{0,5}$/.test(t))
|
|
1414
|
+
return null;
|
|
1415
|
+
return path.posix.normalize(t);
|
|
1416
|
+
}
|
|
1417
|
+
/** The repo paths a row names: backticked spans and bare words of its `remediation`, plus its `references`. */
|
|
1418
|
+
function namedPaths(row) {
|
|
1419
|
+
const texts = [
|
|
1420
|
+
...(typeof row["remediation"] === "string" ? [row["remediation"]] : []),
|
|
1421
|
+
...rowRefs(row),
|
|
1422
|
+
];
|
|
1423
|
+
const tokens = texts.flatMap((t) => [
|
|
1424
|
+
...[...t.matchAll(/`([^`]+)`/g)].map((m) => m[1]),
|
|
1425
|
+
...t.replace(/`[^`]*`/g, " ").split(/[\s,()[\]]+/),
|
|
1426
|
+
]);
|
|
1427
|
+
return [
|
|
1428
|
+
...new Set(tokens.map(pathToken).filter((p) => p !== null && p !== "." && p !== "..")),
|
|
1429
|
+
];
|
|
1430
|
+
}
|
|
1431
|
+
/** True when one of `paths` is a file in `root`. */
|
|
1432
|
+
function existsIn(root, paths) {
|
|
1433
|
+
return paths.some((p) => {
|
|
1434
|
+
const abs = path.resolve(root, p);
|
|
1435
|
+
const rel = path.relative(root, abs);
|
|
1436
|
+
return rel !== "" && !rel.startsWith("..") && !path.isAbsolute(rel) && fs.existsSync(abs);
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
/** True when `a` and `b` name the same path, or one sits inside the other. */
|
|
1440
|
+
const within = (a, b) => a === b || a.startsWith(`${b}/`) || b.startsWith(`${a}/`);
|
|
1441
|
+
const NORMAL = (s) => s.toLowerCase().replace(/\s+/g, " ").trim();
|
|
1442
|
+
/** The items the plan's `Out of Scope` rows declare: their excluded item and every backticked token. */
|
|
1443
|
+
function declaredItems(rows) {
|
|
1444
|
+
const out = new Set();
|
|
1445
|
+
for (const row of rows ?? []) {
|
|
1446
|
+
const item = row.cells[0] ?? "";
|
|
1447
|
+
if (item !== "")
|
|
1448
|
+
out.add(NORMAL(item));
|
|
1449
|
+
for (const cell of row.cells)
|
|
1450
|
+
for (const m of cell.matchAll(/`([^`]+)`/g))
|
|
1451
|
+
if (m[1].trim() !== "")
|
|
1452
|
+
out.add(NORMAL(m[1]));
|
|
1453
|
+
}
|
|
1454
|
+
return out;
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* True when a reference other than the row's own key or the bare FID names a
|
|
1458
|
+
* pre-existing declaration: a plan `Out of Scope` item, or a doc section declared
|
|
1459
|
+
* out of scope. A row that is its own only declaration names none.
|
|
1460
|
+
*/
|
|
1461
|
+
function declares(row, fid, issue, declared) {
|
|
1462
|
+
const own = typeof row["key"] === "string" ? NORMAL(row["key"]) : "";
|
|
1463
|
+
const self = NORMAL(fid);
|
|
1464
|
+
for (const ref of rowRefs(row)) {
|
|
1465
|
+
const t = ref.trim();
|
|
1466
|
+
if (t === "" || NORMAL(t) === own || NORMAL(t) === self || t === `#${issue}`)
|
|
1467
|
+
continue;
|
|
1468
|
+
if (t.includes("§") && /out[- ]of[- ]scope|non-?goals?/i.test(t))
|
|
1469
|
+
return true;
|
|
1470
|
+
const n = NORMAL(t);
|
|
1471
|
+
if (declared.has(n))
|
|
1472
|
+
return true;
|
|
1473
|
+
for (const d of declared)
|
|
1474
|
+
if (d.length >= 8 && n.includes(d))
|
|
1475
|
+
return true;
|
|
1476
|
+
}
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
/** The same-`key` row triage appends: every prior field verbatim, the verdict fields replaced. */
|
|
1480
|
+
export function unjustifiedRow(row, fid, held) {
|
|
1481
|
+
const out = {};
|
|
1482
|
+
for (const [k, v] of Object.entries(row)) {
|
|
1483
|
+
if (k === "schema" || k === "ts" || k === "bkit" || k === "by" || k === "description")
|
|
1484
|
+
continue;
|
|
1485
|
+
out[k] = v;
|
|
1486
|
+
}
|
|
1487
|
+
out["kind"] = "deferral";
|
|
1488
|
+
out["reason"] = UNJUSTIFIED_REASON;
|
|
1489
|
+
out["status"] = "TRIAGED";
|
|
1490
|
+
out["description"] =
|
|
1491
|
+
`Adjudicated unjustified by bkit ledgers triage for ${fid}: every deferral test holds (${held.join(", ")}).`;
|
|
1492
|
+
// The ship orchestrator's sweep step is the writer, so the row clears the kind's writer check.
|
|
1493
|
+
out["by"] = { workflow: "ship", step: "ship-deferred-sweep" };
|
|
1494
|
+
return out;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Bucket the FID's deferral rows by the four tests and append a same-`key`
|
|
1498
|
+
* `unjustified` / `TRIAGED` row for each that holds all four. Throws
|
|
1499
|
+
* CommandError(USAGE) on a missing `--plan` or a plan whose task blocks do not
|
|
1500
|
+
* parse, CommandError(NO) on a plan with no task blocks — nothing written either
|
|
1501
|
+
* way — and EXIT_ROW_REFUSED when a computed row fails validation.
|
|
1502
|
+
*/
|
|
1503
|
+
export function triageDeferrals(root, fid, planPath) {
|
|
1504
|
+
const abs = path.resolve(root, planPath);
|
|
1505
|
+
if (!fs.existsSync(abs))
|
|
1506
|
+
throw new CommandError(EXIT.USAGE, `--plan not found: ${planPath}`);
|
|
1507
|
+
const text = fs.readFileSync(abs, "utf-8");
|
|
1508
|
+
const blocks = parsePlanBlocks(text);
|
|
1509
|
+
const error = blocks.errors[0];
|
|
1510
|
+
if (error !== undefined)
|
|
1511
|
+
throw new CommandError(EXIT.USAGE, `${planPath}:${error.line}: ${error.message} — run \`bkit tests plan-check\``);
|
|
1512
|
+
// No task block means no task surface: every row would bucket `Exempt` unread.
|
|
1513
|
+
if (blocks.tasks.length === 0)
|
|
1514
|
+
throw new CommandError(EXIT.NO, `${planPath}: ${NO_MARKERS_REASON}`);
|
|
1515
|
+
const surfaces = new Set();
|
|
1516
|
+
for (const task of blocks.tasks)
|
|
1517
|
+
for (const ref of [...task.create, ...task.read, ...task.update, ...task.delete])
|
|
1518
|
+
surfaces.add(path.posix.normalize(ref.file));
|
|
1519
|
+
for (const row of reuseInventory(text)?.rows ?? [])
|
|
1520
|
+
for (const f of row.files)
|
|
1521
|
+
surfaces.add(f);
|
|
1522
|
+
const scope = [...surfaces];
|
|
1523
|
+
const declared = declaredItems(outOfScope(text));
|
|
1524
|
+
const issue = fidIssue(fid);
|
|
1525
|
+
const rows = featureDeferrals(readLedgerRows(path.join(root, APPEND_LEDGERS.deferrals.file)), fid);
|
|
1526
|
+
const out = [];
|
|
1527
|
+
const write = [];
|
|
1528
|
+
for (const row of rows) {
|
|
1529
|
+
const key = typeof row["key"] === "string" ? row["key"] : null;
|
|
1530
|
+
// Closed work is done: nothing to test, nothing to write.
|
|
1531
|
+
if (row["status"] === "CLOSED") {
|
|
1532
|
+
out.push({ key, bucket: "Exempt", tests: [], written: false });
|
|
1533
|
+
continue;
|
|
1534
|
+
}
|
|
1535
|
+
// A LOW challenge finding holds without the tests, and an adjudicated row is never
|
|
1536
|
+
// re-adjudicated: it keeps the `Lazy` bucket its adjudication earned, so an
|
|
1537
|
+
// outstanding unjustified deferral never reads as `Exempt Deferrals`.
|
|
1538
|
+
if (row["reason"] === UNJUSTIFIED_REASON) {
|
|
1539
|
+
out.push({ key, bucket: "Lazy", tests: [], written: false });
|
|
1540
|
+
continue;
|
|
1541
|
+
}
|
|
1542
|
+
if (row["reason"] === "low-severity" && row["severity"] === "LOW") {
|
|
1543
|
+
out.push({ key, bucket: "Exempt", tests: [], written: false });
|
|
1544
|
+
continue;
|
|
1545
|
+
}
|
|
1546
|
+
const paths = namedPaths(row);
|
|
1547
|
+
const verdicts = {
|
|
1548
|
+
// Test 1 reads "not a new architecture": an `own-cycle` row declares itself plan-sized.
|
|
1549
|
+
"bounded-remediation": row["reason"] !== "own-cycle" && existsIn(root, paths),
|
|
1550
|
+
"in-scope-surface": paths.some((p) => scope.some((s) => within(p, s))),
|
|
1551
|
+
"no-external-blocker": row["reason"] !== "hard-blocked" && row["reason"] !== "needs-decision",
|
|
1552
|
+
"own-declaration": !declares(row, fid, issue, declared),
|
|
1553
|
+
};
|
|
1554
|
+
const tests = DEFERRAL_TESTS.map((test) => ({ test, held: verdicts[test] }));
|
|
1555
|
+
const lazy = tests.every((t) => t.held);
|
|
1556
|
+
if (lazy)
|
|
1557
|
+
write.push(unjustifiedRow(row, fid, tests.map((t) => t.test)));
|
|
1558
|
+
out.push({ key, bucket: lazy ? "Lazy" : "Exempt", tests, written: lazy });
|
|
1559
|
+
}
|
|
1560
|
+
if (write.length > 0)
|
|
1561
|
+
appendLedgerRows(root, "deferrals", write);
|
|
1562
|
+
return { fid, plan: planPath, rows: out, total: out.length, written: write.length };
|
|
1563
|
+
}
|
|
1564
|
+
function triage(ctx) {
|
|
1565
|
+
const r = triageDeferrals(rootOf(ctx), required(ctx, "fid"), required(ctx, "plan"));
|
|
1566
|
+
for (const row of r.rows) {
|
|
1567
|
+
const verdict = row.tests.length === 0
|
|
1568
|
+
? "not tested"
|
|
1569
|
+
: row.tests.map((t) => `${t.test} ${t.held ? "holds" : "fails"}`).join(", ");
|
|
1570
|
+
ctx.log(`${row.key ?? "(no key)"} — ${row.bucket}: ${verdict}`);
|
|
1571
|
+
}
|
|
1572
|
+
ctx.log(`${r.total} deferral row(s) for ${r.fid}, ${r.written} written unjustified`);
|
|
1573
|
+
ctx.emit({ ...r });
|
|
1574
|
+
return EXIT.OK;
|
|
1575
|
+
}
|