brainiac-github 0.2.4 → 0.2.6

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: 4cb6c5132e15d851261b150a636b895a0d8d8f6487b51a5049290a1ce2f12274
4
- data.tar.gz: c6bf867e0bb5dbca4008e0971dc0568fb95755c2b296b7865e889e2d09645120
3
+ metadata.gz: 6a7a75791c3df9f85c5e2d545bbaa83bc496a7d6f88c34f38a84d73a5bcced59
4
+ data.tar.gz: 896ba92478b7d36dbc9e99f71586c4c0fdb4e777a007e087412ccaf71b2cabdd
5
5
  SHA512:
6
- metadata.gz: ed2481547416f7bd7d0194aff3ec96da00811c6fe2a4ee8478b4f90c63820fde0318e7ea2427ba07646bd5755abcba3ac2a3c32af78170abb6eebb461f54a4dc
7
- data.tar.gz: 3df84f31506b7fbeeaf7636f84b8d8602a9e6fee9d6d8a6a4b18b4f5b76a9de666df79e5c2dccb9c81d1f90727bc8ffd60cc8b784776ea8f55ef0385e3234791
6
+ metadata.gz: eca03777383a673758eb035ea69ed5b604d6fe289486cd4cb5e943c93fb8e6c14a1057268ed68c5ee04adc5fc6744219734dd6756f70b60b00e4720269a28fd6
7
+ data.tar.gz: 17fafeac99cfe179febe43424dd4bf791e199d226f6dc92022f5ce9f7643b151cdbe65698ef956d9794c2651eaff012d0f66395cfb296cf3b13b9dbf1664e0f0
@@ -126,6 +126,16 @@ module Brainiac
126
126
  repo_name = payload.dig("repository", "full_name")
127
127
  review_state = review["state"]
128
128
  reviewer = review.dig("user", "login")
129
+ reviewer_type = review.dig("user", "type")
130
+
131
+ # If the review was submitted by a remote agent bot, ignore — the other machine handles it.
132
+ if reviewer_type == "Bot"
133
+ reviewing_agent = agent_name_from_bot_login(reviewer)
134
+ if reviewing_agent && !local_agent_names.include?(reviewing_agent)
135
+ LOG.info "[GitHub] Ignoring review from remote agent bot #{reviewer} (agent: #{reviewing_agent}) on PR ##{pr_number}"
136
+ return [200, { status: "ignored", reason: "remote agent bot review" }.to_json]
137
+ end
138
+ end
129
139
 
130
140
  # If the PR was opened by a remote agent bot (not local to this machine),
131
141
  # skip dispatch — the other machine that owns the agent will handle it.
@@ -172,6 +182,18 @@ module Brainiac
172
182
  return [200, { status: "processed", card: card_number, pr: pr_number, reviewer: reviewer, action: "hook_only" }.to_json]
173
183
  end
174
184
 
185
+ # If the work item's assigned agent is NOT local to this machine,
186
+ # skip dispatch — the other machine owns this PR's agent.
187
+ # This check is intentionally AFTER the hook emit so gate tracking
188
+ # works on both machines, but only one machine dispatches the agent.
189
+ if result
190
+ work_item_agent = card_info["agent"]
191
+ if work_item_agent && !local_agent_names.include?(work_item_agent)
192
+ LOG.info "[GitHub] PR ##{pr_number} assigned to remote agent #{work_item_agent} — skipping review dispatch"
193
+ return [200, { status: "ignored", reason: "work item owned by remote agent" }.to_json]
194
+ end
195
+ end
196
+
175
197
  card_key = "pr-review-#{repo_name.tr("/", "-")}-#{pr_number}"
176
198
 
177
199
  return [200, { status: "ignored", reason: "session already active" }.to_json] if session_active?(card_key)
@@ -236,12 +258,12 @@ module Brainiac
236
258
  agent_name = mentioned
237
259
  end
238
260
 
239
- # Ignore comments from this project's own bot to prevent self-triggering.
240
- # Cross-agent bot comments (e.g. GLaDOS commenting on Galen's PR) are still processed.
241
- if comment_user_type == "Bot" && own_bot_comment?(comment_user, agent_name)
242
- LOG.info "Ignoring self-triggered bot comment from #{comment_user} (agent: #{agent_name})"
243
- return [200, { status: "ignored", reason: "self-triggered bot comment" }.to_json]
244
- end
261
+ # Ignore comments from agent bots that shouldn't trigger dispatch on this machine:
262
+ # 1. Self-triggered: bot matches the dispatching agent (prevents loops)
263
+ # 2. Remote agent: bot matches a known agent that isn't local (other machine handles it)
264
+ # Cross-agent LOCAL bot comments (e.g. GLaDOS commenting on Galen's PR) are still processed.
265
+ bot_ignore_reason = bot_comment_ignore_reason(comment_user, comment_user_type, agent_name, pr_number)
266
+ return bot_ignore_reason if bot_ignore_reason
245
267
 
246
268
  branch = fetch_pr_branch(repo_name, pr_number, agent_name, project_config)
247
269
  result = find_work_item_by_branch(branch)
@@ -251,12 +273,22 @@ module Brainiac
251
273
  # route to whoever is actually working it (e.g. GLaDOS opened the PR,
252
274
  # so GLaDOS should handle follow-up comments — not the project's default agent).
253
275
  # Explicit mentions still take priority (already resolved above).
276
+ #
277
+ # If the work item's assigned agent is NOT local to this machine,
278
+ # skip dispatch entirely — the other machine owns this PR's agent.
254
279
  if result && !mentioned
255
280
  _, card_info = result
256
281
  work_item_agent = card_info["agent"]
257
- if work_item_agent && work_item_agent.downcase != agent_name.downcase && local_agent_names.include?(work_item_agent)
258
- LOG.info "[GitHub] Work item agent override: #{work_item_agent} (project default: #{agent_name})"
259
- agent_name = work_item_agent
282
+ if work_item_agent
283
+ if local_agent_names.include?(work_item_agent)
284
+ if work_item_agent.downcase != agent_name.downcase
285
+ LOG.info "[GitHub] Work item agent override: #{work_item_agent} (project default: #{agent_name})"
286
+ agent_name = work_item_agent
287
+ end
288
+ else
289
+ LOG.info "[GitHub] PR ##{pr_number} assigned to remote agent #{work_item_agent} — skipping dispatch"
290
+ return [200, { status: "ignored", reason: "work item owned by remote agent" }.to_json]
291
+ end
260
292
  end
261
293
  end
262
294
 
@@ -494,6 +526,30 @@ module Brainiac
494
526
  nil
495
527
  end
496
528
 
529
+ # Determine if a bot comment should be ignored by this machine.
530
+ # Returns a Rack response array if the comment should be ignored, or nil if it should be processed.
531
+ #
532
+ # Ignores:
533
+ # 1. Self-triggered: bot matches the dispatching agent (prevents loops)
534
+ # 2. Remote agent: bot matches a known agent that isn't local (other machine handles it)
535
+ # Allows: cross-agent LOCAL bot comments (e.g. GLaDOS commenting on Galen's PR)
536
+ def bot_comment_ignore_reason(comment_user, comment_user_type, agent_name, pr_number)
537
+ return nil unless comment_user_type == "Bot"
538
+
539
+ if own_bot_comment?(comment_user, agent_name)
540
+ LOG.info "Ignoring self-triggered bot comment from #{comment_user} (agent: #{agent_name})"
541
+ return [200, { status: "ignored", reason: "self-triggered bot comment" }.to_json]
542
+ end
543
+
544
+ commenting_agent = agent_name_from_bot_login(comment_user)
545
+ if commenting_agent && !local_agent_names.include?(commenting_agent)
546
+ LOG.info "[GitHub] Ignoring comment from remote agent bot #{comment_user} (agent: #{commenting_agent}) on PR ##{pr_number}"
547
+ return [200, { status: "ignored", reason: "remote agent bot comment" }.to_json]
548
+ end
549
+
550
+ nil
551
+ end
552
+
497
553
  # Check if a bot comment is from the same agent that would handle this PR.
498
554
  # e.g. "galen-brainiac[bot]" is a self-trigger for agent "Galen",
499
555
  # but "glados-brainiac[bot]" is a cross-agent request and should be processed.
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Github
6
- VERSION = "0.2.4"
6
+ VERSION = "0.2.6"
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-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis