Class: AgentsControl::Registry

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

Overview

A unified session list assembled from disparate sources.

There are three sources, and they complement each other:

1. terminal backends — iTerm2 tabs and tmux panes;
2. the process tree — who's actually alive in those tabs;
3. terminalless agent processes — VS Code sessions, which have no tab.

Source (1) without (2) lies: a tab's title stays up after the agent exits. Source (3) without special handling just gets lost — VS Code sessions aren't a rare edge case, they're often the majority of active sessions.

Instance Method Summary collapse

Constructor Details

#initialize(backends: nil, probe: nil, executor: Executor.new) ⇒ Registry

Returns a new instance of Registry.



17
18
19
20
21
# File 'lib/agents_control/registry.rb', line 17

def initialize(backends: nil, probe: nil, executor: Executor.new)
  @executor = executor
  @backends = backends || default_backends
  @probe = probe || ProcessProbe.new(executor: executor)
end

Instance Method Details

#agentsObject

Only sessions with a confirmed live agent. This is the list that goes to Telegram by default.



33
# File 'lib/agents_control/registry.rb', line 33

def agents = sessions.select(&:agent?)

#available_backendsObject



48
# File 'lib/agents_control/registry.rb', line 48

def available_backends = backends.select(&:available?)

#backend_for(session) ⇒ Object

The backend that can control this session.



38
39
40
# File 'lib/agents_control/registry.rb', line 38

def backend_for(session)
  backends.find { |backend| backend.name == session.backend } || null_backend
end

#find(id) ⇒ Object



35
# File 'lib/agents_control/registry.rb', line 35

def find(id) = sessions.find { |session| session.id == id }

#refreshObject

Drop the cache — the registry is rebuilt on demand, not held in memory.



43
44
45
46
# File 'lib/agents_control/registry.rb', line 43

def refresh
  @sessions = nil
  self
end

#sessionsObject

Every session: terminal tabs plus terminalless agents.



24
25
26
27
28
29
# File 'lib/agents_control/registry.rb', line 24

def sessions
  @sessions ||= begin
    probe.refresh
    enrich(terminal_sessions) + terminalless_sessions
  end
end