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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e17feb99495b6f8328eedaa95020ca097aa4ee7df658ed0a51a925cd6961cdee
4
- data.tar.gz: 8b5dc406788cc2af104813e0711887bfc6a5ef0e97ddc79464291b0da74ad7df
3
+ metadata.gz: 29cd675e5f63893551b3ca87869bc6bca2335a5a2fe15ea38e54ec11dab6329a
4
+ data.tar.gz: 4c2a0fe1003abd939f1ea005cf1aefac1055672dbe80c9fb771937acec1bde24
5
5
  SHA512:
6
- metadata.gz: a8b7ff36197da72c8b1d3ca1c7199da2333015fda502a37c83d819a95394732449b2d26f20084a14687b59c6fcde10445dda5fbf4705890793ae213bda2cba33
7
- data.tar.gz: 22e5d0ae93d2af2c01f383197a10e454667f0d24af0bb463a191922913702d3c976f04fb918e7716833af874ee1913d86182d234e36c65bb568469a8ead8f116
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/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)
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,48 @@
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
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 &bull; Cursor &bull; GitHub Copilot &bull; OpenCode &bull; 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 live MCP tools that understand your entire Rails app. Zero config.
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
- Right now, your AI agent:
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
- rails_search_code(pattern: "can_cook?", match_type: "trace")
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 tool call replaces 6 file reads.**
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 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%** |
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
- "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
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 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)**
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 (29 introspectors)
223
+ │ rails-ai-context
145
224
  │ 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
- └────────────────────┘ └───────────────────────────────┘
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 (picks your AI tools, generates context)
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
- Both commands ask which AI tools you use (Claude, Cursor, Copilot, Windsurf, OpenCode) and only generate what you need.
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
- # Which AI tools to generate context for (selected during install)
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 MCP tools
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 windsurf opencode]` |
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 # 575 examples
339
+ bundle exec rspec # 653 examples
256
340
  bundle exec rubocop # Lint
257
341
  ```
258
342
 
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