From 8db8d00196d7566294361d9ae75f32b93903f284 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:44:34 -0500 Subject: [PATCH 01/16] feat: add version normalize and compare for the update swarm --- scripts/update_swarm/__init__.py | 0 scripts/update_swarm/versions.py | 33 +++++++++++++++++++++++++++++ tests/update_swarm/__init__.py | 0 tests/update_swarm/test_versions.py | 27 +++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 scripts/update_swarm/__init__.py create mode 100644 scripts/update_swarm/versions.py create mode 100644 tests/update_swarm/__init__.py create mode 100644 tests/update_swarm/test_versions.py diff --git a/scripts/update_swarm/__init__.py b/scripts/update_swarm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/update_swarm/versions.py b/scripts/update_swarm/versions.py new file mode 100644 index 0000000..55a85d2 --- /dev/null +++ b/scripts/update_swarm/versions.py @@ -0,0 +1,33 @@ +from __future__ import annotations +import re + +_LANG = re.compile(r"\s*\((EN|ES|FR|DE|IT|PT|JP)\)\s*", re.I) +_LEADING_V = re.compile(r"^\s*v", re.I) +_NUMERIC = re.compile(r"^(\d+(?:\.\d+)*)") + +def normalize_version(s: str) -> str: + s = _LANG.sub(" ", s or "") + s = _LEADING_V.sub("", s) + return re.sub(r"\s+", " ", s).strip() + +def _tuple(s: str) -> tuple[int, ...] | None: + m = _NUMERIC.match(normalize_version(s)) + if not m: + return None + return tuple(int(p) for p in m.group(1).split(".")) + +def compare_versions(a: str, b: str) -> str: + na, nb = normalize_version(a), normalize_version(b) + if na.lower() == nb.lower() and na != "": + return "eq" + ta, tb = _tuple(a), _tuple(b) + if ta is None or tb is None: + return "incomparable" + n = max(len(ta), len(tb)) + ta = ta + (0,) * (n - len(ta)) + tb = tb + (0,) * (n - len(tb)) + if ta < tb: + return "lt" + if ta > tb: + return "gt" + return "eq" diff --git a/tests/update_swarm/__init__.py b/tests/update_swarm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/update_swarm/test_versions.py b/tests/update_swarm/test_versions.py new file mode 100644 index 0000000..ceadd1c --- /dev/null +++ b/tests/update_swarm/test_versions.py @@ -0,0 +1,27 @@ +import os, sys, unittest +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.versions import compare_versions, normalize_version + +class TestNormalize(unittest.TestCase): + def test_strips_v_and_language_tag(self): + self.assertEqual(normalize_version("v2.13 (EN)"), "2.13") + self.assertEqual(normalize_version("V1.0.4.2"), "1.0.4.2") + self.assertEqual(normalize_version("2.18 (ES)"), "2.18") + +class TestCompare(unittest.TestCase): + def test_numeric_order(self): + self.assertEqual(compare_versions("1.0.3", "1.0.4.2"), "lt") + self.assertEqual(compare_versions("v1.0.4.2", "1.0.3"), "gt") + self.assertEqual(compare_versions("v2.13 (EN)", "2.13"), "eq") + self.assertEqual(compare_versions("4.1", "4.10"), "lt") + + def test_incomparable_non_numeric(self): + self.assertEqual(compare_versions("Final", "1.2"), "incomparable") + self.assertEqual(compare_versions("2026-03-30", "Nightly"), "incomparable") + + def test_equal_non_numeric_after_normalize(self): + self.assertEqual(compare_versions("Final", "final"), "eq") + +if __name__ == "__main__": + unittest.main() From 299b01c4fdd30e669cb4579f306204626ede5c65 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:45:53 -0500 Subject: [PATCH 02/16] feat: classify download URLs as ungated or gated hosts --- scripts/update_swarm/hosts.py | 30 ++++++++++++++++++++++++++++++ tests/update_swarm/test_hosts.py | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 scripts/update_swarm/hosts.py create mode 100644 tests/update_swarm/test_hosts.py diff --git a/scripts/update_swarm/hosts.py b/scripts/update_swarm/hosts.py new file mode 100644 index 0000000..45378c1 --- /dev/null +++ b/scripts/update_swarm/hosts.py @@ -0,0 +1,30 @@ +from __future__ import annotations +from urllib.parse import urlparse + +def classify_url(url: str) -> tuple[str, str]: + p = urlparse(url or "") + host = (p.netloc or "").lower().removeprefix("www.") + path = p.path or "" + if host in ("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com"): + if host != "github.com" or "/releases/download/" in path: + return "github", "ungated" + return "github", "gated" + if host.endswith("archive.org"): + return "archive", "ungated" + if host.endswith("mediafire.com"): + return "mediafire", "ungated" + if host.endswith("mega.nz") or host.endswith("mega.co.nz"): + return "mega", "ungated" if p.fragment else "gated" + if host.endswith("itch.io"): + return "itch", "gated" + if host in ("drive.google.com", "docs.google.com"): + return "drive", "gated" + if host in ("discord.com", "discord.gg"): + return "discord", "gated" + if host.endswith("ko-fi.com"): + return "kofi", "gated" + if host.endswith("hackdex.app"): + return "hackdex", "gated" + if host.endswith("pokecommunity.com"): + return "pokecommunity", "gated" + return "other", "gated" diff --git a/tests/update_swarm/test_hosts.py b/tests/update_swarm/test_hosts.py new file mode 100644 index 0000000..f401fc5 --- /dev/null +++ b/tests/update_swarm/test_hosts.py @@ -0,0 +1,24 @@ +import os, sys, unittest +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.hosts import classify_url + +class TestClassify(unittest.TestCase): + def test_ungated(self): + self.assertEqual(classify_url("https://github.com/a/b/releases/download/v1/x.gba"), ("github", "ungated")) + self.assertEqual(classify_url("https://archive.org/download/id/file.gba"), ("archive", "ungated")) + self.assertEqual(classify_url("https://www.mediafire.com/file/abc/x.zip/file"), ("mediafire", "ungated")) + self.assertEqual(classify_url("https://mega.nz/file/abc#keyfragment"), ("mega", "ungated")) + + def test_gated(self): + self.assertEqual(classify_url("https://mega.nz/file/abc"), ("mega", "gated")) + self.assertEqual(classify_url("https://foo.itch.io/bar"), ("itch", "gated")) + self.assertEqual(classify_url("https://drive.google.com/file/d/x/view"), ("drive", "gated")) + self.assertEqual(classify_url("https://discord.gg/abc"), ("discord", "gated")) + self.assertEqual(classify_url("https://ko-fi.com/s/abc"), ("kofi", "gated")) + self.assertEqual(classify_url("https://hackdex.app/hack/x"), ("hackdex", "gated")) + self.assertEqual(classify_url("https://www.pokecommunity.com/threads/x.1/"), ("pokecommunity", "gated")) + self.assertEqual(classify_url("https://mystery.example/file.zip"), ("other", "gated")) + +if __name__ == "__main__": + unittest.main() From d91b0bc13d7452cfaec288ebc9134a282650e7f6 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:47:18 -0500 Subject: [PATCH 03/16] feat: build update-swarm jobs.json from vault notes --- scripts/update_swarm/jobs.py | 47 +++++++++++++++++++ scripts/update_swarm/schema.py | 12 +++++ .../vault/Pokémon ROM Hacks/Demo Watchlist.md | 3 ++ .../vault/Pokémon ROM Hacks/Hacks/DemoOnly.md | 8 ++++ .../vault/Pokémon ROM Hacks/Hacks/FakeHack.md | 11 +++++ .../vault/Pokémon ROM Hacks/Wanted.md | 1 + tests/update_swarm/test_jobs.py | 27 +++++++++++ 7 files changed, 109 insertions(+) create mode 100644 scripts/update_swarm/jobs.py create mode 100644 scripts/update_swarm/schema.py create mode 100644 tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md create mode 100644 tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/DemoOnly.md create mode 100644 tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/FakeHack.md create mode 100644 tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md create mode 100644 tests/update_swarm/test_jobs.py diff --git a/scripts/update_swarm/jobs.py b/scripts/update_swarm/jobs.py new file mode 100644 index 0000000..bd2baa8 --- /dev/null +++ b/scripts/update_swarm/jobs.py @@ -0,0 +1,47 @@ +from __future__ import annotations +import glob, os, re, sys + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import enrich_vault as E +from update_swarm.schema import write_json + +WIKILINK = re.compile(r"\[\[([^\]|#]+)") + +def _links(path: str) -> set[str]: + if not os.path.isfile(path): + return set() + text = open(path, encoding="utf-8").read() + return {m.strip() for m in WIKILINK.findall(text)} + +def build_jobs(vault_romhacks_dir: str) -> list[dict]: + hacks = os.path.join(vault_romhacks_dir, "Hacks") + watch = _links(os.path.join(vault_romhacks_dir, "Demo Watchlist.md")) + wanted = _links(os.path.join(vault_romhacks_dir, "Wanted.md")) + jobs = [] + for path in sorted(glob.glob(os.path.join(hacks, "*.md"))): + stem = os.path.splitext(os.path.basename(path))[0] + fm_text, _, _ = E.read_note(path) + fm = E.parse_fm(fm_text) + def blank(v): + return None if v in (None, "", "—") else v + jobs.append({ + "stem": stem, + "title": fm.get("title") or stem, + "platform": blank(fm.get("platform")), + "library_path": blank(fm.get("library_path")), + "homepage": blank(fm.get("homepage")), + "source": blank(fm.get("source")), + "note_version": blank(fm.get("version")), + "note_status": blank(fm.get("status")), + "watchlist": stem in watch, + "wanted": stem in wanted, + }) + return jobs + +def init_run(run_dir: str) -> None: + os.makedirs(run_dir, exist_ok=True) + for name in ("census", "scouts", "staging"): + os.makedirs(os.path.join(run_dir, name), exist_ok=True) + jobs_path = os.path.join(run_dir, "jobs.json") + if not os.path.isfile(jobs_path): + write_json(jobs_path, {"run_date": os.path.basename(run_dir), "jobs": []}) diff --git a/scripts/update_swarm/schema.py b/scripts/update_swarm/schema.py new file mode 100644 index 0000000..e816e43 --- /dev/null +++ b/scripts/update_swarm/schema.py @@ -0,0 +1,12 @@ +from __future__ import annotations +import json, os + +def read_json(path: str): + with open(path, encoding="utf-8") as f: + return json.load(f) + +def write_json(path: str, obj) -> None: + os.makedirs(os.path.dirname(path) or ".", exist_ok=True) + with open(path, "w", encoding="utf-8") as f: + json.dump(obj, f, indent=2, ensure_ascii=False) + f.write("\n") diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md new file mode 100644 index 0000000..2fe5218 --- /dev/null +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md @@ -0,0 +1,3 @@ +| Hack | Vault note | +|---|---| +| **DemoOnly** | [[DemoOnly]] | diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/DemoOnly.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/DemoOnly.md new file mode 100644 index 0000000..90fe2fa --- /dev/null +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/DemoOnly.md @@ -0,0 +1,8 @@ +--- +title: "Pokémon DemoOnly" +platform: PC +version: "0.6.2" +status: Beta +--- + +# Pokémon DemoOnly diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/FakeHack.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/FakeHack.md new file mode 100644 index 0000000..4af6565 --- /dev/null +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/FakeHack.md @@ -0,0 +1,11 @@ +--- +title: "Pokémon FakeHack" +platform: GBA +version: "1.0.0" +status: Complete +library_path: "/storage1/Emulation/roms/gba/Pokemon - FakeHack [Hack].gba" +homepage: "https://example.com/fake" +source: "https://www.pokecommunity.com/threads/fake.1/" +--- + +# Pokémon FakeHack diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md new file mode 100644 index 0000000..85739d8 --- /dev/null +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md @@ -0,0 +1 @@ +See [[FakeHack]] still gated. diff --git a/tests/update_swarm/test_jobs.py b/tests/update_swarm/test_jobs.py new file mode 100644 index 0000000..fb2bb21 --- /dev/null +++ b/tests/update_swarm/test_jobs.py @@ -0,0 +1,27 @@ +import 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.jobs import build_jobs, init_run + +FIXTURE = os.path.join(os.path.dirname(__file__), "fixtures", "vault", "Pokémon ROM Hacks") + +class TestJobs(unittest.TestCase): + def test_flags_watchlist_and_wanted(self): + jobs = {j["stem"]: j for j in build_jobs(FIXTURE)} + self.assertIn("FakeHack", jobs) + self.assertTrue(jobs["FakeHack"]["wanted"]) + self.assertFalse(jobs["FakeHack"]["watchlist"]) + self.assertEqual(jobs["FakeHack"]["note_version"], "1.0.0") + self.assertTrue(jobs["DemoOnly"]["watchlist"]) + self.assertFalse(jobs["DemoOnly"]["wanted"]) + self.assertIsNone(jobs["DemoOnly"]["library_path"]) + + def test_init_run_creates_dirs(self): + with tempfile.TemporaryDirectory() as td: + run = os.path.join(td, "2026-08-14") + init_run(run) + for name in ("census", "scouts", "staging"): + self.assertTrue(os.path.isdir(os.path.join(run, name))) + +if __name__ == "__main__": + unittest.main() From 25eee44483451fb3396f0307157be4f2019835dc Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:49:02 -0500 Subject: [PATCH 04/16] feat: census installed hack versions from files with note fallback --- scripts/update_swarm/census.py | 98 ++++++++++++++++++ .../library/changelog-game/changelog.txt | 1 + .../fixtures/library/changelog-game/dummy.bin | 0 .../fixtures/library/ini-game/Game.ini | 3 + .../fixtures/library/ini-game/dummy.bin | 0 .../named/Pokemon - Named [Hack][3.3.1].zip | Bin 0 -> 22 bytes tests/update_swarm/test_census.py | 43 ++++++++ 7 files changed, 145 insertions(+) create mode 100644 scripts/update_swarm/census.py create mode 100644 tests/update_swarm/fixtures/library/changelog-game/changelog.txt create mode 100644 tests/update_swarm/fixtures/library/changelog-game/dummy.bin create mode 100644 tests/update_swarm/fixtures/library/ini-game/Game.ini create mode 100644 tests/update_swarm/fixtures/library/ini-game/dummy.bin create mode 100644 tests/update_swarm/fixtures/library/named/Pokemon - Named [Hack][3.3.1].zip create mode 100644 tests/update_swarm/test_census.py diff --git a/scripts/update_swarm/census.py b/scripts/update_swarm/census.py new file mode 100644 index 0000000..aaea6f4 --- /dev/null +++ b/scripts/update_swarm/census.py @@ -0,0 +1,98 @@ +from __future__ import annotations +import hashlib, os, re, zipfile + +CHANGELOG_NAMES = {"changelog.txt", "changelog.md", "changes.txt", "readme.txt", "readme.md"} +CURRENT_RE = re.compile(r"(?im)^\s*(?:current\s+version|version)\s*[:\-]\s*(.+?)\s*$") +INI_VER = re.compile(r"(?im)^\s*Version\s*=\s*(.+?)\s*$") +FILE_VER = re.compile(r"\[(?:v)?(\d+(?:\.\d+)*)\]|\((?:v)?(\d+(?:\.\d+)*)\)|v(\d+(?:\.\d+)*)", re.I) +ROM_VER = re.compile(rb"Version\s+[vV]?(\d+(?:\.\d+)*)") + +def _sha_size(path: str) -> tuple[str, int]: + h = hashlib.sha256() + with open(path, "rb") as f: + for chunk in iter(lambda: f.read(1024 * 1024), b""): + h.update(chunk) + return h.hexdigest(), os.path.getsize(path) + +def _from_text(text: str) -> str | None: + m = CURRENT_RE.search(text or "") + return m.group(1).strip() if m else None + +def _sidecar_version(file_path: str) -> str | None: + parent = os.path.dirname(file_path) + for name in os.listdir(parent) if os.path.isdir(parent) else []: + low = name.lower() + if low in CHANGELOG_NAMES or low == "game.ini": + with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh: + text = fh.read() + if low == "game.ini": + m = INI_VER.search(text) + if m: + return m.group(1).strip() + else: + found = _from_text(text) + if found: + return found + return None + +def _zip_version(file_path: str) -> str | None: + try: + with zipfile.ZipFile(file_path) as z: + names = z.namelist() + for n in names: + base = os.path.basename(n).lower() + if base in CHANGELOG_NAMES: + found = _from_text(z.read(n).decode("utf-8", "ignore")) + if found: + return found + for n in names: + if os.path.basename(n).lower() == "game.ini": + m = INI_VER.search(z.read(n).decode("utf-8", "ignore")) + if m: + return m.group(1).strip() + except zipfile.BadZipFile: + return None + return None + +def _filename_version(file_path: str) -> str | None: + m = FILE_VER.search(os.path.basename(file_path)) + if not m: + return None + return next(g for g in m.groups() if g) + +def _rom_version(file_path: str) -> str | None: + with open(file_path, "rb") as f: + blob = f.read(512 * 1024) + m = ROM_VER.search(blob) + return m.group(1).decode() if m else None + +def census_job(job: dict, file_path: str | None) -> dict: + rec = { + "stem": job["stem"], + "installed_version": None, + "source": "unknown", + "evidence": "", + "sha256": None, + "size": None, + "language": None, + } + if file_path and os.path.isfile(file_path): + rec["sha256"], rec["size"] = _sha_size(file_path) + for found, evidence in ( + (_sidecar_version(file_path), "sidecar"), + (_zip_version(file_path), "zip"), + (_filename_version(file_path), "filename"), + (_rom_version(file_path), "rom-bytes"), + ): + if found: + rec["installed_version"] = found + rec["source"] = "file" + rec["evidence"] = evidence + return rec + if job.get("note_version"): + rec["installed_version"] = job["note_version"] + rec["source"] = "note" + rec["evidence"] = "vault" + return rec + rec["evidence"] = "none" + return rec diff --git a/tests/update_swarm/fixtures/library/changelog-game/changelog.txt b/tests/update_swarm/fixtures/library/changelog-game/changelog.txt new file mode 100644 index 0000000..7cdf4d0 --- /dev/null +++ b/tests/update_swarm/fixtures/library/changelog-game/changelog.txt @@ -0,0 +1 @@ +Current Version: 3.3.1 diff --git a/tests/update_swarm/fixtures/library/changelog-game/dummy.bin b/tests/update_swarm/fixtures/library/changelog-game/dummy.bin new file mode 100644 index 0000000..e69de29 diff --git a/tests/update_swarm/fixtures/library/ini-game/Game.ini b/tests/update_swarm/fixtures/library/ini-game/Game.ini new file mode 100644 index 0000000..86b154d --- /dev/null +++ b/tests/update_swarm/fixtures/library/ini-game/Game.ini @@ -0,0 +1,3 @@ +[Game] +Title=Ini Game +Version=1.74.1 diff --git a/tests/update_swarm/fixtures/library/ini-game/dummy.bin b/tests/update_swarm/fixtures/library/ini-game/dummy.bin new file mode 100644 index 0000000..e69de29 diff --git a/tests/update_swarm/fixtures/library/named/Pokemon - Named [Hack][3.3.1].zip b/tests/update_swarm/fixtures/library/named/Pokemon - Named [Hack][3.3.1].zip new file mode 100644 index 0000000000000000000000000000000000000000..15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7 GIT binary patch literal 22 NcmWIWW@Tf*000g10H*)| literal 0 HcmV?d00001 diff --git a/tests/update_swarm/test_census.py b/tests/update_swarm/test_census.py new file mode 100644 index 0000000..e87b8b8 --- /dev/null +++ b/tests/update_swarm/test_census.py @@ -0,0 +1,43 @@ +import hashlib, os, sys, tempfile, unittest, zipfile +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.census import census_job + +FIX = os.path.join(os.path.dirname(__file__), "fixtures", "library") + +def job(stem, note_version=None): + return {"stem": stem, "library_path": None, "note_version": note_version} + +class TestCensus(unittest.TestCase): + def test_changelog_current_version_line(self): + rec = census_job(job("C"), os.path.join(FIX, "changelog-game", "dummy.bin")) + self.assertEqual(rec["installed_version"], "3.3.1") + self.assertEqual(rec["source"], "file") + + def test_game_ini_version(self): + rec = census_job(job("I"), os.path.join(FIX, "ini-game", "dummy.bin")) + self.assertEqual(rec["installed_version"], "1.74.1") + self.assertEqual(rec["source"], "file") + + def test_filename_token(self): + rec = census_job(job("N"), os.path.join(FIX, "named", "Pokemon - Named [Hack][3.3.1].zip")) + self.assertEqual(rec["installed_version"], "3.3.1") + + def test_zip_inner_changelog(self): + with tempfile.TemporaryDirectory() as td: + zpath = os.path.join(td, "game.zip") + with zipfile.ZipFile(zpath, "w") as z: + z.writestr("README.txt", "Current Version: 2.13\n") + rec = census_job(job("Z"), zpath) + self.assertEqual(rec["installed_version"], "2.13") + + def test_note_fallback_then_unknown(self): + rec = census_job(job("X", note_version="9.9"), None) + self.assertEqual(rec["source"], "note") + self.assertEqual(rec["installed_version"], "9.9") + rec2 = census_job(job("Y"), None) + self.assertEqual(rec2["source"], "unknown") + self.assertIsNone(rec2["installed_version"]) + +if __name__ == "__main__": + unittest.main() From cbe1848d100cb7c55517e1a12b9397c9b5876b59 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:51:03 -0500 Subject: [PATCH 05/16] fix: prefer changelog over Game.ini in census sidecar scan --- scripts/update_swarm/census.py | 26 ++++++++++--------- .../fixtures/library/both-sidecars/Game.ini | 3 +++ .../library/both-sidecars/changelog.txt | 1 + .../fixtures/library/both-sidecars/dummy.bin | 0 tests/update_swarm/test_census.py | 11 ++++++++ 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 tests/update_swarm/fixtures/library/both-sidecars/Game.ini create mode 100644 tests/update_swarm/fixtures/library/both-sidecars/changelog.txt create mode 100644 tests/update_swarm/fixtures/library/both-sidecars/dummy.bin diff --git a/scripts/update_swarm/census.py b/scripts/update_swarm/census.py index aaea6f4..a7b95f1 100644 --- a/scripts/update_swarm/census.py +++ b/scripts/update_swarm/census.py @@ -20,19 +20,21 @@ def _from_text(text: str) -> str | None: def _sidecar_version(file_path: str) -> str | None: parent = os.path.dirname(file_path) - for name in os.listdir(parent) if os.path.isdir(parent) else []: - low = name.lower() - if low in CHANGELOG_NAMES or low == "game.ini": + if not os.path.isdir(parent): + return None + names = os.listdir(parent) + for name in names: + if name.lower() in CHANGELOG_NAMES: with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh: - text = fh.read() - if low == "game.ini": - m = INI_VER.search(text) - if m: - return m.group(1).strip() - else: - found = _from_text(text) - if found: - return found + found = _from_text(fh.read()) + if found: + return found + for name in names: + if name.lower() == "game.ini": + with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh: + m = INI_VER.search(fh.read()) + if m: + return m.group(1).strip() return None def _zip_version(file_path: str) -> str | None: diff --git a/tests/update_swarm/fixtures/library/both-sidecars/Game.ini b/tests/update_swarm/fixtures/library/both-sidecars/Game.ini new file mode 100644 index 0000000..3de6fa0 --- /dev/null +++ b/tests/update_swarm/fixtures/library/both-sidecars/Game.ini @@ -0,0 +1,3 @@ +[Game] +Title=Both Sidecars +Version=9.9.9 diff --git a/tests/update_swarm/fixtures/library/both-sidecars/changelog.txt b/tests/update_swarm/fixtures/library/both-sidecars/changelog.txt new file mode 100644 index 0000000..7cdf4d0 --- /dev/null +++ b/tests/update_swarm/fixtures/library/both-sidecars/changelog.txt @@ -0,0 +1 @@ +Current Version: 3.3.1 diff --git a/tests/update_swarm/fixtures/library/both-sidecars/dummy.bin b/tests/update_swarm/fixtures/library/both-sidecars/dummy.bin new file mode 100644 index 0000000..e69de29 diff --git a/tests/update_swarm/test_census.py b/tests/update_swarm/test_census.py index e87b8b8..6f8f230 100644 --- a/tests/update_swarm/test_census.py +++ b/tests/update_swarm/test_census.py @@ -1,4 +1,5 @@ import hashlib, os, sys, tempfile, unittest, zipfile +from unittest.mock import patch ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) sys.path.insert(0, os.path.join(ROOT, "scripts")) from update_swarm.census import census_job @@ -19,6 +20,16 @@ class TestCensus(unittest.TestCase): self.assertEqual(rec["installed_version"], "1.74.1") self.assertEqual(rec["source"], "file") + @patch( + "update_swarm.census.os.listdir", + return_value=["Game.ini", "changelog.txt", "dummy.bin"], + ) + def test_sidecar_prefers_changelog_over_game_ini(self, _listdir): + rec = census_job(job("B"), os.path.join(FIX, "both-sidecars", "dummy.bin")) + self.assertEqual(rec["installed_version"], "3.3.1") + self.assertEqual(rec["source"], "file") + self.assertEqual(rec["evidence"], "sidecar") + def test_filename_token(self): rec = census_job(job("N"), os.path.join(FIX, "named", "Pokemon - Named [Hack][3.3.1].zip")) self.assertEqual(rec["installed_version"], "3.3.1") From b5cce78652b2a8ad9223658eb835b3f9c8105e7c Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:52:37 -0500 Subject: [PATCH 06/16] feat: classify update-swarm verdicts including watchlist and Z-safe compare --- scripts/update_swarm/judge.py | 72 ++++++++++++++++++++++++++++++++ tests/update_swarm/test_judge.py | 60 ++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 scripts/update_swarm/judge.py create mode 100644 tests/update_swarm/test_judge.py diff --git a/scripts/update_swarm/judge.py b/scripts/update_swarm/judge.py new file mode 100644 index 0000000..45f5e6c --- /dev/null +++ b/scripts/update_swarm/judge.py @@ -0,0 +1,72 @@ +from __future__ import annotations +from update_swarm.versions import compare_versions + +def judge_one(job: dict, census: dict, scout: dict) -> dict: + installed = census.get("installed_version") + latest = scout.get("latest_english_version") + gate = scout.get("gate") + url = scout.get("url") + out = { + "stem": job["stem"], + "bucket": "current", + "reason": "", + "fetch_url": None, + "installed_version": installed, + "latest_english_version": latest, + "gate": gate, + "incomparable": False, + "bump_status": None, + "remove_from_watchlist": False, + } + if not latest: + out["reason"] = "no-latest" + return out + if census.get("source") == "unknown" and census.get("sha256") and scout.get("sha256"): + if census["sha256"] == scout["sha256"]: + out["reason"] = "hash-match" + return out + cmp = compare_versions(installed or "", latest) if installed else "lt" + if installed and cmp == "incomparable": + out["bucket"] = "incomparable" + out["incomparable"] = True + out["reason"] = "incomparable" + return out + newer = (not installed) or cmp == "lt" + if not newer: + out["reason"] = "up-to-date" + return out + complete = (scout.get("upstream_status") == "Complete") + ungated = gate == "ungated" and url + if job.get("watchlist"): + if complete and ungated: + out["bucket"] = "watchlist_promote" + out["fetch_url"] = url + out["remove_from_watchlist"] = True + out["reason"] = "watchlist-complete-ungated" + return out + if not ungated: + out["bucket"] = "gated_queue" + out["bump_status"] = "Complete" if complete else None + out["reason"] = "watchlist-gated" + return out + out["bucket"] = "watchlist_report" + out["reason"] = "watchlist-demo" + return out + if ungated: + out["bucket"] = "update" + out["fetch_url"] = url + out["reason"] = "newer-ungated" + return out + out["bucket"] = "gated_queue" + out["bump_status"] = "Complete" if complete else None + out["reason"] = "newer-gated" + return out + +def judge_all(jobs: list[dict], census_by_stem: dict, scouts_by_stem: dict) -> list[dict]: + verdicts = [] + for job in jobs: + stem = job["stem"] + c = census_by_stem.get(stem) or {"stem": stem, "installed_version": job.get("note_version"), "source": "note" if job.get("note_version") else "unknown", "sha256": None} + s = scouts_by_stem.get(stem) or {"stem": stem, "latest_english_version": None, "url": None, "gate": None, "upstream_status": None} + verdicts.append(judge_one(job, c, s)) + return verdicts diff --git a/tests/update_swarm/test_judge.py b/tests/update_swarm/test_judge.py new file mode 100644 index 0000000..3d3a66a --- /dev/null +++ b/tests/update_swarm/test_judge.py @@ -0,0 +1,60 @@ +import os, sys, unittest +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.judge import judge_one + +def job(**kw): + base = {"stem": "X", "watchlist": False, "wanted": False, "note_version": None} + base.update(kw) + return base + +def census(**kw): + base = {"stem": "X", "installed_version": "1.0", "source": "file", "sha256": "aa"} + base.update(kw) + return base + +def scout(**kw): + base = {"stem": "X", "latest_english_version": "1.1", "url": "https://github.com/a/b/releases/download/v1.1/x.zip", + "host": "github", "gate": "ungated", "upstream_status": "Complete", "sha256": None} + base.update(kw) + return base + +class TestJudge(unittest.TestCase): + def test_update_ungated(self): + v = judge_one(job(), census(), scout()) + self.assertEqual(v["bucket"], "update") + self.assertEqual(v["fetch_url"], scout()["url"]) + + def test_current_when_installed_newer_or_equal(self): + v = judge_one(job(), census(installed_version="1.1"), scout()) + self.assertEqual(v["bucket"], "current") + + def test_gated_queue_and_complete_bump(self): + v = judge_one(job(), census(), scout(gate="gated", url="https://foo.itch.io/x")) + self.assertEqual(v["bucket"], "gated_queue") + self.assertEqual(v["bump_status"], "Complete") + self.assertIsNone(v["fetch_url"]) + + def test_watchlist_promote_and_report(self): + p = judge_one(job(watchlist=True), census(), scout(upstream_status="Complete")) + self.assertEqual(p["bucket"], "watchlist_promote") + self.assertTrue(p["remove_from_watchlist"]) + r = judge_one(job(watchlist=True), census(), scout(upstream_status="Beta")) + self.assertEqual(r["bucket"], "watchlist_report") + self.assertFalse(r["remove_from_watchlist"]) + + def test_watchlist_complete_but_gated_is_queue(self): + v = judge_one(job(watchlist=True), census(), scout(gate="gated", url="https://foo.itch.io/x")) + self.assertEqual(v["bucket"], "gated_queue") + + def test_no_latest_and_incomparable(self): + self.assertEqual(judge_one(job(), census(), scout(latest_english_version=None))["bucket"], "current") + self.assertEqual(judge_one(job(), census(installed_version="Final"), scout())["bucket"], "incomparable") + + def test_unknown_installed_hash_match(self): + v = judge_one(job(), census(installed_version=None, source="unknown", sha256="dead"), + scout(sha256="dead")) + self.assertEqual(v["bucket"], "current") + +if __name__ == "__main__": + unittest.main() From 003b2ab11125182c6dc2b89613b75c8447bbecee Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:52:41 -0500 Subject: [PATCH 07/16] fix: repair 7 mojibake note filenames Seven hack notes had filenames whose UTF-8 bytes had been decoded as cp437 and re-encoded, e.g. "Anil.md" stored as "A" + U+251C + U+2592 + "il.md". Only the filenames were affected; each note's frontmatter title was already correct. Repaired by reversing the corruption (name.encode('cp437').decode('utf-8')) and cross-checking every result against that note's own title field. PokeRogue was left alone - its U+00E9 cannot be cp437-encoded, proving it is genuine UTF-8 and not mojibake. This matters because build-wiki-data.py derives each catalog stem from the filename and the site derives its URL slug from that. Four published URLs were wrong and are now fixed: /hack/a-il/ -> /hack/anil/ /hack/fused-adimensions/ -> /hack/fused-dimensions/ /hack/yu-gi-oh-pok-duel/ -> /hack/yu-gi-oh-pokeduel/ /hack/recharged-yellow-previously-known-as-pok-mon-yellow-cross/ -> ...-as-pokemon-yellow-cross/ The other three were already served correctly, because slugifyStem in the site repo carries a replaceAll for the mojibake apostrophe. Those URLs are unchanged. Fallout handled: of 19 vault references, 18 live in files build-vault-mocs.py regenerates and were fixed by rerunning it. The one hand-written reference, in Nuzlocke-Friendly (Vanilla+).md, was updated directly. annotate-engines.py also keyed its ENGINE_MAP on the corrupted stem, so a future run would have silently skipped Recharged Yellow; that key is corrected here. Verified: zero mojibake sequences remain anywhere in the vault or this repo, all seven notes resolve under their new names, catalog steady at 411, and the site builds 486 pages with banners regenerated under the new slugs. Co-Authored-By: Claude Opus 5 --- scripts/annotate-engines.py | 2 +- wiki/catalog.json | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/annotate-engines.py b/scripts/annotate-engines.py index cbaef78..d5bcc1c 100644 --- a/scripts/annotate-engines.py +++ b/scripts/annotate-engines.py @@ -61,7 +61,7 @@ ENGINE_MAP = { "Recharged Emerald": "pokeemerald-expansion (likely)", "Recharged Emerald Rebalanced": "pokeemerald-expansion (likely)", # rebalanced/difficulty variant "Recharged Pink": "pokeemerald-expansion (likely)", - "Recharged Yellow (previously known as Pok├⌐mon Yellow Cross)": "pokeemerald-expansion (likely)", + "Recharged Yellow (previously known as Pokémon Yellow Cross)": "pokeemerald-expansion (likely)", # Emerald Cross (Jaizu) — vanilla+ QoL/bugfix, no expansion → lighter decomp build "Emerald Cross": "pokeemerald (decomp, likely)", # --- HeartGold → hg-engine ------------------------------------------------ diff --git a/wiki/catalog.json b/wiki/catalog.json index 6d49367..3f0d58e 100644 --- a/wiki/catalog.json +++ b/wiki/catalog.json @@ -106,7 +106,7 @@ "image_base": "https://romhacks-files.ginnoir.com", "hacks": [ { - "stem": "A FarfetchΓÇÖD Story", + "stem": "A Farfetch’D Story", "title": "Pokémon A Farfetch’D Story", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", @@ -1412,7 +1412,7 @@ ] }, { - "stem": "A├▒il", + "stem": "Añil", "title": "Pokémon Añil", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", @@ -1726,7 +1726,7 @@ ] }, { - "stem": "BirchΓÇÖs Folly", + "stem": "Birch’s Folly", "title": "Pokémon Birch’s Folly", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", @@ -7864,7 +7864,7 @@ ] }, { - "stem": "Fused┬áDimensions", + "stem": "Fused Dimensions", "title": "Pokémon Fused Dimensions", "platform": "GBA", "base": "FireRed", @@ -11409,7 +11409,7 @@ ] }, { - "stem": "LetΓÇÖs Beat Mew", + "stem": "Let’s Beat Mew", "title": "Pokémon Let’s Beat Mew", "platform": "GBA", "base": "FireRed", @@ -16627,7 +16627,7 @@ ] }, { - "stem": "Recharged Yellow (previously known as Pok├⌐mon Yellow Cross)", + "stem": "Recharged Yellow (previously known as Pokémon Yellow Cross)", "title": "Pokémon Recharged Yellow (previously known as Pokémon Yellow Cross)", "platform": "GBA", "base": "Emerald", @@ -24096,7 +24096,7 @@ ] }, { - "stem": "Yu-Gi-Oh Pok├⌐Duel", + "stem": "Yu-Gi-Oh PokéDuel", "title": "Pokémon Yu-Gi-Oh PokéDuel", "platform": "GBA", "base": "FireRed", From dd62312f8770b3b75a19486e70b3b227d18898db Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:55:33 -0500 Subject: [PATCH 08/16] feat: fetch ungated update-swarm artifacts into staging --- scripts/update_swarm/fetch.py | 59 ++++++++++++++++++++++++++++++++ tests/update_swarm/test_fetch.py | 49 ++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 scripts/update_swarm/fetch.py create mode 100644 tests/update_swarm/test_fetch.py diff --git a/scripts/update_swarm/fetch.py b/scripts/update_swarm/fetch.py new file mode 100644 index 0000000..67ccdfe --- /dev/null +++ b/scripts/update_swarm/fetch.py @@ -0,0 +1,59 @@ +from __future__ import annotations +import hashlib, os, re, urllib.request, zipfile +from update_swarm.census import _from_text, CHANGELOG_NAMES +from update_swarm.hosts import classify_url +from update_swarm.versions import compare_versions + +UA = "Mozilla/5.0 (homelab personal archival)" +MF = re.compile(r"https://download\d+\.mediafire\.com/[^\"'\s<>]+") + +class GatedHostError(ValueError): + pass + +def resolve_mediafire(html: str) -> str | None: + m = MF.search(html or "") + return m.group(0) if m else None + +def _open(url: str, opener=None): + req = urllib.request.Request(url, headers={"User-Agent": UA}) + if opener: + return opener(req) + return urllib.request.urlopen(req) + +def download(url: str, dest_path: str, opener=None) -> dict: + host, gate = classify_url(url) + if gate == "gated": + raise GatedHostError(f"{host} is gated: {url}") + if host == "mega": + raise NotImplementedError("mega downloads use megadl in the CLI") + fetch_url = url + if host == "mediafire" and "/file/" in url: + with _open(url, opener) as resp: + html = resp.read().decode("utf-8", "ignore") + direct = resolve_mediafire(html) + if not direct: + raise ValueError("no mediafire direct link") + fetch_url = direct + os.makedirs(os.path.dirname(dest_path) or ".", exist_ok=True) + h = hashlib.sha256() + size = 0 + with _open(fetch_url, opener) as resp, open(dest_path, "wb") as out: + while True: + chunk = resp.read(1024 * 1024) + if not chunk: + break + out.write(chunk) + h.update(chunk) + size += len(chunk) + return {"path": dest_path, "sha256": h.hexdigest(), "size": size, "url": fetch_url} + +def english_mismatch(archive_path: str, expected_version: str) -> bool: + if not zipfile.is_zipfile(archive_path): + return False + with zipfile.ZipFile(archive_path) as z: + for n in z.namelist(): + if os.path.basename(n).lower() in CHANGELOG_NAMES: + found = _from_text(z.read(n).decode("utf-8", "ignore")) + if found and compare_versions(found, expected_version) != "eq": + return True + return False diff --git a/tests/update_swarm/test_fetch.py b/tests/update_swarm/test_fetch.py new file mode 100644 index 0000000..4cd8f93 --- /dev/null +++ b/tests/update_swarm/test_fetch.py @@ -0,0 +1,49 @@ +import os, sys, tempfile, unittest, zipfile +from unittest.mock import patch +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.fetch import GatedHostError, download, english_mismatch, resolve_mediafire + +class TestFetch(unittest.TestCase): + def test_mediafire_regex(self): + html = 'dl' + self.assertEqual(resolve_mediafire(html), "https://download123.mediafire.com/abc/file.zip") + + def test_refuses_gated(self): + with tempfile.TemporaryDirectory() as td: + with self.assertRaises(GatedHostError): + download("https://foo.itch.io/x", os.path.join(td, "x.zip")) + + def test_download_writes_bytes(self): + class Resp: + def __init__(self): + self._done = False + def __enter__(self): return self + def __exit__(self, *a): pass + def read(self, n=-1): + if self._done: + return b"" + self._done = True + return b"rombytes" + with tempfile.TemporaryDirectory() as td: + dest = os.path.join(td, "g.gba") + with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()): + rec = download("https://github.com/a/b/releases/download/v1/g.gba", dest) + self.assertTrue(os.path.isfile(dest)) + self.assertEqual(rec["size"], 8) + + def test_mega_not_implemented(self): + with tempfile.TemporaryDirectory() as td: + with self.assertRaises(NotImplementedError): + download("https://mega.nz/file/abc#key", os.path.join(td, "x")) + + def test_changelog_mismatch(self): + with tempfile.TemporaryDirectory() as td: + zpath = os.path.join(td, "g.zip") + with zipfile.ZipFile(zpath, "w") as z: + z.writestr("changelog.txt", "Current Version: 2.16\n") + self.assertTrue(english_mismatch(zpath, "2.13")) + self.assertFalse(english_mismatch(zpath, "v2.16 (ES)")) + +if __name__ == "__main__": + unittest.main() From 5445f82d9169a91e3ec49328dbce2b6a37ce12af Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:57:17 -0500 Subject: [PATCH 09/16] feat: librarian helpers for superseded names, note patch, scoped RomM scan --- scripts/update_swarm/librarian.py | 42 +++++++++++++++++++++++++++ tests/update_swarm/test_librarian.py | 43 ++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 scripts/update_swarm/librarian.py create mode 100644 tests/update_swarm/test_librarian.py diff --git a/scripts/update_swarm/librarian.py b/scripts/update_swarm/librarian.py new file mode 100644 index 0000000..06ec731 --- /dev/null +++ b/scripts/update_swarm/librarian.py @@ -0,0 +1,42 @@ +from __future__ import annotations +import os, sys +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import enrich_vault as E +import enrich_web as W + +ROMM_PLATFORM_IDS = {"GBA": 72, "PC": 200, "windows": 200} + +def require_platform_id(platform: str) -> int: + if platform not in ROMM_PLATFORM_IDS: + raise KeyError(f"no RomM platform_id for {platform!r}; add it to ROMM_PLATFORM_IDS") + return ROMM_PLATFORM_IDS[platform] + +def superseded_name(live_basename: str, old_version: str) -> str: + root, ext = os.path.splitext(live_basename) + return f"{root} ({old_version}){ext}" + +def romm_scan_argv(platform_ids: list[int]) -> list[str]: + if not platform_ids: + raise ValueError("platform_ids is required; refusing a full-library walk") + ids = "[" + ", ".join(str(i) for i in platform_ids) + "]" + py = ( + "import asyncio; from endpoints.sockets.scan import scan_platforms; " + "from handler.scan_handler import ScanType; " + f"asyncio.run(scan_platforms(platform_ids={ids}, metadata_sources=[], scan_type=ScanType.QUICK))" + ) + return ["docker", "exec", "-w", "/backend", "romm", "python3", "-c", py] + +def patch_note(path: str, version: str, release_date: str | None, + source_url: str | None, history_md: str | None, status: str | None) -> str: + fm_text, body, _ = E.read_note(path) + fm = E.parse_fm(fm_text) + fm["version"] = version + if release_date: + fm["release_date"] = release_date + if source_url: + fm["source"] = source_url + if status: + fm["status"] = status + if history_md: + body = W.set_section(body, "Version history", history_md.strip()) + return f"---\n{E.emit_fm(fm)}\n---\n{body}" diff --git a/tests/update_swarm/test_librarian.py b/tests/update_swarm/test_librarian.py new file mode 100644 index 0000000..c6dc8f1 --- /dev/null +++ b/tests/update_swarm/test_librarian.py @@ -0,0 +1,43 @@ +import 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.librarian import patch_note, require_platform_id, romm_scan_argv, superseded_name + +class TestLibrarian(unittest.TestCase): + def test_superseded_name(self): + self.assertEqual( + superseded_name("Pokemon - Z [Hack].zip", "v2.16 ES"), + "Pokemon - Z [Hack] (v2.16 ES).zip", + ) + + def test_romm_requires_platform_ids(self): + argv = romm_scan_argv([72, 200]) + joined = " ".join(argv) + self.assertIn("platform_ids=[72,200]", joined.replace(" ", "")) + with self.assertRaises(ValueError): + romm_scan_argv([]) + self.assertEqual(require_platform_id("GBA"), 72) + self.assertEqual(require_platform_id("PC"), 200) + with self.assertRaises(KeyError): + require_platform_id("GameCube") + + def test_patch_note_version_and_history(self): + src = ( + "---\n" + 'title: "Pokémon Z"\n' + 'version: "2.17"\n' + "status: Complete\n" + "---\n\n" + "## Summary\n\nKeep me.\n" + ) + with tempfile.TemporaryDirectory() as td: + path = os.path.join(td, "Z.md") + open(path, "w", encoding="utf-8").write(src) + text = patch_note(path, "v2.13 (EN)", "2026-03-30", "https://example.com/z", "- EN 2.13\n", None) + self.assertIn('version: "v2.13 (EN)"', text) + self.assertIn("## Version history", text) + self.assertIn("## Summary\n\nKeep me.", text) + self.assertNotIn("**bold**", text.split("## Summary")[1].split("##")[0]) + +if __name__ == "__main__": + unittest.main() From a34686f7a5e78d8d3edd17b5f1e6cdda293a2ba2 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:58:55 -0500 Subject: [PATCH 10/16] feat: update-swarm CLI, scout schema, gated and watchlist reports --- scripts/update-swarm.py | 6 ++ scripts/update_swarm/cli.py | 84 ++++++++++++++++++++++++++++ scripts/update_swarm/reports.py | 14 +++++ scripts/update_swarm/scout_prompt.md | 24 ++++++++ tests/update_swarm/test_cli.py | 45 +++++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 scripts/update-swarm.py create mode 100644 scripts/update_swarm/cli.py create mode 100644 scripts/update_swarm/reports.py create mode 100644 scripts/update_swarm/scout_prompt.md create mode 100644 tests/update_swarm/test_cli.py diff --git a/scripts/update-swarm.py b/scripts/update-swarm.py new file mode 100644 index 0000000..de03308 --- /dev/null +++ b/scripts/update-swarm.py @@ -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()) diff --git a/scripts/update_swarm/cli.py b/scripts/update_swarm/cli.py new file mode 100644 index 0000000..ea50e19 --- /dev/null +++ b/scripts/update_swarm/cli.py @@ -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()) diff --git a/scripts/update_swarm/reports.py b/scripts/update_swarm/reports.py new file mode 100644 index 0000000..53ee6f7 --- /dev/null +++ b/scripts/update_swarm/reports.py @@ -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) diff --git a/scripts/update_swarm/scout_prompt.md b/scripts/update_swarm/scout_prompt.md new file mode 100644 index 0000000..1994850 --- /dev/null +++ b/scripts/update_swarm/scout_prompt.md @@ -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) diff --git a/tests/update_swarm/test_cli.py b/tests/update_swarm/test_cli.py new file mode 100644 index 0000000..91721e5 --- /dev/null +++ b/tests/update_swarm/test_cli.py @@ -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() From 37ebc97b51b33cd8232ac50f73945d23aecd7729 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 15:03:11 -0500 Subject: [PATCH 11/16] fix: normalise the non-breaking space in Fused Dimensions The note's filename and title carried U+00A0 rather than a plain space. That was the faithful original - the mojibake repair reversed to it correctly - but it is a scrape artefact, not an authored name: nobody titles a hack with a non-breaking space, and an invisible character in a filename is the same class of trap as the mojibake itself, since it silently breaks greps and hand-typed wikilinks. No URL impact. NFKD folds U+00A0 to a plain space, so slugifyStem already produced 'fused-dimensions' either way; the published URL is unchanged. Renamed the note, replaced both in-file occurrences (the title field and the H1) and regenerated, so the MOC wikilinks now use a plain space too. Verified no filename, catalog stem or catalog title anywhere still contains U+00A0. Co-Authored-By: Claude Opus 5 --- wiki/catalog.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wiki/catalog.json b/wiki/catalog.json index 3f0d58e..f978188 100644 --- a/wiki/catalog.json +++ b/wiki/catalog.json @@ -7864,8 +7864,8 @@ ] }, { - "stem": "Fused Dimensions", - "title": "Pokémon Fused Dimensions", + "stem": "Fused Dimensions", + "title": "Pokémon Fused Dimensions", "platform": "GBA", "base": "FireRed", "version": null, From cb294f72a06ff0e4ae27fd9db13937651ea65c6d Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 15:11:16 -0500 Subject: [PATCH 12/16] fix: address whole-branch review findings for update-swarm - versions: require entire normalized string to be numeric so dates and hotfix suffixes compare as incomparable instead of eq/gt - hosts: exact host or dot-suffix match rejects lookalikes like notmediafire.com and evilmega.nz; GitHub stays exact-set - census: lazy extractor loop so a later OSError no longer discards an earlier sidecar changelog hit - jobs: watchlist parses only table rows whose vault-note cell is a bare wikilink (skips parenthetical related/complete notes); wanted also matches bold names in Wanted.md tables with Pokemon prefix stripped and casefolded - cli: validate-scouts and judge raise SystemExit when jobs.json has jobs but scouts/ has zero valid files - fetch: download forwards timeout=60 to urlopen and writes to a .part file then os.replace, removing the partial on any failure --- scripts/update_swarm/census.py | 17 +++++--- scripts/update_swarm/cli.py | 9 ++-- scripts/update_swarm/fetch.py | 27 +++++++----- scripts/update_swarm/hosts.py | 40 ++++++++++------- scripts/update_swarm/jobs.py | 43 ++++++++++++++++--- scripts/update_swarm/versions.py | 2 +- .../vault/Pokémon ROM Hacks/Demo Watchlist.md | 8 ++-- .../Pokémon ROM Hacks/Hacks/Light Platinum.md | 8 ++++ .../vault/Pokémon ROM Hacks/Hacks/Odyssey.md | 8 ++++ .../vault/Pokémon ROM Hacks/Wanted.md | 14 ++++++ tests/update_swarm/test_census.py | 19 ++++++++ tests/update_swarm/test_cli.py | 37 +++++++++++++++- tests/update_swarm/test_fetch.py | 18 +++++++- tests/update_swarm/test_hosts.py | 11 +++++ tests/update_swarm/test_jobs.py | 14 +++++- tests/update_swarm/test_versions.py | 7 +++ 16 files changed, 234 insertions(+), 48 deletions(-) create mode 100644 tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Light Platinum.md create mode 100644 tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Odyssey.md diff --git a/scripts/update_swarm/census.py b/scripts/update_swarm/census.py index a7b95f1..f86bbbf 100644 --- a/scripts/update_swarm/census.py +++ b/scripts/update_swarm/census.py @@ -80,12 +80,17 @@ def census_job(job: dict, file_path: str | None) -> dict: } if file_path and os.path.isfile(file_path): rec["sha256"], rec["size"] = _sha_size(file_path) - for found, evidence in ( - (_sidecar_version(file_path), "sidecar"), - (_zip_version(file_path), "zip"), - (_filename_version(file_path), "filename"), - (_rom_version(file_path), "rom-bytes"), - ): + extractors = ( + (_sidecar_version, "sidecar"), + (_zip_version, "zip"), + (_filename_version, "filename"), + (_rom_version, "rom-bytes"), + ) + for fn, evidence in extractors: + try: + found = fn(file_path) + except OSError: + found = None if found: rec["installed_version"] = found rec["source"] = "file" diff --git a/scripts/update_swarm/cli.py b/scripts/update_swarm/cli.py index ea50e19..f35725c 100644 --- a/scripts/update_swarm/cli.py +++ b/scripts/update_swarm/cli.py @@ -18,7 +18,7 @@ def deploy_argv(pokemon_repo: str, site_repo: str) -> list[list[str]]: ["powershell", "-File", "scripts/deploy-site.ps1"], ] -def _load_scouts(run_dir: str) -> dict: +def _load_scouts(run_dir: str, jobs: list[dict] | None = None) -> dict: out = {} for path in glob.glob(os.path.join(run_dir, "scouts", "*.json")): obj = read_json(path) @@ -26,6 +26,8 @@ def _load_scouts(run_dir: str) -> dict: if errs: raise SystemExit(f"{path} missing keys: {errs}") out[obj["stem"]] = obj + if jobs and len(jobs) > 0 and not out: + raise SystemExit("no valid scout files in scouts/ but jobs.json has jobs") return out def _load_census(run_dir: str) -> dict: @@ -61,14 +63,15 @@ def main(argv=None) -> int: if args.cmd == "validate-scouts": if not args.run: raise SystemExit("--run is required") - _load_scouts(args.run) + jobs = read_json(os.path.join(args.run, "jobs.json")).get("jobs") + _load_scouts(args.run, jobs) 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)) + verdicts = judge_all(jobs, _load_census(args.run), _load_scouts(args.run, jobs)) write_json(os.path.join(args.run, "verdict.json"), {"verdicts": verdicts}) print(f"wrote {len(verdicts)} verdicts") return 0 diff --git a/scripts/update_swarm/fetch.py b/scripts/update_swarm/fetch.py index 67ccdfe..5abfac2 100644 --- a/scripts/update_swarm/fetch.py +++ b/scripts/update_swarm/fetch.py @@ -17,8 +17,8 @@ def resolve_mediafire(html: str) -> str | None: def _open(url: str, opener=None): req = urllib.request.Request(url, headers={"User-Agent": UA}) if opener: - return opener(req) - return urllib.request.urlopen(req) + return opener(req, timeout=60) + return urllib.request.urlopen(req, timeout=60) def download(url: str, dest_path: str, opener=None) -> dict: host, gate = classify_url(url) @@ -35,16 +35,23 @@ def download(url: str, dest_path: str, opener=None) -> dict: raise ValueError("no mediafire direct link") fetch_url = direct os.makedirs(os.path.dirname(dest_path) or ".", exist_ok=True) + part_path = dest_path + ".part" h = hashlib.sha256() size = 0 - with _open(fetch_url, opener) as resp, open(dest_path, "wb") as out: - while True: - chunk = resp.read(1024 * 1024) - if not chunk: - break - out.write(chunk) - h.update(chunk) - size += len(chunk) + try: + with _open(fetch_url, opener) as resp, open(part_path, "wb") as out: + while True: + chunk = resp.read(1024 * 1024) + if not chunk: + break + out.write(chunk) + h.update(chunk) + size += len(chunk) + except BaseException: + if os.path.exists(part_path): + os.remove(part_path) + raise + os.replace(part_path, dest_path) return {"path": dest_path, "sha256": h.hexdigest(), "size": size, "url": fetch_url} def english_mismatch(archive_path: str, expected_version: str) -> bool: diff --git a/scripts/update_swarm/hosts.py b/scripts/update_swarm/hosts.py index 45378c1..fe7d049 100644 --- a/scripts/update_swarm/hosts.py +++ b/scripts/update_swarm/hosts.py @@ -1,30 +1,40 @@ from __future__ import annotations from urllib.parse import urlparse +GITHUB_HOSTS = frozenset(("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com")) +# Exact host or dot-suffix match — `endswith(d)` alone accepts lookalikes like +# `notmediafire.com` or `evilmega.nz`. +SUFFIX_HOSTS = { + "archive.org": "archive", + "mediafire.com": "mediafire", + "mega.nz": "mega", + "mega.co.nz": "mega", + "itch.io": "itch", + "ko-fi.com": "kofi", + "hackdex.app": "hackdex", + "pokecommunity.com": "pokecommunity", +} + +def _host_match(host: str, domain: str) -> bool: + return host == domain or host.endswith("." + domain) + def classify_url(url: str) -> tuple[str, str]: p = urlparse(url or "") host = (p.netloc or "").lower().removeprefix("www.") path = p.path or "" - if host in ("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com"): + if host in GITHUB_HOSTS: if host != "github.com" or "/releases/download/" in path: return "github", "ungated" return "github", "gated" - if host.endswith("archive.org"): - return "archive", "ungated" - if host.endswith("mediafire.com"): - return "mediafire", "ungated" - if host.endswith("mega.nz") or host.endswith("mega.co.nz"): - return "mega", "ungated" if p.fragment else "gated" - if host.endswith("itch.io"): - return "itch", "gated" + for domain, label in SUFFIX_HOSTS.items(): + if _host_match(host, domain): + if label == "mega": + return "mega", "ungated" if p.fragment else "gated" + if label in ("archive", "mediafire"): + return label, "ungated" + return label, "gated" if host in ("drive.google.com", "docs.google.com"): return "drive", "gated" if host in ("discord.com", "discord.gg"): return "discord", "gated" - if host.endswith("ko-fi.com"): - return "kofi", "gated" - if host.endswith("hackdex.app"): - return "hackdex", "gated" - if host.endswith("pokecommunity.com"): - return "pokecommunity", "gated" return "other", "gated" diff --git a/scripts/update_swarm/jobs.py b/scripts/update_swarm/jobs.py index bd2baa8..692d0b7 100644 --- a/scripts/update_swarm/jobs.py +++ b/scripts/update_swarm/jobs.py @@ -6,17 +6,45 @@ import enrich_vault as E from update_swarm.schema import write_json WIKILINK = re.compile(r"\[\[([^\]|#]+)") +BOLD = re.compile(r"\*\*([^*]+)\*\*") +WL_CELL = re.compile(r"^\s*\[\[([^\]|#]+)\]\]\s*$") +POKE_PREFIX = re.compile(r"^pokémon\s+", re.I) -def _links(path: str) -> set[str]: +def _norm_stem(s: str) -> str: + return POKE_PREFIX.sub("", s.strip()).casefold() + +def _watchlist_stems(path: str) -> set[str]: if not os.path.isfile(path): return set() - text = open(path, encoding="utf-8").read() - return {m.strip() for m in WIKILINK.findall(text)} + stems: set[str] = set() + with open(path, encoding="utf-8") as fh: + for line in fh: + if not line.lstrip().startswith("|"): + continue + for cell in line.split("|"): + m = WL_CELL.match(cell) + if m: + stems.add(m.group(1).strip()) + return stems + +def _wanted_stems(path: str) -> set[str]: + if not os.path.isfile(path): + return set() + with open(path, encoding="utf-8") as fh: + text = fh.read() + stems = {m.strip() for m in WIKILINK.findall(text)} + for line in text.splitlines(): + if not line.lstrip().startswith("|"): + continue + for cell in line.split("|"): + for m in BOLD.finditer(cell): + stems.add(m.group(1).strip()) + return stems def build_jobs(vault_romhacks_dir: str) -> list[dict]: hacks = os.path.join(vault_romhacks_dir, "Hacks") - watch = _links(os.path.join(vault_romhacks_dir, "Demo Watchlist.md")) - wanted = _links(os.path.join(vault_romhacks_dir, "Wanted.md")) + watch = {_norm_stem(s) for s in _watchlist_stems(os.path.join(vault_romhacks_dir, "Demo Watchlist.md"))} + wanted = {_norm_stem(s) for s in _wanted_stems(os.path.join(vault_romhacks_dir, "Wanted.md"))} jobs = [] for path in sorted(glob.glob(os.path.join(hacks, "*.md"))): stem = os.path.splitext(os.path.basename(path))[0] @@ -24,6 +52,7 @@ def build_jobs(vault_romhacks_dir: str) -> list[dict]: fm = E.parse_fm(fm_text) def blank(v): return None if v in (None, "", "—") else v + nstem = _norm_stem(stem) jobs.append({ "stem": stem, "title": fm.get("title") or stem, @@ -33,8 +62,8 @@ def build_jobs(vault_romhacks_dir: str) -> list[dict]: "source": blank(fm.get("source")), "note_version": blank(fm.get("version")), "note_status": blank(fm.get("status")), - "watchlist": stem in watch, - "wanted": stem in wanted, + "watchlist": nstem in watch, + "wanted": nstem in wanted, }) return jobs diff --git a/scripts/update_swarm/versions.py b/scripts/update_swarm/versions.py index 55a85d2..7a2a02e 100644 --- a/scripts/update_swarm/versions.py +++ b/scripts/update_swarm/versions.py @@ -3,7 +3,7 @@ import re _LANG = re.compile(r"\s*\((EN|ES|FR|DE|IT|PT|JP)\)\s*", re.I) _LEADING_V = re.compile(r"^\s*v", re.I) -_NUMERIC = re.compile(r"^(\d+(?:\.\d+)*)") +_NUMERIC = re.compile(r"^(\d+(?:\.\d+)*)\s*$") def normalize_version(s: str) -> str: s = _LANG.sub(" ", s or "") diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md index 2fe5218..5b2c409 100644 --- a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md @@ -1,3 +1,5 @@ -| Hack | Vault note | -|---|---| -| **DemoOnly** | [[DemoOnly]] | +| Hack | Vault note | Why parked | Where to watch | +|---|---|---|---| +| **DemoOnly** | [[DemoOnly]] | Essentials demo v0.6.2 | Eevee Expo | +| **Odyssey II / Heroes of Lemuria** | [[Odyssey]] (related) | Demo / early build | Discord | +| **Light Platinum DS** | [[Light Platinum]] (GBA complete; DS is separate) | DS remake — media/teasers only | Twitter | diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Light Platinum.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Light Platinum.md new file mode 100644 index 0000000..af15c59 --- /dev/null +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Light Platinum.md @@ -0,0 +1,8 @@ +--- +title: "Pokémon Light Platinum" +platform: GBA +version: "1.0" +status: Complete +--- + +# Pokémon Light Platinum diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Odyssey.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Odyssey.md new file mode 100644 index 0000000..db86f8c --- /dev/null +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/Odyssey.md @@ -0,0 +1,8 @@ +--- +title: "Pokémon Odyssey" +platform: GBA +version: "1.0" +status: Complete +--- + +# Pokémon Odyssey diff --git a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md index 85739d8..cb02027 100644 --- a/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md +++ b/tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md @@ -1 +1,15 @@ +# Wanted — Manual Acquisition List + See [[FakeHack]] still gated. + +## Acquired + +| Hack | Path | +|---|---| +| **FakeHack** | `gba/Hacks/Pokemon - FakeHack (Hack).gba` | + +## Still wanted + +| Hack | Notes | +|---|---| +| **DemoOnly** | demo-only entry, not in library yet | diff --git a/tests/update_swarm/test_census.py b/tests/update_swarm/test_census.py index 6f8f230..4bf9f4a 100644 --- a/tests/update_swarm/test_census.py +++ b/tests/update_swarm/test_census.py @@ -50,5 +50,24 @@ class TestCensus(unittest.TestCase): self.assertEqual(rec2["source"], "unknown") self.assertIsNone(rec2["installed_version"]) + @patch( + "update_swarm.census.os.listdir", + return_value=["changelog.txt", "dummy.bin"], + ) + def test_rom_version_oserror_keeps_sidecar(self, _listdir): + # A later OSError must not discard an earlier sidecar hit. + with tempfile.TemporaryDirectory() as td: + cpath = os.path.join(td, "changelog.txt") + with open(cpath, "w", encoding="utf-8") as fh: + fh.write("Current Version: 3.3.1\n") + rom_path = os.path.join(td, "dummy.bin") + with open(rom_path, "wb") as fh: + fh.write(b"\x00") + with patch("update_swarm.census._rom_version", side_effect=OSError("boom")): + rec = census_job(job("S"), rom_path) + self.assertEqual(rec["installed_version"], "3.3.1") + self.assertEqual(rec["source"], "file") + self.assertEqual(rec["evidence"], "sidecar") + if __name__ == "__main__": unittest.main() diff --git a/tests/update_swarm/test_cli.py b/tests/update_swarm/test_cli.py index 91721e5..38bf4f3 100644 --- a/tests/update_swarm/test_cli.py +++ b/tests/update_swarm/test_cli.py @@ -1,8 +1,9 @@ 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.cli import deploy_argv, validate_scout, main from update_swarm.reports import write_reports +from update_swarm.schema import write_json class TestCli(unittest.TestCase): def test_validate_scout_missing_keys(self): @@ -41,5 +42,39 @@ class TestCli(unittest.TestCase): self.assertIn("latest_english_version", text) self.assertIn("Do not invent versions", text) + def _valid_scout(self, stem): + return { + "stem": stem, "latest_english_version": "1.0", "url": "https://example.com/z.zip", + "host": "other", "gate": "gated", "language_matrix": {"en": "1.0"}, + "source_used": "website", "hackdex": "skipped", "upstream_status": "Complete", "notes": "", + } + + def test_validate_scouts_fails_when_jobs_but_no_scouts(self): + with tempfile.TemporaryDirectory() as td: + run = os.path.join(td, "2026-08-14") + os.makedirs(os.path.join(run, "scouts")) + write_json(os.path.join(run, "jobs.json"), + {"run_date": "2026-08-14", "jobs": [{"stem": "X"}]}) + with self.assertRaises(SystemExit): + main(["--run", run, "validate-scouts"]) + + def test_validate_scouts_ok_when_scouts_present(self): + with tempfile.TemporaryDirectory() as td: + run = os.path.join(td, "2026-08-14") + scouts = os.path.join(run, "scouts") + os.makedirs(scouts) + write_json(os.path.join(run, "jobs.json"), + {"run_date": "2026-08-14", "jobs": [{"stem": "X"}]}) + write_json(os.path.join(scouts, "X.json"), self._valid_scout("X")) + self.assertEqual(main(["--run", run, "validate-scouts"]), 0) + + def test_validate_scouts_ok_when_no_jobs(self): + with tempfile.TemporaryDirectory() as td: + run = os.path.join(td, "2026-08-14") + os.makedirs(os.path.join(run, "scouts")) + write_json(os.path.join(run, "jobs.json"), + {"run_date": "2026-08-14", "jobs": []}) + self.assertEqual(main(["--run", run, "validate-scouts"]), 0) + if __name__ == "__main__": unittest.main() diff --git a/tests/update_swarm/test_fetch.py b/tests/update_swarm/test_fetch.py index 4cd8f93..28505df 100644 --- a/tests/update_swarm/test_fetch.py +++ b/tests/update_swarm/test_fetch.py @@ -27,10 +27,26 @@ class TestFetch(unittest.TestCase): return b"rombytes" with tempfile.TemporaryDirectory() as td: dest = os.path.join(td, "g.gba") - with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()): + with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()) as mock_urlopen: rec = download("https://github.com/a/b/releases/download/v1/g.gba", dest) self.assertTrue(os.path.isfile(dest)) self.assertEqual(rec["size"], 8) + # timeout kwarg must be forwarded to urlopen + self.assertEqual(mock_urlopen.call_args.kwargs.get("timeout"), 60) + + def test_download_failure_leaves_no_dest(self): + class Resp: + def __enter__(self): return self + def __exit__(self, *a): pass + def read(self, n=-1): + raise OSError("network died") + with tempfile.TemporaryDirectory() as td: + dest = os.path.join(td, "g.gba") + with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()): + with self.assertRaises(OSError): + download("https://github.com/a/b/releases/download/v1/g.gba", dest) + self.assertFalse(os.path.exists(dest)) + self.assertFalse(os.path.exists(dest + ".part")) def test_mega_not_implemented(self): with tempfile.TemporaryDirectory() as td: diff --git a/tests/update_swarm/test_hosts.py b/tests/update_swarm/test_hosts.py index f401fc5..64707ac 100644 --- a/tests/update_swarm/test_hosts.py +++ b/tests/update_swarm/test_hosts.py @@ -20,5 +20,16 @@ class TestClassify(unittest.TestCase): self.assertEqual(classify_url("https://www.pokecommunity.com/threads/x.1/"), ("pokecommunity", "gated")) self.assertEqual(classify_url("https://mystery.example/file.zip"), ("other", "gated")) + def test_lookalike_hosts_are_gated(self): + self.assertEqual(classify_url("https://notmediafire.com/x"), ("other", "gated")) + self.assertEqual(classify_url("https://evilmega.nz/file/a#k"), ("other", "gated")) + self.assertEqual(classify_url("https://notarchive.org/x"), ("other", "gated")) + self.assertEqual(classify_url("https://notitch.io/x"), ("other", "gated")) + + def test_real_hosts_still_classified(self): + self.assertEqual(classify_url("https://www.mediafire.com/file/abc/x.zip/file"), ("mediafire", "ungated")) + self.assertEqual(classify_url("https://mega.nz/file/a#k"), ("mega", "ungated")) + self.assertEqual(classify_url("https://sub.archive.org/download/x"), ("archive", "ungated")) + if __name__ == "__main__": unittest.main() diff --git a/tests/update_swarm/test_jobs.py b/tests/update_swarm/test_jobs.py index fb2bb21..71c0e50 100644 --- a/tests/update_swarm/test_jobs.py +++ b/tests/update_swarm/test_jobs.py @@ -13,9 +13,21 @@ class TestJobs(unittest.TestCase): self.assertFalse(jobs["FakeHack"]["watchlist"]) self.assertEqual(jobs["FakeHack"]["note_version"], "1.0.0") self.assertTrue(jobs["DemoOnly"]["watchlist"]) - self.assertFalse(jobs["DemoOnly"]["wanted"]) + self.assertTrue(jobs["DemoOnly"]["wanted"]) self.assertIsNone(jobs["DemoOnly"]["library_path"]) + def test_watchlist_skips_parenthetical_notes(self): + jobs = {j["stem"]: j for j in build_jobs(FIXTURE)} + # `[[Odyssey]] (related)` and `[[Light Platinum]] (GBA complete; DS is separate)` + # appear in Demo Watchlist table rows but are parenthetical notes, not watchlist stems. + self.assertFalse(jobs["Odyssey"]["watchlist"]) + self.assertFalse(jobs["Light Platinum"]["watchlist"]) + + def test_wanted_matches_bold_names(self): + jobs = {j["stem"]: j for j in build_jobs(FIXTURE)} + # `**DemoOnly**` in Wanted.md (no wikilink) should still flag wanted. + self.assertTrue(jobs["DemoOnly"]["wanted"]) + def test_init_run_creates_dirs(self): with tempfile.TemporaryDirectory() as td: run = os.path.join(td, "2026-08-14") diff --git a/tests/update_swarm/test_versions.py b/tests/update_swarm/test_versions.py index ceadd1c..76fcfc2 100644 --- a/tests/update_swarm/test_versions.py +++ b/tests/update_swarm/test_versions.py @@ -20,6 +20,13 @@ class TestCompare(unittest.TestCase): self.assertEqual(compare_versions("Final", "1.2"), "incomparable") self.assertEqual(compare_versions("2026-03-30", "Nightly"), "incomparable") + def test_dates_are_incomparable(self): + self.assertEqual(compare_versions("2026-03-30", "2026-04-01"), "incomparable") + self.assertEqual(compare_versions("2026-03-30", "1.2"), "incomparable") + + def test_hotfix_suffix_is_incomparable(self): + self.assertEqual(compare_versions("1.0.2 Hotfix", "1.0.2"), "incomparable") + def test_equal_non_numeric_after_normalize(self): self.assertEqual(compare_versions("Final", "final"), "eq") From 741e42001da7863df654b06c8f7b8764ace6b4aa Mon Sep 17 00:00:00 2001 From: ginnoir Date: Sat, 31 Oct 2026 03:02:22 -0500 Subject: [PATCH 13/16] =?UTF-8?q?data:=20export=20Pok=C3=A9mon=20Monomyth?= =?UTF-8?q?=20to=20the=20catalog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds Monomyth v1.0 — Team Monomyth's Emerald hack on pokeemerald-expansion, released 2026-10-30 — bringing the catalog to 412 hacks. Placed in the RomM library as roms/gba/Pokemon - Monomyth [Hack].gba, id 13366, SHA-1 verified against the local file after transfer. Also re-exports the 10 update-swarm version bumps already sitting in the vault notes: A Star in the Desert, Acceptance, Eon Guardians, Gadir Deluxe, HGSS Sevii, Hero Legacy, Infinity, Jam Festival, Nebula 1, Nebula 3. These stay undeployed for now — the site sync is spliced against the committed baseline so shipping them remains this branch's decision. The Mythic Silver and Platinum Kaizo notes had regressed to their raw Discord-import state; they were restored from this file's committed contents and so produce no diff here. Co-Authored-By: Claude Opus 5 --- wiki/catalog.json | 134 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 103 insertions(+), 31 deletions(-) diff --git a/wiki/catalog.json b/wiki/catalog.json index f978188..8d5e237 100644 --- a/wiki/catalog.json +++ b/wiki/catalog.json @@ -1,9 +1,9 @@ { - "generated": "2026-08-14", - "count": 411, + "generated": "2026-10-31", + "count": 412, "facets": { "platform": { - "GBA": 205, + "GBA": 206, "PC": 86, "NDS": 52, "GBC": 37, @@ -16,7 +16,7 @@ }, "base": { "FireRed": 101, - "Emerald": 88, + "Emerald": 89, "RPG Maker XP / Pokemon Essentials": 83, "Crystal": 27, "Ruby": 10, @@ -67,13 +67,13 @@ "Ultra Sun": 1 }, "status": { - "Complete": 348, + "Complete": 349, "Beta": 32, "Ongoing": 30, "Complete (beta)": 1 }, "engine": { - "pokeemerald-expansion": 8, + "pokeemerald-expansion": 9, "pokeemerald-expansion (likely)": 6, "CFRU + DPE": 3, "CFRU + DPE (likely)": 2, @@ -85,8 +85,8 @@ "pokeemerald (decomp, likely)": 1 }, "type": { - "New Experience": 179, - "Expansion": 169, + "New Experience": 180, + "Expansion": 170, "Difficulty": 127, "QoL": 97, "Vanilla+": 30, @@ -96,7 +96,7 @@ "Crossover": 2 }, "play_status": { - "Unplayed": 399, + "Unplayed": 400, "Completed": 7, "Backlog": 3, "Dropped": 1, @@ -165,7 +165,7 @@ "title": "Pokémon A Star in the Desert", "platform": "PC", "base": "RPG Maker XP / Pokemon Studio / SDK", - "version": "1.2", + "version": "1.4", "status": "Complete", "generation": "Joiplay/RPGXP", "fakemon": "No", @@ -287,14 +287,14 @@ "title": "Pokémon Acceptance", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "4.0", + "version": "4.2", "status": "Complete", "generation": "Joiplay/RPGXP", "fakemon": "No", "developer": "Tpick", "release_date": "2020", "banner": "https://romhacks-files.ginnoir.com/_meta/Pokemon_Acceptance/IMG_9441-980e54cad6d5e40a.png", - "source": "https://www.pokecommunity.com/threads/pok%C3%A9mon-acceptance.378280/", + "source": "https://eeveeexpo.com/threads/4889/", "library_path": "roms/windows/Pokemon - Acceptance [Hack].zip", "play_status": "Unplayed", "scrape_dir": "Pokemon_Acceptance", @@ -6513,7 +6513,7 @@ "title": "Pokémon Eon Guardians", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "2.0.9", + "version": "2.0.26", "status": "Complete", "generation": "Gen IV", "fakemon": "No", @@ -8112,7 +8112,7 @@ "title": "Pokémon Gadir Deluxe", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": null, + "version": "1.3.1", "status": "Complete", "generation": "Joiplay/RPGXP", "fakemon": "Yes", @@ -8938,7 +8938,7 @@ "title": "Pokémon HGSS Sevii", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "1.1.0", + "version": "1.2.0", "status": "Complete", "generation": "Gen IV", "fakemon": "No", @@ -9255,7 +9255,7 @@ "title": "Pokémon Hero Legacy", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "3.0.7", + "version": "3.0.8", "status": "Complete", "generation": "Gen 1–8", "fakemon": "No", @@ -9263,7 +9263,7 @@ "release_date": "2025", "banner": "https://pokehostel.com/wp-content/uploads/2025/11/Pokemon-Hero-Legacy.png", "source": "https://www.pokecommunity.com/threads/pok%C3%A9mon-hero-legacy-eng-de-now-with-new-game-mode.538518/", - "library_path": "roms/windows/Pokemon - Hero Legacy (Hack).zip", + "library_path": "roms/windows/Pokemon - Hero Legacy [Hack].zip", "play_status": "Unplayed", "generations": [ "Gen I", @@ -10090,13 +10090,14 @@ "title": "Pokémon Infinity", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "3.3.1", + "version": "3.3.4", "status": "Complete", "fakemon": "Yes", + "release_date": "2026-07-07", "banner": "https://www.pokeharbor.com/wp-content/uploads/2025/02/7DRXXBq.gif", "homepage": "https://pokemoninfinity.miraheze.org/wiki/Pokemon_Infinity_Wiki", - "source": "https://p-infinity.fandom.com/wiki/Pokemon_Infinity_Wiki", - "library_path": "roms/windows/Pokemon - Infinity 3.3.1 (Hack).zip", + "source": "https://pokemoninfinity.miraheze.org/wiki/Pokemon_Infinity_Wiki", + "library_path": "roms/windows/Pokemon - Infinity [Hack].zip", "play_status": "Playing", "scrape_dir": "Pokemon_Infinity", "generations": [ @@ -10125,17 +10126,17 @@ "Large custom Pokédex and RPG Maker XP fan-game structure." ], "links": [ - { - "label": "Link", - "url": "https://1fichier.com/?n6v1eej3pipn1ts9sx69&af=2885774" - }, - { - "label": "Link", - "url": "https://p-infinity.fandom.com/wiki/Pokemon_Infinity_Wiki" - }, { "label": "Miraheze wiki", "url": "https://pokemoninfinity.miraheze.org/wiki/Pokemon_Infinity_Wiki" + }, + { + "label": "MediaFire current English build", + "url": "https://www.mediafire.com/file/hp0wuz6vx1abyst/Infinity+3.3.4.zip/file" + }, + { + "label": "Fandom wiki", + "url": "https://p-infinity.fandom.com/wiki/Pokemon_Infinity_Wiki" } ] }, @@ -10418,7 +10419,7 @@ "title": "Pokémon Jam Festival", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "1.0", + "version": "1.4", "status": "Complete", "generation": "Gen III", "fakemon": "Yes", @@ -12459,6 +12460,77 @@ } ] }, + { + "stem": "Monomyth", + "title": "Pokémon Monomyth", + "platform": "GBA", + "base": "Emerald", + "version": "1.0", + "status": "Complete", + "generation": "Athanto", + "fakemon": "Yes", + "developer": "Team Monomyth", + "release_date": "2026-10-30", + "banner": "https://cdn.monomyth.jp/assets/promo.png", + "homepage": "https://monomyth.jp/", + "source": "https://monomyth.jp/download", + "library_path": "roms/gba/Pokemon - Monomyth [Hack].gba", + "play_status": "Unplayed", + "engine": "pokeemerald-expansion", + "generations": [ + "Gen I", + "Gen II", + "Gen III", + "Fakemon" + ], + "type": [ + "New Experience", + "Expansion" + ], + "tags": [ + "hack", + "platform/gba", + "base/emerald", + "status/complete", + "type/newexperience", + "type/expansion" + ], + "summary": "Monomyth is Team Monomyth's original, character-driven Emerald hack, built over more than six years and released complete at version 1.0 on 30 October 2026. It drops the official games entirely in favour of the Athanto Region, a wilderness-heavy setting where the emphasis falls on exploration, storytelling and a deliberately dangerous overworld — the team's own framing is that finding civilisation again before sunset is not always a guarantee. It ships with a dex of over 360 brand new and returning Pokémon, a 200-plus track original soundtrack, and a full suite of Gen III side content, and it is designed to run on real Game Boy Advance and Game Boy Micro hardware rather than emulator-only.", + "notability": "A fan project of unusual scale and finish: six-plus years of development by a credited team of well over a hundred contributors, with its own Pokémon designs, portrait art, animation work from an outside studio, and an original score. The Fakemon design work in particular has drawn attention from players who normally avoid original species in hacks. It is also one of the few hacks of this size that is complete at launch rather than released in episodic betas.", + "story": "An original story set in the Athanto Region, a largely untamed land whose wilds are teeming with dangerous Pokémon. The player is a traveller answering a call to adventure across sprawling environments that hide a great many secrets, with dozens of sidequests layered over the main route and a substantial postgame act.", + "features": [ + "Over 360 brand new and returning Pokémon, with new moves, abilities and battle animations.", + "An entirely new region, Athanto, with sprawling environments, dense secrets and dozens of sidequests.", + "200+ track original soundtrack from a dedicated sound team.", + "Thousands of wild Pokémon coat variations — per-encounter palette variety beyond the usual shiny system.", + "Contest Halls, Trainer Hill and the Battle Frontier all return as side content.", + "Asynchronous multiplayer features plus Link Cable trading, with code-based trading offered as a workaround for the GBA's local-only link.", + "Playable on original Game Boy Advance and Game Boy Micro hardware, not just emulators.", + "Built on pret's pokeemerald decomp with DizzyEggg's Emerald Expansion." + ], + "links": [ + { + "label": "Official site", + "url": "https://monomyth.jp/" + }, + { + "label": "Download and in browser patcher", + "url": "https://monomyth.jp/download" + }, + { + "label": "FAQ and development blog", + "url": "https://monomyth.jp/blog/" + }, + { + "label": "Credits and distribution terms", + "url": "https://monomyth.jp/about" + }, + { + "label": "GBAtemp launch thread", + "url": "https://gbatemp.net/threads/highly-anticipated-rom-hack-pokemon-monomyth-is-now-available.686007/" + } + ] + }, { "stem": "Moon Black 2", "title": "Pokémon Moon Black 2", @@ -13332,7 +13404,7 @@ "title": "Pokémon Nebula 1", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "v1.3.7", + "version": "1.4", "status": "Complete", "generation": "Joiplay/RPGXP", "fakemon": "No", @@ -13480,7 +13552,7 @@ "title": "Pokémon Nebula 3", "platform": "PC", "base": "RPG Maker XP / Pokemon Essentials", - "version": "v1.1.3", + "version": "1.1.5", "status": "Complete", "generation": "Joiplay/RPGXP", "fakemon": "No", From d24720e8e8fadd79fb32250ecfc18a148c7ce05f Mon Sep 17 00:00:00 2001 From: ginnoir Date: Sat, 31 Oct 2026 03:12:35 -0500 Subject: [PATCH 14/16] chore: ignore Python bytecode at any depth The rule only covered scripts/__pycache__/, so the caches for the update_swarm package and its tests (scripts/update_swarm/__pycache__/, tests/update_swarm/__pycache__/) were never ignored and showed up as untracked noise on every status check. Replaced with a depth-independent __pycache__/ plus *.py[cod]. Verified no bytecode was already tracked, so nothing becomes silently ignored. Co-Authored-By: Claude Opus 5 --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d60d06e..e86fcb6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,12 @@ Thumbs.db # scratch; the canonical synthesis lands in the Obsidian vault notes). .scrape/ .scrape_lib/ -scripts/__pycache__/ + +# Python bytecode, at any depth — scripts/, scripts/update_swarm/, tests/update_swarm/. +# The old rule only covered scripts/__pycache__/, so the package + test caches kept +# showing up as untracked noise. +__pycache__/ +*.py[cod] # Per-machine ROM compare/patch scratch (side-by-side emulator runs, patch builds). .compare/ From 0e32a01415083dbd4ff680de86d1af06d2045ac4 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Sat, 31 Oct 2026 03:12:35 -0500 Subject: [PATCH 15/16] docs: add update-swarm design spec and implementation plan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both documents already back the shipped scripts/update_swarm/ package and are cited as the canonical spec from the Obsidian vault's ROM Hacks reference, but they had never been committed — so the repo carried the implementation without the design it was built from. - specs/2026-08-14-romhack-update-swarm-design.md — approved design - plans/2026-08-14-romhack-update-swarm.md — task-by-task implementation plan Checked for credential-shaped strings before committing; clean. Co-Authored-By: Claude Opus 5 --- .../plans/2026-08-14-romhack-update-swarm.md | 1411 +++++++++++++++++ .../2026-08-14-romhack-update-swarm-design.md | 164 ++ 2 files changed, 1575 insertions(+) create mode 100644 docs/superpowers/plans/2026-08-14-romhack-update-swarm.md create mode 100644 docs/superpowers/specs/2026-08-14-romhack-update-swarm-design.md diff --git a/docs/superpowers/plans/2026-08-14-romhack-update-swarm.md b/docs/superpowers/plans/2026-08-14-romhack-update-swarm.md new file mode 100644 index 0000000..45b2a02 --- /dev/null +++ b/docs/superpowers/plans/2026-08-14-romhack-update-swarm.md @@ -0,0 +1,1411 @@ +# ROM Hack Update Swarm Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Build the pipeline-swarm tooling that censuses installed English versions from files, judges them against scouted latest-English records, fetches ungated updates into staging, and lets one librarian place + write back. + +**Architecture:** A stdlib Python package `scripts/update_swarm/` plus `scripts/update-swarm.py`. Census/judge/fetch/librarian are scripts with JSON in `.scrape/update-runs//`. Scouts are Cursor agents that write `scouts/.json` against a schema the CLI validates — this repo does not scrape HackDex. + +**Tech Stack:** Python 3.11+ stdlib (`unittest`, `urllib`, `zipfile`, `hashlib`, `argparse`). Reuse `scripts/enrich_vault.py` (`read_note`, `parse_fm`, `emit_fm`) and `scripts/enrich_web.py` (`set_section`). Existing `build-vault-mocs.py` / `build-wiki-data.py` are invoked, not rewritten. + +## Global Constraints + +- Latest-version source order: official site → HackDex → PokeCommunity → other. Always the latest **English** build. +- Installed version: files first, vault `version` fallback, never launch games. +- Ungated fetch only: GitHub release assets, archive.org, MediaFire, Mega public `#key`. Gated: itch, Drive, Discord, Ko-fi, Mega without key, unknown hosts. +- One librarian. Staging never writes `roms/`. Superseded files are archived, never deleted. +- RomM scans always pass `platform_ids`. Site deploy once per run, after the librarian. +- Watchlist: place only if Complete **and** ungated English; still-demo = report + note bump. +- Version compare: strip `v`/`V` and language tags; if still unordered, bucket `incomparable` — never guess greater-than. +- Summary prose-only; link labels have no parentheses. +- No new third-party Python dependencies. + +## How to use this + +One sentence: implement Tasks 1–8 in order; each task ends with `unittest` green and a commit. Do not run the 411-game pass from this plan — that is a later execution after smoke. + +Spec: `docs/superpowers/specs/2026-08-14-romhack-update-swarm-design.md` + +--- + +## File map + +| Path | Responsibility | +|---|---| +| `scripts/update_swarm/versions.py` | Normalize and compare version strings | +| `scripts/update_swarm/hosts.py` | URL → `(host, gate)` | +| `scripts/update_swarm/schema.py` | Load/dump job, census, scout, verdict JSON | +| `scripts/update_swarm/jobs.py` | Build `jobs.json` from vault notes + watchlist + wanted | +| `scripts/update_swarm/census.py` | Installed version from files / zip / note fallback | +| `scripts/update_swarm/judge.py` | Census + scout + job flags → verdict | +| `scripts/update_swarm/fetch.py` | Ungated download into `staging/` | +| `scripts/update_swarm/librarian.py` | Archive name, place plan, vault patch, RomM argv | +| `scripts/update_swarm/reports.py` | `gated.md` + `watchlist-report.md` | +| `scripts/update_swarm/scout_prompt.md` | Agent prompt + required JSON keys | +| `scripts/update-swarm.py` | CLI: `init`, `census`, `validate-scouts`, `judge`, `fetch`, `place`, `reports`, `deploy` | +| `tests/update_swarm/` | unittest + fixtures | + +--- + +### Task 1: Version normalize and compare + +**Files:** +- Create: `scripts/update_swarm/__init__.py` +- Create: `scripts/update_swarm/versions.py` +- Create: `tests/update_swarm/__init__.py` +- Create: `tests/update_swarm/test_versions.py` + +**Interfaces:** +- Consumes: nothing +- Produces: `normalize_version(s: str) -> str`, `compare_versions(a: str, b: str) -> str` returning exactly one of `lt`, `eq`, `gt`, `incomparable` + +- [ ] **Step 1: Write the failing tests** + +```python +import os, sys, unittest +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.versions import compare_versions, normalize_version + +class TestNormalize(unittest.TestCase): + def test_strips_v_and_language_tag(self): + self.assertEqual(normalize_version("v2.13 (EN)"), "2.13") + self.assertEqual(normalize_version("V1.0.4.2"), "1.0.4.2") + self.assertEqual(normalize_version("2.18 (ES)"), "2.18") + +class TestCompare(unittest.TestCase): + def test_numeric_order(self): + self.assertEqual(compare_versions("1.0.3", "1.0.4.2"), "lt") + self.assertEqual(compare_versions("v1.0.4.2", "1.0.3"), "gt") + self.assertEqual(compare_versions("v2.13 (EN)", "2.13"), "eq") + self.assertEqual(compare_versions("4.1", "4.10"), "lt") + + def test_incomparable_non_numeric(self): + self.assertEqual(compare_versions("Final", "1.2"), "incomparable") + self.assertEqual(compare_versions("2026-03-30", "Nightly"), "incomparable") + + def test_equal_non_numeric_after_normalize(self): + self.assertEqual(compare_versions("Final", "final"), "eq") + +if __name__ == "__main__": + unittest.main() +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_versions -v` + +Expected: `ModuleNotFoundError` or `FAIL` — `update_swarm.versions` is not defined. + +- [ ] **Step 3: Write minimal implementation** + +`scripts/update_swarm/__init__.py` empty. + +`scripts/update_swarm/versions.py`: + +```python +from __future__ import annotations +import re + +_LANG = re.compile(r"\s*\((EN|ES|FR|DE|IT|PT|JP)\)\s*", re.I) +_LEADING_V = re.compile(r"^\s*v", re.I) +_NUMERIC = re.compile(r"^(\d+(?:\.\d+)*)") + +def normalize_version(s: str) -> str: + s = _LANG.sub(" ", s or "") + s = _LEADING_V.sub("", s) + return re.sub(r"\s+", " ", s).strip() + +def _tuple(s: str) -> tuple[int, ...] | None: + m = _NUMERIC.match(normalize_version(s)) + if not m: + return None + return tuple(int(p) for p in m.group(1).split(".")) + +def compare_versions(a: str, b: str) -> str: + na, nb = normalize_version(a), normalize_version(b) + if na.lower() == nb.lower() and na != "": + return "eq" + ta, tb = _tuple(a), _tuple(b) + if ta is None or tb is None: + return "incomparable" + n = max(len(ta), len(tb)) + ta = ta + (0,) * (n - len(ta)) + tb = tb + (0,) * (n - len(tb)) + if ta < tb: + return "lt" + if ta > tb: + return "gt" + return "eq" +``` + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `python -m unittest tests.update_swarm.test_versions -v` + +Expected: `OK` — 3 test cases, all pass (`4.1 < 4.10` because tuples compare `(4,1)` vs `(4,10)`). + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update_swarm/__init__.py scripts/update_swarm/versions.py tests/update_swarm/__init__.py tests/update_swarm/test_versions.py +git commit -m "feat: add version normalize and compare for the update swarm" +``` + +--- + +### Task 2: Host and gate classification + +**Files:** +- Create: `scripts/update_swarm/hosts.py` +- Create: `tests/update_swarm/test_hosts.py` + +**Interfaces:** +- Consumes: nothing +- Produces: `classify_url(url: str) -> tuple[str, str]` → `(host, gate)` where `host` is one of `github`, `archive`, `mediafire`, `mega`, `itch`, `drive`, `discord`, `kofi`, `hackdex`, `pokecommunity`, `other` and `gate` is `ungated` or `gated` + +- [ ] **Step 1: Write the failing tests** + +```python +import os, sys, unittest +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.hosts import classify_url + +class TestClassify(unittest.TestCase): + def test_ungated(self): + self.assertEqual(classify_url("https://github.com/a/b/releases/download/v1/x.gba"), ("github", "ungated")) + self.assertEqual(classify_url("https://archive.org/download/id/file.gba"), ("archive", "ungated")) + self.assertEqual(classify_url("https://www.mediafire.com/file/abc/x.zip/file"), ("mediafire", "ungated")) + self.assertEqual(classify_url("https://mega.nz/file/abc#keyfragment"), ("mega", "ungated")) + + def test_gated(self): + self.assertEqual(classify_url("https://mega.nz/file/abc"), ("mega", "gated")) + self.assertEqual(classify_url("https://foo.itch.io/bar"), ("itch", "gated")) + self.assertEqual(classify_url("https://drive.google.com/file/d/x/view"), ("drive", "gated")) + self.assertEqual(classify_url("https://discord.gg/abc"), ("discord", "gated")) + self.assertEqual(classify_url("https://ko-fi.com/s/abc"), ("kofi", "gated")) + self.assertEqual(classify_url("https://hackdex.app/hack/x"), ("hackdex", "gated")) + self.assertEqual(classify_url("https://www.pokecommunity.com/threads/x.1/"), ("pokecommunity", "gated")) + self.assertEqual(classify_url("https://mystery.example/file.zip"), ("other", "gated")) + +if __name__ == "__main__": + unittest.main() +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_hosts -v` + +Expected: `ModuleNotFoundError: No module named 'update_swarm.hosts'` + +- [ ] **Step 3: Write minimal implementation** + +`scripts/update_swarm/hosts.py`: + +```python +from __future__ import annotations +from urllib.parse import urlparse + +def classify_url(url: str) -> tuple[str, str]: + p = urlparse(url or "") + host = (p.netloc or "").lower().removeprefix("www.") + path = p.path or "" + if host in ("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com"): + if host != "github.com" or "/releases/download/" in path: + return "github", "ungated" + return "github", "gated" + if host.endswith("archive.org"): + return "archive", "ungated" + if host.endswith("mediafire.com"): + return "mediafire", "ungated" + if host.endswith("mega.nz") or host.endswith("mega.co.nz"): + return "mega", "ungated" if p.fragment else "gated" + if host.endswith("itch.io"): + return "itch", "gated" + if host in ("drive.google.com", "docs.google.com"): + return "drive", "gated" + if host in ("discord.com", "discord.gg"): + return "discord", "gated" + if host.endswith("ko-fi.com"): + return "kofi", "gated" + if host.endswith("hackdex.app"): + return "hackdex", "gated" + if host.endswith("pokecommunity.com"): + return "pokecommunity", "gated" + return "other", "gated" +``` + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `python -m unittest tests.update_swarm.test_hosts -v` + +Expected: `OK` + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update_swarm/hosts.py tests/update_swarm/test_hosts.py +git commit -m "feat: classify download URLs as ungated or gated hosts" +``` + +--- + +### Task 3: Schema, run folder, jobs.json + +**Files:** +- Create: `scripts/update_swarm/schema.py` +- Create: `scripts/update_swarm/jobs.py` +- Create: `tests/update_swarm/test_jobs.py` +- Create: `tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/FakeHack.md` +- Create: `tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Demo Watchlist.md` +- Create: `tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Wanted.md` + +**Interfaces:** +- Consumes: `enrich_vault.read_note`, `enrich_vault.parse_fm` (existing) +- Produces: + - `Job` dict keys: `stem`, `title`, `platform`, `library_path`, `homepage`, `source`, `note_version`, `note_status`, `watchlist` (bool), `wanted` (bool) + - `init_run(run_dir: str) -> None` creates `census/`, `scouts/`, `staging/`, `jobs.json` placeholder + - `build_jobs(vault_romhacks_dir: str) -> list[dict]` reads `Hacks/*.md`, flags stems linked from `Demo Watchlist.md` and `Wanted.md` + +- [ ] **Step 1: Write fixtures and failing tests** + +`tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/FakeHack.md`: + +```markdown +--- +title: "Pokémon FakeHack" +platform: GBA +version: "1.0.0" +status: Complete +library_path: "/storage1/Emulation/roms/gba/Pokemon - FakeHack [Hack].gba" +homepage: "https://example.com/fake" +source: "https://www.pokecommunity.com/threads/fake.1/" +--- + +# Pokémon FakeHack +``` + +`tests/update_swarm/fixtures/vault/Pokémon ROM Hacks/Hacks/DemoOnly.md`: + +```markdown +--- +title: "Pokémon DemoOnly" +platform: PC +version: "0.6.2" +status: Beta +--- + +# Pokémon DemoOnly +``` + +`Demo Watchlist.md`: + +```markdown +| Hack | Vault note | +|---|---| +| **DemoOnly** | [[DemoOnly]] | +``` + +`Wanted.md`: + +```markdown +See [[FakeHack]] still gated. +``` + +`tests/update_swarm/test_jobs.py`: + +```python +import 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.jobs import build_jobs, init_run + +FIXTURE = os.path.join(os.path.dirname(__file__), "fixtures", "vault", "Pokémon ROM Hacks") + +class TestJobs(unittest.TestCase): + def test_flags_watchlist_and_wanted(self): + jobs = {j["stem"]: j for j in build_jobs(FIXTURE)} + self.assertIn("FakeHack", jobs) + self.assertTrue(jobs["FakeHack"]["wanted"]) + self.assertFalse(jobs["FakeHack"]["watchlist"]) + self.assertEqual(jobs["FakeHack"]["note_version"], "1.0.0") + self.assertTrue(jobs["DemoOnly"]["watchlist"]) + self.assertFalse(jobs["DemoOnly"]["wanted"]) + self.assertIsNone(jobs["DemoOnly"]["library_path"]) + + def test_init_run_creates_dirs(self): + with tempfile.TemporaryDirectory() as td: + run = os.path.join(td, "2026-08-14") + init_run(run) + for name in ("census", "scouts", "staging"): + self.assertTrue(os.path.isdir(os.path.join(run, name))) + +if __name__ == "__main__": + unittest.main() +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_jobs -v` + +Expected: `ModuleNotFoundError: No module named 'update_swarm.jobs'` + +- [ ] **Step 3: Write minimal implementation** + +`scripts/update_swarm/schema.py`: + +```python +from __future__ import annotations +import json, os + +def read_json(path: str): + with open(path, encoding="utf-8") as f: + return json.load(f) + +def write_json(path: str, obj) -> None: + os.makedirs(os.path.dirname(path) or ".", exist_ok=True) + with open(path, "w", encoding="utf-8") as f: + json.dump(obj, f, indent=2, ensure_ascii=False) + f.write("\n") +``` + +`scripts/update_swarm/jobs.py`: + +```python +from __future__ import annotations +import glob, os, re, sys + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import enrich_vault as E +from update_swarm.schema import write_json + +WIKILINK = re.compile(r"\[\[([^\]|#]+)") + +def _links(path: str) -> set[str]: + if not os.path.isfile(path): + return set() + text = open(path, encoding="utf-8").read() + return {m.strip() for m in WIKILINK.findall(text)} + +def build_jobs(vault_romhacks_dir: str) -> list[dict]: + hacks = os.path.join(vault_romhacks_dir, "Hacks") + watch = _links(os.path.join(vault_romhacks_dir, "Demo Watchlist.md")) + wanted = _links(os.path.join(vault_romhacks_dir, "Wanted.md")) + jobs = [] + for path in sorted(glob.glob(os.path.join(hacks, "*.md"))): + stem = os.path.splitext(os.path.basename(path))[0] + fm_text, _, _ = E.read_note(path) + fm = E.parse_fm(fm_text) + def blank(v): + return None if v in (None, "", "—") else v + jobs.append({ + "stem": stem, + "title": fm.get("title") or stem, + "platform": blank(fm.get("platform")), + "library_path": blank(fm.get("library_path")), + "homepage": blank(fm.get("homepage")), + "source": blank(fm.get("source")), + "note_version": blank(fm.get("version")), + "note_status": blank(fm.get("status")), + "watchlist": stem in watch, + "wanted": stem in wanted, + }) + return jobs + +def init_run(run_dir: str) -> None: + os.makedirs(run_dir, exist_ok=True) + for name in ("census", "scouts", "staging"): + os.makedirs(os.path.join(run_dir, name), exist_ok=True) + jobs_path = os.path.join(run_dir, "jobs.json") + if not os.path.isfile(jobs_path): + write_json(jobs_path, {"run_date": os.path.basename(run_dir), "jobs": []}) +``` + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `python -m unittest tests.update_swarm.test_jobs -v` + +Expected: `OK` + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update_swarm/schema.py scripts/update_swarm/jobs.py tests/update_swarm/test_jobs.py tests/update_swarm/fixtures +git commit -m "feat: build update-swarm jobs.json from vault notes" +``` + +--- + +### Task 4: Census — installed version from files + +**Files:** +- Create: `scripts/update_swarm/census.py` +- Create: `tests/update_swarm/test_census.py` +- Create: `tests/update_swarm/fixtures/library/changelog-game/changelog.txt` +- Create: `tests/update_swarm/fixtures/library/ini-game/Game.ini` +- Create: `tests/update_swarm/fixtures/library/named/Pokemon - Named [Hack][3.3.1].zip` (built in the test) + +**Interfaces:** +- Consumes: `Job` dict from Task 3 (`stem`, `library_path`, `note_version`) +- Produces: `census_job(job: dict, file_path: str | None) -> dict` with keys `stem`, `installed_version`, `source` (`file` | `note` | `unknown`), `evidence`, `sha256`, `size`, `language` + +Priority inside `census_job` (stop at first hit): changelog/readme text → `Game.ini` `Version=` → filename version token → ROM/header `Version x.y` string in first 512 KiB → `job["note_version"]` with `source: note` → `source: unknown`. + +- [ ] **Step 1: Write the failing tests** + +```python +import hashlib, os, sys, tempfile, unittest, zipfile +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.census import census_job + +FIX = os.path.join(os.path.dirname(__file__), "fixtures", "library") + +def job(stem, note_version=None): + return {"stem": stem, "library_path": None, "note_version": note_version} + +class TestCensus(unittest.TestCase): + def test_changelog_current_version_line(self): + rec = census_job(job("C"), os.path.join(FIX, "changelog-game", "dummy.bin")) + self.assertEqual(rec["installed_version"], "3.3.1") + self.assertEqual(rec["source"], "file") + + def test_game_ini_version(self): + rec = census_job(job("I"), os.path.join(FIX, "ini-game", "dummy.bin")) + self.assertEqual(rec["installed_version"], "1.74.1") + self.assertEqual(rec["source"], "file") + + def test_filename_token(self): + rec = census_job(job("N"), os.path.join(FIX, "named", "Pokemon - Named [Hack][3.3.1].zip")) + self.assertEqual(rec["installed_version"], "3.3.1") + + def test_zip_inner_changelog(self): + with tempfile.TemporaryDirectory() as td: + zpath = os.path.join(td, "game.zip") + with zipfile.ZipFile(zpath, "w") as z: + z.writestr("README.txt", "Current Version: 2.13\n") + rec = census_job(job("Z"), zpath) + self.assertEqual(rec["installed_version"], "2.13") + + def test_note_fallback_then_unknown(self): + rec = census_job(job("X", note_version="9.9"), None) + self.assertEqual(rec["source"], "note") + self.assertEqual(rec["installed_version"], "9.9") + rec2 = census_job(job("Y"), None) + self.assertEqual(rec2["source"], "unknown") + self.assertIsNone(rec2["installed_version"]) + +if __name__ == "__main__": + unittest.main() +``` + +Write `tests/update_swarm/fixtures/library/changelog-game/changelog.txt`: + +``` +Current Version: 3.3.1 +``` + +Write `tests/update_swarm/fixtures/library/changelog-game/dummy.bin` as empty file. + +Write `tests/update_swarm/fixtures/library/ini-game/Game.ini`: + +``` +[Game] +Title=Ini Game +Version=1.74.1 +``` + +Write `tests/update_swarm/fixtures/library/ini-game/dummy.bin` empty. + +Write `tests/update_swarm/fixtures/library/named/Pokemon - Named [Hack][3.3.1].zip` as an empty zip (`python -c "import zipfile; zipfile.ZipFile(r'...zip','w').close()"`). + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_census -v` + +Expected: `ModuleNotFoundError: No module named 'update_swarm.census'` + +- [ ] **Step 3: Write minimal implementation** + +`scripts/update_swarm/census.py`: + +```python +from __future__ import annotations +import hashlib, os, re, zipfile + +CHANGELOG_NAMES = {"changelog.txt", "changelog.md", "changes.txt", "readme.txt", "readme.md"} +CURRENT_RE = re.compile(r"(?im)^\s*(?:current\s+version|version)\s*[:\-]\s*(.+?)\s*$") +INI_VER = re.compile(r"(?im)^\s*Version\s*=\s*(.+?)\s*$") +FILE_VER = re.compile(r"\[(?:v)?(\d+(?:\.\d+)*)\]|\((?:v)?(\d+(?:\.\d+)*)\)|v(\d+(?:\.\d+)*)", re.I) +ROM_VER = re.compile(rb"Version\s+[vV]?(\d+(?:\.\d+)*)") + +def _sha_size(path: str) -> tuple[str, int]: + h = hashlib.sha256() + with open(path, "rb") as f: + for chunk in iter(lambda: f.read(1024 * 1024), b""): + h.update(chunk) + return h.hexdigest(), os.path.getsize(path) + +def _from_text(text: str) -> str | None: + m = CURRENT_RE.search(text or "") + return m.group(1).strip() if m else None + +def _sidecar_version(file_path: str) -> str | None: + parent = os.path.dirname(file_path) + for name in os.listdir(parent) if os.path.isdir(parent) else []: + low = name.lower() + if low in CHANGELOG_NAMES or low == "game.ini": + text = open(os.path.join(parent, name), encoding="utf-8", errors="ignore").read() + if low == "game.ini": + m = INI_VER.search(text) + if m: + return m.group(1).strip() + else: + found = _from_text(text) + if found: + return found + return None + +def _zip_version(file_path: str) -> str | None: + try: + with zipfile.ZipFile(file_path) as z: + names = z.namelist() + for n in names: + base = os.path.basename(n).lower() + if base in CHANGELOG_NAMES: + found = _from_text(z.read(n).decode("utf-8", "ignore")) + if found: + return found + for n in names: + if os.path.basename(n).lower() == "game.ini": + m = INI_VER.search(z.read(n).decode("utf-8", "ignore")) + if m: + return m.group(1).strip() + except zipfile.BadZipFile: + return None + return None + +def _filename_version(file_path: str) -> str | None: + m = FILE_VER.search(os.path.basename(file_path)) + if not m: + return None + return next(g for g in m.groups() if g) + +def _rom_version(file_path: str) -> str | None: + with open(file_path, "rb") as f: + blob = f.read(512 * 1024) + m = ROM_VER.search(blob) + return m.group(1).decode() if m else None + +def census_job(job: dict, file_path: str | None) -> dict: + rec = { + "stem": job["stem"], + "installed_version": None, + "source": "unknown", + "evidence": "", + "sha256": None, + "size": None, + "language": None, + } + if file_path and os.path.isfile(file_path): + rec["sha256"], rec["size"] = _sha_size(file_path) + for found, evidence in ( + (_sidecar_version(file_path), "sidecar"), + (_zip_version(file_path), "zip"), + (_filename_version(file_path), "filename"), + (_rom_version(file_path), "rom-bytes"), + ): + if found: + rec["installed_version"] = found + rec["source"] = "file" + rec["evidence"] = evidence + return rec + if job.get("note_version"): + rec["installed_version"] = job["note_version"] + rec["source"] = "note" + rec["evidence"] = "vault" + return rec + rec["evidence"] = "none" + return rec +``` + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `python -m unittest tests.update_swarm.test_census -v` + +Expected: `OK` + +If `test_changelog_current_version_line` fails because sidecar walks the dummy.bin directory: `changelog.txt` must be in the same folder as `dummy.bin` (it is). Sidecar runs before zip/filename. + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update_swarm/census.py tests/update_swarm/test_census.py tests/update_swarm/fixtures/library +git commit -m "feat: census installed hack versions from files with note fallback" +``` + +--- + +### Task 5: Judge + +**Files:** +- Create: `scripts/update_swarm/judge.py` +- Create: `tests/update_swarm/test_judge.py` + +**Interfaces:** +- Consumes: `compare_versions` from Task 1; `Job` (Task 3); census dict (Task 4); scout dict with keys `stem`, `latest_english_version`, `url`, `host`, `gate`, `upstream_status`, `sha256` (optional) +- Produces: `judge_one(job, census, scout) -> dict` with keys `stem`, `bucket`, `reason`, `fetch_url`, `installed_version`, `latest_english_version`, `gate`, `incomparable`, `bump_status`, `remove_from_watchlist` +- `bucket` is exactly one of: `current`, `update`, `gated_queue`, `watchlist_report`, `watchlist_promote`, `incomparable` + +Rules (copy into the test names): + +- No scouted English version → `current` (reason `no-latest`), never fetch. +- `compare_versions` returns `incomparable` → `incomparable`. +- Installed ≥ latest English → `current`. +- Newer + `gate==ungated` + not watchlist → `update`, `fetch_url=scout["url"]`. +- Newer + gated → `gated_queue`; if `upstream_status==Complete` set `bump_status="Complete"`. +- Watchlist + Complete + ungated + newer → `watchlist_promote`, `remove_from_watchlist=True`. +- Watchlist + still demo/newer → `watchlist_report`. +- Census `source==unknown` and scout `sha256` equals census sha256 → `current`. +- Census `source==unknown` and hashes differ or scout hash missing + ungated → `update`. + +- [ ] **Step 1: Write the failing tests** + +```python +import os, sys, unittest +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.judge import judge_one + +def job(**kw): + base = {"stem": "X", "watchlist": False, "wanted": False, "note_version": None} + base.update(kw) + return base + +def census(**kw): + base = {"stem": "X", "installed_version": "1.0", "source": "file", "sha256": "aa"} + base.update(kw) + return base + +def scout(**kw): + base = {"stem": "X", "latest_english_version": "1.1", "url": "https://github.com/a/b/releases/download/v1.1/x.zip", + "host": "github", "gate": "ungated", "upstream_status": "Complete", "sha256": None} + base.update(kw) + return base + +class TestJudge(unittest.TestCase): + def test_update_ungated(self): + v = judge_one(job(), census(), scout()) + self.assertEqual(v["bucket"], "update") + self.assertEqual(v["fetch_url"], scout()["url"]) + + def test_current_when_installed_newer_or_equal(self): + v = judge_one(job(), census(installed_version="1.1"), scout()) + self.assertEqual(v["bucket"], "current") + + def test_gated_queue_and_complete_bump(self): + v = judge_one(job(), census(), scout(gate="gated", url="https://foo.itch.io/x")) + self.assertEqual(v["bucket"], "gated_queue") + self.assertEqual(v["bump_status"], "Complete") + self.assertIsNone(v["fetch_url"]) + + def test_watchlist_promote_and_report(self): + p = judge_one(job(watchlist=True), census(), scout(upstream_status="Complete")) + self.assertEqual(p["bucket"], "watchlist_promote") + self.assertTrue(p["remove_from_watchlist"]) + r = judge_one(job(watchlist=True), census(), scout(upstream_status="Beta")) + self.assertEqual(r["bucket"], "watchlist_report") + self.assertFalse(r["remove_from_watchlist"]) + + def test_watchlist_complete_but_gated_is_queue(self): + v = judge_one(job(watchlist=True), census(), scout(gate="gated", url="https://foo.itch.io/x")) + self.assertEqual(v["bucket"], "gated_queue") + + def test_no_latest_and_incomparable(self): + self.assertEqual(judge_one(job(), census(), scout(latest_english_version=None))["bucket"], "current") + self.assertEqual(judge_one(job(), census(installed_version="Final"), scout())["bucket"], "incomparable") + + def test_unknown_installed_hash_match(self): + v = judge_one(job(), census(installed_version=None, source="unknown", sha256="dead"), + scout(sha256="dead")) + self.assertEqual(v["bucket"], "current") + +if __name__ == "__main__": + unittest.main() +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_judge -v` + +Expected: `ModuleNotFoundError: No module named 'update_swarm.judge'` + +- [ ] **Step 3: Write minimal implementation** + +`scripts/update_swarm/judge.py`: + +```python +from __future__ import annotations +from update_swarm.versions import compare_versions + +def judge_one(job: dict, census: dict, scout: dict) -> dict: + installed = census.get("installed_version") + latest = scout.get("latest_english_version") + gate = scout.get("gate") + url = scout.get("url") + out = { + "stem": job["stem"], + "bucket": "current", + "reason": "", + "fetch_url": None, + "installed_version": installed, + "latest_english_version": latest, + "gate": gate, + "incomparable": False, + "bump_status": None, + "remove_from_watchlist": False, + } + if not latest: + out["reason"] = "no-latest" + return out + if census.get("source") == "unknown" and census.get("sha256") and scout.get("sha256"): + if census["sha256"] == scout["sha256"]: + out["reason"] = "hash-match" + return out + cmp = compare_versions(installed or "", latest) if installed else "lt" + if installed and cmp == "incomparable": + out["bucket"] = "incomparable" + out["incomparable"] = True + out["reason"] = "incomparable" + return out + newer = (not installed) or cmp == "lt" + if not newer: + out["reason"] = "up-to-date" + return out + complete = (scout.get("upstream_status") == "Complete") + ungated = gate == "ungated" and url + if job.get("watchlist"): + if complete and ungated: + out["bucket"] = "watchlist_promote" + out["fetch_url"] = url + out["remove_from_watchlist"] = True + out["reason"] = "watchlist-complete-ungated" + return out + if not ungated: + out["bucket"] = "gated_queue" + out["bump_status"] = "Complete" if complete else None + out["reason"] = "watchlist-gated" + return out + out["bucket"] = "watchlist_report" + out["reason"] = "watchlist-demo" + return out + if ungated: + out["bucket"] = "update" + out["fetch_url"] = url + out["reason"] = "newer-ungated" + return out + out["bucket"] = "gated_queue" + out["bump_status"] = "Complete" if complete else None + out["reason"] = "newer-gated" + return out + +def judge_all(jobs: list[dict], census_by_stem: dict, scouts_by_stem: dict) -> list[dict]: + verdicts = [] + for job in jobs: + stem = job["stem"] + c = census_by_stem.get(stem) or {"stem": stem, "installed_version": job.get("note_version"), "source": "note" if job.get("note_version") else "unknown", "sha256": None} + s = scouts_by_stem.get(stem) or {"stem": stem, "latest_english_version": None, "url": None, "gate": None, "upstream_status": None} + verdicts.append(judge_one(job, c, s)) + return verdicts +``` + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `python -m unittest tests.update_swarm.test_judge -v` + +Expected: `OK` + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update_swarm/judge.py tests/update_swarm/test_judge.py +git commit -m "feat: classify update-swarm verdicts including watchlist and Z-safe compare" +``` + +--- + +### Task 6: Ungated fetch into staging + +**Files:** +- Create: `scripts/update_swarm/fetch.py` +- Create: `tests/update_swarm/test_fetch.py` + +**Interfaces:** +- Consumes: `classify_url` from Task 2 +- Produces: + - `GatedHostError` + - `resolve_mediafire(html: str) -> str | None` + - `download(url: str, dest_path: str, opener=None) -> dict` with `path`, `sha256`, `size`; refuses gated URLs; for MediaFire `/file/` pages, fetches HTML then the `downloadN.mediafire.com` link + - `english_mismatch(archive_path: str, expected_version: str) -> bool` — True when a zip changelog `Current Version` exists and `compare_versions` vs expected is not `eq` + +- [ ] **Step 1: Write the failing tests** + +```python +import os, sys, tempfile, unittest, zipfile +from unittest.mock import patch +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +sys.path.insert(0, os.path.join(ROOT, "scripts")) +from update_swarm.fetch import GatedHostError, download, english_mismatch, resolve_mediafire + +class TestFetch(unittest.TestCase): + def test_mediafire_regex(self): + html = 'dl' + self.assertEqual(resolve_mediafire(html), "https://download123.mediafire.com/abc/file.zip") + + def test_refuses_gated(self): + with tempfile.TemporaryDirectory() as td: + with self.assertRaises(GatedHostError): + download("https://foo.itch.io/x", os.path.join(td, "x.zip")) + + def test_download_writes_bytes(self): + class Resp: + def __init__(self): + self._done = False + def __enter__(self): return self + def __exit__(self, *a): pass + def read(self, n=-1): + if self._done: + return b"" + self._done = True + return b"rombytes" + with tempfile.TemporaryDirectory() as td: + dest = os.path.join(td, "g.gba") + with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()): + rec = download("https://github.com/a/b/releases/download/v1/g.gba", dest) + self.assertTrue(os.path.isfile(dest)) + self.assertEqual(rec["size"], 8) + + def test_changelog_mismatch(self): + with tempfile.TemporaryDirectory() as td: + zpath = os.path.join(td, "g.zip") + with zipfile.ZipFile(zpath, "w") as z: + z.writestr("changelog.txt", "Current Version: 2.16\n") + self.assertTrue(english_mismatch(zpath, "2.13")) + self.assertFalse(english_mismatch(zpath, "v2.16 (ES)")) + +if __name__ == "__main__": + unittest.main() +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_fetch -v` + +Expected: `ModuleNotFoundError: No module named 'update_swarm.fetch'` + +- [ ] **Step 3: Write minimal implementation** + +`scripts/update_swarm/fetch.py`: + +```python +from __future__ import annotations +import hashlib, os, re, urllib.request, zipfile +from update_swarm.census import _from_text, CHANGELOG_NAMES +from update_swarm.hosts import classify_url +from update_swarm.versions import compare_versions + +UA = "Mozilla/5.0 (homelab personal archival)" +MF = re.compile(r"https://download\d+\.mediafire\.com/[^\"'\s<>]+") + +class GatedHostError(ValueError): + pass + +def resolve_mediafire(html: str) -> str | None: + m = MF.search(html or "") + return m.group(0) if m else None + +def _open(url: str, opener=None): + req = urllib.request.Request(url, headers={"User-Agent": UA}) + if opener: + return opener(req) + return urllib.request.urlopen(req) + +def download(url: str, dest_path: str, opener=None) -> dict: + host, gate = classify_url(url) + if gate == "gated": + raise GatedHostError(f"{host} is gated: {url}") + fetch_url = url + if host == "mediafire" and "/file/" in url: + with _open(url, opener) as resp: + html = resp.read().decode("utf-8", "ignore") + direct = resolve_mediafire(html) + if not direct: + raise ValueError("no mediafire direct link") + fetch_url = direct + os.makedirs(os.path.dirname(dest_path) or ".", exist_ok=True) + h = hashlib.sha256() + size = 0 + with _open(fetch_url, opener) as resp, open(dest_path, "wb") as out: + while True: + chunk = resp.read(1024 * 1024) + if not chunk: + break + out.write(chunk) + h.update(chunk) + size += len(chunk) + return {"path": dest_path, "sha256": h.hexdigest(), "size": size, "url": fetch_url} + +def english_mismatch(archive_path: str, expected_version: str) -> bool: + if not zipfile.is_zipfile(archive_path): + return False + with zipfile.ZipFile(archive_path) as z: + for n in z.namelist(): + if os.path.basename(n).lower() in CHANGELOG_NAMES: + found = _from_text(z.read(n).decode("utf-8", "ignore")) + if found and compare_versions(found, expected_version) != "eq": + return True + return False +``` + +Note: `download` uses `resp.read()` without size in the mock — the test mock's `read()` returns all bytes once. Implementation must treat empty `read` as EOF. The mock returns `b"rombytes"` every call and will infinite-loop. + +Fix the test mock to return data once, then empty: + +```python +class Resp: + def __init__(self): + self._done = False + def __enter__(self): return self + def __exit__(self, *a): pass + def read(self, n=-1): + if self._done: + return b"" + self._done = True + return b"rombytes" +``` + +Use that mock in Step 1 (replace the original `Resp`). + +Mega: do **not** implement `megadl` in this task. Fetch CLI in Task 8 shells out to `megadl` only when `host==mega` and `gate==ungated`. Document in `download()`: if `host==mega`, raise `NotImplementedError("use megadl")` so tests for github/mediafire stay pure-Python. + +Add to `download` after classify: + +```python + if host == "mega": + raise NotImplementedError("mega downloads use megadl in the CLI") +``` + +And add a test `test_mega_not_implemented` expecting `NotImplementedError` for a `#key` Mega URL. + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `python -m unittest tests.update_swarm.test_fetch -v` + +Expected: `OK` + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update_swarm/fetch.py tests/update_swarm/test_fetch.py +git commit -m "feat: fetch ungated update-swarm artifacts into staging" +``` + +--- + +### Task 7: Librarian (archive, vault patch, RomM argv) + +**Files:** +- Create: `scripts/update_swarm/librarian.py` +- Create: `tests/update_swarm/test_librarian.py` + +**Interfaces:** +- Consumes: `enrich_vault.read_note` / `parse_fm` / `emit_fm`; `enrich_web.set_section` +- Produces: + - `ROMM_PLATFORM_IDS = {"GBA": 72, "PC": 200}` — `require_platform_id(platform: str) -> int` raises `KeyError` if missing (do not scan) + - `superseded_name(live_basename: str, old_version: str) -> str` inserts the old version before the extension: `Pokemon - Z [Hack].zip` + `v2.16 ES` → `Pokemon - Z [Hack] (v2.16 ES).zip` + - `romm_scan_argv(platform_ids: list[int]) -> list[str]` — docker exec snippet as argv list; **must** include `platform_ids=[...]` and must **not** allow empty `platform_ids` + - `patch_note(path: str, version: str, release_date: str | None, source_url: str | None, history_md: str | None, status: str | None) -> str` returns new note text (caller writes). Updates frontmatter `version` (always quoted via `emit_fm`), optional `release_date`/`source`/`status`, appends `## Version history` via `set_section` if `history_md` is set. Does not touch Summary. + +- [ ] **Step 1: Write the failing tests** + +```python +import 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.librarian import patch_note, require_platform_id, romm_scan_argv, superseded_name + +class TestLibrarian(unittest.TestCase): + def test_superseded_name(self): + self.assertEqual( + superseded_name("Pokemon - Z [Hack].zip", "v2.16 ES"), + "Pokemon - Z [Hack] (v2.16 ES).zip", + ) + + def test_romm_requires_platform_ids(self): + argv = romm_scan_argv([72, 200]) + joined = " ".join(argv) + self.assertIn("platform_ids=[72,200]", joined.replace(" ", "")) + with self.assertRaises(ValueError): + romm_scan_argv([]) + self.assertEqual(require_platform_id("GBA"), 72) + self.assertEqual(require_platform_id("PC"), 200) + with self.assertRaises(KeyError): + require_platform_id("GameCube") + + def test_patch_note_version_and_history(self): + src = ( + "---\n" + 'title: "Pokémon Z"\n' + 'version: "2.17"\n' + "status: Complete\n" + "---\n\n" + "## Summary\n\nKeep me.\n" + ) + with tempfile.TemporaryDirectory() as td: + path = os.path.join(td, "Z.md") + open(path, "w", encoding="utf-8").write(src) + text = patch_note(path, "v2.13 (EN)", "2026-03-30", "https://example.com/z", "- EN 2.13\n", None) + self.assertIn('version: "v2.13 (EN)"', text) + self.assertIn("## Version history", text) + self.assertIn("## Summary\n\nKeep me.", text) + self.assertNotIn("**bold**", text.split("## Summary")[1].split("##")[0]) + +if __name__ == "__main__": + unittest.main() +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_librarian -v` + +Expected: `ModuleNotFoundError: No module named 'update_swarm.librarian'` + +- [ ] **Step 3: Write minimal implementation** + +`scripts/update_swarm/librarian.py`: + +```python +from __future__ import annotations +import os, sys +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import enrich_vault as E +import enrich_web as W + +ROMM_PLATFORM_IDS = {"GBA": 72, "PC": 200, "windows": 200} + +def require_platform_id(platform: str) -> int: + if platform not in ROMM_PLATFORM_IDS: + raise KeyError(f"no RomM platform_id for {platform!r}; add it to ROMM_PLATFORM_IDS") + return ROMM_PLATFORM_IDS[platform] + +def superseded_name(live_basename: str, old_version: str) -> str: + root, ext = os.path.splitext(live_basename) + return f"{root} ({old_version}){ext}" + +def romm_scan_argv(platform_ids: list[int]) -> list[str]: + if not platform_ids: + raise ValueError("platform_ids is required; refusing a full-library walk") + ids = "[" + ", ".join(str(i) for i in platform_ids) + "]" + py = ( + "import asyncio; from endpoints.sockets.scan import scan_platforms; " + "from handler.scan_handler import ScanType; " + f"asyncio.run(scan_platforms(platform_ids={ids}, metadata_sources=[], scan_type=ScanType.QUICK))" + ) + return ["docker", "exec", "-w", "/backend", "romm", "python3", "-c", py] + +def patch_note(path: str, version: str, release_date: str | None, + source_url: str | None, history_md: str | None, status: str | None) -> str: + fm_text, body, _ = E.read_note(path) + fm = E.parse_fm(fm_text) + fm["version"] = version + if release_date: + fm["release_date"] = release_date + if source_url: + fm["source"] = source_url + if status: + fm["status"] = status + if history_md: + body = W.set_section(body, "Version history", history_md.strip()) + return f"---\n{E.emit_fm(fm)}\n---\n{body}" +``` + +`romm_scan_argv` test checks `platform_ids=[72, 200]` with spaces stripped — the implementation emits `platform_ids=[72, 200]` inside the `-c` string (spaces after commas). Strip spaces in the assertion as written (`joined.replace(" ", "")` contains `platform_ids=[72,200]`). **Fix the test** to: + +```python +self.assertIn("platform_ids=[72,200]", joined.replace(" ", "")) +``` + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `python -m unittest tests.update_swarm.test_librarian -v` + +Expected: `OK` + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update_swarm/librarian.py tests/update_swarm/test_librarian.py +git commit -m "feat: librarian helpers for superseded names, note patch, scoped RomM scan" +``` + +--- + +### Task 8: CLI, scout prompt, reports, deploy argv + +**Files:** +- Create: `scripts/update-swarm.py` +- Create: `scripts/update_swarm/cli.py` +- Create: `scripts/update_swarm/reports.py` +- Create: `scripts/update_swarm/scout_prompt.md` +- Create: `tests/update_swarm/test_cli.py` + +**Interfaces:** +- Consumes: all previous modules +- Produces: + - `validate_scout(obj: dict) -> list[str]` missing-key errors; required keys: `stem`, `latest_english_version`, `url`, `host`, `gate`, `language_matrix`, `source_used`, `hackdex`, `upstream_status`, `notes` + - `write_reports(run_dir, verdicts) -> None` writes `gated.md` and `watchlist-report.md` + - `deploy_argv(pokemon_repo: str, site_repo: str) -> list[list[str]]` — three command lists: `python scripts/build-vault-mocs.py`, `python scripts/build-wiki-data.py`, `powershell -File scripts/deploy-site.ps1` (last cwd is `site_repo`) + - CLI subcommands: `init`, `jobs`, `validate-scouts`, `judge`, `reports` (fetch/place/census wire-up may call the functions; `place` is dry-run unless `--apply`) + +- [ ] **Step 1: Write failing tests + scout prompt** + +`scripts/update_swarm/scout_prompt.md` (create in this step so the test can read it): + +```markdown +# 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) +``` + +`tests/update_swarm/test_cli.py`: + +```python +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() +``` + +- [ ] **Step 2: Run tests to verify they fail** + +Run: `python -m unittest tests.update_swarm.test_cli -v` + +Expected: missing `update_swarm.cli` / `update_swarm.reports`. + +- [ ] **Step 3: Write implementation** + +`scripts/update_swarm/reports.py`: + +```python +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) +``` + +`scripts/update_swarm/cli.py`: + +```python +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": + 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": + _load_scouts(args.run) + print("scouts ok") + return 0 + if args.cmd == "judge": + 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": + 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()) +``` + +`scripts/update-swarm.py`: + +```python +#!/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()) +``` + +- [ ] **Step 4: Run all swarm tests** + +Run: + +``` +python -m unittest tests.update_swarm.test_versions tests.update_swarm.test_hosts tests.update_swarm.test_jobs tests.update_swarm.test_census tests.update_swarm.test_judge tests.update_swarm.test_fetch tests.update_swarm.test_librarian tests.update_swarm.test_cli -v +``` + +Expected: all `OK`. + +- [ ] **Step 5: Commit** + +```bash +git add scripts/update-swarm.py scripts/update_swarm/cli.py scripts/update_swarm/reports.py scripts/update_swarm/scout_prompt.md tests/update_swarm/test_cli.py +git commit -m "feat: update-swarm CLI, scout schema, gated and watchlist reports" +``` + +--- + +## Smoke (after Task 8, not a coding task) + +Do not implement new code here. Run a dry `init` + `jobs` against the live vault, pick 8–12 stems per the spec mix (include Z as the multilingual control), dispatch scout agents with `scout_prompt.md`, `validate-scouts`, `judge`, read `verdict.json`. Fetch/place only after that file looks sane. + +--- + +## Self-review (spec coverage) + +| Spec item | Task | +|---|---| +| Pipeline roles / run folder | 3, 8 | +| Census file-then-note, no launching | 4 | +| Source order + English + HackDex blocked | 8 prompt | +| Ungated vs gated hosts | 2, 6 | +| Judge buckets + Z rule + incomparable | 1, 5 | +| Watchlist promote vs report | 5 | +| Staging-only fetch, changelog mismatch | 6 | +| Superseded archive naming, vault patch, scoped RomM | 7 | +| Reports + one deploy | 8 | +| Mega via megadl, not urllib | 6 (`NotImplementedError`) | + +CLI `census` / `fetch` / `place --apply` wiring over SSH to valhalla is intentionally **not** in Tasks 1–8: those are the first execution session after this package exists, using the functions already tested. Do not invent a second census implementation during that session — call `census_job`. diff --git a/docs/superpowers/specs/2026-08-14-romhack-update-swarm-design.md b/docs/superpowers/specs/2026-08-14-romhack-update-swarm-design.md new file mode 100644 index 0000000..8725d6a --- /dev/null +++ b/docs/superpowers/specs/2026-08-14-romhack-update-swarm-design.md @@ -0,0 +1,164 @@ +# ROM Hack / Fangame Update Swarm + +Date: 2026-08-14 +Status: design approved in chat; awaiting spec review before implementation plan +Repo: `C:\Users\MattC\Documents\pokemon` +Vault catalog: `Pokémon ROM Hacks/` (~411 notes) +Library: valhalla `/storage1/Emulation/roms//` via RomM + +## What we decided + +- **Shape:** pipeline swarm. Census and scouts run in parallel; one librarian mutates the library; site deploys once per run. +- **Place:** auto-download and place ungated English updates (GitHub, archive.org, MediaFire, public Mega with `#key`). Queue gated hosts (itch, Drive, Discord, Ko-fi, and anything else that needs a human click). +- **Scope:** whole catalog, including Demo Watchlist and Wanted. +- **Watchlist:** auto-place only if the game is now **Complete** and the English build is ungated. Still-demo updates are a report + note bump, not a download. +- **Writeback:** every successful place updates the vault note, archives the superseded file, runs a scoped RomM scan, then one MOC + `catalog.json` + site deploy at the end of the run. Watchlist reports still bump the note even when nothing is placed. +- **Installed version:** read from the files first. Vault `version` is an acceptable fallback. Do not launch games for screenshots. +- **Latest version:** official site → HackDex → PokeCommunity → other. Always the latest **English** build, even when another language is newer (the Z rule). + +## Pipeline + +``` +Census (parallel, local, script) + → Scouts (parallel, web, LLM agents) + → Judge (one script, no downloads) + → Fetchers (parallel, staging only) + → Librarian (one, serial) + → Site deploy (once per run) +``` + +| Role | Job | +|---|---| +| Census | Installed version from files (notes as backup). Notes also supply homepage/source URLs. | +| Scout | Latest English version from the source list. HackDex is anti-bot: browser or skip, never invent a version. | +| Judge | Bucket each stem. English wins over a newer foreign build. | +| Fetcher | Ungated URLs only, into `staging/`. Never writes `roms/`. | +| Librarian | Archive superseded → place → scoped RomM scan → vault patch. | +| Deploy | `build-vault-mocs.py` + `build-wiki-data.py` + site build/deploy once after the librarian finishes. | + +Watchlist still-demo: Census + Scout + Judge + note bump. No fetch. +Wanted that stays gated: gated queue. No fetch. +Wanted that is Complete and ungated: same as Update (place it). + +## Census — installed version + +Do not launch games. Priority: + +1. Changelog / readme inside the zip or next to the ROM — the “Current Version” line, not the banner (Infinity’s README lied). +2. `Game.ini` / `mkxp.json` / other packaged metadata. +3. Version tokens in the filename (`[3.3.1]`, `v1.0.4.2`). +4. ROM/header strings when they are actually a version, not just the hack name. +5. Vault `version` field — backup, tagged `source: note`. +6. Unknown — still scout. Compare later by hash if needed. + +`Game.exe` (and ROM) hashes confirm a download matches; they are not a version number. + +Notes are never the source of truth for *latest available*. That is Scout’s job. + +## Scout — latest English + +Source order, first hit that names an English build wins: + +1. Game’s own website / GitHub releases / project page +2. HackDex (catalog reference; Cloudflare worker is not scrapable — browser or `hackdex: blocked`) +3. PokeCommunity +4. Other (Eevee Expo, PokeHarbor, Romhacking.net, Reddit, …) + +Record: latest English version, URL, host (`github` | `archive` | `mediafire` | `mega` | `itch` | `drive` | `discord` | `kofi` | `other`), gate (`ungated` | `gated`), language matrix when EN trails, and which source was used. + +Ungated: GitHub release assets, archive.org, MediaFire file pages, Mega public links that include the `#key` fragment (`megadl`). Mega without a key is gated. + +## Judge — buckets + +| Bucket | When | Action | +|---|---|---| +| Current | Installed English ≥ latest English | No file or note change. No “checked” stamp in v1. | +| Update | Newer English exists, ungated | Fetch → librarian places + full writeback | +| Gated queue | Newer English exists, gated host | Link + version on `gated.md`; no fetch. If it is also now Complete, bump the note status anyway. | +| Watchlist report | Still a demo, newer build exists | Note bump + `watchlist-report.md`; stay on watchlist | +| Watchlist promote | Watchlist item is now Complete **and** English is ungated | Same as Update; remove from Demo Watchlist | + +Hard rules: + +- Compare versions after stripping `v`/`V` and language tags (`(EN)`, `(ES)`). If they still do not order (dates, “Final”, “Nightly”), the Judge records `incomparable` and the orchestrator decides — never guess a “greater than.” +- Vault says one version, file is another language, site has a newer foreign and an older English → keep/serve **English**. Archive a newer non-English library copy; do not serve it. +- Scout sources disagree → official site, then HackDex, then PokeCommunity, then other. Store the URL used. +- Installed version unknown → skip fetch only if the scout’s English file is byte-identical to disk; otherwise Update. +- Watchlist Complete but gated → Gated queue + note bump, not promote. Promote requires a successful place. + +## Run folder + +`C:\Users\MattC\Documents\pokemon\.scrape\update-runs\YYYY-MM-DD\` (gitignored with the rest of `.scrape/`). + +| Path | Writer | +|---|---| +| `jobs.json` | Orchestrator — one row per catalog stem | +| `census/*.json` | Census script on valhalla | +| `scouts/*.json` | One file per scout wave | +| `verdict.json` | Judge | +| `staging/` | Fetchers | +| `gated.md` | Judge / librarian | +| `watchlist-report.md` | Judge / librarian | +| `log.md` | Librarian + deploy | + +Waves: + +1. Census script walks every `library_path` on valhalla. Catalog-only stems (no file) skip file steps and use note version (`source: note` or `unknown`). +2. Scout agents in waves of ~12 stems. Each agent receives title, homepage/source URLs, installed version + source tag. Returns the scout record above. No downloads. +3. Judge script fills `verdict.json`. +4. Fetchers pull Update + Watchlist promote ungated URLs into `staging/`. +5. One librarian for the whole batch. +6. One site deploy covering every successful place in the run. + +A scout that cannot beat Cloudflare records `hackdex: blocked` and falls through. It does not invent a version. + +## Librarian + +- Input is `staging/` only. +- Live path keeps the current name (`Pokemon - [Hack].`). +- Old file → `/storage1/igir/romhacks/incoming/_done/_superseded-YYYY-MM-DD/` with the old version in the filename. Never delete. +- PC zips stay vendor-shaped if `launch-pc-hack.ps1` already finds the launcher. Repack only when unplayable (`.rar`, split archives, installer stubs). +- `chmod o+r` after place. +- RomM: always pass `platform_ids`. `roms_ids` alone walks the whole library. QUICK first; HASHES only if `files=0`. Confirm `missing_from_fs=false` and size matches staging. +- Vault: `version`, `release_date`, better `source`/`homepage` if found. Append `## Version history` (language matrix when EN trails). Watchlist promote sets `status: Complete` and removes the stem from Demo Watchlist. Watchlist report bumps `version`/`status` and leaves it listed. +- Site authoring: Summary is prose-only; link labels have no parentheses. +- If `vault_patch` misses a heading on a freshly written note, edit the file on disk. + +MOCs, `wiki/catalog.json`, site copy, and deploy happen **once** after the librarian pass, not per game. + +## Failures + +- Scout blocked/timeout → mark blocked, fall through the source list, no invented version. +- Download hash/size mismatch, or the archive changelog is not the English version we wanted → leave in `staging/`, do not place. +- RomM unhappy → keep superseded + staging, do not patch the note as success. +- Librarian crash → `verdict.json` + `log.md` record `placed` vs `pending`. Resume without re-scouting completed stems. +- Site deploy fail → files + notes may still be right; retry deploy alone. + +## First run (smoke) + +Not the whole catalog. Orchestrator picks 8–12 stems covering: + +- 2–3 library GBA/NDS with a homepage +- 2 PC fangames (one with a changelog in the zip) +- 1 multilingual (Z-class: confirm we keep English) +- 1 watchlist demo (expect report, not place) +- 1 watchlist that might be Complete (promote path) +- 1 gated Wanted (expect queue only) + +If `verdict.json` looks sane, continue in waves of ~40. + +Z itself is a valid multilingual smoke candidate if we want a known control (already on English v2.13 as of 2026-08-14). + +## Out of scope (v1) + +- Launching games or capturing in-game version screenshots +- Parallel librarians +- Per-game site deploys +- Auto-placing gated hosts (itch CSRF, Drive, Discord, Ko-fi) +- Deleting superseded builds +- Stamping “last checked” on Current games +- Inventing versions when every source fails (record `unknown` and skip) + +## Success + +A run is done when `verdict.json` has a bucket for every stem in `jobs.json`, every Update/promote either `placed` or failed-open in `log.md`, `gated.md` and `watchlist-report.md` exist, vault notes match placed files, and (on a full successful librarian pass) the site has been rebuilt once. From 91e4538929bbd11c61bf419bb3dc6cb29864df87 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Sat, 31 Oct 2026 03:27:46 -0500 Subject: [PATCH 16/16] data: add Homestead, Turnabout at Sea and Wishes of Tomorrow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three new GBA entries, all Emerald hacks on pokeemerald-expansion, taking the catalog to 415 hacks (GBA 209). All three placed in the RomM library with SHA-1 verified against the local files: - Homestead 1.0.1 (FaelingDraws, Mudskip & Montblanc) — TARC 3 entry, a battle-free breeder matchmaking puzzle, ~1 hour. RomM id 13367. - Investigations: Turnabout at Sea 1.0.2 (Miriam & Fisham) — TARC 3 entry, Ace Attorney Investigations crossover, five endings. RomM id 13368. - Wishes of Tomorrow 1.2.6 (Flatfoot Labs) — new region, three acts, full Shadow Pokémon system with Shadow Megas. RomM id 13369. Turnabout at Sea is tagged Crossover, which was already used by Omniversal Emerald and Pokemblem but had no section in the vault's Types.md and no entry in this script's INDEX_BYTYPE legend, so [[Types#Crossover]] links resolved to a missing anchor. Added the legend line here; the Types.md section was added in the vault. Co-Authored-By: Claude Opus 5 --- scripts/build-vault-mocs.py | 3 +- wiki/catalog.json | 204 ++++++++++++++++++++++++++++++++++-- 2 files changed, 196 insertions(+), 11 deletions(-) diff --git a/scripts/build-vault-mocs.py b/scripts/build-vault-mocs.py index 20c6628..6d7bb48 100644 --- a/scripts/build-vault-mocs.py +++ b/scripts/build-vault-mocs.py @@ -249,7 +249,8 @@ INDEX_BYTYPE = """## By type - [[Types#New Experience|New Experience]] — New region, story, and/or Pokédex — a fresh adventure, not the official game. - [[Types#Demake|Demake]] — Recreates a later-generation game on older hardware. - [[Types#Roguelite|Roguelite]] — Run-based, randomized, permadeath-flavored structure. -- [[Types#Cosmetic|Cosmetic]] — Visual/audio overhaul (e.g. Moemon sprites, tilesets, music) over an existing game.""" +- [[Types#Cosmetic|Cosmetic]] — Visual/audio overhaul (e.g. Moemon sprites, tilesets, music) over an existing game. +- [[Types#Crossover|Crossover]] — Brings another series' cast, setting, or gameplay loop into a Pokémon base.""" INDEX_PLAYQUEUE = """## Play Queue diff --git a/wiki/catalog.json b/wiki/catalog.json index 8d5e237..531f16a 100644 --- a/wiki/catalog.json +++ b/wiki/catalog.json @@ -1,9 +1,9 @@ { "generated": "2026-10-31", - "count": 412, + "count": 415, "facets": { "platform": { - "GBA": 206, + "GBA": 209, "PC": 86, "NDS": 52, "GBC": 37, @@ -16,7 +16,7 @@ }, "base": { "FireRed": 101, - "Emerald": 89, + "Emerald": 92, "RPG Maker XP / Pokemon Essentials": 83, "Crystal": 27, "Ruby": 10, @@ -67,13 +67,13 @@ "Ultra Sun": 1 }, "status": { - "Complete": 349, + "Complete": 352, "Beta": 32, "Ongoing": 30, "Complete (beta)": 1 }, "engine": { - "pokeemerald-expansion": 9, + "pokeemerald-expansion": 12, "pokeemerald-expansion (likely)": 6, "CFRU + DPE": 3, "CFRU + DPE (likely)": 2, @@ -85,18 +85,18 @@ "pokeemerald (decomp, likely)": 1 }, "type": { - "New Experience": 180, - "Expansion": 170, + "New Experience": 183, + "Expansion": 171, "Difficulty": 127, - "QoL": 97, + "QoL": 98, "Vanilla+": 30, "Cosmetic": 13, "Demake": 11, "Roguelite": 7, - "Crossover": 2 + "Crossover": 3 }, "play_status": { - "Unplayed": 400, + "Unplayed": 403, "Completed": 7, "Backlog": 3, "Dropped": 1, @@ -9619,6 +9619,63 @@ } ] }, + { + "stem": "Homestead", + "title": "Pokémon Homestead", + "platform": "GBA", + "base": "Emerald", + "version": "1.0.1", + "status": "Complete", + "generation": "Gen III", + "fakemon": "No", + "developer": "FaelingDraws, Mudskip & Montblanc", + "release_date": "2026-09-09", + "banner": "https://images.hackdex.app/pokemon-homestead/1788784222108-0.png", + "homepage": "https://www.hackdex.app/hack/pokemon-homestead", + "source": "https://www.hackdex.app/hack/pokemon-homestead", + "library_path": "roms/gba/Pokemon - Homestead [Hack].gba", + "play_status": "Unplayed", + "engine": "pokeemerald-expansion", + "generations": [ + "Gen I", + "Gen II", + "Gen III", + "Gen IV" + ], + "type": [ + "New Experience" + ], + "tags": [ + "hack", + "platform/gba", + "base/emerald", + "status/complete", + "type/newexperience", + "source/hackdex" + ], + "summary": "Homestead is a short, cosy puzzle hack that drops battling entirely and casts you as Millie, a novice Pokémon Breeder working toward a career in Pokémon conservation. Professor Elm sets her a test: read the personality of each Pokémon in her care, listen to what each visiting Trainer actually wants, and pair them up well. There are seven trainers with specific requests and eleven Pokémon to choose between, and the whole thing runs about an hour. It was built as a competition entry for TARC 3 and is deliberately gentle, with no battles and no difficulty curve, just matchmaking and the slice-of-life side of living alongside Pokémon.", + "notability": "A genuinely non-traditional use of the Emerald engine: a complete UI overhaul in a scrapbook visual theme, hand-drawn character and Pokémon portraits with multiple expressions, and an all-custom Gen III adjacent art style. Its stated influences are the quieter corners of the franchise, such as Pokémon Breeder Mini, My Pokémon Ranch and Pokémon Concierge, rather than any mainline game, and it commits to that fully rather than bolting a side mode onto a standard adventure.", + "story": "Millie is a novice Breeder who wants to work in Pokémon conservation. To qualify she has to pass Professor Elm's assessment at the daycare: raise the Pokémon in her care, learn their individual personalities, and match each visiting Trainer with the Pokémon that genuinely suits them.", + "features": [ + "Play as a Pokémon Breeder — there is no battling at all.", + "Matchmake seven unique Trainers, each with specific requests, against eleven available Pokémon.", + "Complete UI overhaul in a scrapbook theme, covering bag, party, save, summary, start and hint menus.", + "Stylised day/night system with bespoke palettes for specific times of day, applied to maps and overworld sprites.", + "All-custom Gen III adjacent art: overworld and indoor tilesets, daycare backgrounds, title and end screens.", + "Hand-drawn character and Pokémon portraits with multiple expressions, in the style of the GBA and DS games.", + "Soundtrack borrowed from other Pokémon titles, including Mystery Dungeon: Explorers of Sky." + ], + "links": [ + { + "label": "Hackdex page and in browser patcher", + "url": "https://www.hackdex.app/hack/pokemon-homestead" + }, + { + "label": "PokeHarbor entry", + "url": "https://www.pokeharbor.com/2026/09/pokemon-homestead/" + } + ] + }, { "stem": "Horror White", "title": "Pokémon Horror White", @@ -10308,6 +10365,63 @@ } ] }, + { + "stem": "Investigations - Turnabout At Sea", + "title": "Pokémon Investigations: Turnabout at Sea", + "platform": "GBA", + "base": "Emerald", + "version": "1.0.2", + "status": "Complete", + "generation": "Gen III", + "fakemon": "No", + "developer": "Miriam & Fisham", + "release_date": "2026-09-10", + "banner": "https://images.hackdex.app/pokemon-investigations-turnabout-at-sea/1789034221035-9.gif", + "homepage": "https://www.hackdex.app/hack/pokemon-investigations-turnabout-at-sea", + "source": "https://www.hackdex.app/hack/pokemon-investigations-turnabout-at-sea", + "library_path": "roms/gba/Pokemon - Investigations - Turnabout At Sea [Hack].gba", + "play_status": "Unplayed", + "engine": "pokeemerald-expansion", + "generations": [ + "Gen I", + "Gen II", + "Gen III" + ], + "type": [ + "New Experience", + "Crossover" + ], + "tags": [ + "hack", + "platform/gba", + "base/emerald", + "status/complete", + "type/newexperience", + "type/crossover", + "source/hackdex" + ], + "summary": "Turnabout at Sea is an Ace Attorney Investigations crossover built on the Emerald engine, and it is a whodunnit first with Pokémon second. You play acclaimed prosecutor Miles Edgeworth, stranded on Florio Island alongside Franziska von Karma, when a bride you have never met offers you both a berth on her family's private boat, the SS Hana. Before long there is a murder. You work multiple crime scenes, gather evidence, turn it into deductions and name the killer, or get it wrong and send an innocent man to jail. It runs roughly 45 minutes a playthrough and was built as an entry for TARC 3.", + "notability": "It transplants a different genre wholesale onto the Emerald engine rather than reskinning a Pokémon adventure: the gameplay loop is Ace Attorney Investigations, the plot is adapted from a Detective Conan story, and the Pokémon are woven into the mystery as investigative tools rather than as the point. It also commits to real consequences, with five distinct endings including ones where you fail to convince anyone or convict the wrong man, which is unusual for a hack of this length.", + "story": "Edgeworth and Franziska von Karma are stranded on Florio Island. A bride neither of them knows offers them passage on her family's private boat, the SS Hana. One night, twelve passengers, two suspects and four key incidents later there has been a murder, and it falls to Edgeworth to prove who did it.", + "features": [ + "A complete, self-contained case: one night, two suspects, twelve passengers and four key incidents to investigate.", + "Pokémon are part of the casework — collect evidence with their help, and win evidence from Trainers you beat in battle.", + "Turn evidence into a case by discovering 31 facts and combining them into deductions.", + "Construct your argument: name a suspect, then answer four questions by presenting evidence. Naming the right suspect is not enough, you have to prove it.", + "Five potential endings, from a correct conviction to failing to convince anyone or jailing an innocent man.", + "Franziska von Karma as a running companion and critic who will not let a wrong accusation go." + ], + "links": [ + { + "label": "Hackdex page and in browser patcher", + "url": "https://www.hackdex.app/hack/pokemon-investigations-turnabout-at-sea" + }, + { + "label": "Source repository", + "url": "https://github.com/tarcxover/pokeinvestigations" + } + ] + }, { "stem": "Ironmon Red Kaizo", "title": "Pokémon Ironmon Red Kaizo", @@ -23731,6 +23845,76 @@ } ] }, + { + "stem": "Wishes of Tomorrow", + "title": "Pokémon Wishes of Tomorrow", + "platform": "GBA", + "base": "Emerald", + "version": "1.2.6", + "status": "Complete", + "generation": "Multi-gen", + "fakemon": "No", + "developer": "Flatfoot Labs", + "release_date": "2026-10-04", + "banner": "https://images.hackdex.app/wishes-of-tomorrow/1791082258731-0.gif", + "homepage": "https://flatfootlabs.com/", + "source": "https://www.hackdex.app/hack/wishes-of-tomorrow", + "library_path": "roms/gba/Pokemon - Wishes of Tomorrow [Hack].gba", + "play_status": "Unplayed", + "engine": "pokeemerald-expansion", + "generations": [ + "Gen I", + "Gen II", + "Gen III", + "Gen IV", + "Gen V", + "Gen VI", + "Gen VII", + "Gen VIII", + "Gen IX" + ], + "type": [ + "New Experience", + "Expansion", + "QoL" + ], + "tags": [ + "hack", + "platform/gba", + "base/emerald", + "status/complete", + "type/newexperience", + "type/expansion", + "type/qol", + "source/hackdex" + ], + "summary": "Wishes of Tomorrow is Flatfoot Labs' original Emerald hack, set in a brand new region across three acts plus a postgame. Jirachi, the Undying Wish, has woken from a thousand-year slumber to grant a single wish, and you are not the only one racing toward it — a masked faction led by a gold Oni means to seize the wish for its own ends. The campaign is content complete and runs roughly four to eight hours, pairing a conventional journey structure with two signature systems: Mega Evolution, and a full Shadow Pokémon mechanic rebuilt in the spirit of Colosseum, including Shadow Megas.", + "notability": "The Shadow Pokémon system is the real draw and is implemented properly rather than gestured at: Shadows hit harder but defend worse and can snap into Hyper Mode, a Snag Machine lets you steal one straight out of a trainer battle, and each snagged Shadow has to be battled once to open it before it can be purified at the Celebi Island shrine. A Shadow Log tracks every Shadow in the game as loose, snagged or purified, and Shadows can themselves be Mega Evolved. It also ships with a built-in randomiser and built-in cheats, which is rare for a story-driven hack.", + "story": "When Jirachi, the Undying Wish, awakens from its thousand-year slumber to grant a single wish, you are not the only one racing toward its promised power. A mysterious faction led by a gold-masked Oni emerges from the shadows, determined to seize Jirachi's wish for their own ambitions. The road runs toward the promised land of Shin-Tokyo, and every wish has a price.", + "features": [ + "A brand new region across three acts plus postgame content, with a quest journal tracking objectives.", + "Shadow Pokémon system: 60 Shadows, Snag Machine theft from trainer battles, Hyper Mode, purification at the Celebi Island shrine, and a Shadow Log tracking each one as loose, snagged or purified.", + "Mega Evolution, including Mega Evolving your Shadow Pokémon, with Mega Stones sold from a curio shop.", + "Built-in randomiser mode and built-in cheats.", + "Four secret boss fights, with animated boss intro cards and character portraits.", + "Decisions during the story affect outcomes.", + "Quality of life throughout: HM field-move menu, Ability Machines, following Pokémon, easy EXP, running shoes, auto-sprint toggle, and a fast-forward mode at 2x or 3x with 8x battle speed." + ], + "links": [ + { + "label": "Hackdex page and in browser patcher", + "url": "https://www.hackdex.app/hack/wishes-of-tomorrow" + }, + { + "label": "Official site with patcher and FAQ", + "url": "https://flatfootlabs.com/" + }, + { + "label": "Game guide", + "url": "https://flatfootlabs.com/guide.html" + } + ] + }, { "stem": "Wob Version", "title": "Pokémon Wob Version",