"""Ingest a repo and run fresh architecture analysis against the local API.""" from __future__ import annotations import json import sys import time import urllib.error import urllib.request BASE = "http://127.0.0.1:8001" LOCAL_PATH = None GITHUB_URL = "https://github.com/tiangolo/full-stack-fastapi-template" if len(sys.argv) > 1: if sys.argv[1].startswith("http"): GITHUB_URL = sys.argv[1] else: LOCAL_PATH = sys.argv[1] def post(path: str, data: dict) -> dict: req = urllib.request.Request( f"{BASE}{path}", data=json.dumps(data).encode(), headers={"Content-Type": "application/json"}, method="POST", ) with urllib.request.urlopen(req, timeout=600) as response: return json.loads(response.read().decode()) def get(path: str) -> dict: with urllib.request.urlopen(f"{BASE}{path}", timeout=120) as response: return json.loads(response.read().decode()) def main() -> None: if LOCAL_PATH: print(f"Ingesting local path {LOCAL_PATH} ...") ingest = post("/api/repo/ingest-local", {"local_path": LOCAL_PATH}) else: print(f"Ingesting {GITHUB_URL} ...") ingest = post("/api/repo/ingest", {"github_url": GITHUB_URL}) repo_id = ingest["repo_id"] print(f"repo_id={repo_id} | {ingest.get('message', '')}") print("Starting architecture analysis ...") job = post("/api/architecture/analyze/start", {"repo_id": repo_id}) job_id = job.get("job_id") or job.get("id") print(f"job_id={job_id}") for attempt in range(180): status = get(f"/api/architecture/analyze/jobs/{job_id}") state = status.get("status") message = str(status.get("message", ""))[:100] print(f" [{attempt}] {state}: {message}") if state == "completed": analysis = (status.get("result") or {}).get("analysis") or {} services = [item.get("name") for item in analysis.get("core_services", [])[:14]] mermaid = analysis.get("mermaid_diagram", "") print("Services:", services) title_lines = [line for line in mermaid.splitlines() if "title" in line.lower()] print("Mermaid title:", title_lines[:2]) print("Has tech_stack:", "tech_stack" in mermaid) print("Has unnamed:", "unnamed" in mermaid.lower()) print() print("Open the app:") print(f" http://localhost:5173/") print(f"Architecture page: http://localhost:5173/architecture?repoId={repo_id}") return if state == "failed": print("FAILED:", status.get("error")) sys.exit(1) time.sleep(3) print("Timed out waiting for architecture job.") sys.exit(1) if __name__ == "__main__": try: main() except urllib.error.URLError as exc: print(f"API not reachable at {BASE}: {exc}") sys.exit(1)