shared_tools 0.1.3 → 0.2.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/CHANGELOG.md +10 -2
- data/README.md +36 -33
- data/lib/shared_tools/raix/what_is_the_weather.rb +3 -3
- data/lib/shared_tools/ruby_llm/edit_file.rb +1 -0
- data/lib/shared_tools/ruby_llm/incomplete/calculator_tool.rb +70 -0
- data/lib/shared_tools/ruby_llm/incomplete/composite_analysis_tool.rb +89 -0
- data/lib/shared_tools/ruby_llm/incomplete/data_science_kit.rb +128 -0
- data/lib/shared_tools/ruby_llm/incomplete/database_query_tool.rb +100 -0
- data/lib/shared_tools/ruby_llm/incomplete/devops_toolkit.rb +112 -0
- data/lib/shared_tools/ruby_llm/incomplete/error_handling_tool.rb +109 -0
- data/lib/shared_tools/ruby_llm/incomplete/secure_tool_template.rb +117 -0
- data/lib/shared_tools/ruby_llm/incomplete/weather_tool.rb +110 -0
- data/lib/shared_tools/ruby_llm/incomplete/workflow_manager_tool.rb +145 -0
- data/lib/shared_tools/ruby_llm/list_files.rb +1 -0
- data/lib/shared_tools/ruby_llm/mcp/github_mcp_server.rb +51 -0
- data/lib/shared_tools/ruby_llm/mcp/imcp.rb +28 -0
- data/lib/shared_tools/ruby_llm/mcp.rb +10 -0
- data/lib/shared_tools/ruby_llm/pdf_page_reader.rb +1 -0
- data/lib/shared_tools/ruby_llm/python_eval.rb +2 -1
- data/lib/shared_tools/ruby_llm/read_file.rb +1 -0
- data/lib/shared_tools/ruby_llm/ruby_eval.rb +2 -1
- data/lib/shared_tools/ruby_llm/run_shell_command.rb +2 -1
- data/lib/shared_tools/ruby_llm.rb +4 -1
- data/lib/shared_tools/version.rb +1 -1
- data/lib/shared_tools.rb +11 -2
- metadata +31 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a08d19c86e31c666473a9c3158500e969eb77dec788427183506e7ff9bec1c
|
4
|
+
data.tar.gz: c9d1f53340c99b733dcb629435ba55a6fc0a7ff142d71e456ff290013599dd1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e35bfb242027c468469b37542ecc20c2f5c9748c60f95925bb2796339d73f038704b29facc2f648eb0bb0c5c3b827d564371bfbb2970b1eddb4f3e736519c80e
|
7
|
+
data.tar.gz: abafd44a016e354e4fd84df3b518ccd1715b37f8a31e795df9f499301ac5a2ef5aa78fcdbd2e4673ac2aa2d76cce42bbcd973484e9ad487f4feddbaf3cba88b6
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
3
|
## Unreleased
|
4
|
-
### [0.1.3] 2025-06-18
|
5
|
-
- tweaking the load all tools process
|
6
4
|
|
7
5
|
## Released
|
8
6
|
|
7
|
+
### [0.2.0] 2025-07-01
|
8
|
+
- added ruby_llm/mcp/github_mcp_server.rb example
|
9
|
+
- added SharedTools.mcp_servers as an Array of MCP servers
|
10
|
+
- added class method name to tool classes as a snake_case of the class name
|
11
|
+
- added ruby_llm/mcp/imcp.rb to get stuff from MacOS apps
|
12
|
+
- added ruby_llm/incomplete directory with some under-development example tools
|
13
|
+
|
14
|
+
### [0.1.3] 2025-06-18
|
15
|
+
- tweaking the load all tools process
|
16
|
+
|
9
17
|
### [0.1.2] 2025-06-10
|
10
18
|
- added `zeitwerk` gem
|
11
19
|
|
data/README.md
CHANGED
@@ -10,56 +10,59 @@ A Ruby gem providing a collection of common tools (call-back functions) for use
|
|
10
10
|
- omniai: multi-provider `gem install omniai-tools` (Not part of the SharedTools namespace)
|
11
11
|
- more to come ...
|
12
12
|
|
13
|
-
##
|
14
|
-
|
15
|
-
Add this line to your application's Gemfile:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
gem 'shared_tools'
|
19
|
-
```
|
20
|
-
|
21
|
-
And then execute:
|
22
|
-
|
23
|
-
```bash
|
24
|
-
bundle install
|
25
|
-
```
|
26
|
-
|
27
|
-
Or install it yourself as:
|
28
|
-
|
29
|
-
```bash
|
30
|
-
gem install shared_tools
|
31
|
-
```
|
13
|
+
## Recent Changes
|
32
14
|
|
33
|
-
|
15
|
+
### Version 0.2.0
|
34
16
|
|
35
|
-
|
17
|
+
- ability to use the `ruby_llm-mcp` gem was added with two example MCP client instances for some useful MCP servers: github-mcp-server and iMCP.app
|
18
|
+
- added `SharedTools.mcp_servers` Array to hold defined client instances.
|
19
|
+
- added a class method `name` to `RubyLLM::Tool` subclasses to define the snake_case String format of the class basename.
|
36
20
|
|
37
|
-
|
38
|
-
require 'shared_tools'
|
39
|
-
```
|
40
|
-
|
41
|
-
### Loading RubyLLM Tools
|
42
|
-
|
43
|
-
RubyLLM tools are loaded conditionally when needed:
|
21
|
+
## Installation
|
44
22
|
|
45
23
|
```ruby
|
46
|
-
|
24
|
+
gem install shared_tools
|
47
25
|
|
48
26
|
# Load all RubyLLM tools (requires ruby_llm gem to be available and loaded first)
|
49
|
-
require 'shared_tools/ruby_llm'
|
27
|
+
require 'shared_tools/ruby_llm' # multiple API libraries are supported besides ruby_llm
|
50
28
|
|
51
29
|
# Or load a specific tool directly
|
52
30
|
require 'shared_tools/ruby_llm/edit_file'
|
53
31
|
require 'shared_tools/ruby_llm/read_file'
|
54
32
|
require 'shared_tools/ruby_llm/python_eval'
|
55
|
-
|
33
|
+
|
34
|
+
# Or load clients for defined MCP servers
|
35
|
+
# Load all the MCP clients for the ruby_llm library
|
36
|
+
require 'shared_tools/ruby_llm/mcp'
|
37
|
+
|
38
|
+
# Or just the ones you want
|
39
|
+
require 'shared_tools/ruby_llm/mcp/github_mcp_server'
|
40
|
+
require 'shared_tools/ruby_llm/mcp/icmp' # MacOS data server
|
41
|
+
|
42
|
+
# The client instances for ruby_llm/mcp servers are available
|
43
|
+
SharedTools.mcp_servers # An Array of MCP clients
|
44
|
+
|
45
|
+
# In ruby_llm library access the tools from MCP servers
|
46
|
+
@tools = []
|
47
|
+
SharedTools.mcp_servers.size.time do |server_inx|
|
48
|
+
@tools += SharedTools.mcp_servers[server_inx].tools
|
49
|
+
end
|
50
|
+
chat = RubyLLM.chat
|
51
|
+
chat.with_tools(@tools)
|
56
52
|
```
|
57
53
|
|
58
|
-
|
54
|
+
## Tips for Tool Authors
|
55
|
+
|
56
|
+
- Provide a clear comprehensive description for your tool and its parameters
|
57
|
+
- Include usage examples in your documentation
|
58
|
+
- Ensure your tool is compatible with different Ruby versions and environments
|
59
|
+
- Make sure your tool is in the correct directory for the library to which it belongs
|
60
|
+
|
61
|
+
## Rails and Autoloader Compatibility
|
59
62
|
|
60
63
|
This gem uses Zeitwerk for autoloading, making it fully compatible with Rails and other Ruby applications that use modern autoloaders. RubyLLM tools are excluded from autoloading and loaded manually to avoid namespace conflicts.
|
61
64
|
|
62
65
|
|
63
|
-
|
66
|
+
Special Thanks
|
64
67
|
|
65
68
|
A special shout-out to Kevin's [omniai-tools](https://github.com/your-github-url/omniai-tools) gem, which is a curated collection of tools for use with his OmniAI gem.
|
@@ -3,11 +3,11 @@
|
|
3
3
|
require_relative "../../shared_tools"
|
4
4
|
|
5
5
|
module SharedTools
|
6
|
-
verify_gem :
|
6
|
+
verify_gem :raix
|
7
7
|
|
8
8
|
class WhatIsTheWeather
|
9
|
-
include Raix::ChatCompletion
|
10
|
-
include Raix::FunctionDispatch
|
9
|
+
include ::Raix::ChatCompletion
|
10
|
+
include ::Raix::FunctionDispatch
|
11
11
|
|
12
12
|
function :check_weather,
|
13
13
|
"Check the weather for a location",
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# calculator_tool.rb - Simple custom tool example
|
2
|
+
require 'ruby_llm/tool'
|
3
|
+
|
4
|
+
module Tools
|
5
|
+
class Calculator < RubyLLM::Tool
|
6
|
+
def self.name = "calculator"
|
7
|
+
|
8
|
+
description <<~DESCRIPTION
|
9
|
+
Perform advanced mathematical calculations with comprehensive error handling and validation.
|
10
|
+
This tool supports basic arithmetic operations, parentheses, and common mathematical functions.
|
11
|
+
It provides safe evaluation of mathematical expressions without executing arbitrary code,
|
12
|
+
making it suitable for use in AI-assisted calculations where security is important.
|
13
|
+
The tool returns formatted results with configurable precision and helpful error messages
|
14
|
+
when invalid expressions are provided.
|
15
|
+
DESCRIPTION
|
16
|
+
|
17
|
+
param :expression,
|
18
|
+
desc: <<~DESC,
|
19
|
+
Mathematical expression to evaluate using standard arithmetic operators and parentheses.
|
20
|
+
Supported operations include: addition (+), subtraction (-), multiplication (*), division (/),
|
21
|
+
and parentheses for grouping. Examples: '2 + 2', '(10 * 5) / 2', '15.5 - 3.2'.
|
22
|
+
Only numeric characters, operators, parentheses, decimal points, and spaces are allowed
|
23
|
+
for security reasons. Complex mathematical functions are not supported in this version.
|
24
|
+
DESC
|
25
|
+
type: :string,
|
26
|
+
required: true
|
27
|
+
|
28
|
+
param :precision,
|
29
|
+
desc: <<~DESC,
|
30
|
+
Number of decimal places to display in the result. Must be a non-negative integer.
|
31
|
+
Set to 0 for whole numbers only, or higher values for more precise decimal results.
|
32
|
+
Default is 2 decimal places, which works well for most financial and general calculations.
|
33
|
+
Maximum precision is limited to 10 decimal places to prevent excessive output.
|
34
|
+
DESC
|
35
|
+
type: :integer,
|
36
|
+
default: 2
|
37
|
+
|
38
|
+
def execute(expression:, precision: 2)
|
39
|
+
begin
|
40
|
+
# Use safe evaluation instead of raw eval
|
41
|
+
result = safe_eval(expression)
|
42
|
+
formatted_result = result.round(precision)
|
43
|
+
|
44
|
+
{
|
45
|
+
success: true,
|
46
|
+
result: formatted_result,
|
47
|
+
expression: expression,
|
48
|
+
precision: precision
|
49
|
+
}
|
50
|
+
rescue => e
|
51
|
+
{
|
52
|
+
success: false,
|
53
|
+
error: "Invalid expression: #{e.message}",
|
54
|
+
expression: expression,
|
55
|
+
suggestion: "Try expressions like '2 + 2' or '10 * 5'"
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def safe_eval(expression)
|
63
|
+
# Implement safe mathematical evaluation
|
64
|
+
# This is a simplified example - use a proper math parser in production
|
65
|
+
allowed_chars = /\A[0-9+\-*\/\(\)\.\s]+\z/
|
66
|
+
raise "Invalid characters in expression" unless expression.match?(allowed_chars)
|
67
|
+
eval(expression)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# composite_analysis_tool.rb - Tool that uses other tools
|
2
|
+
require 'ruby_llm/tool'
|
3
|
+
|
4
|
+
module Tools
|
5
|
+
class CompositeAnalysis < RubyLLM::Tool
|
6
|
+
def self.name = "composite_analysis"
|
7
|
+
|
8
|
+
description <<~DESCRIPTION
|
9
|
+
Perform comprehensive multi-stage data analysis by orchestrating multiple specialized tools
|
10
|
+
to provide complete insights from various data sources. This composite tool automatically
|
11
|
+
determines the appropriate data fetching method (web scraping for URLs, file reading for
|
12
|
+
local paths), analyzes data structure and content, generates statistical insights,
|
13
|
+
and suggests appropriate visualizations based on the data characteristics.
|
14
|
+
Ideal for exploratory data analysis workflows where you need a complete picture
|
15
|
+
from initial data loading through final insights.
|
16
|
+
DESCRIPTION
|
17
|
+
|
18
|
+
param :data_source,
|
19
|
+
desc: <<~DESC,
|
20
|
+
Primary data source to analyze. Can be either a local file path or a web URL.
|
21
|
+
For files: Use relative or absolute paths to CSV, JSON, XML, or text files.
|
22
|
+
For URLs: Use complete HTTP/HTTPS URLs to accessible data endpoints or web pages.
|
23
|
+
The tool automatically detects the source type and uses appropriate fetching methods.
|
24
|
+
Examples: './data/sales.csv', '/home/user/data.json', 'https://api.example.com/data'
|
25
|
+
DESC
|
26
|
+
type: :string,
|
27
|
+
required: true
|
28
|
+
|
29
|
+
def execute(data_source:)
|
30
|
+
results = {}
|
31
|
+
|
32
|
+
begin
|
33
|
+
# Step 1: Fetch data using appropriate tool
|
34
|
+
if data_source.start_with?('http')
|
35
|
+
results[:data] = fetch_web_data(data_source)
|
36
|
+
else
|
37
|
+
results[:data] = read_file_data(data_source)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Step 2: Analyze data structure
|
41
|
+
results[:structure] = analyze_data_structure(results[:data])
|
42
|
+
|
43
|
+
# Step 3: Generate insights
|
44
|
+
results[:insights] = generate_insights(results[:data], results[:structure])
|
45
|
+
|
46
|
+
# Step 4: Create visualizations if applicable
|
47
|
+
if results[:structure][:numeric_columns]&.any?
|
48
|
+
results[:visualizations] = suggest_visualizations(results[:structure])
|
49
|
+
end
|
50
|
+
|
51
|
+
{
|
52
|
+
success: true,
|
53
|
+
analysis: results,
|
54
|
+
data_source: data_source,
|
55
|
+
analyzed_at: Time.now.iso8601
|
56
|
+
}
|
57
|
+
rescue => e
|
58
|
+
{
|
59
|
+
success: false,
|
60
|
+
error: e.message,
|
61
|
+
data_source: data_source,
|
62
|
+
partial_results: results
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def fetch_web_data(url)
|
70
|
+
# Use shared web tools or custom HTTP client
|
71
|
+
end
|
72
|
+
|
73
|
+
def read_file_data(file_path)
|
74
|
+
# Use shared file tools
|
75
|
+
end
|
76
|
+
|
77
|
+
def analyze_data_structure(data)
|
78
|
+
# Implementation for data structure analysis
|
79
|
+
end
|
80
|
+
|
81
|
+
def generate_insights(data, structure)
|
82
|
+
# Implementation for insight generation
|
83
|
+
end
|
84
|
+
|
85
|
+
def suggest_visualizations(structure)
|
86
|
+
# Implementation for visualization suggestions
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# data_science_kit.rb - Analytics and ML tools
|
2
|
+
require 'ruby_llm/tool'
|
3
|
+
|
4
|
+
module Tools
|
5
|
+
class DataScienceKit < RubyLLM::Tool
|
6
|
+
def self.name = "data_science_kit"
|
7
|
+
|
8
|
+
description <<~DESCRIPTION
|
9
|
+
Comprehensive data science and analytics toolkit for performing statistical analysis,
|
10
|
+
machine learning tasks, and data exploration on various data sources. This tool provides
|
11
|
+
a unified interface for common data science operations including descriptive statistics,
|
12
|
+
correlation analysis, time series analysis, clustering algorithms, and predictive modeling.
|
13
|
+
It automatically handles data loading, validation, preprocessing, and result formatting.
|
14
|
+
Supports multiple data formats and provides detailed analysis results with visualizations
|
15
|
+
recommendations and statistical significance testing where applicable.
|
16
|
+
DESCRIPTION
|
17
|
+
|
18
|
+
param :analysis_type,
|
19
|
+
desc: <<~DESC,
|
20
|
+
Type of data science analysis to perform:
|
21
|
+
- 'statistical_summary': Descriptive statistics, distributions, outlier detection
|
22
|
+
- 'correlation_analysis': Correlation matrices, feature relationships, dependency analysis
|
23
|
+
- 'time_series': Trend analysis, seasonality detection, forecasting
|
24
|
+
- 'clustering': K-means, hierarchical clustering, cluster analysis
|
25
|
+
- 'prediction': Regression analysis, classification, predictive modeling
|
26
|
+
Each analysis type requires specific data formats and optional parameters.
|
27
|
+
DESC
|
28
|
+
type: :string,
|
29
|
+
required: true,
|
30
|
+
enum: ["statistical_summary", "correlation_analysis", "time_series", "clustering", "prediction"]
|
31
|
+
|
32
|
+
param :data_source,
|
33
|
+
desc: <<~DESC,
|
34
|
+
Data source specification for analysis. Can be:
|
35
|
+
- File path: Relative or absolute path to CSV, JSON, Excel, or Parquet files
|
36
|
+
- Database query: SQL SELECT statement for database-sourced data
|
37
|
+
- API endpoint: HTTP URL for REST API data sources
|
38
|
+
The tool automatically detects the format and applies appropriate parsing.
|
39
|
+
Examples: './sales_data.csv', 'SELECT * FROM transactions', 'https://api.company.com/data'
|
40
|
+
DESC
|
41
|
+
type: :string,
|
42
|
+
required: true
|
43
|
+
|
44
|
+
param :parameters,
|
45
|
+
desc: <<~DESC,
|
46
|
+
Hash of analysis-specific parameters and configuration options:
|
47
|
+
- statistical_summary: confidence_level, include_quartiles, outlier_method
|
48
|
+
- correlation_analysis: method (pearson/spearman), significance_level
|
49
|
+
- time_series: date_column, value_column, frequency, forecast_periods
|
50
|
+
- clustering: n_clusters, algorithm (kmeans/hierarchical), distance_metric
|
51
|
+
- prediction: target_column, feature_columns, model_type, validation_split
|
52
|
+
Default empty hash uses standard parameters for each analysis type.
|
53
|
+
DESC
|
54
|
+
type: :hash,
|
55
|
+
default: {}
|
56
|
+
|
57
|
+
def execute(analysis_type:, data_source:, parameters: {})
|
58
|
+
begin
|
59
|
+
# Load and validate data
|
60
|
+
data = load_data(data_source)
|
61
|
+
validate_data_for_analysis(data, analysis_type)
|
62
|
+
|
63
|
+
# Perform analysis
|
64
|
+
result = case analysis_type
|
65
|
+
when "statistical_summary"
|
66
|
+
generate_statistical_summary(data, parameters)
|
67
|
+
when "correlation_analysis"
|
68
|
+
perform_correlation_analysis(data, parameters)
|
69
|
+
when "time_series"
|
70
|
+
analyze_time_series(data, parameters)
|
71
|
+
when "clustering"
|
72
|
+
perform_clustering(data, parameters)
|
73
|
+
when "prediction"
|
74
|
+
generate_predictions(data, parameters)
|
75
|
+
end
|
76
|
+
|
77
|
+
{
|
78
|
+
success: true,
|
79
|
+
analysis_type: analysis_type,
|
80
|
+
result: result,
|
81
|
+
data_summary: summarize_data(data),
|
82
|
+
analyzed_at: Time.now.iso8601
|
83
|
+
}
|
84
|
+
rescue => e
|
85
|
+
{
|
86
|
+
success: false,
|
87
|
+
error: e.message,
|
88
|
+
analysis_type: analysis_type,
|
89
|
+
data_source: data_source
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def load_data(source)
|
97
|
+
# Implementation for data loading from various sources
|
98
|
+
end
|
99
|
+
|
100
|
+
def validate_data_for_analysis(data, analysis_type)
|
101
|
+
# Implementation for data validation
|
102
|
+
end
|
103
|
+
|
104
|
+
def generate_statistical_summary(data, parameters)
|
105
|
+
# Implementation for statistical summary
|
106
|
+
end
|
107
|
+
|
108
|
+
def perform_correlation_analysis(data, parameters)
|
109
|
+
# Implementation for correlation analysis
|
110
|
+
end
|
111
|
+
|
112
|
+
def analyze_time_series(data, parameters)
|
113
|
+
# Implementation for time series analysis
|
114
|
+
end
|
115
|
+
|
116
|
+
def perform_clustering(data, parameters)
|
117
|
+
# Implementation for clustering
|
118
|
+
end
|
119
|
+
|
120
|
+
def generate_predictions(data, parameters)
|
121
|
+
# Implementation for prediction
|
122
|
+
end
|
123
|
+
|
124
|
+
def summarize_data(data)
|
125
|
+
# Implementation for data summary
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# database_query_tool.rb - Database interaction example
|
2
|
+
require 'ruby_llm/tool'
|
3
|
+
require 'sequel'
|
4
|
+
|
5
|
+
module Tools
|
6
|
+
class DatabaseQuery < RubyLLM::Tool
|
7
|
+
def self.name = "database_query"
|
8
|
+
|
9
|
+
description <<~DESCRIPTION
|
10
|
+
Execute safe, read-only database queries with automatic connection management and security controls.
|
11
|
+
This tool is designed for secure data retrieval operations only, restricting access to SELECT statements
|
12
|
+
to prevent any data modification. It includes automatic connection pooling, query result limiting,
|
13
|
+
and comprehensive error handling. The tool supports multiple database configurations through
|
14
|
+
environment variables and ensures all connections are properly closed after use.
|
15
|
+
Perfect for AI-assisted data analysis and reporting workflows where read-only access is required.
|
16
|
+
DESCRIPTION
|
17
|
+
|
18
|
+
param :query,
|
19
|
+
desc: <<~DESC,
|
20
|
+
SQL SELECT query to execute against the database. Only SELECT statements are permitted
|
21
|
+
for security reasons - INSERT, UPDATE, DELETE, and DDL statements will be rejected.
|
22
|
+
The query should be well-formed SQL appropriate for the target database system.
|
23
|
+
Examples: 'SELECT * FROM users WHERE active = true', 'SELECT COUNT(*) FROM orders'.
|
24
|
+
Table and column names should match the database schema exactly.
|
25
|
+
DESC
|
26
|
+
type: :string,
|
27
|
+
required: true
|
28
|
+
|
29
|
+
param :database,
|
30
|
+
desc: <<~DESC,
|
31
|
+
Database configuration name to use for the connection. This corresponds to environment
|
32
|
+
variables like DATABASE_URL, STAGING_DATABASE_URL, etc. The tool will look for
|
33
|
+
an environment variable named {DATABASE_NAME}_DATABASE_URL (uppercase).
|
34
|
+
Default is 'default' which looks for DEFAULT_DATABASE_URL environment variable.
|
35
|
+
Common values: 'default', 'staging', 'analytics', 'reporting'.
|
36
|
+
DESC
|
37
|
+
type: :string,
|
38
|
+
default: "default"
|
39
|
+
|
40
|
+
param :limit,
|
41
|
+
desc: <<~DESC,
|
42
|
+
Maximum number of rows to return from the query to prevent excessive memory usage
|
43
|
+
and long response times. The tool automatically adds a LIMIT clause if one is not
|
44
|
+
present in the original query. Set to a reasonable value based on expected data size.
|
45
|
+
Minimum: 1, Maximum: 10000, Default: 100. For large datasets, consider using
|
46
|
+
pagination or more specific WHERE clauses.
|
47
|
+
DESC
|
48
|
+
type: :integer,
|
49
|
+
default: 100
|
50
|
+
|
51
|
+
def execute(query:, database: "default", limit: 100)
|
52
|
+
begin
|
53
|
+
# Security: Only allow SELECT queries
|
54
|
+
normalized_query = query.strip.downcase
|
55
|
+
unless normalized_query.start_with?('select')
|
56
|
+
raise "Only SELECT queries are allowed for security"
|
57
|
+
end
|
58
|
+
|
59
|
+
db = connect_to_database(database)
|
60
|
+
limited_query = add_limit_to_query(query, limit)
|
61
|
+
|
62
|
+
results = db[limited_query].all
|
63
|
+
|
64
|
+
{
|
65
|
+
success: true,
|
66
|
+
query: limited_query,
|
67
|
+
row_count: results.length,
|
68
|
+
data: results,
|
69
|
+
database: database,
|
70
|
+
executed_at: Time.now.iso8601
|
71
|
+
}
|
72
|
+
rescue => e
|
73
|
+
{
|
74
|
+
success: false,
|
75
|
+
error: e.message,
|
76
|
+
query: query,
|
77
|
+
database: database
|
78
|
+
}
|
79
|
+
ensure
|
80
|
+
db&.disconnect
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def connect_to_database(database_name)
|
87
|
+
# Implementation depends on your database setup
|
88
|
+
connection_string = ENV["#{database_name.upcase}_DATABASE_URL"]
|
89
|
+
raise "Database connection not configured for #{database_name}" unless connection_string
|
90
|
+
|
91
|
+
Sequel.connect(connection_string)
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_limit_to_query(query, limit)
|
95
|
+
# Add LIMIT clause if not present
|
96
|
+
query += " LIMIT #{limit}" unless query.downcase.include?('limit')
|
97
|
+
query
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# devops_toolkit.rb - System administration tools
|
2
|
+
require 'ruby_llm/tool'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module Tools
|
6
|
+
class DevOpsToolkit < RubyLLM::Tool
|
7
|
+
def self.name = "devops_toolkit"
|
8
|
+
|
9
|
+
description <<~DESCRIPTION
|
10
|
+
Comprehensive DevOps and system administration toolkit for managing application deployments,
|
11
|
+
monitoring system health, and performing operational tasks across different environments.
|
12
|
+
This tool provides secure, audited access to common DevOps operations including deployments,
|
13
|
+
rollbacks, health checks, log analysis, and metrics collection. It includes built-in safety
|
14
|
+
mechanisms for production environments, comprehensive logging for compliance, and support
|
15
|
+
for multiple deployment environments. All operations are logged and require appropriate
|
16
|
+
permissions and confirmations for sensitive environments.
|
17
|
+
DESCRIPTION
|
18
|
+
|
19
|
+
param :operation,
|
20
|
+
desc: <<~DESC,
|
21
|
+
Specific DevOps operation to perform:
|
22
|
+
- 'deploy': Deploy application code to the specified environment
|
23
|
+
- 'rollback': Revert to the previous stable deployment version
|
24
|
+
- 'health_check': Perform comprehensive health and status checks
|
25
|
+
- 'log_analysis': Analyze application and system logs for issues
|
26
|
+
- 'metric_collection': Gather and report system and application metrics
|
27
|
+
Each operation has specific requirements and safety checks.
|
28
|
+
DESC
|
29
|
+
type: :string,
|
30
|
+
required: true,
|
31
|
+
enum: ["deploy", "rollback", "health_check", "log_analysis", "metric_collection"]
|
32
|
+
|
33
|
+
param :environment,
|
34
|
+
desc: <<~DESC,
|
35
|
+
Target environment for the DevOps operation:
|
36
|
+
- 'development': Local or shared development environment (minimal restrictions)
|
37
|
+
- 'staging': Pre-production environment for testing (moderate restrictions)
|
38
|
+
- 'production': Live production environment (maximum restrictions and confirmations)
|
39
|
+
Production operations require explicit confirmation via the 'production_confirmed' option.
|
40
|
+
DESC
|
41
|
+
type: :string,
|
42
|
+
default: "staging",
|
43
|
+
enum: ["development", "staging", "production"]
|
44
|
+
|
45
|
+
param :options,
|
46
|
+
desc: <<~DESC,
|
47
|
+
Hash of operation-specific options and parameters:
|
48
|
+
- For deploy: version, branch, rollback_on_failure, notification_channels
|
49
|
+
- For rollback: target_version, confirmation_required
|
50
|
+
- For health_check: services_to_check, timeout_seconds
|
51
|
+
- For log_analysis: time_range, log_level, search_patterns
|
52
|
+
- For metric_collection: metric_types, time_window, output_format
|
53
|
+
Production operations require 'production_confirmed: true' for safety.
|
54
|
+
DESC
|
55
|
+
type: :hash,
|
56
|
+
default: {}
|
57
|
+
|
58
|
+
def execute(operation:, environment: "staging", options: {})
|
59
|
+
# Security: Require explicit production confirmation
|
60
|
+
if environment == "production" && !options[:production_confirmed]
|
61
|
+
return {
|
62
|
+
success: false,
|
63
|
+
error: "Production operations require explicit confirmation",
|
64
|
+
required_option: "production_confirmed: true"
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
case operation
|
69
|
+
when "deploy"
|
70
|
+
perform_deployment(environment, options)
|
71
|
+
when "rollback"
|
72
|
+
perform_rollback(environment, options)
|
73
|
+
when "health_check"
|
74
|
+
perform_health_check(environment, options)
|
75
|
+
when "log_analysis"
|
76
|
+
analyze_logs(environment, options)
|
77
|
+
when "metric_collection"
|
78
|
+
collect_metrics(environment, options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def perform_deployment(environment, options)
|
85
|
+
# Implementation for deployment logic
|
86
|
+
{
|
87
|
+
success: true,
|
88
|
+
operation: "deploy",
|
89
|
+
environment: environment,
|
90
|
+
deployed_at: Time.now.iso8601,
|
91
|
+
deployment_id: SecureRandom.uuid,
|
92
|
+
details: "Deployment completed successfully"
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def perform_rollback(environment, options)
|
97
|
+
# Implementation for rollback logic
|
98
|
+
end
|
99
|
+
|
100
|
+
def perform_health_check(environment, options)
|
101
|
+
# Implementation for health check logic
|
102
|
+
end
|
103
|
+
|
104
|
+
def analyze_logs(environment, options)
|
105
|
+
# Implementation for log analysis logic
|
106
|
+
end
|
107
|
+
|
108
|
+
def collect_metrics(environment, options)
|
109
|
+
# Implementation for metric collection logic
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|