brainiac-discord 0.0.6 → 0.0.7

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: c28ec3344ab8f68efb007fc26d1cf8313427b74bc9e0b4db4f8bd82eddd403d8
4
- data.tar.gz: c86021ac1c0145cef864bd59f79e43edde8ba2645a4a2d31cd409570c3f935a1
3
+ metadata.gz: 38d2ec15ff61cbaaac7cc9c0ad3d090950c62e081bd353654ed48c70b982cc97
4
+ data.tar.gz: 167309f8288bbb17d8bc4f1dff9b3c85765e5bede1ec6f786aca076bc27fe705
5
5
  SHA512:
6
- metadata.gz: 26f16e31243fefadb58e7c77c7dcb1cd835c9e674ebbaf0766b3feece5f5cfc4a6262b3a0c3a2281b63f30fc20d8dbc9a51daa806f4a044e2be8c6df6c1e6d39
7
- data.tar.gz: dc8afd82dd157ec2f4c5c81e4bf3fd90b18bfd6dee1b568598eb1245a109a7ccb8aef20b79ae6329f34f2ac704c7cd185d3e56082aa3c08297929eab8820e799
6
+ metadata.gz: b34ea4880a65b80733996be50b6609aa59a2327f021ffe1d140e4475b9ee1b259322efb400998511b164677aa81f065d3975804669d25154822ab1db5d8c4840
7
+ data.tar.gz: 5d661b2560f6ba4bc25a4b5a2b04a2840f9710da16595f551b8de7197346b47769f82495e414b3fb076b28ed5bc8f58e16a918253333cc6f0bb08ef40216a141
@@ -10,8 +10,8 @@ module Brainiac
10
10
  #
11
11
  # Handles incoming messages: authorization, cross-agent routing, project detection,
12
12
  # worktree management, prompt building, agent spawning, and response monitoring.
13
- module Message
14
- class << self
13
+ module Message # rubocop:disable Metrics/ModuleLength
14
+ class << self # rubocop:disable Metrics/ClassLength
15
15
  def handle(message, agent_key, bot_token, bot_user_id)
16
16
  channel_id = message["channel_id"]
17
17
  message_id = message["id"]
@@ -498,7 +498,7 @@ module Brainiac
498
498
  thread_root_context = build_thread_root_context(is_thread, root_message, parent_channel_id, channel_id, bot_token)
499
499
  brain_context = build_brain_context(agent_name: agent_name, card_title: clean_content, comment_body: clean_content)
500
500
 
501
- should_resume, thread_worktree_path, thread_cli_provider, thread_model, thread_effort = manage_worktree(
501
+ should_resume, thread_worktree_path, thread_cli_provider, thread_model, thread_effort, thread_map_key = manage_worktree(
502
502
  agent_key: agent_key, agent_name: agent_name, channel_id: channel_id, message_id: message_id,
503
503
  is_thread: is_thread, is_dm: is_dm, project_config: project_config, clean_content: clean_content,
504
504
  chat_mode: chat_mode, bot_token: bot_token
@@ -522,6 +522,10 @@ module Brainiac
522
522
  clean_content, project_config, thread_model, thread_effort, thread_cli_provider
523
523
  )
524
524
 
525
+ persist_overrides(thread_map_key, clean_content, project_config,
526
+ cli_provider: cli_provider_override, model: model, effort: effort,
527
+ prev_cli_provider: thread_cli_provider, prev_model: thread_model, prev_effort: thread_effort)
528
+
525
529
  meta_file = File.join(Delivery::DRAFT_DIR, "#{response_basename}.meta.json")
526
530
  write_meta(meta_file,
527
531
  channel_id: channel_id, message_id: message_id, agent_key: agent_key,
@@ -593,6 +597,55 @@ module Brainiac
593
597
  [model, effort, cli_provider]
594
598
  end
595
599
 
600
+ # Persist inline overrides to the thread map (and work item map if a work item exists).
601
+ # Only writes when a new inline tag was detected (differs from previously stored values).
602
+ def persist_overrides(thread_map_key, clean_content, project_config,
603
+ cli_provider:, model:, effort:,
604
+ prev_cli_provider:, prev_model:, prev_effort:)
605
+ return unless thread_map_key
606
+
607
+ inline_cli = detect_cli_provider(text: clean_content)
608
+ inline_model = explicit_model_tag?(clean_content, project_config) ? model : nil
609
+ inline_effort = clean_content.match?(/\[effort:\w+\]/i) ? effort : nil
610
+
611
+ return unless inline_cli || inline_model || inline_effort
612
+
613
+ changed = (inline_cli && inline_cli != prev_cli_provider) ||
614
+ (inline_model && inline_model != prev_model) ||
615
+ (inline_effort && inline_effort != prev_effort)
616
+ return unless changed
617
+
618
+ # Update thread map entry with new overrides
619
+ Config.thread_map_mutex.synchronize do
620
+ map = Config.load_thread_map
621
+ entry = map[thread_map_key]
622
+ if entry
623
+ entry["cli_provider"] = cli_provider if inline_cli
624
+ entry["model"] = model if inline_model
625
+ entry["effort"] = effort if inline_effort
626
+ Config.save_thread_map(map)
627
+ end
628
+ end
629
+
630
+ # Also persist to core work item map (if a work item exists for this branch)
631
+ branch = Config.thread_map_mutex.synchronize do
632
+ Config.load_thread_map.dig(thread_map_key, "branch")
633
+ end
634
+ if branch && defined?(resolve_work_item_overrides)
635
+ resolve_work_item_overrides(
636
+ branch: branch,
637
+ inline_cli_provider: inline_cli,
638
+ inline_model: inline_model,
639
+ inline_effort: inline_effort
640
+ )
641
+ end
642
+
643
+ return unless defined?(LOG)
644
+
645
+ LOG.info "[Discord] Persisted overrides for #{thread_map_key}: " \
646
+ "cli=#{cli_provider}, model=#{model}, effort=#{effort}"
647
+ end
648
+
596
649
  def explicit_model_tag?(clean_content, project_config)
597
650
  return false unless project_config
598
651
 
@@ -662,7 +715,7 @@ module Brainiac
662
715
  create_chat_mode_dir(agent_key, agent_name, effective_thread_id, project_config, clean_content, thread_map_key)
663
716
  end
664
717
 
665
- [should_resume, thread_worktree_path, thread_cli_provider, thread_model, thread_effort]
718
+ [should_resume, thread_worktree_path, thread_cli_provider, thread_model, thread_effort, thread_map_key]
666
719
  end
667
720
 
668
721
  def pre_create_thread(agent_key, agent_name, channel_id, message_id, clean_content, bot_token)
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Discord
6
- VERSION = "0.0.6"
6
+ VERSION = "0.0.7"
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis