mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix: worktree-aware minisweagent path discovery + clean up requirements check (#1248)
Salvage of PR #1246 by ChatGPT (teknium1 session), resolved against current main which already includes #1239. Changes: - Add minisweagent_path.py: worktree-aware helper that finds mini-swe-agent/src from either the current checkout or the main checkout behind a git worktree - Use the helper in tools/terminal_tool.py and mini_swe_runner.py instead of naive path-relative lookup that fails in worktrees - Clean up check_terminal_requirements(): - local: return True (no minisweagent dep, per #1239) - singularity/ssh: remove unnecessary minisweagent imports - docker/modal: use importlib.util.find_spec with clear error - Add regression tests for worktree path discovery and tool resolution
This commit is contained in:
@@ -26,6 +26,7 @@ Usage:
|
||||
result = terminal_tool("python server.py", background=True)
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@@ -53,10 +54,11 @@ logger = logging.getLogger(__name__)
|
||||
from tools.interrupt import set_interrupt as set_interrupt_event, is_interrupted, _interrupt_event
|
||||
|
||||
|
||||
# Add mini-swe-agent to path if not installed
|
||||
mini_swe_path = Path(__file__).parent.parent / "mini-swe-agent" / "src"
|
||||
if mini_swe_path.exists():
|
||||
sys.path.insert(0, str(mini_swe_path))
|
||||
# Add mini-swe-agent to path if not installed. In git worktrees the populated
|
||||
# submodule may live in the main checkout rather than the worktree itself.
|
||||
from minisweagent_path import ensure_minisweagent_on_path
|
||||
|
||||
ensure_minisweagent_on_path(Path(__file__).resolve().parent.parent)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
@@ -1124,47 +1126,58 @@ def terminal_tool(
|
||||
|
||||
|
||||
def check_terminal_requirements() -> bool:
|
||||
"""Check if all requirements for the terminal tool are met."""
|
||||
"""Check if all requirements for the terminal tool are met.
|
||||
|
||||
Important: local and singularity backends now use Hermes' own environment
|
||||
wrappers directly and do not require the ``minisweagent`` Python package to
|
||||
be installed. Docker and Modal still rely on mini-swe-agent internals.
|
||||
"""
|
||||
config = _get_env_config()
|
||||
env_type = config["env_type"]
|
||||
|
||||
|
||||
try:
|
||||
if env_type == "local":
|
||||
# Local execution uses Hermes' own LocalEnvironment wrapper and does
|
||||
# not depend on minisweagent being importable.
|
||||
return True
|
||||
|
||||
elif env_type == "docker":
|
||||
from minisweagent.environments.docker import DockerEnvironment
|
||||
ensure_minisweagent_on_path(Path(__file__).resolve().parent.parent)
|
||||
if importlib.util.find_spec("minisweagent") is None:
|
||||
logger.error("mini-swe-agent is required for docker terminal backend but is not importable")
|
||||
return False
|
||||
# Check if docker is available (use find_docker for macOS PATH issues)
|
||||
from tools.environments.docker import find_docker
|
||||
import subprocess
|
||||
docker = find_docker()
|
||||
if not docker:
|
||||
logger.error("Docker executable not found in PATH or common install locations")
|
||||
return False
|
||||
result = subprocess.run([docker, "version"], capture_output=True, timeout=5)
|
||||
return result.returncode == 0
|
||||
|
||||
elif env_type == "singularity":
|
||||
from minisweagent.environments.singularity import SingularityEnvironment
|
||||
# Check if singularity/apptainer is available
|
||||
import subprocess
|
||||
import shutil
|
||||
executable = shutil.which("apptainer") or shutil.which("singularity")
|
||||
if executable:
|
||||
result = subprocess.run([executable, "--version"], capture_output=True, timeout=5)
|
||||
return result.returncode == 0
|
||||
return False
|
||||
|
||||
elif env_type == "ssh":
|
||||
from tools.environments.ssh import SSHEnvironment
|
||||
# Check that host and user are configured
|
||||
return bool(config.get("ssh_host")) and bool(config.get("ssh_user"))
|
||||
|
||||
elif env_type == "modal":
|
||||
from minisweagent.environments.extra.swerex_modal import SwerexModalEnvironment
|
||||
ensure_minisweagent_on_path(Path(__file__).resolve().parent.parent)
|
||||
if importlib.util.find_spec("minisweagent") is None:
|
||||
logger.error("mini-swe-agent is required for modal terminal backend but is not importable")
|
||||
return False
|
||||
# Check for modal token
|
||||
return os.getenv("MODAL_TOKEN_ID") is not None or Path.home().joinpath(".modal.toml").exists()
|
||||
|
||||
elif env_type == "daytona":
|
||||
from daytona import Daytona
|
||||
return os.getenv("DAYTONA_API_KEY") is not None
|
||||
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user