Bot handoff: the daily check pulls Ken's bot repo; route model updates go to the bot by pull request
CI / test (pull_request) Successful in 39s
CI / test (pull_request) Successful in 39s
- update-sources: download DragonKind/DragonKind (read with ATLAS_BOT_TOKEN, or DRAGONKIND_TOKEN if set) and import it as the bot source. Needs DK_ACCOUNT_SALT (the same salt as earlier imports, so accounts keep their keys); without it the bot source is skipped as before. - The bot load keeps one file, data/bot/trajectories-bot.jsonl: the bot's repo holds every account's full history, so each import is merged by attempt id (attempts already published stay; older per-import files are folded in). One copy of each attempt also keeps build-graph.js from counting an attempt twice. - New workflow push-policy: when policy.json, solver.js or graph.js change on main, open (or update) a pull request on DragonKind/DragonKind that replaces vendor/threshing-atlas/ with them. Ken merges it. - forge open-pr: --repo/--base for another repository, and reuse the open pull request for the same branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
+16
-5
@@ -1,6 +1,6 @@
|
||||
"""The repository host (forge.yaml): links, and the few API calls the pipeline makes, for Gitea and GitHub.
|
||||
|
||||
python -m collection forge open-pr --head BRANCH --title T --body-file F [--automerge]
|
||||
python -m collection forge open-pr --head BRANCH --title T --body-file F [--automerge] [--repo OWNER/NAME --base B]
|
||||
python -m collection forge open-issue --title T --body-file F (skipped if an open issue has that title)
|
||||
python -m collection forge ensure-label --name N --color HEX
|
||||
|
||||
@@ -96,10 +96,19 @@ def list_issues(label, env=None, f=None):
|
||||
return sorted(out, key=lambda i: i["number"])
|
||||
|
||||
|
||||
def open_pr(head, title, body, automerge=False, env=None, f=None):
|
||||
f = f or config()
|
||||
def open_pr(head, title, body, automerge=False, env=None, f=None, repo=None, base=None):
|
||||
"""Open a pull request (on this repository, or `repo` on the same host). If one is open for the branch already,
|
||||
it is reused: pushing to its branch has updated it."""
|
||||
f = dict(f or config())
|
||||
if repo:
|
||||
f["repo"] = repo
|
||||
base = base or f["branch"]
|
||||
tok = token(env)
|
||||
pr = _call("POST", f"{api_base(f)}/pulls", {"head": head, "base": f["branch"], "title": title, "body": body}, tok, f)
|
||||
open_prs = _call("GET", f"{api_base(f)}/pulls?state=open&limit=50&per_page=100", tok=tok, f=f) or []
|
||||
same = [p for p in open_prs if (p.get("head") or {}).get("ref") == head]
|
||||
if same:
|
||||
return same[0]["number"]
|
||||
pr = _call("POST", f"{api_base(f)}/pulls", {"head": head, "base": base, "title": title, "body": body}, tok, f)
|
||||
n = pr["number"]
|
||||
if automerge:
|
||||
if f["kind"] == "github":
|
||||
@@ -141,6 +150,8 @@ def main(argv):
|
||||
p.add_argument("--title", required=True)
|
||||
p.add_argument("--body-file", required=True)
|
||||
p.add_argument("--automerge", action="store_true")
|
||||
p.add_argument("--repo", help="another repository on the same host (OWNER/NAME)")
|
||||
p.add_argument("--base", help="the branch to merge into (default: forge.yaml branch)")
|
||||
i = sub.add_parser("open-issue")
|
||||
i.add_argument("--title", required=True)
|
||||
i.add_argument("--body-file", required=True)
|
||||
@@ -150,7 +161,7 @@ def main(argv):
|
||||
a = ap.parse_args(argv)
|
||||
if a.cmd == "open-pr":
|
||||
body = open(a.body_file, encoding="utf-8").read()
|
||||
print(f"pull request #{open_pr(a.head, a.title, body, a.automerge)}")
|
||||
print(f"pull request #{open_pr(a.head, a.title, body, a.automerge, repo=a.repo, base=a.base)}")
|
||||
elif a.cmd == "open-issue":
|
||||
n = open_issue(a.title, open(a.body_file, encoding="utf-8").read())
|
||||
print(f"issue #{n}" if n else "an open issue with that title exists already")
|
||||
|
||||
@@ -95,5 +95,5 @@ sources:
|
||||
# data/raw/bot/account-salt.txt); never committed
|
||||
refuse_fields: [prose, proseNorm, proseExcerpt, email, password, accountId, accountName]
|
||||
max_string: 200 # anything longer looks like game prose
|
||||
load: data/bot # scenes.json (merged) + trajectories-<date>.jsonl
|
||||
load: data/bot # scenes.json and trajectories-bot.jsonl, both merged with what is published
|
||||
runs: bot
|
||||
|
||||
+25
-4
@@ -28,10 +28,33 @@ from datetime import datetime, timezone
|
||||
from .etl import extract as E
|
||||
from .etl import load as L
|
||||
from .etl import codegen, metadata, report_form, runs, validate
|
||||
from .etl.common import Report, path, pipeline
|
||||
from .etl.common import Report, path, pipeline, read_jsonl
|
||||
from .etl.transform import TRANSFORMS
|
||||
|
||||
|
||||
BOT_FILE = "trajectories-bot.jsonl"
|
||||
|
||||
|
||||
def merge_trajectories(target, new):
|
||||
"""Every bot attempt ever imported, in one file (data/bot/trajectories-bot.jsonl), sorted by id. The bot's repo
|
||||
holds each account's full history, so an import is a superset: a re-imported attempt replaces its old copy, and
|
||||
attempts no longer in the bot's repo (an archived account) stay. Older per-import files are folded in."""
|
||||
d = path(target)
|
||||
olds = sorted(d.glob("trajectories-*.jsonl"))
|
||||
by_id = {}
|
||||
for f in olds:
|
||||
for t in read_jsonl(f):
|
||||
by_id.setdefault(t["id"], t)
|
||||
for t in new:
|
||||
by_id[t["id"]] = t
|
||||
wrote = L.jsonl_file(f"{target}/{BOT_FILE}", [by_id[k] for k in sorted(by_id)])
|
||||
for f in olds:
|
||||
if f.name != BOT_FILE:
|
||||
f.unlink()
|
||||
wrote = True
|
||||
return wrote
|
||||
|
||||
|
||||
def update_source(name, spec, manifest, report, local_file=None, env=None):
|
||||
env = os.environ if env is None else env
|
||||
try:
|
||||
@@ -54,9 +77,7 @@ def update_source(name, spec, manifest, report, local_file=None, env=None):
|
||||
old = {"scenes": L.read_json(f"{target}/scenes.json") or {}}
|
||||
lines = mod.describe(old, new)
|
||||
wrote = L.json_file(f"{target}/scenes.json", mod.merge_scenes(old["scenes"], new["scenes"]), compact=False)
|
||||
# one file per import (date + raw checksum), so two imports on the same day (yours, Ken's) never overwrite
|
||||
tag = f"{ctx['changed']}-{manifest[name]['sha256'][:8]}"
|
||||
wrote |= L.jsonl_file(f"{target}/trajectories-{tag}.jsonl", new["trajectories"])
|
||||
wrote |= merge_trajectories(target, new["trajectories"])
|
||||
elif target:
|
||||
old = L.read_json(target)
|
||||
lines = mod.describe(old, new)
|
||||
|
||||
Reference in New Issue
Block a user