Class: Collavre::Tools::PreviewDetachService

Inherits:
Object
  • Object
show all
Extended by:
T::Sig, ToolMeta
Defined in:
app/services/collavre/tools/preview_detach_service.rb

Overview

Mark a previously-attached preview as stopped. AI Agents call this immediately before killing the preview server (per the worktree cleanup workflow) so the chip flips to the “stopped” badge with reduced opacity. The chip stays visible until the user dismisses it with the X button —mirrors the PR-channel post-close UX where the closed badge persists for context.

Instance Method Summary collapse

Instance Method Details

#call(topic_id:, worktree_id:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/collavre/tools/preview_detach_service.rb', line 31

def call(topic_id:, worktree_id:)
  topic = Collavre::Topic.find(topic_id)
  Collavre::Tools::TopicAuthorizer.authorize_write!(topic)

  channel = lookup_channel(topic, worktree_id)
  return { ok: true, status: :noop, worktree_id: worktree_id } if channel.nil?

  status =
    if channel.preview_state == "stopped" && channel.detached?
      :noop
    else
      channel.preview_state = "stopped"
      channel.state = :detached unless channel.detached?
      channel.save!
      :stopped
    end

  { ok: true, channel_id: channel.id, worktree_id: worktree_id, status: status }
end