omniai-tools 0.7.0 → 1.0.0

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: cc6ea7c9ceed0c7ea84e3dbd8870e649d3c9890cc776663ca81134e5bd40b5da
4
- data.tar.gz: c619e234101b74e420a44a4536565fac17ce9f36a00205875fc89aa7e79df415
3
+ metadata.gz: 385d159444de83c26eccbdf950ea03349cddb98a7120b8a9fc374cc8a0b2711b
4
+ data.tar.gz: ccbd00d1298d0a6f2b799172290d249e1a0dedf79067770b7d1702430464a952
5
5
  SHA512:
6
- metadata.gz: 249c297b5d8ee3e69c24e6fa2e594b02766ebd6862f95a52a4491b114d17d5494f06efe98ca602921d76be2937a7e7c57d1864ba323016d50927d58c7cf74b0e
7
- data.tar.gz: 2d0583047e63b56ca62dbc9f6073b12fa5513dc769a770effb5f534f2e485d2c40cbcc4fd52ec9bd19639b9f087f140bbbf1a88e0fb73c4dc69752a944d922c0
6
+ metadata.gz: 963be0688e80f82d3358b0299e884639231613db60d9825d6e08b31bed64e9cb623ec945772927e67887d908a019df4fee6796bc9f299fad5975a743e84cfdec
7
+ data.tar.gz: ddc254f93036bd2688f39736e0216001467f575fd72467a224012edcc4ea322f12e2b5cb6b81002d110a351c34f95fc75535eb3daeeb3f4f8c7536dc3f631a28
data/README.md CHANGED
@@ -179,18 +179,10 @@ root = gets.strip
179
179
 
180
180
  client = OmniAI::OpenAI::Client.new
181
181
  logger = Logger.new($stdout)
182
+ logger.formatter = proc { |_, _, _, message| "[disk] #{message}\n" }
182
183
 
183
- tools = [
184
- OmniAI::Tools::Disk::DirectoryCreateTool,
185
- OmniAI::Tools::Disk::DirectoryDeleteTool,
186
- OmniAI::Tools::Disk::FileCreateTool,
187
- OmniAI::Tools::Disk::FileDeleteTool,
188
- OmniAI::Tools::Disk::FileMoveTool,
189
- OmniAI::Tools::Disk::FileReplaceTool,
190
- OmniAI::Tools::Disk::FileReadTool,
191
- OmniAI::Tools::Disk::FileWriteTool,
192
- OmniAI::Tools::Disk::SummaryTool,
193
- ].map { |klass| klass.new(root:, logger:) }
184
+ driver = OmniAI::Tools::Disk::LocalDriver.new(root:)
185
+ tools = [OmniAI::Tools::DiskTool.new(driver:, logger:)]
194
186
 
195
187
  puts "Type 'exit' or 'quit' to leave."
196
188
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sqlite3"
4
-
5
3
  module OmniAI
6
4
  module Tools
7
5
  module Browser
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sqlite3"
4
-
5
3
  module OmniAI
6
4
  module Tools
7
5
  module Browser
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sqlite3"
4
-
5
3
  module OmniAI
6
4
  module Tools
7
5
  module Computer
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module OmniAI
6
+ module Tools
7
+ module Disk
8
+ # A driver for interacting with a disk via various operations
9
+ class BaseDriver
10
+ # @param root [String]
11
+ def initialize(root:)
12
+ @root = Pathname(root)
13
+ end
14
+
15
+ # @param path [String]
16
+ def directory_create(path:)
17
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
18
+ end
19
+
20
+ # @param path [String]
21
+ def directroy_delete(path:)
22
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
23
+ end
24
+
25
+ # @param path [String]
26
+ # @param destination [String]
27
+ def directory_move(path:, destination:)
28
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
29
+ end
30
+
31
+ # @param path [String]
32
+ def file_create(path:)
33
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
34
+ end
35
+
36
+ # @param path [String]
37
+ def file_delete(path:)
38
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
39
+ end
40
+
41
+ # @param path [String]
42
+ # @param destination [String]
43
+ def file_move(path:, destination:)
44
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
45
+ end
46
+
47
+ # @param path [String]
48
+ # @return [String]
49
+ def file_read(path:)
50
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
51
+ end
52
+
53
+ # @param old_text [String]
54
+ # @param new_text [String]
55
+ # @param path [String]
56
+ def file_replace(old_text:, new_text:, path:)
57
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
58
+ end
59
+
60
+ # @param path [String]
61
+ # @param text [String]
62
+ def file_write(path:, text:)
63
+ raise NotImplementedError, "#{self.class}#{__method__} undefined"
64
+ end
65
+
66
+ protected
67
+
68
+ # @param path [String]
69
+ #
70
+ # @raise [SecurityError]
71
+ #
72
+ # @return Pathname
73
+ def resolve!(path:)
74
+ @root.join(path).tap do |resolved|
75
+ relative = resolved.ascend.any? { |ancestor| ancestor.eql?(@root) }
76
+ raise SecurityError, "unknown path=#{resolved}" unless relative
77
+ end
78
+ end
79
+
80
+ # @param path [String]
81
+ def summarize(path:)
82
+ if File.directory?(path)
83
+ "📁 ./#{path}/"
84
+ else
85
+ "📄 ./#{path} (#{File.size(path)} bytes)"
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -8,27 +8,13 @@ module OmniAI
8
8
  # description "..."
9
9
  # end
10
10
  class BaseTool < OmniAI::Tool
11
- # @param root [Pathname] The root path for which a tool is able to operate within.
11
+ # @param driver [OmniAI::BaseDriver] A driver for interacting with the disk.
12
12
  # @param logger [IO] An optional logger for debugging executed commands.
13
- def initialize(root:, logger: Logger.new(IO::NULL))
13
+ def initialize(driver:, logger: Logger.new(IO::NULL))
14
14
  super()
15
- @root = Pathname(root)
15
+ @driver = driver
16
16
  @logger = logger
17
17
  end
18
-
19
- protected
20
-
21
- # @param path [String]
22
- #
23
- # @raise [SecurityError]
24
- #
25
- # @return Pathname
26
- def resolve!(path:)
27
- @root.join(path).tap do |resolved|
28
- relative = resolved.ascend.any? { |ancestor| ancestor.eql?(@root) }
29
- raise SecurityError, "unknown path=#{resolved}" unless relative
30
- end
31
- end
32
18
  end
33
19
  end
34
20
  end
@@ -19,7 +19,7 @@ module OmniAI
19
19
  def execute(path:)
20
20
  @logger.info("#{self.class.name}#execute path=#{path.inspect}")
21
21
 
22
- FileUtils.mkdir_p(resolve!(path:))
22
+ @driver.directory_create(path:)
23
23
  rescue SecurityError => e
24
24
  @logger.error(e.message)
25
25
  raise e
@@ -19,7 +19,7 @@ module OmniAI
19
19
  def execute(path:)
20
20
  @logger.info("#{self.class.name}#execute path=#{path.inspect}")
21
21
 
22
- FileUtils.rmdir(resolve!(path:))
22
+ @driver.directory_delete(path:)
23
23
  rescue SecurityError => e
24
24
  @logger.error(e.message)
25
25
  raise e
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module Tools
5
+ module Disk
6
+ # @example
7
+ # tool = OmniAI::Tools::Disk::SummaryTool.new(root: "./project")
8
+ # tool.execute
9
+ class DirectoryListTool < BaseTool
10
+ description "Summarizes the contents (files and directories) of a directory."
11
+
12
+ parameter :path, :string, description: "a path to the directory (e.g. `./foo/bar`)"
13
+
14
+ required %i[path]
15
+
16
+ # @return [String]
17
+ def execute(path: ".")
18
+ @logger.info("#{self.class.name}#execute")
19
+
20
+ @driver.directory_list(path:)
21
+ rescue SecurityError => e
22
+ @logger.error(e.message)
23
+ raise e
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -5,22 +5,22 @@ module OmniAI
5
5
  module Disk
6
6
  # @example
7
7
  # tool = OmniAI::Tools::Disk::DirectoryMoveTool.new(root: "./project")
8
- # tool.execute(old_path: "./foo", new_path: "./bar")
8
+ # tool.execute(path: "./foo", destination: "./bar")
9
9
  class DirectoryMoveTool < BaseTool
10
10
  description "Moves a directory from one location to another."
11
11
 
12
- parameter :old_path, :string, description: "a path (e.g. `./old`)"
13
- parameter :new_path, :string, description: "a path (e.g. `./new`)"
12
+ parameter :path, :string, description: "a path (e.g. `./old`)"
13
+ parameter :destination, :string, description: "a path (e.g. `./new`)"
14
14
 
15
- required %i[old_path new_path]
15
+ required %i[path destination]
16
16
 
17
- # @param old_path [String]
18
- # @param new_path [String]
17
+ # @param path [String]
18
+ # @param destination [String]
19
19
  #
20
20
  # @return [String]
21
- def execute(old_path:, new_path:)
22
- @logger.info("#{self.class.name}#execute old_path=#{old_path.inspect} new_path=#{new_path.inspect}")
23
- FileUtils.mv(resolve!(path: old_path), resolve!(path: new_path))
21
+ def execute(path:, destination:)
22
+ @logger.info("#{self.class.name}#execute path=#{path.inspect} destination=#{destination.inspect}")
23
+ @driver.directory_move(path:, destination:)
24
24
  rescue SecurityError => e
25
25
  @logger.error(e.message)
26
26
  raise e
@@ -18,9 +18,7 @@ module OmniAI
18
18
  # @return [String]
19
19
  def execute(path:)
20
20
  @logger.info("#{self.class.name}#execute path=#{path.inspect}")
21
-
22
- resolved = resolve!(path:)
23
- FileUtils.touch(resolved) unless File.exist?(resolved)
21
+ @driver.file_create(path:)
24
22
  rescue SecurityError => e
25
23
  @logger.error(e.message)
26
24
  raise e
@@ -20,8 +20,7 @@ module OmniAI
20
20
  # @return [String]
21
21
  def execute(path:)
22
22
  @logger.info("#{self.class.name}#execute path=#{path.inspect}")
23
-
24
- File.delete(resolve!(path:))
23
+ @driver.file_delete(path:)
25
24
  rescue SecurityError => e
26
25
  @logger.error(e.message)
27
26
  raise e
@@ -6,28 +6,24 @@ module OmniAI
6
6
  # @example
7
7
  # tool = OmniAI::Tools::Disk::FileMoveTool.new(root: "./project")
8
8
  # tool.execute(
9
- # old_path: "./README.txt",
10
- # new_path: "./README.md",
9
+ # path: "./README.txt",
10
+ # destination: "./README.md",
11
11
  # )
12
12
  class FileMoveTool < BaseTool
13
13
  description "Moves a file."
14
14
 
15
- parameter :old_path, :string, description: "a path (e.g. `./old.rb`)"
16
- parameter :new_path, :string, description: "a path (e.g. `./new.rb`)"
15
+ parameter :path, :string, description: "a path (e.g. `./old.rb`)"
16
+ parameter :destination, :string, description: "a path (e.g. `./new.rb`)"
17
17
 
18
- required %i[old_path new_path]
18
+ required %i[path destination]
19
19
 
20
- # @param old_path [String]
21
- # @param new_path [String]
20
+ # @param path [String]
21
+ # @param destination [String]
22
22
  #
23
23
  # @return [String]
24
- def execute(old_path:, new_path:)
25
- @logger.info("#{self.class.name}#execute old_path=#{old_path.inspect} new_path=#{new_path.inspect}")
26
-
27
- FileUtils.mv(
28
- resolve!(path: old_path),
29
- resolve!(path: new_path)
30
- )
24
+ def execute(path:, destination:)
25
+ @logger.info("#{self.class.name}#execute path=#{path.inspect} destination=#{destination.inspect}")
26
+ @driver.file_move(path:, destination:)
31
27
  rescue SecurityError => e
32
28
  @logger.info("ERROR: #{e.message}")
33
29
  raise e
@@ -18,7 +18,7 @@ module OmniAI
18
18
  # @return [String]
19
19
  def execute(path:)
20
20
  @logger.info("#{self.class.name}#execute path=#{path}")
21
- File.read(resolve!(path:))
21
+ @driver.file_read(path:)
22
22
  rescue StandardError => e
23
23
  @logger.error(e.message)
24
24
  raise e
@@ -24,12 +24,8 @@ module OmniAI
24
24
  # @param new_text [String]
25
25
  def execute(old_text:, new_text:, path:)
26
26
  @logger.info %(#{self.class.name}#execute old_text="#{old_text}" new_text="#{new_text}" path="#{path}")
27
-
28
- resolved = resolve!(path:)
29
- contents = File.read(resolved)
30
- modified = contents.gsub(old_text, new_text)
31
- File.write(resolved, modified)
32
- rescue StandardError => e
27
+ @driver.file_replace(old_text:, new_text:, path:)
28
+ rescue SecurityError => e
33
29
  @logger.error(e.message)
34
30
  raise e
35
31
  end
@@ -20,8 +20,8 @@ module OmniAI
20
20
  # @return [String]
21
21
  def execute(path:, text:)
22
22
  @logger.info("#{self.class.name}#execute path=#{path}")
23
- File.write(resolve!(path:), text)
24
- rescue StandardError => e
23
+ @driver.file_write(path:, text:)
24
+ rescue SecurityError => e
25
25
  @logger.error("ERROR: #{e.message}")
26
26
  raise e
27
27
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module Tools
5
+ module Disk
6
+ # A driver for interacting with a disk via various operations
7
+ class LocalDriver < BaseDriver
8
+ # @raise [SecurityError]
9
+ #
10
+ # @param path [String]
11
+ def directory_create(path:)
12
+ FileUtils.mkdir_p(resolve!(path:))
13
+ end
14
+
15
+ # @param path [String]
16
+ def directroy_delete(path:)
17
+ FileUtils.rmdir(resolve!(path:))
18
+ end
19
+
20
+ # @param path [String] optional
21
+ def directory_list(path: ".")
22
+ Dir.chdir(resolve!(path:)) do
23
+ Dir.glob("**/*").map { |path| summarize(path:) }.join("\n")
24
+ end
25
+ end
26
+
27
+ # @param path [String]
28
+ # @param destination [String]
29
+ def directory_move(path:, destination:)
30
+ FileUtils.mv(resolve!(path:), resolve!(path: destination))
31
+ end
32
+
33
+ # @param path [String]
34
+ def file_create(path:)
35
+ path = resolve!(path:)
36
+ FileUtils.touch(path) unless File.exist?(path)
37
+ end
38
+
39
+ # @param path [String]
40
+ def file_delete(path:)
41
+ File.delete(resolve!(path:))
42
+ end
43
+
44
+ # @param path [String]
45
+ # @param destination [String]
46
+ def file_move(path:, destination:)
47
+ FileUtils.mv(resolve!(path:), resolve!(path: destination))
48
+ end
49
+
50
+ # @param path [String]
51
+ #
52
+ # @return [String]
53
+ def file_read(path:)
54
+ File.read(resolve!(path:))
55
+ end
56
+
57
+ # @param old_text [String]
58
+ # @param new_text [String]
59
+ # @param path [String]
60
+ def file_replace(old_text:, new_text:, path:)
61
+ path = resolve!(path:)
62
+ contents = File.read(path)
63
+ text = contents.gsub(old_text, new_text)
64
+ File.write(path, text)
65
+ end
66
+
67
+ # @param path [String]
68
+ # @param text [String]
69
+ def file_write(path:, text:)
70
+ File.write(resolve!(path:), text)
71
+ end
72
+
73
+ protected
74
+
75
+ # @param path [String]
76
+ #
77
+ # @raise [SecurityError]
78
+ #
79
+ # @return Pathname
80
+ def resolve!(path:)
81
+ @root.join(path).tap do |resolved|
82
+ relative = resolved.ascend.any? { |ancestor| ancestor.eql?(@root) }
83
+ raise SecurityError, "unknown path=#{resolved}" unless relative
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -2,14 +2,18 @@
2
2
 
3
3
  module OmniAI
4
4
  module Tools
5
- # A tool for interacting with a computer. Be careful with using as it can perform actions on your computer!
5
+ # A tool for interacting with files and directories. Be careful using as it can perform actions on your computer!
6
6
  #
7
7
  # @example
8
- # computer = OmniAI::Tools::Computer::MacTool.new
9
- # computer.display # { "width": 2560, "height": 1440, "scale": 1 }
10
- # computer.screenshot
11
- class ComputerTool < OmniAI::Tool
12
- description "A tool for interacting with a computer."
8
+ # disk = OmniAI::Tools::DiskTool.new
9
+ # disk.execute(action: OmniAI::Tools::DiskTool::Action::FILE_CREATE, path: "./demo.rb")
10
+ # disk.execute(action: OmniAI::Tools::DiskTool::Action::FILE_WRITE, path: "./demo.rb", text: "puts 'Hello'")
11
+ # disk.execute(action: OmniAI::Tools::DiskTool::Action::FILE_READ, path: "./demo.rb")
12
+ # disk.execute(action: OmniAI::Tools::DiskTool::Action::FILE_DELETE, path: "./demo.rb")
13
+ class DiskTool < OmniAI::Tool
14
+ description <<~TEXT
15
+ A tool for interacting with a system. It is able to list, create, delete, move and modify directories and files.
16
+ TEXT
13
17
 
14
18
  module Action
15
19
  DIRECTORY_CREATE = "directory_create"
@@ -39,13 +43,13 @@ module OmniAI
39
43
 
40
44
  parameter :action, :string, enum: ACTIONS, description: <<~TEXT
41
45
  Options:
42
- * `#{Action::DIRECTORY_CREATE}`: creates a directory at a specific path
43
- * `#{Action::DIRECTORY_DELETE}`: deletes a directory at a specific path
44
- * `#{Action::DIRECTORY_MOVE}`: moves a directory from one path to another
45
- * `#{Action::DIRECTORY_LIST}`: lists the contents of a directory at a specific path
46
- * `#{Action::FILE_CREATE}`: creates a file at a specific path
47
- * `#{Action::FILE_DELETE}`: deletes a file at a specific path
48
- * `#{Action::FILE_MOVE}`: moves a file from one path to another
46
+ * `#{Action::DIRECTORY_CREATE}`: creates a directory at a specific `path`
47
+ * `#{Action::DIRECTORY_DELETE}`: deletes a directory at a specific `path`
48
+ * `#{Action::DIRECTORY_MOVE}`: moves a directory from `path` to (`to`)
49
+ * `#{Action::DIRECTORY_LIST}`: lists the contents of a directory at a specific `path` (use '.' for root)
50
+ * `#{Action::FILE_CREATE}`: creates a file at a specific `path`
51
+ * `#{Action::FILE_DELETE}`: deletes a file at a specific `path`
52
+ * `#{Action::FILE_MOVE}`: moves a file from `path` to another
49
53
  * `#{Action::FILE_READ}`: reads the contents of a file at a specific path
50
54
  * `#{Action::FILE_WRITE}`: writes the contents of a file at a specific path
51
55
  * `#{Action::FILE_REPLACE}`: replaces the contents of a file at a specific path
@@ -63,39 +67,61 @@ module OmniAI
63
67
  * `#{Action::FILE_REPLACE}`
64
68
  TEXT
65
69
 
66
- paramter :to, :string, description: <<~TEXT
70
+ parameter :destination, :string, description: <<~TEXT
67
71
  A file or directory path that is required for the following actions:
68
72
  * `#{Action::DIRECTORY_MOVE}`
69
73
  * `#{Action::FILE_MOVE}`
70
74
  TEXT
71
75
 
72
- # @param driver [Computer::Driver]
73
- def initialize(logger: Logger.new(IO::NULL))
76
+ parameter :text, :string, description: <<~TEXT
77
+ The text to be written to a file for the `#{Action::FILE_WRITE}` action.
78
+ TEXT
79
+
80
+ parameter :old_text, :string, description: <<~TEXT
81
+ The old text to be replaced in a file for the `#{Action::FILE_REPLACE}` action.
82
+ TEXT
83
+
84
+ parameter :new_text, :string, description: <<~TEXT
85
+ The new text to replace in a few file for the `#{Action::FILE_REPLACE}` action.
86
+ TEXT
87
+
88
+ required %i[action path]
89
+
90
+ # @param driver [OmniAI::Tools::Disk::BaseDriver]
91
+ # @param logger [Logger]
92
+ def initialize(driver:, logger: Logger.new(IO::NULL))
74
93
  @logger = logger
94
+ @driver = driver
75
95
  super()
76
96
  end
77
97
 
78
98
  # @param action [String]
79
99
  # @param path [String]
80
- # @param to [String]
81
- def execute(action:, path: nil, to: nil)
100
+ # @param destination [String] optional
101
+ # @param old_text [String] optional
102
+ # @param new_text [String] optional
103
+ # @param text [String] optional
104
+ def execute(action:, path:, destination: nil, old_text: nil, new_text: nil, text: nil)
82
105
  @logger.info({
83
106
  action:,
84
107
  path:,
85
- to:,
108
+ destination:,
109
+ old_text:,
110
+ new_text:,
111
+ text:,
86
112
  }.compact.map { |key, value| "#{key}=#{value.inspect}" }.join(" "))
87
113
 
88
114
  case action
89
- when Action::DIRECTORY_CREATE then Disk::DirectoryCreateTool.new(logger: @logger).execute(path:)
90
- when Action::DIRECTORY_DELETE then Disk::DirectoryDeleteTool.new(logger: @logger).execute(path:)
91
- when Action::DIRECTORY_MOVE then Disk::DirectoryMoveTool.new(logger: @logger).execute(path:, to:)
92
- when Action::DIRECTORY_LIST then Disk::DirectoryListTool.new(logger: @logger).execute(path:)
93
- when Action::FILE_CREATE then Disk::FileCreateTool.new(logger: @logger).execute(path:)
94
- when Action::FILE_DELETE then Disk::FileDeleteTool.new(logger: @logger).execute(path:)
95
- when Action::FILE_MOVE then Disk::FileMoveTool.new(logger: @logger).execute(path:, to:)
96
- when Action::FILE_READ then Disk::FileReadTool.new(logger: @logger).execute(path:)
97
- when Action::FILE_WRITE then Disk::FileWriteTool.new(logger: @logger).execute(path:)
98
- when Action::FILE_REPLACE then Disk::FileReplaceTool.new(logger: @logger).execute(path:)
115
+ when Action::DIRECTORY_CREATE then @driver.directory_create(path:)
116
+ when Action::DIRECTORY_DELETE then @driver.directory_delete(path:)
117
+ when Action::DIRECTORY_MOVE then @driver.directory_move(path:, destination:)
118
+ when Action::DIRECTORY_LIST then @driver.directory_list(path:)
119
+ when Action::FILE_CREATE then @driver.file_create(path:)
120
+ when Action::FILE_DELETE then @driver.file_delete(path:)
121
+ when Action::FILE_MOVE then @driver.file_move(path:, destination:)
122
+ when Action::FILE_READ then @driver.file_read(path:)
123
+ when Action::FILE_WRITE then @driver.file_write(path:, text:)
124
+ when Action::FILE_REPLACE then @driver.file_replace(old_text:, new_text:, path:)
99
125
  end
100
126
  end
101
127
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Tools
5
- VERSION = "0.7.0"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -81,9 +81,11 @@ files:
81
81
  - lib/omniai/tools/database/postgres_driver.rb
82
82
  - lib/omniai/tools/database/sqlite_driver.rb
83
83
  - lib/omniai/tools/database_tool.rb
84
+ - lib/omniai/tools/disk/base_driver.rb
84
85
  - lib/omniai/tools/disk/base_tool.rb
85
86
  - lib/omniai/tools/disk/directory_create_tool.rb
86
87
  - lib/omniai/tools/disk/directory_delete_tool.rb
88
+ - lib/omniai/tools/disk/directory_list_tool.rb
87
89
  - lib/omniai/tools/disk/directory_move_tool.rb
88
90
  - lib/omniai/tools/disk/file_create_tool.rb
89
91
  - lib/omniai/tools/disk/file_delete_tool.rb
@@ -91,7 +93,7 @@ files:
91
93
  - lib/omniai/tools/disk/file_read_tool.rb
92
94
  - lib/omniai/tools/disk/file_replace_tool.rb
93
95
  - lib/omniai/tools/disk/file_write_tool.rb
94
- - lib/omniai/tools/disk/summary_tool.rb
96
+ - lib/omniai/tools/disk/local_driver.rb
95
97
  - lib/omniai/tools/disk_tool.rb
96
98
  - lib/omniai/tools/docker/base_tool.rb
97
99
  - lib/omniai/tools/docker/compose_run_tool.rb
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- module Tools
5
- module Disk
6
- # @example
7
- # tool = OmniAI::Tools::Disk::SummaryTool.new(root: "./project")
8
- # tool.execute
9
- class SummaryTool < BaseTool
10
- description "Summarizes the contents (files and directories) of the project."
11
-
12
- # @return [String]
13
- def execute
14
- @logger.info("#{self.class.name}#execute")
15
-
16
- Dir.chdir(@root) do
17
- summary = Dir.glob("**/*").map { |path| summarize(path:) }.join("\n")
18
- @logger.debug(summary)
19
- summary
20
- end
21
- end
22
-
23
- private
24
-
25
- # @param path [String]
26
- def summarize(path:)
27
- if File.directory?(path)
28
- "📁 ./#{path}/"
29
- else
30
- "📄 ./#{path} (#{File.size(path)} bytes)"
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end