omniai-tools 0.8.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 +4 -4
- data/README.md +3 -11
- data/lib/omniai/tools/browser/text_field_area_set_tool.rb +0 -2
- data/lib/omniai/tools/browser/visit_tool.rb +0 -2
- data/lib/omniai/tools/computer/base_driver.rb +0 -2
- data/lib/omniai/tools/disk/base_driver.rb +91 -0
- data/lib/omniai/tools/disk/base_tool.rb +3 -17
- data/lib/omniai/tools/disk/directory_create_tool.rb +1 -1
- data/lib/omniai/tools/disk/directory_delete_tool.rb +1 -1
- data/lib/omniai/tools/disk/directory_list_tool.rb +28 -0
- data/lib/omniai/tools/disk/directory_move_tool.rb +9 -9
- data/lib/omniai/tools/disk/file_create_tool.rb +1 -3
- data/lib/omniai/tools/disk/file_delete_tool.rb +1 -2
- data/lib/omniai/tools/disk/file_move_tool.rb +10 -14
- data/lib/omniai/tools/disk/file_read_tool.rb +1 -1
- data/lib/omniai/tools/disk/file_replace_tool.rb +2 -6
- data/lib/omniai/tools/disk/file_write_tool.rb +2 -2
- data/lib/omniai/tools/disk/local_driver.rb +89 -0
- data/lib/omniai/tools/disk_tool.rb +43 -31
- data/lib/omniai/tools/version.rb +1 -1
- metadata +4 -2
- data/lib/omniai/tools/disk/summary_tool.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 385d159444de83c26eccbdf950ea03349cddb98a7120b8a9fc374cc8a0b2711b
|
4
|
+
data.tar.gz: ccbd00d1298d0a6f2b799172290d249e1a0dedf79067770b7d1702430464a952
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
184
|
-
|
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
|
|
@@ -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
|
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(
|
13
|
+
def initialize(driver:, logger: Logger.new(IO::NULL))
|
14
14
|
super()
|
15
|
-
@
|
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
|
@@ -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(
|
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 :
|
13
|
-
parameter :
|
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[
|
15
|
+
required %i[path destination]
|
16
16
|
|
17
|
-
# @param
|
18
|
-
# @param
|
17
|
+
# @param path [String]
|
18
|
+
# @param destination [String]
|
19
19
|
#
|
20
20
|
# @return [String]
|
21
|
-
def execute(
|
22
|
-
@logger.info("#{self.class.name}#execute
|
23
|
-
|
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
|
@@ -6,28 +6,24 @@ module OmniAI
|
|
6
6
|
# @example
|
7
7
|
# tool = OmniAI::Tools::Disk::FileMoveTool.new(root: "./project")
|
8
8
|
# tool.execute(
|
9
|
-
#
|
10
|
-
#
|
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 :
|
16
|
-
parameter :
|
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[
|
18
|
+
required %i[path destination]
|
19
19
|
|
20
|
-
# @param
|
21
|
-
# @param
|
20
|
+
# @param path [String]
|
21
|
+
# @param destination [String]
|
22
22
|
#
|
23
23
|
# @return [String]
|
24
|
-
def execute(
|
25
|
-
@logger.info("#{self.class.name}#execute
|
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
|
@@ -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
|
-
|
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
|
-
|
24
|
-
rescue
|
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
|
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
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
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
|
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
|
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,7 +67,7 @@ module OmniAI
|
|
63
67
|
* `#{Action::FILE_REPLACE}`
|
64
68
|
TEXT
|
65
69
|
|
66
|
-
parameter :
|
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}`
|
@@ -81,35 +85,43 @@ module OmniAI
|
|
81
85
|
The new text to replace in a few file for the `#{Action::FILE_REPLACE}` action.
|
82
86
|
TEXT
|
83
87
|
|
84
|
-
|
85
|
-
|
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))
|
86
93
|
@logger = logger
|
94
|
+
@driver = driver
|
87
95
|
super()
|
88
96
|
end
|
89
97
|
|
90
98
|
# @param action [String]
|
91
99
|
# @param path [String]
|
92
|
-
# @param
|
93
|
-
# @param old_text [String]
|
94
|
-
# @param new_text [String]
|
95
|
-
|
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)
|
96
105
|
@logger.info({
|
97
106
|
action:,
|
98
107
|
path:,
|
99
|
-
|
108
|
+
destination:,
|
109
|
+
old_text:,
|
110
|
+
new_text:,
|
111
|
+
text:,
|
100
112
|
}.compact.map { |key, value| "#{key}=#{value.inspect}" }.join(" "))
|
101
113
|
|
102
114
|
case action
|
103
|
-
when Action::DIRECTORY_CREATE then
|
104
|
-
when Action::DIRECTORY_DELETE then
|
105
|
-
when Action::DIRECTORY_MOVE then
|
106
|
-
when Action::DIRECTORY_LIST then
|
107
|
-
when Action::FILE_CREATE then
|
108
|
-
when Action::FILE_DELETE then
|
109
|
-
when Action::FILE_MOVE then
|
110
|
-
when Action::FILE_READ then
|
111
|
-
when Action::FILE_WRITE then
|
112
|
-
when Action::FILE_REPLACE then
|
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:)
|
113
125
|
end
|
114
126
|
end
|
115
127
|
end
|
data/lib/omniai/tools/version.rb
CHANGED
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.
|
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/
|
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
|