Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(chat): distinguish delivered media from incidental metadata
rubenluetke10-beep397e5b9a03b0
diff --git a/jarvis/agent_chat/media.py b/jarvis/agent_chat/media.pyindex c3c2ae3557..4e74801254 100644--- a/jarvis/agent_chat/media.py+++ b/jarvis/agent_chat/media.py@@ -57,7 +57,7 @@ MAX_REFERENCES = 128_EXT = "|".join(re.escape(ext[1:]) for ext in MEDIA_TYPES)_LINK = re.compile(r"(!?\[[^\]\n]*\]\()(<[^>\n]+>|[^)\n]+)(\))")_RAW = re.compile(- rf"(?<![^\s\"'`(=])(?:https?://|file:///|[A-Za-z]:[/\\]|\./|/)[^\s<>\"'`]+?\.(?:{_EXT})(?:\?[^\s<>\"'`)]+)?(?=$|[\s<>\"'`)])",+ rf"(?<![^\s\"'`(=<])(?:https?://|file:///|[A-Za-z]:[/\\]|\./|/)[^\s<>\"'`]+?\.(?:{_EXT})(?:\?[^\s<>\"'`)]+)?(?=$|[\s<>\"'`)])",re.I,)_BARE = re.compile(rf"(?<![\w:/\\])(?:[\w.-]+[/\\])*[\w.-]+\.(?:{_EXT})(?=$|[\s\"'`),])", re.I)@@ -253,6 +253,9 @@ class MediaNormalizer:return rawdef text(self, text: str) -> str:+ stripped = text.strip()+ if stripped.startswith("<") and stripped.endswith(">") and media_type(stripped[1:-1]):+ return self.reference(stripped[1:-1])if text.strip().startswith("data:") and media_type(text.strip()):return self.reference(text.strip())# Code examples are not output receipts. Do not expose a file merely@@ -285,11 +288,13 @@ class MediaNormalizer:parts[i] = partreturn "".join(parts)- def structured(self, value: Any, depth: int = 0, inherited_hint: str = "") -> Any:+ def structured(+ self, value: Any, depth: int = 0, inherited_hint: str = "", scan_text: bool = False+ ) -> Any:if depth > 12:return valueif isinstance(value, list):- return [self.structured(item, depth + 1, inherited_hint) for item in value]+ return [self.structured(item, depth + 1, inherited_hint, scan_text) for item in value]if isinstance(value, dict):result = dict(value)hint = str(@@ -354,10 +359,28 @@ class MediaNormalizer:"audio": "audio/mpeg",}.get(key, hint if key in {"source", "resource", "result"} else "")if key != "data" or not isinstance(child, str):- result[key] = self.structured(child, depth + 1, child_hint)+ result[key] = self.structured(+ child,+ depth + 1,+ child_hint,+ key+ in {+ "text",+ "output",+ "outputs",+ "content",+ "result",+ "data",+ "artifacts",+ "files",+ "media",+ },+ )return resultif isinstance(value, str):- return self.reference(value, inherited_hint) if inherited_hint else self.text(value)+ if inherited_hint:+ return self.reference(value, inherited_hint)+ return self.text(value) if scan_text else valuereturn value@@ -407,7 +430,7 @@ def normalize_media_event(parsed = json.loads(value) if value.lstrip().startswith(("{", "[")) else Noneexcept ValueError:parsed = None- processed = normalizer.structured(parsed) if parsed is not None else None+ processed = normalizer.structured(parsed, scan_text=True) if parsed is not None else Nonerewritten = (json.dumps(processed, ensure_ascii=False)if parsed is not None@@ -422,7 +445,7 @@ def normalize_media_event():rewritten = content_markdown(content, normalizer.receipts)else:- rewritten = json.dumps(normalizer.structured(value), ensure_ascii=False)+ rewritten = json.dumps(normalizer.structured(value, scan_text=True), ensure_ascii=False)result = [{**event, "payload": {**payload, field: rewritten}}]# Explicit Markdown in assistant prose is already rendered in place.inline = (diff --git a/tests/unit/agent_chat/test_media.py b/tests/unit/agent_chat/test_media.pyindex c81bbb5a18..fef025b9ec 100644--- a/tests/unit/agent_chat/test_media.py+++ b/tests/unit/agent_chat/test_media.py@@ -230,6 +230,25 @@ def test_changing_media_is_not_published_as_a_complete_artifact(tmp_path):assert not list(archive.rglob(".standalone-run.json"))+def test_metadata_filenames_do_not_pick_up_unrelated_workspace_images(tmp_path):+ cwd = tmp_path / "work"+ cwd.mkdir()+ (cwd / "logo.png").write_bytes(PNG)+ result = normalize(+ tmp_path, {"filename": "logo.png", "iconLink": "https://example.test/icon.png"}+ )+ assert len(result) == 1+ assert not (tmp_path / "archive").exists()++[email protected]("key", ["output", "outputs", "artifacts", "files", "media"])+def test_plain_output_lists_still_deliver_each_media_url(tmp_path, key):+ result = normalize(+ tmp_path, {key: ["https://example.test/a.png", "https://example.test/b.mp4"]}+ )+ assert len(result) == 3++def test_media_in_failed_tool_output_is_not_claimed_as_a_result(tmp_path):result = normalize(tmp_path, "https://example.test/photo.png", is_error=True)assert len(result) == 1