feat(skill): validate dasha oracle evidence
This commit is contained in:
@@ -56,6 +56,11 @@ def _target_missing(packet: dict[str, Any], fields: list[str]) -> list[str]:
|
||||
return missing
|
||||
|
||||
|
||||
def _dasha_target_filled(task: dict[str, Any], fields: list[str]) -> bool:
|
||||
packet = task.get("evidence_packet", {})
|
||||
return task.get("status") == "external_verified" and not _target_missing(packet, fields)
|
||||
|
||||
|
||||
def _group_missing_fields(missing_fields: list[str]) -> dict[str, Any]:
|
||||
metadata_fields = [field for field in missing_fields if field.startswith("metadata.")]
|
||||
target_fields = [field for field in missing_fields if field.startswith("target.")]
|
||||
@@ -122,9 +127,15 @@ def build_status(oracle_file: str) -> dict[str, Any]:
|
||||
task for task in queue.get("tasks", [])
|
||||
if DASHA_TARGET_FIELD in task.get("target_fields", [])
|
||||
]
|
||||
priority = next((task for task in dasha_tasks if task.get("case_id") == FIRST_PRIORITY_CASE_ID), None)
|
||||
if priority is None and dasha_tasks:
|
||||
priority = dasha_tasks[0]
|
||||
required_target_fields = [DASHA_TARGET_FIELD]
|
||||
unverified_dasha_tasks = [
|
||||
task for task in dasha_tasks
|
||||
if not _dasha_target_filled(task, required_target_fields)
|
||||
]
|
||||
priority_pool = unverified_dasha_tasks or dasha_tasks
|
||||
priority = next((task for task in priority_pool if task.get("case_id") == FIRST_PRIORITY_CASE_ID), None)
|
||||
if priority is None and priority_pool:
|
||||
priority = priority_pool[0]
|
||||
if priority is None:
|
||||
raise RuntimeError("No Dasha target task found")
|
||||
|
||||
@@ -133,12 +144,11 @@ def build_status(oracle_file: str) -> dict[str, Any]:
|
||||
packet_path = f"references/oracle/artifacts/pending_packets/{capture_id}.json"
|
||||
template_path = FIRST_PRIORITY_TEMPLATE_PATH if priority["case_id"] == FIRST_PRIORITY_CASE_ID else packet_path
|
||||
packet = json.loads((ROOT / template_path).read_text(encoding="utf-8"))
|
||||
required_target_fields = [DASHA_TARGET_FIELD]
|
||||
missing_fields = _metadata_missing(packet) + _target_missing(packet, required_target_fields)
|
||||
missing_groups = _group_missing_fields(missing_fields)
|
||||
external_verified = [
|
||||
task for task in dasha_tasks
|
||||
if task.get("status") == "external_verified" and not _target_missing(task.get("evidence_packet", {}), required_target_fields)
|
||||
if _dasha_target_filled(task, required_target_fields)
|
||||
]
|
||||
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Validate Dasha-only external oracle evidence packets.
|
||||
|
||||
The generic oracle evidence validator is intentionally strict for combined
|
||||
Dasha/Shadbala rows. This validator isolates the Dasha closure path so one
|
||||
external Vimshottari boundary can be accepted without waiting for Shadbala
|
||||
absolute-value components.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
DASHA_TARGET_FIELD = "target.vimshottari_start_date"
|
||||
LOCAL_ENGINE_MARKERS = [
|
||||
"local engine",
|
||||
"this-repo",
|
||||
"jyotish_engine.py",
|
||||
"scripts/jyotish",
|
||||
"oracle_collection_queue.py",
|
||||
"oracle_boundary_audit.py",
|
||||
]
|
||||
|
||||
|
||||
def _resolve_path(path: str) -> str:
|
||||
if os.path.isabs(path):
|
||||
return path
|
||||
return os.path.join(ROOT_DIR, path)
|
||||
|
||||
|
||||
def _load_json(path: str) -> dict[str, Any]:
|
||||
with open(_resolve_path(path), "r", encoding="utf-8") as fh:
|
||||
return json.load(fh)
|
||||
|
||||
|
||||
def _is_blank(value: Any) -> bool:
|
||||
return value is None or value == "" or value == [] or value == {}
|
||||
|
||||
|
||||
def _is_missing_external_artifact(value: Any) -> bool:
|
||||
if _is_blank(value):
|
||||
return True
|
||||
text = str(value).strip()
|
||||
return text.endswith("/") or text in {"references/oracle/artifacts", "references/oracle/artifacts/"}
|
||||
|
||||
|
||||
def _artifact_exists(value: Any) -> bool:
|
||||
if _is_missing_external_artifact(value):
|
||||
return False
|
||||
return os.path.exists(_resolve_path(str(value)))
|
||||
|
||||
|
||||
def _is_local_engine_artifact(packet: dict[str, Any]) -> bool:
|
||||
metadata = packet.get("metadata", {})
|
||||
haystack = " ".join(
|
||||
str(metadata.get(field, ""))
|
||||
for field in ["tool_name", "tool_version_or_url", "source_artifact", "operator_note"]
|
||||
).lower()
|
||||
return any(marker in haystack for marker in LOCAL_ENGINE_MARKERS)
|
||||
|
||||
|
||||
def _valid_iso_date(value: Any) -> bool:
|
||||
return isinstance(value, str) and re.fullmatch(r"\d{4}-\d{2}-\d{2}", value) is not None
|
||||
|
||||
|
||||
def _validate_dasha_packet(task: dict[str, Any]) -> dict[str, Any]:
|
||||
packet = task.get("evidence_packet", {})
|
||||
metadata = packet.get("metadata", {})
|
||||
placeholders = packet.get("target_placeholders", {})
|
||||
problems: list[str] = []
|
||||
|
||||
for field in packet.get("required_metadata_fields", []):
|
||||
if _is_blank(metadata.get(field)):
|
||||
problems.append(f"missing_metadata:{field}")
|
||||
|
||||
source_artifact = metadata.get("source_artifact")
|
||||
if _is_missing_external_artifact(source_artifact):
|
||||
problems.append("missing_external_artifact")
|
||||
elif not _artifact_exists(source_artifact):
|
||||
problems.append("external_artifact_not_found")
|
||||
|
||||
if packet.get("status") != "external_verified":
|
||||
problems.append(f"status_not_external_verified:{packet.get('status', 'missing')}")
|
||||
|
||||
value = placeholders.get(DASHA_TARGET_FIELD)
|
||||
if _is_blank(value):
|
||||
problems.append(f"placeholder_unfilled:{DASHA_TARGET_FIELD}")
|
||||
elif not _valid_iso_date(value):
|
||||
problems.append(f"invalid_dasha_date:{DASHA_TARGET_FIELD}")
|
||||
|
||||
integrity = packet.get("integrity_checks", {})
|
||||
if integrity.get("must_not_come_from_local_engine") and _is_local_engine_artifact(packet):
|
||||
problems.append("local_engine_artifact_rejected")
|
||||
|
||||
valid = not problems
|
||||
return {
|
||||
"task_id": task.get("task_id"),
|
||||
"case_id": task.get("case_id"),
|
||||
"capture_id": packet.get("capture_id") or f"missing_capture_id:{task.get('case_id', 'unknown')}",
|
||||
"status": packet.get("status", "missing"),
|
||||
"target_field": DASHA_TARGET_FIELD,
|
||||
"valid": valid,
|
||||
"ready_for_dasha_calibration": valid and packet.get("status") == "external_verified",
|
||||
"problems": problems,
|
||||
}
|
||||
|
||||
|
||||
def build_report(queue: dict[str, Any]) -> dict[str, Any]:
|
||||
packets = [
|
||||
_validate_dasha_packet(task)
|
||||
for task in queue.get("tasks", [])
|
||||
if DASHA_TARGET_FIELD in task.get("target_fields", [])
|
||||
]
|
||||
valid_packets = sum(1 for packet in packets if packet["valid"])
|
||||
ready_for_dasha_calibration = sum(1 for packet in packets if packet["ready_for_dasha_calibration"])
|
||||
return {
|
||||
"scope": "dasha_external_oracle_evidence_validation",
|
||||
"schema_version": 1,
|
||||
"summary": {
|
||||
"total_dasha_packets": len(packets),
|
||||
"valid_dasha_packets": valid_packets,
|
||||
"ready_for_dasha_calibration": ready_for_dasha_calibration,
|
||||
"all_dasha_packets_external_verified": bool(packets) and valid_packets == len(packets),
|
||||
"production_tuning_allowed": bool(packets) and ready_for_dasha_calibration == len(packets),
|
||||
},
|
||||
"packets": packets,
|
||||
"boundary": (
|
||||
"This validator only accepts external Dasha boundary evidence. "
|
||||
"It does not validate Shadbala absolute values and must not be used to claim full oracle closure."
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description="Validate Dasha-only external oracle evidence packets")
|
||||
parser.add_argument("--queue-file", required=True, help="Path to oracle collection queue JSON")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
args = parse_args(argv)
|
||||
queue = _load_json(args.queue_file)
|
||||
print(json.dumps(build_report(queue), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -49,6 +49,15 @@ def _oracle_readiness(oracle_file: str) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _dasha_readiness(oracle_file: str) -> dict[str, Any]:
|
||||
queue = _run_json([PYTHON, "scripts/oracle_collection_queue.py", "--oracle-file", oracle_file, "--format", "json"])
|
||||
with tempfile.NamedTemporaryFile("w+", suffix=".json", encoding="utf-8", delete=True) as fh:
|
||||
json.dump(queue, fh, ensure_ascii=False)
|
||||
fh.flush()
|
||||
validation = _run_json([PYTHON, "scripts/dasha_oracle_evidence_validator.py", "--queue-file", fh.name])
|
||||
return validation["summary"]
|
||||
|
||||
|
||||
def _boundary_audit(oracle_file: str) -> dict[str, Any]:
|
||||
report = _run_json([PYTHON, "scripts/oracle_boundary_audit.py", "--oracle-file", oracle_file])
|
||||
summary = report["summary"]
|
||||
@@ -68,10 +77,12 @@ def build_dashboard(oracle_file: str) -> dict[str, Any]:
|
||||
capability = _run_json([PYTHON, "scripts/audit_capabilities.py", "--mode", "validate"])
|
||||
oracle = _oracle_readiness(oracle_file)
|
||||
boundary = _boundary_audit(oracle_file)
|
||||
dasha = _dasha_readiness(oracle_file)
|
||||
global_first_gap = (
|
||||
"Dasha/Shadbala external oracle readiness remains 0, Shadbala absolute values still need "
|
||||
"component-level external evidence, and public long-term benchmark history is not yet comparable "
|
||||
"to the strongest global open-source projects."
|
||||
f"Dasha-only external oracle readiness is {dasha['valid_dasha_packets']}/"
|
||||
f"{dasha['total_dasha_packets']}; Shadbala absolute values still need component-level "
|
||||
"external evidence, and public long-term benchmark history is not yet comparable to the strongest "
|
||||
"global open-source projects."
|
||||
)
|
||||
can_claim_global_first = bool(
|
||||
capability.get("valid")
|
||||
@@ -89,6 +100,7 @@ def build_dashboard(oracle_file: str) -> dict[str, Any]:
|
||||
"status_counts": capability["status_counts"],
|
||||
},
|
||||
"oracle_readiness": oracle,
|
||||
"dasha_oracle_readiness": dasha,
|
||||
"boundary_audit": boundary,
|
||||
"public_claim": {
|
||||
"can_claim_global_first": can_claim_global_first,
|
||||
@@ -99,7 +111,7 @@ def build_dashboard(oracle_file: str) -> dict[str, Any]:
|
||||
},
|
||||
"global_first_gap": global_first_gap,
|
||||
"next_actions": [
|
||||
"Fill the first external JHora/PyJHora packet under references/oracle/artifacts/pending_packets.",
|
||||
"Fill the next open external JHora/PyJHora packet under references/oracle/artifacts/pending_packets.",
|
||||
"Run oracle_evidence_validator.py until at least one packet is valid.",
|
||||
"Run oracle_boundary_audit.py to inspect Dasha/Shadbala deltas without tuning constants.",
|
||||
"Publish this dashboard after each validated sample batch.",
|
||||
@@ -109,6 +121,7 @@ def build_dashboard(oracle_file: str) -> dict[str, Any]:
|
||||
|
||||
def render_markdown(report: dict[str, Any]) -> str:
|
||||
oracle = report["oracle_readiness"]
|
||||
dasha = report["dasha_oracle_readiness"]
|
||||
boundary = report["boundary_audit"]
|
||||
claim = report["public_claim"]
|
||||
lines = [
|
||||
@@ -128,6 +141,8 @@ def render_markdown(report: dict[str, Any]) -> str:
|
||||
f"- valid_packets: `{oracle['valid_packets']}`",
|
||||
f"- ready_for_calibration: `{oracle['ready_for_calibration']}`",
|
||||
f"- production_tuning_allowed: `{str(oracle['production_tuning_allowed']).lower()}`",
|
||||
f"- valid_dasha_packets: `{dasha['valid_dasha_packets']}`",
|
||||
f"- total_dasha_packets: `{dasha['total_dasha_packets']}`",
|
||||
"",
|
||||
"## Boundary Audit",
|
||||
"",
|
||||
|
||||
Reference in New Issue
Block a user