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:
co-authored by
Claude Opus 5.5
parent
19209a2ad6
commit
5c49591dae
@@ -16,6 +16,7 @@ import shutil
|
||||
import tempfile
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import zipfile
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
@@ -92,6 +93,24 @@ def local_dir(spec, env):
|
||||
return json.dumps(files, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
|
||||
def pack_local(spec, src):
|
||||
"""The bot's files from a folder (a copy of the bot repo) or a .zip someone sent (the files may sit under any
|
||||
top folder inside it), packed as one JSON like local_dir."""
|
||||
src = Path(src).expanduser()
|
||||
if src.is_dir():
|
||||
return local_dir(spec, {spec["env"]: str(src)})
|
||||
files = {rel: None for rel in spec["files"]}
|
||||
with zipfile.ZipFile(src) as z:
|
||||
names = [n for n in z.namelist() if not n.endswith("/") and "__MACOSX" not in n]
|
||||
for rel in spec["files"]:
|
||||
hits = sorted((n for n in names if n == rel or n.endswith("/" + rel)), key=len)
|
||||
if hits:
|
||||
files[rel] = z.read(hits[0]).decode("utf-8")
|
||||
if not any(files.values()):
|
||||
raise RuntimeError(f"{src.name}: none of {', '.join(spec['files'])} found inside")
|
||||
return json.dumps(files, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
|
||||
EXTRACTORS = {"http": http, "reddit": reddit, "github_issues": github_issues, "local_dir": local_dir}
|
||||
|
||||
|
||||
@@ -127,6 +146,12 @@ def extract(name, spec, manifest, env=None, local_file=None):
|
||||
"""Fetch one source (or take a local file) into the raw store. Returns (raw path, changed)."""
|
||||
env = os.environ if env is None else env
|
||||
ext = spec["extract"].get("ext") or "json"
|
||||
data = Path(local_file).read_bytes() if local_file else EXTRACTORS[spec["extract"]["kind"]](spec["extract"], env)
|
||||
kind = spec["extract"]["kind"]
|
||||
if local_file and kind == "local_dir":
|
||||
data = pack_local(spec["extract"], local_file) # a bot folder or a .zip someone sent
|
||||
elif local_file:
|
||||
data = Path(local_file).expanduser().read_bytes()
|
||||
else:
|
||||
data = EXTRACTORS[kind](spec["extract"], env)
|
||||
changed = store(name, ext, data, manifest)
|
||||
return raw_paths(name, ext)[0], changed
|
||||
|
||||
Reference in New Issue
Block a user