Datasets:
Upload folder using huggingface_hub
Browse files- README.md +113 -0
- distill_plans_from_games.py +241 -0
- filter_plans.py +58 -0
- plan_games.jsonl +0 -0
- plan_games_clean.jsonl +0 -0
- verify_plans.py +60 -0
README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
task_categories:
|
| 4 |
+
- text-generation
|
| 5 |
+
tags:
|
| 6 |
+
- agentic-sft
|
| 7 |
+
- planning
|
| 8 |
+
- godot
|
| 9 |
+
- phaser
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# GameDoctor plan corpus, distilled from finished games
|
| 13 |
+
|
| 14 |
+
908 plan-stage SFT rows distilled from **finished games** — 832 Godot, 76 web —
|
| 15 |
+
across 17 archetype families. Each row is `brief -> file-level implementation
|
| 16 |
+
plan`.
|
| 17 |
+
|
| 18 |
+
This exists because plan data does not need a recorded agent session. The corpus
|
| 19 |
+
these came from holds ~900 finished games with no trajectory files, which made
|
| 20 |
+
them useless for generation training but perfectly usable here: the brief comes
|
| 21 |
+
from the task definition, and the plan is read off the finished file tree.
|
| 22 |
+
|
| 23 |
+
## Row format
|
| 24 |
+
|
| 25 |
+
Byte-identical in shape to the original 454-row `plan.jsonl`, so the two pool
|
| 26 |
+
cleanly:
|
| 27 |
+
|
| 28 |
+
```json
|
| 29 |
+
{
|
| 30 |
+
"task": "cardgame-arcane-rail",
|
| 31 |
+
"archetype": "cardgame",
|
| 32 |
+
"model": "gpt-5.5",
|
| 33 |
+
"n_chars": 3067,
|
| 34 |
+
"engine": "godot",
|
| 35 |
+
"source": "basegen_unpublished",
|
| 36 |
+
"messages": [
|
| 37 |
+
{"role": "system", "content": "You are a senior game engineer. Given a game brief, produce a file-level implementation plan: which files to MODIFY and which to CREATE, with a one-line reason for each."},
|
| 38 |
+
{"role": "user", "content": "<the game brief>"},
|
| 39 |
+
{"role": "assistant", "content": "Implementation plan before coding:\n\n- **Files to MODIFY**\n - `path`: reason\n- **Files to CREATE**\n - ..."}
|
| 40 |
+
]
|
| 41 |
+
}
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
`engine` and `source` are added for provenance; only `messages` is trained on.
|
| 45 |
+
|
| 46 |
+
## How it was distilled, and what makes it honest
|
| 47 |
+
|
| 48 |
+
Two rules, both about not writing fiction:
|
| 49 |
+
|
| 50 |
+
* **The plan is read off the ACTUAL file tree, never off a narration.** The
|
| 51 |
+
distiller receives the brief plus the real file listing and excerpts of the main
|
| 52 |
+
source files. A game whose README claimed a physics system it does not contain
|
| 53 |
+
would otherwise have that claim copied into the training target.
|
| 54 |
+
* **Only COMPLETE games are distilled.** Godot needs `project.godot` plus at least
|
| 55 |
+
one script or scene; web needs `package.json` plus a `src/` tree. A plan
|
| 56 |
+
distilled from a half-built game is a plan for half-building.
|
| 57 |
+
|
| 58 |
+
The distiller prompt is **engine-specific**. A Phaser prompt pointed at a Godot
|
| 59 |
+
game produces plans full of TypeScript files that do not exist, so Godot runs are
|
| 60 |
+
told the vocabulary is `.tscn` / `.gd` / `project.godot` and web runs are told it
|
| 61 |
+
is `src/*.ts` / `package.json` / `vite`.
|
| 62 |
+
|
| 63 |
+
## Verification
|
| 64 |
+
|
| 65 |
+
Every backticked path in every plan was checked against the real game's file tree:
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
923 games attempted
|
| 69 |
+
922 distilled (1 skipped: incomplete game; 0 API failures; 0 malformed)
|
| 70 |
+
14 dropped (invented paths, or wrong engine vocabulary)
|
| 71 |
+
908 kept
|
| 72 |
+
|
| 73 |
+
23,785 file paths referenced
|
| 74 |
+
0 not found in the game (0.0%)
|
| 75 |
+
0 rows with wrong engine vocabulary
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
The 14 dropped rows include a few false positives from a deliberately strict
|
| 79 |
+
checker — `res://Main.tscn` is valid Godot syntax and `src/` is a directory, not a
|
| 80 |
+
file — but at 1.5% of the corpus, dropping them is cheaper than reasoning about
|
| 81 |
+
which are safe.
|
| 82 |
+
|
| 83 |
+
## Composition
|
| 84 |
+
|
| 85 |
+
| | this corpus | original `plan.jsonl` |
|
| 86 |
+
|---|---|---|
|
| 87 |
+
| rows | 908 | 454 |
|
| 88 |
+
| engines | Godot 832, web 76 | web only |
|
| 89 |
+
| archetype families | **17** | 15 |
|
| 90 |
+
| plan length | 1,310 – 7,228 chars (p50 2,791) | 908 – 3,106 (p50 2,041) |
|
| 91 |
+
|
| 92 |
+
Top families: simulation 127, platformer 90, cardgame 89, horror 81, roguelike 55,
|
| 93 |
+
strategy 54, towerdefense 47, sports 43.
|
| 94 |
+
|
| 95 |
+
**Note the length difference.** Web games carry ~64 files against Godot's ~20–32,
|
| 96 |
+
so their plans run longer than anything in the original corpus. The content is
|
| 97 |
+
verified accurate, so files were not trimmed out to hit a length target — but
|
| 98 |
+
pooling the two shifts the length distribution upward, and that is a property to
|
| 99 |
+
know rather than a defect to hide.
|
| 100 |
+
|
| 101 |
+
## Caveat if you pool this with generation data
|
| 102 |
+
|
| 103 |
+
The original stage-2 mix was 409 gen + 454 plan, and the concern that motivated a
|
| 104 |
+
reweighting experiment was that generation was being outvoted at 47%. Adding these
|
| 105 |
+
908 rows takes plan to **1,362 against 409 gen — generation falls to 23%**. If that
|
| 106 |
+
concern was ever real, this makes it substantially worse, not better. Consider the
|
| 107 |
+
gen:plan ratio deliberately rather than pooling everything by default.
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
|
| 111 |
+
**Pipeline code:** [WenyiWU0111/OpenGame-reproduce · `gamedoctor_sft/`](https://github.com/WenyiWU0111/OpenGame-reproduce/tree/d3-mechanic-runtime/gamedoctor_sft)
|
| 112 |
+
|
| 113 |
+
**Companion repos:** [adapters](https://huggingface.co/dCoder30/gamedoctor-qwen38-adapters) · [training corpora](https://huggingface.co/datasets/dCoder30/gamedoctor-sft-data) · [eval results](https://huggingface.co/datasets/dCoder30/gamedoctor-eval) · [raw trajectories](https://huggingface.co/datasets/dCoder30/gamedoctor-raw-trajectories)
|
distill_plans_from_games.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Distil PLAN training rows from finished games -- Godot and web.
|
| 2 |
+
|
| 3 |
+
A plan row is three messages: a fixed system prompt, the game BRIEF as the user
|
| 4 |
+
turn, and a file-level "Files to MODIFY / CREATE" plan as the assistant target.
|
| 5 |
+
Nothing about that requires a recorded agent session, which is why finished games
|
| 6 |
+
are usable here even though they carry no trajectory.
|
| 7 |
+
|
| 8 |
+
TWO RULES, both borrowed from distill_realized_plan.py, both about not writing
|
| 9 |
+
fiction:
|
| 10 |
+
|
| 11 |
+
* The plan is read off the ACTUAL file tree, never off any narration. A game
|
| 12 |
+
whose README claims a physics system it does not contain would otherwise have
|
| 13 |
+
that claim copied into the training target.
|
| 14 |
+
* Only COMPLETE games are distilled. Godot needs project.godot plus at least
|
| 15 |
+
one script or scene; web needs package.json plus a src/ tree. A plan distilled
|
| 16 |
+
from a half-built game is a plan for half-building.
|
| 17 |
+
|
| 18 |
+
The row's system prompt is byte-identical to the 454 existing plan rows, so the
|
| 19 |
+
corpus stays homogeneous. The prompt sent to the distiller is a separate thing and
|
| 20 |
+
is engine-specific: a Phaser prompt asked about a Godot game produces plans full
|
| 21 |
+
of TypeScript files that do not exist.
|
| 22 |
+
"""
|
| 23 |
+
from __future__ import annotations
|
| 24 |
+
|
| 25 |
+
import argparse
|
| 26 |
+
import json
|
| 27 |
+
import os
|
| 28 |
+
import sys
|
| 29 |
+
import threading
|
| 30 |
+
import urllib.error
|
| 31 |
+
import urllib.request
|
| 32 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 33 |
+
from pathlib import Path
|
| 34 |
+
|
| 35 |
+
ENV = '/home/tiger/OpenGame-Aayush/agent-test/.env'
|
| 36 |
+
TASKS = Path('/tmp/corpus_new/tasks')
|
| 37 |
+
SRC_ROOTS = [
|
| 38 |
+
('godot', Path('/tmp/plan_src/basegen_unpublished')),
|
| 39 |
+
('godot', Path('/tmp/plan_src/_basegames_new')),
|
| 40 |
+
('web', Path('/tmp/plan_src/gen953_opengame_0')),
|
| 41 |
+
('web', Path('/tmp/plan_src/gen953_opengame_1')),
|
| 42 |
+
('web', Path('/tmp/plan_src/gen953_opengame_2')),
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
# byte-identical to the existing 454 rows
|
| 46 |
+
ROW_SYSTEM = ('You are a senior game engineer. Given a game brief, produce a '
|
| 47 |
+
'file-level implementation plan: which files to MODIFY and which '
|
| 48 |
+
'to CREATE, with a one-line reason for each.')
|
| 49 |
+
|
| 50 |
+
DISTILL_PROMPT = """You are given a game brief and the COMPLETE file tree of the finished game that was built from it, with excerpts of its main source files.
|
| 51 |
+
|
| 52 |
+
Write the file-level implementation plan that would have produced this game. Format exactly:
|
| 53 |
+
|
| 54 |
+
Implementation plan before coding:
|
| 55 |
+
|
| 56 |
+
- **Files to MODIFY**
|
| 57 |
+
- `path`: one-line reason
|
| 58 |
+
- **Files to CREATE**
|
| 59 |
+
- `path`: one-line reason
|
| 60 |
+
|
| 61 |
+
Rules:
|
| 62 |
+
- Reference ONLY files that appear in the tree. Never invent a path.
|
| 63 |
+
- {engine_note}
|
| 64 |
+
- One line per file, naming what that file is responsible for.
|
| 65 |
+
- No preamble, no closing commentary. Start with "Implementation plan before coding:".
|
| 66 |
+
- Aim for 900-3000 characters."""
|
| 67 |
+
|
| 68 |
+
ENGINE_NOTE = {
|
| 69 |
+
'godot': ('This is a GODOT project: scenes are .tscn, scripts are .gd, the '
|
| 70 |
+
'project file is project.godot. Do not mention TypeScript, Phaser, '
|
| 71 |
+
'vite or package.json.'),
|
| 72 |
+
'web': ('This is a WEB project built with Phaser and vite: source is '
|
| 73 |
+
'TypeScript under src/, config in package.json and vite.config.js. '
|
| 74 |
+
'Do not mention .gd or .tscn files.'),
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
SKIP_DIRS = {'.git', 'node_modules', '.godot', 'dist', '__pycache__', '.qwen'}
|
| 78 |
+
MAIN_FILES = {
|
| 79 |
+
'godot': ['project.godot', 'Main.tscn', 'scripts/main.gd'],
|
| 80 |
+
'web': ['package.json', 'src/main.ts', 'src/gameConfig.json'],
|
| 81 |
+
}
|
| 82 |
+
MAX_TREE = 120 # files listed
|
| 83 |
+
MAX_EXCERPT = 2500 # chars per main file
|
| 84 |
+
_lock = threading.Lock()
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def load_env():
|
| 88 |
+
for line in open(ENV):
|
| 89 |
+
line = line.strip()
|
| 90 |
+
if line and not line.startswith('#') and '=' in line:
|
| 91 |
+
k, v = line.split('=', 1)
|
| 92 |
+
os.environ.setdefault(k.strip(), v.strip().strip('"').strip("'"))
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def call_model(system: str, user: str, model: str, retries: int = 3) -> str:
|
| 96 |
+
base = os.environ['OPENGAME_REASONING_BASE_URL'].rstrip('/')
|
| 97 |
+
body = json.dumps({
|
| 98 |
+
'model': model,
|
| 99 |
+
'messages': [{'role': 'system', 'content': system},
|
| 100 |
+
{'role': 'user', 'content': user}],
|
| 101 |
+
'max_tokens': 4000,
|
| 102 |
+
}).encode()
|
| 103 |
+
last = ''
|
| 104 |
+
for attempt in range(retries):
|
| 105 |
+
try:
|
| 106 |
+
req = urllib.request.Request(
|
| 107 |
+
base + '/chat/completions', data=body,
|
| 108 |
+
headers={'Content-Type': 'application/json',
|
| 109 |
+
'Authorization': 'Bearer ' + os.environ['OPENGAME_REASONING_API_KEY']})
|
| 110 |
+
r = json.loads(urllib.request.urlopen(req, timeout=300).read())
|
| 111 |
+
txt = (r['choices'][0]['message'].get('content') or '').strip()
|
| 112 |
+
if txt:
|
| 113 |
+
return txt
|
| 114 |
+
last = 'empty response'
|
| 115 |
+
except Exception as e: # noqa: BLE001
|
| 116 |
+
last = f'{type(e).__name__}: {e}'
|
| 117 |
+
import time
|
| 118 |
+
time.sleep(3 * (attempt + 1))
|
| 119 |
+
raise RuntimeError(last)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def game_is_complete(engine: str, d: Path) -> bool:
|
| 123 |
+
if engine == 'godot':
|
| 124 |
+
if not (d / 'project.godot').exists():
|
| 125 |
+
return False
|
| 126 |
+
return any(d.rglob('*.gd')) or any(d.rglob('*.tscn'))
|
| 127 |
+
if not (d / 'package.json').exists():
|
| 128 |
+
return False
|
| 129 |
+
return (d / 'src').is_dir()
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def describe(engine: str, d: Path) -> str:
|
| 133 |
+
files = []
|
| 134 |
+
for p in sorted(d.rglob('*')):
|
| 135 |
+
if p.is_dir() or any(s in p.parts for s in SKIP_DIRS):
|
| 136 |
+
continue
|
| 137 |
+
try:
|
| 138 |
+
files.append(f'{p.relative_to(d)} ({p.stat().st_size}B)')
|
| 139 |
+
except OSError:
|
| 140 |
+
continue
|
| 141 |
+
shown = files[:MAX_TREE]
|
| 142 |
+
out = [f'FILE TREE ({len(files)} files' +
|
| 143 |
+
(f', showing {len(shown)}' if len(files) > len(shown) else '') + '):']
|
| 144 |
+
out += [' ' + f for f in shown]
|
| 145 |
+
for rel in MAIN_FILES[engine]:
|
| 146 |
+
f = d / rel
|
| 147 |
+
if f.exists() and f.is_file():
|
| 148 |
+
try:
|
| 149 |
+
txt = f.read_text(errors='replace')[:MAX_EXCERPT]
|
| 150 |
+
except OSError:
|
| 151 |
+
continue
|
| 152 |
+
out.append(f'\n--- {rel} (first {len(txt)} chars) ---\n{txt}')
|
| 153 |
+
return '\n'.join(out)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def one(engine: str, d: Path, model: str):
|
| 157 |
+
task = d.name
|
| 158 |
+
brief_f = TASKS / task / 'instruction.md'
|
| 159 |
+
if not brief_f.exists():
|
| 160 |
+
return ('no_brief', task, None)
|
| 161 |
+
if not game_is_complete(engine, d):
|
| 162 |
+
return ('incomplete', task, None)
|
| 163 |
+
brief = brief_f.read_text(errors='replace').strip()
|
| 164 |
+
user = (f'GAME BRIEF:\n{brief}\n\n'
|
| 165 |
+
f'{describe(engine, d)}')
|
| 166 |
+
system = DISTILL_PROMPT.format(engine_note=ENGINE_NOTE[engine])
|
| 167 |
+
try:
|
| 168 |
+
plan = call_model(system, user, model)
|
| 169 |
+
except Exception as e: # noqa: BLE001
|
| 170 |
+
return ('failed', task, str(e)[:120])
|
| 171 |
+
if not plan.startswith('Implementation plan'):
|
| 172 |
+
i = plan.find('Implementation plan')
|
| 173 |
+
if i < 0:
|
| 174 |
+
return ('bad_format', task, plan[:80])
|
| 175 |
+
plan = plan[i:]
|
| 176 |
+
row = {
|
| 177 |
+
'task': task,
|
| 178 |
+
'archetype': task.split('-')[0],
|
| 179 |
+
'model': model,
|
| 180 |
+
'n_chars': len(plan),
|
| 181 |
+
'engine': engine,
|
| 182 |
+
'source': d.parent.name,
|
| 183 |
+
'messages': [
|
| 184 |
+
{'role': 'system', 'content': ROW_SYSTEM},
|
| 185 |
+
{'role': 'user', 'content': brief},
|
| 186 |
+
{'role': 'assistant', 'content': plan},
|
| 187 |
+
],
|
| 188 |
+
}
|
| 189 |
+
return ('ok', task, row)
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def main(argv=None) -> int:
|
| 193 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 194 |
+
ap.add_argument('--out', default='/mnt/hdfs/bi_algo_a2f/minghao.fu/'
|
| 195 |
+
'gamedoctor_sft_pipeline/data/plan_games.jsonl')
|
| 196 |
+
ap.add_argument('--limit', type=int, default=0, help='pilot: only N games')
|
| 197 |
+
ap.add_argument('--workers', type=int, default=10)
|
| 198 |
+
ap.add_argument('--model', default='')
|
| 199 |
+
a = ap.parse_args(argv)
|
| 200 |
+
|
| 201 |
+
load_env()
|
| 202 |
+
model = a.model or os.environ.get('OPENGAME_REASONING_MODEL', 'gpt-5.5')
|
| 203 |
+
|
| 204 |
+
jobs = []
|
| 205 |
+
for engine, root in SRC_ROOTS:
|
| 206 |
+
if not root.is_dir():
|
| 207 |
+
print(f' missing source root {root}')
|
| 208 |
+
continue
|
| 209 |
+
for d in sorted(root.iterdir()):
|
| 210 |
+
if d.is_dir():
|
| 211 |
+
jobs.append((engine, d))
|
| 212 |
+
# interleave engines so a pilot sees both
|
| 213 |
+
jobs.sort(key=lambda j: (j[1].name, j[0]))
|
| 214 |
+
if a.limit:
|
| 215 |
+
god = [j for j in jobs if j[0] == 'godot'][:a.limit // 2 or 1]
|
| 216 |
+
web = [j for j in jobs if j[0] == 'web'][:a.limit - len(god)]
|
| 217 |
+
jobs = god + web
|
| 218 |
+
print(f'{len(jobs)} games to distil with {model} ({a.workers} workers)')
|
| 219 |
+
|
| 220 |
+
done = {'ok': 0, 'no_brief': 0, 'incomplete': 0, 'failed': 0, 'bad_format': 0}
|
| 221 |
+
out = open(a.out, 'w')
|
| 222 |
+
with ThreadPoolExecutor(max_workers=a.workers) as ex:
|
| 223 |
+
for status, task, payload in ex.map(lambda j: one(j[0], j[1], model), jobs):
|
| 224 |
+
done[status] += 1
|
| 225 |
+
if status == 'ok':
|
| 226 |
+
with _lock:
|
| 227 |
+
out.write(json.dumps(payload, ensure_ascii=False) + '\n')
|
| 228 |
+
out.flush()
|
| 229 |
+
elif status in ('failed', 'bad_format'):
|
| 230 |
+
print(f' {status}: {task}: {payload}')
|
| 231 |
+
n = sum(done.values())
|
| 232 |
+
if n % 50 == 0:
|
| 233 |
+
print(f' {n}/{len(jobs)} {done}', flush=True)
|
| 234 |
+
out.close()
|
| 235 |
+
print(f'\nDONE {done}')
|
| 236 |
+
print(f'wrote {a.out}')
|
| 237 |
+
return 0 if done['ok'] else 1
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
if __name__ == '__main__':
|
| 241 |
+
sys.exit(main())
|
filter_plans.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Drop any distilled plan that names a file the game does not contain.
|
| 2 |
+
|
| 3 |
+
Full-run validation found 23 bad paths across 24,257 (0.1%) and one row using the
|
| 4 |
+
wrong engine's vocabulary. That is a good rate, but a plan containing even one
|
| 5 |
+
invented path teaches the model to invent paths -- and at 922 rows, discarding the
|
| 6 |
+
handful that fail costs almost nothing. Lowering the gate to let them through
|
| 7 |
+
would be the wrong trade.
|
| 8 |
+
"""
|
| 9 |
+
import json
|
| 10 |
+
import re
|
| 11 |
+
import sys
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
ROOTS = [Path('/tmp/plan_src/basegen_unpublished'), Path('/tmp/plan_src/_basegames_new'),
|
| 15 |
+
Path('/tmp/plan_src/gen953_opengame_0'), Path('/tmp/plan_src/gen953_opengame_1'),
|
| 16 |
+
Path('/tmp/plan_src/gen953_opengame_2')]
|
| 17 |
+
WRONG_VOCAB = {
|
| 18 |
+
'godot': re.compile(r'\.ts\b|package\.json|vite|Phaser', re.I),
|
| 19 |
+
'web': re.compile(r'\.gd\b|\.tscn\b|project\.godot', re.I),
|
| 20 |
+
}
|
| 21 |
+
SRC = sys.argv[1]
|
| 22 |
+
DST = sys.argv[2]
|
| 23 |
+
|
| 24 |
+
kept, dropped = [], []
|
| 25 |
+
for line in open(SRC):
|
| 26 |
+
if not line.strip():
|
| 27 |
+
continue
|
| 28 |
+
r = json.loads(line)
|
| 29 |
+
task, engine = r['task'], r['engine']
|
| 30 |
+
plan = r['messages'][-1]['content']
|
| 31 |
+
d = next((x / task for x in ROOTS if (x / task).is_dir()), None)
|
| 32 |
+
reason = None
|
| 33 |
+
if d is None:
|
| 34 |
+
reason = 'game dir not found'
|
| 35 |
+
else:
|
| 36 |
+
have = {str(p.relative_to(d)) for p in d.rglob('*') if p.is_file()}
|
| 37 |
+
refs = {x.strip().lstrip('./') for x in re.findall(r'`([^`]+)`', plan)
|
| 38 |
+
if '/' in x or '.' in x}
|
| 39 |
+
miss = [x for x in refs
|
| 40 |
+
if x not in have and not any(h.endswith('/' + x) for h in have)]
|
| 41 |
+
if miss:
|
| 42 |
+
reason = f'{len(miss)} invented path(s): {miss[:3]}'
|
| 43 |
+
elif WRONG_VOCAB[engine].search(plan):
|
| 44 |
+
reason = f'wrong engine vocabulary for {engine}'
|
| 45 |
+
if reason:
|
| 46 |
+
dropped.append((task, reason))
|
| 47 |
+
else:
|
| 48 |
+
kept.append(r)
|
| 49 |
+
|
| 50 |
+
with open(DST, 'w') as fh:
|
| 51 |
+
for r in kept:
|
| 52 |
+
fh.write(json.dumps(r, ensure_ascii=False) + '\n')
|
| 53 |
+
|
| 54 |
+
print(f'kept {len(kept)}')
|
| 55 |
+
print(f'dropped {len(dropped)}')
|
| 56 |
+
for t, why in dropped:
|
| 57 |
+
print(f' {t}: {why}')
|
| 58 |
+
print(f'\nwrote {DST}')
|
plan_games.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
plan_games_clean.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
verify_plans.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Verify distilled plans against the real games.
|
| 2 |
+
|
| 3 |
+
The failure mode that would silently poison the corpus is a plan naming files
|
| 4 |
+
that do not exist -- a hallucinated `src/PlayerController.ts` in a Godot project
|
| 5 |
+
trains the model to invent paths. So every backticked path in the plan is checked
|
| 6 |
+
against the actual file tree, and the engine's file vocabulary is checked too.
|
| 7 |
+
"""
|
| 8 |
+
import json
|
| 9 |
+
import re
|
| 10 |
+
import sys
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
ROOTS = [Path('/tmp/plan_src/basegen_unpublished'), Path('/tmp/plan_src/_basegames_new'),
|
| 14 |
+
Path('/tmp/plan_src/gen953_opengame_0'), Path('/tmp/plan_src/gen953_opengame_1'),
|
| 15 |
+
Path('/tmp/plan_src/gen953_opengame_2')]
|
| 16 |
+
WRONG_VOCAB = {
|
| 17 |
+
'godot': re.compile(r'\.ts\b|package\.json|vite|Phaser', re.I),
|
| 18 |
+
'web': re.compile(r'\.gd\b|\.tscn\b|project\.godot', re.I),
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
path = sys.argv[1] if len(sys.argv) > 1 else '/tmp/plan_pilot.jsonl'
|
| 22 |
+
rows = [json.loads(l) for l in open(path) if l.strip()]
|
| 23 |
+
print(f'{len(rows)} rows in {path}\n')
|
| 24 |
+
|
| 25 |
+
tot_paths = tot_missing = vocab_bad = 0
|
| 26 |
+
for r in rows:
|
| 27 |
+
task, engine = r['task'], r['engine']
|
| 28 |
+
d = next((x / task for x in ROOTS if (x / task).is_dir()), None)
|
| 29 |
+
plan = r['messages'][-1]['content']
|
| 30 |
+
refs = set(re.findall(r'`([^`]+)`', plan))
|
| 31 |
+
refs = {x for x in refs if '/' in x or '.' in x}
|
| 32 |
+
missing = []
|
| 33 |
+
if d:
|
| 34 |
+
have = {str(p.relative_to(d)) for p in d.rglob('*') if p.is_file()}
|
| 35 |
+
for ref in refs:
|
| 36 |
+
clean = ref.strip().lstrip('./')
|
| 37 |
+
if clean not in have and not any(h.endswith('/' + clean) or h == clean for h in have):
|
| 38 |
+
missing.append(ref)
|
| 39 |
+
tot_paths += len(refs)
|
| 40 |
+
tot_missing += len(missing)
|
| 41 |
+
bad = WRONG_VOCAB[engine].findall(plan)
|
| 42 |
+
if bad:
|
| 43 |
+
vocab_bad += 1
|
| 44 |
+
flag = '' if not missing and not bad else ' <-- CHECK'
|
| 45 |
+
print(f'{task:<36} {engine:<6} {len(plan):>5}ch paths={len(refs):<3} '
|
| 46 |
+
f'missing={len(missing):<3} wrong-vocab={len(bad)}{flag}')
|
| 47 |
+
if missing[:4]:
|
| 48 |
+
print(f' missing: {missing[:4]}')
|
| 49 |
+
if bad[:4]:
|
| 50 |
+
print(f' wrong vocab: {bad[:4]}')
|
| 51 |
+
|
| 52 |
+
print()
|
| 53 |
+
pct = 100 * tot_missing / max(1, tot_paths)
|
| 54 |
+
print(f'paths referenced: {tot_paths} not found in the game: {tot_missing} ({pct:.1f}%)')
|
| 55 |
+
print(f'rows using the wrong engine vocabulary: {vocab_bad}/{len(rows)}')
|
| 56 |
+
print()
|
| 57 |
+
if pct > 10 or vocab_bad:
|
| 58 |
+
print('QUALITY GATE FAILED - fix the prompt before scaling up')
|
| 59 |
+
sys.exit(1)
|
| 60 |
+
print('QUALITY GATE PASSED')
|