foobara-agent-cli 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02c3d2e1a47200eb3a55ed6b80634f30dbaf04c7f5b9e0927098bf3866f9d841
4
- data.tar.gz: 467d2fe2e191095ae57685faf1ea3bf5cd0edd39412d2731ee8876bac991f89f
3
+ metadata.gz: 022f075a6a285b82c16fe16b9b275d408420b64a4536bfec012dde9accdf96b5
4
+ data.tar.gz: 265bb11c607742f5c49313786d3ebc7f131e20ca13653f0fdeac734391a5602f
5
5
  SHA512:
6
- metadata.gz: 80609b7d266e727fb9ce1b70e267bae1c14d423ab6ffb898db5704f5e401457458ef829bc554c286b4d867583c15b59a9ded0caee96b10e46c80e7dfc01740ed
7
- data.tar.gz: 6fea8df456f11fbbdc48c4d45c695c0a671a5460165a9bbc9149c6f4a4e364c4c1984ff09a640bb9ae77193414c3936d605dd06b6cb9a29f370954958c8de24d
6
+ metadata.gz: e7bbffda354cfee3922569a507944c0b392ac4a1f0b4c123b7a581b3b074fed6a7beb09b70c155f5005f01c0a3bc5293f8188edbccb01bb044b1e95c7d398d1c
7
+ data.tar.gz: db97a6f637ea354ce4133a445ab587e73b6f697d528ab7015784977dded8f603d4a89cf9b933d8e84fa77fceb81daa1fb3f53ba4ed9189d3bcd94419461b48e4
data/src/foobara/agent.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "io/wait"
2
2
 
3
3
  module Foobara
4
- class Agent
4
+ class Agent < CommandConnector
5
5
  def run_cli(io_in: $stdin, io_out: $stdout, io_err: $stderr)
6
6
  CliRunner.new(self, io_in:, io_out:, io_err:).run
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Agent
2
+ class Agent < CommandConnector
3
3
  class CliRunner
4
4
  attr_accessor :io_in, :io_out, :io_err, :agent
5
5
 
@@ -11,10 +11,8 @@ module Foobara
11
11
  end
12
12
 
13
13
  def run
14
- Util.pipe_write_with_flush(
15
- io_out,
16
- "\nWelcome to the Foobara Agent CLI! Type your goal and press enter to get started.\n\n> "
17
- )
14
+ print_welcome_message
15
+ print_prompt
18
16
 
19
17
  loop do
20
18
  ready = Util.pipe_wait_readable(io_in, 1)
@@ -30,22 +28,19 @@ module Foobara
30
28
 
31
29
  goal = line.strip
32
30
 
33
- break if goal =~ /\A(exit|quit|bye)\z/i
31
+ if goal =~ /\A\/?(exit|quit|bye)\z/i
32
+ print_agent_message("Goodbye for now!")
33
+ agent.kill!
34
+ break
35
+ end
36
+
34
37
  next if goal.empty?
35
38
 
36
39
  begin
40
+ print_agent_message("On it...")
37
41
  outcome = agent.accomplish_goal(goal)
38
-
39
- if outcome.success?
40
- result = outcome.result
41
- Util.pipe_writeline(io_out, "\nAgent says: #{result[:message_to_user]}\n")
42
- else
43
- # :nocov:
44
- Util.pipe_writeline(io_err, "\nError: #{outcome.errors_hash}\n")
45
- # :nocov:
46
- end
47
-
48
- Util.pipe_write_with_flush(io_out, "\n> ")
42
+ print_outcome(outcome)
43
+ print_prompt
49
44
  rescue => e
50
45
  # :nocov:
51
46
  Util.pipe_writeline(io_err, e.message)
@@ -54,6 +49,47 @@ module Foobara
54
49
  end
55
50
  end
56
51
  end
52
+
53
+ def print_welcome_message
54
+ welcome_message = if agent_name
55
+ "Welcome! I am #{agent_name}!"
56
+ else
57
+ "Welcome to the Foobara Agent CLI!"
58
+ end
59
+
60
+ welcome_message << " What would you like me to attempt to accomplish?"
61
+
62
+ Util.pipe_writeline(io_out, "\n#{welcome_message}\n")
63
+ end
64
+
65
+ def print_prompt
66
+ Util.pipe_write_with_flush(io_out, "\n> ")
67
+ end
68
+
69
+ def print_outcome(outcome)
70
+ message, stream = if outcome.success?
71
+ [outcome.result[:message_to_user], io_out]
72
+ else
73
+ # :nocov:
74
+ ["ERROR: #{outcome.errors_hash}", io_err]
75
+ # :nocov:
76
+ end
77
+
78
+ print_agent_message(message, stream)
79
+ end
80
+
81
+ def print_agent_message(message, stream = io_out)
82
+ name = agent_name || "Agent"
83
+ Util.pipe_writeline(stream, "\n#{name} says: #{message}\n")
84
+ end
85
+
86
+ def agent_name
87
+ name = agent.agent_name
88
+
89
+ if name && !name.empty?
90
+ name
91
+ end
92
+ end
57
93
  end
58
94
  end
59
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-agent-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi