# PLAN: Ecosystem-Wide Efficiency, Deduplication, Optimization & Simplification (`Audit Points 1–6` Affirmed, `Rule C` Piecewise Specification) **Document ID:** `PLAN-PIECEWISE-CODEBASE-MODULARITY-DEFERRED-STRATEGIES` **Status:** `ACTIVE / FULLY AFFIRMED PIECEWISE (docs/plans/piecewise/ — 6/6 AUDIT POINTS AFFIRMED: 1A, 2A, 3A, 4A, 5A, 6A)` **Companion Deferred Strategies Plan:** `docs/plans/inactive/PLAN-PIECEWISE-CODEBASE-MODULARITY-DEFERRED-CANDIDATE-STRATEGIES.md` **Parent Plan:** `PLAN-PIECEWISE-CODEBASE-MODULARITY-DEDUPLICATION-AND-RESOURCE-ECONOMIZATION` (`v2.12.0`) **Target Ecosystem Version:** `v2.18.0` (Baseline: `v2.17.0` + working tree) **Target Repositories:** All `6` repositories (`hyperstitionstudio-core`, `ingglish-hyperdope-gematria`, `technocapital-singularity-zoology`, `encyclopedia-knowledge-graph`, `haiperdohp-jemaytreeah`, `hyperdope-ci-build`) **Author:** m00t & Hermes Agent **Date:** 2026-12-01 --- ## 1. Fixed Architectural Constraints & Four Binary Gates (`PLAN-GATE-G01..G04`) - **Fixed Constraint 1 (6-Repo Separation):** Keep all `6` peer Git repositories distinct. - **Fixed Constraint 2 (`task-router` Disciplinary Separation):** Keep Tier 1 deterministic zero-token code cleanly partitioned by domain (`phonetics/`, `ciphers/` + `ipld/` + `lenses/`, `quant/`, `graph/`, `publishing/`, `ci/`, `mcp/`, `db/`) and preserve `haiperdohp-jemaytreeah` upstream patch compatibility. - **Fixed Constraint 3 (Zero Broken Functionality):** Preserve all `20` `hs-*` CLI entrypoints, `20` MCP/OpenAPI 3.1 tools, `63` Caddy routes, Fedora 41 RPM (`ingglish-isopsephic-exegesis`), `ReadOnlyIsolationGuard` SHA-256 locks, and `tests/test_core_suite.py` (`7/7` suites). - **Binary Gates:** `PLAN-GATE-G01.EXTANT_DATA`, `PLAN-GATE-G02.ZERO_LLM`, `PLAN-GATE-G03.EROFS_SAFE`, `PLAN-GATE-G04.EXPORTABLE`. --- ## 2. Affirmed Deliverables Across Audit Points `1–6` (`Rule C.4`) ### Audit Point 1 — `[AFFIRMED: Strategy 1A]` Explication HTML/Nav/Subpage Template Engine (`publishing/explication_template.py`) - Create `src/hyperstitionstud_io/publishing/explication_template.py` (`render_explication_nav_html()`, `render_explication_hub_page_html()`, `render_explication_subpage_html()`, `write_explication_site_bundle()`) and refactor `engineering_docs.py` (`841` lines) and `math_docs.py` (`650` lines) to delegate their shared Group 3 (`UI-G03.BASALT_CHAMFER`) HTML/nav/subpage/bundle rendering while keeping all domain specs, cartridges, manifests, and public signatures 100% intact (`~-290` duplicate lines). ### Audit Point 2 — `[AFFIRMED: Strategy 2A]` Cross-Repo Script, Wrapper, Media & Quant Split Deduplication 1. **Script Single Source of Truth + Clean RPM Staging:** Keep `ingglish-aq-archive/scripts/*` canonical; replace the `9` mirrored copies (`~4,128` lines) in `packaging/bundle/scripts/` and `packaging/bundle/skills/*/scripts/` with ~25-line self-locating `runpy`/JS wrappers; update `build-fedora41-rpm.sh` to copy canonical scripts directly into `${STAGE_TOP}/SOURCES/` (so tracked wrappers never get overwritten dirty on RPM builds); update `test_core_suite.py` (`L1331–1335`) to assert wrapper delegation + canonical script integrity; delegate `compute_aq()` & `safe_urlopen()` in `synthesize_news_dossier_openrouter.py` when `hyperstitionstud_io` is importable. 2. **Cross-Repo Media & Disabled Demo Cleanup (`-83.9 MB`):** Remove the `5` byte-identical `lecture-podcast-ep01..05-*-ingglish-aq.{mp3,md}` duplicates (`83.14 MB`) from `ingglish-hyperdope-gematria` (canonical home: `technocapital-singularity-zoology/podcast-ep01..05-*`) and prune duplicate `meme_2_memegen_awkward_moment_seal_id_ams.png` (`747 KB`) from disabled `site/gallery/media/demos/`. 3. **Disciplinary Quant Consolidation (`site/quant/`):** Move `financial-aq-harvest-latest.json` and `daily-brief-state.json` from `ingglish-hyperdope-gematria/` into `hyperstitionstudio-core/site/quant/` (updating `collector.py`, `daily_brief.py`, `readme_sync.py`, `tests/test_core_suite.py`) and retire the redundant 20-line `collect_financial_quant_aq.py` shim (`hs-quant-harvest` is canonical), keeping `/archive/` Caddy routes (`25..73-dossier-news-*.md` & `10..19-ledger-*.md`) intact. ### Audit Point 3 — `[AFFIRMED: Strategy 3A]` Shared Workspace Helpers, Stat Line Cache & Read-Only JSON Fast-Path (`config/__init__.py`) - Add `CANONICAL_SIX_REPOS`, `resolve_workspace_repo_dir()`, `normalize_workspace_relpath()`, `run_git_stdout()`, and `(resolved_path, st_mtime_ns, st_size)`-memoized `count_file_lines_cached()` to `config/__init__.py`; remove duplicate `_norm_ws_path` (`deploy_scripts_sync.py`, `archive_rotator.py`), `_git_out`/`_git_run` (`readme_sync.py`, `version_sync.py`), and uncached `db.txt` scans (`archive_rotator.py`, `closeups_sync.py`); audit read-only `load_json_cached()` callers to pass `copy_result=False` (eliminating `1.5 MB` `deepcopy` overhead). ### Audit Point 4 — `[AFFIRMED: Strategy 4A]` Eliminate `25+` Uncached JSON Reads & Per-Font `rglob` Walks (`core/src`) - Replace repeated `json.loads(p.read_text())` reads across `math_docs.py` (x5), `quant/timeseries.py` (x2), `quant/daily_brief.py`, `quant/macro.py`, `quant/collector.py`, `db/sqlite_meta.py`, `publishing/quant_voice.py` (`L396`), `publishing/highlights.py` (`L47`), `publishing/closeups_sync.py`, `ci/doctor.py`, `ci/citation_sources.py`, `ci/public_regression.py`, and `mcp/tools.py` with `load_json_cached(..., copy_result=False)`, and replace per-font `/usr/share/fonts` `rglob` calls in `publishing/fonts.py` with a single `@lru_cache` font-filename index map. ### Audit Point 5 — `[AFFIRMED: Strategy 5A]` Bounded Pillow Typography (`publishing/fonts.py`) & Zero-Churn `flow_diagram.py` Digest Skip - Promote `fit_pillow_text_to_width()`, `draw_bounded_box_text()`, and `draw_bounded_kv_row()` out of `closeups_sync.py` (`1,021` lines) into `publishing/fonts.py`, reuse them across `closeups_sync.py`, `flow_diagram.py`, and `quant/cards.py` (`verify_closeup_geometry()` invariants 100% preserved), and embed a deterministic `hs_diagram_sha256` PNG `tEXt` chunk in `flow_diagram.py` so `render_periodic_harvest_cicd_flow_diagram_png(if_changed=True)` skips rewriting the `285 KB` PNG when inputs and version are unchanged. ### Audit Point 6 — `[AFFIRMED: Strategy 6A]` Path-Aware `.git/hooks/pre-commit` & Push Deduplication (`push-all-to-git-libre-audio.sh`, `readme_sync.py`) - Update `PRE_COMMIT_HOOK_SCRIPT` in `readme_sync.py` so `closeups_sync` and `deploy_scripts_sync` only run when staged files affect their respective surfaces (falling back cleanly to `--check` or skipping irrelevant repos), and remove duplicate pre-test subprocess calls in `push-all-to-git-libre-audio.sh` that `tests/test_core_suite.py` already enforces in-process (keeping `version_sync --corpus-delta`, `build-fedora41-rpm.sh`, `run_exegesis_and_push_fedora41.sh --dry-run`, `test_core_suite.py`, and `build_encyclopedia_knowledge_graph.py --verify-only`).