Module: CodexNotify::HookFormatter
- Defined in:
- lib/codex_notify/hook_formatter.rb
Class Method Summary collapse
- .assistant_message(event) ⇒ Object
- .permission_request_message(event) ⇒ Object
- .post_tool_message(event) ⇒ Object
- .pre_tool_message(event) ⇒ Object
- .prompt_message(event, user_name:) ⇒ Object
- .session_root_message(event, title:, user_name:) ⇒ Object
- .tool_message(title, body) ⇒ Object
Class Method Details
.assistant_message(event) ⇒ Object
24 25 26 |
# File 'lib/codex_notify/hook_formatter.rb', line 24 def (event) MessageFormatter.(title: 'assistant', body: event., presentation: :plain) end |
.permission_request_message(event) ⇒ Object
55 56 57 58 59 |
# File 'lib/codex_notify/hook_formatter.rb', line 55 def (event) description = event.tool_input['description'] description ||= 'Codex is waiting for your approval.' ("approval required: #{event.tool_name}", description) end |
.post_tool_message(event) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/codex_notify/hook_formatter.rb', line 42 def (event) output = event.tool_response['output'] exit_code = event.tool_response['exit_code'] stderr = event.tool_response['stderr'] parts = [] parts << "[exit_code] #{exit_code}" unless exit_code.nil? parts << "[output]\n#{output}" unless output.nil? || output.to_s.empty? parts << "[stderr]\n#{stderr}" unless stderr.nil? || stderr.to_s.empty? parts = [JSON.pretty_generate(event.raw_payload)] if parts.empty? ('tool', parts.join("\n\n")) end |
.pre_tool_message(event) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/codex_notify/hook_formatter.rb', line 32 def (event) command = event.tool_input['command'] if command.nil? || command.to_s.empty? payload = JSON.pretty_generate(event.raw_payload) return ('tool', payload) end ('tool', "$ #{command}") end |
.prompt_message(event, user_name:) ⇒ Object
20 21 22 |
# File 'lib/codex_notify/hook_formatter.rb', line 20 def (event, user_name:) MessageFormatter.(title: user_name, body: event.prompt, presentation: :plain) end |
.session_root_message(event, title:, user_name:) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/codex_notify/hook_formatter.rb', line 10 def (event, title:, user_name:) body = [ 'Codex hook notification started.', "CWD: #{event.cwd}", "User: #{user_name}", "Session ID: #{event.session_id}" ].join("\n") (title, body) end |
.tool_message(title, body) ⇒ Object
28 29 30 |
# File 'lib/codex_notify/hook_formatter.rb', line 28 def (title, body) MessageFormatter.(title:, body:, presentation: :block) end |