feat(ui): Support multiple concurrent AI response streams and strategy visualization
This commit is contained in:
@@ -11,6 +11,6 @@
|
||||
- [x] Task: Add visual indicators (colors/icons) for Task statuses (Ready, Blocked, Done). 7252d75
|
||||
|
||||
## Phase 3: Live Output Streams
|
||||
- [ ] Task: Refactor the AI response handling to support multiple concurrent UI text streams.
|
||||
- [~] Task: Refactor the AI response handling to support multiple concurrent UI text streams.
|
||||
- [ ] Task: Bind the output of Tier 1 (Planning) to a designated "Strategy" text box.
|
||||
- [ ] Task: Bind the output of Tier 2 and spawned Tier 3/4 workers to the active Task's detail view in the DAG.
|
||||
37
gui_2.py
37
gui_2.py
@@ -338,6 +338,7 @@ class App:
|
||||
|
||||
# MMA Tracks
|
||||
self.tracks: list[dict] = []
|
||||
self.mma_streams: dict[str, str] = {}
|
||||
|
||||
# Prior session log viewing
|
||||
self.is_viewing_prior_session = False
|
||||
@@ -971,10 +972,20 @@ class App:
|
||||
|
||||
elif action == "handle_ai_response":
|
||||
payload = task.get("payload", {})
|
||||
self.ai_response = payload.get("text", "")
|
||||
self.ai_status = payload.get("status", "done")
|
||||
text = payload.get("text", "")
|
||||
stream_id = payload.get("stream_id")
|
||||
|
||||
if stream_id:
|
||||
self.mma_streams[stream_id] = text
|
||||
if stream_id == "Tier 1":
|
||||
if "status" in payload:
|
||||
self.ai_status = payload["status"]
|
||||
else:
|
||||
self.ai_response = text
|
||||
self.ai_status = payload.get("status", "done")
|
||||
|
||||
self._trigger_blink = True
|
||||
if self.ui_auto_add_history:
|
||||
if self.ui_auto_add_history and not stream_id:
|
||||
role = payload.get("role", "AI")
|
||||
with self._pending_history_adds_lock:
|
||||
self._pending_history_adds.append({
|
||||
@@ -2156,11 +2167,18 @@ class App:
|
||||
tracks = orchestrator_pm.generate_tracks(self.ui_epic_input, flat, file_items, history_summary=history)
|
||||
|
||||
with self._pending_gui_tasks_lock:
|
||||
self._pending_gui_tasks.append({
|
||||
"action": "handle_ai_response",
|
||||
"payload": {
|
||||
"text": json.dumps(tracks, indent=2),
|
||||
"stream_id": "Tier 1",
|
||||
"status": "Epic tracks generated."
|
||||
}
|
||||
})
|
||||
self._pending_gui_tasks.append({
|
||||
"action": "show_track_proposal",
|
||||
"payload": tracks
|
||||
})
|
||||
self.ai_status = "Epic tracks generated."
|
||||
except Exception as e:
|
||||
self.ai_status = f"Epic plan error: {e}"
|
||||
print(f"ERROR in _cb_plan_epic background task: {e}")
|
||||
@@ -2871,6 +2889,11 @@ class App:
|
||||
|
||||
imgui.separator()
|
||||
|
||||
imgui.separator()
|
||||
imgui.text("Strategy (Tier 1)")
|
||||
strategy_text = self.mma_streams.get("Tier 1", "")
|
||||
imgui.input_text_multiline("##mma_strategy", strategy_text, imgui.ImVec2(-1, 150), imgui.InputTextFlags_.read_only)
|
||||
|
||||
# 4. Task DAG Visualizer
|
||||
imgui.text("Task DAG")
|
||||
if self.active_track:
|
||||
@@ -2935,6 +2958,12 @@ class App:
|
||||
deps = ticket.get('depends_on', [])
|
||||
if deps:
|
||||
imgui.text_colored(C_LBL, f"Depends on: {', '.join(deps)}")
|
||||
|
||||
stream_key = f"Tier 3: {tid}"
|
||||
if stream_key in self.mma_streams:
|
||||
imgui.separator()
|
||||
imgui.text_colored(C_KEY, "Worker Stream:")
|
||||
imgui.text_wrapped(self.mma_streams[stream_key])
|
||||
imgui.end_tooltip()
|
||||
|
||||
imgui.same_line()
|
||||
|
||||
@@ -11,6 +11,8 @@ output_dir = "./md_gen"
|
||||
base_dir = "."
|
||||
paths = []
|
||||
|
||||
[files.tier_assignments]
|
||||
|
||||
[screenshots]
|
||||
base_dir = "."
|
||||
paths = []
|
||||
|
||||
@@ -8,5 +8,5 @@ active = "main"
|
||||
|
||||
[discussions.main]
|
||||
git_commit = ""
|
||||
last_updated = "2026-02-27T18:57:49"
|
||||
last_updated = "2026-02-27T22:56:03"
|
||||
history = []
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
import json
|
||||
from unittest.mock import patch, MagicMock
|
||||
import threading
|
||||
import time
|
||||
@@ -29,9 +30,11 @@ def test_mma_ui_state_initialization(app_instance):
|
||||
assert hasattr(app_instance, 'ui_epic_input')
|
||||
assert hasattr(app_instance, 'proposed_tracks')
|
||||
assert hasattr(app_instance, '_show_track_proposal_modal')
|
||||
assert hasattr(app_instance, 'mma_streams')
|
||||
assert app_instance.ui_epic_input == ""
|
||||
assert app_instance.proposed_tracks == []
|
||||
assert app_instance._show_track_proposal_modal is False
|
||||
assert app_instance.mma_streams == {}
|
||||
|
||||
def test_process_pending_gui_tasks_show_track_proposal(app_instance):
|
||||
"""Verifies that the 'show_track_proposal' action correctly updates the UI state."""
|
||||
@@ -69,16 +72,21 @@ def test_cb_plan_epic_launches_thread(app_instance):
|
||||
app_instance._cb_plan_epic()
|
||||
|
||||
# Wait for the background thread to finish (it should be quick with mocks)
|
||||
# In a real test, we might need a more robust way to wait, but for now:
|
||||
max_wait = 5
|
||||
start_time = time.time()
|
||||
while len(app_instance._pending_gui_tasks) == 0 and time.time() - start_time < max_wait:
|
||||
while len(app_instance._pending_gui_tasks) < 2 and time.time() - start_time < max_wait:
|
||||
time.sleep(0.1)
|
||||
|
||||
assert len(app_instance._pending_gui_tasks) > 0
|
||||
task = app_instance._pending_gui_tasks[0]
|
||||
assert task['action'] == 'show_track_proposal'
|
||||
assert task['payload'] == mock_tracks
|
||||
assert len(app_instance._pending_gui_tasks) == 2
|
||||
|
||||
task1 = app_instance._pending_gui_tasks[0]
|
||||
assert task1['action'] == 'handle_ai_response'
|
||||
assert task1['payload']['stream_id'] == 'Tier 1'
|
||||
assert task1['payload']['text'] == json.dumps(mock_tracks, indent=2)
|
||||
|
||||
task2 = app_instance._pending_gui_tasks[1]
|
||||
assert task2['action'] == 'show_track_proposal'
|
||||
assert task2['payload'] == mock_tracks
|
||||
|
||||
mock_get_history.assert_called_once()
|
||||
mock_gen_tracks.assert_called_once()
|
||||
@@ -104,3 +112,36 @@ def test_process_pending_gui_tasks_mma_spawn_approval(app_instance):
|
||||
assert app_instance._mma_spawn_edit_mode is False
|
||||
assert task["dialog_container"][0] is not None
|
||||
assert task["dialog_container"][0]._ticket_id == "T1"
|
||||
|
||||
def test_handle_ai_response_with_stream_id(app_instance):
|
||||
"""Verifies routing to mma_streams."""
|
||||
task = {
|
||||
"action": "handle_ai_response",
|
||||
"payload": {
|
||||
"text": "Tier 1 Strategy Content",
|
||||
"stream_id": "Tier 1",
|
||||
"status": "Thinking..."
|
||||
}
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
|
||||
assert app_instance.mma_streams.get("Tier 1") == "Tier 1 Strategy Content"
|
||||
assert app_instance.ai_status == "Thinking..."
|
||||
assert app_instance.ai_response == ""
|
||||
|
||||
def test_handle_ai_response_fallback(app_instance):
|
||||
"""Verifies fallback to ai_response when stream_id is missing."""
|
||||
task = {
|
||||
"action": "handle_ai_response",
|
||||
"payload": {
|
||||
"text": "Regular AI Response",
|
||||
"status": "done"
|
||||
}
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
|
||||
assert app_instance.ai_response == "Regular AI Response"
|
||||
assert app_instance.ai_status == "done"
|
||||
assert len(app_instance.mma_streams) == 0
|
||||
|
||||
Reference in New Issue
Block a user