refactor: 移除硬编码路径,改用 $HOME 动态构建
- USERS_BASE: 从 /d/hermesai/users 改为 $HOME/users
- HERMES_HOME fallback: 从 /d/hermesai/.hermes 改为 $HOME/.hermes
- sys.path default_path: 从硬编码绝对路径改为动态构建
- 所有回退路径统一使用 os.environ.get('HOME', '/root')
This commit is contained in:
parent
5f962dcc90
commit
32cf7e5d5a
15
main.py
15
main.py
@ -24,7 +24,7 @@ from functools import wraps
|
|||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Resolve Hermes base path dynamically via get_hermes_home() when available,
|
# Resolve Hermes base path dynamically via get_hermes_home() when available,
|
||||||
# with fallback to the hardcoded default for backward compatibility.
|
# with fallback to the user's home directory for portability.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
def _resolve_hermes_home() -> str:
|
def _resolve_hermes_home() -> str:
|
||||||
"""Resolve the Hermes home directory.
|
"""Resolve the Hermes home directory.
|
||||||
@ -32,7 +32,7 @@ def _resolve_hermes_home() -> str:
|
|||||||
Tries:
|
Tries:
|
||||||
1. HERMES_HOME env var (explicit override)
|
1. HERMES_HOME env var (explicit override)
|
||||||
2. get_hermes_home() from hermes_constants module
|
2. get_hermes_home() from hermes_constants module
|
||||||
3. Fallback to the default path
|
3. Fallback to $HOME/.hermes
|
||||||
"""
|
"""
|
||||||
env_override = os.environ.get("HERMES_HOME")
|
env_override = os.environ.get("HERMES_HOME")
|
||||||
if env_override:
|
if env_override:
|
||||||
@ -40,19 +40,22 @@ def _resolve_hermes_home() -> str:
|
|||||||
try:
|
try:
|
||||||
# Add the hermes-agent directory to the Python path so we can import
|
# Add the hermes-agent directory to the Python path so we can import
|
||||||
# from the bundled agent without installing it.
|
# from the bundled agent without installing it.
|
||||||
default_path = "/d/hermesai/.hermes/hermes-agent"
|
home = os.environ.get('HOME', '/root')
|
||||||
|
default_path = os.path.join(home, '.hermes', 'hermes-agent')
|
||||||
if default_path not in sys.path:
|
if default_path not in sys.path:
|
||||||
sys.path.insert(0, default_path)
|
sys.path.insert(0, default_path)
|
||||||
from hermes_constants import get_hermes_home
|
from hermes_constants import get_hermes_home
|
||||||
return get_hermes_home()
|
return get_hermes_home()
|
||||||
except Exception:
|
except Exception:
|
||||||
return "/d/hermesai/.hermes"
|
home = os.environ.get('HOME', '/root')
|
||||||
|
return os.path.join(home, '.hermes')
|
||||||
|
|
||||||
HERMES_HOME = _resolve_hermes_home()
|
HERMES_HOME = _resolve_hermes_home()
|
||||||
BASE_HERMES_PATH = os.path.join(HERMES_HOME, "hermes-agent")
|
BASE_HERMES_PATH = os.path.join(HERMES_HOME, "hermes-agent")
|
||||||
|
|
||||||
# Clean user data directory structure: /d/hermesai/users/{user_id}/.hermes
|
# User data directory structure: $HOME/users/{user_id}/.hermes
|
||||||
USERS_BASE = "/d/hermesai/users"
|
home = os.environ.get('HOME', '/root')
|
||||||
|
USERS_BASE = os.path.join(home, "users")
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
CONFIG_FILE = os.path.join(os.path.dirname(__file__), "config.yaml")
|
CONFIG_FILE = os.path.join(os.path.dirname(__file__), "config.yaml")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user