feat: update-swarm CLI, scout schema, gated and watchlist reports
This commit is contained in:
1 parent
5445f82d91
commit
a34686f7a5
5 files changed
+173
No files matched your search
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
import os, sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__))))
|
||||
from update_swarm.cli import main
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,84 @@
|
||||
from __future__ import annotations
|
||||
import argparse, glob, os, sys
|
||||
from update_swarm.jobs import build_jobs, init_run
|
||||
from update_swarm.judge import judge_all
|
||||
from update_swarm.reports import write_reports
|
||||
from update_swarm.schema import read_json, write_json
|
||||
|
||||
SCOUT_KEYS = ["stem", "latest_english_version", "url", "host", "gate",
|
||||
"language_matrix", "source_used", "hackdex", "upstream_status", "notes"]
|
||||
|
||||
def validate_scout(obj: dict) -> list[str]:
|
||||
return [k for k in SCOUT_KEYS if k not in obj]
|
||||
|
||||
def deploy_argv(pokemon_repo: str, site_repo: str) -> list[list[str]]:
|
||||
return [
|
||||
["python", "scripts/build-vault-mocs.py"],
|
||||
["python", "scripts/build-wiki-data.py"],
|
||||
["powershell", "-File", "scripts/deploy-site.ps1"],
|
||||
]
|
||||
|
||||
def _load_scouts(run_dir: str) -> dict:
|
||||
out = {}
|
||||
for path in glob.glob(os.path.join(run_dir, "scouts", "*.json")):
|
||||
obj = read_json(path)
|
||||
errs = validate_scout(obj)
|
||||
if errs:
|
||||
raise SystemExit(f"{path} missing keys: {errs}")
|
||||
out[obj["stem"]] = obj
|
||||
return out
|
||||
|
||||
def _load_census(run_dir: str) -> dict:
|
||||
out = {}
|
||||
for path in glob.glob(os.path.join(run_dir, "census", "*.json")):
|
||||
obj = read_json(path)
|
||||
out[obj["stem"]] = obj
|
||||
return out
|
||||
|
||||
def main(argv=None) -> int:
|
||||
p = argparse.ArgumentParser(prog="update-swarm")
|
||||
p.add_argument("--run", required=False, help="path to .scrape/update-runs/YYYY-MM-DD")
|
||||
sub = p.add_subparsers(dest="cmd", required=True)
|
||||
sub.add_parser("init")
|
||||
pj = sub.add_parser("jobs")
|
||||
pj.add_argument("--vault", required=True)
|
||||
sub.add_parser("validate-scouts")
|
||||
sub.add_parser("judge")
|
||||
sub.add_parser("reports")
|
||||
args = p.parse_args(argv)
|
||||
if args.cmd == "init":
|
||||
if not args.run:
|
||||
raise SystemExit("--run is required")
|
||||
init_run(args.run)
|
||||
return 0
|
||||
if args.cmd == "jobs":
|
||||
if not args.run:
|
||||
raise SystemExit("--run is required")
|
||||
jobs = build_jobs(args.vault)
|
||||
write_json(os.path.join(args.run, "jobs.json"), {"run_date": os.path.basename(args.run), "jobs": jobs})
|
||||
print(f"wrote {len(jobs)} jobs")
|
||||
return 0
|
||||
if args.cmd == "validate-scouts":
|
||||
if not args.run:
|
||||
raise SystemExit("--run is required")
|
||||
_load_scouts(args.run)
|
||||
print("scouts ok")
|
||||
return 0
|
||||
if args.cmd == "judge":
|
||||
if not args.run:
|
||||
raise SystemExit("--run is required")
|
||||
jobs = read_json(os.path.join(args.run, "jobs.json"))["jobs"]
|
||||
verdicts = judge_all(jobs, _load_census(args.run), _load_scouts(args.run))
|
||||
write_json(os.path.join(args.run, "verdict.json"), {"verdicts": verdicts})
|
||||
print(f"wrote {len(verdicts)} verdicts")
|
||||
return 0
|
||||
if args.cmd == "reports":
|
||||
if not args.run:
|
||||
raise SystemExit("--run is required")
|
||||
verdicts = read_json(os.path.join(args.run, "verdict.json"))["verdicts"]
|
||||
write_reports(args.run, verdicts)
|
||||
return 0
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,14 @@
|
||||
from __future__ import annotations
|
||||
import os
|
||||
|
||||
def write_reports(run_dir: str, verdicts: list[dict]) -> None:
|
||||
gated = [v for v in verdicts if v["bucket"] == "gated_queue"]
|
||||
watch = [v for v in verdicts if v["bucket"] == "watchlist_report"]
|
||||
def table(path, title, rows):
|
||||
lines = [f"# {title}", "", "| Stem | Latest English | Reason |", "|---|---|---|"]
|
||||
for v in rows:
|
||||
lines.append(f"| {v['stem']} | {v.get('latest_english_version') or ''} | {v.get('reason') or ''} |")
|
||||
lines.append("")
|
||||
open(path, "w", encoding="utf-8").write("\n".join(lines))
|
||||
table(os.path.join(run_dir, "gated.md"), "Gated queue", gated)
|
||||
table(os.path.join(run_dir, "watchlist-report.md"), "Watchlist check-in", watch)
|
||||
@@ -0,0 +1,24 @@
|
||||
# Scout agent prompt
|
||||
|
||||
You are a version scout for one Pokémon ROM hack or fangame. Do not download binaries. Do not invent versions.
|
||||
|
||||
Installed version (may be wrong if `source` is `note`): {installed_version} ({installed_source})
|
||||
Homepage: {homepage}
|
||||
Source URL: {source}
|
||||
|
||||
Find the latest **English** playable build, even if Spanish/French/etc. is newer.
|
||||
|
||||
Source order: official site / GitHub releases / project page → HackDex → PokeCommunity → other.
|
||||
If HackDex is Cloudflare-blocked, set hackdex to "blocked" and continue. Never guess.
|
||||
|
||||
Write scouts/{stem}.json with exactly these keys:
|
||||
- stem (string)
|
||||
- latest_english_version (string or null)
|
||||
- url (direct download if ungated, else the page URL, or null)
|
||||
- host (github|archive|mediafire|mega|itch|drive|discord|kofi|hackdex|pokecommunity|other or null)
|
||||
- gate (ungated|gated|null)
|
||||
- language_matrix (object, e.g. {"en": "2.13", "es": "2.18"}; empty object if unknown)
|
||||
- source_used (website|hackdex|pokecommunity|other or null)
|
||||
- hackdex (ok|blocked|skipped)
|
||||
- upstream_status (Complete|Ongoing|Beta or null)
|
||||
- notes (string)
|
||||
@@ -0,0 +1,45 @@
|
||||
import json, os, sys, tempfile, unittest
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
sys.path.insert(0, os.path.join(ROOT, "scripts"))
|
||||
from update_swarm.cli import deploy_argv, validate_scout
|
||||
from update_swarm.reports import write_reports
|
||||
|
||||
class TestCli(unittest.TestCase):
|
||||
def test_validate_scout_missing_keys(self):
|
||||
errs = validate_scout({"stem": "Z"})
|
||||
self.assertIn("latest_english_version", " ".join(errs))
|
||||
|
||||
def test_validate_scout_ok(self):
|
||||
obj = {
|
||||
"stem": "Z", "latest_english_version": "2.13", "url": "https://example.com/z.zip",
|
||||
"host": "other", "gate": "gated", "language_matrix": {"en": "2.13", "es": "2.18"},
|
||||
"source_used": "website", "hackdex": "skipped", "upstream_status": "Complete", "notes": "",
|
||||
}
|
||||
self.assertEqual(validate_scout(obj), [])
|
||||
|
||||
def test_reports(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
verdicts = [
|
||||
{"stem": "A", "bucket": "gated_queue", "latest_english_version": "2.0", "fetch_url": None, "gate": "itch", "reason": "newer-gated"},
|
||||
{"stem": "B", "bucket": "watchlist_report", "latest_english_version": "0.7", "reason": "watchlist-demo"},
|
||||
]
|
||||
write_reports(td, verdicts)
|
||||
gated = open(os.path.join(td, "gated.md"), encoding="utf-8").read()
|
||||
wl = open(os.path.join(td, "watchlist-report.md"), encoding="utf-8").read()
|
||||
self.assertIn("A", gated)
|
||||
self.assertIn("B", wl)
|
||||
|
||||
def test_deploy_argv(self):
|
||||
cmds = deploy_argv("/pokemon", "/site")
|
||||
self.assertEqual(cmds[0], ["python", "scripts/build-vault-mocs.py"])
|
||||
self.assertEqual(cmds[1], ["python", "scripts/build-wiki-data.py"])
|
||||
self.assertEqual(cmds[2][-1], "scripts/deploy-site.ps1")
|
||||
|
||||
def test_prompt_file_exists(self):
|
||||
path = os.path.join(ROOT, "scripts", "update_swarm", "scout_prompt.md")
|
||||
text = open(path, encoding="utf-8").read()
|
||||
self.assertIn("latest_english_version", text)
|
||||
self.assertIn("Do not invent versions", text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user