agent-manifesto-kit 1.8.2 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -2
- package/collection/bundles/game-dev/README.md +69 -0
- package/collection/bundles/game-dev/RECOMMENDS.md +24 -0
- package/collection/bundles/game-dev/agents/game-code-reviewer.md +36 -0
- package/collection/bundles/game-dev/agents/game-image-generator.md +34 -0
- package/collection/bundles/game-dev/agents/game-visual-reviewer.md +34 -0
- package/collection/bundles/game-dev/skills/game-code/SKILL.md +54 -0
- package/collection/bundles/game-dev/skills/game-code/agents/openai.yaml +4 -0
- package/collection/bundles/game-dev/skills/game-code/references/engine-godot.md +45 -0
- package/collection/bundles/game-dev/skills/game-code/references/engine-threejs.md +47 -0
- package/collection/bundles/game-dev/skills/game-delegation/SKILL.md +58 -0
- package/collection/bundles/game-dev/skills/game-delegation/agents/openai.yaml +4 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/SKILL.md +103 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/agents/openai.yaml +4 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/assets/agents-section.md +20 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/references/config.md +46 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/audit.py +202 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/balance.py +197 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/check.py +62 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/delegate.py +350 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/gamedev_config.py +163 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/install.py +172 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/instruction_size.py +75 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/prompts/code_review.md +19 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/prompts/image.md +5 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/prompts/visual_review.md +13 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/pyramid.py +84 -0
- package/collection/bundles/game-dev/skills/game-dev-setup/scripts/test_game_dev.py +309 -0
- package/collection/bundles/game-dev/skills/game-planning/SKILL.md +80 -0
- package/collection/bundles/game-dev/skills/game-planning/agents/openai.yaml +4 -0
- package/collection/bundles/game-dev/skills/game-testing/SKILL.md +58 -0
- package/collection/bundles/game-dev/skills/game-testing/agents/openai.yaml +4 -0
- package/collection/bundles/kit-adopt/conventions/recommended-companions.md +1 -1
- package/collection/skills/astro-preview/SKILL.md +97 -41
- package/collection/skills/astro-preview/references/manifest.md +42 -0
- package/collection/skills/astro-preview/scripts/portal.py +686 -0
- package/collection/skills/astro-preview/scripts/test_portal.py +576 -0
- package/collection/skills/concept-asset-builder/SKILL.md +14 -5
- package/collection/skills/concept-asset-builder/assets/templates/agent_brief.md +5 -2
- package/collection/skills/concept-asset-builder/references/field-lessons.md +9 -0
- package/collection/skills/concept-asset-builder/scripts/blender/render_views.py +4 -2
- package/collection/skills/concept-asset-builder/scripts/codex_review.sh +4 -1
- package/collection/skills/concept-asset-builder/scripts/godot/capture.gd +5 -2
- package/collection/skills/concept-asset-builder/scripts/init_workspace.sh +1 -1
- package/collection/skills/concept-asset-builder/scripts/measure_silhouette.py +18 -4
- package/collection/skills/concept-asset-builder/scripts/overlay_masks.py +25 -0
- package/collection/skills/concept-asset-builder/scripts/test_tools.py +44 -0
- package/collection/skills/concept-asset-builder/scripts/threejs/studio.js +4 -2
- package/collection/skills/concept-asset-builder/scripts/wear_stats.py +35 -1
- package/collection/skills/mixamo/SKILL.md +109 -0
- package/collection/skills/mixamo/agents/openai.yaml +4 -0
- package/collection/skills/mixamo/scripts/mixamo.py +264 -0
- package/collection/skills/mixamo/scripts/test_mixamo.py +108 -0
- package/collection/skills/sfx-creator/SKILL.md +160 -0
- package/collection/skills/sfx-creator/agents/openai.yaml +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"""Delegate image generation and independent reviews to another agent CLI.
|
|
2
|
+
|
|
3
|
+
Models, effort and the generated-art folder come from game-dev.json (`models`, `paths`);
|
|
4
|
+
nothing is pinned here. Image generation always runs in Codex. A review runs in the agent
|
|
5
|
+
that is NOT running this script (Codex reviews a Claude session, Claude reviews a Codex
|
|
6
|
+
session), so a change is never accepted by the context that made it.
|
|
7
|
+
|
|
8
|
+
python3 tools/game-dev/delegate.py check
|
|
9
|
+
python3 tools/game-dev/delegate.py image --out assets/generated/hero.png --prompt p.md [--ref concept.png]
|
|
10
|
+
python3 tools/game-dev/delegate.py review code --brief brief.md [--attach diff.patch] [--reviewer auto|codex|claude]
|
|
11
|
+
python3 tools/game-dev/delegate.py review visual --brief brief.md --attach shot.png [--attach concept.png]
|
|
12
|
+
|
|
13
|
+
Add --dry-run to print the command instead of running it. Exit codes: 0 ok, 2 delegation error.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import datetime
|
|
18
|
+
import hashlib
|
|
19
|
+
import io
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import shutil
|
|
24
|
+
import signal
|
|
25
|
+
import subprocess
|
|
26
|
+
import sys
|
|
27
|
+
import tempfile
|
|
28
|
+
import uuid
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
|
|
31
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
32
|
+
import gamedev_config # noqa: E402
|
|
33
|
+
|
|
34
|
+
PROMPTS = Path(__file__).resolve().parent / "prompts"
|
|
35
|
+
IMAGE_SUFFIXES = {".png", ".jpg", ".jpeg", ".webp", ".gif"}
|
|
36
|
+
PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"
|
|
37
|
+
# Plugins and apps bring their own MCP servers, which a config override cannot switch off;
|
|
38
|
+
# notify starts an external program after each turn.
|
|
39
|
+
CODEX_LOCKDOWN = ("--disable", "plugins", "--disable", "apps", "--disable", "computer_use",
|
|
40
|
+
"--disable", "browser_use", "-c", "notify=[]")
|
|
41
|
+
# Per-session identifiers only: provider configuration (CODEX_HOME, CLAUDE_CONFIG_DIR, ...) must reach the child.
|
|
42
|
+
SESSION_MARKERS = {
|
|
43
|
+
"AI_AGENT", "CLAUDECODE", "CLAUDE_PID", "CLAUDE_CODE_ENTRYPOINT", "CLAUDE_CODE_SESSION_ID",
|
|
44
|
+
"CLAUDE_CODE_HOST_SESSION_ID", "CLAUDE_CODE_CHILD_SESSION", "CLAUDE_CODE_SESSION_ATTENDED",
|
|
45
|
+
"CLAUDE_CODE_MESSAGING_SOCKET", "CLAUDE_CODE_MESSAGING_TOKEN", "CODEX_THREAD_ID", "CODEX_SESSION_ID",
|
|
46
|
+
"CODEX_TOOL_CALL_ID", "CODEX_SANDBOX", "CODEX_SANDBOX_NETWORK_DISABLED", "CODEX_CI",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
SANDBOX_HINT = (" If this ran inside the Codex sandbox, rerun the same command with escalated permissions "
|
|
51
|
+
"so the Claude CLI can reach its API.")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class DelegationError(RuntimeError):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def caller(env):
|
|
59
|
+
"""The agent running this script: GAME_DEV_AGENT wins over CLI markers."""
|
|
60
|
+
marker = env.get("GAME_DEV_AGENT", "").strip().lower()
|
|
61
|
+
if marker in ("claude", "codex"):
|
|
62
|
+
return marker
|
|
63
|
+
if env.get("CLAUDECODE"):
|
|
64
|
+
return "claude"
|
|
65
|
+
if env.get("CODEX_THREAD_ID") or env.get("CODEX_SESSION_ID"):
|
|
66
|
+
return "codex"
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def review_spec(cfg, kind, requested, env, which=shutil.which):
|
|
71
|
+
"""Pick the reviewer's tool, model and effort; never the agent that runs this script."""
|
|
72
|
+
models = cfg["models"]
|
|
73
|
+
preferred = models[f"{kind}_review"]
|
|
74
|
+
claude = models["claude_review"]
|
|
75
|
+
current = caller(env)
|
|
76
|
+
tool = requested
|
|
77
|
+
if tool == "auto":
|
|
78
|
+
tool = {"codex": "claude", "claude": "codex"}.get(current, preferred["tool"])
|
|
79
|
+
if tool == current:
|
|
80
|
+
raise DelegationError(f"a {current} session must be reviewed by the other agent")
|
|
81
|
+
if tool == "claude":
|
|
82
|
+
spec = preferred if preferred["tool"] == "claude" else claude
|
|
83
|
+
elif preferred["tool"] == "codex":
|
|
84
|
+
spec = preferred
|
|
85
|
+
else:
|
|
86
|
+
raise DelegationError(f"models.{kind}_review is not a codex role; set its tool to codex")
|
|
87
|
+
if which(spec["tool"]) is None:
|
|
88
|
+
raise DelegationError(f"{spec['tool']} CLI is not on PATH; install it or pass --reviewer")
|
|
89
|
+
return dict(spec)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def child_env(env, tool):
|
|
93
|
+
clean = {k: v for k, v in env.items() if k not in SESSION_MARKERS}
|
|
94
|
+
clean["GAME_DEV_AGENT"] = tool
|
|
95
|
+
return clean
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def resolved(paths):
|
|
99
|
+
files = [Path(p).resolve() for p in paths]
|
|
100
|
+
for file in files:
|
|
101
|
+
if not file.is_file():
|
|
102
|
+
raise DelegationError(f"missing file: {file}")
|
|
103
|
+
return files
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def read_text(path):
|
|
107
|
+
try:
|
|
108
|
+
return Path(path).read_text(encoding="utf-8")
|
|
109
|
+
except OSError as error:
|
|
110
|
+
raise DelegationError(f"cannot read {path}: {error}") from error
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def role_prompt(name):
|
|
114
|
+
path = PROMPTS / f"{name}.md"
|
|
115
|
+
return read_text(path).rstrip() if path.is_file() else ""
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def review_prompt(kind, root, brief, attachments):
|
|
119
|
+
listed = "\n".join(f"- {p}" for p in attachments) or "- none"
|
|
120
|
+
return (f"{role_prompt(kind + '_review')}\n\n# Review request\n\nRepository root: {root}\n"
|
|
121
|
+
"You review in a fresh context. Stay read-only: do not edit, create, stage or commit files.\n"
|
|
122
|
+
f"Attached files (open them; images must be viewed):\n{listed}\n\n{brief.strip()}\n")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def codex_command(root, spec, output, images, sandbox, overrides=()):
|
|
126
|
+
command = ["codex", "exec", "--model", spec["model"], *overrides,
|
|
127
|
+
"-c", f"model_reasoning_effort=\"{spec['effort']}\"", "--sandbox", sandbox,
|
|
128
|
+
"--disable", "hooks", "--skip-git-repo-check", "--ephemeral", "--cd", str(root),
|
|
129
|
+
"--output-last-message", str(output)]
|
|
130
|
+
for image in images:
|
|
131
|
+
command += ["--image", str(image)]
|
|
132
|
+
return [*command, "-"] # the prompt always goes on stdin: an open terminal stdin makes exec wait
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def claude_command(root, spec, attachments, settings):
|
|
136
|
+
command = ["claude", "-p", "--model", spec["model"], "--effort", spec["effort"],
|
|
137
|
+
"--tools", "Read,Glob,Grep", "--strict-mcp-config", "--settings", str(settings),
|
|
138
|
+
"--no-session-persistence", "--output-format", "json"]
|
|
139
|
+
for folder in sorted({str(p.parent) for p in attachments if not p.is_relative_to(root)}):
|
|
140
|
+
command += ["--add-dir", folder]
|
|
141
|
+
return command
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def codex_mcp_off(root, env):
|
|
145
|
+
"""Read-only reviews fail closed: MCP tools are not bound by the sandbox."""
|
|
146
|
+
def listing(overrides):
|
|
147
|
+
result = subprocess.run(["codex", *overrides, "mcp", "list", "--json"], capture_output=True, text=True,
|
|
148
|
+
encoding="utf-8", errors="replace", env=env, cwd=root, stdin=subprocess.DEVNULL)
|
|
149
|
+
if result.returncode:
|
|
150
|
+
raise DelegationError(f"cannot list Codex MCP servers: {result.stderr[-500:]}")
|
|
151
|
+
try:
|
|
152
|
+
return {s["name"]: bool(s["enabled"]) for s in json.loads(result.stdout or "[]")}
|
|
153
|
+
except (json.JSONDecodeError, KeyError, TypeError) as error:
|
|
154
|
+
raise DelegationError("cannot parse the Codex MCP server list") from error
|
|
155
|
+
|
|
156
|
+
overrides = list(CODEX_LOCKDOWN)
|
|
157
|
+
for name, enabled in listing(overrides).items():
|
|
158
|
+
if enabled:
|
|
159
|
+
if not re.fullmatch(r"[A-Za-z0-9_-]+", name):
|
|
160
|
+
raise DelegationError(f"cannot disable the Codex MCP server {name!r} by name")
|
|
161
|
+
overrides += ["-c", f"mcp_servers.{name}.enabled=false"]
|
|
162
|
+
if left := [n for n, on in listing(overrides).items() if on]:
|
|
163
|
+
raise DelegationError(f"Codex MCP servers stay enabled: {', '.join(left)}")
|
|
164
|
+
return overrides
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def run(command, prompt, env, root, timeout):
|
|
168
|
+
process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
169
|
+
text=True, encoding="utf-8", errors="replace", env=env, cwd=root,
|
|
170
|
+
start_new_session=os.name != "nt")
|
|
171
|
+
try:
|
|
172
|
+
stdout, stderr = process.communicate(prompt, timeout=timeout)
|
|
173
|
+
except subprocess.TimeoutExpired as error:
|
|
174
|
+
if os.name == "nt":
|
|
175
|
+
subprocess.run(["taskkill", "/T", "/F", "/PID", str(process.pid)], capture_output=True)
|
|
176
|
+
else:
|
|
177
|
+
os.killpg(process.pid, signal.SIGKILL)
|
|
178
|
+
try:
|
|
179
|
+
process.communicate(timeout=10)
|
|
180
|
+
except subprocess.TimeoutExpired:
|
|
181
|
+
pass
|
|
182
|
+
raise DelegationError(f"{command[0]} did not finish within {timeout} s") from error
|
|
183
|
+
return subprocess.CompletedProcess(command, process.returncode, stdout, stderr)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def changed_files(root):
|
|
187
|
+
"""{path: content hash} of what git reports as changed or untracked; None outside a git repository.
|
|
188
|
+
|
|
189
|
+
Hashes make an edit to an already-dirty file visible as a change.
|
|
190
|
+
"""
|
|
191
|
+
result = subprocess.run(["git", "status", "--porcelain", "--untracked-files=all"], cwd=root, capture_output=True,
|
|
192
|
+
text=True, stdin=subprocess.DEVNULL)
|
|
193
|
+
if result.returncode:
|
|
194
|
+
return None
|
|
195
|
+
state = {}
|
|
196
|
+
for line in result.stdout.splitlines():
|
|
197
|
+
path = line[3:].strip().strip('"').split(" -> ")[-1]
|
|
198
|
+
file = root / path
|
|
199
|
+
state[path] = hashlib.sha256(file.read_bytes()).hexdigest() if file.is_file() else None
|
|
200
|
+
return state
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def log_path(kind):
|
|
204
|
+
folder = Path(tempfile.gettempdir()) / "game-dev-delegate"
|
|
205
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
206
|
+
stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
207
|
+
return folder / f"{stamp}-{kind}-{uuid.uuid4().hex[:8]}.md"
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def review(args, cfg, root, env):
|
|
211
|
+
spec = review_spec(cfg, args.kind, args.reviewer, env)
|
|
212
|
+
attachments = resolved(args.attach)
|
|
213
|
+
prompt = review_prompt(args.kind, root, read_text(args.brief), attachments)
|
|
214
|
+
output = Path(args.out).resolve() if args.out else log_path(f"{args.kind}-review")
|
|
215
|
+
env = child_env(env, spec["tool"])
|
|
216
|
+
label = f"{spec['tool']} {spec['model']} {spec['effort']}"
|
|
217
|
+
timeout = args.timeout or cfg["timeouts"]["delegate_seconds"]
|
|
218
|
+
if spec["tool"] == "codex":
|
|
219
|
+
images = [p for p in attachments if p.suffix.lower() in IMAGE_SUFFIXES]
|
|
220
|
+
if args.dry_run:
|
|
221
|
+
return " ".join(codex_command(root, spec, output, images, "read-only", CODEX_LOCKDOWN)) + "\n"
|
|
222
|
+
command = codex_command(root, spec, output, images, "read-only", codex_mcp_off(root, env))
|
|
223
|
+
result = run(command, prompt, env, root, timeout)
|
|
224
|
+
if result.returncode or not output.is_file() or not output.read_text(encoding="utf-8").strip():
|
|
225
|
+
raise DelegationError(f"codex review failed ({result.returncode}): {result.stderr[-1500:]}")
|
|
226
|
+
text = output.read_text(encoding="utf-8")
|
|
227
|
+
else:
|
|
228
|
+
settings = Path(tempfile.gettempdir()) / f"game-dev-claude-{uuid.uuid4().hex}.json"
|
|
229
|
+
if args.dry_run:
|
|
230
|
+
return " ".join(claude_command(root, spec, attachments, settings)) + "\n"
|
|
231
|
+
settings.write_text(json.dumps({"disableAllHooks": True}), encoding="utf-8")
|
|
232
|
+
try:
|
|
233
|
+
result = run(claude_command(root, spec, attachments, settings), prompt, env, root, timeout)
|
|
234
|
+
finally:
|
|
235
|
+
settings.unlink(missing_ok=True)
|
|
236
|
+
try:
|
|
237
|
+
data = json.loads(result.stdout)
|
|
238
|
+
except json.JSONDecodeError as error:
|
|
239
|
+
raise DelegationError(f"claude review failed ({result.returncode}): {result.stderr[-1500:]}"
|
|
240
|
+
f"{SANDBOX_HINT}") from error
|
|
241
|
+
if result.returncode or data.get("is_error") or not str(data.get("result", "")).strip():
|
|
242
|
+
raise DelegationError(f"claude review failed: {data.get('result') or data.get('subtype')}{SANDBOX_HINT}")
|
|
243
|
+
text = data["result"]
|
|
244
|
+
output.write_text(text, encoding="utf-8")
|
|
245
|
+
return f"Reviewer: {args.kind} review via {label}; saved to {output}\n\n{text.strip()}\n"
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def image(args, cfg, root, env):
|
|
249
|
+
spec = cfg["models"]["image"]
|
|
250
|
+
if shutil.which("codex") is None and not args.dry_run:
|
|
251
|
+
raise DelegationError("codex CLI is not on PATH; image generation needs Codex")
|
|
252
|
+
out = Path(args.out).resolve()
|
|
253
|
+
allowed = (root / cfg["paths"]["generated_art"]).resolve()
|
|
254
|
+
if not allowed.is_relative_to(root):
|
|
255
|
+
raise DelegationError(f"paths.generated_art must be inside the project: {allowed}")
|
|
256
|
+
if out.suffix.lower() != ".png":
|
|
257
|
+
raise DelegationError(f"output must end in .png: {out}")
|
|
258
|
+
if not out.is_relative_to(allowed):
|
|
259
|
+
raise DelegationError(f"output must be under {allowed} (paths.generated_art)")
|
|
260
|
+
record = out.with_suffix(".prompt.md")
|
|
261
|
+
for existing in (out, record):
|
|
262
|
+
if existing.exists():
|
|
263
|
+
raise DelegationError(f"refusing to overwrite {existing}")
|
|
264
|
+
references = resolved(args.ref)
|
|
265
|
+
prompt_text = read_text(args.prompt)
|
|
266
|
+
part = out.with_name(out.name + ".part")
|
|
267
|
+
rel_part = part.relative_to(root).as_posix()
|
|
268
|
+
prompt = (f"{role_prompt('image')}\n\nGenerate exactly one image with your image generation tool from the "
|
|
269
|
+
f"prompt between the markers. Save it as a PNG at this path, relative to the current directory: "
|
|
270
|
+
f"{rel_part}\nKeep the .part name exactly. Do not create, change or delete any other file. "
|
|
271
|
+
f"Do not ask questions.\nReference images, in order: "
|
|
272
|
+
f"{', '.join(p.name for p in references) or 'none'}\n\n--- PROMPT ---\n{prompt_text.strip()}\n"
|
|
273
|
+
"--- END PROMPT ---\n")
|
|
274
|
+
generator = f"Generator: codex {spec['model']} {spec['effort']}\n"
|
|
275
|
+
if args.dry_run:
|
|
276
|
+
return generator + " ".join(codex_command(root, spec, log_path("image"), references, "workspace-write",
|
|
277
|
+
CODEX_LOCKDOWN)) + "\n"
|
|
278
|
+
env = child_env(env, "codex")
|
|
279
|
+
command = codex_command(root, spec, log_path("image"), references, "workspace-write", codex_mcp_off(root, env))
|
|
280
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
281
|
+
part.unlink(missing_ok=True)
|
|
282
|
+
before = changed_files(root)
|
|
283
|
+
result = run(command, prompt, env, root, args.timeout or cfg["timeouts"]["delegate_seconds"])
|
|
284
|
+
if result.returncode or not part.is_file() or part.read_bytes()[:8] != PNG_SIGNATURE:
|
|
285
|
+
part.unlink(missing_ok=True)
|
|
286
|
+
raise DelegationError(f"codex wrote no PNG to {part} ({result.returncode}): {result.stderr[-1500:]}")
|
|
287
|
+
lines = [f"# Prompt for {out.name}", "", f"- model: {spec['model']}", f"- effort: {spec['effort']}",
|
|
288
|
+
f"- generated: {datetime.date.today().isoformat()}"]
|
|
289
|
+
lines += [f"- reference image: {p.relative_to(root) if p.is_relative_to(root) else p.name}" for p in references]
|
|
290
|
+
record.write_text("\n".join(lines) + "\n\n" + prompt_text.strip() + "\n", encoding="utf-8")
|
|
291
|
+
part.rename(out)
|
|
292
|
+
expected = {p.relative_to(root).as_posix() for p in (out, record, part)}
|
|
293
|
+
after = changed_files(root) if before is not None else {}
|
|
294
|
+
extra = sorted(p for p, digest in after.items() if p not in expected and before.get(p, "") != digest)
|
|
295
|
+
if extra:
|
|
296
|
+
raise DelegationError(f"image saved to {out}, but Codex also changed: {', '.join(extra[:20])}; "
|
|
297
|
+
"review and revert those changes")
|
|
298
|
+
return f"{generator}{out}\n"
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def check(args, cfg, root, env):
|
|
302
|
+
rows = [f"caller: {caller(env) or 'unknown'}"]
|
|
303
|
+
for tool in ("codex", "claude"):
|
|
304
|
+
rows.append(f"{tool}: {'found' if shutil.which(tool) else 'missing'}")
|
|
305
|
+
for role, spec in cfg["models"].items():
|
|
306
|
+
rows.append(f"models.{role}: {spec['tool']} {spec['model']} {spec['effort']}")
|
|
307
|
+
rows.append(f"paths.generated_art: {cfg['paths']['generated_art']}")
|
|
308
|
+
return "\n".join(rows) + "\n"
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def parser():
|
|
312
|
+
root = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
313
|
+
root.add_argument("--project", help="project root (default: nearest folder with game-dev.json)")
|
|
314
|
+
commands = root.add_subparsers(dest="command", required=True)
|
|
315
|
+
commands.add_parser("check", help="show the configured roles and which CLIs are available")
|
|
316
|
+
img = commands.add_parser("image", help="generate one PNG with Codex")
|
|
317
|
+
img.add_argument("--out", required=True)
|
|
318
|
+
img.add_argument("--prompt", required=True, help="Markdown or text file with the image prompt")
|
|
319
|
+
img.add_argument("--ref", action="append", default=[], help="reference image, in order (repeatable)")
|
|
320
|
+
rev = commands.add_parser("review", help="independent read-only review")
|
|
321
|
+
rev.add_argument("kind", choices=("code", "visual"))
|
|
322
|
+
rev.add_argument("--brief", required=True, help="Markdown file: what changed, what to judge, acceptance")
|
|
323
|
+
rev.add_argument("--attach", action="append", default=[], help="diff, render or reference (repeatable)")
|
|
324
|
+
rev.add_argument("--out", help="where to save the review (default: system temp folder)")
|
|
325
|
+
rev.add_argument("--reviewer", choices=("auto", "codex", "claude"), default="auto",
|
|
326
|
+
help="reviewer CLI; auto picks the agent that is not running this script")
|
|
327
|
+
for sub in (img, rev):
|
|
328
|
+
sub.add_argument("--timeout", type=int, help="seconds (default: timeouts.delegate_seconds)")
|
|
329
|
+
sub.add_argument("--dry-run", action="store_true")
|
|
330
|
+
return root
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def main(argv=None, env=None):
|
|
334
|
+
for stream in (sys.stdout, sys.stderr):
|
|
335
|
+
if isinstance(stream, io.TextIOWrapper):
|
|
336
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
337
|
+
args = parser().parse_args(argv)
|
|
338
|
+
env = dict(os.environ if env is None else env)
|
|
339
|
+
try:
|
|
340
|
+
cfg, root = gamedev_config.load(args.project)
|
|
341
|
+
handler = {"check": check, "image": image, "review": review}[args.command]
|
|
342
|
+
sys.stdout.write(handler(args, cfg, root, env))
|
|
343
|
+
except (DelegationError, gamedev_config.ConfigError) as error:
|
|
344
|
+
print(f"delegate: {error}", file=sys.stderr)
|
|
345
|
+
return 2
|
|
346
|
+
return 0
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
if __name__ == "__main__":
|
|
350
|
+
sys.exit(main())
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"""Load and validate a project's game-dev.json (shared by every tools/game-dev script).
|
|
2
|
+
|
|
3
|
+
The file lives at the project root. Missing keys fall back to DEFAULTS, so a project only
|
|
4
|
+
records what it changed. Standard library only.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import copy
|
|
8
|
+
import json
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
CONFIG_NAME = "game-dev.json"
|
|
12
|
+
ENGINES = ("godot", "threejs", "other")
|
|
13
|
+
PHASES = ("pre-alpha", "alpha", "beta", "release")
|
|
14
|
+
COMMIT_POLICIES = ("on-request", "after-checks")
|
|
15
|
+
PREVIEW_POLICIES = ("in-game", "web-page")
|
|
16
|
+
BALANCE_SOURCES = ("json", "xlsx")
|
|
17
|
+
TOOLS = ("codex", "claude")
|
|
18
|
+
ROLES = ("image", "code_review", "visual_review", "claude_review")
|
|
19
|
+
|
|
20
|
+
# Test levels ordered from the base of the pyramid to its tip. `pattern` matches a path
|
|
21
|
+
# relative to the project root (forward slashes); `case` counts test declarations.
|
|
22
|
+
TEST_PRESETS = {
|
|
23
|
+
"threejs": {
|
|
24
|
+
"case": r"^\s*(?:it|test)(?:\.(?:each|for|concurrent|fails|runIf|skipIf)(?:\([^)]*\))?)*\s*\(",
|
|
25
|
+
"levels": [
|
|
26
|
+
{"name": "unit", "pattern": r"^src/.+\.unit\.test\.tsx?$"},
|
|
27
|
+
{"name": "component", "pattern": r"^src/.+\.comp\.test\.tsx?$"},
|
|
28
|
+
{"name": "integration", "pattern": r"^tests/integration/.+\.int\.test\.tsx?$"},
|
|
29
|
+
{"name": "e2e", "pattern": r"^tests/e2e/.+\.spec\.tsx?$"},
|
|
30
|
+
],
|
|
31
|
+
"any_test": r"\.(?:test|spec)\.[cm]?[jt]sx?$",
|
|
32
|
+
"forbidden": r"\b(?:it|test|describe)(?:\.\w+)*\.only\b|\b(?:it|test|describe)(?:\.\w+)*\.(?:skip|fixme)\s*\(\s*['\"`]",
|
|
33
|
+
},
|
|
34
|
+
"godot": {
|
|
35
|
+
"case": r"^func\s+test_\w*\s*\(",
|
|
36
|
+
"levels": [
|
|
37
|
+
{"name": "unit", "pattern": r"(?:^|/)tests/unit/.+\.gd$"},
|
|
38
|
+
{"name": "component", "pattern": r"(?:^|/)tests/component/.+\.gd$"},
|
|
39
|
+
{"name": "integration", "pattern": r"(?:^|/)tests/integration/.+\.gd$"},
|
|
40
|
+
{"name": "e2e", "pattern": r"(?:^|/)tests/e2e/.+\.gd$"},
|
|
41
|
+
],
|
|
42
|
+
"any_test": r"(?:^|/)(?:test_\w+|\w+_(?:test|smoke))\.gd$", # a Godot project may sit in a subfolder
|
|
43
|
+
"forbidden": r"^\s*#\s*(?:SKIP|ONLY)\b",
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
TEST_PRESETS["other"] = {"case": "", "levels": [], "any_test": "", "forbidden": ""}
|
|
47
|
+
|
|
48
|
+
DEFAULTS = {
|
|
49
|
+
"version": 1,
|
|
50
|
+
"engine": "other",
|
|
51
|
+
"genre": "",
|
|
52
|
+
"phase": "pre-alpha",
|
|
53
|
+
"policies": {"commit": "on-request", "preview": "in-game"},
|
|
54
|
+
# Defaults only: the project owns these values and changes them here, never in scripts.
|
|
55
|
+
"models": {
|
|
56
|
+
"image": {"tool": "codex", "model": "gpt-6.2-sol", "effort": "high"},
|
|
57
|
+
"code_review": {"tool": "codex", "model": "gpt-6.2-sol", "effort": "high"},
|
|
58
|
+
"visual_review": {"tool": "codex", "model": "gpt-6.2-sol", "effort": "high"},
|
|
59
|
+
"claude_review": {"tool": "claude", "model": "claude-sonnet-5-5", "effort": "high"},
|
|
60
|
+
},
|
|
61
|
+
"balance": {"source": "json", "data": "data", "schemas": "data/schemas", "workbooks": "design/balance"},
|
|
62
|
+
"tests": None, # None means the engine preset
|
|
63
|
+
"limits": {"instruction_files": ["AGENTS.md"], "max_lines": 80, "skill_max_chars": 10000,
|
|
64
|
+
"description_max_chars": 400},
|
|
65
|
+
"commands": {"test": "", "run": ""}, # shell commands; check.py runs `test` after the game-dev checks
|
|
66
|
+
"paths": {"generated_art": "assets/generated", "sfx_factory": None},
|
|
67
|
+
"timeouts": {"delegate_seconds": 1800},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class ConfigError(ValueError):
|
|
72
|
+
pass
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def merge(base, override):
|
|
76
|
+
out = copy.deepcopy(base)
|
|
77
|
+
for key, value in (override or {}).items():
|
|
78
|
+
if isinstance(value, dict) and isinstance(out.get(key), dict):
|
|
79
|
+
out[key] = merge(out[key], value)
|
|
80
|
+
else:
|
|
81
|
+
out[key] = copy.deepcopy(value)
|
|
82
|
+
return out
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def find_root(start=None):
|
|
86
|
+
"""The nearest folder at or above `start` that holds game-dev.json, else `start`."""
|
|
87
|
+
here = Path(start or Path.cwd()).resolve()
|
|
88
|
+
for folder in (here, *here.parents):
|
|
89
|
+
if (folder / CONFIG_NAME).is_file():
|
|
90
|
+
return folder
|
|
91
|
+
return here
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
SECTIONS = ("policies", "models", "balance", "commands", "limits", "paths", "timeouts")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def validate(cfg):
|
|
98
|
+
wrong = [key for key in SECTIONS if not isinstance(cfg.get(key), dict)]
|
|
99
|
+
if wrong:
|
|
100
|
+
return [f"{key} must be an object" for key in wrong]
|
|
101
|
+
wrong = [f"models.{role}" for role, spec in cfg["models"].items() if not isinstance(spec, dict)]
|
|
102
|
+
if wrong:
|
|
103
|
+
return [f"{key} must be an object with tool, model and effort" for key in wrong]
|
|
104
|
+
problems = []
|
|
105
|
+
|
|
106
|
+
def one_of(path, value, allowed):
|
|
107
|
+
if value not in allowed:
|
|
108
|
+
problems.append(f"{path} is {value!r}; expected one of {', '.join(allowed)}")
|
|
109
|
+
|
|
110
|
+
one_of("engine", cfg.get("engine"), ENGINES)
|
|
111
|
+
one_of("phase", cfg.get("phase"), PHASES)
|
|
112
|
+
policies = cfg.get("policies") or {}
|
|
113
|
+
one_of("policies.commit", policies.get("commit"), COMMIT_POLICIES)
|
|
114
|
+
one_of("policies.preview", policies.get("preview"), PREVIEW_POLICIES)
|
|
115
|
+
one_of("balance.source", (cfg.get("balance") or {}).get("source"), BALANCE_SOURCES)
|
|
116
|
+
for role in ROLES:
|
|
117
|
+
spec = (cfg.get("models") or {}).get(role)
|
|
118
|
+
if not isinstance(spec, dict):
|
|
119
|
+
problems.append(f"models.{role} is missing")
|
|
120
|
+
continue
|
|
121
|
+
one_of(f"models.{role}.tool", spec.get("tool"), TOOLS)
|
|
122
|
+
for key in ("model", "effort"):
|
|
123
|
+
if not isinstance(spec.get(key), str) or not spec[key].strip():
|
|
124
|
+
problems.append(f"models.{role}.{key} must be a non-empty string")
|
|
125
|
+
if not isinstance(cfg["paths"].get("generated_art"), str) or not cfg["paths"]["generated_art"].strip():
|
|
126
|
+
problems.append("paths.generated_art must be a non-empty string")
|
|
127
|
+
seconds = cfg["timeouts"].get("delegate_seconds")
|
|
128
|
+
if not isinstance(seconds, int) or isinstance(seconds, bool) or seconds <= 0:
|
|
129
|
+
problems.append("timeouts.delegate_seconds must be a positive integer")
|
|
130
|
+
if (cfg.get("models") or {}).get("image", {}).get("tool") == "claude":
|
|
131
|
+
problems.append("models.image.tool must be codex: image generation runs in Codex")
|
|
132
|
+
tests = cfg.get("tests")
|
|
133
|
+
if tests is not None:
|
|
134
|
+
if not isinstance(tests, dict) or not isinstance(tests.get("levels"), list):
|
|
135
|
+
problems.append("tests must be null or an object with a levels list")
|
|
136
|
+
else:
|
|
137
|
+
for i, level in enumerate(tests["levels"]):
|
|
138
|
+
if not isinstance(level, dict) or not level.get("name") or not level.get("pattern"):
|
|
139
|
+
problems.append(f"tests.levels[{i}] needs name and pattern")
|
|
140
|
+
return problems
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def load(root=None, required=True):
|
|
144
|
+
"""Return (config, root). Raises ConfigError on a missing (when required) or invalid file."""
|
|
145
|
+
root = find_root(root)
|
|
146
|
+
path = root / CONFIG_NAME
|
|
147
|
+
raw = {}
|
|
148
|
+
if path.is_file():
|
|
149
|
+
try:
|
|
150
|
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
|
151
|
+
except json.JSONDecodeError as error:
|
|
152
|
+
raise ConfigError(f"{path}: invalid JSON: {error}") from error
|
|
153
|
+
if not isinstance(raw, dict):
|
|
154
|
+
raise ConfigError(f"{path}: top level must be an object")
|
|
155
|
+
elif required:
|
|
156
|
+
raise ConfigError(f"{path} not found: run the game-dev-setup skill first")
|
|
157
|
+
cfg = merge(DEFAULTS, raw)
|
|
158
|
+
if cfg.get("tests") is None:
|
|
159
|
+
cfg["tests"] = copy.deepcopy(TEST_PRESETS.get(cfg.get("engine"), TEST_PRESETS["other"]))
|
|
160
|
+
problems = validate(cfg)
|
|
161
|
+
if problems:
|
|
162
|
+
raise ConfigError(f"{path}: " + "; ".join(problems))
|
|
163
|
+
return cfg, root
|