hookset 1.1.0 → 1.2.0
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/claude/codegraph.mjs +90 -0
- package/claude/verify-before-stop.mjs +85 -14
- package/dist/context.js +24 -3
- package/dist/core.d.ts +22 -0
- package/dist/core.js +40 -0
- package/package.json +1 -1
- package/stations.json +19 -2
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// codegraph — Claude Code SessionStart hook. Canonical copy: burgee packages/hookset/claude/.
|
|
3
|
+
// `hookset init --claude` vendors it next to guard-bash.mjs.
|
|
4
|
+
//
|
|
5
|
+
// A repo whose .mcp.json runs the CodeGraph MCP server answers "where is X, what calls it, how
|
|
6
|
+
// does A reach B" from a prebuilt symbol graph in one codegraph_explore call, where grep takes a
|
|
7
|
+
// search, a read and a re-search. The server never builds its own index, and a cloud session
|
|
8
|
+
// starts from a fresh clone without one, so the tool would answer "not indexed" every time. This
|
|
9
|
+
// starts `codegraph init` (or `sync`, when an index is there) in the background so the session is
|
|
10
|
+
// not held for it; the server picks the index up when it lands.
|
|
11
|
+
//
|
|
12
|
+
// Denying a symbol-shaped grep once was tried and measured on burgee: it added tool calls and did
|
|
13
|
+
// not cut greps, so the hook only builds the index.
|
|
14
|
+
//
|
|
15
|
+
// It does nothing in a repo with no codegraph server in .mcp.json, or with HOOKSET_CODEGRAPH=0.
|
|
16
|
+
// `node codegraph.mjs --self-test` runs the cases at the bottom.
|
|
17
|
+
|
|
18
|
+
import { spawn } from "node:child_process";
|
|
19
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
20
|
+
import { tmpdir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
|
|
23
|
+
/** The npm spec the repo's .mcp.json runs (`@colbymchenry/codegraph@1.6.4`), or null when it runs none. */
|
|
24
|
+
export function serverSpec(dir) {
|
|
25
|
+
try {
|
|
26
|
+
const server = JSON.parse(readFileSync(join(dir, ".mcp.json"), "utf8"))?.mcpServers?.codegraph;
|
|
27
|
+
return (server?.args ?? []).find((a) => typeof a === "string" && /(^|\/)codegraph@[^/]+$/.test(a)) ?? null;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The npx arguments that bring the index up to date: build it on a fresh clone, catch it up otherwise. */
|
|
34
|
+
export function indexArgs(dir, spec) {
|
|
35
|
+
const indexed = existsSync(join(dir, ".codegraph", "codegraph.db"));
|
|
36
|
+
return ["-y", spec, ...(indexed ? ["sync"] : ["init", "--yes"]), dir];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function startIndex(dir, spec) {
|
|
40
|
+
const env = { ...process.env, CODEGRAPH_TELEMETRY: "0" };
|
|
41
|
+
const windows = process.platform === "win32";
|
|
42
|
+
const child = spawn(windows ? "npx.cmd" : "npx", indexArgs(dir, spec), { cwd: dir, env, detached: true, stdio: "ignore", shell: windows });
|
|
43
|
+
child.on("error", () => {});
|
|
44
|
+
child.unref();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const CASES = {
|
|
48
|
+
specs: {
|
|
49
|
+
'{"mcpServers":{"codegraph":{"args":["-y","@colbymchenry/codegraph@1.6.4","serve","--mcp"]}}}': "@colbymchenry/codegraph@1.6.4",
|
|
50
|
+
'{"mcpServers":{"codegraph":{"command":"codegraph","args":["serve","--mcp"]}}}': null,
|
|
51
|
+
'{"mcpServers":{"other":{"args":["-y","@colbymchenry/codegraph@1.6.4"]}}}': null,
|
|
52
|
+
"not json": null,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function selfTest() {
|
|
57
|
+
const bad = [];
|
|
58
|
+
for (const [json, want] of Object.entries(CASES.specs)) {
|
|
59
|
+
const dir = mkdtempSync(join(tmpdir(), "codegraph-"));
|
|
60
|
+
writeFileSync(join(dir, ".mcp.json"), json);
|
|
61
|
+
if (serverSpec(dir) !== want) bad.push(`spec of ${json}: want ${want}, got ${serverSpec(dir)}`);
|
|
62
|
+
}
|
|
63
|
+
const dir = mkdtempSync(join(tmpdir(), "codegraph-"));
|
|
64
|
+
if (indexArgs(dir, "x@1").join(" ") !== `-y x@1 init --yes ${dir}`) bad.push("a fresh clone should init");
|
|
65
|
+
mkdirSync(join(dir, ".codegraph"));
|
|
66
|
+
writeFileSync(join(dir, ".codegraph", "codegraph.db"), "");
|
|
67
|
+
if (indexArgs(dir, "x@1").join(" ") !== `-y x@1 sync ${dir}`) bad.push("an indexed repo should sync");
|
|
68
|
+
if (serverSpec(join(dir, "missing")) !== null) bad.push("no .mcp.json should be null");
|
|
69
|
+
process.stdout.write(bad.length ? `${bad.join("\n")}\n${bad.length} failing\n` : `ok: ${Object.keys(CASES.specs).length + 3} cases\n`);
|
|
70
|
+
process.exit(bad.length ? 1 : 0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const isMain = Boolean(process.argv[1]) && import.meta.url.endsWith(`/${process.argv[1].split(/[\\/]/).pop()}`);
|
|
74
|
+
if (isMain && process.argv.includes("--self-test")) selfTest();
|
|
75
|
+
else if (isMain) {
|
|
76
|
+
let raw = "";
|
|
77
|
+
process.stdin.on("data", (d) => (raw += d));
|
|
78
|
+
process.stdin.on("end", () => {
|
|
79
|
+
let payload;
|
|
80
|
+
try {
|
|
81
|
+
payload = JSON.parse(raw) ?? {};
|
|
82
|
+
} catch {
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
if (process.env.HOOKSET_CODEGRAPH === "0" || payload.hook_event_name !== "SessionStart") process.exit(0);
|
|
86
|
+
const dir = process.env.CLAUDE_PROJECT_DIR || payload.cwd || process.cwd();
|
|
87
|
+
const spec = serverSpec(dir);
|
|
88
|
+
if (spec) startIndex(dir, spec);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -29,12 +29,15 @@ import {
|
|
|
29
29
|
import { tmpdir } from "node:os";
|
|
30
30
|
import { join } from "node:path";
|
|
31
31
|
|
|
32
|
-
import { globToRegExp } from "./guard-bash.mjs";
|
|
32
|
+
import { commands, globToRegExp } from "./guard-bash.mjs";
|
|
33
33
|
import { isTestCommand } from "./stop-after-3.mjs";
|
|
34
34
|
|
|
35
35
|
const DOCS = /\.(md|mdx|txt)$/i;
|
|
36
36
|
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* The uncommitted paths `git status` lists, staged, unstaged and untracked, relative to the repo
|
|
39
|
+
* root. A rename lists both sides, so code renamed to a doc still counts; a copy only its new path.
|
|
40
|
+
*/
|
|
38
41
|
export function changedPaths(dir) {
|
|
39
42
|
const r = spawnSync(
|
|
40
43
|
"git",
|
|
@@ -47,7 +50,8 @@ export function changedPaths(dir) {
|
|
|
47
50
|
for (let i = 0; i < parts.length; i++) {
|
|
48
51
|
const entry = parts[i];
|
|
49
52
|
paths.push(entry.slice(3));
|
|
50
|
-
// A rename or copy is followed by its old path
|
|
53
|
+
// A rename or copy is followed by its old path. A rename removed it; a copy left it as it was.
|
|
54
|
+
if (entry[0] === "R" && parts[i + 1]) paths.push(parts[i + 1]);
|
|
51
55
|
if (entry[0] === "R" || entry[0] === "C") i++;
|
|
52
56
|
}
|
|
53
57
|
return paths;
|
|
@@ -59,8 +63,18 @@ export function counts(path, ignore = []) {
|
|
|
59
63
|
return !DOCS.test(rel) && !ignore.some((g) => globToRegExp(g).test(rel));
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
/** The work tree's root, so a hook whose cwd is a package still reads root-relative paths. */
|
|
67
|
+
function rootOf(dir) {
|
|
68
|
+
const r = spawnSync("git", ["rev-parse", "--show-toplevel"], {
|
|
69
|
+
cwd: dir,
|
|
70
|
+
encoding: "utf8",
|
|
71
|
+
});
|
|
72
|
+
return r.status === 0 && r.stdout.trim() ? r.stdout.trim() : dir;
|
|
73
|
+
}
|
|
74
|
+
|
|
62
75
|
/** One hash over every uncommitted code path and its content, or null when there is none. */
|
|
63
|
-
export function fingerprint(
|
|
76
|
+
export function fingerprint(cwd, ignore = []) {
|
|
77
|
+
const dir = rootOf(cwd);
|
|
64
78
|
const paths = changedPaths(dir)
|
|
65
79
|
.filter((p) => counts(p, ignore))
|
|
66
80
|
.sort();
|
|
@@ -93,9 +107,33 @@ function passedHash(session) {
|
|
|
93
107
|
}
|
|
94
108
|
}
|
|
95
109
|
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
/**
|
|
111
|
+
* True when the shell's exit status is the test run's own: the test is the last command and no
|
|
112
|
+
* `|`, `||`, `;` or `&` can hide its failure or run an edit after it. `cd pkg && npx vitest run`
|
|
113
|
+
* proves a pass; `npm test || true`, `npm test | tail` and `npm test && sed -i … a.ts` do not.
|
|
114
|
+
*/
|
|
115
|
+
export function provesPass(command) {
|
|
116
|
+
// `2>&1` merges streams; its `&` is not a background launch.
|
|
117
|
+
const merged = String(command).replace(/\d*>&\d+/g, " ");
|
|
118
|
+
const bare = merged
|
|
119
|
+
.replace(/'[^']*'|"(?:\\.|[^"\\])*"/g, '""')
|
|
120
|
+
.replaceAll("&&", " ");
|
|
121
|
+
if (/[|;&\n]/.test(bare)) return false;
|
|
122
|
+
const last = commands(merged).at(-1);
|
|
123
|
+
return Boolean(last) && isTestCommand(last.join(" "));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* PostToolUse: a passing foreground test run (`{ command, failed, background }`) remembers what
|
|
128
|
+
* the code looked like. A background launch returns before its tests finish. Prints nothing.
|
|
129
|
+
*/
|
|
130
|
+
export function recordPass(
|
|
131
|
+
session,
|
|
132
|
+
dir,
|
|
133
|
+
{ command, failed, background = false },
|
|
134
|
+
ignore = [],
|
|
135
|
+
) {
|
|
136
|
+
if (failed || background || !provesPass(command)) return;
|
|
99
137
|
const fp = fingerprint(dir, ignore);
|
|
100
138
|
// A pass with nothing uncommitted proves the committed tree; forget any older fingerprint.
|
|
101
139
|
if (fp) writeFileSync(stateFile(session), JSON.stringify({ hash: fp.hash }));
|
|
@@ -114,7 +152,7 @@ export function decideStop(session, dir, active, ignore = []) {
|
|
|
114
152
|
decision: "block",
|
|
115
153
|
reason:
|
|
116
154
|
`[verify-before-stop] Code changed since the last passing test run (${shown}). ` +
|
|
117
|
-
"Run the tests that cover it, or the repo's verify skill, and say what passed. " +
|
|
155
|
+
"Run the tests that cover it, or the repo's verify skill, in the foreground as the last command with no pipe, `||`, `;` or `&` after it, and say what passed. " +
|
|
118
156
|
"If they cannot run yet (you need an answer first), say that in your reply and end the turn; this hook will not stop you twice.",
|
|
119
157
|
};
|
|
120
158
|
}
|
|
@@ -176,22 +214,52 @@ function selfTest() {
|
|
|
176
214
|
bad.push("the second stop of a turn should always pass");
|
|
177
215
|
if (decideStop(session, dir, false, ["*.ts"]))
|
|
178
216
|
bad.push("a verifyIgnore glob should not count");
|
|
179
|
-
recordPass(session, dir, "npm run build", false);
|
|
217
|
+
recordPass(session, dir, { command: "npm run build", failed: false });
|
|
180
218
|
if (!decideStop(session, dir, false)) bad.push("a build is not a test run");
|
|
181
|
-
recordPass(session, dir, "npx vitest run", true);
|
|
219
|
+
recordPass(session, dir, { command: "npx vitest run", failed: true });
|
|
182
220
|
if (!decideStop(session, dir, false))
|
|
183
221
|
bad.push("a failing test run is not a pass");
|
|
184
|
-
recordPass(session, dir, "npx vitest run", false);
|
|
222
|
+
recordPass(session, dir, { command: "npx vitest run", failed: false });
|
|
185
223
|
if (decideStop(session, dir, false))
|
|
186
224
|
bad.push("a passing run over this code should end the turn");
|
|
187
225
|
writeFileSync(join(dir, "a.ts"), "export const a = 2;\n");
|
|
188
226
|
if (!decideStop(session, dir, false))
|
|
189
227
|
bad.push("an edit after the pass should send the turn back");
|
|
228
|
+
for (const command of [
|
|
229
|
+
"npm test || true",
|
|
230
|
+
"npx vitest run 2>&1 | tail -5",
|
|
231
|
+
"npm test; echo done",
|
|
232
|
+
"npm test && sed -i s/2/3/ a.ts",
|
|
233
|
+
]) {
|
|
234
|
+
recordPass(session, dir, { command, failed: false });
|
|
235
|
+
if (!decideStop(session, dir, false))
|
|
236
|
+
bad.push(`"${command}" cannot prove a pass`);
|
|
237
|
+
}
|
|
238
|
+
recordPass(session, dir, { command: "npm test", failed: false, background: true });
|
|
239
|
+
if (!decideStop(session, dir, false))
|
|
240
|
+
bad.push("a background launch is not a finished run");
|
|
241
|
+
mkdirSync(join(dir, "pkg"), { recursive: true });
|
|
242
|
+
writeFileSync(join(dir, "pkg", "b.ts"), "export const b = 1;\n");
|
|
243
|
+
recordPass(session, join(dir, "pkg"), {
|
|
244
|
+
command: "npx vitest run 2>&1",
|
|
245
|
+
failed: false,
|
|
246
|
+
});
|
|
247
|
+
if (decideStop(session, join(dir, "pkg"), false))
|
|
248
|
+
bad.push("a pass from a package directory should cover the same tree");
|
|
249
|
+
writeFileSync(join(dir, "pkg", "b.ts"), "export const b = 2;\n");
|
|
250
|
+
if (!decideStop(session, join(dir, "pkg"), false))
|
|
251
|
+
bad.push("an edit seen from a package directory should send the turn back");
|
|
252
|
+
git("add", "-A");
|
|
253
|
+
git("-c", "user.email=t@t", "-c", "user.name=t", "commit", "-q", "-m", "code");
|
|
254
|
+
git("mv", "a.ts", "a.md");
|
|
255
|
+
rmSync(stateFile(session), { force: true });
|
|
256
|
+
if (!decideStop(session, dir, false))
|
|
257
|
+
bad.push("renaming code to a doc removes code and should send the turn back");
|
|
190
258
|
|
|
191
259
|
rmSync(stateFile(session), { force: true });
|
|
192
260
|
rmSync(dir, { recursive: true, force: true });
|
|
193
261
|
process.stdout.write(
|
|
194
|
-
bad.length ? `${bad.join("\n")}\n${bad.length} failing\n` : "ok:
|
|
262
|
+
bad.length ? `${bad.join("\n")}\n${bad.length} failing\n` : "ok: 17 cases\n",
|
|
195
263
|
);
|
|
196
264
|
process.exit(bad.length ? 1 : 0);
|
|
197
265
|
}
|
|
@@ -227,8 +295,11 @@ else if (isMain) {
|
|
|
227
295
|
recordPass(
|
|
228
296
|
payload.session_id,
|
|
229
297
|
dir,
|
|
230
|
-
|
|
231
|
-
|
|
298
|
+
{
|
|
299
|
+
command,
|
|
300
|
+
failed: failedResponse(payload),
|
|
301
|
+
background: payload.tool_input?.run_in_background === true,
|
|
302
|
+
},
|
|
232
303
|
ignore,
|
|
233
304
|
);
|
|
234
305
|
});
|
package/dist/context.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join, posix } from 'node:path';
|
|
3
|
+
import { loadStations, packageRoot } from './core.js';
|
|
3
4
|
const CHARS_PER_TOKEN = 4;
|
|
4
5
|
const LARGEST_SHOWN = 5;
|
|
5
6
|
const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---/;
|
|
@@ -56,15 +57,34 @@ function entryOf(repo, file) {
|
|
|
56
57
|
}
|
|
57
58
|
return { file, chars, userOnly };
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
+
function servers(repo, pkg) {
|
|
61
|
+
const file = join(repo, '.mcp.json');
|
|
62
|
+
if (!existsSync(file))
|
|
63
|
+
return { entries: [], unmeasured: [] };
|
|
64
|
+
const names = Object.keys(JSON.parse(String(readFileSync(file))).mcpServers ?? {});
|
|
65
|
+
const known = new Map(loadStations(pkg).claude.mcp.map((m) => [m.id, m.contextChars]));
|
|
66
|
+
const entries = [];
|
|
67
|
+
const unmeasured = [];
|
|
68
|
+
for (const name of names) {
|
|
69
|
+
const chars = known.get(name);
|
|
70
|
+
if (chars === undefined)
|
|
71
|
+
unmeasured.push(name);
|
|
72
|
+
else
|
|
73
|
+
entries.push({ file: `.mcp.json#${name}`, chars, userOnly: false });
|
|
74
|
+
}
|
|
75
|
+
return { entries, unmeasured };
|
|
76
|
+
}
|
|
77
|
+
export function measureContext(repo, pkg = packageRoot()) {
|
|
60
78
|
const mem = memory(repo);
|
|
61
|
-
const
|
|
79
|
+
const mcp = servers(repo, pkg);
|
|
80
|
+
const entries = [...listed(repo).map((file) => entryOf(repo, file)), ...mcp.entries];
|
|
62
81
|
const chars = entries.reduce((sum, entry) => sum + entry.chars, mem.chars);
|
|
63
82
|
return {
|
|
64
83
|
tokens: tokensOf(chars),
|
|
65
84
|
memoryFiles: mem.files,
|
|
66
85
|
memoryChars: mem.chars,
|
|
67
86
|
entries,
|
|
87
|
+
unmeasured: mcp.unmeasured,
|
|
68
88
|
};
|
|
69
89
|
}
|
|
70
90
|
function readConfig(repo) {
|
|
@@ -121,6 +141,7 @@ export function contextText(result) {
|
|
|
121
141
|
if (result.updated)
|
|
122
142
|
return `ceiling set to ${result.tokens} tokens`;
|
|
123
143
|
const ceiling = result.ceiling;
|
|
124
|
-
const
|
|
144
|
+
const unmeasured = result.unmeasured.length > 0 ? ` + MCP servers not measured: ${result.unmeasured.join(', ')}` : '';
|
|
145
|
+
const line = `✔ always-loaded context: ${result.tokens} tokens${unmeasured} (ceiling ${ceiling})`;
|
|
125
146
|
return result.tokens < ceiling ? `${line}\n below the ceiling: run \`hookset context --update\` to lock in the cut` : line;
|
|
126
147
|
}
|
package/dist/core.d.ts
CHANGED
|
@@ -28,6 +28,25 @@ export interface ClaudeSkill {
|
|
|
28
28
|
placeholder: string;
|
|
29
29
|
detail: string;
|
|
30
30
|
}
|
|
31
|
+
/** An MCP server every repo runs: written into .mcp.json, its index folder gitignored, its tools allowed. */
|
|
32
|
+
export interface ClaudeMcp {
|
|
33
|
+
id: string;
|
|
34
|
+
detail: string;
|
|
35
|
+
/** The `.mcp.json` entry, written as is under `mcpServers.<id>`. */
|
|
36
|
+
server: {
|
|
37
|
+
type: string;
|
|
38
|
+
command: string;
|
|
39
|
+
args: string[];
|
|
40
|
+
env?: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
/** What the server puts in every session (its instructions and tool definitions), in characters. */
|
|
43
|
+
contextChars: number;
|
|
44
|
+
contextSource: string;
|
|
45
|
+
/** The folder the server writes into the repo, which .gitignore must list. */
|
|
46
|
+
ignore: string;
|
|
47
|
+
/** The tool names settings.json allows without a prompt. */
|
|
48
|
+
allow: string[];
|
|
49
|
+
}
|
|
31
50
|
export interface Stations {
|
|
32
51
|
remote: string;
|
|
33
52
|
tagPrefix: string;
|
|
@@ -37,6 +56,7 @@ export interface Stations {
|
|
|
37
56
|
files: string[];
|
|
38
57
|
hooks: ClaudeHook[];
|
|
39
58
|
skills: ClaudeSkill[];
|
|
59
|
+
mcp: ClaudeMcp[];
|
|
40
60
|
};
|
|
41
61
|
}
|
|
42
62
|
export interface Problem {
|
|
@@ -78,6 +98,8 @@ export interface CheckResult {
|
|
|
78
98
|
}
|
|
79
99
|
/** Everything `hookset check` reports for the repo at `repo`, against the presets in `pkg`. */
|
|
80
100
|
export declare function checkRepo(repo: string, pkg: string): CheckResult;
|
|
101
|
+
/** A pack MCP server the repo must run: in .mcp.json as hookset pins it, its index gitignored, enabled in settings.json. */
|
|
102
|
+
export declare function checkMcp(repo: string, mcp: ClaudeMcp): Problem[];
|
|
81
103
|
/** A pack skill the repo must carry and fill in: present, still holding what it requires, no placeholder left. */
|
|
82
104
|
export declare function checkSkill(repo: string, skill: ClaudeSkill): Problem[];
|
|
83
105
|
/** The pack's hooks, each PostToolUse one also on PostToolUseFailure (a failed Bash call lands there). */
|
package/dist/core.js
CHANGED
|
@@ -205,6 +205,26 @@ function checkClaude(repo, pkg, stations) {
|
|
|
205
205
|
}
|
|
206
206
|
for (const skill of stations.claude.skills)
|
|
207
207
|
problems.push(...checkSkill(repo, skill));
|
|
208
|
+
for (const mcp of stations.claude.mcp)
|
|
209
|
+
problems.push(...checkMcp(repo, mcp));
|
|
210
|
+
return problems;
|
|
211
|
+
}
|
|
212
|
+
const readJson = (file, fallback) => (existsSync(file) ? JSON.parse(readText(file)) : fallback);
|
|
213
|
+
export function checkMcp(repo, mcp) {
|
|
214
|
+
const problems = [];
|
|
215
|
+
const server = readJson(join(repo, '.mcp.json'), {}).mcpServers?.[mcp.id];
|
|
216
|
+
if (server === undefined)
|
|
217
|
+
problems.push({ id: `${mcp.id}-mcp-missing`, severity: 'error', message: `.mcp.json does not run the ${mcp.id} server: ${mcp.detail}`, fix: 'run `hookset init --claude`' });
|
|
218
|
+
else if (JSON.stringify(server) !== JSON.stringify(mcp.server))
|
|
219
|
+
problems.push({ id: `${mcp.id}-mcp-drift`, severity: 'error', message: `.mcp.json runs ${mcp.id} differently from the hookset pin (${mcp.server.args.join(' ')})`, fix: 'run `hookset init --claude`; change the pin in burgee packages/hookset/stations.json' });
|
|
220
|
+
const ignore = join(repo, '.gitignore');
|
|
221
|
+
if (!(existsSync(ignore) && readText(ignore).split(/\r?\n/).some((l) => l.trim() === mcp.ignore))) {
|
|
222
|
+
problems.push({ id: `${mcp.id}-not-ignored`, severity: 'error', message: `.gitignore does not list ${mcp.ignore}, the ${mcp.id} index`, fix: `add \`${mcp.ignore}\` to .gitignore (\`hookset init --claude\` does)` });
|
|
223
|
+
}
|
|
224
|
+
const settings = readJson(join(repo, '.claude', 'settings.json'), {});
|
|
225
|
+
if (!(settings.enabledMcpjsonServers ?? []).includes(mcp.id)) {
|
|
226
|
+
problems.push({ id: `${mcp.id}-mcp-disabled`, severity: 'error', message: `.claude/settings.json does not enable the ${mcp.id} server, so every session asks first`, fix: `add "${mcp.id}" to enabledMcpjsonServers (\`hookset init --claude\` does)` });
|
|
227
|
+
}
|
|
208
228
|
return problems;
|
|
209
229
|
}
|
|
210
230
|
export function checkSkill(repo, skill) {
|
|
@@ -269,6 +289,8 @@ export function initRepo(repo, pkg, options = {}) {
|
|
|
269
289
|
if (!existsSync(join(repo, skill.path)))
|
|
270
290
|
write(skill.path, readText(join(pkg, skill.template)));
|
|
271
291
|
write('.claude/settings.json', mergeSettings(repo, stations));
|
|
292
|
+
write('.mcp.json', mergeMcp(repo, stations));
|
|
293
|
+
write('.gitignore', mergeIgnore(repo, stations));
|
|
272
294
|
}
|
|
273
295
|
return { changed: written.length > 0, written };
|
|
274
296
|
}
|
|
@@ -295,6 +317,22 @@ function repin(yaml, ref, remote) {
|
|
|
295
317
|
lines.splice(at, 1, `${line.slice(0, line.indexOf('ref:'))}ref: ${ref}`);
|
|
296
318
|
return lines.join(eol);
|
|
297
319
|
}
|
|
320
|
+
function mergeMcp(repo, stations) {
|
|
321
|
+
const mcp = readJson(join(repo, '.mcp.json'), {});
|
|
322
|
+
mcp.mcpServers = { ...mcp.mcpServers, ...Object.fromEntries(stations.claude.mcp.map((m) => [m.id, m.server])) };
|
|
323
|
+
return `${JSON.stringify(mcp, undefined, 2)}\n`;
|
|
324
|
+
}
|
|
325
|
+
function mergeIgnore(repo, stations) {
|
|
326
|
+
const file = join(repo, '.gitignore');
|
|
327
|
+
const text = existsSync(file) ? readText(file) : '';
|
|
328
|
+
const lines = text.split(/\r?\n/).map((l) => l.trim());
|
|
329
|
+
const missing = stations.claude.mcp.map((m) => m.ignore).filter((i) => !lines.includes(i));
|
|
330
|
+
if (missing.length === 0)
|
|
331
|
+
return text;
|
|
332
|
+
const sep = text === '' || text.endsWith('\n') ? '' : '\n';
|
|
333
|
+
return `${text}${sep}# MCP server indexes, rebuilt per session by .claude/hooks (hookset)\n${missing.join('\n')}\n`;
|
|
334
|
+
}
|
|
335
|
+
const union = (a, b) => [...new Set([...(a ?? []), ...b])];
|
|
298
336
|
function mergeSettings(repo, stations) {
|
|
299
337
|
const file = join(repo, '.claude', 'settings.json');
|
|
300
338
|
const settings = existsSync(file)
|
|
@@ -313,6 +351,8 @@ function mergeSettings(repo, stations) {
|
|
|
313
351
|
groups.push({ matcher: h.matcher, hooks: [{ type: 'command', command: hookCommand(h.file) }] });
|
|
314
352
|
}
|
|
315
353
|
settings.hooks = Object.fromEntries(events);
|
|
354
|
+
settings.enabledMcpjsonServers = union(settings.enabledMcpjsonServers, stations.claude.mcp.map((m) => m.id));
|
|
355
|
+
settings.permissions = { ...settings.permissions, allow: union(settings.permissions?.allow, stations.claude.mcp.flatMap((m) => m.allow)) };
|
|
316
356
|
return `${JSON.stringify(settings, undefined, 2)}\n`;
|
|
317
357
|
}
|
|
318
358
|
function tally(problems) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookset",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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": [
|
package/stations.json
CHANGED
|
@@ -18,13 +18,30 @@
|
|
|
18
18
|
{ "id": "triggerlist", "hook": "pre-push", "mode": "observe", "command": "hookset-triggerlist", "script": "hook:triggerlist", "detail": "protected paths changed only with their trigger" }
|
|
19
19
|
],
|
|
20
20
|
"claude": {
|
|
21
|
-
"files": ["guard-bash.mjs", "stop-after-3.mjs", "verify-before-stop.mjs"],
|
|
21
|
+
"files": ["guard-bash.mjs", "stop-after-3.mjs", "verify-before-stop.mjs", "codegraph.mjs"],
|
|
22
22
|
"hooks": [
|
|
23
23
|
{ "event": "PreToolUse", "matcher": "Bash", "file": "guard-bash.mjs" },
|
|
24
24
|
{ "event": "PreToolUse", "matcher": "Edit|Write|MultiEdit|NotebookEdit", "file": "guard-bash.mjs" },
|
|
25
25
|
{ "event": "PostToolUse", "matcher": "Bash", "file": "stop-after-3.mjs" },
|
|
26
26
|
{ "event": "PostToolUse", "matcher": "Bash", "file": "verify-before-stop.mjs" },
|
|
27
|
-
{ "event": "Stop", "matcher": "", "file": "verify-before-stop.mjs" }
|
|
27
|
+
{ "event": "Stop", "matcher": "", "file": "verify-before-stop.mjs" },
|
|
28
|
+
{ "event": "SessionStart", "matcher": "", "file": "codegraph.mjs" }
|
|
29
|
+
],
|
|
30
|
+
"mcp": [
|
|
31
|
+
{
|
|
32
|
+
"id": "codegraph",
|
|
33
|
+
"detail": "CodeGraph, a prebuilt symbol graph Claude queries instead of grepping; codegraph.mjs builds its index on SessionStart",
|
|
34
|
+
"server": {
|
|
35
|
+
"type": "stdio",
|
|
36
|
+
"command": "npx",
|
|
37
|
+
"args": ["-y", "@colbymchenry/codegraph@1.6.4", "serve", "--mcp", "--no-telemetry"],
|
|
38
|
+
"env": { "CODEGRAPH_TELEMETRY": "0" }
|
|
39
|
+
},
|
|
40
|
+
"contextChars": 8652,
|
|
41
|
+
"contextSource": "codegraph 1.6.4 serve --mcp: initialize instructions (6,718 chars) plus the codegraph_explore tool definition (1,934 chars), measured over stdio on 2026-11-25",
|
|
42
|
+
"ignore": ".codegraph/",
|
|
43
|
+
"allow": ["mcp__codegraph__codegraph_explore"]
|
|
44
|
+
}
|
|
28
45
|
],
|
|
29
46
|
"skills": [
|
|
30
47
|
{ "id": "verify", "path": ".claude/skills/verify/SKILL.md", "template": "claude/skills/verify/SKILL.md", "requires": ["name: verify", "## Feature map"], "placeholder": "TODO(verify)", "detail": "the skill that boots the app, drives the change and checks what it shows, with a feature map" }
|