The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): lead persisted image turns with the caption
Brooklyn Nicholson9b33f549131b
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.pyindex 3644e972de6..f70291c3e6c 100644--- a/tests/test_tui_gateway_server.py+++ b/tests/test_tui_gateway_server.py@@ -13212,8 +13212,8 @@ def test_build_persist_message_with_image_refs_without_images_returns_text(monkeassert server._build_persist_message_with_image_refs("", []) == ""-def test_build_persist_message_with_image_refs_prepends_existing_paths(monkeypatch, tmp_path):- """Attached images that still exist on disk are persisted as leading+def test_build_persist_message_with_image_refs_appends_existing_paths(monkeypatch, tmp_path):+ """Attached images that still exist on disk are persisted as trailing``@image:<path>`` directive lines so the desktop renders them after arestart (instead of the vision-only enrichment that silently breaks)."""img = tmp_path / "cat.png"@@ -13221,7 +13221,19 @@ def test_build_persist_message_with_image_refs_prepends_existing_paths(monkeypatresult = server._build_persist_message_with_image_refs("what is in this photo?", [str(img)])- assert result == f"@image:{img}\nwhat is in this photo?"+ assert result == f"what is in this photo?\n@image:{img}"+++def test_build_persist_message_keeps_the_caption_on_the_first_line(tmp_path):+ """Session previews are the first 60 characters of the first user message,+ so a leading directive would title the session with a truncated file path+ in the sidebar, switcher, and command palette."""+ img = tmp_path / "cat.png"+ img.write_bytes(b"png")++ result = server._build_persist_message_with_image_refs("what is in this photo?", [str(img)])++ assert result.split("\n", 1)[0] == "what is in this photo?"def test_build_persist_message_with_image_refs_skips_missing_paths(monkeypatch, tmp_path):@@ -13233,7 +13245,7 @@ def test_build_persist_message_with_image_refs_skips_missing_paths(monkeypatch,result = server._build_persist_message_with_image_refs("compare them", [str(existing), missing])- assert result == f"@image:{existing}\ncompare them"+ assert result == f"compare them\n@image:{existing}"def test_build_persist_message_with_image_refs_without_text_is_refs_only(monkeypatch, tmp_path):@@ -13257,7 +13269,7 @@ def test_build_persist_message_quotes_paths_containing_spaces(tmp_path):result = server._build_persist_message_with_image_refs("what is this?", [str(img)])- assert result == f"@image:`{img}`\nwhat is this?"+ assert result == f"what is this?\n@image:`{img}`"def test_persist_user_message_mirrors_the_shape_sent_to_the_model(tmp_path):@@ -13272,7 +13284,7 @@ def test_persist_user_message_mirrors_the_shape_sent_to_the_model(tmp_path):override = server._build_persist_user_message("what is this?", [str(img)], native_parts)- assert override == [{"type": "text", "text": f"@image:{img}\nwhat is this?"}, image_part]+ assert override == [{"type": "text", "text": f"what is this?\n@image:{img}"}, image_part]def test_persist_user_message_stays_a_string_for_text_mode(tmp_path):@@ -13283,7 +13295,7 @@ def test_persist_user_message_stays_a_string_for_text_mode(tmp_path):override = server._build_persist_user_message("what is this?", [str(img)], "enriched api-only text")- assert override == f"@image:{img}\nwhat is this?"+ assert override == f"what is this?\n@image:{img}"def test_native_vision_turn_persists_a_renderable_image_ref(tmp_path):diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex 2345eb7a983..5de8d4fc6ab 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -5748,6 +5748,12 @@ def _build_persist_message_with_image_refs(user_text: str, image_paths: list[stran ``image_url:`` hint meant only for the model and must never bepersisted as-is (it silently breaks image rendering after a fullrestart, and reorders image/text on live session-switch reconciliation).++ The caption leads and the directives trail: session previews are the first+ 60 characters of the first user message (``list_sessions_rich``), so a+ leading directive would label the session with a truncated file path in the+ sidebar, switcher, and command palette. Clients lift the refs out of the+ body by line, so their position does not affect how the turn renders."""from agent.context_references import format_reference_value@@ -5755,7 +5761,7 @@ def _build_persist_message_with_image_refs(user_text: str, image_paths: list[strrefs = "\n".join(f"@image:{format_reference_value(p)}" for p in image_paths if Path(p).exists())if not refs:return text- return f"{refs}\n{text}" if text else refs+ return f"{text}\n{refs}" if text else refsdef _build_persist_user_message(user_text: str, image_paths: list[str], run_message: Any) -> Any: