Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(reply): normalize Windows file URIs

cyh7979d094eadf
diff --git a/core/reply_enhancer.py b/core/reply_enhancer.py
index a690f7728..00463c0bd 100644
--- a/core/reply_enhancer.py
+++ b/core/reply_enhancer.py
@@ -16,6 +16,7 @@ Extracts special syntaxes from agent reply text:
from __future__ import annotations
import logging
+import ntpath
import os
import re
from dataclasses import dataclass, field
@@ -133,7 +134,7 @@ def _extract_file_links(text: str) -> List[FileLink]:
parsed = urlparse(url)
if parsed.scheme != "file":
continue
- path = unquote(parsed.path)
+ path = _file_uri_to_local_path(parsed)
if not os.path.isabs(path):
logger.warning("Skipping non-absolute file link: %s", url)
continue
@@ -141,6 +142,19 @@ def _extract_file_links(text: str) -> List[FileLink]:
return results
+def _file_uri_to_local_path(parsed) -> str:
+ """Convert a parsed file URI into a local path for the current OS."""
+ path = unquote(parsed.path)
+ if os.name != "nt":
+ return path
+
+ if parsed.netloc:
+ return ntpath.normpath(f"//{parsed.netloc}{path}")
+ if re.match(r"^/[A-Za-z]:/", path):
+ path = path[1:]
+ return ntpath.normpath(path)
+
+
def _strip_file_links(text: str) -> str:
"""Replace ``[label](file://…)`` with just the label."""
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index 4dc38dea8..7b111083f 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -201,6 +201,14 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
"/Users/test/SaveTwitter.Net_GABV3XNWYAARAZz(gif).mp4",
)
+ def test_windows_file_uri_is_normalized_before_absolute_check(self):
+ with patch("core.reply_enhancer.os.name", "nt"), patch("core.reply_enhancer.os.path.isabs") as isabs:
+ isabs.side_effect = lambda value: value == r"C:\Users\test\generated image.png"
+ enhanced = process_reply("![generated image](file:///C:/Users/test/generated%20image.png)")
+
+ self.assertEqual(len(enhanced.files), 1)
+ self.assertEqual(enhanced.files[0].path, r"C:\Users\test\generated image.png")
+
async def test_wechat_result_ignores_quick_reply_buttons(self):
controller = _StubController("wechat")
dispatcher = ConsolidatedMessageDispatcher(controller)