tidewave 0.1.3 → 0.3.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.
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "tidewave/file_tracker"
4
-
5
- class Tidewave::Tools::ListProjectFiles < Tidewave::Tools::Base
6
- tags :file_system_tool
7
-
8
- tool_name "list_project_files"
9
- description <<~DESC
10
- Returns a list of files in the project.
11
-
12
- By default, when no arguments are passed, it returns all files in the project that
13
- are not ignored by .gitignore.
14
-
15
- Optionally, a glob_pattern can be passed to filter this list. When a pattern is passed,
16
- the gitignore check will be skipped.
17
- DESC
18
-
19
- arguments do
20
- optional(:glob_pattern).maybe(:string).description("Optional: a glob pattern to filter the listed files. If a pattern is passed, the .gitignore check will be skipped.")
21
- end
22
-
23
- def call(glob_pattern: nil)
24
- Tidewave::FileTracker.project_files(glob_pattern: glob_pattern)
25
- end
26
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "net/http"
4
- require "uri"
5
- require "json"
6
-
7
- class Tidewave::Tools::PackageSearch < Tidewave::Tools::Base
8
- tool_name "package_search"
9
- description <<~DESCRIPTION
10
- Searches for packages on RubyGems.
11
-
12
- Use this tool if you need to find new packages to add to the project. Before using this tool,
13
- get an overview of the existing dependencies by using the `project_eval` tool and executing
14
- `Gem::Specification.map { |gem| [gem.name, gem.version] }`.
15
-
16
- The results are paginated, with 30 packages per page. Use the `page` parameter to fetch a specific page.
17
- DESCRIPTION
18
-
19
- arguments do
20
- required(:search).filled(:string).description("The search term")
21
- optional(:page).filled(:integer, gt?: 0).description("The page number to fetch. Must be greater than 0. Defaults to 1.")
22
- end
23
-
24
- def call(search:, page: 1)
25
- uri = URI("https://rubygems.org/api/v1/search.json")
26
- uri.query = URI.encode_www_form(query: search, page: page)
27
-
28
- response = Net::HTTP.get_response(uri)
29
-
30
- if response.is_a?(Net::HTTPSuccess)
31
- JSON.parse(response.body).map do |package|
32
- {
33
- name: package["name"],
34
- version: package["version"],
35
- downloads: package["downloads"],
36
- documentation_uri: package["documentation_uri"]
37
- }
38
- end
39
- else
40
- raise "RubyGems API request failed with status code: #{response.code}"
41
- end
42
- end
43
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "tidewave/file_tracker"
4
-
5
- class Tidewave::Tools::ReadProjectFile < Tidewave::Tools::Base
6
- tags :file_system_tool
7
-
8
- tool_name "read_project_file"
9
- description <<~DESCRIPTION
10
- Returns the contents of the given file.
11
- Supports an optional line_offset and count. To read the full file, only the path needs to be passed.
12
- DESCRIPTION
13
-
14
- arguments do
15
- required(:path).filled(:string).description("The path to the file to read. It is relative to the project root.")
16
- optional(:line_offset).filled(:integer).description("Optional: the starting line offset from which to read. Defaults to 0.")
17
- optional(:count).filled(:integer).description("Optional: the number of lines to read. Defaults to all.")
18
- end
19
-
20
- def call(path:, **keywords)
21
- Tidewave::FileTracker.validate_path_access!(path)
22
- _meta[:mtime], contents = Tidewave::FileTracker.read_file(path, **keywords)
23
- contents
24
- end
25
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "open3"
4
-
5
- class Tidewave::Tools::ShellEval < Tidewave::Tools::Base
6
- tags :file_system_tool
7
- class CommandFailedError < StandardError; end
8
-
9
- tool_name "shell_eval"
10
- description <<~DESCRIPTION
11
- Executes a shell command in the project root directory.
12
-
13
- The operating system is of flavor #{RUBY_PLATFORM}.
14
-
15
- Avoid using this tool for manipulating project files.
16
- Instead rely on the tools with the name matching `*_project_files`.
17
-
18
- Do not use this tool to evaluate Ruby code. Use `project_eval` instead.
19
- Do not use this tool for commands that run indefinitely,
20
- such as servers (like `bin/dev` or `npm run dev`),
21
- REPLs (`bin/rails console`) or file watchers.
22
-
23
- Only use this tool if other means are not available.
24
- DESCRIPTION
25
-
26
- arguments do
27
- required(:command).filled(:string).description("The shell command to execute. Avoid using this for file operations; use dedicated file system tools instead.")
28
- end
29
-
30
- def call(command:)
31
- stdout, status = Open3.capture2e(command)
32
- raise CommandFailedError, "Command failed with status #{status.exitstatus}:\n\n#{stdout}" unless status.exitstatus.zero?
33
-
34
- stdout.strip
35
- end
36
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "tidewave/file_tracker"
4
-
5
- class Tidewave::Tools::WriteProjectFile < Tidewave::Tools::Base
6
- tags :file_system_tool
7
-
8
- tool_name "write_project_file"
9
- description <<~DESCRIPTION
10
- Writes a file to the file system. If the file already exists, it will be overwritten.
11
-
12
- Note that this tool will fail if the file wasn't previously read with the `read_project_file` tool.
13
- DESCRIPTION
14
-
15
- arguments do
16
- required(:path).filled(:string).description("The path to the file to write. It is relative to the project root.")
17
- required(:content).filled(:string).description("The content to write to the file")
18
- optional(:atime).filled(:integer).hidden.description("The Unix timestamp this file was last accessed. Not to be used.")
19
- end
20
-
21
- def call(path:, content:, atime: nil)
22
- Tidewave::FileTracker.validate_path_is_writable!(path, atime)
23
- Tidewave::FileTracker.write_file(path, content)
24
- _meta[:mtime] = Time.now.to_i
25
-
26
- "OK"
27
- end
28
- end