rails-ai-context 2.0.5 → 3.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/CHANGELOG.md +20 -0
- data/CLAUDE.md +8 -4
- data/CONTRIBUTING.md +7 -2
- data/README.md +169 -85
- data/SECURITY.md +2 -2
- data/docs/GUIDE.md +89 -31
- data/exe/rails-ai-context +37 -1
- data/lib/generators/rails_ai_context/install/install_generator.rb +118 -11
- data/lib/rails_ai_context/cli/tool_runner.rb +259 -0
- data/lib/rails_ai_context/configuration.rb +6 -2
- data/lib/rails_ai_context/serializers/claude_rules_serializer.rb +3 -81
- data/lib/rails_ai_context/serializers/claude_serializer.rb +3 -80
- data/lib/rails_ai_context/serializers/context_file_serializer.rb +1 -9
- data/lib/rails_ai_context/serializers/copilot_instructions_serializer.rb +6 -78
- data/lib/rails_ai_context/serializers/copilot_serializer.rb +4 -40
- data/lib/rails_ai_context/serializers/cursor_rules_serializer.rb +6 -82
- data/lib/rails_ai_context/serializers/markdown_serializer.rb +1 -1
- data/lib/rails_ai_context/serializers/opencode_serializer.rb +3 -80
- data/lib/rails_ai_context/serializers/tool_guide_helper.rb +214 -0
- data/lib/rails_ai_context/tasks/rails_ai_context.rake +116 -5
- data/lib/rails_ai_context/version.rb +1 -1
- data/lib/rails_ai_context.rb +1 -1
- data/server.json +2 -2
- metadata +4 -4
- data/lib/rails_ai_context/serializers/windsurf_rules_serializer.rb +0 -148
- data/lib/rails_ai_context/serializers/windsurf_serializer.rb +0 -160
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29cd675e5f63893551b3ca87869bc6bca2335a5a2fe15ea38e54ec11dab6329a
|
|
4
|
+
data.tar.gz: 4c2a0fe1003abd939f1ea005cf1aefac1055672dbe80c9fb771937acec1bde24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31a7796c31b70f9e3d667d4b961d00cd316a6bd365720fff32b9d922d7faa1febdbcfad00adcba0ff7d625af510e80ff8a1b596dba504543e0f1e72ce65022af
|
|
7
|
+
data.tar.gz: 552c6388e3ea2648f400d2b948eefd25e325e4ec67a896b7917dee61d6bd37032df0a5d1c5e03c1dd6dbe66fbf6b21e2e38d725344b4438b98d23c0d5141d6f4
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.0.0] - 2026-03-26
|
|
9
|
+
|
|
10
|
+
### Removed
|
|
11
|
+
|
|
12
|
+
- **Windsurf support dropped** — removed `WindsurfSerializer`, `WindsurfRulesSerializer`, `.windsurfrules` generation, and `.windsurf/rules/` split rules. v2.0.5 is the last version with Windsurf support. If you need Windsurf context files, pin `gem "rails-ai-context", "~> 2.0"` in your Gemfile.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **CLI tool support** — all 25 MCP tools can now be run from the terminal. Rake: `rails 'ai:tool[schema]' table=users detail=full`. Thor CLI: `rails-ai-context tool schema --table users --detail full`. `rails ai:tool` (no args) lists all tools. `--help` shows per-tool help auto-generated from input_schema. `--json` / `JSON=1` for JSON envelope output. Tool name resolution: `schema` → `get_schema` → `rails_get_schema`.
|
|
17
|
+
- **`tool_mode` config** — new `config.tool_mode` option: `:mcp` (default, MCP primary + CLI fallback) or `:cli` (CLI only, no MCP server needed). Selected during `rails generate rails_ai_context:install`.
|
|
18
|
+
- **ToolGuideHelper** — shared serializer module for tool reference sections, rendering MCP or CLI syntax based on `tool_mode`. All 5 serializers updated to use it.
|
|
19
|
+
- **ToolRunner** — `lib/rails_ai_context/cli/tool_runner.rb` handles CLI tool execution with argument parsing, tool name resolution, help generation, and JSON output formatting.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Serializer count reduced from 6 to 5 (Claude, Cursor, Copilot, OpenCode, JSON).
|
|
24
|
+
- Install generator AI tool selection renumbered (4 options instead of 5).
|
|
25
|
+
- Install generator now includes MCP opt-in step for `tool_mode` selection.
|
|
26
|
+
- All documentation, rake tasks, CLI, and configuration updated to reflect Windsurf removal.
|
|
27
|
+
|
|
8
28
|
## [2.0.5] - 2026-03-25
|
|
9
29
|
|
|
10
30
|
### Changed
|
data/CLAUDE.md
CHANGED
|
@@ -10,7 +10,8 @@ structure to AI assistants via the Model Context Protocol (MCP).
|
|
|
10
10
|
- `lib/rails_ai_context/introspector.rb` — Orchestrates sub-introspectors
|
|
11
11
|
- `lib/rails_ai_context/introspectors/` — 29 introspectors (schema, models, routes, jobs, gems, conventions, stimulus, database_stats, controllers, views, view_templates, design_tokens, turbo, i18n, config, active_storage, action_text, auth, api, tests, rake_tasks, assets, devops, action_mailbox, migrations, seeds, middleware, engines, multi_database)
|
|
12
12
|
- `lib/rails_ai_context/tools/` — 25 MCP tools using the official mcp SDK
|
|
13
|
-
- `lib/rails_ai_context/
|
|
13
|
+
- `lib/rails_ai_context/cli/` — CLI tool runner (`tool_runner.rb`) — executes MCP tools from rake/Thor
|
|
14
|
+
- `lib/rails_ai_context/serializers/` — Output formatters (claude, claude_rules, opencode, opencode_rules, cursor_rules, copilot, copilot_instructions, rules, markdown, JSON, context_file_serializer, test_command_detection, tool_guide_helper)
|
|
14
15
|
- `lib/rails_ai_context/resources.rb` — MCP resources (static data AI clients read directly)
|
|
15
16
|
- `lib/rails_ai_context/server.rb` — MCP server configuration (stdio + HTTP transports)
|
|
16
17
|
- `lib/rails_ai_context/middleware.rb` — Rack middleware for auto-mounting MCP HTTP endpoint
|
|
@@ -20,7 +21,7 @@ structure to AI assistants via the Model Context Protocol (MCP).
|
|
|
20
21
|
- `lib/rails_ai_context/watcher.rb` — File watcher for auto-regenerating context files
|
|
21
22
|
- `lib/rails_ai_context/engine.rb` — Rails Engine for auto-integration
|
|
22
23
|
- `lib/generators/rails_ai_context/install/` — Install generator (creates .mcp.json, initializer, context files)
|
|
23
|
-
- `exe/rails-ai-context` — Standalone Thor CLI (serve, context, inspect, watch, doctor, version)
|
|
24
|
+
- `exe/rails-ai-context` — Standalone Thor CLI (serve, context, inspect, watch, doctor, tool, version)
|
|
24
25
|
|
|
25
26
|
## Key Design Decisions
|
|
26
27
|
|
|
@@ -36,18 +37,21 @@ structure to AI assistants via the Model Context Protocol (MCP).
|
|
|
36
37
|
10. **Introspector presets** — `:full` (28) default, `:standard` (13 core) for lightweight usage
|
|
37
38
|
11. **MCP auto-discovery** — `.mcp.json` generated by install generator
|
|
38
39
|
12. **Compact by default** — context files ≤150 lines, MCP tools use `detail` parameter (summary/standard/full)
|
|
39
|
-
13. **Per-tool split rules** — `.claude/rules/`, `.cursor/rules/`, `.
|
|
40
|
+
13. **Per-tool split rules** — `.claude/rules/`, `.cursor/rules/`, `.github/instructions/`
|
|
40
41
|
14. **Section markers** — root file content wrapped in `<!-- BEGIN/END rails-ai-context -->` to preserve user content
|
|
41
42
|
15. **generate_root_files toggle** — when false, skip root files (CLAUDE.md, etc.), only generate split rules
|
|
42
43
|
16. **custom_tools API** — `config.custom_tools` array lets users register additional MCP::Tool subclasses alongside the 25 built-in tools
|
|
43
44
|
17. **Design system extraction** — view templates analyzed for canonical examples, color palette, typography, responsive patterns, interactive states, dark mode
|
|
44
45
|
18. **skip_tools API** — `config.skip_tools` array lets users exclude specific built-in tools (e.g. `%w[rails_security_scan]`)
|
|
45
46
|
19. **Security scanning** — optional Brakeman integration via `rails_security_scan` tool (graceful degradation if not installed)
|
|
47
|
+
20. **tool_mode config** — `:mcp` (default, MCP primary + CLI fallback) or `:cli` (CLI only, no MCP server needed). Selected during install.
|
|
48
|
+
21. **CLI tool access** — all 25 MCP tools callable from terminal: `rails ai:tool[schema]`, `rails-ai-context tool schema`. Tool name resolution: `schema` → `get_schema` → `rails_get_schema`.
|
|
49
|
+
22. **Shared ToolGuideHelper** — serializers use a shared module for tool reference sections, rendering MCP or CLI syntax based on `tool_mode`
|
|
46
50
|
|
|
47
51
|
## Testing
|
|
48
52
|
|
|
49
53
|
```bash
|
|
50
|
-
bundle exec rspec # Run specs (
|
|
54
|
+
bundle exec rspec # Run specs (653 examples)
|
|
51
55
|
bundle exec rubocop # Lint
|
|
52
56
|
```
|
|
53
57
|
|
data/CONTRIBUTING.md
CHANGED
|
@@ -18,13 +18,14 @@ The test suite uses [Combustion](https://github.com/pat/combustion) to boot a mi
|
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
lib/rails_ai_context/
|
|
21
|
+
├── cli/ # CLI tool runner (tool_runner.rb) — executes MCP tools from rake/Thor
|
|
21
22
|
├── introspectors/ # 29 introspectors (schema, models, routes, etc.)
|
|
22
23
|
├── tools/ # 25 MCP tools with detail levels and pagination
|
|
23
|
-
├── serializers/ # Per-assistant formatters
|
|
24
|
+
├── serializers/ # Per-assistant formatters + shared ToolGuideHelper
|
|
24
25
|
├── server.rb # MCP server setup (stdio + HTTP)
|
|
25
26
|
├── live_reload.rb # MCP live reload (file watcher + cache invalidation)
|
|
26
27
|
├── engine.rb # Rails Engine for auto-integration
|
|
27
|
-
└── configuration.rb # User-facing config (presets, context_mode, limits)
|
|
28
|
+
└── configuration.rb # User-facing config (presets, context_mode, tool_mode, limits)
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
## Adding a New Introspector
|
|
@@ -43,6 +44,10 @@ lib/rails_ai_context/
|
|
|
43
44
|
4. Register in `Server::TOOLS`
|
|
44
45
|
5. Write specs in `spec/lib/rails_ai_context/tools/your_tool_spec.rb`
|
|
45
46
|
|
|
47
|
+
## Adding a CLI Tool Interface
|
|
48
|
+
|
|
49
|
+
The `ToolRunner` (`lib/rails_ai_context/cli/tool_runner.rb`) handles CLI execution of all MCP tools. It is tested in `spec/lib/rails_ai_context/cli/tool_runner_spec.rb`. If you add a new MCP tool, it is automatically available via CLI — no extra registration needed. Tool name resolution (`schema` → `get_schema` → `rails_get_schema`) works for all tools.
|
|
50
|
+
|
|
46
51
|
## Code Style
|
|
47
52
|
|
|
48
53
|
- Follow `rubocop-rails-omakase` style (run `bundle exec rubocop`)
|
data/README.md
CHANGED
|
@@ -7,22 +7,48 @@
|
|
|
7
7
|
[](https://github.com/crisnahine/rails-ai-context/actions)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
|
|
10
|
-
**Works with:** Claude Code • Cursor • GitHub Copilot •
|
|
11
|
-
|
|
12
|
-
> Built by a Rails developer with 10 years of production experience. Yes, AI helped write this gem — the same way AI helps me ship features at work. I designed the architecture, made every decision, reviewed every line, and wrote 575 tests. The gem exists because I understand Rails deeply enough to know what AI agents get wrong and what context they need to get it right.
|
|
10
|
+
**Works with:** Claude Code • Cursor • GitHub Copilot • OpenCode • Any terminal
|
|
13
11
|
|
|
14
12
|
```bash
|
|
15
13
|
gem "rails-ai-context", group: :development
|
|
16
14
|
rails generate rails_ai_context:install
|
|
17
15
|
```
|
|
18
16
|
|
|
19
|
-
That's it. Your AI now has 25
|
|
17
|
+
That's it. Your AI now has 25 tools that understand your entire Rails app — via MCP server or CLI. Zero config.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Two ways to use it
|
|
22
|
+
|
|
23
|
+
### MCP Server — AI calls tools directly
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
rails ai:serve
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Your AI agent calls tools via the MCP protocol. Auto-discovered via `.mcp.json` — no manual config.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
→ rails_search_code(pattern: "can_cook?", match_type: "trace")
|
|
33
|
+
→ rails_get_schema(table: "users")
|
|
34
|
+
→ rails_analyze_feature(feature: "billing")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### CLI — works everywhere, no server needed
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
rails 'ai:tool[search_code]' pattern="can_cook?" match_type=trace
|
|
41
|
+
rails 'ai:tool[schema]' table=users
|
|
42
|
+
rails 'ai:tool[analyze_feature]' feature=billing
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Same 25 tools. Same output. AI agents run these as shell commands. **Works in any terminal, any AI tool, any workflow.** No MCP client required.
|
|
20
46
|
|
|
21
47
|
---
|
|
22
48
|
|
|
23
49
|
## What AI gets wrong without this
|
|
24
50
|
|
|
25
|
-
|
|
51
|
+
Your AI agent right now:
|
|
26
52
|
|
|
27
53
|
- **Reads all 2,000 lines of schema.rb** to find one column type
|
|
28
54
|
- **Misses encrypted columns** — doesn't know `gemini_api_key` is encrypted
|
|
@@ -30,7 +56,6 @@ Right now, your AI agent:
|
|
|
30
56
|
- **Doesn't see inherited filters** — misses `authenticate_user!` from ApplicationController
|
|
31
57
|
- **Uses underscores in Stimulus HTML** — `data-cook_status` instead of `data-cook-status`
|
|
32
58
|
- **Breaks Turbo Stream wiring** — broadcasts to channels nobody subscribes to
|
|
33
|
-
- **Permits wrong params** — doesn't cross-check against your schema
|
|
34
59
|
- **Guesses your UI patterns** — invents new button styles instead of matching yours
|
|
35
60
|
|
|
36
61
|
**Every wrong guess = a wasted iteration.** You fix it, re-run, it breaks something else.
|
|
@@ -42,7 +67,7 @@ Right now, your AI agent:
|
|
|
42
67
|
One call. Full picture.
|
|
43
68
|
|
|
44
69
|
```
|
|
45
|
-
|
|
70
|
+
rails 'ai:tool[search_code]' pattern="can_cook?" match_type=trace
|
|
46
71
|
```
|
|
47
72
|
|
|
48
73
|
```
|
|
@@ -69,7 +94,61 @@ app/models/concerns/plan_limitable.rb:8
|
|
|
69
94
|
29: assert_not @user.can_cook?
|
|
70
95
|
```
|
|
71
96
|
|
|
72
|
-
Definition + source code + every caller grouped by type + what it calls internally. **One
|
|
97
|
+
Definition + source code + every caller grouped by type + what it calls internally. **One call replaces 6 file reads.**
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Real-world examples
|
|
102
|
+
|
|
103
|
+
### "Add a subscription field to users"
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Step 1: Check what exists
|
|
107
|
+
rails 'ai:tool[schema]' table=users
|
|
108
|
+
# → 20 columns, types, indexes, encrypted hints, defaults
|
|
109
|
+
|
|
110
|
+
# Step 2: Understand the model
|
|
111
|
+
rails 'ai:tool[model_details]' model=User
|
|
112
|
+
# → associations, validations, scopes, enums, callbacks, Devise modules
|
|
113
|
+
|
|
114
|
+
# Step 3: See the full feature
|
|
115
|
+
rails 'ai:tool[analyze_feature]' feature=subscription
|
|
116
|
+
# → models + controllers + routes + services + jobs + views + tests in one shot
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
AI now writes a correct migration, model change, and controller update on the **first attempt**.
|
|
120
|
+
|
|
121
|
+
### "Fix the broken cook creation flow"
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Trace what happens
|
|
125
|
+
rails 'ai:tool[controllers]' controller=CooksController action=create
|
|
126
|
+
# → source code + inherited filters + strong params + render map + side effects
|
|
127
|
+
|
|
128
|
+
# Check the routes
|
|
129
|
+
rails 'ai:tool[routes]' controller=cooks
|
|
130
|
+
# → code-ready helpers (cook_path(@record)) + required params
|
|
131
|
+
|
|
132
|
+
# Validate after fixing
|
|
133
|
+
rails 'ai:tool[validate]' files=app/controllers/cooks_controller.rb level=rails
|
|
134
|
+
# → syntax + semantics + Brakeman security scan
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### "Build a new dashboard view"
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Get the design system
|
|
141
|
+
rails 'ai:tool[design_system]' detail=standard
|
|
142
|
+
# → your actual button classes, card patterns, color palette — copy-paste ready
|
|
143
|
+
|
|
144
|
+
# Check existing view patterns
|
|
145
|
+
rails 'ai:tool[view]' controller=dashboard
|
|
146
|
+
# → templates with ivars, Turbo frames, Stimulus controllers, partial locals
|
|
147
|
+
|
|
148
|
+
# Get Stimulus data-attributes
|
|
149
|
+
rails 'ai:tool[stimulus]' controller=chart
|
|
150
|
+
# → correct HTML with dashes (not underscores) + reverse view lookup
|
|
151
|
+
```
|
|
73
152
|
|
|
74
153
|
---
|
|
75
154
|
|
|
@@ -79,55 +158,55 @@ Tested on a real Rails 8 app (5 models, 19 controllers, 95 routes):
|
|
|
79
158
|
|
|
80
159
|
| Task | Without gem | With gem | Saved |
|
|
81
160
|
|------|-------------|----------|-------|
|
|
82
|
-
| Trace a method across the codebase | ~9,080 tokens (read 5 files) | ~198 tokens (1
|
|
83
|
-
| Understand a feature (schema + model + controller) | ~5,200 tokens (read 3 files) | ~1,500 tokens (2
|
|
84
|
-
| Check all table columns | ~2,573 tokens (read schema.rb) | ~908 tokens (1
|
|
161
|
+
| Trace a method across the codebase | ~9,080 tokens (read 5 files) | ~198 tokens (1 tool call) | **98%** |
|
|
162
|
+
| Understand a feature (schema + model + controller) | ~5,200 tokens (read 3 files) | ~1,500 tokens (2 tool calls) | **71%** |
|
|
163
|
+
| Check all table columns | ~2,573 tokens (read schema.rb) | ~908 tokens (1 tool call) | **65%** |
|
|
85
164
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
> Savings scale with app size. A 50-model app reads more files per task — MCP calls stay the same size.
|
|
89
|
-
|
|
90
|
-
But tokens are the side effect. The real value:
|
|
91
|
-
|
|
92
|
-
- **First attempt is correct** — AI understands associations, callbacks, and constraints before writing code
|
|
93
|
-
- **Cross-file validation** — catches wrong columns, missing partials, broken routes in one call
|
|
94
|
-
- **Matches your patterns** — your button classes, your test style, your flash messages
|
|
165
|
+
> Savings scale with app size. A 50-model app reads more files per task — tool calls stay the same size.
|
|
95
166
|
|
|
96
167
|
---
|
|
97
168
|
|
|
98
|
-
## 25
|
|
99
|
-
|
|
100
|
-
Every tool is **read-only** and returns structured, token-efficient data.
|
|
101
|
-
|
|
102
|
-
| Tool |
|
|
103
|
-
|
|
104
|
-
|
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
|
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
110
|
-
|
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
|
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
|
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
124
|
-
|
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
|
|
|
129
|
-
|
|
130
|
-
|
|
169
|
+
## 25 Tools
|
|
170
|
+
|
|
171
|
+
Every tool is **read-only** and returns structured, token-efficient data.
|
|
172
|
+
|
|
173
|
+
| Tool | MCP | CLI | What it does |
|
|
174
|
+
|------|-----|-----|-------------|
|
|
175
|
+
| **Search & Trace** | | | |
|
|
176
|
+
| `search_code` | `rails_search_code(pattern:"X", match_type:"trace")` | `rails 'ai:tool[search_code]'` | Trace: definition + source + callers + test coverage. Also: definition, call, class filters |
|
|
177
|
+
| `get_edit_context` | `rails_get_edit_context(file:"X", near:"Y")` | `rails 'ai:tool[edit_context]'` | Method-aware code extraction with class context |
|
|
178
|
+
| **Understand** | | | |
|
|
179
|
+
| `analyze_feature` | `rails_analyze_feature(feature:"X")` | `rails 'ai:tool[analyze_feature]'` | Full-stack: models + controllers + routes + services + jobs + views + tests |
|
|
180
|
+
| `get_context` | `rails_get_context(model:"X")` | `rails 'ai:tool[context]'` | Composite: schema + model + controller + routes + views in one call |
|
|
181
|
+
| **Schema & Models** | | | |
|
|
182
|
+
| `get_schema` | `rails_get_schema(table:"X")` | `rails 'ai:tool[schema]'` | Columns with indexed/unique/encrypted/default hints |
|
|
183
|
+
| `get_model_details` | `rails_get_model_details(model:"X")` | `rails 'ai:tool[model_details]'` | Associations, validations, scopes, enums, macros, delegations |
|
|
184
|
+
| `get_callbacks` | `rails_get_callbacks(model:"X")` | `rails 'ai:tool[callbacks]'` | Callbacks in Rails execution order with source |
|
|
185
|
+
| `get_concern` | `rails_get_concern(name:"X")` | `rails 'ai:tool[concern]'` | Concern methods + source + which models include it |
|
|
186
|
+
| **Controllers & Routes** | | | |
|
|
187
|
+
| `get_controllers` | `rails_get_controllers(controller:"X")` | `rails 'ai:tool[controllers]'` | Actions + inherited filters + render map + strong params |
|
|
188
|
+
| `get_routes` | `rails_get_routes(controller:"X")` | `rails 'ai:tool[routes]'` | Code-ready helpers (`cook_path(@record)`) + required params |
|
|
189
|
+
| **Views & Frontend** | | | |
|
|
190
|
+
| `get_view` | `rails_get_view(controller:"X")` | `rails 'ai:tool[view]'` | Templates with ivars, Turbo wiring, Stimulus refs, partial locals |
|
|
191
|
+
| `get_stimulus` | `rails_get_stimulus(controller:"X")` | `rails 'ai:tool[stimulus]'` | HTML data-attributes (dashes!) + targets + values + actions |
|
|
192
|
+
| `get_design_system` | `rails_get_design_system` | `rails 'ai:tool[design_system]'` | Copy-paste HTML/ERB patterns for your actual components |
|
|
193
|
+
| `get_partial_interface` | `rails_get_partial_interface(partial:"X")` | `rails 'ai:tool[partial_interface]'` | What locals to pass + what methods are called on them |
|
|
194
|
+
| `get_turbo_map` | `rails_get_turbo_map` | `rails 'ai:tool[turbo_map]'` | Broadcast → subscription wiring + mismatch warnings |
|
|
195
|
+
| **Testing** | | | |
|
|
196
|
+
| `get_test_info` | `rails_get_test_info(model:"X")` | `rails 'ai:tool[test_info]'` | Fixtures + relationships + test template matching your patterns |
|
|
197
|
+
| `validate` | `rails_validate(files:[...])` | `rails 'ai:tool[validate]'` | Syntax + semantic + Brakeman security in one call |
|
|
198
|
+
| `security_scan` | `rails_security_scan` | `rails 'ai:tool[security_scan]'` | Brakeman static analysis — SQL injection, XSS, mass assignment |
|
|
199
|
+
| **App Config** | | | |
|
|
200
|
+
| `get_conventions` | `rails_get_conventions` | `rails 'ai:tool[conventions]'` | Auth checks, flash messages, create action template, test patterns |
|
|
201
|
+
| `get_config` | `rails_get_config` | `rails 'ai:tool[config]'` | Database, auth framework, assets, cache, queue, Action Cable |
|
|
202
|
+
| `get_gems` | `rails_get_gems` | `rails 'ai:tool[gems]'` | Notable gems with versions, categories, config file locations |
|
|
203
|
+
| `get_env` | `rails_get_env` | `rails 'ai:tool[env]'` | Environment variables + credentials keys (not values) |
|
|
204
|
+
| `get_helper_methods` | `rails_get_helper_methods` | `rails 'ai:tool[helper_methods]'` | App + framework helpers with view cross-references |
|
|
205
|
+
| **Services & Jobs** | | | |
|
|
206
|
+
| `get_service_pattern` | `rails_get_service_pattern` | `rails 'ai:tool[service_pattern]'` | Interface, dependencies, side effects, callers |
|
|
207
|
+
| `get_job_pattern` | `rails_get_job_pattern` | `rails 'ai:tool[job_pattern]'` | Queue, retries, guard clauses, broadcasts, schedules |
|
|
208
|
+
|
|
209
|
+
> **[Full parameter docs →](docs/GUIDE.md)**
|
|
131
210
|
|
|
132
211
|
---
|
|
133
212
|
|
|
@@ -138,25 +217,22 @@ Every tool is **read-only** and returns structured, token-efficient data. Start
|
|
|
138
217
|
│ Your Rails App │
|
|
139
218
|
│ models + schema + routes + controllers + views + jobs │
|
|
140
219
|
└────────────────────────┬────────────────────────────────┘
|
|
141
|
-
│ introspects
|
|
220
|
+
│ introspects (29 introspectors)
|
|
142
221
|
▼
|
|
143
222
|
┌─────────────────────────────────────────────────────────┐
|
|
144
|
-
│ rails-ai-context
|
|
223
|
+
│ rails-ai-context │
|
|
145
224
|
│ Parses everything. Caches results. Zero config. │
|
|
146
|
-
|
|
147
|
-
│
|
|
148
|
-
▼
|
|
149
|
-
┌────────────────────┐
|
|
150
|
-
│ Static Files
|
|
151
|
-
│ CLAUDE.md
|
|
152
|
-
│ .cursor/rules/
|
|
153
|
-
│ .github/instr...
|
|
154
|
-
|
|
155
|
-
└────────────────────┘ └───────────────────────────────┘
|
|
225
|
+
└────────┬──────────────────┬──────────────┬──────────────┘
|
|
226
|
+
│ │ │
|
|
227
|
+
▼ ▼ ▼
|
|
228
|
+
┌──────────────────┐ ┌────────────┐ ┌────────────────────┐
|
|
229
|
+
│ Static Files │ │ MCP Server │ │ CLI Tools │
|
|
230
|
+
│ CLAUDE.md │ │ 25 tools │ │ Same 25 tools │
|
|
231
|
+
│ .cursor/rules/ │ │ stdio/HTTP │ │ No server needed │
|
|
232
|
+
│ .github/instr... │ │ .mcp.json │ │ rails 'ai:tool[X]' │
|
|
233
|
+
└──────────────────┘ └────────────┘ └────────────────────┘
|
|
156
234
|
```
|
|
157
235
|
|
|
158
|
-
The install generator asks which AI tools you use and only generates files for those.
|
|
159
|
-
|
|
160
236
|
---
|
|
161
237
|
|
|
162
238
|
## Install
|
|
@@ -165,14 +241,16 @@ The install generator asks which AI tools you use and only generates files for t
|
|
|
165
241
|
# Add to Gemfile
|
|
166
242
|
gem "rails-ai-context", group: :development
|
|
167
243
|
|
|
168
|
-
# Install
|
|
244
|
+
# Install — picks your AI tools, asks MCP or CLI mode, generates context
|
|
169
245
|
rails generate rails_ai_context:install
|
|
170
246
|
|
|
171
247
|
# Or generate context directly
|
|
172
248
|
rails ai:context
|
|
173
249
|
```
|
|
174
250
|
|
|
175
|
-
|
|
251
|
+
The install generator asks:
|
|
252
|
+
1. Which AI tools you use (Claude, Cursor, Copilot, OpenCode)
|
|
253
|
+
2. Whether you want MCP server support or CLI-only mode
|
|
176
254
|
|
|
177
255
|
MCP auto-discovery: `.mcp.json` is detected automatically by Claude Code and Cursor. No manual config.
|
|
178
256
|
|
|
@@ -180,21 +258,38 @@ MCP auto-discovery: `.mcp.json` is detected automatically by Claude Code and Cur
|
|
|
180
258
|
|
|
181
259
|
---
|
|
182
260
|
|
|
261
|
+
## Commands
|
|
262
|
+
|
|
263
|
+
| Command | What it does |
|
|
264
|
+
|---------|-------------|
|
|
265
|
+
| `rails ai:context` | Generate context files for your AI tools |
|
|
266
|
+
| `rails 'ai:tool[NAME]'` | Run any of the 25 tools from the CLI |
|
|
267
|
+
| `rails ai:tool` | List all available tools with short names |
|
|
268
|
+
| `rails ai:serve` | Start MCP server (stdio) |
|
|
269
|
+
| `rails ai:doctor` | Diagnostics + AI readiness score |
|
|
270
|
+
| `rails ai:watch` | Auto-regenerate on file changes |
|
|
271
|
+
| `rails ai:inspect` | Print introspection summary |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
183
275
|
## Configuration
|
|
184
276
|
|
|
185
277
|
```ruby
|
|
186
278
|
# config/initializers/rails_ai_context.rb
|
|
187
279
|
RailsAiContext.configure do |config|
|
|
188
|
-
#
|
|
280
|
+
# AI tools to generate context for (selected during install)
|
|
189
281
|
# config.ai_tools = %i[claude cursor]
|
|
190
282
|
|
|
283
|
+
# Tool mode: :mcp (default, MCP + CLI fallback) or :cli (CLI only)
|
|
284
|
+
# config.tool_mode = :mcp
|
|
285
|
+
|
|
191
286
|
# Presets: :full (28 introspectors, default) or :standard (13 core)
|
|
192
287
|
# config.preset = :full
|
|
193
288
|
|
|
194
289
|
# Exclude models from introspection
|
|
195
290
|
# config.excluded_models += %w[AdminUser]
|
|
196
291
|
|
|
197
|
-
# Skip specific
|
|
292
|
+
# Skip specific tools
|
|
198
293
|
# config.skip_tools = %w[rails_security_scan]
|
|
199
294
|
end
|
|
200
295
|
```
|
|
@@ -211,7 +306,8 @@ end
|
|
|
211
306
|
| `context_mode` | `:compact` | `:compact` (≤150 lines) or `:full` (dump everything) |
|
|
212
307
|
| `claude_max_lines` | `150` | Max lines for CLAUDE.md in compact mode |
|
|
213
308
|
| `generate_root_files` | `true` | Generate root files (CLAUDE.md, etc.) — set `false` for split rules only |
|
|
214
|
-
| `ai_tools` | `nil` (all) | AI tools to generate context for: `%i[claude cursor copilot
|
|
309
|
+
| `ai_tools` | `nil` (all) | AI tools to generate context for: `%i[claude cursor copilot opencode]` |
|
|
310
|
+
| `tool_mode` | `:mcp` | `:mcp` (MCP primary + CLI fallback) or `:cli` (CLI only, no MCP server) |
|
|
215
311
|
| **MCP Server** | | |
|
|
216
312
|
| `cache_ttl` | `60` | Cache TTL in seconds |
|
|
217
313
|
| `max_tool_response_chars` | `200_000` | Safety cap for MCP tool responses |
|
|
@@ -228,18 +324,6 @@ end
|
|
|
228
324
|
|
|
229
325
|
---
|
|
230
326
|
|
|
231
|
-
## Commands
|
|
232
|
-
|
|
233
|
-
| Command | What it does |
|
|
234
|
-
|---------|-------------|
|
|
235
|
-
| `rails ai:context` | Generate context files for your AI tools |
|
|
236
|
-
| `rails ai:serve` | Start MCP server (stdio) |
|
|
237
|
-
| `rails ai:doctor` | Diagnostics + AI readiness score |
|
|
238
|
-
| `rails ai:watch` | Auto-regenerate on file changes |
|
|
239
|
-
| `rails ai:inspect` | Print introspection summary |
|
|
240
|
-
|
|
241
|
-
---
|
|
242
|
-
|
|
243
327
|
## Requirements
|
|
244
328
|
|
|
245
329
|
- Ruby >= 3.2, Rails >= 7.1
|
|
@@ -252,7 +336,7 @@ end
|
|
|
252
336
|
```bash
|
|
253
337
|
git clone https://github.com/crisnahine/rails-ai-context.git
|
|
254
338
|
cd rails-ai-context && bundle install
|
|
255
|
-
bundle exec rspec #
|
|
339
|
+
bundle exec rspec # 653 examples
|
|
256
340
|
bundle exec rubocop # Lint
|
|
257
341
|
```
|
|
258
342
|
|
data/SECURITY.md
CHANGED