nitro_kit 2.0.0.beta.3 → 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 (326) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -0
  3. data/LICENSE +21 -28
  4. data/README.md +10 -9
  5. data/app/assets/stylesheets/nitro_kit.css +1660 -1401
  6. data/app/components/nitro_kit/accordion.rb +1 -13
  7. data/app/components/nitro_kit/app_navigation.rb +0 -12
  8. data/app/components/nitro_kit/app_shell.rb +5 -11
  9. data/app/components/nitro_kit/appearance_picker.rb +1 -7
  10. data/app/components/nitro_kit/combobox.rb +366 -21
  11. data/app/components/nitro_kit/command_palette.rb +7 -20
  12. data/app/components/nitro_kit/details_table.rb +5 -11
  13. data/app/components/nitro_kit/dropzone.rb +3 -15
  14. data/app/components/nitro_kit/field.rb +20 -2
  15. data/app/components/nitro_kit/pagination.rb +2 -8
  16. data/app/components/nitro_kit/settings_layout.rb +3 -9
  17. data/app/javascript/controllers/nk/app_shell_controller.js +2 -2
  18. data/app/javascript/controllers/nk/combobox_controller.js +308 -22
  19. data/app/javascript/controllers/nk/combobox_remote.js +70 -0
  20. data/app/javascript/controllers/nk/dropzone_controller.js +2 -2
  21. data/app/javascript/controllers/nk/tabs_controller.js +2 -2
  22. data/config/locales/en.yml +3 -0
  23. data/docs/agent_guide.md +43 -13
  24. data/docs/component_contracts.md +90 -61
  25. data/docs/customization.md +173 -35
  26. data/docs/initialization_prompt.md +4 -5
  27. data/docs/migration_1_to_2.md +10 -8
  28. data/docs/patterns/application_foundation.md +5 -0
  29. data/docs/patterns/composition.md +61 -0
  30. data/docs/patterns/crud_resource.md +5 -0
  31. data/docs/patterns/inset_workspace.md +21 -22
  32. data/docs/patterns/resource_form.md +65 -0
  33. data/docs/rails_integration.md +214 -2
  34. data/lib/generators/nitro_kit/install_generator.rb +5 -4
  35. data/lib/nitro_kit/installation.rb +327 -68
  36. data/lib/nitro_kit/migration_inventory.rb +18 -3
  37. data/lib/nitro_kit/version.rb +1 -1
  38. data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +2 -2
  39. data/patterns/README.md +21 -0
  40. data/patterns/account-settings/files/app/components/ui/account_settings/account_deletion.rb +72 -0
  41. data/patterns/account-settings/files/app/components/ui/account_settings/base.rb +44 -0
  42. data/patterns/account-settings/files/app/components/ui/account_settings/page.rb +57 -0
  43. data/patterns/account-settings/files/app/components/ui/account_settings/preferences.rb +68 -0
  44. data/patterns/account-settings/files/app/components/ui/account_settings/profile.rb +86 -0
  45. data/patterns/account-settings/files/app/components/ui/account_settings/security.rb +69 -0
  46. data/patterns/account-settings/files/app/components/ui/account_settings/sessions.rb +86 -0
  47. data/patterns/account-settings/files/app/controllers/settings/account_deletions_controller.rb +35 -0
  48. data/patterns/account-settings/files/app/controllers/settings/base_controller.rb +12 -0
  49. data/patterns/account-settings/files/app/controllers/settings/other_sessions_controller.rb +8 -0
  50. data/patterns/account-settings/files/app/controllers/settings/preferences_controller.rb +27 -0
  51. data/patterns/account-settings/files/app/controllers/settings/profiles_controller.rb +20 -0
  52. data/patterns/account-settings/files/app/controllers/settings/securities_controller.rb +37 -0
  53. data/patterns/account-settings/files/app/controllers/settings/sessions_controller.rb +31 -0
  54. data/patterns/account-settings/files/app/models/account_settings/account_closure.rb +33 -0
  55. data/patterns/account-settings/files/app/models/account_settings/password_change.rb +42 -0
  56. data/patterns/account-settings/files/app/models/account_settings/session_summary.rb +45 -0
  57. data/patterns/account-settings/files/app/models/concerns/user/account_configurable.rb +18 -0
  58. data/patterns/account-settings/files/config/routes/account_settings.rb +10 -0
  59. data/patterns/account-settings/files/db/migrate/20260731020000_add_account_settings.rb +27 -0
  60. data/patterns/account-settings/files/test/controllers/settings/account_settings_flow_test.rb +84 -0
  61. data/patterns/account-settings/files/test/models/account_settings/password_change_test.rb +40 -0
  62. data/patterns/account-settings/files/test/system/account_settings_test.rb +52 -0
  63. data/patterns/account-settings/item.yml +4 -0
  64. data/patterns/account-settings/pattern.md +44 -0
  65. data/patterns/application-shell/files/app/assets/stylesheets/ui/application_shell.css +267 -0
  66. data/patterns/application-shell/files/app/components/ui/application_shell.rb +184 -0
  67. data/patterns/application-shell/item.yml +4 -0
  68. data/patterns/application-shell/pattern.md +110 -0
  69. data/patterns/authentication/files/app/components/ui/authentication/base.rb +11 -0
  70. data/patterns/authentication/files/app/components/ui/authentication/page.rb +53 -0
  71. data/patterns/authentication/files/app/components/ui/email_verifications/show.rb +62 -0
  72. data/patterns/authentication/files/app/components/ui/password_resets/new.rb +65 -0
  73. data/patterns/authentication/files/app/components/ui/passwords/edit.rb +72 -0
  74. data/patterns/authentication/files/app/components/ui/sessions/new.rb +58 -0
  75. data/patterns/authentication/files/app/components/ui/verification_emails/new.rb +59 -0
  76. data/patterns/authentication/files/app/controllers/concerns/authentication.rb +66 -0
  77. data/patterns/authentication/files/app/controllers/concerns/safe_return_navigation.rb +37 -0
  78. data/patterns/authentication/files/app/controllers/email_verifications_controller.rb +39 -0
  79. data/patterns/authentication/files/app/controllers/password_resets_controller.rb +33 -0
  80. data/patterns/authentication/files/app/controllers/passwords_controller.rb +51 -0
  81. data/patterns/authentication/files/app/controllers/sessions_controller.rb +42 -0
  82. data/patterns/authentication/files/app/controllers/verification_emails_controller.rb +33 -0
  83. data/patterns/authentication/files/app/jobs/authentication_delivery_job.rb +17 -0
  84. data/patterns/authentication/files/app/mailers/authentication_mailer.rb +15 -0
  85. data/patterns/authentication/files/app/models/authentication/credentials.rb +16 -0
  86. data/patterns/authentication/files/app/models/authentication/email_request.rb +17 -0
  87. data/patterns/authentication/files/app/models/concerns/user/email_verifiable.rb +40 -0
  88. data/patterns/authentication/files/app/models/session.rb +5 -0
  89. data/patterns/authentication/files/app/views/authentication_mailer/email_verification.html.erb +3 -0
  90. data/patterns/authentication/files/app/views/authentication_mailer/email_verification.text.erb +5 -0
  91. data/patterns/authentication/files/app/views/authentication_mailer/password_reset.html.erb +3 -0
  92. data/patterns/authentication/files/app/views/authentication_mailer/password_reset.text.erb +5 -0
  93. data/patterns/authentication/files/config/routes/authentication.rb +11 -0
  94. data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb +13 -0
  95. data/patterns/authentication/files/test/controllers/authentication_flow_test.rb +103 -0
  96. data/patterns/authentication/files/test/controllers/safe_return_navigation_test.rb +18 -0
  97. data/patterns/authentication/files/test/mailers/authentication_mailer_test.rb +21 -0
  98. data/patterns/authentication/files/test/models/user_email_verifiable_test.rb +36 -0
  99. data/patterns/authentication/files/test/system/authentication_flow_test.rb +23 -0
  100. data/patterns/authentication/item.yml +12 -0
  101. data/patterns/authentication/pattern.md +54 -0
  102. data/patterns/crud-resource/files/app/assets/stylesheets/ui/projects.css +4 -0
  103. data/patterns/crud-resource/files/app/components/ui/projects/form.rb +89 -0
  104. data/patterns/crud-resource/files/app/components/ui/projects/index.rb +161 -0
  105. data/patterns/crud-resource/files/app/components/ui/projects/show.rb +84 -0
  106. data/patterns/crud-resource/files/app/controllers/projects/archivals_controller.rb +23 -0
  107. data/patterns/crud-resource/files/app/controllers/projects_controller.rb +70 -0
  108. data/patterns/crud-resource/files/app/models/project/archival.rb +8 -0
  109. data/patterns/crud-resource/files/app/models/project/event.rb +12 -0
  110. data/patterns/crud-resource/files/app/models/project/filter.rb +41 -0
  111. data/patterns/crud-resource/files/app/models/project.rb +41 -0
  112. data/patterns/crud-resource/files/app/views/projects/edit.html.erb +19 -0
  113. data/patterns/crud-resource/files/app/views/projects/index.html.erb +18 -0
  114. data/patterns/crud-resource/files/app/views/projects/new.html.erb +16 -0
  115. data/patterns/crud-resource/files/app/views/projects/show.html.erb +28 -0
  116. data/patterns/crud-resource/files/config/routes/crud_resource.rb +7 -0
  117. data/patterns/crud-resource/files/db/migrate/20260720000000_create_crud_resource.rb +37 -0
  118. data/patterns/crud-resource/files/test/controllers/projects_controller_test.rb +64 -0
  119. data/patterns/crud-resource/files/test/models/project_test.rb +34 -0
  120. data/patterns/crud-resource/files/test/support/crud_resource_test_helpers.rb +25 -0
  121. data/patterns/crud-resource/files/test/system/projects_crud_test.rb +87 -0
  122. data/patterns/crud-resource/item.yml +6 -0
  123. data/patterns/crud-resource/pattern.md +48 -0
  124. data/patterns/file-uploads/files/app/assets/stylesheets/ui/uploads.css +133 -0
  125. data/patterns/file-uploads/files/app/components/ui/uploads/base.rb +30 -0
  126. data/patterns/file-uploads/files/app/components/ui/uploads/index.rb +188 -0
  127. data/patterns/file-uploads/files/app/components/ui/uploads/page.rb +33 -0
  128. data/patterns/file-uploads/files/app/controllers/uploads/base_controller.rb +29 -0
  129. data/patterns/file-uploads/files/app/controllers/uploads/direct_uploads_controller.rb +55 -0
  130. data/patterns/file-uploads/files/app/controllers/uploads/retries_controller.rb +14 -0
  131. data/patterns/file-uploads/files/app/controllers/uploads_controller.rb +40 -0
  132. data/patterns/file-uploads/files/app/jobs/upload_blob_cleanup_job.rb +9 -0
  133. data/patterns/file-uploads/files/app/jobs/upload_processing_job.rb +10 -0
  134. data/patterns/file-uploads/files/app/jobs/upload_repair_job.rb +17 -0
  135. data/patterns/file-uploads/files/app/models/concerns/team/uploadable.rb +9 -0
  136. data/patterns/file-uploads/files/app/models/upload.rb +295 -0
  137. data/patterns/file-uploads/files/config/recurring/uploads.yml +7 -0
  138. data/patterns/file-uploads/files/config/routes/uploads.rb +5 -0
  139. data/patterns/file-uploads/files/db/migrate/20260802000000_add_file_uploads.rb +30 -0
  140. data/patterns/file-uploads/files/test/controllers/uploads_flow_test.rb +77 -0
  141. data/patterns/file-uploads/files/test/fixtures/files/workspace.png.base64 +1 -0
  142. data/patterns/file-uploads/files/test/fixtures/uploads.yml +17 -0
  143. data/patterns/file-uploads/files/test/models/upload_test.rb +55 -0
  144. data/patterns/file-uploads/files/test/system/file_uploads_test.rb +30 -0
  145. data/patterns/file-uploads/item.yml +4 -0
  146. data/patterns/file-uploads/pattern.md +71 -0
  147. data/patterns/nitro-kit-1-upgrade/files/docs/nitro_kit_1_upgrade.md +57 -0
  148. data/patterns/nitro-kit-1-upgrade/item.yml +4 -0
  149. data/patterns/nitro-kit-1-upgrade/pattern.md +30 -0
  150. data/patterns/onboarding/files/app/assets/stylesheets/ui/onboarding.css +55 -0
  151. data/patterns/onboarding/files/app/components/ui/onboarding/base.rb +11 -0
  152. data/patterns/onboarding/files/app/components/ui/onboarding/branch_form.rb +36 -0
  153. data/patterns/onboarding/files/app/components/ui/onboarding/details_form.rb +67 -0
  154. data/patterns/onboarding/files/app/components/ui/onboarding/invitation_plan_form.rb +48 -0
  155. data/patterns/onboarding/files/app/components/ui/onboarding/page.rb +75 -0
  156. data/patterns/onboarding/files/app/components/ui/onboarding/review.rb +51 -0
  157. data/patterns/onboarding/files/app/components/ui/onboarding/show.rb +32 -0
  158. data/patterns/onboarding/files/app/controllers/concerns/requires_finished_onboarding.rb +14 -0
  159. data/patterns/onboarding/files/app/controllers/onboarding/base_controller.rb +30 -0
  160. data/patterns/onboarding/files/app/controllers/onboarding/branches_controller.rb +16 -0
  161. data/patterns/onboarding/files/app/controllers/onboarding/completions_controller.rb +13 -0
  162. data/patterns/onboarding/files/app/controllers/onboarding/details_controller.rb +16 -0
  163. data/patterns/onboarding/files/app/controllers/onboarding/invitation_plans_controller.rb +20 -0
  164. data/patterns/onboarding/files/app/controllers/onboardings_controller.rb +7 -0
  165. data/patterns/onboarding/files/app/jobs/onboarding_invitation_delivery_job.rb +15 -0
  166. data/patterns/onboarding/files/app/models/concerns/team/onboardable.rb +23 -0
  167. data/patterns/onboarding/files/app/models/onboarding/completion.rb +17 -0
  168. data/patterns/onboarding/files/app/models/onboarding/invitation_delivery.rb +14 -0
  169. data/patterns/onboarding/files/app/models/onboarding.rb +174 -0
  170. data/patterns/onboarding/files/config/routes/onboarding.rb +11 -0
  171. data/patterns/onboarding/files/db/migrate/20260731010000_create_onboarding.rb +60 -0
  172. data/patterns/onboarding/files/test/controllers/onboarding_flow_test.rb +62 -0
  173. data/patterns/onboarding/files/test/fixtures/onboarding_completions.yml +3 -0
  174. data/patterns/onboarding/files/test/fixtures/onboardings.yml +25 -0
  175. data/patterns/onboarding/files/test/jobs/onboarding_invitation_delivery_job_test.rb +18 -0
  176. data/patterns/onboarding/files/test/models/onboarding_test.rb +60 -0
  177. data/patterns/onboarding/files/test/system/onboarding_flow_test.rb +39 -0
  178. data/patterns/onboarding/item.yml +4 -0
  179. data/patterns/onboarding/pattern.md +53 -0
  180. data/patterns/subscription-billing/files/app/components/ui/billing/base.rb +39 -0
  181. data/patterns/subscription-billing/files/app/components/ui/billing/checkout_result.rb +64 -0
  182. data/patterns/subscription-billing/files/app/components/ui/billing/page.rb +33 -0
  183. data/patterns/subscription-billing/files/app/components/ui/billing/show.rb +149 -0
  184. data/patterns/subscription-billing/files/app/controllers/billing/base_controller.rb +16 -0
  185. data/patterns/subscription-billing/files/app/controllers/billing/checkouts_controller.rb +65 -0
  186. data/patterns/subscription-billing/files/app/controllers/billing/portals_controller.rb +18 -0
  187. data/patterns/subscription-billing/files/app/controllers/billing_controller.rb +17 -0
  188. data/patterns/subscription-billing/files/app/controllers/webhooks/stripe_events_controller.rb +21 -0
  189. data/patterns/subscription-billing/files/app/jobs/billing/stripe_event_job.rb +16 -0
  190. data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_job.rb +16 -0
  191. data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_sweep_job.rb +9 -0
  192. data/patterns/subscription-billing/files/app/models/billing/checkout.rb +58 -0
  193. data/patterns/subscription-billing/files/app/models/billing/plan.rb +19 -0
  194. data/patterns/subscription-billing/files/app/models/billing/stripe_event.rb +73 -0
  195. data/patterns/subscription-billing/files/app/models/billing/subscription.rb +106 -0
  196. data/patterns/subscription-billing/files/app/models/concerns/team/billable.rb +36 -0
  197. data/patterns/subscription-billing/files/config/initializers/stripe.rb +29 -0
  198. data/patterns/subscription-billing/files/config/routes/subscription_billing.rb +10 -0
  199. data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb +61 -0
  200. data/patterns/subscription-billing/files/test/controllers/billing_flow_test.rb +60 -0
  201. data/patterns/subscription-billing/files/test/models/billing/subscription_test.rb +40 -0
  202. data/patterns/subscription-billing/files/test/system/subscription_billing_test.rb +28 -0
  203. data/patterns/subscription-billing/item.yml +4 -0
  204. data/patterns/subscription-billing/pattern.md +59 -0
  205. data/patterns/team-management/files/app/components/ui/invitations/acceptance.rb +33 -0
  206. data/patterns/team-management/files/app/components/ui/teams/index.rb +87 -0
  207. data/patterns/team-management/files/app/components/ui/teams/invitation_form.rb +51 -0
  208. data/patterns/team-management/files/app/components/ui/teams/member_form.rb +78 -0
  209. data/patterns/team-management/files/app/components/ui/teams/members.rb +125 -0
  210. data/patterns/team-management/files/app/controllers/invitations/acceptances_controller.rb +29 -0
  211. data/patterns/team-management/files/app/controllers/teams/base_controller.rb +18 -0
  212. data/patterns/team-management/files/app/controllers/teams/invitations_controller.rb +42 -0
  213. data/patterns/team-management/files/app/controllers/teams/memberships_controller.rb +53 -0
  214. data/patterns/team-management/files/app/controllers/teams_controller.rb +30 -0
  215. data/patterns/team-management/files/app/mailers/team_invitation_mailer.rb +10 -0
  216. data/patterns/team-management/files/app/models/concerns/current_team.rb +13 -0
  217. data/patterns/team-management/files/app/models/concerns/user_teams.rb +37 -0
  218. data/patterns/team-management/files/app/models/invitation.rb +41 -0
  219. data/patterns/team-management/files/app/models/membership.rb +45 -0
  220. data/patterns/team-management/files/app/models/team.rb +25 -0
  221. data/patterns/team-management/files/app/views/invitations/acceptances/show.html.erb +1 -0
  222. data/patterns/team-management/files/app/views/team_invitation_mailer/invite.html.erb +10 -0
  223. data/patterns/team-management/files/app/views/team_invitation_mailer/invite.text.erb +7 -0
  224. data/patterns/team-management/files/app/views/teams/index.html.erb +15 -0
  225. data/patterns/team-management/files/app/views/teams/invitations/new.html.erb +22 -0
  226. data/patterns/team-management/files/app/views/teams/memberships/edit.html.erb +22 -0
  227. data/patterns/team-management/files/app/views/teams/memberships/index.html.erb +20 -0
  228. data/patterns/team-management/files/config/routes/team_management.rb +11 -0
  229. data/patterns/team-management/files/db/migrate/20260717000000_create_team_management.rb +31 -0
  230. data/patterns/team-management/files/test/models/invitation_test.rb +28 -0
  231. data/patterns/team-management/files/test/models/membership_test.rb +29 -0
  232. data/patterns/team-management/files/test/models/team_test.rb +31 -0
  233. data/patterns/team-management/files/test/support/team_management_test_helpers.rb +22 -0
  234. data/patterns/team-management/item.yml +4 -0
  235. data/patterns/team-management/pattern.md +47 -0
  236. data/patterns/webhook-deliveries/files/app/assets/stylesheets/ui/webhooks.css +179 -0
  237. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/base.rb +38 -0
  238. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/delivery.rb +160 -0
  239. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/endpoint.rb +149 -0
  240. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/form.rb +75 -0
  241. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/index.rb +142 -0
  242. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/page.rb +33 -0
  243. data/patterns/webhook-deliveries/files/app/components/ui/webhooks/secret.rb +38 -0
  244. data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries/replays_controller.rb +13 -0
  245. data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries_controller.rb +7 -0
  246. data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints/secrets_controller.rb +41 -0
  247. data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints_controller.rb +67 -0
  248. data/patterns/webhook-deliveries/files/app/controllers/webhooks/base_controller.rb +15 -0
  249. data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_job.rb +9 -0
  250. data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_repair_job.rb +11 -0
  251. data/patterns/webhook-deliveries/files/app/models/concerns/team/webhookable.rb +11 -0
  252. data/patterns/webhook-deliveries/files/app/models/webhook/attempt.rb +30 -0
  253. data/patterns/webhook-deliveries/files/app/models/webhook/delivery.rb +268 -0
  254. data/patterns/webhook-deliveries/files/app/models/webhook/endpoint.rb +58 -0
  255. data/patterns/webhook-deliveries/files/app/models/webhook/event.rb +98 -0
  256. data/patterns/webhook-deliveries/files/app/models/webhook/secret_reveal.rb +53 -0
  257. data/patterns/webhook-deliveries/files/app/models/webhook/signature.rb +22 -0
  258. data/patterns/webhook-deliveries/files/app/models/webhook/transport.rb +176 -0
  259. data/patterns/webhook-deliveries/files/app/views/webhook_deliveries/show.html.erb +5 -0
  260. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/edit.html.erb +1 -0
  261. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/index.html.erb +6 -0
  262. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/new.html.erb +1 -0
  263. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/secrets/new.html.erb +1 -0
  264. data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/show.html.erb +7 -0
  265. data/patterns/webhook-deliveries/files/config/recurring/webhooks.yml +4 -0
  266. data/patterns/webhook-deliveries/files/config/routes/webhook_deliveries.rb +10 -0
  267. data/patterns/webhook-deliveries/files/db/migrate/20260803000000_add_webhook_deliveries.rb +126 -0
  268. data/patterns/webhook-deliveries/files/test/controllers/webhook_endpoints_flow_test.rb +48 -0
  269. data/patterns/webhook-deliveries/files/test/models/webhook/delivery_test.rb +70 -0
  270. data/patterns/webhook-deliveries/files/test/system/webhook_deliveries_test.rb +29 -0
  271. data/patterns/webhook-deliveries/item.yml +4 -0
  272. data/patterns/webhook-deliveries/pattern.md +120 -0
  273. data/plugins/nitro-kit/.codex-plugin/plugin.json +4 -4
  274. data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +7 -9
  275. data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +1 -1
  276. data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +10 -9
  277. data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +1 -1
  278. data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +27 -16
  279. data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +1 -1
  280. data/src/stylesheets/nitro_kit/components/accordion.css +40 -40
  281. data/src/stylesheets/nitro_kit/components/alert.css +7 -6
  282. data/src/stylesheets/nitro_kit/components/app_navigation.css +50 -41
  283. data/src/stylesheets/nitro_kit/components/app_shell.css +371 -280
  284. data/src/stylesheets/nitro_kit/components/appearance_picker.css +38 -38
  285. data/src/stylesheets/nitro_kit/components/avatar.css +3 -3
  286. data/src/stylesheets/nitro_kit/components/avatar_stack.css +18 -18
  287. data/src/stylesheets/nitro_kit/components/badge.css +5 -2
  288. data/src/stylesheets/nitro_kit/components/button.css +57 -49
  289. data/src/stylesheets/nitro_kit/components/button_group.css +14 -14
  290. data/src/stylesheets/nitro_kit/components/checkbox.css +24 -24
  291. data/src/stylesheets/nitro_kit/components/checkbox_group.css +13 -13
  292. data/src/stylesheets/nitro_kit/components/combobox.css +152 -25
  293. data/src/stylesheets/nitro_kit/components/command_palette.css +59 -59
  294. data/src/stylesheets/nitro_kit/components/control_group.css +71 -54
  295. data/src/stylesheets/nitro_kit/components/details_table.css +9 -9
  296. data/src/stylesheets/nitro_kit/components/dialog.css +8 -12
  297. data/src/stylesheets/nitro_kit/components/dropdown.css +22 -26
  298. data/src/stylesheets/nitro_kit/components/dropzone.css +97 -100
  299. data/src/stylesheets/nitro_kit/components/empty_state.css +1 -0
  300. data/src/stylesheets/nitro_kit/components/field.css +26 -30
  301. data/src/stylesheets/nitro_kit/components/fieldset.css +2 -2
  302. data/src/stylesheets/nitro_kit/components/input.css +6 -14
  303. data/src/stylesheets/nitro_kit/components/layout.css +165 -165
  304. data/src/stylesheets/nitro_kit/components/page_header.css +3 -3
  305. data/src/stylesheets/nitro_kit/components/pagination.css +66 -49
  306. data/src/stylesheets/nitro_kit/components/pagination_bar.css +6 -6
  307. data/src/stylesheets/nitro_kit/components/palette.css +24 -22
  308. data/src/stylesheets/nitro_kit/components/progressive_image.css +38 -41
  309. data/src/stylesheets/nitro_kit/components/radio_button.css +19 -19
  310. data/src/stylesheets/nitro_kit/components/radio_button_group.css +43 -43
  311. data/src/stylesheets/nitro_kit/components/rich_text_area.css +4 -4
  312. data/src/stylesheets/nitro_kit/components/select.css +2 -2
  313. data/src/stylesheets/nitro_kit/components/settings_layout.css +17 -18
  314. data/src/stylesheets/nitro_kit/components/settings_section.css +12 -12
  315. data/src/stylesheets/nitro_kit/components/sheet.css +10 -10
  316. data/src/stylesheets/nitro_kit/components/stat_grid.css +9 -9
  317. data/src/stylesheets/nitro_kit/components/switch.css +23 -23
  318. data/src/stylesheets/nitro_kit/components/table.css +27 -27
  319. data/src/stylesheets/nitro_kit/components/tabs.css +32 -34
  320. data/src/stylesheets/nitro_kit/components/toolbar.css +6 -6
  321. data/src/stylesheets/nitro_kit/components/tooltip.css +26 -28
  322. data/src/stylesheets/nitro_kit/layers.css +2 -1
  323. data/src/stylesheets/nitro_kit/reset.css +9 -9
  324. data/src/stylesheets/nitro_kit/tailwind.css +6 -2
  325. data/src/stylesheets/nitro_kit/tokens.css +18 -9
  326. metadata +238 -2
@@ -0,0 +1,295 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tempfile"
4
+
5
+ class Upload < ApplicationRecord
6
+ ACCEPTED_CONTENT_TYPES = %w[image/jpeg image/png].freeze
7
+ MAX_BYTES = 10.megabytes
8
+ MAX_PIXELS = 40_000_000
9
+ AUTOMATIC_ATTEMPTS = 5
10
+ MAX_ATTEMPTS = 8
11
+ VARIANT_PIXELS = [ 48, 320, 640 ].freeze
12
+ FAILURE_CODES = %w[too_large unsupported_type invalid_dimensions too_many_pixels processing_failed].freeze
13
+
14
+ RejectedBlob = Class.new(StandardError)
15
+ BlobAlreadyAttached = Class.new(StandardError)
16
+ BlobNotOwned = Class.new(StandardError)
17
+ FileTooLarge = Class.new(StandardError)
18
+ MissingFile = Class.new(StandardError)
19
+ NotRetryable = Class.new(StandardError)
20
+
21
+ belongs_to :team, inverse_of: :uploads
22
+ belongs_to :user, optional: true
23
+ has_one_attached :file
24
+
25
+ enum :status, {
26
+ pending: "pending",
27
+ processing: "processing",
28
+ ready: "ready",
29
+ failed: "failed"
30
+ }, default: :pending, validate: true
31
+
32
+ validates :failure_code, inclusion: { in: FAILURE_CODES }, allow_nil: true
33
+ validate :file_is_attached
34
+
35
+ scope :recent_first, -> { order(created_at: :desc) }
36
+ broadcasts_refreshes_to ->(upload) { [ upload.team, :uploads ] }
37
+
38
+ class << self
39
+ def receive!(team:, user:, upload:)
40
+ raise MissingFile, "Choose an image to upload" if upload.blank?
41
+
42
+ blob = blob_for(upload, team:, user:)
43
+ record = new(team:, user:)
44
+
45
+ transaction do
46
+ blob.with_lock do
47
+ if blob.attachments.exists? || blob.metadata["upload_consumed_at"].present?
48
+ raise BlobAlreadyAttached, "This upload has already been used"
49
+ end
50
+ unless owned_blob?(blob, team:, user:)
51
+ raise BlobNotOwned, "This upload does not belong to the current workspace"
52
+ end
53
+
54
+ blob.update!(metadata: blob.metadata.merge(upload_consumed_at: Time.current.iso8601))
55
+ record.save!(validate: false)
56
+ record.file.attach(blob)
57
+ record.save!
58
+ end
59
+ end
60
+
61
+ UploadProcessingJob.perform_later(record.id)
62
+ record
63
+ rescue
64
+ if blob&.attachments&.none? && owned_blob?(blob, team:, user:)
65
+ blob.purge_later
66
+ end
67
+ raise
68
+ end
69
+
70
+ private
71
+ def blob_for(upload, team:, user:)
72
+ if upload.is_a?(String)
73
+ return ActiveStorage::Blob.find_signed!(upload, purpose: :file_upload_intake)
74
+ end
75
+ unless upload.respond_to?(:tempfile) && upload.respond_to?(:original_filename)
76
+ raise MissingFile, "Choose an image to upload"
77
+ end
78
+
79
+ upload.tempfile.rewind
80
+ raise MissingFile, "File is empty" unless upload.tempfile.size.positive?
81
+ if upload.tempfile.size > MAX_BYTES
82
+ raise FileTooLarge, "File is larger than 10 MB"
83
+ end
84
+ ActiveStorage::Blob.create_and_upload!(
85
+ io: upload.tempfile,
86
+ filename: upload.original_filename,
87
+ content_type: upload.content_type,
88
+ metadata: upload_metadata(team:, user:),
89
+ identify: false
90
+ ).tap { |blob| blob.update!(analyzed: true) }
91
+ end
92
+
93
+ def owned_blob?(blob, team:, user:)
94
+ metadata = blob.metadata
95
+ metadata["upload_pattern"] == "file_uploads" &&
96
+ metadata["upload_team_id"] == team.id.to_s &&
97
+ metadata["upload_user_id"] == user.id.to_s
98
+ end
99
+
100
+ def upload_metadata(team:, user:)
101
+ {
102
+ upload_pattern: "file_uploads",
103
+ upload_team_id: team.id.to_s,
104
+ upload_user_id: user.id.to_s
105
+ }
106
+ end
107
+ end
108
+
109
+ def process!
110
+ token = SecureRandom.uuid
111
+ claimed = with_lock do
112
+ if attempts_count >= MAX_ATTEMPTS
113
+ if pending? || processable_failure?
114
+ update!(
115
+ status: :failed,
116
+ failure_code: "processing_failed",
117
+ processing_token: nil,
118
+ processing_started_at: nil,
119
+ processed_at: nil
120
+ )
121
+ end
122
+ next false
123
+ end
124
+ next false unless pending? || processable_failure?
125
+
126
+ update!(
127
+ status: :processing,
128
+ failure_code: nil,
129
+ processing_token: token,
130
+ processing_started_at: Time.current,
131
+ processed_at: nil,
132
+ attempts_count: attempts_count + 1
133
+ )
134
+ true
135
+ end
136
+ return unless claimed
137
+
138
+ inspect_blob!
139
+ file.blob.analyze
140
+ inspect_dimensions!
141
+ process_variant!
142
+ with_lock do
143
+ if processing? && processing_token == token
144
+ update!(
145
+ status: :ready,
146
+ failure_code: nil,
147
+ processing_token: nil,
148
+ processing_started_at: nil,
149
+ processed_at: Time.current
150
+ )
151
+ end
152
+ end
153
+ rescue RejectedBlob => error
154
+ fail_with!(error.message, token:)
155
+ rescue
156
+ fail_with!("processing_failed", token:) if token
157
+ raise
158
+ end
159
+
160
+ def retry!
161
+ with_lock do
162
+ unless retryable?
163
+ raise NotRetryable, "Only transient processing failures can be retried"
164
+ end
165
+
166
+ update!(
167
+ status: :pending,
168
+ failure_code: nil,
169
+ processing_token: nil,
170
+ processing_started_at: nil,
171
+ processed_at: nil
172
+ )
173
+ end
174
+ UploadProcessingJob.perform_later(id)
175
+ end
176
+
177
+ def repair!(expected_status:, stale_before:)
178
+ outcome = with_lock do
179
+ timestamp = pending? ? updated_at : processing_started_at
180
+ next false unless status == expected_status && timestamp && timestamp < stale_before
181
+
182
+ if attempts_count >= MAX_ATTEMPTS
183
+ update!(
184
+ status: :failed,
185
+ failure_code: "processing_failed",
186
+ processing_token: nil,
187
+ processing_started_at: nil,
188
+ processed_at: nil
189
+ )
190
+ next :exhausted
191
+ end
192
+
193
+ update!(
194
+ status: :pending,
195
+ failure_code: nil,
196
+ processing_token: nil,
197
+ processing_started_at: nil,
198
+ processed_at: nil
199
+ )
200
+ :repaired
201
+ end
202
+ return unless outcome == :repaired
203
+
204
+ UploadProcessingJob.perform_later(id)
205
+ end
206
+
207
+ def retryable?
208
+ failed? &&
209
+ failure_code == "processing_failed" &&
210
+ attempts_count >= AUTOMATIC_ATTEMPTS &&
211
+ attempts_count < MAX_ATTEMPTS
212
+ end
213
+
214
+ def filename = file.filename.to_s
215
+ def byte_size = file.byte_size
216
+
217
+ def failure_message
218
+ {
219
+ "too_large" => "The stored image is larger than 10 MB.",
220
+ "unsupported_type" => "The stored file is not a JPEG or PNG image.",
221
+ "invalid_dimensions" => "The image has invalid dimensions.",
222
+ "too_many_pixels" => "The decoded image is too large to process safely.",
223
+ "processing_failed" => processing_failure_message
224
+ }.fetch(failure_code, "The image could not be processed.")
225
+ end
226
+
227
+ private
228
+ def inspect_blob!
229
+ actual_size = 0
230
+ detected_type = Tempfile.create([ "upload-inspection", ".bin" ]) do |io|
231
+ io.binmode
232
+ file.blob.download do |chunk|
233
+ actual_size += chunk.bytesize
234
+ raise RejectedBlob, "too_large" if actual_size > MAX_BYTES
235
+
236
+ io.write(chunk)
237
+ end
238
+ io.rewind
239
+ Marcel::MimeType.for(io)
240
+ end
241
+
242
+ raise RejectedBlob, "unsupported_type" unless detected_type.in?(ACCEPTED_CONTENT_TYPES)
243
+
244
+ file.blob.update!(content_type: detected_type, byte_size: actual_size, identified: true)
245
+ end
246
+
247
+ def processable_failure?
248
+ failed? && failure_code == "processing_failed" && attempts_count < MAX_ATTEMPTS
249
+ end
250
+
251
+ def processing_failure_message
252
+ if attempts_count < AUTOMATIC_ATTEMPTS
253
+ "Image processing failed and will retry automatically."
254
+ elsif retryable?
255
+ "The image could not be processed. Retry, or remove it and upload another file."
256
+ else
257
+ "The image could not be processed after several attempts. Remove it and upload another file."
258
+ end
259
+ end
260
+
261
+ def process_variant!
262
+ VARIANT_PIXELS.each do |pixels|
263
+ file.variant(resize_to_limit: [ pixels, pixels ]).processed
264
+ end
265
+ end
266
+
267
+ def inspect_dimensions!
268
+ width = file.blob.metadata["width"]
269
+ height = file.blob.metadata["height"]
270
+ unless width.is_a?(Numeric) && width.positive? && height.is_a?(Numeric) && height.positive?
271
+ raise RejectedBlob, "invalid_dimensions"
272
+ end
273
+ raise RejectedBlob, "too_many_pixels" if width * height > MAX_PIXELS
274
+ end
275
+
276
+ def fail_with!(code, token: processing_token)
277
+ record = self.class.find_by(id:)
278
+ record&.with_lock do
279
+ if record.processing_token == token
280
+ record.update!(
281
+ status: :failed,
282
+ failure_code: code,
283
+ processing_token: nil,
284
+ processing_started_at: nil,
285
+ processed_at: nil
286
+ )
287
+ end
288
+ end
289
+ reload if self.class.exists?(id)
290
+ end
291
+
292
+ def file_is_attached
293
+ errors.add(:file, "must be attached") unless file.attached?
294
+ end
295
+ end
@@ -0,0 +1,7 @@
1
+ production:
2
+ upload_blob_cleanup:
3
+ class: UploadBlobCleanupJob
4
+ schedule: every hour at minute 17
5
+ upload_repair:
6
+ class: UploadRepairJob
7
+ schedule: every 10 minutes
@@ -0,0 +1,5 @@
1
+ post "/rails/active_storage/direct_uploads", to: "uploads/direct_uploads#create"
2
+
3
+ resources :uploads, only: %i[index create destroy] do
4
+ resource :retry, only: :create, module: :uploads
5
+ end
@@ -0,0 +1,30 @@
1
+ class AddFileUploads < ActiveRecord::Migration[8.1]
2
+ def change
3
+ team_key_type = primary_key_type_for(:teams)
4
+ user_key_type = primary_key_type_for(:users)
5
+
6
+ create_table :uploads do |t|
7
+ t.references :team, type: team_key_type, null: false, foreign_key: { on_delete: :cascade }
8
+ t.references :user, type: user_key_type, null: true, foreign_key: { on_delete: :nullify }
9
+ t.string :status, null: false, default: "pending"
10
+ t.string :failure_code
11
+ t.string :processing_token
12
+ t.datetime :processing_started_at
13
+ t.datetime :processed_at
14
+ t.integer :attempts_count, null: false, default: 0
15
+ t.integer :lock_version, null: false, default: 0
16
+ t.timestamps
17
+ end
18
+
19
+ add_index :uploads, [ :team_id, :created_at ]
20
+ add_check_constraint :uploads,
21
+ "status IN ('pending', 'processing', 'ready', 'failed')",
22
+ name: "uploads_status"
23
+ end
24
+
25
+ private
26
+ def primary_key_type_for(table)
27
+ column = connection.columns(table).find { |candidate| candidate.name == "id" }
28
+ column.sql_type.match?(/bigint/i) ? :bigint : column.type
29
+ end
30
+ end
@@ -0,0 +1,77 @@
1
+ require "test_helper"
2
+
3
+ class UploadsFlowTest < ActionDispatch::IntegrationTest
4
+ include ActiveJob::TestHelper
5
+
6
+ setup do
7
+ sign_in users(:ada)
8
+ switch_team teams(:analytical_engines)
9
+ end
10
+
11
+ test "creates a team-owned upload from a direct-upload blob" do
12
+ blob = ActiveStorage::Blob.create_before_direct_upload!(
13
+ filename: "workspace.png",
14
+ byte_size: 68,
15
+ checksum: Digest::MD5.base64digest("image bytes"),
16
+ content_type: "image/png",
17
+ metadata: {
18
+ upload_pattern: "file_uploads",
19
+ upload_team_id: teams(:analytical_engines).id.to_s,
20
+ upload_user_id: users(:ada).id.to_s,
21
+ analyzed: true
22
+ }
23
+ )
24
+
25
+ assert_difference("teams(:analytical_engines).uploads.count") do
26
+ post uploads_path, params: {
27
+ upload: { file: blob.signed_id(purpose: :file_upload_intake) }
28
+ }
29
+ end
30
+
31
+ assert_redirected_to uploads_path
32
+ end
33
+
34
+ test "direct upload metadata is authorized bounded and stamped by the server" do
35
+ assert_difference("ActiveStorage::Blob.count") do
36
+ post "/rails/active_storage/direct_uploads", params: {
37
+ blob: {
38
+ filename: "workspace.png",
39
+ byte_size: 68,
40
+ checksum: Digest::MD5.base64digest("image bytes"),
41
+ content_type: "image/png",
42
+ metadata: { upload_team_id: teams(:secondary).id }
43
+ }
44
+ }
45
+ end
46
+
47
+ assert_response :success
48
+ assert_equal teams(:analytical_engines).id.to_s, ActiveStorage::Blob.last.metadata["upload_team_id"]
49
+ assert_equal users(:ada).id.to_s, ActiveStorage::Blob.last.metadata["upload_user_id"]
50
+ assert_predicate ActiveStorage::Blob.last, :analyzed?
51
+
52
+ assert_no_difference("ActiveStorage::Blob.count") do
53
+ post "/rails/active_storage/direct_uploads", params: {
54
+ blob: {
55
+ filename: "workspace.zip",
56
+ byte_size: 68,
57
+ checksum: Digest::MD5.base64digest("archive bytes"),
58
+ content_type: "application/zip"
59
+ }
60
+ }
61
+ end
62
+ assert_response :unprocessable_entity
63
+ end
64
+
65
+ test "never removes another team's upload" do
66
+ assert_raises(ActiveRecord::RecordNotFound) do
67
+ delete upload_path(uploads(:other_team))
68
+ end
69
+ end
70
+
71
+ test "returns missing files to a recoverable form" do
72
+ post uploads_path, params: { upload: { file: "" } }
73
+
74
+ assert_redirected_to uploads_path
75
+ assert_equal "Choose an image to upload", flash[:alert]
76
+ end
77
+ end
@@ -0,0 +1 @@
1
+ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9Zl9sAAAAASUVORK5CYII=
@@ -0,0 +1,17 @@
1
+ failed_processing:
2
+ team: analytical_engines
3
+ user: ada
4
+ status: failed
5
+ failure_code: processing_failed
6
+ attempts_count: 5
7
+
8
+ rejected_type:
9
+ team: analytical_engines
10
+ user: ada
11
+ status: failed
12
+ failure_code: unsupported_type
13
+
14
+ other_team:
15
+ team: secondary
16
+ user: ada
17
+ status: pending
@@ -0,0 +1,55 @@
1
+ require "test_helper"
2
+ require "base64"
3
+ require "stringio"
4
+
5
+ class UploadTest < ActiveSupport::TestCase
6
+ include ActiveJob::TestHelper
7
+
8
+ test "attaches an unused signed blob and queues processing" do
9
+ blob = create_file_blob("workspace.png", "image/png")
10
+
11
+ assert_enqueued_with(job: UploadProcessingJob) do
12
+ upload = Upload.receive!(
13
+ team: teams(:analytical_engines),
14
+ user: users(:ada),
15
+ upload: blob.signed_id(purpose: :file_upload_intake)
16
+ )
17
+
18
+ assert_predicate upload, :pending?
19
+ assert_predicate upload.file, :attached?
20
+ end
21
+ end
22
+
23
+ test "does not let a signed blob be attached twice" do
24
+ blob = create_file_blob("workspace.png", "image/png")
25
+ signed_id = blob.signed_id(purpose: :file_upload_intake)
26
+ Upload.receive!(team: teams(:analytical_engines), user: users(:ada), upload: signed_id)
27
+
28
+ assert_raises(Upload::BlobAlreadyAttached) do
29
+ Upload.receive!(team: teams(:analytical_engines), user: users(:ada), upload: signed_id)
30
+ end
31
+ end
32
+
33
+ test "only transient processing failures can retry" do
34
+ upload = uploads(:failed_processing)
35
+ assert_enqueued_with(job: UploadProcessingJob) { upload.retry! }
36
+ assert_predicate upload, :pending?
37
+
38
+ assert_raises(Upload::NotRetryable) { uploads(:rejected_type).retry! }
39
+ end
40
+
41
+ private
42
+ def create_file_blob(filename, content_type)
43
+ ActiveStorage::Blob.create_and_upload!(
44
+ io: StringIO.new(Base64.decode64(file_fixture("workspace.png.base64").read)),
45
+ filename:,
46
+ content_type:,
47
+ metadata: {
48
+ upload_pattern: "file_uploads",
49
+ upload_team_id: teams(:analytical_engines).id.to_s,
50
+ upload_user_id: users(:ada).id.to_s,
51
+ analyzed: true
52
+ }
53
+ )
54
+ end
55
+ end
@@ -0,0 +1,30 @@
1
+ require "application_system_test_case"
2
+ require "base64"
3
+ require "tmpdir"
4
+
5
+ class FileUploadsTest < ApplicationSystemTestCase
6
+ test "selects and removes an image before native multipart submission" do
7
+ sign_in users(:ada)
8
+ visit uploads_path
9
+
10
+ Dir.mktmpdir do |directory|
11
+ image = Pathname(directory).join("workspace.png")
12
+ image.binwrite(Base64.decode64(file_fixture("workspace.png.base64").read))
13
+
14
+ attach_file "Choose an image", image, make_visible: true
15
+ assert_text "workspace.png"
16
+ assert_text "Ready"
17
+
18
+ click_button "Remove workspace.png"
19
+ assert_text "No files selected"
20
+ end
21
+ end
22
+
23
+ test "retries a transient processing failure" do
24
+ sign_in users(:ada)
25
+ visit uploads_path
26
+
27
+ within("tr", text: "damaged.jpg") { click_button "Retry" }
28
+ assert_text "Upload queued for another attempt."
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ version: 1.2.0
2
+ title: Active Storage file uploads
3
+ summary: Accept direct or multipart image uploads, process them asynchronously, and expose authorized lifecycle, retry, removal, and cleanup workflows.
4
+ tags: [uploads, active-storage, direct-upload, images, processing, rails]
@@ -0,0 +1,71 @@
1
+ # Active Storage file uploads
2
+
3
+ ## When to use
4
+
5
+ Use this pattern when a team-scoped Rails application accepts images that must not become available until server-side inspection and processing finish. It combines Nitro Kit's native `Dropzone` and `ProgressiveImage` contracts with an application-owned `Upload` lifecycle.
6
+
7
+ Do not use this unchanged for arbitrary documents, executable files, regulated evidence, or media that requires virus scanning, moderation, or private authenticated delivery. Extend the processing gate before broadening the allowlist.
8
+
9
+ ## Composition checklist
10
+
11
+ Run the page composition checklist in the installed gem's `docs/patterns/composition.md` (`bundle show nitro_kit`) before calling any adapted route finished: the shell owns the gutter and the `h1`, and upload rows use default-treatment Dialog triggers for Remove rather than destructive buttons. Keep `variant: :destructive` on the confirming "Remove file" submit inside the Dialog, never on repeated row triggers. Inspect populated, empty, failed, rejected, and 390px states.
12
+
13
+ ## Install and adapt
14
+
15
+ 1. Install Active Storage, add the `image_processing` gem, and configure a durable service plus a Rails-supported image processor.
16
+ 2. Copy the migration and merge it with the host application's `Team` and `User` primary-key types.
17
+ 3. Include `Team::Uploadable` in the host `Team` model.
18
+ 4. Draw `config/routes/uploads.rb`, copy the controllers, model, jobs, and `UI::Uploads` components, and add Uploads to the application shell.
19
+ 5. Add `config/recurring/uploads.yml` to Solid Queue's recurring schedule or invoke `UploadBlobCleanupJob` from the host scheduler.
20
+ 6. Ensure Nitro Kit's Stimulus controllers and `@rails/activestorage` import are registered. The ordinary multipart branch works without JavaScript.
21
+ 7. Configure Turbo refreshes to morph with scroll preservation in the application layout. Team-scoped upload broadcasts then update lifecycle state while the team-keyed permanent upload form preserves an active selection without carrying it across workspace switches.
22
+
23
+ The example accepts one JPEG or PNG image up to 10 MB. It deliberately excludes animated and multi-page formats. Keep `Upload::ACCEPTED_CONTENT_TYPES`, `Upload::MAX_BYTES`, Dropzone hints, processing rules, and tests aligned when changing policy.
24
+
25
+ ## Lifecycle and authority
26
+
27
+ `Uploads::DirectUploadsController` owns the usual Active Storage metadata path before the engine route. It requires the current team and user, rate-limits metadata creation, rejects declared type and byte violations before returning a storage URL, ignores caller metadata, stamps trusted team/user provenance, and returns a two-hour signed ID with the intake-only `file_upload_intake` purpose. Standard Active Storage blob routes reject that purpose. `Upload.receive!` accepts that signed ID or an ordinary multipart upload. The server resolves the blob, locks it, verifies provenance, atomically stamps durable consumption, rejects reuse even after attachment removal, creates the team-owned record, attaches the blob, and queues processing. Client-side `accept` and byte limits are usability hints only.
28
+
29
+ The multipart branch checks the request tempfile before durable storage. Configure the reverse proxy or application server with a request-body ceiling as well, because Rails must receive a multipart body before controller code can inspect it.
30
+
31
+ The persisted states are:
32
+
33
+ - `pending`: attached and queued, but unavailable.
34
+ - `processing`: claimed by a processing job.
35
+ - `ready`: stored bytes were inspected, analyzed, and a representative variant processed successfully.
36
+ - `failed`: rejected by policy or unavailable because processing failed.
37
+
38
+ `Upload#process!` claims work with a fresh processing token, streams the stored object into an inspection file with a hard 10 MB cutoff, detects media type with Marcel rather than trusting direct-upload metadata, runs Active Storage analysis, checks positive decoded dimensions and a 40-megapixel ceiling, and pre-processes the exact 48, 320, and 640 pixel variants used by this screen before marking the upload ready. Recovery invalidates the token, so a stale worker cannot overwrite a newer attempt. Application features must gate use on `upload.ready?`, not attachment presence, a direct-upload callback, a submitted MIME type, or the browser preview.
39
+
40
+ Run image processing on a queue with conservative concurrency, memory, disk, and execution-time limits. The byte and pixel checks are application policy, not a substitute for operating-system and processor resource boundaries around hostile decoders.
41
+
42
+ Only transient `processing_failed` records expose Retry after the five automatic attempts are exhausted, and the total automatic plus manual processing budget is eight attempts. Before that point, the UI says that automatic retry is scheduled. The retry endpoint is separately rate-limited. Deterministic `too_large`, `unsupported_type`, dimension, and pixel-limit failures must be removed and replaced. The job is idempotent: record locking prevents duplicate workers from processing the same ready or in-flight upload.
43
+
44
+ ## Authorization and delivery
45
+
46
+ Every mutation scopes records through `Current.team.uploads`; a caller-supplied ID never selects across teams. `Uploads::BaseController` also requires `Current.membership` to match both the current user and team, so a merely non-nil or caller-selected team context is insufficient. `Current.user` is recorded as the actor, while later account deletion nullifies that attribution rather than blocking deletion. Adapt `upload_member?` to any stricter host permission policy, then add policy tests for owners, members, former members, and administrators.
47
+
48
+ Rails representation URLs are signed capability URLs, not team authorization checks. This pattern shows processed images through `ProgressiveImage` and never links to the original blob. For sensitive media, use authenticated proxy controllers, short-lived URLs, a private service, and response headers appropriate to the content. Add malware scanning, moderation, or content-disarm steps before `ready` when the threat model requires them.
49
+
50
+ ## Removal and cleanup
51
+
52
+ Destroying an `Upload` purges its attachment asynchronously through `has_one_attached`. Direct uploads can still leave unattached blobs when a tab closes, an upload fails, or validation never reaches record creation. `UploadBlobCleanupJob` purges blobs that remain unattached for 24 hours.
53
+
54
+ That cleanup query is application-wide. Before installing it, confirm that no other workflow intentionally keeps unattached blobs longer than the cutoff. If several workflows share Active Storage, centralize cleanup policy instead of adding competing jobs.
55
+
56
+ ## Failure behavior
57
+
58
+ Invalid or replayed signed IDs, missing files, and already-attached blobs return a recoverable form alert. Storage, analysis, and image-processing exceptions retry with Active Job backoff and leave a visible `processing_failed` state. Missing records are discarded so removal remains safe while jobs are queued.
59
+
60
+ Keep storage failures observable. Alert on exhausted `UploadProcessingJob` retries, a rising failed count, unusually old pending/processing records, cleanup failures, and storage capacity. `UploadRepairJob` requeues pending records older than five minutes and processing records older than thirty minutes; tune those windows to the host's largest supported image and queue latency.
61
+
62
+ ## Tests to keep
63
+
64
+ - Direct signed IDs and ordinary multipart uploads both create exactly one authorized record.
65
+ - Blob reuse, invalid signatures, missing context, cross-team IDs, oversized stored bytes, and spoofed content types fail closed.
66
+ - Processing transitions through pending, processing, ready, deterministic rejection, transient failure, and retry.
67
+ - Duplicate jobs do not process ready or already-processing uploads twice.
68
+ - Removal purges asynchronously and queued jobs tolerate a missing record.
69
+ - Unattached cleanup honors its age boundary.
70
+ - Dropzone retains a labelled native input and multipart fallback; direct-upload progress, removal, errors, submit locking, and Turbo teardown work in a real browser.
71
+ - Ready `ProgressiveImage` output has one accessible image; empty, narrow, dark, failed, and long-filename views remain usable.
@@ -0,0 +1,57 @@
1
+ # Upgrade Nitro Kit 1.x by product flow
2
+
3
+ Start with an inventory, not search-and-replace.
4
+
5
+ ## 1. Record the old contract
6
+
7
+ List helper calls, direct component construction, copied Nitro component and
8
+ helper directories, application-owned `controllers/nk`, custom classes passed
9
+ to Nitro roots, and every responsive or interactive behavior. Group them by
10
+ flow: authentication, shell/navigation, collections, forms, settings,
11
+ destructive actions, notifications, and contextual controls.
12
+
13
+ For each flow record native semantics, routes and methods, submitted names and
14
+ values, Turbo boundaries, accessible relationships, focus behavior, empty and
15
+ error states, narrow-screen behavior, and density. Capture wide and narrow
16
+ screenshots.
17
+
18
+ ## 2. Search by intent
19
+
20
+ Search the catalog for the product workflow (`mobile transcript navigation`,
21
+ `team settings`, `empty filtered collection`) rather than the old component
22
+ name. Retrieve the closest complete composition. Read the installed gem's
23
+ component contract before adapting it.
24
+
25
+ Select high-level Nitro Kit 2 components before atoms:
26
+
27
+ - authentication → `AuthShell`
28
+ - application navigation → `AppShell`, `AppNavigation`
29
+ - contextual mobile drawer → `Sheet`
30
+ - settings → `SettingsLayout`, `SettingsSection`
31
+ - collections → `DataSection`, `Table`, `EmptyState`, `PaginationBar`
32
+ - destructive mutations → `DangerZone`, `Dialog`, `ButtonTo`
33
+ - joined copy/filter controls → `ControlGroup`
34
+
35
+ ## 3. Convert without downgrading
36
+
37
+ Use Rails `form_with` and `NitroKit::FormBuilder`. Use `Button` links for GET
38
+ navigation and `ButtonTo` for mutation forms. Use Tooltip's Button path for
39
+ ordinary buttons/links and `as: :custom` to forward its yielded HTML, ARIA,
40
+ and data boundaries to an existing focusable ButtonTo or compound trigger.
41
+
42
+ If Nitro Kit 2 lacks a genuine semantic and behavioral equivalent, preserve
43
+ the control as application-owned Rails or HTML and write down the coverage
44
+ gap. Never retain copied 1.x source or downgrade a specialized control merely
45
+ to make the migration appear complete.
46
+
47
+ ## 4. Verify behavior, not compilation
48
+
49
+ Run tests, then compare every representative flow at wide and narrow widths,
50
+ in light and dark appearance, with keyboard navigation. Exercise dialogs,
51
+ sheets, Turbo forms, invalid fields, empty/error states, tooltip focus, and
52
+ dense metadata. Request tests cannot detect a removed tooltip, a drawer
53
+ replaced by a disclosure, or a lost interactive surface treatment.
54
+
55
+ Delete copied components/helpers/controllers only after the equivalent flow
56
+ passes. Finish with `bin/rails nitro_kit:doctor` and retain the coverage-gap
57
+ ledger for future Nitro Kit work.
@@ -0,0 +1,4 @@
1
+ version: 1.0.0
2
+ title: Upgrade a Nitro Kit 1.x application
3
+ summary: Migrate behavior-first by inventorying copied Nitro Kit 1 surfaces, preserving unsupported application behavior, and verifying real wide and narrow workflows.
4
+ tags: [agents, migration, nitro-kit-1, nitro-kit-2, rails, upgrade]