"""Explicit one-profile persona backfill. Never called by server startup. This task exercises this function only on synthetic local databases. Deployment and authorization for any existing 8310/8320 profile remain a separate handoff. """ import argparse import asyncio import json from pathlib import Path import yaml from cybergril.config import ModelsConfig from cybergril.life.model import PersistentBudget from cybergril.life.persona import Persona, fingerprint from cybergril.memory.store import Store from cybergril.think.wiring import build_router_from_config async def backfill(path, expected): models = ModelsConfig(**yaml.safe_load(Path("config/models.yaml").read_text())) router = build_router_from_config(models) try: with Store(path) as store: before = fingerprint(store) if before != expected: raise ValueError("core fingerprint does not match explicit authorization") router.guard = PersistentBudget(store, router.guard) persona = Persona(store, router, models, enabled=True) ok = await persona.ensure(backfill=True) assert fingerprint(store) == before print(json.dumps({"ok": ok, "core_unchanged": True, "state": persona.view()["state"]})) return ok finally: for tier in router.available_tiers(): await router.provider_for(tier).aclose() if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--db", type=Path, required=True) parser.add_argument("--authorize-core-sha256", required=True) args = parser.parse_args() if not args.db.is_file(): parser.error("existing explicitly authorized database required") raise SystemExit(0 if asyncio.run(backfill(args.db, args.authorize_core_sha256)) else 1)