Repository navigation
Expand file tree
/
Copy pathvalidate-agent-hooks.cjs
More file actions
103 lines (92 loc) · 3.13 KB
/
Copy pathvalidate-agent-hooks.cjs
File metadata and controls
103 lines (92 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env node
/**
* Agent Hooks Dispatcher
*
* Runs the registered agent/plugin validation hooks across every multi-provider
* agent (a directory containing AGENT.md) and every plugin listed in
* plugins/PLUGIN_MANIFEST.json. This is the CI entrypoint that makes the hooks
* in hooks/hook-registry.json actually execute, rather than only being
* registered.
*
* Exit code 1 if any hook reports errors.
*
* @module scripts/validation/validate-agent-hooks
*/
const fs = require("fs");
const path = require("path");
const root = process.cwd();
const specValidator = require(path.join(root, "hooks/agent-spec-validator"));
const consistency = require(
path.join(root, "hooks/multi-provider-consistency-checker"),
);
const security = require(path.join(root, "hooks/agent-security-auditor"));
const pluginIntegrity = require(
path.join(root, "hooks/plugin-integrity-checker"),
);
let hadError = false;
const warn = [];
function report(label, result) {
for (const w of result.warnings || []) warn.push(`${label}: ${w}`);
if (!result.valid) {
hadError = true;
console.error(`❌ ${label}`);
for (const e of result.errors) console.error(` - ${e}`);
} else {
console.log(`✅ ${label}`);
}
}
// Discover multi-provider agents: any directory (recursively under agents/)
// that contains an AGENT.md file.
function findAgentDirs(baseDir) {
const out = [];
if (!fs.existsSync(baseDir)) return out;
const walk = (dir) => {
const entries = fs.readdirSync(dir, { withFileTypes: true });
// Exact-case match (case-insensitive filesystems must not match agent.md).
if (entries.some((e) => e.isFile() && e.name === "AGENT.md")) out.push(dir);
for (const entry of entries) {
if (entry.isDirectory() && !entry.name.startsWith(".")) {
walk(path.join(dir, entry.name));
}
}
};
walk(baseDir);
return out;
}
console.log("🔍 Running agent/plugin validation hooks\n");
const agentDirs = findAgentDirs(path.join(root, "agents"));
for (const dir of agentDirs) {
const rel = path.relative(root, dir);
report(`agent-spec-validator (${rel})`, specValidator.validate(dir));
report(`multi-provider-consistency-checker (${rel})`, consistency.validate(dir));
report(`agent-security-auditor (${rel})`, security.validate(dir));
}
const registryPath = path.join(root, "plugins/PLUGIN_MANIFEST.json");
if (fs.existsSync(registryPath)) {
const registry = JSON.parse(fs.readFileSync(registryPath, "utf8"));
for (const plugin of registry.plugins || []) {
const pluginPath = path.join(root, plugin.path);
if (fs.existsSync(pluginPath)) {
report(
`plugin-integrity-checker (${plugin.path})`,
pluginIntegrity.validate(pluginPath),
);
report(
`agent-security-auditor (${plugin.path})`,
security.validate(pluginPath),
);
}
}
}
if (warn.length) {
console.log("\nWarnings:");
for (const w of warn) console.log(` ⚠️ ${w}`);
}
if (!agentDirs.length) {
console.log("\nNo multi-provider agents (AGENT.md) found.");
}
if (hadError) {
console.error("\nAgent hook validation failed.");
process.exit(1);
}
console.log("\nAgent hook validation passed.");