collavre 0.24.1 → 0.30.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 (1320) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -11
  3. data/app/assets/images/collavre/kollavy.png +0 -0
  4. data/app/assets/images/collavre/kollavy.svg +9 -0
  5. data/app/assets/stylesheets/collavre/actiontext.css +24 -165
  6. data/app/assets/stylesheets/collavre/activity_logs.css +23 -12
  7. data/app/assets/stylesheets/collavre/agent_connections.css +196 -0
  8. data/app/assets/stylesheets/collavre/agent_gateways.css +153 -0
  9. data/app/assets/stylesheets/collavre/attachment_card.css +34 -0
  10. data/app/assets/stylesheets/collavre/comments_popup.css +668 -165
  11. data/app/assets/stylesheets/collavre/creatives.css +1165 -155
  12. data/app/assets/stylesheets/collavre/dark_mode.css +0 -20
  13. data/app/assets/stylesheets/collavre/design_tokens.css +79 -0
  14. data/app/assets/stylesheets/collavre/desktop_setup.css +241 -0
  15. data/app/assets/stylesheets/collavre/gnb.css +64 -3
  16. data/app/assets/stylesheets/collavre/image_lightbox.css +12 -0
  17. data/app/assets/stylesheets/collavre/landing.css +130 -106
  18. data/app/assets/stylesheets/collavre/llm_usages.css +67 -0
  19. data/app/assets/stylesheets/collavre/mention_menu.css +50 -0
  20. data/app/assets/stylesheets/collavre/modal_dialog.css +66 -3
  21. data/app/assets/stylesheets/collavre/notice_bar.css +465 -0
  22. data/app/assets/stylesheets/collavre/org_chart.css +0 -4
  23. data/app/assets/stylesheets/collavre/popup.css +29 -18
  24. data/app/assets/stylesheets/collavre/print.css +0 -1
  25. data/app/assets/stylesheets/collavre/search_popup.css +1 -35
  26. data/app/assets/stylesheets/collavre/secret_fields.css +3 -0
  27. data/app/assets/stylesheets/collavre/slide_view.css +221 -4
  28. data/app/assets/stylesheets/collavre/workflow_editor.css +101 -0
  29. data/app/assets/stylesheets/collavre/workspace.css +310 -0
  30. data/app/channels/collavre/agent_channel.rb +61 -43
  31. data/app/channels/collavre/comments_presence_channel.rb +181 -21
  32. data/app/channels/collavre/inbox_badge_channel.rb +7 -1
  33. data/app/components/collavre/command_menu_component.html.erb +5 -0
  34. data/app/components/collavre/command_menu_component.rb +8 -0
  35. data/app/components/collavre/comment_user_menu_component.html.erb +61 -0
  36. data/app/components/collavre/comment_user_menu_component.rb +14 -0
  37. data/app/components/collavre/cron_badge_component.html.erb +80 -0
  38. data/app/components/collavre/cron_badge_component.rb +50 -0
  39. data/app/components/collavre/inbox/badge_component.rb +6 -13
  40. data/app/components/collavre/progress_filter_component.html.erb +2 -2
  41. data/app/components/collavre/progress_filter_component.rb +20 -0
  42. data/app/controllers/collavre/admin/orchestration_controller.rb +59 -32
  43. data/app/controllers/collavre/admin/settings_controller.rb +80 -8
  44. data/app/controllers/collavre/agent_connections_controller.rb +153 -0
  45. data/app/controllers/collavre/agent_gateways_controller.rb +132 -0
  46. data/app/controllers/collavre/agent_models_controller.rb +55 -0
  47. data/app/controllers/collavre/agent_provisioning_controller.rb +88 -0
  48. data/app/controllers/collavre/api/v1/agents_controller.rb +81 -249
  49. data/app/controllers/collavre/api/v1/task_suspensions_controller.rb +60 -0
  50. data/app/controllers/collavre/application_controller.rb +13 -2
  51. data/app/controllers/collavre/attachments_controller.rb +12 -12
  52. data/app/controllers/collavre/comment_read_pointers_controller.rb +69 -40
  53. data/app/controllers/collavre/comments/activity_logs_controller.rb +2 -0
  54. data/app/controllers/collavre/comments/reactions_controller.rb +10 -12
  55. data/app/controllers/collavre/comments/resends_controller.rb +21 -0
  56. data/app/controllers/collavre/comments/versions_controller.rb +24 -21
  57. data/app/controllers/collavre/comments_controller.rb +104 -139
  58. data/app/controllers/collavre/concerns/creative_history_trackable.rb +31 -0
  59. data/app/controllers/collavre/concerns/shareable.rb +9 -3
  60. data/app/controllers/collavre/concerns/tree_manageable.rb +4 -0
  61. data/app/controllers/collavre/creative_change_sets_controller.rb +112 -0
  62. data/app/controllers/collavre/creative_imports_controller.rb +9 -1
  63. data/app/controllers/collavre/creative_invitations_controller.rb +2 -11
  64. data/app/controllers/collavre/creative_shares_controller.rb +7 -15
  65. data/app/controllers/collavre/creatives/attachments_controller.rb +16 -4
  66. data/app/controllers/collavre/creatives/file_drops_controller.rb +35 -0
  67. data/app/controllers/collavre/creatives/ppt_previews_controller.rb +66 -0
  68. data/app/controllers/collavre/creatives_controller.rb +186 -276
  69. data/app/controllers/collavre/crons_controller.rb +48 -0
  70. data/app/controllers/collavre/desktop_gateway_registrations_controller.rb +156 -0
  71. data/app/controllers/collavre/desktop_setup_controller.rb +102 -0
  72. data/app/controllers/collavre/desktop_sidecar_health_controller.rb +23 -0
  73. data/app/controllers/collavre/features_controller.rb +57 -0
  74. data/app/controllers/collavre/google_auth_controller.rb +3 -4
  75. data/app/controllers/collavre/inline_agent_logins_controller.rb +79 -0
  76. data/app/controllers/collavre/invites_controller.rb +12 -1
  77. data/app/controllers/collavre/llm_models_controller.rb +8 -0
  78. data/app/controllers/collavre/llm_usages_controller.rb +51 -0
  79. data/app/controllers/collavre/notices_controller.rb +20 -0
  80. data/app/controllers/collavre/onboarding_replays_controller.rb +10 -0
  81. data/app/controllers/collavre/public_assets_controller.rb +48 -4
  82. data/app/controllers/collavre/seo_controller.rb +83 -0
  83. data/app/controllers/collavre/sessions_controller.rb +5 -9
  84. data/app/controllers/collavre/tasks_controller.rb +40 -6
  85. data/app/controllers/collavre/topics_controller.rb +136 -74
  86. data/app/controllers/collavre/user_creative_preferences_controller.rb +182 -31
  87. data/app/controllers/collavre/user_notices_controller.rb +64 -0
  88. data/app/controllers/collavre/user_themes_controller.rb +11 -7
  89. data/app/controllers/collavre/users_controller.rb +1 -0
  90. data/app/controllers/concerns/collavre/active_storage_access.rb +127 -0
  91. data/app/controllers/concerns/collavre/api/claude_channel_prompts.rb +209 -0
  92. data/app/controllers/concerns/collavre/blob_access_control.rb +57 -0
  93. data/app/controllers/concerns/collavre/comments/approval_actions.rb +24 -22
  94. data/app/controllers/concerns/collavre/comments/approval_gate_actions.rb +29 -0
  95. data/app/controllers/concerns/collavre/comments/batch_operations.rb +16 -4
  96. data/app/controllers/concerns/collavre/comments/comment_scoping.rb +4 -2
  97. data/app/controllers/concerns/collavre/comments/conversion.rb +1 -1
  98. data/app/controllers/concerns/collavre/comments/history_topic_guard.rb +22 -0
  99. data/app/controllers/concerns/collavre/creative_destroyable.rb +41 -0
  100. data/app/controllers/concerns/collavre/creative_permission_guard.rb +6 -0
  101. data/app/controllers/concerns/collavre/creative_type_editable.rb +76 -0
  102. data/app/controllers/concerns/collavre/loopback_request.rb +32 -0
  103. data/app/controllers/concerns/collavre/origin_verification.rb +29 -0
  104. data/app/controllers/concerns/collavre/permission_update_response.rb +23 -0
  105. data/app/controllers/concerns/collavre/proxy_error_response.rb +14 -0
  106. data/app/controllers/concerns/collavre/public_creative_page.rb +52 -0
  107. data/app/controllers/concerns/collavre/public_creative_redirectable.rb +31 -0
  108. data/app/controllers/concerns/collavre/successful_authentication.rb +12 -0
  109. data/app/controllers/concerns/collavre/svg_streaming.rb +39 -0
  110. data/app/controllers/concerns/collavre/topics/reserved_topic_guard.rb +52 -0
  111. data/app/controllers/concerns/collavre/user_creative_preferences_controller/persistence.rb +98 -0
  112. data/app/controllers/concerns/collavre/users_controller/admin_operations.rb +38 -12
  113. data/app/controllers/concerns/collavre/users_controller/ai_profile_access.rb +25 -0
  114. data/app/controllers/concerns/collavre/users_controller/ai_user_management.rb +182 -32
  115. data/app/controllers/concerns/collavre/users_controller/contact_management.rb +31 -18
  116. data/app/controllers/concerns/collavre/users_controller/profile_and_settings.rb +15 -15
  117. data/app/controllers/concerns/collavre/users_controller/registration.rb +9 -13
  118. data/app/controllers/concerns/collavre/workflow_editable.rb +112 -0
  119. data/app/errors/collavre/approval_gate_pending_error.rb +12 -0
  120. data/app/errors/collavre/approval_pending_error.rb +5 -2
  121. data/app/errors/collavre/screening_pending_error.rb +17 -0
  122. data/app/errors/collavre/task_suspended_error.rb +11 -0
  123. data/app/errors/collavre/turn_deadline_error.rb +20 -0
  124. data/app/helpers/collavre/activity_logs_helper.rb +26 -0
  125. data/app/helpers/collavre/application_helper.rb +45 -41
  126. data/app/helpers/collavre/creative_move_helper.rb +15 -0
  127. data/app/helpers/collavre/creatives_helper.rb +158 -72
  128. data/app/helpers/collavre/navigation_helper.rb +134 -0
  129. data/app/helpers/collavre/public_assets_helper.rb +14 -0
  130. data/app/helpers/collavre/public_creatives_helper.rb +44 -0
  131. data/app/javascript/__tests__/slide_view.test.js +30 -0
  132. data/app/javascript/collavre.js +4 -2
  133. data/app/javascript/collavre_pdf_viewer.js +3 -0
  134. data/app/javascript/collavre_pdf_worker.js +1 -0
  135. data/app/javascript/comments/__tests__/user_menu.test.js +137 -0
  136. data/app/javascript/comments/user_menu.js +205 -0
  137. data/app/javascript/components/EmojiPicker.js +90 -0
  138. data/app/javascript/components/HeadingButtons.js +45 -0
  139. data/app/javascript/components/HistoryButtons.jsx +26 -0
  140. data/app/javascript/components/ImageResizer.jsx +11 -30
  141. data/app/javascript/components/InlineLexicalEditor.jsx +29 -78
  142. data/app/javascript/components/__tests__/EmojiPicker.test.js +127 -0
  143. data/app/javascript/components/__tests__/HeadingButtons.test.js +111 -0
  144. data/app/javascript/components/__tests__/creative_tree_row_document_view.test.js +814 -0
  145. data/app/javascript/components/__tests__/creative_tree_row_parent_id.test.js +32 -2
  146. data/app/javascript/components/__tests__/creative_tree_row_progress_toggle.test.js +255 -0
  147. data/app/javascript/components/__tests__/document_row_swipe.test.js +206 -0
  148. data/app/javascript/components/creative_header_progress.js +24 -0
  149. data/app/javascript/components/creative_tree_row.js +96 -99
  150. data/app/javascript/components/creative_tree_row_document_view.js +251 -0
  151. data/app/javascript/components/document_row_swipe.js +107 -0
  152. data/app/javascript/components/plugins/__tests__/creative_links_plugin.test.js +59 -0
  153. data/app/javascript/components/plugins/__tests__/image_upload_plugin.test.js +107 -0
  154. data/app/javascript/components/plugins/creative_links_plugin.js +24 -0
  155. data/app/javascript/components/plugins/image_upload_plugin.jsx +24 -28
  156. data/app/javascript/components/plugins/markdown_shortcuts_plugin.jsx +5 -2
  157. data/app/javascript/controllers/__tests__/agent_connection_controller.test.js +625 -0
  158. data/app/javascript/controllers/__tests__/agent_vendor_controller.test.js +94 -0
  159. data/app/javascript/controllers/__tests__/comment_agent_model_controller.test.js +148 -0
  160. data/app/javascript/controllers/__tests__/comment_approval_controls.test.js +45 -0
  161. data/app/javascript/controllers/__tests__/comment_user_menu_controller.test.js +285 -0
  162. data/app/javascript/controllers/__tests__/comment_version_controller.test.js +51 -0
  163. data/app/javascript/controllers/__tests__/controller_csrf_requests.test.js +137 -0
  164. data/app/javascript/controllers/__tests__/creative_history_controller.test.js +123 -0
  165. data/app/javascript/controllers/__tests__/creative_history_detail_controller.test.js +104 -0
  166. data/app/javascript/controllers/__tests__/creative_history_undo_controller.test.js +55 -0
  167. data/app/javascript/controllers/__tests__/creative_image_lightbox_controller.test.js +583 -0
  168. data/app/javascript/controllers/__tests__/creative_move_controller.test.js +713 -0
  169. data/app/javascript/controllers/__tests__/cron_badge_controller.test.js +436 -0
  170. data/app/javascript/controllers/__tests__/desktop_proxy_setup_controller.test.js +96 -0
  171. data/app/javascript/controllers/__tests__/document_preview_controller.test.js +33 -0
  172. data/app/javascript/controllers/__tests__/entity_list_controller.test.js +270 -0
  173. data/app/javascript/controllers/__tests__/expansion_controller.test.js +235 -0
  174. data/app/javascript/controllers/__tests__/index.test.js +48 -0
  175. data/app/javascript/controllers/__tests__/inline_creative_picker_controller.test.js +232 -0
  176. data/app/javascript/controllers/__tests__/last_visited_creative_controller.test.js +103 -0
  177. data/app/javascript/controllers/__tests__/link_creative_controller.test.js +354 -2
  178. data/app/javascript/controllers/__tests__/notice_bar_controller.test.js +1076 -0
  179. data/app/javascript/controllers/__tests__/popup_menu_controller.test.js +267 -0
  180. data/app/javascript/controllers/__tests__/progress_filter_controller.test.js +134 -0
  181. data/app/javascript/controllers/__tests__/search_popup_controller.test.js +324 -0
  182. data/app/javascript/controllers/__tests__/share_modal_public_link.test.js +113 -0
  183. data/app/javascript/controllers/__tests__/share_user_search_controller.test.js +17 -0
  184. data/app/javascript/controllers/__tests__/tabs_controller.test.js +137 -0
  185. data/app/javascript/controllers/__tests__/tool_category_controller.test.js +116 -0
  186. data/app/javascript/controllers/__tests__/topic_list_controller.test.js +125 -0
  187. data/app/javascript/controllers/__tests__/workspace_tree_controller.test.js +1746 -0
  188. data/app/javascript/controllers/agent_auth_controller.js +245 -0
  189. data/app/javascript/controllers/agent_connection_controller.js +197 -0
  190. data/app/javascript/controllers/agent_vendor_controller.js +69 -0
  191. data/app/javascript/controllers/comment_agent_model_controller.js +87 -0
  192. data/app/javascript/controllers/comment_controller.js +34 -75
  193. data/app/javascript/controllers/comment_image_lightbox_controller.js +15 -0
  194. data/app/javascript/controllers/comment_user_menu_controller.js +122 -0
  195. data/app/javascript/controllers/comment_version_controller.js +10 -8
  196. data/app/javascript/controllers/comments/__tests__/comment_form_request.test.js +72 -0
  197. data/app/javascript/controllers/comments/__tests__/comment_list_response.test.js +30 -0
  198. data/app/javascript/controllers/comments/__tests__/comment_read_tracker.test.js +71 -0
  199. data/app/javascript/controllers/comments/__tests__/contexts_controller_context_list.test.js +466 -0
  200. data/app/javascript/controllers/comments/__tests__/contexts_controller_dnd.test.js +484 -0
  201. data/app/javascript/controllers/comments/__tests__/creative_quote_review_controller.test.js +111 -0
  202. data/app/javascript/controllers/comments/__tests__/drop_trigger_controller.test.js +48 -0
  203. data/app/javascript/controllers/comments/__tests__/feature_cards_controller.test.js +223 -0
  204. data/app/javascript/controllers/comments/__tests__/form_controller_default_placeholder.test.js +83 -0
  205. data/app/javascript/controllers/comments/__tests__/form_controller_double_submit.test.js +38 -0
  206. data/app/javascript/controllers/comments/__tests__/form_controller_draft.test.js +2254 -0
  207. data/app/javascript/controllers/comments/__tests__/form_controller_ime_send.test.js +324 -0
  208. data/app/javascript/controllers/comments/__tests__/form_controller_review.test.js +377 -2
  209. data/app/javascript/controllers/comments/__tests__/form_controller_search_submit.test.js +106 -0
  210. data/app/javascript/controllers/comments/__tests__/form_controller_stashed_draft.test.js +134 -0
  211. data/app/javascript/controllers/comments/__tests__/form_controller_stashed_draft_creative_switch.test.js +166 -0
  212. data/app/javascript/controllers/comments/__tests__/form_controller_stashed_draft_failure.test.js +183 -0
  213. data/app/javascript/controllers/comments/__tests__/form_draft_manager.test.js +154 -0
  214. data/app/javascript/controllers/comments/__tests__/inline_login_preservation.test.js +23 -0
  215. data/app/javascript/controllers/comments/__tests__/list_controller_approval_gate.test.js +51 -0
  216. data/app/javascript/controllers/comments/__tests__/list_controller_batch_delete.test.js +97 -0
  217. data/app/javascript/controllers/comments/__tests__/list_controller_deep_link_topic.test.js +467 -0
  218. data/app/javascript/controllers/comments/__tests__/list_controller_dnd.test.js +26 -0
  219. data/app/javascript/controllers/comments/__tests__/list_controller_docked.test.js +168 -0
  220. data/app/javascript/controllers/comments/__tests__/list_controller_load_result.test.js +56 -0
  221. data/app/javascript/controllers/comments/__tests__/list_controller_loading.test.js +43 -0
  222. data/app/javascript/controllers/comments/__tests__/list_controller_prev_message.test.js +217 -1
  223. data/app/javascript/controllers/comments/__tests__/list_controller_read_pointer.test.js +288 -0
  224. data/app/javascript/controllers/comments/__tests__/list_controller_resend.test.js +69 -0
  225. data/app/javascript/controllers/comments/__tests__/list_controller_resume_pagination.test.js +191 -0
  226. data/app/javascript/controllers/comments/__tests__/list_controller_stream_archived.test.js +221 -0
  227. data/app/javascript/controllers/comments/__tests__/list_controller_stream_search.test.js +104 -0
  228. data/app/javascript/controllers/comments/__tests__/loading_controller.test.js +83 -0
  229. data/app/javascript/controllers/comments/__tests__/mention_menu_controller.test.js +59 -0
  230. data/app/javascript/controllers/comments/__tests__/placeholder_controller.test.js +79 -0
  231. data/app/javascript/controllers/comments/__tests__/popup_controller.test.js +1070 -3
  232. data/app/javascript/controllers/comments/__tests__/popup_exit_target.test.js +118 -0
  233. data/app/javascript/controllers/comments/__tests__/popup_focus.test.js +72 -0
  234. data/app/javascript/controllers/comments/__tests__/popup_fullscreen.test.js +320 -0
  235. data/app/javascript/controllers/comments/__tests__/popup_initial_url.test.js +103 -0
  236. data/app/javascript/controllers/comments/__tests__/popup_resume_resync.test.js +154 -0
  237. data/app/javascript/controllers/comments/__tests__/presence_controller.test.js +775 -15
  238. data/app/javascript/controllers/comments/__tests__/presence_controller_agent_online.test.js +244 -0
  239. data/app/javascript/controllers/comments/__tests__/presence_controller_participant_list.test.js +570 -0
  240. data/app/javascript/controllers/comments/__tests__/resend_action.test.js +137 -0
  241. data/app/javascript/controllers/comments/__tests__/review_quotes_store.test.js +27 -0
  242. data/app/javascript/controllers/comments/__tests__/run_options_controller.test.js +248 -0
  243. data/app/javascript/controllers/comments/__tests__/topics_controller_action_errors.test.js +6 -0
  244. data/app/javascript/controllers/comments/__tests__/topics_controller_archived.test.js +924 -0
  245. data/app/javascript/controllers/comments/__tests__/topics_controller_creation_container.test.js +165 -0
  246. data/app/javascript/controllers/comments/__tests__/topics_controller_creation_scroll.test.js +92 -0
  247. data/app/javascript/controllers/comments/__tests__/topics_controller_delete.test.js +361 -0
  248. data/app/javascript/controllers/comments/__tests__/topics_controller_dnd.test.js +120 -0
  249. data/app/javascript/controllers/comments/__tests__/topics_controller_docked.test.js +32 -0
  250. data/app/javascript/controllers/comments/__tests__/topics_controller_last_topic_echo.test.js +1938 -0
  251. data/app/javascript/controllers/comments/__tests__/topics_controller_primary_agent.test.js +112 -2
  252. data/app/javascript/controllers/comments/__tests__/topics_controller_scroll.test.js +199 -0
  253. data/app/javascript/controllers/comments/__tests__/topics_controller_selection_race.test.js +1253 -0
  254. data/app/javascript/controllers/comments/__tests__/topics_controller_topic_list.test.js +313 -0
  255. data/app/javascript/controllers/comments/approval_request_options.js +12 -0
  256. data/app/javascript/controllers/comments/comment_form_request.js +26 -0
  257. data/app/javascript/controllers/comments/comment_list_response.js +20 -0
  258. data/app/javascript/controllers/comments/comment_read_tracker.js +143 -0
  259. data/app/javascript/controllers/comments/contexts_controller.js +338 -226
  260. data/app/javascript/controllers/comments/creative_chat_navigation.js +50 -0
  261. data/app/javascript/controllers/comments/creative_quote_review_controller.js +30 -0
  262. data/app/javascript/controllers/comments/drop_trigger_controller.js +2 -7
  263. data/app/javascript/controllers/comments/feature_cards_controller.js +83 -0
  264. data/app/javascript/controllers/comments/form_controller.js +375 -175
  265. data/app/javascript/controllers/comments/form_draft_manager.js +269 -0
  266. data/app/javascript/controllers/comments/form_draft_migration.js +142 -0
  267. data/app/javascript/controllers/comments/form_draft_persistence.js +228 -0
  268. data/app/javascript/controllers/comments/inline_login_preservation.js +18 -0
  269. data/app/javascript/controllers/comments/list_controller.js +283 -186
  270. data/app/javascript/controllers/comments/loading_controller.js +48 -0
  271. data/app/javascript/controllers/comments/mention_menu_controller.js +1 -24
  272. data/app/javascript/controllers/comments/optimistic_removal.js +15 -0
  273. data/app/javascript/controllers/comments/pagination_state.js +20 -0
  274. data/app/javascript/controllers/comments/placeholder_controller.js +30 -0
  275. data/app/javascript/controllers/comments/popup_controller.js +379 -473
  276. data/app/javascript/controllers/comments/popup_creative_progress.js +51 -0
  277. data/app/javascript/controllers/comments/popup_exit_target.js +92 -0
  278. data/app/javascript/controllers/comments/popup_focus.js +5 -0
  279. data/app/javascript/controllers/comments/popup_fullscreen.js +335 -0
  280. data/app/javascript/controllers/comments/popup_resume_resync.js +28 -0
  281. data/app/javascript/controllers/comments/popup_url_open.js +22 -0
  282. data/app/javascript/controllers/comments/presence_controller.js +598 -183
  283. data/app/javascript/controllers/comments/previous_message_navigation.js +154 -0
  284. data/app/javascript/controllers/comments/resend_action.js +63 -0
  285. data/app/javascript/controllers/comments/review_quotes_store.js +11 -8
  286. data/app/javascript/controllers/comments/run_options_controller.js +145 -0
  287. data/app/javascript/controllers/comments/topics/last_topic_save.js +124 -0
  288. data/app/javascript/controllers/comments/topics/reserved_topic_deletion.js +25 -0
  289. data/app/javascript/controllers/comments/topics/save_order_state.js +127 -0
  290. data/app/javascript/controllers/comments/topics/selection_restore_state.js +42 -0
  291. data/app/javascript/controllers/comments/topics/self_echo_state.js +24 -0
  292. data/app/javascript/controllers/comments/topics_controller.js +1723 -240
  293. data/app/javascript/controllers/common_popup_controller.js +2 -2
  294. data/app/javascript/controllers/creative_history_controller.js +57 -0
  295. data/app/javascript/controllers/creative_history_detail_controller.js +41 -0
  296. data/app/javascript/controllers/creative_history_undo_controller.js +19 -0
  297. data/app/javascript/controllers/creative_image_lightbox_controller.js +114 -0
  298. data/app/javascript/controllers/creative_move_controller.js +202 -0
  299. data/app/javascript/controllers/creatives/__tests__/document_selection_controller.test.js +241 -0
  300. data/app/javascript/controllers/creatives/__tests__/document_view_controller.test.js +173 -0
  301. data/app/javascript/controllers/creatives/__tests__/drag_drop_controller.test.js +74 -0
  302. data/app/javascript/controllers/creatives/__tests__/import_controller.test.js +48 -0
  303. data/app/javascript/controllers/creatives/__tests__/select_mode_controller.test.js +250 -0
  304. data/app/javascript/controllers/creatives/__tests__/tree_controller.test.js +1210 -2
  305. data/app/javascript/controllers/creatives/__tests__/workflow_rule_controller.test.js +322 -0
  306. data/app/javascript/controllers/creatives/__tests__/write_access_request_controller.test.js +125 -0
  307. data/app/javascript/controllers/creatives/document_selection_controller.js +77 -0
  308. data/app/javascript/controllers/creatives/document_view_controller.js +82 -0
  309. data/app/javascript/controllers/creatives/drag_drop_controller.js +13 -19
  310. data/app/javascript/controllers/creatives/expansion_controller.js +21 -19
  311. data/app/javascript/controllers/creatives/import_controller.js +1 -1
  312. data/app/javascript/controllers/creatives/select_mode_controller.js +38 -6
  313. data/app/javascript/controllers/creatives/tree_controller.js +260 -59
  314. data/app/javascript/controllers/creatives/workflow_rule_controller.js +96 -0
  315. data/app/javascript/controllers/creatives/workflow_rule_form.js +183 -0
  316. data/app/javascript/controllers/creatives/write_access_request_controller.js +58 -0
  317. data/app/javascript/controllers/cron_badge_controller.js +187 -0
  318. data/app/javascript/controllers/desktop_proxy_setup_controller.js +51 -0
  319. data/app/javascript/controllers/document_preview_controller.js +16 -0
  320. data/app/javascript/controllers/entity_list_controller.js +147 -0
  321. data/app/javascript/controllers/gateway_check_controller.js +34 -0
  322. data/app/javascript/controllers/image_lightbox_controller.js +29 -70
  323. data/app/javascript/controllers/image_lightbox_values.js +13 -0
  324. data/app/javascript/controllers/index.js +106 -8
  325. data/app/javascript/controllers/inline_creative_picker_controller.js +110 -0
  326. data/app/javascript/controllers/last_visited_creative_controller.js +58 -0
  327. data/app/javascript/controllers/link_creative_controller.js +102 -28
  328. data/app/javascript/controllers/notice_bar_controller.js +364 -0
  329. data/app/javascript/controllers/org_chart_controller.js +2 -23
  330. data/app/javascript/controllers/popup_menu_controller.js +128 -45
  331. data/app/javascript/controllers/progress_filter_controller.js +12 -22
  332. data/app/javascript/controllers/search_popup_controller.js +72 -50
  333. data/app/javascript/controllers/searchable_list_controller.js +30 -0
  334. data/app/javascript/controllers/share_modal_controller.js +18 -56
  335. data/app/javascript/controllers/share_user_search_controller.js +3 -13
  336. data/app/javascript/controllers/tabs_controller.js +5 -1
  337. data/app/javascript/controllers/tool_category_controller.js +39 -0
  338. data/app/javascript/controllers/topic_list_controller.js +42 -31
  339. data/app/javascript/controllers/topic_search_controller.js +2 -4
  340. data/app/javascript/controllers/workspace_tree_controller.js +803 -0
  341. data/app/javascript/creatives/__tests__/row_progress.test.js +155 -0
  342. data/app/javascript/creatives/__tests__/tree_reload_events.test.js +101 -0
  343. data/app/javascript/creatives/__tests__/tree_renderer.test.js +195 -0
  344. data/app/javascript/creatives/__tests__/tree_view_state.test.js +277 -0
  345. data/app/javascript/creatives/branch_expansion.js +39 -0
  346. data/app/javascript/creatives/drag_drop/__tests__/command_integration.test.js +194 -0
  347. data/app/javascript/creatives/drag_drop/__tests__/creative_tree_drop.test.js +964 -0
  348. data/app/javascript/creatives/drag_drop/__tests__/drop_completion_empty_state.test.js +98 -0
  349. data/app/javascript/creatives/drag_drop/__tests__/event_handlers_data.test.js +329 -0
  350. data/app/javascript/creatives/drag_drop/__tests__/file_drop.test.js +99 -0
  351. data/app/javascript/creatives/drag_drop/__tests__/hover_expand.test.js +134 -0
  352. data/app/javascript/creatives/drag_drop/__tests__/indicator.test.js +36 -0
  353. data/app/javascript/creatives/drag_drop/__tests__/move_command.test.js +471 -0
  354. data/app/javascript/creatives/drag_drop/__tests__/move_command_dom_recovery.test.js +346 -0
  355. data/app/javascript/creatives/drag_drop/__tests__/move_command_queued_saves.test.js +201 -0
  356. data/app/javascript/creatives/drag_drop/__tests__/move_feedback.test.js +79 -0
  357. data/app/javascript/creatives/drag_drop/__tests__/source_window_bundle.test.js +141 -0
  358. data/app/javascript/creatives/drag_drop/__tests__/state.test.js +36 -0
  359. data/app/javascript/creatives/drag_drop/__tests__/topic_move_released_agent.test.js +125 -0
  360. data/app/javascript/creatives/drag_drop/__tests__/touch_tree_integration.test.js +209 -0
  361. data/app/javascript/creatives/drag_drop/__tests__/workspace_tree_adapter.test.js +517 -0
  362. data/app/javascript/creatives/drag_drop/__tests__/workspace_tree_dom.test.js +105 -0
  363. data/app/javascript/creatives/drag_drop/dom.js +9 -0
  364. data/app/javascript/creatives/drag_drop/event_handlers.js +291 -431
  365. data/app/javascript/creatives/drag_drop/file_drop.js +60 -0
  366. data/app/javascript/creatives/drag_drop/indicator.js +2 -1
  367. data/app/javascript/creatives/drag_drop/move_command.js +297 -0
  368. data/app/javascript/creatives/drag_drop/move_feedback.js +22 -0
  369. data/app/javascript/creatives/drag_drop/operations.js +73 -0
  370. data/app/javascript/creatives/drag_drop/state.js +10 -1
  371. data/app/javascript/creatives/drag_drop/workspace_tree_adapter.js +161 -0
  372. data/app/javascript/creatives/drag_drop/workspace_tree_dom.js +52 -0
  373. data/app/javascript/creatives/row_progress.js +96 -0
  374. data/app/javascript/creatives/tree_reload_events.js +42 -0
  375. data/app/javascript/creatives/tree_renderer.js +132 -40
  376. data/app/javascript/creatives/tree_view_state.js +87 -0
  377. data/app/javascript/lib/__tests__/chat_drafts.test.js +1458 -0
  378. data/app/javascript/lib/__tests__/common_popup_bounds.test.js +8 -3
  379. data/app/javascript/lib/__tests__/common_popup_placement.test.js +374 -0
  380. data/app/javascript/lib/__tests__/common_popup_reshow.test.js +131 -0
  381. data/app/javascript/lib/__tests__/creative_link_prefetch.test.js +46 -0
  382. data/app/javascript/lib/__tests__/creative_quote.test.js +343 -0
  383. data/app/javascript/lib/__tests__/creative_title.test.js +15 -0
  384. data/app/javascript/lib/__tests__/entity_list_popup.test.js +47 -0
  385. data/app/javascript/lib/__tests__/html_escape.test.js +29 -0
  386. data/app/javascript/lib/__tests__/last_visited_creative.test.js +87 -0
  387. data/app/javascript/lib/__tests__/permission_update.test.js +38 -0
  388. data/app/javascript/lib/__tests__/popup_toggle_guard.test.js +82 -0
  389. data/app/javascript/lib/__tests__/ppt_background.test.js +86 -0
  390. data/app/javascript/lib/__tests__/ppt_connector.test.js +80 -0
  391. data/app/javascript/lib/__tests__/ppt_formatting.test.js +246 -0
  392. data/app/javascript/lib/__tests__/ppt_media.test.js +86 -0
  393. data/app/javascript/lib/__tests__/quote_selection_popup.test.js +100 -0
  394. data/app/javascript/lib/__tests__/skill_html_entities.test.js +23 -0
  395. data/app/javascript/lib/__tests__/touch_drag_tap.test.js +31 -0
  396. data/app/javascript/lib/__tests__/touch_drag_targets.test.js +293 -0
  397. data/app/javascript/lib/__tests__/turbo_stream_actions.test.js +218 -0
  398. data/app/javascript/lib/__tests__/workspace_scroll_restoration.test.js +310 -0
  399. data/app/javascript/lib/__tests__/workspace_tree_removal.test.js +108 -0
  400. data/app/javascript/lib/api/__tests__/creatives.test.js +94 -0
  401. data/app/javascript/lib/api/__tests__/csrf_fetch.test.js +27 -0
  402. data/app/javascript/lib/api/__tests__/drag_drop.test.js +136 -0
  403. data/app/javascript/lib/api/__tests__/expansion_intent.test.js +75 -0
  404. data/app/javascript/lib/api/__tests__/expansion_save_queue.test.js +110 -0
  405. data/app/javascript/lib/api/__tests__/queue_manager.test.js +237 -0
  406. data/app/javascript/lib/api/__tests__/queue_reconciliation.test.js +57 -0
  407. data/app/javascript/lib/api/__tests__/queue_recovery.test.js +28 -0
  408. data/app/javascript/lib/api/__tests__/topics_save_last_topic.test.js +112 -0
  409. data/app/javascript/lib/api/creatives.js +35 -13
  410. data/app/javascript/lib/api/csrf_fetch.js +6 -4
  411. data/app/javascript/lib/api/drag_drop.js +25 -1
  412. data/app/javascript/lib/api/expansion_intent.js +28 -0
  413. data/app/javascript/lib/api/expansion_save_queue.js +51 -0
  414. data/app/javascript/lib/api/queue_completion.js +30 -0
  415. data/app/javascript/lib/api/queue_manager.js +34 -50
  416. data/app/javascript/lib/api/queue_reconciliation.js +44 -0
  417. data/app/javascript/lib/api/queue_recovery.js +24 -0
  418. data/app/javascript/lib/api/topics.js +63 -5
  419. data/app/javascript/lib/chat_drafts.js +786 -0
  420. data/app/javascript/lib/common_popup.js +164 -25
  421. data/app/javascript/lib/creative_link_prefetch.js +27 -0
  422. data/app/javascript/lib/creative_quote.js +135 -0
  423. data/app/javascript/lib/creative_title.js +9 -0
  424. data/app/javascript/lib/creative_tree_invalidation.js +4 -0
  425. data/app/javascript/lib/dnd/__tests__/bundle_image.test.js +32 -0
  426. data/app/javascript/lib/dnd/__tests__/envelope.test.js +262 -0
  427. data/app/javascript/lib/dnd/__tests__/hit_test.test.js +69 -0
  428. data/app/javascript/lib/dnd/__tests__/preview.test.js +22 -0
  429. data/app/javascript/lib/dnd/__tests__/registry.test.js +797 -0
  430. data/app/javascript/lib/dnd/__tests__/session.test.js +213 -0
  431. data/app/javascript/lib/dnd/__tests__/session_without_window.test.js +15 -0
  432. data/app/javascript/lib/dnd/__tests__/touch_bridge.test.js +532 -0
  433. data/app/javascript/lib/dnd/creative_label.js +21 -0
  434. data/app/javascript/lib/dnd/envelope.js +194 -0
  435. data/app/javascript/lib/dnd/hit_test.js +42 -0
  436. data/app/javascript/lib/dnd/preview.js +10 -0
  437. data/app/javascript/lib/dnd/registry.js +315 -0
  438. data/app/javascript/lib/dnd/session.js +152 -0
  439. data/app/javascript/lib/dnd/touch_bridge.js +184 -0
  440. data/app/javascript/lib/editor/__tests__/code_languages.test.js +1 -5
  441. data/app/javascript/lib/editor/code_languages.js +0 -1
  442. data/app/javascript/lib/entity_list_popup.js +45 -0
  443. data/app/javascript/lib/html_escape.js +12 -0
  444. data/app/javascript/lib/image_lightbox_pan.js +31 -0
  445. data/app/javascript/lib/last_visited_creative.js +97 -0
  446. data/app/javascript/lib/lexical/__tests__/attachment_payload.test.js +12 -189
  447. data/app/javascript/lib/lexical/__tests__/creative_link_drop.test.js +414 -0
  448. data/app/javascript/lib/lexical/__tests__/creative_link_node.test.js +212 -0
  449. data/app/javascript/lib/lexical/__tests__/creative_link_trigger.test.js +133 -0
  450. data/app/javascript/lib/lexical/__tests__/file_drop.test.js +288 -0
  451. data/app/javascript/lib/lexical/__tests__/link_toolbar.test.js +62 -0
  452. data/app/javascript/lib/lexical/attachment_node.jsx +21 -42
  453. data/app/javascript/lib/lexical/attachment_payload.js +0 -274
  454. data/app/javascript/lib/lexical/attachment_presentation.js +57 -0
  455. data/app/javascript/lib/lexical/creative_link_drop.js +98 -0
  456. data/app/javascript/lib/lexical/creative_link_node.js +127 -0
  457. data/app/javascript/lib/lexical/creative_link_trigger.js +98 -0
  458. data/app/javascript/lib/lexical/file_drop.js +106 -0
  459. data/app/javascript/lib/lexical/link_toolbar.js +23 -0
  460. data/app/javascript/lib/lexical/ppt_attachment.js +26 -0
  461. data/app/javascript/lib/lexical/upload_anchor_node.js +16 -0
  462. data/app/javascript/lib/lexical/upload_nodes.js +6 -0
  463. data/app/javascript/lib/media_loading.js +25 -0
  464. data/app/javascript/lib/permission_update.js +21 -0
  465. data/app/javascript/lib/popup_toggle_guard.js +56 -0
  466. data/app/javascript/lib/ppt_background.js +48 -0
  467. data/app/javascript/lib/ppt_chart.js +59 -0
  468. data/app/javascript/lib/ppt_connector.js +63 -0
  469. data/app/javascript/lib/ppt_formatting.js +138 -0
  470. data/app/javascript/lib/ppt_media.js +61 -0
  471. data/app/javascript/lib/quote_selection_popup.js +67 -0
  472. data/app/javascript/lib/responsive_images.js +0 -12
  473. data/app/javascript/lib/search_combobox.js +61 -0
  474. data/app/javascript/lib/share_modal_links.js +35 -0
  475. data/app/javascript/lib/touch_drag.js +119 -37
  476. data/app/javascript/lib/turbo_stream_actions.js +41 -16
  477. data/app/javascript/lib/utils/__tests__/attachment_rendering.test.js +189 -0
  478. data/app/javascript/lib/utils/__tests__/creative_link_navigation.test.js +301 -0
  479. data/app/javascript/lib/utils/__tests__/filter_navigation.test.js +226 -0
  480. data/app/javascript/lib/utils/__tests__/focus.test.js +144 -0
  481. data/app/javascript/lib/utils/__tests__/markdown.test.js +44 -0
  482. data/app/javascript/lib/utils/__tests__/mermaid_math.test.js +24 -0
  483. data/app/javascript/lib/utils/__tests__/sanitize_description.test.js +10 -0
  484. data/app/javascript/lib/utils/creative_link_navigation.js +64 -0
  485. data/app/javascript/lib/utils/filter_navigation.js +114 -0
  486. data/app/javascript/lib/utils/focus.js +36 -0
  487. data/app/javascript/lib/utils/markdown.js +0 -4
  488. data/app/javascript/lib/utils/sanitize_description.js +12 -4
  489. data/app/javascript/lib/utils/workspace_chat_navigation.js +25 -0
  490. data/app/javascript/lib/viewport_region.js +20 -0
  491. data/app/javascript/lib/workspace_scroll_restoration.js +134 -0
  492. data/app/javascript/lib/workspace_tree_removal.js +91 -0
  493. data/app/javascript/lib/workspace_tree_visibility.js +25 -0
  494. data/app/javascript/modules/__tests__/background_creative_create.test.js +114 -0
  495. data/app/javascript/modules/__tests__/command_args_form.test.js +96 -0
  496. data/app/javascript/modules/__tests__/command_menu_creative_picker.test.js +62 -0
  497. data/app/javascript/modules/__tests__/command_menu_details.test.js +199 -0
  498. data/app/javascript/modules/__tests__/command_menu_typeahead.test.js +267 -0
  499. data/app/javascript/modules/__tests__/creative_inline_dataset.test.js +35 -0
  500. data/app/javascript/modules/__tests__/creative_inline_payload.test.js +35 -0
  501. data/app/javascript/modules/__tests__/creative_link_picker.test.js +85 -0
  502. data/app/javascript/modules/__tests__/creative_row_editor_archive.test.js +391 -0
  503. data/app/javascript/modules/__tests__/creative_row_editor_background_create.test.js +2147 -0
  504. data/app/javascript/modules/__tests__/creative_row_editor_delegated_clicks.test.js +158 -0
  505. data/app/javascript/modules/__tests__/creative_row_editor_empty_state_recovery.test.js +214 -0
  506. data/app/javascript/modules/__tests__/creative_row_editor_empty_state_removal.test.js +468 -0
  507. data/app/javascript/modules/__tests__/creative_row_editor_instant_reveal.test.js +186 -0
  508. data/app/javascript/modules/__tests__/creative_row_editor_save_paths.test.js +1132 -0
  509. data/app/javascript/modules/__tests__/creative_row_editor_session.test.js +144 -0
  510. data/app/javascript/modules/__tests__/creative_save_state.test.js +165 -0
  511. data/app/javascript/modules/__tests__/creative_tree_dom.test.js +30 -0
  512. data/app/javascript/modules/__tests__/creative_tree_empty_state.test.js +186 -0
  513. data/app/javascript/modules/__tests__/creative_type_editor.test.js +203 -0
  514. data/app/javascript/modules/__tests__/dom_listener_registry.test.js +67 -0
  515. data/app/javascript/modules/__tests__/failed_creative_save.test.js +65 -0
  516. data/app/javascript/modules/__tests__/html_content_empty.test.js +11 -0
  517. data/app/javascript/modules/__tests__/integration_wizard.test.js +139 -0
  518. data/app/javascript/modules/__tests__/mention_menu.test.js +190 -0
  519. data/app/javascript/modules/__tests__/notice_bar_motion.test.js +132 -0
  520. data/app/javascript/modules/__tests__/notice_bar_sheet.test.js +108 -0
  521. data/app/javascript/modules/__tests__/notice_bar_spotlight.test.js +109 -0
  522. data/app/javascript/modules/__tests__/notice_bar_storage.test.js +31 -0
  523. data/app/javascript/modules/__tests__/notice_bar_toasts.test.js +71 -0
  524. data/app/javascript/modules/__tests__/notice_bar_view.test.js +89 -0
  525. data/app/javascript/modules/__tests__/pdf_assets.test.js +26 -0
  526. data/app/javascript/modules/__tests__/pdf_document.test.js +231 -0
  527. data/app/javascript/modules/__tests__/persisted_creative_tree.test.js +48 -0
  528. data/app/javascript/modules/__tests__/ppt_viewer.test.js +219 -0
  529. data/app/javascript/modules/__tests__/queued_creative_row.test.js +206 -0
  530. data/app/javascript/modules/__tests__/recovered_creative_position.test.js +57 -0
  531. data/app/javascript/modules/__tests__/slide_view_attachments.test.js +71 -0
  532. data/app/javascript/modules/__tests__/support/inline_editor_dom.js +183 -0
  533. data/app/javascript/modules/__tests__/viewer_navigation.test.js +42 -0
  534. data/app/javascript/modules/background_creative_create.js +326 -0
  535. data/app/javascript/modules/command_args_form.js +30 -40
  536. data/app/javascript/modules/command_menu.js +171 -55
  537. data/app/javascript/modules/creative_inline_dataset.js +34 -0
  538. data/app/javascript/modules/creative_inline_payload.js +10 -14
  539. data/app/javascript/modules/creative_link_picker.js +56 -0
  540. data/app/javascript/modules/creative_removal.js +39 -0
  541. data/app/javascript/modules/creative_row_editor.js +818 -634
  542. data/app/javascript/modules/creative_row_editor_delegated_clicks.js +87 -0
  543. data/app/javascript/modules/creative_save_state.js +141 -0
  544. data/app/javascript/modules/creative_tree_dom.js +4 -0
  545. data/app/javascript/modules/creative_tree_empty_state.js +80 -0
  546. data/app/javascript/modules/creative_type_editor.js +139 -0
  547. data/app/javascript/modules/dom_listener_registry.js +23 -0
  548. data/app/javascript/modules/failed_creative_save.js +42 -0
  549. data/app/javascript/modules/html_content_empty.js +5 -3
  550. data/app/javascript/modules/integration_wizard.js +68 -19
  551. data/app/javascript/modules/keep_goal_text.js +4 -0
  552. data/app/javascript/modules/lexical_inline_editor.jsx +9 -2
  553. data/app/javascript/modules/mention_menu.js +36 -25
  554. data/app/javascript/modules/notice_bar/__tests__/refresh.test.js +177 -0
  555. data/app/javascript/modules/notice_bar/motion.js +59 -0
  556. data/app/javascript/modules/notice_bar/refresh.js +53 -0
  557. data/app/javascript/modules/notice_bar/sheet.js +102 -0
  558. data/app/javascript/modules/notice_bar/spotlight.js +78 -0
  559. data/app/javascript/modules/notice_bar/storage.js +14 -0
  560. data/app/javascript/modules/notice_bar/toasts.js +49 -0
  561. data/app/javascript/modules/notice_bar/view.js +101 -0
  562. data/app/javascript/modules/pdf_document.js +65 -0
  563. data/app/javascript/modules/pending_creative_sync.js +23 -0
  564. data/app/javascript/modules/persisted_creative_tree.js +39 -0
  565. data/app/javascript/modules/ppt_viewer.js +76 -0
  566. data/app/javascript/modules/queued_creative_row.js +128 -0
  567. data/app/javascript/modules/recovered_creative_position.js +52 -0
  568. data/app/javascript/modules/slide_view.js +9 -3
  569. data/app/javascript/modules/viewer_navigation.js +16 -0
  570. data/app/javascript/slide_view.js +9 -0
  571. data/app/javascript/utils/__tests__/caret_anchor.test.js +75 -0
  572. data/app/javascript/utils/__tests__/chevron_icons.test.js +15 -0
  573. data/app/javascript/utils/caret_position.js +10 -0
  574. data/app/javascript/utils/chevron_icons.js +7 -0
  575. data/app/jobs/collavre/agent_provisioning_sync_job.rb +79 -0
  576. data/app/jobs/collavre/ai_agent_job.rb +346 -135
  577. data/app/jobs/collavre/approval_continuation_job.rb +102 -0
  578. data/app/jobs/collavre/approval_gate_resume_job.rb +22 -0
  579. data/app/jobs/collavre/async_approval_resume_job.rb +20 -0
  580. data/app/jobs/collavre/async_approval_sweep_job.rb +44 -0
  581. data/app/jobs/collavre/batch_destroy_comments_job.rb +17 -0
  582. data/app/jobs/collavre/cancel_offline_delegated_tasks_job.rb +34 -106
  583. data/app/jobs/collavre/cdn_invalidation_job.rb +62 -0
  584. data/app/jobs/collavre/claude_approval_resume_job.rb +15 -0
  585. data/app/jobs/collavre/comment_badges_broadcast_job.rb +28 -0
  586. data/app/jobs/collavre/comment_link_preview_job.rb +33 -0
  587. data/app/jobs/collavre/comment_notification_job.rb +14 -0
  588. data/app/jobs/collavre/comment_push_delivery_sweep_job.rb +25 -0
  589. data/app/jobs/collavre/compress_job.rb +36 -49
  590. data/app/jobs/collavre/creative_broadcast_job.rb +166 -56
  591. data/app/jobs/collavre/creative_history_notice_job.rb +40 -0
  592. data/app/jobs/collavre/creative_history_prune_job.rb +86 -0
  593. data/app/jobs/collavre/creative_tree_invalidation_job.rb +33 -0
  594. data/app/jobs/collavre/cron_action_job.rb +55 -20
  595. data/app/jobs/collavre/cron_scheduler_job.rb +44 -3
  596. data/app/jobs/collavre/drop_trigger_job.rb +54 -35
  597. data/app/jobs/collavre/endpoint_health_probe_job.rb +23 -0
  598. data/app/jobs/collavre/endpoint_health_sweep_job.rb +22 -0
  599. data/app/jobs/collavre/gateway_health_probe_job.rb +33 -0
  600. data/app/jobs/collavre/gateway_health_sweep_job.rb +22 -0
  601. data/app/jobs/collavre/inline_agent_replay_job.rb +32 -0
  602. data/app/jobs/collavre/keep_loop_reconcile_job.rb +57 -0
  603. data/app/jobs/collavre/merge_comments_job.rb +37 -44
  604. data/app/jobs/collavre/offline_task_sweep_job.rb +44 -0
  605. data/app/jobs/collavre/permission_cache_job.rb +19 -10
  606. data/app/jobs/collavre/purge_unreferenced_blob_job.rb +19 -0
  607. data/app/jobs/collavre/push_notification_job.rb +65 -20
  608. data/app/jobs/collavre/recover_interrupted_tasks_job.rb +79 -0
  609. data/app/jobs/collavre/restore_dropped_dispatches_job.rb +17 -0
  610. data/app/jobs/collavre/resume_suspended_tasks_job.rb +29 -0
  611. data/app/jobs/collavre/solid_queue_worker_watchdog_job.rb +108 -0
  612. data/app/jobs/collavre/stuck_detector_job.rb +1 -1
  613. data/app/jobs/collavre/touch_creative_subtree_job.rb +14 -0
  614. data/app/jobs/collavre/trigger_loop_check_job.rb +104 -105
  615. data/app/jobs/collavre/trigger_loop_verify_job.rb +51 -82
  616. data/app/jobs/collavre/workflow_outbox_job.rb +10 -0
  617. data/app/jobs/collavre/workflow_push_job.rb +11 -0
  618. data/app/jobs/collavre/workflow_sweep_job.rb +11 -0
  619. data/app/jobs/concerns/collavre/comment_serializable.rb +3 -1
  620. data/app/jobs/concerns/collavre/dispatch_admission.rb +95 -0
  621. data/app/jobs/concerns/collavre/trigger_loop_helpers.rb +178 -13
  622. data/app/models/collavre/agent_gateway.rb +276 -0
  623. data/app/models/collavre/agent_subscription.rb +4 -4
  624. data/app/models/collavre/agent_workspace.rb +245 -0
  625. data/app/models/collavre/blob_access_flag.rb +24 -0
  626. data/app/models/collavre/channel.rb +17 -0
  627. data/app/models/collavre/comment/approvable.rb +14 -1
  628. data/app/models/collavre/comment/approval_gate.rb +98 -0
  629. data/app/models/collavre/comment/batch_destruction.rb +173 -0
  630. data/app/models/collavre/comment/broadcastable.rb +40 -52
  631. data/app/models/collavre/comment/bulk_follow_up_jobs.rb +29 -0
  632. data/app/models/collavre/comment/claude_channel_permission.rb +59 -5
  633. data/app/models/collavre/comment/creative_quote.rb +55 -0
  634. data/app/models/collavre/comment/image_cdn_eviction.rb +36 -0
  635. data/app/models/collavre/comment/notifiable.rb +157 -79
  636. data/app/models/collavre/comment/suspension_notice.rb +20 -0
  637. data/app/models/collavre/comment/topic_membership.rb +61 -0
  638. data/app/models/collavre/comment/trigger_loop_resume.rb +77 -0
  639. data/app/models/collavre/comment.rb +350 -121
  640. data/app/models/collavre/comment_notification_delivery.rb +72 -0
  641. data/app/models/collavre/comment_presence_store/cache_batches.rb +64 -0
  642. data/app/models/collavre/comment_presence_store.rb +272 -12
  643. data/app/models/collavre/comment_read_pointer.rb +9 -15
  644. data/app/models/collavre/comment_version.rb +4 -0
  645. data/app/models/collavre/creative/ai_write_policy.rb +26 -0
  646. data/app/models/collavre/creative/contextual.rb +153 -0
  647. data/app/models/collavre/creative/describable.rb +42 -27
  648. data/app/models/collavre/creative/history_trackable.rb +104 -0
  649. data/app/models/collavre/creative/linkable.rb +21 -1
  650. data/app/models/collavre/creative/permissible.rb +23 -20
  651. data/app/models/collavre/creative/publishable.rb +65 -0
  652. data/app/models/collavre/creative/type_selectable.rb +25 -0
  653. data/app/models/collavre/creative.rb +55 -114
  654. data/app/models/collavre/creative_change.rb +55 -0
  655. data/app/models/collavre/creative_change_set.rb +71 -0
  656. data/app/models/collavre/creative_share.rb +128 -4
  657. data/app/models/collavre/current.rb +9 -1
  658. data/app/models/collavre/llm_model.rb +63 -0
  659. data/app/models/collavre/llm_usage/requester.rb +9 -0
  660. data/app/models/collavre/llm_usage.rb +33 -0
  661. data/app/models/collavre/mcp_tool.rb +25 -3
  662. data/app/models/collavre/orchestrator_policy.rb +25 -29
  663. data/app/models/collavre/preview_channel.rb +1 -15
  664. data/app/models/collavre/retired_task_execution.rb +9 -0
  665. data/app/models/collavre/system_setting.rb +72 -9
  666. data/app/models/collavre/task/approval_gate_cleanup.rb +23 -0
  667. data/app/models/collavre/task/async_approval.rb +30 -0
  668. data/app/models/collavre/task.rb +194 -29
  669. data/app/models/collavre/task_merged_instruction.rb +6 -0
  670. data/app/models/collavre/tool_usage/requester.rb +9 -0
  671. data/app/models/collavre/tool_usage.rb +69 -0
  672. data/app/models/collavre/topic.rb +89 -0
  673. data/app/models/collavre/user/ai_capabilities.rb +38 -0
  674. data/app/models/collavre/user.rb +114 -50
  675. data/app/models/collavre/user_creative_preference.rb +27 -1
  676. data/app/models/collavre/user_notice.rb +64 -0
  677. data/app/models/collavre/workflow/chain.rb +27 -0
  678. data/app/models/collavre/workflow/execution.rb +28 -0
  679. data/app/models/collavre/workflow/outbox.rb +43 -0
  680. data/app/models/collavre/workflow/receipt.rb +26 -0
  681. data/app/models/concerns/collavre/agent_liveness.rb +95 -0
  682. data/app/models/concerns/collavre/agent_run_options.rb +45 -0
  683. data/app/models/concerns/collavre/ai_agent_resolvable.rb +30 -7
  684. data/app/models/concerns/collavre/comment/dispatch_revocation.rb +99 -0
  685. data/app/models/concerns/collavre/comment/keep_loop.rb +166 -0
  686. data/app/models/concerns/collavre/creation_events.rb +25 -0
  687. data/app/models/concerns/collavre/creative/trigger_loop.rb +57 -0
  688. data/app/models/concerns/collavre/creative_history_topic.rb +34 -0
  689. data/app/models/concerns/collavre/creative_reserved_topics.rb +25 -0
  690. data/app/models/concerns/collavre/has_inbox_creative.rb +9 -1
  691. data/app/models/concerns/collavre/system_agent_identity.rb +13 -0
  692. data/app/models/concerns/collavre/task/replay_loop_completion.rb +78 -0
  693. data/app/models/concerns/collavre/task/trigger_loop_completion.rb +126 -0
  694. data/app/models/concerns/collavre/task/usage_attribution_tracking.rb +28 -0
  695. data/app/models/concerns/collavre/task/workflow_completion.rb +59 -0
  696. data/app/services/collavre/agent_health/endpoint_request.rb +64 -0
  697. data/app/services/collavre/agent_health/openai_endpoint_checker.rb +77 -0
  698. data/app/services/collavre/agent_health/probe.rb +47 -0
  699. data/app/services/collavre/agent_health.rb +43 -0
  700. data/app/services/collavre/agent_provisioning/archive.rb +108 -0
  701. data/app/services/collavre/agent_session_abort.rb +2 -2
  702. data/app/services/collavre/agent_tool_permission.rb +43 -0
  703. data/app/services/collavre/ai_agent/a2a_dispatcher.rb +38 -7
  704. data/app/services/collavre/ai_agent/agent_lifecycle_manager.rb +78 -6
  705. data/app/services/collavre/ai_agent/approval_conversation.rb +60 -0
  706. data/app/services/collavre/ai_agent/approval_gate_handler.rb +37 -0
  707. data/app/services/collavre/ai_agent/approval_handler.rb +20 -5
  708. data/app/services/collavre/ai_agent/budgeted_tree_renderer.rb +80 -0
  709. data/app/services/collavre/ai_agent/chat_history_window.rb +87 -0
  710. data/app/services/collavre/ai_agent/claude_channel_adapter.rb +67 -11
  711. data/app/services/collavre/ai_agent/creative_quote_context.rb +66 -0
  712. data/app/services/collavre/ai_agent/history_notice.rb +94 -0
  713. data/app/services/collavre/ai_agent/merged_trigger_comments.rb +164 -0
  714. data/app/services/collavre/ai_agent/message_builder.rb +217 -83
  715. data/app/services/collavre/ai_agent/prompt_budget.rb +142 -0
  716. data/app/services/collavre/ai_agent/referenced_creative_renderer.rb +101 -0
  717. data/app/services/collavre/ai_agent/reply_placeholder.rb +28 -0
  718. data/app/services/collavre/ai_agent/response_finalizer.rb +15 -1
  719. data/app/services/collavre/ai_agent/review_handler.rb +17 -17
  720. data/app/services/collavre/ai_agent/screening_approval_handler.rb +26 -0
  721. data/app/services/collavre/ai_agent/session_context_resolver.rb +6 -1
  722. data/app/services/collavre/ai_agent/session_provisioner.rb +3 -7
  723. data/app/services/collavre/ai_agent/task_claim_service.rb +84 -18
  724. data/app/services/collavre/ai_agent/task_reply_service.rb +90 -0
  725. data/app/services/collavre/ai_agent/task_workspace_user.rb +20 -0
  726. data/app/services/collavre/ai_agent/turn_screening.rb +132 -0
  727. data/app/services/collavre/ai_agent/workspace_authentication.rb +74 -0
  728. data/app/services/collavre/ai_agent_service.rb +113 -50
  729. data/app/services/collavre/ai_approval_summary.rb +51 -0
  730. data/app/services/collavre/ai_client/approval_gate.rb +90 -0
  731. data/app/services/collavre/ai_client/cli_tool_events.rb +100 -0
  732. data/app/services/collavre/ai_client/decision.rb +101 -0
  733. data/app/services/collavre/ai_client/error_handling.rb +67 -0
  734. data/app/services/collavre/ai_client/provider_context.rb +69 -0
  735. data/app/services/collavre/ai_client.rb +175 -136
  736. data/app/services/collavre/ai_usage_tracking.rb +93 -0
  737. data/app/services/collavre/auto_theme_generator.rb +5 -8
  738. data/app/services/collavre/blob_access.rb +166 -0
  739. data/app/services/collavre/cdn_invalidation.rb +67 -0
  740. data/app/services/collavre/claude_approval_handoff.rb +28 -0
  741. data/app/services/collavre/cli_proxy/adapter_engine.rb +27 -0
  742. data/app/services/collavre/cli_proxy/client.rb +190 -0
  743. data/app/services/collavre/cli_proxy/endpoint_policy.rb +81 -0
  744. data/app/services/collavre/cli_proxy/engine_unauthenticated_error.rb +31 -0
  745. data/app/services/collavre/cli_proxy/health_probe.rb +137 -0
  746. data/app/services/collavre/cli_proxy/identity.rb +47 -0
  747. data/app/services/collavre/cli_proxy/inline_login.rb +239 -0
  748. data/app/services/collavre/cli_proxy/inline_replay_admission.rb +57 -0
  749. data/app/services/collavre/cli_proxy/replay_claims.rb +48 -0
  750. data/app/services/collavre/cli_proxy/replay_routing.rb +43 -0
  751. data/app/services/collavre/cli_proxy/replay_workspace.rb +53 -0
  752. data/app/services/collavre/cli_proxy/run_options.rb +90 -0
  753. data/app/services/collavre/cli_proxy/safe_net_http_adapter.rb +19 -0
  754. data/app/services/collavre/command_menu_service.rb +18 -14
  755. data/app/services/collavre/comment_move_service.rb +100 -7
  756. data/app/services/collavre/comment_resend_service/cleanup.rb +20 -0
  757. data/app/services/collavre/comment_resend_service.rb +125 -0
  758. data/app/services/collavre/comment_snapshot_restore_service.rb +27 -15
  759. data/app/services/collavre/comments/action_executor.rb +45 -27
  760. data/app/services/collavre/comments/approval_gate_decision.rb +54 -0
  761. data/app/services/collavre/comments/approved_tool_invocation.rb +37 -0
  762. data/app/services/collavre/comments/async_approval_decision.rb +41 -0
  763. data/app/services/collavre/comments/command_processor.rb +14 -1
  764. data/app/services/collavre/comments/creative_quote_rejection_notice.rb +37 -0
  765. data/app/services/collavre/comments/creative_quote_review.rb +54 -0
  766. data/app/services/collavre/comments/keep_command.rb +80 -0
  767. data/app/services/collavre/comments/list_response.rb +161 -0
  768. data/app/services/collavre/comments/read_pointer_writer.rb +210 -0
  769. data/app/services/collavre/comments/read_receipt_broadcaster.rb +157 -0
  770. data/app/services/collavre/comments/read_receipt_index.rb +152 -0
  771. data/app/services/collavre/comments/topic_command.rb +68 -18
  772. data/app/services/collavre/comments/topic_mutation.rb +20 -0
  773. data/app/services/collavre/creatives/agent_turn_history.rb +15 -0
  774. data/app/services/collavre/creatives/ai_write_policy.rb +36 -0
  775. data/app/services/collavre/creatives/breadcrumb_resolver.rb +1 -1
  776. data/app/services/collavre/creatives/change_set_apply_service.rb +309 -0
  777. data/app/services/collavre/creatives/change_set_diff.rb +216 -0
  778. data/app/services/collavre/creatives/change_set_restore_service.rb +20 -0
  779. data/app/services/collavre/creatives/change_set_revert_service.rb +21 -0
  780. data/app/services/collavre/creatives/change_set_visibility.rb +108 -0
  781. data/app/services/collavre/creatives/children_index.rb +19 -8
  782. data/app/services/collavre/creatives/comment_badge_index.rb +299 -27
  783. data/app/services/collavre/creatives/create_service.rb +3 -1
  784. data/app/services/collavre/creatives/creation_revert_policy.rb +35 -0
  785. data/app/services/collavre/creatives/creative_quote_turn.rb +96 -0
  786. data/app/services/collavre/creatives/description_image_dimensions.rb +50 -0
  787. data/app/services/collavre/creatives/destroy_service.rb +18 -2
  788. data/app/services/collavre/creatives/draft_change_set_applicator.rb +121 -0
  789. data/app/services/collavre/creatives/draft_change_set_capture.rb +206 -0
  790. data/app/services/collavre/creatives/draft_change_set_reject_service.rb +45 -0
  791. data/app/services/collavre/creatives/draft_conflict_dependency_pruner.rb +110 -0
  792. data/app/services/collavre/creatives/draft_link_authorization.rb +61 -0
  793. data/app/services/collavre/creatives/draft_link_progress_reconciliation.rb +36 -0
  794. data/app/services/collavre/creatives/drop_trigger_missing_agent_notifier.rb +31 -0
  795. data/app/services/collavre/creatives/expansion_save_order.rb +70 -0
  796. data/app/services/collavre/creatives/file_drop_service.rb +49 -0
  797. data/app/services/collavre/creatives/filter_pipeline.rb +7 -4
  798. data/app/services/collavre/creatives/filter_state.rb +25 -0
  799. data/app/services/collavre/creatives/filters/base_filter.rb +3 -2
  800. data/app/services/collavre/creatives/filters/cron_filter.rb +19 -0
  801. data/app/services/collavre/creatives/filters/reaction_filter.rb +17 -0
  802. data/app/services/collavre/creatives/historical_snapshot_authorization.rb +108 -0
  803. data/app/services/collavre/creatives/history.rb +302 -0
  804. data/app/services/collavre/creatives/history_page.rb +61 -0
  805. data/app/services/collavre/creatives/importer.rb +19 -5
  806. data/app/services/collavre/creatives/index_query.rb +6 -12
  807. data/app/services/collavre/creatives/keep_agent_scope.rb +29 -0
  808. data/app/services/collavre/creatives/origin_chain_preloader.rb +23 -0
  809. data/app/services/collavre/creatives/permission_cache_builder.rb +72 -42
  810. data/app/services/collavre/creatives/permission_checker.rb +51 -4
  811. data/app/services/collavre/creatives/permission_filter.rb +14 -1
  812. data/app/services/collavre/creatives/progress_propagation_targets.rb +36 -0
  813. data/app/services/collavre/creatives/propagated_change_authorization.rb +142 -0
  814. data/app/services/collavre/creatives/reorderer.rb +140 -49
  815. data/app/services/collavre/creatives/snapshot_assignment.rb +25 -0
  816. data/app/services/collavre/creatives/snapshot_comparison.rb +14 -0
  817. data/app/services/collavre/creatives/tree_builder.rb +41 -14
  818. data/app/services/collavre/creatives/tree_formatter.rb +6 -7
  819. data/app/services/collavre/creatives/trigger_action_command.rb +222 -0
  820. data/app/services/collavre/creatives/type_transition.rb +58 -0
  821. data/app/services/collavre/creatives/workspace_expansion_candidates.rb +24 -0
  822. data/app/services/collavre/creatives/workspace_expansion_order.rb +58 -0
  823. data/app/services/collavre/creatives/workspace_expansion_presence.rb +38 -0
  824. data/app/services/collavre/creatives/workspace_path_resolver.rb +50 -0
  825. data/app/services/collavre/creatives/workspace_tree_builder.rb +100 -0
  826. data/app/services/collavre/crons/change_broadcaster.rb +35 -0
  827. data/app/services/collavre/crons/recurring_task_arguments.rb +10 -2
  828. data/app/services/collavre/crons/recurring_task_index.rb +78 -0
  829. data/app/services/collavre/crons/recurring_topic_tasks.rb +23 -0
  830. data/app/services/collavre/decision_questions.rb +125 -0
  831. data/app/services/collavre/home_page_path.rb +55 -0
  832. data/app/services/collavre/html_text.rb +64 -0
  833. data/app/services/collavre/http_client.rb +52 -7
  834. data/app/services/collavre/inbox_reply_service.rb +2 -1
  835. data/app/services/collavre/keep_loop.rb +84 -0
  836. data/app/services/collavre/kollavy/access_scope.rb +84 -0
  837. data/app/services/collavre/kollavy/identity.rb +25 -0
  838. data/app/services/collavre/kollavy.rb +153 -0
  839. data/app/services/collavre/llm_usage/attribution.rb +99 -0
  840. data/app/services/collavre/llm_usage/history_omission.rb +30 -0
  841. data/app/services/collavre/llm_usage/recorder.rb +59 -0
  842. data/app/services/collavre/llm_usage/report.rb +116 -0
  843. data/app/services/collavre/llm_usage/token_normalizer.rb +54 -0
  844. data/app/services/collavre/markdown_converter.rb +45 -29
  845. data/app/services/collavre/mcp_service.rb +61 -35
  846. data/app/services/collavre/mcp_tool_access.rb +40 -0
  847. data/app/services/collavre/mcp_tool_categories.rb +57 -0
  848. data/app/services/collavre/mcp_tool_registrar.rb +217 -0
  849. data/app/services/collavre/mcp_tool_registry.rb +38 -0
  850. data/app/services/collavre/mention_parser.rb +48 -14
  851. data/app/services/collavre/notices/feed.rb +127 -0
  852. data/app/services/collavre/notices/onboarding_replay.rb +17 -0
  853. data/app/services/collavre/notices/refresh_deadline.rb +15 -0
  854. data/app/services/collavre/notices/tracker.rb +68 -0
  855. data/app/services/collavre/openai_endpoint.rb +24 -0
  856. data/app/services/collavre/orchestration/agent_context_builder.rb +3 -1
  857. data/app/services/collavre/orchestration/agent_orchestrator.rb +488 -144
  858. data/app/services/collavre/orchestration/agent_recovery_trigger.rb +16 -0
  859. data/app/services/collavre/orchestration/arbiter.rb +57 -7
  860. data/app/services/collavre/orchestration/deferred_trigger_scope.rb +64 -0
  861. data/app/services/collavre/orchestration/delivery_record.rb +740 -0
  862. data/app/services/collavre/orchestration/dispatch_records.rb +52 -0
  863. data/app/services/collavre/orchestration/execution_fence.rb +97 -0
  864. data/app/services/collavre/orchestration/job_enqueue.rb +150 -0
  865. data/app/services/collavre/orchestration/keep_dispatch_admission.rb +76 -0
  866. data/app/services/collavre/orchestration/keep_dispatch_restoration.rb +57 -0
  867. data/app/services/collavre/orchestration/keep_loop_ownership.rb +152 -0
  868. data/app/services/collavre/orchestration/keep_queued_dispatches.rb +73 -0
  869. data/app/services/collavre/orchestration/loop_breaker.rb +20 -9
  870. data/app/services/collavre/orchestration/matcher.rb +232 -44
  871. data/app/services/collavre/orchestration/offline_task_grace.rb +50 -0
  872. data/app/services/collavre/orchestration/policy_resolver.rb +110 -11
  873. data/app/services/collavre/orchestration/resource_tracker.rb +4 -1
  874. data/app/services/collavre/orchestration/restored_dispatch_admission.rb +103 -0
  875. data/app/services/collavre/orchestration/restored_dispatch_context.rb +15 -0
  876. data/app/services/collavre/orchestration/resume_context.rb +90 -0
  877. data/app/services/collavre/orchestration/scheduler.rb +19 -6
  878. data/app/services/collavre/orchestration/scheduling_hooks.rb +10 -0
  879. data/app/services/collavre/orchestration/selection.rb +76 -0
  880. data/app/services/collavre/orchestration/solid_queue_retry_recovery.rb +54 -0
  881. data/app/services/collavre/orchestration/stuck_detector.rb +25 -112
  882. data/app/services/collavre/orchestration/task_coalescer.rb +385 -0
  883. data/app/services/collavre/orchestration/task_resumer.rb +408 -0
  884. data/app/services/collavre/orchestration/topic_slot.rb +73 -0
  885. data/app/services/collavre/orchestration/waiting_notice_manager.rb +289 -0
  886. data/app/services/collavre/orchestration/workflow_dispatch.rb +47 -0
  887. data/app/services/collavre/orchestration/workflow_routing.rb +96 -0
  888. data/app/services/collavre/ppt_archive.rb +123 -0
  889. data/app/services/collavre/ppt_backgrounds.rb +97 -0
  890. data/app/services/collavre/ppt_colors.rb +104 -0
  891. data/app/services/collavre/ppt_connectors.rb +33 -0
  892. data/app/services/collavre/ppt_diagrams.rb +50 -0
  893. data/app/services/collavre/ppt_formatting.rb +134 -0
  894. data/app/services/collavre/ppt_geometry.rb +92 -0
  895. data/app/services/collavre/ppt_importer.rb +45 -64
  896. data/app/services/collavre/ppt_inheritance.rb +122 -0
  897. data/app/services/collavre/ppt_inline_media.rb +19 -0
  898. data/app/services/collavre/ppt_media.rb +49 -0
  899. data/app/services/collavre/ppt_numbering.rb +63 -0
  900. data/app/services/collavre/ppt_paragraphs.rb +52 -0
  901. data/app/services/collavre/ppt_preview.rb +12 -0
  902. data/app/services/collavre/ppt_renderer.rb +259 -0
  903. data/app/services/collavre/ppt_shape_fills.rb +35 -0
  904. data/app/services/collavre/ppt_shape_styles.rb +81 -0
  905. data/app/services/collavre/ppt_tables.rb +35 -0
  906. data/app/services/collavre/public_asset_allowlist.rb +41 -0
  907. data/app/services/collavre/quota/agent_execution.rb +31 -0
  908. data/app/services/collavre/quota/exceeded_error.rb +48 -0
  909. data/app/services/collavre/quota/notice.rb +15 -0
  910. data/app/services/collavre/quota/pending_dispatch.rb +35 -0
  911. data/app/services/collavre/quota/probe.rb +44 -0
  912. data/app/services/collavre/quota/recovery.rb +97 -0
  913. data/app/services/collavre/quota/retry_time.rb +65 -0
  914. data/app/services/collavre/ruby_llm_interaction_logger.rb +17 -7
  915. data/app/services/collavre/screening/gate.rb +47 -0
  916. data/app/services/collavre/screening/input.rb +30 -0
  917. data/app/services/collavre/screening/scope.rb +34 -0
  918. data/app/services/collavre/screening/screener.rb +57 -0
  919. data/app/services/collavre/screening/screener_resolver.rb +23 -0
  920. data/app/services/collavre/screening/turn_guard.rb +196 -0
  921. data/app/services/collavre/screening/verdict.rb +30 -0
  922. data/app/services/collavre/screening.rb +65 -0
  923. data/app/services/collavre/source_browser.rb +186 -0
  924. data/app/services/collavre/system_events/context_builder.rb +105 -15
  925. data/app/services/collavre/system_events/dispatcher.rb +67 -12
  926. data/app/services/collavre/system_events/envelope.rb +73 -0
  927. data/app/services/collavre/system_events/vocabulary.rb +48 -0
  928. data/app/services/collavre/task_execution_time.rb +33 -0
  929. data/app/services/collavre/tool_approval_policy.rb +42 -0
  930. data/app/services/collavre/tool_description.rb +35 -0
  931. data/app/services/collavre/tool_usage/approved_invocation.rb +28 -0
  932. data/app/services/collavre/tool_usage/cli_proxy_recorder.rb +100 -0
  933. data/app/services/collavre/tool_usage/mcp_call.rb +52 -0
  934. data/app/services/collavre/tool_usage/recorder.rb +34 -0
  935. data/app/services/collavre/tool_usage/report.rb +38 -0
  936. data/app/services/collavre/tools/approval_request_service.rb +54 -0
  937. data/app/services/collavre/tools/async_approval_request.rb +58 -0
  938. data/app/services/collavre/tools/creative_attach_files_service.rb +10 -2
  939. data/app/services/collavre/tools/creative_batch_service.rb +90 -10
  940. data/app/services/collavre/tools/creative_create_service.rb +33 -4
  941. data/app/services/collavre/tools/creative_import_service.rb +26 -3
  942. data/app/services/collavre/tools/creative_link_service.rb +75 -0
  943. data/app/services/collavre/tools/creative_list_attachments_service.rb +2 -2
  944. data/app/services/collavre/tools/creative_remove_attachment_service.rb +30 -5
  945. data/app/services/collavre/tools/creative_reorder_service.rb +111 -0
  946. data/app/services/collavre/tools/creative_retrieval_service.rb +27 -21
  947. data/app/services/collavre/tools/creative_unlink_service.rb +60 -0
  948. data/app/services/collavre/tools/creative_update_service.rb +88 -81
  949. data/app/services/collavre/tools/cron_cancel_service.rb +3 -17
  950. data/app/services/collavre/tools/cron_create_service.rb +101 -32
  951. data/app/services/collavre/tools/cron_list_service.rb +2 -2
  952. data/app/services/collavre/tools/cron_update_service.rb +5 -19
  953. data/app/services/collavre/tools/id_list.rb +38 -0
  954. data/app/services/collavre/tools/keep_service.rb +42 -0
  955. data/app/services/collavre/tools/source_list_service.rb +25 -0
  956. data/app/services/collavre/tools/source_read_service.rb +26 -0
  957. data/app/services/collavre/tools/source_search_service.rb +25 -0
  958. data/app/services/collavre/tools/source_tool_support.rb +39 -0
  959. data/app/services/collavre/tools/task_descendants.rb +32 -0
  960. data/app/services/collavre/tools/task_lineage.rb +46 -0
  961. data/app/services/collavre/tools/task_status_service.rb +61 -0
  962. data/app/services/collavre/tools/task_tracking.rb +67 -0
  963. data/app/services/collavre/tools/topic_authorizer.rb +62 -8
  964. data/app/services/collavre/tools/topic_branch_service.rb +85 -0
  965. data/app/services/collavre/tools/topic_create_service.rb +117 -0
  966. data/app/services/collavre/tools/topic_list_service.rb +101 -0
  967. data/app/services/collavre/tools/topic_message_create_service.rb +210 -0
  968. data/app/services/collavre/tools/topic_messages_service.rb +346 -0
  969. data/app/services/collavre/tools/topic_move_service.rb +107 -0
  970. data/app/services/collavre/tools/topic_selection.rb +59 -0
  971. data/app/services/collavre/tools/topic_tasks_service.rb +42 -0
  972. data/app/services/collavre/tools/topic_update_service.rb +165 -0
  973. data/app/services/collavre/topic_branch_service.rb +40 -10
  974. data/app/services/collavre/topics/active_topic_snapshot.rb +30 -0
  975. data/app/services/collavre/topics/agent_resolver.rb +93 -0
  976. data/app/services/collavre/topics/char_budget.rb +70 -0
  977. data/app/services/collavre/topics/cron_badge_decorator.rb +32 -0
  978. data/app/services/collavre/topics/last_topic_preference_payload.rb +19 -0
  979. data/app/services/collavre/topics/message_page.rb +380 -0
  980. data/app/services/collavre/topics/message_page_markdown.rb +102 -0
  981. data/app/services/collavre/topics/message_scope.rb +61 -0
  982. data/app/services/collavre/topics/message_stats.rb +92 -0
  983. data/app/services/collavre/topics/move_blocker.rb +47 -0
  984. data/app/services/collavre/topics/next_name.rb +35 -0
  985. data/app/services/collavre/topics/orphaned_cron_notifier.rb +33 -14
  986. data/app/services/collavre/topics/pin_rejection.rb +39 -0
  987. data/app/services/collavre/topics/read_pointer_relocator.rb +71 -0
  988. data/app/services/collavre/topics/reserved_name.rb +24 -0
  989. data/app/services/collavre/topics/serializer.rb +99 -0
  990. data/app/services/collavre/topics/topic_destroy.rb +30 -0
  991. data/app/services/collavre/topics/topic_move.rb +99 -0
  992. data/app/services/collavre/topics/topic_move_effects.rb +35 -0
  993. data/app/services/collavre/topics/topic_mutation.rb +27 -0
  994. data/app/services/collavre/trigger_loop_config.rb +15 -0
  995. data/app/services/collavre/workflow/admission.rb +109 -0
  996. data/app/services/collavre/workflow/child_context.rb +35 -0
  997. data/app/services/collavre/workflow/conditions.rb +79 -0
  998. data/app/services/collavre/workflow/context_preloader.rb +48 -0
  999. data/app/services/collavre/workflow/continuation.rb +16 -0
  1000. data/app/services/collavre/workflow/dispatch_identity.rb +25 -0
  1001. data/app/services/collavre/workflow/dispatch_outcome.rb +9 -0
  1002. data/app/services/collavre/workflow/editor.rb +79 -0
  1003. data/app/services/collavre/workflow/envelope_validation.rb +18 -0
  1004. data/app/services/collavre/workflow/fallback_delivery.rb +59 -0
  1005. data/app/services/collavre/workflow/fixed_anchor.rb +32 -0
  1006. data/app/services/collavre/workflow/human_handoff.rb +39 -0
  1007. data/app/services/collavre/workflow/inbox_notice.rb +56 -0
  1008. data/app/services/collavre/workflow/invocation.rb +60 -0
  1009. data/app/services/collavre/workflow/materialization.rb +41 -0
  1010. data/app/services/collavre/workflow/publication.rb +55 -0
  1011. data/app/services/collavre/workflow/push_delivery.rb +97 -0
  1012. data/app/services/collavre/workflow/recovery.rb +62 -0
  1013. data/app/services/collavre/workflow/resolver.rb +83 -0
  1014. data/app/services/collavre/workflow/rule.rb +189 -0
  1015. data/app/services/collavre/workflow/safety.rb +61 -0
  1016. data/app/services/collavre/workflow/settlement.rb +60 -0
  1017. data/app/services/collavre/workflow/source_message.rb +39 -0
  1018. data/app/services/collavre/workflow/task_admission.rb +114 -0
  1019. data/app/views/collavre/admin/integrations/_setting_row.html.erb +5 -8
  1020. data/app/views/collavre/admin/settings/_system_tab.html.erb +56 -11
  1021. data/app/views/collavre/agent_connections/show.html.erb +84 -0
  1022. data/app/views/collavre/agent_gateways/_form.html.erb +85 -0
  1023. data/app/views/collavre/agent_gateways/edit.html.erb +4 -0
  1024. data/app/views/collavre/agent_gateways/index.html.erb +51 -0
  1025. data/app/views/collavre/agent_gateways/new.html.erb +4 -0
  1026. data/app/views/collavre/agent_models/_editor.html.erb +20 -0
  1027. data/app/views/collavre/comments/_activity_log_details.html.erb +10 -4
  1028. data/app/views/collavre/comments/_agent_run_options.html.erb +12 -0
  1029. data/app/views/collavre/comments/_approval_gate.html.erb +8 -0
  1030. data/app/views/collavre/comments/_comment.html.erb +45 -8
  1031. data/app/views/collavre/comments/_comments_popup.html.erb +105 -29
  1032. data/app/views/collavre/comments/_creative_quote_review.html.erb +29 -0
  1033. data/app/views/collavre/comments/_empty_state.html.erb +33 -0
  1034. data/app/views/collavre/comments/_empty_state_minimal.html.erb +7 -0
  1035. data/app/views/collavre/comments/_feature_card.html.erb +35 -0
  1036. data/app/views/collavre/comments/_list.html.erb +3 -2
  1037. data/app/views/collavre/comments/_loading.html.erb +7 -0
  1038. data/app/views/collavre/comments/_no_search_results.html.erb +3 -0
  1039. data/app/views/collavre/comments/_reaction_buttons.html.erb +7 -0
  1040. data/app/views/collavre/comments/_reaction_picker.html.erb +1 -8
  1041. data/app/views/collavre/comments/_run_options.html.erb +4 -0
  1042. data/app/views/collavre/comments/_thinking_icon.html.erb +7 -0
  1043. data/app/views/collavre/creative_change_sets/_detail.html.erb +88 -0
  1044. data/app/views/collavre/creative_change_sets/_list.html.erb +40 -0
  1045. data/app/views/collavre/creative_change_sets/_undo_toast.html.erb +22 -0
  1046. data/app/views/collavre/creatives/_add_button.html.erb +17 -19
  1047. data/app/views/collavre/creatives/_empty_state.html.erb +109 -0
  1048. data/app/views/collavre/creatives/_import_upload_zone.html.erb +1 -1
  1049. data/app/views/collavre/creatives/_inline_edit_form.html.erb +18 -6
  1050. data/app/views/collavre/creatives/_public_meta.html.erb +16 -0
  1051. data/app/views/collavre/creatives/_share_modal.html.erb +9 -0
  1052. data/app/views/collavre/creatives/_tree_loading_placeholder.html.erb +16 -0
  1053. data/app/views/collavre/creatives/_type_selector.html.erb +15 -0
  1054. data/app/views/collavre/creatives/_workflow_panel.html.erb +71 -0
  1055. data/app/views/collavre/creatives/_workspace_tree.html.erb +36 -0
  1056. data/app/views/collavre/creatives/edit.html.erb +7 -4
  1057. data/app/views/collavre/creatives/index.html.erb +149 -25
  1058. data/app/views/collavre/creatives/ppt_previews/_markdown_document.html.erb +17 -0
  1059. data/app/views/collavre/creatives/ppt_previews/show.html.erb +38 -0
  1060. data/app/views/collavre/creatives/show.html.erb +1 -1
  1061. data/app/views/collavre/desktop_setup/show.html.erb +114 -0
  1062. data/app/views/collavre/features/index.html.erb +42 -0
  1063. data/app/views/collavre/features/show.html.erb +52 -0
  1064. data/app/views/collavre/inline_agent_logins/show.html.erb +31 -0
  1065. data/app/views/collavre/invitation_mailer/invite.html.erb +1 -1
  1066. data/app/views/collavre/invitation_mailer/invite.text.erb +1 -1
  1067. data/app/views/collavre/invites/show.html.erb +14 -1
  1068. data/app/views/collavre/landing/show.html.erb +5 -1
  1069. data/app/views/collavre/llm_usages/_metrics.html.erb +13 -0
  1070. data/app/views/collavre/llm_usages/index.html.erb +88 -0
  1071. data/app/views/collavre/notices/_payload.html.erb +5 -0
  1072. data/app/views/collavre/notices/_zone.html.erb +20 -0
  1073. data/app/views/collavre/seo/sitemap.xml.builder +8 -0
  1074. data/app/views/collavre/seo/sitemap_index.xml.builder +8 -0
  1075. data/app/views/collavre/shared/_creative_move_modal.html.erb +59 -0
  1076. data/app/views/collavre/shared/_link_creative_modal.html.erb +6 -1
  1077. data/app/views/collavre/shared/navigation/_help_button.html.erb +22 -1
  1078. data/app/views/collavre/shared/navigation/_panels.html.erb +1 -8
  1079. data/app/views/collavre/shared/navigation/_search_form.html.erb +27 -3
  1080. data/app/views/collavre/user_themes/index.html.erb +1 -1
  1081. data/app/views/collavre/users/_llm_fields.html.erb +60 -0
  1082. data/app/views/collavre/users/_model_picker.html.erb +36 -0
  1083. data/app/views/collavre/users/_org_chart_node.html.erb +1 -1
  1084. data/app/views/collavre/users/_tool_details.html.erb +7 -0
  1085. data/app/views/collavre/users/_tool_selection.html.erb +51 -0
  1086. data/app/views/collavre/users/edit_ai.html.erb +60 -53
  1087. data/app/views/collavre/users/index.html.erb +96 -80
  1088. data/app/views/collavre/users/new.html.erb +4 -2
  1089. data/app/views/collavre/users/new_ai.html.erb +17 -53
  1090. data/app/views/collavre/users/show.html.erb +19 -24
  1091. data/app/views/layouts/collavre/landing.html.erb +23 -4
  1092. data/app/views/layouts/collavre/slide.html.erb +4 -1
  1093. data/config/initializers/active_storage_access.rb +34 -0
  1094. data/config/initializers/agent_health.rb +7 -0
  1095. data/config/initializers/kollavy_feature_card.rb +11 -0
  1096. data/config/initializers/mcp_discovery_access.rb +17 -0
  1097. data/config/initializers/mcp_tool_usage.rb +17 -0
  1098. data/config/initializers/meta_tool_access.rb +35 -0
  1099. data/config/initializers/rate_limits.rb +4 -0
  1100. data/config/initializers/ruby_llm_openai_cli_events.rb +43 -0
  1101. data/config/initializers/ruby_llm_openai_reasoning_content.rb +78 -0
  1102. data/config/initializers/screening_integration_settings.rb +5 -0
  1103. data/config/initializers/task_recovery.rb +30 -0
  1104. data/config/locales/admin.en.yml +21 -3
  1105. data/config/locales/admin.ko.yml +21 -3
  1106. data/config/locales/agent_gateway.en.yml +221 -0
  1107. data/config/locales/agent_gateway.ko.yml +221 -0
  1108. data/config/locales/ai_agent.en.yml +11 -1
  1109. data/config/locales/ai_agent.ko.yml +11 -1
  1110. data/config/locales/approval_gate.en.yml +11 -0
  1111. data/config/locales/approval_gate.ko.yml +11 -0
  1112. data/config/locales/claude_channel.en.yml +1 -0
  1113. data/config/locales/claude_channel.ko.yml +1 -0
  1114. data/config/locales/comments.en.yml +146 -48
  1115. data/config/locales/comments.ko.yml +146 -48
  1116. data/config/locales/contacts.en.yml +0 -5
  1117. data/config/locales/contacts.ko.yml +0 -5
  1118. data/config/locales/contexts.en.yml +6 -0
  1119. data/config/locales/contexts.ko.yml +6 -0
  1120. data/config/locales/creative_history.en.yml +62 -0
  1121. data/config/locales/creative_history.ko.yml +56 -0
  1122. data/config/locales/creative_types.en.yml +19 -0
  1123. data/config/locales/creative_types.ko.yml +19 -0
  1124. data/config/locales/creatives.en.yml +51 -52
  1125. data/config/locales/creatives.ko.yml +49 -45
  1126. data/config/locales/crons.en.yml +16 -0
  1127. data/config/locales/crons.ko.yml +16 -0
  1128. data/config/locales/dnd.en.yml +26 -0
  1129. data/config/locales/dnd.ko.yml +26 -0
  1130. data/config/locales/drop_trigger.en.yml +5 -16
  1131. data/config/locales/drop_trigger.ko.yml +5 -16
  1132. data/config/locales/features.en.yml +155 -0
  1133. data/config/locales/features.ko.yml +155 -0
  1134. data/config/locales/file_drop.en.yml +5 -0
  1135. data/config/locales/file_drop.ko.yml +5 -0
  1136. data/config/locales/inline_agent_login.en.yml +20 -0
  1137. data/config/locales/inline_agent_login.ko.yml +16 -0
  1138. data/config/locales/integrations.en.yml +0 -1
  1139. data/config/locales/integrations.ko.yml +0 -1
  1140. data/config/locales/invites.en.yml +3 -0
  1141. data/config/locales/invites.ko.yml +3 -0
  1142. data/config/locales/keep.en.yml +18 -0
  1143. data/config/locales/keep.ko.yml +18 -0
  1144. data/config/locales/kollavy.en.yml +4 -0
  1145. data/config/locales/kollavy.ko.yml +4 -0
  1146. data/config/locales/landing.en.yml +4 -7
  1147. data/config/locales/landing.ko.yml +4 -7
  1148. data/config/locales/llm_usages.en.yml +45 -0
  1149. data/config/locales/llm_usages.ko.yml +45 -0
  1150. data/config/locales/mcp_tools.en.yml +6 -0
  1151. data/config/locales/mcp_tools.ko.yml +6 -0
  1152. data/config/locales/notices.en.yml +52 -0
  1153. data/config/locales/notices.ko.yml +52 -0
  1154. data/config/locales/orchestration.en.yml +34 -2
  1155. data/config/locales/orchestration.ko.yml +34 -2
  1156. data/config/locales/ppt_viewer.en.yml +18 -0
  1157. data/config/locales/ppt_viewer.ko.yml +18 -0
  1158. data/config/locales/public_creatives.en.yml +6 -0
  1159. data/config/locales/public_creatives.ko.yml +6 -0
  1160. data/config/locales/quota.en.yml +5 -0
  1161. data/config/locales/quota.ko.yml +5 -0
  1162. data/config/locales/screening.en.yml +22 -0
  1163. data/config/locales/screening.ko.yml +22 -0
  1164. data/config/locales/search_popup.en.yml +2 -3
  1165. data/config/locales/search_popup.ko.yml +2 -3
  1166. data/config/locales/task_tracking.en.yml +13 -0
  1167. data/config/locales/task_tracking.ko.yml +13 -0
  1168. data/config/locales/tool_categories.en.yml +14 -0
  1169. data/config/locales/tool_categories.ko.yml +14 -0
  1170. data/config/locales/tool_descriptions.en.yml +163 -0
  1171. data/config/locales/tool_descriptions.ko.yml +163 -0
  1172. data/config/locales/tools.en.yml +46 -0
  1173. data/config/locales/tools.ko.yml +46 -0
  1174. data/config/locales/users.en.yml +33 -36
  1175. data/config/locales/users.ko.yml +32 -35
  1176. data/config/locales/workflow_editor.en.yml +62 -0
  1177. data/config/locales/workflow_editor.ko.yml +62 -0
  1178. data/config/locales/workflow_runtime.en.yml +19 -0
  1179. data/config/locales/workflow_runtime.ko.yml +19 -0
  1180. data/config/routes/account_settings.rb +4 -0
  1181. data/config/routes/agent_api.rb +6 -0
  1182. data/config/routes/agent_connections.rb +24 -0
  1183. data/config/routes/attachments.rb +2 -0
  1184. data/config/routes/comment_actions.rb +10 -0
  1185. data/config/routes/creative_attachments.rb +2 -0
  1186. data/config/routes/creative_contexts.rb +8 -0
  1187. data/config/routes/creative_history.rb +4 -0
  1188. data/config/routes/creative_preferences.rb +3 -0
  1189. data/config/routes/notices.rb +16 -0
  1190. data/config/routes/public_creatives.rb +12 -0
  1191. data/config/routes.rb +35 -38
  1192. data/db/migrate/20250911084338_backfill_creative_in_comment_inbox_items.rb +9 -1
  1193. data/db/migrate/20251204161133_set_default_routing_expression_for_ai_agents.rb +10 -3
  1194. data/db/migrate/20260724000000_add_creative_id_index_to_comments.rb +34 -0
  1195. data/db/migrate/20260724000001_add_creative_private_id_index_to_comments.rb +50 -0
  1196. data/db/migrate/20260724090000_add_async_comment_notification_state.rb +64 -0
  1197. data/db/migrate/20260727000000_add_waiting_notice_scope_to_comments.rb +30 -0
  1198. data/db/migrate/20260727010000_add_waiting_notice_scope_to_tasks.rb +26 -0
  1199. data/db/migrate/20260805000000_add_creative_workspace_enabled_to_users.rb +5 -0
  1200. data/db/migrate/20260807050000_add_dismissed_notices_to_users.rb +5 -0
  1201. data/db/migrate/20260809000000_change_creative_workspace_enabled_default_to_true.rb +18 -0
  1202. data/db/migrate/20260809000001_create_llm_models.rb +64 -0
  1203. data/db/migrate/20260809000002_create_agent_gateways_and_workspaces.rb +35 -0
  1204. data/db/migrate/20260809000003_hash_agent_workspace_callback_tokens.rb +44 -0
  1205. data/db/migrate/20260809000004_encrypt_agent_workspace_manifest_tokens.rb +59 -0
  1206. data/db/migrate/20260810000000_split_agent_workspace_identity_axes.rb +58 -0
  1207. data/db/migrate/20260810000001_seed_codex_custom_proxy_llm_models.rb +28 -0
  1208. data/db/migrate/20260810010000_add_last_visited_creative_to_users.rb +8 -0
  1209. data/db/migrate/20260810020000_add_last_visited_creative_at_to_users.rb +5 -0
  1210. data/db/migrate/20260810030000_add_last_visited_creative_navigation_order_to_users.rb +6 -0
  1211. data/db/migrate/20260810060000_add_last_visited_creative_issued_sequence_to_users.rb +5 -0
  1212. data/db/migrate/20260810100000_add_desktop_managed_to_agent_gateways.rb +40 -0
  1213. data/db/migrate/20260810100001_add_desktop_preset_adapter_to_users.rb +38 -0
  1214. data/db/migrate/20260811000000_make_agent_gateway_completion_key_nullable.rb +7 -0
  1215. data/db/migrate/20260812000000_remove_workflow_columns_from_tasks.rb +101 -0
  1216. data/db/migrate/20260812000001_remove_android_devices.rb +24 -0
  1217. data/db/migrate/20260812010000_drop_inbox_items.rb +22 -0
  1218. data/db/migrate/20260813000000_clear_claude_channel_presence_routing_expressions.rb +16 -0
  1219. data/db/migrate/20260813000001_add_last_topic_revision_to_user_creative_preferences.rb +5 -0
  1220. data/db/migrate/20260813000002_add_last_topic_save_order_to_user_creative_preferences.rb +6 -0
  1221. data/db/migrate/20260813000003_add_last_topic_save_sequences_to_user_creative_preferences.rb +5 -0
  1222. data/db/migrate/20260813000004_add_last_topic_save_fences_to_user_creative_preferences.rb +6 -0
  1223. data/db/migrate/20260814000000_add_topic_to_comment_read_pointers.rb +79 -0
  1224. data/db/migrate/20260814000001_add_creative_topic_private_id_index_to_comments.rb +37 -0
  1225. data/db/migrate/20260816000000_add_watermark_index_to_comment_read_pointers.rb +27 -0
  1226. data/db/migrate/20260816000001_add_private_recipient_topic_index_to_comments.rb +48 -0
  1227. data/db/migrate/20260820000000_add_topic_assigned_at_to_comments.rb +13 -0
  1228. data/db/migrate/20260903070800_add_joined_at_order_index_to_users.rb +23 -0
  1229. data/db/migrate/20260903180000_create_creative_change_history.rb +47 -0
  1230. data/db/migrate/20260903190000_add_system_kind_to_topics.rb +8 -0
  1231. data/db/migrate/20260908000000_add_last_topic_all_messages_to_user_creative_preferences.rb +5 -0
  1232. data/db/migrate/20260910000000_add_health_to_agent_gateways.rb +10 -0
  1233. data/db/migrate/20260911000000_add_endpoint_health_to_users.rb +9 -0
  1234. data/db/migrate/20260911020000_normalize_user_names_to_single_line.rb +32 -0
  1235. data/db/migrate/20260913000000_create_workflow_executions.rb +64 -0
  1236. data/db/migrate/20260913000002_add_ordinary_delivery_to_workflow_outboxes.rb +7 -0
  1237. data/db/migrate/20260913000100_add_reserved_to_workflow_executions.rb +7 -0
  1238. data/db/migrate/20260914063000_add_justify_creative_descriptions_to_users.rb +5 -0
  1239. data/db/migrate/20260922000000_create_llm_usages.rb +44 -0
  1240. data/db/migrate/20260922000001_add_expansion_save_sequences_to_users.rb +5 -0
  1241. data/db/migrate/20260922000002_deduplicate_root_creative_preferences.rb +37 -0
  1242. data/db/migrate/20260922000003_add_agent_quota_recovery.rb +7 -0
  1243. data/db/migrate/20260922000004_add_agent_quota_probe.rb +6 -0
  1244. data/db/migrate/20260922000005_add_suspension_to_tasks.rb +12 -0
  1245. data/db/migrate/20260922010000_create_retired_task_executions.rb +11 -0
  1246. data/db/migrate/20260922113000_add_emoji_comment_index_to_comment_reactions.rb +17 -0
  1247. data/db/migrate/20260922120000_create_tool_usages.rb +37 -0
  1248. data/db/migrate/20260923000000_link_tool_usages_to_agent_workspaces.rb +44 -0
  1249. data/db/migrate/20260924000000_add_agent_run_options.rb +7 -0
  1250. data/db/migrate/20260924010000_add_run_options_to_comment_versions.rb +5 -0
  1251. data/db/migrate/20260924060000_add_async_approval_recovery_to_comments.rb +24 -0
  1252. data/db/migrate/20260924070000_add_async_approval_task_to_comments.rb +22 -0
  1253. data/db/migrate/20260929000000_create_user_notices.rb +14 -0
  1254. data/db/migrate/20260929010000_add_system_agent_to_users.rb +5 -0
  1255. data/db/migrate/20260929120000_add_actor_lookup_index_to_creative_change_sets.rb +19 -0
  1256. data/db/migrate/20261008000000_add_public_id_to_creatives.rb +6 -0
  1257. data/db/migrate/20261008010000_backfill_public_creative_ids.rb +26 -0
  1258. data/db/migrate/20261012000000_create_blob_access_flags.rb +17 -0
  1259. data/db/migrate/20261012000001_publish_landing_public_assets.rb +16 -0
  1260. data/db/migrate/20261014000000_backfill_implicit_main_cron_topics.rb +38 -0
  1261. data/db/migrate/20261016000000_add_trigger_comment_id_to_tasks.rb +21 -0
  1262. data/db/migrate/20261016000001_index_task_event_causation.rb +20 -0
  1263. data/db/migrate/20261016000002_index_task_merged_instructions.rb +25 -0
  1264. data/db/migrate/20261019000000_add_quoted_creative_to_comments.rb +10 -0
  1265. data/db/migrate/20261028000000_add_deleting_at_to_comments.rb +5 -0
  1266. data/db/seeds.rb +4 -70
  1267. data/lib/collavre/bulk_job_enqueue.rb +145 -0
  1268. data/lib/collavre/engine.rb +119 -7
  1269. data/lib/collavre/feature_card_registry.rb +174 -0
  1270. data/lib/collavre/hashed_access_token_lookup.rb +22 -0
  1271. data/lib/collavre/notice_registry.rb +179 -0
  1272. data/lib/collavre/onboarding_notices.rb +107 -0
  1273. data/lib/collavre/profile_preferences.rb +17 -0
  1274. data/lib/collavre/sensitive_request_silencer.rb +23 -0
  1275. data/lib/collavre/stylesheets_helper.rb +72 -0
  1276. data/lib/collavre/user_extensions.rb +0 -2
  1277. data/lib/collavre/version.rb +1 -1
  1278. data/lib/collavre.rb +13 -0
  1279. data/lib/generators/collavre/install/install_generator.rb +50 -8
  1280. data/lib/generators/collavre/install/templates/build.cjs.tt +1 -0
  1281. data/lib/tasks/public_assets.rake +24 -0
  1282. data/skills/collavre/SKILL.md +207 -0
  1283. data/skills/collavre/package.json +8 -0
  1284. data/skills/collavre/references/tool-authoring.md +121 -0
  1285. data/skills/collavre/references/tool-reference.md +445 -0
  1286. data/skills/collavre/scripts/collavre +653 -0
  1287. data/skills/collavre/scripts/html_entities.js +24 -0
  1288. metadata +995 -36
  1289. data/app/controllers/collavre/api/v1/mobile/agent_events_controller.rb +0 -224
  1290. data/app/controllers/collavre/api/v1/mobile/base_controller.rb +0 -95
  1291. data/app/controllers/collavre/api/v1/mobile/devices_controller.rb +0 -31
  1292. data/app/controllers/collavre/api/v1/mobile/voice_commands_controller.rb +0 -25
  1293. data/app/controllers/collavre/inbox_items_controller.rb +0 -70
  1294. data/app/controllers/collavre/typo_corrections_controller.rb +0 -39
  1295. data/app/javascript/lib/__tests__/typo_correction.test.js +0 -192
  1296. data/app/javascript/lib/typo_correction.js +0 -146
  1297. data/app/javascript/modules/__tests__/typo_corrector.test.js +0 -365
  1298. data/app/javascript/modules/creative_guide.js +0 -67
  1299. data/app/javascript/modules/typo_corrector.js +0 -534
  1300. data/app/jobs/collavre/inbox_summary_job.rb +0 -24
  1301. data/app/mailers/collavre/inbox_mailer.rb +0 -19
  1302. data/app/models/collavre/inbox_item.rb +0 -89
  1303. data/app/services/collavre/comments/concerns/workflow_support.rb +0 -115
  1304. data/app/services/collavre/comments/work_command.rb +0 -161
  1305. data/app/services/collavre/comments/workflow_executor.rb +0 -276
  1306. data/app/services/collavre/gemini_parent_recommender.rb +0 -77
  1307. data/app/services/collavre/mobile/event_summarizer.rb +0 -40
  1308. data/app/services/collavre/typo_corrector.rb +0 -188
  1309. data/app/views/collavre/inbox_items/_item.html.erb +0 -18
  1310. data/app/views/collavre/inbox_items/_items.html.erb +0 -3
  1311. data/app/views/collavre/inbox_items/_list.html.erb +0 -7
  1312. data/app/views/collavre/inbox_items/index.html.erb +0 -1
  1313. data/app/views/collavre/inbox_mailer/daily_summary.html.erb +0 -11
  1314. data/app/views/collavre/inbox_mailer/daily_summary.text.erb +0 -8
  1315. data/app/views/collavre/users/typo_correction.html.erb +0 -50
  1316. data/config/locales/mobile.en.yml +0 -16
  1317. data/config/locales/mobile.ko.yml +0 -16
  1318. data/config/locales/notifications.en.yml +0 -8
  1319. data/config/locales/notifications.ko.yml +0 -8
  1320. /data/app/javascript/{utils/drag_bundle_image.js → lib/dnd/bundle_image.js} +0 -0
@@ -0,0 +1,346 @@
1
+ module Collavre
2
+ require "sorbet-runtime"
3
+ require "rails_mcp_engine"
4
+ module Tools
5
+ # Reads a page of messages from one or more topics.
6
+ #
7
+ # Multi-topic in one call, but never interleaved: each topic is windowed and
8
+ # reported on its own. A merged cross-topic timeline would be the wrong answer
9
+ # to the question people actually ask ("summarize #a, #b and #c") — three
10
+ # conversations shuffled by timestamp read as none of them — and it would make
11
+ # offset meaningless, since a merged offset moves when any of the topics grows.
12
+ #
13
+ # Per-topic windows keep offset reproducible, and max_chars keeps the total
14
+ # bounded so asking for three topics cannot return three times the context you
15
+ # planned for.
16
+ class TopicMessagesService
17
+ extend T::Sig
18
+ extend ToolMeta
19
+
20
+ # Roughly a mid-sized page of prose per call. The cap is on the whole
21
+ # response rather than per topic because the caller's context is the shared
22
+ # resource: five topics at a comfortable per-topic size is not a comfortable
23
+ # call.
24
+ DEFAULT_MAX_CHARS = 40_000
25
+ MAX_MAX_CHARS = 200_000
26
+
27
+ # A successful bounded fallback needs enough room to explain why the
28
+ # requested response was omitted. Values below this are raised to the
29
+ # minimum instead of returning a response wider than the cap just to spell
30
+ # out that the cap was too small.
31
+ MIN_MAX_CHARS = 160
32
+
33
+ # Each topic also pays for its own heading, totals line and "More:" call —
34
+ # or, if it does not fit, its not-fetched notice, which is about the same
35
+ # size. Charged separately from the messages so that a call for many topics
36
+ # cannot overrun the cap on section furniture alone.
37
+ #
38
+ # json restates the same section as the seventeen keys of the entry hash
39
+ # plus their delimiters — around 285 characters measured, against the two
40
+ # lines markdown prints — so the reserve is per format rather than one
41
+ # constant that is right for one of them and wrong for the other.
42
+ TOPIC_HEADER_CHARS = { "markdown" => 350, "json" => 525 }.freeze
43
+
44
+ # The trailing "output hit max_chars" notice, which only exists when the
45
+ # budget ran out and so cannot be paid for out of what is left of it.
46
+ TRUNCATION_CHARS = 120
47
+ NOTHING_FITS_REASON = "max_chars is too small to return anything for this topic"
48
+
49
+ tool_name "topic_messages"
50
+ tool_description <<~DESC.strip
51
+ Read messages from one or more Collavre topics, newest first, with paging.
52
+
53
+ Messages are selected from the newest end: offset 0 is the latest message,
54
+ offset 100 starts 100 messages back. Within the returned window they are
55
+ rendered oldest-to-newest by default so the transcript reads forwards
56
+ (pass order: "desc" for newest-first rendering).
57
+
58
+ Multiple topics per call are windowed independently and returned grouped
59
+ by topic — offset/limit apply to EACH topic, never to a merged timeline.
60
+ Use this to summarize several topics at once, e.g.
61
+ topic_messages(topic_ids: "12,45,78", limit: 100).
62
+ Multi-topic calls are first-page reads: each topic returns its own cursor
63
+ and snapshot, so continue each topic in a separate call rather than
64
+ applying one topic's continuation state to the whole batch.
65
+
66
+ Every topic reports total_count and total_chars for the whole topic, so
67
+ you can tell how much you have not read yet, plus has_more, next_offset,
68
+ and next_cursor for the next call. Pass next_cursor and the returned
69
+ newest_message_id back on follow-up pages. The snapshot id excludes newly
70
+ created messages; the cursor also excludes older messages moved into the
71
+ topic later and keeps paging stable when earlier rows leave. It binds a
72
+ clipped continuation to that row's content version, so an edit restarts
73
+ the changed message at character zero rather than applying a stale offset.
74
+
75
+ If one message is too large for the response cap, its row remains at the
76
+ same next_offset and next_content_offset identifies the next character to
77
+ read. Repeat those values with next_cursor and the snapshot id until
78
+ next_content_offset is absent; only then has that message row been
79
+ consumed.
80
+
81
+ Markdown "More:" calls repeat the resolved limit and max_chars as well
82
+ as the cursor, snapshot, order, scope, and content offset, so following
83
+ one keeps the same context budget and paging semantics.
84
+
85
+ Image attachments are appended to message content as explicit markers
86
+ with filename, content type, byte size, and a readable public-asset URL.
87
+ Image-only comments therefore remain visible, and attachment metadata is
88
+ covered by the same max_chars/content_offset continuation as prose.
89
+
90
+ The response is capped at max_chars in total, measured against the format
91
+ you asked for — json is charged for its field names and string escaping,
92
+ so the same call returns fewer messages as json than as markdown. A topic
93
+ that does not fit is returned partially or marked not-fetched rather than
94
+ silently trimmed — check "truncated" and each topic's next_offset. A
95
+ single message wider than the whole cap is clipped rather than dropped,
96
+ given a content continuation and counted in the topic's clipped_count. If
97
+ fixed
98
+ metadata such as a topic name cannot fit, the tool returns a bounded
99
+ error instead of exceeding max_chars or silently omitting a topic.
100
+
101
+ Long topics: call topic_list first to see message_count, then page. To
102
+ summarize a whole large topic, follow next_cursor while keeping
103
+ max_message_id fixed, until has_more is false.
104
+
105
+ Requires read permission on each topic's creative. Private messages you
106
+ cannot see and approval prompts are always excluded; authorless system
107
+ notices are excluded by default (see include_system). Unknown or
108
+ unreadable ids are reported per topic instead of failing the call.
109
+ DESC
110
+
111
+ tool_param :topic_ids, description: "Topic ids to read. Comma-separated for several, e.g. \"12,45,78\" (max #{TopicSelection::MAX_TOPICS} per call — asking for more is an error, not a silent trim). A single id also works."
112
+ tool_param :offset, description: "How many messages back from the newest to start, applied per topic (default: 0).", required: false
113
+ tool_param :cursor, description: "Opaque per-topic snapshot/keyset cursor returned as next_cursor. Pass it on a single-topic follow-up page so later move-ins stay excluded and moved or deleted earlier messages cannot shift and skip unread rows.", required: false
114
+ tool_param :limit, description: "Messages per topic (default: #{Topics::MessagePage::DEFAULT_LIMIT}, max #{Topics::MessagePage::MAX_LIMIT}).", required: false
115
+ tool_param :order, description: "Rendering order within the returned window: 'asc' (default, oldest-to-newest — reads as a transcript) or 'desc' (newest first). Does not change which messages the window selects.", required: false, enum: Topics::MessagePage::ORDERS
116
+ tool_param :max_message_id, description: "Only consider messages with id <= this. Pass the newest_message_id from your first page on every single-topic follow-up page so paging stays on one snapshot of a live topic.", required: false
117
+ tool_param :content_offset, description: "Character offset within the first selected message (default: 0). For a clipped message, make a single-topic follow-up that repeats next_offset and next_cursor, and pass next_content_offset here with the same max_message_id until the whole row has been returned.", required: false
118
+ tool_param :include_system, description: "Include authorless system notices such as concurrency and channel announcements (default: false). Approval prompts are never returned.", required: false
119
+ tool_param :max_chars, description: "Character cap for the whole response across all topics, measured in the format you requested (default: #{DEFAULT_MAX_CHARS}, min #{MIN_MAX_CHARS}, max #{MAX_MAX_CHARS}). Values below the minimum are raised to it.", required: false
120
+ tool_param :format, description: "'markdown' (default, compact transcript) or 'json' (same data, structured; costs noticeably more of max_chars for the same messages, since field names and string escaping are charged too).", required: false, enum: Topics::CharBudget::FORMATS
121
+
122
+ sig do
123
+ params(
124
+ topic_ids: T.any(String, Integer, T::Array[T.untyped]),
125
+ options: T.untyped
126
+ ).returns(T.any(String, T::Hash[Symbol, T.untyped]))
127
+ end
128
+ def call(topic_ids:, **options)
129
+ options.assert_valid_keys(
130
+ :offset, :limit, :order, :cursor, :max_message_id, :content_offset, :include_system, :max_chars, :format
131
+ )
132
+ user = Current.user || raise("Current.user is required")
133
+ ids = IdList.parse(topic_ids)
134
+ raise ArgumentError, "topic_ids is required" if ids.empty?
135
+ reject_batch_continuation!(ids, options)
136
+
137
+ # The cap and the format it counts in are resolved together and carried
138
+ # through as one object, because what a message costs is what emitting it
139
+ # in this format costs. Budgeting in markdown's units and then returning
140
+ # json is how a 40k cap emits 60k.
141
+ budget = Topics::CharBudget.new(chars: clamp_chars(options[:max_chars]), format: options[:format])
142
+
143
+ payload = build_payload(
144
+ ids: ids, user: user,
145
+ options: page_options(options, budget)
146
+ )
147
+
148
+ response = budget.json? ? payload : Topics::MessagePageMarkdown.call(payload)
149
+ enforce_cap(response, budget)
150
+ end
151
+
152
+ private
153
+
154
+ def reject_batch_continuation!(ids, options)
155
+ return if ids.one?
156
+ return unless options[:cursor].present? || options[:max_message_id].present? ||
157
+ options[:content_offset].to_i.positive?
158
+
159
+ raise ArgumentError,
160
+ "cursor, max_message_id, and content_offset continuation values belong to one topic; " \
161
+ "continue each topic in a separate topic_messages call."
162
+ end
163
+
164
+ def page_options(options, budget)
165
+ {
166
+ offset: options.fetch(:offset, 0).to_i,
167
+ cursor: options[:cursor],
168
+ limit: options[:limit],
169
+ order: options[:order],
170
+ max_message_id: options[:max_message_id],
171
+ content_offset: options.fetch(:content_offset, 0).to_i,
172
+ include_system: options.fetch(:include_system, false),
173
+ budget: budget
174
+ }
175
+ end
176
+
177
+ def build_payload(ids:, user:, options:)
178
+ topics, errors = TopicSelection.resolve(ids, user: user)
179
+ entries = collect(topics, errors, user, options)
180
+
181
+ {
182
+ topics: entries + errors,
183
+ truncated: entries.any? { |entry| entry[:skipped_reason] || entry[:budget_limited] || entry[:clipped_count] },
184
+ max_chars: options[:budget].chars
185
+ }
186
+ end
187
+
188
+ # Topics are served in request order and the budget is spent as it goes, so
189
+ # an early huge topic can leave later ones unfetched. That is reported per
190
+ # topic rather than smoothed over: the caller asked for a specific order and
191
+ # needs to know which of its topics it is still missing.
192
+ #
193
+ # What is charged is what is emitted — message envelopes as well as prose.
194
+ # Counting content alone let a few hundred one-word messages print their
195
+ # ids, timestamps and authors for free and sail past the cap.
196
+ #
197
+ # Every requested topic prints a section whether or not it fits, so all the
198
+ # headers are reserved before any topic spends on messages. Reserving them
199
+ # one at a time would charge only the topics that succeed, and the
200
+ # not-fetched notices — which exist precisely because the budget ran out —
201
+ # would push the response over the cap that skipping them was enforcing.
202
+ def collect(topics, errors, user, options)
203
+ budget = options[:budget]
204
+ remaining = budget.chars - reserved_chars(topics, errors, budget.format)
205
+ served = false
206
+
207
+ topics.map do |topic|
208
+ next not_fetched(topic, options[:offset], options[:content_offset], options[:cursor], served) if remaining <= 0
209
+
210
+ entry = page_entry(topic, user, options, remaining)
211
+ remaining -= entry[:billed_chars].to_i
212
+ served = true
213
+ entry
214
+ end
215
+ end
216
+
217
+ def reserved_chars(topics, errors, format)
218
+ per_topic = TOPIC_HEADER_CHARS.fetch(format)
219
+ TRUNCATION_CHARS + topics.sum { |topic| per_topic + topic.name.to_s.length } +
220
+ error_chars(errors, format)
221
+ end
222
+
223
+ def error_chars(errors, format)
224
+ return errors.sum { |error| error.to_json.length + 1 } if format == "json"
225
+
226
+ errors.sum { |error| Topics::MessagePageMarkdown.render_error(error).length + 1 }
227
+ end
228
+
229
+ def page_entry(topic, user, options, remaining)
230
+ page = Topics::MessagePage.new(
231
+ topic: topic, user: user,
232
+ offset: options[:offset], limit: options[:limit], order: options[:order] || Topics::MessagePage::DEFAULT_ORDER,
233
+ include_system: options[:include_system], max_message_id: options[:max_message_id],
234
+ content_offset: options[:content_offset], cursor: options[:cursor],
235
+ budget: options[:budget].with(chars: remaining)
236
+ ).call
237
+
238
+ serialize(page, include_system: options[:include_system], max_chars: options[:budget].chars)
239
+ end
240
+
241
+ def serialize(page, include_system:, max_chars:)
242
+ {
243
+ topic_id: page.topic.id,
244
+ topic_name: page.topic.name,
245
+ creative_id: page.topic.creative_id,
246
+ total_count: page.total_count,
247
+ total_chars: page.total_chars,
248
+ offset: page.offset,
249
+ limit: page.limit,
250
+ max_chars: max_chars,
251
+ order: page.order,
252
+ returned_count: page.returned_count,
253
+ returned_chars: page.returned_chars,
254
+ # What this topic charged against max_chars: what emitting these
255
+ # messages in the requested format costs, not what their prose measures.
256
+ billed_chars: page.billed_chars,
257
+ has_more: page.has_more?,
258
+ next_offset: page.next_offset,
259
+ next_cursor: page.next_cursor,
260
+ next_content_offset: page.next_content_offset,
261
+ newest_message_id: page.newest_message_id,
262
+ # Echoed so the rendered "More:" line can repeat it. A continuation
263
+ # that drops it pages a narrower set at the same offset and skips
264
+ # whatever the wider first page had already counted.
265
+ include_system: (true if include_system),
266
+ # Only present when the shared max_chars budget, rather than `limit`,
267
+ # is what ended this topic's window — the caller's fix differs: raise
268
+ # max_chars or ask for fewer topics, not just page again.
269
+ budget_limited: page.budget_exhausted.presence,
270
+ # Present only when max_chars cut a message short rather than cutting
271
+ # the window between rows. next_content_offset resumes the same row.
272
+ clipped_count: page.clipped_count.nonzero?,
273
+ skipped_reason: nothing_fits_reason(page),
274
+ messages: page.messages
275
+ }.compact
276
+ end
277
+
278
+ def nothing_fits_reason(page)
279
+ NOTHING_FITS_REASON if page.returned_count.zero? && page.budget_exhausted
280
+ end
281
+
282
+ # Carries has_more/next_offset so the caller can resume this topic without
283
+ # having to work out that "no messages" here means "not read yet" rather
284
+ # than "empty topic".
285
+ #
286
+ # The reason distinguishes the two ways to run out of room, because the
287
+ # fixes differ: drop topics from the call, or raise the cap. Blaming
288
+ # "earlier topics" when this was the first one sends the caller the wrong way.
289
+ def not_fetched(topic, offset, content_offset, cursor, served)
290
+ reason = if served
291
+ "max_chars budget spent on earlier topics"
292
+ else
293
+ NOTHING_FITS_REASON
294
+ end
295
+
296
+ {
297
+ topic_id: topic.id,
298
+ topic_name: topic.name,
299
+ creative_id: topic.creative_id,
300
+ offset: offset,
301
+ next_content_offset: content_offset.presence,
302
+ returned_count: 0,
303
+ returned_chars: 0,
304
+ billed_chars: 0,
305
+ has_more: true,
306
+ next_offset: offset,
307
+ next_cursor: cursor.presence,
308
+ skipped_reason: reason,
309
+ messages: []
310
+ }
311
+ end
312
+
313
+ def clamp_chars(max_chars)
314
+ value = max_chars.to_i
315
+ return DEFAULT_MAX_CHARS if value <= 0
316
+
317
+ value.clamp(MIN_MAX_CHARS, MAX_MAX_CHARS)
318
+ end
319
+
320
+ # Message budgeting normally keeps the rendered response below max_chars,
321
+ # but fixed metadata can be wider than its budget by itself: a tiny cap, a
322
+ # batch of skipped topics, or one unrestricted topic name is enough. The
323
+ # final emitted form is the only authoritative measurement, so replace an
324
+ # oversized result with a bounded error instead of silently chopping a
325
+ # topic name or returning malformed JSON/Markdown.
326
+ def enforce_cap(response, budget)
327
+ emitted_chars = budget.json? ? response.to_json.length : response.length
328
+ return response if emitted_chars <= budget.chars
329
+
330
+ bounded_error(budget, required_chars: emitted_chars)
331
+ end
332
+
333
+ def bounded_error(budget, required_chars:)
334
+ return {
335
+ error: "topic_messages metadata exceeds max_chars",
336
+ required_chars: required_chars,
337
+ max_chars: budget.chars,
338
+ truncated: true
339
+ } if budget.json?
340
+
341
+ "> topic_messages metadata needs #{required_chars} chars; max_chars is #{budget.chars}. " \
342
+ "Request fewer topics or raise max_chars.\n"
343
+ end
344
+ end
345
+ end
346
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Collavre
4
+ require "sorbet-runtime"
5
+ require "rails_mcp_engine"
6
+ module Tools
7
+ # Moves one complete topic to another creative using the same relocation
8
+ # primitive as the drag-and-drop UI.
9
+ class TopicMoveService
10
+ extend T::Sig
11
+ extend ToolMeta
12
+
13
+ tool_name "topic_move"
14
+ tool_description <<~DESC.strip
15
+ Move a complete topic to another creative while keeping its topic id,
16
+ messages, archive state, and read cursors.
17
+
18
+ The primary-agent pin moves too when that agent can still respond on the
19
+ destination. Otherwise the pin is released and the result explains why,
20
+ so the moved topic remains routable. Creative permissions do not move:
21
+ people who could read the source may lose access at the destination.
22
+
23
+ Requires admin permission on the topic's current creative and write
24
+ permission on the destination. The destination id may be a linked
25
+ creative; the topic moves to its origin. Topic names are unique per
26
+ creative. Main, an inbox's System topic, and live agent session topics
27
+ cannot be moved. Wait for or cancel active agent work before moving its
28
+ topic, and wait for any dropped-message restoration to settle. Cancel
29
+ recurring cron jobs targeting the topic and recreate them after the move.
30
+ A topic referenced by a Drop Trigger loop cannot move.
31
+ DESC
32
+
33
+ tool_param :topic_id, description: "The topic to move."
34
+ tool_param :creative_id, description: "The destination creative. Linked creatives resolve to their origin."
35
+
36
+ sig { params(topic_id: Integer, creative_id: Integer).returns(T::Hash[Symbol, T.untyped]) }
37
+ def call(topic_id:, creative_id:)
38
+ user = Current.user || raise(I18n.t("collavre.tools.topic_move.errors.current_user_required"))
39
+ topic = Topic.find(topic_id)
40
+ authorize_source!(topic, user)
41
+ target = Creative.find(creative_id).effective_origin
42
+ authorize_target!(target, user)
43
+ source = topic.creative.effective_origin
44
+
45
+ released_agent, released_reason = move(topic, target, source, user)
46
+
47
+ Topics::Serializer.for_tool(topic).merge(
48
+ moved_from_creative_id: source.id,
49
+ released_primary_agent: released_agent_payload(released_agent, released_reason, target)
50
+ ).compact
51
+ end
52
+
53
+ private
54
+
55
+ def move(topic, target, source, user)
56
+ effects = Topics::TopicMoveEffects.new(topic, source, target)
57
+ Topics::TopicMove.new(topic: topic, target_creative: target).call(after_commit: effects.method(:call)) do |locked_topic|
58
+ authorize_source!(locked_topic, user)
59
+ authorize_target!(target, user)
60
+ validate_move!(locked_topic, target)
61
+ end
62
+ end
63
+
64
+ def authorize_source!(topic, user)
65
+ TopicAuthorizer.authorize_admin!(topic, user: user)
66
+ rescue PermissionDeniedError
67
+ raise PermissionDeniedError, I18n.t("collavre.tools.topic_move.errors.source_permission")
68
+ end
69
+
70
+ def authorize_target!(target, user)
71
+ TopicAuthorizer.authorize_creative!(target, :write, user: user)
72
+ rescue PermissionDeniedError
73
+ raise PermissionDeniedError, I18n.t("collavre.tools.topic_move.errors.target_permission")
74
+ end
75
+
76
+ def validate_move!(topic, target)
77
+ raise ArgumentError, I18n.t("collavre.tools.topic_move.errors.same_creative") if topic.creative_id == target.id
78
+ raise ArgumentError, I18n.t("collavre.tools.topic_move.errors.reserved_topic") if reserved?(topic, target)
79
+ raise ArgumentError, I18n.t("collavre.tools.topic_move.errors.session_topic") if topic.session_id.present?
80
+ return unless target.topics.where(name: topic.name).exists?
81
+
82
+ raise ArgumentError, I18n.t("collavre.tools.topic_move.errors.duplicate_name", name: topic.name)
83
+ end
84
+
85
+ def reserved?(topic, target)
86
+ Topics::ReservedName.reserved_topic?(topic.creative, topic) ||
87
+ (target.inbox? && topic.name == Creative::SYSTEM_TOPIC_NAME)
88
+ end
89
+
90
+ def released_agent_payload(agent, reason, target)
91
+ return unless agent
92
+
93
+ {
94
+ id: agent.id,
95
+ name: agent.display_name,
96
+ reason: reason.to_s,
97
+ message: released_agent_message(agent, reason, target)
98
+ }
99
+ end
100
+
101
+ def released_agent_message(agent, reason, target)
102
+ key = Topics::PinRejection.release_locale_key(reason)
103
+ I18n.t("collavre.topics.move.#{key}", agent: agent.display_name, creative: target.creative_snippet)
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Collavre
4
+ module Tools
5
+ # Turns the `topic_ids` parameter of the read tools into topics, and reports
6
+ # the ones it could not turn into topics instead of raising.
7
+ #
8
+ # A caller asking about three topics has usually copied the ids out of a
9
+ # conversation, so one of them being stale or unshared is ordinary. Failing
10
+ # the whole call there would throw away the two that worked and give no way
11
+ # to tell which id was the bad one.
12
+ module TopicSelection
13
+ # A ceiling on topics per call, not on messages — that is max_chars' job.
14
+ # This one exists because each topic costs a header, a totals query and a
15
+ # window query, and a caller that pastes forty ids has stopped planning
16
+ # and started dumping.
17
+ MAX_TOPICS = 20
18
+
19
+ module_function
20
+
21
+ # Returns [topics, errors], preserving the caller's id order so a numbered
22
+ # request reads back in the order it was asked.
23
+ def resolve(ids, user: Collavre::Current.user)
24
+ enforce_cap!(ids)
25
+ by_id = Topic.where(id: ids).index_by(&:id)
26
+
27
+ ids.each_with_object([ [], [] ]) do |id, (topics, errors)|
28
+ error = rejection_for(by_id[id], user)
29
+ error ? errors << { topic_id: id, error: error } : topics << by_id[id]
30
+ end
31
+ end
32
+
33
+ # An oversized batch is an error, not a trim. Silently keeping the first
34
+ # twenty returns a response that looks complete — every topic asked for
35
+ # that appears, appears in full — while whole conversations are missing
36
+ # with nothing in the payload that says so, and a caller summarizing
37
+ # "all of these" would report on a subset believing it had them all.
38
+ # Unreadable ids are still reported per topic rather than raised: those
39
+ # the caller can see and act on, one entry each.
40
+ def enforce_cap!(ids)
41
+ return if ids.size <= MAX_TOPICS
42
+
43
+ raise ArgumentError,
44
+ "#{ids.size} topics requested but at most #{MAX_TOPICS} can be read per call. " \
45
+ "Split the ids across several calls."
46
+ end
47
+
48
+ # Deliberately the same message for missing and unreadable. Distinguishing
49
+ # them would let a caller probe which topic ids exist on creatives they
50
+ # cannot see.
51
+ def rejection_for(topic, user)
52
+ return "Topic not found or not readable" if topic.nil?
53
+ return nil if TopicAuthorizer.readable?(topic, user: user)
54
+
55
+ "Topic not found or not readable"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sorbet-runtime"
4
+ require "rails_mcp_engine"
5
+
6
+ module Collavre
7
+ module Tools
8
+ class TopicTasksService
9
+ extend T::Sig
10
+ extend ToolMeta
11
+
12
+ tool_name "topic_tasks"
13
+ tool_description "List tasks in a readable topic, newest first. Active uses the same statuses as Stop. Finished includes unsuccessful endings. Reply summaries respect private-message visibility. A done task means a turn ended, not that the requested outcome was verified."
14
+ tool_param :topic_id, description: "Topic to inspect."
15
+ tool_param :status, description: "active (default), finished, or all.", required: false
16
+ tool_param :limit, description: "Maximum tasks, 1 to 100 (default 20).", required: false
17
+
18
+ sig { params(topic_id: Integer, status: String, limit: Integer).returns(T::Hash[Symbol, T.untyped]) }
19
+ def call(topic_id:, status: "active", limit: 20)
20
+ user = TaskTracking.user!
21
+ TaskTracking.invalid!(:invalid_status) unless %w[active finished all].include?(status)
22
+ TaskTracking.invalid!(:invalid_limit) unless (1..100).cover?(limit)
23
+ topic = Topic.find(topic_id)
24
+ TopicAuthorizer.authorize_read!(topic, user: user)
25
+ scope = Task.where(topic_id: topic.id, creative_id: topic.creative_id).includes(:agent)
26
+ scope = filter(scope, status)
27
+ tasks = TaskTracking.visible_tasks(scope, user, creative_id: topic.creative_id).order(created_at: :desc, id: :desc).limit(limit + 1).to_a
28
+ { topic_id: topic.id, tasks: TaskTracking.describe_all(tasks.first(limit), user),
29
+ has_more: tasks.size > limit }
30
+ end
31
+
32
+ private
33
+
34
+ def filter(scope, status)
35
+ return scope.where(status: Task::ACTIVE_STATUSES) if status == "active"
36
+ return scope.where.not(status: Task::ACTIVE_STATUSES) if status == "finished"
37
+
38
+ scope
39
+ end
40
+ end
41
+ end
42
+ end