brainiac-discord 0.0.14 → 0.0.15

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: 7091fddf5aa23196f3e031d6830549eca0463e29fad37433d4683a7c8cb816f7
4
+ data.tar.gz: 1b1bf72a7180aa002c06a18774e65e36550fab21a0c7ec1dc02498454e1c9b2c
5
5
  SHA512:
6
- metadata.gz: c7df8598d6a702644e25c18c76c49aa8f406fa3c0806b2ba9a4eccf0859615fffc027e056d66d2ac42b4d737fdb7b7c00f62e2c2b629a4ee4e4e1adfa9844030
7
- data.tar.gz: f7e4ddc91b9d0b819f82000e276f9490fa4fdc8454fd475ef49d09de5d58b917e988be95df2ec8577a4d55cca4ec186cc4cc1d486022912840e49767a41371ee
6
+ metadata.gz: e1ed0e106262c3cd09c04d00cc918db60fa04c52651c45365daa2af1d1bf658e7ba619f8ecc60f3c841893802ceeb6c4fa18eca8f875bee5c0b3acc18cce26b5
7
+ data.tar.gz: d124b1ed107451cf7c48e9815ba8e9fa049d891c91f78c000f7d2b46945053c7c710c29d15983c02ecf33cc73f0e0343942ee4ba777fa6c84bce474ae3a7456a
@@ -939,6 +939,7 @@ module Brainiac
939
939
  head_before, status_before = capture_brainiac_state(project_config, work_dir)
940
940
  prompt_mode = resolved["prompt_mode"] || "stdin"
941
941
 
942
+ started_at = Time.now
942
943
  pid = spawn(spawn_env, *cmd,
943
944
  chdir: work_dir,
944
945
  **(prompt_mode == "stdin" ? { in: prompt_file } : {}),
@@ -958,7 +959,8 @@ module Brainiac
958
959
  meta_file: meta_file, prompt_file: prompt_file, log_file: log_file,
959
960
  attachment_paths: attachment_paths, project_config: project_config,
960
961
  head_before: head_before, status_before: status_before,
961
- supersede_key: supersede_key
962
+ supersede_key: supersede_key,
963
+ resolved: resolved, model: model, work_dir: work_dir, started_at: started_at
962
964
  )
963
965
  end
964
966
 
@@ -1136,7 +1138,8 @@ module Brainiac
1136
1138
 
1137
1139
  def monitor_agent(pid:, session_key:, agent_name:, agent_config_name:, channel_id:, message_id:,
1138
1140
  bot_token:, response_file:, meta_file:, prompt_file:, log_file:,
1139
- attachment_paths:, project_config:, head_before:, status_before:, supersede_key: nil)
1141
+ attachment_paths:, project_config:, head_before:, status_before:, supersede_key: nil,
1142
+ resolved: nil, model: nil, work_dir: nil, started_at: nil)
1140
1143
  Thread.new do
1141
1144
  Process.wait(pid)
1142
1145
  exit_status = $CHILD_STATUS
@@ -1146,6 +1149,16 @@ module Brainiac
1146
1149
 
1147
1150
  session_cancelled = ACTIVE_SESSIONS_MUTEX.synchronize { !ACTIVE_SESSIONS.key?(session_key) }
1148
1151
 
1152
+ # Record a durable session-history entry regardless of how the session ended.
1153
+ # Discord dispatches its own agents (bypassing core's run_agent/handle_agent_completion),
1154
+ # so without this hook Discord sessions never land in ~/.brainiac/session-history.jsonl.
1155
+ archive_discord_session_history(
1156
+ agent_name: agent_name, agent_config_name: agent_config_name,
1157
+ channel_id: channel_id, message_id: message_id, log_file: log_file,
1158
+ resolved: resolved, model: model, work_dir: work_dir, started_at: started_at,
1159
+ exit_status: exit_status
1160
+ )
1161
+
1149
1162
  if exit_status.signaled? || session_cancelled
1150
1163
  handle_cancelled(exit_status, session_cancelled, agent_name, message_id,
1151
1164
  response_file, meta_file, prompt_file, attachment_paths)
@@ -1174,6 +1187,44 @@ module Brainiac
1174
1187
  schedule_temp_cleanup(prompt_file, attachment_paths)
1175
1188
  end
1176
1189
 
1190
+ # Record a durable session-history entry for a finished Discord session.
1191
+ #
1192
+ # Discord runs agents via its own spawn_agent/monitor_agent path and never
1193
+ # touches core's handle_agent_completion, which is the single choke point that
1194
+ # normally calls archive_session_history. As a result, Discord sessions were
1195
+ # missing entirely from ~/.brainiac/session-history.jsonl (only fizzy/github/etc
1196
+ # showed up). This bridges that gap by building the ctx archive_session_history
1197
+ # expects and calling it directly, with source: :discord.
1198
+ #
1199
+ # Fully best-effort: archive_session_history already rescues internally, but we
1200
+ # guard here too so a history failure can never break Discord's completion path.
1201
+ def archive_discord_session_history(agent_name:, agent_config_name:, channel_id:, message_id:,
1202
+ log_file:, resolved:, model:, work_dir:, started_at:, exit_status:)
1203
+ return unless defined?(archive_session_history)
1204
+
1205
+ ctx = {
1206
+ agent_name: agent_name,
1207
+ agent_config_name: agent_config_name,
1208
+ source: :discord,
1209
+ channel_id: channel_id,
1210
+ source_context: { channel_id: channel_id, message_id: message_id },
1211
+ log_file: log_file,
1212
+ resolved: resolved,
1213
+ chdir: work_dir,
1214
+ agent_cli: resolved && resolved["agent_cli"],
1215
+ model: model,
1216
+ started_at: started_at
1217
+ }
1218
+
1219
+ archive_session_history(
1220
+ ctx: ctx,
1221
+ exit_status: exit_status.exitstatus,
1222
+ signaled: exit_status.signaled?
1223
+ )
1224
+ rescue StandardError => e
1225
+ LOG.warn "[Discord:#{agent_name}] Failed to archive session history: #{e.message}" if defined?(LOG)
1226
+ end
1227
+
1177
1228
  def handle_completed(exit_status:, agent_name:, agent_config_name:, channel_id:, message_id:,
1178
1229
  bot_token:, response_file:, meta_file:, log_file:,
1179
1230
  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.15"
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.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis