Clean up nested duplicate: v2/v2/pharos/build_campus_pack.py
Browse files
v2/v2/pharos/build_campus_pack.py
DELETED
|
@@ -1,120 +0,0 @@
|
|
| 1 |
-
"""Build the campus_architecture Pharos pack from Rivet's context files.
|
| 2 |
-
|
| 3 |
-
Deterministic extraction — no LLM in the loop. Parses the markdown
|
| 4 |
-
tables and section structure of architecture_map.md and imports the
|
| 5 |
-
audit findings from their single source of truth
|
| 6 |
-
(skills/security_review.py). Output is a standard Pharos pack
|
| 7 |
-
(triples.json + stats.json in a directory), loadable by pack_loader and
|
| 8 |
-
KV-warmable by kv_injector.
|
| 9 |
-
|
| 10 |
-
Usage:
|
| 11 |
-
python pharos/build_campus_pack.py [--context-dir ../context] [--out ../packs]
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
import argparse
|
| 15 |
-
import json
|
| 16 |
-
import re
|
| 17 |
-
import sys
|
| 18 |
-
from pathlib import Path
|
| 19 |
-
|
| 20 |
-
sys.path.insert(0, str(Path(__file__).parent.parent))
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def _table_rows(section: str) -> list:
|
| 24 |
-
rows = []
|
| 25 |
-
for line in section.splitlines():
|
| 26 |
-
if not line.strip().startswith("|"):
|
| 27 |
-
continue
|
| 28 |
-
cells = [c.strip() for c in line.strip().strip("|").split("|")]
|
| 29 |
-
if cells and not set(cells[0]) <= {"-", " ", ":"}:
|
| 30 |
-
rows.append(cells)
|
| 31 |
-
return rows[1:] if rows else [] # drop header
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def build_triples(context_dir: Path) -> list:
|
| 35 |
-
triples = []
|
| 36 |
-
arch_path = context_dir / "architecture_map.md"
|
| 37 |
-
if arch_path.exists():
|
| 38 |
-
text = arch_path.read_text()
|
| 39 |
-
|
| 40 |
-
# Stack table: | Layer | Technology |
|
| 41 |
-
stack = re.search(r"## Stack\n(.*?)\n---", text, re.DOTALL)
|
| 42 |
-
if stack:
|
| 43 |
-
for cells in _table_rows(stack.group(1)):
|
| 44 |
-
if len(cells) >= 2:
|
| 45 |
-
triples.append({"subject": "campus_" + cells[0].lower().replace(" ", "_"),
|
| 46 |
-
"predicate": "implemented_with",
|
| 47 |
-
"object": cells[1]})
|
| 48 |
-
|
| 49 |
-
# External services table: | Service | Purpose | Notes |
|
| 50 |
-
services = re.search(r"## External Services\n(.*?)\n---", text, re.DOTALL)
|
| 51 |
-
if services:
|
| 52 |
-
for cells in _table_rows(services.group(1)):
|
| 53 |
-
if len(cells) >= 2:
|
| 54 |
-
triples.append({"subject": "campus",
|
| 55 |
-
"predicate": "integrates",
|
| 56 |
-
"object": f"{cells[0]} ({cells[1]})"})
|
| 57 |
-
|
| 58 |
-
# Hard operational facts.
|
| 59 |
-
triples += [
|
| 60 |
-
{"subject": "staging_environment", "predicate": "shares_database_with",
|
| 61 |
-
"object": "production_environment"},
|
| 62 |
-
{"subject": "campus_migrations", "predicate": "must_be",
|
| 63 |
-
"object": "additive_only"},
|
| 64 |
-
{"subject": "campus_migrations", "predicate": "must_be",
|
| 65 |
-
"object": "backward_compatible_and_reversible"},
|
| 66 |
-
{"subject": "campus_auth", "predicate": "uses",
|
| 67 |
-
"object": "bearer_jwt_15min_access_7day_refresh"},
|
| 68 |
-
{"subject": "campus_auth", "predicate": "middleware_chain",
|
| 69 |
-
"object": "verifyToken -> rejectIfIneligible -> requireAdmin/requireModerator"},
|
| 70 |
-
{"subject": "websocket_auth", "predicate": "verified_via",
|
| 71 |
-
"object": "handshake.auth.token -> verifyToken()"},
|
| 72 |
-
{"subject": "campus_deploy", "predicate": "flows_through",
|
| 73 |
-
"object": "push_to_main -> coolify_rebuild (webhook flaky)"},
|
| 74 |
-
{"subject": "deploy-safe.sh", "predicate": "provides",
|
| 75 |
-
"object": "snapshot + smoke test + rollback"},
|
| 76 |
-
]
|
| 77 |
-
|
| 78 |
-
# Audit findings from their single source of truth.
|
| 79 |
-
from skills.security_review import AUDIT_FINDINGS, RECURRING_PATTERNS
|
| 80 |
-
for f in AUDIT_FINDINGS:
|
| 81 |
-
triples.append({"subject": f"audit_finding_{f.id}",
|
| 82 |
-
"predicate": "severity", "object": f.severity})
|
| 83 |
-
triples.append({"subject": f"audit_finding_{f.id}",
|
| 84 |
-
"predicate": "describes", "object": f.title})
|
| 85 |
-
triples.append({"subject": f"audit_finding_{f.id}",
|
| 86 |
-
"predicate": "remediation", "object": f.advice})
|
| 87 |
-
if f.file_hint:
|
| 88 |
-
triples.append({"subject": f"audit_finding_{f.id}",
|
| 89 |
-
"predicate": "located_at", "object": f.file_hint})
|
| 90 |
-
for name, _, message in RECURRING_PATTERNS:
|
| 91 |
-
triples.append({"subject": f"antipattern_{name}",
|
| 92 |
-
"predicate": "warns", "object": message})
|
| 93 |
-
|
| 94 |
-
return triples
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
def main() -> None:
|
| 98 |
-
ap = argparse.ArgumentParser()
|
| 99 |
-
default_ctx = Path(__file__).parent.parent.parent / "context"
|
| 100 |
-
default_out = Path(__file__).parent.parent.parent / "packs"
|
| 101 |
-
ap.add_argument("--context-dir", default=str(default_ctx))
|
| 102 |
-
ap.add_argument("--out", default=str(default_out))
|
| 103 |
-
args = ap.parse_args()
|
| 104 |
-
|
| 105 |
-
triples = build_triples(Path(args.context_dir))
|
| 106 |
-
pack_dir = Path(args.out) / "campus_architecture"
|
| 107 |
-
pack_dir.mkdir(parents=True, exist_ok=True)
|
| 108 |
-
(pack_dir / "triples.json").write_text(json.dumps({
|
| 109 |
-
"description": ("Multiverse Campus system architecture, operational "
|
| 110 |
-
"constraints, and confirmed audit findings"),
|
| 111 |
-
"triples": triples,
|
| 112 |
-
}, indent=2))
|
| 113 |
-
(pack_dir / "stats.json").write_text(json.dumps({
|
| 114 |
-
"triples": len(triples), "source": "build_campus_pack.py",
|
| 115 |
-
}, indent=2))
|
| 116 |
-
print(f"campus_architecture pack: {len(triples)} triples -> {pack_dir}")
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
if __name__ == "__main__":
|
| 120 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|