18 KiB
PLAN: Piecewise Codebase Modularity, Deduplication & Resource Economization — Revised for v2.12.0..v2.15.0 Code Delta (Audit Points 1–4, Rule C Piecewise Specification)
Document ID: PLAN-PIECEWISE-CODEBASE-MODULARITY-DEFERRED-STRATEGIES
Status: PENDING AUDIT PIECEWISE (docs/plans/piecewise/ — 0/4 AUDIT POINTS AFFIRMED)
Parent Plan: PLAN-PIECEWISE-CODEBASE-MODULARITY-DEDUPLICATION-AND-RESOURCE-ECONOMIZATION (v2.12.0)
Target Ecosystem Version: v2.16.0 (Baseline: v2.15.0, evaluating full v2.12.0..v2.15.0 delta)
Target Repositories: hyperstitionstudio-core, ingglish-hyperdope-gematria, encyclopedia-knowledge-graph
Author: m00t & Hermes Agent
Date: 2026-12-01
1. Ground-Truth Audit: Reactivated Deferred Strategy 2A + v2.12.0..v2.15.0 Code Delta (+4,970 Lines Across 6 Repositories, Rule C.1)
Between v2.12.0 (when the parent Plan #53 was executed) and v2.15.0, implementing Plans #56, #57, #58, #59, and #60 added +4,970 insertions across 96 touched files (+1,500 in hyperstitionstudio-core, +2,090 in ingglish-hyperdope-gematria, +314 in haiperdohp-jemaytreeah, +971 in hyperdope-ci-build, and +220 in encyclopedia-knowledge-graph). Re-auditing the deferred strategy candidates alongside this exact v2.12.0..v2.15.0 code delta reveals 4 high-leverage modularity, deduplication, security, and resource-economization Audit Points:
| Audit Point & Subsystem | Empirically Verified v2.12.0..v2.15.0 Codebase Delta Measurement |
Duplication, Drift Risk, Security Gap or Resource Hotspot Identified |
|---|---|---|
| Audit Point 1 Unified Explication Hub, Subpage & Navigation Template Engine ( publishing/explication_template.py, engineering_docs.py 801 lines & math_docs.py 628 lines — Reactivated Strategy 2A from Plan #53) |
• In Plan #53 (v2.12.0), Strategy 2B unified render_polyglot_cartridge_html() and _render_prereq_box_html(), while deferring Strategy 2A (full explication_template.py extraction).• publishing/engineering_docs.py (801 lines) and publishing/math_docs.py (628 lines) still duplicate ~260 lines of identical <head> CSS, <header> layout, > 6 subpage More Units ▾ overflow <select>, .grid-cards unit card loops, <footer> colophon, prev_link / next_link subpage pagination, and build_*_site() bundle orchestration. |
• Eliminate ~260 Duplicate Lines & Enable Single-Point Cross-Page Nav Unification (Plan #63): Extracting src/hyperstitionstud_io/publishing/explication_template.py (render_explication_nav_html(), render_explication_hub_page_html(), render_explication_subpage_html(), write_explication_site_bundle()) removes ~260 duplicate lines and lets /engineering/* and /math/* share one header/subnav renderer. |
Audit Point 2 (NEW from v2.13.0–v2.15.0 Delta)Exegesis & CI Script Deduplication + safe_urlopen / compute_aq Reuse in ingglish-hyperdope-gematria (+2,090 lines added in v2.13.0–v2.15.0) |
• Plan #56 (v2.13.0) added synthesize_news_dossier_openrouter.py (736 lines) in two identical copies (ingglish-aq-archive/scripts/ and packaging/bundle/scripts/ = 1,472 lines).• Plan #60 ( v2.15.0) had to patch ci_provision_ingglish.py across three identical copies (ingglish-aq-archive/scripts/, packaging/bundle/scripts/, and packaging/bundle/skills/hyperdope-ingglish-ci/scripts/ = ~1,950 lines), plus duplicate copies of collect_news_aq.py, generate_aq_tier_list.py, and build_wire_report_pdf.py (~3,600+ duplicated lines in ingglish-hyperdope-gematria!).• synthesize_news_dossier_openrouter.py redefines compute_aq() locally (lines 39–46) and calls raw urllib.request.urlopen() instead of delegating to hyperstitionstud_io.ciphers.compute_aq and hyperstitionstud_io.security.safe_urlopen when available. |
• Eliminate ~2,100+ Lines of Multi-Copy Script Drift in ingglish-hyperdope-gematria: Keep ingglish-aq-archive/scripts/*.py as the Single Source of Truth, replace duplicate copies in packaging/bundle/scripts/ and packaging/bundle/skills/.../scripts/ with thin runpy delegators (while packaging/build-fedora41-rpm.sh materializes standalone copies into the RPM buildroot at package build time), and wire compute_aq + safe_urlopen delegation into synthesize_news_dossier_openrouter.py. |
Audit Point 3 (NEW from v2.14.0–v2.15.0 Delta)Pre-Commit & Release Pipeline Consolidation: Shared 6-Repo Discovery, Path Normalizer, Git Helper & Stat-Cached Line Counter ( config/__init__.py, deploy_scripts_sync.py 266 lines, version_sync.py 550 lines, readme_sync.py 616 lines, closeups_sync.py 765 lines) |
• Plan #58 (v2.14.0) added src/hyperstitionstud_io/ci/deploy_scripts_sync.py (266 lines) and wired it into .git/hooks/pre-commit (readme_sync.py) and version_sync.py.• Across version_sync.py, readme_sync.py, highlights.py, and deploy_scripts_sync.py, _norm_ws_path(), _resolve_repo_dir() (hyperdope-ci-build vs ingglish-hyperdope-ci), _git_out(), and the canonical 6-repo list are now duplicated in 4 modules.• Every git commit triggers .git/hooks/pre-commit (deploy_scripts_sync + closeups_sync + readme_sync), which scans all 231,615 lines (4.17 MB) of haiperdohp-jemaytreeah/db.txt from disk multiple times even when (st_mtime_ns, st_size) are unchanged. |
• Consolidate 4x Duplicated Repo/Git Helpers & Stat-Cache db.txt Line Counts: Centralizing 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() in src/hyperstitionstud_io/config/__init__.py removes 4 duplicate helper implementations and cuts repeated 4.17 MB db.txt line scans during pre-commit to 0. |
Audit Point 4 (NEW from v2.13.0–v2.15.0 Delta)Shared Bounded Pillow Text-Fitting Primitives ( publishing/fonts.py) & load_json_cached Reuse in publishing/quant_voice.py (511 lines) |
• Plan #57 & Plan #59 (v2.13.0–v2.15.0) added src/hyperstitionstud_io/publishing/quant_voice.py (511 lines), which reads voice-manifest.json via raw json.loads(manifest_p.read_text()) (line 336) instead of load_json_cached().• publishing/closeups_sync.py (765 lines), publishing/flow_diagram.py (401 lines), and quant/cards.py (550 lines) place text via manual d.text() coordinates and [:N] slicing without shared bounded text-fitting primitives in publishing/fonts.py (90 lines). |
• Unified Bounded Pillow Typography & Manifest Caching: Adding fit_pillow_text_to_width(), draw_bounded_box_text(), and draw_bounded_kv_row() to src/hyperstitionstud_io/publishing/fonts.py (directly supporting Plan #61's closeup bounding-box fixes) and wiring load_json_cached() into quant_voice.py unifies image text fitting and JSON caching across publishing/. |
2. Four Factual Binary Engineering Gates (G1–G4, Zero Synthetic Data & Two-Script Deployment Invariant)
Gate G1(100% Backward-Compatible Public API, CLI Entrypoints, RPM Builder & Two-Script Deployment Invariant): Zero breaking changes to anypyproject.tomlCLI entrypoint (hs-*), MCP tool, OpenAPI 3.1 REST endpoint,packaging/build-fedora41-rpm.sh, or the Two-Script Manual Operator Deployment Invariant.Gate G2(0LLM Tokens &0New External Dependencies): Uses Python3.12+standard library (runpy,functools,subprocess) and existing workspace libraries (Pillow).Gate G3(ProtectSystem=strictEROFS&ReadOnlyIsolationGuardSafe): All caches are in-memory and invalidated automatically on(st_mtime_ns, st_size)updates.Gate G4(Measurable Code Deduplication Across Bothhyperstitionstudio-core&ingglish-hyperdope-gematria): Eliminates~260duplicate HTML template lines inpublishing/,~2,100+duplicate Python script lines iningglish-hyperdope-gematria/packaging/bundle/, and4duplicate Git/repo helper blocks.
3. Piecewise Audit Points & Candidate Strategies (Strategies 1A–1C through 4A–4C, Rule C.2)
Each Audit Point below is 100% independent and commutative so they can be reviewed, affirmed, or deferred one at a time under the strict Turn-Ending Invariant (Rule C.3).
Audit Point 1: Unified Explication Hub, Subpage & Navigation Template Engine (src/hyperstitionstud_io/publishing/explication_template.py — Reactivated Strategy 2A)
- Strategy
1A(Extract Shared Group 3 Explication Page Renderer intosrc/hyperstitionstud_io/publishing/explication_template.py— Recommended Candidate):- What Changes:
- Creates
src/hyperstitionstud_io/publishing/explication_template.pycontaining the parameterized Group 3 HTML builders and site-bundle writer shared by/engineering/and/math/:render_explication_nav_html(),render_explication_hub_page_html(),render_explication_subpage_html(), andwrite_explication_site_bundle().
- Refactors
publishing/engineering_docs.py(hs-eng-docs) andpublishing/math_docs.py(hs-math-docs) to delegate their HTML/nav/bundle rendering toexplication_template.pywhile keeping all domain specifications, cartridges, manifests, and public function signatures 100% intact.
- Creates
- Modularity Gain: Eliminates
~260lines of duplicated HTML/CSS/JS templates and provides a single shared header/navigation builder for/engineering/*and/math/*.
- What Changes:
- Strategy
1B(Extract Onlyrender_explication_nav_html()&render_explication_subpage_html(), Keeping Hub Renderers Separate — Partial Candidate):- Unifies navigation and subpage HTML templates while leaving
_render_hub_html()and_render_math_hub_html()separate.
- Unifies navigation and subpage HTML templates while leaving
- Strategy
1C(Retain Currentv2.12.0Strategy2BSplit — Status Quo / Deferred):- Keeps only
render_polyglot_cartridge_html()and_render_prereq_box_html()shared.
- Keeps only
Audit Point 2 (NEW from v2.13.0–v2.15.0 Delta): Exegesis & CI Script Deduplication + safe_urlopen / compute_aq Delegation in ingglish-hyperdope-gematria
- Strategy
2A(Single-Source-of-Truth Scripts iningglish-aq-archive/scripts/+ ThinrunpyBundle Wrappers + Automatic Standalone Copy Materialization inbuild-fedora41-rpm.sh+compute_aq/safe_urlopenDelegation — Recommended Candidate):- What Changes:
- Designates
ingglish-aq-archive/scripts/{synthesize_news_dossier_openrouter.py,ci_provision_ingglish.py,collect_news_aq.py,generate_aq_tier_list.py,build_wire_report_pdf.py}as the Single Source of Truth iningglish-hyperdope-gematria. - Replaces the duplicate multi-hundred-line copies in
packaging/bundle/scripts/*.pyandpackaging/bundle/skills/hyperdope-ingglish-ci/scripts/ci_provision_ingglish.pywith compact (~25-line) self-locatingrunpy.run_path/importlibdelegators that resolve the canonical script iningglish-aq-archive/scripts/when run from the repo, while updatingpackaging/build-fedora41-rpm.shto copy the canonicalingglish-aq-archive/scripts/*.pyfiles directly into the RPMSOURCESbundle at package build time so the installed Fedora 41 RPM (/usr/libexec/ingglish-exegesis/scripts/*.py) remains 100% standalone. - Updates
synthesize_news_dossier_openrouter.pyto delegatecompute_aq()tohyperstitionstud_io.ciphers.compute_aqand HTTP requests incall_openrouter_exegesis()tohyperstitionstud_io.security.safe_urlopenwheneverhyperstitionstud_iois importable (retaining the stdlib fallback for standalone Fedora 41 RPM hosts).
- Designates
- Modularity & Security Gain: Eliminates
~2,100+lines of duplicate Python code acrossingglish-hyperdope-gematria, prevents multi-copy drift across future edits, and extendssafe_urlopenSSRF/size-cap protection tosynthesize_news_dossier_openrouter.py.
- What Changes:
- Strategy
2B(Keep Full Copies on Disk, Add Auto-Sync Step todeploy_scripts_sync.py+compute_aq/safe_urlopenDelegation Only — Partial Candidate):- Keeps duplicate files in Git but synchronizes them automatically in
deploy_scripts_sync.pybefore commits.
- Keeps duplicate files in Git but synchronizes them automatically in
- Strategy
2C(Leave Multi-Copy Scripts iningglish-hyperdope-gematriaUnchanged — Status Quo / Deferred):- Retains the current manual multi-copy layout.
Audit Point 3 (NEW from v2.14.0–v2.15.0 Delta): Pre-Commit & Release Pipeline Consolidation — Shared 6-Repo Discovery, Path Normalizer, Git Helper & Stat-Cached Line Counter (src/hyperstitionstud_io/config/__init__.py)
- Strategy
3A(CentralizeCANONICAL_SIX_REPOS,resolve_workspace_repo_dir(),normalize_workspace_relpath(),run_git_stdout(), and Stat-Memoizedcount_file_lines_cached()insrc/hyperstitionstud_io/config/__init__.py— Recommended Candidate):- What Changes:
- Adds
CANONICAL_SIX_REPOS,resolve_workspace_repo_dir(ws_root, repo_key),normalize_workspace_relpath(p, workspace_root=None),run_git_stdout(repo_dir, args, *, strip_leading=True, timeout=5.0), and(resolved_path, st_mtime_ns, st_size)-memoizedcount_file_lines_cached(path)tosrc/hyperstitionstud_io/config/__init__.py. - Refactors
version_sync.py,publishing/readme_sync.py,publishing/highlights.py,ci/deploy_scripts_sync.py, andpublishing/closeups_sync.pyto import and use these shared helpers instead of maintaining4separate copies of_git_out/_resolve_repo_dir/_norm_ws_pathand re-scanning231,615lines ofdb.txton every commit hook.
- Adds
- Modularity & Resource Gain: Eliminates
4duplicate Git/repo/path helper blocks and cuts repeated4.17 MBdb.txtline-count scans duringpre-commithooks to0.
- What Changes:
- Strategy
3B(Add Stat-Memoizedcount_file_lines_cached()Only — Minimal Candidate):- Caches line counts by
(resolved_path, st_mtime_ns, st_size)inconfig/__init__.pywithout consolidating_git_out,_resolve_repo_dir, and_norm_ws_path.
- Caches line counts by
- Strategy
3C(Keep Separate Helpers & Uncached Line Scans — Status Quo / Deferred):- Leaves
config/__init__.py,version_sync.py,readme_sync.py,highlights.py,deploy_scripts_sync.py, andcloseups_sync.pyunchanged.
- Leaves
Audit Point 4 (NEW from v2.13.0–v2.15.0 Delta): Shared Bounded Pillow Text-Fitting Primitives (publishing/fonts.py) & load_json_cached Reuse in publishing/quant_voice.py
- Strategy
4A(Addfit_pillow_text_to_width(),draw_bounded_box_text(), anddraw_bounded_kv_row()tosrc/hyperstitionstud_io/publishing/fonts.py+ Wireload_json_cached()intopublishing/quant_voice.py— Recommended Candidate):- What Changes:
- Extends
src/hyperstitionstud_io/publishing/fonts.pywith reusable, zero-truncation Pillow text-layout helpers (fit_pillow_text_to_width(),draw_bounded_box_text(), anddraw_bounded_kv_row()) that step down the cached DejaVu font ladder (14px -> 9px) so text always fits inside its bounding box with>= 6pxhorizontal padding and0mid-word[:N]slicing. - Reuses these shared primitives in
publishing/closeups_sync.py(directly powering Plan #61's bounding-box remediation) and wiresload_json_cached()intopublishing/quant_voice.pywhen readingvoice-manifest.json.
- Extends
- Modularity Gain: Centralizes bounded Pillow typography in
publishing/fonts.pyand bringsquant_voice.pyinto full compliance with theload_json_cached()pattern established inv2.12.0.
- What Changes:
- Strategy
4B(Keep Bounded Text Helpers Local Insidepublishing/closeups_sync.pyOnly — Partial Candidate):- Implements text-fitting helpers privately inside
closeups_sync.pywithout promoting them topublishing/fonts.py.
- Implements text-fitting helpers privately inside
- Strategy
4C(Manual Per-Call Coordinate Adjustments Only — Status Quo / Deferred):- Adjusts individual
(x, y)coordinates manually without shared bounded-text primitives.
- Adjusts individual
4. Summary Matrix of Audit Points 1–4 for Stepwise Review (Rule C.3)
| Audit Point | Target Subsystem (v2.12.0..v2.15.0 Delta) |
Strategy A (Full Modularity, Deduplication & Resource Economization — Recommended) |
Strategy B (Partial / Scoped Change) |
Strategy C (Status Quo / Deferred) |
|---|---|---|---|---|
| Point 1 | Explication HTML Template Engine (publishing/explication_template.py, engineering_docs.py, math_docs.py) |
1A: Extract shared Group 3 nav, hub, subpage & bundle builders into explication_template.py (-260 duplicate lines) |
1B: Extract shared nav & subpage HTML builders only, keeping hub HTML builders separate |
1C: Retain v2.12.0 2B split |
| Point 2 | Exegesis & CI Script Deduplication + Security (ingglish-hyperdope-gematria/packaging/bundle/ & synthesize_news_dossier_openrouter.py) |
2A: Single Source of Truth in ingglish-aq-archive/scripts/ + thin runpy bundle wrappers (-2,100+ duplicate lines) + standalone copy materialization in build-fedora41-rpm.sh + compute_aq/safe_urlopen delegation |
2B: Keep duplicate files in Git, auto-sync in deploy_scripts_sync.py + compute_aq/safe_urlopen delegation |
2C: Keep manual multi-copy scripts |
| Point 3 | Pre-Commit & Release Pipeline Consolidation (config/__init__.py, deploy_scripts_sync.py, version_sync.py, readme_sync.py, closeups_sync.py) |
3A: Centralize CANONICAL_SIX_REPOS, resolve_workspace_repo_dir(), normalize_workspace_relpath(), run_git_stdout(), & stat-cached count_file_lines_cached() in config/__init__.py |
3B: Add stat-cached count_file_lines_cached() only |
3C: Keep 4 separate copies & uncached scans |
| Point 4 | Bounded Pillow Text-Fitting Primitives & Voice Manifest Cache (publishing/fonts.py, closeups_sync.py, quant_voice.py) |
4A: Add fit_pillow_text_to_width(), draw_bounded_box_text(), & draw_bounded_kv_row() to publishing/fonts.py + wire load_json_cached() into quant_voice.py |
4B: Keep bounded text helpers private inside closeups_sync.py |
4C: Manual coordinate tweaks only |