2026-05-20 17:12:30 -04:00
|
|
|
"""Supercharged Glyph Registry (LedoGlyph600)
|
|
|
|
|
|
|
|
|
|
Registry for 600-glyph supercharged dataset with:
|
|
|
|
|
- 112 superpowers per glyph
|
|
|
|
|
- frequency signatures (praw: P, R, A, W)
|
|
|
|
|
- contributor inheritance (lineage)
|
|
|
|
|
- symbolic anatomy (originalMetrics)
|
|
|
|
|
- activation envelopes (activation modes)
|
|
|
|
|
- resonance profiles (activation signatures)
|
|
|
|
|
- extended metadata (governance, routing, storage)
|
|
|
|
|
|
|
|
|
|
Data source: /mnt/d/users/dave/Downloads/LEDONOVA/LedoGlyph600.json
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from typing import Optional, List, Dict, Any
|
|
|
|
|
import json
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
# Module-level cache
|
|
|
|
|
_glyphs: Optional[Dict[str, dict]] = None
|
|
|
|
|
_glyph_ids: Optional[List[str]] = None
|
|
|
|
|
_loaded = False
|
|
|
|
|
_load_path: Optional[Path] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_all_supercharged(path: Optional[str] = None) -> None:
|
|
|
|
|
"""Load all 600 supercharged glyphs from JSON file.
|
|
|
|
|
|
|
|
|
|
Lazy-loads and caches glyphs in module-level variables.
|
|
|
|
|
Validates that exactly 600 glyphs are present.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
path: Optional path to LedoGlyph600.json file.
|
|
|
|
|
Defaults to /mnt/d/users/dave/Downloads/LEDONOVA/LedoGlyph600.json
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
FileNotFoundError: If file doesn't exist
|
|
|
|
|
ValueError: If glyph count != 600
|
|
|
|
|
json.JSONDecodeError: If JSON is malformed
|
|
|
|
|
"""
|
|
|
|
|
global _glyphs, _glyph_ids, _loaded, _load_path
|
|
|
|
|
|
|
|
|
|
if _loaded:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Resolve path
|
|
|
|
|
if path is None:
|
2026-07-09 12:54:44 -04:00
|
|
|
# Try local path first, then fallback
|
|
|
|
|
local_path = Path(__file__).parent / "supercharged_glyphs.json"
|
|
|
|
|
if local_path.exists():
|
|
|
|
|
path = str(local_path)
|
|
|
|
|
else:
|
|
|
|
|
path = "/mnt/d/users/dave/Downloads/LEDONOVA/LedoGlyph600.json"
|
2026-05-20 17:12:30 -04:00
|
|
|
|
|
|
|
|
filepath = Path(path)
|
|
|
|
|
if not filepath.exists():
|
|
|
|
|
raise FileNotFoundError(f"Supercharged glyph file not found: {filepath}")
|
|
|
|
|
|
|
|
|
|
_load_path = filepath
|
|
|
|
|
|
|
|
|
|
# Load JSON
|
|
|
|
|
with open(filepath) as f:
|
|
|
|
|
data = json.load(f)
|
|
|
|
|
|
|
|
|
|
# Extract glyphs
|
|
|
|
|
if isinstance(data, dict) and "glyphs" in data:
|
|
|
|
|
glyph_list = data["glyphs"]
|
|
|
|
|
elif isinstance(data, list):
|
|
|
|
|
glyph_list = data
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError("Invalid glyph data structure")
|
|
|
|
|
|
|
|
|
|
# Validate count
|
|
|
|
|
if len(glyph_list) != 600:
|
|
|
|
|
raise ValueError(f"Expected 600 glyphs, got {len(glyph_list)}")
|
|
|
|
|
|
|
|
|
|
# Build cache dict by ID
|
|
|
|
|
_glyphs = {}
|
|
|
|
|
for glyph in glyph_list:
|
|
|
|
|
glyph_id = glyph.get("id")
|
|
|
|
|
if glyph_id:
|
|
|
|
|
_glyphs[glyph_id] = glyph
|
|
|
|
|
|
|
|
|
|
# Build ID list
|
|
|
|
|
_glyph_ids = sorted(list(_glyphs.keys()))
|
|
|
|
|
|
|
|
|
|
_loaded = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_super(glyph_id: str) -> Optional[dict]:
|
|
|
|
|
"""Get a single supercharged glyph by ID.
|
|
|
|
|
|
|
|
|
|
Returns all fields: id, name, category, period, band, originalMetrics,
|
|
|
|
|
praw, score, lineage, activation, routing, storage, governance.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
glyph_id: Glyph ID (e.g. "G001")
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Glyph dict with all supercharged fields, or None if not found
|
|
|
|
|
"""
|
|
|
|
|
if not _loaded:
|
|
|
|
|
load_all_supercharged()
|
|
|
|
|
|
|
|
|
|
return _glyphs.get(glyph_id) if _glyphs else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def list_super_ids() -> List[str]:
|
|
|
|
|
"""List all supercharged glyph IDs (sorted).
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List of 600 glyph IDs
|
|
|
|
|
"""
|
|
|
|
|
if not _loaded:
|
|
|
|
|
load_all_supercharged()
|
|
|
|
|
|
|
|
|
|
return _glyph_ids[:] if _glyph_ids else []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def search_super(
|
|
|
|
|
query: str,
|
|
|
|
|
*,
|
|
|
|
|
fields: Optional[List[str]] = None,
|
|
|
|
|
limit: int = 20
|
|
|
|
|
) -> List[dict]:
|
|
|
|
|
"""Search supercharged glyphs by query across specified fields.
|
|
|
|
|
|
|
|
|
|
Performs case-insensitive substring matching on string fields and
|
|
|
|
|
numeric fields converted to strings.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
query: Search string (case-insensitive substring match)
|
|
|
|
|
fields: List of field names to search.
|
|
|
|
|
Defaults to ['id', 'name', 'category']
|
|
|
|
|
limit: Maximum results to return (default 20)
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List of matching glyph dicts (up to limit)
|
|
|
|
|
"""
|
|
|
|
|
if not _loaded:
|
|
|
|
|
load_all_supercharged()
|
|
|
|
|
|
|
|
|
|
if not _glyphs:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
if fields is None:
|
|
|
|
|
fields = ["id", "name", "category"]
|
|
|
|
|
|
|
|
|
|
query_lower = query.lower()
|
|
|
|
|
results = []
|
|
|
|
|
|
|
|
|
|
for glyph_id in _glyph_ids:
|
|
|
|
|
glyph = _glyphs[glyph_id]
|
|
|
|
|
|
|
|
|
|
# Search in specified fields
|
|
|
|
|
for field in fields:
|
|
|
|
|
value = glyph.get(field)
|
|
|
|
|
if value is None:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Convert to string for matching
|
|
|
|
|
if isinstance(value, str):
|
|
|
|
|
if query_lower in value.lower():
|
|
|
|
|
results.append(glyph)
|
|
|
|
|
break
|
|
|
|
|
elif isinstance(value, (int, float)):
|
|
|
|
|
if query_lower in str(value).lower():
|
|
|
|
|
results.append(glyph)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
# Stop if we've hit limit
|
|
|
|
|
if len(results) >= limit:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
return results[:limit]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def super_stats() -> dict:
|
|
|
|
|
"""Get statistics about the supercharged glyph registry.
|
|
|
|
|
|
|
|
|
|
Validates registry integrity and returns metadata.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Dict with keys:
|
|
|
|
|
- total_glyphs: Count of glyphs (should be 600)
|
|
|
|
|
- fields_present: List of all field names found across glyphs
|
|
|
|
|
- sample_ids: First 5 glyph IDs
|
|
|
|
|
- categories: List of all unique categories
|
|
|
|
|
- loaded: Whether registry is loaded
|
|
|
|
|
- load_path: Path to data file
|
|
|
|
|
"""
|
|
|
|
|
if not _loaded:
|
|
|
|
|
load_all_supercharged()
|
|
|
|
|
|
|
|
|
|
if not _glyphs:
|
|
|
|
|
return {
|
|
|
|
|
"total_glyphs": 0,
|
|
|
|
|
"fields_present": [],
|
|
|
|
|
"sample_ids": [],
|
|
|
|
|
"categories": [],
|
|
|
|
|
"loaded": False,
|
|
|
|
|
"load_path": None,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Collect all field names
|
|
|
|
|
all_fields = set()
|
|
|
|
|
all_categories = set()
|
|
|
|
|
|
|
|
|
|
for glyph in _glyphs.values():
|
|
|
|
|
all_fields.update(glyph.keys())
|
|
|
|
|
category = glyph.get("category")
|
|
|
|
|
if category:
|
|
|
|
|
all_categories.add(category)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"total_glyphs": len(_glyphs),
|
|
|
|
|
"fields_present": sorted(list(all_fields)),
|
|
|
|
|
"sample_ids": _glyph_ids[:5] if _glyph_ids else [],
|
|
|
|
|
"categories": sorted(list(all_categories)),
|
|
|
|
|
"loaded": _loaded,
|
|
|
|
|
"load_path": str(_load_path) if _load_path else None,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_super_field(glyph_id: str, field_path: str, default: Any = None) -> Any:
|
|
|
|
|
"""Get a nested field from a supercharged glyph.
|
|
|
|
|
|
|
|
|
|
Supports dot-notation for nested fields (e.g. "activation.score",
|
|
|
|
|
"praw.P", "lineage.signature").
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
glyph_id: Glyph ID
|
|
|
|
|
field_path: Field path (supports dots for nesting)
|
|
|
|
|
default: Default value if not found
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Field value or default
|
|
|
|
|
"""
|
|
|
|
|
glyph = get_super(glyph_id)
|
|
|
|
|
if glyph is None:
|
|
|
|
|
return default
|
|
|
|
|
|
|
|
|
|
# Handle nested paths
|
|
|
|
|
parts = field_path.split(".")
|
|
|
|
|
value = glyph
|
|
|
|
|
|
|
|
|
|
for part in parts:
|
|
|
|
|
if isinstance(value, dict):
|
|
|
|
|
value = value.get(part)
|
|
|
|
|
if value is None:
|
|
|
|
|
return default
|
|
|
|
|
else:
|
|
|
|
|
return default
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def list_super_by_category(category: str) -> List[dict]:
|
|
|
|
|
"""List all supercharged glyphs in a category.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
category: Category name (e.g. "neural", "harmonic")
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List of matching glyphs
|
|
|
|
|
"""
|
|
|
|
|
if not _loaded:
|
|
|
|
|
load_all_supercharged()
|
|
|
|
|
|
|
|
|
|
if not _glyphs:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
return [g for g in _glyphs.values() if g.get("category") == category]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_super_by_band(band: int) -> List[dict]:
|
|
|
|
|
"""List all supercharged glyphs in a frequency band.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
band: Band number
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List of matching glyphs sorted by band
|
|
|
|
|
"""
|
|
|
|
|
if not _loaded:
|
|
|
|
|
load_all_supercharged()
|
|
|
|
|
|
|
|
|
|
if not _glyphs:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
return sorted(
|
|
|
|
|
[g for g in _glyphs.values() if g.get("band") == band],
|
|
|
|
|
key=lambda g: g.get("id", "")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_glyphs_by_score_range(min_score: int, max_score: int) -> List[dict]:
|
|
|
|
|
"""List glyphs with scores in the given range.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
min_score: Minimum score (inclusive)
|
|
|
|
|
max_score: Maximum score (inclusive)
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List of glyphs sorted by score descending
|
|
|
|
|
"""
|
|
|
|
|
if not _loaded:
|
2026-05-20 17:57:38 -04:00
|
|
|
load_all_supercharged()
|
2026-05-20 17:12:30 -04:00
|
|
|
|
|
|
|
|
if not _glyphs:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
return sorted(
|
|
|
|
|
[
|
|
|
|
|
g for g in _glyphs.values()
|
|
|
|
|
if min_score <= g.get("score", 0) <= max_score
|
|
|
|
|
],
|
|
|
|
|
key=lambda g: g.get("score", 0),
|
|
|
|
|
reverse=True
|
|
|
|
|
)
|