refactor(restructure): rewrite all imports for hermes_agent package

Rewrite all import statements, patch() targets, sys.modules keys,
importlib.import_module() strings, and subprocess -m references to use
hermes_agent.* paths.

Strip sys.path.insert hacks from production code (rely on editable install).
Update COMPONENT_PREFIXES for logger filtering.
Fix 3 hardcoded getLogger() calls to use __name__.
Update transport and tool registry discovery paths.
Update plugin module path strings.
Add legacy process-name patterns for gateway PID detection.
Add main() to skills_sync for console_script entry point.
Fix _get_bundled_dir() path traversal after move.

Part of #14182, #14183
This commit is contained in:
alt-glitch 2026-04-23 08:35:34 +05:30
parent 65ca3ba93b
commit 4b16341975
898 changed files with 12494 additions and 12019 deletions

View file

@ -17,7 +17,7 @@ import sys
from pathlib import Path
from typing import Optional
from hermes_constants import get_hermes_home
from hermes_agent.constants import get_hermes_home
logger = logging.getLogger(__name__)
@ -173,8 +173,8 @@ def _prompt_plugin_env_vars(manifest: dict, console) -> None:
if not requires_env:
return
from hermes_cli.config import get_env_value, save_env_value # noqa: F811
from hermes_constants import display_hermes_home
from hermes_agent.cli.config import get_env_value, save_env_value # noqa: F811
from hermes_agent.constants import display_hermes_home
# Normalise to list-of-dicts
env_specs: list[dict] = []
@ -360,7 +360,7 @@ def cmd_install(
)
sys.exit(1)
if mv_int > _SUPPORTED_MANIFEST_VERSION:
from hermes_cli.config import recommended_update_command
from hermes_agent.cli.config import recommended_update_command
console.print(
f"[red]Error:[/red] Plugin '{plugin_name}' requires manifest_version "
f"{mv}, but this installer only supports up to {_SUPPORTED_MANIFEST_VERSION}.\n"
@ -517,7 +517,7 @@ def _get_disabled_set() -> set:
listed in ``plugins.enabled``.
"""
try:
from hermes_cli.config import load_config
from hermes_agent.cli.config import load_config
config = load_config()
disabled = config.get("plugins", {}).get("disabled", [])
return set(disabled) if isinstance(disabled, list) else set()
@ -527,7 +527,7 @@ def _get_disabled_set() -> set:
def _save_disabled_set(disabled: set) -> None:
"""Write the disabled plugins list to config.yaml."""
from hermes_cli.config import load_config, save_config
from hermes_agent.cli.config import load_config, save_config
config = load_config()
if "plugins" not in config:
config["plugins"] = {}
@ -542,7 +542,7 @@ def _get_enabled_set() -> set:
the key is missing (same behaviour as "nothing enabled yet").
"""
try:
from hermes_cli.config import load_config
from hermes_agent.cli.config import load_config
config = load_config()
plugins_cfg = config.get("plugins", {})
if not isinstance(plugins_cfg, dict):
@ -555,7 +555,7 @@ def _get_enabled_set() -> set:
def _save_enabled_set(enabled: set) -> None:
"""Write the enabled plugins list to config.yaml."""
from hermes_cli.config import load_config, save_config
from hermes_agent.cli.config import load_config, save_config
config = load_config()
if "plugins" not in config:
config["plugins"] = {}
@ -631,7 +631,7 @@ def _plugin_exists(name: str) -> bool:
return True
# Bundled: <repo>/plugins/<name>/
from pathlib import Path as _P
import hermes_cli
import hermes_agent.cli
repo_plugins = _P(hermes_cli.__file__).resolve().parent.parent / "plugins"
if repo_plugins.is_dir():
candidate = repo_plugins / name
@ -659,7 +659,7 @@ def _discover_all_plugins() -> list:
seen: dict = {} # name -> (name, version, description, source, path)
# Bundled (<repo>/plugins/<name>/), excluding memory/ and context_engine/
import hermes_cli
import hermes_agent.cli
repo_plugins = Path(hermes_cli.__file__).resolve().parent.parent / "plugins"
for base, source in ((repo_plugins, "bundled"), (_plugins_dir(), "user")):
if not base.is_dir():
@ -743,7 +743,7 @@ def cmd_list() -> None:
def _discover_memory_providers() -> list[tuple[str, str]]:
"""Return [(name, description), ...] for available memory providers."""
try:
from plugins.memory import discover_memory_providers
from hermes_agent.plugins.memory import discover_memory_providers
return [(name, desc) for name, desc, _avail in discover_memory_providers()]
except Exception:
return []
@ -752,7 +752,7 @@ def _discover_memory_providers() -> list[tuple[str, str]]:
def _discover_context_engines() -> list[tuple[str, str]]:
"""Return [(name, description), ...] for available context engines."""
try:
from plugins.context_engine import discover_context_engines
from hermes_agent.plugins.context_engine import discover_context_engines
return [(name, desc) for name, desc, _avail in discover_context_engines()]
except Exception:
return []
@ -761,7 +761,7 @@ def _discover_context_engines() -> list[tuple[str, str]]:
def _get_current_memory_provider() -> str:
"""Return the current memory.provider from config (empty = built-in)."""
try:
from hermes_cli.config import load_config
from hermes_agent.cli.config import load_config
config = load_config()
return config.get("memory", {}).get("provider", "") or ""
except Exception:
@ -771,7 +771,7 @@ def _get_current_memory_provider() -> str:
def _get_current_context_engine() -> str:
"""Return the current context.engine from config."""
try:
from hermes_cli.config import load_config
from hermes_agent.cli.config import load_config
config = load_config()
return config.get("context", {}).get("engine", "compressor") or "compressor"
except Exception:
@ -780,7 +780,7 @@ def _get_current_context_engine() -> str:
def _save_memory_provider(name: str) -> None:
"""Persist memory.provider to config.yaml."""
from hermes_cli.config import load_config, save_config
from hermes_agent.cli.config import load_config, save_config
config = load_config()
if "memory" not in config:
config["memory"] = {}
@ -790,7 +790,7 @@ def _save_memory_provider(name: str) -> None:
def _save_context_engine(name: str) -> None:
"""Persist context.engine to config.yaml."""
from hermes_cli.config import load_config, save_config
from hermes_agent.cli.config import load_config, save_config
config = load_config()
if "context" not in config:
config["context"] = {}
@ -800,7 +800,7 @@ def _save_context_engine(name: str) -> None:
def _configure_memory_provider() -> bool:
"""Launch a radio picker for memory providers. Returns True if changed."""
from hermes_cli.curses_ui import curses_radiolist
from hermes_agent.cli.ui.curses import curses_radiolist
current = _get_current_memory_provider()
providers = _discover_memory_providers()
@ -838,7 +838,7 @@ def _configure_memory_provider() -> bool:
def _configure_context_engine() -> bool:
"""Launch a radio picker for context engines. Returns True if changed."""
from hermes_cli.curses_ui import curses_radiolist
from hermes_agent.cli.ui.curses import curses_radiolist
current = _get_current_context_engine()
engines = _discover_context_engines()
@ -938,7 +938,7 @@ def cmd_toggle() -> None:
def _run_composite_ui(curses, plugin_names, plugin_labels, plugin_selected,
disabled, categories, console):
"""Custom curses screen with checkboxes + category action rows."""
from hermes_cli.curses_ui import flush_stdin
from hermes_agent.cli.ui.curses import flush_stdin
chosen = set(plugin_selected)
n_plugins = len(plugin_names)
@ -1188,7 +1188,7 @@ def _run_composite_ui(curses, plugin_names, plugin_labels, plugin_selected,
def _run_composite_fallback(plugin_names, plugin_labels, plugin_selected,
disabled, categories, console):
"""Text-based fallback for the composite plugins UI."""
from hermes_cli.colors import Colors, color
from hermes_agent.cli.ui.colors import Colors, color
print(color("\n Plugins", Colors.YELLOW))