Class: AgentsControl::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/agents_control/session.rb

Overview

One session — a terminal tab, or an agent with no terminal at all.

Deliberately knows nothing about Claude or iTerm2: this is the common denominator the core and Telegram operate on. Anything backend-specific lives in the adapters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, backend: nil, tty: nil, title: nil, cwd: nil, processing: nil, at_shell_prompt: nil, agent: nil, agent_pid: nil, foreground_command: nil) ⇒ Session

Returns a new instance of Session.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/agents_control/session.rb', line 12

def initialize(id:, backend: nil, tty: nil, title: nil, cwd: nil,
               processing: nil, at_shell_prompt: nil,
               agent: nil, agent_pid: nil, foreground_command: nil)
  @id = id
  @backend = backend
  @tty = tty
  @title = title
  @cwd = cwd
  @processing = processing
  @at_shell_prompt = at_shell_prompt
  @agent = agent
  @agent_pid = agent_pid
  @foreground_command = foreground_command
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def agent
  @agent
end

#agent_pidObject (readonly)

Returns the value of attribute agent_pid.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def agent_pid
  @agent_pid
end

#backendObject (readonly)

Returns the value of attribute backend.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def backend
  @backend
end

#cwdObject (readonly)

Returns the value of attribute cwd.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def cwd
  @cwd
end

#foreground_commandObject (readonly)

Returns the value of attribute foreground_command.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def foreground_command
  @foreground_command
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def title
  @title
end

#ttyObject (readonly)

Returns the value of attribute tty.



10
11
12
# File 'lib/agents_control/session.rb', line 10

def tty
  @tty
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



61
# File 'lib/agents_control/session.rb', line 61

def ==(other) = other.is_a?(Session) && other.to_h == to_h

#agent?Boolean

Agent presence is confirmed by the process tree, not the tab title.

Returns:

  • (Boolean)


34
# File 'lib/agents_control/session.rb', line 34

def agent? = !@agent.nil?

#at_shell_prompt?Boolean

Returns:

  • (Boolean)


31
# File 'lib/agents_control/session.rb', line 31

def at_shell_prompt? = @at_shell_prompt == true

#hashObject



64
# File 'lib/agents_control/session.rb', line 64

def hash = to_h.hash

#labelObject

Short name for the Telegram list: the directory name is more informative than a full path or a title that may be stale.



42
43
44
45
46
47
# File 'lib/agents_control/session.rb', line 42

def label
  return File.basename(cwd) if cwd && !cwd.empty?
  return title if title && !title.empty?

  id.to_s
end

#processing?Boolean

Terminal is busy working. iTerm2 has is processing; tmux has no direct equivalent, so the value can be nil — "unknown", not "no".

Returns:

  • (Boolean)


29
# File 'lib/agents_control/session.rb', line 29

def processing? = @processing == true

#terminalless?Boolean

A session without a tab: launched from VS Code or another GUI client. Can't be controlled through a terminal, only reached via hooks.

Returns:

  • (Boolean)


38
# File 'lib/agents_control/session.rb', line 38

def terminalless? = @backend.nil? || @tty.nil?

#to_hObject



53
54
55
56
57
58
59
# File 'lib/agents_control/session.rb', line 53

def to_h
  {
    id: id, backend: backend, tty: tty, title: title, cwd: cwd,
    processing: @processing, at_shell_prompt: @at_shell_prompt,
    agent: agent, agent_pid: agent_pid, foreground_command: foreground_command
  }
end

#with(**attrs) ⇒ Object



49
50
51
# File 'lib/agents_control/session.rb', line 49

def with(**attrs)
  Session.new(**to_h.merge(attrs))
end