rails_ai 0.1.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.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec_status +96 -0
  3. data/AGENT_GUIDE.md +513 -0
  4. data/Appraisals +49 -0
  5. data/COMMERCIAL_LICENSE_TEMPLATE.md +92 -0
  6. data/FEATURES.md +204 -0
  7. data/LEGAL_PROTECTION_GUIDE.md +222 -0
  8. data/LICENSE +62 -0
  9. data/LICENSE_SUMMARY.md +74 -0
  10. data/MIT-LICENSE +62 -0
  11. data/PERFORMANCE.md +300 -0
  12. data/PROVIDERS.md +495 -0
  13. data/README.md +454 -0
  14. data/Rakefile +11 -0
  15. data/SPEED_OPTIMIZATIONS.md +217 -0
  16. data/STRUCTURE.md +139 -0
  17. data/USAGE_GUIDE.md +288 -0
  18. data/app/channels/ai_stream_channel.rb +33 -0
  19. data/app/components/ai/prompt_component.rb +25 -0
  20. data/app/controllers/concerns/ai/context_aware.rb +77 -0
  21. data/app/controllers/concerns/ai/streaming.rb +41 -0
  22. data/app/helpers/ai_helper.rb +164 -0
  23. data/app/jobs/ai/generate_embedding_job.rb +25 -0
  24. data/app/jobs/ai/generate_summary_job.rb +25 -0
  25. data/app/models/concerns/ai/embeddable.rb +38 -0
  26. data/app/views/rails_ai/dashboard/index.html.erb +51 -0
  27. data/config/routes.rb +19 -0
  28. data/lib/generators/rails_ai/install/install_generator.rb +38 -0
  29. data/lib/rails_ai/agents/agent_manager.rb +258 -0
  30. data/lib/rails_ai/agents/agent_team.rb +243 -0
  31. data/lib/rails_ai/agents/base_agent.rb +331 -0
  32. data/lib/rails_ai/agents/collaboration.rb +238 -0
  33. data/lib/rails_ai/agents/memory.rb +116 -0
  34. data/lib/rails_ai/agents/message_bus.rb +95 -0
  35. data/lib/rails_ai/agents/specialized_agents.rb +391 -0
  36. data/lib/rails_ai/agents/task_queue.rb +111 -0
  37. data/lib/rails_ai/cache.rb +14 -0
  38. data/lib/rails_ai/config.rb +40 -0
  39. data/lib/rails_ai/context.rb +7 -0
  40. data/lib/rails_ai/context_analyzer.rb +86 -0
  41. data/lib/rails_ai/engine.rb +48 -0
  42. data/lib/rails_ai/events.rb +9 -0
  43. data/lib/rails_ai/image_context.rb +110 -0
  44. data/lib/rails_ai/performance.rb +231 -0
  45. data/lib/rails_ai/provider.rb +8 -0
  46. data/lib/rails_ai/providers/anthropic_adapter.rb +256 -0
  47. data/lib/rails_ai/providers/base.rb +60 -0
  48. data/lib/rails_ai/providers/dummy_adapter.rb +29 -0
  49. data/lib/rails_ai/providers/gemini_adapter.rb +509 -0
  50. data/lib/rails_ai/providers/openai_adapter.rb +535 -0
  51. data/lib/rails_ai/providers/secure_anthropic_adapter.rb +206 -0
  52. data/lib/rails_ai/providers/secure_openai_adapter.rb +284 -0
  53. data/lib/rails_ai/railtie.rb +48 -0
  54. data/lib/rails_ai/redactor.rb +12 -0
  55. data/lib/rails_ai/security/api_key_manager.rb +82 -0
  56. data/lib/rails_ai/security/audit_logger.rb +46 -0
  57. data/lib/rails_ai/security/error_handler.rb +62 -0
  58. data/lib/rails_ai/security/input_validator.rb +176 -0
  59. data/lib/rails_ai/security/secure_file_handler.rb +45 -0
  60. data/lib/rails_ai/security/secure_http_client.rb +177 -0
  61. data/lib/rails_ai/security.rb +0 -0
  62. data/lib/rails_ai/version.rb +5 -0
  63. data/lib/rails_ai/window_context.rb +103 -0
  64. data/lib/rails_ai.rb +502 -0
  65. data/monitoring/ci_setup_guide.md +214 -0
  66. data/monitoring/enhanced_monitoring_script.rb +237 -0
  67. data/monitoring/google_alerts_setup.md +42 -0
  68. data/monitoring_log_20250921.txt +0 -0
  69. data/monitoring_script.rb +161 -0
  70. data/rails_ai.gemspec +54 -0
  71. data/scripts/security_scanner.rb +353 -0
  72. data/setup_monitoring.sh +163 -0
  73. data/wiki/API-Documentation.md +734 -0
  74. data/wiki/Architecture-Overview.md +672 -0
  75. data/wiki/Contributing-Guide.md +407 -0
  76. data/wiki/Development-Setup.md +532 -0
  77. data/wiki/Home.md +278 -0
  78. data/wiki/Installation-Guide.md +527 -0
  79. data/wiki/Quick-Start.md +186 -0
  80. data/wiki/README.md +135 -0
  81. data/wiki/Release-Process.md +467 -0
  82. metadata +385 -0
@@ -0,0 +1,532 @@
1
+ # Development Setup
2
+
3
+ This guide will help you set up a development environment for Rails AI.
4
+
5
+ ## 🛠️ Prerequisites
6
+
7
+ ### Required Software
8
+
9
+ - **Ruby**: 2.7+ (3.x recommended)
10
+ - **Rails**: 5.2+ (8.0 recommended)
11
+ - **Git**: Latest version
12
+ - **Bundler**: Latest version
13
+ - **Node.js**: 16+ (for frontend assets)
14
+
15
+ ### Optional Software
16
+
17
+ - **Docker**: For containerized development
18
+ - **Redis**: For caching and background jobs
19
+ - **PostgreSQL**: For database operations
20
+ - **VS Code**: Recommended editor with extensions
21
+
22
+ ## 🚀 Quick Setup
23
+
24
+ ### 1. Clone the Repository
25
+
26
+ ```bash
27
+ # Clone your fork
28
+ git clone https://github.com/yourusername/rails_ai.git
29
+ cd rails_ai
30
+
31
+ # Add upstream remote
32
+ git remote add upstream https://github.com/original/rails_ai.git
33
+ ```
34
+
35
+ ### 2. Install Dependencies
36
+
37
+ ```bash
38
+ # Install Ruby dependencies
39
+ bundle install
40
+
41
+ # Install Node.js dependencies (if any)
42
+ npm install
43
+ ```
44
+
45
+ ### 3. Run Tests
46
+
47
+ ```bash
48
+ # Run all tests
49
+ bundle exec rspec
50
+
51
+ # Run specific test suites
52
+ bundle exec rspec spec/rails_ai_spec.rb
53
+ bundle exec rspec spec/performance_spec.rb
54
+ ```
55
+
56
+ ### 4. Run Linter
57
+
58
+ ```bash
59
+ # Check code style
60
+ bundle exec standardrb
61
+
62
+ # Auto-fix issues
63
+ bundle exec standardrb --fix
64
+ ```
65
+
66
+ ## 🔧 Detailed Setup
67
+
68
+ ### Ruby Version Management
69
+
70
+ #### Using rbenv
71
+
72
+ ```bash
73
+ # Install rbenv
74
+ brew install rbenv
75
+
76
+ # Install Ruby
77
+ rbenv install 3.2.0
78
+ rbenv local 3.2.0
79
+
80
+ # Verify installation
81
+ ruby --version
82
+ ```
83
+
84
+ #### Using RVM
85
+
86
+ ```bash
87
+ # Install RVM
88
+ curl -sSL https://get.rvm.io | bash -s stable
89
+
90
+ # Install Ruby
91
+ rvm install 3.2.0
92
+ rvm use 3.2.0
93
+
94
+ # Verify installation
95
+ ruby --version
96
+ ```
97
+
98
+ ### Rails Version Testing
99
+
100
+ We test against multiple Rails versions using Appraisal:
101
+
102
+ ```bash
103
+ # Install all Rails versions
104
+ bundle exec appraisal install
105
+
106
+ # Run tests against specific Rails version
107
+ bundle exec appraisal rails-8.0 rspec
108
+ bundle exec appraisal rails-7.1 rspec
109
+ bundle exec appraisal rails-6.1 rspec
110
+ bundle exec appraisal rails-5.2 rspec
111
+
112
+ # Run tests against all Rails versions
113
+ bundle exec appraisal rspec
114
+ ```
115
+
116
+ ### Database Setup
117
+
118
+ #### SQLite (Default)
119
+
120
+ ```bash
121
+ # No additional setup needed
122
+ # SQLite is included in the gemfile
123
+ ```
124
+
125
+ #### PostgreSQL
126
+
127
+ ```bash
128
+ # Install PostgreSQL
129
+ brew install postgresql
130
+
131
+ # Start PostgreSQL
132
+ brew services start postgresql
133
+
134
+ # Create database
135
+ createdb rails_ai_test
136
+ ```
137
+
138
+ #### MySQL
139
+
140
+ ```bash
141
+ # Install MySQL
142
+ brew install mysql
143
+
144
+ # Start MySQL
145
+ brew services start mysql
146
+
147
+ # Create database
148
+ mysql -u root -e "CREATE DATABASE rails_ai_test;"
149
+ ```
150
+
151
+ ### Redis Setup (Optional)
152
+
153
+ ```bash
154
+ # Install Redis
155
+ brew install redis
156
+
157
+ # Start Redis
158
+ brew services start redis
159
+
160
+ # Test Redis connection
161
+ redis-cli ping
162
+ ```
163
+
164
+ ## 🐳 Docker Development
165
+
166
+ ### Dockerfile
167
+
168
+ ```dockerfile
169
+ FROM ruby:3.2.0
170
+
171
+ # Install system dependencies
172
+ RUN apt-get update && apt-get install -y \
173
+ build-essential \
174
+ libpq-dev \
175
+ nodejs \
176
+ npm
177
+
178
+ # Set working directory
179
+ WORKDIR /app
180
+
181
+ # Copy Gemfile
182
+ COPY Gemfile Gemfile.lock ./
183
+
184
+ # Install gems
185
+ RUN bundle install
186
+
187
+ # Copy application code
188
+ COPY . .
189
+
190
+ # Expose port
191
+ EXPOSE 3000
192
+
193
+ # Start application
194
+ CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
195
+ ```
196
+
197
+ ### Docker Compose
198
+
199
+ ```yaml
200
+ version: '3.8'
201
+
202
+ services:
203
+ app:
204
+ build: .
205
+ ports:
206
+ - "3000:3000"
207
+ volumes:
208
+ - .:/app
209
+ environment:
210
+ - RAILS_ENV=development
211
+ depends_on:
212
+ - redis
213
+ - postgres
214
+
215
+ redis:
216
+ image: redis:7-alpine
217
+ ports:
218
+ - "6379:6379"
219
+
220
+ postgres:
221
+ image: postgres:15-alpine
222
+ environment:
223
+ POSTGRES_DB: rails_ai_development
224
+ POSTGRES_USER: postgres
225
+ POSTGRES_PASSWORD: password
226
+ ports:
227
+ - "5432:5432"
228
+ volumes:
229
+ - postgres_data:/var/lib/postgresql/data
230
+
231
+ volumes:
232
+ postgres_data:
233
+ ```
234
+
235
+ ### Docker Commands
236
+
237
+ ```bash
238
+ # Build and start services
239
+ docker-compose up --build
240
+
241
+ # Run tests
242
+ docker-compose exec app bundle exec rspec
243
+
244
+ # Run linter
245
+ docker-compose exec app bundle exec standardrb
246
+
247
+ # Access Rails console
248
+ docker-compose exec app bundle exec rails console
249
+ ```
250
+
251
+ ## 🔧 IDE Setup
252
+
253
+ ### VS Code Extensions
254
+
255
+ ```json
256
+ {
257
+ "recommendations": [
258
+ "rebornix.ruby",
259
+ "castwide.solargraph",
260
+ "ms-vscode.vscode-json",
261
+ "bradlc.vscode-tailwindcss",
262
+ "esbenp.prettier-vscode",
263
+ "ms-vscode.vscode-typescript-next"
264
+ ]
265
+ }
266
+ ```
267
+
268
+ ### VS Code Settings
269
+
270
+ ```json
271
+ {
272
+ "ruby.rubocop.executePath": "bundle exec",
273
+ "ruby.rubocop.configFilePath": ".standard.yml",
274
+ "ruby.format": "rubocop",
275
+ "ruby.lint": {
276
+ "rubocop": true
277
+ },
278
+ "editor.formatOnSave": true,
279
+ "editor.codeActionsOnSave": {
280
+ "source.fixAll": true
281
+ }
282
+ }
283
+ ```
284
+
285
+ ### Solargraph Setup
286
+
287
+ ```bash
288
+ # Install Solargraph
289
+ gem install solargraph
290
+
291
+ # Generate documentation
292
+ bundle exec yard gems
293
+
294
+ # Start Solargraph server
295
+ bundle exec solargraph socket
296
+ ```
297
+
298
+ ## 🧪 Testing Setup
299
+
300
+ ### Test Database
301
+
302
+ ```bash
303
+ # Create test database
304
+ bundle exec rails db:create RAILS_ENV=test
305
+
306
+ # Run migrations
307
+ bundle exec rails db:migrate RAILS_ENV=test
308
+
309
+ # Seed test data
310
+ bundle exec rails db:seed RAILS_ENV=test
311
+ ```
312
+
313
+ ### Test Configuration
314
+
315
+ ```ruby
316
+ # spec/spec_helper.rb
317
+ RSpec.configure do |config|
318
+ # Use transactional fixtures
319
+ config.use_transactional_fixtures = true
320
+
321
+ # Include Rails helpers
322
+ config.include Rails.application.routes.url_helpers
323
+
324
+ # Include FactoryBot methods
325
+ config.include FactoryBot::Syntax::Methods
326
+
327
+ # Include time helpers
328
+ config.include ActiveSupport::Testing::TimeHelpers
329
+ end
330
+ ```
331
+
332
+ ### Performance Testing
333
+
334
+ ```bash
335
+ # Run performance tests
336
+ bundle exec rspec spec/performance_spec.rb
337
+
338
+ # Run with detailed output
339
+ bundle exec rspec spec/performance_spec.rb --format documentation
340
+
341
+ # Run specific performance test
342
+ bundle exec rspec spec/performance_spec.rb -e "caching performance"
343
+ ```
344
+
345
+ ## 🔍 Debugging Setup
346
+
347
+ ### Debugging Tools
348
+
349
+ ```ruby
350
+ # Add to Gemfile
351
+ group :development, :test do
352
+ gem 'byebug'
353
+ gem 'pry-rails'
354
+ gem 'pry-byebug'
355
+ gem 'pry-stack_explorer'
356
+ end
357
+ ```
358
+
359
+ ### Debugging Configuration
360
+
361
+ ```ruby
362
+ # config/environments/development.rb
363
+ Rails.application.configure do
364
+ # Enable debugging
365
+ config.log_level = :debug
366
+
367
+ # Enable detailed error pages
368
+ config.consider_all_requests_local = true
369
+
370
+ # Enable caching in development
371
+ config.cache_store = :memory_store
372
+ end
373
+ ```
374
+
375
+ ### Debugging Commands
376
+
377
+ ```ruby
378
+ # In Rails console
379
+ RailsAi.chat("test") # Basic usage
380
+ RailsAi.metrics # Performance metrics
381
+ RailsAi.clear_cache! # Clear cache
382
+ RailsAi.warmup! # Warmup components
383
+ ```
384
+
385
+ ## 📊 Performance Monitoring
386
+
387
+ ### Benchmarking
388
+
389
+ ```ruby
390
+ # Benchmark specific operations
391
+ require 'benchmark'
392
+
393
+ Benchmark.bm do |x|
394
+ x.report("chat") { RailsAi.chat("test") }
395
+ x.report("image") { RailsAi.generate_image("test") }
396
+ x.report("embed") { RailsAi.embed(["test"]) }
397
+ end
398
+ ```
399
+
400
+ ### Memory Profiling
401
+
402
+ ```ruby
403
+ # Profile memory usage
404
+ require 'memory_profiler'
405
+
406
+ report = MemoryProfiler.report do
407
+ RailsAi.chat("test")
408
+ end
409
+
410
+ puts report.pretty_print
411
+ ```
412
+
413
+ ### CPU Profiling
414
+
415
+ ```ruby
416
+ # Profile CPU usage
417
+ require 'ruby-prof'
418
+
419
+ RubyProf.start
420
+ RailsAi.chat("test")
421
+ result = RubyProf.stop
422
+
423
+ printer = RubyProf::FlatPrinter.new(result)
424
+ printer.print(STDOUT)
425
+ ```
426
+
427
+ ## 🚀 Continuous Integration
428
+
429
+ ### GitHub Actions
430
+
431
+ ```yaml
432
+ # .github/workflows/ci.yml
433
+ name: CI
434
+
435
+ on: [push, pull_request]
436
+
437
+ jobs:
438
+ test:
439
+ runs-on: ubuntu-latest
440
+
441
+ strategy:
442
+ matrix:
443
+ ruby: [2.7, 3.0, 3.1, 3.2]
444
+ rails: [5.2, 6.0, 6.1, 7.0, 7.1, 8.0]
445
+
446
+ steps:
447
+ - uses: actions/checkout@v3
448
+ - uses: ruby/setup-ruby@v1
449
+ with:
450
+ ruby-version: ${{ matrix.ruby }}
451
+ - run: bundle install
452
+ - run: bundle exec rspec
453
+ - run: bundle exec standardrb
454
+ ```
455
+
456
+ ### Local CI
457
+
458
+ ```bash
459
+ # Run full test suite
460
+ bundle exec appraisal rspec
461
+
462
+ # Run linter
463
+ bundle exec standardrb
464
+
465
+ # Run security audit
466
+ bundle audit
467
+
468
+ # Run performance tests
469
+ bundle exec rspec spec/performance_spec.rb
470
+ ```
471
+
472
+ ## 🔧 Troubleshooting
473
+
474
+ ### Common Issues
475
+
476
+ #### Bundle Install Fails
477
+
478
+ ```bash
479
+ # Clear bundle cache
480
+ bundle clean --force
481
+
482
+ # Reinstall gems
483
+ bundle install --redownload
484
+ ```
485
+
486
+ #### Tests Fail
487
+
488
+ ```bash
489
+ # Check test database
490
+ bundle exec rails db:test:prepare
491
+
492
+ # Clear test cache
493
+ bundle exec rails tmp:clear
494
+
495
+ # Run tests with verbose output
496
+ bundle exec rspec --format documentation
497
+ ```
498
+
499
+ #### Linter Fails
500
+
501
+ ```bash
502
+ # Auto-fix issues
503
+ bundle exec standardrb --fix
504
+
505
+ # Check specific files
506
+ bundle exec standardrb lib/rails_ai.rb
507
+ ```
508
+
509
+ #### Performance Issues
510
+
511
+ ```bash
512
+ # Clear cache
513
+ bundle exec rails tmp:clear
514
+
515
+ # Reset performance metrics
516
+ RailsAi.reset_performance_metrics!
517
+
518
+ # Check memory usage
519
+ bundle exec rspec spec/performance_spec.rb
520
+ ```
521
+
522
+ ## 📚 Additional Resources
523
+
524
+ - [Ruby Style Guide](https://rubystyle.guide/)
525
+ - [Rails Style Guide](https://rails.rubystyle.guide/)
526
+ - [RSpec Best Practices](https://rspec.info/documentation/)
527
+ - [StandardRB Documentation](https://github.com/standardrb/standardrb)
528
+ - [Appraisal Documentation](https://github.com/thoughtbot/appraisal)
529
+
530
+ ---
531
+
532
+ Happy coding! 🚀