brainiac-discord 0.0.6 → 0.0.8
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/lib/brainiac/plugins/discord/message.rb +65 -12
- data/lib/brainiac/plugins/discord/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffe7aa25d1f9a232e356f5dc8781f96c7ec35527de9505650102260f0384664a
|
|
4
|
+
data.tar.gz: 0e4cb055a833dd4eeff966e215632266786b275b1d02135ba6e7afe9cfb016bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e4747823b694d2e96492090616339d58b6f388b6812df0abd0c88741bbaae1e1e5aba4118ed600d9cb8e7e750ca13669b6d3af4d2d249ad89ab6118bf7e4df2
|
|
7
|
+
data.tar.gz: 0df896adfa8ae958664f49ae3f54e0020c1ead26d42e657226e3ddefb9d4797b31fef357c45ccf7de278a181ac316dda559d82c29eff2a8a8959560b961bb5f1
|
|
@@ -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,12 +522,16 @@ 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,
|
|
528
532
|
agent_name: agent_name, is_dm: is_dm, is_thread: is_thread,
|
|
529
533
|
clean_content: clean_content,
|
|
530
|
-
explicit_model: explicit_model_tag?(clean_content, project_config) ? model : nil,
|
|
534
|
+
explicit_model: explicit_model_tag?(clean_content, project_config, cli_provider_override: cli_provider_override) ? model : nil,
|
|
531
535
|
explicit_effort: clean_content.match?(/\[effort:\w+\]/i) ? effort : nil)
|
|
532
536
|
|
|
533
537
|
spawn_agent(
|
|
@@ -571,32 +575,81 @@ module Brainiac
|
|
|
571
575
|
|
|
572
576
|
def resolve_overrides(clean_content, project_config, thread_model, thread_effort, thread_cli_provider)
|
|
573
577
|
cli_provider = detect_cli_provider(text: clean_content) || thread_cli_provider
|
|
574
|
-
has_explicit_model = explicit_model_tag?(clean_content, project_config)
|
|
578
|
+
has_explicit_model = explicit_model_tag?(clean_content, project_config, cli_provider_override: cli_provider)
|
|
575
579
|
has_explicit_effort = clean_content.match?(/\[effort:\w+\]/i)
|
|
576
580
|
|
|
577
581
|
model = if has_explicit_model
|
|
578
|
-
detect_model(project_config, text: clean_content)
|
|
582
|
+
detect_model(project_config, text: clean_content, cli_provider_override: cli_provider)
|
|
579
583
|
elsif thread_model
|
|
580
584
|
thread_model
|
|
581
585
|
else
|
|
582
|
-
project_config ? detect_model(project_config, text: clean_content) : nil
|
|
586
|
+
project_config ? detect_model(project_config, text: clean_content, cli_provider_override: cli_provider) : nil
|
|
583
587
|
end
|
|
584
588
|
|
|
585
589
|
effort = if has_explicit_effort
|
|
586
|
-
detect_effort(project_config, text: clean_content)
|
|
590
|
+
detect_effort(project_config, text: clean_content, cli_provider_override: cli_provider)
|
|
587
591
|
elsif thread_effort
|
|
588
592
|
thread_effort
|
|
589
593
|
else
|
|
590
|
-
project_config ? detect_effort(project_config, text: clean_content) : nil
|
|
594
|
+
project_config ? detect_effort(project_config, text: clean_content, cli_provider_override: cli_provider) : nil
|
|
591
595
|
end
|
|
592
596
|
|
|
593
597
|
[model, effort, cli_provider]
|
|
594
598
|
end
|
|
595
599
|
|
|
596
|
-
|
|
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, cli_provider_override: cli_provider) ? 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
|
+
|
|
649
|
+
def explicit_model_tag?(clean_content, project_config, cli_provider_override: nil)
|
|
597
650
|
return false unless project_config
|
|
598
651
|
|
|
599
|
-
allowed_models = resolve_project_cli_config(project_config)["allowed_models"] || {}
|
|
652
|
+
allowed_models = resolve_project_cli_config(project_config, cli_provider_override: cli_provider_override)["allowed_models"] || {}
|
|
600
653
|
model_tag_match = clean_content.match(/\[(\w+)\]/i)
|
|
601
654
|
model_tag_match && allowed_models.key?(model_tag_match[1].downcase)
|
|
602
655
|
end
|
|
@@ -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)
|