chore(cli): cache report finalizers (#137)

This commit is contained in:
ahmet guzererler 2026-03-27 14:51:40 +01:00 committed by GitHub
parent 9ccb22d073
commit 7d9d69a520
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 3 deletions

View File

@ -93,6 +93,7 @@ class MessageBuffer:
self.agent_status = {}
self.current_agent = None
self.report_sections = {}
self.report_finalizers = {}
self.selected_analysts = []
self._last_message_id = None
@ -119,9 +120,11 @@ class MessageBuffer:
# Build report_sections dynamically
self.report_sections = {}
self.report_finalizers = {}
for section, (analyst_key, _) in self.REPORT_SECTIONS.items():
if analyst_key is None or analyst_key in self.selected_analysts:
self.report_sections[section] = None
self.report_finalizers[section] = self.REPORT_SECTIONS[section][1]
# Reset other state
self.current_report = None
@ -145,8 +148,8 @@ class MessageBuffer:
count = 0
for section, content in self.report_sections.items():
if content is not None:
section_info = self.REPORT_SECTIONS.get(section)
if section_info and self.agent_status.get(section_info[1]) == "completed":
finalizing_agent = self.report_finalizers.get(section)
if finalizing_agent and self.agent_status.get(finalizing_agent) == "completed":
count += 1
return count

View File

@ -1,5 +1,5 @@
import pytest
from cli.main import extract_content_string
from cli.main import MessageBuffer, extract_content_string
def test_extract_content_string_empty():
assert extract_content_string(None) is None
@ -25,3 +25,28 @@ def test_extract_content_string_dict():
def test_extract_content_string_list():
assert extract_content_string([{"type": "text", "text": "hello"}, " world"]) == "hello world"
def test_message_buffer_completed_reports_count_tracks_active_sections_only():
buffer = MessageBuffer()
buffer.init_for_analysis(["market", "news"])
buffer.report_sections["market_report"] = "done"
buffer.report_sections["news_report"] = "done"
buffer.report_sections["investment_plan"] = "done"
buffer.agent_status["Market Analyst"] = "completed"
buffer.agent_status["News Analyst"] = "pending"
buffer.agent_status["Research Manager"] = "completed"
assert buffer.get_completed_reports_count() == 2
def test_message_buffer_completed_reports_count_ignores_unknown_section():
buffer = MessageBuffer()
buffer.init_for_analysis(["market"])
buffer.report_sections["market_report"] = "done"
buffer.report_sections["unexpected_report"] = "done"
buffer.agent_status["Market Analyst"] = "completed"
assert buffer.get_completed_reports_count() == 1