@cbartens/bkit 5.2.2 → 5.2.3

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 (82) hide show
  1. package/.bkit/README.md +1 -1
  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/comparison.md +114 -45
  5. package/.bkit/core/.bkit/install.md +3 -3
  6. package/.bkit/core/.bkit/jsonl.md +3 -3
  7. package/.bkit/core/.bkit/prompts.md +6 -5
  8. package/.bkit/core/.bkit/providers.md +5 -4
  9. package/.bkit/core/.bkit/templates.md +11 -10
  10. package/.bkit/core/.bkit/workflows.md +7 -5
  11. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +5 -1
  12. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -2
  13. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +5 -2
  14. package/.bkit/core/docs/templates/bkit-audit-adoption.md +5 -2
  15. package/.bkit/core/docs/templates/bkit-audit-agents.md +5 -2
  16. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +5 -2
  17. package/.bkit/core/docs/templates/bkit-audit-analytics.md +5 -2
  18. package/.bkit/core/docs/templates/bkit-audit-annotations.md +6 -3
  19. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +5 -2
  20. package/.bkit/core/docs/templates/bkit-audit-app-store.md +5 -2
  21. package/.bkit/core/docs/templates/bkit-audit-architecture.md +5 -2
  22. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +5 -2
  23. package/.bkit/core/docs/templates/bkit-audit-config.md +5 -2
  24. package/.bkit/core/docs/templates/bkit-audit-cost.md +5 -2
  25. package/.bkit/core/docs/templates/bkit-audit-coverage.md +5 -2
  26. package/.bkit/core/docs/templates/bkit-audit-database.md +5 -2
  27. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +5 -2
  28. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +5 -2
  29. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +5 -2
  30. package/.bkit/core/docs/templates/bkit-audit-documentation.md +5 -2
  31. package/.bkit/core/docs/templates/bkit-audit-duplication.md +5 -2
  32. package/.bkit/core/docs/templates/bkit-audit-failures.md +6 -3
  33. package/.bkit/core/docs/templates/bkit-audit-flakes.md +6 -3
  34. package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -2
  35. package/.bkit/core/docs/templates/bkit-audit-issues.md +5 -2
  36. package/.bkit/core/docs/templates/bkit-audit-llm.md +5 -2
  37. package/.bkit/core/docs/templates/bkit-audit-logs.md +16 -12
  38. package/.bkit/core/docs/templates/bkit-audit-models.md +5 -2
  39. package/.bkit/core/docs/templates/bkit-audit-privacy.md +5 -2
  40. package/.bkit/core/docs/templates/bkit-audit-prompts.md +5 -2
  41. package/.bkit/core/docs/templates/bkit-audit-red-team.md +5 -2
  42. package/.bkit/core/docs/templates/bkit-audit-reliability.md +6 -3
  43. package/.bkit/core/docs/templates/bkit-audit-repo.md +5 -2
  44. package/.bkit/core/docs/templates/bkit-audit-security.md +6 -3
  45. package/.bkit/core/docs/templates/bkit-audit-slop.md +5 -2
  46. package/.bkit/core/docs/templates/bkit-audit-testing.md +5 -2
  47. package/.bkit/core/docs/templates/bkit-audit-usability.md +5 -2
  48. package/.bkit/core/docs/templates/bkit-plan.md +1 -1
  49. package/.bkit/core/engine/commands/install/check.ts +3 -11
  50. package/.bkit/core/engine/commands/install/doctor.ts +2 -3
  51. package/.bkit/core/engine/commands/install/uninstall.ts +60 -44
  52. package/.bkit/core/engine/commands/install/upgrade.ts +4 -1
  53. package/.bkit/core/engine/commands/workflow/branches.ts +13 -4
  54. package/.bkit/core/engine/install/hosts.ts +14 -4
  55. package/.bkit/core/engine/ledgers/telemetry.ts +3 -4
  56. package/.bkit/core/hooks/guardrails-read.js +4 -9
  57. package/.bkit/core/hooks/guardrails-tiers.js +312 -28
  58. package/.bkit/core/prompts/bkit-audit-generate.md +19 -5
  59. package/.bkit/shared/.claude/settings.json +19 -0
  60. package/.bkit/shared/.opencode/opencode.json +21 -1
  61. package/.bkit/shared/docs/deployments.md +14 -0
  62. package/.bkit/templates/.github/workflows/bkit-ci.yml +9 -0
  63. package/.bkit/templates/context/bkit-cloudrun.md +28 -19
  64. package/.bkit/templates/context/bkit-expo.md +30 -13
  65. package/.bkit/templates/context/bkit-inngest.md +54 -17
  66. package/.bkit/templates/context/bkit-resend.md +36 -8
  67. package/.bkit/templates/context/bkit-sentry.md +11 -4
  68. package/.bkit/templates/context/bkit-stripe.md +39 -22
  69. package/.bkit/templates/context/bkit-supabase.md +45 -20
  70. package/.bkit/templates/context/bkit-vercel.md +45 -16
  71. package/.bkit/templates/scripts/ci/accepted-advisories.json +7 -0
  72. package/.bkit/templates/scripts/ci/check-dependency-audit.mjs +200 -0
  73. package/.bkit/templates/scripts/ci/check-dependency-audit.test.mjs +127 -0
  74. package/CHANGELOG.md +39 -0
  75. package/README.md +76 -20
  76. package/dist/commands/install/check.js +3 -15
  77. package/dist/commands/install/doctor.js +2 -1
  78. package/dist/commands/install/uninstall.js +52 -45
  79. package/dist/commands/install/upgrade.js +4 -1
  80. package/dist/commands/workflow/branches.js +13 -5
  81. package/dist/install/hosts.js +11 -4
  82. package/package.json +1 -1
@@ -6,9 +6,9 @@
6
6
  Fits: apps deployed on Vercel. `context=runtime`: error and fatal lines from serverless and edge functions in a time window (default last 4 h, preview environment), PII-safe projection with `traceId` to stitch to the `sentry` block.
7
7
 
8
8
  - Secret: `VERCEL_TOKEN` (local env; cloud dashboard). No `vercel login` — headless agents cannot run it.
9
- - Non-secret: `VERCEL_SCOPE` (team slug) — uncomment the line in the block so cloud agents inherit it. `VERCEL_ENV` (`preview` default, `production`), `SINCE` / `UNTIL` (ISO-8601 or relative), `VERCEL_N`.
9
+ - Non-secret: `VERCEL_SCOPE` (team slug) — uncomment the line in the block so cloud agents inherit it. `VERCEL_ENV` (`preview` default, `production`), `SINCE` / `UNTIL` (ISO-8601 or relative), `VERCEL_MAX_PAGES` (pages of 50 lines, default 20).
10
10
  - CLI: `vercel`; the provision block installs it in cloud.
11
- - `--limit` returns the NEWEST N lines inside the window, so a wide window on a busy deployment reads like a tail: narrow the window or raise `VERCEL_N`. For counts over a wide window, the Vercel MCP `get_runtime_logs` with `group_by` beats lines.
11
+ - Each call returns at most 50 lines, the newest inside the window, whatever `--limit` says; the block pages backwards with `--until` up to `VERCEL_MAX_PAGES`. `--no-branch` is required: without it CLI 50.x reads only the checked-out git branch. `--level error` also returns `info` lines, so jq filters `.level`. For counts over a wide window, the Vercel MCP `get_runtime_logs` with `group_by` beats lines.
12
12
 
13
13
  Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
14
14
 
@@ -21,22 +21,51 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
21
21
  # VERCEL_SCOPE is non-secret — uncomment + set the line below so local AND cloud
22
22
  # agents inherit it (headless cloud agents never read .bkit/.env):
23
23
  # VERCEL_SCOPE="your-team-slug"
24
- # SINCE / UNTIL take ISO-8601 (2026-01-31T22:50:00Z) or relative (4h). --limit keeps the NEWEST
25
- # N lines inside the window: narrow the window or raise VERCEL_N before widening --level.
26
- # Customise: VERCEL_ENV; SINCE / UNTIL; VERCEL_N; --level / --source; path or status filter; jq keys to the log shape.
24
+ # --no-branch: CLI 50.x otherwise filters to the checked-out git branch; any other branch reads 0
25
+ # lines. Each call returns at most 50 lines, the NEWEST in the window, whatever --limit says → loop
26
+ # pages backwards with --until until a page comes back short. --level error lets `info` through →
27
+ # jq keeps error / fatal only. SINCE / UNTIL: ISO-8601 (2026-01-31T22:50:00Z) or relative (4h).
28
+ # Failed first call → `skipped`; failed later page or page cap → TRUNCATED line naming the unread part.
29
+ # Customise: VERCEL_ENV; SINCE / UNTIL; VERCEL_MAX_PAGES (x 50 lines); --source; path or status filter; jq keys to the log shape. Positive control (suggested): run once over a window holding a known error (e.g. a 5xx seen in the dashboard); nothing back = reader broken, not clean.
27
30
  command -v vercel >/dev/null && [ -n "${VERCEL_TOKEN:-}" ] && [ -n "${VERCEL_SCOPE:-}" ] \
28
31
  || { echo "[context-fetch:vercel] skipped — vercel CLI / VERCEL_TOKEN / VERCEL_SCOPE missing" >&2; exit 0; }
29
- vercel logs \
30
- --token "$VERCEL_TOKEN" \
31
- --scope "$VERCEL_SCOPE" \
32
- --environment "${VERCEL_ENV:-preview}" \
33
- --level error --level fatal \
34
- --source serverless --source edge-function \
35
- --since "${SINCE:-4h}" \
36
- ${UNTIL:+--until "$UNTIL"} \
37
- --limit "${VERCEL_N:-100}" \
38
- --json \
39
- | jq -c '{timestamp, level, source, requestPath, responseStatusCode, traceId, message}' # PII-safe projection; traceId stitches to the sentry block, message is free-text — adjust keys to your log shape
32
+ VERCEL_PAGE=50
33
+ VERCEL_ALL=$(mktemp); VERCEL_CHUNK=$(mktemp)
34
+ trap 'rm -f "$VERCEL_ALL" "$VERCEL_CHUNK"' EXIT
35
+ VERCEL_UNTIL="${UNTIL:-}"; VERCEL_PAGES=0; VERCEL_NOTE=""
36
+ while [ "$VERCEL_PAGES" -lt "${VERCEL_MAX_PAGES:-20}" ]; do
37
+ VERCEL_PAGES=$((VERCEL_PAGES + 1))
38
+ if ! vercel logs \
39
+ --token "$VERCEL_TOKEN" \
40
+ --scope "$VERCEL_SCOPE" \
41
+ --no-branch \
42
+ --environment "${VERCEL_ENV:-preview}" \
43
+ --level error --level fatal \
44
+ --source serverless --source edge-function \
45
+ --since "${SINCE:-4h}" \
46
+ ${VERCEL_UNTIL:+--until "$VERCEL_UNTIL"} \
47
+ --limit "$VERCEL_PAGE" \
48
+ --json > "$VERCEL_CHUNK" 2>/dev/null; then
49
+ [ "$VERCEL_PAGES" -gt 1 ] \
50
+ || { echo "[context-fetch:vercel] skipped — vercel logs exited non-zero (bad token, scope or project, or host unreachable)" >&2; exit 0; }
51
+ VERCEL_NOTE="page $VERCEL_PAGES failed — lines older than $VERCEL_UNTIL NOT read"; break
52
+ fi
53
+ cat "$VERCEL_CHUNK" >> "$VERCEL_ALL"
54
+ [ "$(grep -c . "$VERCEL_CHUNK")" -ge "$VERCEL_PAGE" ] || break
55
+ # Next page ends 1 s after this page's oldest line (overlap, de-duplicated by id below).
56
+ VERCEL_NEXT=$(jq -rs 'map(.timestamp) | min / 1000 | floor + 1 | todate' "$VERCEL_CHUNK")
57
+ [ "$VERCEL_NEXT" != "$VERCEL_UNTIL" ] \
58
+ || { VERCEL_NOTE="over $VERCEL_PAGE lines inside one second at $VERCEL_NEXT — narrow --source or the window"; break; }
59
+ VERCEL_UNTIL="$VERCEL_NEXT"
60
+ [ "$VERCEL_PAGES" -lt "${VERCEL_MAX_PAGES:-20}" ] \
61
+ || VERCEL_NOTE="stopped at VERCEL_MAX_PAGES=${VERCEL_MAX_PAGES:-20} — lines older than $VERCEL_UNTIL NOT read"
62
+ done
63
+ VERCEL_LINES=$(jq -c 'select(.level == "error" or .level == "fatal")' "$VERCEL_ALL" | jq -sc 'unique_by(.id) | sort_by(-.timestamp) | .[]')
64
+ printf '===== vercel %s error/fatal lines, since %s%s — %s lines, %s page(s) =====\n' \
65
+ "${VERCEL_ENV:-preview}" "${SINCE:-4h}" "${UNTIL:+ until $UNTIL}" "$(printf '%s' "$VERCEL_LINES" | grep -c .)" "$VERCEL_PAGES"
66
+ [ -z "$VERCEL_NOTE" ] || { printf '===== TRUNCATED: %s =====\n' "$VERCEL_NOTE"; echo "[context-fetch:vercel] truncated — $VERCEL_NOTE" >&2; }
67
+ printf '%s\n' "$VERCEL_LINES" | grep . \
68
+ | jq -c '{time: (.timestamp / 1000 | floor | todate), level, source, requestPath, responseStatusCode, traceId, message}' # PII-safe projection; traceId stitches to the sentry block, message is free-text — adjust keys to your log shape
40
69
  ```
41
70
 
42
71
  <!-- context-fetch:end -->
@@ -0,0 +1,7 @@
1
+ {
2
+ "blocking": {
3
+ "critical": 7,
4
+ "high": 30
5
+ },
6
+ "accepted": []
7
+ }
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env node
2
+ // Example. Copy into scripts/ci/ and own it. bkit install does not write this file
3
+ // and does not overwrite a copy.
4
+ /**
5
+ * check-dependency-audit.mjs — the dependency-audit gate.
6
+ *
7
+ * Runs `pnpm audit --json` and reds when a blocking advisory (by default high or critical)
8
+ * reaches the lockfile without an acceptance in the registry. An acceptance is a row naming
9
+ * the advisory, a reason and an expiry date. The guard reds when:
10
+ * - a blocking advisory has no acceptance (a new advisory),
11
+ * - an acceptance has expired, or runs longer than its severity allows (`blocking` days),
12
+ * - an acceptance names an advisory the audit no longer reports (a stale row),
13
+ * - a row carries no advisory, no reason, or no `YYYY-MM-DD` expiry, or repeats one,
14
+ * - the audit cannot run or prints no report (fails closed; never green on no answer).
15
+ *
16
+ * pnpm's own `auditConfig.ignoreGhsas` ignores an advisory forever and records no reason;
17
+ * the registry makes every exception say why and come back for review.
18
+ *
19
+ * Reads pnpm's report shape (`advisories`: id → { github_advisory_id, severity, module_name,
20
+ * patched_versions, findings }). Another package manager → adapt `blockingFindings()`.
21
+ *
22
+ * Usage: node scripts/ci/check-dependency-audit.mjs [--registry=<file>] [--report=<file>]
23
+ * --report reads a saved `pnpm audit --json` instead of running the audit.
24
+ * Exit: 0 = every blocking advisory accepted and every row live, 1 = drift or no report.
25
+ */
26
+
27
+ import { spawnSync } from "node:child_process";
28
+ import fs from "node:fs";
29
+ import path from "node:path";
30
+ import { fileURLToPath } from "node:url";
31
+ import { parseArgs } from "node:util";
32
+
33
+ /** Severity → the most days an acceptance may run. Severities not listed never block. */
34
+ export const DEFAULT_BLOCKING = { critical: 7, high: 30 };
35
+
36
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
37
+ const DAY_MS = 24 * 60 * 60 * 1000;
38
+
39
+ /** `YYYY-MM-DD` of a Date, in UTC. */
40
+ export function isoDay(date) {
41
+ return date.toISOString().slice(0, 10);
42
+ }
43
+
44
+ /** Whole days from `from` to `to`, both `YYYY-MM-DD`. */
45
+ function daysBetween(from, to) {
46
+ return Math.round((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / DAY_MS);
47
+ }
48
+
49
+ /**
50
+ * The blocking advisories in a pnpm audit report, one per advisory id.
51
+ * @returns {Array<{advisory: string, severity: string, module: string, patched: string, versions: string[]}>}
52
+ */
53
+ export function blockingFindings(report, blocking = DEFAULT_BLOCKING) {
54
+ const found = new Map();
55
+ for (const a of Object.values(report.advisories ?? {})) {
56
+ if (!(a.severity in blocking)) continue;
57
+ const advisory = a.github_advisory_id || String(a.id);
58
+ const prior = found.get(advisory);
59
+ const versions = (a.findings ?? []).map((f) => f.version);
60
+ if (prior) prior.versions.push(...versions);
61
+ else
62
+ found.set(advisory, {
63
+ advisory,
64
+ severity: a.severity,
65
+ module: a.module_name,
66
+ patched: a.patched_versions ?? "none",
67
+ versions,
68
+ });
69
+ }
70
+ return [...found.values()].sort((x, y) => x.advisory.localeCompare(y.advisory));
71
+ }
72
+
73
+ /**
74
+ * Compare the blocking findings with the registry's acceptances on `today` (`YYYY-MM-DD`).
75
+ * An acceptance is valid through its `expires` day.
76
+ */
77
+ export function checkAcceptances(findings, registry, today) {
78
+ const blocking = registry.blocking ?? DEFAULT_BLOCKING;
79
+ const rows = registry.accepted ?? [];
80
+ const byAdvisory = new Map(findings.map((f) => [f.advisory, f]));
81
+ const invalid = [];
82
+ const expired = [];
83
+ const tooLong = [];
84
+ const stale = [];
85
+ const accepted = new Set();
86
+
87
+ for (const row of rows) {
88
+ if (!row.advisory || !row.reason || !DATE_RE.test(row.expires ?? "")) {
89
+ invalid.push({ row, why: "needs advisory, reason and a YYYY-MM-DD expires" });
90
+ continue;
91
+ }
92
+ if (accepted.has(row.advisory)) {
93
+ invalid.push({ row, why: "listed twice" });
94
+ continue;
95
+ }
96
+ accepted.add(row.advisory);
97
+ const finding = byAdvisory.get(row.advisory);
98
+ if (!finding) {
99
+ stale.push({ row });
100
+ continue;
101
+ }
102
+ if (row.expires < today) {
103
+ expired.push({ row, finding });
104
+ continue;
105
+ }
106
+ const limit = blocking[finding.severity];
107
+ if (daysBetween(today, row.expires) > limit) tooLong.push({ row, finding, limit });
108
+ }
109
+ const missing = findings.filter((f) => !accepted.has(f.advisory));
110
+ return { missing, invalid, expired, tooLong, stale };
111
+ }
112
+
113
+ /**
114
+ * Run `pnpm audit --json`, retrying when it prints no report (a registry blip).
115
+ * pnpm exits 1 whenever it finds an advisory, so the exit code is not the signal; the report is.
116
+ * @returns {object | null} the parsed report, or null after three attempts.
117
+ */
118
+ function runAudit() {
119
+ for (let attempt = 1; attempt <= 3; attempt++) {
120
+ const res = spawnSync("pnpm", ["audit", "--json"], {
121
+ encoding: "utf-8",
122
+ maxBuffer: 64 * 1024 * 1024,
123
+ });
124
+ let parseError = "";
125
+ try {
126
+ const report = JSON.parse(res.stdout);
127
+ if (report && typeof report.advisories === "object") return report;
128
+ } catch (err) {
129
+ parseError = `not JSON (${err.message}): `;
130
+ }
131
+ const tail = (res.stderr || res.stdout || "").trim().split("\n").slice(-3).join(" | ");
132
+ const detail = parseError + tail;
133
+ console.error(`::warning::dependency-audit: attempt ${attempt} printed no report — ${detail}`);
134
+ }
135
+ return null;
136
+ }
137
+
138
+ function main(argv) {
139
+ const { values } = parseArgs({
140
+ args: argv,
141
+ options: { registry: { type: "string" }, report: { type: "string" } },
142
+ strict: false,
143
+ });
144
+ const registryPath = values.registry ?? path.join("scripts", "ci", "accepted-advisories.json");
145
+ const reportPath = values.report ?? null;
146
+
147
+ const registry = fs.existsSync(registryPath)
148
+ ? JSON.parse(fs.readFileSync(registryPath, "utf-8"))
149
+ : { accepted: [] };
150
+ const report = reportPath ? JSON.parse(fs.readFileSync(reportPath, "utf-8")) : runAudit();
151
+ if (!report || typeof report.advisories !== "object") {
152
+ console.error("::error::dependency-audit: the audit printed no report — failing closed");
153
+ process.exit(1);
154
+ }
155
+
156
+ const findings = blockingFindings(report, registry.blocking ?? DEFAULT_BLOCKING);
157
+ const today = isoDay(new Date());
158
+ const { missing, invalid, expired, tooLong, stale } = checkAcceptances(findings, registry, today);
159
+
160
+ const fmt = (f) =>
161
+ ` ${f.advisory} ${f.severity} ${f.module} ${f.versions.join(", ")} (patched: ${f.patched})`;
162
+ let failed = 0;
163
+ const fail = (rows, title, line) => {
164
+ if (!rows.length) return;
165
+ failed = 1;
166
+ console.error(`::error::dependency-audit: ${rows.length} ${title}:`);
167
+ for (const r of rows) console.error(line(r));
168
+ };
169
+ fail(
170
+ missing,
171
+ "blocking advisory(ies) with no acceptance — upgrade, or accept with a reason and expiry",
172
+ fmt,
173
+ );
174
+ fail(
175
+ expired,
176
+ "acceptance(s) expired — upgrade, or re-review and renew",
177
+ (r) => `${fmt(r.finding)} expired ${r.row.expires}`,
178
+ );
179
+ fail(
180
+ tooLong,
181
+ "acceptance(s) run past their severity's limit",
182
+ (r) => `${fmt(r.finding)} expires ${r.row.expires}, limit ${r.limit} days`,
183
+ );
184
+ fail(
185
+ stale,
186
+ "acceptance(s) for advisories the audit no longer reports — delete the row",
187
+ (r) => ` ${r.row.advisory} ${r.row.module ?? ""}`,
188
+ );
189
+ fail(invalid, "invalid row(s)", (r) => ` ${JSON.stringify(r.row)} — ${r.why}`);
190
+ if (!failed) {
191
+ console.error(
192
+ `[dependency-audit] ${findings.length} blocking advisory(ies), all accepted and in date`,
193
+ );
194
+ }
195
+ process.exit(failed);
196
+ }
197
+
198
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
199
+ main(process.argv.slice(2));
200
+ }
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+ // Example. Copy into scripts/ci/ and own it. bkit install does not write this file
3
+ // and does not overwrite a copy.
4
+ /**
5
+ * check-dependency-audit.test.mjs — unit tests for the dependency-audit gate.
6
+ *
7
+ * Pure Node, no runner: `node scripts/ci/check-dependency-audit.test.mjs`.
8
+ * Exit: 0 = all tests passed, 1 = at least one test failed.
9
+ */
10
+
11
+ import { blockingFindings, checkAcceptances } from "./check-dependency-audit.mjs";
12
+
13
+ let passed = 0;
14
+ let failed = 0;
15
+
16
+ function test(name, fn) {
17
+ try {
18
+ fn();
19
+ passed++;
20
+ console.log(` ok ${name}`);
21
+ } catch (err) {
22
+ failed++;
23
+ console.log(` FAIL ${name} — ${err.message}`);
24
+ }
25
+ }
26
+
27
+ function assert(cond, message) {
28
+ if (!cond) throw new Error(message);
29
+ }
30
+
31
+ const REPORT = {
32
+ advisories: {
33
+ 1: {
34
+ id: 1,
35
+ github_advisory_id: "GHSA-crit",
36
+ severity: "critical",
37
+ module_name: "proxy-addr",
38
+ patched_versions: ">=2.0.8",
39
+ findings: [{ version: "2.0.7" }],
40
+ },
41
+ 2: {
42
+ id: 2,
43
+ github_advisory_id: "GHSA-high",
44
+ severity: "high",
45
+ module_name: "braces",
46
+ patched_versions: "<0.0.0",
47
+ findings: [{ version: "3.0.3" }],
48
+ },
49
+ 3: {
50
+ id: 3,
51
+ github_advisory_id: "GHSA-mod",
52
+ severity: "moderate",
53
+ module_name: "nanoid",
54
+ findings: [{ version: "3.3.7" }],
55
+ },
56
+ },
57
+ };
58
+ const TODAY = "2026-10-17";
59
+ const accept = (advisory, expires, extra = {}) => ({
60
+ advisory,
61
+ reason: "no patched release",
62
+ expires,
63
+ ...extra,
64
+ });
65
+
66
+ test("keeps high and critical, drops moderate", () => {
67
+ const ids = blockingFindings(REPORT).map((f) => f.advisory);
68
+ assert(ids.join() === "GHSA-crit,GHSA-high", `got ${ids}`);
69
+ });
70
+
71
+ test("a custom blocking table changes what blocks", () => {
72
+ const ids = blockingFindings(REPORT, { critical: 7 }).map((f) => f.advisory);
73
+ assert(ids.join() === "GHSA-crit", `got ${ids}`);
74
+ });
75
+
76
+ test("an advisory with no acceptance is missing", () => {
77
+ const r = checkAcceptances(blockingFindings(REPORT), { accepted: [] }, TODAY);
78
+ assert(r.missing.length === 2, `missing ${r.missing.length}`);
79
+ });
80
+
81
+ test("accepted, in-date advisories pass", () => {
82
+ const registry = {
83
+ accepted: [accept("GHSA-crit", "2026-10-24"), accept("GHSA-high", "2026-11-16")],
84
+ };
85
+ const r = checkAcceptances(blockingFindings(REPORT), registry, TODAY);
86
+ const total = Object.values(r).reduce((n, rows) => n + rows.length, 0);
87
+ assert(total === 0, JSON.stringify(r));
88
+ });
89
+
90
+ test("an acceptance is valid through its expiry day, expired the day after", () => {
91
+ const registry = { accepted: [accept("GHSA-high", TODAY)] };
92
+ const findings = blockingFindings(REPORT, { high: 30 });
93
+ assert(checkAcceptances(findings, registry, TODAY).expired.length === 0, "expired on its day");
94
+ assert(checkAcceptances(findings, registry, "2026-10-18").expired.length === 1, "not expired");
95
+ });
96
+
97
+ test("an acceptance past its severity's limit is too long", () => {
98
+ const registry = { accepted: [accept("GHSA-crit", "2026-10-25")] };
99
+ const r = checkAcceptances(blockingFindings(REPORT, { critical: 7 }), registry, TODAY);
100
+ assert(r.tooLong.length === 1 && r.tooLong[0].limit === 7, JSON.stringify(r.tooLong));
101
+ });
102
+
103
+ test("an acceptance for an advisory no longer reported is stale", () => {
104
+ const registry = { accepted: [accept("GHSA-gone", "2026-10-20")] };
105
+ const r = checkAcceptances(blockingFindings(REPORT), registry, TODAY);
106
+ assert(r.stale.length === 1, `stale ${r.stale.length}`);
107
+ });
108
+
109
+ test("a row with no reason, a bad date, or a repeat is invalid", () => {
110
+ const registry = {
111
+ accepted: [
112
+ { advisory: "GHSA-crit", expires: "2026-10-20" },
113
+ accept("GHSA-high", "next month"),
114
+ accept("GHSA-crit", "2026-10-20"),
115
+ accept("GHSA-crit", "2026-10-20"),
116
+ ],
117
+ };
118
+ const r = checkAcceptances(blockingFindings(REPORT), registry, TODAY);
119
+ assert(r.invalid.length === 3, `invalid ${r.invalid.length}`);
120
+ });
121
+
122
+ test("a report with no advisories has nothing to block", () => {
123
+ assert(blockingFindings({ advisories: {} }).length === 0, "found something");
124
+ });
125
+
126
+ console.log(`\n${passed} passed, ${failed} failed`);
127
+ process.exit(failed ? 1 : 0);
package/CHANGELOG.md CHANGED
@@ -8,6 +8,45 @@ Format: `## [version] — YYYY-MM-DD`
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [5.2.3] — 2026-10-17
12
+
13
+ ### Added
14
+
15
+ - **Dependency-audit CI gate.** New copy-and-own `scripts/ci/check-dependency-audit.mjs` (+ `.test.mjs`, `accepted-advisories.json`) runs `pnpm audit --json` and fails on any high / critical advisory the registry does not accept. Each acceptance needs a reason and an expiry (at most 7 days for critical, 30 for high); expired, over-long and stale rows fail; no report = fail. The CI template gains a `Check Dependency Audit` step in `bkit-tests-static`, a no-op until the script is copied. `docs/deployments.md` § Dependency updaters. Upgrade hint is `pnpm update -r <pkg>` (works on pnpm 10 and 12).
16
+ - **Audit findings reach `docs/failures.jsonl`.** `@bkit-audit-generate` writes one failure row per `MEDIUM`+ finding once the report is complete (`workflow: "audit"`, `step: "audit-{slug}"`). A rerun reuses an open row's `key` for the same problem, downgrades it to `LOW` when the finding drops, and closes rows it no longer finds in surfaces it checked. The failures and deferrals audits write no rows. Plan and design already read the ledger, so findings feed them without a hand link.
17
+ - **Audit reports carry a `bkit:anchor` block.** The audit agent runs `bkit branches anchor-stamp` right after creating the report, so the audited commit sits at the top of the file like design and plan docs. Step 1 of every template reads this and the previous report's commit from it. `anchor-stamp` gains `--base-ref` (default `origin/dev`).
18
+ - **Audit Pre-Flight checks permissions first.** Every template opens with one read-only call per tool; a blocked call stops the run before `Probe Steps` and hands back narrow allow rules to grant, or `continue`. Blocked calls persist in `Project Instructions` `Permissions`.
19
+
20
+ ### Changed
21
+
22
+ - **Logs audit template checks three things it skipped** (#575). Step 3: fixed `Board` figure per platform re-reporting to the tracker, platform failures beside tracker events (ratio < 1 = lost reports). Step 9: every `docs/noise.md` archive / mute row against its recorded trigger. Step 12: scheduled-job runs started and never finished. "warnings-doc" → `docs/noise.md`.
23
+ - **Audit agent turn cap 150 → 300** (new `XL` tier). One agent runs every template; the longest run ~20 probe steps.
24
+ - **Audit templates probe direnv before calling a credential missing** and run credentialed CLIs through `direnv exec .`. The logs, failures, reliability, flakes and annotations audits point at the `.agents/context.md` readers for their time window.
25
+
26
+ ### Fixed
27
+
28
+ - **Context-fetch templates print `skipped` instead of empty output on an API error** (#575). A consumer's log audit found seven of nine readers returning nothing while real failures existed. Every runtime block now checks HTTP status / CLI exit and body shape, pages the whole window, prints `TRUNCATED` when its page cap stops it, and suggests a positive control in `# Customise:`. Per vendor:
29
+ - `supabase.md`: removed `logs.all` → `analytics/endpoints/logs`, one call per day, counts per SQLSTATE.
30
+ - `vercel.md`: `--no-branch`; pages past the 50-line cap; filters `.level`. `VERCEL_N` → `VERCEL_MAX_PAGES`.
31
+ - `inngest.md`: cursor paging; refuses a branch key with `INNGEST_ENV` unset; error class only, never error text. Adds `UNTIL_ISO`, `INNGEST_MAX_PAGES`.
32
+ - `cloudrun.md`: gcloud login only when `gcloud auth print-access-token` works, else service account in a throwaway `CLOUDSDK_CONFIG`; failed `logging read` → `skipped`. Adds `GCP_FILTER`.
33
+ - `stripe.md`: `starting_after` paging; `delivery_success=false` pass. `STRIPE_N` → `STRIPE_MAX_PAGES`.
34
+ - `resend.md`: `after` paging back to `SINCE_ISO`. `RESEND_N` → `SINCE_ISO`, `RESEND_MAX_PAGES`.
35
+ - `expo.md`: `EAS_N` default 10 → 50. `expo-workflows`: `startedAt` (was `null` via `createdAt`), `--limit` ≤ 100, FAILURE list (`EAS_WF_FAIL_N`), `workflow:status` judged by its JSON.
36
+ - `sentry.md`: status and array-shape checks; detector configs carry uptime-check headers.
37
+
38
+ Templates are copy-and-own: a copy below `bkit:end` changes only when re-copied.
39
+
40
+ - **`.agents/context.md` authoring rules** (#575): API / auth error = self-skip; check status before jq; page the window or print `TRUNCATED`; suggest a positive control.
41
+ - **Destructive-git guardrails catch reordered flags.** The Cursor, Codex and Antigravity hooks parse each command (every `&&` / `;` / `|` part, `bash -c`, `$(...)`) into subcommand and flags in any order, with combined short flags (`-fdx`) and global options (`-C dir`, `-q`). `git reset -q --hard`, `git clean -df`, `git checkout -q -- .` and `git restore --worktree .` now ask. Claude and opencode gain glob rows for the common reordered forms in the same tiers.
42
+ - **Force-push denied in any position on every host.** `git push origin dev --force`, `-f` after other args and `+refspec` are denied on Claude and opencode as on the hook hosts; `--force-with-lease` stays allowed.
43
+ - **`--no-verify` asks on every host** (`git commit -n` too).
44
+ - **Shell reads of secret files ask on Cursor and Antigravity** (advisory on Codex): `.env*` except `.env.example`, `*.pem`, `*.p12`, `id_rsa`. Copy destinations, renames and grep patterns don't count as reads. Claude and opencode don't gate shell reads, because their tables match command text and would stall unattended runs on mentions; `.bkit/providers.md` says so.
45
+ - **`bkit check` and `bkit status` see an Antigravity install with `plugin.json` deleted.** Any of `.agents/plugins/bkit/{plugin.json,hooks.json,agents,skills,hooks}` marks the host installed, so a missing manifest or hook file is drift (exit 1), not `antigravity: absent`. `check`, `status` and install share one detector.
46
+ - **Full `bkit uninstall` removes every bkit-written `.opencode/opencode.json` entry.** Every supported provider block and tracker `mcp` entry that still matches bkit's template is stripped, not just the first one found; an edited block is kept whole.
47
+ - **`bkit upgrade` refreshes the recorded hashes of `.cursor/allowlist.json` and `.cursor/cli.json`** after regenerating them, so a later uninstall no longer keeps them as consumer-modified.
48
+ - **`.bkit/install.md` states that `bkit check` does not verify `.bkit/version` `canonicalHashes`**; a bad entry makes uninstall keep that file (`--force` removes it).
49
+
11
50
  ## [5.2.2] — 2026-10-15
12
51
 
13
52
  ### Fixed