1---2name: gemfile-organize3description: Reorganize a Rails Gemfile with categorized sections, comment headers, and alphabetized gems within each section. Use when the user asks to organize, sort, group, clean up, or restructure a Gemfile.4---56# Gemfile Organize78## Input910- TARGET = first arg or `Gemfile` in cwd11- Read TARGET, parse: `source`, `ruby`, `gem` declarations, groups, inline comments1213## Categories (assignment table)1415| Category | Gem patterns |16|----------|--------------|17| Server | `puma`, `unicorn`, `thin`, `falcon` |18| GraphQL | `graphql*`, `apollo*`, `graphiql*` |19| Databases | `pg*`, `mysql*`, `sqlite*`, `redis*`, `mongo*`, `activerecord*`, `active_record*`, `sequel`, `connection_pool`, `with_advisory_lock`, `store_model`, `attr_json` |20| Background Jobs | `sidekiq*`, `resque*`, `delayed_job*`, `good_job`, `solid_queue`, `activejob`, `active_job*` |21| Authentication & Authorization | `devise*`, `omniauth*`, `doorkeeper*`, `rodauth*`, `pundit`, `cancan*`, `action_policy`, `jwt`, `bcrypt` |22| Feature Flags | `flipper*`, `rollout`, `unleash` |23| Caching | `solid_cache`, `dalli`, `redis-rails`, `bootsnap` |24| Monitoring | `appsignal`, `newrelic*`, `datadog*`, `scout_apm`, `rollbar`, `sentry*`, `bugsnag`, `honeybadger`, `judoscale*`, `rails_autoscale*` |25| Upload & Storage | `shrine`, `carrierwave`, `paperclip`, `active_storage*`, `aws-sdk*`, `google-cloud-storage`, `fog*`, `image_processing`, `mini_magick`, `ruby-vips` |26| External APIs & Services | `stripe`, `braintree`, `paddle`, `twilio*`, `sendgrid*`, `mailgun*`, `postmark*`, `slack-*`, `octokit`, `savon`, `httparty`, `faraday`, `typhoeus`, `intacct`, `quickbooks*`, `xero*` |27| Ruby Extensions | `amazing_print`, `awesome_print`, `oj`, `multi_json`, `alba`, `blueprinter`, `dry-*`, `hashie`, `hash_dot`, `countries`, `money*`, `phonelib`, `chronic`, `ice_cube`, `business_time`, `holidays`, `shale`, `nokogiri`, `ox` |28| PDF Generation | `prawn*`, `wicked_pdf`, `pdfkit`, `hexapdf`, `ttfunk`, `matrix` |29| XLSX/CSV Generation | `caxlsx`, `axlsx*`, `roo*`, `spreadsheet`, `csv`, `smarter_csv` |30| Frontend Dependencies | `turbo-rails`, `stimulus-rails`, `hotwire*`, `importmap*`, `jsbundling*`, `cssbundling*`, `propshaft`, `sprockets*`, `tailwindcss*`, `bootstrap*`, `view_component*`, `inertia*` |31| Admin & Backoffice | `avo*`, `activeadmin`, `rails_admin`, `administrate`, `trestle` |32| Rails Extensions & Tools (default) | `aasm`, `state_machines*`, `friendly_id`, `hashid*`, `sequenced`, `pagy`, `kaminari`, `will_paginate`, `paranoia`, `discard`, `acts_as_paranoid`, `audited`, `paper_trail`, `logidze`, `rack-*`, `lograge*`, most `*-rails` gems, anything uncategorized |3334Group-only categories (kept inside `group` blocks, not top-level):3536| Category | Gem patterns |37|----------|--------------|38| Testing | `rspec*`, `minitest*`, `capybara*`, `factory_bot*`, `faker`, `ffaker`, `vcr`, `webmock`, `shoulda*`, `simplecov`, `codecov`, `database_cleaner*` |39| Development Tools | `rubocop*`, `standard`, `brakeman`, `annotate`, `bullet`, `pry*`, `byebug`, `debug`, `letter_opener*`, `guard*`, `ruby-lsp*`, `solargraph` |4041## Output Format4243```ruby44source "https://rubygems.org"45git_source(:github) { |repo| "https://github.com/#{repo}.git" }4647ruby file: '.ruby-version'4849gem 'rails', '~> 7.x'5051# Server52#########################53gem 'puma'5455# Databases56#########################57gem 'pg'58gem 'redis'5960# [Continue for each non-empty category, in table order]6162group :production do63 # ...64end6566group :development, :test do67 # ...68end6970group :development do71 # ...72end7374group :test do75 # ...76end7778group :tools do79 # ...80end81```8283## Preservation Rules8485- Keep gem options intact: `github:`, `source:`, `require:`, `branch:`, `path:`86- Preserve version constraints: `'~> 1.0'`, `'>= 2.0'`87- Keep inline comments: `gem 'foo' # comment`88- Preserve special blocks like `git_source`89- Sort gems alphabetically within each section90- Only emit category headers for non-empty sections91- Uncategorized gems → "Rails Extensions & Tools"9293## Workflow94951. Read TARGET → parse declarations962. For each gem: assign to category by pattern match (first match wins, table order)973. Build organized output (top-level categories, then groups)984. Compute diff vs current TARGET995. Show summary:100 ```101 Organized N gems into M categories:102 - Category: K gems103 ...104 Uncategorized → Rails Extensions & Tools:105 - gem_a106 - gem_b107 ```1086. AskUserQuestion → options: `Show diff` | `Apply changes` | `Cancel`1097. If Apply → write `TARGET.backup`, then overwrite TARGET