claude-dev-env 2.33.2 → 2.35.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/.agents/skills/recovering-codex-startup/SKILL.md +61 -0
- package/.agents/skills/recovering-codex-startup/reference/task-seeds.md +6 -0
- package/.agents/skills/repairing-hook-boundaries/SKILL.md +60 -0
- package/.agents/skills/repairing-hook-boundaries/reference/task-seeds.md +7 -0
- package/AGENTS.md +6 -0
- package/_shared/pr-loop/scripts/code_rules_gate.py +3 -1
- package/_shared/pr-loop/scripts/code_rules_gate_parts/tests/test_violation_scoping.py +11 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/violation_scoping.py +2 -0
- package/_shared/pr-loop/scripts/test_code_rules_gate.py +7 -5
- package/_shared/pr-loop/scripts/tests/test_code_rules_gate.py +124 -2
- package/bin/ever-shipped-skills.mjs +2 -0
- package/bin/install.test.mjs +16 -0
- package/hooks/blocking/code_rules_comments.py +56 -52
- package/hooks/blocking/test_code_rules_enforcer_javascript_comments.py +44 -1
- package/package.json +1 -1
- package/scripts/audit-hooks-cli.mjs +54 -0
- package/scripts/audit-hooks.mjs +397 -0
- package/scripts/tests/test-audit-hooks.mjs +379 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { auditHooks } from "./audit-hooks.mjs";
|
|
6
|
+
|
|
7
|
+
function parseArguments(argv) {
|
|
8
|
+
const options = {
|
|
9
|
+
catalogPath: null,
|
|
10
|
+
format: "text",
|
|
11
|
+
homeDirectory: null,
|
|
12
|
+
includeInstalled: false,
|
|
13
|
+
outputPath: null,
|
|
14
|
+
repositoryRoot: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../.."),
|
|
15
|
+
};
|
|
16
|
+
for (let offset = 0; offset < argv.length; offset += 1) {
|
|
17
|
+
const argument = argv[offset];
|
|
18
|
+
if (argument === "--installed") options.includeInstalled = true;
|
|
19
|
+
else if (argument === "--catalog") options.catalogPath = argv[++offset];
|
|
20
|
+
else if (argument === "--format") options.format = argv[++offset];
|
|
21
|
+
else if (argument === "--home") options.homeDirectory = argv[++offset];
|
|
22
|
+
else if (argument === "--output") options.outputPath = argv[++offset];
|
|
23
|
+
else if (argument === "--repository-root") options.repositoryRoot = argv[++offset];
|
|
24
|
+
else throw new Error(`unknown argument ${argument}`);
|
|
25
|
+
}
|
|
26
|
+
return options;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function renderText(report) {
|
|
30
|
+
const summary = report.summary;
|
|
31
|
+
return [
|
|
32
|
+
`canonical direct: ${summary.directCount}`,
|
|
33
|
+
`dispatchers: ${summary.dispatcherCount}`,
|
|
34
|
+
`hosted entries: ${summary.effectiveCount}`,
|
|
35
|
+
`logical associations: ${summary.logicalAssociationCount}`,
|
|
36
|
+
`unclassified targets: ${summary.unclassifiedCount}`,
|
|
37
|
+
`installed Claude direct: ${summary.claudeDirectCount}`,
|
|
38
|
+
`installed Codex direct: ${summary.codexDirectCount}`,
|
|
39
|
+
`active native Git hooks: ${summary.gitHookCount}`,
|
|
40
|
+
`findings: ${summary.findingCount}`,
|
|
41
|
+
].join("\n");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function main() {
|
|
45
|
+
const options = parseArguments(process.argv.slice(2));
|
|
46
|
+
const report = auditHooks(options);
|
|
47
|
+
const rendered =
|
|
48
|
+
options.format === "json" ? `${JSON.stringify(report, null, 2)}\n` : `${renderText(report)}\n`;
|
|
49
|
+
if (options.outputPath) writeFileSync(options.outputPath, rendered, "utf8");
|
|
50
|
+
else process.stdout.write(rendered);
|
|
51
|
+
process.exitCode = report.findings.some(({ severity }) => severity === "error") ? 1 : 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main();
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const expectedCounts = Object.freeze({ direct: 32, dispatchers: 5, hosted: 43 });
|
|
7
|
+
const dispatcherSpecs = Object.freeze([
|
|
8
|
+
["script:blocking/pre_tool_use_dispatcher.py", "hooks_constants/pre_tool_use_dispatcher_constants.py", "ALL_HOSTED_HOOK_ENTRIES"],
|
|
9
|
+
["script:blocking/bash_pre_tool_use_dispatcher.py", "hooks_constants/bash_pre_tool_use_dispatcher_constants.py", "ALL_BASH_HOSTED_HOOK_ENTRIES"],
|
|
10
|
+
["script:blocking/stop_dispatcher.py", "hooks_constants/stop_dispatcher_constants.py", "ALL_STOP_HOSTED_HOOK_PATHS"],
|
|
11
|
+
["script:validation/post_tool_use_dispatcher.py", "hooks_constants/post_tool_use_dispatcher_constants.py", "ALL_POST_HOSTED_HOOK_ENTRIES"],
|
|
12
|
+
["script:blocking/bash_post_call_dispatcher.py", "hooks_constants/bash_post_call_dispatcher_constants.py", "ALL_BASH_POST_TOOL_USE_HOSTED_HOOK_ENTRIES"],
|
|
13
|
+
]);
|
|
14
|
+
const lifecycleNames = new Set([
|
|
15
|
+
"delete",
|
|
16
|
+
"keep_boundary_check",
|
|
17
|
+
"keep_nonblocking_automation",
|
|
18
|
+
"move_to_ci",
|
|
19
|
+
"move_to_explicit_command",
|
|
20
|
+
"move_to_linter",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
function normalizeMatcher(rawMatcher) {
|
|
24
|
+
return typeof rawMatcher === "string" && rawMatcher
|
|
25
|
+
? rawMatcher.split("|").sort().join("|")
|
|
26
|
+
: "*";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function targetFromCommand(command, scope, event, ordinal) {
|
|
30
|
+
const normalized = command.replaceAll("\\", "/");
|
|
31
|
+
const hookMarker = "/hooks/";
|
|
32
|
+
if (normalized.includes(hookMarker)) {
|
|
33
|
+
const relative = normalized.split(hookMarker).at(-1).split(/[\s"']/u, 1)[0];
|
|
34
|
+
if (relative.endsWith(".py")) return `script:${relative}`;
|
|
35
|
+
}
|
|
36
|
+
const importMatch = /\bfrom\s+([A-Za-z_][\w.]*)\s+import\s+main\b/u.exec(command);
|
|
37
|
+
if (importMatch) return `script:${importMatch[1].replaceAll(".", "/")}.py`;
|
|
38
|
+
const scriptMatches = [...normalized.matchAll(/(?:^|\s)["']?([^"'/\s]+\.(?:exe|js|mjs|ps1|py))\b/gu)];
|
|
39
|
+
if (scriptMatches.length) return `external:${scriptMatches.at(-1)[1]}`;
|
|
40
|
+
return `external:${scope}:${event}:${ordinal}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readDirect(configPath, scope) {
|
|
44
|
+
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
45
|
+
const records = [];
|
|
46
|
+
for (const [event, groups] of Object.entries(parsed.hooks ?? {})) {
|
|
47
|
+
for (const group of Array.isArray(groups) ? groups : []) {
|
|
48
|
+
appendGroupRecords(records, scope, event, group);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return records;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function appendGroupRecords(records, scope, event, group) {
|
|
55
|
+
const matcher = normalizeMatcher(group.matcher);
|
|
56
|
+
for (const hook of Array.isArray(group.hooks) ? group.hooks : []) {
|
|
57
|
+
if (hook?.type !== "command" || typeof hook.command !== "string") continue;
|
|
58
|
+
const ordinal = records.length;
|
|
59
|
+
const target = targetFromCommand(hook.command, scope, event, ordinal);
|
|
60
|
+
const isDispatcher = dispatcherSpecs.some(([knownTarget]) => knownTarget === target);
|
|
61
|
+
records.push({
|
|
62
|
+
event,
|
|
63
|
+
matcher,
|
|
64
|
+
ordinal,
|
|
65
|
+
role: isDispatcher ? "dispatcher" : "hook",
|
|
66
|
+
scope,
|
|
67
|
+
target,
|
|
68
|
+
timeoutSeconds: Number.isInteger(hook.timeout) ? hook.timeout : null,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function assignmentBody(source, rosterName) {
|
|
74
|
+
const rosterOffset = source.lastIndexOf(rosterName);
|
|
75
|
+
if (rosterOffset < 0) throw new Error(`missing roster ${rosterName}`);
|
|
76
|
+
const equalsOffset = source.indexOf("=", rosterOffset);
|
|
77
|
+
const openOffset = source.indexOf("(", equalsOffset);
|
|
78
|
+
if (equalsOffset < 0 || openOffset < 0) throw new Error(`invalid roster ${rosterName}`);
|
|
79
|
+
const closeOffset = matchingParenthesis(source, openOffset);
|
|
80
|
+
return source.slice(openOffset + 1, closeOffset);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function matchingParenthesis(source, openOffset) {
|
|
84
|
+
let depth = 0;
|
|
85
|
+
let quote = "";
|
|
86
|
+
for (let offset = openOffset; offset < source.length; offset += 1) {
|
|
87
|
+
const character = source[offset];
|
|
88
|
+
const previous = source[offset - 1];
|
|
89
|
+
if (quote && character === quote && previous !== "\\") quote = "";
|
|
90
|
+
else if (!quote && (character === '"' || character === "'")) quote = character;
|
|
91
|
+
else if (!quote && character === "(") depth += 1;
|
|
92
|
+
else if (!quote && character === ")") depth -= 1;
|
|
93
|
+
if (depth === 0) return offset;
|
|
94
|
+
}
|
|
95
|
+
throw new Error("unclosed roster");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function topLevelEntries(source) {
|
|
99
|
+
const entries = [];
|
|
100
|
+
let depth = 0;
|
|
101
|
+
let quote = "";
|
|
102
|
+
let start = 0;
|
|
103
|
+
for (let offset = 0; offset < source.length; offset += 1) {
|
|
104
|
+
const character = source[offset];
|
|
105
|
+
const previous = source[offset - 1];
|
|
106
|
+
if (quote && character === quote && previous !== "\\") quote = "";
|
|
107
|
+
else if (!quote && (character === '"' || character === "'")) quote = character;
|
|
108
|
+
else if (!quote && /[([{]/u.test(character)) depth += 1;
|
|
109
|
+
else if (!quote && /[\])}]/u.test(character)) depth -= 1;
|
|
110
|
+
else if (!quote && character === "," && depth === 0) {
|
|
111
|
+
entries.push(source.slice(start, offset));
|
|
112
|
+
start = offset + 1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
entries.push(source.slice(start));
|
|
116
|
+
return entries.filter((entry) => entry.trim());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function toolMatchers(source) {
|
|
120
|
+
const matchers = new Map();
|
|
121
|
+
for (const match of source.matchAll(/\b([A-Z][A-Z0-9_]*_TOOL_NAME)\s*=\s*["']([^"']+)["']/gu)) {
|
|
122
|
+
matchers.set(match[1], new Set([match[2]]));
|
|
123
|
+
}
|
|
124
|
+
const collections = [...source.matchAll(/\b([A-Z][A-Z0-9_]*_TOOL_NAMES)\s*(?::[^=]+)?=\s*frozenset\s*\(/gu)];
|
|
125
|
+
for (const collection of collections) {
|
|
126
|
+
const openOffset = source.indexOf("(", collection.index + collection[0].indexOf("frozenset"));
|
|
127
|
+
const body = source.slice(openOffset + 1, matchingParenthesis(source, openOffset));
|
|
128
|
+
const names = new Set();
|
|
129
|
+
for (const token of body.match(/\b[A-Z][A-Z0-9_]+\b/gu) ?? []) {
|
|
130
|
+
for (const toolName of matchers.get(token) ?? []) names.add(toolName);
|
|
131
|
+
}
|
|
132
|
+
matchers.set(collection[1], names);
|
|
133
|
+
}
|
|
134
|
+
return matchers;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function rosterEntries(hooksRoot, constantsPath, rosterName) {
|
|
138
|
+
const source = readFileSync(path.join(hooksRoot, constantsPath), "utf8");
|
|
139
|
+
const body = assignmentBody(source, rosterName);
|
|
140
|
+
const matchers = toolMatchers(source);
|
|
141
|
+
return topLevelEntries(body).map((expression) => {
|
|
142
|
+
const targetMatch = /["']([^"']+\.py)["']/u.exec(expression);
|
|
143
|
+
if (!targetMatch) throw new Error(`invalid roster entry ${rosterName}`);
|
|
144
|
+
const names = new Set();
|
|
145
|
+
for (const token of expression.match(/\b[A-Z][A-Z0-9_]+\b/gu) ?? []) {
|
|
146
|
+
for (const toolName of matchers.get(token) ?? []) names.add(toolName);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
matcher: names.size ? [...names].sort().join("|") : null,
|
|
150
|
+
target: `script:${targetMatch[1].replaceAll("\\", "/")}`,
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function expandHosted(directRecords, hooksRoot) {
|
|
156
|
+
const parents = new Map(
|
|
157
|
+
directRecords.filter(({ role }) => role === "dispatcher").map((record) => [record.target, record]),
|
|
158
|
+
);
|
|
159
|
+
const hosted = [];
|
|
160
|
+
for (const [dispatcherTarget, constantsPath, rosterName] of dispatcherSpecs) {
|
|
161
|
+
const parent = parents.get(dispatcherTarget);
|
|
162
|
+
if (!parent) continue;
|
|
163
|
+
const entries = rosterEntries(hooksRoot, constantsPath, rosterName);
|
|
164
|
+
for (const entry of entries) {
|
|
165
|
+
hosted.push({
|
|
166
|
+
event: parent.event,
|
|
167
|
+
matcher: entry.matcher ?? parent.matcher,
|
|
168
|
+
ordinal: hosted.length,
|
|
169
|
+
parentTarget: parent.target,
|
|
170
|
+
role: "hosted",
|
|
171
|
+
scope: parent.scope,
|
|
172
|
+
target: entry.target,
|
|
173
|
+
timeoutSeconds: parent.timeoutSeconds,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return hosted;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function logicalRecords(directRecords, hostedRecords) {
|
|
181
|
+
return [...directRecords.filter(({ role }) => role !== "dispatcher"), ...hostedRecords].sort(recordSort);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function recordSort(left, right) {
|
|
185
|
+
const leftKey = [left.scope, left.event, left.matcher, left.target, left.role, left.ordinal].join("\0");
|
|
186
|
+
const rightKey = [right.scope, right.event, right.matcher, right.target, right.role, right.ordinal].join("\0");
|
|
187
|
+
return leftKey.localeCompare(rightKey);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function duplicateFindings(records, scope) {
|
|
191
|
+
const counts = new Map();
|
|
192
|
+
for (const record of records) {
|
|
193
|
+
const key = [record.event, record.matcher, record.target].join("\0");
|
|
194
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
195
|
+
}
|
|
196
|
+
return [...counts.entries()]
|
|
197
|
+
.filter(([, count]) => count > 1)
|
|
198
|
+
.map(([key, count]) => ({
|
|
199
|
+
code: "DUPLICATE_EFFECTIVE_EXECUTION",
|
|
200
|
+
message: `The same event, matcher, and target run ${count} times.`,
|
|
201
|
+
scope,
|
|
202
|
+
severity: "error",
|
|
203
|
+
target: key.split("\0").at(-1),
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function missingTargetFindings(records, hooksRoot, scope) {
|
|
208
|
+
return records
|
|
209
|
+
.filter(({ target }) => target.startsWith("script:"))
|
|
210
|
+
.filter(({ target }) => !existsSync(path.join(hooksRoot, target.slice("script:".length))))
|
|
211
|
+
.map(({ target }) => ({
|
|
212
|
+
code: "MISSING_HOOK_TARGET",
|
|
213
|
+
message: "The registered script is missing from the installed hook tree.",
|
|
214
|
+
scope,
|
|
215
|
+
severity: "error",
|
|
216
|
+
target,
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function missingManagedFindings(expectedRecords, installedRecords, scope) {
|
|
221
|
+
const installedIdentities = new Set(installedRecords.map(recordIdentity));
|
|
222
|
+
return expectedRecords
|
|
223
|
+
.filter((record) => !installedIdentities.has(recordIdentity(record)))
|
|
224
|
+
.map(({ target }) => ({
|
|
225
|
+
code: "MISSING_MANAGED_REGISTRATION",
|
|
226
|
+
message: "The installed configuration is missing a canonical registration.",
|
|
227
|
+
scope,
|
|
228
|
+
severity: "error",
|
|
229
|
+
target,
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function recordIdentity({ event, matcher, target }) {
|
|
234
|
+
return [event, matcher, target].join("\0");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function readLifecycle(catalogPath) {
|
|
238
|
+
if (!catalogPath) return [];
|
|
239
|
+
const parsed = JSON.parse(readFileSync(catalogPath, "utf8"));
|
|
240
|
+
return Object.entries(parsed.hooks ?? {}).map(([target, decision]) => {
|
|
241
|
+
const safeTarget = /^(?:external:[A-Za-z0-9_.:-]+|git:(?:post-commit|pre-commit|pre-push)|script:[A-Za-z0-9_./-]+)$/u;
|
|
242
|
+
if (!safeTarget.test(target) || !lifecycleNames.has(decision?.lifecycle) || !decision.reason) {
|
|
243
|
+
throw new Error("invalid lifecycle entry");
|
|
244
|
+
}
|
|
245
|
+
return { lifecycle: decision.lifecycle, target };
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function lifecycleFindings(records, lifecycle) {
|
|
250
|
+
const targets = new Set(records.map(({ target }) => target));
|
|
251
|
+
const classified = new Set(lifecycle.map(({ target }) => target));
|
|
252
|
+
const missing = [...targets].filter((target) => !classified.has(target));
|
|
253
|
+
const stale = [...classified].filter((target) => !targets.has(target));
|
|
254
|
+
return [
|
|
255
|
+
...missing.map((target) => ({
|
|
256
|
+
code: "UNCLASSIFIED_HOOK",
|
|
257
|
+
message: "The effective hook has no lifecycle decision.",
|
|
258
|
+
scope: "catalog",
|
|
259
|
+
severity: "error",
|
|
260
|
+
target,
|
|
261
|
+
})),
|
|
262
|
+
...stale.map((target) => ({
|
|
263
|
+
code: "STALE_LIFECYCLE_ENTRY",
|
|
264
|
+
message: "The lifecycle target is absent from the canonical graph.",
|
|
265
|
+
scope: "catalog",
|
|
266
|
+
severity: "warning",
|
|
267
|
+
target,
|
|
268
|
+
})),
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function readInstalled(configPath, hooksRoot, scope) {
|
|
273
|
+
if (!existsSync(configPath)) return { findings: [], logical: [], records: [] };
|
|
274
|
+
const records = readDirect(configPath, scope);
|
|
275
|
+
const hosted = expandHosted(records, hooksRoot);
|
|
276
|
+
const logical = logicalRecords(records, hosted);
|
|
277
|
+
return {
|
|
278
|
+
findings: [
|
|
279
|
+
...duplicateFindings(logical, scope),
|
|
280
|
+
...missingTargetFindings([...records, ...hosted], hooksRoot, scope),
|
|
281
|
+
],
|
|
282
|
+
logical,
|
|
283
|
+
records,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function activeGitHooks(repositoryRoot) {
|
|
288
|
+
const gitQuery = spawnSync("git", ["rev-parse", "--git-path", "hooks"], {
|
|
289
|
+
cwd: repositoryRoot,
|
|
290
|
+
encoding: "utf8",
|
|
291
|
+
shell: false,
|
|
292
|
+
timeout: 10_000,
|
|
293
|
+
});
|
|
294
|
+
if (gitQuery.status !== 0) return [];
|
|
295
|
+
const hooksPath = gitQuery.stdout?.trim();
|
|
296
|
+
if (!hooksPath) return [];
|
|
297
|
+
const hooksRoot = path.isAbsolute(hooksPath) ? hooksPath : path.resolve(repositoryRoot, hooksPath);
|
|
298
|
+
return ["pre-commit", "pre-push", "post-commit"]
|
|
299
|
+
.filter((name) => existsSync(path.join(hooksRoot, name)))
|
|
300
|
+
.map((name, ordinal) => ({
|
|
301
|
+
event: name,
|
|
302
|
+
matcher: "*",
|
|
303
|
+
ordinal,
|
|
304
|
+
role: "native",
|
|
305
|
+
scope: "git",
|
|
306
|
+
target: `git:${name}`,
|
|
307
|
+
timeoutSeconds: null,
|
|
308
|
+
}));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function countFindings(directCount, dispatcherCount, hostedCount) {
|
|
312
|
+
const actual = { direct: directCount, dispatchers: dispatcherCount, hosted: hostedCount };
|
|
313
|
+
return Object.entries(expectedCounts)
|
|
314
|
+
.filter(([name, expected]) => actual[name] !== expected)
|
|
315
|
+
.map(([name, expected]) => ({
|
|
316
|
+
code: `${name.toUpperCase()}_COUNT_DRIFT`,
|
|
317
|
+
message: `Expected ${expected} entries and found ${actual[name]}.`,
|
|
318
|
+
scope: "canonical",
|
|
319
|
+
severity: "error",
|
|
320
|
+
target: null,
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function auditHooks(options) {
|
|
325
|
+
const repositoryRoot = path.resolve(options.repositoryRoot);
|
|
326
|
+
const hooksRoot = path.join(repositoryRoot, "packages", "claude-dev-env", "hooks");
|
|
327
|
+
const direct = readDirect(path.join(hooksRoot, "hooks.json"), "canonical");
|
|
328
|
+
const hosted = expandHosted(direct, hooksRoot);
|
|
329
|
+
const logical = logicalRecords(direct, hosted);
|
|
330
|
+
const lifecycle = readLifecycle(options.catalogPath);
|
|
331
|
+
const dispatcherCount = direct.filter(({ role }) => role === "dispatcher").length;
|
|
332
|
+
const installed = options.includeInstalled
|
|
333
|
+
? installedAudit(options.homeDirectory ?? homedir(), repositoryRoot, logical)
|
|
334
|
+
: { claudeCount: 0, codexCount: 0, findings: [], git: [], logical: [], records: [] };
|
|
335
|
+
const allLogical = [...logical, ...installed.logical, ...installed.git];
|
|
336
|
+
const findings = [
|
|
337
|
+
...countFindings(direct.length, dispatcherCount, hosted.length),
|
|
338
|
+
...duplicateFindings(logical, "canonical"),
|
|
339
|
+
...(options.catalogPath ? lifecycleFindings(allLogical, lifecycle) : []),
|
|
340
|
+
...installed.findings,
|
|
341
|
+
].sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
342
|
+
const targets = new Set(allLogical.map(({ target }) => target));
|
|
343
|
+
const classified = new Set(lifecycle.map(({ target }) => target));
|
|
344
|
+
return {
|
|
345
|
+
directRegistrations: direct.sort(recordSort),
|
|
346
|
+
findings,
|
|
347
|
+
hostedRegistrations: hosted.sort(recordSort),
|
|
348
|
+
installedRegistrations: installed.records.sort(recordSort),
|
|
349
|
+
installedLogicalRegistrations: installed.logical.sort(recordSort),
|
|
350
|
+
gitRegistrations: installed.git,
|
|
351
|
+
lifecycle,
|
|
352
|
+
logicalRegistrations: logical,
|
|
353
|
+
schemaVersion: 1,
|
|
354
|
+
summary: {
|
|
355
|
+
claudeDirectCount: installed.claudeCount,
|
|
356
|
+
codexDirectCount: installed.codexCount,
|
|
357
|
+
directCount: direct.length,
|
|
358
|
+
dispatcherCount,
|
|
359
|
+
effectiveCount: hosted.length,
|
|
360
|
+
findingCount: findings.length,
|
|
361
|
+
gitHookCount: installed.git.length,
|
|
362
|
+
lifecycleCount: lifecycle.length,
|
|
363
|
+
logicalAssociationCount: logical.length,
|
|
364
|
+
unclassifiedCount: options.catalogPath
|
|
365
|
+
? [...targets].filter((target) => !classified.has(target)).length
|
|
366
|
+
: 0,
|
|
367
|
+
uniqueTargetCount: targets.size,
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function installedAudit(homeDirectory, repositoryRoot, canonicalLogical) {
|
|
373
|
+
const claude = readInstalled(
|
|
374
|
+
path.join(homeDirectory, ".claude", "settings.json"),
|
|
375
|
+
path.join(homeDirectory, ".claude", "hooks"),
|
|
376
|
+
"claude",
|
|
377
|
+
);
|
|
378
|
+
const codex = readInstalled(
|
|
379
|
+
path.join(homeDirectory, ".codex", "hooks.json"),
|
|
380
|
+
path.join(homeDirectory, ".codex", "hooks"),
|
|
381
|
+
"codex",
|
|
382
|
+
);
|
|
383
|
+
const git = activeGitHooks(repositoryRoot);
|
|
384
|
+
return {
|
|
385
|
+
claudeCount: claude.records.length,
|
|
386
|
+
codexCount: codex.records.length,
|
|
387
|
+
findings: [
|
|
388
|
+
...claude.findings,
|
|
389
|
+
...codex.findings,
|
|
390
|
+
...missingManagedFindings(canonicalLogical, claude.logical, "claude"),
|
|
391
|
+
...missingManagedFindings(canonicalLogical, codex.logical, "codex"),
|
|
392
|
+
],
|
|
393
|
+
git,
|
|
394
|
+
logical: [...claude.logical, ...codex.logical],
|
|
395
|
+
records: [...claude.records, ...codex.records],
|
|
396
|
+
};
|
|
397
|
+
}
|