Files

96 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Hermes Environment Validator - validates key paths and directory structure."""
import os
import json
from pathlib import Path
def validate_hermes_environment():
"""Validate Hermes Agent environment structure."""
hermes_root = Path("/root/.hermes")
results = {
"hermes_root": {
"path": str(hermes_root),
"exists": hermes_root.exists(),
"is_dir": hermes_root.is_dir() if hermes_root.exists() else False
},
"required_paths": [],
"scratch_dir": None,
"profile_paths": {}
}
# Define required paths
required_paths = [
"profiles/spark", # spark profile
"skills", # skills directory
"plugins", # plugins directory
"cron", # cron directory
"memories", # memories directory
"cache/scratch" # scratch (TMPDIR)
]
for rel_path in required_paths:
full_path = hermes_root / rel_path
results["required_paths"].append({
"path": rel_path,
"full_path": str(full_path),
"exists": full_path.exists(),
"is_dir": full_path.is_dir() if full_path.exists() else False,
"item_count": len(list(full_path.iterdir())) if full_path.exists() and full_path.is_dir() else 0
})
# Check scratch directory
scratch = hermes_root / "profiles/spark/cache/scratch"
results["scratch_dir"] = {
"path": str(scratch),
"exists": scratch.exists(),
"is_dir": scratch.is_dir() if scratch.exists() else False
}
# Check TMPDIR
tmpdir = Path(os.environ.get("TMPDIR", "/tmp"))
results["tmpdir"] = {
"path": str(tmpdir),
"exists": tmpdir.exists(),
"is_dir": tmpdir.is_dir() if tmpdir.exists() else False
}
# Profile paths
profile_root = hermes_root / "profiles"
if profile_root.exists():
for profile in profile_root.iterdir():
if profile.is_dir():
results["profile_paths"][profile.name] = {
"exists": True,
"is_dir": True,
"item_count": len(list(profile.iterdir()))
}
# Overall status
all_required_exist = all(p["exists"] and p["is_dir"] for p in results["required_paths"])
results["valid"] = results["hermes_root"]["is_dir"] and all_required_exist
return results
def main():
results = validate_hermes_environment()
# Print JSON output
print(json.dumps(results, indent=2))
# Print summary
print("\n--- SUMMARY ---")
print(f"Hermes root valid: {results['hermes_root']['is_dir']}")
print(f"All required paths exist: {results['valid']}")
missing = [p for p in results["required_paths"] if not p["exists"]]
if missing:
print(f"Missing paths: {[p['path'] for p in missing]}")
else:
print("All required paths present")
return 0 if results["valid"] else 1
if __name__ == "__main__":
exit(main())