spriteforge 0.1.1__py3-none-any.whl

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.
Files changed (218) hide show
  1. spriteforge/__init__.py +1 -0
  2. spriteforge/__main__.py +3 -0
  3. spriteforge/agents/__init__.py +0 -0
  4. spriteforge/agents/assets.py +109 -0
  5. spriteforge/agents/cancellation.py +12 -0
  6. spriteforge/agents/director.py +50 -0
  7. spriteforge/agents/models.py +63 -0
  8. spriteforge/agents/roles/art-director.md +15 -0
  9. spriteforge/agents/roles/art-reviewer.md +14 -0
  10. spriteforge/agents/roles/director.md +14 -0
  11. spriteforge/agents/roles/game-designer.md +15 -0
  12. spriteforge/agents/roles/level-tile-designer.md +16 -0
  13. spriteforge/agents/roles/librarian.md +13 -0
  14. spriteforge/agents/roles/menu-designer.md +15 -0
  15. spriteforge/agents/roles/pixel-artist.md +14 -0
  16. spriteforge/agents/roles/programmer.md +14 -0
  17. spriteforge/agents/roles/qa-playtester.md +13 -0
  18. spriteforge/agents/roles/sound-director.md +14 -0
  19. spriteforge/agents/roles.py +39 -0
  20. spriteforge/agents/router.py +233 -0
  21. spriteforge/agents/router_eval.py +145 -0
  22. spriteforge/agents/routing_state.py +133 -0
  23. spriteforge/agents/runtime.py +430 -0
  24. spriteforge/agents/workflow.py +389 -0
  25. spriteforge/app/__init__.py +0 -0
  26. spriteforge/app/agents_view.py +248 -0
  27. spriteforge/app/chat.py +114 -0
  28. spriteforge/app/extensions.py +115 -0
  29. spriteforge/app/index.html +279 -0
  30. spriteforge/app/local_only.py +49 -0
  31. spriteforge/app/server.py +358 -0
  32. spriteforge/app/static/assets/index-L2s1wlcp.css +1 -0
  33. spriteforge/app/static/assets/index-aBfzgLQl.js +71 -0
  34. spriteforge/app/static/assets/press-start-2p-latin-400-normal-BKfmdmKK.woff +0 -0
  35. spriteforge/app/static/assets/press-start-2p-latin-400-normal-xj9lRvVs.woff2 +0 -0
  36. spriteforge/app/static/index.html +13 -0
  37. spriteforge/app/static/press-start-2p-LICENSE.txt +93 -0
  38. spriteforge/app/studio.py +278 -0
  39. spriteforge/app/workers.py +73 -0
  40. spriteforge/cli.py +241 -0
  41. spriteforge/config.py +193 -0
  42. spriteforge/config.yaml +157 -0
  43. spriteforge/core/__init__.py +0 -0
  44. spriteforge/core/acting.py +16 -0
  45. spriteforge/core/cost.py +236 -0
  46. spriteforge/core/credentials.py +24 -0
  47. spriteforge/core/demo.py +79 -0
  48. spriteforge/core/forms.py +20 -0
  49. spriteforge/core/gates.py +175 -0
  50. spriteforge/core/security.py +42 -0
  51. spriteforge/core/state.py +222 -0
  52. spriteforge/core/team.py +15 -0
  53. spriteforge/core/usage.py +68 -0
  54. spriteforge/game/__init__.py +0 -0
  55. spriteforge/game/actors.py +377 -0
  56. spriteforge/game/agent_tools.py +178 -0
  57. spriteforge/game/art.py +2097 -0
  58. spriteforge/game/art_checks.py +190 -0
  59. spriteforge/game/art_review.py +518 -0
  60. spriteforge/game/build.py +134 -0
  61. spriteforge/game/bundle.py +1178 -0
  62. spriteforge/game/cli.py +119 -0
  63. spriteforge/game/codegen.py +433 -0
  64. spriteforge/game/codeinfo.py +154 -0
  65. spriteforge/game/dbsource.py +137 -0
  66. spriteforge/game/design.py +342 -0
  67. spriteforge/game/export.py +62 -0
  68. spriteforge/game/gamedb.py +191 -0
  69. spriteforge/game/image_cache.py +61 -0
  70. spriteforge/game/lessons.py +259 -0
  71. spriteforge/game/level_gen.py +118 -0
  72. spriteforge/game/level_preview.py +97 -0
  73. spriteforge/game/levels.py +934 -0
  74. spriteforge/game/loops.py +38 -0
  75. spriteforge/game/menus.py +712 -0
  76. spriteforge/game/mock_game.js +109 -0
  77. spriteforge/game/mock_platformer.js +58 -0
  78. spriteforge/game/motion.py +881 -0
  79. spriteforge/game/pipeline.py +1768 -0
  80. spriteforge/game/plan.py +502 -0
  81. spriteforge/game/playtest.py +318 -0
  82. spriteforge/game/qa.py +664 -0
  83. spriteforge/game/qa_checks.py +223 -0
  84. spriteforge/game/qa_runtime.py +565 -0
  85. spriteforge/game/reach.py +807 -0
  86. spriteforge/game/record.py +138 -0
  87. spriteforge/game/research.py +262 -0
  88. spriteforge/game/revision.py +225 -0
  89. spriteforge/game/sdk/API.md +104 -0
  90. spriteforge/game/sdk/FLOW.md +19 -0
  91. spriteforge/game/sdk/LEVELS.md +65 -0
  92. spriteforge/game/sdk/sf.js +418 -0
  93. spriteforge/game/sdk/sfflow.js +442 -0
  94. spriteforge/game/sdk/sflevel.js +683 -0
  95. spriteforge/game/sdk/sfsound-editor.js +225 -0
  96. spriteforge/game/sdk/sfsound.js +260 -0
  97. spriteforge/game/sdk/sounds.html +67 -0
  98. spriteforge/game/sounds.py +793 -0
  99. spriteforge/game/story.py +188 -0
  100. spriteforge/game/structure.py +98 -0
  101. spriteforge/game/team_reports.py +394 -0
  102. spriteforge/game/tilesets.py +70 -0
  103. spriteforge/game/title_art.py +186 -0
  104. spriteforge/genres/__init__.py +0 -0
  105. spriteforge/library/__init__.py +15 -0
  106. spriteforge/library/cli.py +126 -0
  107. spriteforge/library/describe.py +242 -0
  108. spriteforge/library/looks.py +154 -0
  109. spriteforge/library/models.py +79 -0
  110. spriteforge/library/store.py +422 -0
  111. spriteforge/library/tilesets/README.md +32 -0
  112. spriteforge/library/tilesets/gandalf-seasons.json +111 -0
  113. spriteforge/library/tilesets/pixel-crawler-dungeon.json +66 -0
  114. spriteforge/mcp/__init__.py +0 -0
  115. spriteforge/mcp/cli.py +58 -0
  116. spriteforge/mcp/client.py +57 -0
  117. spriteforge/mcp/filesystem_read.py +32 -0
  118. spriteforge/mcp/gamedb.py +56 -0
  119. spriteforge/mcp/library.py +179 -0
  120. spriteforge/mcp/memory.py +37 -0
  121. spriteforge/mcp/pixel_tools.py +145 -0
  122. spriteforge/mcp/registry.py +145 -0
  123. spriteforge/mcp/service.py +224 -0
  124. spriteforge/mcp/templates/context7.json +6 -0
  125. spriteforge/mcp/templates/fetch.json +6 -0
  126. spriteforge/mcp/templates/filesystem-read.json +6 -0
  127. spriteforge/mcp/templates/pixel-tools.json +6 -0
  128. spriteforge/memory/README.md +10 -0
  129. spriteforge/memory/__init__.py +0 -0
  130. spriteforge/memory/cli.py +131 -0
  131. spriteforge/memory/okf/__init__.py +1 -0
  132. spriteforge/memory/okf/catalog.py +331 -0
  133. spriteforge/memory/okf/codec.py +63 -0
  134. spriteforge/memory/okf/git.py +104 -0
  135. spriteforge/memory/okf/indexes.py +50 -0
  136. spriteforge/memory/okf/models.py +114 -0
  137. spriteforge/memory/okf/search.py +53 -0
  138. spriteforge/memory/okf/seed.py +81 -0
  139. spriteforge/memory/okf/seeds/genres.yaml +121 -0
  140. spriteforge/memory/okf/seeds/other.yaml +150 -0
  141. spriteforge/memory/okf/store.py +402 -0
  142. spriteforge/memory/okf/validate.py +115 -0
  143. spriteforge/pixel/__init__.py +17 -0
  144. spriteforge/pixel/atlas.py +110 -0
  145. spriteforge/pixel/grid.py +174 -0
  146. spriteforge/pixel/palette.py +156 -0
  147. spriteforge/pixel/palettes/dungeon.json +9 -0
  148. spriteforge/pixel/postprocess.py +170 -0
  149. spriteforge/pixel/preview.py +40 -0
  150. spriteforge/pixel/schemas.py +139 -0
  151. spriteforge/pixel/source.py +237 -0
  152. spriteforge/pixel/terrain.py +48 -0
  153. spriteforge/pixel/validate.py +138 -0
  154. spriteforge/prompts/anim_frame.txt +1 -0
  155. spriteforge/prompts/character.txt +1 -0
  156. spriteforge/prompts/item.txt +1 -0
  157. spriteforge/prompts/tile.txt +1 -0
  158. spriteforge/prompts/ui.txt +1 -0
  159. spriteforge/providers/__init__.py +0 -0
  160. spriteforge/providers/base.py +97 -0
  161. spriteforge/providers/http.py +38 -0
  162. spriteforge/providers/mock.py +111 -0
  163. spriteforge/providers/muse_image.py +60 -0
  164. spriteforge/providers/muse_search.py +91 -0
  165. spriteforge/providers/muse_spark.py +66 -0
  166. spriteforge/skills/__init__.py +0 -0
  167. spriteforge/skills/builtin/LICENSE-awesome-gamedev-agent-skills.txt +201 -0
  168. spriteforge/skills/builtin/NOTICE-awesome-gamedev-agent-skills.txt +15 -0
  169. spriteforge/skills/builtin/THIRD_PARTY.md +21 -0
  170. spriteforge/skills/builtin/audio-design/SKILL.md +190 -0
  171. spriteforge/skills/builtin/game-feel/SKILL.md +174 -0
  172. spriteforge/skills/builtin/game-ui-ux/SKILL.md +167 -0
  173. spriteforge/skills/builtin/level-design/SKILL.md +169 -0
  174. spriteforge/skills/builtin/phaser-arcade-physics/SKILL.md +17 -0
  175. spriteforge/skills/builtin/physics-tuning/SKILL.md +164 -0
  176. spriteforge/skills/builtin/pixel-art-prompting/SKILL.md +12 -0
  177. spriteforge/skills/builtin/platformer/SKILL.md +153 -0
  178. spriteforge/skills/builtin/puzzle/SKILL.md +143 -0
  179. spriteforge/skills/builtin/sprite-animation-frames/SKILL.md +11 -0
  180. spriteforge/skills/builtin/tileset-design/SKILL.md +10 -0
  181. spriteforge/skills/catalog.py +200 -0
  182. spriteforge/skills/cli.py +41 -0
  183. spriteforge/stages/__init__.py +0 -0
  184. spriteforge/stages/asset_context.py +301 -0
  185. spriteforge/stages/asset_models.py +192 -0
  186. spriteforge/stages/asset_render.py +366 -0
  187. spriteforge/stages/asset_review.py +140 -0
  188. spriteforge/stages/asset_store.py +94 -0
  189. spriteforge/stages/chat_changes.py +236 -0
  190. spriteforge/stages/concept.py +42 -0
  191. spriteforge/stages/game.py +1699 -0
  192. spriteforge/stages/game_confirm.py +112 -0
  193. spriteforge/stages/game_final.py +220 -0
  194. spriteforge/stages/game_record.py +246 -0
  195. spriteforge/stages/gameplay.py +218 -0
  196. spriteforge/stages/intake.py +372 -0
  197. spriteforge/stages/preview_assets.py +212 -0
  198. spriteforge/stages/preview_models.py +167 -0
  199. spriteforge/stages/preview_render.py +169 -0
  200. spriteforge/stages/preview_repair.py +61 -0
  201. spriteforge/stages/preview_review.py +169 -0
  202. spriteforge/stages/production.py +170 -0
  203. spriteforge/stages/references.py +105 -0
  204. spriteforge/stages/rewind.py +128 -0
  205. spriteforge/stages/workflow.py +440 -0
  206. spriteforge/templates/phaser/audit.js +45 -0
  207. spriteforge/templates/phaser/font.png +0 -0
  208. spriteforge/templates/phaser/font.xml +1 -0
  209. spriteforge/templates/phaser/preview.html +9 -0
  210. spriteforge/templates/phaser/room.js +49 -0
  211. spriteforge/templates/phaser/vendor/LICENSE.md +20 -0
  212. spriteforge/templates/phaser/vendor/phaser.min.js +1 -0
  213. spriteforge-0.1.1.dist-info/METADATA +364 -0
  214. spriteforge-0.1.1.dist-info/RECORD +218 -0
  215. spriteforge-0.1.1.dist-info/WHEEL +5 -0
  216. spriteforge-0.1.1.dist-info/entry_points.txt +2 -0
  217. spriteforge-0.1.1.dist-info/licenses/LICENSE +27 -0
  218. spriteforge-0.1.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,223 @@
1
+ """Code checks (L2.8): the QA Playtester writes its own checks of this game, as code.
2
+
3
+ Any game can be asked for, so no fixed list of steps or bot can know what a game must do. After
4
+ the Programmer's first answer, the QA Playtester reads the design (what the game must do) and
5
+ the code (where things live: scenes, sprite groups, arrays, functions) and writes 3-8 checks of
6
+ this game's own scenarios: "an enemy dies only when a hero bullet touches it", "enemy bullets
7
+ fly until they leave the screen", "standing on a platform never hurts the hero". Each check is
8
+ a JavaScript function body run inside the game's page with one helper, `qa` (qa_runtime): it
9
+ sets a scene up (moves the player, waits, holds keys), lets game time run and asserts with
10
+ `qa.expect`. A failed expect goes to the Programmer like a failed QA test; an exception in the
11
+ check itself is the QA Playtester's mistake: it gets the error once to fix the check, and a
12
+ check still broken is shown at G4 and never blamed on the game.
13
+
14
+ Models propose; code enforces: every check is parsed (`node --check`), limited in size and
15
+ checked for forbidden calls (no network, storage, eval, timers, page navigation, changes to the
16
+ SDK, and no faking outcomes with sf.event or the level engine's open/take/drop) before it runs;
17
+ the browser page is the sandbox and the check has a game-time and a wall-clock limit.
18
+ """
19
+
20
+ import re
21
+
22
+ from pydantic import Field, model_validator
23
+
24
+ from spriteforge.agents.models import Contract
25
+
26
+ from .codegen import GameCode, strip_comments, syntax_errors
27
+ from .design import GameDesign
28
+ from .qa_runtime import CHECK_SECONDS
29
+
30
+ MAX_CHECKS, MIN_CHECKS, MAX_CODE = 8, 1, 4000
31
+ CODE_BUDGET = 30000 # characters of the game's code shown to the QA Playtester
32
+ FORBIDDEN = [
33
+ (r"\bfetch\s*\(|XMLHttpRequest|WebSocket|EventSource|sendBeacon", "network calls"),
34
+ (r"\beval\s*\(|\bFunction\s*\(|\bimport\s*\(|\brequire\s*\(", "eval, Function, import or require"),
35
+ (r"(?m)^\s*(import|export)\s", "module import/export"),
36
+ (r"https?://|//[a-z0-9.-]+\.[a-z]{2,}/", "URLs"),
37
+ (r"localStorage|sessionStorage|indexedDB|document\.cookie", "browser storage"),
38
+ (r"\bwindow\.open\b|\blocation\s*(\.\s*(href|assign|replace|reload)\b|=)|\bhistory\.", "page navigation"),
39
+ (r"\bset(Timeout|Interval)\s*\(|requestAnimationFrame|\bWorker\s*\(|postMessage|\bawait\b|\bPromise\b",
40
+ "timers, workers or async code (use qa.step for time)"),
41
+ (r"document\.write|\.innerHTML\s*=", "rewriting the page"),
42
+ (r"\bsf\s*\.\s*(event|fx|start|choose|input|flow|level\s*\.\s*(open|take|drop|form|respawn))\s*\(",
43
+ ("calling the SDK to make things happen (sf.event, sf.level.open ...): a check plays the "
44
+ "game, it never fakes an outcome")),
45
+ (r"\bsf\s*\.\s*[A-Za-z_]+\s*=(?!=)|\bwindow\s*\.\s*(sf|sfRun|sfShot|sfCapture)\s*=", "changing the SDK"),
46
+ ] # fmt: skip
47
+
48
+
49
+ def need(ok: bool, message: str) -> None:
50
+ if not ok:
51
+ raise ValueError(message)
52
+
53
+
54
+ class CodeCheck(Contract):
55
+ name: str = Field(description="short unique name, e.g. 'enemies die only from hero bullets'")
56
+ purpose: str = Field(description="the rule of this game it proves, in one sentence")
57
+ god: bool = Field(description="true: the player is hurt but never dies (most checks); false "
58
+ "only for a check of losing")
59
+ start: str = Field(description="'play' (the check starts in play, in `level`) or 'title'")
60
+ level: int = Field(description="the level the check starts in (1 = the first)")
61
+ code: str = Field(description="the JavaScript function body (see the task): sets up, steps "
62
+ "game time with qa, asserts with qa.expect")
63
+
64
+ @model_validator(mode="after")
65
+ def check(self):
66
+ self.name, self.purpose = self.name.strip()[:60], self.purpose.strip()[:240]
67
+ need(bool(self.name), "a check needs a name")
68
+ self.start = "title" if self.start.strip().lower() == "title" else "play"
69
+ self.level = max(1, min(8, self.level))
70
+ need(0 < len(self.code.strip()) <= MAX_CODE, f"check {self.name!r}: code must be 1-{MAX_CODE} characters")
71
+ return self
72
+
73
+
74
+ class CodeChecks(Contract):
75
+ checks: list[CodeCheck]
76
+
77
+ @model_validator(mode="after")
78
+ def check(self):
79
+ need(MIN_CHECKS <= len(self.checks) <= MAX_CHECKS, f"write {MIN_CHECKS} to {MAX_CHECKS} checks")
80
+ names = [c.name.casefold() for c in self.checks]
81
+ need(len(set(names)) == len(names), "check names must be unique")
82
+ return self
83
+
84
+
85
+ def check_problems(check: CodeCheck) -> list[str]:
86
+ """Why a check may not run: a forbidden call, a syntax error."""
87
+ bare = strip_comments(check.code)
88
+ out = [f"check '{check.name}' uses {why}" for pattern, why in FORBIDDEN if re.search(pattern, bare)]
89
+ wrapped = "(function (qa, sf) {\n" + check.code + "\n});\n"
90
+ out += [f"check '{check.name}': " + e.split(": ", 1)[-1] for e in syntax_errors({"check.js": wrapped})]
91
+ return out
92
+
93
+
94
+ def usable(checks: CodeChecks) -> tuple[list[CodeCheck], list[str]]:
95
+ """The checks that may run, and why the others were left out."""
96
+ kept, notes = [], []
97
+ for c in checks.checks:
98
+ problems = check_problems(c)
99
+ if problems:
100
+ notes += problems
101
+ else:
102
+ kept.append(c)
103
+ return kept, notes
104
+
105
+
106
+ # --- the prompt ------------------------------------------------------------------------------------
107
+
108
+ QA_API = f"""The check is the body of `function (qa, sf) {{ ... }}`, run synchronously inside the
109
+ running game (the game is paused between frames; only qa.step moves time). `sf` is the SDK
110
+ (read it, never change it): sf.state (hp, x, y, time, level, score ...), sf.counts[name].count,
111
+ sf.level.current (levels as data: .player, .list of things {{id, kind, entity, open, sprite}},
112
+ .tile pixels per tile, .grounded) and the scene's own objects (qa.scene()).
113
+ qa:
114
+ * qa.step(seconds) / qa.frames(n): let game time run (at most {CHECK_SECONDS} s per check)
115
+ * qa.hold(keys, seconds), qa.press(key), qa.down(key), qa.up(key): key presses the game reads
116
+ like real keys; keys: left right up down w a s d space z x c j k shift enter escape
117
+ * qa.scene(): the game's scene object (its fields, groups and arrays: read them); qa.camera():
118
+ {{x, y, width, height}} of the view; qa.onScreen(obj, margin)
119
+ * qa.sprites(texture): live sprites/images, all or of one texture key (string or RegExp):
120
+ [{{key, x, y, visible, alpha, active, w, h, vx, vy, flipX, rotation, obj}}]
121
+ * qa.state(), qa.count(event), qa.events(), qa.errors(), qa.time(), qa.level()
122
+ * qa.expect(condition, message): fails the check with the message (say what was seen)
123
+ * qa.log(...): notes shown with the result; qa.near(a, b, pixels)
124
+ You may move things to set a scene up (e.g. put the player next to an enemy:
125
+ `p.x = e.x - 3 * T; p.body.reset(p.x, p.y)`) and read any object, but never make an outcome
126
+ happen yourself (no sf.event, no killing or opening things from the check): the game must
127
+ do it while time runs. No timers, async code, network, storage or page changes."""
128
+
129
+ EXAMPLE = """// Example (another game): coins are collected only when the player touches them.
130
+ const s = qa.scene(), L = qa.level(), T = L ? L.tile : 32;
131
+ const coins = qa.sprites('coin');
132
+ qa.expect(coins.length > 0, 'no coin sprites in level 1');
133
+ const before = qa.state().score || 0;
134
+ qa.step(2); // standing still far away
135
+ qa.expect((qa.state().score || 0) === before, 'score rose with nothing collected');
136
+ const c = coins[0].obj, p = L.player;
137
+ p.body.reset(c.x - 2 * T, c.y); // set the scene up: two tiles left of a coin
138
+ qa.hold('right', 1.5); // walk into it with real keys
139
+ qa.expect(!c.active || !c.visible, 'the coin is still there after walking into it');
140
+ qa.expect((qa.state().score || 0) > before, 'score did not rise after taking a coin');"""
141
+
142
+
143
+ def code_text(code: GameCode, budget: int = CODE_BUDGET) -> str:
144
+ """The game's files for the QA Playtester, cut to `budget` characters (each file shortened
145
+ in proportion)."""
146
+ total = sum(len(f.content) for f in code.files) or 1
147
+ parts = []
148
+ for f in code.files:
149
+ room = max(800, int(budget * len(f.content) / total))
150
+ text = f.content if len(f.content) <= room else f.content[:room] + "\n/* ... cut ... */"
151
+ parts.append(f"--- {f.path} ---\n{text}")
152
+ return "\n".join(parts)
153
+
154
+
155
+ def check_prompt(design: GameDesign, code: GameCode, levels: str = "", asks=()) -> str:
156
+ """`asks`: checks the human suggested; each becomes one of the checks."""
157
+ asked = "".join(f"\n* {a.strip()}" for a in asks if a.strip())
158
+ asked = (f"\nThe human asked for these checks: write one check for each (named after what "
159
+ f"they asked), then add your own up to {MAX_CHECKS} in all:{asked}\n") if asked else ""
160
+ return f"""Write code checks for this game: 3 to {MAX_CHECKS} small scenario tests of its own
161
+ rules, as JavaScript that runs inside the running game.
162
+
163
+ The design is the truth: check what the design promises (how things are beaten, what hurts the
164
+ player, what projectiles do, what is collected, what changes the score, how levels end). Read
165
+ the code only to find where things live (scene fields, groups, arrays, sprite keys, functions).
166
+ The code may be wrong: when it does something the design does not promise (e.g. enemies dying
167
+ without being hit, a bullet that never goes away, a block that kills the player), write a check
168
+ that catches it. Check behaviour a player sees, each check one rule, with a message that says
169
+ what went wrong. Prefer setting a scene up (move the player next to the thing) and playing it
170
+ with real keys over long waits. Every check starts a fresh game.
171
+ {asked}
172
+ {QA_API}
173
+
174
+ {EXAMPLE}
175
+
176
+ Design:
177
+ {design.model_dump_json(indent=1)}
178
+ {("Levels (data the SDK builds):" + chr(10) + levels + chr(10)) if levels else ""}
179
+ The game's code:
180
+ {code_text(code)}"""
181
+
182
+
183
+ def repair_prompt(prompt: str, broken: list[dict], checks: list[CodeCheck]) -> str:
184
+ """The checks that failed by themselves (an exception in the check, not a failed expect)."""
185
+ by_name = {c.name: c for c in checks}
186
+ lines = []
187
+ for r in broken:
188
+ c = by_name.get(r["name"])
189
+ lines.append(f"* '{r['name']}': {r['failure']}\n code:\n{c.code if c else '?'}")
190
+ return (prompt + "\n\nThese checks failed by themselves (their own code threw, the game was "
191
+ "not at fault). Write the whole list again: fix them using the game's real names "
192
+ "from the code; keep the other checks as they are.\n" + "\n".join(lines)) # fmt: skip
193
+
194
+
195
+ def fallback_checks(design: GameDesign) -> CodeChecks:
196
+ """The offline QA Playtester: checks every game can take."""
197
+ side = design.camera == "side-view"
198
+ return CodeChecks(checks=[
199
+ CodeCheck(name="plays without errors", god=True, start="play", level=1,
200
+ purpose="Moving and both action keys for a few seconds cause no runtime errors.",
201
+ code="qa.hold(['right'], 1.5);\nqa.press('space');\nqa.hold(['left'], 1);\n"
202
+ "qa.press('x');\nqa.step(2);\n"
203
+ "qa.expect(qa.errors().length === 0, 'runtime errors: ' + qa.errors().slice(0, 2).join(' | '));"),
204
+ CodeCheck(name="the player moves with the keys", god=True, start="play", level=1,
205
+ purpose="Holding right moves the player right." + (" (side view)" if side else ""),
206
+ code="const x0 = qa.state().x;\nqa.hold('right', 1);\n"
207
+ "qa.expect(qa.state().x > x0, 'x stayed ' + x0 + ' -> ' + qa.state().x);"),
208
+ ]) # fmt: skip
209
+
210
+
211
+ def check_failures(results: list[dict], checks: list[CodeCheck]) -> str:
212
+ """Failed checks (not broken ones), for the Programmer's repair prompt."""
213
+ failed = [r for r in results if r.get("kind") == "check" and not r["passed"] and not r.get("broken")]
214
+ if not failed:
215
+ return ""
216
+ code = {c.name: c.code for c in checks}
217
+ lines = [("QA code checks failed. The QA Playtester wrote them from the design for this game "
218
+ "and ran them in the game; fix the game (not the checks) where it breaks the rule:")]
219
+ for r in failed:
220
+ lines.append(f"* check '{r['name']}' ({r.get('purpose', '')}): {r['failure']}"
221
+ + (f". Notes: {'; '.join(r.get('logs') or [])[:300]}" if r.get("logs") else "")
222
+ + f"\n the check:\n{code.get(r['name'], '')[:1500]}") # fmt: skip
223
+ return "\n".join(lines)