brainiac-fizzy 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: 90ffad33201985cb5a94b3460fb635d254e806e435543eeb652b533ff59562a6
4
- data.tar.gz: 209e7829523442c8ccc7e3a278454ddd008fd16df6f83495e1edd42c0ac9dada
3
+ metadata.gz: 6ed1ef3ae4c3db228a9a98a796579e7450e25fad4e19fa5ce075777e677342cc
4
+ data.tar.gz: 9e5ceac2510d64194bc498850871ca8105aeea24b742e9930ede13c761928f50
5
5
  SHA512:
6
- metadata.gz: 207769fa7579c519e38ff9551a5b4fb0ff823c1cb88740b7bd3b7f1a459bfd8c7e9ea97e62fd7a6dbeb8a48218595d08143564be8cd577ff32a264be7a97d947
7
- data.tar.gz: e5d52c3fc6dcf2427b70030fccdb3a9196b2c00ecf63b934710accbaa3cdfef16a7c98765afac1ae33435d86f58837371097b697e733d8484f8bdee6efdedef7
6
+ metadata.gz: 73f14f9e28f8eaba2558fac32e14116d0255fdb513cd2ba13753f1e5babe9a311807620832b75cd4b46282473e0603a1127a38483f18034177c0d983a84b5146
7
+ data.tar.gz: d45acdf7a664c1585b262230a0b1cf70eff969699fc80c270193ccedf0d902ed7876fc6d3eb353acf4768217bd88babced1f10db835b6aa7e13edde62b57b27c
@@ -33,8 +33,8 @@ def move_card_to_column(card_number, column_name, project_config:, agent_name: n
33
33
  Brainiac::Plugins::Fizzy::Helpers.move_card_to_column(card_number, column_name, project_config: project_config, agent_name: agent_name)
34
34
  end
35
35
 
36
- def append_fizzy_comment_footer(card_number, project_config:, agent_name: nil)
37
- Brainiac::Plugins::Fizzy::Helpers.append_fizzy_comment_footer(card_number, project_config: project_config, agent_name: agent_name)
36
+ def append_fizzy_comment_footer(card_number, project_config:, agent_name: nil, since: nil)
37
+ Brainiac::Plugins::Fizzy::Helpers.append_fizzy_comment_footer(card_number, project_config: project_config, agent_name: agent_name, since: since)
38
38
  end
39
39
 
40
40
  def ensure_fizzy_yaml!(chdir, project_config)
@@ -44,18 +44,23 @@ module Brainiac
44
44
 
45
45
  # Check if the agent posted a comment on the card since a given time.
46
46
  # If no `since` is provided, checks for any agent comment (legacy behavior).
47
+ # Subtracts a 30s buffer from `since` to account for clock skew between
48
+ # the local server and the Fizzy API.
49
+ CLOCK_SKEW_BUFFER = 30
50
+
47
51
  def agent_commented_on_card?(card_number, agent_name, repo_path:, since: nil)
48
52
  env = Helpers.fizzy_env_for(agent_name)
49
53
  output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, chdir: repo_path, env: env)
50
54
  comments = JSON.parse(output)["data"] || []
51
55
  agent_display = agent_display_name(agent_name)
52
56
 
53
- agent_comments = comments.select { |c| c["creator_name"]&.downcase == agent_display.downcase }
57
+ agent_comments = comments.select { |c| c.dig("creator", "name")&.downcase == agent_display.downcase }
54
58
  return agent_comments.any? unless since
55
59
 
60
+ buffered_since = since - CLOCK_SKEW_BUFFER
56
61
  agent_comments.any? do |c|
57
62
  comment_time = c["created_at"] && Time.parse(c["created_at"])
58
- comment_time && comment_time > since
63
+ comment_time && comment_time > buffered_since
59
64
  end
60
65
  rescue StandardError
61
66
  false
@@ -66,7 +66,7 @@ module Brainiac
66
66
  comments.last(15).map do |c|
67
67
  body = c.dig("body", "plain_text") || ""
68
68
  body = "#{body[0..500]}..." if body.length > 500
69
- "**#{c["creator_name"]}** (#{c["id"]}):\n#{body}"
69
+ "**#{c.dig("creator", "name")}** (#{c["id"]}):\n#{body}"
70
70
  end.join("\n\n---\n\n")
71
71
  rescue StandardError => e
72
72
  LOG.warn "[Fizzy] Could not fetch comments for card ##{card_number}: #{e.message}" if defined?(LOG)
@@ -82,7 +82,7 @@ module Brainiac
82
82
  return nil if comments.empty?
83
83
 
84
84
  comments.last(5).map do |c|
85
- creator = c["creator_name"] || "unknown"
85
+ creator = c.dig("creator", "name") || "unknown"
86
86
  body = (c.dig("body", "plain_text") || "").lines.first(3).join.strip
87
87
  body = "#{body[0..200]}..." if body.length > 200
88
88
  "#{creator}: #{body}"
@@ -102,7 +102,7 @@ module Brainiac
102
102
  run_cmd("fizzy", "card", "column", card_number.to_s, "--column", column_id, chdir: repo_path, env: env)
103
103
  end
104
104
 
105
- def append_fizzy_comment_footer(card_number, project_config:, agent_name: nil)
105
+ def append_fizzy_comment_footer(card_number, project_config:, agent_name: nil, since: nil)
106
106
  repo_path = project_config["repo_path"]
107
107
  env = fizzy_env_for(agent_name || AI_AGENT_NAME)
108
108
 
@@ -110,29 +110,40 @@ module Brainiac
110
110
  comments = JSON.parse(output)["data"] || []
111
111
  agent_display = agent_display_name(agent_name || AI_AGENT_NAME)
112
112
 
113
- last_agent_comment = comments.reverse.find do |c|
114
- c["creator_name"]&.downcase == agent_display.downcase
113
+ # Find the most recent agent comment, scoped to this session if `since` is provided.
114
+ # Subtracts 30s buffer from `since` to account for clock skew between local server and Fizzy API.
115
+ agent_comments = comments.select { |c| c.dig("creator", "name")&.downcase == agent_display.downcase }
116
+ if since
117
+ buffered_since = since - 30
118
+ agent_comments = agent_comments.select do |c|
119
+ comment_time = c["created_at"] && Time.parse(c["created_at"])
120
+ comment_time && comment_time > buffered_since
121
+ end
115
122
  end
116
- return unless last_agent_comment
117
-
118
- # Check if footer already exists
119
- body = last_agent_comment.dig("body", "html") || ""
120
- return if body.include?("<em>Branch:")
121
123
 
122
- # Detect branch from comment content or card map
123
- branch = detect_branch_from_comment(body, card_number)
124
- return unless branch
124
+ last_agent_comment = agent_comments.last
125
+ return false unless last_agent_comment
125
126
 
126
- pr_url = detect_pr_url(branch, project_config)
127
- footer = "<p><em>Branch: <code>#{branch}</code>"
128
- footer += " | <a href=\"#{pr_url}\">PR</a>" if pr_url
129
- footer += "</em></p>"
127
+ # Append footer if applicable
128
+ body = last_agent_comment.dig("body", "html") || ""
129
+ unless body.include?("<em>Branch:")
130
+ branch = detect_branch_from_comment(body, card_number)
131
+ if branch
132
+ pr_url = detect_pr_url(branch, project_config)
133
+ footer = "<p><em>Branch: <code>#{branch}</code>"
134
+ footer += " | <a href=\"#{pr_url}\">PR</a>" if pr_url
135
+ footer += "</em></p>"
136
+
137
+ updated_body = body + footer
138
+ run_cmd("fizzy", "comment", "update", last_agent_comment["id"], "--card", card_number.to_s,
139
+ "--body", updated_body, chdir: repo_path, env: env)
140
+ end
141
+ end
130
142
 
131
- updated_body = body + footer
132
- run_cmd("fizzy", "comment", "update", last_agent_comment["id"], "--card", card_number.to_s,
133
- "--body", updated_body, chdir: repo_path, env: env)
143
+ true
134
144
  rescue StandardError => e
135
145
  LOG.warn "[Fizzy] Could not append footer to card ##{card_number}: #{e.message}" if defined?(LOG)
146
+ false
136
147
  end
137
148
 
138
149
  def ensure_fizzy_yaml!(chdir, project_config)
@@ -42,17 +42,16 @@ module Brainiac
42
42
  record_self_move(card_number)
43
43
  end
44
44
 
45
- Helpers.append_fizzy_comment_footer(card_number,
46
- project_config: ctx[:project_config],
47
- agent_name: ctx[:agent_name])
45
+ found_comment = Helpers.append_fizzy_comment_footer(card_number,
46
+ project_config: ctx[:project_config],
47
+ agent_name: ctx[:agent_name],
48
+ since: ctx[:source_context]&.dig(:dispatched_at))
48
49
 
49
50
  # If the agent didn't post any comment during this session, re-dispatch to summarize from memory.
50
51
  # Uses dispatched_at from source_context to only check for comments made during THIS session,
51
52
  # not previous sessions on the same card.
52
- if !ctx[:source_context]&.dig(:skip_summarize_redispatch) &&
53
- !agent_commented_on_card?(card_number, ctx[:agent_name],
54
- repo_path: ctx[:project_config]["repo_path"],
55
- since: ctx[:source_context]&.dig(:dispatched_at))
53
+ if !found_comment &&
54
+ !ctx[:source_context]&.dig(:skip_summarize_redispatch)
56
55
  dispatch_summarize_session(ctx)
57
56
  end
58
57
 
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Fizzy
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-fizzy
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