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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e17feb99495b6f8328eedaa95020ca097aa4ee7df658ed0a51a925cd6961cdee
4
- data.tar.gz: 8b5dc406788cc2af104813e0711887bfc6a5ef0e97ddc79464291b0da74ad7df
3
+ metadata.gz: 6eefc7e3df780d0a0553d8d33945cba9f799ff12e0013f2f4e4d8dffe2243a08
4
+ data.tar.gz: fed18a63451cf2a649288c5e4f8a5a13386d98eb164cc312b2e559ebc788b739
5
5
  SHA512:
6
- metadata.gz: a8b7ff36197da72c8b1d3ca1c7199da2333015fda502a37c83d819a95394732449b2d26f20084a14687b59c6fcde10445dda5fbf4705890793ae213bda2cba33
7
- data.tar.gz: 22e5d0ae93d2af2c01f383197a10e454667f0d24af0bb463a191922913702d3c976f04fb918e7716833af874ee1913d86182d234e36c65bb568469a8ead8f116
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/serializers/` — Output formatters (claude, claude_rules, opencode, opencode_rules, cursor_rules, windsurf, windsurf_rules, copilot, copilot_instructions, rules, markdown, JSON, context_file_serializer, test_command_detection)
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/`, `.windsurf/rules/`, `.github/instructions/`
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 (575 examples)
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 (claude, opencode, cursor, windsurf, copilot, JSON)
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
  [![CI](https://github.com/crisnahine/rails-ai-context/actions/workflows/ci.yml/badge.svg)](https://github.com/crisnahine/rails-ai-context/actions)
8
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
9
9
 
10
- **Works with:** Claude Code &bull; Cursor &bull; GitHub Copilot &bull; Windsurf &bull; OpenCode
10
+ **Works with:** Claude Code &bull; Cursor &bull; GitHub Copilot &bull; OpenCode &bull; Any terminal
11
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.
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 live MCP tools that understand your entire Rails app. Zero config.
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
- Right now, your AI agent:
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
- rails_search_code(pattern: "can_cook?", match_type: "trace")
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 tool call replaces 6 file reads.**
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 MCP call) | **98%** |
83
- | Understand a feature (schema + model + controller) | ~5,200 tokens (read 3 files) | ~1,500 tokens (2 MCP calls) | **71%** |
84
- | Check all table columns | ~2,573 tokens (read schema.rb) | ~908 tokens (1 MCP call) | **65%** |
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
- "Without" = AI reads files it would realistically need. "With" = MCP tools return only what's relevant.
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 Live MCP Tools
99
-
100
- Every tool is **read-only** and returns structured, token-efficient data. Start with `detail:"summary"`, drill into specifics.
101
-
102
- | Tool | One-liner |
103
- |------|-----------|
104
- | `rails_search_code` | **Trace mode**: definition + class context + source + internal calls + sibling methods + callers with route chain + test coverage. Also: `"definition"`, `"call"`, `"class"` filters, smart pagination |
105
- | `rails_get_context` | **Composite**: schema + model + controller + routes + views in one call |
106
- | `rails_analyze_feature` | **Full-stack**: everything about a feature models, controllers, routes, services, jobs, views, Stimulus, tests |
107
- | `rails_validate` | **Syntax + semantic + security** in one call. Catches wrong columns, missing partials, broken routes, Brakeman vulnerabilities |
108
- | `rails_get_controllers` | Action source code + inherited filters + render map + side effects + private methods inline |
109
- | `rails_get_schema` | Columns with `[indexed]`, `[unique]`, `[encrypted]`, `[default: value]` hints + model name inline |
110
- | `rails_get_model_details` | Associations, validations, scopes with lambda body, enum backing types, macros, delegations, constants |
111
- | `rails_get_routes` | Code-ready helpers (`cook_path(@record)`), controller filters inline, required params |
112
- | `rails_get_view` | Templates with ivars, Turbo wiring, Stimulus refs, partial locals — pipe-separated, scannable |
113
- | `rails_get_stimulus` | Copy-paste HTML data-attributes (dashes, not underscores) + reverse view lookup |
114
- | `rails_get_design_system` | Canonical HTML/ERB copy-paste patterns for buttons, inputs, cards, modals |
115
- | `rails_get_test_info` | Fixture contents with relationships + test template matching your app's patterns |
116
- | `rails_get_conventions` | Your app's actual patterns auth checks, flash messages, create action template, test patterns |
117
- | `rails_get_turbo_map` | Broadcast subscription wiring with mismatch warnings |
118
- | `rails_get_partial_interface` | Partial locals contract what to pass, what methods are called on each local |
119
- | `rails_get_concern` | Public methods, signatures, which models include it |
120
- | `rails_get_callbacks` | Callbacks in Rails execution order with source code |
121
- | `rails_get_service_pattern` | Interface, dependencies, side effects, error handling, who calls it |
122
- | `rails_get_job_pattern` | Queue, retries, guard clauses, Turbo broadcasts, schedules |
123
- | `rails_get_env` | Environment variables, credentials keys (not values), external service dependencies |
124
- | `rails_get_helper_methods` | App + framework helpers with view usage cross-references |
125
- | `rails_get_config` | Database adapter, auth framework, assets stack, Action Cable, middleware |
126
- | `rails_get_gems` | Notable gems with versions, categories, and config file locations |
127
- | `rails_get_edit_context` | Method-aware code extraction with class/method context header |
128
- | `rails_security_scan` | Brakeman static analysis — SQL injection, XSS, mass assignment |
129
-
130
- > **[Full parameter documentation →](docs/GUIDE.md)**
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 (29 introspectors)
227
+ │ rails-ai-context
145
228
  │ Parses everything. Caches results. Zero config. │
146
- └────────┬─────────────────────────────┬──────────────────┘
147
-
148
-
149
- ┌────────────────────┐ ┌───────────────────────────────┐
150
- │ Static Files Live MCP Server (25 tools)
151
- │ CLAUDE.md Real-time queries on demand
152
- │ .cursor/rules/ Schema, models, routes, etc.
153
- │ .github/instr... Trace, validate, analyze
154
- │ .windsurfrules │ │ Auto-discovered via .mcp.json │
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 (picks your AI tools, generates context)
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
- Both commands ask which AI tools you use (Claude, Cursor, Copilot, Windsurf, OpenCode) and only generate what you need.
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
- # Which AI tools to generate context for (selected during install)
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 MCP tools
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 windsurf opencode]` |
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 # 575 examples
343
+ bundle exec rspec # 653 examples
256
344
  bundle exec rubocop # Lint
257
345
  ```
258
346
 
data/SECURITY.md CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  | Version | Supported |
6
6
  |---------|--------------------|
7
+ | 3.0.x | :white_check_mark: |
7
8
  | 2.0.x | :white_check_mark: |
8
- | 1.4.x | :white_check_mark: |
9
- | < 1.4 | :x: |
9
+ | < 2.0 | :x: |
10
10
 
11
11
  ## Reporting a Vulnerability
12
12