@cbartens/bkit 5.3.0 → 5.5.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 +20 -7
- package/.bkit/core/.agents/docs.md +1 -1
- package/.bkit/core/.agents/rules.md +14 -9
- package/.bkit/core/.bkit/README.md +19 -6
- package/.bkit/core/.bkit/cloud.md +77 -46
- package/.bkit/core/.bkit/comparison.md +3 -3
- package/.bkit/core/.bkit/install.md +21 -18
- package/.bkit/core/.bkit/lite.md +6 -6
- package/.bkit/core/.bkit/pipeline.md +6 -3
- package/.bkit/core/.bkit/prompts.md +14 -10
- package/.bkit/core/.bkit/providers.md +7 -7
- package/.bkit/core/.bkit/templates.md +46 -10
- package/.bkit/core/.bkit/trackers.md +92 -38
- package/.bkit/core/.bkit/workflows.md +140 -116
- package/.bkit/core/AGENTS.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-agents.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +4 -2
- package/.bkit/core/docs/templates/bkit-audit-config.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-cost.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-database.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +5 -5
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +14 -13
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-failures.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -2
- package/.bkit/core/docs/templates/bkit-audit-issues.md +25 -8
- package/.bkit/core/docs/templates/bkit-audit-llm.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-logs.md +10 -6
- package/.bkit/core/docs/templates/bkit-audit-models.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +5 -5
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +3 -2
- package/.bkit/core/docs/templates/bkit-audit-repo.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-security.md +11 -9
- package/.bkit/core/docs/templates/bkit-audit-slop.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-testing.md +6 -5
- package/.bkit/core/docs/templates/bkit-audit-usability.md +1 -1
- package/.bkit/core/engine/checks/after/auth.ts +88 -45
- package/.bkit/core/engine/checks/after/github.ts +18 -5
- package/.bkit/core/engine/checks/after/index.ts +1 -1
- package/.bkit/core/engine/checks/after/tools.ts +1 -1
- package/.bkit/core/engine/checks/before/env.ts +28 -18
- package/.bkit/core/engine/checks/before/mcp.ts +4 -2
- package/.bkit/core/engine/checks/status-holes.ts +0 -1
- package/.bkit/core/engine/checks/tips/catalogue.ts +31 -2
- package/.bkit/core/engine/checks/tips/index.ts +49 -27
- package/.bkit/core/engine/cli.ts +27 -18
- package/.bkit/core/engine/commands/ci/ci.ts +107 -0
- package/.bkit/core/engine/commands/comply.ts +25 -16
- package/.bkit/core/engine/commands/install/install.ts +11 -4
- package/.bkit/core/engine/commands/install/uninstall.ts +46 -0
- package/.bkit/core/engine/commands/land.ts +156 -0
- package/.bkit/core/engine/commands/lib.ts +10 -8
- package/.bkit/core/engine/commands/registry.ts +2 -0
- package/.bkit/core/engine/commands/tips.ts +7 -3
- package/.bkit/core/engine/commands/workflow/branches.ts +382 -282
- package/.bkit/core/engine/commands/workflow/disk.ts +556 -0
- package/.bkit/core/engine/commands/workflow/fids.ts +23 -15
- package/.bkit/core/engine/commands/workflow/issues.ts +106 -42
- package/.bkit/core/engine/commands/workflow/ledgers.ts +28 -11
- package/.bkit/core/engine/commands/workflow/locks.ts +38 -152
- package/.bkit/core/engine/commands/workflow/prs.ts +14 -3
- package/.bkit/core/engine/commands/workflow/repo.ts +6 -0
- package/.bkit/core/engine/commands/workflow/roadmap.ts +53 -54
- package/.bkit/core/engine/commands/workflow/runtime.ts +3 -2
- package/.bkit/core/engine/commands/workflow/status.ts +33 -11
- package/.bkit/core/engine/commands/workflow/steps.ts +26 -17
- package/.bkit/core/engine/commands/workflow/workflows.ts +442 -269
- package/.bkit/core/engine/commands/workflow/workstreams.ts +3 -2
- package/.bkit/core/engine/commands/workflow/worktrees.ts +11 -1
- package/.bkit/core/engine/install/manifest.ts +31 -10
- package/.bkit/core/engine/install/modules/cloud.ts +3 -1
- package/.bkit/core/engine/install/modules/core.ts +97 -4
- package/.bkit/core/engine/install/modules/opencode.ts +5 -0
- package/.bkit/core/engine/install/placeholders.ts +13 -17
- package/.bkit/core/engine/install/write.ts +37 -1
- package/.bkit/core/engine/render/trackers.ts +35 -23
- package/.bkit/core/engine/shared/egress.ts +6 -0
- package/.bkit/core/engine/shared/settings.ts +96 -1
- package/.bkit/core/engine/shared/timeouts.ts +8 -7
- package/.bkit/core/hooks/guardrails-tiers.js +1 -1
- package/.bkit/core/prompts/bkit-audit-generate.md +80 -7
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-execute.md +1 -1
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +1 -1
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +1 -1
- package/.bkit/core/prompts/bkit-design-generate.md +2 -1
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +1 -1
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +4 -2
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +4 -2
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +12 -2
- package/.bkit/core/prompts/bkit-utility-update-failures.md +4 -2
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +4 -2
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +12 -5
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +159 -0
- package/.bkit/core/workflows/bkit-auto.md +19 -6
- package/.bkit/core/workflows/bkit-build.md +64 -22
- package/.bkit/core/workflows/bkit-debug.md +72 -28
- package/.bkit/core/workflows/bkit-design.md +101 -37
- package/.bkit/core/workflows/bkit-plan.md +82 -31
- package/.bkit/core/workflows/bkit-ship.md +127 -108
- package/.bkit/shared/.bkit/.env.example +8 -0
- package/.bkit/shared/.claude/bkit-cloud.md +12 -12
- package/.bkit/shared/.claude/settings.json +4 -1
- package/.bkit/shared/.cursor/bkit-cloud.md +2 -2
- package/.bkit/shared/.cursor/mcp.json +11 -4
- package/.bkit/shared/.mcp.json +11 -4
- package/.bkit/shared/.opencode/opencode.json +2 -0
- package/.bkit/shared/docs/deployments.md +44 -29
- package/.bkit/shared/docs/security.md +1 -1
- package/.bkit/shared/docs/testing.md +3 -3
- package/.bkit/shared/gitignore +1 -2
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +2 -2
- package/.bkit/templates/.github/renovate.json5 +1 -1
- package/.bkit/templates/.github/workflows/bkit-ci.yml +29 -56
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +40 -12
- package/.bkit/templates/.husky/pre-commit +10 -4
- package/.bkit/templates/.husky/pre-push +69 -12
- package/.bkit/templates/.lintstagedrc.json +5 -1
- package/.bkit/templates/scripts/ci/lanes/check-tree-cache.mjs +138 -0
- package/.bkit/templates/scripts/ci/lanes/check-tree-cache.test.mjs +181 -0
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.machine.mjs +197 -0
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +164 -0
- package/.bkit/templates/scripts/graphify/bkit-graphify.sh +1 -1
- package/CHANGELOG.md +85 -1
- package/README.md +102 -100
- package/dist/checks/after/auth.js +81 -45
- package/dist/checks/after/github.js +17 -5
- package/dist/checks/after/index.js +1 -1
- package/dist/checks/after/tools.js +1 -1
- package/dist/checks/before/env.js +24 -17
- package/dist/checks/before/mcp.js +4 -2
- package/dist/checks/status-holes.js +0 -1
- package/dist/checks/tips/catalogue.js +28 -2
- package/dist/checks/tips/index.js +44 -28
- package/dist/cli.js +27 -19
- package/dist/commands/ci/ci.js +100 -0
- package/dist/commands/comply.js +20 -13
- package/dist/commands/install/install.js +10 -4
- package/dist/commands/install/uninstall.js +42 -0
- package/dist/commands/land.js +129 -0
- package/dist/commands/lib.js +9 -6
- package/dist/commands/registry.js +2 -0
- package/dist/commands/tips.js +7 -3
- package/dist/commands/workflow/branches.js +300 -243
- package/dist/commands/workflow/disk.js +452 -0
- package/dist/commands/workflow/fids.js +22 -15
- package/dist/commands/workflow/issues.js +90 -41
- package/dist/commands/workflow/ledgers.js +26 -11
- package/dist/commands/workflow/locks.js +35 -130
- package/dist/commands/workflow/prs.js +8 -3
- package/dist/commands/workflow/repo.js +5 -0
- package/dist/commands/workflow/roadmap.js +52 -57
- package/dist/commands/workflow/runtime.js +3 -2
- package/dist/commands/workflow/status.js +32 -12
- package/dist/commands/workflow/steps.js +20 -13
- package/dist/commands/workflow/workflows.js +397 -251
- package/dist/commands/workflow/workstreams.js +3 -2
- package/dist/commands/workflow/worktrees.js +11 -1
- package/dist/install/manifest.js +30 -10
- package/dist/install/modules/cloud.js +3 -1
- package/dist/install/modules/core.js +95 -5
- package/dist/install/modules/opencode.js +6 -0
- package/dist/install/placeholders.js +13 -19
- package/dist/install/write.js +26 -2
- package/dist/render/trackers.js +34 -20
- package/dist/shared/egress.js +6 -0
- package/dist/shared/settings.js +44 -0
- package/dist/shared/timeouts.js +8 -7
- package/package.json +11 -2
package/.bkit/core/engine/cli.ts
CHANGED
|
@@ -346,7 +346,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
|
|
|
346
346
|
if (arg.startsWith("--")) {
|
|
347
347
|
const flag = arg.slice(2);
|
|
348
348
|
|
|
349
|
-
// Value-bearing flag: --tracker=<github|linear|none>
|
|
349
|
+
// Value-bearing flag: --tracker=<github|linear|jira|none>
|
|
350
350
|
if (flag.startsWith("tracker=")) {
|
|
351
351
|
const value = flag.slice("tracker=".length);
|
|
352
352
|
const parsed = parseIssueTracker(value);
|
|
@@ -600,7 +600,10 @@ Usage:
|
|
|
600
600
|
Upgrade everything installed (no module flags). Diffs old
|
|
601
601
|
vs new templates; conflict list emitted to stderr. Use
|
|
602
602
|
--auto-apply for CI (apply non-conflicting; exit non-zero
|
|
603
|
-
on any conflict).
|
|
603
|
+
on any conflict). Only a whole file you edited since bkit
|
|
604
|
+
wrote it conflicts; rendered files (agents, commands,
|
|
605
|
+
skills, .bkit/*.md) are always re-rendered — bkit check
|
|
606
|
+
flags an edit to one.
|
|
604
607
|
--to=<version> / --latest atomically BUMP @cbartens/bkit
|
|
605
608
|
(pnpm add), then re-render + re-pin in one step — so a
|
|
606
609
|
version bump can never drift from its rendered mirrors.
|
|
@@ -625,8 +628,8 @@ Usage:
|
|
|
625
628
|
the tips that matter there first and prints one (each
|
|
626
629
|
workflow runs this at its close; audit and utility do the
|
|
627
630
|
same for audits and the ledger / roadmap updaters);
|
|
628
|
-
--all lists every one. Ends with a star line ("star"
|
|
629
|
-
bkit.ignoreAdvisories silences it), except under
|
|
631
|
+
--all lists every one. Ends with a star line ("bkit-star"
|
|
632
|
+
in bkit.ignoreAdvisories silences it), except under
|
|
630
633
|
--workflow=audit|utility. Local checks only. Exits 0.
|
|
631
634
|
bkit status Read-only host/provider status. Reports current host+provider
|
|
632
635
|
(sampled from .claude/, .cursor/, package.json, and the
|
|
@@ -669,7 +672,7 @@ Usage:
|
|
|
669
672
|
(design|plan|build|debug|ship). Without it, prints the
|
|
670
673
|
ledger-health line only. Read-only: exits 0.
|
|
671
674
|
bkit analysis Cross-repo analysis — reports counts/rates/elapsed-time,
|
|
672
|
-
|
|
675
|
+
change-size vs outcome regression, dispatch-size threshold,
|
|
673
676
|
counterSource trust labelling, per-rule compliance
|
|
674
677
|
rate over kind:"compliance" rows, and the
|
|
675
678
|
unjustified-deferral rate per (subagent, model)
|
|
@@ -724,17 +727,20 @@ Dependency updaters (copy an example and own it):
|
|
|
724
727
|
|
|
725
728
|
--auto=<claude|cursor|opencode>
|
|
726
729
|
Cloud-agent (auto-dispatch) integration (opt-in). --auto=claude needs
|
|
727
|
-
tracker=github + the ANTHROPIC_API_KEY repo secret
|
|
730
|
+
tracker=github + the ANTHROPIC_API_KEY repo secret (or the
|
|
731
|
+
ANTHROPIC_FEDERATION_RULE_ID + ANTHROPIC_ORGANIZATION_ID repo variables
|
|
732
|
+
for keyless federation) + the Claude GitHub App; --auto=cursor
|
|
728
733
|
needs tracker=linear; --auto=opencode needs tracker=github + a remote
|
|
729
734
|
opencode provider (OPENCODE_PROVIDER_KEY). Bare --auto is accepted on
|
|
730
735
|
uninstall only.
|
|
731
736
|
|
|
732
737
|
Cross-cutting / modifiers:
|
|
733
|
-
--tracker=<name> Wire issue tracker integration. Values: github, linear, none
|
|
738
|
+
--tracker=<name> Wire issue tracker integration. Values: github, linear, jira, none
|
|
734
739
|
(default). Records bkit.issueTracker in package.json and substitutes
|
|
735
|
-
tracker snippets into command mirrors.
|
|
736
|
-
|
|
737
|
-
|
|
740
|
+
tracker snippets into command mirrors. Re-renders every installed
|
|
741
|
+
host, and works alone (bkit install --tracker=github). Switching is
|
|
742
|
+
free; a switch removes the old linear or jira MCP entry unless you
|
|
743
|
+
edited it (github always stays). Does NOT own AGENTS.md (tracker-agnostic).
|
|
738
744
|
|
|
739
745
|
Install flags:
|
|
740
746
|
--auto-revert On a Phase 3 blocker, automatically run uninstall and exit 1.
|
|
@@ -803,21 +809,23 @@ function commandsUsage(): string {
|
|
|
803
809
|
|
|
804
810
|
/**
|
|
805
811
|
* Validate the verb/module-flag combination before any dispatch
|
|
806
|
-
* work runs. `install` requires >=1 module flag (
|
|
807
|
-
* `check` / `upgrade` take NO module
|
|
808
|
-
* operate on everything already installed, so a stray flag is a hard
|
|
809
|
-
* pointing at the no-flag form. Returns the error message to print, or `null`
|
|
812
|
+
* work runs. `install` requires >=1 module flag or `--tracker=` (which re-renders
|
|
813
|
+
* every installed host); a bare install errors. `check` / `upgrade` take NO module
|
|
814
|
+
* flags — they operate on everything already installed, so a stray flag is a hard
|
|
815
|
+
* error pointing at the no-flag form. Returns the error message to print, or `null`
|
|
810
816
|
* when the combination is valid.
|
|
811
817
|
*/
|
|
812
818
|
export function validateModuleFlagsForVerb(
|
|
813
819
|
verb: Verb,
|
|
814
820
|
moduleFlags: Set<ModuleFlag>,
|
|
821
|
+
tracker: IssueTracker | null = null,
|
|
815
822
|
): string | null {
|
|
816
|
-
if (verb === "install" && moduleFlags.size === 0) {
|
|
823
|
+
if (verb === "install" && moduleFlags.size === 0 && tracker === null) {
|
|
817
824
|
return (
|
|
818
825
|
"[bkit] `bkit install` requires at least one module flag. Name what to install: " +
|
|
819
826
|
"--claude, --cursor, --codex, --antigravity, --opencode=<provider> (plus opt-in " +
|
|
820
|
-
`--auto=<${CLOUD_VARIANTS.join("|")}>)
|
|
827
|
+
`--auto=<${CLOUD_VARIANTS.join("|")}>), or --tracker=<name> alone to switch the ` +
|
|
828
|
+
"tracker on what is installed. Run `bkit help` for usage."
|
|
821
829
|
);
|
|
822
830
|
}
|
|
823
831
|
if ((verb === "check" || verb === "upgrade") && moduleFlags.size > 0) {
|
|
@@ -904,8 +912,9 @@ export async function main() {
|
|
|
904
912
|
return;
|
|
905
913
|
}
|
|
906
914
|
|
|
907
|
-
// install requires >=1 module flag
|
|
908
|
-
|
|
915
|
+
// install requires >=1 module flag or --tracker=; check/upgrade take NONE
|
|
916
|
+
// (validateModuleFlagsForVerb).
|
|
917
|
+
const moduleFlagsError = validateModuleFlagsForVerb(verb, moduleFlags, tracker);
|
|
909
918
|
if (moduleFlagsError) {
|
|
910
919
|
console.error(moduleFlagsError);
|
|
911
920
|
process.exit(1);
|
|
@@ -14,12 +14,17 @@
|
|
|
14
14
|
//
|
|
15
15
|
// `skip-token` — whether a commit message carries a GitHub skip-CI token
|
|
16
16
|
// (`SKIP_CI_TOKEN`), for the `.husky/pre-push` CI-suppressor guard.
|
|
17
|
+
//
|
|
18
|
+
// `min-push` — whether every file a push changes matches `bkit.minPushPaths`, so
|
|
19
|
+
// `.husky/pre-push` runs `bkit:gate:min`. Files decide, never `[skip ci]` (a typed label
|
|
20
|
+
// GitHub reads off the last commit only).
|
|
17
21
|
|
|
18
22
|
import { spawnSync, type SpawnSyncReturns } from "node:child_process";
|
|
19
23
|
import * as fs from "node:fs";
|
|
20
24
|
import * as os from "node:os";
|
|
21
25
|
import * as path from "node:path";
|
|
22
26
|
|
|
27
|
+
import { readBkitConfig } from "../../shared/settings.js";
|
|
23
28
|
import {
|
|
24
29
|
CommandError,
|
|
25
30
|
commitMessage,
|
|
@@ -31,6 +36,7 @@ import {
|
|
|
31
36
|
type CommandSpec,
|
|
32
37
|
type RunContext,
|
|
33
38
|
} from "../lib.js";
|
|
39
|
+
import { changedOutside } from "../workflow/ledgers.js";
|
|
34
40
|
|
|
35
41
|
/** Exit code: slop-scan could not be started (not installed, not executable). */
|
|
36
42
|
export const EXIT_SLOP_UNAVAILABLE = 3;
|
|
@@ -40,6 +46,8 @@ export const EXIT_SLOP_FAILED = 4;
|
|
|
40
46
|
export const EXIT_NO_WORKTREE = 5;
|
|
41
47
|
/** Exit code: vale could not run, or ended with a runtime error (its exit 2). */
|
|
42
48
|
export const EXIT_VALE_FAILED = 6;
|
|
49
|
+
/** Exit code: a pushed commit, its base, or its `git diff` could not be read. */
|
|
50
|
+
export const EXIT_RANGE_UNKNOWN = 7;
|
|
43
51
|
|
|
44
52
|
/** Branches whose merge-base with HEAD is the default base, in order. */
|
|
45
53
|
const BASE_CANDIDATES = ["origin/dev", "origin/main"];
|
|
@@ -416,6 +424,81 @@ function skipToken(ctx: RunContext): number {
|
|
|
416
424
|
return token === null ? EXIT.NO : EXIT.OK;
|
|
417
425
|
}
|
|
418
426
|
|
|
427
|
+
// ---------------------------------------------------------------------------
|
|
428
|
+
// min-push
|
|
429
|
+
// ---------------------------------------------------------------------------
|
|
430
|
+
|
|
431
|
+
/** `bkit.minPushPaths` as git pathspecs: `:(glob)` unless an entry carries its own magic. */
|
|
432
|
+
export const minPushPathspecs = (paths: readonly string[]): string[] =>
|
|
433
|
+
paths.map((p) => (p.startsWith(":") ? p : `:(glob)${p}`));
|
|
434
|
+
|
|
435
|
+
/** Where a pushed commit's range starts: its merge-base with origin/dev, else origin/main. */
|
|
436
|
+
export function pushBase(cwd: string, sha: string): string | null {
|
|
437
|
+
for (const cand of BASE_CANDIDATES) {
|
|
438
|
+
if (!runGit(cwd, ["rev-parse", "--verify", "--quiet", cand]).ok) continue;
|
|
439
|
+
const mb = runGit(cwd, ["merge-base", sha, cand]);
|
|
440
|
+
if (mb.ok && mb.stdout) return mb.stdout;
|
|
441
|
+
}
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function minPush(ctx: RunContext): number {
|
|
446
|
+
const top = runGit(ctx.cwd, ["rev-parse", "--show-toplevel"]);
|
|
447
|
+
if (!top.ok) throw new CommandError(EXIT.USAGE, `not inside a git repository: ${ctx.cwd}`);
|
|
448
|
+
const given = ctx.flags.ref;
|
|
449
|
+
const refs = Array.isArray(given) && given.length > 0 ? given.map(String) : ["HEAD"];
|
|
450
|
+
const baseFlag = typeof ctx.flags.base === "string" && ctx.flags.base ? ctx.flags.base : null;
|
|
451
|
+
const paths = readBkitConfig(top.stdout).minPushPaths;
|
|
452
|
+
const specs = minPushPathspecs(paths);
|
|
453
|
+
|
|
454
|
+
const changed = new Set<string>();
|
|
455
|
+
const outside = new Set<string>();
|
|
456
|
+
for (const ref of refs) {
|
|
457
|
+
const sha = git(ctx.cwd, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
458
|
+
const base = sha ? (baseFlag ?? pushBase(ctx.cwd, sha)) : null;
|
|
459
|
+
const diff = sha && base ? changedOutside(top.stdout, base, sha, specs) : null;
|
|
460
|
+
if (!diff?.ok) {
|
|
461
|
+
const why = !sha
|
|
462
|
+
? `cannot read commit '${ref}'`
|
|
463
|
+
: !base
|
|
464
|
+
? `no base for ${ref} (neither origin/dev nor origin/main resolves)`
|
|
465
|
+
: `'git diff' failed for ${base}..${ref}: ${diff && !diff.ok ? diff.stderr : ""}`;
|
|
466
|
+
ctx.log(`${why} — not proven a min push`);
|
|
467
|
+
ctx.emit({ minPush: false, reason: "unknown", changed: 0, outside: [], paths });
|
|
468
|
+
return EXIT_RANGE_UNKNOWN;
|
|
469
|
+
}
|
|
470
|
+
for (const p of diff.changed) changed.add(p);
|
|
471
|
+
for (const p of diff.outside) outside.add(p);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const result = (reason: string | null, code: number, message: string) => {
|
|
475
|
+
ctx.log(message);
|
|
476
|
+
ctx.emit({
|
|
477
|
+
minPush: reason === null,
|
|
478
|
+
reason,
|
|
479
|
+
changed: changed.size,
|
|
480
|
+
outside: [...outside].sort(),
|
|
481
|
+
paths,
|
|
482
|
+
});
|
|
483
|
+
return code;
|
|
484
|
+
};
|
|
485
|
+
if (paths.length === 0) {
|
|
486
|
+
return result("no-paths", EXIT.NO, "bkit.minPushPaths is empty — not a min push");
|
|
487
|
+
}
|
|
488
|
+
if (changed.size === 0) {
|
|
489
|
+
return result("no-changes", EXIT.NO, "the push changes no files — not proven a min push");
|
|
490
|
+
}
|
|
491
|
+
if (outside.size > 0) {
|
|
492
|
+
const first = [...outside].sort()[0];
|
|
493
|
+
return result(
|
|
494
|
+
"outside",
|
|
495
|
+
EXIT.NO,
|
|
496
|
+
`${outside.size} of ${changed.size} changed files match no min-push path (first: ${first})`,
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
return result(null, EXIT.OK, `all ${changed.size} changed files match min-push paths`);
|
|
500
|
+
}
|
|
501
|
+
|
|
419
502
|
export const ciCommand: CommandSpec = {
|
|
420
503
|
noun: "ci",
|
|
421
504
|
summary: "Gates CI and the git hooks run.",
|
|
@@ -479,5 +562,29 @@ export const ciCommand: CommandSpec = {
|
|
|
479
562
|
},
|
|
480
563
|
run: skipToken,
|
|
481
564
|
},
|
|
565
|
+
"min-push": {
|
|
566
|
+
summary:
|
|
567
|
+
"Exit 0 when every file a push changes matches bkit.minPushPaths (the pre-push light gate).",
|
|
568
|
+
flags: [
|
|
569
|
+
{
|
|
570
|
+
name: "ref",
|
|
571
|
+
type: "string",
|
|
572
|
+
repeatable: true,
|
|
573
|
+
help: "a pushed commit (default HEAD); its range starts at its merge-base with origin/dev, else origin/main",
|
|
574
|
+
},
|
|
575
|
+
{ name: "base", type: "string", help: "start every range here instead" },
|
|
576
|
+
],
|
|
577
|
+
output: {
|
|
578
|
+
minPush: "true when every changed file matches bkit.minPushPaths",
|
|
579
|
+
reason: "null when a min push; else no-paths | no-changes | outside | unknown",
|
|
580
|
+
changed: "files the push changes, across every ref",
|
|
581
|
+
outside: "the changed files no min-push path matches",
|
|
582
|
+
paths: "bkit.minPushPaths as read",
|
|
583
|
+
},
|
|
584
|
+
exitCodes: {
|
|
585
|
+
[EXIT_RANGE_UNKNOWN]: "a pushed commit, its base, or its git diff could not be read",
|
|
586
|
+
},
|
|
587
|
+
run: minPush,
|
|
588
|
+
},
|
|
482
589
|
},
|
|
483
590
|
};
|
|
@@ -54,25 +54,25 @@ export interface Violation {
|
|
|
54
54
|
// ---------------------------------------------------------------------------
|
|
55
55
|
|
|
56
56
|
export interface GitAdapter {
|
|
57
|
-
/** Returns the diff stat paths (one per line, POSIX) for parentSha..HEAD. */
|
|
58
|
-
diffPaths(parentSha: string, cwd: string): string[];
|
|
59
|
-
/** Returns the subject line of HEAD. */
|
|
60
|
-
headSubject(cwd: string): string;
|
|
57
|
+
/** Returns the diff stat paths (one per line, POSIX) for parentSha..head (HEAD by default). */
|
|
58
|
+
diffPaths(parentSha: string, cwd: string, head?: string): string[];
|
|
59
|
+
/** Returns the subject line of head (HEAD by default). */
|
|
60
|
+
headSubject(cwd: string, head?: string): string;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** SHA charset guard — only raw hex SHAs from the ledger are accepted. */
|
|
64
64
|
const SHA_RE = /^[0-9a-f]{7,40}$/;
|
|
65
65
|
|
|
66
66
|
export const realGitAdapter: GitAdapter = {
|
|
67
|
-
diffPaths(parentSha: string, cwd: string): string[] {
|
|
68
|
-
if (!SHA_RE.test(parentSha)) {
|
|
67
|
+
diffPaths(parentSha: string, cwd: string, head = "HEAD"): string[] {
|
|
68
|
+
if (!SHA_RE.test(parentSha) || (head !== "HEAD" && !SHA_RE.test(head))) {
|
|
69
69
|
console.error(
|
|
70
|
-
`[bkit-comply] diffPaths:
|
|
70
|
+
`[bkit-comply] diffPaths: "${parentSha}..${head}" is not a sha range — skipping diff`,
|
|
71
71
|
);
|
|
72
72
|
return [];
|
|
73
73
|
}
|
|
74
74
|
try {
|
|
75
|
-
const output = execFileSync("git", ["diff", "--name-only", `${parentSha}
|
|
75
|
+
const output = execFileSync("git", ["diff", "--name-only", `${parentSha}..${head}`], {
|
|
76
76
|
cwd,
|
|
77
77
|
env: gitEnv(),
|
|
78
78
|
encoding: "utf8",
|
|
@@ -88,9 +88,10 @@ export const realGitAdapter: GitAdapter = {
|
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
|
|
91
|
-
headSubject(cwd: string): string {
|
|
91
|
+
headSubject(cwd: string, head = "HEAD"): string {
|
|
92
|
+
if (head !== "HEAD" && !SHA_RE.test(head)) return "";
|
|
92
93
|
try {
|
|
93
|
-
return execFileSync("git", ["log", "-1", "--format=%s"], {
|
|
94
|
+
return execFileSync("git", ["log", "-1", "--format=%s", head], {
|
|
94
95
|
cwd,
|
|
95
96
|
env: gitEnv(),
|
|
96
97
|
encoding: "utf8",
|
|
@@ -157,6 +158,8 @@ export function ruleSkipCiNotHead(headSubject: string, phase: string): Violation
|
|
|
157
158
|
export interface GraderInput {
|
|
158
159
|
/** Git SHA of the parent commit (design-start / plan-start / etc.). */
|
|
159
160
|
parentSha: string;
|
|
161
|
+
/** The commit graded, when not HEAD: ship's squash. */
|
|
162
|
+
headSha?: string;
|
|
160
163
|
/** Workflow phase: design | plan | build | debug | ship */
|
|
161
164
|
phase: string;
|
|
162
165
|
/** Working directory for git commands. Defaults to process.cwd(). */
|
|
@@ -173,8 +176,8 @@ export function runGrader(input: GraderInput): Violation[] {
|
|
|
173
176
|
try {
|
|
174
177
|
const cwd = input.cwd ?? process.cwd();
|
|
175
178
|
const adapter = input.gitAdapter ?? realGitAdapter;
|
|
176
|
-
const diffPaths = adapter.diffPaths(input.parentSha, cwd);
|
|
177
|
-
const headSubject = adapter.headSubject(cwd);
|
|
179
|
+
const diffPaths = adapter.diffPaths(input.parentSha, cwd, input.headSha);
|
|
180
|
+
const headSubject = adapter.headSubject(cwd, input.headSha);
|
|
178
181
|
|
|
179
182
|
const violations: Violation[] = [];
|
|
180
183
|
|
|
@@ -279,21 +282,27 @@ export function appendComplianceRows(rows: ComplianceRow[], statsPath: string):
|
|
|
279
282
|
|
|
280
283
|
/**
|
|
281
284
|
* Grade `phase` over HEAD~1..HEAD (HEAD alone in a one-commit repo) and append
|
|
282
|
-
* its compliance rows to `<cwd>/.bkit/stats.jsonl`.
|
|
283
|
-
*
|
|
285
|
+
* its compliance rows to `<cwd>/.bkit/stats.jsonl`. With `squashSha` (ship's
|
|
286
|
+
* close, run in the feature worktree) the squash commit is graded instead —
|
|
287
|
+
* its subject and `squash~1..squash` — so the grade covers the whole feature
|
|
288
|
+
* as it reaches main, not the worktree's last commit. Fail-open: any
|
|
289
|
+
* error is logged and returns null, so a close never stops on the grader.
|
|
284
290
|
*/
|
|
285
291
|
export function gradeCompliance(
|
|
286
292
|
cwd: string,
|
|
287
293
|
phase: string,
|
|
288
294
|
log: (m: string) => void,
|
|
295
|
+
squashSha?: string,
|
|
289
296
|
): Violation[] | null {
|
|
290
297
|
try {
|
|
291
|
-
const
|
|
298
|
+
const squashParent = squashSha === undefined ? "" : resolveGitSha(`${squashSha}~1`, cwd);
|
|
299
|
+
const parentSha = squashParent || resolveGitSha("HEAD~1", cwd) || resolveGitSha("HEAD", cwd);
|
|
292
300
|
if (!parentSha) {
|
|
293
301
|
log("[bkit-comply] cannot resolve a parent SHA (no commits?) — skipping grade");
|
|
294
302
|
return null;
|
|
295
303
|
}
|
|
296
|
-
const
|
|
304
|
+
const headSha = squashParent ? squashSha : undefined;
|
|
305
|
+
const violations = runGrader({ parentSha, phase, cwd, ...(headSha ? { headSha } : {}) });
|
|
297
306
|
const rows = buildComplianceRows({
|
|
298
307
|
violations,
|
|
299
308
|
phase,
|
|
@@ -228,14 +228,21 @@ export async function runInstall(
|
|
|
228
228
|
else if (dryRun) console.log(`${LOG_PREFIX} Running in check (dry-run) mode`);
|
|
229
229
|
|
|
230
230
|
// `bkit check` scopes drift detection to what is INSTALLED (detected by sentinel files),
|
|
231
|
-
// not to a fixed full set. `install` keeps its explicit resolved set
|
|
232
|
-
|
|
231
|
+
// not to a fixed full set. `install` keeps its explicit resolved set, plus every installed
|
|
232
|
+
// host when `--tracker=` is given: each host renders tracker-specific commands, agents and
|
|
233
|
+
// MCP entries, so a host left out would keep the old tracker's.
|
|
234
|
+
const effectiveModules =
|
|
235
|
+
verb === "check"
|
|
236
|
+
? detectInstalledModules(process.cwd())
|
|
237
|
+
: tracker !== null
|
|
238
|
+
? new Set<ModuleFlag>([...modules, ...detectInstalledModules(process.cwd())])
|
|
239
|
+
: modules;
|
|
233
240
|
|
|
234
241
|
// RENDER-input provider resolution. `bkit check` takes no `--opencode=` flag, so the parsed
|
|
235
242
|
// `opencodeProvider` is null on the check path; it falls back to the INSTALLED provider
|
|
236
243
|
// (package.json `bkit.opencodeProvider`, else the opencode.json provider block). On install
|
|
237
|
-
// `?? detect`
|
|
238
|
-
//
|
|
244
|
+
// `?? detect` fires only when opencode joins as an installed host under `--tracker=`; with
|
|
245
|
+
// `--opencode=<provider>` the flag wins. The PARSED `opencodeProvider` alone drives the persist-to-package.json logic
|
|
239
246
|
// below (gated on `!dryRun` + a real flag). The tracker is resolved from package.json below,
|
|
240
247
|
// so the tracker-dependent opencode mcp block renders the same way on check.
|
|
241
248
|
const renderOpencodeProvider = opencodeProvider ?? detectOpencodeProvider(process.cwd());
|
|
@@ -834,6 +834,12 @@ export async function runUninstall(
|
|
|
834
834
|
}
|
|
835
835
|
}
|
|
836
836
|
|
|
837
|
+
// Targeted uninstall: drop the `bkit.*` keys the removed module records, so its advisories
|
|
838
|
+
// stop firing. Core keeps every other key.
|
|
839
|
+
if (!moduleList.includes("core")) {
|
|
840
|
+
stripModuleBkitKeys(moduleList, ctx, result);
|
|
841
|
+
}
|
|
842
|
+
|
|
837
843
|
// Clean up .agents/ bkit-prefix mirror files
|
|
838
844
|
// (.claude/commands/bkit-*.md, .claude/agents/bkit-*.md, .opencode/agents/bkit-*.md, etc.)
|
|
839
845
|
// A dry run lists the same paths in result.deleted and removes nothing.
|
|
@@ -1029,6 +1035,46 @@ export async function runUninstall(
|
|
|
1029
1035
|
return result;
|
|
1030
1036
|
}
|
|
1031
1037
|
|
|
1038
|
+
/** `package.json` `bkit.*` keys each module records on install. */
|
|
1039
|
+
const MODULE_BKIT_KEYS: Partial<Record<ModuleName, readonly string[]>> = {
|
|
1040
|
+
cloud: ["cloudAgents"],
|
|
1041
|
+
opencode: ["opencodeProvider", "opencodeProviders"],
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Remove the `bkit.*` keys recorded by the modules in `moduleList` from the consumer's
|
|
1046
|
+
* package.json, keeping its indent. Lists each removed key in `result.stripped`; a dry run
|
|
1047
|
+
* lists without writing.
|
|
1048
|
+
*/
|
|
1049
|
+
function stripModuleBkitKeys(
|
|
1050
|
+
moduleList: ModuleName[],
|
|
1051
|
+
ctx: UninstallContext,
|
|
1052
|
+
result: UninstallResult,
|
|
1053
|
+
): void {
|
|
1054
|
+
const keys = moduleList.flatMap((m) => MODULE_BKIT_KEYS[m] ?? []);
|
|
1055
|
+
if (keys.length === 0) return;
|
|
1056
|
+
const pkgPath = path.join(ctx.cwd, "package.json");
|
|
1057
|
+
if (!fs.existsSync(pkgPath)) return;
|
|
1058
|
+
const raw = fs.readFileSync(pkgPath, "utf-8");
|
|
1059
|
+
const parsed = parseJson(raw);
|
|
1060
|
+
const pkg = parsed.ok ? (parsed.value as Record<string, unknown> | null) : null;
|
|
1061
|
+
if (pkg === null || !isJsonObject(pkg.bkit as JsonValue)) return;
|
|
1062
|
+
const bkit = pkg.bkit as Record<string, unknown>;
|
|
1063
|
+
const present = keys.filter((k) => k in bkit);
|
|
1064
|
+
if (present.length === 0) return;
|
|
1065
|
+
for (const k of present) {
|
|
1066
|
+
delete bkit[k];
|
|
1067
|
+
result.stripped.push(`package.json#bkit.${k}`);
|
|
1068
|
+
}
|
|
1069
|
+
console.log(
|
|
1070
|
+
`${ctx.logPrefix}${ctx.dryRun ? " [dry-run]" : ""} package.json: removed bkit.${present.join(", bkit.")}`,
|
|
1071
|
+
);
|
|
1072
|
+
if (ctx.dryRun) return;
|
|
1073
|
+
const indentMatch = raw.match(/\n([ \t]+)"/);
|
|
1074
|
+
const indent = indentMatch ? indentMatch[1] : " ";
|
|
1075
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + "\n", "utf-8");
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1032
1078
|
// ---------------------------------------------------------------------------
|
|
1033
1079
|
// runSurgicalOpencodeUninstall — remove exactly ONE provider block
|
|
1034
1080
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// The one way bkit lands a commit on dev: build it in a detached throwaway
|
|
2
|
+
// worktree off a fresh origin/dev and push it as dev. The main checkout's
|
|
3
|
+
// branch, index and edits are never touched, and local dev commits missing from
|
|
4
|
+
// origin/dev are never pushed. dev moved underneath → rebuild on the new dev and
|
|
5
|
+
// push again, with backoff. Used by the design / plan close, the build / debug
|
|
6
|
+
// roadmap mirror, and ship's close and FAILED record. The throwaway runs no git
|
|
7
|
+
// hooks: what it lands is bookkeeping only (docs, logs, ledgers, `[skip ci]`).
|
|
8
|
+
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
import { CommandError, DEV, EXIT, git, runGit } from "./lib.js";
|
|
12
|
+
import { TIMEOUTS } from "../shared/timeouts.js";
|
|
13
|
+
|
|
14
|
+
const REMOTE = "origin";
|
|
15
|
+
const UPSTREAM = `${REMOTE}/${DEV}`;
|
|
16
|
+
|
|
17
|
+
/** dev moved before git sent anything: git compared the remote's dev and stopped. */
|
|
18
|
+
const MOVED_BEFORE = /\[rejected\][^\n]*\((?:fetch first|non-fast-forward)\)/;
|
|
19
|
+
/** dev moved while the push was in flight: the server's ref update lost the race. */
|
|
20
|
+
const MOVED_DURING =
|
|
21
|
+
/\[remote rejected\][^\n]*\((?:incorrect old value provided|cannot lock ref[^\n]*)\)/;
|
|
22
|
+
/** The server turned the push away: branch protection, a ruleset, an HTTP 403. */
|
|
23
|
+
const REFUSED = /\[remote rejected\]|returned error: 403|\bGH0\d\d\b/;
|
|
24
|
+
|
|
25
|
+
/** A dev push rejected only because dev moved: rebuild on the new dev, push again. */
|
|
26
|
+
export const devMoved = (stderr: string) => MOVED_BEFORE.test(stderr) || MOVED_DURING.test(stderr);
|
|
27
|
+
|
|
28
|
+
/** A dev push the server refused for a reason other than dev moving. */
|
|
29
|
+
export const devRefused = (stderr: string) => !devMoved(stderr) && REFUSED.test(stderr);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Milliseconds to wait before retry `retry` (1-based) of a landing: `startS`
|
|
33
|
+
* doubling per retry, capped at `capS`, then jittered down by up to half so two
|
|
34
|
+
* landings that collided once do not retry in step.
|
|
35
|
+
*/
|
|
36
|
+
export function landBackoffMs(
|
|
37
|
+
retry: number,
|
|
38
|
+
random: () => number = Math.random,
|
|
39
|
+
startS: number = TIMEOUTS.LAND_BACKOFF_START_S,
|
|
40
|
+
capS: number = TIMEOUTS.LAND_BACKOFF_CAP_S,
|
|
41
|
+
): number {
|
|
42
|
+
const s = Math.min(startS * 2 ** (retry - 1), capS);
|
|
43
|
+
return Math.round(s * 1000 * (0.5 + random() / 2));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
47
|
+
|
|
48
|
+
/** A FID names one folder: no separators, no `..`. */
|
|
49
|
+
const SAFE_FID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
50
|
+
|
|
51
|
+
/** The throwaway checkout a landing is built in, beside the feature worktrees. */
|
|
52
|
+
export function landDir(root: string, fid: string): string {
|
|
53
|
+
if (!SAFE_FID.test(fid) || fid.includes(".."))
|
|
54
|
+
throw new CommandError(EXIT.USAGE, `--fid "${fid}" is not a feature id`);
|
|
55
|
+
return path.join(root, ".worktrees", `_land-${fid}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Remove a throwaway checkout. A landing killed inside `worktree add` leaves it
|
|
60
|
+
* locked ("initializing"), which a single `--force` and `prune` both skip, so it
|
|
61
|
+
* is unlocked first; a folder git no longer lists is the landing's own scratch.
|
|
62
|
+
*/
|
|
63
|
+
export function dropLandTree(root: string, dir: string): void {
|
|
64
|
+
runGit(root, ["worktree", "unlock", dir]);
|
|
65
|
+
if (fs.existsSync(dir)) runGit(root, ["worktree", "remove", "--force", "--force", dir]);
|
|
66
|
+
runGit(root, ["worktree", "prune"]);
|
|
67
|
+
if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `core.hooksPath` pointing nowhere, so no hook runs. */
|
|
71
|
+
const NO_HOOKS = process.platform === "win32" ? "NUL" : "/dev/null";
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Run `fn` with git hooks off for every git child it starts: one more
|
|
75
|
+
* `GIT_CONFIG_*` entry (git >= 2.31) setting `core.hooksPath`, restored after.
|
|
76
|
+
*/
|
|
77
|
+
export async function withoutHooks<T>(fn: () => T | Promise<T>): Promise<T> {
|
|
78
|
+
const saved = process.env.GIT_CONFIG_COUNT;
|
|
79
|
+
const n = Number(saved ?? 0) || 0;
|
|
80
|
+
const key = `GIT_CONFIG_KEY_${n}`;
|
|
81
|
+
const value = `GIT_CONFIG_VALUE_${n}`;
|
|
82
|
+
process.env.GIT_CONFIG_COUNT = String(n + 1);
|
|
83
|
+
process.env[key] = "core.hooksPath";
|
|
84
|
+
process.env[value] = NO_HOOKS;
|
|
85
|
+
try {
|
|
86
|
+
return await fn();
|
|
87
|
+
} finally {
|
|
88
|
+
if (saved === undefined) delete process.env.GIT_CONFIG_COUNT;
|
|
89
|
+
else process.env.GIT_CONFIG_COUNT = saved;
|
|
90
|
+
delete process.env[key];
|
|
91
|
+
delete process.env[value];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type DevPush =
|
|
96
|
+
| { kind: "landed"; sha: string; attempts: number }
|
|
97
|
+
/** The server refused for a reason other than dev moving (branch protection, a ruleset, a 403). */
|
|
98
|
+
| { kind: "refused"; stderr: string }
|
|
99
|
+
/** The push failed without a server answer (network, credentials): nothing landed, no PR. */
|
|
100
|
+
| { kind: "push-failed"; stderr: string }
|
|
101
|
+
/** dev moved before every one of LAND_ATTEMPTS pushes. */
|
|
102
|
+
| { kind: "exhausted"; attempts: number }
|
|
103
|
+
| { kind: "fetch-failed"; stderr: string }
|
|
104
|
+
| { kind: "setup-failed"; stderr: string };
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Land one commit on dev: per attempt, fetch dev, add `dir` detached at
|
|
108
|
+
* origin/dev, let `build` make the commit there, push `HEAD:dev` — git hooks
|
|
109
|
+
* off. `build` throwing stops the landing with that throw. A server refusal runs
|
|
110
|
+
* `refused` on the built commit first, when given. `dir` is removed on every path.
|
|
111
|
+
*/
|
|
112
|
+
export async function pushToDev(o: {
|
|
113
|
+
root: string;
|
|
114
|
+
dir: string;
|
|
115
|
+
build: (dir: string, attempt: number) => void;
|
|
116
|
+
refused?: (dir: string, stderr: string) => Promise<void>;
|
|
117
|
+
log: (line: string) => void;
|
|
118
|
+
}): Promise<DevPush> {
|
|
119
|
+
o.log("git hooks skipped in the throwaway dev checkout — it lands bookkeeping only");
|
|
120
|
+
for (let attempt = 1; ; attempt++) {
|
|
121
|
+
let wait = 0;
|
|
122
|
+
dropLandTree(o.root, o.dir);
|
|
123
|
+
try {
|
|
124
|
+
const outcome = await withoutHooks(async (): Promise<DevPush | null> => {
|
|
125
|
+
const fetched = runGit(o.root, ["fetch", REMOTE, DEV]);
|
|
126
|
+
if (!fetched.ok) return { kind: "fetch-failed", stderr: fetched.stderr };
|
|
127
|
+
const added = runGit(o.root, ["worktree", "add", "--detach", o.dir, UPSTREAM]);
|
|
128
|
+
if (!added.ok) return { kind: "setup-failed", stderr: added.stderr };
|
|
129
|
+
o.build(o.dir, attempt);
|
|
130
|
+
const pushed = runGit(o.dir, ["push", REMOTE, `HEAD:${DEV}`]);
|
|
131
|
+
if (pushed.ok) {
|
|
132
|
+
return {
|
|
133
|
+
kind: "landed",
|
|
134
|
+
sha: git(o.dir, ["rev-parse", "HEAD"]) ?? "",
|
|
135
|
+
attempts: attempt,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (devRefused(pushed.stderr)) {
|
|
139
|
+
await o.refused?.(o.dir, pushed.stderr);
|
|
140
|
+
return { kind: "refused", stderr: pushed.stderr };
|
|
141
|
+
}
|
|
142
|
+
if (!devMoved(pushed.stderr)) return { kind: "push-failed", stderr: pushed.stderr };
|
|
143
|
+
return null;
|
|
144
|
+
});
|
|
145
|
+
if (outcome !== null) return outcome;
|
|
146
|
+
if (attempt >= TIMEOUTS.LAND_ATTEMPTS) return { kind: "exhausted", attempts: attempt };
|
|
147
|
+
wait = landBackoffMs(attempt);
|
|
148
|
+
o.log(
|
|
149
|
+
`dev moved before push ${attempt} of ${TIMEOUTS.LAND_ATTEMPTS} — rebuilding on the new dev in ${(wait / 1000).toFixed(1)}s`,
|
|
150
|
+
);
|
|
151
|
+
} finally {
|
|
152
|
+
dropLandTree(o.root, o.dir);
|
|
153
|
+
}
|
|
154
|
+
await sleep(wait);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -442,8 +442,13 @@ export function runGh(cwd: string, args: string[], input?: string): GhResult {
|
|
|
442
442
|
};
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
-
/**
|
|
446
|
-
|
|
445
|
+
/**
|
|
446
|
+
* gh cannot serve this call here: not installed, exit 4 (not logged in), or an
|
|
447
|
+
* HTTP 403 — a token or proxy that may not use this API, where the GitHub MCP
|
|
448
|
+
* (its own credentials) can.
|
|
449
|
+
*/
|
|
450
|
+
export const ghUnavailable = (res: GhResult): boolean =>
|
|
451
|
+
res.missing || res.status === 4 || (!res.ok && /\bHTTP 403\b/.test(res.stderr));
|
|
447
452
|
|
|
448
453
|
/**
|
|
449
454
|
* The main checkout's root, from any worktree. `--git-common-dir` points at the
|
|
@@ -476,22 +481,19 @@ export interface StatusLocation {
|
|
|
476
481
|
*
|
|
477
482
|
* - design / plan / build / debug: the feature worktree's copy when it exists
|
|
478
483
|
* (`.worktrees/{fid}`), else the main checkout's.
|
|
479
|
-
* - ship: the
|
|
480
|
-
* worktree
|
|
481
|
-
* least-capable answer: current worktree.
|
|
484
|
+
* - ship: the current worktree's top — the tree ship works in (the feature
|
|
485
|
+
* worktree, or the adopted checkout), so asked from inside it.
|
|
482
486
|
*/
|
|
483
487
|
export function statusLocation(opts: {
|
|
484
488
|
cwd: string;
|
|
485
489
|
workflow: string;
|
|
486
490
|
fid: string;
|
|
487
491
|
month: string;
|
|
488
|
-
devPushes?: boolean;
|
|
489
492
|
}): StatusLocation {
|
|
490
493
|
const root = repoRoot(opts.cwd);
|
|
491
494
|
const rel = statusRelPath(opts.month, opts.fid);
|
|
492
495
|
if (opts.workflow === "ship") {
|
|
493
|
-
const bookRoot =
|
|
494
|
-
opts.devPushes === true ? root : (git(opts.cwd, ["rev-parse", "--show-toplevel"]) ?? root);
|
|
496
|
+
const bookRoot = git(opts.cwd, ["rev-parse", "--show-toplevel"]) ?? root;
|
|
495
497
|
return { bookRoot, path: path.join(bookRoot, rel) };
|
|
496
498
|
}
|
|
497
499
|
const worktree = path.join(root, ".worktrees", opts.fid);
|
|
@@ -11,6 +11,7 @@ import { setupCommand } from "./setup/setup.js";
|
|
|
11
11
|
import { branchesCommand } from "./workflow/branches.js";
|
|
12
12
|
import { contextCommand } from "./workflow/context.js";
|
|
13
13
|
import { countersCommand } from "./workflow/counters.js";
|
|
14
|
+
import { diskCommand } from "./workflow/disk.js";
|
|
14
15
|
import { fidsCommand } from "./workflow/fids.js";
|
|
15
16
|
import { issuesCommand } from "./workflow/issues.js";
|
|
16
17
|
import { ledgersCommand } from "./workflow/ledgers.js";
|
|
@@ -39,6 +40,7 @@ export const COMMANDS: readonly CommandSpec[] = [
|
|
|
39
40
|
locksCommand,
|
|
40
41
|
workflowsCommand,
|
|
41
42
|
worktreesCommand,
|
|
43
|
+
diskCommand,
|
|
42
44
|
branchesCommand,
|
|
43
45
|
skillsCommand,
|
|
44
46
|
prsCommand,
|