Skip to content

The agent that grows with you

fix(paths): display_hermes_home renders POSIX separators on Windows — kills ~/AppData\Local\hermes chimeras in tool schemas and user-facing messages (#97137)

Tekniuma641644f12a9
diff --git a/agent/subdirectory_hints.py b/agent/subdirectory_hints.py
index 4fb268bd4ec..11e4a7d4f9f 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 a45a4936578..b25738679d0 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 9c549a82d33..3f28cd8d1a3 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 65744d2570d..22bc62113d4 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 456eaa93044..e50741fa6c7 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 00000000000..9ad3681fbad
--- /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()