hookset 1.0.0 → 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
@@ -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
@@ -165,7 +165,7 @@ const HOOK_FILE_TOOLS = new Set(["rm", "mv", "chmod", "unlink", "truncate", "ln"
165
165
  function removesHooks(words) {
166
166
  if (hasPhrase(words, "lefthook uninstall")) return true;
167
167
  const inHooks = (w) => /(^|\/)\.git\/hooks(\/|$)/.test(w.replace(/^>+/, ""));
168
- if (words.some((w, i) => inHooks(w) && (/^>/.test(w) || /^>+$/.test(words[i - 1] ?? "")))) return true;
168
+ if (words.some((w, i) => inHooks(w) && (w.startsWith(">") || /^>+$/.test(words[i - 1] ?? "")))) return true;
169
169
  const tool = words.findIndex((w) => HOOK_FILE_TOOLS.has(w.split("/").pop()));
170
170
  return tool !== -1 && words.slice(tool + 1).some(inHooks);
171
171
  }
@@ -330,18 +330,10 @@ export function decideHooked(command, { timeout, run_in_background } = {}) {
330
330
  }
331
331
 
332
332
  /** `*` within a segment, `**` across segments, `?` one character. Paths use forward slashes. */
333
+ const GLOB_TOKEN = /\*\*\/|\*\*|\*|\?|[.+^${}()|[\]\\]/g;
334
+ const GLOB_PART = { "**/": "(?:.*/)?", "**": ".*", "*": "[^/]*", "?": "[^/]" };
333
335
  export function globToRegExp(glob) {
334
- let re = "";
335
- for (let i = 0; i < glob.length; i++) {
336
- const ch = glob[i];
337
- if (ch === "*" && glob[i + 1] === "*") {
338
- re += glob[i + 2] === "/" ? "(?:.*/)?" : ".*";
339
- i += glob[i + 2] === "/" ? 2 : 1;
340
- } else if (ch === "*") re += "[^/]*";
341
- else if (ch === "?") re += "[^/]";
342
- else re += /[.+^${}()|[\]\\]/.test(ch) ? `\\${ch}` : ch;
343
- }
344
- return new RegExp(`^${re}$`);
336
+ return new RegExp(`^${glob.replace(GLOB_TOKEN, (token) => GLOB_PART[token] ?? `\\${token}`)}$`);
345
337
  }
346
338
 
347
339
  /** The verdict for an Edit/Write on `file` (relative to the repo), or null. */
@@ -453,7 +445,7 @@ export const CASES = {
453
445
  "git push -d origin x",
454
446
  "git push --mirror",
455
447
  ],
456
- // decideHooked: [command, Bash input, denied?]
448
+ // decideHooked cases: the command, its Bash input, and whether it is denied.
457
449
  hooked: [
458
450
  ["git push origin main", {}, true],
459
451
  ["git -C repo commit -m x", { timeout: 120000 }, true],
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": "1.0.0",
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,7 +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
9
  hookset-provedone:
10
10
  run: PATH="$PATH:/opt/homebrew/bin:/usr/local/bin" npm run --silent hook:provedone -- {1}
11
11
  fail_text: "No receipt. Add `Verified-by: <command> -> exit 0`, or `Verified-by: none (<why no check applies>)`, and commit again."