Add validateHookFields() that strips invalid hook entries before they cause Claude Code's Zod schema to silently discard the entire settings.json file. Agent hooks require "prompt", command hooks require "command", and entries without a valid hooks sub-array are removed. Uses a clean two-pass approach: first validate and build new arrays (no mutation inside filter predicates), then collect-and-delete empty event keys (no delete during Object.keys iteration). Result entries are shallow copies so the original input objects are never mutated. Includes 24 tests covering passthrough, removal, structural invalidity, empty cleanup, mutation safety, unknown types, and iteration safety. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
12 KiB
12 KiB