Files

38 lines
991 B
Python
Raw Permalink Normal View History

import json
from pathlib import Path
from typing import Dict, Any
from .lineage_resolver import resolve_lineage
from .grammar_hooks import summarize_lineage
def inspect_gx(path: str) -> str:
try:
gx_file = Path(path)
if not gx_file.exists():
return f"Error: File not found: {path}"
data = gx_file.read_bytes()
if len(data) < 8 or not data.startswith(b'XIC'):
return "Error: Invalid .gx file (bad magic bytes)"
version = data[3]
manifest_len = int.from_bytes(data[4:8], 'big')
if len(data) < 8 + manifest_len:
return "Error: Incomplete .gx file"
manifest_json = data[8:8 + manifest_len]
manifest = json.loads(manifest_json.decode('utf-8'))
entry = resolve_lineage(manifest)
return summarize_lineage(entry)
except json.JSONDecodeError as e:
return f"Error: Invalid manifest JSON: {e}"
except Exception as e:
return f"Error: {e}"