Release v2.12.0: Implement single-layer compression enforcement, 256KB plan archive cap with git.libre.audio citations, cold-archived inactive plans, codebase modularity/security/economization (Strategies 1A/2B/3A/4A/5A/6A/7A), and /quant/ spoken voice narration & #lensSelect UI element indicators (Strategies 1B/2A/3A/4A)
This commit is contained in:
1 parent
cc73a57bd8
commit
a066a0d03d
69 files changed
+2334
-619
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -20,29 +20,34 @@ import re
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from hyperstitionstud_io import __version__ as CURRENT_VERSION
|
||||
from hyperstitionstud_io.config import load_workspace_config
|
||||
from hyperstitionstud_io.config import load_json_cached, load_workspace_config
|
||||
from hyperstitionstud_io.glossary import ReadOnlyIsolationGuard
|
||||
from hyperstitionstud_io.ipld import compute_dag_json_cidv1
|
||||
from hyperstitionstud_io.publishing.fonts import (
|
||||
GROUP3_PALETTE,
|
||||
draw_group3_chamfered_plate,
|
||||
load_pillow_font,
|
||||
)
|
||||
|
||||
FONT_SANS = "/usr/share/fonts/google-noto/NotoSans-Regular.ttf"
|
||||
FONT_BOLD = "/usr/share/fonts/google-noto/NotoSans-Bold.ttf"
|
||||
FONT_MONO = "/usr/share/fonts/dejavu-sans-mono-fonts/DejaVuSansMono.ttf"
|
||||
FONT_MONO_B = "/usr/share/fonts/dejavu-sans-mono-fonts/DejaVuSansMono-Bold.ttf"
|
||||
FONT_SANS = "DejaVuSans.ttf"
|
||||
FONT_BOLD = "DejaVuSans-Bold.ttf"
|
||||
FONT_MONO = "DejaVuSansMono.ttf"
|
||||
FONT_MONO_B = "DejaVuSansMono-Bold.ttf"
|
||||
|
||||
VOID = (7, 9, 13)
|
||||
PLATE = (12, 16, 23)
|
||||
WELL = (18, 24, 34)
|
||||
BORDER = (30, 41, 59)
|
||||
TEXT = (241, 245, 249)
|
||||
MUTED = (148, 163, 184)
|
||||
CYAN = (56, 189, 248)
|
||||
VOID = GROUP3_PALETTE["BG_VOID"]
|
||||
PLATE = GROUP3_PALETTE["BG_ODD"]
|
||||
WELL = GROUP3_PALETTE["BG_EVEN"]
|
||||
BORDER = GROUP3_PALETTE["BORDER_MUTED"]
|
||||
TEXT = GROUP3_PALETTE["TXT_PRI"]
|
||||
MUTED = GROUP3_PALETTE["TXT_SEC"]
|
||||
CYAN = GROUP3_PALETTE["CYAN"]
|
||||
GOLD = (245, 198, 48)
|
||||
EMERALD = (52, 211, 153)
|
||||
ROSE = (251, 113, 133)
|
||||
VIOLET = (167, 139, 250)
|
||||
EMERALD = GROUP3_PALETTE["EMERALD"]
|
||||
ROSE = GROUP3_PALETTE["ROSE"]
|
||||
VIOLET = GROUP3_PALETTE["VIOLET"]
|
||||
|
||||
ALL_CLOSEUP_FILENAMES: tuple[str, ...] = (
|
||||
"quadrant-1-cybermemetics-calc-graph.png",
|
||||
@@ -60,10 +65,35 @@ ALL_CLOSEUP_FILENAMES: tuple[str, ...] = (
|
||||
|
||||
|
||||
def _fnt(path: str, size: int) -> Any:
|
||||
try:
|
||||
return ImageFont.truetype(path, size)
|
||||
except Exception:
|
||||
return ImageFont.load_default()
|
||||
return load_pillow_font(path, size)
|
||||
|
||||
|
||||
def _extract_js_ui_signature(js_text: str) -> dict[str, Any]:
|
||||
"""
|
||||
Strategy 4A (Plan #51): Introspect companion `.js` files (`quant-app.js`, `quant-tutorials.js`,
|
||||
`learn-app.js`, `hs-guile-scheme-repl.js`) for dynamic DOM IDs, episode/scene definitions,
|
||||
highlightable UI targets, and control labels.
|
||||
"""
|
||||
clean = re.sub(r"\bv\d+\.\d+\.\d+\b", "vX.Y.Z", js_text)
|
||||
dom_ids = sorted(set(re.findall(r'getElementById\(\s*["\']([^"\']+)["\']\s*\)', clean)))
|
||||
ui_targets = sorted(set(re.findall(r'uiTargets:\s*\[([^\]]+)\]', clean)))
|
||||
ep_codes = re.findall(r'code:\s*["\'](Ep\s*\d+)["\']', clean)
|
||||
speech_texts = re.findall(r'speechText:\s*["\']([^"\']+)["\']', clean)
|
||||
lens_keys = sorted(set(re.findall(r'selectedLens:\s*["\']([^"\']+)["\']', clean)))
|
||||
payload = {
|
||||
"dom_ids": dom_ids,
|
||||
"ui_targets": ui_targets,
|
||||
"ep_codes": ep_codes,
|
||||
"speech_text_count": len(speech_texts),
|
||||
"lens_keys": lens_keys,
|
||||
"has_ui_indicator_badge": "tutUiElementIndicator" in clean,
|
||||
"has_lens_select_highlight": '"lensSelect"' in clean,
|
||||
}
|
||||
digest = hashlib.sha256(json.dumps(payload, sort_keys=True, ensure_ascii=False).encode("utf-8")).hexdigest()
|
||||
return {
|
||||
"js_ui_sha256": digest,
|
||||
**payload,
|
||||
}
|
||||
|
||||
|
||||
def _extract_dom_signature(html_text: str) -> dict[str, Any]:
|
||||
@@ -127,22 +157,33 @@ def introspect_live_ui_elements(workspace_root: str | Path | None = None) -> dic
|
||||
if p.is_file():
|
||||
surface_sigs[k] = _extract_dom_signature(p.read_text(encoding="utf-8"))
|
||||
|
||||
js_surfaces: dict[str, Path] = {
|
||||
"quant_app_js": core / "site" / "quant" / "quant-app.js",
|
||||
"quant_tutorials_js": core / "site" / "quant" / "quant-tutorials.js",
|
||||
"learn_app_js": core / "site" / "learn" / "learn-app.js",
|
||||
"polyglot_repl_js": core / "site" / "assets" / "hs-guile-scheme-repl.js",
|
||||
}
|
||||
js_sigs: dict[str, Any] = {}
|
||||
for jk, jp in js_surfaces.items():
|
||||
if jp.is_file():
|
||||
js_sigs[jk] = _extract_js_ui_signature(jp.read_text(encoding="utf-8"))
|
||||
|
||||
# Live data counts from registries
|
||||
ts_p = core / "site" / "quant" / "quant-timeseries.json"
|
||||
ts_obj = json.loads(ts_p.read_text(encoding="utf-8")) if ts_p.is_file() else {}
|
||||
ts_obj = load_json_cached(ts_p, copy_result=False) if ts_p.is_file() else {}
|
||||
total_bars = sum(
|
||||
sum(1 for b in (inst.get("bars") or []) if b.get("data_available"))
|
||||
for inst in (ts_obj.get("instruments") or [])
|
||||
)
|
||||
brf_p = core / "site" / "quant" / "daily-brief-latest.json"
|
||||
brf_obj = json.loads(brf_p.read_text(encoding="utf-8")) if brf_p.is_file() else {}
|
||||
brf_obj = load_json_cached(brf_p, copy_result=False) if brf_p.is_file() else {}
|
||||
post_probs = (
|
||||
((brf_obj.get("agenda_1_executive_summary") or {}).get("bayesian_regime_inference") or {}).get("posterior_probabilities")
|
||||
or {"R1_BULL_EXPANSION": 0.24, "R2_PINNED_ISOMETRIC": 0.61, "R3_TAIL_DRAWDOWN_RISK_OFF": 0.15}
|
||||
)
|
||||
|
||||
eng_p = core / "site" / "engineering" / "engineering-manifest.json"
|
||||
eng_obj = json.loads(eng_p.read_text(encoding="utf-8")) if eng_p.is_file() else {}
|
||||
eng_obj = load_json_cached(eng_p, copy_result=False) if eng_p.is_file() else {}
|
||||
eng_counts = eng_obj.get("introspected_counts") or {
|
||||
"repositories": 6,
|
||||
"cli_entrypoints": 17,
|
||||
@@ -161,12 +202,13 @@ def introspect_live_ui_elements(workspace_root: str | Path | None = None) -> dic
|
||||
db_entries_count = sum(1 for _ in db_txt_p.open(encoding="utf-8")) if db_txt_p.is_file() else 231615
|
||||
|
||||
ci_rep_p = ci_dir / "ci-audit-report.json"
|
||||
ci_obj = json.loads(ci_rep_p.read_text(encoding="utf-8")) if ci_rep_p.is_file() else {}
|
||||
ci_obj = load_json_cached(ci_rep_p, copy_result=False) if ci_rep_p.is_file() else {}
|
||||
|
||||
combined_hash = hashlib.sha256(
|
||||
json.dumps(
|
||||
{
|
||||
"surfaces": {k: v["ui_structure_sha256"] for k, v in sorted(surface_sigs.items())},
|
||||
"js_surfaces": {k: v["js_ui_sha256"] for k, v in sorted(js_sigs.items())},
|
||||
"total_bars": total_bars,
|
||||
"db_entries_count": db_entries_count,
|
||||
"mcp_tools": eng_counts.get("mcp_tools", 20),
|
||||
@@ -188,6 +230,7 @@ def introspect_live_ui_elements(workspace_root: str | Path | None = None) -> dic
|
||||
"ci_keep_rate_pct": ci_obj.get("keep_rate_pct", 100.0),
|
||||
},
|
||||
"surfaces": surface_sigs,
|
||||
"js_surfaces": js_sigs,
|
||||
}
|
||||
manifest["ipld_dag_json_cidv1"] = {"/": compute_dag_json_cidv1(manifest)}
|
||||
return manifest
|
||||
@@ -211,11 +254,8 @@ def _draw_chamfer_box(
|
||||
chamfer: int = 8,
|
||||
pip: tuple[int, int, int] | None = None,
|
||||
) -> None:
|
||||
x0, y0, x1, y1 = box
|
||||
pts = [(x0, y0), (x1 - chamfer, y0), (x1, y0 + chamfer), (x1, y1), (x0, y1)]
|
||||
d.polygon(pts, fill=fill, outline=outline)
|
||||
if pip:
|
||||
d.rectangle([x0, y0, x0 + 3, y1], fill=pip)
|
||||
_ = chamfer
|
||||
draw_group3_chamfered_plate(d, box, fill=fill, attention_color=outline, pip_color=pip)
|
||||
|
||||
|
||||
def render_all_quadrant_closeups(
|
||||
@@ -277,10 +317,15 @@ def render_all_quadrant_closeups(
|
||||
eng_c = metrics["engineering_counts"]
|
||||
surfaces = live_manifest["surfaces"]
|
||||
|
||||
# Detect live controls on /graph/, /quant/, /learn/, /engineering/
|
||||
# Detect live controls on /graph/, /quant/, /learn/, /engineering/ (HTML + JS)
|
||||
quant_ids = set(surfaces.get("quant", {}).get("ids") or [])
|
||||
quant_tut_js = (live_manifest.get("js_surfaces") or {}).get("quant_tutorials_js") or {}
|
||||
graph_has_min_deg = "minDegreeFilter" in (surfaces.get("graph", {}).get("ids") or [])
|
||||
quant_has_window = "timeWindowPills" in (surfaces.get("quant", {}).get("ids") or [])
|
||||
quant_has_quick_filter = "tickerQuickFilter" in (surfaces.get("quant", {}).get("ids") or [])
|
||||
quant_has_window = "timeWindowPills" in quant_ids
|
||||
quant_has_quick_filter = "tickerQuickFilter" in quant_ids
|
||||
quant_has_speech_btn = "tutSpeechBtn" in quant_ids
|
||||
quant_has_lens_select = "lensSelect" in quant_ids
|
||||
quant_has_ui_indicator = bool(quant_tut_js.get("has_ui_indicator_badge") or ("tutUiElementIndicator" in quant_ids))
|
||||
learn_has_seal_ribbon = "grimoireSealRibbon" in (surfaces.get("learn", {}).get("ids") or [])
|
||||
learn_has_sigil_svg = "grimoireSigilSvg" in (surfaces.get("learn", {}).get("ids") or [])
|
||||
eng_has_cli_filter = "engCliFilterInput" in (surfaces.get("engineering_hub", {}).get("ids") or [])
|
||||
@@ -369,14 +414,15 @@ def render_all_quadrant_closeups(
|
||||
d.text((466, ly + 3), lv[:26], font=f_mono_xs, fill=TEXT)
|
||||
im.save(out_dir / "quadrant-1-tab-2-graph.png", "PNG")
|
||||
|
||||
# 3. Quadrant 02 Tab 1: Panel 1 Trajectory & Dose
|
||||
# 3. Quadrant 02 Tab 1: Panel 1 Trajectory & Dose (dynamically reflects #tutSpeechBtn, #timeWindowPills, #tickerQuickFilter)
|
||||
im, d = _new_canvas()
|
||||
_draw_chamfer_box(d, (10, 10, 670, 250), PLATE, BORDER, chamfer=10, pip=GOLD)
|
||||
d.text((24, 18), "PANEL 1: Synchronized 2-Pane Trajectory & Dose D ∈ {0..4}", font=f_hdr, fill=GOLD)
|
||||
win_badge = "[30D|90D|ALL] • " if quant_has_window else ""
|
||||
flt_badge = "QuickFilter • " if quant_has_quick_filter else ""
|
||||
d.rectangle([416, 16, 656, 36], fill=WELL, outline=GOLD)
|
||||
d.text((424, 19), f"{win_badge}{flt_badge}NVDA (S3)", font=f_mono_xs, fill=GOLD)
|
||||
win_badge = "[30D|90D|ALL]•" if quant_has_window else ""
|
||||
flt_badge = "Filter•" if quant_has_quick_filter else ""
|
||||
vox_badge = "🔊Voice:ON•" if quant_has_speech_btn else ""
|
||||
d.rectangle([388, 16, 656, 36], fill=WELL, outline=GOLD)
|
||||
d.text((394, 19), f"{vox_badge}{win_badge}{flt_badge}NVDA", font=f_mono_xs, fill=GOLD)
|
||||
d.rectangle([24, 42, 656, 168], fill=WELL, outline=BORDER)
|
||||
d.line([(36, 114), (644, 114)], fill=(180, 50, 70), width=1)
|
||||
d.text((42, 96), "Entity Threshold: envideea = 137", font=f_mono_xs, fill=ROSE)
|
||||
@@ -439,10 +485,14 @@ def render_all_quadrant_closeups(
|
||||
d.text((568, fy + 5), fn[:11], font=f_mono_xs, fill=EMERALD)
|
||||
im.save(out_dir / "quadrant-2-tab-2-bayesian-fred.png", "PNG")
|
||||
|
||||
# 5. Quadrant 02 Tab 3: Panel 2 6-Lens Leaderboard & TCG Card
|
||||
# 5. Quadrant 02 Tab 3: Panel 2 6-Lens Leaderboard & TCG Card (dynamically reflects #lensSelect & UI indicator badge)
|
||||
im, d = _new_canvas()
|
||||
_draw_chamfer_box(d, (10, 10, 670, 250), PLATE, BORDER, chamfer=10, pip=GOLD)
|
||||
d.text((24, 18), "PANEL 2 & 3: 6-Lens Assemblage Leaderboard & One-Shot TCG Stats Card", font=f_hdr, fill=GOLD)
|
||||
hdr_q2_t3 = "PANEL 2 & 3: #lensSelect 6-Lens Leaderboard & TCG Card" if quant_has_lens_select else "PANEL 2 & 3: 6-Lens Assemblage Leaderboard & One-Shot TCG Stats Card"
|
||||
d.text((24, 18), hdr_q2_t3, font=f_hdr, fill=GOLD)
|
||||
if quant_has_ui_indicator:
|
||||
d.rectangle([476, 15, 656, 35], fill=WELL, outline=GOLD)
|
||||
d.text((482, 18), "▼ UI: #lensSelect", font=f_mono_xs, fill=GOLD)
|
||||
_draw_chamfer_box(d, (24, 42, 416, 240), WELL, GOLD, chamfer=8, pip=GOLD)
|
||||
lenses = ["[Fund Mgr]", "[TierZoo]", "[Board]", "[Sabermetric]"]
|
||||
for li, ltxt in enumerate(lenses):
|
||||
@@ -694,7 +744,7 @@ def render_all_quadrant_closeups(
|
||||
"ui_elements_fingerprint_sha256": live_manifest["ui_elements_fingerprint_sha256"],
|
||||
"cidv1": live_manifest["ipld_dag_json_cidv1"]["/"],
|
||||
"closeup_count": len(ALL_CLOSEUP_FILENAMES),
|
||||
"isolation_receipt": guard.verification_receipt(),
|
||||
"isolation_receipt": guard.audit_receipt(),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -112,17 +112,19 @@ def _render_polyglot_selector_html() -> str:
|
||||
)
|
||||
|
||||
|
||||
def _render_guile_cartridge_html(key: str) -> str:
|
||||
def render_polyglot_cartridge_html(
|
||||
cartridge: dict[str, str],
|
||||
spec_label: str = "1. Formal Specification & Python:",
|
||||
) -> str:
|
||||
import html
|
||||
|
||||
c = ENGINEERING_GUILE_CARTRIDGES[key]
|
||||
esc_scm = html.escape(c["scm_expr"], quote=True)
|
||||
esc_ts = html.escape(c["ts_expr"], quote=True)
|
||||
esc_rs = html.escape(c["rust_expr"], quote=True)
|
||||
esc_math = html.escape(c["math_view"], quote=True)
|
||||
esc_py = html.escape(c["py_view"], quote=True)
|
||||
esc_title = html.escape(c["title"], quote=True)
|
||||
esc_chal = html.escape(c["challenge"], quote=True)
|
||||
esc_scm = html.escape(cartridge["scm_expr"], quote=True)
|
||||
esc_ts = html.escape(cartridge["ts_expr"], quote=True)
|
||||
esc_rs = html.escape(cartridge["rust_expr"], quote=True)
|
||||
esc_math = html.escape(cartridge["math_view"], quote=True)
|
||||
esc_py = html.escape(cartridge["py_view"], quote=True)
|
||||
esc_title = html.escape(cartridge["title"], quote=True)
|
||||
esc_chal = html.escape(cartridge["challenge"], quote=True)
|
||||
return (
|
||||
'<section class="panel hs-plate-g3 hs-guile-cartridge">'
|
||||
'<div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:0.5rem;">'
|
||||
@@ -136,7 +138,7 @@ def _render_guile_cartridge_html(key: str) -> str:
|
||||
'</div>'
|
||||
'</div>'
|
||||
'<div class="hs-guile-triview">'
|
||||
f'<div class="hs-guile-box"><strong style="color:var(--gold);display:block;margin-bottom:0.2rem;">1. Formal Specification & Python:</strong><code>{esc_math}</code><pre style="white-space:pre-wrap;margin-top:0.25rem;color:var(--text-secondary);">{esc_py}</pre></div>'
|
||||
f'<div class="hs-guile-box"><strong style="color:var(--gold);display:block;margin-bottom:0.2rem;">{spec_label}</strong><code>{esc_math}</code><pre style="white-space:pre-wrap;margin-top:0.25rem;color:var(--text-secondary);">{esc_py}</pre></div>'
|
||||
f'<div class="hs-guile-box hs-lang-box-guile"><div style="display:flex;justify-content:space-between;align-items:center;"><strong style="color:var(--cyan);">λ Guile Scheme (Z-Combinator):</strong><button type="button" class="btn hs-load-in-repl-btn" data-polyglot-lang="guile" data-scheme-expr="{esc_scm}" style="padding:0.12rem 0.4rem;font-size:0.65rem;">REPL →</button></div><code class="hs-guile-code-expr">{esc_scm}</code><div class="hs-guile-eval-result" style="margin-top:0.3rem;font-weight:700;color:var(--emerald);">=> [Select Lens to evaluate]</div></div>'
|
||||
f'<div class="hs-guile-box hs-lang-box-ts"><div style="display:flex;justify-content:space-between;align-items:center;"><strong style="color:var(--gold);">TS TypeScript (Strict AST):</strong><button type="button" class="btn hs-load-in-repl-btn" data-polyglot-lang="ts" data-scheme-expr="{esc_ts}" style="padding:0.12rem 0.4rem;font-size:0.65rem;">REPL →</button></div><code class="hs-ts-code-expr">{esc_ts}</code><div class="hs-ts-eval-result" style="margin-top:0.3rem;font-weight:700;color:var(--emerald);">=> [Select Lens to evaluate]</div></div>'
|
||||
f'<div class="hs-guile-box hs-lang-box-rust"><div style="display:flex;justify-content:space-between;align-items:center;"><strong style="color:var(--emerald);">Rs Rust (Option/Iterator AST):</strong><button type="button" class="btn hs-load-in-repl-btn" data-polyglot-lang="rust" data-scheme-expr="{esc_rs}" style="padding:0.12rem 0.4rem;font-size:0.65rem;">REPL →</button></div><code class="hs-rust-code-expr">{esc_rs}</code><div class="hs-rust-eval-result" style="margin-top:0.3rem;font-weight:700;color:var(--emerald);">=> [Select Lens to evaluate]</div></div>'
|
||||
@@ -146,6 +148,13 @@ def _render_guile_cartridge_html(key: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
def _render_guile_cartridge_html(key: str) -> str:
|
||||
return render_polyglot_cartridge_html(
|
||||
ENGINEERING_GUILE_CARTRIDGES[key],
|
||||
spec_label="1. Formal Specification & Python:",
|
||||
)
|
||||
|
||||
|
||||
def _render_guile_repl_drawer_html(rel_prefix: str) -> str:
|
||||
return f"""
|
||||
<aside id="hsGuileReplDrawer" class="hs-plate-g3" aria-label="In-Browser Polyglot Guile Scheme, TypeScript, and Rust Hardened REPL">
|
||||
@@ -433,7 +442,14 @@ def _render_nav_html(active_slug: str | None, enabled_subpages: list[str], rel_p
|
||||
return "\n ".join(links)
|
||||
|
||||
|
||||
def _render_prereq_box_html(level_str: str, prereqs: list[str], resources: list[dict[str, Any]], rel_prefix: str) -> str:
|
||||
def _render_prereq_box_html(
|
||||
level_str: str,
|
||||
prereqs: list[str],
|
||||
resources: list[dict[str, Any]],
|
||||
rel_prefix: str,
|
||||
intro_prompt: str = "If any concepts on this page are unfamiliar, occupy your study time with these free foundational resources first:",
|
||||
prereq_heading: str = "Core Concepts Required:",
|
||||
) -> str:
|
||||
p_items = "".join(f"<li>{p}</li>" for p in prereqs)
|
||||
r_items = []
|
||||
for r in resources:
|
||||
@@ -445,9 +461,9 @@ def _render_prereq_box_html(level_str: str, prereqs: list[str], resources: list[
|
||||
return (
|
||||
'<section class="panel hs-plate-g3 plate-lock-emerald hs-prereq-ladder" style="margin-bottom:0.9rem;padding:1rem 1.2rem;">'
|
||||
f'<div style="font-size:0.74rem;font-weight:700;color:var(--emerald);text-transform:uppercase;letter-spacing:0.06em;">Prerequisite Track for Novices • Required Expertise: {level_str}</div>'
|
||||
'<p style="font-size:0.76rem;color:var(--text-secondary);margin:0.35rem 0;">If any concepts on this page are unfamiliar, occupy your study time with these free foundational resources first:</p>'
|
||||
f'<p style="font-size:0.76rem;color:var(--text-secondary);margin:0.35rem 0;">{intro_prompt}</p>'
|
||||
'<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:0.8rem;margin-top:0.4rem;">'
|
||||
f'<div><strong style="font-size:0.73rem;color:var(--gold);">Core Concepts Required:</strong><ul style="font-size:0.72rem;color:var(--text-main);margin:0.25rem 0 0 1.1rem;line-height:1.5;">{p_items}</ul></div>'
|
||||
f'<div><strong style="font-size:0.73rem;color:var(--gold);">{prereq_heading}</strong><ul style="font-size:0.72rem;color:var(--text-main);margin:0.25rem 0 0 1.1rem;line-height:1.5;">{p_items}</ul></div>'
|
||||
f'<div><strong style="font-size:0.73rem;color:var(--cyan);">Curated Free Public Study Resources:</strong><ul style="font-size:0.72rem;color:var(--text-main);margin:0.25rem 0 0 1.1rem;line-height:1.5;">{"".join(r_items)}</ul></div>'
|
||||
'</div></section>'
|
||||
)
|
||||
|
||||
@@ -16,59 +16,31 @@ from typing import Any
|
||||
|
||||
from hyperstitionstud_io import __version__ as CURRENT_VERSION
|
||||
from hyperstitionstud_io.config import load_workspace_config
|
||||
from hyperstitionstud_io.publishing.fonts import load_pillow_font
|
||||
from hyperstitionstud_io.publishing.fonts import (
|
||||
GROUP3_PALETTE,
|
||||
chamfer_polygon_points as _chamfer_pts,
|
||||
draw_group3_chamfered_plate as _draw_group3_plate,
|
||||
load_pillow_font,
|
||||
)
|
||||
|
||||
DIAGRAM_WIDTH = 1800
|
||||
DIAGRAM_HEIGHT = 1280
|
||||
|
||||
# Group 3 Preferred Default Palette Tokens (90% Quiet Matte Basalt / 7% #38bdf8 Interactive / 3% Explicit Lock Beacons)
|
||||
BG_VOID = (2, 6, 23) # #020617
|
||||
BG_WELL = (7, 13, 27) # #070d1b
|
||||
BG_ODD = (12, 19, 36) # #0c1324
|
||||
BG_EVEN = (17, 26, 46) # #111a2e
|
||||
BG_BEZEL = (24, 35, 56) # #182338
|
||||
BORDER_MUTED = (38, 52, 77) # #26344d
|
||||
TXT_PRI = (226, 232, 240) # #e2e8f0
|
||||
TXT_SEC = (148, 163, 184) # #94a3b8
|
||||
TXT_DIM = (100, 116, 139) # #64748b
|
||||
CYAN = (56, 189, 248) # #38bdf8
|
||||
GOLD = (245, 158, 11) # #f59e0b
|
||||
EMERALD = (16, 185, 129) # #10b981
|
||||
ROSE = (244, 63, 94) # #f43f5e
|
||||
VIOLET = (168, 85, 247) # #a855f7
|
||||
|
||||
|
||||
def _chamfer_pts(x0: int, y0: int, x1: int, y1: int, ctl: int = 10, ctr: int = 10, cbr: int = 4, cbl: int = 4) -> list[tuple[int, int]]:
|
||||
return [
|
||||
(x0 + ctl, y0),
|
||||
(x1 - ctr, y0),
|
||||
(x1, y0 + ctr),
|
||||
(x1, y1 - cbr),
|
||||
(x1 - cbr, y1),
|
||||
(x0 + cbl, y1),
|
||||
(x0, y1 - cbl),
|
||||
(x0, y0 + ctl),
|
||||
]
|
||||
|
||||
|
||||
def _draw_group3_plate(
|
||||
draw: Any,
|
||||
box: tuple[int, int, int, int],
|
||||
fill: tuple[int, int, int],
|
||||
attention_color: tuple[int, int, int] | None = None,
|
||||
pip_color: tuple[int, int, int] | None = None,
|
||||
) -> None:
|
||||
x0, y0, x1, y1 = box
|
||||
out_col = attention_color if attention_color else BORDER_MUTED
|
||||
pts = _chamfer_pts(x0, y0, x1, y1, 10, 10, 4, 4)
|
||||
draw.polygon(pts, fill=fill, outline=out_col)
|
||||
band_h = min(y1 - y0, 26)
|
||||
for y in range(y0 + 3, y0 + band_h, 3):
|
||||
for x in range(x0 + 8 + (y % 2) * 3, x1 - 8, 6):
|
||||
draw.point((x, y), fill=(22, 33, 54))
|
||||
draw.polygon([(x0 + 10, y0 + 1), (x1 - 10, y0 + 1), (x1 - 7, y0 + 4), (x0 + 7, y0 + 4)], fill=BG_BEZEL)
|
||||
pcol = attention_color or pip_color or (71, 85, 105)
|
||||
draw.rectangle((x0 + 14, y0 + 1, x0 + 48, y0 + 4), fill=pcol)
|
||||
BG_VOID = GROUP3_PALETTE["BG_VOID"]
|
||||
BG_WELL = GROUP3_PALETTE["BG_WELL"]
|
||||
BG_ODD = GROUP3_PALETTE["BG_ODD"]
|
||||
BG_EVEN = GROUP3_PALETTE["BG_EVEN"]
|
||||
BG_BEZEL = GROUP3_PALETTE["BG_BEZEL"]
|
||||
BORDER_MUTED = GROUP3_PALETTE["BORDER_MUTED"]
|
||||
TXT_PRI = GROUP3_PALETTE["TXT_PRI"]
|
||||
TXT_SEC = GROUP3_PALETTE["TXT_SEC"]
|
||||
TXT_DIM = GROUP3_PALETTE["TXT_DIM"]
|
||||
CYAN = GROUP3_PALETTE["CYAN"]
|
||||
GOLD = GROUP3_PALETTE["GOLD"]
|
||||
EMERALD = GROUP3_PALETTE["EMERALD"]
|
||||
ROSE = GROUP3_PALETTE["ROSE"]
|
||||
VIOLET = GROUP3_PALETTE["VIOLET"]
|
||||
|
||||
|
||||
def _draw_arrow_down(draw: Any, x: int, y0: int, y1: int, color: tuple[int, int, int], label: str | None = None, font: Any = None) -> None:
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
"""
|
||||
hyperstitionstud_io.publishing.fonts — Cross-OS TrueType Font Resolver with Built-In Fallbacks.
|
||||
hyperstitionstud_io.publishing.fonts — Cross-OS TrueType Font Resolver, `@lru_cache` Pillow Font Loader,
|
||||
and Shared Group 3 ("Stealth Basalt Plate & Micro-Pip Signal Ribbon") Pillow Drawing Primitives.
|
||||
Searches Debian/Ubuntu, Fedora/RHEL, Arch, Alpine, macOS, and user font directories so PDF and
|
||||
PNG rendering never crashes on OS-specific font paths.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -13,6 +15,7 @@ FONT_SEARCH_DIRS = [
|
||||
Path("/usr/share/fonts/truetype/dejavu"),
|
||||
Path("/usr/share/fonts/dejavu-sans-fonts"),
|
||||
Path("/usr/share/fonts/dejavu-sans-mono-fonts"),
|
||||
Path("/usr/share/fonts/google-noto"),
|
||||
Path("/usr/share/fonts/TTF"),
|
||||
Path("/usr/share/fonts/dejavu"),
|
||||
Path.home() / ".local" / "share" / "fonts",
|
||||
@@ -21,6 +24,69 @@ FONT_SEARCH_DIRS = [
|
||||
Path("/System/Library/Fonts"),
|
||||
]
|
||||
|
||||
# Shared Group 3 Preferred Default Palette Tokens (90% Quiet Matte Basalt / 7% #38bdf8 Interactive / 3% Explicit Lock Beacons)
|
||||
GROUP3_PALETTE: dict[str, tuple[int, int, int]] = {
|
||||
"BG_VOID": (2, 6, 23), # #020617
|
||||
"BG_WELL": (7, 13, 27), # #070d1b
|
||||
"BG_ODD": (12, 19, 36), # #0c1324
|
||||
"BG_EVEN": (17, 26, 46), # #111a2e
|
||||
"BG_BEZEL": (24, 35, 56), # #182338
|
||||
"BORDER_MUTED": (38, 52, 77), # #26344d
|
||||
"TXT_PRI": (226, 232, 240), # #e2e8f0
|
||||
"TXT_SEC": (148, 163, 184), # #94a3b8
|
||||
"TXT_DIM": (100, 116, 139), # #64748b
|
||||
"CYAN": (56, 189, 248), # #38bdf8
|
||||
"GOLD": (245, 158, 11), # #f59e0b
|
||||
"EMERALD": (16, 185, 129), # #10b981
|
||||
"ROSE": (244, 63, 94), # #f43f5e
|
||||
"VIOLET": (168, 85, 247), # #a855f7
|
||||
}
|
||||
|
||||
|
||||
def chamfer_polygon_points(
|
||||
x0: int,
|
||||
y0: int,
|
||||
x1: int,
|
||||
y1: int,
|
||||
ctl: int = 10,
|
||||
ctr: int = 10,
|
||||
cbr: int = 4,
|
||||
cbl: int = 4,
|
||||
) -> list[tuple[int, int]]:
|
||||
return [
|
||||
(x0 + ctl, y0),
|
||||
(x1 - ctr, y0),
|
||||
(x1, y0 + ctr),
|
||||
(x1, y1 - cbr),
|
||||
(x1 - cbr, y1),
|
||||
(x0 + cbl, y1),
|
||||
(x0, y1 - cbl),
|
||||
(x0, y0 + ctl),
|
||||
]
|
||||
|
||||
|
||||
def draw_group3_chamfered_plate(
|
||||
draw: Any,
|
||||
box: tuple[int, int, int, int],
|
||||
fill: tuple[int, int, int],
|
||||
attention_color: tuple[int, int, int] | None = None,
|
||||
pip_color: tuple[int, int, int] | None = None,
|
||||
) -> None:
|
||||
x0, y0, x1, y1 = box
|
||||
out_col = attention_color if attention_color else GROUP3_PALETTE["BORDER_MUTED"]
|
||||
pts = chamfer_polygon_points(x0, y0, x1, y1, 10, 10, 4, 4)
|
||||
draw.polygon(pts, fill=fill, outline=out_col)
|
||||
band_h = min(y1 - y0, 26)
|
||||
for y in range(y0 + 3, y0 + band_h, 3):
|
||||
for x in range(x0 + 8 + (y % 2) * 3, x1 - 8, 6):
|
||||
draw.point((x, y), fill=(22, 33, 54))
|
||||
draw.polygon(
|
||||
[(x0 + 10, y0 + 1), (x1 - 10, y0 + 1), (x1 - 7, y0 + 4), (x0 + 7, y0 + 4)],
|
||||
fill=GROUP3_PALETTE["BG_BEZEL"],
|
||||
)
|
||||
pcol = attention_color or pip_color or (71, 85, 105)
|
||||
draw.rectangle((x0 + 14, y0 + 1, x0 + 48, y0 + 4), fill=pcol)
|
||||
|
||||
|
||||
def _reportlab_vera_fallback(filename: str) -> Path | None:
|
||||
try:
|
||||
@@ -43,7 +109,11 @@ def _reportlab_vera_fallback(filename: str) -> Path | None:
|
||||
return None
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=64)
|
||||
def resolve_font_path(filename: str, fallback_filename: str | None = None) -> Path | None:
|
||||
cand_direct = Path(filename)
|
||||
if cand_direct.is_absolute() and cand_direct.is_file():
|
||||
return cand_direct
|
||||
for d in FONT_SEARCH_DIRS:
|
||||
cand = d / filename
|
||||
if cand.is_file():
|
||||
@@ -65,6 +135,7 @@ def resolve_font_path(filename: str, fallback_filename: str | None = None) -> Pa
|
||||
return _reportlab_vera_fallback(filename)
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=64)
|
||||
def load_pillow_font(filename: str, size: int) -> Any:
|
||||
from PIL import ImageFont
|
||||
|
||||
|
||||
@@ -99,36 +99,11 @@ MATH_GUILE_CARTRIDGES: dict[str, dict[str, str]] = {
|
||||
|
||||
|
||||
def _render_math_guile_cartridge_html(key: str) -> str:
|
||||
import html
|
||||
from hyperstitionstud_io.publishing.engineering_docs import render_polyglot_cartridge_html
|
||||
|
||||
c = MATH_GUILE_CARTRIDGES[key]
|
||||
esc_scm = html.escape(c["scm_expr"], quote=True)
|
||||
esc_ts = html.escape(c["ts_expr"], quote=True)
|
||||
esc_rs = html.escape(c["rust_expr"], quote=True)
|
||||
esc_math = html.escape(c["math_view"], quote=True)
|
||||
esc_py = html.escape(c["py_view"], quote=True)
|
||||
esc_title = html.escape(c["title"], quote=True)
|
||||
esc_chal = html.escape(c["challenge"], quote=True)
|
||||
return (
|
||||
'<section class="panel hs-plate-g3 hs-guile-cartridge">'
|
||||
'<div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:0.5rem;">'
|
||||
f'<div style="font-size:0.74rem;font-weight:700;color:var(--cyan);text-transform:uppercase;letter-spacing:0.05em;">λ {esc_title}</div>'
|
||||
'<div style="display:flex;gap:0.25rem;flex-wrap:wrap;align-items:center;">'
|
||||
'<button type="button" class="hs-polyglot-seg" data-lens-mode="guile">λ Guile</button>'
|
||||
'<button type="button" class="hs-polyglot-seg" data-lens-mode="ts">TS TypeScript</button>'
|
||||
'<button type="button" class="hs-polyglot-seg" data-lens-mode="rust">Rs Rust</button>'
|
||||
'<button type="button" class="hs-polyglot-seg" data-lens-mode="all">≡ All 3</button>'
|
||||
'<button type="button" class="hs-polyglot-seg" data-lens-mode="off">Hide</button>'
|
||||
'</div>'
|
||||
'</div>'
|
||||
'<div class="hs-guile-triview">'
|
||||
f'<div class="hs-guile-box"><strong style="color:var(--gold);display:block;margin-bottom:0.2rem;">1. Mathematical Identity & Python:</strong><code>{esc_math}</code><pre style="white-space:pre-wrap;margin-top:0.25rem;color:var(--text-secondary);">{esc_py}</pre></div>'
|
||||
f'<div class="hs-guile-box hs-lang-box-guile"><div style="display:flex;justify-content:space-between;align-items:center;"><strong style="color:var(--cyan);">λ Guile Scheme (Z-Combinator):</strong><button type="button" class="btn hs-load-in-repl-btn" data-polyglot-lang="guile" data-scheme-expr="{esc_scm}" style="padding:0.12rem 0.4rem;font-size:0.65rem;">REPL →</button></div><code class="hs-guile-code-expr">{esc_scm}</code><div class="hs-guile-eval-result" style="margin-top:0.3rem;font-weight:700;color:var(--emerald);">=> [Select Lens to evaluate]</div></div>'
|
||||
f'<div class="hs-guile-box hs-lang-box-ts"><div style="display:flex;justify-content:space-between;align-items:center;"><strong style="color:var(--gold);">TS TypeScript (Strict AST):</strong><button type="button" class="btn hs-load-in-repl-btn" data-polyglot-lang="ts" data-scheme-expr="{esc_ts}" style="padding:0.12rem 0.4rem;font-size:0.65rem;">REPL →</button></div><code class="hs-ts-code-expr">{esc_ts}</code><div class="hs-ts-eval-result" style="margin-top:0.3rem;font-weight:700;color:var(--emerald);">=> [Select Lens to evaluate]</div></div>'
|
||||
f'<div class="hs-guile-box hs-lang-box-rust"><div style="display:flex;justify-content:space-between;align-items:center;"><strong style="color:var(--emerald);">Rs Rust (Option/Iterator AST):</strong><button type="button" class="btn hs-load-in-repl-btn" data-polyglot-lang="rust" data-scheme-expr="{esc_rs}" style="padding:0.12rem 0.4rem;font-size:0.65rem;">REPL →</button></div><code class="hs-rust-code-expr">{esc_rs}</code><div class="hs-rust-eval-result" style="margin-top:0.3rem;font-weight:700;color:var(--emerald);">=> [Select Lens to evaluate]</div></div>'
|
||||
'</div>'
|
||||
f'<div style="font-size:0.71rem;color:var(--text-secondary);"><strong>Guided Micro-Challenge (4-Ring Zero-Escape Sandbox):</strong> {esc_chal}</div>'
|
||||
'</section>'
|
||||
return render_polyglot_cartridge_html(
|
||||
MATH_GUILE_CARTRIDGES[key],
|
||||
spec_label="1. Mathematical Identity & Python:",
|
||||
)
|
||||
|
||||
MATH_HUB_PREREQ_LADDER: dict[str, Any] = {
|
||||
@@ -385,22 +360,15 @@ def _render_math_nav_html(active_slug: str | None, enabled_subpages: list[str],
|
||||
|
||||
|
||||
def _render_math_prereq_html(level_str: str, prereqs: list[str], resources: list[dict[str, Any]], rel_prefix: str) -> str:
|
||||
p_items = "".join(f"<li>{p}</li>" for p in prereqs)
|
||||
r_items = []
|
||||
for r in resources:
|
||||
url = r["url"]
|
||||
if not r.get("external") and url.startswith("/"):
|
||||
url = f"{rel_prefix}..{url}"
|
||||
ext_attr = ' target="_blank" rel="noopener noreferrer"' if r.get("external") else ""
|
||||
r_items.append(f'<li><a href="{url}"{ext_attr} style="color:var(--cyan);">{r["label"]} ↗</a></li>')
|
||||
return (
|
||||
'<section class="panel hs-plate-g3 plate-lock-emerald hs-prereq-ladder" style="margin-bottom:0.9rem;padding:1rem 1.2rem;">'
|
||||
f'<div style="font-size:0.74rem;font-weight:700;color:var(--emerald);text-transform:uppercase;letter-spacing:0.06em;">Prerequisite Track for Novices • Required Expertise: {level_str}</div>'
|
||||
'<p style="font-size:0.76rem;color:var(--text-secondary);margin:0.35rem 0;">If any mathematical notation on this page is unfamiliar, occupy your study time with these free foundational resources first:</p>'
|
||||
'<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:0.8rem;margin-top:0.4rem;">'
|
||||
f'<div><strong style="font-size:0.73rem;color:var(--gold);">Core Mathematical Prerequisites:</strong><ul style="font-size:0.72rem;color:var(--text-main);margin:0.25rem 0 0 1.1rem;line-height:1.5;">{p_items}</ul></div>'
|
||||
f'<div><strong style="font-size:0.73rem;color:var(--cyan);">Curated Free Public Study Resources:</strong><ul style="font-size:0.72rem;color:var(--text-main);margin:0.25rem 0 0 1.1rem;line-height:1.5;">{"".join(r_items)}</ul></div>'
|
||||
'</div></section>'
|
||||
from hyperstitionstud_io.publishing.engineering_docs import _render_prereq_box_html
|
||||
|
||||
return _render_prereq_box_html(
|
||||
level_str=level_str,
|
||||
prereqs=prereqs,
|
||||
resources=resources,
|
||||
rel_prefix=rel_prefix,
|
||||
intro_prompt="If any mathematical notation on this page is unfamiliar, occupy your study time with these free foundational resources first:",
|
||||
prereq_heading="Core Mathematical Prerequisites:",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -694,7 +694,7 @@ def discover_web_and_repo_pdf_pairs(workspace_root: str | Path | None = None) ->
|
||||
if not scan_dir.is_dir():
|
||||
continue
|
||||
for p in sorted(scan_dir.rglob("*.pdf")):
|
||||
if "archive" in p.parts:
|
||||
if "archive" in p.parts or ("plans" in p.parts and "inactive" in p.parts):
|
||||
continue
|
||||
rp = p.resolve()
|
||||
if rp not in seen_pdfs:
|
||||
|
||||
Reference in new issue
Block a user