Hand-offs without GitHub: bot kit zip, bot zip import, local refresh

- python -m collection export-bot-kit: policy.json, solver.js, graph.js and a
  README with checksums, zipped for the bot
- the bot import takes a folder or a zip (files may sit under any top folder)
- python -m collection refresh: the daily workflow, run locally
- trajectories files are named by date and raw checksum, so two imports on
  one day never overwrite each other

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
ekcSchiano
2026-11-10 01:50:12 +00:00
co-authored by Claude Opus 5.5
parent 19209a2ad6
commit 5c49591dae
7 changed files with 174 additions and 2 deletions
+82
View File
@@ -0,0 +1,82 @@
"""Hand-offs without GitHub: the zip of atlas files for the bot, and the local equivalent of the daily workflow.
python -m collection export-bot-kit -> exports/atlas-for-bot-<date>-<policy id>.zip
policy.json, solver.js and graph.js (what the bot vendors into vendor/threshing-atlas/), plus a README and
checksums. Send it to the bot's maintainer; they unzip it into vendor/threshing-atlas/.
python -m collection refresh [--bot PATH ...]
Every source (and any bot folders or zips given), then the graph, the route model, the statistics and the
build: what .github/workflows/update-sources.yml does every day.
"""
import hashlib
import json
import shutil
import subprocess
import sys
import zipfile
from datetime import datetime, timezone
from .common import ROOT, path
KIT = {"policy.json": "data/public/policy.json", "solver.js": "core/solver.js", "graph.js": "core/graph.js"}
README = """Threshing Atlas files for the DragonKind bot
============================================
Policy id: {policy}
Made: {made}
Unzip these three files into the bot's vendor/threshing-atlas/ folder, replacing the old ones, and keep them
together: solver.js reads the game from this policy.json.
policy.json the route model (the game, the counts behind every roll, the best routes per colour)
solver.js the advisor: advisor(), recommendOption(), solverHistory()
graph.js trajectoryVariables(): the bot's steps -> the community form's variables
How the bot uses them: docs/BOT_INTEGRATION.md in the atlas repo. Log the policy id above as policyId on each run.
Checksums (sha256):
{sums}
To send runs back: zip the bot's data/runs.jsonl, data/knowledge.json and logs/encounters.jsonl (keep the folder
names) and send the zip. It is imported with `python -m collection refresh --bot <the zip>`; only anonymised
steps and outcomes are kept (no game prose, no account names).
"""
def export_bot_kit(out_dir="exports"):
policy = json.loads(path(KIT["policy.json"]).read_text(encoding="utf-8"))
pid = str(policy.get("id", "unknown"))[:12]
made = datetime.now(timezone.utc).strftime("%Y-%m-%d")
sums = "\n".join(f" {hashlib.sha256(path(src).read_bytes()).hexdigest()} {name}" for name, src in KIT.items())
out = path(out_dir)
out.mkdir(parents=True, exist_ok=True)
zpath = out / f"atlas-for-bot-{made}-{pid}.zip"
with zipfile.ZipFile(zpath, "w", zipfile.ZIP_DEFLATED) as z:
for name, src in KIT.items():
z.writestr(zipfile.ZipInfo(name, (2026, 1, 1, 0, 0, 0)), path(src).read_bytes(), zipfile.ZIP_DEFLATED)
z.writestr(zipfile.ZipInfo("README.txt", (2026, 1, 1, 0, 0, 0)), README.format(policy=pid, made=made, sums=sums))
return zpath
def _step(label, cmd):
print(f"\n== {label}: {' '.join(cmd)}", flush=True)
subprocess.run(cmd, cwd=ROOT, check=True)
def refresh(update_main, bots=()):
"""update -> (graph, policy, stats, build) when something changed. Returns 0 on success."""
py = sys.executable
args = ["update", "--report", str(path("exports/last-report.md"))]
path("exports").mkdir(exist_ok=True)
rc = update_main(args)
for i, b in enumerate(bots):
rc |= update_main(["update", "--source", "bot", "--file", f"bot={b}", "--report", str(path(f"exports/last-report-bot{i + 1}.md"))])
if shutil.which("node"):
_step("route graph", ["node", "analysis/network/build-graph.js"])
else:
print("\n(node is not installed: data/public/graph.json is not rebuilt; everything else is)")
_step("route model (about 2 minutes)", [py, "planner/build_policy.py"])
_step("statistics", [py, "analysis/stats/site_stats.py"])
_step("runs, generated files and metadata", [py, "-m", "collection", "build"])
print(f"\nDone. What changed: exports/last-report.md. Send the bot its files with: {py} -m collection export-bot-kit")
return rc