Class: Silas::Chat

Inherits:
Object
  • Object
show all
Defined in:
lib/silas/chat.rb

Overview

Terminal REPL for talking to the app's agent: bin/rails silas:chat.

The dev-loop equivalent of a hosted platform's CLI — except there is no platform: this runs inside your app, so tools hit your real dev database and the transcript is rows in your own Postgres. Parked approvals prompt inline and call the exact same approve!/decline! as the inbox and Slack.

IO is injected so the loop is testable; the rake task wires $stdin/$stdout and forces the synchronous :inline adapter (a REPL wants each turn settled before the next prompt, and the dev-default Async adapter is unsafe).

Constant Summary collapse

GLYPH =
{ "completed" => "", "failed" => "", "pending" => "",
"started" => "", "in_doubt" => "?" }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(io_in: $stdin, io_out: $stdout, actor: ENV["USER"] || "cli", session: nil) ⇒ Chat

Returns a new instance of Chat.



16
17
18
19
20
21
# File 'lib/silas/chat.rb', line 16

def initialize(io_in: $stdin, io_out: $stdout, actor: ENV["USER"] || "cli", session: nil)
  @in = io_in
  @out = io_out
  @actor = actor
  @session = session
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/silas/chat.rb', line 23

def run
  banner
  if @session && pending_for(@session).exists? # resuming a session that parked last time
    settle_parked
    print_outcome(@session.turns.reload.last)
  end

  loop do
    @out.print "\nyou> "
    line = @in.gets
    break if line.nil?

    line = line.strip
    next if line.empty?
    break if %w[exit quit].include?(line.downcase)

    submit(line)
  end
  @out.puts "bye — session #{@session.id}" if @session
end