feat(oracle): add dasha closure status board
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Report the shortest path to the first Dasha external-oracle closure."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PYTHON = sys.executable
|
||||
FIRST_PRIORITY_CASE_ID = "template_steve_jobs_dasha_lahiri"
|
||||
DASHA_TARGET_FIELD = "target.vimshottari_start_date"
|
||||
|
||||
|
||||
def _run_json(command: list[str]) -> dict[str, Any]:
|
||||
completed = subprocess.run(
|
||||
command,
|
||||
cwd=ROOT,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
timeout=60,
|
||||
check=False,
|
||||
)
|
||||
if completed.returncode != 0:
|
||||
raise RuntimeError(completed.stderr.strip() or completed.stdout.strip())
|
||||
return json.loads(completed.stdout)
|
||||
|
||||
|
||||
def _metadata_missing(packet: dict[str, Any]) -> list[str]:
|
||||
metadata = packet.get("metadata", {})
|
||||
missing: list[str] = []
|
||||
for field in packet.get("required_metadata_fields", []):
|
||||
value = metadata.get(field)
|
||||
if value is None or value == "" or value == [] or value == {}:
|
||||
missing.append(f"metadata.{field}")
|
||||
source_artifact = metadata.get("source_artifact")
|
||||
if source_artifact in {"references/oracle/artifacts/", "references/oracle/artifacts", "", None}:
|
||||
if "metadata.source_artifact" not in missing:
|
||||
missing.append("metadata.source_artifact")
|
||||
return missing
|
||||
|
||||
|
||||
def _target_missing(packet: dict[str, Any], fields: list[str]) -> list[str]:
|
||||
placeholders = packet.get("target_placeholders", {})
|
||||
missing: list[str] = []
|
||||
for field in fields:
|
||||
value = placeholders.get(field)
|
||||
if value is None or value == "" or value == [] or value == {}:
|
||||
missing.append(field)
|
||||
return missing
|
||||
|
||||
|
||||
def _apply_command(packet_path: str, oracle_file: str) -> str:
|
||||
return (
|
||||
"python3 scripts/oracle_collection_queue.py "
|
||||
f"--oracle-file {oracle_file} "
|
||||
f"--apply-packet {packet_path} "
|
||||
"--format json"
|
||||
)
|
||||
|
||||
|
||||
def _validate_command(oracle_file: str) -> str:
|
||||
return (
|
||||
"python3 scripts/oracle_collection_queue.py "
|
||||
f"--oracle-file {oracle_file} --format json > /tmp/jyotish_oracle_queue_filled.json && "
|
||||
"python3 scripts/oracle_evidence_validator.py --queue-file /tmp/jyotish_oracle_queue_filled.json"
|
||||
)
|
||||
|
||||
|
||||
def build_status(oracle_file: str) -> dict[str, Any]:
|
||||
queue = _run_json([PYTHON, "scripts/oracle_collection_queue.py", "--oracle-file", oracle_file, "--format", "json"])
|
||||
dasha_tasks = [
|
||||
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]
|
||||
if priority is None:
|
||||
raise RuntimeError("No Dasha target task found")
|
||||
|
||||
packet = priority["evidence_packet"]
|
||||
capture_id = packet["capture_id"]
|
||||
packet_path = f"references/oracle/artifacts/pending_packets/{capture_id}.json"
|
||||
required_target_fields = [DASHA_TARGET_FIELD]
|
||||
missing_fields = _metadata_missing(packet) + _target_missing(packet, required_target_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)
|
||||
]
|
||||
|
||||
return {
|
||||
"scope": "dasha_external_oracle_closure_status",
|
||||
"schema_version": 1,
|
||||
"summary": {
|
||||
"dasha_task_count": len(dasha_tasks),
|
||||
"external_verified_dasha_tasks": len(external_verified),
|
||||
"can_claim_dasha_oracle_closure": bool(dasha_tasks) and len(external_verified) == len(dasha_tasks),
|
||||
"production_tuning_allowed": False,
|
||||
},
|
||||
"first_priority": {
|
||||
"case_id": priority["case_id"],
|
||||
"capture_id": capture_id,
|
||||
"packet_path": packet_path,
|
||||
"birth": priority.get("birth", {}),
|
||||
"settings": priority.get("settings", {}),
|
||||
"required_target_fields": required_target_fields,
|
||||
"missing_fields": missing_fields,
|
||||
"external_sources": [
|
||||
"JHora Vimshottari Dasha screenshot",
|
||||
"PyJHora black-box dasha output",
|
||||
"documented printed/software example",
|
||||
],
|
||||
"artifact_policy": "Save redacted screenshots or stdout snippets under references/oracle/artifacts/.",
|
||||
"apply_command": _apply_command(packet_path, oracle_file),
|
||||
"validate_command": _validate_command(oracle_file),
|
||||
},
|
||||
"next_actions": [
|
||||
"Open the first priority packet and fill metadata from an external oracle.",
|
||||
"Fill target.vimshottari_start_date only from JHora/PyJHora/book example, not from this repository.",
|
||||
"Set status to external_verified after the artifact path and Dasha target are filled.",
|
||||
"Apply the packet, regenerate the queue, and run oracle_evidence_validator.py.",
|
||||
],
|
||||
"boundary": (
|
||||
"This board isolates the Dasha shortest path. Shadbala remains a separate absolute-value "
|
||||
"closure task and must not block collecting the first Dasha boundary date."
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def render_markdown(report: dict[str, Any]) -> str:
|
||||
summary = report["summary"]
|
||||
first = report["first_priority"]
|
||||
lines = [
|
||||
"# Dasha External Oracle Closure Status",
|
||||
"",
|
||||
f"- dasha_task_count: `{summary['dasha_task_count']}`",
|
||||
f"- external_verified_dasha_tasks: `{summary['external_verified_dasha_tasks']}`",
|
||||
f"- can_claim_dasha_oracle_closure: `{str(summary['can_claim_dasha_oracle_closure']).lower()}`",
|
||||
f"- production_tuning_allowed: `{str(summary['production_tuning_allowed']).lower()}`",
|
||||
"",
|
||||
"## First Priority Packet",
|
||||
"",
|
||||
f"- case_id: `{first['case_id']}`",
|
||||
f"- capture_id: `{first['capture_id']}`",
|
||||
f"- packet_path: `{first['packet_path']}`",
|
||||
f"- required_target_fields: `{', '.join(first['required_target_fields'])}`",
|
||||
f"- missing_fields: `{', '.join(first['missing_fields'])}`",
|
||||
"",
|
||||
"## Commands",
|
||||
"",
|
||||
"```bash",
|
||||
first["apply_command"],
|
||||
"```",
|
||||
"",
|
||||
"```bash",
|
||||
first["validate_command"],
|
||||
"```",
|
||||
"",
|
||||
"## Next Actions",
|
||||
"",
|
||||
]
|
||||
lines.extend(f"- {item}" for item in report["next_actions"])
|
||||
lines.extend(["", "## Boundary", "", report["boundary"], ""])
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description="Report Dasha external oracle closure status")
|
||||
parser.add_argument("--oracle-file", default="references/oracle/dasha_shadbala_oracle_cases.json")
|
||||
parser.add_argument("--format", choices=["json", "markdown"], default="json")
|
||||
parser.add_argument("--output", help="Optional output path")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
args = parse_args(argv)
|
||||
report = build_status(args.oracle_file)
|
||||
text = json.dumps(report, ensure_ascii=False, indent=2) if args.format == "json" else render_markdown(report)
|
||||
if args.output:
|
||||
output = Path(args.output)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_text(text, encoding="utf-8")
|
||||
print(text)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user