Module: Brainiac::Plugins::Discord::ThreadCleanup
- Defined in:
- lib/brainiac/plugins/discord/thread_cleanup.rb
Overview
Handles cleanup of Discord thread worktrees when threads are archived or deleted.
When a thread is archived (manually closed or auto-archived due to inactivity) or deleted, this module looks up the associated worktree in discord_thread_map.json, verifies it has no uncommitted changes, removes the worktree + branch, and removes the thread map entry.
Class Method Summary collapse
Class Method Details
.handle_archive(data, agent_key, agent_display) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/brainiac/plugins/discord/thread_cleanup.rb', line 17 def handle_archive(data, agent_key, agent_display) thread_id = data["id"] return unless thread_id thread_map_key = "#{agent_key}:#{thread_id}" entry = Config.thread_map_mutex.synchronize do map = Config.load_thread_map map[thread_map_key] end unless entry LOG.info "[Discord:#{agent_display}] Thread #{thread_id} archived — no worktree tracked, nothing to clean up" if defined?(LOG) return end worktree_path = entry["worktree"] branch = entry["branch"] project_key = entry["project"] chat_mode = entry["chat_mode"] if chat_mode cleanup_chat_mode_dir(worktree_path, thread_map_key, agent_display, thread_id) else cleanup_worktree(worktree_path, branch, project_key, thread_map_key, agent_display, thread_id) end end |