diff --git a/README.md b/README.md index 1cd277a6b..4ab85801f 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ bin/rails g ## Generators * [Core Setup](./lib/generators/rolemodel/core_setup) +* [Agent Docs](./lib/generators/rolemodel/agent_docs) * [Github](./lib/generators/rolemodel/github) * [Heroku](./lib/generators/rolemodel/heroku) * [Readme](./lib/generators/rolemodel/readme) @@ -129,7 +130,7 @@ Generators that leave behind conventions a coding agent needs to follow also ins | `rolemodel:turbo:modals` | `turbo-modals` | | `rolemodel:turbo:form` | `dynamic-forms` | | `rolemodel:soft_destroyable` | `soft-destroyable` | -| `rolemodel:core_setup` | `polymorphic-parent-resources`, `rake-tasks` | +| `rolemodel:core_setup` | `controller-patterns`, `polymorphic-parent-resources`, `rake-tasks` | ## Utilities diff --git a/lib/generators/rolemodel/README.md b/lib/generators/rolemodel/README.md index 2c16cf702..e475c0337 100644 --- a/lib/generators/rolemodel/README.md +++ b/lib/generators/rolemodel/README.md @@ -4,6 +4,7 @@ ## What you get +* [Agent Docs](./agent_docs) * [Editors](./editors) * [Github](./github) * [GoodJob](./good_job) diff --git a/lib/generators/rolemodel/agent_docs/README.md b/lib/generators/rolemodel/agent_docs/README.md new file mode 100644 index 000000000..dce3e6e2c --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/README.md @@ -0,0 +1,14 @@ +# Agent Docs Generator + +[USAGE](./USAGE) + +The agent instructions and conventions a new RoleModel app starts with. `rolemodel:core_setup` runs it. + +## What you get + + - `AGENTS.md`, with `CLAUDE.md` pointing at it. Fill in its first sentence: what the app is, and the one fact that changes how every task in it is approached. + - `docs/CONVENTIONS.md`, an index of the files in `docs/conventions/`. Each entry carries a `` glob naming the files it applies to. + - `.github/instructions/conventions.instructions.md`, which points Copilot (including code review) at the same conventions. + - `.claude/hooks/surface_conventions.rb`, registered in `.claude/settings.json`. Before Claude Code edits a file, the hook lists the conventions whose globs match it. It's downloaded from the [`scaffold-docs`](https://github.com/RoleModel/skills/tree/main/skills/scaffold-docs) skill, so there's one copy to maintain, and it needs Ruby on the `PATH`. + +The conventions assume the stack `core_setup` installs (Slim, SimpleForm, Optics, Turbo, RSpec with Playwright) and the [`controller-patterns`](https://github.com/RoleModel/skills/tree/main/skills/controller-patterns) skill. For an existing app, use the `scaffold-docs` and `generate-conventions` skills instead. diff --git a/lib/generators/rolemodel/agent_docs/USAGE b/lib/generators/rolemodel/agent_docs/USAGE new file mode 100644 index 000000000..e38a99707 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/USAGE @@ -0,0 +1,10 @@ +Description: + Adds AGENTS.md and RoleModel's starting conventions for a new app + + Writes AGENTS.md (with CLAUDE.md pointing at it), docs/CONVENTIONS.md and + the convention files it indexes, and Copilot instructions that point at + them. It also installs the surface_conventions hook from RoleModel/skills, + which shows Claude Code the conventions that apply to each file it edits. + +Example: + rails generate rolemodel:agent_docs diff --git a/lib/generators/rolemodel/agent_docs/agent_docs_generator.rb b/lib/generators/rolemodel/agent_docs/agent_docs_generator.rb new file mode 100644 index 000000000..544179946 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/agent_docs_generator.rb @@ -0,0 +1,22 @@ +module Rolemodel + class AgentDocsGenerator < GeneratorBase + HOOK_URL = 'https://raw.githubusercontent.com/RoleModel/skills/main/skills/scaffold-docs/assets/surface_conventions.rb'.freeze + + source_root File.expand_path('templates', __dir__) + + def install_docs + directory '.', '.' + end + + def install_hook + get HOOK_URL, '.claude/hooks/surface_conventions.rb' + chmod '.claude/hooks/surface_conventions.rb', 0o755 + end + + private + + def project_name + Rails.application.class.module_parent_name.titleize + end + end +end diff --git a/lib/generators/rolemodel/agent_docs/templates/.claude/settings.json b/lib/generators/rolemodel/agent_docs/templates/.claude/settings.json new file mode 100644 index 000000000..c542f3fe4 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/.claude/settings.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "PreToolUse": [ + { + "matcher": "^(Edit|Write)$", + "hooks": [ + { + "type": "command", + "command": "\"${CLAUDE_PROJECT_DIR}/.claude/hooks/surface_conventions.rb\"" + } + ] + } + ] + } +} diff --git a/lib/generators/rolemodel/agent_docs/templates/.github/instructions/conventions.instructions.md b/lib/generators/rolemodel/agent_docs/templates/.github/instructions/conventions.instructions.md new file mode 100644 index 000000000..2551b819b --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/.github/instructions/conventions.instructions.md @@ -0,0 +1,9 @@ +--- +applyTo: "app/**/*,spec/**/*,db/migrate/**/*,lib/**/*,config/**/*" +--- + +# Conventions + +`docs/CONVENTIONS.md` is the source of truth for this repo's conventions. Each entry carries a `` comment naming the files it applies to. Read the convention files whose paths match what you're changing, and follow what they say — not the one-line index summary. + +The branch name or PR title carries a ticket ID like `ABC-123`. Whenever the `linear` MCP server is connected, fetch that issue with `linear-get_issue` and read its description and acceptance criteria before writing or reviewing code — every time, not only when something looks off. Flag changes that contradict the ticket and requirements the diff doesn't address. No ID, or no server: work against these conventions alone and don't block on it. diff --git a/lib/generators/rolemodel/agent_docs/templates/AGENTS.md.tt b/lib/generators/rolemodel/agent_docs/templates/AGENTS.md.tt new file mode 100644 index 000000000..121bcd7b6 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/AGENTS.md.tt @@ -0,0 +1,26 @@ +# <%= project_name %> + + + +## How We Build + +- Deliver the smallest change that adds value. Speculative complexity makes the next change harder, so never pre-solve a hypothetical case; flag real uncertainty in one line and move on. +- Make the change easy, then make the easy change. When extending something, ask whether it's still the right shape, and reshape it first if not. +- Think like a Rubyist: prefer polymorphism to conditionals, and Rails conventions to custom machinery. +- Fix root causes, never symptoms. When reusing a method exposes a bug, fix that method rather than writing a near-copy around it. +- Testability is a code virtue: write code that looks test-first even when it wasn't. Test behavior, not implementation, and don't over-constrain. +- Prefer a clearer name or an extracted method to a comment. + +## Before Editing + +- Read `docs/CONVENTIONS.md`, then the convention files relevant to the task. +- No new gems, top-level directories, base classes, or JS libraries without asking. If no existing pattern fits, stop and say so. +- Keep changes minimal and focused; preserve unrelated work in a dirty tree. +- Write a focused failing test before implementing feature behavior. + +## Verification + +- `bin/setup` once per checkout; `bin/dev` to run the app. +- `bundle exec rspec spec/path/to_spec.rb` for the specs your change touches. CI runs the full suite; don't run it locally. +- `bundle exec rubocop -a` +- `yarn eslint` diff --git a/lib/generators/rolemodel/agent_docs/templates/CLAUDE.md b/lib/generators/rolemodel/agent_docs/templates/CLAUDE.md new file mode 100644 index 000000000..43c994c2d --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/CONVENTIONS.md b/lib/generators/rolemodel/agent_docs/templates/docs/CONVENTIONS.md new file mode 100644 index 000000000..f18394b5c --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/CONVENTIONS.md @@ -0,0 +1,18 @@ +# Conventions + +Read the entries below, then the files relevant to the task. + +- [Controllers follow the controller-patterns skill](conventions/controllers.md) — load the skill before writing a controller or route; no custom actions. +- [Logic lives in models](conventions/logic-in-models.md) — models, POROs and form objects; app/services only for external boundaries; jobs call one method. +- [Callbacks stay guarded](conventions/callbacks.md) — the record, its siblings, or a Turbo refresh; guarded state-transition jobs; never mail or API calls. +- [String-backed enums, referenced by key](conventions/string-enums.md) — explicit string values, never a magic string. +- [Queries live in model scopes](conventions/reuse-scopes.md) — named scopes, no order/where/group_by in templates. +- [No SQL strings in queries](conventions/no-sql-strings.md) — hashes, ranges, association joins, in_order_of; Arel only as a last resort. +- [Eager load in the query that feeds the view](conventions/eager-loading.md) — includes up front; includes plus joins becomes eager_load. +- [Views are Slim; forms are simple_form](conventions/views-and-forms.md) — Slim, simple_form and app/inputs, render records by to_partial_path, shared partials in app/views/application, Optics. +- [Partials declare their locals](conventions/partial-locals.md) — locals on the first line; never an instance variable. +- [Reach for Turbo before Stimulus](conventions/stimulus.md) — TurboForm and Turbo refreshes first; Stimulus only for browser-only interactions. +- [Generate migrations; never renumber one](conventions/migrations.md) — generator timestamps, data__ migrations with their own models, schema.rb column order. +- [Test layers](conventions/test-layers.md) — system specs for flows, request specs for page-less endpoints, no controller specs. +- [A fix ships with the spec that proves it](conventions/reproduce-the-bug.md) — failing-first specs with factories; don't stub the app's own models. +- [System specs assert what a user sees](conventions/system-spec-assertions.md) — labels and text for targets, data_test for scoping, flash for success. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/callbacks.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/callbacks.md new file mode 100644 index 000000000..0d7be7c41 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/callbacks.md @@ -0,0 +1,5 @@ +# Callbacks stay guarded + +A callback derives the record's own attributes, keeps its siblings consistent, or broadcasts a Turbo refresh. It may enqueue a job for a specific state transition, but only behind a guard like `if: -> { saved_change_to_status?(to: 'closed') }`. A callback never sends mail or calls an external API directly. + +An unguarded side effect runs on every save path, including factories, imports, and the console. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/controllers.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/controllers.md new file mode 100644 index 000000000..495594c54 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/controllers.md @@ -0,0 +1,3 @@ +# Controllers follow the controller-patterns skill + +Load the `controller-patterns` skill before writing or reshaping a controller or route, and match one of its shapes. There are no custom actions: an action that doesn't fit is a resource of its own. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/eager-loading.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/eager-loading.md new file mode 100644 index 000000000..bf67bcad9 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/eager-loading.md @@ -0,0 +1,5 @@ +# Eager load in the query that feeds the view + +Load the associations a view or job walks with `includes` in the query that fetches the records, not with per-row lookups. + +`includes` silently turns into one large joined `eager_load` when the same association is also joined or filtered on. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/logic-in-models.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/logic-in-models.md new file mode 100644 index 000000000..a5532c338 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/logic-in-models.md @@ -0,0 +1,7 @@ +# Logic lives in models + +Put a business rule or state transition in a named model method, or in a PORO under `app/models/`. Put input spanning several records in a form object in `app/forms/` that includes `ActiveModel::Model` and `ActiveModel::Attributes`. + +`app/services/` is for boundaries with the outside world (third-party APIs, uploads, webhook consumers). Don't add a service for domain logic. + +A controller holds control flow only (see the controller-patterns skill). A job loads its records and calls one model method. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/migrations.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/migrations.md new file mode 100644 index 000000000..0122fa0da --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/migrations.md @@ -0,0 +1,7 @@ +# Generate migrations; never renumber one + +Create a migration with `bin/rails generate migration`, never by hand-writing the timestamp: round `...0000` versions collide. The `schema_migrations` table tracks applied migrations by their timestamp prefix alone, so never change a committed migration's timestamp. + +Generate a migration that changes data as `bin/rails generate migration data__`, so data migrations stand apart from schema changes in `db/migrate/`. It declares its own models, so later changes to the app's models can't change what it does. Name each after its table and inherit from `ActiveRecord::Base`: `class Issue < ActiveRecord::Base; end`. A table with a `type` column also needs `self.inheritance_column = nil`. Back-fill with one `update_all` per distinct value rather than one per row. + +`db/schema.rb` dumps columns in the local database's physical order. Before committing it, check that no column moved without a migration causing it; order follows the order migrations landed on the default branch. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/no-sql-strings.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/no-sql-strings.md new file mode 100644 index 000000000..1691496a4 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/no-sql-strings.md @@ -0,0 +1,11 @@ +# No SQL strings in queries + +Build queries from ActiveRecord, never from SQL string fragments. That rules out `select('...')`, `order('...')`, `pluck('...')`, `joins('...')`, `group('...')`, `where('start_date < ?', date)`, string `update_all`, and `Arel.sql(...)`. + +Use instead: + +- Hash conditions and open-ended ranges: `where(start_date: ...date)`, `where(archived_at: nil)`. +- Association joins and nested hashes: `joins(:team).order(teams: { name: :asc })`. +- `in_order_of(:status, %w[active pending archived])` for a custom sort order. + +If a query seems to need raw SQL (a JSONB `->>` lookup, Postgres `DISTINCT ON`, `NULLS LAST`), redesign it: store the value in a real column, or narrow the rows with a scope and pick in Ruby. An Arel node is the last resort, and worth a note in the PR. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/partial-locals.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/partial-locals.md new file mode 100644 index 000000000..a96331820 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/partial-locals.md @@ -0,0 +1,3 @@ +# Partials declare their locals + +A partial declares its locals on the first line with `-# locals: (widget:)`. It never reads an instance variable. When a partial isn't a record's, render it with the shorthand `render 'widgets/fields', f:`, not `render partial:`. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reproduce-the-bug.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reproduce-the-bug.md new file mode 100644 index 000000000..24a2c16dc --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reproduce-the-bug.md @@ -0,0 +1,5 @@ +# A fix ships with the spec that proves it + +A bug fix includes a spec that fails without the fix. Build real records with factories, and don't stub the app's own models. + +A spec that stubs the collaborator holding the bug passes whether or not the fix is there. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reuse-scopes.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reuse-scopes.md new file mode 100644 index 000000000..7fbc76d1a --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/reuse-scopes.md @@ -0,0 +1,3 @@ +# Queries live in model scopes + +Chain the model's existing scopes before writing a query, and add a missing query as a named scope on the model, not inline in a controller, job, or template. Templates render what they're given: no `order`, `where`, or `group_by` in Slim. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/stimulus.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/stimulus.md new file mode 100644 index 000000000..6c9ed7e90 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/stimulus.md @@ -0,0 +1,3 @@ +# Reach for Turbo before Stimulus + +Dynamic page behavior is server-rendered: a dependent or conditional form uses TurboForm (the `dynamic-forms` skill), and a page that changes after an action redirects and morphs with a Turbo refresh. Stimulus is for interactions only the browser can do (drag-and-drop, Tom Select), using the controllers the gem's generators install. No inline JavaScript in templates. A new Stimulus controller is a question to raise in the PR. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/string-enums.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/string-enums.md new file mode 100644 index 000000000..0f7eedf89 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/string-enums.md @@ -0,0 +1,3 @@ +# String-backed enums, referenced by key + +Declare enums with explicit string values on a string column, like `enum :status, { active: 'active', archived: 'archived' }`. Reference values by key, predicate, scope, or factory trait, never as a raw string. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/system-spec-assertions.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/system-spec-assertions.md new file mode 100644 index 000000000..ff26a7518 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/system-spec-assertions.md @@ -0,0 +1,17 @@ +# System specs assert what a user sees + +Select by what the user sees, never by CSS class or DOM structure: + +- Click targets and form fields by their visible text or label: `click_on "Yes, I'm Sure"`, `fill_in 'Name', with: 'Bob'`. A field without a label uses its name attribute: `fill_in 'user[name]', with: 'Bob'`. +- Scope to one part of the page with a `data-testid` from `dom_id`, and select it with the `data_test` helper: + + ```slim + tr data-testid=dom_id(widget) + td = link_to 'Edit', edit_widget_path(widget) + ``` + + ```ruby + within(data_test(widget)) { click_on 'Edit' } + ``` + +End every interaction with an assertion on its visible result. For a create, update or destroy, that's usually the flash message: `expect(page).to have_content 'Successfully Created Widget'`. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/test-layers.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/test-layers.md new file mode 100644 index 000000000..9f8556d67 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/test-layers.md @@ -0,0 +1,3 @@ +# Test layers + +Cover a user flow with a system spec on the default `rack_test` driver, and add `js: true` (Playwright) only when the behavior needs JavaScript. Cover an endpoint with no page of its own (a webhook, a turbo_stream or JSON endpoint) with a request spec in `spec/requests/`. Don't write controller specs. Unit-test logic in the model that holds it, and policies in `spec/policies/`. diff --git a/lib/generators/rolemodel/agent_docs/templates/docs/conventions/views-and-forms.md b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/views-and-forms.md new file mode 100644 index 000000000..9fcd5f7f7 --- /dev/null +++ b/lib/generators/rolemodel/agent_docs/templates/docs/conventions/views-and-forms.md @@ -0,0 +1,9 @@ +# Views are Slim; forms are simple_form + +Templates are Slim. Build every form with `simple_form_for`, `simple_fields_for` for nested attributes, and `f.association` for `belongs_to` selects. Reach for the custom inputs in `app/inputs/` before adding one. + +Every input option earns its place: drop options that restate a default. A `label_method` repeated across forms becomes `to_label` on the model; an option every input of a type needs becomes a custom input or wrapper. + +Render records with `render @widget` or `render @widgets`, which find the partial through `to_partial_path`. Name a partial only when no record owns it. + +Shared partials live in `app/views/application/`, the fallback lookup path for a bare `render`, never in `app/views/shared/`. Check there and in `app/helpers/` for an existing partial or helper before writing a new one. Style with Optics classes and tokens (the `optics-context` skill), not one-off CSS. diff --git a/lib/generators/rolemodel/all_generator.rb b/lib/generators/rolemodel/all_generator.rb index ede1dfd09..04e0d5d38 100644 --- a/lib/generators/rolemodel/all_generator.rb +++ b/lib/generators/rolemodel/all_generator.rb @@ -20,6 +20,7 @@ def run_all_the_generators generate 'rolemodel:saas:all' generate 'rolemodel:mailers' generate 'rolemodel:linters:all' + generate 'rolemodel:agent_docs' generate 'rolemodel:ui_components:all' generate 'rolemodel:source_map' generate 'rolemodel:good_job' diff --git a/lib/generators/rolemodel/core_setup/README.md b/lib/generators/rolemodel/core_setup/README.md index 9d27fc186..4053686ef 100644 --- a/lib/generators/rolemodel/core_setup/README.md +++ b/lib/generators/rolemodel/core_setup/README.md @@ -31,6 +31,7 @@ app you can push straight to Heroku right after generation. - [GitHub](../github) — standard GitHub configuration - [Readme](../readme) — standard project README - [Linters](../linters) — Rubocop and ESLint + - [Agent Docs](../agent_docs) — `AGENTS.md`, conventions, and the hook that surfaces them - [Heroku](../heroku) — standard Heroku deployment configuration - [Sentry](../sentry) — error monitoring for Ruby and JavaScript - [Lograge](../lograge) — condensed request logging diff --git a/lib/generators/rolemodel/core_setup/USAGE b/lib/generators/rolemodel/core_setup/USAGE index c0083c250..45322ce8a 100644 --- a/lib/generators/rolemodel/core_setup/USAGE +++ b/lib/generators/rolemodel/core_setup/USAGE @@ -2,8 +2,8 @@ Description: Runs the core generators every new Rails app should have Sets up Slim, Webpack, Optics, SimpleForm, Tom Select, testing (RSpec & - friends), Turbo, flash messages, GitHub config, README, linters, Heroku - deployment, Sentry, and Lograge. It also installs the agent skills for + friends), Turbo, flash messages, GitHub config, README, linters, agent + docs and conventions, Heroku deployment, Sentry, and Lograge. It also installs the agent skills for controller patterns, resource_for, and TaskTools. The result is an app that is ready to push directly to Heroku. diff --git a/lib/generators/rolemodel/core_setup/core_setup_generator.rb b/lib/generators/rolemodel/core_setup/core_setup_generator.rb index 5067badfd..4c8273e2b 100644 --- a/lib/generators/rolemodel/core_setup/core_setup_generator.rb +++ b/lib/generators/rolemodel/core_setup/core_setup_generator.rb @@ -27,6 +27,7 @@ def run_the_core_generators generate 'rolemodel:github' generate 'rolemodel:readme' generate 'rolemodel:linters:all' + generate 'rolemodel:agent_docs' return if options.skip_deployable? generate 'rolemodel:heroku' diff --git a/spec/generators/rolemodel/agent_docs_generator_spec.rb b/spec/generators/rolemodel/agent_docs_generator_spec.rb new file mode 100644 index 000000000..77f937576 --- /dev/null +++ b/spec/generators/rolemodel/agent_docs_generator_spec.rb @@ -0,0 +1,32 @@ +RSpec.describe Rolemodel::AgentDocsGenerator, type: :generator do + before do + hook = StringIO.new("#!/usr/bin/env ruby\n") + allow(URI).to receive(:open).with(described_class::HOOK_URL, {}).and_yield(hook) + end + + it 'adds AGENTS.md, the conventions index, and Copilot instructions' do + run_generators + + assert_file 'AGENTS.md', /\A# Example Rails Current$/ + assert_file 'CLAUDE.md', "@AGENTS.md\n" + assert_file 'docs/CONVENTIONS.md', %r{\(conventions/controllers\.md\)} + assert_file 'docs/conventions/controllers.md' + assert_file '.github/instructions/conventions.instructions.md' + end + + it 'installs the surface_conventions hook from RoleModel/skills and registers it' do + run_generators + + assert_file '.claude/hooks/surface_conventions.rb', "#!/usr/bin/env ruby\n" + expect(File.executable?(File.join(destination_root, '.claude/hooks/surface_conventions.rb'))).to be true + assert_file '.claude/settings.json', %r{\.claude/hooks/surface_conventions\.rb} + end + + it 'indexes every convention file it installs' do + run_generators + + index = File.read(File.join(destination_root, 'docs/CONVENTIONS.md')) + installed = Dir.children(File.join(destination_root, 'docs/conventions')).sort + expect(index.scan(%r{\(conventions/([\w-]+\.md)\)}).flatten.sort).to eq installed + end +end