Class: Parabot::Messaging::TmuxAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/parabot/messaging/tmux_adapter.rb

Overview

Tmux implementation of the MessagingAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dry_run: false, **_kwargs) ⇒ TmuxAdapter

Returns a new instance of TmuxAdapter.



12
13
14
# File 'lib/parabot/messaging/tmux_adapter.rb', line 12

def initialize(dry_run: false, **_kwargs)
  @tmux_manager = TmuxManager.new(dry_run: dry_run)
end

Instance Attribute Details

#tmux_managerObject (readonly)

Returns the value of attribute tmux_manager.



10
11
12
# File 'lib/parabot/messaging/tmux_adapter.rb', line 10

def tmux_manager
  @tmux_manager
end

Instance Method Details

#abortBoolean

Returns true if abort command was sent successfully (ESC key).

Returns:

  • (Boolean)

    true if abort command was sent successfully (ESC key)



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/parabot/messaging/tmux_adapter.rb', line 46

def abort
  session = tmux_manager.find_claude_session
  return false unless session

  target = tmux_manager.find_claude_target(session)

  # Send ESC key to abort current Claude response
  send_cmd("tmux send-keys -t #{session}:#{target.tr(':', '.')} Escape")

  true
rescue TmuxError
  false
end

#end_sessionBoolean

Returns true if session was ended successfully.

Returns:

  • (Boolean)

    true if session was ended successfully



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/parabot/messaging/tmux_adapter.rb', line 29

def end_session
  session = tmux_manager.find_claude_session
  return false unless session

  target = tmux_manager.find_claude_target(session)

  # Send Ctrl+C then exit command
  send_cmd("tmux send-keys -t #{session}:#{target.tr(':', '.')} C-c")
  sleep(0.2)
  send_cmd("tmux send-keys -t #{session}:#{target.tr(':', '.')} exit Enter")

  true
rescue TmuxError
  false
end

#send_message(message) ⇒ Boolean

Returns true if message was sent successfully.

Parameters:

  • message (String)

    the message to send to Claude

Returns:

  • (Boolean)

    true if message was sent successfully



18
19
20
# File 'lib/parabot/messaging/tmux_adapter.rb', line 18

def send_message(message)
  tmux_manager.send_to_claude(message)
end

#session_active?Boolean

Returns true if Claude session is available and active.

Returns:

  • (Boolean)

    true if Claude session is available and active



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/parabot/messaging/tmux_adapter.rb', line 61

def session_active?
  session = tmux_manager.find_claude_session
  return false unless session

  target = tmux_manager.find_claude_target(session)

  # Check if the target pane has a Claude process running
  window_pane = target.tr(":", ".")
  result = tmux_manager.run_command("tmux list-panes -t #{session}:#{window_pane} -F '\#{pane_current_command}'")
  result.success? && result.out.strip.match?(/claude/i)
rescue SystemCallError
  false
end

#start_session(system_prompt: nil) ⇒ Boolean

Returns true if Claude session was started successfully.

Parameters:

  • system_prompt (String, nil) (defaults to: nil)

    optional system prompt

Returns:

  • (Boolean)

    true if Claude session was started successfully



24
25
26
# File 'lib/parabot/messaging/tmux_adapter.rb', line 24

def start_session(system_prompt: nil)
  tmux_manager.start_claude_session(system_prompt: system_prompt)
end