known_dirs.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. """Directories where tools install outside PATH, grouped by the ecosystem that owns them.
  2. Every table in Hermes lives here. A directory literal outside this module fails the ratchet in
  3. `tests/test_managed_runtime_resolution.py`. Each table is empty on an OS where the ecosystem
  4. does not install there, so callers compose tables without OS branches.
  5. """
  6. from __future__ import annotations
  7. import sys
  8. _POSIX = sys.platform != "win32"
  9. _WIN = sys.platform == "win32"
  10. def homebrew_dirs() -> tuple[str, ...]:
  11. return ("/opt/homebrew/bin", "/usr/local/bin") if sys.platform == "darwin" else ()
  12. def user_local_bin() -> tuple[str, ...]:
  13. return ("~/.local/bin",) if _POSIX else ("%USERPROFILE%/.local/bin",)
  14. def rust_tool_dirs() -> tuple[str, ...]:
  15. return ("~/.cargo/bin",) if _POSIX else ("%USERPROFILE%/.cargo/bin",)
  16. def node_tool_dirs() -> tuple[str, ...]:
  17. return ("~/.npm-global/bin", "~/.bun/bin", "~/.volta/bin") if _POSIX else ("%APPDATA%/npm", "%USERPROFILE%/.bun/bin", "%LOCALAPPDATA%/Volta/bin")
  18. def hermes_vendored_dirs() -> tuple[str, ...]:
  19. return ("~/.hermes/bin",) if _POSIX else ("%USERPROFILE%/.hermes/bin",)
  20. def machine_marker_files() -> tuple[str, ...]:
  21. """Where Hermes records that this OS user has used it. No Hermes data-dir setting moves these.
  22. The first entry is the one written; the rest are read too (Windows: MSIX builds that ran with
  23. filesystem virtualisation wrote under the package's LocalCache)."""
  24. if _WIN:
  25. return ("%LOCALAPPDATA%/Nous Research/.machine",
  26. "%LOCALAPPDATA%/Packages/NousResearch*_*/LocalCache/Local/Nous Research/.machine")
  27. if sys.platform == "darwin":
  28. return ("~/Library/Application Support/Nous Research/.machine",)
  29. return ("$XDG_STATE_HOME/nous-research/.machine", "~/.local/state/nous-research/.machine")
  30. def hermes_home_globs() -> tuple[str, ...]:
  31. """Every place a Hermes data root can sit by default: suffixed channel roots, the legacy Windows
  32. root, and the per-package roots of MSIX builds that ran with filesystem virtualisation."""
  33. if _WIN:
  34. return ("%LOCALAPPDATA%/hermes*", "%USERPROFILE%/.hermes",
  35. "%LOCALAPPDATA%/Packages/NousResearch*_*/LocalCache/Local/hermes*")
  36. return ("~/.hermes*",)
  37. def gateway_service_definition_globs() -> tuple[str, ...]:
  38. """This OS user's gateway service definitions, each naming the HERMES_HOME it serves."""
  39. if _WIN:
  40. return ("%APPDATA%/Microsoft/Windows/Start Menu/Programs/Startup/Hermes_Gateway*",)
  41. if sys.platform == "darwin":
  42. return ("~/Library/LaunchAgents/ai.hermes.gateway*.plist",)
  43. return ("$XDG_CONFIG_HOME/systemd/user/hermes-gateway*.service", "~/.config/systemd/user/hermes-gateway*.service")
  44. def system_gateway_service_definition_globs() -> tuple[str, ...]:
  45. """Machine-wide gateway services. Each runs as the account its ``User=`` names (root when none)."""
  46. return ("/etc/systemd/system/hermes-gateway*.service",) if _POSIX and sys.platform != "darwin" else ()
  47. def mac_privacy_protected_dirs() -> tuple[str, ...]:
  48. """Folders macOS guards with a permission prompt (TCC); opening anything inside raises it."""
  49. if sys.platform != "darwin":
  50. return ()
  51. return ("~/Documents", "~/Desktop", "~/Downloads", "~/Library/Mobile Documents") # windows-footgun: ok — macOS only
  52. def windows_user_program_dirs() -> tuple[str, ...]:
  53. if not _WIN:
  54. return ()
  55. return (
  56. "%LOCALAPPDATA%/Programs",
  57. "%USERPROFILE%/scoop/shims",
  58. "%LOCALAPPDATA%/Microsoft/WinGet/Links",
  59. )
  60. def visual_studio_installer_dirs() -> tuple[str, ...]:
  61. """Where the Visual Studio installer puts vswhere.exe; it is never on PATH."""
  62. return ("%ProgramFiles(x86)%/Microsoft Visual Studio/Installer",) if _WIN else ()
  63. def mac_application_dirs() -> tuple[str, ...]:
  64. return ("/Applications", "~/Applications") if sys.platform == "darwin" else ()
  65. def flatpak_export_dirs() -> tuple[str, ...]:
  66. """Where flatpak links each installed app's launcher, named by its app id (system, then per-user)."""
  67. return ("/var/lib/flatpak/exports/bin", "~/.local/share/flatpak/exports/bin") if sys.platform.startswith("linux") else ()
  68. def snap_bin_dirs() -> tuple[str, ...]:
  69. return ("/snap/bin",) if sys.platform.startswith("linux") else ()