brainiac-discord 0.0.1 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 223dd60e819a0b61ff8b4f82e27cf88774d431b2a2673f82e5e5d7724ca6ed9b
4
- data.tar.gz: 1777674edaec7db3e0772bdc3fa55d3f7438b1c0fba4c2450c50cd78ffa46442
3
+ metadata.gz: f25b1975521590991edab7777fc07cb22083c2c151998f42bc4f0151bc6b5f11
4
+ data.tar.gz: ba4aeb7c4559d80bc0fea056ec8e0505ad884ffa5ac6945e648d830f357e2b9e
5
5
  SHA512:
6
- metadata.gz: 3a2f08e64fa903bd185a7c4a09a279a5dd23425b744e59f0e5e4bd17bc7d9adb841bef15d7f1c09b614ff89587fac1ed01a11bf38edb10059e06956e21816358
7
- data.tar.gz: 3dd471e951c05a947837a55ab5f9c6510e798eb41d2d86c65ab13c0264b29804e48de6cf430654639d5076db912c1093bee6578ad307a0bde56ad51a51309cb8
6
+ metadata.gz: 2ac2c2933550c7a524d74f443e119d8c83c84cd1e3857c66a9ef57a4784694359e2004947bc8174ea3a28363fe247b145ef04034bc12bc31ed3a826f2be2d4a1
7
+ data.tar.gz: a9ac55676eb5b6b75ffc2d74b146e1023783313c0e5aca96159f9845a814dd184427e958102b6b7a173e41ab4f67b11532d72a7d104e64d7b767c97d4f1bd242
@@ -139,10 +139,15 @@ module Brainiac
139
139
  end
140
140
 
141
141
  def run_gateway_connection(agent_key, agent_display, bot_token, bot_user_id)
142
- @bots_mutex.synchronize do
143
- @bots[agent_key] ||= {}
144
- @bots[agent_key][:status] = "connecting"
145
- @bots[agent_key][:token] = bot_token
142
+ # Capture module-level ivars in local variables so the event_emitter
143
+ # blocks (which run via instance_exec on the WS client) can access them.
144
+ bots = @bots
145
+ bots_mutex = @bots_mutex
146
+
147
+ bots_mutex.synchronize do
148
+ bots[agent_key] ||= {}
149
+ bots[agent_key][:status] = "connecting"
150
+ bots[agent_key][:token] = bot_token
146
151
  end
147
152
 
148
153
  LOG.debug "[Discord:#{agent_display}] Connecting to Gateway..." if defined?(LOG) && LOG.respond_to?(:debug)
@@ -168,8 +173,8 @@ module Brainiac
168
173
  end
169
174
 
170
175
  ws.on :close do |_e|
171
- @bots_mutex.synchronize do
172
- @bots[agent_key][:status] = "disconnected" if @bots[agent_key]
176
+ bots_mutex.synchronize do
177
+ bots[agent_key][:status] = "disconnected" if bots[agent_key]
173
178
  end
174
179
  LOG.warn "[Discord:#{agent_display}] WebSocket closed" if defined?(LOG)
175
180
  heartbeat_thread&.kill
@@ -284,6 +284,12 @@ module Brainiac
284
284
  return
285
285
  end
286
286
  handle_supersede(is_bot, supersede_key, discord_user, agent_name, bot_token)
287
+
288
+ if intent_skip?(clean_content, agent_name: agent_name, source: :discord, channel: "Discord #{is_thread ? "thread" : "channel"}")
289
+ LOG.info "[Discord:#{agent_name}] Intent skip — not dispatching for: #{clean_content[0..80]}" if defined?(LOG)
290
+ return
291
+ end
292
+
287
293
  Thread.new do
288
294
  Api.remove_reaction(channel_id, message_id, "🛑", token: bot_token)
289
295
  Api.add_reaction(channel_id, message_id, "👀", token: bot_token)
@@ -567,8 +573,7 @@ module Brainiac
567
573
 
568
574
  def thread_resume?(project_config, clean_content, thread_cli_provider, agent_name)
569
575
  effective_provider = detect_cli_provider(text: clean_content) || thread_cli_provider
570
- resolved = resolve_project_cli_config(project_config, cli_provider_override: effective_provider, agent_name: agent_name)
571
- resolved["resume_flag"] ? true : false
576
+ resume_viable?(project_config: project_config, cli_provider: effective_provider, agent_name: agent_name)
572
577
  end
573
578
 
574
579
  def detect_thread_overrides(project_config, clean_content, fallback_cli: nil, fallback_model: nil, fallback_effort: nil)
@@ -630,7 +635,7 @@ module Brainiac
630
635
  discord_user:, channel_name:, reply_context:, channel_history:, thread_root_context:,
631
636
  project_context:, response_file:, card_id:, brain_context:, agent_name:)
632
637
  if should_resume && thread_worktree_path
633
- return render_discord_resume_prompt(
638
+ return Brainiac::Plugins::Discord::Prompts.render_resume(
634
639
  message_body: clean_content_for_prompt, discord_user: discord_user,
635
640
  response_file: response_file, agent_name: agent_name, card_id: card_id
636
641
  )
@@ -103,6 +103,33 @@ module Brainiac
103
103
 
104
104
  **IMPORTANT: Write your response to `{{RESPONSE_FILE}}`. Do NOT reply via stdout.**
105
105
  PROMPT
106
+
107
+ # Lean resume prompt for Discord threads. The previous session has full context
108
+ # (role, persona, knowledge, instructions). We only send the new message.
109
+ def self.render_resume(message_body:, discord_user:, response_file:, agent_name: AI_AGENT_NAME, card_id: nil)
110
+ memory_dir = memory_dir_for(agent_name)
111
+ if card_id
112
+ memory_file = File.join(memory_dir, "card-#{card_id}.md")
113
+ FileUtils.mkdir_p(memory_dir)
114
+ FileUtils.touch(memory_file)
115
+ end
116
+
117
+ lines = []
118
+ lines << "## Resumed Session — New Discord Message"
119
+ lines << ""
120
+ lines << "This is a continuation of your previous session in this thread."
121
+ lines << "All prior context, instructions, and your previous work are still in this conversation."
122
+ lines << ""
123
+ lines << "### New Message from #{discord_user}"
124
+ lines << ""
125
+ lines << message_body
126
+ lines << ""
127
+ lines << "---"
128
+ lines << "**IMPORTANT: Write your response to `#{response_file}`. Do NOT reply via stdout.**"
129
+ lines << "All your previous instructions still apply (memory, persona, one message per session, etc.)."
130
+
131
+ lines.join("\n")
132
+ end
106
133
  end
107
134
  end
108
135
  end
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Discord
6
- VERSION = "0.0.1"
6
+ VERSION = "0.0.3"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainiac-discord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.9
18
+ version: 0.0.14
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.9
25
+ version: 0.0.14
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: websocket-client-simple
28
28
  requirement: !ruby/object:Gem::Requirement