# Proposal: the family's tools in two licence-shaped repositories Status: **proposal** (2026-11-19, the charter session, at Aubrey's request). Local skeletons exist (`/data/emu/emu-tools`, `/data/emu/emu-tools-gpl`); no existing repository changes until the licensing clean-up (wave 2) is finished. The charter is Aubrey's: the charter text at the end is a suggestion for him to accept, change or drop. ## Why The provenance audit and its rewrites (November 2026) kept running into the same shapes: - **The same harness written many times.** A ctypes driver for Mesen2's C API exists in famicom-python, pcengine-python, snes-python and hg51b-python; a C harness linking a Nuked model in ym2612-, ym2413-, sn76489- and megadrive-python; MAME trace and Lua scripts in most boards; one-off referees for WinUAE, NanoBoyAdvance, mGBA, jgenesis, SameBoy, atari800 and ProSystem. Each copy has its own output format, its own bugs, its own pins. - **GPL code inside MIT repositories.** A harness that links or `#include`s a GPL emulator, or declares its C API from GPL headers, is part of that emulator's GPL world. Several sat in MIT trees until the audit moved them out by hand (`m68000-winuae-referee`, `hg51b-mesen-harness`), and more are owed (Mesen2 harnesses, Nuked harnesses, `nba_driver`, `jgenesis_harness`). - **We avoided improving the closed boxes.** Under "run, never read", we could not patch an emulator to expose the trace we needed, so harnesses grew hacks (internal-node taps, stub layouts, scraping debugger text) that later turned into audit findings. - **Our own tools are scattered too.** Lockstep runners, the fault seeder, the three-layout A/B, the provenance checker, ROM census and fetch-and-pin scripts are copied between repositories and drift. ## The proposal Two repositories, grouped by licence compatibility, not one per licence: | Repository | Licence | Holds | | --- | --- | --- | | `emu-tools` | MIT | Our own tools: lockstep and gate runners, fault seeding, layout-aware A/B, provenance checking, ROM census, pin and fetch helpers, readers and writers for the shared output formats, and **the contract** (the formats every tool speaks). Anything MIT or permissive that drives a permissive emulator (MAME's BSD-3 parts run as programs, ares, SameBoy, Musashi). | | `emu-tools-gpl` | GPL-3.0-or-later | Every tool that links, includes, patches or declares the API of a GPL, LGPL or MPL program: Mesen2, Nuked-OPN2/OPLL/PSG/MD, WinUAE, NanoBoyAdvance, mGBA, jgenesis, snes_spc, BlastEm, openMSX, Stella, atari800, ProSystem, Mednafen. Here we may read, patch and improve those programs freely, keep our patches, and make good tools that others can use. | What GPL-3.0-or-later can hold: GPL-2.0-or-later, GPL-3.0, LGPL-2.1+/3.0, MPL-2.0 (through its secondary-licence clause, unless a file says otherwise), and anything permissive. What it cannot: **GPL-2.0-only** code (incompatible with GPL-3; such a tool gets its own small repository if we ever need one), **AGPL** (would change the repository's terms; own repository if ever needed), **non-commercial** code (Genesis Plus GX, PicoDrive: never in any repository, run as shipped binaries only), and **anything by authors who object to AI use** (furrtek: not at all). ## When an upstream must be patched The rule underneath: **whatever links or contains upstream code takes the upstream's licence; everything else stays on the other side of a process boundary.** The boundary is not only between MIT and GPL: it also keeps GPL-2.0-only and GPL-3.0 code from ever being combined. In order of preference: 1. **No patch.** Use what the program already offers: its public C API, its scripting (Lua, debugger commands), a GDB stub, a libretro core driven through the libretro API, a trace logger. 2. **Upstream the hook.** Offer the project a small, generic trace or headless hook, so they carry it and everyone gains. Only where the project accepts AI-assisted contributions (Mesen2 and NESdev projects do not; MAME needs the model and version named): see the family's notes on upstream AI policies. 3. **Patch files, not forks**, for GPL-2.0-or-later, GPL-3.0, LGPL and MPL upstreams: small named patches in `emu-tools-gpl/tools//patches/`, applied by `build.sh` to the pinned commit. 4. **A fork** only when the patches grow large or must live long. The fork keeps the upstream's licence, and the tool pins the fork's commit. 5. **GPL-2.0-only upstreams** (and AGPL, if ever): patches and any fork live **outside** `emu-tools-gpl`, in a repository under the upstream's exact licence (a fork of that project, or a small `emu-tools-gpl2` if several gather). Patch files carry upstream context lines, so they are copies of upstream code and must sit under its licence. The patch makes the patched program itself speak the contract (a flag that writes the manifest and traces), so it runs as a separate executable and no GPL-3 or MIT code is ever linked with it. Either way, the patch should make the upstream program speak the contract directly, so the harness logic around it is as small as possible. If a patched binary is ever shared, its complete corresponding source goes with it under the upstream's licence. ## The contract (lives in `emu-tools/docs/contract.md`, MIT) 1. **A process boundary.** MIT code runs a GPL tool as a separate program (command line, files, pipes) and never imports, links or includes it. The tool's command line and output formats are specified in MIT documents written without GPL code, so the MIT side only ever handles data. 2. **Shared formats, versioned.** A run manifest (tool, tool version, emulator, its pinned commit and licence, arguments, ROM SHA-1s, host); bus and instruction traces as JSON Lines (or a documented binary twin for volume); state snapshots; frames as PNG; audio as WAV; pin logs. Every output carries its manifest, so a consumer can tag a value `OBSERVED ( @ , via )` automatically. 3. **Pinned and reproducible.** Each tool pins its emulator by commit, fetches it with a script, keeps our patches as patch files, and builds with one command. ROMs, BIOS and firmware only through environment variables (`NO_INTRO_DIR`, `MAME_ROMPATH`, named per-console variables), never committed. 4. **The wall.** Work in `emu-tools-gpl` reads GPL source; that is its purpose. The same session or agent does not then write MIT emulator code: briefs for GPL-tool work are separate, and what crosses the wall is only the tool's outputs and the MIT-written format documents. MIT projects never quote the tools' code or patches. (This is the clean-room discipline the restarts needed, made structural.) 5. **Evidence stays honest.** A tool's output is a closed-box measurement (OBSERVED), never a hardware fact, however good the tool (the 2026-11-19 ruling on "verified on hardware" applies). Hardware tools (probe carts, capture parsers) live in `emu-tools` and their outputs are MEASURED. 6. **Notices travel.** Each GPL tool directory names the upstream, its licence and commit; if the tool is shared, its complete corresponding source (our code, patches, the pinned upstream) goes with it. 7. **A quality bar.** Each tool: a README (what it measures, how to build, its command line, its outputs), a smoke test, a changelog line per change. Tools are versioned so consumers can pin them. ## Inventory (what would move, later) | Group | Today | Target | | --- | --- | --- | | Mesen2 runners | famicom-, pcengine-, snes-python `scripts/mesen_run.py`; `hg51b-mesen-harness` | `emu-tools-gpl/tools/mesen2` (one runner, per-console adapters, patched trace hooks) | | Nuked chip harnesses | ym2612-, ym2413-, sn76489-python `validation/nuked_harness.c`; megadrive-python `nuked_md_headless.c` | `emu-tools-gpl/tools/nuked` (one harness family, pins only) | | CPU referees | `m68000-winuae-referee`; gba-python `nba_driver`, `mgba_driver.c`; sh2-python `jgenesis_harness` | `emu-tools-gpl/tools/{winuae,nba,mgba,jgenesis}` | | Other GPL runners | a5200 `atari800_run.py`, a7800 `prosystem_run.py`, s-dsp referee (snes_spc), BlastEm/openMSX/Stella drivers | `emu-tools-gpl/tools/...` | | Permissive runners | MAME trace and Lua scripts, gameboy `sameboy_run.py`, Musashi referee | `emu-tools/tools/{mame,sameboy,musashi}` | | Our own tools | `scripts/lockstep.py`, fault seeders, `scripts/ab.sh`/`ab.py`, `provenance_check.py`, census and fetch scripts | `emu-tools/tools/...`, consumed by pin | ## Order of work (after wave 2) 1. Accept or change this proposal; settle the names. 2. Write the formats (`contract.md` is a first draft) and the readers in `emu-tools`. 3. Move the two loose GPL tools in (`m68000-winuae-referee`, `hg51b-mesen-harness`), then the Mesen2 runners as one tool, then the Nuked harnesses; each move leaves the consumer pointing at the tool by pin or environment variable, with its gates re-run. 4. Move our own shared scripts into `emu-tools` as consumers next touch them. 5. Publish when presentable (the family's rule); the GPL repository's quality bar is what makes it worth sharing. ## Suggested charter text (for Aubrey) > **Tools.** The family's tools live in two repositories: `emu-tools` (MIT: our own tools and > the output contract) and `emu-tools-gpl` (GPL-3.0-or-later: every tool that links, > includes, patches or declares the API of a copyleft program). Emulator repositories run > tools as separate programs and consume only their outputs, in the contract's formats. > GPL-tool work is briefed separately from emulator work; nothing crosses from the GPL > repository into an MIT one except outputs and the MIT-written format documents.