fix: enforce frozen agent hook blocking

This commit is contained in:
ZacharyZhang-NY committed 2026-07-19 01:38:28 -04:00
1 parent df604f82be
commit f0e82b46fb
5 files changed
+184 -12

No files matched your search

+3 -3
View File
@@ -301,7 +301,7 @@ main();
*
* - Caches the agent status locally (60s TTL) to avoid hitting the API on every tool call
* - Fails open: if the API is unreachable, tool execution is allowed
* - If frozen: exits with code 1 to block the tool
* - If frozen: exits with code 2, the blocking code shared by supported hook CLIs
*/
export function generateGuardScript(agentName: string, agentId: string): string {
return `#!/usr/bin/env node
@@ -344,7 +344,7 @@ async function main() {
if (age < CACHE_TTL_MS) {
if (cache.status === 'frozen') {
process.stderr.write('Agent "' + AGENT_NAME + '" is frozen by Elydora. Tool execution blocked.\\n');
process.exitCode = 1;
process.exitCode = 2;
}
return; // Cache is fresh — use cached result
}
@@ -388,7 +388,7 @@ async function main() {
if (agentStatus === 'frozen') {
process.stderr.write('Agent "' + AGENT_NAME + '" is frozen by Elydora. Tool execution blocked.\\n');
process.exitCode = 1;
process.exitCode = 2;
}
}
} catch {
+8 -9
View File
@@ -25,21 +25,20 @@ export const ElydoraAuditPlugin = async (ctx) => {
return {
"tool.execute.before": async (input, output) => {
// Guard — blocks tool if agent is frozen
let result;
try {
const result = spawnSync('node', ['__ELYDORA_GUARD_SCRIPT_PATH__'], {
result = spawnSync('node', ['__ELYDORA_GUARD_SCRIPT_PATH__'], {
timeout: 5000,
stdio: ['pipe', 'ignore', 'pipe'],
});
if (result.status === 2) {
const msg = result.stderr ? result.stderr.toString().trim() : 'Agent is frozen by Elydora.';
// Signal denial by setting a blocked flag
if (output && typeof output === 'object') {
output.blocked = true;
output.reason = msg;
}
}
} catch {
// Fail-open — allow if guard can't run
return;
}
if (result.status === 2) {
const msg = result.stderr ? result.stderr.toString().trim() : 'Agent is frozen by Elydora.';
throw new Error(msg);
}
},