collavre 0.21.0 → 0.23.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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/assets/stylesheets/collavre/actiontext.css +251 -90
- data/app/assets/stylesheets/collavre/code_highlight.css +7 -201
- data/app/assets/stylesheets/collavre/comments_popup.css +169 -64
- data/app/assets/stylesheets/collavre/creatives.css +11 -2
- data/app/assets/stylesheets/collavre/modal_dialog.css +32 -0
- data/app/assets/stylesheets/collavre/popup.css +148 -0
- data/app/assets/stylesheets/collavre/tables.css +91 -0
- data/app/channels/collavre/agent_channel.rb +205 -0
- data/app/channels/collavre/inbox_badge_channel.rb +30 -0
- data/app/controllers/collavre/admin/integrations_controller.rb +16 -5
- data/app/controllers/collavre/api/v1/agents_controller.rb +777 -0
- data/app/controllers/collavre/api/v1/base_controller.rb +46 -0
- data/app/controllers/collavre/api/v1/mobile/agent_events_controller.rb +224 -0
- data/app/controllers/collavre/api/v1/mobile/base_controller.rb +95 -0
- data/app/controllers/collavre/api/v1/mobile/devices_controller.rb +31 -0
- data/app/controllers/collavre/api/v1/mobile/voice_commands_controller.rb +25 -0
- data/app/controllers/collavre/attachments_controller.rb +30 -2
- data/app/controllers/collavre/comments_controller.rb +1 -1
- data/app/controllers/collavre/creatives/attachments_controller.rb +79 -0
- data/app/controllers/collavre/creatives_controller.rb +107 -6
- data/app/controllers/collavre/tasks_controller.rb +21 -4
- data/app/controllers/collavre/topics_controller.rb +64 -1
- data/app/controllers/collavre/typo_corrections_controller.rb +39 -0
- data/app/controllers/concerns/collavre/comments/approval_actions.rb +57 -14
- data/app/controllers/concerns/collavre/users_controller/profile_and_settings.rb +16 -1
- data/app/controllers/concerns/collavre/users_controller/registration.rb +41 -1
- data/app/helpers/collavre/application_helper.rb +1 -0
- data/app/javascript/collavre.js +2 -0
- data/app/javascript/components/ImageResizer.jsx +9 -3
- data/app/javascript/components/InlineLexicalEditor.jsx +196 -96
- data/app/javascript/components/creative_tree_row.js +20 -3
- data/app/javascript/components/plugins/attachment_cleanup_plugin.jsx +3 -0
- data/app/javascript/components/plugins/image_upload_plugin.jsx +12 -0
- data/app/javascript/components/plugins/list_tab_indent_plugin.jsx +16 -0
- data/app/javascript/components/plugins/table_hover_actions_plugin.jsx +405 -0
- data/app/javascript/controllers/__tests__/inbox_badge_controller.test.js +73 -0
- data/app/javascript/controllers/__tests__/link_creative_controller.test.js +447 -0
- data/app/javascript/controllers/comment_controller.js +11 -5
- data/app/javascript/controllers/comment_version_controller.js +2 -1
- data/app/javascript/controllers/comments/__tests__/form_controller_double_submit.test.js +159 -0
- data/app/javascript/controllers/comments/__tests__/presence_controller.test.js +111 -2
- data/app/javascript/controllers/comments/__tests__/topics_controller_delete.test.js +94 -0
- data/app/javascript/controllers/comments/form_controller.js +21 -5
- data/app/javascript/controllers/comments/list_controller.js +35 -19
- data/app/javascript/controllers/comments/presence_controller.js +58 -6
- data/app/javascript/controllers/comments/topics_controller.js +14 -8
- data/app/javascript/controllers/creatives/__tests__/tree_controller.test.js +150 -0
- data/app/javascript/controllers/creatives/import_controller.js +2 -1
- data/app/javascript/controllers/creatives/select_mode_controller.js +2 -1
- data/app/javascript/controllers/creatives/tree_controller.js +142 -1
- data/app/javascript/controllers/image_lightbox_controller.js +2 -1
- data/app/javascript/controllers/inbox_badge_controller.js +33 -0
- data/app/javascript/controllers/index.js +4 -1
- data/app/javascript/controllers/link_creative_controller.js +451 -29
- data/app/javascript/controllers/share_modal_controller.js +4 -3
- data/app/javascript/controllers/topic_search_controller.js +2 -1
- data/app/javascript/creatives/drag_drop/event_handlers.js +14 -5
- data/app/javascript/creatives/topic_move_members_popup.js +156 -0
- data/app/javascript/creatives/tree_renderer.js +11 -0
- data/app/javascript/lib/__tests__/turbo_confirm.test.js +81 -0
- data/app/javascript/lib/__tests__/typo_correction.test.js +192 -0
- data/app/javascript/lib/api/__tests__/api_error.test.js +96 -0
- data/app/javascript/lib/api/__tests__/queue_manager.test.js +88 -1
- data/app/javascript/lib/api/api_error.js +108 -0
- data/app/javascript/lib/api/creatives.js +13 -0
- data/app/javascript/lib/api/queue_manager.js +38 -4
- data/app/javascript/lib/common_popup.js +18 -5
- data/app/javascript/lib/editor/__tests__/code_edit_view_token_parity.test.js +121 -0
- data/app/javascript/lib/editor/__tests__/code_language_roundtrip.test.js +152 -0
- data/app/javascript/lib/editor/__tests__/code_languages.test.js +93 -0
- data/app/javascript/lib/editor/code_languages.js +173 -0
- data/app/javascript/lib/editor/code_token_theme.js +41 -0
- data/app/javascript/lib/lexical/__tests__/color_import.test.js +318 -0
- data/app/javascript/lib/lexical/__tests__/image_focus.test.js +139 -0
- data/app/javascript/lib/lexical/__tests__/list_tab_indent.test.js +633 -0
- data/app/javascript/lib/lexical/__tests__/markdown_serialize.test.js +627 -0
- data/app/javascript/lib/lexical/__tests__/minimize_html.test.js +278 -0
- data/app/javascript/lib/lexical/__tests__/selection_boundary.test.js +88 -0
- data/app/javascript/lib/lexical/__tests__/table_transformer.test.js +163 -0
- data/app/javascript/lib/lexical/__tests__/trailing_paragraph.test.js +104 -0
- data/app/javascript/lib/lexical/color_import.js +186 -0
- data/app/javascript/lib/lexical/list_tab_indent.js +210 -0
- data/app/javascript/lib/lexical/markdown_serialize.js +320 -0
- data/app/javascript/lib/lexical/minimize_html.js +182 -0
- data/app/javascript/lib/lexical/selection_boundary.js +58 -0
- data/app/javascript/lib/lexical/table_transformer.js +182 -0
- data/app/javascript/lib/lexical/trailing_paragraph.js +29 -0
- data/app/javascript/lib/lexical/video_node.jsx +96 -0
- data/app/javascript/lib/turbo_confirm.js +46 -0
- data/app/javascript/lib/typo_correction.js +146 -0
- data/app/javascript/lib/utils/__tests__/confirm_dialog.test.js +88 -0
- data/app/javascript/lib/utils/__tests__/dialog.test.js +92 -0
- data/app/javascript/lib/utils/__tests__/markdown.test.js +153 -0
- data/app/javascript/lib/utils/__tests__/sanitize_description.test.js +68 -0
- data/app/javascript/lib/utils/__tests__/table_download.test.js +93 -0
- data/app/javascript/lib/utils/confirm_dialog.js +10 -0
- data/app/javascript/lib/utils/dialog.js +300 -0
- data/app/javascript/lib/utils/markdown.js +154 -67
- data/app/javascript/lib/utils/sanitize_description.js +31 -0
- data/app/javascript/lib/utils/table_download.js +15 -0
- data/app/javascript/modules/__tests__/typo_corrector.test.js +365 -0
- data/app/javascript/modules/creative_row_editor.js +110 -70
- data/app/javascript/modules/export_to_markdown.js +2 -1
- data/app/javascript/modules/lexical_inline_editor.jsx +2 -1
- data/app/javascript/modules/slide_view.js +11 -2
- data/app/javascript/modules/typo_corrector.js +534 -0
- data/app/jobs/collavre/ai_agent_job.rb +92 -3
- data/app/jobs/collavre/cancel_offline_delegated_tasks_job.rb +134 -0
- data/app/jobs/collavre/claude_channel_presence_job.rb +91 -0
- data/app/jobs/collavre/compress_job.rb +6 -2
- data/app/models/collavre/agent_subscription.rb +52 -0
- data/app/models/collavre/comment/broadcastable.rb +46 -7
- data/app/models/collavre/comment/claude_channel_permission.rb +145 -0
- data/app/models/collavre/comment/notifiable.rb +14 -4
- data/app/models/collavre/comment.rb +124 -11
- data/app/models/collavre/creative/describable.rb +220 -4
- data/app/models/collavre/creative_share.rb +1 -0
- data/app/models/collavre/task.rb +49 -5
- data/app/models/collavre/topic.rb +5 -0
- data/app/models/collavre/user.rb +61 -1
- data/app/services/collavre/agent_session_abort.rb +28 -0
- data/app/services/collavre/ai_agent/claude_channel_adapter.rb +79 -0
- data/app/services/collavre/ai_agent/response_finalizer.rb +4 -2
- data/app/services/collavre/ai_agent_service.rb +68 -49
- data/app/services/collavre/ai_client.rb +28 -10
- data/app/services/collavre/attachment_backfill.rb +26 -0
- data/app/services/collavre/auto_theme_generator.rb +1 -1
- data/app/services/collavre/creatives/breadcrumb_resolver.rb +91 -0
- data/app/services/collavre/creatives/filter_pipeline.rb +26 -42
- data/app/services/collavre/creatives/filters/search_filter.rb +12 -2
- data/app/services/collavre/creatives/index_query.rb +195 -24
- data/app/services/collavre/creatives/permission_filter.rb +50 -0
- data/app/services/collavre/creatives/reveal_path_resolver.rb +118 -0
- data/app/services/collavre/creatives/tree_builder.rb +2 -1
- data/app/services/collavre/crons/recurring_task_arguments.rb +28 -0
- data/app/services/collavre/gemini_parent_recommender.rb +1 -1
- data/app/services/collavre/inbox_reply_service.rb +5 -0
- data/app/services/collavre/markdown_converter.rb +13 -3
- data/app/services/collavre/mobile/event_summarizer.rb +40 -0
- data/app/services/collavre/orchestration/agent_orchestrator.rb +33 -7
- data/app/services/collavre/orchestration/arbiter.rb +16 -0
- data/app/services/collavre/orchestration/matcher.rb +79 -4
- data/app/services/collavre/orchestration/policy_resolver.rb +4 -3
- data/app/services/collavre/orchestration/stuck_detector.rb +146 -19
- data/app/services/collavre/tools/creative_attach_files_service.rb +29 -63
- data/app/services/collavre/tools/creative_batch_service.rb +3 -2
- data/app/services/collavre/tools/creative_create_service.rb +8 -8
- data/app/services/collavre/tools/creative_remove_attachment_service.rb +7 -5
- data/app/services/collavre/tools/creative_update_service.rb +23 -8
- data/app/services/collavre/tools/cron_list_service.rb +1 -14
- data/app/services/collavre/topics/orphaned_cron_notifier.rb +68 -0
- data/app/services/collavre/typo_corrector.rb +188 -0
- data/app/views/collavre/admin/integrations/_category.html.erb +1 -1
- data/app/views/collavre/admin/integrations/_setting_row.html.erb +27 -11
- data/app/views/collavre/comments/_comment.html.erb +15 -1
- data/app/views/collavre/comments/_comments_popup.html.erb +18 -3
- data/app/views/collavre/creatives/_inline_edit_form.html.erb +1 -0
- data/app/views/collavre/creatives/_topic_move_members_modal.html.erb +42 -0
- data/app/views/collavre/creatives/index.html.erb +14 -1
- data/app/views/collavre/creatives/slide_view.html.erb +1 -1
- data/app/views/collavre/shared/_link_creative_modal.html.erb +6 -2
- data/app/views/collavre/users/show.html.erb +3 -0
- data/app/views/collavre/users/typo_correction.html.erb +50 -0
- data/app/views/layouts/collavre/slide.html.erb +1 -0
- data/config/locales/channels.en.yml +2 -0
- data/config/locales/channels.ko.yml +2 -0
- data/config/locales/claude_channel.en.yml +16 -0
- data/config/locales/claude_channel.ko.yml +16 -0
- data/config/locales/comments.en.yml +18 -0
- data/config/locales/comments.ko.yml +18 -0
- data/config/locales/creatives.en.yml +2 -0
- data/config/locales/creatives.ko.yml +2 -0
- data/config/locales/integrations.en.yml +13 -2
- data/config/locales/integrations.ko.yml +13 -2
- data/config/locales/mobile.en.yml +16 -0
- data/config/locales/mobile.ko.yml +16 -0
- data/config/locales/orchestration.en.yml +1 -0
- data/config/locales/orchestration.ko.yml +1 -0
- data/config/locales/users.en.yml +15 -0
- data/config/locales/users.ko.yml +15 -0
- data/config/routes.rb +25 -0
- data/db/migrate/20260609000000_drop_action_text_rich_texts.rb +20 -0
- data/db/migrate/20260609005000_add_session_id_to_topics.rb +16 -0
- data/db/migrate/20260609010000_create_agent_subscriptions.rb +19 -0
- data/db/migrate/20260609020000_add_last_seen_at_to_agent_subscriptions.rb +23 -0
- data/db/migrate/20260609030000_add_session_id_to_agent_subscriptions.rb +17 -0
- data/db/migrate/20260609190659_backfill_creative_files_into_description.rb +24 -0
- data/db/migrate/20260612000000_add_topic_concurrency_defer_to_comments.rb +38 -0
- data/db/migrate/20260617090000_add_typo_correction_settings_to_users.rb +18 -0
- data/db/seeds.rb +51 -0
- data/lib/collavre/engine.rb +0 -1
- data/lib/collavre/integration_settings/key_definition.rb +6 -0
- data/lib/collavre/integration_settings/registry.rb +7 -2
- data/lib/collavre/version.rb +1 -1
- data/lib/generators/collavre/install/install_generator.rb +1 -0
- metadata +85 -3
- data/app/services/collavre/openclaw_abort_service.rb +0 -45
- data/app/services/collavre/tools/description_normalizable.rb +0 -16
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Collavre
|
|
4
|
+
class AgentChannel < ApplicationCable::Channel
|
|
5
|
+
# Heartbeat for Claude Channel presence rows. Fires for every subscription,
|
|
6
|
+
# but touch_presence is a no-op unless this connection registered a presence
|
|
7
|
+
# row (agent_id subscribe by a Claude Channel agent), so topic/legacy/non-
|
|
8
|
+
# Claude subscribers pay only an idle timer.
|
|
9
|
+
periodically :touch_presence, every: AgentSubscription::HEARTBEAT_SECONDS
|
|
10
|
+
|
|
11
|
+
# Subscribes to an agent stream for real-time dispatch notifications.
|
|
12
|
+
# Accepts either:
|
|
13
|
+
# - agent_id: per-agent stream — used by MCP plugin clients (Claude
|
|
14
|
+
# Channel) so they receive every dispatch routed to the agent, no
|
|
15
|
+
# matter which topic triggered it. Authorized by created_by ownership.
|
|
16
|
+
# - topic_id: per-topic stream — legacy/UI listeners scoped to one topic.
|
|
17
|
+
def subscribed
|
|
18
|
+
return reject unless current_user
|
|
19
|
+
|
|
20
|
+
if params[:agent_id].present?
|
|
21
|
+
subscribe_to_agent_stream
|
|
22
|
+
elsif params[:topic_id].present?
|
|
23
|
+
subscribe_to_topic_stream
|
|
24
|
+
else
|
|
25
|
+
reject
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# When the MCP process crashes or the WebSocket drops before the plugin
|
|
30
|
+
# can call DELETE /api/v1/agent/:id, a Claude Channel session would
|
|
31
|
+
# otherwise stay matchable (routing_expression: "true") and any future
|
|
32
|
+
# comment on a creative still shared with the agent would dispatch into an
|
|
33
|
+
# empty stream — delegated work that only clears via stuck recovery.
|
|
34
|
+
#
|
|
35
|
+
# One shared agent can have MANY concurrent sessions, so routing is gated
|
|
36
|
+
# on PRESENCE: this session drops its own AgentSubscription row, and
|
|
37
|
+
# routing is cleared only when NO rows remain. A still-live sibling session
|
|
38
|
+
# keeps its row, so routing stays active and its in-flight work is never
|
|
39
|
+
# cancelled. Done under the agent's row lock so a concurrent subscribe on
|
|
40
|
+
# the same agent serializes (no clear-vs-activate race).
|
|
41
|
+
#
|
|
42
|
+
# Cross-process / late unsubscribe: the row was keyed by this connection's
|
|
43
|
+
# own @subscription_token. A stale unsubscribe whose row was already
|
|
44
|
+
# removed (newer subscribe took over, or a different Puma/Kamal process)
|
|
45
|
+
# deletes zero rows and becomes a no-op — required for scaled deployments
|
|
46
|
+
# (WEB_CONCURRENCY > 1, Solid Cable).
|
|
47
|
+
def unsubscribed
|
|
48
|
+
return unless @session_agent && @subscription_token
|
|
49
|
+
|
|
50
|
+
cleared = false
|
|
51
|
+
dropped_session_id = nil
|
|
52
|
+
@session_agent.with_lock do
|
|
53
|
+
scope = AgentSubscription.where(agent_id: @session_agent.id, token: @subscription_token)
|
|
54
|
+
# Capture the dropped session's id before deleting its row so a live-
|
|
55
|
+
# sibling exit can still scope a cleanup to this session's own topic.
|
|
56
|
+
dropped_session_id = scope.pick(:session_id)
|
|
57
|
+
deleted = scope.delete_all
|
|
58
|
+
# Stale: our presence row is already gone. The live owner's lifecycle
|
|
59
|
+
# owns routing — do not clobber it, do not schedule cancellation.
|
|
60
|
+
if deleted.zero?
|
|
61
|
+
dropped_session_id = nil
|
|
62
|
+
next
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Drop crash-orphaned sibling rows (a Puma/ActionCable process that
|
|
66
|
+
# died without firing unsubscribed) before reading presence, so a dead
|
|
67
|
+
# row cannot masquerade as a live sibling and pin routing on forever.
|
|
68
|
+
AgentSubscription.reap_stale!(@session_agent.id)
|
|
69
|
+
|
|
70
|
+
# Another session is still LIVE on this shared agent. Keep routing
|
|
71
|
+
# active; whichever session unsubscribes last clears it.
|
|
72
|
+
next if AgentSubscription.live.where(agent_id: @session_agent.id).exists?
|
|
73
|
+
|
|
74
|
+
@session_agent.update_columns(
|
|
75
|
+
routing_expression: nil,
|
|
76
|
+
routing_subscription_token: nil
|
|
77
|
+
)
|
|
78
|
+
cleared = true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
if cleared
|
|
82
|
+
# Reconnect-grace cancellation (last session): clearing routing only
|
|
83
|
+
# makes the agent unroutable. Any task already "delegated" still holds
|
|
84
|
+
# its ResourceTracker slot — the dispatch was broadcast to a now-dead
|
|
85
|
+
# stream so no client remains to call /reply, and the slot would stay
|
|
86
|
+
# held until StuckDetectorJob times out. The job cancels those tasks
|
|
87
|
+
# after a grace window, but only if the agent is still offline (it
|
|
88
|
+
# rechecks routing_expression AND that no session has resubscribed).
|
|
89
|
+
CancelOfflineDelegatedTasksJob
|
|
90
|
+
.set(wait: CancelOfflineDelegatedTasksJob::GRACE_SECONDS.seconds)
|
|
91
|
+
.perform_later(@session_agent.id, @subscription_token)
|
|
92
|
+
elsif dropped_session_id.present?
|
|
93
|
+
# A live sibling keeps the shared agent routable, so we must NOT clear
|
|
94
|
+
# routing or sweep agent-wide. But this dropped session's OWN session
|
|
95
|
+
# topic is private to it — siblings filter session_topic dispatches to
|
|
96
|
+
# their own topic, so none will /reply to a task delegated there and it
|
|
97
|
+
# would hold its slot until stuck recovery. Schedule a grace-delayed,
|
|
98
|
+
# session-scoped cancellation (skipped if this same session reconnects
|
|
99
|
+
# within the window), mirroring the destroy path's cancel_tasks_for_topic.
|
|
100
|
+
CancelOfflineDelegatedTasksJob
|
|
101
|
+
.set(wait: CancelOfflineDelegatedTasksJob::GRACE_SECONDS.seconds)
|
|
102
|
+
.perform_later(@session_agent.id, @subscription_token, dropped_session_id)
|
|
103
|
+
end
|
|
104
|
+
rescue ActiveRecord::StatementInvalid => e
|
|
105
|
+
Rails.logger.warn("[AgentChannel] unsubscribed presence clear failed: #{e.message}")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Pull-on-resubscribe replay (Codex P2): after every (re)subscribe the plugin
|
|
109
|
+
# sends the permission request_ids it still holds pending, and the server
|
|
110
|
+
# re-broadcasts the recorded decision for exactly those ids. A decision
|
|
111
|
+
# broadcast once into the transient agent:user:<id> stream while the plugin's
|
|
112
|
+
# WebSocket was down would otherwise be lost (action_executed_at already
|
|
113
|
+
# stamped, buttons hidden), hanging the suspended tool with no retry path.
|
|
114
|
+
# The plugin's pending set is the sole bound — there is no wall-clock window,
|
|
115
|
+
# so an outage of any length is covered, and a decision already consumed is
|
|
116
|
+
# never requested. Idempotent: the plugin's coordinator drops any id it no
|
|
117
|
+
# longer holds. Gated on @session_agent so only a Claude Channel agent
|
|
118
|
+
# subscription (where stream_from agent:user:<id> is attached) can pull.
|
|
119
|
+
def replay_permissions(data)
|
|
120
|
+
return unless @session_agent
|
|
121
|
+
|
|
122
|
+
Comment.replay_claude_channel_permission_decisions_for(
|
|
123
|
+
@session_agent.id,
|
|
124
|
+
data["request_ids"]
|
|
125
|
+
)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Broadcast an arbitrary payload to a topic's agent stream.
|
|
129
|
+
def self.broadcast_to_topic(topic_id, payload)
|
|
130
|
+
ActionCable.server.broadcast("agent:topic:#{topic_id}", payload)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Broadcast to a per-agent stream so the agent's MCP plugin receives the
|
|
134
|
+
# dispatch regardless of which topic triggered it.
|
|
135
|
+
def self.broadcast_to_agent(agent_id, payload)
|
|
136
|
+
ActionCable.server.broadcast("agent:user:#{agent_id}", payload)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
private
|
|
140
|
+
|
|
141
|
+
def subscribe_to_topic_stream
|
|
142
|
+
@topic = Topic.find_by(id: params[:topic_id])
|
|
143
|
+
return reject unless @topic
|
|
144
|
+
|
|
145
|
+
creative = @topic.creative&.effective_origin
|
|
146
|
+
return reject unless creative&.has_permission?(current_user, :read)
|
|
147
|
+
|
|
148
|
+
stream_from "agent:topic:#{@topic.id}"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def subscribe_to_agent_stream
|
|
152
|
+
agent = User.find_by(id: params[:agent_id])
|
|
153
|
+
return reject unless agent&.ai_user?
|
|
154
|
+
return reject unless agent.created_by_id == current_user.id
|
|
155
|
+
|
|
156
|
+
# Attach the stream BEFORE activating routing. Orchestration::Matcher
|
|
157
|
+
# can pick this agent as soon as routing_expression becomes "true";
|
|
158
|
+
# broadcasts to agent:user:<id> in the window between the UPDATE
|
|
159
|
+
# committing and stream_from registering the subscription would land
|
|
160
|
+
# in a stream with no subscriber, leaving the new delegated task
|
|
161
|
+
# waiting on stuck recovery. Registering the subscription first means
|
|
162
|
+
# by the time the agent is matchable, this connection is already
|
|
163
|
+
# receiving broadcasts.
|
|
164
|
+
@session_agent = agent if agent.claude_channel_agent?
|
|
165
|
+
@subscription_token = SecureRandom.hex(8) if agent.claude_channel_agent?
|
|
166
|
+
stream_from "agent:user:#{agent.id}"
|
|
167
|
+
|
|
168
|
+
# Record this session's presence row and (re)activate routing under the
|
|
169
|
+
# agent's row lock, so a concurrent unsubscribe on the same shared agent
|
|
170
|
+
# serializes against this and cannot clear routing out from under a live
|
|
171
|
+
# session. routing_subscription_token is kept as the most-recent-session
|
|
172
|
+
# marker (debugging / grace-job arg); presence rows are the real gate.
|
|
173
|
+
if agent.claude_channel_agent?
|
|
174
|
+
agent.with_lock do
|
|
175
|
+
# Self-heal: clear crash-orphaned rows for this agent before counting
|
|
176
|
+
# so this session's activation isn't blocked from, and presence reads
|
|
177
|
+
# aren't fooled by, a dead process's leftover row.
|
|
178
|
+
AgentSubscription.reap_stale!(agent.id)
|
|
179
|
+
# Record the plugin-supplied session_id (stable across --resume) on the
|
|
180
|
+
# row. The HTTP unregister path (DELETE /api/v1/agent/:id) cannot know
|
|
181
|
+
# this connection's server-minted @subscription_token, so it correlates
|
|
182
|
+
# the exiting session to its row via session_id instead.
|
|
183
|
+
AgentSubscription.create!(
|
|
184
|
+
agent_id: agent.id,
|
|
185
|
+
token: @subscription_token,
|
|
186
|
+
session_id: params[:session_id].presence
|
|
187
|
+
)
|
|
188
|
+
agent.update_columns(
|
|
189
|
+
routing_subscription_token: @subscription_token,
|
|
190
|
+
routing_expression: "true"
|
|
191
|
+
)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Periodic heartbeat callback: keep this session's presence row live. No-op
|
|
197
|
+
# once the row is gone (rotated by a newer subscribe, or reaped), so it can
|
|
198
|
+
# never resurrect a removed row.
|
|
199
|
+
def touch_presence
|
|
200
|
+
return unless @session_agent && @subscription_token
|
|
201
|
+
|
|
202
|
+
AgentSubscription.touch!(@session_agent.id, @subscription_token)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Collavre
|
|
2
|
+
# Keeps the global inbox badge in sync without a full page reload.
|
|
3
|
+
#
|
|
4
|
+
# The badge is updated in real time by fire-and-forget Turbo Stream
|
|
5
|
+
# broadcasts on the ["inbox", user] stream (see Comment::Broadcastable).
|
|
6
|
+
# ActionCable does not replay messages missed while a socket is down, so any
|
|
7
|
+
# badge update broadcast during a WebSocket gap (Turbo navigation, sleep/wake,
|
|
8
|
+
# network blip, server restart, the window before the cable connects) was lost
|
|
9
|
+
# until the next full page render — the "badge only shows up after refresh" bug.
|
|
10
|
+
#
|
|
11
|
+
# This channel closes that gap with the established pull-on-subscribe pattern:
|
|
12
|
+
# ActionCable re-runs #subscribed on every (re)connect, so we re-push the
|
|
13
|
+
# authoritative count each time. No client polling, no time window — the server
|
|
14
|
+
# self-heals the count on reconnect.
|
|
15
|
+
class InboxBadgeChannel < ApplicationCable::Channel
|
|
16
|
+
def subscribed
|
|
17
|
+
return reject unless current_user
|
|
18
|
+
|
|
19
|
+
# Deliver the snapshot through THIS subscription (transmit), not by
|
|
20
|
+
# re-broadcasting to the sibling ["inbox", user] Turbo stream. On reconnect
|
|
21
|
+
# the two subscriptions re-attach independently, so a broadcast from here
|
|
22
|
+
# could fire before that stream re-attaches and be dropped — leaving the
|
|
23
|
+
# badge stale. transmit only reaches this just-confirmed subscriber, so the
|
|
24
|
+
# snapshot can never be sent while no client is listening.
|
|
25
|
+
inbox = Creative.inbox_for(current_user)
|
|
26
|
+
snapshot = Comment.inbox_badge_turbo_stream(inbox, current_user)
|
|
27
|
+
transmit(snapshot) if snapshot
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -23,6 +23,10 @@ module Collavre
|
|
|
23
23
|
next if value.blank?
|
|
24
24
|
|
|
25
25
|
definition = Registry.instance.find(key) or next
|
|
26
|
+
# Mirror the index filter: keys hidden from the admin UI
|
|
27
|
+
# (admin_visible: false) are not editable via this form, so a crafted
|
|
28
|
+
# POST cannot write them.
|
|
29
|
+
next if definition.admin_visible == false
|
|
26
30
|
|
|
27
31
|
row = Collavre::IntegrationSetting.find_or_initialize_by(key: definition.key.to_s)
|
|
28
32
|
row.category = definition.category
|
|
@@ -47,14 +51,21 @@ module Collavre
|
|
|
47
51
|
private
|
|
48
52
|
|
|
49
53
|
def load_definition!
|
|
50
|
-
@definition = Registry.instance.find(params[:key])
|
|
51
|
-
|
|
54
|
+
@definition = Registry.instance.find(params[:key])
|
|
55
|
+
# Keys hidden from the admin UI (admin_visible: false) are treated as
|
|
56
|
+
# non-addressable here too, so a crafted DELETE cannot reset them.
|
|
57
|
+
if @definition.nil? || @definition.admin_visible == false
|
|
58
|
+
@definition = nil
|
|
59
|
+
render file: Rails.root.join("public/404.html"), status: :not_found, layout: false and return
|
|
60
|
+
end
|
|
52
61
|
end
|
|
53
62
|
|
|
54
63
|
def build_grouped_settings
|
|
55
|
-
Registry.instance.by_category.sort_by { |category, _defs| category.to_s }.
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
Registry.instance.by_category.sort_by { |category, _defs| category.to_s }.filter_map do |category, definitions|
|
|
65
|
+
visible = definitions.select { |d| d.admin_visible != false }
|
|
66
|
+
next if visible.empty?
|
|
67
|
+
|
|
68
|
+
[ category, visible.map { |definition| build_row(definition) } ]
|
|
58
69
|
end
|
|
59
70
|
end
|
|
60
71
|
|