@pix3/cli 1.6.0

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 (155) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +754 -0
  3. package/dist/index.js +494 -0
  4. package/dist/runtime-types.json +1 -0
  5. package/dist/smoke/prebuilt/build-7MIXIMSZ.mjs +948 -0
  6. package/dist/smoke/prebuilt/chunk-J2SJVMDO.mjs +2 -0
  7. package/dist/smoke/prebuilt/chunk-OJXQXIIQ.mjs +239 -0
  8. package/dist/smoke/prebuilt/chunk-P2CBRXPJ.mjs +4050 -0
  9. package/dist/smoke/prebuilt/runtime.mjs +2 -0
  10. package/dist/smoke/prebuilt/smoke-worker.mjs +3 -0
  11. package/dist/smoke/prebuilt/three.mjs +2 -0
  12. package/dist/smoke/prebuilt/tree-defaults.mjs +2 -0
  13. package/dist/validate/prebuilt/build-AUGKXER3.js +948 -0
  14. package/dist/validate/prebuilt/bundle-main.js +24 -0
  15. package/dist/validate/prebuilt/chunk-6ACT6FNV.js +4050 -0
  16. package/dist/validate/prebuilt/chunk-BS2OZM7U.js +239 -0
  17. package/dist/validate/prebuilt/runtime.js +2 -0
  18. package/dist/validate/prebuilt/three.js +2 -0
  19. package/kit/files/.claude/skills/pix3-nodes/SKILL.md +210 -0
  20. package/kit/files/.claude/skills/pix3-nodes/reference.md +1331 -0
  21. package/kit/files/.claude/skills/pix3-scene-format/SKILL.md +235 -0
  22. package/kit/files/.claude/skills/pix3-scene-format/reference.md +176 -0
  23. package/kit/files/.claude/skills/pix3-scripts/SKILL.md +281 -0
  24. package/kit/files/.claude/skills/pix3-scripts/reference.md +638 -0
  25. package/kit/files/.claude/skills/pix3-verify/SKILL.md +386 -0
  26. package/kit/files/.claude/skills/pix3-verify/reference.md +21 -0
  27. package/kit/files/AGENTS.md +203 -0
  28. package/kit/files/CLAUDE.md +1 -0
  29. package/kit/kit.json +24 -0
  30. package/package.json +54 -0
  31. package/templates/empty-2d/files/README.md +20 -0
  32. package/templates/empty-2d/files/scenes/main.pix3scene +68 -0
  33. package/templates/empty-2d/files/sprites/pix3-logo.png +0 -0
  34. package/templates/empty-2d/template.yaml +7 -0
  35. package/templates/empty-3d/files/README.md +20 -0
  36. package/templates/empty-3d/files/scenes/main.pix3scene +108 -0
  37. package/templates/empty-3d/files/sprites/pix3-logo.png +0 -0
  38. package/templates/empty-3d/template.yaml +7 -0
  39. package/templates/idea-blank/files/README.md +22 -0
  40. package/templates/idea-blank/files/scenes/main.pix3scene +37 -0
  41. package/templates/idea-blank/template.yaml +10 -0
  42. package/templates/minigame-2d/files/README.md +44 -0
  43. package/templates/minigame-2d/files/design/tests/reachability.json +1 -0
  44. package/templates/minigame-2d/files/design/tests/routines/mute-music.json +44 -0
  45. package/templates/minigame-2d/files/scenes/main.pix3scene +84 -0
  46. package/templates/minigame-2d/files/scenes/menu.pix3scene +118 -0
  47. package/templates/minigame-2d/files/scenes/ui/settings-window.pix3scene +138 -0
  48. package/templates/minigame-2d/files/scripts/GameFlow.ts +133 -0
  49. package/templates/minigame-2d/files/scripts/MenuFlow.ts +217 -0
  50. package/templates/minigame-2d/files/scripts/SettingsWindow.ts +198 -0
  51. package/templates/minigame-2d/template.yaml +10 -0
  52. package/templates/playable-2d/files/README.md +30 -0
  53. package/templates/playable-2d/files/design/recipe.md +83 -0
  54. package/templates/playable-2d/files/design/tests/reachability.json +4 -0
  55. package/templates/playable-2d/files/design/tests/routines/intro-to-cta.json +32 -0
  56. package/templates/playable-2d/files/scenes/main.pix3scene +111 -0
  57. package/templates/playable-2d/files/scenes/ui/end-screen.pix3scene +91 -0
  58. package/templates/playable-2d/files/scenes/ui/intro.pix3scene +65 -0
  59. package/templates/playable-2d/files/scripts/CtaButton.ts +55 -0
  60. package/templates/playable-2d/files/scripts/GameFlow.ts +256 -0
  61. package/templates/playable-2d/files/sprites/pix3-logo.png +0 -0
  62. package/templates/playable-2d/template.yaml +9 -0
  63. package/templates/playable-3d/files/README.md +32 -0
  64. package/templates/playable-3d/files/design/recipe.md +127 -0
  65. package/templates/playable-3d/files/design/tests/reachability.json +4 -0
  66. package/templates/playable-3d/files/design/tests/routines/intro-to-cta.json +32 -0
  67. package/templates/playable-3d/files/scenes/main.pix3scene +230 -0
  68. package/templates/playable-3d/files/scenes/ui/end-screen.pix3scene +91 -0
  69. package/templates/playable-3d/files/scenes/ui/intro.pix3scene +65 -0
  70. package/templates/playable-3d/files/scripts/CtaButton.ts +55 -0
  71. package/templates/playable-3d/files/scripts/GameFlow.ts +309 -0
  72. package/templates/playable-3d/files/scripts/GameRules.ts +290 -0
  73. package/templates/playable-3d/files/scripts/ScoreHud.ts +113 -0
  74. package/templates/playable-3d/template.yaml +9 -0
  75. package/templates/recipe-arena-2d/files/README.md +48 -0
  76. package/templates/recipe-arena-2d/files/design/recipe.md +127 -0
  77. package/templates/recipe-arena-2d/files/design/tests/reachability.json +4 -0
  78. package/templates/recipe-arena-2d/files/design/tests/routines/terminal-retry.json +23 -0
  79. package/templates/recipe-arena-2d/files/scenes/main.pix3scene +292 -0
  80. package/templates/recipe-arena-2d/files/scenes/menu.pix3scene +100 -0
  81. package/templates/recipe-arena-2d/files/scenes/prefabs/hazard.pix3scene +42 -0
  82. package/templates/recipe-arena-2d/files/scenes/prefabs/pickup.pix3scene +45 -0
  83. package/templates/recipe-arena-2d/files/scenes/ui/result.pix3scene +85 -0
  84. package/templates/recipe-arena-2d/files/scripts/GameRules.ts +368 -0
  85. package/templates/recipe-arena-2d/files/scripts/MenuFlow.ts +106 -0
  86. package/templates/recipe-arena-2d/files/scripts/PlayerController.ts +151 -0
  87. package/templates/recipe-arena-2d/files/scripts/ScoreHud.ts +94 -0
  88. package/templates/recipe-arena-2d/files/scripts/Spawner.ts +214 -0
  89. package/templates/recipe-arena-2d/files/scripts/TouchRules.ts +174 -0
  90. package/templates/recipe-arena-2d/files/sprites/ph-avatar.png +0 -0
  91. package/templates/recipe-arena-2d/files/sprites/ph-hazard.png +0 -0
  92. package/templates/recipe-arena-2d/files/sprites/ph-pickup.png +0 -0
  93. package/templates/recipe-arena-2d/template.yaml +10 -0
  94. package/templates/recipe-blank-2d/files/README.md +61 -0
  95. package/templates/recipe-blank-2d/files/design/recipe.md +148 -0
  96. package/templates/recipe-blank-2d/files/design/tests/reachability.json +4 -0
  97. package/templates/recipe-blank-2d/files/design/tests/routines/restart.json +27 -0
  98. package/templates/recipe-blank-2d/files/design/tests/routines/terminal-retry.json +23 -0
  99. package/templates/recipe-blank-2d/files/scenes/main.pix3scene +224 -0
  100. package/templates/recipe-blank-2d/files/scenes/ui/result.pix3scene +85 -0
  101. package/templates/recipe-blank-2d/files/scripts/GameRules.ts +350 -0
  102. package/templates/recipe-blank-2d/files/scripts/ScoreHud.ts +110 -0
  103. package/templates/recipe-blank-2d/files/sprites/ph-bg.png +0 -0
  104. package/templates/recipe-blank-2d/files/sprites/ph-capsule.png +0 -0
  105. package/templates/recipe-blank-2d/files/sprites/ph-circle.png +0 -0
  106. package/templates/recipe-blank-2d/files/sprites/ph-orb.png +0 -0
  107. package/templates/recipe-blank-2d/files/sprites/ph-ring.png +0 -0
  108. package/templates/recipe-blank-2d/files/sprites/ph-star.png +0 -0
  109. package/templates/recipe-blank-2d/template.yaml +10 -0
  110. package/templates/recipe-bouncer-2d/files/README.md +81 -0
  111. package/templates/recipe-bouncer-2d/files/design/recipe.md +146 -0
  112. package/templates/recipe-bouncer-2d/files/design/tests/reachability.json +4 -0
  113. package/templates/recipe-bouncer-2d/files/design/tests/routines/terminal-retry.json +23 -0
  114. package/templates/recipe-bouncer-2d/files/scenes/main.pix3scene +615 -0
  115. package/templates/recipe-bouncer-2d/files/scenes/menu.pix3scene +191 -0
  116. package/templates/recipe-bouncer-2d/files/scenes/ui/result.pix3scene +87 -0
  117. package/templates/recipe-bouncer-2d/files/scripts/BallBody.ts +298 -0
  118. package/templates/recipe-bouncer-2d/files/scripts/GameRules.ts +377 -0
  119. package/templates/recipe-bouncer-2d/files/scripts/MenuFlow.ts +109 -0
  120. package/templates/recipe-bouncer-2d/files/scripts/PaddleController.ts +112 -0
  121. package/templates/recipe-bouncer-2d/files/scripts/ScoreHud.ts +94 -0
  122. package/templates/recipe-bouncer-2d/files/scripts/TouchRules.ts +263 -0
  123. package/templates/recipe-bouncer-2d/files/scripts/ball-collision.ts +307 -0
  124. package/templates/recipe-bouncer-2d/files/sprites/ph-ball.png +0 -0
  125. package/templates/recipe-bouncer-2d/files/sprites/ph-bg.png +0 -0
  126. package/templates/recipe-bouncer-2d/files/sprites/ph-bumper.png +0 -0
  127. package/templates/recipe-bouncer-2d/files/sprites/ph-paddle.png +0 -0
  128. package/templates/recipe-bouncer-2d/template.yaml +10 -0
  129. package/templates/recipe-grid-3d/files/README.md +22 -0
  130. package/templates/recipe-grid-3d/files/design/recipe.md +110 -0
  131. package/templates/recipe-grid-3d/files/scenes/main.pix3scene +169 -0
  132. package/templates/recipe-grid-3d/files/scenes/menu.pix3scene +100 -0
  133. package/templates/recipe-grid-3d/files/scenes/ui/result.pix3scene +105 -0
  134. package/templates/recipe-grid-3d/files/scripts/GridBoard.ts +319 -0
  135. package/templates/recipe-grid-3d/files/scripts/GridRules.ts +278 -0
  136. package/templates/recipe-grid-3d/files/scripts/MenuFlow.ts +106 -0
  137. package/templates/recipe-grid-3d/files/scripts/ScoreHud.ts +94 -0
  138. package/templates/recipe-grid-3d/template.yaml +10 -0
  139. package/templates/recipe-tapper-2d/files/README.md +39 -0
  140. package/templates/recipe-tapper-2d/files/design/recipe.md +132 -0
  141. package/templates/recipe-tapper-2d/files/design/tests/reachability.json +4 -0
  142. package/templates/recipe-tapper-2d/files/design/tests/routines/terminal-retry.json +23 -0
  143. package/templates/recipe-tapper-2d/files/scenes/main.pix3scene +269 -0
  144. package/templates/recipe-tapper-2d/files/scenes/menu.pix3scene +100 -0
  145. package/templates/recipe-tapper-2d/files/scenes/prefabs/hazard.pix3scene +42 -0
  146. package/templates/recipe-tapper-2d/files/scenes/prefabs/target.pix3scene +45 -0
  147. package/templates/recipe-tapper-2d/files/scenes/ui/result.pix3scene +85 -0
  148. package/templates/recipe-tapper-2d/files/scripts/GameRules.ts +368 -0
  149. package/templates/recipe-tapper-2d/files/scripts/MenuFlow.ts +106 -0
  150. package/templates/recipe-tapper-2d/files/scripts/ScoreHud.ts +94 -0
  151. package/templates/recipe-tapper-2d/files/scripts/Spawner.ts +214 -0
  152. package/templates/recipe-tapper-2d/files/scripts/TouchRules.ts +192 -0
  153. package/templates/recipe-tapper-2d/files/sprites/ph-hazard.png +0 -0
  154. package/templates/recipe-tapper-2d/files/sprites/ph-target.png +0 -0
  155. package/templates/recipe-tapper-2d/template.yaml +10 -0
@@ -0,0 +1,386 @@
1
+ ---
2
+ name: pix3-verify
3
+ description: How to check and run a Pix3 change — `pix3 check` / `pix3 validate` / `pix3 read`, the diagnostic codes, reading merge-log entries (the editor kept a human's value over yours), the live channel (`pix3 serve` + `pix3 mcp --workspace`, `game_run` with `expect` hashes, the barrier's answer fields and error codes), and how to report what was and was not verified. Use after every batch of edits to .pix3scene or scripts/*.ts, and before telling the user a change is done.
4
+ ---
5
+
6
+ <!-- Pix3 agent kit 1.6.0 -->
7
+ # Verify a change
8
+
9
+ Leave files that load and type-check, run the game when the live channel is there, and tell
10
+ the human exactly what to press and what they should see.
11
+
12
+ ## 1. `pix3 check` after every batch
13
+
14
+ ```bash
15
+ pix3 check # validate (both levels) + tsc over the scripts + merge-log + versions
16
+ pix3 check --json # the same, machine-readable
17
+ pix3 validate [paths] [--json] # scenes/prefabs only, no type-check
18
+ pix3 smoke scenes/main.pix3scene # then: run the game headless for 120 frames, report what threw
19
+ pix3 tree [scene] # outline of a scene (or of the project) instead of reading it
20
+ ```
21
+
22
+ If `pix3` is not on your PATH, run the pinned one from `.mcp.json`: `npx -y @pix3/cli@1.6.0 check`.
23
+
24
+ Exit code 1 = at least one **error**. Fix every error before reporting; warnings (off-screen
25
+ nodes, zero size, unused assets, out-of-range values) are for judgement.
26
+
27
+ `--json` answers `{ ok, errorCount, warningCount, files, diagnostics, notes, typecheck,
28
+ mergeLog, kit, … }`:
29
+
30
+ - `files` — every scene validated and every script type-checked, as
31
+ `[{ "file": "scenes/main.pix3scene", "sha256": "…" }]` (the key is `file`, not `path`) — the
32
+ **sha256 of its raw bytes**. These are the hashes `expect` and `pix3 ack --sha256` take.
33
+ - `diagnostics` — one list: `{ severity, code, file, line?, nodeId?, path?, message, fix? }`.
34
+ - `typecheck` — `{ ok, errors, tsconfig, mode, files, typescript, skipped }`; tsc errors are
35
+ `E_TYPE` diagnostics in the list above; `skipped` says why tsc did not run at all.
36
+ - `mergeLog` — the newest `.pix3/merge-log.jsonl` entries (section 2).
37
+ - `kit` — `{ version, cliVersion, upToDate }`: `pix3 kit --update` when it is stale.
38
+
39
+ The first `check` on a machine may install TypeScript once into `~/.pix3/typescript/` (it
40
+ prints the `npm install` it runs; `--offline` refuses and prints the command instead).
41
+
42
+ **A project with its own `package.json` needs `npm install` before `pix3 check` can
43
+ type-check.** Such a project has its own `tsconfig.json` and type-checks against its own
44
+ `node_modules`; without them `check` reports one `E_DEPENDENCIES_MISSING` (fix: `npm install`)
45
+ and skips tsc — the scenes are still validated. Run `npm install` once, then `check` again.
46
+
47
+ Codes and what they usually mean:
48
+
49
+ | Code | Usual cause / fix |
50
+ | --- | --- |
51
+ | `E_YAML` | Bad indentation, unquoted `#colour`, a `:` inside an unquoted string |
52
+ | `E_UNKNOWN_NODE_TYPE` | Typo in the node type — use the suggested name |
53
+ | `E_UNKNOWN_COMPONENT` | `user:X` with no exported `class X extends Script` that has `static getPropertySchema()` in `scripts/`; or a `core:` name that does not exist |
54
+ | `E_UNKNOWN_PROPERTY` | Key not read for that node / component — check `pix3-nodes`; a flat `horizontalAlign` belongs in `layout:` |
55
+ | `E_PROPERTY_TYPE` | `"10"` for a number, a colour without quotes, an enum value not in the list |
56
+ | `E_MISSING_RESOURCE` | `res://` path typo, or the asset was never written |
57
+ | `E_MISSING_PREFAB`, `E_PREFAB_*`, `E_DUPLICATE_ID` | Fix the `instance:` path; a prefab file needs exactly one root; ids are unique |
58
+ | `E_EMOJI_AS_ART` | A `label`/`text` that is only emoji — use a sprite or `ColorRect2D` |
59
+ | `E_SVG_INVALID`, `E_SVG_NO_SIZE`, `W_SVG_VIEWBOX_ONLY` | An `.svg` sprite without `xmlns` or without `width`/`height` in px — see the SVG template in `pix3-nodes` |
60
+ | `W_SVG_EXTERNAL_REF` | An `.svg` that links a file, URL or font — it will draw without it; inline it |
61
+ | `E_TYPE` | A TypeScript error in a script (`TS2339: Property … does not exist …`) |
62
+ | `E_TYPECHECK_UNAVAILABLE` | TypeScript could not be installed — run the printed command |
63
+ | `E_DEPENDENCIES_MISSING` | A project with its own `tsconfig.json` and no `node_modules` — `npm install`; tsc was skipped |
64
+ | `W_RUNTIME_VERSION_MISMATCH` / `W_RUNTIME_NOT_INSTALLED` | A project with its own `tsconfig.json` type-checks against its own `node_modules/@pix3/runtime` — `npm install` it at the CLI's version |
65
+ | `W_KIT_OUTDATED` | This kit is older than the CLI — `pix3 kit --update` |
66
+
67
+ `pix3 validate --help` and `pix3 check --help` list every code. Level 2 of validate compiles
68
+ and loads your scripts to check the properties of `user:` components; with `--no-hydrate` (or
69
+ when scripts cannot be loaded) those are **not** checked — say so if your change depends on them.
70
+
71
+ ### `pix3 smoke` — when no editor is connected
72
+
73
+ `pix3 smoke <scene>` (after a green `check`) runs that scene in Node: your scripts compiled, the
74
+ scene loaded by the real loader, `--frames N` steps of 1/60 s (default 120). **Name the scene you
75
+ changed** — the game is `pix3 smoke scenes/main.pix3scene`. Input is empty, so a menu never
76
+ presses PLAY: smoking the menu (the build's entry scene) proves nothing about the game. With no
77
+ scene, smoke runs several, one line each and exit 1 if any fails: the top-level scenes your
78
+ uncommitted changes reach (git: the scene, a prefab or overlay it instances, a `user:` script it
79
+ attaches), else — no git, nothing changed, or a change it cannot trace — every top-level scene,
80
+ `scenes/main.pix3scene` first (`--changed` / `--all` force either; `--json` then answers
81
+ `{ ok, selection, reason, runs: [one report per scene] }`). Exit 1 lists every
82
+ `E_SMOKE_SCRIPT` (a hook threw: script, node, frame — 0 = `onAttach`/`onStart` — and a stack
83
+ pointing at your `.ts` line), `E_SMOKE_CONSOLE_ERROR`, `E_SMOKE_UNHANDLED` (a rejected promise
84
+ nobody awaited), `E_SMOKE_DOM` (a browser API the headless run lacks — `domAccess` names it; a
85
+ browser-only feature, not necessarily a bug: say so). `W_SMOKE_MISSING_RESOURCE` is a `res://`
86
+ typo. Exit 2 = it could not run (`E_SMOKE_NO_SCENE`: pass the scene; `E_SMOKE_TIMEOUT`: a loop
87
+ that never ends). Nothing is drawn, heard or tapped: a green smoke run proves the game starts and
88
+ runs without throwing, not that it plays — report it as exactly that, and tell the human what to
89
+ press and what they should see (section 4). With the live channel, `game_run` (section 3) is the
90
+ stronger check.
91
+
92
+ **No live channel: the fallback, in this order** — `pix3 check` (green), then
93
+ `pix3 smoke <the scene you changed>` (green), then ask the human to press Play in that scene,
94
+ naming what to press and what they should see.
95
+
96
+ ## 2. Merge-log: the editor kept the human's value
97
+
98
+ The human edits the same files in the editor. When you write a value over one the human set
99
+ after your last read, the editor keeps the human's value and logs it to
100
+ `.pix3/merge-log.jsonl`; `pix3 check` prints the newest entries, e.g.
101
+ `scenes/main.pix3scene merged: the editor KEPT 1 human value(s) over yours`.
102
+
103
+ When you see one:
104
+
105
+ 1. `pix3 read <file>` — prints the current file and records that you have read this version
106
+ (`.pix3/ack.json`).
107
+ 2. Decide: is your value still intended given what the human did? If yes, write it again —
108
+ it now sticks. If unsure, ask the human (that is your one question this turn).
109
+
110
+ Without step 1 the editor keeps restoring the human's value on every write you make, even if
111
+ you write the same number the human chose.
112
+
113
+ `check` prints `note: … read confirmation for a version the editor has not recorded — ignored`
114
+ as a note, not a merge-log line: your `pix3 read` named bytes the editor has no record of
115
+ having loaded or written (e.g. a version that was on disk only between two of its polls).
116
+ Nothing was lost and nothing is protected by it; no action unless a KEPT line follows. (`pix3 ack <file> --sha256 <hash>` confirms a
117
+ version whose hash you took from `pix3 check --json` without printing it again.)
118
+
119
+ ## 3. Live channel — run the game yourself
120
+
121
+ Available when the human runs `pix3 serve` in the project and connects the editor to it
122
+ (File → Connect to Workspace…); your MCP client starts `pix3 mcp --workspace` from `.mcp.json`
123
+ (`pix3 setup claude|codex` prints the registration for a client without it). Without a server
124
+ every tool answers `no_workspace_server`; without a connected window, `no_editor`.
125
+
126
+ The 14 tools:
127
+
128
+ - `project_status` — Whether a Pix3 editor window is connected to this project, what it has open, external versions it has not applied yet, unreadable files, merge conflicts and the latest merge-log entries (why a write of yours did not land as written).
129
+ - `play_start` — Enter play mode.
130
+ - `play_stop` — Exit play mode.
131
+ - `play_restart` — Restart play mode.
132
+ - `play_status` — Whether the game is playing, and what the last frame drew (draw calls, visible meshes).
133
+ - `game_run` — Run the game frame by frame until a predicate holds (`until`, OR), fails (`fail`) or a budget runs out, or run a stored routine from design/tests/routines (`routine`, `args`).
134
+ - `game_input` — Send real input to the running game (steps: tap / key / keys / drag / hover / invoke / wait) and report the reaction; `observe` watches nodes over the window.
135
+ - `game_observe` — Read live node state of the running game (by name or id) without sending input.
136
+ - `read_errors` — Recent runtime errors captured in the editor (console.error, window errors, rejections).
137
+ - `read_logs` — Recent editor log entries; `since` (epoch ms) returns only newer ones.
138
+ - `viewport_screenshot` — A screenshot as an image: the running game while playing, else the editor viewport.
139
+ - `generate_asset` — Generate an image with the editor's configured image provider (the user's keys — the editor asks the user to allow this for the session), post-process it and save it into the project.
140
+ - `generate_sfx` — Generate a prototype sound effect (WAV under res://sfx/) with the editor's LLM (asks the user to allow this for the session).
141
+ - `get_selection` — What the human has selected in the editor right now (node ids, primary, hovered).
142
+
143
+ The loop after a batch of edits:
144
+
145
+ 1. `pix3 check --json` → take the `sha256` of every file you wrote from `files`
146
+ (`{ file, sha256 }` entries).
147
+ 2. A barrier tool — `game_run`, `play_start` or `play_restart` — with
148
+ `expect: { "<path>": "<sha256>", … }`: the run starts only if the disk holds exactly those
149
+ versions and the editor loaded them.
150
+ 3. Green = no error, `matchesAgent: true`, `matchesDisk: true`, empty `changedDuringRun`. Then
151
+ `read_errors`, `game_observe` / `viewport_screenshot` to see what happened.
152
+ 4. `disk_differs_from_agent` with `mergeLog: true` → the editor merged your file with a human
153
+ edit: `pix3 read` it (section 2). With `recovery` → someone overwrote it; the named file under
154
+ `.pix3/recovery/` holds your version. Otherwise write the file again.
155
+
156
+ ### Two ways to prove behaviour
157
+
158
+ **Every barrier call stops the game and starts it again from the files on disk.** `game_run`
159
+ included: it is always a run from a fresh start, so it can never judge state that an earlier
160
+ `game_input` produced — that state is gone before its first frame. Pick the pattern by what
161
+ causes the behaviour:
162
+
163
+ - **(a) Autonomous behaviour** (spawns, timers, physics, a HUD that counts on its own):
164
+ one `game_run` with `expect`, predicates in `until` (any one ends the run as a pass) and
165
+ `fail` (any one ends it as a failure), e.g. `until:
166
+ [{ kind: "nodeProperty", name: "ScoreLabel", path: "text", op: "contains", value: "10" }]`,
167
+ `fail: [{ kind: "newErrors" }]` (a script threw). Read `verdict`, then the result's
168
+ `newErrors` count, then `read_errors` when it is not 0.
169
+ - **(b) Input-driven behaviour** (taps, keys, combos): `play_start` or `play_restart` with
170
+ `expect` (the barrier, once) → one or more `game_input` calls → `game_observe` / `read_logs`.
171
+ `game_input` and `game_observe` are observing tools: they neither stop nor resync, so the
172
+ state builds up across calls. Do **not** end with `game_run` to "check the result" — it
173
+ restarts the game.
174
+
175
+ ### `game_input` — what the steps really do
176
+
177
+ - **Coordinates** (`x`, `y` on `tap` / `drag` / `hover`) are the 2D design space the scene
178
+ file uses: origin at the **centre**, **Y up**, the same numbers as a node's `position`. With
179
+ the 2D camera at rest, `{ x: 0, y: 0 }` is the centre of the viewport and the top edge of a
180
+ 1080 x 1920 design is `y: 960` — not `(540, 960)` or `(960, 540)`. Coordinates follow the 2D
181
+ camera; a node under a `CanvasLayer2D` (a HUD) is pinned to the screen instead, so for HUD and
182
+ buttons prefer `target: "<node name or id>"`, which projects the node's live position the
183
+ right way for either.
184
+ - **`tap` holds the pointer down 700 ms by default** (so a `Button2D` sees a real press). For
185
+ fast repeated hits — a combo window, a rhythm check — pass `holdMs` (e.g. `holdMs: 50`) and a
186
+ short `wait` between taps; `frames` instead of `ms` / `holdMs` counts game ticks.
187
+ - **One call is capped at 15 s** of requested time (holds + drags + waits); longer answers
188
+ `Input script too long` — split it into several `game_input` calls.
189
+ - **Input goes through the engine's `InputService`**: `PointerEvent`s on the game canvas and
190
+ `KeyboardEvent`s on `window`. Scripts that read `this.input` see it. A game that listens for
191
+ DOM `mouse*` / `click` / `touch*` events, keys on `document`, or on a canvas of its own does
192
+ **not** — verify such input by hand.
193
+
194
+ ### Reading the answers
195
+
196
+ - **Barrier answers** carry `revision`, `startupMs` (how long the game took to start),
197
+ `matchesAgent` / `agentExpectations`, `matchesDisk`, `changedDuringRun`,
198
+ `editorWroteDuringRun`, `editorChangedSinceAgentWrite` and `result` (the editor tool's own
199
+ answer). **Observing answers** are `{ revision, stale, result }`.
200
+ - `revision` is the running game's file → hash map: every open scene, every script the build
201
+ read, `pix3project.yaml` — it can run to hundreds of lines. Check `stale` and the match
202
+ flags; never paste `revision` into a report.
203
+ - **Labels and HUD text.** An observed node reports its rendered `text` only at the window's
204
+ **start and end** — `observed.<node>.before.text` / `.after.text` in `game_input`,
205
+ `nodes.<node>.text` (and `movement.<node>.before` / `.after` with `sampleMs` or `frames`) in
206
+ `game_observe`;
207
+ there is no per-frame text timeline. The one-line `verdict` does not count a text change:
208
+ it can say `NO ACTIVITY` while the label went from `x1` to `x3`. For HUD text, read the text
209
+ fields, never the verdict alone.
210
+ - **Timing proofs** ("the combo resets after 1 s", "x3 appears on the third hit"): add
211
+ temporary `console.info('[combo] x3')` markers in the script, note the current epoch ms
212
+ before the input, run it, then `read_logs` with `since` set to that value — every console line
213
+ the game prints arrives with its own epoch-ms `timestamp`, so the gaps between markers are the
214
+ timing. **Remove the markers afterwards** and run `pix3 check` again.
215
+ - **Movement below ~0.5 units reads as `moved: false`**, and a shake that returns to rest
216
+ inside the window has no endpoint delta at all — a small camera shake is not provable from
217
+ `moved`. Take a `viewport_screenshot` mid-shake or log the offset with a marker.
218
+ - **Sound**: synthetic input is not a user gesture, so the browser may keep Web Audio
219
+ suspended; nothing in the answers says whether a sound was heard. Report it as "code path
220
+ verified, audibility not".
221
+ - **Latency** (measured in trials): observing calls take about 1 s; a barrier call takes the
222
+ game's startup plus 1–2 s — a small 2D game a few seconds, a heavy 3D game 13–14 s
223
+ (`startupMs` says which). Batch several input steps into one `game_input` rather than many
224
+ calls.
225
+
226
+ The contract, as the CLI documents it:
227
+
228
+ A stdio MCP server the agent starts from its config (`.mcp.json`, `pix3 setup`). It has no port
229
+ of its own: it finds the running `pix3 serve` of the project (`--project`, else the nearest
230
+ ancestor of the cwd with `pix3project.yaml`) through `.pix3/workspace.json` and confirms it with
231
+ `GET /ws/agent/status` + the control secret. When none runs, every tool answers
232
+ `no_workspace_server` and stderr says ``Workspace server is not running. Run `pix3 serve` in
233
+ <root>``; the next call looks again, so the agent never restarts its MCP server.
234
+
235
+ **Presence.** While it runs, the process announces itself to that server
236
+ (`POST /ws/agent/presence`, every 10 s and on start/stop; failures are silent and the next beat
237
+ rediscovers a restarted server). That is what tells the editor an agent is attached, so it keeps
238
+ the game, the viewport, file polling and reconnects running in a hidden or unfocused tab instead
239
+ of pausing them for battery (`AgentKeepaliveService`; the user can switch this off in Settings →
240
+ General). `PIX3_PRESENCE_HEARTBEAT_MS` overrides the cadence (tests).
241
+
242
+ **Tools (v1, exactly):** `project_status`, `play_start`, `play_stop`, `play_restart`,
243
+ `play_status`, `game_run`, `game_input`, `game_observe`, `read_errors`, `read_logs`,
244
+ `viewport_screenshot` (the PNG comes back as an MCP image block), `generate_asset`,
245
+ `generate_sfx`, `get_selection`. No scene-mutating tool: the agent edits files. Schemas are the
246
+ window's (`GET /ws/agent/tools`), with a static fallback so `tools/list` works before a window
247
+ connects (a `notifications/tools/list_changed` follows once a window's schemas are known).
248
+ `play_start` / `play_restart` / `game_run` also take `expect: { path: sha256 }` — the sha256 of the
249
+ raw bytes of every file the agent wrote.
250
+
251
+ **The sync barrier** (plan §5 D) runs before `play_start`, `play_restart` and `game_run`:
252
+
253
+ 1. **Agent's expectations.** `expect` is checked against the disk (`/ws/agent/expect`) before
254
+ anything syncs. Any mismatch → `disk_differs_from_agent` with, per file: merged by the editor
255
+ (`mergeLog: true` — re-read it), or overwritten — with `recovery: ".pix3/recovery/…"` only when
256
+ a copy with exactly those bytes exists, else "no copy exists — write the file again". Nothing
257
+ starts. Without `expect` the answer says `agentExpectations: "none"`.
258
+ 2. **Editor = disk.** The window's internal `sync_barrier` holds autosave (edits accumulate and are
259
+ saved after the run), stops play, runs `syncNow()` (waits for the stabilisation window and the
260
+ script build; re-reads `pix3project.yaml` when the disk holds another version) and returns
261
+ `{loaded: {path: sha256}, errors}` — every open scene/prefab (any path), every source the last
262
+ script build read (the entry scripts **and every module the bundle pulled in**, e.g. `src/**`;
263
+ the hash recorded when the build read it, so nothing is re-read) and `pix3project.yaml`. An open
264
+ scene the editor holds no disk version of is a `load_failed` error, never silently left out. The
265
+ MCP process gives this call 100 s. These hashes (plus `expect`) are compared with `/ws/agent/hash` at that moment;
266
+ a mismatch retries the editor's sync for up to ~5 s. Then: loader/compiler errors →
267
+ `load_failed` (`{file, line, message, kind}`); a file that stays unreadable →
268
+ `pending_external`; hashes that never agree → `sync_timeout` with the differing paths. The
269
+ window then starts the game (`game_run` starts play itself; `play_restart` of a stopped game is
270
+ a start) and answers only once the game is actually running: up to 30 s, as soon as it runs,
271
+ failing fast (`load_failed` with the play-mode error) when play mode stops instead; `startupMs`
272
+ says how long the start took (always present in the answer: `null` means no start happened —
273
+ `game_run` found the game already running — never "0 ms"). The MCP process gives the tool call 120 s (the server's cap). The
274
+ hold is released (`sync_release`) after the run.
275
+ 3. **After the run** (for `game_run` when it finished; for `play_start` / `play_restart` right
276
+ after the start was acknowledged) the verified files are hashed again and
277
+ `/ws/agent/changes?since=<seq of the verification>` is read: `changedDuringRun` and
278
+ `editorWroteDuringRun`.
279
+
280
+ The answer of a barrier tool:
281
+
282
+ ```json
283
+ {
284
+ "revision": { "<path>": "<sha256 of the verified version>" },
285
+ "startupMs": 8123,
286
+ "matchesAgent": true,
287
+ "matchesDisk": true,
288
+ "changedDuringRun": [],
289
+ "editorWroteDuringRun": [],
290
+ "editorChangedSinceAgentWrite": [],
291
+ "result": { "…": "the editor tool's own result" }
292
+ }
293
+ ```
294
+
295
+ `startupMs` is always present: the milliseconds from the start request until the game was
296
+ running, or `null` when no start happened (the game was already running, so there was nothing to
297
+ measure). `matchesAgent` is `null` (with `agentExpectations: "none"`) without `expect`; `matchesDisk` is
298
+ whether every verified hash still matched the disk at the final check; `changedDuringRun` is what
299
+ the barrier did not verify: every file changed meanwhile by someone other than the editor, plus
300
+ every verified file whose hash moved between the two checks with no editor write on record
301
+ (`changeLogIncomplete: true` when the server's ring did not reach back); `editorWroteDuringRun` is
302
+ every file whose only changes since the verification are the editor's own writes through the file
303
+ API (e.g. a run report under `design/tests/reports/`) — known to the server, so not a
304
+ detection. Both list files only, never directories; `editorChangedSinceAgentWrite` is
305
+ the `expect` paths the merge log says the editor wrote after the check. **A green answer without
306
+ marks means: at start disk = agent's expectations = verified version; at the final check the
307
+ verified hashes match disk; detected changes are listed.** It does not mean the disk did not change
308
+ during the run: `v1 → v2 → v1` between the two checks is invisible, and the game reads resources
309
+ lazily.
310
+
311
+ **Observing tools** (`play_status`, `game_input`, `game_observe`, `viewport_screenshot`,
312
+ `read_errors`, `read_logs`) neither stop nor sync: `{ revision, stale, result }`, where `revision` is
313
+ what the running game was verified against (`null` when play was not started through the barrier)
314
+ and `stale: true` when the editor saw an external change during play or a `revision` path's disk
315
+ hash moved since. Other tools (`project_status`, `play_stop`, `get_selection`, `generate_*`) answer
316
+ with the editor's result as is. `project_status` without a window answers
317
+ `{ connected: false, server, editor: null, message }` (not an error).
318
+
319
+ **Error codes** (every error is `isError: true` with `{ "error": "<code>", "message", … }`):
320
+
321
+ | Code | When |
322
+ | --- | --- |
323
+ | `disk_differs_from_agent` | Step 1: the disk does not hold the `expect` versions (`differing[]` with `recovery`, `mergeLog`, `hint`). |
324
+ | `sync_timeout` | Step 2: the editor's loaded hashes did not match the disk within ~5 s (`differing[]` with `loadedHash` / `agentHash` / `diskHash`). |
325
+ | `load_failed` | Step 2: the loader or the script compiler failed on the current files, or an open scene has no verified version (`errors[]`). At the start: the game was not running within 30 s, or play mode stopped (`result` carries it, with `startupMs`). |
326
+ | `pending_external` | Step 2: a file stays unreadable (partial / invalid write); the editor keeps its last good version. |
327
+ | `no_editor` | No window holds the lease, it did not answer (`reason: "no_reply"`), or it lost the lease mid-call (`reason: "lease_lost"`). |
328
+ | `permission_denied` | `generate_*`: the human denied, or did not answer within 60 s. |
329
+ | `no_workspace_server` | No `pix3 serve` runs for the project root. |
330
+
331
+ Anything else the editor refuses (`unknown_tool`, `agent_disabled` when the human switched the
332
+ channel off) is passed through as the editor wrote it.
333
+
334
+ **Generation permission.** The first `generate_asset` / `generate_sfx` of a connection (server
335
+ session + lease + `pix3 mcp` process) opens a prompt in the editor naming the process and what it
336
+ calls itself (unverified); the call waits up to 60 s. Allowed → 20 generations, then it asks again.
337
+ In memory only: a reconnect, a new `pix3 serve` run, a lease takeover or a new `pix3 mcp` process
338
+ resets it; the status-bar Agent pill has a revoke button and switches the channel off.
339
+
340
+ ### MCP configuration
341
+
342
+ `pix3 new` and `pix3 kit` write the project's `.mcp.json` (Claude Code's project format), **pinned
343
+ to the CLI version that wrote it** — never a bare `@pix3/cli`:
344
+
345
+ ```json
346
+ { "mcpServers": { "pix3": { "command": "npx", "args": ["-y", "@pix3/cli@<X.Y.Z>", "mcp", "--workspace"] } } }
347
+ ```
348
+
349
+ `pix3 setup [claude|codex]` prints (never runs) the registration for a project without one:
350
+ `claude mcp add pix3 -- npx -y @pix3/cli@<X.Y.Z> mcp --workspace` (run in the project folder), and
351
+ for Codex a `~/.codex/config.toml` block — `[mcp_servers.pix3]` with `command`, `args` (plus
352
+ `--project <root>`, since that config is global) and `tool_timeout_sec = 180`. The Codex keys are
353
+ the ones `tools/pix3-agent-bridge` passes to `codex exec -c mcp_servers.pix3.*`; the file form is
354
+ best-effort, check `codex mcp --help` of your Codex version.
355
+
356
+ **Dev mode.** From a checkout of the pix3 repo (the CLI runs from `packages/pix3-cli/src/`), or
357
+ with `PIX3_CLI_DEV=1`, both write `node <repo>/packages/pix3-cli/src/index.ts mcp --workspace`
358
+ instead, so the channel can be tried before that version is on npm. `PIX3_CLI_DEV=0` forces the
359
+ pinned form.
360
+
361
+ ## 4. Report honestly
362
+
363
+ A file that passes `check` loads and compiles. It is not a game that works. End the turn
364
+ with:
365
+
366
+ - what you changed (files), and whether `pix3 check` was green;
367
+ - whether you ran it (the barrier answer, and which pattern: `game_run` predicates or
368
+ `game_input` + observed text / log markers) — or **what the human should do to see it**:
369
+ "press Play in `scenes/main.pix3scene`, tap the gold stars — the combo label top-right should
370
+ count x2, x3";
371
+ - what you could not verify (feel, audibility, small shakes, anything the channel cannot see);
372
+ - placeholders you left — art (`ColorRect2D`, tinted PNGs, hand-written SVGs) and sound. A sound
373
+ you made with `pix3 sfx` is a real `.wav`, not a placeholder in the file sense, but say it is a
374
+ synthesised stand-in and that you could not listen to it.
375
+
376
+ If the human reports an error from the editor, ask for the exact text (the editor's console
377
+ or the load error shown on the scene), fix the first one, and check again.
378
+
379
+ ## Known gaps
380
+
381
+ - `pix3 check` shows the newest merge-log entries, not only the ones since your last write —
382
+ compare their age with when you wrote.
383
+ - The barrier verifies the open scenes and the built scripts; prefabs and assets the game loads
384
+ lazily are only caught afterwards, in `changedDuringRun`.
385
+ - `.pix3/kit-manifest.json` (how `pix3 kit --update` knows which files are still the kit's) is
386
+ in the gitignored `.pix3/`: on a fresh clone every kit file counts as edited and is skipped.
@@ -0,0 +1,21 @@
1
+ <!-- Pix3 agent kit 1.6.0 — generated from docs/pix3-specification.md. Do not edit: pix3 kit --update regenerates it. -->
2
+ # What the editor does with your files
3
+
4
+ The engine specification's own statements, for when something surprises you. `SKILL.md`
5
+ beside this file is the practical version. Source paths quoted here (`src/…`, `packages/…`) are files of the Pix3 engine repository, not of this project.
6
+
7
+ ## Strict profile — what `pix3 validate` checks
8
+
9
+ **Strict profile — `pix3 validate`.** The loader stays forgiving (above); strictness lives in the CLI (`packages/pix3-cli/src/validate/`), which reports every problem as `{severity, code, file, nodeId?, path, line?, message, fix?}` (`--json` adds the sha256 of each validated file; exit code 1 on any error). Level 1 reads files only — no project code, no DOM: document/node/component shape, `type:` vocabulary, property keys and values, `core:` component config, `user:` components by existence (a file under `scripts/` with `extends Script` exporting that name), `res://` targets, prefab targets/cycles/roots, override targets, duplicate ids, emoji-as-art. Level 2 (on unless `--no-hydrate`) hydrates the scene with the real `SceneLoader` in plain Node (`@pix3/runtime/node`: canvas-only `document` shim, disk `ResourceManager`, existence-checking `AssetLoader`) after compiling the project scripts with native esbuild, and reports loader rejections/warnings, still-pending components, `user:` config keys against the compiled schema, and the renderability lint as warnings. "Unknown property" is decided by the **disk format**, not by `getPropertySchema()`: `packages/pix3-runtime/src/core/scene-disk-format.ts` lists, per node type, which keys the loader reads under `properties:` (flat schema names, `transform`/`layout`/`flow`/`material`/`stateTextureKeys` nesting, per-type extras and read-compat aliases), and `scene-disk-format.spec.ts` pins it against what `SceneLoader` actually honours and what `SceneSaver` actually writes. There are no scene-format migrations today: `version` other than `1.0.0` is only a warning.
10
+
11
+ ## Co-authoring mode — the editor's side of a shared folder
12
+
13
+ - **Co-authoring mode (an external agent writes the same folder)** — plan `.plans/external-agent-authoring.md` §4.3/§5 C; code in `src/services/project/coauthoring/` + `autosave/`. Promise: a manual edit is never lost for good and never overwritten silently. (1) **Autosave** (`AutosaveService`): ~1 s after the last committed operation every dirty open `res://` scene is saved through `SaveSceneOperation` (`quiet`, invoked with `origin: 'system'`, never pushed to history). On for `workspace` projects, for local/browser folders with an agent kit (`AGENTS.md` at the root or a `.pix3/` directory, detected at open) or with the **Settings → General → Autosave scenes in local project folders** switch (`ui.autosaveLocalProjects`); never for cloud. Only the owner window saves (`ProjectOwnershipService`: workspace lease holder, or the Web Lock `pix3-project:<projectId>` holder — a second window queues for the lock; no lock API = owner). Held while that scene has a pending external version or a pointer gesture is in progress (`GestureStateService`). Status-bar pill: On disk / Autosave… / Saving… / Waiting for disk / Autosave off, plus **Stale** while play mode defers an external change. (2) **Pre-write check** (`SaveSceneOperation`): the file's current sha256 — always of the **raw bytes** (`coauthoring/disk-version.ts` → `readDiskVersion`; a BOM or CRLF is part of the hash, exactly as `pix3 serve` / `pix3 read` compute it) — must equal the version the editor last read or wrote (`SceneDiskStateService`, `path → {hash, genAtWrite}`, recorded by `LoadSceneCommand`, `ReloadSceneOperation` and every save); otherwise nothing is written, the path is reported to the external-change path and the outcome is `external-change` (the scene stays dirty; autosave retries after the reload). For workspaces the server's `If-Match` refusal (`WorkspaceConflictError`) maps to the same outcome. The dirty flag clears only after the write and only if no operation completed meanwhile. (3) **Recovery journal** (`RecoveryJournalService`): before every scene write, and before a reload replaces a dirty graph, the manual version goes to `.pix3/recovery/<encodeURIComponent(path)>/<ISO stamp with - for :.>-<hash8>.pix3scene`; ring per project of 200 versions / 7 days (the newest version of a scene never ages out), consecutive duplicates skipped; if `.pix3/` cannot be written (or the project is cloud) the versions go to IndexedDB. `.pix3/` is excluded from exports (`NON_SHIPPABLE_DIRECTORIES`), from FileWatch/workspace change dispatch and from `fileRefreshSignal` bumps. (4) **Protected set `P`** (`ProtectedSetService`): every operation pushed to history with origin `user`, and every undo/redo, is recorded via `recordHumanOperation` as the difference between the saved-form document before and after it (`external-merge/human-operation-diff.ts` — disk paths such as `properties.transform.position`, `components/@id/config/<key>`, whole-node create snapshots with `{parent, prevSibling}`, subtree tombstones on delete, LCS-based moves); reloads (tagged `NON_HUMAN_OPERATION_TAG`), `origin: 'external' | 'system'` and history-less operations only move the baseline. Persisted by the owner, debounced, to `.pix3/protected.json` = `{ format: 1, scenes: { <path>: ProtectedSetData } }`; every save records `(hash, genAtWrite)` via `recordEditorWrite`, and so does every version the editor accepts from disk as is — scene load and a plain reload, at the current gen (`SceneDiskStateService.acceptVersion` → `ProtectedSetService.trackAcceptedVersions`) — so a `pix3 read` of the bytes the editor opened is a known version, not `ack-unknown`. (5) **Stabilisation** (`ExternalChangeService`): a reported change (poll, push, refused pre-write check) is accepted when two snapshots (size + sha256) 300 ms apart match; files that change within one quiet window are delivered together to `onExternalBatch`, which the editor shell hands to `ExternalMergeService.handleBatch` (7); own writes are recognised by hash; a scene that does not parse (or that the loader rejects) keeps the last good graph, holds autosave for that path and after ~5 s logs "File not readable: …"; during play the change is detected but deferred (`coauthoring.stale`). FileWatch polls every 1 s while the document is **visible**, focused or not, and keeps polling during play. (6) **`ProjectSyncService.syncNow()`**: immediate scan (workspace manifest re-scan, or a poll of watched files + script sources vs. the last build), reports every open scene whose bytes differ, waits for the window to settle and for `ProjectScriptLoaderService.ensureReady()`, and returns `{ path: sha256 }` of the versions it holds. (7) **Merge instead of reload** (`ExternalMergeService`): the owner window reads `A` once as bytes and runs `mergeExternalVersion({ E, A, P, acks, externalHash, typeResolver })`, where `E` is the last version the editor wrote or accepted (`SceneDiskStateService.getEditorVersion`, set by load, accepting reloads and every save). Empty `P` and no acks → plain reload from `A` (fast path); `clean` with `M == A` → reload from `A`; `clean` otherwise or `conflicts` → journal the human version (`before-external`), reload from `M` (dirty), write `M` back through `SaveSceneOperation` (pre-write check), `conflicts` also opens the banner; `rejected` → the last good graph stays, nothing is written, the path is **held for a decision** (autosave waits) and a whole-scene banner offers *Accept agent's version* (reload `A`, release all of `P`) / *Keep mine* (`SaveSceneOperation({ overwriteExternalHash })` over exactly that version; the agent's file is journaled first). A non-owner window never merges — it reloads the disk. Every reload is non-destructive (selection kept by id — `ReloadSceneOperation` prunes only vanished ids; the camera state and the scene tree's collapsed ids are keyed by id and untouched; the viewport reconciles proxies incrementally), clears undo history and logs "… was changed outside Pix3 and reloaded — undo history was cleared", and highlights changed nodes in the scene tree for ~3 s (`coauthoring.recentlyChangedNodeIds`, class `tree-node__content--external-change`). (8) **Acks and merge log**: `.pix3/ack.json` = `{ acks: [{ path, sha256, at }] }` written by `pix3 read <path>` (prints the bytes, acks their hash) / `pix3 ack <path> --sha256 <h>`; `AckService` watches this one `.pix3/` file explicitly (2 s poll while visible; workspace push is let through `FileWatchService`), the merge re-reads it and passes that path's hashes as `acks`; `consumedAcks` are removed from the file (one-shot). Each `MergeLogEntry` (merge / ack-applied / ack-unknown, `mergedHash` stamped after the write) and each editor decision (accept-agent, keep-mine, restore-version) is appended by the owner to `.pix3/merge-log.jsonl` as `{ at, file, ... }`, a ring of 500 lines. (9) **Banner and restore** (`pix3-merge-banner`): "Agent changed N properties you edited in <scene> — yours were kept." with *Accept agent's version* (all), *Details* (each conflict: yours → agent's, per-item *Accept*) and *Restore my version before the agent's changes*. Accept = `AcceptAgentVersionCommand` → `AcceptAgentVersionOperation`: `acceptAgentVersion(P, conflicts)` then re-runs the merge of `A` against the released set, installs the result as a new graph instance; undo swaps the previous instance back (`SceneManager.setActiveSceneGraph(…, { disposePrevious: false })`) and restores `P`. Restore = `RestoreRecoveryVersionCommand` → `RestoreRecoveryVersionOperation`: a journal version as one undoable graph swap whose differences are recorded into `P` as one human operation. Right-clicking a scene/prefab tab (`LayoutManagerService.subscribeEditorTabContextMenu` → `pix3-recovery-menu`) offers *Restore my version…* over the last 10 journal versions. (10) **Second window**: a non-owner window is view-only — `CommandDispatcher` refuses every command outside a small allowlist (load/reload/prefab refresh, selection, `viewport.*`, `game.*`, `editor.open-*`; undo/redo and saves are refused) and sets `coauthoring.editBlockedAt`; local folders show "Project is being edited in another window — [Take over]" in `pix3-workspace-banner` (workspaces keep the lease banner). Take over (`ProjectOwnershipService.requestTakeOver`) posts on `BroadcastChannel('pix3-project:<id>')`; the owner runs its release hooks (`AutosaveService.handOver` = flush + journal whatever stays dirty; `ProtectedSetService.flush`), goes view-only and releases the Web Lock (the requester is queued first) and re-queues; no answer in 3 s → `steal: true`.
14
+
15
+ ## Live agent channel — the editor's side of `pix3 mcp --workspace`
16
+
17
+ - **Live agent channel (`pix3 mcp --workspace`)** — plan §5 D over the workspace backend; wire contract in `packages/pix3-cli/README.md` ("Agent lane", "`pix3 mcp --workspace`"). The agent's stdio MCP server finds the project's running `pix3 serve` through `.pix3/workspace.json` and relays every tool through the server's control-secret agent lane (`/ws/agent/*`; bearer tokens and `Origin`-bearing requests refused) to the lease-holding window, where `WorkspaceAgentToolBridge` (`src/services/project/workspace/`, registered by the editor shell into `WorkspaceSessionService.setCallHandler`) executes exactly 14 tools through `AgentToolRegistry.execute` — `project_status`, `play_start/stop/restart`, `play_status`, `game_run`, `game_input`, `game_observe`, `read_errors`, `read_logs`, `viewport_screenshot` (image block), `generate_asset`, `generate_sfx`, `get_selection` — plus internal `sync_barrier` / `sync_release` / `tools_manifest`; no scene mutation. `play_start` / `play_restart` / `game_run` pass the **sync barrier**: `expect` hashes vs. disk (`disk_differs_from_agent`, with a `.pix3/recovery/` copy only when one exists), then `sync_barrier` (`AutosaveService.hold`, stop play, `ProjectSyncService.barrierRevision()` = `syncNow()` + every open scene/prefab + every source the last script build read, entry scripts and bundled modules alike, with the hash the loader recorded while reading + `pix3project.yaml`, re-read by `syncNow()` when the disk moved) compared with disk hashes for ~5 s (`sync_timeout` / `load_failed` / `pending_external`), run — a start answers once the game is actually running (≤ 30 s, fail-fast when play mode stops, `startupMs` in the answer) — and a second hash + change-log check (`changedDuringRun`; the editor's own file-API writes go to `editorWroteDuringRun`); the verified hashes become `coauthoring.playRevision`, which observing tools report with `stale`. `generate_*` ask the human once per connection (server session + lease + MCP process, 60 s, then `permission_denied`), 20 generations per allowance, revocable from the status-bar **Agent** pill (`pix3-agent-channel-indicator`), which also switches the channel off. `pix3 new` writes a pinned `.mcp.json`; `pix3 setup [claude|codex]` prints the registration.
18
+
19
+ ## Workspace backend — `pix3 serve`
20
+
21
+ - **Workspace backend (pix3 serve)**: a project folder on another machine (VS Code Remote SSH) or one the browser cannot pick is opened over HTTP + WebSocket instead of File System Access. `pix3 serve` (`packages/pix3-cli/README.md` is the wire contract) serves one root on loopback with a pairing token; **File → Connect to Workspace…** (also on the welcome screen) takes the address — whatever local port the forward uses — and the token. The project then has `backend: 'workspace'`, and `ProjectStorageService` routes every read/write through `WorkspaceClient` (`src/services/project/workspace/`): listings and mtimes come from the server manifest (patched by the client's own mutations and pushed events), reads revalidate with `If-None-Match`, every write carries `If-Match` = the hash of the bytes this editor last read or wrote plus an `X-Mutation-Id`, and a `409 base_mismatch` becomes a `WorkspaceConflictError` — never a silent overwrite of an agent's edit. `WorkspaceSessionService` runs `/ws/events` (auth frame first, token never in the URL): pushed `change` batches go into `FileWatchService.notifyExternalChange`, i.e. the same listeners the FSA poller drives, so an open scene reloads through `ReloadSceneCommand` exactly as for a local folder; a reconnect re-scans the whole manifest; the edit **lease** decides which window may write (another holder → read-only banner with **Take over**); the granted `leaseId` is kept per `workspaceId` in `sessionStorage`, so a reloaded tab resumes its own lease inside the server's grace — or, when the new page connects before the old page's socket closed, the server moves the lease to the socket presenting the holder's `leaseId` (`lost {reason: 'resumed_elsewhere'}` on the old one); a stored id is presented only on a reload or after the old page's `pagehide` marked it, so a duplicated tab never takes it (a second tab never shares it), and a `busy {inGrace: true}` answer is retried after `hello.leaseGraceMs` (+500 ms; 11 s fallback) until granted or held by a connected window. The co-authoring bookkeeping under `.pix3/` (protected set, merge log, recovery journal, acks) is read and written through the same routes and listed by the manifest, but stays out of the revision and of change events (except `.pix3/ack.json`); only the server's own `.pix3/workspace.json`, `serve.lock`, `tmp/`, `link/` are refused. The protocol version is `WORKSPACE_PROTOCOL` (`workspace-protocol.ts`), refused on mismatch. The token lives in IndexedDB keyed by `workspaceId`; the recents entry stores `{ backend: 'workspace', endpoint, workspaceId }` and reopens with one click, and a rejected token or dead server opens the connect dialog — never a folder picker. Refused for a workspace in this slice: picker-based Save As, cloud/hybrid sync, Open in IDE.
@@ -0,0 +1,203 @@
1
+ <!-- Pix3 agent kit 1.6.0 — written by `pix3 kit`. You may edit it: `pix3 kit --update` never overwrites a kit file you changed. -->
2
+ # AGENTS.md — Pix3 game project
3
+
4
+ This folder is a **Pix3 game**: a 2D/3D browser game. You edit it by writing files. A human
5
+ has the same folder open in the Pix3 editor, moves things with the mouse and presses Play;
6
+ the editor saves their edits to the same files. The files are the whole contract.
7
+
8
+ If it started from a **recipe** (`design/recipe.md` exists), it is a game that already plays.
9
+ Change it; do not rebuild it.
10
+
11
+ ## Read first
12
+
13
+ 1. `design/recipe.md` (if present) — the map: stable node ids, tunables with ranges, extension
14
+ points, what must not be touched. It speaks in the in-editor agent's tool names; translate
15
+ them with the table in `.claude/skills/pix3-scene-format/SKILL.md` ("Recipe tool names").
16
+ 2. `README.md` — file layout of this project.
17
+ 3. The one scene or script you are about to change. Nothing else. Do not survey the repo.
18
+ To find it, and to find your way inside it, use `pix3 tree` (every scene and prefab with
19
+ node counts, types and components) and `pix3 tree <scene>` (one line per node: id, type,
20
+ position, size, layout, components, prefab instances; `--types Label2D,Button2D`,
21
+ `--depth 2`, `--props`) — not a read of whole scene files. Read the file itself right
22
+ before you edit it (rule 2).
23
+
24
+ ## Layout
25
+
26
+ The layout is **whatever this project has** — do not assume folders. Three rules hold everywhere:
27
+
28
+ - **Scenes**: find them with a glob `**/*.pix3scene` outside `node_modules/` (and `.pix3/`).
29
+ `defaultExportScenePath` in `pix3project.yaml` names the build's entry scene.
30
+ - **`res://` is always relative to the project root** (the folder with `pix3project.yaml`), so
31
+ `res://src/assets/textures/x.png` is as normal as `res://sprites/x.png`. Copy the style the
32
+ scene you are editing already uses.
33
+ - **Scripts** live under `scripts/**` or `src/scripts/**` (the only two roots the editor and
34
+ `pix3 check` scan). `export class X extends Script` → `type: user:X`.
35
+
36
+ `pix3project.yaml` is the manifest (do not edit unless asked); `.pix3/` is editor + CLI
37
+ bookkeeping (recovery journal, merge log, script types) — never edit it.
38
+
39
+ Example — the layout a **recipe** project (`pix3 new`) ships; other projects differ:
40
+
41
+ | Path | What |
42
+ | --- | --- |
43
+ | `scenes/*.pix3scene` | Scenes |
44
+ | `scenes/ui/*.pix3scene` | Full-screen overlays (result card, modal), one file each, instanced hidden |
45
+ | `scenes/prefabs/*.pix3scene` | Prefabs: a scene file with exactly ONE root node (a top-level `prefabs/` works too) |
46
+ | `scripts/*.ts` | Script components |
47
+ | `sprites/`, `audio/`, `fonts/`, `models/` … | Assets, referenced as `res://sprites/x.png` |
48
+ | `design/` | Recipe contract, GDD, tests. `design/tests/` is written by the editor's harness |
49
+
50
+ ## The five rules
51
+
52
+ 1. **Playable change first, questions after.** Make the change the user asked for, in the
53
+ smallest form that plays, before asking anything. Choose small things yourself (a shade, a
54
+ speed, a count) and say so in one line. At most ONE question per turn, and only about a
55
+ fork that changes structure ("win by score or by time?"). Never open with a question.
56
+ 2. **Re-read a scene before you edit it.** The human may have changed it in the editor a
57
+ minute ago. Edit the lines you mean to change (search/replace), never regenerate a whole
58
+ scene from memory. After writing, if `pix3 check` lists **merge-log** entries where the
59
+ editor KEPT the human's value instead of yours, re-read the file with `pix3 read <file>`
60
+ (that is your read confirmation); if your value is still intended, write it again — or ask
61
+ the human. Without that re-read the editor keeps restoring the human's value on every
62
+ write you make, even if you write the same number.
63
+ 3. **Leave layout, colours and fine-tuning to the human.** If asked "a bit more to the left",
64
+ do it, then offer: "you can drag it in the editor — it saves on its own".
65
+ 4. **Run `pix3 check` after every batch of edits** and fix every error before you say "done".
66
+ It checks YAML, node types, properties, `res://` paths, prefabs, components, and
67
+ type-checks your scripts (tsc). With the live channel connected (MCP, below), then run the
68
+ game with `game_run` (or `play_restart`), **passing `expect`** — the sha256 of every file you
69
+ wrote, as `pix3 check --json` prints them under `files`. An answer with
70
+ `disk_differs_from_agent`, or a non-empty `changedDuringRun`, is not green.
71
+ **No editor connected?** `pix3 check`, then `pix3 smoke <the scene you changed>` — the
72
+ game is `pix3 smoke scenes/main.pix3scene`; the menu never presses PLAY headless, so a
73
+ smoke of the menu says nothing about the game. It runs that scene in Node for 2 s
74
+ (`--frames N` for more) and exits 1 on any script throw, `console.error` or unhandled
75
+ rejection, naming script, frame and source line. With no scene it runs several, a line
76
+ each: the scenes your uncommitted changes reach (git), else every top-level scene, game
77
+ first. Green means nothing threw; it does not mean it plays (nothing was tapped or drawn)
78
+ — so then tell the human what to press and what they should see.
79
+ 5. **Art: placeholder → SVG → `generate_asset`, never emoji.** Placeholder = `ColorRect2D`, or
80
+ a near-white PNG in `sprites/` tinted with a `core:tint` effect. Better art = an SVG you
81
+ write into `sprites/` — it works on a `Sprite2D` when the root has `xmlns` plus px
82
+ `width`/`height`; `pix3 validate` checks it (`E_SVG_*`); template in `pix3-nodes` — or
83
+ `generate_asset` through the live channel. A label/text that is only emoji is
84
+ refused — emoji are not art. List every placeholder you leave.
85
+
86
+ ## YAML essentials (`.pix3scene`) — details in `pix3-scene-format`
87
+
88
+ ```yaml
89
+ version: 1.0.0
90
+ metadata: { description: 'what this scene is' }
91
+ root:
92
+ - id: game-root # unique in the scene; never rename an existing id
93
+ type: Group2D # exact node type name; a typo loads as an inert node
94
+ name: Game Root
95
+ properties:
96
+ width: 1080
97
+ height: 1920
98
+ transform: { position: [0, 0], scale: [1, 1], rotation: 0 } # 2D, rotation in degrees
99
+ components:
100
+ - id: game-rules
101
+ type: user:GameRules # user:<ExportedClassName> or core:<Builtin>
102
+ enabled: true
103
+ config: { targetScore: 18 } # keys = the script's schema names
104
+ children:
105
+ - id: result-overlay # prefab/overlay instance: NO type, NO components
106
+ name: Result Overlay
107
+ instance: res://scenes/ui/result.pix3scene
108
+ properties: { visible: false }
109
+ ```
110
+
111
+ - The sample assumes a 1080×1920 portrait 2D root; yours may not have one. Read
112
+ `viewportBaseSize` and `projectType` in `pix3project.yaml` first; a `3d` project may have loose
113
+ top-level 2D nodes (HUD) with no 2D root at all. Place new HUD relative to the HUD nodes that
114
+ already exist (same parent, same anchoring), not to an assumed screen size.
115
+ - 2D space: design pixels, origin at the screen centre, **X right, Y up**. `position` is the
116
+ node's centre. Tree order is paint order: later/deeper draws on top.
117
+ - **Quote every colour**: `color: "#141a2e"`. Unquoted, `#` starts a YAML comment.
118
+ - Textures: `texture: { type: 'texture', url: 'res://sprites/ph-target.png' }`.
119
+ - `visible: false` on an overlay instance hides it **in the editor only**; play mode reads
120
+ `initiallyVisible` on the overlay file's root. Keep both as the recipe has them.
121
+ - The loader is forgiving — unknown types, unknown keys and wrong value types load silently
122
+ as nothing. That is why rule 4 exists.
123
+
124
+ ## Script essentials — details in `pix3-scripts`
125
+
126
+ ```ts
127
+ import { Script, type PropertySchema } from '@pix3/runtime';
128
+
129
+ export class Combo extends Script {
130
+ constructor(id: string, type: string) {
131
+ super(id, type);
132
+ this.config = { windowSec: 1 }; // defaults; scene `config` merges over them
133
+ }
134
+ static getPropertySchema(): PropertySchema { // REQUIRED, or the class is not registered
135
+ return { nodeType: 'Combo', properties: [/* one entry per config key */], groups: {} };
136
+ }
137
+ onStart(): void {} // scene is loaded
138
+ onUpdate(dt: number): void {} // dt in seconds
139
+ }
140
+ ```
141
+
142
+ - One mechanic = one new script of 70–140 lines. Extend a recipe's scripts only where
143
+ `design/recipe.md` names an extension point; do not restructure them.
144
+ - Talk between scripts the way the project already does. Recipes use signals on nodes:
145
+ `node.emit('touch-scored', 1)` / `node.connect('touch-scored', this, fn)` — never rename the
146
+ recipe's signals or node ids. An existing game may use its own event bus or store instead
147
+ (next section).
148
+ - Transforms are mutated, never assigned: `node.position.set(x, y, 0)`, `node.rotation.z = rad`.
149
+ - Types come from `@pix3/runtime`: `pix3 check` type-checks against the bundled declarations in
150
+ `.pix3/types/` (or against your own `node_modules` when the project has its own `tsconfig.json`).
151
+
152
+ ## Hosting an existing (non-recipe) game
153
+
154
+ A game that was not made from a recipe has its own architecture; plug into it, do not add a
155
+ second one.
156
+
157
+ - **Find its event bus / state store** before writing a script:
158
+ `grep -rn "CustomEvent\|dispatchEvent\|addEventListener\|subscribe(\|EventTarget\|emit(" src scripts`.
159
+ Window `CustomEvent`s, an `EventTarget` singleton, or a store with `subscribe()` are all
160
+ normal; node signals are only one option. Listen to what the game already emits.
161
+ - **Clean up by hand.** `Script.onDetach` auto-disconnects only **node signals** whose target is
162
+ the script (on its own node or any other). Window listeners, store subscriptions and timers
163
+ must be removed in `onDetach` (keep the handler in a field; call the
164
+ unsubscribe the store returned) — otherwise every play/stop in the editor leaves one more
165
+ live listener behind.
166
+ - **Two instruction files.** The project's own `AGENTS.md` wins on **process** (planning first,
167
+ where config and tests go, commit rules); this kit wins on **Pix3 facts** (the YAML format,
168
+ the runtime API, `pix3 check`).
169
+ - The project's own `package.json` means `npm install` before `pix3 check` can type-check.
170
+ - **Use the game's own feedback mechanisms.** If its camera controller writes the camera's
171
+ position every frame, an engine `scene.juice.shake('camera')` / `core:Shake` on that 3D camera
172
+ (or on any node the game positions itself) is overwritten every frame and never shows — call
173
+ the game's own shake (grep `shake`) instead. The same holds for its own sound/tween helpers.
174
+
175
+ ## The CLI and the live channel
176
+
177
+ - `pix3 check [--json]` — after every batch (rule 4). `--json` prints `files` (`{ file, sha256 }`,
178
+ sha256 of the raw bytes), `diagnostics`, `typecheck`, `mergeLog`, `kit`.
179
+ - `pix3 read <file>` — print a file and confirm to the editor you read exactly these bytes.
180
+ - `pix3 validate [paths…]` — scenes only, no type-check.
181
+ - `pix3 smoke [scene] [--frames N] [--json]` — run a scene headless (no browser) and report
182
+ script throws with frame and stack, `console.error`, missing `res://` files; exit 1 on errors.
183
+ Name the game scene (`pix3 smoke scenes/main.pix3scene`); no scene = the scenes git changes
184
+ reach, else every top-level scene (`--all` forces that).
185
+ - `pix3 tree [scene] [--types A,B] [--depth N] [--props] [--json]` — scene outline, one line
186
+ per node; no scene = project overview.
187
+ - **Live channel (optional).** When the human runs `pix3 serve` in this folder and connects the
188
+ editor to it (File → Connect to Workspace…), the MCP server in `.mcp.json`
189
+ (`pix3 mcp --workspace`) gives you 14 tools: running and observing the game, screenshots,
190
+ asset/sfx generation. There is no scene-editing tool — you still edit files. Details and the
191
+ answer fields: `.claude/skills/pix3-verify/SKILL.md` ("Live channel").
192
+
193
+ ## Skills (read the one you need, when you need it)
194
+
195
+ - `.claude/skills/pix3-scene-format/SKILL.md` — full YAML format, prefabs, overlays, recipe tool table
196
+ - `.claude/skills/pix3-nodes/SKILL.md` — 2D node properties (Group2D, ColorRect2D, Sprite2D, Label2D, Button2D, Bar2D, CanvasLayer2D, PostProcess); every node in `reference.md` beside it
197
+ - `.claude/skills/pix3-scripts/SKILL.md` — Script API: lifecycle, schema, scene/input/juice/tween/audio/physics, `core:` components, traps
198
+ - `.claude/skills/pix3-verify/SKILL.md` — `pix3 check` / `validate` / `read`, merge-log, the live channel (`game_run` + `expect`)
199
+
200
+ ## Finish every turn with
201
+
202
+ What changed (files), what `pix3 check` said, whether you ran the game (and what `game_run`
203
+ answered) or what the human should press and see, placeholders left, and 2–3 concrete next steps.