aia 0.9.7 → 0.9.9

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.config/tocer/configuration.yml +2 -1
  3. data/.version +1 -1
  4. data/CHANGELOG.md +15 -1
  5. data/README.md +43 -0
  6. data/Rakefile +16 -8
  7. data/examples/directives/ask.rb +21 -0
  8. data/examples/tools/edit_file.rb +2 -0
  9. data/examples/tools/incomplete/calculator_tool.rb +70 -0
  10. data/examples/tools/incomplete/composite_analysis_tool.rb +89 -0
  11. data/examples/tools/incomplete/data_science_kit.rb +128 -0
  12. data/examples/tools/incomplete/database_query_tool.rb +100 -0
  13. data/examples/tools/incomplete/devops_toolkit.rb +112 -0
  14. data/examples/tools/incomplete/error_handling_tool.rb +109 -0
  15. data/examples/tools/incomplete/pdf_page_reader.rb +32 -0
  16. data/examples/tools/incomplete/secure_tool_template.rb +117 -0
  17. data/examples/tools/incomplete/weather_tool.rb +110 -0
  18. data/examples/tools/incomplete/workflow_manager_tool.rb +145 -0
  19. data/examples/tools/list_files.rb +2 -0
  20. data/examples/tools/mcp/README.md +1 -0
  21. data/examples/tools/mcp/github_mcp_server.rb +41 -0
  22. data/examples/tools/mcp/imcp.rb +15 -0
  23. data/examples/tools/read_file.rb +2 -0
  24. data/examples/tools/run_shell_command.rb +2 -0
  25. data/lib/aia/chat_processor_service.rb +3 -26
  26. data/lib/aia/config.rb +542 -414
  27. data/lib/aia/context_manager.rb +3 -8
  28. data/lib/aia/directive_processor.rb +24 -11
  29. data/lib/aia/ruby_llm_adapter.rb +78 -10
  30. data/lib/aia/session.rb +313 -215
  31. data/lib/aia/ui_presenter.rb +7 -5
  32. data/lib/aia/utility.rb +26 -6
  33. data/lib/aia.rb +5 -1
  34. metadata +32 -12
  35. data/lib/aia/shell_command_executor.rb +0 -109
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21134c8c9fa3664309baf0c3d1bce2857dffd3dd1ad8c554c7cb15ac48b57634
4
- data.tar.gz: 46f64bdbefe73eede9add530bad3a4957f6b7033706a1d1daf5aa6bef1fb6084
3
+ metadata.gz: e7e11bfdcf25a6688acbb7f283673964f7b24cd982fef2af374396b166eb3ede
4
+ data.tar.gz: b826a553b444d212949a4b6ef24fcdbd5d0674328e5e294a5981caccfa5aa239
5
5
  SHA512:
6
- metadata.gz: dc1273757619b1962986e1dfac94b8d10b2c493ff0cf0d01d0938c65a902700d96484d42e661770328a4f6f904a1265f6a136964fb8c31218ed22135fed806dc
7
- data.tar.gz: edc7124424b74f7d167a78635abd7302eb05cd4208058947dd8700e5e05c1200eba47346d1f0beea0ed9ea37a5875ca7cb585d40752dbcf88c64063dc278e398
6
+ metadata.gz: f775c09be01764332b7551830f5a9ff801d957c3965a0ae4ba4d83b640533503a10b0f4c991482c8ee768a516be8f8f29db9ed73e3ccd08998121be3aecc68a3
7
+ data.tar.gz: 8cbd963323424416b75cdb0e33e2c1ad71c26b956a8ee2c5621f5b654552cb88eb0bcd3962b6af34078ce52b760315c7737818c0cbe5fee8c30a89855358d020
@@ -1,5 +1,6 @@
1
1
  label: "## Table of Contents"
2
2
  patterns:
3
3
  - "README.md"
4
- - doc/*.md
4
+ - docs/*.md
5
+ - docs/draft_articles/*.md
5
6
  root_dir: "."
data/.version CHANGED
@@ -1 +1 @@
1
- 0.9.7
1
+ 0.9.9
data/CHANGELOG.md CHANGED
@@ -1,10 +1,24 @@
1
1
  # Changelog
2
2
  ## [Unreleased]
3
3
 
4
- ### [0.9.8] WIP
4
+ ### [0.9.9] WIP
5
+ - refactored the Session and Config classes into more testable method_missing
6
+ - updated the test suire for both the Session and Config classes
7
+ - added support for MCP servers coming into AIA via the shared_tools gem
8
+ - added +RubyLLM::MCP.support_complex_parameters! to patch ruby_llm gem until such time as it supports the more complex optional parameters in tool calls
9
+ - added an examples/tools/mcp directory with 2 MCP client definitions
10
+ - updated to ruby_llm-mcp gem version 0.5.1
11
+ - //model directive now dumps full model details
12
+ - //available_models now has context window size and capabilities for each model returned
5
13
 
6
14
  ## Released
7
15
 
16
+ ### [0.9.8] 2025-06-25
17
+ - fixing an issue with pipelined prompts
18
+ - now showing the complete modality of the model on the processing line.
19
+ - changed -p option from prompts_dir to pipeline
20
+ - found problem with simple cov and deep cov w/r/t their reported test coverage; they have problems with heredoc and complex conditionals.
21
+
8
22
  ### [0.9.7] 2025-06-20
9
23
 
10
24
  - **NEW FEATURE**: Added `--available_models` CLI option to list all available AI models
data/README.md CHANGED
@@ -358,6 +358,33 @@ Your prompt content here...
358
358
  Analyze the above information and provide insights.
359
359
  ```
360
360
 
361
+ #### Custom Directive Examples
362
+
363
+ You can extend AIA with custom directives by creating Ruby files that define new directive methods:
364
+
365
+ ```ruby
366
+ # examples/directives/ask.rb
367
+ module AIA
368
+ class DirectiveProcessor
369
+ private
370
+ desc "A meta-prompt to LLM making its response available as part of the primary prompt"
371
+ def ask(args, context_manager=nil)
372
+ meta_prompt = args.empty? ? "What is meta-prompting?" : args.join(' ')
373
+ AIA.config.client.chat(meta_prompt)
374
+ end
375
+ end
376
+ end
377
+ ```
378
+
379
+ **Usage:** Use the --tools option to specific a specific directive file or a directory full of files
380
+ ```bash
381
+ # Load custom directive
382
+ aia --tools examples/directives/ask.rb --chat
383
+
384
+ # Use the results of the custom directive as input to a prompt
385
+ //ask gather the latest closing data for the DOW, NASDAQ, and S&P 500
386
+ ```
387
+
361
388
  ### Shell Integration
362
389
 
363
390
  AIA automatically processes shell patterns in prompts:
@@ -499,6 +526,22 @@ aia --tools ~/tools/ --rejected_tools deprecated
499
526
  - API integrations
500
527
  - Data processing utilities
501
528
 
529
+ **MCP Client Examples** (see `examples/tools/mcp/` directory):
530
+
531
+ AIA supports Model Context Protocol (MCP) clients for extended functionality:
532
+
533
+ ```bash
534
+ # GitHub MCP Server (requires: brew install github-mcp-server)
535
+ # Set GITHUB_PERSONAL_ACCESS_TOKEN environment variable
536
+ aia --tools examples/tools/mcp/github_mcp_server.rb --chat
537
+
538
+ # iMCP for macOS (requires: brew install --cask loopwork/tap/iMCP)
539
+ # Provides access to Notes, Calendar, Contacts, etc.
540
+ aia --tools examples/tools/mcp/imcp.rb --chat
541
+ ```
542
+
543
+ These MCP clients require the `ruby_llm-mcp` gem and provide access to external services and data sources through the Model Context Protocol.
544
+
502
545
  **Shared Tools Collection:**
503
546
  AIA can use the [shared_tools gem](https://github.com/madbomber/shared_tools) which provides a curated collection of commonly-used tools (aka functions) via the --require option.
504
547
 
data/Rakefile CHANGED
@@ -2,23 +2,31 @@
2
2
 
3
3
  begin
4
4
  require "tocer/rake/register"
5
- rescue LoadError => error
6
- puts error.message
5
+ Tocer::Rake::Register.call
6
+ rescue LoadError, StandardError => e
7
+ warn "Skipping tocer tasks: #{e.message}"
7
8
  end
8
9
 
9
- Tocer::Rake::Register.call
10
-
11
- require 'kramdown/man/task'
12
- Kramdown::Man::Task.new
10
+ begin
11
+ require 'kramdown/man/task'
12
+ Kramdown::Man::Task.new
13
+ rescue LoadError, StandardError => e
14
+ warn "Skipping kramdown man task: #{e.message}"
15
+ end
13
16
 
14
- require "bundler/gem_tasks"
17
+ begin
18
+ require "bundler/gem_tasks"
19
+ rescue LoadError, StandardError => e
20
+ warn "Skipping bundler/gem_tasks: #{e.message}"
21
+ end
15
22
  require "minitest/test_task"
16
23
 
17
24
  Minitest::TestTask.create(:test) do |t|
18
25
  t.libs << "test"
19
26
  t.libs << "lib"
20
27
  t.warning = false
21
- t.test_globs = ["test/aia/*_test.rb", "test/aia_test.rb", "!test/integration/**/*_test.rb"]
28
+ # Include all unit tests under test/, excluding integration tests
29
+ t.test_globs = ["test/**/*_test.rb", "!test/integration/**/*_test.rb"]
22
30
  end
23
31
 
24
32
  Minitest::TestTask.create(:integration) do |t|
@@ -0,0 +1,21 @@
1
+ # ~/examples/directives/ask.rb
2
+ # Desc: An example of how to extend the AIA directives
3
+ # Usage: aia <options> --require path/to/ask.rb
4
+ #
5
+ # A directive is just a private method of the AIA::DirectiveProcessor class. its
6
+ # definition is preceeded by the `desc` method which has a single String parameter
7
+ # that is a description of the directive. This discription is shown with the
8
+ # directive's name in the --chat mode with the //help directive is used.
9
+
10
+ module AIA
11
+ class DirectiveProcessor
12
+ private
13
+ desc "A meta-prompt to LLM making its response available as part of the primary prompt"
14
+ # args is an Array of Strings
15
+ # context_manager is an optional parameter TBD
16
+ def ask(args, context_manager=nil)
17
+ meta_prompt = args.empty? ? "What is meta-prompting?" : args.join(' ')
18
+ AIA.config.client.chat(meta_prompt)
19
+ end
20
+ end
21
+ end
@@ -4,6 +4,8 @@ require "ruby_llm/tool"
4
4
 
5
5
  module Tools
6
6
  class EditFile < RubyLLM::Tool
7
+ def self.name = "edit_file"
8
+
7
9
  description <<~DESCRIPTION
8
10
  Make edits to a text file.
9
11
 
@@ -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
+ # TODO: Use shared web tools or custom HTTP client
71
+ end
72
+
73
+ def read_file_data(file_path)
74
+ # TODO: Use shared file tools
75
+ end
76
+
77
+ def analyze_data_structure(data)
78
+ # TODO: Implementation for data structure analysis
79
+ end
80
+
81
+ def generate_insights(data, structure)
82
+ # TODO: Implementation for insight generation
83
+ end
84
+
85
+ def suggest_visualizations(structure)
86
+ # TODO: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
+ # TODO: Implementation for data loading from various sources
98
+ end
99
+
100
+ def validate_data_for_analysis(data, analysis_type)
101
+ # TODO: Implementation for data validation
102
+ end
103
+
104
+ def generate_statistical_summary(data, parameters)
105
+ # TODO: Implementation for statistical summary
106
+ end
107
+
108
+ def perform_correlation_analysis(data, parameters)
109
+ # TODO: Implementation for correlation analysis
110
+ end
111
+
112
+ def analyze_time_series(data, parameters)
113
+ # TODO: Implementation for time series analysis
114
+ end
115
+
116
+ def perform_clustering(data, parameters)
117
+ # TODO: Implementation for clustering
118
+ end
119
+
120
+ def generate_predictions(data, parameters)
121
+ # TODO: Implementation for prediction
122
+ end
123
+
124
+ def summarize_data(data)
125
+ # TODO: 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
+ # TODO: Implementation for rollback logic
98
+ end
99
+
100
+ def perform_health_check(environment, options)
101
+ # TODO: Implementation for health check logic
102
+ end
103
+
104
+ def analyze_logs(environment, options)
105
+ # TODO: Implementation for log analysis logic
106
+ end
107
+
108
+ def collect_metrics(environment, options)
109
+ # TODO: Implementation for metric collection logic
110
+ end
111
+ end
112
+ end