From 1a305ee6143cb1261b524c6f387569ab24bbe896 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 14 Mar 2026 09:35:41 -0400 Subject: [PATCH] fix(gui): push AI monologue/text chunks to discussion history immediately per round instead of accumulating --- src/app_controller.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/app_controller.py b/src/app_controller.py index 1689c4f..39d3376 100644 --- a/src/app_controller.py +++ b/src/app_controller.py @@ -611,20 +611,6 @@ class AppController: self._token_stats_dirty = True if not is_streaming: self._autofocus_response_tab = True - # ONLY add to history when turn is complete - if self.ui_auto_add_history and not stream_id and not is_streaming: - role = payload.get("role", "AI") - segments, parsed_response = thinking_parser.parse_thinking_trace(self.ai_response) - entry = { - "role": role, - "content": parsed_response, - "collapsed": True, - "ts": project_manager.now_ts() - } - if segments: - entry["thinking_segments"] = [{"content": s.content, "marker": s.marker} for s in segments] - with self._pending_history_adds_lock: - self._pending_history_adds.append(entry) elif action in ("mma_stream", "mma_stream_append"): # Some events might have these at top level, some in a 'payload' dict stream_id = task.get("stream_id") or task.get("payload", {}).get("stream_id") @@ -1495,6 +1481,25 @@ class AppController: "ts": entry.get("ts", project_manager.now_ts()) }) + if kind == "response": + if self.ui_auto_add_history: + role = payload.get("role", "AI") + text_content = payload.get("text", "") + if text_content.strip(): + segments, parsed_response = thinking_parser.parse_thinking_trace(text_content) + entry_obj = { + "role": role, + "content": parsed_response.strip() if parsed_response else "", + "collapsed": True, + "ts": entry.get("ts", project_manager.now_ts()) + } + if segments: + entry_obj["thinking_segments"] = [{"content": s.content, "marker": s.marker} for s in segments] + + if entry_obj["content"] or segments: + with self._pending_history_adds_lock: + self._pending_history_adds.append(entry_obj) + if kind in ("tool_result", "tool_call"): if self.ui_auto_add_history: role = "Tool" if kind == "tool_result" else "Vendor API"