-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathrun-skill-posttool-validation.js
More file actions
63 lines (50 loc) · 1.78 KB
/
Copy pathrun-skill-posttool-validation.js
File metadata and controls
63 lines (50 loc) · 1.78 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
#!/usr/bin/env node
const path = require('path');
const { spawnSync } = require('child_process');
const {
getTrackedSkillFromToolInput,
getValidatorScript,
} = require('../scripts/lib/powerpages-hook-utils');
const DEBUG = process.env.DEBUG === '1' || process.env.DEBUG === 'true';
function debug(msg) {
if (DEBUG) process.stderr.write(msg);
}
debug('[power-pages hook] run-skill-posttool-validation.js started\n');
let inputData = '';
process.stdin.on('data', (chunk) => {
inputData += chunk;
});
process.stdin.on('end', () => {
debug(`[power-pages hook] stdin closed, received ${inputData.length} bytes\n`);
try {
const input = JSON.parse(inputData);
const skillName = getTrackedSkillFromToolInput(input.tool_input);
if (!skillName) {
debug('[power-pages hook] No tracked skill detected — skipping validation\n');
process.exit(0);
}
const validatorScript = getValidatorScript(skillName);
if (!validatorScript) {
debug(`[power-pages hook] Skill "${skillName}" has no validator — skipping\n`);
process.exit(0);
}
debug(`[power-pages hook] Running validator for skill "${skillName}": ${validatorScript}\n`);
const validatorPath = path.join(__dirname, '..', validatorScript);
const result = spawnSync(process.execPath, [validatorPath], {
input: inputData,
encoding: 'utf8',
cwd: input.cwd || process.cwd(),
});
if (result.stdout) {
process.stdout.write(result.stdout);
}
if (result.stderr) {
process.stderr.write(result.stderr);
}
debug(`[power-pages hook] Validator exited with code ${result.status ?? 0}\n`);
process.exit(result.status ?? 0);
} catch (err) {
process.stderr.write(`[power-pages hook] Unexpected error: ${err.message}\n`);
process.exit(0);
}
});