brainiac-discord 0.0.14 → 0.0.16

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: f90a4cf177bc62d55f5773e21f3b5e05aaefbdbff94bae975fcbcb21ae3dbb64
4
- data.tar.gz: a9dc84c5ab058a8173c96a6bda909a5ea8959a36fe61065d316b0b408ab2eb54
3
+ metadata.gz: afab8518a3314e7873e2bec99ba79f7efeedf1b45b80be5ccc9d0654d0b64b77
4
+ data.tar.gz: a39348b184343d375313e1ca30e746165690562a729bac532e9880af4a9b540c
5
5
  SHA512:
6
- metadata.gz: c7df8598d6a702644e25c18c76c49aa8f406fa3c0806b2ba9a4eccf0859615fffc027e056d66d2ac42b4d737fdb7b7c00f62e2c2b629a4ee4e4e1adfa9844030
7
- data.tar.gz: f7e4ddc91b9d0b819f82000e276f9490fa4fdc8454fd475ef49d09de5d58b917e988be95df2ec8577a4d55cca4ec186cc4cc1d486022912840e49767a41371ee
6
+ metadata.gz: aecb0bff2e82096ba8ec67c7a862a9316025030fa999d87c323f023a95ab463807c0dcf1eac5b7055b1d6307f346acf80fd08ae0805bf21c7e248fc29e3f35b5
7
+ data.tar.gz: aeb1f966c703cbf553d50535dcf6768ef1af4fc38443c47b0e0d4544dd11c42d5cf31049ccc86a7a8d6efdfd7e256e9f02c898cac9792ebc82732c243ba4692b
@@ -61,6 +61,7 @@ module Brainiac
61
61
 
62
62
  reload_projects!
63
63
  reload_agent_registry!
64
+ reload_profiles! if defined?(reload_profiles!)
64
65
  Config.reload!
65
66
  return unless authorize_user(discord_user, discord_user_id, message, channel_id, message_id, agent_name, bot_token)
66
67
 
@@ -605,7 +606,8 @@ module Brainiac
605
606
  meta_file: meta_file, model: model, effort: effort, actual_resume: actual_resume,
606
607
  resolved: resolved, project_config: project_config,
607
608
  session_key: session_key, supersede_key: supersede_key,
608
- attachment_paths: attachment_paths, timestamp: timestamp, response_dir: response_dir
609
+ attachment_paths: attachment_paths, timestamp: timestamp, response_dir: response_dir,
610
+ profile: parse_inline_tags(clean_content)[:profile]
609
611
  )
610
612
  end
611
613
 
@@ -904,7 +906,7 @@ module Brainiac
904
906
  def spawn_agent(agent_key:, agent_name:, bot_token:, channel_id:, message_id:, discord_user:,
905
907
  work_dir:, prompt_file:, response_file:, meta_file:, model:, effort:,
906
908
  actual_resume:, resolved:, project_config:,
907
- session_key:, supersede_key:, attachment_paths:, timestamp:, response_dir:)
909
+ session_key:, supersede_key:, attachment_paths:, timestamp:, response_dir:, profile: nil)
908
910
  agent_config_name = agent_key.downcase.gsub(/[^a-z0-9-]/, "-")
909
911
  log_file = File.join(response_dir, "discord-agent-#{timestamp}-#{agent_key}-#{message_id}.log")
910
912
 
@@ -920,6 +922,10 @@ module Brainiac
920
922
 
921
923
  spawn_env = {}
922
924
  agent_env = agent_env_for(agent_name)
925
+ # Profile env (named bundle, e.g. an alternate kiro-cli account via
926
+ # XDG_DATA_HOME). An explicitly-requested [profile:X] wins over agent
927
+ # env; the default profile is only a fallback. See core profiles.rb.
928
+ agent_env = profile_spawn_env(agent_env, profile) if defined?(profile_spawn_env)
923
929
  unless agent_env.empty?
924
930
  spawn_env.merge!(agent_env)
925
931
  LOG.info "[Discord:#{agent_name}] Injecting #{agent_env.size} env var(s): #{agent_env.keys.join(", ")}" if defined?(LOG)
@@ -939,6 +945,7 @@ module Brainiac
939
945
  head_before, status_before = capture_brainiac_state(project_config, work_dir)
940
946
  prompt_mode = resolved["prompt_mode"] || "stdin"
941
947
 
948
+ started_at = Time.now
942
949
  pid = spawn(spawn_env, *cmd,
943
950
  chdir: work_dir,
944
951
  **(prompt_mode == "stdin" ? { in: prompt_file } : {}),
@@ -958,7 +965,8 @@ module Brainiac
958
965
  meta_file: meta_file, prompt_file: prompt_file, log_file: log_file,
959
966
  attachment_paths: attachment_paths, project_config: project_config,
960
967
  head_before: head_before, status_before: status_before,
961
- supersede_key: supersede_key
968
+ supersede_key: supersede_key,
969
+ resolved: resolved, model: model, work_dir: work_dir, started_at: started_at
962
970
  )
963
971
  end
964
972
 
@@ -1136,7 +1144,8 @@ module Brainiac
1136
1144
 
1137
1145
  def monitor_agent(pid:, session_key:, agent_name:, agent_config_name:, channel_id:, message_id:,
1138
1146
  bot_token:, response_file:, meta_file:, prompt_file:, log_file:,
1139
- attachment_paths:, project_config:, head_before:, status_before:, supersede_key: nil)
1147
+ attachment_paths:, project_config:, head_before:, status_before:, supersede_key: nil,
1148
+ resolved: nil, model: nil, work_dir: nil, started_at: nil)
1140
1149
  Thread.new do
1141
1150
  Process.wait(pid)
1142
1151
  exit_status = $CHILD_STATUS
@@ -1146,6 +1155,16 @@ module Brainiac
1146
1155
 
1147
1156
  session_cancelled = ACTIVE_SESSIONS_MUTEX.synchronize { !ACTIVE_SESSIONS.key?(session_key) }
1148
1157
 
1158
+ # Record a durable session-history entry regardless of how the session ended.
1159
+ # Discord dispatches its own agents (bypassing core's run_agent/handle_agent_completion),
1160
+ # so without this hook Discord sessions never land in ~/.brainiac/session-history.jsonl.
1161
+ archive_discord_session_history(
1162
+ agent_name: agent_name, agent_config_name: agent_config_name,
1163
+ channel_id: channel_id, message_id: message_id, log_file: log_file,
1164
+ resolved: resolved, model: model, work_dir: work_dir, started_at: started_at,
1165
+ exit_status: exit_status
1166
+ )
1167
+
1149
1168
  if exit_status.signaled? || session_cancelled
1150
1169
  handle_cancelled(exit_status, session_cancelled, agent_name, message_id,
1151
1170
  response_file, meta_file, prompt_file, attachment_paths)
@@ -1174,6 +1193,44 @@ module Brainiac
1174
1193
  schedule_temp_cleanup(prompt_file, attachment_paths)
1175
1194
  end
1176
1195
 
1196
+ # Record a durable session-history entry for a finished Discord session.
1197
+ #
1198
+ # Discord runs agents via its own spawn_agent/monitor_agent path and never
1199
+ # touches core's handle_agent_completion, which is the single choke point that
1200
+ # normally calls archive_session_history. As a result, Discord sessions were
1201
+ # missing entirely from ~/.brainiac/session-history.jsonl (only fizzy/github/etc
1202
+ # showed up). This bridges that gap by building the ctx archive_session_history
1203
+ # expects and calling it directly, with source: :discord.
1204
+ #
1205
+ # Fully best-effort: archive_session_history already rescues internally, but we
1206
+ # guard here too so a history failure can never break Discord's completion path.
1207
+ def archive_discord_session_history(agent_name:, agent_config_name:, channel_id:, message_id:,
1208
+ log_file:, resolved:, model:, work_dir:, started_at:, exit_status:)
1209
+ return unless defined?(archive_session_history)
1210
+
1211
+ ctx = {
1212
+ agent_name: agent_name,
1213
+ agent_config_name: agent_config_name,
1214
+ source: :discord,
1215
+ channel_id: channel_id,
1216
+ source_context: { channel_id: channel_id, message_id: message_id },
1217
+ log_file: log_file,
1218
+ resolved: resolved,
1219
+ chdir: work_dir,
1220
+ agent_cli: resolved && resolved["agent_cli"],
1221
+ model: model,
1222
+ started_at: started_at
1223
+ }
1224
+
1225
+ archive_session_history(
1226
+ ctx: ctx,
1227
+ exit_status: exit_status.exitstatus,
1228
+ signaled: exit_status.signaled?
1229
+ )
1230
+ rescue StandardError => e
1231
+ LOG.warn "[Discord:#{agent_name}] Failed to archive session history: #{e.message}" if defined?(LOG)
1232
+ end
1233
+
1177
1234
  def handle_completed(exit_status:, agent_name:, agent_config_name:, channel_id:, message_id:,
1178
1235
  bot_token:, response_file:, meta_file:, log_file:,
1179
1236
  project_config:, head_before:, status_before:)
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Discord
6
- VERSION = "0.0.14"
6
+ VERSION = "0.0.16"
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.14
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis