release: Mantoz — population-scale evaluation with simulated personas
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Offline self-check for a fresh clone of Mantoz.
|
||||
|
||||
Runs with the standard library only: no network, no Docker, no Harbor, no git.
|
||||
It proves the tree a stranger just downloaded is internally consistent — the
|
||||
schemas parse, the persona dependency graph has no cycle, the grounding
|
||||
registry still separates what may be redistributed from what may not, and the
|
||||
attribution required by the licenses is actually present in the files.
|
||||
|
||||
Exit code 0 means every check passed. Any failure prints the reason and exits 1.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
FAILURES: list[str] = []
|
||||
PASSED: list[str] = []
|
||||
|
||||
|
||||
def check(name: str, condition: bool, detail: str = "") -> None:
|
||||
if condition:
|
||||
PASSED.append(name)
|
||||
else:
|
||||
FAILURES.append(f"{name}: {detail}" if detail else name)
|
||||
|
||||
|
||||
def load_json(relative: str):
|
||||
path = ROOT / relative
|
||||
if not path.is_file():
|
||||
FAILURES.append(f"missing file: {relative}")
|
||||
return None
|
||||
try:
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
except (json.JSONDecodeError, UnicodeDecodeError) as error:
|
||||
FAILURES.append(f"unreadable JSON: {relative}: {error}")
|
||||
return None
|
||||
|
||||
|
||||
def check_persona_schema() -> None:
|
||||
schema = load_json("persona/schema/dimensions.json")
|
||||
if schema is None:
|
||||
return
|
||||
dimensions = schema.get("dimensions", [])
|
||||
ids = [item.get("id") for item in dimensions]
|
||||
categories = {item.get("category") for item in dimensions}
|
||||
check("persona schema has dimensions", len(dimensions) >= 40, f"found {len(dimensions)}")
|
||||
check("persona dimension ids are unique", len(ids) == len(set(ids)))
|
||||
check("persona schema keeps four categories", len(categories) == 4, f"found {sorted(categories)}")
|
||||
for item in dimensions:
|
||||
if not item.get("values"):
|
||||
FAILURES.append(f"dimension without values: {item.get('id')}")
|
||||
return
|
||||
PASSED.append("every persona dimension carries values")
|
||||
|
||||
|
||||
def check_persona_dag() -> None:
|
||||
schema = load_json("persona/schema/dimensions.json")
|
||||
edges_file = load_json("persona/schema/dependencies.json")
|
||||
if schema is None or edges_file is None:
|
||||
return
|
||||
known = {item.get("id") for item in schema.get("dimensions", [])}
|
||||
edges = edges_file.get("edges", edges_file.get("dependencies", []))
|
||||
graph: dict[str, set[str]] = {}
|
||||
for edge in edges:
|
||||
parent = edge.get("parent") or edge.get("from")
|
||||
child = edge.get("child") or edge.get("to")
|
||||
if parent not in known or child not in known:
|
||||
FAILURES.append(f"dependency edge points outside the schema: {parent} -> {child}")
|
||||
return
|
||||
graph.setdefault(parent, set()).add(child)
|
||||
check("persona dependency graph is not empty", bool(graph))
|
||||
|
||||
colour: dict[str, int] = {}
|
||||
|
||||
def has_cycle(node: str) -> bool:
|
||||
colour[node] = 1
|
||||
for nxt in graph.get(node, ()): # grey means we are back on our own path
|
||||
if colour.get(nxt) == 1:
|
||||
return True
|
||||
if colour.get(nxt) is None and has_cycle(nxt):
|
||||
return True
|
||||
colour[node] = 2
|
||||
return False
|
||||
|
||||
for node in list(graph):
|
||||
if colour.get(node) is None and has_cycle(node):
|
||||
FAILURES.append(f"persona dependency graph has a cycle through {node}")
|
||||
return
|
||||
PASSED.append("persona dependency graph is acyclic")
|
||||
|
||||
|
||||
def check_grounding_registry() -> None:
|
||||
registry = load_json("config/grounding.json")
|
||||
if registry is None:
|
||||
return
|
||||
sources = registry["sources"] if isinstance(registry, dict) else registry
|
||||
check("grounding registry lists sources", bool(sources))
|
||||
commercial = [s for s in sources if s.get("commercial_use") is True]
|
||||
check("at least one source allows commercial use", bool(commercial))
|
||||
for source in sources:
|
||||
if source.get("commercial_use") is True:
|
||||
continue
|
||||
if source.get("local_only") is not True:
|
||||
FAILURES.append(
|
||||
f"source {source.get('id')} is not cleared for commercial use "
|
||||
"and is not marked local_only"
|
||||
)
|
||||
return
|
||||
PASSED.append("every restricted grounding source is marked local_only")
|
||||
|
||||
|
||||
def check_agent_registry() -> None:
|
||||
registry = load_json("config/agents.json")
|
||||
if registry is None:
|
||||
return
|
||||
agents = registry["agents"] if isinstance(registry, dict) else registry
|
||||
check("agent registry holds at least ten entries", len(agents) >= 10, f"found {len(agents)}")
|
||||
ids = [agent.get("id") for agent in agents]
|
||||
check("agent ids are unique", len(ids) == len(set(ids)))
|
||||
|
||||
|
||||
def check_task_contracts() -> None:
|
||||
tasks = sorted((ROOT / "application" / "tasks").glob("*/"))
|
||||
check("task library is not empty", bool(tasks))
|
||||
for task in tasks:
|
||||
for required in ("task.toml", "instruction.md", "tests/test.sh"):
|
||||
if not (task / required).is_file():
|
||||
FAILURES.append(f"task {task.name} is missing {required}")
|
||||
return
|
||||
PASSED.append("every task carries a contract, an instruction and its own verifier")
|
||||
|
||||
|
||||
def check_parity_checklist() -> None:
|
||||
path = ROOT / "docs" / "PARITY.md"
|
||||
if not path.is_file():
|
||||
FAILURES.append("missing file: docs/PARITY.md")
|
||||
return
|
||||
rows = [line for line in path.read_text(encoding="utf-8").splitlines() if line.startswith("|")]
|
||||
open_rows = []
|
||||
for row in rows:
|
||||
cells = [cell.strip() for cell in row.strip("|").split("|")]
|
||||
if len(cells) < 4:
|
||||
continue
|
||||
status = cells[2]
|
||||
if status.startswith("отсутствует") and not re.search(r"OUT-\d{2}", cells[3]):
|
||||
open_rows.append(cells[1][:60])
|
||||
check("parity checklist has no unjustified gap", not open_rows, "; ".join(open_rows))
|
||||
check("parity checklist has real rows", len(rows) > 10, f"found {len(rows)}")
|
||||
|
||||
|
||||
def check_attribution() -> None:
|
||||
notice = (ROOT / "NOTICE").read_text(encoding="utf-8") if (ROOT / "NOTICE").is_file() else ""
|
||||
check("NOTICE credits Harbor", "harbor-framework" in notice)
|
||||
check("NOTICE names the Apache-2.0 license", "Apache License" in notice)
|
||||
readme = (ROOT / "README.md").read_text(encoding="utf-8") if (ROOT / "README.md").is_file() else ""
|
||||
check("README cites the persona research", "arXiv:2608.04205" in readme)
|
||||
check("LICENSE is present", (ROOT / "LICENSE").is_file())
|
||||
|
||||
|
||||
def check_data_boundary() -> None:
|
||||
ignore = (ROOT / ".gitignore").read_text(encoding="utf-8") if (ROOT / ".gitignore").is_file() else ""
|
||||
check("data/ is ignored by git", any(line.strip() in {"data/", "/data/"} for line in ignore.splitlines()))
|
||||
stray = [str(p.relative_to(ROOT)) for p in ROOT.rglob("*.sav")] + \
|
||||
[str(p.relative_to(ROOT)) for p in ROOT.rglob("*.dta")] + \
|
||||
[str(p.relative_to(ROOT)) for p in ROOT.rglob("*.marginals.json")]
|
||||
check("no restricted survey data sits in the tree", not stray, ", ".join(stray[:5]))
|
||||
|
||||
|
||||
def main() -> int:
|
||||
check_persona_schema()
|
||||
check_persona_dag()
|
||||
check_grounding_registry()
|
||||
check_agent_registry()
|
||||
check_task_contracts()
|
||||
check_parity_checklist()
|
||||
check_attribution()
|
||||
check_data_boundary()
|
||||
|
||||
for name in PASSED:
|
||||
print(f"ok {name}")
|
||||
for failure in FAILURES:
|
||||
print(f"FAIL {failure}", file=sys.stderr)
|
||||
if FAILURES:
|
||||
print(f"\n{len(FAILURES)} check(s) failed", file=sys.stderr)
|
||||
return 1
|
||||
print(f"\nall {len(PASSED)} checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# Offline self-check of a fresh clone: no network, no Docker, no Harbor, no git.
|
||||
# Accepts --selftest so the release gate can discover and run it.
|
||||
set -e
|
||||
cd "$(dirname "$0")/.."
|
||||
PY=python3
|
||||
command -v "$PY" >/dev/null 2>&1 || { echo "mantoz-selfcheck: python3 not found" >&2; exit 1; }
|
||||
exec "$PY" scripts/mantoz-selfcheck.py "$@"
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Carve the workflow labels onto the blank marble plates of the takt frame.
|
||||
|
||||
The takt frame is one generated image with five blank plates. The words on those
|
||||
plates differ per README language, and an image model cannot be trusted to write
|
||||
Cyrillic or Chinese correctly, so the text is composited here instead: the same
|
||||
plates, the same geometry, three deterministic outputs.
|
||||
|
||||
python3 scripts/pantheon-takt.py
|
||||
|
||||
Reads the plate rectangles from .github/pantheon/takt-plity.json and the labels
|
||||
from the stages of .github/pantheon.json, writes docs/assets/pantheon/takt-<lang>.png.
|
||||
|
||||
Needs Pillow. It is a build tool for the project's own assets, not a runtime
|
||||
dependency: `python3 -m pip install pillow` before running it.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
SOURCE = ROOT / "docs/assets/pantheon/takt.png"
|
||||
PLATES = ROOT / ".github/pantheon/takt-plity.json"
|
||||
MANIFEST = ROOT / ".github/pantheon.json"
|
||||
|
||||
FONTS = {
|
||||
"en": "/System/Library/Fonts/Supplemental/Times New Roman.ttf",
|
||||
"ru": "/System/Library/Fonts/Supplemental/Times New Roman.ttf",
|
||||
"zh": "/System/Library/Fonts/Supplemental/Songti.ttc",
|
||||
}
|
||||
CARVED = (62, 58, 54) # charcoal of the palette
|
||||
HIGHLIGHT = (255, 253, 248) # the lit lower edge of a real groove
|
||||
|
||||
|
||||
def fit(text: str, font_path: str, box_w: int, box_h: int) -> ImageFont.FreeTypeFont:
|
||||
"""Largest size that still leaves a margin inside the plate."""
|
||||
size = box_h
|
||||
while size > 8:
|
||||
font = ImageFont.truetype(font_path, size)
|
||||
left, top, right, bottom = font.getbbox(text)
|
||||
if right - left <= box_w * 0.78 and bottom - top <= box_h * 0.42:
|
||||
return font
|
||||
size -= 2
|
||||
return ImageFont.truetype(font_path, 10)
|
||||
|
||||
|
||||
def carve(language: str, labels: list[str], plates: list[dict]) -> Path:
|
||||
image = Image.open(SOURCE).convert("RGB")
|
||||
draw = ImageDraw.Draw(image)
|
||||
# One size for the whole row. Fitting each plate on its own makes the short
|
||||
# words huge and the long ones tiny, and the row stops reading as one frame.
|
||||
size = min(fit(label, FONTS[language], plate["w"], plate["h"]).size
|
||||
for label, plate in zip(labels, plates))
|
||||
shared = ImageFont.truetype(FONTS[language], size)
|
||||
for label, plate in zip(labels, plates):
|
||||
font = shared
|
||||
left, top, right, bottom = draw.textbbox((0, 0), label, font=font)
|
||||
x = plate["x"] + (plate["w"] - (right - left)) / 2 - left
|
||||
y = plate["y"] + (plate["h"] - (bottom - top)) / 2 - top
|
||||
# A groove reads as a dark cut with one lit edge just below it.
|
||||
draw.text((x + 1, y + 1), label, font=font, fill=HIGHLIGHT)
|
||||
draw.text((x, y), label, font=font, fill=CARVED)
|
||||
out = ROOT / f"docs/assets/pantheon/takt-{language}.png"
|
||||
image.save(out)
|
||||
return out
|
||||
|
||||
|
||||
def main() -> int:
|
||||
for path in (SOURCE, PLATES, MANIFEST):
|
||||
if not path.is_file():
|
||||
print(f"missing: {path.relative_to(ROOT)}", file=sys.stderr)
|
||||
return 1
|
||||
plates = json.loads(PLATES.read_text(encoding="utf-8"))
|
||||
stages = json.loads(MANIFEST.read_text(encoding="utf-8"))["visuals"]["stages"]
|
||||
if len(plates) != len(stages):
|
||||
print(f"{len(plates)} plates but {len(stages)} stages", file=sys.stderr)
|
||||
return 1
|
||||
for language in FONTS:
|
||||
labels = [stage[f"diagram_{language}"] for stage in stages]
|
||||
print("written", carve(language, labels, plates).relative_to(ROOT))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user