(template: HookTemplate)
| 403 | }; |
| 404 | |
| 405 | const applyTemplate = (template: HookTemplate) => { |
| 406 | if (matcherEvents.includes(template.event as any)) { |
| 407 | // For events with matchers |
| 408 | const newMatcher: EditableHookMatcher = { |
| 409 | id: HooksManager.generateId(), |
| 410 | matcher: template.matcher, |
| 411 | hooks: template.commands.map(cmd => ({ |
| 412 | id: HooksManager.generateId(), |
| 413 | type: 'command' as const, |
| 414 | command: cmd |
| 415 | })), |
| 416 | expanded: true |
| 417 | }; |
| 418 | |
| 419 | setEditableHooks(prev => ({ |
| 420 | ...prev, |
| 421 | [template.event]: [...(prev[template.event as 'PreToolUse' | 'PostToolUse'] as EditableHookMatcher[]), newMatcher] |
| 422 | })); |
| 423 | } else { |
| 424 | // For direct events |
| 425 | const newCommands: EditableHookCommand[] = template.commands.map(cmd => ({ |
| 426 | id: HooksManager.generateId(), |
| 427 | type: 'command' as const, |
| 428 | command: cmd |
| 429 | })); |
| 430 | |
| 431 | setEditableHooks(prev => ({ |
| 432 | ...prev, |
| 433 | [template.event]: [...(prev[template.event as 'Notification' | 'Stop' | 'SubagentStop'] as EditableHookCommand[]), ...newCommands] |
| 434 | })); |
| 435 | } |
| 436 | |
| 437 | setSelectedEvent(template.event); |
| 438 | setShowTemplateDialog(false); |
| 439 | }; |
| 440 | |
| 441 | const validateHooks = async () => { |
| 442 | if (!hooks) { |
no test coverage detected