diff --git a/Sensor/adr_sensor/parsers/warp_parser.py b/Sensor/adr_sensor/parsers/warp_parser.py index bb65e154..4f34b4a6 100644 --- a/Sensor/adr_sensor/parsers/warp_parser.py +++ b/Sensor/adr_sensor/parsers/warp_parser.py @@ -222,6 +222,18 @@ def _create_entry_from_exchanges( msg = ChatMessage(role="user", content=text, tools=[], sequence_id=sequence_id) entry.chat_history.append(msg) + # Legacy databases keep the model's reply to the query in ai_blocks. + response_text = self._extract_llm_text(llm_output) + if response_text: + entry.chat_history.append( + ChatMessage( + role="assistant", + content=response_text, + tools=[], + sequence_id=f"{sequence_id}_response", + ) + ) + elif "ActionResult" in first_item: action_result = first_item["ActionResult"] tools = [] diff --git a/Sensor/tests/test_parsers.py b/Sensor/tests/test_parsers.py index ffeb2fd2..d50d876c 100644 --- a/Sensor/tests/test_parsers.py +++ b/Sensor/tests/test_parsers.py @@ -1985,13 +1985,17 @@ def test_parses_conversation_content(self, tmp_path): entry = entries[0] assert entry.source == "warp" assert entry.session_id == "warp_conv-1" - assert len(entry.chat_history) == 2 + assert len(entry.chat_history) == 3 user_msg = entry.chat_history[0] assert user_msg.role == "user" assert "hello from ex-1" in user_msg.content - assistant_msg = entry.chat_history[1] + reply_msg = entry.chat_history[1] + assert reply_msg.role == "assistant" + assert reply_msg.content == "reply for ex-1" + + assistant_msg = entry.chat_history[2] assert assistant_msg.role == "assistant" assert len(assistant_msg.tools) == 1 assert assistant_msg.tools[0].tool_name == "execute_command" @@ -2036,6 +2040,27 @@ def test_legacy_schema_retains_llm_output(self, tmp_path): assert len(entries) == 1 assert entries[0].chat_history[0].content == "synthetic response" + def test_legacy_schema_retains_query_response(self, tmp_path): + """The model's reply to a user query is kept alongside the query.""" + now = datetime.now(timezone.utc).isoformat() + conversations = [ + { + "conversation_id": "legacy-query-conv", + "last_modified_at": now, + "exchanges": [self._query_exchange("legacy-query", now)], + } + ] + db_path = tmp_path / "warp.sqlite" + _build_warp_db(db_path, conversations) + + entries = self._make_parser(tmp_path).parse_all() + + assert len(entries) == 1 + assert [(m.role, m.content) for m in entries[0].chat_history] == [ + ("user", "hello from legacy-query"), + ("assistant", "reply for legacy-query"), + ] + def test_checks_legacy_table_once_per_database(self, tmp_path): """Schema detection should not add one sqlite_master query per conversation.""" now = datetime.now(timezone.utc).isoformat()