# Architecture & Migration Plan: Shared Common Library Across All `/workspace` Projects Under the `hyperstitionstud.io` Namespace (`v1.0.0`) - **Document ID:** `PLAN-COMMON-LIBRARY-HYPERSTITIONSTUDIO` (`v1.0.0`) - **Canonical Domain & Authority:** `hyperstitionstud.io` - **Python PEP 420 Reverse-DNS Namespace:** `io.hyperstitionstud.*` (installed from `/workspace/hyperstitionstudio-core`) - **JavaScript / ESM Scope Namespace:** `@hyperstitionstud.io/*` (`window.HyperstitionStudio.*` in offline browser bundles) - **Schema, XML & URN Authority:** `https://hyperstitionstud.io/schemas/v1/*`, `https://hyperstitionstud.io/ns/*`, and `urn:io:hyperstitionstud:*` - **Glossary & Encyclopedia Isolation Invariant:** Verified (`0` changes to `taxonomy/glossary-registry.json` or `encyclopedia/encyclopedia-manifest.json`). --- ## 1. Executive Summary & Architectural Problem Statement Across the peer repositories in `/workspace` (`ingglish-hyperdope-gematria`, `technocapital-singularity-zoology`, `encyclopedia-knowledge-graph`, `hyperdope-ci-build`, `hyperdope-gematria`, `memes`, and `thomas-calculus-tutor`), several foundational subsystems are currently either **duplicated in-file** or **coupled via cross-repository hardcoded script paths**: 1. **Cross-Repo Subprocess Handoffs for PDF & Tier-List Rendering:** Both `technocapital-singularity-zoology` and `encyclopedia-knowledge-graph` invoke `/workspace/ingglish-hyperdope-gematria/ingglish-aq-archive/scripts/build_wire_report_pdf.py` and `generate_aq_tier_list.py` via hardcoded sibling paths. 2. **Cross-Repo Node.js `ingglish` (`CMUdict`) Resolution:** `technocapital-singularity-zoology/scripts/classify_technocapital_singularity.py` spawns `node --input-type=module` with `--workdir /workspace/ingglish-hyperdope-gematria` to resolve `node_modules/ingglish`. 3. **Duplicated Base-36 `AQ` & Prime Arithmetic:** `compute_aq()`, prime-sieve/rank lookup (`is_prime`, `prime_rank`), repdigit detection (`37 * k`), and `G1–G6` drift/variance-collapse equations are re-implemented separately in `classify_technocapital_singularity.py`, `build_encyclopedia_knowledge_graph.py`, `ci_provision_ingglish.py`, and `generate_aq_tier_list.py`. 4. **Ad-Hoc JSON Schema & Provenance Identifiers:** The 8 JSON registries in `technocapital-singularity-zoology` and the exported graph files in `encyclopedia-knowledge-graph` lack a unified `$schema` URI and XML/URN namespace authority. ### Solution Overview Extract all shared computation, phonetic translation, PDF/PNG/Canvas rendering, cryptographic isolation guards, and CI validation into a single, zero-duplication sibling repository: - **Repository Path:** `/workspace/hyperstitionstudio-core` - **Python Namespace Package (PEP 420):** `io.hyperstitionstud.*` - **JS/Browser Namespace:** `@hyperstitionstud.io/*` - **XML/JSON/URN Namespace:** `https://hyperstitionstud.io/...` & `urn:io:hyperstitionstud:...` --- ## 2. Canonical `hyperstitionstud.io` Namespace Hierarchy | Layer / Ecosystem | Canonical Namespace Pattern | Concrete Examples | | :--- | :--- | :--- | | **Python 3.10+ (PEP 420 Namespace Package)** | `io.hyperstitionstud.` | `io.hyperstitionstud.ciphers`
`io.hyperstitionstud.phonetics`
`io.hyperstitionstud.publishing`
`io.hyperstitionstud.glossary`
`io.hyperstitionstud.graph`
`io.hyperstitionstud.ci`
`io.hyperstitionstud.audio` | | **Node.js / ESM Packages** | `@hyperstitionstud.io/` | `@hyperstitionstud.io/phonetics-g2p`
`"@hyperstitionstud.io/ciphers-aq"`
`"@hyperstitionstud.io/graph-workbench"` | | **Offline Browser Global (`file://`)** | `window.HyperstitionStudio.` | `window.HyperstitionStudio.EncyclopediaGraphData`
`window.HyperstitionStudio.GraphWorkbench`
`window.HyperstitionStudio.Ciphers` | | **JSON Schema `$schema` & `$id` URIs** | `https://hyperstitionstud.io/schemas/v1/.schema.json` | `https://hyperstitionstud.io/schemas/v1/glossary-registry.schema.json`
`https://hyperstitionstud.io/schemas/v1/encyclopedia-manifest.schema.json`
`https://hyperstitionstud.io/schemas/v1/encyclopedia-graph.schema.json` | | **GraphML / GEXF XML Namespace** | `xmlns:hs="https://hyperstitionstud.io/ns/kg/1.0"` | ``
`249.36` | | **Entity & Node URN Identifiers** | `urn:io:hyperstitionstud:::` | `urn:io:hyperstitionstud:zoology:build:S1`
`urn:io:hyperstitionstud:aq:hub:125`
`urn:io:hyperstitionstud:lexicon:spec:blackwell` | | **CLI Entry Points (`pyproject.toml`)** | `hs-` | `hs-pdf-build`, `hs-tier-list`, `hs-ci-provision`, `hs-kg-build`, `hs-isolation-check` | --- ## 3. Repository Layout of `/workspace/hyperstitionstudio-core` ```text /workspace/hyperstitionstudio-core/ ├── pyproject.toml # Editable install: pip install -e /workspace/hyperstitionstudio-core ├── package.json # Workspace root for @hyperstitionstud.io/* JS/ESM packages ├── requirements.txt # Pillow>=10.0, reportlab>=4.0, pypdf>=4.0, pdfplumber>=0.10 ├── README.md ├── schemas/ │ └── v1/ # Canonical JSON Schemas (https://hyperstitionstud.io/schemas/v1/*) │ ├── glossary-registry.schema.json │ ├── encyclopedia-manifest.schema.json │ ├── singularity-zoology-matrix.schema.json │ ├── memetic-superclass-registry.schema.json │ ├── assemblage-builds-tier-list.schema.json │ ├── quantitative-economic-anchors.schema.json │ ├── citations-ledger.schema.json │ └── encyclopedia-graph.schema.json ├── src/ │ └── io/ │ └── hyperstitionstud/ # PEP 420 Namespace Root (no __init__.py at io/, explicit at leaf packages) │ ├── ciphers/ │ │ ├── __init__.py │ │ ├── base36_aq.py # compute_aq(), digit/spoken/dual quant modes, zero-d-filter guard │ │ ├── primes.py # Prime sieve, prime_rank(), twin-prime & repdigit (37*k) predicates │ │ └── vectors_g1_g6.py # G1 variance collapse, G2 cross-gen twins, G3 steps, G4 iso, G5 twin-prime │ ├── phonetics/ │ │ ├── __init__.py │ │ ├── ingglish_bridge.py # Self-contained Node G2P bridge + pure-Python CMUdict fallback cache │ │ └── cmudict_fallback.json # Offline deterministic fallback so zero --workdir coupling is needed │ ├── publishing/ │ │ ├── __init__.py │ │ ├── fonts.py # DejaVu Sans / Mono TrueType resolver & ReportLab family registration │ │ ├── pdf_compiler.py # Unified build_wire_report_pdf (atomic .tmp.pdf + pypdf verification) │ │ ├── tier_list_renderer.py # Unified S+..F & ETI 0-100 .pdf/.png card renderer (Pillow + ReportLab) │ │ ├── encyclopedia_pdf.py # Multi-division, alphabetized volume PDF compiler │ │ └── pokedex_compositor.py # Gen IV INFO Pokedex & meme-card compositor with box collision audit │ ├── glossary/ │ │ ├── __init__.py │ │ ├── registry.py # GlossaryRegistry CRUD, provenance-keyed filtering (source_type) │ │ └── isolation_guard.py # Pre/post SHA-256 context manager (`with ReadOnlyIsolationGuard(...):`) │ ├── graph/ │ │ ├── __init__.py │ │ ├── builder.py # Multi-partite property graph builder & seen_edges deduplicator │ │ ├── layouts.py # Mode 1 Trophic, Mode 2 Concentric ETI Radar, Mode 3 Funnel, Mode 4 Grid │ │ ├── exporters.py # JSON, GraphML (xmlns:hs), GEXF 1.3, Obsidian JSON Canvas 1.0 │ │ └── atlas_png.py # 1600x1060 high-res static board renderer with pill-masked arrows │ ├── ci/ │ │ ├── __init__.py │ │ ├── gates_hyperdope.py # 4-Gate CI validator (normalize_caps, classify_candidates, db.json) │ │ └── citation_sources.py # 3-tier provenance verifier (git remote URL -> local full-path fallback) │ └── audio/ │ ├── __init__.py │ └── multi_voice_tts.py # 5-voice edge-tts synthesizer, ffmpeg concat, mutagen duration audit ├── packages-js/ │ ├── ciphers-aq/ # @hyperstitionstud.io/ciphers-aq (shared with hyperdope-gematria) │ └── graph-workbench/ # @hyperstitionstud.io/graph-workbench (shared with index.html) └── tests/ ├── test_ciphers_and_vectors.py ├── test_phonetics_offline.py ├── test_publishing_pdf_and_png.py ├── test_glossary_isolation_guard.py └── test_graph_exporters_and_urns.py ``` --- ## 4. Detailed Module Specifications & How Each Eliminates Cross-Repo Coupling ### 4.1 `io.hyperstitionstud.ciphers` — Unified Base-36 `AQ`, Prime & `G1–G6` Vector Engine - **Replaces duplicated code in:** - `technocapital-singularity-zoology/scripts/classify_technocapital_singularity.py` - `encyclopedia-knowledge-graph/scripts/build_encyclopedia_knowledge_graph.py` - `ingglish-hyperdope-gematria/ingglish-aq-archive/scripts/ci_provision_ingglish.py` - `ingglish-hyperdope-gematria/ingglish-aq-archive/scripts/generate_aq_tier_list.py` - **Capabilities:** - `compute_aq(text: str, quant_mode: Literal["off", "spoken", "digit", "dual"] = "off") -> int` - `prime_rank(n: int) -> int | None` (1-indexed prime rank, e.g., `193 -> 44`, `137 -> 33`, `71 -> 20`) - `evaluate_bidirectional_lock(eng: str, ing: str) -> BidirectionalLock` (computes all 18 fields of the `G1–G6` schema: `eng_aq`, `ing_aq`, `delta`, `isometric`, `twin_prime_mutation`, `g3_quantized_step`, etc.) - `assert_zero_d_filter(text: str)` (enforces the strict boundary that Zoology and Knowledge Graph artifacts contain `0` references to the 10-letter `d` decagram). ### 4.2 `io.hyperstitionstud.phonetics` — Self-Contained `Ingglish` (`CMUdict`) Translator - **Eliminates `--workdir /workspace/ingglish-hyperdope-gematria` coupling:** - Currently, `classify_technocapital_singularity.py` requires `/workspace/ingglish-hyperdope-gematria/node_modules/ingglish` on disk to translate new English tokens into `Gen 1` Ingglish. - `io.hyperstitionstud.phonetics.translate_batch(terms)` embeds both: 1. A bundled deterministic `cmudict_fallback.json` + pure-Python ARPAbet-to-Ingglish grapheme mapper for `100%` offline zero-Node operation, and 2. An optional Node `@hyperstitionstud.io/phonetics-g2p` bridge when Node.js is available. - Result: `technocapital-singularity-zoology` can run `--scan-harvest`, `--revise-anchor`, and `--terms` on any machine even if `ingglish-hyperdope-gematria` is not cloned alongside it. ### 4.3 `io.hyperstitionstud.publishing` — Unified ReportLab PDF & Pillow Visual Renderer - **Eliminates hardcoded cross-repo script calls (`build_wire_report_pdf.py` & `generate_aq_tier_list.py`):** - `compile_markdown_to_pdf(md_path, pdf_path, title, namespace_footer="hyperstitionstud.io")`: - Performs atomic writes via `.tmp.pdf` -> `os.replace()`. - Automatically escapes inline code spans before bold/italic regexes so ReportLab's XML parser never fails on `<` or `>`. - Automatically verifies page count and extracted character count via `pypdf` and `pdfplumber`. - `render_tier_list_artifacts(rows, tier_defs, out_md, out_pdf, out_png)`: - Directly importable by both `ingglish-hyperdope-gematria` (`Option #4` `S+..F` evaluations) and `technocapital-singularity-zoology` (`ETI 0–100` Zoological Assemblage Builds) without spawning cross-repo subprocesses. ### 4.4 `io.hyperstitionstud.glossary` — Provenance-Keyed Glossary & Cryptographic Isolation Guard - **Provides reusable glossary infrastructure for all `/workspace` projects:** - `ReadOnlyIsolationGuard(paths: list[Path])`: ```python from io.hyperstitionstud.glossary import ReadOnlyIsolationGuard with ReadOnlyIsolationGuard([glossary_path, encyclopedia_manifest_path]) as guard: graph = build_graph(upstream_repo) # Automatically asserts pre_sha256 == post_sha256 on exit and emits guard.audit_receipt() ``` - `ProvenanceFilter`: Filters entries by explicit `source_type` (`"archive_dossier"`, `"news_wire_harvest"`, `"podcast_series"`, `"knowledge_graph_meta"`) rather than fragile substring matching, guaranteeing that excluding in-house media or graph terms never strips extrinsic news-wire or dossier vocabulary. --- ## 5. Project-by-Project Dependency & Migration Matrix | Workspace Project | Components Replaced by `io.hyperstitionstud.*` | Post-Migration Modularity Status | | :--- | :--- | :--- | | **`/workspace/technocapital-singularity-zoology`** | Replaces `--workdir` Node `ingglish` subprocess, subprocess calls to `generate_aq_tier_list.py` and `build_wire_report_pdf.py`, and in-file `compute_aq`/`prime_rank` with `io.hyperstitionstud.{ciphers,phonetics,publishing,glossary,ci,audio}`. | **100% Standalone** (zero runtime or build-time dependency on `ingglish-hyperdope-gematria`). | | **`/workspace/encyclopedia-knowledge-graph`** | Replaces in-file `compute_aq`, XML/Canvas serializers, SHA-256 check boilerplate, and `build_wire_report_pdf.py` calls with `io.hyperstitionstud.{graph,glossary,publishing}` + `xmlns:hs="https://hyperstitionstud.io/ns/kg/1.0"` and `urn:io:hyperstitionstud:*` node URNs. | **100% Standalone Compiler & Workbench** (consumes upstream JSONs validated against `https://hyperstitionstud.io/schemas/v1/*`). | | **`/workspace/ingglish-hyperdope-gematria`** | Delegates `build_wire_report_pdf.py`, `generate_aq_tier_list.py`, and `ci_provision_ingglish.py` core logic to `io.hyperstitionstud.{publishing,ci,ciphers}` while keeping thin CLI wrappers at existing script paths for backwards compatibility. | **100% Backwards-Compatible** (zero broken CLI paths; zero duplicated rendering code). | | **`/workspace/hyperdope-ci-build`** | Uses `io.hyperstitionstud.ci.gates_hyperdope` during provisioning while keeping `feat/ingglish-aq-corpus` free of third-party files so upstream PR diffs remain 100% clean. | **100% PR-Clean** (zero extraneous files added to upstream PR branch). | | **`/workspace/hyperdope-gematria`** | Consumes `@hyperstitionstud.io/ciphers-aq` in `calc/ciphers.js` on branch `feat/ingglish-priority-toggle`. | **Shared JS Cipher Parity** with Python `io.hyperstitionstud.ciphers`. | | **`/workspace/memes`** | Uses `io.hyperstitionstud.publishing.pokedex_compositor` for Gen IV INFO Pokedex cards and meme templates. | **Unified Card & Font Rendering** with automatic box-collision verification. | --- ## 6. Phased Implementation & Rollout Roadmap (`Phases 1–4`, Non-Breaking) ### Phase 1: Scaffold `/workspace/hyperstitionstudio-core` & Publish `v1` JSON Schemas 1. Initialize `/workspace/hyperstitionstudio-core` (`git init -b main`) with `pyproject.toml` (`name = "hyperstitionstudio-core"`, `version = "1.0.0"`) and `src/io/hyperstitionstud/`. 2. Author the 8 canonical JSON Schema files under `schemas/v1/*.schema.json` with `$id: "https://hyperstitionstud.io/schemas/v1/.schema.json"`. 3. Install in editable mode across the workspace environment (`pip install --no-deps -e /workspace/hyperstitionstudio-core`). ### Phase 2: Extract `ciphers`, `phonetics`, `glossary`, and `ci` Modules + Unit Test Suite 1. Implement `io.hyperstitionstud.ciphers`, `io.hyperstitionstud.phonetics` (with offline `cmudict_fallback.json`), `io.hyperstitionstud.glossary.isolation_guard`, and `io.hyperstitionstud.ci`. 2. Run `pytest /workspace/hyperstitionstudio-core/tests/` to verify 100% numerical parity on all `282` glossary entries, `190` bilingual specimens, and `189` cross-scale `333/666/777` equations. ### Phase 3: Extract `publishing` (`pdf_compiler`, `tier_list_renderer`, `pokedex_compositor`) & `graph` 1. Move the core ReportLab and Pillow rendering engines into `io.hyperstitionstud.publishing` and `io.hyperstitionstud.graph`. 2. Replace the bodies of `/workspace/ingglish-hyperdope-gematria/ingglish-aq-archive/scripts/build_wire_report_pdf.py` and `generate_aq_tier_list.py` with thin, backwards-compatible CLI shims that import from `io.hyperstitionstud.publishing`. ### Phase 4: Cut Over `technocapital-singularity-zoology` & `encyclopedia-knowledge-graph` and Run 3-Stage Audit 1. Update `classify_technocapital_singularity.py` and `build_encyclopedia_knowledge_graph.py` to import from `io.hyperstitionstud.*`. 2. Execute the full 3-Stage `BUILD -> TEST -> STAGE_COMMIT` pipeline (`ci_provision_ingglish.py --tier 2`, `sources.py verify --evidence`, and `build_encyclopedia_knowledge_graph.py --verify-only`), verifying `all_gates_passed == true` and `0` SHA-256 mutations on `glossary-registry.json` and `encyclopedia-manifest.json`.