rails-ai-context 2.0.5 → 3.0.1
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 +27 -0
- data/CLAUDE.md +8 -4
- data/CONTRIBUTING.md +7 -2
- data/README.md +172 -84
- 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 +3 -3
- metadata +13 -11
- 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: 6eefc7e3df780d0a0553d8d33945cba9f799ff12e0013f2f4e4d8dffe2243a08
|
|
4
|
+
data.tar.gz: fed18a63451cf2a649288c5e4f8a5a13386d98eb164cc312b2e559ebc788b739
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 84fc5cb59112194dbc3a6f31c1473734646f7cd5cb29777f58290a2cc12c1ebf87036186ed7cc4fd60b52365b9486adea6a9995a561ee4f00c3348487deec532
|
|
7
|
+
data.tar.gz: b74d3406587a18690aa4bffcfbd928efd4b0ead69c176e14163821dee96b3d983958c007cf0c74073b94875e098865ab73cf239b67a59a0565b4911d7d9a7cfe
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,33 @@ 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: `rails 'ai:tool[schema]' table=users detail=full`. Also via Thor CLI: `rails-ai-context tool schema --table users`. `rails ai:tool` lists all tools. `--help` shows per-tool help auto-generated from input_schema. `--json` / `JSON=1` for JSON envelope. Tool name resolution: `schema` → `get_schema` → `rails_get_schema`.
|
|
17
|
+
- **`tool_mode` config** — `:mcp` (default, MCP primary + CLI fallback) or `:cli` (CLI only, no MCP server needed). Selected during install and first `rails ai:context` run.
|
|
18
|
+
- **ToolRunner** — `lib/rails_ai_context/cli/tool_runner.rb` handles CLI tool execution: arg parsing, type coercion from input_schema, required param validation, enum checking, fuzzy tool name suggestions on typos.
|
|
19
|
+
- **ToolGuideHelper** — shared serializer module renders tool reference sections with MCP or CLI syntax based on `tool_mode`, with MANDATORY enforcement + CLI escape hatch. 3-column tool table (MCP | CLI | description).
|
|
20
|
+
- **Copilot `excludeAgent`** — MCP tools instruction file uses `excludeAgent: "code-review"` (code review can't invoke MCP tools, saves 4K char budget).
|
|
21
|
+
- **`.mcp.json` auto-create** — `rails ai:context` automatically creates `.mcp.json` when `tool_mode` is `:mcp` and the file doesn't exist. Existing apps upgrading to v3.0.0 get it without re-running the install generator.
|
|
22
|
+
- **Full config initializer** — generated initializer documents every configuration option organized by section (AI Tools, Introspection, Models & Filtering, MCP Server, File Size Limits, Extensibility, Security, Search).
|
|
23
|
+
- **Cursor MDC compliance spec** — 26 tests validating MDC format: frontmatter fields, rule types, glob syntax, line limits.
|
|
24
|
+
- **Copilot compliance spec** — 25 tests validating instruction format: applyTo, excludeAgent, file naming, content quality.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- Serializer count reduced from 6 to 5 (Claude, Cursor, Copilot, OpenCode, JSON).
|
|
29
|
+
- Install generator renumbered (4 AI tool options instead of 5) + MCP opt-in step.
|
|
30
|
+
- Cursor glob-based rules no longer combine `globs` + `description` (pure Type 2 auto-attach per Cursor best practices).
|
|
31
|
+
- MCP tool instructions use MANDATORY enforcement with CLI escape hatch — AI agents use tools when available, fall back to CLI or file reading when not.
|
|
32
|
+
- All CLI examples use zsh-safe quoting: `rails 'ai:tool[X]'` (brackets are glob patterns in zsh).
|
|
33
|
+
- README rewritten with real-world workflow examples, categorized tool table, MCP vs CLI showcase.
|
|
34
|
+
|
|
8
35
|
## [2.0.5] - 2026-03-25
|
|
9
36
|
|
|
10
37
|
### 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, design_system_helper, stack_overview_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,52 @@
|
|
|
7
7
|
[](https://github.com/crisnahine/rails-ai-context/actions)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
|
|
10
|
-
**Works with:** Claude Code • Cursor • GitHub Copilot •
|
|
10
|
+
**Works with:** Claude Code • Cursor • GitHub Copilot • OpenCode • Any terminal
|
|
11
11
|
|
|
12
|
-
> Built by a Rails developer with 10 years of production experience.
|
|
12
|
+
> Built by a Rails developer with 10+ years of production experience. AI assisted — the same way it assists me shipping features at work. I designed the architecture, made every decision, reviewed every line, and wrote 653 tests. This gem exists because I understand Rails deeply enough to know exactly what AI agents get wrong and what context they need to get it right.
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
gem "rails-ai-context", group: :development
|
|
16
16
|
rails generate rails_ai_context:install
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
That's it. Your AI now has 25
|
|
19
|
+
That's it. Your AI now has 25 tools that understand your entire Rails app — via MCP server or CLI. Zero config.
|
|
20
|
+
|
|
21
|
+
> **[Full Guide →](docs/GUIDE.md)** — every command, every parameter, every configuration option.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Two ways to use it
|
|
26
|
+
|
|
27
|
+
### MCP Server — AI calls tools directly
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
rails ai:serve
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Your AI agent calls tools via the MCP protocol. Auto-discovered via `.mcp.json` — no manual config.
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
→ rails_search_code(pattern: "can_cook?", match_type: "trace")
|
|
37
|
+
→ rails_get_schema(table: "users")
|
|
38
|
+
→ rails_analyze_feature(feature: "billing")
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### CLI — works everywhere, no server needed
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
rails 'ai:tool[search_code]' pattern="can_cook?" match_type=trace
|
|
45
|
+
rails 'ai:tool[schema]' table=users
|
|
46
|
+
rails 'ai:tool[analyze_feature]' feature=billing
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
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
50
|
|
|
21
51
|
---
|
|
22
52
|
|
|
23
53
|
## What AI gets wrong without this
|
|
24
54
|
|
|
25
|
-
|
|
55
|
+
Your AI agent right now:
|
|
26
56
|
|
|
27
57
|
- **Reads all 2,000 lines of schema.rb** to find one column type
|
|
28
58
|
- **Misses encrypted columns** — doesn't know `gemini_api_key` is encrypted
|
|
@@ -30,7 +60,6 @@ Right now, your AI agent:
|
|
|
30
60
|
- **Doesn't see inherited filters** — misses `authenticate_user!` from ApplicationController
|
|
31
61
|
- **Uses underscores in Stimulus HTML** — `data-cook_status` instead of `data-cook-status`
|
|
32
62
|
- **Breaks Turbo Stream wiring** — broadcasts to channels nobody subscribes to
|
|
33
|
-
- **Permits wrong params** — doesn't cross-check against your schema
|
|
34
63
|
- **Guesses your UI patterns** — invents new button styles instead of matching yours
|
|
35
64
|
|
|
36
65
|
**Every wrong guess = a wasted iteration.** You fix it, re-run, it breaks something else.
|
|
@@ -42,7 +71,7 @@ Right now, your AI agent:
|
|
|
42
71
|
One call. Full picture.
|
|
43
72
|
|
|
44
73
|
```
|
|
45
|
-
|
|
74
|
+
rails 'ai:tool[search_code]' pattern="can_cook?" match_type=trace
|
|
46
75
|
```
|
|
47
76
|
|
|
48
77
|
```
|
|
@@ -69,7 +98,61 @@ app/models/concerns/plan_limitable.rb:8
|
|
|
69
98
|
29: assert_not @user.can_cook?
|
|
70
99
|
```
|
|
71
100
|
|
|
72
|
-
Definition + source code + every caller grouped by type + what it calls internally. **One
|
|
101
|
+
Definition + source code + every caller grouped by type + what it calls internally. **One call replaces 6 file reads.**
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Real-world examples
|
|
106
|
+
|
|
107
|
+
### "Add a subscription field to users"
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Step 1: Check what exists
|
|
111
|
+
rails 'ai:tool[schema]' table=users
|
|
112
|
+
# → 20 columns, types, indexes, encrypted hints, defaults
|
|
113
|
+
|
|
114
|
+
# Step 2: Understand the model
|
|
115
|
+
rails 'ai:tool[model_details]' model=User
|
|
116
|
+
# → associations, validations, scopes, enums, callbacks, Devise modules
|
|
117
|
+
|
|
118
|
+
# Step 3: See the full feature
|
|
119
|
+
rails 'ai:tool[analyze_feature]' feature=subscription
|
|
120
|
+
# → models + controllers + routes + services + jobs + views + tests in one shot
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
AI now writes a correct migration, model change, and controller update on the **first attempt**.
|
|
124
|
+
|
|
125
|
+
### "Fix the broken cook creation flow"
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Trace what happens
|
|
129
|
+
rails 'ai:tool[controllers]' controller=CooksController action=create
|
|
130
|
+
# → source code + inherited filters + strong params + render map + side effects
|
|
131
|
+
|
|
132
|
+
# Check the routes
|
|
133
|
+
rails 'ai:tool[routes]' controller=cooks
|
|
134
|
+
# → code-ready helpers (cook_path(@record)) + required params
|
|
135
|
+
|
|
136
|
+
# Validate after fixing
|
|
137
|
+
rails 'ai:tool[validate]' files=app/controllers/cooks_controller.rb level=rails
|
|
138
|
+
# → syntax + semantics + Brakeman security scan
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### "Build a new dashboard view"
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Get the design system
|
|
145
|
+
rails 'ai:tool[design_system]' detail=standard
|
|
146
|
+
# → your actual button classes, card patterns, color palette — copy-paste ready
|
|
147
|
+
|
|
148
|
+
# Check existing view patterns
|
|
149
|
+
rails 'ai:tool[view]' controller=dashboard
|
|
150
|
+
# → templates with ivars, Turbo frames, Stimulus controllers, partial locals
|
|
151
|
+
|
|
152
|
+
# Get Stimulus data-attributes
|
|
153
|
+
rails 'ai:tool[stimulus]' controller=chart
|
|
154
|
+
# → correct HTML with dashes (not underscores) + reverse view lookup
|
|
155
|
+
```
|
|
73
156
|
|
|
74
157
|
---
|
|
75
158
|
|
|
@@ -79,55 +162,55 @@ Tested on a real Rails 8 app (5 models, 19 controllers, 95 routes):
|
|
|
79
162
|
|
|
80
163
|
| Task | Without gem | With gem | Saved |
|
|
81
164
|
|------|-------------|----------|-------|
|
|
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
|
|
165
|
+
| Trace a method across the codebase | ~9,080 tokens (read 5 files) | ~198 tokens (1 tool call) | **98%** |
|
|
166
|
+
| Understand a feature (schema + model + controller) | ~5,200 tokens (read 3 files) | ~1,500 tokens (2 tool calls) | **71%** |
|
|
167
|
+
| Check all table columns | ~2,573 tokens (read schema.rb) | ~908 tokens (1 tool call) | **65%** |
|
|
85
168
|
|
|
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
|
|
169
|
+
> Savings scale with app size. A 50-model app reads more files per task — tool calls stay the same size.
|
|
95
170
|
|
|
96
171
|
---
|
|
97
172
|
|
|
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
|
-
|
|
173
|
+
## 25 Tools
|
|
174
|
+
|
|
175
|
+
Every tool is **read-only** and returns structured, token-efficient data.
|
|
176
|
+
|
|
177
|
+
| Tool | MCP | CLI | What it does |
|
|
178
|
+
|------|-----|-----|-------------|
|
|
179
|
+
| **Search & Trace** | | | |
|
|
180
|
+
| `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 |
|
|
181
|
+
| `get_edit_context` | `rails_get_edit_context(file:"X", near:"Y")` | `rails 'ai:tool[edit_context]'` | Method-aware code extraction with class context |
|
|
182
|
+
| **Understand** | | | |
|
|
183
|
+
| `analyze_feature` | `rails_analyze_feature(feature:"X")` | `rails 'ai:tool[analyze_feature]'` | Full-stack: models + controllers + routes + services + jobs + views + tests |
|
|
184
|
+
| `get_context` | `rails_get_context(model:"X")` | `rails 'ai:tool[context]'` | Composite: schema + model + controller + routes + views in one call |
|
|
185
|
+
| **Schema & Models** | | | |
|
|
186
|
+
| `get_schema` | `rails_get_schema(table:"X")` | `rails 'ai:tool[schema]'` | Columns with indexed/unique/encrypted/default hints |
|
|
187
|
+
| `get_model_details` | `rails_get_model_details(model:"X")` | `rails 'ai:tool[model_details]'` | Associations, validations, scopes, enums, macros, delegations |
|
|
188
|
+
| `get_callbacks` | `rails_get_callbacks(model:"X")` | `rails 'ai:tool[callbacks]'` | Callbacks in Rails execution order with source |
|
|
189
|
+
| `get_concern` | `rails_get_concern(name:"X")` | `rails 'ai:tool[concern]'` | Concern methods + source + which models include it |
|
|
190
|
+
| **Controllers & Routes** | | | |
|
|
191
|
+
| `get_controllers` | `rails_get_controllers(controller:"X")` | `rails 'ai:tool[controllers]'` | Actions + inherited filters + render map + strong params |
|
|
192
|
+
| `get_routes` | `rails_get_routes(controller:"X")` | `rails 'ai:tool[routes]'` | Code-ready helpers (`cook_path(@record)`) + required params |
|
|
193
|
+
| **Views & Frontend** | | | |
|
|
194
|
+
| `get_view` | `rails_get_view(controller:"X")` | `rails 'ai:tool[view]'` | Templates with ivars, Turbo wiring, Stimulus refs, partial locals |
|
|
195
|
+
| `get_stimulus` | `rails_get_stimulus(controller:"X")` | `rails 'ai:tool[stimulus]'` | HTML data-attributes (dashes!) + targets + values + actions |
|
|
196
|
+
| `get_design_system` | `rails_get_design_system` | `rails 'ai:tool[design_system]'` | Copy-paste HTML/ERB patterns for your actual components |
|
|
197
|
+
| `get_partial_interface` | `rails_get_partial_interface(partial:"X")` | `rails 'ai:tool[partial_interface]'` | What locals to pass + what methods are called on them |
|
|
198
|
+
| `get_turbo_map` | `rails_get_turbo_map` | `rails 'ai:tool[turbo_map]'` | Broadcast → subscription wiring + mismatch warnings |
|
|
199
|
+
| **Testing** | | | |
|
|
200
|
+
| `get_test_info` | `rails_get_test_info(model:"X")` | `rails 'ai:tool[test_info]'` | Fixtures + relationships + test template matching your patterns |
|
|
201
|
+
| `validate` | `rails_validate(files:[...])` | `rails 'ai:tool[validate]'` | Syntax + semantic + Brakeman security in one call |
|
|
202
|
+
| `security_scan` | `rails_security_scan` | `rails 'ai:tool[security_scan]'` | Brakeman static analysis — SQL injection, XSS, mass assignment |
|
|
203
|
+
| **App Config** | | | |
|
|
204
|
+
| `get_conventions` | `rails_get_conventions` | `rails 'ai:tool[conventions]'` | Auth checks, flash messages, create action template, test patterns |
|
|
205
|
+
| `get_config` | `rails_get_config` | `rails 'ai:tool[config]'` | Database, auth framework, assets, cache, queue, Action Cable |
|
|
206
|
+
| `get_gems` | `rails_get_gems` | `rails 'ai:tool[gems]'` | Notable gems with versions, categories, config file locations |
|
|
207
|
+
| `get_env` | `rails_get_env` | `rails 'ai:tool[env]'` | Environment variables + credentials keys (not values) |
|
|
208
|
+
| `get_helper_methods` | `rails_get_helper_methods` | `rails 'ai:tool[helper_methods]'` | App + framework helpers with view cross-references |
|
|
209
|
+
| **Services & Jobs** | | | |
|
|
210
|
+
| `get_service_pattern` | `rails_get_service_pattern` | `rails 'ai:tool[service_pattern]'` | Interface, dependencies, side effects, callers |
|
|
211
|
+
| `get_job_pattern` | `rails_get_job_pattern` | `rails 'ai:tool[job_pattern]'` | Queue, retries, guard clauses, broadcasts, schedules |
|
|
212
|
+
|
|
213
|
+
> **[Full parameter docs →](docs/GUIDE.md)**
|
|
131
214
|
|
|
132
215
|
---
|
|
133
216
|
|
|
@@ -138,25 +221,22 @@ Every tool is **read-only** and returns structured, token-efficient data. Start
|
|
|
138
221
|
│ Your Rails App │
|
|
139
222
|
│ models + schema + routes + controllers + views + jobs │
|
|
140
223
|
└────────────────────────┬────────────────────────────────┘
|
|
141
|
-
│ introspects
|
|
224
|
+
│ introspects (29 introspectors)
|
|
142
225
|
▼
|
|
143
226
|
┌─────────────────────────────────────────────────────────┐
|
|
144
|
-
│ rails-ai-context
|
|
227
|
+
│ rails-ai-context │
|
|
145
228
|
│ Parses everything. Caches results. Zero config. │
|
|
146
|
-
|
|
147
|
-
│
|
|
148
|
-
▼
|
|
149
|
-
┌────────────────────┐
|
|
150
|
-
│ Static Files
|
|
151
|
-
│ CLAUDE.md
|
|
152
|
-
│ .cursor/rules/
|
|
153
|
-
│ .github/instr...
|
|
154
|
-
|
|
155
|
-
└────────────────────┘ └───────────────────────────────┘
|
|
229
|
+
└────────┬──────────────────┬──────────────┬──────────────┘
|
|
230
|
+
│ │ │
|
|
231
|
+
▼ ▼ ▼
|
|
232
|
+
┌──────────────────┐ ┌────────────┐ ┌────────────────────┐
|
|
233
|
+
│ Static Files │ │ MCP Server │ │ CLI Tools │
|
|
234
|
+
│ CLAUDE.md │ │ 25 tools │ │ Same 25 tools │
|
|
235
|
+
│ .cursor/rules/ │ │ stdio/HTTP │ │ No server needed │
|
|
236
|
+
│ .github/instr... │ │ .mcp.json │ │ rails 'ai:tool[X]' │
|
|
237
|
+
└──────────────────┘ └────────────┘ └────────────────────┘
|
|
156
238
|
```
|
|
157
239
|
|
|
158
|
-
The install generator asks which AI tools you use and only generates files for those.
|
|
159
|
-
|
|
160
240
|
---
|
|
161
241
|
|
|
162
242
|
## Install
|
|
@@ -165,14 +245,16 @@ The install generator asks which AI tools you use and only generates files for t
|
|
|
165
245
|
# Add to Gemfile
|
|
166
246
|
gem "rails-ai-context", group: :development
|
|
167
247
|
|
|
168
|
-
# Install
|
|
248
|
+
# Install — picks your AI tools, asks MCP or CLI mode, generates context
|
|
169
249
|
rails generate rails_ai_context:install
|
|
170
250
|
|
|
171
251
|
# Or generate context directly
|
|
172
252
|
rails ai:context
|
|
173
253
|
```
|
|
174
254
|
|
|
175
|
-
|
|
255
|
+
The install generator asks:
|
|
256
|
+
1. Which AI tools you use (Claude, Cursor, Copilot, OpenCode)
|
|
257
|
+
2. Whether you want MCP server support or CLI-only mode
|
|
176
258
|
|
|
177
259
|
MCP auto-discovery: `.mcp.json` is detected automatically by Claude Code and Cursor. No manual config.
|
|
178
260
|
|
|
@@ -180,21 +262,38 @@ MCP auto-discovery: `.mcp.json` is detected automatically by Claude Code and Cur
|
|
|
180
262
|
|
|
181
263
|
---
|
|
182
264
|
|
|
265
|
+
## Commands
|
|
266
|
+
|
|
267
|
+
| Command | What it does |
|
|
268
|
+
|---------|-------------|
|
|
269
|
+
| `rails ai:context` | Generate context files for your AI tools |
|
|
270
|
+
| `rails 'ai:tool[NAME]'` | Run any of the 25 tools from the CLI |
|
|
271
|
+
| `rails ai:tool` | List all available tools with short names |
|
|
272
|
+
| `rails ai:serve` | Start MCP server (stdio) |
|
|
273
|
+
| `rails ai:doctor` | Diagnostics + AI readiness score |
|
|
274
|
+
| `rails ai:watch` | Auto-regenerate on file changes |
|
|
275
|
+
| `rails ai:inspect` | Print introspection summary |
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
183
279
|
## Configuration
|
|
184
280
|
|
|
185
281
|
```ruby
|
|
186
282
|
# config/initializers/rails_ai_context.rb
|
|
187
283
|
RailsAiContext.configure do |config|
|
|
188
|
-
#
|
|
284
|
+
# AI tools to generate context for (selected during install)
|
|
189
285
|
# config.ai_tools = %i[claude cursor]
|
|
190
286
|
|
|
287
|
+
# Tool mode: :mcp (default, MCP + CLI fallback) or :cli (CLI only)
|
|
288
|
+
# config.tool_mode = :mcp
|
|
289
|
+
|
|
191
290
|
# Presets: :full (28 introspectors, default) or :standard (13 core)
|
|
192
291
|
# config.preset = :full
|
|
193
292
|
|
|
194
293
|
# Exclude models from introspection
|
|
195
294
|
# config.excluded_models += %w[AdminUser]
|
|
196
295
|
|
|
197
|
-
# Skip specific
|
|
296
|
+
# Skip specific tools
|
|
198
297
|
# config.skip_tools = %w[rails_security_scan]
|
|
199
298
|
end
|
|
200
299
|
```
|
|
@@ -211,7 +310,8 @@ end
|
|
|
211
310
|
| `context_mode` | `:compact` | `:compact` (≤150 lines) or `:full` (dump everything) |
|
|
212
311
|
| `claude_max_lines` | `150` | Max lines for CLAUDE.md in compact mode |
|
|
213
312
|
| `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
|
|
313
|
+
| `ai_tools` | `nil` (all) | AI tools to generate context for: `%i[claude cursor copilot opencode]` |
|
|
314
|
+
| `tool_mode` | `:mcp` | `:mcp` (MCP primary + CLI fallback) or `:cli` (CLI only, no MCP server) |
|
|
215
315
|
| **MCP Server** | | |
|
|
216
316
|
| `cache_ttl` | `60` | Cache TTL in seconds |
|
|
217
317
|
| `max_tool_response_chars` | `200_000` | Safety cap for MCP tool responses |
|
|
@@ -228,18 +328,6 @@ end
|
|
|
228
328
|
|
|
229
329
|
---
|
|
230
330
|
|
|
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
331
|
## Requirements
|
|
244
332
|
|
|
245
333
|
- Ruby >= 3.2, Rails >= 7.1
|
|
@@ -252,7 +340,7 @@ end
|
|
|
252
340
|
```bash
|
|
253
341
|
git clone https://github.com/crisnahine/rails-ai-context.git
|
|
254
342
|
cd rails-ai-context && bundle install
|
|
255
|
-
bundle exec rspec #
|
|
343
|
+
bundle exec rspec # 653 examples
|
|
256
344
|
bundle exec rubocop # Lint
|
|
257
345
|
```
|
|
258
346
|
|
data/SECURITY.md
CHANGED