agent-manifesto-kit 1.8.3 → 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/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,46 @@
|
|
|
1
|
+
# game-dev.json
|
|
2
|
+
|
|
3
|
+
Project root. Every key is optional; missing keys use these defaults. `gamedev_config.py` checks
|
|
4
|
+
section types, the enumerated values, the model fields and the test levels, and fails with the
|
|
5
|
+
key name.
|
|
6
|
+
|
|
7
|
+
| Key | Default | Meaning |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `version` | `1` | file format version |
|
|
10
|
+
| `engine` | `other` | `godot`, `threejs` or `other`; selects the test preset and the `game-code` profile |
|
|
11
|
+
| `genre` | `""` | free text, e.g. `tower-defense`; informs the balance source and planning |
|
|
12
|
+
| `phase` | `pre-alpha` | `pre-alpha`, `alpha`, `beta`, `release` |
|
|
13
|
+
| `policies.commit` | `on-request` | `on-request` or `after-checks` (commit each finished piece once check.py passes) |
|
|
14
|
+
| `policies.preview` | `in-game` | `in-game` or `web-page` |
|
|
15
|
+
| `models.image` | codex `gpt-6.2-sol` `high` | image generation; always Codex |
|
|
16
|
+
| `models.code_review` | codex `gpt-6.2-sol` `high` | independent code review, read-only |
|
|
17
|
+
| `models.visual_review` | codex `gpt-6.2-sol` `high` | fresh-context visual review, read-only |
|
|
18
|
+
| `models.claude_review` | claude `claude-sonnet-5-5` `high` | the reviewer used when the session itself is Codex |
|
|
19
|
+
| `balance.source` | `json` | `json` or `xlsx` |
|
|
20
|
+
| `balance.data` | `data` | JSON the game loads |
|
|
21
|
+
| `balance.schemas` | `data/schemas` | `<name>.schema.json` per data file |
|
|
22
|
+
| `balance.workbooks` | `design/balance` | XLSX sources when `source` is `xlsx` |
|
|
23
|
+
| `tests` | engine preset | `{case, levels[{name, pattern}], any_test, forbidden}` regexes, base level first |
|
|
24
|
+
| `commands.test` | `""` | the project's full test command; check.py runs it last |
|
|
25
|
+
| `commands.run` | `""` | how to start the game; also the Astro Preview run command |
|
|
26
|
+
| `limits` | 80 lines, 10000 chars, 400 chars | `instruction_files`, `max_lines`, `skill_max_chars`, `description_max_chars` |
|
|
27
|
+
| `paths.generated_art` | `assets/generated` | the only folder image generation may write to |
|
|
28
|
+
| `paths.sfx_factory` | `null` | the sfx-factory checkout for the `sfx-creator` companion (`SFX_FACTORY` overrides) |
|
|
29
|
+
| `timeouts.delegate_seconds` | `1800` | a delegated run is killed after this |
|
|
30
|
+
|
|
31
|
+
Model names are defaults, not part of the bundle's contract: when a newer model is preferred,
|
|
32
|
+
change it here. Every model field is `{tool, model, effort}`; sandboxes are fixed by role
|
|
33
|
+
(image `workspace-write`, reviews `read-only`).
|
|
34
|
+
|
|
35
|
+
Example of a small file:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"engine": "godot",
|
|
40
|
+
"genre": "tactics",
|
|
41
|
+
"phase": "alpha",
|
|
42
|
+
"policies": {"commit": "after-checks", "preview": "in-game"},
|
|
43
|
+
"balance": {"source": "xlsx"},
|
|
44
|
+
"commands": {"test": "godot --headless -s tests/run.gd", "run": "godot --path ."}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""Inventory a game project for game-dev-setup. Read-only.
|
|
2
|
+
|
|
3
|
+
python3 audit.py --project DIR [--json]
|
|
4
|
+
|
|
5
|
+
Reports facts only: engine, existing AI instructions and their size, Taskpilot shape, roadmap,
|
|
6
|
+
Astro Preview portal, data and balance files, test layout, asset signals, available CLIs, model
|
|
7
|
+
names hard-coded in scripts, and the installed game-dev files. `suggest` lists the companion
|
|
8
|
+
capabilities whose signals were found; the skill decides with the user what to install.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import shutil
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
HERE = Path(__file__).resolve().parent
|
|
21
|
+
sys.path.insert(0, str(HERE))
|
|
22
|
+
import gamedev_config # noqa: E402
|
|
23
|
+
import pyramid # noqa: E402
|
|
24
|
+
|
|
25
|
+
SKIP = {".git", "node_modules", "dist", "build", ".godot", ".venv", "venv", "__pycache__", "local", ".cache"}
|
|
26
|
+
CLAUDE_ADAPTER = "CLAUDE" + ".md"
|
|
27
|
+
MODEL_NAME = re.compile(r"\b(?:gpt-\d[\w.-]*|claude-(?:opus|sonnet|haiku|fable)[\w.-]*|o\d-[\w-]+)\b")
|
|
28
|
+
SCRIPT_SUFFIXES = {".py", ".sh", ".mjs", ".js", ".ts", ".toml"}
|
|
29
|
+
IMAGE = {".png", ".jpg", ".jpeg", ".webp"}
|
|
30
|
+
AUDIO = {".wav", ".ogg", ".mp3", ".flac"}
|
|
31
|
+
RUNTIME = ("gamedev_config.py", "delegate.py", "balance.py", "pyramid.py", "instruction_size.py", "check.py",
|
|
32
|
+
"prompts/code_review.md", "prompts/visual_review.md", "prompts/image.md")
|
|
33
|
+
MACHINES = re.compile(r"mech|vehicle|tank|turret|aircraft|helicopter|drone", re.I)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def walk(root, limit=20000):
|
|
37
|
+
count = 0
|
|
38
|
+
for folder, dirs, names in os.walk(root):
|
|
39
|
+
dirs[:] = [d for d in dirs if d not in SKIP and not (d.startswith(".") and d not in (".claude", ".agents",
|
|
40
|
+
".codex", ".astro"))]
|
|
41
|
+
for name in names:
|
|
42
|
+
count += 1
|
|
43
|
+
if count > limit:
|
|
44
|
+
return
|
|
45
|
+
yield Path(folder) / name
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def runtime_state(root, name):
|
|
49
|
+
"""missing, same (as this kit version) or differs (stale or adapted by the project); prompts included."""
|
|
50
|
+
installed = root / "tools/game-dev" / name
|
|
51
|
+
if not installed.is_file():
|
|
52
|
+
return "missing"
|
|
53
|
+
return "same" if installed.read_bytes() == (HERE / name).read_bytes() else "differs"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def engine(root):
|
|
57
|
+
if (root / "project.godot").is_file() or any(root.glob("*/project.godot")) or any(root.glob("*/*/project.godot")):
|
|
58
|
+
return "godot"
|
|
59
|
+
pkg = root / "package.json"
|
|
60
|
+
if pkg.is_file():
|
|
61
|
+
try:
|
|
62
|
+
deps = json.loads(pkg.read_text(encoding="utf-8"))
|
|
63
|
+
except json.JSONDecodeError:
|
|
64
|
+
deps = {}
|
|
65
|
+
names = {**deps.get("dependencies", {}), **deps.get("devDependencies", {})}
|
|
66
|
+
if "three" in names:
|
|
67
|
+
return "threejs"
|
|
68
|
+
return "other"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def lines(path):
|
|
72
|
+
return len(path.read_text(encoding="utf-8", errors="replace").splitlines()) if path.is_file() else None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def taskpilot(root):
|
|
76
|
+
items = root / ".taskpilot" / "items"
|
|
77
|
+
if not (root / ".taskpilot" / "project.yaml").is_file():
|
|
78
|
+
return None
|
|
79
|
+
by_type, by_status, orphans, no_dod = {}, {}, 0, 0
|
|
80
|
+
for item in sorted(items.glob("*.yaml")) if items.is_dir() else []:
|
|
81
|
+
text = item.read_text(encoding="utf-8", errors="replace")
|
|
82
|
+
kind = (re.search(r"^type:\s*(\S+)", text, re.M) or [None, "?"])[1]
|
|
83
|
+
status = (re.search(r"^status:\s*(\S+)", text, re.M) or [None, "?"])[1]
|
|
84
|
+
by_type[kind] = by_type.get(kind, 0) + 1
|
|
85
|
+
by_status[status] = by_status.get(status, 0) + 1
|
|
86
|
+
if kind in ("task", "bug") and not re.search(r"^parent_id:\s*\S", text, re.M):
|
|
87
|
+
orphans += 1
|
|
88
|
+
if kind == "feature" and not re.search(r"^dod:", text, re.M):
|
|
89
|
+
no_dod += 1
|
|
90
|
+
return {"types": by_type, "statuses": by_status, "tasks_without_parent": orphans, "features_without_dod": no_dod}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def audit(root):
|
|
94
|
+
root = Path(root).resolve()
|
|
95
|
+
files = list(walk(root))
|
|
96
|
+
rel = [p.relative_to(root).as_posix() for p in files]
|
|
97
|
+
suffixes = {}
|
|
98
|
+
for p in files:
|
|
99
|
+
suffixes[p.suffix.lower()] = suffixes.get(p.suffix.lower(), 0) + 1
|
|
100
|
+
detected = engine(root)
|
|
101
|
+
hardcoded = []
|
|
102
|
+
for p, r in zip(files, rel):
|
|
103
|
+
own = r.startswith(("tools/game-dev/", ".claude/skills/game-", ".agents/skills/game-"))
|
|
104
|
+
if p.suffix in SCRIPT_SUFFIXES and not own and p.stat().st_size < 200_000:
|
|
105
|
+
found = sorted(set(MODEL_NAME.findall(p.read_text(encoding="utf-8", errors="replace"))))
|
|
106
|
+
if found:
|
|
107
|
+
hardcoded.append({"file": r, "models": found})
|
|
108
|
+
preset = gamedev_config.TEST_PRESETS[detected]
|
|
109
|
+
counts, test_problems = pyramid.measure(root, preset) if preset["levels"] else ({}, [])
|
|
110
|
+
concept_dirs = sorted({str(Path(r).parent) for r in rel if Path(r).suffix.lower() in IMAGE
|
|
111
|
+
and re.search(r"concept|reference|art/direction", r, re.I)})
|
|
112
|
+
git = subprocess.run(["git", "status", "--porcelain"], cwd=root, capture_output=True, text=True,
|
|
113
|
+
stdin=subprocess.DEVNULL)
|
|
114
|
+
report = {
|
|
115
|
+
"root": str(root),
|
|
116
|
+
"git": {"repo": git.returncode == 0, "uncommitted": git.stdout.splitlines()[:40] if git.returncode == 0 else []},
|
|
117
|
+
"engine": detected,
|
|
118
|
+
"game_dev": {
|
|
119
|
+
"config": (root / gamedev_config.CONFIG_NAME).is_file(),
|
|
120
|
+
"runtime": {name: runtime_state(root, name) for name in RUNTIME},
|
|
121
|
+
"agents_section": "<!-- game-dev:begin" in ((root / "AGENTS.md").read_text(encoding="utf-8")
|
|
122
|
+
if (root / "AGENTS.md").is_file() else ""),
|
|
123
|
+
},
|
|
124
|
+
"instructions": {
|
|
125
|
+
"AGENTS.md": lines(root / "AGENTS.md"),
|
|
126
|
+
CLAUDE_ADAPTER: lines(root / CLAUDE_ADAPTER),
|
|
127
|
+
"claude_imports_agents": bool(re.search(r"@(?:\./)?AGENTS\.md", (root / CLAUDE_ADAPTER).read_text(
|
|
128
|
+
encoding="utf-8") if (root / CLAUDE_ADAPTER).is_file() else "")),
|
|
129
|
+
"skills": sorted({p.parent.name for p in files if p.name == "SKILL.md"}),
|
|
130
|
+
"agents": sorted(r for r in rel if re.match(r"\.(claude/agents/.+\.md|codex/agents/.+\.toml)$", r)),
|
|
131
|
+
"hooks": sorted(r for r in rel if r.startswith((".githooks/", "scripts/hooks/"))),
|
|
132
|
+
},
|
|
133
|
+
"taskpilot": taskpilot(root),
|
|
134
|
+
"roadmap": {"plan": (root / "docs/roadmap_plan.json").is_file(), "page": (root / "docs/roadmap.html").is_file(),
|
|
135
|
+
"phase_docs": sorted(r for r in rel if re.search(r"(pre-alpha|alpha|beta)[^/]*\.md$", r))},
|
|
136
|
+
"astro": {"portal": (root / ".astro/portal.json").is_file(), "wiki_pages": len(list(root.glob("docs/wiki/*.md"))),
|
|
137
|
+
"readme": (root / "README.md").is_file()},
|
|
138
|
+
"data": {
|
|
139
|
+
"json": sorted(r for r in rel if r.endswith(".json") and not r.endswith(".schema.json")
|
|
140
|
+
and re.search(r"(?:^|/)(?:data|balance)/", r))[:40],
|
|
141
|
+
"json_in_code": len([r for r in rel if r.endswith(".json") and re.match(r"(?:src|game|scripts)/", r)
|
|
142
|
+
and not re.search(r"(?:^|/)(?:data|balance)/", r)]),
|
|
143
|
+
"xlsx": sorted(r for r in rel if r.endswith(".xlsx"))[:40],
|
|
144
|
+
"schemas": sorted(r for r in rel if r.endswith(".schema.json"))[:40],
|
|
145
|
+
},
|
|
146
|
+
"tests": {"preset": detected, "counts": counts, "problems": test_problems[:20]},
|
|
147
|
+
"assets": {"blend": suffixes.get(".blend", 0), "fbx_glb": suffixes.get(".fbx", 0) + suffixes.get(".glb", 0),
|
|
148
|
+
"audio": sum(suffixes.get(s, 0) for s in AUDIO), "concept_dirs": concept_dirs[:20]},
|
|
149
|
+
"clis": {name: shutil.which(name) is not None
|
|
150
|
+
for name in ("codex", "claude", "taskpilot", "blender", "godot", "node", "agentkit")},
|
|
151
|
+
"hardcoded_models": hardcoded[:30],
|
|
152
|
+
}
|
|
153
|
+
report["suggest"] = suggest(report)
|
|
154
|
+
return report
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def suggest(r):
|
|
158
|
+
"""Companion capabilities whose signals were found, with the signal; the user decides.
|
|
159
|
+
|
|
160
|
+
roadmap, astro-preview and session-retro are always offered: every game gets phases, a portal
|
|
161
|
+
entry with wiki and README, and retros.
|
|
162
|
+
"""
|
|
163
|
+
out = [{"name": "roadmap", "kind": "skill", "why": "always offered: phases and milestones from Taskpilot"}]
|
|
164
|
+
out.append({"name": "astro-preview", "kind": "skill", "why": "always offered: portal entry, wiki and README"})
|
|
165
|
+
a = r["assets"]
|
|
166
|
+
if a["blend"] or a["fbx_glb"] or r["clis"]["blender"]:
|
|
167
|
+
out.append({"name": "blender-3d", "kind": "bundle", "why": f"{a['blend']} .blend, {a['fbx_glb']} fbx/glb files"})
|
|
168
|
+
if a["concept_dirs"]:
|
|
169
|
+
why = f"concept images in {', '.join(a['concept_dirs'][:3])}"
|
|
170
|
+
out += [{"name": n, "kind": "skill", "why": why}
|
|
171
|
+
for n in ("art-direction-pass", "concept-scene-builder", "concept-asset-builder")]
|
|
172
|
+
if any(MACHINES.search(d) for d in a["concept_dirs"]):
|
|
173
|
+
out.append({"name": "machine-builder", "kind": "skill", "why": "machine concepts in the concept folders"})
|
|
174
|
+
if r["clis"]["codex"] != r["clis"]["claude"]:
|
|
175
|
+
out.append({"name": "code-reviewer", "kind": "agent",
|
|
176
|
+
"why": "only one agent CLI found: a fresh-context review in the same tool"})
|
|
177
|
+
if a["fbx_glb"]:
|
|
178
|
+
out.append({"name": "mixamo", "kind": "skill", "why": "humanoid models may need a rig and clips"})
|
|
179
|
+
if a["audio"]:
|
|
180
|
+
out.append({"name": "sfx-creator", "kind": "skill", "why": f"{a['audio']} audio files"})
|
|
181
|
+
if r["engine"] == "threejs":
|
|
182
|
+
out.append({"name": "qa-automation", "kind": "bundle", "why": "browser game: Playwright e2e"})
|
|
183
|
+
out.append({"name": "session-retro", "kind": "bundle", "why": "always offered: retro after a session, then fix skills"})
|
|
184
|
+
return out
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def main(argv=None):
|
|
188
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
189
|
+
parser.add_argument("--project", default=".")
|
|
190
|
+
parser.add_argument("--json", action="store_true")
|
|
191
|
+
args = parser.parse_args(argv)
|
|
192
|
+
report = audit(args.project)
|
|
193
|
+
if args.json:
|
|
194
|
+
print(json.dumps(report, indent=1))
|
|
195
|
+
else:
|
|
196
|
+
for key, value in report.items():
|
|
197
|
+
print(f"{key}: {json.dumps(value, ensure_ascii=False)[:300]}")
|
|
198
|
+
return 0
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
if __name__ == "__main__":
|
|
202
|
+
sys.exit(main())
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""Check and import the game's balance data. The game always reads JSON.
|
|
2
|
+
|
|
3
|
+
python3 tools/game-dev/balance.py check # validate every data JSON against its schema
|
|
4
|
+
python3 tools/game-dev/balance.py import [--check] # XLSX workbooks -> data JSON (needs openpyxl)
|
|
5
|
+
|
|
6
|
+
Layout comes from game-dev.json `balance`: `data` (JSON the game loads), `schemas`
|
|
7
|
+
(`<name>.schema.json` for `<data>/<name>.json`), `workbooks` (XLSX sources when `source` is xlsx).
|
|
8
|
+
|
|
9
|
+
Schemas use a small JSON Schema subset: type, properties, required, additionalProperties (false),
|
|
10
|
+
items, enum, minimum, maximum, minLength, minItems, maxItems, uniqueItems and the extension
|
|
11
|
+
`uniqueKey` (an array of objects whose given key must be unique, e.g. "id").
|
|
12
|
+
|
|
13
|
+
Workbook format: one table per sheet. Row 1 holds keys, row 2 a human note (units, range), rows 3+
|
|
14
|
+
data. Sheets whose name starts with "_" are notes. Output per workbook: {sheet: [{key: value}]}.
|
|
15
|
+
Import fails on duplicate or empty keys and on duplicate or missing ids in an "id" column;
|
|
16
|
+
--check writes nothing and also fails when a JSON file differs from its workbook.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import json
|
|
21
|
+
import sys
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
25
|
+
import gamedev_config # noqa: E402
|
|
26
|
+
|
|
27
|
+
TYPES = {"object": dict, "array": list, "string": str, "boolean": bool, "null": type(None)}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def type_ok(value, expected):
|
|
31
|
+
if isinstance(expected, list):
|
|
32
|
+
return any(type_ok(value, e) for e in expected)
|
|
33
|
+
if expected == "integer":
|
|
34
|
+
return isinstance(value, int) and not isinstance(value, bool)
|
|
35
|
+
if expected == "number":
|
|
36
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
37
|
+
return isinstance(value, TYPES.get(expected, object))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def validate(value, schema, path="$"):
|
|
41
|
+
"""Return a list of 'path: problem' strings for the supported schema subset."""
|
|
42
|
+
problems = []
|
|
43
|
+
expected = schema.get("type")
|
|
44
|
+
if expected is not None and not type_ok(value, expected):
|
|
45
|
+
return [f"{path}: expected {expected}, got {type(value).__name__}"]
|
|
46
|
+
if "enum" in schema and value not in schema["enum"]:
|
|
47
|
+
problems.append(f"{path}: {value!r} is not one of {schema['enum']}")
|
|
48
|
+
if isinstance(value, (int, float)) and not isinstance(value, bool):
|
|
49
|
+
if "minimum" in schema and value < schema["minimum"]:
|
|
50
|
+
problems.append(f"{path}: {value} < minimum {schema['minimum']}")
|
|
51
|
+
if "maximum" in schema and value > schema["maximum"]:
|
|
52
|
+
problems.append(f"{path}: {value} > maximum {schema['maximum']}")
|
|
53
|
+
if isinstance(value, str) and len(value) < schema.get("minLength", 0):
|
|
54
|
+
problems.append(f"{path}: shorter than {schema['minLength']}")
|
|
55
|
+
if isinstance(value, dict):
|
|
56
|
+
props = schema.get("properties", {})
|
|
57
|
+
for key in schema.get("required", []):
|
|
58
|
+
if key not in value:
|
|
59
|
+
problems.append(f"{path}: missing required key {key!r}")
|
|
60
|
+
for key, item in value.items():
|
|
61
|
+
if key in props:
|
|
62
|
+
problems += validate(item, props[key], f"{path}.{key}")
|
|
63
|
+
elif schema.get("additionalProperties") is False:
|
|
64
|
+
problems.append(f"{path}: unknown key {key!r}")
|
|
65
|
+
elif isinstance(schema.get("additionalProperties"), dict):
|
|
66
|
+
problems += validate(item, schema["additionalProperties"], f"{path}.{key}")
|
|
67
|
+
if isinstance(value, list):
|
|
68
|
+
if len(value) < schema.get("minItems", 0):
|
|
69
|
+
problems.append(f"{path}: fewer than {schema['minItems']} items")
|
|
70
|
+
if "maxItems" in schema and len(value) > schema["maxItems"]:
|
|
71
|
+
problems.append(f"{path}: more than {schema['maxItems']} items")
|
|
72
|
+
if schema.get("uniqueItems"):
|
|
73
|
+
seen = [json.dumps(v, sort_keys=True) for v in value]
|
|
74
|
+
if len(set(seen)) != len(seen):
|
|
75
|
+
problems.append(f"{path}: items are not unique")
|
|
76
|
+
key = schema.get("uniqueKey")
|
|
77
|
+
if key:
|
|
78
|
+
ids = [v.get(key) for v in value if isinstance(v, dict)]
|
|
79
|
+
dupes = sorted({str(i) for i in ids if ids.count(i) > 1})
|
|
80
|
+
if dupes:
|
|
81
|
+
problems.append(f"{path}: duplicate {key} {', '.join(dupes)}")
|
|
82
|
+
if isinstance(schema.get("items"), dict):
|
|
83
|
+
for i, item in enumerate(value):
|
|
84
|
+
problems += validate(item, schema["items"], f"{path}[{i}]")
|
|
85
|
+
return problems
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def check(cfg, root):
|
|
89
|
+
data = root / cfg["balance"]["data"]
|
|
90
|
+
schemas = root / cfg["balance"]["schemas"]
|
|
91
|
+
problems, checked = [], 0
|
|
92
|
+
files = sorted(p for p in data.rglob("*.json") if not p.is_relative_to(schemas)) if data.is_dir() else []
|
|
93
|
+
# JSON generated from a workbook is checked by `import --check`; its schema is optional.
|
|
94
|
+
books = root / cfg["balance"]["workbooks"]
|
|
95
|
+
generated = ({p.stem for p in books.glob("*.xlsx")} if cfg["balance"]["source"] == "xlsx" and books.is_dir()
|
|
96
|
+
else set())
|
|
97
|
+
for file in files:
|
|
98
|
+
rel = file.relative_to(data).with_suffix("")
|
|
99
|
+
schema_file = schemas / f"{rel.as_posix()}.schema.json"
|
|
100
|
+
if not schema_file.is_file() and file.parent == data and file.stem in generated:
|
|
101
|
+
continue
|
|
102
|
+
try:
|
|
103
|
+
value = json.loads(file.read_text(encoding="utf-8"))
|
|
104
|
+
except json.JSONDecodeError as error:
|
|
105
|
+
problems.append(f"{file.relative_to(root)}: invalid JSON: {error}")
|
|
106
|
+
continue
|
|
107
|
+
if not schema_file.is_file():
|
|
108
|
+
problems.append(f"{file.relative_to(root)}: no schema at {schema_file.relative_to(root)}")
|
|
109
|
+
continue
|
|
110
|
+
schema = json.loads(schema_file.read_text(encoding="utf-8"))
|
|
111
|
+
problems += [f"{file.relative_to(root)}: {p}" for p in validate(value, schema)]
|
|
112
|
+
checked += 1
|
|
113
|
+
for line in problems:
|
|
114
|
+
print(line)
|
|
115
|
+
print(f"balance: {checked} file(s) checked, {len(problems)} problem(s)")
|
|
116
|
+
return 1 if problems else 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def read_workbook(path):
|
|
120
|
+
try:
|
|
121
|
+
from openpyxl import load_workbook
|
|
122
|
+
except ImportError as error:
|
|
123
|
+
raise SystemExit("balance: openpyxl is required for XLSX import (python3 -m pip install openpyxl)") from error
|
|
124
|
+
wb = load_workbook(path, data_only=True, read_only=True)
|
|
125
|
+
tables, problems = {}, []
|
|
126
|
+
for ws in wb.worksheets:
|
|
127
|
+
if ws.title.startswith("_"):
|
|
128
|
+
continue
|
|
129
|
+
rows = list(ws.iter_rows(values_only=True))
|
|
130
|
+
header = list(rows[0]) if rows else []
|
|
131
|
+
while header and header[-1] is None:
|
|
132
|
+
header.pop()
|
|
133
|
+
if None in header:
|
|
134
|
+
problems.append(f"{ws.title}: empty key in row 1")
|
|
135
|
+
keys = [k for k in header if k is not None]
|
|
136
|
+
if len(set(keys)) != len(keys):
|
|
137
|
+
problems.append(f"{ws.title}: duplicate column keys")
|
|
138
|
+
data = [dict(zip(keys, r)) for r in rows[2:] if any(v is not None for v in r[:len(keys)])]
|
|
139
|
+
if "id" in keys:
|
|
140
|
+
ids = [d.get("id") for d in data]
|
|
141
|
+
if None in ids:
|
|
142
|
+
problems.append(f"{ws.title}: row without id")
|
|
143
|
+
if len(set(i for i in ids if i is not None)) != len([i for i in ids if i is not None]):
|
|
144
|
+
problems.append(f"{ws.title}: duplicate ids")
|
|
145
|
+
tables[ws.title] = data
|
|
146
|
+
return tables, problems
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def import_workbooks(cfg, root, only_check):
|
|
150
|
+
src = root / cfg["balance"]["workbooks"]
|
|
151
|
+
out_dir = root / cfg["balance"]["data"]
|
|
152
|
+
failed = False
|
|
153
|
+
books = sorted(p for p in src.glob("*.xlsx") if not p.name.startswith("~$")) if src.is_dir() else []
|
|
154
|
+
if not books:
|
|
155
|
+
print(f"balance: no workbooks in {src.relative_to(root)} (balance.source is xlsx)")
|
|
156
|
+
return 1
|
|
157
|
+
for book in books:
|
|
158
|
+
tables, problems = read_workbook(book)
|
|
159
|
+
for p in problems:
|
|
160
|
+
print(f"{book.name}: {p}")
|
|
161
|
+
failed |= bool(problems)
|
|
162
|
+
out = out_dir / f"{book.stem}.json"
|
|
163
|
+
text = json.dumps(tables, indent=1, ensure_ascii=False, default=str) + "\n"
|
|
164
|
+
if problems:
|
|
165
|
+
continue
|
|
166
|
+
if only_check:
|
|
167
|
+
current = out.read_text(encoding="utf-8") if out.is_file() else None
|
|
168
|
+
if current != text:
|
|
169
|
+
print(f"{book.name}: {out.relative_to(root)} is out of date; run balance.py import")
|
|
170
|
+
failed = True
|
|
171
|
+
else:
|
|
172
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
173
|
+
out.write_text(text, encoding="utf-8")
|
|
174
|
+
print(f"{book.name} -> {out.relative_to(root)} ({', '.join(f'{k}:{len(v)}' for k, v in tables.items())})")
|
|
175
|
+
return 1 if failed else 0
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def main(argv=None):
|
|
179
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
180
|
+
parser.add_argument("--project")
|
|
181
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
182
|
+
sub.add_parser("check")
|
|
183
|
+
imp = sub.add_parser("import")
|
|
184
|
+
imp.add_argument("--check", action="store_true", help="validate only; fail on drift")
|
|
185
|
+
args = parser.parse_args(argv)
|
|
186
|
+
try:
|
|
187
|
+
cfg, root = gamedev_config.load(args.project)
|
|
188
|
+
except gamedev_config.ConfigError as error:
|
|
189
|
+
print(f"balance: {error}", file=sys.stderr)
|
|
190
|
+
return 2
|
|
191
|
+
if args.command == "check":
|
|
192
|
+
return check(cfg, root)
|
|
193
|
+
return import_workbooks(cfg, root, args.check)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if __name__ == "__main__":
|
|
197
|
+
sys.exit(main())
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Run every game-dev check, then the project's own tests.
|
|
2
|
+
|
|
3
|
+
python3 tools/game-dev/check.py [--project DIR] [--skip-tests]
|
|
4
|
+
|
|
5
|
+
Order: game-dev.json validity, instruction size, test pyramid, balance data (schemas, and XLSX
|
|
6
|
+
drift when balance.source is xlsx), then `commands.test` from game-dev.json. Prints one line per
|
|
7
|
+
step and exits non-zero when any step fails. Report what it printed, not what you expected.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
HERE = Path(__file__).resolve().parent
|
|
16
|
+
sys.path.insert(0, str(HERE))
|
|
17
|
+
import gamedev_config # noqa: E402
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def step(name, command, root, shell=False):
|
|
21
|
+
result = subprocess.run(command, cwd=root, capture_output=True, text=True, stdin=subprocess.DEVNULL, shell=shell)
|
|
22
|
+
output = (result.stdout + result.stderr).strip()
|
|
23
|
+
status = "pass" if result.returncode == 0 else "FAIL"
|
|
24
|
+
print(f"[{status}] {name}")
|
|
25
|
+
if result.returncode:
|
|
26
|
+
print("\n".join(" " + line for line in output.splitlines()[-30:]))
|
|
27
|
+
return result.returncode == 0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main(argv=None):
|
|
31
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
32
|
+
parser.add_argument("--project")
|
|
33
|
+
parser.add_argument("--skip-tests", action="store_true", help="only the game-dev checks")
|
|
34
|
+
args = parser.parse_args(argv)
|
|
35
|
+
try:
|
|
36
|
+
cfg, root = gamedev_config.load(args.project)
|
|
37
|
+
except gamedev_config.ConfigError as error:
|
|
38
|
+
print(f"[FAIL] game-dev.json: {error}")
|
|
39
|
+
return 1
|
|
40
|
+
print("[pass] game-dev.json")
|
|
41
|
+
py = sys.executable
|
|
42
|
+
ok = step("instruction size", [py, str(HERE / "instruction_size.py"), "--project", str(root)], root)
|
|
43
|
+
ok &= step("test pyramid", [py, str(HERE / "pyramid.py"), "--project", str(root)], root)
|
|
44
|
+
ok &= step("balance data", [py, str(HERE / "balance.py"), "--project", str(root), "check"], root)
|
|
45
|
+
if cfg["balance"]["source"] == "xlsx":
|
|
46
|
+
if (root / cfg["balance"]["workbooks"]).is_dir():
|
|
47
|
+
ok &= step("balance workbooks", [py, str(HERE / "balance.py"), "--project", str(root), "import",
|
|
48
|
+
"--check"], root)
|
|
49
|
+
else:
|
|
50
|
+
print(f"[skip] balance workbooks: no {cfg['balance']['workbooks']} folder yet")
|
|
51
|
+
test_command = cfg["commands"].get("test")
|
|
52
|
+
if args.skip_tests:
|
|
53
|
+
print("[skip] project tests (--skip-tests)")
|
|
54
|
+
elif test_command:
|
|
55
|
+
ok &= step(f"project tests: {test_command}", test_command, root, shell=True)
|
|
56
|
+
else:
|
|
57
|
+
print("[skip] project tests: commands.test is empty in game-dev.json")
|
|
58
|
+
return 0 if ok else 1
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
sys.exit(main())
|