hookset 0.2.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,8 +26,8 @@
26
26
  </p>
27
27
 
28
28
  <p align="center">
29
- Docs: <a href="https://burgee.interlace.tools/docs/packages/hookset">https://burgee.interlace.tools/docs/packages/hookset</a><br />
30
- Migrating from: <a href="https://github.com/ofri-peretz/burgee/tree/main/packages/hookset#migrating">husky</a>
29
+ Docs: <a href="https://hookset.interlace.tools">https://hookset.interlace.tools</a><br />
30
+ Migrating from: <a href="https://hookset.interlace.tools/docs/coming-from/husky">husky</a>
31
31
  </p>
32
32
 
33
33
  **hookset** puts the same verification stations in every repository: lefthook presets for
@@ -105,7 +105,7 @@ The switch is one command, `npx hookset init`, and husky's folder comes out:
105
105
  ```
106
106
 
107
107
  `npx hookset init` writes `lefthook.yml`; move each `.husky/<hook>` script into the
108
- `hook:staged` or `hook:verify` script its station calls, then delete `.husky/`.
108
+ `hook:provedone`, `hook:staged` or `hook:verify` script its station calls, then delete `.husky/`.
109
109
 
110
110
  ## Compatibility
111
111
 
@@ -181,13 +181,13 @@ keeps both true.
181
181
  | [bellpull](https://bellpull.interlace.tools/docs) | Subprocesses, and which executable actually ran | cross-spawn and which |
182
182
  | [controlroom](https://controlroom.interlace.tools/docs) | Keyboard-driven terminal screens, inline or full-screen | ink |
183
183
  | [oxmutate](https://oxmutate.interlace.tools/docs) | Mutation testing on the oxc engine, inside your own Vitest | Stryker |
184
- | [truepass](https://burgee.interlace.tools/docs/packages/truepass) | Lint rules and a pre-push check that keep a test suite honest | @vitest/eslint-plugin |
185
- | [contractdiff](https://burgee.interlace.tools/docs/packages/contractdiff) | API contracts: breaking-change diff, lint, and code from the spec | openapi-typescript |
186
- | [truefit](https://burgee.interlace.tools/docs/packages/truefit) | Validation whose schemas are data, with no eval | zod |
187
- | [provedone](https://burgee.interlace.tools/docs/packages/provedone) | A receipt for how every change was verified, and a gate that reads it | @commitlint/cli |
188
- | [replz](https://burgee.interlace.tools/docs/packages/replz) | Recall of a reviewer and its checks, replayed on bugs that shipped | promptfoo |
184
+ | [truepass](https://truepass.interlace.tools/docs) | Lint rules and a pre-push check that keep a test suite honest | @vitest/eslint-plugin |
185
+ | [contractdiff](https://contractdiff.interlace.tools/docs) | API contracts: breaking-change diff, lint, and code from the spec | openapi-typescript |
186
+ | [truefit](https://truefit.interlace.tools/docs) | Validation whose schemas are data, with no eval | zod |
187
+ | [provedone](https://provedone.interlace.tools/docs) | A receipt for how every change was verified, and a gate that reads it | @commitlint/cli |
188
+ | [replz](https://replz.interlace.tools/docs) | Recall of a reviewer and its checks, replayed on bugs that shipped | promptfoo |
189
189
  | **hookset** (this package) | The same git and Claude Code hooks in every repository, pinned by tag | husky |
190
- | [triggerlist](https://burgee.interlace.tools/docs/packages/triggerlist) | The review checklist a diff selects, read from the base branch | danger |
190
+ | [triggerlist](https://triggerlist.interlace.tools/docs) | The review checklist a diff selects, read from the base branch | danger |
191
191
 
192
192
  Every migration guide, and the family-wide [compatibility](https://burgee.interlace.tools/docs/compatibility)
193
193
  and [benchmarks](https://burgee.interlace.tools/docs/benchmarks) pages, are on
@@ -6,16 +6,22 @@
6
6
  // It replaces prose that every CLAUDE.md used to repeat. A rule an agent can break
7
7
  // with one command is a check, not a sentence: the denial below is the documentation.
8
8
  //
9
- // 1. Skipping git hooks (--no-verify, `git commit -n`, LEFTHOOK=0/HUSKY=0) — the hooks are the gate.
10
- // 2. Pointing git at other hooks (`git config core.hooksPath`, `git -c core.hooksPath=`).
11
- // 3. Hand-rolled CI polling (`until/while … gh … sleep`) — the harness kills those loops
12
- // and the turn ends knowing nothing. `gh pr checks <PR> --watch` blocks correctly.
13
- // 4. Asks (never denies) before a publish: `npm publish`, `changeset publish`, and the
14
- // commands the repo lists under `ask` in .claude/hookset.json (deploys, releases).
15
- // 5. Denies Edit/Write on a path matching a glob the repo lists under `frozen` there.
9
+ // 1. Skipping git hooks (--no-verify and its abbreviations, `git commit -n`, LEFTHOOK=0/HUSKY=0,
10
+ // also exported earlier in the same command) — the hooks are the gate.
11
+ // 2. Pointing git at other hooks (`git config core.hooksPath`, `git -c core.hooksPath=`,
12
+ // GIT_CONFIG_KEY_n=core.hooksPath) or removing them (`lefthook uninstall`, rm/mv/chmod .git/hooks).
13
+ // 3. Hand-rolled CI polling (`until/while/for … gh … sleep`, `watch … gh`) — the harness kills
14
+ // those loops and the turn ends knowing nothing. `gh pr checks <PR> --watch` blocks correctly.
15
+ // 4. Asks (never denies) before a publish: npm/pnpm/yarn/bun `publish`, `unpublish`, `deprecate`,
16
+ // `dist-tag add|rm`, `changeset publish`, `lerna publish`, and the commands the repo lists
17
+ // under `ask` in .claude/hookset.json (deploys, releases).
18
+ // 5. Denies Edit/Write on a path matching a glob the repo lists under `frozen` there, and on
19
+ // a generated file (`generated`: glob -> the command that writes it), naming that command.
16
20
  // 6. Denies `git commit` / `git push` run in the foreground under the default 2-minute
17
21
  // timeout: their hooks are the repo's gate and take minutes. The denial names the fix
18
22
  // (timeout 600000 or run_in_background), so no CLAUDE.md has to say "not a hang".
23
+ // 7. Asks before a push that rewrites or deletes remote history: --force, --force-with-lease,
24
+ // -f, +refspec, --delete, :refspec, --mirror, --prune.
19
25
  //
20
26
  // Matching is done on tokens, not regexes over the raw command: quoted strings and
21
27
  // heredoc bodies are data (commit messages, PR bodies), and no pattern here can backtrack.
@@ -131,7 +137,8 @@ function skipsHooks(words) {
131
137
  const env = words.slice(0, words.indexOf("git"));
132
138
  const sub = words[s];
133
139
  const args = words.slice(s + 1);
134
- if (args.includes("--no-verify")) return true;
140
+ // git takes any unambiguous prefix of a long option: `--no-veri` skips hooks like `--no-verify`.
141
+ if (args.some((a) => /^--no-veri(f|fy)?$/.test(a))) return true;
135
142
  if (
136
143
  sub === "commit" &&
137
144
  args.some((a) => /^-[a-zA-Z]+$/.test(a) && a.includes("n"))
@@ -141,8 +148,32 @@ function skipsHooks(words) {
141
148
  return offEnv && (sub === "commit" || sub === "push");
142
149
  }
143
150
 
144
- /** `git config [--global|--local] core.hooksPath x` or `git -c core.hooksPath=x …`. */
151
+ const HOOKS_OFF = /^(LEFTHOOK|HUSKY)=(0|false)$/;
152
+
153
+ /** `export LEFTHOOK=0; git push`: the variable outlives its own command, so any commit or push after it is unhooked. */
154
+ function hooksOffInShell(cmds) {
155
+ if (!cmds.some((w) => w.some((x) => HOOKS_OFF.test(x)))) return false;
156
+ return cmds.some((w) => {
157
+ const s = gitSub(w);
158
+ return s !== -1 && (w[s] === "commit" || w[s] === "push");
159
+ });
160
+ }
161
+
162
+ const HOOK_FILE_TOOLS = new Set(["rm", "mv", "chmod", "unlink", "truncate", "ln"]);
163
+
164
+ /** `lefthook uninstall`, `rm .git/hooks/pre-push`, `> .git/hooks/pre-commit`: the hooks are gone. */
165
+ function removesHooks(words) {
166
+ if (hasPhrase(words, "lefthook uninstall")) return true;
167
+ const inHooks = (w) => /(^|\/)\.git\/hooks(\/|$)/.test(w.replace(/^>+/, ""));
168
+ if (words.some((w, i) => inHooks(w) && (w.startsWith(">") || /^>+$/.test(words[i - 1] ?? "")))) return true;
169
+ const tool = words.findIndex((w) => HOOK_FILE_TOOLS.has(w.split("/").pop()));
170
+ return tool !== -1 && words.slice(tool + 1).some(inHooks);
171
+ }
172
+
173
+ /** `git config [--global|--local] core.hooksPath x`, `git -c core.hooksPath=x …`, `GIT_CONFIG_KEY_0=core.hooksPath`. */
145
174
  function movesHooks(words) {
175
+ if (words.some((w) => /^GIT_CONFIG_KEY_\d+=core\.hookspath$/i.test(w))) return true;
176
+ if (removesHooks(words)) return true;
146
177
  const g = words.indexOf("git");
147
178
  if (g === -1) return false;
148
179
  const rest = words.slice(g + 1);
@@ -161,32 +192,51 @@ function hasPhrase(words, phrase) {
161
192
  return false;
162
193
  }
163
194
 
164
- export const PUBLISH = ["npm publish", "pnpm publish", "yarn npm publish", "changeset publish"];
195
+ export const PUBLISH = ["npm publish", "pnpm publish", "yarn npm publish", "changeset publish", "lerna publish"];
196
+
197
+ const PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun"]);
198
+ /** Subcommands that change the registry for everyone: no later command takes them back. */
199
+ const REGISTRY_WRITES = new Set(["publish", "unpublish", "deprecate"]);
165
200
 
166
201
  /**
167
- * True when `words` runs `npm` or `pnpm` with `publish` as its subcommand after global options:
168
- * `npm --access=public publish`, `npm --registry https://r publish`. An option without `=`
169
- * may take the next word as its value, so that word is skipped unless it is `publish` itself.
202
+ * The registry write `words` runs, or null: npm, pnpm, yarn or bun (by any path, `/usr/bin/npm`)
203
+ * with `publish`, `unpublish`, `deprecate` or `dist-tag add|rm` as its subcommand, after global
204
+ * options: `npm --access=public publish`, `npm --registry https://r publish`. An option without `=`
205
+ * may take the next word as its value, so that word is skipped unless it is the subcommand itself.
170
206
  */
171
207
  function publishesAfterOptions(words) {
208
+ const isWrite = (k) => REGISTRY_WRITES.has(words[k]) || (words[k] === "dist-tag" && /^(add|rm)$/.test(words[k + 1] ?? ""));
172
209
  for (let i = 0; i < words.length; i++) {
173
- if (words[i] !== "npm" && words[i] !== "pnpm") continue;
210
+ const tool = words[i].split("/").pop();
211
+ if (!PACKAGE_MANAGERS.has(tool)) continue;
174
212
  let j = i + 1;
175
213
  while (j < words.length && words[j].startsWith("-")) {
176
214
  // Any option without `=` may take the next word as its value (`--registry url`, `-F pkg`).
177
215
  const valued = !words[j].includes("=");
178
216
  j++;
179
- if (valued && j < words.length && !words[j].startsWith("-") && words[j] !== "publish") j++;
217
+ if (valued && j < words.length && !words[j].startsWith("-") && !isWrite(j)) j++;
180
218
  }
181
- if (words[j] === "publish") return `${words[i]} publish`;
219
+ if (isWrite(j)) return `${tool} ${words[j]}${words[j] === "dist-tag" ? ` ${words[j + 1]}` : ""}`;
182
220
  }
183
221
  return null;
184
222
  }
185
223
 
224
+ /** True when `words` is a `git push` that rewrites or deletes history on the remote. */
225
+ function forcePushes(words) {
226
+ const s = gitSub(words);
227
+ if (s === -1 || words[s] !== "push") return false;
228
+ return words.slice(s + 1).some(
229
+ (a) =>
230
+ /^--(force|force-with-lease|mirror|delete|prune)(=.*)?$/.test(a) ||
231
+ (/^-[a-zA-Z]+$/.test(a) && /[fd]/.test(a)) ||
232
+ /^[+:]./.test(a),
233
+ );
234
+ }
235
+
186
236
  const RULES = [
187
237
  {
188
238
  id: "no-verify",
189
- test: (cmds) => cmds.some(skipsHooks),
239
+ test: (cmds) => cmds.some(skipsHooks) || hooksOffInShell(cmds),
190
240
  reason:
191
241
  "Git hooks are this repo's gate: never skip them (--no-verify, commit -n, LEFTHOOK=0). " +
192
242
  "If a hook fails, fix what it reports. If it is slow, wait: commit/push hooks can take 3–4 minutes, " +
@@ -196,15 +246,16 @@ const RULES = [
196
246
  id: "hooks-path",
197
247
  test: (cmds) => cmds.some(movesHooks),
198
248
  reason:
199
- "Do not point git at other hooks (core.hooksPath): lefthook installed this repo's hooks and they are the gate. " +
249
+ "Do not point git at other hooks (core.hooksPath) or remove them (lefthook uninstall, .git/hooks): lefthook installed this repo's hooks and they are the gate. " +
200
250
  "If a hook is wrong, fix lefthook.yml or the hookset preset in a PR.",
201
251
  },
202
252
  {
203
253
  id: "ci-poll-loop",
204
254
  test: (cmds) => {
205
255
  const all = cmds.flat();
256
+ if (cmds.some((w) => w[0] === "watch" && w.includes("gh"))) return true;
206
257
  return (
207
- (all.includes("until") || all.includes("while")) &&
258
+ (all.includes("until") || all.includes("while") || all.includes("for")) &&
208
259
  all.includes("gh") &&
209
260
  all.includes("sleep")
210
261
  );
@@ -231,7 +282,15 @@ export function decide(command, ask = []) {
231
282
  return {
232
283
  decision: "ask",
233
284
  id: "publish",
234
- reason: `\`${phrase}\` publishes or deploys outside this repo, and that cannot be undone. A person approves it; CI release workflows are the usual route.`,
285
+ reason: `\`${phrase}\` changes the package registry outside this repo, and that cannot be undone. A person approves it; CI release workflows are the usual route.`,
286
+ };
287
+ if (cmds.some(forcePushes))
288
+ return {
289
+ decision: "ask",
290
+ id: "force-push",
291
+ reason:
292
+ "This push rewrites or deletes history on the remote, which other sessions and reviewers may have built on. A person approves it. " +
293
+ "If a push was rejected because the remote has commits you lack, merge them instead: `git fetch origin <branch> && git merge --no-edit FETCH_HEAD`.",
235
294
  };
236
295
  const listed = ask.find((p) => cmds.some((w) => hasPhrase(w, p)));
237
296
  if (listed)
@@ -271,24 +330,23 @@ export function decideHooked(command, { timeout, run_in_background } = {}) {
271
330
  }
272
331
 
273
332
  /** `*` within a segment, `**` across segments, `?` one character. Paths use forward slashes. */
333
+ const GLOB_TOKEN = /\*\*\/|\*\*|\*|\?|[.+^${}()|[\]\\]/g;
334
+ const GLOB_PART = { "**/": "(?:.*/)?", "**": ".*", "*": "[^/]*", "?": "[^/]" };
274
335
  export function globToRegExp(glob) {
275
- let re = "";
276
- for (let i = 0; i < glob.length; i++) {
277
- const ch = glob[i];
278
- if (ch === "*" && glob[i + 1] === "*") {
279
- re += glob[i + 2] === "/" ? "(?:.*/)?" : ".*";
280
- i += glob[i + 2] === "/" ? 2 : 1;
281
- } else if (ch === "*") re += "[^/]*";
282
- else if (ch === "?") re += "[^/]";
283
- else re += /[.+^${}()|[\]\\]/.test(ch) ? `\\${ch}` : ch;
284
- }
285
- return new RegExp(`^${re}$`);
336
+ return new RegExp(`^${glob.replace(GLOB_TOKEN, (token) => GLOB_PART[token] ?? `\\${token}`)}$`);
286
337
  }
287
338
 
288
339
  /** The verdict for an Edit/Write on `file` (relative to the repo), or null. */
289
- export function decideEdit(file, frozen = []) {
340
+ export function decideEdit(file, frozen = [], generated = {}) {
290
341
  // posix.normalize folds `a/../b` and `./a`, so a dotted path cannot step around a frozen glob.
291
342
  const rel = posix.normalize(String(file ?? "").replaceAll("\\", "/")).replace(/^\.\//, "");
343
+ const made = Object.entries(generated).find(([g]) => globToRegExp(g).test(rel));
344
+ if (made)
345
+ return {
346
+ decision: "deny",
347
+ id: "generated",
348
+ reason: `${rel} is generated (\`${made[0]}\` in .claude/hookset.json). Edit its source, then run \`${made[1]}\`.`,
349
+ };
292
350
  const hit = frozen.find((g) => globToRegExp(g).test(rel));
293
351
  return hit
294
352
  ? {
@@ -320,6 +378,21 @@ export const CASES = {
320
378
  "until gh pr view 5 --json state | grep MERGED; do sleep 30; done",
321
379
  "while true; do gh run list; sleep 10; done",
322
380
  "until gh workflow view ci; do sleep 5; done",
381
+ "git push --no-veri origin x",
382
+ "git commit --no-verif -m x",
383
+ "export LEFTHOOK=0; git push",
384
+ "LEFTHOOK=0\ngit commit -m x",
385
+ "export HUSKY=false && git -C . commit -m x",
386
+ "lefthook uninstall",
387
+ "npx lefthook uninstall",
388
+ "rm .git/hooks/pre-push",
389
+ "rm -f /repo/.git/hooks/pre-commit",
390
+ "chmod -x .git/hooks/pre-commit",
391
+ "mv .git/hooks .git/hooks.off",
392
+ "echo > .git/hooks/pre-push",
393
+ "GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.hooksPath GIT_CONFIG_VALUE_0=/dev/null git push",
394
+ "for i in 1 2 3; do gh pr checks 5; sleep 30; done",
395
+ "watch -n 30 gh pr checks 5",
323
396
  ],
324
397
  allow: [
325
398
  'git commit -m "docs: explain why --no-verify is banned"',
@@ -335,6 +408,16 @@ export const CASES = {
335
408
  "git log -n 3",
336
409
  "git config --get core.hooksPath",
337
410
  'echo "npm publish" > notes.txt',
411
+ 'git commit -m "never use --no-veri"',
412
+ "cat .git/hooks/pre-push",
413
+ "ls .git/hooks",
414
+ "git push -u origin feature",
415
+ "git push origin HEAD:refs/heads/feature",
416
+ "npm view pkg dist-tags",
417
+ "npm dist-tag ls pkg",
418
+ "npm run publish:dry",
419
+ "for f in a b; do echo $f; done",
420
+ "LEFTHOOK=0 npm ci && git status",
338
421
  ],
339
422
  ask: [
340
423
  "npm publish --access public",
@@ -345,8 +428,24 @@ export const CASES = {
345
428
  "pnpm --filter pkg publish",
346
429
  "pnpm -F pkg publish",
347
430
  "npm -g publish",
431
+ "yarn publish",
432
+ "bun publish",
433
+ "/usr/local/bin/npm publish",
434
+ "npm unpublish pkg@1.0.0",
435
+ "pnpm deprecate pkg@1 old",
436
+ "npm dist-tag add pkg@1.0.0 latest",
437
+ "npx lerna publish from-package",
438
+ "git push --force origin main",
439
+ "git push -f",
440
+ "git push -uf origin x",
441
+ "git push origin +main",
442
+ "git push --force-with-lease=main origin main",
443
+ "git push origin :main",
444
+ "git push --delete origin x",
445
+ "git push -d origin x",
446
+ "git push --mirror",
348
447
  ],
349
- // decideHooked: [command, Bash input, denied?]
448
+ // decideHooked cases: the command, its Bash input, and whether it is denied.
350
449
  hooked: [
351
450
  ["git push origin main", {}, true],
352
451
  ["git -C repo commit -m x", { timeout: 120000 }, true],
@@ -359,8 +458,18 @@ export const CASES = {
359
458
  ["git commit -F - <<'EOF'\nx\nEOF", { timeout: 300000 }, false],
360
459
  ["echo 'git push'", {}, false],
361
460
  ],
461
+ // decideEdit: [path, denied as] against EDIT_CONFIG.
462
+ edit: [
463
+ ["content/a/b.md", "frozen"],
464
+ ["./docs/../content/a.md", "frozen"],
465
+ ["public/r/button.json", "generated"],
466
+ ["public/r/../r/x.json", "generated"],
467
+ ["src/button.tsx", null],
468
+ ],
362
469
  };
363
470
 
471
+ const EDIT_CONFIG = { frozen: ["content/**/*.md"], generated: { "public/r/**": "npm run registry:build" } };
472
+
364
473
  function selfTest() {
365
474
  const bad = [
366
475
  ...CASES.deny.filter((c) => decide(c)?.decision !== "deny").map((c) => `should deny: ${c}`),
@@ -369,16 +478,19 @@ function selfTest() {
369
478
  ...CASES.hooked
370
479
  .filter(([c, input, denied]) => Boolean(decideHooked(c, input)) !== denied)
371
480
  .map(([c, input, denied]) => `should ${denied ? "deny" : "allow"} ${JSON.stringify(input)}: ${c}`),
481
+ ...CASES.edit
482
+ .filter(([f, id]) => (decideEdit(f, EDIT_CONFIG.frozen, EDIT_CONFIG.generated)?.id ?? null) !== id)
483
+ .map(([f, id]) => `should ${id ? `deny as ${id}` : "allow"}: edit ${f}`),
372
484
  ];
373
485
  process.stdout.write(
374
486
  bad.length
375
487
  ? `${bad.join("\n")}\n${bad.length} failing\n`
376
- : `ok: ${CASES.deny.length} denied, ${CASES.allow.length} allowed, ${CASES.ask.length} asked, ${CASES.hooked.length} timed\n`,
488
+ : `ok: ${CASES.deny.length} denied, ${CASES.allow.length} allowed, ${CASES.ask.length} asked, ${CASES.hooked.length} timed, ${CASES.edit.length} edits\n`,
377
489
  );
378
490
  process.exit(bad.length ? 1 : 0);
379
491
  }
380
492
 
381
- /** The repo's `.claude/hookset.json`: `{ "ask": [phrases], "frozen": [globs] }`. Missing is empty. */
493
+ /** The repo's `.claude/hookset.json`: `{ "ask": [phrases], "frozen": [globs], "generated": { glob: command } }`. Missing is empty. */
382
494
  async function repoConfig() {
383
495
  const { readFile } = await import("node:fs/promises");
384
496
  const dir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
@@ -388,9 +500,13 @@ async function repoConfig() {
388
500
  dir,
389
501
  ask: Array.isArray(c.ask) ? c.ask.map(String) : [],
390
502
  frozen: Array.isArray(c.frozen) ? c.frozen.map(String) : [],
503
+ generated:
504
+ c.generated && typeof c.generated === "object" && !Array.isArray(c.generated)
505
+ ? Object.fromEntries(Object.entries(c.generated).map(([g, cmd]) => [g, String(cmd)]))
506
+ : {},
391
507
  };
392
508
  } catch {
393
- return { dir, ask: [], frozen: [] };
509
+ return { dir, ask: [], frozen: [], generated: {} };
394
510
  }
395
511
  }
396
512
 
@@ -418,7 +534,7 @@ else if (isMain) {
418
534
  // Windows hands both paths over with backslashes: compare them with forward slashes.
419
535
  const [f, d] = [file, config.dir].map((p) => posix.normalize(p.replaceAll("\\", "/")));
420
536
  const rel = f.startsWith(`${d}/`) ? f.slice(d.length + 1) : f;
421
- hit = decideEdit(rel, config.frozen);
537
+ hit = decideEdit(rel, config.frozen, config.generated);
422
538
  }
423
539
  }
424
540
  if (!hit) process.exit(0);
package/dist/core.js CHANGED
@@ -31,16 +31,18 @@ const listItem = (text) => (text.startsWith('- ') ? text.slice(2).trim() : undef
31
31
  const stripComment = (line) => String(line.split(' #', 1)[0]).trim();
32
32
  const REMOTE_KEYS = new Set(['git_url', 'ref', 'configs', 'refetch', 'refetch_frequency']);
33
33
  export function parseRemotes(yaml) {
34
- const lines = yaml.split(/\r?\n/);
34
+ return scanRemotes(yaml.split(/\r?\n/)).map(({ refAt: _, ...remote }) => remote);
35
+ }
36
+ function scanRemotes(lines) {
35
37
  const block = topBlock(lines, 'remotes');
36
38
  if (!block)
37
39
  return [];
38
40
  const state = { remotes: [], inConfigs: false };
39
- for (const raw of lines.slice(block.from + 1, block.to))
40
- remoteLine(state, stripComment(raw));
41
+ const from = block.from + 1;
42
+ lines.slice(from, block.to).forEach((raw, i) => remoteLine(state, stripComment(raw), from + i));
41
43
  return state.remotes;
42
44
  }
43
- function remoteLine(state, text) {
45
+ function remoteLine(state, text, at) {
44
46
  const item = listItem(text);
45
47
  const pair = keyValue(item ?? text);
46
48
  const isKey = pair !== undefined && (item === undefined || REMOTE_KEYS.has(pair[0]));
@@ -51,6 +53,8 @@ function remoteLine(state, text) {
51
53
  return;
52
54
  if (isKey) {
53
55
  state.inConfigs = pair[0] === 'configs';
56
+ if (pair[0] === 'ref')
57
+ current.refAt = at;
54
58
  assign(current, pair[0], pair[1]);
55
59
  }
56
60
  else if (item !== undefined && state.inConfigs)
@@ -254,21 +258,20 @@ function nextLefthook(repo, stations, ref, force) {
254
258
  return { text: lefthookTemplate(stations, ref) };
255
259
  const yaml = readText(file);
256
260
  if (parseRemotes(yaml).some((r) => sameRemote(r.gitUrl, stations.remote)))
257
- return { text: repin(yaml, ref) };
261
+ return { text: repin(yaml, ref, stations.remote) };
258
262
  if (yaml.split(/\r?\n/).some((l) => l.startsWith('remotes:')))
259
263
  return { refused: 'lefthook.yml already has a remotes: block; add the hookset remote to it by hand' };
260
264
  if (!force)
261
265
  return { refused: 'lefthook.yml was written by hand; pass --force to add the presets on top of it' };
262
266
  return { text: `${remotesBlock(stations, ref)}\n${yaml}` };
263
267
  }
264
- function repin(yaml, ref) {
268
+ function repin(yaml, ref, remote) {
265
269
  const eol = yaml.includes('\r\n') ? '\r\n' : '\n';
266
270
  const lines = yaml.split(/\r?\n/);
267
- const block = topBlock(lines, 'remotes');
268
- const at = lines.findIndex((l, i) => block !== undefined && i > block.from && i < block.to && keyValue(listItem(l.trim()) ?? l.trim())?.[0] === 'ref');
269
- const line = lines[at];
270
- if (line === undefined)
271
+ const at = scanRemotes(lines).find((r) => sameRemote(r.gitUrl, remote)).refAt;
272
+ if (at === undefined)
271
273
  return yaml;
274
+ const line = String(lines[at]);
272
275
  lines.splice(at, 1, `${line.slice(0, line.indexOf('ref:'))}ref: ${ref}`);
273
276
  return lines.join(eol);
274
277
  }
@@ -292,8 +295,18 @@ function mergeSettings(repo, stations) {
292
295
  settings.hooks = Object.fromEntries(events);
293
296
  return `${JSON.stringify(settings, undefined, 2)}\n`;
294
297
  }
298
+ function tally(problems) {
299
+ const counts = [];
300
+ for (const severity of ['error', 'warning']) {
301
+ const n = problems.filter((p) => p.severity === severity).length;
302
+ const plural = n === 1 ? '' : 's';
303
+ if (n > 0)
304
+ counts.push(`${String(n)} ${severity}${plural}`);
305
+ }
306
+ return counts.join(', ');
307
+ }
295
308
  export function checkText(result) {
296
309
  const lines = result.problems.map((p) => `${p.severity === 'error' ? '✗' : '!'} ${p.message}\n fix: ${p.fix}`);
297
- const head = result.ok ? `hookset: ok (${result.pinned ?? 'unpinned'})` : `hookset: ${String(result.problems.filter((p) => p.severity === 'error').length)} problem(s)`;
310
+ const head = result.ok ? `hookset: ok (${result.pinned ?? 'unpinned'})` : `hookset: ${tally(result.problems)}`;
298
311
  return [head, ...lines].join('\n');
299
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hookset",
3
- "version": "0.2.2",
3
+ "version": "1.0.1",
4
4
  "private": false,
5
5
  "description": "Git hooks presets for AI coding agents: lefthook presets pulled by a pinned tag, a Claude Code hook pack that denies skipped hooks, and `hookset init` and `check`. No dependency outside the burgee family. A husky migration path.",
6
6
  "keywords": [
@@ -15,7 +15,7 @@
15
15
  "cli"
16
16
  ],
17
17
  "license": "MIT",
18
- "homepage": "https://burgee.interlace.tools",
18
+ "homepage": "https://hookset.interlace.tools",
19
19
  "repository": {
20
20
  "type": "git",
21
21
  "url": "git+https://github.com/ofri-peretz/burgee.git",
@@ -54,10 +54,10 @@
54
54
  "typecheck": "tsc -p tsconfig.json --noEmit",
55
55
  "test": "vitest run",
56
56
  "coverage": "vitest run --coverage.enabled",
57
- "lint": "eslint src"
57
+ "lint": "cd ../.. && eslint packages/hookset/src --max-warnings 0"
58
58
  },
59
59
  "dependencies": {
60
- "burgee": "^2.1.3"
60
+ "burgee": "^2.2.2"
61
61
  },
62
62
  "devDependencies": {
63
63
  "vitest": "^5.0.1"
@@ -5,4 +5,7 @@ commit-msg:
5
5
  commands:
6
6
  hookset-commitlint:
7
7
  run: PATH="$PATH:/opt/homebrew/bin:/usr/local/bin" npx --no -- commitlint --edit {1}
8
- fail_text: "The message must be <type>(<scope>): <subject>, with a scope from commitlint.config. Fix it and commit again."
8
+ fail_text: "commitlint rejected the message. Each ✖ line above names the rule it broke (type, scope, length). Fix those and commit again."
9
+ hookset-provedone:
10
+ run: PATH="$PATH:/opt/homebrew/bin:/usr/local/bin" npm run --silent hook:provedone -- {1}
11
+ fail_text: "No receipt. Add `Verified-by: <command> -> exit 0`, or `Verified-by: none (<why no check applies>)`, and commit again."
package/stations.json CHANGED
@@ -9,6 +9,7 @@
9
9
  },
10
10
  "stations": [
11
11
  { "id": "commitlint", "hook": "commit-msg", "mode": "enforce", "command": "hookset-commitlint", "detail": "the message follows the repo's commitlint config" },
12
+ { "id": "provedone", "hook": "commit-msg", "mode": "enforce", "command": "hookset-provedone", "script": "hook:provedone", "detail": "the commit carries a Verified-by receipt, or none with a reason" },
12
13
  { "id": "staged", "hook": "pre-commit", "mode": "enforce", "command": "hookset-staged", "script": "hook:staged", "detail": "lint and format the staged files only, under 10 s" },
13
14
  { "id": "verify", "hook": "pre-push", "mode": "enforce", "command": "hookset-verify", "script": "hook:verify", "detail": "typecheck, the affected tests and the build" },
14
15
  { "id": "mutation", "hook": "pre-push", "mode": "optional", "command": "hookset-mutation", "script": "hook:mutation", "detail": "changed-lines mutation testing" },