Module: CodexNotify::HookInputValidator
- Defined in:
- lib/codex_notify/hook_input_validator.rb
Constant Summary collapse
- EVENT_ALIASES =
{ 'userpromptsubmit' => 'UserPromptSubmit', 'pretooluse' => 'PreToolUse', 'posttooluse' => 'PostToolUse', 'permissionrequest' => 'PermissionRequest', 'stop' => 'Stop', 'sessionstart' => 'SessionStart' }.freeze
- SUPPORTED_EVENTS =
EVENT_ALIASES.values.freeze
Class Method Summary collapse
Class Method Details
.normalize_event_name(name) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/codex_notify/hook_input_validator.rb', line 42 def normalize_event_name(name) return nil unless name.is_a?(String) text = name.strip return nil if text.empty? return text if SUPPORTED_EVENTS.include?(text) EVENT_ALIASES[text.downcase.gsub(/[_\s-]/, '')] || text end |
.validate(event_name:, payload:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/codex_notify/hook_input_validator.rb', line 21 def validate(event_name:, payload:) raise HookInputError, 'hook payload must be a JSON object' unless payload.is_a?(Hash) normalized_event = validate_event_name(event_name, payload) session_id = validate_session_id(payload) attributes = normalize_event_payload(normalized_event, payload) HookEvent.new( name: immutable_copy(normalized_event), session_id: immutable_copy(session_id), cwd: immutable_copy(payload['cwd'] || Dir.pwd), source: nil, prompt: nil, tool_name: nil, tool_input: nil, tool_response: nil, assistant_message: nil, raw_payload: nil, **attributes ) end |