Module: CodexNotify::HookFormatter

Defined in:
lib/codex_notify/hook_formatter.rb

Class Method Summary collapse

Class Method Details

.assistant_message(event) ⇒ Object



24
25
26
# File 'lib/codex_notify/hook_formatter.rb', line 24

def assistant_message(event)
  MessageFormatter.message(title: 'assistant', body: event.assistant_message, presentation: :plain)
end

.permission_request_message(event) ⇒ Object



55
56
57
58
59
# File 'lib/codex_notify/hook_formatter.rb', line 55

def permission_request_message(event)
  description = event.tool_input['description']
  description ||= 'Codex is waiting for your approval.'
  tool_message("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 post_tool_message(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_message('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 pre_tool_message(event)
  command = event.tool_input['command']
  if command.nil? || command.to_s.empty?
    payload = JSON.pretty_generate(event.raw_payload)
    return tool_message('tool', payload)
  end

  tool_message('tool', "$ #{command}")
end

.prompt_message(event, user_name:) ⇒ Object



20
21
22
# File 'lib/codex_notify/hook_formatter.rb', line 20

def prompt_message(event, user_name:)
  MessageFormatter.message(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 session_root_message(event, title:, user_name:)
  body = [
    'Codex hook notification started.',
    "CWD: #{event.cwd}",
    "User: #{user_name}",
    "Session ID: #{event.session_id}"
  ].join("\n")
  tool_message(title, body)
end

.tool_message(title, body) ⇒ Object



28
29
30
# File 'lib/codex_notify/hook_formatter.rb', line 28

def tool_message(title, body)
  MessageFormatter.message(title:, body:, presentation: :block)
end