nitro_kit 2.0.0.beta.2 → 2.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.
Files changed (331) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +79 -1
  3. data/LICENSE +21 -28
  4. data/README.md +10 -9
  5. data/STYLE_GUIDE.md +1 -1
  6. data/app/assets/stylesheets/nitro_kit.css +1706 -1400
  7. data/app/assets/tailwind/nitro_kit/engine.css +15 -0
  8. data/app/components/nitro_kit/accordion.rb +1 -13
  9. data/app/components/nitro_kit/app_navigation.rb +0 -12
  10. data/app/components/nitro_kit/app_shell.rb +5 -11
  11. data/app/components/nitro_kit/appearance_picker.rb +1 -7
  12. data/app/components/nitro_kit/combobox.rb +366 -21
  13. data/app/components/nitro_kit/command_palette.rb +7 -20
  14. data/app/components/nitro_kit/details_table.rb +5 -11
  15. data/app/components/nitro_kit/dropzone.rb +3 -15
  16. data/app/components/nitro_kit/field.rb +20 -2
  17. data/app/components/nitro_kit/pagination.rb +2 -8
  18. data/app/components/nitro_kit/settings_layout.rb +3 -9
  19. data/app/javascript/controllers/nk/app_shell_controller.js +2 -2
  20. data/app/javascript/controllers/nk/combobox_controller.js +308 -22
  21. data/app/javascript/controllers/nk/combobox_remote.js +70 -0
  22. data/app/javascript/controllers/nk/dropzone_controller.js +2 -2
  23. data/app/javascript/controllers/nk/tabs_controller.js +2 -2
  24. data/config/locales/en.yml +3 -0
  25. data/docs/agent_guide.md +43 -13
  26. data/docs/browser_support.md +7 -1
  27. data/docs/component_contracts.md +90 -61
  28. data/docs/customization.md +205 -47
  29. data/docs/initialization_prompt.md +4 -5
  30. data/docs/migration_1_to_2.md +10 -8
  31. data/docs/patterns/application_foundation.md +5 -0
  32. data/docs/patterns/composition.md +61 -0
  33. data/docs/patterns/crud_resource.md +5 -0
  34. data/docs/patterns/inset_workspace.md +21 -22
  35. data/docs/patterns/resource_form.md +65 -0
  36. data/docs/rails_integration.md +217 -3
  37. data/lib/generators/nitro_kit/install_generator.rb +5 -4
  38. data/lib/nitro_kit/engine.rb +13 -0
  39. data/lib/nitro_kit/installation.rb +353 -72
  40. data/lib/nitro_kit/migration_inventory.rb +18 -3
  41. data/lib/nitro_kit/version.rb +1 -1
  42. data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +2 -2
  43. data/lib/tasks/nitro_kit_tasks.rake +1 -1
  44. data/patterns/README.md +21 -0
  45. data/patterns/account-settings/files/app/components/ui/account_settings/account_deletion.rb +72 -0
  46. data/patterns/account-settings/files/app/components/ui/account_settings/base.rb +44 -0
  47. data/patterns/account-settings/files/app/components/ui/account_settings/page.rb +57 -0
  48. data/patterns/account-settings/files/app/components/ui/account_settings/preferences.rb +68 -0
  49. data/patterns/account-settings/files/app/components/ui/account_settings/profile.rb +86 -0
  50. data/patterns/account-settings/files/app/components/ui/account_settings/security.rb +69 -0
  51. data/patterns/account-settings/files/app/components/ui/account_settings/sessions.rb +86 -0
  52. data/patterns/account-settings/files/app/controllers/settings/account_deletions_controller.rb +35 -0
  53. data/patterns/account-settings/files/app/controllers/settings/base_controller.rb +12 -0
  54. data/patterns/account-settings/files/app/controllers/settings/other_sessions_controller.rb +8 -0
  55. data/patterns/account-settings/files/app/controllers/settings/preferences_controller.rb +27 -0
  56. data/patterns/account-settings/files/app/controllers/settings/profiles_controller.rb +20 -0
  57. data/patterns/account-settings/files/app/controllers/settings/securities_controller.rb +37 -0
  58. data/patterns/account-settings/files/app/controllers/settings/sessions_controller.rb +31 -0
  59. data/patterns/account-settings/files/app/models/account_settings/account_closure.rb +33 -0
  60. data/patterns/account-settings/files/app/models/account_settings/password_change.rb +42 -0
  61. data/patterns/account-settings/files/app/models/account_settings/session_summary.rb +45 -0
  62. data/patterns/account-settings/files/app/models/concerns/user/account_configurable.rb +18 -0
  63. data/patterns/account-settings/files/config/routes/account_settings.rb +10 -0
  64. data/patterns/account-settings/files/db/migrate/20260731020000_add_account_settings.rb +27 -0
  65. data/patterns/account-settings/files/test/controllers/settings/account_settings_flow_test.rb +84 -0
  66. data/patterns/account-settings/files/test/models/account_settings/password_change_test.rb +40 -0
  67. data/patterns/account-settings/files/test/system/account_settings_test.rb +52 -0
  68. data/patterns/account-settings/item.yml +4 -0
  69. data/patterns/account-settings/pattern.md +44 -0
  70. data/patterns/application-shell/files/app/assets/stylesheets/ui/application_shell.css +267 -0
  71. data/patterns/application-shell/files/app/components/ui/application_shell.rb +184 -0
  72. data/patterns/application-shell/item.yml +4 -0
  73. data/patterns/application-shell/pattern.md +110 -0
  74. data/patterns/authentication/files/app/components/ui/authentication/base.rb +11 -0
  75. data/patterns/authentication/files/app/components/ui/authentication/page.rb +53 -0
  76. data/patterns/authentication/files/app/components/ui/email_verifications/show.rb +62 -0
  77. data/patterns/authentication/files/app/components/ui/password_resets/new.rb +65 -0
  78. data/patterns/authentication/files/app/components/ui/passwords/edit.rb +72 -0
  79. data/patterns/authentication/files/app/components/ui/sessions/new.rb +58 -0
  80. data/patterns/authentication/files/app/components/ui/verification_emails/new.rb +59 -0
  81. data/patterns/authentication/files/app/controllers/concerns/authentication.rb +66 -0
  82. data/patterns/authentication/files/app/controllers/concerns/safe_return_navigation.rb +37 -0
  83. data/patterns/authentication/files/app/controllers/email_verifications_controller.rb +39 -0
  84. data/patterns/authentication/files/app/controllers/password_resets_controller.rb +33 -0
  85. data/patterns/authentication/files/app/controllers/passwords_controller.rb +51 -0
  86. data/patterns/authentication/files/app/controllers/sessions_controller.rb +42 -0
  87. data/patterns/authentication/files/app/controllers/verification_emails_controller.rb +33 -0
  88. data/patterns/authentication/files/app/jobs/authentication_delivery_job.rb +17 -0
  89. data/patterns/authentication/files/app/mailers/authentication_mailer.rb +15 -0
  90. data/patterns/authentication/files/app/models/authentication/credentials.rb +16 -0
  91. data/patterns/authentication/files/app/models/authentication/email_request.rb +17 -0
  92. data/patterns/authentication/files/app/models/concerns/user/email_verifiable.rb +40 -0
  93. data/patterns/authentication/files/app/models/session.rb +5 -0
  94. data/patterns/authentication/files/app/views/authentication_mailer/email_verification.html.erb +3 -0
  95. data/patterns/authentication/files/app/views/authentication_mailer/email_verification.text.erb +5 -0
  96. data/patterns/authentication/files/app/views/authentication_mailer/password_reset.html.erb +3 -0
  97. data/patterns/authentication/files/app/views/authentication_mailer/password_reset.text.erb +5 -0
  98. data/patterns/authentication/files/config/routes/authentication.rb +11 -0
  99. data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb +13 -0
  100. data/patterns/authentication/files/test/controllers/authentication_flow_test.rb +103 -0
  101. data/patterns/authentication/files/test/controllers/safe_return_navigation_test.rb +18 -0
  102. data/patterns/authentication/files/test/mailers/authentication_mailer_test.rb +21 -0
  103. data/patterns/authentication/files/test/models/user_email_verifiable_test.rb +36 -0
  104. data/patterns/authentication/files/test/system/authentication_flow_test.rb +23 -0
  105. data/patterns/authentication/item.yml +12 -0
  106. data/patterns/authentication/pattern.md +54 -0
  107. data/patterns/crud-resource/files/app/assets/stylesheets/ui/projects.css +4 -0
  108. data/patterns/crud-resource/files/app/components/ui/projects/form.rb +89 -0
  109. data/patterns/crud-resource/files/app/components/ui/projects/index.rb +161 -0
  110. data/patterns/crud-resource/files/app/components/ui/projects/show.rb +84 -0
  111. data/patterns/crud-resource/files/app/controllers/projects/archivals_controller.rb +23 -0
  112. data/patterns/crud-resource/files/app/controllers/projects_controller.rb +70 -0
  113. data/patterns/crud-resource/files/app/models/project/archival.rb +8 -0
  114. data/patterns/crud-resource/files/app/models/project/event.rb +12 -0
  115. data/patterns/crud-resource/files/app/models/project/filter.rb +41 -0
  116. data/patterns/crud-resource/files/app/models/project.rb +41 -0
  117. data/patterns/crud-resource/files/app/views/projects/edit.html.erb +19 -0
  118. data/patterns/crud-resource/files/app/views/projects/index.html.erb +18 -0
  119. data/patterns/crud-resource/files/app/views/projects/new.html.erb +16 -0
  120. data/patterns/crud-resource/files/app/views/projects/show.html.erb +28 -0
  121. data/patterns/crud-resource/files/config/routes/crud_resource.rb +7 -0
  122. data/patterns/crud-resource/files/db/migrate/20260720000000_create_crud_resource.rb +37 -0
  123. data/patterns/crud-resource/files/test/controllers/projects_controller_test.rb +64 -0
  124. data/patterns/crud-resource/files/test/models/project_test.rb +34 -0
  125. data/patterns/crud-resource/files/test/support/crud_resource_test_helpers.rb +25 -0
  126. data/patterns/crud-resource/files/test/system/projects_crud_test.rb +87 -0
  127. data/patterns/crud-resource/item.yml +6 -0
  128. data/patterns/crud-resource/pattern.md +48 -0
  129. data/patterns/file-uploads/files/app/assets/stylesheets/ui/uploads.css +133 -0
  130. data/patterns/file-uploads/files/app/components/ui/uploads/base.rb +30 -0
  131. data/patterns/file-uploads/files/app/components/ui/uploads/index.rb +188 -0
  132. data/patterns/file-uploads/files/app/components/ui/uploads/page.rb +33 -0
  133. data/patterns/file-uploads/files/app/controllers/uploads/base_controller.rb +29 -0
  134. data/patterns/file-uploads/files/app/controllers/uploads/direct_uploads_controller.rb +55 -0
  135. data/patterns/file-uploads/files/app/controllers/uploads/retries_controller.rb +14 -0
  136. data/patterns/file-uploads/files/app/controllers/uploads_controller.rb +40 -0
  137. data/patterns/file-uploads/files/app/jobs/upload_blob_cleanup_job.rb +9 -0
  138. data/patterns/file-uploads/files/app/jobs/upload_processing_job.rb +10 -0
  139. data/patterns/file-uploads/files/app/jobs/upload_repair_job.rb +17 -0
  140. data/patterns/file-uploads/files/app/models/concerns/team/uploadable.rb +9 -0
  141. data/patterns/file-uploads/files/app/models/upload.rb +295 -0
  142. data/patterns/file-uploads/files/config/recurring/uploads.yml +7 -0
  143. data/patterns/file-uploads/files/config/routes/uploads.rb +5 -0
  144. data/patterns/file-uploads/files/db/migrate/20260802000000_add_file_uploads.rb +30 -0
  145. data/patterns/file-uploads/files/test/controllers/uploads_flow_test.rb +77 -0
  146. data/patterns/file-uploads/files/test/fixtures/files/workspace.png.base64 +1 -0
  147. data/patterns/file-uploads/files/test/fixtures/uploads.yml +17 -0
  148. data/patterns/file-uploads/files/test/models/upload_test.rb +55 -0
  149. data/patterns/file-uploads/files/test/system/file_uploads_test.rb +30 -0
  150. data/patterns/file-uploads/item.yml +4 -0
  151. data/patterns/file-uploads/pattern.md +71 -0
  152. data/patterns/nitro-kit-1-upgrade/files/docs/nitro_kit_1_upgrade.md +57 -0
  153. data/patterns/nitro-kit-1-upgrade/item.yml +4 -0
  154. data/patterns/nitro-kit-1-upgrade/pattern.md +30 -0
  155. data/patterns/onboarding/files/app/assets/stylesheets/ui/onboarding.css +55 -0
  156. data/patterns/onboarding/files/app/components/ui/onboarding/base.rb +11 -0
  157. data/patterns/onboarding/files/app/components/ui/onboarding/branch_form.rb +36 -0
  158. data/patterns/onboarding/files/app/components/ui/onboarding/details_form.rb +67 -0
  159. data/patterns/onboarding/files/app/components/ui/onboarding/invitation_plan_form.rb +48 -0
  160. data/patterns/onboarding/files/app/components/ui/onboarding/page.rb +75 -0
  161. data/patterns/onboarding/files/app/components/ui/onboarding/review.rb +51 -0
  162. data/patterns/onboarding/files/app/components/ui/onboarding/show.rb +32 -0
  163. data/patterns/onboarding/files/app/controllers/concerns/requires_finished_onboarding.rb +14 -0
  164. data/patterns/onboarding/files/app/controllers/onboarding/base_controller.rb +30 -0
  165. data/patterns/onboarding/files/app/controllers/onboarding/branches_controller.rb +16 -0
  166. data/patterns/onboarding/files/app/controllers/onboarding/completions_controller.rb +13 -0
  167. data/patterns/onboarding/files/app/controllers/onboarding/details_controller.rb +16 -0
  168. data/patterns/onboarding/files/app/controllers/onboarding/invitation_plans_controller.rb +20 -0
  169. data/patterns/onboarding/files/app/controllers/onboardings_controller.rb +7 -0
  170. data/patterns/onboarding/files/app/jobs/onboarding_invitation_delivery_job.rb +15 -0
  171. data/patterns/onboarding/files/app/models/concerns/team/onboardable.rb +23 -0
  172. data/patterns/onboarding/files/app/models/onboarding/completion.rb +17 -0
  173. data/patterns/onboarding/files/app/models/onboarding/invitation_delivery.rb +14 -0
  174. data/patterns/onboarding/files/app/models/onboarding.rb +174 -0
  175. data/patterns/onboarding/files/config/routes/onboarding.rb +11 -0
  176. data/patterns/onboarding/files/db/migrate/20260731010000_create_onboarding.rb +60 -0
  177. data/patterns/onboarding/files/test/controllers/onboarding_flow_test.rb +62 -0
  178. data/patterns/onboarding/files/test/fixtures/onboarding_completions.yml +3 -0
  179. data/patterns/onboarding/files/test/fixtures/onboardings.yml +25 -0
  180. data/patterns/onboarding/files/test/jobs/onboarding_invitation_delivery_job_test.rb +18 -0
  181. data/patterns/onboarding/files/test/models/onboarding_test.rb +60 -0
  182. data/patterns/onboarding/files/test/system/onboarding_flow_test.rb +39 -0
  183. data/patterns/onboarding/item.yml +4 -0
  184. data/patterns/onboarding/pattern.md +53 -0
  185. data/patterns/subscription-billing/files/app/components/ui/billing/base.rb +39 -0
  186. data/patterns/subscription-billing/files/app/components/ui/billing/checkout_result.rb +64 -0
  187. data/patterns/subscription-billing/files/app/components/ui/billing/page.rb +33 -0
  188. data/patterns/subscription-billing/files/app/components/ui/billing/show.rb +149 -0
  189. data/patterns/subscription-billing/files/app/controllers/billing/base_controller.rb +16 -0
  190. data/patterns/subscription-billing/files/app/controllers/billing/checkouts_controller.rb +65 -0
  191. data/patterns/subscription-billing/files/app/controllers/billing/portals_controller.rb +18 -0
  192. data/patterns/subscription-billing/files/app/controllers/billing_controller.rb +17 -0
  193. data/patterns/subscription-billing/files/app/controllers/webhooks/stripe_events_controller.rb +21 -0
  194. data/patterns/subscription-billing/files/app/jobs/billing/stripe_event_job.rb +16 -0
  195. data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_job.rb +16 -0
  196. data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_sweep_job.rb +9 -0
  197. data/patterns/subscription-billing/files/app/models/billing/checkout.rb +58 -0
  198. data/patterns/subscription-billing/files/app/models/billing/plan.rb +19 -0
  199. data/patterns/subscription-billing/files/app/models/billing/stripe_event.rb +73 -0
  200. data/patterns/subscription-billing/files/app/models/billing/subscription.rb +106 -0
  201. data/patterns/subscription-billing/files/app/models/concerns/team/billable.rb +36 -0
  202. data/patterns/subscription-billing/files/config/initializers/stripe.rb +29 -0
  203. data/patterns/subscription-billing/files/config/routes/subscription_billing.rb +10 -0
  204. data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb +61 -0
  205. data/patterns/subscription-billing/files/test/controllers/billing_flow_test.rb +60 -0
  206. data/patterns/subscription-billing/files/test/models/billing/subscription_test.rb +40 -0
  207. data/patterns/subscription-billing/files/test/system/subscription_billing_test.rb +28 -0
  208. data/patterns/subscription-billing/item.yml +4 -0
  209. data/patterns/subscription-billing/pattern.md +59 -0
  210. data/patterns/team-management/files/app/components/ui/invitations/acceptance.rb +33 -0
  211. data/patterns/team-management/files/app/components/ui/teams/index.rb +87 -0
  212. data/patterns/team-management/files/app/components/ui/teams/invitation_form.rb +51 -0
  213. data/patterns/team-management/files/app/components/ui/teams/member_form.rb +78 -0
  214. data/patterns/team-management/files/app/components/ui/teams/members.rb +125 -0
  215. data/patterns/team-management/files/app/controllers/invitations/acceptances_controller.rb +29 -0
  216. data/patterns/team-management/files/app/controllers/teams/base_controller.rb +18 -0
  217. data/patterns/team-management/files/app/controllers/teams/invitations_controller.rb +42 -0
  218. data/patterns/team-management/files/app/controllers/teams/memberships_controller.rb +53 -0
  219. data/patterns/team-management/files/app/controllers/teams_controller.rb +30 -0
  220. data/patterns/team-management/files/app/mailers/team_invitation_mailer.rb +10 -0
  221. data/patterns/team-management/files/app/models/concerns/current_team.rb +13 -0
  222. data/patterns/team-management/files/app/models/concerns/user_teams.rb +37 -0
  223. data/patterns/team-management/files/app/models/invitation.rb +41 -0
  224. data/patterns/team-management/files/app/models/membership.rb +45 -0
  225. data/patterns/team-management/files/app/models/team.rb +25 -0
  226. data/patterns/team-management/files/app/views/invitations/acceptances/show.html.erb +1 -0
  227. data/patterns/team-management/files/app/views/team_invitation_mailer/invite.html.erb +10 -0
  228. data/patterns/team-management/files/app/views/team_invitation_mailer/invite.text.erb +7 -0
  229. data/patterns/team-management/files/app/views/teams/index.html.erb +15 -0
  230. data/patterns/team-management/files/app/views/teams/invitations/new.html.erb +22 -0
  231. data/patterns/team-management/files/app/views/teams/memberships/edit.html.erb +22 -0
  232. data/patterns/team-management/files/app/views/teams/memberships/index.html.erb +20 -0
  233. data/patterns/team-management/files/config/routes/team_management.rb +11 -0
  234. data/patterns/team-management/files/db/migrate/20260717000000_create_team_management.rb +31 -0
  235. data/patterns/team-management/files/test/models/invitation_test.rb +28 -0
  236. data/patterns/team-management/files/test/models/membership_test.rb +29 -0
  237. data/patterns/team-management/files/test/models/team_test.rb +31 -0
  238. data/patterns/team-management/files/test/support/team_management_test_helpers.rb +22 -0
  239. data/patterns/team-management/item.yml +4 -0
  240. data/patterns/team-management/pattern.md +47 -0
  241. data/patterns/webhook-deliveries/files/app/assets/stylesheets/ui/webhooks.css +179 -0
  242. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/base.rb +38 -0
  243. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/delivery.rb +160 -0
  244. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/endpoint.rb +149 -0
  245. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/form.rb +75 -0
  246. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/index.rb +142 -0
  247. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/page.rb +33 -0
  248. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/secret.rb +38 -0
  249. data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries/replays_controller.rb +13 -0
  250. data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries_controller.rb +7 -0
  251. data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints/secrets_controller.rb +41 -0
  252. data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints_controller.rb +67 -0
  253. data/patterns/webhook-deliveries/files/app/controllers/webhooks/base_controller.rb +15 -0
  254. data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_job.rb +9 -0
  255. data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_repair_job.rb +11 -0
  256. data/patterns/webhook-deliveries/files/app/models/concerns/team/webhookable.rb +11 -0
  257. data/patterns/webhook-deliveries/files/app/models/webhook/attempt.rb +30 -0
  258. data/patterns/webhook-deliveries/files/app/models/webhook/delivery.rb +268 -0
  259. data/patterns/webhook-deliveries/files/app/models/webhook/endpoint.rb +58 -0
  260. data/patterns/webhook-deliveries/files/app/models/webhook/event.rb +98 -0
  261. data/patterns/webhook-deliveries/files/app/models/webhook/secret_reveal.rb +53 -0
  262. data/patterns/webhook-deliveries/files/app/models/webhook/signature.rb +22 -0
  263. data/patterns/webhook-deliveries/files/app/models/webhook/transport.rb +176 -0
  264. data/patterns/webhook-deliveries/files/app/views/webhook_deliveries/show.html.erb +5 -0
  265. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/edit.html.erb +1 -0
  266. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/index.html.erb +6 -0
  267. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/new.html.erb +1 -0
  268. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/secrets/new.html.erb +1 -0
  269. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/show.html.erb +7 -0
  270. data/patterns/webhook-deliveries/files/config/recurring/webhooks.yml +4 -0
  271. data/patterns/webhook-deliveries/files/config/routes/webhook_deliveries.rb +10 -0
  272. data/patterns/webhook-deliveries/files/db/migrate/20260803000000_add_webhook_deliveries.rb +126 -0
  273. data/patterns/webhook-deliveries/files/test/controllers/webhook_endpoints_flow_test.rb +48 -0
  274. data/patterns/webhook-deliveries/files/test/models/webhook/delivery_test.rb +70 -0
  275. data/patterns/webhook-deliveries/files/test/system/webhook_deliveries_test.rb +29 -0
  276. data/patterns/webhook-deliveries/item.yml +4 -0
  277. data/patterns/webhook-deliveries/pattern.md +120 -0
  278. data/plugins/nitro-kit/.codex-plugin/plugin.json +4 -4
  279. data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +7 -9
  280. data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +1 -1
  281. data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +10 -9
  282. data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +1 -1
  283. data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +27 -16
  284. data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +1 -1
  285. data/src/stylesheets/nitro_kit/components/accordion.css +40 -40
  286. data/src/stylesheets/nitro_kit/components/alert.css +7 -6
  287. data/src/stylesheets/nitro_kit/components/app_navigation.css +50 -41
  288. data/src/stylesheets/nitro_kit/components/app_shell.css +371 -280
  289. data/src/stylesheets/nitro_kit/components/appearance_picker.css +38 -38
  290. data/src/stylesheets/nitro_kit/components/avatar.css +3 -3
  291. data/src/stylesheets/nitro_kit/components/avatar_stack.css +18 -18
  292. data/src/stylesheets/nitro_kit/components/badge.css +5 -2
  293. data/src/stylesheets/nitro_kit/components/button.css +57 -49
  294. data/src/stylesheets/nitro_kit/components/button_group.css +14 -14
  295. data/src/stylesheets/nitro_kit/components/checkbox.css +24 -24
  296. data/src/stylesheets/nitro_kit/components/checkbox_group.css +13 -13
  297. data/src/stylesheets/nitro_kit/components/combobox.css +152 -25
  298. data/src/stylesheets/nitro_kit/components/command_palette.css +59 -59
  299. data/src/stylesheets/nitro_kit/components/control_group.css +71 -54
  300. data/src/stylesheets/nitro_kit/components/details_table.css +9 -9
  301. data/src/stylesheets/nitro_kit/components/dialog.css +8 -12
  302. data/src/stylesheets/nitro_kit/components/dropdown.css +22 -26
  303. data/src/stylesheets/nitro_kit/components/dropzone.css +97 -100
  304. data/src/stylesheets/nitro_kit/components/empty_state.css +1 -0
  305. data/src/stylesheets/nitro_kit/components/field.css +26 -30
  306. data/src/stylesheets/nitro_kit/components/fieldset.css +2 -2
  307. data/src/stylesheets/nitro_kit/components/input.css +6 -14
  308. data/src/stylesheets/nitro_kit/components/layout.css +165 -165
  309. data/src/stylesheets/nitro_kit/components/page_header.css +3 -3
  310. data/src/stylesheets/nitro_kit/components/pagination.css +66 -49
  311. data/src/stylesheets/nitro_kit/components/pagination_bar.css +6 -6
  312. data/src/stylesheets/nitro_kit/components/palette.css +24 -22
  313. data/src/stylesheets/nitro_kit/components/progressive_image.css +38 -41
  314. data/src/stylesheets/nitro_kit/components/radio_button.css +19 -19
  315. data/src/stylesheets/nitro_kit/components/radio_button_group.css +43 -43
  316. data/src/stylesheets/nitro_kit/components/rich_text_area.css +4 -4
  317. data/src/stylesheets/nitro_kit/components/select.css +2 -2
  318. data/src/stylesheets/nitro_kit/components/settings_layout.css +17 -18
  319. data/src/stylesheets/nitro_kit/components/settings_section.css +12 -12
  320. data/src/stylesheets/nitro_kit/components/sheet.css +10 -10
  321. data/src/stylesheets/nitro_kit/components/stat_grid.css +9 -9
  322. data/src/stylesheets/nitro_kit/components/switch.css +23 -23
  323. data/src/stylesheets/nitro_kit/components/table.css +27 -27
  324. data/src/stylesheets/nitro_kit/components/tabs.css +32 -34
  325. data/src/stylesheets/nitro_kit/components/toolbar.css +6 -6
  326. data/src/stylesheets/nitro_kit/components/tooltip.css +26 -28
  327. data/src/stylesheets/nitro_kit/layers.css +10 -1
  328. data/src/stylesheets/nitro_kit/reset.css +10 -10
  329. data/{app/assets/stylesheets/nitro_kit-tailwind-v4.css → src/stylesheets/nitro_kit/tailwind.css} +10 -7
  330. data/src/stylesheets/nitro_kit/tokens.css +18 -9
  331. metadata +240 -3
@@ -2,6 +2,7 @@ require "fileutils"
2
2
  require "open3"
3
3
  require "pathname"
4
4
  require "ripper"
5
+ require "yaml"
5
6
  require "nitro_kit/migration_inventory"
6
7
 
7
8
  module NitroKit
@@ -9,9 +10,27 @@ module NitroKit
9
10
  ROOT = Pathname.new(File.expand_path("../..", __dir__))
10
11
  SKILLS = %w[nitro-kit-hotwire nitro-kit-rails nitro-kit-ui].freeze
11
12
  SKILL_ROOTS = [ ".agents/skills", ".claude/skills" ].freeze
13
+ # Doctor outcomes, most to least severe after :fail. Only :fail makes the
14
+ # installation unhealthy. :unverified means Doctor could not inspect the
15
+ # setup and names what to check by hand; :optional is a convention the
16
+ # application chose not to adopt; :warn is an application next step.
17
+ STATUS_COLORS = {
18
+ pass: :green,
19
+ optional: :blue,
20
+ unverified: :cyan,
21
+ warn: :yellow,
22
+ fail: :red
23
+ }.freeze
24
+ CONFIG_PATH = "config/nitro_kit/doctor.yml"
25
+ THEME_OWNERS = %w[nitro_kit application].freeze
26
+ CONFIG_KEYS = %w[theme_owner skill_roots retained_dependencies].freeze
27
+ # nitro_kit-tailwind-v4 is the beta-era adapter that nitro_kit.css absorbed;
28
+ # it stays managed so doctor flags a leftover link instead of ignoring it.
12
29
  MANAGED_STYLESHEETS = %w[
13
30
  lexxy nitro_kit-tailwind-v4 nitro_kit tailwind application
14
31
  ].freeze
32
+ TAILWIND_ENTRY = "app/assets/tailwind/application.css"
33
+ TAILWIND_BUNDLE_IMPORT = %r{@import\s+["'](?:\.\./)+builds/tailwind/nitro_kit(?:\.css)?["']}
15
34
  AGENTS_START = "<!-- nitro-kit:start -->"
16
35
  AGENTS_END = "<!-- nitro-kit:end -->"
17
36
  AGENTS_BLOCK = <<~MARKDOWN.freeze
@@ -23,12 +42,11 @@ module NitroKit
23
42
  Each skill resolves the installed gem with `bundle show nitro_kit` and reads
24
43
  its version-matched documentation.
25
44
 
26
- For greenfield planning or broad product work, check whether Nitro Kit
27
- catalog or MCP tools are available. When they are, inventory and search the
28
- catalog by product workflow, retrieve the relevant patterns, and state what
29
- will be used, adapted, or deferred before implementation. When they are not,
30
- continue with the bundled skills, documentation, and component contracts;
31
- catalog access is optional and must never block the work. Nitro Kit Doctor
45
+ For greenfield planning or broad product work, browse the bundled
46
+ application patterns under `patterns/` in the installed gem
47
+ (`patterns/README.md`) by product workflow, read the relevant `pattern.md`
48
+ guides and reference files, and state what will be used, adapted, or
49
+ deferred before implementation. Nitro Kit Doctor
32
50
  verifies integration health, not product completeness.
33
51
 
34
52
  In a greenfield application, run `bin/rails generate phlex:install` and use
@@ -53,12 +71,35 @@ module NitroKit
53
71
 
54
72
  Check = Struct.new(:status, :label, :detail, keyword_init: true)
55
73
  LayoutExpression = Struct.new(:range, :type, :assets, :dynamic, keyword_init: true)
56
- LayoutAnalysis = Struct.new(:head_range, :stylesheets, :bootstraps, :errors, keyword_init: true)
74
+ # errors: every reason the installer must leave the layout alone.
75
+ # uninspectable: the subset that stops Doctor from verifying the head.
76
+ # defects: the subset Doctor can prove is wrong.
77
+ LayoutAnalysis = Struct.new(:head_range, :stylesheets, :bootstraps, :errors, :uninspectable, :defects, keyword_init: true)
78
+ Configuration = Struct.new(:theme_owner, :skill_roots, :retained_dependencies, :errors, :present, keyword_init: true) do
79
+ def theme_owned_by_application? = theme_owner == "application"
80
+ end
81
+
82
+ # One line after the per-check output: the verdict, then what the
83
+ # non-failing outcomes ask of the reader.
84
+ def self.summary(checks)
85
+ counts = checks.map(&:status).tally
86
+ verdict = counts[:fail] ? "Doctor found #{counts[:fail]} failure#{'s' unless counts[:fail] == 1}" : "Doctor found no failures"
87
+ notes = []
88
+ notes << "#{counts[:unverified]} UNVERIFIED to check by hand" if counts[:unverified]
89
+ notes << "#{counts[:optional]} OPTIONAL convention#{'s' unless counts[:optional] == 1} not adopted" if counts[:optional]
90
+ notes << "#{counts[:warn]} WARN next step#{'s' unless counts[:warn] == 1}" if counts[:warn]
91
+ [ verdict, *notes ].join("; ") + "."
92
+ end
57
93
 
58
94
  attr_reader :application_root
59
95
 
60
- def initialize(application_root)
96
+ def initialize(application_root, pretend: false)
61
97
  @application_root = Pathname.new(application_root)
98
+ @pretend = pretend
99
+ end
100
+
101
+ def pretend?
102
+ @pretend
62
103
  end
63
104
 
64
105
  def install
@@ -80,7 +121,7 @@ module NitroKit
80
121
  end
81
122
 
82
123
  def write_skills
83
- SKILL_ROOTS.product(SKILLS).to_h do |root, skill|
124
+ configuration.skill_roots.product(SKILLS).to_h do |root, skill|
84
125
  destination = application_root.join(root, skill, "SKILL.md")
85
126
  source = skill_source(skill)
86
127
  [ destination.relative_path_from(application_root).to_s, write(destination, source.read) ]
@@ -104,23 +145,34 @@ module NitroKit
104
145
  def checks
105
146
  [
106
147
  version_check,
148
+ configuration_check,
107
149
  agents_check,
108
150
  skills_check,
109
151
  hotwire_check,
110
152
  stimulus_loader_check,
111
153
  stylesheet_setup_check,
154
+ appearance_check,
112
155
  phlex_kit_check,
113
156
  *migration_checks
114
- ]
157
+ ].compact
115
158
  end
116
159
 
117
160
  def healthy?
118
161
  checks.none? { _1.status == :fail }
119
162
  end
120
163
 
164
+ # Host-declared Doctor exceptions from config/nitro_kit/doctor.yml. A file
165
+ # rather than a Ruby initializer so the installer and Doctor read the same
166
+ # answer without booting the application. Invalid settings fall back to the
167
+ # defaults and fail the "Doctor configuration" check.
168
+ def configuration
169
+ @configuration ||= load_configuration
170
+ end
171
+
121
172
  private
122
173
  def write(path, contents)
123
174
  return :unchanged if path.exist? && path.read == contents
175
+ return :written if pretend?
124
176
 
125
177
  FileUtils.mkdir_p(path.dirname)
126
178
  path.write(contents)
@@ -146,18 +198,98 @@ module NitroKit
146
198
  )
147
199
  end
148
200
 
149
- def skills_check
150
- missing = SKILL_ROOTS.product(SKILLS).filter_map do |root, skill|
151
- path = application_root.join(root, skill, "SKILL.md")
152
- path.relative_path_from(application_root).to_s unless path.exist? && path.read == skill_source(skill).read
201
+ def load_configuration
202
+ defaults = { theme_owner: "nitro_kit", skill_roots: SKILL_ROOTS, retained_dependencies: {} }
203
+ path = application_root.join(CONFIG_PATH)
204
+ return Configuration.new(**defaults, errors: [], present: false) unless path.file?
205
+
206
+ data = begin
207
+ YAML.safe_load(path.read) || {}
208
+ rescue Psych::Exception => error
209
+ return Configuration.new(**defaults, errors: [ "could not parse: #{error.message}" ], present: true)
210
+ end
211
+ return Configuration.new(**defaults, errors: [ "expected a mapping of settings" ], present: true) unless data.is_a?(Hash)
212
+
213
+ errors = []
214
+ unknown = data.keys - CONFIG_KEYS
215
+ errors << "unknown settings #{unknown.join(', ')}; expected #{CONFIG_KEYS.join(', ')}" if unknown.any?
216
+
217
+ theme_owner = data.fetch("theme_owner", defaults[:theme_owner])
218
+ unless THEME_OWNERS.include?(theme_owner)
219
+ errors << "theme_owner must be one of #{THEME_OWNERS.join(', ')}"
220
+ theme_owner = defaults[:theme_owner]
221
+ end
222
+
223
+ skill_roots = data.fetch("skill_roots", SKILL_ROOTS)
224
+ unless skill_roots.is_a?(Array) && skill_roots.any? && skill_roots.uniq.size == skill_roots.size && (skill_roots - SKILL_ROOTS).empty?
225
+ errors << "skill_roots must list one or both of #{SKILL_ROOTS.join(', ')}"
226
+ skill_roots = SKILL_ROOTS
227
+ end
228
+
229
+ retained = data.fetch("retained_dependencies", {})
230
+ known = MigrationInventory::VENDORED_MODULES.keys
231
+ if !retained.is_a?(Hash)
232
+ errors << "retained_dependencies must map a package name to the reason it is retained"
233
+ retained = {}
234
+ else
235
+ invalid = retained.reject { |name, reason| known.include?(name) && reason.is_a?(String) && !reason.strip.empty? }
236
+ if invalid.any?
237
+ errors << "retained_dependencies entries need a known package (#{known.join(', ')}) and a non-empty reason: #{invalid.keys.join(', ')}"
238
+ retained = retained.except(*invalid.keys)
239
+ end
153
240
  end
241
+
242
+ Configuration.new(theme_owner:, skill_roots: SKILL_ROOTS & skill_roots, retained_dependencies: retained, errors:, present: true)
243
+ end
244
+
245
+ def configuration_check
246
+ return unless configuration.present
247
+
248
+ settings = [
249
+ "theme owner #{configuration.theme_owner}",
250
+ "skill roots #{configuration.skill_roots.join(', ')}",
251
+ "#{configuration.retained_dependencies.size} retained dependenc#{configuration.retained_dependencies.one? ? 'y' : 'ies'}"
252
+ ]
154
253
  Check.new(
155
- status: missing.empty? ? :pass : :fail,
156
- label: "Project-local skills",
157
- detail: missing.empty? ? "Codex and Claude skill routers are current" : "missing or stale: #{missing.join(', ')}"
254
+ status: configuration.errors.empty? ? :pass : :fail,
255
+ label: "Doctor configuration",
256
+ detail: "#{CONFIG_PATH}: #{configuration.errors.empty? ? settings.join('; ') : "#{configuration.errors.join('; ')}; using defaults for invalid settings"}"
158
257
  )
159
258
  end
160
259
 
260
+ def skills_check
261
+ skipped = SKILL_ROOTS - configuration.skill_roots
262
+ missing = skill_paths(configuration.skill_roots).reject { current_skill?(*_1) }.map(&:first)
263
+ # A stale copy in a root the application chose not to adopt still
264
+ # misleads the agent that reads it.
265
+ stale = skill_paths(skipped).select { |path, skill| application_root.join(path).exist? && !current_skill?(path, skill) }.map(&:first)
266
+
267
+ if missing.any? || stale.any?
268
+ detail = [
269
+ ("missing or stale: #{missing.join(', ')}" if missing.any?),
270
+ ("stale outside the configured skill_roots; refresh or remove: #{stale.join(', ')}" if stale.any?)
271
+ ].compact.join("; ")
272
+ Check.new(status: :fail, label: "Project-local skills", detail:)
273
+ elsif skipped.any?
274
+ Check.new(
275
+ status: :optional,
276
+ label: "Project-local skills",
277
+ detail: "#{configuration.skill_roots.join(', ')} current; #{skipped.join(', ')} not adopted (skill_roots in #{CONFIG_PATH})"
278
+ )
279
+ else
280
+ Check.new(status: :pass, label: "Project-local skills", detail: "Codex and Claude skill routers are current")
281
+ end
282
+ end
283
+
284
+ def skill_paths(roots)
285
+ roots.product(SKILLS).map { |root, skill| [ File.join(root, skill, "SKILL.md"), skill ] }
286
+ end
287
+
288
+ def current_skill?(path, skill)
289
+ path = application_root.join(path)
290
+ path.exist? && path.read == skill_source(skill).read
291
+ end
292
+
161
293
  def hotwire_check
162
294
  missing = %w[turbo-rails stimulus-rails].reject { Gem.loaded_specs.key?(_1) }
163
295
  Check.new(
@@ -168,72 +300,183 @@ module NitroKit
168
300
  end
169
301
 
170
302
  def stimulus_loader_check
171
- javascript = application_root.glob("app/javascript/**/*.{js,ts}").select(&:file?).map(&:read)
172
- loader = if javascript.any? { _1.include?("eagerLoadControllersFrom") }
173
- "eager controller loading"
174
- elsif javascript.any? { _1.match?(/\bapplication\.register\s*\(/) }
175
- "explicit controller registration"
303
+ label = "Stimulus loader"
304
+ files = application_root.glob("app/javascript/**/*.{js,ts}").select(&:file?)
305
+ sources = files.map(&:read)
306
+ importmap = application_root.join("config/importmap.rb").file?
307
+
308
+ if sources.any? { _1.match?(/\b(?:eager|lazy)LoadControllersFrom\s*\(\s*["']controllers["']/) }
309
+ if importmap
310
+ return Check.new(
311
+ status: :pass,
312
+ label:,
313
+ detail: "importmap controller loading is configured (Nitro Kit engine pins controllers/nk/*)"
314
+ )
315
+ end
316
+
317
+ return Check.new(
318
+ status: :unverified,
319
+ label:,
320
+ detail: "importmap-style controller loading is configured, but config/importmap.rb is absent; check by hand that Nitro Kit controllers (nk--*) are registered"
321
+ )
322
+ end
323
+
324
+ registered = registered_nitro_controllers(sources)
325
+ if registered.any?
326
+ missing = nitro_controller_identifiers - registered
327
+ if missing.empty?
328
+ return Check.new(
329
+ status: :pass,
330
+ label:,
331
+ detail: "explicit Nitro Kit controller registration covers all #{nitro_controller_identifiers.size} controllers"
332
+ )
333
+ end
334
+
335
+ return Check.new(
336
+ status: :fail,
337
+ label:,
338
+ detail: "explicit Nitro Kit controller registration is missing: #{missing.join(', ')}"
339
+ )
340
+ end
341
+
342
+ if sources.any? { _1.match?(/\bapplication\.register\s*\(/) }
343
+ return Check.new(
344
+ status: :fail,
345
+ label:,
346
+ detail: "Stimulus registers controllers explicitly, but no Nitro Kit controllers are registered; missing: #{nitro_controller_identifiers.join(', ')}"
347
+ )
176
348
  end
177
349
 
178
350
  Check.new(
179
- status: loader ? :pass : :warn,
180
- label: "Stimulus loader",
181
- detail: loader ? "#{loader} is configured" : "verify the application's controller registration"
351
+ status: :unverified,
352
+ label:,
353
+ detail: "could not verify Nitro Kit Stimulus controller registration; check by hand that controllers/nk/* (#{nitro_controller_identifiers.size} controllers) are registered"
182
354
  )
183
355
  end
184
356
 
357
+ def nitro_controller_identifiers
358
+ @nitro_controller_identifiers ||= ROOT.glob("app/javascript/controllers/nk/**/*_controller.js").sort.map do |path|
359
+ path.relative_path_from(ROOT.join("app/javascript/controllers")).to_s
360
+ .delete_suffix("_controller.js")
361
+ .tr("_", "-")
362
+ .gsub("/", "--")
363
+ end
364
+ end
365
+
366
+ def registered_nitro_controllers(sources)
367
+ sources.flat_map do |source|
368
+ source.scan(/\bapplication\.register\s*\(\s*["'](nk--[a-z0-9-]+)["']/).flatten
369
+ end.uniq.sort
370
+ end
371
+
185
372
  def stylesheet_setup_check
186
- return Check.new(
187
- status: :fail,
188
- label: "Stylesheet and appearance setup",
189
- detail: "missing application layout; add AppearanceBootstrap before the ordered stylesheet entries"
190
- ) unless layout_path
373
+ label = "Stylesheet and appearance setup"
374
+ unless layout_path
375
+ other_layouts = application_root.glob("app/views/layouts/*.{erb,haml,slim}").select(&:file?)
376
+ if other_layouts.any?
377
+ return Check.new(
378
+ status: :unverified,
379
+ label:,
380
+ detail: "no conventional application layout; check by hand that #{other_layouts.map { relative(_1) }.join(', ')} load#{'s' if other_layouts.one?} #{setup_sequence(%w[nitro_kit])} before application styles"
381
+ )
382
+ end
191
383
 
192
- contents = layout_path.read
193
- analysis = analyze_layout(contents)
384
+ detail = bootstrap_required? ? "add AppearanceBootstrap before the ordered stylesheet entries" : "add the ordered stylesheet entries"
385
+ return Check.new(status: :fail, label:, detail: "missing application layout; #{detail}")
386
+ end
387
+
388
+ analysis = analyze_layout(layout_path.read)
194
389
  expected = expected_stylesheets(analysis)
195
- errors = []
196
- bootstrap_count = analysis.bootstraps.size
390
+ assets = managed_stylesheet_assets(analysis)
391
+ location = relative(layout_path)
392
+
393
+ if analysis.uninspectable.any?
394
+ defects = analysis.defects + visible_stylesheet_defects(expected, assets)
395
+ if defects.any?
396
+ return Check.new(
397
+ status: :fail,
398
+ label:,
399
+ detail: "#{location}: #{defects.join('; ')}; installer left the layout unchanged — #{analysis.errors.join('; ')}"
400
+ )
401
+ end
197
402
 
198
- if analysis.errors.any?
199
403
  return Check.new(
200
- status: :fail,
201
- label: "Stylesheet and appearance setup",
202
- detail: "#{relative(layout_path)}: installer left the layout unchanged — #{analysis.errors.join('; ')}; manually ensure AppearanceBootstrap → #{expected.join(' → ')} without discarding existing options"
404
+ status: :unverified,
405
+ label:,
406
+ detail: "#{location}: could not inspect the head — #{analysis.uninspectable.join('; ')}; check by hand that the rendered head loads #{setup_sequence(expected)}, each once, in that order"
203
407
  )
204
408
  end
205
409
 
206
- errors << "add one NitroKit::AppearanceBootstrap before every stylesheet" if bootstrap_count.zero?
410
+ errors = analysis.defects.dup
411
+ bootstrap_count = analysis.bootstraps.size
412
+ errors << "add one NitroKit::AppearanceBootstrap before every stylesheet" if bootstrap_count.zero? && bootstrap_required?
207
413
  errors << "remove duplicate NitroKit::AppearanceBootstrap entries" if bootstrap_count > 1
208
414
 
209
- assets = managed_stylesheet_assets(analysis)
210
415
  expected.each do |stylesheet|
211
416
  count = assets.count(stylesheet)
212
417
  errors << "add stylesheet #{stylesheet.inspect}" if count.zero?
213
418
  errors << "remove duplicate stylesheet #{stylesheet.inspect}" if count > 1
214
419
  end
215
420
 
216
- if (edit_error = layout_edit_error(analysis, expected))
217
- errors << "installer left the layout unchanged: #{edit_error}"
218
- end
421
+ errors.concat(obsolete_stylesheet_defects(assets))
219
422
 
220
- if assets.include?("nitro_kit-tailwind-v4") && !expected.include?("tailwind")
221
- errors << "remove nitro_kit-tailwind-v4 or load compiled Tailwind after nitro_kit"
423
+ bootstrap = analysis.bootstraps.first
424
+ first_stylesheet = analysis.stylesheets.first
425
+ bootstrap_late = bootstrap && first_stylesheet && bootstrap.range.begin >= first_stylesheet.range.begin
426
+ if errors.empty? && (bootstrap_late || assets != expected)
427
+ errors << "reorder to #{setup_sequence(expected)}"
222
428
  end
223
429
 
224
- bootstrap_position = analysis.bootstraps.first&.range&.begin
225
- first_stylesheet_position = analysis.stylesheets.first&.range&.begin
226
- if errors.empty? && (bootstrap_position >= first_stylesheet_position || assets != expected)
227
- errors << "reorder to AppearanceBootstrap → #{expected.join(' → ')}"
430
+ if errors.any? && (edit_error = layout_edit_error(analysis, expected))
431
+ errors << "installer left the layout unchanged: #{edit_error}"
228
432
  end
229
433
 
230
434
  Check.new(
231
435
  status: errors.empty? ? :pass : :fail,
232
- label: "Stylesheet and appearance setup",
233
- detail: errors.empty? ? "#{relative(layout_path)}: AppearanceBootstrap → #{expected.join(' → ')}" : "#{relative(layout_path)}: #{errors.join('; ')}"
436
+ label:,
437
+ detail: "#{location}: #{errors.empty? ? setup_sequence(expected, present: bootstrap) : errors.join('; ')}"
234
438
  )
235
439
  end
236
440
 
441
+ # Order problems Doctor can still prove from the static calls it found in
442
+ # a head it could not fully inspect.
443
+ def visible_stylesheet_defects(expected, assets)
444
+ defects = obsolete_stylesheet_defects(assets)
445
+ visible = assets.uniq - [ "nitro_kit-tailwind-v4" ]
446
+ defects << "reorder the visible stylesheets to #{setup_sequence(expected)}" unless visible == expected.select { visible.include?(_1) }
447
+ defects
448
+ end
449
+
450
+ def obsolete_stylesheet_defects(assets)
451
+ defects = []
452
+ if assets.include?("nitro_kit-tailwind-v4")
453
+ defects << "remove stylesheet \"nitro_kit-tailwind-v4\"; nitro_kit now includes the Tailwind v4 layer order and theme aliases"
454
+ end
455
+ if tailwind_bundles_nitro_kit? && assets.include?("nitro_kit")
456
+ defects << "remove stylesheet \"nitro_kit\"; #{TAILWIND_ENTRY} already bundles it"
457
+ end
458
+ defects
459
+ end
460
+
461
+ def appearance_check
462
+ return unless configuration.theme_owned_by_application?
463
+
464
+ Check.new(
465
+ status: :optional,
466
+ label: "Appearance bootstrap",
467
+ detail: "theme_owner is application in #{CONFIG_PATH}, so AppearanceBootstrap is not required; set data-theme=\"light|dark\" on <html> or leave it unset to follow prefers-color-scheme. AppearancePicker still needs AppearanceBootstrap"
468
+ )
469
+ end
470
+
471
+ def bootstrap_required?
472
+ !configuration.theme_owned_by_application?
473
+ end
474
+
475
+ def setup_sequence(stylesheets, present: nil)
476
+ bootstrap = bootstrap_required? || present ? [ "AppearanceBootstrap" ] : []
477
+ [ *bootstrap, *stylesheets ].join(" → ")
478
+ end
479
+
237
480
  def phlex_kit_check
238
481
  ready = application_root.glob("app/components/**/*.rb").any? { _1.read.match?(/include\s+(?:\(?\s*)?NitroKit\b/) }
239
482
  Check.new(
@@ -244,9 +487,17 @@ module NitroKit
244
487
  end
245
488
 
246
489
  def migration_checks
247
- MigrationInventory.new(application_root).categories.map do |label, findings|
490
+ inventory = MigrationInventory.new(application_root, retained_dependencies: configuration.retained_dependencies)
491
+ inventory.categories.map do |label, findings|
492
+ status = if findings.empty?
493
+ :pass
494
+ elsif findings.all? { _1.status == :retained }
495
+ :optional
496
+ else
497
+ :warn
498
+ end
248
499
  Check.new(
249
- status: findings.empty? ? :pass : :warn,
500
+ status:,
250
501
  label: "Migration: #{label}",
251
502
  detail: findings.empty? ? "migrated: none found" : findings.map do |finding|
252
503
  "#{finding.status.to_s.tr('_', '-')}: #{finding.path} — #{finding.guidance}"
@@ -279,13 +530,14 @@ module NitroKit
279
530
  return contents if edit_error
280
531
 
281
532
  missing = expected - managed_stylesheet_assets(analysis)
282
- return contents if missing.empty? && analysis.bootstraps.one?
533
+ insert_bootstrap = analysis.bootstraps.empty? && bootstrap_required?
534
+ return contents if missing.empty? && !insert_bootstrap
283
535
 
284
536
  lines = contents.lines
285
537
  insertions = Hash.new { |hash, index| hash[index] = [] }
286
538
  indent = layout_indent(lines, analysis)
287
539
 
288
- if analysis.bootstraps.empty?
540
+ if insert_bootstrap
289
541
  bootstrap_index = analysis.stylesheets.first&.range&.begin || analysis.head_range.begin + 1
290
542
  insertions[bootstrap_index] << bootstrap_markup(indent)
291
543
  end
@@ -305,31 +557,38 @@ module NitroKit
305
557
 
306
558
  def analyze_layout(contents)
307
559
  errors = []
308
- errors << "multiple application layouts found: #{layout_paths.map { relative(_1) }.join(', ')}" if layout_paths.many?
560
+ uninspectable = []
561
+ defects = []
562
+ unverifiable = ->(message) { errors << message; uninspectable << message }
563
+ defect = ->(message) { errors << message; defects << message }
564
+
565
+ unverifiable.("multiple application layouts found: #{layout_paths.map { relative(_1) }.join(', ')}") if layout_paths.many?
309
566
  lines = contents.lines
310
567
  head_range, boundary_errors = if layout_path.extname == ".rb"
311
568
  phlex_head_range(contents)
312
569
  else
313
570
  erb_head_range(contents)
314
571
  end
315
- errors.concat(boundary_errors)
572
+ boundary_errors.each(&unverifiable)
316
573
 
317
574
  all_expressions = layout_path.extname == ".rb" ? phlex_layout_expressions(contents) : erb_layout_expressions(contents)
318
575
  expressions = if head_range
319
576
  all_expressions.select do |expression|
320
577
  inside = head_range.cover?(expression.range.begin) && head_range.cover?(expression.range.end)
321
578
  overlaps = head_range.cover?(expression.range.begin) || head_range.cover?(expression.range.end)
322
- errors << "#{expression.type} call on line #{expression.range.begin + 1} crosses the document head boundary" if overlaps && !inside
579
+ unverifiable.("#{expression.type} call on line #{expression.range.begin + 1} crosses the document head boundary") if overlaps && !inside
323
580
  inside
324
581
  end
325
582
  else
326
583
  []
327
584
  end
328
- outside_expressions = all_expressions - expressions
329
- outside_expressions.each do |expression|
330
- next if head_range && (head_range.cover?(expression.range.begin) || head_range.cover?(expression.range.end))
585
+ # Without a known head, Doctor cannot tell where a call renders.
586
+ if head_range && boundary_errors.empty?
587
+ (all_expressions - expressions).each do |expression|
588
+ next if head_range.cover?(expression.range.begin) || head_range.cover?(expression.range.end)
331
589
 
332
- errors << "#{expression.type} call on line #{expression.range.begin + 1} is outside the document head"
590
+ defect.("#{expression.type} call on line #{expression.range.begin + 1} is outside the document head")
591
+ end
333
592
  end
334
593
 
335
594
  stylesheets = expressions.select { _1.type == :stylesheet }
@@ -338,24 +597,32 @@ module NitroKit
338
597
 
339
598
  expressions.each do |expression|
340
599
  actual_indent = lines[expression.range.begin][/^\s*/].to_s.length
341
- errors << "#{expression.type} call on line #{expression.range.begin + 1} is conditional or nested" unless actual_indent == target_indent
600
+ unverifiable.("#{expression.type} call on line #{expression.range.begin + 1} is conditional or nested") unless actual_indent == target_indent
342
601
  end
343
602
  stylesheets.each do |expression|
344
- errors << "stylesheet call on line #{expression.range.begin + 1} has dynamic assets" if expression.dynamic
603
+ unverifiable.("stylesheet call on line #{expression.range.begin + 1} has dynamic assets") if expression.dynamic
345
604
  if (expression.assets & MANAGED_STYLESHEETS).any? && (expression.assets - MANAGED_STYLESHEETS).any?
605
+ # Doctor can still read the order; only the installer must stay out.
346
606
  errors << "stylesheet call on line #{expression.range.begin + 1} combines custom and canonical assets"
347
607
  end
348
608
  end
349
609
 
350
610
  head_contents = head_range ? lines[head_range].join : ""
351
611
  if layout_path.extname == ".erb" && head_contents.match?(/<%(?![=%#])/)
352
- errors << "head contains conditional or executable ERB"
612
+ unverifiable.("head contains conditional or executable ERB")
353
613
  end
354
614
  if head_contents.match?(/<link\b[^>]*\brel=["']stylesheet["']/i)
355
- errors << "head contains a custom stylesheet link"
615
+ unverifiable.("head contains a custom stylesheet link")
356
616
  end
357
617
 
358
- LayoutAnalysis.new(head_range: head_range || (0..0), stylesheets:, bootstraps:, errors: errors.uniq)
618
+ LayoutAnalysis.new(
619
+ head_range: head_range || (0..0),
620
+ stylesheets:,
621
+ bootstraps:,
622
+ errors: errors.uniq,
623
+ uninspectable: uninspectable.uniq,
624
+ defects: defects.uniq
625
+ )
359
626
  end
360
627
 
361
628
  def erb_head_range(contents)
@@ -569,17 +836,20 @@ module NitroKit
569
836
  assets = managed_stylesheet_assets(analysis) - [ "nitro_kit-tailwind-v4" ]
570
837
  assets << "lexxy" if dependency?("lexxy")
571
838
  assets << "tailwind" if tailwind?(assets)
572
- assets << "nitro_kit"
839
+ if tailwind_bundles_nitro_kit?
840
+ assets -= [ "nitro_kit" ]
841
+ assets << "tailwind"
842
+ else
843
+ assets << "nitro_kit"
844
+ end
573
845
  assets << "application" if assets.include?("application") || application_stylesheet_asset?
574
- assets << "nitro_kit-tailwind-v4" if assets.include?("tailwind")
575
846
  ordered_stylesheets(assets.uniq)
576
847
  end
577
848
 
578
849
  def ordered_stylesheets(assets)
579
- vendor = assets - %w[nitro_kit-tailwind-v4 nitro_kit tailwind application]
850
+ vendor = assets - %w[nitro_kit tailwind application]
580
851
  [
581
852
  *vendor,
582
- *(%w[nitro_kit-tailwind-v4] & assets),
583
853
  *(%w[nitro_kit] & assets),
584
854
  *(%w[tailwind] & assets),
585
855
  *(%w[application] & assets)
@@ -597,6 +867,9 @@ module NitroKit
597
867
 
598
868
  existing = managed_stylesheet_assets(analysis)
599
869
  return "duplicate canonical stylesheet assets require manual review" if existing.uniq != existing
870
+ if existing.include?("nitro_kit-tailwind-v4")
871
+ return "drop \"nitro_kit-tailwind-v4\" from its stylesheet call without changing the call's options"
872
+ end
600
873
  unless existing == expected.select { existing.include?(_1) }
601
874
  return "existing canonical stylesheets are misordered; reorder their intact calls manually"
602
875
  end
@@ -657,7 +930,15 @@ module NitroKit
657
930
  end
658
931
 
659
932
  def tailwind?(assets)
660
- assets.include?("tailwind") || dependency?("tailwindcss-rails") || application_root.join("app/assets/tailwind/application.css").file?
933
+ assets.include?("tailwind") || dependency?("tailwindcss-rails") || application_root.join(TAILWIND_ENTRY).file?
934
+ end
935
+
936
+ # True when the application's Tailwind source imports the engine entry
937
+ # that tailwindcss-rails generates from app/assets/tailwind/nitro_kit/engine.css,
938
+ # so the compiled "tailwind" stylesheet already contains Nitro Kit.
939
+ def tailwind_bundles_nitro_kit?
940
+ entry = application_root.join(TAILWIND_ENTRY)
941
+ entry.file? && entry.read.match?(TAILWIND_BUNDLE_IMPORT)
661
942
  end
662
943
 
663
944
  def application_stylesheet_asset?