brainiac-discord 0.0.13 → 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: 1f2f87e89db33072e4ceb141ec472b71ce09f22d3a383da595f195f3f441b9ee
4
- data.tar.gz: 69aeb6d7e6f945f0fb517c8bfd37a6d91e749137d634d5578596a462579044b2
3
+ metadata.gz: 7091fddf5aa23196f3e031d6830549eca0463e29fad37433d4683a7c8cb816f7
4
+ data.tar.gz: 1b1bf72a7180aa002c06a18774e65e36550fab21a0c7ec1dc02498454e1c9b2c
5
5
  SHA512:
6
- metadata.gz: 2eab7e192cfe422009193273e88bbf8aab1b8ccecdf3d33d7643847b4799a55f44bb5c3d5f18c56eea753982491c73426942e420a1d99c418867829c9bb65fdf
7
- data.tar.gz: 6f66c81ea46ac32423fb10a542730c3e2c71d6d7db71b959ef188b93effa68a12932f4e8e52cc1d203473882355d78339058320dbba9eb61eb8e88d62a479700
6
+ metadata.gz: e1ed0e106262c3cd09c04d00cc918db60fa04c52651c45365daa2af1d1bf658e7ba619f8ecc60f3c841893802ceeb6c4fa18eca8f875bee5c0b3acc18cce26b5
7
+ data.tar.gz: d124b1ed107451cf7c48e9815ba8e9fa049d891c91f78c000f7d2b46945053c7c710c29d15983c02ecf33cc73f0e0343942ee4ba777fa6c84bce474ae3a7456a
@@ -826,6 +826,13 @@ module Brainiac
826
826
  debounced_repo_fetch(repo_path)
827
827
  worktree_path = create_or_reuse_worktree(repo_path: repo_path, branch: branch)
828
828
 
829
+ # Register a work item so brainiac-github can route PR comments/reviews back
830
+ # to the agent that actually owns this Discord thread's worktree. Without this,
831
+ # PRs created from a conversational session have no work item and comments
832
+ # fall back to the project's default agent.
833
+ project_key = PROJECTS.find { |_k, v| v == project_config }&.first
834
+ register_work_item(branch: branch, worktree: worktree_path, project: project_key, agent: agent_name)
835
+
829
836
  cli, model, effort = detect_thread_overrides(
830
837
  project_config, clean_content,
831
838
  fallback_cli: existing&.dig("cli_provider"),
@@ -932,6 +939,7 @@ module Brainiac
932
939
  head_before, status_before = capture_brainiac_state(project_config, work_dir)
933
940
  prompt_mode = resolved["prompt_mode"] || "stdin"
934
941
 
942
+ started_at = Time.now
935
943
  pid = spawn(spawn_env, *cmd,
936
944
  chdir: work_dir,
937
945
  **(prompt_mode == "stdin" ? { in: prompt_file } : {}),
@@ -951,7 +959,8 @@ module Brainiac
951
959
  meta_file: meta_file, prompt_file: prompt_file, log_file: log_file,
952
960
  attachment_paths: attachment_paths, project_config: project_config,
953
961
  head_before: head_before, status_before: status_before,
954
- supersede_key: supersede_key
962
+ supersede_key: supersede_key,
963
+ resolved: resolved, model: model, work_dir: work_dir, started_at: started_at
955
964
  )
956
965
  end
957
966
 
@@ -1129,7 +1138,8 @@ module Brainiac
1129
1138
 
1130
1139
  def monitor_agent(pid:, session_key:, agent_name:, agent_config_name:, channel_id:, message_id:,
1131
1140
  bot_token:, response_file:, meta_file:, prompt_file:, log_file:,
1132
- 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)
1133
1143
  Thread.new do
1134
1144
  Process.wait(pid)
1135
1145
  exit_status = $CHILD_STATUS
@@ -1139,6 +1149,16 @@ module Brainiac
1139
1149
 
1140
1150
  session_cancelled = ACTIVE_SESSIONS_MUTEX.synchronize { !ACTIVE_SESSIONS.key?(session_key) }
1141
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
+
1142
1162
  if exit_status.signaled? || session_cancelled
1143
1163
  handle_cancelled(exit_status, session_cancelled, agent_name, message_id,
1144
1164
  response_file, meta_file, prompt_file, attachment_paths)
@@ -1167,6 +1187,44 @@ module Brainiac
1167
1187
  schedule_temp_cleanup(prompt_file, attachment_paths)
1168
1188
  end
1169
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
+
1170
1228
  def handle_completed(exit_status:, agent_name:, agent_config_name:, channel_id:, message_id:,
1171
1229
  bot_token:, response_file:, meta_file:, log_file:,
1172
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.13"
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.13
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis