From a641644f12a90496faaeaacf57214690b8cd5809 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Fri, 28 Aug 2026 05:45:00 -0700 Subject: [PATCH] =?UTF-8?q?fix(paths):=20display=5Fhermes=5Fhome=20renders?= =?UTF-8?q?=20POSIX=20separators=20on=20Windows=20=E2=80=94=20kills=20~/Ap?= =?UTF-8?q?pData\Local\hermes=20chimeras=20in=20tool=20schemas=20and=20use?= =?UTF-8?q?r-facing=20messages=20(#97137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/subdirectory_hints.py | 5 +- hermes_cli/main.py | 2 +- hermes_constants.py | 8 +- plugins/platforms/google_chat/oauth.py | 2 +- .../google-workspace/scripts/_hermes_home.py | 2 +- tests/test_display_hermes_home.py | 73 +++++++++++++++++++ 6 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 tests/test_display_hermes_home.py diff --git a/agent/subdirectory_hints.py b/agent/subdirectory_hints.py index 4fb268bd4e..11e4a7d4f9 100644 --- a/agent/subdirectory_hints.py +++ b/agent/subdirectory_hints.py @@ -314,8 +314,9 @@ class SubdirectoryHintTracker: rel_path = str(hint_path.relative_to(self.working_dir)) except (ValueError, RuntimeError): try: - rel_path = str(hint_path.relative_to(Path.home())) - rel_path = "~/" + rel_path + # as_posix: "~/" shorthand implies POSIX rendering + # (avoids ~/AppData\Local\... chimeras on Windows). + rel_path = "~/" + hint_path.relative_to(Path.home()).as_posix() except (ValueError, RuntimeError): pass # keep absolute found_hints.append((rel_path, content)) diff --git a/hermes_cli/main.py b/hermes_cli/main.py index a45a493657..b25738679d 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -11166,7 +11166,7 @@ def cmd_profile(args): # Profile dir for display try: - profile_dir_display = "~/" + str(profile_dir.relative_to(Path.home())) + profile_dir_display = "~/" + profile_dir.relative_to(Path.home()).as_posix() except ValueError: profile_dir_display = str(profile_dir) diff --git a/hermes_constants.py b/hermes_constants.py index 9c549a82d3..3f28cd8d1a 100644 --- a/hermes_constants.py +++ b/hermes_constants.py @@ -1117,7 +1117,13 @@ def display_hermes_home() -> str: """ home = get_hermes_home() try: - return "~/" + str(home.relative_to(Path.home())) + # as_posix(): on Windows, str() of a relative Path renders + # backslashes, producing mixed-separator chimeras like + # ``~/AppData\Local\hermes/skills/`` once callers append + # sub-paths. ``~/`` shorthand implies POSIX rendering; keep the + # whole string consistent (forward slashes work everywhere, + # including Windows shells and Python APIs). + return "~/" + home.relative_to(Path.home()).as_posix() except ValueError: return str(home) diff --git a/plugins/platforms/google_chat/oauth.py b/plugins/platforms/google_chat/oauth.py index 65744d2570..22bc62113d 100644 --- a/plugins/platforms/google_chat/oauth.py +++ b/plugins/platforms/google_chat/oauth.py @@ -90,7 +90,7 @@ except (ModuleNotFoundError, ImportError): def display_hermes_home() -> str: home = get_hermes_home() try: - return "~/" + str(home.relative_to(Path.home())) + return "~/" + home.relative_to(Path.home()).as_posix() except ValueError: return str(home) diff --git a/skills/productivity/google-workspace/scripts/_hermes_home.py b/skills/productivity/google-workspace/scripts/_hermes_home.py index 456eaa9304..e50741fa6c 100644 --- a/skills/productivity/google-workspace/scripts/_hermes_home.py +++ b/skills/productivity/google-workspace/scripts/_hermes_home.py @@ -37,6 +37,6 @@ except (ModuleNotFoundError, ImportError): Mirrors ``hermes_constants.display_hermes_home()``.""" home = get_hermes_home() try: - return "~/" + str(home.relative_to(Path.home())) + return "~/" + home.relative_to(Path.home()).as_posix() except ValueError: return str(home) diff --git a/tests/test_display_hermes_home.py b/tests/test_display_hermes_home.py new file mode 100644 index 0000000000..9ad3681fba --- /dev/null +++ b/tests/test_display_hermes_home.py @@ -0,0 +1,73 @@ +"""display_hermes_home() renders POSIX separators on every platform. + +Maintainer catch (#95681 arc): on Windows with a custom HERMES_HOME under +the user profile (e.g. AppData/Local/hermes), ``"~/" + +str(home.relative_to(Path.home()))`` produced the mixed-separator chimera +``~/AppData\\Local\\hermes`` — which then leaked into every consumer that +appends sub-paths (the skill_manage schema showed the agent +``~/AppData\\Local\\hermes/skills/``). The ``~/`` shorthand implies POSIX +rendering; the whole string must be consistent. +""" +import os +import sys +import unittest +from pathlib import Path, PureWindowsPath +from unittest.mock import patch + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) + + +class TestDisplayHermesHomePosix(unittest.TestCase): + def test_nested_home_renders_forward_slashes(self): + """Simulate the Windows shape portably: home nested several levels + under the user profile must render with forward slashes only.""" + import hermes_constants as hc + + fake_userhome = Path.home() + nested = fake_userhome / "AppData" / "Local" / "hermes" + with patch.object(hc, "get_hermes_home", return_value=nested): + out = hc.display_hermes_home() + self.assertEqual(out, "~/AppData/Local/hermes") + self.assertNotIn("\\", out) + + def test_default_home_unchanged(self): + import hermes_constants as hc + + with patch.object(hc, "get_hermes_home", + return_value=Path.home() / ".hermes"): + out = hc.display_hermes_home() + self.assertEqual(out, "~/.hermes") + + def test_outside_home_falls_back_to_absolute(self): + import hermes_constants as hc + + outside = Path("/opt/hermes-custom") if os.name != "nt" else Path("C:/opt/hermes-custom") + with patch.object(hc, "get_hermes_home", return_value=outside): + out = hc.display_hermes_home() + self.assertEqual(out, str(outside)) + + def test_no_serving_schema_carries_tilde_backslash_chimera(self): + """Fleet guard: no served tool schema string may combine '~/' with + a backslash — the class of bug, not the one site.""" + from model_tools import get_tool_definitions + + offenders = [] + + def walk(o, tool): + if isinstance(o, str): + if "~/" in o and "\\" in o: + offenders.append((tool, o[:80])) + elif isinstance(o, dict): + for v in o.values(): + walk(v, tool) + elif isinstance(o, list): + for v in o: + walk(v, tool) + + for t in get_tool_definitions(quiet_mode=True): + walk(t, t["function"]["name"]) + self.assertEqual(offenders, []) + + +if __name__ == "__main__": + unittest.main()