2026-03-04 04:25:14 +00:00
|
|
|
"""Refresh all stale documentation — relationships and repo summaries."""
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
2026-03-04 04:42:28 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
# Load .env if present
|
|
|
|
|
_env_file = Path(__file__).parent / ".env"
|
|
|
|
|
if _env_file.exists():
|
|
|
|
|
for line in _env_file.read_text().splitlines():
|
|
|
|
|
line = line.strip()
|
|
|
|
|
if line and not line.startswith("#") and "=" in line:
|
|
|
|
|
key, _, val = line.partition("=")
|
|
|
|
|
os.environ.setdefault(key.strip(), val.strip())
|
2026-03-04 04:25:14 +00:00
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
|
from db import GraphDB
|
|
|
|
|
from docgen import generate_relationship_doc, generate_repo_doc
|
|
|
|
|
|
|
|
|
|
REPO_DIR = os.environ.get("REPO_DIR", os.path.join(os.path.dirname(__file__), "repos", "target"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_stale():
|
|
|
|
|
db = GraphDB()
|
|
|
|
|
|
|
|
|
|
print(f"\n{'='*60}")
|
|
|
|
|
print("Refreshing stale documentation")
|
|
|
|
|
print(f"{'='*60}")
|
|
|
|
|
|
|
|
|
|
stats_before = db.get_stats()
|
|
|
|
|
print(f"\nBefore: {stats_before['stale_relationships']} stale relationships")
|
|
|
|
|
|
|
|
|
|
# Refresh stale relationship docs
|
|
|
|
|
stale_rels = db.get_stale_relationships()
|
|
|
|
|
if stale_rels:
|
|
|
|
|
print(f"\n[1/2] Regenerating {len(stale_rels)} stale relationship docs...")
|
|
|
|
|
for i, rel in enumerate(stale_rels):
|
|
|
|
|
doc = generate_relationship_doc(
|
|
|
|
|
rel["from_file"], rel["from_doc"] or "",
|
|
|
|
|
rel["to_file"], rel["to_doc"] or "",
|
|
|
|
|
)
|
|
|
|
|
db.update_relationship_doc(rel["from_file"], rel["to_file"], doc)
|
|
|
|
|
if (i + 1) % 5 == 0 or (i + 1) == len(stale_rels):
|
|
|
|
|
print(f" Refreshed {i+1}/{len(stale_rels)}")
|
|
|
|
|
else:
|
|
|
|
|
print("\n[1/2] No stale relationships.")
|
|
|
|
|
|
|
|
|
|
# Refresh stale repo docs
|
|
|
|
|
stale_repos = db.get_stale_repos()
|
|
|
|
|
if stale_repos:
|
|
|
|
|
print(f"\n[2/2] Regenerating {len(stale_repos)} stale repo docs...")
|
|
|
|
|
for repo in stale_repos:
|
|
|
|
|
file_docs = db.get_repo_files_docs(repo["name"])
|
|
|
|
|
priority_names = ["echo.go", "router.go", "context.go", "group.go", "main.go", "server.go"]
|
|
|
|
|
entry_files = []
|
|
|
|
|
for name in priority_names:
|
|
|
|
|
for path, doc in file_docs:
|
|
|
|
|
if path.endswith(name) and doc:
|
|
|
|
|
entry_files.append((path, doc))
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
readme_path = os.path.join(REPO_DIR, "README.md")
|
|
|
|
|
readme = ""
|
|
|
|
|
if os.path.exists(readme_path):
|
|
|
|
|
with open(readme_path) as f:
|
|
|
|
|
readme = f.read()
|
|
|
|
|
|
|
|
|
|
repo_doc = generate_repo_doc(readme, entry_files)
|
|
|
|
|
db.update_repo_doc(repo["name"], repo_doc)
|
|
|
|
|
print(f" Refreshed repo: {repo['name']}")
|
|
|
|
|
else:
|
|
|
|
|
print("\n[2/2] No stale repos.")
|
|
|
|
|
|
|
|
|
|
stats_after = db.get_stats()
|
|
|
|
|
print(f"\n{'='*60}")
|
|
|
|
|
print("Refresh complete!")
|
|
|
|
|
print(f" Stale rels: {stats_before['stale_relationships']} → {stats_after['stale_relationships']}")
|
|
|
|
|
print(f"{'='*60}")
|
|
|
|
|
|
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
refresh_stale()
|