Class: Parabot::Messaging::TmuxAdapter
- Defined in:
- lib/parabot/messaging/tmux_adapter.rb
Overview
Tmux implementation of the MessagingAdapter
Instance Attribute Summary collapse
-
#tmux_manager ⇒ Object
readonly
Returns the value of attribute tmux_manager.
Instance Method Summary collapse
-
#abort ⇒ Boolean
True if abort command was sent successfully (ESC key).
-
#end_session ⇒ Boolean
True if session was ended successfully.
-
#initialize(dry_run: false, **_kwargs) ⇒ TmuxAdapter
constructor
A new instance of TmuxAdapter.
-
#send_message(message) ⇒ Boolean
True if message was sent successfully.
-
#session_active? ⇒ Boolean
True if Claude session is available and active.
-
#start_session(system_prompt: nil) ⇒ Boolean
True if Claude session was started successfully.
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_manager ⇒ Object (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
#abort ⇒ Boolean
Returns 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_session ⇒ Boolean
Returns 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.
18 19 20 |
# File 'lib/parabot/messaging/tmux_adapter.rb', line 18 def () tmux_manager.send_to_claude() end |
#session_active? ⇒ Boolean
Returns 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.
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 |