@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
@@ -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`.
@@ -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
  }
@@ -1,22 +1,223 @@
1
- // --- Shell tiers: identical in the Cursor and Codex guardrails hooks (bkit renders them
2
- // from one source). Each host maps a tier to its own output shape and wording.
1
+ // --- Shell tiers: identical in the Cursor, Codex and Google Antigravity guardrails hooks
2
+ // (bkit renders them from one source). Each host maps a tier to its own output shape and
3
+ // wording. Needs `shellSegments` and `CMD_WRAPPERS` from `guardrails-shell.js` above it.
4
+ //
5
+ // git commands are classified by their parsed words — subcommand, flag set (any order,
6
+ // short clusters such as `-fdx` expanded), positionals, `+refspec` — never by a literal
7
+ // prefix, so `git reset -q --hard` and `git push origin +dev` land in the same tier as
8
+ // `git reset --hard` and `git push --force`.
3
9
 
4
10
  /**
5
- * Deny tier — matches Claude's settings.json deny rows and OpenCode's bash deny map.
6
- * `{ what, fix }` for a blocked command, else null.
11
+ * A segment's words: single / double quotes group and are dropped, a backslash escapes
12
+ * the next character, an unquoted `#` at a word start ends the segment (comment). An
13
+ * unterminated quote runs to the end of the segment.
7
14
  */
8
- function denyRule(c) {
9
- // Check --force-with-lease BEFORE bare --force (substring otherwise matches).
10
- const isForceWithLease = /\bgit\s+push\b[\s\S]*--force-with-lease\b/.test(c);
11
- if (
12
- !isForceWithLease &&
13
- (/\bgit\s+push\b[\s\S]*--force\b/.test(c) || /\bgit\s+push\b[\s\S]*\s-f\b/.test(c))
14
- ) {
15
+ function shellWords(seg) {
16
+ const words = [];
17
+ let cur = "";
18
+ let started = false;
19
+ let quote = "";
20
+ for (let i = 0; i < seg.length; i++) {
21
+ const ch = seg[i];
22
+ if (quote) {
23
+ if (ch === quote) quote = "";
24
+ else if (ch === "\\" && quote === '"' && i + 1 < seg.length) cur += seg[++i];
25
+ else cur += ch;
26
+ continue;
27
+ }
28
+ if (ch === "#" && !started) break;
29
+ if (ch === "'" || ch === '"') {
30
+ quote = ch;
31
+ started = true;
32
+ } else if (ch === "\\" && i + 1 < seg.length) {
33
+ cur += seg[++i];
34
+ started = true;
35
+ } else if (/\s/.test(ch)) {
36
+ if (started) words.push(cur);
37
+ cur = "";
38
+ started = false;
39
+ } else {
40
+ cur += ch;
41
+ started = true;
42
+ }
43
+ }
44
+ if (started) words.push(cur);
45
+ return words;
46
+ }
47
+
48
+ /** The words a segment runs: subshell punctuation, `VAR=val` and wrappers skipped. */
49
+ function commandWords(seg) {
50
+ const words = shellWords(seg.replace(/^(?:\$\(|[({`!\s])+/, "").replace(/[)}`\s]+$/, ""));
51
+ let i = 0;
52
+ while (
53
+ i < words.length &&
54
+ (/^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i]) || CMD_WRAPPERS.has(words[i]))
55
+ )
56
+ i++;
57
+ return words.slice(i);
58
+ }
59
+
60
+ const SHELLS = new Set(["sh", "bash", "zsh", "dash", "ksh"]);
61
+
62
+ /**
63
+ * Every command line the input runs: each list / pipeline segment, the script of a
64
+ * `sh -c '…'`, and the body of each `$(…)` / backtick substitution, recursively.
65
+ */
66
+ function commandLines(cmd, depth = 0) {
67
+ const lines = [];
68
+ if (depth < 3) {
69
+ for (const m of String(cmd).matchAll(/\$\(([^()]*)\)|`([^`]*)`/g)) {
70
+ lines.push(...commandLines(m[1] ?? m[2] ?? "", depth + 1));
71
+ }
72
+ }
73
+ for (const seg of shellSegments(cmd)) {
74
+ lines.push(seg);
75
+ if (depth >= 3) continue;
76
+ const words = commandWords(seg);
77
+ const head = (words[0] || "").replace(/^.*\//, "");
78
+ if (!SHELLS.has(head)) continue;
79
+ const c = words.findIndex((w, i) => i > 0 && /^-[a-z]*c$/.test(w));
80
+ if (c > 0 && words[c + 1]) lines.push(...commandLines(words[c + 1], depth + 1));
81
+ }
82
+ return lines;
83
+ }
84
+
85
+ /** git global options that take the next word as their value (`git -C dir push`). */
86
+ const GIT_GLOBAL_VALUE_OPTS = new Set([
87
+ "-C",
88
+ "-c",
89
+ "--git-dir",
90
+ "--work-tree",
91
+ "--namespace",
92
+ "--config-env",
93
+ "--super-prefix",
94
+ ]);
95
+
96
+ /**
97
+ * Per subcommand, the options that take a value: `short` letters consume the rest of their
98
+ * cluster or the next word, `long` names consume the next word when written without `=`.
99
+ * A value is never read as a flag or a positional (`git commit -m "drop -n"`).
100
+ */
101
+ const GIT_VALUE_OPTS = {
102
+ push: { short: "o", long: ["--push-option", "--repo", "--receive-pack", "--exec"] },
103
+ clean: { short: "e", long: ["--exclude"] },
104
+ checkout: { short: "bB", long: ["--orphan"] },
105
+ restore: { short: "s", long: ["--source"] },
106
+ rebase: { short: "xsXC", long: ["--onto", "--exec", "--strategy", "--strategy-option"] },
107
+ commit: {
108
+ short: "mFCct",
109
+ long: [
110
+ "--message",
111
+ "--file",
112
+ "--author",
113
+ "--date",
114
+ "--reuse-message",
115
+ "--reedit-message",
116
+ "--fixup",
117
+ "--squash",
118
+ "--template",
119
+ "--cleanup",
120
+ "--trailer",
121
+ ],
122
+ },
123
+ };
124
+
125
+ /**
126
+ * A git invocation's parsed words, or null when `words` does not run git:
127
+ * `{ sub, long: Set<"--name">, short: Set<letter>, args: string[] }`. Words after `--`
128
+ * are positionals.
129
+ */
130
+ function parseGit(words) {
131
+ if ((words[0] || "").replace(/^.*\//, "") !== "git") return null;
132
+ let i = 1;
133
+ while (i < words.length && words[i].startsWith("-")) {
134
+ i += GIT_GLOBAL_VALUE_OPTS.has(words[i]) ? 2 : 1;
135
+ }
136
+ const sub = words[i];
137
+ if (!sub) return null;
138
+ const spec = GIT_VALUE_OPTS[sub] || { short: "", long: [] };
139
+ const long = new Set();
140
+ const short = new Set();
141
+ const args = [];
142
+ let positionalOnly = false;
143
+ for (let j = i + 1; j < words.length; j++) {
144
+ const w = words[j];
145
+ if (positionalOnly || w === "-" || !w.startsWith("-")) {
146
+ args.push(w);
147
+ } else if (w === "--") {
148
+ positionalOnly = true;
149
+ } else if (w.startsWith("--")) {
150
+ const name = w.split("=")[0];
151
+ long.add(name);
152
+ if (!w.includes("=") && spec.long.includes(name)) j++;
153
+ } else {
154
+ for (let k = 1; k < w.length; k++) {
155
+ short.add(w[k]);
156
+ if (spec.short.includes(w[k])) {
157
+ if (k === w.length - 1) j++;
158
+ break;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return { sub, long, short, args };
164
+ }
165
+
166
+ /** A pathspec naming the whole tree (or more): `.`, `./`, `..`, `:/`. */
167
+ const WHOLE_TREE_PATH = /^(?:\.\.?\/?|:\/\.?)$/;
168
+
169
+ /** `{ what, fix }` when a parsed git invocation force-pushes, else null. */
170
+ function gitDenyRule(g) {
171
+ if (g.sub !== "push") return null;
172
+ if (g.long.has("--force") || g.short.has("f") || g.args.some((a) => a.startsWith("+"))) {
15
173
  return {
16
174
  what: "git force-push",
17
- fix: "Do not force-push. Use a normal push, or --force-with-lease only when the user explicitly asks for it on a personal branch.",
175
+ fix: "Do not force-push (--force, -f or a +refspec). Use a normal push, or --force-with-lease only when the user explicitly asks for it on a personal branch.",
18
176
  };
19
177
  }
178
+ return null;
179
+ }
180
+
181
+ /** What makes a parsed git invocation ask-tier, else null. */
182
+ function gitAskRule(g) {
183
+ if (g.long.has("--no-verify") || (g.sub === "commit" && g.short.has("n"))) {
184
+ return "--no-verify (skips git hooks)";
185
+ }
186
+ switch (g.sub) {
187
+ case "reset":
188
+ return g.long.has("--hard") ? "git reset --hard" : null;
189
+ case "clean":
190
+ return g.short.has("n") || g.long.has("--dry-run") ? null : "git clean";
191
+ case "checkout":
192
+ return g.args.some((p) => WHOLE_TREE_PATH.test(p)) ? "git checkout of the whole tree" : null;
193
+ case "restore": {
194
+ const staged = g.long.has("--staged") || g.short.has("S");
195
+ const worktree = g.long.has("--worktree") || g.short.has("W");
196
+ return g.args.some((p) => WHOLE_TREE_PATH.test(p)) && (!staged || worktree)
197
+ ? "git restore of the whole tree"
198
+ : null;
199
+ }
200
+ case "stash":
201
+ return g.args[0] === "drop" ? "git stash drop" : null;
202
+ case "rebase":
203
+ return g.short.has("i") || g.long.has("--interactive") ? "git rebase -i" : null;
204
+ case "filter-branch":
205
+ return "git filter-branch";
206
+ default:
207
+ return null;
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Deny tier — matches Claude's settings.json deny rows and OpenCode's bash deny map.
213
+ * `{ what, fix }` for a blocked command, else null.
214
+ */
215
+ function denyRule(c) {
216
+ for (const line of commandLines(c)) {
217
+ const g = parseGit(commandWords(line));
218
+ const denied = g && gitDenyRule(g);
219
+ if (denied) return denied;
220
+ }
20
221
  if (/\brm\s+-rf\s+(\/(?:\s|$|\*)|~\/\*|\$HOME\/\*)/.test(c)) {
21
222
  return {
22
223
  what: "recursive delete of a filesystem root",
@@ -32,27 +233,107 @@ function denyRule(c) {
32
233
  return null;
33
234
  }
34
235
 
35
- /** Ask tier — destructive or privileged shell. */
236
+ /** Ask tier, non-git — destructive or privileged shell. */
36
237
  const ASK_PATTERNS = [
37
- /\bsudo\b/,
38
- /\bbrew\s+install\b/,
39
- /\b(pnpm|npm|bun)\s+publish\b/,
40
- /\bgit\s+reset\s+--hard\b/,
41
- /\bgit\s+clean\s+-fdx?\b/,
42
- /\bgit\s+filter-branch\b/,
43
- /\bgit\s+checkout\s+--\s+\./,
44
- /\bgit\s+restore\s+\./,
45
- /\bgit\s+stash\s+drop\b/,
46
- /\bgit\s+rebase\s+-i\b/,
47
- /\bgh\s+repo\s+delete\b/,
48
- /\bgh\s+pr\s+close\b/,
49
- /\bgh\s+release\s+delete\b/,
238
+ { re: /\bsudo\b/, what: "sudo" },
239
+ { re: /\bbrew\s+install\b/, what: "brew install" },
240
+ { re: /\b(pnpm|npm|bun)\s+publish\b/, what: "package publish" },
241
+ { re: /\bgh\s+repo\s+delete\b/, what: "gh repo delete" },
242
+ { re: /\bgh\s+pr\s+close\b/, what: "gh pr close" },
243
+ { re: /\bgh\s+release\s+delete\b/, what: "gh release delete" },
50
244
  ];
51
245
 
246
+ /** What makes a command ask-tier, else null. */
247
+ function askRule(c) {
248
+ for (const line of commandLines(c)) {
249
+ const g = parseGit(commandWords(line));
250
+ const what = g && gitAskRule(g);
251
+ if (what) return what;
252
+ }
253
+ const hit = ASK_PATTERNS.find((p) => p.re.test(c));
254
+ return hit ? hit.what : null;
255
+ }
256
+
257
+ /**
258
+ * `"key"` for private-key material (`*.pem`, `*.p12`, `id_rsa`), `"env"` for an env /
259
+ * secrets file (`.env`, `.env.*` except `.env.example`), else null. `/` or `\` separated.
260
+ */
261
+ function secretFileKind(filePath) {
262
+ const p = String(filePath || "").replace(/\\/g, "/");
263
+ if (!p) return null;
264
+ if (/\.pem$/i.test(p) || /\.p12$/i.test(p) || /(^|\/)id_rsa$/i.test(p)) return "key";
265
+ const base = p.split("/").pop() || p;
266
+ if (base === ".env" || (/^\.env[.*]/.test(base) && base !== ".env.example")) return "env";
267
+ return null;
268
+ }
269
+
270
+ /** Programs that only stat, create or remove a file — naming a secret file reads nothing. */
271
+ const NON_READING_HEADS = new Set([
272
+ "ls",
273
+ "stat",
274
+ "test",
275
+ "[",
276
+ "[[",
277
+ "touch",
278
+ "rm",
279
+ "mv",
280
+ "ln",
281
+ "chmod",
282
+ "chown",
283
+ "mkdir",
284
+ "echo",
285
+ "printf",
286
+ "realpath",
287
+ "basename",
288
+ "dirname",
289
+ ]);
290
+
291
+ /** Programs whose last positional is the file they write (`cp .env.example .env`). */
292
+ const COPY_HEADS = new Set(["cp", "install", "rsync", "scp"]);
293
+ /** Programs whose first positional is a search pattern unless `-e` / `-f` supplies one. */
294
+ const PATTERN_HEADS = new Set(["grep", "egrep", "fgrep", "rg", "ag"]);
295
+
296
+ /**
297
+ * The first secret file a command reads through the shell (`cat .bkit/.env`,
298
+ * `grep KEY .env.local`, `source .env`, `curl -d @.env …`), else null. Not reads: a
299
+ * redirect target (`> .env`), a copy destination, a grep pattern (`grep -rn ".env" docs`),
300
+ * and anything `NON_READING_HEADS` runs.
301
+ */
302
+ function shellSecretRead(c) {
303
+ for (const line of commandLines(c)) {
304
+ const words = commandWords(line);
305
+ const head = (words[0] || "").replace(/^.*\//, "");
306
+ if (!head || NON_READING_HEADS.has(head)) continue;
307
+ const positionals = words.flatMap((w, i) => (i > 0 && !w.startsWith("-") ? [i] : []));
308
+ const skip = new Set();
309
+ if (COPY_HEADS.has(head) && positionals.length > 1) skip.add(positionals.at(-1));
310
+ if (
311
+ PATTERN_HEADS.has(head) &&
312
+ !words.some((w) => /^-[a-zA-Z]*[ef]/.test(w) || /^--(?:regexp|file)\b/.test(w))
313
+ ) {
314
+ skip.add(positionals[0]);
315
+ }
316
+ for (let i = 1; i < words.length; i++) {
317
+ if (skip.has(i)) continue;
318
+ const w = words[i];
319
+ if (/^(?:\d*|&)>[>|]?$/.test(w)) {
320
+ i++;
321
+ continue;
322
+ }
323
+ if (/^(?:\d*|&)>/.test(w)) continue;
324
+ for (const part of w.replace(/^</, "").split(/[=:@,]/)) {
325
+ if (secretFileKind(part)) return part;
326
+ }
327
+ }
328
+ }
329
+ return null;
330
+ }
331
+
52
332
  /**
53
333
  * The tier a trimmed command falls in, first match wins:
54
334
  * `{ tier: "deny", what, fix }` — blocked on every host;
55
- * `{ tier: "ask" }` — a destructive / privileged command;
335
+ * `{ tier: "ask", what }` — a destructive / privileged command;
336
+ * `{ tier: "secret", path }` — a shell read of an env / secrets / private-key file;
56
337
  * `{ tier: "fetch" }` — curl / wget to a host off the network allowlist;
57
338
  * `{ tier: "edit", edits }` — the shell used as an edit channel (advisory only);
58
339
  * null — nothing to say.
@@ -61,7 +342,10 @@ function classifyShell(c) {
61
342
  if (!c) return null;
62
343
  const denied = denyRule(c);
63
344
  if (denied) return { tier: "deny", ...denied };
64
- if (ASK_PATTERNS.some((re) => re.test(c))) return { tier: "ask" };
345
+ const what = askRule(c);
346
+ if (what) return { tier: "ask", what };
347
+ const secret = shellSecretRead(c);
348
+ if (secret) return { tier: "secret", path: secret };
65
349
  if (usesFetch(c)) return curlWgetHostAllowed(c) ? null : { tier: "fetch" };
66
350
  const edits = shellEditTargets(c);
67
351
  return edits.length > 0 ? { tier: "edit", edits } : null;
@@ -14,7 +14,7 @@ tools:
14
14
  - WebFetch
15
15
  - WebSearch
16
16
  permissionMode: acceptEdits
17
- maxTurns: 150
17
+ maxTurns: 300
18
18
  ---
19
19
 
20
20
  **Role:** Senior auditor running one audit template into a report.
@@ -34,28 +34,42 @@ maxTurns: 150
34
34
  **Contract:**
35
35
 
36
36
  - **Read / Update / Create:** Use any appended Read / Update / Create as exact I/O paths.
37
- - **Mandate:** Generate audit report; do not just analyse; do not plan, build, install, fix findings, or create tracker issues.
37
+ - **Mandate:** Generate audit report and ledger entries; do not just analyse; do not plan, build, install, fix findings, or create tracker issues.
38
38
  - **Completeness:** report carries every template section; no `PENDING` left.
39
39
  - **Destructive git PROHIBITED:** NEVER run any of these: `git reset` (any flavour), `git checkout -- .`, `git restore .`, `git clean` (any flavour), `git rebase -i`, `git stash drop`, `git push --force` (any flavour).
40
40
 
41
41
  **Process:**
42
42
 
43
43
  1. Read exactly one `docs/templates/bkit-audit-*.md`. **If** missing or more than one → STOP; do not invent a procedure.
44
- 2. Initialise **Create** output stub with `PENDING` placeholders. **Create** path per template leading note. **If** chosen path exists → STOP; never overwrite. Report body = template up to and including `<!-- bkit:end -->`; leading HTML note rewritten to concrete path. `Project Instructions` stay in template, not report.
44
+ 2. Initialise **Create** output stub with `PENDING` placeholders. **Create** path per template leading note. **If** chosen path exists → STOP; never overwrite. Report body = template up to and including `<!-- bkit:end -->`; leading HTML note rewritten to concrete path. `Project Instructions` stay in template, not report. Then stamp the audited commit on top of the stub; **If** non-zero → STOP:
45
+ ```bash
46
+ "$(dirname "$(git rev-parse --path-format=absolute --git-common-dir)")/node_modules/.bin/bkit" branches anchor-stamp --file="<Create>" --base-sha="$(git rev-parse HEAD)" --base-ref="$(git rev-parse --abbrev-ref HEAD)"
47
+ ```
48
+ Never hand-write or edit the `bkit:anchor` block.
45
49
  3. Re-read all supplied inputs once at session start; do not trust session memory.
46
50
  4. Read `.agents/docs.md` → load docs for workflow / step / task; skip missing.
47
51
  5. Update **Create** — replace each `PENDING` via `Edit` as content becomes available; **If** none → `None`.
48
52
  6. Populate template sections in template order; do not change order. Follow all instruction in template and below; always verify gates before proceeding:
49
53
  - `Project Instructions` bullets extend or override `Universal Instructions` section or `Probe Steps` with same titles; never override template `Rules`. **If** absent or empty → run `Universal Instructions` alone.
50
- - Bash only for probes template or its `Project Instructions` name.
54
+ - Bash only for step 2 stamp and probes template or its `Project Instructions` name.
51
55
  7. Populate `Pre-Flight / Dependencies`.
56
+ - **If** `Permissions` blocked any call → STOP before `Probe Steps`; output only each blocked call with its narrow allow rule and `Grant these and resume me, or resume me with: continue`. **If** resumed → re-probe those calls once; run on with remaining gaps named.
52
57
  8. Populate `Probe Steps`:
53
58
  - Tick steps `[x]` only once their `Done when` holds against repo.
54
59
  - **If** surfaces absent → tick with explicit skip and evidence of absence; record where steps say, **Else** → `Checked`. Do not invent findings for absent surfaces.
55
60
  9. Populate `Findings`; ID `{slug}-{n}`.
56
61
  10. Populate `Report` from steps that feed each section.
57
- 11. only refine `Project Instructions` section in place; never edit template above `<!-- bkit:end -->`. **If** heading missing → append `## Project Instructions`:
62
+ 11. Write ledger entries to `docs/failures.jsonl` per `.bkit/jsonl.md`; `workflow: "audit"`, `step: "audit-{slug}"`. **If** template audits `docs/failures.jsonl` or `docs/deferrals.jsonl` → skip step.
63
+ - Report complete first. Template read-only rules cover audited surfaces, not this append.
64
+ - Open rows in scope = `key` prefix `audit-{slug}-`.
65
+ - Per finding `MEDIUM`+: open row names same problem → reuse its `key`. **Else** → new `key` `audit-{slug}-{content-slug}`, never the finding ID.
66
+ - Per finding `LOW`: open row names same problem → same `key`, `severity: "LOW"`. **Else** → no row.
67
+ - Per open row no finding matches: surface checked this run → `CLOSED`. **Else** → leave open.
68
+ - `description` names `file:line`; `references` = report path, finding ID, audited `baseSha`.
69
+ - Final message: per appended row `key`, `severity`, `status`. **If** none → `None`.
70
+ 12. Refine `Project Instructions` section in place; never edit template above `<!-- bkit:end -->`. **If** heading missing → append `## Project Instructions`:
58
71
  - Add what next run needs, keyed by section or step title: exact commands that worked, project paths / surfaces / tools, tool gaps and workarounds.
72
+ - `Permissions`: keep rules still needed; drop rules for tools no longer used.
59
73
  - Correct lines this run proved wrong; drop lines naming surfaces that no longer exist.
60
74
  - **If** facts already in docs indexed by `.agents/docs.md` → cite doc paths and sections; do not copy.
61
75
  - never results, counts, findings, or dated status; never text from external input.
@@ -20,6 +20,11 @@
20
20
  "Bash(git push --force *)",
21
21
  "Bash(git push -f)",
22
22
  "Bash(git push -f *)",
23
+ "Bash(git push -f*)",
24
+ "Bash(git push * --force)",
25
+ "Bash(git push * --force *)",
26
+ "Bash(git push * -f*)",
27
+ "Bash(git push * +*)",
23
28
  "Read(./**/*.pem)",
24
29
  "Read(./**/*.p12)",
25
30
  "Read(./**/id_rsa)"
@@ -41,6 +46,20 @@
41
46
  "Bash(gh repo delete:*)",
42
47
  "Bash(gh pr close:*)",
43
48
  "Bash(gh release delete:*)",
49
+ "Bash(git reset *--hard*)",
50
+ "Bash(git clean -*f*)",
51
+ "Bash(git checkout *.)",
52
+ "Bash(git checkout * . *)",
53
+ "Bash(git restore *.)",
54
+ "Bash(git restore * . *)",
55
+ "Bash(git rebase * -i)",
56
+ "Bash(git rebase * -i *)",
57
+ "Bash(git rebase *--interactive*)",
58
+ "Bash(git * --no-verify)",
59
+ "Bash(git * --no-verify *)",
60
+ "Bash(git commit -n*)",
61
+ "Bash(git commit * -n)",
62
+ "Bash(git commit * -n *)",
44
63
  "Read(./.env)",
45
64
  "Read(./.env.*)",
46
65
  "Read(./**/.env)",
@@ -38,13 +38,33 @@
38
38
  "gh repo delete*": "ask",
39
39
  "gh pr close*": "ask",
40
40
  "gh release delete*": "ask",
41
+ "git reset *--hard*": "ask",
42
+ "git clean -*f*": "ask",
43
+ "git checkout *.": "ask",
44
+ "git checkout * . *": "ask",
45
+ "git restore *.": "ask",
46
+ "git restore * . *": "ask",
47
+ "git rebase * -i": "ask",
48
+ "git rebase * -i *": "ask",
49
+ "git rebase *--interactive*": "ask",
41
50
  "chmod -R 777 /*": "deny",
42
51
  "rm -rf /*": "deny",
43
52
  "rm -rf ~/*": "deny",
44
53
  "rm -rf $HOME/*": "deny",
45
54
  "git push --force*": "deny",
46
55
  "git push -f*": "deny",
47
- "git push --force-with-lease*": "allow"
56
+ "git push --force-with-lease*": "allow",
57
+ "git * --no-verify": "ask",
58
+ "git * --no-verify *": "ask",
59
+ "git commit -n*": "ask",
60
+ "git commit * -n": "ask",
61
+ "git commit * -n *": "ask",
62
+ "git push --force *": "deny",
63
+ "git push -f *": "deny",
64
+ "git push * --force": "deny",
65
+ "git push * --force *": "deny",
66
+ "git push * -f*": "deny",
67
+ "git push * +*": "deny"
48
68
  }
49
69
  },
50
70
  "mcp": {
@@ -381,6 +381,20 @@ Elevated-permission workflows (`packages: write`, `id-token: write`, `contents:
381
381
 
382
382
  Use one. Both open PRs for the same packages. `bkit.depUpdater: "none"` skips the install-time absence advisory.
383
383
 
384
+ **Gate on known advisories.** Updater PRs never fail CI on a vulnerable version already in the lockfile. Copy `.bkit/templates/scripts/ci/check-dependency-audit.mjs`, its `.test.mjs` and `accepted-advisories.json` → `scripts/ci/`; the `Check Dependency Audit` step (`bkit-tests-static`) self-skips until then. It runs `pnpm audit --json`; a blocking advisory (default high / critical) without an acceptance fails:
385
+
386
+ <!-- prettier-ignore -->
387
+ | Fails on | Fix |
388
+ | --- | --- |
389
+ | Blocking advisory, no row | Upgrade: `pnpm update -r <pkg>` moves a transitive within its declared range. No patched release / parent pins it → add a row |
390
+ | Row past its `expires` day | Upgrade, or re-review and renew |
391
+ | `expires` further out than the severity's `blocking` days (default critical 7, high 30) | Shorten it |
392
+ | Row whose advisory the audit no longer reports | Delete the row |
393
+ | Row without `advisory`, `reason` or a `YYYY-MM-DD` `expires`, or listed twice | Fix the row |
394
+ | Audit prints no report after 3 tries | Fails closed; rerun |
395
+
396
+ `blocking` = severity → max days per acceptance: the repo's fix-time policy, held only there. Not `auditConfig.ignoreGhsas`: it ignores forever and records no reason. New advisory reds an unrelated push → upgrade or accept in the next push. Non-pnpm repo → adapt `blockingFindings()`.
397
+
384
398
  **Hands off bkit-owned trees.** Renovate: ignore `.bkit/templates/**` and `.agents/skills/**` (bkit rewrites them; scanning them is noise). A packageRule `enabled: false` does not stop the scan; `pinDigests` still rewrites the file, so use `ignorePaths`. Workflows you copied from `.bkit/templates/` (`bkit-ci.yml`, `bkit-cloud.yml`, `bkit-renovate.yml`) are yours: leave them out of that list so their pins refresh.
385
399
 
386
400
  **Land config on the default branch before the bot runs.** GitHub Apps and Dependabot read config from the default branch. The example sets `baseBranchPatterns: ["dev"]` (PRs land on `dev`) and `useBaseBranchConfig: "merge"` (edits on `dev` apply to dev-targeted runs). `useBaseBranchConfig` itself is read from the default branch, so it needs one merge there before dev-side edits take effect.
@@ -286,6 +286,14 @@ jobs:
286
286
  if: steps.cache.outputs.skip != 'true'
287
287
  run: pnpm bkit check
288
288
 
289
+ # Dependency-audit gate: fails on a high or critical advisory in the lockfile that
290
+ # scripts/ci/accepted-advisories.json does not accept with a reason and an in-date expiry.
291
+ # Self-skips when the guard is absent — a repo that did not adopt
292
+ # scripts/ci/check-dependency-audit.mjs is a no-op. deployments.md § Dependency updaters.
293
+ - name: Check Dependency Audit
294
+ if: steps.cache.outputs.skip != 'true' && hashFiles('scripts/ci/check-dependency-audit.mjs') != ''
295
+ run: node scripts/ci/check-dependency-audit.mjs
296
+
289
297
  # Capability-register freshness gate: rebuild the graph with graphify and fail when
290
298
  # docs/capabilities.md is not what this tree produces, so the register cannot drift
291
299
  # silently. Self-skips when the graphify wrapper is absent — a repo that did not adopt
@@ -868,6 +876,7 @@ jobs:
868
876
  # - name: Tear Down Base Worktree # if: always()
869
877
  # - name: Run bkit Check # [U] drift gate (same as pre-push); catches --no-verify/web-edit/cloud drift
870
878
  # - name: Check Accepted Divergences # [U] node scripts/ci/check-accepted-divergences.mjs — every event-keyed step is registered; stale rows fail too. testing.md § Accepted divergences.
879
+ # - name: Check Dependency Audit # [U] node scripts/ci/check-dependency-audit.mjs — high/critical advisories fail unless accepted with a reason + expiry. deployments.md § Dependency updaters.
871
880
  # - name: Pull Vercel Env Vars # [D] preview vs prod env by branch; set CI_ENV_FILE; FAIL-FAST if critical secrets empty
872
881
  # - name: Assert Environment Shape # [D] env-shape checker (e.g. env-check.sh)
873
882
  # # Resolve URL and remote db push are NOT steps in this catalogue.