feat(graph): integrate hyperstitionstud_io.* & urn:io:hyperstitionstud:* namespaces, dual file:// + http:// portability (--bundle-encyclopedia), and v1.2.0 common library

This commit is contained in:
Hermes Agent committed 2026-11-29 21:06:48 +00:00
1 parent cd1abd3c6c
commit b4ca2ceb1e
11 files changed
+302 -275

No files matched your search

+39 -4
View File
@@ -25,9 +25,27 @@ import html
import json
import math
import re
import shutil
import sys
from pathlib import Path
from typing import Any
_CORE_SRC = Path("/workspace/hyperstitionstudio-core/src")
if _CORE_SRC.is_dir() and str(_CORE_SRC) not in sys.path:
sys.path.insert(0, str(_CORE_SRC))
try:
from hyperstitionstud_io.ciphers import compute_aq as _hs_compute_aq
from hyperstitionstud_io.glossary import ReadOnlyIsolationGuard
from hyperstitionstud_io.graph import URN_GRAPH_NS, URN_SCHEMA_GRAPH, make_entity_urn
except ImportError:
_hs_compute_aq = None
ReadOnlyIsolationGuard = None
URN_GRAPH_NS = "urn:io:hyperstitionstud:ns:kg:1.0"
URN_SCHEMA_GRAPH = "urn:io:hyperstitionstud:schema:v1:encyclopedia-graph"
def make_entity_urn(domain: str, entity_type: str, entity_id: str | int) -> str:
return f"urn:io:hyperstitionstud:{domain}:{entity_type}:{entity_id}"
KG_REPO_ROOT = Path("/workspace/encyclopedia-knowledge-graph")
UPSTREAM_REPO_DEFAULT = Path("/workspace/technocapital-singularity-zoology")
HOST_UPSTREAM_ROOT = "/home/m00t/hermes/workspace/technocapital-singularity-zoology"
@@ -680,7 +698,11 @@ def build_graph(upstream_repo: Path = UPSTREAM_REPO_DEFAULT) -> dict[str, Any]:
)[:15]
return {
"version": "1.0.0",
"$schema": "./schemas/v1/encyclopedia-graph.schema.json",
"$id": URN_SCHEMA_GRAPH,
"namespace_urn": URN_GRAPH_NS,
"version": "1.2.0",
"encyclopedia_base_path": "../technocapital-singularity-zoology/encyclopedia",
"upstream_repository": str(upstream_repo),
"isolation_verified": {
"glossary_registry_sha256_pre": pre_gl_sha,
@@ -726,7 +748,7 @@ def build_graph(upstream_repo: Path = UPSTREAM_REPO_DEFAULT) -> dict[str, Any]:
def export_graphml(graph_data: dict[str, Any], out_path: Path) -> None:
lines = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<graphml xmlns="http://graphml.graphdrawing.org/xmlns">',
f'<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:hs="{URN_GRAPH_NS}">',
' <key id="label" for="node" attr.name="label" attr.type="string"/>',
' <key id="node_type" for="node" attr.name="node_type" attr.type="string"/>',
' <key id="color" for="node" attr.name="color" attr.type="string"/>',
@@ -771,7 +793,7 @@ def export_graphml(graph_data: dict[str, Any], out_path: Path) -> None:
def export_gexf(graph_data: dict[str, Any], out_path: Path) -> None:
lines = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<gexf xmlns="http://www.gexf.net/1.3" xmlns:viz="http://www.gexf.net/1.3/viz" version="1.3">',
f'<gexf xmlns="http://www.gexf.net/1.3" xmlns:viz="http://www.gexf.net/1.3/viz" xmlns:hs="{URN_GRAPH_NS}" version="1.3">',
' <graph mode="static" defaultedgetype="directed">',
' <attributes class="node">',
' <attribute id="0" title="node_type" type="string"/>',
@@ -1063,6 +1085,7 @@ def main() -> int:
ap = argparse.ArgumentParser(description="Build, verify, and query the Encyclopedia of Technocapital Singularity Zoology Knowledge Graph.")
ap.add_argument("--upstream-repo", default=str(UPSTREAM_REPO_DEFAULT), help="Path to upstream technocapital-singularity-zoology repository (read-only).")
ap.add_argument("--out-dir", default=str(KG_REPO_ROOT), help="Target output directory for generated graph artifacts (default: /workspace/encyclopedia-knowledge-graph).")
ap.add_argument("--bundle-encyclopedia", action="store_true", help="Copy/bundle ./encyclopedia/ into --out-dir and set encyclopedia_base_path='./encyclopedia' for single-folder static HTTP hosting.")
ap.add_argument("--verify-only", action="store_true", help="Run 6-gate verification on existing knowledge-graph artifacts without rebuilding.")
ap.add_argument("--check-isolation", action="store_true", help="Print upstream glossary and encyclopedia SHA-256 digests and verify zero modifications.")
ap.add_argument("--query-node", default=None, help="Query a node by ID, headword, Ingglish token, or integer AQ coordinate and inspect its ego-network.")
@@ -1101,6 +1124,13 @@ def main() -> int:
return 0
out_dir.mkdir(parents=True, exist_ok=True)
if args.bundle_encyclopedia:
src_enc = upstream_repo / "encyclopedia"
dst_enc = out_dir / "encyclopedia"
if src_enc.is_dir():
shutil.copytree(src_enc, dst_enc, dirs_exist_ok=True)
graph_data["encyclopedia_base_path"] = "./encyclopedia"
json_path = out_dir / "encyclopedia-graph.json"
js_path = out_dir / "graph-data.js"
graphml_path = out_dir / "encyclopedia-graph.graphml"
@@ -1109,7 +1139,12 @@ def main() -> int:
json_str = json.dumps(graph_data, indent=2, ensure_ascii=False)
json_path.write_text(json_str + "\n", encoding="utf-8")
js_path.write_text(f"window.ENCYCLOPEDIA_GRAPH_DATA = {json_str};\n", encoding="utf-8")
js_path.write_text(
"window.HyperstitionStudio = window.HyperstitionStudio || {};\n"
f"window.HyperstitionStudio.EncyclopediaGraphData = {json_str};\n"
"window.ENCYCLOPEDIA_GRAPH_DATA = window.HyperstitionStudio.EncyclopediaGraphData;\n",
encoding="utf-8",
)
export_graphml(graph_data, graphml_path)
export_gexf(graph_data, gexf_path)