mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-08-08 07:45:47 +00:00
Squash the four overlapping feature branches into a single change set against main, eliminating cross-PR merge conflicts and the duplicated CI-fix scripts. What this brings in (merge order #79 -> #80 -> #81 -> #89): - #79 refactor(infra): shared utilities (4-Infrastructure/lib/*: q16, hashing, jsonl, fraction_utils) + the scripts/math-first/* validators that the math-check CI requires. - #80 feat(lean): Semantics.E8Sidon (1025 lines) -- Eisenstein coefficient identity E4^2 = E8 and the Sidon framework. E4_sq_eq_E8_coeff is fully proved (all Fourier-coefficient extraction machine-checked); the single residual gap is pinned to E4_sq_eq_E8_qExpansion (Mathlib lacks the valence formula / dim M8 = 1). 4 sorries + 1 axiom (e8_additive_completeness), all TODO(lean-port). - #81 refactor(lean): Float-free FixedPoint core (integer-only sqrt/log2/expNeg). E8Sidon.lean kept at #80's final 1025-line version (the #81 intermediate 438-line copy was overridden by merge order). - #89 feat(lean): Semantics.RRC.PolyFactorIdentity -- short-sleeve polynomial detection at the zerocopy limb boundary; now imports Semantics.E8Sidon for sigma3/sigma7/convolutionLHS (single source of truth) instead of inlining them. Conflict resolution: - flake.nix -> canonical rs-surface removal (Garnix shutdown). - scripts/math-first/* -> byte-identical across branches, clean. - .cursorrules / AGENTS.md -> unified; baselines + sorry inventory refreshed. Verification: - lake build (default aggregator): 3573 jobs, 0 errors. - lake build Semantics.RRC.PolyFactorIdentity (E8Sidon + FixedPoint + PolyFactor): 3655 jobs, 0 errors. Witnesses verified (sigma7 4 = 16513, convolutionLHS 6 = 2350). - Python tests: 68/68 pass. Note: the "Workers Builds: researchstack" check is a preexisting external Cloudflare build unrelated to this change (no branch touches 4-Infrastructure/cloudflare/). Build: 3573 jobs (default), 3655 jobs (narrow), 0 errors Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
134 lines
4.1 KiB
Python
134 lines
4.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from common.catalog import (
|
|
cad_ref_from_step_path as fallback_cad_ref_from_step_path,
|
|
find_source_by_cad_ref,
|
|
find_source_by_path,
|
|
viewer_artifact_path_for_step_path,
|
|
viewer_directory_for_step_path,
|
|
)
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[6] / "4-Infrastructure"))
|
|
from lib.hashing import sha256_file
|
|
|
|
|
|
REPO_ROOT = Path.cwd().resolve()
|
|
CAD_ROOT = REPO_ROOT
|
|
|
|
|
|
def _source_for_cad_ref(cad_ref: str):
|
|
source = find_source_by_cad_ref(cad_ref)
|
|
if source is None:
|
|
raise ValueError(f"CAD STEP ref not found: {cad_ref}")
|
|
return source
|
|
|
|
|
|
def cad_ref_from_step_path(step_path: Path) -> str:
|
|
source = find_source_by_path(step_path)
|
|
if source is not None:
|
|
return source.cad_ref
|
|
return fallback_cad_ref_from_step_path(step_path)
|
|
|
|
|
|
def part_stl_path_for_cad_ref(cad_ref: str) -> Path:
|
|
source = _source_for_cad_ref(cad_ref)
|
|
if source.stl_path is None:
|
|
raise ValueError(f"CAD STEP ref has no configured STL output: {cad_ref}")
|
|
return source.stl_path
|
|
|
|
|
|
def viewer_dir_for_cad_ref(cad_ref: str) -> Path:
|
|
source = _source_for_cad_ref(cad_ref)
|
|
if source.step_path is None:
|
|
raise ValueError(f"CAD STEP ref has no STEP path: {cad_ref}")
|
|
return viewer_directory_for_step_path(source.step_path)
|
|
|
|
|
|
def viewer_artifact_path(cad_ref: str, suffix: str) -> Path:
|
|
source = _source_for_cad_ref(cad_ref)
|
|
if source.step_path is None:
|
|
raise ValueError(f"CAD STEP ref has no STEP path: {cad_ref}")
|
|
return viewer_artifact_path_for_step_path(source.step_path, suffix)
|
|
|
|
|
|
def part_glb_path_for_cad_ref(cad_ref: str) -> Path:
|
|
return viewer_artifact_path(cad_ref, ".glb")
|
|
|
|
|
|
def part_selector_manifest_path_for_cad_ref(cad_ref: str) -> Path:
|
|
return viewer_artifact_path(cad_ref, ".topology.json")
|
|
|
|
|
|
def part_selector_binary_path_for_cad_ref(cad_ref: str) -> Path:
|
|
return viewer_artifact_path(cad_ref, ".topology.bin")
|
|
|
|
|
|
def native_component_glb_dir(step_path: Path) -> Path:
|
|
return viewer_directory_for_step_path(step_path) / "components"
|
|
|
|
|
|
def part_stl_path(step_path: Path) -> Path:
|
|
return part_stl_path_for_cad_ref(cad_ref_from_step_path(step_path))
|
|
|
|
|
|
def part_glb_path(step_path: Path) -> Path:
|
|
return viewer_artifact_path_for_step_path(step_path, ".glb")
|
|
|
|
|
|
def part_selector_manifest_path(step_path: Path) -> Path:
|
|
return viewer_artifact_path_for_step_path(step_path, ".topology.json")
|
|
|
|
|
|
def part_selector_binary_path(step_path: Path) -> Path:
|
|
return viewer_artifact_path_for_step_path(step_path, ".topology.bin")
|
|
|
|
|
|
def render_artifact_paths_for_cad_ref(cad_ref: str) -> tuple[Path, Path, Path, Path]:
|
|
return (
|
|
part_stl_path_for_cad_ref(cad_ref),
|
|
part_glb_path_for_cad_ref(cad_ref),
|
|
part_selector_manifest_path_for_cad_ref(cad_ref),
|
|
part_selector_binary_path_for_cad_ref(cad_ref),
|
|
)
|
|
|
|
|
|
def render_artifact_paths(step_path: Path) -> tuple[Path, Path, Path, Path]:
|
|
return render_artifact_paths_for_cad_ref(cad_ref_from_step_path(step_path))
|
|
|
|
|
|
def relative_to_repo(path: Path) -> str:
|
|
resolved = path.resolve()
|
|
try:
|
|
return resolved.relative_to(REPO_ROOT).as_posix()
|
|
except ValueError:
|
|
return resolved.as_posix()
|
|
def versioned_repo_url(path: Path, content_hash: str) -> str:
|
|
resolved = path.resolve()
|
|
try:
|
|
relative_path = resolved.relative_to(CAD_ROOT.resolve()).as_posix()
|
|
except ValueError:
|
|
relative_path = resolved.as_posix().lstrip("/")
|
|
suffix = f"?v={content_hash}" if content_hash else ""
|
|
return f"/{relative_path}{suffix}"
|
|
|
|
|
|
def atomic_write_json(output_path: Path, payload: object) -> Path:
|
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
with tempfile.NamedTemporaryFile(
|
|
"w",
|
|
dir=output_path.parent,
|
|
prefix=f".{output_path.name}.",
|
|
suffix=".tmp",
|
|
delete=False,
|
|
encoding="utf-8",
|
|
) as handle:
|
|
json.dump(payload, handle, separators=(",", ":"), ensure_ascii=True)
|
|
handle.write("\n")
|
|
temp_path = Path(handle.name)
|
|
temp_path.replace(output_path)
|
|
return output_path
|