@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.
Files changed (100) hide show
  1. package/.bkit/README.md +4 -2
  2. package/.bkit/core/.agents/context.md +2 -2
  3. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +7 -1
  4. package/.bkit/core/.bkit/README.md +3 -1
  5. package/.bkit/core/.bkit/comparison.md +114 -45
  6. package/.bkit/core/.bkit/install.md +6 -6
  7. package/.bkit/core/.bkit/jsonl.md +3 -3
  8. package/.bkit/core/.bkit/prompts.md +6 -5
  9. package/.bkit/core/.bkit/providers.md +5 -4
  10. package/.bkit/core/.bkit/templates.md +30 -11
  11. package/.bkit/core/.bkit/workflows.md +14 -7
  12. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +5 -1
  13. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -2
  14. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +13 -2
  15. package/.bkit/core/docs/templates/bkit-audit-adoption.md +13 -2
  16. package/.bkit/core/docs/templates/bkit-audit-agents.md +13 -2
  17. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +13 -2
  18. package/.bkit/core/docs/templates/bkit-audit-analytics.md +13 -2
  19. package/.bkit/core/docs/templates/bkit-audit-annotations.md +15 -4
  20. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +13 -2
  21. package/.bkit/core/docs/templates/bkit-audit-app-store.md +13 -2
  22. package/.bkit/core/docs/templates/bkit-audit-architecture.md +13 -2
  23. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +13 -2
  24. package/.bkit/core/docs/templates/bkit-audit-config.md +13 -2
  25. package/.bkit/core/docs/templates/bkit-audit-cost.md +14 -3
  26. package/.bkit/core/docs/templates/bkit-audit-coverage.md +13 -2
  27. package/.bkit/core/docs/templates/bkit-audit-database.md +13 -2
  28. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +13 -2
  29. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +13 -2
  30. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +13 -2
  31. package/.bkit/core/docs/templates/bkit-audit-documentation.md +13 -2
  32. package/.bkit/core/docs/templates/bkit-audit-duplication.md +13 -2
  33. package/.bkit/core/docs/templates/bkit-audit-failures.md +14 -3
  34. package/.bkit/core/docs/templates/bkit-audit-flakes.md +15 -4
  35. package/.bkit/core/docs/templates/bkit-audit-gates.md +13 -2
  36. package/.bkit/core/docs/templates/bkit-audit-issues.md +13 -2
  37. package/.bkit/core/docs/templates/bkit-audit-llm.md +13 -2
  38. package/.bkit/core/docs/templates/bkit-audit-logs.md +25 -13
  39. package/.bkit/core/docs/templates/bkit-audit-models.md +13 -2
  40. package/.bkit/core/docs/templates/bkit-audit-privacy.md +13 -2
  41. package/.bkit/core/docs/templates/bkit-audit-prompts.md +13 -2
  42. package/.bkit/core/docs/templates/bkit-audit-red-team.md +14 -3
  43. package/.bkit/core/docs/templates/bkit-audit-reliability.md +14 -3
  44. package/.bkit/core/docs/templates/bkit-audit-repo.md +14 -3
  45. package/.bkit/core/docs/templates/bkit-audit-security.md +15 -4
  46. package/.bkit/core/docs/templates/bkit-audit-slop.md +13 -2
  47. package/.bkit/core/docs/templates/bkit-audit-testing.md +14 -3
  48. package/.bkit/core/docs/templates/bkit-audit-usability.md +13 -2
  49. package/.bkit/core/docs/templates/bkit-plan.md +1 -1
  50. package/.bkit/core/engine/checks/tips/catalogue.ts +10 -0
  51. package/.bkit/core/engine/commands/install/check.ts +3 -11
  52. package/.bkit/core/engine/commands/install/doctor.ts +2 -3
  53. package/.bkit/core/engine/commands/install/uninstall.ts +60 -44
  54. package/.bkit/core/engine/commands/install/upgrade.ts +13 -11
  55. package/.bkit/core/engine/commands/workflow/branches.ts +72 -9
  56. package/.bkit/core/engine/commands/workflow/repo.ts +16 -2
  57. package/.bkit/core/engine/commands/workflow/workflows.ts +4 -3
  58. package/.bkit/core/engine/install/hosts.ts +14 -4
  59. package/.bkit/core/engine/ledgers/telemetry.ts +3 -4
  60. package/.bkit/core/engine/shared/bkit-latest.ts +164 -0
  61. package/.bkit/core/engine/shared/timeouts.ts +6 -0
  62. package/.bkit/core/hooks/guardrails-read.js +4 -9
  63. package/.bkit/core/hooks/guardrails-tiers.js +312 -28
  64. package/.bkit/core/prompts/bkit-audit-generate.md +21 -5
  65. package/.bkit/core/workflows/bkit-build.md +1 -1
  66. package/.bkit/core/workflows/bkit-debug.md +1 -1
  67. package/.bkit/core/workflows/bkit-design.md +1 -1
  68. package/.bkit/core/workflows/bkit-plan.md +1 -1
  69. package/.bkit/core/workflows/bkit-ship.md +1 -1
  70. package/.bkit/shared/.claude/settings.json +19 -0
  71. package/.bkit/shared/.opencode/opencode.json +21 -1
  72. package/.bkit/shared/docs/deployments.md +14 -0
  73. package/.bkit/templates/.github/workflows/bkit-ci.yml +9 -0
  74. package/.bkit/templates/.husky/pre-push +7 -0
  75. package/.bkit/templates/context/bkit-cloudrun.md +28 -19
  76. package/.bkit/templates/context/bkit-expo.md +30 -13
  77. package/.bkit/templates/context/bkit-inngest.md +54 -17
  78. package/.bkit/templates/context/bkit-resend.md +36 -8
  79. package/.bkit/templates/context/bkit-sentry.md +11 -4
  80. package/.bkit/templates/context/bkit-stripe.md +39 -22
  81. package/.bkit/templates/context/bkit-supabase.md +45 -20
  82. package/.bkit/templates/context/bkit-vercel.md +45 -16
  83. package/.bkit/templates/scripts/ci/accepted-advisories.json +7 -0
  84. package/.bkit/templates/scripts/ci/check-dependency-audit.mjs +200 -0
  85. package/.bkit/templates/scripts/ci/check-dependency-audit.test.mjs +127 -0
  86. package/.bkit/templates/scripts/cleanup/bkit-tmp-prune.mjs +115 -0
  87. package/CHANGELOG.md +56 -0
  88. package/README.md +76 -20
  89. package/dist/checks/tips/catalogue.js +9 -0
  90. package/dist/commands/install/check.js +3 -15
  91. package/dist/commands/install/doctor.js +2 -1
  92. package/dist/commands/install/uninstall.js +52 -45
  93. package/dist/commands/install/upgrade.js +13 -11
  94. package/dist/commands/workflow/branches.js +64 -10
  95. package/dist/commands/workflow/repo.js +14 -2
  96. package/dist/commands/workflow/workflows.js +4 -3
  97. package/dist/install/hosts.js +11 -4
  98. package/dist/shared/bkit-latest.js +150 -0
  99. package/dist/shared/timeouts.js +6 -0
  100. package/package.json +1 -1
@@ -29,6 +29,7 @@ import {
29
29
  type FlagValue,
30
30
  type RunContext,
31
31
  } from "../lib.js";
32
+ import { bkitVersionStatus, type BkitVersionStatus } from "../../shared/bkit-latest.js";
32
33
  import { TIMEOUTS } from "../../shared/timeouts.js";
33
34
  import { commitBookkeeping } from "./ledgers.js";
34
35
  import { acquireDevLock, lockRoot, releaseLock, resolveMonth, workflowLockPath } from "./locks.js";
@@ -354,7 +355,17 @@ export function resolveRebase(
354
355
 
355
356
  const ANCHOR_OPEN = "<!-- bkit:anchor";
356
357
  const ANCHOR_CLOSE = "-->";
357
- export const ANCHOR_FIELDS = ["baseSha", "baseRef", "designPath", "designBaseSha"] as const;
358
+ /** Ends the visible line a stamp writes under the block when the doc came from an outdated bkit. */
359
+ const OUTDATED_MARK = "<!-- bkit:outdated -->";
360
+ const OUTDATED_LINE = new RegExp(`^.*${OUTDATED_MARK}\n(?:\n)?`, "gm");
361
+ export const ANCHOR_FIELDS = [
362
+ "baseSha",
363
+ "baseRef",
364
+ "designPath",
365
+ "designBaseSha",
366
+ "bkitVersion",
367
+ "bkitLatest",
368
+ ] as const;
358
369
  export type AnchorField = (typeof ANCHOR_FIELDS)[number];
359
370
 
360
371
  /** Lines of `text` with whether each sits inside an anchor block (a `sed '/open/,/close/'` range). */
@@ -390,19 +401,49 @@ export function readAnchor(text: string): Partial<Record<AnchorField, string>> {
390
401
  return out;
391
402
  }
392
403
 
393
- /** `text` with a fresh anchor block on top and every prior one removed, so re-stamping is idempotent. */
404
+ /**
405
+ * The bkit release a doc is being generated from, for its anchor: undefined when
406
+ * this repo has no `.bkit/version` pin (nothing to record). Asks the registry for
407
+ * the newest release at most once a day; offline leaves `latest` null.
408
+ */
409
+ export function anchorBkitStatus(cwd: string): BkitVersionStatus | undefined {
410
+ const status = bkitVersionStatus(
411
+ git(cwd, ["rev-parse", "--show-toplevel"]) ?? cwd,
412
+ git(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]),
413
+ );
414
+ return status.version === null ? undefined : status;
415
+ }
416
+
417
+ /**
418
+ * `text` with a fresh anchor block on top and every prior one removed, so re-stamping
419
+ * is idempotent. With `bkit`, the block records the release the doc came from and the
420
+ * newest one (empty when unknown); an outdated release adds one visible warning line
421
+ * under the block, replaced or dropped by the next stamp like the block itself.
422
+ */
394
423
  export function stampAnchor(
395
424
  text: string,
396
425
  baseSha: string,
397
426
  design?: { path: string; baseSha: string },
427
+ baseRef: string = UPSTREAM,
428
+ bkit?: BkitVersionStatus,
398
429
  ): string {
399
- const header = [ANCHOR_OPEN, `baseSha: ${baseSha}`, `baseRef: ${UPSTREAM}`];
430
+ const header = [ANCHOR_OPEN, `baseSha: ${baseSha}`, `baseRef: ${baseRef}`];
400
431
  if (design) header.push(`designPath: ${design.path}`, `designBaseSha: ${design.baseSha}`);
432
+ if (bkit) header.push(`bkitVersion: ${bkit.version ?? ""}`, `bkitLatest: ${bkit.latest ?? ""}`);
401
433
  header.push(ANCHOR_CLOSE);
402
- const body = anchorLines(text)
434
+ let body = anchorLines(text)
403
435
  .filter((l) => !l.inBlock)
404
436
  .map((l) => (l.last ? l.line : `${l.line}\n`))
405
- .join("");
437
+ .join("")
438
+ .replace(OUTDATED_LINE, "");
439
+ if (bkit?.outdated === true) {
440
+ // Blank lines on both sides of the warning, as prettier writes them.
441
+ header.push(
442
+ "",
443
+ `> **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}`,
444
+ );
445
+ body = `\n${body.replace(/^\n+/, "")}`;
446
+ }
406
447
  return `${header.join("\n")}\n${body}`;
407
448
  }
408
449
 
@@ -1180,6 +1221,7 @@ function anchorStampVerb(ctx: RunContext): number {
1180
1221
  return EXIT_NO_FILE;
1181
1222
  }
1182
1223
  if (baseSha === "") throw new CommandError(EXIT.USAGE, "--base-sha must be non-empty");
1224
+ const baseRef = str(ctx.flags.baseRef) ?? UPSTREAM;
1183
1225
  const designFlag = str(ctx.flags.design);
1184
1226
  const designFile = designFlag === undefined ? undefined : path.resolve(ctx.cwd, designFlag);
1185
1227
  const design =
@@ -1189,8 +1231,10 @@ function anchorStampVerb(ctx: RunContext): number {
1189
1231
  baseSha: readAnchor(fs.readFileSync(designFile, "utf-8")).baseSha ?? "",
1190
1232
  }
1191
1233
  : undefined;
1234
+ const bkit = anchorBkitStatus(ctx.cwd);
1235
+ if (bkit?.advisory) ctx.log(bkit.advisory);
1192
1236
  const before = fs.readFileSync(file, "utf-8");
1193
- const after = stampAnchor(before, baseSha, design);
1237
+ const after = stampAnchor(before, baseSha, design, baseRef, bkit);
1194
1238
  // Temp file + rename: a crash mid-write never leaves a half-stamped doc.
1195
1239
  const tmp = `${file}.bkit-anchor.tmp`;
1196
1240
  fs.writeFileSync(tmp, after);
@@ -1198,8 +1242,13 @@ function anchorStampVerb(ctx: RunContext): number {
1198
1242
  ctx.emit({
1199
1243
  file: rel,
1200
1244
  baseSha,
1245
+ baseRef,
1201
1246
  designPath: design?.path ?? null,
1202
1247
  designBaseSha: design?.baseSha ?? null,
1248
+ bkitVersion: bkit?.version ?? null,
1249
+ bkitLatest: bkit?.latest ?? null,
1250
+ bkitOutdated: bkit?.outdated ?? null,
1251
+ bkitAdvisory: bkit?.advisory ?? null,
1203
1252
  changed: before !== after,
1204
1253
  });
1205
1254
  return EXIT.OK;
@@ -1218,7 +1267,7 @@ function anchorReadVerb(ctx: RunContext): number {
1218
1267
  ctx.emit({ ...fields, value: null, skip: reason, landed: null });
1219
1268
  return EXIT_ANCHOR_SKIP;
1220
1269
  };
1221
- const none = { baseSha: null, baseRef: null, designPath: null, designBaseSha: null };
1270
+ const none = Object.fromEntries(ANCHOR_FIELDS.map((f) => [f, null]));
1222
1271
  if (!fs.statSync(file, { throwIfNoEntry: false })?.isFile()) {
1223
1272
  if (against !== undefined) return skip("no-file", `no ${rel} — nothing to check`, none);
1224
1273
  ctx.log(`${rel} not found`);
@@ -1452,7 +1501,7 @@ export const branchesCommand: CommandSpec = {
1452
1501
  },
1453
1502
  "anchor-stamp": {
1454
1503
  summary:
1455
- "Put a <!-- bkit:anchor --> block recording the base commit on top of a design/plan doc (idempotent).",
1504
+ "Put a <!-- bkit:anchor --> block recording the base commit and bkit release on top of a design/plan doc or audit report (idempotent).",
1456
1505
  flags: [
1457
1506
  { name: "file", type: "string", required: true, help: "doc to stamp (must exist)" },
1458
1507
  {
@@ -1461,6 +1510,11 @@ export const branchesCommand: CommandSpec = {
1461
1510
  required: true,
1462
1511
  help: "base commit the doc was written against (non-empty)",
1463
1512
  },
1513
+ {
1514
+ name: "base-ref",
1515
+ type: "string",
1516
+ help: `ref baseSha was taken from (default ${UPSTREAM}; audit reports pass the audited branch)`,
1517
+ },
1464
1518
  {
1465
1519
  name: "design",
1466
1520
  type: "string",
@@ -1470,9 +1524,16 @@ export const branchesCommand: CommandSpec = {
1470
1524
  output: {
1471
1525
  file: "doc stamped",
1472
1526
  baseSha: "base commit stamped",
1527
+ baseRef: "ref stamped",
1473
1528
  designPath: "design path stamped (null when none)",
1474
1529
  designBaseSha:
1475
1530
  "the design doc's baseSha stamped (null when none; empty when it had no anchor)",
1531
+ bkitVersion:
1532
+ "the .bkit/version pin stamped (null when unpinned: no bkit fields are stamped then)",
1533
+ bkitLatest: "newest published bkit stamped (null when unknown: stamped empty)",
1534
+ bkitOutdated:
1535
+ "true when bkitVersion is older than bkitLatest: a visible warning line is stamped under the block (null when unknown)",
1536
+ bkitAdvisory: "one warning line when bkitOutdated, else null",
1476
1537
  changed: "false when the doc already carried exactly this block",
1477
1538
  },
1478
1539
  exitCodes: { [EXIT_NO_FILE]: "--file is missing or not a file" },
@@ -1482,7 +1543,7 @@ export const branchesCommand: CommandSpec = {
1482
1543
  summary:
1483
1544
  "Read a doc's anchor fields; with --against, decide whether anything landed since its baseSha.",
1484
1545
  flags: [
1485
- { name: "file", type: "string", required: true, help: "design/plan doc" },
1546
+ { name: "file", type: "string", required: true, help: "design/plan doc or audit report" },
1486
1547
  {
1487
1548
  name: "field",
1488
1549
  type: "string",
@@ -1499,6 +1560,8 @@ export const branchesCommand: CommandSpec = {
1499
1560
  baseRef: "anchor baseRef (null when absent)",
1500
1561
  designPath: "anchor designPath (null when absent)",
1501
1562
  designBaseSha: "anchor designBaseSha (null when absent)",
1563
+ bkitVersion: "anchor bkitVersion (null when absent)",
1564
+ bkitLatest: "anchor bkitLatest (null when absent)",
1502
1565
  value: "the --field value (null when absent or no --field)",
1503
1566
  skip: "with --against: no-file | no-anchor | unreachable | nothing-landed (null = run the check)",
1504
1567
  landed: "with --against: paths changed between baseSha and the ref",
@@ -4,14 +4,15 @@
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, and the bkit binary every later block
8
- // calls ride along so Step 1 is one call.
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
 
10
10
  import * as fs from "node:fs";
11
11
  import * as path from "node:path";
12
12
 
13
13
  import { parseRemoteUrlToSlug } from "../../ledgers/telemetry.js";
14
14
  import { EXIT, git, repoRoot, runGit, runTool, type CommandSpec } from "../lib.js";
15
+ import { bkitVersionStatus } from "../../shared/bkit-latest.js";
15
16
 
16
17
  /** Exit code: neither gh nor the origin remote named an owner/repo. */
17
18
  export const EXIT_NO_REPO = 3;
@@ -122,6 +123,13 @@ export const repoCommand: CommandSpec = {
122
123
  repoRoot: "the main checkout (the same from any worktree)",
123
124
  bkit: "the bkit binary the workflow blocks call: <repoRoot>/node_modules/.bin/bkit, else `bkit` on PATH",
124
125
  outboxRoot: "<git common dir>/bkit-outbox: per-run scratch files, never committed",
126
+ bkitVersion:
127
+ ".bkit/version pinnedVersion: the release this repo's bkit files came from (null when unpinned)",
128
+ bkitLatest:
129
+ "newest published @cbartens/bkit, asked at most once a day (null when offline, opted out via BKIT_NO_UPDATE_CHECK, or unpinned)",
130
+ bkitOutdated:
131
+ "true when bkitVersion is older than bkitLatest (null when either is unknown)",
132
+ bkitAdvisory: "one line to show the user when bkitOutdated, else null",
125
133
  },
126
134
  exitCodes: {
127
135
  [EXIT_NO_REPO]: "neither gh nor the origin remote named an owner/repo",
@@ -156,6 +164,8 @@ export const repoCommand: CommandSpec = {
156
164
  }
157
165
  const root = repoRoot(ctx.cwd);
158
166
  const common = git(ctx.cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
167
+ const latest = bkitVersionStatus(root, common);
168
+ if (latest.advisory !== null) ctx.log(latest.advisory);
159
169
  ctx.emit({
160
170
  ...resolved,
161
171
  owner,
@@ -165,6 +175,10 @@ export const repoCommand: CommandSpec = {
165
175
  repoRoot: root,
166
176
  bkit: resolveBkitBinary(root),
167
177
  outboxRoot: path.join(common ?? path.join(root, ".git"), "bkit-outbox"),
178
+ bkitVersion: latest.version,
179
+ bkitLatest: latest.latest,
180
+ bkitOutdated: latest.outdated,
181
+ bkitAdvisory: latest.advisory,
168
182
  });
169
183
  if (branch === null && ctx.flags.allowDetached !== true) {
170
184
  ctx.log("HEAD is detached — no current branch");
@@ -55,7 +55,7 @@ import {
55
55
  type FlagValue,
56
56
  type RunContext,
57
57
  } from "../lib.js";
58
- import { pushBranch, readAnchor, stampAnchor } from "./branches.js";
58
+ import { anchorBkitStatus, pushBranch, readAnchor, stampAnchor } from "./branches.js";
59
59
  import {
60
60
  AUTO_LABEL,
61
61
  AUTO_ROUTE_SUFFIX,
@@ -998,7 +998,7 @@ export function highestVersion(dir: string, workflow: string): { file: string; n
998
998
  return best;
999
999
  }
1000
1000
 
1001
- /** Stamp `file`'s anchor when a base commit is known (plan: with its design's own anchor). */
1001
+ /** Stamp `file`'s anchor when a base commit is known (plan: with its design's own anchor; both: the bkit release). */
1002
1002
  function stamp(cwd: string, file: string, baseSha: string, design?: string): void {
1003
1003
  if (baseSha === "") return;
1004
1004
  const abs = path.resolve(cwd, file);
@@ -1008,7 +1008,8 @@ function stamp(cwd: string, file: string, baseSha: string, design?: string): voi
1008
1008
  ? { path: design, baseSha: readAnchor(fs.readFileSync(designAbs, "utf-8")).baseSha ?? "" }
1009
1009
  : undefined;
1010
1010
  const tmp = `${abs}.bkit-anchor.tmp`;
1011
- fs.writeFileSync(tmp, stampAnchor(fs.readFileSync(abs, "utf-8"), baseSha, d));
1011
+ const text = fs.readFileSync(abs, "utf-8");
1012
+ fs.writeFileSync(tmp, stampAnchor(text, baseSha, d, undefined, anchorBkitStatus(cwd)));
1012
1013
  fs.renameSync(tmp, abs);
1013
1014
  }
1014
1015
 
@@ -5,9 +5,19 @@ import * as path from "node:path";
5
5
  import type { ModuleFlag } from "../cli.js";
6
6
 
7
7
  /**
8
- * Detect which host modules a consumer has installed, by the presence of each host's
9
- * source-rendered agents directory. `bkit upgrade` re-renders only these hosts — never
10
- * force-creating an opencode/cursor tree — and setup tips key host-specific advice on them.
8
+ * The Antigravity plugin's bkit-written paths (install/modules/antigravity.ts). Any one
9
+ * present marks the host installed, so deleting a single file (the manifest included) still
10
+ * leaves the host detected and its missing files reported as drift.
11
+ */
12
+ const ANTIGRAVITY_SENTINELS = ["plugin.json", "hooks.json", "agents", "skills", "hooks"].map((p) =>
13
+ path.join(".agents", "plugins", "bkit", p),
14
+ );
15
+
16
+ /**
17
+ * Detect which host modules a consumer has installed: each host's source-rendered agents
18
+ * directory, or for Antigravity any of its plugin files. `bkit upgrade` re-renders only these
19
+ * hosts — never force-creating an opencode/cursor tree — and setup tips key host-specific
20
+ * advice on them.
11
21
  */
12
22
  export function detectInstalledHostModules(cwd: string): Set<ModuleFlag> {
13
23
  const mods = new Set<ModuleFlag>();
@@ -15,7 +25,7 @@ export function detectInstalledHostModules(cwd: string): Set<ModuleFlag> {
15
25
  if (fs.existsSync(path.join(cwd, ".cursor", "agents"))) mods.add("cursor");
16
26
  if (fs.existsSync(path.join(cwd, ".opencode", "agents"))) mods.add("opencode");
17
27
  if (fs.existsSync(path.join(cwd, ".codex", "agents"))) mods.add("codex");
18
- if (fs.existsSync(path.join(cwd, ".agents", "plugins", "bkit", "plugin.json")))
28
+ if (ANTIGRAVITY_SENTINELS.some((rel) => fs.existsSync(path.join(cwd, rel))))
19
29
  mods.add("antigravity");
20
30
  return mods;
21
31
  }
@@ -118,7 +118,7 @@ export interface TelemetryEnvelope {
118
118
  repo: string;
119
119
  /** bkit version stamped on every row for regression attribution. */
120
120
  bkitVersion: string;
121
- /** Emitting workflow: design | plan | build | debug | ship */
121
+ /** Emitting workflow: design | plan | build | debug | ship | audit */
122
122
  workflow: string;
123
123
  /**
124
124
  * The WORKFLOW STEP the row was emitted at, e.g. `build-close-workflow`,
@@ -218,9 +218,8 @@ export const SEVERITY_KINDS: Set<string> = new Set(["friction", "deferral", "fai
218
218
  * `OPEN` raised, cause unknown -> `TRIAGED` analysed, disposition known, not yet
219
219
  * fixed -> `CLOSED` dealt with (fixed, refuted, or established as not ours).
220
220
  *
221
- * `TRIAGED` IS STILL OPEN WORK. Readers counting open entries — a CI gate on open
222
- * CRITICAL failures, an audit debt lens, an age report — MUST count it. Only
223
- * `CLOSED` is done.
221
+ * `TRIAGED` IS STILL OPEN WORK. Readers counting open entries — an audit debt
222
+ * lens, an age report — MUST count it. Only `CLOSED` is done.
224
223
  *
225
224
  * NOT on knowledge or decision. Both use the `ACTIVE` / `SUPERSEDED`
226
225
  * lifecycle, a different axis entirely. Absent `status` = `ACTIVE`.
@@ -0,0 +1,164 @@
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
+
11
+ import { spawnSync } from "node:child_process";
12
+ import * as fs from "node:fs";
13
+ import * as path from "node:path";
14
+
15
+ import { readBkitVersion } from "../install/version-file.js";
16
+ import { parseJson } from "./json.js";
17
+ import { PACKAGE_RUNNER } from "./package-manager.js";
18
+ import { TIMEOUTS } from "./timeouts.js";
19
+
20
+ export const BKIT_PACKAGE = "@cbartens/bkit";
21
+ /** Cache file name inside the git common dir. */
22
+ export const BKIT_LATEST_CACHE = "bkit-latest-version.json";
23
+ /** Set to anything but `0` / empty to skip the registry lookup (air-gapped machines, CI). */
24
+ export const NO_UPDATE_CHECK_ENV = "BKIT_NO_UPDATE_CHECK";
25
+
26
+ const SEMVER_RE = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
27
+
28
+ /** Order of two prerelease identifier lists per semver §11: numeric < alphanumeric, shorter < longer. */
29
+ function comparePrerelease(a: string[], b: string[]): number {
30
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
31
+ const x = a[i];
32
+ const y = b[i];
33
+ if (x === undefined) return -1;
34
+ if (y === undefined) return 1;
35
+ const xn = /^\d+$/.test(x);
36
+ const yn = /^\d+$/.test(y);
37
+ if (xn && yn) {
38
+ if (Number(x) !== Number(y)) return Number(x) < Number(y) ? -1 : 1;
39
+ } else if (xn !== yn) {
40
+ return xn ? -1 : 1;
41
+ } else if (x !== y) {
42
+ return x < y ? -1 : 1;
43
+ }
44
+ }
45
+ return 0;
46
+ }
47
+
48
+ /**
49
+ * -1 / 0 / 1 for `a` older / equal / newer than `b`, compared as numbers (so 5.10.0
50
+ * is newer than 5.9.0) and with a prerelease older than its release. null when
51
+ * either is not a semver.
52
+ */
53
+ export function compareSemver(a: string, b: string): -1 | 0 | 1 | null {
54
+ const ma = SEMVER_RE.exec(a.trim());
55
+ const mb = SEMVER_RE.exec(b.trim());
56
+ if (!ma || !mb) 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) return x < y ? -1 : 1;
61
+ }
62
+ const pa = ma[4];
63
+ const pb = mb[4];
64
+ if (pa === undefined && pb === undefined) return 0;
65
+ if (pa === undefined) return 1;
66
+ if (pb === undefined) return -1;
67
+ const c = comparePrerelease(pa.split("."), pb.split("."));
68
+ return c === 0 ? 0 : c < 0 ? -1 : 1;
69
+ }
70
+
71
+ /** The newest published bkit per the registry, or null on any failure (offline, timeout, no pnpm). */
72
+ export function lookupLatestPublished(
73
+ cwd: string,
74
+ timeoutS: number | null = TIMEOUTS.BKIT_LATEST_LOOKUP_TIMEOUT_S,
75
+ ): string | null {
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) return null;
82
+ const version = (res.stdout ?? "").trim().replace(/^v/, "");
83
+ return SEMVER_RE.test(version) ? version : null;
84
+ }
85
+
86
+ export interface BkitVersionStatus {
87
+ /** `.bkit/version` `pinnedVersion`: the release this repo's bkit files were rendered from. */
88
+ version: string | null;
89
+ /** Newest published release, or null when unknown (offline, opted out, no pin to compare). */
90
+ latest: string | null;
91
+ /** true when `version` is older than `latest`; null when either is unknown. */
92
+ outdated: boolean | null;
93
+ /** One line to show the user when outdated, else null. */
94
+ advisory: string | null;
95
+ }
96
+
97
+ export interface BkitLatestDeps {
98
+ now?: () => number;
99
+ lookup?: (cwd: string) => string | null;
100
+ }
101
+
102
+ /** The cached registry answer when still fresh: a version, or null for a remembered failure. */
103
+ function readCache(file: string, now: number): { latest: string | null } | undefined {
104
+ if (!fs.existsSync(file)) return undefined;
105
+ const parsed = parseJson(fs.readFileSync(file, "utf-8"));
106
+ if (!parsed.ok || typeof parsed.value !== "object" || parsed.value === null) return undefined;
107
+ const { latest, checkedAt } = parsed.value as { latest?: unknown; checkedAt?: unknown };
108
+ if (typeof checkedAt !== "number") return undefined;
109
+ const value = typeof latest === "string" && SEMVER_RE.test(latest) ? latest : null;
110
+ const ttl = value === null ? TIMEOUTS.BKIT_LATEST_RETRY_S : TIMEOUTS.BKIT_LATEST_CACHE_S;
111
+ return now - checkedAt < ttl * 1000 && now >= checkedAt ? { latest: value } : undefined;
112
+ }
113
+
114
+ /** Remember the registry answer; a cache that cannot be written only costs a lookup next run. */
115
+ function writeCache(file: string, latest: string | null, now: number): void {
116
+ const tmp = `${file}.${process.pid}.tmp`;
117
+ try {
118
+ fs.writeFileSync(tmp, `${JSON.stringify({ latest, checkedAt: now })}\n`);
119
+ fs.renameSync(tmp, file);
120
+ } catch {
121
+ // Read-only git dir: the next run asks the registry again, nothing else changes.
122
+ fs.rmSync(tmp, { force: true });
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Whether this repo's bkit is behind the newest release. `gitCommonDir` holds the
128
+ * once-a-day cache; null (not a git repo) skips the cache, not the check.
129
+ */
130
+ export function bkitVersionStatus(
131
+ root: string,
132
+ gitCommonDir: string | null,
133
+ deps: BkitLatestDeps = {},
134
+ ): BkitVersionStatus {
135
+ const version = readBkitVersion(path.join(root, ".bkit", "version"))?.pinnedVersion || null;
136
+ const unknown = { version, latest: null, outdated: null, advisory: null };
137
+ if (version === null) return unknown;
138
+ const optOut = process.env[NO_UPDATE_CHECK_ENV];
139
+ if (optOut !== undefined && optOut !== "" && optOut !== "0") return unknown;
140
+
141
+ const now = (deps.now ?? Date.now)();
142
+ const cacheFile = gitCommonDir === null ? null : path.join(gitCommonDir, BKIT_LATEST_CACHE);
143
+ let latest: string | null;
144
+ const cached = cacheFile === null ? undefined : readCache(cacheFile, now);
145
+ if (cached !== undefined) {
146
+ latest = cached.latest;
147
+ } else {
148
+ latest = (deps.lookup ?? lookupLatestPublished)(root);
149
+ if (cacheFile !== null) writeCache(cacheFile, latest, now);
150
+ }
151
+ if (latest === null) return unknown;
152
+
153
+ const order = compareSemver(version, latest);
154
+ if (order === null) return { version, latest, outdated: null, advisory: null };
155
+ const outdated = order < 0;
156
+ return {
157
+ version,
158
+ latest,
159
+ outdated,
160
+ advisory: outdated
161
+ ? `running bkit ${version}; ${latest} is out. Upgrade: ${PACKAGE_RUNNER} bkit upgrade --latest`
162
+ : null,
163
+ };
164
+ }
@@ -17,4 +17,10 @@ export const TIMEOUTS = {
17
17
  SHIP_DEV_LOCK_STALE_S: 900,
18
18
  /** Seconds to contend for `.dev.lock` before giving up. */
19
19
  SHIP_DEV_LOCK_ACQUIRE_DEADLINE_S: 600,
20
+ /** Seconds a registry answer for the newest published bkit is reused before asking again. */
21
+ BKIT_LATEST_CACHE_S: 86400,
22
+ /** Seconds a failed registry lookup is remembered, so an offline run does not wait on every call. */
23
+ BKIT_LATEST_RETRY_S: 3600,
24
+ /** Seconds the registry lookup may take before it counts as failed. */
25
+ BKIT_LATEST_LOOKUP_TIMEOUT_S: 5,
20
26
  } as const;
@@ -1,7 +1,7 @@
1
1
  // --- Secret-file read tier: identical in the Cursor and Google Antigravity guardrails hooks
2
2
  // (bkit renders it from one source). Same policy as Claude's settings.json `Read(...)` deny /
3
3
  // ask rows and opencode's `permission.read` map; each host maps a tier to its own output
4
- // shape and wording.
4
+ // shape and wording. Needs `secretFileKind` from `guardrails-tiers.js` above it.
5
5
 
6
6
  /**
7
7
  * The read tier for a file path (`/` or `\` separated), first match wins:
@@ -11,13 +11,8 @@
11
11
  */
12
12
  function classifyRead(filePath) {
13
13
  const p = String(filePath || "").replace(/\\/g, "/");
14
- if (!p) return null;
15
- if (/\.pem$/i.test(p) || /\.p12$/i.test(p) || /(^|\/)id_rsa$/i.test(p)) {
16
- return { tier: "deny", path: p };
17
- }
18
- const base = p.split("/").pop() || p;
19
- if (base === ".env" || (/^\.env\./.test(base) && base !== ".env.example")) {
20
- return { tier: "ask", path: p };
21
- }
14
+ const kind = secretFileKind(p);
15
+ if (kind === "key") return { tier: "deny", path: p };
16
+ if (kind === "env") return { tier: "ask", path: p };
22
17
  return null;
23
18
  }