foobara-agent-cli 0.0.2 → 0.0.4

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: ec206db778ad18c2a54abe667f5f008bedc9c7e29d4dd380f5dab800993a5092
4
+ data.tar.gz: 608aac583d84f28e30aac7da763281cb3631dc1bb35d70cbe4e3cf2082e5ee9d
5
5
  SHA512:
6
- metadata.gz: 80609b7d266e727fb9ce1b70e267bae1c14d423ab6ffb898db5704f5e401457458ef829bc554c286b4d867583c15b59a9ded0caee96b10e46c80e7dfc01740ed
7
- data.tar.gz: 6fea8df456f11fbbdc48c4d45c695c0a671a5460165a9bbc9149c6f4a4e364c4c1984ff09a640bb9ae77193414c3936d605dd06b6cb9a29f370954958c8de24d
6
+ metadata.gz: 0f552536d87b5350ff91331d72f8a305d0135bdb9fd0d67982bef75c8a7f03aac73ffffde1350cfe022f97095ad48e622840b3b4794cfb38990658a28833832f
7
+ data.tar.gz: ba88235162d3d3744342ee3170f30247b4fbf047e409deb399c2ae0abefa1faa3272ce94c3d9258543de55e8121b68afaeadd1a7c749eefbaf2a0b4ce3dd24ad
data/CHANGELOG.md CHANGED
@@ -1,7 +1,19 @@
1
- ## [Unreleased]
1
+ ## [0.0.4] - 2025-06-19
2
2
 
3
- - Move version.rb.erb to top-level
3
+ - Support cuter ways to exit
4
4
 
5
- ## [0.0.1] - 2025-05-21
5
+ ## [0.0.3] - 2025-05-30
6
+
7
+ - Decompose #run_cli a bit, add a way to quit, and improve output
8
+
9
+ ## [0.0.2] - 2025-05-30
10
+
11
+ - Improve test concurrency issues, test ollama, extract #run_cli to CliRunner and add improvements
12
+
13
+ ## [0.0.1] - 2025-06-19
6
14
 
7
15
  - Initial release
16
+
17
+ ## [0.0.0] - 2025-05-19
18
+
19
+ - Project birth
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 user_wants_to_quit?(goal)
32
+ print_agent_message("Goodbye for now!\n")
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,61 @@ 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 user_wants_to_quit?(goal)
87
+ if goal =~ /\/?(exit|quit|(good)?.?bye)/i
88
+ remainder = "#{::Regexp.last_match.pre_match}#{::Regexp.last_match.post_match}."
89
+ remainder.strip!
90
+
91
+ remainder.gsub!(/thanks?.?(you)?[\.!]*/i, "")
92
+ remainder.gsub!(/\A\s*\w+[\.!]*/i, "")
93
+ remainder.gsub!(/[\.!]*\z/i, "")
94
+
95
+ remainder.strip!
96
+ remainder.empty?
97
+ end
98
+ end
99
+
100
+ def agent_name
101
+ name = agent.agent_name
102
+
103
+ if name && !name.empty?
104
+ name
105
+ end
106
+ end
57
107
  end
58
108
  end
59
109
  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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.6.7
62
+ rubygems_version: 3.6.9
63
63
  specification_version: 4
64
64
  summary: Enables a Foobara::Agent to be ran as a CLI tool
65
65
  test_files: []