Add compact oracle and local env closure packs

This commit is contained in:
732642856
2026-06-29 10:45:11 +08:00
parent a824588d90
commit bb904156e6
7 changed files with 411 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
"""Minimal local env loader for repo-scoped developer configuration."""
from __future__ import annotations
import os
from pathlib import Path
DEFAULT_ENV_FILES = (".env.local", ".jyotish.local.env")
_LOADED_ROOTS: set[Path] = set()
def _parse_env_line(line: str) -> tuple[str, str] | None:
text = line.strip()
if not text or text.startswith("#") or "=" not in text:
return None
key, value = text.split("=", 1)
key = key.strip()
value = value.strip()
if not key:
return None
if value and value[0] == value[-1] and value[0] in {"'", '"'}:
value = value[1:-1]
return key, value
def load_local_env(root: str | Path | None = None) -> list[Path]:
if os.environ.get("JYOTISH_SKIP_LOCAL_ENV", "").strip().lower() in {"1", "true", "yes"}:
return []
repo_root = (Path(root) if root is not None else Path(__file__).resolve().parents[1]).resolve()
if repo_root in _LOADED_ROOTS:
return []
_LOADED_ROOTS.add(repo_root)
loaded: list[Path] = []
for name in DEFAULT_ENV_FILES:
path = repo_root / name
if not path.exists():
continue
for line in path.read_text(encoding="utf-8").splitlines():
parsed = _parse_env_line(line)
if not parsed:
continue
key, value = parsed
os.environ.setdefault(key, value)
loaded.append(path)
return loaded
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env python3
"""Build a compact batch closure report by reusing existing oracle entrypoints."""
from __future__ import annotations
import argparse
import json
from typing import Any
from scripts.dasha_oracle_closure_status import build_status as build_dasha_status
from scripts.shadbala_oracle_comparison import compare_case as compare_shadbala_case
SHADBALA_CASE_IDS = [
"template_user_REDACTED_YEAR_moon_longitude_lahiri",
"template_steve_jobs_dasha_lahiri",
]
def build_report(oracle_file: str) -> dict[str, Any]:
dasha = build_dasha_status(oracle_file)
shadbala_rows = []
shadbala_within_tolerance = 0
for case_id in SHADBALA_CASE_IDS:
report = compare_shadbala_case(oracle_file=oracle_file, case_id=case_id)
within = report["summary"]["planet_count"] == report["summary"]["planets_within_total_tolerance"]
if within:
shadbala_within_tolerance += 1
shadbala_rows.append({
"kind": "shadbala",
"case_id": report["case_id"],
"status": report["status"],
"ayanamsa": report["settings"].get("ayanamsa"),
"planets_within_total_tolerance": report["summary"]["planets_within_total_tolerance"],
"planet_count": report["summary"]["planet_count"],
"max_abs_total_delta_rupa": report["summary"]["max_abs_total_delta_rupa"],
"global_scaling_recommendation": report["global_scaling_check"].get("recommendation"),
"within_case_tolerance": within,
})
rows = [{
"kind": "dasha",
"dasha_task_count": dasha["summary"]["dasha_task_count"],
"external_verified_dasha_tasks": dasha["summary"]["external_verified_dasha_tasks"],
"can_claim_dasha_oracle_closure": dasha["summary"]["can_claim_dasha_oracle_closure"],
"production_tuning_allowed": dasha["summary"]["production_tuning_allowed"],
}, *shadbala_rows]
return {
"scope": "oracle_batch_closure_pack",
"schema_version": 1,
"summary": {
"dasha_can_claim_closure": dasha["summary"]["can_claim_dasha_oracle_closure"],
"shadbala_case_count": len(shadbala_rows),
"shadbala_within_tolerance_case_count": shadbala_within_tolerance,
"global_oracle_closure_blocked": True,
},
"rows": rows,
"boundary": (
"This pack reuses existing Dasha and Shadbala oracle entrypoints. "
"Dasha-only closure can be complete while global oracle closure remains blocked "
"until Shadbala and other non-Dasha fronts are closed."
),
"next_actions": [
"Keep reusing dasha_oracle_closure_status.py for Dasha truth instead of duplicating logic.",
"Expand Shadbala comparison case count before changing any production-tuning claim.",
"Do not apply a global scaling factor when component-level deltas disagree by planet.",
],
}
def main() -> None:
parser = argparse.ArgumentParser(description="Build a compact batched oracle closure report")
parser.add_argument("--oracle-file", default="references/oracle/dasha_shadbala_oracle_cases.json")
parser.add_argument("--format", choices=("json", "markdown"), default="json")
args = parser.parse_args()
report = build_report(args.oracle_file)
if args.format == "markdown":
lines = [
"# Oracle Batch Closure Pack",
"",
f"- dasha_can_claim_closure: `{str(report['summary']['dasha_can_claim_closure']).lower()}`",
f"- shadbala_case_count: `{report['summary']['shadbala_case_count']}`",
f"- shadbala_within_tolerance_case_count: `{report['summary']['shadbala_within_tolerance_case_count']}`",
f"- global_oracle_closure_blocked: `{str(report['summary']['global_oracle_closure_blocked']).lower()}`",
"",
"| Kind | Case | Status | Notes |",
"| --- | --- | --- | --- |",
]
for row in report["rows"]:
if row["kind"] == "dasha":
lines.append(
f"| dasha | target_set | {'closed' if row['can_claim_dasha_oracle_closure'] else 'open'} | "
f"{row['external_verified_dasha_tasks']}/{row['dasha_task_count']} external verified |"
)
else:
lines.append(
f"| shadbala | {row['case_id']} | {row['status']} | "
f"{row['planets_within_total_tolerance']}/{row['planet_count']} planets within tolerance; "
f"max delta {row['max_abs_total_delta_rupa']} |"
)
print("\n".join(lines))
return
print(json.dumps(report, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
+128
View File
@@ -0,0 +1,128 @@
#!/usr/bin/env python3
"""Build a compact closure report for VedAstro strict ingestion."""
from __future__ import annotations
import json
import os
import subprocess
import sys
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
PYTHON = sys.executable
def _run_json(args: list[str], env: dict[str, str] | None = None) -> dict[str, Any]:
completed = subprocess.run(
[PYTHON, "scripts/vedastro_service_adapter.py", *args],
cwd=ROOT,
text=True,
capture_output=True,
timeout=120,
check=False,
env=env,
)
if completed.returncode != 0:
raise RuntimeError(completed.stderr.strip() or completed.stdout.strip())
return json.loads(completed.stdout)
def build_report() -> dict[str, Any]:
schema = _run_json(["--print-schema"])
unconfigured_env = os.environ.copy()
unconfigured_env.pop("VEDASTRO_API_ENDPOINT", None)
unconfigured_env.pop("VEDASTRO_ENABLE_NETWORK", None)
unconfigured_env["JYOTISH_SKIP_LOCAL_ENV"] = "1"
unconfigured = _run_json(
["--range-scan", "--domain", "marriage", "--case", "beijing_first_use_demo", "--start-date", "2026-01-01", "--end-date", "2031-01-01"],
env=unconfigured_env,
)
preview_env = os.environ.copy()
preview_env["VEDASTRO_API_ENDPOINT"] = "https://example.invalid/vedastro"
preview_env.pop("VEDASTRO_ENABLE_NETWORK", None)
preview_env["JYOTISH_SKIP_LOCAL_ENV"] = "1"
preview = _run_json(
["--range-scan", "--domain", "wealth", "--case", "beijing_first_use_demo", "--start-date", "2026-01-01", "--end-date", "2031-01-01"],
env=preview_env,
)
life_event_graph_test = subprocess.run(
[
PYTHON,
"-m",
"pytest",
"tests/test_life_event_graph_v1.py",
"-q",
"-k",
"vedastro or strict_workflow_accepts_adapter_range_scan_result_without_manual_repackaging",
],
cwd=ROOT,
text=True,
capture_output=True,
timeout=120,
check=False,
)
life_event_graph_accepts_external_window = life_event_graph_test.returncode == 0
return {
"scope": "vedastro_ingestion_closure_pack",
"schema_version": 1,
"summary": {
"range_scan_domains": sorted(schema["range_scan_event_allowlist"].keys()),
"schema_declares_allowlist": "range_scan_event_allowlist" in schema,
"unconfigured_status": unconfigured["status"],
"network_preview_status": preview["status"],
"life_event_graph_accepts_external_window": life_event_graph_accepts_external_window,
"global_live_closure_blocked": True,
},
"rows": [
{
"kind": "schema",
"allowlist_domains": sorted(schema["range_scan_event_allowlist"].keys()),
"coverage": schema["vedastro_calculation_coverage"],
},
{
"kind": "blocked_boundary",
"status": unconfigured["status"],
"domain": unconfigured["request_preview"]["domain"],
"event_method": unconfigured["request_preview"]["vedastro_event_method"],
},
{
"kind": "network_preview",
"status": preview["status"],
"domain": preview["request_preview"]["domain"],
"event_method": preview["request_preview"]["vedastro_event_method"],
},
{
"kind": "life_event_graph",
"status": "pass" if life_event_graph_accepts_external_window else "fail",
"test_selector": (
"tests/test_life_event_graph_v1.py "
"-k 'vedastro or strict_workflow_accepts_adapter_range_scan_result_without_manual_repackaging'"
),
},
],
"boundary": (
"This pack reuses the existing VedAstro adapter schema, blocked boundary, network-preview boundary, "
"and Life Event Graph ingestion tests. It does not claim live official endpoint closure."
),
"next_actions": [
"Keep using the adapter allowlist contract instead of inventing a second filtering layer.",
"Keep the live path blocked until a real endpoint-backed smoke is configured.",
"Only promote allowlisted external_window signals into strict workflow secondary evidence.",
],
}
def main() -> None:
report = build_report()
print(json.dumps(report, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()