@cbartens/bkit 5.2.2 → 5.2.4
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 +4 -2
- package/.bkit/core/.agents/context.md +2 -2
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +7 -1
- package/.bkit/core/.bkit/README.md +3 -1
- package/.bkit/core/.bkit/comparison.md +114 -45
- package/.bkit/core/.bkit/install.md +6 -6
- package/.bkit/core/.bkit/jsonl.md +3 -3
- package/.bkit/core/.bkit/prompts.md +6 -5
- package/.bkit/core/.bkit/providers.md +5 -4
- package/.bkit/core/.bkit/templates.md +30 -11
- package/.bkit/core/.bkit/workflows.md +14 -7
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +5 -1
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -2
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-agents.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +15 -4
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-config.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-cost.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-database.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-failures.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +15 -4
- package/.bkit/core/docs/templates/bkit-audit-gates.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-issues.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-llm.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-logs.md +25 -13
- package/.bkit/core/docs/templates/bkit-audit-models.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-repo.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-security.md +15 -4
- package/.bkit/core/docs/templates/bkit-audit-slop.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-testing.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-usability.md +13 -2
- package/.bkit/core/docs/templates/bkit-plan.md +1 -1
- package/.bkit/core/engine/checks/tips/catalogue.ts +10 -0
- package/.bkit/core/engine/commands/install/check.ts +3 -11
- package/.bkit/core/engine/commands/install/doctor.ts +2 -3
- package/.bkit/core/engine/commands/install/uninstall.ts +60 -44
- package/.bkit/core/engine/commands/install/upgrade.ts +13 -11
- package/.bkit/core/engine/commands/workflow/branches.ts +72 -9
- package/.bkit/core/engine/commands/workflow/repo.ts +16 -2
- package/.bkit/core/engine/commands/workflow/workflows.ts +4 -3
- package/.bkit/core/engine/install/hosts.ts +14 -4
- package/.bkit/core/engine/ledgers/telemetry.ts +3 -4
- package/.bkit/core/engine/shared/bkit-latest.ts +164 -0
- package/.bkit/core/engine/shared/timeouts.ts +6 -0
- package/.bkit/core/hooks/guardrails-read.js +4 -9
- package/.bkit/core/hooks/guardrails-tiers.js +312 -28
- package/.bkit/core/prompts/bkit-audit-generate.md +21 -5
- package/.bkit/core/workflows/bkit-build.md +1 -1
- package/.bkit/core/workflows/bkit-debug.md +1 -1
- package/.bkit/core/workflows/bkit-design.md +1 -1
- package/.bkit/core/workflows/bkit-plan.md +1 -1
- package/.bkit/core/workflows/bkit-ship.md +1 -1
- package/.bkit/shared/.claude/settings.json +19 -0
- package/.bkit/shared/.opencode/opencode.json +21 -1
- package/.bkit/shared/docs/deployments.md +14 -0
- package/.bkit/templates/.github/workflows/bkit-ci.yml +9 -0
- package/.bkit/templates/.husky/pre-push +7 -0
- package/.bkit/templates/context/bkit-cloudrun.md +28 -19
- package/.bkit/templates/context/bkit-expo.md +30 -13
- package/.bkit/templates/context/bkit-inngest.md +54 -17
- package/.bkit/templates/context/bkit-resend.md +36 -8
- package/.bkit/templates/context/bkit-sentry.md +11 -4
- package/.bkit/templates/context/bkit-stripe.md +39 -22
- package/.bkit/templates/context/bkit-supabase.md +45 -20
- package/.bkit/templates/context/bkit-vercel.md +45 -16
- package/.bkit/templates/scripts/ci/accepted-advisories.json +7 -0
- package/.bkit/templates/scripts/ci/check-dependency-audit.mjs +200 -0
- package/.bkit/templates/scripts/ci/check-dependency-audit.test.mjs +127 -0
- package/.bkit/templates/scripts/cleanup/bkit-tmp-prune.mjs +115 -0
- package/CHANGELOG.md +56 -0
- package/README.md +76 -20
- package/dist/checks/tips/catalogue.js +9 -0
- package/dist/commands/install/check.js +3 -15
- package/dist/commands/install/doctor.js +2 -1
- package/dist/commands/install/uninstall.js +52 -45
- package/dist/commands/install/upgrade.js +13 -11
- package/dist/commands/workflow/branches.js +64 -10
- package/dist/commands/workflow/repo.js +14 -2
- package/dist/commands/workflow/workflows.js +4 -3
- package/dist/install/hosts.js +11 -4
- package/dist/shared/bkit-latest.js +150 -0
- package/dist/shared/timeouts.js +6 -0
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ import * as os from "node:os";
|
|
|
15
15
|
import * as path from "node:path";
|
|
16
16
|
import { gitEnv } from "../../ledgers/telemetry.js";
|
|
17
17
|
import { bodySkipToken, CommandError, EXIT, git, parseJson, repoRoot, runGit, SKIP_CI_TOKEN, } from "../lib.js";
|
|
18
|
+
import { bkitVersionStatus } from "../../shared/bkit-latest.js";
|
|
18
19
|
import { TIMEOUTS } from "../../shared/timeouts.js";
|
|
19
20
|
import { commitBookkeeping } from "./ledgers.js";
|
|
20
21
|
import { acquireDevLock, lockRoot, releaseLock, resolveMonth, workflowLockPath } from "./locks.js";
|
|
@@ -284,7 +285,17 @@ export function resolveRebase(top, onLog = () => undefined) {
|
|
|
284
285
|
// ---------------------------------------------------------------------------
|
|
285
286
|
const ANCHOR_OPEN = "<!-- bkit:anchor";
|
|
286
287
|
const ANCHOR_CLOSE = "-->";
|
|
287
|
-
|
|
288
|
+
/** Ends the visible line a stamp writes under the block when the doc came from an outdated bkit. */
|
|
289
|
+
const OUTDATED_MARK = "<!-- bkit:outdated -->";
|
|
290
|
+
const OUTDATED_LINE = new RegExp(`^.*${OUTDATED_MARK}\n(?:\n)?`, "gm");
|
|
291
|
+
export const ANCHOR_FIELDS = [
|
|
292
|
+
"baseSha",
|
|
293
|
+
"baseRef",
|
|
294
|
+
"designPath",
|
|
295
|
+
"designBaseSha",
|
|
296
|
+
"bkitVersion",
|
|
297
|
+
"bkitLatest",
|
|
298
|
+
];
|
|
288
299
|
/** Lines of `text` with whether each sits inside an anchor block (a `sed '/open/,/close/'` range). */
|
|
289
300
|
function anchorLines(text) {
|
|
290
301
|
const lines = text.split("\n");
|
|
@@ -319,16 +330,38 @@ export function readAnchor(text) {
|
|
|
319
330
|
}
|
|
320
331
|
return out;
|
|
321
332
|
}
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
|
|
333
|
+
/**
|
|
334
|
+
* The bkit release a doc is being generated from, for its anchor: undefined when
|
|
335
|
+
* this repo has no `.bkit/version` pin (nothing to record). Asks the registry for
|
|
336
|
+
* the newest release at most once a day; offline leaves `latest` null.
|
|
337
|
+
*/
|
|
338
|
+
export function anchorBkitStatus(cwd) {
|
|
339
|
+
const status = bkitVersionStatus(git(cwd, ["rev-parse", "--show-toplevel"]) ?? cwd, git(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]));
|
|
340
|
+
return status.version === null ? undefined : status;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* `text` with a fresh anchor block on top and every prior one removed, so re-stamping
|
|
344
|
+
* is idempotent. With `bkit`, the block records the release the doc came from and the
|
|
345
|
+
* newest one (empty when unknown); an outdated release adds one visible warning line
|
|
346
|
+
* under the block, replaced or dropped by the next stamp like the block itself.
|
|
347
|
+
*/
|
|
348
|
+
export function stampAnchor(text, baseSha, design, baseRef = UPSTREAM, bkit) {
|
|
349
|
+
const header = [ANCHOR_OPEN, `baseSha: ${baseSha}`, `baseRef: ${baseRef}`];
|
|
325
350
|
if (design)
|
|
326
351
|
header.push(`designPath: ${design.path}`, `designBaseSha: ${design.baseSha}`);
|
|
352
|
+
if (bkit)
|
|
353
|
+
header.push(`bkitVersion: ${bkit.version ?? ""}`, `bkitLatest: ${bkit.latest ?? ""}`);
|
|
327
354
|
header.push(ANCHOR_CLOSE);
|
|
328
|
-
|
|
355
|
+
let body = anchorLines(text)
|
|
329
356
|
.filter((l) => !l.inBlock)
|
|
330
357
|
.map((l) => (l.last ? l.line : `${l.line}\n`))
|
|
331
|
-
.join("")
|
|
358
|
+
.join("")
|
|
359
|
+
.replace(OUTDATED_LINE, "");
|
|
360
|
+
if (bkit?.outdated === true) {
|
|
361
|
+
// Blank lines on both sides of the warning, as prettier writes them.
|
|
362
|
+
header.push("", `> **Outdated bkit:** generated with bkit ${bkit.version} while ${bkit.latest} was out, so its workflow and template text may be stale. Upgrade with \`pnpm bkit upgrade --latest\` and regenerate if that matters. ${OUTDATED_MARK}`);
|
|
363
|
+
body = `\n${body.replace(/^\n+/, "")}`;
|
|
364
|
+
}
|
|
332
365
|
return `${header.join("\n")}\n${body}`;
|
|
333
366
|
}
|
|
334
367
|
// ---------------------------------------------------------------------------
|
|
@@ -947,6 +980,7 @@ function anchorStampVerb(ctx) {
|
|
|
947
980
|
}
|
|
948
981
|
if (baseSha === "")
|
|
949
982
|
throw new CommandError(EXIT.USAGE, "--base-sha must be non-empty");
|
|
983
|
+
const baseRef = str(ctx.flags.baseRef) ?? UPSTREAM;
|
|
950
984
|
const designFlag = str(ctx.flags.design);
|
|
951
985
|
const designFile = designFlag === undefined ? undefined : path.resolve(ctx.cwd, designFlag);
|
|
952
986
|
const design = designFlag !== undefined && designFile !== undefined && fs.existsSync(designFile)
|
|
@@ -955,8 +989,11 @@ function anchorStampVerb(ctx) {
|
|
|
955
989
|
baseSha: readAnchor(fs.readFileSync(designFile, "utf-8")).baseSha ?? "",
|
|
956
990
|
}
|
|
957
991
|
: undefined;
|
|
992
|
+
const bkit = anchorBkitStatus(ctx.cwd);
|
|
993
|
+
if (bkit?.advisory)
|
|
994
|
+
ctx.log(bkit.advisory);
|
|
958
995
|
const before = fs.readFileSync(file, "utf-8");
|
|
959
|
-
const after = stampAnchor(before, baseSha, design);
|
|
996
|
+
const after = stampAnchor(before, baseSha, design, baseRef, bkit);
|
|
960
997
|
// Temp file + rename: a crash mid-write never leaves a half-stamped doc.
|
|
961
998
|
const tmp = `${file}.bkit-anchor.tmp`;
|
|
962
999
|
fs.writeFileSync(tmp, after);
|
|
@@ -964,8 +1001,13 @@ function anchorStampVerb(ctx) {
|
|
|
964
1001
|
ctx.emit({
|
|
965
1002
|
file: rel,
|
|
966
1003
|
baseSha,
|
|
1004
|
+
baseRef,
|
|
967
1005
|
designPath: design?.path ?? null,
|
|
968
1006
|
designBaseSha: design?.baseSha ?? null,
|
|
1007
|
+
bkitVersion: bkit?.version ?? null,
|
|
1008
|
+
bkitLatest: bkit?.latest ?? null,
|
|
1009
|
+
bkitOutdated: bkit?.outdated ?? null,
|
|
1010
|
+
bkitAdvisory: bkit?.advisory ?? null,
|
|
969
1011
|
changed: before !== after,
|
|
970
1012
|
});
|
|
971
1013
|
return EXIT.OK;
|
|
@@ -983,7 +1025,7 @@ function anchorReadVerb(ctx) {
|
|
|
983
1025
|
ctx.emit({ ...fields, value: null, skip: reason, landed: null });
|
|
984
1026
|
return EXIT_ANCHOR_SKIP;
|
|
985
1027
|
};
|
|
986
|
-
const none =
|
|
1028
|
+
const none = Object.fromEntries(ANCHOR_FIELDS.map((f) => [f, null]));
|
|
987
1029
|
if (!fs.statSync(file, { throwIfNoEntry: false })?.isFile()) {
|
|
988
1030
|
if (against !== undefined)
|
|
989
1031
|
return skip("no-file", `no ${rel} — nothing to check`, none);
|
|
@@ -1206,7 +1248,7 @@ export const branchesCommand = {
|
|
|
1206
1248
|
run: landVerb,
|
|
1207
1249
|
},
|
|
1208
1250
|
"anchor-stamp": {
|
|
1209
|
-
summary: "Put a <!-- bkit:anchor --> block recording the base commit on top of a design/plan doc (idempotent).",
|
|
1251
|
+
summary: "Put a <!-- bkit:anchor --> block recording the base commit and bkit release on top of a design/plan doc or audit report (idempotent).",
|
|
1210
1252
|
flags: [
|
|
1211
1253
|
{ name: "file", type: "string", required: true, help: "doc to stamp (must exist)" },
|
|
1212
1254
|
{
|
|
@@ -1215,6 +1257,11 @@ export const branchesCommand = {
|
|
|
1215
1257
|
required: true,
|
|
1216
1258
|
help: "base commit the doc was written against (non-empty)",
|
|
1217
1259
|
},
|
|
1260
|
+
{
|
|
1261
|
+
name: "base-ref",
|
|
1262
|
+
type: "string",
|
|
1263
|
+
help: `ref baseSha was taken from (default ${UPSTREAM}; audit reports pass the audited branch)`,
|
|
1264
|
+
},
|
|
1218
1265
|
{
|
|
1219
1266
|
name: "design",
|
|
1220
1267
|
type: "string",
|
|
@@ -1224,8 +1271,13 @@ export const branchesCommand = {
|
|
|
1224
1271
|
output: {
|
|
1225
1272
|
file: "doc stamped",
|
|
1226
1273
|
baseSha: "base commit stamped",
|
|
1274
|
+
baseRef: "ref stamped",
|
|
1227
1275
|
designPath: "design path stamped (null when none)",
|
|
1228
1276
|
designBaseSha: "the design doc's baseSha stamped (null when none; empty when it had no anchor)",
|
|
1277
|
+
bkitVersion: "the .bkit/version pin stamped (null when unpinned: no bkit fields are stamped then)",
|
|
1278
|
+
bkitLatest: "newest published bkit stamped (null when unknown: stamped empty)",
|
|
1279
|
+
bkitOutdated: "true when bkitVersion is older than bkitLatest: a visible warning line is stamped under the block (null when unknown)",
|
|
1280
|
+
bkitAdvisory: "one warning line when bkitOutdated, else null",
|
|
1229
1281
|
changed: "false when the doc already carried exactly this block",
|
|
1230
1282
|
},
|
|
1231
1283
|
exitCodes: { [EXIT_NO_FILE]: "--file is missing or not a file" },
|
|
@@ -1234,7 +1286,7 @@ export const branchesCommand = {
|
|
|
1234
1286
|
"anchor-read": {
|
|
1235
1287
|
summary: "Read a doc's anchor fields; with --against, decide whether anything landed since its baseSha.",
|
|
1236
1288
|
flags: [
|
|
1237
|
-
{ name: "file", type: "string", required: true, help: "design/plan doc" },
|
|
1289
|
+
{ name: "file", type: "string", required: true, help: "design/plan doc or audit report" },
|
|
1238
1290
|
{
|
|
1239
1291
|
name: "field",
|
|
1240
1292
|
type: "string",
|
|
@@ -1251,6 +1303,8 @@ export const branchesCommand = {
|
|
|
1251
1303
|
baseRef: "anchor baseRef (null when absent)",
|
|
1252
1304
|
designPath: "anchor designPath (null when absent)",
|
|
1253
1305
|
designBaseSha: "anchor designBaseSha (null when absent)",
|
|
1306
|
+
bkitVersion: "anchor bkitVersion (null when absent)",
|
|
1307
|
+
bkitLatest: "anchor bkitLatest (null when absent)",
|
|
1254
1308
|
value: "the --field value (null when absent or no --field)",
|
|
1255
1309
|
skip: "with --against: no-file | no-anchor | unreachable | nothing-landed (null = run the check)",
|
|
1256
1310
|
landed: "with --against: paths changed between baseSha and the ref",
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
// `owner/repo` comes from `gh repo view`; when gh is missing, unauthed, or
|
|
5
5
|
// answers nothing, from the `origin` remote URL instead (the MCP fallback the
|
|
6
6
|
// workflows already describe: "parse git remote"). The current branch, how far it
|
|
7
|
-
// trails `origin/dev`, the main checkout,
|
|
8
|
-
//
|
|
7
|
+
// trails `origin/dev`, the main checkout, the bkit binary every later block calls,
|
|
8
|
+
// and whether that bkit is behind the newest release ride along so Step 1 is one call.
|
|
9
9
|
import * as fs from "node:fs";
|
|
10
10
|
import * as path from "node:path";
|
|
11
11
|
import { parseRemoteUrlToSlug } from "../../ledgers/telemetry.js";
|
|
12
12
|
import { EXIT, git, repoRoot, runGit, runTool } from "../lib.js";
|
|
13
|
+
import { bkitVersionStatus } from "../../shared/bkit-latest.js";
|
|
13
14
|
/** Exit code: neither gh nor the origin remote named an owner/repo. */
|
|
14
15
|
export const EXIT_NO_REPO = 3;
|
|
15
16
|
/** Exit code: HEAD is detached, so there is no current branch (and --allow-detached was not given). */
|
|
@@ -107,6 +108,10 @@ export const repoCommand = {
|
|
|
107
108
|
repoRoot: "the main checkout (the same from any worktree)",
|
|
108
109
|
bkit: "the bkit binary the workflow blocks call: <repoRoot>/node_modules/.bin/bkit, else `bkit` on PATH",
|
|
109
110
|
outboxRoot: "<git common dir>/bkit-outbox: per-run scratch files, never committed",
|
|
111
|
+
bkitVersion: ".bkit/version pinnedVersion: the release this repo's bkit files came from (null when unpinned)",
|
|
112
|
+
bkitLatest: "newest published @cbartens/bkit, asked at most once a day (null when offline, opted out via BKIT_NO_UPDATE_CHECK, or unpinned)",
|
|
113
|
+
bkitOutdated: "true when bkitVersion is older than bkitLatest (null when either is unknown)",
|
|
114
|
+
bkitAdvisory: "one line to show the user when bkitOutdated, else null",
|
|
110
115
|
},
|
|
111
116
|
exitCodes: {
|
|
112
117
|
[EXIT_NO_REPO]: "neither gh nor the origin remote named an owner/repo",
|
|
@@ -136,6 +141,9 @@ export const repoCommand = {
|
|
|
136
141
|
}
|
|
137
142
|
const root = repoRoot(ctx.cwd);
|
|
138
143
|
const common = git(ctx.cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
144
|
+
const latest = bkitVersionStatus(root, common);
|
|
145
|
+
if (latest.advisory !== null)
|
|
146
|
+
ctx.log(latest.advisory);
|
|
139
147
|
ctx.emit({
|
|
140
148
|
...resolved,
|
|
141
149
|
owner,
|
|
@@ -145,6 +153,10 @@ export const repoCommand = {
|
|
|
145
153
|
repoRoot: root,
|
|
146
154
|
bkit: resolveBkitBinary(root),
|
|
147
155
|
outboxRoot: path.join(common ?? path.join(root, ".git"), "bkit-outbox"),
|
|
156
|
+
bkitVersion: latest.version,
|
|
157
|
+
bkitLatest: latest.latest,
|
|
158
|
+
bkitOutdated: latest.outdated,
|
|
159
|
+
bkitAdvisory: latest.advisory,
|
|
148
160
|
});
|
|
149
161
|
if (branch === null && ctx.flags.allowDetached !== true) {
|
|
150
162
|
ctx.log("HEAD is detached — no current branch");
|
|
@@ -25,7 +25,7 @@ import { readBkitVersion } from "../../install/version-file.js";
|
|
|
25
25
|
import { TIMEOUTS } from "../../shared/timeouts.js";
|
|
26
26
|
import { gradeCompliance } from "../comply.js";
|
|
27
27
|
import { CommandError, EXIT, git, parseJson, repoRoot, runGh, runGit, statusLocation, statusRelPath, } from "../lib.js";
|
|
28
|
-
import { pushBranch, readAnchor, stampAnchor } from "./branches.js";
|
|
28
|
+
import { anchorBkitStatus, pushBranch, readAnchor, stampAnchor } from "./branches.js";
|
|
29
29
|
import { AUTO_LABEL, AUTO_ROUTE_SUFFIX, buildComment, linearState, transitionLabels, } from "./issues.js";
|
|
30
30
|
import { EXIT_EMPTY, commitBookkeeping, unionLedgers } from "./ledgers.js";
|
|
31
31
|
import { EXIT_REMOVE_FAILED, EXIT_SPLIT_BUCKET, acquireDevLock, acquireWorkflowLock, lockRoot, owns, readHolder, releaseLock, resolveMonth, workflowLockPath, } from "./locks.js";
|
|
@@ -807,7 +807,7 @@ export function highestVersion(dir, workflow) {
|
|
|
807
807
|
}
|
|
808
808
|
return best;
|
|
809
809
|
}
|
|
810
|
-
/** Stamp `file`'s anchor when a base commit is known (plan: with its design's own anchor). */
|
|
810
|
+
/** Stamp `file`'s anchor when a base commit is known (plan: with its design's own anchor; both: the bkit release). */
|
|
811
811
|
function stamp(cwd, file, baseSha, design) {
|
|
812
812
|
if (baseSha === "")
|
|
813
813
|
return;
|
|
@@ -817,7 +817,8 @@ function stamp(cwd, file, baseSha, design) {
|
|
|
817
817
|
? { path: design, baseSha: readAnchor(fs.readFileSync(designAbs, "utf-8")).baseSha ?? "" }
|
|
818
818
|
: undefined;
|
|
819
819
|
const tmp = `${abs}.bkit-anchor.tmp`;
|
|
820
|
-
|
|
820
|
+
const text = fs.readFileSync(abs, "utf-8");
|
|
821
|
+
fs.writeFileSync(tmp, stampAnchor(text, baseSha, d, undefined, anchorBkitStatus(cwd)));
|
|
821
822
|
fs.renameSync(tmp, abs);
|
|
822
823
|
}
|
|
823
824
|
function promoteVerb(ctx) {
|
package/dist/install/hosts.js
CHANGED
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The Antigravity plugin's bkit-written paths (install/modules/antigravity.ts). Any one
|
|
6
|
+
* present marks the host installed, so deleting a single file (the manifest included) still
|
|
7
|
+
* leaves the host detected and its missing files reported as drift.
|
|
8
|
+
*/
|
|
9
|
+
const ANTIGRAVITY_SENTINELS = ["plugin.json", "hooks.json", "agents", "skills", "hooks"].map((p) => path.join(".agents", "plugins", "bkit", p));
|
|
10
|
+
/**
|
|
11
|
+
* Detect which host modules a consumer has installed: each host's source-rendered agents
|
|
12
|
+
* directory, or for Antigravity any of its plugin files. `bkit upgrade` re-renders only these
|
|
13
|
+
* hosts — never force-creating an opencode/cursor tree — and setup tips key host-specific
|
|
14
|
+
* advice on them.
|
|
8
15
|
*/
|
|
9
16
|
export function detectInstalledHostModules(cwd) {
|
|
10
17
|
const mods = new Set();
|
|
@@ -16,7 +23,7 @@ export function detectInstalledHostModules(cwd) {
|
|
|
16
23
|
mods.add("opencode");
|
|
17
24
|
if (fs.existsSync(path.join(cwd, ".codex", "agents")))
|
|
18
25
|
mods.add("codex");
|
|
19
|
-
if (fs.existsSync(path.join(cwd,
|
|
26
|
+
if (ANTIGRAVITY_SENTINELS.some((rel) => fs.existsSync(path.join(cwd, rel))))
|
|
20
27
|
mods.add("antigravity");
|
|
21
28
|
return mods;
|
|
22
29
|
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// bkit-latest — is the bkit this repo rendered its workflows and audit templates
|
|
2
|
+
// from behind the newest published release?
|
|
3
|
+
//
|
|
4
|
+
// `bkit repo info` (every phase workflow's Step 1) and the anchor stamp on every
|
|
5
|
+
// audit report, design and plan report it, so a run on outdated workflow /
|
|
6
|
+
// template text says so. Advisory only: no registry answer means `latest`
|
|
7
|
+
// is null and nothing is printed, never an error. The registry answer is kept in
|
|
8
|
+
// the git common dir (shared by every worktree, never committed) so parallel runs
|
|
9
|
+
// ask npm at most once a day.
|
|
10
|
+
import { spawnSync } from "node:child_process";
|
|
11
|
+
import * as fs from "node:fs";
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import { readBkitVersion } from "../install/version-file.js";
|
|
14
|
+
import { parseJson } from "./json.js";
|
|
15
|
+
import { PACKAGE_RUNNER } from "./package-manager.js";
|
|
16
|
+
import { TIMEOUTS } from "./timeouts.js";
|
|
17
|
+
export const BKIT_PACKAGE = "@cbartens/bkit";
|
|
18
|
+
/** Cache file name inside the git common dir. */
|
|
19
|
+
export const BKIT_LATEST_CACHE = "bkit-latest-version.json";
|
|
20
|
+
/** Set to anything but `0` / empty to skip the registry lookup (air-gapped machines, CI). */
|
|
21
|
+
export const NO_UPDATE_CHECK_ENV = "BKIT_NO_UPDATE_CHECK";
|
|
22
|
+
const SEMVER_RE = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
23
|
+
/** Order of two prerelease identifier lists per semver §11: numeric < alphanumeric, shorter < longer. */
|
|
24
|
+
function comparePrerelease(a, b) {
|
|
25
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
26
|
+
const x = a[i];
|
|
27
|
+
const y = b[i];
|
|
28
|
+
if (x === undefined)
|
|
29
|
+
return -1;
|
|
30
|
+
if (y === undefined)
|
|
31
|
+
return 1;
|
|
32
|
+
const xn = /^\d+$/.test(x);
|
|
33
|
+
const yn = /^\d+$/.test(y);
|
|
34
|
+
if (xn && yn) {
|
|
35
|
+
if (Number(x) !== Number(y))
|
|
36
|
+
return Number(x) < Number(y) ? -1 : 1;
|
|
37
|
+
}
|
|
38
|
+
else if (xn !== yn) {
|
|
39
|
+
return xn ? -1 : 1;
|
|
40
|
+
}
|
|
41
|
+
else if (x !== y) {
|
|
42
|
+
return x < y ? -1 : 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* -1 / 0 / 1 for `a` older / equal / newer than `b`, compared as numbers (so 5.10.0
|
|
49
|
+
* is newer than 5.9.0) and with a prerelease older than its release. null when
|
|
50
|
+
* either is not a semver.
|
|
51
|
+
*/
|
|
52
|
+
export function compareSemver(a, b) {
|
|
53
|
+
const ma = SEMVER_RE.exec(a.trim());
|
|
54
|
+
const mb = SEMVER_RE.exec(b.trim());
|
|
55
|
+
if (!ma || !mb)
|
|
56
|
+
return null;
|
|
57
|
+
for (let i = 1; i <= 3; i++) {
|
|
58
|
+
const x = Number(ma[i]);
|
|
59
|
+
const y = Number(mb[i]);
|
|
60
|
+
if (x !== y)
|
|
61
|
+
return x < y ? -1 : 1;
|
|
62
|
+
}
|
|
63
|
+
const pa = ma[4];
|
|
64
|
+
const pb = mb[4];
|
|
65
|
+
if (pa === undefined && pb === undefined)
|
|
66
|
+
return 0;
|
|
67
|
+
if (pa === undefined)
|
|
68
|
+
return 1;
|
|
69
|
+
if (pb === undefined)
|
|
70
|
+
return -1;
|
|
71
|
+
const c = comparePrerelease(pa.split("."), pb.split("."));
|
|
72
|
+
return c === 0 ? 0 : c < 0 ? -1 : 1;
|
|
73
|
+
}
|
|
74
|
+
/** The newest published bkit per the registry, or null on any failure (offline, timeout, no pnpm). */
|
|
75
|
+
export function lookupLatestPublished(cwd, timeoutS = TIMEOUTS.BKIT_LATEST_LOOKUP_TIMEOUT_S) {
|
|
76
|
+
const res = spawnSync(PACKAGE_RUNNER, ["view", BKIT_PACKAGE, "version"], {
|
|
77
|
+
cwd,
|
|
78
|
+
encoding: "utf-8",
|
|
79
|
+
...(timeoutS === null ? {} : { timeout: timeoutS * 1000 }),
|
|
80
|
+
});
|
|
81
|
+
if (res.error || res.status !== 0)
|
|
82
|
+
return null;
|
|
83
|
+
const version = (res.stdout ?? "").trim().replace(/^v/, "");
|
|
84
|
+
return SEMVER_RE.test(version) ? version : null;
|
|
85
|
+
}
|
|
86
|
+
/** The cached registry answer when still fresh: a version, or null for a remembered failure. */
|
|
87
|
+
function readCache(file, now) {
|
|
88
|
+
if (!fs.existsSync(file))
|
|
89
|
+
return undefined;
|
|
90
|
+
const parsed = parseJson(fs.readFileSync(file, "utf-8"));
|
|
91
|
+
if (!parsed.ok || typeof parsed.value !== "object" || parsed.value === null)
|
|
92
|
+
return undefined;
|
|
93
|
+
const { latest, checkedAt } = parsed.value;
|
|
94
|
+
if (typeof checkedAt !== "number")
|
|
95
|
+
return undefined;
|
|
96
|
+
const value = typeof latest === "string" && SEMVER_RE.test(latest) ? latest : null;
|
|
97
|
+
const ttl = value === null ? TIMEOUTS.BKIT_LATEST_RETRY_S : TIMEOUTS.BKIT_LATEST_CACHE_S;
|
|
98
|
+
return now - checkedAt < ttl * 1000 && now >= checkedAt ? { latest: value } : undefined;
|
|
99
|
+
}
|
|
100
|
+
/** Remember the registry answer; a cache that cannot be written only costs a lookup next run. */
|
|
101
|
+
function writeCache(file, latest, now) {
|
|
102
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
103
|
+
try {
|
|
104
|
+
fs.writeFileSync(tmp, `${JSON.stringify({ latest, checkedAt: now })}\n`);
|
|
105
|
+
fs.renameSync(tmp, file);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Read-only git dir: the next run asks the registry again, nothing else changes.
|
|
109
|
+
fs.rmSync(tmp, { force: true });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Whether this repo's bkit is behind the newest release. `gitCommonDir` holds the
|
|
114
|
+
* once-a-day cache; null (not a git repo) skips the cache, not the check.
|
|
115
|
+
*/
|
|
116
|
+
export function bkitVersionStatus(root, gitCommonDir, deps = {}) {
|
|
117
|
+
const version = readBkitVersion(path.join(root, ".bkit", "version"))?.pinnedVersion || null;
|
|
118
|
+
const unknown = { version, latest: null, outdated: null, advisory: null };
|
|
119
|
+
if (version === null)
|
|
120
|
+
return unknown;
|
|
121
|
+
const optOut = process.env[NO_UPDATE_CHECK_ENV];
|
|
122
|
+
if (optOut !== undefined && optOut !== "" && optOut !== "0")
|
|
123
|
+
return unknown;
|
|
124
|
+
const now = (deps.now ?? Date.now)();
|
|
125
|
+
const cacheFile = gitCommonDir === null ? null : path.join(gitCommonDir, BKIT_LATEST_CACHE);
|
|
126
|
+
let latest;
|
|
127
|
+
const cached = cacheFile === null ? undefined : readCache(cacheFile, now);
|
|
128
|
+
if (cached !== undefined) {
|
|
129
|
+
latest = cached.latest;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
latest = (deps.lookup ?? lookupLatestPublished)(root);
|
|
133
|
+
if (cacheFile !== null)
|
|
134
|
+
writeCache(cacheFile, latest, now);
|
|
135
|
+
}
|
|
136
|
+
if (latest === null)
|
|
137
|
+
return unknown;
|
|
138
|
+
const order = compareSemver(version, latest);
|
|
139
|
+
if (order === null)
|
|
140
|
+
return { version, latest, outdated: null, advisory: null };
|
|
141
|
+
const outdated = order < 0;
|
|
142
|
+
return {
|
|
143
|
+
version,
|
|
144
|
+
latest,
|
|
145
|
+
outdated,
|
|
146
|
+
advisory: outdated
|
|
147
|
+
? `running bkit ${version}; ${latest} is out. Upgrade: ${PACKAGE_RUNNER} bkit upgrade --latest`
|
|
148
|
+
: null,
|
|
149
|
+
};
|
|
150
|
+
}
|
package/dist/shared/timeouts.js
CHANGED
|
@@ -16,4 +16,10 @@ export const TIMEOUTS = {
|
|
|
16
16
|
SHIP_DEV_LOCK_STALE_S: 900,
|
|
17
17
|
/** Seconds to contend for `.dev.lock` before giving up. */
|
|
18
18
|
SHIP_DEV_LOCK_ACQUIRE_DEADLINE_S: 600,
|
|
19
|
+
/** Seconds a registry answer for the newest published bkit is reused before asking again. */
|
|
20
|
+
BKIT_LATEST_CACHE_S: 86400,
|
|
21
|
+
/** Seconds a failed registry lookup is remembered, so an offline run does not wait on every call. */
|
|
22
|
+
BKIT_LATEST_RETRY_S: 3600,
|
|
23
|
+
/** Seconds the registry lookup may take before it counts as failed. */
|
|
24
|
+
BKIT_LATEST_LOOKUP_TIMEOUT_S: 5,
|
|
19
25
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cbartens/bkit",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "From vibe coding to production code. A senior engineering team's process, ready-made: AI agents design, plan, build, review, fix and ship your features on Claude Code, Cursor, Codex, Google Antigravity and opencode.",
|
|
6
6
|
"keywords": [
|