collavre 0.25.0 → 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 (1103) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -10
  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 +512 -87
  11. data/app/assets/stylesheets/collavre/creatives.css +827 -126
  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 +0 -5
  15. data/app/assets/stylesheets/collavre/image_lightbox.css +12 -0
  16. data/app/assets/stylesheets/collavre/landing.css +23 -104
  17. data/app/assets/stylesheets/collavre/llm_usages.css +67 -0
  18. data/app/assets/stylesheets/collavre/mention_menu.css +18 -0
  19. data/app/assets/stylesheets/collavre/modal_dialog.css +66 -3
  20. data/app/assets/stylesheets/collavre/notice_bar.css +465 -0
  21. data/app/assets/stylesheets/collavre/org_chart.css +0 -4
  22. data/app/assets/stylesheets/collavre/popup.css +15 -18
  23. data/app/assets/stylesheets/collavre/search_popup.css +0 -34
  24. data/app/assets/stylesheets/collavre/slide_view.css +221 -4
  25. data/app/assets/stylesheets/collavre/workflow_editor.css +101 -0
  26. data/app/assets/stylesheets/collavre/workspace.css +13 -10
  27. data/app/channels/collavre/agent_channel.rb +48 -23
  28. data/app/components/collavre/command_menu_component.html.erb +5 -0
  29. data/app/components/collavre/command_menu_component.rb +8 -0
  30. data/app/components/collavre/comment_user_menu_component.html.erb +61 -0
  31. data/app/components/collavre/comment_user_menu_component.rb +14 -0
  32. data/app/components/collavre/cron_badge_component.html.erb +80 -0
  33. data/app/components/collavre/cron_badge_component.rb +50 -0
  34. data/app/controllers/collavre/admin/orchestration_controller.rb +59 -32
  35. data/app/controllers/collavre/admin/settings_controller.rb +77 -8
  36. data/app/controllers/collavre/agent_connections_controller.rb +9 -21
  37. data/app/controllers/collavre/agent_models_controller.rb +55 -0
  38. data/app/controllers/collavre/agent_provisioning_controller.rb +31 -22
  39. data/app/controllers/collavre/api/v1/agents_controller.rb +47 -163
  40. data/app/controllers/collavre/api/v1/task_suspensions_controller.rb +60 -0
  41. data/app/controllers/collavre/attachments_controller.rb +12 -12
  42. data/app/controllers/collavre/comments/activity_logs_controller.rb +2 -0
  43. data/app/controllers/collavre/comments/reactions_controller.rb +10 -12
  44. data/app/controllers/collavre/comments/resends_controller.rb +21 -0
  45. data/app/controllers/collavre/comments/versions_controller.rb +24 -21
  46. data/app/controllers/collavre/comments_controller.rb +61 -10
  47. data/app/controllers/collavre/concerns/creative_history_trackable.rb +31 -0
  48. data/app/controllers/collavre/concerns/tree_manageable.rb +4 -0
  49. data/app/controllers/collavre/creative_change_sets_controller.rb +112 -0
  50. data/app/controllers/collavre/creative_imports_controller.rb +9 -1
  51. data/app/controllers/collavre/creative_invitations_controller.rb +2 -11
  52. data/app/controllers/collavre/creative_shares_controller.rb +7 -15
  53. data/app/controllers/collavre/creatives/attachments_controller.rb +16 -4
  54. data/app/controllers/collavre/creatives/file_drops_controller.rb +35 -0
  55. data/app/controllers/collavre/creatives/ppt_previews_controller.rb +66 -0
  56. data/app/controllers/collavre/creatives_controller.rb +49 -272
  57. data/app/controllers/collavre/crons_controller.rb +48 -0
  58. data/app/controllers/collavre/desktop_gateway_registrations_controller.rb +2 -19
  59. data/app/controllers/collavre/desktop_setup_controller.rb +2 -19
  60. data/app/controllers/collavre/desktop_sidecar_health_controller.rb +2 -14
  61. data/app/controllers/collavre/google_auth_controller.rb +3 -4
  62. data/app/controllers/collavre/inline_agent_logins_controller.rb +79 -0
  63. data/app/controllers/collavre/llm_usages_controller.rb +51 -0
  64. data/app/controllers/collavre/onboarding_replays_controller.rb +10 -0
  65. data/app/controllers/collavre/public_assets_controller.rb +48 -4
  66. data/app/controllers/collavre/seo_controller.rb +83 -0
  67. data/app/controllers/collavre/sessions_controller.rb +5 -9
  68. data/app/controllers/collavre/topics_controller.rb +17 -32
  69. data/app/controllers/collavre/user_creative_preferences_controller.rb +26 -59
  70. data/app/controllers/collavre/user_notices_controller.rb +64 -0
  71. data/app/controllers/collavre/user_themes_controller.rb +11 -7
  72. data/app/controllers/collavre/users_controller.rb +1 -0
  73. data/app/controllers/concerns/collavre/active_storage_access.rb +127 -0
  74. data/app/controllers/concerns/collavre/api/claude_channel_prompts.rb +209 -0
  75. data/app/controllers/concerns/collavre/blob_access_control.rb +57 -0
  76. data/app/controllers/concerns/collavre/comments/approval_actions.rb +24 -22
  77. data/app/controllers/concerns/collavre/comments/approval_gate_actions.rb +29 -0
  78. data/app/controllers/concerns/collavre/comments/batch_operations.rb +1 -1
  79. data/app/controllers/concerns/collavre/comments/comment_scoping.rb +4 -2
  80. data/app/controllers/concerns/collavre/comments/history_topic_guard.rb +22 -0
  81. data/app/controllers/concerns/collavre/creative_destroyable.rb +41 -0
  82. data/app/controllers/concerns/collavre/creative_permission_guard.rb +6 -0
  83. data/app/controllers/concerns/collavre/creative_type_editable.rb +76 -0
  84. data/app/controllers/concerns/collavre/loopback_request.rb +32 -0
  85. data/app/controllers/concerns/collavre/origin_verification.rb +29 -0
  86. data/app/controllers/concerns/collavre/permission_update_response.rb +23 -0
  87. data/app/controllers/concerns/collavre/proxy_error_response.rb +14 -0
  88. data/app/controllers/concerns/collavre/public_creative_page.rb +52 -0
  89. data/app/controllers/concerns/collavre/public_creative_redirectable.rb +31 -0
  90. data/app/controllers/concerns/collavre/successful_authentication.rb +12 -0
  91. data/app/controllers/concerns/collavre/svg_streaming.rb +39 -0
  92. data/app/controllers/concerns/collavre/topics/reserved_topic_guard.rb +52 -0
  93. data/app/controllers/concerns/collavre/user_creative_preferences_controller/persistence.rb +98 -0
  94. data/app/controllers/concerns/collavre/users_controller/admin_operations.rb +38 -12
  95. data/app/controllers/concerns/collavre/users_controller/ai_profile_access.rb +25 -0
  96. data/app/controllers/concerns/collavre/users_controller/ai_user_management.rb +80 -40
  97. data/app/controllers/concerns/collavre/users_controller/contact_management.rb +31 -18
  98. data/app/controllers/concerns/collavre/users_controller/profile_and_settings.rb +15 -1
  99. data/app/controllers/concerns/collavre/users_controller/registration.rb +7 -11
  100. data/app/controllers/concerns/collavre/workflow_editable.rb +112 -0
  101. data/app/errors/collavre/approval_gate_pending_error.rb +12 -0
  102. data/app/errors/collavre/approval_pending_error.rb +5 -2
  103. data/app/errors/collavre/screening_pending_error.rb +17 -0
  104. data/app/errors/collavre/task_suspended_error.rb +11 -0
  105. data/app/helpers/collavre/activity_logs_helper.rb +26 -0
  106. data/app/helpers/collavre/application_helper.rb +10 -44
  107. data/app/helpers/collavre/creative_move_helper.rb +15 -0
  108. data/app/helpers/collavre/creatives_helper.rb +117 -65
  109. data/app/helpers/collavre/navigation_helper.rb +122 -0
  110. data/app/helpers/collavre/public_assets_helper.rb +14 -0
  111. data/app/helpers/collavre/public_creatives_helper.rb +44 -0
  112. data/app/javascript/__tests__/slide_view.test.js +30 -0
  113. data/app/javascript/collavre.js +3 -0
  114. data/app/javascript/collavre_pdf_viewer.js +3 -0
  115. data/app/javascript/collavre_pdf_worker.js +1 -0
  116. data/app/javascript/comments/__tests__/user_menu.test.js +137 -0
  117. data/app/javascript/comments/user_menu.js +205 -0
  118. data/app/javascript/components/EmojiPicker.js +90 -0
  119. data/app/javascript/components/HeadingButtons.js +45 -0
  120. data/app/javascript/components/HistoryButtons.jsx +26 -0
  121. data/app/javascript/components/ImageResizer.jsx +11 -30
  122. data/app/javascript/components/InlineLexicalEditor.jsx +19 -77
  123. data/app/javascript/components/__tests__/EmojiPicker.test.js +127 -0
  124. data/app/javascript/components/__tests__/HeadingButtons.test.js +111 -0
  125. data/app/javascript/components/__tests__/creative_tree_row_document_view.test.js +814 -0
  126. data/app/javascript/components/__tests__/creative_tree_row_progress_toggle.test.js +72 -2
  127. data/app/javascript/components/__tests__/document_row_swipe.test.js +206 -0
  128. data/app/javascript/components/creative_header_progress.js +24 -0
  129. data/app/javascript/components/creative_tree_row.js +39 -82
  130. data/app/javascript/components/creative_tree_row_document_view.js +251 -0
  131. data/app/javascript/components/document_row_swipe.js +107 -0
  132. data/app/javascript/components/plugins/__tests__/creative_links_plugin.test.js +59 -0
  133. data/app/javascript/components/plugins/__tests__/image_upload_plugin.test.js +107 -0
  134. data/app/javascript/components/plugins/creative_links_plugin.js +24 -0
  135. data/app/javascript/components/plugins/image_upload_plugin.jsx +24 -28
  136. data/app/javascript/components/plugins/markdown_shortcuts_plugin.jsx +5 -2
  137. data/app/javascript/controllers/__tests__/agent_connection_controller.test.js +433 -3
  138. data/app/javascript/controllers/__tests__/agent_vendor_controller.test.js +94 -0
  139. data/app/javascript/controllers/__tests__/comment_agent_model_controller.test.js +148 -0
  140. data/app/javascript/controllers/__tests__/comment_approval_controls.test.js +45 -0
  141. data/app/javascript/controllers/__tests__/comment_user_menu_controller.test.js +285 -0
  142. data/app/javascript/controllers/__tests__/comment_version_controller.test.js +51 -0
  143. data/app/javascript/controllers/__tests__/controller_csrf_requests.test.js +137 -0
  144. data/app/javascript/controllers/__tests__/creative_history_controller.test.js +123 -0
  145. data/app/javascript/controllers/__tests__/creative_history_detail_controller.test.js +104 -0
  146. data/app/javascript/controllers/__tests__/creative_history_undo_controller.test.js +55 -0
  147. data/app/javascript/controllers/__tests__/creative_image_lightbox_controller.test.js +583 -0
  148. data/app/javascript/controllers/__tests__/creative_move_controller.test.js +713 -0
  149. data/app/javascript/controllers/__tests__/cron_badge_controller.test.js +436 -0
  150. data/app/javascript/controllers/__tests__/document_preview_controller.test.js +33 -0
  151. data/app/javascript/controllers/__tests__/entity_list_controller.test.js +270 -0
  152. data/app/javascript/controllers/__tests__/expansion_controller.test.js +235 -0
  153. data/app/javascript/controllers/__tests__/index.test.js +6 -0
  154. data/app/javascript/controllers/__tests__/inline_creative_picker_controller.test.js +232 -0
  155. data/app/javascript/controllers/__tests__/link_creative_controller.test.js +101 -0
  156. data/app/javascript/controllers/__tests__/notice_bar_controller.test.js +1076 -0
  157. data/app/javascript/controllers/__tests__/popup_menu_controller.test.js +267 -0
  158. data/app/javascript/controllers/__tests__/search_popup_controller.test.js +46 -32
  159. data/app/javascript/controllers/__tests__/share_modal_public_link.test.js +113 -0
  160. data/app/javascript/controllers/__tests__/share_user_search_controller.test.js +17 -0
  161. data/app/javascript/controllers/__tests__/tabs_controller.test.js +137 -0
  162. data/app/javascript/controllers/__tests__/tool_category_controller.test.js +116 -0
  163. data/app/javascript/controllers/__tests__/topic_list_controller.test.js +14 -0
  164. data/app/javascript/controllers/__tests__/workspace_tree_controller.test.js +757 -22
  165. data/app/javascript/controllers/agent_auth_controller.js +245 -0
  166. data/app/javascript/controllers/agent_connection_controller.js +29 -189
  167. data/app/javascript/controllers/agent_vendor_controller.js +47 -1
  168. data/app/javascript/controllers/comment_agent_model_controller.js +87 -0
  169. data/app/javascript/controllers/comment_controller.js +34 -77
  170. data/app/javascript/controllers/comment_image_lightbox_controller.js +15 -0
  171. data/app/javascript/controllers/comment_user_menu_controller.js +122 -0
  172. data/app/javascript/controllers/comment_version_controller.js +10 -8
  173. data/app/javascript/controllers/comments/__tests__/comment_form_request.test.js +72 -0
  174. data/app/javascript/controllers/comments/__tests__/comment_list_response.test.js +30 -0
  175. data/app/javascript/controllers/comments/__tests__/comment_read_tracker.test.js +71 -0
  176. data/app/javascript/controllers/comments/__tests__/contexts_controller_context_list.test.js +466 -0
  177. data/app/javascript/controllers/comments/__tests__/contexts_controller_dnd.test.js +484 -0
  178. data/app/javascript/controllers/comments/__tests__/creative_quote_review_controller.test.js +111 -0
  179. data/app/javascript/controllers/comments/__tests__/drop_trigger_controller.test.js +48 -0
  180. data/app/javascript/controllers/comments/__tests__/feature_cards_controller.test.js +2 -2
  181. data/app/javascript/controllers/comments/__tests__/form_controller_double_submit.test.js +38 -0
  182. data/app/javascript/controllers/comments/__tests__/form_controller_draft.test.js +202 -17
  183. data/app/javascript/controllers/comments/__tests__/form_controller_review.test.js +375 -0
  184. data/app/javascript/controllers/comments/__tests__/form_controller_stashed_draft.test.js +4 -4
  185. data/app/javascript/controllers/comments/__tests__/form_controller_stashed_draft_creative_switch.test.js +2 -2
  186. data/app/javascript/controllers/comments/__tests__/form_draft_manager.test.js +154 -0
  187. data/app/javascript/controllers/comments/__tests__/inline_login_preservation.test.js +23 -0
  188. data/app/javascript/controllers/comments/__tests__/list_controller_approval_gate.test.js +51 -0
  189. data/app/javascript/controllers/comments/__tests__/list_controller_batch_delete.test.js +97 -0
  190. data/app/javascript/controllers/comments/__tests__/list_controller_dnd.test.js +26 -0
  191. data/app/javascript/controllers/comments/__tests__/list_controller_docked.test.js +54 -1
  192. data/app/javascript/controllers/comments/__tests__/list_controller_load_result.test.js +56 -0
  193. data/app/javascript/controllers/comments/__tests__/list_controller_loading.test.js +43 -0
  194. data/app/javascript/controllers/comments/__tests__/list_controller_prev_message.test.js +202 -1
  195. data/app/javascript/controllers/comments/__tests__/list_controller_read_pointer.test.js +12 -0
  196. data/app/javascript/controllers/comments/__tests__/list_controller_resend.test.js +69 -0
  197. data/app/javascript/controllers/comments/__tests__/list_controller_resume_pagination.test.js +191 -0
  198. data/app/javascript/controllers/comments/__tests__/loading_controller.test.js +83 -0
  199. data/app/javascript/controllers/comments/__tests__/mention_menu_controller.test.js +59 -0
  200. data/app/javascript/controllers/comments/__tests__/popup_controller.test.js +318 -4
  201. data/app/javascript/controllers/comments/__tests__/popup_exit_target.test.js +118 -0
  202. data/app/javascript/controllers/comments/__tests__/popup_focus.test.js +72 -0
  203. data/app/javascript/controllers/comments/__tests__/popup_fullscreen.test.js +320 -0
  204. data/app/javascript/controllers/comments/__tests__/popup_initial_url.test.js +103 -0
  205. data/app/javascript/controllers/comments/__tests__/popup_resume_resync.test.js +154 -0
  206. data/app/javascript/controllers/comments/__tests__/presence_controller.test.js +58 -0
  207. data/app/javascript/controllers/comments/__tests__/presence_controller_agent_online.test.js +244 -0
  208. data/app/javascript/controllers/comments/__tests__/presence_controller_participant_list.test.js +570 -0
  209. data/app/javascript/controllers/comments/__tests__/resend_action.test.js +137 -0
  210. data/app/javascript/controllers/comments/__tests__/review_quotes_store.test.js +27 -0
  211. data/app/javascript/controllers/comments/__tests__/run_options_controller.test.js +248 -0
  212. data/app/javascript/controllers/comments/__tests__/topics_controller_archived.test.js +45 -0
  213. data/app/javascript/controllers/comments/__tests__/topics_controller_creation_container.test.js +165 -0
  214. data/app/javascript/controllers/comments/__tests__/topics_controller_delete.test.js +231 -0
  215. data/app/javascript/controllers/comments/__tests__/topics_controller_dnd.test.js +120 -0
  216. data/app/javascript/controllers/comments/__tests__/topics_controller_scroll.test.js +17 -0
  217. data/app/javascript/controllers/comments/__tests__/topics_controller_selection_race.test.js +274 -2
  218. data/app/javascript/controllers/comments/__tests__/topics_controller_topic_list.test.js +4 -4
  219. data/app/javascript/controllers/comments/approval_request_options.js +12 -0
  220. data/app/javascript/controllers/comments/comment_form_request.js +26 -0
  221. data/app/javascript/controllers/comments/comment_list_response.js +20 -0
  222. data/app/javascript/controllers/comments/comment_read_tracker.js +143 -0
  223. data/app/javascript/controllers/comments/contexts_controller.js +338 -226
  224. data/app/javascript/controllers/comments/creative_chat_navigation.js +50 -0
  225. data/app/javascript/controllers/comments/creative_quote_review_controller.js +30 -0
  226. data/app/javascript/controllers/comments/drop_trigger_controller.js +2 -7
  227. data/app/javascript/controllers/comments/feature_cards_controller.js +1 -1
  228. data/app/javascript/controllers/comments/form_controller.js +128 -706
  229. data/app/javascript/controllers/comments/form_draft_manager.js +269 -0
  230. data/app/javascript/controllers/comments/form_draft_migration.js +142 -0
  231. data/app/javascript/controllers/comments/form_draft_persistence.js +228 -0
  232. data/app/javascript/controllers/comments/inline_login_preservation.js +18 -0
  233. data/app/javascript/controllers/comments/list_controller.js +105 -273
  234. data/app/javascript/controllers/comments/loading_controller.js +48 -0
  235. data/app/javascript/controllers/comments/mention_menu_controller.js +1 -24
  236. data/app/javascript/controllers/comments/optimistic_removal.js +15 -0
  237. data/app/javascript/controllers/comments/pagination_state.js +20 -0
  238. data/app/javascript/controllers/comments/popup_controller.js +74 -510
  239. data/app/javascript/controllers/comments/popup_creative_progress.js +51 -0
  240. data/app/javascript/controllers/comments/popup_exit_target.js +92 -0
  241. data/app/javascript/controllers/comments/popup_focus.js +5 -0
  242. data/app/javascript/controllers/comments/popup_fullscreen.js +335 -0
  243. data/app/javascript/controllers/comments/popup_resume_resync.js +28 -0
  244. data/app/javascript/controllers/comments/popup_url_open.js +22 -0
  245. data/app/javascript/controllers/comments/presence_controller.js +295 -142
  246. data/app/javascript/controllers/comments/previous_message_navigation.js +154 -0
  247. data/app/javascript/controllers/comments/resend_action.js +63 -0
  248. data/app/javascript/controllers/comments/review_quotes_store.js +11 -8
  249. data/app/javascript/controllers/comments/run_options_controller.js +145 -0
  250. data/app/javascript/controllers/comments/topics/last_topic_save.js +124 -0
  251. data/app/javascript/controllers/comments/topics/reserved_topic_deletion.js +25 -0
  252. data/app/javascript/controllers/comments/topics/save_order_state.js +127 -0
  253. data/app/javascript/controllers/comments/topics/selection_restore_state.js +42 -0
  254. data/app/javascript/controllers/comments/topics/self_echo_state.js +24 -0
  255. data/app/javascript/controllers/comments/topics_controller.js +336 -478
  256. data/app/javascript/controllers/creative_history_controller.js +57 -0
  257. data/app/javascript/controllers/creative_history_detail_controller.js +41 -0
  258. data/app/javascript/controllers/creative_history_undo_controller.js +19 -0
  259. data/app/javascript/controllers/creative_image_lightbox_controller.js +114 -0
  260. data/app/javascript/controllers/creative_move_controller.js +202 -0
  261. data/app/javascript/controllers/creatives/__tests__/document_selection_controller.test.js +241 -0
  262. data/app/javascript/controllers/creatives/__tests__/document_view_controller.test.js +173 -0
  263. data/app/javascript/controllers/creatives/__tests__/drag_drop_controller.test.js +74 -0
  264. data/app/javascript/controllers/creatives/__tests__/import_controller.test.js +48 -0
  265. data/app/javascript/controllers/creatives/__tests__/select_mode_controller.test.js +111 -0
  266. data/app/javascript/controllers/creatives/__tests__/tree_controller.test.js +605 -2
  267. data/app/javascript/controllers/creatives/__tests__/workflow_rule_controller.test.js +322 -0
  268. data/app/javascript/controllers/creatives/document_selection_controller.js +77 -0
  269. data/app/javascript/controllers/creatives/document_view_controller.js +82 -0
  270. data/app/javascript/controllers/creatives/drag_drop_controller.js +13 -19
  271. data/app/javascript/controllers/creatives/expansion_controller.js +21 -19
  272. data/app/javascript/controllers/creatives/import_controller.js +1 -1
  273. data/app/javascript/controllers/creatives/select_mode_controller.js +31 -4
  274. data/app/javascript/controllers/creatives/tree_controller.js +128 -36
  275. data/app/javascript/controllers/creatives/workflow_rule_controller.js +96 -0
  276. data/app/javascript/controllers/creatives/workflow_rule_form.js +183 -0
  277. data/app/javascript/controllers/cron_badge_controller.js +187 -0
  278. data/app/javascript/controllers/document_preview_controller.js +16 -0
  279. data/app/javascript/controllers/entity_list_controller.js +147 -0
  280. data/app/javascript/controllers/gateway_check_controller.js +3 -5
  281. data/app/javascript/controllers/image_lightbox_controller.js +29 -70
  282. data/app/javascript/controllers/image_lightbox_values.js +13 -0
  283. data/app/javascript/controllers/index.js +85 -11
  284. data/app/javascript/controllers/inline_creative_picker_controller.js +110 -0
  285. data/app/javascript/controllers/link_creative_controller.js +14 -11
  286. data/app/javascript/controllers/notice_bar_controller.js +364 -0
  287. data/app/javascript/controllers/org_chart_controller.js +2 -23
  288. data/app/javascript/controllers/popup_menu_controller.js +128 -45
  289. data/app/javascript/controllers/search_popup_controller.js +12 -8
  290. data/app/javascript/controllers/searchable_list_controller.js +30 -0
  291. data/app/javascript/controllers/share_modal_controller.js +18 -56
  292. data/app/javascript/controllers/share_user_search_controller.js +1 -11
  293. data/app/javascript/controllers/tabs_controller.js +5 -1
  294. data/app/javascript/controllers/tool_category_controller.js +39 -0
  295. data/app/javascript/controllers/topic_list_controller.js +5 -31
  296. data/app/javascript/controllers/topic_search_controller.js +2 -4
  297. data/app/javascript/controllers/workspace_tree_controller.js +194 -53
  298. data/app/javascript/creatives/__tests__/row_progress.test.js +155 -0
  299. data/app/javascript/creatives/__tests__/tree_reload_events.test.js +101 -0
  300. data/app/javascript/creatives/__tests__/tree_renderer.test.js +116 -1
  301. data/app/javascript/creatives/__tests__/tree_view_state.test.js +277 -0
  302. data/app/javascript/creatives/branch_expansion.js +39 -0
  303. data/app/javascript/creatives/drag_drop/__tests__/command_integration.test.js +194 -0
  304. data/app/javascript/creatives/drag_drop/__tests__/creative_tree_drop.test.js +964 -0
  305. data/app/javascript/creatives/drag_drop/__tests__/event_handlers_data.test.js +329 -0
  306. data/app/javascript/creatives/drag_drop/__tests__/file_drop.test.js +99 -0
  307. data/app/javascript/creatives/drag_drop/__tests__/hover_expand.test.js +134 -0
  308. data/app/javascript/creatives/drag_drop/__tests__/indicator.test.js +36 -0
  309. data/app/javascript/creatives/drag_drop/__tests__/move_command.test.js +471 -0
  310. data/app/javascript/creatives/drag_drop/__tests__/move_command_dom_recovery.test.js +346 -0
  311. data/app/javascript/creatives/drag_drop/__tests__/move_command_queued_saves.test.js +201 -0
  312. data/app/javascript/creatives/drag_drop/__tests__/move_feedback.test.js +79 -0
  313. data/app/javascript/creatives/drag_drop/__tests__/source_window_bundle.test.js +141 -0
  314. data/app/javascript/creatives/drag_drop/__tests__/state.test.js +36 -0
  315. data/app/javascript/creatives/drag_drop/__tests__/touch_tree_integration.test.js +209 -0
  316. data/app/javascript/creatives/drag_drop/__tests__/workspace_tree_adapter.test.js +517 -0
  317. data/app/javascript/creatives/drag_drop/__tests__/workspace_tree_dom.test.js +105 -0
  318. data/app/javascript/creatives/drag_drop/dom.js +9 -0
  319. data/app/javascript/creatives/drag_drop/event_handlers.js +279 -431
  320. data/app/javascript/creatives/drag_drop/file_drop.js +60 -0
  321. data/app/javascript/creatives/drag_drop/indicator.js +2 -1
  322. data/app/javascript/creatives/drag_drop/move_command.js +297 -0
  323. data/app/javascript/creatives/drag_drop/move_feedback.js +22 -0
  324. data/app/javascript/creatives/drag_drop/operations.js +73 -0
  325. data/app/javascript/creatives/drag_drop/state.js +10 -1
  326. data/app/javascript/creatives/drag_drop/workspace_tree_adapter.js +161 -0
  327. data/app/javascript/creatives/drag_drop/workspace_tree_dom.js +52 -0
  328. data/app/javascript/creatives/row_progress.js +96 -0
  329. data/app/javascript/creatives/tree_reload_events.js +42 -0
  330. data/app/javascript/creatives/tree_renderer.js +70 -21
  331. data/app/javascript/creatives/tree_view_state.js +87 -0
  332. data/app/javascript/lib/__tests__/creative_quote.test.js +343 -0
  333. data/app/javascript/lib/__tests__/creative_title.test.js +15 -0
  334. data/app/javascript/lib/__tests__/entity_list_popup.test.js +47 -0
  335. data/app/javascript/lib/__tests__/html_escape.test.js +29 -0
  336. data/app/javascript/lib/__tests__/permission_update.test.js +38 -0
  337. data/app/javascript/lib/__tests__/popup_toggle_guard.test.js +82 -0
  338. data/app/javascript/lib/__tests__/ppt_background.test.js +86 -0
  339. data/app/javascript/lib/__tests__/ppt_connector.test.js +80 -0
  340. data/app/javascript/lib/__tests__/ppt_formatting.test.js +246 -0
  341. data/app/javascript/lib/__tests__/ppt_media.test.js +86 -0
  342. data/app/javascript/lib/__tests__/quote_selection_popup.test.js +100 -0
  343. data/app/javascript/lib/__tests__/touch_drag_tap.test.js +31 -0
  344. data/app/javascript/lib/__tests__/touch_drag_targets.test.js +293 -0
  345. data/app/javascript/lib/__tests__/turbo_stream_actions.test.js +29 -1
  346. data/app/javascript/lib/__tests__/workspace_scroll_restoration.test.js +310 -0
  347. data/app/javascript/lib/__tests__/workspace_tree_removal.test.js +108 -0
  348. data/app/javascript/lib/api/__tests__/creatives.test.js +27 -1
  349. data/app/javascript/lib/api/__tests__/drag_drop.test.js +136 -0
  350. data/app/javascript/lib/api/__tests__/expansion_intent.test.js +75 -0
  351. data/app/javascript/lib/api/__tests__/expansion_save_queue.test.js +110 -0
  352. data/app/javascript/lib/api/__tests__/queue_manager.test.js +237 -0
  353. data/app/javascript/lib/api/__tests__/queue_reconciliation.test.js +57 -0
  354. data/app/javascript/lib/api/__tests__/queue_recovery.test.js +28 -0
  355. data/app/javascript/lib/api/creatives.js +5 -2
  356. data/app/javascript/lib/api/drag_drop.js +25 -1
  357. data/app/javascript/lib/api/expansion_intent.js +28 -0
  358. data/app/javascript/lib/api/expansion_save_queue.js +51 -0
  359. data/app/javascript/lib/api/queue_completion.js +30 -0
  360. data/app/javascript/lib/api/queue_manager.js +34 -50
  361. data/app/javascript/lib/api/queue_reconciliation.js +44 -0
  362. data/app/javascript/lib/api/queue_recovery.js +24 -0
  363. data/app/javascript/lib/common_popup.js +7 -7
  364. data/app/javascript/lib/creative_quote.js +135 -0
  365. data/app/javascript/lib/creative_title.js +9 -0
  366. data/app/javascript/lib/creative_tree_invalidation.js +4 -0
  367. data/app/javascript/lib/dnd/__tests__/bundle_image.test.js +32 -0
  368. data/app/javascript/lib/dnd/__tests__/envelope.test.js +262 -0
  369. data/app/javascript/lib/dnd/__tests__/hit_test.test.js +69 -0
  370. data/app/javascript/lib/dnd/__tests__/preview.test.js +22 -0
  371. data/app/javascript/lib/dnd/__tests__/registry.test.js +797 -0
  372. data/app/javascript/lib/dnd/__tests__/session.test.js +213 -0
  373. data/app/javascript/lib/dnd/__tests__/session_without_window.test.js +15 -0
  374. data/app/javascript/lib/dnd/__tests__/touch_bridge.test.js +532 -0
  375. data/app/javascript/lib/dnd/creative_label.js +21 -0
  376. data/app/javascript/lib/dnd/envelope.js +194 -0
  377. data/app/javascript/lib/dnd/hit_test.js +42 -0
  378. data/app/javascript/lib/dnd/preview.js +10 -0
  379. data/app/javascript/lib/dnd/registry.js +315 -0
  380. data/app/javascript/lib/dnd/session.js +152 -0
  381. data/app/javascript/lib/dnd/touch_bridge.js +184 -0
  382. data/app/javascript/lib/editor/__tests__/code_languages.test.js +1 -5
  383. data/app/javascript/lib/editor/code_languages.js +0 -1
  384. data/app/javascript/lib/entity_list_popup.js +45 -0
  385. data/app/javascript/lib/html_escape.js +12 -0
  386. data/app/javascript/lib/image_lightbox_pan.js +31 -0
  387. data/app/javascript/lib/lexical/__tests__/attachment_payload.test.js +12 -189
  388. data/app/javascript/lib/lexical/__tests__/creative_link_drop.test.js +414 -0
  389. data/app/javascript/lib/lexical/__tests__/creative_link_node.test.js +50 -0
  390. data/app/javascript/lib/lexical/__tests__/file_drop.test.js +288 -0
  391. data/app/javascript/lib/lexical/attachment_node.jsx +21 -42
  392. data/app/javascript/lib/lexical/attachment_payload.js +0 -274
  393. data/app/javascript/lib/lexical/attachment_presentation.js +57 -0
  394. data/app/javascript/lib/lexical/creative_link_drop.js +98 -0
  395. data/app/javascript/lib/lexical/creative_link_node.js +30 -4
  396. data/app/javascript/lib/lexical/file_drop.js +106 -0
  397. data/app/javascript/lib/lexical/ppt_attachment.js +26 -0
  398. data/app/javascript/lib/lexical/upload_anchor_node.js +16 -0
  399. data/app/javascript/lib/lexical/upload_nodes.js +6 -0
  400. data/app/javascript/lib/media_loading.js +25 -0
  401. data/app/javascript/lib/permission_update.js +21 -0
  402. data/app/javascript/lib/popup_toggle_guard.js +56 -0
  403. data/app/javascript/lib/ppt_background.js +48 -0
  404. data/app/javascript/lib/ppt_chart.js +59 -0
  405. data/app/javascript/lib/ppt_connector.js +63 -0
  406. data/app/javascript/lib/ppt_formatting.js +138 -0
  407. data/app/javascript/lib/ppt_media.js +61 -0
  408. data/app/javascript/lib/quote_selection_popup.js +67 -0
  409. data/app/javascript/lib/responsive_images.js +0 -12
  410. data/app/javascript/lib/search_combobox.js +61 -0
  411. data/app/javascript/lib/share_modal_links.js +35 -0
  412. data/app/javascript/lib/touch_drag.js +119 -37
  413. data/app/javascript/lib/turbo_stream_actions.js +19 -1
  414. data/app/javascript/lib/utils/__tests__/attachment_rendering.test.js +189 -0
  415. data/app/javascript/lib/utils/__tests__/creative_link_navigation.test.js +301 -0
  416. data/app/javascript/lib/utils/__tests__/filter_navigation.test.js +16 -0
  417. data/app/javascript/lib/utils/__tests__/focus.test.js +144 -0
  418. data/app/javascript/lib/utils/__tests__/mermaid_math.test.js +24 -0
  419. data/app/javascript/lib/utils/__tests__/sanitize_description.test.js +10 -0
  420. data/app/javascript/lib/utils/creative_link_navigation.js +64 -0
  421. data/app/javascript/lib/utils/filter_navigation.js +16 -2
  422. data/app/javascript/lib/utils/focus.js +36 -0
  423. data/app/javascript/lib/utils/markdown.js +0 -4
  424. data/app/javascript/lib/utils/sanitize_description.js +12 -4
  425. data/app/javascript/lib/utils/workspace_chat_navigation.js +25 -0
  426. data/app/javascript/lib/viewport_region.js +20 -0
  427. data/app/javascript/lib/workspace_scroll_restoration.js +134 -0
  428. data/app/javascript/lib/workspace_tree_removal.js +91 -0
  429. data/app/javascript/lib/workspace_tree_visibility.js +25 -0
  430. data/app/javascript/modules/__tests__/background_creative_create.test.js +114 -0
  431. data/app/javascript/modules/__tests__/command_args_form.test.js +96 -0
  432. data/app/javascript/modules/__tests__/command_menu_details.test.js +199 -0
  433. data/app/javascript/modules/__tests__/creative_inline_dataset.test.js +35 -0
  434. data/app/javascript/modules/__tests__/creative_inline_payload.test.js +35 -0
  435. data/app/javascript/modules/__tests__/creative_row_editor_background_create.test.js +2147 -0
  436. data/app/javascript/modules/__tests__/creative_row_editor_empty_state_recovery.test.js +15 -320
  437. data/app/javascript/modules/__tests__/creative_row_editor_empty_state_removal.test.js +122 -0
  438. data/app/javascript/modules/__tests__/creative_row_editor_instant_reveal.test.js +186 -0
  439. data/app/javascript/modules/__tests__/creative_row_editor_save_paths.test.js +1132 -0
  440. data/app/javascript/modules/__tests__/creative_save_state.test.js +165 -0
  441. data/app/javascript/modules/__tests__/creative_type_editor.test.js +203 -0
  442. data/app/javascript/modules/__tests__/failed_creative_save.test.js +65 -0
  443. data/app/javascript/modules/__tests__/html_content_empty.test.js +11 -0
  444. data/app/javascript/modules/__tests__/integration_wizard.test.js +139 -0
  445. data/app/javascript/modules/__tests__/mention_menu.test.js +190 -0
  446. data/app/javascript/modules/__tests__/notice_bar_motion.test.js +132 -0
  447. data/app/javascript/modules/__tests__/notice_bar_sheet.test.js +108 -0
  448. data/app/javascript/modules/__tests__/notice_bar_spotlight.test.js +109 -0
  449. data/app/javascript/modules/__tests__/notice_bar_storage.test.js +31 -0
  450. data/app/javascript/modules/__tests__/notice_bar_toasts.test.js +71 -0
  451. data/app/javascript/modules/__tests__/notice_bar_view.test.js +89 -0
  452. data/app/javascript/modules/__tests__/pdf_assets.test.js +26 -0
  453. data/app/javascript/modules/__tests__/pdf_document.test.js +231 -0
  454. data/app/javascript/modules/__tests__/persisted_creative_tree.test.js +48 -0
  455. data/app/javascript/modules/__tests__/ppt_viewer.test.js +219 -0
  456. data/app/javascript/modules/__tests__/queued_creative_row.test.js +206 -0
  457. data/app/javascript/modules/__tests__/recovered_creative_position.test.js +57 -0
  458. data/app/javascript/modules/__tests__/slide_view_attachments.test.js +71 -0
  459. data/app/javascript/modules/__tests__/support/inline_editor_dom.js +24 -0
  460. data/app/javascript/modules/__tests__/viewer_navigation.test.js +42 -0
  461. data/app/javascript/modules/background_creative_create.js +326 -0
  462. data/app/javascript/modules/command_args_form.js +32 -30
  463. data/app/javascript/modules/command_menu.js +91 -17
  464. data/app/javascript/modules/creative_inline_dataset.js +34 -0
  465. data/app/javascript/modules/creative_inline_payload.js +10 -14
  466. data/app/javascript/modules/creative_removal.js +39 -0
  467. data/app/javascript/modules/creative_row_editor.js +383 -402
  468. data/app/javascript/modules/creative_save_state.js +141 -0
  469. data/app/javascript/modules/creative_type_editor.js +139 -0
  470. data/app/javascript/modules/failed_creative_save.js +42 -0
  471. data/app/javascript/modules/html_content_empty.js +5 -3
  472. data/app/javascript/modules/integration_wizard.js +68 -19
  473. data/app/javascript/modules/keep_goal_text.js +4 -0
  474. data/app/javascript/modules/lexical_inline_editor.jsx +9 -2
  475. data/app/javascript/modules/mention_menu.js +34 -22
  476. data/app/javascript/modules/notice_bar/__tests__/refresh.test.js +177 -0
  477. data/app/javascript/modules/notice_bar/motion.js +59 -0
  478. data/app/javascript/modules/notice_bar/refresh.js +53 -0
  479. data/app/javascript/modules/notice_bar/sheet.js +102 -0
  480. data/app/javascript/modules/notice_bar/spotlight.js +78 -0
  481. data/app/javascript/modules/notice_bar/storage.js +14 -0
  482. data/app/javascript/modules/notice_bar/toasts.js +49 -0
  483. data/app/javascript/modules/notice_bar/view.js +101 -0
  484. data/app/javascript/modules/pdf_document.js +65 -0
  485. data/app/javascript/modules/pending_creative_sync.js +23 -0
  486. data/app/javascript/modules/persisted_creative_tree.js +39 -0
  487. data/app/javascript/modules/ppt_viewer.js +76 -0
  488. data/app/javascript/modules/queued_creative_row.js +128 -0
  489. data/app/javascript/modules/recovered_creative_position.js +52 -0
  490. data/app/javascript/modules/slide_view.js +9 -3
  491. data/app/javascript/modules/viewer_navigation.js +16 -0
  492. data/app/javascript/slide_view.js +9 -0
  493. data/app/jobs/collavre/agent_provisioning_sync_job.rb +79 -0
  494. data/app/jobs/collavre/ai_agent_job.rb +181 -160
  495. data/app/jobs/collavre/approval_continuation_job.rb +102 -0
  496. data/app/jobs/collavre/approval_gate_resume_job.rb +22 -0
  497. data/app/jobs/collavre/async_approval_resume_job.rb +20 -0
  498. data/app/jobs/collavre/async_approval_sweep_job.rb +44 -0
  499. data/app/jobs/collavre/batch_destroy_comments_job.rb +17 -0
  500. data/app/jobs/collavre/cancel_offline_delegated_tasks_job.rb +35 -82
  501. data/app/jobs/collavre/cdn_invalidation_job.rb +62 -0
  502. data/app/jobs/collavre/claude_approval_resume_job.rb +15 -0
  503. data/app/jobs/collavre/comment_push_delivery_sweep_job.rb +9 -1
  504. data/app/jobs/collavre/compress_job.rb +3 -27
  505. data/app/jobs/collavre/creative_broadcast_job.rb +13 -16
  506. data/app/jobs/collavre/creative_history_notice_job.rb +40 -0
  507. data/app/jobs/collavre/creative_history_prune_job.rb +86 -0
  508. data/app/jobs/collavre/creative_tree_invalidation_job.rb +33 -0
  509. data/app/jobs/collavre/cron_action_job.rb +24 -7
  510. data/app/jobs/collavre/cron_scheduler_job.rb +44 -3
  511. data/app/jobs/collavre/drop_trigger_job.rb +35 -30
  512. data/app/jobs/collavre/endpoint_health_probe_job.rb +23 -0
  513. data/app/jobs/collavre/endpoint_health_sweep_job.rb +22 -0
  514. data/app/jobs/collavre/gateway_health_probe_job.rb +33 -0
  515. data/app/jobs/collavre/gateway_health_sweep_job.rb +22 -0
  516. data/app/jobs/collavre/inline_agent_replay_job.rb +32 -0
  517. data/app/jobs/collavre/keep_loop_reconcile_job.rb +57 -0
  518. data/app/jobs/collavre/merge_comments_job.rb +6 -30
  519. data/app/jobs/collavre/offline_task_sweep_job.rb +44 -0
  520. data/app/jobs/collavre/permission_cache_job.rb +19 -10
  521. data/app/jobs/collavre/purge_unreferenced_blob_job.rb +19 -0
  522. data/app/jobs/collavre/push_notification_job.rb +4 -3
  523. data/app/jobs/collavre/recover_interrupted_tasks_job.rb +79 -0
  524. data/app/jobs/collavre/resume_suspended_tasks_job.rb +29 -0
  525. data/app/jobs/collavre/solid_queue_worker_watchdog_job.rb +108 -0
  526. data/app/jobs/collavre/trigger_loop_check_job.rb +104 -105
  527. data/app/jobs/collavre/trigger_loop_verify_job.rb +51 -82
  528. data/app/jobs/collavre/workflow_outbox_job.rb +10 -0
  529. data/app/jobs/collavre/workflow_push_job.rb +11 -0
  530. data/app/jobs/collavre/workflow_sweep_job.rb +11 -0
  531. data/app/jobs/concerns/collavre/comment_serializable.rb +3 -1
  532. data/app/jobs/concerns/collavre/dispatch_admission.rb +95 -0
  533. data/app/jobs/concerns/collavre/trigger_loop_helpers.rb +178 -13
  534. data/app/models/collavre/agent_gateway.rb +76 -0
  535. data/app/models/collavre/agent_workspace.rb +42 -7
  536. data/app/models/collavre/blob_access_flag.rb +24 -0
  537. data/app/models/collavre/channel.rb +17 -0
  538. data/app/models/collavre/comment/approvable.rb +14 -1
  539. data/app/models/collavre/comment/approval_gate.rb +98 -0
  540. data/app/models/collavre/comment/batch_destruction.rb +173 -0
  541. data/app/models/collavre/comment/broadcastable.rb +18 -0
  542. data/app/models/collavre/comment/bulk_follow_up_jobs.rb +29 -0
  543. data/app/models/collavre/comment/claude_channel_permission.rb +59 -5
  544. data/app/models/collavre/comment/creative_quote.rb +55 -0
  545. data/app/models/collavre/comment/image_cdn_eviction.rb +36 -0
  546. data/app/models/collavre/comment/notifiable.rb +7 -6
  547. data/app/models/collavre/comment/suspension_notice.rb +20 -0
  548. data/app/models/collavre/comment/topic_membership.rb +21 -1
  549. data/app/models/collavre/comment/trigger_loop_resume.rb +77 -0
  550. data/app/models/collavre/comment.rb +30 -106
  551. data/app/models/collavre/comment_notification_delivery.rb +19 -8
  552. data/app/models/collavre/comment_version.rb +4 -0
  553. data/app/models/collavre/creative/ai_write_policy.rb +26 -0
  554. data/app/models/collavre/creative/contextual.rb +153 -0
  555. data/app/models/collavre/creative/describable.rb +34 -25
  556. data/app/models/collavre/creative/history_trackable.rb +104 -0
  557. data/app/models/collavre/creative/linkable.rb +21 -1
  558. data/app/models/collavre/creative/permissible.rb +12 -20
  559. data/app/models/collavre/creative/publishable.rb +65 -0
  560. data/app/models/collavre/creative/type_selectable.rb +25 -0
  561. data/app/models/collavre/creative.rb +26 -110
  562. data/app/models/collavre/creative_change.rb +55 -0
  563. data/app/models/collavre/creative_change_set.rb +71 -0
  564. data/app/models/collavre/creative_share.rb +19 -0
  565. data/app/models/collavre/current.rb +8 -1
  566. data/app/models/collavre/llm_model.rb +1 -0
  567. data/app/models/collavre/llm_usage/requester.rb +9 -0
  568. data/app/models/collavre/llm_usage.rb +33 -0
  569. data/app/models/collavre/mcp_tool.rb +25 -3
  570. data/app/models/collavre/orchestrator_policy.rb +25 -29
  571. data/app/models/collavre/preview_channel.rb +1 -15
  572. data/app/models/collavre/retired_task_execution.rb +9 -0
  573. data/app/models/collavre/system_setting.rb +60 -8
  574. data/app/models/collavre/task/approval_gate_cleanup.rb +23 -0
  575. data/app/models/collavre/task/async_approval.rb +30 -0
  576. data/app/models/collavre/task.rb +76 -30
  577. data/app/models/collavre/task_merged_instruction.rb +6 -0
  578. data/app/models/collavre/tool_usage/requester.rb +9 -0
  579. data/app/models/collavre/tool_usage.rb +69 -0
  580. data/app/models/collavre/topic.rb +41 -3
  581. data/app/models/collavre/user/ai_capabilities.rb +38 -0
  582. data/app/models/collavre/user.rb +28 -24
  583. data/app/models/collavre/user_creative_preference.rb +25 -1
  584. data/app/models/collavre/user_notice.rb +64 -0
  585. data/app/models/collavre/workflow/chain.rb +27 -0
  586. data/app/models/collavre/workflow/execution.rb +28 -0
  587. data/app/models/collavre/workflow/outbox.rb +43 -0
  588. data/app/models/collavre/workflow/receipt.rb +26 -0
  589. data/app/models/concerns/collavre/agent_liveness.rb +95 -0
  590. data/app/models/concerns/collavre/agent_run_options.rb +45 -0
  591. data/app/models/concerns/collavre/ai_agent_resolvable.rb +30 -7
  592. data/app/models/concerns/collavre/comment/dispatch_revocation.rb +99 -0
  593. data/app/models/concerns/collavre/comment/keep_loop.rb +166 -0
  594. data/app/models/concerns/collavre/creation_events.rb +25 -0
  595. data/app/models/concerns/collavre/creative/trigger_loop.rb +57 -0
  596. data/app/models/concerns/collavre/creative_history_topic.rb +34 -0
  597. data/app/models/concerns/collavre/creative_reserved_topics.rb +25 -0
  598. data/app/models/concerns/collavre/has_inbox_creative.rb +9 -1
  599. data/app/models/concerns/collavre/system_agent_identity.rb +13 -0
  600. data/app/models/concerns/collavre/task/replay_loop_completion.rb +78 -0
  601. data/app/models/concerns/collavre/task/trigger_loop_completion.rb +126 -0
  602. data/app/models/concerns/collavre/task/usage_attribution_tracking.rb +28 -0
  603. data/app/models/concerns/collavre/task/workflow_completion.rb +59 -0
  604. data/app/services/collavre/agent_health/endpoint_request.rb +64 -0
  605. data/app/services/collavre/agent_health/openai_endpoint_checker.rb +77 -0
  606. data/app/services/collavre/agent_health/probe.rb +47 -0
  607. data/app/services/collavre/agent_health.rb +43 -0
  608. data/app/services/collavre/agent_session_abort.rb +2 -2
  609. data/app/services/collavre/agent_tool_permission.rb +43 -0
  610. data/app/services/collavre/ai_agent/a2a_dispatcher.rb +22 -4
  611. data/app/services/collavre/ai_agent/agent_lifecycle_manager.rb +16 -1
  612. data/app/services/collavre/ai_agent/approval_conversation.rb +60 -0
  613. data/app/services/collavre/ai_agent/approval_gate_handler.rb +37 -0
  614. data/app/services/collavre/ai_agent/approval_handler.rb +8 -1
  615. data/app/services/collavre/ai_agent/budgeted_tree_renderer.rb +80 -0
  616. data/app/services/collavre/ai_agent/chat_history_window.rb +87 -0
  617. data/app/services/collavre/ai_agent/claude_channel_adapter.rb +60 -9
  618. data/app/services/collavre/ai_agent/creative_quote_context.rb +66 -0
  619. data/app/services/collavre/ai_agent/history_notice.rb +94 -0
  620. data/app/services/collavre/ai_agent/message_builder.rb +160 -113
  621. data/app/services/collavre/ai_agent/prompt_budget.rb +142 -0
  622. data/app/services/collavre/ai_agent/referenced_creative_renderer.rb +101 -0
  623. data/app/services/collavre/ai_agent/reply_placeholder.rb +28 -0
  624. data/app/services/collavre/ai_agent/response_finalizer.rb +15 -1
  625. data/app/services/collavre/ai_agent/review_handler.rb +17 -17
  626. data/app/services/collavre/ai_agent/screening_approval_handler.rb +26 -0
  627. data/app/services/collavre/ai_agent/session_context_resolver.rb +6 -1
  628. data/app/services/collavre/ai_agent/task_claim_service.rb +55 -3
  629. data/app/services/collavre/ai_agent/task_reply_service.rb +30 -7
  630. data/app/services/collavre/ai_agent/task_workspace_user.rb +20 -0
  631. data/app/services/collavre/ai_agent/turn_screening.rb +132 -0
  632. data/app/services/collavre/ai_agent/workspace_authentication.rb +74 -0
  633. data/app/services/collavre/ai_agent_service.rb +49 -74
  634. data/app/services/collavre/ai_approval_summary.rb +51 -0
  635. data/app/services/collavre/ai_client/approval_gate.rb +90 -0
  636. data/app/services/collavre/ai_client/cli_tool_events.rb +100 -0
  637. data/app/services/collavre/ai_client/decision.rb +101 -0
  638. data/app/services/collavre/ai_client/error_handling.rb +67 -0
  639. data/app/services/collavre/ai_client/provider_context.rb +69 -0
  640. data/app/services/collavre/ai_client.rb +58 -209
  641. data/app/services/collavre/ai_usage_tracking.rb +93 -0
  642. data/app/services/collavre/auto_theme_generator.rb +5 -8
  643. data/app/services/collavre/blob_access.rb +166 -0
  644. data/app/services/collavre/cdn_invalidation.rb +67 -0
  645. data/app/services/collavre/claude_approval_handoff.rb +28 -0
  646. data/app/services/collavre/cli_proxy/adapter_engine.rb +27 -0
  647. data/app/services/collavre/cli_proxy/client.rb +56 -13
  648. data/app/services/collavre/cli_proxy/engine_unauthenticated_error.rb +31 -0
  649. data/app/services/collavre/cli_proxy/health_probe.rb +137 -0
  650. data/app/services/collavre/cli_proxy/inline_login.rb +239 -0
  651. data/app/services/collavre/cli_proxy/inline_replay_admission.rb +57 -0
  652. data/app/services/collavre/cli_proxy/replay_claims.rb +48 -0
  653. data/app/services/collavre/cli_proxy/replay_routing.rb +43 -0
  654. data/app/services/collavre/cli_proxy/replay_workspace.rb +53 -0
  655. data/app/services/collavre/cli_proxy/run_options.rb +90 -0
  656. data/app/services/collavre/command_menu_service.rb +18 -4
  657. data/app/services/collavre/comment_move_service.rb +5 -1
  658. data/app/services/collavre/comment_resend_service/cleanup.rb +20 -0
  659. data/app/services/collavre/comment_resend_service.rb +125 -0
  660. data/app/services/collavre/comment_snapshot_restore_service.rb +16 -10
  661. data/app/services/collavre/comments/action_executor.rb +15 -25
  662. data/app/services/collavre/comments/approval_gate_decision.rb +54 -0
  663. data/app/services/collavre/comments/approved_tool_invocation.rb +37 -0
  664. data/app/services/collavre/comments/async_approval_decision.rb +41 -0
  665. data/app/services/collavre/comments/command_processor.rb +14 -0
  666. data/app/services/collavre/comments/creative_quote_rejection_notice.rb +37 -0
  667. data/app/services/collavre/comments/creative_quote_review.rb +54 -0
  668. data/app/services/collavre/comments/keep_command.rb +80 -0
  669. data/app/services/collavre/comments/list_response.rb +30 -2
  670. data/app/services/collavre/comments/topic_command.rb +6 -27
  671. data/app/services/collavre/creatives/agent_turn_history.rb +15 -0
  672. data/app/services/collavre/creatives/ai_write_policy.rb +36 -0
  673. data/app/services/collavre/creatives/change_set_apply_service.rb +309 -0
  674. data/app/services/collavre/creatives/change_set_diff.rb +216 -0
  675. data/app/services/collavre/creatives/change_set_restore_service.rb +20 -0
  676. data/app/services/collavre/creatives/change_set_revert_service.rb +21 -0
  677. data/app/services/collavre/creatives/change_set_visibility.rb +108 -0
  678. data/app/services/collavre/creatives/children_index.rb +19 -8
  679. data/app/services/collavre/creatives/create_service.rb +3 -1
  680. data/app/services/collavre/creatives/creation_revert_policy.rb +35 -0
  681. data/app/services/collavre/creatives/creative_quote_turn.rb +96 -0
  682. data/app/services/collavre/creatives/description_image_dimensions.rb +50 -0
  683. data/app/services/collavre/creatives/destroy_service.rb +18 -2
  684. data/app/services/collavre/creatives/draft_change_set_applicator.rb +121 -0
  685. data/app/services/collavre/creatives/draft_change_set_capture.rb +206 -0
  686. data/app/services/collavre/creatives/draft_change_set_reject_service.rb +45 -0
  687. data/app/services/collavre/creatives/draft_conflict_dependency_pruner.rb +110 -0
  688. data/app/services/collavre/creatives/draft_link_authorization.rb +61 -0
  689. data/app/services/collavre/creatives/draft_link_progress_reconciliation.rb +36 -0
  690. data/app/services/collavre/creatives/drop_trigger_missing_agent_notifier.rb +31 -0
  691. data/app/services/collavre/creatives/expansion_save_order.rb +70 -0
  692. data/app/services/collavre/creatives/file_drop_service.rb +49 -0
  693. data/app/services/collavre/creatives/filter_pipeline.rb +7 -4
  694. data/app/services/collavre/creatives/filter_state.rb +25 -0
  695. data/app/services/collavre/creatives/filters/base_filter.rb +3 -2
  696. data/app/services/collavre/creatives/filters/cron_filter.rb +19 -0
  697. data/app/services/collavre/creatives/filters/reaction_filter.rb +17 -0
  698. data/app/services/collavre/creatives/historical_snapshot_authorization.rb +108 -0
  699. data/app/services/collavre/creatives/history.rb +302 -0
  700. data/app/services/collavre/creatives/history_page.rb +61 -0
  701. data/app/services/collavre/creatives/importer.rb +19 -5
  702. data/app/services/collavre/creatives/index_query.rb +6 -12
  703. data/app/services/collavre/creatives/keep_agent_scope.rb +29 -0
  704. data/app/services/collavre/creatives/origin_chain_preloader.rb +23 -0
  705. data/app/services/collavre/creatives/permission_cache_builder.rb +72 -42
  706. data/app/services/collavre/creatives/permission_checker.rb +51 -4
  707. data/app/services/collavre/creatives/permission_filter.rb +14 -1
  708. data/app/services/collavre/creatives/progress_propagation_targets.rb +36 -0
  709. data/app/services/collavre/creatives/propagated_change_authorization.rb +142 -0
  710. data/app/services/collavre/creatives/reorderer.rb +128 -49
  711. data/app/services/collavre/creatives/snapshot_assignment.rb +25 -0
  712. data/app/services/collavre/creatives/snapshot_comparison.rb +14 -0
  713. data/app/services/collavre/creatives/tree_builder.rb +40 -13
  714. data/app/services/collavre/creatives/tree_formatter.rb +1 -1
  715. data/app/services/collavre/creatives/trigger_action_command.rb +222 -0
  716. data/app/services/collavre/creatives/type_transition.rb +58 -0
  717. data/app/services/collavre/creatives/workspace_expansion_candidates.rb +24 -0
  718. data/app/services/collavre/creatives/workspace_expansion_order.rb +58 -0
  719. data/app/services/collavre/creatives/workspace_expansion_presence.rb +38 -0
  720. data/app/services/collavre/creatives/workspace_tree_builder.rb +19 -11
  721. data/app/services/collavre/crons/change_broadcaster.rb +35 -0
  722. data/app/services/collavre/crons/recurring_task_arguments.rb +10 -2
  723. data/app/services/collavre/crons/recurring_task_index.rb +78 -0
  724. data/app/services/collavre/decision_questions.rb +125 -0
  725. data/app/services/collavre/http_client.rb +42 -6
  726. data/app/services/collavre/inbox_reply_service.rb +1 -0
  727. data/app/services/collavre/keep_loop.rb +84 -0
  728. data/app/services/collavre/kollavy/access_scope.rb +84 -0
  729. data/app/services/collavre/kollavy/identity.rb +25 -0
  730. data/app/services/collavre/kollavy.rb +153 -0
  731. data/app/services/collavre/llm_usage/attribution.rb +99 -0
  732. data/app/services/collavre/llm_usage/history_omission.rb +30 -0
  733. data/app/services/collavre/llm_usage/recorder.rb +59 -0
  734. data/app/services/collavre/llm_usage/report.rb +116 -0
  735. data/app/services/collavre/llm_usage/token_normalizer.rb +54 -0
  736. data/app/services/collavre/markdown_converter.rb +45 -41
  737. data/app/services/collavre/mcp_service.rb +61 -35
  738. data/app/services/collavre/mcp_tool_access.rb +40 -0
  739. data/app/services/collavre/mcp_tool_categories.rb +57 -0
  740. data/app/services/collavre/mcp_tool_registrar.rb +217 -0
  741. data/app/services/collavre/mcp_tool_registry.rb +38 -0
  742. data/app/services/collavre/mention_parser.rb +48 -14
  743. data/app/services/collavre/notices/feed.rb +127 -0
  744. data/app/services/collavre/notices/onboarding_replay.rb +17 -0
  745. data/app/services/collavre/notices/refresh_deadline.rb +15 -0
  746. data/app/services/collavre/notices/tracker.rb +68 -0
  747. data/app/services/collavre/openai_endpoint.rb +24 -0
  748. data/app/services/collavre/orchestration/agent_context_builder.rb +3 -1
  749. data/app/services/collavre/orchestration/agent_orchestrator.rb +100 -451
  750. data/app/services/collavre/orchestration/agent_recovery_trigger.rb +16 -0
  751. data/app/services/collavre/orchestration/arbiter.rb +15 -8
  752. data/app/services/collavre/orchestration/deferred_trigger_scope.rb +12 -1
  753. data/app/services/collavre/orchestration/delivery_record.rb +31 -83
  754. data/app/services/collavre/orchestration/dispatch_records.rb +52 -0
  755. data/app/services/collavre/orchestration/execution_fence.rb +97 -0
  756. data/app/services/collavre/orchestration/job_enqueue.rb +150 -0
  757. data/app/services/collavre/orchestration/keep_dispatch_admission.rb +76 -0
  758. data/app/services/collavre/orchestration/keep_dispatch_restoration.rb +57 -0
  759. data/app/services/collavre/orchestration/keep_loop_ownership.rb +152 -0
  760. data/app/services/collavre/orchestration/keep_queued_dispatches.rb +73 -0
  761. data/app/services/collavre/orchestration/loop_breaker.rb +10 -5
  762. data/app/services/collavre/orchestration/matcher.rb +123 -50
  763. data/app/services/collavre/orchestration/offline_task_grace.rb +50 -0
  764. data/app/services/collavre/orchestration/policy_resolver.rb +58 -7
  765. data/app/services/collavre/orchestration/resource_tracker.rb +4 -1
  766. data/app/services/collavre/orchestration/restored_dispatch_admission.rb +103 -0
  767. data/app/services/collavre/orchestration/restored_dispatch_context.rb +15 -0
  768. data/app/services/collavre/orchestration/resume_context.rb +90 -0
  769. data/app/services/collavre/orchestration/scheduler.rb +9 -2
  770. data/app/services/collavre/orchestration/selection.rb +40 -7
  771. data/app/services/collavre/orchestration/solid_queue_retry_recovery.rb +54 -0
  772. data/app/services/collavre/orchestration/task_coalescer.rb +52 -22
  773. data/app/services/collavre/orchestration/task_resumer.rb +408 -0
  774. data/app/services/collavre/orchestration/waiting_notice_manager.rb +289 -0
  775. data/app/services/collavre/orchestration/workflow_dispatch.rb +47 -0
  776. data/app/services/collavre/orchestration/workflow_routing.rb +96 -0
  777. data/app/services/collavre/ppt_archive.rb +123 -0
  778. data/app/services/collavre/ppt_backgrounds.rb +97 -0
  779. data/app/services/collavre/ppt_colors.rb +104 -0
  780. data/app/services/collavre/ppt_connectors.rb +33 -0
  781. data/app/services/collavre/ppt_diagrams.rb +50 -0
  782. data/app/services/collavre/ppt_formatting.rb +134 -0
  783. data/app/services/collavre/ppt_geometry.rb +92 -0
  784. data/app/services/collavre/ppt_importer.rb +45 -64
  785. data/app/services/collavre/ppt_inheritance.rb +122 -0
  786. data/app/services/collavre/ppt_inline_media.rb +19 -0
  787. data/app/services/collavre/ppt_media.rb +49 -0
  788. data/app/services/collavre/ppt_numbering.rb +63 -0
  789. data/app/services/collavre/ppt_paragraphs.rb +52 -0
  790. data/app/services/collavre/ppt_preview.rb +12 -0
  791. data/app/services/collavre/ppt_renderer.rb +259 -0
  792. data/app/services/collavre/ppt_shape_fills.rb +35 -0
  793. data/app/services/collavre/ppt_shape_styles.rb +81 -0
  794. data/app/services/collavre/ppt_tables.rb +35 -0
  795. data/app/services/collavre/public_asset_allowlist.rb +41 -0
  796. data/app/services/collavre/quota/agent_execution.rb +31 -0
  797. data/app/services/collavre/quota/exceeded_error.rb +48 -0
  798. data/app/services/collavre/quota/notice.rb +15 -0
  799. data/app/services/collavre/quota/pending_dispatch.rb +35 -0
  800. data/app/services/collavre/quota/probe.rb +44 -0
  801. data/app/services/collavre/quota/recovery.rb +97 -0
  802. data/app/services/collavre/quota/retry_time.rb +65 -0
  803. data/app/services/collavre/ruby_llm_interaction_logger.rb +17 -7
  804. data/app/services/collavre/screening/gate.rb +47 -0
  805. data/app/services/collavre/screening/input.rb +30 -0
  806. data/app/services/collavre/screening/scope.rb +34 -0
  807. data/app/services/collavre/screening/screener.rb +57 -0
  808. data/app/services/collavre/screening/screener_resolver.rb +23 -0
  809. data/app/services/collavre/screening/turn_guard.rb +196 -0
  810. data/app/services/collavre/screening/verdict.rb +30 -0
  811. data/app/services/collavre/screening.rb +65 -0
  812. data/app/services/collavre/source_browser.rb +186 -0
  813. data/app/services/collavre/system_events/context_builder.rb +53 -12
  814. data/app/services/collavre/system_events/dispatcher.rb +26 -17
  815. data/app/services/collavre/system_events/vocabulary.rb +4 -1
  816. data/app/services/collavre/task_execution_time.rb +33 -0
  817. data/app/services/collavre/tool_approval_policy.rb +42 -0
  818. data/app/services/collavre/tool_description.rb +35 -0
  819. data/app/services/collavre/tool_usage/approved_invocation.rb +28 -0
  820. data/app/services/collavre/tool_usage/cli_proxy_recorder.rb +100 -0
  821. data/app/services/collavre/tool_usage/mcp_call.rb +52 -0
  822. data/app/services/collavre/tool_usage/recorder.rb +34 -0
  823. data/app/services/collavre/tool_usage/report.rb +38 -0
  824. data/app/services/collavre/tools/approval_request_service.rb +54 -0
  825. data/app/services/collavre/tools/async_approval_request.rb +58 -0
  826. data/app/services/collavre/tools/creative_attach_files_service.rb +10 -2
  827. data/app/services/collavre/tools/creative_batch_service.rb +90 -10
  828. data/app/services/collavre/tools/creative_create_service.rb +33 -4
  829. data/app/services/collavre/tools/creative_import_service.rb +26 -3
  830. data/app/services/collavre/tools/creative_link_service.rb +75 -0
  831. data/app/services/collavre/tools/creative_list_attachments_service.rb +2 -2
  832. data/app/services/collavre/tools/creative_remove_attachment_service.rb +30 -5
  833. data/app/services/collavre/tools/creative_reorder_service.rb +111 -0
  834. data/app/services/collavre/tools/creative_retrieval_service.rb +27 -21
  835. data/app/services/collavre/tools/creative_unlink_service.rb +60 -0
  836. data/app/services/collavre/tools/creative_update_service.rb +88 -81
  837. data/app/services/collavre/tools/cron_cancel_service.rb +3 -17
  838. data/app/services/collavre/tools/cron_create_service.rb +91 -36
  839. data/app/services/collavre/tools/cron_list_service.rb +2 -2
  840. data/app/services/collavre/tools/cron_update_service.rb +5 -19
  841. data/app/services/collavre/tools/keep_service.rb +42 -0
  842. data/app/services/collavre/tools/source_list_service.rb +25 -0
  843. data/app/services/collavre/tools/source_read_service.rb +26 -0
  844. data/app/services/collavre/tools/source_search_service.rb +25 -0
  845. data/app/services/collavre/tools/source_tool_support.rb +39 -0
  846. data/app/services/collavre/tools/task_descendants.rb +32 -0
  847. data/app/services/collavre/tools/task_lineage.rb +46 -0
  848. data/app/services/collavre/tools/task_status_service.rb +61 -0
  849. data/app/services/collavre/tools/task_tracking.rb +67 -0
  850. data/app/services/collavre/tools/topic_authorizer.rb +2 -2
  851. data/app/services/collavre/tools/topic_message_create_service.rb +35 -17
  852. data/app/services/collavre/tools/topic_move_service.rb +3 -4
  853. data/app/services/collavre/tools/topic_tasks_service.rb +42 -0
  854. data/app/services/collavre/tools/topic_update_service.rb +1 -1
  855. data/app/services/collavre/topic_branch_service.rb +1 -0
  856. data/app/services/collavre/topics/active_topic_snapshot.rb +30 -0
  857. data/app/services/collavre/topics/agent_resolver.rb +7 -1
  858. data/app/services/collavre/topics/cron_badge_decorator.rb +32 -0
  859. data/app/services/collavre/topics/last_topic_preference_payload.rb +1 -0
  860. data/app/services/collavre/topics/message_page.rb +1 -1
  861. data/app/services/collavre/topics/orphaned_cron_notifier.rb +33 -14
  862. data/app/services/collavre/topics/pin_rejection.rb +16 -2
  863. data/app/services/collavre/topics/reserved_name.rb +6 -0
  864. data/app/services/collavre/topics/serializer.rb +10 -3
  865. data/app/services/collavre/topics/topic_move.rb +21 -2
  866. data/app/services/collavre/trigger_loop_config.rb +15 -0
  867. data/app/services/collavre/workflow/admission.rb +109 -0
  868. data/app/services/collavre/workflow/child_context.rb +35 -0
  869. data/app/services/collavre/workflow/conditions.rb +79 -0
  870. data/app/services/collavre/workflow/context_preloader.rb +48 -0
  871. data/app/services/collavre/workflow/continuation.rb +16 -0
  872. data/app/services/collavre/workflow/dispatch_identity.rb +25 -0
  873. data/app/services/collavre/workflow/dispatch_outcome.rb +9 -0
  874. data/app/services/collavre/workflow/editor.rb +79 -0
  875. data/app/services/collavre/workflow/envelope_validation.rb +18 -0
  876. data/app/services/collavre/workflow/fallback_delivery.rb +59 -0
  877. data/app/services/collavre/workflow/fixed_anchor.rb +32 -0
  878. data/app/services/collavre/workflow/human_handoff.rb +39 -0
  879. data/app/services/collavre/workflow/inbox_notice.rb +56 -0
  880. data/app/services/collavre/workflow/invocation.rb +60 -0
  881. data/app/services/collavre/workflow/materialization.rb +41 -0
  882. data/app/services/collavre/workflow/publication.rb +55 -0
  883. data/app/services/collavre/workflow/push_delivery.rb +97 -0
  884. data/app/services/collavre/workflow/recovery.rb +62 -0
  885. data/app/services/collavre/workflow/resolver.rb +83 -0
  886. data/app/services/collavre/workflow/rule.rb +189 -0
  887. data/app/services/collavre/workflow/safety.rb +61 -0
  888. data/app/services/collavre/workflow/settlement.rb +60 -0
  889. data/app/services/collavre/workflow/source_message.rb +39 -0
  890. data/app/services/collavre/workflow/task_admission.rb +114 -0
  891. data/app/views/collavre/admin/settings/_system_tab.html.erb +49 -11
  892. data/app/views/collavre/agent_connections/show.html.erb +76 -69
  893. data/app/views/collavre/agent_gateways/_form.html.erb +69 -55
  894. data/app/views/collavre/agent_gateways/edit.html.erb +4 -2
  895. data/app/views/collavre/agent_gateways/index.html.erb +48 -51
  896. data/app/views/collavre/agent_gateways/new.html.erb +4 -2
  897. data/app/views/collavre/agent_models/_editor.html.erb +20 -0
  898. data/app/views/collavre/comments/_activity_log_details.html.erb +10 -4
  899. data/app/views/collavre/comments/_agent_run_options.html.erb +12 -0
  900. data/app/views/collavre/comments/_approval_gate.html.erb +8 -0
  901. data/app/views/collavre/comments/_comment.html.erb +45 -8
  902. data/app/views/collavre/comments/_comments_popup.html.erb +81 -12
  903. data/app/views/collavre/comments/_creative_quote_review.html.erb +29 -0
  904. data/app/views/collavre/comments/_feature_card.html.erb +1 -1
  905. data/app/views/collavre/comments/_loading.html.erb +7 -0
  906. data/app/views/collavre/comments/_reaction_buttons.html.erb +7 -0
  907. data/app/views/collavre/comments/_reaction_picker.html.erb +1 -8
  908. data/app/views/collavre/comments/_run_options.html.erb +4 -0
  909. data/app/views/collavre/comments/_thinking_icon.html.erb +7 -0
  910. data/app/views/collavre/creative_change_sets/_detail.html.erb +88 -0
  911. data/app/views/collavre/creative_change_sets/_list.html.erb +40 -0
  912. data/app/views/collavre/creative_change_sets/_undo_toast.html.erb +22 -0
  913. data/app/views/collavre/creatives/_import_upload_zone.html.erb +1 -1
  914. data/app/views/collavre/creatives/_inline_edit_form.html.erb +14 -2
  915. data/app/views/collavre/creatives/_public_meta.html.erb +16 -0
  916. data/app/views/collavre/creatives/_share_modal.html.erb +9 -0
  917. data/app/views/collavre/creatives/_type_selector.html.erb +15 -0
  918. data/app/views/collavre/creatives/_workflow_panel.html.erb +71 -0
  919. data/app/views/collavre/creatives/_workspace_tree.html.erb +4 -1
  920. data/app/views/collavre/creatives/edit.html.erb +7 -4
  921. data/app/views/collavre/creatives/index.html.erb +74 -11
  922. data/app/views/collavre/creatives/ppt_previews/_markdown_document.html.erb +17 -0
  923. data/app/views/collavre/creatives/ppt_previews/show.html.erb +38 -0
  924. data/app/views/collavre/creatives/show.html.erb +1 -1
  925. data/app/views/collavre/features/index.html.erb +4 -4
  926. data/app/views/collavre/inline_agent_logins/show.html.erb +31 -0
  927. data/app/views/collavre/llm_usages/_metrics.html.erb +13 -0
  928. data/app/views/collavre/llm_usages/index.html.erb +88 -0
  929. data/app/views/collavre/notices/_payload.html.erb +5 -0
  930. data/app/views/collavre/notices/_zone.html.erb +20 -0
  931. data/app/views/collavre/seo/sitemap.xml.builder +8 -0
  932. data/app/views/collavre/seo/sitemap_index.xml.builder +8 -0
  933. data/app/views/collavre/shared/_creative_move_modal.html.erb +59 -0
  934. data/app/views/collavre/shared/_link_creative_modal.html.erb +2 -0
  935. data/app/views/collavre/shared/navigation/_help_button.html.erb +21 -2
  936. data/app/views/collavre/shared/navigation/_search_form.html.erb +14 -1
  937. data/app/views/collavre/users/_llm_fields.html.erb +26 -31
  938. data/app/views/collavre/users/_model_picker.html.erb +36 -0
  939. data/app/views/collavre/users/_tool_details.html.erb +7 -0
  940. data/app/views/collavre/users/_tool_selection.html.erb +51 -0
  941. data/app/views/collavre/users/edit_ai.html.erb +29 -24
  942. data/app/views/collavre/users/index.html.erb +96 -80
  943. data/app/views/collavre/users/new_ai.html.erb +4 -22
  944. data/app/views/collavre/users/show.html.erb +12 -29
  945. data/app/views/layouts/collavre/landing.html.erb +14 -0
  946. data/app/views/layouts/collavre/slide.html.erb +4 -1
  947. data/config/initializers/active_storage_access.rb +34 -0
  948. data/config/initializers/agent_health.rb +7 -0
  949. data/config/initializers/kollavy_feature_card.rb +11 -0
  950. data/config/initializers/mcp_discovery_access.rb +17 -0
  951. data/config/initializers/mcp_tool_usage.rb +17 -0
  952. data/config/initializers/meta_tool_access.rb +35 -0
  953. data/config/initializers/rate_limits.rb +4 -0
  954. data/config/initializers/ruby_llm_openai_cli_events.rb +43 -0
  955. data/config/initializers/ruby_llm_openai_reasoning_content.rb +8 -7
  956. data/config/initializers/screening_integration_settings.rb +5 -0
  957. data/config/initializers/task_recovery.rb +30 -0
  958. data/config/locales/admin.en.yml +19 -3
  959. data/config/locales/admin.ko.yml +19 -3
  960. data/config/locales/agent_gateway.en.yml +6 -2
  961. data/config/locales/agent_gateway.ko.yml +6 -2
  962. data/config/locales/ai_agent.en.yml +11 -0
  963. data/config/locales/ai_agent.ko.yml +11 -0
  964. data/config/locales/approval_gate.en.yml +11 -0
  965. data/config/locales/approval_gate.ko.yml +11 -0
  966. data/config/locales/claude_channel.en.yml +1 -0
  967. data/config/locales/claude_channel.ko.yml +1 -0
  968. data/config/locales/comments.en.yml +80 -18
  969. data/config/locales/comments.ko.yml +80 -18
  970. data/config/locales/contacts.en.yml +0 -5
  971. data/config/locales/contacts.ko.yml +0 -5
  972. data/config/locales/contexts.en.yml +6 -0
  973. data/config/locales/contexts.ko.yml +6 -0
  974. data/config/locales/creative_history.en.yml +62 -0
  975. data/config/locales/creative_history.ko.yml +56 -0
  976. data/config/locales/creative_types.en.yml +19 -0
  977. data/config/locales/creative_types.ko.yml +19 -0
  978. data/config/locales/creatives.en.yml +19 -51
  979. data/config/locales/creatives.ko.yml +17 -44
  980. data/config/locales/crons.en.yml +16 -0
  981. data/config/locales/crons.ko.yml +16 -0
  982. data/config/locales/dnd.en.yml +26 -0
  983. data/config/locales/dnd.ko.yml +26 -0
  984. data/config/locales/drop_trigger.en.yml +5 -16
  985. data/config/locales/drop_trigger.ko.yml +5 -16
  986. data/config/locales/features.en.yml +15 -0
  987. data/config/locales/features.ko.yml +15 -0
  988. data/config/locales/file_drop.en.yml +5 -0
  989. data/config/locales/file_drop.ko.yml +5 -0
  990. data/config/locales/inline_agent_login.en.yml +20 -0
  991. data/config/locales/inline_agent_login.ko.yml +16 -0
  992. data/config/locales/integrations.en.yml +0 -1
  993. data/config/locales/integrations.ko.yml +0 -1
  994. data/config/locales/keep.en.yml +18 -0
  995. data/config/locales/keep.ko.yml +18 -0
  996. data/config/locales/kollavy.en.yml +4 -0
  997. data/config/locales/kollavy.ko.yml +4 -0
  998. data/config/locales/landing.en.yml +2 -6
  999. data/config/locales/landing.ko.yml +2 -6
  1000. data/config/locales/llm_usages.en.yml +45 -0
  1001. data/config/locales/llm_usages.ko.yml +45 -0
  1002. data/config/locales/mcp_tools.en.yml +6 -0
  1003. data/config/locales/mcp_tools.ko.yml +6 -0
  1004. data/config/locales/notices.en.yml +52 -0
  1005. data/config/locales/notices.ko.yml +52 -0
  1006. data/config/locales/orchestration.en.yml +34 -2
  1007. data/config/locales/orchestration.ko.yml +34 -2
  1008. data/config/locales/ppt_viewer.en.yml +18 -0
  1009. data/config/locales/ppt_viewer.ko.yml +18 -0
  1010. data/config/locales/public_creatives.en.yml +6 -0
  1011. data/config/locales/public_creatives.ko.yml +6 -0
  1012. data/config/locales/quota.en.yml +5 -0
  1013. data/config/locales/quota.ko.yml +5 -0
  1014. data/config/locales/screening.en.yml +22 -0
  1015. data/config/locales/screening.ko.yml +22 -0
  1016. data/config/locales/search_popup.en.yml +2 -3
  1017. data/config/locales/search_popup.ko.yml +2 -3
  1018. data/config/locales/task_tracking.en.yml +13 -0
  1019. data/config/locales/task_tracking.ko.yml +13 -0
  1020. data/config/locales/tool_categories.en.yml +14 -0
  1021. data/config/locales/tool_categories.ko.yml +14 -0
  1022. data/config/locales/tool_descriptions.en.yml +163 -0
  1023. data/config/locales/tool_descriptions.ko.yml +163 -0
  1024. data/config/locales/tools.en.yml +26 -0
  1025. data/config/locales/tools.ko.yml +26 -0
  1026. data/config/locales/users.en.yml +19 -23
  1027. data/config/locales/users.ko.yml +19 -22
  1028. data/config/locales/workflow_editor.en.yml +62 -0
  1029. data/config/locales/workflow_editor.ko.yml +62 -0
  1030. data/config/locales/workflow_runtime.en.yml +19 -0
  1031. data/config/locales/workflow_runtime.ko.yml +19 -0
  1032. data/config/routes/account_settings.rb +4 -0
  1033. data/config/routes/agent_api.rb +6 -0
  1034. data/config/routes/agent_connections.rb +24 -0
  1035. data/config/routes/attachments.rb +2 -0
  1036. data/config/routes/comment_actions.rb +10 -0
  1037. data/config/routes/creative_attachments.rb +2 -0
  1038. data/config/routes/creative_contexts.rb +8 -0
  1039. data/config/routes/creative_history.rb +4 -0
  1040. data/config/routes/creative_preferences.rb +3 -0
  1041. data/config/routes/notices.rb +16 -0
  1042. data/config/routes/public_creatives.rb +12 -0
  1043. data/config/routes.rb +13 -42
  1044. data/db/migrate/20251204161133_set_default_routing_expression_for_ai_agents.rb +10 -3
  1045. data/db/migrate/20260903070800_add_joined_at_order_index_to_users.rb +23 -0
  1046. data/db/migrate/20260903180000_create_creative_change_history.rb +47 -0
  1047. data/db/migrate/20260903190000_add_system_kind_to_topics.rb +8 -0
  1048. data/db/migrate/20260908000000_add_last_topic_all_messages_to_user_creative_preferences.rb +5 -0
  1049. data/db/migrate/20260910000000_add_health_to_agent_gateways.rb +10 -0
  1050. data/db/migrate/20260911000000_add_endpoint_health_to_users.rb +9 -0
  1051. data/db/migrate/20260911020000_normalize_user_names_to_single_line.rb +32 -0
  1052. data/db/migrate/20260913000000_create_workflow_executions.rb +64 -0
  1053. data/db/migrate/20260913000002_add_ordinary_delivery_to_workflow_outboxes.rb +7 -0
  1054. data/db/migrate/20260913000100_add_reserved_to_workflow_executions.rb +7 -0
  1055. data/db/migrate/20260914063000_add_justify_creative_descriptions_to_users.rb +5 -0
  1056. data/db/migrate/20260922000000_create_llm_usages.rb +44 -0
  1057. data/db/migrate/20260922000001_add_expansion_save_sequences_to_users.rb +5 -0
  1058. data/db/migrate/20260922000002_deduplicate_root_creative_preferences.rb +37 -0
  1059. data/db/migrate/20260922000003_add_agent_quota_recovery.rb +7 -0
  1060. data/db/migrate/20260922000004_add_agent_quota_probe.rb +6 -0
  1061. data/db/migrate/20260922000005_add_suspension_to_tasks.rb +12 -0
  1062. data/db/migrate/20260922010000_create_retired_task_executions.rb +11 -0
  1063. data/db/migrate/20260922113000_add_emoji_comment_index_to_comment_reactions.rb +17 -0
  1064. data/db/migrate/20260922120000_create_tool_usages.rb +37 -0
  1065. data/db/migrate/20260923000000_link_tool_usages_to_agent_workspaces.rb +44 -0
  1066. data/db/migrate/20260924000000_add_agent_run_options.rb +7 -0
  1067. data/db/migrate/20260924010000_add_run_options_to_comment_versions.rb +5 -0
  1068. data/db/migrate/20260924060000_add_async_approval_recovery_to_comments.rb +24 -0
  1069. data/db/migrate/20260924070000_add_async_approval_task_to_comments.rb +22 -0
  1070. data/db/migrate/20260929000000_create_user_notices.rb +14 -0
  1071. data/db/migrate/20260929010000_add_system_agent_to_users.rb +5 -0
  1072. data/db/migrate/20260929120000_add_actor_lookup_index_to_creative_change_sets.rb +19 -0
  1073. data/db/migrate/20261008000000_add_public_id_to_creatives.rb +6 -0
  1074. data/db/migrate/20261008010000_backfill_public_creative_ids.rb +26 -0
  1075. data/db/migrate/20261012000000_create_blob_access_flags.rb +17 -0
  1076. data/db/migrate/20261012000001_publish_landing_public_assets.rb +16 -0
  1077. data/db/migrate/20261014000000_backfill_implicit_main_cron_topics.rb +38 -0
  1078. data/db/migrate/20261016000000_add_trigger_comment_id_to_tasks.rb +21 -0
  1079. data/db/migrate/20261016000001_index_task_event_causation.rb +20 -0
  1080. data/db/migrate/20261016000002_index_task_merged_instructions.rb +25 -0
  1081. data/db/migrate/20261019000000_add_quoted_creative_to_comments.rb +10 -0
  1082. data/db/migrate/20261028000000_add_deleting_at_to_comments.rb +5 -0
  1083. data/db/seeds.rb +3 -19
  1084. data/lib/collavre/bulk_job_enqueue.rb +145 -0
  1085. data/lib/collavre/engine.rb +11 -6
  1086. data/lib/collavre/feature_card_registry.rb +8 -2
  1087. data/lib/collavre/notice_registry.rb +179 -0
  1088. data/lib/collavre/onboarding_notices.rb +107 -0
  1089. data/lib/collavre/profile_preferences.rb +17 -0
  1090. data/lib/collavre/stylesheets_helper.rb +72 -0
  1091. data/lib/collavre/version.rb +1 -1
  1092. data/lib/collavre.rb +12 -0
  1093. data/lib/generators/collavre/install/install_generator.rb +50 -8
  1094. data/lib/generators/collavre/install/templates/build.cjs.tt +1 -0
  1095. data/lib/tasks/public_assets.rake +24 -0
  1096. data/skills/collavre/SKILL.md +42 -0
  1097. data/skills/collavre/references/tool-authoring.md +121 -0
  1098. data/skills/collavre/references/tool-reference.md +98 -0
  1099. data/skills/collavre/scripts/collavre +30 -11
  1100. metadata +774 -7
  1101. data/config/locales/notifications.en.yml +0 -8
  1102. data/config/locales/notifications.ko.yml +0 -8
  1103. /data/app/javascript/{utils/drag_bundle_image.js → lib/dnd/bundle_image.js} +0 -0
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Collavre
4
+ class Comment
5
+ # When a human user comments in a trigger topic that is awaiting user
6
+ # input, auto-resume the trigger loop so the agent can continue working.
7
+ module TriggerLoopResume
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ after_create_commit :resume_trigger_loop_if_awaiting, unless: :skip_dispatch
12
+ end
13
+
14
+ private
15
+
16
+ def resume_trigger_loop_if_awaiting
17
+ return unless trigger_loop_resume_candidate?
18
+ # Lock-free precheck on a fresh read: almost every comment lands on a
19
+ # creative with no loop awaiting this topic, and must not pay for a
20
+ # write transaction + row lock just to find that out.
21
+ return unless trigger_loop_resumable?(Creative.where(id: creative.id).pick(:data))
22
+
23
+ # Claim and dispatch roll back together under topic -> creative locks.
24
+ Comments::TopicMutation.call(topic_id, creative.id) do
25
+ progress = claim_awaiting_trigger_loop
26
+ post_loop_resume(*progress) if progress
27
+ end
28
+ rescue StandardError => e
29
+ Rails.logger.error(
30
+ "[Comment#resume_trigger_loop_if_awaiting] Failed for comment #{id}: " \
31
+ "#{e.class} #{e.message}"
32
+ )
33
+ end
34
+
35
+ # Human, public, non-approval replies only: private input is absent from
36
+ # agent history, and the approval surface is not a user-resume signal.
37
+ def trigger_loop_resume_candidate?
38
+ public_human_loop_reply? && creative.present?
39
+ end
40
+
41
+ # True when the loop is awaiting user input and this comment is in its
42
+ # trigger topic (or the loop has no trigger topic recorded).
43
+ def trigger_loop_resumable?(data)
44
+ loop_data = data&.dig("trigger", "loop")
45
+ return false unless loop_data.is_a?(Hash) && loop_data["state"] == "awaiting_user"
46
+ return false if id.present? && loop_data["current_comment_id"] == id
47
+
48
+ trigger_topic_id = loop_data["trigger_topic_id"]
49
+ trigger_topic_id.blank? || trigger_topic_id == topic_id
50
+ end
51
+
52
+ # Pessimistic lock prevents duplicate resumes from concurrent comments.
53
+ # Returns [iteration, max, snapshot] when this comment moved the loop to
54
+ # running, nil when the re-check under the lock finds it no longer
55
+ # resumable (e.g. a concurrent comment resumed it after the precheck, or
56
+ # the selected keep agent became unavailable).
57
+ def claim_awaiting_trigger_loop
58
+ creative.with_lock do
59
+ data = creative.data
60
+ next unless trigger_loop_resumable?(data)
61
+ next if creative.keep_loop_agent_unavailable?
62
+ # A public reply already sent through ordinary routing must not also
63
+ # resume a newly blocked keep turn.
64
+ if @keep_reply_dispatch_checked && creative.keep_loop?
65
+ next unless data.dig("trigger", "loop") == @blocked_keep_reply_snapshot
66
+ end
67
+
68
+ loop_cfg = data["trigger"]["loop"]
69
+ loop_cfg["generation"] = Collavre::KeepLoop.next_generation!(data) if loop_cfg["source"] == "keep"
70
+ loop_cfg["state"] = "running"
71
+ creative.update!(data: data)
72
+ [ loop_cfg["current_iteration"] || 0, loop_cfg["max_iterations"] || 10, loop_cfg.deep_dup ]
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -4,7 +4,7 @@ module Collavre
4
4
 
5
5
  STREAMING_PLACEHOLDER_CONTENT = "..."
6
6
  # Authorless "⏳" waiting-notice system messages posted when an agent is
7
- # deferred for topic concurrency. AgentOrchestrator.cleanup_waiting_notices!
7
+ # deferred for topic concurrency. WaitingNoticeManager.cleanup_waiting_notices!
8
8
  # matches the same prefix to remove them once the waiter is dequeued.
9
9
  WAITING_NOTICE_PREFIX = "⏳"
10
10
 
@@ -29,7 +29,7 @@ module Collavre
29
29
  #
30
30
  # It therefore comes down wherever the waiter leaves, which is why this
31
31
  # lives here beside the columns rather than in one of those callers: the
32
- # promotion (AgentOrchestrator.cleanup_waiter_notice!) and the fold
32
+ # promotion (WaitingNoticeManager.cleanup_waiter_notice!) and the fold
33
33
  # (Orchestration::TaskCoalescer) are two doors onto the same rule, and a
34
34
  # third would otherwise write its own copy or forget.
35
35
  #
@@ -137,15 +137,10 @@ module Collavre
137
137
  belongs_to :topic, class_name: "Collavre::Topic", optional: true
138
138
  belongs_to :quoted_comment, class_name: "Collavre::Comment", optional: true
139
139
 
140
- scope :public_only, -> { where(private: false) }
141
-
142
- # SQL inverse of Comment#approval_action? (action.present?). Approval-surface
143
- # messages must never reach an AI agent — not only at the dispatch seams but
144
- # also as chat-history/trigger context — so agent-context queries exclude them.
145
- scope :without_approval_action, -> { where("action IS NULL OR action = ''") }
140
+ scope :public_only, -> { not_deleting.where(private: false) }
146
141
 
147
142
  scope :visible_to, ->(user) {
148
- where(
143
+ not_deleting.where(
149
144
  "comments.private = ? OR comments.user_id = ? OR comments.approver_id = ?",
150
145
  false, user.id, user.id
151
146
  )
@@ -167,16 +162,17 @@ module Collavre
167
162
 
168
163
  has_many_attached :images, dependent: :purge_later
169
164
 
165
+ include KeepLoop
170
166
  include Broadcastable
171
167
  include Notifiable
172
168
  include Approvable
173
- include ClaudeChannelPermission
169
+ include ClaudeChannelPermission, CreationEvents, ImageCdnEviction, BulkFollowUpJobs, CreativeQuote, BatchDestruction
174
170
 
175
171
  attribute :skip_default_user, :boolean, default: false
176
172
  attribute :skip_dispatch, :boolean, default: false
177
173
  attribute :skip_link_preview, :boolean, default: false
178
174
  attribute :skip_notification_revision, :boolean, default: false
179
- # Set by AgentOrchestrator.cleanup_waiting_notices! so destroying a notice as
175
+ # Set by WaitingNoticeManager.cleanup_waiting_notices! so destroying a notice as
180
176
  # part of *promoting* a waiter does not run the user-delete cancel cascade
181
177
  # (which would cancel other still-queued waiters in the same topic).
182
178
  attribute :suppress_waiter_cancellation, :boolean, default: false
@@ -184,16 +180,15 @@ module Collavre
184
180
  before_validation :use_origin_creative
185
181
  before_validation :assign_default_user, on: :create
186
182
  include TopicMembership
183
+ include DispatchRevocation
187
184
  after_commit :enqueue_link_preview, on: [ :create, :update ], if: :link_preview_enqueue_required?
188
185
  after_create_commit :dispatch_to_orchestration
189
- after_create_commit :resume_trigger_loop_if_awaiting
186
+ include TriggerLoopResume
190
187
 
191
188
  validates :content, presence: true, unless: -> { images.attached? }
192
189
  validate :creative_must_be_origin_creative
193
190
  validate :images_must_be_images
194
191
 
195
- after_destroy_commit :cancel_pending_tasks
196
-
197
192
  def next_version_number
198
193
  (comment_versions.maximum(:version_number) || 0) + 1
199
194
  end
@@ -235,7 +230,8 @@ module Collavre
235
230
  content: content,
236
231
  user_id: user_id,
237
232
  from_ai: user&.searchable? || false,
238
- quoted_comment_id: quoted_comment_id
233
+ quoted_comment_id: quoted_comment_id,
234
+ keep_loop_generation: dispatch_loop_generation
239
235
  }.compact,
240
236
  creative: {
241
237
  id: creative_id,
@@ -244,9 +240,7 @@ module Collavre
244
240
  topic: {
245
241
  id: topic_id
246
242
  },
247
- chat: {
248
- content: content
249
- }
243
+ chat: loop_dispatch_chat
250
244
  }
251
245
  end
252
246
 
@@ -259,15 +253,12 @@ module Collavre
259
253
  def cancel_pending_tasks
260
254
  stranded_scopes = []
261
255
 
262
- # Cancel tasks triggered by this comment (no creative_id scoping —
256
+ # Cancel tasks anchored to or rendering this merged comment (no creative_id scoping —
263
257
  # CommentMoveService can change comment.creative_id without updating
264
258
  # existing tasks, so scoping would miss moved-comment tasks).
265
- # Include "delegated" so a deleted prompt also cancels Claude Channel
266
- # work that's still waiting on an external MCP reply — otherwise the
267
- # delegated task keeps holding the topic/agent slot until stuck recovery.
268
- Task.where(status: %w[pending running queued delegated]).find_each do |task|
269
- next unless task.trigger_event_payload&.dig("comment", "id") == id
270
-
259
+ # Include approval-paused and delegated work: both can resume side effects
260
+ # after withdrawal and keep holding the topic/agent slot without a worker.
261
+ active_tasks_for_withdrawal.each do |task|
271
262
  # An un-started task can be the survivor of a coalesced burst, answering
272
263
  # several comments at once. Cancelling it because its anchor was deleted
273
264
  # would throw away the absorbed comments too — they have no task of their
@@ -275,10 +266,8 @@ module Collavre
275
266
  # (session-backed agents receive only the trigger). Re-anchor onto the
276
267
  # newest surviving merged comment instead; only a task with nothing left
277
268
  # to say is cancelled.
278
- next if reanchor_coalesced_task(task)
279
-
280
- was_delegated = task.status == "delegated"
281
- task.update!(status: "cancelled")
269
+ previous_status = cancel_task_for_withdrawn_source(task)
270
+ next unless previous_status
282
271
 
283
272
  # A waiter cancelled here leaves the queue without ever being promoted,
284
273
  # exactly as a folded one does — so the notice that spoke for it is left
@@ -297,10 +286,9 @@ module Collavre
297
286
  # loop, once every task this deletion cancels has left the queue.
298
287
  stranded_scopes << [ task.creative_id, task.topic_id ]
299
288
 
300
- # Delegated tasks live past their job: the AiAgentJob already returned,
301
- # holding the agent slot under task.id and counting against the per-topic
302
- # serializer. Mirror the cancel path used elsewhere to free both.
303
- next unless was_delegated
289
+ # Match explicit Stop: these states have no worker to release their
290
+ # reservation and drain the topic queue after cancellation.
291
+ next unless Task::HELD_SLOT_WITHOUT_WORKER.include?(previous_status)
304
292
  if task.agent
305
293
  Collavre::Orchestration::ResourceTracker.for(task.agent).release!(task.id)
306
294
  end
@@ -336,15 +324,6 @@ module Collavre
336
324
  # Only un-started tasks: a `running`/`delegated` task has already been handed
337
325
  # its payload, so re-anchoring changes nothing and deleting the prompt must
338
326
  # still stop the turn.
339
- def reanchor_coalesced_task(task)
340
- return false unless %w[queued pending].include?(task.status)
341
-
342
- Task.transaction { reanchor_locked_task(task) }
343
- rescue ActiveRecord::RecordNotFound
344
- # The task went away between the scan and the lock (a cascading delete).
345
- # Nothing to rescue, and nothing left to cancel either.
346
- false
347
- end
348
327
 
349
328
  # The lock body. `task` is the object cancel_pending_tasks' scan loaded, and
350
329
  # everything derived here has to come from the row as it stands *now*:
@@ -362,11 +341,11 @@ module Collavre
362
341
  # handed its payload — deleting the prompt must stop it, not re-target it.
363
342
  def reanchor_locked_task(task)
364
343
  task.lock!
344
+ return false if task.workflow?
365
345
  return false unless %w[queued pending].include?(task.status)
366
346
 
367
347
  payload = task.trigger_event_payload || {}
368
- merged = Array(payload[Collavre::Orchestration::TaskCoalescer::PAYLOAD_KEY])
369
- .compact.map(&:to_i).uniq - [ id ]
348
+ merged = dispatch_source_ids(task) - [ id ]
370
349
  return false if merged.empty?
371
350
 
372
351
  # Anything else in the merge window may have been deleted too. Newest by id:
@@ -397,7 +376,8 @@ module Collavre
397
376
  .in_turn(merged, "creative" => { "id" => task.creative_id },
398
377
  "topic" => { "id" => task.topic_id })
399
378
  .order(:id).to_a
400
- replacement = in_scope.last
379
+ # Withdrawing a merged source need not move a still-valid anchor.
380
+ replacement = in_scope.find { |comment| comment.id == payload.dig("comment", "id").to_i } || in_scope.last
401
381
  return false unless replacement
402
382
 
403
383
  # Through the same door the refresh uses, so the promotion is recorded as
@@ -412,6 +392,8 @@ module Collavre
412
392
  Collavre::Orchestration::TaskCoalescer::PAYLOAD_KEY =>
413
393
  (in_scope.map(&:id) - [ replacement.id ]).sort
414
394
  )
395
+ return false unless replay_route_preserved?(task, payload)
396
+
415
397
  task.update!(trigger_event_payload: payload)
416
398
 
417
399
  Rails.logger.info(
@@ -426,7 +408,7 @@ module Collavre
426
408
  # Cancelling one was right while each deferral posted its own notice: the
427
409
  # newest queued task was the one that notice belonged to. A topic now gets
428
410
  # exactly one deduplicated notice
429
- # (Orchestration::AgentOrchestrator.with_deduped_topic_notice), and with
411
+ # (Orchestration::WaitingNoticeManager.with_deduped_topic_notice), and with
430
412
  # topic_max_concurrent_jobs > 1 it can stand for waiters from several agents
431
413
  # — coalescing folds same-agent siblings only. Deleting it while cancelling
432
414
  # one of them leaves the rest queued with nothing on screen representing
@@ -549,7 +531,7 @@ module Collavre
549
531
  # Orchestration::Matcher, which scopes a Claude session agent to its own
550
532
  # registered session topic — keeping non-System topics truly identical to a
551
533
  # normal topic whether or not a session is live.
552
- return if creative.inbox? && inbox_system_topic?
534
+ return if orchestration_topic_blocked?
553
535
 
554
536
  # A Claude Channel session suspended on a native tool-permission prompt
555
537
  # parks its in-flight dispatch as a `delegated` task carrying a
@@ -565,7 +547,7 @@ module Collavre
565
547
  # when the local Claude TUI answered the prompt, leaving pending_tool_call
566
548
  # set on the server for the rest of a locally-approved tool run.
567
549
 
568
- SystemEvents::Dispatcher.dispatch("comment_created", dispatch_payload, source: "comment_callback")
550
+ dispatch_loop_comment
569
551
  rescue StandardError => e
570
552
  Rails.logger.error(
571
553
  "[Comment#dispatch_to_orchestration] Failed for comment #{id}: " \
@@ -587,64 +569,6 @@ module Collavre
587
569
  self.user ||= Collavre.current_user
588
570
  end
589
571
 
590
- # When a human user comments in a trigger topic that is awaiting user input,
591
- # auto-resume the trigger loop so the agent can continue working.
592
- def resume_trigger_loop_if_awaiting
593
- return unless user_id # must have a user (not system)
594
- return if user&.ai_user? # must be a human, not an AI agent
595
- return if approval_action? # approval surface is not a user-resume signal; the resumed @agent turn would otherwise carry it into history
596
- return unless creative
597
-
598
- # Use pessimistic lock to prevent duplicate resume from concurrent comments
599
- iteration = nil
600
- max = nil
601
- creative.with_lock do
602
- loop_data = creative.data&.dig("trigger", "loop")
603
- return unless loop_data && loop_data["state"] == "awaiting_user"
604
-
605
- # Only resume if this comment is in the trigger topic
606
- trigger_topic_id = loop_data["trigger_topic_id"]
607
- return if trigger_topic_id.present? && trigger_topic_id != topic_id
608
-
609
- # Transition to running and post continue instruction atomically
610
- data = creative.data || {}
611
- trigger = data["trigger"] || {}
612
- loop_cfg = trigger["loop"] || {}
613
- iteration = loop_cfg["current_iteration"] || 0
614
- max = loop_cfg["max_iterations"] || 10
615
- loop_cfg["state"] = "running"
616
- trigger["loop"] = loop_cfg
617
- data["trigger"] = trigger
618
- creative.update!(data: data)
619
- end
620
-
621
- # Post continue instruction outside lock (state already committed)
622
- return unless iteration # guard: lock block returned early
623
-
624
- parent = creative.parent
625
- return unless parent&.drop_trigger_enabled?
626
-
627
- agent = parent.find_ai_agent(:write)
628
- return unless agent
629
-
630
- creative.comments.create!(
631
- content: "@#{agent.name}: #{I18n.t(
632
- 'collavre.trigger_loop.user_resumed',
633
- iteration: iteration,
634
- max: max
635
- )}",
636
- topic_id: topic_id,
637
- private: false,
638
- user: creative.user,
639
- skip_dispatch: false
640
- )
641
- rescue StandardError => e
642
- Rails.logger.error(
643
- "[Comment#resume_trigger_loop_if_awaiting] Failed for comment #{id}: " \
644
- "#{e.class} #{e.message}"
645
- )
646
- end
647
-
648
572
  def use_origin_creative
649
573
  return unless creative
650
574
  self.creative = creative.effective_origin
@@ -9,11 +9,18 @@ module Collavre
9
9
  validates :delivery_key, :recipient_id, :message, presence: true
10
10
 
11
11
  scope :ready_for_push, -> {
12
- where(push_enqueued_at: nil)
12
+ ordinary = where(workflow_execution_id: nil, push_enqueued_at: nil)
13
13
  .where("push_claimed_at IS NULL OR push_claimed_at < ?", CLAIM_TIMEOUT.ago)
14
+ ordinary.or(Workflow::PushDelivery.ready(where.not(workflow_execution_id: nil)))
14
15
  }
15
16
 
16
17
  def enqueue_push!
18
+ return Workflow::PushDelivery.new(self).enqueue! if workflow_execution_id
19
+
20
+ enqueue_ordinary_push!
21
+ end
22
+
23
+ def enqueue_ordinary_push!
17
24
  claim_token = SecureRandom.uuid
18
25
  claimed_at = Time.current
19
26
  claimed = self.class.ready_for_push
@@ -32,6 +39,17 @@ module Collavre
32
39
  raise enqueue_error || ActiveJob::EnqueueError.new("Push notification enqueue failed")
33
40
  end
34
41
 
42
+ acknowledge_ordinary_push!(claim_token)
43
+
44
+ true
45
+ rescue StandardError
46
+ release_claim(claim_token)
47
+ raise
48
+ end
49
+
50
+ private
51
+
52
+ def acknowledge_ordinary_push!(claim_token)
35
53
  acknowledged = self.class
36
54
  .where(id: id, push_claim_token: claim_token, push_enqueued_at: nil)
37
55
  .update_all(
@@ -41,15 +59,8 @@ module Collavre
41
59
  updated_at: Time.current
42
60
  )
43
61
  raise ActiveRecord::StaleObjectError.new(self, "enqueue push") unless acknowledged == 1
44
-
45
- true
46
- rescue StandardError
47
- release_claim(claim_token)
48
- raise
49
62
  end
50
63
 
51
- private
52
-
53
64
  def release_claim(claim_token)
54
65
  self.class.where(id: id, push_claim_token: claim_token).update_all(
55
66
  push_claim_token: nil,
@@ -7,6 +7,10 @@ module Collavre
7
7
  belongs_to :comment, class_name: "Collavre::Comment", counter_cache: true
8
8
  belongs_to :review_comment, class_name: "Collavre::Comment", optional: true
9
9
 
10
+ def comment_attributes
11
+ { content: content, agent_run_options: agent_run_options, selected_version_id: id }
12
+ end
13
+
10
14
  validates :content, presence: true
11
15
  validates :version_number, presence: true,
12
16
  uniqueness: { scope: :comment_id },
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Collavre
4
+ class Creative < ApplicationRecord
5
+ module AiWritePolicy
6
+ extend ActiveSupport::Concern
7
+
8
+ POLICIES = %w[auto review].freeze
9
+ DEFAULT_POLICY = "auto"
10
+
11
+ def effective_ai_write_policy(visited_ids = Set.new)
12
+ return DEFAULT_POLICY if visited_ids.include?(id)
13
+
14
+ visited_ids.add(id)
15
+ own_policy = data&.dig("ai_write_policy").to_s
16
+ return own_policy if own_policy.in?(POLICIES)
17
+
18
+ parent&.effective_ai_write_policy(visited_ids) || DEFAULT_POLICY
19
+ end
20
+
21
+ def ai_write_review?
22
+ effective_ai_write_policy == "review"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,153 @@
1
+ module Collavre
2
+ class Creative < ApplicationRecord
3
+ # Context creatives injected into AI prompts: direct and inherited IDs, the
4
+ # disabled set, and the user-arranged display/injection order.
5
+ module Contextual
6
+ extend ActiveSupport::Concern
7
+
8
+ # Returns the directly-configured context creative IDs for this creative.
9
+ def context_ids
10
+ data.is_a?(Hash) ? context_id_list(data["context_ids"]) : []
11
+ end
12
+
13
+ # Returns the directly-configured disabled context IDs for this creative.
14
+ def disabled_context_ids
15
+ data.is_a?(Hash) ? context_id_list(data["disabled_context_ids"]) : []
16
+ end
17
+
18
+ # Returns the effective context IDs: own + inherited from ancestors (deduplicated).
19
+ def effective_context_ids(visited_ids = Set.new)
20
+ return [] if visited_ids.include?(id)
21
+
22
+ visited_ids.add(id)
23
+ own = context_ids
24
+ parent_ctx = parent&.effective_context_ids(visited_ids) || []
25
+ (own + parent_ctx).uniq
26
+ end
27
+
28
+ # Returns the effective disabled context IDs: own + inherited from ancestors (deduplicated).
29
+ def effective_disabled_context_ids(visited_ids = Set.new)
30
+ return [] if visited_ids.include?(id)
31
+
32
+ visited_ids.add(id)
33
+ own = disabled_context_ids
34
+ parent_disabled = parent&.effective_disabled_context_ids(visited_ids) || []
35
+ (own + parent_disabled).uniq
36
+ end
37
+
38
+ # Returns the user-arranged context order saved on this creative.
39
+ def context_order
40
+ data.is_a?(Hash) ? context_id_list(data["context_order"]) : []
41
+ end
42
+
43
+ # Returns effective context IDs (excluding self) in the order shown in the
44
+ # chat context bar and injected into AI prompts. Ancestors' arrangement
45
+ # always wins: contexts inherited from the parent keep the parent's order,
46
+ # and only contexts newly added on this creative follow its own saved
47
+ # order (they may sit between inherited ones).
48
+ def ordered_context_ids
49
+ arranged_context_ids(Set.new, id)
50
+ end
51
+
52
+ # Contexts arranged by ancestors; their order cannot be changed here.
53
+ def inherited_ordered_context_ids
54
+ parent&.arranged_context_ids(Set[id]) || []
55
+ end
56
+
57
+ # Returns context creatives (excludes self to avoid duplication).
58
+ def context_creatives
59
+ ids = effective_context_ids
60
+ ids -= [ id ]
61
+ Creative.where(id: ids)
62
+ end
63
+
64
+ # Applies the chat context bar settings present in +settings+ (context_ids,
65
+ # context_order, disabled_context_ids, disabled_self_context). The row is
66
+ # locked and reloaded first so concurrent requests (e.g. another tab
67
+ # removing a context while this one reorders) merge into the latest data
68
+ # instead of overwriting it with a stale copy.
69
+ def update_context_settings(settings)
70
+ settings = settings.to_h.with_indifferent_access
71
+ with_lock { update(data: context_settings_data(settings)) }
72
+ end
73
+
74
+ protected
75
+
76
+ # +hidden_id+ (the viewing creative itself) is dropped before slots are
77
+ # assigned, so a hidden inherited ID cannot take a visible context's slot.
78
+ def arranged_context_ids(visited_ids = Set.new, hidden_id = nil)
79
+ return [] if visited_ids.include?(id)
80
+
81
+ visited_ids.add(id)
82
+ inherited = (parent&.arranged_context_ids(visited_ids) || []) - [ hidden_id ]
83
+ arrange_own_contexts(inherited, context_ids - inherited - [ hidden_id ])
84
+ end
85
+
86
+ private
87
+
88
+ # Sorts by this creative's saved order to pick the slots of its own new
89
+ # contexts, then refills the remaining slots with the inherited contexts
90
+ # in the ancestors' order.
91
+ def arrange_own_contexts(inherited, own_new)
92
+ order = context_order
93
+ return inherited + own_new if order.empty? || own_new.empty?
94
+
95
+ rank = order.each_with_index.to_h
96
+ slots = (inherited + own_new).each_with_index.sort_by { |cid, index| [ rank.fetch(cid, order.size), index ] }
97
+ queue = inherited.dup
98
+ slots.map { |cid, _| own_new.include?(cid) ? cid : queue.shift }
99
+ end
100
+
101
+ def context_settings_data(settings)
102
+ new_data = (data || {}).dup
103
+ apply_context_ids_setting(new_data, settings) if settings.key?(:context_ids)
104
+ apply_context_order_setting(new_data, settings[:context_order]) if settings.key?(:context_order)
105
+ new_data.delete("context_order") if new_data.key?("context_order") && new_data["context_order"].empty?
106
+ apply_disabled_context_setting(new_data, settings[:disabled_context_ids]) if settings.key?(:disabled_context_ids)
107
+ apply_disabled_self_context_setting(new_data, settings[:disabled_self_context]) if settings.key?(:disabled_self_context)
108
+ new_data
109
+ end
110
+
111
+ # Metadata is free-form JSON, so drop anything that is not a positive ID
112
+ # and normalize digit strings to integers for membership checks.
113
+ def context_id_list(values)
114
+ Array(values).filter_map { |v| v.to_i if v.is_a?(Integer) || v.to_s.match?(/\A\d+\z/) }.select(&:positive?).uniq
115
+ end
116
+
117
+ # Keeps only IDs that are still effective contexts under the lock, so a
118
+ # stale reorder from another tab cannot resurrect a just-removed context.
119
+ def apply_context_order_setting(new_data, requested)
120
+ own_ids = context_id_list(new_data["context_ids"])
121
+ effective = own_ids + (parent&.effective_context_ids || [])
122
+ new_data["context_order"] = context_id_list(requested) & effective
123
+ end
124
+
125
+ # A removed context must not keep its old slot in context_order, or
126
+ # re-adding it later would restore that slot instead of appending it.
127
+ # IDs still inherited from an ancestor remain visible, so they keep theirs.
128
+ def apply_context_ids_setting(new_data, settings)
129
+ new_ids = context_id_list(settings[:context_ids])
130
+ removed_ids = context_ids - new_ids - (parent&.effective_context_ids || [])
131
+ new_data["context_order"] = context_order - removed_ids if removed_ids.any? && new_data.key?("context_order")
132
+ new_data["context_ids"] = new_ids
133
+ end
134
+
135
+ # Only this creative's own disabled IDs are stored; ones inherited from
136
+ # ancestors stay with the ancestor.
137
+ def apply_disabled_context_setting(new_data, requested)
138
+ parent_disabled = parent&.effective_disabled_context_ids || []
139
+ inherited_only = parent_disabled - disabled_context_ids
140
+ new_data["disabled_context_ids"] = context_id_list(requested) - inherited_only
141
+ new_data.delete("disabled_context_ids") if new_data["disabled_context_ids"].empty?
142
+ end
143
+
144
+ def apply_disabled_self_context_setting(new_data, value)
145
+ if ActiveModel::Type::Boolean.new.cast(value)
146
+ new_data["disabled_self_context"] = true
147
+ else
148
+ new_data.delete("disabled_self_context")
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end