mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
refactor: remove remaining redundant local imports (comprehensive sweep)
Full AST-based scan of all .py files to find every case where a module
or name is imported locally inside a function body but is already
available at module level. This is the second pass — the first commit
handled the known cases from the lint report; this one catches
everything else.
Files changed (19):
cli.py — 16 removals: time as _time/_t/_tmod (×10),
re / re as _re (×2), os as _os, sys,
partial os from combo import,
from model_tools import get_tool_definitions
gateway/run.py — 8 removals: MessageEvent as _ME /
MessageType as _MT (×3), os as _os2,
MessageEvent+MessageType (×2), Platform,
BasePlatformAdapter as _BaseAdapter
run_agent.py — 6 removals: get_hermes_home as _ghh,
partial (contextlib, os as _os),
cleanup_vm, cleanup_browser,
set_interrupt as _sif (×2),
partial get_toolset_for_tool
hermes_cli/main.py — 4 removals: get_hermes_home, time as _time,
logging as _log, shutil
hermes_cli/config.py — 1 removal: get_hermes_home as _ghome
hermes_cli/runtime_provider.py
— 1 removal: load_config as _load_bedrock_config
hermes_cli/setup.py — 2 removals: importlib.util (×2)
hermes_cli/nous_subscription.py
— 1 removal: from hermes_cli.config import load_config
hermes_cli/tools_config.py
— 1 removal: from hermes_cli.config import load_config, save_config
cron/scheduler.py — 3 removals: concurrent.futures, json as _json,
from hermes_cli.config import load_config
batch_runner.py — 1 removal: list_distributions as get_all_dists
(kept print_distribution_info, not at top level)
tools/send_message_tool.py
— 2 removals: import os (×2)
tools/skills_tool.py — 1 removal: logging as _logging
tools/browser_camofox.py
— 1 removal: from hermes_cli.config import load_config
tools/image_generation_tool.py
— 1 removal: import fal_client
environments/tool_context.py
— 1 removal: concurrent.futures
gateway/platforms/bluebubbles.py
— 1 removal: httpx as _httpx
gateway/platforms/whatsapp.py
— 1 removal: import asyncio
tui_gateway/server.py — 2 removals: from datetime import datetime,
import time
All alias references (_time, _t, _tmod, _re, _os, _os2, _json, _ghh,
_ghome, _sif, _ME, _MT, _BaseAdapter, _load_bedrock_config, _httpx,
_logging, _log, get_all_dists) updated to use the top-level names.
This commit is contained in:
@@ -543,7 +543,6 @@ def camofox_vision(question: str, annotate: bool = False,
|
||||
)
|
||||
|
||||
try:
|
||||
from hermes_cli.config import load_config
|
||||
_cfg = load_config()
|
||||
_vision_cfg = _cfg.get("auxiliary", {}).get("vision", {})
|
||||
_vision_timeout = float(_vision_cfg.get("timeout", 120))
|
||||
|
||||
@@ -742,7 +742,7 @@ def check_image_generation_requirements() -> bool:
|
||||
try:
|
||||
if not check_fal_api_key():
|
||||
return False
|
||||
import fal_client # noqa: F401 — SDK presence check
|
||||
fal_client # noqa: F401 — SDK presence check
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
@@ -226,7 +226,6 @@ def _handle_send(args):
|
||||
# Weixin can be configured purely via .env; synthesize a pconfig so
|
||||
# send_message and cron delivery work without a gateway.yaml entry.
|
||||
if platform_name == "weixin":
|
||||
import os
|
||||
wx_token = os.getenv("WEIXIN_TOKEN", "").strip()
|
||||
wx_account = os.getenv("WEIXIN_ACCOUNT_ID", "").strip()
|
||||
if wx_token and wx_account:
|
||||
@@ -254,7 +253,6 @@ def _handle_send(args):
|
||||
if not chat_id:
|
||||
home = config.get_home_channel(platform)
|
||||
if not home and platform_name == "weixin":
|
||||
import os
|
||||
wx_home = os.getenv("WEIXIN_HOME_CHANNEL", "").strip()
|
||||
if wx_home:
|
||||
from gateway.config import HomeChannel
|
||||
|
||||
@@ -975,8 +975,7 @@ def skill_view(name: str, file_path: str = None, task_id: str = None) -> str:
|
||||
_warnings.append(f"skill file is outside the trusted skills directory (~/.hermes/skills/): {skill_md}")
|
||||
if _injection_detected:
|
||||
_warnings.append("skill content contains patterns that may indicate prompt injection")
|
||||
import logging as _logging
|
||||
_logging.getLogger(__name__).warning("Skill security warning for '%s': %s", name, "; ".join(_warnings))
|
||||
logging.getLogger(__name__).warning("Skill security warning for '%s': %s", name, "; ".join(_warnings))
|
||||
|
||||
parsed_frontmatter: Dict[str, Any] = {}
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user