63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Hermes Path Resolver - resolves paths relative to various Hermes contexts.
|
|
Produces a traceable log of all resolved paths.
|
|
"""
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def resolve_hermes_path(path_str: str, base: str = "cwd") -> dict:
|
|
"""Resolve a path given a Hermes context base."""
|
|
bases = {
|
|
"cwd": Path.cwd(),
|
|
"home": Path.home(),
|
|
"hermes": Path("/root/.hermes"),
|
|
"outputs": Path("/root/.hermes/wizard-outputs"),
|
|
"spark": Path("/root/.hermes/wizard-outputs/spark"),
|
|
}
|
|
|
|
if base not in bases:
|
|
return {"error": f"Unknown base: {base}"}
|
|
|
|
base_path = bases[base]
|
|
resolved = (base_path / path_str).resolve()
|
|
|
|
return {
|
|
"input": path_str,
|
|
"base_context": base,
|
|
"base_path": str(base_path),
|
|
"resolved": str(resolved),
|
|
"exists": resolved.exists(),
|
|
"is_abs": path_str.startswith("/"),
|
|
"relative_to_base": str(resolved.relative_to(base_path)) if resolved.is_relative_to(base_path) else "N/A"
|
|
}
|
|
|
|
def main():
|
|
paths_to_resolve = [
|
|
("ledger-2026-10-12-0013.txt", "outputs"),
|
|
(".", "hermes"),
|
|
("../spark", "outputs"),
|
|
("hermit-shell", "hermes"), # Does not exist - test case
|
|
]
|
|
|
|
results = []
|
|
for path, base in paths_to_resolve:
|
|
result = resolve_hermes_path(path, base)
|
|
results.append(result)
|
|
|
|
# Write output
|
|
output_path = Path("/root/.hermes/wizard-outputs/spark/resolved-paths.json")
|
|
import json
|
|
with open(output_path, "w") as f:
|
|
json.dump({
|
|
"tool": "hermes-path-resolver",
|
|
"timestamp": "2026-10-12T00:15:00Z",
|
|
"results": results
|
|
}, f, indent=2)
|
|
|
|
print(f"Resolved {len(results)} paths to: {output_path}")
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |