feat(core): initialize hyperstitionstudio-core (hyperstitionstud_io.* / urn:io:hyperstitionstud:*) shared library, 4897-entry offline CMUdict fallback, local-config citation resolver, CLI entrypoints, and test suite (v1.2.0)
This commit is contained in:
commit
f8235a2037
32 files changed
+6646
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
hyperstitionstud_io.glossary — Provenance-Keyed Glossary Registry & Cryptographic SHA-256 Isolation Guard.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterable
|
||||
|
||||
|
||||
def sha256_file(path: str | Path) -> str:
|
||||
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
||||
|
||||
|
||||
class ReadOnlyIsolationGuard:
|
||||
"""
|
||||
Context manager verifying via pure-Python hashlib.sha256 that protected upstream
|
||||
registries (such as glossary-registry.json and encyclopedia-manifest.json) remain
|
||||
100% byte-for-byte unchanged across a build or verification pass. Zero VCS calls.
|
||||
"""
|
||||
|
||||
def __init__(self, protected_paths: Iterable[str | Path]) -> None:
|
||||
self.paths: list[Path] = [Path(p).resolve() for p in protected_paths]
|
||||
self.pre_digests: dict[str, str] = {}
|
||||
self.post_digests: dict[str, str] = {}
|
||||
|
||||
def __enter__(self) -> ReadOnlyIsolationGuard:
|
||||
self.pre_digests = {str(p): sha256_file(p) for p in self.paths if p.is_file()}
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
||||
self.post_digests = {str(p): sha256_file(p) for p in self.paths if p.is_file()}
|
||||
for p_str, pre_sha in self.pre_digests.items():
|
||||
post_sha = self.post_digests.get(p_str)
|
||||
if pre_sha != post_sha:
|
||||
raise AssertionError(
|
||||
f"ISOLATION BREACH on {p_str}: pre-SHA256={pre_sha} != post-SHA256={post_sha}"
|
||||
)
|
||||
|
||||
def audit_receipt(self) -> dict[str, Any]:
|
||||
if not self.post_digests:
|
||||
self.post_digests = {str(p): sha256_file(p) for p in self.paths if p.is_file()}
|
||||
all_unchanged = all(self.pre_digests.get(k) == self.post_digests.get(k) for k in self.pre_digests)
|
||||
return {
|
||||
"namespace_urn": "urn:io:hyperstitionstud:isolation-receipt:v1",
|
||||
"all_unchanged": all_unchanged,
|
||||
"files": {
|
||||
k: {
|
||||
"pre_sha256": self.pre_digests.get(k),
|
||||
"post_sha256": self.post_digests.get(k),
|
||||
"unchanged": self.pre_digests.get(k) == self.post_digests.get(k),
|
||||
}
|
||||
for k in self.pre_digests
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user