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,172 @@
|
|
|
1
|
+
"""Apply the approved game-dev setup to a project. Idempotent; --dry-run writes nothing.
|
|
2
|
+
|
|
3
|
+
python3 install.py --project DIR --engine godot|threejs|other [--genre G] [--phase P]
|
|
4
|
+
[--balance json|xlsx] [--commit on-request|after-checks] [--preview in-game|web-page]
|
|
5
|
+
[--test-command CMD] [--run-command CMD] [--dry-run] [--force | --force-file PATH ...]
|
|
6
|
+
|
|
7
|
+
1. Copies the runtime (gamedev_config, delegate, balance, pyramid, instruction_size, check and
|
|
8
|
+
prompts/) into tools/game-dev/. A copy that differs from this kit version is reported and
|
|
9
|
+
kept: the project may have adapted it. --force-file replaces one file, --force all of them.
|
|
10
|
+
2. Writes game-dev.json when it is missing; an existing file is never rewritten, only reported.
|
|
11
|
+
Flags fill the new file; values not given use the defaults.
|
|
12
|
+
3. Writes or replaces the marked game-dev section in AGENTS.md from assets/agents-section.md,
|
|
13
|
+
filled from game-dev.json. Text outside the markers is never changed.
|
|
14
|
+
4. Creates the Claude Code adapter that imports AGENTS.md when it is missing; an existing one
|
|
15
|
+
without the import is reported as a conflict and never edited (merge the import by hand).
|
|
16
|
+
Prints one line per action: add / update / keep / skip / conflict.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import filecmp
|
|
21
|
+
import json
|
|
22
|
+
import re
|
|
23
|
+
import shutil
|
|
24
|
+
import sys
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
HERE = Path(__file__).resolve().parent
|
|
28
|
+
ASSETS = HERE.parent / "assets"
|
|
29
|
+
sys.path.insert(0, str(HERE))
|
|
30
|
+
import gamedev_config # noqa: E402
|
|
31
|
+
|
|
32
|
+
RUNTIME = ("gamedev_config.py", "delegate.py", "balance.py", "pyramid.py", "instruction_size.py", "check.py")
|
|
33
|
+
SECTION = re.compile(r"<!-- game-dev:begin.*?<!-- game-dev:end -->\n?", re.S)
|
|
34
|
+
CLAUDE_ADAPTER = "CLAUDE" + ".md"
|
|
35
|
+
COMMIT_TEXT = {
|
|
36
|
+
"on-request": "only when the user asks; never push without an explicit request.",
|
|
37
|
+
"after-checks": "commit each finished piece once `tools/game-dev/check.py` passes, with a message that "
|
|
38
|
+
"says what changed and why; never push without an explicit request.",
|
|
39
|
+
}
|
|
40
|
+
PREVIEW_TEXT = {
|
|
41
|
+
"in-game": "the user checks results in the running game; do not build screenshot or comparison pages "
|
|
42
|
+
"unless asked.",
|
|
43
|
+
"web-page": "show visual and UI changes on a local web page (cards, before/after labels, a short numbered "
|
|
44
|
+
"list of what to check).",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def copy_runtime(root, dry, force, force_files, log):
|
|
49
|
+
target = root / "tools" / "game-dev"
|
|
50
|
+
sources = [HERE / n for n in RUNTIME] + sorted((HERE / "prompts").glob("*.md"))
|
|
51
|
+
for src in sources:
|
|
52
|
+
dst = target / src.relative_to(HERE)
|
|
53
|
+
rel = dst.relative_to(root).as_posix()
|
|
54
|
+
if not dst.exists():
|
|
55
|
+
log("add", rel)
|
|
56
|
+
elif filecmp.cmp(src, dst, shallow=False):
|
|
57
|
+
log("keep", rel)
|
|
58
|
+
continue
|
|
59
|
+
elif force or rel in force_files:
|
|
60
|
+
log("update", rel)
|
|
61
|
+
else:
|
|
62
|
+
log("conflict", f"{rel} differs from the kit copy; kept (--force-file {rel} replaces it)")
|
|
63
|
+
continue
|
|
64
|
+
if not dry:
|
|
65
|
+
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
66
|
+
shutil.copyfile(src, dst)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def new_config(args):
|
|
70
|
+
cfg = {"version": 1, "engine": args.engine, "genre": args.genre or "", "phase": args.phase,
|
|
71
|
+
"policies": {"commit": args.commit, "preview": args.preview},
|
|
72
|
+
"models": gamedev_config.DEFAULTS["models"],
|
|
73
|
+
"balance": {**gamedev_config.DEFAULTS["balance"], "source": args.balance},
|
|
74
|
+
"commands": {"test": args.test_command or "", "run": args.run_command or ""},
|
|
75
|
+
"paths": gamedev_config.DEFAULTS["paths"]}
|
|
76
|
+
problems = gamedev_config.validate(gamedev_config.merge(gamedev_config.DEFAULTS, cfg))
|
|
77
|
+
if problems:
|
|
78
|
+
raise SystemExit("install: " + "; ".join(problems))
|
|
79
|
+
return cfg
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def write_config(root, args, dry, log):
|
|
83
|
+
path = root / gamedev_config.CONFIG_NAME
|
|
84
|
+
if path.exists():
|
|
85
|
+
log("keep", f"{gamedev_config.CONFIG_NAME} exists; review it instead of rewriting")
|
|
86
|
+
return
|
|
87
|
+
log("add", gamedev_config.CONFIG_NAME)
|
|
88
|
+
if not dry:
|
|
89
|
+
path.write_text(json.dumps(new_config(args), indent=2) + "\n", encoding="utf-8")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def section_text(cfg):
|
|
93
|
+
template = (ASSETS / "agents-section.md").read_text(encoding="utf-8")
|
|
94
|
+
balance = cfg["balance"]
|
|
95
|
+
source = ("JSON checked against schemas in `" + balance["schemas"] + "`" if balance["source"] == "json"
|
|
96
|
+
else "JSON imported from the XLSX workbooks in `" + balance["workbooks"] + "`; edit the workbooks")
|
|
97
|
+
return template.format(engine=cfg["engine"], genre=cfg["genre"] or "unset", phase=cfg["phase"],
|
|
98
|
+
data=balance["data"], balance=source, commit=COMMIT_TEXT[cfg["policies"]["commit"]],
|
|
99
|
+
preview=PREVIEW_TEXT[cfg["policies"]["preview"]])
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def write_section(root, cfg, dry, log):
|
|
103
|
+
path = root / "AGENTS.md"
|
|
104
|
+
section = section_text(cfg)
|
|
105
|
+
if not path.exists():
|
|
106
|
+
text, action = f"# {root.name}\n\n{section}", "add"
|
|
107
|
+
else:
|
|
108
|
+
current = path.read_text(encoding="utf-8")
|
|
109
|
+
if SECTION.search(current):
|
|
110
|
+
text = SECTION.sub(lambda _: section, current, count=1)
|
|
111
|
+
action = "keep" if text == current else "update"
|
|
112
|
+
else:
|
|
113
|
+
text, action = current.rstrip("\n") + "\n\n" + section, "update"
|
|
114
|
+
log(action, "AGENTS.md game-dev section")
|
|
115
|
+
if action != "keep" and not dry:
|
|
116
|
+
path.write_text(text, encoding="utf-8")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def write_adapter(root, dry, log):
|
|
120
|
+
path = root / CLAUDE_ADAPTER
|
|
121
|
+
if not path.exists():
|
|
122
|
+
log("add", f"{CLAUDE_ADAPTER} (imports AGENTS.md)")
|
|
123
|
+
if not dry:
|
|
124
|
+
path.write_text("@AGENTS.md\n", encoding="utf-8")
|
|
125
|
+
elif not re.search(r"@(?:\./)?AGENTS\.md", path.read_text(encoding="utf-8")):
|
|
126
|
+
log("conflict", f"{CLAUDE_ADAPTER} does not import AGENTS.md; add the line '@AGENTS.md' or merge by hand")
|
|
127
|
+
else:
|
|
128
|
+
log("keep", CLAUDE_ADAPTER)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def main(argv=None):
|
|
132
|
+
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
133
|
+
p.add_argument("--project", required=True)
|
|
134
|
+
p.add_argument("--engine", choices=gamedev_config.ENGINES, required=True)
|
|
135
|
+
p.add_argument("--genre")
|
|
136
|
+
p.add_argument("--phase", choices=gamedev_config.PHASES, default="pre-alpha")
|
|
137
|
+
p.add_argument("--balance", choices=gamedev_config.BALANCE_SOURCES, default="json")
|
|
138
|
+
p.add_argument("--commit", choices=gamedev_config.COMMIT_POLICIES, default="on-request")
|
|
139
|
+
p.add_argument("--preview", choices=gamedev_config.PREVIEW_POLICIES, default="in-game")
|
|
140
|
+
p.add_argument("--test-command")
|
|
141
|
+
p.add_argument("--run-command")
|
|
142
|
+
p.add_argument("--dry-run", action="store_true")
|
|
143
|
+
p.add_argument("--force", action="store_true", help="replace every runtime file that differs from the kit")
|
|
144
|
+
p.add_argument("--force-file", action="append", default=[], metavar="PATH",
|
|
145
|
+
help="replace this one runtime file, e.g. tools/game-dev/pyramid.py (repeatable)")
|
|
146
|
+
args = p.parse_args(argv)
|
|
147
|
+
root = Path(args.project).resolve()
|
|
148
|
+
if not root.is_dir():
|
|
149
|
+
raise SystemExit(f"install: no such project folder: {root}")
|
|
150
|
+
actions = []
|
|
151
|
+
|
|
152
|
+
def log(action, what):
|
|
153
|
+
actions.append((action, what))
|
|
154
|
+
print(f"{action:8} {what}")
|
|
155
|
+
|
|
156
|
+
known = {f"tools/game-dev/{n}" for n in RUNTIME} | {f"tools/game-dev/prompts/{p.name}" for p in (HERE / "prompts").glob("*.md")}
|
|
157
|
+
for name in sorted(set(args.force_file) - known):
|
|
158
|
+
log("conflict", f"--force-file {name} is not a runtime file; expected one of {', '.join(sorted(known))}")
|
|
159
|
+
copy_runtime(root, args.dry_run, args.force, set(args.force_file), log)
|
|
160
|
+
write_config(root, args, args.dry_run, log)
|
|
161
|
+
existing = root / gamedev_config.CONFIG_NAME
|
|
162
|
+
cfg = (gamedev_config.load(root)[0] if existing.exists()
|
|
163
|
+
else gamedev_config.merge(gamedev_config.DEFAULTS, new_config(args)))
|
|
164
|
+
write_section(root, cfg, args.dry_run, log)
|
|
165
|
+
write_adapter(root, args.dry_run, log)
|
|
166
|
+
if args.dry_run:
|
|
167
|
+
print("dry run: nothing written")
|
|
168
|
+
return 1 if any(a == "conflict" for a, _ in actions) else 0
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
if __name__ == "__main__":
|
|
172
|
+
sys.exit(main())
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Keep AI instructions lean.
|
|
2
|
+
|
|
3
|
+
python3 tools/game-dev/instruction_size.py [--project DIR]
|
|
4
|
+
|
|
5
|
+
Limits come from game-dev.json `limits`: every file in `instruction_files` stays within
|
|
6
|
+
`max_lines`; every project skill (`.claude/skills/*/SKILL.md`, `.agents/skills/*/SKILL.md`)
|
|
7
|
+
stays within `skill_max_chars`; every skill and agent `description` stays within
|
|
8
|
+
`description_max_chars`. Turn a rule into a script check instead of growing these files.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
17
|
+
import gamedev_config # noqa: E402
|
|
18
|
+
|
|
19
|
+
DESCRIPTION = re.compile(r"^description:\s*(.+?)\s*$", re.M)
|
|
20
|
+
SKILL_GLOBS = (".claude/skills/*/SKILL.md", ".agents/skills/*/SKILL.md")
|
|
21
|
+
AGENT_GLOBS = (".claude/agents/*.md",)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def description(text):
|
|
25
|
+
if not text.startswith("---"):
|
|
26
|
+
return None
|
|
27
|
+
head = text.split("\n---", 1)[0]
|
|
28
|
+
match = DESCRIPTION.search(head)
|
|
29
|
+
return match.group(1).strip("'\"") if match else None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def measure(root, limits):
|
|
33
|
+
problems = []
|
|
34
|
+
for name in limits["instruction_files"]:
|
|
35
|
+
path = root / name
|
|
36
|
+
if path.is_file():
|
|
37
|
+
lines = len(path.read_text(encoding="utf-8").splitlines())
|
|
38
|
+
if lines > limits["max_lines"]:
|
|
39
|
+
problems.append(f"{name}: {lines} lines > {limits['max_lines']}; move detail into a skill or a script")
|
|
40
|
+
seen = set()
|
|
41
|
+
for pattern in SKILL_GLOBS + AGENT_GLOBS:
|
|
42
|
+
for path in sorted(root.glob(pattern)):
|
|
43
|
+
real = path.resolve()
|
|
44
|
+
if real in seen:
|
|
45
|
+
continue
|
|
46
|
+
seen.add(real)
|
|
47
|
+
text = path.read_text(encoding="utf-8")
|
|
48
|
+
rel = path.relative_to(root).as_posix()
|
|
49
|
+
if path.name == "SKILL.md" and len(text) > limits["skill_max_chars"]:
|
|
50
|
+
problems.append(f"{rel}: {len(text)} chars > {limits['skill_max_chars']}; split it or move "
|
|
51
|
+
"reference detail into references/")
|
|
52
|
+
desc = description(text)
|
|
53
|
+
if desc and len(desc) > limits["description_max_chars"]:
|
|
54
|
+
problems.append(f"{rel}: description {len(desc)} chars > {limits['description_max_chars']}")
|
|
55
|
+
return problems
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def main(argv=None):
|
|
59
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
60
|
+
parser.add_argument("--project")
|
|
61
|
+
args = parser.parse_args(argv)
|
|
62
|
+
try:
|
|
63
|
+
cfg, root = gamedev_config.load(args.project)
|
|
64
|
+
except gamedev_config.ConfigError as error:
|
|
65
|
+
print(f"instruction_size: {error}", file=sys.stderr)
|
|
66
|
+
return 2
|
|
67
|
+
problems = measure(root, cfg["limits"])
|
|
68
|
+
for line in problems:
|
|
69
|
+
print(line)
|
|
70
|
+
print(f"instruction_size: {len(problems)} problem(s)")
|
|
71
|
+
return 1 if problems else 0
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
if __name__ == "__main__":
|
|
75
|
+
sys.exit(main())
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Code reviewer
|
|
2
|
+
|
|
3
|
+
You are an independent reviewer of a game project's change. You did not write it and you do not
|
|
4
|
+
fix it. Judge the change against the brief, then report.
|
|
5
|
+
|
|
6
|
+
Look for, in this order:
|
|
7
|
+
|
|
8
|
+
1. Correctness: wrong behavior, broken edge cases, crashes, state that leaks between runs or scenes.
|
|
9
|
+
2. Gameplay numbers or content hard-coded in logic instead of the project's data files
|
|
10
|
+
(`balance` in game-dev.json says where data lives).
|
|
11
|
+
3. Determinism of the simulation where the project requires it: wall-clock time, unseeded random
|
|
12
|
+
numbers, frame-rate dependent logic.
|
|
13
|
+
4. Tests: a behavior change without a test at the lowest level that can catch it; tests at a
|
|
14
|
+
higher level than needed; skipped or focused tests.
|
|
15
|
+
5. Structure: code placed outside its domain module, files that mix responsibilities, dead code.
|
|
16
|
+
|
|
17
|
+
Report at most seven findings, most severe first. For each: file and line, what is wrong, a concrete
|
|
18
|
+
failure scenario, and the smallest fix. Say "no findings" when there are none. Do not praise, do not
|
|
19
|
+
restate the diff, do not propose unrelated refactors.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Image generation
|
|
2
|
+
|
|
3
|
+
You generate images for a game. Follow the prompt literally: subject, framing, palette and style
|
|
4
|
+
as written. Match attached reference images in style and palette unless the prompt says otherwise.
|
|
5
|
+
No text, logos, watermarks or signatures in the image unless the prompt asks for them.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Visual reviewer
|
|
2
|
+
|
|
3
|
+
You judge images in a fresh context: you know nothing about how they were made, and you must not
|
|
4
|
+
assume the maker's intent beyond the brief. Open every attached image before judging.
|
|
5
|
+
|
|
6
|
+
Compare the result with the reference images the brief names (concept art, an approved look).
|
|
7
|
+
Judge at the size the player will see. Check, in this order: silhouette and proportions, palette
|
|
8
|
+
and value (exact hues, no drift toward a generic look), materials and wear, readability against
|
|
9
|
+
the game's background, and anything the brief lists as must-have.
|
|
10
|
+
|
|
11
|
+
Report at most five findings, most visible first. For each: what differs, where (image and
|
|
12
|
+
region), how far off (a number when you can: percent, angle, color), and what to change. End with
|
|
13
|
+
one line: "matches", "close" or "off", relative to the reference. Do not soften findings.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Check that the project's tests form a pyramid.
|
|
2
|
+
|
|
3
|
+
python3 tools/game-dev/pyramid.py [--project DIR] [--json]
|
|
4
|
+
|
|
5
|
+
Levels come from game-dev.json `tests` (default: the engine preset). Fails when a test file
|
|
6
|
+
matches no level, a file holds a focused or skipped test (`forbidden`), or a higher level has
|
|
7
|
+
more test declarations than the level below it. The shape is judged only from 12 declarations
|
|
8
|
+
on, because a pyramid needs something to be built from.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
19
|
+
import gamedev_config # noqa: E402
|
|
20
|
+
|
|
21
|
+
SKIP_DIRS = {".git", "node_modules", "dist", "build", ".godot", ".venv", "addons", "local"}
|
|
22
|
+
MIN_TOTAL_FOR_SHAPE = 12
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def files(root):
|
|
26
|
+
for folder, dirs, names in os.walk(root):
|
|
27
|
+
dirs[:] = [d for d in dirs if d not in SKIP_DIRS and not d.startswith(".")]
|
|
28
|
+
for name in names:
|
|
29
|
+
yield (Path(folder) / name).relative_to(root).as_posix()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def measure(root, tests):
|
|
33
|
+
levels = [(lvl["name"], re.compile(lvl["pattern"])) for lvl in tests.get("levels", [])]
|
|
34
|
+
any_test = re.compile(tests["any_test"]) if tests.get("any_test") else None
|
|
35
|
+
case = re.compile(tests["case"], re.M) if tests.get("case") else None
|
|
36
|
+
forbidden = re.compile(tests["forbidden"], re.M) if tests.get("forbidden") else None
|
|
37
|
+
counts = {name: {"files": 0, "cases": 0} for name, _ in levels}
|
|
38
|
+
problems = []
|
|
39
|
+
for path in files(root):
|
|
40
|
+
level = next((name for name, rx in levels if rx.search(path)), None)
|
|
41
|
+
if level is None:
|
|
42
|
+
if any_test and any_test.search(path):
|
|
43
|
+
problems.append(f"{path}: matches no test level ({', '.join(n for n, _ in levels)})")
|
|
44
|
+
continue
|
|
45
|
+
source = (root / path).read_text(encoding="utf-8", errors="replace")
|
|
46
|
+
if forbidden and forbidden.search(source):
|
|
47
|
+
problems.append(f"{path}: holds a focused or skipped test; fix it or remove it")
|
|
48
|
+
counts[level]["files"] += 1
|
|
49
|
+
counts[level]["cases"] += len(case.findall(source)) if case else 0
|
|
50
|
+
total = sum(c["cases"] for c in counts.values())
|
|
51
|
+
names = [n for n, _ in levels]
|
|
52
|
+
if total >= MIN_TOTAL_FOR_SHAPE:
|
|
53
|
+
for lower, upper in zip(names, names[1:]):
|
|
54
|
+
if counts[upper]["cases"] > counts[lower]["cases"]:
|
|
55
|
+
problems.append(f"pyramid inverted: {counts[upper]['cases']} {upper} but only "
|
|
56
|
+
f"{counts[lower]['cases']} {lower}; move coverage down a level or add {lower} tests")
|
|
57
|
+
return counts, problems
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def main(argv=None):
|
|
61
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
62
|
+
parser.add_argument("--project")
|
|
63
|
+
parser.add_argument("--json", action="store_true")
|
|
64
|
+
args = parser.parse_args(argv)
|
|
65
|
+
try:
|
|
66
|
+
cfg, root = gamedev_config.load(args.project)
|
|
67
|
+
except gamedev_config.ConfigError as error:
|
|
68
|
+
print(f"pyramid: {error}", file=sys.stderr)
|
|
69
|
+
return 2
|
|
70
|
+
if not cfg["tests"].get("levels"):
|
|
71
|
+
print("pyramid: no test levels configured (engine 'other'); set tests.levels in game-dev.json")
|
|
72
|
+
return 0
|
|
73
|
+
counts, problems = measure(root, cfg["tests"])
|
|
74
|
+
if args.json:
|
|
75
|
+
print(json.dumps({"counts": counts, "problems": problems}, indent=1))
|
|
76
|
+
else:
|
|
77
|
+
for line in problems:
|
|
78
|
+
print(line)
|
|
79
|
+
print("test declarations: " + ", ".join(f"{n} {c['cases']}" for n, c in counts.items()))
|
|
80
|
+
return 1 if problems else 0
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
sys.exit(main())
|