From 7ec5fc3a52d0866525eb1ab4c1934e74a58fb2ae Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Thu, 12 Feb 2026 16:24:48 -0800 Subject: [PATCH] fix: add event type enum to hooks schema and avoid shared RegExp state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hooks.schema.json: add enum constraint for hook event types (PreToolUse, PostToolUse, PreCompact, SessionStart, SessionEnd, Stop, Notification, SubagentStop) — enables IDE autocompletion and compile-time validation - utils.js countInFile: always create fresh RegExp to avoid shared lastIndex state when reusing global regex instances - README: update AgentShield stats (751 tests, 73 rules) --- README.md | 2 +- schemas/hooks.schema.json | 13 ++++++++++++- scripts/lib/utils.js | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2fe72ea..0e75d30 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ Both options create: ### AgentShield — Security Auditor -> Built at the Claude Code Hackathon (Cerebral Valley x Anthropic, Feb 2026). 697 tests, 98% coverage, 63 static analysis rules. +> Built at the Claude Code Hackathon (Cerebral Valley x Anthropic, Feb 2026). 751 tests, 98% coverage, 73 static analysis rules. Scan your Claude Code configuration for vulnerabilities, misconfigurations, and injection risks. diff --git a/schemas/hooks.schema.json b/schemas/hooks.schema.json index ceb2bd9..cd58cfb 100644 --- a/schemas/hooks.schema.json +++ b/schemas/hooks.schema.json @@ -11,7 +11,18 @@ ], "properties": { "type": { - "type": "string" + "type": "string", + "enum": [ + "PreToolUse", + "PostToolUse", + "PreCompact", + "SessionStart", + "SessionEnd", + "Stop", + "Notification", + "SubagentStop" + ], + "description": "Hook event type that triggers this hook" }, "command": { "oneOf": [ diff --git a/scripts/lib/utils.js b/scripts/lib/utils.js index b675a08..a0b548c 100644 --- a/scripts/lib/utils.js +++ b/scripts/lib/utils.js @@ -418,8 +418,8 @@ function countInFile(filePath, pattern) { let regex; try { if (pattern instanceof RegExp) { - // Ensure global flag is set for correct counting - regex = pattern.global ? pattern : new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : pattern.flags + 'g'); + // Always create new RegExp to avoid shared lastIndex state; ensure global flag + regex = new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : pattern.flags + 'g'); } else if (typeof pattern === 'string') { regex = new RegExp(pattern, 'g'); } else {