fix: add event type enum to hooks schema and avoid shared RegExp state

- 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)
This commit is contained in:
Affaan Mustafa
2026-02-12 16:24:48 -08:00
parent bc0520c6c1
commit 7ec5fc3a52
3 changed files with 15 additions and 4 deletions

View File

@@ -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 {