File size: 1,610 Bytes
90329e9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #!/usr/bin/env python3
"""Inspect a redacted Task B observation JSON without importing the simulator.
Input: a JSON file containing an observation-like mapping.
Output: a stable tree of keys, Python types, and list shapes.
The tool intentionally does not read simulator ground truth or model checkpoints.
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from typing import Any
def shape(value: Any) -> list[int]:
result: list[int] = []
current = value
while isinstance(current, list):
result.append(len(current))
if not current:
break
current = current[0]
return result
def walk(value: Any, path: str = "obs") -> list[dict[str, Any]]:
rows: list[dict[str, Any]] = []
if isinstance(value, dict):
rows.append({"path": path, "type": "dict", "keys": sorted(value)})
for key in sorted(value):
rows.extend(walk(value[key], f"{path}.{key}"))
elif isinstance(value, list):
rows.append({"path": path, "type": "list", "shape": shape(value)})
if value and isinstance(value[0], (dict, list)):
rows.extend(walk(value[0], f"{path}[0]"))
else:
rows.append({"path": path, "type": type(value).__name__})
return rows
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--input", required=True, type=Path)
args = parser.parse_args()
payload = json.loads(args.input.read_text(encoding="utf-8"))
print(json.dumps(walk(payload), ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
|