feat(core): implement Plan #62 efficiency, deduplication, caching & hook optimizations

This commit is contained in:
Hermes Agent committed 2026-12-02 22:09:58 +00:00
1 parent d4b7502501
commit 9b587d6351
20 files changed
+176 -195

No files matched your search

+11 -11
View File
@@ -39,7 +39,7 @@ from hyperstitionstud_io.ciphers import ( # noqa: E402
is_repdigit_37,
prime_rank,
)
from hyperstitionstud_io.config import load_workspace_config # noqa: E402
from hyperstitionstud_io.config import load_json_cached, load_workspace_config # noqa: E402
from hyperstitionstud_io.glossary import ReadOnlyIsolationGuard # noqa: E402
from hyperstitionstud_io.ipld import ( # noqa: E402
compute_dag_json_cidv1,
@@ -377,7 +377,7 @@ def _load_real_history_latest_bars() -> dict[str, dict[str, Any]]:
if not hist_path.is_file():
return {}
try:
raw = json.loads(hist_path.read_text(encoding="utf-8"))
raw = load_json_cached(hist_path, copy_result=False)
out: dict[str, dict[str, Any]] = {}
for sym, sym_obj in (raw.get("instruments") or {}).items():
bars_by_date = sym_obj.get("bars_by_date") or {}
@@ -471,7 +471,7 @@ def build_financial_quant_harvest(
cfg = load_workspace_config()
with ReadOnlyIsolationGuard(cfg.read_only_files) as guard:
if snapshot_path and Path(snapshot_path).is_file():
raw_watchlist = json.loads(Path(snapshot_path).read_text(encoding="utf-8"))
raw_watchlist = load_json_cached(snapshot_path, copy_result=False)
else:
raw_watchlist = fetch_live_watchlist(
CANONICAL_WATCHLIST_24,
@@ -497,7 +497,7 @@ def build_financial_quant_harvest(
news_entities: dict[str, list[str]] = {}
if effective_news_path.is_file():
try:
news_obj = json.loads(effective_news_path.read_text(encoding="utf-8"))
news_obj = load_json_cached(effective_news_path, copy_result=False)
headline_records: list[str] = []
for st in news_obj.get("stories", news_obj.get("headlines", [])):
if isinstance(st, dict):
@@ -856,7 +856,7 @@ def update_real_market_history_cache(
cfg = load_workspace_config()
h_path = Path(history_path) if history_path else (cfg.core_dir / "site" / "quant" / "real-market-history.json")
if h_path.is_file():
doc = json.loads(h_path.read_text(encoding="utf-8"))
doc = load_json_cached(h_path, copy_result=True)
else:
doc = {"version": CURRENT_VERSION, "synthetic_data_eliminated": True, "instruments": {}}
@@ -1034,7 +1034,7 @@ def snapshot_local_telemetry(
src = q_dir / fname
if src.is_file():
try:
json.loads(src.read_text(encoding="utf-8"))
load_json_cached(src, copy_result=False)
shutil.copy2(src, s_dir / fname)
saved.append(fname)
except Exception:
@@ -1046,7 +1046,7 @@ def snapshot_local_telemetry(
snap_rmh_p = s_dir / "real-market-history.json"
if snap_rmh_p.is_file():
try:
base_rmh = json.loads(snap_rmh_p.read_text(encoding="utf-8"))
base_rmh = load_json_cached(snap_rmh_p, copy_result=True)
insts = base_rmh.setdefault("instruments", {})
for hist_doc in _excavate_git_json_versions(cfg.core_dir, "site/quant/real-market-history.json"):
for sym, s_obj in (hist_doc.get("instruments") or {}).items():
@@ -1102,8 +1102,8 @@ def reconcile_telemetry_snapshot(
cur_hist_p = q_dir / "real-market-history.json"
if snap_hist_p.is_file() and cur_hist_p.is_file():
try:
snap_hist = json.loads(snap_hist_p.read_text(encoding="utf-8"))
cur_hist = json.loads(cur_hist_p.read_text(encoding="utf-8"))
snap_hist = load_json_cached(snap_hist_p, copy_result=False)
cur_hist = load_json_cached(cur_hist_p, copy_result=True)
cur_insts = cur_hist.setdefault("instruments", {})
for sym, snap_obj in (snap_hist.get("instruments") or {}).items():
if sym == "ANTHR-PVT":
@@ -1139,8 +1139,8 @@ def reconcile_telemetry_snapshot(
cur_macro_p = q_dir / "real-macro-indicators.json"
if snap_macro_p.is_file() and cur_macro_p.is_file():
try:
snap_macro = json.loads(snap_macro_p.read_text(encoding="utf-8"))
cur_macro = json.loads(cur_macro_p.read_text(encoding="utf-8"))
snap_macro = load_json_cached(snap_macro_p, copy_result=False)
cur_macro = load_json_cached(cur_macro_p, copy_result=True)
cur_series = cur_macro.setdefault("series", {})
for s_key, snap_s in (snap_macro.get("series") or {}).items():
if s_key not in cur_series or not isinstance(snap_s, dict):
+2 -2
View File
@@ -19,7 +19,7 @@ from pathlib import Path
from typing import Any
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.quant.collector import NO_DATA_AVAILABLE
@@ -186,7 +186,7 @@ def build_daily_portfolio_brief(
active_read_state_path = state_path if state_path.is_file() else next((p for p in legacy_state_paths if p.is_file()), state_path)
if active_read_state_path.is_file():
try:
prior_state = json.loads(active_read_state_path.read_text(encoding="utf-8"))
prior_state = load_json_cached(active_read_state_path, copy_result=False)
except Exception:
prior_state = {}
+2 -2
View File
@@ -19,7 +19,7 @@ from typing import Any
from hyperstitionstud_io import __version__ as CURRENT_VERSION
from hyperstitionstud_io.ciphers import compute_aq, int_to_spoken_words, prime_rank
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.phonetics import translate_batch
@@ -328,7 +328,7 @@ def build_macro_indicators_bundle(
cached_bundle: dict[str, Any] = {}
if cache_path.is_file():
try:
cached_bundle = json.loads(cache_path.read_text(encoding="utf-8"))
cached_bundle = load_json_cached(cache_path, copy_result=False)
except Exception:
cached_bundle = {}
+3 -3
View File
@@ -31,7 +31,7 @@ from hyperstitionstud_io.ciphers import (
is_repdigit_37,
prime_rank,
)
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, write_pretty_and_dag_json
from hyperstitionstud_io.lenses import DEFAULT_LENS, ENABLED_LENSES, LENS_REGISTRY, apply_all_lenses
@@ -256,7 +256,7 @@ def _load_real_market_history_bars(cfg: Any) -> dict[str, dict[str, dict[str, An
if not hist_path.is_file():
return {}
try:
raw = json.loads(hist_path.read_text(encoding="utf-8"))
raw = load_json_cached(hist_path, copy_result=False)
out: dict[str, dict[str, dict[str, Any]]] = {}
for sym, sym_obj in (raw.get("instruments") or {}).items():
out[sym] = dict(sym_obj.get("bars_by_date") or {})
@@ -809,7 +809,7 @@ def build_quant_timeseries_bundle(
tl_path = cfg.zoology_dir / "taxonomy" / "assemblage-builds-tier-list.json"
builds_out: list[dict[str, Any]] = []
if tl_path.is_file():
tl_data = json.loads(tl_path.read_text(encoding="utf-8"))
tl_data = load_json_cached(tl_path, copy_result=False)
for row in tl_data.get("rows", []):
s6 = row.get("stats_6") or {}
b_struct = {