@cbartens/bkit 5.4.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 +18 -6
- package/.bkit/core/.agents/rules.md +7 -8
- package/.bkit/core/.bkit/README.md +17 -5
- package/.bkit/core/.bkit/cloud.md +44 -13
- package/.bkit/core/.bkit/comparison.md +2 -2
- package/.bkit/core/.bkit/install.md +16 -14
- package/.bkit/core/.bkit/pipeline.md +3 -1
- package/.bkit/core/.bkit/prompts.md +12 -9
- package/.bkit/core/.bkit/providers.md +6 -6
- package/.bkit/core/.bkit/templates.md +12 -6
- package/.bkit/core/.bkit/trackers.md +89 -34
- package/.bkit/core/.bkit/workflows.md +42 -38
- package/.bkit/core/AGENTS.md +2 -2
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +1 -1
- package/.bkit/core/docs/templates/bkit-audit-issues.md +22 -6
- 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/tips/catalogue.ts +15 -2
- package/.bkit/core/engine/cli.ts +7 -5
- package/.bkit/core/engine/commands/ci/ci.ts +107 -0
- package/.bkit/core/engine/commands/install/uninstall.ts +46 -0
- package/.bkit/core/engine/commands/workflow/fids.ts +23 -15
- package/.bkit/core/engine/commands/workflow/issues.ts +35 -16
- package/.bkit/core/engine/commands/workflow/ledgers.ts +28 -11
- package/.bkit/core/engine/commands/workflow/prs.ts +3 -1
- package/.bkit/core/engine/commands/workflow/repo.ts +6 -0
- package/.bkit/core/engine/commands/workflow/roadmap.ts +5 -1
- package/.bkit/core/engine/commands/workflow/steps.ts +2 -2
- package/.bkit/core/engine/commands/workflow/workflows.ts +9 -4
- 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 +82 -4
- package/.bkit/core/engine/install/modules/opencode.ts +5 -0
- 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 +88 -1
- package/.bkit/core/hooks/guardrails-tiers.js +1 -1
- package/.bkit/core/prompts/bkit-audit-generate.md +42 -12
- 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 +3 -1
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +3 -1
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +11 -1
- package/.bkit/core/prompts/bkit-utility-update-failures.md +3 -1
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +3 -1
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +9 -2
- 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 +59 -17
- package/.bkit/core/workflows/bkit-debug.md +64 -20
- package/.bkit/core/workflows/bkit-design.md +83 -28
- package/.bkit/core/workflows/bkit-plan.md +61 -20
- package/.bkit/core/workflows/bkit-ship.md +48 -18
- package/.bkit/shared/.bkit/.env.example +8 -0
- package/.bkit/shared/.claude/settings.json +3 -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 +15 -4
- package/.bkit/shared/docs/security.md +1 -1
- package/.bkit/shared/docs/testing.md +3 -3
- package/.bkit/templates/.github/renovate.json5 +1 -1
- package/.bkit/templates/.github/workflows/bkit-ci.yml +22 -54
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +40 -12
- package/.bkit/templates/.husky/pre-commit +4 -4
- package/.bkit/templates/.husky/pre-push +62 -12
- 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/graphify/bkit-graphify.sh +1 -1
- package/CHANGELOG.md +37 -1
- package/README.md +7 -6
- 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/tips/catalogue.js +14 -2
- package/dist/cli.js +7 -5
- package/dist/commands/ci/ci.js +100 -0
- package/dist/commands/install/uninstall.js +42 -0
- package/dist/commands/workflow/fids.js +22 -15
- package/dist/commands/workflow/issues.js +28 -15
- package/dist/commands/workflow/ledgers.js +26 -11
- package/dist/commands/workflow/prs.js +3 -1
- package/dist/commands/workflow/repo.js +5 -0
- package/dist/commands/workflow/roadmap.js +3 -1
- package/dist/commands/workflow/steps.js +2 -2
- package/dist/commands/workflow/workflows.js +9 -4
- package/dist/install/manifest.js +30 -10
- package/dist/install/modules/cloud.js +3 -1
- package/dist/install/modules/core.js +82 -5
- package/dist/install/modules/opencode.js +6 -0
- 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 +39 -0
- package/package.json +11 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
5
|
import * as path from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
7
|
import type { PreflightFinding } from "../before/index.js";
|
|
8
8
|
import { readJsonFile } from "../../shared/json.js";
|
|
9
9
|
import { readBkitConfig } from "../../shared/settings.js";
|
|
@@ -79,26 +79,32 @@ export function detectGhMcpToken(cwd: string): PreflightFinding | null {
|
|
|
79
79
|
return null;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Names of the consumer repo's GitHub Actions secrets or variables (repo level only).
|
|
84
|
+
* `null` if gh CLI unavailable, unauthenticated, or not a GitHub repo.
|
|
85
|
+
*/
|
|
86
|
+
function listGhNames(kind: "secret" | "variable"): string[] | null {
|
|
87
|
+
const res = spawnSync("gh", [kind, "list", "--json", "name", "-q", ".[].name"], {
|
|
88
|
+
encoding: "utf-8",
|
|
89
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
90
|
+
timeout: 5000,
|
|
91
|
+
});
|
|
92
|
+
if (res.status !== 0 || typeof res.stdout !== "string") return null;
|
|
93
|
+
return res.stdout
|
|
94
|
+
.split("\n")
|
|
95
|
+
.map((s) => s.trim())
|
|
96
|
+
.filter(Boolean);
|
|
97
|
+
}
|
|
98
|
+
|
|
82
99
|
/**
|
|
83
100
|
* Detect whether a named secret is set on the consumer's GitHub repo.
|
|
84
101
|
* Returns "present" | "missing" | "unknown".
|
|
85
102
|
* "unknown" if gh CLI unavailable, unauthenticated, or not a GitHub repo.
|
|
86
103
|
*/
|
|
87
104
|
export function detectGhSecret(secretName: string): TokenPresence {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
92
|
-
timeout: 5000,
|
|
93
|
-
});
|
|
94
|
-
const names = out
|
|
95
|
-
.split("\n")
|
|
96
|
-
.map((s) => s.trim())
|
|
97
|
-
.filter(Boolean);
|
|
98
|
-
return names.includes(secretName) ? "present" : "missing";
|
|
99
|
-
} catch {
|
|
100
|
-
return "unknown";
|
|
101
|
-
}
|
|
105
|
+
const names = listGhNames("secret");
|
|
106
|
+
if (names === null) return "unknown";
|
|
107
|
+
return names.includes(secretName) ? "present" : "missing";
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
/**
|
|
@@ -116,18 +122,21 @@ export function buildCloudDashboardsAdvisory(cwd: string): PreflightFinding | nu
|
|
|
116
122
|
const hasCursor = fs.existsSync(path.join(cwd, ".cursor"));
|
|
117
123
|
if (!hasRouter && !hasClaude && !hasCursor) return null;
|
|
118
124
|
|
|
119
|
-
// cloud=claude path (bkit-cloud.yml): GitHub-tracker only, ANTHROPIC_API_KEY
|
|
120
|
-
// cloud=cursor path (.cursor/): BKIT_LINEAR_API_KEY for Cursor dashboard.
|
|
121
|
-
// Distinguish by recorded variant; fall back to presence-based detection.
|
|
122
|
-
const
|
|
123
|
-
const isCursorCloud =
|
|
125
|
+
// cloud=claude path (bkit-cloud.yml): GitHub-tracker only, ANTHROPIC_API_KEY or federation.
|
|
126
|
+
// cloud=cursor path (.cursor/): BKIT_LINEAR_API_KEY for Cursor dashboard; Linear-tracker only.
|
|
127
|
+
// Distinguish by recorded variant; fall back to presence-based detection under linear.
|
|
128
|
+
const config = readBkitConfig(cwd);
|
|
129
|
+
const isCursorCloud =
|
|
130
|
+
config.cloudAgents === "cursor" ||
|
|
131
|
+
(!hasRouter && hasCursor && config.issueTracker === "linear");
|
|
124
132
|
|
|
125
133
|
const secretList = isCursorCloud ? "`BKIT_LINEAR_API_KEY`" : "`ANTHROPIC_API_KEY`";
|
|
126
134
|
const ghSetLines = isCursorCloud
|
|
127
135
|
? " gh secret set BKIT_LINEAR_API_KEY --body='<value>'\n\n" +
|
|
128
136
|
" Verify: `gh secret list | grep -E 'BKIT_LINEAR_API_KEY'`\n\n"
|
|
129
137
|
: " gh secret set ANTHROPIC_API_KEY --body='<value>'\n\n" +
|
|
130
|
-
" Verify: `gh secret list | grep -E 'ANTHROPIC_API_KEY'`\n\n"
|
|
138
|
+
" Verify: `gh secret list | grep -E 'ANTHROPIC_API_KEY'`\n\n" +
|
|
139
|
+
" Keyless alternative for bkit-cloud.yml (workload identity federation): leave the secret unset and set the `ANTHROPIC_FEDERATION_RULE_ID` + `ANTHROPIC_ORGANIZATION_ID` repo variables (`gh variable set`) from a Claude Console federation rule.\n\n";
|
|
131
140
|
const vendorNote = isCursorCloud
|
|
132
141
|
? "BKIT_LINEAR_API_KEY is read from the Linear dashboard (https://linear.app/settings/api)."
|
|
133
142
|
: "ANTHROPIC_API_KEY is read from the Anthropic dashboard (https://console.anthropic.com/settings/keys); `.bkit/.env` holds the same value as BKIT_ANTHROPIC_API_KEY. The Claude GitHub App (`/install-github-app`) is also required for `cloud=claude`.";
|
|
@@ -147,35 +156,69 @@ export function buildCloudDashboardsAdvisory(cwd: string): PreflightFinding | nu
|
|
|
147
156
|
};
|
|
148
157
|
}
|
|
149
158
|
|
|
159
|
+
/** Repo variables that, both set, switch bkit-cloud.yml's claude job to workload identity federation. */
|
|
160
|
+
const FEDERATION_VARIABLES = ["ANTHROPIC_FEDERATION_RULE_ID", "ANTHROPIC_ORGANIZATION_ID"];
|
|
161
|
+
|
|
150
162
|
/**
|
|
151
|
-
* Detect whether
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* GitHub-tracker only — no
|
|
155
|
-
*
|
|
163
|
+
* Detect whether `bkit-cloud.yml`'s claude job has a credential. Only fires when
|
|
164
|
+
* `.github/workflows/bkit-cloud.yml` exists. The claude job (claude-code-action) takes the
|
|
165
|
+
* `ANTHROPIC_API_KEY` repo secret OR workload identity federation (both
|
|
166
|
+
* `FEDERATION_VARIABLES` repo variables). The workflow is GitHub-tracker only — no
|
|
167
|
+
* `BKIT_LINEAR_API_KEY` dependency. Silent when gh cannot list secrets; when only the
|
|
168
|
+
* variables are unlistable, a missing key still raises the missing-credential finding.
|
|
156
169
|
*/
|
|
157
170
|
export function detectCiRouterSecrets(cwd: string): PreflightFinding[] {
|
|
158
|
-
const findings: PreflightFinding[] = [];
|
|
159
171
|
const routerPath = path.join(cwd, ".github", "workflows", "bkit-cloud.yml");
|
|
160
|
-
if (!fs.existsSync(routerPath)) return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
id:
|
|
172
|
+
if (!fs.existsSync(routerPath)) return [];
|
|
173
|
+
const key = detectGhSecret("ANTHROPIC_API_KEY");
|
|
174
|
+
if (key === "unknown") return [];
|
|
175
|
+
const variables = listGhNames("variable");
|
|
176
|
+
const federated = variables !== null && FEDERATION_VARIABLES.every((v) => variables.includes(v));
|
|
177
|
+
|
|
178
|
+
if (key === "present" && federated) {
|
|
179
|
+
return [
|
|
180
|
+
{
|
|
181
|
+
id: "anthropic-api-key-shadows-federation",
|
|
170
182
|
severity: "advisory",
|
|
171
|
-
detect:
|
|
183
|
+
detect:
|
|
184
|
+
"The `ANTHROPIC_API_KEY` repo secret and the `ANTHROPIC_FEDERATION_RULE_ID` + `ANTHROPIC_ORGANIZATION_ID` repo variables are all set. claude-code-action uses the key and skips workload identity federation.",
|
|
172
185
|
action:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
// "unknown" → silent skip (CLI absent / unauthenticated).
|
|
186
|
+
"To run keyless, delete the secret: `gh secret delete ANTHROPIC_API_KEY`. To stay on the key, delete the variables: `gh variable delete ANTHROPIC_FEDERATION_RULE_ID` and `gh variable delete ANTHROPIC_ORGANIZATION_ID`.",
|
|
187
|
+
},
|
|
188
|
+
];
|
|
179
189
|
}
|
|
180
|
-
return
|
|
190
|
+
if (key === "present") return [];
|
|
191
|
+
|
|
192
|
+
if (federated) {
|
|
193
|
+
if (fs.readFileSync(routerPath, "utf-8").includes("anthropic_federation_rule_id:")) return [];
|
|
194
|
+
return [
|
|
195
|
+
{
|
|
196
|
+
id: "anthropic-federation-template-stale",
|
|
197
|
+
severity: "advisory",
|
|
198
|
+
detect:
|
|
199
|
+
"The `ANTHROPIC_FEDERATION_RULE_ID` + `ANTHROPIC_ORGANIZATION_ID` repo variables are set, but `.github/workflows/bkit-cloud.yml` does not pass `anthropic_federation_rule_id` to claude-code-action — the claude job exits no-op.",
|
|
200
|
+
action:
|
|
201
|
+
"Re-copy the template: `cp .bkit/templates/.github/workflows/bkit-cloud.yml .github/workflows/bkit-cloud.yml`, then re-apply your own edits (the `runs-on` runner at minimum).",
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return [
|
|
207
|
+
{
|
|
208
|
+
id: "anthropic-api-key-secret-missing",
|
|
209
|
+
severity: "advisory",
|
|
210
|
+
detect:
|
|
211
|
+
variables === null
|
|
212
|
+
? "gh confirms the `ANTHROPIC_API_KEY` repo secret is not set on this GitHub repo, and could not list repo variables to check for the `ANTHROPIC_FEDERATION_RULE_ID` + `ANTHROPIC_ORGANIZATION_ID` federation variables."
|
|
213
|
+
: "gh confirms neither the `ANTHROPIC_API_KEY` repo secret nor both `ANTHROPIC_FEDERATION_RULE_ID` + `ANTHROPIC_ORGANIZATION_ID` repo variables are set on this GitHub repo.",
|
|
214
|
+
action:
|
|
215
|
+
"`.github/workflows/bkit-cloud.yml`'s claude job needs one claude credential; without it, the job exits no-op. Set ONE of:\n\n" +
|
|
216
|
+
"- API key:\n\n gh secret set ANTHROPIC_API_KEY --body='<paste-value-here>'\n\n" +
|
|
217
|
+
"- Workload identity federation (keyless): Claude Console → Settings → Workload identity → Connect workload → GitHub Actions creates the issuer, service account and federation rule. Then:\n\n" +
|
|
218
|
+
" gh variable set ANTHROPIC_FEDERATION_RULE_ID --body='fdrl_...'\n" +
|
|
219
|
+
" gh variable set ANTHROPIC_ORGANIZATION_ID --body='<organization-uuid>'\n\n" +
|
|
220
|
+
" Optional: `ANTHROPIC_SERVICE_ACCOUNT_ID` (`svac_...`) and `ANTHROPIC_WORKSPACE_ID` (`wrkspc_...`, needed when the rule covers more than one workspace).\n\n" +
|
|
221
|
+
"Then verify: `gh secret list` / `gh variable list`. The workflow itself does not need redeploying — both are read at run time.",
|
|
222
|
+
},
|
|
223
|
+
];
|
|
181
224
|
}
|
|
@@ -70,7 +70,8 @@ export function detectActionsWritePermissions(): TokenPresence {
|
|
|
70
70
|
*
|
|
71
71
|
* - `github` → GitHub tracker: the GitHub MCP server authenticates with `BKIT_GH_TOKEN`; `gh` uses `gh auth login`.
|
|
72
72
|
* - `linear` → existing Linear setup message (BKIT_LINEAR_API_KEY + LINEAR_ISSUE_ID).
|
|
73
|
-
* - `
|
|
73
|
+
* - `jira` → admin switch, BKIT_JIRA_API_TOKEN and `bkit.jira` in package.json.
|
|
74
|
+
* - `none` → prompt to run `bkit install --tracker=github`, `--tracker=linear` or `--tracker=jira`.
|
|
74
75
|
*
|
|
75
76
|
* Only fires when bkit workflows are installed (.claude/ or .cursor/ present).
|
|
76
77
|
*/
|
|
@@ -102,6 +103,16 @@ export function buildTrackerSetupAdvisory(cwd: string): PreflightFinding | null
|
|
|
102
103
|
};
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
if (tracker === "jira") {
|
|
107
|
+
return {
|
|
108
|
+
id: "tracker-setup-jira",
|
|
109
|
+
severity: "advisory",
|
|
110
|
+
detect: "bkit tracker is configured as `jira`. Jira Cloud is the active tracker.",
|
|
111
|
+
action:
|
|
112
|
+
'Jira tracker: (1) an org admin turns on API-token sign-in for the Rovo MCP server (admin.atlassian.com → Rovo → Rovo MCP server → Authentication → "Allow API token authentication"); (2) create an API token with scopes for the app "Atlassian MCP V2" at https://id.atlassian.com/manage-profile/security/api-tokens and set it as `BKIT_JIRA_API_TOKEN` in `.bkit/.env`, then `direnv allow`; (3) set `bkit.jira.site` (e.g. `https://acme.atlassian.net`) and `bkit.jira.project` (the project key) in package.json. Full steps: `.bkit/trackers.md` § jira.',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
// tracker === "none". Distinguish opt-out (explicit `bkit.issueTracker: "none"`)
|
|
106
117
|
// from undecided (field absent). An explicit `none` silences the nudge, as with the
|
|
107
118
|
// dep-updater advisory.
|
|
@@ -113,7 +124,7 @@ export function buildTrackerSetupAdvisory(cwd: string): PreflightFinding | null
|
|
|
113
124
|
detect:
|
|
114
125
|
"bkit tracker is not configured (`bkit.issueTracker` absent). Workflows run but every tracker call is a no-op.",
|
|
115
126
|
action:
|
|
116
|
-
'Optional post-install decision. Run `bkit install --tracker=github` (recommended)
|
|
127
|
+
'Optional post-install decision. Run `bkit install --tracker=github` (recommended), `--tracker=linear` or `--tracker=jira` to enable tracker integration. GitHub tracker requires `BKIT_GH_TOKEN` in `.bkit/.env` (fine-grained PAT for one owner, classic PAT across owners). Linear tracker requires `BKIT_LINEAR_API_KEY` in `.bkit/.env`. Jira tracker requires `BKIT_JIRA_API_TOKEN` in `.bkit/.env` and `bkit.jira` in package.json. To opt out and silence this advisory, set `bkit.issueTracker` to `"none"` in package.json.',
|
|
117
128
|
};
|
|
118
129
|
}
|
|
119
130
|
|
|
@@ -276,6 +287,7 @@ export function detectGithubProjectFieldIdFormat(cwd: string): PreflightFinding
|
|
|
276
287
|
* opt-out):
|
|
277
288
|
* - `.github/workflows/bkit-cloud.yml` present → `cloud-router` (informational; active)
|
|
278
289
|
* - `bkit.cloudAgents === "none"` → null (opt-out — stay quiet)
|
|
290
|
+
* - `bkit.issueTracker === "jira"` → null (Jira runs locally only)
|
|
279
291
|
* - otherwise (undecided) → `cloud-router-none` (nudge to choose)
|
|
280
292
|
*
|
|
281
293
|
* Only fires when there is a `.github/workflows/` dir (the router wakes on a CI
|
|
@@ -307,15 +319,16 @@ export function buildCloudSetupAdvisory(cwd: string): PreflightFinding | null {
|
|
|
307
319
|
severity: "advisory",
|
|
308
320
|
detect:
|
|
309
321
|
"Cloud agents: post-CI auto-routing is active (`.github/workflows/bkit-cloud.yml` present). The Claude GitHub App is required — run `/install-github-app` (Claude Code CLI) once if not already done.",
|
|
310
|
-
action: `The workflow requires: the \`ANTHROPIC_API_KEY\` repo secret, the Claude GitHub App (\`/install-github-app\`), and GitHub Actions write permissions (org AND repo). See the \`bkit-auto-setup\` advisory (emitted by \`bkit install --auto=claude\`) and bkit's \`cloud.md\` § Post-CI auto-routing for the full checklist.\n\nbkit's agents comment as you, so every workflow those comments trigger notifies you, even ones that skip. To see only failures: GitHub → Settings → Notifications → System → Actions → "Only notify for failed workflows".`,
|
|
322
|
+
action: `The workflow requires: the \`ANTHROPIC_API_KEY\` repo secret OR the \`ANTHROPIC_FEDERATION_RULE_ID\` + \`ANTHROPIC_ORGANIZATION_ID\` repo variables (keyless workload identity federation), the Claude GitHub App (\`/install-github-app\`), and GitHub Actions write permissions (org AND repo). See the \`bkit-auto-setup\` advisory (emitted by \`bkit install --auto=claude\`) and bkit's \`cloud.md\` § Post-CI auto-routing for the full checklist.\n\nbkit's agents comment as you, so every workflow those comments trigger notifies you, even ones that skip. To see only failures: GitHub → Settings → Notifications → System → Actions → "Only notify for failed workflows".`,
|
|
311
323
|
};
|
|
312
324
|
}
|
|
313
325
|
|
|
314
326
|
// No router present — distinguish opt-out from undecided.
|
|
315
|
-
const { cloudAgents, cloudAgentsExplicit } = readBkitConfig(cwd);
|
|
327
|
+
const { cloudAgents, cloudAgentsExplicit, issueTracker } = readBkitConfig(cwd);
|
|
316
328
|
if (cloudAgents === "none" && cloudAgentsExplicit) {
|
|
317
329
|
return null; // consumer explicitly chose `none` — stay quiet
|
|
318
330
|
}
|
|
331
|
+
if (issueTracker === "jira") return null; // no cloud setup exists for a Jira tracker
|
|
319
332
|
|
|
320
333
|
// Only nudge if there's a workflows dir for the router to wake on.
|
|
321
334
|
if (!fs.existsSync(path.join(cwd, ".github", "workflows"))) return null;
|
|
@@ -327,7 +340,7 @@ export function buildCloudSetupAdvisory(cwd: string): PreflightFinding | null {
|
|
|
327
340
|
"Cloud agents: post-CI auto-routing is not configured. `.github/workflows/` exists but no `bkit-cloud.yml` — CI pass/fail does not auto-dispatch bkit-ship / bkit-debug.",
|
|
328
341
|
action:
|
|
329
342
|
"Optional post-install decision. For a GitHub-tracker repo: `pnpm bkit install --auto=claude --tracker=github`. For a Linear-tracker repo: `pnpm bkit install --auto=cursor --tracker=linear`.\n\n" +
|
|
330
|
-
"Prerequisites for `--auto=claude`: `ANTHROPIC_API_KEY` repo secret + Claude GitHub App (`/install-github-app`) + GitHub Actions write permissions.\n\n" +
|
|
343
|
+
"Prerequisites for `--auto=claude`: `ANTHROPIC_API_KEY` repo secret (or the `ANTHROPIC_FEDERATION_RULE_ID` + `ANTHROPIC_ORGANIZATION_ID` repo variables for keyless workload identity federation) + Claude GitHub App (`/install-github-app`) + GitHub Actions write permissions.\n\n" +
|
|
331
344
|
'To opt out and silence this advisory, set `bkit.cloudAgents` to `"none"` in package.json.',
|
|
332
345
|
};
|
|
333
346
|
}
|
|
@@ -404,7 +404,7 @@ export function runPostInstallCheck(
|
|
|
404
404
|
const cloudSetup = buildCloudSetupAdvisory(cwd);
|
|
405
405
|
if (cloudSetup) phase3.push(cloudSetup);
|
|
406
406
|
|
|
407
|
-
// bkit-cloud.yml needs the ANTHROPIC_API_KEY repo secret.
|
|
407
|
+
// bkit-cloud.yml's claude job needs the ANTHROPIC_API_KEY repo secret or federation variables.
|
|
408
408
|
for (const f of detectCiRouterSecrets(cwd)) phase3.push(f);
|
|
409
409
|
|
|
410
410
|
// bkit-cloud.yml also needs repo Actions write permissions + PR-creation
|
|
@@ -148,7 +148,7 @@ const BKIT_STUBS: BkitStub[] = [
|
|
|
148
148
|
id: "coverage",
|
|
149
149
|
file: ".github/workflows/bkit-ci.yml",
|
|
150
150
|
description:
|
|
151
|
-
"Report vitest coverage on PRs and in every run's job summary via davelosert/vitest-coverage-report-action (free, runs inside Actions with GITHUB_TOKEN — no third-party service, safe for private repos). PER-TIER: unit and integration are measured and commented SEPARATELY (a single merged number lets integration mask a hollow unit suite — coverage is a union). Report-only by default: nothing fails the build until a threshold is set. Enabling (documented in the stub header): (1) add `@vitest/coverage-v8` (pinned to your vitest major) plus a vitest.config coverage block with `reporter: ['text','json-summary','json']` and `reportOnFailure: true` — json-summary + json are load-bearing (the action reads coverage-summary.json and coverage-final.json); (2) run coverage TWICE into separate dirs — unit → coverage/unit (exclude integration files), integration → coverage/integration — so each tier gets its own honest number (avoids the last-writer-wins clobber a second same-dir run would cause); (3) add a JOB-LEVEL permissions block to bkit-tests-unit with `actions: read` + `contents: read` + `pull-requests: write` — job-level REPLACES the workflow-level block (not additive) and the Check
|
|
151
|
+
"Report vitest coverage on PRs and in every run's job summary via davelosert/vitest-coverage-report-action (free, runs inside Actions with GITHUB_TOKEN — no third-party service, safe for private repos). PER-TIER: unit and integration are measured and commented SEPARATELY (a single merged number lets integration mask a hollow unit suite — coverage is a union). Report-only by default: nothing fails the build until a threshold is set. Enabling (documented in the stub header): (1) add `@vitest/coverage-v8` (pinned to your vitest major) plus a vitest.config coverage block with `reporter: ['text','json-summary','json']` and `reportOnFailure: true` — json-summary + json are load-bearing (the action reads coverage-summary.json and coverage-final.json); (2) run coverage TWICE into separate dirs — unit → coverage/unit (exclude integration files), integration → coverage/integration — so each tier gets its own honest number (avoids the last-writer-wins clobber a second same-dir run would cause); (3) add a JOB-LEVEL permissions block to bkit-tests-unit with `actions: read` + `contents: read` + `pull-requests: write` — job-level REPLACES the workflow-level block (not additive) and the Check Tree Cache step needs `actions: read`, so omitting it breaks the cache step; (4) two report steps with distinct `name:` (unit / integration) pointing at each dir's coverage-summary.json + coverage-final.json; the unit step runs on every event (`if: !cancelled()` plus a `hashFiles` guard on its summary), sets `vite-config-path: vitest.unit.config.ts` so the job summary and PR comment show the floor as the target, and comments only on same-repo PRs (`comment-on: pr`, else `none`). SEPARATE LANES (one job per tier): put the integration run + report + its OWN pull-requests: write block in bkit-tests-integration, not bkit-tests-unit — each lane posts its own comment. Thresholds are opt-in and PER TIER: UNIT is the gate — put `coverage.thresholds.branches` in a `vitest.unit.config.ts` (`mergeConfig` over vitest.config) that ONLY the unit run loads via `-c` (vitest coverage is per-RUN/root config, NOT per-project — `projects` does not scope it and a `thresholds` block in vitest.config reds BOTH runs; the report action reads the same file as raw text, so keep the floor on one unquoted `branches: <n>` line and no other metric name + colon + number in it; branches is the meaningful floor, set to current and ratchet up). INTEGRATION is REPORT-ONLY — gate it on EXECUTION (the capstone's integration_ran > 0), not a %: a whole-repo integration % is denominator-noise (it covers boundaries/flows, not pure logic). For a real integration %, add `--coverage.include=src/server/**` on the integration run (same CLI-flag idiom as --exclude) then set a floor, or ratchet from current — never a picked number. Fork PRs: GITHUB_TOKEN is read-only, so the unit step sets `comment-on: none` there (its job summary still lands) and the integration step keeps the `head.repo == repo` guard (or use the action's workflow_run two-workflow pattern). Guard the integration report on `hashFiles('coverage/integration/coverage-summary.json') != ''` so a repo with no integration tier skips it cleanly.",
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
154
|
id: "e2e-coverage",
|
|
@@ -11,14 +11,33 @@ import type { PreflightFinding } from "./index.js";
|
|
|
11
11
|
// [mcp-env] advisories — direnv + .bkit/.env setup (BAR-260)
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
13
|
|
|
14
|
+
/** The token a tracker's MCP server reads from `.bkit/.env`, beside `BKIT_GH_TOKEN`. */
|
|
15
|
+
const TRACKER_TOKENS: Partial<Record<IssueTracker, { key: string; description: string }>> = {
|
|
16
|
+
linear: {
|
|
17
|
+
key: "BKIT_LINEAR_API_KEY",
|
|
18
|
+
description:
|
|
19
|
+
"Linear personal API key for the Linear MCP server and the Linear preflight hook (generate at https://linear.app/settings/api)",
|
|
20
|
+
},
|
|
21
|
+
jira: {
|
|
22
|
+
key: "BKIT_JIRA_API_TOKEN",
|
|
23
|
+
description:
|
|
24
|
+
'Atlassian API token with scopes for the app "Atlassian MCP V2", sent as Bearer to the Jira MCP server (create at https://id.atlassian.com/manage-profile/security/api-tokens; see .bkit/trackers.md § jira)',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** The token names `tracker` needs, `BKIT_GH_TOKEN` first. */
|
|
29
|
+
function tokenKeys(tracker: IssueTracker): string[] {
|
|
30
|
+
const own = TRACKER_TOKENS[tracker];
|
|
31
|
+
return own ? ["BKIT_GH_TOKEN", own.key] : ["BKIT_GH_TOKEN"];
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
/**
|
|
15
35
|
* Advisory: .bkit/.env.example exists but .bkit/.env does not.
|
|
16
36
|
* Consumer ran `bkit install` (which seeds .env.example) but has not yet
|
|
17
37
|
* copied it to .bkit/.env and filled in their tokens.
|
|
18
38
|
*/
|
|
19
|
-
// `tracker`
|
|
20
|
-
//
|
|
21
|
-
// caller passes the consumer's resolved `bkit.issueTracker`.
|
|
39
|
+
// `tracker` adds its own token to the token prose (`TRACKER_TOKENS`). Defaults to
|
|
40
|
+
// `linear`; the real Phase-3 caller passes the consumer's resolved `bkit.issueTracker`.
|
|
22
41
|
export function detectMissingDotenv(
|
|
23
42
|
cwd: string,
|
|
24
43
|
tracker: IssueTracker = "linear",
|
|
@@ -27,7 +46,7 @@ export function detectMissingDotenv(
|
|
|
27
46
|
const envPath = path.join(cwd, ".bkit", ".env");
|
|
28
47
|
if (!fs.existsSync(examplePath)) return null;
|
|
29
48
|
if (fs.existsSync(envPath)) return null;
|
|
30
|
-
const tokens = tracker
|
|
49
|
+
const tokens = tokenKeys(tracker).join(", ");
|
|
31
50
|
return {
|
|
32
51
|
id: "mcp-env-missing-dotenv",
|
|
33
52
|
severity: "advisory",
|
|
@@ -68,16 +87,8 @@ export function detectBlankDotenvKeys(
|
|
|
68
87
|
description:
|
|
69
88
|
"fine-grained PAT for the GitHub MCP server (Contents, Pull requests, Issues, Actions, Workflows, Metadata — read/write), or a classic PAT when one token must span owners",
|
|
70
89
|
},
|
|
71
|
-
//
|
|
72
|
-
...(tracker
|
|
73
|
-
? [
|
|
74
|
-
{
|
|
75
|
-
key: "BKIT_LINEAR_API_KEY",
|
|
76
|
-
description:
|
|
77
|
-
"Linear personal API key for the Linear MCP server and the Linear preflight hook (generate at https://linear.app/settings/api)",
|
|
78
|
-
},
|
|
79
|
-
]
|
|
80
|
-
: []),
|
|
90
|
+
// A tracker token is required only under its tracker.
|
|
91
|
+
...(TRACKER_TOKENS[tracker] ? [TRACKER_TOKENS[tracker]] : []),
|
|
81
92
|
];
|
|
82
93
|
|
|
83
94
|
const findings: PreflightFinding[] = [];
|
|
@@ -121,9 +132,8 @@ export function detectDirenvMissing(
|
|
|
121
132
|
|
|
122
133
|
const result = spawnSync("which", ["direnv"], { encoding: "utf-8" });
|
|
123
134
|
if (result.status === 0 && result.stdout.trim()) return null;
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
const exportKeys = tracker === "linear" ? "BKIT_GH_TOKEN / BKIT_LINEAR_API_KEY" : "BKIT_GH_TOKEN";
|
|
135
|
+
const editKeys = tokenKeys(tracker).join(", ");
|
|
136
|
+
const exportKeys = tokenKeys(tracker).join(" / ");
|
|
127
137
|
return {
|
|
128
138
|
id: "mcp-env-direnv-missing",
|
|
129
139
|
severity: "advisory",
|
|
@@ -180,7 +190,7 @@ export function detectDirenvNotAllowed(
|
|
|
180
190
|
severity: "advisory",
|
|
181
191
|
detect:
|
|
182
192
|
"direnv is installed but the .envrc in this repo is blocked. .bkit/.env is not being auto-loaded.",
|
|
183
|
-
action: `[mcp-env] Run \`direnv allow\` in this repo to trust the .envrc and enable auto-load of .bkit/.env. direnv will then export ${tracker
|
|
193
|
+
action: `[mcp-env] Run \`direnv allow\` in this repo to trust the .envrc and enable auto-load of .bkit/.env. direnv will then export ${tokenKeys(tracker).join(" and ")} into your shell whenever you cd into the repo.`,
|
|
184
194
|
};
|
|
185
195
|
}
|
|
186
196
|
return null;
|
|
@@ -7,7 +7,7 @@ import type { IssueTracker } from "../../install/manifest.js";
|
|
|
7
7
|
import type { PreflightFinding } from "./index.js";
|
|
8
8
|
|
|
9
9
|
/** Every MCP server key bkit writes; `requiredMcpServersForTracker` picks the required subset. */
|
|
10
|
-
const BKIT_MCP_SERVERS: readonly string[] = ["linear", "github"];
|
|
10
|
+
const BKIT_MCP_SERVERS: readonly string[] = ["linear", "github", "jira"];
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* bkit-written servers a workflow step calls under every tracker, so never flagged as extra:
|
|
@@ -78,7 +78,9 @@ export function detectMissingMcpServers(
|
|
|
78
78
|
? `"url": "https://mcp.linear.app/mcp"`
|
|
79
79
|
: key === "github"
|
|
80
80
|
? `"url": "https://api.githubcopilot.com/mcp/"`
|
|
81
|
-
:
|
|
81
|
+
: key === "jira"
|
|
82
|
+
? `"url": "https://mcp.atlassian.com/v2/mcp"`
|
|
83
|
+
: `"url": "<server-url>"`;
|
|
82
84
|
findings.push({
|
|
83
85
|
id: `mcp-missing-server-${key}-${advisoryPathSlug(relPath)}`,
|
|
84
86
|
severity: "advisory",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// `bkit.ignoreAdvisories` entry silences both.
|
|
23
23
|
|
|
24
24
|
import * as fs from "node:fs";
|
|
25
|
+
import * as path from "node:path";
|
|
25
26
|
|
|
26
27
|
import { machineStepsPath, REPO_STEPS } from "../../commands/workflow/disk.js";
|
|
27
28
|
import { detectContextFetchMissing } from "../before/context-fetch.js";
|
|
@@ -87,7 +88,7 @@ export const SETUP_TIPS: readonly SetupTip[] = [
|
|
|
87
88
|
id: "tracker",
|
|
88
89
|
workflows: EVERY_CONTEXT,
|
|
89
90
|
title: "Connect an issue tracker",
|
|
90
|
-
line: "bkit isn't connected to an issue tracker, so it can't read the task it's working on or record what it did. Connect GitHub or
|
|
91
|
+
line: "bkit isn't connected to an issue tracker, so it can't read the task it's working on or record what it did. Connect GitHub, Linear or Jira, or switch this tip off if you don't want one.",
|
|
91
92
|
why: "Every workflow starts by reading the issue it's working on and reports progress back to it as it goes. Without a tracker, you have to paste in what the agent should look at each time, and nothing records what changed or why.",
|
|
92
93
|
ask: 'Connect bkit to GitHub Issues: re-run `bkit install` with the tool flags I use plus `--tracker=github` (it records `bkit.issueTracker` in package.json and adds the tracker server to .mcp.json). If I don\'t want a tracker, set `"issueTracker": "none"` under `bkit` in package.json instead.',
|
|
93
94
|
steps:
|
|
@@ -235,7 +236,7 @@ export const SETUP_TIPS: readonly SetupTip[] = [
|
|
|
235
236
|
title: "Finish cloud setup",
|
|
236
237
|
line: "You've turned on cloud agents, but setup isn't finished, so cloud runs will stop partway. Finish the remaining steps.",
|
|
237
238
|
why: "With cloud agents, bkit runs on its own: a change that passes its checks gets shipped and one that fails gets investigated, with nobody at the keyboard. That only works once every piece is in place.",
|
|
238
|
-
ask: "Check my cloud-agent setup against .bkit/cloud.md: copy .bkit/templates/.github/workflows/bkit-cloud.yml to .github/workflows/bkit-cloud.yml and .bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh to .claude/hooks/ (for Cursor: .bkit/templates/.cursor/environment.json and .bkit/templates/.cursor/Dockerfile to .cursor/), run `gh secret set ANTHROPIC_API_KEY
|
|
239
|
+
ask: "Check my cloud-agent setup against .bkit/cloud.md: copy .bkit/templates/.github/workflows/bkit-cloud.yml to .github/workflows/bkit-cloud.yml and .bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh to .claude/hooks/ (for Cursor: .bkit/templates/.cursor/environment.json and .bkit/templates/.cursor/Dockerfile to .cursor/), run `gh secret set ANTHROPIC_API_KEY` (or, keyless, `gh variable set` ANTHROPIC_FEDERATION_RULE_ID and ANTHROPIC_ORGANIZATION_ID from a Claude Console federation rule), then tell me which dashboard settings are left.",
|
|
239
240
|
steps: "`.bkit/cloud.md`; `.bkit/templates.md` § Cloud-agent workflow and § Cursor.",
|
|
240
241
|
fires: (cwd) => {
|
|
241
242
|
const cloud = readBkitConfig(cwd).cloudAgents;
|
|
@@ -378,6 +379,18 @@ export const SETUP_TIPS: readonly SetupTip[] = [
|
|
|
378
379
|
fires: (cwd) =>
|
|
379
380
|
exists(cwd, ".husky/pre-push") && !exists(cwd, "scripts/cleanup/bkit-tmp-prune.mjs"),
|
|
380
381
|
},
|
|
382
|
+
{
|
|
383
|
+
id: "min-push",
|
|
384
|
+
workflows: ["plan", "ship"],
|
|
385
|
+
title: "Quick pushes for logs and records",
|
|
386
|
+
line: "Pushing only plan logs and records still runs every test. Add the quick path for those pushes.",
|
|
387
|
+
why: "A workflow's last push is often just its logs and records. The quick path checks only formatting and wording on such a push, so it takes seconds and never waits on anything another session is using. Any other file still runs everything.",
|
|
388
|
+
ask: 'Copy the min-push parts of .bkit/templates/.husky/pre-push into .husky/pre-push: PUSH_SHAS / PUSH_SHARED_SHAS in the stdin loop, the `Min push` and `CI-suppressor guard on dev / main` blocks, and the `bkit:gate:min` branch. Wrap slow checks below the gates in `if [ "$MIN_PUSH" != "1" ]`.',
|
|
389
|
+
steps: "`.bkit/templates.md` § Git hooks.",
|
|
390
|
+
fires: (cwd) =>
|
|
391
|
+
exists(cwd, ".husky/pre-push") &&
|
|
392
|
+
!fs.readFileSync(path.join(cwd, ".husky/pre-push"), "utf-8").includes("bkit ci min-push"),
|
|
393
|
+
},
|
|
381
394
|
{
|
|
382
395
|
id: "disk-prune",
|
|
383
396
|
workflows: ALL_WORKFLOWS,
|
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);
|
|
@@ -727,18 +727,20 @@ Dependency updaters (copy an example and own it):
|
|
|
727
727
|
|
|
728
728
|
--auto=<claude|cursor|opencode>
|
|
729
729
|
Cloud-agent (auto-dispatch) integration (opt-in). --auto=claude needs
|
|
730
|
-
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
|
|
731
733
|
needs tracker=linear; --auto=opencode needs tracker=github + a remote
|
|
732
734
|
opencode provider (OPENCODE_PROVIDER_KEY). Bare --auto is accepted on
|
|
733
735
|
uninstall only.
|
|
734
736
|
|
|
735
737
|
Cross-cutting / modifiers:
|
|
736
|
-
--tracker=<name> Wire issue tracker integration. Values: github, linear, none
|
|
738
|
+
--tracker=<name> Wire issue tracker integration. Values: github, linear, jira, none
|
|
737
739
|
(default). Records bkit.issueTracker in package.json and substitutes
|
|
738
740
|
tracker snippets into command mirrors. Re-renders every installed
|
|
739
741
|
host, and works alone (bkit install --tracker=github). Switching is
|
|
740
|
-
free; a switch removes the old linear MCP entry unless you
|
|
741
|
-
(github always stays). Does NOT own AGENTS.md (tracker-agnostic).
|
|
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).
|
|
742
744
|
|
|
743
745
|
Install flags:
|
|
744
746
|
--auto-revert On a Phase 3 blocker, automatically run uninstall and 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
|
};
|