brainiac-fizzy 0.0.21 → 0.0.23

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: e1056d8b7b4c49d9d894136c786cdcc06ac9afc2c99a4170c3853ba4fd5e00d6
4
- data.tar.gz: fc14a297accc9f82468fc31ca9e3fe5ce450d42a3d5445fdda72cadf463862d5
3
+ metadata.gz: 49fb9f716295e5635310802446ef24b4ab0fc50a0de0e7ed51aa6d8a66229cb3
4
+ data.tar.gz: 877d8bb3380a19038ff7d5783b249e3ef5f8334074985b46bfeba2f82e174be1
5
5
  SHA512:
6
- metadata.gz: 9020ce620ad63e672f7649e073e42ac173f2209ade3096b1e155f83bee296b3f54cb5e048da57bee7acba8c2a46e6e215b1d80544f9b65d0f6073a560906a2bc
7
- data.tar.gz: a871635aa26480877c983cdb352d6267a474cd8e970dbead96881c5f2e45f8b6bf77bc2b58c777dcc6ba64cca4327b21bf2d773c4210371e9733617b4160ba17
6
+ metadata.gz: cea8aef292a4c13e70d551c666ef541aeb4c017077feff75dbfa47fee6c7cfad65c07050c1360735279120124442c178bae7d7a11cd7b36f71fc2fe597dd6469
7
+ data.tar.gz: f39a533e11ab58b15ac93a360026b660c67b612fa7f6e17b58ebf91ad280e17b4eed65ab3076da76406d8d8207e6d85c7fa54eae32554a354bf1c51081074325
@@ -33,6 +33,22 @@ end
33
33
  DEPLOYMENTS_CONFIG = load_deployments_config
34
34
  DEPLOYMENT_STATE = load_deployment_state
35
35
 
36
+ # Load work items as a card-map-compatible structure for deployment lookups.
37
+ def load_card_map
38
+ map = load_work_item_map
39
+ map.transform_values do |entry|
40
+ {
41
+ "worktree" => entry["worktree"],
42
+ "branch" => entry["branch"],
43
+ "number" => entry.dig("sources", "fizzy", "card_number"),
44
+ "title" => entry.dig("sources", "fizzy", "card_title"),
45
+ "prs" => entry.dig("sources", "github", "prs") || []
46
+ }
47
+ end
48
+ rescue StandardError
49
+ {}
50
+ end
51
+
36
52
  def reload_deployments_config!(force: false)
37
53
  return unless file_changed?(DEPLOYMENTS_CONFIG_FILE, force: force)
38
54
 
@@ -50,7 +50,7 @@ module Brainiac
50
50
 
51
51
  def agent_commented_on_card?(card_number, agent_name, repo_path:, since: nil)
52
52
  env = Helpers.fizzy_env_for(agent_name)
53
- output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, chdir: repo_path, env: env)
53
+ output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, "--all", chdir: repo_path, env: env)
54
54
  comments = JSON.parse(output)["data"] || []
55
55
  agent_display = agent_display_name(agent_name)
56
56
 
@@ -111,14 +111,14 @@ module Brainiac
111
111
  project_config)
112
112
  Thread.new do
113
113
  wait_for_process_or_timeout(pid, timeout: 60)
114
- sleep 2 # Brief pause to let any comment propagate
114
+ sleep 5 # Wait for Fizzy API propagation before checking
115
115
 
116
116
  unless agent_commented_on_card?(card_number, agent_name, repo_path: repo_path, since: session_started_at)
117
117
  post_fallback_comment(card_number, branch, agent_name, project_config)
118
118
  end
119
119
  rescue Errno::ECHILD
120
120
  # Process already reaped by session manager — check for comment
121
- sleep 2
121
+ sleep 5
122
122
  unless agent_commented_on_card?(card_number, agent_name, repo_path: repo_path, since: session_started_at)
123
123
  post_fallback_comment(card_number, branch, agent_name, project_config)
124
124
  end
@@ -59,7 +59,7 @@ module Brainiac
59
59
  end
60
60
 
61
61
  def fetch_card_comments(card_number, repo_path:, env:)
62
- output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, chdir: repo_path, env: env)
62
+ output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, "--all", chdir: repo_path, env: env)
63
63
  comments = JSON.parse(output)["data"] || []
64
64
  return "" if comments.empty?
65
65
 
@@ -77,7 +77,7 @@ module Brainiac
77
77
  # Returns a simple "author: message" format (last 5 comments).
78
78
  def fetch_intent_context(card_number, repo_path:, agent_name: nil)
79
79
  env = fizzy_env_for(agent_name || AI_AGENT_NAME)
80
- output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, chdir: repo_path, env: env)
80
+ output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, "--all", chdir: repo_path, env: env)
81
81
  comments = JSON.parse(output)["data"] || []
82
82
  return nil if comments.empty?
83
83
 
@@ -106,7 +106,7 @@ module Brainiac
106
106
  repo_path = project_config["repo_path"]
107
107
  env = fizzy_env_for(agent_name || AI_AGENT_NAME)
108
108
 
109
- output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, chdir: repo_path, env: env)
109
+ output = run_cmd("fizzy", "comment", "list", "--card", card_number.to_s, "--all", chdir: repo_path, env: env)
110
110
  comments = JSON.parse(output)["data"] || []
111
111
  agent_display = agent_display_name(agent_name || AI_AGENT_NAME)
112
112
 
@@ -48,6 +48,17 @@ module Brainiac
48
48
  agent_name: ctx[:agent_name],
49
49
  since: ctx[:source_context]&.dig(:dispatched_at))
50
50
 
51
+ # Retry once after a short delay to account for Fizzy API propagation.
52
+ # The agent may have posted its comment just before exiting, and the API
53
+ # might not return it immediately in a list call.
54
+ if !found_comment
55
+ sleep 5
56
+ found_comment = Helpers.append_fizzy_comment_footer(card_number,
57
+ project_config: ctx[:project_config],
58
+ agent_name: ctx[:agent_name],
59
+ since: ctx[:source_context]&.dig(:dispatched_at))
60
+ end
61
+
51
62
  # If the agent didn't post any comment during this session, re-dispatch to summarize from memory.
52
63
  # Uses dispatched_at from source_context to only check for comments made during THIS session,
53
64
  # not previous sessions on the same card.
@@ -349,20 +360,38 @@ module Brainiac
349
360
  boards = Config.boards
350
361
  return if boards.empty?
351
362
 
352
- env = Helpers.default_fizzy_env
363
+ admin_token = Config.current["admin_token"]
364
+ unless admin_token
365
+ LOG.debug "[Fizzy] Webhook reactivation check skipped (no admin_token in fizzy.json)"
366
+ return
367
+ end
368
+
369
+ env = { "FIZZY_TOKEN" => admin_token }
353
370
  boards.each do |board_key, board_config|
354
371
  board_id = board_config["board_id"]
355
372
  next unless board_id
356
373
 
357
- output = run_cmd("fizzy", "webhook", "list", "--board", board_id, "--all", "--json", env: env)
358
- webhooks = JSON.parse(output)["data"] || []
374
+ stdout, _stderr, status = Open3.capture3(env, "fizzy", "webhook", "list",
375
+ "--board", board_id, "--all", "--json",
376
+ chdir: Dir.home)
377
+ unless status.success?
378
+ parsed = JSON.parse(stdout) rescue nil
379
+ if parsed&.dig("code") == "forbidden"
380
+ LOG.warn "[Fizzy] Webhook check failed for board '#{board_key}' (admin_token lacks permission)"
381
+ else
382
+ LOG.warn "[Fizzy] Could not check webhooks for board '#{board_key}': exit #{status.exitstatus}"
383
+ end
384
+ next
385
+ end
359
386
 
387
+ webhooks = (JSON.parse(stdout)["data"] || [])
360
388
  webhooks.each do |webhook|
361
389
  next unless webhook["name"]&.start_with?("brainiac")
362
390
  next if webhook["active"]
363
391
 
364
392
  LOG.info "[Fizzy] Reactivating webhook '#{webhook["name"]}' on board '#{board_key}' (was inactive)"
365
- run_cmd("fizzy", "webhook", "reactivate", webhook["id"], "--board", board_id, env: env)
393
+ run_cmd("fizzy", "webhook", "reactivate", webhook["id"], "--board", board_id,
394
+ chdir: Dir.home, env: env)
366
395
  end
367
396
  rescue StandardError => e
368
397
  LOG.warn "[Fizzy] Could not check webhooks for board '#{board_key}': #{e.message}"
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Fizzy
6
- VERSION = "0.0.21"
6
+ VERSION = "0.0.23"
7
7
  end
8
8
  end
9
9
  end
@@ -171,6 +171,27 @@ module Brainiac
171
171
  LOG.info "[Fizzy:Deploy] #{env_key} marked deploying via API"
172
172
  { status: "deploying", env: env_key }.to_json
173
173
  end
174
+
175
+ app.post "/api/deployments/:env/failed" do
176
+ content_type :json
177
+ env_key = params["env"]
178
+ config = DEPLOYMENTS_CONFIG["environments"] || {}
179
+ halt 404, { error: "Unknown environment: #{env_key}" }.to_json unless config.key?(env_key)
180
+ request.body.rewind
181
+ payload = begin
182
+ JSON.parse(request.body.read)
183
+ rescue StandardError
184
+ {}
185
+ end
186
+ state = load_deployment_state
187
+ state[env_key] ||= {}
188
+ state[env_key]["last_deploy_status"] = "failed"
189
+ state[env_key]["last_deploy_at"] = Time.now.iso8601
190
+ save_deployment_state(state)
191
+ DEPLOYMENT_STATE.replace(state)
192
+ LOG.info "[Fizzy:Deploy] #{env_key} marked failed via API"
193
+ { status: "failed", env: env_key }.to_json
194
+ end
174
195
  end
175
196
 
176
197
  public
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.21
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis