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.
Files changed (56) hide show
  1. package/README.md +29 -2
  2. package/collection/bundles/game-dev/README.md +69 -0
  3. package/collection/bundles/game-dev/RECOMMENDS.md +24 -0
  4. package/collection/bundles/game-dev/agents/game-code-reviewer.md +36 -0
  5. package/collection/bundles/game-dev/agents/game-image-generator.md +34 -0
  6. package/collection/bundles/game-dev/agents/game-visual-reviewer.md +34 -0
  7. package/collection/bundles/game-dev/skills/game-code/SKILL.md +54 -0
  8. package/collection/bundles/game-dev/skills/game-code/agents/openai.yaml +4 -0
  9. package/collection/bundles/game-dev/skills/game-code/references/engine-godot.md +45 -0
  10. package/collection/bundles/game-dev/skills/game-code/references/engine-threejs.md +47 -0
  11. package/collection/bundles/game-dev/skills/game-delegation/SKILL.md +58 -0
  12. package/collection/bundles/game-dev/skills/game-delegation/agents/openai.yaml +4 -0
  13. package/collection/bundles/game-dev/skills/game-dev-setup/SKILL.md +103 -0
  14. package/collection/bundles/game-dev/skills/game-dev-setup/agents/openai.yaml +4 -0
  15. package/collection/bundles/game-dev/skills/game-dev-setup/assets/agents-section.md +20 -0
  16. package/collection/bundles/game-dev/skills/game-dev-setup/references/config.md +46 -0
  17. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/audit.py +202 -0
  18. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/balance.py +197 -0
  19. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/check.py +62 -0
  20. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/delegate.py +350 -0
  21. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/gamedev_config.py +163 -0
  22. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/install.py +172 -0
  23. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/instruction_size.py +75 -0
  24. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/prompts/code_review.md +19 -0
  25. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/prompts/image.md +5 -0
  26. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/prompts/visual_review.md +13 -0
  27. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/pyramid.py +84 -0
  28. package/collection/bundles/game-dev/skills/game-dev-setup/scripts/test_game_dev.py +309 -0
  29. package/collection/bundles/game-dev/skills/game-planning/SKILL.md +80 -0
  30. package/collection/bundles/game-dev/skills/game-planning/agents/openai.yaml +4 -0
  31. package/collection/bundles/game-dev/skills/game-testing/SKILL.md +58 -0
  32. package/collection/bundles/game-dev/skills/game-testing/agents/openai.yaml +4 -0
  33. package/collection/bundles/kit-adopt/conventions/recommended-companions.md +1 -1
  34. package/collection/skills/astro-preview/SKILL.md +97 -41
  35. package/collection/skills/astro-preview/references/manifest.md +42 -0
  36. package/collection/skills/astro-preview/scripts/portal.py +686 -0
  37. package/collection/skills/astro-preview/scripts/test_portal.py +576 -0
  38. package/collection/skills/concept-asset-builder/SKILL.md +14 -5
  39. package/collection/skills/concept-asset-builder/assets/templates/agent_brief.md +5 -2
  40. package/collection/skills/concept-asset-builder/references/field-lessons.md +9 -0
  41. package/collection/skills/concept-asset-builder/scripts/blender/render_views.py +4 -2
  42. package/collection/skills/concept-asset-builder/scripts/codex_review.sh +4 -1
  43. package/collection/skills/concept-asset-builder/scripts/godot/capture.gd +5 -2
  44. package/collection/skills/concept-asset-builder/scripts/init_workspace.sh +1 -1
  45. package/collection/skills/concept-asset-builder/scripts/measure_silhouette.py +18 -4
  46. package/collection/skills/concept-asset-builder/scripts/overlay_masks.py +25 -0
  47. package/collection/skills/concept-asset-builder/scripts/test_tools.py +44 -0
  48. package/collection/skills/concept-asset-builder/scripts/threejs/studio.js +4 -2
  49. package/collection/skills/concept-asset-builder/scripts/wear_stats.py +35 -1
  50. package/collection/skills/mixamo/SKILL.md +109 -0
  51. package/collection/skills/mixamo/agents/openai.yaml +4 -0
  52. package/collection/skills/mixamo/scripts/mixamo.py +264 -0
  53. package/collection/skills/mixamo/scripts/test_mixamo.py +108 -0
  54. package/collection/skills/sfx-creator/SKILL.md +160 -0
  55. package/collection/skills/sfx-creator/agents/openai.yaml +4 -0
  56. package/package.json +1 -1
@@ -0,0 +1,576 @@
1
+ """Tests for portal.py: python3 -m unittest discover -s <skills dir>/astro-preview/scripts"""
2
+ import json
3
+ import os
4
+ import shutil
5
+ import stat
6
+ import subprocess
7
+ import sys
8
+ import tempfile
9
+ import textwrap
10
+ import time
11
+ import unittest
12
+ from pathlib import Path
13
+
14
+ HERE = Path(__file__).resolve().parent
15
+ SCRIPT = HERE / "portal.py"
16
+ sys.path.insert(0, str(HERE))
17
+ import portal # noqa: E402
18
+
19
+ GIT_ENV = {
20
+ "GIT_AUTHOR_NAME": "t",
21
+ "GIT_AUTHOR_EMAIL": "t@example.test",
22
+ "GIT_COMMITTER_NAME": "t",
23
+ "GIT_COMMITTER_EMAIL": "t@example.test",
24
+ "GIT_CONFIG_GLOBAL": "/dev/null",
25
+ "GIT_CONFIG_SYSTEM": "/dev/null",
26
+ }
27
+
28
+ FAKE_CLAUDE = textwrap.dedent(
29
+ """\
30
+ #!/usr/bin/env python3
31
+ import json, os, subprocess, sys
32
+ from pathlib import Path
33
+ Path(os.environ["FAKE_LOG"]).write_text(json.dumps({"argv": sys.argv[1:], "cwd": os.getcwd()}))
34
+ wiki = Path("docs/wiki")
35
+ (wiki / "01-idea.md").write_text("# Idea\\n\\nDefend the castle with towers.\\n")
36
+ (wiki / "10-new.md").write_text("# New page\\n")
37
+ if os.environ.get("FAKE_OUTSIDE"):
38
+ Path("src.txt").write_text("agent edit outside the wiki")
39
+ if os.environ.get("FAKE_SYMLINK"):
40
+ os.symlink(os.environ["FAKE_SYMLINK"], wiki / "11-link.md")
41
+ if os.environ.get("FAKE_DELETE"):
42
+ (wiki / os.environ["FAKE_DELETE"]).unlink()
43
+ if os.environ.get("FAKE_STATE"):
44
+ (wiki / ".state.json").write_text('{"commit": "0000000"}')
45
+ root = os.environ.get("FAKE_ROOT")
46
+ if os.environ.get("FAKE_COMMIT_WIKI"):
47
+ Path(root, "docs/wiki/03-mechanics.md").write_text("# Core Mechanics\\n\\nUser commit during the run.\\n")
48
+ subprocess.run(["git", "-C", root, "commit", "-qam", "user wiki commit"], check=True)
49
+ if os.environ.get("FAKE_CHECKOUT"):
50
+ subprocess.run(["git", "-C", root, "checkout", "-qb", os.environ["FAKE_CHECKOUT"]], check=True)
51
+ if os.environ.get("FAKE_LOCK_INDEX"):
52
+ Path(root, ".git", "index.lock").write_text("")
53
+ if os.environ.get("FAKE_DIRTY"):
54
+ Path(os.environ["FAKE_DIRTY"]).write_text("user edit while the agent ran")
55
+ sys.exit(int(os.environ.get("FAKE_EXIT", "0")))
56
+ """
57
+ )
58
+
59
+
60
+ class Project(unittest.TestCase):
61
+ """A git repository on main with one commit, optionally initialised by the skill."""
62
+
63
+ def setUp(self):
64
+ self.tmp = Path(tempfile.mkdtemp(prefix="astro-portal-"))
65
+ self.root = self.tmp / "game"
66
+ self.root.mkdir()
67
+ self.env = {**os.environ, **GIT_ENV}
68
+ for key in ("ASTRO_WIKI_HOOK", "ROADMAP_HOOK"):
69
+ self.env.pop(key, None)
70
+ self.git("init", "-q", "-b", "main")
71
+ (self.root / "README.md").write_text("# Tiny game\n")
72
+ (self.root / "src.txt").write_text("v1\n")
73
+ self.git("add", "-A")
74
+ self.git("commit", "-qm", "init")
75
+ fake = self.tmp / "claude"
76
+ fake.write_text(FAKE_CLAUDE)
77
+ fake.chmod(fake.stat().st_mode | stat.S_IEXEC)
78
+ self.log = self.tmp / "claude.json"
79
+ self.env.update({"ASTRO_CLAUDE": str(fake), "FAKE_LOG": str(self.log)})
80
+
81
+ def tearDown(self):
82
+ subprocess.run(["rm", "-rf", str(self.tmp)], check=False)
83
+
84
+ def git(self, *args):
85
+ return subprocess.run(["git", *args], cwd=self.root, env=getattr(self, "env", {**os.environ, **GIT_ENV}),
86
+ check=True, capture_output=True, text=True).stdout.strip()
87
+
88
+ def run_portal(self, *args, env=None, check=True):
89
+ result = subprocess.run([sys.executable, str(SCRIPT), *args, "--project", str(self.root)],
90
+ cwd=self.root, env={**self.env, **(env or {})}, capture_output=True, text=True)
91
+ if check and result.returncode:
92
+ raise AssertionError(f"portal.py {' '.join(args)} failed: {result.stdout}{result.stderr}")
93
+ return result
94
+
95
+ def manifest(self):
96
+ return json.loads((self.root / ".astro" / "portal.json").read_text())
97
+
98
+ def init_and_commit(self, kind="game"):
99
+ self.run_portal("init", "--type", kind)
100
+ self.git("add", "-A")
101
+ self.git("commit", "-qm", "portal")
102
+
103
+
104
+ class Init(Project):
105
+ def test_creates_manifest_and_game_pages(self):
106
+ self.run_portal("init", "--type", "game", "--sounds", "assets/audio,sfx", "--run", "npm run play")
107
+ self.assertEqual(self.manifest(), {
108
+ "version": 1, "type": "game", "wiki": "docs/wiki", "sounds": ["assets/audio", "sfx"],
109
+ "run": "npm run play", "autoUpdate": True, "model": "claude-sonnet-5-5", "effort": "medium"})
110
+ pages = sorted(p.name for p in (self.root / "docs" / "wiki").glob("*.md"))
111
+ self.assertEqual(pages[:3], ["01-idea.md", "02-concepts.md", "03-mechanics.md"])
112
+ self.assertIn("04-game-loop.md", pages)
113
+ self.assertTrue((self.root / "docs/wiki/01-idea.md").read_text().startswith("# Idea\n"))
114
+
115
+ def test_app_template_has_app_sections(self):
116
+ self.run_portal("init", "--type", "app")
117
+ pages = sorted(p.name for p in (self.root / "docs" / "wiki").glob("*.md"))
118
+ self.assertIn("04-user-flows.md", pages)
119
+ self.assertNotIn("03-mechanics.md", pages)
120
+
121
+ def test_never_overwrites(self):
122
+ (self.root / ".astro").mkdir()
123
+ (self.root / ".astro" / "portal.json").write_text('{"type": "app", "custom": 1}')
124
+ (self.root / "docs" / "wiki").mkdir(parents=True)
125
+ (self.root / "docs/wiki/01-idea.md").write_text("mine")
126
+ self.run_portal("init", "--type", "game")
127
+ self.assertEqual(self.manifest(), {"type": "app", "custom": 1})
128
+ self.assertEqual((self.root / "docs/wiki/01-idea.md").read_text(), "mine")
129
+
130
+ def test_rejects_unknown_type_and_bad_paths(self):
131
+ self.assertNotEqual(self.run_portal("init", "--type", "film", check=False).returncode, 0)
132
+ self.assertNotEqual(self.run_portal("init", "--type", "game", "--wiki", "../x", check=False).returncode, 0)
133
+ self.assertNotEqual(self.run_portal("init", "--type", "game", "--sounds", "a,.hidden", check=False).returncode, 0)
134
+ self.assertNotEqual(self.run_portal("init", "--type", "game", "--run", "a\nb", check=False).returncode, 0)
135
+ self.assertFalse((self.root / ".astro").exists())
136
+
137
+
138
+ class ManifestParity(unittest.TestCase):
139
+ """portal.py rejects what Astro Preview's reader (shared/portal.ts parseManifest) rejects."""
140
+
141
+ def check(self, raw):
142
+ root = Path(tempfile.mkdtemp(prefix="astro-manifest-"))
143
+ try:
144
+ (root / ".astro").mkdir()
145
+ (root / ".astro" / "portal.json").write_text(json.dumps(raw))
146
+ return portal.load_manifest(root)
147
+ finally:
148
+ subprocess.run(["rm", "-rf", str(root)], check=False)
149
+
150
+ def test_rejections(self):
151
+ for raw in ({"type": "film"}, {"type": "game", "wiki": "../x"}, {"type": "game", "run": "a\nb"},
152
+ {"type": "game", "run": "x" * 501}, {"type": "game", "sounds": [f"s{i}" for i in range(17)]},
153
+ {"type": "game", "autoUpdate": "yes"}, {"type": "game", "model": "Bad Model"},
154
+ {"type": "game", "effort": "max"}, {"type": "game", "version": 2}):
155
+ with self.assertRaises(portal.PortalError, msg=raw):
156
+ self.check(raw)
157
+
158
+ def test_defaults(self):
159
+ self.assertEqual(self.check({"type": "game"}), {
160
+ "version": 1, "type": "game", "wiki": "docs/wiki", "sounds": [], "autoUpdate": True,
161
+ "model": "claude-sonnet-5-5", "effort": "medium"})
162
+
163
+
164
+ class Toggle(Project):
165
+ def test_disable_and_enable_keep_other_keys(self):
166
+ self.run_portal("init", "--type", "game")
167
+ data = self.manifest()
168
+ data["custom"] = "kept"
169
+ (self.root / ".astro/portal.json").write_text(json.dumps(data))
170
+ self.run_portal("disable")
171
+ self.assertEqual(self.manifest()["autoUpdate"], False)
172
+ self.assertEqual(self.manifest()["custom"], "kept")
173
+ self.run_portal("enable")
174
+ self.assertEqual(self.manifest()["autoUpdate"], True)
175
+
176
+
177
+ class Subfolder(Project):
178
+ def test_a_project_in_a_repository_subfolder_keeps_its_portal_there(self):
179
+ game = self.root / "game"
180
+ game.mkdir()
181
+ (game / "main.txt").write_text("v1\n")
182
+ self.git("add", "-A")
183
+ self.git("commit", "-qm", "game folder")
184
+ subprocess.run([sys.executable, str(SCRIPT), "init", "--type", "game", "--project", str(game)],
185
+ env=self.env, check=True, capture_output=True)
186
+ self.assertTrue((game / ".astro" / "portal.json").is_file())
187
+ self.assertFalse((self.root / ".astro").exists())
188
+ self.git("add", "-A")
189
+ self.git("commit", "-qm", "portal")
190
+ subprocess.run([sys.executable, str(SCRIPT), "update", "--project", str(game / "docs")], env=self.env,
191
+ check=True, capture_output=True, cwd=game)
192
+ call = json.loads(self.log.read_text())
193
+ self.assertTrue(call["cwd"].endswith("/game"))
194
+ self.assertEqual(sorted(self.git("show", "--name-only", "--format=", "HEAD").split()),
195
+ ["game/docs/wiki/.state.json", "game/docs/wiki/01-idea.md", "game/docs/wiki/10-new.md"])
196
+
197
+
198
+ class SharedRepository(Project):
199
+ def test_two_projects_in_one_repository_keep_their_own_hooks(self):
200
+ a, b = self.root.resolve() / "a", self.root.resolve() / "b"
201
+ for folder in (a, b):
202
+ folder.mkdir()
203
+ subprocess.run([sys.executable, str(SCRIPT), "init", "--type", "app", "--project", str(folder)],
204
+ env=self.env, check=True, capture_output=True)
205
+ for folder in (a, b):
206
+ subprocess.run([sys.executable, str(SCRIPT), "hook", "install", "--project", str(folder)],
207
+ env=self.env, check=True, capture_output=True)
208
+ text = (self.root / ".git" / "hooks" / "post-commit").read_text()
209
+ self.assertIn(f"--project '{a}'", text)
210
+ self.assertIn(f"--project '{b}'", text)
211
+ self.assertTrue(portal.hook_installed(a) and portal.hook_installed(b))
212
+ self.assertNotEqual(portal.lock_path(a), portal.lock_path(b))
213
+ subprocess.run([sys.executable, str(SCRIPT), "hook", "remove", "--project", str(a)], env=self.env,
214
+ check=True, capture_output=True)
215
+ self.assertFalse(portal.hook_installed(a))
216
+ self.assertTrue(portal.hook_installed(b))
217
+
218
+
219
+ class Hooks(Project):
220
+ def hook(self, name):
221
+ return (self.root / ".git" / "hooks" / name).read_text()
222
+
223
+ def test_install_is_idempotent_and_keeps_existing_hooks(self):
224
+ existing = self.root / ".git" / "hooks" / "post-commit"
225
+ existing.write_text("#!/bin/sh\necho roadmap\n")
226
+ self.run_portal("hook", "install")
227
+ self.run_portal("hook", "install")
228
+ for name in ("post-commit", "post-merge"):
229
+ text = self.hook(name)
230
+ self.assertEqual(text.count(portal.HOOK_BEGIN), 1, name)
231
+ self.assertIn("--hook --background", text)
232
+ self.assertTrue(os.access(self.root / ".git" / "hooks" / name, os.X_OK))
233
+ self.assertIn("echo roadmap", self.hook("post-commit"))
234
+ self.run_portal("hook", "remove")
235
+ self.assertEqual(self.hook("post-commit"), "#!/bin/sh\necho roadmap\n")
236
+ self.assertFalse((self.root / ".git" / "hooks" / "post-merge").exists())
237
+
238
+ def test_refuses_hook_managers_and_non_shell_hooks_unless_forced(self):
239
+ self.git("config", "core.hooksPath", ".husky")
240
+ result = self.run_portal("hook", "install", check=False)
241
+ self.assertNotEqual(result.returncode, 0)
242
+ self.assertIn("core.hooksPath", result.stderr)
243
+ self.assertIn("--hook --background", result.stderr)
244
+ self.assertFalse((self.root / ".husky").exists())
245
+ self.git("config", "--unset", "core.hooksPath")
246
+ node = self.root / ".git" / "hooks" / "post-merge"
247
+ node.write_text("#!/usr/bin/env node\nconsole.log(1)\n")
248
+ self.assertNotEqual(self.run_portal("hook", "install", check=False).returncode, 0)
249
+ self.assertEqual(node.read_text(), "#!/usr/bin/env node\nconsole.log(1)\n")
250
+
251
+ def test_the_hook_names_the_project_folder(self):
252
+ self.run_portal("hook", "install")
253
+ self.assertIn(f"--project '{self.root.resolve()}'", self.hook("post-commit"))
254
+
255
+ def test_remove_keeps_text_around_the_block(self):
256
+ self.run_portal("hook", "install")
257
+ path = self.root / ".git" / "hooks" / "post-commit"
258
+ path.write_text(path.read_text() + "echo after\n")
259
+ self.run_portal("hook", "remove")
260
+ self.assertEqual(path.read_text(), "#!/bin/sh\necho after\n")
261
+
262
+ def test_commits_still_succeed_when_the_hook_cannot_run(self):
263
+ self.run_portal("hook", "install")
264
+ (self.root / ".astro").mkdir()
265
+ (self.root / ".astro" / "portal.json").write_text("{ broken")
266
+ (self.root / "src.txt").write_text("v2\n")
267
+ self.git("add", "-A")
268
+ self.git("commit", "-qm", "with a broken manifest")
269
+ self.assertEqual(self.git("log", "-1", "--format=%s"), "with a broken manifest")
270
+ self.assertFalse(self.log.exists())
271
+
272
+
273
+ class Update(Project):
274
+ def setUp(self):
275
+ super().setUp()
276
+ self.init_and_commit()
277
+
278
+ def test_updates_in_a_snapshot_and_commits_only_the_wiki(self):
279
+ (self.root / "staged.txt").write_text("user work")
280
+ self.git("add", "staged.txt")
281
+ (self.root / "src.txt").write_text("unstaged user edit\n")
282
+ head = self.git("rev-parse", "HEAD")
283
+ self.run_portal("update")
284
+ call = json.loads(self.log.read_text())
285
+ self.assertNotEqual(Path(call["cwd"]).resolve(), self.root.resolve())
286
+ argv = call["argv"]
287
+ self.assertEqual(argv[0], "-p")
288
+ self.assertEqual(argv[argv.index("--model") + 1], "claude-sonnet-5-5")
289
+ self.assertEqual(argv[argv.index("--effort") + 1], "medium")
290
+ allowed = argv[argv.index("--allowedTools") + 1:]
291
+ self.assertIn("Edit(docs/wiki/**)", allowed)
292
+ self.assertFalse(any(tool.startswith("Write(") for tool in allowed), "the CLI accepts only Edit(path) rules")
293
+ self.assertNotIn("Edit", allowed)
294
+ self.assertNotIn("Bash", allowed)
295
+ self.assertEqual(self.git("log", "-1", "--format=%s"), f"Wiki: update for {head[:7]}")
296
+ self.assertEqual(sorted(self.git("show", "--name-only", "--format=", "HEAD").split()),
297
+ ["docs/wiki/.state.json", "docs/wiki/01-idea.md", "docs/wiki/10-new.md"])
298
+ state = json.loads((self.root / "docs/wiki/.state.json").read_text())
299
+ self.assertEqual(state["commit"], head)
300
+ self.assertEqual((self.root / "src.txt").read_text(), "unstaged user edit\n")
301
+ self.assertIn("A staged.txt", self.git("status", "--porcelain"))
302
+
303
+ def test_agent_edits_outside_the_wiki_are_discarded(self):
304
+ self.run_portal("update", env={"FAKE_OUTSIDE": "1"})
305
+ self.assertEqual((self.root / "src.txt").read_text(), "v1\n")
306
+ self.assertEqual(self.git("status", "--porcelain"), "")
307
+ self.assertTrue(self.git("log", "-1", "--format=%s").startswith("Wiki: update"))
308
+
309
+ def test_failed_agent_run_commits_nothing(self):
310
+ before = self.git("rev-parse", "HEAD")
311
+ result = self.run_portal("update", env={"FAKE_EXIT": "3"}, check=False)
312
+ self.assertNotEqual(result.returncode, 0)
313
+ self.assertEqual(self.git("rev-parse", "HEAD"), before)
314
+ self.assertFalse((self.root / "docs/wiki/.state.json").exists())
315
+
316
+ def test_skips_when_wiki_has_uncommitted_edits(self):
317
+ (self.root / "docs/wiki/01-idea.md").write_text("my unsaved edit")
318
+ before = self.git("rev-parse", "HEAD")
319
+ result = self.run_portal("update", check=False)
320
+ self.assertNotEqual(result.returncode, 0)
321
+ self.assertIn("uncommitted", result.stderr + result.stdout)
322
+ self.assertEqual(self.git("rev-parse", "HEAD"), before)
323
+ self.assertFalse(self.log.exists())
324
+
325
+ def test_agent_cannot_smuggle_symlinks_or_state_and_can_delete_pages(self):
326
+ secret = self.tmp / "secret.md"
327
+ secret.write_text("# Secret\n")
328
+ self.run_portal("update", env={"FAKE_SYMLINK": str(secret), "FAKE_DELETE": "02-concepts.md",
329
+ "FAKE_STATE": "1"})
330
+ wiki = self.root / "docs" / "wiki"
331
+ self.assertFalse((wiki / "11-link.md").exists())
332
+ self.assertFalse((wiki / "02-concepts.md").exists())
333
+ self.assertNotIn("docs/wiki/02-concepts.md", self.git("ls-files"))
334
+ state = json.loads((wiki / ".state.json").read_text())
335
+ self.assertEqual(state["commit"], self.git("rev-parse", "HEAD~1"))
336
+
337
+ def test_user_edits_during_the_run_win(self):
338
+ before = self.git("rev-parse", "HEAD")
339
+ page = self.root / "docs" / "wiki" / "01-idea.md"
340
+ result = self.run_portal("update", env={"FAKE_DIRTY": str(page)}, check=False)
341
+ self.assertNotEqual(result.returncode, 0)
342
+ self.assertEqual(page.read_text(), "user edit while the agent ran")
343
+ self.assertEqual(self.git("rev-parse", "HEAD"), before)
344
+ self.assertFalse((self.root / "docs/wiki/10-new.md").exists())
345
+
346
+ def test_a_held_lock_skips_and_a_stale_lock_is_reclaimed(self):
347
+ lock = portal.lock_path(self.root)
348
+ lock.write_text("123")
349
+ result = self.run_portal("update")
350
+ self.assertIn("Another wiki update is running", result.stdout)
351
+ self.assertFalse(self.log.exists())
352
+ old = time.time() - portal.LOCK_TTL - 60
353
+ os.utime(lock, (old, old))
354
+ self.run_portal("update")
355
+ self.assertTrue(self.log.exists())
356
+ self.assertFalse(lock.exists())
357
+
358
+ def test_update_without_a_manifest_fails_but_the_hook_stays_silent(self):
359
+ (self.root / ".astro" / "portal.json").write_text("{ broken")
360
+ self.assertEqual(self.run_portal("update", check=False).returncode, 1)
361
+ self.assertEqual(self.run_portal("update", "--hook", check=False).returncode, 0)
362
+ self.assertFalse(self.log.exists())
363
+
364
+ def test_a_wiki_commit_made_during_the_run_is_never_reverted(self):
365
+ result = self.run_portal("update", env={"FAKE_COMMIT_WIKI": "1", "FAKE_ROOT": str(self.root)}, check=False)
366
+ self.assertNotEqual(result.returncode, 0)
367
+ self.assertIn("committed during the update", result.stderr)
368
+ self.assertEqual(self.git("log", "-1", "--format=%s"), "user wiki commit")
369
+ self.assertIn("User commit during the run.", (self.root / "docs/wiki/03-mechanics.md").read_text())
370
+ self.assertEqual(self.git("status", "--porcelain"), "")
371
+
372
+ def test_a_branch_switch_during_the_run_commits_nothing(self):
373
+ result = self.run_portal("update", env={"FAKE_CHECKOUT": "feature", "FAKE_ROOT": str(self.root)},
374
+ check=False)
375
+ self.assertNotEqual(result.returncode, 0)
376
+ self.assertEqual(self.git("log", "-1", "--format=%s"), "portal")
377
+ self.assertEqual(self.git("status", "--porcelain"), "")
378
+
379
+ def test_an_io_failure_while_copying_rolls_back(self):
380
+ before = (self.root / "docs/wiki/01-idea.md").read_text()
381
+ real = portal.shutil.copyfile
382
+ calls = []
383
+
384
+ def failing(src, dst):
385
+ calls.append(dst)
386
+ if len(calls) == 2:
387
+ raise OSError("disk full")
388
+ return real(src, dst)
389
+
390
+ portal.shutil.copyfile = failing
391
+ cwd = os.getcwd()
392
+ saved = dict(os.environ)
393
+ try:
394
+ os.environ.update(self.env)
395
+ with self.assertRaises(OSError):
396
+ portal.update_once(self.root, portal.load_manifest(self.root), commit=True)
397
+ finally:
398
+ portal.shutil.copyfile = real
399
+ os.environ.clear()
400
+ os.environ.update(saved)
401
+ os.chdir(cwd)
402
+ self.assertEqual((self.root / "docs/wiki/01-idea.md").read_text(), before)
403
+ self.assertEqual(self.git("status", "--porcelain"), "")
404
+
405
+ def test_a_failed_commit_rolls_back_what_it_wrote(self):
406
+ before = (self.root / "docs/wiki/01-idea.md").read_text()
407
+ result = self.run_portal("update", env={"FAKE_LOCK_INDEX": "1", "FAKE_ROOT": str(self.root)}, check=False)
408
+ self.assertNotEqual(result.returncode, 0)
409
+ (self.root / ".git" / "index.lock").unlink()
410
+ self.assertEqual((self.root / "docs/wiki/01-idea.md").read_text(), before)
411
+ self.assertFalse((self.root / "docs/wiki/10-new.md").exists())
412
+ self.assertFalse((self.root / "docs/wiki/.state.json").exists())
413
+ self.assertEqual(self.git("status", "--porcelain"), "")
414
+ self.run_portal("update")
415
+ self.assertTrue(self.git("log", "-1", "--format=%s").startswith("Wiki: update"))
416
+
417
+ def test_ignored_files_and_tracked_symlinks_in_the_wiki_survive(self):
418
+ wiki = self.root / "docs" / "wiki"
419
+ (self.root / ".gitignore").write_text("docs/wiki/draft.md\n")
420
+ (wiki / "draft.md").write_text("local draft")
421
+ os.symlink("01-idea.md", wiki / "00-alias.md")
422
+ self.git("add", "-A")
423
+ self.git("commit", "-qm", "draft rules")
424
+ self.run_portal("update")
425
+ self.assertEqual((wiki / "draft.md").read_text(), "local draft")
426
+ self.assertTrue((wiki / "00-alias.md").is_symlink())
427
+ self.assertIn("docs/wiki/00-alias.md", self.git("ls-files"))
428
+
429
+ def test_full_rebuilds_an_up_to_date_wiki_from_scratch(self):
430
+ self.run_portal("update")
431
+ self.log.unlink()
432
+ self.run_portal("update", "--full")
433
+ self.assertTrue(self.log.exists())
434
+ prompt = json.loads(self.log.read_text())["argv"][1]
435
+ self.assertIn("read the README, the docs and the source tree", prompt)
436
+ self.assertEqual(self.git("log", "--format=%s").count("Wiki: update"), 2, "one full round, not three")
437
+
438
+ def test_prompt_asks_for_the_project_visuals(self):
439
+ prompt = portal.build_prompt(self.root, portal.load_manifest(self.root))
440
+ self.assertIn("![", prompt)
441
+ self.assertIn("Concepts & Art", prompt)
442
+ self.assertIn(".glb", prompt)
443
+ self.assertIn("only files that exist", prompt)
444
+
445
+ def test_up_to_date_after_an_update_until_code_changes(self):
446
+ self.run_portal("update")
447
+ self.log.unlink()
448
+ self.run_portal("update")
449
+ self.assertFalse(self.log.exists(), "nothing new outside the wiki")
450
+ (self.root / "src.txt").write_text("v2\n")
451
+ self.git("commit", "-qam", "code")
452
+ self.run_portal("update")
453
+ self.assertTrue(self.log.exists())
454
+
455
+ def test_prompt_lists_pages_sections_and_changes(self):
456
+ self.run_portal("update")
457
+ (self.root / "src.txt").write_text("v2\n")
458
+ self.git("commit", "-qam", "Add the castle gate")
459
+ prompt = portal.build_prompt(self.root, portal.load_manifest(self.root))
460
+ self.assertIn("docs/wiki/01-idea.md", prompt)
461
+ self.assertIn("Core Mechanics", prompt)
462
+ self.assertIn("Add the castle gate", prompt)
463
+ self.assertIn("English", prompt)
464
+ self.assertIn("under 8,000 characters", prompt)
465
+
466
+
467
+ class HookGuards(Project):
468
+ def setUp(self):
469
+ super().setUp()
470
+ self.init_and_commit()
471
+
472
+ def test_hook_mode_respects_auto_update_branch_and_recursion(self):
473
+ self.run_portal("disable")
474
+ self.git("commit", "-qam", "off")
475
+ self.run_portal("update", "--hook")
476
+ self.assertFalse(self.log.exists(), "autoUpdate false")
477
+ self.run_portal("enable")
478
+ self.git("commit", "-qam", "on")
479
+ self.git("checkout", "-qb", "feature")
480
+ self.run_portal("update", "--hook")
481
+ self.assertFalse(self.log.exists(), "not main")
482
+ self.git("checkout", "-q", "main")
483
+ self.run_portal("update", "--hook", env={"ASTRO_WIKI_HOOK": "1"})
484
+ self.assertFalse(self.log.exists(), "recursive call")
485
+ self.run_portal("update", "--hook")
486
+ self.assertTrue(self.log.exists())
487
+
488
+ def test_hook_mode_skips_rebases_and_detached_heads_but_runs_on_master(self):
489
+ (self.root / ".git" / "rebase-merge").mkdir()
490
+ self.run_portal("update", "--hook")
491
+ self.assertFalse(self.log.exists(), "rebase in progress")
492
+ (self.root / ".git" / "rebase-merge").rmdir()
493
+ self.git("checkout", "-q", "--detach")
494
+ self.run_portal("update", "--hook")
495
+ self.assertFalse(self.log.exists(), "detached HEAD")
496
+ self.git("checkout", "-qb", "master")
497
+ self.run_portal("update", "--hook")
498
+ self.assertTrue(self.log.exists(), "master")
499
+
500
+ def test_hook_mode_skips_worktrees(self):
501
+ other = self.tmp / "wt"
502
+ self.git("worktree", "add", "-q", "-b", "main2", str(other))
503
+ result = subprocess.run([sys.executable, str(SCRIPT), "update", "--hook", "--project", str(other)],
504
+ cwd=other, env=self.env, capture_output=True, text=True)
505
+ self.assertEqual(result.returncode, 0)
506
+ self.assertFalse(self.log.exists())
507
+
508
+ def test_installed_hook_updates_in_background_after_a_commit_on_main(self):
509
+ self.run_portal("hook", "install")
510
+ (self.root / "src.txt").write_text("v2\n")
511
+ self.git("commit", "-qam", "code")
512
+ lock = portal.lock_path(self.root)
513
+ for _ in range(150):
514
+ if self.git("log", "-1", "--format=%s").startswith("Wiki: update") and not lock.exists():
515
+ break
516
+ time.sleep(0.1)
517
+ self.assertTrue(self.git("log", "-1", "--format=%s").startswith("Wiki: update"))
518
+ self.assertEqual(self.git("log", "-2", "--format=%s").splitlines()[1], "code")
519
+ time.sleep(0.5)
520
+ log = (self.root / ".git" / "astro-wiki.log").read_text()
521
+ self.assertEqual(log.count("--- "), 1, "the wiki commit must not start another update")
522
+ self.assertEqual(self.git("log", "--format=%s").count("Wiki: update"), 1)
523
+
524
+
525
+ class Status(Project):
526
+ def test_reports_manifest_hook_and_staleness(self):
527
+ self.init_and_commit()
528
+ data = json.loads(self.run_portal("status", "--json").stdout)
529
+ self.assertEqual(data["manifest"]["type"], "game")
530
+ self.assertEqual(data["hook"], False)
531
+ self.assertIsNone(data["stale"])
532
+ self.run_portal("update")
533
+ self.assertEqual(json.loads(self.run_portal("status", "--json").stdout)["stale"], False)
534
+
535
+
536
+ class Register(unittest.TestCase):
537
+ """register finds Astro Preview's CLI through --astro-dir or ASTRO_PREVIEW_DIR, never a fixed home path."""
538
+
539
+ def setUp(self):
540
+ self.tmp = Path(tempfile.mkdtemp(prefix="astro-register-"))
541
+ self.astro = self.tmp / "astro"
542
+ (self.astro / "bin").mkdir(parents=True)
543
+ self.calls = self.tmp / "calls.json"
544
+ (self.astro / "bin" / "viewer.mjs").write_text(
545
+ "import { writeFileSync } from 'node:fs';\n"
546
+ "writeFileSync(process.env.FAKE_LOG, JSON.stringify(process.argv.slice(2)));\n")
547
+ self.project = self.tmp / "game"
548
+ self.project.mkdir()
549
+ subprocess.run(["git", "init", "-q", "-b", "main"], cwd=self.project, check=True)
550
+
551
+ def tearDown(self):
552
+ subprocess.run(["rm", "-rf", str(self.tmp)], check=False)
553
+
554
+ def register(self, *args, env=None):
555
+ base = {k: v for k, v in os.environ.items() if k != "ASTRO_PREVIEW_DIR"}
556
+ return subprocess.run([sys.executable, str(SCRIPT), "register", "--project", str(self.project), *args],
557
+ capture_output=True, text=True, env={**base, "FAKE_LOG": str(self.calls), **(env or {})})
558
+
559
+ @unittest.skipUnless(shutil.which("node"), "node is not installed")
560
+ def test_uses_the_flag_or_the_environment(self):
561
+ for args, env in ((("--astro-dir", str(self.astro), "--name", "Tiny"), None),
562
+ (("--name", "Tiny"), {"ASTRO_PREVIEW_DIR": str(self.astro)})):
563
+ self.calls.unlink(missing_ok=True)
564
+ result = self.register(*args, env=env)
565
+ self.assertEqual(result.returncode, 0, result.stderr)
566
+ self.assertEqual(json.loads(self.calls.read_text()),
567
+ ["project", "add", "Tiny", "--root", str(self.project.resolve()), "--json"])
568
+
569
+ def test_reports_a_missing_checkout(self):
570
+ result = self.register("--astro-dir", str(self.tmp / "missing"))
571
+ self.assertNotEqual(result.returncode, 0)
572
+ self.assertIn("ASTRO_PREVIEW_DIR", result.stderr)
573
+
574
+
575
+ if __name__ == "__main__":
576
+ unittest.main()
@@ -49,28 +49,28 @@ Read from the invocation; defaults in brackets.
49
49
  blender/ threejs/ studio (frozen) + the builder's code
50
50
  out/<pipeline>/<view>.png renders; reviews/; reports/; textures/
51
51
  ```
52
- 2. **No sheet yet?** Generate one with Codex image generation (`codex exec -m gpt-6.2-sol -c model_reasoning_effort=high -i <scene crop> -i <an approved sheet of the same scene>`, prompt via stdin). Ask for: the same layout and rendering style as the approved sheet, 5 labelled views at the same scale and camera height, a detail panel, palette and proportions, neutral soft studio light (not the scene's mood light), and weathering in the scene's language (name it: chips to primer with ragged edges at edges and corners, short rust drips under seams, grime only at the bottom). Look at the result before using it; regenerate if views disagree or are cropped.
52
+ 2. **No sheet yet?** Generate one with Codex image generation (`codex exec -m gpt-6.2-sol -c model_reasoning_effort=high -i <scene crop> -i <an approved sheet of the same scene>`, prompt via stdin). Ask for: the same layout and rendering style as the approved sheet, 5 labelled views at the same scale and camera height, a detail panel, palette and proportions, neutral soft studio light (not the scene's mood light), and weathering in the scene's language (name it: chips to primer with ragged edges at edges and corners, short rust drips under seams, grime only at the bottom). Look at the result before using it; regenerate if views disagree or are cropped. Then check it against the scene concept and the style file: image models like to draw wear as a regular lattice of identical patches (a building sheet drew peeling plaster as a diamond grid) — a stamped pattern the style forbids. Keep the sheet for shape, layout and colour, and name the scene concept as the reference for the wear language in the description, so neither the builder nor the reviewer copies the stamp.
53
53
  3. Cut the views: write `reference/boxes.json` ({view: [x0, y0, x1, y1]} in sheet pixels, include the whole object and a margin, exclude labels), run `python3 tools/crop.py`, LOOK at every crop.
54
54
  4. View conventions (used by every studio): azimuth 0 = front (+Z), positive toward +X; `left` = −90 (the front edge appears on the RIGHT of the image), `right` = +90, `3q` = the sheet's 3/4 (estimate the azimuth from the visible front/side width ratio: tan(az) ≈ (W/D)·(side px/front px)). Elevation: 8–15° (top surfaces barely visible); all views share one elevation unless the sheet clearly differs.
55
55
 
56
56
  ## 2. Spec from pixels (geometry is measured, never eyeballed)
57
57
 
58
- `python3 tools/measure_silhouette.py front --height <h>` (and `left`, `back`) prints mm/px, the width profile by height and the largest dark/bright components with their positions in metres. LOOK at the crop and name each component (opening, panel, window, button). Write `spec/object.json`:
58
+ `python3 tools/measure_silhouette.py front --height <h>` (and `back`, `left`, `right`) prints mm/px, the width profile by height and the largest dark/bright components with their positions in metres, already in object coordinates for that view (back mirrors x; side views report z). When only part of the height is known (a building: wall height known, roof not), measure with `--height 1` and scale by a known width. LOOK at the crop and name each component (opening, panel, window, button). Write `spec/object.json`:
59
59
  - dimensions of the body and every visible part (metres; Y up, front +Z, ground y=0, x from the centre), counts (facets, shelves, slats, screws), edge radii;
60
60
  - palette sampled from the concept (median of each paint zone, not your words);
61
61
  - `cameras`: `fov_deg` 18, `elevation_deg`, `views` azimuths, `image` [560, 1100], `fill` 0.955 (object fills 95.5% of the image height, like the crops), `target_y`; `palette.background` = the sheet background.
62
62
 
63
- Treat the spec as a draft: a contact shadow inside the silhouette shifts heights by a few cm, top surfaces add height, AI sheets disagree between views. Builders must log deviations they find (Phase 4) instead of silently following a wrong number.
63
+ Put the owner's hard numbers (overall size, floor heights, counts, "a wooden back door") in a `constraints` block of the spec, separate from measured values: they always win over the sheet, and a builder who finds the sheet disagreeing (a floor seam drawn at 3.45 m when floors are 3 m) follows the constraint and logs it, instead of guessing which to trust. Treat the measured part as a draft: a contact shadow inside the silhouette shifts heights by a few cm, top surfaces add height, AI sheets disagree between views. Builders must log deviations they find (Phase 4) instead of silently following a wrong number.
64
64
 
65
65
  ## 3. Wear description (the shared numeric target)
66
66
 
67
67
  This is the step that replaced most of the owner's corrections. Do it once per object, before any building.
68
- 1. **Calibrate the masks.** Edit `reference/zones.json` (template: `assets/templates/zones.json`, filled example `zones_example_vending.json`): horizontal `bands` in metres over the whole silhouette (every view) and `front_rects` for key parts; chip rule (`dL`, `min_L`, `max_C`, `window_m`; for light paint where chips differ by hue: `mode: "hue"`), rust rule (`mode: "dark"` for red/orange paint, `"hue"` with an orange-brown hue range for other colours), grime hue range, `exclude_emissive` for glowing windows. Run `python3 tools/wear_stats.py`, overlay the masks on the crops (chips, rust, grime in different colours) and LOOK. Expect 3–4 iterations; never trust a mask you have not overlaid. Typical traps: chips larger than the paint window vanish (use a wide chip window), light paint makes chips "not lighter", bright paint or the background read as a glowing window, louvres and highlights read as chips.
68
+ 1. **Calibrate the masks.** Edit `reference/zones.json` (template: `assets/templates/zones.json`, filled example `zones_example_vending.json`): horizontal `bands` in metres over the whole silhouette (every view) and `front_rects` for key parts; chip rule (`dL`, `min_L`, `max_C`, `window_m`; for light paint where chips differ by hue: `mode: "hue"`), rust rule (`mode: "dark"` for red/orange paint, `"hue"` with an orange-brown hue range for other colours), grime hue range, `exclude_emissive` for glowing windows, `exclude_rects` per view for areas that are not surface (glazing with goods behind it, signs). For wear that is DARKER than the surface (peeling plaster or paint over a darker layer) use chip `mode: "dark"`: it compares with a high percentile (`ref_pct`, 80) of the wall in a wide window (`window_m` ~1 m), because a median is dragged down when a third of the wall is peeled. Run `python3 tools/wear_stats.py`, then `python3 tools/overlay_masks.py <out.png> [image_dir] [views]` (chips magenta, rust orange, grime green, excluded areas dimmed) and LOOK. Expect 3–4 iterations; never trust a mask you have not overlaid. Typical traps: chips larger than the paint window vanish (use a wide chip window), light paint makes chips "not lighter", bright paint or the background read as a glowing window, louvres and highlights read as chips.
69
69
  2. **Write `brief/wear_description.md`** from the numbers AND your eyes on 2x crops (example: `assets/templates/wear_description_example.md`):
70
70
  - the object in one paragraph (materials, paint zones, edge radii);
71
71
  - a table per zone: chip % of area, rust %, grime %, character (where, which sizes);
72
72
  - per part and per side: count and size classes of chips (small < 2 cm, medium 2–5, large ≥ 5 cm, with ranges), where they sit (edges vs faces), drip sources and lengths, edge-wear strength, special notes ("the door: drips matter more than wear", "back is not empty: 3–5 large flakes");
73
- - the measurement caveats (what the masks over/under-count on this object);
73
+ - the measurement caveats (what the masks over/under-count on this object; zones a mask cannot judge, e.g. striped awnings or dark roofs, which the reviewer judges by eye). Coverage measurements saturate: where a patch is above ~40% of a local window the reference itself shifts and the number stops growing, so give ranges, and do not let a reviewer push a builder past what the eye shows;
74
74
  - a short "do not" list.
75
75
  3. **Rubric** `brief/rubric.json` (template `assets/templates/rubric.json`): keep the generic criteria (shape, paint, chips, edge_wear, drips, grime, style), replace `parts_*` with the object's key parts, weights sum to 1. The reviewer scores each 0–10; the script computes the weighted total, so scores are comparable between rounds.
76
76
 
@@ -85,8 +85,17 @@ What every builder must know (put it in the brief):
85
85
  - **Textures**: optional, via `tools/gen_texture.sh <out> <WxH> <x|xy|none> "<description>"` (Codex image generation, concept attached). A generated texture is only the paint base: clean out baked chips, moss and stains (hue/lightness filter) so wear comes only from the procedural layer tied to geometry; discard a texture with 20%+ "chips".
86
86
  - **Wear language**: `references/wear-language.md` (chips as flakes, edges first, drip clusters with bell-curve lengths, grime only low, dull marks) with implementations in `references/examples/` and in the scene's style library. Copy functions; keep the scene's language.
87
87
  - **Self-check before any review**: 5-view sheets (`tools/sheet.py`), 2x close-ups of every part, `python3 tools/wear_stats.py out/<pipeline>` against `out/wear_stats_concept.json`, `python3 tools/metrics.py <pipeline>` (silhouette IoU ≥ 0.9 per view, zone ΔE).
88
+ - **Extra renders**: anything the 5 views cannot show (interiors as floor-plan cutaways, sections, close-ups of key parts) goes to `out/<pipeline>/extra_*.png`; the review attaches them with no concept counterpart.
88
89
  - **Decisions log** `reviews/<pipeline>_decisions.md`: what was done and why, deliberate deviations from the spec or description. The reviewer reads it.
89
90
 
91
+ ### Large and composite objects
92
+
93
+ A building, a kiosk or anything with an interior is still one asset for this skill, built from parts in one script; concept-scene-builder decomposes larger things (a street block) before calling it.
94
+ - Spec: give the plan (rooms, stairs, partitions with door openings) next to the façades; interiors that are not visible from outside still need correct geometry (walls never cross windows, openings are walkable) and are judged from the extra cutaway renders.
95
+ - Framing: set `cameras.image` wider than tall (e.g. 1400 × 1000) for wide objects; the studios fit both axes.
96
+ - Performance: repeated elements (roof tiles, slats, bricks) as arrays/instances, not thousands of unique objects.
97
+ - Expect about twice the time of a small prop (the shop: ~2.5 h for one builder and 3 review rounds) and the same ceiling: massing, roof and openings reach 8–9, stains and grime stay around 6–8.
98
+
90
99
  ## 5. Review loop
91
100
 
92
101
  `tools/codex_review.sh <pipeline> <round>` (rounds 1..max_review_rounds; 3–10 minutes; run in the background and wait). The reviewer is a different model (Codex gpt-6.2-sol, high, read-only sandbox) with no context but: concept|render sheets per view, 2x close-ups, the description, the scene style, the rubric, the measurements of both, its own previous review and the builder's decisions log. It must keep its earlier requirements unless it explains why, and report fixed/improved/open for its previous top list. Output: `reviews/<pipeline>_r<n>.md` and `.json` with the weighted total.