The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix(hooks): preserve truncated event enforcement
wellkiloe5b629509ca9
diff --git a/scripts/hooks/hookify-runtime.js b/scripts/hooks/hookify-runtime.jsindex 85721858d..32d7a6dac 100644--- a/scripts/hooks/hookify-runtime.js+++ b/scripts/hooks/hookify-runtime.js@@ -713,12 +713,17 @@ function truncatedEventContext(raw, options) {|| 'PreToolUse');const toolName = parsed?.tool_name || options.toolName || '';- const alias = eventAlias({- ...(parsed || {}),- hook_event_name: hookEvent,- tool_name: toolName,- });- return { parsed, hookEvent, toolName, alias };+ const alias = toolName || !['PreToolUse', 'PostToolUse'].includes(hookEvent)+ ? eventAlias({+ ...(parsed || {}),+ hook_event_name: hookEvent,+ tool_name: toolName,+ })+ : null;+ const possibleAliases = alias+ ? [alias]+ : ['PreToolUse', 'PostToolUse'].includes(hookEvent) ? ['bash', 'file'] : [];+ return { parsed, hookEvent, toolName, alias, possibleAliases };}function handleTruncatedInput(raw, projectRoot, env, maxStdin, options = {}) {@@ -726,7 +731,7 @@ function handleTruncatedInput(raw, projectRoot, env, maxStdin, options = {}) {const loaded = enforceRuleTrust(projectRoot, loadRules(projectRoot), env);const blockers = loaded.rules.filter(rule => (rule.action === 'block'- && (!context.alias || rule.event === 'all' || rule.event === context.alias)+ && (rule.event === 'all' || context.possibleAliases.includes(rule.event))&& (!context.toolName || matchesTool(rule.toolMatcher, context.toolName))));const reason = 'Hookify input exceeded ' + maxStdin + ' bytes and could not be fully inspected.';diff --git a/tests/hooks/hookify-registration.test.js b/tests/hooks/hookify-registration.test.jsindex 43b1d50c9..192712959 100644--- a/tests/hooks/hookify-registration.test.js+++ b/tests/hooks/hookify-registration.test.js@@ -141,6 +141,24 @@ if (test('direct entrypoint emits valid JSON for a matched prompt rule', () => {}})) passed++; else failed++;+if (test('registered PreToolUse hook fails closed on oversized file input', () => {+ const root = createProject();+ try {+ writeRule(root, 'oversized-file', 'name: oversized-file\nevent: file\naction: block\npattern: BLOCK_ME', 'Oversized writes require review.');+ const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8')).hooks;+ const entry = hooks.PreToolUse.find(item => item.id === 'pre:hookify-runtime');+ const result = runRegisteredEntry(root, entry, {+ hook_event_name: 'PreToolUse',+ tool_name: 'Write',+ tool_input: { file_path: 'large.txt', content: 'x'.repeat(1024 * 1024 + 1) },+ });+ assert.strictEqual(result.status, 0, result.stderr);+ assert.strictEqual(JSON.parse(result.stdout).hookSpecificOutput.permissionDecision, 'deny');+ } finally {+ fs.rmSync(root, { recursive: true, force: true });+ }+})) passed++; else failed++;+if (test('PostToolUse dispatcher preserves Hookify block decisions over sibling output', () => {const dispatcher = require(dispatcherPath);const raw = JSON.stringify({ hook_event_name: 'PostToolUse', tool_name: 'Write' });