Class: AgentsControl::Console

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

Overview

The interactive console.

The tool is meant to live in a tab, not run once and exit: that's its working state — it listens to Telegram and receives agent events while it's open. Separate subcommands would be misleading here: after setup it would look like everything's running, while in fact nothing is polling Telegram, and messages pile up unread on its side.

So running with no arguments opens the console itself, and the commands inside it are the same as the bot's — with a slash.

Constant Summary collapse

COMMANDS =
{
  "/help" => "list of commands",
  "/sessions" => "sessions with a live agent",
  "/tabs" => "all terminal tabs",
  "/status" => "what's happening right now",
  "/away" => "intercept agent questions (before stepping out)",
  "/settings" => "settings; /settings NAME — toggle",
  "/token" => "set the Telegram token",
  "/doctor" => "check that everything is in place",
  "/hooks" => "hook status; /hooks install|uninstall",
  "/quit" => "quit"
}.freeze
ARGUMENTS =

Values worth suggesting as a second word.

{
  "/away" => %w[on off],
  "/hooks" => %w[install uninstall]
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config: nil, store: nil, secrets: nil, output: $stdout) ⇒ Console

Returns a new instance of Console.



34
35
36
37
38
39
40
# File 'lib/agents_control/console.rb', line 34

def initialize(config: nil, store: nil, secrets: nil, output: $stdout)
  @config = config || Config.load
  @store = store || Store.new
  @secrets = secrets || Secrets.new
  @out = output
  @out.sync = true if @out.respond_to?(:sync=)
end

Instance Method Details

#runObject



42
43
44
45
46
47
48
49
50
# File 'lib/agents_control/console.rb', line 42

def run
  banner
  start_daemon
  loop_commands
ensure
  say("")
  say("Stopping…")
  @daemon&.stop
end