137 lines
4.5 KiB
Python
137 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Hermes Environment Diagnostic for Spark Agent
|
|
Verifies key components of the Hermes runtime environment.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def check_file_exists(path, description):
|
|
"""Check if a file exists and return result."""
|
|
path_str = str(path)
|
|
exists = Path(path).exists()
|
|
status = "PASS" if exists else "FAIL"
|
|
return {"path": path_str, "description": description, "exists": exists, "status": status}
|
|
|
|
def check_directory_exists(path, description):
|
|
"""Check if a directory exists and return result."""
|
|
path_str = str(path)
|
|
exists = Path(path).exists() and Path(path).is_dir()
|
|
status = "PASS" if exists else "FAIL"
|
|
return {"path": path_str, "description": description, "exists": exists, "status": status}
|
|
|
|
def read_yaml_simple(path):
|
|
"""Simple YAML reader for basic key-value files."""
|
|
if not Path(path).exists():
|
|
return None
|
|
result = {}
|
|
with open(path, 'r') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if ':' in line and not line.startswith('#'):
|
|
key, value = line.split(':', 1)
|
|
result[key.strip()] = value.strip()
|
|
return result
|
|
|
|
def main():
|
|
results = {"checks": [], "passed": 0, "failed": 0, "profile_path": None}
|
|
|
|
# Determine profile path
|
|
profile_env = os.environ.get('HERMES_PROFILE', 'spark')
|
|
profile_path = Path(f'/root/.hermes/profiles/{profile_env}')
|
|
results["profile_path"] = str(profile_path)
|
|
|
|
# Check profile directory
|
|
check = check_directory_exists(profile_path, "Hermes profile directory")
|
|
results["checks"].append(check)
|
|
if check["exists"]:
|
|
results["passed"] += 1
|
|
else:
|
|
results["failed"] += 1
|
|
|
|
# Check config.yaml
|
|
config_path = profile_path / 'config.yaml'
|
|
check = check_file_exists(config_path, "Profile config.yaml")
|
|
results["checks"].append(check)
|
|
if check["exists"]:
|
|
results["passed"] += 1
|
|
config = read_yaml_simple(config_path)
|
|
results["config"] = config or {}
|
|
else:
|
|
results["failed"] += 1
|
|
results["config"] = {}
|
|
|
|
# Check skills directory
|
|
skills_path = profile_path / 'skills'
|
|
check = check_directory_exists(skills_path, "Skills directory")
|
|
results["checks"].append(check)
|
|
if check["exists"]:
|
|
results["passed"] += 1
|
|
else:
|
|
results["failed"] += 1
|
|
|
|
# Check caches directory
|
|
cache_path = profile_path / 'cache'
|
|
check = check_directory_exists(cache_path, "Cache directory")
|
|
results["checks"].append(check)
|
|
if check["exists"]:
|
|
results["passed"] += 1
|
|
else:
|
|
results["failed"] += 1
|
|
|
|
# Check memories directory
|
|
memories_path = profile_path / 'memories'
|
|
check = check_directory_exists(memories_path, "Memories directory")
|
|
results["checks"].append(check)
|
|
if check["exists"]:
|
|
results["passed"] += 1
|
|
else:
|
|
results["failed"] += 1
|
|
|
|
# Check Python version
|
|
python_version = sys.version.split()[0]
|
|
results["python_version"] = python_version
|
|
results["passed"] += 1
|
|
|
|
# Check Python is 3.14+
|
|
major, minor = map(int, python_version.split('.')[:2])
|
|
if major >= 3 and minor >= 14:
|
|
results["python_check"] = "PASS"
|
|
else:
|
|
results["python_check"] = f"WARN: Python {python_version}, expected 3.14+"
|
|
|
|
# Check hermes_tools availability
|
|
try:
|
|
from hermes_tools import web_search, web_extract, terminal
|
|
results["hermes_tools"] = {"available": True, "status": "PASS"}
|
|
results["passed"] += 1
|
|
except ImportError as e:
|
|
results["hermes_tools"] = {"available": False, "error": str(e), "status": "FAIL"}
|
|
results["failed"] += 1
|
|
|
|
# Check model configuration
|
|
if results["config"]:
|
|
model_config = results["config"].get('model', {})
|
|
if isinstance(model_config, dict):
|
|
results["model_default"] = model_config.get('default', 'not found')
|
|
results["model_provider"] = model_config.get('provider', 'not found')
|
|
|
|
# Summary
|
|
results["summary"] = {
|
|
"total_checks": len(results["checks"]) + 1 + 1, # +1 for Python, +1 for hermes_tools
|
|
"passed": results["passed"],
|
|
"failed": results["failed"],
|
|
"all_passed": results["failed"] == 0
|
|
}
|
|
|
|
return results
|
|
|
|
if __name__ == "__main__":
|
|
results = main()
|
|
print(json.dumps(results, indent=2))
|
|
|
|
# Exit with error code based on overall status
|
|
sys.exit(0 if results["failed"] == 0 else 1) |